TELECOMMAND MANAGER V1

Dependencies:   mbed SLCD mbed-rtos

Revision:
7:e71ecfe3a340
Parent:
6:6e9ae3b44e60
Child:
8:cb93c1d3209a
--- a/COM_RCV_TC.h	Sat Jul 04 13:22:07 2015 +0000
+++ b/COM_RCV_TC.h	Mon Jul 06 05:00:29 2015 +0000
@@ -4,8 +4,18 @@
 //have kept this slightly higher than actual//donno why gives error 
 
 
-namespace RCV_TC{
-    uint16_t x = 0;//counter for keeping count of data read
+class RCV_TC{
+
+private:
+    uint16_t x;
+    //counter for keeping count of data read
+    TC_list *rcv_tc_head;
+    unsigned char temp[135];
+    
+    TC_list *t_frame;
+    TC_list *prev_frame;
+    
+    bool crc_pass;
     
     //this just converts a binary number to store in int variable, I am using while creating sample telecommands
     #define B(x) S_to_binary_(#x)
@@ -19,13 +29,6 @@
         return i;
     }
     
-    unsigned char temp[135];
-    
-    TC_list *t_frame;
-    TC_list *prev_frame;
-    
-    bool crc_pass;
-    
     void copy_bit(unsigned char* src_byte, unsigned char* dest_byte, unsigned char* count)
     {
         if (*src_byte & 0x80)
@@ -41,11 +44,20 @@
     unsigned char read_byte(unsigned char* shift_in)
     {
         unsigned char byte;
-        byte = VAR_SPACE::data[x++];
-//        byte = VAR_SPACE::data_node->val;
-//        VAR_SPACE::data_node = VAR_SPACE::data_node->next;
+        
+        // byte = VAR_SPACE::data[x++];
+        ++x;
         
-//        ++x;
+        byte = VAR_SPACE::data_node->val;
+        data_list *temp = VAR_SPACE::data_node->next;
+        delete VAR_SPACE::data_node;
+        VAR_SPACE::data_node = temp;
+        
+        if( x == 1 ){
+            VAR_SPACE::head_data = new data_list;
+            VAR_SPACE::rx_new_node = VAR_SPACE::head_data;
+            VAR_SPACE::rx_new_node->next = NULL;
+        }
 
         *shift_in = 0;
     
@@ -63,8 +75,8 @@
         t_frame = new TC_list;
         t_frame->next_TC = NULL;
         if(*frame_no == 0){
-            VAR_SPACE::Head_node = t_frame;
-            prev_frame = VAR_SPACE::Head_node;
+            rcv_tc_head = t_frame;
+            prev_frame = rcv_tc_head;
         }
         else{
             prev_frame->next_TC = t_frame;
@@ -143,6 +155,13 @@
         }//considering 3rd bit of 2nd byte of packet as last bit flag
     }
     
+public:    
+    
+    // Constructor
+    RCV_TC(TC_list *HEAD){
+        rcv_tc_head = HEAD;
+        x = 0;
+    }
     
     void RX_RCV_TC() 
     {
@@ -244,7 +263,13 @@
                 dstuff_byte = 0;
             }
         }
-    //RX end
+        
+        //RX end
+        while(VAR_SPACE::data_node != NULL){
+            data_list *temp = VAR_SPACE::data_node->next;
+            delete VAR_SPACE::data_node;
+            VAR_SPACE::data_node = temp; 
+        }
     }
     
-}
+};