Browse Source

initialize

Test
lanselambor 4 years ago
parent
commit
969b1dcfe7
  1. 190
      MC20_Arduino_Interface.cpp
  2. 75
      MC20_Arduino_Interface.h
  3. 313
      MC20_BT.cpp
  4. 210
      MC20_BT.h
  5. 368
      MC20_Common.cpp
  6. 203
      MC20_Common.h
  7. 618
      MC20_GNSS.cpp
  8. 163
      MC20_GNSS.h
  9. 258
      MC20_GPRS.cpp
  10. 115
      MC20_GPRS.h
  11. 28
      README.md
  12. 25
      examples/Button_LightSensor/Button_LightSensor.ino
  13. 18
      examples/Check_battery/Check_battery.ino
  14. 99
      examples/I2C_3Axis/I2C_3Axis.ino
  15. 39
      examples/MC20_BlueTooth/BT_ClientHandle/BT_ClientHandle.ino
  16. 36
      examples/MC20_BlueTooth/BT_FastConnect/BT_FastConnect.ino
  17. 53
      examples/MC20_BlueTooth/BT_ScanDeviceID/BT_ScanDeviceID.ino
  18. 46
      examples/MC20_CallUp/MC20_CallUp.ino
  19. 32
      examples/MC20_GNSS/GNSS_DataFlowMode/GNSS_DataFlowMode.ino
  20. 111
      examples/MC20_GNSS/GNSS_Google_KML/GNSS_Google_KML.ino
  21. 53
      examples/MC20_GNSS/GNSS_LP_Mode/GNSS_LP_Mode.ino
  22. 37
      examples/MC20_GNSS/GNSS_Show_Coordinate/GNSS_Show_Coordinate.ino
  23. 49
      examples/MC20_GPRSHTTP/MC20_GPRSHTTP.ino
  24. 43
      examples/MC20_GSMRSSI/MC20_GSMRSSI.ino
  25. 56
      examples/MC20_SMSRead/MC20_SMSRead.ino
  26. 38
      examples/MC20_SMSSend/MC20_SMSSend.ino
  27. 32
      examples/RGB_LED/RGB_LED.ino
  28. 65
      examples/SD_Card_Test_DumpFile/SD_Card_Test_DumpFile.ino
  29. 27
      examples/SerialDebug/SerialDebug.ino
  30. 192
      examples/TestSamples/GNSSWorkMode/GSM_full_function_mode/GSM_full_function_mode.ino
  31. 81
      examples/TestSamples/GNSSWorkMode/GSM_on_GNSS_1PPS_mode/GSM_on_GNSS_1PPS_mode.ino
  32. 76
      examples/TestSamples/GNSSWorkMode/GSM_on_GNSS_GPL_mode/GSM_on_GNSS_GPL_mode.ino
  33. 80
      examples/TestSamples/GNSSWorkMode/GSM_on_GNSS_alwaysLocation/GSM_on_GNSS_alwaysLocation.ino
  34. 76
      examples/TestSamples/GNSSWorkMode/GSM_on_GNSS_changeMode/GSM_on_GNSS_changeMode.ino
  35. 66
      examples/TestSamples/GNSSWorkMode/GSM_on_GNSS_default/GSM_on_GNSS_default.ino
  36. 194
      examples/TestSamples/MCU_Sleep/MCU_Sleep.ino

190
MC20_Arduino_Interface.cpp

