##// END OF EJS Templates
getConnectionStatus changes
imanay -
r111:112
parent child
Show More
@@ -1,650 +1,561
1 /* No newline at end of file
1 /*
2 * Servidor.c No newline at end of file
2 * Servidor.c
3 * No newline at end of file
3 *
4 * Created on: Nov 3, 2009 No newline at end of file
4 * Created on: Nov 3, 2009
5 * Author: Jose Francisco Quenta No newline at end of file
5 * Author: Jose Francisco Quenta
6 * No newline at end of file
6 *
7 * Se implementa: No newline at end of file
7 * Se implementa:
8 * -Carga en memoria los apuntes contenidos en un archivo de experimentos: apunte0 -> GPIO No newline at end of file
8 * -Carga en memoria los apuntes contenidos en un archivo de experimentos: apunte0 -> GPIO
9 * -Cambio de apunte. No newline at end of file
9 * -Cambio de apunte.
10 * -Lectura del estado actual del apunte y grabado del mismo en un archivo No newline at end of file
10 * -Lectura del estado actual del apunte y grabado del mismo en un archivo
11 *
No newline at end of file
12 * Modified by IvΓ‘n Manay since Nov 2012
No newline at end of file
13 * -From UDP to TCP.
No newline at end of file
14 * -Use of a frame for TCP communications with the central control module. No newline at end of file
11 */ No newline at end of file
15 */
12 No newline at end of file
16
13 #include <stdio.h> No newline at end of file
17 #include <stdio.h>
14 #include <stdlib.h> No newline at end of file
18 #include <stdlib.h>
15 #include <string.h> No newline at end of file
19 #include <string.h>
16 #include <unistd.h> No newline at end of file
20 #include <unistd.h>
17 #include <errno.h> No newline at end of file
21 #include <errno.h>
18 No newline at end of file
22
19 #include <sys/types.h> No newline at end of file
23 #include <sys/types.h>
20 #include <sys/socket.h> No newline at end of file
24 #include <sys/socket.h>
21 #include <netinet/in.h> No newline at end of file
25 #include <netinet/in.h>
22 #include <arpa/inet.h> No newline at end of file
26 #include <arpa/inet.h>
23 #include <netdb.h> No newline at end of file
27 #include <netdb.h>
24 No newline at end of file
28
25 #include "./Librerias/AT91gpio_Funciones.h" No newline at end of file
29 #include "./Librerias/AT91gpio_Funciones.h"
26 #include "./Librerias/Mensajes.h" No newline at end of file
30 #include "./Librerias/Mensajes.h"
27 No newline at end of file
31
28 #define PUERTO_SERVIDOR 5500 No newline at end of file
32 #define PUERTO_SERVIDOR 5500
29 #define TAM_BUFFER 1024 No newline at end of file
33 #define TAM_BUFFER 1024
30 No newline at end of file
34
31 #define maskc_out PC30+PC28+PC26+PC24+PC22+PC20 //MSB-UP-LSB MSB-DOWN-LSB //APUNTE No newline at end of file
35 #define maskc_out PC30+PC28+PC26+PC24+PC22+PC20 //MSB-UP-LSB MSB-DOWN-LSB //APUNTE
32 No newline at end of file
36
33 #define maskb_in PB16+PB18+PB20+PB30+PB24+PB22 //MSB-UP-LSB MSB-DOWN-LSB //VERIFICACION No newline at end of file
37 #define maskb_in PB16+PB18+PB20+PB30+PB24+PB22 //MSB-UP-LSB MSB-DOWN-LSB //VERIFICACION
34 No newline at end of file
38
35 #define bit_up_2 0x00010000 //Mascara de cada bit a revisar: bit_up_2 es MSB No newline at end of file
39 #define bit_up_2 0x00010000 //Mascara de cada bit a revisar: bit_up_2 es MSB
36 #define bit_up_1 0x00040000 No newline at end of file
40 #define bit_up_1 0x00040000
37 #define bit_up_0 0x00100000 No newline at end of file
41 #define bit_up_0 0x00100000
38 #define bit_dow_2 0x40000000 No newline at end of file
42 #define bit_dow_2 0x40000000
39 #define bit_dow_1 0x01000000 No newline at end of file
43 #define bit_dow_1 0x01000000
40 #define bit_dow_0 0x00400000 No newline at end of file
44 #define bit_dow_0 0x00400000
41 No newline at end of file
45
42 #define MyID 11 No newline at end of file
46 #define MyID 11
43 #define MAXPENDING 5 /* Maximum outstanding connection requests */ No newline at end of file
47 #define MAXPENDING 5 /* Maximum outstanding connection requests */
44 No newline at end of file
48
45 char *buff_experimento= NULL; No newline at end of file
49 char *buff_experimento= NULL;
46 No newline at end of file
50
47 AT91S_PIO *pioc; No newline at end of file
51 AT91S_PIO *pioc;
48 AT91S_PIO *piob; No newline at end of file
52 AT91S_PIO *piob;
49 No newline at end of file
53
50 struct control_module_parameters { No newline at end of file
54 struct control_module_parameters {
51 char ID[20]; No newline at end of file
55 char ID[20];
52 char param2[20]; No newline at end of file
56 char param2[20];
53 char param3[20]; No newline at end of file
57 char param3[20];
54 char param4[20]; No newline at end of file
58 char param4[20];
55 }; No newline at end of file
59 };
56 No newline at end of file
60
57 typedef struct control_module_parameters cmp; No newline at end of file
61 typedef struct control_module_parameters cmp;
58 No newline at end of file
62
59 No newline at end of file
63 char *header = NULL;
60 char *header = NULL; No newline at end of file
64 char *TypeOfInstrument = NULL;
61 char *TypeOfInstrument = NULL; No newline at end of file
65 char *iDSource = NULL;
62 char *iDSource = NULL; No newline at end of file
66 char *iDDestino = NULL;
63 char *iDDestino = NULL;
67 char *rx_len = NULL;
No newline at end of file
68 char *cmd = NULL; No newline at end of file
64 char *len = NULL; No newline at end of file
65 char *cmd = NULL; No newline at end of file
69 char *rx_data = NULL;
66 char *rx_data = NULL; No newline at end of file
70 char *crc = NULL;
67 char *crc = NULL; No newline at end of file
71
68 No newline at end of file
72 cmp parameters;
69 cmp parameters; No newline at end of file
73 /*
70 /* No newline at end of file
74 * Zona de declaracion de cabeceras.
71 * Zona de declaracion de cabeceras. No newline at end of file
75 */
72 */ No newline at end of file
76 cmp inicializa_modulo(cmp p);
73 cmp inicializa_modulo(cmp p); No newline at end of file
77 int inicializa_ethernet();
74 int inicializa_ethernet(); No newline at end of file
78 int rxData(int, char*);
75 int rxData(int, char*); No newline at end of file
79 void txData(int, char*);
76 void txData(int, char*); No newline at end of file
80 void inicializa_gpio();
77 void inicializa_gpio(); No newline at end of file
81 void procesa_peticion(char *rx_buffer, char *tx_buffer);
78 void procesa_peticion(char *rx_buffer, char *tx_buffer); No newline at end of file
82 int cambia_apuntamiento(char *puntero_char);
79 int cambia_apuntamiento(char *puntero_char); No newline at end of file
83 int carga_experimento(char *nombre_archivo);
80 int carga_experimento(char *nombre_archivo); No newline at end of file
84 char *chequeo_sistema(char *filename, char *numero_muestras);
81 char *chequeo_sistema(char *filename, char *numero_muestras);
85 void recibe_experimento(char *data, char filename[]);
No newline at end of file
82 int chequeo_sistema2(char *filename, char *numero_muestras); No newline at end of file
83 void recibe_experimento(char *data, char filename[]);
86 void SplitFrame(char *frame);
No newline at end of file
84 char* File2buffer(char *filename2, int n); No newline at end of file
85 void SplitFrame(char *frame);
87 void intToStr( int number, char* str );
No newline at end of file
88 No newline at end of file
86 void procesa_peticion2(char *rx_buffer, char *tx_buffer); No newline at end of file
87 No newline at end of file
89 /*
88 /* No newline at end of file
90 *
89 * No newline at end of file
91 */
90 */ No newline at end of file
92 int main(){
91 int main(){ No newline at end of file
93
92 No newline at end of file
94 int servSocket;
93 int servSocket; No newline at end of file
95 int clntSocket;
94 int clntSocket; No newline at end of file
96
95 No newline at end of file
97
96 No newline at end of file
98 char *rx_buffer = (char *) malloc(TAM_BUFFER);
97 char *rx_buffer = (char *) malloc(TAM_BUFFER); No newline at end of file
99 char *tx_buffer = (char *) malloc(TAM_BUFFER);
98 char *tx_buffer = (char *) malloc(TAM_BUFFER); No newline at end of file
100 /* Inicializa parametros del modulo*/
99 /* Inicializa parametros del modulo*/ No newline at end of file
101 parameters = inicializa_modulo(parameters);
100 parameters = inicializa_modulo(parameters); No newline at end of file
102 printf("%s\n%s\n%s\n%s\n",parameters.ID, parameters.param2, parameters.param3, parameters.param4);
101 printf("%s\n%s\n%s\n%s\n",parameters.ID, parameters.param2, parameters.param3, parameters.param4); No newline at end of file
103 /* Inicializa red*/
102 /* Inicializa red*/ No newline at end of file
104 servSocket = inicializa_ethernet();
103 servSocket = inicializa_ethernet(); No newline at end of file
105 /* Inicializamos el puerto GPIO del sistema embebido GSBC-9260S */
104 /* Inicializamos el puerto GPIO del sistema embebido GSBC-9260S */ No newline at end of file
106 inicializa_gpio();
105 inicializa_gpio(); No newline at end of file
107
106 No newline at end of file
108 while(1){
107 while(1){ No newline at end of file
109 // RecepciΓ³n TCP de peticiΓ³n
108 // RecepciΓ³n TCP de peticiΓ³n No newline at end of file
110 clntSocket = rxData(servSocket, rx_buffer);
109 clntSocket = rxData(servSocket, rx_buffer); No newline at end of file
111 //testpoint
110 //testpoint No newline at end of file
112 printf("rx:%s\n",rx_buffer);
111 printf("rx:%s\n",rx_buffer); No newline at end of file
113 // Procesamiento de la peticiΓ³n
112 // Procesamiento de la peticiΓ³n No newline at end of file
114 procesa_peticion(rx_buffer, tx_buffer);
113 procesa_peticion(rx_buffer, tx_buffer); No newline at end of file
115 //testpoint
114 //testpoint No newline at end of file
116 printf("tx:%s\n",tx_buffer);
115 printf("tx:%s\n",tx_buffer); No newline at end of file
117 // Respuesta del modulo de control
116 // Respuesta del modulo de control No newline at end of file
118 txData(clntSocket, tx_buffer);
117 txData(clntSocket, tx_buffer); No newline at end of file
119
118 No newline at end of file
120 }
119 } No newline at end of file
121 }
120 } No newline at end of file
122
121 No newline at end of file
123
122 No newline at end of file
124 int inicializa_ethernet(){
123 int inicializa_ethernet(){ No newline at end of file
125
124 No newline at end of file
126 struct sockaddr_in inf_servidor;
125 struct sockaddr_in inf_servidor; No newline at end of file
127
126 No newline at end of file
128 int servSocket;
127 int servSocket; No newline at end of file
129
128 No newline at end of file
130 int resultado;
129 int resultado; No newline at end of file
131
130 No newline at end of file
132 /* Haciendo la estructura local*/
131 /* Haciendo la estructura local*/ No newline at end of file
133 memset(&inf_servidor, 0, sizeof(inf_servidor));
132 memset(&inf_servidor, 0, sizeof(inf_servidor)); No newline at end of file
134 inf_servidor.sin_family= AF_INET;
133 inf_servidor.sin_family= AF_INET; No newline at end of file
135 inf_servidor.sin_port= htons(PUERTO_SERVIDOR);
134 inf_servidor.sin_port= htons(PUERTO_SERVIDOR); No newline at end of file
136 inf_servidor.sin_addr.s_addr= INADDR_ANY;
135 inf_servidor.sin_addr.s_addr= INADDR_ANY; No newline at end of file
137
136 No newline at end of file
138 /* Se establece el socket */
137 /* Se establece el socket */ No newline at end of file
139 servSocket = socket(AF_INET,SOCK_STREAM, IPPROTO_TCP);
138 servSocket = socket(AF_INET,SOCK_STREAM, IPPROTO_TCP); No newline at end of file
140 if (servSocket == -1){
139 if (servSocket == -1){ No newline at end of file
141 ERROR_FATAL("No se establecio correctamente el socket: socket()\n");
140 ERROR_FATAL("No se establecio correctamente el socket: socket()\n"); No newline at end of file
142 exit(-1);
141 exit(-1); No newline at end of file
143 }
142 } No newline at end of file
144
143 No newline at end of file
145 /* Se asocia el socket a un puerto y una IP */
144 /* Se asocia el socket a un puerto y una IP */ No newline at end of file
146 resultado = bind(servSocket,(struct sockaddr *)&inf_servidor,sizeof(inf_servidor));
145 resultado = bind(servSocket,(struct sockaddr *)&inf_servidor,sizeof(inf_servidor)); No newline at end of file
147 if (resultado== -1){
146 if (resultado== -1){ No newline at end of file
148 ERROR_FATAL("No se establecio correctamente el socket: bind()\n");
147 ERROR_FATAL("No se establecio correctamente el socket: bind()\n"); No newline at end of file
149 exit(-1);
148 exit(-1); No newline at end of file
150 }
149 } No newline at end of file
151
150 No newline at end of file
152 if (listen(servSocket, MAXPENDING) < 0){
151 if (listen(servSocket, MAXPENDING) < 0){ No newline at end of file
153 printf("listen() failed\n");
152 printf("listen() failed\n"); No newline at end of file
154 exit(-1);
153 exit(-1); No newline at end of file
155 }
154 } No newline at end of file
156
155 No newline at end of file
157 return servSocket;
156 return servSocket; No newline at end of file
158
157 No newline at end of file
159 }
158 } No newline at end of file
160
159 No newline at end of file
161 int rxData(int servSocket, char* rx_buffer){
160 int rxData(int servSocket, char* rx_buffer){ No newline at end of file
162
161 No newline at end of file
163 int clntSocket;
162 int clntSocket; No newline at end of file
164 struct sockaddr_in inf_cliente;
163 struct sockaddr_in inf_cliente; No newline at end of file
165 int numbytes_recibidos;
164 int numbytes_recibidos; No newline at end of file
166 unsigned int inf_client_Len;
165 unsigned int inf_client_Len; No newline at end of file
167
166 No newline at end of file
168 printf("\nEsperando solicitud de cliente...\n");
167 printf("\nEsperando solicitud de cliente...\n"); No newline at end of file
169
168 No newline at end of file
170 /* Set the size of the in-out parameter */
169 /* Set the size of the in-out parameter */ No newline at end of file
171 inf_client_Len = sizeof(inf_cliente);
170 inf_client_Len = sizeof(inf_cliente); No newline at end of file
172 /* Se espera hasta que un cliente se conecte */
171 /* Se espera hasta que un cliente se conecte */ No newline at end of file
173 if ((clntSocket = accept(servSocket, (struct sockaddr *) &inf_cliente,
172 if ((clntSocket = accept(servSocket, (struct sockaddr *) &inf_cliente, No newline at end of file
174 &inf_client_Len)) < 0)
173 &inf_client_Len)) < 0) No newline at end of file
175 printf("accept() failed\n");
174 printf("accept() failed\n"); No newline at end of file
176
175 No newline at end of file
177 if ((numbytes_recibidos = recv(clntSocket, rx_buffer, TAM_BUFFER, 0)) < 0)
176 if ((numbytes_recibidos = recv(clntSocket, rx_buffer, TAM_BUFFER, 0)) < 0) No newline at end of file
178 printf("recv() failed\n");
177 printf("recv() failed\n"); No newline at end of file
179
178 No newline at end of file
180 /* Se procede a procesar los datos recibidos */
179 /* Se procede a procesar los datos recibidos */ No newline at end of file
181 rx_buffer[numbytes_recibidos]= '\0';
180 rx_buffer[numbytes_recibidos]= '\0'; No newline at end of file
182
181 No newline at end of file
183 return clntSocket;
182 return clntSocket; No newline at end of file
184 }
183 } No newline at end of file
185
184 No newline at end of file
186 void txData(int clntSocket, char* data){
185 void txData(int clntSocket, char* data){ No newline at end of file
187
186 No newline at end of file
188 /* Echo message back to client */
187 /* Echo message back to client */ No newline at end of file
189 if (send(clntSocket, data, strlen(data), 0) != strlen(data))
188 if (send(clntSocket, data, strlen(data), 0) != strlen(data)) No newline at end of file
190 printf("send() failed\n");
189 printf("send() failed\n"); No newline at end of file
191
190 No newline at end of file
192 close(clntSocket); /* Close client socket */
191 close(clntSocket); /* Close client socket */ No newline at end of file
193 }
192 } No newline at end of file
194
193 /* No newline at end of file
195 /*
194 * Esta funcion incializa el puerto GPIO No newline at end of file
196 * Esta funcion incializa el puerto GPIO
195 */ No newline at end of file
197 */
196 void inicializa_gpio(){ No newline at end of file
198 void inicializa_gpio(){
197 No newline at end of file
199
198 // Configuracion de los pines de APUNTE No newline at end of file
200 // Configuracion de los pines de APUNTE
199 pioc = pio_map(PIOC_BASE); No newline at end of file
201 pioc = pio_map(PIOC_BASE);
200 pio_enable(pioc, maskc_out); No newline at end of file
202 pio_enable(pioc, maskc_out);
201 pio_disable_irq(pioc, maskc_out); No newline at end of file
203 pio_disable_irq(pioc, maskc_out);
202 pio_disable_multiple_driver(pioc, maskc_out); No newline at end of file
204 pio_disable_multiple_driver(pioc, maskc_out);
203 pio_disable_pull_ups(pioc, maskc_out); No newline at end of file
205 pio_disable_pull_ups(pioc, maskc_out);
204 pio_synchronous_data_output(pioc, maskc_out); No newline at end of file
206 pio_synchronous_data_output(pioc, maskc_out);
205 pio_output_enable(pioc, maskc_out); No newline at end of file
207 pio_output_enable(pioc, maskc_out);
206 No newline at end of file
208
207 // Configuracion de los pines de VERIFICACION No newline at end of file
209 // Configuracion de los pines de VERIFICACION
208 piob = pio_map(PIOB_BASE); No newline at end of file
210 piob = pio_map(PIOB_BASE);
209 pio_enable(piob, maskb_in); No newline at end of file
211 pio_enable(piob, maskb_in);
210 pio_disable_irq(piob, maskb_in); No newline at end of file
212 pio_disable_irq(piob, maskb_in);
211 pio_disable_multiple_driver(piob, maskb_in); No newline at end of file
213 pio_disable_multiple_driver(piob, maskb_in);
212 pio_disable_pull_ups(piob, maskb_in); No newline at end of file
214 pio_disable_pull_ups(piob, maskb_in);
213 pio_input_enable(piob, maskb_in);
215 pio_input_enable(piob, maskb_in);
No newline at end of file
216 }
214
No newline at end of file
No newline at end of file
217
215 }
No newline at end of file
No newline at end of file
218
216
No newline at end of file
No newline at end of file
219 /*
217 /*
No newline at end of file
No newline at end of file
220 * Divide rx frame into the frame components
218 * Esta funcion procesa el mensaje de peticion y genera respuesta
No newline at end of file
No newline at end of file
221 */ No newline at end of file
219 */
No newline at end of file
220 void procesa_peticion2(char *rx_buffer, char *tx_buffer){
No newline at end of file
221 int n = 0;
No newline at end of file
222 char filename1[50];
No newline at end of file
223 char filename2[] = "verificacion.txt";
No newline at end of file
224 char *tx_data = NULL;
No newline at end of file
225 char *header = strtok(rx_buffer, ":");
No newline at end of file
226 char *TypeOfInstrument = strtok(NULL, ":");
No newline at end of file
227 char *iDSource = strtok(NULL, ":");
No newline at end of file
228 char *iDDestino = strtok(NULL, ":");
No newline at end of file
229 char *len = strtok(NULL, ":");
No newline at end of file
230 char *cmd = strtok(NULL, ":");
No newline at end of file
231 char *rx_data = strtok(NULL, ":");
No newline at end of file
232 char *crc = strtok(NULL, ":");
No newline at end of file
233
No newline at end of file
234 if ((cmd == NULL) || (rx_data == NULL)){
No newline at end of file
235 ERROR("procesarPeticion: formato de mensaje incorrecto");
No newline at end of file
236 }
No newline at end of file
237 else{
No newline at end of file
238 if(strcmp(cmd,"SNDF") == 0){
No newline at end of file
239 recibe_experimento(rx_data,filename1);
No newline at end of file
240 carga_experimento(filename1);
No newline at end of file
241 cambia_apuntamiento("0");
No newline at end of file
242 tx_data = (char*)malloc(3);
No newline at end of file
243 tx_data = "OK";
No newline at end of file
244 }
No newline at end of file
245 else if(strcmp(cmd,"CHGB") == 0){
No newline at end of file
246 cambia_apuntamiento(rx_data);
No newline at end of file
247 tx_data = (char*)malloc(3);
No newline at end of file
248 tx_data = "OK";
No newline at end of file
249
No newline at end of file
250 }
No newline at end of file
251
No newline at end of file
252 else if(strcmp(cmd,"ANST") == 0){
No newline at end of file
253 n = chequeo_sistema2(filename2,rx_data);
No newline at end of file
254 printf("%i\n",n);
No newline at end of file
255 tx_data = File2buffer(filename2, n);
No newline at end of file
256 }
No newline at end of file
257 else{
No newline at end of file
258 tx_data = (char*)malloc(6);
No newline at end of file
259 tx_data = "Error";
No newline at end of file
260 ERROR("procesa_peticion: comando no reconocido");
No newline at end of file
261 }
No newline at end of file
262
No newline at end of file
263 strcpy(tx_buffer,header);
No newline at end of file
264 strcat(tx_buffer,":");
No newline at end of file
265 strcat(tx_buffer,TypeOfInstrument);
No newline at end of file
266 strcat(tx_buffer,":");
No newline at end of file
267 strcat(tx_buffer,iDDestino);
No newline at end of file
268 strcat(tx_buffer,":");
No newline at end of file
269 strcat(tx_buffer,iDSource);
No newline at end of file
270 strcat(tx_buffer,":");
No newline at end of file
271 strcat(tx_buffer,len);
No newline at end of file
272 strcat(tx_buffer,":");
No newline at end of file
273 strcat(tx_buffer,cmd);
No newline at end of file
274 strcat(tx_buffer,":");
No newline at end of file
275 strcat(tx_buffer,tx_data);
No newline at end of file
276 strcat(tx_buffer,":");
No newline at end of file
277 strcat(tx_buffer,crc);
No newline at end of file
278 strcat(tx_buffer,":");
No newline at end of file
279 strcat(tx_buffer,"quit");
No newline at end of file
280 }
No newline at end of file
281 }
No newline at end of file
282 No newline at end of file
283 void SplitFrame(char *frame){ No newline at end of file
222 void SplitFrame(char *frame){
284 header = malloc(4); No newline at end of file
223 header = malloc(4);
285 *header = *frame; No newline at end of file
224 *header = *frame;
286 *(header + 1) = *(frame + 1); No newline at end of file
225 *(header + 1) = *(frame + 1);
287 *(header + 2) = *(frame + 2); No newline at end of file
226 *(header + 2) = *(frame + 2);
288 *(header + 3) = '\0';
227 *(header + 3) = '\0';
No newline at end of file
289 printf("%s\n",header); No newline at end of file
290 TypeOfInstrument = malloc(4); No newline at end of file
228 TypeOfInstrument = malloc(4);
291 *TypeOfInstrument = *(frame + 3); No newline at end of file
229 *TypeOfInstrument = *(frame + 3);
292 *(TypeOfInstrument + 1) = *(frame + 4); No newline at end of file
230 *(TypeOfInstrument + 1) = *(frame + 4);
293 *(TypeOfInstrument + 2) = *(frame + 5); No newline at end of file
231 *(TypeOfInstrument + 2) = *(frame + 5);
294 *(TypeOfInstrument + 3) = '\0';
232 *(TypeOfInstrument + 3) = '\0';
No newline at end of file
295 printf("%s\n",TypeOfInstrument); No newline at end of file
296 iDSource = malloc(8); No newline at end of file
233 iDSource = malloc(8);
297 *iDSource = *(frame + 6); No newline at end of file
234 *iDSource = *(frame + 6);
298 *(iDSource + 1) = *(frame + 7); No newline at end of file
235 *(iDSource + 1) = *(frame + 7);
299 *(iDSource + 2) = *(frame + 8); No newline at end of file
236 *(iDSource + 2) = *(frame + 8);
300 *(iDSource + 3) = *(frame + 9); No newline at end of file
237 *(iDSource + 3) = *(frame + 9);
301 *(iDSource + 4) = *(frame + 10); No newline at end of file
238 *(iDSource + 4) = *(frame + 10);
302 *(iDSource + 5) = *(frame + 11); No newline at end of file
239 *(iDSource + 5) = *(frame + 11);
303 *(iDSource + 6) = *(frame + 12); No newline at end of file
240 *(iDSource + 6) = *(frame + 12);
304 *(iDSource + 7) = '\0';
241 *(iDSource + 7) = '\0';
No newline at end of file
305 printf("%s\n",iDSource); No newline at end of file
306 iDDestino = malloc(8); No newline at end of file
242 iDDestino = malloc(8);
307 *iDDestino = *(frame + 13); No newline at end of file
243 *iDDestino = *(frame + 13);
308 *(iDDestino + 1) = *(frame + 14); No newline at end of file
244 *(iDDestino + 1) = *(frame + 14);
309 *(iDDestino + 2) = *(frame + 15); No newline at end of file
245 *(iDDestino + 2) = *(frame + 15);
310 *(iDDestino + 3) = *(frame + 16); No newline at end of file
246 *(iDDestino + 3) = *(frame + 16);
311 *(iDDestino + 4) = *(frame + 17); No newline at end of file
247 *(iDDestino + 4) = *(frame + 17);
312 *(iDDestino + 5) = *(frame + 18); No newline at end of file
248 *(iDDestino + 5) = *(frame + 18);
313 *(iDDestino + 6) = *(frame + 19); No newline at end of file
249 *(iDDestino + 6) = *(frame + 19);
314 *(iDDestino + 7) = '\0';
250 *(iDDestino + 7) = '\0';
No newline at end of file
251 rx_len = malloc(7);
315 printf("%s\n",iDDestino);
No newline at end of file
No newline at end of file
252 *rx_len = *(frame + 20);
316 len = malloc(7);
No newline at end of file
No newline at end of file
253 *(rx_len + 1) = *(frame + 21);
317 *len = *(frame + 20);
No newline at end of file
No newline at end of file
254 *(rx_len + 2) = *(frame + 22);
318 *(len + 1) = *(frame + 21);
No newline at end of file
No newline at end of file
255 *(rx_len + 3) = *(frame + 23);
319 *(len + 2) = *(frame + 22);
No newline at end of file
No newline at end of file
256 *(rx_len + 4) = *(frame + 24);
320 *(len + 3) = *(frame + 23);
No newline at end of file
No newline at end of file
257 *(rx_len + 5) = *(frame + 25);
321 *(len + 4) = *(frame + 24);
No newline at end of file
No newline at end of file
258 *(rx_len + 6) = '\0'; No newline at end of file
322 *(len + 5) = *(frame + 25);
No newline at end of file
323 *(len + 6) = '\0';
No newline at end of file
324 printf("%s\n",len); No newline at end of file
325 cmd = malloc(5); No newline at end of file
259 cmd = malloc(5);
326 *cmd = *(frame + 26); No newline at end of file
260 *cmd = *(frame + 26);
327 *(cmd + 1) = *(frame + 27); No newline at end of file
261 *(cmd + 1) = *(frame + 27);
328 *(cmd + 2) = *(frame + 28); No newline at end of file
262 *(cmd + 2) = *(frame + 28);
329 *(cmd + 3) = *(frame + 29); No newline at end of file
263 *(cmd + 3) = *(frame + 29);
330 *(cmd + 4) = '\0';
264 *(cmd + 4) = '\0';
No newline at end of file
265
331 printf("%s\n",cmd);
No newline at end of file
No newline at end of file
266 int l = atoi(rx_len); No newline at end of file
332
No newline at end of file
333 int l = atoi(len) - 31; //Resto del tamaΓ±o total de la trama los 31 bytes fijos No newline at end of file
334 rx_data = malloc(l + 1); No newline at end of file
267 rx_data = malloc(l + 1);
335 int i; No newline at end of file
268 int i;
336 for (i = 30; i < 30 + l; i++) No newline at end of file
269 for (i = 30; i < 30 + l; i++)
337 *(rx_data + (i-30)) = *(frame + i); No newline at end of file
270 *(rx_data + (i-30)) = *(frame + i);
338 *(rx_data + l) = '\0';
271 *(rx_data + l) = '\0';
No newline at end of file
339 printf("%s\n",rx_data); No newline at end of file
340 crc = malloc(2); No newline at end of file
272 crc = malloc(2);
341 *crc = *(frame + 30 + l); No newline at end of file
273 *crc = *(frame + 30 + l);
342 *(crc + 1) = '\0';
274 *(crc + 1) = '\0';
No newline at end of file
275 }
343 printf("%s\n",crc);
No newline at end of file
No newline at end of file
276
344 }
No newline at end of file
No newline at end of file
277
345 No newline at end of file
No newline at end of file
278 /*
No newline at end of file
279 * Esta funcion procesa el mensaje de peticion y genera respuesta
No newline at end of file
280 */ No newline at end of file
346 void procesa_peticion(char *rx_buffer, char *tx_buffer){ No newline at end of file
281 void procesa_peticion(char *rx_buffer, char *tx_buffer){
347 // int n = 0; No newline at end of file
282 // int n = 0;
348 char filename1[50]; No newline at end of file
283 char filename1[50];
349 char filename2[] = "verificacion.txt"; No newline at end of file
284 char filename2[] = "verificacion.txt";
350 char *tx_data = NULL; No newline at end of file
285 char *tx_data = NULL;
286 char *tx_len = NULL; No newline at end of file
351 SplitFrame(rx_buffer);
287 SplitFrame(rx_buffer);
No newline at end of file
352 printf("Split\n");
No newline at end of file
353 printf("%s\n",header);
No newline at end of file
354 printf("%s\n",TypeOfInstrument);
No newline at end of file
355 printf("%s\n",iDSource);
No newline at end of file
356 printf("%s\n",iDDestino);
No newline at end of file
357 printf("%s\n",len);
No newline at end of file
358 printf("%s\n",cmd);
No newline at end of file
359 printf("%s\n",rx_data);
No newline at end of file
360 printf("%s\n",crc);
No newline at end of file
361 printf("Split\n"); No newline at end of file
362 No newline at end of file
288
363 if ((cmd == NULL) || (rx_data == NULL)){ No newline at end of file
289 if ((cmd == NULL) || (rx_data == NULL)){
364 ERROR("procesarPeticion: formato de mensaje incorrecto"); No newline at end of file
290 ERROR("procesarPeticion: formato de mensaje incorrecto");
365 } No newline at end of file
291 }
366 else{ No newline at end of file
292 else{
367 if(strcmp(cmd,"SNDF") == 0){ No newline at end of file
293 if(strcmp(cmd,"SNDF") == 0){
368 recibe_experimento(rx_data,filename1); No newline at end of file
294 recibe_experimento(rx_data,filename1);
369 carga_experimento(filename1); No newline at end of file
295 carga_experimento(filename1);
370 cambia_apuntamiento("0"); No newline at end of file
296 cambia_apuntamiento("0");
371 tx_data = (char*)malloc(3); No newline at end of file
297 tx_data = (char*)malloc(3);
372 tx_data = "OK"; No newline at end of file
298 tx_data = "OK";
373 } No newline at end of file
299 }
374 else if(strcmp(cmd,"CHGB") == 0){ No newline at end of file
300 else if(strcmp(cmd,"CHGB") == 0){
375 cambia_apuntamiento(rx_data); No newline at end of file
301 cambia_apuntamiento(rx_data);
376 tx_data = (char*)malloc(3); No newline at end of file
302 tx_data = (char*)malloc(3);
377 tx_data = "OK";
303 tx_data = "OK";
No newline at end of file
304 } No newline at end of file
378
No newline at end of file
379 }
No newline at end of file
380 No newline at end of file
381 else if(strcmp(cmd,"ANST") == 0){
305 else if(strcmp(cmd,"ANST") == 0){
No newline at end of file
382 /*n = chequeo_sistema(filename2,rx_data);
No newline at end of file
383 printf("%i\n",n);
No newline at end of file
384 tx_data = File2buffer(filename2, n);*/ No newline at end of file
385 tx_data = chequeo_sistema(filename2,rx_data); No newline at end of file
306 tx_data = chequeo_sistema(filename2,rx_data);
307 printf("%s\n",tx_data);
No newline at end of file
308 }
No newline at end of file
309 else if(strcmp(cmd,"NTST") == 0){
No newline at end of file
310 tx_data = malloc(strlen(parameters.ID) + 1);
No newline at end of file
311 strcpy(tx_data,parameters.ID); No newline at end of file
386 printf("%s\n",tx_data); No newline at end of file
312 printf("%s\n",tx_data);
387 } No newline at end of file
313 }
388 else{ No newline at end of file
314 else{
389 tx_data = (char*)malloc(6); No newline at end of file
315 tx_data = (char*)malloc(6);
390 tx_data = "Error"; No newline at end of file
316 tx_data = "Error";
391 ERROR("procesa_peticion: comando no reconocido"); No newline at end of file
317 ERROR("procesa_peticion: comando no reconocido");
392 } No newline at end of file
318 }
393 No newline at end of file
319
320 tx_len = malloc(7);
No newline at end of file
321 int number = strlen(tx_data);
No newline at end of file
322 intToStr(number, tx_len );
No newline at end of file
323 No newline at end of file
394 strcpy(tx_buffer,header); //3 No newline at end of file
324 strcpy(tx_buffer,header); //3
395 strcat(tx_buffer,TypeOfInstrument); //3 No newline at end of file
325 strcat(tx_buffer,TypeOfInstrument); //3
396 strcat(tx_buffer,parameters.ID); //7 No newline at end of file
326 strcat(tx_buffer,parameters.ID); //7
397 strcat(tx_buffer,iDSource); //7
327 strcat(tx_buffer,iDSource); //7
No newline at end of file
328 strcat(tx_buffer,tx_len); //6 No newline at end of file
398 strcat(tx_buffer,"000033"); //6 No newline at end of file
399 strcat(tx_buffer,cmd); //4
329 strcat(tx_buffer,cmd); //4
No newline at end of file
330 strcat(tx_buffer,tx_data); //? No newline at end of file
400 strcat(tx_buffer,tx_data); //2 No newline at end of file
401 strcat(tx_buffer,crc); //1 No newline at end of file
331 strcat(tx_buffer,crc); //1
402 No newline at end of file
332
403 } No newline at end of file
333 }
404 No newline at end of file
334
405 } No newline at end of file
335 }
406 No newline at end of file
336
407 /* No newline at end of file
337 /*
408 * Esta funciΓ³n genera el archivo de experimento a partir de la trama TCP recibida No newline at end of file
338 * Esta funciΓ³n genera el archivo de experimento a partir de la trama TCP recibida
409 */ No newline at end of file
339 */
410 No newline at end of file
340 void recibe_experimento(char *p_data, char filename[]){
411 void recibe_experimento(char *p_data, char filename[]){ No newline at end of file
341 FILE *fd;
412 FILE *fd; No newline at end of file
342 int i = 0;
413 int i = 0; No newline at end of file
343
414 No newline at end of file
344 while (*p_data != '\n'){
415 while (*p_data != '\n'){ No newline at end of file
345 filename[i] = *p_data;
416 filename[i] = *p_data; No newline at end of file
346 i++;
417 i++; No newline at end of file
347 p_data++;
418 p_data++; No newline at end of file
348 }
419 } No newline at end of file
349 filename[i] = '\0';
420 filename[i] = '\0'; No newline at end of file
350 p_data = p_data - i;
421 p_data = p_data - i; No newline at end of file
351 fd = fopen(filename,"w");
422 fd = fopen(filename,"w"); No newline at end of file
352 fprintf(fd, p_data);
423 fprintf(fd, p_data); No newline at end of file
353 fclose(fd);
424 fclose(fd); No newline at end of file
354 }
425 } No newline at end of file
355
426 No newline at end of file
356 /*
427 /* No newline at end of file
357 * Esta funcion carga un archivo en un buffer que esta ubicado en memoria, luego
428 * Esta funcion carga un archivo en un buffer que esta ubicado en memoria, luego No newline at end of file
358 * este buffer es usado en la funcion "cambia_apuntamiento" para obtener el dato
429 * este buffer es usado en la funcion "cambia_apuntamiento" para obtener el dato No newline at end of file
359 * que sera usado en el cambio de apuntamiento.
430 * que sera usado en el cambio de apuntamiento. No newline at end of file
360 */
431 */ No newline at end of file
361 int carga_experimento(char *nombre_archivo){
432 int carga_experimento(char *nombre_archivo){ No newline at end of file
362
433 No newline at end of file
363 FILE *Archivo_Fd;
434 FILE *Archivo_Fd; No newline at end of file
364
435 No newline at end of file
365 char *cadena = (char *) malloc(25);
436 char *cadena = (char *) malloc(25); No newline at end of file
366
437 No newline at end of file
367 int longitud_cadena;
438 int longitud_cadena; No newline at end of file
368 int num_bytes= 0;
439 int num_bytes= 0; No newline at end of file
369 int num_filas= 0;
440 int num_filas= 0; No newline at end of file
370
441 No newline at end of file
371 Archivo_Fd = fopen(nombre_archivo,"r"); // Se procede a abrir el archivo, segun la ruta especificada
442 Archivo_Fd = fopen(nombre_archivo,"r"); // Se procede a abrir el archivo, segun la ruta especificada No newline at end of file
372 if(!Archivo_Fd){
443 if(!Archivo_Fd){ No newline at end of file
373 ERROR("carga_archivo: No se pudo abrir el archivo!!! --> fopen()\n");
444 ERROR("carga_archivo: No se pudo abrir el archivo!!! --> fopen()\n"); No newline at end of file
374 return -1;
445 return -1; No newline at end of file
375 }else{
446 }else{ No newline at end of file
376
447 No newline at end of file
377 while(!feof(Archivo_Fd)){ // Se procede a calcular la longitud del archivo para separar memoria
448 while(!feof(Archivo_Fd)){ // Se procede a calcular la longitud del archivo para separar memoria No newline at end of file
378 fgets(cadena,20,Archivo_Fd);
449 fgets(cadena,20,Archivo_Fd); No newline at end of file
379 longitud_cadena= strlen(cadena);
450 longitud_cadena= strlen(cadena); No newline at end of file
380 cadena[longitud_cadena-1] = '\0';
451 cadena[longitud_cadena-1] = '\0'; No newline at end of file
381 num_bytes = num_bytes + longitud_cadena;
452 num_bytes = num_bytes + longitud_cadena; No newline at end of file
382 num_filas++;
453 num_filas++; No newline at end of file
383 }
454 } No newline at end of file
384
455 No newline at end of file
385 rewind(Archivo_Fd); // Se reinicia el puntero del archivo
456 rewind(Archivo_Fd); // Se reinicia el puntero del archivo No newline at end of file
386
457 No newline at end of file
387 char *buffer_temporal = (char *) malloc(num_bytes+1); // Se separa espacio de memoria segun
458 char *buffer_temporal = (char *) malloc(num_bytes+1); // Se separa espacio de memoria segun No newline at end of file
388 // la longitud del archivo
459 // la longitud del archivo No newline at end of file
389 fread(buffer_temporal, sizeof(char), num_bytes, Archivo_Fd);
460 fread(buffer_temporal, sizeof(char), num_bytes, Archivo_Fd); No newline at end of file
390
461 No newline at end of file
391 char *puntero= strstr(buffer_temporal,".ab1"); // Se procede a eliminar la cabecera del archivo
462 char *puntero= strstr(buffer_temporal,".ab1"); // Se procede a eliminar la cabecera del archivo No newline at end of file
392 puntero= puntero + 12;
463 puntero= puntero + 12; No newline at end of file
393
464 No newline at end of file
394 buff_experimento = (char *) malloc(7*(num_filas-3)); // num_bytes_fila*(num_filas-3);
465 buff_experimento = (char *) malloc(7*(num_filas-3)); // num_bytes_fila*(num_filas-3); No newline at end of file
395 strncpy(buff_experimento,puntero,7*(num_filas-3)); // Se carga en memoria la informacion del archivo
466 strncpy(buff_experimento,puntero,7*(num_filas-3)); // Se carga en memoria la informacion del archivo No newline at end of file
396
467 No newline at end of file
397 fclose(Archivo_Fd);
468 fclose(Archivo_Fd); No newline at end of file
398
469 No newline at end of file
399 return 1;
470 return 1; No newline at end of file
400 }
471 } No newline at end of file
401 }
472 } No newline at end of file
402
473 No newline at end of file
403 /*
474 /* No newline at end of file
404 * Esta funcion recibe un numero en formato char, el dato se transforma a su equivalente en
475 * Esta funcion recibe un numero en formato char, el dato se transforma a su equivalente en No newline at end of file
405 * un numero entero, que sera usado para sacar un dato del buffer "buff_experimento", esta
476 * un numero entero, que sera usado para sacar un dato del buffer "buff_experimento", esta No newline at end of file
406 * dato es el valor que se enviara al sistema de conmutacion RF para el cambio de apunte a
477 * dato es el valor que se enviara al sistema de conmutacion RF para el cambio de apunte a No newline at end of file
407 * traves del puerto GPIO.
478 * traves del puerto GPIO. No newline at end of file
408 */
479 */ No newline at end of file
409 int cambia_apuntamiento(char *puntero_char){
480 int cambia_apuntamiento(char *puntero_char){ No newline at end of file
410
481 No newline at end of file
411 /*MSB-UP-LSB MSB-DOWN-LSB*/
482 /*MSB-UP-LSB MSB-DOWN-LSB*/ No newline at end of file
412 int desplazamiento[6]={30,28,26,24,22,20}; // Defino los dezplazamientos que se aplicara
483 int desplazamiento[6]={30,28,26,24,22,20}; // Defino los dezplazamientos que se aplicara No newline at end of file
413 // al dato que ingresa para formar el nΓΊmero
484 // al dato que ingresa para formar el nΓΊmero No newline at end of file
414 // entero que se le pasara al puerto GPIO
485 // entero que se le pasara al puerto GPIO No newline at end of file
415 // Estos nΓΊmeros son los pines del puerto GPIO
486 // Estos nΓΊmeros son los pines del puerto GPIO No newline at end of file
416 // que se estan usando para el control
487 // que se estan usando para el control No newline at end of file
417
488 No newline at end of file
418 int puntero= atoi(puntero_char); // Se convierte a entero la direccion del puntero
489 int puntero= atoi(puntero_char); // Se convierte a entero la direccion del puntero No newline at end of file
419
490 No newline at end of file
420 int base= 7*puntero; // base= cantidad_bytes del dato x puntero
491 int base= 7*puntero; // base= cantidad_bytes del dato x puntero No newline at end of file
421 // cantidad de bytes es el numero de bytes que
492 // cantidad de bytes es el numero de bytes que No newline at end of file
422 printf("%s\n",puntero_char); // contiene cada dato, para este caso es 7
493 printf("%s\n",puntero_char); // contiene cada dato, para este caso es 7 No newline at end of file
423 // porque es 6 bits de datos + 1 bit del cambio
494 // porque es 6 bits de datos + 1 bit del cambio No newline at end of file
424 // de linea.
495 // de linea. No newline at end of file
425 char valor_char;
496 char valor_char; No newline at end of file
426 unsigned long valor;
497 unsigned long valor; No newline at end of file
427 unsigned long acumulado_ceros=0;
498 unsigned long acumulado_ceros=0; No newline at end of file
428 unsigned long acumulado_unos=0;
499 unsigned long acumulado_unos=0; No newline at end of file
429
500 No newline at end of file
430 int offset; // Defino offset para el desplazamiento a traves
501 int offset; // Defino offset para el desplazamiento a traves No newline at end of file
431 for(offset=0;offset<6;offset++){ // de cada dato que se obtiene del "buff_experimento"
502 for(offset=0;offset<6;offset++){ // de cada dato que se obtiene del "buff_experimento" No newline at end of file
432
503 No newline at end of file
433 valor_char= buff_experimento[base+offset]; // Obtengo el dato
504 valor_char= buff_experimento[base+offset]; // Obtengo el dato No newline at end of file
434
505 No newline at end of file
435 if (valor_char == '0'){ // Obtengo el nΓΊmero acumulado segun sea un cero o un uno
506 if (valor_char == '0'){ // Obtengo el nΓΊmero acumulado segun sea un cero o un uno No newline at end of file
436 valor= 0;
507 valor= 0; No newline at end of file
437 acumulado_ceros= acumulado_ceros + (1 << desplazamiento[offset]);
508 acumulado_ceros= acumulado_ceros + (1 << desplazamiento[offset]); No newline at end of file
438 }else{
509 }else{ No newline at end of file
439 valor= 1;
510 valor= 1; No newline at end of file
440 acumulado_unos= acumulado_unos + (1 << desplazamiento[offset]);
511 acumulado_unos= acumulado_unos + (1 << desplazamiento[offset]); No newline at end of file
441 }
512 } No newline at end of file
442 }
513 } No newline at end of file
443 pio_out(pioc, maskc_out, acumulado_unos, 1);
514 pio_out(pioc, maskc_out, acumulado_unos, 1); No newline at end of file
444 pio_out(pioc, maskc_out, acumulado_ceros, 0);
515 pio_out(pioc, maskc_out, acumulado_ceros, 0); No newline at end of file
445
516 No newline at end of file
446 return 1;
517 return 1; No newline at end of file
447
518
448 }
No newline at end of file
519 }
No newline at end of file
520
No newline at end of file
521 /*
No newline at end of file
522 * Esta funcion lee "n" veces el estado del APUNTE actual y lo guarda en el
No newline at end of file
523 * archivo Verificacion.
No newline at end of file
524 */
No newline at end of file
525
No newline at end of file
526 int chequeo_sistema2(char *filename, char *numero_muestras){
No newline at end of file
527
No newline at end of file
528 char valor[7];
No newline at end of file
529 int i,cnt;
No newline at end of file
530 unsigned int entradac= 0;
No newline at end of file
531 FILE *fd;
No newline at end of file
532 fd=fopen(filename,"w");
No newline at end of file
533 fprintf(fd,"%s\n","Verificacion");
No newline at end of file
534 fprintf(fd,"%s\n",parameters.ID);
No newline at end of file
535 fprintf(fd,"%s\n","------------");
No newline at end of file
536 cnt=0;
No newline at end of file
537 do
No newline at end of file
538 {
No newline at end of file
539 //Inicializando arreglo
No newline at end of file
540 for(i=0;i<6;i++)
No newline at end of file
541 valor[i]='0';
No newline at end of file
542
No newline at end of file
543 valor[6]='\0';
No newline at end of file
544
No newline at end of file
545 //Lectura de puerto
No newline at end of file
546 entradac= pio_in(piob,maskb_in);
No newline at end of file
547
No newline at end of file
548 //Dandole formato al dato
No newline at end of file
549 if (!(entradac & bit_up_2))
No newline at end of file
550 valor[0] = '1';
No newline at end of file
551 if (!(entradac & bit_up_1))
No newline at end of file
552 valor[1] = '1';
No newline at end of file
553 if (!(entradac & bit_up_0))
No newline at end of file
554 valor[2] = '1';
No newline at end of file
555 if (!(entradac & bit_dow_2))
No newline at end of file
556 valor[3] = '1';
No newline at end of file
557 if (!(entradac & bit_dow_1))
No newline at end of file
558 valor[4] = '1';
No newline at end of file
559 if (!(entradac & bit_dow_0))
No newline at end of file
560 valor[5] = '1';
No newline at end of file
561
No newline at end of file
562 //Escribiendo en archivo
No newline at end of file
563 fprintf(fd,"%s\n",valor);
No newline at end of file
564 cnt=cnt+1;
No newline at end of file
565 usleep(1*1000*1000);
No newline at end of file
566
No newline at end of file
567 }while(cnt < atoi(numero_muestras));
No newline at end of file
568
No newline at end of file
569 fclose(fd);
No newline at end of file
570
No newline at end of file
571 return 7*atoi(numero_muestras) + 26 + 4 + 1; //incluye eof
No newline at end of file
572 }
No newline at end of file
573
No newline at end of file
574 char* File2buffer(char *filename, int n){
No newline at end of file
575 FILE *fd;
No newline at end of file
576 char* tx_data = (char *)malloc(n);
No newline at end of file
577 fd = fopen(filename,"r");
No newline at end of file
578 fread(tx_data, 1, n-1, fd);
No newline at end of file
579 fclose(fd);
No newline at end of file
580 tx_data = tx_data + n - 1;
No newline at end of file
581 *tx_data = '\0';
No newline at end of file
582 tx_data = tx_data - n + 1;
No newline at end of file
583 return tx_data; No newline at end of file
584 } No newline at end of file
449
585 No newline at end of file
450 /*
586 /* No newline at end of file
451 * Esta funcion lee "n" veces el estado del APUNTE actual y reporta
587 * Esta funcion lee "n" veces el estado del APUNTE actual y reporta No newline at end of file
452 * una cadena de Verificacion.
588 * una cadena de Verificacion. No newline at end of file
453 */
589 */ No newline at end of file
454 char* chequeo_sistema(char *filename, char *numero_muestras){
590 char* chequeo_sistema(char *filename, char *numero_muestras){ No newline at end of file
455
591 No newline at end of file
456 int i;
592 int i; No newline at end of file
457 int cnt = 0;
593 int cnt = 0; No newline at end of file
458 unsigned int entradac= 0;
594 unsigned int entradac= 0; No newline at end of file
459
595 No newline at end of file
460 char page0[250];
596 char page0[250]; No newline at end of file
461
597 No newline at end of file
462 strcpy(page0,"Verificacion\n");
598 strcpy(page0,"Verificacion\n"); No newline at end of file
463 strcat(page0,parameters.ID);
599 strcat(page0,parameters.ID); No newline at end of file
464 strcat(page0,"\n------------\n");
600 strcat(page0,"\n------------\n"); No newline at end of file
465
601 No newline at end of file
466 char page1[8];
602 char page1[8]; No newline at end of file
467
603 No newline at end of file
468 do{
604 do{ No newline at end of file
469 //Inicializando arreglo
605 //Inicializando arreglo No newline at end of file
470 for(i=0;i<6;i++)
606 for(i=0;i<6;i++) No newline at end of file
471 page1[i]='0';
607 page1[i]='0'; No newline at end of file
472 page1[6] = '\n';
608 page1[6] = '\n'; No newline at end of file
473 page1[7] = '\0';
609 page1[7] = '\0'; No newline at end of file
474 //Lectura de puerto
610 //Lectura de puerto No newline at end of file
475 entradac= pio_in(piob,maskb_in);
611 entradac= pio_in(piob,maskb_in); No newline at end of file
476 //Dandole formato al dato
612 //Dandole formato al dato No newline at end of file
477 if (!(entradac & bit_up_2))
613 if (!(entradac & bit_up_2)) No newline at end of file
478 page1[0] = '1';
614 page1[0] = '1'; No newline at end of file
479 if (!(entradac & bit_up_1))
615 if (!(entradac & bit_up_1)) No newline at end of file
480 page1[1] = '1';
616 page1[1] = '1'; No newline at end of file
481 if (!(entradac & bit_up_0))
617 if (!(entradac & bit_up_0)) No newline at end of file
482 page1[2] = '1';
618 page1[2] = '1'; No newline at end of file
483 if (!(entradac & bit_dow_2))
619 if (!(entradac & bit_dow_2)) No newline at end of file
484 page1[3] = '1';
620 page1[3] = '1'; No newline at end of file
485 if (!(entradac & bit_dow_1))
621 if (!(entradac & bit_dow_1)) No newline at end of file
486 page1[4] = '1';
622 page1[4] = '1'; No newline at end of file
487 if (!(entradac & bit_dow_0))
623 if (!(entradac & bit_dow_0)) No newline at end of file
488 page1[5] = '1';
624 page1[5] = '1'; No newline at end of file
489
625 No newline at end of file
490 strcat(page0, page1);
626 strcat(page0, page1); No newline at end of file
491 cnt=cnt+1;
627 cnt=cnt+1; No newline at end of file
492 usleep(1*1000*1000);
628 usleep(1*1000*1000); No newline at end of file
493
629 No newline at end of file
494 }while(cnt < atoi(numero_muestras));
630 }while(cnt < atoi(numero_muestras)); No newline at end of file
495
631 No newline at end of file
496 page0[strlen(page0)] = '\0';
632 page0[strlen(page0)] = '\0'; No newline at end of file
497
633 No newline at end of file
498 char *all_pages = malloc(strlen(page0)+1);
634 char *all_pages = malloc(strlen(page0)+1); No newline at end of file
499 strcpy(all_pages, page0);
635 strcpy(all_pages, page0); No newline at end of file
500 return all_pages;
636 return all_pages; No newline at end of file
501 }
637 } No newline at end of file
502
503 /*
No newline at end of file
504 *
No newline at end of file
505 */
No newline at end of file
506 cmp inicializa_modulo(cmp p){ No newline at end of file
638 cmp inicializa_modulo(cmp p){ No newline at end of file
507 FILE *fd = fopen("configuration.txt","r");
639 FILE *fd = fopen("configuration.txt","r"); No newline at end of file
508 fgets(p.ID,20,fd);
640 fgets(p.ID,20,fd); No newline at end of file
509 p.ID[7]='\0';
641 p.ID[7]='\0'; No newline at end of file
510 fgets(p.param2,20,fd);
642 fgets(p.param2,20,fd); No newline at end of file
511 p.param2[10]='\0';
643 p.param2[10]='\0'; No newline at end of file
512 fgets(p.param3,20,fd);
644 fgets(p.param3,20,fd); No newline at end of file
513 p.param3[10]='\0';
645 p.param3[10]='\0'; No newline at end of file
514 fgets(p.param4,20,fd);
646 fgets(p.param4,20,fd); No newline at end of file
515 p.param4[10]='\0';
647 p.param4[10]='\0'; No newline at end of file
516 fclose(fd);
648 fclose(fd); No newline at end of file
517 return p;
649 return p; No newline at end of file
518 }
650 } No newline at end of file
519
520 /*
No newline at end of file
521 *
No newline at end of file
522 */
No newline at end of file
523 void intToStr( int number, char* str )
No newline at end of file
524
No newline at end of file
525 {
No newline at end of file
526 int index = 0;
No newline at end of file
527
No newline at end of file
528 while( number > 0 )
No newline at end of file
529 {
No newline at end of file
530 int digit = number%10;
No newline at end of file
531 str[index++] = digit + '0';
No newline at end of file
532 number /= 10;
No newline at end of file
533 }
No newline at end of file
534 str[index] = '\0';
No newline at end of file
535 //Adding zero to the left
No newline at end of file
536 int n= strlen(str);
No newline at end of file
537 if (n == 1) {
No newline at end of file
538 strcat(str,"00000");
No newline at end of file
539 index = index + 5;
No newline at end of file
540 }else if(n == 2){
No newline at end of file
541 strcat(str,"0000");
No newline at end of file
542 index = index + 4;
No newline at end of file
543 }else if(n == 3){
No newline at end of file
544 strcat(str,"000");
No newline at end of file
545 index = index + 3;
No newline at end of file
546 }else if(n == 4){
No newline at end of file
547 strcat(str,"00");
No newline at end of file
548 index = index + 2;
No newline at end of file
549 }else if(n == 5){
No newline at end of file
550 strcat(str,"0");
No newline at end of file
551 index = index + 1;
No newline at end of file
552 }
No newline at end of file
553 //Now reverse the numbers in the string.
No newline at end of file
554 int position;
No newline at end of file
555 for( position = 0; position <= (index-1)/2; ++position )
No newline at end of file
556 {
No newline at end of file
557 char tmp = str[position];
No newline at end of file
558 str[position] = str[(index-1)-position];
No newline at end of file
559 str[(index-1)-position] = tmp;
No newline at end of file
560 }
No newline at end of file
561 } No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now