HGGitLab

Commit f9fd7fa7 authored by luoliangyi's avatar luoliangyi

websdk,完善设置和获取设备配置的功能

parent 13583d6b
......@@ -257,6 +257,8 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
devParam.single = GetJsonBoolValue(json, "single");
devParam.format = GetJsonStringValue(json, "format");
devParam.resolution = GetJsonIntValue(json, "resolution");
if (0 == devParam.resolution)
devParam.resolution = atoi(GetJsonStringValue(json, "resolution").c_str());
devParam.orentation = GetJsonIntValue(json, "orentation");
devParam.paperType = GetJsonStringValue(json, "paperType");
devParam.splitImage = GetJsonIntValue(json, "splitImage");
......
#include "Manager.h"
#include "Manager.h"
#include "MsgLoop.h"
#include "../../base/HGBuffer.h"
#include "../../base/HGBase64.h"
......@@ -62,6 +62,131 @@ static std::string StdStringToUtf8(const char* str)
#endif
}
static void TrimString(std::string& str)
{
int s = (int)str.find_first_not_of(" ");
int e = (int)str.find_last_not_of(" ");
str = str.substr(s, e - s + 1);
}
DevParam::DevParam()
{
Reset();
}
DevParam::~DevParam()
{
}
void DevParam::Reset()
{
autofeeder = true;
pixel = 1;
white = false;
discardBlankThre = 5;
single = false;
format = "jpg";
resolution = 200;
orentation = 0;
paperType = "Auto";
splitImage = 0;
noiseDetachEnable = true;
noiseDetach = 15;
uploadMode = 2;
ftpPort = 21;
ftpMode = 2;
}
void DevParam::Load(const std::string& cfgPath)
{
HGInt intValue;
HGChar strValue[256];
HGBase_GetProfileString(cfgPath.c_str(), "devParam", "device", "", strValue, 256);
device = strValue;
HGBase_GetProfileInt(cfgPath.c_str(), "devParam", "autofeeder", 1, &intValue);
autofeeder = (bool)intValue;
HGBase_GetProfileInt(cfgPath.c_str(), "devParam", "pixel", 1, &intValue);
pixel = intValue;
HGBase_GetProfileInt(cfgPath.c_str(), "devParam", "white", 0, &intValue);
white = (bool)intValue;
HGBase_GetProfileInt(cfgPath.c_str(), "devParam", "discardBlankThre", 5, &intValue);
discardBlankThre = intValue;
HGBase_GetProfileInt(cfgPath.c_str(), "devParam", "single", 0, &intValue);
single = (bool)intValue;
HGBase_GetProfileString(cfgPath.c_str(), "devParam", "format", "jpg", strValue, 256);
format = strValue;
HGBase_GetProfileInt(cfgPath.c_str(), "devParam", "resolution", 200, &intValue);
resolution = intValue;
HGBase_GetProfileInt(cfgPath.c_str(), "devParam", "orentation", 0, &intValue);
orentation = intValue;
HGBase_GetProfileString(cfgPath.c_str(), "devParam", "paperType", "Auto", strValue, 256);
paperType = strValue;
HGBase_GetProfileInt(cfgPath.c_str(), "devParam", "splitImage", 0, &intValue);
splitImage = intValue;
HGBase_GetProfileInt(cfgPath.c_str(), "devParam", "noiseDetachEnable”", 1, &intValue);
noiseDetachEnable = (bool)intValue;
HGBase_GetProfileInt(cfgPath.c_str(), "devParam", "noiseDetach", 15, &intValue);
noiseDetach = intValue;
HGBase_GetProfileInt(cfgPath.c_str(), "devParam", "uploadMode", 2, &intValue);
uploadMode = intValue;
HGBase_GetProfileString(cfgPath.c_str(), "devParam", "httpUrl", "", strValue, 256);
httpUrl = strValue;
HGBase_GetProfileString(cfgPath.c_str(), "devParam", "fileName", "", strValue, 256);
fileName = strValue;
HGBase_GetProfileString(cfgPath.c_str(), "devParam", "httpMethod", "", strValue, 256);
httpMethod = strValue;
HGBase_GetProfileString(cfgPath.c_str(), "devParam", "header", "", strValue, 256);
header = strValue;
HGBase_GetProfileString(cfgPath.c_str(), "devParam", "param", "", strValue, 256);
param = strValue;
HGBase_GetProfileString(cfgPath.c_str(), "devParam", "ftpUrl", "", strValue, 256);
ftpUrl = strValue;
HGBase_GetProfileString(cfgPath.c_str(), "devParam", "ftpPath", "", strValue, 256);
ftpPath = strValue;
HGBase_GetProfileString(cfgPath.c_str(), "devParam", "ftpUser", "", strValue, 256);
ftpUser = strValue;
HGBase_GetProfileString(cfgPath.c_str(), "devParam", "ftpPassword", "", strValue, 256);
ftpPassword = strValue;
HGBase_GetProfileInt(cfgPath.c_str(), "devParam", "ftpPort", 21, &intValue);
ftpPort = intValue;
HGBase_GetProfileInt(cfgPath.c_str(), "devParam", "ftpMode", 2, &intValue);
ftpMode = intValue;
}
void DevParam::Save(const std::string& cfgPath)
{
HGBase_SetProfileString(cfgPath.c_str(), "devParam", "device", device.c_str());
HGBase_SetProfileInt(cfgPath.c_str(), "devParam", "autofeeder", autofeeder);
HGBase_SetProfileInt(cfgPath.c_str(), "devParam", "pixel", pixel);
HGBase_SetProfileInt(cfgPath.c_str(), "devParam", "white", white);
HGBase_SetProfileInt(cfgPath.c_str(), "devParam", "discardBlankThre", discardBlankThre);
HGBase_SetProfileInt(cfgPath.c_str(), "devParam", "single", single);
HGBase_SetProfileString(cfgPath.c_str(), "devParam", "format", format.c_str());
HGBase_SetProfileInt(cfgPath.c_str(), "devParam", "resolution", resolution);
HGBase_SetProfileInt(cfgPath.c_str(), "devParam", "orentation", orentation);
HGBase_SetProfileString(cfgPath.c_str(), "devParam", "paperType", paperType.c_str());
HGBase_SetProfileInt(cfgPath.c_str(), "devParam", "splitImage", splitImage);
HGBase_SetProfileInt(cfgPath.c_str(), "devParam", "noiseDetachEnable", noiseDetachEnable);
HGBase_SetProfileInt(cfgPath.c_str(), "devParam", "noiseDetach", noiseDetach);
HGBase_SetProfileInt(cfgPath.c_str(), "devParam", "uploadMode", uploadMode);
HGBase_SetProfileString(cfgPath.c_str(), "devParam", "httpUrl", httpUrl.c_str());
HGBase_SetProfileString(cfgPath.c_str(), "devParam", "fileName", fileName.c_str());
HGBase_SetProfileString(cfgPath.c_str(), "devParam", "httpMethod", httpMethod.c_str());
HGBase_SetProfileString(cfgPath.c_str(), "devParam", "header", header.c_str());
HGBase_SetProfileString(cfgPath.c_str(), "devParam", "param", param.c_str());
HGBase_SetProfileString(cfgPath.c_str(), "devParam", "ftpUrl", ftpUrl.c_str());
HGBase_SetProfileString(cfgPath.c_str(), "devParam", "ftpPath", ftpPath.c_str());
HGBase_SetProfileString(cfgPath.c_str(), "devParam", "ftpUser", ftpUser.c_str());
HGBase_SetProfileString(cfgPath.c_str(), "devParam", "ftpPassword", ftpPassword.c_str());
HGBase_SetProfileInt(cfgPath.c_str(), "devParam", "ftpPort", ftpPort);
HGBase_SetProfileInt(cfgPath.c_str(), "devParam", "ftpMode", ftpMode);
}
Manager::Manager(class MsgLoop* loop)
{
m_loop = loop;
......@@ -85,6 +210,7 @@ Manager::~Manager()
{
StopScan();
m_devParam.Reset();
sane_close(m_devHandle);
m_devHandle = NULL;
m_devName.clear();
......@@ -100,12 +226,19 @@ void Manager::OpenDev(const OpenDevParam* param)
return;
}
bool ret = false;
SANE_Status status = sane_open(param->devName.c_str(), &m_devHandle);
SANE_Handle devHandle = NULL;
SANE_Status status = sane_open(param->devName.c_str(), &devHandle);
if (SANE_STATUS_GOOD == status)
{
assert(NULL != m_devHandle);
assert(NULL != devHandle);
m_devName = param->devName;
m_devHandle = devHandle;
std::string filePath = GetFilePath(m_devName);
std::string cfgPath = filePath + "config.ini";
m_devParam.Load(cfgPath);
SetDevParam(m_devName, m_devParam);
}
}
......@@ -120,6 +253,7 @@ void Manager::CloseDev(const CloseDevParam* param)
StopScan();
m_devParam.Reset();
sane_close(m_devHandle);
m_devHandle = NULL;
m_devName.clear();
......@@ -231,12 +365,232 @@ bool Manager::GetImageByDevId(const std::string& devId, std::vector<std::string>
bool Manager::GetDevParam(const std::string& devId, DevParam& devParam)
{
return true;
bool ret = false;
if (NULL != m_devHandle)
{
m_devParam.device = m_devName;
// 从设备获取到m_devParam
SANE_Int num_dev_options = 0;
sane_control_option(m_devHandle, 0, SANE_ACTION_GET_VALUE, &num_dev_options, NULL);
for (int i = 1; i < num_dev_options; ++i)
{
const SANE_Option_Descriptor* desp = sane_get_option_descriptor(m_devHandle, i);
if (NULL == desp)
continue;
std::string title = Utf8ToStdString(desp->title);
TrimString(title);
HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "title=%s", title.c_str());
if (SANE_TYPE_BOOL == desp->type)
{
SANE_Bool value = 0;
sane_control_option(m_devHandle, i, SANE_ACTION_GET_VALUE, &value, NULL);
HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, " valueType=BOOL, value=%s", value ? "TRUE" : "FALSE");
if (0 == strcmp(title.c_str(), "图像拆分"))
m_devParam.splitImage = value ? 1 : 0;
else if (0 == strcmp(title.c_str(), "黑白图像噪点优化"))
m_devParam.noiseDetachEnable = (bool)value;
}
else if (SANE_TYPE_INT == desp->type)
{
SANE_Int value = 0;
sane_control_option(m_devHandle, i, SANE_ACTION_GET_VALUE, &value, NULL);
HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, " valueType=INT, value=%d", value);
if (0 == strcmp(title.c_str(), "跳过空白页灵敏度"))
m_devParam.discardBlankThre = value;
else if (0 == strcmp(title.c_str(), "分辨率"))
m_devParam.resolution = value;
}
else if (SANE_TYPE_FIXED == desp->type)
{
HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, " valueType=FIXED");
}
else if (SANE_TYPE_STRING == desp->type)
{
char value[256] = {0};
sane_control_option(m_devHandle, i, SANE_ACTION_GET_VALUE, value, NULL);
std::string stdValue = Utf8ToStdString(value);
TrimString(stdValue);
HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, " valueType=STRING, value=%s", stdValue.c_str());
if (0 == strcmp("颜色模式", title.c_str()) && 0 == strcmp("24位彩色", stdValue.c_str()))
m_devParam.pixel = 2;
else if (0 == strcmp("颜色模式", title.c_str()) && 0 == strcmp("256级灰度", stdValue.c_str()))
m_devParam.pixel = 1;
else if (0 == strcmp("颜色模式", title.c_str()) && 0 == strcmp("黑白", stdValue.c_str()))
m_devParam.pixel = 0;
else if (0 == strcmp("扫描页面", title.c_str()) && 0 == strcmp("双面", stdValue.c_str()))
{
m_devParam.white = false;
m_devParam.single = false;
}
else if (0 == strcmp("扫描页面", title.c_str()) && 0 == strcmp("单面", stdValue.c_str()))
{
m_devParam.white = false;
m_devParam.single = true;
}
else if (0 == strcmp("扫描页面", title.c_str()) && NULL != strstr(stdValue.c_str(), "跳过空白页"))
{
m_devParam.white = true;
m_devParam.single = false;
}
else if (0 == strcmp("文稿方向", title.c_str()) && 0 == strcmp("0°", stdValue.c_str()))
m_devParam.orentation = 0;
else if (0 == strcmp("文稿方向", title.c_str()) && 0 == strcmp("90°", stdValue.c_str()))
m_devParam.orentation = 1;
else if (0 == strcmp("文稿方向", title.c_str()) && 0 == strcmp("180°", stdValue.c_str()))
m_devParam.orentation = 2;
else if (0 == strcmp("文稿方向", title.c_str()) && 0 == strcmp("-90°", stdValue.c_str()))
m_devParam.orentation = 3;
else if (0 == strcmp("纸张尺寸", title.c_str()) && 0 == strcmp("匹配原始尺寸", stdValue.c_str()))
m_devParam.paperType = "Auto";
else if (0 == strcmp("纸张尺寸", title.c_str()) && 0 == strcmp("A3", stdValue.c_str()))
m_devParam.paperType = "A3";
else if (0 == strcmp("纸张尺寸", title.c_str()) && 0 == strcmp("A4", stdValue.c_str()))
m_devParam.paperType = "A4";
}
else if (SANE_TYPE_BUTTON == desp->type)
{
HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, " valueType=BUTTON");
}
else if (SANE_TYPE_GROUP == desp->type)
{
HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, " valueType=GROUP");
}
}
std::string filePath = GetFilePath(m_devName);
std::string cfgPath = filePath + "config.ini";
m_devParam.Save(cfgPath);
ret = true;
}
devParam = m_devParam;
return ret;
}
bool Manager::SetDevParam(const std::string& devId, const DevParam& devParam)
{
return true;
m_devParam = devParam;
std::string filePath = GetFilePath(m_devName);
std::string cfgPath = filePath + "config.ini";
m_devParam.Save(cfgPath);
bool ret = false;
if (NULL != m_devHandle)
{
// 设置m_devParam到设备
SANE_Int num_dev_options = 0;
sane_control_option(m_devHandle, 0, SANE_ACTION_GET_VALUE, &num_dev_options, NULL);
for (int i = 1; i < num_dev_options; ++i)
{
const SANE_Option_Descriptor* desp = sane_get_option_descriptor(m_devHandle, i);
if (NULL == desp)
continue;
std::string title = Utf8ToStdString(desp->title);
TrimString(title);
if (SANE_TYPE_BOOL == desp->type)
{
if (0 == strcmp(title.c_str(), "图像拆分"))
{
SANE_Bool value = SANE_FALSE;
if (0 != m_devParam.splitImage)
value = SANE_TRUE;
sane_control_option(m_devHandle, i, SANE_ACTION_SET_VALUE, &value, NULL);
}
else if (0 == strcmp(title.c_str(), "黑白图像噪点优化"))
{
SANE_Bool value = SANE_FALSE;
if (m_devParam.noiseDetachEnable)
value = SANE_TRUE;
sane_control_option(m_devHandle, i, SANE_ACTION_SET_VALUE, &value, NULL);
}
}
else if (SANE_TYPE_INT == desp->type)
{
if (0 == strcmp(title.c_str(), "跳过空白页灵敏度"))
{
SANE_Int value = m_devParam.discardBlankThre;
sane_control_option(m_devHandle, i, SANE_ACTION_SET_VALUE, &value, NULL);
}
else if (0 == strcmp(title.c_str(), "分辨率"))
{
SANE_Int value = m_devParam.resolution;
sane_control_option(m_devHandle, i, SANE_ACTION_SET_VALUE, &value, NULL);
}
}
else if (SANE_TYPE_FIXED == desp->type)
{
}
else if (SANE_TYPE_STRING == desp->type)
{
if (0 == strcmp("颜色模式", title.c_str()))
{
char value[256] = { 0 };
strcpy(value, "24位彩色");
if (1 == m_devParam.pixel)
strcpy(value, "256级灰度");
else if (0 == m_devParam.pixel)
strcpy(value, "黑白");
sane_control_option(m_devHandle, i, SANE_ACTION_SET_VALUE, (void *)(StdStringToUtf8(value).c_str()), NULL);
}
else if (0 == strcmp("扫描页面", title.c_str()))
{
char value[256] = { 0 };
strcpy(value, "双面");
if (!m_devParam.white && m_devParam.single)
strcpy(value, "单面");
else if (m_devParam.white && !m_devParam.single)
strcpy(value, "跳过空白页");
sane_control_option(m_devHandle, i, SANE_ACTION_SET_VALUE, (void*)(StdStringToUtf8(value).c_str()), NULL);
}
else if (0 == strcmp("文稿方向", title.c_str()))
{
char value[256] = { 0 };
strcpy(value, "0°");
if (1 == m_devParam.orentation)
strcpy(value, "90°");
else if (2 == m_devParam.orentation)
strcpy(value, "180°");
else if (3 == m_devParam.orentation)
strcpy(value, "-90°");
sane_control_option(m_devHandle, i, SANE_ACTION_SET_VALUE, (void*)(StdStringToUtf8(value).c_str()), NULL);
}
else if (0 == strcmp("纸张尺寸", title.c_str()))
{
char value[256] = { 0 };
strcpy(value, "匹配原始尺寸");
if ("A3" == m_devParam.paperType)
strcpy(value, "A3");
else if ("A4" == m_devParam.paperType)
strcpy(value, "A4");
sane_control_option(m_devHandle, i, SANE_ACTION_SET_VALUE, (void*)(StdStringToUtf8(value).c_str()), NULL);
}
}
else if (SANE_TYPE_BUTTON == desp->type)
{
}
else if (SANE_TYPE_GROUP == desp->type)
{
}
}
ret = true;
}
return ret;
}
bool Manager::ExportOfdFile(HGByte** data, HGUInt* size)
......@@ -456,6 +810,7 @@ bool Manager::ExportZipFile(HGByte** data, HGUInt* size)
bool Manager::UploadImage(const UploadParam& uploadParam)
{
// 打包并上传
return true;
}
......
......@@ -18,25 +18,12 @@
struct DevParam
{
DevParam()
{
autofeeder = true;
pixel = 1;
white = false;
discardBlankThre = 5;
single = false;
format = "jpg";
resolution = 200;
orentation = 0;
paperType = "Auto";
splitImage = 0;
noiseDetachEnable = true;
noiseDetach = 15;
DevParam();
~DevParam();
uploadMode = 2;
ftpPort = 21;
ftpMode = 2;
}
void Reset();
void Load(const std::string& cfgPath);
void Save(const std::string& cfgPath);
std::string device; // 设备名称,默认null
bool autofeeder; // 自动进纸,默认true
......@@ -45,7 +32,7 @@ struct DevParam
int discardBlankThre; // 跳过空白页阈值 1­-100 默认值5
bool single; // 单页扫描,默认false
std::string format; // 输出格式 jpg png bmp tiff pdf ofd,默认jpg
int resolution; // 扫描分辨率 范围 100­600 默认值200
int resolution; // 扫描分辨率 范围 100­-600 默认值200
int orentation; // 图片旋转 0:原图 90:度 180:旋转180度 270:旋转270度,默认0
std::string paperType; // 扫描幅面 A3:A3幅面 Auto:自适应幅面 A4:A4幅面,默认Auto
int splitImage; // 图像分割 0:disable 1:垂直分割 2: 水平分割,默认0
......@@ -168,6 +155,7 @@ private:
class MsgLoop* m_loop;
std::string m_devName;
SANE_Handle m_devHandle;
DevParam m_devParam;
std::string m_scanInsertImgName;
bool m_scanIsInsert;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment