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