Connection Manager library for u-blox cellular modules. It manages the modem for keeping data connection always active.

Dependents:   C027_demo_ConnMan

Committer:
msinig
Date:
Thu Jan 21 14:00:25 2016 +0000
Revision:
1:29ad1d1ac1f9
Parent:
0:86284a262735
fix bugs

Who changed what in which revision?

UserRevisionLine numberNew contents of line
msinig 0:86284a262735 1 #pragma once
msinig 0:86284a262735 2
msinig 0:86284a262735 3 #include "CNLib.h"
msinig 0:86284a262735 4
msinig 0:86284a262735 5 #define TIMEOUT_RETRY_DATA_CONNECTION (5 * 1000) //!< timeout for bringing up data in case of faults
msinig 0:86284a262735 6 #define TIMEOUT_CHECK_STATUS_DATA_CONNECITION (5 * 1000) //!< timeout for checking data connection status
msinig 0:86284a262735 7 #define TIMEOUT_POLLING_NETWORK_STATUS (5 * 1000) //!< timeout for polling the network status
msinig 0:86284a262735 8 #define MAX_ERROR_RETRIES 5 //!< number of error before reset
msinig 0:86284a262735 9 #define SIM_WAIT_MAX_CYCLE 15 //!< wait cycle for sim init
msinig 1:29ad1d1ac1f9 10 #define MEX_RESP_ERROR 5
msinig 0:86284a262735 11
msinig 1:29ad1d1ac1f9 12 //! Manager events
msinig 1:29ad1d1ac1f9 13 typedef enum {
msinig 1:29ad1d1ac1f9 14 MNG_EV_IDLE, //!< idle
msinig 1:29ad1d1ac1f9 15 MNG_EV_DATA_UP, //!< data connection is active
msinig 1:29ad1d1ac1f9 16 MNG_EV_DATA_DOWN, //!< data connection is active
msinig 1:29ad1d1ac1f9 17 } MngEvents;
msinig 1:29ad1d1ac1f9 18
msinig 0:86284a262735 19
msinig 0:86284a262735 20 /** Function handler for data status updates
msinig 1:29ad1d1ac1f9 21 /param ev new data status
msinig 1:29ad1d1ac1f9 22 /param param void pointer
msinig 0:86284a262735 23 */
msinig 1:29ad1d1ac1f9 24 typedef void (*evMngHandler) (MngEvents ev, void* param);
msinig 0:86284a262735 25
msinig 0:86284a262735 26 /** Init Function
msinig 1:29ad1d1ac1f9 27 This function has to be called before CNMLoop
msinig 0:86284a262735 28 \param powerOn module power status at boot: enabled on, disabled off
msinig 0:86284a262735 29 \param dataEnabled data connection status at boot: enabled on, disabled off
msinig 0:86284a262735 30 \param roomingEnabled unsolicited messages status: enabled on, disabled off
msinig 0:86284a262735 31 \return true if successful false otherwise
msinig 0:86284a262735 32 */
msinig 1:29ad1d1ac1f9 33 bool cnInit(bool powerOn = true, bool dataEnabled = true, bool roomingEnabled = true);
msinig 1:29ad1d1ac1f9 34
msinig 1:29ad1d1ac1f9 35 /**Handler registration
msinig 1:29ad1d1ac1f9 36
msinig 1:29ad1d1ac1f9 37 \param handler Handler for data status changes
msinig 1:29ad1d1ac1f9 38 \param param void paramter to be passed to the handler
msinig 1:29ad1d1ac1f9 39 */
msinig 1:29ad1d1ac1f9 40 void cnRegHandler(evMngHandler handler, void* param=NULL);
msinig 0:86284a262735 41
msinig 0:86284a262735 42 /** Set the debug level.
msinig 1:29ad1d1ac1f9 43 This function has to be called before CNMLoop
msinig 0:86284a262735 44 \param level -1 = OFF, 0 = ERROR, 1 = INFO(default), 2 = TRACE, 3 = ATCMD,TEST
msinig 0:86284a262735 45 \return true if successful, false not possible
msinig 0:86284a262735 46 */
msinig 0:86284a262735 47 bool cnSetDebug(int level);
msinig 0:86284a262735 48
msinig 0:86284a262735 49 /** Cycle the connection manager loop.
msinig 0:86284a262735 50 * \return true if successful, false otherwise
msinig 0:86284a262735 51 */
msinig 0:86284a262735 52 int cnLoop();
msinig 0:86284a262735 53
msinig 0:86284a262735 54 /** force module reset.
msinig 0:86284a262735 55 This function can be called at any time.
msinig 0:86284a262735 56 Force the reset of the connection manager and of the module.
msinig 0:86284a262735 57 */
msinig 0:86284a262735 58 void cnReset();
msinig 0:86284a262735 59
msinig 0:86284a262735 60 /** Set the module power.
msinig 0:86284a262735 61 This function can be called at any time.
msinig 0:86284a262735 62 \param on if true the module is switched on, if false is switched off
msinig 0:86284a262735 63 */
msinig 0:86284a262735 64 void cnSetPower(bool on);
msinig 0:86284a262735 65
msinig 0:86284a262735 66 /** Register (Attach) the MT to the GPRS service.
msinig 0:86284a262735 67 This function can be called at any time.
msinig 0:86284a262735 68 \param enabled if true data connection is requested, if false not.
msinig 0:86284a262735 69 */
msinig 0:86284a262735 70 void cnSetDataEnabled(bool enabled);
msinig 0:86284a262735 71
msinig 0:86284a262735 72 /** Set parameters for the GPRS service.
msinig 1:29ad1d1ac1f9 73 This function has to be called before CNMLoop.
msinig 0:86284a262735 74 If Apn parameters are not set, the internal APN info database will be used.
msinig 0:86284a262735 75 \param apn the of the network provider e.g. "internet" or "apn.provider.com"
msinig 0:86284a262735 76 \param username is the user name text string for the authentication phase
msinig 0:86284a262735 77 \param password is the password text string for the authentication phase
msinig 0:86284a262735 78 \param auth is the authentication mode (CHAP,PAP,NONE or DETECT)
msinig 0:86284a262735 79 */
msinig 0:86284a262735 80 void cnSetApn(const char *apn,const char* username = NULL,const char* password = NULL);
msinig 0:86284a262735 81
msinig 0:86284a262735 82 /** Set Sim pin for unlocking the sim
msinig 0:86284a262735 83 This function has to be called prior to CNMLoop.
msinig 0:86284a262735 84 \param pin of the SIM card
msinig 0:86284a262735 85 */
msinig 0:86284a262735 86 void cnSetSimPin(const char* pin);
msinig 0:86284a262735 87
msinig 0:86284a262735 88 /** Set if rooming is allowed.
msinig 0:86284a262735 89 \param enabled if true rooming is allowed, false it is not
msinig 0:86284a262735 90 */
msinig 0:86284a262735 91 void cnSetRoamingOn(bool enabled);
msinig 0:86284a262735 92
msinig 0:86284a262735 93 /** Get data connection status.
msinig 1:29ad1d1ac1f9 94 * \return yes if connection is up, false otherways
msinig 0:86284a262735 95 */
msinig 1:29ad1d1ac1f9 96 bool cnIsDataUp();
msinig 0:86284a262735 97
msinig 1:29ad1d1ac1f9 98 /** Get the MDM library's pointer.
msinig 1:29ad1d1ac1f9 99 * \return the MDM pointer
msinig 1:29ad1d1ac1f9 100 */
msinig 1:29ad1d1ac1f9 101 MDMSerial* cnGetMDM();
msinig 0:86284a262735 102
msinig 1:29ad1d1ac1f9 103 /** Get a copy of NetStatus.
msinig 1:29ad1d1ac1f9 104 * \param net pointer where NetStatus will be copied into
msinig 0:86284a262735 105 */
msinig 1:29ad1d1ac1f9 106 void getNetStatus(MDMParser::NetStatus* net);
msinig 1:29ad1d1ac1f9 107
msinig 1:29ad1d1ac1f9 108 /** Get a copy of DevStatus.
msinig 1:29ad1d1ac1f9 109 * \param dev pointer where DevStatus will be copied into
msinig 1:29ad1d1ac1f9 110 */
msinig 1:29ad1d1ac1f9 111 void getDevStatus(MDMParser::DevStatus* dev);