UART Command Parser Time Manager Data Store for SD Card for stm32l476 [it's not Licensed as BSD/GPLx]
Dependencies: mbed SDFileSystem
main.cpp@0:c347f602596d, 2019-04-20 (annotated)
- Committer:
- Inscape_ao
- Date:
- Sat Apr 20 09:23:39 2019 +0000
- Revision:
- 0:c347f602596d
- Child:
- 1:71c9c97c9f3d
create UartReceiver, CommandParser
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Inscape_ao | 0:c347f602596d | 1 | /** --- Includes --- */ |
Inscape_ao | 0:c347f602596d | 2 | #include "mbed.h" |
Inscape_ao | 0:c347f602596d | 3 | #include "UartReceiver.h" |
Inscape_ao | 0:c347f602596d | 4 | #include "CommandParser.h" |
Inscape_ao | 0:c347f602596d | 5 | #include "global.h" |
Inscape_ao | 0:c347f602596d | 6 | #include "string.h" |
Inscape_ao | 0:c347f602596d | 7 | |
Inscape_ao | 0:c347f602596d | 8 | |
Inscape_ao | 0:c347f602596d | 9 | class CommandParser; |
Inscape_ao | 0:c347f602596d | 10 | |
Inscape_ao | 0:c347f602596d | 11 | /** --- Global Variables --- */ |
Inscape_ao | 0:c347f602596d | 12 | Serial pc(SERIAL_TX, SERIAL_RX); |
Inscape_ao | 0:c347f602596d | 13 | DigitalOut myled(LED1); |
Inscape_ao | 0:c347f602596d | 14 | |
Inscape_ao | 0:c347f602596d | 15 | /** --- Prototypes --- */ |
Inscape_ao | 0:c347f602596d | 16 | /** --- Static functions --- */ |
Inscape_ao | 0:c347f602596d | 17 | static int sampleHanlder(char *arg) |
Inscape_ao | 0:c347f602596d | 18 | { |
Inscape_ao | 0:c347f602596d | 19 | pc.printf("[sampleHanlder] ARG=%s[EOL]", arg); |
Inscape_ao | 0:c347f602596d | 20 | return 0; |
Inscape_ao | 0:c347f602596d | 21 | } |
Inscape_ao | 0:c347f602596d | 22 | |
Inscape_ao | 0:c347f602596d | 23 | CmdParseRule rules[] = { |
Inscape_ao | 0:c347f602596d | 24 | {"CMD", sampleHanlder}, |
Inscape_ao | 0:c347f602596d | 25 | }; |
Inscape_ao | 0:c347f602596d | 26 | |
Inscape_ao | 0:c347f602596d | 27 | /** --- main --- */ |
Inscape_ao | 0:c347f602596d | 28 | int main() |
Inscape_ao | 0:c347f602596d | 29 | { |
Inscape_ao | 0:c347f602596d | 30 | int i = 1; |
Inscape_ao | 0:c347f602596d | 31 | |
Inscape_ao | 0:c347f602596d | 32 | /** UART Initalizer */ |
Inscape_ao | 0:c347f602596d | 33 | /* setup UART 115200, 8bit, Parity=None, stopbit:1bit */ |
Inscape_ao | 0:c347f602596d | 34 | /* https://os.mbed.com/users/okini3939/notebook/Serial_jp/ */ |
Inscape_ao | 0:c347f602596d | 35 | pc.baud(115200); |
Inscape_ao | 0:c347f602596d | 36 | pc.format(8, Serial::None, 1); |
Inscape_ao | 0:c347f602596d | 37 | |
Inscape_ao | 0:c347f602596d | 38 | /* Receive Buffer Control */ |
Inscape_ao | 0:c347f602596d | 39 | pUR = new UartReceiver(&pc); |
Inscape_ao | 0:c347f602596d | 40 | /* Generate Command parser as DeviceID = 0, ParsingRule = rules */ |
Inscape_ao | 0:c347f602596d | 41 | pCP = new CommandParser(pUR, 0, rules, sizeof(rules)/sizeof(CmdParseRule)); |
Inscape_ao | 0:c347f602596d | 42 | pCP->run(); |
Inscape_ao | 0:c347f602596d | 43 | |
Inscape_ao | 0:c347f602596d | 44 | pc.printf("Hello World !\n"); |
Inscape_ao | 0:c347f602596d | 45 | while(1) { |
Inscape_ao | 0:c347f602596d | 46 | wait(1); |
Inscape_ao | 0:c347f602596d | 47 | pc.printf("This program runs since %d seconds.\n", i++); |
Inscape_ao | 0:c347f602596d | 48 | myled = !myled; |
Inscape_ao | 0:c347f602596d | 49 | } |
Inscape_ao | 0:c347f602596d | 50 | } |