#include "jsonconfig.h" #include #include #include #include #include #include #define SP_COLOR_DEFAULT 0x438 #define SP_GRAY_DEFAULT 0xca8 jsonconfig::jsonconfig() { } jsonconfig::~jsonconfig() { } void jsonconfig::savecisconfig(HGCorrectConfigs configs) { if (access(JSON_CORRECTDIR_PATH, 0) == -1) { auto ret = mkdir(JSON_CORRECTDIR_PATH, 0777); if (ret != 0) { printf("make dir failed .path=%s \n", JSON_CORRECTDIR_PATH); } } json m_json; m_json[STRCON(STR_COLOR, STR_EXPF)] = configs.color.expF; m_json[STRCON(STR_COLOR, STR_EXPB)] = configs.color.expB; m_json[STRCON(STR_COLOR, STR_GAINF)] = configs.color.gainF; m_json[STRCON(STR_COLOR, STR_GAINB)] = configs.color.gainB; m_json[STRCON(STR_COLOR, STR_OFFSETF)] = configs.color.offsetsF; m_json[STRCON(STR_COLOR, STR_OFFSETB)] = configs.color.offsetsB; if(configs.color.sp <= 0 ){ configs.color.sp = SP_COLOR_DEFAULT; } m_json[STRCON(STR_COLOR, STR_SP)] = configs.color.sp; m_json[STRCON(STR_CORRECTCOLOR, STR_EXPF)] = configs.colorCorrect.expF; m_json[STRCON(STR_CORRECTCOLOR, STR_EXPB)] = configs.colorCorrect.expB; m_json[STRCON(STR_CORRECTCOLOR, STR_GAINF)] = configs.colorCorrect.gainF; m_json[STRCON(STR_CORRECTCOLOR, STR_GAINB)] = configs.colorCorrect.gainB; m_json[STRCON(STR_CORRECTCOLOR, STR_OFFSETF)] = configs.colorCorrect.offsetsF; m_json[STRCON(STR_CORRECTCOLOR, STR_OFFSETB)] = configs.colorCorrect.offsetsB; if(configs.colorCorrect.sp <= 0 ){ configs.colorCorrect.sp = SP_COLOR_DEFAULT; } m_json[STRCON(STR_CORRECTCOLOR, STR_SP)] = configs.colorCorrect.sp; m_json[STRCON(STR_GRAY, STR_EXPF)] = configs.gray.expF; m_json[STRCON(STR_GRAY, STR_EXPB)] = configs.gray.expB; m_json[STRCON(STR_GRAY, STR_GAINF)] = configs.gray.gainF; m_json[STRCON(STR_GRAY, STR_GAINB)] = configs.gray.gainB; m_json[STRCON(STR_GRAY, STR_OFFSETF)] = configs.gray.offsetsF; m_json[STRCON(STR_GRAY, STR_OFFSETB)] = configs.gray.offsetsB; if(configs.gray.sp <= 0 ){ configs.gray.sp = SP_GRAY_DEFAULT; } m_json[STRCON(STR_GRAY, STR_SP)] = configs.gray.sp; m_json[STRCON(STR_CORRECTGRAY, STR_EXPF)] = configs.grayCorrect.expF; m_json[STRCON(STR_CORRECTGRAY, STR_EXPB)] = configs.grayCorrect.expB; m_json[STRCON(STR_CORRECTGRAY, STR_GAINF)] = configs.grayCorrect.gainF; m_json[STRCON(STR_CORRECTGRAY, STR_GAINB)] = configs.grayCorrect.gainB; m_json[STRCON(STR_CORRECTGRAY, STR_OFFSETF)] = configs.grayCorrect.offsetsF; m_json[STRCON(STR_CORRECTGRAY, STR_OFFSETB)] = configs.grayCorrect.offsetsB; if(configs.grayCorrect.sp <= 0 ){ configs.grayCorrect.sp = SP_GRAY_DEFAULT; } m_json[STRCON(STR_CORRECTGRAY, STR_SP)] = configs.grayCorrect.sp; std::cout << m_json << std::endl; std::ofstream o(JSON_CORRECTFILE_PATH); o << std::setw(4) << m_json << std::endl; o.close(); } HGCorrectConfigs jsonconfig::getcorrectconfigs() { HGCorrectConfigs cfs; if (access(JSON_CORRECTDIR_PATH, 0) == -1) { auto ret = mkdir(JSON_CORRECTDIR_PATH, 0777); if (ret != 0) { printf("make dir failed .path=%s \n", JSON_CORRECTDIR_PATH); } } if (access(JSON_CORRECTFILE_PATH, F_OK) != 0) { cfs = getdefaultconfigs(); savecisconfig(cfs); return cfs; } std::ifstream i(JSON_CORRECTFILE_PATH); auto pos = i.tellg(); i.seekg(0, std::ios::end); //printf("file length =%d ", i.tellg()); if (i.tellg() <= 2) { cfs = getdefaultconfigs(); savecisconfig(cfs); return cfs; } i.seekg(pos); json m_json; i >> m_json; i.close(); cfs.colorCorrect.sp = cfs.color.sp = SP_COLOR_DEFAULT; cfs.grayCorrect.sp = cfs.gray.sp = SP_GRAY_DEFAULT; std::cout <<"GET GET GET GET GET GET" < lc(mtx); ScannerNativeParam snp; if (access(JSON_SCANNER_INFO_DIR, 0) == -1) { auto ret = mkdir(JSON_SCANNER_INFO_DIR, 0777); if (ret != 0) { printf("make dir failed .path=%s \n", JSON_SCANNER_INFO_DIR); } } if (access(JSON_SCANNER_INFO_FILE, 0) == -1) { printf("\nerror !!! file no exist"); snp = getdefaultscannerinfo(); savescannerinfo(snp); return snp; } std::ifstream i(JSON_SCANNER_INFO_FILE); auto pos = i.tellg(); i.seekg(0, std::ios::end); //printf("file length =%d ", i.tellg()); if (i.tellg() <= 2) { printf("\nerror !!! file data error"); snp = getdefaultscannerinfo(); savescannerinfo(snp); return snp; } i.seekg(pos); json m_json; i >> m_json; if (!m_json[S_INFO_DOUNUM].is_null()) m_json[S_INFO_DOUNUM].get_to(snp.DoubleFeedTimes); else snp.DoubleFeedTimes = 0; if (!m_json[S_INFO_FEEDERROR].is_null()) m_json[S_INFO_FEEDERROR].get_to(snp.FeedErrorTimes); else snp.FeedErrorTimes = 0; if (!m_json[S_INFO_HRATIO].is_null()) m_json[S_INFO_HRATIO].get_to(snp.H_ratio); else snp.H_ratio = 1065353216; if (!m_json[S_INFO_JAMNUM].is_null()) m_json[S_INFO_JAMNUM].get_to(snp.JamTimes); else snp.JamTimes = 0; if (!m_json[S_INFO_ROLLERNUM].is_null()) m_json[S_INFO_ROLLERNUM].get_to(snp.RollerNum); else snp.RollerNum = 0; if (!m_json[S_INFO_SCANSESSIONCOUNT].is_null()) m_json[S_INFO_SCANSESSIONCOUNT].get_to(snp.ScanSessionsCount); else snp.ScanSessionsCount = 0; if (!m_json[S_INFO_SERIALNUM].is_null()) m_json[S_INFO_SERIALNUM].get_to(snp.SerialNum); else snp.SerialNum = SERIALNUM; if (!m_json[S_INFO_TOKEN].is_null()) m_json[S_INFO_TOKEN].get_to(snp.Token); else snp.Token = "abcdefghijklmnopqrstuvwxyz012345"; if (!m_json[S_INFO_TOTALSCANNED].is_null()) m_json[S_INFO_TOTALSCANNED].get_to(snp.TotalScanned); else snp.TotalScanned = 0; if (!m_json[S_INFO_VRATIO].is_null()) m_json[S_INFO_VRATIO].get_to(snp.V_ratio); else snp.V_ratio = 1065353216; if (!m_json[S_COLOR_SP].is_null()) m_json[S_COLOR_SP].get_to(snp.color_sp); else #ifdef G200 snp.color_sp = 0x27C; #else snp.color_sp = 0x2B6; #endif if (!m_json[S_GRAY_SP].is_null()) m_json[S_GRAY_SP].get_to(snp.gray_sp); else #ifdef G200 snp.gray_sp = 0x775; #else snp.gray_sp = 0x822; #endif if(!m_json[S_INFO_SLEEPTIME].is_null()) m_json[S_INFO_SLEEPTIME].get_to(snp.sleeptime); else snp.sleeptime = 10800; if(!m_json[S_INFO_CLR_MAXBRT].is_null()) m_json[S_INFO_CLR_MAXBRT].get_to(snp.clr_maxbright); else snp.clr_maxbright=200; if(!m_json[S_INFO_GRAY_MAXBRT].is_null()) m_json[S_INFO_GRAY_MAXBRT].get_to(snp.gray_maxbright); else snp.gray_maxbright=200; if(!m_json[S_INFO_SPEEDMODE].is_null()) m_json[S_INFO_SPEEDMODE].get_to(snp.speedmode),printf("\n %s Get speedmode value = %d",JSON_SCANNER_INFO_FILE,snp.speedmode); else snp.speedmode=0,printf("\n %s Get speedmode failed ",JSON_SCANNER_INFO_FILE); if(!m_json[S_INFO_PID].is_null()) m_json[S_INFO_PID].get_to(snp.Pid); else { #ifdef G100 snp.Pid = 0x139; #else snp.Pid = 0x239; #endif } if(!m_json[S_INFO_VID].is_null()) m_json[S_INFO_VID].get_to(snp.Vid); else snp.Vid = 0x3072; if(!m_json[S_INFO_CHUZHI_MOTOR_SPEED_200].is_null()) m_json[S_INFO_CHUZHI_MOTOR_SPEED_200].get_to(snp.chu_motor_speed_200); else snp.chu_motor_speed_200 = 300; if(!m_json[S_INFO_CHUZHI_MOTOR_SPEED_300].is_null()) m_json[S_INFO_CHUZHI_MOTOR_SPEED_300].get_to(snp.chu_motor_speed_300); else snp.chu_motor_speed_300 = 200; if(!m_json[S_INFO_CHUZHI_MOTOR_SPEED_600].is_null()) m_json[S_INFO_CHUZHI_MOTOR_SPEED_600].get_to(snp.chu_motor_speed_600); else snp.chu_motor_speed_600 = 100; //printf("vid = %d pid =%d \n",snp.Vid,snp.Pid ); return snp; } ScannerNativeParam jsonconfig::getdefaultscannerinfo() { ScannerNativeParam param; param.DoubleFeedTimes = 0; param.FeedErrorTimes = 0; param.H_ratio = 1065353216; param.V_ratio = 1065353216; param.JamTimes = 0; param.RollerNum = param.TotalScanned = 0; param.Token = "abcdefghijklmnopqrstuvwxyz012345"; //default 32byte length param.SerialNum = SERIALNUM; #ifdef G200 param.gray_sp=0x775; //G200 140 ppm 0x27c 0x775 G100 100 ppm 0x2B6 0x822 param.color_sp=0x27C; param.speedmode = 100; param.Pid = 0x0239; #else param.gray_sp=0x822; //G200 140 ppm 0x27c 0x781 G100 100 ppm 0x2B6 0x822 param.color_sp=0x2B6; param.speedmode = 70; param.Pid = 0x0139; #endif param.Vid = 0x3072; param.sleeptime=10800; param.clr_maxbright = param.gray_maxbright = 200; param.chu_motor_speed_200 = 300; param.chu_motor_speed_300 = 200; param.chu_motor_speed_600 = 100; return param; }