.

Dependencies:   L432KC_SPI_Pey_Lal

Revision:
115:156b8234f2de
Parent:
114:c1f7be27aa5d
Child:
116:6dfcafa00e42
diff -r c1f7be27aa5d -r 156b8234f2de main.cpp
--- a/main.cpp	Wed May 18 16:12:59 2022 +0000
+++ b/main.cpp	Wed May 18 18:07:09 2022 +0000
@@ -33,6 +33,8 @@
 uint32_t pulsewidth_direction = 1100;
 uint32_t pulsewidth_propulsion = 1500;
 
+char protocolReceivedPayload[PAYLOAD_MAX_SIZE];
+
 int main()
 {    
     //Test Serial port
@@ -65,9 +67,33 @@
         //If decoding has ended, get and changes PWM values.
         if(isDataAvailable())
         {
-            getVerifiedPWMValues(&pulsewidth_propulsion, &pulsewidth_direction);
-            propulsion.pulsewidth_us(pulsewidth_propulsion);
-            direction.pulsewidth_us(pulsewidth_direction);
+            char receivedCommand = getVerifiedPayload(protocolReceivedPayload);
+            switch(receivedCommand)
+            {
+                case COMMAND_PWM:
+                    pulsewidth_propulsion = protocolReceivedPayload[0] << 8;
+                    pulsewidth_propulsion += protocolReceivedPayload[1];
+                    pulsewidth_direction = protocolReceivedPayload[2] << 8;
+                    pulsewidth_direction += protocolReceivedPayload[3];
+                    propulsion.pulsewidth_us(pulsewidth_propulsion);
+                    direction.pulsewidth_us(pulsewidth_direction);
+                    break;
+                    
+                case COMMAND_ASSERVISSEMENT: 
+                    commandSpeed = convertBytesToFloat(protocolReceivedPayload, 0);
+                    pulsewidth_direction = protocolReceivedPayload[4] << 8;
+                    pulsewidth_direction += protocolReceivedPayload[5];
+                    direction.pulsewidth_us(pulsewidth_direction);
+                    break;
+                    
+                case COMMAND_PARAMETRES:
+                {                       
+                    float kp = convertBytesToFloat(protocolReceivedPayload, 0);
+                    float ki = convertBytesToFloat(protocolReceivedPayload, 4);                                                
+                    setPIDParameters(kp, ki);
+                    break;   
+                }
+            }
         }        
         
         //If no speed captor interrupt, consider speed = 0
@@ -116,5 +142,4 @@
     propulsion.pulsewidth_us(pulsewidth_propulsion);
     
     //Open loop (for coef)
-    
 }
\ No newline at end of file