xrocusOS_ADXL355 version

Dependencies:   mbed SDFileSystem

Committer:
Inscape_ao
Date:
Fri Jul 05 01:26:19 2019 +0000
Revision:
19:36072b9b79f3
Parent:
18:f0027b61bc08
Child:
20:2f2687580ecb
add LICENSE.txt

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 19:36072b9b79f3 57 uprintf(":%d WAK 0004 0000\n", deviceId);
Inscape_ao 12:a45a9c65dc03 58 dbgprintf("start mainloop\n");
Inscape_ao 12:a45a9c65dc03 59 mainloop();
Inscape_ao 12:a45a9c65dc03 60 }
Inscape_ao 12:a45a9c65dc03 61
Inscape_ao 12:a45a9c65dc03 62 /****************************************************/
Inscape_ao 12:a45a9c65dc03 63 /* MainLoop (for User Button handling) */
Inscape_ao 12:a45a9c65dc03 64 /****************************************************/
Inscape_ao 12:a45a9c65dc03 65 static void mainloop(void)
Inscape_ao 12:a45a9c65dc03 66 {
Inscape_ao 12:a45a9c65dc03 67 typedef enum e_offline_mode {
Inscape_ao 12:a45a9c65dc03 68 OFFLINE_MODE_READY,
Inscape_ao 12:a45a9c65dc03 69 OFFLINE_MODE_RUN,
Inscape_ao 12:a45a9c65dc03 70 OFFLINE_MODE_END,
Inscape_ao 12:a45a9c65dc03 71 } OfflineMode;
Inscape_ao 4:bec3f80dc49c 72
Inscape_ao 12:a45a9c65dc03 73 DigitalOut myled(PB_7);
Inscape_ao 18:f0027b61bc08 74 DigitalOut ledY(PC_2);
Inscape_ao 18:f0027b61bc08 75 DigitalOut ledG(PC_3);
Inscape_ao 18:f0027b61bc08 76
Inscape_ao 12:a45a9c65dc03 77 DigitalIn btn(USER_BUTTON);
Inscape_ao 12:a45a9c65dc03 78 OfflineMode state = OFFLINE_MODE_READY;
Inscape_ao 12:a45a9c65dc03 79 int blinky = 0;
Inscape_ao 12:a45a9c65dc03 80 myled = blinky;
Inscape_ao 18:f0027b61bc08 81 ledG = blinky;
Inscape_ao 18:f0027b61bc08 82 ledY = 0;
Inscape_ao 18:f0027b61bc08 83
Inscape_ao 0:c347f602596d 84 while(1) {
Inscape_ao 12:a45a9c65dc03 85 switch(state) {
Inscape_ao 12:a45a9c65dc03 86 case OFFLINE_MODE_READY:
Inscape_ao 12:a45a9c65dc03 87 myled = blinky;
Inscape_ao 18:f0027b61bc08 88 ledG = blinky;
Inscape_ao 18:f0027b61bc08 89
Inscape_ao 12:a45a9c65dc03 90 if (btn == 0) {
Inscape_ao 13:7cda5bef6390 91 uartOn = false;
Inscape_ao 12:a45a9c65dc03 92 pCP->parse(":0 RRP 0010");
Inscape_ao 12:a45a9c65dc03 93 pCP->parse(":0 RMC 001s");
Inscape_ao 12:a45a9c65dc03 94 pCP->parse(":0 SDS 0000");
Inscape_ao 12:a45a9c65dc03 95 pCP->parse(":0 CRS 0000");
Inscape_ao 12:a45a9c65dc03 96 state = OFFLINE_MODE_RUN;
Inscape_ao 12:a45a9c65dc03 97 }
Inscape_ao 12:a45a9c65dc03 98 wait(0.2);
Inscape_ao 12:a45a9c65dc03 99 break;
Inscape_ao 12:a45a9c65dc03 100 case OFFLINE_MODE_RUN:
Inscape_ao 12:a45a9c65dc03 101 myled = blinky;
Inscape_ao 18:f0027b61bc08 102 ledG = blinky;
Inscape_ao 18:f0027b61bc08 103
Inscape_ao 12:a45a9c65dc03 104 if (pCP->parse(":0 CPS 0000") == 0) {
Inscape_ao 12:a45a9c65dc03 105 pCP->parse(":0 SDE 0000");
Inscape_ao 12:a45a9c65dc03 106 state = OFFLINE_MODE_END;
Inscape_ao 12:a45a9c65dc03 107 }
Inscape_ao 12:a45a9c65dc03 108 wait(1);
Inscape_ao 12:a45a9c65dc03 109 break;
Inscape_ao 12:a45a9c65dc03 110 case OFFLINE_MODE_END:
Inscape_ao 12:a45a9c65dc03 111 default:
Inscape_ao 12:a45a9c65dc03 112 myled = 1;
Inscape_ao 18:f0027b61bc08 113 ledG = 1;
Inscape_ao 18:f0027b61bc08 114
Inscape_ao 12:a45a9c65dc03 115 wait(5);
Inscape_ao 12:a45a9c65dc03 116 break;
Inscape_ao 12:a45a9c65dc03 117 }
Inscape_ao 12:a45a9c65dc03 118 blinky = !blinky;
Inscape_ao 0:c347f602596d 119 }
Inscape_ao 12:a45a9c65dc03 120
Inscape_ao 0:c347f602596d 121 }