Demo application for the Connection Manager and CellLocate technology.

Dependencies:   C027_Support CNManager mbed

Fork of C027_demo_ConnMan by Marco Sinigaglia

Committer:
msinig
Date:
Fri Jan 22 15:29:51 2016 +0000
Revision:
0:951893313850
Initial drop

Who changed what in which revision?

UserRevisionLine numberNew contents of line
msinig 0:951893313850 1 //------------------------------------------------------------------------------------
msinig 0:951893313850 2 /* This example was tested on C027-U20 and C027-G35 with the on board modem.
msinig 0:951893313850 3
msinig 0:951893313850 4 Additionally it was tested with a shield where the SARA-G350/U260/U270 RX/TX/PWRON
msinig 0:951893313850 5 is connected to D0/D1/D4 and the GPS SCL/SDA is connected D15/D15. In this
msinig 0:951893313850 6 configuration the following platforms were tested (it is likely that others
msinig 0:951893313850 7 will work as well)
msinig 0:951893313850 8 - U-BLOX: C027-G35, C027-U20, C027-C20 (for shield set define C027_FORCE_SHIELD)
msinig 0:951893313850 9 - NXP: LPC1549v2, LPC4088qsb
msinig 0:951893313850 10 - Freescale: FRDM-KL05Z, FRDM-KL25Z, FRDM-KL46Z, FRDM-K64F
msinig 0:951893313850 11 - STM: NUCLEO-F401RE, NUCLEO-F030R8
msinig 0:951893313850 12 mount resistors SB13/14 1k, SB62/63 0R
msinig 0:951893313850 13 */
msinig 0:951893313850 14 #include "GPS.h"
msinig 0:951893313850 15 #include "MDM.h"
msinig 0:951893313850 16 #include "CNManager/CNManager.h"
msinig 0:951893313850 17 //------------------------------------------------------------------------------------
msinig 0:951893313850 18 // You need to configure these cellular modem / SIM parameters.
msinig 0:951893313850 19 // These parameters are ignored for LISA-C200 variants and can be left NULL.
msinig 0:951893313850 20 //------------------------------------------------------------------------------------
msinig 0:951893313850 21 //! Set your secret SIM pin here (e.g. "1234"). Check your SIM manual.
msinig 0:951893313850 22 #define SIMPIN NULL
msinig 0:951893313850 23 /*! The APN of your network operator SIM, sometimes it is "internet" check your
msinig 0:951893313850 24 contract with the network operator. You can also try to look-up your settings in
msinig 0:951893313850 25 google: https://www.google.de/search?q=APN+list */
msinig 0:951893313850 26 #define APN NULL
msinig 0:951893313850 27 //! Set the user name for your APN, or NULL if not needed
msinig 0:951893313850 28 #define USERNAME NULL
msinig 0:951893313850 29 //! Set the password for your APN, or NULL if not needed
msinig 0:951893313850 30 #define PASSWORD NULL
msinig 0:951893313850 31 //------------------------------------------------------------------------------------
msinig 0:951893313850 32
msinig 0:951893313850 33
msinig 0:951893313850 34 //handler function
msinig 0:951893313850 35 void mngHandler(MngEvents ev, void* p){
msinig 0:951893313850 36 if (ev == MNG_EV_IDLE){
msinig 0:951893313850 37 MDMSerial* mdm = cnGetMDM();
msinig 0:951893313850 38 MDMParser::DevStatus devStatus = {};
msinig 0:951893313850 39
msinig 0:951893313850 40 printf("Handler:: Device has been inited correctly\r\n");
msinig 0:951893313850 41 getDevStatus(&devStatus);
msinig 0:951893313850 42 mdm->dumpDevStatus(&devStatus);
msinig 0:951893313850 43 }else if (ev == MNG_EV_DATA_UP){
msinig 0:951893313850 44 MDMParser::NetStatus netStatus = {};
msinig 0:951893313850 45 MDMSerial* mdm = cnGetMDM();
msinig 0:951893313850 46
msinig 0:951893313850 47 printf("Handler:: DATA is now UP\r\n");
msinig 0:951893313850 48 getNetStatus(&netStatus);
msinig 0:951893313850 49 mdm->dumpNetStatus(&netStatus);
msinig 0:951893313850 50 //Token can be released from u-blox site, when you got one replace "TOKEN" below
msinig 0:951893313850 51 //if (!mdm.cellLocSrvTcp("TOKEN"))
msinig 0:951893313850 52 if (!mdm->cellLocSrvTcp("c_vCHm7ifUWKlj3M2t0Bhw"))
msinig 0:951893313850 53 mdm->cellLocSrvUdp();
msinig 0:951893313850 54 mdm->cellLocConfig(1); // Deep scan mode
msinig 0:951893313850 55 mdm->cellLocUnsol(1);
msinig 0:951893313850 56 }
msinig 0:951893313850 57 else if (ev == MNG_EV_DATA_DOWN){
msinig 0:951893313850 58 MDMParser::NetStatus netStatus = {};
msinig 0:951893313850 59 MDMSerial* mdm = cnGetMDM();
msinig 0:951893313850 60
msinig 0:951893313850 61 printf("Handler:: DATA is now DOWN\r\n");
msinig 0:951893313850 62 getNetStatus(&netStatus);
msinig 0:951893313850 63 mdm->dumpNetStatus(&netStatus);
msinig 0:951893313850 64 }
msinig 0:951893313850 65 }
msinig 0:951893313850 66
msinig 0:951893313850 67 int main(void)
msinig 0:951893313850 68 {
msinig 0:951893313850 69 const int wait = 100;
msinig 0:951893313850 70 const int timeoutMargin = 5; // seconds
msinig 0:951893313850 71 const int submitPeriod = 40; // 1 minutes in seconds
msinig 0:951893313850 72 unsigned int j = submitPeriod * 1000/wait;
msinig 0:951893313850 73 bool cellLocWait = false;
msinig 0:951893313850 74 GPSI2C gps;
msinig 0:951893313850 75
msinig 0:951893313850 76 printf("Main::CM\r\n");
msinig 0:951893313850 77 cnInit();
msinig 0:951893313850 78 cnSetApn(APN, USERNAME, PASSWORD);
msinig 0:951893313850 79 cnSetSimPin(SIMPIN);
msinig 0:951893313850 80 cnSetDebug(3);
msinig 0:951893313850 81 cnRegHandler(mngHandler);
msinig 0:951893313850 82
msinig 0:951893313850 83 while (true){
msinig 0:951893313850 84 if (cnIsDataUp()){
msinig 0:951893313850 85 printf("Main:: DATA is UP\r\n");
msinig 0:951893313850 86 MDMSerial* mdm = cnGetMDM();
msinig 0:951893313850 87 if (j++ == submitPeriod * 1000/wait) {
msinig 0:951893313850 88 j=0;
msinig 0:951893313850 89 printf("CellLocate Request\r\n");
msinig 0:951893313850 90 if (mdm->cellLocRequest(MDMParser::CELL_HYBRID, submitPeriod-timeoutMargin, 1,MDMParser::CELL_MULTIHYP, 2))
msinig 0:951893313850 91 cellLocWait = true;
msinig 0:951893313850 92 }
msinig 0:951893313850 93 if (cellLocWait && mdm->cellLocGetExpRes()>0 && mdm->cellLocGetRes() == mdm->cellLocGetExpRes()){
msinig 0:951893313850 94 MDMParser::CellLocData loc;
msinig 0:951893313850 95 cellLocWait = false;
msinig 0:951893313850 96 for(int i=0; i < mdm->cellLocGetRes(); i++){
msinig 0:951893313850 97 mdm->cellLocGetData(&loc, i);
msinig 0:951893313850 98 printf("CellLocate position received number %d, sensor_used: %d\r\n", i, loc.sensor );
msinig 0:951893313850 99 printf(" latitude: %0.5f, longitude: %0.5f, altitute: %d\r\n", loc.latitude, loc.longitude, loc.altitutude);
msinig 0:951893313850 100 if (loc.sensor == 1)
msinig 0:951893313850 101 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);
msinig 0:951893313850 102 }
msinig 0:951893313850 103 }
msinig 0:951893313850 104 else if (cellLocWait && (j%10 == 0 ))
msinig 0:951893313850 105 printf("Waiting for CellLocate...\r\n");
msinig 0:951893313850 106 }
msinig 0:951893313850 107 cnLoop();
msinig 0:951893313850 108 wait_ms(30);
msinig 0:951893313850 109 }
msinig 0:951893313850 110
msinig 0:951893313850 111 gps.powerOff();
msinig 0:951893313850 112 cnSetPower(false);
msinig 0:951893313850 113 return 0;
msinig 0:951893313850 114 }