|
|
|
@ -140,6 +140,9 @@ int str2int(unsigned char *ptr){
|
|
|
|
|
|
|
|
|
|
int DAQ(int t_hrs, int tm_s)
|
|
|
|
|
{
|
|
|
|
|
const char colums[200] = "t(s)\tCO2 uf(ppm)\tCO2(ppm)\tCO uf(ppm)\t"\
|
|
|
|
|
"CO(ppm)\tO2(ppm)\tO2(%%)\tT C02(ºC*10)\t"\
|
|
|
|
|
"T 02(ºC)\tP C02(.mBar)\tP 02(mBar)\tRH(.)\n";
|
|
|
|
|
FILE* dfp; // create a file pointer
|
|
|
|
|
unsigned char co2_uf[10]="", co2_f[10]="",
|
|
|
|
|
co_uf[10]="", co_f[10]="",
|
|
|
|
@ -156,30 +159,22 @@ int DAQ(int t_hrs, int tm_s)
|
|
|
|
|
dfp = fopen(data_file_path, "w"); // open file for writing
|
|
|
|
|
time_t curtime; //current time (date)
|
|
|
|
|
time(&curtime); //saving date in curtime
|
|
|
|
|
fprintf(dfp, "%sStarting DAQ\ntime(s)\tCO2 unfil(ppm)\tCO2 fil(ppm)\tCO unfil(ppm)\tCO fil(ppm)"\
|
|
|
|
|
"\tO2(ppm)\tO2(%c)\tTemperaure C02(ºC*10)\tTemperaure 02(ºC)"\
|
|
|
|
|
"\tPressure C02(.mBar)\tPresure 02(mBar)\tRelative Humidity(.)\n",
|
|
|
|
|
ctime(&curtime), '%'); // send the value to the file
|
|
|
|
|
fprintf(dfp, "Starting DAQ at %s\n"\
|
|
|
|
|
,
|
|
|
|
|
ctime(&curtime)); // send the value to the file
|
|
|
|
|
fclose(dfp); // close the file using the file pointer
|
|
|
|
|
|
|
|
|
|
printf("%s", colums);
|
|
|
|
|
//ciclo
|
|
|
|
|
t0 = time(NULL) + tm_s; //intitial time = current time + tiempo de muestreo
|
|
|
|
|
new_time = t0; //saving initial time in time control variable
|
|
|
|
|
for(int i = 0; i < (t_hrs*3600); i=i+tm_s){ //cycle from 0 to adquisition time (seconds), incrementing sampling period
|
|
|
|
|
|
|
|
|
|
if (dif <= 0) printf("T=%d Communication time exceded.\n", (int)(new_time-t0));
|
|
|
|
|
else usleep((int)dif); //checking if there's time to sleep
|
|
|
|
|
//waiting new second (time.h system) to start measurements
|
|
|
|
|
if (time(NULL) < new_time) while(new_time != time(NULL));
|
|
|
|
|
else printf("T=%d time error.\n", (int)(new_time-t0));
|
|
|
|
|
//checking if there's time to sleep
|
|
|
|
|
if (dif <= 0) printf("Ejecution time exceded.\n");
|
|
|
|
|
else usleep((int)dif); //inactivity time
|
|
|
|
|
//waiting to start measurements
|
|
|
|
|
while(new_time != time(NULL));
|
|
|
|
|
|
|
|
|
|
start_t = clock(); //saving start time
|
|
|
|
|
/*new_time = time(NULL); //refresh new_time (next iteration)
|
|
|
|
|
no necesario por:
|
|
|
|
|
while(new_time != time(NULL));
|
|
|
|
|
se avanza cuando new_time = time(NULL)
|
|
|
|
|
por lo tanto "new_time = time(NULL);" es redundante
|
|
|
|
|
*/
|
|
|
|
|
//transmiting commands to sensors
|
|
|
|
|
uartTransmit(CM31911, get_readigns);
|
|
|
|
|
uartTransmit(OX0052, Readings_OX);
|
|
|
|
@ -188,7 +183,7 @@ int DAQ(int t_hrs, int tm_s)
|
|
|
|
|
uartReceive(OX0052);
|
|
|
|
|
uartReceive(CM31911);
|
|
|
|
|
uartReceive(GC0017);
|
|
|
|
|
//saving gas measurements in measurements variables
|
|
|
|
|
//interpreting and spliting measurements in variables
|
|
|
|
|
memcpy(co2_uf, gmeasures(receive[GC0017], 'z', 5), 5);
|
|
|
|
|
memcpy(co2_f, gmeasures(receive[GC0017], 'Z', 5), 5);
|
|
|
|
|
memcpy(co_uf, gmeasures(receive[CM31911], 'z', 5), 5);
|
|
|
|
@ -201,14 +196,11 @@ int DAQ(int t_hrs, int tm_s)
|
|
|
|
|
memcpy(o2_press, gmeasures(receive[OX0052], 'P', 4), 4);
|
|
|
|
|
memcpy(co2_relH, gmeasures(receive[CM31911], 'H', 5), 5);
|
|
|
|
|
//saving formated measurements in string DATA
|
|
|
|
|
sprintf(DATA, "%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s",
|
|
|
|
|
sprintf(DATA,
|
|
|
|
|
"%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s",
|
|
|
|
|
(int)(new_time-t0), co2_uf, co2_f, co_uf, co_f, o2_ppm, o2_xcent,
|
|
|
|
|
co2_temp, o2_temp, co2_press, o2_press, co2_relH);
|
|
|
|
|
//showing measurements on display
|
|
|
|
|
printf("time(s)\tCO2 unfil(ppm)\tCO2 fil(ppm)\tCO unfil(ppm)\tCO fil(ppm)"\
|
|
|
|
|
"\tO2(ppm)\tO2(%c)\tTemperaure C02(ºC*10)\tTemperaure 02(ºC)"\
|
|
|
|
|
"\tPressure C02(.mBar)\tPresure 02(mBar)\tRelative Humidity(.)\n", '%');
|
|
|
|
|
printf("%s\n", DATA);
|
|
|
|
|
printf("\r%s", DATA); //showing measurements on display
|
|
|
|
|
|
|
|
|
|
dfp = fopen(data_file_path, "a"); // open file for writing
|
|
|
|
|
fprintf(dfp, "%s\n", DATA); // saving measurements string to data file
|
|
|
|
|