#include #include #include #include "api/video/video_frame.h" #include "../common/comm.h" #include "../common/iobuffer.h" #include "api.h" #include "protocol.pb.h" #include "PCANBasic.h" #include "message_queue.h" #include #include #include #include #include #include #include #include #include bool g_collbrate=false; void renableUSB(const char *file) { // return; printf("Resetting USB device %s\n", file); int fd = open(file, O_WRONLY); if (fd < 0) { char text[256]; perror(text); printf("Error opening output file %s", text); return; } int rc = ioctl(fd, USBDEVFS_RESET, 0); if (rc < 0) { perror("Error in ioctl"); return; } printf("Reset successful\n"); close(fd); } void daemonize(void) { signal(SIGTTOU, SIG_IGN); signal(SIGTTIN, SIG_IGN); signal(SIGTSTP, SIG_IGN); if (0 != fork()) exit(0); if (-1 == setsid()) exit(0); signal(SIGHUP, SIG_IGN); if (0 != fork()) exit(0); // if (0 != chdir("/")) exit(0); } bool checkOnly() { const char filename[] = "./lockfile"; int fd = open(filename, O_WRONLY | O_CREAT, 0644); int flock = lockf(fd, F_TLOCK, 0); if (fd == -1) { return false; } // 给文件加锁 if (flock == -1) { return false; } // 程序退出后,文件自动解锁 return true; } std::string getpath() { char exec_name[BUFSIZ]; memset(exec_name, 0, sizeof(exec_name)); readlink("/proc/self/exe", exec_name, BUFSIZ); // std::cout<= 0; i--) { if (exec_name[i] == '/') { exec_name[i] = 0; break; } } return std::string(exec_name); } int8_t hi_byte(int16_t value) { int8_t hi = (int8_t)((value & 0xFF00) >> 8); return hi; } int8_t lo_byte(int16_t value) { int8_t lo = (int8_t)(value & 0xff); return lo; } int main(int argc, char *argv[]) { // renableUSB("/dev/bus/usb/002/002"); // renableUSB("/dev/bus/usb/001/003"); // daemonize(); // printf("sensors_init:%d, %s\n", err ,sensors_strerror(err)); auto path = getpath(); std::cout << "hello" << path << std::endl; if (-1 == chdir(path.c_str())) return 0; if (checkOnly() == false) { std::cout << "进程已经在运行" << std::endl; return 0; } // std::cout << "进程启动..." << std::endl; // char temp[BUFSIZ]; // getcwd(temp,BUFSIZ); // std::cout<