html

Dependencies:   mbed bloc_io mbed-rtos html EthernetInterface

Files at this revision

API Documentation at this revision

Comitter:
viale
Date:
Fri Dec 13 13:50:12 2019 +0000
Parent:
2:172619ae2eb7
Commit message:
aaaaaaa

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 172619ae2eb7 -r 5945b9edc15a main.cpp
--- a/main.cpp	Fri Nov 22 13:23:17 2019 +0000
+++ b/main.cpp	Fri Dec 13 13:50:12 2019 +0000
@@ -9,19 +9,41 @@
 #define RADIUS  0.2F // wheel size
 #define NBPOLES 8 // magnetic pole number
 #define DELTA_T 0.1F // speed measurement counting period
-#define PI 3.14F // PIIIIIII
+#define PI 3.14F // PI
+#define SensibiliteTemp 0.01F // doc
+#define CoeffTensionbat 77.5F // determiner manuellemnt
+#define SensibiliteCourant 0.185F // doc ACS712
+#define batt 2 // 2 A pendant 1 minute Jauge d'energie capacité
+#define itest 0.0333  // A*minutes
+#define PDTI 1.85F // 33/(28+33)*3.3 = 1.85
+#define cstCAN 0.001
+
+
 DigitalOut PWM_VALID (p21);
-InterruptIn TopHall (p22);                        // valid pmw mbed pin
-AnalogIn POIGNEE (p17);                            // analog input connected to mbed
+InterruptIn TopHall (p22);// valid pmw mbed pin
+AnalogIn POIGNEE (p17); // broche poignee
+AnalogIn Temp(p19); // broche temperature
+AnalogIn Vbat(p18);// analog input connected to mbed
+AnalogIn Ibat(p20); // broche courant batterie
 Bloc_IO MyPLD(p25,p26,p5,p6,p7,p8,p9,p10,p23,p24);// instantiate object needed to communicate with PLD
-Serial pc(USBTX, USBRX);                         // tx, rx
+Serial pc(USBTX, USBRX);// tx, rx
+
 void PWM ();
 void Mesure();
 void CalculV ();
-void saveFile(); //  sauvegarde fichier
+void saveFile();//sauvegarde fichier
+void MesureTemp(void);
+void MesureVbat(void);
+void MesureIbat(void);
+void Mesurepoingnee(void); // pourcentage POIGNEE
+void MesuresWeb(void);
+void Receive ();
+
+int iCounter1Sec;
+Ticker T_Mesures;
 Ticker AUTO;
 Ticker CalculVitesse;
-float GazMax,GazMin;
+float GazMax, GazMin, caparestante;
 int pwmmanuel,x,Overcurrent,Brake,FLTA,Direction,HALLC,HALLB,HALLA;
 char cChoix;
 int pwm_final=0;
@@ -34,6 +56,21 @@
 float vitessemesure;
 float vitessebride = 25.0;
 int tophallpartiel;
+float temp,vbat, ibat, pourcentage;
+float batterieAc = 0.0;
+int a; // bus CAN
+float valpoignee; //bus CAN
+
+
+// UTILISATION DU BUS CAN ENVOIE
+Ticker ticker;
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3); // blink when can message is sent
+DigitalOut led4(LED4); // blink when can message is received
+
+char counter = 0;
+
 // Top_Hall Pin
 
 /************ persistent file parameters section *****************/
@@ -46,18 +83,20 @@
 int giCounter=0;// acces counting
 
 
+
 /*********************** can bus section  ************/
 // determine message ID used to send Gaz ref over can bus
 #define _CAN_DEBUG // used to debug can bus activity
-//#define USE_CAN_REF // uncomment to receive gaz ref over can_bus
+#define USE_CAN_REF // uncomment to receive gaz ref over can_bus
 CAN can_port (p30, p29); // initialisation du Bus CAN sur les broches 30 (rd) et 29(td) for lpc1768 + mbed shield
 bool bCan_Active=false;
 
 
