APP4 S5

Dependencies:   mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
Cheroukee
Date:
Thu Oct 12 20:48:02 2017 +0000
Parent:
8:a878763b0ae3
Child:
10:c4629b6c42f8
Commit message:
Hello

Changed in this revision

radio.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/radio.cpp	Thu Oct 12 20:14:21 2017 +0000
+++ b/radio.cpp	Thu Oct 12 20:48:02 2017 +0000
@@ -27,12 +27,12 @@
 
 DigitalOut output(OUTPUT_RADIO);
 
-#ifdef LED
-DigitalOut in_debug_led(LED4);
-DigitalOut out_debug_led(LED3);
+#ifndef LED
+DigitalOut in_debug_led4(LED4);
+DigitalOut out_debug_led3(LED3);
 
-DigitalOut frame_end_led(LED2);
-DigitalOut frame_in_end_led(LED1);
+DigitalOut frame_out_end_led2(LED2);
+DigitalOut frame_in_end_led1(LED1);
 #endif
 
 Serial PC(USBTX, USBRX);
@@ -54,25 +54,20 @@
     in_idle
 } receive_state_t;
 
-
-
-DigitalOut led4(LED4);
-DigitalOut led3(LED3);
-DigitalOut led2(LED2);
-DigitalOut led1(LED1);
+int start_speed = MANCHESTER_SPEED_OUT;
 
 byte current_state = in_attente;
 byte current_byte_progress = 0;
 
-
 void stop_frame(void const *n);
 
 RtosTimer ticker_watch(stop_frame, osTimerPeriodic, NULL);
+
 Thread thread;
 
 void stop_frame(void const *n)
 {
-    //frame_in_end_led = 0;
+    frame_in_end_led1 = 0;
     current_state = in_attente;
     current_byte_progress = 0;
     ticker_watch.stop();
@@ -89,31 +84,25 @@
     
     static byte current_byte = 0;
     
-    //in_debug_led = !in_debug_led;   
+    in_debug_led4 = !in_debug_led4;   
     
     
     switch (current_state)
     {
         case in_attente:
-        {    
-            //led4 = 0;
-            led3 = 0;
-            led2 = 0;
-            led1 = 0;        
-            //frame_in_end_led = 0;
+        {     
+            frame_in_end_led1 = 0;
             if (input == 1)
             {
-                led1 = 1;
                 timer.start();
                 current_state = in_preambule;   
                 current_byte_progress = 1;
-                //frame_in_end_led = 1;
+                frame_in_end_led1 = 1;
             }
             break;
         }
         case in_preambule:
         {
-            led2 = 1;
             current_byte_progress++;
             t = timer.read_ms();           
             timer.reset();
@@ -130,11 +119,9 @@
         }
         case in_data:
         {        
-            led3 = 1;   
             if(timer.read_ms() > t + t_half)
             {
-                led4 = 1;
-                //frame_in_end_led = 0;
+                frame_in_end_led1 = 0;
                 current_state = in_attente;
                 current_byte_progress = 0;
                 
@@ -147,7 +134,6 @@
                 current_byte_progress++ ;
                 //PC.putc(input);
                 // Display data 
-                //frame_in_end_led = !input;
                 ticker_watch.start(t + t_half);
                 timer.reset();      
                 
@@ -167,8 +153,7 @@
         }
         case in_idle:
         {
-            led4 = 1;
-            //frame_in_end_led = 0;
+            frame_in_end_led1 = 0;
             current_state = in_attente;
             current_byte_progress = 0;
             break;
@@ -203,8 +188,8 @@
     out_message_in = 0;
     out_message_out = 0;
         
-    //out_debug_led = 0;    
-    //frame_end_led = 1;
+    out_debug_led3 = 0;    
+    frame_out_end_led2 = 0;
     
     //////////////////////////////////////////////////////
     // Creation d'un message et insertion dans le buffer
@@ -228,18 +213,18 @@
     //////////////////////////////////////////////////////   
     output = 0;
     wait(1);
-    out_timer.start(MANCHESTER_SPEED_OUT);       
+    out_timer.start(start_speed);       
 }
 
 typedef enum {
-    preambule = 0,
-    start,
-    options,
-    length,
-    data,
-    crc,
-    end,
-    idle
+    out_preambule = 0,
+    out_start,
+    out_options,
+    out_length,
+    out_data,
+    out_crc,
+    out_end,
+    out_idle
 } out_state_t;
 
 void radio_out(void const *args)
@@ -265,38 +250,39 @@
                                     current_byte_progress = 0;  \
                              }
     
-    //out_debug_led = !out_debug_led;
+    out_debug_led3 = !out_debug_led3;
     
     if (!IsBitTransition)
     {
         // Dependant du state, on progresse dans l'envoi du message
         switch (out_current_state) 
         {
-            case preambule: // preambule
+            case out_preambule: // preambule
             {
+                frame_out_end_led2 = 1;
                 SET_VAL_SHIFT(message->preambule, current_byte_progress++);
                 CHECK_NEXT_STATE
                 break;
             }        
-            case start: // start
+            case out_start: // start
             {
                 SET_VAL_SHIFT(message->start, current_byte_progress++);
                 CHECK_NEXT_STATE
                 break;
             }   
-            case options: // entete options
+            case out_options: // entete options
             {
                 SET_VAL_SHIFT(message->options, current_byte_progress++);
                 CHECK_NEXT_STATE
                 break;
             }             
-            case length: // entete lenght
+            case out_length: // entete lenght
             {
                 SET_VAL_SHIFT(message->length, current_byte_progress++);
                 CHECK_NEXT_STATE
                 break;
             }        
-            case data: // charge utile
+            case out_data: // charge utile
             {
                 SET_VAL_SHIFT(message->data[current_byte], current_byte_progress++)
                 if (current_byte_progress > 7)
@@ -312,19 +298,19 @@
                 //CHECK_NEXT_STATE
                 break;
             }        
-            case crc: // controle
+            case out_crc: // controle
             {
                 SET_VAL_SHIFT(message->control, current_byte_progress++);
                 CHECK_NEXT_STATE
                 break;
             }        
-            case end: // end
+            case out_end: // end
             {
                 SET_VAL_SHIFT(message->end, current_byte_progress++);
                 CHECK_NEXT_STATE
                 break; 
             }
-            case idle:
+            case out_idle:
             {
                 //current_state = 0;
                 current_byte = 0;
@@ -333,18 +319,24 @@
             }                                         
         }
         
-        if (next_value != output && out_current_state != idle)
+        // Changement d'etat pour permettre de faire la bonne transition de valeur
+        if (next_value != output && out_current_state != out_idle)
         {
             output = !output;
         }
         
-        if (out_current_state > end)
+        // Si on est a la fin du packet, on retourne au debut et on reenvoye les donnees
+        if (out_current_state > out_end)
         {
-            //frame_end_led = 0;
-            //out_current_state = preambule;
+            frame_out_end_led2 = 0;
+            out_current_state = out_preambule;
+            out_timer.stop(); 
+            start_speed += 1;    
+            out_timer.start(start_speed);   
         }
     }
-    else if (out_current_state != idle)
+    // Si on est pas dans une transitipon 
+    else if (out_current_state != out_idle)
     {
         output = !output;
     }