/*Alarm check */
#include <sys/types.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <time.h>
/* Main program. */
int main(int argc, char **argv)
{
int fd;
FILE *log;
/* These TIOCM_* parameters are defined in <linux/termios.h>, which */
/* is indirectly included here. */
int set_bits;
int flags;
int sleep_time;
int pc;
time_t now;
char strtime[30];
if (argc != 2) {
printf("Usage: relays <device> \n");
exit(1);
}
/* Open monitor device. */
if ((fd = open(argv[1], O_RDWR | O_NDELAY)) < 0) {
fprintf(stderr, "port: %s: %s\n", argv[1], sys_errlist[errno]);
exit(1);}
/* Get the bits to set from the command line. */
sscanf(argv[2], "%x", &set_bits);
sscanf(argv[3], "%d", &sleep_time);
/* Set the command line specified bits (& only the command line */
/* specified bits). */
ioctl(fd, TIOCMSET, &set_bits);
sleep(1);
ioctl(fd, TIOCMGET, &flags);
time(&now);
printf("%d\t",now);
printf("%x\t", flags);
if (flags & 0x100) { printf ("on\t"); } else { printf ("off\t"); }
if (flags & 0x80) { printf ("on\t"); } else { printf ("off\t"); }
if (flags & 0x40) { printf ("on\t"); } else { printf ("off\t"); }
if (flags & 0x20) { printf ("on\t"); } else { printf ("off\t"); }
printf("%s",ctime(&now));
close(fd);
}