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; }

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter13: Structures
Section13.1: Single Structures
Problem 4E
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
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning