You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 line
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::setTime(time);
  16. positions::appendLast(battery, gpsStatus);
  17. uint8_t velocity;
  18. gps::getVelocity(velocity);
  19. core::setSleepTime(velocity);
  20. }
  21. if (positions::needsToSend()) {
  22. positions::send();
  23. }
  24. mainunit::deepSleep(core::sleepTime);
  25. }
  26. void setSleepTime(uint8_t velocity) {
  27. for (uint8_t i = 0; i < flash::getArraySize(config::defaultSleepTimings); i++) {
  28. sleepTimings_t timing;
  29. flash::read(&config::defaultSleepTimings[i], timing);
  30. if (velocity > timing.speed) continue;
  31. sleepTime = timing.seconds;
  32. return;
  33. }
  34. sleepTime = SLEEP_DEFAULT_TIME_SECONDS;
  35. }
  36. }