SDInterface.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include "SDInterface.h"
  2. bool SDInterface::initSD() {
  3. String display_string = "";
  4. if (!SD.begin(SD_CS)) {
  5. Serial.println("Failed to mount SD Card");
  6. this->supported = false;
  7. return false;
  8. }
  9. else {
  10. this->supported = true;
  11. this->cardType = SD.cardType();
  12. if (cardType == CARD_MMC)
  13. Serial.println("SD: MMC Mounted");
  14. else if(cardType == CARD_SD)
  15. Serial.println("SD: SDSC Mounted");
  16. else if(cardType == CARD_SDHC)
  17. Serial.println("SD: SDHC Mounted");
  18. else
  19. Serial.println("SD: UNKNOWN Card Mounted");
  20. //this->cardSizeBT = SD.cardSize();
  21. //this->cardSizeKB = SD.cardSize() / 1024;
  22. this->cardSizeMB = SD.cardSize() / (1024 * 1024);
  23. //this->cardSizeGB = SD.cardSize() / (1024 * 1024 * 1024);
  24. //Serial.printf("SD Card Size: %llu Bytes\n", this->cardSizeBT);
  25. //Serial.printf("SD Card Size: %lluKB\n", this->cardSizeKB);
  26. Serial.printf("SD Card Size: %lluMB\n", this->cardSizeMB);
  27. //Serial.printf("SD Card Size: %lluGB\n", this->cardSizeGB);
  28. if (this->supported) {
  29. //display_obj.tft.println((byte)(sd_obj.cardSizeMB % 10));
  30. const int NUM_DIGITS = log10(this->cardSizeMB) + 1;
  31. char sz[NUM_DIGITS + 1];
  32. sz[NUM_DIGITS] = 0;
  33. for ( size_t i = NUM_DIGITS; i--; this->cardSizeMB /= 10)
  34. {
  35. sz[i] = '0' + (this->cardSizeMB % 10);
  36. display_string.concat((String)sz[i]);
  37. }
  38. //this->card_sz = display_string;
  39. this->card_sz = sz;
  40. }
  41. buffer_obj = Buffer();
  42. //if (this->supported)
  43. // buffer_obj.open(&SD);
  44. return true;
  45. }
  46. }
  47. void SDInterface::addPacket(uint8_t* buf, uint32_t len) {
  48. if ((this->supported) && (this->do_save)) {
  49. //Serial.println("Adding packet to buffer...");
  50. buffer_obj.addPacket(buf, len);
  51. }
  52. }
  53. void SDInterface::openCapture() {
  54. if (this->supported)
  55. buffer_obj.open(&SD);
  56. }
  57. void SDInterface::main() {
  58. if ((this->supported) && (this->do_save)) {
  59. //Serial.println("Saving packet...");
  60. buffer_obj.save(&SD);
  61. }
  62. }
  63. //void SDInterface::savePacket(uint8_t* buf, uint32_t len) {
  64. // if (this->supported)
  65. // buffer_obj.save(
  66. //}