1st release (without comment)
RMS_UART.cpp@3:ff36fb2cefb0, 2016-09-15 (annotated)
- Committer:
- nsrwsurasak
- Date:
- Thu Sep 15 23:05:27 2016 +0000
- Revision:
- 3:ff36fb2cefb0
- Parent:
- 2:38567b4310a4
- Child:
- 4:cd5fb2575b50
Fix bug (serial print status)
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 | 3:ff36fb2cefb0 | 125 | serial_device.printf("\n -- File is too large!!\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 | 1:5e6c5fbd48d6 | 180 | /* Command may be mismatched type */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 181 | else |
nsrwsurasak | 0:bc10ea82aec3 | 182 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 183 | /* Not receive true type command */ |
nsrwsurasak | 2:38567b4310a4 | 184 | if(Msg_index >= MSG2CMD) |
nsrwsurasak | 0:bc10ea82aec3 | 185 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 186 | if(!((strstr(Msg_RxBuf,CMD_LISTFILE)) || |
nsrwsurasak | 1:5e6c5fbd48d6 | 187 | (strstr(Msg_RxBuf,CMD_READFILE)) || |
nsrwsurasak | 1:5e6c5fbd48d6 | 188 | (strstr(Msg_RxBuf,CMD_WRITEFILE) || |
nsrwsurasak | 1:5e6c5fbd48d6 | 189 | (strstr(Msg_RxBuf,CMD_DELETEFILE))))) |
nsrwsurasak | 1:5e6c5fbd48d6 | 190 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 191 | /* Call command error function */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 192 | GetCmdError(); |
nsrwsurasak | 1:5e6c5fbd48d6 | 193 | } |
nsrwsurasak | 0:bc10ea82aec3 | 194 | } |
nsrwsurasak | 0:bc10ea82aec3 | 195 | } |
nsrwsurasak | 1:5e6c5fbd48d6 | 196 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 197 | /* Command and file name buffer are full */ |
nsrwsurasak | 0:bc10ea82aec3 | 198 | if(Msg_index == MSG_BUF_SIZE) |
nsrwsurasak | 0:bc10ea82aec3 | 199 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 200 | /* Clear command index and buffer */ |
nsrwsurasak | 0:bc10ea82aec3 | 201 | ClearCmdIndexAndBuf(); |
nsrwsurasak | 0:bc10ea82aec3 | 202 | } |
nsrwsurasak | 0:bc10ea82aec3 | 203 | } |
nsrwsurasak | 0:bc10ea82aec3 | 204 | |
nsrwsurasak | 0:bc10ea82aec3 | 205 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 206 | * @brief Categorization commands type |
nsrwsurasak | 1:5e6c5fbd48d6 | 207 | * @note Received file name and type |
nsrwsurasak | 0:bc10ea82aec3 | 208 | * @retval |
nsrwsurasak | 0:bc10ea82aec3 | 209 | */ |
nsrwsurasak | 0:bc10ea82aec3 | 210 | void CheckReadEditCmd() |
nsrwsurasak | 0:bc10ea82aec3 | 211 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 212 | /* Command type is read file ($rd) */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 213 | if(strstr(Msg_RxBuf,CMD_READFILE)) |
nsrwsurasak | 0:bc10ea82aec3 | 214 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 215 | /* Check file name */ |
nsrwsurasak | 0:bc10ea82aec3 | 216 | GetFileName(); |
nsrwsurasak | 1:5e6c5fbd48d6 | 217 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 218 | /* Set REQ_READ event's reqFileCmdType */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 219 | reqFileCmdType = REQ_READ; |
nsrwsurasak | 1:5e6c5fbd48d6 | 220 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 221 | /* Set flag evetnt */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 222 | /* Waiting! main program call event */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 223 | UART_File_event = true; |
nsrwsurasak | 0:bc10ea82aec3 | 224 | } |
nsrwsurasak | 1:5e6c5fbd48d6 | 225 | /* Command type is write/create file ($ed) */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 226 | else if(strstr(Msg_RxBuf,CMD_WRITEFILE)) |
nsrwsurasak | 0:bc10ea82aec3 | 227 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 228 | /* Check file name */ |
nsrwsurasak | 0:bc10ea82aec3 | 229 | GetFileName(); |
nsrwsurasak | 1:5e6c5fbd48d6 | 230 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 231 | /* Set event flag for fill contents buffer */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 232 | MsgContentManagement = true; |
nsrwsurasak | 2:38567b4310a4 | 233 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 234 | } |
nsrwsurasak | 1:5e6c5fbd48d6 | 235 | /* Command type is delete ($df) */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 236 | else if(strstr(Msg_RxBuf,CMD_DELETEFILE)) |
nsrwsurasak | 1:5e6c5fbd48d6 | 237 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 238 | /* Check file name */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 239 | GetFileName(); |
nsrwsurasak | 1:5e6c5fbd48d6 | 240 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 241 | /* Set REQ_DELETE event's reqFileCmdType */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 242 | reqFileCmdType = REQ_DELETE; |
nsrwsurasak | 1:5e6c5fbd48d6 | 243 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 244 | /* Set flag evetnt */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 245 | /* Waiting! main program call event */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 246 | UART_File_event = true; |
nsrwsurasak | 0:bc10ea82aec3 | 247 | } |
nsrwsurasak | 0:bc10ea82aec3 | 248 | else |
nsrwsurasak | 0:bc10ea82aec3 | 249 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 250 | /* Call command error function */ |
nsrwsurasak | 0:bc10ea82aec3 | 251 | GetCmdError(); |
nsrwsurasak | 0:bc10ea82aec3 | 252 | } |
nsrwsurasak | 0:bc10ea82aec3 | 253 | } |
nsrwsurasak | 0:bc10ea82aec3 | 254 | |
nsrwsurasak | 0:bc10ea82aec3 | 255 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 256 | * @brief Received command error |
nsrwsurasak | 1:5e6c5fbd48d6 | 257 | * @note $?? |
nsrwsurasak | 0:bc10ea82aec3 | 258 | * @retval |
nsrwsurasak | 0:bc10ea82aec3 | 259 | */ |
nsrwsurasak | 0:bc10ea82aec3 | 260 | void GetCmdError() |
nsrwsurasak | 0:bc10ea82aec3 | 261 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 262 | serial_device.printf("$%s -- Command Error %s\n",Msg_RxBuf); |
nsrwsurasak | 1:5e6c5fbd48d6 | 263 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 264 | /* Clear command index and buffer */ |
nsrwsurasak | 0:bc10ea82aec3 | 265 | ClearCmdIndexAndBuf(); |
nsrwsurasak | 0:bc10ea82aec3 | 266 | } |
nsrwsurasak | 0:bc10ea82aec3 | 267 | |
nsrwsurasak | 0:bc10ea82aec3 | 268 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 269 | * @brief FileName process |
nsrwsurasak | 1:5e6c5fbd48d6 | 270 | * @note Fill file name as buffer |
nsrwsurasak | 0:bc10ea82aec3 | 271 | * @retval |
nsrwsurasak | 0:bc10ea82aec3 | 272 | */ |
nsrwsurasak | 0:bc10ea82aec3 | 273 | void GetFileName() |
nsrwsurasak | 0:bc10ea82aec3 | 274 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 275 | /* Copy file name from Msg to FileName */ |
nsrwsurasak | 0:bc10ea82aec3 | 276 | memcpy(FileName,&Msg_RxBuf[3],Msg_index - 3); |
nsrwsurasak | 1:5e6c5fbd48d6 | 277 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 278 | /* Clear command index and buffer */ |
nsrwsurasak | 0:bc10ea82aec3 | 279 | ClearCmdIndexAndBuf(); |
nsrwsurasak | 0:bc10ea82aec3 | 280 | } |
nsrwsurasak | 0:bc10ea82aec3 | 281 | |
nsrwsurasak | 0:bc10ea82aec3 | 282 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 283 | * @brief Request sent contents to main |
nsrwsurasak | 1:5e6c5fbd48d6 | 284 | * @note |
nsrwsurasak | 0:bc10ea82aec3 | 285 | * @retval |
nsrwsurasak | 0:bc10ea82aec3 | 286 | */ |
nsrwsurasak | 0:bc10ea82aec3 | 287 | void SendContentToFile() |
nsrwsurasak | 0:bc10ea82aec3 | 288 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 289 | /* Set fill buffer to command */ |
nsrwsurasak | 0:bc10ea82aec3 | 290 | MsgContentManagement = true; |
nsrwsurasak | 1:5e6c5fbd48d6 | 291 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 292 | /* Set REQ_WRITE event's reqFileCmdType */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 293 | reqFileCmdType = REQ_WRITE; |
nsrwsurasak | 1:5e6c5fbd48d6 | 294 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 295 | /* Set flag evetnt */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 296 | /* Waiting! main program call event */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 297 | UART_File_event = true; |
nsrwsurasak | 1:5e6c5fbd48d6 | 298 | |
nsrwsurasak | 0:bc10ea82aec3 | 299 | } |
nsrwsurasak | 0:bc10ea82aec3 | 300 | |
nsrwsurasak | 0:bc10ea82aec3 | 301 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 302 | * @brief Clear index and buffer of command and file name |
nsrwsurasak | 1:5e6c5fbd48d6 | 303 | * @note |
nsrwsurasak | 0:bc10ea82aec3 | 304 | * @retval |
nsrwsurasak | 0:bc10ea82aec3 | 305 | */ |
nsrwsurasak | 0:bc10ea82aec3 | 306 | void ClearCmdIndexAndBuf() |
nsrwsurasak | 0:bc10ea82aec3 | 307 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 308 | /* Clear counter */ |
nsrwsurasak | 0:bc10ea82aec3 | 309 | Msg_index = 0; |
nsrwsurasak | 1:5e6c5fbd48d6 | 310 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 311 | /* Clear buffer */ |
nsrwsurasak | 0:bc10ea82aec3 | 312 | memset(Msg_RxBuf,' ',MSG_BUF_SIZE); |
nsrwsurasak | 0:bc10ea82aec3 | 313 | } |
nsrwsurasak | 0:bc10ea82aec3 | 314 | |
nsrwsurasak | 0:bc10ea82aec3 | 315 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 316 | * @brief Clear index and buffer of contents |
nsrwsurasak | 0:bc10ea82aec3 | 317 | * @note |
nsrwsurasak | 0:bc10ea82aec3 | 318 | * @retval |
nsrwsurasak | 0:bc10ea82aec3 | 319 | */ |
nsrwsurasak | 0:bc10ea82aec3 | 320 | void ClearContentIndexAndBuf() |
nsrwsurasak | 0:bc10ea82aec3 | 321 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 322 | /* Clear counter */ |
nsrwsurasak | 0:bc10ea82aec3 | 323 | Content_index = 0; |
nsrwsurasak | 1:5e6c5fbd48d6 | 324 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 325 | /* Clear buffer */ |
nsrwsurasak | 0:bc10ea82aec3 | 326 | memset(Content_RxBuf,' ',CONTENT_BUF_SIZE); |
nsrwsurasak | 0:bc10ea82aec3 | 327 | } |
nsrwsurasak | 1:5e6c5fbd48d6 | 328 | |
nsrwsurasak | 1:5e6c5fbd48d6 | 329 | /** |
nsrwsurasak | 1:5e6c5fbd48d6 | 330 | * @brief Clear fileName buffer |
nsrwsurasak | 1:5e6c5fbd48d6 | 331 | * @note |
nsrwsurasak | 1:5e6c5fbd48d6 | 332 | * @retval |
nsrwsurasak | 1:5e6c5fbd48d6 | 333 | */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 334 | void ClearFileNameBuf() |
nsrwsurasak | 1:5e6c5fbd48d6 | 335 | { |
nsrwsurasak | 1:5e6c5fbd48d6 | 336 | /* Clear buffer */ |
nsrwsurasak | 1:5e6c5fbd48d6 | 337 | memset(FileName,' ',MSG2FILENAME); |
nsrwsurasak | 1:5e6c5fbd48d6 | 338 | } |