#include "jsonconfig.h" #include #include #include #include #include #include #define SP_COLOR_DEFAULT 0x438 #define SP_GRAY_DEFAULT 0xca8 jsonconfig m_static_jsonconfig; jsonconfig::jsonconfig() { getscannerinfo(); } 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" << m_json << std::endl; m_json[STRCON(STR_COLOR, STR_EXPF)].get_to(cfs.color.expF); m_json[STRCON(STR_COLOR, STR_EXPB)].get_to(cfs.color.expB); m_json[STRCON(STR_COLOR, STR_GAINF)].get_to(cfs.color.gainF); m_json[STRCON(STR_COLOR, STR_GAINB)].get_to(cfs.color.gainB); m_json[STRCON(STR_COLOR, STR_OFFSETF)].get_to(cfs.color.offsetsF); m_json[STRCON(STR_COLOR, STR_OFFSETB)].get_to(cfs.color.offsetsB); m_json[STRCON(STR_COLOR, STR_SP)].get_to(cfs.color.sp); m_json[STRCON(STR_CORRECTCOLOR, STR_EXPF)].get_to(cfs.colorCorrect.expF); m_json[STRCON(STR_CORRECTCOLOR, STR_EXPB)].get_to(cfs.colorCorrect.expB); m_json[STRCON(STR_CORRECTCOLOR, STR_GAINF)].get_to(cfs.colorCorrect.gainF); m_json[STRCON(STR_CORRECTCOLOR, STR_GAINB)].get_to(cfs.colorCorrect.gainB); m_json[STRCON(STR_CORRECTCOLOR, STR_OFFSETF)].get_to(cfs.colorCorrect.offsetsF); m_json[STRCON(STR_CORRECTCOLOR, STR_OFFSETB)].get_to(cfs.colorCorrect.offsetsB); m_json[STRCON(STR_CORRECTCOLOR, STR_SP)].get_to(cfs.colorCorrect.sp); m_json[STRCON(STR_GRAY, STR_EXPF)].get_to(cfs.gray.expF); m_json[STRCON(STR_GRAY, STR_EXPB)].get_to(cfs.gray.expB); m_json[STRCON(STR_GRAY, STR_GAINF)].get_to(cfs.gray.gainF); m_json[STRCON(STR_GRAY, STR_GAINB)].get_to(cfs.gray.gainB); m_json[STRCON(STR_GRAY, STR_OFFSETF)].get_to(cfs.gray.offsetsF); m_json[STRCON(STR_GRAY, STR_OFFSETB)].get_to(cfs.gray.offsetsB); m_json[STRCON(STR_GRAY, STR_SP)].get_to(cfs.gray.sp); m_json[STRCON(STR_CORRECTGRAY, STR_EXPF)].get_to(cfs.grayCorrect.expF); m_json[STRCON(STR_CORRECTGRAY, STR_EXPB)].get_to(cfs.grayCorrect.expB); m_json[STRCON(STR_CORRECTGRAY, STR_GAINF)].get_to(cfs.grayCorrect.gainF); m_json[STRCON(STR_CORRECTGRAY, STR_GAINB)].get_to(cfs.grayCorrect.gainB); m_json[STRCON(STR_CORRECTGRAY, STR_OFFSETF)].get_to(cfs.grayCorrect.offsetsF); m_json[STRCON(STR_CORRECTGRAY, STR_OFFSETB)].get_to(cfs.grayCorrect.offsetsB); m_json[STRCON(STR_CORRECTGRAY, STR_SP)].get_to(cfs.grayCorrect.sp); return cfs; } HGCorrectConfigs jsonconfig::getdefaultconfigs() { HGCorrectConfigs cfs; for (int i = 0; i < 3; i++) { int expclorF, expgrayF, expclorB, expgrayB; switch (i) { case 0: // B expclorF = 1300; // 789 expclorB = 1350; expgrayF = 420; expgrayB = 420; break; case 1: // G expclorF = 1350; expclorB = 1280; expgrayF = 420; expgrayB = 420; break; case 2: // R expclorF = 789; expclorB = 824; expgrayF = 420; expgrayB = 420; break; default: break; } cfs.colorCorrect.expB[i] = expclorF; cfs.colorCorrect.expF[i] = expclorB; cfs.grayCorrect.expB[i] = expgrayF; cfs.grayCorrect.expF[i] = expgrayB; cfs.gray.expB[i] = expgrayB; cfs.gray.expF[i] = expgrayF; cfs.color.expF[i] = expclorF; cfs.color.expB[i] = expclorB; } for (int i = 0; i < 6; i++) { cfs.colorCorrect.gainB[i] = cfs.colorCorrect.gainF[i] = 120; cfs.grayCorrect.gainB[i] = cfs.grayCorrect.gainF[i] = 120; cfs.gray.gainB[i] = cfs.gray.gainF[i] = 120; cfs.color.gainB[i] = cfs.color.gainF[i] = 120; cfs.colorCorrect.offsetsB[i] = cfs.colorCorrect.offsetsF[i] = 125; cfs.grayCorrect.offsetsB[i] = cfs.grayCorrect.offsetsF[i] = 125; cfs.gray.offsetsB[i] = cfs.gray.offsetsF[i] = 125; cfs.color.offsetsB[i] = cfs.color.offsetsF[i] = 125; } cfs.colorCorrect.sp = cfs.color.sp = SP_COLOR_DEFAULT; cfs.grayCorrect.sp = cfs.gray.sp = SP_GRAY_DEFAULT; return cfs; } void jsonconfig::savescannerinfo(ScannerNativeParam param) { m_mem_param = param; json m_json; m_json[S_INFO_DOUNUM] = (param.DoubleFeedTimes); m_json[S_INFO_FEEDERROR] = (param.FeedErrorTimes); m_json[S_INFO_HRATIO] = (param.H_ratio); m_json[S_INFO_JAMNUM] = (param.JamTimes); m_json[S_INFO_ROLLERNUM] = (param.RollerNum); m_json[S_INFO_SCANSESSIONCOUNT] = (param.ScanSessionsCount); m_json[S_INFO_SERIALNUM] = (param.SerialNum); m_json[S_INFO_TOKEN] = (param.Token); m_json[S_INFO_TOTALSCANNED] = (param.TotalScanned); m_json[S_INFO_VRATIO] = (param.V_ratio); m_json[S_COLOR_SP] = (param.color_sp); m_json[S_GRAY_SP] = (param.gray_sp); m_json[S_INFO_SLEEPTIME] = (param.sleeptime); m_json[S_INFO_CLR_MAXBRT] = (param.clr_maxbright); m_json[S_INFO_GRAY_MAXBRT] = (param.gray_maxbright); m_json[S_INFO_SPEEDMODE] = (param.speedmode); m_json[S_INFO_VID] = (param.Vid); m_json[S_INFO_PID] = (param.Pid); m_json[S_INFO_CHUZHI_MOTOR_SPEED_200] = (param.chu_motor_speed_200); m_json[S_INFO_CHUZHI_MOTOR_SPEED_300] = (param.chu_motor_speed_300); m_json[S_INFO_CHUZHI_MOTOR_SPEED_600] = (param.chu_motor_speed_600); std::ofstream o(JSON_SCANNER_INFO_FILE); o << std::setw(4) << m_json << std::endl; o.close(); printf("\n %s speedmode value = %d", JSON_SCANNER_INFO_FILE, param.speedmode); } ScannerNativeParam jsonconfig::getscannerinfo() { std::lock_guard 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 ); m_mem_param = snp; 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; } ScannerNativeParam jsonconfig::getmemparam() { return m_mem_param; }