📄 proc_cmd.c
字号:
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <termios.h>
#include <errno.h>
#include "args_cmd.h"
#include "thread.h"
#include "types.h"
#include "define.h"
#include "ctrl.h"
#define CHECK_DEV if (!(*is_me)) {\
printf("I have not set anything\n");\
if (g_is_dev_busy) {\
printf("device is busy now \n");\
return RPL_DEV_BUSY;\
}else{ \
*is_me =1;\
g_is_dev_busy =1;\
}\
}
int sound_state=0;
extern int g_is_running;
extern int g_is_dev_busy;
extern struct sockaddr_in tcp_client_addr[25];
int do_sth(){
return RPL_NOT_IMPLEMENT;
}
//extern THREAD_RETURN THREAD_API play_snd(void* arg);
int get_com_setting( char * buf, unsigned int *nlen )
{
if ( *nlen == 0)
{
}
strcpy(buf,"9600,8,N,1");
return 0;
}
static inline int eight_bit_add(char *ch, int startx, int endx)
{
int count = 0;
int i;
for ( i = startx ; i <= endx; ++ i )
{ count += ch[i];
}
return count % 256;
}
int control_device( int camera_no, uint16_t action, int com_handle,const char * add_data, size_t length )
{
char ch[7] = {0xff,camera_no + 1,0,0,0,0,0};
switch(action)
{
case 0://stop
ch[2] = 0;
ch[3] = 0;
ch[4] = 0;
ch[5] = 0;
break;
case 1://up
ch[2] = 0;
ch[3] = 0x08;
ch[4] = 0;
ch[5] = 0x2f;
printf("action:up\n");
break;
case 2://down
printf("case 2!\n");
ch[2] = 0;
ch[3] = 0x10;
ch[4] = 0;
ch[5] = 0x2f;
printf("action:down\n");
break;
case 3://left
ch[2] = 0;
ch[3] = 0x04;
ch[4] = 0x2f;
ch[5] = 0;
printf("action:left\n");
break;
case 4://right
ch[2] = 0;
ch[3] = 0x02;
ch[4] = 0x2f;
ch[5] = 0;
printf("action:right\n");
break;
case 5://aperture+
ch[2] = 0x02;
ch[3] = 0;
ch[4] = 0;
ch[5] = 0;
printf("action:iris +\n");
break;
case 6://aperture-
ch[2] = 0x04;
ch[3] = 0;
ch[4] = 0;
ch[5] = 0;
printf("action:iris -\n");
break;
case 7://zoom +
ch[2] = 0;
ch[3] = 0x20;
ch[4] = 0;
ch[5] = 0;
printf("action:zoom+\n");
break;
case 8://zoom-
ch[2] = 0;
ch[3] = 0x40;
ch[4] = 0;
ch[5] = 0;
printf("action:zoom-\n");
break;
case 9://focus+
ch[2] = 0x01;
ch[3] = 0;
ch[4] = 0;
ch[5] = 0;
printf("action:focus+\n");
break;
case 10://focus-
ch[2] = 0;
ch[3] = 0x80;
ch[4] = 0;
ch[5] = 0;
printf("aciont:focus-\n");
break;
case 11:
ch[2] = 0x00;
ch[3] = 0x07;
ch[4] = 0x00;
ch[5] = 0x63;
break;
case 12:
ch[2] = 0x00;
ch[3] = 0x07;
ch[4] = 0x00;
ch[5] = 0x60;
break;
case 13:
ch[2] = 0;
ch[3] = 0x09;
ch[4] = 0;
ch[5] = 0x01;
break;
case 14:
ch[2] = 0;
ch[3] = 0x0b;
ch[4] = 0;
ch[5] = 0x01;
break;
case 15:
ch[2] = 0;
ch[3] = 0x09;
ch[4] = 0;
ch[5] = 0x04;
break;
case 16:
ch[2] = 0;
ch[3] = 0x0b;
ch[4] = 0;
ch[5] = 0x04;
break;
case 17:
ch[2] = 0;
ch[3] = 0x09;
ch[4] = 0;
ch[5] = 0x02;
break;
case 18:
ch[2] = 0;
ch[3] = 0x0b;
ch[4] = 0;
ch[5] = 0x02;
break;
case 19:
ch[2] = 0;
ch[3] = 0x09;
ch[4] = 0;
ch[5] = 0x03;
break;
case 20:
ch[2] = 0;
ch[3] = 0x0b;
ch[4] = 0;
ch[5] = 0x03;
break;
case 8200:
{
printf("8200!\n");
if ( length == 2 || length == 4 )
{
int i = 0;
AGAIN:
printf("%c,%d,",add_data[i],add_data[i+1]);
switch (add_data[i])
{
case 'U':
printf("case U!\n");
ch[3] += 0x08;
ch[5] = add_data[i+1] * 0x3F / 255;
break;
case 'D':
ch[3] += 0x10;
ch[5] = add_data[i+1] * 0x3F / 255;
break;
case 'L':
ch[3] += 0x04;
ch[4] = add_data[i+1] * 0x3F / 255;
break;
case 'R':
ch[3] += 0x02;
ch[4] = add_data[i+1] * 0x3F / 255;
break;
default:
return -1;
}
if ( length == 4 )
{
i += 2;
length = 120; // is not 4
goto AGAIN;
}
printf("\n");
}
else
return -1;
break;
}
case 8202:
{
ch[2] = 0;
ch[3] = 0;
ch[4] = 0;
ch[5] = 0;
break;
}
case 8206:
{
if ( add_data[0] <= 32 )
{
ch[2] = 0x00;
ch[3] = 0x03;
ch[4] = 0x00;
ch[5] = add_data[0];
}
else
{
ch[2] = 0x02;
ch[3] = 0xFF;
ch[4] = add_data[0] - 33;
ch[5] = 0x01;
}
break;
}
case 8208:
{
return -1;
}
break;
case 8210:
{
if ( add_data[0] <= 32 )
{
ch[2] = 0x00;
ch[3] = 0x07;
ch[4] = 0x00;
ch[5] = add_data[0];
}
else
{
ch[2] = 0x02;
ch[3] = 0xFF;
ch[4] = add_data[0] - 33;
ch[5] = 0x00;
}
break;
}
case 8212:
return -1;
case 8300:
{
if ( add_data[0] )
ch[2] = 0x02;
else
ch[2] = 0x04;
ch[3] = 0;
ch[4] = 0;
ch[5] = 0;
break;
}
case 8302:
{
ch[2] = 0;
ch[4] = 0;
ch[5] = 0;
if ( add_data[0] )
ch[3] = 0x20;
else
ch[3] = 0x40;
break;
}
case 8304:
{
if ( add_data[0] )
ch[2] = 0x01;
else
ch[3] = 0x80;
break;
}
case 8306:
case 8308:
case 8310:
{
ch[2] = 0;
ch[3] = 0;
ch[4] = 0;
ch[5] = 0;
printf("8310!\n");
break;
}
case 8204:
{
if ( add_data[0] )
{
ch[2] = 0x10;
ch[3] = 0x00;
ch[4] = 0x00;
ch[5] = 0x00;
ch[6] = eight_bit_add(ch,1,5);
write(com_handle, ch, 7);
}
ch[2] = 0x00;
ch[3] = 0x07;
ch[4] = 0x00;
if ( add_data[0] )
ch[5] = 0x63;
else
ch[5] = 0x60;
break;
}
default: // not supported!
return -1;
}
ch[6] = eight_bit_add(ch,1,5);
write(com_handle, ch, 7);
usleep(500000);
return 0;
}
int set_opt(int fd,int nSpeed, int nBits, char nEvent, int nStop)
{
struct termios newtio,oldtio;
if ( tcgetattr( fd,&oldtio) != 0) {
perror("SetupSerial 1");
return -1;
}
bzero( &newtio, sizeof( newtio ) );
newtio.c_cflag &= ~CSIZE;
// set the nBits
switch( nBits )
{
case 7:
newtio.c_cflag |= CS7;
break;
case 8:
newtio.c_cflag |= CS8;
break;
}
//Set the Check mode and StopBit
switch( nEvent )
{
case 'O': //odd
newtio.c_cflag |= PARENB;
newtio.c_cflag |= PARODD;
newtio.c_iflag |= (INPCK | ISTRIP);
break;
case 'E': //even
newtio.c_iflag |= (INPCK | ISTRIP);
newtio.c_cflag |= PARENB;
newtio.c_cflag &= ~PARODD;
break;
case 'N': //NULL
newtio.c_cflag &= ~PARENB;
break;
}
newtio.c_cflag |= CLOCAL | CREAD;
switch( nSpeed )
{
case 2400:
cfsetispeed(&newtio, B2400);
cfsetospeed(&newtio, B2400);
break;
case 4800:
cfsetispeed(&newtio, B4800);
cfsetospeed(&newtio, B4800);
break;
case 9600:
cfsetispeed(&newtio, B9600);
cfsetospeed(&newtio, B9600);
break;
case 115200:
cfsetispeed(&newtio, B115200);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -