UART Command Parser Time Manager Data Store for SD Card for stm32l476 [it's not Licensed as BSD/GPLx]
Dependencies: mbed SDFileSystem
Revision 19:36072b9b79f3, committed 2019-07-05
- Comitter:
- Inscape_ao
- Date:
- Fri Jul 05 01:26:19 2019 +0000
- Parent:
- 18:f0027b61bc08
- Commit message:
- add LICENSE.txt
Changed in this revision
diff -r f0027b61bc08 -r 36072b9b79f3 LICENSE.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LICENSE.txt Fri Jul 05 01:26:19 2019 +0000 @@ -0,0 +1,27 @@ +Copyright (c) 2019, Analog Devices, Inc. +Copyright (c) 2019, Inscape, Inc. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +The views and conclusions contained in the software and documentation are those +of the authors and should not be interpreted as representing official policies, +either expressed or implied, of the FreeBSD Project.
diff -r f0027b61bc08 -r 36072b9b79f3 common/CommandParser.cpp --- a/common/CommandParser.cpp Fri Jun 14 00:21:09 2019 +0000 +++ b/common/CommandParser.cpp Fri Jul 05 01:26:19 2019 +0000 @@ -41,16 +41,16 @@ /* parsing */ head = pStr; - uprintf("%s\n", pStr); + //uprintf("%s\n", pStr); /** Command Format ":0 CMD 0000" */ if (len != CmdLen) { - this->reply(false, CommandParser::CmdReply::InvalidLen); + this->reply(false, CommandParser::NakCode::NAK_INVAL_LEN); return -1; } /** check Command Header */ if (head[0] != ':') { - this->reply(false, CommandParser::CmdReply::InvalidFmt); + this->reply(false, CommandParser::NakCode::NAK_INVAL_FMT); return -1; } /** check Command DeviceID */ @@ -72,7 +72,7 @@ ruleTable[rn].exarg); } - this->reply(false, CommandParser::CmdReply::InvalidCmd); + this->reply(false, CommandParser::NakCode::NAK_INVAL_CMD); return -1; }
diff -r f0027b61bc08 -r 36072b9b79f3 event.cpp --- a/event.cpp Fri Jun 14 00:21:09 2019 +0000 +++ b/event.cpp Fri Jul 05 01:26:19 2019 +0000 @@ -66,7 +66,7 @@ bool success; success = pDevRept->start(); if (!success) { - pC->reply(false, 3); + pC->reply(false, CommandParser::NakCode::NAK_IN_RUNNING); return 1; } pC->reply(); @@ -78,7 +78,7 @@ bool success; success = pDevRept->stop(); if (!success) { - pC->reply(false, 3); + pC->reply(false, CommandParser::NakCode::NAK_IN_STOPPED); return 1; } pC->reply(); @@ -90,7 +90,7 @@ bool success; success = pDevRept->readyToStart(); if (!success) { - pC->reply(false, 3); + pC->reply(false, CommandParser::NakCode::NAK_IN_RUNNING); return 1; } pC->reply(); @@ -103,7 +103,7 @@ int setvalue = atoi(arg); success = pDevRept->setRepeatCount(setvalue); if (!success) { - pC->reply(false, 4); + pC->reply(false, CommandParser::NakCode::NAK_IN_RUNNING); return 1; } pC->reply(); @@ -126,12 +126,12 @@ /* NOP setvalue = setvalue */ } else { /* invalid format */ - pC->reply(false, 6); + pC->reply(false, CommandParser::NakCode::NAK_INVAL_PARAM); return 1; } success = pDevRept->setRepeatStride(setvalue); if (!success) { - pC->reply(false, 5); + pC->reply(false, CommandParser::NakCode::NAK_IN_RUNNING); return 1; } pC->reply(); @@ -148,13 +148,13 @@ setMode = false; } else { /* INVALID COMMAND */ - pC->reply(false, 7); + pC->reply(false, CommandParser::NakCode::NAK_INVAL_PARAM); return 1; } success = pDevRept->setRepeatSingleShot(setMode); if (success != true) { /* INVALID COMMAND in SetMode */ - pC->reply(false, 5); + pC->reply(false, CommandParser::NakCode::NAK_IN_RUNNING); return 1; } pC->reply(); @@ -170,7 +170,7 @@ int setvalue = strtol(arg, NULL, 16); success = pDevRept->setConfigId(setvalue); if (!success) { - pC->reply(false, 3); + pC->reply(false, CommandParser::NakCode::NAK_INVAL_SEQ); return 1; } pC->reply(); @@ -183,7 +183,7 @@ int setvalue = strtol(arg, NULL, 16); success = pDevRept->setConfigValue(setvalue); if (!success) { - pC->reply(false, 3); + pC->reply(false, CommandParser::NakCode::NAK_INVAL_SEQ); return 1; } pC->reply(); @@ -198,7 +198,7 @@ success = pDevRept->getConfigValue(&getvalue); if (!success) { - pC->reply(false, 3); + pC->reply(false, CommandParser::NakCode::NAK_INVAL_SEQ); return 1; } uprintf(":%d CFG 0004 %04x\n", pC->getDeviceID(), getvalue); @@ -223,8 +223,11 @@ /* Sample Command */ static int sampleHanlder(CommandParser *pC, char *arg, int exarg) { - pC->reply(); - return 0; + wait(1); + NVIC_SystemReset(); + /* Never Reached. */ + pC->reply(false, CommandParser::NakCode::NAK_INVAL_SEQ); + return 1; } /****************************************************/ @@ -233,7 +236,7 @@ static int startSDStore(CommandParser *pC, char *arg, int exarg) { if (pSds->startFileWithTimeStamp("","txt") != true) { - pC->reply(false, 1); + pC->reply(false, CommandParser::NakCode::NAK_INTERNAL_ERR); return 1; } pC->reply(); @@ -262,7 +265,7 @@ if ((fp = pSds->getFilePointer()) == NULL) { /* NOP */ - pC->reply(false, 2); + pC->reply(false, CommandParser::NakCode::NAK_INVAL_SEQ); return 2; } pTM->getTimeStamp(curr); @@ -291,7 +294,7 @@ success = pTM->setCurrentTime(exarg,setvalue); break; } - pC->reply(success, (success)? 0 : setvalue ); + pC->reply(success, (success)? 0 : CommandParser::NakCode::NAK_INVAL_PARAM ); return 0; }
diff -r f0027b61bc08 -r 36072b9b79f3 include/CommandParser.h --- a/include/CommandParser.h Fri Jun 14 00:21:09 2019 +0000 +++ b/include/CommandParser.h Fri Jul 05 01:26:19 2019 +0000 @@ -24,13 +24,18 @@ /* CMD total length */ const static int CmdLen = sizeof(":0 CMD 0000") - 1 /* EOL */; /* reply code (for ACK/NAK) */ - class CmdReply + class NakCode { public: - const static int Success = 0; - const static int InvalidFmt = 1; - const static int InvalidCmd = 2; - const static int InvalidLen = 3; + const static int NAK_UNDEFINED = 0000; + const static int NAK_INVAL_CMD = 1000; + const static int NAK_INVAL_LEN = 1001; + const static int NAK_INVAL_FMT = 1002; + const static int NAK_INVAL_PARAM = 1003; + const static int NAK_INVAL_SEQ = 1004; + const static int NAK_IN_RUNNING = 2000; + const static int NAK_IN_STOPPED = 2010; + const static int NAK_INTERNAL_ERR = 4000; }; private: int deviceID;
diff -r f0027b61bc08 -r 36072b9b79f3 main.cpp --- a/main.cpp Fri Jun 14 00:21:09 2019 +0000 +++ b/main.cpp Fri Jul 05 01:26:19 2019 +0000 @@ -54,6 +54,7 @@ pCP->run(); uprintf(":%d ACK 0004 0000\n", deviceId); + uprintf(":%d WAK 0004 0000\n", deviceId); dbgprintf("start mainloop\n"); mainloop(); }