v1.0

Dependencies:   CAN_CONSOLE_v3 mbed

Fork of CAN_CONSOLE_v3 by RaC2018

Files at this revision

API Documentation at this revision

Comitter:
protongamer
Date:
Tue Mar 27 09:54:04 2018 +0000
Parent:
2:1e06fd49ea7b
Commit message:
1 moteur un bp; probl?me sur la requete pour la demande de postiion

Changed in this revision

CAN_CONSOLE_v2.lib Show annotated file Show diff for this revision Revisions of this file
can_parameters.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CAN_CONSOLE_v2.lib	Tue Mar 27 09:54:04 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/RaC2018/code/CAN_CONSOLE_v3/#1e06fd49ea7b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/can_parameters.h	Tue Mar 27 09:54:04 2018 +0000
@@ -0,0 +1,88 @@
+/*
+Here is the list of the CAN Codes to sent to the motor driver
+There identifiers and word code
+These parameters can be changed
+
+Here is the default values
+
+
+//Identifier Codes
+
+#define INITOP    0x00 
+#define RPDO1_R   0x215
+#define RPDO2_R   0x315
+#define RPDO3_R   0x415
+#define RPDO4_R   0x515
+#define TPDO1_R   0x195
+#define TPDO2_R   0x295
+#define TPDO3_R   0x395
+#define TPDO4_R   0x495
+#define RPDO1_L   0x220
+#define RPDO2_L   0x320
+#define RPDO3_L   0x420
+#define RPDO4_L   0x520
+#define TPDO1_L   0x1A0
+#define TPDO2_L   0x2A0
+#define TPDO3_L   0x3A0
+#define TPDO4_L   0x4A0
+
+
+
+//Word codes
+
+//Driver adresses
+#define DRIVER11 0x01
+#define DRIVER12 0x15
+#define DRIVER21 0x01
+#define DRIVER22 0x20
+
+
+
+*/
+
+
+
+
+
+//Identifier Codes
+
+/*
+To set right value for:
+RPDO1 => 0x200 + ID
+RPDO2 => 0x300 + ID
+RPDO3 => 0x400 + ID
+RPDO4 => 0x500 + ID
+TPDO1 => 0x180 + ID
+TPDO2 => 0x280 + ID
+TPDO3 => 0x380 + ID
+TPDO4 => 0x480 + ID
+*/
+
+
+#define INITOP    0x00 
+#define RPDO1_R   0x215
+#define RPDO2_R   0x315
+#define RPDO3_R   0x415
+#define RPDO4_R   0x515
+#define TPDO1_R   0x195
+#define TPDO2_R   0x295
+#define TPDO3_R   0x395
+#define TPDO4_R   0x495
+#define RPDO1_L   0x220
+#define RPDO2_L   0x320
+#define RPDO3_L   0x420
+#define RPDO4_L   0x520
+#define TPDO1_L   0x1A0
+#define TPDO2_L   0x2A0
+#define TPDO3_L   0x3A0
+#define TPDO4_L   0x4A0
+
+
+
+//Word codes
+
+//Driver adresses
+#define DRIVER_R1 0x01
+#define DRIVER_R2 0x15
+#define DRIVER_L1 0x01
+#define DRIVER_L2 0x20
--- a/main.cpp	Fri Mar 02 10:05:55 2018 +0000
+++ b/main.cpp	Tue Mar 27 09:54:04 2018 +0000
@@ -1,23 +1,27 @@
 #include "mbed.h"
- // LR 10/02/18
- //
- // bus CAN generateur de trames
- //
- // Emission d'une trame parmi 4 selection à l'aide du pot1
- // eviter les positions intermédaires du pot1 !
- //  !! emission sur CAN2 p30Rx p29Tx
- // Attention si pas d'ACK faire reset après chaque changement
- // J'ai constaté des comportements bizarre dans cette situation
- // Des infos sur la liaison série
- // La trame est envoyée aussi sur LCD
- // 
- // testé à l'analyseur logique = OK !!
- //
- //
+#include "can_parameters.h"
+ /* 
+  Projet BTS SN - Robot à câbles - Lycée Georges Cabanis
+  Enzo Niro - Erwin Sazio
+  Transmission par Bus CAN(protocol CANOpen)
+  
+ */
  
  
-DigitalOut led1(LED1);
-DigitalOut led2(LED2);
+
+
+
+
+DigitalOut MOTOR1_OP(LED1);
+DigitalOut MOTOR2_OP(LED2);
+DigitalOut DEB_MOD_DEG(LED3);
+DigitalOut DEB_MOD_NOR(LED4);
+DigitalOut MOD_DEG(p26);
+DigitalOut MOD_NOR(p25);
+DigitalIn SWH(p5);
+DigitalIn SWV(p6);
+DigitalIn BPO(p7);
+
 CAN can1(p9, p10,1000000);// on definit pin et debit
 CAN can2(p30, p29, 1000000);
 Serial pc(USBTX, USBRX);
