|
|
|
@ -24,10 +24,14 @@
|
|
|
|
|
#define get_readigns "Q\r\n"
|
|
|
|
|
#define percent_oxigen "%\r\n"
|
|
|
|
|
#define ppm_oxigen "O\r\n"
|
|
|
|
|
#define M_zZTHBD "M 14406\r\n"
|
|
|
|
|
#define Readings_CM "Q\r\n"
|
|
|
|
|
#define Readings_OX "A\r\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int sensConf(unsigned char uartNumber, int baudRate, unsigned char mode[], unsigned char response[]);
|
|
|
|
|
int measure(unsigned char uartNumber, unsigned char command[], int multiplier, int excess);
|
|
|
|
|
char *gmeasures(char src[], char fval, int nchar);
|
|
|
|
|
|
|
|
|
|
int str2int(unsigned char *ptr);
|
|
|
|
|
|
|
|
|
@ -36,6 +40,8 @@ int DAQ(int t_hrs, int tm_s);
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]){
|
|
|
|
|
|
|
|
|
|
//char bioxCsen[], OXsen[], monoxCsen[];
|
|
|
|
|
|
|
|
|
|
int T,t;
|
|
|
|
|
|
|
|
|
|
if(argc!=3){
|
|
|
|
@ -48,13 +54,16 @@ int main(int argc, char *argv[]){
|
|
|
|
|
sensConf(GC0017, B9600, Pulling_Mode, " K 00002\r\n");
|
|
|
|
|
printf("Configuring CO sensor\n");
|
|
|
|
|
sensConf(CM31911, B9600, Pulling_Mode, "K 00002\r\n");
|
|
|
|
|
sensConf(CM31911, B9600, M_zZTHBD, "M 14406\r\n");
|
|
|
|
|
printf("Configuring O2 sensor\n");
|
|
|
|
|
sensConf(OX0052, B9600, OX_P_Mode, "M 01\r\n");
|
|
|
|
|
|
|
|
|
|
//adquisición
|
|
|
|
|
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);
|
|
|
|
|
sleep(1);
|
|
|
|
|
|
|
|
|
@ -132,7 +141,15 @@ int str2int(unsigned char *ptr){
|
|
|
|
|
int DAQ(int t_hrs, int tm_s)
|
|
|
|
|
{
|
|
|
|
|
FILE* dfp; // create a file pointer dfp
|
|
|
|
|
|
|
|
|
|
int co2, co, o2, temp;
|
|
|
|
|
unsigned char 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]="";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
clock_t start_t, end_t;
|
|
|
|
|
time_t new_time, prev_time, t0;
|
|
|
|
|
double tm_ms = tm_s*1e6 - 0.20e6;
|
|
|
|
@ -142,7 +159,10 @@ int DAQ(int t_hrs, int tm_s)
|
|
|
|
|
dfp = fopen(data_file_path, "w"); // open file for writing
|
|
|
|
|
time_t curtime;
|
|
|
|
|
time(&curtime);
|
|
|
|
|
fprintf(dfp, "%sStarting DAQ\ntime(s)\tCO2(ppm)\tCO(ppm)\tO2(ppm)\tTemperaure(ºC*10)\n", ctime(&curtime)); // send the value to the file
|
|
|
|
|
fprintf(dfp, "%sStarting DAQ\ntime(s)\tCO2(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
|
|
|
|
|
fclose(dfp); // close the file using the file pointer
|
|
|
|
|
|
|
|
|
|
//ciclo
|
|
|
|
@ -158,17 +178,48 @@ int DAQ(int t_hrs, int tm_s)
|
|
|
|
|
|
|
|
|
|
start_t = clock();
|
|
|
|
|
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);
|
|
|
|
|
//command transmitions
|
|
|
|
|
uartTransmit(CM31911, Readings_CM);
|
|
|
|
|
uartTransmit(OX0052, Readings_OX);
|
|
|
|
|
uartTransmit(GC0017, unf_gas_con);
|
|
|
|
|
|
|
|
|
|
//uart receptions
|
|
|
|
|
uartReceive(OX0052);
|
|
|
|
|
uartReceive(CM31911);
|
|
|
|
|
co2 = read_measure(GC0017, 10, 0);
|
|
|
|
|
o2 = read_measure(OX0052, 1, 0);
|
|
|
|
|
temp = read_measure(CM31911, 1, 1000);
|
|
|
|
|
|
|
|
|
|
//co = read_measure(CM31911, 1, 0);
|
|
|
|
|
//uartTransmit(CM31911, Temperature);
|
|
|
|
|
//o2 = read_measure(OX0052, 1, 0);
|
|
|
|
|
//temp = read_measure(CM31911, 1, 1000);
|
|
|
|
|
|
|
|
|
|
//printf("unfil co: %s\n",gmeasures(receive[CM31911], 'H', 5));
|
|
|
|
|
//printf("unfil co: %s\n",gmeasures(receive[CM31911], 'Z', 5));
|
|
|
|
|
|
|
|
|
|
memcpy(co_uf, gmeasures(receive[CM31911], 'z', 5), 5);
|
|
|
|
|
memcpy(co_f, gmeasures(receive[CM31911], 'Z', 5), 5);
|
|
|
|
|
memcpy(o2_ppm, gmeasures(receive[OX0052], 'O', 6), 6);
|
|
|
|
|
memcpy(o2_xcent, gmeasures(receive[OX0052], '%', 6), 6);
|
|
|
|
|
memcpy(co2_temp, gmeasures(receive[CM31911], 'T', 5), 5);
|
|
|
|
|
memcpy(o2_temp, gmeasures(receive[OX0052], 'T', 5), 5);
|
|
|
|
|
memcpy(co2_press,gmeasures(receive[CM31911], 'B', 5), 5);
|
|
|
|
|
memcpy(o2_press, gmeasures(receive[OX0052], 'P', 4), 4);
|
|
|
|
|
memcpy(co2_relH, gmeasures(receive[CM31911], 'H', 5), 5);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//printf("pressure: %s\n",gmeasures(receive[OX0052], 'P', 4));
|
|
|
|
|
//printf("oxigen xcent: %s\n",gmeasures(receive[OX0052], '%', 6));
|
|
|
|
|
//printf("Temperature: %s\n",gmeasures(receive[OX0052], 'T', 5));
|
|
|
|
|
|
|
|
|
|
dfp = fopen(data_file_path, "a"); // open file for writing
|
|
|
|
|
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
|
|
|
|
|
fprintf(dfp, "%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
|
|
|
|
|
(int)(new_time-t0), co2, co_uf, co_f, o2_ppm, o2_xcent,
|
|
|
|
|
co2_temp, o2_temp, co2_press, o2_press, co2_relH);
|
|
|
|
|
/* gmeasures(receive[CM31911], 'Z', 5), gmeasures(receive[OX0052], 'O', 6),
|
|
|
|
|
gmeasures(receive[OX0052], '%', 6), gmeasures(receive[CM31911], 'T', 5),
|
|
|
|
|
gmeasures(receive[OX0052], 'T', 5), gmeasures(receive[CM31911], 'P', 5),
|
|
|
|
|
gmeasures(receive[OX0052], 'P', 4), gmeasures(receive[CM31911], 'H', 5)); // send the value to the file
|
|
|
|
|
*/
|
|
|
|
|
fclose(dfp); // close the file using the file pointer
|
|
|
|
|
new_time += tm_s;
|
|
|
|
|
end_t = clock();
|
|
|
|
@ -179,3 +230,12 @@ int DAQ(int t_hrs, int tm_s)
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *gmeasures(char src[], char fval, int nchar){
|
|
|
|
|
char * ptr = &src[0];
|
|
|
|
|
static char s[10]="";
|
|
|
|
|
|
|
|
|
|
while(*ptr != fval) ptr++;
|
|
|
|
|
ptr += 2;
|
|
|
|
|
memcpy(s, ptr, nchar);
|
|
|
|
|
return s;
|
|
|
|
|
}
|