/* James Nobis UPSD monitoring program for apc ups' GPL'ed */ #include #include #include #include #include #include #include int main() { int serial,i,outage; char c; struct termios old_flags, new_flags; outage=0; daemon(0,0); serial = open ("/dev/ttyS0",O_RDONLY); if (serial==-1) exit(0); tcgetattr(serial,&old_flags); new_flags = old_flags; new_flags.c_lflag &= ~(ECHO | ICANON | ISIG); new_flags.c_iflag &= ~(BRKINT | ICRNL); new_flags.c_oflag &= ~OPOST; new_flags.c_cc[VTIME] = 0; new_flags.c_cc[VMIN] = 1; if (tcsetattr(serial, TCSAFLUSH, &new_flags) < 0) printf("woops\n"); while ((i = read(serial, &c, 1) == 1)) { if ((c &= 255) == 33) { if (outage==2) { system("echo \"Uaho!\" | mail -s 'power outage!' 9999999999@messaging.sprintpcs.com"); } outage++; } if ((c & 255) == 36) outage=0; } close(serial); }