zynq_7010/scanservices_utils.h

342 lines
7.9 KiB
C++

#pragma once
#include <string>
#include <functional>
#include <map>
//#include <opencv2/opencv.hpp>
using namespace std;
/*****************************************
* 定义编译版本 *
* G400/G300 *
******************************************/
#define G300
/******************************************
* SPEEDMODE==3 60PPM *
* SPEEDMODE==4 70PPM *
* SPEEDMODE==5 80PPM *
*******************************************/
#define SPEEDMODE 5
#define MT_DEBUG
#define COLORSENSOR_SUP
/*支持低功耗模式开关*/
#define ENABLE_LOWPOWERMODE
/*支持写入系统syslog 功能开关*/
#define ENLOG_SYSLOG
//#define TEST_MODE
//#define __DEBUG__
//#define _LOG
#define IMAGE_COLOR 1
#define IMAGE_GRAY 0
#ifdef _LOG
#define LOG printf
#else
#define LOG
#endif
#ifdef G400
#define FWVERSION "G440220112"
#define SERIALNUM "HG1060A38001P1"
#else
#define FWVERSION "G340230429"
#define SERIALNUM "HS6010A38001P1"
#endif
typedef struct
{
int s_FRAME_COLOR_SP;
int s_FRAME_GRAY_SP;
string FWVERSIO;
}sp_COLOR_or_GRAY;
#define STR(X) #X
#define CON(a,b) STR(a##b)
static std::map<int , sp_COLOR_or_GRAY>mapFradme_SP={
{1,{0x08ED1003,0x1ACC1002,CON(G340,230429)}},//40 ppm
{2,{0x06DB1003,0x14A01002,CON(G350,230429)}},//50 ppm
{3,{0x05591003,0x100E1002,CON(G360,230429)}},//60 ppm
{4,{0x04421003,0x0CD11002,CON(G370,230429)}},//70 ppm
{5,{0x036c1003,0x0A421002,CON(G380,230429)}},//80 ppm
};
enum class LedStatus
{
Ready,
Scanning,
Abnormal,
NoPaper,
StopScan,
CoverOpen,
Updating,
UpdateDone
};
struct HG_JpegCompressInfo
{
unsigned char *pJpegData;
unsigned int DataLength;
};
struct HG_Msg{
int code;
std::string msg;
};
enum class CISVendor
{
CIS_UNKNOWUN,
HUALIN_CIS_V0,
DUNNAN_CIS_V0,
DUNNAN_CIS_COLOR_V0
};
enum class PaperSize
{
G400_A3 = 0,
G400_A4,
G400_A4R,
G400_A5,
G400_A5R,
G400_A6,
G400_A6R,
G400_B4,
G400_B5,
G400_B5R,
G400_B6,
G400_B6R,
G400_DOUBLELETTER,
G400_LEGAL,
G400_LETTER,
G400_LETTERR,
G400_LONGLETTER,
G400_MAXSIZE,
G400_AUTO,
G400_MAXAUTO
};
struct HGSize
{
unsigned int width;
unsigned int height;
bool operator<(HGSize const &right) const
{
if (width < right.width && height < right.height)
return true;
return false;
}
};
typedef struct Paper_Res
{
Paper_Res(unsigned int res,PaperSize papertype):Res(res),PaperType(papertype){}
Paper_Res():Res(0),PaperType(PaperSize::G400_A4){}
unsigned int Res;
PaperSize PaperType;
friend bool operator<(const struct Paper_Res &a,const struct Paper_Res &b)
{
if(a.Res<b.Res || (a.Res==b.Res && a.PaperType < b.PaperType)){
return true;
}
return false;
}
}PaperRes;
static std::map<PaperRes,HGSize> supportPapers={
{{1,PaperSize::G400_A4},{3672,12000}},//300dpi
{{0,PaperSize::G400_A4},{7344,16000}},//600dpi
};
/*
*支持的幅面
*/
#ifdef G400
static std::map<PaperSize, HGSize> papersMap = {
{PaperSize::G400_A3, {1632, 10800}},
{PaperSize::G400_A4, {1632, 8100}},
{PaperSize::G400_A4R, {1632, 6000}},
{PaperSize::G400_A5, {1632, 8100}},
{PaperSize::G400_A5R, {1632, 8100}},
{PaperSize::G400_A6, {1632, 6000}},
{PaperSize::G400_A6R, {1632, 6000}},
{PaperSize::G400_B4, {1632, 10800}},
{PaperSize::G400_B5, {1632, 10800}},
{PaperSize::G400_B5R, {1632, 10800}},
{PaperSize::G400_B6, {1632, 6000}},
{PaperSize::G400_DOUBLELETTER, {1632, 10800}},
{PaperSize::G400_B6R, {1632, 6000}},
{PaperSize::G400_LEGAL, {1632, 10800}},
{PaperSize::G400_LETTER, {1632, 8100}},
{PaperSize::G400_MAXSIZE, {1632, 16002}},
{PaperSize::G400_AUTO, {1632, 10800}},
{PaperSize::G400_MAXAUTO, {1632, 16002}},
};
#else
static std::map<PaperSize, HGSize> papersMap = {
{PaperSize::G400_A3, {1728, 8100}},
{PaperSize::G400_A4, {1728, 8100}},
{PaperSize::G400_A4R, {1728, 8100}},
{PaperSize::G400_A5, {1728, 8100}},
{PaperSize::G400_A5R, {1728, 8100}},
{PaperSize::G400_A6, {1728, 8100}},
{PaperSize::G400_A6R, {1728, 8100}},
{PaperSize::G400_B4, {1728, 10800}},
{PaperSize::G400_B5, {1728, 10800}},
{PaperSize::G400_B5R, {1728, 10800}},
{PaperSize::G400_B6, {1728, 10800}},
{PaperSize::G400_B6R, {1728, 10800}},
{PaperSize::G400_DOUBLELETTER, {1728, 10800}},
{PaperSize::G400_LEGAL, {1728, 10800}},
{PaperSize::G400_LETTER, {1728, 10800}},
{PaperSize::G400_MAXSIZE, {1728, 16200}},
};
#endif
static std::map<PaperSize,int> paperHeight={
{PaperSize::G400_A3, 475},
{PaperSize::G400_A4, 317},
{PaperSize::G400_A4R, 237},
{PaperSize::G400_A5, 317},
{PaperSize::G400_A5R, 317},
{PaperSize::G400_A6, 237 },
{PaperSize::G400_A6R, 237},
{PaperSize::G400_B4, 373},
{PaperSize::G400_B5, 270},
{PaperSize::G400_B5R, 237},
{PaperSize::G400_B6, 237},
{PaperSize::G400_DOUBLELETTER, 460},
{PaperSize::G400_B6R, 237},
{PaperSize::G400_LEGAL, 376},
{PaperSize::G400_LETTER, 299},
{PaperSize::G400_LETTERR, 236},
{PaperSize::G400_MAXSIZE, 3050},//300 dpi max heigth
#ifdef G300
{PaperSize::G400_AUTO, 635},//300 dpi max heigth
#else
{PaperSize::G400_AUTO, 860},//300 dpi max heigth
#endif
{PaperSize::G400_MAXAUTO, 3050}//300 dpi max heigth
};
union HG_ScanConfiguration
{
struct
{
unsigned int pageSize : 5;
unsigned int isColor : 1;
unsigned int dpi : 2;
unsigned int doubleFeeded : 1;
unsigned int enableStable : 1;
unsigned int enableLed : 1;
unsigned int enableSizeDetect : 1;
unsigned int lutmode : 1 ;
unsigned int reversed1 : 4;
unsigned int isCorrect : 1;
unsigned int dstHeight : 8;
unsigned int reversed2 : 6;
} params;
unsigned int value;
};
union VIDPID
{
struct
{
unsigned short VID;
unsigned short PID;
};
unsigned int Value;
};
struct ScannerGlue
{
ScannerGlue(const std::function<void(const HG_JpegCompressInfo &imginfo)> &imageready, const std::function<void(const int eventID,std::string)> &deviceevent) : m_imageready(imageready), m_deviceevent(deviceevent) {}
std::function<void(const HG_JpegCompressInfo &)> m_imageready;
std::function<void(const int,std::string)> m_deviceevent;
};
struct V4L2_DATAINFO
{
//cv::Mat mat;
char *data;
int width;
int height;
int pixtype;
};
struct V4L2_DATAINFO_Ex:V4L2_DATAINFO
{
unsigned int snaped_index;
unsigned int frame_index;
unsigned int dpi;
unsigned int error_code;
bool lost_frame;
bool last_frame;
bool snap_end;
};
typedef struct CaptureParams
{
int correctColorExposure[2][3];
int correctColorGain[2][6];
int correctColorOffset[2][6];
int correctGrayExposure[2][3];
int correctGrayGain[2][6];
int correctGrayOffset[2][6];
int colorExposure[2][3];
int colorGain[2][6];
int colorOffset[2][6];
int grayExposure[2][3];
int grayGain[2][6];
int grayOffset[2][6];
int uvCorrectColorExposure[2];
int uvCorrectGrayExposure[2];
int uvColorExposure[2];
int uvGrayExposure[2];
} CaptureParams;
struct ScannerScanInfo
{
unsigned int TotalScanned; //扫描总页数
unsigned int RollerNum;
unsigned int CuoNum; //搓纸总数
unsigned int JamInNum; //搓纸失败次数
unsigned int JamOutNum; //卡纸次数
unsigned int DoubleNum; //双张次数
unsigned int ErrorNum; //其他异常次数
unsigned int HRatio; //横向校正系数
unsigned int VRatio; //纵向校正系数
unsigned int SleepTime; //休眠时间 单位s
unsigned int SpeedMode; //速率模式
unsigned int VID; //vid
unsigned short PID; //pid
std::string SerialNum; //序列号
std::string FWVersion; //固件版本号
std::string Token; //token 令牌
};
constexpr char BULK_CTL_PATH[] = "/dev/usb-ffs/mtp/ep0";
constexpr char BULK_OUT_PATH[] = "/dev/usb-ffs/mtp/ep2";
constexpr char BULK_IN_PATH[] = "/dev/usb-ffs/mtp/ep1";
constexpr char BULK_INT_PATH[] = "/dev/usb-ffs/mtp/ep3";
constexpr char STATE_PATH[] = "/sys/class/android_usb/android0/state";