@ -0,0 +1,190 @@
/*
* MC20_Common.cpp
* A library for SeeedStudio GPS Tracker
*
* Copyright (c) 2017 seeed technology inc.
* Website : www.seeed.cc
* Author : lawliet zou, lambor
* Create Time: April 2017
* Change Log :
*
* The MIT License (MIT)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "MC20_Arduino_Interface.h"
void MC20_init()
{
serialMC20.begin(115200);
}
int MC20_check_readable()
{
return serialMC20.available();
}
int MC20_wait_readable (int wait_time)
{
unsigned long timerStart;
int dataLen = 0;
timerStart = millis();
while((unsigned long) (millis() - timerStart) > wait_time * 1000UL) {
delay(500);
dataLen = MC20_check_readable();
if(dataLen > 0){
break;
}
}
return dataLen;
}
void MC20_flush_serial()
{
while(MC20_check_readable()){
serialMC20.read();
}
}
void MC20_read_buffer(char *buffer, int count, unsigned int timeout, unsigned int chartimeout)
{
int i = 0;
unsigned long timerStart, prevChar;
timerStart = millis();
prevChar = 0;
while(1) {
while (MC20_check_readable()) {
char c = serialMC20.read();
prevChar = millis();
buffer[i++] = c;
if(i >= count)break;
}
if(i >= count)break;
if ((unsigned long) (millis() - timerStart) > timeout * 1000UL) {
break;
}
//If interchar Timeout => return FALSE. So we can return sooner from this function. Not DO it if we dont recieve at least one char (prevChar <> 0)
if (((unsigned long) (millis() - prevChar) > chartimeout) && (prevChar != 0)) {
break;
}
}
}
void MC20_clean_buffer(char *buffer, int count)
{
for(int i=0; i < count; i++) {
buffer[i] = '\0';
}
}
//HACERR quitar esta funcion ?
void MC20_send_byte(uint8_t data)
{
serialMC20.write(data);
}
void MC20_send_char(const char c)
{
serialMC20.write(c);
}
void MC20_send_cmd(const char* cmd)
{
for(uint16_t i=0; i<strlen(cmd); i++)
{
MC20_send_byte(cmd[i]);
}
}
void MC20_send_cmd(const __FlashStringHelper* cmd)
{
int i = 0;
const char *ptr = (const char *) cmd;
while (pgm_read_byte(ptr + i) != 0x00) {
MC20_send_byte(pgm_read_byte(ptr + i++));
}
}
void MC20_send_cmd_P(const char* cmd)
{
while (pgm_read_byte(cmd) != 0x00)
MC20_send_byte(pgm_read_byte(cmd++));
}
boolean MC20_Test_AT(void)
{
return MC20_check_with_cmd("AT\r\n","OK",CMD);
}
void MC20_send_End_Mark(void)
{
MC20_send_byte((char)26);
}
boolean MC20_wait_for_resp(const char* resp, DataType type, unsigned int timeout, unsigned int chartimeout, bool debug)
{
int len = strlen(resp);
int sum = 0;
unsigned long timerStart, prevChar; //prevChar is the time when the previous Char has been read.
timerStart = millis();
prevChar = 0;
while(1) {
if(MC20_check_readable()) {
char c = serialMC20.read();
if(debug){
serialDebug.write(c);
}
prevChar = millis();
sum = (c==resp[sum]) ? sum+1 : 0;
if(sum == len)break;
}
if ((unsigned long) (millis() - timerStart) > timeout * 1000UL) {
return false;
}
//If interchar Timeout => return FALSE. So we can return sooner from this function.
if (((unsigned long) (millis() - prevChar) > chartimeout) && (prevChar != 0)) {
return false;
}
}
#ifdef UART_DEBUG
serialDebug.println();
#endif
//If is a CMD, we will finish to read buffer.
if(type == CMD) MC20_flush_serial();
return true;
}
boolean MC20_check_with_cmd(const char* cmd, const char *resp, DataType type, unsigned int timeout, unsigned int chartimeout, bool debug)
{
MC20_send_cmd(cmd);
return MC20_wait_for_resp(resp,type,timeout,chartimeout,debug);
}
//HACERR que tambien la respuesta pueda ser FLASH STRING
boolean MC20_check_with_cmd(const __FlashStringHelper* cmd, const char *resp, DataType type, unsigned int timeout, unsigned int chartimeout, bool debug)
{
MC20_send_cmd(cmd);
return MC20_wait_for_resp(resp,type,timeout,chartimeout,debug);
}

75
MC20_Arduino_Interface.h

@ -0,0 +1,75 @@
/*
* MC20_Common.h
* A library for SeeedStudio GPS Tracker
*
* Copyright (c) 2017 seeed technology inc.
* Website : www.seeed.cc
* Author : lawliet zou, lambor
* Create Time: April 2017
* Change Log :
*
* The MIT License (MIT)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef __MC20_ARDUINO_INTERFACE_H__
#define __MC20_ARDUINO_INTERFACE_H__
#include <Arduino.h>
#define serialMC20 Serial1
#define serialDebug SerialUSB
#define DEFAULT_TIMEOUT 5 //seconds
#define DEFAULT_INTERCHAR_TIMEOUT 3000 //miliseconds
#define UART_DEBUG true
#ifdef UART_DEBUG
#define ERROR(x) SerialUSB.println(x)
#define DEBUG(x) SerialUSB.println(x)
#else
#define ERROR(x)
#define DEBUG(x)
#endif
enum DataType {
CMD = 0,
DATA = 1,
};
void MC20_init();
int MC20_check_readable();
int MC20_wait_readable(int wait_time);
void MC20_flush_serial();
void MC20_read_buffer(char* buffer,int count, unsigned int timeout = DEFAULT_TIMEOUT, unsigned int chartimeout = DEFAULT_INTERCHAR_TIMEOUT);
void MC20_clean_buffer(char* buffer, int count);
void MC20_send_byte(uint8_t data);
void MC20_send_char(const char c);
void MC20_send_cmd(const char* cmd);
void MC20_send_cmd(const __FlashStringHelper* cmd);
void MC20_send_cmd_P(const char* cmd);
boolean MC20_Test_AT(void);
void MC20_send_End_Mark(void);
boolean MC20_wait_for_resp(const char* resp, DataType type, unsigned int timeout = DEFAULT_TIMEOUT, unsigned int chartimeout = DEFAULT_INTERCHAR_TIMEOUT, bool debug=false);
boolean MC20_check_with_cmd(const char* cmd, const char *resp, DataType type, unsigned int timeout = DEFAULT_TIMEOUT, unsigned int chartimeout = DEFAULT_INTERCHAR_TIMEOUT*5, bool debug=false);
boolean MC20_check_with_cmd(const __FlashStringHelper* cmd, const char *resp, DataType type, unsigned int timeout = DEFAULT_TIMEOUT, unsigned int chartimeout = DEFAULT_INTERCHAR_TIMEOUT, bool debug=false);
#endif

313
MC20_BT.cpp

@ -0,0 +1,313 @@
/*
* MC20_BT.cpp
* A library for SeeedStudio GPS Tracker BT
*
* Copyright (c) 2017 seeed technology inc.
* Website : www.seeed.cc
* Author : lawliet zou, lambor
* Create Time: April 2017
* Change Log :
*
* The MIT License (MIT)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "MC20_BT.h"
int BlueTooth::BTPowerOn(void)
{
MC20_Test_AT();
if(0 == bluetoothPower){
if( !MC20_check_with_cmd(F("AT+QBTPWR?\r\n"), "+QBTPWR: 1", CMD, DEFAULT_TIMEOUT) )
{
if(!MC20_check_with_cmd(F("AT+QBTPWR=1\r\n"), "OK", CMD, DEFAULT_TIMEOUT)) {
ERROR("\r\nERROR:bluetoothPowerOn\r\n");
return -1;
}else{
bluetoothPower = 1;
}
}
else
bluetoothPower = 1;
}
return 0;
}
int BlueTooth::BTPowerOff(void)
{
if(1 == bluetoothPower){
if(!MC20_check_with_cmd("AT+QBTPWR=0\r\n", "OK", CMD, DEFAULT_TIMEOUT)){
ERROR("\r\nERROR:bluetoothPowerOff\r\n");
return -1;
}else {
bluetoothPower = 0;
}
}
return 0;
}
// int BlueTooth::getHostDeviceName(char* deviceName)
// {
// char Buffer[40];
// char *s,*p;
// int i = 0;
// MC20_send_cmd("AT+BTHOST?\r\n");
// MC20_read_buffer(Buffer,40,DEFAULT_TIMEOUT);
// if(NULL == (s = strstr(Buffer,"+BTHOST:"))) {
// ERROR("\r\nERROR: get host device name error\r\n");
// return -1;
// }
// p = s + 9;//+BTHOST: SIM800H,33:7d:77:18:62:60
// while(*(p) != ','){
// deviceName[i++] = *p;
// p++;
// }
// deviceName[i] = '\0';
// return i;
// }
int BlueTooth::scanForTargetDevice(char* deviceName)
{
char Buffer[256];
char *s;
int deviceID;
MC20_clean_buffer(Buffer,256);
MC20_send_cmd("AT+QBTSCAN\r\n"); //scan 20s
MC20_read_buffer(Buffer,256,30, 30000);//+QBTSCAN: 4,"Mobile",DC0C5CB8C9F1
DEBUG(Buffer);
if(NULL == (s = strstr(Buffer,deviceName))) {
ERROR("\r\nERROR: scan For Target Device error\r\n");
return -1;
}
deviceID = atoi(s-3);
return deviceID;
}
int BlueTooth::sendPairingReqstToDevice(int deviceID)
{
char cmd[30];
if(0 == deviceID)
return -1;
sprintf(cmd,"AT+QBTPAIR=%d\r\n",deviceID);
MC20_send_cmd(cmd);
return 0;
}
int BlueTooth::unPair(void)
{
char cmd[30];
if(0 == targetDeviceID)
return -1;
sprintf(cmd,"AT+QBTUNPAIR=%d\r\n",targetDeviceID);
if(!MC20_check_with_cmd(cmd, "OK", CMD, DEFAULT_TIMEOUT)){
ERROR("\r\nERROR: AT+QBTUNPAIR\r\n");
return -1;
}
return 0;
}
bool BlueTooth::acceptPairing(void)
{
return MC20_check_with_cmd("AT+QBTPAIRCNF=1\r\n", "OK", CMD, 5);
}
int BlueTooth::acceptConnect(void)
{
if(!MC20_check_with_cmd("AT+QBTACPT=1\r\n", "OK", CMD, DEFAULT_TIMEOUT)){
ERROR("\r\nERROR:AT+QBTACPT\r\n");
return -1;
}
return 0;
}
int BlueTooth::disconnect(int targetDeviceID)
{
char cmd[30];
if(0 == targetDeviceID)
return -1;
sprintf(cmd,"AT+QBTDISCONN=%d\r\n",targetDeviceID);
if(!MC20_check_with_cmd(cmd, "OK", CMD, DEFAULT_TIMEOUT)){
ERROR("\r\nERROR: AT+QBTDISCONN\r\n");
return -1;
}
return 0;
}
int BlueTooth::loopHandle(void)
{
char Buffer[100];
MC20_clean_buffer(Buffer,100);
while(!MC20_check_readable());
MC20_read_buffer(Buffer,100,DEFAULT_TIMEOUT);
DEBUG(Buffer);
if(NULL != strstr(Buffer,"+QBTIND: \"pair\"")){
if(!acceptPairing()){
return -1;
ERROR("\r\nERROR:bluetoothAcceptPairing\r\n");
}
}
return 0;
}
// int BlueTooth::connectInSPP(int deviceID) //Serial Port Profile
// {
// char Buffer[200];
// char cmd[20];
// char *s;
// sprintf(cmd,"AT+BTGETPROF=%d\r\n",deviceID);
// MC20_send_cmd(cmd);
// MC20_read_buffer(Buffer,200,DEFAULT_TIMEOUT);
// if(NULL == ( s = strstr(Buffer,"\"SPP\""))) {
// ERROR("\r\nERROR: No SPP Profile\r\n");
// return -1;
// }
// MC20_clean_buffer(cmd,20);
// sprintf(cmd,"AT+BTCONNECT=%d,%c\r\n",deviceID,*(s-2));
// if(!MC20_check_with_cmd(cmd, "OK", CMD, DEFAULT_TIMEOUT)){
// ERROR("\r\nERROR:AT+BTCONNECT\r\n");
// return -1;
// }
// return 0;
// }
// int BlueTooth::recvInSPP(char* data)
// {
// char bluetoothBuffer[64];
// char * p = NULL;
// int count = 0;
// if(!MC20_check_with_cmd("AT+BTSPPGET=0\r\n", "OK", CMD, DEFAULT_TIMEOUT)){
// ERROR("\r\nERROR:AT+BTSPPGET\r\n");
// return -1;
// }
// while(!serialMC20.available()){
// delay(200);
// }
// MC20_read_buffer(bluetoothBuffer,64,DEFAULT_TIMEOUT);
// p = strstr(bluetoothBuffer,"+BTSPPDATA:");
// if(NULL != p){
// p += 11;
// while(count != 2){
// if(*(p++) == ','){
// count++;
// }
// }
// int i = 0;
// while(*(p++) != '$'){
// data[i++] = *p;
// }
// }else{
// ERROR("\r\nERROR: get data error\r\n");
// return -1;
// }
// return 0;
// }
// int BlueTooth::sendInSPP(char* data)
// {
// if(!MC20_check_with_cmd("AT+BTSPPSEND\r\n", ">", CMD, DEFAULT_TIMEOUT)){
// ERROR("\r\nERROR:AT+BTSPPSEND\r\n");
// return -1;
// }
// MC20_send_cmd(data);
// // sendEndMark();
// return 0;
// }
int BlueTooth::getBTState(void)
{
char *s;
char buffer[256];
MC20_clean_buffer(buffer, 256);
MC20_send_cmd("AT+QBTSTATE\r\n");
MC20_read_buffer(buffer, 256, 2, 500);
// +QBTSTATE: 7
int state = -1;
DEBUG(buffer);
if(NULL == (s = strstr(buffer,"+QBTSTATE:"))) {
ERROR("\r\nERROR: Get BT state error!\r\n");
return -1;
}
state = atoi(s+11);
return state;
}
int BlueTooth::getPairedDeviceID(char *deviceName)
{
char Buffer[256];
char *s;
int device_id;
MC20_clean_buffer(Buffer,256);
MC20_send_cmd("AT+QBTSTATE\r\n"); //scan 20s
MC20_read_buffer(Buffer,256,2,1000);//+QBTSCAN: 4,"Mobile",DC0C5CB8C9F1
DEBUG(Buffer);
if(NULL == (s = strstr(Buffer,deviceName))) {
ERROR("\r\nERROR: Device not paired!\r\n");
return -1;
}
device_id = atoi(s-3);
return device_id;
}
bool BlueTooth::BTConnectPairedDevice(int deviceID, int profileName)
{
// char recvBuffer[256];
char sendBuffer[20];
MC20_clean_buffer(sendBuffer, 20);
sprintf(sendBuffer, "AT+QBTCONN=%d,%d\n\r", deviceID, profileName);
bool ret = MC20_check_with_cmd(sendBuffer, "+QBTCONN: 1", CMD, 5);
if(ret) targetDeviceID = deviceID;
return ret;
}
bool BlueTooth::BTFastConnect(char* deviceName, int profileName)
{
// char recvBuffer[256];
char sendBuffer[20];
int deviceID;
bool ret;
MC20_clean_buffer(sendBuffer, 20);
deviceID = getPairedDeviceID(deviceName);
if(-1 == deviceID){
deviceID = scanForTargetDevice(deviceName);
if(0 > deviceID){
return false;
}
sprintf(sendBuffer, "AT+QBTPAIR=%d\n\r", deviceID);
if(!MC20_check_with_cmd(sendBuffer, "+QBTPAIRCNF:", CMD, 5))
{
return false;
}
}
ret = BTConnectPairedDevice(deviceID, profileName);
return ret;
}

210
MC20_BT.h

@ -0,0 +1,210 @@
/*
* MC20_BT.h
* A library for SeeedStudio GPS Tracker BT
*
* Copyright (c) 2017 seeed technology inc.
* Website : www.seeed.cc
* Author : lawliet zou, lambor
* Create Time: April 2017
* Change Log :
*
* The MIT License (MIT)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef __MC20_BT_H__
#define __MC20_BT_H__
#include "MC20_Common.h"
#include "MC20_Arduino_Interface.h"
enum BT_STATE{
INITIAL_ON = 0,
DEACTIVATING = 1,
ACTIVATING = 2,
IDLE = 5,
SCANNING = 6,
SCAN_RESULT_INDICATION = 7,
SCAN_CANCELLING = 8,
INITIATE_PAIRING = 9,
CONNECTING = 12,
UNPAIRING = 13,
DELETING_PAIRED_DEVICE = 14,
DELETING_ALL = 15,
DISCONNECTING = 16,
NUMERIC_CONFIRM = 19,
NUMERIC_CONFIrM_reSPONSE = 20,
CONNECT_ACCEPT_CONFIRM_INDICATION = 25,
SERVICE_REFRESHING = 26,
DEVICe_NAME_SETTING = 29,
AUTHENTICATION_SETTING = 30,
RELEASE_ALL_CONNECTION = 31,
ACTIVATING_PROFILES = 36
};
enum PROFILE_ID{
SPP_PROFILE = 0,
HF_PROFILE = 5,
HFG_PROFILE = 6
};
class BlueTooth : public GPSTracker
{
public:
BlueTooth():GPSTracker(){
}
/** power on BlueTooth module
* @returns
* 0 on success
* -1 on error
*/
int BTPowerOn(void);
/** power off BlueTooth module
* @returns
* 0 on success
* -1 on error
*/
int BTPowerOff(void);
/** get host device name of BlueTooth module
* @param deviceName buffer array to save device name.
* @returns
* 0 on success
* -1 on error
*/
// int getHostDeviceName(char* deviceName);
/** scan for target device according to device name
* @param deviceName device which will be scanned for
* @returns
* 0 on success
* -1 on error
*/
int scanForTargetDevice(char* deviceName);
/** send pairing request to device according to deviceID
* @param deviceID device ID
* @returns
* 0 on success
* -1 on error
*/
int sendPairingReqstToDevice(int deviceID);
/** accept other BlueTooth module's pairing request
* @returns
* true on success
* false on error
*/
bool acceptPairing(void);
/** unPair with paired BlueTooth device
* @returns
* 0 on success
* -1 on error
*/
int unPair(void);
/** accept other BlueTooth device's connecting request
* @returns
* 0 on success
* -1 on error
*/
int acceptConnect(void);
/** wait to handle other BlueTooth device's pairing or connecting request
* @returns
* 0 on success
* -1 on error
*/
int loopHandle(void);
/** disconnect with connected BlueTooth device
* @param deviceID device that will be disconnected
* @returns
* 0 on success
* -1 on error
*/
int disconnect(int deviceID);
/** connect with other BlueTooth device in SPP profile
* @param deviceID device that will be connect in SPP profile
* @returns
* 0 on success
* -1 on error
*/
// int connectInSPP(int deviceID);
/** receive data in SPP profile
* @param data buffer array to receive data from other BlueTooth device in SPP profile
* @returns
* 0 on success
* -1 on error
*/
// int recvInSPP(char* data);
/** send data in SPP profile
* @param data buffer array to send data to other BlueTooth device in SPP profile
* @returns
* 0 on success
* -1 on error
*/
// int sendInSPP(char* data);
/** get BT state
* @return BT_STATE
*/
int getBTState(void);
/** Check if BT device paired and return its id
* @param deviceName BT device name
* @return
* (0,n)paired device ID
* -1 not found
*/
int getPairedDeviceID(char *deviceName);
/** connect paired BT device
* @param deviceID device id
* @param profileName profile name that connecting device in
*/
bool BTConnectPairedDevice(int deviceID, int profileName);
/**
*
*/
bool BTFastConnect(char* deviceID, int profileName);
private:
/** BlueTooth power flag
*/
bool bluetoothPower;
/** target device ID
*/
int targetDeviceID;
};
#endif

