LoRa node acquiring analog input and sending to LoRa Server - Working ok
Dependents: DISCO-L072CZ-LRWAN1_LoRa_node EIoT_LoRa_node_1 EIoT_LoRa_node_2 EIoT_LoRa_node_3
Fork of SX1276GenericLib by
Arduino-mbed-APIs/arduino-util.cpp@79:8ae448a3c1fd, 2017-08-03 (annotated)
- Committer:
- Helmut Tschemernjak
- Date:
- Thu Aug 03 11:59:54 2017 +0200
- Revision:
- 79:8ae448a3c1fd
- Parent:
- 75:7330dd86cdea
- Child:
- 81:d288917af0ce
Fixed a restart-timer problem that the existing timer stop was not re-used.
Fixed a dprintf timestamp problem, we need to limit the u-seconds to 6 digits
Block the dprintf function if it is busy.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Helmut Tschemernjak | 74:66223d437a25 | 1 | #ifdef ARDUINO |
Helmut Tschemernjak | 74:66223d437a25 | 2 | |
Helmut Tschemernjak | 74:66223d437a25 | 3 | #include <Arduino.h> |
Helmut Tschemernjak | 74:66223d437a25 | 4 | #include "arduino-util.h" |
Helmut Tschemernjak | 74:66223d437a25 | 5 | #include <cstdarg> |
Helmut Tschemernjak | 74:66223d437a25 | 6 | #include <stdio.h> |
Helmut Tschemernjak | 74:66223d437a25 | 7 | |
Helmut Tschemernjak | 74:66223d437a25 | 8 | |
Helmut Tschemernjak | 74:66223d437a25 | 9 | char tmpbuf[160]; |
Helmut Tschemernjak | 74:66223d437a25 | 10 | extern int us_getTicker(void); |
Helmut Tschemernjak | 74:66223d437a25 | 11 | extern int s_getTicker(void); |
Helmut Tschemernjak | 75:7330dd86cdea | 12 | extern Stream *ser; |
Helmut Tschemernjak | 74:66223d437a25 | 13 | |
Helmut Tschemernjak | 74:66223d437a25 | 14 | void |
Helmut Tschemernjak | 74:66223d437a25 | 15 | dprintf(const char *format, ...) |
Helmut Tschemernjak | 74:66223d437a25 | 16 | { |
Helmut Tschemernjak | 79:8ae448a3c1fd | 17 | static volatile bool busy; |
Helmut Tschemernjak | 79:8ae448a3c1fd | 18 | if (busy) |
Helmut Tschemernjak | 79:8ae448a3c1fd | 19 | return; |
Helmut Tschemernjak | 79:8ae448a3c1fd | 20 | busy = true; |
Helmut Tschemernjak | 79:8ae448a3c1fd | 21 | |
Helmut Tschemernjak | 74:66223d437a25 | 22 | int secs = s_getTicker(); |
Helmut Tschemernjak | 74:66223d437a25 | 23 | int s = secs % 60; |
Helmut Tschemernjak | 74:66223d437a25 | 24 | int m = secs / 60; |
Helmut Tschemernjak | 74:66223d437a25 | 25 | int h = secs / 3600; |
Helmut Tschemernjak | 79:8ae448a3c1fd | 26 | int us = us_getTicker(); |
Helmut Tschemernjak | 79:8ae448a3c1fd | 27 | while(us > 999999) |
Helmut Tschemernjak | 79:8ae448a3c1fd | 28 | us /= 10; // get it to 6 digits only |
Helmut Tschemernjak | 74:66223d437a25 | 29 | |
Helmut Tschemernjak | 74:66223d437a25 | 30 | snprintf(tmpbuf, sizeof(tmpbuf)-1, "%02d:%02d:%02d.%.06d ", h, m, s, us); |
Helmut Tschemernjak | 75:7330dd86cdea | 31 | ser->write(tmpbuf, (int) sizeof "00:00:34.3436868 " -1); |
Helmut Tschemernjak | 74:66223d437a25 | 32 | |
Helmut Tschemernjak | 74:66223d437a25 | 33 | va_list arg; |
Helmut Tschemernjak | 74:66223d437a25 | 34 | va_start(arg, format); |
Helmut Tschemernjak | 74:66223d437a25 | 35 | int len = vsnprintf(tmpbuf, sizeof(tmpbuf)-3, format, arg); |
Helmut Tschemernjak | 74:66223d437a25 | 36 | tmpbuf[len] = '\r'; |
Helmut Tschemernjak | 74:66223d437a25 | 37 | tmpbuf[len+1] = '\n'; |
Helmut Tschemernjak | 74:66223d437a25 | 38 | tmpbuf[len+2] = 0; |
Helmut Tschemernjak | 75:7330dd86cdea | 39 | ser->write(tmpbuf, len+3); |
Helmut Tschemernjak | 74:66223d437a25 | 40 | va_end(arg); |
Helmut Tschemernjak | 79:8ae448a3c1fd | 41 | busy = false; |
Helmut Tschemernjak | 74:66223d437a25 | 42 | } |
Helmut Tschemernjak | 74:66223d437a25 | 43 | |
Helmut Tschemernjak | 74:66223d437a25 | 44 | void |
Helmut Tschemernjak | 74:66223d437a25 | 45 | rprintf(const char *format, ...) |
Helmut Tschemernjak | 74:66223d437a25 | 46 | { |
Helmut Tschemernjak | 74:66223d437a25 | 47 | va_list arg; |
Helmut Tschemernjak | 74:66223d437a25 | 48 | va_start(arg, format); |
Helmut Tschemernjak | 74:66223d437a25 | 49 | int len = vsnprintf(tmpbuf, sizeof(tmpbuf)-3, format, arg); |
Helmut Tschemernjak | 74:66223d437a25 | 50 | tmpbuf[len] = 0; |
Helmut Tschemernjak | 75:7330dd86cdea | 51 | ser->write(tmpbuf, len+1); |
Helmut Tschemernjak | 74:66223d437a25 | 52 | va_end(arg); |
Helmut Tschemernjak | 74:66223d437a25 | 53 | } |
Helmut Tschemernjak | 74:66223d437a25 | 54 | |
Helmut Tschemernjak | 74:66223d437a25 | 55 | void |
Helmut Tschemernjak | 74:66223d437a25 | 56 | dump(const char *title, const void *data, int len) |
Helmut Tschemernjak | 74:66223d437a25 | 57 | { |
Helmut Tschemernjak | 74:66223d437a25 | 58 | dprintf("dump(\"%s\", 0x%x, %d bytes)", title, data, len); |
Helmut Tschemernjak | 74:66223d437a25 | 59 | |
Helmut Tschemernjak | 74:66223d437a25 | 60 | int i, j, cnt; |
Helmut Tschemernjak | 74:66223d437a25 | 61 | unsigned char *u; |
Helmut Tschemernjak | 74:66223d437a25 | 62 | const int width = 16; |
Helmut Tschemernjak | 74:66223d437a25 | 63 | const int seppos = 7; |
Helmut Tschemernjak | 74:66223d437a25 | 64 | |
Helmut Tschemernjak | 74:66223d437a25 | 65 | cnt = 0; |
Helmut Tschemernjak | 74:66223d437a25 | 66 | u = (unsigned char *)data; |
Helmut Tschemernjak | 74:66223d437a25 | 67 | while (len > 0) { |
Helmut Tschemernjak | 74:66223d437a25 | 68 | rprintf("%08x: ", (unsigned int)data + cnt); |
Helmut Tschemernjak | 74:66223d437a25 | 69 | cnt += width; |
Helmut Tschemernjak | 74:66223d437a25 | 70 | j = len < width ? len : width; |
Helmut Tschemernjak | 74:66223d437a25 | 71 | for (i = 0; i < j; i++) { |
Helmut Tschemernjak | 74:66223d437a25 | 72 | rprintf("%2.2x ", *(u + i)); |
Helmut Tschemernjak | 74:66223d437a25 | 73 | if (i == seppos) |
Helmut Tschemernjak | 75:7330dd86cdea | 74 | ser->write(' '); |
Helmut Tschemernjak | 74:66223d437a25 | 75 | } |
Helmut Tschemernjak | 75:7330dd86cdea | 76 | ser->write(' '); |
Helmut Tschemernjak | 74:66223d437a25 | 77 | if (j < width) { |
Helmut Tschemernjak | 74:66223d437a25 | 78 | i = width - j; |
Helmut Tschemernjak | 74:66223d437a25 | 79 | if (i > seppos + 1) |
Helmut Tschemernjak | 75:7330dd86cdea | 80 | ser->write(' '); |
Helmut Tschemernjak | 74:66223d437a25 | 81 | while (i--) { |
Helmut Tschemernjak | 75:7330dd86cdea | 82 | ser->print(" "); |
Helmut Tschemernjak | 74:66223d437a25 | 83 | } |
Helmut Tschemernjak | 74:66223d437a25 | 84 | } |
Helmut Tschemernjak | 74:66223d437a25 | 85 | for (i = 0; i < j; i++) { |
Helmut Tschemernjak | 74:66223d437a25 | 86 | int c = *(u + i); |
Helmut Tschemernjak | 74:66223d437a25 | 87 | if (c >= ' ' && c <= '~') |
Helmut Tschemernjak | 75:7330dd86cdea | 88 | ser->write(c); |
Helmut Tschemernjak | 74:66223d437a25 | 89 | else |
Helmut Tschemernjak | 75:7330dd86cdea | 90 | ser->write('.'); |
Helmut Tschemernjak | 74:66223d437a25 | 91 | if (i == seppos) |
Helmut Tschemernjak | 75:7330dd86cdea | 92 | ser->write(' '); |
Helmut Tschemernjak | 74:66223d437a25 | 93 | } |
Helmut Tschemernjak | 74:66223d437a25 | 94 | len -= width; |
Helmut Tschemernjak | 74:66223d437a25 | 95 | u += width; |
Helmut Tschemernjak | 75:7330dd86cdea | 96 | ser->print("\r\n"); |
Helmut Tschemernjak | 74:66223d437a25 | 97 | } |
Helmut Tschemernjak | 75:7330dd86cdea | 98 | ser->print("--\r\n"); |
Helmut Tschemernjak | 74:66223d437a25 | 99 | |
Helmut Tschemernjak | 74:66223d437a25 | 100 | } |
Helmut Tschemernjak | 74:66223d437a25 | 101 | #endif |