Buffer.h 939 B

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