Buffer.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #ifndef Buffer_h
  2. #define Buffer_h
  3. #include "Arduino.h"
  4. #include "FS.h"
  5. #include "settings.h"
  6. //#include "SD_MMC.h"
  7. #define BUF_SIZE 3 * 1024 // Had to reduce buffer size to save RAM. GG @spacehuhn
  8. #define SNAP_LEN 2324 // max len of each recieved packet
  9. //extern bool useSD;
  10. extern Settings settings_obj;
  11. class Buffer {
  12. public:
  13. Buffer();
  14. void createPcapFile(fs::FS* fs, String fn = "");
  15. void open();
  16. void close(fs::FS* fs);
  17. void addPacket(uint8_t* buf, uint32_t len);
  18. void save(fs::FS* fs);
  19. void forceSave(fs::FS* fs);
  20. void forceSaveSerial();
  21. private:
  22. void write(int32_t n);
  23. void write(uint32_t n);
  24. void write(uint16_t n);
  25. void write(uint8_t* buf, uint32_t len);
  26. uint8_t* bufA;
  27. uint8_t* bufB;
  28. uint32_t bufSizeA = 0;
  29. uint32_t bufSizeB = 0;
  30. bool writing = false; // acceppting writes to buffer
  31. bool useA = true; // writing to bufA or bufB
  32. bool saving = false; // currently saving onto the SD card
  33. String fileName = "/0.pcap";
  34. File file;
  35. };
  36. #endif