1. 增加.gitignore 文件;

2. 调整cmakelist编译体系文件,采用相对路径,解决编译链接找不到库的问题;
3.调整配置文件读取路径。现调整为/mnt/conf-disk/huago目录
4.解决USB挂载问题,诱因USB挂载前打印消息中含有“\n”,调整挂载部分代码;
5. 解决测试过程中电机走纸速度慢问题,诱因电机板类型初始化不正确;
6. 删除部分无用代码以及调整打印日志;
7. 解决模拟数据验证整机稳定性部分测试代码bug;
This commit is contained in:
modehua 2023-07-19 02:17:07 -07:00
parent 355b44018a
commit 79db30f554
18 changed files with 168 additions and 346 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
./build/*

View File

@ -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/
)

View File

@ -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"

View File

@ -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();
}

View File

@ -16,6 +16,8 @@
//#include "camconfig.h"
#include <iostream>
#include <errno.h>
#include "logs_out.h"
#define ADC_82V48
@ -24,14 +26,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*)&timestr, sizeof(timestr)); \
fprintf(stdout, \
"[HCamDevice - %s - Info] " fmt "\n",(char*)&timestr, \
## args); \
fflush(stdout); \
}
#define camera_dbg(fmt, args...) { \
char timestr[32]; \
timestamp((char*)&timestr, sizeof(timestr)); \
fprintf(stdout, \
"[HCamDevice - %s - Info] " fmt "\n",(char*)&timestr, \
## args); \
fflush(stdout); \
}
#define camera_err(fmt, args...) { \
char timestr[32]; \
timestamp((char*)&timestr, sizeof(timestr)); \
fprintf(stdout, "[HCamDevice - %s - Info] " fmt "\n",(char*)&timestr, \
## args); \
fflush(stdout); \
}
#define CLEAR(x) memset(&(x), 0, sizeof(x))
@ -94,7 +123,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));
@ -304,15 +333,15 @@ int HCamDevice::HtCamReadCaptureFrame(void **pbuf, int timeout)
}
if (ioctl(videofd, VIDIOC_DQBUF, &buf) == 0)
camera_dbg("*****DQBUF[%d] FINISH*****\n", buf.index);
camera_dbg("*****DQBUF[%d] FINISH*****", buf.index)
else
{
camera_err("****DQBUF FAIL*****\n");
camera_err("****DQBUF FAIL*****");
return -2;
}
if (ioctl(videofd, VIDIOC_QBUF, &buf) == 0)
camera_dbg("************QBUF[%d] FINISH**************\n", buf.index);
camera_dbg("************QBUF[%d] FINISH**************", buf.index)
else
{
return -2;
@ -397,7 +426,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;
@ -405,7 +434,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;
}
@ -414,7 +443,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;
@ -434,14 +463,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;
}
@ -471,12 +500,12 @@ int HCamDevice::init_capture()
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;
}
@ -484,33 +513,33 @@ int HCamDevice::init_capture()
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);
@ -518,7 +547,7 @@ int HCamDevice::init_capture()
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));
}
return 0;
}
@ -536,13 +565,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);
@ -566,7 +595,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);
@ -584,7 +613,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);
@ -597,7 +626,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);
}
}

View File

@ -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");

View File

@ -6,7 +6,7 @@
#include <map>
#include <mutex>
#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

View File

@ -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"

View File

@ -89,7 +89,7 @@ void MultiFrameCapture::SetParent(void *scanner)
{
}
void MultiFrameCapture::open_video()
void MultiFrameCapture::open()
{
// reset_fpga();
m_capFpageregs->resetADC();
@ -248,17 +248,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
}
@ -339,7 +341,7 @@ void MultiFrameCapture::waitsnapdone(int state)
info.DataLength = m_test_pimg_len;
info.pJpegData = m_test_pimg;
m_glue.m_imageready(&info);
m_glue.m_imageready(info);
#else
printf("!!!!!!!!!!!!!!!! m_cv_snapdone wait \n");
V4L2_DATAINFO_Ex info;
@ -1116,24 +1118,10 @@ void MultiFrameCapture::openDevice(int dpi, int mode)
.selftest = 0,
.sp = fpgaparam.Sp}; // 600DPI 0x1450 300DPI 0xe10
// 2023 7-15 屏蔽
// m_capFpageregs->setRegs(0x01, *((int *)(&fpgamod)));
// m_capFpageregs->setSample(startsample);
// m_capFpageregs->setVsp(vsp_A, vsp_B);
// m_capFpageregs->enableLed(true);
// m_capFpageregs->setEnTestCol(false);
// m_capFpageregs->setEnTestBit(false);
// m_capFpageregs->setFrame_interval_max(static_cast<int>(sp_dst * 4 / (mode ? 1 : 3))); //dpi > 2 ? 7200 : 3600
// m_capFpageregs->setFrame_interval_min(static_cast<int>(sp_dst * 0.1 / (mode ? 1 : 3) )); //1540
.
// 2023 7-15 屏蔽
// m_capFpageregs->setFrame_interval_max(0x1010); //dpi > 2 ? 7200 : 3600
// m_capFpageregs->setFrame_interval_min(0xa98); //dpi > 2 ? 900 : 1540
configFPGAParam(mode, dpi);
configFPGAParam(mode, dpi);
StopWatch swwv4l2open;
// int ret = video->open_video(width, 60 * 2); // 300dpi 7344/2 600dpi 7344 //FRAME_HEIGHT * 2
int ret = video->open_video(); // 300dpi 7344/2 600dpi 7344 //FRAME_HEIGHT * 2
int ret = video->open_video(width, 60 * 2); // 300dpi 7344/2 600dpi 7344 //FRAME_HEIGHT * 2
//int ret = video->open(); // 300dpi 7344/2 600dpi 7344 //FRAME_HEIGHT * 2
if (ret < 0)
{
return;

View File

@ -54,7 +54,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_;

View File

@ -2,6 +2,8 @@
#include <turbojpeg.h>
#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");
}

View File

@ -4,6 +4,7 @@
#include <memory>
#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;
};

View File

@ -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();
}

View File

@ -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]; \

169
main.cpp
View File

@ -9,7 +9,7 @@
#include "FpgaComm.h"
#include "FsmState.h"
#include "Scanner.h"
#include "filetools.h"
// #include "filetools.h"
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
@ -28,6 +28,9 @@
#include "USBProtocol.h"
#include "MotorConfig.h"
#include <iomanip>
#include "usbdevice.h"
using json = nlohmann::json;
using namespace std;
@ -198,153 +201,6 @@ int menu()
return choice;
}
void list_regs(std::shared_ptr<FpgaComm> &regs)
{
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<FpgaComm> &regs)
{
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<FpgaComm> fpgauart=std::make_shared<FpgaComm>();
// 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,14 +252,16 @@ 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;
}

View File

@ -28,7 +28,7 @@ using namespace std;
//#define TEST_MODE
//#define __DEBUG__
#define _LOG
//#define _LOG
#define IMAGE_COLOR 1

View File

@ -317,11 +317,11 @@ UsbDevice::UsbDevice(std::function<bool(int, struct usb_ctrlrequest *, unsigned
{
camtp_context.reset(new camtp_ctx);
memset(camtp_context.get(), 0, sizeof(camtp_ctx));
ctrl_handler = handler;
std::this_thread::sleep_for(std::chrono::milliseconds(10));
thread_main = std::move(std::thread(&UsbDevice::usb_main, this));
// get_system_output(R"(echo petalinux:petalinux | sudo -S sh -c "ls /sys/class/udc/ > /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; i<nevents; i++)
{
PRINT_MSG("event.type = %d ", event.type);
switch (event.type)
{
case FUNCTIONFS_ENABLE:
PRINT_DEBUG("EP0 FFS ENABLE");
PRINT_MSG("FUNCTIONFS_ENABLE Usb Connect");
//!< nick usb on
b_connected = true;
if(connect_call)
@ -881,7 +882,8 @@ int UsbDevice::handle_ffs_ep0(usb_gadget * ctx)
break;
case FUNCTIONFS_DISABLE:
PRINT_DEBUG("EP0 FFS DISABLE");
PRINT_MSG("FUNCTIONFS_DISABLE Usb disconnect");
b_connected = false;
if(connect_call)
connect_call(b_connected);
@ -902,20 +904,20 @@ int UsbDevice::handle_ffs_ep0(usb_gadget * ctx)
break;
case FUNCTIONFS_SETUP:
PRINT_DEBUG("EP0 FFS SETUP");
PRINT_MSG("EP0 FFS SETUP");
handle_setup_request(ctx, &event.u.setup);
break;
case FUNCTIONFS_BIND:
PRINT_DEBUG("EP0 FFS BIND");
PRINT_MSG("EP0 FFS BIND");
break;
case FUNCTIONFS_UNBIND:
PRINT_DEBUG("EP0 FFS UNBIND");
PRINT_MSG("EP0 FFS UNBIND");
break;
case FUNCTIONFS_SUSPEND:
PRINT_DEBUG("EP0 FFS SUSPEND");
PRINT_MSG("EP0 FFS SUSPEND");
break;
case FUNCTIONFS_RESUME:
PRINT_DEBUG("EP0 FFS RESUME");
PRINT_MSG("EP0 FFS RESUME");
break;
}
}
@ -1164,11 +1166,11 @@ int UsbDevice::init_ep(usb_gadget * ctx,int index,int ffs_mode)
void * descriptor_ptr;
int descriptor_size;
PRINT_DEBUG("Init end point %s (%d)",ctx->ep_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;
}

View File

@ -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
}
@ -379,15 +379,15 @@ void stop_countdown()
void init_get_CISType_GPIO()
{
system("echo 190 > /sys/class/gpio/export");
system("echo in > /sys/class/gpio/gpio190/direction");
system("echo 191 > /sys/class/gpio/export");
system("echo in > /sys/class/gpio/gpio191/direction");
// system("echo 190 > /sys/class/gpio/export");
// system("echo in > /sys/class/gpio/gpio190/direction");
// system("echo 191 > /sys/class/gpio/export");
// system("echo in > /sys/class/gpio/gpio191/direction");
system("echo 233 > /sys/class/gpio/export");
system("echo in > /sys/class/gpio/gpio233/direction");
system("echo 234 > /sys/class/gpio/export");
system("echo in > /sys/class/gpio/gpio234/direction");
// system("echo 233 > /sys/class/gpio/export");
// system("echo in > /sys/class/gpio/gpio233/direction");
// system("echo 234 > /sys/class/gpio/export");
// system("echo in > /sys/class/gpio/gpio234/direction");
}
CISVendor GetCisType()