-DigitalOut led1(LED1); //initialisation des Leds présentes sur le micro-controleur Mbed*/
-DigitalOut led2(LED2);
-DigitalOut led3(LED3); // blink when can message is sent
-DigitalOut led4(LED4); // blink when can message is received
+//DigitalOut led1(LED1); //initialisation des Leds présentes sur le micro-controleur Mbed*/
+//DigitalOut led2(LED2);
+//DigitalOut led3(LED3); // blink when can message is sent
+//DigitalOut led4(LED4); // blink when can message is received
+
 
 
 
@@ -68,11 +107,12 @@
 void saveFile()
 {
     FILE *fp = fopen("/local/gr1.txt", "w");
-    if(fp != NULL) fprintf(fp,"valeur max : %f, valeur min: %f, tophalltotal: %d, vitesse de la bride: %f, tophallpartiel:%d",GazMin,GazMax,tophalltotal,vitessebride,tophallpartiel);
+    if(fp != NULL) fprintf(fp,"valeur max : %f, valeur min: %f, tophalltotal: %d, vitesse de la bride: %f, tophallpartiel:%d, capacite restante: %f",GazMin,GazMax,tophalltotal,vitessebride,tophallpartiel,caparestante);
     else printf("ERREUR FICHIER NON VALIDE");
     fclose(fp);
 
 }
+
 //************** calibation gaz function needed to record min_gaz and max_gaz value to persistent text file  ******************
 
 
@@ -86,16 +126,41 @@
 
 
 /********* main cgi function used to patch data to the web server thread **********************************/
+
+
 void CGI_Function(void) // cgi function that patch web data to empty web page
 {
     char ma_chaine4[20]= {}; // needed to form html response
 
+    sprintf (ma_chaine4,"%f",vitessemesure);
+    printf("chaine4=%s\n",ma_chaine4);
+    Html_Patch (tab_balise,0,ma_chaine4);
+
+    sprintf (ma_chaine4,"%f",vitessemesure);
+    printf("chaine4=%s\n",ma_chaine4);
+    Html_Patch (tab_balise,1,ma_chaine4);
+
+    sprintf (ma_chaine4,"%d",(int)((valpwm*100 )/ 255));
+    printf("chaine4=%s\n",ma_chaine4);
+    Html_Patch (tab_balise,2,ma_chaine4);
+
+    sprintf (ma_chaine4,"%f",(temp-273.15));
+    printf("chaine4=%s\n",ma_chaine4);
+    Html_Patch (tab_balise,3,ma_chaine4);
+
+    sprintf (ma_chaine4,"%f",vbat);
+    printf("chaine4=%s\n",ma_chaine4);
+    Html_Patch (tab_balise,4,ma_chaine4);
+
+    sprintf (ma_chaine4,"%f",ibat);
+    printf("chaine4=%s\n",ma_chaine4);
+    Html_Patch (tab_balise,5,ma_chaine4);
+
 }
 
 
 /*********************** CAN BUS SECTION  **********************/
 
-
 void CAN_REC_THREAD(void const *args)
 {
     int iCount,iError;
@@ -105,44 +170,58 @@
         // code todo
 
     }
+}
 
