2024-03-05 03:46:18 +00:00
|
|
|
|
#include "scannerregs.h"
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <fstream>
|
|
|
|
|
#include "IScanner.h"
|
|
|
|
|
#include "scanner.h"
|
|
|
|
|
#include "usbimageprocqueue.h"
|
|
|
|
|
#include "filetools.h"
|
|
|
|
|
#include "stringex.hpp"
|
|
|
|
|
#include "applog.h"
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include "memoryex.h"
|
|
|
|
|
#include "jsonconfig.h"
|
|
|
|
|
#include "CorrectParam.h"
|
|
|
|
|
#include "MotorboardParam.h"
|
|
|
|
|
#include "hgutils.h"
|
|
|
|
|
#include "base64.hpp"
|
|
|
|
|
#include "deviceconfig.h"
|
|
|
|
|
#include <libgen.h>
|
|
|
|
|
#include <syslog.h>
|
|
|
|
|
#include <dailex.hpp>
|
|
|
|
|
#include "SensorConfig.h"
|
|
|
|
|
|
|
|
|
|
constexpr int max_write_size = 1024*1024*20;
|
|
|
|
|
|
|
|
|
|
const std::vector<std::pair<std::string,int>> supported_w_r_dir{
|
|
|
|
|
{"/home/linaro",1},
|
|
|
|
|
{"/usr/local/huago",1},
|
|
|
|
|
{"/var/log",0},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const std::vector<std::pair<std::string,int>> supported_w_r_file{
|
|
|
|
|
{"/home/linaro/microtek_sn",1},
|
|
|
|
|
{"/var/log/black_list_file.txt",1},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unsigned long getfilesize(const char *filename)
|
|
|
|
|
{
|
|
|
|
|
struct stat buf;
|
|
|
|
|
if (stat(filename, &buf) < 0)
|
|
|
|
|
return 0;
|
|
|
|
|
return (unsigned long)buf.st_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void get_system_output(char *cmd, char *output, int size)
|
|
|
|
|
{
|
|
|
|
|
FILE *fp = NULL;
|
|
|
|
|
fp = popen(cmd, "r");
|
|
|
|
|
if (fp)
|
|
|
|
|
{
|
|
|
|
|
if (fgets(output, size, fp) != NULL)
|
|
|
|
|
{
|
|
|
|
|
if (output[strlen(output) - 1] == '\n')
|
|
|
|
|
output[strlen(output) - 1] = '\0';
|
|
|
|
|
}
|
|
|
|
|
pclose(fp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string get_system_output(const char *cmd)
|
|
|
|
|
{
|
|
|
|
|
FILE *fp = NULL;
|
|
|
|
|
char output[100];
|
|
|
|
|
std::string str ="";
|
|
|
|
|
fp = popen(cmd, "r");
|
|
|
|
|
if (fp)
|
|
|
|
|
{
|
|
|
|
|
while (fgets(output, sizeof(output), fp) != NULL)
|
|
|
|
|
{
|
|
|
|
|
str += output;
|
|
|
|
|
memset(output,0,sizeof(output));
|
|
|
|
|
}
|
|
|
|
|
pclose(fp);
|
|
|
|
|
}
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void updatesyslog(int loglevel, std::string loginfo)
|
|
|
|
|
{
|
|
|
|
|
openlog("scanservice", LOG_CONS | LOG_PID, LOG_USER);
|
|
|
|
|
syslog(loglevel, "%s \n", loginfo.c_str());
|
|
|
|
|
closelog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const std::string loggername = "ScannerRegAccess";
|
|
|
|
|
|
|
|
|
|
ScannerRegAccess::ScannerRegAccess(std::shared_ptr<IScanner> scanner, std::shared_ptr<UsbImageProcQueue> usbimages, std::shared_ptr<ITransmit> transmit, std::shared_ptr<IReceive> receiv)
|
|
|
|
|
{
|
|
|
|
|
LOG_INIT();
|
|
|
|
|
this->scanner = scanner;
|
|
|
|
|
this->usbimages = usbimages;
|
|
|
|
|
this->transmit = transmit;
|
|
|
|
|
this->recieve = receiv;
|
|
|
|
|
this->m_upstautus = Start_updata;
|
|
|
|
|
this->scanner->set_paprent(this);
|
|
|
|
|
file_pos = 0;
|
|
|
|
|
m_token = "null";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ScannerRegAccess::~ScannerRegAccess()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ScannerRegAccess::write(unsigned int addr, const unsigned int val)
|
|
|
|
|
{
|
|
|
|
|
switch (addr)
|
|
|
|
|
{
|
|
|
|
|
case SR_CMD:
|
|
|
|
|
return cmd(val);
|
|
|
|
|
case SR_IM_CLEAR:
|
|
|
|
|
while (!usbimages->empty())
|
|
|
|
|
usbimages->pop();
|
|
|
|
|
return true;
|
|
|
|
|
case SR_IM_TYPE:
|
|
|
|
|
return true;
|
|
|
|
|
case SR_IM_TX:
|
|
|
|
|
{
|
|
|
|
|
// if (val != 1 && (transmit->is_writing() || usbimages->empty()))
|
|
|
|
|
// return false;
|
|
|
|
|
// if (!usbimages->size())
|
|
|
|
|
// return false;
|
|
|
|
|
auto img = usbimages->front();
|
|
|
|
|
if (img.get())
|
|
|
|
|
{
|
|
|
|
|
transmit->write(img);
|
|
|
|
|
// transmit->write_bulk(img->data(),img->size());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LOG_TRACE(string_format("\nimage pop data is empty"));
|
|
|
|
|
scanner->add_scansever({.From = V4L2, .Code = 1});
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_NOTIFY_SLEEP:
|
|
|
|
|
if(scanner->get_sleepstatus() == 0)
|
|
|
|
|
scanner->set_sleepstatus(true);
|
|
|
|
|
return true;
|
|
|
|
|
case SR_SET_FEEDMODE:
|
|
|
|
|
if(val <3 && val >=0)
|
|
|
|
|
scanner->setfeedmode(val);
|
|
|
|
|
return true;
|
|
|
|
|
case SR_SET_TRAYPOSITION:
|
|
|
|
|
if(val <3 && val >=0)
|
|
|
|
|
scanner->settrayposition(val);
|
|
|
|
|
return true;
|
|
|
|
|
case SR_IM_POP:
|
|
|
|
|
usbimages->pop();
|
|
|
|
|
return true;
|
|
|
|
|
case SR_IM_ABORT:
|
|
|
|
|
transmit->cannel();
|
|
|
|
|
printf("\n SR_IM_ABORT ");
|
|
|
|
|
return true;
|
|
|
|
|
case SR_CONFIG_SCAN_PARAM:
|
|
|
|
|
scanner->configparam(*((HGScanConfig *)&val));
|
|
|
|
|
return true;
|
|
|
|
|
case SR_CONFIF_IMGPROCPARAM:
|
|
|
|
|
{
|
|
|
|
|
printf("\nSR_CONFIF_IMGPROCPARAM size =%d",val);
|
|
|
|
|
std::vector<char> data(val);
|
|
|
|
|
if(val==0)
|
|
|
|
|
data.resize(116);
|
|
|
|
|
auto lin = recieve->read_bulk(data.data(), data.size());
|
|
|
|
|
char capdata[sizeof(GScanCap)]{0};
|
|
|
|
|
printf("\n gcap size = %d \n",sizeof(GScanCap));
|
|
|
|
|
memcpy(capdata,data.data(),std::min(sizeof(GScanCap),data.size()));
|
|
|
|
|
GScanCap cap = *(GScanCap*)capdata;
|
|
|
|
|
scanner->set_hgimgconfig(cap);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_FWVERSION:
|
|
|
|
|
{
|
|
|
|
|
std::string fw(FWVersion);
|
|
|
|
|
transmit->write_bulk(&fw[0], fw.length());
|
|
|
|
|
//printf((fw + "%d\n").c_str(), fw.length());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SC_AUTOCORRECT:
|
|
|
|
|
scanner->test_autocorrect(val);
|
|
|
|
|
return true;
|
|
|
|
|
case SC_GET_CORRECT_PARAM:
|
|
|
|
|
{
|
|
|
|
|
auto param = getcisparams();
|
|
|
|
|
transmit->write_bulk(¶m, sizeof(param));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SC_SET_CORRECT_PARAM:
|
|
|
|
|
{
|
|
|
|
|
auto cisparam = getcisparams();
|
|
|
|
|
switch (val)
|
|
|
|
|
{
|
|
|
|
|
case 0: //correct color
|
|
|
|
|
{
|
|
|
|
|
recieve->read_bulk(&cisparam.colorCorrect, sizeof(HGCISConfig));
|
|
|
|
|
for (int i = 0; i < 6; i++)
|
|
|
|
|
{
|
|
|
|
|
if (i < 3)
|
|
|
|
|
{
|
|
|
|
|
printf("colorCorrect.expF[%d] = %d \n", i, cisparam.colorCorrect.expF[i]);
|
|
|
|
|
printf("colorCorrect.expB[%d] = %d \n", i, cisparam.colorCorrect.expB[i]);
|
|
|
|
|
}
|
|
|
|
|
printf("colorCorrect.GainsF[%d] = %d \n", i, cisparam.colorCorrect.gainF[i]);
|
|
|
|
|
printf("colorCorrect.GainsB[%d] = %d \n", i, cisparam.colorCorrect.gainB[i]);
|
|
|
|
|
printf("colorCorrect.offsetsF[%d] = %d \n", i, cisparam.colorCorrect.offsetsF[i]);
|
|
|
|
|
printf("colorCorrect.offsetsB[%d] = %d \n", i, cisparam.colorCorrect.offsetsB[i]);
|
|
|
|
|
}
|
|
|
|
|
savecisparams(cisparam);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 1: //color
|
|
|
|
|
{
|
|
|
|
|
recieve->read_bulk(&cisparam.color, sizeof(HGCISConfig));
|
|
|
|
|
for (int i = 0; i < 6; i++)
|
|
|
|
|
{
|
|
|
|
|
if (i < 3)
|
|
|
|
|
{
|
|
|
|
|
printf("color.expF[%d] = %d \n", i, cisparam.color.expF[i]);
|
|
|
|
|
printf("color.expB[%d] = %d \n", i, cisparam.color.expB[i]);
|
|
|
|
|
}
|
|
|
|
|
printf("color.GainsF[%d] = %d \n", i, cisparam.color.gainF[i]);
|
|
|
|
|
printf("color.GainsB[%d] = %d \n", i, cisparam.color.gainB[i]);
|
|
|
|
|
printf("color.offsetsF[%d] = %d \n", i, cisparam.color.offsetsF[i]);
|
|
|
|
|
printf("color.offsetsB[%d] = %d \n", i, cisparam.color.offsetsB[i]);
|
|
|
|
|
}
|
|
|
|
|
savecisparams(cisparam);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 2: //correct gray
|
|
|
|
|
recieve->read_bulk(&cisparam.grayCorrect, sizeof(HGCISConfig));
|
|
|
|
|
savecisparams(cisparam);
|
|
|
|
|
break;
|
|
|
|
|
case 3: //gray
|
|
|
|
|
recieve->read_bulk(&cisparam.gray, sizeof(HGCISConfig));
|
|
|
|
|
savecisparams(cisparam);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_UPDATA_START:
|
|
|
|
|
{
|
|
|
|
|
//scanner->set_sleepstatus(false); //安路电机板更新时需要电机板不断电
|
|
|
|
|
int currlenght = 0;
|
|
|
|
|
std::vector<char> buff;
|
|
|
|
|
std::fstream fd;
|
|
|
|
|
if (access("/home/updata.zip", 4) == 0)
|
|
|
|
|
remove("/home/updata.zip");
|
|
|
|
|
fd.open("/home/updata.zip", std::ios::out | std::ios::binary);
|
|
|
|
|
updatesyslog(6,"Start Updating firmware with "+ std::to_string(val) + "Byte");
|
|
|
|
|
if (val < 512 * 1024)
|
|
|
|
|
{
|
|
|
|
|
buff.resize(val);
|
|
|
|
|
recieve->read_bulk(buff.data(), val);
|
|
|
|
|
if (fd.is_open())
|
|
|
|
|
{
|
|
|
|
|
m_upstautus = Download_file;
|
|
|
|
|
fd.write(buff.data(), val);
|
|
|
|
|
fd.close();
|
|
|
|
|
m_upstautus = Download_file_finish;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
m_upstautus = Download_file_error;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
buff.resize(512 * 1024);
|
|
|
|
|
if (fd.is_open())
|
|
|
|
|
{
|
|
|
|
|
int readnum = 0;
|
|
|
|
|
m_upstautus = Download_file;
|
|
|
|
|
while (val > currlenght)
|
|
|
|
|
{
|
|
|
|
|
readnum = recieve->read_bulk(buff.data(), ((val - currlenght) > 512 * 1024) ? (512 * 1024) : (val - currlenght));
|
|
|
|
|
fd.write(buff.data(), readnum);
|
|
|
|
|
fd.seekp(0, std::ios::end);
|
|
|
|
|
currlenght += readnum;
|
|
|
|
|
printf("\nresvice data lenght =%d ", currlenght);
|
|
|
|
|
}
|
|
|
|
|
fd.close();
|
|
|
|
|
m_upstautus = Download_file_finish;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
m_upstautus = Download_file_error;
|
|
|
|
|
}
|
|
|
|
|
if (m_upstautus = Download_file_finish)
|
|
|
|
|
{
|
|
|
|
|
updatesyslog(6,"Downloading firmware with done,and checking firmware token");
|
|
|
|
|
system("cp /home/updata.zip /userdata/update.zip -f");
|
|
|
|
|
system("rm -rf /home/updata.zip");
|
|
|
|
|
system("echo 5 > /userdata/md5_result.log");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
updatesyslog(3,"Downloading firmware error");
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_REBOOT:
|
|
|
|
|
{
|
|
|
|
|
if(val >0)
|
|
|
|
|
system("reboot loader");
|
|
|
|
|
else
|
|
|
|
|
system("reboot");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_POWEROFF:
|
|
|
|
|
{
|
|
|
|
|
system("poweroff");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_SET_STARTBACKUP:
|
|
|
|
|
{
|
|
|
|
|
printf("start Back up system\n");
|
|
|
|
|
system("touch /etc/back_status");
|
|
|
|
|
system("echo 0 > /etc/back_status");
|
|
|
|
|
system("/etc/hgbackup_auto.sh &");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_SET_H_RATIO:
|
|
|
|
|
case SR_SET_V_RATIO:
|
|
|
|
|
case SR_SET_H_200_RATIO:
|
|
|
|
|
case SR_SET_H_300_RATIO:
|
|
|
|
|
case SR_SET_H_600_RATIO:
|
|
|
|
|
case SR_SET_V_200_RATIO:
|
|
|
|
|
case SR_SET_V_300_RATIO:
|
|
|
|
|
case SR_SET_V_600_RATIO:
|
|
|
|
|
case SR_SET_SERIALNUM:
|
|
|
|
|
case SR_GET_SERIALNUM:
|
|
|
|
|
{
|
|
|
|
|
unsigned int value = val;
|
|
|
|
|
return procscannerinfo(addr, value);
|
|
|
|
|
}
|
|
|
|
|
case SR_SET_GRAY_SP:
|
|
|
|
|
{
|
|
|
|
|
auto info = Get_static_jsonconfig().getscannerinfo();
|
|
|
|
|
#ifdef G200
|
|
|
|
|
if(info.speedmode==100||info.speedmode==110||info.speedmode==120||info.speedmode==130)
|
|
|
|
|
info.gray_sp= val;
|
|
|
|
|
#else
|
|
|
|
|
if(info.speedmode==70||info.speedmode==80||info.speedmode==90 || info.speedmode == 110)
|
|
|
|
|
info.gray_sp = val;
|
|
|
|
|
#endif
|
|
|
|
|
printf(" \n SR_SET_GRAY_SP %d ", val);
|
|
|
|
|
Get_static_jsonconfig().savescannerinfo(info);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_SET_COLOR_SP:
|
|
|
|
|
{
|
|
|
|
|
auto info = Get_static_jsonconfig().getscannerinfo();
|
|
|
|
|
#ifdef G200
|
|
|
|
|
if(info.speedmode==100||info.speedmode==110||info.speedmode==120||info.speedmode==130)
|
|
|
|
|
info.color_sp = val;
|
|
|
|
|
#else
|
|
|
|
|
if(info.speedmode==70||info.speedmode==80||info.speedmode==90||info.speedmode==110)
|
|
|
|
|
info.color_sp = val;
|
|
|
|
|
#endif
|
|
|
|
|
printf(" \n SR_SET_COLOR_SP %d ", val);
|
|
|
|
|
Get_static_jsonconfig().savescannerinfo(info);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_SET_SLEEPTIME:
|
|
|
|
|
{
|
|
|
|
|
int value = (*((int *)&val));
|
|
|
|
|
if(value>=60 || value == -1){
|
|
|
|
|
scanner->resettime();
|
|
|
|
|
scanner->set_sleeptime(value);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_FLAT_CLR_MAX_BRIGHT:
|
|
|
|
|
case SR_FLAT_GRAY_MAX_BRIGHT:
|
|
|
|
|
{
|
|
|
|
|
auto snp = getscannerinfo();
|
|
|
|
|
addr == SR_FLAT_CLR_MAX_BRIGHT ? snp.clr_maxbright = val : snp.gray_maxbright = val;
|
|
|
|
|
savescannerinfo(snp);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_KERNEL_VERSION:
|
|
|
|
|
{
|
|
|
|
|
std::string cmd = "uname -a";
|
|
|
|
|
char version[1024];
|
|
|
|
|
get_system_output(const_cast<char *>(cmd.c_str()), version, sizeof(version));
|
|
|
|
|
std::string str_version(version);
|
|
|
|
|
transmit->write_bulk(const_cast<char *>(str_version.c_str()), str_version.length());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_SET_SPEEDMODE:
|
|
|
|
|
{
|
|
|
|
|
auto info = getscannerinfo();
|
|
|
|
|
#ifdef G200
|
|
|
|
|
if (val == 90 || val == 100 || val == 140 || val == 110 || val == 120 || val == 130)
|
|
|
|
|
info.speedmode = val;
|
|
|
|
|
#else
|
|
|
|
|
if (val == 100 || val == 70 || val == 80 || val == 90 || val == 110)
|
|
|
|
|
info.speedmode = val;
|
|
|
|
|
#endif
|
|
|
|
|
setcameraparmSp(val);
|
|
|
|
|
savescannerinfo(info);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_IPADDR:
|
|
|
|
|
{
|
|
|
|
|
char buf[1024]={0};
|
|
|
|
|
get_system_output("sudo ifconfig eth0 | awk '/inet /{print substr($2,1)}'",buf,sizeof(buf));
|
|
|
|
|
std::string ip = std::string(buf);
|
|
|
|
|
transmit->write_bulk(&ip[0],ip.length());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_MACADDR:
|
|
|
|
|
{
|
|
|
|
|
char buf[1024]={0};
|
|
|
|
|
get_system_output("sudo ifconfig eth0 | awk '/ether /{print substr($2,1)}'",buf,sizeof(buf));
|
|
|
|
|
std::string ip = std::string(buf);
|
|
|
|
|
transmit->write_bulk(&ip[0],ip.length());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_MBVERSION:
|
|
|
|
|
{
|
|
|
|
|
transmit->write_bulk(&scanner->getmbversion()[0],scanner->getmbversion().length());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_SET_USBVIDPID:
|
|
|
|
|
{
|
|
|
|
|
USBVIDPID vidpid=*(USBVIDPID*)&val;
|
|
|
|
|
auto info = getscannerinfo();
|
|
|
|
|
printf("set vid = %d pid = %d \n",vidpid.param.VID,vidpid.param.PID);
|
|
|
|
|
if(vidpid.param.VID!=0 && vidpid.param.PID!=0)
|
|
|
|
|
{
|
|
|
|
|
info.Vid = vidpid.param.VID;
|
|
|
|
|
info.Pid = vidpid.param.PID;
|
|
|
|
|
std::string cmd = "/etc/mdfusbconfig " + std::to_string(vidpid.param.VID)+" "+std::to_string(vidpid.param.PID);
|
|
|
|
|
system(cmd.c_str());
|
|
|
|
|
savescannerinfo(info);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
printf("error vid pid value\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SR_SET_JSON_PATH:
|
|
|
|
|
{
|
|
|
|
|
std::string path;
|
|
|
|
|
path.resize(val);
|
|
|
|
|
recieve->read_bulk(&path[0],val);
|
|
|
|
|
jsonpath = path;
|
|
|
|
|
printf("\n %s size =%d",path.c_str(),val);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_JSON:
|
|
|
|
|
{
|
|
|
|
|
std::string buff;
|
|
|
|
|
int bufsize = val < 512*1024 ? val : 512*1024;
|
|
|
|
|
int touch = 0;
|
|
|
|
|
buff.resize(bufsize);
|
|
|
|
|
if(b_supported_w_r(jsonpath,false) == false)
|
|
|
|
|
{
|
|
|
|
|
while(touch < val)
|
|
|
|
|
{
|
|
|
|
|
transmit->write_bulk(&buff[0],bufsize);
|
|
|
|
|
touch += bufsize;
|
|
|
|
|
bufsize = bufsize > val -touch ? val -touch : bufsize;
|
|
|
|
|
printf("\n discard file size =%d ",touch);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
std::fstream i;
|
|
|
|
|
i.open(jsonpath.c_str(),std::ios::in|std::ios::binary);
|
|
|
|
|
i.seekp(file_pos,std::ios::beg);
|
|
|
|
|
while(touch < val)
|
|
|
|
|
{
|
|
|
|
|
i.read(&buff[0],bufsize);
|
|
|
|
|
transmit->write_bulk(&buff[0],bufsize);
|
|
|
|
|
touch += bufsize;
|
|
|
|
|
bufsize = bufsize > val -touch ? val -touch : bufsize;
|
|
|
|
|
printf("\n get file size =%d ",touch);
|
|
|
|
|
}
|
|
|
|
|
i.close();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_SET_JSON:
|
|
|
|
|
{
|
|
|
|
|
std::string buff;
|
|
|
|
|
int bufsize = val < 512*1024 ? val : 512*1024;
|
|
|
|
|
int touch = 0;
|
|
|
|
|
buff.resize(bufsize);
|
|
|
|
|
if((b_supported_w_r(jsonpath,false) == false) || (val > max_write_size))
|
|
|
|
|
{
|
|
|
|
|
while(touch < val){
|
|
|
|
|
recieve->read_bulk(&buff[0],bufsize);
|
|
|
|
|
touch += bufsize;
|
|
|
|
|
bufsize = bufsize > val -touch ? val -touch : bufsize;
|
|
|
|
|
printf("\ndiscard file size =%d ",touch);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
std::fstream out;
|
|
|
|
|
out.open(jsonpath.c_str(),std::ios::out|std::ios::binary);
|
|
|
|
|
out.seekg(file_pos,std::ios::beg);
|
|
|
|
|
while(touch < val){
|
|
|
|
|
recieve->read_bulk(&buff[0],bufsize);
|
|
|
|
|
out.write(&buff[0],bufsize);
|
|
|
|
|
touch += bufsize;
|
|
|
|
|
bufsize = bufsize > val -touch ? val -touch : bufsize;
|
|
|
|
|
printf("\nget file size =%d ",touch);
|
|
|
|
|
}
|
|
|
|
|
out.close();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_SET_FILE_POS:
|
|
|
|
|
{
|
|
|
|
|
file_pos = val;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_SET_AUTOMATICCONTROLFEEDMODE_ENABLE:
|
|
|
|
|
{
|
|
|
|
|
if(val == 0)
|
|
|
|
|
MotorboardParam().GetOrSetEnableAutomaticControlFeedMode(false,0);
|
|
|
|
|
else
|
|
|
|
|
MotorboardParam().GetOrSetEnableAutomaticControlFeedMode(false,1);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_SET_AUTOMATICCONTROLFEEDMODE_THRESHOLD:
|
|
|
|
|
{
|
|
|
|
|
float fx = *((float *)&val);
|
|
|
|
|
printf("\n SR_SET_AUTOMATICCONTROLFEEDMODE_THRESHOLD %f",fx);
|
|
|
|
|
if(fx >0 && fx < 1)
|
|
|
|
|
{
|
|
|
|
|
auto param_tmp = MotorboardParam().GetParam();
|
|
|
|
|
param_tmp.automaticcontrolfeedmode_threshold = fx;
|
|
|
|
|
MotorboardParam().SaveParam(param_tmp);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_SET_LOCK_STATES:
|
|
|
|
|
{
|
|
|
|
|
printf("\n SR_SET_LOCK_STATES %d",val);
|
|
|
|
|
auto param = Get_static_deviceconfig().GetParam();
|
|
|
|
|
param.is_lock = val == 1 ? true : false;
|
|
|
|
|
Get_static_deviceconfig().SaveParam(param);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_SET_TOKEN:
|
|
|
|
|
{
|
|
|
|
|
if(val < 1)
|
|
|
|
|
return true;
|
|
|
|
|
std::string token;
|
|
|
|
|
token.resize(val);
|
|
|
|
|
recieve->read_bulk(&token[0],val);
|
|
|
|
|
auto decode_token = Base64().Decode(token.c_str(),token.length());
|
|
|
|
|
// printf("\n SR_SET_TOKEN %s",decode_token.c_str());
|
|
|
|
|
if(decode_token.length()<2)
|
|
|
|
|
return true;
|
|
|
|
|
for(int i =1;i<decode_token.size();i++)
|
|
|
|
|
{
|
|
|
|
|
char c = decode_token[i];
|
|
|
|
|
if (c==0) break;
|
|
|
|
|
if (c&0x80)
|
|
|
|
|
if (decode_token[i-1] & 0x80) //包含中文
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
auto param = Get_static_deviceconfig().GetParam();
|
|
|
|
|
param.token = decode_token;
|
|
|
|
|
Get_static_deviceconfig().SaveParam(param);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_DECODE_TOKEN:
|
|
|
|
|
{
|
|
|
|
|
if(val < 1)
|
|
|
|
|
return true;
|
|
|
|
|
std::string token;
|
|
|
|
|
token.resize(val);
|
|
|
|
|
recieve->read_bulk(&token[0],val);
|
|
|
|
|
m_token = token;
|
|
|
|
|
// printf("\n token = ");
|
|
|
|
|
// for(int i =0;i<val;i++)
|
|
|
|
|
// printf(" %x",token[i]);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_TOKEN:
|
|
|
|
|
{
|
|
|
|
|
auto tmp = Get_static_deviceconfig().GetParam().token;
|
|
|
|
|
tmp = Base64().Encode((const uchar*)tmp.c_str(),tmp.length());
|
|
|
|
|
transmit->write_bulk(&tmp[0],val);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_CLEAN_PAPER_ROAD:
|
|
|
|
|
scanner->clean_paper_road();
|
|
|
|
|
return true;
|
|
|
|
|
case SR_EXECUTE_CMD:
|
|
|
|
|
{
|
|
|
|
|
std::string cmd;
|
|
|
|
|
cmd.resize(val);
|
|
|
|
|
recieve->read_bulk(&cmd[0],val);
|
|
|
|
|
printf("SR_EXECUTE_CMD = %s \n",cmd.c_str());
|
|
|
|
|
std::thread cmd_thread([this,cmd]{
|
|
|
|
|
cmd_out = get_system_output(cmd.c_str());
|
|
|
|
|
printf("lens = %d \n %s \n",cmd_out.length(), cmd_out.c_str());
|
|
|
|
|
scanner->add_scansever({.From = HGType::CMD_OUT, .Code = static_cast<unsigned int>(cmd_out.length())});
|
|
|
|
|
// transmit->write_bulk(&str[0],str.length());
|
|
|
|
|
});
|
|
|
|
|
cmd_thread.detach();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_EXECUTE_CMD_OUT:
|
|
|
|
|
{
|
|
|
|
|
if(val > cmd_out.size())
|
|
|
|
|
cmd_out.resize(val);
|
|
|
|
|
transmit->write_bulk(&cmd_out[0],val);
|
|
|
|
|
cmd_out = "";
|
|
|
|
|
cmd_out.resize(10);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_SET_Corrective_Restoration:
|
|
|
|
|
{
|
|
|
|
|
std::vector<std::string> path{ "200clr","200gray","300clr","300gray","600clr","600gray","slow_moireclr","slow_moiregray"};
|
|
|
|
|
if(val<path.size())
|
|
|
|
|
system(("cp /usr/local/huago/Textlut"+ path[val]+".bmp-back /usr/local/huago/Textlut"+ path[val]+".bmp").c_str());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_BACKUP_RESTORES_HUAGODIR:
|
|
|
|
|
{
|
|
|
|
|
if(val == 1){
|
|
|
|
|
mkdir("/usr/local/huago-back",0777);
|
|
|
|
|
system("cp -rf /usr/local/huago/* /usr/local/huago-back");
|
|
|
|
|
}
|
|
|
|
|
else if(val == 2)
|
|
|
|
|
system("cp -rf /usr/local/huago-back/* /usr/local/huago");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_SINGLE_CORRECT_MODE:
|
|
|
|
|
{
|
|
|
|
|
printf("\nSR_SINGLE_CORRECT_MODE %d \n",val);
|
|
|
|
|
scanner->single_correct(val);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_SET_GRAYCORRECT_MODE:
|
|
|
|
|
{
|
|
|
|
|
printf("\nSR_SET_GRAYCORRECT_MODE %d \n",val);
|
|
|
|
|
auto tmp = Get_static_deviceconfig().GetParam();
|
|
|
|
|
tmp.gray_param = val;
|
|
|
|
|
Get_static_deviceconfig().SaveParam(tmp);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_ARM_DATETIME:
|
|
|
|
|
{
|
|
|
|
|
if(val > arm_datetime.size())
|
|
|
|
|
arm_datetime.resize(val);
|
|
|
|
|
transmit->write_bulk(&arm_datetime[0],val);
|
|
|
|
|
arm_datetime = "";
|
|
|
|
|
arm_datetime.resize(0);
|
|
|
|
|
arm_datetime.shrink_to_fit();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_SET_ARM_DATETIME:
|
|
|
|
|
{
|
|
|
|
|
if(val < 1)
|
|
|
|
|
return true;
|
|
|
|
|
std::string datetime;
|
|
|
|
|
datetime.resize(val);
|
|
|
|
|
recieve->read_bulk(&datetime[0],val);
|
|
|
|
|
printf("SR_SET_ARM_DATETIME = %s \n",datetime.c_str()); // 示范格式 2023-10-25 10:52:00
|
|
|
|
|
int year, month, day, hours, min, seconds, conver;
|
|
|
|
|
conver = sscanf(datetime.c_str(), "%d-%d-%d %d:%d:%d", &year, &month, &day, &hours, &min, &seconds);
|
|
|
|
|
printf("%d-%d-%d %d:%d:%d \n", year, month, day, hours, min, seconds);
|
|
|
|
|
if(conver !=6)
|
|
|
|
|
return true;
|
|
|
|
|
system("timedatectl set-ntp false");
|
|
|
|
|
system(("timedatectl set-time \" "+std::to_string(year)+"-"+std::to_string(month)+"-"+std::to_string(day)
|
|
|
|
|
+" "+std::to_string(hours)+":"+std::to_string(min)+":"+std::to_string(seconds)+"\"").c_str());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2024-03-18 06:31:20 +00:00
|
|
|
|
case SR_SET_LCD_LANGUAGE:
|
|
|
|
|
{
|
|
|
|
|
if(val >=0 && val < 3)
|
2024-03-05 03:46:18 +00:00
|
|
|
|
{
|
2024-03-18 06:31:20 +00:00
|
|
|
|
auto param = Get_static_deviceconfig().GetParam();
|
|
|
|
|
param.language = val;
|
|
|
|
|
Get_static_deviceconfig().SaveParam(param);
|
2024-03-05 03:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2024-03-18 06:31:20 +00:00
|
|
|
|
case SR_GET_SENSOR_CONFIG:
|
2024-03-05 03:46:18 +00:00
|
|
|
|
{
|
2024-03-18 06:31:20 +00:00
|
|
|
|
if(val < 1) return true;
|
|
|
|
|
std::string str = Get_Static_SC().get_mem_param_js().dump();
|
|
|
|
|
str.resize(val);
|
|
|
|
|
transmit->write_bulk(&str[0],val);
|
2024-03-05 03:46:18 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2024-03-18 06:31:20 +00:00
|
|
|
|
case SR_SET_SENSOR_CONFIG:
|
2024-03-05 03:46:18 +00:00
|
|
|
|
{
|
2024-03-18 06:31:20 +00:00
|
|
|
|
if(val < 1) return true;
|
|
|
|
|
//1:扫描;2:开盖;3:歪斜—1;4:歪斜-2;5:出纸口;6:有无纸 7:双张检测周期;8:有无纸检测周期;9:双张阈值;10:单张阈值;
|
|
|
|
|
//11: 对射传感器配置使能; 12:双张传感器配置使能
|
|
|
|
|
int type = val >> 24;
|
|
|
|
|
uint32_t duty = val & 0xffffff;
|
|
|
|
|
auto config = Get_Static_SC().get_mem_param();
|
|
|
|
|
if((type>0)&&(type < 7)&&(duty < 100))
|
2024-03-05 03:46:18 +00:00
|
|
|
|
{
|
2024-03-18 06:31:20 +00:00
|
|
|
|
scanner->set_sensor_param(type - 1,duty);
|
|
|
|
|
}
|
|
|
|
|
if((type>6)&&(type < 11)&&(duty < 255))
|
|
|
|
|
{
|
|
|
|
|
scanner->set_sensor_param(type - 1,duty);
|
|
|
|
|
}
|
|
|
|
|
if((type == 11) || (type == 12))
|
|
|
|
|
{
|
|
|
|
|
scanner->set_sensor_param(type - 1,duty);
|
2024-03-05 03:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ScannerRegAccess::read(unsigned int addr, unsigned int &val)
|
|
|
|
|
{
|
|
|
|
|
switch (addr)
|
|
|
|
|
{
|
|
|
|
|
case SR_STATUS:
|
|
|
|
|
val = scanner->is_runscan() | ((!usbimages->empty()) << 1) | scanner->paper_ready() << 2;//1/0 (1/0 << 1 | 1/0<< 2)
|
|
|
|
|
LOG_TRACE(string_format("run status:%d", val));
|
|
|
|
|
return true;
|
|
|
|
|
case SR_SCAN_COUNT:
|
|
|
|
|
val = scanner->count();
|
|
|
|
|
return true;
|
|
|
|
|
case SR_GET_MBSTATUS:
|
|
|
|
|
val = scanner->getmbstatus();
|
|
|
|
|
return true;
|
|
|
|
|
case SR_GET_IMAGEPROCESSDONE:
|
|
|
|
|
val = scanner->getimageprocedone();
|
|
|
|
|
return true;
|
|
|
|
|
case SR_OS:
|
|
|
|
|
val = scanner->mode();
|
|
|
|
|
return true;
|
|
|
|
|
case SR_IM_COUNT:
|
|
|
|
|
val = usbimages->size();
|
|
|
|
|
//printf("\nusbimages->size =%d",val);
|
|
|
|
|
return true;
|
|
|
|
|
case SR_IM_FRONT_SIZE:
|
|
|
|
|
if (!usbimages->size())
|
|
|
|
|
{
|
|
|
|
|
LOG_TRACE("\nGet image size , USBimage size =0");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
val = usbimages->front_datasize();
|
|
|
|
|
return true;
|
|
|
|
|
case SR_IM_TXING:
|
|
|
|
|
val = transmit->is_writing();
|
|
|
|
|
return true;
|
|
|
|
|
case SR_UPDATA_STAUTUS:
|
|
|
|
|
val = (int)m_upstautus;
|
|
|
|
|
printf("\nm_upstautus value =%d", m_upstautus);
|
|
|
|
|
return true;
|
|
|
|
|
case SR_UPDATA_MD5_RELUST:
|
|
|
|
|
{
|
|
|
|
|
std::fstream updateResult("/userdata/md5_result.log");
|
|
|
|
|
if (!updateResult.is_open())
|
|
|
|
|
val = 0;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
updateResult >> val;
|
|
|
|
|
updateResult.close();
|
|
|
|
|
}
|
|
|
|
|
if (val == 2)
|
|
|
|
|
m_upstautus = Updata_Stautus::MD5_Rboot;
|
|
|
|
|
else if (val == 3)
|
|
|
|
|
m_upstautus = Updata_Stautus::MD5_Reovery;
|
|
|
|
|
else
|
|
|
|
|
m_upstautus = Updata_Stautus::MD5_Error;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_UPDATA_RECOVERY:
|
|
|
|
|
{
|
|
|
|
|
if (m_upstautus == Updata_Stautus::MD5_Reovery)
|
|
|
|
|
{
|
|
|
|
|
system("update ota /userdata/updatefile/update.img");
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_BACKUPSTATUS:
|
|
|
|
|
{
|
|
|
|
|
std::ifstream i("/etc/back_status");
|
|
|
|
|
i>> val;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_UPDATA_REBOOT:
|
|
|
|
|
{
|
|
|
|
|
if (m_upstautus == MD5_Rboot)
|
|
|
|
|
{
|
|
|
|
|
system("reboot");
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_CUO_ERROR:
|
|
|
|
|
{
|
|
|
|
|
auto info = Get_static_jsonconfig().getscannerinfo();
|
|
|
|
|
val = info.FeedErrorTimes;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_DOU_ERROR:
|
|
|
|
|
{
|
|
|
|
|
auto info = Get_static_jsonconfig().getscannerinfo();
|
|
|
|
|
val = info.DoubleFeedTimes;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_JAM_ERROR:
|
|
|
|
|
{
|
|
|
|
|
auto info = Get_static_jsonconfig().getscannerinfo();
|
|
|
|
|
val = info.JamTimes;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_SCANN_NUM:
|
|
|
|
|
{
|
|
|
|
|
auto info = Get_static_jsonconfig().getscannerinfo();
|
|
|
|
|
val = info.TotalScanned;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_CLR_ROLLER_NUM:
|
|
|
|
|
{
|
|
|
|
|
auto info = Get_static_jsonconfig().getscannerinfo();
|
|
|
|
|
info.RollerNum = 0;
|
|
|
|
|
Get_static_jsonconfig().savescannerinfo(info);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_ROLLER_NUM:
|
|
|
|
|
{
|
|
|
|
|
auto info = Get_static_jsonconfig().getscannerinfo();
|
|
|
|
|
val = info.RollerNum;
|
|
|
|
|
printf(" info.RollerNum =%d", info.RollerNum);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_CLR_SCANN_NUM:
|
|
|
|
|
{
|
|
|
|
|
auto info = Get_static_jsonconfig().getscannerinfo();
|
|
|
|
|
info.TotalScanned = 0;
|
|
|
|
|
Get_static_jsonconfig().savescannerinfo(info);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_SERIAL_LEN:
|
|
|
|
|
case SR_GET_H_RATIO:
|
|
|
|
|
case SR_GET_V_RATIO:
|
|
|
|
|
case SR_GET_H_200_RATIO:
|
|
|
|
|
case SR_GET_H_300_RATIO:
|
|
|
|
|
case SR_GET_H_600_RATIO:
|
|
|
|
|
case SR_GET_V_200_RATIO:
|
|
|
|
|
case SR_GET_V_300_RATIO:
|
|
|
|
|
case SR_GET_V_600_RATIO:
|
|
|
|
|
{
|
|
|
|
|
return procscannerinfo(addr, val);
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_GRAY_SP:
|
|
|
|
|
{
|
|
|
|
|
val = Get_static_jsonconfig().getscannerinfo().gray_sp;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_COLOR_SP:
|
|
|
|
|
{
|
|
|
|
|
val = Get_static_jsonconfig().getscannerinfo().color_sp;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_SLEEPTIME:
|
|
|
|
|
{
|
|
|
|
|
val = scanner->get_sleeptime();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_SLEEP_STAUTUS:
|
|
|
|
|
{
|
|
|
|
|
val = scanner->get_sleepstatus();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_KEEP_LAST_PAPER:
|
|
|
|
|
{
|
|
|
|
|
val = scanner->get_keeplastpaper();
|
|
|
|
|
printf("\nget_keeplastpaper =%d ", val);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_FLAT_CLR_MAX_BRIGHT:
|
|
|
|
|
case SR_FLAT_GRAY_MAX_BRIGHT:
|
|
|
|
|
{
|
|
|
|
|
auto snp = getscannerinfo();
|
|
|
|
|
val = addr == SR_FLAT_CLR_MAX_BRIGHT ? snp.clr_maxbright : snp.gray_maxbright;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_KERNEL_VERSION_INFO_LENGTH:
|
|
|
|
|
{
|
|
|
|
|
std::string cmd = "uname -a";
|
|
|
|
|
char version[1024];
|
|
|
|
|
get_system_output(const_cast<char *>(cmd.c_str()), version, sizeof(version));
|
|
|
|
|
std::string str_version(version);
|
|
|
|
|
val = str_version.length();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_PAPERON:
|
|
|
|
|
val = scanner->getpaperon();
|
|
|
|
|
return true;
|
|
|
|
|
case SR_GET_SPEEDMODE:
|
|
|
|
|
{
|
|
|
|
|
val = getscannerinfo().speedmode;
|
|
|
|
|
printf("\n SR_GET_SPEEDMODE %d ",val);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_IPADDR_LENGHT:
|
|
|
|
|
{
|
|
|
|
|
char buf[1024]={0};
|
|
|
|
|
get_system_output("sudo ifconfig eth0 | awk '/inet /{print substr($2,1)}'",buf,sizeof(buf));
|
|
|
|
|
val= std::string(buf).length();
|
|
|
|
|
printf("\n ip = %s lenght =%d",buf,val);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_MBVERSION_LENGHT:
|
|
|
|
|
{
|
|
|
|
|
val = scanner->getmbversion().length();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_USBVIDPID:
|
|
|
|
|
{
|
|
|
|
|
auto info = getscannerinfo();
|
|
|
|
|
USBVIDPID vidpid;
|
|
|
|
|
vidpid.param.VID = info.Vid;
|
|
|
|
|
vidpid.param.PID = info.Pid;
|
|
|
|
|
val = vidpid.value;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_JOSN_SIZE:
|
|
|
|
|
{
|
|
|
|
|
val = 0;
|
|
|
|
|
printf("\n json path =%s ",jsonpath.c_str());
|
|
|
|
|
if(b_supported_w_r(jsonpath,false) == false)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
struct stat buff;
|
|
|
|
|
printf("\n json path =%s ",jsonpath.c_str());
|
|
|
|
|
if (stat(jsonpath.c_str(), &buff) == 0)//存在
|
|
|
|
|
{
|
|
|
|
|
val = buff.st_size;
|
|
|
|
|
printf("\n json size =%d ",val);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_FILE_POS:
|
|
|
|
|
{
|
|
|
|
|
val = file_pos;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_FEEDMODE:
|
|
|
|
|
{
|
|
|
|
|
val = MotorboardParam().GetOrSetFeedMode(true,0);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_TRAYPOSITION:
|
|
|
|
|
{
|
|
|
|
|
val = MotorboardParam().GetOrSetTrayPosition(true,0);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_AUTOMATICCONTROLFEEDMODE_ENABLE:
|
|
|
|
|
{
|
|
|
|
|
val = MotorboardParam().GetOrSetEnableAutomaticControlFeedMode(true,0);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_AUTOMATICCONTROLFEEDMODE_THRESHOLD:
|
|
|
|
|
{
|
|
|
|
|
float tmp = MotorboardParam().GetParam().automaticcontrolfeedmode_threshold;
|
|
|
|
|
val = *((unsigned int *)&tmp);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_LOCK_STATES:
|
|
|
|
|
{
|
|
|
|
|
val = Get_static_deviceconfig().GetParam().is_lock;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_TOKEN_LENGHT:
|
|
|
|
|
{
|
|
|
|
|
auto tmp = Get_static_deviceconfig().GetParam().token;
|
|
|
|
|
tmp = Base64().Encode((const uchar*)tmp.c_str(),tmp.length());
|
|
|
|
|
val = tmp.length();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_EXECUTE_CMD_OUT_LENGHT:
|
|
|
|
|
{
|
|
|
|
|
val = cmd_out.size();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_GRAYCORRECT_MODE:
|
|
|
|
|
{
|
|
|
|
|
val = Get_static_deviceconfig().GetParam().gray_param;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_DAIL_CODE:
|
|
|
|
|
{
|
|
|
|
|
val = Dail().GetValue().value;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_ARM_DATETIME_LENGHT:
|
|
|
|
|
{
|
|
|
|
|
arm_datetime = get_system_output("date +\"%Y-%m-%d %H:%M:%S\"");
|
|
|
|
|
printf("SR_GET_ARM_DATETIME_LENGHT %s \n",arm_datetime.c_str());
|
|
|
|
|
val = arm_datetime.size();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_LCD_LANGUAGE:
|
|
|
|
|
{
|
|
|
|
|
val = Get_static_deviceconfig().GetParam().language;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2024-03-18 06:31:20 +00:00
|
|
|
|
case SR_GET_SENSOR_CONFIG_LENGHT:
|
|
|
|
|
{
|
|
|
|
|
json j = Get_Static_SC().get_mem_param_js();
|
|
|
|
|
val = j.dump().length();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_ULTRASONIC_VERSION:
|
|
|
|
|
{
|
|
|
|
|
val = scanner->get_ultrasonic_version();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2024-03-05 03:46:18 +00:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ScannerRegAccess::cmd(const unsigned int val)
|
|
|
|
|
{
|
|
|
|
|
switch (val)
|
|
|
|
|
{
|
|
|
|
|
case SC_START:
|
|
|
|
|
scanner->try_scan(m_token);
|
|
|
|
|
m_token = "null";
|
|
|
|
|
//scanner->start_scan();
|
|
|
|
|
return true;
|
|
|
|
|
case SC_STOP:
|
|
|
|
|
scanner->stop_scan();
|
|
|
|
|
return true;
|
|
|
|
|
case SC_CLEAR:
|
|
|
|
|
scanner->clear_error();
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ScannerRegAccess::procscannerinfo(unsigned int addr, unsigned int &value)
|
|
|
|
|
{
|
|
|
|
|
bool ret = true;
|
|
|
|
|
auto info = getscannerinfo();
|
|
|
|
|
switch (addr)
|
|
|
|
|
{
|
|
|
|
|
case SR_SET_SERIALNUM:
|
|
|
|
|
{
|
|
|
|
|
printf("SR_SET_SERIALNUM length = %d \n", value);
|
|
|
|
|
std::string serial;
|
|
|
|
|
if (value > 0)
|
|
|
|
|
{
|
|
|
|
|
serial.resize(value);
|
|
|
|
|
recieve->read_bulk(&serial[0], value);
|
|
|
|
|
info.SerialNum = serial;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
ret = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_SERIALNUM:
|
|
|
|
|
transmit->write_bulk(&info.SerialNum[0], info.SerialNum.length());
|
|
|
|
|
break;
|
|
|
|
|
case SR_GET_SERIAL_LEN:
|
|
|
|
|
value = info.SerialNum.length();
|
|
|
|
|
break;
|
|
|
|
|
case SR_GET_H_RATIO:
|
|
|
|
|
value = info.H_ratio;
|
|
|
|
|
break;
|
|
|
|
|
case SR_SET_H_RATIO:
|
|
|
|
|
{
|
|
|
|
|
float fx = *((float *)&value);
|
|
|
|
|
if (fx > 1.2f || fx < 0.8f)
|
|
|
|
|
break;
|
|
|
|
|
info.H_ratio = value;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_V_RATIO:
|
|
|
|
|
value = info.V_ratio;
|
|
|
|
|
break;
|
|
|
|
|
case SR_SET_V_RATIO:
|
|
|
|
|
{
|
|
|
|
|
float fy = *((float *)&value);
|
|
|
|
|
if (fy > 1.2f || fy < 0.8f)
|
|
|
|
|
break;
|
|
|
|
|
info.V_ratio = value;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_H_200_RATIO:
|
|
|
|
|
case SR_GET_H_300_RATIO:
|
|
|
|
|
case SR_GET_H_600_RATIO:
|
|
|
|
|
if(scanner->get_fpga_version() >0x91000 && scanner->get_fpga_version() >0xb0000)
|
|
|
|
|
value = Get_Static_CorrectParam().GetFpgaparam_8478(addr == SR_GET_H_200_RATIO? 1:(addr == SR_GET_H_300_RATIO? 2:3),1).HRatio;
|
|
|
|
|
else
|
|
|
|
|
value = Get_Static_CorrectParam().GetFpgaparam(addr == SR_GET_H_200_RATIO? 1:(addr == SR_GET_H_300_RATIO? 2:3),1).HRatio;
|
|
|
|
|
break;
|
|
|
|
|
case SR_SET_H_200_RATIO:
|
|
|
|
|
case SR_SET_H_300_RATIO:
|
|
|
|
|
case SR_SET_H_600_RATIO:
|
|
|
|
|
{
|
|
|
|
|
float fx = *((float *)&value);
|
|
|
|
|
if (fx > 1.2f || fx < 0.8f)
|
|
|
|
|
break;
|
|
|
|
|
for(int x = 0;x<2;x++){
|
|
|
|
|
if(scanner->get_fpga_version() >0x91000 && scanner->get_fpga_version() >0xb0000){
|
|
|
|
|
auto tmp = Get_Static_CorrectParam().GetFpgaparam_8478(addr == SR_SET_H_200_RATIO? 1:(addr == SR_SET_H_300_RATIO? 2:3),x);
|
|
|
|
|
tmp.HRatio = value;
|
|
|
|
|
Get_Static_CorrectParam().SaveCorrectParam(tmp);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
auto tmp = Get_Static_CorrectParam().GetFpgaparam(addr == SR_SET_H_200_RATIO? 1:(addr == SR_SET_H_300_RATIO? 2:3),x);
|
|
|
|
|
tmp.HRatio = value;
|
|
|
|
|
Get_Static_CorrectParam().SaveCorrectParam(tmp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SR_GET_V_200_RATIO:
|
|
|
|
|
case SR_GET_V_300_RATIO:
|
|
|
|
|
case SR_GET_V_600_RATIO:
|
|
|
|
|
if(scanner->get_fpga_version() >0x91000 && scanner->get_fpga_version() >0xb0000)
|
|
|
|
|
value = Get_Static_CorrectParam().GetFpgaparam_8478(addr == SR_GET_V_200_RATIO? 1:(addr == SR_GET_V_300_RATIO? 2:3),1).VRatio;
|
|
|
|
|
else
|
|
|
|
|
value = Get_Static_CorrectParam().GetFpgaparam(addr == SR_GET_V_200_RATIO? 1:(addr == SR_GET_V_300_RATIO? 2:3),1).VRatio;
|
|
|
|
|
break;
|
|
|
|
|
case SR_SET_V_200_RATIO:
|
|
|
|
|
case SR_SET_V_300_RATIO:
|
|
|
|
|
case SR_SET_V_600_RATIO:
|
|
|
|
|
{
|
|
|
|
|
float fy = *((float *)&value);
|
|
|
|
|
if (fy > 1.2f || fy < 0.8f)
|
|
|
|
|
break;
|
|
|
|
|
for(int x = 0;x<2;x++){
|
|
|
|
|
if(scanner->get_fpga_version() >0x91000 && scanner->get_fpga_version() >0xb0000){
|
|
|
|
|
auto tmp = Get_Static_CorrectParam().GetFpgaparam_8478(addr == SR_SET_V_200_RATIO? 1:(addr == SR_SET_V_300_RATIO? 2:3),x);
|
|
|
|
|
tmp.VRatio = value;
|
|
|
|
|
Get_Static_CorrectParam().SaveCorrectParam(tmp);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
auto tmp = Get_Static_CorrectParam().GetFpgaparam(addr == SR_SET_V_200_RATIO? 1:(addr == SR_SET_V_300_RATIO? 2:3),x);
|
|
|
|
|
tmp.VRatio = value;
|
|
|
|
|
Get_Static_CorrectParam().SaveCorrectParam(tmp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
ret = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
savescannerinfo(info);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScannerRegAccess::write_info(std::string info)
|
|
|
|
|
{
|
|
|
|
|
if (transmit.get())
|
|
|
|
|
{
|
|
|
|
|
auto ret = transmit->write_bulk(const_cast<char *>(info.c_str()), info.length());
|
|
|
|
|
LOG_TRACE(string_format("write info error !with info =%s ", info.c_str()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScannerRegAccess::setcameraparmSp(int speedmode){
|
|
|
|
|
if(cameraparmSp.find(SpeedMode(speedmode)) == cameraparmSp.end())
|
|
|
|
|
return ;
|
|
|
|
|
CorrectParam cparam;
|
|
|
|
|
for(int i=1;i<4;i++)
|
|
|
|
|
{
|
|
|
|
|
for(int j =0; j<2;j++)
|
|
|
|
|
{
|
|
|
|
|
auto param = cparam.GetFpgaparam(i,j);
|
|
|
|
|
auto param_8478 = cparam.GetFpgaparam_8478(i,j);
|
|
|
|
|
if((j==1)&& (i==1)){
|
|
|
|
|
param.Sp = cameraparmSp[(SpeedMode)speedmode].colorSp_200;
|
|
|
|
|
param_8478.Sp = cameraparmSp_8478[(SpeedMode)speedmode].colorSp_200;
|
|
|
|
|
}
|
|
|
|
|
if((j==0)&& (i==1)){
|
|
|
|
|
param.Sp = cameraparmSp[(SpeedMode)speedmode].graySp_200;
|
|
|
|
|
param_8478.Sp = cameraparmSp_8478[(SpeedMode)speedmode].graySp_200;
|
|
|
|
|
}
|
|
|
|
|
if((j==1)&& (i==2)){
|
|
|
|
|
param.Sp = cameraparmSp[(SpeedMode)speedmode].colorSp_300;
|
|
|
|
|
param_8478.Sp = cameraparmSp_8478[(SpeedMode)speedmode].colorSp_300;
|
|
|
|
|
}
|
|
|
|
|
if((j==0)&& (i==2)){
|
|
|
|
|
param.Sp = cameraparmSp[(SpeedMode)speedmode].graySp_300;
|
|
|
|
|
param_8478.Sp = cameraparmSp_8478[(SpeedMode)speedmode].graySp_300;
|
|
|
|
|
}
|
|
|
|
|
if((j==1)&& (i==3)){
|
|
|
|
|
param.Sp = cameraparmSp[(SpeedMode)speedmode].colorSp_600;
|
|
|
|
|
param_8478.Sp = cameraparmSp_8478[(SpeedMode)speedmode].colorSp_600;
|
|
|
|
|
}
|
|
|
|
|
if((j==0)&& (i==3)){
|
|
|
|
|
param.Sp = cameraparmSp[(SpeedMode)speedmode].graySp_600;
|
|
|
|
|
param_8478.Sp = cameraparmSp_8478[(SpeedMode)speedmode].graySp_600;
|
|
|
|
|
}
|
|
|
|
|
printf("\n param.Sp = %d param_8478.Sp = %d", param.Sp,param_8478.Sp);
|
|
|
|
|
cparam.SaveCorrectParam(param);
|
|
|
|
|
cparam.SaveCorrectParam(param_8478);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
printf("\n slow_moire param.Sp = %d param_8478.Sp = 4680", cameraparmSp[SpeedMode::PPM110].graySp_300);
|
|
|
|
|
printf("\n slow_moire param.Sp = %d param_8478.Sp = 4680", cameraparmSp[SpeedMode::PPM110].colorSp_300);
|
|
|
|
|
cparam.set_sp(0x10,0,cameraparmSp[SpeedMode::PPM110].graySp_300);
|
|
|
|
|
cparam.set_sp(0x10,1,cameraparmSp[SpeedMode::PPM110].colorSp_300);
|
|
|
|
|
|
|
|
|
|
cparam.set_sp_8478(0x10,0,4680);
|
|
|
|
|
cparam.set_sp_8478(0x10,1,4680);
|
|
|
|
|
cparam.set_sp_8478(0x11,0,6460);
|
|
|
|
|
cparam.set_sp_8478(0x11,1,6460);
|
|
|
|
|
cparam.set_sp_8478(0x20,0,30627);
|
|
|
|
|
cparam.set_sp_8478(0x20,1,30627);
|
|
|
|
|
cparam.set_sp_8478(0x21,0,20436);
|
|
|
|
|
cparam.set_sp_8478(0x21,1,20436);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ScannerRegAccess::b_supported_w_r(std::string path,bool b_w){
|
|
|
|
|
for(auto& tmp : supported_w_r_file)
|
|
|
|
|
{
|
|
|
|
|
if((tmp.first == path) && (tmp.second >= b_w))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
char buf[1024] ={0};
|
|
|
|
|
strncpy(buf,path.c_str(),path.length());
|
|
|
|
|
std::string dir_ = dirname(buf);
|
|
|
|
|
for(auto& tmp : supported_w_r_dir)
|
|
|
|
|
{
|
|
|
|
|
if((tmp.first == dir_) && (tmp.second >= b_w))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|