添加用户权限管理;添加BMP文件头函数;restore不判断auto属性

This commit is contained in:
gb 2024-01-05 17:36:50 +08:00
parent be23610bae
commit 8f294f8bf6
24 changed files with 686 additions and 196 deletions

View File

@ -20,9 +20,9 @@
FpgaComm::controller::controller() FpgaComm::controller::controller()
{ {
status_.reset(new Gpio(PORT_STATUS)); status_.reset(new Gpio(PORT_STATUS));
reload_.reset(new GpioOut(PORT_RELOAD));
cfg_.reset(new Gpio(PORT_CONFIG)); cfg_.reset(new Gpio(PORT_CONFIG));
reset_.reset(new GpioOut(PORT_RESET)); reload_.reset(new Gpio(PORT_RELOAD));
reset_.reset(new Gpio(PORT_RESET));
} }
FpgaComm::controller::~controller() FpgaComm::controller::~controller()
{} {}
@ -56,17 +56,22 @@ void FpgaComm::controller::reload(void)
utils::to_log(LOG_LEVEL_DEBUG, "FPGA-reload set High after 3 seconds: %d\n", status_->getValue()); utils::to_log(LOG_LEVEL_DEBUG, "FPGA-reload set High after 3 seconds: %d\n", status_->getValue());
} }
FpgaComm::FpgaComm(int bauds) : bauds_(bauds) FpgaComm::FpgaComm(int bauds, bool query) : bauds_(bauds)
{ {
controller_.reset(new controller()); controller_.reset(new controller());
m_regsAccess.reset(new UartRegsAccess(FPGA_UART, bauds_, 0x03, 0x83)); m_regsAccess.reset(new UartRegsAccess(FPGA_UART, bauds_, 0x03, 0x83));
update(); if(query)
return;
ok_ = update();
if(ok_)
{
Reg(AledR).sample = 256; Reg(AledR).sample = 256;
WR_Reg(AledR); WR_Reg(AledR);
controller_->reset(); controller_->reset();
} }
}
bool FpgaComm::read(unsigned int addr, unsigned int& val) { bool FpgaComm::read(unsigned int addr, unsigned int& val) {
return m_regsAccess->read(addr, val); return m_regsAccess->read(addr, val);
@ -319,13 +324,25 @@ void FpgaComm::setDelayTime(int value) {
WR_Reg(DelayTime); WR_Reg(DelayTime);
} }
void FpgaComm::update() bool FpgaComm::update()
{ {
// spends 6.5s bool good = true;
chronograph watch;
utils::to_log(LOG_LEVEL_DEBUG, "Read %u FpgaComm registers ...\n", MAX_REGS);
for(int i = 0; i < MAX_REGS; i++) for(int i = 0; i < MAX_REGS; i++)
{ {
read(i, fpgaParams.regs[i]); good = read(i, fpgaParams.regs[i]);
if(!good)
{
utils::to_log(LOG_LEVEL_FATAL, " FATAL: Register %d(0x%08x) timeout.\n", i, fpgaParams.regs[i]);
break;
} }
utils::to_log(LOG_LEVEL_DEBUG, " reg(%02d) = 0x%08x\n", i, fpgaParams.regs[i]);
}
utils::to_log(LOG_LEVEL_DEBUG, "Read FpgaComm registers over.\n");
return good;
} }
void FpgaComm::enableJamCheck(bool b){ void FpgaComm::enableJamCheck(bool b){
@ -403,3 +420,8 @@ void FpgaComm::resetADC() {
fpgaParams.mode.adcB = 0; fpgaParams.mode.adcB = 0;
WR_Reg(mode); WR_Reg(mode);
} }
bool FpgaComm::is_ok(void)
{
return ok_;
}

View File

@ -6,7 +6,7 @@
#ifdef HAS_UV #ifdef HAS_UV
#define MAX_REGS 0x0e #define MAX_REGS 0x0e
#else #else
#define MAX_REGS 0x0d #define MAX_REGS 0x10
#endif #endif
typedef struct Frame_FPGA typedef struct Frame_FPGA
@ -114,7 +114,7 @@ typedef union Fpga_Params
unsigned int DelayTime; //0x0c unsigned int DelayTime; //0x0c
CisLedUv UVLed; CisLedUv UVLed;
}; };
unsigned int regs[14]; unsigned int regs[MAX_REGS];
} FpgaParams; } FpgaParams;
#define FPGA_UART "/dev/ttyUSB0" #define FPGA_UART "/dev/ttyUSB0"
@ -137,6 +137,7 @@ class Gpio;
class FpgaComm : public IRegsAccess class FpgaComm : public IRegsAccess
{ {
int bauds_ = 921600; int bauds_ = 921600;
bool ok_ = true;
class controller class controller
{ {
@ -148,9 +149,9 @@ class FpgaComm : public IRegsAccess
PORT_RESET = 232, PORT_RESET = 232,
}; };
std::unique_ptr<Gpio> status_; // status reader - port 69 std::unique_ptr<Gpio> status_; // status reader - port 69
std::unique_ptr<GpioOut> reload_; // codes reload - port 70 std::unique_ptr<Gpio> reload_; // codes reload - port 70
std::unique_ptr<Gpio> cfg_; // configuration reload - port 71 std::unique_ptr<Gpio> cfg_; // configuration reload - port 71
std::unique_ptr<GpioOut> reset_; // circuit reset - port Fpga_Reset std::unique_ptr<Gpio> reset_; // circuit reset - port Fpga_Reset
public: public:
controller(); controller();
@ -163,7 +164,7 @@ class FpgaComm : public IRegsAccess
std::unique_ptr<controller> controller_; std::unique_ptr<controller> controller_;
public: public:
FpgaComm(int bauds = 921600); FpgaComm(int bauds = 921600, bool query = false);
virtual ~FpgaComm(){} virtual ~FpgaComm(){}
enum { CIS_SECTOR_COUNT = 6 }; // how many sectors of ONE CIS enum { CIS_SECTOR_COUNT = 6 }; // how many sectors of ONE CIS
@ -212,12 +213,14 @@ public:
void setDelayTime(int value); void setDelayTime(int value);
void setTrigMode(bool isArmMode); void setTrigMode(bool isArmMode);
void update(); bool update();
void enableJamCheck(bool b); void enableJamCheck(bool b);
void resetADC(); void resetADC();
virtual bool write(unsigned int addr, unsigned int val); virtual bool write(unsigned int addr, unsigned int val);
virtual bool read(unsigned int addr, unsigned int& val); virtual bool read(unsigned int addr, unsigned int& val);
bool is_ok(void);
private: private:
FpgaParams fpgaParams; FpgaParams fpgaParams;
std::shared_ptr<IRegsAccess> m_regsAccess; std::shared_ptr<IRegsAccess> m_regsAccess;

View File

@ -221,7 +221,6 @@ void gVideo::uninit_device(void)
struct v4l2_requestbuffers req; struct v4l2_requestbuffers req;
CLEAR(req); CLEAR(req);
req.count = 0; req.count = 0;
LOG_TRACE(utils::format_string("frame count: %d\n", req.count));
req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
req.memory = V4L2_MEMORY_USERPTR; req.memory = V4L2_MEMORY_USERPTR;
@ -232,6 +231,10 @@ void gVideo::uninit_device(void)
else else
utils::to_log(LOG_LEVEL_FATAL, "VIDIOC_REQBUFS\n"); utils::to_log(LOG_LEVEL_FATAL, "VIDIOC_REQBUFS\n");
} }
else
{
LOG_TRACE(utils::format_string("rest frame count: %d\n", req.count));
}
for (int i = 0; i < n_buffers; ++i) for (int i = 0; i < n_buffers; ++i)
free(buffers[i].start); free(buffers[i].start);

File diff suppressed because one or more lines are too long

View File

