diff --git a/Parameters.h b/Parameters.h deleted file mode 100644 index a09a028..0000000 --- a/Parameters.h +++ /dev/null @@ -1,101 +0,0 @@ -#pragma once -#include - -//#define Color 3 - -typedef enum Scan_Mode -{ - SM_GRAY, - SM_COLOR -} ScanMode; - -const std::string ScanPaperTypes[] = -{ - "A4", - "A3" -}; - -const int SPTSizes[] = {1728, 1632}; - -typedef enum Scan_Paper_Type -{ - SPT_A4, - SPT_A3 -}ScanPaperType; - -#ifdef A3 - - // 图像像素值 - #define IMG_HEIGHT 3600 - #define IMG_WIDTH 2592 * 2 - #define SPI_COLOR 0x04501003 //0x0cf01002, 0x04501003 - #define SPI_GRAY 0x0cf01002 - - // 300 dpi 图像宽度像素值(目前仅为双面扫描,故尺寸为单面尺寸乘以2) - #define IMG_WIDTH_300DPI 3672 * 2 - - // 200 dpi 图像宽度像素值(目前仅为双面扫描,故尺寸为单面尺寸乘以2) - #define IMG_WIDTH_200DPI 2448 * 2 - - #define IMG_WIDTH_150DPI 1836 * 2 - - #define IMG_HEIGHT_200DPI IMG_HEIGHT - - #define IMG_HEIGHT_300DPI IMG_HEIGHT * 1.5 - - #define IMG_HEIGHT_150DPI IMG_HEIGHT * 0.75 - - //原始图像相对于200dpi的倍数 - #define IMG_W_RADIO 1 - #define IMG_H_RADIO 1 - #define FRAME_COUNT 4 - - -#else - // 300 dpi 图像宽度像素值(目前仅为双面扫描,故尺寸为单面尺寸乘以2) - -#define IMG_WIDTH_300DPI 2592 * 2 - - // 200 dpi 图像宽度像素值(目前仅为双面扫描,故尺寸为单面尺寸乘以2) -#define IMG_WIDTH_200DPI 1728 * 2 - -#define IMG_WIDTH_150DPI 1296 * 2 - - -#define IMG_HEIGHT_200DPI 3600 - -#define IMG_HEIGHT_300DPI 4050 - -#define IMG_HEIGHT_150DPI 2025 - - //原始图像相对于200dpi 系数 -#define IMG_W_RADIO 1/1.5 -#define IMG_H_RADIO 1 - - // 图像像素值 - - - - -#ifdef HAS_UV -// #define SPI_COLOR 0x03D81001 -// #define SPI_GRAY 0x13001000 - #define SPI_COLOR 0x05181001 - #define SPI_GRAY 0x19501000 -// 0x19501000, 0x05181001 -#else -const int SPI_SP = 0x04b0; -const int SPI_SAMPLE = 256; -const int SPI_COLOR_MODE = SM_COLOR; -const int SCAN_PAPER_TYPE = SPT_A4; -#endif - -const int IMG_HEIGHT = 9000; -const int IMG_V4L_WIDTH = SPTSizes[SCAN_PAPER_TYPE]; -const int FRAME_COUNT = 3; -const int TEST_FRAME = 1; -const int TEST_ENABLE = 0; -const int LED_ENABLE = 1; -const bool SAVE_ENABLE = true; - -#endif diff --git a/Properties.cpp b/Properties.cpp index ad5bd19..9f4eb74 100644 --- a/Properties.cpp +++ b/Properties.cpp @@ -18,11 +18,10 @@ std::string Properties::GetProperty(const std::string& key) const { } -//ǰļȡ ֳkeyvalmapmapȡval std::string Properties::GetProperty(const std::string& key, const std::string& defaultValue) const { if (key.compare("fpga.correctColor.BOffset") == 0) - printf("Get Config File Size (path: /usr/local/huago/ properties ) = %d \r\n",properties.size()); + printf("Get Config File Size (path: /usr/local/huago/ ��properties�� ) = %d \r\n",properties.size()); if (properties.find(key) == properties.end()) { return defaultValue; } @@ -34,7 +33,7 @@ std::vector Properties::GetPropertyNames() const { return keys; } -//ļдmap +//�������ļ�����д��map void Properties::AddProperty(const std::string& key, const std::string& value) { if (properties.find(key) == properties.end()) { keys.push_back(key); diff --git a/Scanner.cpp b/Scanner.cpp index d3c4053..4b8c86a 100644 --- a/Scanner.cpp +++ b/Scanner.cpp @@ -37,7 +37,6 @@ Scanner::Scanner(ScannerGlue glue) { if (fc.updatefpga()) { - //system("sh /etc/reloadfpga.sh"); system("poweroff"); } else @@ -77,17 +76,14 @@ Scanner::Scanner(ScannerGlue glue) motorZouzhi.setSpeed(4000); motorCuozhi.setSpeed(3000); motorCuozhi.setDirection(false); - //sensor->isPaperAtScan(); - //system("cat /sys/class/gpio/gpio226/value"); - //sensor->enableDoubleSensor(true); + std::this_thread::sleep_for(std::chrono::milliseconds(50)); - //sensor->enableDoubleSensor(false); + FsmState::setScanner(this); threadRunMessageLoop = std::thread(&Scanner::runMessageLoop, this); Motor::enablePower(true); this_thread::sleep_for(std::chrono::milliseconds(200)); - //meminfo = MemoryInfo::GetInstance(); - //GetSysInfo(); + } Scanner::~Scanner() @@ -111,18 +107,11 @@ void Scanner::updateSpeedMode(int speed) m_scaninfo.SpeedMode=3; printf("速度模式:%d dpi:%d 颜色:%d \n",m_scaninfo.SpeedMode,m_config.params.dpi,m_config.params.isColor); unsigned int t_dpi = m_config.params.dpi; - // if(typeid(*capturer)==typeid(MonoCapturer)) - // { - // if(m_config.params.dpi==0x03&& m_scansysinfo->IsSmallRam()) - // t_dpi=0x02; - // else - // t_dpi = m_config.params.dpi; - // } + if(typeid(*capturer)==typeid(MultiFrameCapture)) if(m_config.params.pageSize == 17 || m_config.params.pageSize == 19) //长文稿采用600dpi模式扫描 t_dpi = 3; - motorCuozhi.speedChange(m_scaninfo.SpeedMode, t_dpi,m_config.params.isColor); motorZouzhi.speedChange(m_scaninfo.SpeedMode, t_dpi,m_config.params.isColor); } @@ -149,19 +138,15 @@ void Scanner::runMessageLoop() while (bMsgLoop) { ScanEvent evt = sysEvent.Take(); - //LOG("\n---------------------%d--------------------------\n", evt); fsmState = fsmState->on_event(evt); - //printf("current fsmState =%s ",typeid(*fsmState).name()); processevent(fsmState, evt); } } void Scanner::processevent(FsmState *fsmState, ScanEvent event) { - LOG("processevent Event:%d\n", (int)event); if (fsmState == nullptr) { - LOG("processevent BBBBBBBBBBBBBB Event:%d\n", (int)event); return; } @@ -211,20 +196,14 @@ void Scanner::runScan() motorZouzhi.start(); motorCuozhi.pauseWaitForThread(); - if (!isPaperInit) { - - preFeed(); - + preFeed(); isPaperInit = true; } - this_thread::sleep_for(std::chrono::milliseconds(200)); imageindex = 0; - //*capturer->setFPGATriggerMode(false, 0); - - //capturer->setFanMode(3); + sensor->resetPaperPin(); @@ -248,22 +227,15 @@ void Scanner::runScan() { if (!sensor->waitPaperStandBy(0)) { - // this_thread::sleep_for(std::chrono::milliseconds(200)); put(S_EVT_STOP_SCAN); LOG("STOP STOP STOP RUNSCAN \n"); } break; } - else - { - //LOG(" Detect Feeder loaded ,Paper Ready !!! \n"); - } - sensor->enableDoubleSensor(m_config.params.doubleFeeded); - //LOG("enableDoubleSensor QQQQQQQ:%s %s\n", m_config.params.doubleFeeded ? "true" : "false",GetCurrentTimeStamp(2).c_str()); + if (m_DstScannum == 0) //被取消扫描了 { - LOG("canceled canceled canceled 999999999999999999999999999999999999999999 \n"); break; } @@ -271,14 +243,12 @@ void Scanner::runScan() if (!sensor->isPaperStandby()) { put(S_EVT_STOP_SCAN); - LOG("START SCAN LOOP STOP STOP STOP\n"); isRested = false; break; } isRested = false; if (!sensor->waitPaperIn(3000))// { - LOG("START SCAN LOOP S_EVT_JAM_IN S_EVT_JAM_IN S_EVT_JAM_IN\n"); if (!m_isDoublePaper) { m_glue.m_deviceevent(4, "Feed error"); @@ -308,7 +278,6 @@ void Scanner::runScan() max = 200; } - LOG("paper pauseWaitForThread \n"); waitpapertime = 200; sw2.reset(); while (!sensor->waitPaperOut(waitpapertime) && i < max) @@ -321,8 +290,6 @@ void Scanner::runScan() break; } } - printf("等待纸张出去?????????????%f\r\n",sw2.elapsed_ms()); - LOG("paper isPaperIn \n"); if (i == max && sensor->isPaperIn()) { @@ -343,7 +310,6 @@ void Scanner::runScan() capturer->stopsnap(b_autosize); capturer->waitsnapdone(1);//等待采集完成 this_thread::sleep_for(std::chrono::milliseconds(500));//200 80ms 600 260ms - LOG("\n ----------------EXIT 11111---------------- \n"); break; } //LOG("\nclose double sensor %s\n",GetCurrentTimeStamp(2).c_str()); @@ -366,8 +332,6 @@ void Scanner::runScan() { delay = 0; } - - //LOG("AutoSize sleep_for delay=%d \n",delay); this_thread::sleep_for(std::chrono::milliseconds(delay));//200 80ms 600 260ms } if(b_autosize) @@ -387,10 +351,8 @@ void Scanner::runScan() capturer->stopsnap(b_autosize); break; } - //std::this_thread::sleep_for(std::chrono::milliseconds(50)); } - LOG("\nclose b_autosize %s\n",GetCurrentTimeStamp(2).c_str()); capturer->stopsnap(b_autosize); capturer->waitsnapdone(m_isDoublePaper || m_jamPaper);//等待采集完成 m_DstScannum--; @@ -399,7 +361,6 @@ void Scanner::runScan() if (m_DstScannum == 0) { - LOG("\n ----------------EXIT 2222 cnt=%d---------------- \n",m_DstScannum); this_thread::sleep_for(std::chrono::milliseconds(200)); put(S_EVT_STOP_SCAN); @@ -422,8 +383,6 @@ void Scanner::runScan() printf("一张纸完成时间:%f\r\n",sw1.elapsed_ms()); if( m_config.params.dpi == 3) this_thread::sleep_for(std::chrono::milliseconds(3000)); - //else if( m_config.params.dpi == 1) - //this_thread::sleep_for(std::chrono::milliseconds(50)); } m_DstScannum = 0; @@ -438,8 +397,6 @@ void Scanner::runScan() capturer->setFanMode(0); - //capturer->close(); - LOG("\n--------------------------scan done --------------------------------\n"); } @@ -447,7 +404,6 @@ void Scanner::runScan() void Scanner::CreatCorrectData(int correctmode) { m_correctting = true; - LOG("\n-----------------校正模式 %d-----------------------\n",correctmode); capturer->createCorrect(correctmode); } @@ -463,7 +419,7 @@ void Scanner::preFeed() std::string Scanner::GetSysInfo() { meminfo = MemoryInfo::GetInstance(); - LOG(" GetSysInfo-------- \n"); + auto scannerinfo = GetScanInfo(); auto fwverion = mapFradme_SP[scannerinfo.SpeedMode].FWVERSIO; ScannerSysInfo info = { @@ -482,7 +438,7 @@ std::string Scanner::GetSysInfo() .Have_EthernPort = 0, .ServiceVersion = fwverion, .UsbProtocol = 1.0}; - LOG("FPGAVersion=%08x \n",info.FPGAVersion); + m_scansysinfo.reset(new SysInforTool(info)); return m_scansysinfo->GetSysInfo(); } diff --git a/Sensor.cpp b/Sensor.cpp index dccf172..e8c474f 100644 --- a/Sensor.cpp +++ b/Sensor.cpp @@ -152,43 +152,41 @@ void Sensor::monitor() while (bMonitor) { ret = poll(&pfd, 1, 1000); - if (ret > 0) + if (ret <= 0) { - if (pfd.revents & POLLPRI) - { - LOG(" ------------------------ scanpin running--------------------- \n"); - lseek(pfd.fd, 0, SEEK_SET); - num = read(pfd.fd, buf, 8); - buf[num - 1] = '\0'; - ret = atoi(buf); - //ftt.append_log(ret?"in":"out"); - if (ret) - { - - printf("检测纸张进入 time:%f\r\n",sw2.elapsed_ms()); - sw1.reset(); - }else - { - printf("检测纸张出去 time:%f\r\n",sw1.elapsed_ms()); - sw2.reset(); - } - - edges[ret]->notify_all(); - printf("\n *************scanpin %d time = %s ********* \n",ret,GetCurrentTimeStamp(2).c_str()); - //sw.reset(); - while(sw.elapsed_ms() < 10) - { - ret = poll(&pfd, 1, 1); - if (ret > 0) - { - num = read(pfd.fd, buf, 8); - buf[num - 1] = '\0'; - ret = atoi(buf); - //printf("pMonitor nread = %d ret val = %d \n",num,ret); - } - } - } + continue; } + if (pfd.revents & POLLPRI) + { + + lseek(pfd.fd, 0, SEEK_SET); + num = read(pfd.fd, buf, 8); + buf[num - 1] = '\0'; + ret = atoi(buf); + //ftt.append_log(ret?"in":"out"); + if (ret) + { + printf("检测纸张进入 time:%f\r\n",sw2.elapsed_ms()); + sw1.reset(); + } + else + { + printf("检测纸张出去 time:%f\r\n",sw1.elapsed_ms()); + sw2.reset(); + } + edges[ret]->notify_all(); + + while(sw.elapsed_ms() < 10) + { + ret = poll(&pfd, 1, 1); + if (ret > 0) + { + num = read(pfd.fd, buf, 8); + buf[num - 1] = '\0'; + ret = atoi(buf); + } + } + } } close(pfd.fd); @@ -209,16 +207,12 @@ void Sensor::monitor2() int fd = -1; char buf[8]; int num; - //LOG(" ------------------------ monitor2 running \n"); - for (size_t i = 0; i < gpios.size(); ++i) { fd = open(gpios[i]->getValuePath().c_str(), O_RDONLY); - //LOG(" ------------------------ monitor2 open gpio[%d]=%s \n",i,gpios[i]->getValuePath().c_str()); if (fd < 0) { ret = -1; - LOG(" ------------------------ monitor2 open break \n"); break; } @@ -228,75 +222,54 @@ void Sensor::monitor2() pollfds.push_back(pfd); } - //LOG(" ------------------------ monitor2 while running \n"); if (ret >= 0) { bMonitor2 = true; while (bMonitor2) { - static int poll_t = 0; - ret = poll(&pollfds[0], pollfds.size(), 1000); - //LOG(" ------------------------ monitor2 while running poll_t=%d ret=%d \n",++poll_t,ret); - if (ret > 0) + if (ret < 0) { - for (size_t i = 0; i < pollfds.size(); ++i) + continue; + } + for (size_t i = 0; i < pollfds.size(); ++i) + { + if (pollfds[i].revents) { - if (pollfds[i].revents) - { - ret = readfile(pollfds[i].fd,num,buf); - //LOG("event id : %d i= %d \n",evts[i * 2 + ret] , i ); - // if(evts[i * 2 + ret] == 272) - // { - // //LOG("\n\n---------------double paper ----------------:%s \n\n", GetCurrentTimeStamp(2).c_str()); - // enableDoubleSensor(false); - // } - if (i == 2) - { - double_1 = ret; - printf("2 double_1 :%d double_2:%d\r\n",double_1,double_2); - if (double_2 && double_1 && enbale_double_) - { - printf("双张111111111111111111111111\r\n"); - events.Put(ScanEvent(S_EVT_DOUBLEPAPER)); - enableDoubleSensor(false); - } - else - { - //printf("3 double_1 :%d double_2:%d\r\n",double_1,double_2); - //events.Put(ScanEvent(S_EVT_NOT_DOUBLEPAPER)); - } - } - if (i == 3) - { - double_2 = ret; - printf("3 double_1 :%d double_2:%d\r\n",double_1,double_2); - if (double_2 && double_1 && enbale_double_) - { - printf("双张2222222222222222222222\r\n"); - events.Put(ScanEvent(S_EVT_DOUBLEPAPER)); - enableDoubleSensor(false); - } - else - { - //printf("4 double_1 :%d double_2:%d\r\n",double_1,double_2); - //events.Put(ScanEvent(S_EVT_NOT_DOUBLEPAPER)); - } - } - if (i != 2 && i != 3) - { - if(i == 1) - { - //LOG("paper sensor ret:%d \n", ret); - cv_paper_on.notify_all(); - } - events.Put(evts[i * 2 + ret]); - } + ret = readfile(pollfds[i].fd,num,buf); + if (i == 2) + { + double_1 = ret; + printf("2 double_1 :%d double_2:%d\r\n",double_1,double_2); + if (double_2 && double_1 && enbale_double_) + { + events.Put(ScanEvent(S_EVT_DOUBLEPAPER)); + enableDoubleSensor(false); + } } + if (i == 3) + { + double_2 = ret; + printf("3 double_1 :%d double_2:%d\r\n",double_1,double_2); + if (double_2 && double_1 && enbale_double_) + { + events.Put(ScanEvent(S_EVT_DOUBLEPAPER)); + enableDoubleSensor(false); + } + + } + if (i != 2 && i != 3) + { + if(i == 1) + { + cv_paper_on.notify_all(); + } + events.Put(evts[i * 2 + ret]); + } } - } + } } } diff --git a/scanservices_utils.h b/scanservices_utils.h index 4181ebc..3b47617 100644 --- a/scanservices_utils.h +++ b/scanservices_utils.h @@ -25,10 +25,6 @@ using namespace std; /*支持写入系统syslog 功能开关*/ #define ENLOG_SYSLOG -//#define TEST_MODE - -//#define __DEBUG__ -//#define _LOG #define IMAGE_COLOR 1 @@ -40,14 +36,9 @@ using namespace std; #define LOG //printf #endif -#ifdef G400 -#define FWVERSION "G440220112" -#define SERIALNUM "HG1060A38001P1" -#else - #define FWVERSION "G345230918" #define SERIALNUM "HS6010A38001P1" -#endif + typedef struct { int s_FRAME_COLOR_SP;