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.

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