u-blox / Mbed 2 deprecated C027_demo_ConnMan

Dependencies:   C027_Support CNManager mbed

Fork of C027_demo_ConnMan by Marco Sinigaglia

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 //------------------------------------------------------------------------------------
00002 /* This example was tested on C027-U20 and C027-G35 with the on board modem. 
00003    
00004    Additionally it was tested with a shield where the SARA-G350/U260/U270 RX/TX/PWRON 
00005    is connected to D0/D1/D4 and the GPS SCL/SDA is connected D15/D15. In this 
00006    configuration the following platforms were tested (it is likely that others 
00007    will work as well)
00008    - U-BLOX:    C027-G35, C027-U20, C027-C20 (for shield set define C027_FORCE_SHIELD)
00009    - NXP:       LPC1549v2, LPC4088qsb
00010    - Freescale: FRDM-KL05Z, FRDM-KL25Z, FRDM-KL46Z, FRDM-K64F
00011    - STM:       NUCLEO-F401RE, NUCLEO-F030R8
00012                 mount resistors SB13/14 1k, SB62/63 0R
00013 */
00014 #include "GPS.h"
00015 #include "MDM.h"
00016 #include "CNManager/CNManager.h"
00017 //------------------------------------------------------------------------------------
00018 // You need to configure these cellular modem / SIM parameters.
00019 // These parameters are ignored for LISA-C200 variants and can be left NULL.
00020 //------------------------------------------------------------------------------------
00021 //! Set your secret SIM pin here (e.g. "1234"). Check your SIM manual.
00022 #define SIMPIN      NULL
00023 /*! The APN of your network operator SIM, sometimes it is "internet" check your 
00024     contract with the network operator. You can also try to look-up your settings in 
00025     google: https://www.google.de/search?q=APN+list */
00026 #define APN         NULL
00027 //! Set the user name for your APN, or NULL if not needed
00028 #define USERNAME    NULL
00029 //! Set the password for your APN, or NULL if not needed
00030 #define PASSWORD    NULL 
00031 //------------------------------------------------------------------------------------
00032 
00033 
00034 //handler function
00035 void mngHandler(MngEvents ev, void* p){
00036     if (ev == MNG_EV_IDLE){
00037         MDMSerial* mdm = cnGetMDM();
00038         MDMParser::DevStatus devStatus = {};
00039         
00040         printf("Handler:: Device has been inited correctly\r\n");
00041         getDevStatus(&devStatus);
00042         mdm->dumpDevStatus(&devStatus);        
00043     }else if (ev == MNG_EV_DATA_UP){
00044         MDMParser::NetStatus netStatus = {};
00045         MDMSerial* mdm = cnGetMDM();
00046         
00047         printf("Handler:: DATA is now UP\r\n");
00048         getNetStatus(&netStatus);
00049         mdm->dumpNetStatus(&netStatus);                   
00050         //Token can be released from u-blox site, when you got one replace "TOKEN" below 
00051         //if (!mdm.cellLocSrvTcp("TOKEN"))
00052         if (!mdm->cellLocSrvTcp("c_vCHm7ifUWKlj3M2t0Bhw"))
00053             mdm->cellLocSrvUdp();        
00054         mdm->cellLocConfig(1);   // Deep scan mode
00055         mdm->cellLocUnsol(1);
00056     }
00057     else if (ev == MNG_EV_DATA_DOWN){
00058         MDMParser::NetStatus netStatus = {};
00059         MDMSerial* mdm = cnGetMDM();
00060         
00061         printf("Handler:: DATA is now DOWN\r\n");
00062         getNetStatus(&netStatus);
00063         mdm->dumpNetStatus(&netStatus);                 
00064     }
00065 }
00066 
00067 int main(void)
00068 {    
00069     const int wait = 100;
00070     const int timeoutMargin = 5; // seconds
00071     const int submitPeriod = 40; // 1 minutes in seconds
00072     unsigned int j = submitPeriod * 1000/wait;
00073     bool cellLocWait = false;     
00074     GPSI2C gps; 
00075     
00076     printf("Main::CM\r\n");
00077     cnInit();
00078     cnSetApn(APN, USERNAME, PASSWORD);
00079     cnSetSimPin(SIMPIN);
00080     cnSetDebug(3);    
00081     cnRegHandler(mngHandler);
00082      
00083      while (true){
00084        if (cnIsDataUp()){
00085            printf("Main:: DATA is UP\r\n");
00086            MDMSerial* mdm = cnGetMDM();
00087            if (j++ == submitPeriod * 1000/wait) {   
00088                 j=0;
00089                 printf("CellLocate Request\r\n");
00090                 if (mdm->cellLocRequest(MDMParser::CELL_HYBRID, submitPeriod-timeoutMargin, 1,MDMParser::CELL_MULTIHYP, 2))
00091                     cellLocWait = true;
00092             }                  
00093             if (cellLocWait && mdm->cellLocGetExpRes()>0 && mdm->cellLocGetRes() == mdm->cellLocGetExpRes()){   
00094                 MDMParser::CellLocData loc;  
00095                 cellLocWait = false;     
00096                 for(int i=0; i < mdm->cellLocGetRes(); i++){
00097                     mdm->cellLocGetData(&loc, i);                        
00098                     printf("CellLocate position received number %d, sensor_used: %d\r\n", i, loc.sensor );           
00099                     printf("  latitude: %0.5f, longitude: %0.5f, altitute: %d\r\n", loc.latitude, loc.longitude, loc.altitutude);
00100                     if (loc.sensor == 1)
00101                         printf("  uncertainty: %d, speed: %d, direction: %d, vertical_acc: %d, satellite used: %d \r\n", loc.uncertainty,loc.speed,loc.direction,loc.verticalAcc,loc.svUsed);                                      
00102                 }
00103             }
00104             else if (cellLocWait && (j%10 == 0 ))
00105                 printf("Waiting for CellLocate...\r\n");        
00106          }
00107          cnLoop();
00108          wait_ms(30);
00109      }
00110      
00111     gps.powerOff();
00112     cnSetPower(false);
00113     return 0;
00114 }