368
MC20_Common.cpp

@ -0,0 +1,368 @@
/*
* MC20_Arduino_Interface.cpp
* A library for SeeedStudio GPS Tracker
*
* Copyright (c) 2017 seeed technology inc.
* Website : www.seeed.cc
* Author : lawliet zou, lambor
* Create Time: April 2017
* Change Log :
*
* The MIT License (MIT)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <stdio.h>
#include "MC20_Common.h"
// GPSTracker* GPSTracker::inst;
GPSTracker::GPSTracker()
{
// inst = this;
// MC20_init();
// io_init();
pinMode(RGB_PIN, OUTPUT);
digitalWrite(RGB_PIN, LOW);
}
bool GPSTracker::init(void)
{
if(!MC20_check_with_cmd(F("AT\r\n"),"OK\r\n",CMD)){
return false;
}
if(!MC20_check_with_cmd(F("AT+CPIN?\r\n"),"OK\r\n",CMD)){
return false;
}
if(!checkSIMStatus()) {
return false;
}
return true;
}
bool GPSTracker::Check_If_Power_On(void)
{
return MC20_check_with_cmd(F("AT\n\r"), "OK", CMD, 2, 2000);
}
void GPSTracker::Power_On(void)
{
MC20_init();
if(Check_If_Power_On()){
return;
}
pinMode(PWR_BAT, OUTPUT);
pinMode(PWR_KEY, OUTPUT);
digitalWrite(PWR_BAT, HIGH);
digitalWrite(PWR_KEY, HIGH);
delay(2000);
digitalWrite(PWR_KEY, LOW);
// delay(2000);
}
void GPSTracker::powerReset(void)
{
digitalWrite(PWR_KEY, LOW);
}
void GPSTracker::io_init()
{
for(int i = 0; i< 20; i++){
pinMode(12, OUTPUT);
digitalWrite(i, LOW);
}
}
bool GPSTracker::checkSIMStatus(void)
{
char mc20_Buffer[32];
int count = 0;
MC20_clean_buffer(mc20_Buffer,32);
while(count < 3) {
MC20_send_cmd("AT+CPIN?\r\n");
MC20_read_buffer(mc20_Buffer,32,DEFAULT_TIMEOUT);
if((NULL != strstr(mc20_Buffer,"+CPIN: READY"))) {
break;
}
count++;
delay(300);
}
if(count == 3) {
return false;
}
return true;
}
bool GPSTracker::waitForNetworkRegister(void)
{
int errCounts = 0;
//
while(!MC20_check_with_cmd("AT+CREG?\n\r", "+CREG: 0,1", CMD, 2, 2000)){
errCounts++;
if(errCounts > 30) // Check for 30 times
{
return false;
}
delay(1000);
}
errCounts = 0;
while(!MC20_check_with_cmd("AT+CGREG?\n\r", "+CGREG: 0,1", CMD, 2, 2000)){
errCounts++;
if(errCounts > 30) // Check for 30 times
{
return false;
}
delay(1000);
}
return true;
}
bool GPSTracker::sendSMS(char *number, char *data)
{
//char cmd[32];
if(!MC20_check_with_cmd(F("AT+CMGF=1\r\n"), "OK\r\n", CMD)) { // Set message mode to ASCII
return false;
}
delay(500);
MC20_flush_serial();
MC20_send_cmd("AT+CMGS=\"");
MC20_send_cmd(number);
if(!MC20_check_with_cmd(F("\"\r\n"),">",CMD)) {
return false;
}
delay(1000);
MC20_send_cmd(data);
delay(500);
MC20_send_End_Mark();
return MC20_wait_for_resp("OK\r\n", CMD, 10);
}
bool GPSTracker::readSMS(int messageIndex, char *message, int length, char *phone, char *datetime)
{
/* Response is like:
AT+CMGR=2
+CMGR: "REC READ","XXXXXXXXXXX","","14/10/09,17:30:17+08"
SMS text here
So we need (more or lees), 80 chars plus expected message length in buffer. CAUTION FREE MEMORY
*/
int i = 0;
char mc20_Buffer[80 + length];
//char cmd[16];
char num[4];
char *p,*p2,*s;
MC20_check_with_cmd(F("AT+CMGF=1\r\n"),"OK\r\n",CMD);
delay(1000);
//sprintf(cmd,"AT+CMGR=%d\r\n",messageIndex);
//MC20_send_cmd(cmd);
MC20_send_cmd("AT+CMGR=");
itoa(messageIndex, num, 10);
MC20_send_cmd(num);
MC20_send_cmd("\r\n");
MC20_clean_buffer(mc20_Buffer,sizeof(mc20_Buffer));
MC20_read_buffer(mc20_Buffer,sizeof(mc20_Buffer));
if(NULL != ( s = strstr(mc20_Buffer,"READ\",\""))){
// Extract phone number string
p = strstr(s,",");
p2 = p + 2; //We are in the first phone number character
p = strstr((char *)(p2), "\"");
if (NULL != p) {
i = 0;
while (p2 < p) {
phone[i++] = *(p2++);
}
phone[i] = '\0';
}
// Extract date time string
p = strstr((char *)(p2),",");
p2 = p + 1;
p = strstr((char *)(p2), ",");
p2 = p + 2; //We are in the first date time character
p = strstr((char *)(p2), "\"");
if (NULL != p) {
i = 0;
while (p2 < p) {
datetime[i++] = *(p2++);
}
datetime[i] = '\0';
}
if(NULL != ( s = strstr(s,"\r\n"))){
i = 0;
p = s + 2;
while((*p != '\r')&&(i < length-1)) {
message[i++] = *(p++);
}
message[i] = '\0';
}
return true;
}
return false;
}
bool GPSTracker::readSMS(int messageIndex, char *message,int length)
{
int i = 0;
char mc20_Buffer[100];
//char cmd[16];
char num[4];
char *p,*s;
MC20_check_with_cmd(F("AT+CMGF=1\r\n"),"OK\r\n",CMD);
delay(1000);
MC20_send_cmd("AT+CMGR=");
itoa(messageIndex, num, 10);
MC20_send_cmd(num);
// MC20_send_cmd("\r\n");
MC20_send_cmd("\r\n");
// sprintf(cmd,"AT+CMGR=%d\r\n",messageIndex);
// MC20_send_cmd(cmd);
MC20_clean_buffer(mc20_Buffer,sizeof(mc20_Buffer));
MC20_read_buffer(mc20_Buffer,sizeof(mc20_Buffer),DEFAULT_TIMEOUT);
if(NULL != ( s = strstr(mc20_Buffer,"+CMGR:"))){
if(NULL != ( s = strstr(s,"\r\n"))){
p = s + 2;
while((*p != '\r')&&(i < length-1)) {
message[i++] = *(p++);
}
message[i] = '\0';
return true;
}
}
return false;
}
bool GPSTracker::deleteSMS(int index)
{
//char cmd[16];
char num[4];
//sprintf(cmd,"AT+CMGD=%d\r\n",index);
MC20_send_cmd("AT+CMGD=");
if(index > 998){
MC20_send_cmd("1,4");
}
else{
itoa(index, num, 10);
MC20_send_cmd(num);
}
// We have to wait OK response
//return MC20_check_with_cmd(cmd,"OK\r\n",CMD);
return MC20_check_with_cmd(F("\r"),"OK\r\n",CMD);
}
bool GPSTracker::callUp(char *number)
{
//char cmd[24];
if(!MC20_check_with_cmd(F("AT+COLP=1\r\n"),"OK\r\n",CMD)) {
return false;
}
delay(1000);
//HACERR quitar SPRINTF para ahorar memoria ???
//sprintf(cmd,"ATD%s;\r\n", number);
//MC20_send_cmd(cmd);
MC20_send_cmd("ATD");
MC20_send_cmd(number);
MC20_send_cmd(";\r\n");
return true;
}
void GPSTracker::answer(void)
{
MC20_send_cmd("ATA\r\n"); //TO CHECK: ATA doesnt return "OK" ????
}
bool GPSTracker::hangup(void)
{
return MC20_check_with_cmd(F("ATH\r\n"),"OK\r\n",CMD);
}
bool GPSTracker::getSignalStrength(int *buffer)
{
//AT+CSQ --> 6 + CR = 10
//+CSQ: <rssi>,<ber> --> CRLF + 5 + CRLF = 9
//OK --> CRLF + 2 + CRLF = 6
byte i = 0;
char mc20_Buffer[26];
char *p, *s;
char buffers[4];
MC20_flush_serial();
MC20_send_cmd("AT+CSQ\r");
MC20_clean_buffer(mc20_Buffer, 26);
MC20_read_buffer(mc20_Buffer, 26, DEFAULT_TIMEOUT);
if (NULL != (s = strstr(mc20_Buffer, "+CSQ:"))) {
s = strstr((char *)(s), " ");
s = s + 1; //We are in the first phone number character
p = strstr((char *)(s), ","); //p is last character """
if (NULL != s) {
i = 0;
while (s < p) {
buffers[i++] = *(s++);
}
buffers[i] = '\0';
}
*buffer = atoi(buffers);
return true;
}
return false;
}
int GPSTracker::recv(char* buf, int len)
{
MC20_clean_buffer(buf,len);
MC20_read_buffer(buf,len); //Ya he llamado a la funcion con la longitud del buffer - 1 y luego le estoy añadiendo el 0
return strlen(buf);
}
bool GPSTracker::GSM_work_mode(int mode)
{
char buf_w[20];
MC20_clean_buffer(buf_w, 20);
sprintf(buf_w, "AT+CFUN=%d", mode);
MC20_send_cmd(buf_w);
return MC20_check_with_cmd("\n\r", "OK", CMD, 2, 2000, UART_DEBUG);
}
bool GPSTracker::GSM_config_slow_clk(int mode)
{
char buf_w[20];
MC20_clean_buffer(buf_w, 20);
sprintf(buf_w, "AT+QSCLK=%d", mode);
MC20_send_cmd(buf_w);
return MC20_check_with_cmd("\n\r", "OK", CMD, 2, 2000, UART_DEBUG);
}
bool GPSTracker::AT_PowerDown(void)
{
return MC20_check_with_cmd("AT+QPOWD=1\n\r", "NORMAL POWER DOWN", CMD, 5, 2000, UART_DEBUG);
}

