#include #include #include #include #include #include #include #include // gettimeofday #include #include #include #include #include #include #include #include #include #include #include "confile.h" #include "Util.h" volatile int count; volatile int count_pre=0; void endian_swap(unsigned int *x) { *x = (*x>>24) | ((*x<<8) & 0x00FF0000) | ((*x>>8) & 0x0000FF00) | (*x<<24); } int get_parameter(struct decoce_param *pparam) { if(confile_init()) { printf("config file parse failed!\n"); return -1; } pparam->sdi_switch = get_conf_int("sdi_switch", 0); pparam->osd_on = get_conf_int("osd_on", 0); //pparam->light = get_conf_int("light", 0); printf("sdi %d osd %d ",pparam->sdi_switch,pparam->osd_on); return 0; } int main(int argc, char **argv) { unsigned long filesize; int socket_descriptor; int len; struct timeval timeout; struct sockaddr_in address; // volatile int count; // volatile int count_pre=0; int i; int flag=0; int port; char buf_cmd[20]; struct decoce_param param; struct sockaddr_in clientAddr; len = sizeof(clientAddr); bzero(&address,sizeof(address)); address.sin_family=AF_INET; address.sin_addr.s_addr=htonl(INADDR_ANY); port = atoi(argv[1]); address.sin_port=htons(port); socket_descriptor=socket(AF_INET,SOCK_DGRAM,0);//IPV4 get_parameter(¶m); count = param.sdi_switch; /* timeout.tv_sec = 1; timeout.tv_usec = 1000; if (setsockopu(socket_descriptor, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) == -1) { printf("setsockopt failed:\n"); } */ if (bind(socket_descriptor, (struct sockaddr *)&address, sizeof(address)) < 0) { perror("bind"); exit(1); } sprintf(buf_cmd,"/root/shell_sdi_cut_reg.sh %d",count); printf("-- %s\n",buf_cmd); system(buf_cmd); while(1) { i = recvfrom(socket_descriptor, &count, 4, 0, (struct sockaddr*)&clientAddr, &len); //printf("count %d\n",count); if(count_pre != count){ count_pre = count; //printf("++count ==== %d\n",count); //printf("count_pre +++ %d\n",count_pre); set_conf_int("sdi_switch",count); save_confile("/root/decode.cfg"); sprintf(buf_cmd,"/root/shell_sdi_cut_reg.sh %d",count); printf("%s\n",buf_cmd); system(buf_cmd); // count_pre = count; } } close(socket_descriptor); printf("send file finish\r\n"); }