@@ -31,1191 +35,119 @@
     
     if (RouD == 'D')
     { emis_ok = can2.write(CANMessage(id, octet_emis, longueur, CANData, CANStandard )) ;
-      pc.printf("id: %x, %c L = %d,  \nData : %x:%x:%x:%x ...   \n", id,RouD,longueur,octet_emis[0],octet_emis[1], octet_emis[2], octet_emis[3] );
+      //pc.printf("id: %x, %c L = %d,  \nData : %x:%x:%x:%x ...   \n", id,RouD,longueur,octet_emis[0],octet_emis[1], octet_emis[2], octet_emis[3] );
     }// c'ets la valeur retournée par la fonction write
    else
     { emis_ok = can2.write(CANMessage(id, octet_emis, longueur,  CANRemote, CANStandard ));
-        pc.printf("id: %x, %c L = %d,  \nData : %x:%x:%x:%x ...   \n", id,RouD,longueur,octet_emis[0],octet_emis[1], octet_emis[2], octet_emis[3] );
+        //pc.printf("id: %x, %c L = %d,  \nData : %x:%x:%x:%x ...   \n", id,RouD,longueur,octet_emis[0],octet_emis[1], octet_emis[2], octet_emis[3] );
          }
     //lcd.locate(0,10);
     //lcd.printf("id: %x, %c L = %d,  \nData : %x:%x:%x:%x ...   \n", id,RouD,longueur,octet_emis[0],octet_emis[1], octet_emis[2], octet_emis[3] );
-    if(emis_ok) {
+    /*if(emis_ok) {
         // ici octet emis n'a pas de sens car trame remote !
-     pc.printf("j'emets bien !!! \n");
-    } 
-    led1 = !led1;
+     //pc.printf("send \r \n");
+    } */
 }
 
 
 
  
 int main() {
- //   int choix = 0 ;
-    int i = 0 ;
-    
-char octet_send[9]  = "DDDDDDDD"; // valeurs par defaut D=44
-int identif = 0x123 ; // par défaut
-char RemoteData = 'D' ;  
-char length = 2 ;
-char c;
-uint32_t instruction = 0;
-uint8_t state_val = 0;
-uint8_t state = 0;
-int data_rc;
-int data_report[100];
-bool dejafait = 0;
-CANMessage msg;
 
-    pc.printf("CAN CONSOLE \r \n");
-   
-   
-   
-    while(1) {
-        data_rc = 0;
-   pc.printf(" Identifier : ");
-        while(state == 0){
-   c = pc.getc();
-   switch(c){
-           
-           
-                
-           case '0':
-           pc.printf("0");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b0000;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b0000;
-               state_val++;
-               }
-            
-           break;
-           
-           case '1':
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b0001;
-                }
-                
-           pc.printf("1");
-           if(state_val == 0){
-               instruction = 0b0001;
-               state_val++;
-               }
-            
-           break;
-           
-           case '2':
-           
-            if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b0010;
-                }
-                
-           pc.printf("2");
-           if(state_val == 0){
-               instruction = 0b0010;
-               state_val++;
-               }
-           
-           break;
-           
-           case '3':
-           pc.printf("3");
-          
-          if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b0011;
-                }
-          
-           if(state_val == 0){
-               instruction = 0b0011;
-               state_val++;
-               }
-            
-           break;
-           
-           case '4':
-           
-            if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b0100;
-                }           
-           
-           pc.printf("4");
-           if(state_val == 0){
-               instruction = 0b0100;
-               state_val++;
-               }
-
-           break;
-           
-           case '5':
-           pc.printf("5");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b0101;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b0101;
-               state_val++;
-               }
-            
-           break;
-           
-           case '6':
-           pc.printf("6");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b0110;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b0110;
-               state_val++;
-               }
-            
-           break;
-           
-           case '7':
-           pc.printf("7");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b0111;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b0111;
-               state_val++;
-               }
-            
-           break;
-           
-           case '8':
-           pc.printf("8");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1000;
-                }
-           
-           
-           if(state_val == 0){
-               instruction = 0b1000;
-               state_val++;
-               }
-            
-           break;
-           
-           case '9':
-           pc.printf("9");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1001;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1001;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'a':
-           pc.printf("a");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1010;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1010;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'b':
-           pc.printf("b");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1011;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1011;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'c':
-           pc.printf("c");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1100;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1100;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'd':
-           pc.printf("d");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1101;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1101;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'e':
-           pc.printf("e");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1110;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1110;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'f':
-           pc.printf("f");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1111;
+    CANMessage msg;
+    uint8_t ping = 0;
+    char command[8]; //word to send command
+        //define Pullup switch
+        SWH.mode(PullUp);
+        SWV.mode(PullUp);
+        BPO.mode(PullUp);
+        pc.printf("starting...\r\n");
+            MOD_DEG = 1;
+            wait(0.1);
+            MOD_DEG = 0;
+            wait(0.1);
+            MOD_DEG = 1;
+            wait(0.1);
+            MOD_DEG = 0;
+            wait(0.1);
+            MOD_DEG = 1;
+            wait(0.1);
+            MOD_DEG = 0;
+            wait(0.1);
+        
+        command[0] = DRIVER_R1;
+        command[1] = DRIVER_R2;
+        
+        while(ping == 0){
+            pc.printf("ping...\r\n");
+            send(INITOP, command, 'D', 2); //send word to put pluto driver in operational mode
+            MOD_NOR = 1;
+            if(can2.read(msg)) {
+                pc.printf("Done\r\n");
+                ping = 1;
                 }
-           
-           if(state_val == 0){
-               instruction = 0b1111;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'A':
-           pc.printf("a");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1010;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1010;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'B':
-           pc.printf("b");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1011;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1011;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'C':
-           pc.printf("c");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1100;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1100;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'D':
-           pc.printf("d");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1101;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1101;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'E':
-           pc.printf("e");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1110;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1110;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'F':
-           pc.printf("f");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1111;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1111;
-               state_val++;
-               }
-            
-           break;
-           
-           case '\r':
-           pc.printf("\r\nOk\r\n");
-           identif = instruction;
-           state++;
-            
-           break;
-           
-           }
-           }
-           
-   pc.printf("\r\n Number of octets : ");
-   
-   c = pc.getc();
-   instruction = 0;
-   state_val = 0;
-   
-    switch(c){
-         case '0':
-           pc.printf("0");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b0000;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b0000;
-               state_val++;
-               }
-            
-           break;
-           
-           case '1':
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b0001;
-                }
-                
-           pc.printf("1");
-           if(state_val == 0){
-               instruction = 0b0001;
-               state_val++;
-               }
-            
-           break;
-           
-           case '2':
-           
-            if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b0010;
-                }
-                
-           pc.printf("2");
-           if(state_val == 0){
-               instruction = 0b0010;
-               state_val++;
-               }
-           
-           break;
-           
-           case '3':
-           pc.printf("3");
-          
-          if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b0011;
-                }
-          
-           if(state_val == 0){
-               instruction = 0b0011;
-               state_val++;
-               }
-            
-           break;
-           
-           case '4':
-           
-            if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b0100;
-                }           
-           
-           pc.printf("4");
-           if(state_val == 0){
-               instruction = 0b0100;
-               state_val++;
-               }
-
-           break;
-           
-           case '5':
-           pc.printf("5");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b0101;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b0101;
-               state_val++;
-               }
-            
-           break;
-           
-           case '6':
-           pc.printf("6");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b0110;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b0110;
-               state_val++;
-               }
-            
-           break;
-           
-           case '7':
-           pc.printf("7");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b0111;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b0111;
-               state_val++;
-               }
-            
-           break;
-           
-           case '8':
-           pc.printf("8");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1000;
-                }
-           
-           
-           if(state_val == 0){
-               instruction = 0b1000;
-               state_val++;
-               }
-            
-           break;
-           
-           case '9':
-           pc.printf("9");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1001;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1001;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'a':
-           pc.printf("a");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1010;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1010;
-               state_val++;
-               }
+            wait(0.1);
+            MOD_NOR = 0;
+            wait(0.9);
             
-           break;
-           
-           case 'b':
-           pc.printf("b");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1011;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1011;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'c':
-           pc.printf("c");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1100;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1100;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'd':
-           pc.printf("d");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1101;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1101;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'e':
-           pc.printf("e");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1110;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1110;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'f':
-           pc.printf("f");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1111;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1111;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'A':
-           pc.printf("a");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1010;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1010;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'B':
-           pc.printf("b");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1011;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1011;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'C':
-           pc.printf("c");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1100;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1100;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'D':
-           pc.printf("d");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1101;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1101;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'E':
-           pc.printf("e");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1110;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1110;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'F':
-           pc.printf("f");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1111;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1111;
-               state_val++;
-               }
-            
-           break;
-           
-           }
-    
-    length = instruction;
-    pc.printf("\r\n");
-    if(length > 0){
-    pc.printf("Send octets in hexa\r\n");
-    i = 0;
-    pc.printf("\r\n Octet[%d] : ", i);
-    while(i <= length - 1){
-    
+            }
         
-        c = pc.getc();
-        switch(c){
-         case '0':
-           pc.printf("0");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b0000;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b0000;
-               state_val++;
-               }
-            
-           break;
-           
-           case '1':
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b0001;
-                }
-                
-           pc.printf("1");
-           if(state_val == 0){
-               instruction = 0b0001;
-               state_val++;
-               }
-            
-           break;
-           
-           case '2':
-           
-            if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b0010;
-                }
-                
-           pc.printf("2");
-           if(state_val == 0){
-               instruction = 0b0010;
-               state_val++;
-               }
-           
-           break;
-           
-           case '3':
-           pc.printf("3");
-          
-          if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b0011;
-                }
-          
-           if(state_val == 0){
-               instruction = 0b0011;
-               state_val++;
-               }
-            
-           break;
-           
-           case '4':
-           
-            if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b0100;
-                }           
-           
-           pc.printf("4");
-           if(state_val == 0){
-               instruction = 0b0100;
-               state_val++;
-               }
-
-           break;
-           
-           case '5':
-           pc.printf("5");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b0101;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b0101;
-               state_val++;
-               }
-            
-           break;
-           
-           case '6':
-           pc.printf("6");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b0110;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b0110;
-               state_val++;
-               }
-            
-           break;
-           
-           case '7':
-           pc.printf("7");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b0111;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b0111;
-               state_val++;
-               }
-            
-           break;
-           
-           case '8':
-           pc.printf("8");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1000;
-                }
-           
-           
-           if(state_val == 0){
-               instruction = 0b1000;
-               state_val++;
-               }
-            
-           break;
-           
-           case '9':
-           pc.printf("9");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1001;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1001;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'a':
-           pc.printf("a");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1010;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1010;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'b':
-           pc.printf("b");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1011;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1011;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'c':
-           pc.printf("c");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1100;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1100;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'd':
-           pc.printf("d");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1101;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1101;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'e':
-           pc.printf("e");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1110;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1110;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'f':
-           pc.printf("f");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1111;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1111;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'A':
-           pc.printf("a");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1010;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1010;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'B':
-           pc.printf("b");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1011;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1011;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'C':
-           pc.printf("c");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1100;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1100;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'D':
-           pc.printf("d");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1101;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1101;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'E':
-           pc.printf("e");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1110;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1110;
-               state_val++;
-               }
-            
-           break;
-           
-           case 'F':
-           pc.printf("f");
-           
-           if(state_val > 0){
-                instruction = instruction << 4;
-                instruction |= 0b1111;
-                }
-           
-           if(state_val == 0){
-               instruction = 0b1111;
-               state_val++;
-               }
-            
-           break;
-           
-           case '\r':
-           octet_send[i] = instruction;
-           instruction = 0;
-           state_val = 0;       
-           i++;    
-           if(i <= length - 1){
-           pc.printf("\r\n Octet[%d] : ", i);}
-           break;
-           
-           }
-           
-              
-        }//end of while
-        }
-        pc.printf("Set RTR (1 or 0): ");
-        c = pc.getc();
-        if(c == '0'){
-            RemoteData = 'D';
-            }
-            if(c == '1'){
-            RemoteData = 'R';
-            }
-            pc.printf("%c \r\n",c);
-            wait(2);
-    
-    
-    for(i = 0; i < 25; i++){
-        if(dejafait == 0){
-        send(identif, octet_send, RemoteData, length );
-    data_rc = 0;
-    dejafait = 1;
-    }
-    
-        pc.printf("Awaiting Data... \r\n");
-        if(can2.read(msg)) {
-            pc.printf("Message received\r\n");
-            pc.printf("Number of octet: %d \r\n", msg.len);
-            
-        } 
-        }//end of for
         
         
-        for(i = 0; i < msg.len; i++){
-        pc.printf("Data captured %d : 0x%x \r\n", i, msg.data[i]);
+    while(1){
+        if(SWH == 0){
+            wait(1.0);
+            send(0x0195, command, 'R', 0); //send word to put pluto driver in operational mode
+            wait(1);
+            if(can2.read(msg)) {
+            for(int i = 0; i < msg.len; i++){
+            pc.printf("0x%x ",msg.data[i]);
+            }//end of for
+            pc.printf("\r \n");
+            }//can.read(len)
+            }//end of SWH == 0
+            
+        switch(BPO){
+            case 0:
+
+            switch(SWV){
+                case 0:
+                command[0] = 0x00;
+                command[1] = 0x00;
+                command[2] = 0xBF;
+                command[3] = 0x00;
+                send(RPDO1_R, command, 'D', 4); //send word to put pluto driver in operational mode
+                break;
+                
+                case 1:
+                command[0] = 0xFF;
+                command[1] = 0xFF;
+                command[2] = 0x40;
+                command[3] = 0xFF;
+                send(RPDO1_R, command, 'D', 4); //send word to put pluto driver in operational mode
+
+                break;
+                
+            
+
+                }
+            
+            break;
+            
+            case 1:
+ 
+                command[0] = 0x00;
+                command[1] = 0x00;
+                command[2] = 0x00;
+                command[3] = 0x00;
+                send(RPDO1_R, command, 'D', 4); //send word to put pluto driver in operational mode
+            break;
+                 
+                }
         
-        }
-        data_rc = 0;
-        dejafait = 0;
-        i = 0;
-        state = 0;
-        pc.printf("\r\n");
-        //end of for 
             
     }// fin while(1)
          
 } // fin main
          
