1st release (without comment)

Revision:
9:025a189e5082
Parent:
8:f08bb4074bc8
Child:
10:ec0470d18ea4
--- a/RMS_UART.cpp	Mon Sep 19 04:00:29 2016 +0000
+++ b/RMS_UART.cpp	Tue Sep 20 07:40:01 2016 +0000
@@ -2,8 +2,8 @@
   ******************************************************************************
   * @file    RMS_UART.cpp
   * @author  Surasak N
-  * @version V1
-  * @date    15/09/2016
+  * @version V2
+  * @date    20/09/2016
   * @brief   Command for Mini-RMS <> RMS via UART
   ******************************************************************************/
   
@@ -18,15 +18,18 @@
     Serial serial_device(PA_3, PB_3);
 #endif
 
-char Msg_RxBuf[MSG_BUF_SIZE + 1];               // An Command Buffer 
-int  Msg_index;                                 // An Command index
+char Msg_RxBuf[MSG_BUF_SIZE + 1];               // Command Buffer 
+int  Msg_index;                                 // Command index
+
+char Content_RxBuf[CONTENT_BUF_SIZE + 1];       // Contents Buffer 
+int  Content_index;                             // Contents index
 
-char Content_RxBuf[CONTENT_BUF_SIZE + 1];       // An Contents Buffer 
-int  Content_index;                             // An Contents index
-
-char FileName[MSG2FILENAME];                    // An Command Buffer 
+char FileName[MSG2FILENAME];                    // Command Buffer 
 FileRequest_CMD_Type reqFileCmdType = REQ_NONE; // An Events Request and management
+Error_Code_Type gErrorCode = EC_SUCCESS;        // An Error definition
 bool MsgContentManagement = false;              // Command and Contents buffer management
+bool SystemStandBy = false;                     // Mini-RMS system standby flag
+bool OverBufSize   = false;                     // Content buffer size overload
 
 /**
  * @brief   Initials bsp and interrupt of serial communication
@@ -72,15 +75,16 @@
 void DoTheContent()
 {   
     // Note: you need to actually read from the serial to clear the RX interrupt
-    
+  
     /* Fill data as serial to contents buffer */
     Content_RxBuf[Content_index] = serial_device.getc();
-    
+        
     /* Shift contents index */
     Content_index++;
     
     /* Check end of content */
     CheckContentMsg();
+
 }
 
  /**
@@ -92,7 +96,6 @@
 {
         
     // Note: you need to actually read from the serial to clear the RX interrupt
-    
     /* Fill data as serial to command and file name buffer */
     Msg_RxBuf[Msg_index] = serial_device.getc();
     
@@ -110,23 +113,22 @@
  */
 void CheckContentMsg()
 {
+    
     /* Found the *end* */
     if(strstr(Content_RxBuf,CMD_END_OF_CONTENT))
     {
         /* Call function for check contents */
         SendContentToFile();
-        
-        
     }
-    /* Content buffer are full */
+    
+    /* Check content over buffer size */
     if(Content_index == CONTENT_BUF_SIZE)
     {
-        /* Call function for check contents */
-        serial_device.printf("\n -- File is too large!!\r\n");
-        ClearCmdIndexAndBuf();
+        /* Clear content buffer and index */
         ClearContentIndexAndBuf();
-        ClearFileNameBuf();
-        MsgContentManagement = false;
+        
+        /* Set content buffer overload flag */
+        OverBufSize = true;
         
     }
 }
@@ -142,6 +144,29 @@
     
     /* Command type is list file ($ls) */
     if(strstr(Msg_RxBuf,CMD_LISTFILE))
+    {        
+        /* Set REQ_LISTDIR  event's reqFileCmdType */
+        reqFileCmdType = REQ_FLAG_OK;
+        
+        /* Set flag evetnt */
+        /* Waiting! main program call event */
+        UART_File_event = true;
+        
+    }
+    /* Command type is check error ($ce) */
+    else if(strstr(Msg_RxBuf,CMD_CHECK_ERROR))
+    {
+        /* Send an Error definition */
+        serial_device.printf("%d",gErrorCode);
+        
+        /* Clear an error to EC_SUCCESS */
+        gErrorCode = EC_SUCCESS;
+        
+        /* Clear command index and buffer */
+        ClearCmdIndexAndBuf();
+    }
+    /* RMS sent "LK" acknowledge */
+    else if(strstr(Msg_RxBuf,RMS_STATUS_LIST_OK))
     {
         /* Set REQ_LISTDIR  event's reqFileCmdType */
         reqFileCmdType = REQ_LISTDIR;
@@ -152,6 +177,13 @@
         
         /* Clear command index and buffer */
         ClearCmdIndexAndBuf();
+        
+    }
+    /* RMS sent "RK" acknowledge */
+    else if(strstr(Msg_RxBuf,RMS_STATUS_READ_OK))
+    {
+        /* Categorization command type */
+        CheckReadEditCmd();
     }
     /* Got the *.csv file name */
     else if(strstr(Msg_RxBuf,FOUND_CSV_FILE))