@ -69,6 +69,7 @@ class scanner_hw : public sane_opt_provider
void init(void); void init(void);
void init_version(std::string& text);
void thread_image_capture(void); void thread_image_capture(void);
bool is_scan_fatal(void); bool is_scan_fatal(void);
void retrieve_v4l2_mem(safe_fifo<int>* mem, int* used); void retrieve_v4l2_mem(safe_fifo<int>* mem, int* used);
@ -90,6 +91,7 @@ public:
int start_scan(void); int start_scan(void);
int stop_scan(void); int stop_scan(void);
int close(void); int close(void);
bool is_scanning(void);
}; };
// { // {
// "mode": { // "mode": {
@ -556,5 +558,34 @@ public:
// "step": 1 // "step": 1
// }, // },
// "depend": "is-check-askew==true" // "depend": "is-check-askew==true"
// },
// "motor-ver": {
// "cat": "none",
// "group": "关于",
// "title": "电机驱动版本",
// "desc": "电机板驱动程序版本号",
// "type": "string",
// "fix-id": 34909,
// "ui-pos": 16,
// "auth": 0,
// "readonly": true,
// "size": 24,
// "auto": false,
// "cur": "",
// "default": ""
// },
// "fpga-ver": {
// "cat": "none",
// "group": "关于",
// "title": "CIS控制器版本",
// "desc": "镜头参数控制驱动程序版本号",
// "type": "string",
// "ui-pos": 17,
// "auth": 0,
// "readonly": true,
// "size": 24,
// "auto": false,
// "cur": "",
// "default": ""
// } // }
// } // }

View File

@ -13,10 +13,18 @@
static const std::string loggername = "MotorBoard"; static const std::string loggername = "MotorBoard";
MotorBoard::MotorBoard() MotorBoard::MotorBoard(std::function<void(int, unsigned int)> cbev)
: devPort(MOTOR_UART), : devPort(MOTOR_UART)
m_glue({nullptr, nullptr, nullptr,nullptr,nullptr,nullptr}) , cb_event_(cbev)
{ {
auto cb_null = [&](int type, unsigned int val) -> void
{
utils::to_log(LOG_LEVEL_DEBUG, "motorboard event %d value: 0x%08x\n", type, val);
};
if(!cb_event_)
cb_event_ = cb_null;
m_uartEnable.reset(new GpioOut(152)); m_uartEnable.reset(new GpioOut(152));
m_uartEnable->setDirection(Gpio::out); m_uartEnable->setDirection(Gpio::out);
// m_uartEnable->setEdge(Gpio::rising); // m_uartEnable->setEdge(Gpio::rising);
@ -33,6 +41,8 @@ static int paperinnum = 0;
void MotorBoard::start() void MotorBoard::start()
{ {
keep_last_paper=false; keep_last_paper=false;
paperinnum = 0 ;
unsigned int val; unsigned int val;
SMBCONFIG *smbc = (SMBCONFIG *)(&val); SMBCONFIG *smbc = (SMBCONFIG *)(&val);
read(0, val); read(0, val);
@ -40,7 +50,6 @@ void MotorBoard::start()
write(0, val); write(0, val);
smbc->enable = 1; smbc->enable = 1;
write(0, val); write(0, val);
paperinnum =0 ;
} }
void MotorBoard::stop() void MotorBoard::stop()
@ -253,55 +262,50 @@ std::shared_ptr<IRegsAccess> MotorBoard::regs()
static int pinindex=0; static int pinindex=0;
void MotorBoard::pin_call(unsigned int pinNum) void MotorBoard::pin_call(unsigned int pinNum)
{ {
static int index = 0;
utils::to_log(LOG_LEVEL_DEBUG, utils::format_string("pin %d", index++).c_str());
int os_m = os_mode(); int os_m = os_mode();
if (m_os_mode != os_m) if (m_os_mode != os_m)
{ {
m_os_mode = os_m; m_os_mode = os_m;
cv_os_mode.notify_all(); cv_os_mode.notify_all();
if (m_glue.m_os_mode_call) cb_event_(MOTOR_BORD_EVENT_MODE, m_os_mode);
m_glue.m_os_mode_call(m_os_mode);
} }
if (m_os_mode) if (m_os_mode)
{ {
utils::to_log(LOG_LEVEL_DEBUG, "not scan mode"); // utils::to_log(LOG_LEVEL_DEBUG, "not scan mode");
return; return;
} }
unsigned int val; unsigned int val;
SMBSTATUS *smb_status = (SMBSTATUS *)&val; SMBSTATUS *smb_status = (SMBSTATUS *)&val;
if (!read(PORT_STATUS, val)) if (!read(PORT_STATUS, val))
utils::to_log(LOG_LEVEL_DEBUG, "read error"); {
utils::to_log(LOG_LEVEL_DEBUG, utils::format_string("status %08x", val).c_str()); utils::to_log(LOG_LEVEL_DEBUG, "read motorboard status failed\n");
return;
}
utils::to_log(LOG_LEVEL_DEBUG, utils::format_string("motorboard status %08x\n", val).c_str());
//printf("\n reg 1 val =%d",val); //printf("\n reg 1 val =%d",val);
if(val & 0x800){ if(smb_status->keep_last_paper) // (val & 0x800)
//printf("\n keep_last_paper "); {
keep_last_paper=true; keep_last_paper=true;
} }
if(val & 0x1000) if(smb_status->sleep_set) // (val & 0x1000)
{ {
if(m_glue.m_set_sleepmode_call) cb_event_(MOTOR_BORD_EVENT_SLEEP, smb_status->sleep_conf);
m_glue.m_set_sleepmode_call(val & 0xf000);
} }
if(val & 0x80000) if(smb_status->ml_top_sin) // (val & 0x80000)
{ {
if(m_glue.m_mltop_call) cb_event_(MOTOR_BORD_EVENT_LIFTER_READY, smb_status->ml_top_sin);
m_glue.m_mltop_call(val);
} }
if(smb_status->paper_auto) if(smb_status->paper_auto)
{ {
if(m_glue.m_auto_paper) cb_event_(MOTOR_BORD_EVENT_PAPER_READY, smb_status->paper_auto);
m_glue.m_auto_paper(1);
} }
if (val & 0xAFE) if (val & STATUS_ERROR_MASK)
{ {
cv_error.notify_all(); cv_error.notify_all();
if (m_glue.m_error_call) cb_event_(MOTOR_BORD_EVENT_ERROR, val & STATUS_ERROR_MASK);
m_glue.m_error_call(val & 0x30efe); //0xefe index of 16:aquireimage error index of bit 17 :size check error
utils::to_log(LOG_LEVEL_DEBUG, "error");
return; return;
} }
else else
@ -309,23 +313,21 @@ void MotorBoard::pin_call(unsigned int pinNum)
if (!smb_status->scan_pulse) if (!smb_status->scan_pulse)
{ {
cv_paper_in.notify_all(); cv_paper_in.notify_all();
utils::to_log(LOG_LEVEL_DEBUG, "paper in"); paperinnum++;
printf("\n paper pulse num = %d ", paperinnum++); cb_event_(MOTOR_BORD_EVENT_PAPER_PASSING, 1);
} }
if(smb_status->paper_left) if(smb_status->paper_left)
{ {
cv_paper_out.notify_all(); cv_paper_out.notify_all();
utils::to_log(LOG_LEVEL_DEBUG, "paper left"); cb_event_(MOTOR_BORD_EVENT_PAPER_PASSING, 0);
} }
} }
if (val & 0x400) if (smb_status->motor_status) // (val & 0x400)
{ {
utils::to_log(LOG_LEVEL_DEBUG, "done");
cv_scan_done.notify_all(); cv_scan_done.notify_all();
if (m_glue.m_scan_done_call) cb_event_(MOTOR_BORD_EVENT_SCAN_DONE, 1);
m_glue.m_scan_done_call();
} }
} }
@ -347,10 +349,6 @@ bool MotorBoard::read(unsigned int addr, unsigned int &val)
return m_regsAccess->read(addr, val); return m_regsAccess->read(addr, val);
} }
void MotorBoard::set_callbacks(MotorBoardGlue glue)
{
m_glue = glue;
}
bool MotorBoard::set_screw_inpect(bool enable) bool MotorBoard::set_screw_inpect(bool enable)
{ {

View File

@ -37,34 +37,44 @@ typedef struct SMB_CONFIG
typedef struct SMB_STATUS typedef struct SMB_STATUS
{ {
unsigned int scan_pulse : 1; unsigned int scan_pulse : 1; // 0x000001
unsigned int m1_paper_sin : 1; unsigned int m1_paper_sin : 1; // 0x000002
unsigned int open_machine : 1; unsigned int open_machine : 1; // 0x000004
unsigned int pick_failed : 1; unsigned int pick_failed : 1; // 0x000008
unsigned int stop_jam : 1; // 5
unsigned int double_paper : 1; unsigned int stop_jam : 1; // 5 // 0x000010
unsigned int staple : 1; unsigned int double_paper : 1; // 0x000020
unsigned int papertilted : 1; unsigned int staple : 1; // 0x000040
unsigned int count_pulse : 1; unsigned int papertilted : 1; // 0x000080
unsigned int scan_mode_change : 1; // 5
unsigned int motor_status : 1; unsigned int count_pulse : 1; // 0x000100
unsigned int keep_last_paper : 1; unsigned int scan_mode_change : 1; // 5 // 0x000200
unsigned int sleep_set : 1; unsigned int motor_status : 1; // 0x000400
unsigned int sleep_conf : 3; unsigned int keep_last_paper : 1; // 0x000800
unsigned int dsp_get_paper_error : 1;
unsigned int paper_check_result : 1; unsigned int sleep_set : 1; // 0x001000
unsigned int top_wuzhi : 1; unsigned int sleep_conf : 3; // 0x00e000
unsigned int ml_top_sin : 1; // 10
unsigned int paper_auto : 1; unsigned int dsp_get_paper_error : 1; // 0x010000
unsigned int paper_left : 1; unsigned int paper_check_result : 1; // 0x020000
unsigned int top_wuzhi : 1; // 0x040000
unsigned int ml_top_sin : 1; // 10 // 0x080000
unsigned int paper_auto : 1; // 0x100000
unsigned int paper_left : 1; // 0x200000
} SMBSTATUS; } SMBSTATUS;
#define STATUS_ERROR_MASK 0x30EFE
typedef struct SMB_MODE typedef struct SMB_MODE
{ {
unsigned int scan_num : 14; unsigned int scan_num : 14;
unsigned int scan_mode : 2; unsigned int scan_mode : 2;
unsigned int feeding_paper_ready : 1; unsigned int feeding_paper_ready : 1;
unsigned int work_status : 1; unsigned int work_status : 1;
unsigned int paper_jammed_in : 2;
unsigned int paper_jammed_out : 1;
} SMBMODE; } SMBMODE;
typedef struct SMB_CONFIG_EXT typedef struct SMB_CONFIG_EXT
@ -75,30 +85,6 @@ typedef struct SMB_CONFIG_EXT
unsigned int cuo_speed : 7; unsigned int cuo_speed : 7;
} SMBCONFIGEXT; } SMBCONFIGEXT;
struct MotorBoardGlue
{
MotorBoardGlue(const std::function<void(unsigned int)> error_call,
const std::function<void()> scan_done_call,
const std::function<void(unsigned int)> os_mode_call,
const std::function<void(unsigned int)> set_sleepmode_call,
const std::function<void(unsigned int)> mltop_call,
std::function<void(unsigned int)> auto_paper)
: m_error_call(error_call),
m_scan_done_call(scan_done_call),
m_os_mode_call(os_mode_call),
m_set_sleepmode_call(set_sleepmode_call),
m_mltop_call(mltop_call),
m_auto_paper(auto_paper)
{
}
std::function<void(unsigned int)> m_error_call;
std::function<void()> m_scan_done_call;
std::function<void(unsigned int)> m_os_mode_call;
std::function<void(unsigned int)> m_set_sleepmode_call;
std::function<void(unsigned int)> m_mltop_call;
std::function<void(unsigned int)> m_auto_paper;
};
enum enum
{ {
@ -116,10 +102,23 @@ enum
SPEED_PPM_BASE_30, SPEED_PPM_BASE_30,
}; };
enum
{
MOTOR_BORD_EVENT_MODE = 1, // os mode changed, value = new mode
MOTOR_BORD_EVENT_SLEEP, //
MOTOR_BORD_EVENT_LIFTER_READY, //
MOTOR_BORD_EVENT_PAPER_READY,
MOTOR_BORD_EVENT_PAPER_PASSING, // value = 0: paper left, 1: paper is passing through the sensor
MOTOR_BORD_EVENT_SCAN_DONE,
MOTOR_BORD_EVENT_ERROR, // value = SMBSTATUS
};
class MotorBoard class MotorBoard
{ {
std::function<void(int, unsigned int)> cb_event_;
public: public:
MotorBoard(); MotorBoard(std::function<void(int, unsigned int)> cbev = std::function<void(int, unsigned int)>());
void start(); void start();
void stop(); void stop();
@ -153,7 +152,6 @@ public:
bool set_paper_inpect_info(unsigned int value); bool set_paper_inpect_info(unsigned int value);
bool set_paper_inspect(bool enable = true); bool set_paper_inspect(bool enable = true);
bool set_cuospeed(unsigned int speed); bool set_cuospeed(unsigned int speed);
void set_callbacks(MotorBoardGlue glue);
bool get_keeplastpaper(); bool get_keeplastpaper();
bool en_testbit(bool en); bool en_testbit(bool en);
std::shared_ptr<IRegsAccess> regs(); std::shared_ptr<IRegsAccess> regs();
@ -179,6 +177,5 @@ private:
AutoSemaphore cv_os_mode; AutoSemaphore cv_os_mode;
unsigned int m_os_mode; unsigned int m_os_mode;
volatile bool keep_last_paper; volatile bool keep_last_paper;
MotorBoardGlue m_glue;
bool b_paperin; bool b_paperin;
}; };

