code_production/code/base/test_base.h

415 lines
13 KiB
C
Raw Normal View History

2022-12-08 10:10:19 +00:00
#pragma once
#include "string"
#include "sane/sane_ex.h"
2022-12-15 02:54:09 +00:00
#include "ui_helper.h"
2022-12-15 06:05:53 +00:00
#include <Windows.h>
2022-12-31 09:02:23 +00:00
2022-12-08 10:10:19 +00:00
//////////////////////////////////////TITLE//////////////////////////////////////
2023-01-03 03:12:53 +00:00
2022-12-08 10:10:19 +00:00
/* 拨码开关校验 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_TITLE_DIAL_SWITCH L"拨码开关校验"
2022-12-08 10:10:19 +00:00
/* 检查船型开关功能 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_TITLE_ROCKER_SWITCH L"检查船型开关功能"
2022-12-08 10:10:19 +00:00
/* 设备上电并观察开机状态 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_TITLE_BOOT_STATUS L"设备上电并观察开机状态"
2022-12-08 10:10:19 +00:00
/* 检查液晶显示 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_TITLE_LCD_DISPLAY L"检查液晶显示"
2022-12-08 10:10:19 +00:00
/* 清理纸道功能确认 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_TITLE_CLEAR_PAPER_PATH L"清理纸道功能确认" //1
2022-12-08 10:10:19 +00:00
/* 按键功能检测 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_TITLE_KEY_FUNCTION L"按键功能检测"
2022-12-08 10:10:19 +00:00
/* 计数模式检测 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_TITLE_COUNTING_MODE L"计数模式检测"//1
2022-12-08 10:10:19 +00:00
/* 歪斜检测 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_TITLE_SKEW_DETECTION L"歪斜检测"//1
2022-12-08 10:10:19 +00:00
/* 分纸电机检测 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_TITLE_SEPARATER_MOTOR L"分纸电机检测"
2022-12-08 10:10:19 +00:00
/* CIS原图初检 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_TITLE_CIS_ORIGINAL_IMAGE L"CIS原图初检"
2022-12-08 10:10:19 +00:00
/* 主机风扇功能检测 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_TITLE_HOST_FAN L"主机风扇功能检测"
2022-12-08 10:10:19 +00:00
/* 超声波模块检验 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_TITLE_ULTRASONIC_MODULE L"超声波模块检验"
2022-12-08 10:10:19 +00:00
/* LED灯状态检查 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_TITLE_LED_LIGHT L"LED灯状态检查"
2022-12-08 10:10:19 +00:00
/* 复位检查 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_TITLE_RESET L"复位检查"
2022-12-08 10:10:19 +00:00
/* 走纸检查 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_TITLE_PAPER_FEED L"走纸检查"
2022-12-08 10:10:19 +00:00
/* 开盖传感器检查 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_TITLE_COVER_SENSOR L"开盖传感器检查"
2022-12-08 10:10:19 +00:00
/* 扫描传感器检查 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_TITLE_SCANNING_SENSOR L"扫描传感器检查"
2022-12-08 10:10:19 +00:00
/* 配置速度模式 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_TITLE_CONFIGURE_SPEED_MODE L"配置速度模式"
2022-12-08 10:10:19 +00:00
/* 放置校正纸 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_TITLE_PLACE_CORRECTION_PAPER L"放置校正纸"
2022-12-08 10:10:19 +00:00
/* 自动平场校正 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_TITLE_AUTO_FLAT_FIELD L"自动平场校正"
2022-12-08 10:10:19 +00:00
/* 重启设备 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_TITLE_REBOOT_DEVICE L"重启设备"
2022-12-08 10:10:19 +00:00
/* 扫描图像质量确认 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_TITLE_IMAGE_QUALITY L"扫描图像质量确认"
2022-12-08 10:10:19 +00:00
/* 色卡纸成像质量评估 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_TITLE_COLORCARD_IMAGEING_QUALITY L"色卡纸成像质量评估"
2022-12-08 10:10:19 +00:00
/* 色卡纸偏色成像质量评估 */
#define HGPDTTOOLDB_TITLE_COLORCARD_BIAS_IMAGEING_QUALITY L"色卡纸偏色成像质量评估"
/* 清晰度质量评估 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_TITLE_CLARITY_QUALITY L"清晰度质量评估"
2022-12-08 10:10:19 +00:00
/* 畸变修正 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_TITLE_DISTORTION L"畸变修正"
2022-12-08 10:10:19 +00:00
/* 设置休眠 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_TITLE_DORMANCY L"设置休眠"
2022-12-08 10:10:19 +00:00
/* 歪斜挡位检测 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_TITLE_SKEW_GEAR L"歪斜挡位检测"
2022-12-08 10:10:19 +00:00
/* 分纸强度检测 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_TITLE_PAPER_SEPARATION_STRENGTH L"分纸强度检测"
2022-12-08 10:10:19 +00:00
/* 机械走纸倾斜检测 */
#define HGPDTTOOLDB_TITLE_MECH_PAPER_FEEDING_INCLINATION L"机械走纸倾斜检测"
/* 单张测试1 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_TITLE_SINGLE_PAGE_TEST_1 L"单张测试"
2022-12-08 10:10:19 +00:00
/* 清除滚轴计数 */
2022-12-31 09:02:23 +00:00
#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"
2022-12-08 10:10:19 +00:00
//////////////////////////////////////NAME//////////////////////////////////////
2023-01-03 03:12:53 +00:00
#define WRITE_CFG_NAME L"write-cfg"
2023-01-05 09:46:52 +00:00
/* 设置json序列号 */
#define HGPDTTOOLDB_NAME_SET_JSON_SN L"SET_JSON_SN"
2022-12-08 10:10:19 +00:00
/* 拨码开关校验 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_NAME_DIAL_SWITCH L"DIAL_SWITCH"
2022-12-08 10:10:19 +00:00
/* 检查船型开关功能 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_NAME_ROCKER_SWITCH L"ROCKER_SWITCH"
2022-12-08 10:10:19 +00:00
/* 设备上电并观察开机状态 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_NAME_BOOT_STATUS L"BOOT_STATUS"
2022-12-08 10:10:19 +00:00
/* 检查液晶显示 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_NAME_LCD_DISPLAY L"LCD_DISPLAY"
2022-12-08 10:10:19 +00:00
/* 清理纸道功能确认 */
2023-01-03 03:12:53 +00:00
#define HGPDTTOOLDB_NAME_CLEAR_PAPER_PATH L"PAPER_PATH"
2022-12-08 10:10:19 +00:00
/* 按键功能检测 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_NAME_KEY_FUNCTION L"KEY_FUNCTION"
2022-12-08 10:10:19 +00:00
/* 计数模式检测 */
2023-01-03 03:12:53 +00:00
#define HGPDTTOOLDB_NAME_COUNTING_MODE L"COUNTING_MODE"
2022-12-08 10:10:19 +00:00
/* 歪斜检测 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_NAME_SKEW_DETECTION L"SKEW_DETECTION"
2022-12-08 10:10:19 +00:00
/* 分纸电机检测 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_NAME_SEPARATER_MOTOR L"SEPARATER_MOTOR"
2022-12-08 10:10:19 +00:00
/* CIS原图初检 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_NAME_CIS_ORIGINAL_IMAGE L"CIS_ORIGINAL_IMAGE"
2022-12-08 10:10:19 +00:00
/* 主机风扇功能检测 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_NAME_HOST_FAN L"HOST_FAN"
2022-12-08 10:10:19 +00:00
/* 超声波模块检验 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_NAME_ULTRASONIC_MODULE L"ULTRASONIC_MODULE"
2022-12-08 10:10:19 +00:00
/* LED灯状态检查 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_NAME_LED_LIGHT L"LED_LIGHT"
2022-12-08 10:10:19 +00:00
/* 复位检查 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_NAME_RESET L"RESET"
2022-12-08 10:10:19 +00:00
/* 走纸检查 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_NAME_PAPER_FEED L"PAPER_FEED"
2022-12-08 10:10:19 +00:00
/* 开盖传感器检查 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_NAME_COVER_SENSOR L"COVER_SENSOR"
2022-12-08 10:10:19 +00:00
/* 扫描传感器检查 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_NAME_SCANNING_SENSOR L"SCANNING_SENSOR"
2022-12-08 10:10:19 +00:00
/* 配置速度模式 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_NAME_CONFIGURE_SPEED_MODE L"CONFIGURE_SPEED_MODE"
2022-12-08 10:10:19 +00:00
/* 放置校正纸 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_NAME_PLACE_CORRECTION_PAPER L"PLACE_CORRECTION_PAPER"
2022-12-08 10:10:19 +00:00
/* 自动平场校正 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_NAME_AUTO_FLAT_FIELD L"AUTO_FLAT_FIELD"
2022-12-08 10:10:19 +00:00
/* 重启设备 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_NAME_REBOOT_DEVICE L"REBOOT_DEVICE"
2023-02-08 07:25:54 +00:00
/* 扫描图像彩色质量确认 */
#define HGPDTTOOLDB_NAME_IMAGE_COLOR_QUALITY L"IMAGE_COLOR_QUALITY"
/* 扫描图像灰度质量确认 */
#define HGPDTTOOLDB_NAME_IMAGE_GRAY_QUALITY L"IMAGE_GRAY_QUALITY"
2022-12-08 10:10:19 +00:00
/* 色卡纸成像质量评估 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_NAME_COLORCARD_IMAGEING_QUALITY L"COLORCARD_IMAGEING_QUALITY"
2022-12-08 10:10:19 +00:00
/* 色卡纸偏色成像质量评估 */
2022-12-30 09:13:18 +00:00
#define HGPDTTOOLDB_NAME_COLORCARD_BIAS_IMAGEING_QUALITY L"COLORCARD_BIAS_IMAGEING_QUALITY"
2022-12-08 10:10:19 +00:00
/* 清晰度质量评估 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_NAME_CLARITY_QUALITY L"CLARITY_QUALITY"
2023-01-05 09:46:52 +00:00
/* 获取畸变修正值 */
#define HGPDTTOOLDB_NAME_GET_DISTORTION_VAL L"GET_DISTORTION_VAL"
/* 设置畸变修正值 */
#define HGPDTTOOLDB_NAME_SET_DISTORTION_VAL L"SET_DISTORTION_VAL"
2022-12-08 10:10:19 +00:00
/* 设置休眠 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_NAME_DORMANCY L"DORMANCY"
2022-12-08 10:10:19 +00:00
/* 歪斜挡位检测 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_NAME_SKEW_GEAR L"SKEW_GEAR"
2022-12-08 10:10:19 +00:00
/* 分纸强度检测 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_NAME_PAPER_SEPARATION_STRENGTH L"PAPER_SEPARATION_STRENGTH"
2022-12-08 10:10:19 +00:00
/* 机械走纸倾斜检测 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_NAME_MECH_PAPER_FEEDING_INCLINATION L"MECH_PAPER_FEEDING_INCLINATION"
/* 单张测试 */
#define HGPDTTOOLDB_NAME_SINGLE_PAGE_TEST L"SINGLE_PAGE_TEST"
2022-12-08 10:10:19 +00:00
/* 压力测试2轮 */
2022-12-31 09:02:23 +00:00
#define HGPDTTOOLDB_NAME_PRESSUER_TEST L"PRESSUER_TEST"
2022-12-08 10:10:19 +00:00
/* 清除滚轴计数 */
2022-12-31 09:02:23 +00:00
#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"
2022-12-15 11:53:41 +00:00
2022-12-15 06:39:32 +00:00
#define TEST_DLL
2022-12-08 10:10:19 +00:00
#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
2022-12-31 09:02:23 +00:00
2022-12-30 06:34:20 +00:00
enum write_cat
{
2023-01-03 03:12:53 +00:00
WRITE_CAT_VID_PID = 0, // val = (int*)
2022-12-30 06:34:20 +00:00
WRITE_CAT_SPEED, // val = (int*)
WRITE_CAT_SLEEP, // val = (int*)
2022-12-30 06:39:49 +00:00
WRITE_CAT_SERIALNUM // val = (char*)
2022-12-30 06:34:20 +00:00
};
typedef struct _write_cfg
{
enum write_cat cat;
void* val;
}WRITECFG, *LPWRITECFG;
2022-12-08 10:10:19 +00:00
// Function: do ONE function test
//
2022-12-30 06:34:20 +00:00
// Parameter: name - function name. "write-cfg" for write predefined configuration, oper is LPWRITECFG
2022-12-08 10:10:19 +00:00
//
// 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);
}
};
2022-12-30 06:34:20 +00:00
/////////////////////////*////////////////////////////////////////////////////////////////////////