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
Committer:
wardm
Date:
Sat May 19 11:41:10 2018 +0000
Revision:
12:02d779e8c4f6
Code for Technion Formula car sensors reader transmit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wardm 12:02d779e8c4f6 1 #ifdef ARDUINO
wardm 12:02d779e8c4f6 2
wardm 12:02d779e8c4f6 3 #include <Arduino.h>
wardm 12:02d779e8c4f6 4 #include "arduino-util.h"
wardm 12:02d779e8c4f6 5 #include <cstdarg>
wardm 12:02d779e8c4f6 6 #include <stdio.h>
wardm 12:02d779e8c4f6 7
wardm 12:02d779e8c4f6 8
wardm 12:02d779e8c4f6 9 char tmpbuf[160];
wardm 12:02d779e8c4f6 10 extern int us_getTicker(void);
wardm 12:02d779e8c4f6 11 extern int s_getTicker(void);
wardm 12:02d779e8c4f6 12 extern Stream *ser;
wardm 12:02d779e8c4f6 13
wardm 12:02d779e8c4f6 14 void
wardm 12:02d779e8c4f6 15 dprintf(const char *format, ...)
wardm 12:02d779e8c4f6 16 {
wardm 12:02d779e8c4f6 17 static volatile bool busy;
wardm 12:02d779e8c4f6 18 if (busy)
wardm 12:02d779e8c4f6 19 return;
wardm 12:02d779e8c4f6 20 busy = true;
wardm 12:02d779e8c4f6 21
wardm 12:02d779e8c4f6 22 int secs = s_getTicker();
wardm 12:02d779e8c4f6 23 int s = secs % 60;
wardm 12:02d779e8c4f6 24 int m = secs / 60;
wardm 12:02d779e8c4f6 25 int h = secs / 3600;
wardm 12:02d779e8c4f6 26 int us = us_getTicker() % 1000000;
wardm 12:02d779e8c4f6 27
wardm 12:02d779e8c4f6 28 snprintf(tmpbuf, sizeof(tmpbuf)-1, "%02d:%02d:%02d.%.06d ", h, m, s, us);
wardm 12:02d779e8c4f6 29 ser->write(tmpbuf, (int) sizeof "00:00:34.3436868 " -1);
wardm 12:02d779e8c4f6 30
wardm 12:02d779e8c4f6 31 va_list arg;
wardm 12:02d779e8c4f6 32 va_start(arg, format);
wardm 12:02d779e8c4f6 33 int len = vsnprintf(tmpbuf, sizeof(tmpbuf)-3, format, arg);
wardm 12:02d779e8c4f6 34 tmpbuf[len] = '\r';
wardm 12:02d779e8c4f6 35 tmpbuf[len+1] = '\n';
wardm 12:02d779e8c4f6 36 tmpbuf[len+2] = 0;
wardm 12:02d779e8c4f6 37 ser->write(tmpbuf, len+3);
wardm 12:02d779e8c4f6 38 va_end(arg);
wardm 12:02d779e8c4f6 39 busy = false;
wardm 12:02d779e8c4f6 40 }
wardm 12:02d779e8c4f6 41
wardm 12:02d779e8c4f6 42 void
wardm 12:02d779e8c4f6 43 rprintf(const char *format, ...)
wardm 12:02d779e8c4f6 44 {
wardm 12:02d779e8c4f6 45 va_list arg;
wardm 12:02d779e8c4f6 46 va_start(arg, format);
wardm 12:02d779e8c4f6 47 int len = vsnprintf(tmpbuf, sizeof(tmpbuf)-3, format, arg);
wardm 12:02d779e8c4f6 48 tmpbuf[len] = 0;
wardm 12:02d779e8c4f6 49 ser->write(tmpbuf, len+1);
wardm 12:02d779e8c4f6 50 va_end(arg);
wardm 12:02d779e8c4f6 51 }
wardm 12:02d779e8c4f6 52
wardm 12:02d779e8c4f6 53 void
wardm 12:02d779e8c4f6 54 dump(const char *title, const void *data, int len)
wardm 12:02d779e8c4f6 55 {
wardm 12:02d779e8c4f6 56 dprintf("dump(\"%s\", 0x%x, %d bytes)", title, data, len);
wardm 12:02d779e8c4f6 57
wardm 12:02d779e8c4f6 58 int i, j, cnt;
wardm 12:02d779e8c4f6 59 unsigned char *u;
wardm 12:02d779e8c4f6 60 const int width = 16;
wardm 12:02d779e8c4f6 61 const int seppos = 7;
wardm 12:02d779e8c4f6 62
wardm 12:02d779e8c4f6 63 cnt = 0;
wardm 12:02d779e8c4f6 64 u = (unsigned char *)data;
wardm 12:02d779e8c4f6 65 while (len > 0) {
wardm 12:02d779e8c4f6 66 rprintf("%08x: ", (unsigned int)data + cnt);
wardm 12:02d779e8c4f6 67 cnt += width;
wardm 12:02d779e8c4f6 68 j = len < width ? len : width;
wardm 12:02d779e8c4f6 69 for (i = 0; i < j; i++) {
wardm 12:02d779e8c4f6 70 rprintf("%2.2x ", *(u + i));
wardm 12:02d779e8c4f6 71 if (i == seppos)
wardm 12:02d779e8c4f6 72 ser->write(' ');
wardm 12:02d779e8c4f6 73 }
wardm 12:02d779e8c4f6 74 ser->write(' ');
wardm 12:02d779e8c4f6 75 if (j < width) {
wardm 12:02d779e8c4f6 76 i = width - j;
wardm 12:02d779e8c4f6 77 if (i > seppos + 1)
wardm 12:02d779e8c4f6 78 ser->write(' ');
wardm 12:02d779e8c4f6 79 while (i--) {
wardm 12:02d779e8c4f6 80 ser->print(" ");
wardm 12:02d779e8c4f6 81 }
wardm 12:02d779e8c4f6 82 }
wardm 12:02d779e8c4f6 83 for (i = 0; i < j; i++) {
wardm 12:02d779e8c4f6 84 int c = *(u + i);
wardm 12:02d779e8c4f6 85 if (c >= ' ' && c <= '~')
wardm 12:02d779e8c4f6 86 ser->write(c);
wardm 12:02d779e8c4f6 87 else
wardm 12:02d779e8c4f6 88 ser->write('.');
wardm 12:02d779e8c4f6 89 if (i == seppos)
wardm 12:02d779e8c4f6 90 ser->write(' ');
wardm 12:02d779e8c4f6 91 }
wardm 12:02d779e8c4f6 92 len -= width;
wardm 12:02d779e8c4f6 93 u += width;
wardm 12:02d779e8c4f6 94 ser->print("\r\n");
wardm 12:02d779e8c4f6 95 }
wardm 12:02d779e8c4f6 96 ser->print("--\r\n");
wardm 12:02d779e8c4f6 97
wardm 12:02d779e8c4f6 98 }
wardm 12:02d779e8c4f6 99 #endif