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.

61 lines
1.4 KiB

  1. /**
  2. * @file TinyGsmTime.tpp
  3. * @author Volodymyr Shymanskyy
  4. * @license LGPL-3.0
  5. * @copyright Copyright (c) 2016 Volodymyr Shymanskyy
  6. * @date Nov 2016
  7. */
  8. #ifndef SRC_TINYGSMTIME_H_
  9. #define SRC_TINYGSMTIME_H_
  10. #include "TinyGsmCommon.h"
  11. #define TINY_GSM_MODEM_HAS_TIME
  12. enum TinyGSMDateTimeFormat { DATE_FULL = 0, DATE_TIME = 1, DATE_DATE = 2 };
  13. template <class modemType>
  14. class TinyGsmTime {
  15. public:
  16. /*
  17. * Time functions
  18. */
  19. String getGSMDateTime(TinyGSMDateTimeFormat format) {
  20. return thisModem().getGSMDateTimeImpl(format);
  21. }
  22. /*
  23. * CRTP Helper
  24. */
  25. protected:
  26. inline const modemType& thisModem() const {
  27. return static_cast<const modemType&>(*this);
  28. }
  29. inline modemType& thisModem() {
  30. return static_cast<modemType&>(*this);
  31. }
  32. /*
  33. * Time functions
  34. */
  35. protected:
  36. String getGSMDateTimeImpl(TinyGSMDateTimeFormat format) {
  37. thisModem().sendAT(GF("+CCLK?"));
  38. if (thisModem().waitResponse(2000L, GF("+CCLK: \"")) != 1) { return ""; }
  39. String res;
  40. switch (format) {
  41. case DATE_FULL: res = thisModem().stream.readStringUntil('"'); break;
  42. case DATE_TIME:
  43. thisModem().streamSkipUntil(',');
  44. res = thisModem().stream.readStringUntil('"');
  45. break;
  46. case DATE_DATE: res = thisModem().stream.readStringUntil(','); break;
  47. }
  48. return res;
  49. }
  50. };
  51. #endif // SRC_TINYGSMTIME_H_