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.

132 lines
4.4 KiB

  1. /**
  2. * @file TinyGsmClientSIM808.h
  3. * @author Volodymyr Shymanskyy
  4. * @license LGPL-3.0
  5. * @copyright Copyright (c) 2016 Volodymyr Shymanskyy
  6. * @date Nov 2016
  7. */
  8. #ifndef SRC_TINYGSMCLIENTSIM808_H_
  9. #define SRC_TINYGSMCLIENTSIM808_H_
  10. // #pragma message("TinyGSM: TinyGsmClientSIM808")
  11. #include "TinyGsmClientSIM800.h"
  12. #include "TinyGsmGPS.tpp"
  13. class TinyGsmSim808 : public TinyGsmSim800, public TinyGsmGPS<TinyGsmSim808> {
  14. friend class TinyGsmGPS<TinyGsmSim808>;
  15. public:
  16. explicit TinyGsmSim808(Stream& stream) : TinyGsmSim800(stream) {}
  17. /*
  18. * GPS/GNSS/GLONASS location functions
  19. */
  20. protected:
  21. // enable GPS
  22. bool enableGPSImpl() {
  23. sendAT(GF("+CGNSPWR=1"));
  24. if (waitResponse() != 1) { return false; }
  25. return true;
  26. }
  27. bool disableGPSImpl() {
  28. sendAT(GF("+CGNSPWR=0"));
  29. if (waitResponse() != 1) { return false; }
  30. return true;
  31. }
  32. // get the RAW GPS output
  33. // works only with ans SIM808 V2
  34. String getGPSrawImpl() {
  35. sendAT(GF("+CGNSINF"));
  36. if (waitResponse(10000L, GF(GSM_NL "+CGNSINF:")) != 1) { return ""; }
  37. String res = stream.readStringUntil('\n');
  38. waitResponse();
  39. res.trim();
  40. return res;
  41. }
  42. // get GPS informations
  43. // works only with ans SIM808 V2
  44. bool getGPSImpl(float* lat, float* lon, float* speed = 0, float* alt = 0,
  45. int* vsat = 0, int* usat = 0, float* accuracy = 0,
  46. int* year = 0, int* month = 0, int* day = 0, int* hour = 0,
  47. int* minute = 0, int* second = 0) {
  48. sendAT(GF("+CGNSINF"));
  49. if (waitResponse(10000L, GF(GSM_NL "+CGNSINF:")) != 1) { return false; }
  50. streamSkipUntil(','); // GNSS run status
  51. if (streamGetIntBefore(',') == 1) { // fix status
  52. // init variables
  53. float ilat = 0;
  54. float ilon = 0;
  55. float ispeed = 0;
  56. float ialt = 0;
  57. int ivsat = 0;
  58. int iusat = 0;
  59. float iaccuracy = 0;
  60. int iyear = 0;
  61. int imonth = 0;
  62. int iday = 0;
  63. int ihour = 0;
  64. int imin = 0;
  65. float secondWithSS = 0;
  66. // UTC date & Time
  67. iyear = streamGetIntLength(4); // Four digit year
  68. imonth = streamGetIntLength(2); // Two digit month
  69. iday = streamGetIntLength(2); // Two digit day
  70. ihour = streamGetIntLength(2); // Two digit hour
  71. imin = streamGetIntLength(2); // Two digit minute
  72. secondWithSS =
  73. streamGetFloatBefore(','); // 6 digit second with subseconds
  74. ilat = streamGetFloatBefore(','); // Latitude
  75. ilon = streamGetFloatBefore(','); // Longitude
  76. ialt = streamGetFloatBefore(','); // MSL Altitude. Unit is meters
  77. ispeed = streamGetFloatBefore(','); // Speed Over Ground. Unit is knots.
  78. streamSkipUntil(','); // Course Over Ground. Degrees.
  79. streamSkipUntil(','); // Fix Mode
  80. streamSkipUntil(','); // Reserved1
  81. iaccuracy =
  82. streamGetFloatBefore(','); // Horizontal Dilution Of Precision
  83. streamSkipUntil(','); // Position Dilution Of Precision
  84. streamSkipUntil(','); // Vertical Dilution Of Precision
  85. streamSkipUntil(','); // Reserved2
  86. ivsat = streamGetIntBefore(','); // GNSS Satellites in View
  87. iusat = streamGetIntBefore(','); // GNSS Satellites Used
  88. streamSkipUntil(','); // GLONASS Satellites Used
  89. streamSkipUntil(','); // Reserved3
  90. streamSkipUntil(','); // C/N0 max
  91. streamSkipUntil(','); // HPA
  92. streamSkipUntil('\n'); // VPA
  93. // Set pointers
  94. if (lat != NULL) *lat = ilat;
  95. if (lon != NULL) *lon = ilon;
  96. if (speed != NULL) *speed = ispeed;
  97. if (alt != NULL) *alt = ialt;
  98. if (vsat != NULL) *vsat = ivsat;
  99. if (usat != NULL) *usat = iusat;
  100. if (accuracy != NULL) *accuracy = iaccuracy;
  101. if (iyear < 2000) iyear += 2000;
  102. if (year != NULL) *year = iyear;
  103. if (month != NULL) *month = imonth;
  104. if (day != NULL) *day = iday;
  105. if (hour != NULL) *hour = ihour;
  106. if (minute != NULL) *minute = imin;
  107. if (second != NULL) *second = static_cast<int>(secondWithSS);
  108. waitResponse();
  109. return true;
  110. }
  111. streamSkipUntil('\n'); // toss the row of commas
  112. waitResponse();
  113. return false;
  114. }
  115. };
  116. #endif // SRC_TINYGSMCLIENTSIM808_H_