Question: Lab.c #include #include #include #include ghcontrol.h int main() { time_t now; double creadings[SENSORS] = {0.0}; GhControllerInit(); while (1) { now = time(NULL); GhDisplayReadings(now,creadings); GhDelay(GHUPDATE); }

Lab.c

#include #include #include #include "ghcontrol.h"

int main() {

time_t now; double creadings[SENSORS] = {0.0};

GhControllerInit(); while (1) { now = time(NULL); GhDisplayReadings(now,creadings); GhDelay(GHUPDATE); }

fprintf(stdout, "Press ENTER to continue..."); getchar();

return EXIT_FAILURE; }

ghcontrol.h

// Constants #ifndef GHCONTROL_H #define GHCONTROL_H #define SEARCHSTR "serial\t\t" #define SYSINFOBUFSZ 512 #define GHUPDATE 2000 #define SENSORS 3 #define TEMPERATURE 0 #define HUMIDITY 1 #define PRESSURE 2

// Includes #include #include #include #include #include #include #include

// Function Prototypes void GhControllerInit(void); int GhGetRandom(int range); uint64_t GhGetSerial(void); void GhGetReadings(double readings[SENSORS]); double GhGetHumidity(void); double GhGetPressure(void); double GhGetTemperature(void); void GhDisplayHeader(const char *sname); void GhDisplayReadings(time_t rtime, double dreads[SENSORS]); void GhDisplayControls(void); void GhDisplayTargets(void); void GhSetControls(void); void GhSetTargets(void); void GhDelay(int milliseconds);

#endif

ghcontrol.c

#include "ghcontrol.h"

void GhControllerInit(void) { srand((unsigned)time (NULL)); GhDisplayHeader("Name"); }

void GhDisplayHeader(const char *sname) { fprintf(stdout, "%s's Greenhouse Controller ", sname); }

void GhDisplayReadings(time_t rtime, double dreads[SENSORS]) { // fprintf(stdout," Unit: %LX %sReadings\tT: %5.1fC\tH: %5.1f%\tP: %6.1fmb ",GhGetSerial(),ctime(&rtime),GhGetRandom(100)-50.0); fprintf(stdout," Unit: %LX %sReadings\tT: %5.1lfC\tH: %5.1f%%\tP: %6.1lfmb ",GhGetSerial(),ctime(&rtime),GhGetRandom(100)-50.0),dreads[TEMPERATURE],dreads[HUMIDITY],dreads[PRESSURE]; }

void GhDisplayControls(void) {

}

void GhDisplayTargets(void) {

}

void GhSetControls(void) {

}

void GhSetTargets(void) {

}

void GhDelay(int milliseconds) { long wait; clock_t now, start;

wait = milliseconds * (CLOCKS_PER_SEC / 1000); start = clock(); now = start; while ((now - start)

uint64_t GhGetSerial(void) { static uint64_t serial = 0; FILE *fp; char buf[SYSINFOBUFSZ]; char searchstring[] = SEARCHSTR; fp = fopen("/proc/cpuinfo", "r"); if (fp != NULL) { while (fgets(buf, sizeof(buf), fp) != NULL) { if (!strncasecmp(searchstring, buf, strlen(searchstring))) { sscanf(buf + strlen(searchstring), "%lu", &serial); } } fclose(fp); } if (serial == 0) { system("uname -a"); system("ls --fu /usr/lib/codeblocks | grep -Po '\\.\\K[^ ]+'>stamp.txt"); fp = fopen("stamp.txt", "r"); if (fp != NULL) { while (fgets(buf, sizeof(buf), fp) != NULL) { sscanf(buf, "%lu", &serial); } fclose(fp); } } return serial; }

void GhGetReadings(double readings[SENSORS]) { readings[HUMIDITY] = GhGetHumidity(); readings[TEMPERATURE] = GhGetTemperature(); readings[PRESSURE] = GhGetPressure(); }

double GhGetHumidity(void) { return 55.0; }

double GhGetPressure(void) { return 1013.0; }

double GhGetTemperature(void) { return 20.0; }

int GhGetRandom(int range) {

return rand() % range; }

Lab.c #include #include #include #include "ghcontrol.h" int main() { time_t now; double

Having trouble fprint the humidity and pressure, thanks for the help in advance

Task 4-ghcontrol Functions Add the following new functions to the ghcontrol.h/c files. double GhGetHumidity(void); This function will return a fixed value of 55.0 double GhGetPressure(void); This function will return a fixed value of 1013.0 double GhGet Temperature(void); This function will return a fixed value of 20.0 void GhGetReadings(double readings[SENSORS]); 1. This function uses a data type found in time.h, make sure you include this header file in ghcontrol.h 2. SENSORS is a constant with a value of 3, three other constants are declared as well: TEMPERATURE with a value of 0, HUMIDITY with a value of 1, and PRESSURE with a value of 2. 3. Assign readings to the appropriate readings element using the appropriate function call. For example: readings[TEMPERATURE] = GhGet Temperature(); Task 5 - GhDisplay Readings Modify this function by adding a new parameter and array of the sensor readings. void GhDisplayReadings(time_t rtime, double dreads[SENSORS]); Use an fprintf statement to print the data-time information: fprintf(stdout, AnUnit:%LX %s Readings\tT: %5.11fC ", GhGetSerial0,ctime(&rtime), dreads[TEMPERATURE); Add to this fprintf to print the reading information using the values passed to this function by the dreads array. The fprintf format specifiers should print doubles with 5.11f for temperature, 5.11f for humidity, and 6.11f format for pressure. Notice that the serial number information has been moved from GhDisplayHeader. Task 6 - labo3.c Modifications We now require a few data structures in the main() to use with the change function interfaces. 1. Before the while loop, declare an array of doubles called creadings, with size SENSORS, and initialize the values to 0.0 2. In the while loop, pass the array name creadings to GhGetReadings, and then GhDisplay Readings. Task 4-ghcontrol Functions Add the following new functions to the ghcontrol.h/c files. double GhGetHumidity(void); This function will return a fixed value of 55.0 double GhGetPressure(void); This function will return a fixed value of 1013.0 double GhGet Temperature(void); This function will return a fixed value of 20.0 void GhGetReadings(double readings[SENSORS]); 1. This function uses a data type found in time.h, make sure you include this header file in ghcontrol.h 2. SENSORS is a constant with a value of 3, three other constants are declared as well: TEMPERATURE with a value of 0, HUMIDITY with a value of 1, and PRESSURE with a value of 2. 3. Assign readings to the appropriate readings element using the appropriate function call. For example: readings[TEMPERATURE] = GhGet Temperature(); Task 5 - GhDisplay Readings Modify this function by adding a new parameter and array of the sensor readings. void GhDisplayReadings(time_t rtime, double dreads[SENSORS]); Use an fprintf statement to print the data-time information: fprintf(stdout, AnUnit:%LX %s Readings\tT: %5.11fC ", GhGetSerial0,ctime(&rtime), dreads[TEMPERATURE); Add to this fprintf to print the reading information using the values passed to this function by the dreads array. The fprintf format specifiers should print doubles with 5.11f for temperature, 5.11f for humidity, and 6.11f format for pressure. Notice that the serial number information has been moved from GhDisplayHeader. Task 6 - labo3.c Modifications We now require a few data structures in the main() to use with the change function interfaces. 1. Before the while loop, declare an array of doubles called creadings, with size SENSORS, and initialize the values to 0.0 2. In the while loop, pass the array name creadings to GhGetReadings, and then GhDisplay Readings

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!