Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

102 řádky
2.6 KiB

  1. #pragma once
  2. #include "NetworkPositionsBackup.h"
  3. #include "Debug.h"
  4. #include "Positions.h"
  5. #include "Config.h"
  6. #include "Hardware.h"
  7. #include "Network.h"
  8. #define LOGGER_NAME "Positions::backup::network"
  9. #define BUFFER_SIZE 170
  10. namespace positions {
  11. namespace backup {
  12. namespace net {
  13. namespace details {
  14. bool isBackupNeeded() {
  15. config_t *config = &config::main::value;
  16. return config->network.lastSavedEntry == 0xFFFF ||
  17. positions::count(config->network.lastSavedEntry) > config->network.saveThreshold;
  18. }
  19. bool appendPosition(PositionEntry &entry) {
  20. VERBOSE("appendPosition");
  21. debug::displayFreeRam();
  22. delay(100);
  23. char buffer[BUFFER_SIZE];
  24. sprintf(buffer, "%d", 2100);
  25. /*snprintf(buffer, BUFFER_SIZE, "%d,%d,%.2f,%d,",
  26. entry.metadata.batteryLevel,
  27. entry.metadata.batteryVoltage,
  28. entry.metadata.temperature,
  29. static_cast<uint8_t>(entry.metadata.status));*/
  30. ////strcat(buffer, entry.position);
  31. //Serial.println(buffer);
  32. debug::displayFreeRam();
  33. return false;
  34. /*return hardware::sim808::device.httpPost(
  35. config.network.url,
  36. PSTR("text/csv"),
  37. buffer,
  38. buffer,
  39. BUFFER_SIZE
  40. ) == POSITIONS_CONFIG_NET_DEFAULT_EXPECTED_RESPONSE;*/
  41. }
  42. void appendPositions() {
  43. VERBOSE("appendPositions");
  44. debug::displayFreeRam();
  45. uint16_t currentEntryIndex = config::main::value.network.lastSavedEntry + 1;
  46. PositionEntry currentEntry;
  47. SIM808RegistrationStatus networkStatus;
  48. /*network::powerOn();
  49. networkStatus = network::waitForRegistered(NETWORK_DEFAULT_TOTAL_TIMEOUT_MS);
  50. if (!network::isAvailable(networkStatus.stat)) VERBOSE_MSG("appendPositions", "network unavailable");
  51. else if (!network::enableGprs()) VERBOSE_MSG("appendPositions", "gprs unavailable");
  52. else {*/
  53. hardware::i2c::powerOn();
  54. do {
  55. if (!positions::get(currentEntryIndex, currentEntry)) break;
  56. debug::displayFreeRam();
  57. //if (!appendPosition(currentEntry)) break;
  58. /*config::main::value.network.lastSavedEntry = currentEntryIndex;
  59. config::main::save();
  60. */
  61. } while (positions::moveNext(currentEntryIndex));
  62. debug::displayFreeRam();
  63. hardware::i2c::powerOff();
  64. //}
  65. //network::powerOff();
  66. debug::displayFreeRam();
  67. }
  68. }
  69. void NetworkPositionsBackup::setup() {
  70. VERBOSE("setup");
  71. }
  72. void NetworkPositionsBackup::backup() {
  73. VERBOSE("backup");
  74. debug::displayFreeRam();
  75. if (!details::isBackupNeeded()) return;
  76. debug::displayFreeRam();
  77. details::appendPositions();
  78. }
  79. }
  80. }
  81. }