Bonjour,
J'ai un projet informatique à effectuer pour la fin de l'année et j'ai déja bien avancé mais mon code ne plait pas au prof pcq c mal foutu. Il faudrait des classes, un tableau à double dimension et récupérer les données dans des structures.
Malheureusement je ne suis pas un pro en prog alors je galère.
Voila mon code :

Code C++ : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
 
/********************************************************************/ 
/* Station Météo */ 
/* Communication et Récupération des données */ 
/*********************************************a***********************/ 
 
#include <stddef.h> 
#include <stdio.h> 
#include <errno.h> 
#include <stdlib.h> 
#include <math.h> 
#include <winsock2.h> 
#include <iostream> 
#include<string> 
#include <cstdlib> 
#include <fstream> 
//#include <fstream> 
 
using namespace std; 
 
#define TAILLE_BUF 100 
#define REVEIL_OK 1 
#define ESSAI_MAX 12 
#define SERVER_PORT_NUM 10001 /* server's port number for bind() */ 
#define NBRDATA 10 
#define SERVER_PORT_NUM1 20 
#define SERVER_PORT_NUM2 21 
#define SERVER_PORT_BIND 5000 
 
/*Prototypes*/ 
 
void commande(int); 
 
int main ( ) 
 
{ 
char serverName[]="192.168.3.221"; 
char message_recept[512]; 
 
struct sockaddr_in serverAddr; /* server's socket address */ 
int sockAddrSize; /* size of socket address structure */ 
int sFd; /* socket file descriptor */ 
int status,rcv ; 
WSADATA WSAData; 
 
 
status=WSAStartup(MAKEWORD(2,0), &WSAData); 
 
sFd = socket (AF_INET, SOCK_STREAM, 0); 
 
sockAddrSize = sizeof (struct sockaddr_in); 
 
serverAddr.sin_family = AF_INET; 
 
serverAddr.sin_port = htons (SERVER_PORT_NUM); 
 
serverAddr.sin_addr.s_addr= inet_addr (serverName); 
 
status=connect (sFd, (struct sockaddr *) &serverAddr, sockAddrSize); 
if(status==-1) cout << "ERREUR"<<endl; 
 
commande(sFd); /* appelle de la fonction recup_donne */ 
 
closesocket (sFd); 
 
WSACleanup(); 
 
return 0; 
 
} 
 
