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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education