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