This is code is part of a Technion course project in advanced IoT, implementing a device to receive and present sensors data from a Formula racing car built by students at Technion - Israel Institute of Technology.
Fork of DISCO-L072CZ-LRWAN1_LoRa_PingPong by
This is code is part of a Technion course project in advanced IoT, implementing a device to receive sensors data from another L072CZ-LRWAN1 installed on a Formula racing car (built by students at Technion - Israel Institute of Technology), and sends it to a GUI presenting the data (GUI project: github.com/ward-mattar/TechnionFormulaGUI).
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_Receiver"
- Select a Platform like so:
- Click button at top-left
- Add Board
- Search "NUCLEO F103RB" 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@12:046346a16ff4, 2018-05-19 (annotated)
- Committer:
- wardm
- Date:
- Sat May 19 15:42:38 2018 +0000
- Revision:
- 12:046346a16ff4
V1.0.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wardm | 12:046346a16ff4 | 1 | #ifdef ARDUINO |
wardm | 12:046346a16ff4 | 2 | |
wardm | 12:046346a16ff4 | 3 | #include <Arduino.h> |
wardm | 12:046346a16ff4 | 4 | #include "arduino-util.h" |
wardm | 12:046346a16ff4 | 5 | #include <cstdarg> |
wardm | 12:046346a16ff4 | 6 | #include <stdio.h> |
wardm | 12:046346a16ff4 | 7 | |
wardm | 12:046346a16ff4 | 8 | |
wardm | 12:046346a16ff4 | 9 | char tmpbuf[160]; |
wardm | 12:046346a16ff4 | 10 | extern int us_getTicker(void); |
wardm | 12:046346a16ff4 | 11 | extern int s_getTicker(void); |
wardm | 12:046346a16ff4 | 12 | extern Stream *ser; |
wardm | 12:046346a16ff4 | 13 | |
wardm | 12:046346a16ff4 | 14 | void |
wardm | 12:046346a16ff4 | 15 | dprintf(const char *format, ...) |
wardm | 12:046346a16ff4 | 16 | { |
wardm | 12:046346a16ff4 | 17 | static volatile bool busy; |
wardm | 12:046346a16ff4 | 18 | if (busy) |
wardm | 12:046346a16ff4 | 19 | return; |
wardm | 12:046346a16ff4 | 20 | busy = true; |
wardm | 12:046346a16ff4 | 21 | |
wardm | 12:046346a16ff4 | 22 | int secs = s_getTicker(); |
wardm | 12:046346a16ff4 | 23 | int s = secs % 60; |
wardm | 12:046346a16ff4 | 24 | int m = secs / 60; |
wardm | 12:046346a16ff4 | 25 | int h = secs / 3600; |
wardm | 12:046346a16ff4 | 26 | int us = us_getTicker() % 1000000; |
wardm | 12:046346a16ff4 | 27 | |
wardm | 12:046346a16ff4 | 28 | snprintf(tmpbuf, sizeof(tmpbuf)-1, "%02d:%02d:%02d.%.06d ", h, m, s, us); |
wardm | 12:046346a16ff4 | 29 | ser->write(tmpbuf, (int) sizeof "00:00:34.3436868 " -1); |
wardm | 12:046346a16ff4 | 30 | |
wardm | 12:046346a16ff4 | 31 | va_list arg; |
wardm | 12:046346a16ff4 | 32 | va_start(arg, format); |
wardm | 12:046346a16ff4 | 33 | int len = vsnprintf(tmpbuf, sizeof(tmpbuf)-3, format, arg); |
wardm | 12:046346a16ff4 | 34 | tmpbuf[len] = '\r'; |
wardm | 12:046346a16ff4 | 35 | tmpbuf[len+1] = '\n'; |
wardm | 12:046346a16ff4 | 36 | tmpbuf[len+2] = 0; |
wardm | 12:046346a16ff4 | 37 | ser->write(tmpbuf, len+3); |
wardm | 12:046346a16ff4 | 38 | va_end(arg); |
wardm | 12:046346a16ff4 | 39 | busy = false; |
wardm | 12:046346a16ff4 | 40 | } |
wardm | 12:046346a16ff4 | 41 | |
wardm | 12:046346a16ff4 | 42 | void |
wardm | 12:046346a16ff4 | 43 | rprintf(const char *format, ...) |
wardm | 12:046346a16ff4 | 44 | { |
wardm | 12:046346a16ff4 | 45 | va_list arg; |
wardm | 12:046346a16ff4 | 46 | va_start(arg, format); |
wardm | 12:046346a16ff4 | 47 | int len = vsnprintf(tmpbuf, sizeof(tmpbuf)-3, format, arg); |
wardm | 12:046346a16ff4 | 48 | tmpbuf[len] = 0; |
wardm | 12:046346a16ff4 | 49 | ser->write(tmpbuf, len+1); |
wardm | 12:046346a16ff4 | 50 | va_end(arg); |
wardm | 12:046346a16ff4 | 51 | } |
wardm | 12:046346a16ff4 | 52 | |
wardm | 12:046346a16ff4 | 53 | void |
wardm | 12:046346a16ff4 | 54 | dump(const char *title, const void *data, int len) |
wardm | 12:046346a16ff4 | 55 | { |
wardm | 12:046346a16ff4 | 56 | dprintf("dump(\"%s\", 0x%x, %d bytes)", title, data, len); |
wardm | 12:046346a16ff4 | 57 | |
wardm | 12:046346a16ff4 | 58 | int i, j, cnt; |
wardm | 12:046346a16ff4 | 59 | unsigned char *u; |
wardm | 12:046346a16ff4 | 60 | const int width = 16; |
wardm | 12:046346a16ff4 | 61 | const int seppos = 7; |
wardm | 12:046346a16ff4 | 62 | |
wardm | 12:046346a16ff4 | 63 | cnt = 0; |
wardm | 12:046346a16ff4 | 64 | u = (unsigned char *)data; |
wardm | 12:046346a16ff4 | 65 | while (len > 0) { |
wardm | 12:046346a16ff4 | 66 | rprintf("%08x: ", (unsigned int)data + cnt); |
wardm | 12:046346a16ff4 | 67 | cnt += width; |
wardm | 12:046346a16ff4 | 68 | j = len < width ? len : width; |
wardm | 12:046346a16ff4 | 69 | for (i = 0; i < j; i++) { |
wardm | 12:046346a16ff4 | 70 | rprintf("%2.2x ", *(u + i)); |
wardm | 12:046346a16ff4 | 71 | if (i == seppos) |
wardm | 12:046346a16ff4 | 72 | ser->write(' '); |
wardm | 12:046346a16ff4 | 73 | } |
wardm | 12:046346a16ff4 | 74 | ser->write(' '); |
wardm | 12:046346a16ff4 | 75 | if (j < width) { |
wardm | 12:046346a16ff4 | 76 | i = width - j; |
wardm | 12:046346a16ff4 | 77 | if (i > seppos + 1) |
wardm | 12:046346a16ff4 | 78 | ser->write(' '); |
wardm | 12:046346a16ff4 | 79 | while (i--) { |
wardm | 12:046346a16ff4 | 80 | ser->print(" "); |
wardm | 12:046346a16ff4 | 81 | } |
wardm | 12:046346a16ff4 | 82 | } |
wardm | 12:046346a16ff4 | 83 | for (i = 0; i < j; i++) { |
wardm | 12:046346a16ff4 | 84 | int c = *(u + i); |
wardm | 12:046346a16ff4 | 85 | if (c >= ' ' && c <= '~') |
wardm | 12:046346a16ff4 | 86 | ser->write(c); |
wardm | 12:046346a16ff4 | 87 | else |
wardm | 12:046346a16ff4 | 88 | ser->write('.'); |
wardm | 12:046346a16ff4 | 89 | if (i == seppos) |
wardm | 12:046346a16ff4 | 90 | ser->write(' '); |
wardm | 12:046346a16ff4 | 91 | } |
wardm | 12:046346a16ff4 | 92 | len -= width; |
wardm | 12:046346a16ff4 | 93 | u += width; |
wardm | 12:046346a16ff4 | 94 | ser->print("\r\n"); |
wardm | 12:046346a16ff4 | 95 | } |
wardm | 12:046346a16ff4 | 96 | ser->print("--\r\n"); |
wardm | 12:046346a16ff4 | 97 | |
wardm | 12:046346a16ff4 | 98 | } |
wardm | 12:046346a16ff4 | 99 | #endif |