TELECOMMAND MANAGER V1

Dependencies:   mbed SLCD mbed-rtos

Revision:
10:024c2ef51cb1
Parent:
8:cb93c1d3209a
Child:
11:109f16cc35d7
Child:
13:7b27a8e9cbb4
--- a/main.cpp	Mon Jul 13 10:21:45 2015 +0000
+++ b/main.cpp	Thu Jul 16 14:14:41 2015 +0000
@@ -1,4 +1,7 @@
+//how to handle interrupt while running other thread ?
+
 #include "mbed.h"
+#include "rtos.h"
 #define ENDL "\r" << endl
 
 #include "SLCD.h"
@@ -8,7 +11,7 @@
 #define PASS_TIME_LIMIT 1200
 
 Serial PC(USBTX, USBRX);
-Serial rx1m(PTE0, PTE1);
+RawSerial rx1m(PTE0, PTE1);
 
 DigitalOut ledr(LED_RED);
 DigitalOut ledg(LED_GREEN);
@@ -39,7 +42,8 @@
     
     bool new_tc_received = false;
     bool execute_obosc = false;
-
+    
+    Thread *mng_tmtc_thread = NULL;
 }
 
 Timeout rx_timeout;
@@ -51,6 +55,7 @@
 #include "SND_TM.h"
 #include "COM_RCV_TC.h"
 #include "MNG_TC.h"
+#include "ThreadFunctions.h"
 
 void after_pass(){
     pass_time.detach();
@@ -61,64 +66,39 @@
     rx_timeout.detach();
     VAR_SPACE::rx_new_node->val = 0x00;
     
-    VAR_SPACE::new_tc_received = true;
-    
     if(first_time){
         first_time = false;
         pass_time.attach(&after_pass, PASS_TIME_LIMIT);
     }
-}
-
-void rx_read() {
-    //~ store value
-    VAR_SPACE::rx_new_node->val = rx1m.getc();
-
-    //~ allocate new node
-    VAR_SPACE::rx_new_node->next = new data_list;
-    VAR_SPACE::rx_new_node = VAR_SPACE::rx_new_node->next;
-    VAR_SPACE::rx_new_node->next = NULL;
-
-    rx_timeout.attach(&after_receive, RX_TIMEOUT_LIMIT);
+    
+    VAR_SPACE::new_tc_received = true;
+    VAR_SPACE::mng_tmtc_thread->signal_set(0x01);
 }
 
-void reset_all(){
-    printf("resetting all\r\n");
-    // reset MNG_TC
-    MNG_TC::init();
-    TC_list *tcp = VAR_SPACE::Head_node;
-    while(tcp != NULL){
-        TC_list *temp = tcp->next_TC;
-        delete tcp;
-        tcp = temp;
-    }
+unsigned char rx_char = 0;
+bool byte_rx = false;
+
+void rx_read() {
+//    store value
+//    rx_char = UART1->D;
+    rx_char = rx1m.getc();
     
-    // reset COM_RCV_TC
-//    handle reset
-    
-    // reset data linked list
-    data_list *dataptr = VAR_SPACE::head_data;
-    while( dataptr != NULL ){
-        data_list *temp = dataptr->next;
-        delete dataptr;
-        dataptr = temp;
-    }
-    VAR_SPACE::head_data = new data_list;
-    VAR_SPACE::rx_new_node = VAR_SPACE::head_data;
+    byte_rx = true;
 }
 
 int main(){
     
     printf("welcome to mng_tm_tc\r\n");
-    ledr = 1;
     
     PC.baud(9600);
     
     rx1m.baud(1200);
-    rx1m.attach(&rx_read);
+    rx1m.attach(&rx_read, Serial::RxIrq);
     VAR_SPACE::head_data = new data_list;
     VAR_SPACE::head_data->next = NULL;
     VAR_SPACE::rx_new_node = VAR_SPACE::head_data;
     
+    VAR_SPACE::mng_tmtc_thread = new Thread(com_mng_fun);
     MNG_TC::init();
     
     lcd.printf("0");
@@ -131,43 +111,21 @@
     printf("\r\n");
     
     while(true){
-        ledg = !ledg;
-        if( VAR_SPACE::new_tc_received ){
-            VAR_SPACE::new_tc_received = false;
-            struct data_list *haha = VAR_SPACE::head_data;
-            unsigned int count = 0;
-            while( haha != NULL ){
-                ++count;
-//                printf("%x ", haha->val);
-                haha = haha->next;
-            }
-            printf("\t count = %u \r\n", count);
-            printf("new tc received : state = %u\r\n", VAR_SPACE::rx_state);
-            if( VAR_SPACE::rx_state == 0 ){
-                VAR_SPACE::data_node = VAR_SPACE::head_data;
-                COM_RCV_TC::rx_rcv_tc();
-                MNG_TC::start_with();
-                if( MNG_TC::check_for_missing_TC() ){
-                    printf("everything pass\r\n");
-                    VAR_SPACE::rx_state = 1;
-                    MNG_TC::execute_TC();
-                }
-            }
-            else if( VAR_SPACE::rx_state == 3 ){
-                VAR_SPACE::data_node = VAR_SPACE::head_data;
-                COM_RCV_TC::rx_rcv_tc();
-                MNG_TC::start_with();
-                if( MNG_TC::check_for_missing_TC() ){
-                    VAR_SPACE::execute_obosc = true;
-                    VAR_SPACE::rx_state = 2;
-                    MNG_TC::execute_TC();
-                }
-            }
-            else{
-                // invalid state in main found reset
-                reset_all();
-            }
+//        ledg = !ledg;
+        if(byte_rx){
+            ledg = !ledg;
+            byte_rx = false;
+            
+            VAR_SPACE::rx_new_node->val = rx_char;
+            
+            //~ allocate new node
+            VAR_SPACE::rx_new_node->next = new data_list;
+            VAR_SPACE::rx_new_node = VAR_SPACE::rx_new_node->next;
+            VAR_SPACE::rx_new_node->next = NULL;
+            
+            rx_timeout.attach(&after_receive, RX_TIMEOUT_LIMIT);
         }
+
         if(pass_over){
             pass_over = false;
             first_time = true;