Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Revision 1:13af94a28e0d, committed 2020-02-06
- Comitter:
- EISR
- Date:
- Thu Feb 06 08:22:13 2020 +0000
- Parent:
- 0:9e8a54e32f30
- Commit message:
- V2 fonctionnelle commentee
Changed in this revision
bluetoothV2bibli.cpp | 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 |
--- a/bluetoothV2bibli.cpp Thu Feb 06 07:46:51 2020 +0000 +++ b/bluetoothV2bibli.cpp Thu Feb 06 08:22:13 2020 +0000 @@ -6,9 +6,9 @@ Serial blueth(p9, p10,115200); // tx,rx,baudrate -static int blueRxBuffer[6]; // Buffer de réception de la liaison série bluetooth -static int blueTxBuffer[6]={240,0,0,0,0,15}; // Buffer de transmission de la liaison série bluetooth -static int RxBuffer[4][6]; +static int blueRxBuffer[6]; // Buffer de réception de la liaison serie bluetooth +static int blueTxBuffer[6]={240,0,0,0,0,15}; // Buffer de transmission de la liaison serie bluetooth +static int RxBuffer[4][6]; // Copie de blueRxbuffer à l'issue de la reception des 4 trames static int paramRx[4][2]; //0 KP 1 KI 2 KD 3 SPEED static short flagR=0; @@ -27,26 +27,26 @@ void transmitBlu(void) { static short i = 0; - if(blueth.writable()) //fonctionne si la liaison est libre + if(blueth.writable()) //fonctionne si la liaison est libre { - blueth.putc(blueTxBuffer[i]); //transmission de la trame de 6 octets + blueth.putc(blueTxBuffer[i]); //transmission de la trame de 6 octets dans le buffer i++; } if(i>5) { i=0; - blueth.attach(NULL, Serial::TxIrq); + blueth.attach(NULL, Serial::TxIrq); // on coupe la liaison (ISR de transmssion) tant que pas necessaire pour permettre la reception } } -void formatTrameT(short reg, int val) +void formatTrameT(short reg, int val) // Creation de la trame au format Start Registre Donnees Donnees Donnees Stop { blueTxBuffer[1]=reg; - blueTxBuffer[2]=((val&0xFF0000)>>16); //Conversion sur trois octets independants + blueTxBuffer[2]=((val&0xFF0000)>>16); //Conversion sur trois octets independants de la donnee blueTxBuffer[3]=((val&0x00FF00)>>8); blueTxBuffer[4]=((val&0x0000FF)); - blueth.attach(&transmitBlu, Serial::TxIrq); + blueth.attach(&transmitBlu, Serial::TxIrq); //Ouverture de la liaison (ISR de transmission) } @@ -56,48 +56,48 @@ { static short j = 0, compteur=0; - if(blueth.readable()) + if(blueth.readable()) //Si la liaison est libre { blueRxBuffer[j]=blueth.getc(); //reception - blueth.putc(blueRxBuffer[j]); //renvoie de la reception pour tester - j++; + j++; //Permet d'ecrire les 6 octets dans blueRxBuffer if(j>5) { j=0; - for(short i=0;i<6;i++)RxBuffer[compteur][i]=blueRxBuffer[i]; + for(short i=0;i<6;i++)RxBuffer[compteur][i]=blueRxBuffer[i]; //Si une trame est reçue, on la copie dans RxBuffer compteur++; - if(compteur>4) + if(compteur>4) //Permet de savoir si les 4 donnees KP KI KD et SPEED ont été transmises { compteur=0; - flagR=1; + flagR=1; //Permet la gestion de decomposition de trames } } } } -int get_val_pc(short reg) +int get_val_pc(short reg) //Permet de connaitre la donnee associée à un registre { short indice; - if(flagR==1) + if(flagR==1) // Decompose les trames si reception de 4 nouvelles trames { - decomp_trame(); + decomp_trame(); flagR=0; } - if(reg == 30)indice = 0; + if(reg == 30)indice = 0; if(reg == 45)indice = 1; if(reg == 60)indice = 2; if(reg == 75)indice = 3; - return paramRx[indice][1]; + return paramRx[indice][1]; //renvoie la valeur stocke pour un registre } void decomp_trame(void) { for(short i=0;i<4;i++) { - if(RxBuffer[i][0]== 240 && RxBuffer[i][5]==15) + if(RxBuffer[i][0]== 240 && RxBuffer[i][5]==15) //verification des bits start et stop { - paramRx[i][0]= RxBuffer[i][1]; + paramRx[i][0]= RxBuffer[i][1]; //ecriture du registre paramRx[i][1] = RxBuffer[i][2]*pow((double)2,(double)16)+RxBuffer[i][3]*pow((double)2,(double)8)+RxBuffer[i][4]; + //recomposition de la donnee stockee sur 3 octets } } } \ No newline at end of file
--- a/main.cpp Thu Feb 06 07:46:51 2020 +0000 +++ b/main.cpp Thu Feb 06 08:22:13 2020 +0000 @@ -2,28 +2,26 @@ #include "math.h" #include "bluetoothV2bibli.h" -DigitalOut myled(LED1); -DigitalOut myled4(LED4); +DigitalOut myled(LED1); //led de test void data_on_blueth(void); //fonction d'interruption int main(void) { - //Ticker timer; + Ticker timer; //ticker pour gérer la frequence d'appelle d'une fonction - init_blueth(); - myled=1; - myled4=1; - //timer.attach(&data_on_blueth,0.005); // creation de l'interruption + init_blueth(); //initialisation avec ISR de reception et premier message + myled=1; + timer.attach(&data_on_blueth,0.005); // permet d'appeler formatTrameT qui gère l'ISR de transmission while(1) { - if(get_val_pc(30) == 1024)myled=!myled; + if(get_val_pc(30) == 1024)myled=!myled; //Test en reception } } -void data_on_blueth(void) +void data_on_blueth(void) //fonction de test pour appeler formatTrameT { static short i = 0; short reg[4]={30,45,60,75}; - formatTrameT(reg[i], 500000 ); //A chaque IT - i++; - if(i>3)i=0; + formatTrameT(reg[i], 500000 ); // envoie du registre et de la valeur sur ce registre + i++; // permet lecture du tableau pour le test + if(i>3)i=0; } \ No newline at end of file