/*****************************************************************************/ /*** (Final Year Project Bluetooth-Infrared Converter) bic_michael.c ***/ /*** Michael Cheung Ka Kin***/ /*****************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include char filename[500] = { 0 }; char logfile[256] = { 0 }; char alarmhandler[256] = { 0 }; int alarmlevel = LOG_WARNING; int loglevel = 9; int ret_code; char tmp[100]; char command[1024];//used for AT command only for creating menu char buffer[1024];//used for AT command only when the number of choice1 is dynamic char answer[1024];//used for the command for the Linux PC char type[3]; char remote[20]; char *target, *user, *password; MYSQL mysql; MYSQL_RES *result; MYSQL_ROW row; void TVcontrol(char remote[]); void CDcontrol(char remote[]); void VCDcontrol(char remote[]); void DVDcontrol(char remote[]); void VCRcontrol(char remote[]); void projectorcontrol(char remote[]); void devicecontrol(MYSQL *, char [], char []); void parsearguments1() { strcpy (device, "/dev/null"); baudrate = 115200; errorsleeptime = 10; rtscts = 0; strcpy (modemname, device); } void parsearguments () { strcpy (device, "/dev/rfcomm0"); baudrate = 115200; errorsleeptime = 10; rtscts = 0; strcpy (modemname, device); } void flush (char *fl,int len) { int m; for (m=0;m=10) && (atoi(outputint)<=99)) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s 10+", remote); //system(instruct); sprintf(instruct, "/usr/local/irtrans/irclient localhost %s %d", remote, atoi(outputint)/10); //system(instruct); sprintf(instruct, "/usr/local/irtrans/irclient localhost %s %d", remote, atoi(outputint)%10); //system(instruct); printf("\nThe user has chosen channel %s \n", outputint); channel_count++; if (channel_count==2) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s 10+", remote); //system(instruct); channel_count=0; } goto TV; } else if ((atoi(outputint)>=0) && (atoi(outputint)<=9)) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s %s", remote, outputint); //system(instruct); printf("\nThe user has chosen channel %s \n", outputint); goto TV; } break; case 3: printf("The user has entered volume mode\n"); vol: sprintf (command, "AT*EASM=\"Volume\",1,1,3,\"increase vol?\",\"decrease vol?\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (c=0; c<3; c++) ans_select[c]=0; while (!ans_select[0] && !ans_select[1] && !ans_select[2]) { ret_code = put_command ("", answer, sizeof (answer), 5, 0); ans_select[0]=(NULL!=strstr(answer, "*EAMI: 1")); ans_select[1]=(NULL!=strstr(answer, "*EAMI: 2")); ans_select[2]=(NULL!=strstr(answer, "*EAMI: 3")); } if (ans_select[2]) goto TV; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s upvol", remote); //system(instruct); printf("The user has increased volume \n"); } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s downvol", remote); //system(instruct); printf("The user has decreased volume \n"); } goto vol; } break; case 4: menu_count=0; sprintf(instruct, "/usr/local/irtrans/irclient localhost %s menu", remote); //system(instruct); printf("The user has entered menu mode \n"); menu: sprintf(command, "AT*EASM=\"Menu\",1,1,6,\"up\",\"down\",\"left\",\"right\",\"Menu\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (d=0; d<6; d++) ans_select[d]=0; choice1=1; while (choice1) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); for (e=0; e<6; e++) { sprintf (buffer, "*EAMI: %d", e+1); ans_select[e]=(NULL != strstr (answer, buffer)); if (ans_select[e]==1) { choice1=0; break; } } } if (ans_select[5]) break; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s upchannel", remote); //system(instruct); goto menu; } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s downchannel", remote); //system(instruct); goto menu; } else if (ans_select[2]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s downvol", remote); //system(instruct); goto menu; } else if (ans_select[3]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s upvol", remote); //system(instruct); goto menu; } else if (ans_select[4]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s menu", remote); //system(instruct); printf("The user has chosen an item in the menu \n"); menu_count++; if (menu_count==1) goto menu; else goto TV; } } break; case 5: sprintf(instruct, "/usr/local/irtrans/irclient localhost %s lang", remote); //system(instruct); printf("The user has changed language \n"); break; case 6: printf("The user has entered others mode \n"); Other: sprintf (command, "AT*EASM=\"Others\",1,1,4,\"Mode\",\"Silent\",\"Call\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (f=0; f<4; f++) ans_select[f]=0; while (!ans_select[0] && !ans_select[1] && !ans_select[2] && !ans_select[3]) { ret_code = put_command ("", answer, sizeof (answer), 5, 0); ans_select[0]=(NULL!=strstr(answer, "*EAMI: 1")); ans_select[1]=(NULL!=strstr(answer, "*EAMI: 2")); ans_select[2]=(NULL!=strstr(answer, "*EAMI: 3")); ans_select[3]=(NULL!=strstr(answer, "*EAMI: 4")); } if (ans_select[3]) break; else if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s mode", remote); //system(instruct); printf("The user has changed mode \n"); goto Other; } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s silent", remote); //system(instruct); printf("The user has chosen to let TV be silent \n"); goto Other; } else if (ans_select[2]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s call", remote); //system(instruct); printf("The user has done call function \n"); goto Other; } break; default: break; } goto TV; } } void CDcontrol(char remote[]) { char instruct[1024]; int item_choice1=0; int ans_select[100]; int con; int win; int a,b,c,d,e,f,g,h,i; int choice1; int choice2; int menu_count; //int chapter_count=0; printf("The user has entered CD mode \n"); CD: sprintf (command, "AT*EASM=\"CD\",1,1,6,\"Power\",\"Chapter\",\"Play\",\"Volume\",\"Menu\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (a=0; a<6; a++) ans_select[a]=0; choice1=1; while (choice1) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); for (b=0; b<6; b++) { sprintf (buffer, "*EAMI: %d", b+1); ans_select[b] = (NULL != strstr (answer, buffer)); if (ans_select[b]==1) { choice1=0; con=b+1; break; } } } if (ans_select[5]) { printf("The user has quitted CD mode\n"); return; } else { switch (con) { case 1: sprintf(instruct, "/usr/local/irtrans/irclient localhost %s power", remote); /*system(instruct); if (!system(instruct)) printf("The user has turned on/off the CD player \n"); else printf("Error on turning on/off CD player! Please check if the CD player's power is in standby mode \n");*/ break; case 2: printf("The user has entered the chapter choice mode \n"); sprintf (command, "AT*EAID=7,1,\"Chapter\",\"Chapter?\",0,99,\r"); ret_code = put_command (command, answer, sizeof (answer), 7, 0); win=0; char *location=NULL; while (!win) { ret_code = put_command ("", answer, sizeof (answer), 5,0); location = strstr(answer, "*EAII: 7,"); win = (NULL != strstr (answer, "*EAII: 7,")); } char outputint[3]; flush (outputint,3); outputint[0]=answer[location-answer+9]; outputint[1]=answer[location-answer+10]; outputint[2]='\0'; if ((atoi(outputint)>=10) && (atoi(outputint)<=99)) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s 10+", remote); //system(instruct); sprintf(instruct, "/usr/local/irtrans/irclient localhost %s %d", remote, atoi(outputint)/10); //system(instruct); sprintf(instruct, "/usr/local/irtrans/irclient localhost %s %d", remote, atoi(outputint)%10); //system(instruct); printf("The user has chosen chapter %s \n", outputint); goto CD; } else if ((atoi(outputint)>=0) && (atoi(outputint)<=9)) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s %s", remote, outputint); //system(instruct); printf("The user has chosen chapter %s \n", outputint); goto CD; } break; case 3: printf("The user has entered play mode \n"); play: sprintf (command, "AT*EASM=\"Play\",1,1,3,\"Play by key?\",\"Play by menu?\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (a=0; a<3; a++) ans_select[a]=0; while (!ans_select[0] && !ans_select[1] && !ans_select[2]) { ret_code = put_command ("", answer, sizeof (answer), 5, 0); ans_select[0]=(NULL!=strstr(answer, "*EAMI: 1")); ans_select[1]=(NULL!=strstr(answer, "*EAMI: 2")); ans_select[2]=(NULL!=strstr(answer, "*EAMI: 3")); } if (ans_select[2]) goto CD; else if (ans_select[0]) { play_key: sprintf (command, "AT*EASM=\"Play\",1,1,10,\"Play\",\"Stop\",\"Pause/step\",\"Fast backward?\",\"Fast forward?\",\"Last chapter?\",\"Next chapter?\",\"Repeat?\",\"Eject?\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (b=0; b<10; b++) ans_select[b]=0; choice1=1; while (choice1) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); for (c=0; c<10; c++) { sprintf (buffer, "*EAMI: %d", c+1); ans_select[c]=(NULL != strstr (answer, buffer)); if (ans_select[c]==1) { choice1=0; break; } } } if (ans_select[9]) goto play; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s play", remote); //system(instruct); printf("The CD is playing \n"); goto play_key; } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s stop", remote); //system(instruct); printf("The CD is stopped \n"); goto play_key; } else if (ans_select[2]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s pause/step", remote); //system(instruct); printf("The CD is paused \n"); goto play_key; } else if (ans_select[3]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s fbw", remote); //system(instruct); printf("The CD is fast-backwarding \n"); goto play_key; } else if (ans_select[4]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s ffw", remote); //system(instruct); printf("The CD is fast-forwarding \n"); goto play_key; } else if (ans_select[5]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s last", remote); //system(instruct); printf("The CD is playing the previous chapter \n"); goto play_key; } else if (ans_select[6]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s next", remote); //system(instruct); printf("The CD is playing next chapter \n"); goto play_key; } else if (ans_select[7]) { Repeat: sprintf (command, "AT*EASM=\"Repeat\",1,1,3,\"A-B?\",\"1/All?\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (a=0; a<3; a++) ans_select[a]=0; while (!ans_select[0] && !ans_select[1] && !ans_select[2]) { ret_code = put_command ("", answer, sizeof (answer), 5, 0); ans_select[0]=(NULL!=strstr(answer, "*EAMI: 1")); ans_select[1]=(NULL!=strstr(answer, "*EAMI: 2")); ans_select[2]=(NULL!=strstr(answer, "*EAMI: 3")); } if (ans_select[2]) goto play_key; else if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s repeat1", remote); //system(instruct); printf("The CD is repeating in A-B mode \n"); goto Repeat; } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s repeat2", remote); //system(instruct); printf("The CD is displaying in 1/all mode \n"); goto Repeat; } } else if (ans_select[8]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s eject", remote); //system(instruct); printf("The CD is ejected out \n"); goto play_key; } } } else if (ans_select[1]) { printf("The user has entered play menu setting mode \n"); play_menu: sprintf (command, "AT*EASM=\"Play menu\",1,1,2,\"Set\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); ans_select[0]=0; ans_select[1]=0; while (!ans_select[0] && !ans_select[1]) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); ans_select[0]=(NULL!=strstr(answer, "*EAMI: 1")); ans_select[1]=(NULL!=strstr(answer, "*EAMI: 2")); } if (ans_select[1]) goto play; else { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s schedule", remote); //system(instruct); printf("The user is modifying the menu\n"); select: sprintf(command, "AT*EASM=\"Choice\",1,1,10,\"up\",\"down\",\"left\",\"right\",\"chapter\",\"enter\",\"clear\",\"next page\",\"last page\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (f=0; f<10; f++) ans_select[f]=0; choice1=1; while (choice1) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); for (g=0; g<10; g++) { sprintf (buffer, "*EAMI: %d", g+1); ans_select[g]=(NULL != strstr (answer, buffer)); if (ans_select[g]==1) { choice1=0; break; } } } if (ans_select[9]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s schedule", remote); //system(instruct); printf("The user has set the play menu \n"); goto play_menu; } else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s up", remote); //system(instruct); goto select; } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s down", remote); //system(instruct); goto select; } else if (ans_select[2]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s left", remote); //system(instruct); goto select; } else if (ans_select[3]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s right", remote); //system(instruct); goto select; } else if (ans_select[4]) { sprintf (command, "AT*EAID=7,1,\"Chapter\",\"Chapter?\",0,99,\r"); ret_code = put_command (command, answer, sizeof (answer), 7, 0); win=0; char *location=NULL; while (!win) { ret_code = put_command ("", answer, sizeof (answer), 5,0); location = strstr(answer, "*EAII: 7,"); win = (NULL != strstr (answer, "*EAII: 7,")); } char outputint[3]; flush (outputint,3); outputint[0]=answer[location-answer+9]; outputint[1]=answer[location-answer+10]; outputint[2]='\0'; if ((atoi(outputint)>=10) && (atoi(outputint)<=99)) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s 10+", remote); //system(instruct); sprintf(instruct, "/usr/local/irtrans/irclient localhost %s %d", remote, atoi(outputint)/10); //system(instruct); sprintf(instruct, "/usr/local/irtrans/irclient localhost %s %d", remote, atoi(outputint)%10); //system(instruct); printf("The user has chosen chapter %s \n", outputint); goto select; } else if ((atoi(outputint)>=0) && (atoi(outputint)<=9)) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s %s", remote, outputint); //system(instruct); printf("The user has chosen chapter %s \n", outputint); goto select; } } else if (ans_select[5]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s enter", remote); //system(instruct); printf("The user has entered a chapter in the play list \n"); goto play_menu; } else if (ans_select[6]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s clear", remote); //system(instruct); printf("The user has cleared an item \n"); goto play_menu; } else if (ans_select[7]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s ffw", remote); //system(instruct); printf("The list has been switched to next page \n"); goto play_menu; } else if (ans_select[8]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s fbw", remote); //system(instruct); printf("The list has been switched to previous page \n"); goto play_menu; } } } } break; case 4: printf("The user has entered volume mode \n"); vol: sprintf (command, "AT*EASM=\"Volume\",1,1,3,\"increase vol?\",\"decrease vol?\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (a=0; a<3; a++) ans_select[a]=0; while (!ans_select[0] && !ans_select[1] && !ans_select[2]) { ret_code = put_command ("", answer, sizeof (answer), 5, 0); ans_select[0]=(NULL!=strstr(answer, "*EAMI: 1")); ans_select[1]=(NULL!=strstr(answer, "*EAMI: 2")); ans_select[2]=(NULL!=strstr(answer, "*EAMI: 3")); } if (ans_select[2]) break; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s upvol", remote); //system(instruct); printf("The user has increased volume \n"); } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s downvol", remote); //system(instruct); printf("The user has decreased volume \n"); } goto vol; } break; case 5: sprintf(instruct, "/usr/local/irtrans/irclient localhost %s menu", remote); //system(instruct); printf("The user has entered menu setting mode \n"); menu: sprintf(command, "AT*EASM=\"Menu\",1,1,6,\"up\",\"down\",\"left\",\"right\",\"enter\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (d=0; d<6; d++) ans_select[d]=0; choice1=1; while (choice1) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); for (e=0; e<6; e++) { sprintf (buffer, "*EAMI: %d", e+1); ans_select[e]=(NULL != strstr (answer, buffer)); if (ans_select[e]==1) { choice1=0; break; } } } if (ans_select[5]) goto CD; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s upchannel", remote); //system(instruct); goto menu; } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s downchannel", remote); //system(instruct); goto menu; } else if (ans_select[2]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s downvol", remote); //system(instruct); goto menu; } else if (ans_select[3]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s upvol", remote); //system(instruct); goto menu; } else if (ans_select[4]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s enter", remote); //system(instruct); printf("The user has chosen an item\n"); goto CD; } } break; default: break; } goto CD; } } void VCDcontrol(char remote[]) { char instruct[1024]; int item_choice1=0; int ans_select[100]; int con; int win; int chapter1; int chapter2; int a,b,c,d,e,f,g,h,i; int choice1; int choice2; int menu_count; //int chapter_count=0; printf("The user has entered VCD mode\n"); VCD: sprintf (command, "AT*EASM=\"VCD\",1,1,8,\"Power\",\"Chapter\",\"Play\",\"Volume\",\"Menu\",\"Display\",\"Others\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (a=0; a<8; a++) ans_select[a]=0; choice1=1; while (choice1) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); for (b=0; b<8; b++) { sprintf (buffer, "*EAMI: %d", b+1); ans_select[b] = (NULL != strstr (answer, buffer)); if (ans_select[b]==1) { choice1=0; con=b+1; break; } } } if (ans_select[7]) { printf("The user has quitted from VCD mode \n"); return; } else { switch (con) { case 1: sprintf(instruct, "/usr/local/irtrans/irclient localhost %s power", remote); /*system(instruct); if (!system(instruct)) printf("The user has turned on/off the VCD player \n"); else printf("Error on turning on/off VCD player! Please check if the VCD player's power is in standby mode \n");*/ break; case 2: printf("The user has entered the chapter choice mode \n"); sprintf (command, "AT*EAID=7,1,\"Chapter\",\"Chapter?\",0,99,\r"); ret_code = put_command (command, answer, sizeof (answer), 7, 0); win=0; char *location=NULL; while (!win) { ret_code = put_command ("", answer, sizeof (answer), 5,0); location = strstr(answer, "*EAII: 7,"); win = (NULL != strstr (answer, "*EAII: 7,")); } char outputint[3]; flush (outputint,3); outputint[0]=answer[location-answer+9]; outputint[1]=answer[location-answer+10]; outputint[2]='\0'; if ((atoi(outputint)>=10) && (atoi(outputint)<=99)) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s 10+", remote); //system(instruct); sprintf(instruct, "/usr/local/irtrans/irclient localhost %s %d", remote, atoi(outputint)/10); //system(instruct); sprintf(instruct, "/usr/local/irtrans/irclient localhost %s %d", remote, atoi(outputint)%10); //system(instruct); printf("The user has chosen chapter %s \n", outputint); goto VCD; } else if ((atoi(outputint)>=0) && (atoi(outputint)<=9)) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s %s", remote, outputint); //system(instruct); printf("The user has chosen chapter %s \n", outputint); goto VCD; } break; case 3: printf("The user has entered play mode \n"); play: sprintf (command, "AT*EASM=\"Play\",1,1,3,\"Play by key?\",\"Play by menu?\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (a=0; a<3; a++) ans_select[a]=0; while (!ans_select[0] && !ans_select[1] && !ans_select[2]) { ret_code = put_command ("", answer, sizeof (answer), 5, 0); ans_select[0]=(NULL!=strstr(answer, "*EAMI: 1")); ans_select[1]=(NULL!=strstr(answer, "*EAMI: 2")); ans_select[2]=(NULL!=strstr(answer, "*EAMI: 3")); } if (ans_select[2]) goto VCD; else if (ans_select[0]) { play_key: sprintf (command, "AT*EASM=\"Play\",1,1,10,\"Play\",\"Stop\",\"Pause/step\",\"Fast backward?\",\"Fast forward?\",\"Last chapter?\",\"Next chapter?\",\"Repeat?\",\"Eject?\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (b=0; b<10; b++) ans_select[b]=0; choice1=1; while (choice1) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); for (c=0; c<10; c++) { sprintf (buffer, "*EAMI: %d", c+1); ans_select[c]=(NULL != strstr (answer, buffer)); if (ans_select[c]==1) { choice1=0; break; } } } if (ans_select[9]) goto play; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s play", remote); //system(instruct); printf("The VCD is playing \n"); goto play; } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s stop", remote); //system(instruct); printf("The VCD is stopped \n"); goto play; } else if (ans_select[2]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s pause/step", remote); //system(instruct); printf("The VCD is paused \n"); goto play; } else if (ans_select[3]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s fbw", remote); //system(instruct); printf("The VCD is fast-backwarding \n"); goto play; } else if (ans_select[4]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s ffw", remote); //system(instruct); printf("The VCD is fast-forwarding \n"); goto play; } else if (ans_select[5]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s last", remote); //system(instruct); printf("The VCD is playing the previous chapter \n"); goto play; } else if (ans_select[6]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s next", remote); //system(instruct); printf("The VCD is playing next chapter \n"); goto play; } else if (ans_select[7]) { Repeat: sprintf (command, "AT*EASM=\"Repeat\",1,1,3,\"A-B?\",\"1/All?\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (a=0; a<3; a++) ans_select[a]=0; while (!ans_select[0] && !ans_select[1] && !ans_select[2]) { ret_code = put_command ("", answer, sizeof (answer), 5, 0); ans_select[0]=(NULL!=strstr(answer, "*EAMI: 1")); ans_select[1]=(NULL!=strstr(answer, "*EAMI: 2")); ans_select[2]=(NULL!=strstr(answer, "*EAMI: 3")); } if (ans_select[2]) goto play; else if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s repeat1", remote); //system(instruct); printf("The VCD is repeating in A-B mode \n"); goto Repeat; } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s repeat2", remote); //system(instruct); printf("The VCD is displaying in 1/all mode \n"); goto Repeat; } } else if (ans_select[8]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s eject", remote); //system(instruct); printf("The VCD is ejected out \n"); goto play; } } } else if (ans_select[1]) { printf("The user has entered play menu setting mode \n"); play_menu: sprintf (command, "AT*EASM=\"Play menu\",1,1,2,\"Set\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); ans_select[0]=0; ans_select[1]=0; while (!ans_select[0] && !ans_select[1]) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); ans_select[0]=(NULL!=strstr(answer, "*EAMI: 1")); ans_select[1]=(NULL!=strstr(answer, "*EAMI: 2")); } if (ans_select[1]) goto play; else { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s schedule", remote); //system(instruct); printf("The user is modifying the menu\n"); select: sprintf(command, "AT*EASM=\"Choice\",1,1,10,\"up\",\"down\",\"left\",\"right\",\"chapter\",\"enter\",\"clear\",\"next page\",\"last page\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (f=0; f<10; f++) ans_select[f]=0; choice1=1; while (choice1) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); for (g=0; g<10; g++) { sprintf (buffer, "*EAMI: %d", g+1); ans_select[g]=(NULL != strstr (answer, buffer)); if (ans_select[g]==1) { choice1=0; break; } } } if (ans_select[9]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s schedule", remote); //system(instruct); printf("The user has set the play menu \n"); goto play_menu; } else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s up", remote); //system(instruct); goto select; } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s down", remote); //system(instruct); goto select; } else if (ans_select[2]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s left", remote); //system(instruct); goto select; } else if (ans_select[3]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s right", remote); //system(instruct); goto select; } else if (ans_select[4]) { sprintf (command, "AT*EAID=7,1,\"Chapter\",\"Chapter?\",0,99,\r"); ret_code = put_command (command, answer, sizeof (answer), 7, 0); win=0; char *location=NULL; while (!win) { ret_code = put_command ("", answer, sizeof (answer), 5,0); location = strstr(answer, "*EAII: 7,"); win = (NULL != strstr (answer, "*EAII: 7,")); } char outputint[3]; flush (outputint,3); outputint[0]=answer[location-answer+9]; outputint[1]=answer[location-answer+10]; outputint[2]='\0'; if ((atoi(outputint)>=10) && (atoi(outputint)<=99)) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s 10+", remote); //system(instruct); sprintf(instruct, "/usr/local/irtrans/irclient localhost %s %d", remote, atoi(outputint)/10); //system(instruct); sprintf(instruct, "/usr/local/irtrans/irclient localhost %s %d", remote, atoi(outputint)%10); //system(instruct); printf("The user has chosen chapter %s \n", outputint); goto select; } else if ((atoi(outputint)>=0) && (atoi(outputint)<=9)) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s %s", remote, outputint); //system(instruct); printf("The user has chosen chapter %s \n", outputint); goto select; } } else if (ans_select[5]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s enter", remote); //system(instruct); printf("The user has entered a chapter in the play list \n"); goto play_menu; } else if (ans_select[6]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s clear", remote); //system(instruct); printf("The user has cleared an item \n"); goto play_menu; } else if (ans_select[7]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s ffw", remote); //system(instruct); printf("The list has been switched to next page \n"); goto play_menu; } else if (ans_select[8]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s fbw", remote); //system(instruct); printf("The list has been switched to previous page \n"); goto play_menu; } } } } break; case 4: printf("The user has entered volume mode \n"); vol: sprintf (command, "AT*EASM=\"Volume\",1,1,3,\"increase vol?\",\"decrease vol?\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (a=0; a<3; a++) ans_select[a]=0; while (!ans_select[0] && !ans_select[1] && !ans_select[2]) { ret_code = put_command ("", answer, sizeof (answer), 5, 0); ans_select[0]=(NULL!=strstr(answer, "*EAMI: 1")); ans_select[1]=(NULL!=strstr(answer, "*EAMI: 2")); ans_select[2]=(NULL!=strstr(answer, "*EAMI: 3")); } if (ans_select[2]) goto VCD; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s upvol", remote); //system(instruct); printf("The user has increased volume \n"); } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s downvol", remote); //system(instruct); printf("The user has decreased volume \n"); } goto vol; } break; case 5: sprintf(instruct, "/usr/local/irtrans/irclient localhost %s menu", remote); //system(instruct); printf("The user has entered menu setting mode \n"); menu: sprintf(command, "AT*EASM=\"Menu\",1,1,6,\"up\",\"down\",\"left\",\"right\",\"enter\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (d=0; d<6; d++) ans_select[d]=0; choice1=1; while (choice1) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); for (e=0; e<6; e++) { sprintf (buffer, "*EAMI: %d", e+1); ans_select[e]=(NULL != strstr (answer, buffer)); if (ans_select[e]==1) { choice1=0; break; } } } if (ans_select[5]) goto VCD; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s upchannel", remote); //system(instruct); goto menu; } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s downchannel", remote); //system(instruct); goto menu; } else if (ans_select[2]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s downvol", remote); //system(instruct); goto menu; } else if (ans_select[3]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s upvol", remote); //system(instruct); goto menu; } else if (ans_select[4]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s enter", remote); //system(instruct); printf("The user has chosen an item\n"); goto VCD; } } break; case 6: printf("The user has entered display setting mode \n"); display: sprintf (command, "AT*EASM=\"Display\",1,1,9,\"Display?\",\"Zoom?\",\"Browse?\",\"Signal mode?\",\"Caption?\",\"Angle?\",\"Channel?\",\"Title?\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (a=0; a<9; a++) ans_select[a]=0; choice1=1; while (choice1) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); for (b=0; b<9; b++) { sprintf (buffer, "*EAMI: %d", b+1); ans_select[b] = (NULL != strstr (answer, buffer)); if (ans_select[b]==1) { choice1=0; con=b+1; break; } } } if (ans_select[8]) goto VCD; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s display", remote); //system(instruct); printf("The user has chosen a display format \n"); } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s zoom", remote); //system(instruct); printf("The user has chosen a zooming aspects \n"); } else if (ans_select[2]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s browse", remote); //system(instruct); printf("The user has chosen to browse \n"); } else if (ans_select[3]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s signal_mode", remote); //system(instruct); printf("The user has searched a signal mode\n"); } else if (ans_select[4]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s caption", remote); //system(instruct); printf("The user has chosen (not) to show caption\n"); } else if (ans_select[5]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s angle", remote); //system(instruct); printf("The user has chosen a display angle \n"); } else if (ans_select[6]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s channel", remote); //system(instruct); printf("The user has chosen a display channel \n"); } else if (ans_select[7]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s title", remote); //system(instruct); printf("The user has chosen to show a title \n"); } goto display; } break; case 7: printf("The user has entered others mode \n"); others: sprintf (command, "AT*EASM=\"Others\",1,1,3,\"Setup\",\"Silent\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (a=0; a<3; a++) ans_select[a]=0; while (!ans_select[0] && !ans_select[1] && !ans_select[2]) { ret_code = put_command ("", answer, sizeof (answer), 5, 0); ans_select[0]=(NULL!=strstr(answer, "*EAMI: 1")); ans_select[1]=(NULL!=strstr(answer, "*EAMI: 2")); ans_select[2]=(NULL!=strstr(answer, "*EAMI: 3")); } if (ans_select[2]) goto VCD; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s setup", remote); //system(instruct); printf("The user has entered setup menu \n"); setup: sprintf(command, "AT*EASM=\"Setup\",1,1,6,\"up\",\"down\",\"left\",\"right\",\"enter\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (d=0; d<6; d++) ans_select[d]=0; choice1=1; while (choice1) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); for (e=0; e<6; e++) { sprintf (buffer, "*EAMI: %d", e+1); ans_select[e]=(NULL != strstr (answer, buffer)); if (ans_select[e]==1) { choice1=0; break; } } } if (ans_select[5]) goto others; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s upchannel", remote); //system(instruct); goto setup; } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s downchannel", remote); //system(instruct); goto setup; } else if (ans_select[2]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s downvol", remote); //system(instruct); goto setup; } else if (ans_select[3]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s upvol", remote); //system(instruct); goto setup; } else if (ans_select[4]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s enter", remote); //system(instruct); printf("The user has chosen an item\n"); goto others; } } } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s silent", remote); //system(instruct); printf("The user has made the VCD player silently \n"); } goto others; } break; default: break; } goto VCD; } } void DVDcontrol(char remote[]) { char instruct[1024]; int item_choice1=0; int ans_select[100]; int con; int win; int chapter1; int chapter2; int a,b,c,d,e,f,g,h,i; int choice1; int choice2; int menu_count; //int chapter_count=0; printf("The user has entered DVD mode \n"); DVD: sprintf (command, "AT*EASM=\"DVD\",1,1,8,\"Power\",\"Chapter\",\"Play\",\"Volume\",\"Menu\",\"Display\",\"Others\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (a=0; a<8; a++) ans_select[a]=0; choice1=1; while (choice1) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); for (b=0; b<8; b++) { sprintf (buffer, "*EAMI: %d", b+1); ans_select[b] = (NULL != strstr (answer, buffer)); if (ans_select[b]==1) { choice1=0; con=b+1; break; } } } if (ans_select[7]) { printf("The user has quitted from DVD mode \n"); return; } else { switch (con) { case 1: sprintf(instruct, "/usr/local/irtrans/irclient localhost %s power", remote); /*system(instruct); if (!system(instruct)) printf("The user has turned on/off the DVD player \n"); else printf("Error on turning on/off DVD player! Please check if the DVD player's power is in standby mode \n");*/ break; case 2: printf("The user has entered the chapter choice mode \n"); sprintf (command, "AT*EAID=7,1,\"Chapter\",\"Chapter?\",0,99,\r"); ret_code = put_command (command, answer, sizeof (answer), 7, 0); win=0; char *location=NULL; while (!win) { ret_code = put_command ("", answer, sizeof (answer), 5,0); location = strstr(answer, "*EAII: 7,"); win = (NULL != strstr (answer, "*EAII: 7,")); } char outputint[3]; flush (outputint,3); outputint[0]=answer[location-answer+9]; outputint[1]=answer[location-answer+10]; outputint[2]='\0'; if ((atoi(outputint)>=10) && (atoi(outputint)<=99)) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s 10+", remote); //system(instruct); sprintf(instruct, "/usr/local/irtrans/irclient localhost %s %d", remote, atoi(outputint)/10); //system(instruct); sprintf(instruct, "/usr/local/irtrans/irclient localhost %s %d", remote, atoi(outputint)%10); //system(instruct); printf("The user has chosen chapter %s \n", outputint); goto DVD; } else if ((atoi(outputint)>=0) && (atoi(outputint)<=9)) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s %s", remote, outputint); //system(instruct); printf("The user has chosen chapter %s \n", outputint); goto DVD; } break; case 3: printf("The user has entered play mode \n"); play: sprintf (command, "AT*EASM=\"Play\",1,1,3,\"Play by key?\",\"Play by menu?\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (a=0; a<3; a++) ans_select[a]=0; while (!ans_select[0] && !ans_select[1] && !ans_select[2]) { ret_code = put_command ("", answer, sizeof (answer), 5, 0); ans_select[0]=(NULL!=strstr(answer, "*EAMI: 1")); ans_select[1]=(NULL!=strstr(answer, "*EAMI: 2")); ans_select[2]=(NULL!=strstr(answer, "*EAMI: 3")); } if (ans_select[2]) goto DVD; else if (ans_select[0]) { play_key: sprintf (command, "AT*EASM=\"Play\",1,1,10,\"Play\",\"Stop\",\"Pause/step\",\"Fast backward?\",\"Fast forward?\",\"Last chapter?\",\"Next chapter?\",\"Repeat?\",\"Eject?\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (b=0; b<10; b++) ans_select[b]=0; choice1=1; while (choice1) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); for (c=0; c<10; c++) { sprintf (buffer, "*EAMI: %d", c+1); ans_select[c]=(NULL != strstr (answer, buffer)); if (ans_select[c]==1) { choice1=0; break; } } } if (ans_select[9]) goto play; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s play", remote); //system(instruct); printf("The DVD is playing \n"); goto play; } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s stop", remote); //system(instruct); printf("The DVD is stopped \n"); goto play; } else if (ans_select[2]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s pause/step", remote); //system(instruct); printf("The DVD is paused \n"); goto play; } else if (ans_select[3]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s fbw", remote); //system(instruct); printf("The DVD is fast-backwarding \n"); goto play; } else if (ans_select[4]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s ffw", remote); //system(instruct); printf("The DVD is fast-forwarding \n"); goto play; } else if (ans_select[5]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s last", remote); //system(instruct); printf("The DVD is playing the previous chapter \n"); goto play; } else if (ans_select[6]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s next", remote); //system(instruct); printf("The DVD is playing next chapter \n"); goto play; } else if (ans_select[7]) { Repeat: sprintf (command, "AT*EASM=\"Repeat\",1,1,3,\"A-B?\",\"1/All?\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (a=0; a<3; a++) ans_select[a]=0; while (!ans_select[0] && !ans_select[1] && !ans_select[2]) { ret_code = put_command ("", answer, sizeof (answer), 5, 0); ans_select[0]=(NULL!=strstr(answer, "*EAMI: 1")); ans_select[1]=(NULL!=strstr(answer, "*EAMI: 2")); ans_select[2]=(NULL!=strstr(answer, "*EAMI: 3")); } if (ans_select[2]) goto play; else if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s repeat1", remote); //system(instruct); printf("The DVD is repeating in A-B mode \n"); goto Repeat; } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s repeat2", remote); //system(instruct); printf("The DVD is displaying in 1/all mode \n"); goto Repeat; } } else if (ans_select[8]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s eject", remote); //system(instruct); printf("The DVD is ejected out \n"); goto play; } } } else if (ans_select[1]) { printf("The user has entered play menu setting mode \n"); play_menu: sprintf (command, "AT*EASM=\"Play menu\",1,1,2,\"Set\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); ans_select[0]=0; ans_select[1]=0; while (!ans_select[0] && !ans_select[1]) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); ans_select[0]=(NULL!=strstr(answer, "*EAMI: 1")); ans_select[1]=(NULL!=strstr(answer, "*EAMI: 2")); } if (ans_select[1]) goto play; else { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s schedule", remote); //system(instruct); printf("The user is modifying the menu\n"); select: sprintf(command, "AT*EASM=\"Choice\",1,1,10,\"up\",\"down\",\"left\",\"right\",\"chapter\",\"enter\",\"clear\",\"next page\",\"last page\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (f=0; f<10; f++) ans_select[f]=0; choice1=1; while (choice1) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); for (g=0; g<10; g++) { sprintf (buffer, "*EAMI: %d", g+1); ans_select[g]=(NULL != strstr (answer, buffer)); if (ans_select[g]==1) { choice1=0; break; } } } if (ans_select[9]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s schedule", remote); //system(instruct); printf("The user has set the play menu \n"); goto play_menu; } else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s up", remote); //system(instruct); goto select; } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s down", remote); //system(instruct); goto select; } else if (ans_select[2]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s left", remote); //system(instruct); goto select; } else if (ans_select[3]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s right", remote); //system(instruct); goto select; } else if (ans_select[4]) { sprintf (command, "AT*EAID=7,1,\"Chapter\",\"Chapter?\",0,99,\r"); ret_code = put_command (command, answer, sizeof (answer), 7, 0); win=0; char *location=NULL; while (!win) { ret_code = put_command ("", answer, sizeof (answer), 5,0); location = strstr(answer, "*EAII: 7,"); win = (NULL != strstr (answer, "*EAII: 7,")); } char outputint[3]; flush (outputint,3); outputint[0]=answer[location-answer+9]; outputint[1]=answer[location-answer+10]; outputint[2]='\0'; if ((atoi(outputint)>=10) && (atoi(outputint)<=99)) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s 10+", remote); //system(instruct); sprintf(instruct, "/usr/local/irtrans/irclient localhost %s %d", remote, atoi(outputint)/10); //system(instruct); sprintf(instruct, "/usr/local/irtrans/irclient localhost %s %d", remote, atoi(outputint)%10); //system(instruct); printf("The user has chosen chapter %s \n", outputint); goto select; } else if ((atoi(outputint)>=0) && (atoi(outputint)<=9)) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s %s", remote, outputint); //system(instruct); printf("The user has chosen chapter %s \n", outputint); goto select; } } else if (ans_select[5]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s enter", remote); //system(instruct); printf("The user has entered a chapter in the play list \n"); goto play_menu; } else if (ans_select[6]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s clear", remote); //system(instruct); printf("The user has cleared an item \n"); goto play_menu; } else if (ans_select[7]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s ffw", remote); //system(instruct); printf("The list has been switched to next page \n"); goto play_menu; } else if (ans_select[8]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s fbw", remote); //system(instruct); printf("The list has been switched to previous page \n"); goto play_menu; } } } } break; case 4: printf("The user has entered volume mode \n"); vol: sprintf (command, "AT*EASM=\"Volume\",1,1,3,\"increase vol?\",\"decrease vol?\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (a=0; a<3; a++) ans_select[a]=0; while (!ans_select[0] && !ans_select[1] && !ans_select[2]) { ret_code = put_command ("", answer, sizeof (answer), 5, 0); ans_select[0]=(NULL!=strstr(answer, "*EAMI: 1")); ans_select[1]=(NULL!=strstr(answer, "*EAMI: 2")); ans_select[2]=(NULL!=strstr(answer, "*EAMI: 3")); } if (ans_select[2]) goto DVD; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s upvol", remote); //system(instruct); printf("The user has increased volume \n"); } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s downvol", remote); //system(instruct); printf("The user has decreased volume \n"); } goto vol; } break; case 5: sprintf(instruct, "/usr/local/irtrans/irclient localhost %s menu", remote); //system(instruct); printf("The user has entered menu setting mode \n"); menu: sprintf(command, "AT*EASM=\"Menu\",1,1,6,\"up\",\"down\",\"left\",\"right\",\"enter\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (d=0; d<6; d++) ans_select[d]=0; choice1=1; while (choice1) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); for (e=0; e<6; e++) { sprintf (buffer, "*EAMI: %d", e+1); ans_select[e]=(NULL != strstr (answer, buffer)); if (ans_select[e]==1) { choice1=0; break; } } } if (ans_select[5]) goto DVD; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s upchannel", remote); //system(instruct); goto menu; } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s downchannel", remote); //system(instruct); goto menu; } else if (ans_select[2]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s downvol", remote); //system(instruct); goto menu; } else if (ans_select[3]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s upvol", remote); //system(instruct); goto menu; } else if (ans_select[4]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s enter", remote); //system(instruct); printf("The user has chosen an item\n"); goto DVD; } } break; case 6: printf("The user has entered display setting mode \n"); display: sprintf (command, "AT*EASM=\"Display\",1,1,9,\"Display?\",\"Zoom?\",\"Browse?\",\"Signal mode?\",\"Caption?\",\"Angle?\",\"Channel?\",\"Title?\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (a=0; a<9; a++) ans_select[a]=0; choice1=1; while (choice1) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); for (b=0; b<9; b++) { sprintf (buffer, "*EAMI: %d", b+1); ans_select[b] = (NULL != strstr (answer, buffer)); if (ans_select[b]==1) { choice1=0; con=b+1; break; } } } if (ans_select[8]) goto DVD; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s display", remote); //system(instruct); printf("The user has chosen a display format \n"); } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s zoom", remote); //system(instruct); printf("The user has chosen a zooming aspects \n"); } else if (ans_select[2]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s browse", remote); //system(instruct); printf("The user has chosen to browse \n"); } else if (ans_select[3]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s signal_mode", remote); //system(instruct); printf("The user has searched a signal mode\n"); } else if (ans_select[4]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s caption", remote); //system(instruct); printf("The user has chosen (not) to show caption\n"); } else if (ans_select[5]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s angle", remote); //system(instruct); printf("The user has chosen a display angle \n"); } else if (ans_select[6]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s channel", remote); //system(instruct); printf("The user has chosen a display channel \n"); } else if (ans_select[7]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s title", remote); //system(instruct); printf("The user has chosen to show a title \n"); } goto display; } break; case 7: printf("The user has entered others mode \n"); others: sprintf (command, "AT*EASM=\"Others\",1,1,3,\"Setup\",\"Silent\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (a=0; a<3; a++) ans_select[a]=0; while (!ans_select[0] && !ans_select[1] && !ans_select[2]) { ret_code = put_command ("", answer, sizeof (answer), 5, 0); ans_select[0]=(NULL!=strstr(answer, "*EAMI: 1")); ans_select[1]=(NULL!=strstr(answer, "*EAMI: 2")); ans_select[2]=(NULL!=strstr(answer, "*EAMI: 3")); } if (ans_select[2]) goto DVD; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s setup", remote); //system(instruct); printf("The user has entered setup menu \n"); setup: sprintf(command, "AT*EASM=\"Setup\",1,1,6,\"up\",\"down\",\"left\",\"right\",\"enter\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (d=0; d<6; d++) ans_select[d]=0; choice1=1; while (choice1) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); for (e=0; e<6; e++) { sprintf (buffer, "*EAMI: %d", e+1); ans_select[e]=(NULL != strstr (answer, buffer)); if (ans_select[e]==1) { choice1=0; break; } } } if (ans_select[5]) goto others; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s upchannel", remote); //system(instruct); goto setup; } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s downchannel", remote); //system(instruct); goto setup; } else if (ans_select[2]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s downvol", remote); //system(instruct); goto setup; } else if (ans_select[3]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s upvol", remote); //system(instruct); goto setup; } else if (ans_select[4]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s enter", remote); //system(instruct); printf("The user has chosen an item\n"); goto others; } } } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s silent", remote); //system(instruct); printf("The user has made the DVD player silently \n"); } goto others; } break; default: break; } goto DVD; } } void VCRcontrol(char remote[]) { char instruct[1024]; int item_choice1=0; int ans_select[100]; int con; int win; int a,b,c,d,e,f,g,h,i; int choice1; int choice2; int menu_count; //int chapter_count=0; printf("The user has entered VCR mode \n"); VCR: sprintf (command, "AT*EASM=\"VCR\",1,1,6,\"Power\",\"Channel\",\"Play\",\"Recording\",\"Others\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (a=0; a<6; a++) ans_select[a]=0; choice1=1; while (choice1) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); for (b=0; b<6; b++) { sprintf (buffer, "*EAMI: %d", b+1); ans_select[b] = (NULL != strstr (answer, buffer)); if (ans_select[b]==1) { choice1=0; con=b+1; break; } } } if (ans_select[5]) { printf("The user has quitted from VCR mode \n"); return; } else { switch (con) { case 1: sprintf(instruct, "/usr/local/irtrans/irclient localhost %s power", remote); /*system(instruct); if (!system(instruct)) printf("The user has turned on/off the VCR \n"); else printf("Error on turning on/off VCR! Please check if the VCR's power is in standby mode \n");*/ break; case 2: printf("The user wishes to change recording channel\n"); channel_choice1: sprintf (command, "AT*EASM=\"Channel\",1,1,3,\"Change by key?\",\"Change by no.?\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (a=0; a<3; a++) ans_select[a]=0; while (!ans_select[0] && !ans_select[1] && !ans_select[2]) { ret_code = put_command ("", answer, sizeof (answer), 5, 0); ans_select[0]=(NULL!=strstr(answer, "*EAMI: 1")); ans_select[1]=(NULL!=strstr(answer, "*EAMI: 2")); ans_select[2]=(NULL!=strstr(answer, "*EAMI: 3")); } if (ans_select[2]) goto VCR; else if (ans_select[0]) { channel_choice2: sprintf (command, "AT*EASM=\"Volume\",1,1,3,\"up channel?\",\"down channel?\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (a=0; a<3; a++) ans_select[a]=0; while (!ans_select[0] && !ans_select[1] && !ans_select[2]) { ret_code = put_command ("", answer, sizeof (answer), 5, 0); ans_select[0]=(NULL!=strstr(answer, "*EAMI: 1")); ans_select[1]=(NULL!=strstr(answer, "*EAMI: 2")); ans_select[2]=(NULL!=strstr(answer, "*EAMI: 3")); } if (ans_select[2]) goto channel_choice1; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s upchannel", remote); //system(instruct); } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s downchannel", remote); //system(instruct); } goto channel_choice2; } } else if (ans_select[1]) { sprintf (command, "AT*EAID=7,1,\"Channel\",\"Channel?\",0,99,\r"); ret_code = put_command (command, answer, sizeof (answer), 7, 0); win=0; char *location=NULL; while (!win) { ret_code = put_command ("", answer, sizeof (answer), 5,0); location = strstr(answer, "*EAII: 7,"); win = (NULL != strstr (answer, "*EAII: 7,")); } char outputint[3]; flush (outputint,3); outputint[0]=answer[location-answer+9]; outputint[1]=answer[location-answer+10]; outputint[2]='\0'; if ((atoi(outputint)>=10) && (atoi(outputint)<=99)) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s 10+", remote); //system(instruct); sprintf(instruct, "/usr/local/irtrans/irclient localhost %s %d", remote, atoi(outputint)/10); //system(instruct); sprintf(instruct, "/usr/local/irtrans/irclient localhost %s %d", remote, atoi(outputint)%10); //system(instruct); printf("The user has chosen channel %s \n", outputint); goto VCR; } else if ((atoi(outputint)>=0) && (atoi(outputint)<=9)) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s %s", remote, outputint); //system(instruct); printf("The user has chosen channel %s \n", outputint); goto VCR; } } break; case 3: printf("The user has entered play mode \n"); play: sprintf (command, "AT*EASM=\"Play\",1,1,6,\"Play\",\"Stop/eject?\",\"Pause\",\"Fast backward?\",\"Fast forward?\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (b=0; b<6; b++) ans_select[b]=0; choice1=1; while (choice1) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); for (c=0; c<6; c++) { sprintf (buffer, "*EAMI: %d", c+1); ans_select[c]=(NULL != strstr (answer, buffer)); if (ans_select[c]==1) { choice1=0; break; } } } if (ans_select[5]) goto VCR; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s play", remote); //system(instruct); printf("The user has chosen to play \n"); } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s stop", remote); //system(instruct); printf("The user has chosen to stop \n"); } else if (ans_select[2]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s pause/step", remote); //system(instruct); printf("The user has chosen to pause/play in step \n"); } else if (ans_select[3]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s fbw", remote); //system(instruct); printf("The user has chosen to fast-backward \n"); } else if (ans_select[4]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s ffw", remote); //system(instruct); printf("The user has chosen to fast-forward \n"); } goto play; } break; case 4: printf("The user has entered recording mode\n"); record: sprintf (command, "AT*EASM=\"Recording\",1,1,3,\"By key?\",\"By setting time?\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (a=0; a<3; a++) ans_select[a]=0; while (!ans_select[0] && !ans_select[1] && !ans_select[2]) { ret_code = put_command ("", answer, sizeof (answer), 5, 0); ans_select[0]=(NULL!=strstr(answer, "*EAMI: 1")); ans_select[1]=(NULL!=strstr(answer, "*EAMI: 2")); ans_select[2]=(NULL!=strstr(answer, "*EAMI: 3")); } if (ans_select[2]) break; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s record", remote); //system(instruct); printf("The VCR is starting recording\n"); } else if (ans_select[1]) { printf("The user is setting the recording information\n"); record_set: sprintf (command, "AT*EASM=\"Record setting\",1,1,3,\"Channel\",\"Time\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (a=0; a<3; a++) ans_select[a]=0; while (!ans_select[0] && !ans_select[1] && !ans_select[2]) { ret_code = put_command ("", answer, sizeof (answer), 5, 0); ans_select[0]=(NULL!=strstr(answer, "*EAMI: 1")); ans_select[1]=(NULL!=strstr(answer, "*EAMI: 2")); ans_select[2]=(NULL!=strstr(answer, "*EAMI: 3")); } if (ans_select[2]) break; else if(ans_select[0]) { printf("The user is choosing channel for recording\n"); sprintf (command, "AT*EAID=7,1,\"Channel\",\"Channel?\",0,99,\r"); ret_code = put_command (command, answer, sizeof (answer), 7, 0); win=0; char *location=NULL; while (!win) { ret_code = put_command ("", answer, sizeof (answer), 5,0); location = strstr(answer, "*EAII: 7,"); win = (NULL != strstr (answer, "*EAII: 7,")); } char outputint[3]; flush (outputint,3); outputint[0]=answer[location-answer+9]; outputint[1]=answer[location-answer+10]; outputint[2]='\0'; if ((atoi(outputint)>=10) && (atoi(outputint)<=99)) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s 10+", remote); //system(instruct); sprintf(instruct, "/usr/local/irtrans/irclient localhost %s %d", remote, atoi(outputint)/10); //system(instruct); sprintf(instruct, "/usr/local/irtrans/irclient localhost %s %d", remote, atoi(outputint)%10); //system(instruct); printf("The user has chosen channel %s \n", outputint); goto record_set; } else if ((atoi(outputint)>=0) && (atoi(outputint)<=9)) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s %s", remote, outputint); //system(instruct); printf("The user has chosen channel %s \n", outputint); goto record_set; } } else if(ans_select[1]) { printf("The user is setting record time\n"); rec_time: while (1) { sprintf (command, "AT*EAID=9,1,\"Start Date\"\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); win=0; char *location=NULL; while (!win) { ret_code = put_command ("", answer, sizeof (answer), 5,0); location = strstr(answer, "*EAII: 9,"); win = (NULL != strstr (answer, "*EAII: 9,")); } char year[3]; flush (year,3); year[0]=answer[location-answer+10]; year[1]=answer[location-answer+11]; year[2]='\0'; char month[3]; flush (month,3); month[0]=answer[location-answer+13]; month[1]=answer[location-answer+14]; month[2]='\0'; char day[3]; flush (day,3); day[0]=answer[location-answer+16]; day[1]=answer[location-answer+17]; day[2]='\0'; printf ("%s\n",year); printf ("%s\n",month); printf ("%s\n",day); printf ("Start Date (yy/mm/dd): %s/%s/%s\n", year, month, day); win=0; location=NULL; sprintf (command, "AT*EAID=10,1,\"Start Time\"\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); while (!win) { ret_code = put_command ("", answer, sizeof (answer), 20, 0); location = strstr(answer, "*EAII: 10,"); win = (NULL != strstr (answer, "*EAII: 10,")); } printf("%s\n", answer); char hour[3]; flush (hour,3); //hour[0]=answer[location-answer+11]; //hour[1]=answer[location-answer+12]; hour[0]='1'; hour[1]=answer[location-answer+11]; hour[2]='\0'; char min[3]; flush (min,3); min[0]=answer[location-answer+13]; min[1]=answer[location-answer+14]; min[2]='\0'; printf ("%s\n", hour); printf ("%s\n", min); printf ("Start Time (hh:mm): %s:%s\n", hour, min); win=0; location=NULL; sprintf (command, "AT*EAID=9,1,\"End Date\"\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); while (!win) { ret_code = put_command ("", answer, sizeof (answer), 5, 0); location = strstr(answer, "*EAII: 9,"); win = (NULL != strstr (answer, "*EAII: 9,")); } char end_year[3]; flush (end_year,3); end_year[0]=answer[location-answer+10]; end_year[1]=answer[location-answer+11]; end_year[2]='\0'; char end_month[3]; flush (end_month,3); end_month[0]=answer[location-answer+13]; end_month[1]=answer[location-answer+14]; end_month[2]='\0'; char end_day[3]; flush (end_day,3); end_day[0]=answer[location-answer+16]; end_day[1]=answer[location-answer+17]; end_day[2]='\0'; printf("%s\n",end_year); printf("%s\n",end_month); printf("%s\n",end_day); printf("End Date (yy/mm/dd): %s/%s/%s\n", end_year, end_month, end_day); win=0; location=NULL; sprintf (command, "AT*EAID=10,1,\"End Time\"\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); while (!win) { ret_code = put_command ("", answer, sizeof (answer), 20, 0); location = strstr(answer, "*EAII: 10,"); win = (NULL != strstr (answer, "*EAII: 10,")); } printf("%s",answer); char end_hour[3]; flush (end_hour,3); end_hour[0]='1'; //end_hour[0]=answer[location-answer+11]; end_hour[1]=answer[location-answer+11]; end_hour[2]='\0'; char end_min[3]; flush (end_min,3); end_min[0]=answer[location-answer+13]; end_min[1]=answer[location-answer+14]; end_min[2]='\0'; printf("%s\n",end_hour); printf("%s\n",end_min); printf("End Time (hh:mm): %s:%s\n", end_hour, end_min); goto record_set; } } } } break; case 5: printf("The user enters other mode\n"); others: sprintf (command, "AT*EASM=\"Others\",1,1,3,\"Menu\",\"Guide\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (a=0; a<3; a++) ans_select[a]=0; while (!ans_select[0] && !ans_select[1] && !ans_select[2]) { ret_code = put_command ("", answer, sizeof (answer), 5, 0); ans_select[0]=(NULL!=strstr(answer, "*EAMI: 1")); ans_select[1]=(NULL!=strstr(answer, "*EAMI: 2")); ans_select[2]=(NULL!=strstr(answer, "*EAMI: 3")); } if (ans_select[2]) break; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s menu", remote); //system(instruct); printf("The user has entered menu setting mode\n"); vcr_menu: sprintf(command, "AT*EASM=\"Menu\",1,1,6,\"up\",\"down\",\"left\",\"right\",\"select\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (d=0; d<6; d++) ans_select[d]=0; choice1=1; while (choice1) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); for (e=0; e<6; e++) { sprintf (buffer, "*EAMI: %d", e+1); ans_select[e]=(NULL != strstr (answer, buffer)); if (ans_select[e]==1) { choice1=0; break; } } } if (ans_select[5]) goto others; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s upchannel", remote); //system(instruct); goto vcr_menu; } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s downchannel", remote); //system(instruct); goto vcr_menu; } else if (ans_select[2]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s downvol", remote); //system(instruct); goto vcr_menu; } else if (ans_select[3]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s upvol", remote); //system(instruct); goto vcr_menu; } else if (ans_select[4]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s select", remote); //system(instruct); printf("The user has selected an item in menu\n"); goto VCR; } } } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s guide", remote); //system(instruct); printf("The user has entered guide mode\n"); vcr_guide: sprintf(command, "AT*EASM=\"Menu\",1,1,6,\"up\",\"down\",\"left\",\"right\",\"select\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (d=0; d<6; d++) ans_select[d]=0; choice1=1; while (choice1) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); for (e=0; e<6; e++) { sprintf (buffer, "*EAMI: %d", e+1); ans_select[e]=(NULL != strstr (answer, buffer)); if (ans_select[e]==1) { choice1=0; break; } } } if (ans_select[5]) goto others; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s upchannel", remote); //system(instruct); goto vcr_guide; } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s downchannel", remote); //system(instruct); goto vcr_guide; } else if (ans_select[2]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s downvol", remote); //system(instruct); goto vcr_guide; } else if (ans_select[3]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s upvol", remote); //system(instruct); goto vcr_guide; } else if (ans_select[4]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s guide", remote); //system(instruct); goto VCR; } } } } break; default: break; } goto VCR; } } void projectorcontrol(char remote[]) { char instruct[1024]; int item_choice1=0; int ans_select[100]; int con; int a,b,c,d,e,f,g,h,i; int choice1; int choice2; int menu_count; //int chapter_count=0; printf("The user has entered projector mode \n"); projector: sprintf (command, "AT*EASM=\"Projector\",1,1,7,\"Power\",\"menu\",\"input\",\"Display\",\"volume\",\"others\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (a=0; a<7; a++) ans_select[a]=0; choice1=1; while (choice1) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); for (b=0; b<7; b++) { sprintf (buffer, "*EAMI: %d", b+1); ans_select[b] = (NULL != strstr (answer, buffer)); if (ans_select[b]==1) { choice1=0; con=b+1; break; } } } if (ans_select[6]) { printf("The user has quitted from projector mode \n"); return; } else { switch (con) { case 1: printf("The user has entered the power mode\n"); power: sprintf (command, "AT*EASM=\"Power\",1,1,3,\"Power\",\"Standby\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (c=0; c<3; c++) ans_select[c]=0; while (!ans_select[0] && !ans_select[1] && !ans_select[2]) { ret_code = put_command ("", answer, sizeof (answer), 5, 0); ans_select[0]=(NULL!=strstr(answer, "*EAMI: 1")); ans_select[1]=(NULL!=strstr(answer, "*EAMI: 2")); ans_select[2]=(NULL!=strstr(answer, "*EAMI: 3")); } if (ans_select[2]) break; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s power", remote); //system(instruct); if (!system(instruct)) printf("The user has turned on/off the projector \n"); else printf("Error on turning on/off projector!\n"); } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s standby", remote); //system(instruct); if (!system(instruct)) printf("The user has turned the projector to standby mode\n"); else printf("Error on turning the projector to standby mode!\n"); } goto power; } break; case 2: sprintf(instruct, "/usr/local/irtrans/irclient localhost %s menu", remote); //system(instruct); printf("The user has entered the power mode\n"); projector_menu: sprintf(command, "AT*EASM=\"Menu\",1,1,9,\"up\",\"down\",\"left\",\"right\",\"enter\",\"reset\",\"menu\",\"undo\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (c=0; c<9; c++) ans_select[d]=0; choice1=1; while (choice1) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); for (d=0; d<9; d++) { sprintf (buffer, "*EAMI: %d", d+1); ans_select[d]=(NULL != strstr (answer, buffer)); if (ans_select[d]==1) { choice1=0; break; } } } if (ans_select[8]) goto projector; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s up", remote); //system(instruct); goto projector_menu; } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s down", remote); //system(instruct); goto projector_menu; } else if (ans_select[2]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s left", remote); //system(instruct); goto projector_menu; } else if (ans_select[3]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s right", remote); //system(instruct); goto projector_menu; } else if (ans_select[4]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s enter", remote); //system(instruct); printf("The user has selected an item in menu\n"); goto projector_menu; } else if (ans_select[5]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s reset", remote); //system(instruct); printf("The user has reset all settings to default one\n"); goto projector_menu; } else if (ans_select[6]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s menu", remote); //system(instruct); printf("The user has quitted from menu\n"); goto projector; } else if (ans_select[7]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s undo", remote); //system(instruct); printf("The user has cancelled the setting\n"); goto projector; } } break; case 3: printf("The user has entered input mode\n"); input: sprintf (command, "AT*EASM=\"Input\",1,1,8,\"mode 1\",\"mode 2\",\"mode 3\",\"mode 4\",\"mode 5\",\"Computer\",\"Video\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (c=0; c<7; c++) ans_select[c]=0; choice1=1; while (choice1) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); for (d=0; d<7; d++) { sprintf (buffer, "*EAMI: %d", d+1); ans_select[d]=(NULL != strstr (answer, buffer)); if (ans_select[d]==1) { choice1=0; break; } } } if (ans_select[7]) goto projector; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s input1", remote); //system(instruct); printf("The user has chosen input mode 1\n"); goto input; } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s input2", remote); //system(instruct); printf("The user has chosen input mode 2\n"); goto input; } else if (ans_select[2]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s input3", remote); //system(instruct); printf("The user has chosen input mode 3\n"); goto input; } else if (ans_select[3]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s input4", remote); //system(instruct); printf("The user has chosen input mode 4\n"); goto input; } else if (ans_select[4]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s input5", remote); //system(instruct); printf("The user has chosen input mode 5\n"); goto input; } else if (ans_select[5]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s computer", remote); //system(instruct); printf("The user has chosen input from computer \n"); goto input; } else if (ans_select[6]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s video", remote); //system(instruct); printf("The user has chosen input from video\n"); goto input; } } break; case 4: printf("The user has entered the display mode\n"); display: sprintf (command, "AT*EASM=\"Display\",1,1,7,\"Image\",\"Keystone\",\"Auto\",\"PinP\",\"Freeze\",\"Aspect\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (c=0; c<7; c++) ans_select[c]=0; choice1=1; while (choice1) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); for (d=0; d<7; d++) { sprintf (buffer, "*EAMI: %d", d+1); ans_select[d]=(NULL != strstr (answer, buffer)); if (ans_select[d]==1) { choice1=0; break; } } } if (ans_select[6]) goto projector; else { if (ans_select[0]) { printf("The user has entered image mode\n"); image: sprintf (command, "AT*EASM=\"Image\",1,1,7,\"Focus\",\"Zoom\",\"Magnify\",\"Position\",\"RGB\",\"Blank\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (e=0; e<7; e++) ans_select[e]=0; choice1=1; while (choice1) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); for (f=0; f<7; f++) { sprintf (buffer, "*EAMI: %d", f+1); ans_select[f]=(NULL != strstr (answer, buffer)); if (ans_select[f]==1) { choice1=0; break; } } } if (ans_select[6]) goto display; else { if (ans_select[0]) { printf("The user is changing focus\n"); focus: sprintf (command, "AT*EASM=\"Focus\",1,1,3,\"increase?\",\"decrease?\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (g=0; g<3; g++) ans_select[g]=0; while (!ans_select[0] && !ans_select[1] && !ans_select[2]) { ret_code = put_command ("", answer, sizeof (answer), 5, 0); ans_select[0]=(NULL!=strstr(answer, "*EAMI: 1")); ans_select[1]=(NULL!=strstr(answer, "*EAMI: 2")); ans_select[2]=(NULL!=strstr(answer, "*EAMI: 3")); } if (ans_select[2]) goto image; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s upfocus", remote); //system(instruct); printf("The user has increased the focus\n"); } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s downfocus", remote); //system(instruct); printf("The user has decreased the focus\n"); } goto focus; } } else if (ans_select[1]) { printf("The user is changing the zooming level\n"); zoom: sprintf (command, "AT*EASM=\"zoom\",1,1,3,\"increase?\",\"decrease?\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (g=0; g<3; g++) ans_select[g]=0; while (!ans_select[0] && !ans_select[1] && !ans_select[2]) { ret_code = put_command ("", answer, sizeof (answer), 5, 0); ans_select[0]=(NULL!=strstr(answer, "*EAMI: 1")); ans_select[1]=(NULL!=strstr(answer, "*EAMI: 2")); ans_select[2]=(NULL!=strstr(answer, "*EAMI: 3")); } if (ans_select[2]) goto image; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s upfocus", remote); //system(instruct); printf("The user has zoomed in\n"); } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s downfocus", remote); //system(instruct); printf("The user has zoomed out\n"); } goto zoom; } } else if (ans_select[2]) { printf("The user is changing the magnification\n"); magnify: sprintf (command, "AT*EASM=\"magnify\",1,1,3,\"up\",\"down\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (g=0; g<3; g++) ans_select[g]=0; choice1=1; while (choice1) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); for (h=0; h<3; h++) { sprintf (buffer, "*EAMI: %d", h+1); ans_select[h]=(NULL != strstr (answer, buffer)); if (ans_select[h]==1) { choice1=0; break; } } } if (ans_select[2]) goto image; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s up", remote); //system(instruct); printf("The user has magnified the display\n"); } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s down", remote); //system(instruct); printf("The user has made the display smaller\n"); } goto magnify; } } else if (ans_select[3]) { printf("The user is changing the display's position\n"); position: sprintf (command, "AT*EASM=\"position\",1,1,5,\"up\",\"down\",\"left\",\"right\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (g=0; g<5; g++) ans_select[g]=0; choice1=1; while (choice1) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); for (h=0; h<5; h++) { sprintf (buffer, "*EAMI: %d", h+1); ans_select[h]=(NULL != strstr (answer, buffer)); if (ans_select[h]==1) { choice1=0; break; } } } if (ans_select[4]) goto image; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s up", remote); //system(instruct); printf("The display has been shifted up\n"); } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s down", remote); //system(instruct); printf("The display has been shifted down\n"); } else if (ans_select[2]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s left", remote); //system(instruct); printf("The display has been shifted left\n"); } else if (ans_select[3]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s right", remote); //system(instruct); printf("The display has been shifted right\n"); } goto position; } } else if (ans_select[4]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s rgb", remote); //system(instruct); printf("The user has changed the display in rgb mode\n"); goto image; } else if (ans_select[5]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s blank", remote); //system(instruct); printf("The display has been blanked\n"); goto image; } } } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s keystone", remote); //system(instruct); printf("The user has entered keystone mode\n"); keystone: sprintf (command, "AT*EASM=\"Keystone\",1,1,7,\"up\",\"down\",\"left\",\"right\",\"keystone\",\"undo\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (e=0; e<7; e++) ans_select[e]=0; choice1=1; while (choice1) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); for (f=0; f<7; f++) { sprintf (buffer, "*EAMI: %d", f+1); ans_select[f]=(NULL != strstr (answer, buffer)); if (ans_select[f]==1) { choice1=0; break; } } } if (ans_select[6]) goto display; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s up", remote); //system(instruct); printf("The user has increased the level of the keystone\n"); goto keystone; } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s down", remote); //system(instruct); printf("The user has decreased the level of the keystone\n"); goto keystone; } else if (ans_select[2]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s left", remote); //system(instruct); printf("The user has changed the direction of keystone\n"); goto keystone; } else if (ans_select[3]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s right", remote); //system(instruct); printf("The user has changed the direction of keystone\n"); goto keystone; } else if (ans_select[4]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s keystone", remote); //system(instruct); printf("The user has closed the keystone dialog\n"); goto display; } else if (ans_select[5]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s undo", remote); //system(instruct); printf("The user has cleared the keystone change\n"); goto display; } } } else if (ans_select[2]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s auto", remote); //system(instruct); printf("The user has chosen auto position mode\n"); goto display; } else if (ans_select[3]) { printf("The user has chosen Picture-in-picture mode\n"); pinp: sprintf (command, "AT*EASM=\"PinP\",1,1,6,\"up\",\"down\",\"left\",\"right\",\"PinP\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (e=0; e<6; e++) ans_select[e]=0; choice1=1; while (choice1) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); for (f=0; f<6; f++) { sprintf (buffer, "*EAMI: %d", f+1); ans_select[f]=(NULL != strstr (answer, buffer)); if (ans_select[f]==1) { choice1=0; break; } } } if (ans_select[5]) goto image; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s up", remote); //system(instruct); printf("The user has switching the images\n"); } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s down", remote); //system(instruct); printf("The user has switching the images\n"); } else if (ans_select[2]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s left", remote); //system(instruct); printf("The user has changed image position\n"); } else if (ans_select[3]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s right", remote); //system(instruct); printf("The user has changed image position\n"); } else if (ans_select[4]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s pinp", remote); //system(instruct); printf("The sub image disappeared\n"); } goto pinp; } } else if (ans_select[4]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s freeze", remote); //system(instruct); printf("The display is freezed\n"); goto display; } else if (ans_select[5]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s aspect", remote); //system(instruct); printf("The user has changed the aspect\n"); goto display; } } break; case 5: printf("The user has entered volume mode \n"); volume: sprintf (command, "AT*EASM=\"Volume\",1,1,4,\"increase vol?\",\"decrease vol?\",\"mute?\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (a=0; a<4; a++) ans_select[a]=0; while (!ans_select[0] && !ans_select[1] && !ans_select[2] && !ans_select[3]) { ret_code = put_command ("", answer, sizeof (answer), 5, 0); ans_select[0]=(NULL!=strstr(answer, "*EAMI: 1")); ans_select[1]=(NULL!=strstr(answer, "*EAMI: 2")); ans_select[2]=(NULL!=strstr(answer, "*EAMI: 3")); ans_select[3]=(NULL!=strstr(answer, "*EAMI: 4")); } if (ans_select[3]) goto projector; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s upvol", remote); //system(instruct); printf("The user has increased volume\n"); } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s downvol", remote); //system(instruct); printf("The user has decreased volume \n"); } else if (ans_select[2]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s mute", remote); //system(instruct); printf("The projector was set to be silent \n"); } goto volume; } break; case 6: printf("The user has entered others mode \n"); others: sprintf (command, "AT*EASM=\"Others\",1,1,4,\"search\",\"laser\",\"mouse control\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (a=0; a<4; a++) ans_select[a]=0; while (!ans_select[0] && !ans_select[1] && !ans_select[2] && !ans_select[3]) { ret_code = put_command ("", answer, sizeof (answer), 5, 0); ans_select[0]=(NULL!=strstr(answer, "*EAMI: 1")); ans_select[1]=(NULL!=strstr(answer, "*EAMI: 2")); ans_select[2]=(NULL!=strstr(answer, "*EAMI: 3")); ans_select[3]=(NULL!=strstr(answer, "*EAMI: 4")); } if (ans_select[3]) goto projector; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s search", remote); //system(instruct); printf("The projector is searching..... \n"); } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s laser", remote); //system(instruct); printf("The projector is changed into laser mode \n"); } else if (ans_select[2]) { printf("The user has entered mouse mode \n"); mouse: sprintf (command, "AT*EASM=\"Mouse control\",1,1,7,\"up\",\"down\",\"left\",\"right\",\"enter\",\"reset\",\"quit\",\r"); ret_code = put_command (command, answer, sizeof (answer), 5, 0); for (e=0; e<7; e++) ans_select[e]=0; choice1=1; while (choice1) { ret_code=put_command ("", answer, sizeof (answer), 5, 0); for (f=0; f<7; f++) { sprintf (buffer, "*EAMI: %d", f+1); ans_select[f]=(NULL != strstr (answer, buffer)); if (ans_select[f]==1) { choice1=0; break; } } } if (ans_select[6]) goto others; else { if (ans_select[0]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s up", remote); //system(instruct); printf("The cursor is moving upward \n"); goto mouse; } else if (ans_select[1]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s down", remote); //system(instruct); printf("The cursor is moving downward \n"); goto mouse; } else if (ans_select[2]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s left", remote); //system(instruct); printf("The cursor is moving left \n"); goto mouse; } else if (ans_select[3]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s right", remote); //system(instruct); printf("The cursor is moving right \n"); goto mouse; } else if (ans_select[4]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s enter", remote); //system(instruct); printf("The cursor has chosen a point \n"); goto mouse; } else if (ans_select[5]) { sprintf(instruct, "/usr/local/irtrans/irclient localhost %s reset", remote); //system(instruct); printf("The user has right-clicked the mouse \n"); goto mouse; } } } } break; default: break; } goto projector; } }