SDInterface.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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::main() {
  54. if ((this->supported) && (this->do_save)) {
  55. //Serial.println("Saving packet...");
  56. buffer_obj.save(&SD);
  57. }
  58. }
  59. //void SDInterface::savePacket(uint8_t* buf, uint32_t len) {
  60. // if (this->supported)
  61. // buffer_obj.save(
  62. //}