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@81:d288917af0ce, 2017-08-05 (annotated)
- Committer:
- Helmut Tschemernjak
- Date:
- Sat Aug 05 16:08:26 2017 +0200
- Revision:
- 81:d288917af0ce
- Parent:
- 79:8ae448a3c1fd
- Child:
- 91:55971936cee4
Use correct usec timestamps
More complete support for RxSignalPending detection
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 | 81:d288917af0ce | 26 | int us = us_getTicker() % 1000000; |
Helmut Tschemernjak | 74:66223d437a25 | 27 | |
Helmut Tschemernjak | 74:66223d437a25 | 28 | snprintf(tmpbuf, sizeof(tmpbuf)-1, "%02d:%02d:%02d.%.06d ", h, m, s, us); |
Helmut Tschemernjak | 75:7330dd86cdea | 29 | ser->write(tmpbuf, (int) sizeof "00:00:34.3436868 " -1); |
Helmut Tschemernjak | 74:66223d437a25 | 30 | |
Helmut Tschemernjak | 74:66223d437a25 | 31 | va_list arg; |
Helmut Tschemernjak | 74:66223d437a25 | 32 | va_start(arg, format); |
Helmut Tschemernjak | 74:66223d437a25 | 33 | int len = vsnprintf(tmpbuf, sizeof(tmpbuf)-3, format, arg); |
Helmut Tschemernjak | 74:66223d437a25 | 34 | tmpbuf[len] = '\r'; |
Helmut Tschemernjak | 74:66223d437a25 | 35 | tmpbuf[len+1] = '\n'; |
Helmut Tschemernjak | 74:66223d437a25 | 36 | tmpbuf[len+2] = 0; |
Helmut Tschemernjak | 75:7330dd86cdea | 37 | ser->write(tmpbuf, len+3); |
Helmut Tschemernjak | 74:66223d437a25 | 38 | va_end(arg); |
Helmut Tschemernjak | 79:8ae448a3c1fd | 39 | busy = false; |
Helmut Tschemernjak | 74:66223d437a25 | 40 | } |
Helmut Tschemernjak | 74:66223d437a25 | 41 | |
Helmut Tschemernjak | 74:66223d437a25 | 42 | void |
Helmut Tschemernjak | 74:66223d437a25 | 43 | rprintf(const char *format, ...) |
Helmut Tschemernjak | 74:66223d437a25 | 44 | { |
Helmut Tschemernjak | 74:66223d437a25 | 45 | va_list arg; |
Helmut Tschemernjak | 74:66223d437a25 | 46 | va_start(arg, format); |
Helmut Tschemernjak | 74:66223d437a25 | 47 | int len = vsnprintf(tmpbuf, sizeof(tmpbuf)-3, format, arg); |
Helmut Tschemernjak | 74:66223d437a25 | 48 | tmpbuf[len] = 0; |
Helmut Tschemernjak | 75:7330dd86cdea | 49 | ser->write(tmpbuf, len+1); |
Helmut Tschemernjak | 74:66223d437a25 | 50 | va_end(arg); |
Helmut Tschemernjak | 74:66223d437a25 | 51 | } |
Helmut Tschemernjak | 74:66223d437a25 | 52 | |
Helmut Tschemernjak | 74:66223d437a25 | 53 | void |
Helmut Tschemernjak | 74:66223d437a25 | 54 | dump(const char *title, const void *data, int len) |
Helmut Tschemernjak | 74:66223d437a25 | 55 | { |
Helmut Tschemernjak | 74:66223d437a25 | 56 | dprintf("dump(\"%s\", 0x%x, %d bytes)", title, data, len); |
Helmut Tschemernjak | 74:66223d437a25 | 57 | |
Helmut Tschemernjak | 74:66223d437a25 | 58 | int i, j, cnt; |
Helmut Tschemernjak | 74:66223d437a25 | 59 | unsigned char *u; |
Helmut Tschemernjak | 74:66223d437a25 | 60 | const int width = 16; |
Helmut Tschemernjak | 74:66223d437a25 | 61 | const int seppos = 7; |
Helmut Tschemernjak | 74:66223d437a25 | 62 | |
Helmut Tschemernjak | 74:66223d437a25 | 63 | cnt = 0; |
Helmut Tschemernjak | 74:66223d437a25 | 64 | u = (unsigned char *)data; |
Helmut Tschemernjak | 74:66223d437a25 | 65 | while (len > 0) { |
Helmut Tschemernjak | 74:66223d437a25 | 66 | rprintf("%08x: ", (unsigned int)data + cnt); |
Helmut Tschemernjak | 74:66223d437a25 | 67 | cnt += width; |
Helmut Tschemernjak | 74:66223d437a25 | 68 | j = len < width ? len : width; |
Helmut Tschemernjak | 74:66223d437a25 | 69 | for (i = 0; i < j; i++) { |
Helmut Tschemernjak | 74:66223d437a25 | 70 | rprintf("%2.2x ", *(u + i)); |
Helmut Tschemernjak | 74:66223d437a25 | 71 | if (i == seppos) |
Helmut Tschemernjak | 75:7330dd86cdea | 72 | ser->write(' '); |
Helmut Tschemernjak | 74:66223d437a25 | 73 | } |
Helmut Tschemernjak | 75:7330dd86cdea | 74 | ser->write(' '); |
Helmut Tschemernjak | 74:66223d437a25 | 75 | if (j < width) { |
Helmut Tschemernjak | 74:66223d437a25 | 76 | i = width - j; |
Helmut Tschemernjak | 74:66223d437a25 | 77 | if (i > seppos + 1) |
Helmut Tschemernjak | 75:7330dd86cdea | 78 | ser->write(' '); |
Helmut Tschemernjak | 74:66223d437a25 | 79 | while (i--) { |
Helmut Tschemernjak | 75:7330dd86cdea | 80 | ser->print(" "); |
Helmut Tschemernjak | 74:66223d437a25 | 81 | } |
Helmut Tschemernjak | 74:66223d437a25 | 82 | } |
Helmut Tschemernjak | 74:66223d437a25 | 83 | for (i = 0; i < j; i++) { |
Helmut Tschemernjak | 74:66223d437a25 | 84 | int c = *(u + i); |
Helmut Tschemernjak | 74:66223d437a25 | 85 | if (c >= ' ' && c <= '~') |
Helmut Tschemernjak | 75:7330dd86cdea | 86 | ser->write(c); |
Helmut Tschemernjak | 74:66223d437a25 | 87 | else |
Helmut Tschemernjak | 75:7330dd86cdea | 88 | ser->write('.'); |
Helmut Tschemernjak | 74:66223d437a25 | 89 | if (i == seppos) |
Helmut Tschemernjak | 75:7330dd86cdea | 90 | ser->write(' '); |
Helmut Tschemernjak | 74:66223d437a25 | 91 | } |
Helmut Tschemernjak | 74:66223d437a25 | 92 | len -= width; |
Helmut Tschemernjak | 74:66223d437a25 | 93 | u += width; |
Helmut Tschemernjak | 75:7330dd86cdea | 94 | ser->print("\r\n"); |
Helmut Tschemernjak | 74:66223d437a25 | 95 | } |
Helmut Tschemernjak | 75:7330dd86cdea | 96 | ser->print("--\r\n"); |
Helmut Tschemernjak | 74:66223d437a25 | 97 | |
Helmut Tschemernjak | 74:66223d437a25 | 98 | } |
Helmut Tschemernjak | 74:66223d437a25 | 99 | #endif |