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:
Fri Jun 14 00:21:09 2019 +0000
Revision:
18:f0027b61bc08
Parent:
15:35f01ee28b44
Child:
19:36072b9b79f3
change USER LED(Green); PB_7->PC_3; add USER LED(Yellow); PC_2

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 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 15:35f01ee28b44 50 pDevRept = new DeviceRepeater(deviceId, &Adxl372Simple);
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 18:f0027b61bc08 73 DigitalOut ledY(PC_2);
Inscape_ao 18:f0027b61bc08 74 DigitalOut ledG(PC_3);
Inscape_ao 18:f0027b61bc08 75
Inscape_ao 12:a45a9c65dc03 76 DigitalIn btn(USER_BUTTON);
Inscape_ao 12:a45a9c65dc03 77 OfflineMode state = OFFLINE_MODE_READY;
Inscape_ao 12:a45a9c65dc03 78 int blinky = 0;
Inscape_ao 12:a45a9c65dc03 79 myled = blinky;
Inscape_ao 18:f0027b61bc08 80 ledG = blinky;
Inscape_ao 18:f0027b61bc08 81 ledY = 0;
Inscape_ao 18:f0027b61bc08 82
Inscape_ao 0:c347f602596d 83 while(1) {
Inscape_ao 12:a45a9c65dc03 84 switch(state) {
Inscape_ao 12:a45a9c65dc03 85 case OFFLINE_MODE_READY:
Inscape_ao 12:a45a9c65dc03 86 myled = blinky;
Inscape_ao 18:f0027b61bc08 87 ledG = blinky;
Inscape_ao 18:f0027b61bc08 88
Inscape_ao 12:a45a9c65dc03 89 if (btn == 0) {
Inscape_ao 13:7cda5bef6390 90 uartOn = false;
Inscape_ao 12:a45a9c65dc03 91 pCP->parse(":0 RRP 0010");
Inscape_ao 12:a45a9c65dc03 92 pCP->parse(":0 RMC 001s");
Inscape_ao 12:a45a9c65dc03 93 pCP->parse(":0 SDS 0000");
Inscape_ao 12:a45a9c65dc03 94 pCP->parse(":0 CRS 0000");
Inscape_ao 12:a45a9c65dc03 95 state = OFFLINE_MODE_RUN;
Inscape_ao 12:a45a9c65dc03 96 }
Inscape_ao 12:a45a9c65dc03 97 wait(0.2);
Inscape_ao 12:a45a9c65dc03 98 break;
Inscape_ao 12:a45a9c65dc03 99 case OFFLINE_MODE_RUN:
Inscape_ao 12:a45a9c65dc03 100 myled = blinky;
Inscape_ao 18:f0027b61bc08 101 ledG = blinky;
Inscape_ao 18:f0027b61bc08 102
Inscape_ao 12:a45a9c65dc03 103 if (pCP->parse(":0 CPS 0000") == 0) {
Inscape_ao 12:a45a9c65dc03 104 pCP->parse(":0 SDE 0000");
Inscape_ao 12:a45a9c65dc03 105 state = OFFLINE_MODE_END;
Inscape_ao 12:a45a9c65dc03 106 }
Inscape_ao 12:a45a9c65dc03 107 wait(1);
Inscape_ao 12:a45a9c65dc03 108 break;
Inscape_ao 12:a45a9c65dc03 109 case OFFLINE_MODE_END:
Inscape_ao 12:a45a9c65dc03 110 default:
Inscape_ao 12:a45a9c65dc03 111 myled = 1;
Inscape_ao 18:f0027b61bc08 112 ledG = 1;
Inscape_ao 18:f0027b61bc08 113
Inscape_ao 12:a45a9c65dc03 114 wait(5);
Inscape_ao 12:a45a9c65dc03 115 break;
Inscape_ao 12:a45a9c65dc03 116 }
Inscape_ao 12:a45a9c65dc03 117 blinky = !blinky;
Inscape_ao 0:c347f602596d 118 }
Inscape_ao 12:a45a9c65dc03 119
Inscape_ao 0:c347f602596d 120 }