Written by Dana Kirsch and Solomon Assefa #include #include #include #include #include #include #include #include #include #include #include #include /* declarations */ void hash(int); char msg[256]; int OpenPort() { struct termios t; int fd= open("/dev/cua1", O_RDWR); if (fd < 0) { perror("opening com1 port"); } else { tcgetattr(fd, &t); cfsetispeed(&t, B2400); cfsetospeed(&t, B2400); cfmakeraw(&t); tcsetattr(fd, TCSANOW, &t); } return(fd); } void main() { int port; int last=0; int sum; // time_t time; char firstbyte, secondbyte, fourthbyte; char thirdbyte; port = OpenPort(); while (1) { /* firstbyte is the floor, secondbyte is the room number, thirdbyte is the * ASCII representation of the room letter designation, fourthbyte is * the message for the hash table. */ getid(port, &firstbyte, &secondbyte, &thirdbyte, &fourthbyte); /* NEED A BETTER ERROR CHECKING MEATHOD !!!!!!!!!!! */ sum = (firstbyte + secondbyte + thirdbyte + fourthbyte); /* if the signal changes, room number or message, then write (to the * history file) the date, time, place, and message. */ if (sum != last) { // printf("%s\n", ctime(time(NULL)) ); hash(fourthbyte); printf("Room: %d%d%c - %s \n", firstbyte, secondbyte, thirdbyte, msg); } last = sum; fflush(stdout); } } int getid(int port, char *fst, char *snd, char *thd, char *fth) { char buffer[4]; char i; read(port, buffer, 4); *fst = buffer[0]; *snd = buffer[1]; *thd = buffer[2]; *fth = buffer[3]; return 0; } void hash(int num) { switch (num) { case 0: sprintf(msg, "Want to leave a message?"); break; case 2: sprintf(msg, "I have a demo in the afternoon -- Thad"); break; case 3: sprintf(msg, "You had a call. Call her back when you get in"); break; case 4: sprintf(msg, "Come to my office, please -- Prof. Sandy"); break; case 5: sprintf(msg,"Gone for the day. -- Thad"); break; case 6: sprintf(msg,"Solo has gone for some cocoa"); break; case 7: sprintf(msg,"Please make sure the lights are off when you leave!"); break; case 8: sprintf(msg, "I have a meeting now. I will be back in an hour"); break; case 9: sprintf(msg, "Please do not disturb. Door is locked from inside."); break; default: sprintf(msg,"No messages"); break; } }