#include #include #include // gettimeofday #include #include #include #include #include #include #include #include #include #include #include #include #include "serial.h" #include "uartinf.h" #include "confile.h" #include "udp_util.h" #include "Util.h" char _rx_data[1024]; int switch_video; int count=0; int osd_on=0; int *switch_memory_open(void) { char buf[128]; int fd; sprintf(buf, "/video_switch"); fd = shm_open(buf, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); if(fd < 0) { perror("shm_open"); exit(1); } if (ftruncate(fd, 4096) == -1) { perror("ftruncate"); exit(1); } int *retval = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); return retval; } int get_parameter(struct decoce_param *pparam) { if(confile_init()) { printf("config file parse filed!\n"); return -1; } pparam->sdi_switch = get_conf_int("sdi_switch", 0); pparam->osd_on = get_conf_int("osd_on", 0); printf("sdi %d osd %d ",pparam->sdi_switch,pparam->osd_on); return 0; } int main (int argc, char *argv[]) { int n_read; char buffer[1024]; char buffer1[1024]; int *switch_mode; int len; int anjian; int anjian_pre; int mode; int count ; struct decoce_param param; switch_video = 5; int fd_param; int *buffer_param; switch_mode = switch_memory_open(); get_parameter(¶m); switch_mode[0] = param.sdi_switch; count = param.sdi_switch; switch_mode[1] = param.osd_on; osd_on = param.osd_on; // printf("osd: %d count %d \n",osd_on,count); n_read = uart_init(ROUTE_UART, "/dev/ttyAMA0", 115200, 'N'); if(n_read <=0 ) { printf("open /dev/ttyAMA4 failed\n"); return -1; } buffer[0]=0xaa; buffer[1]=0x01; buffer[2]=switch_mode[0]; buffer[3]=0x55; //anjian=switch_mode[10]; //anjian_pre = anjian; for(int i=0;i<20;i++){ uart_write(ROUTE_UART, buffer); usleep(100000); //sleep(1); } while(1){ n_read = uart_get(ROUTE_UART, _rx_data); if(n_read>0){ printf("0 %x %x anjian %x",_rx_data[0],_rx_data[1],_rx_data[38]); set_conf_int("sdi_switch",_rx_data[2]); save_confile("/root/decode.cfg"); switch_mode[0] = _rx_data[2]; switch_mode[1] = osd_on; } } }