1st release (without comment)
RMS_UART.cpp@9:025a189e5082, 2016-09-20 (annotated)
- Committer:
- nsrwsurasak
- Date:
- Tue Sep 20 07:40:01 2016 +0000
- Revision:
- 9:025a189e5082
- Parent:
- 8:f08bb4074bc8
- Child:
- 10:ec0470d18ea4
Fix bug and addition stop command and action event.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nsrwsurasak | 1:5e6c5fbd48d6 | 1 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 2 | ****************************************************************************** |
nsrwsurasak | 1:5e6c5fbd48d6 | 3 | * @file RMS_UART.cpp |
nsrwsurasak | 1:5e6c5fbd48d6 | 4 | * @author Surasak N |
nsrwsurasak | 9:025a189e5082 | 5 | * @version V2 |
nsrwsurasak | 9:025a189e5082 | 6 | * @date 20/09/2016 |
nsrwsurasak | 1:5e6c5fbd48d6 | 7 | * @brief Command for Mini-RMS <> RMS via UART |
nsrwsurasak | 1:5e6c5fbd48d6 | 8 | ******************************************************************************/ |
nsrwsurasak | 1:5e6c5fbd48d6 | 9 | |
nsrwsurasak | 0:bc10ea82aec3 | 10 | #include "mbed.h" |
nsrwsurasak | 1:5e6c5fbd48d6 | 11 | #include "main.h" |
nsrwsurasak | 0:bc10ea82aec3 | 12 | |
nsrwsurasak | 0:bc10ea82aec3 | 13 | #ifdef EXT_SERIAL |
nsrwsurasak | 1:5e6c5fbd48d6 | 14 | /* Using UART1 as in Debuger (ST-Link) */ |
nsrwsurasak | 0:bc10ea82aec3 | 15 | Serial serial_device(SERIAL_TX, SERIAL_RX); |
nsrwsurasak | 0:bc10ea82aec3 | 16 | #else |
nsrwsurasak | 1:5e6c5fbd48d6 | 17 | /* Using UART2 via external UART to USB */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 18 | Serial serial_device(PA_3, PB_3); |
nsrwsurasak | 0:bc10ea82aec3 | 19 | #endif |
nsrwsurasak | 0:bc10ea82aec3 | 20 | |
nsrwsurasak | 9:025a189e5082 | 21 | char Msg_RxBuf[MSG_BUF_SIZE + 1]; // Command Buffer |
nsrwsurasak | 9:025a189e5082 | 22 | int Msg_index; // Command index |
nsrwsurasak | 9:025a189e5082 | 23 | |
nsrwsurasak | 9:025a189e5082 | 24 | char Content_RxBuf[CONTENT_BUF_SIZE + 1]; // Contents Buffer |
nsrwsurasak | 9:025a189e5082 | 25 | int Content_index; // Contents index |
nsrwsurasak | 0:bc10ea82aec3 | 26 | |
nsrwsurasak | 9:025a189e5082 | 27 | char FileName[MSG2FILENAME]; // Command Buffer |
nsrwsurasak | 1:5e6c5fbd48d6 | 28 | FileRequest_CMD_Type reqFileCmdType = REQ_NONE; // An Events Request and management |
nsrwsurasak | 9:025a189e5082 | 29 | Error_Code_Type gErrorCode = EC_SUCCESS; // An Error definition |
nsrwsurasak | 1:5e6c5fbd48d6 | 30 | bool MsgContentManagement = false; // Command and Contents buffer management |
nsrwsurasak | 9:025a189e5082 | 31 | bool SystemStandBy = false; // Mini-RMS system standby flag |
nsrwsurasak | 9:025a189e5082 | 32 | bool OverBufSize = false; // Content buffer size overload |
nsrwsurasak | 0:bc10ea82aec3 | 33 | |
nsrwsurasak | 0:bc10ea82aec3 | 34 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 35 | * @brief Initials bsp and interrupt of serial communication |
nsrwsurasak | 1:5e6c5fbd48d6 | 36 | * @note BPS have 9600bps only |
nsrwsurasak | 0:bc10ea82aec3 | 37 | * @retval |
nsrwsurasak | 0:bc10ea82aec3 | 38 | */ |
nsrwsurasak | 0:bc10ea82aec3 | 39 | void Init_SerialDevice() |
nsrwsurasak | 0:bc10ea82aec3 | 40 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 41 | /* Initial begining bps with 9600bps */ |
nsrwsurasak | 0:bc10ea82aec3 | 42 | serial_device.baud(BPS_9600); |
nsrwsurasak | 1:5e6c5fbd48d6 | 43 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 44 | /* Initial interrupt callback function */ |
nsrwsurasak | 0:bc10ea82aec3 | 45 | serial_device.attach(&RxMsgInterruptCallback); |
nsrwsurasak | 0:bc10ea82aec3 | 46 | } |
nsrwsurasak | 0:bc10ea82aec3 | 47 | |
nsrwsurasak | 0:bc10ea82aec3 | 48 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 49 | * @brief Intertupt callback function |
nsrwsurasak | 1:5e6c5fbd48d6 | 50 | * @note Management fill buffer direction |
nsrwsurasak | 0:bc10ea82aec3 | 51 | * @retval |
nsrwsurasak | 0:bc10ea82aec3 | 52 | */ |
nsrwsurasak | 0:bc10ea82aec3 | 53 | void RxMsgInterruptCallback() |
nsrwsurasak | 0:bc10ea82aec3 | 54 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 55 | /* Received serial Rx interrupt */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 56 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 57 | /* Check buffer direction */ |
nsrwsurasak | 0:bc10ea82aec3 | 58 | if(MsgContentManagement == false) |
nsrwsurasak | 0:bc10ea82aec3 | 59 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 60 | /* Fill buffer to commands */ |
nsrwsurasak | 0:bc10ea82aec3 | 61 | DoTheMsgCmd(); |
nsrwsurasak | 0:bc10ea82aec3 | 62 | } |
nsrwsurasak | 0:bc10ea82aec3 | 63 | else |
nsrwsurasak | 0:bc10ea82aec3 | 64 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 65 | /* Fill buffer to contents */ |
nsrwsurasak | 0:bc10ea82aec3 | 66 | DoTheContent(); |
nsrwsurasak | 0:bc10ea82aec3 | 67 | } |
nsrwsurasak | 0:bc10ea82aec3 | 68 | } |
nsrwsurasak | 0:bc10ea82aec3 | 69 | |
nsrwsurasak | 0:bc10ea82aec3 | 70 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 71 | * @brief Fill serial data as in contents buffer |
nsrwsurasak | 1:5e6c5fbd48d6 | 72 | * @note |
nsrwsurasak | 0:bc10ea82aec3 | 73 | * @retval |
nsrwsurasak | 0:bc10ea82aec3 | 74 | */ |
nsrwsurasak | 0:bc10ea82aec3 | 75 | void DoTheContent() |
nsrwsurasak | 0:bc10ea82aec3 | 76 | { |
nsrwsurasak | 0:bc10ea82aec3 | 77 | // Note: you need to actually read from the serial to clear the RX interrupt |
nsrwsurasak | 9:025a189e5082 | 78 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 79 | /* Fill data as serial to contents buffer */ |
nsrwsurasak | 0:bc10ea82aec3 | 80 | Content_RxBuf[Content_index] = serial_device.getc(); |
nsrwsurasak | 9:025a189e5082 | 81 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 82 | /* Shift contents index */ |
nsrwsurasak | 0:bc10ea82aec3 | 83 | Content_index++; |
nsrwsurasak | 0:bc10ea82aec3 | 84 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 85 | /* Check end of content */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 86 | CheckContentMsg(); |
nsrwsurasak | 9:025a189e5082 | 87 | |
nsrwsurasak | 0:bc10ea82aec3 | 88 | } |
nsrwsurasak | 0:bc10ea82aec3 | 89 | |
nsrwsurasak | 0:bc10ea82aec3 | 90 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 91 | * @brief Fill serial data as in command buffer |
nsrwsurasak | 1:5e6c5fbd48d6 | 92 | * @note Command type and FileName |
nsrwsurasak | 0:bc10ea82aec3 | 93 | * @retval |
nsrwsurasak | 0:bc10ea82aec3 | 94 | */ |
nsrwsurasak | 0:bc10ea82aec3 | 95 | void DoTheMsgCmd() |
nsrwsurasak | 0:bc10ea82aec3 | 96 | { |
nsrwsurasak | 0:bc10ea82aec3 | 97 | |
nsrwsurasak | 0:bc10ea82aec3 | 98 | // Note: you need to actually read from the serial to clear the RX interrupt |
nsrwsurasak | 1:5e6c5fbd48d6 | 99 | /* Fill data as serial to command and file name buffer */ |
nsrwsurasak | 0:bc10ea82aec3 | 100 | Msg_RxBuf[Msg_index] = serial_device.getc(); |
nsrwsurasak | 1:5e6c5fbd48d6 | 101 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 102 | /* Shift command and filename index */ |
nsrwsurasak | 0:bc10ea82aec3 | 103 | Msg_index++; |
nsrwsurasak | 0:bc10ea82aec3 | 104 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 105 | /* Check command type */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 106 | CheckCmdType(); |
nsrwsurasak | 1:5e6c5fbd48d6 | 107 | } |
nsrwsurasak | 1:5e6c5fbd48d6 | 108 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 109 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 110 | * @brief Checking and processing contents data |
nsrwsurasak | 1:5e6c5fbd48d6 | 111 | * @note Check command *end* and clear buffer |
nsrwsurasak | 1:5e6c5fbd48d6 | 112 | * @retval |
nsrwsurasak | 1:5e6c5fbd48d6 | 113 | */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 114 | void CheckContentMsg() |
nsrwsurasak | 1:5e6c5fbd48d6 | 115 | { |
nsrwsurasak | 9:025a189e5082 | 116 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 117 | /* Found the *end* */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 118 | if(strstr(Content_RxBuf,CMD_END_OF_CONTENT)) |
nsrwsurasak | 0:bc10ea82aec3 | 119 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 120 | /* Call function for check contents */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 121 | SendContentToFile(); |
nsrwsurasak | 0:bc10ea82aec3 | 122 | } |
nsrwsurasak | 9:025a189e5082 | 123 | |
nsrwsurasak | 9:025a189e5082 | 124 | /* Check content over buffer size */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 125 | if(Content_index == CONTENT_BUF_SIZE) |
nsrwsurasak | 1:5e6c5fbd48d6 | 126 | { |
nsrwsurasak | 9:025a189e5082 | 127 | /* Clear content buffer and index */ |
nsrwsurasak | 2:38567b4310a4 | 128 | ClearContentIndexAndBuf(); |
nsrwsurasak | 9:025a189e5082 | 129 | |
nsrwsurasak | 9:025a189e5082 | 130 | /* Set content buffer overload flag */ |
nsrwsurasak | 9:025a189e5082 | 131 | OverBufSize = true; |
nsrwsurasak | 3:ff36fb2cefb0 | 132 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 133 | } |
nsrwsurasak | 1:5e6c5fbd48d6 | 134 | } |
nsrwsurasak | 1:5e6c5fbd48d6 | 135 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 136 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 137 | * @brief Checking and processing command type |
nsrwsurasak | 1:5e6c5fbd48d6 | 138 | * @note $ls, $ed, $rd, $rs and $df and etc. |
nsrwsurasak | 1:5e6c5fbd48d6 | 139 | * @retval |
nsrwsurasak | 1:5e6c5fbd48d6 | 140 | */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 141 | void CheckCmdType() |
nsrwsurasak | 1:5e6c5fbd48d6 | 142 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 143 | // Note : Procese the command type and file name |
nsrwsurasak | 0:bc10ea82aec3 | 144 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 145 | /* Command type is list file ($ls) */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 146 | if(strstr(Msg_RxBuf,CMD_LISTFILE)) |
nsrwsurasak | 9:025a189e5082 | 147 | { |
nsrwsurasak | 9:025a189e5082 | 148 | /* Set REQ_LISTDIR event's reqFileCmdType */ |
nsrwsurasak | 9:025a189e5082 | 149 | reqFileCmdType = REQ_FLAG_OK; |
nsrwsurasak | 9:025a189e5082 | 150 | |
nsrwsurasak | 9:025a189e5082 | 151 | /* Set flag evetnt */ |
nsrwsurasak | 9:025a189e5082 | 152 | /* Waiting! main program call event */ |
nsrwsurasak | 9:025a189e5082 | 153 | UART_File_event = true; |
nsrwsurasak | 9:025a189e5082 | 154 | |
nsrwsurasak | 9:025a189e5082 | 155 | } |
nsrwsurasak | 9:025a189e5082 | 156 | /* Command type is check error ($ce) */ |
nsrwsurasak | 9:025a189e5082 | 157 | else if(strstr(Msg_RxBuf,CMD_CHECK_ERROR)) |
nsrwsurasak | 9:025a189e5082 | 158 | { |
nsrwsurasak | 9:025a189e5082 | 159 | /* Send an Error definition */ |
nsrwsurasak | 9:025a189e5082 | 160 | serial_device.printf("%d",gErrorCode); |
nsrwsurasak | 9:025a189e5082 | 161 | |
nsrwsurasak | 9:025a189e5082 | 162 | /* Clear an error to EC_SUCCESS */ |
nsrwsurasak | 9:025a189e5082 | 163 | gErrorCode = EC_SUCCESS; |
nsrwsurasak | 9:025a189e5082 | 164 | |
nsrwsurasak | 9:025a189e5082 | 165 | /* Clear command index and buffer */ |
nsrwsurasak | 9:025a189e5082 | 166 | ClearCmdIndexAndBuf(); |
nsrwsurasak | 9:025a189e5082 | 167 | } |
nsrwsurasak | 9:025a189e5082 | 168 | /* RMS sent "LK" acknowledge */ |
nsrwsurasak | 9:025a189e5082 | 169 | else if(strstr(Msg_RxBuf,RMS_STATUS_LIST_OK)) |
nsrwsurasak | 0:bc10ea82aec3 | 170 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 171 | /* Set REQ_LISTDIR event's reqFileCmdType */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 172 | reqFileCmdType = REQ_LISTDIR; |
nsrwsurasak | 1:5e6c5fbd48d6 | 173 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 174 | /* Set flag evetnt */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 175 | /* Waiting! main program call event */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 176 | UART_File_event = true; |
nsrwsurasak | 1:5e6c5fbd48d6 | 177 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 178 | /* Clear command index and buffer */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 179 | ClearCmdIndexAndBuf(); |
nsrwsurasak | 9:025a189e5082 | 180 | |
nsrwsurasak | 9:025a189e5082 | 181 | } |
nsrwsurasak | 9:025a189e5082 | 182 | /* RMS sent "RK" acknowledge */ |
nsrwsurasak | 9:025a189e5082 | 183 | else if(strstr(Msg_RxBuf,RMS_STATUS_READ_OK)) |
nsrwsurasak | 9:025a189e5082 | 184 | { |
nsrwsurasak | 9:025a189e5082 | 185 | /* Categorization command type */ |
nsrwsurasak | 9:025a189e5082 | 186 | CheckReadEditCmd(); |
nsrwsurasak | 0:bc10ea82aec3 | 187 | } |
nsrwsurasak | 1:5e6c5fbd48d6 | 188 | /* Got the *.csv file name */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 189 | else if(strstr(Msg_RxBuf,FOUND_CSV_FILE)) |
nsrwsurasak | 0:bc10ea82aec3 | 190 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 191 | /* Categorization ommand type */ |
nsrwsurasak | 0:bc10ea82aec3 | 192 | CheckReadEditCmd(); |
nsrwsurasak | 0:bc10ea82aec3 | 193 | } |
nsrwsurasak | 1:5e6c5fbd48d6 | 194 | /* Got the *.xml file name */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 195 | else if(strstr(Msg_RxBuf,FOUND_XML_FILE)) |
nsrwsurasak | 0:bc10ea82aec3 | 196 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 197 | /* Categorization command type */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 198 | CheckReadEditCmd(); |
nsrwsurasak | 1:5e6c5fbd48d6 | 199 | } |
nsrwsurasak | 1:5e6c5fbd48d6 | 200 | /* Got the *.log file name */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 201 | else if(strstr(Msg_RxBuf,FOUND_LOG_FILE)) |
nsrwsurasak | 1:5e6c5fbd48d6 | 202 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 203 | /* Categorization command type */ |
nsrwsurasak | 0:bc10ea82aec3 | 204 | CheckReadEditCmd(); |
nsrwsurasak | 0:bc10ea82aec3 | 205 | } |
nsrwsurasak | 1:5e6c5fbd48d6 | 206 | /* Command type is system restart ($rs) */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 207 | else if(strstr(Msg_RxBuf,CMD_SYS_RESTART)) |
nsrwsurasak | 1:5e6c5fbd48d6 | 208 | { |
nsrwsurasak | 9:025a189e5082 | 209 | /* Set SystemStandBy to not active */ |
nsrwsurasak | 9:025a189e5082 | 210 | SystemStandBy = false; |
nsrwsurasak | 9:025a189e5082 | 211 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 212 | /* Request system restart */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 213 | NVIC_SystemReset(); |
nsrwsurasak | 1:5e6c5fbd48d6 | 214 | } |
nsrwsurasak | 4:cd5fb2575b50 | 215 | /* Command type is help ($-h) */ |
nsrwsurasak | 4:cd5fb2575b50 | 216 | else if(strstr(Msg_RxBuf,CMD_HELP)) |
nsrwsurasak | 4:cd5fb2575b50 | 217 | { |
nsrwsurasak | 4:cd5fb2575b50 | 218 | /* List all command */ |
nsrwsurasak | 4:cd5fb2575b50 | 219 | GetHelpCmd(); |
nsrwsurasak | 4:cd5fb2575b50 | 220 | } |
nsrwsurasak | 8:f08bb4074bc8 | 221 | /* Command type is stop ($sp) */ |
nsrwsurasak | 9:025a189e5082 | 222 | else if(strstr(Msg_RxBuf,CMD_SYS_PAUSE)) |
nsrwsurasak | 8:f08bb4074bc8 | 223 | { |
nsrwsurasak | 9:025a189e5082 | 224 | /* Set SystemStandBy to active */ |
nsrwsurasak | 9:025a189e5082 | 225 | SystemStandBy = true; |
nsrwsurasak | 8:f08bb4074bc8 | 226 | } |
nsrwsurasak | 1:5e6c5fbd48d6 | 227 | /* Command may be mismatched type */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 228 | else |
nsrwsurasak | 0:bc10ea82aec3 | 229 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 230 | /* Not receive true type command */ |
nsrwsurasak | 2:38567b4310a4 | 231 | if(Msg_index >= MSG2CMD) |
nsrwsurasak | 0:bc10ea82aec3 | 232 | { |
nsrwsurasak | 9:025a189e5082 | 233 | if(!((strstr(Msg_RxBuf,RMS_STATUS_LIST_OK))|| |
nsrwsurasak | 9:025a189e5082 | 234 | (strstr(Msg_RxBuf,RMS_STATUS_READ_OK))|| |
nsrwsurasak | 9:025a189e5082 | 235 | (strstr(Msg_RxBuf,CMD_LISTFILE)) || |
nsrwsurasak | 9:025a189e5082 | 236 | (strstr(Msg_RxBuf,CMD_READFILE)) || |
nsrwsurasak | 9:025a189e5082 | 237 | (strstr(Msg_RxBuf,CMD_WRITEFILE) || |
nsrwsurasak | 9:025a189e5082 | 238 | (strstr(Msg_RxBuf,CMD_HELP)) || |
nsrwsurasak | 9:025a189e5082 | 239 | (strstr(Msg_RxBuf,CMD_SYS_RESTART)) || |
nsrwsurasak | 9:025a189e5082 | 240 | (strstr(Msg_RxBuf,CMD_SYS_PAUSE)) || |
nsrwsurasak | 9:025a189e5082 | 241 | (strstr(Msg_RxBuf,CMD_DELETEFILE))))) |
nsrwsurasak | 1:5e6c5fbd48d6 | 242 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 243 | /* Call command error function */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 244 | GetCmdError(); |
nsrwsurasak | 1:5e6c5fbd48d6 | 245 | } |
nsrwsurasak | 0:bc10ea82aec3 | 246 | } |
nsrwsurasak | 0:bc10ea82aec3 | 247 | } |
nsrwsurasak | 1:5e6c5fbd48d6 | 248 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 249 | /* Command and file name buffer are full */ |
nsrwsurasak | 0:bc10ea82aec3 | 250 | if(Msg_index == MSG_BUF_SIZE) |
nsrwsurasak | 0:bc10ea82aec3 | 251 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 252 | /* Clear command index and buffer */ |
nsrwsurasak | 0:bc10ea82aec3 | 253 | ClearCmdIndexAndBuf(); |
nsrwsurasak | 0:bc10ea82aec3 | 254 | } |
nsrwsurasak | 0:bc10ea82aec3 | 255 | } |
nsrwsurasak | 0:bc10ea82aec3 | 256 | |
nsrwsurasak | 0:bc10ea82aec3 | 257 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 258 | * @brief Categorization commands type |
nsrwsurasak | 1:5e6c5fbd48d6 | 259 | * @note Received file name and type |
nsrwsurasak | 0:bc10ea82aec3 | 260 | * @retval |
nsrwsurasak | 0:bc10ea82aec3 | 261 | */ |
nsrwsurasak | 0:bc10ea82aec3 | 262 | void CheckReadEditCmd() |
nsrwsurasak | 0:bc10ea82aec3 | 263 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 264 | /* Command type is read file ($rd) */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 265 | if(strstr(Msg_RxBuf,CMD_READFILE)) |
nsrwsurasak | 0:bc10ea82aec3 | 266 | { |
nsrwsurasak | 9:025a189e5082 | 267 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 268 | /* Check file name */ |
nsrwsurasak | 0:bc10ea82aec3 | 269 | GetFileName(); |
nsrwsurasak | 9:025a189e5082 | 270 | |
nsrwsurasak | 9:025a189e5082 | 271 | /* Set REQ_READ event's reqFileCmdType */ |
nsrwsurasak | 9:025a189e5082 | 272 | reqFileCmdType = REQ_READ_CHECK; |
nsrwsurasak | 1:5e6c5fbd48d6 | 273 | |
nsrwsurasak | 9:025a189e5082 | 274 | /* Set flag evetnt */ |
nsrwsurasak | 9:025a189e5082 | 275 | /* Waiting! main program call event */ |
nsrwsurasak | 9:025a189e5082 | 276 | UART_File_event = true; |
nsrwsurasak | 9:025a189e5082 | 277 | } |
nsrwsurasak | 9:025a189e5082 | 278 | else if(strstr(Msg_RxBuf,RMS_STATUS_READ_OK)) |
nsrwsurasak | 9:025a189e5082 | 279 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 280 | /* Set REQ_READ event's reqFileCmdType */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 281 | reqFileCmdType = REQ_READ; |
nsrwsurasak | 1:5e6c5fbd48d6 | 282 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 283 | /* Set flag evetnt */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 284 | /* Waiting! main program call event */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 285 | UART_File_event = true; |
nsrwsurasak | 0:bc10ea82aec3 | 286 | } |
nsrwsurasak | 9:025a189e5082 | 287 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 288 | /* Command type is write/create file ($ed) */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 289 | else if(strstr(Msg_RxBuf,CMD_WRITEFILE)) |
nsrwsurasak | 0:bc10ea82aec3 | 290 | { |
nsrwsurasak | 9:025a189e5082 | 291 | /* Set REQ_READ event's reqFileCmdType */ |
nsrwsurasak | 9:025a189e5082 | 292 | reqFileCmdType = REQ_FLAG_OK; |
nsrwsurasak | 9:025a189e5082 | 293 | |
nsrwsurasak | 9:025a189e5082 | 294 | /* Set flag evetnt */ |
nsrwsurasak | 9:025a189e5082 | 295 | /* Waiting! main program call event */ |
nsrwsurasak | 9:025a189e5082 | 296 | UART_File_event = true; |
nsrwsurasak | 9:025a189e5082 | 297 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 298 | /* Check file name */ |
nsrwsurasak | 0:bc10ea82aec3 | 299 | GetFileName(); |
nsrwsurasak | 1:5e6c5fbd48d6 | 300 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 301 | /* Set event flag for fill contents buffer */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 302 | MsgContentManagement = true; |
nsrwsurasak | 2:38567b4310a4 | 303 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 304 | } |
nsrwsurasak | 1:5e6c5fbd48d6 | 305 | /* Command type is delete ($df) */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 306 | else if(strstr(Msg_RxBuf,CMD_DELETEFILE)) |
nsrwsurasak | 1:5e6c5fbd48d6 | 307 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 308 | /* Check file name */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 309 | GetFileName(); |
nsrwsurasak | 1:5e6c5fbd48d6 | 310 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 311 | /* Set REQ_DELETE event's reqFileCmdType */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 312 | reqFileCmdType = REQ_DELETE; |
nsrwsurasak | 1:5e6c5fbd48d6 | 313 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 314 | /* Set flag evetnt */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 315 | /* Waiting! main program call event */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 316 | UART_File_event = true; |
nsrwsurasak | 0:bc10ea82aec3 | 317 | } |
nsrwsurasak | 0:bc10ea82aec3 | 318 | else |
nsrwsurasak | 0:bc10ea82aec3 | 319 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 320 | /* Call command error function */ |
nsrwsurasak | 0:bc10ea82aec3 | 321 | GetCmdError(); |
nsrwsurasak | 0:bc10ea82aec3 | 322 | } |
nsrwsurasak | 0:bc10ea82aec3 | 323 | } |
nsrwsurasak | 0:bc10ea82aec3 | 324 | |
nsrwsurasak | 0:bc10ea82aec3 | 325 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 326 | * @brief Received command error |
nsrwsurasak | 1:5e6c5fbd48d6 | 327 | * @note $?? |
nsrwsurasak | 0:bc10ea82aec3 | 328 | * @retval |
nsrwsurasak | 0:bc10ea82aec3 | 329 | */ |
nsrwsurasak | 0:bc10ea82aec3 | 330 | void GetCmdError() |
nsrwsurasak | 0:bc10ea82aec3 | 331 | { |
nsrwsurasak | 9:025a189e5082 | 332 | /* Error is command not found */ |
nsrwsurasak | 9:025a189e5082 | 333 | gErrorCode = EC_CMD_ERROR; |
nsrwsurasak | 9:025a189e5082 | 334 | |
nsrwsurasak | 9:025a189e5082 | 335 | /* Send error status "ER" */ |
nsrwsurasak | 9:025a189e5082 | 336 | serial_device.printf(FLAG_STATUS_ERROR); |
nsrwsurasak | 1:5e6c5fbd48d6 | 337 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 338 | /* Clear command index and buffer */ |
nsrwsurasak | 0:bc10ea82aec3 | 339 | ClearCmdIndexAndBuf(); |
nsrwsurasak | 0:bc10ea82aec3 | 340 | } |
nsrwsurasak | 0:bc10ea82aec3 | 341 | |
nsrwsurasak | 0:bc10ea82aec3 | 342 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 343 | * @brief FileName process |
nsrwsurasak | 1:5e6c5fbd48d6 | 344 | * @note Fill file name as buffer |
nsrwsurasak | 0:bc10ea82aec3 | 345 | * @retval |
nsrwsurasak | 0:bc10ea82aec3 | 346 | */ |
nsrwsurasak | 0:bc10ea82aec3 | 347 | void GetFileName() |
nsrwsurasak | 0:bc10ea82aec3 | 348 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 349 | /* Copy file name from Msg to FileName */ |
nsrwsurasak | 0:bc10ea82aec3 | 350 | memcpy(FileName,&Msg_RxBuf[3],Msg_index - 3); |
nsrwsurasak | 1:5e6c5fbd48d6 | 351 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 352 | /* Clear command index and buffer */ |
nsrwsurasak | 0:bc10ea82aec3 | 353 | ClearCmdIndexAndBuf(); |
nsrwsurasak | 0:bc10ea82aec3 | 354 | } |
nsrwsurasak | 0:bc10ea82aec3 | 355 | |
nsrwsurasak | 0:bc10ea82aec3 | 356 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 357 | * @brief Request sent contents to main |
nsrwsurasak | 1:5e6c5fbd48d6 | 358 | * @note |
nsrwsurasak | 0:bc10ea82aec3 | 359 | * @retval |
nsrwsurasak | 0:bc10ea82aec3 | 360 | */ |
nsrwsurasak | 0:bc10ea82aec3 | 361 | void SendContentToFile() |
nsrwsurasak | 0:bc10ea82aec3 | 362 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 363 | /* Set fill buffer to command */ |
nsrwsurasak | 0:bc10ea82aec3 | 364 | MsgContentManagement = true; |
nsrwsurasak | 1:5e6c5fbd48d6 | 365 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 366 | /* Set REQ_WRITE event's reqFileCmdType */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 367 | reqFileCmdType = REQ_WRITE; |
nsrwsurasak | 1:5e6c5fbd48d6 | 368 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 369 | /* Set flag evetnt */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 370 | /* Waiting! main program call event */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 371 | UART_File_event = true; |
nsrwsurasak | 1:5e6c5fbd48d6 | 372 | |
nsrwsurasak | 0:bc10ea82aec3 | 373 | } |
nsrwsurasak | 0:bc10ea82aec3 | 374 | |
nsrwsurasak | 0:bc10ea82aec3 | 375 | /** |
nsrwsurasak | 4:cd5fb2575b50 | 376 | * @brief Command help |
nsrwsurasak | 4:cd5fb2575b50 | 377 | * @note $-h |
nsrwsurasak | 4:cd5fb2575b50 | 378 | * @retval |
nsrwsurasak | 4:cd5fb2575b50 | 379 | */ |
nsrwsurasak | 4:cd5fb2575b50 | 380 | void GetHelpCmd() |
nsrwsurasak | 4:cd5fb2575b50 | 381 | { |
nsrwsurasak | 9:025a189e5082 | 382 | /* List all commands*/ |
Lucyjungz | 6:e4022b92f008 | 383 | serial_device.printf("\r\n$ls : List fils as in directory"); |
Lucyjungz | 6:e4022b92f008 | 384 | serial_device.printf("\r\n$rd [File Name] : Read fils as file name"); |
Lucyjungz | 6:e4022b92f008 | 385 | serial_device.printf("\r\n$df [File Name] : Delete fils as file name"); |
Lucyjungz | 6:e4022b92f008 | 386 | serial_device.printf("\r\n$ed [File Name] [Content] : Write/Create fils as in directory with content"); |
nsrwsurasak | 9:025a189e5082 | 387 | serial_device.printf("\r\n\tNote : Content must contain EOF signature (*end*) to indicate end of file"); |
nsrwsurasak | 9:025a189e5082 | 388 | serial_device.printf("\r\n\te.g. ed TestFile.xml test content *end*"); |
Lucyjungz | 6:e4022b92f008 | 389 | serial_device.printf("\r\n$rs : Mini-RMS system restart"); |
nsrwsurasak | 9:025a189e5082 | 390 | serial_device.printf("\r\n$sp : Mini-RMS system stop"); |
nsrwsurasak | 9:025a189e5082 | 391 | serial_device.printf("\r\n\tNote : Need $rs for resumming Mini-RMS system"); |
nsrwsurasak | 4:cd5fb2575b50 | 392 | |
nsrwsurasak | 4:cd5fb2575b50 | 393 | /* Clear buffer */ |
nsrwsurasak | 4:cd5fb2575b50 | 394 | ClearCmdIndexAndBuf(); |
nsrwsurasak | 4:cd5fb2575b50 | 395 | } |
nsrwsurasak | 4:cd5fb2575b50 | 396 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 397 | * @brief Clear index and buffer of command and file name |
nsrwsurasak | 1:5e6c5fbd48d6 | 398 | * @note |
nsrwsurasak | 0:bc10ea82aec3 | 399 | * @retval |
nsrwsurasak | 0:bc10ea82aec3 | 400 | */ |
nsrwsurasak | 0:bc10ea82aec3 | 401 | void ClearCmdIndexAndBuf() |
nsrwsurasak | 0:bc10ea82aec3 | 402 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 403 | /* Clear counter */ |
nsrwsurasak | 0:bc10ea82aec3 | 404 | Msg_index = 0; |
nsrwsurasak | 1:5e6c5fbd48d6 | 405 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 406 | /* Clear buffer */ |
nsrwsurasak | 0:bc10ea82aec3 | 407 | memset(Msg_RxBuf,' ',MSG_BUF_SIZE); |
nsrwsurasak | 0:bc10ea82aec3 | 408 | } |
nsrwsurasak | 0:bc10ea82aec3 | 409 | |
nsrwsurasak | 0:bc10ea82aec3 | 410 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 411 | * @brief Clear index and buffer of contents |
nsrwsurasak | 0:bc10ea82aec3 | 412 | * @note |
nsrwsurasak | 0:bc10ea82aec3 | 413 | * @retval |
nsrwsurasak | 0:bc10ea82aec3 | 414 | */ |
nsrwsurasak | 0:bc10ea82aec3 | 415 | void ClearContentIndexAndBuf() |
nsrwsurasak | 0:bc10ea82aec3 | 416 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 417 | /* Clear counter */ |
nsrwsurasak | 0:bc10ea82aec3 | 418 | Content_index = 0; |
nsrwsurasak | 1:5e6c5fbd48d6 | 419 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 420 | /* Clear buffer */ |
nsrwsurasak | 0:bc10ea82aec3 | 421 | memset(Content_RxBuf,' ',CONTENT_BUF_SIZE); |
nsrwsurasak | 0:bc10ea82aec3 | 422 | } |
nsrwsurasak | 1:5e6c5fbd48d6 | 423 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 424 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 425 | * @brief Clear fileName buffer |
nsrwsurasak | 1:5e6c5fbd48d6 | 426 | * @note |
nsrwsurasak | 1:5e6c5fbd48d6 | 427 | * @retval |
nsrwsurasak | 1:5e6c5fbd48d6 | 428 | */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 429 | void ClearFileNameBuf() |
nsrwsurasak | 1:5e6c5fbd48d6 | 430 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 431 | /* Clear buffer */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 432 | memset(FileName,' ',MSG2FILENAME); |
nsrwsurasak | 4:cd5fb2575b50 | 433 | } |
nsrwsurasak | 9:025a189e5082 | 434 | ////////////////////////////////////////////////* END *//////////////////////////////////////////////// |