C program: fill out TODO'S IN THE PROGRAM   #include // EXIT_ codes #include // bool #include // printf, scanf #include // strlen, strcmp #include // poll #include // usleep #include "sysfs_gpio.h" // custom virtual file system gpio library #include "udp.h" // custom udp library #define SERVER_LISTENER_PORT 4096 #define DOOR 17 #define MOTION 27 #define TIMEOUT_SECONDS 25 bool isAnyKeyPressed() { struct pollfd pfd; pfd.fd = 1; pfd.events = POLLIN; poll(&pfd, 1, 1); return pfd.revents == POLLIN; } //----------------------------------------------------------------------------- // Main //----------------------------------------------------------------------------- int main(int argc, char* argv[]) { char *remoteIp; int remotePort; bool armed = false; bool quit = false; int timeout = TIMEOUT_SECONDS; // Verify arguments are good bool goodArguments = (argc == 2); if (goodArguments) remoteIp = argv[1]; if (!goodArguments) { printf("usage: alarm IPV4_ADDRESS\n"); printf(" where:\n"); printf(" IPV4_ADDRESS is address of the remote machine\n");               exit(EXIT_FAILURE); } // Set remote port remotePort = SERVER_LISTENER_PORT; // Setup pins as inputs // TODO: Add code to configure the door button // and motion sensor pins are inputs // Send disarmed message sendUdpMessage(remoteIp, remotePort, "disarmed"); // Loop until 'q' is pressed on keyboard while (!quit) { // TODO: Add code to read the door and motion inputs // and send messages and display on screen // If key pressed on keyboard, get key and process // If 'a', arm system // If 'd', disarm system // If 'q', quit if (isAnyKeyPressed()) { char c = fgetc(stdin); switch(c) { // TODO: Add code to look for q input and exit loop // TODO: Add code to look for a or d and handle arm/disarm } } if (!quit) { // Sleep for 1 second usleep(1000000); // TODO: Add to code decrement the timeout by one // TODO: When the timeout reaches zero: // - send a pulse message to keep connection alive // - reload the timeout variable with TIMEOUT_SECONDS } } return EXIT_SUCCESS; }

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

C program:

fill out TODO'S IN THE PROGRAM

 


#include <stdlib.h> // EXIT_ codes
#include <stdbool.h> // bool
#include <stdio.h> // printf, scanf
#include <string.h> // strlen, strcmp
#include <poll.h> // poll
#include <unistd.h> // usleep
#include "sysfs_gpio.h" // custom virtual file system gpio library
#include "udp.h" // custom udp library
#define SERVER_LISTENER_PORT 4096
#define DOOR 17
#define MOTION 27
#define TIMEOUT_SECONDS 25
bool isAnyKeyPressed()
{
struct pollfd pfd;
pfd.fd = 1;
pfd.events = POLLIN;
poll(&pfd, 1, 1);
return pfd.revents == POLLIN;
}
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
int main(int argc, char* argv[])
{
char *remoteIp;
int remotePort;
bool armed = false;
bool quit = false;
int timeout = TIMEOUT_SECONDS;
// Verify arguments are good
bool goodArguments = (argc == 2);
if (goodArguments)
remoteIp = argv[1];
if (!goodArguments)
{
printf("usage: alarm IPV4_ADDRESS\n");
printf(" where:\n");
printf(" IPV4_ADDRESS is address of the remote machine\n");
 
 
 
 
 
 
 
exit(EXIT_FAILURE);
}
// Set remote port
remotePort = SERVER_LISTENER_PORT;
// Setup pins as inputs
// TODO: Add code to configure the door button
// and motion sensor pins are inputs
// Send disarmed message
sendUdpMessage(remoteIp, remotePort, "disarmed");
// Loop until 'q' is pressed on keyboard
while (!quit)
{
// TODO: Add code to read the door and motion inputs
// and send messages and display on screen

// If key pressed on keyboard, get key and process
// If 'a', arm system
// If 'd', disarm system
// If 'q', quit
if (isAnyKeyPressed())
{
char c = fgetc(stdin);
switch(c)
{
// TODO: Add code to look for q input and exit loop
// TODO: Add code to look for a or d and handle arm/disarm
}
}
if (!quit)
{
// Sleep for 1 second
usleep(1000000);

// TODO: Add to code decrement the timeout by one
// TODO: When the timeout reaches zero:
// - send a pulse message to keep connection alive
// - reload the timeout variable with TIMEOUT_SECONDS
}
}
return EXIT_SUCCESS;
}
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Function Arguments
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
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