Connection Manager library for u-blox cellular modules. It manages the modem for keeping data connection always active.
CNUtil.h@0:86284a262735, 2016-01-12 (annotated)
- Committer:
- msinig
- Date:
- Tue Jan 12 09:08:15 2016 +0000
- Revision:
- 0:86284a262735
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 "mbed.h" |
msinig | 0:86284a262735 | 4 | |
msinig | 0:86284a262735 | 5 | #define ISCMEERROR(X) (X == MDMParser::RESP_ERROR_CME) |
msinig | 0:86284a262735 | 6 | #define RESPOK(X) (X == MDMParser::RESP_OK) |
msinig | 0:86284a262735 | 7 | #define BOOLTOSTR(b) (b?"true":"false") |
msinig | 0:86284a262735 | 8 | |
msinig | 0:86284a262735 | 9 | /****************************/ |
msinig | 0:86284a262735 | 10 | //! general response |
msinig | 0:86284a262735 | 11 | typedef enum { |
msinig | 0:86284a262735 | 12 | RES_OK = 0, //! Ok |
msinig | 0:86284a262735 | 13 | RES_ERROR = -1, //! Error |
msinig | 0:86284a262735 | 14 | RES_ERROR_STUCK = -2 //! Blocking Error |
msinig | 0:86284a262735 | 15 | } CNResp; |
msinig | 0:86284a262735 | 16 | |
msinig | 0:86284a262735 | 17 | /****************************/ |
msinig | 0:86284a262735 | 18 | #define CN_DEBUG |
msinig | 0:86284a262735 | 19 | |
msinig | 0:86284a262735 | 20 | #ifdef CN_DEBUG |
msinig | 0:86284a262735 | 21 | #if 1 // colored terminal output using ANSI escape sequences |
msinig | 0:86284a262735 | 22 | #define COL(c) "\033[" c |
msinig | 0:86284a262735 | 23 | #else |
msinig | 0:86284a262735 | 24 | #define COL(c) |
msinig | 0:86284a262735 | 25 | #endif |
msinig | 0:86284a262735 | 26 | #define DEF COL("39m") |
msinig | 0:86284a262735 | 27 | #define BLA COL("30m") |
msinig | 0:86284a262735 | 28 | #define RED COL("31m") |
msinig | 0:86284a262735 | 29 | #define GRE COL("32m") |
msinig | 0:86284a262735 | 30 | #define YEL COL("33m") |
msinig | 0:86284a262735 | 31 | #define BLU COL("34m") |
msinig | 0:86284a262735 | 32 | #define MAG COL("35m") |
msinig | 0:86284a262735 | 33 | #define CYA COL("36m") |
msinig | 0:86284a262735 | 34 | #define WHY COL("37m") |
msinig | 0:86284a262735 | 35 | |
msinig | 0:86284a262735 | 36 | void debugPrint(int level, const char* color, const char* format, ...); |
msinig | 0:86284a262735 | 37 | |
msinig | 0:86284a262735 | 38 | #define ERROR(...) debugPrint(0, RED, __VA_ARGS__) |
msinig | 0:86284a262735 | 39 | #define INFO(...) debugPrint(1, GRE, __VA_ARGS__) |
msinig | 0:86284a262735 | 40 | #define TRACE(...) debugPrint(2, DEF, __VA_ARGS__) |
msinig | 0:86284a262735 | 41 | #define TEST(...) debugPrint(3, CYA, __VA_ARGS__) |
msinig | 0:86284a262735 | 42 | |
msinig | 0:86284a262735 | 43 | #else |
msinig | 0:86284a262735 | 44 | #define ERROR(...) (void)0 // no tracing |
msinig | 0:86284a262735 | 45 | #define TEST(...) (void)0 // no tracing |
msinig | 0:86284a262735 | 46 | #define INFO(...) (void)0 // no tracing |
msinig | 0:86284a262735 | 47 | #define TRACE(...) (void)0 // no tracing |
msinig | 0:86284a262735 | 48 | |
msinig | 0:86284a262735 | 49 | #endif |
msinig | 0:86284a262735 | 50 | |
msinig | 0:86284a262735 | 51 | int getUtilDebugLevel(); |
msinig | 0:86284a262735 | 52 | bool setUtilDebugLevel(int level); |
msinig | 0:86284a262735 | 53 | |
msinig | 0:86284a262735 | 54 | /**************************************/ |
msinig | 0:86284a262735 | 55 | |
msinig | 0:86284a262735 | 56 | class CNTimer : Timer { |
msinig | 0:86284a262735 | 57 | public: |
msinig | 0:86284a262735 | 58 | CNTimer(): Timer(), _counter(0) {} |
msinig | 0:86284a262735 | 59 | |
msinig | 0:86284a262735 | 60 | void start(); |
msinig | 0:86284a262735 | 61 | bool isExpired(); |
msinig | 0:86284a262735 | 62 | bool isOn() { return (_counter > 0);} |
msinig | 0:86284a262735 | 63 | void stop() { Timer::stop(); Timer::reset(); _counter = 0;} |
msinig | 0:86284a262735 | 64 | void reset() {Timer::reset();} |
msinig | 0:86284a262735 | 65 | int read() {return Timer::read_ms();} |
msinig | 0:86284a262735 | 66 | int getRetryContunter() {return _counter;} |
msinig | 0:86284a262735 | 67 | void setExpireTimeout(int timeout) {_timeout = timeout;} |
msinig | 0:86284a262735 | 68 | int getTimeout() {return _timeout;} |
msinig | 0:86284a262735 | 69 | |
msinig | 0:86284a262735 | 70 | private: |
msinig | 0:86284a262735 | 71 | int _timeout; |
msinig | 0:86284a262735 | 72 | int _counter; |
msinig | 0:86284a262735 | 73 | }; |