UART Command Parser Time Manager Data Store for SD Card for stm32l476 [it's not Licensed as BSD/GPLx]
Dependencies: mbed SDFileSystem
main.cpp@14:89665bcef3f0, 2019-05-27 (annotated)
- Committer:
- Inscape_ao
- Date:
- Mon May 27 07:56:09 2019 +0000
- Revision:
- 14:89665bcef3f0
- Parent:
- 13:7cda5bef6390
- Child:
- 15:35f01ee28b44
Rename project (->xrocus); Rename Device Driver(-> ADXL372Drv)
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 | 2:a694440145e9 | 3 | #include "SDFileSystem.h" |
Inscape_ao | 2:a694440145e9 | 4 | #include "TimeManager.h" |
Inscape_ao | 0:c347f602596d | 5 | #include "UartReceiver.h" |
Inscape_ao | 0:c347f602596d | 6 | #include "CommandParser.h" |
Inscape_ao | 5:a37e3a15444b | 7 | #include "SDDataStore.h" |
Inscape_ao | 0:c347f602596d | 8 | #include "global.h" |
Inscape_ao | 0:c347f602596d | 9 | #include "string.h" |
Inscape_ao | 7:9ab8809f9693 | 10 | #include "DeviceRepeater.h" |
Inscape_ao | 14:89665bcef3f0 | 11 | #include "Adxl372Drv.h" |
Inscape_ao | 0:c347f602596d | 12 | |
Inscape_ao | 0:c347f602596d | 13 | /** --- Global Variables --- */ |
Inscape_ao | 12:a45a9c65dc03 | 14 | Serial uartStream(SERIAL_TX, SERIAL_RX); |
Inscape_ao | 13:7cda5bef6390 | 15 | bool uartOn = true; |
Inscape_ao | 12:a45a9c65dc03 | 16 | #ifdef _DEBUG_PRINTF_ |
Inscape_ao | 12:a45a9c65dc03 | 17 | Serial dbg(PC_4, PC_5); /* Serial3_TX, Serial3_RX*/ |
Inscape_ao | 12:a45a9c65dc03 | 18 | #endif /* _DEBUG_PRINTF_ */ |
Inscape_ao | 10:db2be22bc2f9 | 19 | |
Inscape_ao | 12:a45a9c65dc03 | 20 | /** --- prototypes --- */ |
Inscape_ao | 12:a45a9c65dc03 | 21 | static void mainloop(void); |
Inscape_ao | 10:db2be22bc2f9 | 22 | |
Inscape_ao | 0:c347f602596d | 23 | /** --- main --- */ |
Inscape_ao | 0:c347f602596d | 24 | int main() |
Inscape_ao | 0:c347f602596d | 25 | { |
Inscape_ao | 10:db2be22bc2f9 | 26 | int deviceId = 0; |
Inscape_ao | 10:db2be22bc2f9 | 27 | |
Inscape_ao | 0:c347f602596d | 28 | /** UART Initalizer */ |
Inscape_ao | 0:c347f602596d | 29 | /* setup UART 115200, 8bit, Parity=None, stopbit:1bit */ |
Inscape_ao | 0:c347f602596d | 30 | /* https://os.mbed.com/users/okini3939/notebook/Serial_jp/ */ |
Inscape_ao | 12:a45a9c65dc03 | 31 | uartStream.baud(115200); |
Inscape_ao | 12:a45a9c65dc03 | 32 | uartStream.format(8, Serial::None, 1); |
Inscape_ao | 12:a45a9c65dc03 | 33 | #ifdef _DEBUG_PRINTF_ |
Inscape_ao | 12:a45a9c65dc03 | 34 | /** UART Initalizer */ |
Inscape_ao | 12:a45a9c65dc03 | 35 | /* setup UART 115200, 8bit, Parity=None, stopbit:1bit */ |
Inscape_ao | 12:a45a9c65dc03 | 36 | /* https://os.mbed.com/users/okini3939/notebook/Serial_jp/ */ |
Inscape_ao | 12:a45a9c65dc03 | 37 | dbg.baud(115200); |
Inscape_ao | 12:a45a9c65dc03 | 38 | dbg.format(8, Serial::None, 1); |
Inscape_ao | 12:a45a9c65dc03 | 39 | #endif /* _DEBUG_PRINTF_ */ |
Inscape_ao | 12:a45a9c65dc03 | 40 | dbgprintf("start debug console as 115200,8b,1\n"); |
Inscape_ao | 0:c347f602596d | 41 | |
Inscape_ao | 2:a694440145e9 | 42 | /* new timer manager */ |
Inscape_ao | 2:a694440145e9 | 43 | pTM = new TimeManager(); |
Inscape_ao | 5:a37e3a15444b | 44 | /* Generate SDDataStore */ |
Inscape_ao | 5:a37e3a15444b | 45 | pSds = new SDDataStore(pTM); |
Inscape_ao | 0:c347f602596d | 46 | /* Receive Buffer Control */ |
Inscape_ao | 12:a45a9c65dc03 | 47 | pUR = new UartReceiver(&uartStream); |
Inscape_ao | 9:c81d0df866f5 | 48 | |
Inscape_ao | 9:c81d0df866f5 | 49 | /* create Device */ |
Inscape_ao | 10:db2be22bc2f9 | 50 | pDevRept = new DeviceRepeater(deviceId, &DummyDev); |
Inscape_ao | 9:c81d0df866f5 | 51 | |
Inscape_ao | 0:c347f602596d | 52 | /* Generate Command parser as DeviceID = 0, ParsingRule = rules */ |
Inscape_ao | 10:db2be22bc2f9 | 53 | pCP = new CommandParser(pUR, deviceId, rules, getNumOfRules); |
Inscape_ao | 0:c347f602596d | 54 | pCP->run(); |
Inscape_ao | 6:81a3d517fd56 | 55 | |
Inscape_ao | 13:7cda5bef6390 | 56 | uprintf(":%d ACK 0004 0000\n", deviceId); |
Inscape_ao | 12:a45a9c65dc03 | 57 | dbgprintf("start mainloop\n"); |
Inscape_ao | 12:a45a9c65dc03 | 58 | mainloop(); |
Inscape_ao | 12:a45a9c65dc03 | 59 | } |
Inscape_ao | 12:a45a9c65dc03 | 60 | |
Inscape_ao | 12:a45a9c65dc03 | 61 | /****************************************************/ |
Inscape_ao | 12:a45a9c65dc03 | 62 | /* MainLoop (for User Button handling) */ |
Inscape_ao | 12:a45a9c65dc03 | 63 | /****************************************************/ |
Inscape_ao | 12:a45a9c65dc03 | 64 | static void mainloop(void) |
Inscape_ao | 12:a45a9c65dc03 | 65 | { |
Inscape_ao | 12:a45a9c65dc03 | 66 | typedef enum e_offline_mode { |
Inscape_ao | 12:a45a9c65dc03 | 67 | OFFLINE_MODE_READY, |
Inscape_ao | 12:a45a9c65dc03 | 68 | OFFLINE_MODE_RUN, |
Inscape_ao | 12:a45a9c65dc03 | 69 | OFFLINE_MODE_END, |
Inscape_ao | 12:a45a9c65dc03 | 70 | } OfflineMode; |
Inscape_ao | 4:bec3f80dc49c | 71 | |
Inscape_ao | 12:a45a9c65dc03 | 72 | DigitalOut myled(PB_7); |
Inscape_ao | 12:a45a9c65dc03 | 73 | DigitalIn btn(USER_BUTTON); |
Inscape_ao | 12:a45a9c65dc03 | 74 | OfflineMode state = OFFLINE_MODE_READY; |
Inscape_ao | 12:a45a9c65dc03 | 75 | int blinky = 0; |
Inscape_ao | 12:a45a9c65dc03 | 76 | myled = blinky; |
Inscape_ao | 0:c347f602596d | 77 | while(1) { |
Inscape_ao | 12:a45a9c65dc03 | 78 | switch(state) { |
Inscape_ao | 12:a45a9c65dc03 | 79 | case OFFLINE_MODE_READY: |
Inscape_ao | 12:a45a9c65dc03 | 80 | myled = blinky; |
Inscape_ao | 12:a45a9c65dc03 | 81 | if (btn == 0) { |
Inscape_ao | 13:7cda5bef6390 | 82 | uartOn = false; |
Inscape_ao | 12:a45a9c65dc03 | 83 | pCP->parse(":0 RRP 0010"); |
Inscape_ao | 12:a45a9c65dc03 | 84 | pCP->parse(":0 RMC 001s"); |
Inscape_ao | 12:a45a9c65dc03 | 85 | pCP->parse(":0 SDS 0000"); |
Inscape_ao | 12:a45a9c65dc03 | 86 | pCP->parse(":0 CRS 0000"); |
Inscape_ao | 12:a45a9c65dc03 | 87 | state = OFFLINE_MODE_RUN; |
Inscape_ao | 12:a45a9c65dc03 | 88 | } |
Inscape_ao | 12:a45a9c65dc03 | 89 | wait(0.2); |
Inscape_ao | 12:a45a9c65dc03 | 90 | break; |
Inscape_ao | 12:a45a9c65dc03 | 91 | case OFFLINE_MODE_RUN: |
Inscape_ao | 12:a45a9c65dc03 | 92 | myled = blinky; |
Inscape_ao | 12:a45a9c65dc03 | 93 | if (pCP->parse(":0 CPS 0000") == 0) { |
Inscape_ao | 12:a45a9c65dc03 | 94 | pCP->parse(":0 SDE 0000"); |
Inscape_ao | 12:a45a9c65dc03 | 95 | state = OFFLINE_MODE_END; |
Inscape_ao | 12:a45a9c65dc03 | 96 | } |
Inscape_ao | 12:a45a9c65dc03 | 97 | wait(1); |
Inscape_ao | 12:a45a9c65dc03 | 98 | break; |
Inscape_ao | 12:a45a9c65dc03 | 99 | case OFFLINE_MODE_END: |
Inscape_ao | 12:a45a9c65dc03 | 100 | default: |
Inscape_ao | 12:a45a9c65dc03 | 101 | myled = 1; |
Inscape_ao | 12:a45a9c65dc03 | 102 | wait(5); |
Inscape_ao | 12:a45a9c65dc03 | 103 | break; |
Inscape_ao | 12:a45a9c65dc03 | 104 | } |
Inscape_ao | 12:a45a9c65dc03 | 105 | blinky = !blinky; |
Inscape_ao | 0:c347f602596d | 106 | } |
Inscape_ao | 12:a45a9c65dc03 | 107 | |
Inscape_ao | 0:c347f602596d | 108 | } |