|
|
|
@ -12,7 +12,7 @@
|
|
|
|
|
#define data_file_path "/var/lib/cloud9/daq-serial-bbb/data.dat"
|
|
|
|
|
|
|
|
|
|
#define GC0017 4 //co2
|
|
|
|
|
#define CM31911 1 //co
|
|
|
|
|
#define CM31911 1 //co, t
|
|
|
|
|
#define OX0052 2 //o2
|
|
|
|
|
|
|
|
|
|
#define Rep_Dev_ID "Y\r\n"
|
|
|
|
@ -23,6 +23,7 @@
|
|
|
|
|
#define Temperature "T\r\n"
|
|
|
|
|
#define get_readigns "Q\r\n"
|
|
|
|
|
#define percent_oxigen "%\r\n"
|
|
|
|
|
#define ppm_oxigen "O\r\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int sensConf(unsigned char uartNumber, int baudRate, unsigned char mode[], unsigned char response[]);
|
|
|
|
@ -43,15 +44,15 @@ int main(int argc, char *argv[]){
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//configuración de sensores
|
|
|
|
|
//printf("Configuring CO2 sensor\n");
|
|
|
|
|
//sensConf(GC0017, B9600, Pulling_Mode, " K 00002\r\n");
|
|
|
|
|
//printf("Configuring CO sensor\n");
|
|
|
|
|
//sensConf(CM31911, B9600, Pulling_Mode, "K 00002\r\n");
|
|
|
|
|
printf("Configuring CO2 sensor\n");
|
|
|
|
|
sensConf(GC0017, B9600, Pulling_Mode, " K 00002\r\n");
|
|
|
|
|
printf("Configuring CO sensor\n");
|
|
|
|
|
sensConf(CM31911, B9600, Pulling_Mode, "K 00002\r\n");
|
|
|
|
|
printf("Configuring O2 sensor\n");
|
|
|
|
|
sensConf(OX0052, B9600, OX_P_Mode, "M 01\r\n");
|
|
|
|
|
|
|
|
|
|
//adquisición
|
|
|
|
|
T = atoi(argv[1]);
|
|
|
|
|
T = atoi(argv[1]);//str to int
|
|
|
|
|
t = atoi(argv[2]);
|
|
|
|
|
printf("Starting data acquisition with duration of %dh and every %ds\n", T, t);
|
|
|
|
|
DAQ(T, t);
|
|
|
|
@ -107,6 +108,13 @@ int measure(unsigned char uartNumber, unsigned char command[], int multiplier, i
|
|
|
|
|
return measure;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int read_measure(unsigned char uartNumber, int multiplier, int excess){
|
|
|
|
|
int measure;
|
|
|
|
|
uartReceive(uartNumber);
|
|
|
|
|
measure = (str2int(&receive[uartNumber]) - excess)*multiplier ;
|
|
|
|
|
return measure;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int str2int(unsigned char *ptr){
|
|
|
|
|
|
|
|
|
|
int number = 0;
|
|
|
|
@ -127,32 +135,45 @@ int DAQ(int t_hrs, int tm_s)
|
|
|
|
|
int co2, co, o2, temp;
|
|
|
|
|
clock_t start_t, end_t;
|
|
|
|
|
time_t new_time, prev_time, t0;
|
|
|
|
|
double dif;
|
|
|
|
|
|
|
|
|
|
double tm_ms = tm_s*1e6 - 0.20e6;
|
|
|
|
|
double dif = tm_ms;
|
|
|
|
|
|
|
|
|
|
//registro datos de inicio
|
|
|
|
|
dfp = fopen(data_file_path, "w"); // open file for writing
|
|
|
|
|
time_t curtime;
|
|
|
|
|
time(&curtime);
|
|
|
|
|
fprintf(dfp, "%sStarting DAQ\ntime(s)\t\tCO2(ppm)\t\tCO(ppm)\t\tO2(ppm)\t\tTemperaure(ºC*10)\n", ctime(&curtime)); // send the value to the file
|
|
|
|
|
fprintf(dfp, "%sStarting DAQ\ntime(s)\tCO2(ppm)\tCO(ppm)\tO2(ppm)\tTemperaure(ºC*10)\n", ctime(&curtime)); // send the value to the file
|
|
|
|
|
fclose(dfp); // close the file using the file pointer
|
|
|
|
|
|
|
|
|
|
//ciclo
|
|
|
|
|
t0 = (prev_time=time(NULL));
|
|
|
|
|
t0 = time(NULL) + tm_s;
|
|
|
|
|
new_time = t0;
|
|
|
|
|
for(int i = 0; i < (t_hrs*3600); i=i+tm_s){
|
|
|
|
|
while((prev_time+tm_s) != (new_time = time(NULL)));
|
|
|
|
|
|
|
|
|
|
if (dif <= 0) printf("T=%d Communication time exceded.\n", (int)(new_time-t0));
|
|
|
|
|
else usleep((int)dif);
|
|
|
|
|
|
|
|
|
|
if (time(NULL) < new_time) while(new_time != time(NULL));
|
|
|
|
|
else printf("T=%d time error.\n", (int)(new_time-t0));
|
|
|
|
|
|
|
|
|
|
start_t = clock();
|
|
|
|
|
//co2 = measure(GC0017, fil_gas_con, 10, 0); co = measure(CM31911, fil_gas_con, 1, 0);
|
|
|
|
|
o2 = measure(OX0052, percent_oxigen, 1, 0);///*temp = measure(CM31911, Temperature, 1, 1000);
|
|
|
|
|
new_time = time(NULL);
|
|
|
|
|
uartTransmit(CM31911, fil_gas_con);
|
|
|
|
|
uartTransmit(GC0017, fil_gas_con);
|
|
|
|
|
co = read_measure(CM31911, 1, 0);
|
|
|
|
|
uartTransmit(CM31911, Temperature);
|
|
|
|
|
uartTransmit(OX0052, ppm_oxigen);
|
|
|
|
|
co2 = read_measure(GC0017, 10, 0);
|
|
|
|
|
o2 = read_measure(OX0052, 1, 0);
|
|
|
|
|
temp = read_measure(CM31911, 1, 1000);
|
|
|
|
|
|
|
|
|
|
dfp = fopen(data_file_path, "a"); // open file for writing
|
|
|
|
|
fprintf(dfp, "%ld \t\t%d\t\t%d\t\t%d\t\t%d\n", new_time-t0, co2, co, o2, temp); // send the value to the file
|
|
|
|
|
fprintf(dfp, "%d \t%d\t%d\t%d\t%d\n", (int)(new_time-t0), co2, co, o2, temp); // send the value to the file
|
|
|
|
|
fclose(dfp); // close the file using the file pointer
|
|
|
|
|
prev_time = new_time;
|
|
|
|
|
new_time += tm_s;
|
|
|
|
|
end_t = clock();
|
|
|
|
|
dif = (double)(end_t - start_t)*1e6 / CLOCKS_PER_SEC;
|
|
|
|
|
dif = tm_s*1e6 - dif - .15e6;
|
|
|
|
|
if (dif < 0) dif = 0;
|
|
|
|
|
usleep((int)dif);
|
|
|
|
|
|
|
|
|
|
dif = tm_ms - ((double)(end_t - start_t)*1e6 / CLOCKS_PER_SEC);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|