corrections

master
Sayeth 5 years ago
parent 9cb52e6269
commit 225d97c9dc

24
daq.c

@ -102,14 +102,14 @@ int DAQ(int t_hrs, int sp_s)
{ {
FILE* dfp; // create a file pointer FILE* dfp; // create a file pointer
const char colums[200] = "t(s)\tCO2 uf(ppm)\tCO2(ppm)\tCO uf(ppm)\t"\ 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"\ "CO(ppm)\tO2(ppm)\tO2(%%)\tT C0(ºC*10)\t"\
"T 02(ºC)\tP C02(.mBar)\tP 02(mBar)\tRH(.)\n"; "T 02(ºC)\tP C0(.mBar)\tP 02(mBar)\tRH(.)\n";
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]="", co_temp[10]="", o2_temp[10]="",
co2_press[10]="", o2_press[10]="", co_press[10]="", o2_press[10]="",
co2_relH[10]="", DATA[100]=""; //measurements varirables co_relH[10]="", DATA[100]=""; //measurements varirables
time_t curtime; //current time (date) time_t curtime; //current time (date)
clock_t start_t, end_t; //processing time measurements variables clock_t start_t, end_t; //processing time measurements variables
time_t next_samp_time, t0; //time control variables time_t next_samp_time, t0; //time control variables
@ -152,16 +152,16 @@ int DAQ(int t_hrs, int sp_s)
memcpy(co_f, getMeasures(receive[COAF], 'Z', 5), 5); memcpy(co_f, getMeasures(receive[COAF], 'Z', 5), 5);
memcpy(o2_ppm, getMeasures(receive[LuminOX], 'O', 6), 6); memcpy(o2_ppm, getMeasures(receive[LuminOX], 'O', 6), 6);
memcpy(o2_xcent, getMeasures(receive[LuminOX], '%', 6), 6); memcpy(o2_xcent, getMeasures(receive[LuminOX], '%', 6), 6);
memcpy(co2_temp, getMeasures(receive[SprintIR],'T', 5), 5); memcpy(co_temp, getMeasures(receive[COAF], 'T', 5), 5);
memcpy(o2_temp, getMeasures(receive[LuminOX], 'T', 5), 5); memcpy(o2_temp, getMeasures(receive[LuminOX], 'T', 5), 5);
memcpy(co2_press,getMeasures(receive[SprintIR],'B', 5), 5); memcpy(co_press, getMeasures(receive[COAF], 'B', 5), 5);
memcpy(o2_press, getMeasures(receive[LuminOX], 'P', 4), 4); memcpy(o2_press, getMeasures(receive[LuminOX], 'P', 4), 4);
memcpy(co2_relH, getMeasures(receive[SprintIR],'H', 5), 5); memcpy(co_relH, getMeasures(receive[COAF], 'H', 5), 5);
//saving formated measurements in string DATA //saving formated measurements in string DATA
sprintf(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", "%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s",
(int)t, co2_uf, co2_f, co_uf, co_f, o2_ppm, o2_xcent, (int)t, co2_uf, co2_f, co_uf, co_f, o2_ppm, o2_xcent,
co2_temp, o2_temp, co2_press, o2_press, co2_relH); co_temp, o2_temp, co_press, o2_press, co_relH);
printf("\r%s", DATA); //showing measurements on display printf("\r%s", DATA); //showing measurements on display
dfp = fopen(data_file_path, "a"); // open file for writing dfp = fopen(data_file_path, "a"); // open file for writing

