|
|
|
@ -10,10 +10,9 @@
|
|
|
|
|
#include"uart.c"
|
|
|
|
|
|
|
|
|
|
#define data_file_path "/var/lib/cloud9/daq-serial-bbb/data.dat"
|
|
|
|
|
|
|
|
|
|
#define GC0017 4 //co2
|
|
|
|
|
#define CM31911 1 //co, t
|
|
|
|
|
#define OX0052 2 //o2
|
|
|
|
|
#define SprintIR 4 //co2 sensor
|
|
|
|
|
#define COAF 1 //co sensor
|
|
|
|
|
#define LuminOX 2 //o2
|
|
|
|
|
|
|
|
|
|
#define Rep_Dev_ID "Y\r\n"
|
|
|
|
|
#define Pulling_Mode "K 2\r\n"
|
|
|
|
@ -28,52 +27,43 @@
|
|
|
|
|
#define M_zZTHBD "M 14406\r\n"
|
|
|
|
|
#define Readings_OX "A\r\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int sensConf(unsigned char uartNumber, int baudRate, unsigned char mode[], unsigned char response[], int tries);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
int DAQ(int t_hrs, int tm_s);
|
|
|
|
|
|
|
|
|
|
char *gmeasures(char src[], char fval, int nchar
|
|
|
|
|
int str2int(unsigned char *ptr
|
|
|
|
|
int DAQ(int t_hrs, int tm_s
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]){
|
|
|
|
|
|
|
|
|
|
//char bioxCsen[], OXsen[], monoxCsen[];
|
|
|
|
|
|
|
|
|
|
int T,t;
|
|
|
|
|
int T_acq, t_samp;
|
|
|
|
|
|
|
|
|
|
if(argc!=3){
|
|
|
|
|
printf("Invalid number of arguments,\n usage: daq <time(h)> <sampling period(s)>\nexiting!\n");
|
|
|
|
|
printf("Invalid number of arguments,\n"\
|
|
|
|
|
"Usage: daq <time(h)> <sampling period(s)>\nexiting!\n");
|
|
|
|
|
return -2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//configuración de sensores
|
|
|
|
|
printf("Configuring CO2 sensor\n");
|
|
|
|
|
sensConf(GC0017, B9600, Pulling_Mode, " K 00002\r\n", 5);
|
|
|
|
|
sensConf(GC0017, B9600, FILnUNFIL, " M 00006\r\n", 5);
|
|
|
|
|
sensConf(SprintIR, B9600, Pulling_Mode, " K 00002\r\n", 5);
|
|
|
|
|
sensConf(SprintIR, B9600, FILnUNFIL, " M 00006\r\n", 5);
|
|
|
|
|
printf("Configuring CO sensor\n");
|
|
|
|
|
sensConf(CM31911, B9600, Pulling_Mode, "K 00002\r\n", 5);
|
|
|
|
|
sensConf(CM31911, B9600, M_zZTHBD, "M 14406\r\n", 5);
|
|
|
|
|
sensConf(COAF, B9600, Pulling_Mode, "K 00002\r\n", 5);
|
|
|
|
|
sensConf(COAF, B9600, M_zZTHBD, "M 14406\r\n", 5);
|
|
|
|
|
printf("Configuring O2 sensor\n");
|
|
|
|
|
sensConf(OX0052, B9600, OX_P_Mode, "M 01\r\n", 5);
|
|
|
|
|
sensConf(LuminOX, B9600, OX_P_Mode, "M 01\r\n", 5);
|
|
|
|
|
|
|
|
|
|
//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);
|
|
|
|
|
|
|
|
|
|
T_acq = atoi(argv[1]);//str to int
|
|
|
|
|
t_samp = atoi(argv[2]);
|
|
|
|
|
printf("Starting data acquisition with duration of %dh every %ds\n", T_acq, t_samp);
|
|
|
|
|
DAQ(T, t);
|
|
|
|
|
sleep(1);
|
|
|
|
|
|
|
|
|
|
//finalización
|
|
|
|
|
//deinit uart
|
|
|
|
|
uartClose(GC0017);
|
|
|
|
|
uartClose(CM31911);
|
|
|
|
|
uartClose(OX0052);
|
|
|
|
|
|
|
|
|
|
uartClose(SprintIR);
|
|
|
|
|
uartClose(COAF);
|
|
|
|
|
uartClose(LuminOX);
|
|
|
|
|
//finalización
|
|
|
|
|
printf("Exiting of the program...\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -163,38 +153,39 @@ int DAQ(int t_hrs, int tm_s)
|
|
|
|
|
,
|
|
|
|
|
ctime(&curtime)); // send the value to the file
|
|
|
|
|
fclose(dfp); // close the file using the file pointer
|
|
|
|
|
printf("%s", colums);
|
|
|
|
|
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
|
|
|
|
|
//checking if there's time to sleep
|
|
|
|
|
if (dif <= 0) printf("Ejecution time exceded.\n");
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
|
|
start_t = clock(); //saving start time
|
|
|
|
|
//transmiting commands to sensors
|
|
|
|
|
uartTransmit(CM31911, get_readigns);
|
|
|
|
|
uartTransmit(OX0052, Readings_OX);
|
|
|
|
|
uartTransmit(GC0017, get_readigns
|
|
|
|
|
uartTransmit(COAF, get_readigns);
|
|
|
|
|
uartTransmit(LuminOX, Readings_OX);
|
|
|
|
|
uartTransmit(SprintIR, get_readigns
|
|
|
|
|
//receiving replys from sensors
|
|
|
|
|
uartReceive(OX0052);
|
|
|
|
|
uartReceive(CM31911);
|
|
|
|
|
uartReceive(GC0017);
|
|
|
|
|
uartReceive(LuminOX);
|
|
|
|
|
uartReceive(COAF);
|
|
|
|
|
uartReceive(SprintIR);
|
|
|
|
|
//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);
|
|
|
|
|
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);
|
|
|
|
|
memcpy(co2_uf, gmeasures(receive[SprintIR], 'z', 5), 5);
|
|
|
|
|
memcpy(co2_f, gmeasures(receive[SprintIR], 'Z', 5), 5);
|
|
|
|
|
memcpy(co_uf, gmeasures(receive[COAF], 'z', 5), 5);
|
|
|
|
|
memcpy(co_f, gmeasures(receive[COAF], 'Z', 5), 5);
|
|
|
|
|
memcpy(o2_ppm, gmeasures(receive[LuminOX], 'O', 6), 6);
|
|
|
|
|
memcpy(o2_xcent, gmeasures(receive[LuminOX], '%', 6), 6);
|
|
|
|
|
memcpy(co2_temp, gmeasures(receive[COAF], 'T', 5), 5);
|
|
|
|
|
memcpy(o2_temp, gmeasures(receive[LuminOX], 'T', 5), 5);
|
|
|
|
|
memcpy(co2_press,gmeasures(receive[COAF], 'B', 5), 5);
|
|
|
|
|
memcpy(o2_press, gmeasures(receive[LuminOX], 'P', 4), 4);
|
|
|
|
|
memcpy(co2_relH, gmeasures(receive[COAF], '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",
|
|
|
|
|