ok

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
stersky
Date:
Tue Feb 12 14:46:02 2019 +0000
Commit message:
ok

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Feb 12 14:46:02 2019 +0000
@@ -0,0 +1,63 @@
+#include "mbed.h"
+
+Serial centrale(p9,p10);
+Serial PC(USBTX,USBRX);
+
+void lecture_centrale(int *ptr1, int *ptr2);
+
+int main() {
+    int vitesse,gouvernail;
+    centrale.baud(9600);
+    PC.baud(460800);
+    
+    while(1) {
+        lecture_centrale(&vitesse,&gouvernail);
+        PC.printf("Vmoteur : %d\n\rDirMoteur : %d\n\r",vitesse,gouvernail);
+    }
+}
+
+void lecture_centrale(int* ptr1, int* ptr2)
+{
+    char fin=0;
+    char etat = 0;
+    char a,i=0;
+    char buffer[30];
+    
+    while(fin==0)
+    {
+if (centrale.readable()) 
+        {  // attention PC.readable reste à 1 tant qu'il n'y a pas eu de getc qui vide le buffer
+            a=centrale.getc();
+            
+        switch(etat)
+        {
+            case 0 :
+            if(a=='$')//On attend le début d'une trame
+            {
+                buffer[0] = '$';
+                i=1;
+                etat = 1;
+            }
+            break;
+            
+            case 1 ://Après le début d'une trame, on récupère la trame en entier et on l'analyse
+            buffer[i] = a;
+            i++;
+            if(a=='*')
+            {
+                sscanf(buffer,"$%d|%d*",ptr1,ptr2);
+                fin = 1;
+                i=0;
+                etat=0;
+            }
+            break;
+            
+            default :
+            etat = 0;
+            break;
+            
+
+           }
+           }
+           }
+           }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Feb 12 14:46:02 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/3a7713b1edbc
\ No newline at end of file