support library for C027 helper functions for Buffer Pipes, Buffered Serial Port (rtos capable) and GPS parsing. It includes modem APIs for USSD, SMS and Sockets.
Fork of C027_Support by
Revision 133:57b208dd96fb, committed 2015-11-26
- Comitter:
- msinig
- Date:
- Thu Nov 26 09:42:01 2015 +0000
- Parent:
- 132:de505da3aadf
- Child:
- 134:2fbd5723e063
- Commit message:
- Added CellLocate API
Changed in this revision
MDM.cpp | Show annotated file Show diff for this revision Revisions of this file |
MDM.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/MDM.cpp Wed Nov 11 16:26:19 2015 +0000 +++ b/MDM.cpp Thu Nov 26 09:42:01 2015 +0000 @@ -162,7 +162,7 @@ const char* cmd = buf+3; int a, b, c, d, r; char s[32]; - + // SMS Command --------------------------------- // +CNMI: <mem>,<index> if (sscanf(cmd, "CMTI: \"%*[^\"]\",%d", &a) == 1) { @@ -185,9 +185,19 @@ int socket = _findSocket(a); TRACE("Socket %d: handle %d closed by remote host\r\n", socket, a); if ((socket != SOCKET_ERROR) && _sockets[socket].connected) - _sockets[socket].connected = false; - } - if (_dev.dev == DEV_LISA_C2) { + _sockets[socket].connected = false; + // +UULOC: <date>,<time>,<lat>,<long>,<alt>,<uncertainty>,<speed>, <direction>,<vertical_acc>,<sensor_used>,<SV_used>,<antenna_status>, <jamming_status> + }else if (sscanf(cmd, "UULOC: %d/%d/%d,%d:%d:%d.%*d,%f,%f,%d,%d,%d,%d,%d,%d,%d,%*d,%*d",\ + &_loc.time.tm_mday, &_loc.time.tm_mon, &_loc.time.tm_year, &_loc.time.tm_hour, &_loc.time.tm_min, &_loc.time.tm_sec,\ + &_loc.latitue, &_loc.longitude, &_loc.altitutude, &_loc.uncertainty, &_loc.speed, &_loc.direction, &_loc.verticalAcc, \ + &_loc.sensorUsed, &_loc.svUsed) == 15) { + _loc.time.tm_mon -= 1; + _loc.time.tm_wday=0; + _loc.time.tm_yday=0; + _loc.validData = true; + TRACE("Parsed UULOC position\r\n"); + } + if (_dev.dev == DEV_LISA_C2) { // CDMA Specific ------------------------------------------- // +CREG: <n><SID>,<NID>,<stat> if (sscanf(cmd, "CREG: %*d,%d,%d,%d",&a,&b,&c) == 3) { @@ -512,7 +522,8 @@ { if ((type == TYPE_UNKNOWN) && dev) { if (strstr(buf, "SARA-G35")) *dev = DEV_SARA_G35; - else if (strstr(buf, "LISA-U2")) *dev = DEV_LISA_U2; + else if (strstr(buf, "LISA-U200-03S")) *dev = DEV_LISA_U2_03S; + else if (strstr(buf, "LISA-U2")) *dev = DEV_LISA_U2; else if (strstr(buf, "LISA-C2")) *dev = DEV_LISA_C2; else if (strstr(buf, "SARA-U2")) *dev = DEV_SARA_U2; else if (strstr(buf, "LEON-G2")) *dev = DEV_LEON_G2; @@ -1465,7 +1476,91 @@ } return WAIT; } - +// ---------------------------------------------------------------- +int MDMParser::cellLocSrvHttp (const char* token, const char* server_1, const char* server_2, int days/* = 14*/, \ + int period/* = 4*/, int resolution/* = 1*/) +{ + bool ok = false; + LOCK(); + if (_dev.dev == DEV_LISA_U2_03S || _dev.dev == DEV_SARA_U2 ){ + sendFormated("AT+UGSRV=\"%s\",\"%s\",\"%s\"\r\n", server_1, server_2, token, days, period, resolution); + ok = (RESP_OK == waitFinalResp()); + } else + ok = false; //command not supported by module + UNLOCK(); + return ok; +} + +int MDMParser::cellLocSrvUdp(const char* server_1 /*= "cell-live1.services.u-blox.com"*/, int port /*= 46434*/, \ + int latency/* = 1000*/, int mode/* = 0*/) +{ + bool ok = false; + LOCK(); + if (_dev.dev != DEV_TOBY_L2){ + sendFormated("AT+UGAOP=\"%s\",%d,%d,%d\r\n", server_1, port, latency, mode); + ok = (RESP_OK == waitFinalResp()); + } else + ok = false; //command not supported by module + UNLOCK(); + return ok; +} + +int MDMParser::cellLocUnsolIndication(int mode) +{ + bool ok = false; + LOCK(); + if (_dev.dev == DEV_LISA_U2_03S){ + sendFormated("AT+ULOCIND=%d\r\n", mode); + ok = (RESP_OK == waitFinalResp()); + } else + ok = false; //command not supported by module + UNLOCK(); + return ok; +} + +int MDMParser::cellLocConfigSensor(int scanMode) +{ + bool ok = false; + LOCK(); + if (_dev.dev != DEV_TOBY_L2){ + sendFormated("AT+ULOCCELL=%d\r\n", scanMode); + ok = (RESP_OK == waitFinalResp()); + }else + ok = false; //command not supported by module + UNLOCK(); + return ok; +} + +int MDMParser::cellLocRequest(int sensor, int timeout, int accuracy, int numHypotesis /* =1*/) +{ + bool ok = false; + + LOCK(); + _loc.validData = false; + if (_dev.dev == DEV_LISA_U2_03S){ + sendFormated("AT+ULOC=2,%d,1,%d,%d,%d\r\n", sensor, timeout, accuracy, numHypotesis); + ok = (RESP_OK == waitFinalResp()); + } else if (_dev.dev != DEV_TOBY_L2){ + sendFormated("AT+ULOC=2,%d,1,%d,%d\r\n", sensor, timeout, accuracy); + ok = (RESP_OK == waitFinalResp()); + } + else ok = false; //command not supported by module + + + UNLOCK(); + return ok; +} + +int MDMParser::cellLocGet(CellLocData *data){ + waitFinalResp(NULL,NULL,0); + if (_loc.validData){ + memcpy(data, &_loc, sizeof(_loc)); + _loc.validData = false; + return true; + } + return false; +} + // ---------------------------------------------------------------- bool MDMParser::setDebug(int level) { @@ -1481,7 +1576,7 @@ _DPRINT dprint, void* param) { dprint(param, "Modem::devStatus\r\n"); - const char* txtDev[] = { "Unknown", "SARA-G35", "LISA-U2", "LISA-C2", + const char* txtDev[] = { "Unknown", "SARA-G35", "LISA-U2", "LISA-U2-03S", "LISA-C2", "SARA-U2", "LEON-G2", "TOBY-L2", "MPCI-L2" }; if (status->dev < sizeof(txtDev)/sizeof(*txtDev) && (status->dev != DEV_UNKNOWN)) dprint(param, " Device: %s\r\n", txtDev[status->dev]); @@ -1777,4 +1872,4 @@ int MDMUsb::getLine(char* buffer, int length) { return NOT_FOUND; } -#endif +#endif \ No newline at end of file
--- a/MDM.h Wed Nov 11 16:26:19 2015 +0000 +++ b/MDM.h Thu Nov 26 09:42:01 2015 +0000 @@ -33,7 +33,7 @@ // ---------------------------------------------------------------- //! MT Device Types typedef enum { DEV_UNKNOWN, - DEV_SARA_G35, DEV_LISA_U2, DEV_LISA_C2, + DEV_SARA_G35, DEV_LISA_U2, DEV_LISA_U2_03S, DEV_LISA_C2, DEV_SARA_U2, DEV_LEON_G2, DEV_TOBY_L2, DEV_MPCI_L2 } Dev; //! SIM Status typedef enum { SIM_UNKNOWN, SIM_MISSING, SIM_PIN, SIM_READY } Sim; @@ -69,6 +69,21 @@ unsigned short lac; //!< location area code in hexadecimal format (2 bytes in hex) unsigned int ci; //!< Cell ID in hexadecimal format (2 to 4 bytes in hex) } NetStatus; + //! Cell Locate Data + typedef struct { + bool validData; //!< Flag for indicating if data is valid + struct tm time; //!< GPS Timestamp + float longitude; //!< Estimated longitude, in degrees + float latitue; //!< Estimated latitude, in degrees + int altitutude; //!< Estimated altitude, in meters^2 + int uncertainty; //!< Maximum possible error, in meters + int speed; //!< Speed over ground m/s^2 + int direction; //!< Course over ground in degrees + int verticalAcc; //!< Vertical accuracy, in meters^2 + int sensorUsed; //!< Sensor used for last calculation + int svUsed; //!< number of satellite used + }CellLocData; + //! An IP v4 address typedef uint32_t IP; #define NOIP ((MDMParser::IP)0) //!< No IP address @@ -329,6 +344,55 @@ \return the number of bytes read */ int readFile(const char* filename, char* buf, int len); + // ---------------------------------------------------------------- + // Cell Locate + // ---------------------------------------------------------------- + + /** Configures CellLocate Http Aiding server + \server_1 Host name of the primary MGA server + \server_2 Host name of the secondary MGA server + \token Authentication Token for MGA server access + \days The number of days into the future the Offline data for the u-blox 7 + \period The number of weeks into the future the Offline data for u-blox M8 + \resolution Resolution of offline data for u-blox M8: 1 everyday, 0 every other day + */ + int cellLocSrvHttp(const char* token, const char* server_1 = "cell-live1.services.u-blox.com", \ + const char* server_2 = "cell-live2.services.u-blox.com", int days = 14, int period = 4, int resolution = 1); + + /** Configures CellLocate Udp Aiding server + \server_1 Host name of the primary MGA server + \port Server port + \latency Expected network latency in seconds from 0 to 10000ms + \mode Assist now management, mode of operation: 0 data downloaded at GNSS power up, + 1 automatically kept alive, manual download + */ + int cellLocSrvUdp(const char* server_1 = "cell-live1.services.u-blox.com", int port = 46434, int latency = 1000, int mode = 0); + + /** Configures CellLocate URCs in the case of +ULOC operations + \mode Urc configuration: 0 disabled, 1 enabled + */ + int cellLocUnsolIndication(int mode); + + /** Configures CellLocate location sensor + \scanMode Network scan mode: 0 normal, 1 deep scan + */ + int cellLocConfigSensor(int scanMode); + + /** Request CellLocate + This function is not blocking, the result has to be retrived using cellLocGet + \cb Call back function called when position is available + \sensor Sensor selection: 0: use last fix and stop GNSS receiver, 1: use GNSS, 2: CellLocate, 3: Hybrid + \timeout Timeout period in seconds (1 - 999) + \accuracy Target accuracy in meters (1 - 999999) + \numHypotesis Maximum desired number of responses from CellLocate® (up to 16) + */ + int cellLocRequest(int sensor, int timeout, int accuracy, int numHypotesis =1); + + /** Check if a position is available + \data pointer to a CellLocData struct where the location will be copied in + \return 1 if data is available, 0 otherwise + */ + int cellLocGet(CellLocData *data); // ---------------------------------------------------------------- // DEBUG/DUMP status to standard out (printf) @@ -561,6 +625,7 @@ DevStatus _dev; //!< collected device information NetStatus _net; //!< collected network information IP _ip; //!< assigned ip address + CellLocData _loc; //!< CellLocate data // management struture for sockets typedef struct { int handle; int timeout_ms; volatile bool connected; volatile int pending; } SockCtrl; // LISA-C has 6 TCP and 6 UDP sockets