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:
Tue Apr 23 08:47:11 2019 +0000
Revision:
2:a694440145e9
Child:
5:a37e3a15444b
add TimeManager

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Inscape_ao 2:a694440145e9 1 /** --- Includes --- */
Inscape_ao 2:a694440145e9 2 #include "mbed.h"
Inscape_ao 2:a694440145e9 3 #include "TimeManager.h"
Inscape_ao 2:a694440145e9 4 #include "UartReceiver.h"
Inscape_ao 2:a694440145e9 5 #include "CommandParser.h"
Inscape_ao 2:a694440145e9 6 #include "global.h"
Inscape_ao 2:a694440145e9 7 #include "string.h"
Inscape_ao 2:a694440145e9 8
Inscape_ao 2:a694440145e9 9 static int sampleHanlder(CommandParser *pC, char *arg, int exarg);
Inscape_ao 2:a694440145e9 10 static int setTimeHanlder(CommandParser *pC, char *arg, int exarg);
Inscape_ao 2:a694440145e9 11 static int getTimeHanlder(CommandParser *pC, char *arg, int exarg);
Inscape_ao 2:a694440145e9 12
Inscape_ao 2:a694440145e9 13 /* Event Hankder */
Inscape_ao 2:a694440145e9 14 CmdParseRule rules[] = {
Inscape_ao 2:a694440145e9 15 /* サンプルコマンド */
Inscape_ao 2:a694440145e9 16 {"CMD", sampleHanlder, 0},
Inscape_ao 2:a694440145e9 17 /* 時刻取得 */
Inscape_ao 2:a694440145e9 18 {"GTS", getTimeHanlder, 0},
Inscape_ao 2:a694440145e9 19 /* 時刻設定 */
Inscape_ao 2:a694440145e9 20 {"TYR", setTimeHanlder, TimeManager::SetTimeMethod::Year},
Inscape_ao 2:a694440145e9 21 {"TMO", setTimeHanlder, TimeManager::SetTimeMethod::Month},
Inscape_ao 2:a694440145e9 22 {"TDA", setTimeHanlder, TimeManager::SetTimeMethod::Day},
Inscape_ao 2:a694440145e9 23 {"THR", setTimeHanlder, TimeManager::SetTimeMethod::Hour},
Inscape_ao 2:a694440145e9 24 {"TMI", setTimeHanlder, TimeManager::SetTimeMethod::Min},
Inscape_ao 2:a694440145e9 25 {"TSE", setTimeHanlder, TimeManager::SetTimeMethod::Sec},
Inscape_ao 2:a694440145e9 26 };
Inscape_ao 2:a694440145e9 27
Inscape_ao 2:a694440145e9 28 int getNumOfRules = sizeof(rules)/sizeof(CmdParseRule);
Inscape_ao 2:a694440145e9 29
Inscape_ao 2:a694440145e9 30
Inscape_ao 2:a694440145e9 31 /****************************************************/
Inscape_ao 2:a694440145e9 32 /* Event Handlers */
Inscape_ao 2:a694440145e9 33 /****************************************************/
Inscape_ao 2:a694440145e9 34 /* Sample Command */
Inscape_ao 2:a694440145e9 35 static int sampleHanlder(CommandParser *pC, char *arg, int exarg)
Inscape_ao 2:a694440145e9 36 {
Inscape_ao 2:a694440145e9 37 pC->reply();
Inscape_ao 2:a694440145e9 38 return 0;
Inscape_ao 2:a694440145e9 39 }
Inscape_ao 2:a694440145e9 40
Inscape_ao 2:a694440145e9 41 /* Time Set Command */
Inscape_ao 2:a694440145e9 42 static int setTimeHanlder(CommandParser *pC, char *arg, int exarg)
Inscape_ao 2:a694440145e9 43 {
Inscape_ao 2:a694440145e9 44 bool success = false;
Inscape_ao 2:a694440145e9 45 int setvalue = atoi(arg);
Inscape_ao 2:a694440145e9 46
Inscape_ao 2:a694440145e9 47 switch (exarg) {
Inscape_ao 2:a694440145e9 48 case TimeManager::SetTimeMethod::Year:
Inscape_ao 2:a694440145e9 49 case TimeManager::SetTimeMethod::Month:
Inscape_ao 2:a694440145e9 50 case TimeManager::SetTimeMethod::Day:
Inscape_ao 2:a694440145e9 51 case TimeManager::SetTimeMethod::Hour:
Inscape_ao 2:a694440145e9 52 case TimeManager::SetTimeMethod::Min:
Inscape_ao 2:a694440145e9 53 case TimeManager::SetTimeMethod::Sec:
Inscape_ao 2:a694440145e9 54 success = pTM->setCurrentTime(exarg,setvalue);
Inscape_ao 2:a694440145e9 55 break;
Inscape_ao 2:a694440145e9 56 }
Inscape_ao 2:a694440145e9 57 pC->reply(success, (success)? 0 : setvalue );
Inscape_ao 2:a694440145e9 58 return 0;
Inscape_ao 2:a694440145e9 59 }
Inscape_ao 2:a694440145e9 60
Inscape_ao 2:a694440145e9 61 /* Time Get Command */
Inscape_ao 2:a694440145e9 62 static int getTimeHanlder(CommandParser *pC, char *arg, int exarg)
Inscape_ao 2:a694440145e9 63 {
Inscape_ao 2:a694440145e9 64 int len;
Inscape_ao 2:a694440145e9 65 char timestamp[TimeManager::TimeStampLength + 1] = {0};
Inscape_ao 2:a694440145e9 66 Serial *pUart = pC->getCurrentUart();
Inscape_ao 2:a694440145e9 67 len = pTM->getTimeStamp(timestamp);
Inscape_ao 2:a694440145e9 68 pUart->printf(":%d RTS %04d %s\n", pC->getDeviceID(), len, timestamp);
Inscape_ao 2:a694440145e9 69 return 0;
Inscape_ao 2:a694440145e9 70 }