A cute tiny piece of code implementing an IoT NAND device, demonstrating how to setup and advertise a cute GATT (NAND) service. The code has been tested on a Nordic nRF51822-DK.

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_HeartRate_IDB0XA1 by ST

bricks/trace.cpp

Committer:
hux
Date:
2017-01-08
Revision:
23:2e73c391bb12

File content as of revision 23:2e73c391bb12:

// trace.cpp - trace a message depending on verbose level
//

#include "bricks/trace.h"

   Serial pc(USBTX, USBRX);            // serial port to PC terminal

//==============================================================================
// Managing the Verbose Lewvel
//==============================================================================

   static int threshold = 0;           // verbose threshold, no verbose messages
  
   void verbose(O&o, int level)        // setup verbose level               
   {
      threshold = level;               // update verbose threshold
   }
   
//==============================================================================
// Printing Trace Messages
//==============================================================================

   void trace(O&o, int level, const char *msg) // trace a message
   {
      if (level <= threshold)          // update verbose threshold
      {  char buf[2] = " ";            // must be terminated
         
         for (; *msg; msg++)
         {  buf[0] = *msg;  
            pc.printf(buf);
            if (*msg == '\n')
            {  buf[0] = '\r';          // auto adding carriage return
               pc.printf(buf);
            }
         }
      }
   }
   
   void trace(O&o, int level, const char*format, int value)
   {
       char buf[80];
       if (strlen(format) > 70)
          trace(o,level," *** buffer overflow *** ");
       else
       {  sprintf(buf,format,value);
          trace(o,level,buf);
       }
   }

   void traceln(O&o, int level, const char*msg)  // trace with CR & LF
   {
       trace(o,level,msg);  trace(o,level,"\r\n");
   }