moustic74 | Bonjour à tous, je suis en période de projet dans mon bts, et je galère sur une acquisition de température...
Je n'arrive PLUS (alors que ca marchait avant) à acquérir une température et à l'envoyer via Socket à mon collègue sur un autre pc.
Si quelqu'un a le courage de jeter un oeil (ou deux) sur ce travail, pour me donner une piste, ca serait cool...Merci à tous!
Code :
- #include <stdio.h>
- #include <conio.h>
- #include <dos.h>
- #include <string.h>
- #include <math.h>
- #include <tcpipapi.h>
- #include "io_toss.h"
- #include "i2c.h"
- #include "adu8591.h"
- #include "clib.h"
- #include <I2C_API.h>
- /*constante*/
- #define ecoute 1080
- #define recu 1080
- #define taille_envoi 20
- #define num_port 1080
- /*variable*/
- static char recvbuf[recu];
- char* sendbuf[taille_envoi];
- static char ClientIP[17];
- struct sockaddr_in addr;
- struct sockaddr_in claddr;
- char* valeur;
- char* val="";
- float temperature=0,temperature1=0;
- char* temperature_finale=0;
- char* temp=0;
- char degres[5];
- int sd;
- int asd;
- int established = 0;
- int i;
- int retval=0;
- int error=0;
- int retourne=0;
- void fermeture_socket_serveur(void);
- void envoi(char*);
- void automate(void);
- /**************FIN DES DECLARATIONS*********************************/
- /**************PARTIE SOCKET ***************************************/
- void fermeture_socket_serveur(void)
- {
- printf("\r\nFermeture de la socket" );
- closesocket(sd, &error);
- }
- void envoi(char* donnee)
- {
- retval = send( asd, donnee, strlen(donnee), 0, &error );
-
- if(retval == API_ERROR)
- {
- #ifdef TCP_ECHO_SERVER_DEBUG
- printf("\r\nTCPserver: Senderror %d",error);
- #endif
- established = 0;
- //break;
- }
- else
- {
- #ifdef TCP_ECHO_SERVER_DEBUG
- printf("\r\nTCPserver: Nothing received %d\r\n",error);
- #endif
- }
- }
- void automate(void)
- {
- //envoi vers l'ihm de la donnée
- valeur= strcat(degres,"&" );
- envoi(valeur);
- }
- void init_dk50 (void)
- {
- union REGS inregs;
- union REGS outregs;
- struct SREGS segregs;
- // Enable bus mask
- inregs.x.ax = 0x8001; // enable ALE
- inregs.x.dx = 0x0070; // what bits of databus are inputs/outputs
- // only Bits 0..6 on databus
- int86x(PFE_INT, &inregs, &outregs, &segregs);
- // Enable programmable chip selects
- inregs.h.ah = 0x83;
- inregs.x.dx = 0x04; // PCS2#
- int86x(PFE_INT, &inregs, &outregs, &segregs);
- }
- void logo(void)
- {
- int j=0;
- int y=0;
- text_ini();
- clear_text();
- i2c_transmit(0x70,0x00);
- _gotoxy(0,y+2);printf("Systeme" ); // add some text
- _gotoxy(2,y+3);printf("de Gestion " );
- _gotoxy(4,y+4);printf("et de traitement " );
- _gotoxy(5,y+5);printf("des pontes" );
- i2c_transmit(0x74,0xfe); i2c_release(); // LED1 blue on - Bit 0
- api_sleep(100);
- for(j=0;j<3;j++)
- {
- i2c_transmit(0x74,0xfd); i2c_release(); // LED2 green on - Bit 1
- api_sleep(100);
- i2c_transmit(0x74,0xfb); i2c_release(); // LED3 yellow on - Bit 2
- api_sleep(100);
- i2c_transmit(0x74,0xf7); i2c_release(); // LED4 red on - Bit 3
- api_sleep(100);
- i2c_transmit(0x74,0xfb); i2c_release(); // LED3 yellow on - Bit 2
- api_sleep(100);
- i2c_transmit(0x74,0xfd); i2c_release(); // LED2 green on - Bit 1
- api_sleep(100);
- i2c_transmit(0x74,0xfe); i2c_release(); // LED1 blue on - Bit 0
- api_sleep(100);
- }
- }
- void f_temperature(void)
- {
- int v2=0;
-
- I2C_select_clock_pin (0);// choix de scl
- I2C_select_data_pin (1); // choix de sda
- i2c_init();
- RTX_Sleep_Time(400);
- //acquisition temperature
- I2C_release();
- I2C_transmit_char(0x90,0x00); /*trame de canal*/
- I2C_receive_char(0x91,&temp,0); /*recevoir la valeur*/
- I2C_release(); /*initialiser*/
- v2=(int)temp; /*convertie une chaine de caractère en entier*/
- temperature1=(float)((2*v2)/100);
- temperature=temperature1/0.02;
- temperature_finale=(int)temperature;
- itoa(temperature,degres,10);
- //Affichage
- _gotoxy(3,6);
- printf("Temp:%.1f degres", temperature); /*Affichage en degrés*/
- _gotoxy(3,11);
- printf("Tension: %.1f volt",temperature1); /*Affichage en Volt*/
- I2C_release();
- }
- void jeu(void)
- {
- int i,j,wert,pos_point=0;
- unsigned char k;
- clear_text();clear_graphic(); // clear text and graphic display
- _gotoxy(0,0);printf("Choisir action" );
- _gotoxy(0,1);printf("<--I2C" );
- _gotoxy(13,1);printf("Bleu ->" );
- _gotoxy(13,5);printf("Vert ->" );
- _gotoxy(13,9);printf("Jaune->" );
- _gotoxy(13,13);printf("Flics->" );
- i=500;
- while (i--)
- {
- wert=(~i2c_receive(0x76))&0x00FF; // read bus at 0x76 -> keys
- if (wert)
- { j=wert; k=1; while(j>>=1)k++; // key 1..8 correnpond bit 0..7
- _gotoxy(10,6);printf("%d",k); // print number of key 1..8
- if(k==1)
- {
- clear_text();
- _gotoxy(10,7);printf("Acquisition en cours" ); // print number of key 1..8
- for(pos_point=0;pos_point<10;pos_point++)
- {
- printf("." );
- api_sleep(100);
- }
- clear_text();
- f_temperature();
- }
- if(k==5)
- {
- i2c_transmit(0x74,0xfe); i2c_release(); // LED1 blue on - Bit 0
- clear_text();
- _gotoxy(10,7);printf("Bleu!" ); // print number of key 1..8
- }
- if(k==6)
- {
- i2c_transmit(0x74,0xfd); i2c_release(); // LED2 green on - Bit 1
- clear_text();
- _gotoxy(10,7);printf("Vert!" ); // print number of key 1..8
- }
- if(k==7)
- {
- i2c_transmit(0x74,0xfb); i2c_release(); // LED2 yellow on - Bit 2
- clear_text();
- _gotoxy(10,7);printf("Jaune!" ); // print number of key 1..8
- }
- if(k==8)
- {
- i2c_transmit(0x74,0xf7); i2c_release(); // LED2 red on - Bit 3
- api_sleep(25);
- i2c_transmit(0x74,0xfe); i2c_release(); // LED1 blue on - Bit 0
- api_sleep(25);
- i2c_transmit(0x74,0xef); i2c_release(); // beep on - Bit 4
- api_sleep(25);
- i2c_transmit(0x74,0xff); i2c_release();
- clear_text();
- _gotoxy(10,7);printf("Flics!" ); // print number of key 1..8
- }
- }
- else
- { del_textline(7);
- // init port 0x74 -> Leds off, beep off, backlight on
- i2c_transmit(0x74,0xff); i2c_release();
- clear_graphic();
- }
- if(wert>250) // abort
- { clear_graphic();clear_text();
- // init port 0x74 -> Leds off, beep off, backlight on
- i2c_transmit(0x74,0xff); i2c_release();
- return;
- }
- api_sleep(10); // wait 10ms
- }
- }
- void invaders()
- {
- graph_ini();
- graph_on();
- clear_graphic();
- draw_line(6, 0, 9, 0);
- draw_line(12, 0, 15, 0);
- draw_line(6, 1, 9, 1);
- draw_line(12, 1, 15, 1);
- draw_line(0, 2, 0, 7);
- draw_line(1, 2, 0, 7);
- draw_line(2, 6, 2, 9);
- draw_line(3, 6, 3, 9);
- draw_line(4, 2, 4, 11);
- draw_line(5, 2, 5, 11);
- draw_line(4, 16, 4, 19);
- draw_line(5, 16, 5, 19);
- draw_line(6, 0, 6, 1);
- draw_line(6, 4, 6, 7);
- draw_line(6, 10, 6, 15);
- draw_line(7, 0, 7, 1);
- draw_line(7, 4, 7, 7);
- draw_line(7, 10, 7, 15);
- draw_line(8, 0, 8, 1);
- draw_line(8, 4, 8, 11);
- draw_line(9, 4, 9, 11);
- draw_line(10, 4, 10, 11);
- draw_line(11, 4, 11, 11);
- draw_line(12, 0, 12, 1);
- draw_line(12, 4, 12, 11);
- draw_line(13,4,13,11);
- draw_line(14,0,14,1);
- draw_line(14,4,14,7);
- draw_line(14,10,14,15);
- draw_line(15,0,14,1);
- draw_line(15,4,15,7);
- draw_line(15,10,15,15);
- api_sleep(1000);
- }
- void main()
- {
- init_dk50();
- logo();
- clear_text();
- //invaders();
- jeu();
- f_temperature();
- /*main()*/
- clear_text();
- api_sleep(1000);
- retval = opensocket(SOCK_STREAM, &error);
- sd = retval;
- /*Lire adresse local*/
- addr.sin_family = PF_INET;
- //convertir port d'envoie
- retval = htons(ecoute);
- addr.sin_port = retval;
- addr.sin_addr.s_addr = 0L;
- api_sleep(2000);
- /*Bind()*/
- retval = bind(sd, (const struct sockaddr *) &addr, &error);
- if(retval == API_ERROR);
- {
- _gotoxy(2,6);printf("\r\nErreur de bind: %d",error);
- //fermeture_socket_serveur();
- }
- api_sleep(2000);
- while(1) //Boucle infini
- {
- /*ecoute de la connexion*/
- _gotoxy(2,7);printf("\r\nEcoute pour la connexion" );
- retval = listen( sd,1,&error);
- api_sleep(2000);
- if(retval == API_ERROR);
- {
- _gotoxy(2,8);printf("\r\nErreur lors de l'ecoute: %d",error);
- //fermeture_socket_serveur();
- }
- /*Etablir le connection*/
- claddr.sin_family = PF_INET;
- claddr.sin_port = 0;
- claddr.sin_addr.s_addr = 0;
- retval = accept(sd, (struct sockaddr *)&claddr, &error);
- api_sleep(2000);
- if(retval == API_ERROR)
- {
- _gotoxy(2,8);printf("\r\nErreur lors de l'acception: %d",error);
- //fermeture_socket_serveur();
- }
- //Enregistrement la nouvelle description de la socket
- asd = retval;
- established = 1;
- api_sleep(2000);
- //Obtention de l'adresse IP du client
- InetToAscii((unsigned long *) &claddr.sin_addr.s_addr, (char *)ClientIP);
- _gotoxy(2,9);printf("\r\nL'adresse %s vient de se connecter\r\n",ClientIP);
- I2C_release();
- I2C_transmit_char(0x70,0x00);
- I2C_release();
- while(established) //Boucle infini
- {
- /*Attend les donné*/
- do
- {
- /*recv*/
- retval = recv(asd, (char *)recvbuf, recu, MSG_TIMEOUT, 20000, &error);
- if( retval == API_ERROR)
- {
- established = 0;
- break;
- }
- else
- {
- if(retval>0) //Reception des données
- {
- //affichage des donnée et analyse de celle-ci
- val=(char*)recvbuf;
- if(strcmp (val,"m" ) == 0)
- {
- //Test avec les lampes
- I2C_transmit_char(0x74, 0xfc); //Eteint
- I2C_release();
- automate();
- I2C_transmit_char(0X74, 0xfb); //Allume
- I2C_release();
- }
- if(strcmp (val,"n" ) == 0)
- {
- I2C_transmit_char(0x74,0xfc);
- I2C_release();
- }
- printf("Donnees recues: %s",val);
- recvbuf[0] = NULL;
- recvbuf[1] = NULL;
- recvbuf[2] = NULL;
- recvbuf[3] = NULL;
- recvbuf[4] = NULL;
- }
- }
- }while((retval!=API_ERROR) && (retval>0));//tant que les donnée sont bonnes
- }
- }
- }
- /******************************************* PROG JEREMY *************************************/
|
Y'a surement du déchet.. |