From 21dd8dfef41ee872285ac5026d8978e88eca7772 Mon Sep 17 00:00:00 2001 From: modehua Date: Fri, 17 Nov 2023 19:48:39 -0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zynq_7010_code/DevUtil.h | 58 +----- zynq_7010_code/FsmState.cpp | 3 +- zynq_7010_code/FsmState.h | 29 --- zynq_7010_code/ICapturer.h | 6 +- zynq_7010_code/MultiFrameCapture.cpp | 201 ++++++--------------- zynq_7010_code/MultiFrameCapture.h | 38 ++-- zynq_7010_code/PropertiesUtils.cpp | 95 ---------- zynq_7010_code/PropertiesUtils.h | 55 ------ zynq_7010_code/Scanner.cpp | 142 ++++----------- zynq_7010_code/Scanner.h | 10 +- zynq_7010_code/Sensor.cpp | 17 +- zynq_7010_code/USBProtocol.h | 224 ----------------------- zynq_7010_code/UsbScanner.cpp | 36 ++-- zynq_7010_code/UsbScanner.h | 2 +- zynq_7010_code/filetools.h | 158 ---------------- zynq_7010_code/main.cpp | 64 +------ zynq_7010_code/scanservices_utils.h | 260 ++++++++++++++++++++++++++- zynq_7010_code/utilsfunc.cpp | 230 +----------------------- 18 files changed, 413 insertions(+), 1215 deletions(-) delete mode 100644 zynq_7010_code/PropertiesUtils.cpp delete mode 100644 zynq_7010_code/PropertiesUtils.h delete mode 100644 zynq_7010_code/filetools.h diff --git a/zynq_7010_code/DevUtil.h b/zynq_7010_code/DevUtil.h index 304da95..c77838d 100644 --- a/zynq_7010_code/DevUtil.h +++ b/zynq_7010_code/DevUtil.h @@ -63,63 +63,7 @@ enum PIN_PORT_7010 MOTOR_POWER_1 = 64 + 901, //电机1 电源开关 MOTOR_POWER_2 = 65 + 901, //电机2 电源开关 }; -enum PORTS -{ - //Start = 171, - //Stop = 49, - //Power = 5, - Fpga_InitN = 7,//GPIO0_A7 - Fpga_Load = 8,//GPIO0_B7 -#ifndef G300 - Power_12v_Off = 12, -#endif - - //MotorPower = 48, - //CuoZhiMotor_Reset = 56, - //CuoZhiMotor_Sleep = 57, - //CuoZhiMotor_Enable = 58, - - //CuoZhiMotor_Direction = 62, - //CuoZhiMotor_Decay = 63, - //CuoZhiMotor_Home = 184, - //CuoZhiMotor_Fault = 185, - - //CuoZhiMotor_Mode0 = 59, - //CuoZhiMotor_Mode1 = 60, - //CuoZhiMotor_Mode2 = 61, - //Cover = 189,// 'GPIO6A5' opened:0 ; closed:1 - - //Paper = 225,// 'GPIO7B1' has paper:0 ; no paper:1 - //Scan = 226,// 'GPIO7B2' no paper:0 ; has paper:1 - //PaperJam = 102, - //Double_Paper = 219,// 'GPIO7A3' not doubled:0 ; doubled:1 - SW_NOR_FLASH = 221, - //Double_Enable = 250,// 'GPIO8A2' off: 0 ; on: 1 - - //ZouZhiMotor_Reset = 64, - //ZouZhiMotor_Sleep = 65, - //ZouZhiMotor_Enable = 66, - //ZouZhiMotor_Direction = 70, - - //ZouZhiMotor_Decay = 71, - //ZouZhiMotor_Home = 187, - //ZouZhiMotor_Fault = 188, - //ZouZhiMotor_Mode0 = 67, - - //ZouZhiMotor_Mode1 = 68, - //ZouZhiMotor_Mode2 = 69, - CIS_3v3_Off = 96, - CIS_5v_En = 98, - - Fpga_InitDone = 99, - Image_In_Transfer = 101, - Fpga_Reset = 232, - CIS_T_S0=190, - CIS_T_S1=191, - CIS_T_S2=234, - CIS_T_S3=233 -}; - + class DeviceExport { public: diff --git a/zynq_7010_code/FsmState.cpp b/zynq_7010_code/FsmState.cpp index e31aaa7..18b38b4 100644 --- a/zynq_7010_code/FsmState.cpp +++ b/zynq_7010_code/FsmState.cpp @@ -17,7 +17,6 @@ std::map> FsmStateManager::fsmStates; void StandbyState::initial() { printf("INIT FSM:扫描仪准备完成 \n"); - //typeName = "StandbyState"; scanner->getPanelLeds().setStatus(LedStatus::Ready); doReset(); } @@ -129,7 +128,7 @@ void ErrorJamState::doPaper_pullout() FsmState *ErrorJamState::on_event(ScanEvent event) { - //printf("ErrorJamState on_event %d \n", event); + printf("FSM :卡纸--->返回状态: %d \n",event); if (scanner->getSensor().isCoverClosed() && !scanner->getSensor().isPaperStandby() && !scanner->getSensor().isPaperIn()) { return FsmStateManagerEx::GetState(); diff --git a/zynq_7010_code/FsmState.h b/zynq_7010_code/FsmState.h index 5a4a567..b2a6562 100644 --- a/zynq_7010_code/FsmState.h +++ b/zynq_7010_code/FsmState.h @@ -9,35 +9,6 @@ class Scanner; -enum ScanEvent { - S_EVT_NORES = 0x0, - S_EVT_SCAN_FINISHED = 0x2, - S_EVT_CLEAR_ERR = 0x03, - S_EVT_PAPER_PULLOUT = 0x05, - S_EVT_COVER_OPENED = 0x01, - S_EVT_COVER_CLOSED = 0x102, - S_EVT_PAPER_AT_SCAN = 0x08, - S_EVT_PAPER_NOT_AT_SCAN = 0x106, - S_EVT_DOUBLEPAPER = 0x110, - S_EVT_NOT_DOUBLEPAPER = 0x111, - S_EVT_START_SCAN = 0x45, - S_EVT_STOP_SCAN = 0x46, - S_EVT_SCAN_STARTED = 0x112, - S_EVT_SCAN_STOPPED = 0x113, - S_EVT_JAM_IN = 0x114, - S_EVT_JAM_OUT = 0x115, - S_EVT_SAMPLE_ERR = 0x116, - S_EVT_COVER_IN_OPEN = 0x117, - S_EVT_ERROR_PICKING = 0x4, - S_EVT_ERROR_JAM = 0x8, - S_EVT_ERROR_DOUBLEPAPER = 0x10, - S_EVT_ERROR_STAPLE = 0x20, - S_EVT_ERROR_FPGA = 0x44, - S_EVT_HAVING_IMAGE = 0x47, - S_EVT_ONE_PAPER_END = 0x59, - S_EVT_PAPER_NOT_STANDBY = 0,//? - S_EVT_PAPER_STANDBY = 0 //? -}; class FsmState diff --git a/zynq_7010_code/ICapturer.h b/zynq_7010_code/ICapturer.h index e7f2c56..1b4c390 100644 --- a/zynq_7010_code/ICapturer.h +++ b/zynq_7010_code/ICapturer.h @@ -54,8 +54,12 @@ public: virtual void SetLowPower(bool islow) = 0; + virtual void set_image_callback(image_callback cb)= 0; + + virtual void wait_image_notify()= 0; + protected: - BlockingQueue m_v4l2data; std::shared_ptr video;//Capturer 类内部自己初始化 HG_ScanConfiguration m_config; + image_callback image_cb_; }; diff --git a/zynq_7010_code/MultiFrameCapture.cpp b/zynq_7010_code/MultiFrameCapture.cpp index b18aa8f..287849b 100644 --- a/zynq_7010_code/MultiFrameCapture.cpp +++ b/zynq_7010_code/MultiFrameCapture.cpp @@ -6,39 +6,27 @@ #include "CameraParam.h" #include "correct_ultis.h" -#include "filetools.h" + #include "USBProtocol.h" #include "utilsfunc.h" #include "CImageMerge.h" #include "Jpegcompress.h" #include "ThreadPool.h" #include "HCamDevice.h" +#include "StopWatch.h" const int vsp_A = 45; const int vsp_B = 45; #define ARRAYLEN(table) (sizeof(table) / sizeof(table[0])) // using namespace cv; -MultiFrameCapture::MultiFrameCapture(ScannerGlue glue) : - frame_count(1), - b_snap_run(true), - b_stop_snap(false), - b_imgproc(true), - m_glue(glue), - iImageremain(0), - bScanning(false), - +MultiFrameCapture::MultiFrameCapture(ScannerGlue glue) :b_snap_run(true),b_stop_snap(false), + m_glue(glue), bScanning(false), ////////////////默认300dpi 和灰度设置 - resolution_(DPI_300), - v4l2_width_(WIDTH), - v4l2_height_(HEIGHT), - pixels_width_(WIDTH), - fpga_height_(HEIGHT), + resolution_(DPI_300), v4l2_width_(WIDTH), + v4l2_height_(HEIGHT), pixels_width_(WIDTH), paper_size_((unsigned int)PaperSize::G400_AUTO), - color_mode_(GRAY), - is_correct_(0), - is_double_paper_(0), - is_remove_morr_(0), - m_cv_snap_is_scaning(false) + color_mode_(GRAY), is_correct_(0), + is_double_paper_(0), is_remove_morr_(0) { video.reset(new HCamDevice); video->HtCamSetdivder(true); @@ -46,34 +34,24 @@ MultiFrameCapture::MultiFrameCapture(ScannerGlue glue) : m_snap_thread.reset(new std::thread(&MultiFrameCapture::snaprun, this)); m_imgproc_thread.reset(new std::thread(&MultiFrameCapture::procimage, this)); } - MultiFrameCapture::~MultiFrameCapture() { if (video.get()) video.reset(); - m_frameinfos.Clear(); - m_frameinfos.ShutDown(); if (m_imgproc_thread.get()) { if (m_imgproc_thread->joinable()) { - b_imgproc = false; m_imgproc_thread->join(); } } -#ifdef TEST_SIMCAP - if (m_test_pimg) - free(m_test_pimg); -#endif } - void MultiFrameCapture::SetParent(void *scanner) { video->HtCamSetdivder(true); } - void MultiFrameCapture::open() { int ret = video->open_device(v4l2_width_,v4l2_height_); @@ -87,10 +65,8 @@ void MultiFrameCapture::open() i = video->HtCamReadCaptureFrame((void **)&buf, 10); } } - void MultiFrameCapture::snap() { -#ifndef TEST_SIMCAP std::lock_guard m_lock(m_mtx_snap); b_stop_snap = b_end_snap = false; @@ -102,31 +78,26 @@ void MultiFrameCapture::snap() this_thread::sleep_for(std::chrono::milliseconds(10)); video->HtCamStartVideoCapturing(); - m_cv_snap.notify_all(); -#endif } - void MultiFrameCapture::stopsnap(bool autosize) { if (autosize) { + printf("走纸已完成 等待图像采集完成\r\n"); video->HtCamStopSampling(); b_stop_snap = true; } } - void MultiFrameCapture::close() { if (video.get()) video->close_device(); } - int MultiFrameCapture::read(int addr) { } - void *MultiFrameCapture::readFrameTest(int timeout) { return nullptr; @@ -135,7 +106,6 @@ void MultiFrameCapture::SetLowPower(bool islow) { video->HtCamSetLowPower(islow); } - #include uint32_t MultiFrameCapture::compute_frame(int paper_size,int dpi) { @@ -177,8 +147,6 @@ void MultiFrameCapture::UpdateScanParam(HG_ScanConfiguration config) { return ; } - int config_dpi = config.params.dpi; - int config_color = config.params.isColor; resolution_ = config.params.dpi; //0:600dpi 1:300dpi config.params.dpi = 2||3 pc 1 代表200 2代表300 3代表600 color_mode_ = config.params.isColor; @@ -191,14 +159,13 @@ void MultiFrameCapture::UpdateScanParam(HG_ScanConfiguration config) video->HtCamSetPeriod(config.params.dc); - //int height = resolution_ == DPI_600 ? 342 : 900; int height = config.params.dpi == 3 ? 900 :(config.params.dpi == 2?999:300); compute_height(WIDTH , height); video->HtCamSetClolr(color_mode_); video->HtCamSetDpi(resolution_); - FPGAConfigParam fpgaparam = GetFpgaparam(config_dpi, config_color); + FPGAConfigParam fpgaparam = GetFpgaparam(resolution_, color_mode_); video->HtCamSetSpTime(fpgaparam.Sp,fpgaparam.MaxExp); //3通道 75 6通道49 if (color_mode_) { @@ -206,7 +173,7 @@ void MultiFrameCapture::UpdateScanParam(HG_ScanConfiguration config) } video->HtCamSetStSp(fpgaparam.MaxBright);//172 是根据实际测试出来的图像质量得来 172 6通道 3通道 260 - configFPGAParam(config_color, config_dpi); + configFPGAParam(color_mode_, resolution_); { int val = resolution_ == 3 ? 600 :(resolution_ == 2?300:200); @@ -245,17 +212,13 @@ void MultiFrameCapture::UpdateScanParam(HG_ScanConfiguration config) } } - - + //关于帧数设置:一定要注意帧数的数量 直接影响到你usb传输效率 uint32_t cnt = compute_frame(paper_size_ , val) ; - if (resolution_ == 2 && paper_size_ == (int)PaperSize::G400_A4) + if (resolution_ == 2) { cnt -=1 ; } - if (resolution_ == 3) - { - cnt += 2 ; - } + video->HtCamSetFrameCnt(cnt); printf(" -----------------------设置帧数:%d------------------\r\n",cnt); } @@ -264,12 +227,8 @@ void MultiFrameCapture::UpdateScanParam(HG_ScanConfiguration config) printf("分辨率:%d\r\n",resolution_); printf("V4L2宽: %d 高:%d\r\n",v4l2_width_,v4l2_height_); printf("像素宽:%d 高: %d\r\n",pixels_width_,pixels_height_); - printf("fpga_height_:%d\r\n", fpga_height_); - - printf("color_mode_:%d\r\n", color_mode_); printf("paper_size_:%d\r\n", paper_size_); } - void MultiFrameCapture::createCorrect(int correctmode) { if (m_correctThread.joinable()) @@ -277,25 +236,19 @@ void MultiFrameCapture::createCorrect(int correctmode) stop_countdown(); m_correctThread = std::thread(&MultiFrameCapture::correctcolor, this, correctmode); } - void MultiFrameCapture::setFPGATriggerMode(bool autotrigger, int delay) { } - void MultiFrameCapture::setFanMode(int mode) { } - void MultiFrameCapture::fpgaReload() -{ - +{ } - bool MultiFrameCapture::capturerImage() { return true; } - void MultiFrameCapture::waitsnapdone(int state) { StopWatch sw; @@ -324,33 +277,25 @@ void MultiFrameCapture::waitsnapdone(int state) b_end_snap = true; printf("!!!!!!!!!!!!!!!! m_cv_snapdone wait done :%f \n",sw.elapsed_ms()); } - bool MultiFrameCapture::IsImageQueueEmpty() { - //printf(" m_frameinfos.Size = %d iImageremain = %d bScanning = %d\n", m_frameinfos.Size(), iImageremain.operator int(), bScanning); - return (m_frameinfos.Size() == 0 && iImageremain == 0) && !bScanning; + return !bScanning; } - void MultiFrameCapture::resetimageremain() { - iImageremain = 0; + } - std::atomic_int &MultiFrameCapture::getimageremain() { return iImageremain; } - void MultiFrameCapture::clearimages() { - m_frameinfos.Clear(); } - void MultiFrameCapture::setScanFlag(bool brun) { bScanning = brun; } - void MultiFrameCapture::configFPGAParam(int mode, int dpi) { FPGAConfigParam fpgaparam = GetFpgaparam(dpi, mode); @@ -362,7 +307,6 @@ void MultiFrameCapture::configFPGAParam(int mode, int dpi) { video->HtCamWriteADCReg_ALL(true,true,i,fpgaparam.GainF[i]); video->HtCamWriteADCReg_ALL(false,true,i,fpgaparam.OffsetF[i]); - video->HtCamWriteADCReg_ALL(true,false,i,fpgaparam.GainB[i]); video->HtCamWriteADCReg_ALL(false,false,i,fpgaparam.OffsetB[i]); } @@ -372,10 +316,7 @@ void MultiFrameCapture::configFPGAParam(int mode, int dpi) // //video->HtCamReadADCReg_ALL(i); // } }; - #include "bmp.h" - - void MultiFrameCapture::snaprun() { //frame_info 发送得数据信息 channels 图像位深 num 需要取得帧数 time_out读图超时时间设置 @@ -384,38 +325,36 @@ void MultiFrameCapture::snaprun() StopWatch sw; sw.reset(); unsigned char *data = NULL; - //printf("设置超时时间:%d\r\n",time_out); + int ret = video->HtCamReadCaptureFrame((void **)&data, time_out); - int t = resolution_ == DPI_600 ? sw.elapsed_ms() + 600 : sw.elapsed_ms() + 20; - time_out = t; uint32_t sendLine = video->HtCamReadFpgaRegs(0x000e);////0x000e 取出来的实际行数 printf("--------------fpga send line ------------:%d\r\n",sendLine); if (data) { - - //cv::Mat mat = cv::Mat(info_ex.height, info_ex.width, CV_8UC1, data, cv::Mat::AUTO_STEP); - - // printf("获取数据 width:%d height:%d \r\n",info_ex.width,info_ex.height); - - //cv::imwrite("/home/root/test+_" + to_string(i)+".bmp", mat); - // printf("--------------frame_index------------:%d\r\n",frame_index); - if (i == 2) - { - // cv::imwrite("/home/root/test.bmp", mat); - //cv::imwrite("/home/root/test.bmp", mat); - //savebitmap(data,15552,512,"1.bmp"); - } - //info_ex.mat = mat.clone(); - - //JpegCompress cmp(90); - //HG_JpegCompressInfo info = cmp.GetCompressedImg(mat); + if (i == 1) + { + uint32_t cnt = 25; + if (paper_size_ != (unsigned int)PaperSize::G400_MAXSIZE && !is_remove_morr_) + { + int val = resolution_ == 3 ? 600 :(resolution_ == 2?300:200); + cnt = compute_frame((unsigned int)PaperSize::G400_AUTO , val) ; + cnt *=sw.elapsed_ms(); + } + else + cnt = (info_ex.frame_index + 1) * sw.elapsed_ms(); + + image_cb_(cnt); + img_wait_.notify_all(); + // cv::imwrite("/home/root/test.bmp", mat); + //cv::imwrite("/home/root/test.bmp", mat); + //savebitmap(data,15552,512,"1.bmp"); + } HG_JpegCompressInfo info ; info.pJpegData = data; - info.dpi = false ; - + info.dpi = resolution_ ; info.DataLength = info_ex.width * info_ex.height; info.first_frame = info_ex.first_frame; info.last_frame = info_ex.last_frame; @@ -426,8 +365,6 @@ void MultiFrameCapture::snaprun() //printf("获取数据 width:%d height:%d is_first:%d is_last:%d DataLength:%d\r\n",info_ex.width,info_ex.height,info.first_frame,info.last_frame,info.DataLength); m_glue.m_imageready(info); - - //m_frameinfos.Put(info_ex); printf("采集图像耗时:%f\r\n",sw.elapsed_ms()); } return ret; @@ -437,9 +374,7 @@ void MultiFrameCapture::snaprun() while (b_snap_run) { std::unique_lock lock(m_mtx_snap); - m_cv_snap_is_scaning = false; m_cv_snap.wait(lock); - m_cv_snap_is_scaning = true; V4L2_DATAINFO_Ex frame_info_; frame_info_.pixtype = color_mode_; @@ -459,10 +394,6 @@ void MultiFrameCapture::snaprun() { time_out = 2000; } - - - int time_out_cnt = 0; - if (color_mode_) { time_out += 400; @@ -481,9 +412,7 @@ void MultiFrameCapture::snaprun() // video->HtCamSetStSp(ti); // printf("设置 StSp%d\r\n",ti); // ti++; - int mill = 0; //= resolution_ == DPI_600 ? 30 : 25; - //mill = color_mode == 1?mill*3:mill; - printf("mill:%d\r\n",mill); + StopWatch sw; sw.reset(); for (size_t i = 1; i <= frame_info_.frame_index ; i++) @@ -511,20 +440,9 @@ void MultiFrameCapture::snaprun() func_sig = snap_func(frame_info_, channels,time_out ,ind);//同上面一样 val--; - if(resolution_ == DPI_600) - { - int d = 200; - this_thread::sleep_for(std::chrono::milliseconds(d)); - } } break; - } - - if(m_config.params.dpi == 3) - { - int d = 200; - this_thread::sleep_for(std::chrono::milliseconds(d)); - } + } } uint32_t in=0; @@ -536,17 +454,14 @@ void MultiFrameCapture::snaprun() b_end_snap = true; } } - void MultiFrameCapture::updatesnapstatus(int papertype) { b_stop_snap = false; } - void MultiFrameCapture::procimage() { } -static int temp_val = 0; #define CIS_6CH bool MultiFrameCapture::saveLutImg(int dpi, int mode, bool black) { @@ -586,17 +501,7 @@ bool MultiFrameCapture::saveLutImg(int dpi, int mode, bool black) CImageMerge t_marge; cv::Mat mrgmat = t_marge.MergeImage(src, dstwidth, height, mode,true); - printf("mrgmat width = %d height = %d temp_val=%d\n", mrgmat.cols, mrgmat.rows,temp_val); - int inx = 0; - if (temp_val == 0 && !black) - { - //inx+=1; - //temp_val++; - //imwrite(to_string(inx) + ".bmp", mrgmat); - } - - - //return 0; + printf("mrgmat width = %d height = %d \n", mrgmat.cols, mrgmat.rows); FPGAConfigParam param = GetFpgaparam(dpi, mode); if (black) // 暗场 @@ -752,12 +657,12 @@ bool MultiFrameCapture::saveLutImg(int dpi, int mode, bool black) // else // diff = 240 - *((double *)values + k); int diff; - if (x==0) - { - diff = 130 - *((double *)values + k); //R曝光值拉低 - } - else - diff = 240 - *((double *)values + k); + // if (x==0) + // { + // diff = 170 - *((double *)values + k); //R曝光值拉低 + // } + // else + diff = 200 - *((double *)values + k); log += " 明场:" + std::to_string(k) + ";diff:" + std::to_string(diff) + "\r\n"; @@ -890,7 +795,6 @@ bool MultiFrameCapture::saveLutImg(int dpi, int mode, bool black) printf("exit Save_lut \n"); return isNeedSave; } - void MultiFrameCapture::formatStep() { for (int i = 0; i < 2; i++) @@ -903,7 +807,6 @@ void MultiFrameCapture::formatStep() for (int i = 0; i < 12; i++) offsetStep[i] = 64; } - void MultiFrameCapture::correctcolor(int correctmode) { StopWatch sw_correct; @@ -978,7 +881,6 @@ void MultiFrameCapture::correctcolor(int correctmode) if (m_glue.m_deviceevent) m_glue.m_deviceevent((int)HG_ScannerStatus::AUTO_FLAT_FINISHED, "******Correct Done times = " + to_string(sw_correct.elapsed_s()) + " ****** \r\n"); } - void MultiFrameCapture::openDevice(int dpi, int mode) { bool dunnancis = true; @@ -1046,7 +948,6 @@ void MultiFrameCapture::openDevice(int dpi, int mode) printf("opened video with width = %d height = %d time eplased = %.2f pbuffer = %p \n", width, 60 * 2, swwv4l2open.elapsed_ms(),buf); } - void MultiFrameCapture::creatcorrectconfig(int dpi, int mode) { openDevice(dpi, mode); @@ -1109,4 +1010,12 @@ void MultiFrameCapture::creatcorrectconfig(int dpi, int mode) //creatLUTData(dpi, mode); video->close_device(); } - +void MultiFrameCapture::set_image_callback(image_callback cb) +{ + image_cb_ = cb; +} +void MultiFrameCapture::wait_image_notify() +{ + std::unique_lock lock(img_lock_); + img_wait_.wait(lock); +} \ No newline at end of file diff --git a/zynq_7010_code/MultiFrameCapture.h b/zynq_7010_code/MultiFrameCapture.h index f28878e..fd4d425 100644 --- a/zynq_7010_code/MultiFrameCapture.h +++ b/zynq_7010_code/MultiFrameCapture.h @@ -26,43 +26,33 @@ typedef struct hg_tag_SIZE typedef CSSIZE SIZE; + class MultiFrameCapture : public ICapturer { private: - int frame_height = 60; - int m_total_height = 0; - int readframe_timeout = 100; - unsigned int frame_count; - - BlockingQueue m_frameinfos; bool b_snap_run; bool b_stop_snap; - bool stop_snap_ = false ; bool b_end_snap; - bool b_imgproc; - bool is_size_error; bool bScanning; std::atomic iImageremain; FPGAConfigParam m_fpgaparam; + std::mutex m_mtx_snap; std::mutex m_mtx_snapdone; + std::mutex img_lock_; + std::condition_variable img_wait_; std::condition_variable m_cv_snap; - bool m_cv_snap_is_scaning; std::condition_variable m_cv_snapdone; std::shared_ptr m_snap_thread; std::shared_ptr m_imgproc_thread; - std::thread m_correctThread; ScannerGlue m_glue; + int offsetStep[12]; int expStep[2][3]; double radio = 1; -#ifdef TEST_SIMCAP - unsigned char* m_test_pimg; - unsigned int m_test_pimg_len; -#endif - CamZ_Reg_4 reg_; + private: void configFPGAParam(int mode,int dpi); void snaprun(); @@ -75,22 +65,17 @@ private: void openDevice(int dpi,int mode); private: - unsigned int resolution_; // 分辨率 //3:600dpi 2:300dpi 1:200dpi - unsigned int v4l2_width_; // v4l2 图像宽 unsigned int v4l2_height_; // v4l2 图像高 unsigned int pixels_height_; // opencv需要生成的高 unsigned int pixels_width_ ; // opencv需要生成的宽 - unsigned int fpga_height_; // PGPA 需要的高的是三倍数 ,发950 就是指951 - unsigned int paper_size_; // 纸张大小 unsigned int color_mode_; // 颜色模式 unsigned int is_correct_; // 是否校正 unsigned int is_double_paper_; // 是否启动双张检测 - unsigned int is_remove_morr_; // 去除摩尔纹 + unsigned int is_remove_morr_; // 去除摩尔纹 - cv::Mat lut; std::map paper_map_ { @@ -113,13 +98,10 @@ private: SIZE GetPaperSize(PaperSize paper, int dpi); uint32_t compute_frame(int paper_size,int dpi); //计算固定幅面需要采集的帧数 void compute_height(int width,int height); //在open 之前调用 -public: - public: MultiFrameCapture(ScannerGlue glue); - virtual ~MultiFrameCapture(); - +public: virtual void SetParent(void *scanner) override; virtual void open() override; @@ -161,4 +143,8 @@ public: virtual void setScanFlag(bool brun) override; virtual void SetLowPower(bool islow); + + virtual void set_image_callback(image_callback cb) override; + + virtual void wait_image_notify() override; }; \ No newline at end of file diff --git a/zynq_7010_code/PropertiesUtils.cpp b/zynq_7010_code/PropertiesUtils.cpp deleted file mode 100644 index 7f9125f..0000000 --- a/zynq_7010_code/PropertiesUtils.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2014 Fredy Wijaya - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "PropertiesUtils.h" - -namespace cppproperties { -namespace PropertiesUtils { - -namespace { -const std::string TRIM_DELIMITERS = " \f\n\r\t\v"; -std::string ltrim(const std::string& str) { - std::string::size_type s = str.find_first_not_of(TRIM_DELIMITERS); - if (s == std::string::npos) { - return ""; - } - return str.substr(s); -} -} - -std::string RightTrim(const std::string& str) { - std::string::size_type s = str.find_last_not_of(TRIM_DELIMITERS); - if (s == std::string::npos) { - return ""; - } - return str.substr(0, s+1); -} - -std::string LeftTrim(const std::string& str) { - std::string rstr = ltrim(str); - - while (rstr != ltrim(rstr)) { - rstr = ltrim(rstr); - } - - return rstr; -} - -std::string Trim(const std::string& str) { - return RightTrim(LeftTrim(str)); -} - -bool IsProperty(const std::string& str) { - std::string trimmedStr = LeftTrim(str); - std::string::size_type s = trimmedStr.find_first_of("="); - if (s == std::string::npos) { - return false; - } - std::string key = Trim(trimmedStr.substr(0, s)); - // key can't be empty - if (key == "") { - return false; - } - return true; -} - -std::pair ParseProperty(const std::string& str) { - std::string trimmedStr = LeftTrim(str); - std::string::size_type s = trimmedStr.find_first_of("="); - std::string key = Trim(trimmedStr.substr(0, s)); - std::string value = LeftTrim(trimmedStr.substr(s+1)); - - return std::pair(key, value); -} - -bool IsComment(const std::string& str) { - std::string trimmedStr = LeftTrim(str); - return trimmedStr[0] == '#'; -} - -bool IsEmptyLine(const std::string& str) { - std::string trimmedStr = LeftTrim(str); - return trimmedStr == ""; -} - -} // namespace PropertiesUtils -} // namespace cppproperties - diff --git a/zynq_7010_code/PropertiesUtils.h b/zynq_7010_code/PropertiesUtils.h deleted file mode 100644 index 68420ef..0000000 --- a/zynq_7010_code/PropertiesUtils.h +++ /dev/null @@ -1,55 +0,0 @@ - -#ifndef PROPERTIESUTILS_H_ -#define PROPERTIESUTILS_H_ - -#include -#include - -namespace cppproperties { -namespace PropertiesUtils { - -/** - * Left trims a string. - * This function doesn't modify the given str. - */ -std::string LeftTrim(const std::string& str); - -/** - * Right trims a string. - * This function doesn't modify the given str. - */ -std::string RightTrim(const std::string& str); - -/** - * Trims a string (perform a left and right trims). - * This function doesn't modify the given str. - */ -std::string Trim(const std::string& str); - -/** - * Is a given string a property. A property must have the following format: - * key=value - */ -bool IsProperty(const std::string& str); - -/** - * Parses a given property into a pair of key and value. - * - * ParseProperty assumes a given string has a correct format. - */ -std::pair ParseProperty(const std::string& str); - -/** - * Is a given string a comment? A comment starts with # - */ -bool IsComment(const std::string& str); - -/** - * Is a given string empty? - */ -bool IsEmptyLine(const std::string& str); - -} // namespace PropertiesUtils -} // namespace cppproperties - -#endif /* PROPERTIESUTILS_H_ */ diff --git a/zynq_7010_code/Scanner.cpp b/zynq_7010_code/Scanner.cpp index c35e19a..527cc5f 100644 --- a/zynq_7010_code/Scanner.cpp +++ b/zynq_7010_code/Scanner.cpp @@ -1,10 +1,10 @@ #include "Scanner.h" #include -#include "filetools.h" #include "MemoryInfo.h" #include "SysInforTool.h" #include "USBProtocol.h" +#include "StopWatch.h" #define BTN_START 0 #define BTN_STOP 1 //按键停止扫描 @@ -24,11 +24,13 @@ Scanner::Scanner(ScannerGlue glue) waitpapertime(200), m_scansysinfo(nullptr) { + frame_time_ = 3000; m_scaninfo = GetScanInfoFromJson(); capturer.reset(new MultiFrameCapture(m_glue)); capturer->SetParent(this); + capturer->set_image_callback(&have_img_callback); this_thread::sleep_for(std::chrono::milliseconds(50)); //固件版本 int version=7010; @@ -114,6 +116,15 @@ void Scanner::updateSpeedMode() motorZouzhi.speedChange(sp, t_dpi,m_config.params.isColor); } +void Scanner::have_img_callback(int val) +{ + if (val < 0) + { + frame_time_ = 3000; + } + frame_time_ = val ; +} + void Scanner::startScan() { if (threadRunScan.joinable()) @@ -147,18 +158,18 @@ void Scanner::processevent(FsmState *fsmState, ScanEvent event) //开盖模式:1 扫描中开盖 2 未扫描的时候开盖 ,目前我想不到更好的方法,暂时先这样处理 if (event == S_EVT_COVER_OPENED && isScaning) { - //printf("回调:开盖\r\n"); + //printf("回调:开盖1111\r\n"); m_glue.m_deviceevent(1, "Cover Open"); } else if (typeid(*fsmState) == typeid(CoverOpenState) && !isScaning) { - //printf("回调:开盖\r\n"); + //printf("回调:开盖2222\r\n"); m_glue.m_deviceevent(1, "Cover Open"); } else if (event == S_EVT_SCAN_STOPPED) { - //printf("回调:停止\r\n"); + //printf("回调:停止1111\r\n"); if (!m_correctting) { m_glue.m_deviceevent(70, "Scan done"); @@ -166,7 +177,7 @@ void Scanner::processevent(FsmState *fsmState, ScanEvent event) } else if (event == S_EVT_JAM_IN) { - //printf("回调:搓纸失败\r\n"); + //printf("回调:搓纸失败11111\r\n"); m_glue.m_deviceevent(4, "Feed error"); } else if (event == S_EVT_DOUBLEPAPER) @@ -183,7 +194,7 @@ void Scanner::processevent(FsmState *fsmState, ScanEvent event) else if (typeid(*fsmState) == typeid(ErrorState) && m_jamIn == true) { - //printf("回调:搓纸失败\r\n"); + //printf("回调:搓纸失败22222\r\n"); m_glue.m_deviceevent(4, "Feed error"); } if (!IsScanning() && (typeid(*fsmState) == typeid(ErrorJamState) || @@ -192,7 +203,7 @@ void Scanner::processevent(FsmState *fsmState, ScanEvent event) { if (!m_correctting) { - //printf("回调:停止\r\n"); + //printf("回调:停止2222\r\n"); m_glue.m_deviceevent(70, "Scan Stop"); } } @@ -215,7 +226,6 @@ void Scanner::runScan() sensor->resetPaperPin(); - capturer->clearimages(); capturer->resetimageremain(); capturer->setScanFlag(true); @@ -224,7 +234,6 @@ void Scanner::runScan() m_config.params.pageSize==(int)PaperSize::G400_MAXSIZE; StopWatch sw; StopWatch sw1; - isScaning = true; int error_code = 0; while (m_DstScannum > 0) @@ -239,7 +248,6 @@ void Scanner::runScan() if (!sensor->waitPaperStandBy(0)) { put(S_EVT_STOP_SCAN); - LOG("STOP STOP STOP RUNSCAN \n"); } isScaning = false; break; @@ -265,7 +273,6 @@ void Scanner::runScan() { if (!m_isDoublePaper) { - m_glue.m_deviceevent(4, "Feed error"); m_jamIn = true; put(S_EVT_JAM_IN); m_scaninfo.JamInNum++; @@ -276,128 +283,54 @@ void Scanner::runScan() printf("检测到纸张的时间:%f\r\n",sw.elapsed_ms());//检测到纸张 capturer->snap(); + motorCuozhi.pauseWaitForThread(); - int i = 0; - int max = 7; + capturer->wait_image_notify(); - if(m_config.params.pageSize >= (int)PaperSize::G400_LONGLETTER) - max = m_scaninfo.SpeedMode > 3 ? 10 : 25; - else - max = m_scaninfo.SpeedMode > 3 ? 5 : 8; - - max = m_config.params.dpi > 2 ? 30 : max * m_config.params.dpi; - - - if(m_config.params.pageSize == 17 || m_config.params.pageSize == 19 || m_config.params.slow_moire) - { - max = 200; - } - - - waitpapertime = 200; - while (!sensor->waitPaperOut(waitpapertime) && i < max) - { - //printf("max :%d i:%d\r\n",max,i); - i++; - if (!sensor->isPaperIn()) - { - printf("paper 假卡纸了。。。。。\n"); - isScaning = false; - break; - } - } - if (!sensor->isCoverClosed()) + if (!sensor->isCoverClosed()) //中途开盖 笑麻了 { break; } - - if (i == max && sensor->isPaperIn()) - { + printf("frame_time_:%d\r\n",frame_time_); + if (sensor->waitPaperOut(frame_time_)) + { if (!m_isDoublePaper) { - error_code = S_EVT_JAM_OUT; - m_glue.m_deviceevent(8, "Jam out"); //卡纸 + error_code = (int)HG_ScannerStatus::PAPER_JAM; m_jamPaper = true; put(S_EVT_JAM_OUT); m_scaninfo.JamOutNum++; printf("paper 卡纸了。。。。。\n"); } - else - { - // m_glue.m_deviceevent(16); //双张 - // LOG("paper 双张了。。。。。\n"); - m_scaninfo.DoubleNum++; - } capturer->waitsnapdone(error_code);//等待采集完成 - this_thread::sleep_for(std::chrono::milliseconds(500));//200 80ms 600 260ms isScaning = false; break; } - //LOG("\nclose double sensor %s\n",GetCurrentTimeStamp(2).c_str()); - sensor->enableDoubleSensor(false); - if(b_autosize) - { - int dly_speed= (5 - m_scaninfo.SpeedMode)*10; - int delay = m_config.params.dpi==0x02?70:(m_config.params.dpi==0x03?350: 20); - if((m_config.params.pageSize == 17 || m_config.params.pageSize == 19)&&(delay < 350)) - { - delay = 350; - } - - if(m_config.params.pageSize == 18) - delay = std::max(delay,80); - - delay += dly_speed; - if (m_config.params.dpi == 3) - { - delay = 0; - } - this_thread::sleep_for(std::chrono::milliseconds(delay));//200 80ms 600 260ms - } - if(b_autosize) - { - int de = (5 - m_scaninfo.SpeedMode) * 10 * m_config.params.dpi; - if (de == 3) - { - de = 0; - } - std::this_thread::sleep_for(std::chrono::milliseconds(de)); - if(sensor->isPaperAtScan()) - { - m_glue.m_deviceevent((int)HG_ScannerStatus::PAPER_HOLE,"paper have hole"); - - capturer->waitsnapdone((int)HG_ScannerStatus::PAPER_HOLE);//等待采集完成 - isScaning = false; - break; - } - } - + sensor->enableDoubleSensor(false); capturer->stopsnap(b_autosize); - error_code = m_isDoublePaper ? S_EVT_DOUBLEPAPER : m_jamPaper ? S_EVT_JAM_OUT :0; + error_code = m_isDoublePaper ? (int)HG_ScannerStatus::DETECT_DOUBLE_FEED : m_jamPaper ? (int)HG_ScannerStatus::PAPER_JAM :0; capturer->waitsnapdone(error_code);//等待采集完成 + m_DstScannum--; m_scaninfo.RollerNum++; m_scaninfo.TotalScanned++; if (m_DstScannum == 0) { - this_thread::sleep_for(std::chrono::milliseconds(200)); - put(S_EVT_STOP_SCAN); isScaning = false; break; } sw.reset(); - while (meminfo->GetMemoryUsed() > 90.0f||(m_config.params.dpi ==0x03 && capturer->getimageremain()>1)) //内存占用高于75% + + while (meminfo->GetMemoryUsed() > 90.0f||(m_config.params.dpi ==0x03 && capturer->getimageremain()>1)) //内存占用高于75% 其实我觉得开发人员应该自己控制好这个内存大小,让他绝对不可能超过这个内存大小 { if (sw.elapsed_s() < 50.0) - { - std::this_thread::yield(); - } + std::this_thread::yield(); else { put(S_EVT_STOP_SCAN); @@ -409,6 +342,7 @@ void Scanner::runScan() printf("一张纸完成时间:%f\r\n",sw1.elapsed_ms()); if( m_config.params.dpi == 3) this_thread::sleep_for(std::chrono::milliseconds(3000)); + } isScaning = false; m_DstScannum = 0; @@ -417,13 +351,11 @@ void Scanner::runScan() capturer->setScanFlag(false); capturer->stopsnap(b_autosize); - int t_delay = m_config.params.dpi == 0x02 ? 150 : (m_config.params.dpi == 0x03 ? 350 : 100); + int t_delay = 500;//b_autosize ?350 : 200; + //int t_delay = m_config.params.dpi == 0x02 ? 150 : (m_config.params.dpi == 0x03 ? 350 : 100); this_thread::sleep_for(std::chrono::milliseconds(t_delay)); //走纸多转一会儿 确保扫描传感器过了之后 纸能出完 - capturer->setFanMode(0); - - LOG("\n--------------------------scan done --------------------------------\n"); } @@ -475,10 +407,6 @@ void Scanner::emergency_stop(int id) sensor->cancelWaitPaper(); sensor->enableDoubleSensor(false); m_DstScannum = 0; - if (id == S_EVT_ERROR_DOUBLEPAPER) //双张 - m_glue.m_deviceevent(S_EVT_ERROR_DOUBLEPAPER, "double feed"); - // else if(id == S_EVT_COVER_OPENED) - // m_glue.m_deviceevent(S_EVT_COVER_OPENED, "cover opened"); motorCuozhi.stop(); motorZouzhi.stop(); @@ -495,8 +423,10 @@ void Scanner::stop_scan() sensor->cancelWaitPaper(); sensor->enableDoubleSensor(false); m_DstScannum = 0; + if (threadRunScan.joinable()) threadRunScan.join(); + motorZouzhi.stop(); motorCuozhi.stop(); diff --git a/zynq_7010_code/Scanner.h b/zynq_7010_code/Scanner.h index 8318c9b..5ceb771 100644 --- a/zynq_7010_code/Scanner.h +++ b/zynq_7010_code/Scanner.h @@ -13,16 +13,19 @@ #include "scanservices_utils.h" #include "Keyboard.h" #include "utilsfunc.h" -#include "filetools.h" + #include "SysInforTool.h" #include "MotorConfig.h" #include "correct_ultis.h" class ICapturer; class MemoryInfo; // class SysInforTool; - + static int frame_time_ ; class Scanner { + std::mutex cb_lock_; + std::condition_variable wait_cb_; + public: bool isRested = false; bool isScaning = false; @@ -38,6 +41,7 @@ public: void CreatCorrectData(int correctmode); void UpdateScanInfo(); void updateSpeedMode(); + static void have_img_callback(int val); std::string GetSysInfo(); public: @@ -55,7 +59,7 @@ public: inline bool GetIsJamPaper() { return m_jamPaper; } inline bool GetIsJamIn() { return m_jamIn; } inline void ResetJamIn() { m_jamIn = false; } - inline bool IsScanning() { return !capturer->IsImageQueueEmpty(); } + inline bool IsScanning() { return isScaning; } inline void close_v4l2() { capturer->close(); } CaptureParams GetCaptureParams() diff --git a/zynq_7010_code/Sensor.cpp b/zynq_7010_code/Sensor.cpp index 9792197..e59b4ec 100644 --- a/zynq_7010_code/Sensor.cpp +++ b/zynq_7010_code/Sensor.cpp @@ -7,7 +7,8 @@ #include #include #include -#include "filetools.h" +#include "StopWatch.h" + //FileTools ftt("/home/linaro/scanpin.log"); @@ -103,13 +104,8 @@ bool Sensor::waitPaperIn(int timeout_ms) bool Sensor::waitPaperOut(int timeout_ms) { std::unique_lock lck(cv_m); - if (!isPaperIn()) - { - LOG("scanPin Value is low! \n"); - return true; - } cv_scan_not_at.wait_for(lck, std::chrono::milliseconds(timeout_ms)) == std::cv_status::no_timeout; - return !isPaperIn(); + return isPaperIn(); } bool Sensor::waitPaperStandBy(int timeout_ms) @@ -150,6 +146,7 @@ void Sensor::monitor() num = read(pfd.fd, buf, 8); // This is to clear the avaible read std::cout<<"read time "<< sw.elapsed_ms()<notify_all(); sw.reset(); diff --git a/zynq_7010_code/USBProtocol.h b/zynq_7010_code/USBProtocol.h index c3b8c32..f23e7af 100644 --- a/zynq_7010_code/USBProtocol.h +++ b/zynq_7010_code/USBProtocol.h @@ -1,225 +1 @@ #pragma once - -typedef struct -{ - int Command; - int Data; - int Length; -} USBCB; - -enum class USBCommand : unsigned int -{ - //无命令 - NO_COMMAND = 0, - //获取dsp 状态 - GET_DSP_STATUS = 1, - //取图 - GET_IMAGE = 2, - //销毁DSP中驻存的图 - POP_IMAGE = 3, - //开始扫描命令 - START_COMMAND = 4, - //停止扫描命令 - STOP = 5, - //获取扫描仪扫描模式 - GET_SCAN_MODE = 6, - //获取固件版本号 - GET_FW_VERSION = 7, - //返回PC端的状态 - SEND_STATUS_PC = 8, - //下发扫描配置参数 - CONFIGURED_DATA = 9, - //下发固件信息 - SEND_FW = 10, - //获取扫描参数 - GET_CONFIG_DATA = 11, - //获取扫描总张数 - GET_SCANN_NUM = 12, - //获取有无纸的状态 - GET_PAPERFEEDER_STATUS = 13, - //DSP初始化 - INIT_HARDWARE_SYS = 14, - //下发元器件配置参数(灰度,LED R曝光时间) - SEND_COMPONENTS_GR = 15, - //下发元器件配置参数(LED G/B曝光时间) - SEND_COMPONENTS_GB = 16, - //下发扫描模式 - SEND_SCAN_MODE = 17, - //开始进行平场矫正 - START_FLAT = 18, - //停止平场矫正 - STOP_FLAT = 19, - //下发200dpi彩色平场矫正参数 - SEND_200_COLOR_FLAT_DATA = 20, - //下发300dpi彩色平场矫正参数 - SEND_300_COLOR_FLAT_DATA = 21, - //获取200dpi彩色平场矫正参数 - GET_200_COLOR_FLAT_DATA = 22, - //获取300dpi彩色平场矫正参数 - GET_300_COLOR_FLAT_DATA = 23, - //下发200dpi灰度平场校正参数 - SEND_200_GRAY_FLAT_DATA = 24, - //下发300dpi灰度平场校正参数 - SEND_300_GRAY_FLAT_DATA = 25, - //获取200DPI灰度平场校正参数 - GET_200_GRAY_FLAT_DATA = 26, - //获取300DPI灰度平场校正参数 - GET_300_GRAY_FLAT_DATA = 27, - //下发序列号命令 - SEND_SERIAL = 28, - //获取序列号命令 - GET_SERIAL = 29, - //获取滚轴数 - GET_ROLLER_NUM = 0x1e, - //清零滚轴数 - CLR_ROLLER_NUM = 0x1f, - //清除扫描总张数 - CLR_SCAN_NUM = 0x20, - //准备更新固件 - PRE_UPGRADE = 0X21, - //开始更新固件 - START_UPGRADE = 0x22, - //彩色的AD参数 - RGB_ADI_PARA = 0x23, - //灰度的AD参数 - ADI_PARA = 0x24, - //获取CIS参数(曝光时间,ad参数) - GET_CIS_PARA = 0x25, - //扫描张数 - START_COMMAND_COUNT = 0x26, - //下发休眠时间 - SET_SLEEP_TIME = 0x27, - //获取休眠时间 - GET_SLEEP_TIME = 0x28, - //清除缓存 - CLR_CACHE = 0x29, - //下发速度模式 - SET_SPEED_MODE = 0x2a, - //获取扫描速度模式 - GET_SPEED_MODE = 0X2b, - //设置固件版本一共8个字节 - SET_FW_VERSION = 0X2c, - //获取DSP版本 - GET_DSP_VERSION = 0X2d, - //采集板FPGA固件版本 - GET_SCANFPGA_VERSION = 0x2e, - //电机板FPGA固件版本 - GET_MOTORFPGA_VERSION = 0X2f, - //设置制造商信息 - SET_USB_INFOR_MANUFACTURE = 0X30, - //获取制造商信息 - GET_USB_INFOR_MANUFACTURE = 0X31, - //设置产品型号信息 - SET_USB_INFOR_MODEL_NAME = 0X32, - //获取产品型号信息 - GET_USB_INFOR_MODEL_NAME = 0X33, - //设置USB PID / VID信息 - SET_USB_INFOR_VIDPID = 0X34, - GET_USB_INFOR_VIDPID = 0X35, - //设置卡纸急停检测灵敏度 - SET_JAM_DETECT_SENSITIVE = 0X36, - //获取卡纸急停检测灵敏度 - GET_JAM_DETECT_SENSITIVE = 0X37, - //设置横向畸变系数 - SET_JUST_COF_H = 0x38, - //读取横向畸变系数 - GET_JUST_COF_H = 0x39, - //G400 清除硬件异常 - CLEAR_HWERROR = 0x40, - //设置纵向畸变系数 - SET_JUST_COF_V = 0x41, - //读取纵向畸变系数 - GET_JUST_COF_V = 0x42, - //设置彩色校正参数 - SEND_COLOR_FLAT = 0x43, - //设置彩色平场校正参数 - SEND_COLORCORRECT_FLAT = 0x44, - //设置灰度校正参数 - SEND_GRAY_FLAT = 0x45, - //设置灰度平场校正参数 - SEND_GRAYCORRECT_FLAT = 0x46, - //设置平场校正参数 - GET_FLAT_DATA =0x47, - //更新完成 - UPDATE_FINISHED = 0x48, - //重启 - REBOOT = 0x49, - //获取日志 - GET_LOG_FILES_INFO = 0x50, - //发送log文件完成 - GET_UPDATE_RESULT=0x51, - //清空日志 - CLEAR_LOG_FILES = 0x52, - //获取搓纸失败 - GET_CUO_ERROR, - //获取双张失败次数 - GET_DOU_ERROR, - //获取卡纸次数 - GET_JAM_ERROR, - ACTIVE_SCANNER=0x100, - //图像处理参数下发 - GETSYSINFO_LEN =0x200, - GETSYSINFO =0x201, - GETMOTORPARAM = 0x202, - GETMOTORPARMLEN=0x203, - SETMOTORPARAM = 0x204, - SETMOTORPARAMLEN = 0x205, - DEVICES_7010 = 0x7010 -}; - -enum class HG_ScannerStatus -{ - //异常 - HAVE_ERROR = -1, - //正常状态 - NORMAL = 0, - //开盖 - OPEN_COVER = 1, - // 无纸 - NO_FEED = 2, - // 搓纸失败 - FEED_IN_ERROR = 4, - // 卡纸 - PAPER_JAM = 8, - // 检测到双张 - DETECT_DOUBLE_FEED = 16, - // 检测到订书钉 - DETECT_STAPLE = 32, - // 纸张倾斜 - PAPER_SKEW = 64, - // 自动模式 - AUTO_SCAN_MODE = 65, - // 手动模式 - MANAUL_SCAN_MODE = 66, - // 计数模式 - COUNT_MODE = 67, - // 硬件错误 - HARDWARE_ERROR = 68, - // FPGA崩溃 - FPGA_ERROR = 68, - // 开始 - START_SCAN = 69, - //停止 - STOP_SCAN = 70, - //有图 - HAVE_IMAGE = 71, - // 更新扫描参数 - UPDATE_SCAN_PARAMETER = 72, - // PC繁忙或出错 - PC_SCAN_BUSY_or_ERROR = 73, - // 更新完成 - UPDATE_FINISHED = 74, - //尺寸检测错误 - SIZE_ERROR=75, - //纸张有孔 - PAPER_HOLE = 84, - //自动校正中 - AUTO_FLATTING=198, - //USB 未连接 - USB_DISCONNECTED = 200, - //用户点击停止 - USER_STOP = 201, - //自动平场校正完成 - AUTO_FLAT_FINISHED = 202, - SCANNER_ACTIVED=0x10 -}; \ No newline at end of file diff --git a/zynq_7010_code/UsbScanner.cpp b/zynq_7010_code/UsbScanner.cpp index 40ffb15..f5e1d38 100644 --- a/zynq_7010_code/UsbScanner.cpp +++ b/zynq_7010_code/UsbScanner.cpp @@ -2,9 +2,9 @@ #include #include "JsonConfig.h" #include "USBProtocol.h" -#include "filetools.h" #include "logs_out.h" #include "JsonConfig.h" +#include "StopWatch.h" #define USB_REQ_GET_FPGA_REGS 0x40 #define USB_REQ_SET_FPGA_REGS 0x41 @@ -138,22 +138,22 @@ UsbScanner::UsbScanner() : m_startscan(false), auto deviceevent = [this](const int eventID, std::string capmsg) { + printf("插入事件:%d\r\n",eventID); + eventsramain++; + m_scannerEvents.Put({eventID, capmsg}); + if (eventID == (int)HG_ScannerStatus::STOP_SCAN) { - eventsramain++; - m_scannerEvents.Put({eventID, capmsg}); - if (eventID == (int)HG_ScannerStatus::STOP_SCAN) - { - m_startscan = false; - } - if (eventID == (int)(HG_ScannerStatus::AUTO_FLAT_FINISHED)) - { - m_hgScanner->ResetCorrectflags(); - } - else if ((eventID == (int)HG_ScannerStatus::SIZE_ERROR) || (eventID == (int)HG_ScannerStatus::PAPER_HOLE)) - { - m_hgScanner->StopScan(0); - } + m_startscan = false; } + if (eventID == (int)(HG_ScannerStatus::AUTO_FLAT_FINISHED)) + { + m_hgScanner->ResetCorrectflags(); + } + else if ((eventID == (int)HG_ScannerStatus::SIZE_ERROR) || (eventID == (int)HG_ScannerStatus::PAPER_HOLE)) + { + m_hgScanner->StopScan(0); + } + }; ScannerGlue glue = {imageready, deviceevent}; m_hgScanner.reset(new Scanner(glue)); @@ -299,7 +299,7 @@ bool UsbScanner::GetImagequeueEmpty() { if (m_images.Size() != 0) { - LOG("队列剩余图像帧数:%d\r\n",m_images.Size()); + printf("队列剩余图像帧数:%d\r\n",m_images.Size()); } return m_images.Size() == 0; @@ -443,7 +443,7 @@ std::string UsbScanner::GetSysInfo() return m_hgScanner->GetSysInfo(); } -int UsbScanner::read_bulk(void *pdata, int length) +int UsbScanner::read_bulk(void *pdata, int length ,int time) { int ret=0; @@ -452,7 +452,7 @@ int UsbScanner::read_bulk(void *pdata, int length) if(m_usb.get()&& m_usb->is_connected()) { - ret = m_usb->read_bulk(pdata,length,1000); + ret = m_usb->read_bulk(pdata,length,time); } return ret; } diff --git a/zynq_7010_code/UsbScanner.h b/zynq_7010_code/UsbScanner.h index a1d10b3..a76313a 100644 --- a/zynq_7010_code/UsbScanner.h +++ b/zynq_7010_code/UsbScanner.h @@ -44,7 +44,7 @@ public: virtual void close_v4l2()override; std::string GetSysInfo(); - int read_bulk(void *pdata, int length); + int read_bulk(void *pdata, int length,int time = 1000); int write_bulk(void *pdata, int length); bool is_connect(); private: diff --git a/zynq_7010_code/filetools.h b/zynq_7010_code/filetools.h deleted file mode 100644 index 05854a8..0000000 --- a/zynq_7010_code/filetools.h +++ /dev/null @@ -1,158 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class FileTools -{ -private: - std::string mPath; - -public: - FileTools(std::string path) - { - mPath = path; - } - void createLog(std::string log) - { - time_t now = time(0); - tm *ltm = localtime(&now); - char loc_date[30]; - sprintf(loc_date, "%d%02d%02d %d:%d:%d", 1900 + ltm->tm_year, 1 + ltm->tm_mon, ltm->tm_mday, ltm->tm_hour, ltm->tm_min, ltm->tm_sec); - std::ofstream ofs(mPath); - ofs << loc_date << ": " << log << std::endl; - ofs.close(); - } - void append_log(std::string log, bool printTime = true) - { - std::ofstream ofs(mPath, std::ios::app); - if (printTime) - { - // time_t now = time(0); - - // struct timeb stTimeb; - - // ftime(&stTimeb); - // tm *ltm = localtime(&now); - // char loc_date[30]; - // sprintf(loc_date, "%d%02d%02d %d:%d:%d", 1900 + ltm->tm_year, 1 + ltm->tm_mon, ltm->tm_mday, ltm->tm_hour, ltm->tm_min, ltm->tm_sec); - struct tm *ptm; - struct timeb stTimeb; - static char loc_date[30]; - - ftime(&stTimeb); - ptm = localtime(&stTimeb.time); - sprintf(loc_date, "%02d-%02d %02d:%02d:%02d.%03d", - ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec, stTimeb.millitm); - ofs << loc_date << ": " << log << std::endl; - } - else - { - ofs << " " << log << std::endl; - } - ofs.close(); - } - - void clear() - { - try - { - std::fstream fout(mPath, std::ios::out | std::ios::trunc); - fout.close(); - } - catch (std::exception &e) - { - //LOG("error happened: %s \n", e.what()); - } - } -}; - - -static std::string GetCurrentTimeStamp(int time_stamp_type ) -{ - std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); - - std::time_t now_time_t = std::chrono::system_clock::to_time_t(now); - std::tm* now_tm = std::localtime(&now_time_t); - - char buffer[128]; - strftime(buffer, sizeof(buffer), "%F %T", now_tm); - - std::ostringstream ss; - ss.fill('0'); - - std::chrono::milliseconds ms; - std::chrono::microseconds cs; - std::chrono::nanoseconds ns; - - switch (time_stamp_type) - { - case 0: - ss << buffer; - break; - case 1: - ms = std::chrono::duration_cast(now.time_since_epoch()) % 1000; - ss << buffer << ":" << ms.count(); - break; - case 2: - ms = std::chrono::duration_cast(now.time_since_epoch()) % 1000; - cs = std::chrono::duration_cast(now.time_since_epoch()) % 1000000; - ss << buffer << ":" << ms.count() << ":" << cs.count() % 1000; - break; - case 3: - ms = std::chrono::duration_cast(now.time_since_epoch()) % 1000; - cs = std::chrono::duration_cast(now.time_since_epoch()) % 1000000; - ns = std::chrono::duration_cast(now.time_since_epoch()) % 1000000000; - ss << buffer << ":" << ms.count() << ":" << cs.count() % 1000 << ":" << ns.count() % 1000; - break; - default: - ss << buffer; - break; - } - - return ss.str(); -} - -class StopWatch -{ -public: - StopWatch() - { - _start = std::chrono::steady_clock::now(); - } - - void reset() - { - _start = std::chrono::steady_clock::now(); - } - - double elapsed_s() - { - return std::chrono::duration(std::chrono::steady_clock::now() - _start).count(); - } - - double elapsed_ms() - { - return std::chrono::duration(std::chrono::steady_clock::now() - _start).count(); - } - - double elapsed_us() - { - return std::chrono::duration(std::chrono::steady_clock::now() - _start).count(); - } - - double elapsed_ns() - { - return std::chrono::duration(std::chrono::steady_clock::now() - _start).count(); - } - -private: - std::chrono::steady_clock::time_point _start; -}; diff --git a/zynq_7010_code/main.cpp b/zynq_7010_code/main.cpp index cf82e6a..08ef9a4 100644 --- a/zynq_7010_code/main.cpp +++ b/zynq_7010_code/main.cpp @@ -8,7 +8,6 @@ #include "FsmState.h" #include "Scanner.h" -// #include "filetools.h" #include #include #include @@ -39,6 +38,9 @@ static unsigned int total_length = 0; extern int errno; #define MY_PID_FILE "/tmp/scanservice_pid" #define BUF_LEN_FOR_PID 64 +#define WAITCONNECTMAXTIME 50 +bool b_runloop = true; + static int write_pid_into_fd(int fd, pid_t pid) { @@ -65,7 +67,6 @@ static int write_pid_into_fd(int fd, pid_t pid) return ret; } - static int create_pid_file(pid_t pid) { int fd, ret; @@ -93,7 +94,6 @@ static int create_pid_file(pid_t pid) return ret; } - static int check_pid_file(int fd, pid_t pid) { int ret = -1; @@ -146,7 +146,6 @@ static int check_pid_file(int fd, pid_t pid) return ret; } - static int init_pid_file() { pid_t pid; @@ -175,7 +174,6 @@ static int init_pid_file() return ret; } - static void sigHandler(int sig) { if (sig == SIGINT || sig == SIGTERM) @@ -183,7 +181,6 @@ static void sigHandler(int sig) _exit(0); } - int menu() { int choice; @@ -206,30 +203,23 @@ void initscanner() LOG("init m_scanner failed\n"); } -bool b_runloop = true; -int waittimes = 0; -#define WAITCONNECTMAXTIME 50 - int main(int argc, char *argv[]) { if (-1 == init_pid_file()) { exit(-1); } - /* Ctrl + C */ if (signal(SIGINT, sigHandler) == SIG_ERR) { exit(-1); } - /* kill pid / killall name */ if (signal(SIGTERM, sigHandler) == SIG_ERR) { exit(-1); } creat_sleep_fifo(); - initscanner(); start_enter_lowpwoer(); @@ -238,17 +228,12 @@ int main(int argc, char *argv[]) int t_arg1 = atoi(argv[1]); if (t_arg1 == 236) { - LOG("onboard start auto correct!\n"); m_scanner->CreatCorrectData(0); while (m_scanner->GetEvent().code != (int)HG_ScannerStatus::AUTO_FLAT_FINISHED) { std::this_thread::sleep_for(chrono::milliseconds(2)); } } - else - { - LOG("onboard unkown command!\n"); - } } while (b_runloop) @@ -269,35 +254,24 @@ int main(int argc, char *argv[]) std::this_thread::sleep_for(std::chrono::milliseconds(10)); continue; } - // printf("Usb command %d \n",usbcb.Command); - switch ((USBCommand)usbcb.Command) { case USBCommand::GET_DSP_STATUS: { USBCB sts = {1, 0, 0}; - if (m_scanner->IsScanning()) // 队列不为空 + if (m_scanner->IsScanning()) //采集图像线程工作中 { - if (m_scanner->GetImagequeueEmpty()) { - // LOG("GetImagequeueEmpty\n"); auto evt = m_scanner->GetEventFront(); - // if (evt != (int)HG_ScannerStatus::NORMAL && evt != (int)HG_ScannerStatus::STOP_SCAN) if (evt.code != (int)HG_ScannerStatus::NORMAL && evt.code != (int)HG_ScannerStatus::STOP_SCAN) - { sts.Data = m_scanner->GetEvent().code; // 确保第一张扫描之前所发生的异常事件能够被通知 - } - } else { - LOG("not GetImagequeueEmpty\n"); int evt = m_scanner->GetEventFront().code; if (evt != (int)HG_ScannerStatus::NORMAL && evt != (int)HG_ScannerStatus::STOP_SCAN) - { sts.Data = m_scanner->GetEvent().code; // 扫描中途的事件能够被通知 - } else { HG_JpegCompressInfo info = m_scanner->GetFrontImage(); @@ -308,10 +282,8 @@ int main(int argc, char *argv[]) } else { - // LOG("Scanning not scanning \n"); if (!m_scanner->GetImagequeueEmpty()) { - HG_JpegCompressInfo info = m_scanner->GetFrontImage(); sts.Data = (int)HG_ScannerStatus::HAVE_IMAGE; sts.Length = info.DataLength; @@ -324,8 +296,7 @@ int main(int argc, char *argv[]) printf("关闭V4L2 4444\r\n"); m_scanner->close_v4l2(); } - - + sts.Data = data.code; if (data.code == (int)HG_ScannerStatus::AUTO_FLATTING || data.code == (int)HG_ScannerStatus::AUTO_FLAT_FINISHED) { @@ -344,7 +315,7 @@ int main(int argc, char *argv[]) case USBCommand::GET_IMAGE: { HG_JpegCompressInfo info = m_scanner->GetImage(); - printf("USB error_code:%d\r\n",info.error_code); + //printf("USB error_code:%d\r\n",info.error_code); if (info.pJpegData != nullptr && info.DataLength != 0 || info.error_code) { @@ -542,22 +513,6 @@ int main(int argc, char *argv[]) printf("升级包下载:%s...\r\n",tmpUpdate.Data == 10 ? "失败":"成功"); - // LOG("\n-----------START_UPGRADE----------------\n %d %d %d ", usbcb.Command, usbcb.Data, usbcb.Length); - // USBCB tmpUpdate = {(unsigned int)(USBCommand::START_UPGRADE), 0, 0}; - // if (usbcb.Length != 0) - // { - // LOG("\n-----------read_bulk----------------"); - // uint ntoReadn = usbcb.Length; - // char *bufferData = (char *)malloc(ntoReadn * sizeof(char)); - // if (bufferData) - // { - // m_scanner->read_bulk(bufferData, ntoReadn); - // updatePkg.write(bufferData, ntoReadn); - // tmpUpdate.Length = ntoReadn; - // free(bufferData); - // } - // } - // m_scanner->write_bulk(&tmpUpdate, sizeof(tmpUpdate)); } break; case USBCommand::UPDATE_FINISHED: @@ -800,10 +755,7 @@ int main(int argc, char *argv[]) { lut_buffer = new unsigned char[flatinfo.params.datalen]; if (lut_buffer) - { - lut_item.read((char *)lut_buffer, flatinfo.params.datalen); - } - + lut_item.read((char *)lut_buffer, flatinfo.params.datalen); else { flatinfo.params.status = 2; // OOM 异常 @@ -835,6 +787,8 @@ int main(int argc, char *argv[]) m_scanner->write_bulk(&usbcb, sizeof(usbcb)); break; default: + usbcb.Data = 56833; + m_scanner->write_bulk(&usbcb, sizeof(usbcb)); break; } } diff --git a/zynq_7010_code/scanservices_utils.h b/zynq_7010_code/scanservices_utils.h index d0e08b0..883639b 100644 --- a/zynq_7010_code/scanservices_utils.h +++ b/zynq_7010_code/scanservices_utils.h @@ -60,7 +60,7 @@ typedef struct #define STR(X) #X #define CON(a,b) STR(a##b) - + typedef void (*image_callback)(int element); static std::mapmapFradme_SP={ {1,{0x08ED1003,0x1ACC1002,CON(G34D,231027)}},//40 ppm {2,{0x06DB1003,0x14A01002,CON(G3ZY,231102)}},//50 ppm @@ -307,4 +307,260 @@ enum scanner_err SCANNER_ERR_UPDATE_CHECK_VAL_ERROR, //设备更新:校验检测错误 SCANNER_ERR_UPDATE_CHECK_FILE_LOST, //设备更新:文件丢失 SCANNER_ERR_UPDATE_UNZIP_FAIL, //设备更新:解压失败 -}; \ No newline at end of file +}; + + +enum ScanEvent { + S_EVT_NORES = 0x0, + S_EVT_SCAN_FINISHED = 0x2, + S_EVT_CLEAR_ERR = 0x03, + S_EVT_PAPER_PULLOUT = 0x05, + S_EVT_COVER_OPENED = 0x01, + S_EVT_COVER_CLOSED = 0x102, + S_EVT_PAPER_AT_SCAN = 0x08, + S_EVT_PAPER_NOT_AT_SCAN = 0x106, + S_EVT_DOUBLEPAPER = 0x110, + S_EVT_NOT_DOUBLEPAPER = 0x111, + S_EVT_START_SCAN = 0x45, + S_EVT_STOP_SCAN = 0x46, + S_EVT_SCAN_STARTED = 0x112, + S_EVT_SCAN_STOPPED = 0x113, + S_EVT_JAM_IN = 0x114, + S_EVT_JAM_OUT = 0x115, + S_EVT_SAMPLE_ERR = 0x116, + S_EVT_COVER_IN_OPEN = 0x117, + S_EVT_ERROR_PICKING = 0x4, + S_EVT_ERROR_JAM = 0x8, + S_EVT_ERROR_DOUBLEPAPER = 0x10, + S_EVT_ERROR_STAPLE = 0x20, + S_EVT_ERROR_FPGA = 0x44, + S_EVT_HAVING_IMAGE = 0x47, + S_EVT_ONE_PAPER_END = 0x59, + S_EVT_PAPER_NOT_STANDBY = 0,//? + S_EVT_PAPER_STANDBY = 0 //? +}; + + +typedef struct +{ + int Command; + int Data; + int Length; +} USBCB; + +enum class USBCommand : unsigned int +{ + //无命令 + NO_COMMAND = 0, + //获取dsp 状态 + GET_DSP_STATUS = 1, + //取图 + GET_IMAGE = 2, + //销毁DSP中驻存的图 + POP_IMAGE = 3, + //开始扫描命令 + START_COMMAND = 4, + //停止扫描命令 + STOP = 5, + //获取扫描仪扫描模式 + GET_SCAN_MODE = 6, + //获取固件版本号 + GET_FW_VERSION = 7, + //返回PC端的状态 + SEND_STATUS_PC = 8, + //下发扫描配置参数 + CONFIGURED_DATA = 9, + //下发固件信息 + SEND_FW = 10, + //获取扫描参数 + GET_CONFIG_DATA = 11, + //获取扫描总张数 + GET_SCANN_NUM = 12, + //获取有无纸的状态 + GET_PAPERFEEDER_STATUS = 13, + //DSP初始化 + INIT_HARDWARE_SYS = 14, + //下发元器件配置参数(灰度,LED R曝光时间) + SEND_COMPONENTS_GR = 15, + //下发元器件配置参数(LED G/B曝光时间) + SEND_COMPONENTS_GB = 16, + //下发扫描模式 + SEND_SCAN_MODE = 17, + //开始进行平场矫正 + START_FLAT = 18, + //停止平场矫正 + STOP_FLAT = 19, + //下发200dpi彩色平场矫正参数 + SEND_200_COLOR_FLAT_DATA = 20, + //下发300dpi彩色平场矫正参数 + SEND_300_COLOR_FLAT_DATA = 21, + //获取200dpi彩色平场矫正参数 + GET_200_COLOR_FLAT_DATA = 22, + //获取300dpi彩色平场矫正参数 + GET_300_COLOR_FLAT_DATA = 23, + //下发200dpi灰度平场校正参数 + SEND_200_GRAY_FLAT_DATA = 24, + //下发300dpi灰度平场校正参数 + SEND_300_GRAY_FLAT_DATA = 25, + //获取200DPI灰度平场校正参数 + GET_200_GRAY_FLAT_DATA = 26, + //获取300DPI灰度平场校正参数 + GET_300_GRAY_FLAT_DATA = 27, + //下发序列号命令 + SEND_SERIAL = 28, + //获取序列号命令 + GET_SERIAL = 29, + //获取滚轴数 + GET_ROLLER_NUM = 0x1e, + //清零滚轴数 + CLR_ROLLER_NUM = 0x1f, + //清除扫描总张数 + CLR_SCAN_NUM = 0x20, + //准备更新固件 + PRE_UPGRADE = 0X21, + //开始更新固件 + START_UPGRADE = 0x22, + //彩色的AD参数 + RGB_ADI_PARA = 0x23, + //灰度的AD参数 + ADI_PARA = 0x24, + //获取CIS参数(曝光时间,ad参数) + GET_CIS_PARA = 0x25, + //扫描张数 + START_COMMAND_COUNT = 0x26, + //下发休眠时间 + SET_SLEEP_TIME = 0x27, + //获取休眠时间 + GET_SLEEP_TIME = 0x28, + //清除缓存 + CLR_CACHE = 0x29, + //下发速度模式 + SET_SPEED_MODE = 0x2a, + //获取扫描速度模式 + GET_SPEED_MODE = 0X2b, + //设置固件版本一共8个字节 + SET_FW_VERSION = 0X2c, + //获取DSP版本 + GET_DSP_VERSION = 0X2d, + //采集板FPGA固件版本 + GET_SCANFPGA_VERSION = 0x2e, + //电机板FPGA固件版本 + GET_MOTORFPGA_VERSION = 0X2f, + //设置制造商信息 + SET_USB_INFOR_MANUFACTURE = 0X30, + //获取制造商信息 + GET_USB_INFOR_MANUFACTURE = 0X31, + //设置产品型号信息 + SET_USB_INFOR_MODEL_NAME = 0X32, + //获取产品型号信息 + GET_USB_INFOR_MODEL_NAME = 0X33, + //设置USB PID / VID信息 + SET_USB_INFOR_VIDPID = 0X34, + GET_USB_INFOR_VIDPID = 0X35, + //设置卡纸急停检测灵敏度 + SET_JAM_DETECT_SENSITIVE = 0X36, + //获取卡纸急停检测灵敏度 + GET_JAM_DETECT_SENSITIVE = 0X37, + //设置横向畸变系数 + SET_JUST_COF_H = 0x38, + //读取横向畸变系数 + GET_JUST_COF_H = 0x39, + //G400 清除硬件异常 + CLEAR_HWERROR = 0x40, + //设置纵向畸变系数 + SET_JUST_COF_V = 0x41, + //读取纵向畸变系数 + GET_JUST_COF_V = 0x42, + //设置彩色校正参数 + SEND_COLOR_FLAT = 0x43, + //设置彩色平场校正参数 + SEND_COLORCORRECT_FLAT = 0x44, + //设置灰度校正参数 + SEND_GRAY_FLAT = 0x45, + //设置灰度平场校正参数 + SEND_GRAYCORRECT_FLAT = 0x46, + //设置平场校正参数 + GET_FLAT_DATA =0x47, + //更新完成 + UPDATE_FINISHED = 0x48, + //重启 + REBOOT = 0x49, + //获取日志 + GET_LOG_FILES_INFO = 0x50, + //发送log文件完成 + GET_UPDATE_RESULT=0x51, + //清空日志 + CLEAR_LOG_FILES = 0x52, + //获取搓纸失败 + GET_CUO_ERROR, + //获取双张失败次数 + GET_DOU_ERROR, + //获取卡纸次数 + GET_JAM_ERROR, + ACTIVE_SCANNER=0x100, + //图像处理参数下发 + GETSYSINFO_LEN =0x200, + GETSYSINFO =0x201, + GETMOTORPARAM = 0x202, + GETMOTORPARMLEN=0x203, + SETMOTORPARAM = 0x204, + SETMOTORPARAMLEN = 0x205, + DEVICES_7010 = 0x7010 +}; + +enum class HG_ScannerStatus +{ + //异常 + HAVE_ERROR = -1, + //正常状态 + NORMAL = 0, + //开盖 + OPEN_COVER = 1, + // 无纸 + NO_FEED = 2, + // 搓纸失败 + FEED_IN_ERROR = 4, + // 卡纸 + PAPER_JAM = 8, + // 检测到双张 + DETECT_DOUBLE_FEED = 16, + // 检测到订书钉 + DETECT_STAPLE = 32, + // 纸张倾斜 + PAPER_SKEW = 64, + // 自动模式 + AUTO_SCAN_MODE = 65, + // 手动模式 + MANAUL_SCAN_MODE = 66, + // 计数模式 + COUNT_MODE = 67, + // 硬件错误 + HARDWARE_ERROR = 68, + // FPGA崩溃 + FPGA_ERROR = 68, + // 开始 + START_SCAN = 69, + //停止 + STOP_SCAN = 70, + //有图 + HAVE_IMAGE = 71, + // 更新扫描参数 + UPDATE_SCAN_PARAMETER = 72, + // PC繁忙或出错 + PC_SCAN_BUSY_or_ERROR = 73, + // 更新完成 + UPDATE_FINISHED = 74, + //尺寸检测错误 + SIZE_ERROR=75, + //纸张有孔 + PAPER_HOLE = 84, + //自动校正中 + AUTO_FLATTING=198, + //USB 未连接 + USB_DISCONNECTED = 200, + //用户点击停止 + USER_STOP = 201, + //自动平场校正完成 + AUTO_FLAT_FINISHED = 202, + SCANNER_ACTIVED=0x10 +}; diff --git a/zynq_7010_code/utilsfunc.cpp b/zynq_7010_code/utilsfunc.cpp index 60b609a..a98b720 100644 --- a/zynq_7010_code/utilsfunc.cpp +++ b/zynq_7010_code/utilsfunc.cpp @@ -4,8 +4,8 @@ #include #include #include -#include "filetools.h" - +#include +using namespace std; #define VMRSS_LINE 21 #define VMSIZE_LINE 17 @@ -17,34 +17,6 @@ #define LUT_COLOR_LUT_PATH "/usr/local/huago/color_lut.bmp" #define LUT_GRAY_LUT_PATH "/usr/local/huago/gray_lut.bmp" - - - - -//using namespace cv; - -// cv::Mat extractRepresentRow(const cv::Mat &src) -// { -// LOG("extractRepresentRow2 enter \n"); -// Mat src_temp(src.rows, src.step, CV_8UC1, src.data); -// Mat dst(1, src.cols, CV_8UC(src.channels())); -// Mat dst_temp(1, src.step, CV_8UC1, dst.data); - - -// for (int i = 0, length = src.step; i < length; i++) -// { -// Mat col = src_temp(Rect(i, 0, 1, src_temp.rows)); -// float value = 0; -// for (int j = 0, rows = col.rows; j < rows; j++) -// { -// value += (float)col.at(Point(0, j)) / rows; -// } -// dst_temp.data[i] = (int) value; -// } -// LOG("extractRepresentRow2 exit \n"); -// return dst; -// } - float curve_coffes[2][3][3] = { { {-6e-5, 0.9928, 0.289}, @@ -58,204 +30,6 @@ float curve_coffes[2][3][3] = { } }; - -// cv::Mat create_lut(const cv::Mat &black, const cv::Mat &white,bool colormode,CISVendor vendor) -// { -// LOG("create_lut enter \n"); -// #ifdef G400 -// int channel = 4896 / 12; // 1632*3 -// #else -// int channel = 5184 / 12; // 1728*3 -// #endif - -// const int rows = black.cols / channel; //408 -// const int cols = 256; -// LOG("LUT White width: %d height :%d channels:%d \n", white.cols, white.rows, white.channels()); -// LOG("LUT black width: %d height :%d channels:%d \n", black.cols, black.rows, black.channels()); -// Mat lut(rows, cols, CV_8UC(channel)); -// float* cisCoffoes; -// float* coffoes; -// if(vendor==CISVendor::DUNNAN_CIS_V0) -// cisCoffoes = &curve_coffes[0][0][0]; -// else if(vendor==CISVendor::HUALIN_CIS_V0) -// cisCoffoes = &curve_coffes[1][0][0]; -// else -// { -// cisCoffoes = &curve_coffes[1][0][0]; -// LOG("warnning!!! unknown cis type,use hualin CIS cisCoffoes params \n"); -// } - -// for (size_t i = 0; i < rows; i++) -// { -// Mat lut_row = lut(cv::Rect(0, i, cols, 1)); -// unsigned char *ptr_buffer = lut_row.data; -// unsigned char *ptr_black = black.data + i * channel; -// unsigned char *ptr_white = white.data + i * channel; -// for (size_t j = 0; j < cols; j++) -// { -// for (size_t k = 0; k < channel; k++) -// { -// if (ptr_black[k] >= ptr_white[k]) -// { -// ptr_buffer[j * channel + k] = 0; -// LOG("ptr_black[%d] >= ptr_white[%d]", k, k); -// continue; -// } -// if (j <= ptr_black[k]) -// { -// ptr_buffer[j * channel + k] = 0; -// } -// else if (j >= ptr_white[k]) -// { -// ptr_buffer[j * channel + k] = 255; -// } -// else -// { -// if(colormode==IMAGE_COLOR) -// { -// float val = 255.0 * (j - ptr_black[k]) / (ptr_white[k] - ptr_black[k])*1.2; -// // if (k % 3 == 2) -// // val = pow(10, -6) * pow(val, 3) - 0.0004 * pow(val, 2) + 1.0065 * val - 1.6495; -// // else if (k % 3 == 1) -// // val = 7 * pow(10, -7) * pow(val, 3) - 0.0002 * pow(val, 2) + 0.9861 * val - 0.4419; -// // else -// // val = -pow(10, -7) * 9 * pow(val, 3) + 0.0001 * pow(val, 2) + 1.0627 * val + 1.1538; -// coffoes = cisCoffoes + 3 * (k % 3); -// val = coffoes[0] * val * val + coffoes[1] * val + coffoes[2]; -// if (val > 255) -// val = 255; - -// if (val < 0) -// val = 0; - -// ptr_buffer[j * channel + k] = (unsigned char)val; -// } -// else -// { -// float val = 255.0 * (j - ptr_black[k]) / (ptr_white[k] - ptr_black[k])*1.2; -// if (val > 255) -// val = 255; - -// if (val < 0) -// val = 0; -// ptr_buffer[j * channel + k] = (unsigned char)val; -// } -// } -// } -// } -// } -// LOG("create_lut exit \n"); -// return lut; -// } - -void initLut() -{ - //lutoldGrayMat = cv::imread(LUT_GRAY_LUT_PATH, IMREAD_GRAYSCALE); //灰色校正值 - //lutoldColorMat = cv::imread(LUT_COLOR_LUT_PATH, IMREAD_GRAYSCALE); //彩色校正值 -} - -//void correctColor(cv::Mat src, bool enhance) -//{ - // Mat tSrc; - // Mat lutMat; - // int patch = 0; - // int SIZE = src.cols / 12; - // //printf("lutMat.empty() src.width::%d SIZE: %d \n", src.cols, SIZE); - - // if (src.type() == CV_8UC3) - // { - // patch = (src.cols * 3) / SIZE; - // if (lutoldColorMat.empty()) - // { - // if (access(LUT_COLOR_LUT_PATH, F_OK) != -1) - // { - // lutoldColorMat = imread(LUT_COLOR_LUT_PATH, IMREAD_GRAYSCALE); - // } - // else - // { - // LOG("error error error %s NOT FOUND \n", LUT_COLOR_LUT_PATH); - // return; - // } - // } - // lutMat = lutoldColorMat; - // } - // else - // { - // patch = (src.cols) / SIZE; - // if (lutoldGrayMat.empty()) - // { - // if (access(LUT_GRAY_LUT_PATH, F_OK) != -1) - // { - // lutoldGrayMat = imread(LUT_GRAY_LUT_PATH, IMREAD_GRAYSCALE); - // } - // else - // { - // LOG("error error error %s NOT FOUND", LUT_GRAY_LUT_PATH); - // return; - // } - // } - // lutMat = lutoldGrayMat; - // } - // if (lutMat.empty()) - // { - // return; - // } - // lutMat = cv::Mat(patch, 256, CV_8UC(SIZE), lutMat.data); - // tSrc = cv::Mat(src.rows, patch, CV_8UC(SIZE), src.data); - // for (int i = 0; i < patch; i++) - // { - // LUT(tSrc(cv::Rect(i, 0, 1, src.rows)), lutMat(cv::Rect(0, i, 256, 1)), tSrc(cv::Rect(i, 0, 1, src.rows))); - // } -//} - -// void creatLUTData(int mode,CISVendor vendor) -// { -// LOG("eneter creatLUTData \n"); -// auto colormode = mode == IMAGE_COLOR ? IMREAD_COLOR : IMREAD_GRAYSCALE; -// std::string blackPath = mode == IMAGE_COLOR ? LUT_COLOR_BLACK_PATH : LUT_GRAY_BLACK_PATH; -// std::string whitePath = mode == IMAGE_COLOR ? LUT_COLOR_WHITE_PATH : LUT_GRAY_WHITE_PATH; -// std::string lutsavePath = mode == IMAGE_COLOR ? LUT_COLOR_LUT_PATH : LUT_GRAY_LUT_PATH; -// cv::Mat lut; -// cv::Mat twMat = cv::imread(whitePath, colormode); -// cv::Mat tbMat = cv::imread(blackPath, colormode); -// cv::Mat wMat, bMat; -// if (mode == IMAGE_COLOR) -// { -// wMat = cv::Mat(twMat.rows, twMat.cols * 3, CV_8UC1, twMat.data); -// bMat = cv::Mat(twMat.rows, twMat.cols * 3, CV_8UC1, tbMat.data); -// } -// else -// { -// wMat = twMat; -// bMat = tbMat; -// } - -// lut = create_lut(extractRepresentRow(bMat), extractRepresentRow(wMat),mode,vendor); // add by liuyong: 刘丁维提供 2019/4/12 -// Mat dst(bMat.cols * bMat.channels(), 256, CV_8UC1); -// memcpy(dst.data, lut.data, bMat.cols * bMat.channels() * 256); -// cv::imwrite(lutsavePath, dst); -// LOG("exit creatLUTData \n"); -// } - -// cv::Mat flipRightHalf(Mat &src, int papertype) -// { -// Mat left = src(cv::Rect(0, 0, src.cols / 2, src.rows)); -// Mat right = src(cv::Rect(src.cols / 2, 0, src.cols / 2, src.rows)); -// Mat rightFlip; -// // if (papertype == (int)(PaperSize::G400_A4R)) -// // { -// flip(right, rightFlip, 0); -// // } -// // else -// // { -// // flip(right, rightFlip, 1); -// // } - -// Mat dst; -// hconcat(left, rightFlip, dst); -// return dst; -// } - void SaveScaninfo(const ScannerScanInfo &info) { js_config.SaveScanInfo(info);