Connection Manager library for u-blox cellular modules. It manages the modem for keeping data connection always active.
CNManager.h@0:86284a262735, 2016-01-12 (annotated)
- Committer:
- msinig
- Date:
- Tue Jan 12 09:08:15 2016 +0000
- Revision:
- 0:86284a262735
- Child:
- 1:29ad1d1ac1f9
first drop
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:86284a262735 | 10 | |
msinig | 0:86284a262735 | 11 | //! Data events |
msinig | 0:86284a262735 | 12 | typedef enum{ |
msinig | 0:86284a262735 | 13 | DATA_DISCONNECTED = 0, //!< Data channel is down |
msinig | 0:86284a262735 | 14 | DATA_CONNECTED = 1, //!< Data channel is up |
msinig | 0:86284a262735 | 15 | } DataStatus; |
msinig | 0:86284a262735 | 16 | |
msinig | 0:86284a262735 | 17 | /** Function handler for data status updates |
msinig | 0:86284a262735 | 18 | /param ev new data status |
msinig | 0:86284a262735 | 19 | */ |
msinig | 0:86284a262735 | 20 | typedef void (*evDataHandler) (DataStatus ev); |
msinig | 0:86284a262735 | 21 | |
msinig | 0:86284a262735 | 22 | /** Init Function |
msinig | 0:86284a262735 | 23 | This function has to be called prior to CNMLoop |
msinig | 0:86284a262735 | 24 | \param handler Handler for data status changes |
msinig | 0:86284a262735 | 25 | \param powerOn module power status at boot: enabled on, disabled off |
msinig | 0:86284a262735 | 26 | \param dataEnabled data connection status at boot: enabled on, disabled off |
msinig | 0:86284a262735 | 27 | \param roomingEnabled unsolicited messages status: enabled on, disabled off |
msinig | 0:86284a262735 | 28 | \return true if successful false otherwise |
msinig | 0:86284a262735 | 29 | */ |
msinig | 0:86284a262735 | 30 | bool cnInit(evDataHandler handler = NULL, bool powerOn = true, bool dataEnabled = true, bool roomingEnabled = true); |
msinig | 0:86284a262735 | 31 | |
msinig | 0:86284a262735 | 32 | /** Set the debug level. |
msinig | 0:86284a262735 | 33 | This function has to be called prior to CNMLoop |
msinig | 0:86284a262735 | 34 | \param level -1 = OFF, 0 = ERROR, 1 = INFO(default), 2 = TRACE, 3 = ATCMD,TEST |
msinig | 0:86284a262735 | 35 | \return true if successful, false not possible |
msinig | 0:86284a262735 | 36 | */ |
msinig | 0:86284a262735 | 37 | bool cnSetDebug(int level); |
msinig | 0:86284a262735 | 38 | |
msinig | 0:86284a262735 | 39 | /** Cycle the connection manager loop. |
msinig | 0:86284a262735 | 40 | * \return true if successful, false otherwise |
msinig | 0:86284a262735 | 41 | */ |
msinig | 0:86284a262735 | 42 | int cnLoop(); |
msinig | 0:86284a262735 | 43 | |
msinig | 0:86284a262735 | 44 | /** force module reset. |
msinig | 0:86284a262735 | 45 | This function can be called at any time. |
msinig | 0:86284a262735 | 46 | Force the reset of the connection manager and of the module. |
msinig | 0:86284a262735 | 47 | */ |
msinig | 0:86284a262735 | 48 | void cnReset(); |
msinig | 0:86284a262735 | 49 | |
msinig | 0:86284a262735 | 50 | /** Set the module power. |
msinig | 0:86284a262735 | 51 | This function can be called at any time. |
msinig | 0:86284a262735 | 52 | \param on if true the module is switched on, if false is switched off |
msinig | 0:86284a262735 | 53 | */ |
msinig | 0:86284a262735 | 54 | void cnSetPower(bool on); |
msinig | 0:86284a262735 | 55 | |
msinig | 0:86284a262735 | 56 | /** Register (Attach) the MT to the GPRS service. |
msinig | 0:86284a262735 | 57 | This function can be called at any time. |
msinig | 0:86284a262735 | 58 | \param enabled if true data connection is requested, if false not. |
msinig | 0:86284a262735 | 59 | */ |
msinig | 0:86284a262735 | 60 | void cnSetDataEnabled(bool enabled); |
msinig | 0:86284a262735 | 61 | |
msinig | 0:86284a262735 | 62 | /** Set parameters for the GPRS service. |
msinig | 0:86284a262735 | 63 | This function has to be called prior to CNMLoop. |
msinig | 0:86284a262735 | 64 | If Apn parameters are not set, the internal APN info database will be used. |
msinig | 0:86284a262735 | 65 | \param apn the of the network provider e.g. "internet" or "apn.provider.com" |
msinig | 0:86284a262735 | 66 | \param username is the user name text string for the authentication phase |
msinig | 0:86284a262735 | 67 | \param password is the password text string for the authentication phase |
msinig | 0:86284a262735 | 68 | \param auth is the authentication mode (CHAP,PAP,NONE or DETECT) |
msinig | 0:86284a262735 | 69 | */ |
msinig | 0:86284a262735 | 70 | void cnSetApn(const char *apn,const char* username = NULL,const char* password = NULL); |
msinig | 0:86284a262735 | 71 | |
msinig | 0:86284a262735 | 72 | /** Set Sim pin for unlocking the sim |
msinig | 0:86284a262735 | 73 | This function has to be called prior to CNMLoop. |
msinig | 0:86284a262735 | 74 | \param pin of the SIM card |
msinig | 0:86284a262735 | 75 | */ |
msinig | 0:86284a262735 | 76 | void cnSetSimPin(const char* pin); |
msinig | 0:86284a262735 | 77 | |
msinig | 0:86284a262735 | 78 | /** Set if rooming is allowed. |
msinig | 0:86284a262735 | 79 | \param enabled if true rooming is allowed, false it is not |
msinig | 0:86284a262735 | 80 | */ |
msinig | 0:86284a262735 | 81 | void cnSetRoamingOn(bool enabled); |
msinig | 0:86284a262735 | 82 | |
msinig | 0:86284a262735 | 83 | /** Get data connection status. |
msinig | 0:86284a262735 | 84 | * \return dataStatus |
msinig | 0:86284a262735 | 85 | */ |
msinig | 0:86284a262735 | 86 | DataStatus cnGetDataConnStatus(); |
msinig | 0:86284a262735 | 87 | |
msinig | 0:86284a262735 | 88 | |
msinig | 0:86284a262735 | 89 | /** Get the modem library's pointer. |
msinig | 0:86284a262735 | 90 | * \return the MDMParser pointer |
msinig | 0:86284a262735 | 91 | */ |
msinig | 0:86284a262735 | 92 | CNLib* cnGetMDM(); |