amq amq / CNManager

Fork of CNManager by u-blox

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers CNUtil.h Source File

CNUtil.h

00001 #pragma once 
00002 
00003 #include "mbed.h"
00004 
00005 #define ISCMEERROR(X)  (X == MDMParser::RESP_ERROR_CME)
00006 #define RESPOK(X)     (X == MDMParser::RESP_OK)
00007 #define BOOLTOSTR(b)  (b?"true":"false")
00008 
00009 /****************************/
00010 //! general response
00011 typedef enum {
00012     RES_OK = 0,                 //! Ok
00013     RES_ERROR = -1,             //! Error
00014     RES_ERROR_STUCK = -2        //! Blocking Error
00015 } CNResp;
00016 
00017 /****************************/
00018 #define CN_DEBUG
00019 
00020 #ifdef CN_DEBUG
00021 #if 1 // colored terminal output using ANSI escape sequences
00022   #define COL(c) "\033[" c
00023  #else
00024   #define COL(c)
00025  #endif
00026  #define DEF COL("39m")
00027  #define BLA COL("30m")
00028  #define RED COL("31m")
00029  #define GRE COL("32m")
00030  #define YEL COL("33m")
00031  #define BLU COL("34m")
00032  #define MAG COL("35m")
00033  #define CYA COL("36m")
00034  #define WHY COL("37m")
00035 
00036 void debugPrint(int level, const char* color, const char* format, ...);
00037 
00038  #define ERROR(...)     debugPrint(0, RED, __VA_ARGS__)
00039  #define INFO(...)      debugPrint(1, GRE, __VA_ARGS__)
00040  #define TRACE(...)     debugPrint(2, DEF, __VA_ARGS__)
00041  #define TEST(...)      debugPrint(3, CYA, __VA_ARGS__)
00042 
00043 #else
00044  #define ERROR(...) (void)0 // no tracing
00045  #define TEST(...)  (void)0 // no tracing
00046  #define INFO(...)  (void)0 // no tracing
00047  #define TRACE(...) (void)0 // no tracing
00048 
00049 #endif
00050 
00051 int getUtilDebugLevel();
00052 bool setUtilDebugLevel(int level);
00053 
00054 /**************************************/
00055 
00056 class CNTimer : Timer {
00057 public:
00058     CNTimer(): Timer(), _counter(0) {}
00059 
00060     void start();
00061     bool isExpired();
00062     bool isOn() { return (_counter > 0);}
00063     void stop() { Timer::stop(); Timer::reset(); _counter = 0;}
00064     void reset() {Timer::reset();}
00065     int read() {return Timer::read_ms();}
00066     int getRetryContunter() {return _counter;}
00067     void setExpireTimeout(int timeout)  {_timeout = timeout;}
00068     int getTimeout() {return _timeout;}
00069 
00070 private:
00071     int _timeout;
00072     int _counter;
00073 };