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.

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