187 lines
4.4 KiB
C
Executable File
187 lines
4.4 KiB
C
Executable File
#include <linux/input.h>
|
|
#include <fcntl.h>
|
|
#include <stdio.h>
|
|
#include <stdint.h>
|
|
#include <pthread.h>
|
|
#include "keyboard.h"
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
#include <sys/stat.h>
|
|
#include <string.h>
|
|
#include <sys/socket.h>
|
|
#include <netinet/in.h>
|
|
#include <arpa/inet.h>
|
|
#include <netdb.h>
|
|
#include <unistd.h>
|
|
#include <sys/types.h>
|
|
#include <sys/time.h>
|
|
#include <fcntl.h>
|
|
#include <sys/mman.h>
|
|
#include <arpa/inet.h>
|
|
#include <netdb.h>
|
|
#include "confile.h"
|
|
#include "Util.h"
|
|
|
|
//#define KEY_EVENT_DEV0_NAME "/dev/input/event0"
|
|
|
|
#define DEFAULT_MD_LEN 4096
|
|
//unsigned char key_value;
|
|
|
|
static pthread_t pkts_thread;
|
|
|
|
int socket_descriptor;
|
|
struct sockaddr_in address;
|
|
|
|
int fd_param;
|
|
int *buffer_param;
|
|
//int fd_param_uart;
|
|
//int *buffer_param_uart;
|
|
int *switch_video;
|
|
//int pre_switch_mode;
|
|
int switch_mode_pre=0;
|
|
int switch_mode=1;
|
|
int buffer[1024];
|
|
|
|
void * memmap(unsigned int phy_addr, unsigned int size);
|
|
void* pkts_worker(void *arg)
|
|
{
|
|
|
|
printf("pkts_worker...\n");
|
|
|
|
//int anjian_switch=0;
|
|
|
|
//uint32_t ulOld;
|
|
//int read_key;
|
|
//void* pMem = NULL;
|
|
|
|
|
|
while(1)
|
|
{
|
|
|
|
sendto(socket_descriptor,buffer,13*4,0,(struct sockaddr *)&address,sizeof(address));
|
|
//anjian_switch =count;
|
|
//if(anjian_switch ==(switch_video+1)){
|
|
// anjian_switch =1;
|
|
//}
|
|
//sendto(socket_descriptor,buffer,13*4,0,(struct sockaddr *)&address,sizeof(address));
|
|
// printf("-------------%x\n",anjian_switch);
|
|
// sendto(socket_descriptor,&anjian_switch,4,0,(struct sockaddr *)&address,sizeof(address));
|
|
sleep(2);
|
|
|
|
}
|
|
}
|
|
|
|
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 main(int argc, char **argv)
|
|
{
|
|
|
|
|
|
//int key_fd = 0;
|
|
//struct input_event key_event = {0};
|
|
//int ret;
|
|
int port;
|
|
//int *switch_mode;
|
|
int len;
|
|
pthread_attr_t attr;
|
|
// int *buffer;
|
|
struct decoce_param param;
|
|
|
|
|
|
fd_param = shm_open("/param.txt",O_RDWR|O_CREAT|O_EXCL,0777);
|
|
if(fd_param < 0){
|
|
fd_param = shm_open("/param.txt",O_RDWR,0777);
|
|
}else
|
|
ftruncate(fd_param,4096);
|
|
buffer_param= mmap(NULL,4096,PROT_READ|PROT_WRITE,MAP_SHARED,fd_param,0);
|
|
|
|
//switch_video = 6;
|
|
|
|
bzero(&address,sizeof(address));
|
|
address.sin_family=AF_INET;
|
|
address.sin_addr.s_addr=inet_addr(argv[1]);
|
|
port = atoi(argv[2]);
|
|
address.sin_port=htons(port);
|
|
|
|
socket_descriptor=socket(AF_INET,SOCK_DGRAM,0);//IPV4
|
|
|
|
//switch_video = atoi(argv[3]);
|
|
|
|
// int flag_down=0;
|
|
// int count_down=0;
|
|
|
|
#if 1
|
|
pthread_attr_init(&attr);
|
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
|
|
len = pthread_create(&pkts_thread, &attr, pkts_worker, NULL);
|
|
pthread_attr_destroy(&attr);
|
|
#endif
|
|
switch_video= switch_memory_open();
|
|
|
|
buffer[0]= 0x11;
|
|
//switch_mode[0] = 0x01;
|
|
//switch_mode[0] = param.sdi_switch;
|
|
//count = param.sdi_switch;
|
|
//switch_mode[1] = param.osd_on;
|
|
//switch_mode[3] = param.light;
|
|
//osd_on = param.osd_on;
|
|
//light = param.light;
|
|
//buffer[0] = 0x11;
|
|
//printf("switch_mode[0] %x \n",switch_mode[0]);
|
|
// for(int i=0;i<21;i++){
|
|
// printf("%x",switch_mode[i]);
|
|
|
|
// }
|
|
// printf("\n");
|
|
|
|
// printf("++++\n");
|
|
switch_mode_pre = switch_mode;
|
|
while(1)
|
|
{
|
|
//printf("while \n");
|
|
switch_mode =switch_video[0];
|
|
// printf("switch_mode %x\n",switch_mode);
|
|
memcpy(buffer+1,switch_video,24);
|
|
memcpy(buffer+7,buffer_param,24);
|
|
//printf("----");
|
|
#if 1
|
|
if(switch_mode != switch_mode_pre){
|
|
printf("hello\n");
|
|
printf("++++++%x \n",switch_mode);
|
|
// SAMPLE_VDEC_VPSS_VO_SET_MODE(switch_mode);
|
|
switch_mode_pre = switch_mode;
|
|
|
|
memcpy(buffer+1,switch_video,24);
|
|
memcpy(buffer+7,buffer_param,24);
|
|
|
|
sendto(socket_descriptor,buffer,13*4,0,(struct sockaddr *)&address,sizeof(address));
|
|
}
|
|
|
|
#endif
|
|
|
|
sleep(1);
|
|
//sendto(socket_descriptor,switch_mode,40,0,(struct sockaddr *)&address,sizeof(address));
|
|
//usleep(500000);
|
|
// sendto(socket_descriptor,buffer_param,20,0,(struct sockaddr *)&address,sizeof(address));
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|