adjust log

This commit is contained in:
gb 2023-12-29 10:53:04 +08:00
parent 225efeff9d
commit 90b2550dd6
11 changed files with 248 additions and 125 deletions

View File

@ -110,7 +110,7 @@ bool gVideo::wait(int msTimeout) {
void* gVideo::read_frame(int timeout) { void* gVideo::read_frame(int timeout) {
if (!wait(timeout)){ if (!wait(timeout)){
utils::to_log(LOG_LEVEL_FATAL, "read frame time out"); utils::to_log(LOG_LEVEL_FATAL, "read frame time out\n");
return 0; return 0;
} }
v4l2_buffer buf; v4l2_buffer buf;
@ -141,7 +141,7 @@ void gVideo::stop_capturing(void) {
type = V4L2_BUF_TYPE_VIDEO_CAPTURE; type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
if (-1 == ioctl(fd, VIDIOC_STREAMOFF, &type)) if (-1 == ioctl(fd, VIDIOC_STREAMOFF, &type))
utils::to_log(LOG_LEVEL_FATAL, "streamo off"); utils::to_log(LOG_LEVEL_FATAL, "streamo off\n");
} }
unsigned int querybuf_length; unsigned int querybuf_length;
@ -168,14 +168,14 @@ void gVideo::start_capturing(void)
buf.length = 1; buf.length = 1;
if (-1 == ioctl(fd, VIDIOC_QBUF, &buf)) if (-1 == ioctl(fd, VIDIOC_QBUF, &buf))
LOG_ERROR(utils::format_string("VIDIOC_QBUF Error %d", i)); LOG_ERROR(utils::format_string("VIDIOC_QBUF Error %d\n", i));
else else
LOG_ERROR(utils::format_string("VIDIOC_QBUF %d\n", i)); LOG_ERROR(utils::format_string("VIDIOC_QBUF %d\n", i));
} }
type = V4L2_BUF_TYPE_VIDEO_CAPTURE; type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
if (-1 == ioctl(fd, VIDIOC_STREAMON, &type)) if (-1 == ioctl(fd, VIDIOC_STREAMON, &type))
utils::to_log(LOG_LEVEL_FATAL, "VIDIOC_STREAMON"); utils::to_log(LOG_LEVEL_FATAL, "VIDIOC_STREAMON\n");
} }
void gVideo::uninit_device(void) void gVideo::uninit_device(void)
@ -185,16 +185,16 @@ 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", req.count)); 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;
if (-1 == ioctl(fd, VIDIOC_REQBUFS, &req)) if (-1 == ioctl(fd, VIDIOC_REQBUFS, &req))
{ {
if (EINVAL == errno) if (EINVAL == errno)
utils::to_log(LOG_LEVEL_FATAL, "does not support user pointer i/o"); utils::to_log(LOG_LEVEL_FATAL, "does not support user pointer i/o\n");
else else
utils::to_log(LOG_LEVEL_FATAL, "VIDIOC_REQBUFS"); utils::to_log(LOG_LEVEL_FATAL, "VIDIOC_REQBUFS\n");
} }
for (int i = 0; i < n_buffers; ++i) for (int i = 0; i < n_buffers; ++i)
@ -398,9 +398,9 @@ void printCamInfo(int fd)
while (ioctl(fd, VIDIOC_ENUM_FRAMESIZES, &frmsize) >= 0) while (ioctl(fd, VIDIOC_ENUM_FRAMESIZES, &frmsize) >= 0)
{ {
if(frmsize.type == V4L2_FRMSIZE_TYPE_DISCRETE) if(frmsize.type == V4L2_FRMSIZE_TYPE_DISCRETE)
LOG_TRACE(utils::format_string("line:%d %dx%d", __LINE__, frmsize.discrete.width, frmsize.discrete.height)); LOG_TRACE(utils::format_string("line:%d %dx%d\n", __LINE__, frmsize.discrete.width, frmsize.discrete.height));
else if (frmsize.type == V4L2_FRMSIZE_TYPE_STEPWISE) else if (frmsize.type == V4L2_FRMSIZE_TYPE_STEPWISE)
LOG_TRACE(utils::format_string("line:%d %dx%d", __LINE__, frmsize.discrete.width, frmsize.discrete.height)); LOG_TRACE(utils::format_string("line:%d %dx%d\n", __LINE__, frmsize.discrete.width, frmsize.discrete.height));
frmsize.index++; frmsize.index++;
} }
fmt_1.index++; fmt_1.index++;
@ -413,16 +413,16 @@ void gVideo::init_device(void) {
printCamInfo(fd); printCamInfo(fd);
if (-1 == ioctl(fd, VIDIOC_QUERYCAP, &cap)) { if (-1 == ioctl(fd, VIDIOC_QUERYCAP, &cap)) {
if (EINVAL == errno) if (EINVAL == errno)
LOG_ERROR(utils::format_string("%s is no V4L2 device", dev_name.c_str())); LOG_ERROR(utils::format_string("%s is no V4L2 device\n", dev_name.c_str()));
else else
utils::to_log(LOG_LEVEL_DEBUG, "VIDIOC_QUERYCAP"); utils::to_log(LOG_LEVEL_DEBUG, "VIDIOC_QUERYCAP\n");
} }
if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
LOG_ERROR(utils::format_string("%s is no video capture device", dev_name.c_str())); LOG_ERROR(utils::format_string("%s is no video capture device\n", dev_name.c_str()));
if (!(cap.capabilities & V4L2_CAP_STREAMING)) if (!(cap.capabilities & V4L2_CAP_STREAMING))
LOG_ERROR(utils::format_string("%s does not support streaming i/o", dev_name.c_str())); LOG_ERROR(utils::format_string("%s does not support streaming i/o\n", dev_name.c_str()));
CLEAR(fmt); CLEAR(fmt);
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
@ -433,13 +433,13 @@ void gVideo::init_device(void) {
fmt.fmt.pix.field = V4L2_FIELD_INTERLACED; fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
if (-1 == ioctl(fd, VIDIOC_S_FMT, &fmt)) if (-1 == ioctl(fd, VIDIOC_S_FMT, &fmt))
utils::to_log(LOG_LEVEL_DEBUG, "VIDIOC_S_FMT error"); utils::to_log(LOG_LEVEL_DEBUG, "VIDIOC_S_FMT error\n");
init_mmap(); init_mmap();
} }
void gVideo::close_device(void) { void gVideo::close_device(void) {
if (-1 == ::close(fd)) if (-1 == ::close(fd))
utils::to_log(LOG_LEVEL_DEBUG, "close"); utils::to_log(LOG_LEVEL_DEBUG, "close\n");
fd = -1; fd = -1;
} }
@ -447,5 +447,5 @@ void gVideo::close_device(void) {
void gVideo::open_device(void) void gVideo::open_device(void)
{ {
if((fd = ::open(dev_name.c_str(), O_RDWR /* required */ /*| O_NONBLOCK*/, 0)) == -1) if((fd = ::open(dev_name.c_str(), O_RDWR /* required */ /*| O_NONBLOCK*/, 0)) == -1)
LOG_ERROR(utils::format_string("Cannot open %s", dev_name.c_str())); LOG_ERROR(utils::format_string("Cannot open %s\n", dev_name.c_str()));
} }

View File

@ -157,10 +157,10 @@ void* GVideoISP1::read_frame(int timeout) {
ret = ioctl(fd, VIDIOC_DQBUF, &buf); ret = ioctl(fd, VIDIOC_DQBUF, &buf);
if (ret < 0) { if (ret < 0) {
LOG_TRACE(utils::format_string("Unable to dequeue buffer: %s (%d).",strerror(errno), errno)); LOG_TRACE(utils::format_string("Unable to dequeue buffer: %s (%d).\n",strerror(errno), errno));
} }
else { else {
LOG_TRACE(utils::format_string("VIDIOC_DQBUF sucess")); LOG_TRACE(utils::format_string("VIDIOC_DQBUF sucess\n"));
} }
@ -169,7 +169,7 @@ void* GVideoISP1::read_frame(int timeout) {
LOG_ERROR(utils::format_string("Unable to requeue buffer: %s (%d).\n",strerror(errno), errno)); LOG_ERROR(utils::format_string("Unable to requeue buffer: %s (%d).\n",strerror(errno), errno));
} }
else { else {
LOG_TRACE(utils::format_string("VIDIOC_QBUF sucess")); LOG_TRACE(utils::format_string("VIDIOC_QBUF sucess\n"));
} }
LOG_TRACE(utils::format_string("buf.index = %d,buf.addr = %p\n",buf.index,buffers[buf.index].start)); LOG_TRACE(utils::format_string("buf.index = %d,buf.addr = %p\n",buf.index,buffers[buf.index].start));
return buffers[buf.index].start; return buffers[buf.index].start;
@ -200,18 +200,18 @@ void GVideoISP1::start_capturing(void) {
ret = ioctl(fd, VIDIOC_QBUF, &buf); ret = ioctl(fd, VIDIOC_QBUF, &buf);
if (ret < 0) if (ret < 0)
LOG_ERROR(utils::format_string("Unable to queue buffer: %s (%d).",strerror(errno), errno)); LOG_ERROR(utils::format_string("Unable to queue buffer: %s (%d).\n",strerror(errno), errno));
else else
LOG_TRACE(utils::format_string("buf.index = %d VIDIOC_QBUF sucess.",i)); LOG_TRACE(utils::format_string("buf.index = %d VIDIOC_QBUF sucess.\n",i));
} }
type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
ret = ioctl(fd, VIDIOC_STREAMON, &type); ret = ioctl(fd, VIDIOC_STREAMON, &type);
if (ret < 0) { if (ret < 0) {
LOG_ERROR(utils::format_string("Unable to %s streaming: %s (%d).","start", strerror(errno), errno)); LOG_ERROR(utils::format_string("Unable to %s streaming: %s (%d).\n","start", strerror(errno), errno));
} }
else { else {
LOG_TRACE(utils::format_string("VIDIOC_STREAMON sucess.")); LOG_TRACE(utils::format_string("VIDIOC_STREAMON sucess.\n"));
} }
} }
@ -220,9 +220,9 @@ void GVideoISP1::stop_capturing(void) {
type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
if (-1 == ioctl(fd, VIDIOC_STREAMOFF, &type)) if (-1 == ioctl(fd, VIDIOC_STREAMOFF, &type))
LOG_ERROR(utils::format_string("streamo off")); LOG_ERROR(utils::format_string("streamo off\n"));
LOG_TRACE(utils::format_string("gVideo stop_capturing")); LOG_TRACE(utils::format_string("gVideo stop_capturing\n"));
} }
static void get_ts_flags(uint32_t flags, const char **ts_type, const char **ts_source) static void get_ts_flags(uint32_t flags, const char **ts_type, const char **ts_source)
@ -428,12 +428,13 @@ static const char *v4l2_format_name(unsigned int fourcc)
return name; return name;
} }
static void video_enum_frame_intervals(int fd, __u32 pixelformat, static std::string video_enum_frame_intervals(int fd, __u32 pixelformat,
unsigned int width, unsigned int height) unsigned int width, unsigned int height)
{ {
struct v4l2_frmivalenum ival; struct v4l2_frmivalenum ival;
unsigned int i; unsigned int i;
int ret; int ret;
std::string fsdesc("");
for (i = 0; ; ++i) { for (i = 0; ; ++i) {
memset(&ival, 0, sizeof ival); memset(&ival, 0, sizeof ival);
@ -459,21 +460,23 @@ static void video_enum_frame_intervals(int fd, __u32 pixelformat,
switch (ival.type) { switch (ival.type) {
case V4L2_FRMIVAL_TYPE_DISCRETE: case V4L2_FRMIVAL_TYPE_DISCRETE:
LOG_TRACE(utils::format_string("%u/%u", ival.discrete.numerator, ival.discrete.denominator)); fsdesc = utils::format_string("%u/%u", ival.discrete.numerator, ival.discrete.denominator);
break; return std::move(fsdesc);
case V4L2_FRMIVAL_TYPE_CONTINUOUS: case V4L2_FRMIVAL_TYPE_CONTINUOUS:
LOG_TRACE(utils::format_string("%u/%u - %u/%u", ival.stepwise.min.numerator, ival.stepwise.min.denominator, ival.stepwise.max.numerator, ival.stepwise.max.denominator)); fsdesc = utils::format_string("%u/%u - %u/%u", ival.stepwise.min.numerator, ival.stepwise.min.denominator, ival.stepwise.max.numerator, ival.stepwise.max.denominator);
return; return std::move(fsdesc);
case V4L2_FRMIVAL_TYPE_STEPWISE: case V4L2_FRMIVAL_TYPE_STEPWISE:
LOG_TRACE(utils::format_string("%u/%u - %u/%u (by %u/%u)", ival.stepwise.min.numerator, ival.stepwise.min.denominator, ival.stepwise.max.numerator, ival.stepwise.max.denominator, ival.stepwise.step.numerator, ival.stepwise.step.denominator)); fsdesc = utils::format_string("%u/%u - %u/%u (by %u/%u)", ival.stepwise.min.numerator, ival.stepwise.min.denominator, ival.stepwise.max.numerator, ival.stepwise.max.denominator, ival.stepwise.step.numerator, ival.stepwise.step.denominator);
return; return std::move(fsdesc);
default: default:
break; break;
} }
} }
return std::move(fsdesc);
} }
static void video_enum_frame_sizes(int fd, __u32 pixelformat) static void video_enum_frame_sizes(int fd, __u32 pixelformat)
@ -497,18 +500,18 @@ static void video_enum_frame_sizes(int fd, __u32 pixelformat)
switch (frame.type) { switch (frame.type) {
case V4L2_FRMSIZE_TYPE_DISCRETE: case V4L2_FRMSIZE_TYPE_DISCRETE:
LOG_TRACE(utils::format_string("\tFrame size: %ux%u (", frame.discrete.width, frame.discrete.height)); LOG_TRACE(utils::format_string("\tFrame size: %ux%u (%s)\n", frame.discrete.width, frame.discrete.height,
video_enum_frame_intervals(fd, frame.pixel_format, frame.discrete.width, frame.discrete.height); video_enum_frame_intervals(fd, frame.pixel_format, frame.discrete.width, frame.discrete.height).c_str()));
break; break;
case V4L2_FRMSIZE_TYPE_CONTINUOUS: case V4L2_FRMSIZE_TYPE_CONTINUOUS:
LOG_TRACE(utils::format_string("\tFrame size: %ux%u - %ux%u (", frame.stepwise.min_width, frame.stepwise.min_height, frame.stepwise.max_width, frame.stepwise.max_height)); LOG_TRACE(utils::format_string("\tFrame size: %ux%u - %ux%u (%s)\n", frame.stepwise.min_width, frame.stepwise.min_height, frame.stepwise.max_width, frame.stepwise.max_height,
video_enum_frame_intervals(fd, frame.pixel_format, frame.stepwise.max_width, frame.stepwise.max_height); video_enum_frame_intervals(fd, frame.pixel_format, frame.stepwise.max_width, frame.stepwise.max_height).c_str()));
break; break;
case V4L2_FRMSIZE_TYPE_STEPWISE: case V4L2_FRMSIZE_TYPE_STEPWISE:
LOG_TRACE(utils::format_string("\tFrame size: %ux%u - %ux%u (by %ux%u) (\n", frame.stepwise.min_width, frame.stepwise.min_height, frame.stepwise.max_width, frame.stepwise.max_height, frame.stepwise.step_width, frame.stepwise.step_height)); LOG_TRACE(utils::format_string("\tFrame size: %ux%u - %ux%u (by %ux%u) (%s)\n", frame.stepwise.min_width, frame.stepwise.min_height, frame.stepwise.max_width, frame.stepwise.max_height, frame.stepwise.step_width, frame.stepwise.step_height,
video_enum_frame_intervals(fd, frame.pixel_format, frame.stepwise.max_width, frame.stepwise.max_height); video_enum_frame_intervals(fd, frame.pixel_format, frame.stepwise.max_width, frame.stepwise.max_height).c_str()));
break; break;
default: default:
@ -537,7 +540,7 @@ static void video_enum_formats(int fd, enum v4l2_buf_type type)
if (type != fmt.type) if (type != fmt.type)
LOG_TRACE(utils::format_string("Warning: driver returned wrong format type " "%u.\n", fmt.type)); LOG_TRACE(utils::format_string("Warning: driver returned wrong format type " "%u.\n", fmt.type));
LOG_TRACE(utils::format_string("\tFormat %u: %s (%08x)\n", i, v4l2_format_name(fmt.pixelformat), fmt.pixelformat)); LOG_TRACE(utils::format_string("Format %u: %s (%08x)\n", i, v4l2_format_name(fmt.pixelformat), fmt.pixelformat));
LOG_TRACE(utils::format_string("\tType: %s (%u)\n", v4l2_buf_type_name(fmt.type), fmt.type)); LOG_TRACE(utils::format_string("\tType: %s (%u)\n", v4l2_buf_type_name(fmt.type), fmt.type));
LOG_TRACE(utils::format_string("\tName: %.32s\n", fmt.description)); LOG_TRACE(utils::format_string("\tName: %.32s\n", fmt.description));
video_enum_frame_sizes(fd, fmt.pixelformat); video_enum_frame_sizes(fd, fmt.pixelformat);
@ -880,7 +883,7 @@ void GVideoISP1::init_device(void) {
LOG_TRACE(utils::format_string("Unable to get format: %s (%d).\n", strerror(errno),errno)); LOG_TRACE(utils::format_string("Unable to get format: %s (%d).\n", strerror(errno),errno));
} }
else { else {
utils::to_log(LOG_LEVEL_DEBUG, "VIDIOC_G_FMT sucess."); utils::to_log(LOG_LEVEL_DEBUG, "VIDIOC_G_FMT sucess.\n");
} }
LOG_TRACE(utils::format_string("Video format: %s (%08x) %ux%u field %s, %u planes: \n", v4l2_format_name(fmt.fmt.pix_mp.pixelformat), fmt.fmt.pix_mp.pixelformat, fmt.fmt.pix_mp.width, fmt.fmt.pix_mp.height, v4l2_field_name(fmt.fmt.pix_mp.field), fmt.fmt.pix_mp.num_planes)); LOG_TRACE(utils::format_string("Video format: %s (%08x) %ux%u field %s, %u planes: \n", v4l2_format_name(fmt.fmt.pix_mp.pixelformat), fmt.fmt.pix_mp.pixelformat, fmt.fmt.pix_mp.width, fmt.fmt.pix_mp.height, v4l2_field_name(fmt.fmt.pix_mp.field), fmt.fmt.pix_mp.num_planes));
for (i = 0; i < fmt.fmt.pix_mp.num_planes; i++) for (i = 0; i < fmt.fmt.pix_mp.num_planes; i++)

File diff suppressed because one or more lines are too long

View File

@ -26,7 +26,7 @@ class MotorBoard;
class scanner_hw : public sane_opt_provider class scanner_hw : public sane_opt_provider
{ {
std::function<IMAGE_HANDLER_PROTO> img_handler_; std::function<IMAGE_HANDLER_PROTO> img_handler_ = std::function<IMAGE_HANDLER_PROTO>();
bool scanning_ = false; bool scanning_ = false;
bool auto_scan_ = false; bool auto_scan_ = false;
int time_to_exit_auto_scan_ = 60; // seconds int time_to_exit_auto_scan_ = 60; // seconds
@ -48,6 +48,7 @@ class scanner_hw : public sane_opt_provider
COLOR_IND_COUNT, COLOR_IND_COUNT,
}; };
std::string mode_; std::string mode_;
std::string family_ = "G200";
int dpi_ = 300; int dpi_ = 300;
int baud_ = 921600; int baud_ = 921600;
int delay_ = 1000; int delay_ = 1000;
@ -59,6 +60,7 @@ class scanner_hw : public sane_opt_provider
bool staple_chk_ = true; bool staple_chk_ = true;
bool screw_chk_ = true; bool screw_chk_ = true;
int screw_chk_level_ = 3;
bool paper_on_ = false; bool paper_on_ = false;
bool double_chk_ = true; bool double_chk_ = true;
int motor_speed_ = /*SPEED_PPM_100*/0; int motor_speed_ = /*SPEED_PPM_100*/0;
@ -429,5 +431,24 @@ public:
// "size": 4, // "size": 4,
// "cur": true, // "cur": true,
// "default": true // "default": true
// },
// "askew-range": {
// "cat": "none",
// "group": "feeder",
// "title": "歪斜容忍度",
// "desc": "值越小,能容忍得送入文稿歪斜角度越小",
// "type": "int",
// "fix-id": 34869,
// "ui-pos": 20,
// "auth": 0,
// "size": 4,
// "cur": 3,
// "default": 3,
// "range": {
// "min": 1,
// "max": 7,
// "step": 1
// },
// "depend": "is-check-askew==true"
// } // }
// } // }

View File

@ -57,13 +57,13 @@ void MotorBoard::pick_paper(void)
{ {
unsigned int val; unsigned int val;
SMBCONFIG *smbc = (SMBCONFIG *)(&val); SMBCONFIG *smbc = (SMBCONFIG *)(&val);
read(0x00, val); read(PORT_CONFIG, val);
smbc->pick_paper = 0; smbc->pick_paper = 0;
write(0x00, val); write(PORT_CONFIG, val);
smbc->pick_paper = 1; smbc->pick_paper = 1;
write(0x00, val); write(PORT_CONFIG, val);
// smbc->pick_paper = 0; // smbc->pick_paper = 0;
// write(0x00, val); // write(PORT_CONFIG, val);
} }
void MotorBoard::clear_error() void MotorBoard::clear_error()
@ -100,7 +100,7 @@ bool MotorBoard::wait_done(int timeout_ms)
int MotorBoard::os_mode() int MotorBoard::os_mode()
{ {
unsigned int val; unsigned int val;
read(0x02, val); read(PORT_MODE, val);
SMB_MODE *smb_mode = (SMB_MODE *)&val; SMB_MODE *smb_mode = (SMB_MODE *)&val;
return smb_mode->scan_mode; return smb_mode->scan_mode;
} }
@ -108,7 +108,7 @@ int MotorBoard::os_mode()
bool MotorBoard::paper_ready() bool MotorBoard::paper_ready()
{ {
unsigned int val; unsigned int val;
read(0x02, val); read(PORT_MODE, val);
SMB_MODE *smb_mode = (SMB_MODE *)&val; SMB_MODE *smb_mode = (SMB_MODE *)&val;
return smb_mode->feeding_paper_ready; return smb_mode->feeding_paper_ready;
} }
@ -116,7 +116,7 @@ bool MotorBoard::paper_ready()
bool MotorBoard::is_scanning() bool MotorBoard::is_scanning()
{ {
unsigned int val; unsigned int val;
read(0x02, val); read(PORT_MODE, val);
SMB_MODE *smb_mode = (SMB_MODE *)&val; SMB_MODE *smb_mode = (SMB_MODE *)&val;
return smb_mode->work_status; return smb_mode->work_status;
} }
@ -124,7 +124,7 @@ bool MotorBoard::is_scanning()
int MotorBoard::paper_counter() int MotorBoard::paper_counter()
{ {
unsigned int val; unsigned int val;
read(0x02, val); read(PORT_MODE, val);
SMBMODE *smb_mode = (SMBMODE *)&val; SMBMODE *smb_mode = (SMBMODE *)&val;
return smb_mode->scan_num; return smb_mode->scan_num;
} }
@ -132,11 +132,11 @@ int MotorBoard::paper_counter()
bool MotorBoard::set_paper_inspect_param(unsigned int value /* = 1000 */) bool MotorBoard::set_paper_inspect_param(unsigned int value /* = 1000 */)
{ {
unsigned int val; unsigned int val;
if (!read(0x04, val)) if (!read(PORT_CONFIG_EX, val))
return false; return false;
SMBCONFIGEXT *smb_config_ext = (SMBCONFIGEXT *)&val; SMBCONFIGEXT *smb_config_ext = (SMBCONFIGEXT *)&val;
smb_config_ext->error_range_set = value; smb_config_ext->error_range_set = value;
return write(0x04, val); return write(PORT_CONFIG_EX, val);
} }
bool MotorBoard::get_keeplastpaper(){ bool MotorBoard::get_keeplastpaper(){
@ -146,31 +146,31 @@ bool MotorBoard::get_keeplastpaper(){
bool MotorBoard::set_paper_inpect_info(unsigned int value) bool MotorBoard::set_paper_inpect_info(unsigned int value)
{ {
unsigned int val; unsigned int val;
if (!read(0x04, val)) if (!read(PORT_CONFIG_EX, val))
return false; return false;
SMBCONFIGEXT *smb_config_ext = (SMBCONFIGEXT *)&val; SMBCONFIGEXT *smb_config_ext = (SMBCONFIGEXT *)&val;
smb_config_ext->paper_infor = value; smb_config_ext->paper_infor = value;
return write(0x04, val); return write(PORT_CONFIG_EX, val);
} }
bool MotorBoard::set_paper_inspect(bool enable /* = true */) bool MotorBoard::set_paper_inspect(bool enable /* = true */)
{ {
unsigned int val; unsigned int val;
if (!read(0x04, val)) if (!read(PORT_CONFIG_EX, val))
return false; return false;
SMBCONFIGEXT *smb_config_ext = (SMBCONFIGEXT *)&val; SMBCONFIGEXT *smb_config_ext = (SMBCONFIGEXT *)&val;
smb_config_ext->paper_size_check_en = enable; smb_config_ext->paper_size_check_en = enable;
return write(0x04, val); return write(PORT_CONFIG_EX, val);
} }
bool MotorBoard::set_double_inpect(bool enable) bool MotorBoard::set_double_inpect(bool enable)
{ {
unsigned int val; unsigned int val;
if (!read(0x00, val)) if (!read(PORT_CONFIG, val))
return false; return false;
SMBCONFIG *smb_config = (SMBCONFIG *)&val; SMBCONFIG *smb_config = (SMBCONFIG *)&val;
smb_config->double_paper = enable; smb_config->double_paper = enable;
return write(0x00, val); return write(PORT_CONFIG, val);
} }
bool MotorBoard::get_doublle_inpect() bool MotorBoard::get_doublle_inpect()
{ {
@ -178,21 +178,21 @@ bool MotorBoard::get_doublle_inpect()
bool MotorBoard::set_auto_paper(bool enable){ bool MotorBoard::set_auto_paper(bool enable){
unsigned int val; unsigned int val;
if (!read(0x00, val)) if (!read(PORT_CONFIG, val))
return false; return false;
SMBCONFIG *smb_config = (SMBCONFIG *)&val; SMBCONFIG *smb_config = (SMBCONFIG *)&val;
smb_config->paper_auto_module = enable; smb_config->paper_auto_module = enable;
return write(0x00, val); return write(PORT_CONFIG, val);
} }
bool MotorBoard::set_staple_inpect(bool enable) bool MotorBoard::set_staple_inpect(bool enable)
{ {
unsigned int val; unsigned int val;
if (!read(0x00, val)) if (!read(PORT_CONFIG, val))
return false; return false;
SMBCONFIG *smb_config = (SMBCONFIG *)&val; SMBCONFIG *smb_config = (SMBCONFIG *)&val;
smb_config->staple_enable = enable; smb_config->staple_enable = enable;
return write(0x00, val); return write(PORT_CONFIG, val);
} }
bool MotorBoard::get_staple_inpect() bool MotorBoard::get_staple_inpect()
@ -201,11 +201,11 @@ bool MotorBoard::get_staple_inpect()
bool MotorBoard::set_color_mode(int mode) bool MotorBoard::set_color_mode(int mode)
{ {
unsigned int val; unsigned int val;
if (!read(0x00, val)) if (!read(PORT_CONFIG, val))
return false; return false;
SMBCONFIG *smb_config = (SMBCONFIG *)&val; SMBCONFIG *smb_config = (SMBCONFIG *)&val;
smb_config->color_mode = mode; smb_config->color_mode = mode;
return write(0x00, val); return write(PORT_CONFIG, val);
} }
int MotorBoard::get_color_mode() int MotorBoard::get_color_mode()
{ {
@ -214,21 +214,21 @@ int MotorBoard::get_color_mode()
bool MotorBoard::set_speed_mode(int mode) bool MotorBoard::set_speed_mode(int mode)
{ {
unsigned int val; unsigned int val;
if (!read(0x00, val)) if (!read(PORT_CONFIG, val))
return false; return false;
SMBCONFIG *smb_config = (SMBCONFIG *)&val; SMBCONFIG *smb_config = (SMBCONFIG *)&val;
smb_config->speed_set_enable = 1; smb_config->speed_set_enable = 1;
smb_config->v_setting = mode; smb_config->v_setting = mode;
write(0x00, val); write(PORT_CONFIG, val);
smb_config->speed_set_enable = 0; smb_config->speed_set_enable = 0;
return write(0x00, val); return write(PORT_CONFIG, val);
} }
int MotorBoard::get_speed_mode() int MotorBoard::get_speed_mode()
{ {
unsigned int val; unsigned int val;
if (!read(0x00, val)) if (!read(PORT_CONFIG, val))
return -1; return -1;
SMBCONFIG *smb_config = (SMBCONFIG *)&val; SMBCONFIG *smb_config = (SMBCONFIG *)&val;
return smb_config->v_setting; return smb_config->v_setting;
@ -237,11 +237,11 @@ int MotorBoard::get_speed_mode()
bool MotorBoard::set_cuospeed(unsigned int speed) bool MotorBoard::set_cuospeed(unsigned int speed)
{ {
unsigned int val; unsigned int val;
if (!read(0x04, val)) if (!read(PORT_CONFIG_EX, val))
return -1; return -1;
SMB_CONFIG_EXT *smb_config = (SMB_CONFIG_EXT *)&val; SMB_CONFIG_EXT *smb_config = (SMB_CONFIG_EXT *)&val;
smb_config->cuo_speed = speed; smb_config->cuo_speed = speed;
return write(0x04,val); return write(PORT_CONFIG_EX,val);
} }
@ -272,7 +272,7 @@ void MotorBoard::pin_call(unsigned int pinNum)
unsigned int val; unsigned int val;
SMBSTATUS *smb_status = (SMBSTATUS *)&val; SMBSTATUS *smb_status = (SMBSTATUS *)&val;
if (!read(0x01, val)) if (!read(PORT_STATUS, val))
utils::to_log(LOG_LEVEL_DEBUG, "read error"); 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, utils::format_string("status %08x", val).c_str());
//printf("\n reg 1 val =%d",val); //printf("\n reg 1 val =%d",val);
@ -355,16 +355,16 @@ void MotorBoard::set_callbacks(MotorBoardGlue glue)
bool MotorBoard::set_screw_inpect(bool enable) bool MotorBoard::set_screw_inpect(bool enable)
{ {
unsigned int val; unsigned int val;
if (!read(0x00, val)) if (!read(PORT_CONFIG, val))
return false; return false;
SMBCONFIG *smb_config = (SMBCONFIG *)&val; SMBCONFIG *smb_config = (SMBCONFIG *)&val;
smb_config->skew_enable = enable; smb_config->skew_enable = enable;
return write(0x00, val); return write(PORT_CONFIG, val);
} }
bool MotorBoard::get_screw_inpect() bool MotorBoard::get_screw_inpect()
{ {
unsigned int val; unsigned int val;
read(0x00, val); read(PORT_CONFIG, val);
SMBCONFIG *smb_mode = (SMBCONFIG *)&val; SMBCONFIG *smb_mode = (SMBCONFIG *)&val;
return smb_mode->skew_enable; return smb_mode->skew_enable;
} }
@ -372,27 +372,27 @@ bool MotorBoard::get_screw_inpect()
bool MotorBoard::set_screw_level(int level) bool MotorBoard::set_screw_level(int level)
{ {
unsigned int val; unsigned int val;
if (!read(0x00, val)) if (!read(PORT_CONFIG, val))
return false; return false;
SMBCONFIG *smb_config = (SMBCONFIG *)&val; SMBCONFIG *smb_config = (SMBCONFIG *)&val;
smb_config->skew_parameter = level; smb_config->skew_parameter = level;
return write(0x00, val); return write(PORT_CONFIG, val);
} }
bool MotorBoard::set_long_paper(bool enable) bool MotorBoard::set_long_paper(bool enable)
{ {
unsigned int val; unsigned int val;
if (!read(0x00, val)) if (!read(PORT_CONFIG, val))
return false; return false;
SMBCONFIG *smb_config = (SMBCONFIG *)&val; SMBCONFIG *smb_config = (SMBCONFIG *)&val;
smb_config->paper = enable; smb_config->paper = enable;
return write(0x00, val); return write(PORT_CONFIG, val);
} }
int MotorBoard::get_screw_level() int MotorBoard::get_screw_level()
{ {
unsigned int val; unsigned int val;
auto ret= read(0x00, val); auto ret= read(PORT_CONFIG, val);
if(!ret) if(!ret)
return -1; return -1;
SMBCONFIG *smb_mode = (SMBCONFIG *)&val; SMBCONFIG *smb_mode = (SMBCONFIG *)&val;
@ -402,12 +402,12 @@ int MotorBoard::get_screw_level()
bool MotorBoard::en_testbit(bool en) bool MotorBoard::en_testbit(bool en)
{ {
unsigned int val; unsigned int val;
auto ret= read(0x00, val); auto ret= read(PORT_CONFIG, val);
if(!ret) if(!ret)
return -1; return -1;
SMBCONFIG *smb_mode = (SMBCONFIG *)&val; SMBCONFIG *smb_mode = (SMBCONFIG *)&val;
smb_mode->testbit = en?1:0; smb_mode->testbit = en?1:0;
return write(0x00,val); return write(PORT_CONFIG,val);
} }
void MotorBoard::release_statecontrol() void MotorBoard::release_statecontrol()

View File

@ -102,10 +102,18 @@ struct MotorBoardGlue
enum enum
{ {
SPEED_PPM_100 = 0, PORT_CONFIG = 0,
SPEED_PPM_70, PORT_STATUS,
SPEED_PPM_120, PORT_MODE,
SPEED_PPM_150 PORT_VERSION,
PORT_CONFIG_EX = 4,
};
enum
{
SPEED_PPM_BASE = 0,
SPEED_PPM_BASE_10,
SPEED_PPM_BASE_20,
SPEED_PPM_BASE_30,
}; };
class MotorBoard class MotorBoard
@ -151,6 +159,8 @@ public:
std::shared_ptr<IRegsAccess> regs(); std::shared_ptr<IRegsAccess> regs();
void release_statecontrol(); void release_statecontrol();
void init_statecontrol(); void init_statecontrol();
private: private:
void pin_call(unsigned int pinNum); void pin_call(unsigned int pinNum);
void scansensor_call(unsigned int pinNum); void scansensor_call(unsigned int pinNum);

View File

@ -62,6 +62,7 @@ async_scanner::async_scanner() : usb_(nullptr), cfg_mgr_(nullptr), scan_id_(0)
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();
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]);
cfg_mgr_->add(cis_); cfg_mgr_->add(cis_);
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());
@ -412,9 +413,16 @@ dyn_mem_ptr async_scanner::handle_scan_start(LPPACK_BASE pack, uint32_t* used, p
scan_err_ = 0; scan_err_ = 0;
reply_start_ = false; reply_start_ = false;
auto receiver = [this](dyn_mem_ptr, bool, LPPACKIMAGE) -> void
{
};
*used = base_head_size; *used = base_head_size;
reply->set_len(base_head_size); reply->set_len(base_head_size);
// scan_err_ = capture_->start(); scan_err_ = cis_->open(receiver);
if(scan_err_ == 0)
scan_err_ = cis_->start_scan();
BASE_PACKET_REPLY(*((LPPACK_BASE)reply->ptr()), pack->cmd + 1, pack->pack_id, scan_err_); BASE_PACKET_REPLY(*((LPPACK_BASE)reply->ptr()), pack->cmd + 1, pack->pack_id, scan_err_);
*used |= INT32_MAX + 1; *used |= INT32_MAX + 1;
@ -427,7 +435,7 @@ dyn_mem_ptr async_scanner::handle_scan_stop(LPPACK_BASE pack, uint32_t* used, pa
int err = 0; int err = 0;
utils::to_log(LOG_LEVEL_DEBUG, "Received command Stop-Scan.\n"); utils::to_log(LOG_LEVEL_DEBUG, "Received command Stop-Scan.\n");
// err = capture_->stop(); err = cis_->stop_scan();
BASE_PACKET_REPLY(*((LPPACK_BASE)reply->ptr()), pack->cmd + 1, pack->pack_id, err); BASE_PACKET_REPLY(*((LPPACK_BASE)reply->ptr()), pack->cmd + 1, pack->pack_id, err);
reply->set_len(base_head_size); reply->set_len(base_head_size);
*used = base_head_size; *used = base_head_size;

View File

@ -1958,6 +1958,7 @@ int shared_memory::write(const char* data, size_t len)
// safe_thread // safe_thread
safe_thread::safe_thread() : excep_que_("thread-exception") safe_thread::safe_thread() : excep_que_("thread-exception")
{ {
excep_que_.enable_wait_log(false);
notify_thread_.reset(new std::thread(&safe_thread::thread_notify_exception, this)); notify_thread_.reset(new std::thread(&safe_thread::thread_notify_exception, this));
} }
safe_thread::~safe_thread() safe_thread::~safe_thread()
@ -1980,7 +1981,7 @@ void safe_thread::thread_worker(std::function<void(void)> func, std::string name
{ {
try try
{ {
utils::to_log(LOG_LEVEL_DEBUG, "+++ safe_thread of '%s(%p) - %p' is running ...\n", name.c_str(), addr, GetCurrentThreadId()); utils::to_log(LOG_LEVEL_DEBUG, "+++ safe_thread of '%s(addr: %p) - id: %p' is running ...\n", name.c_str(), addr, GetCurrentThreadId());
func(); func();
utils::to_log(LOG_LEVEL_DEBUG, "--- safe_thread of '%s - %p' exited.\n", name.c_str(), GetCurrentThreadId()); utils::to_log(LOG_LEVEL_DEBUG, "--- safe_thread of '%s - %p' exited.\n", name.c_str(), GetCurrentThreadId());
return; return;

View File

@ -1198,24 +1198,24 @@ void device_option::insert_option(gb_json* opt, sane_opt_provider* from, const c
from->add_ref(); from->add_ref();
} }
if (added) //if (added) // error occurs when condition default value, move to after to_now ...
{ //{
// restore to default value ... // // restore to default value ...
int size = 0; // int size = 0;
bool can_auto = false; // bool can_auto = false;
std::string val(get_option_value(opt->key().c_str(), SANE_ACTION_GET_DEFAULT_VALUE, &size)); // std::string val(get_option_value(opt->key().c_str(), SANE_ACTION_GET_DEFAULT_VALUE, &size));
//
if (!opt->get_value("auto", can_auto) || can_auto) // if (!opt->get_value("auto", can_auto) || can_auto)
{ // {
std::string type(""); // std::string type("");
opt->get_value("type", type); // opt->get_value("type", type);
val.resize(size); // val.resize(size);
type = sane_opt_provider::sane_value_2_text(type.c_str(), &val[0]); // type = sane_opt_provider::sane_value_2_text(type.c_str(), &val[0]);
utils::to_log(LOG_LEVEL_ALL, "Set option '%s' to default value: '%s'\n", opt->key().c_str(), type.c_str()); // utils::to_log(LOG_LEVEL_ALL, "Set option '%s' to default value: '%s'\n", opt->key().c_str(), type.c_str());
from->set_value(opt->key().c_str(), &val[0]); // from->set_value(opt->key().c_str(), &val[0]);
sane_opt_provider::set_opt_value(opt, &val[0]); // sane_opt_provider::set_opt_value(opt, &val[0]);
} // }
} //}
} }
bool device_option::arrange_raw_json(sane_opt_provider* sop) bool device_option::arrange_raw_json(sane_opt_provider* sop)
{ {
@ -1703,7 +1703,9 @@ bool device_option::add(sane_opt_provider* sop)
if (arrange_raw_json(sop)) if (arrange_raw_json(sop))
{ {
ret = to_now(true, nullptr); ret = to_now(true, nullptr);
if (!ret) if (ret)
restore(nullptr);
else
clear(); clear();
} }
else else
@ -1909,7 +1911,7 @@ int device_option::restore(sane_opt_provider* holder)
child = cur->first_child(); child = cur->first_child();
while (child) while (child)
{ {
if (src_.count(child->key()) && src_[child->key()] == holder if ((!holder || src_.count(child->key()) && src_[child->key()] == holder)
&& is_auto_restore_default(child->key().c_str())) && is_auto_restore_default(child->key().c_str()))
{ {
std::string val(device_option::option_value(child, true)); std::string val(device_option::option_value(child, true));

View File

@ -555,7 +555,7 @@ int usb_device::open_device(const char* dev, bool ffs_mode, int* fd)
} }
else else
{ {
utils::to_log(LOG_LEVEL_DEBUG, "Open usb device(%s) success.\n", dev); utils::to_log(LOG_LEVEL_DEBUG, "Open usb device(%s) success, fd = %d.\n", dev, gadget_.usb_device);
ffs_mode_ = ffs_mode; ffs_mode_ = ffs_mode;
// get_system_output(R"(echo linaro | sudo -S sh -c "chmod 777 /dev/ffs-camtp -R")"); // get_system_output(R"(echo linaro | sudo -S sh -c "chmod 777 /dev/ffs-camtp -R")");
@ -608,7 +608,7 @@ int usb_device::open_endpoint(int ep_ind, int* fd)
} }
else else
{ {
utils::to_log(LOG_LEVEL_DEBUG, "open endpoint(%s - %s) ok.\n", usb_device::endpoint_index_str(ep_ind).c_str(), gadget_.ep_path[ep_ind]); utils::to_log(LOG_LEVEL_DEBUG, "open endpoint(%s - %s) ok, fd = %d.\n", usb_device::endpoint_index_str(ep_ind).c_str(), gadget_.ep_path[ep_ind], gadget_.ep_handles[ep_ind]);
} }
} }
} }
@ -639,6 +639,7 @@ int usb_device::close_endpoint(int ep_ind)
utils::to_log(LOG_LEVEL_FATAL, "close endpoint(%s) failed: %d(%s)\n", usb_device::endpoint_index_str(i).c_str(), errno, strerror(errno)); utils::to_log(LOG_LEVEL_FATAL, "close endpoint(%s) failed: %d(%s)\n", usb_device::endpoint_index_str(i).c_str(), errno, strerror(errno));
break; break;
} }
utils::to_log(LOG_LEVEL_DEBUG, "close endpoint(%s, fd = %d) ok.\n", usb_device::endpoint_index_str(i).c_str(), gadget_.ep_handles[i]);
gadget_.ep_handles[i] = -1; gadget_.ep_handles[i] = -1;
} }
} }
@ -653,8 +654,8 @@ int usb_device::close_endpoint(int ep_ind)
utils::to_log(LOG_LEVEL_FATAL, "close endpoint(%s) failed: %d(%s)\n", usb_device::endpoint_index_str(ep_ind).c_str(), errno, strerror(errno)); utils::to_log(LOG_LEVEL_FATAL, "close endpoint(%s) failed: %d(%s)\n", usb_device::endpoint_index_str(ep_ind).c_str(), errno, strerror(errno));
else else
{ {
utils::to_log(LOG_LEVEL_DEBUG, "close endpoint(%s, fd = %d) ok.\n", usb_device::endpoint_index_str(ep_ind).c_str(), gadget_.ep_handles[ep_ind]);
gadget_.ep_handles[ep_ind] = -1; gadget_.ep_handles[ep_ind] = -1;
utils::to_log(LOG_LEVEL_DEBUG, "close endpoint(%s) ok.\n", usb_device::endpoint_index_str(ep_ind).c_str());
} }
} }
} }
@ -679,10 +680,13 @@ int usb_device::close_device(void)
{ {
ret = close(gadget_.usb_device); ret = close(gadget_.usb_device);
if(ret == 0) if(ret == 0)
{
utils::to_log(LOG_LEVEL_DEBUG, "Close usb device(fd = %d) ok.\n", gadget_.usb_device);
gadget_.usb_device = -1; gadget_.usb_device = -1;
} }
} }
} }
}
return ret; return ret;
} }

View File

@ -28,6 +28,8 @@ async_usb_gadget::async_usb_gadget(std::function<FUNCTION_PROTO_COMMAND_HANDLE>
{ {
cmd_que_.enable_wait_log(false); cmd_que_.enable_wait_log(false);
sent_que_.enable_wait_log(false); sent_que_.enable_wait_log(false);
wait_in_.enable_log(false);
wait_out_.enable_log(false);
dev_ = new usb_device("fe900000.dwc3", "/opt/cfg/usb_gadget/g1/UDC", "linaro"); dev_ = new usb_device("fe900000.dwc3", "/opt/cfg/usb_gadget/g1/UDC", "linaro");
dev_->add_endpoint(USB_EP_BULK_IN, true, true); dev_->add_endpoint(USB_EP_BULK_IN, true, true);