DAQ funtion commented.

master
Sayeth 5 years ago
parent 77ce5114b3
commit b90947c35e

151
daq.c

@ -140,84 +140,81 @@ int str2int(unsigned char *ptr){
int DAQ(int t_hrs, int tm_s) int DAQ(int t_hrs, int tm_s)
{ {
FILE* dfp; // create a file pointer dfp FILE* dfp; // create a file pointer
//int co2, co, o2, temp; unsigned char co2_uf[10]="", co2_f[10]="",
unsigned char co2_uf[10]="", co2_f[10]="", co_uf[10]="", co_f[10]="",
co_uf[10]="", co_f[10]="", o2_ppm[10]="", o2_xcent[10]="",
o2_ppm[10]="", o2_xcent[10]="", co2_temp[10]="", o2_temp[10]="",
co2_temp[10]="", o2_temp[10]="", co2_press[10]="", o2_press[10]="",
co2_press[10]="", o2_press[10]="", co2_relH[10]="", DATA[100]=""; //measurements varirables
co2_relH[10]="", DATA[100]=""; clock_t start_t, end_t; //processing time measurements variables
time_t new_time, prev_time, t0; //time control variables
clock_t start_t, end_t; double tm_ms = tm_s*1e6 - 0.20e6; //tiempo de muestreo en milisegundos (-) margen
time_t new_time, prev_time, t0; double dif = tm_ms; //diferencia de tiempo(time to sleep)
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
//registro datos de inicio time_t curtime; //current time (date)
dfp = fopen(data_file_path, "w"); // open file for writing time(&curtime); //saving date in curtime
time_t curtime; fprintf(dfp, "%sStarting DAQ\ntime(s)\tCO2 unfil(ppm)\tCO2 fil(ppm)\tCO unfil(ppm)\tCO fil(ppm)"\
time(&curtime); "\tO2(ppm)\tO2(%c)\tTemperaure C02(ºC*10)\tTemperaure 02(ºC)"\
fprintf(dfp, "%sStarting DAQ\ntime(s)\tCO2 unfil(ppm)\tCO2 fil(ppm)\tCO unfil(ppm)\tCO fil(ppm)"\ "\tPressure C02(.mBar)\tPresure 02(mBar)\tRelative Humidity(.)\n",
"\tO2(ppm)\tO2(%c)\tTemperaure C02(ºC*10)\tTemperaure 02(ºC)"\ ctime(&curtime), '%'); // send the value to the file
"\tPressure C02(.mBar)\tPresure 02(mBar)\tRelative Humidity(.)\n", fclose(dfp); // close the file using the file pointer
ctime(&curtime), '%'); // send the value to the file
fclose(dfp); // close the file using the file pointer //ciclo
t0 = time(NULL) + tm_s; //intitial time = current time + tiempo de muestreo
//ciclo new_time = t0; //saving initial time in time control variable
t0 = time(NULL) + tm_s; for(int i = 0; i < (t_hrs*3600); i=i+tm_s){ //cycle from 0 to adquisition time (seconds), incrementing sampling period
new_time = t0;
for(int i = 0; i < (t_hrs*3600); i=i+tm_s){ 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
if (dif <= 0) printf("T=%d Communication time exceded.\n", (int)(new_time-t0)); //waiting new second (time.h system) to start measurements
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));
if (time(NULL) < new_time) while(new_time != time(NULL));
else printf("T=%d time error.\n", (int)(new_time-t0)); start_t = clock(); //saving start time
new_time = time(NULL); //refresh new_time (next iteration)
start_t = clock(); //transmiting commands to sensors
new_time = time(NULL); uartTransmit(CM31911, get_readigns);
//command transmitions uartTransmit(OX0052, Readings_OX);
uartTransmit(CM31911, get_readigns); uartTransmit(GC0017, get_readigns
uartTransmit(OX0052, Readings_OX); //receiving replys from sensors
uartTransmit(GC0017, get_readigns); uartReceive(OX0052);
uartReceive(CM31911);
//uart receptions uartReceive(GC0017);
uartReceive(OX0052); //saving gas measurements in measurements variables
uartReceive(CM31911); memcpy(co2_uf, gmeasures(receive[GC0017], 'z', 5), 5);
uartReceive(GC0017); memcpy(co2_f, gmeasures(receive[GC0017], 'Z', 5), 5);
memcpy(co_uf, gmeasures(receive[CM31911], 'z', 5), 5);
memcpy(co2_uf, gmeasures(receive[GC0017], 'z', 5), 5); memcpy(co_f, gmeasures(receive[CM31911], 'Z', 5), 5);
memcpy(co2_f, gmeasures(receive[GC0017], 'Z', 5), 5); memcpy(o2_ppm, gmeasures(receive[OX0052], 'O', 6), 6);
memcpy(co_uf, gmeasures(receive[CM31911], 'z', 5), 5); memcpy(o2_xcent, gmeasures(receive[OX0052], '%', 6), 6);
memcpy(co_f, gmeasures(receive[CM31911], 'Z', 5), 5); memcpy(co2_temp, gmeasures(receive[CM31911], 'T', 5), 5);
memcpy(o2_ppm, gmeasures(receive[OX0052], 'O', 6), 6); memcpy(o2_temp, gmeasures(receive[OX0052], 'T', 5), 5);
memcpy(o2_xcent, gmeasures(receive[OX0052], '%', 6), 6); memcpy(co2_press,gmeasures(receive[CM31911], 'B', 5), 5);
memcpy(co2_temp, gmeasures(receive[CM31911], 'T', 5), 5); memcpy(o2_press, gmeasures(receive[OX0052], 'P', 4), 4);
memcpy(o2_temp, gmeasures(receive[OX0052], 'T', 5), 5); memcpy(co2_relH, gmeasures(receive[CM31911], 'H', 5), 5);
memcpy(co2_press,gmeasures(receive[CM31911], 'B', 5), 5); //saving formated measurements in string DATA
memcpy(o2_press, gmeasures(receive[OX0052], 'P', 4), 4); 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",
memcpy(co2_relH, gmeasures(receive[CM31911], 'H', 5), 5); (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);
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", //showing measurements on display
(int)(new_time-t0), co2_uf, co2_f, co_uf, co_f, o2_ppm, o2_xcent, printf("time(s)\tCO2 unfil(ppm)\tCO2 fil(ppm)\tCO unfil(ppm)\tCO fil(ppm)"\
co2_temp, o2_temp, co2_press, o2_press, co2_relH); "\tO2(ppm)\tO2(%c)\tTemperaure C02(ºC*10)\tTemperaure 02(ºC)"\
"\tPressure C02(.mBar)\tPresure 02(mBar)\tRelative Humidity(.)\n", '%');
printf("time(s)\tCO2 unfil(ppm)\tCO2 fil(ppm)\tCO unfil(ppm)\tCO fil(ppm)"\ printf("%s\n", DATA);
"\tO2(ppm)\tO2(%c)\tTemperaure C02(ºC*10)\tTemperaure 02(ºC)"\
"\tPressure C02(.mBar)\tPresure 02(mBar)\tRelative Humidity(.)\n", '%'); dfp = fopen(data_file_path, "a"); // open file for writing
printf("%s\n", DATA); fprintf(dfp, "%s\n", DATA); // saving measurements string to data file
fclose(dfp); // close the file using the file pointer
dfp = fopen(data_file_path, "a"); // open file for writing new_time += tm_s; //adding sampling period to new_time
fprintf(dfp, "%s\n", DATA); end_t = clock(); //saving end time
fclose(dfp); // close the file using the file pointer //calculate time to sleep
new_time += tm_s; dif = tm_ms - ((double)(end_t - start_t)*1e6 / CLOCKS_PER_SEC);
end_t = clock(); }
dif = tm_ms - ((double)(end_t - start_t)*1e6 / CLOCKS_PER_SEC);
}
return 0; return 0;
} }
char *gmeasures(char src[], char fval, int nchar){ char *gmeasures(char src[], char fval, int nchar){

Loading…
Cancel
Save