+void Receive()
+{
+    CANMessage msg;
+    if(can_port.read(msg)) {
+    
+    valpoignee=*reinterpret_cast<int*>(msg.data)*cstCAN;
+    }
 }
 //*************************** main function *****************************************
 int main()
 {
+
+    caparestante = (batterieAc*100)/(batt);
     MyPLD.write(0);
     PWM_VALID.write(1);
     char carac;
     FILE *fp = fopen("/local/gr1.txt", "r");
     if(fp != NULL) {
-        fscanf(fp,"valeur max : %f, valeur min: %f, tophalltotal: %d, vitesse de la bride: %f, tophallpartiel:%d",&GazMin,&GazMax,&tophalltotal,&vitessebride,&tophallpartiel);
-        printf("Valeur min:%f , Valeur max:%f ,tophalltotal:%d,vitesse de la bride:%f,tophallpartiel:%d\n\r",GazMin,GazMax,tophalltotal,vitessebride,tophallpartiel);
+        fscanf(fp,"valeur max : %f, valeur min: %f, tophalltotal: %d, vitesse de la bride: %f, tophallpartiel:%d, capacite restante: %f",&GazMin,&GazMax,&tophalltotal,&vitessebride,&tophallpartiel,&caparestante);
+        printf("Valeur min:%f , Valeur max:%f ,tophalltotal:%d,vitesse de la bride:%f,tophallpartiel:%d, capacite restante: %f\n\r",GazMin,GazMax,tophalltotal,vitessebride,tophallpartiel,caparestante);
     } else
         printf("ERREUR FICHIER NON VALIDE\n\r");
     fclose(fp);
 
-    // int write,read;
-    // f_poignee = fopen("nom-de-fichier","r");
-    // read=fgetc(f_poignee);
-    //  fclose(f_poignee);
-    //  printf("&d",read);
+//***************************************** web section ********************************************/
+
+
 
-//***************************************** web section ********************************************/
-//Init_Web_Server(&CGI_Function); // create and initialize tcp server socket and pass function pointer to local CGI function
-//Thread WebThread(Web_Server_Thread);// create and launch web server thread
+    Init_Web_Server(&CGI_Function); // create and initialize tcp server socket and pass function pointer to local CGI function
+    Thread WebThread(Web_Server_Thread);// create and launch web server thread
+    Gen_HtmlCode_From_File("/local/tintin.htm",tab_balise,5);
     /********* main cgi function used to patch data to the web server thread **********************************/
 
 //******************************************* end web section  ************************************* /
 
 
+
+
+
+
 //********************* can bus section initialisation *******************************************
 //bCan_Active=true;// needed to lauchn CAN thread
 //Thread CanThread(CAN_REC_THREAD);// create and launch can receiver  thread
 //********************* end can bus section *****************************************************
+    can_port.attach(&Receive,CAN::RxIrq);
     TopHall.mode(PullUp);
     AUTO.attach(&PWM,0.02);
     TopHall.rise(&Mesure);
     CalculVitesse.attach(&CalculV,0.1);
+    T_Mesures.attach(&MesuresWeb,0.1);
     pc.printf("programme scooter mbed \n\r");
     while(cChoix!='q' and cChoix!='Q') {
         pc.printf("Veuillez saisir un choix parmi la liste proposee:\n\r");
@@ -155,7 +234,11 @@
         pc.printf("h: Lecture vitesse\n\r");
         pc.printf("i: Compteur kilometrique\n\r");
         pc.printf("j: RAZ compteur partiel\n\r");
+        pc.printf("k: Valeur de la temperature\n\r");
+        pc.printf("l: rechargement batterie\n\r");
+        pc.printf("z: BUS CAN \n\r");
         pc.printf("q:quitter\n\r");
+
         //************* multithreading : main thread need to sleep in order to allow web response */
         while (pc.readable()==0) { // determine if char availabler
             Thread::wait(10);   // wait 10 until char available on serial input
@@ -178,7 +261,7 @@
                 printf("\n\r");
                 printf("Veuillez entrer n'importe quel caractere si vous etes OK pour la valeur max\n\r");
                 scanf("%c",&carac);
-                GazMax=POIGNEE.read();
+                GazMax=valpoignee;
                 printf("\n\r");
                 printf("Valeur de la poignee min:%g\n\r",GazMin);
                 printf("Valeur de la poignee max:%g\n\r",GazMax);
@@ -234,17 +317,15 @@
             case 'f': // VITESSE DE LA ROUE DU SCOOT
                 printf("vitesse de la roue: %f\n\r",vitesse);
                 break;
-
             case 'g': // SAISIE DE LA BRIDE
                 printf("Veuillez saisir la valeur de la bride entre 0 et 30 km/h \n\r");
                 scanf("%f",&vitessebride);
                 saveFile();
-                printf("Valeur de la bride\n\r", vitessebride);
+                printf("Valeur de la bride \n\r",vitessebride);
                 break;
             case 'h': // VITESSE DE LA ROUE DU SCOOT
                 printf("Vitesse:%1.3f km/h \n\r",vitessemesure*3.6);
                 break;
-
             case 'i': // DISTANCE DE LA ROUE TOTAL ET PARTIEL
                 printf("Distance parcourue totale: %f metres\n\r",(tophalltotal*2*PI*RADIUS)/(6*NBPOLES));
                 printf("Distance parcourue partielle: %f metres\n\r",(tophallpartiel*2*PI*RADIUS)/(6*NBPOLES));
@@ -255,6 +336,18 @@
                 tophallpartiel=0;
                 saveFile();
                 break;
+            case 'k': //VALEUR DE LA TEMPERATURE , TENSION BATTERIE, COURANT , POURCENTAGE POINGNEE ,JAUGE D'ENERGIE
+
+                MesureTemp();
+                MesureVbat();
+                MesureIbat();
+                Mesurepoingnee();
+                printf("l'intensite de la batterie est de %1.3fA et jauge d'energie = %f pourcentage\n\r", ibat,(batterieAc*100)/(batt) );
+                break;
+            case 'l':
+                batterieAc = batt;
+                printf("batterie rechargee\n\r");
+                break;
             case 'q': // QUITTER LE PROGRAMME
                 AUTO.detach();
                 CalculVitesse.detach();
@@ -262,21 +355,44 @@
                 if (PWM_VALID.read()==0) MyPLD.write(0);
                 printf("BYE");
                 break;
+                
+            case 'z': //VALEUR CAN
+                printf("valeur recu CAN : %f\n\r", valpoignee);
+                break;
         }
         saveFile();
         pc.printf("fin programme scooter mbed\n\r");
     } // end while
 }
 //************** thread deinit *********************
