add minio
This commit is contained in:
parent
b8c16155b4
commit
41c692ee8b
@ -1,8 +1,11 @@
|
||||
cmake_minimum_required (VERSION 3.5.1)
|
||||
cmake_minimum_required (VERSION 3.20)
|
||||
project (application C CXX)
|
||||
set (VERSION 1.0.1)
|
||||
# 指定C++标准
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
|
||||
|
||||
option (USE_MQTT "use mqtt protocol" ON)
|
||||
option (USE_MQTT "use mqtt protocol" OFF)
|
||||
option (USE_WEBSOCKET "use websocket" ON)
|
||||
option (USE_SQLITE3 "use sqlite3" ON)
|
||||
|
||||
@ -48,6 +51,9 @@ if (HAVE_FTP_PROCESS)
|
||||
set (APP_LIBS ${APP_LIBS} curl)
|
||||
endif ()
|
||||
|
||||
find_package(miniocpp REQUIRED)
|
||||
target_link_libraries(application PRIVATE miniocpp::miniocpp)
|
||||
|
||||
include_directories (
|
||||
inc
|
||||
inc/json
|
||||
@ -77,6 +83,7 @@ set (APP_SRCS
|
||||
rtustatusproc/rtustatus.cpp
|
||||
subiec104/sub_iec104.cpp
|
||||
zjd3100proc/zjd3100pro.cpp
|
||||
minio/ftp2minio.cpp
|
||||
)
|
||||
|
||||
set (APP_SRCS ${APP_SRCS}
|
||||
|
13
das-dn/CMakePresets.json
Normal file
13
das-dn/CMakePresets.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"version": 3,
|
||||
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "debug",
|
||||
"binaryDir": "${sourceDir}/build",
|
||||
"cacheVariables": {
|
||||
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -6,6 +6,7 @@
|
||||
#include "../hostmodbustcp/host_modbus_tcp.h"
|
||||
#include "../rtustatusproc/rtustatus.h"
|
||||
#include "../zjd3100proc/zjd3100pro.h"
|
||||
#include "../minio/ftp2minio.h"
|
||||
//#include "../bfftpfile2issmqtt/bfftpfile2issmqtt.h"
|
||||
#ifdef USE_WEBSOCKET
|
||||
#endif
|
||||
@ -354,6 +355,11 @@ void CChangeMaster::StartUp(void)
|
||||
vLog(LOG_INFO, "协议<%d>创建为: iec104从协议.\n", i);
|
||||
procs[i] = new CSubIEC104Process();
|
||||
}
|
||||
else if (PROTOCOL_FTP2MINIO == config.processes[i].proto)
|
||||
{
|
||||
vLog(LOG_INFO, "协议<%d>创建为: FTP读取转MINIO存储协议.\n", i);
|
||||
procs[i] = new CFtp2MinioProcess();
|
||||
}
|
||||
else if (PROTOCOL_LOCAL_DEBUG == config.processes[i].proto)
|
||||
{//Local debug
|
||||
vLog(LOG_INFO, "协议<%d>创建为: 本地调试协议.\n", i);
|
||||
|
2177
das-dn/cmg/main.cpp
2177
das-dn/cmg/main.cpp
File diff suppressed because it is too large
Load Diff
@ -12,17 +12,6 @@ CRYDevice::~CRYDevice()
|
||||
|
||||
}
|
||||
|
||||
std::vector<std::string> CRYDevice::split(const std::string &s, char delimiter)
|
||||
{
|
||||
std::vector<std::string> tokens;
|
||||
std::istringstream tokenStream(s);
|
||||
std::string token;
|
||||
while (std::getline(tokenStream, token, delimiter)) {
|
||||
tokens.push_back(token);
|
||||
}
|
||||
return tokens;
|
||||
}
|
||||
|
||||
bool CRYDevice::configInitializeMemory(void)
|
||||
{
|
||||
int i, j;
|
||||
@ -894,8 +883,20 @@ int CRYDevice::MakeYKFrame(int uid)
|
||||
} else {
|
||||
jsonRoot["result"] = true;
|
||||
}
|
||||
|
||||
publish_sensor_data(m_traceId, "deviceControlResp", jsonRoot);
|
||||
//查找设备serviceName的traceId
|
||||
char idName[512];
|
||||
snprintf(idName, sizeof(idName), "%s%s", static_units[uid].deviceId, config.units[uid].yks[order].name);
|
||||
std::string key(idName);
|
||||
std::string traceId;
|
||||
if (unitserviceName2cmdId_map.find(key) != unitserviceName2cmdId_map.end()) {
|
||||
traceId = unitserviceName2cmdId_map[key];
|
||||
unitserviceName2cmdId_map.erase(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
publish_sensor_data(traceId, "deviceControlResp", jsonRoot);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@ -939,7 +940,20 @@ int CRYDevice::MakeYTFrame(int uid)
|
||||
jsonRoot["result"] = true;
|
||||
}
|
||||
|
||||
publish_sensor_data(m_traceId, "deviceControlResp", jsonRoot);
|
||||
//查找设备serviceName的traceId
|
||||
char idName[512];
|
||||
snprintf(idName, sizeof(idName), "%s%s", static_units[uid].deviceId, config.units[uid].yks[order].name);
|
||||
std::string key(idName);
|
||||
std::string traceId;
|
||||
if (unitserviceName2cmdId_map.find(key) != unitserviceName2cmdId_map.end()) {
|
||||
traceId = unitserviceName2cmdId_map[key];
|
||||
unitserviceName2cmdId_map.erase(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
publish_sensor_data(traceId, "deviceControlResp", jsonRoot);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -976,6 +990,14 @@ bool CRYDevice::OnReceivedDeviceCommand(const Json::Value jsonRoot)
|
||||
return FALSE;
|
||||
}
|
||||
int operValue = jsonRoot["opValue"].asInt();
|
||||
//插入信息显示traceId和serviceName的对组关系
|
||||
std::string key = deviceId + serviceName;
|
||||
if (unitserviceName2cmdId_map.find(key) == unitserviceName2cmdId_map.end()) {
|
||||
unitserviceName2cmdId_map.insert(unitserviceName2cmdIdmap::value_type(key, m_traceId));
|
||||
} else {
|
||||
vLog(LOG_WARN, "系统同时下发了两个相同的serviceName<%s>控制,请检查。\n", serviceName.c_str());
|
||||
return false;
|
||||
}
|
||||
SetUnitYK(uid, point, (operValue & 0x03), YKS_SELREQ, YKR_IDLE);
|
||||
vLog(LOG_WARN, "Unit(%d) yk(%d) %s state is YKS_SELREQ result is YKR_IDLE.\n", uid, point, ((operValue & 0x03) ? "CLOSE" : "TRIP"));
|
||||
} else if (operType == CMD_CONTROL_SETTING) { //遥调
|
||||
@ -989,6 +1011,14 @@ bool CRYDevice::OnReceivedDeviceCommand(const Json::Value jsonRoot)
|
||||
}
|
||||
if (jsonRoot["opValue"].isInt()) operValue.dval = jsonRoot["opValue"].asInt();
|
||||
else if (jsonRoot["opValue"].isDouble()) operValue.fval = jsonRoot["opValue"].asFloat();
|
||||
//插入信息显示traceId和serviceName的对组关系
|
||||
std::string key = deviceId + serviceName;
|
||||
if (unitserviceName2cmdId_map.find(key) == unitserviceName2cmdId_map.end()) {
|
||||
unitserviceName2cmdId_map.insert(unitserviceName2cmdIdmap::value_type(key, m_traceId));
|
||||
} else {
|
||||
vLog(LOG_WARN, "系统同时下发了两个相同的serviceName<%s>调节,请检查。\n", serviceName.c_str());
|
||||
return false;
|
||||
}
|
||||
SetUnitYT(uid, point, operValue.dval, YTS_EXEREQ, YTR_IDLE);
|
||||
vLog(LOG_DEBUG, "Unit(%d) set point(%d) %d state is YTS_EXEREQ result is YTR_IDLE.\n", uid, point, operValue.dval);
|
||||
} else {
|
||||
@ -1044,32 +1074,141 @@ BOOLEAN CRYDevice::processUartParam(const Json::Value jsonRoot, int ord)
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
BOOLEAN CRYDevice::processNetworkParam(const Json::Value jsonRoot, int pid)
|
||||
|
||||
BOOLEAN CRYDevice::processRymodbustcpParam(const Json::Value jsonRoot, int pid)
|
||||
{
|
||||
if (pid < 0 || pid >= PROCESSES_NUM) return FALSE;
|
||||
|
||||
config_config.processes[pid].option.network.ignored_source = TRUE;
|
||||
config_config.processes[pid].option.network.socket_type = SOCK_STREAM;
|
||||
config_config.processes[pid].option.network.bind_addr = INADDR_ANY;
|
||||
config_config.processes[pid].option.network.bind_port = 0;
|
||||
config_config.processes[pid].option.network.target_addr = INADDR_ANY;
|
||||
config_config.processes[pid].option.network.target_port = 502;
|
||||
config_config.processes[pid].option.rymodbus.net.ignored_source = TRUE;
|
||||
config_config.processes[pid].option.rymodbus.net.socket_type = SOCK_STREAM;
|
||||
config_config.processes[pid].option.rymodbus.net.bind_addr = INADDR_ANY;
|
||||
config_config.processes[pid].option.rymodbus.net.bind_port = 0;
|
||||
config_config.processes[pid].option.rymodbus.net.target_addr = INADDR_ANY;
|
||||
config_config.processes[pid].option.rymodbus.net.target_port = 502;
|
||||
|
||||
if (jsonRoot["targetAddr"].isInt()) {
|
||||
config_config.processes[pid].option.network.target_addr = jsonRoot["targetAddr"].asInt();
|
||||
config_config.processes[pid].option.rymodbus.net.target_addr = jsonRoot["targetAddr"].asInt();
|
||||
} else if (jsonRoot["targetAddr"].isString()) {
|
||||
if (inet_pton(AF_INET, jsonRoot["targetAddr"].asCString(), &config_config.processes[pid].option.network.target_addr) == 1) {
|
||||
vLog(LOG_DEBUG, "IPv4 地址转换成功,网络字节序为: %u.\n", config_config.processes[pid].option.network.target_addr);
|
||||
if (inet_pton(AF_INET, jsonRoot["targetAddr"].asCString(), &config_config.processes[pid].option.rymodbus.net.target_addr) == 1) {
|
||||
vLog(LOG_DEBUG, "IPv4 地址转换成功,网络字节序为: %u.\n", config_config.processes[pid].option.rymodbus.net.target_addr);
|
||||
} else {
|
||||
vLog(LOG_ERROR, "inet_pton error(%d,%s).\n", errno, strerror(errno));
|
||||
}
|
||||
}
|
||||
if (jsonRoot["targetPort"].isInt()) {
|
||||
config_config.processes[pid].option.network.target_port = jsonRoot["targetPort"].asInt();
|
||||
config_config.processes[pid].option.rymodbus.net.target_port = jsonRoot["targetPort"].asInt();
|
||||
} else if (jsonRoot["targetPort"].isString()) {
|
||||
config_config.processes[pid].option.network.target_port = atoi(jsonRoot["targetPort"].asCString());
|
||||
config_config.processes[pid].option.rymodbus.net.target_port = atoi(jsonRoot["targetPort"].asCString());
|
||||
}
|
||||
|
||||
//增加ftp协议参数
|
||||
if (jsonRoot["enableFtp"].isInt()) {
|
||||
config_config.processes[pid].option.rymodbus.bHaveFTP = jsonRoot["enableFtp"].asInt();
|
||||
} else if (jsonRoot["enableFtp"].isString()) {
|
||||
config_config.processes[pid].option.rymodbus.bHaveFTP = atoi(jsonRoot["enableFtp"].asCString());
|
||||
} else { //默认存在允许ftp功能
|
||||
config_config.processes[pid].option.rymodbus.bHaveFTP = TRUE;
|
||||
}
|
||||
//用户名
|
||||
if (jsonRoot["userName"].isString()) {
|
||||
snprintf(config_config.processes[pid].option.rymodbus.ftp.user, sizeof(config_config.processes[pid].option.rymodbus.ftp.user), "%s", jsonRoot["userName"].asCString());
|
||||
} else { //默认存在允许ftp功能
|
||||
snprintf(config_config.processes[pid].option.rymodbus.ftp.user, sizeof(config_config.processes[pid].option.rymodbus.ftp.user), "%s", "administrator");
|
||||
}
|
||||
//密码
|
||||
if (jsonRoot["passWord"].isString()) {
|
||||
snprintf(config_config.processes[pid].option.rymodbus.ftp.password, sizeof(config_config.processes[pid].option.rymodbus.ftp.password), "%s", jsonRoot["passWord"].asCString());
|
||||
} else { //默认存在允许ftp功能
|
||||
snprintf(config_config.processes[pid].option.rymodbus.ftp.password, sizeof(config_config.processes[pid].option.rymodbus.ftp.password), "%s", "123456");
|
||||
}
|
||||
//远程路径
|
||||
if (jsonRoot["remotePath"].isString()) {
|
||||
snprintf(config_config.processes[pid].option.rymodbus.ftp.remotePath, sizeof(config_config.processes[pid].option.rymodbus.ftp.remotePath), "%s", jsonRoot["remotePath"].asCString());
|
||||
} else { //默认存在允许ftp功能
|
||||
snprintf(config_config.processes[pid].option.rymodbus.ftp.remotePath, sizeof(config_config.processes[pid].option.rymodbus.ftp.remotePath), "%s", "Hard Disk2/data/rtdatalog");
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOLEAN CRYDevice::processRyFTP2MinioParam(const Json::Value jsonRoot, int pid)
|
||||
{
|
||||
if (pid < 0 || pid >= PROCESSES_NUM) return FALSE;
|
||||
|
||||
config_config.processes[pid].option.ftp2minio.net.ignored_source = TRUE;
|
||||
config_config.processes[pid].option.ftp2minio.net.socket_type = SOCK_STREAM;
|
||||
config_config.processes[pid].option.ftp2minio.net.bind_addr = INADDR_ANY;
|
||||
config_config.processes[pid].option.ftp2minio.net.bind_port = 0;
|
||||
config_config.processes[pid].option.ftp2minio.net.target_addr = INADDR_ANY;
|
||||
config_config.processes[pid].option.ftp2minio.net.target_port = 502;
|
||||
|
||||
if (jsonRoot["targetAddr"].isInt()) {
|
||||
config_config.processes[pid].option.ftp2minio.net.target_addr = jsonRoot["targetAddr"].asInt();
|
||||
} else if (jsonRoot["targetAddr"].isString()) {
|
||||
if (inet_pton(AF_INET, jsonRoot["targetAddr"].asCString(), &config_config.processes[pid].option.ftp2minio.net.target_addr) == 1) {
|
||||
vLog(LOG_DEBUG, "IPv4 地址转换成功,网络字节序为: %u.\n", config_config.processes[pid].option.ftp2minio.net.target_addr);
|
||||
} else {
|
||||
vLog(LOG_ERROR, "inet_pton error(%d,%s).\n", errno, strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
//FTP参数
|
||||
//用户名
|
||||
if (jsonRoot["userName"].isString()) {
|
||||
snprintf(config_config.processes[pid].option.ftp2minio.ftp.user, sizeof(config_config.processes[pid].option.ftp2minio.ftp.user), "%s", jsonRoot["userName"].asCString());
|
||||
} else {
|
||||
snprintf(config_config.processes[pid].option.ftp2minio.ftp.user, sizeof(config_config.processes[pid].option.ftp2minio.ftp.user), "%s", "administrator");
|
||||
}
|
||||
//密码
|
||||
if (jsonRoot["passWord"].isString()) {
|
||||
snprintf(config_config.processes[pid].option.ftp2minio.ftp.password, sizeof(config_config.processes[pid].option.ftp2minio.ftp.password), "%s", jsonRoot["passWord"].asCString());
|
||||
} else {
|
||||
snprintf(config_config.processes[pid].option.ftp2minio.ftp.password, sizeof(config_config.processes[pid].option.ftp2minio.ftp.password), "%s", "123456");
|
||||
}
|
||||
//远程路径
|
||||
if (jsonRoot["remotePath"].isString()) {
|
||||
snprintf(config_config.processes[pid].option.ftp2minio.ftp.remotePath, sizeof(config_config.processes[pid].option.ftp2minio.ftp.remotePath), "%s", jsonRoot["remotePath"].asCString());
|
||||
} else {
|
||||
snprintf(config_config.processes[pid].option.ftp2minio.ftp.remotePath, sizeof(config_config.processes[pid].option.ftp2minio.ftp.remotePath), "%s", "Hard Disk2/data/rtdatalog");
|
||||
}
|
||||
//本地路径
|
||||
if (jsonRoot["localPath"].isString()) {
|
||||
snprintf(config_config.processes[pid].option.ftp2minio.ftp.localPath, sizeof(config_config.processes[pid].option.ftp2minio.ftp.localPath), "%s", jsonRoot["localPath"].asCString());
|
||||
} else {
|
||||
snprintf(config_config.processes[pid].option.ftp2minio.ftp.localPath, sizeof(config_config.processes[pid].option.ftp2minio.ftp.localPath), "%s", "./");
|
||||
}
|
||||
|
||||
//Minio参数
|
||||
//URL
|
||||
if (jsonRoot["URL"].isString()) {
|
||||
snprintf(config_config.processes[pid].option.ftp2minio.minio.url, sizeof(config_config.processes[pid].option.ftp2minio.minio.url), "%s", jsonRoot["URL"].asCString());
|
||||
} else {
|
||||
snprintf(config_config.processes[pid].option.ftp2minio.minio.url, sizeof(config_config.processes[pid].option.ftp2minio.minio.url), "%s", "http://192.168.109.187:9000");
|
||||
}
|
||||
//用户名
|
||||
if (jsonRoot["minioUserName"].isString()) {
|
||||
snprintf(config_config.processes[pid].option.ftp2minio.minio.user, sizeof(config_config.processes[pid].option.ftp2minio.minio.user), "%s", jsonRoot["minioUserName"].asCString());
|
||||
} else {
|
||||
snprintf(config_config.processes[pid].option.ftp2minio.minio.user, sizeof(config_config.processes[pid].option.ftp2minio.minio.user), "%s", "das");
|
||||
}
|
||||
//密码
|
||||
if (jsonRoot["minioPassWord"].isString()) {
|
||||
snprintf(config_config.processes[pid].option.ftp2minio.minio.password, sizeof(config_config.processes[pid].option.ftp2minio.minio.password), "%s", jsonRoot["minioPassWord"].asCString());
|
||||
} else {
|
||||
snprintf(config_config.processes[pid].option.ftp2minio.minio.password, sizeof(config_config.processes[pid].option.ftp2minio.minio.password), "%s", "zaq12WSX");
|
||||
}
|
||||
//桶
|
||||
if (jsonRoot["bucket"].isString()) {
|
||||
snprintf(config_config.processes[pid].option.ftp2minio.minio.bucket, sizeof(config_config.processes[pid].option.ftp2minio.minio.bucket), "%s", jsonRoot["bucket"].asCString());
|
||||
} else {
|
||||
snprintf(config_config.processes[pid].option.ftp2minio.minio.bucket, sizeof(config_config.processes[pid].option.ftp2minio.minio.bucket), "%s", "test");
|
||||
}
|
||||
//桶中的绝对路径
|
||||
if (jsonRoot["object"].isString()) {
|
||||
snprintf(config_config.processes[pid].option.ftp2minio.minio.object, sizeof(config_config.processes[pid].option.ftp2minio.minio.object), "%s", jsonRoot["object"].asCString());
|
||||
} else {
|
||||
snprintf(config_config.processes[pid].option.ftp2minio.minio.object, sizeof(config_config.processes[pid].option.ftp2minio.minio.object), "%s", "/A-001/Alarm/");
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -1153,15 +1292,37 @@ BOOLEAN CRYDevice::processModbusPointParam(const Json::Value jsonRoot, int uid,
|
||||
} else {
|
||||
config_config.units[uid].yxs[point].m_param[0] = 0;
|
||||
}
|
||||
//功能码
|
||||
if (jsonRoot["funcCode"].isString()) {
|
||||
BYTE funcCode = (BYTE)atoi(jsonRoot["funcCode"].asCString());
|
||||
config_config.units[uid].yxs[point].m_param[0] = funcCode;
|
||||
} else if (jsonRoot["funcCode"].isInt()) {
|
||||
BYTE funcCode = (BYTE)jsonRoot["funcCode"].asInt();
|
||||
config_config.units[uid].yxs[point].m_param[0] = funcCode;
|
||||
} else {
|
||||
config_config.units[uid].yxs[point].m_param[0] = 0;
|
||||
}
|
||||
//
|
||||
if (jsonRoot["col2"].isString()) {
|
||||
BYTE offSet = (BYTE)atoi(jsonRoot["col2"].asCString());
|
||||
config_config.units[uid].yxs[point].m_param[3] = offSet;
|
||||
} if (jsonRoot["col2"].isInt()) {
|
||||
} else if (jsonRoot["col2"].isInt()) {
|
||||
BYTE offSet = (BYTE)jsonRoot["col2"].asInt();
|
||||
config_config.units[uid].yxs[point].m_param[3] = offSet;
|
||||
} else {
|
||||
config_config.units[uid].yxs[point].m_param[3] = 0;
|
||||
}
|
||||
//偏移量
|
||||
if (jsonRoot["offSet"].isString()) {
|
||||
BYTE offSet = (BYTE)atoi(jsonRoot["offSet"].asCString());
|
||||
config_config.units[uid].yxs[point].m_param[3] = offSet;
|
||||
} else if (jsonRoot["offSet"].isInt()) {
|
||||
BYTE offSet = (BYTE)jsonRoot["offSet"].asInt();
|
||||
config_config.units[uid].yxs[point].m_param[3] = offSet;
|
||||
} else {
|
||||
config_config.units[uid].yxs[point].m_param[3] = 0;
|
||||
}
|
||||
//
|
||||
if (jsonRoot["col3"].isString()) {
|
||||
WORD registerAddr = (WORD)atoi(jsonRoot["col3"].asCString());
|
||||
config_config.units[uid].yxs[point].m_param[1] = (registerAddr & 0xff);
|
||||
@ -1174,6 +1335,20 @@ BOOLEAN CRYDevice::processModbusPointParam(const Json::Value jsonRoot, int uid,
|
||||
config_config.units[uid].yxs[point].m_param[1] = 0;
|
||||
config_config.units[uid].yxs[point].m_param[2] = 0;
|
||||
}
|
||||
//寄存器
|
||||
if (jsonRoot["registerAddr"].isString()) {
|
||||
WORD registerAddr = (WORD)atoi(jsonRoot["registerAddr"].asCString());
|
||||
config_config.units[uid].yxs[point].m_param[1] = (registerAddr & 0xff);
|
||||
config_config.units[uid].yxs[point].m_param[2] = ((registerAddr >> 8) & 0xff);
|
||||
} else if (jsonRoot["registerAddr"].isInt()) {
|
||||
WORD registerAddr = (WORD)jsonRoot["registerAddr"].asInt();
|
||||
config_config.units[uid].yxs[point].m_param[1] = (registerAddr & 0xff);
|
||||
config_config.units[uid].yxs[point].m_param[2] = ((registerAddr >> 8) & 0xff);
|
||||
} else {
|
||||
config_config.units[uid].yxs[point].m_param[1] = 0;
|
||||
config_config.units[uid].yxs[point].m_param[2] = 0;
|
||||
}
|
||||
//
|
||||
break;
|
||||
case POINT_TYPE_YC:
|
||||
if (point >= config_config.units[uid].yccount) return FALSE;
|
||||
@ -1186,6 +1361,17 @@ BOOLEAN CRYDevice::processModbusPointParam(const Json::Value jsonRoot, int uid,
|
||||
} else {
|
||||
config_config.units[uid].ycs[point].m_param[0] = 0;
|
||||
}
|
||||
//功能码
|
||||
if (jsonRoot["funcCode"].isString()) {
|
||||
BYTE funcCode = (BYTE)atoi(jsonRoot["funcCode"].asCString());
|
||||
config_config.units[uid].ycs[point].m_param[0] = funcCode;
|
||||
} else if (jsonRoot["funcCode"].isInt()) {
|
||||
BYTE funcCode = jsonRoot["funcCode"].asInt();
|
||||
config_config.units[uid].ycs[point].m_param[0] = funcCode;
|
||||
} else {
|
||||
config_config.units[uid].ycs[point].m_param[0] = 0;
|
||||
}
|
||||
//
|
||||
if (jsonRoot["col2"].isString()) {
|
||||
BYTE dataType = (BYTE)atoi(jsonRoot["col2"].asCString());
|
||||
config_config.units[uid].ycs[point].m_param[4] = dataType;
|
||||
@ -1200,6 +1386,22 @@ BOOLEAN CRYDevice::processModbusPointParam(const Json::Value jsonRoot, int uid,
|
||||
config_config.units[uid].ycs[point].m_param[4] = 0;
|
||||
config_config.units[uid].ycs[point].m_param[3] = 1;
|
||||
}
|
||||
//数据格式
|
||||
if (jsonRoot["dataType"].isString()) {
|
||||
BYTE dataType = (BYTE)atoi(jsonRoot["dataType"].asCString());
|
||||
config_config.units[uid].ycs[point].m_param[4] = dataType;
|
||||
if (dataType == 2 || dataType == 8) config_config.units[uid].ycs[point].m_param[3] = 1;
|
||||
else config_config.units[uid].ycs[point].m_param[3] = 2;
|
||||
} else if (jsonRoot["dataType"].isInt()) {
|
||||
BYTE dataType = jsonRoot["dataType"].asInt();
|
||||
config_config.units[uid].ycs[point].m_param[4] = dataType;
|
||||
if (dataType == 2 || dataType == 8) config_config.units[uid].ycs[point].m_param[3] = 1;
|
||||
else config_config.units[uid].ycs[point].m_param[3] = 2;
|
||||
} else {
|
||||
config_config.units[uid].ycs[point].m_param[4] = 0;
|
||||
config_config.units[uid].ycs[point].m_param[3] = 1;
|
||||
}
|
||||
//
|
||||
if (jsonRoot["col3"].isString()) {
|
||||
BYTE signMark = (BYTE)atoi(jsonRoot["col3"].asCString());
|
||||
config_config.units[uid].ycs[point].m_param[5] = signMark;
|
||||
@ -1209,6 +1411,17 @@ BOOLEAN CRYDevice::processModbusPointParam(const Json::Value jsonRoot, int uid,
|
||||
} else {
|
||||
config_config.units[uid].ycs[point].m_param[5] = 0;
|
||||
}
|
||||
//数据类型
|
||||
if (jsonRoot["signMark"].isString()) {
|
||||
BYTE signMark = (BYTE)atoi(jsonRoot["signMark"].asCString());
|
||||
config_config.units[uid].ycs[point].m_param[5] = signMark;
|
||||
} else if (jsonRoot["signMark"].isInt()) {
|
||||
BYTE signMark = jsonRoot["signMark"].asInt();
|
||||
config_config.units[uid].ycs[point].m_param[5] = signMark;
|
||||
} else {
|
||||
config_config.units[uid].ycs[point].m_param[5] = 0;
|
||||
}
|
||||
//
|
||||
if (jsonRoot["col4"].isString()) {
|
||||
WORD registerAddr = (WORD)atoi(jsonRoot["col4"].asCString());
|
||||
config_config.units[uid].ycs[point].m_param[1] = (registerAddr & 0xff);
|
||||
@ -1221,33 +1434,103 @@ BOOLEAN CRYDevice::processModbusPointParam(const Json::Value jsonRoot, int uid,
|
||||
config_config.units[uid].ycs[point].m_param[1] = 0;
|
||||
config_config.units[uid].ycs[point].m_param[2] = 0;
|
||||
}
|
||||
//寄存器
|
||||
if (jsonRoot["registerAddr"].isString()) {
|
||||
WORD registerAddr = (WORD)atoi(jsonRoot["registerAddr"].asCString());
|
||||
config_config.units[uid].ycs[point].m_param[1] = (registerAddr & 0xff);
|
||||
config_config.units[uid].ycs[point].m_param[2] = ((registerAddr >> 8) & 0xff);
|
||||
} else if (jsonRoot["registerAddr"].isInt()) {
|
||||
WORD registerAddr = (WORD)jsonRoot["registerAddr"].asInt();
|
||||
config_config.units[uid].ycs[point].m_param[1] = (registerAddr & 0xff);
|
||||
config_config.units[uid].ycs[point].m_param[2] = ((registerAddr >> 8) & 0xff);
|
||||
} else {
|
||||
config_config.units[uid].ycs[point].m_param[1] = 0;
|
||||
config_config.units[uid].ycs[point].m_param[2] = 0;
|
||||
}
|
||||
//
|
||||
break;
|
||||
case POINT_TYPE_YM:
|
||||
if (point >= config_config.units[uid].ymcount) return FALSE;
|
||||
if (jsonRoot["col1"].isString()) {
|
||||
BYTE funcCode = (BYTE)atoi(jsonRoot["col1"].asCString());
|
||||
config.units[uid].yms[point].m_param[0] = funcCode;
|
||||
} else if (jsonRoot["col1"].isInt()) {
|
||||
BYTE funcCode = jsonRoot["col1"].asInt();
|
||||
config_config.units[uid].yms[point].m_param[0] = funcCode;
|
||||
} else {
|
||||
config.units[uid].yms[point].m_param[0] = 0;
|
||||
}
|
||||
//功能码
|
||||
if (jsonRoot["funcCode"].isString()) {
|
||||
BYTE funcCode = (BYTE)atoi(jsonRoot["funcCode"].asCString());
|
||||
config.units[uid].yms[point].m_param[0] = funcCode;
|
||||
} else if (jsonRoot["funcCode"].isInt()) {
|
||||
BYTE funcCode = jsonRoot["funcCode"].asInt();
|
||||
config_config.units[uid].yms[point].m_param[0] = funcCode;
|
||||
} else {
|
||||
config.units[uid].yms[point].m_param[0] = 0;
|
||||
}
|
||||
//
|
||||
if (jsonRoot["col2"].isString()) {
|
||||
BYTE dataType = (BYTE)atoi(jsonRoot["col2"].asCString());
|
||||
config.units[uid].yms[point].m_param[4] = dataType;
|
||||
if (dataType == 0) config.units[uid].yms[point].m_param[3] = 1;
|
||||
if (dataType == 7 || dataType == 8) config.units[uid].yms[point].m_param[3] = 4;
|
||||
else config.units[uid].yms[point].m_param[3] = 2;
|
||||
} else if (jsonRoot["col2"].isInt()) {
|
||||
BYTE dataType = jsonRoot["col2"].asInt();
|
||||
config.units[uid].yms[point].m_param[4] = dataType;
|
||||
if (dataType == 0) config.units[uid].yms[point].m_param[3] = 1;
|
||||
if (dataType == 7 || dataType == 8) config.units[uid].yms[point].m_param[3] = 4;
|
||||
else config.units[uid].yms[point].m_param[3] = 2;
|
||||
} else {
|
||||
config.units[uid].yms[point].m_param[4] = 0;
|
||||
config.units[uid].yms[point].m_param[3] = 1;
|
||||
}
|
||||
//数据格式
|
||||
if (jsonRoot["dataType"].isString()) {
|
||||
BYTE dataType = (BYTE)atoi(jsonRoot["dataType"].asCString());
|
||||
config.units[uid].yms[point].m_param[4] = dataType;
|
||||
if (dataType == 0) config.units[uid].yms[point].m_param[3] = 1;
|
||||
if (dataType == 7 || dataType == 8) config.units[uid].yms[point].m_param[3] = 4;
|
||||
else config.units[uid].yms[point].m_param[3] = 2;
|
||||
} else if (jsonRoot["dataType"].isInt()) {
|
||||
BYTE dataType = jsonRoot["dataType"].asInt();
|
||||
config.units[uid].yms[point].m_param[4] = dataType;
|
||||
if (dataType == 0) config.units[uid].yms[point].m_param[3] = 1;
|
||||
if (dataType == 7 || dataType == 8) config.units[uid].yms[point].m_param[3] = 4;
|
||||
else config.units[uid].yms[point].m_param[3] = 2;
|
||||
} else {
|
||||
config.units[uid].yms[point].m_param[4] = 0;
|
||||
config.units[uid].yms[point].m_param[3] = 1;
|
||||
}
|
||||
//
|
||||
if (jsonRoot["col4"].isString()) {
|
||||
WORD registerAddr = (WORD)atoi(jsonRoot["col4"].asCString());
|
||||
config.units[uid].yms[point].m_param[1] = (registerAddr & 0xff);
|
||||
config.units[uid].yms[point].m_param[2] = ((registerAddr >> 8) & 0xff);
|
||||
} else if (jsonRoot["col4"].isInt()) {
|
||||
WORD registerAddr = (WORD)jsonRoot["col4"].asInt();
|
||||
config_config.units[uid].yms[point].m_param[1] = (registerAddr & 0xff);
|
||||
config_config.units[uid].yms[point].m_param[2] = ((registerAddr >> 8) & 0xff);
|
||||
} else {
|
||||
config.units[uid].yms[point].m_param[1] = 0;
|
||||
config.units[uid].yms[point].m_param[2] = 0;
|
||||
}
|
||||
//寄存器
|
||||
if (jsonRoot["registerAddr"].isString()) {
|
||||
WORD registerAddr = (WORD)atoi(jsonRoot["registerAddr"].asCString());
|
||||
config.units[uid].yms[point].m_param[1] = (registerAddr & 0xff);
|
||||
config.units[uid].yms[point].m_param[2] = ((registerAddr >> 8) & 0xff);
|
||||
} else if (jsonRoot["registerAddr"].isInt()) {
|
||||
WORD registerAddr = (WORD)jsonRoot["registerAddr"].asInt();
|
||||
config_config.units[uid].yms[point].m_param[1] = (registerAddr & 0xff);
|
||||
config_config.units[uid].yms[point].m_param[2] = ((registerAddr >> 8) & 0xff);
|
||||
} else {
|
||||
config.units[uid].yms[point].m_param[1] = 0;
|
||||
config.units[uid].yms[point].m_param[2] = 0;
|
||||
}
|
||||
//
|
||||
break;
|
||||
case POINT_TYPE_YK:
|
||||
if (point >= config_config.units[uid].ykcount) return FALSE;
|
||||
@ -1264,17 +1547,28 @@ BOOLEAN CRYDevice::processModbusPointParam(const Json::Value jsonRoot, int uid,
|
||||
if (jsonRoot["col1"].isString()) {
|
||||
BYTE funcCode = (BYTE)atoi(jsonRoot["col1"].asCString());
|
||||
config_config.units[uid].yks[point].m_param[0] = funcCode;
|
||||
} if (jsonRoot["col1"].isInt()) {
|
||||
} else if (jsonRoot["col1"].isInt()) {
|
||||
BYTE funcCode = (BYTE)jsonRoot["col1"].asInt();
|
||||
config_config.units[uid].yks[point].m_param[0] = funcCode;
|
||||
} else {
|
||||
config_config.units[uid].yks[point].m_param[0] = 0;
|
||||
}
|
||||
//功能码
|
||||
if (jsonRoot["funcCode"].isString()) {
|
||||
BYTE funcCode = (BYTE)atoi(jsonRoot["funcCode"].asCString());
|
||||
config_config.units[uid].yks[point].m_param[0] = funcCode;
|
||||
} else if (jsonRoot["funcCode"].isInt()) {
|
||||
BYTE funcCode = (BYTE)jsonRoot["funcCode"].asInt();
|
||||
config_config.units[uid].yks[point].m_param[0] = funcCode;
|
||||
} else {
|
||||
config_config.units[uid].yks[point].m_param[0] = 0;
|
||||
}
|
||||
//
|
||||
if (jsonRoot["col4"].isString()) {
|
||||
WORD registerAddr = (WORD)atoi(jsonRoot["col4"].asCString());
|
||||
config_config.units[uid].yks[point].m_param[6] = (registerAddr & 0xff);
|
||||
config_config.units[uid].yks[point].m_param[7] = ((registerAddr >> 8) & 0xff);
|
||||
} if (jsonRoot["col4"].isInt()) {
|
||||
} else if (jsonRoot["col4"].isInt()) {
|
||||
WORD registerAddr = (WORD)jsonRoot["col4"].asInt();
|
||||
config_config.units[uid].yks[point].m_param[6] = (registerAddr & 0xff);
|
||||
config_config.units[uid].yks[point].m_param[7] = ((registerAddr >> 8) & 0xff);
|
||||
@ -1282,11 +1576,25 @@ BOOLEAN CRYDevice::processModbusPointParam(const Json::Value jsonRoot, int uid,
|
||||
config_config.units[uid].yks[point].m_param[6] = 0xFF;
|
||||
config_config.units[uid].yks[point].m_param[7] = 0xFF;
|
||||
}
|
||||
//合闸寄存器
|
||||
if (jsonRoot["closeRegisterAddr"].isString()) {
|
||||
WORD registerAddr = (WORD)atoi(jsonRoot["closeRegisterAddr"].asCString());
|
||||
config_config.units[uid].yks[point].m_param[6] = (registerAddr & 0xff);
|
||||
config_config.units[uid].yks[point].m_param[7] = ((registerAddr >> 8) & 0xff);
|
||||
} else if (jsonRoot["closeRegisterAddr"].isInt()) {
|
||||
WORD registerAddr = (WORD)jsonRoot["closeRegisterAddr"].asInt();
|
||||
config_config.units[uid].yks[point].m_param[6] = (registerAddr & 0xff);
|
||||
config_config.units[uid].yks[point].m_param[7] = ((registerAddr >> 8) & 0xff);
|
||||
} else {
|
||||
config_config.units[uid].yks[point].m_param[6] = 0xFF;
|
||||
config_config.units[uid].yks[point].m_param[7] = 0xFF;
|
||||
}
|
||||
//
|
||||
if (jsonRoot["col6"].isString()) {
|
||||
WORD closeVal = (WORD)atoi(jsonRoot["col6"].asCString());
|
||||
config_config.units[uid].yks[point].m_param[10] = (closeVal & 0xff);
|
||||
config_config.units[uid].yks[point].m_param[11] = ((closeVal >> 8) & 0xff);
|
||||
} if (jsonRoot["col6"].isInt()) {
|
||||
} else if (jsonRoot["col6"].isInt()) {
|
||||
WORD closeVal = (WORD)jsonRoot["col6"].asInt();
|
||||
config_config.units[uid].yks[point].m_param[10] = (closeVal & 0xff);
|
||||
config_config.units[uid].yks[point].m_param[11] = ((closeVal >> 8) & 0xff);
|
||||
@ -1294,11 +1602,25 @@ BOOLEAN CRYDevice::processModbusPointParam(const Json::Value jsonRoot, int uid,
|
||||
config_config.units[uid].yks[point].m_param[10] = 0xFF;
|
||||
config_config.units[uid].yks[point].m_param[11] = 0xFF;
|
||||
}
|
||||
//合闸值
|
||||
if (jsonRoot["closeValue"].isString()) {
|
||||
WORD closeVal = (WORD)atoi(jsonRoot["closeValue"].asCString());
|
||||
config_config.units[uid].yks[point].m_param[10] = (closeVal & 0xff);
|
||||
config_config.units[uid].yks[point].m_param[11] = ((closeVal >> 8) & 0xff);
|
||||
} else if (jsonRoot["closeValue"].isInt()) {
|
||||
WORD closeVal = (WORD)jsonRoot["closeValue"].asInt();
|
||||
config_config.units[uid].yks[point].m_param[10] = (closeVal & 0xff);
|
||||
config_config.units[uid].yks[point].m_param[11] = ((closeVal >> 8) & 0xff);
|
||||
} else {
|
||||
config_config.units[uid].yks[point].m_param[10] = 0xFF;
|
||||
config_config.units[uid].yks[point].m_param[11] = 0xFF;
|
||||
}
|
||||
//
|
||||
if (jsonRoot["col8"].isString()) {
|
||||
WORD registerAddr = (WORD)atoi(jsonRoot["col8"].asCString());
|
||||
config_config.units[uid].yks[point].m_param[14] = (registerAddr & 0xff);
|
||||
config_config.units[uid].yks[point].m_param[15] = ((registerAddr >> 8) & 0xff);
|
||||
} if (jsonRoot["col8"].isInt()) {
|
||||
} else if (jsonRoot["col8"].isInt()) {
|
||||
WORD registerAddr = (WORD)jsonRoot["col8"].asInt();
|
||||
config_config.units[uid].yks[point].m_param[14] = (registerAddr & 0xff);
|
||||
config_config.units[uid].yks[point].m_param[15] = ((registerAddr >> 8) & 0xff);
|
||||
@ -1306,11 +1628,25 @@ BOOLEAN CRYDevice::processModbusPointParam(const Json::Value jsonRoot, int uid,
|
||||
config_config.units[uid].yks[point].m_param[14] = 0xFF;
|
||||
config_config.units[uid].yks[point].m_param[15] = 0xFF;
|
||||
}
|
||||
//分闸寄存器
|
||||
if (jsonRoot["openRegisterAddr"].isString()) {
|
||||
WORD registerAddr = (WORD)atoi(jsonRoot["openRegisterAddr"].asCString());
|
||||
config_config.units[uid].yks[point].m_param[14] = (registerAddr & 0xff);
|
||||
config_config.units[uid].yks[point].m_param[15] = ((registerAddr >> 8) & 0xff);
|
||||
} if (jsonRoot["openRegisterAddr"].isInt()) {
|
||||
WORD registerAddr = (WORD)jsonRoot["openRegisterAddr"].asInt();
|
||||
config_config.units[uid].yks[point].m_param[14] = (registerAddr & 0xff);
|
||||
config_config.units[uid].yks[point].m_param[15] = ((registerAddr >> 8) & 0xff);
|
||||
} else {
|
||||
config_config.units[uid].yks[point].m_param[14] = 0xFF;
|
||||
config_config.units[uid].yks[point].m_param[15] = 0xFF;
|
||||
}
|
||||
//
|
||||
if (jsonRoot["col10"].isString()) {
|
||||
WORD openVal = (WORD)atoi(jsonRoot["col10"].asCString());
|
||||
config_config.units[uid].yks[point].m_param[18] = (openVal & 0xff);
|
||||
config_config.units[uid].yks[point].m_param[19] = ((openVal >> 8) & 0xff);
|
||||
} if (jsonRoot["col10"].isInt()) {
|
||||
} else if (jsonRoot["col10"].isInt()) {
|
||||
WORD openVal = (WORD)jsonRoot["col10"].asInt();
|
||||
config_config.units[uid].yks[point].m_param[18] = (openVal & 0xff);
|
||||
config_config.units[uid].yks[point].m_param[19] = ((openVal >> 8) & 0xff);
|
||||
@ -1318,6 +1654,20 @@ BOOLEAN CRYDevice::processModbusPointParam(const Json::Value jsonRoot, int uid,
|
||||
config_config.units[uid].yks[point].m_param[18] = 0xFF;
|
||||
config_config.units[uid].yks[point].m_param[19] = 0xFF;
|
||||
}
|
||||
//分闸值
|
||||
if (jsonRoot["openValue"].isString()) {
|
||||
WORD openVal = (WORD)atoi(jsonRoot["openValue"].asCString());
|
||||
config_config.units[uid].yks[point].m_param[18] = (openVal & 0xff);
|
||||
config_config.units[uid].yks[point].m_param[19] = ((openVal >> 8) & 0xff);
|
||||
} else if (jsonRoot["openValue"].isInt()) {
|
||||
WORD openVal = (WORD)jsonRoot["openValue"].asInt();
|
||||
config_config.units[uid].yks[point].m_param[18] = (openVal & 0xff);
|
||||
config_config.units[uid].yks[point].m_param[19] = ((openVal >> 8) & 0xff);
|
||||
} else {
|
||||
config_config.units[uid].yks[point].m_param[18] = 0xFF;
|
||||
config_config.units[uid].yks[point].m_param[19] = 0xFF;
|
||||
}
|
||||
//
|
||||
break;
|
||||
case POINT_TYPE_YT:
|
||||
if (point >= config_config.units[uid].ytcount) return FALSE;
|
||||
@ -1327,28 +1677,50 @@ BOOLEAN CRYDevice::processModbusPointParam(const Json::Value jsonRoot, int uid,
|
||||
config_config.units[uid].yts[point].m_param[8] = 0xFF;
|
||||
config_config.units[uid].yts[point].m_param[9] = 0xFF;
|
||||
if (jsonRoot["col1"].isString()) {
|
||||
BYTE nSetType = (BYTE)atoi(jsonRoot["col1"].asCString());
|
||||
config_config.units[uid].yts[point].m_param[0] = nSetType;
|
||||
} if (jsonRoot["col1"].isInt()) {
|
||||
BYTE nSetType = (BYTE)jsonRoot["col1"].asInt();
|
||||
config_config.units[uid].yts[point].m_param[0] = nSetType;
|
||||
BYTE setType = (BYTE)atoi(jsonRoot["col1"].asCString());
|
||||
config_config.units[uid].yts[point].m_param[0] = setType;
|
||||
} else if (jsonRoot["col1"].isInt()) {
|
||||
BYTE setType = (BYTE)jsonRoot["col1"].asInt();
|
||||
config_config.units[uid].yts[point].m_param[0] = setType;
|
||||
} else {
|
||||
config_config.units[uid].yts[point].m_param[0] = 0;
|
||||
}
|
||||
//设值方式
|
||||
if (jsonRoot["setType"].isString()) {
|
||||
BYTE setType = (BYTE)atoi(jsonRoot["setType"].asCString());
|
||||
config_config.units[uid].yts[point].m_param[0] = setType;
|
||||
} else if (jsonRoot["setType"].isInt()) {
|
||||
BYTE setType = (BYTE)jsonRoot["setType"].asInt();
|
||||
config_config.units[uid].yts[point].m_param[0] = setType;
|
||||
} else {
|
||||
config_config.units[uid].yts[point].m_param[0] = 0;
|
||||
}
|
||||
//
|
||||
if (jsonRoot["col2"].isString()) {
|
||||
BYTE funcCode = (BYTE)atoi(jsonRoot["col2"].asCString());
|
||||
config_config.units[uid].yts[point].m_param[1] = funcCode;
|
||||
} if (jsonRoot["col2"].isInt()) {
|
||||
} else if (jsonRoot["col2"].isInt()) {
|
||||
BYTE funcCode = (BYTE)jsonRoot["col2"].asInt();
|
||||
config_config.units[uid].yts[point].m_param[1] = funcCode;
|
||||
} else {
|
||||
config_config.units[uid].yts[point].m_param[1] = 0;
|
||||
}
|
||||
//功能码
|
||||
if (jsonRoot["funcCode"].isString()) {
|
||||
BYTE funcCode = (BYTE)atoi(jsonRoot["funcCode"].asCString());
|
||||
config_config.units[uid].yts[point].m_param[1] = funcCode;
|
||||
} else if (jsonRoot["funcCode"].isInt()) {
|
||||
BYTE funcCode = (BYTE)jsonRoot["funcCode"].asInt();
|
||||
config_config.units[uid].yts[point].m_param[1] = funcCode;
|
||||
} else {
|
||||
config_config.units[uid].yts[point].m_param[1] = 0;
|
||||
}
|
||||
//
|
||||
if (jsonRoot["col5"].isString()) {
|
||||
WORD registerAddr = (WORD)atoi(jsonRoot["col5"].asCString());
|
||||
config_config.units[uid].yts[point].m_param[6] = (registerAddr & 0xff);
|
||||
config_config.units[uid].yts[point].m_param[7] = ((registerAddr >> 8) & 0xff);
|
||||
} if (jsonRoot["col5"].isInt()) {
|
||||
} else if (jsonRoot["col5"].isInt()) {
|
||||
WORD registerAddr = (WORD)jsonRoot["col5"].asInt();
|
||||
config_config.units[uid].yts[point].m_param[6] = (registerAddr & 0xff);
|
||||
config_config.units[uid].yts[point].m_param[7] = ((registerAddr >> 8) & 0xff);
|
||||
@ -1356,6 +1728,20 @@ BOOLEAN CRYDevice::processModbusPointParam(const Json::Value jsonRoot, int uid,
|
||||
config_config.units[uid].yts[point].m_param[6] = 0xFF;
|
||||
config_config.units[uid].yts[point].m_param[7] = 0xFF;
|
||||
}
|
||||
//寄存器地址
|
||||
if (jsonRoot["registerAddr"].isString()) {
|
||||
WORD registerAddr = (WORD)atoi(jsonRoot["registerAddr"].asCString());
|
||||
config_config.units[uid].yts[point].m_param[6] = (registerAddr & 0xff);
|
||||
config_config.units[uid].yts[point].m_param[7] = ((registerAddr >> 8) & 0xff);
|
||||
} else if (jsonRoot["registerAddr"].isInt()) {
|
||||
WORD registerAddr = (WORD)jsonRoot["registerAddr"].asInt();
|
||||
config_config.units[uid].yts[point].m_param[6] = (registerAddr & 0xff);
|
||||
config_config.units[uid].yts[point].m_param[7] = ((registerAddr >> 8) & 0xff);
|
||||
} else {
|
||||
config_config.units[uid].yts[point].m_param[6] = 0xFF;
|
||||
config_config.units[uid].yts[point].m_param[7] = 0xFF;
|
||||
}
|
||||
//
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
@ -1431,7 +1817,10 @@ bool CRYDevice::dealConfigFile(const Json::Value jsonRoot)
|
||||
break;
|
||||
case PROTOCOL_HOST_MODBUS_TCP:
|
||||
case PROTOCOL_HOST_MODBUS_RTU_TCP:
|
||||
processNetworkParam(params, i);
|
||||
processRymodbustcpParam(params, i);
|
||||
break;
|
||||
case PROTOCOL_FTP2MINIO:
|
||||
processRyFTP2MinioParam(params, i);
|
||||
break;
|
||||
case PROTOCOL_HOST_IEC104:
|
||||
processHostIEC104ProcessParam(params, i);
|
||||
@ -1989,9 +2378,9 @@ bool CRYDevice::publishdeviceEventData(void)
|
||||
value["attrCode"] = (const char *)config.units[uid].yxs[yxbw_point].name;
|
||||
value["attrValue"] = yxbw_value;
|
||||
value["eventType"] = 0;
|
||||
Json::Int64 datatime = (Json::Int64)time(NULL);
|
||||
datatime *= 1000;
|
||||
value["dataTime"] = datatime;
|
||||
Json::Int64 eventTime = (Json::Int64)time(NULL);
|
||||
eventTime *= 1000;
|
||||
value["eventTime"] = eventTime;
|
||||
value["limitValue"] = Json::Value::null;
|
||||
|
||||
root.append(value);
|
||||
@ -2010,9 +2399,9 @@ bool CRYDevice::publishdeviceEventData(void)
|
||||
value["attrCode"] = (const char *)config.units[uid].ycs[ycbw_point].name;
|
||||
value["attrValue"] = ycbw_value;
|
||||
value["eventType"] = ycbw_type;
|
||||
Json::Int64 datatime = (Json::Int64)time(NULL);
|
||||
datatime *= 1000;
|
||||
value["dataTime"] = datatime;
|
||||
Json::Int64 eventTime = (Json::Int64)time(NULL);
|
||||
eventTime *= 1000;
|
||||
value["eventTime"] = eventTime;
|
||||
value["limitValue"] = GetUnitYCLimitReal(uid, ycbw_point, ycbw_type);
|
||||
|
||||
root.append(value);
|
||||
|
@ -42,6 +42,7 @@ typedef struct {
|
||||
|
||||
typedef std::unordered_map<std::string, struct_service_item> name2servicemap;
|
||||
typedef std::unordered_map<std::string, name2servicemap> unitname2servicemap;
|
||||
typedef std::unordered_map<std::string, std::string> unitserviceName2cmdIdmap;
|
||||
|
||||
typedef struct {
|
||||
std::string name;
|
||||
@ -62,6 +63,7 @@ public:
|
||||
private:
|
||||
uid2pidmap uid2pid_map;
|
||||
unitname2servicemap unitname2service_map;
|
||||
unitserviceName2cmdIdmap unitserviceName2cmdId_map;
|
||||
std::string m_traceId;
|
||||
|
||||
LONG m_soeload = 0;
|
||||
@ -92,8 +94,6 @@ private:
|
||||
|
||||
time_t last_sec;
|
||||
private:
|
||||
std::vector<std::string> split(const std::string &s, char delimiter);
|
||||
|
||||
bool configInitializeMemory(void);
|
||||
bool configWriteSystemCFG(void);
|
||||
bool configWriteNodeCFG(void);
|
||||
@ -120,18 +120,19 @@ private:
|
||||
int GetUnitYCBW(int& uid, LONG& value, int& type, unionCP56Time& st);
|
||||
BOOLEAN GetUnitYK(int uid, int& order, BYTE& value, BYTE& act, BYTE& result);
|
||||
void SetUnitYK(int uid, int order, BYTE value, BYTE act, BYTE result);
|
||||
BOOLEAN GetUnitYT(int uid, int& order, DWORD& value, BYTE& act, BYTE& result);
|
||||
void SetUnitYT(int uid, int order, DWORD value, BYTE act, BYTE result);
|
||||
int MakeYKFrame(int uid);
|
||||
int MakeYTFrame(int uid);
|
||||
bool OnReceivedDeviceCommand(const Json::Value jsonRoot);
|
||||
BOOLEAN processUartParam(const Json::Value jsonRoot, int ord);
|
||||
BOOLEAN processNetworkParam(const Json::Value jsonRoot, int pid);
|
||||
BOOLEAN processHostIEC104ProcessParam(const Json::Value jsonRoot, int pid);
|
||||
BOOLEAN processModbusPointParam(const Json::Value jsonRoot, int uid, int point, int type);
|
||||
bool dealConfigFile(const Json::Value jsonRoot);
|
||||
bool OnReceivedSystemAction(const std::string cmdId, const std::string cmd, const Json::Value data);
|
||||
void on_message(const char *msg, const int size);
|
||||
BOOLEAN GetUnitYT(int, int& order, DWORD& value, BYTE& act, BYTE& result);
|
||||
void SetUnitYT(int, int order, DWORD value, BYTE act, BYTE result);
|
||||
int MakeYKFrame(int);
|
||||
int MakeYTFrame(int);
|
||||
bool OnReceivedDeviceCommand(const Json::Value);
|
||||
BOOLEAN processUartParam(const Json::Value, int);
|
||||
BOOLEAN processRymodbustcpParam(const Json::Value, int);
|
||||
BOOLEAN processRyFTP2MinioParam(const Json::Value, int);
|
||||
BOOLEAN processHostIEC104ProcessParam(const Json::Value, int pid);
|
||||
BOOLEAN processModbusPointParam(const Json::Value, int, int, int);
|
||||
bool dealConfigFile(const Json::Value);
|
||||
bool OnReceivedSystemAction(const std::string, const std::string, const Json::Value);
|
||||
void on_message(const char*, const int);
|
||||
|
||||
void heart_beat(int status);
|
||||
bool publishinitDeviceData(int uid);
|
||||
|
@ -322,6 +322,65 @@ DWORD BufToVal(BYTE* buf, int lenth, BOOLEAN bBigEndian)
|
||||
return sum;
|
||||
}
|
||||
|
||||
std::vector<std::string> split(const std::string &s, char delimiter)
|
||||
{
|
||||
std::vector<std::string> tokens;
|
||||
std::istringstream tokenStream(s);
|
||||
std::string token;
|
||||
while (std::getline(tokenStream, token, delimiter)) {
|
||||
tokens.push_back(token);
|
||||
}
|
||||
return tokens;
|
||||
}
|
||||
// 计算新字符串的长度,考虑到每个指定字符都可能被替换为更长的转义序列
|
||||
size_t calculate_escaped_length(const char *str, char escape_char)
|
||||
{
|
||||
size_t length = 0;
|
||||
size_t i;
|
||||
for (i = 0; str[i] != '\0'; i++)
|
||||
{
|
||||
if (str[i] == escape_char)
|
||||
{
|
||||
length += 3; // 每个指定字符替换为"\xXX"形式,长度为3
|
||||
}
|
||||
else
|
||||
{
|
||||
length += 1; // 其他字符保持不变
|
||||
}
|
||||
}
|
||||
return length + 1; // 加1是为了字符串末尾的空字符
|
||||
}
|
||||
|
||||
// 实现字符转义
|
||||
char* escape_char_in_string(const char *str, char escape_char)
|
||||
{
|
||||
size_t new_length = calculate_escaped_length(str, escape_char);
|
||||
|
||||
vLog(LOG_DEBUG, "new length is: %d\n", new_length);
|
||||
char *escaped_str = (char *)malloc(new_length);
|
||||
if (escaped_str == NULL)
|
||||
{
|
||||
return NULL; // 内存分配失败
|
||||
}
|
||||
|
||||
size_t j = 0;
|
||||
for (size_t i = 0; str[i] != '\0'; i++)
|
||||
{
|
||||
if (str[i] == escape_char)
|
||||
{
|
||||
sprintf(escaped_str + j, "%s", "\%20");
|
||||
j += 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
escaped_str[j++] = str[i];
|
||||
}
|
||||
}
|
||||
escaped_str[j] = '\0'; // 添加字符串末尾的空字符
|
||||
|
||||
return escaped_str;
|
||||
}
|
||||
|
||||
int unionCP56TimeToBuf(BYTE* buf, unionCP56Time st)
|
||||
{
|
||||
int len = 0;
|
||||
|
@ -3,8 +3,7 @@
|
||||
#include <math.h>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
|
||||
#ifdef HAVE_FTP_PROCESS
|
||||
#include <curl/curl.h>
|
||||
|
||||
#define MODBUSP_READ_ID 100 //读取文件及文件夹ID
|
||||
#define MODBUSP_READ_ID_FUNCCODE 0x03 //读取文件及文件夹ID功能码。
|
||||
@ -189,8 +188,6 @@ struct {
|
||||
{ 2, 368 }
|
||||
};
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
static int websocket_write(const noPollConn* conn, const char * buffer, int buffer_len)
|
||||
{
|
||||
int result;
|
||||
@ -542,26 +539,38 @@ static void* ryftp_process(void* param)
|
||||
CHostModbusTcpProcess* mbt = (CHostModbusTcpProcess *)param;
|
||||
|
||||
//获取此协议配置里面的ftp信息
|
||||
char remote[256];
|
||||
char name[256];
|
||||
char remote[512];
|
||||
char name[512];
|
||||
|
||||
//默认参数,或是通过协议配置获取
|
||||
char user[128] = "administrator";
|
||||
char password[128] = "123456";
|
||||
char ipaddress[128] = "127.0.0.1";
|
||||
char remotePath[128] = "Hard Disk2/data/rtdatalog";
|
||||
char pathName[128] = "./";
|
||||
|
||||
//配置远方路径
|
||||
char* escaped_string = escape_char_in_string(mbt->m_remotePath, ' ');
|
||||
if (escaped_string == NULL)
|
||||
{
|
||||
vLog(LOG_DEBUG, "路径转义错误!\n");
|
||||
return ((void*)0);
|
||||
}
|
||||
snprintf(remotePath, sizeof(remotePath), "%s", escaped_string);
|
||||
free(escaped_string);
|
||||
#if 0
|
||||
//根据协议创s建一个本地协议目录
|
||||
int pid = mbt->GetCurID();
|
||||
if (pid < 0 || pid >= PROCESSES_NUM) return ((void*)0);
|
||||
char pathName[128];
|
||||
snprintf(pathName, sizeof(pathName), "%d", pid);
|
||||
if (mbt->_mkdir(pathName) < 0) return ((void*)0);
|
||||
|
||||
#endif
|
||||
//配置的用户名和密码
|
||||
#if 0
|
||||
snprintf(user, sizeof(user), "%s", mbt->m_user);
|
||||
snprintf(password, sizeof(password), "%s", mbt->m_password);
|
||||
#endif
|
||||
|
||||
//配置ip地址
|
||||
DWORD target_addr = mbt->target_addr;
|
||||
memset(ipaddress, '\0', sizeof(ipaddress));
|
||||
inet_ntop(AF_INET, &target_addr, ipaddress, 16);
|
||||
@ -569,6 +578,7 @@ static void* ryftp_process(void* param)
|
||||
for (int i = 0; i < sizeof(m_datalen_mbaddr) / sizeof(m_datalen_mbaddr[0]); i++) {
|
||||
m_datalen2mbaddr_map.insert(datalen2mbaddrmap::value_type(m_datalen_mbaddr[i].address, i + 1));
|
||||
}
|
||||
|
||||
int len = 0;
|
||||
struRYDeviceData t_data;
|
||||
FIELDDES fields[1024];
|
||||
@ -1055,7 +1065,6 @@ static void* ryftp_process(void* param)
|
||||
datatypeposmap yxdatamap;
|
||||
|
||||
int yccount = GetUnitYCCount(uid);
|
||||
vLog(LOG_DEBUG, "yccount is: %d.\n", yccount);
|
||||
for (int i = 0; i < yccount; i++) {
|
||||
//根据遥测参数配置寄存器,获取高频数据寄存器
|
||||
WORD register_addr = GetUnitYCRegisterAddr(uid, i);
|
||||
@ -1070,7 +1079,6 @@ static void* ryftp_process(void* param)
|
||||
}
|
||||
}
|
||||
int yxcount = GetUnitYXCount(uid);
|
||||
vLog(LOG_DEBUG, "yxcount is: %d.\n", yxcount);
|
||||
for (int i = 0; i < yxcount; i++) {
|
||||
//根据遥测参数配置寄存器,获取高频数据寄存器
|
||||
WORD register_addr = GetUnitYXRegisterAddr(uid, i);
|
||||
@ -1087,6 +1095,7 @@ static void* ryftp_process(void* param)
|
||||
//根据实际配置表将
|
||||
WORD ftpget_retry_count = 0;
|
||||
BOOLEAN bReadCurrentFile = TRUE; //读取当前文件标识
|
||||
|
||||
while (TRUE) {
|
||||
sleep(1); //每秒执行一次
|
||||
if (!mbt->m_bFtpRun) break;
|
||||
@ -1099,16 +1108,17 @@ static void* ryftp_process(void* param)
|
||||
if (bReadCurrentFile)
|
||||
{ //读取当前文件
|
||||
snprintf(name, sizeof(name), "%s/%d", pathName, mbt->m_currentFileNo);
|
||||
snprintf(remote, sizeof(remote), "ftp://%s/Hard%20Disk2/data/rtdatalog/%d/%d", ipaddress, mbt->m_currentDirNo, mbt->m_currentFileNo);
|
||||
snprintf(remote, sizeof(remote), "ftp://%s/%s/%d/%d", ipaddress, remotePath, mbt->m_currentDirNo, mbt->m_currentFileNo);
|
||||
}
|
||||
else
|
||||
{ //读取未读的文件
|
||||
snprintf(name, sizeof(name), "%s/%d", pathName, mbt->m_lastReadFileNo);
|
||||
snprintf(remote, sizeof(remote), "ftp://%s/Hard%20Disk2/data/rtdatalog/%d/%d", ipaddress, mbt->m_lastReadDirNo, mbt->m_lastReadFileNo);
|
||||
snprintf(remote, sizeof(remote), "ftp://%s/%s/%d/%d", ipaddress, remotePath, mbt->m_lastReadDirNo, mbt->m_lastReadFileNo);
|
||||
}
|
||||
|
||||
struct memory chunk = {0}; // For storing the downloaded data
|
||||
int result = ftpget(remote, name, user, password, 3, &chunk);
|
||||
|
||||
if (result == CURLE_OK) {
|
||||
//成功,处理文件
|
||||
vLog(LOG_DEBUG, "get %s to local %s, with name: %s, and password: %s okay.\n", remote, name, user, password);
|
||||
@ -1221,9 +1231,6 @@ static void* ryftp_process(void* param)
|
||||
return ((void*)0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
CHostModbusTcpProcessItem::CHostModbusTcpProcessItem()
|
||||
{
|
||||
m_nNum = 0;
|
||||
@ -1320,26 +1327,21 @@ CHostModbusTcpProcess::CHostModbusTcpProcess()
|
||||
m_nCurBeginReg = 0;
|
||||
m_nNeedSend = FALSE;
|
||||
|
||||
#ifdef HAVE_FTP_PROCESS
|
||||
//websocket接口
|
||||
m_pid = 0;
|
||||
|
||||
//目录无效
|
||||
m_iv = 1;
|
||||
|
||||
m_currentDirNo = -1; //当前目录编号
|
||||
m_currentFileNo = -1; //当前文件编号
|
||||
m_lastDirNo = -1; //上一目录编号
|
||||
m_lastFileNo = -1; //上一文件编号
|
||||
|
||||
m_bFtpRun = FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
CHostModbusTcpProcess::~CHostModbusTcpProcess()
|
||||
{
|
||||
vLog(LOG_DEBUG, "here.....\n");
|
||||
#ifdef HAVE_FTP_PROCESS
|
||||
if (m_bHaveFTP)
|
||||
{
|
||||
m_bFtpRun = FALSE;
|
||||
vLog(LOG_DEBUG, "保存本协议读取到的那个目录和文件\n");
|
||||
char fileName[260];
|
||||
@ -1352,7 +1354,7 @@ CHostModbusTcpProcess::~CHostModbusTcpProcess()
|
||||
fwrite(&m_currentDirStartFileNo, sizeof(LONG), 1, pf);
|
||||
fclose(pf);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
CNetProcessItem *CHostModbusTcpProcess::CreateItem(int ord)
|
||||
@ -1668,10 +1670,23 @@ BOOLEAN CHostModbusTcpProcess::OnPreCreate(int id)
|
||||
{
|
||||
if (!CNetProcess::OnPreCreate(id)) return FALSE;
|
||||
|
||||
if (!GetOption(&m_nOptions, sizeof(m_nOptions)))
|
||||
{
|
||||
vLog(LOG_DEBUG, "润阳modbus读取配置错误。");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
m_bHaveFTP = m_nOptions.bHaveFTP;
|
||||
m_nTimeout = 200;
|
||||
calc2();
|
||||
|
||||
#ifdef HAVE_FTP_PROCESS
|
||||
if (m_bHaveFTP)
|
||||
{
|
||||
snprintf(m_user, sizeof(m_user), "%s", m_nOptions.ftp.user);
|
||||
snprintf(m_password, sizeof(m_password), "%s", m_nOptions.ftp.password);
|
||||
snprintf(m_remotePath, sizeof(m_remotePath), "%s", m_nOptions.ftp.remotePath);
|
||||
snprintf(m_localPath, sizeof(m_localPath), "%s", m_nOptions.ftp.localPath);
|
||||
|
||||
vLog(LOG_DEBUG, "file size is: %d\n", sizeof(struRYDeviceData) * 250 / 1024);
|
||||
//读取文件
|
||||
m_lastReadDirNo = 1;
|
||||
@ -1710,8 +1725,7 @@ BOOLEAN CHostModbusTcpProcess::OnPreCreate(int id)
|
||||
|
||||
pthread_attr_destroy(&attr);
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -1816,8 +1830,8 @@ BOOLEAN CHostModbusTcpProcess::OnTimer(void)
|
||||
if (pItem == NULL) return TRUE;
|
||||
m_nNeedSend = TRUE;
|
||||
|
||||
#ifdef HAVE_FTP_PROCESS
|
||||
//启动时读取一次,后面自己维护序号
|
||||
if (m_bHaveFTP)
|
||||
{ //启动时读取一次,后面自己维护序号
|
||||
if ((m_currentDirNo == -1) && (m_currentFileNo == -1))
|
||||
{ //当前文件和目录都为-1,程序第一次启动。需要获取ftp目录及文件ID
|
||||
m_nFrameType = MODBUSP_READ_ID;
|
||||
@ -1827,7 +1841,7 @@ BOOLEAN CHostModbusTcpProcess::OnTimer(void)
|
||||
pItem->m_nFramePoll |= MODBUSP_GET_DATA_FRAME;
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
struModbusExtFrame* frame = pItem->GetNextFrame();
|
||||
if (frame != NULL)
|
||||
{
|
||||
@ -2237,12 +2251,10 @@ BOOLEAN CHostModbusTcpProcess::OnReceiveData(CHostModbusTcpProcessItem *pItem, B
|
||||
{
|
||||
return OnReceiveYMData(pItem, &pData[3], count);
|
||||
}
|
||||
#ifdef HAVE_FTP_PROCESS
|
||||
else if (m_nCurFrame == MODBUSP_READ_ID)
|
||||
{
|
||||
return OnReceiveIDData(pItem, &pData[3], count);
|
||||
}
|
||||
#endif
|
||||
else if (m_nCurFrame == MODBUSP_YK_EXECUTE)
|
||||
{
|
||||
SetUnitYK(uid, m_nYKOrder, m_bYKValue, YKS_EXEED, YKR_SUCC);
|
||||
@ -2284,7 +2296,6 @@ BOOLEAN CHostModbusTcpProcess::OnReceiveData(CHostModbusTcpProcessItem *pItem, B
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#ifdef HAVE_FTP_PROCESS
|
||||
BOOLEAN CHostModbusTcpProcess::OnReceiveIDData(CHostModbusTcpProcessItem *pItem, BYTE* pData, int count)
|
||||
{
|
||||
int uid;
|
||||
@ -2339,7 +2350,6 @@ BOOLEAN CHostModbusTcpProcess::OnReceiveIDData(CHostModbusTcpProcessItem *pItem,
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
BOOLEAN CHostModbusTcpProcess::OnReceiveYXData(CHostModbusTcpProcessItem *pItem, BYTE* pData, int count)
|
||||
{
|
||||
|
@ -4,8 +4,6 @@
|
||||
#include "netproc.h"
|
||||
#include "modbus_def.h"
|
||||
|
||||
//#define HAVE_FTP_PROCESS
|
||||
#ifdef HAVE_FTP_PROCESS
|
||||
#include <dirent.h>
|
||||
#include <nopoll.h>
|
||||
#include <nopoll_decl.h>
|
||||
@ -172,8 +170,6 @@ typedef struct {
|
||||
} struRYDeviceData;
|
||||
#pragma pack()
|
||||
|
||||
#endif
|
||||
|
||||
class CHostModbusTcpProcessItem : public CNetProcessItem
|
||||
{
|
||||
public:
|
||||
@ -222,12 +218,21 @@ private:
|
||||
void sort1(STRUCT_PARAM*, int); //功能码排序
|
||||
void sort2(STRUCT_PARAM*, int); //寄存地址排序
|
||||
|
||||
#ifdef HAVE_FTP_PROCESS
|
||||
struRYModbusOption m_nOptions;
|
||||
//增加websocket连接
|
||||
pthread_t m_pid;
|
||||
short m_uid;
|
||||
|
||||
public:
|
||||
BOOLEAN m_bHaveFTP; //存在FTP协议
|
||||
|
||||
//ftp参数信息
|
||||
char m_user[64];
|
||||
char m_password[64];
|
||||
char m_remotePath[128];
|
||||
char m_localPath[128];
|
||||
|
||||
//文件信息
|
||||
int m_iv;
|
||||
LONG m_currentDirNo; //当前目录编号
|
||||
LONG m_currentFileNo; //当前文件编号
|
||||
@ -243,10 +248,6 @@ public:
|
||||
BOOLEAN m_bHaveUnReadFile; //存在未读的文件
|
||||
BOOLEAN m_bFtpRun;
|
||||
|
||||
//ftp参数信息
|
||||
char m_user[128];
|
||||
char m_password[128];
|
||||
char m_remoteIp[64];
|
||||
|
||||
int _mkdir(const char* pathName) {
|
||||
if (access(pathName, F_OK) == 0) return 0;
|
||||
@ -258,8 +259,6 @@ public:
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
public:
|
||||
CHostModbusTcpProcess();
|
||||
virtual ~CHostModbusTcpProcess();
|
||||
@ -279,9 +278,9 @@ public:
|
||||
|
||||
BOOLEAN OnReceiveData(CHostModbusTcpProcessItem *pItem, BYTE* pData, int count);
|
||||
int OnPackageReceived(BYTE* pBuf, int count, int ord /* = -1 */);
|
||||
#ifdef HAVE_FTP_PROCESS
|
||||
|
||||
virtual BOOLEAN OnReceiveIDData(CHostModbusTcpProcessItem *pItem, BYTE* pData, int count);
|
||||
#endif
|
||||
|
||||
virtual BOOLEAN OnReceiveYXData(CHostModbusTcpProcessItem *pItem, BYTE* pData, int count);
|
||||
virtual BOOLEAN OnReceiveYCData(CHostModbusTcpProcessItem *pItem, BYTE* pData, int count);
|
||||
virtual BOOLEAN OnReceiveYMData(CHostModbusTcpProcessItem *pItem, BYTE* pData, int count);
|
||||
|
@ -198,7 +198,7 @@ typedef int SOCKET;
|
||||
#define PROTOCOL_SUB_GDW104 47 //国网104从
|
||||
#define PROTOCOL_HW_MQTT 72 //华为物联平台ROMA
|
||||
#define PROTOCOL_OPCUA 78 //opcua协议
|
||||
|
||||
#define PROTOCOL_FTP2MINIO 79 //opcua协议
|
||||
|
||||
#define ADDR_TYPE_NORMAL 0
|
||||
#define ADDR_TYPE_HEX 1
|
||||
@ -602,6 +602,38 @@ typedef struct
|
||||
} struNetWorkOption;
|
||||
//end
|
||||
|
||||
// add by assouan for ry modbus options, it has ftp paramters;
|
||||
typedef struct
|
||||
{
|
||||
char user[64];
|
||||
char password[64];
|
||||
char remotePath[128];
|
||||
char localPath[128];
|
||||
} struFTPOption;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char url[256];
|
||||
char user[64];
|
||||
char password[64];
|
||||
char bucket[64];
|
||||
char object[256];
|
||||
} struMINIOOption;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
struNetWorkOption net;
|
||||
BOOLEAN bHaveFTP;
|
||||
struFTPOption ftp;
|
||||
} struRYModbusOption;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
struNetWorkOption net;
|
||||
struFTPOption ftp;
|
||||
struMINIOOption minio;
|
||||
} struRYFTP2MINIOOption;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
BOOLEAN use_owner_config; //单元配置是否启用
|
||||
@ -824,6 +856,8 @@ typedef union
|
||||
struIEC104Option iec104;
|
||||
struIEC103Option iec103;
|
||||
struIEC101Option iec101;
|
||||
struRYModbusOption rymodbus;
|
||||
struRYFTP2MINIOOption ftp2minio;
|
||||
} unionProcOption;
|
||||
|
||||
typedef struct
|
||||
@ -1346,6 +1380,8 @@ time_t unionCP56TimetoTime_t(unionCP56Time* st);
|
||||
unionCP56Time Time_ttounionCP56Time(time_t st);
|
||||
QLONG filetime_to_unix(QLONG ft);
|
||||
QWORD getTimeInMs();
|
||||
char* escape_char_in_string(const char *str, char escape_char);
|
||||
std::vector<std::string> split(const std::string &s, char delimiter);
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
typedef enum
|
||||
{
|
||||
|
375
das-dn/minio/ftp2minio.cpp
Normal file
375
das-dn/minio/ftp2minio.cpp
Normal file
@ -0,0 +1,375 @@
|
||||
#include "ftp2minio.h"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
FtpManage::FtpManage(const std::string user, const std::string password, const std::string id)
|
||||
:Ftp_ip(id), User(user), Password(password)
|
||||
{
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL); // 初始化全局环境只需要初始化一次
|
||||
if (res != CURLE_OK)
|
||||
{
|
||||
vLog(LOG_ERROR, "curl_global_init() falied %s\n", curl_easy_strerror(res));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
FtpManage::~FtpManage()
|
||||
{
|
||||
if (curl)
|
||||
{
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
curl_global_cleanup();
|
||||
}
|
||||
|
||||
//接收消息回调函数
|
||||
size_t WriteCallback(void* contents, size_t size, size_t nmemb, std::string* output)
|
||||
{
|
||||
size_t totalSize = size * nmemb;
|
||||
output->append(static_cast<char*>(contents), totalSize);
|
||||
return totalSize;
|
||||
}
|
||||
|
||||
// 初始化curl
|
||||
void FtpManage::SetURL()
|
||||
{
|
||||
curl = curl_easy_init();
|
||||
curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L); // 设置长连接
|
||||
curl_easy_setopt(curl, CURLOPT_USERPWD, (User + ':' + Password).c_str()); //设置用户名和密码
|
||||
}
|
||||
|
||||
// 把带有路径的文件转换为文件名 D:/ggbond/123.jpg->123.jpg
|
||||
std::string FtpManage::GetFileNameFromPath(const std::string& filePath)
|
||||
{
|
||||
if (filePath == "") return filePath;
|
||||
|
||||
//去除路径最后的空格
|
||||
std::string retPath;
|
||||
size_t lastBlank = filePath.find_last_not_of(' ');
|
||||
if (lastBlank != std::string::npos)
|
||||
{
|
||||
retPath = filePath.substr(0, lastBlank+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
size_t lastSlashPos = retPath.find_last_of("/\\");
|
||||
if (lastSlashPos != std::string::npos)
|
||||
{
|
||||
return retPath.substr(lastSlashPos + 1);
|
||||
}
|
||||
else
|
||||
{ // 如果没有找到斜杠或反斜杠,整个路径就是文件名
|
||||
return retPath;
|
||||
}
|
||||
}
|
||||
// 下载单一文件,把remoteFilePath的文件下载到localDirectory里面
|
||||
bool FtpManage::DownloadFile(const char* remoteFilePath, const char* localDirectory)
|
||||
{
|
||||
SetURL();
|
||||
_URL = Ftp_ip + remoteFilePath;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, _URL.c_str()); // 设置请求的URL
|
||||
if (curl)
|
||||
{
|
||||
FILE* fp = fopen((localDirectory + GetFileNameFromPath(remoteFilePath)).c_str(), "wb");
|
||||
if (fp)
|
||||
{ // 设置文件写入地址
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
|
||||
// 执行任务
|
||||
CURLcode res = curl_easy_perform(curl);
|
||||
if (res != CURLE_OK)
|
||||
{
|
||||
vLog(LOG_ERROR, "DownLoad file: %s failed<%s>.", remoteFilePath, curl_easy_strerror(res));
|
||||
fclose(fp);
|
||||
curl_easy_cleanup(curl);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
vLog(LOG_DEBUG, "DownLoad file: %s successfully!\n", remoteFilePath);
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
vLog(LOG_ERROR, "file open failed!\n");
|
||||
curl_easy_cleanup(curl); // 清除curl
|
||||
return false;
|
||||
}
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
return true;
|
||||
}
|
||||
// 下载全部文件
|
||||
bool FtpManage::DownloadAllFiles(const char* remoteFilePath, const char* localDirectory)
|
||||
{
|
||||
if (GetfilenameFromftp(remoteFilePath))
|
||||
{
|
||||
for (const auto& fns : fNs)
|
||||
{
|
||||
std::string filename = remoteFilePath + fns;
|
||||
bool res = DownloadFile(filename.c_str(), localDirectory);
|
||||
if (res) continue;
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 获取ftp某个文件夹内文件名
|
||||
bool FtpManage::GetfilenameFromftp(const std::string filePath)
|
||||
{
|
||||
SetURL();
|
||||
std::string path = Ftp_ip + filePath;
|
||||
std::string fileName; // 文件名列表保存位置
|
||||
|
||||
vLog(LOG_DEBUG, "path is: %s", path.c_str());
|
||||
if (curl)
|
||||
{
|
||||
curl_easy_setopt(curl, CURLOPT_URL, path.c_str()); // 设置访问URL
|
||||
curl_easy_setopt(curl, CURLOPT_DIRLISTONLY, 1L); // 设置只返回文件
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &fileName); // 设置只获取文件名列表
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); // 设置get的回调函数
|
||||
if (curl_easy_perform(curl) == CURLE_OK) //执行任务
|
||||
{
|
||||
fNs.clear();
|
||||
size_t startPos = 0, endPos = 0;
|
||||
while ((endPos = fileName.find('\n', startPos)) != std::string::npos )
|
||||
{
|
||||
std::string name = fileName.substr(startPos, endPos - startPos);
|
||||
fNs.emplace_back(name);
|
||||
startPos = endPos + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 获取FTP文件夹内所有文件名的接口函数
|
||||
const std::vector<std::string>& FtpManage::GetFilesName(const std::string filepath)
|
||||
{
|
||||
if (GetfilenameFromftp(filepath))
|
||||
{
|
||||
return fNs;
|
||||
}
|
||||
return std::vector<std::string>();
|
||||
}
|
||||
|
||||
CFtp2MinioProcess::CFtp2MinioProcess()
|
||||
{
|
||||
m_pAftp = NULL;
|
||||
}
|
||||
|
||||
CFtp2MinioProcess::~CFtp2MinioProcess()
|
||||
{
|
||||
if (m_pAftp) delete m_pAftp;
|
||||
m_pAftp = NULL;
|
||||
saveMapToFile();
|
||||
}
|
||||
|
||||
void CFtp2MinioProcess::saveMapToFile(void)
|
||||
{
|
||||
char fileName[260];
|
||||
snprintf(fileName, sizeof(fileName), "minioftp_%d.mem", GetCurID());
|
||||
std::ofstream outFile(fileName);
|
||||
if (!outFile)
|
||||
{
|
||||
vLog(LOG_ERROR, "Unable to open file for writing!\n");
|
||||
return;
|
||||
}
|
||||
for (const auto& pair : fileName2Id_map)
|
||||
{
|
||||
outFile << pair.first << " " << pair.second << std::endl;
|
||||
}
|
||||
outFile.close();
|
||||
}
|
||||
|
||||
void CFtp2MinioProcess::loadMapFromFile(void)
|
||||
{
|
||||
char fileName[260];
|
||||
snprintf(fileName, sizeof(fileName), "minioftp_%d.mem", GetCurID());
|
||||
std::ifstream inFile(fileName);
|
||||
if (!inFile)
|
||||
{
|
||||
vLog(LOG_ERROR, "Unable to open file for reading!\n");
|
||||
return;
|
||||
}
|
||||
std::string key;
|
||||
int value;
|
||||
fileName2Id_map.clear();
|
||||
while (inFile >> key >> value) {
|
||||
fileName2Id_map[key] = value; //如果键已经存在,则会更新其值
|
||||
}
|
||||
inFile.close();
|
||||
}
|
||||
|
||||
BOOLEAN CFtp2MinioProcess::OnPreCreate(int id)
|
||||
{
|
||||
if (!CProcess::OnPreCreate(id)) return FALSE;
|
||||
|
||||
DWORD target_addr;
|
||||
if (!GetOption(&m_nOptions, sizeof(m_nOptions)))
|
||||
{ //获取新配置
|
||||
vLog(LOG_DEBUG, "润阳ftp转modbus读取配置错误。");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (m_pAftp) m_pAftp = NULL;
|
||||
|
||||
target_addr = m_nOptions.net.target_addr;
|
||||
|
||||
char user[128] = "administrator";
|
||||
char password[128] = "123456";
|
||||
char ipaddress[128] = "127.0.0.1";
|
||||
char remotePath[128] = "\0";
|
||||
char localPath[128];
|
||||
char url[256];
|
||||
char listpath[256];
|
||||
snprintf(user, sizeof(user), "%s", m_nOptions.ftp.user);
|
||||
snprintf(password, sizeof(password), "%s", m_nOptions.ftp.password);
|
||||
snprintf(localPath, sizeof(localPath), "%s", m_nOptions.ftp.localPath);
|
||||
m_localPath = std::string(localPath);
|
||||
|
||||
char *escaped_string = escape_char_in_string(m_nOptions.ftp.remotePath, ' ');
|
||||
if (!escaped_string) return FALSE;
|
||||
snprintf(remotePath, sizeof(remotePath), "%s", escaped_string);
|
||||
free(escaped_string);
|
||||
|
||||
memset(ipaddress, '\0', sizeof(ipaddress));
|
||||
inet_ntop(AF_INET, &target_addr, ipaddress, 16);
|
||||
|
||||
snprintf(url, sizeof(url), "ftp://%s", ipaddress);
|
||||
snprintf(listpath, sizeof(listpath), "/%s", remotePath);
|
||||
|
||||
m_pAftp = new FtpManage(user, password, url);
|
||||
m_listPath = std::string(listpath);
|
||||
|
||||
fileName2Id_map.clear();
|
||||
//读取列表
|
||||
loadMapFromFile();
|
||||
|
||||
last_count = fileName2Id_map.size();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOLEAN CFtp2MinioProcess::Run(void)
|
||||
{
|
||||
if (!CProcess::Run()) return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOLEAN CFtp2MinioProcess::OnTimer(void)
|
||||
{
|
||||
if (!CProcess::OnTimer()) return FALSE;
|
||||
|
||||
BOOLEAN min_changed = FALSE;
|
||||
if (last_min != system32.now.minute)
|
||||
{
|
||||
last_min = system32.now.minute;
|
||||
min_changed = TRUE;
|
||||
}
|
||||
if (min_changed)
|
||||
{
|
||||
vLog(LOG_DEBUG, "准备读取文件夹%s的内容\n", m_listPath.c_str());
|
||||
for (const auto& n : m_pAftp->GetFilesName(m_listPath))
|
||||
{
|
||||
std::string remotefile = m_listPath + "/" + n;
|
||||
std::string localpath = m_localPath;
|
||||
if (fileName2Id_map.find(n) == fileName2Id_map.end())
|
||||
{
|
||||
fileName2Id_map.insert(fileName2Idmap::value_type(n, 0));
|
||||
if (m_pAftp->DownloadFile(remotefile.c_str(), localpath.c_str()))
|
||||
{
|
||||
vLog(LOG_DEBUG, "下载成功!\n");
|
||||
push2minio(n);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
vLog(LOG_WARN, "该文件:%s已经被下载。\n", n.c_str());
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
if (last_count != fileName2Id_map.size())
|
||||
{
|
||||
last_count = fileName2Id_map.size();
|
||||
saveMapToFile();
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOLEAN CFtp2MinioProcess::push2minio(std::string pathName)
|
||||
{
|
||||
//创建URL
|
||||
//minio::s3::BaseUrl base_url("http://192.168.109.187:9000");
|
||||
minio::s3::BaseUrl base_url(m_nOptions.minio.url);
|
||||
base_url.https = false;
|
||||
|
||||
//创建鉴权对象
|
||||
//minio::creds::StaticProvider provider("das", "zaq12WSX");
|
||||
minio::creds::StaticProvider provider(m_nOptions.minio.user, m_nOptions.minio.password);
|
||||
|
||||
// 创建客户端
|
||||
minio::s3::Client client(base_url, &provider);
|
||||
//std::string bucket_name = "test";
|
||||
std::string bucket_name = std::string(m_nOptions.minio.bucket);
|
||||
|
||||
// 检查test桶是否存在
|
||||
bool exist;
|
||||
{
|
||||
minio::s3::BucketExistsArgs args;
|
||||
args.bucket = bucket_name;
|
||||
|
||||
minio::s3::BucketExistsResponse resp = client.BucketExists(args);
|
||||
if (!resp) {
|
||||
vLog(LOG_ERROR, "unable to do bucket existence check; %s\n", resp.Error());
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
exist = resp.exist;
|
||||
}
|
||||
|
||||
// 如果test桶不存在,则创建test桶
|
||||
if (!exist) {
|
||||
minio::s3::MakeBucketArgs args;
|
||||
args.bucket = bucket_name;
|
||||
|
||||
minio::s3::MakeBucketResponse resp = client.MakeBucket(args);
|
||||
if (!resp) {
|
||||
vLog(LOG_ERROR, "unable to create bucket; %s\n", resp.Error());
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// 上传文件
|
||||
minio::s3::UploadObjectArgs args;
|
||||
args.bucket = bucket_name;
|
||||
//上传到桶中的绝对路径
|
||||
//char *pYMDhms = strchr((char *)pathName.c_str(), '.');
|
||||
//args.object = "/A-001/Alarm/" + pathName;
|
||||
args.object = std::string(m_nOptions.minio.object) + pathName;
|
||||
|
||||
//本地文件系统中的绝对路径
|
||||
args.filename = pathName;//"/das/minio-example/test.txt";
|
||||
|
||||
minio::s3::UploadObjectResponse resp = client.UploadObject(args);
|
||||
if (!resp) {
|
||||
vLog(LOG_ERROR, "unable to upload object; %s\n", resp.Error());
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
vLog(LOG_DEBUG, "'%s' is successfully uploaded as object '%s' to bucket 'test'.", args.filename.c_str(), args.object.c_str());
|
||||
|
||||
return TRUE;
|
||||
}
|
65
das-dn/minio/ftp2minio.h
Normal file
65
das-dn/minio/ftp2minio.h
Normal file
@ -0,0 +1,65 @@
|
||||
#ifndef _ZJD_FTP2MINIO_PROCESS_H_
|
||||
#define _ZJD_FTP2MINIO_PROCESS_H_
|
||||
|
||||
#include "process.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <curl/curl.h>
|
||||
#include <unordered_map>
|
||||
#include <miniocpp/client.h>
|
||||
|
||||
class FtpManage
|
||||
{
|
||||
public:
|
||||
FtpManage();
|
||||
FtpManage(const std::string user, const std::string password, const std::string id);
|
||||
~FtpManage();
|
||||
|
||||
bool DownloadFile(const char* remoteFilePath, const char* localDirectory);
|
||||
bool DownloadAllFiles(const char* remoteFilePath, const char* localDirectory);
|
||||
const std::vector<std::string>& GetFilesName(const std::string filepath);
|
||||
|
||||
private:
|
||||
void SetURL();
|
||||
std::string UrlEncode(const std::string& value);
|
||||
std::string GetFileNameFromPath(const std::string& filePath);
|
||||
bool GetfilenameFromftp(const std::string directoryname);
|
||||
|
||||
private:
|
||||
std::string Ftp_ip; //Ftp服务器地址
|
||||
std::string User, Password; //登录用户名及密码
|
||||
std::string _URL;
|
||||
std::vector<std::string> fNs; //用于记录全部文件名
|
||||
CURL* curl;
|
||||
};
|
||||
|
||||
typedef std::unordered_map<std::string, int> fileName2Idmap;
|
||||
|
||||
class CFtp2MinioProcess : public CProcess
|
||||
{
|
||||
public:
|
||||
CFtp2MinioProcess();
|
||||
virtual ~CFtp2MinioProcess();
|
||||
|
||||
virtual BOOLEAN OnPreCreate(int id);
|
||||
virtual BOOLEAN Run(void);
|
||||
virtual BOOLEAN OnTimer(void);
|
||||
|
||||
private:
|
||||
FtpManage* m_pAftp;
|
||||
std::string m_listPath; //需要查询的目录
|
||||
std::string m_localPath; //文件保存到本地的目录
|
||||
|
||||
//struNetWorkOption network;
|
||||
struRYFTP2MINIOOption m_nOptions;
|
||||
|
||||
DWORD last_min;
|
||||
fileName2Idmap fileName2Id_map;
|
||||
DWORD last_count;
|
||||
void saveMapToFile(void);
|
||||
void loadMapFromFile(void);
|
||||
|
||||
BOOLEAN push2minio(std::string);
|
||||
};
|
||||
|
||||
#endif //_ZJD_FTP2MINIO_PROCESS_H_
|
Loading…
Reference in New Issue
Block a user