Connection Manager library for u-blox cellular modules. It manages the modem for keeping data connection always active.
CNUtil.cpp@1:29ad1d1ac1f9, 2016-01-21 (annotated)
- 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?
User | Revision | Line number | New contents of line |
---|---|---|---|
msinig | 0:86284a262735 | 1 | #include "CNUtil.h" |
msinig | 0:86284a262735 | 2 | #include <stdarg.h> |
msinig | 0:86284a262735 | 3 | |
msinig | 0:86284a262735 | 4 | static int _debugLevel = 1; |
msinig | 0:86284a262735 | 5 | |
msinig | 0:86284a262735 | 6 | int getUtilDebugLevel(){ |
msinig | 0:86284a262735 | 7 | return _debugLevel; |
msinig | 0:86284a262735 | 8 | } |
msinig | 0:86284a262735 | 9 | bool setUtilDebugLevel(int level){ |
msinig | 0:86284a262735 | 10 | #ifdef CN_DEBUG |
msinig | 0:86284a262735 | 11 | if ((_debugLevel >= -1) && (level >= -1) && |
msinig | 0:86284a262735 | 12 | (_debugLevel <= 3) && (level <= 3)) { |
msinig | 0:86284a262735 | 13 | _debugLevel = level; |
msinig | 0:86284a262735 | 14 | return true; |
msinig | 0:86284a262735 | 15 | } |
msinig | 0:86284a262735 | 16 | #endif |
msinig | 0:86284a262735 | 17 | return false; |
msinig | 0:86284a262735 | 18 | } |
msinig | 0:86284a262735 | 19 | |
msinig | 0:86284a262735 | 20 | void debugPrint(int level, const char* color, const char* format, ...) |
msinig | 0:86284a262735 | 21 | { |
msinig | 0:86284a262735 | 22 | #ifdef CN_DEBUG |
msinig | 0:86284a262735 | 23 | if (_debugLevel >= level) |
msinig | 0:86284a262735 | 24 | { |
msinig | 0:86284a262735 | 25 | va_list args; |
msinig | 0:86284a262735 | 26 | va_start (args, format); |
msinig | 0:86284a262735 | 27 | if (color) ::printf(color); |
msinig | 0:86284a262735 | 28 | ::vprintf(format, args); |
msinig | 0:86284a262735 | 29 | if (color) ::printf(DEF); |
msinig | 0:86284a262735 | 30 | va_end (args); |
msinig | 0:86284a262735 | 31 | } |
msinig | 0:86284a262735 | 32 | #endif |
msinig | 0:86284a262735 | 33 | } |
msinig | 0:86284a262735 | 34 | |
msinig | 0:86284a262735 | 35 | void CNTimer::start() { |
msinig | 0:86284a262735 | 36 | if (_counter++ == 0) Timer::start(); |
msinig | 0:86284a262735 | 37 | else Timer::reset(); |
msinig | 0:86284a262735 | 38 | } |
msinig | 0:86284a262735 | 39 | bool CNTimer::isExpired(){ |
msinig | 0:86284a262735 | 40 | if (Timer::read_ms() > _timeout) { |
msinig | 0:86284a262735 | 41 | Timer::reset(); |
msinig | 0:86284a262735 | 42 | return true; |
msinig | 0:86284a262735 | 43 | } |
msinig | 0:86284a262735 | 44 | else return false; |
msinig | 0:86284a262735 | 45 | } |