413 lines
13 KiB
C++
413 lines
13 KiB
C++
#pragma once
|
|
#include "string"
|
|
#include "sane/sane_ex.h"
|
|
#include "ui_helper.h"
|
|
#include <Windows.h>
|
|
|
|
//////////////////////////////////////TITLE//////////////////////////////////////
|
|
|
|
/* 拨码开关校验 */
|
|
#define HGPDTTOOLDB_TITLE_DIAL_SWITCH L"拨码开关校验"
|
|
/* 检查船型开关功能 */
|
|
#define HGPDTTOOLDB_TITLE_ROCKER_SWITCH L"检查船型开关功能"
|
|
/* 设备上电并观察开机状态 */
|
|
#define HGPDTTOOLDB_TITLE_BOOT_STATUS L"设备上电并观察开机状态"
|
|
/* 检查液晶显示 */
|
|
#define HGPDTTOOLDB_TITLE_LCD_DISPLAY L"检查液晶显示"
|
|
/* 清理纸道功能确认 */
|
|
#define HGPDTTOOLDB_TITLE_CLEAR_PAPER_PATH L"清理纸道功能确认" //1
|
|
/* 按键功能检测 */
|
|
#define HGPDTTOOLDB_TITLE_KEY_FUNCTION L"按键功能检测"
|
|
/* 计数模式检测 */
|
|
#define HGPDTTOOLDB_TITLE_COUNTING_MODE L"计数模式检测"//1
|
|
/* 歪斜检测 */
|
|
#define HGPDTTOOLDB_TITLE_SKEW_DETECTION L"歪斜检测"//1
|
|
/* 分纸电机检测 */
|
|
#define HGPDTTOOLDB_TITLE_SEPARATER_MOTOR L"分纸电机检测"
|
|
/* CIS原图初检 */
|
|
#define HGPDTTOOLDB_TITLE_CIS_ORIGINAL_IMAGE L"CIS原图初检"
|
|
/* 主机风扇功能检测 */
|
|
#define HGPDTTOOLDB_TITLE_HOST_FAN L"主机风扇功能检测"
|
|
/* 超声波模块检验 */
|
|
#define HGPDTTOOLDB_TITLE_ULTRASONIC_MODULE L"超声波模块检验"
|
|
/* LED灯状态检查 */
|
|
#define HGPDTTOOLDB_TITLE_LED_LIGHT L"LED灯状态检查"
|
|
/* 复位检查 */
|
|
#define HGPDTTOOLDB_TITLE_RESET L"复位检查"
|
|
/* 走纸检查 */
|
|
#define HGPDTTOOLDB_TITLE_PAPER_FEED L"走纸检查"
|
|
/* 开盖传感器检查 */
|
|
#define HGPDTTOOLDB_TITLE_COVER_SENSOR L"开盖传感器检查"
|
|
/* 扫描传感器检查 */
|
|
#define HGPDTTOOLDB_TITLE_SCANNING_SENSOR L"扫描传感器检查"
|
|
/* 配置速度模式 */
|
|
#define HGPDTTOOLDB_TITLE_CONFIGURE_SPEED_MODE L"配置速度模式"
|
|
/* 放置校正纸 */
|
|
#define HGPDTTOOLDB_TITLE_PLACE_CORRECTION_PAPER L"放置校正纸"
|
|
/* 自动平场校正 */
|
|
#define HGPDTTOOLDB_TITLE_AUTO_FLAT_FIELD L"自动平场校正"
|
|
/* 重启设备 */
|
|
#define HGPDTTOOLDB_TITLE_REBOOT_DEVICE L"重启设备"
|
|
/* 扫描图像质量确认 */
|
|
#define HGPDTTOOLDB_TITLE_IMAGE_QUALITY L"扫描图像质量确认"
|
|
/* 色卡纸成像质量评估 */
|
|
#define HGPDTTOOLDB_TITLE_COLORCARD_IMAGEING_QUALITY L"色卡纸成像质量评估"
|
|
/* 色卡纸偏色成像质量评估 */
|
|
#define HGPDTTOOLDB_TITLE_COLORCARD_BIAS_IMAGEING_QUALITY L"色卡纸偏色成像质量评估"
|
|
/* 清晰度质量评估 */
|
|
#define HGPDTTOOLDB_TITLE_CLARITY_QUALITY L"清晰度质量评估"
|
|
/* 畸变修正 */
|
|
#define HGPDTTOOLDB_TITLE_DISTORTION L"畸变修正"
|
|
/* 设置休眠 */
|
|
#define HGPDTTOOLDB_TITLE_DORMANCY L"设置休眠"
|
|
/* 歪斜挡位检测 */
|
|
#define HGPDTTOOLDB_TITLE_SKEW_GEAR L"歪斜挡位检测"
|
|
/* 分纸强度检测 */
|
|
#define HGPDTTOOLDB_TITLE_PAPER_SEPARATION_STRENGTH L"分纸强度检测"
|
|
/* 机械走纸倾斜检测 */
|
|
#define HGPDTTOOLDB_TITLE_MECH_PAPER_FEEDING_INCLINATION L"机械走纸倾斜检测"
|
|
/* 单张测试1 */
|
|
#define HGPDTTOOLDB_TITLE_SINGLE_PAGE_TEST_1 L"单张测试"
|
|
/* 清除滚轴计数 */
|
|
#define HGPDTTOOLDB_TITLE_CLEAR_ROLLER_COUNT L"清除滚轴计数"
|
|
/*压力测试彩色+200dpi*/
|
|
#define HGPDTTOOLDB_TITLE_PRESSUER_TEST_RGB_200DPI L"压力测试彩色_200dpi"
|
|
/*压力测试灰色+200dpi*/
|
|
#define HGPDTTOOLDB_TITLE_PRESSUER_TEST_RGB_300DPI L"压力测试彩色_300dpi"
|
|
/*压力测试彩色+300dpi*/
|
|
#define HGPDTTOOLDB_TITLE_PRESSUER_TEST_GRAY_200DPI L"压力测试灰色_200dpi"
|
|
/*压力测试灰色+300dpi*/
|
|
#define HGPDTTOOLDB_TITLE_PRESSUER_TEST_GRAY_300DPI L"压力测试灰色_300dpi"
|
|
//////////////////////////////////////NAME//////////////////////////////////////
|
|
#define WRITE_CFG_NAME L"write-cfg"
|
|
/* 设置json序列号 */
|
|
#define HGPDTTOOLDB_NAME_SET_JSON_SN L"SET_JSON_SN"
|
|
/* 拨码开关校验 */
|
|
#define HGPDTTOOLDB_NAME_DIAL_SWITCH L"DIAL_SWITCH"
|
|
/* 检查船型开关功能 */
|
|
#define HGPDTTOOLDB_NAME_ROCKER_SWITCH L"ROCKER_SWITCH"
|
|
/* 设备上电并观察开机状态 */
|
|
#define HGPDTTOOLDB_NAME_BOOT_STATUS L"BOOT_STATUS"
|
|
/* 检查液晶显示 */
|
|
#define HGPDTTOOLDB_NAME_LCD_DISPLAY L"LCD_DISPLAY"
|
|
/* 清理纸道功能确认 */
|
|
#define HGPDTTOOLDB_NAME_CLEAR_PAPER_PATH L"PAPER_PATH"
|
|
/* 按键功能检测 */
|
|
#define HGPDTTOOLDB_NAME_KEY_FUNCTION L"KEY_FUNCTION"
|
|
/* 计数模式检测 */
|
|
#define HGPDTTOOLDB_NAME_COUNTING_MODE L"COUNTING_MODE"
|
|
/* 歪斜检测 */
|
|
#define HGPDTTOOLDB_NAME_SKEW_DETECTION L"SKEW_DETECTION"
|
|
/* 分纸电机检测 */
|
|
#define HGPDTTOOLDB_NAME_SEPARATER_MOTOR L"SEPARATER_MOTOR"
|
|
/* CIS原图初检 */
|
|
#define HGPDTTOOLDB_NAME_CIS_ORIGINAL_IMAGE L"CIS_ORIGINAL_IMAGE"
|
|
/* 主机风扇功能检测 */
|
|
#define HGPDTTOOLDB_NAME_HOST_FAN L"HOST_FAN"
|
|
/* 超声波模块检验 */
|
|
#define HGPDTTOOLDB_NAME_ULTRASONIC_MODULE L"ULTRASONIC_MODULE"
|
|
/* LED灯状态检查 */
|
|
#define HGPDTTOOLDB_NAME_LED_LIGHT L"LED_LIGHT"
|
|
/* 复位检查 */
|
|
#define HGPDTTOOLDB_NAME_RESET L"RESET"
|
|
/* 走纸检查 */
|
|
#define HGPDTTOOLDB_NAME_PAPER_FEED L"PAPER_FEED"
|
|
/* 开盖传感器检查 */
|
|
#define HGPDTTOOLDB_NAME_COVER_SENSOR L"COVER_SENSOR"
|
|
/* 扫描传感器检查 */
|
|
#define HGPDTTOOLDB_NAME_SCANNING_SENSOR L"SCANNING_SENSOR"
|
|
/* 配置速度模式 */
|
|
#define HGPDTTOOLDB_NAME_CONFIGURE_SPEED_MODE L"CONFIGURE_SPEED_MODE"
|
|
/* 放置校正纸 */
|
|
#define HGPDTTOOLDB_NAME_PLACE_CORRECTION_PAPER L"PLACE_CORRECTION_PAPER"
|
|
/* 自动平场校正 */
|
|
#define HGPDTTOOLDB_NAME_AUTO_FLAT_FIELD L"AUTO_FLAT_FIELD"
|
|
/* 重启设备 */
|
|
#define HGPDTTOOLDB_NAME_REBOOT_DEVICE L"REBOOT_DEVICE"
|
|
/* 扫描图像质量确认 */
|
|
#define HGPDTTOOLDB_NAME_IMAGE_QUALITY L"IMAGE_QUALITY"
|
|
/* 色卡纸成像质量评估 */
|
|
#define HGPDTTOOLDB_NAME_COLORCARD_IMAGEING_QUALITY L"COLORCARD_IMAGEING_QUALITY"
|
|
/* 色卡纸偏色成像质量评估 */
|
|
#define HGPDTTOOLDB_NAME_COLORCARD_BIAS_IMAGEING_QUALITY L"COLORCARD_BIAS_IMAGEING_QUALITY"
|
|
/* 清晰度质量评估 */
|
|
#define HGPDTTOOLDB_NAME_CLARITY_QUALITY L"CLARITY_QUALITY"
|
|
/* 获取畸变修正值 */
|
|
#define HGPDTTOOLDB_NAME_GET_DISTORTION_VAL L"GET_DISTORTION_VAL"
|
|
/* 设置畸变修正值 */
|
|
#define HGPDTTOOLDB_NAME_SET_DISTORTION_VAL L"SET_DISTORTION_VAL"
|
|
/* 设置休眠 */
|
|
#define HGPDTTOOLDB_NAME_DORMANCY L"DORMANCY"
|
|
/* 歪斜挡位检测 */
|
|
#define HGPDTTOOLDB_NAME_SKEW_GEAR L"SKEW_GEAR"
|
|
/* 分纸强度检测 */
|
|
#define HGPDTTOOLDB_NAME_PAPER_SEPARATION_STRENGTH L"PAPER_SEPARATION_STRENGTH"
|
|
/* 机械走纸倾斜检测 */
|
|
#define HGPDTTOOLDB_NAME_MECH_PAPER_FEEDING_INCLINATION L"MECH_PAPER_FEEDING_INCLINATION"
|
|
/* 单张测试 */
|
|
#define HGPDTTOOLDB_NAME_SINGLE_PAGE_TEST L"SINGLE_PAGE_TEST"
|
|
/* 压力测试2轮 */
|
|
#define HGPDTTOOLDB_NAME_PRESSUER_TEST L"PRESSUER_TEST"
|
|
/* 清除滚轴计数 */
|
|
#define HGPDTTOOLDB_NAME_CLEAR_ROLLER_COUNT L"CLEAR_ROLLER_COUNT"
|
|
/*压力测试彩色+200dpi*/
|
|
#define HGPDTTOOLDB_NAME_PRESSUER_TEST_RGB_200DPI L"PRESSUER_TEST_RGB_200DPI"
|
|
/*压力测试灰色+200dpi*/
|
|
#define HGPDTTOOLDB_NAME_PRESSUER_TEST_GRAY_200DPI L"PRESSUER_TEST_GRAY_200DPI"
|
|
/*压力测试彩色+300dpi*/
|
|
#define HGPDTTOOLDB_NAME_PRESSUER_TEST_RGB_300DPI L"PRESSUER_TEST_RGB_300DPI"
|
|
/*压力测试灰色+300dpi*/
|
|
#define HGPDTTOOLDB_NAME_PRESSUER_TEST_GRAY_300DPI L"PRESSUER_TEST_GRAY_300DPI"
|
|
|
|
#define TEST_DLL
|
|
#ifdef TEST_DLL
|
|
#define DECL_API(ret) __declspec(dllexport) ret __stdcall
|
|
#else
|
|
#define DECL_API(ret) __declspec(dllimport) ret __stdcall
|
|
#endif
|
|
|
|
// Function: initialize module
|
|
DECL_API(int) func_test_init(void*);
|
|
|
|
// Function: to get testing function list supported by this module/DLL
|
|
//
|
|
// Parameter: buf - to receive the list JSON
|
|
//
|
|
// len - [in] space of 'buf' in words, [out] words copied in buf, or less buffer size in words if return ERROR_INSUFFICIENT_BUFFER
|
|
//
|
|
// Return: ERROR_SUCCESS - JSON configuration has copied into buf
|
|
// ERROR_INSUFFICIENT_BUFFER - buffer is too small, and the minium size in words is stored in 'len'
|
|
// ERROR_INVALID_PARAMETER - NULL for parameter 'len' is not acceptable
|
|
DECL_API(int) func_test_get_list(wchar_t* buf // to receive the JSON text
|
|
, size_t* len); // [in] space of 'buf' in words, [out] words copied in buf, or less buffer size in words if return ERROR_INSUFFICIENT_BUFFER
|
|
|
|
|
|
enum write_cat
|
|
{
|
|
WRITE_CAT_VID_PID = 0, // val = (int*)
|
|
WRITE_CAT_SPEED, // val = (int*)
|
|
WRITE_CAT_SLEEP, // val = (int*)
|
|
WRITE_CAT_SERIALNUM // val = (char*)
|
|
};
|
|
|
|
typedef struct _write_cfg
|
|
{
|
|
enum write_cat cat;
|
|
void* val;
|
|
}WRITECFG, *LPWRITECFG;
|
|
// Function: do ONE function test
|
|
//
|
|
// Parameter: name - function name. "write-cfg" for write predefined configuration, oper is LPWRITECFG
|
|
//
|
|
// oper - test operation, "start", "pause", "resume", "stop", ...
|
|
//
|
|
// helper - parameter and testing process callback
|
|
//
|
|
// Return: error code
|
|
DECL_API(int) func_test_go(const wchar_t* name // test name
|
|
, const wchar_t* oper // test oper - "start", "pause", "resume", "stop", ...
|
|
, ui_helper* helper);
|
|
|
|
// Function: uninitialize module
|
|
DECL_API(int) func_test_uninit(void*);
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
|
/*/ testing-DLL load code ...
|
|
#include <vector>
|
|
#include <string>
|
|
#include <algorithm>
|
|
#include <Windows.h>
|
|
|
|
class json : public ref
|
|
{
|
|
public:
|
|
json();
|
|
|
|
protected:
|
|
~json();
|
|
|
|
public:
|
|
bool attach(const wchar_t* text);
|
|
bool get_value(const wchar_t* key, int& val);
|
|
bool get_value(const wchar_t* key, std::wstring& val);
|
|
bool get_value(const wchar_t* key, json*& val);
|
|
};
|
|
|
|
class test_factory
|
|
{
|
|
typedef struct _test_func
|
|
{
|
|
std::wstring name;
|
|
int ver;
|
|
int(__stdcall* test_api)(const wchar_t*, const wchar_t*, ui_helper*);
|
|
|
|
struct _test_func()
|
|
{
|
|
name = L"";
|
|
ver = 0;
|
|
test_api = NULL;
|
|
}
|
|
bool operator==(const wchar_t* n)
|
|
{
|
|
return name == n;
|
|
}
|
|
}TESTFUNC, *LPTESTFUNC;
|
|
std::vector<TESTFUNC> test_;
|
|
|
|
void add_api(const wchar_t* name, int ver, int(__stdcall* test_api)(const wchar_t*, const wchar_t*, ui_helper*))
|
|
{
|
|
std::vector<TESTFUNC>::iterator it = std::find(test_.begin(), test_.end(), name);
|
|
|
|
if (it == test_.end())
|
|
{
|
|
TESTFUNC tf;
|
|
|
|
tf.name = name;
|
|
tf.ver = ver;
|
|
tf.test_api = test_api;
|
|
test_.push_back(tf);
|
|
}
|
|
else if (ver > it->ver)
|
|
{
|
|
it->test_api = test_api;
|
|
it->ver = ver;
|
|
}
|
|
}
|
|
void load_test_dll(const wchar_t* path_dll)
|
|
{
|
|
HMODULE mod = LoadLibraryW(path_dll);
|
|
int(__stdcall * init)(void*) = NULL;
|
|
int(__stdcall * get)(void*, size_t*) = NULL;
|
|
int(__stdcall * go)(const wchar_t*, const wchar_t*, ui_helper*) = NULL;
|
|
FARPROC* api = (FARPROC*)&init;
|
|
wchar_t* buf = NULL;
|
|
size_t len = 0;
|
|
json* root = NULL, * child = NULL;
|
|
|
|
if (!mod)
|
|
return;
|
|
|
|
*api = GetProcAddress(mod, "func_test_init");
|
|
if (!api)
|
|
{
|
|
FreeLibrary(mod);
|
|
return;
|
|
}
|
|
init(NULL);
|
|
|
|
api = (FARPROC*)&get;
|
|
*api = GetProcAddress(mod, "func_test_get_list");
|
|
if(!api)
|
|
{
|
|
FreeLibrary(mod);
|
|
return;
|
|
}
|
|
|
|
api = (FARPROC*)&go;
|
|
*api = GetProcAddress(mod, "func_test_go");
|
|
if (!api)
|
|
{
|
|
FreeLibrary(mod);
|
|
return;
|
|
}
|
|
|
|
if(get(buf, &len) != ERROR_INSUFFICIENT_BUFFER)
|
|
{
|
|
FreeLibrary(mod);
|
|
return;
|
|
}
|
|
|
|
buf = new wchar_t[len + 8];
|
|
memset(buf, 0, (len + 8) * 2);
|
|
if (get(buf, &len))
|
|
{
|
|
delete[] buf;
|
|
FreeLibrary(mod);
|
|
return;
|
|
}
|
|
|
|
// parse json ...
|
|
len = 0;
|
|
root = new json();
|
|
if (root->attach(buf))
|
|
{
|
|
for (int i = 1; 1; ++i)
|
|
{
|
|
swprintf_s(buf, 20, L"%d", i);
|
|
if (!root->get_value(buf, child) || !child)
|
|
break;
|
|
|
|
std::wstring name(L"");
|
|
int ver = 0;
|
|
if (child->get_value(L"name", name) && child->get_value(L"ver", ver))
|
|
{
|
|
add_api(name.c_str(), ver, go);
|
|
len++;
|
|
}
|
|
child->release();
|
|
}
|
|
}
|
|
|
|
root->release();
|
|
delete[] buf;
|
|
if (len == 0)
|
|
FreeLibrary(mod);
|
|
}
|
|
void init(void)
|
|
{
|
|
wchar_t path[MAX_PATH] = { 0 };
|
|
std::wstring dir(L"");
|
|
size_t pos = 0;
|
|
HANDLE hf = INVALID_HANDLE_VALUE;
|
|
WIN32_FIND_DATAW fd = { 0 };
|
|
|
|
GetModuleFileNameW(NULL, path, _countof(path) - 1);
|
|
dir = pos;
|
|
pos = dir.rfind(L'\\');
|
|
if (pos++ == std::wstring::npos)
|
|
return;
|
|
|
|
dir.erase(pos);
|
|
dir += L"dlls\\";
|
|
hf = FindFirstFileW((dir + L"*.dll").c_str(), &fd);
|
|
if (hf != INVALID_HANDLE_VALUE)
|
|
{
|
|
do
|
|
{
|
|
load_test_dll((dir + fd.cFileName).c_str());
|
|
} while (FindNextFileW(hf, &fd));
|
|
|
|
FindClose(hf);
|
|
}
|
|
}
|
|
|
|
public:
|
|
test_factory()
|
|
{
|
|
init();
|
|
}
|
|
~test_factory()
|
|
{
|
|
|
|
}
|
|
|
|
public:
|
|
bool is_test_available(const wchar_t* name) // check if the test item with name 'name' is supported
|
|
{
|
|
std::vector<TESTFUNC>::iterator it = std::find(test_.begin(), test_.end(), name);
|
|
|
|
return it != test_.end();
|
|
}
|
|
int test(const wchar_t* name, ui_helper* ui, const wchar_t* oper = L"start")
|
|
{
|
|
std::vector<TESTFUNC>::iterator it = std::find(test_.begin(), test_.end(), name);
|
|
|
|
if (it == test_.end())
|
|
return ERROR_NOT_SUPPORTED;
|
|
|
|
return it->test_api(name, oper, ui);
|
|
}
|
|
};
|
|
/////////////////////////*////////////////////////////////////////////////////////////////////////
|