modify the serialio.c file so that it continuously takes 960 samples, computes the average, converts the average value to temperature, and prints out the result. you can’t give the buf array as a buffer pointer to read. Instead, you will need to give a pointer to the current position in the buf array like &buf[i], where i is the number of bytes that have been read so far. Every time you do the read, you will need to read 960-i bytes to account for the fact that you have already read i bytes. Once you reach 960 bytes, drop out of the loop and calculate the average and the actual temperature using the formulas below. After you print the temperature, start again, and get a new 960 samples of data. Also, when doing the math, make sure you are doing the calculations using floats or doubles.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter8: I/o Streams And Data Files
Section: Chapter Questions
Problem 8PP: (Data processing) A bank’s customer records are to be stored in a file and read into a set of arrays...
icon
Related questions
Question

modify the serialio.c file so that it continuously takes 960 samples, computes
the average, converts the average value to temperature, and prints out the result. you can’t give the buf array as a buffer
pointer to read. Instead, you will need to give a pointer to the current position in the buf array
like &buf[i], where i is the number of bytes that have been read so far. Every time you do the
read, you will need to read 960-i bytes to account for the fact that you have already read i bytes.
Once you reach 960 bytes, drop out of the loop and calculate the average and the actual temperature
using the formulas below. After you print the temperature, start again, and get a new 960 samples
of data. Also, when
doing the math, make sure you are doing the calculations using floats or doubles.

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <termios.h>
int main(int argc, char** argv)
{
char *port = argv[1];
int fd = open(port, O_RDONLY);
if (fd < 0) {
}
perror("Could not open port");
exit(-1);
// code to set communication rate to 9600 bits per second
struct termios tio;
tcgetattr(fd, &tio);
cfsetspeed(&tio, 89600);
tcsetattr(fd, 0, &tio);
// reopen the serial port so that the speed change takes effect
close(fd);
fd = open(port, O_RDONLY);
if (fd < 0) {
}
perror("Could not open port");
exit(-1);
uint8_t buf[256];
while(1) {
int nbytes = read(fd, buf, sizeof(buf));
if (nbytes == -1) {
}
perror("read error");
for (int i=0; i<nbytes; i++) {
printf("%d\n", buf[i]);
}
Transcribed Image Text:#include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <unistd.h> #include <termios.h> int main(int argc, char** argv) { char *port = argv[1]; int fd = open(port, O_RDONLY); if (fd < 0) { } perror("Could not open port"); exit(-1); // code to set communication rate to 9600 bits per second struct termios tio; tcgetattr(fd, &tio); cfsetspeed(&tio, 89600); tcsetattr(fd, 0, &tio); // reopen the serial port so that the speed change takes effect close(fd); fd = open(port, O_RDONLY); if (fd < 0) { } perror("Could not open port"); exit(-1); uint8_t buf[256]; while(1) { int nbytes = read(fd, buf, sizeof(buf)); if (nbytes == -1) { } perror("read error"); for (int i=0; i<nbytes; i++) { printf("%d\n", buf[i]); }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,