code_production/code/base/test_base.cpp

1300 lines
38 KiB
C++
Raw Normal View History

2022-12-30 01:28:56 +00:00
#include"test_base.h"
2022-12-08 10:10:19 +00:00
#include<string>
#include <stdio.h>
#include <windows.h>
#include <map>
#include <iostream>
2022-12-14 06:58:06 +00:00
#include "huagao/hgscanner_error.h"
2022-12-31 09:02:23 +00:00
#include "sane/sane_option_definitions.h";
static struct Test_Map
{
const wchar_t* name; // DIAL_SWITCH
const wchar_t* title; // 歪斜检测
}Test_Map_NO[] =
{
{HGPDTTOOLDB_NAME_DIAL_SWITCH ,HGPDTTOOLDB_TITLE_DIAL_SWITCH},
{HGPDTTOOLDB_NAME_ROCKER_SWITCH ,HGPDTTOOLDB_TITLE_ROCKER_SWITCH},
{HGPDTTOOLDB_NAME_BOOT_STATUS ,HGPDTTOOLDB_TITLE_BOOT_STATUS},
{HGPDTTOOLDB_NAME_LCD_DISPLAY ,HGPDTTOOLDB_TITLE_LCD_DISPLAY},
{HGPDTTOOLDB_NAME_KEY_FUNCTION ,HGPDTTOOLDB_TITLE_KEY_FUNCTION},
{HGPDTTOOLDB_NAME_COUNTING_MODE ,HGPDTTOOLDB_TITLE_COUNTING_MODE},
{HGPDTTOOLDB_NAME_CIS_ORIGINAL_IMAGE ,HGPDTTOOLDB_TITLE_CIS_ORIGINAL_IMAGE},
{HGPDTTOOLDB_NAME_HOST_FAN ,HGPDTTOOLDB_TITLE_HOST_FAN},
{HGPDTTOOLDB_NAME_LED_LIGHT ,HGPDTTOOLDB_TITLE_LED_LIGHT},
{HGPDTTOOLDB_NAME_RESET ,HGPDTTOOLDB_TITLE_RESET},
{HGPDTTOOLDB_NAME_PAPER_FEED ,HGPDTTOOLDB_TITLE_PAPER_FEED},
{HGPDTTOOLDB_NAME_SCANNING_SENSOR ,HGPDTTOOLDB_TITLE_SCANNING_SENSOR},
{HGPDTTOOLDB_NAME_PLACE_CORRECTION_PAPER ,HGPDTTOOLDB_TITLE_PLACE_CORRECTION_PAPER},
{HGPDTTOOLDB_NAME_AUTO_FLAT_FIELD ,HGPDTTOOLDB_TITLE_AUTO_FLAT_FIELD},
2023-02-08 07:25:54 +00:00
{HGPDTTOOLDB_NAME_IMAGE_COLOR_QUALITY ,HGPDTTOOLDB_TITLE_IMAGE_QUALITY},
2022-12-31 09:02:23 +00:00
{HGPDTTOOLDB_NAME_COLORCARD_IMAGEING_QUALITY ,HGPDTTOOLDB_TITLE_COLORCARD_IMAGEING_QUALITY},
{HGPDTTOOLDB_NAME_COLORCARD_BIAS_IMAGEING_QUALITY ,HGPDTTOOLDB_TITLE_COLORCARD_BIAS_IMAGEING_QUALITY},
{HGPDTTOOLDB_NAME_CLARITY_QUALITY ,HGPDTTOOLDB_TITLE_CLARITY_QUALITY},
2023-01-05 09:46:52 +00:00
{HGPDTTOOLDB_NAME_GET_DISTORTION_VAL ,HGPDTTOOLDB_TITLE_DISTORTION},
2022-12-31 09:02:23 +00:00
{HGPDTTOOLDB_NAME_SEPARATER_MOTOR ,HGPDTTOOLDB_TITLE_SEPARATER_MOTOR},
{HGPDTTOOLDB_NAME_CLEAR_PAPER_PATH ,HGPDTTOOLDB_TITLE_CLEAR_PAPER_PATH},
{HGPDTTOOLDB_NAME_SKEW_DETECTION ,HGPDTTOOLDB_TITLE_SKEW_DETECTION},
{HGPDTTOOLDB_NAME_ULTRASONIC_MODULE ,HGPDTTOOLDB_TITLE_ULTRASONIC_MODULE},
{HGPDTTOOLDB_NAME_COVER_SENSOR ,HGPDTTOOLDB_TITLE_COVER_SENSOR },
{HGPDTTOOLDB_NAME_REBOOT_DEVICE ,HGPDTTOOLDB_TITLE_REBOOT_DEVICE},
{HGPDTTOOLDB_NAME_MECH_PAPER_FEEDING_INCLINATION ,HGPDTTOOLDB_TITLE_MECH_PAPER_FEEDING_INCLINATION},
{HGPDTTOOLDB_NAME_CLEAR_ROLLER_COUNT ,HGPDTTOOLDB_TITLE_CLEAR_ROLLER_COUNT},
{HGPDTTOOLDB_NAME_CLEAR_ROLLER_COUNT ,HGPDTTOOLDB_TITLE_CLEAR_ROLLER_COUNT},
{HGPDTTOOLDB_NAME_PAPER_SEPARATION_STRENGTH ,HGPDTTOOLDB_TITLE_PAPER_SEPARATION_STRENGTH},
{HGPDTTOOLDB_NAME_CONFIGURE_SPEED_MODE ,HGPDTTOOLDB_TITLE_CONFIGURE_SPEED_MODE},
{HGPDTTOOLDB_NAME_DORMANCY ,HGPDTTOOLDB_TITLE_DORMANCY},
};
2022-12-15 11:53:41 +00:00
2022-12-29 16:07:01 +00:00
static std::string StringToUtf(std::string strValue)
{
int nwLen = MultiByteToWideChar(CP_UTF8, 0, strValue.c_str(), -1, NULL, 0);
2022-12-30 01:28:56 +00:00
wchar_t* pwBuf = new wchar_t[nwLen + 1];//加上末尾'\0'
2022-12-29 16:07:01 +00:00
memset(pwBuf, 0, nwLen * 2 + 2);
MultiByteToWideChar(CP_UTF8, 0, strValue.c_str(), strValue.length(), pwBuf, nwLen);
int nLen = WideCharToMultiByte(CP_ACP, 0, pwBuf, -1, NULL, NULL, NULL, NULL);
char* pBuf = new char[nLen + 1];
memset(pBuf, 0, nLen + 1);
WideCharToMultiByte(CP_ACP, 0, pwBuf, nwLen, pBuf, nLen, NULL, NULL);
std::string retStr = pBuf;
delete[]pBuf;
delete[]pwBuf;
return retStr;
}
2022-12-26 09:18:25 +00:00
static int str_to_wchar(std::string str, wchar_t* s, size_t* strlen)
{
if (str.empty())
return ERROR_INSUFFICIENT_BUFFER;
size_t size = str.length();
int len = 0;
len = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, NULL, 0);
if (*strlen < len)
{
*strlen = len;
return ERROR_INSUFFICIENT_BUFFER;
}
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, s, len);
return 0;
}
2023-01-04 09:25:14 +00:00
static int wchar_to_char(std::string &str, wchar_t* s, size_t* strlen)
{
if (!s)
return ERROR_INSUFFICIENT_BUFFER;
int len = WideCharToMultiByte(CP_ACP, 0, s, -1, NULL, 0, NULL, NULL);
if (*strlen < len)
{
*strlen = len;
return ERROR_INSUFFICIENT_BUFFER;
}
WideCharToMultiByte(CP_ACP, 0, s, -1, (char *)str.c_str(), len, NULL, NULL);
return 0;
}
2022-12-26 09:18:25 +00:00
int get_json_config_file()
{
int len = 0;
char exePath[256];
char* buf = NULL;
GetModuleFileNameA(NULL, exePath, 255);
2022-12-30 01:28:56 +00:00
(strrchr(exePath, '\\'))[1] = 0; //去掉执行的文件名。
2022-12-26 09:18:25 +00:00
strcat(exePath, "DLLs\\G302.hsc");
FILE* fp = fopen(exePath, "rb");
if (fp == NULL)
{
return -1;
}
fseek(fp, 0, SEEK_END);
len = ftell(fp);
fseek(fp, 0, SEEK_SET);
buf = new char[len];
if (!buf)
{
fclose(fp);
return -1;
}
memset(buf, 0, len);
fread(buf, len, 1, fp);
fclose(fp);
std::cout << buf << std::endl;
}
2022-12-28 02:21:16 +00:00
static std::wstring set_test_name_ =L"";
2023-03-01 09:34:07 +00:00
//bool is_distortion_get_image = false;
//bool is_distortion_get_image_abnormal = false;
std::atomic<bool> is_distortion_get_image_abnormal(false);
std::atomic<bool> is_distortion_get_image(false);
2022-12-15 11:53:41 +00:00
class test
2022-12-08 10:10:19 +00:00
{
2022-12-15 11:53:41 +00:00
ui_helper* helper_;
2022-12-28 09:14:23 +00:00
int fw_;
2023-01-05 09:46:52 +00:00
2023-01-03 03:12:53 +00:00
/*设置vid pid*/
int test_set_vidpid(void* data)
{
unsigned int len = sizeof(int);
int set_vidpid = *((int*)data),
get_vidpid = 0,
ret = SCANNER_ERR_OK;
2023-01-04 07:59:12 +00:00
ret = helper_->io_control(IO_CTRL_CODE_SET_VIDPID, &set_vidpid, &len);
2023-01-03 03:12:53 +00:00
if (ret == SCANNER_ERR_OK)
{
2023-01-04 07:59:12 +00:00
ret = helper_->io_control(IO_CTRL_CODE_GET_VIDPID, &get_vidpid, &len);
2023-01-03 03:12:53 +00:00
if (set_vidpid == get_vidpid)
2023-01-04 09:25:14 +00:00
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_MANUAL_CONFIRMATION, (void*)L"设置vidpid成功", true);
2023-01-03 03:12:53 +00:00
else
2023-01-04 09:25:14 +00:00
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_MANUAL_CONFIRMATION, (void*)L"设置vidpid失败", false);
2023-01-03 03:12:53 +00:00
}
return ret;
}
/*设置序列号*/
int test_set_serial_num(void* data)
{
2023-01-04 06:56:45 +00:00
wchar_t* sn = (wchar_t*)data;
2023-01-04 09:25:14 +00:00
std::string set_sn,
2023-01-03 03:12:53 +00:00
get_sn;
2023-01-04 06:56:45 +00:00
int ret = SCANNER_ERR_OK;
size_t len = 0;
2023-01-04 09:25:14 +00:00
ret = wchar_to_char(set_sn, sn, &len);
2023-01-04 06:56:45 +00:00
if (ret == ERROR_INSUFFICIENT_BUFFER)
{
2023-01-04 09:25:14 +00:00
set_sn.resize(len);
ret = wchar_to_char(set_sn, sn, &len);
2023-01-04 06:56:45 +00:00
}
2023-01-03 03:12:53 +00:00
unsigned int setlen = set_sn.size(),
getlen = 0;
2023-01-04 10:12:16 +00:00
ret = helper_->io_control(IO_CTRL_CODE_SET_SERIAL, &set_sn[0], &setlen);
2023-01-03 03:12:53 +00:00
if (ret != SCANNER_ERR_OK)return ret;
2023-01-04 09:25:14 +00:00
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_MANUAL_CONFIRMATION, (void*)L"设置序列号完成", true);
2023-01-03 03:12:53 +00:00
return ret;
}
/* 设置休眠 */
int test_dormancy(void* data)
{
const wchar_t sleep_buf[8] = { 0,5,10,30,60,120,240 };
int sleep_time = *((int*)data);
SANE_Power power;
unsigned int len = sizeof(SANE_Power);
for (size_t i = 0; i < 8; i++)
{
if (sleep_buf[i] == sleep_time)
{
power = (SANE_Power)i;
}
}
int ret = helper_->io_control(IO_CTRL_CODE_SET_POWER_LEVEL, &power, &len);
if (ret != SCANNER_ERR_OK)
{
return ret;
}
int gettime = 0;
unsigned int timelen = sizeof(int*);
ret = helper_->io_control(IO_CTRL_CODE_GET_POWER_LEVEL, &gettime, &timelen);
if (gettime == INT_MAX || gettime == -1)
gettime = 0;
else
gettime /= 60;
if (sleep_time == gettime)
2023-01-04 09:25:14 +00:00
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_MANUAL_CONFIRMATION, (void*)L"设置休眠时间成功", true);
2023-01-03 03:12:53 +00:00
else
2023-01-04 09:25:14 +00:00
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_MANUAL_CONFIRMATION, (void*)L"设置休眠时间失败", false);
2023-01-03 03:12:53 +00:00
return ret;
}
/*获取固件版本号*/
std::string get_firmware_version()
{
std::string fw = "";
unsigned int len = 0;
int ret = helper_->io_control(IO_CTRL_CODE_GET_HARDWARE_VERSION, &fw[0], &len);
fw.resize(len);
ret = helper_->io_control(IO_CTRL_CODE_GET_HARDWARE_VERSION, &fw[0], &len);
return fw;
}
/* 配置速度模式 */
int test_configure_speed_mode(void* data)
{
unsigned int len = sizeof(int);
int speed_mode = *((int*)data);
bool type = false;
const wchar_t G139[6] = { 70,80,90,110 };
const wchar_t G239[6] = { 100,110,120,130 };
const wchar_t G300[6] = { 40,50,60,70 };
const wchar_t G400[6] = { 40,50,60,70,80 };
if (fw_ == 3 || fw_ == 4 && speed_mode >= 40 && speed_mode <= 80)
{
for (size_t i = 0; i < sizeof(G400) / sizeof(G400[0]); i++)//3288设置速度模式为1 2 3 4 5
{
if (G400[i] == speed_mode)
{
speed_mode = i + 1;
break;
}
}
}
int ret = helper_->io_control(IO_CTRL_CODE_SET_SPEED_MODE, &speed_mode, &len);
if (ret != SCANNER_ERR_OK)
{
return ret;
}
SANE_Int num = 0;
unsigned int l = sizeof(SANE_Int);
ret = helper_->io_control(IO_CTRL_CODE_GET_SPEED_MODE, &num, &l);
int save_num = 0;
if (fw_ == 3 || fw_ == 4 && num > 0 && num < 6)
{
for (size_t i = 0; i < sizeof(G400) / sizeof(G400[0]); i++)//3288设置速度模式为1 2 3 4 5
{
if ((num - 1) == i)
{
save_num = G400[i];
break;
}
}
}
else
save_num = num;
wchar_t* infocat = NULL;
wchar_t c[6];
if (num != speed_mode)
{
wchar_t buf[30] = L"设置速度模式失败...现在速度是:";
type = false;
wsprintfW(c, L"%dppm", save_num);
wcscat(buf, c);
infocat = buf;
}
else
{
wchar_t buf[30] = L"设置速度模式成功...现在速度是:";
type = true;
wsprintfW(c, L"%dppm", save_num);
wcscat(buf, c);
infocat = buf;
}
2023-01-04 09:25:14 +00:00
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_MANUAL_CONFIRMATION, (void*)infocat, type);
2023-01-03 03:12:53 +00:00
return SCANNER_ERR_OK;
}
2022-12-15 11:53:41 +00:00
public:
2022-12-26 09:18:25 +00:00
static int sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned int* len, void* param)
{
if (!hdev && !param)
{
return -1;
}
ui_helper* h= (ui_helper*)param;
2022-12-28 02:21:16 +00:00
std::wstring wstr = L"";
size_t l = 0;
bool type = true;
2022-12-31 09:02:23 +00:00
wchar_t buf[128] =L"";
2023-01-06 07:34:35 +00:00
int ret = SCANNER_ERR_OK;
if (code != SANE_EVENT_IMAGE_OK)
2022-12-26 09:18:25 +00:00
{
2023-01-06 07:34:35 +00:00
ret = str_to_wchar((char*)data, (wchar_t*)wstr.c_str(), &l);
if (ret == ERROR_INSUFFICIENT_BUFFER)
{
wstr.resize(l);
ret = str_to_wchar((char*)data, (wchar_t*)wstr.c_str(), &l);
}
if (ret == ERROR_INSUFFICIENT_BUFFER)
{
type = false;
h->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void*)wstr.c_str(), type);
return -1;
}
2022-12-26 09:18:25 +00:00
}
2023-01-06 07:34:35 +00:00
2022-12-29 16:07:01 +00:00
//std::string str = StringToUtf((char*)data);
2022-12-28 02:21:16 +00:00
switch (code)
{
2022-12-26 09:18:25 +00:00
case SANE_EVENT_SCAN_FINISHED:
{
2022-12-31 09:02:23 +00:00
SANE_Bool close = false;
unsigned int closelen = sizeof(SANE_Bool);
2022-12-28 02:21:16 +00:00
2022-12-27 08:26:41 +00:00
if (wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_SKEW_DETECTION) == 0)
2022-12-26 09:18:25 +00:00
{
2022-12-29 10:07:00 +00:00
if (strcmp((char*)data, STATU_DESC_SCANNER_ERR_DEVICE_PAPER_SKEW) != 0)
{
type = false;
2022-12-31 09:02:23 +00:00
wcscpy(buf, L"未检测到纸张倾斜, 原因--->");
2022-12-29 10:07:00 +00:00
}
2022-12-28 02:21:16 +00:00
}
2022-12-29 10:30:29 +00:00
else if(wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_ULTRASONIC_MODULE) == 0)
{
if (strcmp((char*)data, STATU_DESC_SCANNER_ERR_DEVICE_DOUBLE_FEEDING) != 0)
{
type = false;
2022-12-31 09:02:23 +00:00
wcscpy(buf, L"未检测到双张, 原因--->");
2022-12-29 10:30:29 +00:00
}
}
else if (wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_COVER_SENSOR) == 0)
{
if (strcmp((char*)data, STATU_DESC_SCANNER_ERR_DEVICE_COVER_OPENNED) != 0)
{
2022-12-31 09:02:23 +00:00
type = false;;
wcscpy(buf, L"未检测到设备开盖, 原因--->");
}
}
2022-12-30 10:15:49 +00:00
else if (wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_PAPER_FEED) == 0)
{
if (strcmp((char*)data, STATU_DESC_SCAN_STOPPED) != 0)
{
type = false;
2022-12-31 09:02:23 +00:00
wcscpy(buf, L"走纸检测失败, 原因--->");
2022-12-30 10:15:49 +00:00
}
}
else if(wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_AUTO_FLAT_FIELD) == 0)
{
if (strcmp((char*)data, STATU_DESC_SCANNER_ERR_DEVICE_AUTO_FAIL_OVER) != 0)
{
type = false;
2022-12-31 09:02:23 +00:00
wcscpy(buf, L"平场校正失败, 原因--->");
2022-12-30 10:15:49 +00:00
}
}
2023-01-05 09:46:52 +00:00
else if (wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_GET_DISTORTION_VAL) == 0)
2022-12-31 03:13:04 +00:00
{
2023-01-06 09:56:19 +00:00
2022-12-31 03:13:04 +00:00
if (strcmp((char*)data, STATU_DESC_SCAN_STOPPED) != 0 || strcmp((char*)data, STATU_DESC_SCANNER_ERR_DEVICE_DISTORTION) == 0)
{
type = false;
2023-01-05 12:19:55 +00:00
is_distortion_get_image = false;
is_distortion_get_image_abnormal = true;
2023-01-05 09:46:52 +00:00
wcscpy(buf, L"畸变修正值获取失败,原因--->");
2022-12-31 03:13:04 +00:00
}
else
{
2023-01-05 12:19:55 +00:00
is_distortion_get_image = true;
//type = true;
//wcscpy(buf, L"畸变修正值获取完成:");
2023-03-01 09:34:07 +00:00
break;
2022-12-31 03:13:04 +00:00
}
2023-03-01 09:34:07 +00:00
//break;
2023-01-05 09:46:52 +00:00
//ret = h->io_control(IO_CTRL_CODE_GET_DPI_COLOR_CHECK_VAL, &close, &closelen);//结束恢复默认
2022-12-31 03:13:04 +00:00
}
2023-02-08 07:25:54 +00:00
else if (wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_COLOR_QUALITY) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_GRAY_QUALITY) == 0)
2022-12-31 09:02:23 +00:00
{
if (strcmp((char*)data, STATU_DESC_SCAN_STOPPED) != 0)
{
type = false;
wcscpy(buf, L"扫描图像质量确认失败, 原因--->");
}
}
else if (wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_SCANNING_SENSOR) == 0)
{
if (strcmp((char*)data, STATU_DESC_SCAN_STOPPED) != 0)
{
type = false;
wcscpy(buf, L"扫描传感器检查失败, 原因--->");
}
}
else if (wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_CIS_ORIGINAL_IMAGE) == 0)
{
2023-01-03 03:12:53 +00:00
if (strcmp((char*)data, STATU_DESC_SCAN_STOPPED) != 0)
{
type = false;
wcscpy(buf, L"CIS原图初检, 原因--->");
}
2022-12-31 09:02:23 +00:00
h->io_control(IO_CTRL_CODE_SET_CIS_IMAGE, &close, &closelen);
}
else if (wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_PRESSUER_TEST_RGB_200DPI) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_PRESSUER_TEST_GRAY_200DPI) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_PRESSUER_TEST_RGB_300DPI) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_PRESSUER_TEST_GRAY_300DPI) == 0)
{
if (strcmp((char*)data, STATU_DESC_SCAN_STOPPED) != 0)
{
type = false;
wcscpy(buf, L"压力测试失败, 原因--->");
}
else
{
type = true;
wcscpy(buf, L"压力测试完成--->");
}
}
else if (wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_COLORCARD_IMAGEING_QUALITY) == 0)
{
if (strcmp((char*)data, STATU_DESC_SCAN_STOPPED) != 0)
{
type = false;
wcscpy(buf, L"色卡纸成像质量评估失败, 原因--->");
}
}
else if (wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_COLORCARD_BIAS_IMAGEING_QUALITY) == 0)
{
if (strcmp((char*)data, STATU_DESC_SCAN_STOPPED) != 0)
{
type = false;
wcscpy(buf, L"色卡纸偏色成像质量评估失败, 原因--->");
}
}
else if (wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_CLARITY_QUALITY) == 0)
{
if (strcmp((char*)data, STATU_DESC_SCAN_STOPPED) != 0)
{
type = false;
wcscpy(buf, L"清晰度质量评估失败, 原因--->");
}
}
else if (wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_SINGLE_PAGE_TEST) == 0)
{
if (strcmp((char*)data, STATU_DESC_SCAN_STOPPED) != 0)
{
type = false;
wcscpy(buf, L"单张测试失败, 原因--->");
}
}
2023-01-03 03:12:53 +00:00
2022-12-31 09:02:23 +00:00
wcscat(buf, wstr.c_str());
2022-12-31 04:08:59 +00:00
ret = h->io_control(IO_CTRL_CODE_RESTORE_SETTINGS, NULL, NULL);//结束恢复默认
2022-12-31 04:10:28 +00:00
2022-12-31 09:02:23 +00:00
h->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void*)buf, type);
2022-12-26 09:18:25 +00:00
}
break;
case SANE_EVENT_ERROR:
{
2022-12-28 02:21:16 +00:00
h->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void*)wstr.c_str(), false);
2022-12-26 09:18:25 +00:00
}
break;
2022-12-29 16:07:01 +00:00
case SANE_EVENT_STATUS:
{
if (wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_AUTO_FLAT_FIELD) == 0)
{
2022-12-30 10:15:49 +00:00
h->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_FALT_INFO, (wchar_t*)wstr.c_str(), type);
2022-12-29 16:07:01 +00:00
}
}
break;
2022-12-26 09:18:25 +00:00
case SANE_EVENT_IMAGE_OK:
{
2022-12-28 02:21:16 +00:00
if ( wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_CIS_ORIGINAL_IMAGE) == 0
2023-02-08 07:25:54 +00:00
||wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_COLOR_QUALITY) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_IMAGE_GRAY_QUALITY) == 0
2023-01-05 09:46:52 +00:00
||wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_GET_DISTORTION_VAL) == 0
2022-12-31 09:02:23 +00:00
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_SCANNING_SENSOR) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_COLORCARD_IMAGEING_QUALITY) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_COLORCARD_BIAS_IMAGEING_QUALITY) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_CLARITY_QUALITY) == 0
2023-01-06 06:23:55 +00:00
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_SINGLE_PAGE_TEST) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_PRESSUER_TEST_RGB_200DPI) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_PRESSUER_TEST_GRAY_200DPI) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_PRESSUER_TEST_RGB_300DPI) == 0
|| wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_PRESSUER_TEST_GRAY_300DPI) == 0)
2022-12-27 08:26:41 +00:00
{
2023-01-05 09:46:52 +00:00
if (wcscmp(set_test_name_.c_str(), HGPDTTOOLDB_NAME_GET_DISTORTION_VAL) == 0)
{
2023-01-06 09:56:19 +00:00
//is_distortion_get_image = true;
2023-01-05 09:46:52 +00:00
}
2022-12-28 02:21:16 +00:00
h->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_HAVE_IMAGE, data, true);
2022-12-27 08:26:41 +00:00
}
2022-12-26 09:18:25 +00:00
}
break;
}
return 0;
}
2022-12-28 09:14:23 +00:00
test(ui_helper* helper) :helper_(helper), fw_(0)
2022-12-23 02:39:07 +00:00
{
2022-12-26 09:18:25 +00:00
helper->register_sane_callback(sane_ex_callback, NULL);
2022-12-23 02:39:07 +00:00
init_test_map_();
}
2022-12-15 11:53:41 +00:00
~test()
{}
2022-12-27 08:26:41 +00:00
std::map<std::wstring, int(test::*)(void *)> test_map_;
2022-12-15 11:53:41 +00:00
void init_test_map_()
{
2023-01-03 03:12:53 +00:00
test_map_[WRITE_CFG_NAME] = &test::set_init_cfg;
2023-01-05 09:49:56 +00:00
test_map_[HGPDTTOOLDB_NAME_SET_JSON_SN] = &test::test_set_json_serial_num;
2022-12-27 08:26:41 +00:00
test_map_[HGPDTTOOLDB_NAME_CLEAR_PAPER_PATH] = &test::tset_clear_paper_path;
test_map_[HGPDTTOOLDB_NAME_KEY_FUNCTION] = &test::test_key_funtion;
test_map_[HGPDTTOOLDB_NAME_COUNTING_MODE] = &test::test_count_mode;
test_map_[HGPDTTOOLDB_NAME_SKEW_DETECTION] = &test::test_skew_detection;
test_map_[HGPDTTOOLDB_NAME_SEPARATER_MOTOR] = &test::test_separater_motor;
test_map_[HGPDTTOOLDB_NAME_CIS_ORIGINAL_IMAGE] = &test::test_cis__original_image;
test_map_[HGPDTTOOLDB_NAME_HOST_FAN] = &test::test_host_fan;
test_map_[HGPDTTOOLDB_NAME_ULTRASONIC_MODULE] = &test::test_ultrasonic_module;
test_map_[HGPDTTOOLDB_NAME_LED_LIGHT] = &test::test_led_light;
test_map_[HGPDTTOOLDB_NAME_RESET] = &test::test_reset;
test_map_[HGPDTTOOLDB_NAME_PAPER_FEED] = &test::test_paper_feed;
test_map_[HGPDTTOOLDB_NAME_SCANNING_SENSOR] = &test::test_scanning_sensor;
test_map_[HGPDTTOOLDB_NAME_CONFIGURE_SPEED_MODE] = &test::test_configure_speed_mode;
test_map_[HGPDTTOOLDB_NAME_PLACE_CORRECTION_PAPER] = &test::test_place_correction_paper;
test_map_[HGPDTTOOLDB_NAME_AUTO_FLAT_FIELD] = &test::test_auto_flat_field;
test_map_[HGPDTTOOLDB_NAME_REBOOT_DEVICE] = &test::test_reboot_device;
2023-02-08 07:25:54 +00:00
test_map_[HGPDTTOOLDB_NAME_IMAGE_COLOR_QUALITY] = &test::test_image_color_quality;
test_map_[HGPDTTOOLDB_NAME_IMAGE_GRAY_QUALITY] = &test::test_image_gray_quality;
2023-01-05 09:46:52 +00:00
test_map_[HGPDTTOOLDB_NAME_GET_DISTORTION_VAL] = &test::test_get_auto_distortion;
test_map_[HGPDTTOOLDB_NAME_SET_DISTORTION_VAL] = &test::test_set_auto_distortion;
2022-12-27 08:26:41 +00:00
test_map_[HGPDTTOOLDB_NAME_DORMANCY] = &test::test_dormancy;
test_map_[HGPDTTOOLDB_NAME_PAPER_SEPARATION_STRENGTH] = &test::test_paper_separation_strength;
test_map_[HGPDTTOOLDB_NAME_MECH_PAPER_FEEDING_INCLINATION] = &test::test_mech_paper_feeding_inclination;
test_map_[HGPDTTOOLDB_NAME_CLEAR_ROLLER_COUNT] = &test::test_clear_roller_count;
2022-12-31 09:02:23 +00:00
test_map_[HGPDTTOOLDB_NAME_COVER_SENSOR] = &test::test_single_page_test;
test_map_[HGPDTTOOLDB_NAME_SINGLE_PAGE_TEST] = &test::test_single_page_test;
test_map_[HGPDTTOOLDB_NAME_COLORCARD_IMAGEING_QUALITY] = &test::test_single_page_test;
test_map_[HGPDTTOOLDB_NAME_COLORCARD_BIAS_IMAGEING_QUALITY] = &test::test_single_page_test;
test_map_[HGPDTTOOLDB_NAME_CLARITY_QUALITY] = &test::test_single_page_test;
test_map_[HGPDTTOOLDB_NAME_PRESSUER_TEST_RGB_200DPI] = &test::test_pressuer_test_rgb_200dpi;
test_map_[HGPDTTOOLDB_NAME_PRESSUER_TEST_GRAY_200DPI] = &test::test_pressuer_test_gray_200dpi;
test_map_[HGPDTTOOLDB_NAME_PRESSUER_TEST_RGB_300DPI] = &test::test_pressuer_test_rgb_300dpi;
test_map_[HGPDTTOOLDB_NAME_PRESSUER_TEST_GRAY_300DPI] = &test::test_pressuer_test_gray_300dpi;
2023-02-15 11:40:08 +00:00
test_map_[HGPDTTOOLDB_NAME_GET_DEVICE_CONFIG] = &test::test_get_device_config;
2022-12-23 02:39:07 +00:00
}
2023-01-03 11:15:58 +00:00
int set_test(const wchar_t* name,const wchar_t* oper)
2022-12-23 02:39:07 +00:00
{
if (wcscmp(name, HGPDTTOOLDB_NAME_SET_JSON_SN) == 0
|| wcscmp(name, HGPDTTOOLDB_NAME_GET_DEVICE_CONFIG) == 0
2023-03-01 03:05:47 +00:00
|| wcscmp(name, HGPDTTOOLDB_NAME_CONFIGURE_SPEED_MODE) == 0
|| wcscmp(name, WRITE_CFG_NAME) == 0)
{
std::string fw1(get_firmware_version());
2023-03-01 03:05:47 +00:00
if (!fw1.empty())
{
if ("G1" == fw1.substr(0, 2))
fw_ = 1;
else if ("G2" == fw1.substr(0, 2))
fw_ = 2;
else if ("G3" == fw1.substr(0, 2))
fw_ = 3;
else if ("G4" == fw1.substr(0, 2))
fw_ = 4;
}
}
2023-01-03 11:15:58 +00:00
if (!name)
2022-12-23 02:39:07 +00:00
return SCANNER_ERR_NO_DATA;
2023-01-03 11:15:58 +00:00
set_test_name_ = name;
2022-12-23 02:39:07 +00:00
int ret = SCANNER_ERR_OK;
2023-01-03 11:15:58 +00:00
auto it = test_map_.find(name);
2022-12-27 08:26:41 +00:00
2022-12-23 02:39:07 +00:00
if (it != test_map_.end())
{
2023-01-03 11:15:58 +00:00
ret = (this->*test_map_[name])((void *)oper);
2022-12-23 02:39:07 +00:00
}
else
{
2023-01-03 11:15:58 +00:00
helper_->test_callback(name, ui_helper::TEST_EVENT_NOT_FIND_TEST, NULL, false);
2022-12-27 08:26:41 +00:00
return ret;
2022-12-23 02:39:07 +00:00
}
if (ret == SCANNER_ERR_DEVICE_NOT_SUPPORT
|| ret == SCANNER_ERR_IO
|| ret == SCANNER_ERR_TIMEOUT
|| ret == SCANNER_ERR_NO_DATA
)
2022-12-23 02:39:07 +00:00
{
2023-01-03 11:15:58 +00:00
helper_->test_callback(name, ui_helper::TEST_EVENT_IO_FAIL, NULL, ret);
2022-12-23 02:39:07 +00:00
}
return ret;
2022-12-15 11:53:41 +00:00
}
public:
2023-01-03 03:12:53 +00:00
int set_init_cfg(void *data)
2022-12-28 09:14:23 +00:00
{
2023-01-03 11:15:58 +00:00
const wchar_t* p = (const wchar_t*)data;
LPWRITECFG cfg = (LPWRITECFG)p;
2022-12-28 09:14:23 +00:00
unsigned int len = 0;
2023-01-03 03:12:53 +00:00
int ret = SCANNER_ERR_OK;
switch (cfg->cat)
{
case WRITE_CAT_VID_PID:
ret = test_set_vidpid(cfg->val);
break;
case WRITE_CAT_SPEED:
ret = test_configure_speed_mode(cfg->val);
break;
case WRITE_CAT_SLEEP:
ret = test_dormancy(cfg->val);
break;
case WRITE_CAT_SERIALNUM:
ret = test_set_serial_num(cfg->val);
break;
default:
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void*)L"协议未找到", false);
break;
}
return ret;
2022-12-28 09:14:23 +00:00
}
2022-12-15 11:53:41 +00:00
2023-01-05 09:46:52 +00:00
/*设置序列号*/
int test_set_json_serial_num(void* data)
{
int ret = SCANNER_ERR_OK,
val = 0;
wchar_t* sn;
std::string set_sn,get_sn;
size_t len = 0;
parameter* prt = helper_->get_user_input(ui_helper::DATA_FROM_USER, ui_helper::VAL_TYPE_FLOAT, set_test_name_.c_str(), L"请设置序列号");
if (!prt)
{
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void*)L"已退出序列号设置", false);
return -1;
}
else
{
sn = (wchar_t*)prt->get_data();
if (!sn)
{
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void*)L"设置序列号失败", false);
return -1;
}
}
ret = wchar_to_char(set_sn, sn, &len);
if (ret == ERROR_INSUFFICIENT_BUFFER)
{
if (fw_ == 3 || fw_ == 4)
{
if (len != 14)
{
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void*)L"设置序列号不足:14位", false);
return -1;
}
}
set_sn.resize(len);
ret = wchar_to_char(set_sn, sn, &len);
}
unsigned int setlen = set_sn.size(),
getlen = 0;
ret = helper_->io_control(IO_CTRL_CODE_SET_SERIAL, &set_sn[0], &setlen);
if (ret != SCANNER_ERR_OK)return ret;
ret = helper_->io_control(IO_CTRL_CODE_GET_SERIAL, &get_sn[0], &getlen);
if (ret == SANE_STATUS_NO_MEM)
{
2023-02-15 11:40:08 +00:00
ret = helper_->io_control(IO_CTRL_CODE_GET_SERIAL, &get_sn[0], &getlen);
2023-01-05 09:46:52 +00:00
}
if (set_sn == get_sn)
{
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void*)L"设置序列号完成", true);
}
else
{
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void*)L"设置序列号失败", true);
}
2023-01-03 03:12:53 +00:00
2023-01-05 09:46:52 +00:00
return ret;
}
2022-12-30 01:28:56 +00:00
/* 清理纸道功能确认 */
2022-12-27 08:26:41 +00:00
int tset_clear_paper_path(void *data)
2022-12-15 11:53:41 +00:00
{
2022-12-23 02:39:07 +00:00
int ret = helper_->io_control(IO_CTRL_CODE_GET_CLEAN_PAPER_ROAD, NULL, NULL);
if (ret != SCANNER_ERR_OK)
{
2022-12-26 09:18:25 +00:00
return ret;
2022-12-23 02:39:07 +00:00
}
2022-12-30 01:28:56 +00:00
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_MANUAL_CONFIRMATION, (void*)L"请确认是否清理纸道成功", true);
2022-12-23 02:39:07 +00:00
return ret;
2022-12-15 11:53:41 +00:00
}
2022-12-30 01:28:56 +00:00
/* 按键功能检测 */
2022-12-27 08:26:41 +00:00
int test_key_funtion(void *data)
2022-12-15 11:53:41 +00:00
{
2022-12-23 02:39:07 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
2022-12-15 11:53:41 +00:00
}
2022-12-30 01:28:56 +00:00
/* 计数模式检测 */
2022-12-27 08:26:41 +00:00
int test_count_mode(void *data)
2022-12-15 11:53:41 +00:00
{
2022-12-23 02:39:07 +00:00
SANE_Bool ismode = false;
unsigned int len = sizeof(SANE_Bool);
2022-12-26 09:18:25 +00:00
int ret = helper_->io_control(IO_CTRL_CODE_GET_IS_MODE, &ismode, &len);
2022-12-23 02:39:07 +00:00
if (ret != SCANNER_ERR_OK)
{
return ret;
}
2022-12-30 01:28:56 +00:00
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_MANUAL_CONFIRMATION, (void*)L"请确认与液晶面板是否匹配", ismode);
2022-12-23 02:39:07 +00:00
return ret;
2022-12-15 11:53:41 +00:00
}
2022-12-30 01:28:56 +00:00
/* 歪斜检测 */
2022-12-27 08:26:41 +00:00
int test_skew_detection(void *data)
2022-12-15 11:53:41 +00:00
{
2022-12-29 10:07:00 +00:00
const wchar_t* NAME = set_test_name_.c_str();
2022-12-26 09:18:25 +00:00
SANE_Bool type = true;
2022-12-23 02:39:07 +00:00
unsigned int len = sizeof(SANE_Bool);
2022-12-27 08:26:41 +00:00
int num = 0;
2022-12-28 09:14:23 +00:00
void* get_data = NULL;
2022-12-30 01:28:56 +00:00
parameter * ptr = helper_->get_user_input(ui_helper::DATA_FROM_USER, ui_helper::VAL_TYPE_INT, NAME,L"请歪斜放纸...设置阈值0 - 5,值越小越容易检测,0为关闭歪斜检测");
2022-12-27 08:26:41 +00:00
if (ptr)
2022-12-28 04:04:50 +00:00
{
2022-12-28 09:14:23 +00:00
get_data = ptr->get_data();
if (!get_data)
{
2022-12-30 01:28:56 +00:00
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void*)L"已退出歪斜检测流程", false);
2022-12-28 09:14:23 +00:00
return -1;
}
num = *((int*)get_data);
2022-12-28 04:04:50 +00:00
}
2022-12-29 03:22:22 +00:00
else
2022-12-27 08:26:41 +00:00
{
2022-12-30 01:28:56 +00:00
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void*)L"已退出歪斜检测流程", false);
2022-12-29 03:22:22 +00:00
return -1;
2022-12-27 08:26:41 +00:00
}
2022-12-29 03:22:22 +00:00
type = num == 0 ? false:true;
ptr->release();
int ret = helper_->io_control(IO_CTRL_CODE_SET_SKEW_CHECK, &type, &len);
2022-12-29 10:07:00 +00:00
if (ret != SCANNER_ERR_OK)
return ret;
2022-12-29 03:22:22 +00:00
2022-12-27 08:26:41 +00:00
ret = helper_->io_control(IO_CTRL_CODE_SET_SKEW_CHECK_VAL, &num, &len);
2022-12-29 10:07:00 +00:00
if (ret != SCANNER_ERR_OK)
return ret;
2022-12-23 02:39:07 +00:00
2022-12-29 03:22:22 +00:00
ret = helper_->io_control(IO_CTRL_CODE_TEST_SINGLE, NULL, NULL);
2022-12-23 02:39:07 +00:00
return ret;
2022-12-15 11:53:41 +00:00
}
2022-12-30 01:28:56 +00:00
/* 分纸电机检测 */
2022-12-27 08:26:41 +00:00
int test_separater_motor(void *data)
2022-12-15 11:53:41 +00:00
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
2022-12-15 11:53:41 +00:00
}
2022-12-30 01:28:56 +00:00
/* cis原图初检 */
2022-12-27 08:26:41 +00:00
int test_cis__original_image(void *data)
2022-12-15 11:53:41 +00:00
{
2022-12-29 10:07:00 +00:00
const wchar_t* NAME = set_test_name_.c_str();
2022-12-27 08:26:41 +00:00
SANE_Bool type = true;
unsigned int len = sizeof(SANE_Bool);
int ret = SCANNER_ERR_OK;
ret = helper_->io_control(IO_CTRL_CODE_SET_CIS_IMAGE, &type, &len);
if (ret != SCANNER_ERR_OK)
{
return ret;
}
2023-01-05 09:52:17 +00:00
ret = helper_->io_control(IO_CTRL_CODE_GET_IMAGE, NULL, NULL);
2022-12-27 08:26:41 +00:00
if (ret != SCANNER_ERR_OK)
{
return ret;
}
return ret;
2022-12-15 11:53:41 +00:00
}
2022-12-30 01:28:56 +00:00
/* 主机风扇功能检测 */
2022-12-27 08:26:41 +00:00
int test_host_fan(void *data)
2022-12-15 11:53:41 +00:00
{
2022-12-29 13:17:20 +00:00
return helper_->io_control(IO_CTRL_CODE_GET_IMAGE, NULL, NULL);
2022-12-15 11:53:41 +00:00
}
2022-12-30 01:28:56 +00:00
/* 超声波模块检验 */
2022-12-27 08:26:41 +00:00
int test_ultrasonic_module(void *data)
2022-12-15 11:53:41 +00:00
{
2022-12-29 10:07:00 +00:00
const wchar_t* NAME = set_test_name_.c_str();
2022-12-28 09:14:23 +00:00
SANE_Bool type = true;
unsigned int len = sizeof(SANE_Bool);
void* get_data = NULL;
int ret = SCANNER_ERR_OK;
2022-12-29 03:22:22 +00:00
parameter* ptr = helper_->get_user_input(ui_helper::DATA_FROM_USER, ui_helper::VAL_TYPE_BOOL, NAME,
2022-12-30 01:28:56 +00:00
L"请选择是否开启超声波检查,并且请放置双张纸");
2022-12-28 09:14:23 +00:00
if (ptr)
{
get_data = ptr->get_data();
2022-12-29 03:22:22 +00:00
if (!get_data)
2022-12-28 09:14:23 +00:00
{
2022-12-30 01:28:56 +00:00
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void*)L"已退出超声波模块检测流程", false);
2022-12-28 09:14:23 +00:00
return -1;
}
2022-12-29 03:22:22 +00:00
else
type = *((bool*)get_data);
2022-12-28 09:14:23 +00:00
}
2022-12-29 03:22:22 +00:00
else
{
2022-12-30 01:28:56 +00:00
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void*)L"已退出超声波模块检测流程", false);
2022-12-29 03:22:22 +00:00
return -1;
}
ptr->release();
2022-12-28 09:14:23 +00:00
ret = helper_->io_control(IO_CTRL_CODE_SET_ULTRASONIC_MODULE, &type, &len);
2022-12-29 03:22:22 +00:00
2022-12-28 09:14:23 +00:00
if (ret != SCANNER_ERR_OK)
{
return ret;
}
ret = helper_->io_control(IO_CTRL_CODE_TEST_SINGLE, NULL, NULL);
return ret;
2022-12-15 11:53:41 +00:00
}
2022-12-30 01:28:56 +00:00
/* led灯状态检查 */
2022-12-27 08:26:41 +00:00
int test_led_light(void *data)
2022-12-15 11:53:41 +00:00
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
2022-12-15 11:53:41 +00:00
}
2022-12-30 01:28:56 +00:00
/* 复位检查 */
2022-12-27 08:26:41 +00:00
int test_reset(void *data)
2022-12-15 11:53:41 +00:00
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
2022-12-15 11:53:41 +00:00
}
2022-12-30 01:28:56 +00:00
/* 走纸检查 */
int test_paper_feed(void *data) //使用单张扫描测试
2022-12-15 11:53:41 +00:00
{
return helper_->io_control(IO_CTRL_CODE_GET_IMAGE, NULL, NULL);
2022-12-15 11:53:41 +00:00
}
2022-12-30 01:28:56 +00:00
/* 扫描传感器检查 */
2022-12-27 08:26:41 +00:00
int test_scanning_sensor(void *data)
2022-12-15 11:53:41 +00:00
{
2022-12-29 13:17:20 +00:00
return helper_->io_control(IO_CTRL_CODE_GET_IMAGE, NULL, NULL);
2022-12-15 11:53:41 +00:00
}
2022-12-30 01:28:56 +00:00
/* 放置校正纸 */
2022-12-27 08:26:41 +00:00
int test_place_correction_paper(void *data)
2022-12-15 11:53:41 +00:00
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
2022-12-15 11:53:41 +00:00
}
2022-12-30 01:28:56 +00:00
/* 自动平场校正 */
2022-12-27 08:26:41 +00:00
int test_auto_flat_field(void *data)
2022-12-15 11:53:41 +00:00
{
2022-12-29 16:07:01 +00:00
return helper_->io_control(IO_CTRL_CODE_SET_AUTO_FALT, NULL, NULL);;
2022-12-15 11:53:41 +00:00
}
2022-12-30 01:28:56 +00:00
/* 重启设备 */
2022-12-27 08:26:41 +00:00
int test_reboot_device(void *data)
2022-12-15 11:53:41 +00:00
{
2023-01-03 13:25:54 +00:00
if (!data)
2022-12-29 10:07:00 +00:00
{
2023-01-03 13:25:54 +00:00
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void*)L"设备重启中失败", false);
2022-12-29 10:07:00 +00:00
return -1;
}
2023-01-03 13:25:54 +00:00
wchar_t* p = (wchar_t*)data;
2022-12-29 03:22:22 +00:00
2023-01-03 13:25:54 +00:00
int i = _wtoi(p);
unsigned int len = sizeof(int);
int ret = helper_->io_control(IO_CTRL_CODE_SET_DEVS_REBOOT, &i, &len);
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void*)L"设备重启中,请观察设备是否重启", true);
2022-12-29 10:07:00 +00:00
return ret;
2022-12-15 11:53:41 +00:00
}
2023-02-08 07:25:54 +00:00
/* 扫描图像彩色质量确认 */
int test_image_color_quality(void *data)
{
if (!data)
{
return SCANNER_ERR_DATA_DAMAGED;
}
wchar_t* p = (wchar_t*)data;
std::string str;
int ret = SCANNER_ERR_OK,
dpi = 0;
unsigned int len = sizeof(int);
size_t strl = 0;
ret = wchar_to_char(str, p, &strl);
if (ret == ERROR_INSUFFICIENT_BUFFER)
{
str.resize(strl);
ret = wchar_to_char(str, p, &strl);
if (str.empty())
{
return SCANNER_ERR_DATA_DAMAGED;
}
dpi = atoi(str.c_str());
}
if (dpi > 0)
{
ret = helper_->io_control(IO_CTRL_CODE_SET_DPI, &dpi, &len);
}
if (ret != SCANNER_ERR_OK)
{
return -1;
}
const char* color = OPTION_VALUE_YSMS_24WCS;
unsigned int colorlen = strlen(color);
helper_->io_control(IO_CTRL_CODE_SET_COLOR, (void*)color, &colorlen);
return helper_->io_control(IO_CTRL_CODE_GET_IMAGE, NULL, NULL);
}
/* 扫描图像灰度质量确认 */
int test_image_gray_quality(void* data)
2022-12-15 11:53:41 +00:00
{
2023-01-09 08:16:05 +00:00
if (!data)
{
return SCANNER_ERR_DATA_DAMAGED;
}
2023-01-09 09:16:19 +00:00
wchar_t* p = (wchar_t*)data;
std::string str;
int ret = SCANNER_ERR_OK,
dpi = 0;
unsigned int len = sizeof(int);
size_t strl = 0;
ret = wchar_to_char(str, p, &strl);
if (ret == ERROR_INSUFFICIENT_BUFFER)
{
str.resize(strl);
ret = wchar_to_char(str, p, &strl);
2023-01-10 01:36:59 +00:00
if (str.empty())
{
return SCANNER_ERR_DATA_DAMAGED;
}
dpi = atoi(str.c_str());
2023-01-09 09:16:19 +00:00
}
2023-01-10 01:36:59 +00:00
if (dpi > 0)
2023-01-09 09:16:19 +00:00
{
2023-01-10 01:36:59 +00:00
ret = helper_->io_control(IO_CTRL_CODE_SET_DPI, &dpi, &len);
2023-01-09 09:16:19 +00:00
}
2023-01-09 08:16:05 +00:00
if (ret != SCANNER_ERR_OK)
{
return -1;
}
2023-02-08 07:25:54 +00:00
const char* color = OPTION_VALUE_YSMS_256JHD;
unsigned int colorlen = strlen(color);
helper_->io_control(IO_CTRL_CODE_SET_COLOR, (void*)color, &colorlen);
2022-12-29 13:17:20 +00:00
return helper_->io_control(IO_CTRL_CODE_GET_IMAGE, NULL, NULL);
2022-12-15 11:53:41 +00:00
}
2023-01-05 09:46:52 +00:00
/* 获取自动计算畸变值 */
int test_get_auto_distortion(void *data)
2022-12-15 11:53:41 +00:00
{
2023-01-09 08:16:05 +00:00
if (!data )
{
return SCANNER_ERR_DATA_DAMAGED;
}
2023-01-09 09:16:19 +00:00
wchar_t* p = (wchar_t*)data;
std::string str;
2023-01-10 06:22:02 +00:00
int ret = SCANNER_ERR_OK,
2023-01-09 09:16:19 +00:00
dpi = 0;
2022-12-28 02:21:16 +00:00
SANE_Bool type = true;
2023-01-05 09:46:52 +00:00
unsigned int len = sizeof(SANE_Bool),
llen = sizeof(int);
2023-01-09 09:16:19 +00:00
size_t strl = 0;
ret = wchar_to_char(str, p, &strl);
if (ret == ERROR_INSUFFICIENT_BUFFER)
{
str.resize(strl);
ret = wchar_to_char(str, p, &strl);
2023-01-10 01:36:59 +00:00
if (str.empty())
{
return SCANNER_ERR_DATA_DAMAGED;
}
dpi = atoi(str.c_str());
2023-01-09 09:16:19 +00:00
}
2023-01-10 01:36:59 +00:00
if (dpi > 0)
2023-01-09 09:16:19 +00:00
{
2023-01-10 01:36:59 +00:00
ret = helper_->io_control(IO_CTRL_CODE_SET_DPI, &dpi, &llen);
2023-01-09 09:16:19 +00:00
}
2023-01-10 01:36:59 +00:00
2023-01-05 12:19:55 +00:00
ret = helper_->io_control(IO_CTRL_CODE_SET_DISTORTION_IMAGE, &type, &len);
if (ret != SCANNER_ERR_OK)
{
return ret;
}
int cnt = 0;
2023-01-09 09:55:07 +00:00
SANE_DISTORTION_VAL dis = { 0 };
2023-01-05 12:19:55 +00:00
while (ret == SCANNER_ERR_OK)
2023-01-05 09:46:52 +00:00
{
if (is_distortion_get_image)
2023-01-05 09:46:52 +00:00
{
2023-01-09 08:16:05 +00:00
ret = helper_->io_control(IO_CTRL_CODE_GET_DISTORTION_CHECK_VAL, &dis, &llen);
2023-01-05 09:46:52 +00:00
break;
}
else if (cnt == 30)
2023-01-05 12:19:55 +00:00
break;
if (is_distortion_get_image_abnormal)
2023-03-01 07:41:04 +00:00
return -1;
2023-01-05 12:19:55 +00:00
Sleep(1000);
cnt++;
2023-01-05 09:46:52 +00:00
}
if (dis.h > 0 && dis.scaleXY < 10)
2023-01-05 09:46:52 +00:00
{
2023-01-09 08:16:05 +00:00
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_DISTORTION_VAL, (void *)&dis, true);
2023-01-05 09:46:52 +00:00
}
2023-01-06 09:56:19 +00:00
else
{
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT,(void*)L"自动计算畸变值获取失败", false);
2023-01-06 09:56:19 +00:00
}
2023-01-05 09:46:52 +00:00
return ret;
2022-12-15 11:53:41 +00:00
}
2023-01-05 09:46:52 +00:00
int test_set_auto_distortion(void* data)
{
2023-01-10 06:25:38 +00:00
if (!data)
{
return SCANNER_ERR_DATA_DAMAGED;
}
wchar_t* p = (wchar_t*)data;
std::string str;
2023-01-05 09:46:52 +00:00
int ret = SCANNER_ERR_OK,
2023-01-10 06:25:38 +00:00
dpi = 0;
2023-01-05 09:46:52 +00:00
unsigned int len = sizeof(int);
2023-01-10 06:25:38 +00:00
float distortion = 0.0;
size_t strl = 0;
ret = wchar_to_char(str, p, &strl);
if (ret == ERROR_INSUFFICIENT_BUFFER)
{
str.resize(strl);
ret = wchar_to_char(str, p, &strl);
if (str.empty())
{
return SCANNER_ERR_DATA_DAMAGED;
}
dpi = atoi(str.c_str());
}
if (dpi > 0)
{
ret = helper_->io_control(IO_CTRL_CODE_SET_DPI, &dpi, &len);
}
2023-01-05 09:46:52 +00:00
parameter* prt = helper_->get_user_input(ui_helper::DATA_FROM_USER, ui_helper::VAL_TYPE_FLOAT, set_test_name_.c_str(), L"请设置畸变值");
if (!prt)
{
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void*)L"已退出畸变值设置", false);
return -1;
}
else
{
void * p = prt->get_data();
distortion = *(float*)p;
}
if (distortion == 0.0)
{
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void *)L"已退出畸变值设置", false);
return -1;
}
int setdistortion = *(int*)&distortion;
int getdistortion = 0;
ret = helper_->io_control(IO_CTRL_CODE_SET_DISTORTION_CHECK_VAL, &setdistortion, &len);
if (ret != SCANNER_ERR_OK)
{
return ret;
}
2023-01-10 06:22:02 +00:00
ret = helper_->io_control(IO_CTRL_CODE_GET_DISTORTION_DEVS_CHECK_VAL, &getdistortion, &len);
if (setdistortion == getdistortion)
{
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void*)L"设置畸变值成功", true);
}
else
{
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void*)L"设置畸变值失败", false);
}
2023-01-05 09:46:52 +00:00
return ret;
}
2022-12-30 01:28:56 +00:00
/* 分纸强度检测 */
2022-12-27 08:26:41 +00:00
int test_paper_separation_strength(void *data)
2022-12-15 11:53:41 +00:00
{
2022-12-29 10:07:00 +00:00
//parameter* ptr = helper_->get_user_input(ui_helper::DATA_FROM_USER, ui_helper::VAL_TYPE_TIPS_VAL, NAME, (wchar_t*)&info_);
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
2022-12-15 11:53:41 +00:00
}
2022-12-30 01:28:56 +00:00
/* 机械走纸倾斜检测 */
2022-12-27 08:26:41 +00:00
int test_mech_paper_feeding_inclination(void *data)
2022-12-15 11:53:41 +00:00
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
2022-12-15 11:53:41 +00:00
}
2022-12-30 01:28:56 +00:00
/* 清除滚轴计数 */
2022-12-27 08:26:41 +00:00
int test_clear_roller_count(void *data)
2022-12-15 11:53:41 +00:00
{
2022-12-29 10:07:00 +00:00
SANE_Int roller_num = -1;
const wchar_t* info = NULL;
bool type = false;
unsigned int len = sizeof(SANE_Int);
int ret = helper_->io_control(IO_CTRL_CODE_SET_CLEAR_ROLLER_COUNT, NULL, NULL);
ret = helper_->io_control(IO_CTRL_CODE_GET_ROLLER_NUM, &roller_num, &len);
if ((roller_num == 0 && roller_num != -1))
{
type = true;
2022-12-30 01:28:56 +00:00
info = L"清除滚轴计数成功";
2022-12-29 10:07:00 +00:00
}
else
{
type = false;
2022-12-30 01:28:56 +00:00
info = L"清除滚轴计数失败";
2022-12-29 10:07:00 +00:00
}
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void*)info, type);
return ret;
2022-12-15 11:53:41 +00:00
}
2022-12-31 09:02:23 +00:00
/* 单张测试 */
int test_single_page_test(void* data)
{
return helper_->io_control(IO_CTRL_CODE_TEST_SINGLE, NULL, NULL);
}
/*压力测试彩色_200dpi*/
int test_pressuer_test_rgb_200dpi(void* data)
{
const char* color = OPTION_VALUE_YSMS_24WCS;
int dpi = 200;
unsigned int len = strlen(color);
helper_->io_control(IO_CTRL_CODE_SET_COLOR, (void *)color, &len);
helper_->io_control(IO_CTRL_CODE_SET_DPI, (void*)&dpi, &len);
return helper_->io_control(IO_CTRL_CODE_GET_IMAGE, NULL, NULL);
}
/*压力测试灰色_200dpi*/
int test_pressuer_test_gray_200dpi(void* data)
{
const char* color = OPTION_VALUE_YSMS_256JHD;
int dpi = 200;
unsigned int len = strlen(color);
helper_->io_control(IO_CTRL_CODE_SET_COLOR, (void*)color, &len);
helper_->io_control(IO_CTRL_CODE_SET_DPI, (void*)&dpi, &len);
return helper_->io_control(IO_CTRL_CODE_GET_IMAGE, NULL, NULL);
}
/*压力测试彩色_300dpi*/
int test_pressuer_test_rgb_300dpi(void* data)
{
const char* color = OPTION_VALUE_YSMS_24WCS;
int dpi = 300;
unsigned int len = strlen(color);
helper_->io_control(IO_CTRL_CODE_SET_COLOR, (void*)color, &len);
helper_->io_control(IO_CTRL_CODE_SET_DPI, (void*)&dpi, &len);
return helper_->io_control(IO_CTRL_CODE_GET_IMAGE, NULL, NULL);
}
/*压力测试灰色_300dpi*/
int test_pressuer_test_gray_300dpi(void* data)
{
const char* color = OPTION_VALUE_YSMS_256JHD;
int dpi = 300;
unsigned int len = strlen(color);
helper_->io_control(IO_CTRL_CODE_SET_COLOR, (void*)color, &len);
helper_->io_control(IO_CTRL_CODE_SET_DPI, (void*)&dpi, &len);
return helper_->io_control(IO_CTRL_CODE_GET_IMAGE, NULL, NULL);
}
2023-02-15 11:40:08 +00:00
/*获取设备配置*/
int test_get_device_config(void* data)
{
unsigned int len = sizeof(int);
unsigned int getlen = 0;
int get_vidpid = 0,
ret = SCANNER_ERR_OK;
if (ret == SCANNER_ERR_OK)
{
ret = helper_->io_control(IO_CTRL_CODE_GET_VIDPID, &get_vidpid, &len);
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVEB_GET_DEVICE_CONFIG_VIDPID, &get_vidpid, true);
}
std::string set_sn, get_sn;
std::wstring wstr;
size_t l = 0;
ret = helper_->io_control(IO_CTRL_CODE_GET_SERIAL, &get_sn[0], &getlen);
if (ret == SANE_STATUS_NO_MEM)
{
ret = helper_->io_control(IO_CTRL_CODE_GET_SERIAL, &get_sn[0], &getlen);
if (ret != SCANNER_ERR_OK)
{
return ret;
}
ret = str_to_wchar(get_sn.c_str(), (wchar_t*)wstr.c_str(), &l);
if (ret == ERROR_INSUFFICIENT_BUFFER)
{
wstr.resize(l);
ret = str_to_wchar(get_sn.c_str(), (wchar_t*)wstr.c_str(), &l);
}
if (wstr.empty())
{
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVEB_GET_DEVICE_CONFIG_SN, (void*)L"获取序列号失败", false);
return ret;
}
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVEB_GET_DEVICE_CONFIG_SN, (void *)wstr.c_str(), true);
}
int gettime = 0;
unsigned int timelen = sizeof(int*);
ret = helper_->io_control(IO_CTRL_CODE_GET_POWER_LEVEL, &gettime, &timelen);
if (gettime == INT_MAX || gettime == -1)
gettime = 0;
else
gettime /= 60;
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVEB_GET_DEVICE_CONFIG_SLEEPTIME, (void*)&gettime, true);
const wchar_t G139[6] = { 70,80,90,110 };
const wchar_t G239[6] = { 100,110,120,130 };
const wchar_t G300[6] = { 40,50,60,70 };
const wchar_t G400[6] = { 40,50,60,70,80 };
SANE_Int num = 0;
unsigned int lensp = sizeof(SANE_Int);
ret = helper_->io_control(IO_CTRL_CODE_GET_SPEED_MODE, &num, &lensp);
int save_num = 0;
if (fw_ == 3 || fw_ == 4 && num > 0 && num < 6)
{
for (size_t i = 0; i < sizeof(G400) / sizeof(G400[0]); i++)//3288设置速度模式为1 2 3 4 5
{
if ((num - 1) == i)
{
save_num = G400[i];
break;
}
}
}
else
save_num = num;
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVEB_GET_DEVICE_CONFIG_SP, (void*)&save_num, true);
helper_->test_callback(set_test_name_.c_str(), ui_helper::TEST_EVENT_RESULT, (void*)(L"配置获取完成"), true);
return ret;
}
2022-12-15 11:53:41 +00:00
private:
2022-12-08 10:10:19 +00:00
};
2022-12-15 11:53:41 +00:00
2022-12-08 10:10:19 +00:00
//test
2022-12-27 08:26:41 +00:00
static std::string jsontext1("{\"1\":{\"NAME\":\"test-8\",\"ver\":1}}");
2022-12-15 11:53:41 +00:00
bool have_img_ = false;
2022-12-27 08:26:41 +00:00
DECL_API(int) func_test_init(void* init)
2022-12-08 10:10:19 +00:00
{
return 0;
}
2022-12-15 06:39:32 +00:00
DECL_API(int) func_test_get_list(wchar_t* buf, size_t* len)
2022-12-08 10:10:19 +00:00
{
2022-12-14 06:58:06 +00:00
return str_to_wchar(jsontext1, buf, len);
2022-12-08 10:10:19 +00:00
}
2022-12-27 08:26:41 +00:00
DECL_API(int) func_test_go(const wchar_t* NAME, const wchar_t* oper, ui_helper* helper)
2022-12-08 10:10:19 +00:00
{
2022-12-27 08:26:41 +00:00
if (!NAME || !oper || !helper)
2022-12-08 10:10:19 +00:00
{
return -1;
}
2022-12-27 08:26:41 +00:00
//helper->add_ref(void *data);
2022-12-08 10:10:19 +00:00
2023-01-06 09:56:19 +00:00
is_distortion_get_image = false;
is_distortion_get_image_abnormal = false;
2022-12-27 08:26:41 +00:00
int ret = 0;
SANE_Bool type = false;
unsigned int len = sizeof(SANE_Bool);
test ts(helper);
2023-01-03 11:15:58 +00:00
ret = ts.set_test(NAME, oper);
2022-12-27 08:26:41 +00:00
if (ret != SCANNER_ERR_OK)
{
return ret;
}
2022-12-30 09:13:18 +00:00
//ret = helper->io_control(IO_CTRL_CODE_RESTORE_SETTINGS, NULL, NULL);//结束恢复默认
2022-12-23 02:39:07 +00:00
return ret;
2022-12-08 10:10:19 +00:00
}
2022-12-27 08:26:41 +00:00
DECL_API(int) func_test_uninit(void* uninit)
2022-12-08 10:10:19 +00:00
{
return 0;
2022-12-30 01:28:56 +00:00
}