-        /*
-        
-        printf("loop()\n");
-        if(can2.read(msg)) {
-            printf("Message received: %d\n", msg.data[0]);
-            led2 = !led2;
-        } 
-        wait(0.2);
-    }
-} */
-
-//choix= 5*pot_1.read();
-   // lcd.locate(0,0);
-   // lcd. printf("Trame %d \n", choix);
-   /* switch (choix)
-    { // debut sw
-    case (0): // Trame qui passe le noeud 15 en Operationnal state
-    {   identif =  0x00 ;
-        octet_send[0] = 0x01 ;
-        octet_send[1] = 0x15 ;
-        RemoteData = 'D';
-        length = 2 ;
-        break ;
-    }     // fin case 0
-     case (1): // Trame qui passe le noeud 20 en Operationnal state
-    {   identif =  0x00 ;
-         octet_send[0] = 0x01 ;
-        octet_send[1] = 0x20 ;
-        RemoteData = 'D';
-       length = 2 ;
-        break ;
-    }     // fin case 1
-     case (2): // trame qui ping le noeud 15
-    {   identif =  0x715 ;
-        for(i=0;i<9;i++)
-        { octet_send[i]='D';} // 44 en hexa par defaut
-        RemoteData = 'R';
-        length = 0 ;
-        break ;
-    }     // fin case 2
-    case (3): // trame qui ping le noeud 20
-    {   identif =  0x720 ;
-         for(i=0;i<9;i++)
-        { octet_send[i]='D';} // 44 en hexa par defaut
-        RemoteData = 'R';
-        length = 0 ;
-        break ;
-    }     // fin case 3
-    
-   default : // 4 ou 5
-    {   identif =  0x123 ;
-         for(i=0;i<9;i++)
-        { octet_send[i]='D';} // 44 en hexa par defaut
-        RemoteData = 'D';
-        length = 8 ;
-        break ;
-    }     // fin default
-    
-    } // fin switch
-    */
\ No newline at end of file
+        
\ No newline at end of file