View File

@ -14,6 +14,7 @@
#include <huagao/hgscanner_error.h> #include <huagao/hgscanner_error.h>
#include "scanner_const_opts.h" #include "scanner_const_opts.h"
#include <hardware.h> #include <hardware.h>
#include <base/user.h>
@ -30,7 +31,7 @@ async_scanner::async_scanner() : usb_(nullptr), cfg_mgr_(nullptr), scan_id_(0)
{ {
utils::init_log(LOG_TYPE_FILE); utils::init_log(LOG_TYPE_FILE);
utils::to_log(LOG_LEVEL_DEBUG, "System info: page-size = %u, mapping-page-size = %u, disk-cluster-size = %u.\n" utils::to_log(LOG_LEVEL_DEBUG, "System info: page-size = %u, mapping-page-size = %u, disk-cluster-size = %u.\n"
, sys_info::page_size, sys_info::page_map_size, sys_info::cluster_size); , global_info::page_size, global_info::page_map_size, global_info::cluster_size);
init(); init();
auto bulk_handle = [&](dyn_mem_ptr data, uint32_t* used, packet_data_base_ptr* required) -> dyn_mem_ptr auto bulk_handle = [&](dyn_mem_ptr data, uint32_t* used, packet_data_base_ptr* required) -> dyn_mem_ptr
@ -52,18 +53,22 @@ async_scanner::async_scanner() : usb_(nullptr), cfg_mgr_(nullptr), scan_id_(0)
auto user = [&](int priv) -> bool auto user = [&](int priv) -> bool
{ {
return true; return user_->has_privilege(priv);
}; };
auto on_log = [&](const char* msg) -> void auto on_log = [&](const char* msg) -> void
{ {
utils::log_info(msg, LOG_LEVEL_DEBUG); utils::log_info(msg, LOG_LEVEL_DEBUG);
}; };
cfg_mgr_ = new device_option(true, user, on_log); cfg_mgr_ = new device_option(true, user, on_log);
utils::to_log(LOG_LEVEL_DEBUG, "OPT - initializing ...\n"); utils::to_log(LOG_LEVEL_DEBUG, "OPT - initializing ...\n");
const_opts_ = new scanner_const_opts(); const_opts_ = new scanner_const_opts();
user_ = new user_priv();
cfg_mgr_->add(const_opts_); cfg_mgr_->add(const_opts_);
cis_->set_value(SANE_FULL_NAME(DEVICE_MODEL), &cfg_mgr_->get_option_value(SANE_FULL_NAME(DEVICE_MODEL), SANE_ACTION_GET_VALUE)[0]); cis_->set_value(SANE_FULL_NAME(DEVICE_MODEL), &cfg_mgr_->get_option_value(SANE_FULL_NAME(DEVICE_MODEL), SANE_ACTION_GET_VALUE)[0]);
cfg_mgr_->add(cis_); cfg_mgr_->add(cis_);
cfg_mgr_->add(user_);
utils::to_log(LOG_LEVEL_DEBUG, "OPT - initialized %u options.\n", cfg_mgr_->count()); utils::to_log(LOG_LEVEL_DEBUG, "OPT - initialized %u options.\n", cfg_mgr_->count());
usb_ = new async_usb_gadget(bulk_handle, on_connect); usb_ = new async_usb_gadget(bulk_handle, on_connect);
@ -94,6 +99,7 @@ async_scanner::~async_scanner()
v->release(); v->release();
send_files_.clear(); send_files_.clear();
const_opts_->release(); const_opts_->release();
user_->release();
utils::uninit(); utils::uninit();
} }
@ -165,6 +171,22 @@ void async_scanner::init(void)
{ {
cis_ = new scanner_hw(); cis_ = new scanner_hw();
} }
bool async_scanner::on_energy_conservation(bool normal)
{
bool enable = true;
if(normal)
{
}
else
{
if(cis_->is_scanning())
enable = false;
}
return enable;
}
dyn_mem_ptr async_scanner::handle_simple_roger(LPPACK_BASE pack, uint32_t* used, packet_data_base_ptr* required) dyn_mem_ptr async_scanner::handle_simple_roger(LPPACK_BASE pack, uint32_t* used, packet_data_base_ptr* required)
{ {
@ -232,7 +254,8 @@ dyn_mem_ptr async_scanner::handle_get_opt_all(LPPACK_BASE pack, uint32_t* used,
return reply; return reply;
} }
dyn_mem_ptr async_scanner::handle_set_opt(LPPACK_BASE pack, uint32_t* used, packet_data_base_ptr* required) dyn_mem_ptr async_scanner::handle_set_opt(LPPACK_BASE pack, uint32_t* used, packet_data_base_ptr* required)
{ uint32_t base_head_size = sizeof(PACK_BASE); {
uint32_t base_head_size = sizeof(PACK_BASE);
dyn_mem_ptr reply = nullptr; dyn_mem_ptr reply = nullptr;
LPPACK_BASE pk = nullptr; LPPACK_BASE pk = nullptr;

View File

@ -17,6 +17,7 @@ class img_processor;
class gb_json; class gb_json;
class scanner_const_opts; class scanner_const_opts;
class scanner_hw; class scanner_hw;
class user_priv;
class async_scanner : public refer class async_scanner : public refer
{ {
@ -24,6 +25,7 @@ class async_scanner : public refer
device_option *cfg_mgr_ = nullptr; device_option *cfg_mgr_ = nullptr;
scanner_const_opts *const_opts_ = nullptr; scanner_const_opts *const_opts_ = nullptr;
scanner_hw *cis_ = nullptr; scanner_hw *cis_ = nullptr;
user_priv *user_ = nullptr;
MUTEX locker_; MUTEX locker_;
volatile bool connected_ = false; volatile bool connected_ = false;
@ -38,6 +40,7 @@ class async_scanner : public refer
dyn_mem_ptr handle_bulk_cmd(LPPACK_BASE pack, uint32_t* used, packet_data_base_ptr* required); dyn_mem_ptr handle_bulk_cmd(LPPACK_BASE pack, uint32_t* used, packet_data_base_ptr* required);
void init(void); void init(void);
bool on_energy_conservation(bool normal/*true - working status; false - go to sleep*/); // return true to enable get into 'normal' status
dyn_mem_ptr handle_simple_roger(LPPACK_BASE pack, uint32_t* used, packet_data_base_ptr* required); dyn_mem_ptr handle_simple_roger(LPPACK_BASE pack, uint32_t* used, packet_data_base_ptr* required);
dyn_mem_ptr handle_get_opt_value(LPPACK_BASE pack, uint32_t* used, packet_data_base_ptr* required); dyn_mem_ptr handle_get_opt_value(LPPACK_BASE pack, uint32_t* used, packet_data_base_ptr* required);

View File

@ -20,7 +20,7 @@
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// option json: // option json:
static std::string device_opt_json[] = { static std::string device_opt_json[] = {
"{\"dev-vid\":{\"cat\":\"base\",\"group\":\"\\u5173\\u4e8e\",\"title\":\"USB-VID\",\"desc\":\"\\u8bbe\\u5907\\u5236\\u9020\\u5546\\u5728USB\\u7ec4\\u7ec7\\u7684ID\",\"type\":\"string\",\"fix-id\":34898,\"ui-pos\":10,\"auth\":0,\"readonly\":true,\"size\":16,\"auto\":false,\"cur\":\"3072\",\"default\":\"3072\"},\"dev-pid\":{\"cat\":\"base\",\"group\":\"\\u5173\\u4e8e\",\"title\":\"USB-PID\",\"desc\":\"\\u8bbe\\u5907\\u5728USB\\u7ec4\\u7ec7\\u4e2d\\u7684\\u4ea7\\u54c1ID\",\"type\":\"string\",\"fix-id\":34899,\"ui-pos\":11,\"auth\":0,\"readonly\":true,\"size\":16,\"auto\":false,\"cur\":\"0306\",\"default\":\"0306\"},\"dev-name\":{\"cat\":\"base\",\"group\":\"\\u5173\\u4e8e\",\"title\":\"\\u8bbe\\u5907\\u540d\\u79f0\",\"desc\":\"\\u8bbe\\u5907\\u540d\\u79f0\",\"type\":\"string\",\"fix-id\":34900,\"ui-pos\":12,\"auth\":0,\"readonly\":true,\"size\":96,\"auto\":false,\"cur\":\"300NewTx\",\"default\":\"300NewTx\"},\"dev-model\":{\"cat\":\"base\",\"group\":\"\\u5173\\u4e8e\",\"title\":\"\\u4ea7\\u54c1\\u7cfb\\u5217\",\"desc\":\"\\u8bbe\\u5907\\u6240\\u5c5e\\u4ea7\\u54c1\\u7cfb\\u5217\\u540d\\u79f0\",\"type\":\"string\",\"fix-id\":34901,\"ui-pos\":13,\"auth\":0,\"readonly\":true,\"size\":96,\"auto\":false,\"cur\":\"G300\",\"default\":\"G300\"},\"dev-sn\":{\"cat\":\"base\",\"group\":\"\\u5173\\u4e8e\",\"title\":\"\\u5e8f\\u5217\\u53f7\",\"desc\":\"\\u8bbe\\u5907\\u5e8f\\u5217\\u53f7\",\"type\":\"string\",\"fix-id\":34902,\"ui-pos\":14,\"auth\":0,\"readonly\":true,\"size\":32,\"auto\":false,\"ownread\":true,\"cur\":\"GB20231201\",\"default\":\"GB20231201\"},\"fmw-ver\":{\"cat\":\"base\",\"group\":\"\\u5173\\u4e8e\",\"title\":\"\\u56fa\\u4ef6\\u7248\\u672c\",\"desc\":\"\\u8bbe\\u5907\\u56fa\\u4ef6\\u7248\\u672c\\u53f7\",\"type\":\"string\",\"fix-id\":34903,\"ui-pos\":15,\"auth\":0,\"readonly\":true,\"size\":32,\"auto\":false,\"cur\":\"G2393B0500\",\"default\":\"G2393B0500\"},\"roller-life\":{\"cat\":\"base\",\"group\":\"\\u5173\\u4e8e\",\"title\":\"\\u6eda\\u8f74\\u5bff\\u547d\",\"desc\":\"\\u8be5\\u8bbe\\u5907\\u6eda\\u8f74\\u8fc7\\u7eb8\\u7684\\u6700\\u5927\\u5f20\\u6570\",\"type\":\"int\",\"fix-id\":34907,\"ui-pos\":16,\"auth\":0,\"readonly\":true,\"size\":4,\"auto\":false,\"cur\":450000,\"default\":450000},\"ip-addr\":{\"cat\":\"base\",\"group\":\"\\u5173\\u4e8e\",\"title\":\"IP\",\"desc\":\"\\u8bbe\\u5907\\u8054\\u7f51\\u65f6\\u6240\\u5206\\u914d\\u7684IP\\u5730\\u5740\",\"type\":\"string\",\"fix-id\":34904,\"ui-pos\":20,\"auth\":0,\"readonly\":true,\"size\":96,\"auto\":false,\"ownread\":true,\"cur\":\"0\",\"default\":\"0\"},\"mac-addr\":{\"cat\":\"base\",\"group\":\"\\u5173\\u4e8e\",\"title\":\"MAC\",\"desc\":\"\\u8bbe\\u5907\\u7f51\\u5361\\u5730\\u5740\",\"type\":\"string\",\"fix-id\":34905,\"ui-pos\":21,\"auth\":0,\"readonly\":true,\"size\":96,\"auto\":false,\"ownread\":true,\"cur\":\"0\",\"default\":\"0\"}}" "{\"dev-vid\":{\"cat\":\"base\",\"group\":\"\\u5173\\u4e8e\",\"title\":\"USB-VID\",\"desc\":\"\\u8bbe\\u5907\\u5236\\u9020\\u5546\\u5728USB\\u7ec4\\u7ec7\\u7684ID\",\"type\":\"string\",\"fix-id\":34898,\"ui-pos\":10,\"auth\":0,\"readonly\":true,\"size\":16,\"auto\":false,\"cur\":\"3072\",\"default\":\"3072\"},\"dev-pid\":{\"cat\":\"base\",\"group\":\"\\u5173\\u4e8e\",\"title\":\"USB-PID\",\"desc\":\"\\u8bbe\\u5907\\u5728USB\\u7ec4\\u7ec7\\u4e2d\\u7684\\u4ea7\\u54c1ID\",\"type\":\"string\",\"fix-id\":34899,\"ui-pos\":11,\"auth\":0,\"readonly\":true,\"size\":16,\"auto\":false,\"cur\":\"0306\",\"default\":\"0306\"},\"dev-name\":{\"cat\":\"base\",\"group\":\"\\u5173\\u4e8e\",\"title\":\"\\u8bbe\\u5907\\u540d\\u79f0\",\"desc\":\"\\u8bbe\\u5907\\u540d\\u79f0\",\"type\":\"string\",\"fix-id\":34900,\"ui-pos\":12,\"auth\":0,\"readonly\":true,\"size\":96,\"auto\":false,\"cur\":\"300NewTx\",\"default\":\"300NewTx\"},\"dev-model\":{\"cat\":\"base\",\"group\":\"\\u5173\\u4e8e\",\"title\":\"\\u4ea7\\u54c1\\u7cfb\\u5217\",\"desc\":\"\\u8bbe\\u5907\\u6240\\u5c5e\\u4ea7\\u54c1\\u7cfb\\u5217\\u540d\\u79f0\",\"type\":\"string\",\"fix-id\":34901,\"ui-pos\":13,\"auth\":0,\"readonly\":true,\"size\":96,\"auto\":false,\"cur\":\"G300\",\"default\":\"G300\"},\"dev-sn\":{\"cat\":\"base\",\"group\":\"\\u5173\\u4e8e\",\"title\":\"\\u5e8f\\u5217\\u53f7\",\"desc\":\"\\u8bbe\\u5907\\u5e8f\\u5217\\u53f7\",\"type\":\"string\",\"fix-id\":34902,\"ui-pos\":14,\"auth\":0,\"readonly\":true,\"size\":32,\"auto\":false,\"ownread\":true,\"cur\":\"GB20231201\",\"default\":\"GB20231201\"},\"fmw-ver\":{\"cat\":\"base\",\"group\":\"\\u5173\\u4e8e\",\"title\":\"\\u56fa\\u4ef6\\u7248\\u672c\",\"desc\":\"\\u8bbe\\u5907\\u56fa\\u4ef6\\u7248\\u672c\\u53f7\",\"type\":\"string\",\"fix-id\":34903,\"ui-pos\":15,\"auth\":0,\"readonly\":true,\"size\":32,\"auto\":false,\"cur\":\"G2393B0500\",\"default\":\"G2393B0500\"},\"roller-life\":{\"cat\":\"base\",\"group\":\"\\u5173\\u4e8e\",\"title\":\"\\u6eda\\u8f74\\u5bff\\u547d\",\"desc\":\"\\u8be5\\u8bbe\\u5907\\u6eda\\u8f74\\u8fc7\\u7eb8\\u7684\\u6700\\u5927\\u5f20\\u6570\",\"type\":\"int\",\"fix-id\":34907,\"ui-pos\":20,\"auth\":0,\"readonly\":true,\"size\":4,\"auto\":false,\"cur\":450000,\"default\":450000},\"ip-addr\":{\"cat\":\"base\",\"group\":\"\\u5173\\u4e8e\",\"title\":\"IP\",\"desc\":\"\\u8bbe\\u5907\\u8054\\u7f51\\u65f6\\u6240\\u5206\\u914d\\u7684IP\\u5730\\u5740\",\"type\":\"string\",\"fix-id\":34904,\"ui-pos\":21,\"auth\":0,\"readonly\":true,\"size\":96,\"auto\":false,\"ownread\":true,\"cur\":\"0\",\"default\":\"0\"},\"mac-addr\":{\"cat\":\"base\",\"group\":\"\\u5173\\u4e8e\",\"title\":\"MAC\",\"desc\":\"\\u8bbe\\u5907\\u7f51\\u5361\\u5730\\u5740\",\"type\":\"string\",\"fix-id\":34905,\"ui-pos\":22,\"auth\":0,\"readonly\":true,\"size\":96,\"auto\":false,\"ownread\":true,\"cur\":\"0\",\"default\":\"0\"}}"
}; };

View File

@ -125,7 +125,7 @@ public:
// "desc": "该设备滚轴过纸的最大张数", // "desc": "该设备滚轴过纸的最大张数",
// "type": "int", // "type": "int",
// "fix-id": 34907, // "fix-id": 34907,
// "ui-pos": 16, // "ui-pos": 20,
// "auth": 0, // "auth": 0,
// "readonly": true, // "readonly": true,
// "size": 4, // "size": 4,
@ -140,7 +140,7 @@ public:
// "desc": "设备联网时所分配的IP地址", // "desc": "设备联网时所分配的IP地址",
// "type": "string", // "type": "string",
// "fix-id": 34904, // "fix-id": 34904,
// "ui-pos": 20, // "ui-pos": 21,
// "auth": 0, // "auth": 0,
// "readonly": true, // "readonly": true,
// "size": 96, // "size": 96,
@ -156,7 +156,7 @@ public:
// "desc": "设备网卡地址", // "desc": "设备网卡地址",
// "type": "string", // "type": "string",
// "fix-id": 34905, // "fix-id": 34905,
// "ui-pos": 21, // "ui-pos": 22,
// "auth": 0, // "auth": 0,
// "readonly": true, // "readonly": true,
// "size": 96, // "size": 96,

View File

@ -10,28 +10,6 @@
#include <sys/mman.h> #include <sys/mman.h>
#endif #endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// sys_info
uint32_t sys_info::page_size = 0;
uint32_t sys_info::page_map_size = 0;
uint32_t sys_info::cluster_size = 0;
sys_info::sys_info()
{
sys_info::page_size = utils::get_page_size(&sys_info::page_map_size);
std::string path(utils::get_local_data_path());
unsigned long long cluster = 0;
utils::get_disk_space(path.c_str(), nullptr, nullptr, &cluster);
sys_info::cluster_size = cluster;
printf("Page size: %u\nMap size: %u\nCluster : %u\n", sys_info::page_size, sys_info::page_map_size, sys_info::cluster_size);
}
sys_info::~sys_info()
{}
static sys_info g_si;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// //

View File

@ -76,17 +76,6 @@ public:
uint8_t* buffer(void); uint8_t* buffer(void);
}; };
class sys_info
{
public:
sys_info();
~sys_info();
public:
static uint32_t page_size;
static uint32_t page_map_size;
static uint32_t cluster_size;
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// //

View File

@ -126,33 +126,6 @@ enum img_cb_type
IMG_CB_STOPPED, IMG_CB_STOPPED,
}; };
enum scanner_status
{
SCANNER_STATUS_READY = 0x10000, // status beginning, avoiding conficts with standards/system error code
SCANNER_STATUS_NOT_OPEN,
SCANNER_STATUS_LOST_CONNECT,
SCANNER_STATUS_RESET_BULK,
SCANNER_STATUS_START_SCANNING, // start ok, but scanning-thread not working
SCANNER_STATUS_SCANNING, // start ok, and scanning-thread is working
SCANNER_STATUS_SCAN_FINISHED, // not a persistance status
SCANNER_STATUS_BUSY, // doing task exclude scanning
SCANNER_STATUS_COVER_OPENNED,
SCANNER_STATUS_COVER_CLOSED,
SCANNER_STATUS_SLEEPING,
SCANNER_STATUS_WAKED_UP,
SCANNER_STATUS_COUNT_MODE,
SCANNER_STATUS_DOUBLE_FEEDED,
SCANNER_STATUS_PAPER_JAMMED,
SCANNER_STATUS_PAPER_ASKEW,
SCANNER_STATUS_FEED_FAILED,
SCANNER_STATUS_NO_PAPER,
SCANNER_STATUS_PAPER_ON,
SCANNER_STATUS_STAPLE_ON,
SCANNER_STATUS_SIZE_ERR,
SCANNER_STATUS_DOGEAR,
SCANNER_STATUS_CFG_CHANGED, // PACK_BASE::payload - LPCFGVAL
};
// option affection if value changed, see SANE_INFO_xxx // option affection if value changed, see SANE_INFO_xxx
enum opt_affect enum opt_affect
{ {

View File

@ -17,6 +17,7 @@
#define ALIGN_TO(v, align) (((v) + (align) - 1) / (align) * (align)) #define ALIGN_TO(v, align) (((v) + (align) - 1) / (align) * (align))
#define ALIGN_INT(v) ALIGN_TO(v, sizeof(int)) #define ALIGN_INT(v) ALIGN_TO(v, sizeof(int))
#define CLEAN_ARRAY(a) memset(a, 0, sizeof(a)) #define CLEAN_ARRAY(a) memset(a, 0, sizeof(a))
#define BMP_LINE_BYTES(bits) (((bits) + 31) / 32 * 4)
#define RETURN_ENUM_STR(v, e) \ #define RETURN_ENUM_STR(v, e) \
if(v == e) \ if(v == e) \

167
sdk/base/user.cpp Normal file
View File

@ -0,0 +1,167 @@
#include "user.h"
#include <huagao/hgscanner_error.h>
#include <string.h>
#include <base/ini_file.h>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// json ...
static std::string device_opt_json[] = {
"{\"user-name\":{\"cat\":\"none\",\"group\":\"\\u7528\\u6237\",\"title\":\"\\u7528\\u6237\\u540d\",\"desc\":\"\\u767b\\u5f55\\u7528\\u6237\\u8d26\\u53f7\",\"type\":\"string\",\"fix-id\":39173,\"ui-pos\":10,\"auth\":0,\"size\":32,\"cur\":\"\",\"default\":\"\"},\"user-pwd\":{\"cat\":\"none\",\"group\":\"\\u7528\\u6237\",\"title\":\"\\u5bc6\\u7801\",\"desc\":\"\\u767b\\u5f55\\u7528\\u6237\\u8d26\\u53f7\\u5bc6\\u7801\",\"type\":\"string\",\"fix-id\":39174,\"ui-pos\":11,\"auth\":0,\"size\":32,\"cur\":\"\",\"default\":\"\"},\"login\":{\"cat\":\"none\",\"group\":\"\\u7528\\u6237\",\"title\":\"\\u767b\\u5f55\",\"desc\":\"\\u7528\\u6237\\u767b\\u5f55\",\"type\":\"button\",\"fix-id\":39168,\"ui-pos\":20,\"auth\":0,\"affect\":6,\"size\":4,\"auto\":false},\"logout\":{\"cat\":\"none\",\"group\":\"\\u7528\\u6237\",\"title\":\"\\u6ce8\\u9500\",\"desc\":\"\\u7528\\u6237\\u767b\\u51fa\",\"type\":\"button\",\"fix-id\":39169,\"ui-pos\":21,\"auth\":0,\"affect\":6,\"size\":4,\"auto\":false},\"dev-sn\":{\"cat\":\"base\",\"group\":\"\\u5173\\u4e8e\",\"title\":\"\\u5e8f\\u5217\\u53f7\",\"desc\":\"\\u8bbe\\u5907\\u5e8f\\u5217\\u53f7\",\"type\":\"string\",\"pos\":100,\"fix-id\":34902,\"ui-pos\":14,\"auth\":0,\"size\":32,\"auto\":false,\"cur\":\"\",\"default\":\"\"}}"
};
struct
{
std::string name;
int priv;
}g_user_priv[] = { {"user", USER_PRIVILEGE_COMMON}
, {"admin", USER_PRIVILEGE_LOCAL_MGR}
, {"owner", USER_PRIVILEGE_TECH_SUPPORTING}
, {"developer", USER_PRIVILEGE_DEVLOPER}
};
static std::string base64_table = "!@#$_~=;/+";
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// user_priv
user_priv::user_priv()
{
simple_ini ini;
std::string text("");
cfg_file_ = utils::get_local_data_path() + PATH_SEPARATOR + "config";
utils::create_folder(cfg_file_.c_str());
cfg_file_ += std::string(PATH_SEPARATOR) + "user.txt";
ini.load(cfg_file_.c_str());
for(auto& v: g_user_priv)
login_times_[v.name] = atoi(ini.get(v.name.c_str(), "login", "0").c_str());
set_where("user");
for(auto& v : device_opt_json)
text += v;
set_opt_json_text(&text[0]);
}
user_priv::~user_priv()
{
simple_ini ini;
ini.load(cfg_file_.c_str());
for(auto& v: login_times_)
{
if(v.second)
ini.set(v.first.c_str(), "login", std::to_string(v.second).c_str());
}
ini.save(cfg_file_.c_str());
}
bool user_priv::login(void)
{
bool ok = false;
for(auto& v: g_user_priv)
{
if(v.name == name_)
{
if(name_ == "user")
{
ok = true;
}
else
{
ok = true;
}
break;
}
}
return ok;
}
void user_priv::reset_privilege(void)
{
priv_ = USER_PRIVILEGE_COMMON;
for(auto& v : g_user_priv)
{
if(v.name == name_)
{
priv_ = v.priv;
break;
}
}
}
// sane_opt_provider
int user_priv::set_value(const char* name, void* val)
{
int ret = SCANNER_ERR_OK;
if(strcmp(name, SANE_FULL_NAME(USER_NAME)) == 0)
{
name_ = (char*)val;
priv_ = USER_PRIVILEGE_COMMON;
}
else if(strcmp(name, SANE_FULL_NAME(USER_PASSWORD)) == 0)
{
pwd_ = (char*)val;
priv_ = USER_PRIVILEGE_COMMON;
}
else if(strcmp(name, SANE_FULL_NAME(DEVICE_SERIAL_NO)) == 0)
{
dev_sn_ = (char*)val;
utils::to_log(LOG_LEVEL_DEBUG, "set user device SN: %s\n", dev_sn_.c_str());
priv_ = USER_PRIVILEGE_COMMON;
}
else if(strcmp(name, SANE_FULL_NAME(LOGIN)) == 0)
{
// login ...
if(login_times_.count(name) == 0)
{
ret = SCANNER_ERR_INVALID_USER_NAME;
}
else
{
if(login())
{
simple_ini ini;
ini.load(cfg_file_.c_str());
login_times_[name]++;
reset_privilege();
ini.set(name, "login", std::to_string(login_times_[name]).c_str());
}
else
{
ret = SCANNER_ERR_INVALID_PASSWORD;
}
}
}
else if(strcmp(name, SANE_FULL_NAME(LOGOUT)) == 0)
{
name_ = pwd_ = "";
reset_privilege();
}
else
{
ret = SCANNER_ERR_DEVICE_NOT_SUPPORT;
}
return ret;
}
bool user_priv::has_privilege(int priv)
{
return priv_ >= priv;
}
int user_priv::get_current_user_login_times(void)
{
if(login_times_.count(name_))
return login_times_[name_];
else
return 0;
}

121
sdk/base/user.h Normal file
View File

@ -0,0 +1,121 @@
// user management
//
// Date: 2024-01-04
#pragma once
#include <base/utils.h>
#include <sane/sane_ex.h>
#include <map>
#include <sane_opt_json/base_opt.h>
// name password time-limit
//
// developer calc(dev-sn + login-times) 6min
//
// owner calc(dev-sn + login-times) 30min
//
// admin dev-sn 1hour
//
// user none, default level always
//
class user_priv : public sane_opt_provider
{
std::map<std::string, int> login_times_;
std::string cfg_file_;
std::string dev_sn_ = "01234567AABBCCDDEE";
std::string name_;
std::string pwd_;
int priv_ = USER_PRIVILEGE_COMMON;
bool login(void);
void reset_privilege(void);
public:
user_priv();
protected:
~user_priv();
// sane_opt_provider
public:
virtual int set_value(const char* name, void* val) override;
public:
bool has_privilege(int priv);
int get_current_user_login_times(void);
};
// {
// "user-name": {
// "cat": "none",
// "group": "用户",
// "title": "用户名",
// "desc": "登录用户账号",
// "type": "string",
// "fix-id": 39173,
// "ui-pos": 10,
// "auth": 0,
// "size": 32,
// "cur": "",
// "default": ""
// },
// "user-pwd": {
// "cat": "none",
// "group": "用户",
// "title": "密码",
// "desc": "登录用户账号密码",
// "type": "string",
// "fix-id": 39174,
// "ui-pos": 11,
// "auth": 0,
// "size": 32,
// "cur": "",
// "default": ""
// },
// "login": {
// "cat": "none",
// "group": "用户",
// "title": "登录",
// "desc": "用户登录",
// "type": "button",
// "fix-id": 39168,
// "ui-pos": 20,
// "auth": 0,
// "affect": 6,
// "size": 4,
// "auto": false
// },
// "logout": {
// "cat": "none",
// "group": "用户",
// "title": "注销",
// "desc": "用户登出",
// "type": "button",
// "fix-id": 39169,
// "ui-pos": 21,
// "auth": 0,
// "affect": 6,
// "size": 4,
// "auto": false
// },
// "dev-sn": {
// "cat": "base",
// "group": "关于",
// "title": "序列号",
// "desc": "设备序列号",
// "type": "string",
// "fix-id": 34902,
// "ui-pos": 14,
// "pos": 100,
// "auth": 0,
// "size": 32,
// "auto": false,
// "cur": "",
// "default": ""
// }
// }

View File

@ -605,8 +605,12 @@ namespace utils
ldp = path; ldp = path;
ldp += PATH_SEPARATOR; ldp += PATH_SEPARATOR;
} }
#else
#ifdef BUILD_AS_DEVICE
const char* path = "/var/log";
#else #else
const char* path(getenv("HOME")); const char* path(getenv("HOME"));
#endif
if (path) if (path)
{ {
@ -926,11 +930,11 @@ namespace utils
HMODULE load_dll(const char* path_file, int flag) HMODULE load_dll(const char* path_file, int flag)
{ {
#if OS_WIN #if OS_WIN
HMODULE h = LoadLibraryA(path_file); HMODULE h = NULL; // LoadLibraryA(path_file);
int ret = GetLastError(); int ret = 0; // GetLastError();
utils::to_log(1, "[TWAIN]Load: LoadLibraryA(%s) = %d\r\n", path_file, ret); // utils::to_log(1, "[TWAIN]Load: LoadLibraryA(%s) = %d\r\n", path_file, ret);
if (!h && (ret == ERROR_MOD_NOT_FOUND || ret == ERROR_BAD_EXE_FORMAT)) // if (!h && (ret == ERROR_MOD_NOT_FOUND || ret == ERROR_BAD_EXE_FORMAT))
{ {
std::string dir(path_file); std::string dir(path_file);
size_t pos = dir.rfind('\\'); size_t pos = dir.rfind('\\');
@ -1239,6 +1243,53 @@ namespace utils
return 0; return 0;
} }
std::string bitmap_info_header(int pixel_w, int pixel_h, int bpp, int dpix, int dpiy)
{
BITMAPINFODEADER bih = {0};
std::string stream("");
if(dpiy == 0)
dpiy = dpix;
bih.biSize = sizeof(bih);
bih.biWidth = pixel_w;
bih.biHeight = pixel_h;
bih.biBitCount = bpp;
bih.biSizeImage = BMP_LINE_BYTES(pixel_w * bpp) * pixel_h;
bih.biPlanes = 1;
bih.biCompression = BI_RGB;
bih.biXPelsPerMeter = (LONG)(dpix * 39.37f + .5f);
bih.biYPelsPerMeter = (LONG)(dpiy * 39.37f + .5f);
stream = std::string((char*)&bih, sizeof(bih));
if(bpp == 1)
{
int pal[] = { 0, 0x0ffffff };
stream += std::string((char*)pal, sizeof(pal));
bih.biClrUsed = _countof(pal);
}
else if(bpp == 8)
{
stream += std::string((char*)global_info::gray_pallete, sizeof(global_info::gray_pallete));
bih.biClrUsed = _countof(global_info::gray_pallete);
}
return std::move(stream);
}
std::string bitmap_file_header(BITMAPINFOHEADER *lpbi) // return BITMAPFILEHEADER
{
BITMAPFILEHEADER bfh = {0};
int pal_size = 0;
bfh.bfType = MAKEWORD('B', 'M');
if(lpbi->biBitCount == 1)
pal_size = 2 * sizeof(int);
else if(lpbi->biBitCount == 8)
pal_size = 256 * sizeof(int);
bfh.bfOffBits = sizeof(bfh) + sizeof(BITMAPINFOHEADER) + pal_size;
bfh.bfSize = bfh.bfOffBits + lpbi->biSizeImage;
return std::move(std::string((char*)&bfh, sizeof(bfh)));
}
#if OS_WIN #if OS_WIN
bool run_get_message(HWND hwnd, UINT filter_min, UINT filter_max, std::function<bool(MSG*, bool*)> msghandler) bool run_get_message(HWND hwnd, UINT filter_min, UINT filter_max, std::function<bool(MSG*, bool*)> msghandler)
{ {
@ -1598,6 +1649,32 @@ void chronograph::reset()
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// global_info
uint32_t global_info::page_size = 0;
uint32_t global_info::page_map_size = 0;
uint32_t global_info::cluster_size = 0;
uint32_t global_info::gray_pallete[] = {0};
global_info::global_info()
{
global_info::page_size = utils::get_page_size(&global_info::page_map_size);
std::string path(utils::get_local_data_path());
unsigned long long cluster = 0;
utils::get_disk_space(path.c_str(), nullptr, nullptr, &cluster);
global_info::cluster_size = cluster;
for(int i = 0; i < _countof(global_info::gray_pallete); ++i)
global_info::gray_pallete[i] = MAKELONG(MAKEWORD(i, i), MAKEWORD(i, 0));
printf("Page size: %u\nMap size: %u\nCluster : %u\n", global_info::page_size, global_info::page_map_size, global_info::cluster_size);
}
global_info::~global_info()
{}
static global_info g_si;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -77,6 +77,10 @@ namespace utils
int copy_log_file_to(const char* dst); int copy_log_file_to(const char* dst);
int clear_log_file(void); int clear_log_file(void);
// bitmap header ...
std::string bitmap_info_header(int pixel_w, int pixel_h, int bpp, int dpix, int dpiy = 0); // return BITMPINFOHEADER + pallete if need. dpiy same as dpix if was ZERO
std::string bitmap_file_header(BITMAPINFOHEADER *lpbi); // return BITMAPFILEHEADER
#if OS_WIN #if OS_WIN
// Function: pump message recycle (GetMessageW) // Function: pump message recycle (GetMessageW)
// //
@ -232,6 +236,20 @@ public:
void reset(void); void reset(void);
}; };
// global info
class global_info
{
public:
global_info();
~global_info();
public:
static uint32_t page_size;
static uint32_t page_map_size;
static uint32_t cluster_size;
static uint32_t gray_pallete[256];
};
// event // event
class platform_event : public refer class platform_event : public refer
{ {

View File

@ -43,6 +43,8 @@ enum scanner_err
SCANNER_ERR_RELOAD_IMAGE_PARAM, // 配置成功,会影响图像参数,应用需要重新加载图像参数 - added on 2023-02-18 for XSANE修改影响图像参数的属性后扫描崩溃的问题 SCANNER_ERR_RELOAD_IMAGE_PARAM, // 配置成功,会影响图像参数,应用需要重新加载图像参数 - added on 2023-02-18 for XSANE修改影响图像参数的属性后扫描崩溃的问题
SCANNER_ERR_RELOAD_OPT_PARAM, // SCANNER_ERR_CONFIGURATION_CHANGED + SCANNER_ERR_RELOAD_IMAGE_PARAM - added on 2023-02-18 for XSANE修改影响图像参数的属性后扫描崩溃的问题 SCANNER_ERR_RELOAD_OPT_PARAM, // SCANNER_ERR_CONFIGURATION_CHANGED + SCANNER_ERR_RELOAD_IMAGE_PARAM - added on 2023-02-18 for XSANE修改影响图像参数的属性后扫描崩溃的问题
SCANNER_ERR_THROW_EXCEPTION, // catched exception SCANNER_ERR_THROW_EXCEPTION, // catched exception
SCANNER_ERR_INVALID_USER_NAME,
SCANNER_ERR_INVALID_PASSWORD,
// 2USB错误 // 2USB错误
SCANNER_ERR_USB_INIT_FAILED = 0x5b00, // libusb_init 失败 SCANNER_ERR_USB_INIT_FAILED = 0x5b00, // libusb_init 失败
@ -80,6 +82,15 @@ enum scanner_err
SCANNER_ERR_DEVICE_NOT_READY, // 设备未准备好(执行某操作的前置条件未准备好) SCANNER_ERR_DEVICE_NOT_READY, // 设备未准备好(执行某操作的前置条件未准备好)
SCANNER_ERR_DEVICE_GET_STATUS_FAILED, // 获取电机板状态失败 SCANNER_ERR_DEVICE_GET_STATUS_FAILED, // 获取电机板状态失败
SCANNER_ERR_DEVICE_HD_001, // 设备硬件访问错误
SCANNER_ERR_DEVICE_HD_002, // 设备硬件访问错误
SCANNER_ERR_DEVICE_HD_003, // 设备硬件访问错误
SCANNER_ERR_DEVICE_HD_004, // 设备硬件访问错误
SCANNER_ERR_DEVICE_HD_005, // 设备硬件访问错误
SCANNER_ERR_DEVICE_HD_006, // 设备硬件访问错误
SCANNER_ERR_DEVICE_HD_007, // 设备硬件访问错误
SCANNER_ERR_DEVICE_HD_008, // 设备硬件访问错误
SCANNER_ERR_DEVICE_HD_009, // 设备硬件访问错误
}; };
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -218,6 +218,8 @@ enum opt_visible_level // "visible" field
#define SANE_STD_OPT_NAME_CO_TEL "co-tel" // 公司电话 #define SANE_STD_OPT_NAME_CO_TEL "co-tel" // 公司电话
#define SANE_STD_OPT_NAME_CO_ADDR "co-addr" // 公司地址 #define SANE_STD_OPT_NAME_CO_ADDR "co-addr" // 公司地址
#define SANE_STD_OPT_NAME_CO_GPS "co-gps" // 公司地图定位 #define SANE_STD_OPT_NAME_CO_GPS "co-gps" // 公司地图定位
#define SANE_STD_OPT_NAME_USER_NAME "user-name" // 登录账号
#define SANE_STD_OPT_NAME_USER_PASSWORD "user-pwd" // 登录密码
#define SANE_STD_OPT_NAME_LOGIN "login" // 登录 #define SANE_STD_OPT_NAME_LOGIN "login" // 登录
#define SANE_STD_OPT_NAME_LOGOUT "logout" // 登出 #define SANE_STD_OPT_NAME_LOGOUT "logout" // 登出
#define SANE_STD_OPT_NAME_DRIVER_LOG "drv-log" // 驱动日志 #define SANE_STD_OPT_NAME_DRIVER_LOG "drv-log" // 驱动日志
@ -225,6 +227,7 @@ enum opt_visible_level // "visible" field
#define SANE_STD_OPT_NAME_ROLLER_LIFE "roller-life" // 滚轴最大寿命(过纸张数) #define SANE_STD_OPT_NAME_ROLLER_LIFE "roller-life" // 滚轴最大寿命(过纸张数)
#define SANE_STD_OPT_NAME_LANGUAGE "language" // 语言 #define SANE_STD_OPT_NAME_LANGUAGE "language" // 语言
#define SANE_STD_OPT_NAME_MOTOR_VER "motor-ver" // 电机固件版本, data = char* #define SANE_STD_OPT_NAME_MOTOR_VER "motor-ver" // 电机固件版本, data = char*
#define SANE_STD_OPT_NAME_FPGA_VER "fpga-ver" // CIS控制器FPGA版本, data = char*
#define SANE_STD_OPT_NAME_TRANSFORM_IMAGE_FORMAT "trans-img-fmt" // 图像格式转换, data - SANE_ImageFormatConvert*, dst.data 调用SANE_STD_OPT_NAME_FREE_BUFFER释放 #define SANE_STD_OPT_NAME_TRANSFORM_IMAGE_FORMAT "trans-img-fmt" // 图像格式转换, data - SANE_ImageFormatConvert*, dst.data 调用SANE_STD_OPT_NAME_FREE_BUFFER释放
#define SANE_STD_OPT_NAME_FREE_BUFFER "free-buf" // 释放由驱动返回的内存, data - (void**)&buf #define SANE_STD_OPT_NAME_FREE_BUFFER "free-buf" // 释放由驱动返回的内存, data - (void**)&buf
#define SANE_STD_OPT_NAME_PAPER_ON "paper-on" // check whether paper is on #define SANE_STD_OPT_NAME_PAPER_ON "paper-on" // check whether paper is on
@ -375,6 +378,8 @@ enum sane_option_id
SANE_OPT_ID_ROLLER_COUNT = 0x9902, SANE_OPT_ID_ROLLER_COUNT = 0x9902,
SANE_OPT_ID_DRIVER_LOG = 0x9903, SANE_OPT_ID_DRIVER_LOG = 0x9903,
SANE_OPT_ID_DEVICE_LOG = 0x9904, SANE_OPT_ID_DEVICE_LOG = 0x9904,
SANE_OPT_ID_USER_NAME = 0x9905,
SANE_OPT_ID_USER_PASSWORD = 0x9906,
}; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -1785,6 +1785,20 @@ int device_option::update_data(const char* name, void* value, bool reorder_if_ne
|| (child->get_value("auth", err) && user_ && !user_(err))) || (child->get_value("auth", err) && user_ && !user_(err)))
{ {
err = SCANNER_ERR_ACCESS_DENIED; err = SCANNER_ERR_ACCESS_DENIED;
// following ...
if (src_.count(name))
{
sane_opt_provider* opt = src_[name]->get_following(name);
while(opt)
{
opt->set_value(name, value);
sane_opt_provider* next = opt->get_following(name);
opt->release();
opt = next;
}
}
} }
else else
{ {
@ -1921,7 +1935,8 @@ int device_option::restore(sane_opt_provider* holder)
while (child) while (child)
{ {
if ((!holder || src_.count(child->key()) && src_[child->key()] == holder) if ((!holder || src_.count(child->key()) && src_[child->key()] == holder)
&& is_auto_restore_default(child)) // && is_auto_restore_default(child)
)
{ {
std::string val(device_option::option_value(child, true)); std::string val(device_option::option_value(child, true));
update_data(child->key().c_str(), &val[0], false); update_data(child->key().c_str(), &val[0], false);

View File

@ -96,7 +96,7 @@ async_usb_gadget::async_usb_gadget(std::function<FUNCTION_PROTO_COMMAND_HANDLE>
}; };
threads_.set_exception_handler(excep); threads_.set_exception_handler(excep);
unit_in_ = unit_out_ = sys_info::page_size; // dev_->get_max_packet(); unit_in_ = unit_out_ = global_info::page_size; // dev_->get_max_packet();
// allocate 10MB for IO // allocate 10MB for IO
#ifdef MEM_POOL #ifdef MEM_POOL
@ -852,6 +852,14 @@ int async_usb_gadget::stop(void)
{ {
run_ = false; run_ = false;
if(dev_)
{
dev_->pull_down();
dev_->close_device();
dev_->release();
dev_ = nullptr;
}
#ifdef MEM_POOL #ifdef MEM_POOL
io_buf_->stop(); io_buf_->stop();
#else #else
@ -862,14 +870,6 @@ int async_usb_gadget::stop(void)
cmd_que_.trigger(); cmd_que_.trigger();
sent_que_.trigger(); sent_que_.trigger();
if(dev_)
{
dev_->pull_down();
dev_->close_device();
dev_->release();
dev_ = nullptr;
}
return 0; return 0;
} }
int async_usb_gadget::write_bulk(data_source_ptr data) int async_usb_gadget::write_bulk(data_source_ptr data)

View File

@ -57,10 +57,11 @@ add_packagedirs("sdk")
-- -- set_configvar("MOTOR_UART", "/dev/ttyUSB0") -- -- set_configvar("MOTOR_UART", "/dev/ttyUSB0")
-- set_configvar("VIDEO_CLASS", has_config("isp1") and "GVideoISP1" or "gVideo") -- set_configvar("VIDEO_CLASS", has_config("isp1") and "GVideoISP1" or "gVideo")
add_defines("BUILD_AS_DEVICE")
add_defines("VER_MAIN=2") add_defines("VER_MAIN=2")
add_defines("VER_FAMILY=300") add_defines("VER_FAMILY=300")
add_defines("VER_DATE=20240103") add_defines("VER_DATE=20240105")
add_defines("VER_BUILD=7") add_defines("VER_BUILD=3")
target("conf") target("conf")
set_kind("phony") set_kind("phony")