xrocusOS_ADXL355 version

Dependencies:   mbed SDFileSystem

Revision:
7:9ab8809f9693
Parent:
5:a37e3a15444b
Child:
8:b18a8764ecae
--- a/event.cpp	Thu May 09 00:06:21 2019 +0000
+++ b/event.cpp	Sat May 11 04:03:33 2019 +0000
@@ -7,33 +7,189 @@
 #include "string.h"
 
 static int sampleHanlder(CommandParser *pC, char *arg, int exarg);
+static int softResetHanlder(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);
 
+static int configIDHandler(CommandParser *pC, char *arg, int exarg);
+static int configWriteHandler(CommandParser *pC, char *arg, int exarg);
+static int configReadHandler(CommandParser *pC, char *arg, int exarg);
+
+static int startRunHandler(CommandParser *pC, char *arg, int exarg);
+static int stopReqHandler(CommandParser *pC, char *arg, int exarg);
+static int checkRunStatHandler(CommandParser *pC, char *arg, int exarg);
+static int setRepeatCountHandler(CommandParser *pC, char *arg, int exarg);
+static int setRepeatStrideHandler(CommandParser *pC, char *arg, int exarg);
+
 /* Event Hankder */
 CmdParseRule rules[] = {
-    /* サンプルコマンド */
+    /* -- sample -- */
     {"CMD", sampleHanlder, 0},
-    /* SDカード記録 */
+    /* Control SD-Card(NOT-SDHC) */
     {"SDS", startSDStore, 0},
     {"SDE", endSDStore, 0},
     {"SDW", writeSDStore, 0}, /* for TEST */
-    /* 時刻取得 */
+    /* Get Timestamp */
     {"GTS", getTimeHanlder, 0},
-    /* 時刻設定 */
+    /* Set Timestamp */
     {"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},
+    /* Sensing Control */
+    {"CRS", startRunHandler, 0},        /* Run(start) */
+    {"CRE", stopReqHandler, 0},         /* Stop -- req */
+    {"CPS", checkRunStatHandler, 0},    /* Check ReadyToRun */
+    {"RRP", setRepeatCountHandler, 0},  /* set repeat setting => Count */
+    {"RMC", setRepeatStrideHandler, 0}, /* set repeat setting => Stride */
+    /* Device Control */
+    {"SRS", softResetHanlder, 0},     /* TODO: Software Reset */
+    {"CID", configIDHandler, 0},      /* Config ID Access */
+    {"CFW", configWriteHandler, 0},   /* Config Write */
+    {"CFR", configReadHandler, 0},    /* Config Read */
     };
 
 int getNumOfRules = sizeof(rules)/sizeof(CmdParseRule);
 
+/****************************************************/
+/* Event Handlers (Device Control) */
+/****************************************************/
+static int startRunHandler(CommandParser *pC, char *arg, int exarg)
+{
+    bool success;
+    success = pDevRept->start();
+    if (!success) {
+        pC->reply(false, 3);
+        return 1;
+    }
+    pC->reply();
+    return 0;    
+}
+
+static int stopReqHandler(CommandParser *pC, char *arg, int exarg)
+{
+    bool success;
+    success = pDevRept->stop();
+    if (!success) {
+        pC->reply(false, 3);
+        return 1;
+    }
+    pC->reply();
+    return 0;    
+}
+
+static int checkRunStatHandler(CommandParser *pC, char *arg, int exarg)
+{
+    bool success;
+    success = pDevRept->readyToStart();
+    if (!success) {
+        pC->reply(false, 3);
+        return 1;
+    }
+    pC->reply();
+    return 0;    
+}
+
+static int setRepeatCountHandler(CommandParser *pC, char *arg, int exarg)
+{
+    bool success;
+    int setvalue = atoi(arg);
+    success = pDevRept->setRepeatCount(setvalue);
+    if (!success) {
+        pC->reply(false, 4);
+        return 1;
+    }
+    pC->reply();
+    return 0;    
+}
+static int setRepeatStrideHandler(CommandParser *pC, char *arg, int exarg)
+{
+    bool success;
+    char msflag = arg[3];
+    char valsrc[4] = {0};
+    int setvalue;
+    
+    /* this Argment is "xxxs" or "xxxm" */
+    memcpy(valsrc, arg, 3);
+    setvalue = atoi(valsrc);
+    
+    if (msflag == 'm') {
+        setvalue *= 60; /* setvalue x 60(min to sec)*/
+    } else if (msflag == 's') {
+        /* NOP setvalue = setvalue */
+    } else {
+        /* invalid format */
+        pC->reply(false, 6);
+        return 1;
+    }
+    success = pDevRept->setRepeatStride(setvalue);
+    if (!success) {
+        pC->reply(false, 5);
+        return 1;
+    }
+    pC->reply();
+    return 0;    
+}
+/****************************************************/
+/* Event Handlers (Device Control) */
+/****************************************************/
+static int configIDHandler(CommandParser *pC, char *arg, int exarg)
+{
+    bool success;
+    int setvalue = strtol(arg, NULL, 16);
+    success = pDevRept->setConfigId(setvalue);
+    if (!success) {
+        pC->reply(false, 3);
+        return 1;
+    }
+    pC->reply();
+    return 0;    
+}
+
+static int configWriteHandler(CommandParser *pC, char *arg, int exarg)
+{
+    bool success;
+    int setvalue = strtol(arg, NULL, 16);
+    success = pDevRept->setConfigValue(setvalue);
+    if (!success) {
+        pC->reply(false, 3);
+        return 1;
+    }
+    pC->reply();
+    return 0;
+}
+
+static int configReadHandler(CommandParser *pC, char *arg, int exarg)
+{
+    bool success;
+    int getvalue;
+    Serial *pUart = pC->getCurrentUart();
+    
+    success = pDevRept->getConfigValue(&getvalue);
+    if (!success) {
+        pC->reply(false, 3);
+        return 1;
+    }
+    pUart->printf(":%d CFG 0004 %04x\n", pC->getDeviceID(), getvalue);
+    return 0;
+}
+
+static int softResetHanlder(CommandParser *pC, char *arg, int exarg)
+{   
+    bool success;
+    success = pDevRept->resetAllStatus();
+    if (!success) {
+        pC->reply(false, 3);
+        return 1;
+    }
+    pC->reply();
+    return 0;
+}
 
 /****************************************************/
 /* Event Handlers */