From 225d97c9dc67d310888236599b430653706843c4 Mon Sep 17 00:00:00 2001 From: Sayeth Date: Tue, 13 Oct 2020 11:33:05 -0500 Subject: [PATCH] corrections --- daq.c | 24 ++++++++++++------------ uart.c | 53 ++++++++++++++++++++++++----------------------------- uart.h | 7 +++++-- 3 files changed, 41 insertions(+), 43 deletions(-) diff --git a/daq.c b/daq.c index 9cc8e8b..55dc379 100644 --- a/daq.c +++ b/daq.c @@ -102,14 +102,14 @@ int DAQ(int t_hrs, int sp_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"; - 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 + "CO(ppm)\tO2(ppm)\tO2(%%)\tT C0(ºC*10)\t"\ + "T 02(ºC)\tP C0(.mBar)\tP 02(mBar)\tRH(.)\n"; + unsigned char co2_uf[10]="", co2_f[10]="", + co_uf[10]="", co_f[10]="", + o2_ppm[10]="", o2_xcent[10]="", + co_temp[10]="", o2_temp[10]="", + co_press[10]="", o2_press[10]="", + co_relH[10]="", DATA[100]=""; //measurements varirables time_t curtime; //current time (date) clock_t start_t, end_t; //processing time measurements 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(o2_ppm, getMeasures(receive[LuminOX], 'O', 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(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(co2_relH, getMeasures(receive[SprintIR],'H', 5), 5); + memcpy(co_relH, getMeasures(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", (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 dfp = fopen(data_file_path, "a"); // open file for writing diff --git a/uart.c b/uart.c index 01f2ef3..4e91459 100644 --- a/uart.c +++ b/uart.c @@ -1,5 +1,5 @@ /* - asd + comments */ //libraries #include "uart.h" @@ -7,27 +7,24 @@ //paths and global variables #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 -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]; - + //completing uart file path - if ((uartNumber == 1) || - (uartNumber == 2) || - (uartNumber == 4) || - (uartNumber == 5)) sprintf(fullFileName, incomplet_uart_path "%d", uartNumber); + if ((uartNumber==1)||(uartNumber==2)||(uartNumber==4)||(uartNumber==5)) + sprintf(fullFileName, incomplet_uart_path "%d", uartNumber); else{ - perror("Wrong UART number. " \ - "UART numbers availables 1, 2, 4 or 5.\n"); - return 2; + perror("Wrong UART number. " \ + "UART numbers availables 1, 2, 4 or 5.\n"); + return 2; } - //openign uart file printf("Configuring UART%d.\n", uartNumber); 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"); return -1; } - //Sets the parameters associated with file tcgetattr(uartFile[uartNumber], &options); - + //cleaning flags options.c_ispeed = 0; options.c_lflag = 0; options.c_line = 0; options.c_oflag = 0; - options.c_ospeed = 0; - + options.c_ospeed = 0 // Set up the communications options: // 8-bit, enable receiver, no modem control lines options.c_cflag = baudRate | CS8 | CREAD | CLOCAL; @@ -54,22 +49,22 @@ int uartConf(unsigned char uartNumber, int baudRate){ //options.c_lflag = ICANON; tcflush(uartFile[uartNumber], TCIOFLUSH); //discard file information not transmitted tcsetattr(uartFile[uartNumber], TCSANOW, &options); //changes occur immmediately - printf("UART%d configurated.\n", uartNumber); - - + return 0; } -int uartClose(unsigned char uartNumber){ - printf("Closing UART4.\n"); close(uartFile[uartNumber]); +int uartClose(unsigned char uartNumber) +{ + printf("Closing UART%d.\n", uartNumber); + close(uartFile[uartNumber]); return 0; } -int uartTransmit(unsigned char uartNumber, unsigned char message[]){ - +int uartTransmit(unsigned char uartNumber, unsigned char message[]) +{ int count; - + //writing file if ((count = write(uartFile[uartNumber], message, (strlen(message))))<0){ //send the string perror("Failed to write to the output\n"); @@ -80,8 +75,8 @@ int uartTransmit(unsigned char uartNumber, unsigned char message[]){ return 0; } -int uartReceive(unsigned char uartNumber){ - +int uartReceive(unsigned char uartNumber) +{ int count; /*if ((count = read(uartFile[uartNumber], (void*)receive[uartNumber], 100))<0){ //receive[uartNumber] the data diff --git a/uart.h b/uart.h index f0db2c9..4fd870b 100644 --- a/uart.h +++ b/uart.h @@ -1,7 +1,7 @@ -/* +/* * Copyright (C) 2019 Akshay Patwardhan * akshay.patwardhan@outlook.com - * + * * Please go through readme.md for usage and other instructions, if any. * * This program is free software: you can redistribute it and/or modify @@ -40,6 +40,9 @@ #define UART_INCORRECT_PATH 4 // Function declarations +/* + * uartNumber as unsigned char (8 bits) to reduce RAM usage +*/ int uartConf(unsigned char uartNumber, int baudRate); int uartClose(unsigned char uartNumber); int uartTransmit(unsigned char uartNumber, unsigned char message[]);