1st release (without comment)
RMS_UART.cpp@7:5401cc8ee60f, 2016-09-19 (annotated)
- Committer:
- nsrwsurasak
- Date:
- Mon Sep 19 03:55:18 2016 +0000
- Revision:
- 7:5401cc8ee60f
- Parent:
- 5:4ffe57c4bfaa
Addition stop command
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 | 1:5e6c5fbd48d6 | 5 | * @version V1 |
nsrwsurasak | 1:5e6c5fbd48d6 | 6 | * @date 15/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 | 1:5e6c5fbd48d6 | 21 | char Msg_RxBuf[MSG_BUF_SIZE + 1]; // An Command Buffer |
nsrwsurasak | 1:5e6c5fbd48d6 | 22 | int Msg_index; // An Command index |
nsrwsurasak | 0:bc10ea82aec3 | 23 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 24 | char Content_RxBuf[CONTENT_BUF_SIZE + 1]; // An Contents Buffer |
nsrwsurasak | 1:5e6c5fbd48d6 | 25 | int Content_index; // An Contents index |
nsrwsurasak | 0:bc10ea82aec3 | 26 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 27 | char FileName[MSG2FILENAME]; // An Command Buffer |
nsrwsurasak | 1:5e6c5fbd48d6 | 28 | FileRequest_CMD_Type reqFileCmdType = REQ_NONE; // An Events Request and management |
nsrwsurasak | 1:5e6c5fbd48d6 | 29 | bool MsgContentManagement = false; // Command and Contents buffer management |
nsrwsurasak | 0:bc10ea82aec3 | 30 | |
nsrwsurasak | 0:bc10ea82aec3 | 31 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 32 | * @brief Initials bsp and interrupt of serial communication |
nsrwsurasak | 1:5e6c5fbd48d6 | 33 | * @note BPS have 9600bps only |
nsrwsurasak | 0:bc10ea82aec3 | 34 | * @retval |
nsrwsurasak | 0:bc10ea82aec3 | 35 | */ |
nsrwsurasak | 0:bc10ea82aec3 | 36 | void Init_SerialDevice() |
nsrwsurasak | 0:bc10ea82aec3 | 37 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 38 | /* Initial begining bps with 9600bps */ |
nsrwsurasak | 0:bc10ea82aec3 | 39 | serial_device.baud(BPS_9600); |
nsrwsurasak | 1:5e6c5fbd48d6 | 40 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 41 | /* Initial interrupt callback function */ |
nsrwsurasak | 0:bc10ea82aec3 | 42 | serial_device.attach(&RxMsgInterruptCallback); |
nsrwsurasak | 0:bc10ea82aec3 | 43 | } |
nsrwsurasak | 0:bc10ea82aec3 | 44 | |
nsrwsurasak | 0:bc10ea82aec3 | 45 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 46 | * @brief Intertupt callback function |
nsrwsurasak | 1:5e6c5fbd48d6 | 47 | * @note Management fill buffer direction |
nsrwsurasak | 0:bc10ea82aec3 | 48 | * @retval |
nsrwsurasak | 0:bc10ea82aec3 | 49 | */ |
nsrwsurasak | 0:bc10ea82aec3 | 50 | void RxMsgInterruptCallback() |
nsrwsurasak | 0:bc10ea82aec3 | 51 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 52 | /* Received serial Rx interrupt */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 53 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 54 | /* Check buffer direction */ |
nsrwsurasak | 0:bc10ea82aec3 | 55 | if(MsgContentManagement == false) |
nsrwsurasak | 0:bc10ea82aec3 | 56 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 57 | /* Fill buffer to commands */ |
nsrwsurasak | 0:bc10ea82aec3 | 58 | DoTheMsgCmd(); |
nsrwsurasak | 0:bc10ea82aec3 | 59 | } |
nsrwsurasak | 0:bc10ea82aec3 | 60 | else |
nsrwsurasak | 0:bc10ea82aec3 | 61 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 62 | /* Fill buffer to contents */ |
nsrwsurasak | 0:bc10ea82aec3 | 63 | DoTheContent(); |
nsrwsurasak | 0:bc10ea82aec3 | 64 | } |
nsrwsurasak | 0:bc10ea82aec3 | 65 | } |
nsrwsurasak | 0:bc10ea82aec3 | 66 | |
nsrwsurasak | 0:bc10ea82aec3 | 67 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 68 | * @brief Fill serial data as in contents buffer |
nsrwsurasak | 1:5e6c5fbd48d6 | 69 | * @note |
nsrwsurasak | 0:bc10ea82aec3 | 70 | * @retval |
nsrwsurasak | 0:bc10ea82aec3 | 71 | */ |
nsrwsurasak | 0:bc10ea82aec3 | 72 | void DoTheContent() |
nsrwsurasak | 0:bc10ea82aec3 | 73 | { |
nsrwsurasak | 0:bc10ea82aec3 | 74 | // Note: you need to actually read from the serial to clear the RX interrupt |
nsrwsurasak | 1:5e6c5fbd48d6 | 75 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 76 | /* Fill data as serial to contents buffer */ |
nsrwsurasak | 0:bc10ea82aec3 | 77 | Content_RxBuf[Content_index] = serial_device.getc(); |
nsrwsurasak | 1:5e6c5fbd48d6 | 78 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 79 | /* Shift contents index */ |
nsrwsurasak | 0:bc10ea82aec3 | 80 | Content_index++; |
nsrwsurasak | 0:bc10ea82aec3 | 81 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 82 | /* Check end of content */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 83 | CheckContentMsg(); |
nsrwsurasak | 0:bc10ea82aec3 | 84 | } |
nsrwsurasak | 0:bc10ea82aec3 | 85 | |
nsrwsurasak | 0:bc10ea82aec3 | 86 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 87 | * @brief Fill serial data as in command buffer |
nsrwsurasak | 1:5e6c5fbd48d6 | 88 | * @note Command type and FileName |
nsrwsurasak | 0:bc10ea82aec3 | 89 | * @retval |
nsrwsurasak | 0:bc10ea82aec3 | 90 | */ |
nsrwsurasak | 0:bc10ea82aec3 | 91 | void DoTheMsgCmd() |
nsrwsurasak | 0:bc10ea82aec3 | 92 | { |
nsrwsurasak | 0:bc10ea82aec3 | 93 | |
nsrwsurasak | 0:bc10ea82aec3 | 94 | // Note: you need to actually read from the serial to clear the RX interrupt |
nsrwsurasak | 1:5e6c5fbd48d6 | 95 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 96 | /* Fill data as serial to command and file name buffer */ |
nsrwsurasak | 0:bc10ea82aec3 | 97 | Msg_RxBuf[Msg_index] = serial_device.getc(); |
nsrwsurasak | 1:5e6c5fbd48d6 | 98 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 99 | /* Shift command and filename index */ |
nsrwsurasak | 0:bc10ea82aec3 | 100 | Msg_index++; |
nsrwsurasak | 0:bc10ea82aec3 | 101 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 102 | /* Check command type */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 103 | CheckCmdType(); |
nsrwsurasak | 1:5e6c5fbd48d6 | 104 | } |
nsrwsurasak | 1:5e6c5fbd48d6 | 105 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 106 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 107 | * @brief Checking and processing contents data |
nsrwsurasak | 1:5e6c5fbd48d6 | 108 | * @note Check command *end* and clear buffer |
nsrwsurasak | 1:5e6c5fbd48d6 | 109 | * @retval |
nsrwsurasak | 1:5e6c5fbd48d6 | 110 | */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 111 | void CheckContentMsg() |
nsrwsurasak | 1:5e6c5fbd48d6 | 112 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 113 | /* Found the *end* */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 114 | if(strstr(Content_RxBuf,CMD_END_OF_CONTENT)) |
nsrwsurasak | 0:bc10ea82aec3 | 115 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 116 | /* Call function for check contents */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 117 | SendContentToFile(); |
nsrwsurasak | 1:5e6c5fbd48d6 | 118 | |
nsrwsurasak | 2:38567b4310a4 | 119 | |
nsrwsurasak | 0:bc10ea82aec3 | 120 | } |
nsrwsurasak | 1:5e6c5fbd48d6 | 121 | /* Content buffer are full */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 122 | if(Content_index == CONTENT_BUF_SIZE) |
nsrwsurasak | 1:5e6c5fbd48d6 | 123 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 124 | /* Call function for check contents */ |
nsrwsurasak | 4:cd5fb2575b50 | 125 | serial_device.printf("\n -- File is too large!!\r\n"); |
nsrwsurasak | 2:38567b4310a4 | 126 | ClearCmdIndexAndBuf(); |
nsrwsurasak | 2:38567b4310a4 | 127 | ClearContentIndexAndBuf(); |
nsrwsurasak | 2:38567b4310a4 | 128 | ClearFileNameBuf(); |
nsrwsurasak | 3:ff36fb2cefb0 | 129 | MsgContentManagement = false; |
nsrwsurasak | 3:ff36fb2cefb0 | 130 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 131 | } |
nsrwsurasak | 1:5e6c5fbd48d6 | 132 | } |
nsrwsurasak | 1:5e6c5fbd48d6 | 133 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 134 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 135 | * @brief Checking and processing command type |
nsrwsurasak | 1:5e6c5fbd48d6 | 136 | * @note $ls, $ed, $rd, $rs and $df and etc. |
nsrwsurasak | 1:5e6c5fbd48d6 | 137 | * @retval |
nsrwsurasak | 1:5e6c5fbd48d6 | 138 | */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 139 | void CheckCmdType() |
nsrwsurasak | 1:5e6c5fbd48d6 | 140 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 141 | // Note : Procese the command type and file name |
nsrwsurasak | 0:bc10ea82aec3 | 142 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 143 | /* Command type is list file ($ls) */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 144 | if(strstr(Msg_RxBuf,CMD_LISTFILE)) |
nsrwsurasak | 0:bc10ea82aec3 | 145 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 146 | /* Set REQ_LISTDIR event's reqFileCmdType */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 147 | reqFileCmdType = REQ_LISTDIR; |
nsrwsurasak | 1:5e6c5fbd48d6 | 148 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 149 | /* Set flag evetnt */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 150 | /* Waiting! main program call event */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 151 | UART_File_event = true; |
nsrwsurasak | 1:5e6c5fbd48d6 | 152 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 153 | /* Clear command index and buffer */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 154 | ClearCmdIndexAndBuf(); |
nsrwsurasak | 0:bc10ea82aec3 | 155 | } |
nsrwsurasak | 1:5e6c5fbd48d6 | 156 | /* Got the *.csv file name */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 157 | else if(strstr(Msg_RxBuf,FOUND_CSV_FILE)) |
nsrwsurasak | 0:bc10ea82aec3 | 158 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 159 | /* Categorization ommand type */ |
nsrwsurasak | 0:bc10ea82aec3 | 160 | CheckReadEditCmd(); |
nsrwsurasak | 0:bc10ea82aec3 | 161 | } |
nsrwsurasak | 1:5e6c5fbd48d6 | 162 | /* Got the *.xml file name */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 163 | else if(strstr(Msg_RxBuf,FOUND_XML_FILE)) |
nsrwsurasak | 0:bc10ea82aec3 | 164 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 165 | /* Categorization command type */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 166 | CheckReadEditCmd(); |
nsrwsurasak | 1:5e6c5fbd48d6 | 167 | } |
nsrwsurasak | 1:5e6c5fbd48d6 | 168 | /* Got the *.log file name */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 169 | else if(strstr(Msg_RxBuf,FOUND_LOG_FILE)) |
nsrwsurasak | 1:5e6c5fbd48d6 | 170 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 171 | /* Categorization command type */ |
nsrwsurasak | 0:bc10ea82aec3 | 172 | CheckReadEditCmd(); |
nsrwsurasak | 0:bc10ea82aec3 | 173 | } |
nsrwsurasak | 1:5e6c5fbd48d6 | 174 | /* Command type is system restart ($rs) */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 175 | else if(strstr(Msg_RxBuf,CMD_SYS_RESTART)) |
nsrwsurasak | 1:5e6c5fbd48d6 | 176 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 177 | /* Request system restart */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 178 | NVIC_SystemReset(); |
nsrwsurasak | 1:5e6c5fbd48d6 | 179 | } |
nsrwsurasak | 4:cd5fb2575b50 | 180 | /* Command type is help ($-h) */ |
nsrwsurasak | 4:cd5fb2575b50 | 181 | else if(strstr(Msg_RxBuf,CMD_HELP)) |
nsrwsurasak | 4:cd5fb2575b50 | 182 | { |
nsrwsurasak | 4:cd5fb2575b50 | 183 | /* List all command */ |
nsrwsurasak | 4:cd5fb2575b50 | 184 | GetHelpCmd(); |
nsrwsurasak | 4:cd5fb2575b50 | 185 | } |
nsrwsurasak | 7:5401cc8ee60f | 186 | /* Command type is stop ($st) */ |
nsrwsurasak | 7:5401cc8ee60f | 187 | else if(strstr(Msg_RxBuf,CMD_STOP)) |
nsrwsurasak | 7:5401cc8ee60f | 188 | { |
nsrwsurasak | 7:5401cc8ee60f | 189 | /* ## waiting call function for stop or hold or self mode */ |
nsrwsurasak | 7:5401cc8ee60f | 190 | |
nsrwsurasak | 7:5401cc8ee60f | 191 | } |
nsrwsurasak | 7:5401cc8ee60f | 192 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 193 | /* Command may be mismatched type */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 194 | else |
nsrwsurasak | 0:bc10ea82aec3 | 195 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 196 | /* Not receive true type command */ |
nsrwsurasak | 2:38567b4310a4 | 197 | if(Msg_index >= MSG2CMD) |
nsrwsurasak | 0:bc10ea82aec3 | 198 | { |
nsrwsurasak | 4:cd5fb2575b50 | 199 | if(!((strstr(Msg_RxBuf,CMD_LISTFILE)) || |
nsrwsurasak | 1:5e6c5fbd48d6 | 200 | (strstr(Msg_RxBuf,CMD_READFILE)) || |
nsrwsurasak | 4:cd5fb2575b50 | 201 | (strstr(Msg_RxBuf,CMD_WRITEFILE) || |
nsrwsurasak | 7:5401cc8ee60f | 202 | (strstr(Msg_RxBuf,CMD_HELP)) || |
nsrwsurasak | 7:5401cc8ee60f | 203 | (strstr(Msg_RxBuf,CMD_STOP)) || |
nsrwsurasak | 1:5e6c5fbd48d6 | 204 | (strstr(Msg_RxBuf,CMD_DELETEFILE))))) |
nsrwsurasak | 1:5e6c5fbd48d6 | 205 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 206 | /* Call command error function */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 207 | GetCmdError(); |
nsrwsurasak | 1:5e6c5fbd48d6 | 208 | } |
nsrwsurasak | 0:bc10ea82aec3 | 209 | } |
nsrwsurasak | 0:bc10ea82aec3 | 210 | } |
nsrwsurasak | 1:5e6c5fbd48d6 | 211 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 212 | /* Command and file name buffer are full */ |
nsrwsurasak | 0:bc10ea82aec3 | 213 | if(Msg_index == MSG_BUF_SIZE) |
nsrwsurasak | 0:bc10ea82aec3 | 214 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 215 | /* Clear command index and buffer */ |
nsrwsurasak | 0:bc10ea82aec3 | 216 | ClearCmdIndexAndBuf(); |
nsrwsurasak | 0:bc10ea82aec3 | 217 | } |
nsrwsurasak | 0:bc10ea82aec3 | 218 | } |
nsrwsurasak | 0:bc10ea82aec3 | 219 | |
nsrwsurasak | 0:bc10ea82aec3 | 220 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 221 | * @brief Categorization commands type |
nsrwsurasak | 1:5e6c5fbd48d6 | 222 | * @note Received file name and type |
nsrwsurasak | 0:bc10ea82aec3 | 223 | * @retval |
nsrwsurasak | 0:bc10ea82aec3 | 224 | */ |
nsrwsurasak | 0:bc10ea82aec3 | 225 | void CheckReadEditCmd() |
nsrwsurasak | 0:bc10ea82aec3 | 226 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 227 | /* Command type is read file ($rd) */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 228 | if(strstr(Msg_RxBuf,CMD_READFILE)) |
nsrwsurasak | 0:bc10ea82aec3 | 229 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 230 | /* Check file name */ |
nsrwsurasak | 0:bc10ea82aec3 | 231 | GetFileName(); |
nsrwsurasak | 1:5e6c5fbd48d6 | 232 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 233 | /* Set REQ_READ event's reqFileCmdType */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 234 | reqFileCmdType = REQ_READ; |
nsrwsurasak | 1:5e6c5fbd48d6 | 235 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 236 | /* Set flag evetnt */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 237 | /* Waiting! main program call event */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 238 | UART_File_event = true; |
nsrwsurasak | 0:bc10ea82aec3 | 239 | } |
nsrwsurasak | 1:5e6c5fbd48d6 | 240 | /* Command type is write/create file ($ed) */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 241 | else if(strstr(Msg_RxBuf,CMD_WRITEFILE)) |
nsrwsurasak | 0:bc10ea82aec3 | 242 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 243 | /* Check file name */ |
nsrwsurasak | 0:bc10ea82aec3 | 244 | GetFileName(); |
nsrwsurasak | 1:5e6c5fbd48d6 | 245 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 246 | /* Set event flag for fill contents buffer */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 247 | MsgContentManagement = true; |
nsrwsurasak | 2:38567b4310a4 | 248 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 249 | } |
nsrwsurasak | 1:5e6c5fbd48d6 | 250 | /* Command type is delete ($df) */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 251 | else if(strstr(Msg_RxBuf,CMD_DELETEFILE)) |
nsrwsurasak | 1:5e6c5fbd48d6 | 252 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 253 | /* Check file name */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 254 | GetFileName(); |
nsrwsurasak | 1:5e6c5fbd48d6 | 255 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 256 | /* Set REQ_DELETE event's reqFileCmdType */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 257 | reqFileCmdType = REQ_DELETE; |
nsrwsurasak | 1:5e6c5fbd48d6 | 258 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 259 | /* Set flag evetnt */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 260 | /* Waiting! main program call event */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 261 | UART_File_event = true; |
nsrwsurasak | 0:bc10ea82aec3 | 262 | } |
nsrwsurasak | 0:bc10ea82aec3 | 263 | else |
nsrwsurasak | 0:bc10ea82aec3 | 264 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 265 | /* Call command error function */ |
nsrwsurasak | 0:bc10ea82aec3 | 266 | GetCmdError(); |
nsrwsurasak | 0:bc10ea82aec3 | 267 | } |
nsrwsurasak | 0:bc10ea82aec3 | 268 | } |
nsrwsurasak | 0:bc10ea82aec3 | 269 | |
nsrwsurasak | 0:bc10ea82aec3 | 270 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 271 | * @brief Received command error |
nsrwsurasak | 1:5e6c5fbd48d6 | 272 | * @note $?? |
nsrwsurasak | 0:bc10ea82aec3 | 273 | * @retval |
nsrwsurasak | 0:bc10ea82aec3 | 274 | */ |
nsrwsurasak | 0:bc10ea82aec3 | 275 | void GetCmdError() |
nsrwsurasak | 0:bc10ea82aec3 | 276 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 277 | serial_device.printf("$%s -- Command Error %s\n",Msg_RxBuf); |
nsrwsurasak | 1:5e6c5fbd48d6 | 278 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 279 | /* Clear command index and buffer */ |
nsrwsurasak | 0:bc10ea82aec3 | 280 | ClearCmdIndexAndBuf(); |
nsrwsurasak | 0:bc10ea82aec3 | 281 | } |
nsrwsurasak | 0:bc10ea82aec3 | 282 | |
nsrwsurasak | 0:bc10ea82aec3 | 283 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 284 | * @brief FileName process |
nsrwsurasak | 1:5e6c5fbd48d6 | 285 | * @note Fill file name as buffer |
nsrwsurasak | 0:bc10ea82aec3 | 286 | * @retval |
nsrwsurasak | 0:bc10ea82aec3 | 287 | */ |
nsrwsurasak | 0:bc10ea82aec3 | 288 | void GetFileName() |
nsrwsurasak | 0:bc10ea82aec3 | 289 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 290 | /* Copy file name from Msg to FileName */ |
nsrwsurasak | 0:bc10ea82aec3 | 291 | memcpy(FileName,&Msg_RxBuf[3],Msg_index - 3); |
nsrwsurasak | 1:5e6c5fbd48d6 | 292 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 293 | /* Clear command index and buffer */ |
nsrwsurasak | 0:bc10ea82aec3 | 294 | ClearCmdIndexAndBuf(); |
nsrwsurasak | 0:bc10ea82aec3 | 295 | } |
nsrwsurasak | 0:bc10ea82aec3 | 296 | |
nsrwsurasak | 0:bc10ea82aec3 | 297 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 298 | * @brief Request sent contents to main |
nsrwsurasak | 1:5e6c5fbd48d6 | 299 | * @note |
nsrwsurasak | 0:bc10ea82aec3 | 300 | * @retval |
nsrwsurasak | 0:bc10ea82aec3 | 301 | */ |
nsrwsurasak | 0:bc10ea82aec3 | 302 | void SendContentToFile() |
nsrwsurasak | 0:bc10ea82aec3 | 303 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 304 | /* Set fill buffer to command */ |
nsrwsurasak | 0:bc10ea82aec3 | 305 | MsgContentManagement = true; |
nsrwsurasak | 1:5e6c5fbd48d6 | 306 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 307 | /* Set REQ_WRITE event's reqFileCmdType */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 308 | reqFileCmdType = REQ_WRITE; |
nsrwsurasak | 1:5e6c5fbd48d6 | 309 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 310 | /* Set flag evetnt */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 311 | /* Waiting! main program call event */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 312 | UART_File_event = true; |
nsrwsurasak | 1:5e6c5fbd48d6 | 313 | |
nsrwsurasak | 0:bc10ea82aec3 | 314 | } |
nsrwsurasak | 0:bc10ea82aec3 | 315 | |
nsrwsurasak | 0:bc10ea82aec3 | 316 | /** |
nsrwsurasak | 4:cd5fb2575b50 | 317 | * @brief Command help |
nsrwsurasak | 4:cd5fb2575b50 | 318 | * @note $-h |
nsrwsurasak | 4:cd5fb2575b50 | 319 | * @retval |
nsrwsurasak | 4:cd5fb2575b50 | 320 | */ |
nsrwsurasak | 4:cd5fb2575b50 | 321 | void GetHelpCmd() |
nsrwsurasak | 4:cd5fb2575b50 | 322 | { |
nsrwsurasak | 5:4ffe57c4bfaa | 323 | serial_device.printf("\n$ls : List fils as in directory"); |
nsrwsurasak | 5:4ffe57c4bfaa | 324 | serial_device.printf("\n$rd [File Name] : Read fils as file name"); |
nsrwsurasak | 5:4ffe57c4bfaa | 325 | serial_device.printf("\n$df [File Name] : Delete fils as file name"); |
nsrwsurasak | 5:4ffe57c4bfaa | 326 | serial_device.printf("\n$ed [File Name] : Write/Create fils as in directory"); |
nsrwsurasak | 5:4ffe57c4bfaa | 327 | serial_device.printf("\n$rs : Mini-RMS system restart"); |
nsrwsurasak | 5:4ffe57c4bfaa | 328 | serial_device.printf("\n$df : List fils as in directory"); |
nsrwsurasak | 4:cd5fb2575b50 | 329 | |
nsrwsurasak | 4:cd5fb2575b50 | 330 | /* Clear buffer */ |
nsrwsurasak | 4:cd5fb2575b50 | 331 | ClearCmdIndexAndBuf(); |
nsrwsurasak | 4:cd5fb2575b50 | 332 | } |
nsrwsurasak | 4:cd5fb2575b50 | 333 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 334 | * @brief Clear index and buffer of command and file name |
nsrwsurasak | 1:5e6c5fbd48d6 | 335 | * @note |
nsrwsurasak | 0:bc10ea82aec3 | 336 | * @retval |
nsrwsurasak | 0:bc10ea82aec3 | 337 | */ |
nsrwsurasak | 0:bc10ea82aec3 | 338 | void ClearCmdIndexAndBuf() |
nsrwsurasak | 0:bc10ea82aec3 | 339 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 340 | /* Clear counter */ |
nsrwsurasak | 0:bc10ea82aec3 | 341 | Msg_index = 0; |
nsrwsurasak | 1:5e6c5fbd48d6 | 342 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 343 | /* Clear buffer */ |
nsrwsurasak | 0:bc10ea82aec3 | 344 | memset(Msg_RxBuf,' ',MSG_BUF_SIZE); |
nsrwsurasak | 0:bc10ea82aec3 | 345 | } |
nsrwsurasak | 0:bc10ea82aec3 | 346 | |
nsrwsurasak | 0:bc10ea82aec3 | 347 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 348 | * @brief Clear index and buffer of contents |
nsrwsurasak | 0:bc10ea82aec3 | 349 | * @note |
nsrwsurasak | 0:bc10ea82aec3 | 350 | * @retval |
nsrwsurasak | 0:bc10ea82aec3 | 351 | */ |
nsrwsurasak | 0:bc10ea82aec3 | 352 | void ClearContentIndexAndBuf() |
nsrwsurasak | 0:bc10ea82aec3 | 353 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 354 | /* Clear counter */ |
nsrwsurasak | 0:bc10ea82aec3 | 355 | Content_index = 0; |
nsrwsurasak | 1:5e6c5fbd48d6 | 356 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 357 | /* Clear buffer */ |
nsrwsurasak | 0:bc10ea82aec3 | 358 | memset(Content_RxBuf,' ',CONTENT_BUF_SIZE); |
nsrwsurasak | 0:bc10ea82aec3 | 359 | } |
nsrwsurasak | 1:5e6c5fbd48d6 | 360 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 361 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 362 | * @brief Clear fileName buffer |
nsrwsurasak | 1:5e6c5fbd48d6 | 363 | * @note |
nsrwsurasak | 1:5e6c5fbd48d6 | 364 | * @retval |
nsrwsurasak | 1:5e6c5fbd48d6 | 365 | */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 366 | void ClearFileNameBuf() |
nsrwsurasak | 1:5e6c5fbd48d6 | 367 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 368 | /* Clear buffer */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 369 | memset(FileName,' ',MSG2FILENAME); |
nsrwsurasak | 4:cd5fb2575b50 | 370 | } |