203
MC20_Common.h

@ -0,0 +1,203 @@
/*
* GPSTracker_Arduino_Interface.h
* A library for SeeedStudio GPS Tracker
*
* Copyright (c) 2017 seeed technology inc.
* Website : www.seeed.cc
* Author : lawliet zou, lambor
* Create Time: April 2017
* Change Log :
*
* The MIT License (MIT)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef __MC20_COMMON_H__
#define __MC20_COMMON_H__
#include "MC20_Arduino_Interface.h"
/** GPSTracker class.
* used to realize GPSTracker communication
*/
enum Protocol {
CLOSED = 0,
TCP = 1,
UDP = 2,
};
class GPSTracker
{
public:
/** Create GPSTracker instance
* @param number default phone number during mobile communication
*/
GPSTracker();
/** get instance of GPSTracker class
*/
// static GPSTracker* getInstance() {
// return inst;
// };
/** initialize GPSTracker module including SIM card check & signal strength
* @return true if connected, false otherwise
*/
bool init(void);
/** check if GPSTracker module is powered on or not
* @returns
* true on success
* false on error
*/
bool Check_If_Power_On(void);
/** power Up GPSTracker module
* @param pin D13 is connectted to a power switch IC, the power is on when pin D13 pull up.
* @returns
*
*/
void Power_On(void);
/** power reset for SIM800 board
* @param pin (preconfigurated as OUTPUT)
* @returns
*
*/
void powerReset(void);
void io_init();
/** Wait for network register
*
*
* @returns
* true on success
* false on error
*/
bool waitForNetworkRegister(void);
/** send text SMS
* @param *number phone number which SMS will be send to
* @param *data message that will be send to
* @returns
* true on success
* false on error
*/
bool sendSMS(char* number, char* data);
/** read SMS, phone and date if getting a SMS message. It changes SMS status to READ
* @param messageIndex SIM position to read
* @param message buffer used to get SMS message
* @param length length of message buffer
* @param phone buffer used to get SMS's sender phone number
* @param datetime buffer used to get SMS's send datetime
* @returns
* true on success
* false on error
*/
bool readSMS(int messageIndex, char *message, int length, char *phone, char *datetime);
/** read SMS if getting a SMS message
* @param buffer buffer that get from GPSTracker module(when getting a SMS, GPSTracker module will return a buffer array)
* @param message buffer used to get SMS message
* @param check whether to check phone number(we may only want to read SMS from specified phone number)
* @returns
* true on success
* false on error
*/
bool readSMS(int messageIndex, char *message, int length);
/** delete SMS message on SIM card
* @param index the index number which SMS message will be delete
* index > 998, delete all message stored on SIM card
* @returns
* true on success
* false on error
*/
bool deleteSMS(int index);
/** call someone
* @param number the phone number which you want to call
* @returns
* true on success
* false on error
*/
bool callUp(char* number);
/** auto answer if coming a call
* @returns
*/
void answer(void);
/** hang up if coming a call
* @returns
* true on success
* false on error
*/
bool hangup(void);
/** get Signal Strength from SIM900 (see AT command: AT+CSQ) as integer
* @param
* @returns
* true on success
* false on error
*/
bool getSignalStrength(int *buffer);
int recv(char* buf, int len);
/** GSM power Mode
* @param
* 0, least consumption 1, 4
* 1, standard mode
* 4, shut down RF send and receive function
*/
bool GSM_work_mode(int mode);
/** Config GSM slow clock mode
* @param
* 0 Disable slow clock
* 1 Enable slow clock, and it is controlled by DTR
* 2 When there is no data on serial port in 5 seconds, module will enter Sleep Disable slow clock
*/
bool GSM_config_slow_clk(int mode);
/**
* Turn off module power buy AT commnad
*/
bool AT_PowerDown(void);
// private:
bool checkSIMStatus(void);
int PWR_KEY = 13; // Pulse power control
int PWR_BAT = 7; // BAT power
int RGB_PIN = 10; // RGB LED Pin
int VB_PIN = 12; // VCCB control pin
int DTR_PIN = 9;
};
#endif

