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

Dependencies:   mbed SDFileSystem

Revision:
5:a37e3a15444b
Parent:
2:a694440145e9
Child:
7:9ab8809f9693
--- a/event.cpp	Wed Apr 24 00:40:42 2019 +0000
+++ b/event.cpp	Wed Apr 24 02:34:51 2019 +0000
@@ -9,11 +9,18 @@
 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);
+static int startSDStore(CommandParser *pC, char *arg, int exarg);
+static int endSDStore(CommandParser *pC, char *arg, int exarg);
+static int writeSDStore(CommandParser *pC, char *arg, int exarg);
 
 /* Event Hankder */
 CmdParseRule rules[] = {
     /* サンプルコマンド */
     {"CMD", sampleHanlder, 0},
+    /* SDカード記録 */
+    {"SDS", startSDStore, 0},
+    {"SDE", endSDStore, 0},
+    {"SDW", writeSDStore, 0}, /* for TEST */
     /* 時刻取得 */
     {"GTS", getTimeHanlder, 0},
     /* 時刻設定 */
@@ -38,6 +45,54 @@
     return 0;
 }
 
+/****************************************************/
+/* Event Handlers (SD Control) */
+/****************************************************/
+static int startSDStore(CommandParser *pC, char *arg, int exarg)
+{
+    if (pSds->startFileWithTimeStamp("","txt") != true) {
+        pC->reply(false, 1);
+        return 1;
+    }
+    pC->reply();
+    return 0;
+}
+
+static int endSDStore(CommandParser *pC, char *arg, int exarg)
+{
+    FILE *fp;
+    if ((fp = pSds->getFilePointer()) == NULL) {
+        /* NOP */
+        pC->reply(false, 2);
+        return 2;
+    }
+    fprintf(fp, "call endSDStore(%s)\n", pSds->getFileName());    
+    pSds->syncFile();
+    pSds->closeFile();
+    pC->reply();
+    return 0;
+}
+
+static int writeSDStore(CommandParser *pC, char *arg, int exarg)
+{
+    FILE *fp;
+    char curr[TimeManager::TimeStampLength + 1] = {0};
+    
+    if ((fp = pSds->getFilePointer()) == NULL) {
+        /* NOP */
+        pC->reply(false, 2);
+        return 2;
+    }
+    pTM->getTimeStamp(curr);
+    fprintf(fp, "call writeSDStore at %s\n", curr);    
+    pSds->syncFile();
+    pC->reply();
+    return 0;
+}
+
+/****************************************************/
+/* Event Handlers (Time Control) */
+/****************************************************/
 /* Time Set Command */
 static int setTimeHanlder(CommandParser *pC, char *arg, int exarg)
 {