@@ -1,1106 +1,1140 | |||||
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 | * Modified by Iván Manay since Nov 2012 No newline at end of file |
|
12 | * Modified by Iván Manay since Nov 2012 | |
13 | * -From UDP to TCP. No newline at end of file |
|
13 | * -From UDP to TCP. | |
14 | * -Use of a frame for TCP communications with the central control module. No newline at end of file |
|
14 | * -Use of a frame for TCP communications with the central control module. | |
15 | */ No newline at end of file |
|
15 | */ | |
16 | No newline at end of file |
|
16 | ||
17 | #include <stdio.h> No newline at end of file |
|
17 | #include <stdio.h> | |
18 | #include <stdlib.h> No newline at end of file |
|
18 | #include <stdlib.h> | |
19 | #include <string.h> No newline at end of file |
|
19 | #include <string.h> | |
20 | #include <unistd.h> No newline at end of file |
|
20 | #include <unistd.h> | |
21 | #include <errno.h> No newline at end of file |
|
21 | #include <errno.h> | |
22 | No newline at end of file |
|
22 | ||
23 | #include <sys/types.h> No newline at end of file |
|
23 | #include <sys/types.h> | |
24 | #include <sys/socket.h> No newline at end of file |
|
24 | #include <sys/socket.h> | |
25 | #include <netinet/in.h> No newline at end of file |
|
25 | #include <netinet/in.h> | |
26 | #include <arpa/inet.h> No newline at end of file |
|
26 | #include <arpa/inet.h> | |
27 | #include <netdb.h> No newline at end of file |
|
27 | #include <netdb.h> | |
28 | #include <time.h> No newline at end of file |
|
28 | #include <time.h> | |
29 | #include <math.h> No newline at end of file |
|
29 | #include <math.h> | |
30 | No newline at end of file |
|
30 | ||
31 | #include "./Librerias/at91gpio.h" No newline at end of file |
|
31 | #include "./Librerias/at91gpio.h" | |
32 | //#include "./Librerias/Mensajes.h" No newline at end of file |
|
32 | //#include "./Librerias/Mensajes.h" | |
33 | #include "./Librerias/at91adc.h" No newline at end of file |
|
33 | #include "./Librerias/at91adc.h" | |
34 | //clock No newline at end of file |
|
34 | //clock | |
35 | #include "./Librerias/at91sysclock.h" No newline at end of file |
|
35 | #include "./Librerias/at91sysclock.h" | |
36 | No newline at end of file |
|
36 | ||
37 | #define PUERTO_SERVIDOR 5500 No newline at end of file |
|
37 | #define PUERTO_SERVIDOR 5500 | |
38 | #define TAM_BUFFER 1024 No newline at end of file |
|
38 | #define TAM_BUFFER 1024 | |
39 | No newline at end of file |
|
39 | ||
40 | #define maskc_out_beam PC30+PC28+PC26+PC24+PC22+PC20 //MSB-UP-LSB MSB-DOWN-LSB //APUNTE No newline at end of file |
|
40 | #define maskc_out_beam PC30+PC28+PC26+PC24+PC22+PC20 //MSB-UP-LSB MSB-DOWN-LSB //APUNTE | |
41 | #define maskc_out_cntl PC4+PC5+PC6 //MONITORING CONTROL No newline at end of file |
|
41 | #define maskc_out_cntl PC4+PC5+PC6 //MONITORING CONTROL | |
42 | No newline at end of file |
|
42 | ||
43 | #define mask_sel_canal PC4 //MONITORING CONTROL No newline at end of file |
|
43 | #define mask_sel_canal PC4 //MONITORING CONTROL | |
44 | #define mask_sel_atenuacion PC5 No newline at end of file |
|
44 | #define mask_sel_atenuacion PC5 | |
45 | #define mask_sel_calibracion PC6 No newline at end of file |
|
45 | #define mask_sel_calibracion PC6 | |
46 | No newline at end of file |
|
46 | ||
47 | #define maskb_in PB16+PB18+PB20+PB30+PB24+PB22 //MSB-UP-LSB MSB-DOWN-LSB //VERIFICACION No newline at end of file |
|
47 | #define maskb_in PB16+PB18+PB20+PB30+PB24+PB22 //MSB-UP-LSB MSB-DOWN-LSB //VERIFICACION | |
48 | No newline at end of file |
|
48 | ||
49 | #define maskc_in_adc PC0+PC1 No newline at end of file |
|
49 | #define maskc_in_adc PC0+PC1 | |
50 | No newline at end of file |
|
50 | ||
51 | #define bit_up_2 0x00010000 //Mascara de cada bit a revisar: bit_up_2 es MSB No newline at end of file |
|
51 | #define bit_up_2 0x00010000 //Mascara de cada bit a revisar: bit_up_2 es MSB | |
52 | #define bit_up_1 0x00040000 No newline at end of file |
|
52 | #define bit_up_1 0x00040000 | |
53 | #define bit_up_0 0x00100000 No newline at end of file |
|
53 | #define bit_up_0 0x00100000 | |
54 | #define bit_dow_2 0x40000000 No newline at end of file |
|
54 | #define bit_dow_2 0x40000000 | |
55 | #define bit_dow_1 0x01000000 No newline at end of file |
|
55 | #define bit_dow_1 0x01000000 | |
56 | #define bit_dow_0 0x00400000 No newline at end of file |
|
56 | #define bit_dow_0 0x00400000 | |
57 | No newline at end of file |
|
57 | ||
58 | #define MyID 11 No newline at end of file |
|
58 | #define MyID 11 | |
59 | #define MAXPENDING 5 /* Maximum outstanding connection requests */ No newline at end of file |
|
59 | #define MAXPENDING 5 /* Maximum outstanding connection requests */ | |
60 | No newline at end of file |
|
60 | ||
61 | //parameters for the name of the output file No newline at end of file |
|
61 | //parameters for the name of the output file | |
62 | #define FPRE "AD" //prefix for the output file name No newline at end of file |
|
62 | #define FPRE "AD" //prefix for the output file name | |
63 | #define FEXT ".out" //file extension for the output file No newline at end of file |
|
63 | #define FEXT ".out" //file extension for the output file | |
64 | #define FNAMELEN 40 No newline at end of file |
|
64 | #define FNAMELEN 40 | |
65 | No newline at end of file |
|
65 | ||
66 | //ADC parameters No newline at end of file |
|
66 | //ADC parameters | |
67 | #define REP 1 //defines how many times the data acquisation loop is repeated No newline at end of file |
|
67 | #define REP 1 //defines how many times the data acquisation loop is repeated | |
68 | #define NSAMPLES 10 //defines how many samples are taken in one data acqu- No newline at end of file |
|
68 | #define NSAMPLES 10 //defines how many samples are taken in one data acqu- | |
69 | // isation loop No newline at end of file |
|
69 | // isation loop | |
|
70 | ||||
|
No newline at end of file | ||||
|
71 | #define NLOOPS 200 // Number of loops for the transmisor checking No newline at end of file | |||
70 | #define CNVTIME 14.3 //defines how long it takes to get one sample. Value No newline at end of file |
|
72 | #define CNVTIME 14.3 //defines how long it takes to get one sample. Value | |
71 | // is only needed for the output file, doesn't change No newline at end of file |
|
73 | // is only needed for the output file, doesn't change | |
72 | // any ADC configurations No newline at end of file |
|
74 | // any ADC configurations | |
73 | #define UREF 3.3 //Reference Voltage of ADC (max. ADC Voltage) No newline at end of file |
|
75 | #define UREF 3.3 //Reference Voltage of ADC (max. ADC Voltage) | |
74 | #define ADCRES 1023 //Resolution of ADC (10bit=1023) No newline at end of file |
|
76 | #define ADCRES 1023 //Resolution of ADC (10bit=1023) | |
75 | No newline at end of file |
|
77 | ||
76 | No newline at end of file |
|
78 | ||
77 | char *buff_experimento= NULL; No newline at end of file |
|
79 | char *buff_experimento= NULL; | |
78 | No newline at end of file |
|
80 | ||
79 | AT91S_PIO *pioc; No newline at end of file |
|
81 | AT91S_PIO *pioc; | |
80 | AT91S_PIO *piob; No newline at end of file |
|
82 | AT91S_PIO *piob; | |
81 | AT91S_PIO *pio_adc; No newline at end of file |
|
83 | AT91S_PIO *pio_adc; | |
82 | AT91S_ADC *padc; No newline at end of file |
|
84 | AT91S_ADC *padc; | |
83 | AT91S_ADC *padd; No newline at end of file |
|
85 | AT91S_ADC *padd; | |
84 | No newline at end of file |
|
86 | ||
85 | struct control_module_parameters { No newline at end of file |
|
87 | struct control_module_parameters { | |
86 | char ID[20]; No newline at end of file |
|
88 | char ID[20]; | |
87 | char param2[20]; No newline at end of file |
|
89 | char param2[20]; | |
88 | char param3[20]; No newline at end of file |
|
90 | char param3[20]; | |
89 | char param4[20]; No newline at end of file |
|
91 | char param4[20]; | |
90 | }; No newline at end of file |
|
92 | }; | |
91 | No newline at end of file |
|
93 | ||
92 | typedef struct control_module_parameters cmp; No newline at end of file |
|
94 | typedef struct control_module_parameters cmp; | |
93 | No newline at end of file |
|
95 | ||
94 | char *header = NULL; No newline at end of file |
|
96 | char *header = NULL; | |
95 | char *TypeOfInstrument = NULL; No newline at end of file |
|
97 | char *TypeOfInstrument = NULL; | |
96 | char *iDSource = NULL; No newline at end of file |
|
98 | char *iDSource = NULL; | |
97 | char *iDDestino = NULL; No newline at end of file |
|
99 | char *iDDestino = NULL; | |
98 | char *rx_len = NULL; No newline at end of file |
|
100 | char *rx_len = NULL; | |
99 | char *cmd = NULL; No newline at end of file |
|
101 | char *cmd = NULL; | |
100 | char *rx_data = NULL; No newline at end of file |
|
102 | char *rx_data = NULL; | |
101 | char *crc = NULL; No newline at end of file |
|
103 | char *crc = NULL; | |
102 | No newline at end of file |
|
104 | ||
103 | cmp parameters; No newline at end of file |
|
105 | cmp parameters; | |
104 | /* No newline at end of file |
|
106 | /* | |
105 | * Zona de declaracion de cabeceras. No newline at end of file |
|
107 | * Zona de declaracion de cabeceras. | |
106 | */ No newline at end of file |
|
108 | */ | |
107 | cmp inicializa_modulo(cmp p); No newline at end of file |
|
109 | cmp inicializa_modulo(cmp p); | |
108 | int inicializa_ethernet(); No newline at end of file |
|
110 | int inicializa_ethernet(); | |
109 | int rxData(int, char*); No newline at end of file |
|
111 | int rxData(int, char*); | |
110 | void txData(int, char*); No newline at end of file |
|
112 | void txData(int, char*); | |
111 | void inicializa_gpio(); No newline at end of file |
|
113 | void inicializa_gpio(); | |
112 | void inicializa_adc(); No newline at end of file |
|
114 | void inicializa_adc(); | |
113 | void procesa_peticion(char *rx_buffer, char *tx_buffer); No newline at end of file |
|
115 | void procesa_peticion(char *rx_buffer, char *tx_buffer); | |
114 | int cambia_apuntamiento(char *puntero_char); No newline at end of file |
|
116 | int cambia_apuntamiento(char *puntero_char); | |
115 | int carga_experimento(char *nombre_archivo); No newline at end of file |
|
117 | int carga_experimento(char *nombre_archivo); | |
116 | char *chequeo_sistema(char *filename, char *numero_muestras); No newline at end of file |
|
118 | char *chequeo_sistema(char *filename, char *numero_muestras); | |
117 | void recibe_experimento(char *data, char filename[]); No newline at end of file |
|
119 | void recibe_experimento(char *data, char filename[]); | |
118 | void SplitFrame(char *frame); No newline at end of file |
|
120 | void SplitFrame(char *frame); | |
119 | void intToStr( int number, char* str ); No newline at end of file |
|
121 | void intToStr( int number, char* str ); | |
120 | No newline at end of file |
|
122 | ||
121 | //ABS monitoring No newline at end of file |
|
123 | //ABS monitoring | |
122 | //int ABS_monitoreo(int sel_atenuador, int sel_calibracion, float umbral, int pulsewidth); No newline at end of file |
|
124 | //int ABS_monitoreo(int sel_atenuador, int sel_calibracion, float umbral, int pulsewidth); | |
123 | char* ABS_monitoreo(int sel_atenuador, int sel_calibracion, float umbral, int pulsewidth); No newline at end of file |
|
125 | char* ABS_monitoreo(int sel_atenuador, int sel_calibracion, float umbral, int pulsewidth); | |
124 | AT91S_ADC * configADC1(void); No newline at end of file |
|
126 | AT91S_ADC * configADC1(void); | |
125 | AT91S_ADC * configADC2(void); No newline at end of file |
|
127 | AT91S_ADC * configADC2(void); | |
126 | No newline at end of file |
|
128 | ||
127 | FILE * create_Output(char*, time_t); No newline at end of file |
|
129 | FILE * create_Output(char*, time_t); | |
128 | No newline at end of file |
|
130 | ||
129 | void writeOutput(float resultado, FILE * output); No newline at end of file |
|
131 | void writeOutput(float resultado, FILE * output); | |
130 | No newline at end of file |
|
132 | ||
131 | int checkTx(long int results1[],long int results2[], float umbral, int pulsewidth); No newline at end of file |
|
133 | int checkTx(long int results1[],long int results2[], float umbral, int pulsewidth); | |
132 | No newline at end of file |
|
134 | ||
133 | double mediana(long int *results, unsigned int cuenta); No newline at end of file |
|
135 | double mediana(long int *results, unsigned int cuenta); | |
134 | float getPhase(long int results1[], long int results2[]); No newline at end of file |
|
136 | float getPhase(long int results1[], long int results2[]); | |
135 | No newline at end of file |
|
137 | ||
136 | int fExists(char *); No newline at end of file |
|
138 | int fExists(char *); | |
137 | int configCLK(); No newline at end of file |
|
139 | int configCLK(); | |
138 | // No newline at end of file |
|
140 | // | |
139 | No newline at end of file |
|
141 | ||
140 | /* No newline at end of file |
|
142 | /* | |
141 | * No newline at end of file |
|
143 | * | |
142 | */ No newline at end of file |
|
144 | */ | |
143 | int main(){ No newline at end of file |
|
145 | int main(){ | |
144 | No newline at end of file |
|
146 | ||
145 | int servSocket; No newline at end of file |
|
147 | int servSocket; | |
146 | int clntSocket; No newline at end of file |
|
148 | int clntSocket; | |
147 | No newline at end of file |
|
149 | ||
148 | No newline at end of file |
|
150 | ||
149 | char *rx_buffer = (char *) malloc(TAM_BUFFER); No newline at end of file |
|
151 | char *rx_buffer = (char *) malloc(TAM_BUFFER); | |
150 | char *tx_buffer = (char *) malloc(TAM_BUFFER); No newline at end of file |
|
152 | char *tx_buffer = (char *) malloc(TAM_BUFFER); | |
151 | /* Inicializa parametros del modulo*/ No newline at end of file |
|
153 | /* Inicializa parametros del modulo*/ | |
152 | parameters = inicializa_modulo(parameters); No newline at end of file |
|
154 | parameters = inicializa_modulo(parameters); | |
153 | printf("%s\n%s\n%s\n%s\n",parameters.ID, parameters.param2, parameters.param3, parameters.param4); No newline at end of file |
|
155 | printf("%s\n%s\n%s\n%s\n",parameters.ID, parameters.param2, parameters.param3, parameters.param4); | |
154 | /* Inicializa red*/ No newline at end of file |
|
156 | /* Inicializa red*/ | |
155 | servSocket = inicializa_ethernet(); No newline at end of file |
|
157 | servSocket = inicializa_ethernet(); | |
156 | /* Inicializamos el puerto GPIO del sistema embebido GSBC-9260S */ No newline at end of file |
|
158 | /* Inicializamos el puerto GPIO del sistema embebido GSBC-9260S */ | |
157 | inicializa_gpio(); No newline at end of file |
|
159 | inicializa_gpio(); | |
158 | inicializa_adc(); No newline at end of file |
|
160 | inicializa_adc(); | |
159 | No newline at end of file |
|
161 | ||
160 | while(1){ No newline at end of file |
|
162 | while(1){ | |
161 | // Recepción TCP de petición No newline at end of file |
|
163 | // Recepción TCP de petición | |
162 | clntSocket = rxData(servSocket, rx_buffer); No newline at end of file |
|
164 | clntSocket = rxData(servSocket, rx_buffer); | |
163 | //testpoint No newline at end of file |
|
165 | //testpoint | |
164 | printf("rx:%s\n",rx_buffer); No newline at end of file |
|
166 | printf("rx:%s\n",rx_buffer); | |
165 | // Procesamiento de la petición No newline at end of file |
|
167 | // Procesamiento de la petición | |
166 | procesa_peticion(rx_buffer, tx_buffer); No newline at end of file |
|
168 | procesa_peticion(rx_buffer, tx_buffer); | |
167 | //testpoint No newline at end of file |
|
169 | //testpoint | |
168 | printf("tx:%s\n",tx_buffer); No newline at end of file |
|
170 | printf("tx:%s\n",tx_buffer); | |
169 | // Respuesta del modulo de control No newline at end of file |
|
171 | // Respuesta del modulo de control | |
170 | txData(clntSocket, tx_buffer); No newline at end of file |
|
172 | txData(clntSocket, tx_buffer); | |
171 | No newline at end of file |
|
173 | ||
172 | } No newline at end of file |
|
174 | } | |
173 | } No newline at end of file |
|
175 | } | |
174 | No newline at end of file |
|
176 | ||
175 | No newline at end of file |
|
177 | ||
176 | int inicializa_ethernet(){ No newline at end of file |
|
178 | int inicializa_ethernet(){ | |
177 | No newline at end of file |
|
179 | ||
178 | struct sockaddr_in inf_servidor; No newline at end of file |
|
180 | struct sockaddr_in inf_servidor; | |
179 | No newline at end of file |
|
181 | ||
180 | int servSocket; No newline at end of file |
|
182 | int servSocket; | |
181 | No newline at end of file |
|
183 | ||
182 | int resultado; No newline at end of file |
|
184 | int resultado; | |
183 | No newline at end of file |
|
185 | ||
184 | /* Haciendo la estructura local*/ No newline at end of file |
|
186 | /* Haciendo la estructura local*/ | |
185 | memset(&inf_servidor, 0, sizeof(inf_servidor)); No newline at end of file |
|
187 | memset(&inf_servidor, 0, sizeof(inf_servidor)); | |
186 | inf_servidor.sin_family= AF_INET; No newline at end of file |
|
188 | inf_servidor.sin_family= AF_INET; | |
187 | inf_servidor.sin_port= htons(PUERTO_SERVIDOR); No newline at end of file |
|
189 | inf_servidor.sin_port= htons(PUERTO_SERVIDOR); | |
188 | inf_servidor.sin_addr.s_addr= INADDR_ANY; No newline at end of file |
|
190 | inf_servidor.sin_addr.s_addr= INADDR_ANY; | |
189 | No newline at end of file |
|
191 | ||
190 | /* Se establece el socket */ No newline at end of file |
|
192 | /* Se establece el socket */ | |
191 | servSocket = socket(AF_INET,SOCK_STREAM, IPPROTO_TCP); No newline at end of file |
|
193 | servSocket = socket(AF_INET,SOCK_STREAM, IPPROTO_TCP); | |
192 | if (servSocket == -1){ No newline at end of file |
|
194 | if (servSocket == -1){ | |
193 | printf("No se establecio correctamente el socket: socket()\n"); No newline at end of file |
|
195 | printf("No se establecio correctamente el socket: socket()\n"); | |
194 | //ERROR_FATAL("No se establecio correctamente el socket: socket()\n"); No newline at end of file |
|
196 | //ERROR_FATAL("No se establecio correctamente el socket: socket()\n"); | |
195 | exit(-1); No newline at end of file |
|
197 | exit(-1); | |
196 | } No newline at end of file |
|
198 | } | |
197 | No newline at end of file |
|
199 | ||
198 | /* Se asocia el socket a un puerto y una IP */ No newline at end of file |
|
200 | /* Se asocia el socket a un puerto y una IP */ | |
199 | resultado = bind(servSocket,(struct sockaddr *)&inf_servidor,sizeof(inf_servidor)); No newline at end of file |
|
201 | resultado = bind(servSocket,(struct sockaddr *)&inf_servidor,sizeof(inf_servidor)); | |
200 | if (resultado== -1){ No newline at end of file |
|
202 | if (resultado== -1){ | |
201 | printf("No se establecio correctamente el socket: bind()\n"); No newline at end of file |
|
203 | printf("No se establecio correctamente el socket: bind()\n"); | |
202 | //ERROR_FATAL("No se establecio correctamente el socket: bind()\n"); No newline at end of file |
|
204 | //ERROR_FATAL("No se establecio correctamente el socket: bind()\n"); | |
203 | exit(-1); No newline at end of file |
|
205 | exit(-1); | |
204 | } No newline at end of file |
|
206 | } | |
205 | No newline at end of file |
|
207 | ||
206 | if (listen(servSocket, MAXPENDING) < 0){ No newline at end of file |
|
208 | if (listen(servSocket, MAXPENDING) < 0){ | |
207 | printf("listen() failed\n"); No newline at end of file |
|
209 | printf("listen() failed\n"); | |
208 | exit(-1); No newline at end of file |
|
210 | exit(-1); | |
209 | } No newline at end of file |
|
211 | } | |
210 | No newline at end of file |
|
212 | ||
211 | return servSocket; No newline at end of file |
|
213 | return servSocket; | |
212 | No newline at end of file |
|
214 | ||
213 | } No newline at end of file |
|
215 | } | |
214 | No newline at end of file |
|
216 | ||
215 | int rxData(int servSocket, char* rx_buffer){ No newline at end of file |
|
217 | int rxData(int servSocket, char* rx_buffer){ | |
216 | No newline at end of file |
|
218 | ||
217 | int clntSocket; No newline at end of file |
|
219 | int clntSocket; | |
218 | struct sockaddr_in inf_cliente; No newline at end of file |
|
220 | struct sockaddr_in inf_cliente; | |
219 | int numbytes_recibidos; No newline at end of file |
|
221 | int numbytes_recibidos; | |
220 | unsigned int inf_client_Len; No newline at end of file |
|
222 | unsigned int inf_client_Len; | |
221 | No newline at end of file |
|
223 | ||
222 | printf("\nEsperando solicitud de cliente...\n"); No newline at end of file |
|
224 | printf("\nEsperando solicitud de cliente...\n"); | |
223 | No newline at end of file |
|
225 | ||
224 | /* Set the size of the in-out parameter */ No newline at end of file |
|
226 | /* Set the size of the in-out parameter */ | |
225 | inf_client_Len = sizeof(inf_cliente); No newline at end of file |
|
227 | inf_client_Len = sizeof(inf_cliente); | |
226 | /* Se espera hasta que un cliente se conecte */ No newline at end of file |
|
228 | /* Se espera hasta que un cliente se conecte */ | |
227 | if ((clntSocket = accept(servSocket, (struct sockaddr *) &inf_cliente, No newline at end of file |
|
229 | if ((clntSocket = accept(servSocket, (struct sockaddr *) &inf_cliente, | |
228 | &inf_client_Len)) < 0) No newline at end of file |
|
230 | &inf_client_Len)) < 0) | |
229 | printf("accept() failed\n"); No newline at end of file |
|
231 | printf("accept() failed\n"); | |
230 | No newline at end of file |
|
232 | ||
231 | if ((numbytes_recibidos = recv(clntSocket, rx_buffer, TAM_BUFFER, 0)) < 0) No newline at end of file |
|
233 | if ((numbytes_recibidos = recv(clntSocket, rx_buffer, TAM_BUFFER, 0)) < 0) | |
232 | printf("recv() failed\n"); No newline at end of file |
|
234 | printf("recv() failed\n"); | |
233 | No newline at end of file |
|
235 | ||
234 | /* Se procede a procesar los datos recibidos */ No newline at end of file |
|
236 | /* Se procede a procesar los datos recibidos */ | |
235 | rx_buffer[numbytes_recibidos]= '\0'; No newline at end of file |
|
237 | rx_buffer[numbytes_recibidos]= '\0'; | |
236 | No newline at end of file |
|
238 | ||
237 | return clntSocket; No newline at end of file |
|
239 | return clntSocket; | |
238 | } No newline at end of file |
|
240 | } | |
239 | No newline at end of file |
|
241 | ||
240 | void txData(int clntSocket, char* data){ No newline at end of file |
|
242 | void txData(int clntSocket, char* data){ | |
241 | No newline at end of file |
|
243 | ||
242 | /* Echo message back to client */ No newline at end of file |
|
244 | /* Echo message back to client */ | |
243 | if (send(clntSocket, data, strlen(data), 0) != strlen(data)) No newline at end of file |
|
245 | if (send(clntSocket, data, strlen(data), 0) != strlen(data)) | |
244 | printf("send() failed\n"); No newline at end of file |
|
246 | printf("send() failed\n"); | |
245 | No newline at end of file |
|
247 | ||
246 | close(clntSocket); /* Close client socket */ No newline at end of file |
|
248 | close(clntSocket); /* Close client socket */ | |
247 | } No newline at end of file |
|
249 | } | |
248 | No newline at end of file |
|
250 | ||
249 | /* No newline at end of file |
|
251 | /* | |
250 | * Esta funcion incializa el puerto GPIO No newline at end of file |
|
252 | * Esta funcion incializa el puerto GPIO | |
251 | */ No newline at end of file |
|
253 | */ | |
252 | void inicializa_gpio(){ No newline at end of file |
|
254 | void inicializa_gpio(){ | |
253 | No newline at end of file |
|
255 | ||
254 | int desplazamiento_beam[6]={30,28,26,24,22,20}; //Desplazamientos para los pines de apunte No newline at end of file |
|
256 | int desplazamiento_beam[6]={30,28,26,24,22,20}; //Desplazamientos para los pines de apunte | |
255 | int desplazamiento_cntl[3]={4,5,6}; //Desplazamientos para los pines de control de monitoreo No newline at end of file |
|
257 | int desplazamiento_cntl[3]={4,5,6}; //Desplazamientos para los pines de control de monitoreo | |
256 | unsigned long acumulado_ceros=0; No newline at end of file |
|
258 | unsigned long acumulado_ceros=0; | |
257 | int i; No newline at end of file |
|
259 | int i; | |
258 | No newline at end of file |
|
260 | ||
259 | // Configuracion de los pines de APUNTE y control de monitoreo No newline at end of file |
|
261 | // Configuracion de los pines de APUNTE y control de monitoreo | |
260 | pioc = pio_map(PIOC_BASE); No newline at end of file |
|
262 | pioc = pio_map(PIOC_BASE); | |
261 | pio_enable(pioc, maskc_out_beam + maskc_out_cntl); No newline at end of file |
|
263 | pio_enable(pioc, maskc_out_beam + maskc_out_cntl); | |
262 | pio_disable_irq(pioc, maskc_out_beam + maskc_out_cntl); No newline at end of file |
|
264 | pio_disable_irq(pioc, maskc_out_beam + maskc_out_cntl); | |
263 | pio_disable_multiple_driver(pioc, maskc_out_beam + maskc_out_cntl); No newline at end of file |
|
265 | pio_disable_multiple_driver(pioc, maskc_out_beam + maskc_out_cntl); | |
264 | pio_disable_pull_ups(pioc, maskc_out_beam + maskc_out_cntl); No newline at end of file |
|
266 | pio_disable_pull_ups(pioc, maskc_out_beam + maskc_out_cntl); | |
265 | pio_synchronous_data_output(pioc, maskc_out_beam + maskc_out_cntl); No newline at end of file |
|
267 | pio_synchronous_data_output(pioc, maskc_out_beam + maskc_out_cntl); | |
266 | pio_output_enable(pioc, maskc_out_beam + maskc_out_cntl); No newline at end of file |
|
268 | pio_output_enable(pioc, maskc_out_beam + maskc_out_cntl); | |
267 | No newline at end of file |
|
269 | ||
268 | // Configuracion de los pines de VERIFICACION No newline at end of file |
|
270 | // Configuracion de los pines de VERIFICACION | |
269 | piob = pio_map(PIOB_BASE); No newline at end of file |
|
271 | piob = pio_map(PIOB_BASE); | |
270 | pio_enable(piob, maskb_in); No newline at end of file |
|
272 | pio_enable(piob, maskb_in); | |
271 | pio_disable_irq(piob, maskb_in); No newline at end of file |
|
273 | pio_disable_irq(piob, maskb_in); | |
272 | pio_disable_multiple_driver(piob, maskb_in); No newline at end of file |
|
274 | pio_disable_multiple_driver(piob, maskb_in); | |
273 | pio_disable_pull_ups(piob, maskb_in); No newline at end of file |
|
275 | pio_disable_pull_ups(piob, maskb_in); | |
274 | pio_input_enable(piob, maskb_in); No newline at end of file |
|
276 | pio_input_enable(piob, maskb_in); | |
275 | No newline at end of file |
|
277 | ||
276 | //Pînes de ADC No newline at end of file |
|
278 | //Pînes de ADC | |
277 | pio_adc = pio_map(PIOC_BASE); No newline at end of file |
|
279 | pio_adc = pio_map(PIOC_BASE); | |
278 | pin_adc_enable(pio_adc,maskc_in_adc); //Habilitamos PC0 para usar con ADC0 y 1 No newline at end of file |
|
280 | pin_adc_enable(pio_adc,maskc_in_adc); //Habilitamos PC0 para usar con ADC0 y 1 | |
279 | pio_disable_irq(pio_adc, maskc_in_adc); No newline at end of file |
|
281 | pio_disable_irq(pio_adc, maskc_in_adc); | |
280 | pio_disable_multiple_driver(pio_adc, maskc_in_adc); No newline at end of file |
|
282 | pio_disable_multiple_driver(pio_adc, maskc_in_adc); | |
281 | pio_disable_pull_ups(pio_adc, maskc_in_adc); No newline at end of file |
|
283 | pio_disable_pull_ups(pio_adc, maskc_in_adc); | |
282 | pio_input_enable(pio_adc, maskc_in_adc); No newline at end of file |
|
284 | pio_input_enable(pio_adc, maskc_in_adc); | |
283 | No newline at end of file |
|
285 | ||
284 | //Inicializando a cero los pines de apunte No newline at end of file |
|
286 | //Inicializando a cero los pines de apunte | |
285 | for(i=0;i<6;i++) No newline at end of file |
|
287 | for(i=0;i<6;i++) | |
286 | acumulado_ceros= acumulado_ceros + (1 << desplazamiento_beam[i]); No newline at end of file |
|
288 | acumulado_ceros= acumulado_ceros + (1 << desplazamiento_beam[i]); | |
287 | pio_out(pioc, maskc_out_beam, acumulado_ceros, 0); No newline at end of file |
|
289 | pio_out(pioc, maskc_out_beam, acumulado_ceros, 0); | |
288 | No newline at end of file |
|
290 | ||
289 | //Inicializando a cero los pines de control de monitoreo: atenuacion, calibracion y canal No newline at end of file |
|
291 | //Inicializando a cero los pines de control de monitoreo: atenuacion, calibracion y canal | |
290 | for(i=0;i<3;i++) No newline at end of file |
|
292 | for(i=0;i<3;i++) | |
291 | acumulado_ceros= acumulado_ceros + (1 << desplazamiento_cntl[i]); No newline at end of file |
|
293 | acumulado_ceros= acumulado_ceros + (1 << desplazamiento_cntl[i]); | |
292 | pio_out(pioc, maskc_out_cntl, acumulado_ceros, 0); No newline at end of file |
|
294 | pio_out(pioc, maskc_out_cntl, acumulado_ceros, 0); | |
293 | No newline at end of file |
|
295 | ||
294 | } No newline at end of file |
|
296 | } | |
295 | No newline at end of file |
|
297 | ||
296 | void inicializa_adc(){ No newline at end of file |
|
298 | void inicializa_adc(){ | |
297 | No newline at end of file |
|
299 | ||
298 | if (configCLK() == 1) No newline at end of file |
|
300 | if (configCLK() == 1) | |
299 | printf("clock ADC enable.\n"); No newline at end of file |
|
301 | printf("clock ADC enable.\n"); | |
300 | //configure ADC Settings No newline at end of file |
|
302 | //configure ADC Settings | |
301 | padc=configADC1(); No newline at end of file |
|
303 | padc=configADC1(); | |
302 | padd=configADC2(); No newline at end of file |
|
304 | padd=configADC2(); | |
303 | } No newline at end of file |
|
305 | } | |
304 | No newline at end of file |
|
306 | ||
305 | No newline at end of file |
|
307 | ||
306 | /* No newline at end of file |
|
308 | /* | |
307 | * Divide rx frame into the frame components No newline at end of file |
|
309 | * Divide rx frame into the frame components | |
308 | */ No newline at end of file |
|
310 | */ | |
309 | void SplitFrame(char *frame){ No newline at end of file |
|
311 | void SplitFrame(char *frame){ | |
310 | header = malloc(4); No newline at end of file |
|
312 | header = malloc(4); | |
311 | *header = *frame; No newline at end of file |
|
313 | *header = *frame; | |
312 | *(header + 1) = *(frame + 1); No newline at end of file |
|
314 | *(header + 1) = *(frame + 1); | |
313 | *(header + 2) = *(frame + 2); No newline at end of file |
|
315 | *(header + 2) = *(frame + 2); | |
314 | *(header + 3) = '\0'; No newline at end of file |
|
316 | *(header + 3) = '\0'; | |
315 | TypeOfInstrument = malloc(4); No newline at end of file |
|
317 | TypeOfInstrument = malloc(4); | |
316 | *TypeOfInstrument = *(frame + 3); No newline at end of file |
|
318 | *TypeOfInstrument = *(frame + 3); | |
317 | *(TypeOfInstrument + 1) = *(frame + 4); No newline at end of file |
|
319 | *(TypeOfInstrument + 1) = *(frame + 4); | |
318 | *(TypeOfInstrument + 2) = *(frame + 5); No newline at end of file |
|
320 | *(TypeOfInstrument + 2) = *(frame + 5); | |
319 | *(TypeOfInstrument + 3) = '\0'; No newline at end of file |
|
321 | *(TypeOfInstrument + 3) = '\0'; | |
320 | iDSource = malloc(8); No newline at end of file |
|
322 | iDSource = malloc(8); | |
321 | *iDSource = *(frame + 6); No newline at end of file |
|
323 | *iDSource = *(frame + 6); | |
322 | *(iDSource + 1) = *(frame + 7); No newline at end of file |
|
324 | *(iDSource + 1) = *(frame + 7); | |
323 | *(iDSource + 2) = *(frame + 8); No newline at end of file |
|
325 | *(iDSource + 2) = *(frame + 8); | |
324 | *(iDSource + 3) = *(frame + 9); No newline at end of file |
|
326 | *(iDSource + 3) = *(frame + 9); | |
325 | *(iDSource + 4) = *(frame + 10); No newline at end of file |
|
327 | *(iDSource + 4) = *(frame + 10); | |
326 | *(iDSource + 5) = *(frame + 11); No newline at end of file |
|
328 | *(iDSource + 5) = *(frame + 11); | |
327 | *(iDSource + 6) = *(frame + 12); No newline at end of file |
|
329 | *(iDSource + 6) = *(frame + 12); | |
328 | *(iDSource + 7) = '\0'; No newline at end of file |
|
330 | *(iDSource + 7) = '\0'; | |
329 | iDDestino = malloc(8); No newline at end of file |
|
331 | iDDestino = malloc(8); | |
330 | *iDDestino = *(frame + 13); No newline at end of file |
|
332 | *iDDestino = *(frame + 13); | |
331 | *(iDDestino + 1) = *(frame + 14); No newline at end of file |
|
333 | *(iDDestino + 1) = *(frame + 14); | |
332 | *(iDDestino + 2) = *(frame + 15); No newline at end of file |
|
334 | *(iDDestino + 2) = *(frame + 15); | |
333 | *(iDDestino + 3) = *(frame + 16); No newline at end of file |
|
335 | *(iDDestino + 3) = *(frame + 16); | |
334 | *(iDDestino + 4) = *(frame + 17); No newline at end of file |
|
336 | *(iDDestino + 4) = *(frame + 17); | |
335 | *(iDDestino + 5) = *(frame + 18); No newline at end of file |
|
337 | *(iDDestino + 5) = *(frame + 18); | |
336 | *(iDDestino + 6) = *(frame + 19); No newline at end of file |
|
338 | *(iDDestino + 6) = *(frame + 19); | |
337 | *(iDDestino + 7) = '\0'; No newline at end of file |
|
339 | *(iDDestino + 7) = '\0'; | |
338 | rx_len = malloc(7); No newline at end of file |
|
340 | rx_len = malloc(7); | |
339 | *rx_len = *(frame + 20); No newline at end of file |
|
341 | *rx_len = *(frame + 20); | |
340 | *(rx_len + 1) = *(frame + 21); No newline at end of file |
|
342 | *(rx_len + 1) = *(frame + 21); | |
341 | *(rx_len + 2) = *(frame + 22); No newline at end of file |
|
343 | *(rx_len + 2) = *(frame + 22); | |
342 | *(rx_len + 3) = *(frame + 23); No newline at end of file |
|
344 | *(rx_len + 3) = *(frame + 23); | |
343 | *(rx_len + 4) = *(frame + 24); No newline at end of file |
|
345 | *(rx_len + 4) = *(frame + 24); | |
344 | *(rx_len + 5) = *(frame + 25); No newline at end of file |
|
346 | *(rx_len + 5) = *(frame + 25); | |
345 | *(rx_len + 6) = '\0'; No newline at end of file |
|
347 | *(rx_len + 6) = '\0'; | |
346 | cmd = malloc(5); No newline at end of file |
|
348 | cmd = malloc(5); | |
347 | *cmd = *(frame + 26); No newline at end of file |
|
349 | *cmd = *(frame + 26); | |
348 | *(cmd + 1) = *(frame + 27); No newline at end of file |
|
350 | *(cmd + 1) = *(frame + 27); | |
349 | *(cmd + 2) = *(frame + 28); No newline at end of file |
|
351 | *(cmd + 2) = *(frame + 28); | |
350 | *(cmd + 3) = *(frame + 29); No newline at end of file |
|
352 | *(cmd + 3) = *(frame + 29); | |
351 | *(cmd + 4) = '\0'; No newline at end of file |
|
353 | *(cmd + 4) = '\0'; | |
352 | No newline at end of file |
|
354 | ||
353 | int l = atoi(rx_len); No newline at end of file |
|
355 | int l = atoi(rx_len); | |
354 | rx_data = malloc(l + 1); No newline at end of file |
|
356 | rx_data = malloc(l + 1); | |
355 | int i; No newline at end of file |
|
357 | int i; | |
356 | for (i = 30; i < 30 + l; i++) No newline at end of file |
|
358 | for (i = 30; i < 30 + l; i++) | |
357 | *(rx_data + (i-30)) = *(frame + i); No newline at end of file |
|
359 | *(rx_data + (i-30)) = *(frame + i); | |
358 | *(rx_data + l) = '\0'; No newline at end of file |
|
360 | *(rx_data + l) = '\0'; | |
359 | crc = malloc(2); No newline at end of file |
|
361 | crc = malloc(2); | |
360 | *crc = *(frame + 30 + l); No newline at end of file |
|
362 | *crc = *(frame + 30 + l); | |
361 | *(crc + 1) = '\0'; No newline at end of file |
|
363 | *(crc + 1) = '\0'; | |
362 | } No newline at end of file |
|
364 | } | |
363 | No newline at end of file |
|
365 | ||
364 | /* No newline at end of file |
|
366 | /* | |
365 | * Esta funcion procesa el mensaje de peticion y genera respuesta No newline at end of file |
|
367 | * Esta funcion procesa el mensaje de peticion y genera respuesta | |
366 | */ No newline at end of file |
|
368 | */ | |
367 | void procesa_peticion(char *rx_buffer, char *tx_buffer){ No newline at end of file |
|
369 | void procesa_peticion(char *rx_buffer, char *tx_buffer){ | |
368 | // int n = 0; No newline at end of file |
|
370 | // int n = 0; | |
369 | char filename1[50]; No newline at end of file |
|
371 | char filename1[50]; | |
370 | char filename2[] = "verificacion.txt"; No newline at end of file |
|
372 | char filename2[] = "verificacion.txt"; | |
371 | char *tx_data = NULL; No newline at end of file |
|
373 | char *tx_data = NULL; | |
372 | char *tx_len = NULL; No newline at end of file |
|
374 | char *tx_len = NULL; | |
373 | SplitFrame(rx_buffer); No newline at end of file |
|
375 | SplitFrame(rx_buffer); | |
374 | No newline at end of file |
|
376 | ||
375 | if ((cmd == NULL) || (rx_data == NULL)){ No newline at end of file |
|
377 | if ((cmd == NULL) || (rx_data == NULL)){ | |
376 | printf("procesarPeticion: formato de mensaje incorrecto"); No newline at end of file |
|
378 | printf("procesarPeticion: formato de mensaje incorrecto"); | |
377 | //ERROR("procesarPeticion: formato de mensaje incorrecto"); No newline at end of file |
|
379 | //ERROR("procesarPeticion: formato de mensaje incorrecto"); | |
378 | No newline at end of file |
|
380 | ||
379 | } No newline at end of file |
|
381 | } | |
380 | else{ No newline at end of file |
|
382 | else{ | |
381 | if(strcmp(cmd,"SNDF") == 0){ No newline at end of file |
|
383 | if(strcmp(cmd,"SNDF") == 0){ | |
382 | recibe_experimento(rx_data,filename1); No newline at end of file |
|
384 | recibe_experimento(rx_data,filename1); | |
383 | carga_experimento(filename1); No newline at end of file |
|
385 | carga_experimento(filename1); | |
384 | cambia_apuntamiento("0"); No newline at end of file |
|
386 | cambia_apuntamiento("0"); | |
385 | tx_data = (char*)malloc(3); No newline at end of file |
|
387 | tx_data = (char*)malloc(3); | |
386 | tx_data = "OK"; No newline at end of file |
|
388 | tx_data = "OK"; | |
387 | } No newline at end of file |
|
389 | } | |
388 | else if(strcmp(cmd,"CHGB") == 0){ No newline at end of file |
|
390 | else if(strcmp(cmd,"CHGB") == 0){ | |
389 | cambia_apuntamiento(rx_data); No newline at end of file |
|
391 | cambia_apuntamiento(rx_data); | |
390 | tx_data = (char*)malloc(3); No newline at end of file |
|
392 | tx_data = (char*)malloc(3); | |
391 | tx_data = "OK"; No newline at end of file |
|
393 | tx_data = "OK"; | |
392 | } No newline at end of file |
|
394 | } | |
393 | else if(strcmp(cmd,"ANST") == 0){ No newline at end of file |
|
395 | else if(strcmp(cmd,"ANST") == 0){ | |
394 | tx_data = chequeo_sistema(filename2,rx_data); No newline at end of file |
|
396 | tx_data = chequeo_sistema(filename2,rx_data); | |
395 | printf("%s\n",tx_data); No newline at end of file |
|
397 | printf("%s\n",tx_data); | |
396 | } |
|
398 | } | |
No newline at end of file |
|
399 | else if(strcmp(cmd,"BGPH") == 0){ | ||
397 | else if(strcmp(cmd,"ANPH") == 0){ |
|
No newline at end of file | ||
No newline at end of file |
|
400 | tx_data = ABS_monitoreo(1, 0, 50, 10); | ||
398 | tx_data = ABS_monitoreo(1, 1, 50, 10); No newline at end of file |
|
No newline at end of file | ||
|
401 | // tx_data = "Not implemented\n"; | |||
|
No newline at end of file | ||||
|
402 | printf("%s\n",tx_data); | |||
|
No newline at end of file | ||||
|
403 | } | |||
|
No newline at end of file | ||||
|
404 | else if(strcmp(cmd,"LWPH") == 0){ | |||
|
No newline at end of file | ||||
|
405 | tx_data = ABS_monitoreo(0, 0, 50, 10); No newline at end of file | |||
399 | // tx_data = "Not implemented\n"; No newline at end of file |
|
406 | // tx_data = "Not implemented\n"; | |
400 | printf("%s\n",tx_data); No newline at end of file |
|
407 | printf("%s\n",tx_data); | |
401 | } No newline at end of file |
|
408 | } | |
402 | else if(strcmp(cmd,"NTST") == 0){ No newline at end of file |
|
409 | else if(strcmp(cmd,"NTST") == 0){ | |
403 | tx_data = malloc(strlen(parameters.ID) + 1); No newline at end of file |
|
410 | tx_data = malloc(strlen(parameters.ID) + 1); | |
404 | strcpy(tx_data,parameters.ID); No newline at end of file |
|
411 | strcpy(tx_data,parameters.ID); | |
405 | printf("%s\n",tx_data); No newline at end of file |
|
412 | printf("%s\n",tx_data); | |
406 | } No newline at end of file |
|
413 | } | |
407 | else{ No newline at end of file |
|
414 | else{ | |
408 | tx_data = (char*)malloc(6); No newline at end of file |
|
415 | tx_data = (char*)malloc(6); | |
409 | tx_data = "Error"; No newline at end of file |
|
416 | tx_data = "Error"; | |
410 | printf("procesa_peticion: comando no reconocido"); No newline at end of file |
|
417 | printf("procesa_peticion: comando no reconocido"); | |
411 | //ERROR("procesa_peticion: comando no reconocido"); No newline at end of file |
|
418 | //ERROR("procesa_peticion: comando no reconocido"); | |
412 | } No newline at end of file |
|
419 | } | |
413 | No newline at end of file |
|
420 | ||
414 | tx_len = malloc(7); No newline at end of file |
|
421 | tx_len = malloc(7); | |
415 | int number = strlen(tx_data); No newline at end of file |
|
422 | int number = strlen(tx_data); | |
416 | intToStr(number, tx_len ); No newline at end of file |
|
423 | intToStr(number, tx_len ); | |
417 | No newline at end of file |
|
424 | ||
418 | strcpy(tx_buffer,header); //3 No newline at end of file |
|
425 | strcpy(tx_buffer,header); //3 | |
419 | strcat(tx_buffer,TypeOfInstrument); //3 No newline at end of file |
|
426 | strcat(tx_buffer,TypeOfInstrument); //3 | |
420 | strcat(tx_buffer,parameters.ID); //7 No newline at end of file |
|
427 | strcat(tx_buffer,parameters.ID); //7 | |
421 | strcat(tx_buffer,iDSource); //7 No newline at end of file |
|
428 | strcat(tx_buffer,iDSource); //7 | |
422 | strcat(tx_buffer,tx_len); //6 No newline at end of file |
|
429 | strcat(tx_buffer,tx_len); //6 | |
423 | strcat(tx_buffer,cmd); //4 No newline at end of file |
|
430 | strcat(tx_buffer,cmd); //4 | |
424 | strcat(tx_buffer,tx_data); //? No newline at end of file |
|
431 | strcat(tx_buffer,tx_data); //? | |
425 | strcat(tx_buffer,crc); //1 No newline at end of file |
|
432 | strcat(tx_buffer,crc); //1 | |
426 | No newline at end of file |
|
433 | ||
427 | } No newline at end of file |
|
434 | } | |
428 | No newline at end of file |
|
435 | ||
429 | } No newline at end of file |
|
436 | } | |
430 | No newline at end of file |
|
437 | ||
431 | /* No newline at end of file |
|
438 | /* | |
432 | * Esta función genera el archivo de experimento a partir de la trama TCP recibida No newline at end of file |
|
439 | * Esta función genera el archivo de experimento a partir de la trama TCP recibida | |
433 | */ No newline at end of file |
|
440 | */ | |
434 | void recibe_experimento(char *p_data, char filename[]){ No newline at end of file |
|
441 | void recibe_experimento(char *p_data, char filename[]){ | |
435 | FILE *fd; No newline at end of file |
|
442 | FILE *fd; | |
436 | int i = 0; No newline at end of file |
|
443 | int i = 0; | |
437 | No newline at end of file |
|
444 | ||
438 | while (*p_data != '\n'){ No newline at end of file |
|
445 | while (*p_data != '\n'){ | |
439 | filename[i] = *p_data; No newline at end of file |
|
446 | filename[i] = *p_data; | |
440 | i++; No newline at end of file |
|
447 | i++; | |
441 | p_data++; No newline at end of file |
|
448 | p_data++; | |
442 | } No newline at end of file |
|
449 | } | |
443 | filename[i] = '\0'; No newline at end of file |
|
450 | filename[i] = '\0'; | |
444 | p_data = p_data - i; No newline at end of file |
|
451 | p_data = p_data - i; | |
445 | fd = fopen(filename,"w"); No newline at end of file |
|
452 | fd = fopen(filename,"w"); | |
446 | fprintf(fd, p_data); No newline at end of file |
|
453 | fprintf(fd, p_data); | |
447 | fclose(fd); No newline at end of file |
|
454 | fclose(fd); | |
448 | } No newline at end of file |
|
455 | } | |
449 | No newline at end of file |
|
456 | ||
450 | /* No newline at end of file |
|
457 | /* | |
451 | * Esta funcion carga un archivo en un buffer que esta ubicado en memoria, luego No newline at end of file |
|
458 | * Esta funcion carga un archivo en un buffer que esta ubicado en memoria, luego | |
452 | * este buffer es usado en la funcion "cambia_apuntamiento" para obtener el dato No newline at end of file |
|
459 | * este buffer es usado en la funcion "cambia_apuntamiento" para obtener el dato | |
453 | * que sera usado en el cambio de apuntamiento. No newline at end of file |
|
460 | * que sera usado en el cambio de apuntamiento. | |
454 | */ No newline at end of file |
|
461 | */ | |
455 | int carga_experimento(char *nombre_archivo){ No newline at end of file |
|
462 | int carga_experimento(char *nombre_archivo){ | |
456 | No newline at end of file |
|
463 | ||
457 | FILE *Archivo_Fd; No newline at end of file |
|
464 | FILE *Archivo_Fd; | |
458 | No newline at end of file |
|
465 | ||
459 | char *cadena = (char *) malloc(25); No newline at end of file |
|
466 | char *cadena = (char *) malloc(25); | |
460 | No newline at end of file |
|
467 | ||
461 | int longitud_cadena; No newline at end of file |
|
468 | int longitud_cadena; | |
462 | int num_bytes= 0; No newline at end of file |
|
469 | int num_bytes= 0; | |
463 | int num_filas= 0; No newline at end of file |
|
470 | int num_filas= 0; | |
464 | No newline at end of file |
|
471 | ||
465 | Archivo_Fd = fopen(nombre_archivo,"r"); // Se procede a abrir el archivo, segun la ruta especificada No newline at end of file |
|
472 | Archivo_Fd = fopen(nombre_archivo,"r"); // Se procede a abrir el archivo, segun la ruta especificada | |
466 | if(!Archivo_Fd){ No newline at end of file |
|
473 | if(!Archivo_Fd){ | |
467 | printf("carga_archivo: No se pudo abrir el archivo!!! --> fopen()\n"); No newline at end of file |
|
474 | printf("carga_archivo: No se pudo abrir el archivo!!! --> fopen()\n"); | |
468 | //ERROR("carga_archivo: No se pudo abrir el archivo!!! --> fopen()\n"); No newline at end of file |
|
475 | //ERROR("carga_archivo: No se pudo abrir el archivo!!! --> fopen()\n"); | |
469 | return -1; No newline at end of file |
|
476 | return -1; | |
470 | }else{ No newline at end of file |
|
477 | }else{ | |
471 | No newline at end of file |
|
478 | ||
472 | while(!feof(Archivo_Fd)){ // Se procede a calcular la longitud del archivo para separar memoria No newline at end of file |
|
479 | while(!feof(Archivo_Fd)){ // Se procede a calcular la longitud del archivo para separar memoria | |
473 | fgets(cadena,20,Archivo_Fd); No newline at end of file |
|
480 | fgets(cadena,20,Archivo_Fd); | |
474 | longitud_cadena= strlen(cadena); No newline at end of file |
|
481 | longitud_cadena= strlen(cadena); | |
475 | cadena[longitud_cadena-1] = '\0'; No newline at end of file |
|
482 | cadena[longitud_cadena-1] = '\0'; | |
476 | num_bytes = num_bytes + longitud_cadena; No newline at end of file |
|
483 | num_bytes = num_bytes + longitud_cadena; | |
477 | num_filas++; No newline at end of file |
|
484 | num_filas++; | |
478 | } No newline at end of file |
|
485 | } | |
479 | No newline at end of file |
|
486 | ||
480 | rewind(Archivo_Fd); // Se reinicia el puntero del archivo No newline at end of file |
|
487 | rewind(Archivo_Fd); // Se reinicia el puntero del archivo | |
481 | No newline at end of file |
|
488 | ||
482 | char *buffer_temporal = (char *) malloc(num_bytes+1); // Se separa espacio de memoria segun No newline at end of file |
|
489 | char *buffer_temporal = (char *) malloc(num_bytes+1); // Se separa espacio de memoria segun | |
483 | // la longitud del archivo No newline at end of file |
|
490 | // la longitud del archivo | |
484 | fread(buffer_temporal, sizeof(char), num_bytes, Archivo_Fd); No newline at end of file |
|
491 | fread(buffer_temporal, sizeof(char), num_bytes, Archivo_Fd); | |
485 | No newline at end of file |
|
492 | ||
486 | char *puntero= strstr(buffer_temporal,".ab1"); // Se procede a eliminar la cabecera del archivo No newline at end of file |
|
493 | char *puntero= strstr(buffer_temporal,".ab1"); // Se procede a eliminar la cabecera del archivo | |
487 | puntero= puntero + 12; No newline at end of file |
|
494 | puntero= puntero + 12; | |
488 | No newline at end of file |
|
495 | ||
489 | buff_experimento = (char *) malloc(7*(num_filas-3)); // num_bytes_fila*(num_filas-3); No newline at end of file |
|
496 | buff_experimento = (char *) malloc(7*(num_filas-3)); // num_bytes_fila*(num_filas-3); | |
490 | strncpy(buff_experimento,puntero,7*(num_filas-3)); // Se carga en memoria la informacion del archivo No newline at end of file |
|
497 | strncpy(buff_experimento,puntero,7*(num_filas-3)); // Se carga en memoria la informacion del archivo | |
491 | No newline at end of file |
|
498 | ||
492 | fclose(Archivo_Fd); No newline at end of file |
|
499 | fclose(Archivo_Fd); | |
493 | No newline at end of file |
|
500 | ||
494 | return 1; No newline at end of file |
|
501 | return 1; | |
495 | } No newline at end of file |
|
502 | } | |
496 | } No newline at end of file |
|
503 | } | |
497 | No newline at end of file |
|
504 | ||
498 | /* No newline at end of file |
|
505 | /* | |
499 | * Esta funcion recibe un numero en formato char, el dato se transforma a su equivalente en No newline at end of file |
|
506 | * Esta funcion recibe un numero en formato char, el dato se transforma a su equivalente en | |
500 | * un numero entero, que sera usado para sacar un dato del buffer "buff_experimento", esta No newline at end of file |
|
507 | * un numero entero, que sera usado para sacar un dato del buffer "buff_experimento", esta | |
501 | * dato es el valor que se enviara al sistema de conmutacion RF para el cambio de apunte a No newline at end of file |
|
508 | * dato es el valor que se enviara al sistema de conmutacion RF para el cambio de apunte a | |
502 | * traves del puerto GPIO. No newline at end of file |
|
509 | * traves del puerto GPIO. | |
503 | */ No newline at end of file |
|
510 | */ | |
504 | int cambia_apuntamiento(char *puntero_char){ No newline at end of file |
|
511 | int cambia_apuntamiento(char *puntero_char){ | |
505 | No newline at end of file |
|
512 | ||
506 | /*MSB-UP-LSB MSB-DOWN-LSB*/ No newline at end of file |
|
513 | /*MSB-UP-LSB MSB-DOWN-LSB*/ | |
507 | int desplazamiento[6]={30,28,26,24,22,20}; // Defino los dezplazamientos que se aplicara No newline at end of file |
|
514 | int desplazamiento[6]={30,28,26,24,22,20}; // Defino los dezplazamientos que se aplicara | |
508 | // al dato que ingresa para formar el número No newline at end of file |
|
515 | // al dato que ingresa para formar el número | |
509 | // entero que se le pasara al puerto GPIO No newline at end of file |
|
516 | // entero que se le pasara al puerto GPIO | |
510 | // Estos números son los pines del puerto GPIO No newline at end of file |
|
517 | // Estos números son los pines del puerto GPIO | |
511 | // que se estan usando para el control No newline at end of file |
|
518 | // que se estan usando para el control | |
512 | No newline at end of file |
|
519 | ||
513 | int puntero= atoi(puntero_char); // Se convierte a entero la direccion del puntero No newline at end of file |
|
520 | int puntero= atoi(puntero_char); // Se convierte a entero la direccion del puntero | |
514 | No newline at end of file |
|
521 | ||
515 | int base= 7*puntero; // base= cantidad_bytes del dato x puntero No newline at end of file |
|
522 | int base= 7*puntero; // base= cantidad_bytes del dato x puntero | |
516 | // cantidad de bytes es el numero de bytes que No newline at end of file |
|
523 | // cantidad de bytes es el numero de bytes que | |
517 | printf("%s\n",puntero_char); // contiene cada dato, para este caso es 7 No newline at end of file |
|
524 | printf("%s\n",puntero_char); // contiene cada dato, para este caso es 7 | |
518 | // porque es 6 bits de datos + 1 bit del cambio No newline at end of file |
|
525 | // porque es 6 bits de datos + 1 bit del cambio | |
519 | // de linea. No newline at end of file |
|
526 | // de linea. | |
520 | char valor_char; No newline at end of file |
|
527 | char valor_char; | |
521 | unsigned long valor; No newline at end of file |
|
528 | unsigned long valor; | |
522 | unsigned long acumulado_ceros=0; No newline at end of file |
|
529 | unsigned long acumulado_ceros=0; | |
523 | unsigned long acumulado_unos=0; No newline at end of file |
|
530 | unsigned long acumulado_unos=0; | |
524 | No newline at end of file |
|
531 | ||
525 | int offset; // Defino offset para el desplazamiento a traves No newline at end of file |
|
532 | int offset; // Defino offset para el desplazamiento a traves | |
526 | for(offset=0;offset<6;offset++){ // de cada dato que se obtiene del "buff_experimento" No newline at end of file |
|
533 | for(offset=0;offset<6;offset++){ // de cada dato que se obtiene del "buff_experimento" | |
527 | No newline at end of file |
|
534 | ||
528 | valor_char= buff_experimento[base+offset]; // Obtengo el dato No newline at end of file |
|
535 | valor_char= buff_experimento[base+offset]; // Obtengo el dato | |
529 | No newline at end of file |
|
536 | ||
530 | if (valor_char == '0'){ // Obtengo el número acumulado segun sea un cero o un uno No newline at end of file |
|
537 | if (valor_char == '0'){ // Obtengo el número acumulado segun sea un cero o un uno | |
531 | valor= 0; No newline at end of file |
|
538 | valor= 0; | |
532 | acumulado_ceros= acumulado_ceros + (1 << desplazamiento[offset]); No newline at end of file |
|
539 | acumulado_ceros= acumulado_ceros + (1 << desplazamiento[offset]); | |
533 | }else{ No newline at end of file |
|
540 | }else{ | |
534 | valor= 1; No newline at end of file |
|
541 | valor= 1; | |
535 | acumulado_unos= acumulado_unos + (1 << desplazamiento[offset]); No newline at end of file |
|
542 | acumulado_unos= acumulado_unos + (1 << desplazamiento[offset]); | |
536 | } No newline at end of file |
|
543 | } | |
537 | } No newline at end of file |
|
544 | } | |
538 | pio_out(pioc, maskc_out_beam, acumulado_unos, 1); No newline at end of file |
|
545 | pio_out(pioc, maskc_out_beam, acumulado_unos, 1); | |
539 | pio_out(pioc, maskc_out_beam, acumulado_ceros, 0); No newline at end of file |
|
546 | pio_out(pioc, maskc_out_beam, acumulado_ceros, 0); | |
540 | No newline at end of file |
|
547 | ||
541 | return 1; No newline at end of file |
|
548 | return 1; | |
542 | No newline at end of file |
|
549 | ||
543 | } No newline at end of file |
|
550 | } | |
544 | No newline at end of file |
|
551 | ||
545 | /* No newline at end of file |
|
552 | /* | |
546 | * Esta funcion lee "n" veces el estado del APUNTE actual y reporta No newline at end of file |
|
553 | * Esta funcion lee "n" veces el estado del APUNTE actual y reporta | |
547 | * una cadena de Verificacion. No newline at end of file |
|
554 | * una cadena de Verificacion. | |
548 | */ No newline at end of file |
|
555 | */ | |
549 | char* chequeo_sistema(char *filename, char *numero_muestras){ No newline at end of file |
|
556 | char* chequeo_sistema(char *filename, char *numero_muestras){ | |
550 | No newline at end of file |
|
557 | ||
551 | int i; No newline at end of file |
|
558 | int i; | |
552 | int cnt = 0; No newline at end of file |
|
559 | int cnt = 0; | |
553 | unsigned int entradac= 0; No newline at end of file |
|
560 | unsigned int entradac= 0; | |
554 | No newline at end of file |
|
561 | ||
555 | char page0[250]; No newline at end of file |
|
562 | char page0[250]; | |
556 | No newline at end of file |
|
563 | ||
557 | /*strcpy(page0,"Verificacion\n"); No newline at end of file |
|
564 | /*strcpy(page0,"Verificacion\n"); | |
558 | strcat(page0,parameters.ID);*/ No newline at end of file |
|
565 | strcat(page0,parameters.ID);*/ | |
559 | strcpy(page0,parameters.ID); No newline at end of file |
|
566 | strcpy(page0,parameters.ID); | |
560 | strcat(page0,"\n-------\n"); No newline at end of file |
|
567 | strcat(page0,"\n-------\n"); | |
561 | No newline at end of file |
|
568 | ||
562 | char page1[8]; No newline at end of file |
|
569 | char page1[8]; | |
563 | No newline at end of file |
|
570 | ||
564 | do{ No newline at end of file |
|
571 | do{ | |
565 | //Inicializando arreglo No newline at end of file |
|
572 | //Inicializando arreglo | |
566 | for(i=0;i<6;i++) No newline at end of file |
|
573 | for(i=0;i<6;i++) | |
567 | page1[i]='0'; No newline at end of file |
|
574 | page1[i]='0'; | |
568 | page1[6] = '\n'; No newline at end of file |
|
575 | page1[6] = '\n'; | |
569 | page1[7] = '\0'; No newline at end of file |
|
576 | page1[7] = '\0'; | |
570 | //Lectura de puerto No newline at end of file |
|
577 | //Lectura de puerto | |
571 | entradac= pio_in(piob,maskb_in); No newline at end of file |
|
578 | entradac= pio_in(piob,maskb_in); | |
572 | //Dandole formato al dato No newline at end of file |
|
579 | //Dandole formato al dato | |
573 | if (!(entradac & bit_up_2)) No newline at end of file |
|
580 | if (!(entradac & bit_up_2)) | |
574 | page1[0] = '1'; No newline at end of file |
|
581 | page1[0] = '1'; | |
575 | if (!(entradac & bit_up_1)) No newline at end of file |
|
582 | if (!(entradac & bit_up_1)) | |
576 | page1[1] = '1'; No newline at end of file |
|
583 | page1[1] = '1'; | |
577 | if (!(entradac & bit_up_0)) No newline at end of file |
|
584 | if (!(entradac & bit_up_0)) | |
578 | page1[2] = '1'; No newline at end of file |
|
585 | page1[2] = '1'; | |
579 | if (!(entradac & bit_dow_2)) No newline at end of file |
|
586 | if (!(entradac & bit_dow_2)) | |
580 | page1[3] = '1'; No newline at end of file |
|
587 | page1[3] = '1'; | |
581 | if (!(entradac & bit_dow_1)) No newline at end of file |
|
588 | if (!(entradac & bit_dow_1)) | |
582 | page1[4] = '1'; No newline at end of file |
|
589 | page1[4] = '1'; | |
583 | if (!(entradac & bit_dow_0)) No newline at end of file |
|
590 | if (!(entradac & bit_dow_0)) | |
584 | page1[5] = '1'; No newline at end of file |
|
591 | page1[5] = '1'; | |
585 | No newline at end of file |
|
592 | ||
586 | strcat(page0, page1); No newline at end of file |
|
593 | strcat(page0, page1); | |
587 | cnt=cnt+1; No newline at end of file |
|
594 | cnt=cnt+1; | |
588 | usleep(1*1000*1000); No newline at end of file |
|
595 | usleep(1*1000*1000); | |
589 | No newline at end of file |
|
596 | ||
590 | }while(cnt < atoi(numero_muestras)); No newline at end of file |
|
597 | }while(cnt < atoi(numero_muestras)); | |
591 | No newline at end of file |
|
598 | ||
592 | page0[strlen(page0)] = '\0'; No newline at end of file |
|
599 | page0[strlen(page0)] = '\0'; | |
593 | No newline at end of file |
|
600 | ||
594 | char *all_pages = malloc(strlen(page0)+1); No newline at end of file |
|
601 | char *all_pages = malloc(strlen(page0)+1); | |
595 | strcpy(all_pages, page0); No newline at end of file |
|
602 | strcpy(all_pages, page0); | |
596 | return all_pages; No newline at end of file |
|
603 | return all_pages; | |
597 | } No newline at end of file |
|
604 | } | |
598 | No newline at end of file |
|
605 | ||
599 | /* No newline at end of file |
|
606 | /* | |
600 | * No newline at end of file |
|
607 | * | |
601 | */ No newline at end of file |
|
608 | */ | |
602 | cmp inicializa_modulo(cmp p){ No newline at end of file |
|
609 | cmp inicializa_modulo(cmp p){ | |
603 | FILE *fd = fopen("configuration.txt","r"); No newline at end of file |
|
610 | FILE *fd = fopen("configuration.txt","r"); | |
604 | fgets(p.ID,20,fd); No newline at end of file |
|
611 | fgets(p.ID,20,fd); | |
605 | p.ID[7]='\0'; No newline at end of file |
|
612 | p.ID[7]='\0'; | |
606 | fgets(p.param2,20,fd); No newline at end of file |
|
613 | fgets(p.param2,20,fd); | |
607 | p.param2[10]='\0'; No newline at end of file |
|
614 | p.param2[10]='\0'; | |
608 | fgets(p.param3,20,fd); No newline at end of file |
|
615 | fgets(p.param3,20,fd); | |
609 | p.param3[10]='\0'; No newline at end of file |
|
616 | p.param3[10]='\0'; | |
610 | fgets(p.param4,20,fd); No newline at end of file |
|
617 | fgets(p.param4,20,fd); | |
611 | p.param4[10]='\0'; No newline at end of file |
|
618 | p.param4[10]='\0'; | |
612 | fclose(fd); No newline at end of file |
|
619 | fclose(fd); | |
613 | return p; No newline at end of file |
|
620 | return p; | |
614 | } No newline at end of file |
|
621 | } | |
615 | No newline at end of file |
|
622 | ||
616 | /* No newline at end of file |
|
623 | /* | |
617 | * No newline at end of file |
|
624 | * | |
618 | */ No newline at end of file |
|
625 | */ | |
619 | void intToStr( int number, char* str ) No newline at end of file |
|
626 | void intToStr( int number, char* str ) | |
620 | No newline at end of file |
|
627 | ||
621 | { No newline at end of file |
|
628 | { | |
622 | int index = 0; No newline at end of file |
|
629 | int index = 0; | |
623 | No newline at end of file |
|
630 | ||
624 | while( number > 0 ) No newline at end of file |
|
631 | while( number > 0 ) | |
625 | { No newline at end of file |
|
632 | { | |
626 | int digit = number%10; No newline at end of file |
|
633 | int digit = number%10; | |
627 | str[index++] = digit + '0'; No newline at end of file |
|
634 | str[index++] = digit + '0'; | |
628 | number /= 10; No newline at end of file |
|
635 | number /= 10; | |
629 | } No newline at end of file |
|
636 | } | |
630 | str[index] = '\0'; No newline at end of file |
|
637 | str[index] = '\0'; | |
631 | //Adding zero to the left No newline at end of file |
|
638 | //Adding zero to the left | |
632 | int n= strlen(str); No newline at end of file |
|
639 | int n= strlen(str); | |
633 | if (n == 1) { No newline at end of file |
|
640 | if (n == 1) { | |
634 | strcat(str,"00000"); No newline at end of file |
|
641 | strcat(str,"00000"); | |
635 | index = index + 5; No newline at end of file |
|
642 | index = index + 5; | |
636 | }else if(n == 2){ No newline at end of file |
|
643 | }else if(n == 2){ | |
637 | strcat(str,"0000"); No newline at end of file |
|
644 | strcat(str,"0000"); | |
638 | index = index + 4; No newline at end of file |
|
645 | index = index + 4; | |
639 | }else if(n == 3){ No newline at end of file |
|
646 | }else if(n == 3){ | |
640 | strcat(str,"000"); No newline at end of file |
|
647 | strcat(str,"000"); | |
641 | index = index + 3; No newline at end of file |
|
648 | index = index + 3; | |
642 | }else if(n == 4){ No newline at end of file |
|
649 | }else if(n == 4){ | |
643 | strcat(str,"00"); No newline at end of file |
|
650 | strcat(str,"00"); | |
644 | index = index + 2; No newline at end of file |
|
651 | index = index + 2; | |
645 | }else if(n == 5){ No newline at end of file |
|
652 | }else if(n == 5){ | |
646 | strcat(str,"0"); No newline at end of file |
|
653 | strcat(str,"0"); | |
647 | index = index + 1; No newline at end of file |
|
654 | index = index + 1; | |
648 | } No newline at end of file |
|
655 | } | |
649 | //Now reverse the numbers in the string. No newline at end of file |
|
656 | //Now reverse the numbers in the string. | |
650 | int position; No newline at end of file |
|
657 | int position; | |
651 | for( position = 0; position <= (index-1)/2; ++position ) No newline at end of file |
|
658 | for( position = 0; position <= (index-1)/2; ++position ) | |
652 | { No newline at end of file |
|
659 | { | |
653 | char tmp = str[position]; No newline at end of file |
|
660 | char tmp = str[position]; | |
654 | str[position] = str[(index-1)-position]; No newline at end of file |
|
661 | str[position] = str[(index-1)-position]; | |
655 | str[(index-1)-position] = tmp; No newline at end of file |
|
662 | str[(index-1)-position] = tmp; | |
656 | } No newline at end of file |
|
663 | } | |
657 | } No newline at end of file |
|
664 | } | |
658 | No newline at end of file |
|
665 | ||
659 | No newline at end of file |
|
666 | ||
660 | //***************************************************************** No newline at end of file |
|
667 | //***************************************************************** | |
661 | //ABS_monitoreo es la funci�n principal del proyecto ABS_Monitoreo. No newline at end of file |
|
668 | //ABS_monitoreo es la funci�n principal del proyecto ABS_Monitoreo. | |
662 | //Esta funci�n es la que se debe agregar en otros c�digos. No newline at end of file |
|
669 | //Esta funci�n es la que se debe agregar en otros c�digos. | |
663 | //***************************************************************** No newline at end of file |
|
670 | //***************************************************************** | |
664 | char* ABS_monitoreo(int sel_atenuador, int sel_calibracion, float umbral, int pulsewidth){ No newline at end of file |
|
671 | char* ABS_monitoreo(int sel_atenuador, int sel_calibracion, float umbral, int pulsewidth){ | |
665 | No newline at end of file |
|
672 | ||
666 | //local variables No newline at end of file |
|
673 | //local variables | |
667 | /* AT91S_PIO *pioc; No newline at end of file |
|
674 | /* AT91S_PIO *pioc; | |
668 | pioc = pio_map(PIOC_BASE); No newline at end of file |
|
675 | pioc = pio_map(PIOC_BASE); | |
669 | unsigned int mask_sel_canal =PC4; //Aqu� se indican los pines que se desean usar como salidas. Las constantes PCx est�n defiidas en el header at91gpio.h No newline at end of file |
|
676 | unsigned int mask_sel_canal =PC4; //Aqu� se indican los pines que se desean usar como salidas. Las constantes PCx est�n defiidas en el header at91gpio.h | |
670 | unsigned int mask_sel_atenuacion =PC5; No newline at end of file |
|
677 | unsigned int mask_sel_atenuacion =PC5; | |
671 | unsigned int mask_sel_calibracion =PC6;*/ No newline at end of file |
|
678 | unsigned int mask_sel_calibracion =PC6;*/ | |
672 | No newline at end of file |
|
679 | ||
673 | unsigned long acumulado_ceros=0; No newline at end of file |
|
680 | unsigned long acumulado_ceros=0; | |
674 | unsigned long acumulado_unos=0; No newline at end of file |
|
681 | unsigned long acumulado_unos=0; | |
675 | /* AT91S_ADC *padc; No newline at end of file |
|
682 | /* AT91S_ADC *padc; | |
676 | AT91S_ADC *padd;*/ No newline at end of file |
|
683 | AT91S_ADC *padd;*/ | |
677 | FILE *fp; No newline at end of file |
|
684 | FILE *fp; | |
678 | long int results1[NSAMPLES], results2[NSAMPLES], results3[NSAMPLES], results4[NSAMPLES]; No newline at end of file |
|
685 | long int results1[NSAMPLES], results2[NSAMPLES], results3[NSAMPLES], results4[NSAMPLES]; | |
679 | unsigned int i=0; No newline at end of file |
|
686 | unsigned int i=0; | |
680 | char fname[FNAMELEN]; No newline at end of file |
|
687 | char fname[FNAMELEN]; | |
681 | int j=0; No newline at end of file |
|
688 | int j=0; | |
682 | time_t now; No newline at end of file |
|
689 | time_t now; | |
683 | FILE *archivo; No newline at end of file |
|
690 | FILE *archivo; | |
684 | float phase1; No newline at end of file |
|
691 | float phase1; | |
685 | float phase2; No newline at end of file |
|
692 | float phase2; | |
686 | char page0[30]; No newline at end of file |
|
693 | char page0[30]; | |
687 | char page1[20]; No newline at end of file |
|
694 | char page1[20]; | |
|
695 | ||||
|
No newline at end of file | ||||
|
696 | int cnt = 0; No newline at end of file | |||
688 | //system("./map_clock"); No newline at end of file |
|
697 | //system("./map_clock"); | |
689 | /* No newline at end of file |
|
698 | /* | |
690 | if (configCLK() == 1) No newline at end of file |
|
699 | if (configCLK() == 1) | |
691 | printf("clock ADC enable.\n"); No newline at end of file |
|
700 | printf("clock ADC enable.\n"); | |
692 | */ No newline at end of file |
|
701 | */ | |
693 | /* No newline at end of file |
|
702 | /* | |
694 | //configurar tres pines como salida usando als m�scaras mask_sel_canal, mask_sel_atenuacion y mask_sel_calibracion. En este caso corresponden a los pines pc4, pc5 y pc6. No newline at end of file |
|
703 | //configurar tres pines como salida usando als m�scaras mask_sel_canal, mask_sel_atenuacion y mask_sel_calibracion. En este caso corresponden a los pines pc4, pc5 y pc6. | |
695 | pio_enable(pioc, mask_sel_canal); No newline at end of file |
|
704 | pio_enable(pioc, mask_sel_canal); | |
696 | pio_enable(pioc, mask_sel_atenuacion); No newline at end of file |
|
705 | pio_enable(pioc, mask_sel_atenuacion); | |
697 | pio_enable(pioc, mask_sel_calibracion); No newline at end of file |
|
706 | pio_enable(pioc, mask_sel_calibracion); | |
698 | pio_output_enable(pioc, mask_sel_canal); //configurar pc4 como salida No newline at end of file |
|
707 | pio_output_enable(pioc, mask_sel_canal); //configurar pc4 como salida | |
699 | pio_output_enable(pioc, mask_sel_atenuacion); //configurar pc5 como salida No newline at end of file |
|
708 | pio_output_enable(pioc, mask_sel_atenuacion); //configurar pc5 como salida | |
700 | pio_output_enable(pioc, mask_sel_calibracion); //configurar pc6 como salida No newline at end of file |
|
709 | pio_output_enable(pioc, mask_sel_calibracion); //configurar pc6 como salida | |
701 | */ No newline at end of file |
|
710 | */ | |
702 | No newline at end of file |
|
711 | ||
703 | //Se modifican las salidas correspondientes a la selecci�n del atenuador y calibraci�n, de acuerdo a los par�metros ingresados en la funci�n ABS_monitoreo. No newline at end of file |
|
712 | //Se modifican las salidas correspondientes a la selecci�n del atenuador y calibraci�n, de acuerdo a los par�metros ingresados en la funci�n ABS_monitoreo. | |
704 | /*if ( sel_atenuador == 1) No newline at end of file |
|
713 | /*if ( sel_atenuador == 1) | |
705 | pio_out(pioc, mask_sel_atenuacion, sel_atenuador,1); No newline at end of file |
|
714 | pio_out(pioc, mask_sel_atenuacion, sel_atenuador,1); | |
706 | else No newline at end of file |
|
715 | else | |
707 | pio_out(pioc, mask_sel_atenuacion, sel_atenuador,0); No newline at end of file |
|
716 | pio_out(pioc, mask_sel_atenuacion, sel_atenuador,0); | |
708 | if ( sel_calibracion == 1) No newline at end of file |
|
717 | if ( sel_calibracion == 1) | |
709 | pio_out(pioc, mask_sel_calibracion, sel_calibracion,1); No newline at end of file |
|
718 | pio_out(pioc, mask_sel_calibracion, sel_calibracion,1); | |
710 | else No newline at end of file |
|
719 | else | |
711 | pio_out(pioc, mask_sel_calibracion, sel_calibracion,0);*/ No newline at end of file |
|
720 | pio_out(pioc, mask_sel_calibracion, sel_calibracion,0);*/ | |
712 | No newline at end of file |
|
721 | ||
713 | if ( sel_atenuador == 1) No newline at end of file |
|
722 | if ( sel_atenuador == 1) | |
714 | acumulado_unos = acumulado_unos + (1 << 5); No newline at end of file |
|
723 | acumulado_unos = acumulado_unos + (1 << 5); | |
715 | else No newline at end of file |
|
724 | else | |
716 | acumulado_ceros = acumulado_ceros + (1 << 5); No newline at end of file |
|
725 | acumulado_ceros = acumulado_ceros + (1 << 5); | |
717 | if ( sel_calibracion == 1) No newline at end of file |
|
726 | if ( sel_calibracion == 1) | |
718 | acumulado_unos = acumulado_unos + (1 << 6); No newline at end of file |
|
727 | acumulado_unos = acumulado_unos + (1 << 6); | |
719 | else No newline at end of file |
|
728 | else | |
720 | acumulado_ceros = acumulado_ceros + (1 << 6); No newline at end of file |
|
729 | acumulado_ceros = acumulado_ceros + (1 << 6); | |
721 | No newline at end of file |
|
730 | ||
722 | No newline at end of file |
|
731 | ||
723 | strcpy (fname, "/mnt/sd/absmonitoreo.txt"); //Direcci�n y nombre del archivo donde se desea guardar los datos. No newline at end of file |
|
732 | strcpy (fname, "/mnt/sd/absmonitoreo.txt"); //Direcci�n y nombre del archivo donde se desea guardar los datos. | |
724 | No newline at end of file |
|
733 | ||
725 | if (fExists(fname)==0){ //si el archivo no existe, crea uno y le asigna el titulo No newline at end of file |
|
734 | if (fExists(fname)==0){ //si el archivo no existe, crea uno y le asigna el titulo | |
726 | archivo = fopen(fname,"a+"); No newline at end of file |
|
735 | archivo = fopen(fname,"a+"); | |
727 | fprintf(archivo,"%s"," Registro de datos del ABS Control \n"); No newline at end of file |
|
736 | fprintf(archivo,"%s"," Registro de datos del ABS Control \n"); | |
728 | fprintf(archivo,"%s"," Fecha y hora Fase UP Fase DOWN\n"); No newline at end of file |
|
737 | fprintf(archivo,"%s"," Fecha y hora Fase UP Fase DOWN\n"); | |
729 | fclose(archivo); No newline at end of file |
|
738 | fclose(archivo); | |
730 | } No newline at end of file |
|
739 | } | |
731 | No newline at end of file |
|
740 | ||
732 | /* No newline at end of file |
|
741 | /* | |
733 | //configure ADC Settings No newline at end of file |
|
742 | //configure ADC Settings | |
734 | padc=configADC1(); No newline at end of file |
|
743 | padc=configADC1(); | |
735 | padd=configADC2(); No newline at end of file |
|
744 | padd=configADC2(); | |
736 | */ No newline at end of file |
|
745 | */ | |
737 | //while (1){ No newline at end of file |
|
746 | //while (1){ | |
738 | No newline at end of file |
|
747 | ||
739 | ENABLE_CHANNEL(padc, ADC_CH0+ADC_CH1); No newline at end of file |
|
748 | ENABLE_CHANNEL(padc, ADC_CH0+ADC_CH1); | |
740 | printf("\nAdquiriendo datos...\n"); //Indica en el terminal que se est�n adquiriendo datos (muestreando la se�al). No newline at end of file |
|
749 | printf("\nAdquiriendo datos...\n"); //Indica en el terminal que se est�n adquiriendo datos (muestreando la se�al). | |
741 | No newline at end of file |
|
750 | ||
742 | No newline at end of file |
|
751 | ||
743 | now = time(0); //Get current Time for File Name No newline at end of file |
|
752 | now = time(0); //Get current Time for File Name | |
744 | No newline at end of file |
|
753 | ||
745 | //Se pone la salida de selecci�n de canal para seleccionar el canal 1 del detector de fase No newline at end of file |
|
754 | //Se pone la salida de selecci�n de canal para seleccionar el canal 1 del detector de fase | |
746 | acumulado_ceros = acumulado_ceros + (1 << 4); No newline at end of file |
|
755 | acumulado_ceros = acumulado_ceros + (1 << 4); | |
747 | pio_out(pioc, maskc_out_cntl, acumulado_ceros, 0); No newline at end of file |
|
756 | pio_out(pioc, maskc_out_cntl, acumulado_ceros, 0); | |
748 | pio_out(pioc, maskc_out_cntl, acumulado_unos, 1); No newline at end of file |
|
757 | pio_out(pioc, maskc_out_cntl, acumulado_unos, 1); | |
749 | sleep(1); No newline at end of file |
|
758 | sleep(1); | |
750 | No newline at end of file |
|
759 | ||
751 | //Se toman muestras para el canal 1 del detector de fase |
|
760 | //Se toman muestras para el canal 1 del detector de fase | |
No newline at end of file |
|
761 | /*while(1){ No newline at end of file | ||
752 | //while(1){ No newline at end of file |
|
|||
753 | for(i=0; i < NSAMPLES; i++){ No newline at end of file |
|
762 | for(i=0; i < NSAMPLES; i++){ | |
754 |
|
|
763 | ||
755 | ADC_INIT(padc); No newline at end of file |
|
764 | ADC_INIT(padc); | |
756 | results1[i] = GET_ADC0(padc); No newline at end of file |
|
765 | results1[i] = GET_ADC0(padc); | |
757 | results2[i] = GET_ADC1(padd); No newline at end of file |
|
766 | results2[i] = GET_ADC1(padd); | |
758 | } |
|
767 | } | |
No newline at end of file |
|
768 | No newline at end of file | ||
759 | /* No newline at end of file |
|
|||
760 | if (checkTx(results1, results2, umbral, pulsewidth)==1){ //Se verifica que las muestras tomadas del canal 1 del datector de fase //correspondan a un pulso. No newline at end of file |
|
769 | if (checkTx(results1, results2, umbral, pulsewidth)==1){ //Se verifica que las muestras tomadas del canal 1 del datector de fase //correspondan a un pulso. | |
761 | break; No newline at end of file |
|
770 | break; | |
762 | } |
|
771 | } | |
No newline at end of file |
|
772 | |||
763 | */ |
|
No newline at end of file | ||
No newline at end of file |
|
773 | }*/ | ||
764 | //} |
|
No newline at end of file | ||
No newline at end of file |
|
774 | |||
765 | No newline at end of file |
|
No newline at end of file | ||
|
775 | do{ | |||
|
No newline at end of file | ||||
|
776 | for(i=0; i < NSAMPLES; i++){ | |||
|
No newline at end of file | ||||
|
777 | ||||
|
No newline at end of file | ||||
|
778 | ADC_INIT(padc); | |||
|
No newline at end of file | ||||
|
779 | results1[i] = GET_ADC0(padc); | |||
|
No newline at end of file | ||||
|
780 | results2[i] = GET_ADC1(padd); | |||
|
No newline at end of file | ||||
|
781 | } | |||
|
No newline at end of file | ||||
|
782 | ||||
|
No newline at end of file | ||||
|
783 | if (checkTx(results1, results2, umbral, pulsewidth)==1){ //Se verifica que las muestras tomadas del canal 1 del datector de fase //correspondan a un pulso. | |||
|
No newline at end of file | ||||
|
784 | break; | |||
|
No newline at end of file | ||||
|
785 | } | |||
|
No newline at end of file | ||||
|
786 | cnt += 1; | |||
|
No newline at end of file | ||||
|
787 | }while (cnt < NLOOPS); No newline at end of file | |||
766 | No newline at end of file |
|
788 | ||
767 | //Se pone la salida de selecci�n de canal para seleccionar el canal 2 del detector de fase No newline at end of file |
|
789 | //Se pone la salida de selecci�n de canal para seleccionar el canal 2 del detector de fase | |
768 | acumulado_ceros = acumulado_ceros - (1 << 4); No newline at end of file |
|
790 | acumulado_ceros = acumulado_ceros - (1 << 4); | |
769 | acumulado_unos = acumulado_unos + (1 << 4); No newline at end of file |
|
791 | acumulado_unos = acumulado_unos + (1 << 4); | |
770 | pio_out(pioc, maskc_out_cntl, acumulado_ceros, 0); No newline at end of file |
|
792 | pio_out(pioc, maskc_out_cntl, acumulado_ceros, 0); | |
771 | pio_out(pioc, maskc_out_cntl, acumulado_unos, 1); No newline at end of file |
|
793 | pio_out(pioc, maskc_out_cntl, acumulado_unos, 1); | |
772 | sleep(1); No newline at end of file |
|
794 | sleep(1); | |
773 | No newline at end of file |
|
795 | ||
774 | No newline at end of file |
|
796 | ||
775 | //Setoman muestras para el canal 2 del detector de fase |
|
797 | //Setoman muestras para el canal 2 del detector de fase | |
No newline at end of file |
|
798 | /* while(1){ No newline at end of file | ||
776 | // while(1){ No newline at end of file |
|
|||
777 | for(i=0; i < NSAMPLES; i++){ No newline at end of file |
|
799 | for(i=0; i < NSAMPLES; i++){ | |
778 |
|
|
800 | ||
779 | ADC_INIT(padc); No newline at end of file |
|
801 | ADC_INIT(padc); | |
780 | results3[i] = GET_ADC0(padc); No newline at end of file |
|
802 | results3[i] = GET_ADC0(padc); | |
781 | results4[i] = GET_ADC1(padd); No newline at end of file |
|
803 | results4[i] = GET_ADC1(padd); | |
782 | } |
|
804 | } | |
No newline at end of file |
|
805 | No newline at end of file | ||
783 | /* No newline at end of file |
|
|||
784 | if (checkTx(results3, results4, umbral, pulsewidth)==1){ //Se verifica que las muestras tomadas del canal 2 del detector de fase //correspondan a un pulso. No newline at end of file |
|
806 | if (checkTx(results3, results4, umbral, pulsewidth)==1){ //Se verifica que las muestras tomadas del canal 2 del detector de fase //correspondan a un pulso. | |
785 | break; No newline at end of file |
|
807 | break; | |
786 | } |
|
808 | } | |
No newline at end of file |
|
809 | }*/ | ||
787 | */ |
|
No newline at end of file | ||
No newline at end of file |
|
810 | cnt = 0; | ||
788 | // } |
|
No newline at end of file | ||
No newline at end of file |
|
811 | do{ | ||
789 | No newline at end of file |
|
No newline at end of file | ||
|
812 | for(i=0; i < NSAMPLES; i++){ | |||
|
No newline at end of file | ||||
|
813 | ||||
|
No newline at end of file | ||||
|
814 | ADC_INIT(padc); | |||
|
No newline at end of file | ||||
|
815 | results3[i] = GET_ADC0(padc); | |||
|
No newline at end of file | ||||
|
816 | results4[i] = GET_ADC1(padd); | |||
|
No newline at end of file | ||||
|
817 | } | |||
|
No newline at end of file | ||||
|
818 | ||||
|
No newline at end of file | ||||
|
819 | if (checkTx(results3, results4, umbral, pulsewidth)==1){ //Se verifica que las muestras tomadas del canal 2 del detector de fase //correspondan a un pulso. | |||
|
No newline at end of file | ||||
|
820 | break; | |||
|
No newline at end of file | ||||
|
821 | } | |||
|
No newline at end of file | ||||
|
822 | cnt += 1; | |||
|
No newline at end of file | ||||
|
823 | }while(cnt < NLOOPS); No newline at end of file | |||
790 | No newline at end of file |
|
824 | ||
791 | //Una vez que se ha encontrado un pulso en cada canal, se calcula la fase de ambos. No newline at end of file |
|
825 | //Una vez que se ha encontrado un pulso en cada canal, se calcula la fase de ambos. | |
792 | No newline at end of file |
|
826 | ||
793 | phase1 = getPhase(results1, results2); //Calcular la fase del canal 1 del detector de fase. No newline at end of file |
|
827 | phase1 = getPhase(results1, results2); //Calcular la fase del canal 1 del detector de fase. | |
794 | phase2 = getPhase(results3, results4); //Calcular la fase del canal 2 del detector de fase. No newline at end of file |
|
828 | phase2 = getPhase(results3, results4); //Calcular la fase del canal 2 del detector de fase. | |
795 | //create Output File No newline at end of file |
|
829 | //create Output File | |
796 | No newline at end of file |
|
830 | ||
797 | strcpy (fname, "/mnt/sd/absmonitoreo.txt"); No newline at end of file |
|
831 | strcpy (fname, "/mnt/sd/absmonitoreo.txt"); | |
798 | printf("\nTerminada la prueba # %d \n", j++); No newline at end of file |
|
832 | printf("\nTerminada la prueba # %d \n", j++); | |
799 | fp=create_Output(fname, now); //Coloca la fecha y la hora en el archivo de texto No newline at end of file |
|
833 | fp=create_Output(fname, now); //Coloca la fecha y la hora en el archivo de texto | |
800 | printf("mediana ch1 = %1.2f\n", phase1); //muestra resultado en terminal No newline at end of file |
|
834 | printf("mediana ch1 = %1.2f\n", phase1); //muestra resultado en terminal | |
801 | printf("mediana ch2 = %1.2f\n", phase2); //muestra resultado en terminal No newline at end of file |
|
835 | printf("mediana ch2 = %1.2f\n", phase2); //muestra resultado en terminal | |
802 | writeOutput(phase1, fp); //graba el resultado en el archivo de texto No newline at end of file |
|
836 | writeOutput(phase1, fp); //graba el resultado en el archivo de texto | |
803 | writeOutput(phase2, fp); //graba el resultado en el archivo de texto No newline at end of file |
|
837 | writeOutput(phase2, fp); //graba el resultado en el archivo de texto | |
804 | fprintf(fp, "\n"); //Pasa a la siguiente l�nea del archivo de texto No newline at end of file |
|
838 | fprintf(fp, "\n"); //Pasa a la siguiente l�nea del archivo de texto | |
805 | fclose(fp); No newline at end of file |
|
839 | fclose(fp); | |
806 | printf("Resultado guardado en %s \n", fname); No newline at end of file |
|
840 | printf("Resultado guardado en %s \n", fname); | |
807 | No newline at end of file |
|
841 | ||
808 | sleep(1); No newline at end of file |
|
842 | sleep(1); | |
809 | No newline at end of file |
|
843 | ||
810 | strcpy(page0,parameters.ID); No newline at end of file |
|
844 | strcpy(page0,parameters.ID); | |
811 | strcat(page0,"\n-------\n"); No newline at end of file |
|
845 | strcat(page0,"\n-------\n"); | |
812 | No newline at end of file |
|
846 | ||
813 | sprintf(page1,"UP:%1.2f DW:%1.2f\n",phase1, phase2); No newline at end of file |
|
847 | sprintf(page1,"UP:%1.2f DW:%1.2f\n",phase1, phase2); | |
814 | strcat(page0,page1); No newline at end of file |
|
848 | strcat(page0,page1); | |
815 | char *all_pages = malloc(strlen(page0)+1); No newline at end of file |
|
849 | char *all_pages = malloc(strlen(page0)+1); | |
816 | strcpy(all_pages, page0); No newline at end of file |
|
850 | strcpy(all_pages, page0); | |
817 | return all_pages; No newline at end of file |
|
851 | return all_pages; | |
818 | No newline at end of file |
|
852 | ||
819 | // } No newline at end of file |
|
853 | // } | |
820 | // return 0; No newline at end of file |
|
854 | // return 0; | |
821 | } No newline at end of file |
|
855 | } | |
822 | /*============================================================================= No newline at end of file |
|
856 | /*============================================================================= | |
823 | Function definitions No newline at end of file |
|
857 | Function definitions | |
824 | =============================================================================*/ No newline at end of file |
|
858 | =============================================================================*/ | |
825 | No newline at end of file |
|
859 | ||
826 | // Configures ADC registers in order to get a sample every 10us No newline at end of file |
|
860 | // Configures ADC registers in order to get a sample every 10us | |
827 | AT91S_ADC * configADC1(void){ No newline at end of file |
|
861 | AT91S_ADC * configADC1(void){ | |
828 | //Variables a usar: No newline at end of file |
|
862 | //Variables a usar: | |
829 | /* No newline at end of file |
|
863 | /* | |
830 | unsigned int maskc_adc =PC0; //Usamos ADC0 y ADC1 No newline at end of file |
|
864 | unsigned int maskc_adc =PC0; //Usamos ADC0 y ADC1 | |
831 | No newline at end of file |
|
865 | ||
832 | //configuro pin: No newline at end of file |
|
866 | //configuro pin: | |
833 | AT91S_PIO *pioc; No newline at end of file |
|
867 | AT91S_PIO *pioc; | |
834 | pioc = pio_map(PIOC_BASE); No newline at end of file |
|
868 | pioc = pio_map(PIOC_BASE); | |
835 | pin_adc_enable(pioc,maskc_adc); //Habilitamos PC0 para usar con ADC0 y 1 No newline at end of file |
|
869 | pin_adc_enable(pioc,maskc_adc); //Habilitamos PC0 para usar con ADC0 y 1 | |
836 | pio_disable_irq(pioc, maskc_adc); No newline at end of file |
|
870 | pio_disable_irq(pioc, maskc_adc); | |
837 | pio_disable_multiple_driver(pioc, maskc_adc); No newline at end of file |
|
871 | pio_disable_multiple_driver(pioc, maskc_adc); | |
838 | pio_disable_pull_ups(pioc, maskc_adc); No newline at end of file |
|
872 | pio_disable_pull_ups(pioc, maskc_adc); | |
839 | pio_input_enable(pioc, maskc_adc); No newline at end of file |
|
873 | pio_input_enable(pioc, maskc_adc); | |
840 | */ No newline at end of file |
|
874 | */ | |
841 | No newline at end of file |
|
875 | ||
842 | //Configuro el ADC: No newline at end of file |
|
876 | //Configuro el ADC: | |
843 | //AT91S_ADC *padc; No newline at end of file |
|
877 | //AT91S_ADC *padc; | |
844 | No newline at end of file |
|
878 | ||
845 | padc = adc_map1(ADC_BASE); No newline at end of file |
|
879 | padc = adc_map1(ADC_BASE); | |
846 | No newline at end of file |
|
880 | ||
847 | //clock ADC = 1MHz No newline at end of file |
|
881 | //clock ADC = 1MHz | |
848 | //time startup = 8us No newline at end of file |
|
882 | //time startup = 8us | |
849 | //time sample and hold = 2us No newline at end of file |
|
883 | //time sample and hold = 2us | |
850 | // hold No newline at end of file |
|
884 | // hold | |
851 | // ___________ No newline at end of file |
|
885 | // ___________ | |
852 | // start ___________| |___________ No newline at end of file |
|
886 | // start ___________| |___________ | |
853 | // No newline at end of file |
|
887 | // | |
854 | // | --1.2us-- | --0.15us-- | No newline at end of file |
|
888 | // | --1.2us-- | --0.15us-- | | |
855 | //ADC_RESET(padc); No newline at end of file |
|
889 | //ADC_RESET(padc); | |
856 | CONFIG_ADC(padc,ADC_TRGEN_DIS | ADC_RES_10BIT | ADC_SLEEP_NORMAL_MODE | ADC_PRESCAL | ADC_STARTUP | ADC_SHTIM); No newline at end of file |
|
890 | CONFIG_ADC(padc,ADC_TRGEN_DIS | ADC_RES_10BIT | ADC_SLEEP_NORMAL_MODE | ADC_PRESCAL | ADC_STARTUP | ADC_SHTIM); | |
857 | ENABLE_CHANNEL(padc,ADC_CH0); //habilito canal 0 No newline at end of file |
|
891 | ENABLE_CHANNEL(padc,ADC_CH0); //habilito canal 0 | |
858 | return padc; No newline at end of file |
|
892 | return padc; | |
859 | } No newline at end of file |
|
893 | } | |
860 | No newline at end of file |
|
894 | ||
861 | AT91S_ADC * configADC2(void){ No newline at end of file |
|
895 | AT91S_ADC * configADC2(void){ | |
862 | //Variables a usar: No newline at end of file |
|
896 | //Variables a usar: | |
863 | /* No newline at end of file |
|
897 | /* | |
864 | unsigned int maskc_adc =PC1; //Usamos ADC0 y ADC1 No newline at end of file |
|
898 | unsigned int maskc_adc =PC1; //Usamos ADC0 y ADC1 | |
865 | No newline at end of file |
|
899 | ||
866 | //configuro pin: No newline at end of file |
|
900 | //configuro pin: | |
867 | AT91S_PIO *piod; No newline at end of file |
|
901 | AT91S_PIO *piod; | |
868 | piod = pio_map(PIOC_BASE); No newline at end of file |
|
902 | piod = pio_map(PIOC_BASE); | |
869 | pin_adc_enable(piod,maskc_adc); //Habilitamos PC1 para usar con ADC0 y 1 No newline at end of file |
|
903 | pin_adc_enable(piod,maskc_adc); //Habilitamos PC1 para usar con ADC0 y 1 | |
870 | pio_disable_irq(piod, maskc_adc); No newline at end of file |
|
904 | pio_disable_irq(piod, maskc_adc); | |
871 | pio_disable_multiple_driver(piod, maskc_adc); No newline at end of file |
|
905 | pio_disable_multiple_driver(piod, maskc_adc); | |
872 | pio_disable_pull_ups(piod, maskc_adc); No newline at end of file |
|
906 | pio_disable_pull_ups(piod, maskc_adc); | |
873 | pio_input_enable(piod, maskc_adc); No newline at end of file |
|
907 | pio_input_enable(piod, maskc_adc); | |
874 | */ No newline at end of file |
|
908 | */ | |
875 | //Configuro el ADC: No newline at end of file |
|
909 | //Configuro el ADC: | |
876 | //AT91S_ADC *padd; No newline at end of file |
|
910 | //AT91S_ADC *padd; | |
877 | No newline at end of file |
|
911 | ||
878 | padd = adc_map1(ADC_BASE); No newline at end of file |
|
912 | padd = adc_map1(ADC_BASE); | |
879 | No newline at end of file |
|
913 | ||
880 | //clock ADC = 1MHz No newline at end of file |
|
914 | //clock ADC = 1MHz | |
881 | //time startup = 8us No newline at end of file |
|
915 | //time startup = 8us | |
882 | //time sample and hold = 2us No newline at end of file |
|
916 | //time sample and hold = 2us | |
883 | // hold No newline at end of file |
|
917 | // hold | |
884 | // ___________ No newline at end of file |
|
918 | // ___________ | |
885 | // start ___________| |___________ No newline at end of file |
|
919 | // start ___________| |___________ | |
886 | // No newline at end of file |
|
920 | // | |
887 | // | --1.2us-- | --0.15us-- | No newline at end of file |
|
921 | // | --1.2us-- | --0.15us-- | | |
888 | //ADC_RESET(padc); No newline at end of file |
|
922 | //ADC_RESET(padc); | |
889 | CONFIG_ADC(padd,ADC_TRGEN_DIS | ADC_RES_10BIT | ADC_SLEEP_NORMAL_MODE | ADC_PRESCAL | ADC_STARTUP | ADC_SHTIM); No newline at end of file |
|
923 | CONFIG_ADC(padd,ADC_TRGEN_DIS | ADC_RES_10BIT | ADC_SLEEP_NORMAL_MODE | ADC_PRESCAL | ADC_STARTUP | ADC_SHTIM); | |
890 | ENABLE_CHANNEL(padd,ADC_CH1); //habilito canal 1 No newline at end of file |
|
924 | ENABLE_CHANNEL(padd,ADC_CH1); //habilito canal 1 | |
891 | return padd; No newline at end of file |
|
925 | return padd; | |
892 | } No newline at end of file |
|
926 | } | |
893 | No newline at end of file |
|
927 | ||
894 | No newline at end of file |
|
928 | ||
895 | //++++++++++++++++++++ No newline at end of file |
|
929 | //++++++++++++++++++++ | |
896 | No newline at end of file |
|
930 | ||
897 | //creats the output file with a timestamp in the name No newline at end of file |
|
931 | //creats the output file with a timestamp in the name | |
898 | FILE * create_Output(char *fname, time_t rawtime){ No newline at end of file |
|
932 | FILE * create_Output(char *fname, time_t rawtime){ | |
899 | FILE *file; No newline at end of file |
|
933 | FILE *file; | |
900 | char timestamp[80];//, counter[5]="dcv"; No newline at end of file |
|
934 | char timestamp[80];//, counter[5]="dcv"; | |
901 | //char str[4]; No newline at end of file |
|
935 | //char str[4]; | |
902 | struct tm * timeinfo; No newline at end of file |
|
936 | struct tm * timeinfo; | |
903 | No newline at end of file |
|
937 | ||
904 | //format time No newline at end of file |
|
938 | //format time | |
905 | timeinfo = localtime ( &rawtime ); No newline at end of file |
|
939 | timeinfo = localtime ( &rawtime ); | |
906 | strftime (timestamp,sizeof(timestamp),"%a %y-%m-%d %H:%M:%S %Z",timeinfo); No newline at end of file |
|
940 | strftime (timestamp,sizeof(timestamp),"%a %y-%m-%d %H:%M:%S %Z",timeinfo); | |
907 | No newline at end of file |
|
941 | ||
908 | No newline at end of file |
|
942 | ||
909 | //Creates the file name out of the #define parameters No newline at end of file |
|
943 | //Creates the file name out of the #define parameters | |
910 | No newline at end of file |
|
944 | ||
911 | strcpy (fname, "/mnt/sd/absmonitoreo.txt"); No newline at end of file |
|
945 | strcpy (fname, "/mnt/sd/absmonitoreo.txt"); | |
912 | file = fopen(fname,"a+"); No newline at end of file |
|
946 | file = fopen(fname,"a+"); | |
913 | fprintf(file,"%s", timestamp); No newline at end of file |
|
947 | fprintf(file,"%s", timestamp); | |
914 | //printf("\nTerminada la prueba # %d. Guardando resultado en %s\n",r, fname); No newline at end of file |
|
948 | //printf("\nTerminada la prueba # %d. Guardando resultado en %s\n",r, fname); | |
915 | //printf("\nTerminada la prueba # %d/%d. Writing data to the file %s\n",r+1 , REP, fname); No newline at end of file |
|
949 | //printf("\nTerminada la prueba # %d/%d. Writing data to the file %s\n",r+1 , REP, fname); | |
916 | //printf("\nAAAAAAAAAA %d...%s\n", counter[1], fname); No newline at end of file |
|
950 | //printf("\nAAAAAAAAAA %d...%s\n", counter[1], fname); | |
917 | // return file pointer No newline at end of file |
|
951 | // return file pointer | |
918 | return file; No newline at end of file |
|
952 | return file; | |
919 | } No newline at end of file |
|
953 | } | |
920 | No newline at end of file |
|
954 | ||
921 | //++++++++++++++++++++ No newline at end of file |
|
955 | //++++++++++++++++++++ | |
922 | No newline at end of file |
|
956 | ||
923 | //tests if a file already exists. returns 1 if it exists and 0 if it doesn't No newline at end of file |
|
957 | //tests if a file already exists. returns 1 if it exists and 0 if it doesn't | |
924 | No newline at end of file |
|
958 | ||
925 | No newline at end of file |
|
959 | ||
926 | No newline at end of file |
|
960 | ||
927 | //Funci�n checkTx verifica que la se�al muestreada corresponda a un pulso. No newline at end of file |
|
961 | //Funci�n checkTx verifica que la se�al muestreada corresponda a un pulso. | |
928 | //results1 y results2 son los arreglos que contienen los datos muestreados por ambos canales del ADC del embebido. No newline at end of file |
|
962 | //results1 y results2 son los arreglos que contienen los datos muestreados por ambos canales del ADC del embebido. | |
929 | //umbral indica qu� valor debe superar una muestra para considerarla un posible pulso o pico. No newline at end of file |
|
963 | //umbral indica qu� valor debe superar una muestra para considerarla un posible pulso o pico. | |
930 | //pulsewidth indica cu�ntas muestras consecutivas deben superar el umbral para que se considere que se ha detectado un pulso. No newline at end of file |
|
964 | //pulsewidth indica cu�ntas muestras consecutivas deben superar el umbral para que se considere que se ha detectado un pulso. | |
931 | int checkTx(long int results1[],long int results2[], float umbral, int pulsewidth){ No newline at end of file |
|
965 | int checkTx(long int results1[],long int results2[], float umbral, int pulsewidth){ | |
932 | No newline at end of file |
|
966 | ||
933 | int i, cont; No newline at end of file |
|
967 | int i, cont; | |
934 | float z[NSAMPLES], sum, avg; No newline at end of file |
|
968 | float z[NSAMPLES], sum, avg; | |
935 | int isSignal, pulse; No newline at end of file |
|
969 | int isSignal, pulse; | |
936 | No newline at end of file |
|
970 | ||
937 | for(i=0;i<NSAMPLES;i++){ No newline at end of file |
|
971 | for(i=0;i<NSAMPLES;i++){ | |
938 | No newline at end of file |
|
972 | ||
939 | z[i] =sqrt(1.0*results1[i]*results1[i]+1.0*results2[i]*results2[i]); No newline at end of file |
|
973 | z[i] =sqrt(1.0*results1[i]*results1[i]+1.0*results2[i]*results2[i]); | |
940 | } No newline at end of file |
|
974 | } | |
941 | No newline at end of file |
|
975 | ||
942 | pulse = 0; No newline at end of file |
|
976 | pulse = 0; | |
943 | isSignal = 0; No newline at end of file |
|
977 | isSignal = 0; | |
944 | cont =0; No newline at end of file |
|
978 | cont =0; | |
945 | No newline at end of file |
|
979 | ||
946 | sum = 0; No newline at end of file |
|
980 | sum = 0; | |
947 | for(i=0;i<NSAMPLES;i++){ No newline at end of file |
|
981 | for(i=0;i<NSAMPLES;i++){ | |
948 | No newline at end of file |
|
982 | ||
949 | sum += z[i]; No newline at end of file |
|
983 | sum += z[i]; | |
950 | avg = sum/(i+1); No newline at end of file |
|
984 | avg = sum/(i+1); | |
951 | if ((z[i] - avg) > umbral){ No newline at end of file |
|
985 | if ((z[i] - avg) > umbral){ | |
952 | if (isSignal == 1){ No newline at end of file |
|
986 | if (isSignal == 1){ | |
953 | cont += 1; No newline at end of file |
|
987 | cont += 1; | |
954 | } No newline at end of file |
|
988 | } | |
955 | if (cont == pulsewidth){ No newline at end of file |
|
989 | if (cont == pulsewidth){ | |
956 | pulse = 1; No newline at end of file |
|
990 | pulse = 1; | |
957 | break; No newline at end of file |
|
991 | break; | |
958 | } No newline at end of file |
|
992 | } | |
959 | isSignal = 1; No newline at end of file |
|
993 | isSignal = 1; | |
960 | continue; No newline at end of file |
|
994 | continue; | |
961 | isSignal = 0; No newline at end of file |
|
995 | isSignal = 0; | |
962 | cont = 0; No newline at end of file |
|
996 | cont = 0; | |
963 | } No newline at end of file |
|
997 | } | |
964 | } No newline at end of file |
|
998 | } | |
965 | No newline at end of file |
|
999 | ||
966 | return pulse; //devuelve un entero: 1 si se ha detectado pulso, de lo contrario, 0. No newline at end of file |
|
1000 | return pulse; //devuelve un entero: 1 si se ha detectado pulso, de lo contrario, 0. | |
967 | } No newline at end of file |
|
1001 | } | |
968 | No newline at end of file |
|
1002 | ||
969 | No newline at end of file |
|
1003 | ||
970 | int fExists(char * fname){ No newline at end of file |
|
1004 | int fExists(char * fname){ | |
971 | FILE * file; No newline at end of file |
|
1005 | FILE * file; | |
972 | No newline at end of file |
|
1006 | ||
973 | file = fopen (fname, "r"); No newline at end of file |
|
1007 | file = fopen (fname, "r"); | |
974 | if (file == NULL) No newline at end of file |
|
1008 | if (file == NULL) | |
975 | { No newline at end of file |
|
1009 | { | |
976 | return 0; No newline at end of file |
|
1010 | return 0; | |
977 | } No newline at end of file |
|
1011 | } | |
978 | fclose(file); No newline at end of file |
|
1012 | fclose(file); | |
979 | return 1; No newline at end of file |
|
1013 | return 1; | |
980 | } No newline at end of file |
|
1014 | } | |
981 | No newline at end of file |
|
1015 | ||
982 | No newline at end of file |
|
1016 | ||
983 | //Funci�n que calcula la mediana de un conjunto de muestras No newline at end of file |
|
1017 | //Funci�n que calcula la mediana de un conjunto de muestras | |
984 | double mediana(long int *results,unsigned int cuenta){ No newline at end of file |
|
1018 | double mediana(long int *results,unsigned int cuenta){ | |
985 | unsigned int i=0,j=0,aux=0; No newline at end of file |
|
1019 | unsigned int i=0,j=0,aux=0; | |
986 | No newline at end of file |
|
1020 | ||
987 | double median=0; No newline at end of file |
|
1021 | double median=0; | |
988 | /*Calculo mediana */ No newline at end of file |
|
1022 | /*Calculo mediana */ | |
989 | No newline at end of file |
|
1023 | ||
990 | for(i=0;i<cuenta-1;i++){ No newline at end of file |
|
1024 | for(i=0;i<cuenta-1;i++){ | |
991 | for (j=i+1;j<cuenta;j++){ No newline at end of file |
|
1025 | for (j=i+1;j<cuenta;j++){ | |
992 | if(results[i]>results[j] ){ No newline at end of file |
|
1026 | if(results[i]>results[j] ){ | |
993 | No newline at end of file |
|
1027 | ||
994 | aux=results[i]; No newline at end of file |
|
1028 | aux=results[i]; | |
995 | results[i]=results[j]; No newline at end of file |
|
1029 | results[i]=results[j]; | |
996 | results[j]=aux; No newline at end of file |
|
1030 | results[j]=aux; | |
997 | No newline at end of file |
|
1031 | ||
998 | } No newline at end of file |
|
1032 | } | |
999 | } No newline at end of file |
|
1033 | } | |
1000 | No newline at end of file |
|
1034 | ||
1001 | } No newline at end of file |
|
1035 | } | |
1002 | median=results[cuenta/2]; No newline at end of file |
|
1036 | median=results[cuenta/2]; | |
1003 | return median; No newline at end of file |
|
1037 | return median; | |
1004 | } No newline at end of file |
|
1038 | } | |
1005 | No newline at end of file |
|
1039 | ||
1006 | No newline at end of file |
|
1040 | ||
1007 | No newline at end of file |
|
1041 | ||
1008 | //Funci�n que halla la fase de la se�al. No newline at end of file |
|
1042 | //Funci�n que halla la fase de la se�al. | |
1009 | //Tiene como entradas las muestras correspondientes a la parte real e imaginaria de la se�al. No newline at end of file |
|
1043 | //Tiene como entradas las muestras correspondientes a la parte real e imaginaria de la se�al. | |
1010 | float getPhase(long int results1[],long int results2[]){ No newline at end of file |
|
1044 | float getPhase(long int results1[],long int results2[]){ | |
1011 | No newline at end of file |
|
1045 | ||
1012 | unsigned int count=0, i=0,umbral=1000; No newline at end of file |
|
1046 | unsigned int count=0, i=0,umbral=1000; | |
1013 | //long int results1[]; No newline at end of file |
|
1047 | //long int results1[]; | |
1014 | //long int results2[]; No newline at end of file |
|
1048 | //long int results2[]; | |
1015 | long int power[NSAMPLES]; No newline at end of file |
|
1049 | long int power[NSAMPLES]; | |
1016 | long int sumI=0,sumQ=0,I[NSAMPLES], Q[NSAMPLES],II[NSAMPLES], QQ[NSAMPLES]; No newline at end of file |
|
1050 | long int sumI=0,sumQ=0,I[NSAMPLES], Q[NSAMPLES],II[NSAMPLES], QQ[NSAMPLES]; | |
1017 | double median1=0,median2=0; No newline at end of file |
|
1051 | double median1=0,median2=0; | |
1018 | long int promedioI=0,promedioQ=0;/*Calculo mediana 1*/ No newline at end of file |
|
1052 | long int promedioI=0,promedioQ=0;/*Calculo mediana 1*/ | |
1019 | float resultado=0; No newline at end of file |
|
1053 | float resultado=0; | |
1020 | No newline at end of file |
|
1054 | ||
1021 | for(i=0;i<NSAMPLES;i++){ No newline at end of file |
|
1055 | for(i=0;i<NSAMPLES;i++){ | |
1022 | No newline at end of file |
|
1056 | ||
1023 | I[i] =results1[i]; No newline at end of file |
|
1057 | I[i] =results1[i]; | |
1024 | Q[i] =results2[i]; No newline at end of file |
|
1058 | Q[i] =results2[i]; | |
1025 | } No newline at end of file |
|
1059 | } | |
1026 | No newline at end of file |
|
1060 | ||
1027 | /*Calculo mediana 1*/ No newline at end of file |
|
1061 | /*Calculo mediana 1*/ | |
1028 | median1=mediana(I,NSAMPLES); No newline at end of file |
|
1062 | median1=mediana(I,NSAMPLES); | |
1029 | No newline at end of file |
|
1063 | ||
1030 | /*Calculo mediana 2*/ No newline at end of file |
|
1064 | /*Calculo mediana 2*/ | |
1031 | median2=mediana(Q,NSAMPLES); No newline at end of file |
|
1065 | median2=mediana(Q,NSAMPLES); | |
1032 | No newline at end of file |
|
1066 | ||
1033 | No newline at end of file |
|
1067 | ||
1034 | No newline at end of file |
|
1068 | ||
1035 | No newline at end of file |
|
1069 | ||
1036 | No newline at end of file |
|
1070 | ||
1037 | No newline at end of file |
|
1071 | ||
1038 | for(i=0;i<NSAMPLES;i++){ No newline at end of file |
|
1072 | for(i=0;i<NSAMPLES;i++){ | |
1039 | No newline at end of file |
|
1073 | ||
1040 | I[i] =results1[i]; No newline at end of file |
|
1074 | I[i] =results1[i]; | |
1041 | Q[i] =results2[i]; No newline at end of file |
|
1075 | Q[i] =results2[i]; | |
1042 | No newline at end of file |
|
1076 | ||
1043 | } No newline at end of file |
|
1077 | } | |
1044 | No newline at end of file |
|
1078 | ||
1045 | No newline at end of file |
|
1079 | ||
1046 | No newline at end of file |
|
1080 | ||
1047 | for(i = 0; i < NSAMPLES ; i++){ No newline at end of file |
|
1081 | for(i = 0; i < NSAMPLES ; i++){ | |
1048 | No newline at end of file |
|
1082 | ||
1049 | I[i]=(I[i]-median1); No newline at end of file |
|
1083 | I[i]=(I[i]-median1); | |
1050 | Q[i]=(Q[i]-median2); No newline at end of file |
|
1084 | Q[i]=(Q[i]-median2); | |
1051 | No newline at end of file |
|
1085 | ||
1052 | } No newline at end of file |
|
1086 | } | |
1053 | No newline at end of file |
|
1087 | ||
1054 | for(i = 0; i < NSAMPLES ; i++){ No newline at end of file |
|
1088 | for(i = 0; i < NSAMPLES ; i++){ | |
1055 | No newline at end of file |
|
1089 | ||
1056 | power[i]=I[i]*I[i]+Q[i]*Q[i]; No newline at end of file |
|
1090 | power[i]=I[i]*I[i]+Q[i]*Q[i]; | |
1057 | No newline at end of file |
|
1091 | ||
1058 | if(power[i] > umbral) No newline at end of file |
|
1092 | if(power[i] > umbral) | |
1059 | { No newline at end of file |
|
1093 | { | |
1060 | No newline at end of file |
|
1094 | ||
1061 | II[count]=I[i]; No newline at end of file |
|
1095 | II[count]=I[i]; | |
1062 | QQ[count]=Q[i]; No newline at end of file |
|
1096 | QQ[count]=Q[i]; | |
1063 | count=count+1; No newline at end of file |
|
1097 | count=count+1; | |
1064 | No newline at end of file |
|
1098 | ||
1065 | } No newline at end of file |
|
1099 | } | |
1066 | No newline at end of file |
|
1100 | ||
1067 | } No newline at end of file |
|
1101 | } | |
1068 | No newline at end of file |
|
1102 | ||
1069 | for(i = 0; i < count ; i++){ No newline at end of file |
|
1103 | for(i = 0; i < count ; i++){ | |
1070 | No newline at end of file |
|
1104 | ||
1071 | sumI=sumI+II[i]; No newline at end of file |
|
1105 | sumI=sumI+II[i]; | |
1072 | sumQ=sumQ+QQ[i]; No newline at end of file |
|
1106 | sumQ=sumQ+QQ[i]; | |
1073 | No newline at end of file |
|
1107 | ||
1074 | } No newline at end of file |
|
1108 | } | |
1075 | No newline at end of file |
|
1109 | ||
1076 | promedioI=sumI; No newline at end of file |
|
1110 | promedioI=sumI; | |
1077 | promedioQ=sumQ; No newline at end of file |
|
1111 | promedioQ=sumQ; | |
1078 | No newline at end of file |
|
1112 | ||
1079 | resultado = atan2(1.0*promedioI,1.0*promedioQ)*180/3.1416+62-44; No newline at end of file |
|
1113 | resultado = atan2(1.0*promedioI,1.0*promedioQ)*180/3.1416+62-44; | |
1080 | No newline at end of file |
|
1114 | ||
1081 | No newline at end of file |
|
1115 | ||
1082 | return resultado; No newline at end of file |
|
1116 | return resultado; | |
1083 | No newline at end of file |
|
1117 | ||
1084 | } No newline at end of file |
|
1118 | } | |
1085 | No newline at end of file |
|
1119 | ||
1086 | No newline at end of file |
|
1120 | ||
1087 | No newline at end of file |
|
1121 | ||
1088 | //Funci�n que muestra la fase detectada en el terminal y tambi�n la graba en el archivo de texto. No newline at end of file |
|
1122 | //Funci�n que muestra la fase detectada en el terminal y tambi�n la graba en el archivo de texto. | |
1089 | void writeOutput(float resultado, FILE * output){ No newline at end of file |
|
1123 | void writeOutput(float resultado, FILE * output){ | |
1090 | No newline at end of file |
|
1124 | ||
1091 | No newline at end of file |
|
1125 | ||
1092 | // No newline at end of file |
|
1126 | // | |
1093 | No newline at end of file |
|
1127 | ||
1094 | fprintf(output," %1.2f ",resultado); //graba resultado en archivo .txt No newline at end of file |
|
1128 | fprintf(output," %1.2f ",resultado); //graba resultado en archivo .txt | |
1095 | // No newline at end of file |
|
1129 | // | |
1096 | No newline at end of file |
|
1130 | ||
1097 | } No newline at end of file |
|
1131 | } | |
1098 | No newline at end of file |
|
1132 | ||
1099 | int configCLK(){ No newline at end of file |
|
1133 | int configCLK(){ | |
1100 | //configuro pin: No newline at end of file |
|
1134 | //configuro pin: | |
1101 | AT91S_PMC *sys_clock; No newline at end of file |
|
1135 | AT91S_PMC *sys_clock; | |
1102 | sys_clock = clock_map(CLOCK_BASE); No newline at end of file |
|
1136 | sys_clock = clock_map(CLOCK_BASE); | |
1103 | enable_clock_adc(sys_clock); No newline at end of file |
|
1137 | enable_clock_adc(sys_clock); | |
1104 | //printf("clock ADC enable.\n"); No newline at end of file |
|
1138 | //printf("clock ADC enable.\n"); | |
1105 | return 1; No newline at end of file |
|
1139 | return 1; | |
1106 | } No newline at end of file |
|
1140 | } |
General Comments 0
You need to be logged in to leave comments.
Login now