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.

148 lines
3.5 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 TinyGsmClientSIM808_h
  9. #define TinyGsmClientSIM808_h
  10. #include <TinyGsmClientSIM800.h>
  11. class TinyGsmSim808: public TinyGsmSim800
  12. {
  13. public:
  14. TinyGsmSim808(Stream& stream)
  15. : TinyGsmSim800(stream)
  16. {}
  17. /*
  18. * GPS location functions
  19. */
  20. // enable GPS
  21. bool enableGPS() {
  22. uint16_t state;
  23. sendAT(GF("+CGNSPWR=1"));
  24. if (waitResponse() != 1) {
  25. return false;
  26. }
  27. return true;
  28. }
  29. bool disableGPS() {
  30. uint16_t state;
  31. sendAT(GF("+CGNSPWR=0"));
  32. if (waitResponse() != 1) {
  33. return false;
  34. }
  35. return true;
  36. }
  37. // get the RAW GPS output
  38. // works only with ans SIM808 V2
  39. String getGPSraw() {
  40. sendAT(GF("+CGNSINF"));
  41. if (waitResponse(GF(GSM_NL "+CGNSINF:")) != 1) {
  42. return "";
  43. }
  44. String res = stream.readStringUntil('\n');
  45. waitResponse();
  46. res.trim();
  47. return res;
  48. }
  49. // get GPS informations
  50. // works only with ans SIM808 V2
  51. bool getGPS(float *lat, float *lon, float *speed=0, int *alt=0, int *vsat=0, int *usat=0) {
  52. //String buffer = "";
  53. char chr_buffer[12];
  54. bool fix = false;
  55. sendAT(GF("+CGNSINF"));
  56. if (waitResponse(GF(GSM_NL "+CGNSINF:")) != 1) {
  57. return false;
  58. }
  59. stream.readStringUntil(','); // mode
  60. if ( stream.readStringUntil(',').toInt() == 1 ) fix = true;
  61. stream.readStringUntil(','); //utctime
  62. *lat = stream.readStringUntil(',').toFloat(); //lat
  63. *lon = stream.readStringUntil(',').toFloat(); //lon
  64. if (alt != NULL) *alt = stream.readStringUntil(',').toFloat(); //lon
  65. if (speed != NULL) *speed = stream.readStringUntil(',').toFloat(); //speed
  66. stream.readStringUntil(',');
  67. stream.readStringUntil(',');
  68. stream.readStringUntil(',');
  69. stream.readStringUntil(',');
  70. stream.readStringUntil(',');
  71. stream.readStringUntil(',');
  72. stream.readStringUntil(',');
  73. if (vsat != NULL) *vsat = stream.readStringUntil(',').toInt(); //viewed satelites
  74. if (usat != NULL) *usat = stream.readStringUntil(',').toInt(); //used satelites
  75. stream.readStringUntil('\n');
  76. waitResponse();
  77. return fix;
  78. }
  79. // get GPS time
  80. // works only with SIM808 V2
  81. bool getGPSTime(int *year, int *month, int *day, int *hour, int *minute, int *second) {
  82. bool fix = false;
  83. char chr_buffer[12];
  84. sendAT(GF("+CGNSINF"));
  85. if (waitResponse(GF(GSM_NL "+CGNSINF:")) != 1) {
  86. return false;
  87. }
  88. for (int i = 0; i < 3; i++) {
  89. String buffer = stream.readStringUntil(',');
  90. buffer.toCharArray(chr_buffer, sizeof(chr_buffer));
  91. switch (i) {
  92. case 0:
  93. //mode
  94. break;
  95. case 1:
  96. //fixstatus
  97. if ( buffer.toInt() == 1 ) {
  98. fix = buffer.toInt();
  99. }
  100. break;
  101. case 2:
  102. *year = buffer.substring(0,4).toInt();
  103. *month = buffer.substring(4,6).toInt();
  104. *day = buffer.substring(6,8).toInt();
  105. *hour = buffer.substring(8,10).toInt();
  106. *minute = buffer.substring(10,12).toInt();
  107. *second = buffer.substring(12,14).toInt();
  108. break;
  109. default:
  110. // if nothing else matches, do the default
  111. // default is optional
  112. break;
  113. }
  114. }
  115. String res = stream.readStringUntil('\n');
  116. waitResponse();
  117. if (fix) {
  118. return true;
  119. } else {
  120. return false;
  121. }
  122. }
  123. };
  124. #endif