UART Command Parser Time Manager Data Store for SD Card for stm32l476 [it's not Licensed as BSD/GPLx]
Dependencies: mbed SDFileSystem
main.cpp@1:71c9c97c9f3d, 2019-04-21 (annotated)
- Committer:
- Inscape_ao
- Date:
- Sun Apr 21 02:50:19 2019 +0000
- Revision:
- 1:71c9c97c9f3d
- Parent:
- 0:c347f602596d
- Child:
- 2:a694440145e9
add Reply Method in Command Parser
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 | /** --- Global Variables --- */ |
Inscape_ao | 0:c347f602596d | 9 | Serial pc(SERIAL_TX, SERIAL_RX); |
Inscape_ao | 0:c347f602596d | 10 | DigitalOut myled(LED1); |
Inscape_ao | 0:c347f602596d | 11 | |
Inscape_ao | 0:c347f602596d | 12 | /** --- Prototypes --- */ |
Inscape_ao | 0:c347f602596d | 13 | /** --- Static functions --- */ |
Inscape_ao | 1:71c9c97c9f3d | 14 | static int sampleHanlder(CommandParser *pC, char *arg) |
Inscape_ao | 0:c347f602596d | 15 | { |
Inscape_ao | 0:c347f602596d | 16 | pc.printf("[sampleHanlder] ARG=%s[EOL]", arg); |
Inscape_ao | 1:71c9c97c9f3d | 17 | pC->reply(); |
Inscape_ao | 0:c347f602596d | 18 | return 0; |
Inscape_ao | 0:c347f602596d | 19 | } |
Inscape_ao | 0:c347f602596d | 20 | |
Inscape_ao | 0:c347f602596d | 21 | CmdParseRule rules[] = { |
Inscape_ao | 0:c347f602596d | 22 | {"CMD", sampleHanlder}, |
Inscape_ao | 0:c347f602596d | 23 | }; |
Inscape_ao | 0:c347f602596d | 24 | |
Inscape_ao | 1:71c9c97c9f3d | 25 | static inline int getNumOfRules(void) |
Inscape_ao | 1:71c9c97c9f3d | 26 | { |
Inscape_ao | 1:71c9c97c9f3d | 27 | return sizeof(rules)/sizeof(CmdParseRule); |
Inscape_ao | 1:71c9c97c9f3d | 28 | } |
Inscape_ao | 1:71c9c97c9f3d | 29 | |
Inscape_ao | 0:c347f602596d | 30 | /** --- main --- */ |
Inscape_ao | 0:c347f602596d | 31 | int main() |
Inscape_ao | 0:c347f602596d | 32 | { |
Inscape_ao | 0:c347f602596d | 33 | int i = 1; |
Inscape_ao | 0:c347f602596d | 34 | |
Inscape_ao | 0:c347f602596d | 35 | /** UART Initalizer */ |
Inscape_ao | 0:c347f602596d | 36 | /* setup UART 115200, 8bit, Parity=None, stopbit:1bit */ |
Inscape_ao | 0:c347f602596d | 37 | /* https://os.mbed.com/users/okini3939/notebook/Serial_jp/ */ |
Inscape_ao | 0:c347f602596d | 38 | pc.baud(115200); |
Inscape_ao | 0:c347f602596d | 39 | pc.format(8, Serial::None, 1); |
Inscape_ao | 0:c347f602596d | 40 | |
Inscape_ao | 0:c347f602596d | 41 | /* Receive Buffer Control */ |
Inscape_ao | 0:c347f602596d | 42 | pUR = new UartReceiver(&pc); |
Inscape_ao | 0:c347f602596d | 43 | /* Generate Command parser as DeviceID = 0, ParsingRule = rules */ |
Inscape_ao | 1:71c9c97c9f3d | 44 | pCP = new CommandParser(pUR, 0, rules, getNumOfRules()); |
Inscape_ao | 0:c347f602596d | 45 | pCP->run(); |
Inscape_ao | 0:c347f602596d | 46 | |
Inscape_ao | 0:c347f602596d | 47 | pc.printf("Hello World !\n"); |
Inscape_ao | 0:c347f602596d | 48 | while(1) { |
Inscape_ao | 0:c347f602596d | 49 | wait(1); |
Inscape_ao | 0:c347f602596d | 50 | pc.printf("This program runs since %d seconds.\n", i++); |
Inscape_ao | 0:c347f602596d | 51 | myled = !myled; |
Inscape_ao | 0:c347f602596d | 52 | } |
Inscape_ao | 0:c347f602596d | 53 | } |