/* * X10 IP播报和出厂设置检测程序 * 2019.7.30 lpc * * Intercom device Funtions: Dial && PlayIP * Speaker device Funtions: PlayIP && FactoryREST */ #include #include #include #include #include #include #include #include #include #include #include #define Boolean int #define TRUE 1 #define FALSE 0 #define MAX_PIPE_BUFSIZE 256 static int playip_lock = FALSE; static int press_down = FALSE; static enum devType { INTERCOM = 0, SPEAKER }; static int devType; Boolean get_ip(char * pv) { FILE * fp; char cmdbuf[128], value[32]; sprintf(cmdbuf,"/sbin/ifconfig eth0 | grep inet | cut -d\":\" -f2 | cut -d\" \" -f1"); fp = popen(cmdbuf, "r"); if (fp == NULL) { // printf("Fail to open pipe\n"); return FALSE; } memset(value,0,sizeof(value)); if (!feof(fp) && fgets(value,MAX_PIPE_BUFSIZE,fp) != NULL) ; // printf("value:%s\n", value); else { printf("ip wrong\n"); return FALSE; } pclose(fp); if(strlen(value) < 10) return FALSE; strcpy(pv,value); return TRUE; } int PlayIP() { //add by ssc 2019-12-26 char language[32]; FILE *fp = popen("sysconf /etc/speaker.conf get system language","r"); if(!fp) perror("popen wrong"); bzero(language,sizeof(language)); fread(language,1,sizeof(language),fp); pclose(fp); language[strlen(language)] = '\0'; playip_lock = TRUE; char ipaddr[16],cmd_line[240]; if(!get_ip(ipaddr)) { if (strcmp(language, "en") == 0){ system("mpg123 -r 48000 /home/new-speaker/target/share/sounds/en/get_ip_failed.mp3"); }else{ system("mpg123 -r 48000 /home/new-speaker/target/share/sounds/cn/get_ip_failed.mp3"); } return 0; } if (strcmp(language, "en") == 0){ strcpy(cmd_line,"cd /home/new-speaker/target/share/sounds/en/;mpg123 -r 48000 "); }else{ strcpy(cmd_line,"cd /home/new-speaker/target/share/sounds/cn/;mpg123 -r 48000 "); } int i; for (i=0;i= 30) { press_down = TRUE; time(&newtime); printf("KEY DOWN\n"); } else { time(&lastime); len = lastime - newtime; printf("KEY UP, Time:%d\n", len); if(press_down){ press_down = FALSE; if(devType == SPEAKER){ if ( len >= 2 && len <= 9) // Play IP pthread_create(&thread, NULL, thread_playIP, NULL); else if ( len >= 1000) pthread_create(&thread, NULL, thread_playIP, NULL); else if ( len >= 10){ system("/etc/scripts/play_rebooting.sh;rm -f /oem/.userdata && /sbin/reboot"); } } else { if (len >= 5) pthread_create(&thread, NULL, thread_playIP, NULL); else // Make a phone call. if(checkSIPActive()) emergencyCall(); } } } } } }