Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

55 рядки
1.6 KiB

  1. #include "Gps.h"
  2. #include "Debug.h"
  3. #include "Hardware.h"
  4. #include "MainUnit.h"
  5. #define LOGGER_NAME "Gps"
  6. #define WAIT_FOR_FIX_DELAY 10000
  7. #define TIME_YEAR_OFFSET 0
  8. #define TIME_MONTH_OFFSET 4
  9. #define TIME_DAY_OFFSET 6
  10. #define TIME_HOUR_OFFSET 8
  11. #define TIME_MINUTE_OFFSET 10
  12. #define TIME_SECOND_OFFSET 12
  13. #define STRTOUL_SUBSTRING(dst, src, size) strtoul(strncpy(dst, src , size), NULL, 2);
  14. namespace gps {
  15. char lastPosition[GPS_POSITION_SIZE];
  16. SIM808_GPS_STATUS lastStatus;
  17. SIM808_GPS_STATUS acquireCurrentPosition(uint16_t timeout) {
  18. SIM808_GPS_STATUS currentStatus = SIM808_GPS_STATUS::OFF;
  19. do {
  20. currentStatus = hardware::sim808::device.getGpsStatus();
  21. if (currentStatus > SIM808_GPS_STATUS::NO_FIX) break;
  22. mainunit::deepSleep(WAIT_FOR_FIX_DELAY);
  23. timeout -= WAIT_FOR_FIX_DELAY;
  24. } while (timeout > 1);
  25. if (currentStatus > SIM808_GPS_STATUS::NO_FIX) {
  26. lastStatus = currentStatus;
  27. hardware::sim808::device.getGpsPosition(lastPosition);
  28. }
  29. return currentStatus;
  30. }
  31. void getTime(tmElements_t &time) {
  32. char *timeStr;
  33. char buffer[4];
  34. hardware::sim808::device.getGpsField(lastPosition, SIM808_GPS_FIELD::UTC, timeStr);
  35. time.Year = STRTOUL_SUBSTRING(buffer, timeStr + TIME_YEAR_OFFSET, 4);
  36. time.Month = STRTOUL_SUBSTRING(buffer, timeStr + TIME_MONTH_OFFSET, 2);
  37. time.Day = STRTOUL_SUBSTRING(buffer, timeStr + TIME_DAY_OFFSET, 2);
  38. time.Hour = STRTOUL_SUBSTRING(buffer, timeStr + TIME_HOUR_OFFSET, 2);
  39. time.Minute = STRTOUL_SUBSTRING(buffer, timeStr + TIME_MINUTE_OFFSET, 2);
  40. time.Second = STRTOUL_SUBSTRING(buffer, timeStr + TIME_SECOND_OFFSET, 2);
  41. }
  42. }