1st release (without comment)

Committer:
nsrwsurasak
Date:
Mon Sep 26 08:26:13 2016 +0000
Revision:
12:3bbbabca6590
Parent:
10:ec0470d18ea4
Change error type refer requirement.

Who changed what in which revision?

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