618
MC20_GNSS.cpp

@ -0,0 +1,618 @@
/*
* MC20_BT.cpp
* A library for SeeedStudio GPS Tracker BT
*
* Copyright (c) 2017 seeed technology inc.
* Website : www.seeed.cc
* Author : lawliet zou, lambor
* Create Time: April 2017
* Change Log :
*
* The MIT License (MIT)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "MC20_GNSS.h"
bool GNSS::initialize()
{
return true;
}
bool GNSS::close_GNSS()
{
int errCounts = 0;
//Open GNSS funtion
while(!MC20_check_with_cmd("AT+QGNSSC?\n\r", "+QGNSSC: 0", CMD, 2, 2000, UART_DEBUG)){
errCounts ++;
if(errCounts > 5){
return false;
}
MC20_check_with_cmd("AT+QGNSSC=0\n\r", "OK", CMD, 2, 2000, UART_DEBUG);
delay(1000);
}
return true;
}
bool GNSS::open_GNSS(int mode)
{
bool ret = true;
switch(mode){
case GNSS_DEFAULT_MODE:
ret = open_GNSS_default_mode(); // Default GNSS mode
break;
case EPO_QUICK_MODE:
ret = open_GNSS_EPO_quick_mode(); // Quick mode with EPO
break;
case EPO_LP_MODE:
ret = open_GNSS_EPO_LP_mode(); // Low power consumption mode with EPO
break;
case EPO_RL_MODE:
ret = open_GNSS_RL_mode(); // Reference-location mode
break;
};
return ret;
}
bool GNSS::open_GNSS(void)
{
int errCounts = 0;
//Open GNSS funtion
while(!MC20_check_with_cmd("AT+QGNSSC?\n\r", "+QGNSSC: 1", CMD, 2, 2000, UART_DEBUG)){
errCounts ++;
if(errCounts > 5){
return false;
}
MC20_check_with_cmd("AT+QGNSSC=1\n\r", "OK", CMD, 2, 2000, UART_DEBUG);
delay(1000);
}
return true;
}
bool GNSS::open_GNSS_default_mode(void)
{
return open_GNSS();
}
bool GNSS::open_GNSS_EPO_quick_mode(void)
{
//Open GNSS funtion
if(!open_GNSS()){
return false;
}
//
if(!settingContext()){
return false;
}
// Check network register status
if(!isNetworkRegistered()){
return false;
}
// Check time synchronization status
if(!isTimeSynchronized()){
return true; // Return true to work on
}
// Enable EPO funciton
if(!enableEPO()){
return false;
}
// Trigger EPO funciton
if(!triggerEPO()){
return false;
}
return true;
}
bool GNSS::open_GNSS_EPO_LP_mode(void)
{
//
if(!settingContext()){
return false;
}
// Check network register status
if(!isNetworkRegistered()){
return false;
}
// Check time synchronization status
if(!isTimeSynchronized()){
//Open GNSS funtion
if(!open_GNSS()){
return false;
}
return true; // Return true to work on
}
// Enable EPO funciton
if(!enableEPO()){
return false;
}
// Trigger EPO funciton
if(!triggerEPO()){
return false;
}
//Open GNSS funtion
if(!open_GNSS()){
return false;
}
return true;
}
bool GNSS::open_GNSS_RL_mode(void)
{
int errCounts = 0;
char buffer[128];
MC20_clean_buffer(buffer, 128);
//
if(!settingContext()){
return false;
}
// Check network register status
if(!isNetworkRegistered()){
return false;
}
// Check time synchronization status
if(!isTimeSynchronized()){
//Open GNSS funtion
if(!open_GNSS()){
return false;
}
return true; // Return true to work on
}
// Write in reference-location
// sprintf(buffer, "AT+QGREFLOC=%f,%f\n\r", ref_longitude, ref_latitude);
sprintf(buffer, "AT+QGREFLOC=22.584322,113.966678\n\r\n\r");
if(!MC20_check_with_cmd("AT+QGREFLOC=22.584322,113.966678\n\r", "OK", CMD, 2, 2000, UART_DEBUG)){
errCounts++;
if(errCounts > 3)
{
return false;
}
delay(1000);
}
// Enable EPO funciton
if(!enableEPO()){
return false;
}
// Trigger EPO funciton
if(!triggerEPO()){
return false;
}
//Open GNSS funtion
if(!open_GNSS()){
return false;
}
return true;
}
void GNSS::doubleToString(double longitude, double latitude)
{
int u8_lon = (int)longitude;
int u8_lat = (int)latitude;
uint32_t u32_lon = (longitude - u8_lon)*1000000;
uint32_t u32_lat = (