diff --git a/hgdriver/hgdev/hg_scanner.cpp b/hgdriver/hgdev/hg_scanner.cpp index 624a16f..35eb99b 100644 --- a/hgdriver/hgdev/hg_scanner.cpp +++ b/hgdriver/hgdev/hg_scanner.cpp @@ -3456,6 +3456,11 @@ int hg_scanner::device_io_control(unsigned long code, void* data, unsigned* len) get_scan_islock(&islock); *((SANE_Bool*)data) = islock; } + else if (code == IO_CTRL_CODE_SET_FIRMWARE_UPGRADE) + { + string str = (char*)data; + firmware_upgrade(str); + } return SCANNER_ERR_DEVICE_NOT_SUPPORT; } std::string hg_scanner::get_firmware_version(void) @@ -3506,6 +3511,10 @@ int hg_scanner::set_scan_lock_check_val(string check_str) { return -2; } +int hg_scanner::firmware_upgrade(std::string filename) +{ + return -2; +} ////////////////////////////////////////////////////////////////////////////////////////////////////// int hg_scanner::set_leaflet_scan(void) { diff --git a/hgdriver/hgdev/hg_scanner.h b/hgdriver/hgdev/hg_scanner.h index 1e57743..6cf1d9b 100644 --- a/hgdriver/hgdev/hg_scanner.h +++ b/hgdriver/hgdev/hg_scanner.h @@ -390,6 +390,7 @@ public: virtual int set_scan_islock(SANE_Bool set_islock); virtual int get_scan_islock(SANE_Bool* islock);//获取设备是否锁定 -2:设备不支持该功能;它大于等于0的为正常 virtual int set_scan_lock_check_val(string check_str);//获取设备是否锁定 -2:设备不支持该功能;它大于等于0的为正常 + virtual int firmware_upgrade(std::string filename); //固件升级 -2:设备不支持该功能;它大于等于0的为正常 }; #ifdef UOS diff --git a/hgdriver/hgdev/hg_scanner_239.cpp b/hgdriver/hgdev/hg_scanner_239.cpp index 5c0f38e..71dc960 100644 --- a/hgdriver/hgdev/hg_scanner_239.cpp +++ b/hgdriver/hgdev/hg_scanner_239.cpp @@ -1892,4 +1892,79 @@ int hg_scanner_239::set_scan_lock_check_val(string check_str) return ret; #endif +} + +int hg_scanner_239::firmware_upgrade(std::string filename) +{ + std::ifstream fwname; + int ret = SCANNER_ERR_OK; + + fwname.open(filename, std::ios_base::in | std::ios_base::binary); + if (!fwname.is_open()) + { + return false; + } + fwname.seekg(0, std::ios::end); + int total = fwname.tellg();//记录总长度 + fwname.seekg(0, std::ios::beg); + int pos = fwname.tellg();//记录pos位置 + + ret = write_register(setting3399::SR_UPDATA_START,total); + if (ret != SCANNER_ERR_OK) + { + return ret; + } + int block = total; + while (total > 0) + { + block = 512 * 1024; + + if (total < block) + block = total; + + std::vectordata; + data.resize(block + 1); + fwname.read(data.data(), block); + + io_->write_bulk(data.data(), &block); + if (ret != SCANNER_ERR_OK) + return ret; + + pos += block; + total -= block; + fwname.seekg(pos); + } + this_thread::sleep_for(std::chrono::milliseconds(200)); + + int val = 0; + int ret = read_register(setting3399::SR_UPDATA_STAUTUS, &val); + if (ret != SCANNER_ERR_OK) + return ret; + else if (!val) + return SCANNER_ERR_DEVICE_UPGRADE_FAIL; + + int to_cnt = 0; + //暂时屏蔽 到这个位置已经能够升级成功了 后面对升级结果做下判断 + //while (to_cnt++ > 20) + { + /*int ret = read_register(setting3399::SR_UPDATA_MD5_RELUST, &val); + if (ret != SCANNER_ERR_OK) + { + return ret; + } + if (val == 2) + { + + } + else if(val ==3) + { + + } + else if (true) + { + + } + this_thread::sleep_for(std::chrono::milliseconds(20));*/ + } + return ret; } \ No newline at end of file diff --git a/hgdriver/hgdev/hg_scanner_239.h b/hgdriver/hgdev/hg_scanner_239.h index cbb652d..49f8ab5 100644 --- a/hgdriver/hgdev/hg_scanner_239.h +++ b/hgdriver/hgdev/hg_scanner_239.h @@ -129,5 +129,6 @@ public: virtual int set_scan_islock(SANE_Bool set_islock); virtual int get_scan_islock(SANE_Bool* islock); virtual int set_scan_lock_check_val(string check_str); + virtual int firmware_upgrade(std::string filename); };