This is code is part of a Technion course project in advanced IoT, implementing a device to read and transmit sensors data from a Formula racing car built by students at Technion - Israel Institute of Technology.

Dependencies:   mbed Buffer

Fork of DISCO-L072CZ-LRWAN1_LoRa_PingPong by ST

This is code is part of a Technion course project in advanced IoT, implementing a device to read and transmit sensors data from a Formula racing car built by students at Technion - Israel Institute of Technology.

How to install

  • Create an account on Mbed: https://os.mbed.com/account/signup/
  • Import project into Compiler
  • In the Program Workspace select "Formula_Nucleo_Reader"
  • Select a Platform like so:
  1. Click button at top-left
  2. Add Board
  3. Search "B-L072Z-LRWAN1" and then "Add to your Mbed Compiler"
  • Finally click "Compile", if the build was successful, the binary would download automatically
  • To install it on device simply plug it in to a PC, open device drive and drag then drop binary file in it

SX1276GenericLib/Arduino-mbed-APIs/arduino-util.cpp

Committer:
wardm
Date:
2018-05-19
Revision:
12:02d779e8c4f6

File content as of revision 12:02d779e8c4f6:

#ifdef ARDUINO

#include <Arduino.h>
#include "arduino-util.h"
#include <cstdarg>
#include <stdio.h>


char tmpbuf[160];
extern int us_getTicker(void);
extern int s_getTicker(void);
extern Stream *ser;

void
dprintf(const char *format, ...)
{
    static volatile bool busy;
    if (busy)
        return;
    busy = true;
    
    int secs = s_getTicker();
    int s = secs % 60;
    int m = secs / 60;
    int h = secs / 3600;
    int us = us_getTicker() % 1000000;

    snprintf(tmpbuf, sizeof(tmpbuf)-1, "%02d:%02d:%02d.%.06d ", h, m, s, us);
    ser->write(tmpbuf, (int) sizeof "00:00:34.3436868 " -1);

	va_list arg;
	va_start(arg, format);
	int len = vsnprintf(tmpbuf, sizeof(tmpbuf)-3, format, arg);
	tmpbuf[len] = '\r';
	tmpbuf[len+1] = '\n';
	tmpbuf[len+2] = 0;
	ser->write(tmpbuf, len+3);
	va_end(arg);
    busy = false;
}

void
rprintf(const char *format, ...)
{
    va_list arg;
    va_start(arg, format);
    int len = vsnprintf(tmpbuf, sizeof(tmpbuf)-3, format, arg);
    tmpbuf[len] = 0;
    ser->write(tmpbuf, len+1);
    va_end(arg);
}

void
dump(const char *title, const void *data, int len)
{
    dprintf("dump(\"%s\", 0x%x, %d bytes)", title, data, len);
    
    int i, j, cnt;
    unsigned char *u;
    const int width = 16;
    const int seppos = 7;
    
    cnt = 0;
    u = (unsigned char *)data;
    while (len > 0) {
        rprintf("%08x: ", (unsigned int)data + cnt);
        cnt += width;
        j = len < width ? len : width;
        for (i = 0; i < j; i++) {
            rprintf("%2.2x ", *(u + i));
            if (i == seppos)
                ser->write(' ');
        }
        ser->write(' ');
        if (j < width) {
            i = width - j;
            if (i > seppos + 1)
                ser->write(' ');
            while (i--) {
                ser->print("   ");
            }
        }
        for (i = 0; i < j; i++) {
            int c = *(u + i);
            if (c >= ' ' && c <= '~')
                ser->write(c);
            else
                ser->write('.');
            if (i == seppos)
                ser->write(' ');
        }
        len -= width;
        u += width;
        ser->print("\r\n");
    }
    ser->print("--\r\n");
    
}
#endif