diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..51e2fb7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +./build/* \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 1797c1c..42e1dbb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ add_compile_options(-std=c++14) # set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc) # set(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++) # set(CMAKE_LIBRARY_ARCHITECTURE arm) - +add_subdirectory(fpga) set(-mfloat-abi=hard) # set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) @@ -63,17 +63,11 @@ add_custom_command(TARGET ${PROJECT_NAME} set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS_RELEASE "-s") - -#target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS} pthread) -message(/home/modehua/sdk/scanservices/scanservices/fpga/bin/libfpgaupdate.a) -target_link_libraries(${PROJECT_NAME} /home/modehua/sdk/scanservices/scanservices/fpga/bin/libfpgaupdate.a) +target_link_libraries(${PROJECT_NAME} ${PROJECT_BINARY_DIR}/bin/libfpgaupdate.a) #target_link_libraries(${PROJECT_NAME} opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs turbojpeg pthread ) target_link_libraries(${PROJECT_NAME} pthread ) target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR} - -${PROJECT_SOURCE_DIR}/fpga -${PROJECT_SOURCE_DIR}/imageprocess -${PROJECT_SOURCE_DIR}/imageprocess/include -${PROJECT_SOURCE_DIR}/home/modehua/sdk/sysroots/cortexa9t2hf-neon-xilinx-linux-gnueabi/usr/include/opencv4/ + ${PROJECT_SOURCE_DIR}/fpga + ${PROJECT_SOURCE_DIR}/home/modehua/sdk/sysroots/cortexa9t2hf-neon-xilinx-linux-gnueabi/usr/include/opencv4/ ) \ No newline at end of file diff --git a/CorrectParam.cpp b/CorrectParam.cpp index 25dbdb9..40a5752 100644 --- a/CorrectParam.cpp +++ b/CorrectParam.cpp @@ -7,7 +7,7 @@ using namespace std; -#define JSONPATH "/usr/local/huago/cameraparam.json" +#define JSONPATH "/mnt/conf-disk/huago/cameraparam.json" #define TEXTLUT200COLORPATH "/usr/local/huago/Textlut200clr.bmp" #define LUT200COLORPATH "/usr/local/huago/lut200clr.bmp" diff --git a/CuoZhiMotor.cpp b/CuoZhiMotor.cpp index bd3c6ee..52cf1bb 100644 --- a/CuoZhiMotor.cpp +++ b/CuoZhiMotor.cpp @@ -4,7 +4,8 @@ CuoZhiMotor::CuoZhiMotor() : Motor(motorPorts_Cuozhi) { - auto t_smbtype = smbtype == SMBType::MB_DRV_TMC216 ? MotorConfig::MTBDType::MT_TMC : MotorConfig::MTBDType::MT_DRV; + //auto t_smbtype = smbtype == SMBType::MB_DRV_TMC216 ? MotorConfig::MTBDType::MT_TMC : MotorConfig::MTBDType::MT_DRV; + auto t_smbtype = MotorConfig::MTBDType::MT_TMC; m_cuoparamex = m_mtconfig->GetMotorSpeedParam(false, t_smbtype, 4, 1, 1); speedConfig(); mspCuozhiFeeding = {.finalPeriod = 1427500, .Fmin = 2027500, .stepnum = 30, .a = 100, .offset = 4, .finalDelay = 3000}; @@ -100,7 +101,8 @@ void CuoZhiMotor::feeding() void CuoZhiMotor::speedChange(int speed, int dpi, int colormode) // speed should be in range [0,5] (by ply,at 2019.5.23) { - auto t_smbtype = smbtype == SMBType::MB_DRV_8825 ? MotorConfig::MTBDType::MT_DRV : MotorConfig::MTBDType::MT_TMC; + //auto t_smbtype = smbtype == SMBType::MB_DRV_8825 ? MotorConfig::MTBDType::MT_DRV : MotorConfig::MTBDType::MT_TMC; + auto t_smbtype = MotorConfig::MTBDType::MT_TMC; m_cuoparamex = m_mtconfig->GetMotorSpeedParam(false, t_smbtype, speed, colormode, dpi); speedConfig(); } diff --git a/HCamDevice.cpp b/HCamDevice.cpp index 36aef57..95ee6ab 100644 --- a/HCamDevice.cpp +++ b/HCamDevice.cpp @@ -19,6 +19,8 @@ #include +#include "logs_out.h" + #define ADC_82V48 @@ -27,14 +29,41 @@ #define HT_CAM_REG_CR_CHANGE_MASK 0x00020000 -#define camera_print(...) (printf("L%d(%s):", __LINE__, __FILE__), \ - printf(__VA_ARGS__)) +// #define camera_print(...) (printf("L%d(%s):", __LINE__, __FILE__), \ +// printf(__VA_ARGS__)) -#define camera_dbg(...) (printf("L%d(%s):", __LINE__, __FILE__), \ - printf(__VA_ARGS__)) +// #define camera_dbg(...) (printf("L%d(%s):", __LINE__, __FILE__), \ +// printf(__VA_ARGS__)) -#define camera_err(...) (printf("L%d(%s):", __LINE__, __FILE__), \ - printf(__VA_ARGS__)) +// #define camera_err(...) (printf("L%d(%s):", __LINE__, __FILE__), \ +// printf(__VA_ARGS__)) + + +#define camera_print(fmt, args...) { \ + char timestr[32]; \ + timestamp((char*)×tr, sizeof(timestr)); \ + fprintf(stdout, \ + "[HCamDevice - %s - Info] " fmt "\n",(char*)×tr, \ + ## args); \ + fflush(stdout); \ + } + +#define camera_dbg(fmt, args...) { \ + char timestr[32]; \ + timestamp((char*)×tr, sizeof(timestr)); \ + fprintf(stdout, \ + "[HCamDevice - %s - Info] " fmt "\n",(char*)×tr, \ + ## args); \ + fflush(stdout); \ + } + +#define camera_err(fmt, args...) { \ + char timestr[32]; \ + timestamp((char*)×tr, sizeof(timestr)); \ + fprintf(stdout, "[HCamDevice - %s - Info] " fmt "\n",(char*)×tr, \ + ## args); \ + fflush(stdout); \ + } #define CLEAR(x) memset(&(x), 0, sizeof(x)) @@ -97,7 +126,7 @@ HCamDevice::HCamDevice() for (int i = 0; i < 20; i++) { HtCamReadADCReg(i, &val); - camera_print("ADDR: 0x%x, Value: 0x%x\n", i, val); + camera_print("ADDR: 0x%x, Value: 0x%x", i, val); } this->event_thread.reset(new std::thread(&HCamDevice::HtCamEventWorkThread, this)); @@ -306,18 +335,17 @@ int HCamDevice::read_frame(void **pbuf, int timeout) buf.length = nplanes; buf.m.planes = (struct v4l2_plane *)calloc(nplanes, sizeof(struct v4l2_plane)); } - - int ret = ioctl(videofd, VIDIOC_DQBUF, &buf); - if ( ret == 0) - camera_dbg("*****DQBUF[%d] FINISH*****\n", buf.index); + + if (ioctl(videofd, VIDIOC_DQBUF, &buf) == 0) + camera_dbg("*****DQBUF[%d] FINISH*****", buf.index) else { - camera_err("****DQBUF FAIL %d*****\n",ret); + camera_err("****DQBUF FAIL*****"); return -2; } if (ioctl(videofd, VIDIOC_QBUF, &buf) == 0) - camera_dbg("************QBUF[%d] FINISH buffer size:%d**************\n", buf.index,buf.length); + camera_dbg("************QBUF[%d] FINISH**************", buf.index) else { return -2; @@ -421,7 +449,7 @@ int HCamDevice::init_fd() if ((fd = open("/dev/mem", O_RDWR | O_SYNC)) < 0) { - camera_dbg("Cannot open /dev/mem \n"); + camera_dbg("Cannot open /dev/mem "); return -1; } memfd = fd; @@ -429,7 +457,7 @@ int HCamDevice::init_fd() map_base = mmap(NULL, AddrMapSize, PROT_READ | PROT_WRITE, MAP_SHARED, memfd, phyBaseAddr); if (map_base == NULL) { - camera_dbg("Cannot mmap addr \n"); + camera_dbg("Cannot mmap addr "); close(fd); return -1; } @@ -438,7 +466,7 @@ int HCamDevice::init_fd() if ((fd = open(subDeviceName.c_str(), O_RDWR, 0)) == -1) { - camera_dbg("t Cam Cannot open subdevice file\n"); + camera_dbg("t Cam Cannot open subdevice file"); return -1; } subDevicefd = fd; @@ -458,14 +486,14 @@ int HCamDevice::init_sample() ret = ioctl(subDevicefd, VIDIOC_SUBDEV_S_FMT, &subdev_fmt); if (ret < 0) - printf("VIDIOC_SUBDEV_S_FMT failed.\n"); + printf("VIDIOC_SUBDEV_S_FMT failed."); struct v4l2_event_subscription sub; memset(&sub, 0, sizeof(sub)); sub.type = V4L2_EVENT_HTCAMMOD_OVERFREP; ret = ioctl(subDevicefd, VIDIOC_SUBSCRIBE_EVENT, &sub); if (ret < 0) - printf("VIDIOC_SUBSCRIBE_EVENT failed.\n"); + printf("VIDIOC_SUBSCRIBE_EVENT failed."); return ret; } @@ -497,12 +525,12 @@ int HCamDevice::init_device() int ioctlRet = ioctl(videofd, VIDIOC_S_FMT, &fmt) ; if ( ioctlRet < 0) { - camera_err("error %s\n" , strerror(errno)); - camera_err(" setting the data format failed!width %d height %d planes %d \n" , fmt.fmt.pix_mp.width,fmt.fmt.pix_mp.height , fmt.fmt.pix_mp.num_planes ); - camera_print(" fmt.type = %d\n", fmt.type); - camera_print(" fmt.fmt.pix.width = %d\n", fmt.fmt.pix_mp.width); - camera_print(" fmt.fmt.pix.height = %d\n", fmt.fmt.pix_mp.height); - camera_print(" fmt.fmt.pix.field = %d\n", fmt.fmt.pix_mp.field); + camera_err("error %s" , strerror(errno)); + camera_err(" setting the data format failed!width %d height %d planes %d " , fmt.fmt.pix_mp.width,fmt.fmt.pix_mp.height , fmt.fmt.pix_mp.num_planes ); + camera_print(" fmt.type = %d", fmt.type); + camera_print(" fmt.fmt.pix.width = %d", fmt.fmt.pix_mp.width); + camera_print(" fmt.fmt.pix.height = %d", fmt.fmt.pix_mp.height); + camera_print(" fmt.fmt.pix.field = %d", fmt.fmt.pix_mp.field); // close(videofd); return -1; } @@ -510,33 +538,33 @@ int HCamDevice::init_device() if (drivertype == V4L2_CAP_VIDEO_CAPTURE_MPLANE) { if (v4lWidth != fmt.fmt.pix_mp.width || v4lHeight != fmt.fmt.pix_mp.height) - camera_err(" does not support %u * %u\n", v4lWidth, v4lHeight); + camera_err(" does not support %u * %u", v4lWidth, v4lHeight); v4lWidth = fmt.fmt.pix_mp.width; v4lHeight = fmt.fmt.pix_mp.height; - camera_print(" VIDIOC_S_FMT succeed\n"); - camera_print(" fmt.type = %d\n", fmt.type); - camera_print(" fmt.fmt.pix.width = %d\n", fmt.fmt.pix_mp.width); - camera_print(" fmt.fmt.pix.height = %d\n", fmt.fmt.pix_mp.height); - camera_print(" fmt.fmt.pix.field = %d\n", fmt.fmt.pix_mp.field); + camera_print(" VIDIOC_S_FMT succeed"); + camera_print(" fmt.type = %d", fmt.type); + camera_print(" fmt.fmt.pix.width = %d", fmt.fmt.pix_mp.width); + camera_print(" fmt.fmt.pix.height = %d", fmt.fmt.pix_mp.height); + camera_print(" fmt.fmt.pix.field = %d", fmt.fmt.pix_mp.field); if (ioctl(videofd, VIDIOC_G_FMT, &fmt) < 0) - camera_err(" get the data format failed!\n"); + camera_err(" get the data format failed!"); nplanes = fmt.fmt.pix_mp.num_planes; } else { if (v4lWidth != fmt.fmt.pix.width || v4lHeight != fmt.fmt.pix.height) - camera_err(" does not support %u * %u\n", v4lWidth, v4lHeight); + camera_err(" does not support %u * %u", v4lWidth, v4lHeight); v4lWidth = fmt.fmt.pix.width; v4lHeight = fmt.fmt.pix.height; - camera_print(" VIDIOC_S_FMT succeed\n"); - camera_print(" fmt.type = %d\n", fmt.type); - camera_print(" fmt.fmt.pix.width = %d\n", fmt.fmt.pix.width); - camera_print(" fmt.fmt.pix.height = %d\n", fmt.fmt.pix.height); - camera_print(" fmt.fmt.pix.field = %d\n", fmt.fmt.pix.field); + camera_print(" VIDIOC_S_FMT succeed"); + camera_print(" fmt.type = %d", fmt.type); + camera_print(" fmt.fmt.pix.width = %d", fmt.fmt.pix.width); + camera_print(" fmt.fmt.pix.height = %d", fmt.fmt.pix.height); + camera_print(" fmt.fmt.pix.field = %d", fmt.fmt.pix.field); } CLEAR(ctrl); @@ -544,7 +572,7 @@ int HCamDevice::init_device() ctrl.value = (1 << 2); // XVIP_LOW_LATENCY_DISABLE if (ioctl(videofd, VIDIOC_S_CTRL, &ctrl) < 0) { - camera_err("Fail to set control:%s.\n", strerror(errno)); + camera_err("Fail to set control:%s.", strerror(errno)); } init_video_buffer(); return 0; @@ -563,13 +591,13 @@ int HCamDevice::init_video_buffer() req.memory = v4l2memtype; if (ioctl(videofd, VIDIOC_REQBUFS, &req) < 0) { - camera_err(" VIDIOC_REQBUFS failed\n"); + camera_err(" VIDIOC_REQBUFS failed"); close(videofd); return -1; } v4lBufferCount = req.count; - camera_dbg(" reqbuf number is %d\n", v4lBufferCount); + camera_dbg(" reqbuf number is %d", v4lBufferCount); if (captureBufers != NULL) free(captureBufers); @@ -593,7 +621,7 @@ int HCamDevice::init_video_buffer() if (ioctl(videofd, VIDIOC_QUERYBUF, &buf) == -1) { - camera_err(" VIDIOC_QUERYBUF error\n"); + camera_err(" VIDIOC_QUERYBUF error"); if (drivertype == V4L2_CAP_VIDEO_CAPTURE_MPLANE) free(buf.m.planes); free(captureBufers); @@ -611,7 +639,7 @@ int HCamDevice::init_video_buffer() MAP_SHARED, videofd, buf.m.planes[0].m.mem_offset); - camera_dbg(" map buffer index: %d, mem: %p, len: %x, offset: %x\n", + camera_dbg(" map buffer index: %d, mem: %p, len: %x, offset: %x", n_buffers, captureBufers[n_buffers].start, buf.m.planes[0].length, buf.m.planes[0].m.mem_offset); free(buf.m.planes); @@ -624,7 +652,7 @@ int HCamDevice::init_video_buffer() PROT_READ /*| PROT_WRITE*/, MAP_SHARED, videofd, buf.m.offset); - camera_dbg(" map buffer index: %d, mem: %p, len: %x, offset: %x\n", + camera_dbg(" map buffer index: %d, mem: %p, len: %x, offset: %x", n_buffers, captureBufers[n_buffers].start, buf.length, buf.m.offset); } } diff --git a/JsonConfig.cpp b/JsonConfig.cpp index 57bc0f8..cac627f 100644 --- a/JsonConfig.cpp +++ b/JsonConfig.cpp @@ -144,7 +144,6 @@ ScannerScanInfo JsonConfig::GetScanInfo() std::ifstream i(SCANNER_SCAN_INFO_PATH); auto pos = i.tellg(); i.seekg(0, ios::end); - cout << "file length =" << i.tellg() << endl; if(i.tellg()<=2) { printf("/usr/local/huago/jsonconfig.json file size < 2!\n"); diff --git a/JsonConfig.h b/JsonConfig.h index 23328a1..8176522 100644 --- a/JsonConfig.h +++ b/JsonConfig.h @@ -6,7 +6,7 @@ #include #include -#define SCANNER_SCAN_INFO_PATH "/usr/local/huago/jsonconfig.json" +#define SCANNER_SCAN_INFO_PATH "/mnt/conf-disk/huago/jsonconfig.json" using namespace std; using json = nlohmann::json; class JsonConfig diff --git a/MotorConfig.h b/MotorConfig.h index eed0e01..2c41909 100644 --- a/MotorConfig.h +++ b/MotorConfig.h @@ -6,10 +6,10 @@ using json= nlohmann::json; #ifndef WIN32 -#define MT_DRV888_CUO_PATH "/usr/local/huago/drv888_cuo.json" -#define MT_DRV888_ZOU_PATH "/usr/local/huago/drv888_zou.json" -#define MT_TMC216_CUO_PATH "/usr/local/huago/tmc216_cuo.json" -#define MT_TMC216_ZOU_PATH "/usr/local/huago/tmc216_zou.json" +#define MT_DRV888_CUO_PATH "/mnt/conf-disk/huago/drv888_cuo.json" +#define MT_DRV888_ZOU_PATH "/mnt/conf-disk/huago/drv888_zou.json" +#define MT_TMC216_CUO_PATH "/mnt/conf-disk/huago/tmc216_cuo.json" +#define MT_TMC216_ZOU_PATH "/mnt/conf-disk/huago/tmc216_zou.json" #else #define MT_DRV888_CUO_PATH "drv888_cuo.json" #define MT_DRV888_ZOU_PATH "drv888_zou.json" diff --git a/MultiFrameCapture.cpp b/MultiFrameCapture.cpp index c2a3f43..cd4da92 100644 --- a/MultiFrameCapture.cpp +++ b/MultiFrameCapture.cpp @@ -253,17 +253,19 @@ void MultiFrameCapture::UpdateScanParam(HG_ScanConfiguration config) FILE *f_img; if (m_config.params.isColor == 1) // color - f_img = fopen("/home/root/color.jpg", "rb"); + f_img = fopen("/home/root/color.bmp", "rb"); else - f_img = fopen("/home/root/gray.jpg", "rb"); + f_img = fopen("/home/root/gray.bmp", "rb"); if (f_img == nullptr) printf("!!!!!!!!!! error while reading image \r\n"); fseek(f_img, 0, SEEK_END); m_test_pimg_len = ftell(f_img); - m_test_pimg = malloc(m_test_pimg_len); - //printf("!!!!!!!!!! info: reading image len = %d m_test_pimg = %p \r\n", f_len, m_test_pimg); + m_test_pimg = (unsigned char*)malloc(m_test_pimg_len); + fseek(f_img, 0, SEEK_SET); + fread(m_test_pimg,1,m_test_pimg_len,f_img); + printf("!!!!!!!!!! info: reading image len = %d m_test_pimg = %p \r\n", m_test_pimg_len, m_test_pimg); fclose(f_img); #endif } diff --git a/MultiFrameCapture.h b/MultiFrameCapture.h index 727963e..83b31ce 100644 --- a/MultiFrameCapture.h +++ b/MultiFrameCapture.h @@ -55,7 +55,7 @@ private: int expStep[2][3]; double radio = 1; #ifdef TEST_SIMCAP - void* m_test_pimg; + unsigned char* m_test_pimg; unsigned int m_test_pimg_len; #endif CamZ_Reg_4 reg_; diff --git a/UsbScanner.cpp b/UsbScanner.cpp index bfcd354..821b518 100644 --- a/UsbScanner.cpp +++ b/UsbScanner.cpp @@ -2,6 +2,8 @@ #include #include "JsonConfig.h" #include "USBProtocol.h" +#include "filetools.h" +#include "logs_out.h" #define USB_REQ_GET_FPGA_REGS 0x40 #define USB_REQ_SET_FPGA_REGS 0x41 @@ -30,9 +32,8 @@ UsbScanner::UsbScanner() : m_startscan(false), { DeviceExport(); m_serial = ("G20018000298OO"); - m_fwversion = ("12345613"); + m_fwversion = ("1234561300"); mount_usb_device(); - printf("mount usb ing \n"); auto ctrl_req_handler = [&](int fd, struct usb_ctrlrequest *setup, unsigned char *buffer) -> bool { if (!(setup->bRequestType & USB_TYPE_VENDOR) || (setup->bRequestType & USB_RECIP_MASK) != USB_RECIP_DEVICE) @@ -99,60 +100,6 @@ UsbScanner::UsbScanner() : m_startscan(false), return true; } break; - - // case USB_REQ_GET_DEV_REGS: - // if ((setup->bRequestType & USB_DIR_IN) && creg && this->devregs) - // { - // if (!read_regs(regs, regindex, creg, this->devregs)) - // return false; - // ::write(fd, buffer, setup->wLength); - // return true; - // } - // break; - // case USB_REQ_SET_DEV_REGS: - // if (!(setup->bRequestType & USB_DIR_IN) && creg && this->devregs) - // { - // ::read(fd, buffer, setup->wLength); - // if (!write_regs(regs, regindex, creg, this->devregs)) - // return false; - // return true; - // } - // break; - // case USB_REQ_ACCES_DEV_LOG: - // if (setup->wLength != 64) - // return false; - - // if (!(setup->bRequestType & USB_DIR_IN)) - // { - // ::read(fd, buffer, setup->wLength); - // buffer[64 - 1] = 0; - // logstring = (char *)buffer; - // return true; - // } - // else - // { - // memset(buffer, 0, 64); - // if (!logstring.empty()) - // memcpy(buffer, logstring.data(), logstring.size()); - // ::write(fd, buffer, setup->wLength); - // return true; - // } - // break; - - // case USB_REQ_GET_DEV_LOG: - // if ((setup->wLength == 4) && (setup->bRequestType & USB_DIR_IN) && log_get_level(logstring, regindex, *((int *)regs))) - // { - // ::write(fd, buffer, setup->wLength); - // return true; - // } - // break; - // case USB_REQ_SET_DEV_LOG: - // if ((setup->wLength == 4) && !(setup->bRequestType & USB_DIR_IN)) - // { - // ::read(fd, buffer, setup->wLength); - // return log_set_level(logstring, regindex, *((int *)regs)); - // } - // break; default: break; } @@ -162,11 +109,19 @@ UsbScanner::UsbScanner() : m_startscan(false), auto hotplug_handler = [&](bool isconnect) { - LOG("usb hotplug_handler is connect : %s \n", isconnect ? "true" : "false"); + printf("usb hotplug_handler is connect : %s \n", isconnect ? "true" : "false"); }; m_usb.reset(new UsbDevice(ctrl_req_handler, hotplug_handler)); - // m_usb.get(); + StopWatch sw; + while (!m_usb->is_connected()) + { + if(sw.elapsed_ms() >= 1000.0) + break; + + std::this_thread::sleep_for(std::chrono::milliseconds(2)); + } + PRINT_MSG("!!!!!!!!!!time eplased :%.2f ",sw.elapsed_ms()); auto imageready = [this](const HG_JpegCompressInfo &imageinfo) { imageremain++; @@ -177,11 +132,8 @@ UsbScanner::UsbScanner() : m_startscan(false), auto deviceevent = [this](const int eventID, std::string capmsg) { { - LOG("\n 222222222 Enqueue event %d \n", eventID); + LOG("\n 222222222 Enqueue event %d \n", eventID); eventsramain++; - // unsigned char buff[64]={0}; - - //printf("--------------------------66 = %d\r\n",eventsramain); m_scannerEvents.Put({eventID, capmsg}); if (eventID == (int)HG_ScannerStatus::STOP_SCAN) { @@ -195,7 +147,6 @@ UsbScanner::UsbScanner() : m_startscan(false), else if ((eventID == (int)HG_ScannerStatus::SIZE_ERROR) || (eventID == (int)HG_ScannerStatus::PAPER_HOLE)) { m_hgScanner->StopScan(0); - // m_usb-> } } }; @@ -526,6 +477,7 @@ void UsbScanner::mount_usb_device() { if ((access("/dev/ffs-camtp/ep0", F_OK)) != -1) return; + int result = system("modprobe libcomposite\n \ mkdir /var/cfg\n \ mount none /var/cfg -t configfs\n \ @@ -545,4 +497,6 @@ void UsbScanner::mount_usb_device() ln -s functions/ffs.camtp configs/c.1\n \ mkdir /dev/ffs-camtp\n \ mount -t functionfs camtp /dev/ffs-camtp"); + + //printf("!!!!!!!!!!!!!!!!!!!modprobe libcomposite done \n"); } \ No newline at end of file diff --git a/UsbScanner.h b/UsbScanner.h index 309ffe0..b0b87a1 100644 --- a/UsbScanner.h +++ b/UsbScanner.h @@ -4,6 +4,7 @@ #include #include "FsmState.h" #include "usbdevice.h" + using namespace std; class UsbScanner : public IScanner @@ -52,4 +53,5 @@ private: bool m_startscan; volatile int imageremain; volatile int eventsramain; + std::condition_variable t_waitconnect; }; \ No newline at end of file diff --git a/ZouZhiMotor.cpp b/ZouZhiMotor.cpp index cef8226..3e46bcb 100644 --- a/ZouZhiMotor.cpp +++ b/ZouZhiMotor.cpp @@ -4,7 +4,8 @@ ZouZhiMotor::ZouZhiMotor() : Motor(motorPorts_Zouzhi) { - auto t_smbtype = smbtype == SMBType::MB_DRV_TMC216 ? MotorConfig::MTBDType::MT_TMC : MotorConfig::MTBDType::MT_DRV; + //auto t_smbtype = smbtype == SMBType::MB_DRV_TMC216 ? MotorConfig::MTBDType::MT_TMC : MotorConfig::MTBDType::MT_DRV; + auto t_smbtype = MotorConfig::MTBDType::MT_TMC; m_zouparamex = m_mtconfig->GetMotorSpeedParam(true, t_smbtype, 4, 1, 1); speedConfig(); } @@ -21,8 +22,9 @@ void ZouZhiMotor::start() void ZouZhiMotor::speedChange(int speed, int dpi, int colormode) // speed should be in range [0,5] (by ply,at 2019.5.23) { - auto t_smbtype = smbtype == SMBType::MB_DRV_TMC216 ? MotorConfig::MTBDType::MT_TMC : MotorConfig::MTBDType::MT_DRV; - m_zouparamex = m_mtconfig->GetMotorSpeedParam(true, t_smbtype, 4, colormode, dpi); + //auto t_smbtype = smbtype == SMBType::MB_DRV_TMC216 ? MotorConfig::MTBDType::MT_TMC : MotorConfig::MTBDType::MT_DRV; + auto t_smbtype = MotorConfig::MTBDType::MT_TMC; + m_zouparamex = m_mtconfig->GetMotorSpeedParam(true, t_smbtype, speed, colormode, dpi); speedConfig(); } diff --git a/logs_out.h b/logs_out.h index 1c4dca5..b55ebd4 100755 --- a/logs_out.h +++ b/logs_out.h @@ -89,7 +89,7 @@ void timestamp(char * timestr, int maxsize); ## args); \ fflush(stdout); \ } -#define DEBUG +//#define DEBUG #ifdef DEBUG #define PRINT_DEBUG(fmt, args...) { \ char timestr[32]; \ diff --git a/main.cpp b/main.cpp index 63d1a1d..bcbd51e 100644 --- a/main.cpp +++ b/main.cpp @@ -9,7 +9,7 @@ #include "FpgaComm.h" #include "FsmState.h" #include "Scanner.h" -#include "filetools.h" +// #include "filetools.h" #include #include #include @@ -28,6 +28,9 @@ #include "USBProtocol.h" #include "MotorConfig.h" #include + +#include "usbdevice.h" + using json = nlohmann::json; using namespace std; @@ -198,153 +201,6 @@ int menu() return choice; } -void list_regs(std::shared_ptr ®s) -{ - StopWatch sw; - unsigned int val; - for (int i = 0; i < 0x10; i++) - { - sw.reset(); - val = 0; - // if (regs->read(i)) - std::cout << string_format("reg[0x%d] =0x%08x, read elapsed: %f\n", i, regs->read(i), sw.elapsed_ms()); - // else - // std::cout << string_format("reg[0x%d] read error\n", i); - } -} - -void test_regs(std::shared_ptr ®s) -{ - StopWatch sw; - unsigned int val; - for (int i = 0; i < 1; i++) - { - sw.reset(); - regs->setFrameHeight(i); - { - std::cout << string_format("reg[0x%d] =0x%08x, write elapsed: %f\n", 0, i, sw.elapsed_ms()); - auto height = regs->getFrameHeight(); - if (height == i) - std::cout << string_format("reg[0x%d] =0x%08x, read elapsed: %f\n", 0, height, sw.elapsed_ms()); - else - std::cout << string_format("reg[0x%d] read error\n", 0); - } - } -} - -void JsonTest() -{ - MotorConfig cfg; - // std::shared_ptr fpgauart=std::make_shared(); - // int option; - // bool exit = false; - // for (;;) - // { - // option = menu(); - // switch (option) - // { - // case 0: - // exit = true; - // break; - // case 1: - // { - // std::cout << "cap regs list:" << std::endl; - // list_regs(fpgauart); - // } - // break; - // break; - // case 2: - // test_regs(fpgauart); - // break; - // default: - // std::cout << "Please select again! \n" << endl; - // break; - // } - // /* code */ - // if (exit) - // break; - // } - - // std::cout << "exit munu"; - // cout << " **** Menu **** " << endl - // << endl; - // cout << " color mode (0/1 gray/color)." << endl; - // cout << " dpi mode (1/2/3 200 300 600DPI)" << endl; - // cout << "default args 0 2,means 300dpi gray mode capturer " << endl - // << endl; - // cout << " Enter color mode :" << endl; - // int color, dpi; - // cin >> color; - // if (color != 0 && color != 1) - // color = 0; - // cout << " Enter dpi mode :" << endl; - // cin >> dpi; - // if (dpi != 1 && dpi != 2 && dpi != 3) - // dpi = 2; - // printf("Captuer Param info: color mode = %s dpi = %s \n", color == 0 ? "Gray" : "Color", dpi == 1 ? "200" : (dpi == 2 ? "300" : "600")); - // Capturer cap(nullptr, nullptr); - // HG_ScanConfiguration config = {0}; - // config.params.dpi = dpi; - // config.params.isColor = color; - // config.params.pageSize = 2; - - // for (int i = 0; i < 1000; i++) - // { - // config.params.isColor = i%2==0?1:0; - // cap.UpdateScanParam(config); - // cap.open(); - // for (int j = 0; j < 2; j++) - // { - // auto data = cap.readFrameTest(2000); - // if (data == nullptr) - // { - // printf("Read frame error! \n"); - // } - // else - // { - // printf("Read Frame success! \n"); - // } - // } - // printf("Try to close index %d of 1000,cap %d images \n",i+1,(i+1)*2); - // cap.close(); - // } - // ScannerSysInfo info={ - // .CPU = SCPU::CPU_3288, - // .Systype = SysType::Sys_Linux_Debian, - // .Screentype = ScreenType::ST_None, - // .MtBoardVersion = 0x20220114, - // .MtType = SMBType::MB_DRV_8825, - // .FPGAVersion = 0x00090001, - // .Cistype = HGCISType::CIS_DUNNAN_MONO_V0, - // .ResSup = {200,300,0}, - // .MemTotal = 0, - // .DiskTotal = 100, - // .DiskUsed = 0, - // .KernelVersion ="", - // .Have_EthernPort = 0, - // .ServiceVersion = "G470220114", - // .UsbProtocol = 1.1f - // }; - // SysInforTool infortool(info); - // auto in= infortool.GetSysInfo(); - // printf("%s \n",in.c_str()); -} - -void initusb() -{ - // m_usb.reset(new HGUsb()); - // if (!m_usb.get()) - // LOG("init m_usb failed low memory \n"); - // if (m_usb.get()) - // { - // int ret = m_usb->open(); - // if (ret != (int)HGUSB_ErrorCode::HG_USBSuccess) - // { - // LOG("USB Open fialed start while loop to waitting for open success\n"); - // } - // } -} - void initscanner() { m_scanner.reset(new UsbScanner()); @@ -375,19 +231,10 @@ int main(int argc, char *argv[]) exit(-1); } - JsonTest(); - // return 0; - // while(1) {std::this_thread::sleep_for(std::chrono::milliseconds(1));} - initusb(); init_get_CISType_GPIO(); initscanner(); start_enter_lowpwoer(); - // m_scanner->StartScan(1); - // return 0; - // while(1) - // { - std::this_thread::sleep_for(std::chrono::seconds(10)); - // } + if (argc == 2) { int t_arg1 = atoi(argv[1]); @@ -405,17 +252,19 @@ int main(int argc, char *argv[]) LOG("onboard unkown command!\n"); } } + while (b_runloop) { + if (!m_scanner->is_connect()) { - LOG("USB DISCONNECT DISCONNECT DISCONNECT DISCONNECT DISCONNECT DISCONNECT DISCONNECT\n"); + printf("USB DISCONNECT DISCONNECT DISCONNECT DISCONNECT DISCONNECT DISCONNECT DISCONNECT\n"); b_runloop = false; m_scanner->StopScan(); - // stop_countdown(); + stop_countdown(); break; } - + USBCB usbcb = {0}; m_scanner->read_bulk(&usbcb, sizeof(usbcb)); if (usbcb.Command == 0) @@ -906,4 +755,4 @@ int main(int argc, char *argv[]) LOG("scanservice exit \n"); writesyslog(LOG_INFO, "usb disconnect! scanservices exit now"); return 0; -} +} \ No newline at end of file diff --git a/scanservices_utils.h b/scanservices_utils.h index d30db9d..31151b0 100644 --- a/scanservices_utils.h +++ b/scanservices_utils.h @@ -28,7 +28,7 @@ using namespace std; //#define TEST_MODE //#define __DEBUG__ -#define _LOG +//#define _LOG #define IMAGE_COLOR 1 diff --git a/usbdevice.cpp b/usbdevice.cpp index 433cb5e..78d745d 100755 --- a/usbdevice.cpp +++ b/usbdevice.cpp @@ -317,11 +317,11 @@ UsbDevice::UsbDevice(std::function /var/cfg/usb_gadget/g1/UDC")"); get_system_output(R"(echo root:root | sh -c "ls /sys/class/udc/ > /var/cfg/usb_gadget/g1/UDC")"); - - ctrl_handler = handler; #ifdef AIO_BULK_TRANSFER aio_event_thread = std::move(std::thread(&UsbDevice::aio_event_poll, this)); #endif @@ -775,7 +775,7 @@ void UsbDevice::usb_main() { usb_ctx = init_usb_camtp_gadget(camtp_context.get()); // get_system_output(R"(echo petalinux:petalinux | sudo -S sh -c "chmod 777 /dev/ffs-camtp -R")"); - get_system_output(R"(echo petalinux:petalinux | sh -c "chmod 777 /dev/ffs-camtp -R")"); + get_system_output(R"(echo root:root | sh -c "chmod 777 /dev/ffs-camtp -R")"); if (usb_ctx) { @@ -822,7 +822,7 @@ int UsbDevice::handle_ffs_ep0(usb_gadget * ctx) struct usb_functionfs_event event; int status; - PRINT_DEBUG("handle_ffs_ep0 : Entering..."); + PRINT_MSG("handle_ffs_ep0 : Entering... ctx->stop = %d \n",ctx->stop); timeout.tv_sec = 20; timeout.tv_usec = 0; @@ -843,14 +843,14 @@ int UsbDevice::handle_ffs_ep0(usb_gadget * ctx) if(ctx->wait_connection && ret == 0 ) continue; - + PRINT_MSG("Select ret = %d ",ret); if( ret <= 0 ) return ret; timeout.tv_sec = 0; ret = read(ctx->usb_device, &event, sizeof(event)); - + PRINT_MSG("read(ctx->usb_device ret = %d ",ret); if (ret < 0) { PRINT_ERROR("handle_ffs_ep0 : Read error %d (%m)", ret); @@ -859,14 +859,15 @@ int UsbDevice::handle_ffs_ep0(usb_gadget * ctx) nevents = ret / sizeof(event); - PRINT_DEBUG("%d event(s)", nevents); + PRINT_MSG("%d event(s)", nevents); for (i=0; iep_path[index],index); + PRINT_MSG("Init end point %s (%d)",ctx->ep_path[index],index); fd = open(ctx->ep_path[index], O_RDWR); if ( fd <= 0 ) { - PRINT_ERROR("init_ep : Endpoint %s (%d) init failed ! : Can't open the endpoint ! (error %d - %m)",ctx->ep_path[index],index,fd); + PRINT_MSG("init_ep : Endpoint %s (%d) init failed ! : Can't open the endpoint ! (error %d - %m)",ctx->ep_path[index],index,fd); goto init_ep_error; } diff --git a/utilsfunc.cpp b/utilsfunc.cpp index 8cabb0a..2b80133 100644 --- a/utilsfunc.cpp +++ b/utilsfunc.cpp @@ -358,15 +358,15 @@ std::string getmeminfo() void start_enter_lowpwoer() { #ifdef ENABLE_LOWPOWERMODE - int seconds=900; - auto scaninfo= js_config.GetScanInfo(); - if(scaninfo.SleepTime<0||scaninfo.SleepTime<180) - seconds=180; - else - seconds=scaninfo.SleepTime; - std::string str="sh /etc/countdown.sh start 0 0 "+std::to_string(seconds)+" &"; - LOG("start_enter_lowpwoer %s \n",str.c_str()); - system(str.c_str()); + // int seconds=900; + // auto scaninfo= js_config.GetScanInfo(); + // if(scaninfo.SleepTime<0||scaninfo.SleepTime<180) + // seconds=180; + // else + // seconds=scaninfo.SleepTime; + // std::string str="sh /etc/countdown.sh start 0 0 "+std::to_string(seconds)+" &"; + // LOG("start_enter_lowpwoer %s \n",str.c_str()); + // system(str.c_str()); #endif }