![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
squelette de demarrage projet ERS3 IUT NICE GEII
Dependencies: mbed bloc_io mbed-rtos html EthernetInterface
Diff: main.cpp
- Revision:
- 1:545a3d6b5933
- Parent:
- 0:e30c9ba95bd4
- Child:
- 2:153d417b318b
diff -r e30c9ba95bd4 -r 545a3d6b5933 main.cpp --- a/main.cpp Sat Aug 22 15:51:59 2015 +0000 +++ b/main.cpp Tue Oct 15 07:14:47 2019 +0000 @@ -1,5 +1,3 @@ - - //#include "EthernetInterface.h" #include <stdlib.h> #include <string.h> @@ -10,26 +8,26 @@ #define RADIUS 0.2F // wheel size #define NBPOLES 8 // magnetic pole number #define DELTA_T 0.1F // speed measurement counting period +DigitalOut valid(p21);//rajout +void Init(int);//rajout +void lecture(void); +Bloc_IO MyPLD(p25,p26,p5,p6,p7,p8,p9,p10,p23,p24);// instantiate object needed to communicate with PLD +// analog input connected to mbed +// valid pmw mbed pin +Serial pc(USBTX, USBRX); // tx, rx +// Top_Hall Pin +int valref=0 ;//rajout +//void modulo (int ); + +/************ persistent file parameters section *****************/ +LocalFileSystem local("local"); // Create the local filesystem under the name "local" -Bloc_IO MyPLD(p25,p26,p5,p6,p7,p8,p9,p10,p23,p24);// instantiate object needed to communicate with PLD - // analog input connected to mbed - // valid pmw mbed pin -Serial pc(USBTX, USBRX); // tx, rx - // Top_Hall Pin - - - - -/************ persistent file parameters section *****************/ -LocalFileSystem local("local"); // Create the local filesystem under the name "local" - + + - - - - - + + /********************* web server section **********************************/ var_field_t tab_balise[10]; //une balise est présente dans le squelette @@ -37,7 +35,7 @@ /*********************** can bus section ************/ - // determine message ID used to send Gaz ref over can bus +// 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 CAN can_port (p30, p29); // initialisation du Bus CAN sur les broches 30 (rd) et 29(td) for lpc1768 + mbed shield @@ -48,12 +46,12 @@ 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 led4(LED4); // blink when can message is received - + - + //************ local function prototypes ******************* @@ -61,7 +59,7 @@ - + /**************** Read persistent data from text file located on local file system ****************/ @@ -81,9 +79,9 @@ //********************** timer interrupt for speed measurement each 100ms ************************* - - - + + + //********************* Timer Interrupt for gaz ref management each 10ms ******************** @@ -92,31 +90,38 @@ /********* 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 +{ + char ma_chaine4[20]= {}; // needed to form html response } - - - /*********************** CAN BUS SECTION **********************/ - + + +/*********************** CAN BUS SECTION **********************/ + void CAN_REC_THREAD(void const *args) -{ int iCount,iError; +{ + int iCount,iError; - while (bCan_Active) - {Thread::wait(100);// wait 100ms - // code todo - + while (bCan_Active) { + Thread::wait(100);// wait 100ms + // code todo + } - + } - - - + + + //*************************** main function ***************************************** -int main() { -char cChoix=0; +int main() +{ + int data_in; + char cChoix=0; + valid.write(0); + MyPLD.write(0); + valid.write(1); @@ -125,14 +130,14 @@ //***************************************** 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 -/********* main cgi function used to patch data to the web server thread **********************************/ + /********* main cgi function used to patch data to the web server thread **********************************/ -//******************************************* end web section ************************************* / +//******************************************* end web section ************************************* / -pc.printf(" programme scooter mbed \n"); + pc.printf(" programme scooter mbed \n"); @@ -141,29 +146,194 @@ //Thread CanThread(CAN_REC_THREAD);// create and launch can receiver thread //********************* end can bus section ***************************************************** + + while(cChoix!='q' and cChoix!='Q' /*and cChoix='c'*/) { + pc.printf(" veuillez saisir un choix parmi la liste proposee: \r\n"); + pc.printf(" a:saisie consigne pwm \r\n"); + pc.printf(" c:lecture interne \r\n"); + pc.printf(" q:quitter \r\n"); -while(cChoix!='q' and cChoix!='Q') -{pc.printf(" veuillez saisir un choix parmi la liste proposee: \n"); - pc.printf(" a:saisie consigne pwm \n"); - pc.printf(" q:quitter \n"); - - /************* 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 - /************* end of main thread sleep ****************/ - - pc.scanf(" %c",&cChoix); - switch (cChoix){ - case 'a': - break; - case 'q': - break; - } -} // end while - - //************** thread deinit ********************* - //DeInit_Web_Server(); - //bCan_Active=false; - //CanThread=false;// close can received thread + /************* 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 + } + /************* end of main thread sleep ****************/ + + pc.scanf(" %c",&cChoix); + switch (cChoix) { + case 'a': + + printf("donne moi une valeur de pwmref entre 0 et 255:"); + scanf("%d",&valref); + if(valref<=255) + { + MyPLD.write(valref); + } + else + { + valref=0; + MyPLD.write(valref); + printf("valeur entre 0 et 255"); + } + break; + case 'c' : + lecture(); + if((MyPLD.read() and 4)== 4){ + pc.printf("Frein inactif\n\r"); + } + else{ + printf("Frein actif\n\r"); + } + if((MyPLD.read() and 8==8)){ + pc.printf("FLTA actif\n\r"); + } + else{ + printf("FLTA inactif\n\r"); + } + if((MyPLD.read() and 16)==16){ + pc.printf("overcurrent inactif\n\r"); + } + else{ + printf("avercurrent actif\n\r"); + } + if((MyPLD.read() and 32)==32){ + pc.printf("direction avant\n\r"); + } + else{ + printf("direction arriere\n\r"); + } + if((MyPLD.read() and 64)==64){ + pc.printf("hallC a 1\n\r"); + } + else{ + printf("hallC a 0\n\r"); + } + if((MyPLD.read() and 128)==128){ + pc.printf("hallB a 1\n\r"); + } + else{ + printf("hallB a 0\n\r"); + } + if((MyPLD.read() and 256)==256){ + pc.printf("hallA a 1\n\r"); + } + else{ + printf("hallA a 0\n\r"); + } + + break; + case 'q': + valid.write(0); + MyPLD.write(0); + + break; + /* case 'q': + +frein.read(); +DigitalIn flta.read(); +DigitalIn overcurrent.read(); +DigitalIn direction.read(); + HALLA.read(); + HALLB.read(); + HALLC.read(); + break;*/ + } + } // end while + + //************** thread deinit ********************* + //DeInit_Web_Server(); + //bCan_Active=false; + //CanThread=false;// close can received thread pc.printf(" fin programme scooter mbed \n"); } // end main + + +void lecture (void){ + if((MyPLD.read() and 4)== 4){ + pc.printf("Frein inactif\n\r"); + } + else{ + printf("Frein actif\n\r"); + } + if((MyPLD.read() and 8==8)){ + pc.printf("FLTA actif\n\r"); + } + else{ + printf("FLTA inactif\n\r"); + } + if((MyPLD.read() and 16)==16){ + pc.printf("overcurrent inactif\n\r"); + } + else{ + printf("avercurrent actif\n\r"); + } + if((MyPLD.read() and 32)==32){ + pc.printf("direction avant\n\r"); + } + else{ + printf("direction arriere\n\r"); + } + if((MyPLD.read() and 64)==64){ + pc.printf("hallC a 1\n\r"); + } + else{ + printf("hallC a 0\n\r"); + } + if((MyPLD.read() and 128)==128){ + pc.printf("hallB a 1\n\r"); + } + else{ + printf("hallB a 0\n\r"); + } + if((MyPLD.read() and 256)==256){ + pc.printf("hallA a 1\n\r"); + } + else{ + printf("hallA a 0\n\r"); + } +} +/*void Init(int r) +{ + valid.write(r); + //MyPLD.write(valref); + +}*/ + + + /*void modulo (int a) + { + char x; + if(a==0) + { + x=0; + MyPLD.write(x); a + + } + if(a==64) + { + x=64; + MyPLD.write(x); + + } + if(a==96) + { + x=96; + MyPLD.write(x); + + } + if(a==112) + { + x=112; + MyPLD.write(x); + + } if(a==80) + { + x=80; + MyPLD.write(x); + + } if(a==48) + { + x=48; + MyPLD.write(x); + + }}*/ \ No newline at end of file