@ -74,38 +74,32 @@ namespace settingsdsp_300
return code ;
return code ;
}
}
}
}
hg_scanner_300 : : hg_scanner_300 ( const char * dev_name , int pid , usb_io * io ) : hg_scanner ( G100Serial , dev_name , io , pid ) , papersize ( pid )
hg_scanner_300 : : hg_scanner_300 ( const char * dev_name , int pid , usb_io * io ) : hg_scanner ( G100Serial , dev_name , io , pid ) , papersize ( pid ) , is_devs_sleep_ ( false )
{
{
initdevice ( ) ;
# ifndef MAPPING_FUNCTION_IN_BASE
# ifndef MAPPING_FUNCTION_IN_BASE
init_setting_map ( setting_map_ , ARRAY_SIZE ( setting_map_ ) ) ; //优先初始化
init_setting_map ( setting_map_ , ARRAY_SIZE ( setting_map_ ) ) ; //优先初始化
# endif
# endif
initdevice ( ) ;
if ( init_settings ( pid_ ) )
if ( init_settings ( pid_ ) )
{
{
if ( pid_ = = 0x300 )
if ( pid_ = = 0x300 )
{
init_settings ( ( jsontext1 + jsontext2 ) . c_str ( ) ) ;
init_settings ( ( jsontext1 + jsontext2 ) . c_str ( ) ) ;
string fw = get_firmware_version ( ) ;
if ( fw . size ( ) > 5 )
{
if ( atoi ( fw . substr ( 4 , 6 ) . c_str ( ) ) > = 221106 & & atoi ( fw . substr ( 4 , 6 ) . c_str ( ) ) < 230210 )
is_kernelsnap3288_221106_ = true ;
else if ( atoi ( fw . substr ( 4 , 6 ) . c_str ( ) ) > = 230210 )
is_kernelsnap3288_230210_ = true ;
else
{
is_kernelsnap3288_221106_ = false ;
is_kernelsnap3288_230210_ = false ;
}
}
}
else
else
init_settings ( ( jsontext3 + jsontext4 ) . c_str ( ) ) ;
init_settings ( ( jsontext3 + jsontext4 ) . c_str ( ) ) ;
}
}
//printf_devconfig();
int val = 0 ;
int ret = get_scan_is_sleep ( val ) ;
if ( ! val & & ret = = SCANNER_ERR_OK )
{
is_devs_sleep_ = status_ = SCANNER_ERR_DEVICE_SLEEPING ;
VLOG_MINI_1 ( LOG_LEVEL_WARNING , " init device start status is(%s) \n " , hg_log : : lang_load ( ID_STATU_DESC_SCANNER_ERR_DEVICE_SLEEPING ) ) ;
}
if ( pid_ = = 0x400 | | is_devs_sleep_ )
return ;
//目前300才做处理
set_kernelsnap_ver ( ) ;
is_devs_sleep_ = false ;
}
}
hg_scanner_300 : : ~ hg_scanner_300 ( )
hg_scanner_300 : : ~ hg_scanner_300 ( )
{ }
{ }
@ -128,8 +122,8 @@ void hg_scanner_300::thread_handle_usb_read(void)
USBCB usb = { 0 } ;
USBCB usb = { 0 } ;
ret = get_scanner_status ( usb ) ;
ret = get_scanner_status ( usb ) ;
//printf("usb.u32_Data = %d ret = %d\r\n",usb.u32_Data,ret);
//printf("usb.u32_Data = %d ret = %d\r\n",usb.u32_Data,ret);
// // 如果设备出现卡纸 或者双张等设备信息问题, 需要等到设备进行发送stop才能停止。 所以始终以 "停止" 消息为结束信号
// 如果设备出现卡纸 或者双张等设备信息问题, 需要等到设备进行发送stop才能停止。 所以始终以 "停止" 消息为结束信号
// // 如果有图的情况下,并且卡纸或双张等,设备会先发送卡纸双张信息。所以接受到错误信息之后,仍需要把图像取出来。
// 如果有图的情况下,并且卡纸或双张等,设备会先发送卡纸双张信息。所以接受到错误信息之后,仍需要把图像取出来。
if ( ret = = SCANNER_ERR_DEVICE_STOPPED )
if ( ret = = SCANNER_ERR_DEVICE_STOPPED )
{
{
status_ = ! savestatus_ . empty ( ) ? savestatus_ [ 0 ] : SCANNER_ERR_OK ; //以第一个消息为准
status_ = ! savestatus_ . empty ( ) ? savestatus_ [ 0 ] : SCANNER_ERR_OK ; //以第一个消息为准
@ -214,19 +208,25 @@ void hg_scanner_300::thread_handle_usb_read(void)
}
}
else
else
{
{
//3288固件 获取有纸无纸问题的bug, 如果是打开盖子在start之前【主动】获取的话, 会先报无纸, 而不是开盖。
if ( ! savestatus_ . empty ( ) ) //以第一个消息为准
//但是在【端点】又获取不到有纸还是无纸的状态,所以只能通过等待超时,再来【主动】获取有无纸张。
{
status_ = ! savestatus_ . empty ( ) ? savestatus_ [ 0 ] : SCANNER_ERR_TIMEOUT ; //以第一个消息为准
status_ = savestatus_ [ 0 ] ;
}
savestatus_ . clear ( ) ;
savestatus_ . clear ( ) ;
hg_log : : log ( LOG_LEVEL_WARNING , " get status timeout,get image out 30S \n " ) ;
hg_log : : log ( LOG_LEVEL_WARNING , " Get Status TimeOut,get image out 30S \n " ) ;
notify_ui_working_status ( hg_log : : lang_load ( ID_STATU_DESC_SCANNER_ERR_DEVICE_GET_IMAGE_OUTTIME ) , SANE_EVENT_ERROR , status_ ) ; // 取图通信超时
break ;
break ;
}
}
}
}
if ( sw . elapsed_ms ( ) > 60000 )
if ( sw . elapsed_ms ( ) > 60000 )
{
{
status_ = ! savestatus_ . empty ( ) ? savestatus_ [ 0 ] : SCANNER_ERR_TIMEOUT ; //以第一个消息为准
if ( ! savestatus_ . empty ( ) ) //以第一个消息为准
{
status_ = savestatus_ [ 0 ] ;
}
savestatus_ . clear ( ) ;
savestatus_ . clear ( ) ;
hg_log : : log ( LOG_LEVEL_WARNING , " MaxSize OutTime 60S \n " ) ;
hg_log : : log ( LOG_LEVEL_WARNING , " MaxSize TimeOut,Get Image 60S \n " ) ;
notify_ui_working_status ( hg_log : : lang_load ( ID_STATU_DESC_SCANNER_ERR_DEVICE_GET_IMAGE_OUTTIME ) , SANE_EVENT_ERROR , status_ ) ; // 取图通信超时
break ;
break ;
}
}
if ( ret = = SCANNER_ERR_OK & & usb . u32_Count > 0 )
if ( ret = = SCANNER_ERR_OK & & usb . u32_Count > 0 )
@ -281,14 +281,6 @@ int hg_scanner_300::start(void)
if ( handled )
if ( handled )
return ret ;
return ret ;
ret = writedown_device_configuration ( true ) ;
if ( ret = = SCANNER_ERR_OK )
writedown_image_configuration ( ) ;
else
{
status_ = ret ;
return ret ;
}
ret = get_scan_is_sleep ( val ) ;
ret = get_scan_is_sleep ( val ) ;
if ( ! val & & ret = = SCANNER_ERR_OK )
if ( ! val & & ret = = SCANNER_ERR_OK )
{
{
@ -310,6 +302,23 @@ int hg_scanner_300::start(void)
{
{
return ret ;
return ret ;
}
}
if ( is_devs_sleep_ ) //设备在睡眠的状态当中获取固件是失败的,所以在这个地方进行标志位设置。(总感觉不保险)
{
is_devs_sleep_ = false ;
set_kernelsnap_ver ( ) ;
int paper = image_prc_param_ . bits . paper ;
on_paper_changed ( paper ) ;
int dpi = resolution_ ;
on_resolution_changed ( dpi ) ;
}
ret = writedown_device_configuration ( true ) ;
if ( ret = = SCANNER_ERR_OK )
writedown_image_configuration ( ) ;
else
{
status_ = ret ;
return ret ;
}
//printf_devconfig();
//printf_devconfig();
USBCB usb = { setting3288dsp : : START_COMMAND , img_conf_ . scannum , 0 } ;
USBCB usb = { setting3288dsp : : START_COMMAND , img_conf_ . scannum , 0 } ;
ret = writeusb ( usb ) ;
ret = writeusb ( usb ) ;
@ -392,15 +401,18 @@ int hg_scanner_300::get_scanner_status(USBCB &usb)
int ret = SCANNER_ERR_OK ;
int ret = SCANNER_ERR_OK ;
usb = { setting3288dsp : : GET_DSP_STATUS , 0 , 0 } ;
usb = { setting3288dsp : : GET_DSP_STATUS , 0 , 0 } ;
io_ - > set_timeout ( 2000 ) ;
ret = writeusb ( usb ) ;
ret = writeusb ( usb ) ;
if ( ret ! = SCANNER_ERR_OK )
if ( ret ! = SCANNER_ERR_OK )
{
VLOG_MINI_1 ( LOG_LEVEL_WARNING , " get_scanner_status write usb: %s \n " , hg_scanner_err_name ( ret ) ) ;
return ret ;
return ret ;
}
ret = readusb ( usb ) ;
ret = readusb ( usb ) ;
if ( ret ! = SCANNER_ERR_OK )
if ( ret ! = SCANNER_ERR_OK )
{
{
VLOG_MINI_1 ( LOG_LEVEL_WARNING , " get_scanner_status read usb: %s \n " , hg_scanner_err_name ( ret ) ) ;
status_ = ret ;
status_ = ret ;
return ret ;
return ret ;
}
}
@ -418,6 +430,7 @@ int hg_scanner_300::get_img_data(std::shared_ptr<tiny_buffer> &imagedata)
ret = writeusb ( usb ) ;
ret = writeusb ( usb ) ;
if ( ret ! = SCANNER_ERR_OK )
if ( ret ! = SCANNER_ERR_OK )
{
{
VLOG_MINI_1 ( LOG_LEVEL_WARNING , " get_img_data setting3288dsp::GET_IMAGE write usb: %s \n " , hg_scanner_err_name ( ret ) ) ;
status_ = ret ;
status_ = ret ;
return ret ;
return ret ;
}
}
@ -445,6 +458,7 @@ int hg_scanner_300::get_img_data(std::shared_ptr<tiny_buffer> &imagedata)
if ( ret ! = SCANNER_ERR_OK )
if ( ret ! = SCANNER_ERR_OK )
{
{
VLOG_MINI_1 ( LOG_LEVEL_WARNING , " get_img_data read_bulk : %s \n " , hg_scanner_err_name ( ret ) ) ;
status_ = ret ;
status_ = ret ;
return ret ;
return ret ;
}
}
@ -488,8 +502,9 @@ int hg_scanner_300::writedown_device_configuration(bool type,setting_hardware::H
//d->params_3288.pageSize = setting3288dsp::G400_MAXSIZE;
//d->params_3288.pageSize = setting3288dsp::G400_MAXSIZE;
}
}
if ( is_quality_ = = IMG_SPEED & & resolution_ > = 300 )
if ( ( is_quality_ = = IMG_SPEED ) & & ( resolution_ > = 300 ) )
{
{
VLOG_MINI_1 ( LOG_LEVEL_WARNING , " writedown_device_configuration is_quality_ is .(%d) \n " , is_quality_ )
d - > params_3288 . dpi = 1 ;
d - > params_3288 . dpi = 1 ;
}
}
if ( image_prc_param_ . bits . paper = = PAPER_AUTO_MATCH
if ( image_prc_param_ . bits . paper = = PAPER_AUTO_MATCH
@ -587,7 +602,7 @@ int hg_scanner_300::on_resolution_changed(int& dpi)
else
else
dsp_config . params_3288 . dpi = 1 ;
dsp_config . params_3288 . dpi = 1 ;
VLOG_MINI_3 ( LOG_LEVEL_WARNING , " on_resolution_changed is dpi:%d .set device dpi(%d),is_kernelsnap3288_221106_ is :%d \n " , dpi , dsp_config . params_3288 . dpi , is_kernelsnap3288_221106_ ) ;
ret = writedown_device_configuration ( ) ;
ret = writedown_device_configuration ( ) ;
return ret ;
return ret ;
@ -609,6 +624,30 @@ int hg_scanner_300::on_ultrasonic_check_changed(bool& check)
return ret ;
return ret ;
}
}
int hg_scanner_300 : : set_kernelsnap_ver ( )
{
int ret = SCANNER_ERR_OK ;
string fw = get_firmware_version ( ) ;
if ( ! fw . empty ( ) )
{
if ( atoi ( fw . substr ( 4 , 6 ) . c_str ( ) ) > = 221106 & & atoi ( fw . substr ( 4 , 6 ) . c_str ( ) ) < 230210 )
is_kernelsnap3288_221106_ = true ;
else if ( atoi ( fw . substr ( 4 , 6 ) . c_str ( ) ) > = 230210 )
is_kernelsnap3288_230210_ = true ;
else
{
is_kernelsnap3288_221106_ = false ;
is_kernelsnap3288_230210_ = false ;
}
}
else
{
ret = SCANNER_ERR_NO_DATA ;
}
VLOG_MINI_2 ( LOG_LEVEL_WARNING , " hg_scanner_300 is_kernelsnap3288_221106_ :%d ,is_kernelsnap3288_230210_:%d \n " , is_kernelsnap3288_221106_ , is_kernelsnap3288_230210_ ) ;
return SCANNER_ERR_OK ;
}
int hg_scanner_300 : : agreement ( TwSS tw , int align )
int hg_scanner_300 : : agreement ( TwSS tw , int align )
{
{
int ret = SCANNER_ERR_OK ;
int ret = SCANNER_ERR_OK ;
@ -629,7 +668,6 @@ int hg_scanner_300::initdevice()
dsp_config . params_3288 . enableSizeDetect = 0 ;
dsp_config . params_3288 . enableSizeDetect = 0 ;
//writedown_device_configuration(true);
//writedown_device_configuration(true);
//printf_devconfig();
//printf_devconfig();
return SCANNER_ERR_OK ;
return SCANNER_ERR_OK ;
}
}
void hg_scanner_300 : : writedown_image_configuration ( void )
void hg_scanner_300 : : writedown_image_configuration ( void )
@ -689,7 +727,10 @@ std::string hg_scanner_300::get_firmware_version()
USBCB cmd = { setting3288dsp : : GET_FW_VERSION , len , 0 , } ;
USBCB cmd = { setting3288dsp : : GET_FW_VERSION , len , 0 , } ;
ret = writeusb ( cmd ) ;
ret = writeusb ( cmd ) ;
std : : lock_guard < std : : mutex > lock ( io_lock_ ) ;
ret = io_ - > read_bulk ( buf , & len ) ;
ret = io_ - > read_bulk ( buf , & len ) ;
string fw = buf ;
VLOG_MINI_1 ( LOG_LEVEL_WARNING , " get_firmware_version:%s \n " , ! fw . empty ( ) ? fw . c_str ( ) : " not find devs firmware_version " ) ;
return buf ;
return buf ;
}
}
@ -705,11 +746,8 @@ std::string hg_scanner_300::get_firmware_version()
std : : lock_guard < std : : mutex > lock ( io_lock_ ) ;
std : : lock_guard < std : : mutex > lock ( io_lock_ ) ;
ret = io_ - > read_bulk ( & SerialNum [ 0 ] , & len ) ;
ret = io_ - > read_bulk ( & SerialNum [ 0 ] , & len ) ;
if ( ret ! = SCANNER_ERR_OK )
{
return " 0000000000000000000 " ;
}
VLOG_MINI_1 ( LOG_LEVEL_WARNING , " get_serial_num:%s \n " , ! SerialNum . empty ( ) ? SerialNum . c_str ( ) : " not find devs get_serial_num " ) ;
return SerialNum ;
return SerialNum ;
}
}
std : : string hg_scanner_300 : : get_ip ( void )
std : : string hg_scanner_300 : : get_ip ( void )
@ -748,11 +786,11 @@ int hg_scanner_300::get_sleep_time(int &data)
}
}
len = sizeof ( usbcb ) ;
len = sizeof ( usbcb ) ;
ret = io_ - > read_bulk ( & usbcb , & len ) ;
ret = io_ - > read_bulk ( & usbcb , & len ) ;
printf ( " usbcb.u32_Data = %d \r \n " , usbcb . u32_Data ) ;
if ( ret = = SCANNER_ERR_OK )
if ( ret = = SCANNER_ERR_OK )
{
{
data = ( SANE_Power ) usbcb . u32_Data ;
data = ( SANE_Power ) usbcb . u32_Data ;
}
}
VLOG_MINI_1 ( LOG_LEVEL_WARNING , " get_serial_num:%d \n " , data ) ;
return ret ;
return ret ;
}
}
int hg_scanner_300 : : set_sleep_time ( int data )
int hg_scanner_300 : : set_sleep_time ( int data )
@ -782,7 +820,7 @@ int hg_scanner_300::get_scanner_paperon(SANE_Bool& type)
// ret = SCANNER_ERR_DEVICE_NO_PAPER;
// ret = SCANNER_ERR_DEVICE_NO_PAPER;
//else
//else
// ret = SCANNER_ERR_OK;
// ret = SCANNER_ERR_OK;
VLOG_MINI_1 ( LOG_LEVEL_WARNING , " get_scanner_paperon is(%s) \n " , hg_scanner_err_name ( ret ) ) ;
VLOG_MINI_1 ( LOG_LEVEL_WARNING , " get_scanner_paperon is(%s) \n " , ! type ? hg_scanner_err_name ( SCANNER_ERR_DEVICE_NO_PAPER ) : hg_scanner_err_name ( SCANNER_ERR_OK ) ) ;
return ret ;
return ret ;
}
}
@ -810,7 +848,7 @@ int hg_scanner_300::get_scan_is_sleep(SANE_Bool& type)
type = false ;
type = false ;
//return SCANNER_ERR_DEVICE_SLEEPING;
//return SCANNER_ERR_DEVICE_SLEEPING;
}
}
VLOG_MINI_1 ( LOG_LEVEL_WARNING , " get_scan_is_sleep is(%s) \n " , hg_scanner_err_name ( ret ) ) ;
VLOG_MINI_1 ( LOG_LEVEL_WARNING , " get_scan_is_sleep is(%s) \n " , ! type ? hg_scanner_err_name ( SCANNER_ERR_DEVICE_SLEEPING ) : hg_scanner_err_name ( SCANNER_ERR_OK ) ) ;
return ret ;
return ret ;
}
}
///此款设备无此功能
///此款设备无此功能
@ -930,32 +968,34 @@ int hg_scanner_300::set_distortion_check_val(int data)
{
{
int ret = SCANNER_ERR_OK ,
int ret = SCANNER_ERR_OK ,
len = 0 ;
len = 0 ;
USBCB usbcb = { setting3288dsp : : SET_JUST_COF_V , data , resolution_ } ;
len = sizeof ( usbcb ) ;
io_ - > write_bulk ( & usbcb , & len ) ;
//USBCB cmd = { setting3288dsp::GET_JUST_COF_H ,0,resolution_ };
int protocol_dpi = resolution_ = = 200 ? 1 : ( resolution_ = = 300 ? 2 : 3 ) ;
//len = sizeof(cmd);
USBCB usbcb = { setting3288dsp : : SET_JUST_COF_V , data , protocol_dpi } ;
//io_->write_bulk(&cmd, &len);
len = sizeof ( usbcb ) ;
//io_->read_bulk(&cmd, &len);
float f = * ( float * ) & ( data ) ;
//int ratio = cmd.u32_Data;
VLOG_MINI_3 ( LOG_LEVEL_WARNING , " set_distortion_check_val dpi is:%d,config dpi = %d,distortion_check_val(%f) \n " , resolution_ , protocol_dpi , f ) ;
io_ - > set_timeout ( 5000 ) ;
ret = io_ - > write_bulk ( & usbcb , & len ) ;
return ret ;
return ret ;
}
}
int hg_scanner_300 : : get_devs_distortion_check_val ( int & data )
int hg_scanner_300 : : get_devs_distortion_check_val ( int & data )
{
{
int ret = SCANNER_ERR_OK ,
int ret = SCANNER_ERR_OK ,
len = 0 ;
len = 0 ;
USBCB usbcb = { setting3288dsp : : GET_JUST_COF_V , 0 , resolution_ } ;
int protocol_dpi = resolution_ = = 200 ? 1 : ( resolution_ = = 300 ? 2 : 3 ) ;
USBCB usbcb = { setting3288dsp : : GET_JUST_COF_V , 0 , protocol_dpi } ;
len = sizeof ( usbcb ) ;
len = sizeof ( usbcb ) ;
ret = io_ - > write_bulk ( & usbcb , & len ) ;
ret = io_ - > write_bulk ( & usbcb , & len ) ;
if ( ret = = SCANNER_ERR_OK )
if ( ret = = SCANNER_ERR_OK )
{
{
std : : this_thread : : sleep_for ( std : : chrono : : milliseconds ( 1000 ) ) ;
io_ - > set_timeout ( 3000 ) ;
io_ - > set_timeout ( 3000 ) ;
ret = io_ - > read_bulk ( & usbcb , & len ) ;
ret = io_ - > read_bulk ( & usbcb , & len ) ;
data = usbcb . u32_Data ;
data = usbcb . u32_Data ;
}
}
float f = * ( float * ) & data ;
VLOG_MINI_3 ( LOG_LEVEL_WARNING , " get_distortion_check_val dpi is:%d,protocol_dpi = %d get_distortion_check_val(%f) \n " , resolution_ , protocol_dpi , f ) ;
return ret ;
return ret ;
}
}
int hg_scanner_300 : : set_auto_flat ( void )
int hg_scanner_300 : : set_auto_flat ( void )
@ -991,7 +1031,6 @@ int hg_scanner_300::set_serial_num(string str)
ret = io_ - > write_bulk ( & str , & len ) ;
ret = io_ - > write_bulk ( & str , & len ) ;
}
}
return ret ;
return ret ;
}
}
int hg_scanner_300 : : set_vid_pid ( int data )
int hg_scanner_300 : : set_vid_pid ( int data )
{
{