![](/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@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 |
---|---|---|---|
jeanpierreaulas | 3:2de8e4771674 | 1 | #include "mbed.h" |
jeanpierreaulas | 3:2de8e4771674 | 2 | |
jeanpierreaulas | 3:2de8e4771674 | 3 | const int kMaxBufferSize = 125; |
jeanpierreaulas | 4:fbbf5d1785e7 | 4 | |
jeanpierreaulas | 3:2de8e4771674 | 5 | volatile char bufferSerialUSB[kMaxBufferSize+3]; |
jeanpierreaulas | 3:2de8e4771674 | 6 | volatile int idxSerialIntUSB = 0; |
jeanpierreaulas | 3:2de8e4771674 | 7 | int idxSerialUserUSB = 0; |
jeanpierreaulas | 3:2de8e4771674 | 8 | volatile int msgSerialUSB = 0; |
jeanpierreaulas | 8:275ae4382788 | 9 | char stringSerialUSB[kMaxBufferSize+3]; |
jeanpierreaulas | 8:275ae4382788 | 10 | int stringSerialUSBok = 0; // si ==1 alors trame dispo (fin de trame == LF ou 10 |
jeanpierreaulas | 8:275ae4382788 | 11 | int idxSerialStringUSB = 0; |
jeanpierreaulas | 3:2de8e4771674 | 12 | |
jeanpierreaulas | 4:fbbf5d1785e7 | 13 | volatile char bufferSerial2[kMaxBufferSize+3]; |
jeanpierreaulas | 4:fbbf5d1785e7 | 14 | volatile int idxSerialInt2 = 0; |
jeanpierreaulas | 4:fbbf5d1785e7 | 15 | int idxSerialUser2 = 0; |
jeanpierreaulas | 4:fbbf5d1785e7 | 16 | volatile int msgSerial2 = 0; |
jeanpierreaulas | 8:275ae4382788 | 17 | char stringSerial2[kMaxBufferSize+3]; |
jeanpierreaulas | 8:275ae4382788 | 18 | int stringSerial2ok = 0; // si ==1 alors trame dispo (fin de trame == LF ou 10 |
jeanpierreaulas | 8:275ae4382788 | 19 | int idxSerialString2 = 0; |
jeanpierreaulas | 4:fbbf5d1785e7 | 20 | |
jeanpierreaulas | 4:fbbf5d1785e7 | 21 | volatile char bufferSerial7[kMaxBufferSize+3]; |
jeanpierreaulas | 4:fbbf5d1785e7 | 22 | volatile int idxSerialInt7 = 0; |
jeanpierreaulas | 4:fbbf5d1785e7 | 23 | int idxSerialUser7 = 0; |
jeanpierreaulas | 4:fbbf5d1785e7 | 24 | volatile int msgSerial7 = 0; |
jeanpierreaulas | 8:275ae4382788 | 25 | char stringSerial7[kMaxBufferSize+3]; |
jeanpierreaulas | 8:275ae4382788 | 26 | int stringSerial7ok = 0; // si ==1 alors trame dispo (fin de trame == LF ou 10 |
jeanpierreaulas | 8:275ae4382788 | 27 | int idxSerialString7 = 0; |
jeanpierreaulas | 4:fbbf5d1785e7 | 28 | |
jeanpierreaulas | 3:2de8e4771674 | 29 | //RawSerial |
jeanpierreaulas | 4:fbbf5d1785e7 | 30 | RawSerial serialUSB(USBTX, USBRX); // serial PC |
jeanpierreaulas | 4:fbbf5d1785e7 | 31 | RawSerial serial2(PC_6, PC_7); // TX, RX for udp bridge |
jeanpierreaulas | 4:fbbf5d1785e7 | 32 | RawSerial serial7(PF_7, PF_6); // TX, RX for extension |
jeanpierreaulas | 3:2de8e4771674 | 33 | // --------------------------------------------------- |
jeanpierreaulas | 3:2de8e4771674 | 34 | void serialUSB_int_recv() |
jeanpierreaulas | 4:fbbf5d1785e7 | 35 | { |
jeanpierreaulas | 3:2de8e4771674 | 36 | if(serialUSB.readable()) |
jeanpierreaulas | 3:2de8e4771674 | 37 | { |
jeanpierreaulas | 3:2de8e4771674 | 38 | bufferSerialUSB[idxSerialIntUSB]=(serialUSB.getc()); |
jeanpierreaulas | 3:2de8e4771674 | 39 | idxSerialIntUSB++; |
jeanpierreaulas | 3:2de8e4771674 | 40 | if (idxSerialIntUSB >= kMaxBufferSize) {idxSerialIntUSB = 0;} |
jeanpierreaulas | 3:2de8e4771674 | 41 | bufferSerialUSB[idxSerialIntUSB]= 0; |
jeanpierreaulas | 3:2de8e4771674 | 42 | msgSerialUSB = 1; |
jeanpierreaulas | 3:2de8e4771674 | 43 | } |
jeanpierreaulas | 3:2de8e4771674 | 44 | return; |
jeanpierreaulas | 4:fbbf5d1785e7 | 45 | } |
38domo | 10:41aff2b7acc6 | 46 | // --------------------------------------------------------------------------- |
jeanpierreaulas | 4:fbbf5d1785e7 | 47 | void serial2_int_recv() |
jeanpierreaulas | 4:fbbf5d1785e7 | 48 | { |
jeanpierreaulas | 4:fbbf5d1785e7 | 49 | if(serial2.readable()) |
jeanpierreaulas | 4:fbbf5d1785e7 | 50 | { |
jeanpierreaulas | 4:fbbf5d1785e7 | 51 | bufferSerial2[idxSerialInt2]=(serial2.getc()); |
jeanpierreaulas | 4:fbbf5d1785e7 | 52 | idxSerialInt2++; |
jeanpierreaulas | 4:fbbf5d1785e7 | 53 | if (idxSerialInt2 >= kMaxBufferSize) {idxSerialInt2 = 0;} |
jeanpierreaulas | 4:fbbf5d1785e7 | 54 | bufferSerial2[idxSerialInt2]= 0; |
jeanpierreaulas | 4:fbbf5d1785e7 | 55 | msgSerial2 = 1; |
jeanpierreaulas | 4:fbbf5d1785e7 | 56 | } |
jeanpierreaulas | 4:fbbf5d1785e7 | 57 | return; |
jeanpierreaulas | 4:fbbf5d1785e7 | 58 | } |
38domo | 10:41aff2b7acc6 | 59 | // ---------------------------------------------------------------------------- |
jeanpierreaulas | 4:fbbf5d1785e7 | 60 | void serial7_int_recv() |
jeanpierreaulas | 4:fbbf5d1785e7 | 61 | { |
jeanpierreaulas | 4:fbbf5d1785e7 | 62 | if(serial7.readable()) |
38domo | 10:41aff2b7acc6 | 63 | { |
jeanpierreaulas | 4:fbbf5d1785e7 | 64 | bufferSerial7[idxSerialInt7]=(serial7.getc()); |
38domo | 10:41aff2b7acc6 | 65 | //printf("%c",bufferSerial7[idxSerialInt7]); |
jeanpierreaulas | 4:fbbf5d1785e7 | 66 | idxSerialInt7++; |
jeanpierreaulas | 4:fbbf5d1785e7 | 67 | if (idxSerialInt7 >= kMaxBufferSize) {idxSerialInt7 = 0;} |
jeanpierreaulas | 4:fbbf5d1785e7 | 68 | bufferSerial7[idxSerialInt7]= 0; |
jeanpierreaulas | 4:fbbf5d1785e7 | 69 | msgSerial7 = 1; |
jeanpierreaulas | 4:fbbf5d1785e7 | 70 | } |
jeanpierreaulas | 4:fbbf5d1785e7 | 71 | return; |
jeanpierreaulas | 4:fbbf5d1785e7 | 72 | } |
38domo | 10:41aff2b7acc6 | 73 | // -------------------------------------------------------------------------------- |
jeanpierreaulas | 3:2de8e4771674 | 74 | void initSerial() |
jeanpierreaulas | 3:2de8e4771674 | 75 | { |
jeanpierreaulas | 3:2de8e4771674 | 76 | serialUSB.baud(115200); |
jeanpierreaulas | 3:2de8e4771674 | 77 | serialUSB.attach(&serialUSB_int_recv, Serial::RxIrq); |
38domo | 10:41aff2b7acc6 | 78 | serial2.baud(115200); // required for Tasmota |
38domo | 10:41aff2b7acc6 | 79 | //serial2.baud(57600); // required for UDP bridge |
jeanpierreaulas | 4:fbbf5d1785e7 | 80 | serial2.attach(&serial2_int_recv, Serial::RxIrq); |
jeanpierreaulas | 3:2de8e4771674 | 81 | serial7.baud(115200); // required for tasmota |
38domo | 10:41aff2b7acc6 | 82 | serial7.attach(&serial7_int_recv, Serial::RxIrq); |
jeanpierreaulas | 3:2de8e4771674 | 83 | bufferSerialUSB[0] = '\0'; |
jeanpierreaulas | 4:fbbf5d1785e7 | 84 | bufferSerial2[0] = '\0'; |
38domo | 10:41aff2b7acc6 | 85 | bufferSerial7[0] = '\0'; |
jeanpierreaulas | 3:2de8e4771674 | 86 | } |
38domo | 10:41aff2b7acc6 | 87 | // --------------------------------------------------------------------------- |
jeanpierreaulas | 3:2de8e4771674 | 88 | void sendSerialUSB(char * str) |
jeanpierreaulas | 3:2de8e4771674 | 89 | { |
jeanpierreaulas | 3:2de8e4771674 | 90 | serialUSB.printf(str); |
jeanpierreaulas | 3:2de8e4771674 | 91 | } |
38domo | 10:41aff2b7acc6 | 92 | // --------------------------------------------------------------------------- |
jeanpierreaulas | 3:2de8e4771674 | 93 | void receiveSerialUSB() |
jeanpierreaulas | 3:2de8e4771674 | 94 | { |
jeanpierreaulas | 8:275ae4382788 | 95 | char x; |
jeanpierreaulas | 8:275ae4382788 | 96 | if (stringSerialUSBok == 0) // string user dispo flag a mettre a 0 par user a chaque lecture de string |
jeanpierreaulas | 3:2de8e4771674 | 97 | { |
jeanpierreaulas | 8:275ae4382788 | 98 | while(idxSerialIntUSB != idxSerialUserUSB) |
jeanpierreaulas | 8:275ae4382788 | 99 | { |
jeanpierreaulas | 8:275ae4382788 | 100 | x=bufferSerialUSB[idxSerialUserUSB]; |
jeanpierreaulas | 8:275ae4382788 | 101 | //printf("%c",x); |
jeanpierreaulas | 8:275ae4382788 | 102 | idxSerialUserUSB = idxSerialUserUSB + 1; |
jeanpierreaulas | 8:275ae4382788 | 103 | if (idxSerialUserUSB >= kMaxBufferSize) {idxSerialUserUSB = 0;} |
jeanpierreaulas | 8:275ae4382788 | 104 | |
jeanpierreaulas | 8:275ae4382788 | 105 | stringSerialUSB[idxSerialStringUSB] = x; |
jeanpierreaulas | 8:275ae4382788 | 106 | idxSerialStringUSB = idxSerialStringUSB + 1;stringSerialUSB[idxSerialStringUSB] = 0; |
jeanpierreaulas | 8:275ae4382788 | 107 | if (idxSerialStringUSB >= kMaxBufferSize) |
jeanpierreaulas | 8:275ae4382788 | 108 | {stringSerialUSB[idxSerialStringUSB-1] = 10;idxSerialStringUSB = 0;stringSerialUSBok = 1;} |
jeanpierreaulas | 8:275ae4382788 | 109 | if (x == 10) {idxSerialStringUSB = 0;stringSerialUSBok = 1;} |
jeanpierreaulas | 8:275ae4382788 | 110 | } |
jeanpierreaulas | 8:275ae4382788 | 111 | msgSerialUSB = 0; |
jeanpierreaulas | 3:2de8e4771674 | 112 | } |
jeanpierreaulas | 3:2de8e4771674 | 113 | } |
38domo | 10:41aff2b7acc6 | 114 | // ------------------------------------------------------------------------------ |
jeanpierreaulas | 6:55fdfef6dfa9 | 115 | void sendSerial2(char * str) |
jeanpierreaulas | 3:2de8e4771674 | 116 | { |
jeanpierreaulas | 3:2de8e4771674 | 117 | serial2.printf(str); |
jeanpierreaulas | 3:2de8e4771674 | 118 | } |
38domo | 10:41aff2b7acc6 | 119 | // ------------------------------------------------------------------------------ |
jeanpierreaulas | 4:fbbf5d1785e7 | 120 | void receiveSerial2() |
jeanpierreaulas | 4:fbbf5d1785e7 | 121 | { |
jeanpierreaulas | 8:275ae4382788 | 122 | char x; |
jeanpierreaulas | 8:275ae4382788 | 123 | if (stringSerial2ok == 0) // string user dispo flag a mettre a 0 par user a chaque lecture de string |
jeanpierreaulas | 4:fbbf5d1785e7 | 124 | { |
jeanpierreaulas | 8:275ae4382788 | 125 | while(idxSerialInt2 != idxSerialUser2) |
jeanpierreaulas | 8:275ae4382788 | 126 | { |
jeanpierreaulas | 8:275ae4382788 | 127 | x=bufferSerial2[idxSerialUser2]; |
jeanpierreaulas | 8:275ae4382788 | 128 | //printf("%c",x); |
jeanpierreaulas | 8:275ae4382788 | 129 | idxSerialUser2 = idxSerialUser2 + 1; |
jeanpierreaulas | 8:275ae4382788 | 130 | if (idxSerialUser2 >= kMaxBufferSize) {idxSerialUser2 = 0;} |
jeanpierreaulas | 8:275ae4382788 | 131 | |
jeanpierreaulas | 8:275ae4382788 | 132 | stringSerial2[idxSerialString2] = x; |
jeanpierreaulas | 8:275ae4382788 | 133 | idxSerialString2 = idxSerialString2 + 1;stringSerial2[idxSerialString2] = 0; |
jeanpierreaulas | 8:275ae4382788 | 134 | if (idxSerialString2 >= kMaxBufferSize) |
jeanpierreaulas | 8:275ae4382788 | 135 | {stringSerial2[idxSerialString2-1] = 10;idxSerialString2 = 0;stringSerial2ok = 1;} |
jeanpierreaulas | 8:275ae4382788 | 136 | if (x == 10) {idxSerialString2 = 0;stringSerial2ok = 1;} |
jeanpierreaulas | 8:275ae4382788 | 137 | } |
jeanpierreaulas | 8:275ae4382788 | 138 | msgSerial2 = 0; |
jeanpierreaulas | 4:fbbf5d1785e7 | 139 | } |
jeanpierreaulas | 4:fbbf5d1785e7 | 140 | } |
38domo | 10:41aff2b7acc6 | 141 | // -------------------------------------------------------------------------------- |
jeanpierreaulas | 6:55fdfef6dfa9 | 142 | void sendSerial7(char * str) |
jeanpierreaulas | 3:2de8e4771674 | 143 | { |
jeanpierreaulas | 3:2de8e4771674 | 144 | serial7.printf(str); |
jeanpierreaulas | 4:fbbf5d1785e7 | 145 | } |
38domo | 10:41aff2b7acc6 | 146 | // ------------------------------------------------------------------------------- |
jeanpierreaulas | 4:fbbf5d1785e7 | 147 | void receiveSerial7() |
jeanpierreaulas | 4:fbbf5d1785e7 | 148 | { |
jeanpierreaulas | 8:275ae4382788 | 149 | char x; |
jeanpierreaulas | 8:275ae4382788 | 150 | if (stringSerial7 == 0) // string user dispo flag a mettre a 0 par user a chaque lecture de string |
jeanpierreaulas | 4:fbbf5d1785e7 | 151 | { |
jeanpierreaulas | 8:275ae4382788 | 152 | while(idxSerialInt7 != idxSerialUser7) |
jeanpierreaulas | 8:275ae4382788 | 153 | { |
jeanpierreaulas | 8:275ae4382788 | 154 | x=bufferSerial7[idxSerialUser7]; |
38domo | 10:41aff2b7acc6 | 155 | //printf("%c",x); |
jeanpierreaulas | 8:275ae4382788 | 156 | idxSerialUser7 = idxSerialUser7 + 1; |
jeanpierreaulas | 8:275ae4382788 | 157 | if (idxSerialUser7 >= kMaxBufferSize) {idxSerialUser7 = 0;} |
jeanpierreaulas | 8:275ae4382788 | 158 | |
jeanpierreaulas | 8:275ae4382788 | 159 | stringSerial7[idxSerialString7] = x; |
jeanpierreaulas | 8:275ae4382788 | 160 | idxSerialString7 = idxSerialString7 + 1;stringSerial2[idxSerialString7] = 0; |
jeanpierreaulas | 8:275ae4382788 | 161 | if (idxSerialString7 >= kMaxBufferSize) |
jeanpierreaulas | 8:275ae4382788 | 162 | {stringSerial7[idxSerialString7-1] = 10;idxSerialString7 = 0;stringSerial7ok = 1;} |
jeanpierreaulas | 8:275ae4382788 | 163 | if (x == 10) {idxSerialString7 = 0;stringSerial7ok = 1;} |
jeanpierreaulas | 8:275ae4382788 | 164 | } |
38domo | 10:41aff2b7acc6 | 165 | //msgSerial2 = 0; |
38domo | 10:41aff2b7acc6 | 166 | msgSerial7 = 0; |
jeanpierreaulas | 4:fbbf5d1785e7 | 167 | } |
jeanpierreaulas | 3:2de8e4771674 | 168 | } |