@@ -174,6 +206,9 @@
     /* Command type is system restart ($rs) */
     else if(strstr(Msg_RxBuf,CMD_SYS_RESTART))
     {
+        /* Set SystemStandBy to not active */
+        SystemStandBy = false;
+        
         /* Request system restart */
         NVIC_SystemReset();
     }
@@ -184,10 +219,10 @@
         GetHelpCmd();
     }
     /* Command type is stop ($sp) */
-    else if(strstr(Msg_RxBuf,CMD_STOP   ))
+    else if(strstr(Msg_RxBuf,CMD_SYS_PAUSE))
     {
-        /* Stop/Hold systems */
-        
+        /* Set SystemStandBy to active */
+        SystemStandBy = true;
     }
     /* Command may be mismatched type */
     else
@@ -195,12 +230,15 @@
         /* Not receive true type command */
         if(Msg_index >= MSG2CMD)
         {
-            if(!((strstr(Msg_RxBuf,CMD_LISTFILE))  || 
-                  (strstr(Msg_RxBuf,CMD_READFILE)) || 
-                  (strstr(Msg_RxBuf,CMD_WRITEFILE) ||
-                  (strstr(Msg_RxBuf,CMD_HELP))     || 
-                  (strstr(Msg_RxBuf,CMD_STOP))     || 
-                  (strstr(Msg_RxBuf,CMD_DELETEFILE)))))
+            if(!((strstr(Msg_RxBuf,RMS_STATUS_LIST_OK))||
+                 (strstr(Msg_RxBuf,RMS_STATUS_READ_OK))||
+                 (strstr(Msg_RxBuf,CMD_LISTFILE))      || 
+                 (strstr(Msg_RxBuf,CMD_READFILE))      || 
+                 (strstr(Msg_RxBuf,CMD_WRITEFILE)      ||
+                 (strstr(Msg_RxBuf,CMD_HELP))          || 
+                 (strstr(Msg_RxBuf,CMD_SYS_RESTART))   ||
+                 (strstr(Msg_RxBuf,CMD_SYS_PAUSE))     || 
+                 (strstr(Msg_RxBuf,CMD_DELETEFILE)))))
             {
                 /* Call command error function */ 
                 GetCmdError();
@@ -226,9 +264,19 @@
     /* Command type is read file ($rd) */
     if(strstr(Msg_RxBuf,CMD_READFILE))
     {   
+    
         /* Check file name */
         GetFileName();
+
+        /* Set REQ_READ  event's reqFileCmdType */
+        reqFileCmdType = REQ_READ_CHECK;
         
+        /* Set flag evetnt */
+        /* Waiting! main program call event */
+        UART_File_event = true;
+    }
+    else if(strstr(Msg_RxBuf,RMS_STATUS_READ_OK))
+    {        
         /* Set REQ_READ  event's reqFileCmdType */
         reqFileCmdType = REQ_READ;
         
@@ -236,9 +284,17 @@
         /* Waiting! main program call event */
         UART_File_event = true;
     }
+    
     /* Command type is write/create file ($ed) */
     else if(strstr(Msg_RxBuf,CMD_WRITEFILE))
     {
+        /* Set REQ_READ  event's reqFileCmdType */
+        reqFileCmdType = REQ_FLAG_OK;
+        
+        /* Set flag evetnt */
+        /* Waiting! main program call event */
+        UART_File_event = true;
+        
         /* Check file name */
         GetFileName();
         
@@ -273,7 +329,11 @@
  */
 void GetCmdError()
 {   
-    serial_device.printf("$%s -- Command Error %s\n",Msg_RxBuf);
+    /* Error is command not found */
+    gErrorCode = EC_CMD_ERROR;
+    
+    /* Send error status "ER" */
+    serial_device.printf(FLAG_STATUS_ERROR);
     
     /* Clear command index and buffer */
     ClearCmdIndexAndBuf();
@@ -319,13 +379,16 @@
  */
 void GetHelpCmd()
 {   
+    /* List all commands*/
     serial_device.printf("\r\n$ls : List fils as in directory");
     serial_device.printf("\r\n$rd [File Name] : Read fils as file name");
     serial_device.printf("\r\n$df [File Name] : Delete fils as file name");
     serial_device.printf("\r\n$ed [File Name] [Content] : Write/Create fils as in directory with content");
-    serial_device.printf("\r\n Note : Content must contain EOF signature (*end*) to indicate end of file");
-    serial_device.printf("\r\n e.g. ed TestFile.xml test content *end*");
+    serial_device.printf("\r\n\tNote : Content must contain EOF signature (*end*) to indicate end of file");
+    serial_device.printf("\r\n\te.g. ed TestFile.xml test content *end*");
     serial_device.printf("\r\n$rs : Mini-RMS system restart");
+    serial_device.printf("\r\n$sp : Mini-RMS system stop");
+    serial_device.printf("\r\n\tNote : Need $rs for resumming Mini-RMS system");
     
     /* Clear buffer */
     ClearCmdIndexAndBuf();
@@ -368,3 +431,4 @@
     /* Clear buffer */
     memset(FileName,' ',MSG2FILENAME);
 }
+////////////////////////////////////////////////* END *////////////////////////////////////////////////
\ No newline at end of file