+
 //DeInit_Web_Server();
 //bCan_Active=false;
 //CanThread=false;// close can received thread
 
-// end main
+
+
+
+// END MAIN
 void PWM()
 {
+    Receive();
     x=MyPLD.read();
     Brake= (x & 32)/32;
+
+
+    iCounter1Sec++;
+
+    if (iCounter1Sec == 50) { // compteur 1 seconde
+        iCounter1Sec= 0;
+        MesureIbat();
+        batterieAc = batterieAc-0.0333; // utiliser le courant
+
+        if (batterieAc < 0) {
+            batterieAc = 0 ;
+        }
+    }
+
     if (mode==1) { // MODE MANUEL
         MyPLD.write(0);
         if (pwmmanuel > 0 && pwmmanuel <=255) {
@@ -291,7 +407,7 @@
             pwm_final=0;
         } else if ( Brake == 1 ) { // frein désactif
 
-            valpwm =(255/(GazMax-GazMin))*POIGNEE.read()-(255/(GazMax-GazMin))*GazMin; // calcul de la PWM brute
+            valpwm =(255/(GazMax-GazMin))*valpoignee-(255/(GazMax-GazMin))*GazMin; // calcul de la PWM brute
         }
 
         if ((vitessemesure *3.6) > vitessebride) { // VITESSE MESURE
@@ -325,4 +441,40 @@
     tophalltotal += tophall;
     tophallpartiel += tophall;
     tophall=0;
+}
+void MesureTemp ()
+{
+    temp = (Temp.read()*3.3 )/ SensibiliteTemp;
+    printf("la temperature est de %1.3f KELVIN equivaut a %1.3f DEGRES\n\r",temp, temp-273.15);
+}
+
+void MesureVbat ()
+{
+    vbat = Vbat.read()*CoeffTensionbat;
+    printf("la tension de la batterie est de %1.3f volts\n\r", vbat );
+}
+void MesureIbat ()
+{
+    ibat = ((Ibat.read()*3.3*PDTI)-2.5)/SensibiliteCourant;
+    if (ibat < 0) {
+        ibat = 0;
+    }
+
+
+}
+void Mesurepoingnee()
+{
+    pourcentage = (valpwm*100 )/ 255;
+    printf("valeur pourcentage poignee %g  \n\r", pourcentage);
+
+}
+
+void MesuresWeb(void)
+{
+    temp = (Temp.read()*3.3 )/ SensibiliteTemp;
+    vbat = Vbat.read()*CoeffTensionbat;
+    ibat = ((Ibat.read()*3.3*PDTI)-2.5)/SensibiliteCourant;
+    if (ibat < 0) {
+        ibat = 0;
+    }
 }
\ No newline at end of file