* add C027_Support fork

Fork of C027_Support by u-blox

Revision:
136:8dc8f48275fc
Parent:
135:cbccf4052d45
Child:
137:6a7a5c4f35f6
--- a/MDM.cpp	Thu Jan 21 15:59:42 2016 +0000
+++ b/MDM.cpp	Fri Jan 22 15:28:39 2016 +0000
@@ -192,17 +192,51 @@
                     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;                
+                        _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");
+                        &_loc[0].time.tm_mday, &_loc[0].time.tm_mon, &_loc[0].time.tm_year, &_loc[0].time.tm_hour, &_loc[0].time.tm_min, &_loc[0].time.tm_sec,\
+                        &_loc[0].latitude, &_loc[0].longitude, &_loc[0].altitutude, &_loc[0].uncertainty, &_loc[0].speed, &_loc[0].direction, &_loc[0].verticalAcc, \
+                        &b, &_loc[0].svUsed) == 15) {
+                    TRACE("Parsed UULOC position at index 0\r\n");                                        
+                    _loc[0].sensor = (b==0)? CELL_LAST : (b==1)? CELL_GNSS : (b==2)? CELL_LOCATE : (b==3)? CELL_HYBRID : CELL_LAST;
+                    _loc[0].time.tm_mon -= 1;
+                    _loc[0].time.tm_wday=0;
+                    _loc[0].time.tm_yday=0;
+                    _loc[0].validData = true;
+                    _locExpPos=1;
+                    _locRcvPos++;
+               // +UULOC: <sol>,<num>,<sensor_used>,<date>,<time>,<lat>,<long>,<alt>,<uncertainty>,<speed>, <direction>,<vertical_acc>,,<SV_used>,<antenna_status>, <jamming_status>                              
+               }else if (sscanf(cmd, "UULOC: %d,%d,%d,%d/%d/%d,%d:%d:%d.%*d,%f,%f,%d,%d,%d,%d,%d,%d,%*d,%*d",\
+                        &a,&_locExpPos,&b, \
+                        &_loc[CELL_MAX_HYP-1].time.tm_mday, &_loc[CELL_MAX_HYP-1].time.tm_mon, &_loc[CELL_MAX_HYP-1].time.tm_year, &_loc[CELL_MAX_HYP-1].time.tm_hour, &_loc[CELL_MAX_HYP-1].time.tm_min, &_loc[CELL_MAX_HYP-1].time.tm_sec,\
+                        &_loc[CELL_MAX_HYP-1].latitude, &_loc[CELL_MAX_HYP-1].longitude, &_loc[CELL_MAX_HYP-1].altitutude, &_loc[CELL_MAX_HYP-1].uncertainty, &_loc[CELL_MAX_HYP-1].speed, &_loc[CELL_MAX_HYP-1].direction, &_loc[CELL_MAX_HYP-1].verticalAcc, \
+                        &_loc[CELL_MAX_HYP-1].svUsed) == 17) {  
+                    if (--a>=0){                         
+                        TRACE("Parsed UULOC position at index %d\r\n",a);                    
+                        memcpy(&_loc[a], &_loc[CELL_MAX_HYP-1], sizeof(*_loc)); 
+                        _loc[a].sensor = (b==0)? CELL_LAST : (b==1)? CELL_GNSS : (b==2)? CELL_LOCATE : (b==3)? CELL_HYBRID : CELL_LAST;                                       
+                        _loc[a].time.tm_mon -= 1;
+                        _loc[a].time.tm_wday=0;
+                        _loc[a].time.tm_yday=0;
+                        _loc[a].validData = true;                    
+                        _locRcvPos++;                                            
+                    }
+              //+UULOC: <sol>,<num>,<sensor_used>,<date>,<time>,<lat>,<long>,<alt>,<lat50>,<long50>,<major50>,<minor50>,<orientation50>,<confidence50>[,<lat95>,<long95>,<major95>,<minor95>,<orientation95>,<confidence95>]
+               }else if (sscanf(cmd, "UULOC: %d,%d,%d,%d/%d/%d,%d:%d:%d.%*d,%f,%f,%d,%*f,%*f,%d,%*d,%*d,%*d",\
+                        &a,&_locExpPos,&b, \
+                        &_loc[CELL_MAX_HYP-1].time.tm_mday, &_loc[CELL_MAX_HYP-1].time.tm_mon, &_loc[CELL_MAX_HYP-1].time.tm_year, &_loc[CELL_MAX_HYP-1].time.tm_hour, &_loc[CELL_MAX_HYP-1].time.tm_min, &_loc[CELL_MAX_HYP-1].time.tm_sec,\
+                        &_loc[CELL_MAX_HYP-1].latitude, &_loc[CELL_MAX_HYP-1].longitude, &_loc[CELL_MAX_HYP-1].altitutude, &_loc[CELL_MAX_HYP-1].uncertainty) == 13) {                    
+                    if (--a>=0){    
+                        TRACE("Parsed UULOC position at index %d\r\n",a);
+                        memcpy(&_loc[a], &_loc[CELL_MAX_HYP-1], sizeof(*_loc));                                        
+                        _loc[a].sensor = (b==0)? CELL_LAST : (b==1)? CELL_GNSS : (b==2)? CELL_LOCATE : (b==3)? CELL_HYBRID : CELL_LAST;
+                        _loc[a].time.tm_mon -= 1;
+                        _loc[a].time.tm_wday=0;
+                        _loc[a].time.tm_yday=0;
+                        _loc[a].validData = true;                    
+                        _locRcvPos++;                    
+                    }                              
                 // +UHTTPCR: <profile_id>,<op_code>,<param_val>
                 } else if ((sscanf(cmd, "UUHTTPCR: %d,%d,%d", &a, &b, &c) == 3)) {
                     _httpProfiles[a].cmd = b;          //command
@@ -252,7 +286,7 @@
                                 else if (a == 5) *reg = REG_ROAMING;  // 5: registered, roaming
                                 else if (a == 6) *reg = REG_HOME;     // 6: registered, sms only, home
                                 if ((r >= 3) && (b != 0xFFFF))      _net.lac = b; // location area code
-                                if ((r >= 4) && (c != 0xFFFFFFFF))  _net.ci  = c; // cell ID
+                                if ((r >= 4) && (c != 0xFFFFFFFF))  _net.ci  = c; // cell ID                                                                                                
                                 // access technology
                                 if (r >= 5) {
                                     if      (d == 0) _net.act = ACT_GSM;      // 0: GSM
@@ -1894,8 +1928,7 @@
 }
 
 // ----------------------------------------------------------------
-
-int MDMParser::cellLocSrvHttp (const char* token, const char* server_1, const char* server_2, int days/* = 14*/, \
+int MDMParser::cellLocSrvTcp(const char* token, const char* server_1, const char* server_2, int days/* = 14*/, \
         int period/* = 4*/, int resolution/* = 1*/)
 {
     bool ok = false;
@@ -1904,7 +1937,7 @@
         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
+        ERROR("Command not supported\r\n"); 
     UNLOCK();
     return ok;
 }
@@ -1918,12 +1951,12 @@
         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
+        ERROR("Command not supported\r\n"); 
     UNLOCK();
     return ok;
 }
 
-int MDMParser::cellLocUnsolIndication(int mode)
+int MDMParser::cellLocUnsol(int mode)
 {
     bool ok = false;
     LOCK();
@@ -1931,12 +1964,12 @@
         sendFormated("AT+ULOCIND=%d\r\n", mode);
         ok = (RESP_OK == waitFinalResp());
     } else
-        ok = false; //command not supported by module
+        ERROR("Command not supported\r\n"); 
     UNLOCK();
     return ok;
 }
 
