Скрипт наклона Huddle Cam, работающий на Linux, но не на Android устройстве - PullRequest
0 голосов
/ 03 февраля 2020

Я пытаюсь проверить камеру Huddle с устройством Android. У камеры есть опция наклона (вверх, вниз, вправо, влево). И это можно контролировать с помощью отправки HEX-кодов через USB-порт. Я написал скрипт в C, чтобы сделать наклон камеры в Linux, и скомпилировал его с помощью g cc. Когда я запускаю скрипт, он работает, но когда я компилирую тот же файл C для устройства Android, используя команду "mmm" и отправляя его на устройство с ADB pu sh, он не работает, он не работает даже отправив что-нибудь в Huddle Camera. Интересно, что у меня есть некоторые функции fprint в скрипте, когда я запускаю скрипт на устройстве Android, я вижу строки fprint. Итак, scrpit работает, он просто не посылает шестнадцатеричные команды на камеру. Как сделать так, чтобы этот скрипт правильно работал на устройстве Android?

Вы можете увидеть коды ниже:

#include <stdio.h>
#include <string.h>

// Linux headers
#include <fcntl.h> // Contains file controls like O_RDWR
#include <errno.h> // Error integer and strerror() function
#include <termios.h> // Contains POSIX terminal control definitions
#include <unistd.h> // write(), read(), close()

int main()
{   
int delay = 1;
int serial_port;
unsigned long i;
struct termios tty;
unsigned char up[] ={ 0x81, 0x01, 0x06, 0x01, 0x05, 0x05, 0x03, 0x01, 0xff};
unsigned char down[] = {0x81, 0x01, 0x06, 0x01, 0x05, 0x05, 0x03, 0x02, 0xFF};
unsigned char left[] = {0x81, 0x01, 0x06, 0x01, 0x05, 0x05, 0x01, 0x03, 0xFF};
unsigned char right[] = {0x81, 0x01, 0x06, 0x01, 0x05, 0x05, 0x02, 0x03, 0xFF};
unsigned char stop[] = {0x81, 0x01, 0x06, 0x01, 0x05, 0x05, 0x03, 0x03, 0xFF};
unsigned char upleft[] = {0x81, 0x01, 0x06, 0x01, 0x05, 0x05, 0x01, 0x01, 0xFF};
unsigned char upright[] = {0x81, 0x01, 0x06, 0x01, 0x05, 0x05, 0x02, 0x01, 0xFF};
unsigned char downleft[] = {0x81, 0x01, 0x06, 0x01, 0x05, 0x05, 0x01, 0x02, 0xFF};
unsigned char downright[] = {0x81, 0x01, 0x06, 0x01, 0x05, 0x05, 0x02, 0x02, 0xFF};


char read_buf [256];
int ret;

serial_port = open("/dev/ttyUSB0", O_RDWR);

//# Check for errors
if (serial_port < 0) {
    printf("Error %i from open: %s\n", errno, strerror(errno));
}


memset(&tty, 0, sizeof tty);

// Read in existing settings, and handle any error
if(tcgetattr(serial_port, &tty) != 0) {
    printf("Error %i from tcgetattr: %s\n", errno, strerror(errno));
}

tty.c_cflag &= ~PARENB; // Clear parity bit, disabling parity (most common)
tty.c_cflag &= ~CSTOPB; //Stop bit 1
tty.c_cflag |= CS8; // Receive 8 byte
tty.c_cflag &= ~CRTSCTS;  //Flow control disable
tty.c_cflag |= CREAD | CLOCAL; //Read data bit
tty.c_lflag &= ~ICANON; //Canonical mode disabled
tty.c_lflag &= ~ECHO; // Disable echo
tty.c_lflag &= ~ECHOE; // Disable erasure
tty.c_lflag &= ~ECHONL; // Disable new-line echo
tty.c_lflag &= ~ISIG; // Disable interpretation of INTR, QUIT and SUSP
tty.c_iflag &= ~(IXON | IXOFF | IXANY); // Turn off s/w flow ctrl
tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL); // Disable any special handling of received bytes
tty.c_oflag &= ~OPOST; // Prevent special interpretation of output bytes (e.g. newline chars)
tty.c_oflag &= ~ONLCR; // Prevent conversion of newline to carriage return/line feed
tty.c_cc[VTIME] = 10;    // Wait for up to 1s (10 deciseconds), returning as soon as any data is received.
tty.c_cc[VMIN] = 0;

cfsetispeed(&tty, B9600);
cfsetospeed(&tty, B9600);


if (tcsetattr(serial_port, TCSANOW, &tty) != 0) {
    printf("Error %i from tcsetattr: %s\n", errno, strerror(errno));
}



while(1){


/*
    for ((printf("Msg: "), i = 0); i < 9; i++){
        printf( "0x%02X ", up[i]);
}
printf("\n");*/

ret = write(serial_port, up, sizeof(up));
if(ret != 0) {
    printf("%d bytes sent to /dev/ttyUSB0.  - Going up!\n", ret);
}
sleep(delay);

ret = write(serial_port, down, sizeof(down));
if(ret != 0) {
    printf("%d bytes sent to /dev/ttyUSB0.  - Going down!\n", ret);
}
sleep(delay);
ret = write(serial_port, stop, sizeof(stop));


ret = write(serial_port, right, sizeof(down));
if(ret != 0) {
    printf("%d bytes sent to /dev/ttyUSB0.  - Going right!\n", ret);
}

sleep(delay);

ret = write(serial_port, left, sizeof(down));
if(ret != 0) {
    printf("%d bytes sent to /dev/ttyUSB0.  - Going left!\n", ret);
}
sleep(delay);
ret = write(serial_port, stop, sizeof(stop));

ret = write(serial_port, upleft, sizeof(upleft));
if(ret != 0) {
    printf("%d bytes sent to /dev/ttyUSB0.  - Going upleft!\n", ret);
}
sleep(delay);

ret = write(serial_port, downright, sizeof(downright));
if(ret != 0) {
    printf("%d bytes sent to /dev/ttyUSB0.  - Going downright!\n", ret);
}
sleep(delay);

ret = write(serial_port, upright, sizeof(upright));
if(ret != 0) {
    printf("%d bytes sent to /dev/ttyUSB0.  - Going downright!\n", ret);
}
sleep(delay);

ret = write(serial_port, downleft, sizeof(downleft));
if(ret > 0) {
    printf("%d bytes sent to /dev/ttyUSB0.  - Going downright!\n", ret);
}
sleep(delay);
ret = write(serial_port, stop, sizeof(stop));

//sleep
//write(serial_port, down, sizeof(msg));
//sleep
//write(serial_port, left, sizeof(msg));
//write(serial_port, right, sizeof(msg));


/*
memset(&read_buf, '\0', sizeof(read_buf));
int n = read(serial_port, &read_buf, sizeof(read_buf));

for((printf("Ans: "), i=0); i<sizeof(read_buf)/ sizeof(read_buf[0]); i++){
printf("0x%02X ",read_buf[i]);  
}
printf("\n");
*/

}




close(serial_port);

}

...