|
|
|
@ -129,38 +129,37 @@ int str2int(unsigned char *ptr){
|
|
|
|
|
|
|
|
|
|
int DAQ(int t_hrs, int tm_s)
|
|
|
|
|
{
|
|
|
|
|
FILE* dfp; // create a file pointer
|
|
|
|
|
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]="",
|
|
|
|
|
o2_ppm[10]="", o2_xcent[10]="",
|
|
|
|
|
co2_temp[10]="", o2_temp[10]="",
|
|
|
|
|
co2_press[10]="", o2_press[10]="",
|
|
|
|
|
co2_relH[10]="", DATA[100]=""; //measurements varirables
|
|
|
|
|
time_t curtime; //current time (date)
|
|
|
|
|
clock_t start_t, end_t; //processing time measurements variables
|
|
|
|
|
time_t new_time, prev_time, t0; //time control variables
|
|
|
|
|
time_t next_samp_time; //time control variables
|
|
|
|
|
double tm_ms = tm_s*1e6 - 0.20e6; //tiempo de muestreo en milisegundos (-) margen
|
|
|
|
|
double dif = tm_ms; //diferencia de tiempo(time to sleep)
|
|
|
|
|
|
|
|
|
|
time(&curtime); //saving date in curtime
|
|
|
|
|
//registro datos de inicio
|
|
|
|
|
dfp = fopen(data_file_path, "w"); // open file for writing
|
|
|
|
|
time_t curtime; //current time (date)
|
|
|
|
|
time(&curtime); //saving date in curtime
|
|
|
|
|
// send the value to the file
|
|
|
|
|
fprintf(dfp, "Starting DAQ at %s\n", ctime(&curtime);
|
|
|
|
|
fclose(dfp); // close the file using the file pointer
|
|
|
|
|
printf("%s", colums); //display variables 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
|
|
|
|
|
next_samp_time = time(NULL) + tm_s; //setting nex sampling time
|
|
|
|
|
for(int t = 0; t < (t_hrs*3600); t+=tm_s){ //cycle from 0 to adquisition time (seconds), incrementing sampling period
|
|
|
|
|
//checking if there's time to sleep
|
|
|
|
|
if (dif <= 0) printf("Ejecution time exceded.\n%s", colums);
|
|
|
|
|
else usleep((int)dif); //inactivity time
|
|
|
|
|
//waiting to start measurements
|
|
|
|
|
while(new_time != time(NULL));
|
|
|
|
|
while(next_samp_time != time(NULL));
|
|
|
|
|
|
|
|
|
|
start_t = clock(); //saving start time
|
|
|
|
|
//transmiting commands to sensors
|
|
|
|
@ -186,14 +185,14 @@ int DAQ(int t_hrs, int tm_s)
|
|
|
|
|
//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",
|
|
|
|
|
(int)(new_time-t0), co2_uf, co2_f, co_uf, co_f, o2_ppm, o2_xcent,
|
|
|
|
|
t, co2_uf, co2_f, co_uf, co_f, o2_ppm, o2_xcent,
|
|
|
|
|
co2_temp, o2_temp, co2_press, o2_press, co2_relH);
|
|
|
|
|
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
|
|
|
|
|
fclose(dfp); // close the file using the file pointer
|
|
|
|
|
new_time += tm_s; //adding sampling period to new_time
|
|
|
|
|
next_samp_time += tm_s; //adding sampling period to next_samp_time
|
|
|
|
|
end_t = clock(); //saving end time
|
|
|
|
|
//calculate time to sleep
|
|
|
|
|
dif = tm_ms - ((double)(end_t - start_t)*1e6 / CLOCKS_PER_SEC);
|
|
|
|
|