-int MDMParser::cellLocConfigSensor(int scanMode)
+int MDMParser::cellLocConfig(int scanMode)
 {
     bool ok = false;
     LOCK();
@@ -1944,39 +1977,62 @@
         sendFormated("AT+ULOCCELL=%d\r\n", scanMode);
         ok = (RESP_OK == waitFinalResp());    
     }else
-        ok = false; //command not supported by module
+        ERROR("Command not supported\r\n"); 
     UNLOCK();
     return ok;
 }
 
-int MDMParser::cellLocRequest(int sensor, int timeout, int accuracy, int numHypotesis /* =1*/)
+int MDMParser::cellLocRequest(CellSensType sensor, int timeout, int accuracy, CellRespType type/* =1*/, int hypotesis/* =1*/)
 {
     bool ok = false;
     
-    LOCK();
-     _loc.validData = false;
+    if (hypotesis > 1 && type != CELL_MULTIHYP){
+        ERROR("Num hypotesis is not set accordelying to CellRespType\r\n");
+        return false;
+        }        
+    if (hypotesis > CELL_MAX_HYP){
+        ERROR("Number of hypotesis is too big\r\n");
+        return false;  
+    }        
+    LOCK();      
+    _locRcvPos=0;
+    _locExpPos=0;
+    for (int i=0; i < hypotesis; i++)
+        _loc[i].validData = false;          
     if (_dev.dev == DEV_LISA_U2_03S){
-        sendFormated("AT+ULOC=2,%d,1,%d,%d,%d\r\n", sensor, timeout, accuracy, numHypotesis);
+        sendFormated("AT+ULOC=2,%d,%d,%d,%d,%d\r\n", sensor, type, timeout, accuracy, hypotesis);        
         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
-
-
+    } else
+        ERROR("Command not supported\r\n");  
     UNLOCK();
     return ok;
 }  
-
-int MDMParser::cellLocGet(CellLocData *data){
+int MDMParser::cellLocGetRes()
+{
+    return _locRcvPos;
+}
+int MDMParser::cellLocGetExpRes()
+{
+    int res=0;
     waitFinalResp(NULL,NULL,0);
-    if (_loc.validData){
-        memcpy(data, &_loc, sizeof(_loc));
-        _loc.validData = false;
-        return true;
-    }
-    return false;
+    LOCK();
+    if (_locRcvPos>0)
+        res = _locExpPos;
+    UNLOCK();
+    return res;
+}
+
+int MDMParser::cellLocGetData(CellLocData *data, int index/*=0*/){
+    
+    if (!_loc[index].validData)
+          return false;
+    LOCK(); 
+    memcpy(data, &_loc[index], sizeof(*_loc));
+    UNLOCK();
+    return true;
 }
 
 // ----------------------------------------------------------------