Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

50 lignes
1.1 KiB

  1. #include "Core.h"
  2. #include "Config.h"
  3. #include "Flash.h"
  4. #define LOGGER_NAME "Core"
  5. namespace core {
  6. uint16_t sleepTime = SLEEP_DEFAULT_TIME_SECONDS;;
  7. void main() {
  8. gps::powerOn();
  9. SIM808_GPS_STATUS gpsStatus = gps::acquireCurrentPosition(GPS_DEFAULT_TOTAL_TIMEOUT_MS);
  10. SIM808ChargingStatus battery = hardware::sim808::device.getChargingState();
  11. gps::powerOff();
  12. if (gpsStatus > SIM808_GPS_STATUS::NO_FIX) {
  13. tmElements_t time;
  14. gps::getTime(time);
  15. rtc::powerOn();
  16. rtc::setTime(time);
  17. rtc::powerOff();
  18. positions::appendLast(battery, gpsStatus);
  19. uint8_t velocity;
  20. gps::getVelocity(velocity);
  21. core::setSleepTime(velocity);
  22. }
  23. if (positions::needsToSend()) {
  24. positions::send();
  25. }
  26. mainunit::deepSleep(core::sleepTime);
  27. }
  28. void setSleepTime(uint8_t velocity) {
  29. for (uint8_t i = 0; i < flash::getArraySize(config::defaultSleepTimings); i++) {
  30. sleepTimings_t timing;
  31. flash::read(&config::defaultSleepTimings[i], timing);
  32. if (velocity > timing.speed) continue;
  33. sleepTime = timing.seconds;
  34. return;
  35. }
  36. sleepTime = SLEEP_DEFAULT_TIME_SECONDS;
  37. }
  38. }