void commande(int sFd) 
{ int i,status; 
u_long temp; 
 
// Start Length Device-Option Number Command Data Field Checksum 
char Trame_IG[TAILLE_BUF]={0x80,0x80,0x80,0x00,0x00,0x00,0x04,0x04}; 
ioctlsocket(sFd,FIONREAD,&temp); 
if (temp) i=recv(sFd,(char *)Trame_IG,sizeof(Trame_IG),0); 
status=send(sFd,Trame_IG,8,0); 
Sleep(100); 
i=recv(sFd,(char *)Trame_IG,sizeof(Trame_IG),0); 
printf(" Recuperation des donnees del'onduleur numero : %d\n",Trame_IG[i-2]); 
 
//Acquisition de la puissance 
Sleep(500); 
char TrameP[TAILLE_BUF]={0x80,0x80,0x80,0x00,0x01,0x01,0x10,0x12}; 
ioctlsocket(sFd,FIONREAD,&temp); 
if (temp) i=recv(sFd,(char *)TrameP,sizeof(TrameP),0); 
status=send(sFd,TrameP,8,0); 
Sleep(100); 
 
i=recv(sFd,(char *)TrameP,sizeof(TrameP),0); 
printf("La puissance actuelle est de %.2f W\n",(((unsigned char)TrameP[i-4]*256) + (unsigned char)TrameP[i-3])*pow(10,(char)TrameP[i-2])); 
 
//Acquisition de l'énergie totale produite 
Sleep(500); 
char Trame_nrj[TAILLE_BUF]={0x80,0x80,0x80,0x00,0x01,0x01,0x11,0x13}; 
ioctlsocket(sFd,FIONREAD,&temp); 
if (temp) i=recv(sFd,(char *)Trame_nrj,sizeof(Trame_nrj),0); 
status=send(sFd,Trame_nrj,8,0); 
Sleep(100); 
 
i=recv(sFd,(char *)Trame_nrj,sizeof(Trame_nrj),0); 
printf("Energie totale : %.2f Wh\n",(((unsigned char)Trame_nrj[i-4]*256) + (unsigned char)Trame_nrj[i-3])*pow(10,(char)Trame_nrj[i-2])); 
 
//Acquisition de l'énergie jour produite 
Sleep(500); 
char Trame_nrjjr[TAILLE_BUF]={0x80,0x80,0x80,0x00,0x01,0x01,0x12,0x14}; 
ioctlsocket(sFd,FIONREAD,&temp); 
if (temp) i=recv(sFd,(char *)Trame_nrjjr,sizeof(Trame_nrjjr),0); 
status=send(sFd,Trame_nrjjr,8,0); 
Sleep(100); 
 
i=recv(sFd,(char *)Trame_nrjjr,sizeof(Trame_nrjjr),0); 
printf("Energie aujourdhui : %.2f Wh/j\n",(((unsigned char)Trame_nrjjr[i-4]*256) + (unsigned char)Trame_nrjjr[i-3])*pow(10,(char)Trame_nrjjr[i-2])); 
 
//Acquisition AC courant 
Sleep(500); 
char Trame_ac_courant[TAILLE_BUF]={0x80,0x80,0x80,0x00,0x01,0x01,0x14,0x16}; 
ioctlsocket(sFd,FIONREAD,&temp); 
if (temp) i=recv(sFd,(char *)Trame_ac_courant,sizeof(Trame_ac_courant),0); 
status=send(sFd,Trame_ac_courant,8,0); 
Sleep(100); 
 
i=recv(sFd,(char *)Trame_ac_courant,sizeof(Trame_ac_courant),0); 
printf("AC courant : %.2f A\n",(((unsigned char)Trame_ac_courant[i-4]*256) + (unsigned char)Trame_ac_courant[i-3])*pow(10,(char)Trame_ac_courant[i-2])); 
 
//Acquisition DC courant 
Sleep(500); 
char Trame_dc_courant[TAILLE_BUF]={0x80,0x80,0x80,0x00,0x01,0x01,0x17,0x19}; 
ioctlsocket(sFd,FIONREAD,&temp); 
if (temp) i=recv(sFd,(char *)Trame_dc_courant,sizeof(Trame_dc_courant),0); 
status=send(sFd,Trame_dc_courant,8,0); 
Sleep(100); 
 
i=recv(sFd,(char *)Trame_dc_courant,sizeof(Trame_dc_courant),0); 
printf("DC courant : %.2f A\n",(((unsigned char)Trame_dc_courant[i-4]*256) + (unsigned char)Trame_dc_courant[i-3])*pow(10,(char)Trame_dc_courant[i-2])); 
 
//Acquisition AC voltage 
Sleep(500); 
char Trame_ac_voltage[TAILLE_BUF]={0x80,0x80,0x80,0x00,0x01,0x01,0x15,0x17}; 
ioctlsocket(sFd,FIONREAD,&temp); 
if (temp) i=recv(sFd,(char *)Trame_ac_voltage,sizeof(Trame_ac_voltage),0); 
status=send(sFd,Trame_ac_voltage,8,0); 
Sleep(100); 
i=recv(sFd,(char *)Trame_ac_voltage,sizeof(Trame_ac_voltage),0); 
printf("AC voltage : %.2f V\n",(((unsigned char)Trame_ac_voltage[i-4]*256) + (unsigned char)Trame_ac_voltage[i-3])*pow(10,(char)Trame_ac_voltage[i-2])); 
 
//Acquisition DC voltage 
Sleep(500); 
char Trame_dc_voltage[TAILLE_BUF]={0x80,0x80,0x80,0x00,0x01,0x01,0x18,0x1A }; 
ioctlsocket(sFd,FIONREAD,&temp); 
if (temp) i=recv(sFd,(char *)Trame_dc_voltage,sizeof(Trame_dc_voltage),0); 
status=send(sFd,Trame_dc_voltage,8,0); 
Sleep(100); 
i=recv(sFd,(char *)Trame_dc_voltage,sizeof(Trame_dc_voltage),0); 
printf("DC voltage : %.2f V\n",(((unsigned char)Trame_dc_voltage[i-4]*256) + (unsigned char)Trame_dc_voltage[i-3])*pow(10,(char)Trame_dc_voltage[i-2])); 
 
//Acquisition de la fréquence 
Sleep (500); 
char Trame_freq[TAILLE_BUF]={0x80,0x80,0x80,0x00,0x01,0x01,0x16,0x18}; 
ioctlsocket(sFd,FIONREAD,&temp); 
if (temp) i=recv(sFd,(char *)Trame_freq,sizeof(Trame_freq),0); 
status=send(sFd,Trame_freq,8,0); 
Sleep(100); 
i=recv(sFd,(char *)Trame_freq,sizeof(Trame_freq),0); 
printf("Frequence : %.2f Hz\n",(((unsigned char)Trame_freq[i-4]*256) + (unsigned char)Trame_freq[i-3])*pow(10,(char)Trame_freq[i-2])); 
 
//Acquisition de la température 
Sleep(500); 
char TrameT[TAILLE_BUF]={0x80,0x80,0x80,0x00,0x02,0x02,0xe1,0xe5}; 
ioctlsocket(sFd,FIONREAD,&temp); 
if (temp) i=recv(sFd,(char *)TrameT,sizeof(TrameT),0); 
status=send(sFd,TrameT,8,0); 
Sleep(100); 
 
i=recv(sFd,(char *)TrameT,sizeof(TrameT),0); 
printf("Temperature ambiante : %.2f degres C\n",(((unsigned char)TrameT[i-4]*256) + (unsigned char)TrameT[i-3])*pow(10,(char)TrameT[i-2])); 
 
//Acquisition de l'ensoleillement 
Sleep(500); 
char Trame_sol[TAILLE_BUF]={0x80,0x80,0x80,0x00,0x02,0x02,0xe2,0xe6}; 
ioctlsocket(sFd,FIONREAD,&temp); 
if (temp) i=recv(sFd,(char *)Trame_sol,sizeof(Trame_sol),0); 
status=send(sFd,Trame_sol,8,0); 
Sleep(100); 
i=recv(sFd,(char *)Trame_sol,sizeof(Trame_sol),0); 
printf("L'ensoleillement est de %.2f W/m par metre carre\n",(((unsigned char)Trame_sol[i-4]*256) + (unsigned char)Trame_sol[i-3])*pow(10,(char)Trame_sol[i-2])); 
 
 
FILE *fp; 
int offset; 
int taille; 
 
fp=fopen("don_sol1.csv","w+"); 
 
int IG=Trame_IG[i-2]; 
 
float puissance=(((unsigned char)TrameP[i-4]*256) + (unsigned char)TrameP[i-3])*pow(10,(char)TrameP[i-2]); 
float nrj=(((unsigned char)Trame_nrj[i-4]*256) + (unsigned char)Trame_nrj[i-3])*pow(10,(char)Trame_nrj[i-2])/1000; 
float nrjjr=(((unsigned char)Trame_nrjjr[i-4]*256) + (unsigned char)Trame_nrjjr[i-3])*pow(10,(char)Trame_nrjjr[i-2])/1000; 
float temperature=(((unsigned char)TrameT[i-4]*256) + (unsigned char)TrameT[i-3])*pow(10,(char)TrameT[i-2]); 
float sol=(((unsigned char)Trame_sol[i-4]*256) + (unsigned char)Trame_sol[i-3])*pow(10,(char)Trame_sol[i-2]); 
 
float AC_courant=(((unsigned char)Trame_ac_courant[i-4]*256) + (unsigned char)Trame_ac_courant[i-3])*pow(10,(char)Trame_ac_courant[i-2]); 
float DC_courant=(((unsigned char)Trame_dc_courant[i-4]*256) + (unsigned char)Trame_dc_courant[i-3])*pow(10,(char)Trame_dc_courant[i-2]); 
float AC_voltage=(((unsigned char)Trame_ac_voltage[i-4]*256) + (unsigned char)Trame_ac_voltage[i-3])*pow(10,(char)Trame_ac_voltage[i-2]); 
float DC_voltage=(((unsigned char)Trame_dc_voltage[i-4]*256) + (unsigned char)Trame_dc_voltage[i-3])*pow(10,(char)Trame_dc_voltage[i-2]); 
 
float frequence=(((unsigned char)Trame_freq[i-4]*256) + (unsigned char)Trame_freq[i-3])*pow(10,(char)Trame_freq[i-2]); 
 
 
printf("%d\n",IG); 
// fseek(fp,offset,SEEK_SET); 
fprintf(fp,"%d;%.2f;%.2f;%.2f;%.2f;%.2f;%.2f;%.2f;%.2f;%.2f;%.2f \n",IG,puissance,nrj,nrjjr,temperature,sol,AC_courant,DC_courant,AC_voltage,DC_voltag*e,frequence); 
// fseek(fp,0,SEEK_SET); 
fclose(fp); 
}

Merci d'avance