UART analysis program. UART 4 port. for M8Q(GPS)
Fork of FRDM-K64F-UARTCOMMS by
main.cpp@2:628579c8221c, 2017-01-17 (annotated)
- Committer:
- Okoshi
- Date:
- Tue Jan 17 01:38:56 2017 +0000
- Revision:
- 2:628579c8221c
- Parent:
- 1:623f51ea713b
UART analysis program.; 4 port.; for M8Q(GPS)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andcor02 | 0:f682dcf80f00 | 1 | #include "mbed.h" |
Okoshi | 2:628579c8221c | 2 | // Simple program allowing user to send messages from mbed COM out through UART to another UART COM. |
Okoshi | 2:628579c8221c | 3 | // Updated 2016/12/20 Hiroaki Okoshi |
Okoshi | 2:628579c8221c | 4 | // Target Board NUCLEO_F446RE |
Okoshi | 2:628579c8221c | 5 | |
Okoshi | 2:628579c8221c | 6 | Serial pc(USBTX, USBRX,921600); // tx, rx // 9600 ではタイミング衝突し取りこぼす。 |
Okoshi | 2:628579c8221c | 7 | Serial uart3 (PB_10, PC_5,57600); |
Okoshi | 2:628579c8221c | 8 | Serial uart4 (PA_0, PA_1,9600); |
Okoshi | 2:628579c8221c | 9 | Serial uart5 (PC_12, PD_2,9600); |
Okoshi | 2:628579c8221c | 10 | Serial uart6 (PC_6, PC_7,57600); |
erigow01 | 1:623f51ea713b | 11 | |
Okoshi | 2:628579c8221c | 12 | DigitalOut led1(LED1); |
Okoshi | 2:628579c8221c | 13 | |
Okoshi | 2:628579c8221c | 14 | char* PARSE_TRIGGERS = "\n"; |
Okoshi | 2:628579c8221c | 15 | int PARSE_TRIGGERS_LENGTH = 1; |
erigow01 | 1:623f51ea713b | 16 | int MAX_BUFFER_SIZE = 128; |
andcor02 | 0:f682dcf80f00 | 17 | |
erigow01 | 1:623f51ea713b | 18 | bool isTriggerChar(char c); |
erigow01 | 1:623f51ea713b | 19 | |
erigow01 | 1:623f51ea713b | 20 | int main() { |
Okoshi | 2:628579c8221c | 21 | char buffer5[MAX_BUFFER_SIZE],buffer6[MAX_BUFFER_SIZE]; |
Okoshi | 2:628579c8221c | 22 | |
Okoshi | 2:628579c8221c | 23 | int pos5 = 0,pos6 = 0; |
erigow01 | 1:623f51ea713b | 24 | char thisChar = 0; |
Okoshi | 2:628579c8221c | 25 | bool u3_flag=false,u4_flag=false; |
Okoshi | 2:628579c8221c | 26 | |
Okoshi | 2:628579c8221c | 27 | set_time(1481508000); // Set RTC time to Wed, 28 Oct 2009 11:35:37 |
Okoshi | 2:628579c8221c | 28 | // http://exp777.cs.land.to/epochsec.html |
Okoshi | 2:628579c8221c | 29 | |
Okoshi | 2:628579c8221c | 30 | pc.printf("UART Monitor Start\r\n"); |
Okoshi | 2:628579c8221c | 31 | |
Okoshi | 2:628579c8221c | 32 | while(true) { |
Okoshi | 2:628579c8221c | 33 | time_t seconds = time(NULL); |
Okoshi | 2:628579c8221c | 34 | struct tm *t = localtime(&seconds); |
Okoshi | 2:628579c8221c | 35 | /* |
Okoshi | 2:628579c8221c | 36 | // CPU 57600bps Port |
Okoshi | 2:628579c8221c | 37 | if (uart3.readable()) { |
Okoshi | 2:628579c8221c | 38 | if (u3_flag){ |
Okoshi | 2:628579c8221c | 39 | pc.printf("%02d:%02d|",t->tm_min, t->tm_sec); |
Okoshi | 2:628579c8221c | 40 | pc.printf("U3(CPU:57600)|"); |
Okoshi | 2:628579c8221c | 41 | u3_flag=false; |
Okoshi | 2:628579c8221c | 42 | } |
Okoshi | 2:628579c8221c | 43 | //printf("%s", ctime(&seconds)); |
Okoshi | 2:628579c8221c | 44 | thisChar = uart3.getc(); |
Okoshi | 2:628579c8221c | 45 | pc.printf("%2.2X|", thisChar); |
Okoshi | 2:628579c8221c | 46 | |
Okoshi | 2:628579c8221c | 47 | // buffer3[pos3++] = thisChar; |
Okoshi | 2:628579c8221c | 48 | // //If trigger or buffer overflow, output and reset buffer... |
Okoshi | 2:628579c8221c | 49 | // if(pos3 >= MAX_BUFFER_SIZE || isTriggerChar(thisChar)) { |
Okoshi | 2:628579c8221c | 50 | // pc.printf("U3:%.*s", pos3, buffer3); |
Okoshi | 2:628579c8221c | 51 | // pos3 = 0; |
Okoshi | 2:628579c8221c | 52 | // } |
Okoshi | 2:628579c8221c | 53 | } |
Okoshi | 2:628579c8221c | 54 | */ |
Okoshi | 2:628579c8221c | 55 | // CPU 9600bps Port |
Okoshi | 2:628579c8221c | 56 | if (uart4.readable()) { |
Okoshi | 2:628579c8221c | 57 | if (u4_flag){ |
Okoshi | 2:628579c8221c | 58 | pc.printf("%02d:%02d|",t->tm_min, t->tm_sec); |
Okoshi | 2:628579c8221c | 59 | pc.printf("U4(CPU:9600)|"); |
Okoshi | 2:628579c8221c | 60 | u4_flag=false; |
Okoshi | 2:628579c8221c | 61 | } |
Okoshi | 2:628579c8221c | 62 | //printf("%s", ctime(&seconds)); |
Okoshi | 2:628579c8221c | 63 | thisChar = uart4.getc(); |
Okoshi | 2:628579c8221c | 64 | pc.printf("%2.2X|", thisChar); |
Okoshi | 2:628579c8221c | 65 | |
Okoshi | 2:628579c8221c | 66 | // buffer4[pos4++] = thisChar; |
Okoshi | 2:628579c8221c | 67 | // //If trigger or buffer overflow, output and reset buffer... |
Okoshi | 2:628579c8221c | 68 | // if(pos4 >= MAX_BUFFER_SIZE || isTriggerChar(thisChar)) { |
Okoshi | 2:628579c8221c | 69 | // printf( "\r\n"); |
Okoshi | 2:628579c8221c | 70 | // pc.printf("%02d:%02d|",t->tm_min, t->tm_sec); |
Okoshi | 2:628579c8221c | 71 | // pc.printf("U4|%.*s", pos4, buffer4); |
Okoshi | 2:628579c8221c | 72 | // pos4 = 0; |
Okoshi | 2:628579c8221c | 73 | // } |
Okoshi | 2:628579c8221c | 74 | } |
Okoshi | 2:628579c8221c | 75 | |
Okoshi | 2:628579c8221c | 76 | // M8Q 9600bps Port |
Okoshi | 2:628579c8221c | 77 | if (uart5.readable()) { |
Okoshi | 2:628579c8221c | 78 | thisChar = uart5.getc(); |
Okoshi | 2:628579c8221c | 79 | // printf("U5[%2.2X]%c\r\n",thisChar,thisChar ); |
Okoshi | 2:628579c8221c | 80 | buffer5[pos5++] = thisChar; |
erigow01 | 1:623f51ea713b | 81 | //If trigger or buffer overflow, output and reset buffer... |
Okoshi | 2:628579c8221c | 82 | if(pos5 >= MAX_BUFFER_SIZE || isTriggerChar(thisChar)) { |
Okoshi | 2:628579c8221c | 83 | printf( "\r\n"); |
Okoshi | 2:628579c8221c | 84 | pc.printf("%02d:%02d|",t->tm_min, t->tm_sec); |
Okoshi | 2:628579c8221c | 85 | pc.printf("U5(M8Q:9600):%.*s", pos5, buffer5); |
Okoshi | 2:628579c8221c | 86 | pos5 = 0; |
Okoshi | 2:628579c8221c | 87 | u3_flag = u4_flag = true; |
erigow01 | 1:623f51ea713b | 88 | } |
andcor02 | 0:f682dcf80f00 | 89 | } |
Okoshi | 2:628579c8221c | 90 | |
Okoshi | 2:628579c8221c | 91 | // M8Q 57600bps Port |
Okoshi | 2:628579c8221c | 92 | if (uart6.readable()) { |
Okoshi | 2:628579c8221c | 93 | thisChar = uart6.getc(); |
Okoshi | 2:628579c8221c | 94 | buffer6[pos6++] = thisChar; |
Okoshi | 2:628579c8221c | 95 | //If trigger or buffer overflow, output and reset buffer... |
Okoshi | 2:628579c8221c | 96 | if(pos6 >= MAX_BUFFER_SIZE || isTriggerChar(thisChar)) { |
Okoshi | 2:628579c8221c | 97 | printf( "\r\n"); |
Okoshi | 2:628579c8221c | 98 | pc.printf("%02d:%02d|",t->tm_min, t->tm_sec); |
Okoshi | 2:628579c8221c | 99 | pc.printf("U6(M8Q:57600):%.*s", pos6, buffer6); |
Okoshi | 2:628579c8221c | 100 | pos6 = 0; |
Okoshi | 2:628579c8221c | 101 | u3_flag = u4_flag = true; |
Okoshi | 2:628579c8221c | 102 | } |
Okoshi | 2:628579c8221c | 103 | } |
Okoshi | 2:628579c8221c | 104 | |
Okoshi | 2:628579c8221c | 105 | led1 = !led1; |
andcor02 | 0:f682dcf80f00 | 106 | } |
andcor02 | 0:f682dcf80f00 | 107 | } |
erigow01 | 1:623f51ea713b | 108 | |
erigow01 | 1:623f51ea713b | 109 | bool isTriggerChar(char c) { |
erigow01 | 1:623f51ea713b | 110 | for (int i = 0; i < PARSE_TRIGGERS_LENGTH; i++) { |
erigow01 | 1:623f51ea713b | 111 | if(c == PARSE_TRIGGERS[i]) { |
erigow01 | 1:623f51ea713b | 112 | return true; |
erigow01 | 1:623f51ea713b | 113 | } |
erigow01 | 1:623f51ea713b | 114 | } |
erigow01 | 1:623f51ea713b | 115 | return false; |
erigow01 | 1:623f51ea713b | 116 | } |