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