![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
updated version with parameters loaded from sdcard
Dependencies: F7_Ethernet mbed MbedJSONValue LCD_DISCO_F746NG mbed-rtos BSP_DISCO_F746NG CANMsg NetworkAPI SDFileSystem_Warning_Fixed GroveStreamsmodified LcdDiscoF746NgTracer JSON
ManageBufferJPA.cpp.orig@16:f0d946e6da36, 2020-12-30 (annotated)
- Committer:
- 38domo
- Date:
- Wed Dec 30 17:22:27 2020 +0000
- Branch:
- jpa
- Revision:
- 16:f0d946e6da36
- Parent:
- 10:41aff2b7acc6
version with updated libs
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
38domo | 10:41aff2b7acc6 | 1 | #include "mbed.h" |
38domo | 10:41aff2b7acc6 | 2 | |
38domo | 10:41aff2b7acc6 | 3 | const int kMaxBufferSize = 125; |
38domo | 10:41aff2b7acc6 | 4 | |
38domo | 10:41aff2b7acc6 | 5 | volatile char bufferSerialUSB[kMaxBufferSize+3]; |
38domo | 10:41aff2b7acc6 | 6 | volatile int idxSerialIntUSB = 0; |
38domo | 10:41aff2b7acc6 | 7 | int idxSerialUserUSB = 0; |
38domo | 10:41aff2b7acc6 | 8 | volatile int msgSerialUSB = 0; |
38domo | 10:41aff2b7acc6 | 9 | |
38domo | 10:41aff2b7acc6 | 10 | volatile char bufferSerial2[kMaxBufferSize+3]; |
38domo | 10:41aff2b7acc6 | 11 | volatile int idxSerialInt2 = 0; |
38domo | 10:41aff2b7acc6 | 12 | int idxSerialUser2 = 0; |
38domo | 10:41aff2b7acc6 | 13 | volatile int msgSerial2 = 0; |
38domo | 10:41aff2b7acc6 | 14 | |
38domo | 10:41aff2b7acc6 | 15 | volatile char bufferSerial7[kMaxBufferSize+3]; |
38domo | 10:41aff2b7acc6 | 16 | volatile int idxSerialInt7 = 0; |
38domo | 10:41aff2b7acc6 | 17 | int idxSerialUser7 = 0; |
38domo | 10:41aff2b7acc6 | 18 | volatile int msgSerial7 = 0; |
38domo | 10:41aff2b7acc6 | 19 | |
38domo | 10:41aff2b7acc6 | 20 | //RawSerial |
38domo | 10:41aff2b7acc6 | 21 | RawSerial serialUSB(USBTX, USBRX); // serial PC |
38domo | 10:41aff2b7acc6 | 22 | RawSerial serial2(PC_6, PC_7); // TX, RX for udp bridge |
38domo | 10:41aff2b7acc6 | 23 | RawSerial serial7(PF_7, PF_6); // TX, RX for extension |
38domo | 10:41aff2b7acc6 | 24 | volatile char x; |
38domo | 10:41aff2b7acc6 | 25 | // --------------------------------------------------- |
38domo | 10:41aff2b7acc6 | 26 | void serialUSB_int_recv() |
38domo | 10:41aff2b7acc6 | 27 | { |
38domo | 10:41aff2b7acc6 | 28 | if(serialUSB.readable()) |
38domo | 10:41aff2b7acc6 | 29 | { |
38domo | 10:41aff2b7acc6 | 30 | bufferSerialUSB[idxSerialIntUSB]=(serialUSB.getc()); |
38domo | 10:41aff2b7acc6 | 31 | idxSerialIntUSB++; |
38domo | 10:41aff2b7acc6 | 32 | if (idxSerialIntUSB >= kMaxBufferSize) {idxSerialIntUSB = 0;} |
38domo | 10:41aff2b7acc6 | 33 | bufferSerialUSB[idxSerialIntUSB]= 0; |
38domo | 10:41aff2b7acc6 | 34 | msgSerialUSB = 1; |
38domo | 10:41aff2b7acc6 | 35 | } |
38domo | 10:41aff2b7acc6 | 36 | return; |
38domo | 10:41aff2b7acc6 | 37 | } |
38domo | 10:41aff2b7acc6 | 38 | // -------------------------------------------------- |
38domo | 10:41aff2b7acc6 | 39 | void serial2_int_recv() |
38domo | 10:41aff2b7acc6 | 40 | { |
38domo | 10:41aff2b7acc6 | 41 | if(serial2.readable()) |
38domo | 10:41aff2b7acc6 | 42 | { |
38domo | 10:41aff2b7acc6 | 43 | bufferSerial2[idxSerialInt2]=(serial2.getc()); |
38domo | 10:41aff2b7acc6 | 44 | idxSerialInt2++; |
38domo | 10:41aff2b7acc6 | 45 | if (idxSerialInt2 >= kMaxBufferSize) {idxSerialInt2 = 0;} |
38domo | 10:41aff2b7acc6 | 46 | bufferSerial2[idxSerialInt2]= 0; |
38domo | 10:41aff2b7acc6 | 47 | msgSerial2 = 1; |
38domo | 10:41aff2b7acc6 | 48 | } |
38domo | 10:41aff2b7acc6 | 49 | return; |
38domo | 10:41aff2b7acc6 | 50 | } |
38domo | 10:41aff2b7acc6 | 51 | // ------------------------------------------------------ |
38domo | 10:41aff2b7acc6 | 52 | void serial7_int_recv() |
38domo | 10:41aff2b7acc6 | 53 | { |
38domo | 10:41aff2b7acc6 | 54 | if(serial7.readable()) |
38domo | 10:41aff2b7acc6 | 55 | { |
38domo | 10:41aff2b7acc6 | 56 | bufferSerial7[idxSerialInt7]=(serial7.getc()); |
38domo | 10:41aff2b7acc6 | 57 | idxSerialInt7++; |
38domo | 10:41aff2b7acc6 | 58 | if (idxSerialInt7 >= kMaxBufferSize) {idxSerialInt7 = 0;} |
38domo | 10:41aff2b7acc6 | 59 | bufferSerial7[idxSerialInt7]= 0; |
38domo | 10:41aff2b7acc6 | 60 | msgSerial7 = 1; |
38domo | 10:41aff2b7acc6 | 61 | } |
38domo | 10:41aff2b7acc6 | 62 | return; |
38domo | 10:41aff2b7acc6 | 63 | } |
38domo | 10:41aff2b7acc6 | 64 | // ---------------------------------------------- |
38domo | 10:41aff2b7acc6 | 65 | void initSerial() |
38domo | 10:41aff2b7acc6 | 66 | { |
38domo | 10:41aff2b7acc6 | 67 | serialUSB.baud(115200); |
38domo | 10:41aff2b7acc6 | 68 | serialUSB.attach(&serialUSB_int_recv, Serial::RxIrq); |
38domo | 10:41aff2b7acc6 | 69 | serial2.baud(115200); // required for UDP bridge |
38domo | 10:41aff2b7acc6 | 70 | serial2.attach(&serial2_int_recv, Serial::RxIrq); |
38domo | 10:41aff2b7acc6 | 71 | serial7.baud(115200); // required for tasmota |
38domo | 10:41aff2b7acc6 | 72 | serial7.attach(&serial7_int_recv, Serial::RxIrq); |
38domo | 10:41aff2b7acc6 | 73 | bufferSerialUSB[0] = '\0'; |
38domo | 10:41aff2b7acc6 | 74 | bufferSerial2[0] = '\0'; |
38domo | 10:41aff2b7acc6 | 75 | bufferSerial7[0] = '\0'; |
38domo | 10:41aff2b7acc6 | 76 | } |
38domo | 10:41aff2b7acc6 | 77 | // ---------------------------------------------------- |
38domo | 10:41aff2b7acc6 | 78 | void sendSerialUSB(char * str) |
38domo | 10:41aff2b7acc6 | 79 | { |
38domo | 10:41aff2b7acc6 | 80 | serialUSB.printf(str); |
38domo | 10:41aff2b7acc6 | 81 | } |
38domo | 10:41aff2b7acc6 | 82 | // ------------------------------------------------------------- |
38domo | 10:41aff2b7acc6 | 83 | void receiveSerialUSB() |
38domo | 10:41aff2b7acc6 | 84 | { |
38domo | 10:41aff2b7acc6 | 85 | while(idxSerialIntUSB != idxSerialUserUSB) |
38domo | 10:41aff2b7acc6 | 86 | { |
38domo | 10:41aff2b7acc6 | 87 | x=bufferSerialUSB[idxSerialUserUSB]; |
38domo | 10:41aff2b7acc6 | 88 | printf("%c",x); |
38domo | 10:41aff2b7acc6 | 89 | idxSerialUserUSB = idxSerialUserUSB + 1; |
38domo | 10:41aff2b7acc6 | 90 | if (idxSerialUserUSB >= kMaxBufferSize) {idxSerialUserUSB = 0;} |
38domo | 10:41aff2b7acc6 | 91 | } |
38domo | 10:41aff2b7acc6 | 92 | msgSerialUSB = 0; |
38domo | 10:41aff2b7acc6 | 93 | } |
38domo | 10:41aff2b7acc6 | 94 | // ------------------------------------- |
38domo | 10:41aff2b7acc6 | 95 | void sendSerial2(char * str) |
38domo | 10:41aff2b7acc6 | 96 | { |
38domo | 10:41aff2b7acc6 | 97 | serial2.printf(str); |
38domo | 10:41aff2b7acc6 | 98 | } |
38domo | 10:41aff2b7acc6 | 99 | // ----------------------------------------------- |
38domo | 10:41aff2b7acc6 | 100 | void receiveSerial2() |
38domo | 10:41aff2b7acc6 | 101 | { |
38domo | 10:41aff2b7acc6 | 102 | while(idxSerialInt2 != idxSerialUser2) |
38domo | 10:41aff2b7acc6 | 103 | { |
38domo | 10:41aff2b7acc6 | 104 | x=bufferSerial2[idxSerialUser2]; |
38domo | 10:41aff2b7acc6 | 105 | printf("%c",x); |
38domo | 10:41aff2b7acc6 | 106 | idxSerialUser2 = idxSerialUser2 + 1; |
38domo | 10:41aff2b7acc6 | 107 | if (idxSerialUser2 >= kMaxBufferSize) {idxSerialUser2 = 0;} |
38domo | 10:41aff2b7acc6 | 108 | } |
38domo | 10:41aff2b7acc6 | 109 | msgSerial2 = 0; |
38domo | 10:41aff2b7acc6 | 110 | } |
38domo | 10:41aff2b7acc6 | 111 | // ---------------------------------------------------- |
38domo | 10:41aff2b7acc6 | 112 | void sendSerial7(char * str) |
38domo | 10:41aff2b7acc6 | 113 | { |
38domo | 10:41aff2b7acc6 | 114 | serial7.printf(str); |
38domo | 10:41aff2b7acc6 | 115 | } |
38domo | 10:41aff2b7acc6 | 116 | // -------------------------------------------------------- |
38domo | 10:41aff2b7acc6 | 117 | void receiveSerial7() |
38domo | 10:41aff2b7acc6 | 118 | { |
38domo | 10:41aff2b7acc6 | 119 | while(idxSerialInt7 != idxSerialUser7) |
38domo | 10:41aff2b7acc6 | 120 | { |
38domo | 10:41aff2b7acc6 | 121 | x=bufferSerial7[idxSerialUser7]; |
38domo | 10:41aff2b7acc6 | 122 | printf("%c",x); |
38domo | 10:41aff2b7acc6 | 123 | idxSerialUser7 = idxSerialUser7 + 1; |
38domo | 10:41aff2b7acc6 | 124 | if (idxSerialUser7 >= kMaxBufferSize) {idxSerialUser7 = 0;} |
38domo | 10:41aff2b7acc6 | 125 | } |
38domo | 10:41aff2b7acc6 | 126 | msgSerial7 = 0; |
38domo | 10:41aff2b7acc6 | 127 | } |