##// END OF EJS Templates
Se corrigió bug de funcion file2buffer. Faltaba '\0' al final de la cadena.
imanay -
r77:78
parent child
Show More
@@ -1,460 +1,459
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
58
No newline at end of file
59 cmp parameters; No newline at end of file
59 No newline at end of file
60 /* No newline at end of file
60 /*
61 * Zona de declaracion de cabeceras. No newline at end of file
61 * Zona de declaracion de cabeceras.
62 */ No newline at end of file
62 */
63 cmp inicializa_modulo(cmp p); No newline at end of file
63 cmp inicializa_modulo(cmp p);
64 int inicializa_ethernet(); No newline at end of file
64 int inicializa_ethernet();
65 int rxData(int, char*); No newline at end of file
65 int rxData(int, char*);
66 void txData(int, char*); No newline at end of file
66 void txData(int, char*);
67 void inicializa_gpio(); No newline at end of file
67 void inicializa_gpio();
68 void procesa_peticion(char *rx_buffer, char *tx_buffer); No newline at end of file
68 void procesa_peticion(char *rx_buffer, char *tx_buffer);
69 int cambia_apuntamiento(char *puntero_char); No newline at end of file
69 int cambia_apuntamiento(char *puntero_char);
70 int carga_experimento(char *nombre_archivo); No newline at end of file
70 int carga_experimento(char *nombre_archivo);
71 int chequeo_sistema(char *filename, char *numero_muestras); No newline at end of file
71 int chequeo_sistema(char *filename, char *numero_muestras);
72 void recibe_experimento(char *data, char filename[]); No newline at end of file
72 void recibe_experimento(char *data, char filename[]);
73 char* File2buffer(char *filename2, int n); No newline at end of file
73 char* File2buffer(char *filename2, int n);
74 No newline at end of file
74
75 /* No newline at end of file
75 /*
76 * No newline at end of file
76 *
77 */ No newline at end of file
77 */
78 int main(){ No newline at end of file
78 int main(){
79 No newline at end of file
79
80 int servSocket; No newline at end of file
80 int servSocket;
81 int clntSocket;
81 int clntSocket;
No newline at end of file
82 No newline at end of file
82 cmp parameters; No newline at end of file
83 No newline at end of file
83
84 char *rx_buffer = (char *) malloc(TAM_BUFFER); No newline at end of file
84 char *rx_buffer = (char *) malloc(TAM_BUFFER);
85 char *tx_buffer = (char *) malloc(TAM_BUFFER); No newline at end of file
85 char *tx_buffer = (char *) malloc(TAM_BUFFER);
86 /* Inicializa parametros del modulo*/ No newline at end of file
86 /* Inicializa parametros del modulo*/
87 parameters = inicializa_modulo(parameters); No newline at end of file
87 parameters = inicializa_modulo(parameters);
88 printf("%s%s%s%s",parameters.ID, parameters.param2, parameters.param3, parameters.param4); No newline at end of file
88 printf("%s%s%s%s",parameters.ID, parameters.param2, parameters.param3, parameters.param4);
89 /* Inicializa red*/ No newline at end of file
89 /* Inicializa red*/
90 servSocket = inicializa_ethernet(); No newline at end of file
90 servSocket = inicializa_ethernet();
91 /* Inicializamos el puerto GPIO del sistema embebido GSBC-9260S */ No newline at end of file
91 /* Inicializamos el puerto GPIO del sistema embebido GSBC-9260S */
92 inicializa_gpio(); No newline at end of file
92 inicializa_gpio();
93 No newline at end of file
93
94 while(1){ No newline at end of file
94 while(1){
95 // Recepción TCP de petición No newline at end of file
95 // Recepción TCP de petición
96 clntSocket = rxData(servSocket, rx_buffer); No newline at end of file
96 clntSocket = rxData(servSocket, rx_buffer);
97 //testpoint No newline at end of file
97 //testpoint
98 printf("rx:%s\n",rx_buffer); No newline at end of file
98 printf("rx:%s\n",rx_buffer);
99 // Procesamiento de la petición No newline at end of file
99 // Procesamiento de la petición
100 procesa_peticion(rx_buffer, tx_buffer); No newline at end of file
100 procesa_peticion(rx_buffer, tx_buffer);
101 //testpoint No newline at end of file
101 //testpoint
102 printf("tx:%s\n",tx_buffer); No newline at end of file
102 printf("tx:%s\n",tx_buffer);
103 // Respuesta del modulo de control No newline at end of file
103 // Respuesta del modulo de control
104 txData(clntSocket, tx_buffer); No newline at end of file
104 txData(clntSocket, tx_buffer);
105 No newline at end of file
105
106 } No newline at end of file
106 }
107 } No newline at end of file
107 }
108 No newline at end of file
108
109 No newline at end of file
109
110 int inicializa_ethernet(){ No newline at end of file
110 int inicializa_ethernet(){
111 No newline at end of file
111
112 struct sockaddr_in inf_servidor; No newline at end of file
112 struct sockaddr_in inf_servidor;
113 No newline at end of file
113
114 int servSocket; No newline at end of file
114 int servSocket;
115 No newline at end of file
115
116 int resultado; No newline at end of file
116 int resultado;
117 No newline at end of file
117
118 /* Haciendo la estructura local*/ No newline at end of file
118 /* Haciendo la estructura local*/
119 memset(&inf_servidor, 0, sizeof(inf_servidor)); No newline at end of file
119 memset(&inf_servidor, 0, sizeof(inf_servidor));
120 inf_servidor.sin_family= AF_INET; No newline at end of file
120 inf_servidor.sin_family= AF_INET;
121 inf_servidor.sin_port= htons(PUERTO_SERVIDOR); No newline at end of file
121 inf_servidor.sin_port= htons(PUERTO_SERVIDOR);
122 inf_servidor.sin_addr.s_addr= INADDR_ANY; No newline at end of file
122 inf_servidor.sin_addr.s_addr= INADDR_ANY;
123 No newline at end of file
123
124 /* Se establece el socket */ No newline at end of file
124 /* Se establece el socket */
125 servSocket = socket(AF_INET,SOCK_STREAM, IPPROTO_TCP); No newline at end of file
125 servSocket = socket(AF_INET,SOCK_STREAM, IPPROTO_TCP);
126 if (servSocket == -1){ No newline at end of file
126 if (servSocket == -1){
127 ERROR_FATAL("No se establecio correctamente el socket: socket()\n"); No newline at end of file
127 ERROR_FATAL("No se establecio correctamente el socket: socket()\n");
128 exit(-1); No newline at end of file
128 exit(-1);
129 } No newline at end of file
129 }
130 No newline at end of file
130
131 /* Se asocia el socket a un puerto y una IP */ No newline at end of file
131 /* Se asocia el socket a un puerto y una IP */
132 resultado = bind(servSocket,(struct sockaddr *)&inf_servidor,sizeof(inf_servidor)); No newline at end of file
132 resultado = bind(servSocket,(struct sockaddr *)&inf_servidor,sizeof(inf_servidor));
133 if (resultado== -1){ No newline at end of file
133 if (resultado== -1){
134 ERROR_FATAL("No se establecio correctamente el socket: bind()\n"); No newline at end of file
134 ERROR_FATAL("No se establecio correctamente el socket: bind()\n");
135 exit(-1); No newline at end of file
135 exit(-1);
136 } No newline at end of file
136 }
137 No newline at end of file
137
138 if (listen(servSocket, MAXPENDING) < 0){ No newline at end of file
138 if (listen(servSocket, MAXPENDING) < 0){
139 printf("listen() failed\n"); No newline at end of file
139 printf("listen() failed\n");
140 exit(-1); No newline at end of file
140 exit(-1);
141 } No newline at end of file
141 }
142 No newline at end of file
142
143 return servSocket; No newline at end of file
143 return servSocket;
144 No newline at end of file
144
145 } No newline at end of file
145 }
146 No newline at end of file
146
147 int rxData(int servSocket, char* rx_buffer){ No newline at end of file
147 int rxData(int servSocket, char* rx_buffer){
148 No newline at end of file
148
149 int clntSocket; No newline at end of file
149 int clntSocket;
150 struct sockaddr_in inf_cliente; No newline at end of file
150 struct sockaddr_in inf_cliente;
151 int numbytes_recibidos; No newline at end of file
151 int numbytes_recibidos;
152 unsigned int inf_client_Len; No newline at end of file
152 unsigned int inf_client_Len;
153 No newline at end of file
153
154 printf("\nEsperando solicitud de cliente...\n"); No newline at end of file
154 printf("\nEsperando solicitud de cliente...\n");
155 No newline at end of file
155
156 /* Set the size of the in-out parameter */ No newline at end of file
156 /* Set the size of the in-out parameter */
157 inf_client_Len = sizeof(inf_cliente); No newline at end of file
157 inf_client_Len = sizeof(inf_cliente);
158 /* Se espera hasta que un cliente se conecte */ No newline at end of file
158 /* Se espera hasta que un cliente se conecte */
159 if ((clntSocket = accept(servSocket, (struct sockaddr *) &inf_cliente, No newline at end of file
159 if ((clntSocket = accept(servSocket, (struct sockaddr *) &inf_cliente,
160 &inf_client_Len)) < 0) No newline at end of file
160 &inf_client_Len)) < 0)
161 printf("accept() failed\n"); No newline at end of file
161 printf("accept() failed\n");
162 No newline at end of file
162
163 if ((numbytes_recibidos = recv(clntSocket, rx_buffer, TAM_BUFFER, 0)) < 0) No newline at end of file
163 if ((numbytes_recibidos = recv(clntSocket, rx_buffer, TAM_BUFFER, 0)) < 0)
164 printf("recv() failed\n"); No newline at end of file
164 printf("recv() failed\n");
165 No newline at end of file
165
166 /* Se procede a procesar los datos recibidos */ No newline at end of file
166 /* Se procede a procesar los datos recibidos */
167 rx_buffer[numbytes_recibidos]= '\0'; No newline at end of file
167 rx_buffer[numbytes_recibidos]= '\0';
168 No newline at end of file
168
169 return clntSocket; No newline at end of file
169 return clntSocket;
170 } No newline at end of file
170 }
171 No newline at end of file
171
172 void txData(int clntSocket, char* data){ No newline at end of file
172 void txData(int clntSocket, char* data){
173 No newline at end of file
173
174 /* Echo message back to client */ No newline at end of file
174 /* Echo message back to client */
175 if (send(clntSocket, data, strlen(data), 0) != strlen(data)) No newline at end of file
175 if (send(clntSocket, data, strlen(data), 0) != strlen(data))
176 printf("send() failed\n"); No newline at end of file
176 printf("send() failed\n");
177 No newline at end of file
177
178 close(clntSocket); /* Close client socket */ No newline at end of file
178 close(clntSocket); /* Close client socket */
179 } No newline at end of file
179 }
180 /* No newline at end of file
180 /*
181 * Esta funcion incializa el puerto GPIO No newline at end of file
181 * Esta funcion incializa el puerto GPIO
182 */ No newline at end of file
182 */
183 void inicializa_gpio(){ No newline at end of file
183 void inicializa_gpio(){
184 No newline at end of file
184
185 // Configuracion de los pines de APUNTE No newline at end of file
185 // Configuracion de los pines de APUNTE
186 pioc = pio_map(PIOC_BASE); No newline at end of file
186 pioc = pio_map(PIOC_BASE);
187 pio_enable(pioc, maskc_out); No newline at end of file
187 pio_enable(pioc, maskc_out);
188 pio_disable_irq(pioc, maskc_out); No newline at end of file
188 pio_disable_irq(pioc, maskc_out);
189 pio_disable_multiple_driver(pioc, maskc_out); No newline at end of file
189 pio_disable_multiple_driver(pioc, maskc_out);
190 pio_disable_pull_ups(pioc, maskc_out); No newline at end of file
190 pio_disable_pull_ups(pioc, maskc_out);
191 pio_synchronous_data_output(pioc, maskc_out); No newline at end of file
191 pio_synchronous_data_output(pioc, maskc_out);
192 pio_output_enable(pioc, maskc_out); No newline at end of file
192 pio_output_enable(pioc, maskc_out);
193 No newline at end of file
193
194 // Configuracion de los pines de VERIFICACION No newline at end of file
194 // Configuracion de los pines de VERIFICACION
195 piob = pio_map(PIOB_BASE); No newline at end of file
195 piob = pio_map(PIOB_BASE);
196 pio_enable(piob, maskb_in); No newline at end of file
196 pio_enable(piob, maskb_in);
197 pio_disable_irq(piob, maskb_in); No newline at end of file
197 pio_disable_irq(piob, maskb_in);
198 pio_disable_multiple_driver(piob, maskb_in); No newline at end of file
198 pio_disable_multiple_driver(piob, maskb_in);
199 pio_disable_pull_ups(piob, maskb_in); No newline at end of file
199 pio_disable_pull_ups(piob, maskb_in);
200 pio_input_enable(piob, maskb_in); No newline at end of file
200 pio_input_enable(piob, maskb_in);
201 No newline at end of file
201
202 } No newline at end of file
202 }
203 No newline at end of file
203
204 /* No newline at end of file
204 /*
205 * Esta funcion procesa el mensaje de peticion y genera respuesta No newline at end of file
205 * Esta funcion procesa el mensaje de peticion y genera respuesta
206 */ No newline at end of file
206 */
207 void procesa_peticion(char *rx_buffer, char *tx_buffer){ No newline at end of file
207 void procesa_peticion(char *rx_buffer, char *tx_buffer){
208 int n = 0; No newline at end of file
208 int n = 0;
209 char filename1[50]; No newline at end of file
209 char filename1[50];
210 char filename2[] = "verificacion.txt"; No newline at end of file
210 char filename2[] = "verificacion.txt";
211 char *tx_data = NULL; No newline at end of file
211 char *tx_data = NULL;
212 char *header = strtok(rx_buffer, ":"); No newline at end of file
212 char *header = strtok(rx_buffer, ":");
213 char *TypeOfInstrument = strtok(NULL, ":"); No newline at end of file
213 char *TypeOfInstrument = strtok(NULL, ":");
214 char *iDSource = strtok(NULL, ":"); No newline at end of file
214 char *iDSource = strtok(NULL, ":");
215 char *iDDestino = strtok(NULL, ":"); No newline at end of file
215 char *iDDestino = strtok(NULL, ":");
216 char *len = strtok(NULL, ":"); No newline at end of file
216 char *len = strtok(NULL, ":");
217 char *cmd = strtok(NULL, ":"); No newline at end of file
217 char *cmd = strtok(NULL, ":");
218 char *rx_data = strtok(NULL, ":"); No newline at end of file
218 char *rx_data = strtok(NULL, ":");
219 char *crc = strtok(NULL, ":"); No newline at end of file
219 char *crc = strtok(NULL, ":");
220 No newline at end of file
220
221 if ((cmd == NULL) || (rx_data == NULL)){ No newline at end of file
221 if ((cmd == NULL) || (rx_data == NULL)){
222 ERROR("procesarPeticion: formato de mensaje incorrecto"); No newline at end of file
222 ERROR("procesarPeticion: formato de mensaje incorrecto");
223 } No newline at end of file
223 }
224 else{ No newline at end of file
224 else{
225 if(strcmp(cmd,"SNDF") == 0){ No newline at end of file
225 if(strcmp(cmd,"SNDF") == 0){
226 recibe_experimento(rx_data,filename1); No newline at end of file
226 recibe_experimento(rx_data,filename1);
227 carga_experimento(filename1); No newline at end of file
227 carga_experimento(filename1);
228 cambia_apuntamiento("0"); No newline at end of file
228 cambia_apuntamiento("0");
229 tx_data = (char*)malloc(3); No newline at end of file
229 tx_data = (char*)malloc(3);
230 tx_data = "OK"; No newline at end of file
230 tx_data = "OK";
231 } No newline at end of file
231 }
232 else if(strcmp(cmd,"CHGB") == 0){
232 else if(strcmp(cmd,"CHGB") == 0){
No newline at end of file
233 cambia_apuntamiento(rx_data); No newline at end of file
233 //cambia_apuntamiento(rx_data);
No newline at end of file
234 printf("%s\n",rx_data);
No newline at end of file
235 //cambia_apuntamiento(rx_data);
No newline at end of file
236 cambia_apuntamiento("1"); No newline at end of file
237 tx_data = (char*)malloc(3); No newline at end of file
234 tx_data = (char*)malloc(3);
238 tx_data = "OK"; No newline at end of file
235 tx_data = "OK";
239 No newline at end of file
236
240 } No newline at end of file
237 }
241 No newline at end of file
238
242 else if(strcmp(cmd,"ANST") == 0){ No newline at end of file
239 else if(strcmp(cmd,"ANST") == 0){
243 n = chequeo_sistema(filename2,rx_data); No newline at end of file
240 n = chequeo_sistema(filename2,rx_data);
244 printf("%i\n",n); No newline at end of file
241 printf("%i\n",n);
245 tx_data = File2buffer(filename2, n); No newline at end of file
242 tx_data = File2buffer(filename2, n);
246 } No newline at end of file
243 }
247 else{ No newline at end of file
244 else{
248 tx_data = (char*)malloc(6); No newline at end of file
245 tx_data = (char*)malloc(6);
249 tx_data = "Error"; No newline at end of file
246 tx_data = "Error";
250 ERROR("procesa_peticion: comando no reconocido"); No newline at end of file
247 ERROR("procesa_peticion: comando no reconocido");
251 } No newline at end of file
248 }
252 No newline at end of file
249
253 strcpy(tx_buffer,header); No newline at end of file
250 strcpy(tx_buffer,header);
254 strcat(tx_buffer,":"); No newline at end of file
251 strcat(tx_buffer,":");
255 strcat(tx_buffer,TypeOfInstrument); No newline at end of file
252 strcat(tx_buffer,TypeOfInstrument);
256 strcat(tx_buffer,":"); No newline at end of file
253 strcat(tx_buffer,":");
257 strcat(tx_buffer,iDDestino); No newline at end of file
254 strcat(tx_buffer,iDDestino);
258 strcat(tx_buffer,":"); No newline at end of file
255 strcat(tx_buffer,":");
259 strcat(tx_buffer,iDSource); No newline at end of file
256 strcat(tx_buffer,iDSource);
260 strcat(tx_buffer,":"); No newline at end of file
257 strcat(tx_buffer,":");
261 strcat(tx_buffer,len); No newline at end of file
258 strcat(tx_buffer,len);
262 strcat(tx_buffer,":"); No newline at end of file
259 strcat(tx_buffer,":");
263 strcat(tx_buffer,cmd); No newline at end of file
260 strcat(tx_buffer,cmd);
264 strcat(tx_buffer,":"); No newline at end of file
261 strcat(tx_buffer,":");
265 strcat(tx_buffer,tx_data); No newline at end of file
262 strcat(tx_buffer,tx_data);
266 strcat(tx_buffer,":"); No newline at end of file
263 strcat(tx_buffer,":");
267 strcat(tx_buffer,crc); No newline at end of file
264 strcat(tx_buffer,crc);
265 strcat(tx_buffer,":");
No newline at end of file
266 strcat(tx_buffer,"quit"); No newline at end of file
268 No newline at end of file
267
269 } No newline at end of file
268 }
270 No newline at end of file
269
271 } No newline at end of file
270 }
272 No newline at end of file
271
273 /* No newline at end of file
272 /*
274 * Esta función genera el archivo de experimento a partir de la trama TCP recibida No newline at end of file
273 * Esta función genera el archivo de experimento a partir de la trama TCP recibida
275 */ No newline at end of file
274 */
276 No newline at end of file
275
277 void recibe_experimento(char *p_data, char filename[]){ No newline at end of file
276 void recibe_experimento(char *p_data, char filename[]){
278 FILE *fd; No newline at end of file
277 FILE *fd;
279 int i = 0; No newline at end of file
278 int i = 0;
280 No newline at end of file
279
281 while (*p_data != '\n'){ No newline at end of file
280 while (*p_data != '\n'){
282 filename[i] = *p_data; No newline at end of file
281 filename[i] = *p_data;
283 i++; No newline at end of file
282 i++;
284 p_data++; No newline at end of file
283 p_data++;
285 } No newline at end of file
284 }
286 filename[i] = '\0'; No newline at end of file
285 filename[i] = '\0';
287 p_data = p_data - i; No newline at end of file
286 p_data = p_data - i;
288 fd = fopen(filename,"w"); No newline at end of file
287 fd = fopen(filename,"w");
289 fprintf(fd, p_data); No newline at end of file
288 fprintf(fd, p_data);
290 fclose(fd); No newline at end of file
289 fclose(fd);
291 } No newline at end of file
290 }
292 No newline at end of file
291
293 /* No newline at end of file
292 /*
294 * Esta funcion carga un archivo en un buffer que esta ubicado en memoria, luego No newline at end of file
293 * Esta funcion carga un archivo en un buffer que esta ubicado en memoria, luego
295 * este buffer es usado en la funcion "cambia_apuntamiento" para obtener el dato No newline at end of file
294 * este buffer es usado en la funcion "cambia_apuntamiento" para obtener el dato
296 * que sera usado en el cambio de apuntamiento. No newline at end of file
295 * que sera usado en el cambio de apuntamiento.
297 */ No newline at end of file
296 */
298 int carga_experimento(char *nombre_archivo){ No newline at end of file
297 int carga_experimento(char *nombre_archivo){
299 No newline at end of file
298
300 FILE *Archivo_Fd; No newline at end of file
299 FILE *Archivo_Fd;
301 No newline at end of file
300
302 char *cadena = (char *) malloc(25); No newline at end of file
301 char *cadena = (char *) malloc(25);
303 No newline at end of file
302
304 int longitud_cadena; No newline at end of file
303 int longitud_cadena;
305 int num_bytes= 0; No newline at end of file
304 int num_bytes= 0;
306 int num_filas= 0; No newline at end of file
305 int num_filas= 0;
307 No newline at end of file
306
308 Archivo_Fd = fopen(nombre_archivo,"r"); // Se procede a abrir el archivo, segun la ruta especificada No newline at end of file
307 Archivo_Fd = fopen(nombre_archivo,"r"); // Se procede a abrir el archivo, segun la ruta especificada
309 if(!Archivo_Fd){ No newline at end of file
308 if(!Archivo_Fd){
310 ERROR("carga_archivo: No se pudo abrir el archivo!!! --> fopen()\n"); No newline at end of file
309 ERROR("carga_archivo: No se pudo abrir el archivo!!! --> fopen()\n");
311 return -1; No newline at end of file
310 return -1;
312 }else{ No newline at end of file
311 }else{
313 No newline at end of file
312
314 while(!feof(Archivo_Fd)){ // Se procede a calcular la longitud del archivo para separar memoria No newline at end of file
313 while(!feof(Archivo_Fd)){ // Se procede a calcular la longitud del archivo para separar memoria
315 fgets(cadena,20,Archivo_Fd); No newline at end of file
314 fgets(cadena,20,Archivo_Fd);
316 longitud_cadena= strlen(cadena); No newline at end of file
315 longitud_cadena= strlen(cadena);
317 cadena[longitud_cadena-1] = '\0'; No newline at end of file
316 cadena[longitud_cadena-1] = '\0';
318 num_bytes = num_bytes + longitud_cadena; No newline at end of file
317 num_bytes = num_bytes + longitud_cadena;
319 num_filas++; No newline at end of file
318 num_filas++;
320 } No newline at end of file
319 }
321 No newline at end of file
320
322 rewind(Archivo_Fd); // Se reinicia el puntero del archivo No newline at end of file
321 rewind(Archivo_Fd); // Se reinicia el puntero del archivo
323 No newline at end of file
322
324 char *buffer_temporal = (char *) malloc(num_bytes+1); // Se separa espacio de memoria segun No newline at end of file
323 char *buffer_temporal = (char *) malloc(num_bytes+1); // Se separa espacio de memoria segun
325 // la longitud del archivo No newline at end of file
324 // la longitud del archivo
326 fread(buffer_temporal, sizeof(char), num_bytes, Archivo_Fd); No newline at end of file
325 fread(buffer_temporal, sizeof(char), num_bytes, Archivo_Fd);
327
326
No newline at end of file
327 char *puntero= strstr(buffer_temporal,".ab1"); // Se procede a eliminar la cabecera del archivo No newline at end of file
328 char *puntero= strstr(buffer_temporal,".abs"); // Se procede a eliminar la cabecera del archivo No newline at end of file
329 puntero= puntero + 12; No newline at end of file
328 puntero= puntero + 12;
330 No newline at end of file
329
331 buff_experimento = (char *) malloc(7*(num_filas-3)); // num_bytes_fila*(num_filas-3); No newline at end of file
330 buff_experimento = (char *) malloc(7*(num_filas-3)); // num_bytes_fila*(num_filas-3);
332 strncpy(buff_experimento,puntero,7*(num_filas-3)); // Se carga en memoria la informacion del archivo No newline at end of file
331 strncpy(buff_experimento,puntero,7*(num_filas-3)); // Se carga en memoria la informacion del archivo
333 No newline at end of file
332
334 fclose(Archivo_Fd); No newline at end of file
333 fclose(Archivo_Fd);
335 No newline at end of file
334
336 return 1; No newline at end of file
335 return 1;
337 } No newline at end of file
336 }
338 } No newline at end of file
337 }
339 No newline at end of file
338
340 /* No newline at end of file
339 /*
341 * Esta funcion recibe un numero en formato char, el dato se transforma a su equivalente en No newline at end of file
340 * Esta funcion recibe un numero en formato char, el dato se transforma a su equivalente en
342 * un numero entero, que sera usado para sacar un dato del buffer "buff_experimento", esta No newline at end of file
341 * un numero entero, que sera usado para sacar un dato del buffer "buff_experimento", esta
343 * dato es el valor que se enviara al sistema de conmutacion RF para el cambio de apunte a No newline at end of file
342 * dato es el valor que se enviara al sistema de conmutacion RF para el cambio de apunte a
344 * traves del puerto GPIO. No newline at end of file
343 * traves del puerto GPIO.
345 */ No newline at end of file
344 */
346 int cambia_apuntamiento(char *puntero_char){ No newline at end of file
345 int cambia_apuntamiento(char *puntero_char){
347 No newline at end of file
346
348 /*MSB-UP-LSB MSB-DOWN-LSB*/ No newline at end of file
347 /*MSB-UP-LSB MSB-DOWN-LSB*/
349 int desplazamiento[6]={30,28,26,24,22,20}; // Defino los dezplazamientos que se aplicara No newline at end of file
348 int desplazamiento[6]={30,28,26,24,22,20}; // Defino los dezplazamientos que se aplicara
350 // al dato que ingresa para formar el número No newline at end of file
349 // al dato que ingresa para formar el número
351 // entero que se le pasara al puerto GPIO No newline at end of file
350 // entero que se le pasara al puerto GPIO
352 // Estos números son los pines del puerto GPIO No newline at end of file
351 // Estos números son los pines del puerto GPIO
353 // que se estan usando para el control No newline at end of file
352 // que se estan usando para el control
354 No newline at end of file
353
355 int puntero= atoi(puntero_char); // Se convierte a entero la direccion del puntero No newline at end of file
354 int puntero= atoi(puntero_char); // Se convierte a entero la direccion del puntero
356 No newline at end of file
355
357 int base= 7*puntero; // base= cantidad_bytes del dato x puntero No newline at end of file
356 int base= 7*puntero; // base= cantidad_bytes del dato x puntero
358 // cantidad de bytes es el numero de bytes que
357 // cantidad de bytes es el numero de bytes que
No newline at end of file
358 printf("%s\n",puntero_char); // contiene cada dato, para este caso es 7 No newline at end of file
359 printf("%s\n%i\n",puntero_char,puntero); // contiene cada dato, para este caso es 7 No newline at end of file
360 // porque es 6 bits de datos + 1 bit del cambio No newline at end of file
359 // porque es 6 bits de datos + 1 bit del cambio
361 // de linea. No newline at end of file
360 // de linea.
362 char valor_char; No newline at end of file
361 char valor_char;
363 unsigned long valor; No newline at end of file
362 unsigned long valor;
364 unsigned long acumulado_ceros=0; No newline at end of file
363 unsigned long acumulado_ceros=0;
365 unsigned long acumulado_unos=0; No newline at end of file
364 unsigned long acumulado_unos=0;
366 No newline at end of file
365
367 int offset; // Defino offset para el desplazamiento a traves No newline at end of file
366 int offset; // Defino offset para el desplazamiento a traves
368 for(offset=0;offset<6;offset++){ // de cada dato que se obtiene del "buff_experimento"
367 for(offset=0;offset<6;offset++){ // de cada dato que se obtiene del "buff_experimento"
No newline at end of file
368 No newline at end of file
369 printf("tp1\n");
No newline at end of file
370 printf("%i\n",base+offset); No newline at end of file
371 valor_char= buff_experimento[base+offset]; // Obtengo el dato No newline at end of file
369 valor_char= buff_experimento[base+offset]; // Obtengo el dato
372 No newline at end of file
370
373 if (valor_char == '0'){ // Obtengo el número acumulado segun sea un cero o un uno No newline at end of file
371 if (valor_char == '0'){ // Obtengo el número acumulado segun sea un cero o un uno
374 valor= 0; No newline at end of file
372 valor= 0;
375 acumulado_ceros= acumulado_ceros + (1 << desplazamiento[offset]); No newline at end of file
373 acumulado_ceros= acumulado_ceros + (1 << desplazamiento[offset]);
376 }else{ No newline at end of file
374 }else{
377 valor= 1; No newline at end of file
375 valor= 1;
378 acumulado_unos= acumulado_unos + (1 << desplazamiento[offset]); No newline at end of file
376 acumulado_unos= acumulado_unos + (1 << desplazamiento[offset]);
379 } No newline at end of file
377 }
380 }
378 }
No newline at end of file
381 printf("tp2\n"); No newline at end of file
382 pio_out(pioc, maskc_out, acumulado_unos, 1);
379 pio_out(pioc, maskc_out, acumulado_unos, 1);
No newline at end of file
383 printf("tp3\n"); No newline at end of file
384 pio_out(pioc, maskc_out, acumulado_ceros, 0);
380 pio_out(pioc, maskc_out, acumulado_ceros, 0);
No newline at end of file
385 printf("tp4\n"); No newline at end of file
386 No newline at end of file
381
387 return 1; No newline at end of file
382 return 1;
388 No newline at end of file
383
389 } No newline at end of file
384 }
390 No newline at end of file
385
391 /* No newline at end of file
386 /*
392 * Esta funcion lee "n" veces el estado del APUNTE actual y lo guarda en el No newline at end of file
387 * Esta funcion lee "n" veces el estado del APUNTE actual y lo guarda en el
393 * archivo Verificacion. No newline at end of file
388 * archivo Verificacion.
394 */ No newline at end of file
389 */
395 No newline at end of file
390
396 int chequeo_sistema(char *filename, char *numero_muestras){ No newline at end of file
391 int chequeo_sistema(char *filename, char *numero_muestras){
397 No newline at end of file
392
398 char valor[7]; No newline at end of file
393 char valor[7];
399 int i,cnt; No newline at end of file
394 int i,cnt;
400 unsigned int entradac= 0; No newline at end of file
395 unsigned int entradac= 0;
401 FILE *fd; No newline at end of file
396 FILE *fd;
402 fd=fopen(filename,"w"); No newline at end of file
397 fd=fopen(filename,"w");
403 fprintf(fd,"%s\n","Verificacion"); No newline at end of file
398 fprintf(fd,"%s\n","Verificacion");
399 fprintf(fd,"%s",parameters.ID); No newline at end of file
404 fprintf(fd,"%s\n","------------"); No newline at end of file
400 fprintf(fd,"%s\n","------------");
405 cnt=0; No newline at end of file
401 cnt=0;
406 do No newline at end of file
402 do
407 { No newline at end of file
403 {
408 //Inicializando arreglo No newline at end of file
404 //Inicializando arreglo
409 for(i=0;i<6;i++) No newline at end of file
405 for(i=0;i<6;i++)
410 valor[i]='0'; No newline at end of file
406 valor[i]='0';
411 No newline at end of file
407
412 valor[6]='\0'; No newline at end of file
408 valor[6]='\0';
413 No newline at end of file
409
414 //Lectura de puerto No newline at end of file
410 //Lectura de puerto
415 entradac= pio_in(piob,maskb_in); No newline at end of file
411 entradac= pio_in(piob,maskb_in);
416 No newline at end of file
412
417 //Dandole formato al dato No newline at end of file
413 //Dandole formato al dato
418 if (!(entradac & bit_up_2)) No newline at end of file
414 if (!(entradac & bit_up_2))
419 valor[0] = '1'; No newline at end of file
415 valor[0] = '1';
420 if (!(entradac & bit_up_1)) No newline at end of file
416 if (!(entradac & bit_up_1))
421 valor[1] = '1'; No newline at end of file
417 valor[1] = '1';
422 if (!(entradac & bit_up_0)) No newline at end of file
418 if (!(entradac & bit_up_0))
423 valor[2] = '1'; No newline at end of file
419 valor[2] = '1';
424 if (!(entradac & bit_dow_2)) No newline at end of file
420 if (!(entradac & bit_dow_2))
425 valor[3] = '1'; No newline at end of file
421 valor[3] = '1';
426 if (!(entradac & bit_dow_1)) No newline at end of file
422 if (!(entradac & bit_dow_1))
427 valor[4] = '1'; No newline at end of file
423 valor[4] = '1';
428 if (!(entradac & bit_dow_0)) No newline at end of file
424 if (!(entradac & bit_dow_0))
429 valor[5] = '1'; No newline at end of file
425 valor[5] = '1';
430 No newline at end of file
426
431 //Escribiendo en archivo No newline at end of file
427 //Escribiendo en archivo
432 fprintf(fd,"%s\n",valor); No newline at end of file
428 fprintf(fd,"%s\n",valor);
433 cnt=cnt+1; No newline at end of file
429 cnt=cnt+1;
434 usleep(1*1000*1000); No newline at end of file
430 usleep(1*1000*1000);
435 No newline at end of file
431
436 }while(cnt < atoi(numero_muestras)); No newline at end of file
432 }while(cnt < atoi(numero_muestras));
437 No newline at end of file
433
438 fclose(fd); No newline at end of file
434 fclose(fd);
439
435
No newline at end of file
436 return 7*atoi(numero_muestras) + 26 + 4 + 1; //incluye eof No newline at end of file
440 return 7*atoi(numero_muestras) + 26 + 1; //incluye eof No newline at end of file
441 } No newline at end of file
437 }
442 No newline at end of file
438
443 char* File2buffer(char *filename, int n){ No newline at end of file
439 char* File2buffer(char *filename, int n){
444 FILE *fd; No newline at end of file
440 FILE *fd;
445 char* tx_data = (char *)malloc(n); No newline at end of file
441 char* tx_data = (char *)malloc(n);
446 fd = fopen(filename,"r");
442 fd = fopen(filename,"r");
No newline at end of file
443 fread(tx_data, 1, n-1, fd); No newline at end of file
447 fread(tx_data, 1, n, fd); No newline at end of file
448 fclose(fd); No newline at end of file
444 fclose(fd);
445 tx_data = tx_data + n - 1;
No newline at end of file
446 *tx_data = '\0';
No newline at end of file
447 tx_data = tx_data - n + 1; No newline at end of file
449 return tx_data; No newline at end of file
448 return tx_data;
450 } No newline at end of file
449 }
451 No newline at end of file
450
452 cmp inicializa_modulo(cmp p){ No newline at end of file
451 cmp inicializa_modulo(cmp p){
453 FILE *fd = fopen("configuration.txt","r"); No newline at end of file
452 FILE *fd = fopen("configuration.txt","r");
454 fgets(p.ID,20,fd); No newline at end of file
453 fgets(p.ID,20,fd);
455 fgets(p.param2,20,fd); No newline at end of file
454 fgets(p.param2,20,fd);
456 fgets(p.param3,20,fd); No newline at end of file
455 fgets(p.param3,20,fd);
457 fgets(p.param4,20,fd); No newline at end of file
456 fgets(p.param4,20,fd);
458 fclose(fd); No newline at end of file
457 fclose(fd);
459 return p; No newline at end of file
458 return p;
460 } No newline at end of file
459 }
General Comments 0
You need to be logged in to leave comments. Login now