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

Dependencies:   mbed SDFileSystem

Revision:
2:a694440145e9
Child:
5:a37e3a15444b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/event.cpp	Tue Apr 23 08:47:11 2019 +0000
@@ -0,0 +1,70 @@
+/** --- Includes --- */
+#include "mbed.h"
+#include "TimeManager.h"
+#include "UartReceiver.h"
+#include "CommandParser.h"
+#include "global.h"
+#include "string.h"
+
+static int sampleHanlder(CommandParser *pC, char *arg, int exarg);
+static int setTimeHanlder(CommandParser *pC, char *arg, int exarg);
+static int getTimeHanlder(CommandParser *pC, char *arg, int exarg);
+
+/* Event Hankder */
+CmdParseRule rules[] = {
+    /* サンプルコマンド */
+    {"CMD", sampleHanlder, 0},
+    /* 時刻取得 */
+    {"GTS", getTimeHanlder, 0},
+    /* 時刻設定 */
+    {"TYR", setTimeHanlder, TimeManager::SetTimeMethod::Year},
+    {"TMO", setTimeHanlder, TimeManager::SetTimeMethod::Month},
+    {"TDA", setTimeHanlder, TimeManager::SetTimeMethod::Day},
+    {"THR", setTimeHanlder, TimeManager::SetTimeMethod::Hour},
+    {"TMI", setTimeHanlder, TimeManager::SetTimeMethod::Min},
+    {"TSE", setTimeHanlder, TimeManager::SetTimeMethod::Sec},
+    };
+
+int getNumOfRules = sizeof(rules)/sizeof(CmdParseRule);
+
+
+/****************************************************/
+/* Event Handlers */
+/****************************************************/
+/* Sample Command */
+static int sampleHanlder(CommandParser *pC, char *arg, int exarg)
+{   
+    pC->reply();
+    return 0;
+}
+
+/* Time Set Command */
+static int setTimeHanlder(CommandParser *pC, char *arg, int exarg)
+{   
+    bool success = false;
+    int setvalue = atoi(arg);
+    
+    switch (exarg) {
+    case TimeManager::SetTimeMethod::Year:
+    case TimeManager::SetTimeMethod::Month:
+    case TimeManager::SetTimeMethod::Day:
+    case TimeManager::SetTimeMethod::Hour:
+    case TimeManager::SetTimeMethod::Min:
+    case TimeManager::SetTimeMethod::Sec:
+        success = pTM->setCurrentTime(exarg,setvalue);
+        break;
+    }
+    pC->reply(success, (success)? 0 : setvalue );
+    return 0;
+}
+
+/* Time Get Command */
+static int getTimeHanlder(CommandParser *pC, char *arg, int exarg)
+{
+    int len;
+    char timestamp[TimeManager::TimeStampLength + 1] = {0};
+    Serial *pUart = pC->getCurrentUart();
+    len = pTM->getTimeStamp(timestamp);
+    pUart->printf(":%d RTS %04d %s\n", pC->getDeviceID(), len, timestamp);
+    return 0;
+}
\ No newline at end of file