@ -1,5 +1,5 @@
/* /*
asd comments
*/ */
//libraries //libraries
#include "uart.h" #include "uart.h"
@ -7,27 +7,24 @@
//paths and global variables //paths and global variables
#define incomplet_uart_path "/dev/ttyO" #define incomplet_uart_path "/dev/ttyO"
int uartFile[6]; //file descriptor int uartFile[6]; //file descriptor
unsigned char receive[6][100]; //declare a buffer for receiving data unsigned char receive[6][100]; //declare a buffer for receiving data
struct termios options; //The termios structure is vital struct termios options; //The termios structure
//funtions // *** FUNCTIONS ***
int uartConf(unsigned char uartNumber, int baudRate){ int uartConf(unsigned char uartNumber, int baudRate)
{
unsigned char fullFileName[11]; unsigned char fullFileName[11];
//completing uart file path //completing uart file path
if ((uartNumber == 1) || if ((uartNumber==1)||(uartNumber==2)||(uartNumber==4)||(uartNumber==5))
(uartNumber == 2) || sprintf(fullFileName, incomplet_uart_path "%d", uartNumber);
(uartNumber == 4) ||
(uartNumber == 5)) sprintf(fullFileName, incomplet_uart_path "%d", uartNumber);
else{ else{
perror("Wrong UART number. " \ perror("Wrong UART number. " \
"UART numbers availables 1, 2, 4 or 5.\n"); "UART numbers availables 1, 2, 4 or 5.\n");
return 2; return 2;
} }
//openign uart file //openign uart file
printf("Configuring UART%d.\n", uartNumber); printf("Configuring UART%d.\n", uartNumber);
if ((uartFile[uartNumber] = open(fullFileName, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK))<0){ if ((uartFile[uartNumber] = open(fullFileName, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK))<0){
@ -36,16 +33,14 @@ int uartConf(unsigned char uartNumber, int baudRate){
perror("UART: Failed to open the file.\n"); perror("UART: Failed to open the file.\n");
return -1; return -1;
} }
//Sets the parameters associated with file //Sets the parameters associated with file
tcgetattr(uartFile[uartNumber], &options); tcgetattr(uartFile[uartNumber], &options);
//cleaning flags
options.c_ispeed = 0; options.c_ispeed = 0;
options.c_lflag = 0; options.c_lflag = 0;
options.c_line = 0; options.c_line = 0;
options.c_oflag = 0; options.c_oflag = 0;
options.c_ospeed = 0; options.c_ospeed = 0
// Set up the communications options: // Set up the communications options:
// 8-bit, enable receiver, no modem control lines // 8-bit, enable receiver, no modem control lines
options.c_cflag = baudRate | CS8 | CREAD | CLOCAL; options.c_cflag = baudRate | CS8 | CREAD | CLOCAL;
@ -54,22 +49,22 @@ int uartConf(unsigned char uartNumber, int baudRate){
//options.c_lflag = ICANON; //options.c_lflag = ICANON;
tcflush(uartFile[uartNumber], TCIOFLUSH); //discard file information not transmitted tcflush(uartFile[uartNumber], TCIOFLUSH); //discard file information not transmitted
tcsetattr(uartFile[uartNumber], TCSANOW, &options); //changes occur immmediately tcsetattr(uartFile[uartNumber], TCSANOW, &options); //changes occur immmediately
printf("UART%d configurated.\n", uartNumber); printf("UART%d configurated.\n", uartNumber);
return 0; return 0;
} }
int uartClose(unsigned char uartNumber){ int uartClose(unsigned char uartNumber)
printf("Closing UART4.\n"); close(uartFile[uartNumber]); {
printf("Closing UART%d.\n", uartNumber);
close(uartFile[uartNumber]);
return 0; return 0;
} }
int uartTransmit(unsigned char uartNumber, unsigned char message[]){ int uartTransmit(unsigned char uartNumber, unsigned char message[])
{
int count; int count;
//writing file //writing file
if ((count = write(uartFile[uartNumber], message, (strlen(message))))<0){ //send the string if ((count = write(uartFile[uartNumber], message, (strlen(message))))<0){ //send the string
perror("Failed to write to the output\n"); perror("Failed to write to the output\n");
@ -80,8 +75,8 @@ int uartTransmit(unsigned char uartNumber, unsigned char message[]){
return 0; return 0;
} }
int uartReceive(unsigned char uartNumber){ int uartReceive(unsigned char uartNumber)
{
int count; int count;
/*if ((count = read(uartFile[uartNumber], (void*)receive[uartNumber], 100))<0){ //receive[uartNumber] the data /*if ((count = read(uartFile[uartNumber], (void*)receive[uartNumber], 100))<0){ //receive[uartNumber] the data

@ -1,7 +1,7 @@
/* /*
* Copyright (C) 2019 Akshay Patwardhan * Copyright (C) 2019 Akshay Patwardhan
* akshay.patwardhan@outlook.com * akshay.patwardhan@outlook.com
* *
* Please go through readme.md for usage and other instructions, if any. * Please go through readme.md for usage and other instructions, if any.
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -40,6 +40,9 @@
#define UART_INCORRECT_PATH 4 #define UART_INCORRECT_PATH 4
// Function declarations // Function declarations
/*
* uartNumber as unsigned char (8 bits) to reduce RAM usage
*/
int uartConf(unsigned char uartNumber, int baudRate); int uartConf(unsigned char uartNumber, int baudRate);
int uartClose(unsigned char uartNumber); int uartClose(unsigned char uartNumber);
int uartTransmit(unsigned char uartNumber, unsigned char message[]); int uartTransmit(unsigned char uartNumber, unsigned char message[]);

Loading…
Cancel
Save