UART Command Parser Time Manager Data Store for SD Card for stm32l476 [it's not Licensed as BSD/GPLx]

Dependencies:   mbed SDFileSystem

Committer:
Inscape_ao
Date:
Wed May 22 09:10:18 2019 +0000
Revision:
12:a45a9c65dc03
Parent:
10:db2be22bc2f9
Child:
13:7cda5bef6390
update LED seq and USER_BUTTON

Who changed what in which revision?

UserRevisionLine numberNew 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 7:9ab8809f9693 11 #include "DummyDevice.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 10:db2be22bc2f9 15
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 12:a45a9c65dc03 56 uartStream.printf(":%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 12:a45a9c65dc03 82 pCP->parse(":0 RRP 0010");
Inscape_ao 12:a45a9c65dc03 83 pCP->parse(":0 RMC 001s");
Inscape_ao 12:a45a9c65dc03 84 pCP->parse(":0 SDS 0000");
Inscape_ao 12:a45a9c65dc03 85 pCP->parse(":0 CRS 0000");
Inscape_ao 12:a45a9c65dc03 86 state = OFFLINE_MODE_RUN;
Inscape_ao 12:a45a9c65dc03 87 }
Inscape_ao 12:a45a9c65dc03 88 wait(0.2);
Inscape_ao 12:a45a9c65dc03 89 break;
Inscape_ao 12:a45a9c65dc03 90 case OFFLINE_MODE_RUN:
Inscape_ao 12:a45a9c65dc03 91 myled = blinky;
Inscape_ao 12:a45a9c65dc03 92 if (pCP->parse(":0 CPS 0000") == 0) {
Inscape_ao 12:a45a9c65dc03 93 pCP->parse(":0 SDE 0000");
Inscape_ao 12:a45a9c65dc03 94 state = OFFLINE_MODE_END;
Inscape_ao 12:a45a9c65dc03 95 }
Inscape_ao 12:a45a9c65dc03 96 wait(1);
Inscape_ao 12:a45a9c65dc03 97 break;
Inscape_ao 12:a45a9c65dc03 98 case OFFLINE_MODE_END:
Inscape_ao 12:a45a9c65dc03 99 default:
Inscape_ao 12:a45a9c65dc03 100 myled = 1;
Inscape_ao 12:a45a9c65dc03 101 wait(5);
Inscape_ao 12:a45a9c65dc03 102 break;
Inscape_ao 12:a45a9c65dc03 103 }
Inscape_ao 12:a45a9c65dc03 104 blinky = !blinky;
Inscape_ao 0:c347f602596d 105 }
Inscape_ao 12:a45a9c65dc03 106
Inscape_ao 0:c347f602596d 107 }