update
This commit is contained in:
parent
75d48b9c1a
commit
b5702bfa7f
@ -5,6 +5,8 @@ CRYDevice::CRYDevice()
|
||||
{
|
||||
ctx = NULL;
|
||||
conn = NULL;
|
||||
|
||||
msg_count = 0;
|
||||
}
|
||||
|
||||
CRYDevice::~CRYDevice()
|
||||
@ -1788,7 +1790,7 @@ BOOLEAN CRYDevice::processSubModbusPointParam(const Json::Value jsonRoot, int ui
|
||||
{
|
||||
if (uid < 0 || uid >= UNIT_NUM) return FALSE;
|
||||
if (point < 0) return FALSE;
|
||||
vLog(LOG_DEBUG, "%s", jsonRoot.toStyledString().c_str());
|
||||
//vLog(LOG_DEBUG, "%s", jsonRoot.toStyledString().c_str());
|
||||
switch (type)
|
||||
{
|
||||
case POINT_TYPE_YX:
|
||||
@ -1849,16 +1851,38 @@ bool CRYDevice::dealConfigFile(const Json::Value jsonRoot)
|
||||
int count = links.size();
|
||||
int uartId = 0;
|
||||
|
||||
//m_gLinkIDs.clear();
|
||||
int uid = 0;
|
||||
uid2pid_map.clear();
|
||||
|
||||
long yxorder = 0, ycorder = 0, ymorder = 0, ykorder = 0, ytorder = 0;
|
||||
string2intmap map_yxorders, map_ycorders, map_ymorders, map_ykorders, map_ytorders;
|
||||
|
||||
pid2attrvectormap map_pid2attrserice;
|
||||
|
||||
char dbyxname[512];
|
||||
snprintf(dbyxname, sizeof(dbyxname), "%s/%s", configpath, FILE_DATABASE_YX_STATIC);
|
||||
FILE *pfdbyxname = fopen(dbyxname, "wb+");
|
||||
char dbycname[512];
|
||||
snprintf(dbycname, sizeof(dbycname), "%s/%s", configpath, FILE_DATABASE_YC_STATIC);
|
||||
FILE *pfdbycname = fopen(dbycname, "wb+");
|
||||
char dbymname[512];
|
||||
snprintf(dbymname, sizeof(dbymname), "%s/%s", configpath, FILE_DATABASE_YM_STATIC);
|
||||
FILE *pfdbymname = fopen(dbymname, "wb+");
|
||||
char dbykname[512];
|
||||
snprintf(dbykname, sizeof(dbykname), "%s/%s", configpath, FILE_DATABASE_YK_STATIC);
|
||||
FILE *pfdbykname = fopen(dbykname, "wb+");
|
||||
char dbytname[512];
|
||||
snprintf(dbytname, sizeof(dbytname), "%s/%s", configpath, FILE_DATABASE_YT_STATIC);
|
||||
FILE *pfdbytname = fopen(dbytname, "wb+");
|
||||
|
||||
map_yxorders.clear(); map_ycorders.clear(); map_ymorders.clear(); map_ykorders.clear(); map_ytorders.clear();
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
const Json::Value link = links[i];
|
||||
|
||||
|
||||
config_config.processes[i].state = TRUE;
|
||||
config_config.processes[i].type = MASTER_UNIT;
|
||||
config_config.processes[i].time_gap = 300; //默认参数
|
||||
config_config.processes[i].poll_gap = 5;
|
||||
config_config.processes[i].mode = PROCESS_MODE_MASTER;
|
||||
|
||||
if (link["linkName"].isString()) {
|
||||
snprintf(config_config.processes[i].name, sizeof(config_config.processes[i].name), "%s", link["linkName"].asCString());
|
||||
@ -1869,32 +1893,49 @@ bool CRYDevice::dealConfigFile(const Json::Value jsonRoot)
|
||||
if (link["protocol"].isInt()) {
|
||||
config_config.processes[i].proto = link["protocol"].asInt();
|
||||
}
|
||||
|
||||
//处理链路参数,根据协议参数的不同来处理
|
||||
BYTE addrType = ADDR_TYPE_NORMAL; //根据协议设定单元地址类型
|
||||
const Json::Value params = link["params"];
|
||||
if (!params.isNull()) {
|
||||
switch (config_config.processes[i].proto) {
|
||||
case PROTOCOL_HOST_MODBUS_RTU:
|
||||
processUartParam(params, uartId);
|
||||
config_config.processes[i].order = uartId++;
|
||||
config_config.processes[i].type = 1;
|
||||
config_config.processes[i].mode = PROCESS_MODE_MASTER;
|
||||
break;
|
||||
case PROTOCOL_HOST_MODBUS_TCP:
|
||||
processHostModbustcpParam(params, i);
|
||||
config_config.processes[i].type = 3;
|
||||
config_config.processes[i].mode = PROCESS_MODE_MASTER;
|
||||
addrType = ADDR_TYPE_IPV4;
|
||||
break;
|
||||
case PROTOCOL_HOST_BF_MODBUSTCP:
|
||||
processRymodbustcpParam(params, i);
|
||||
config_config.processes[i].type = 3;
|
||||
config_config.processes[i].mode = PROCESS_MODE_MASTER;
|
||||
addrType = ADDR_TYPE_IPV4;
|
||||
break;
|
||||
case PROTOCOL_FTP2MINIO:
|
||||
processRyFTP2MinioParam(params, i);
|
||||
break;
|
||||
case PROTOCOL_HOST_IEC104:
|
||||
processHostIEC104ProcessParam(params, i);
|
||||
config_config.processes[i].type = 3;
|
||||
config_config.processes[i].mode = PROCESS_MODE_MASTER;
|
||||
addrType = ADDR_TYPE_IPV4_FACNO;
|
||||
break;
|
||||
case PROTOCOL_SUB_IEC104:
|
||||
processSubIEC104ProcessParam(params, i);
|
||||
config_config.processes[i].type = 3;
|
||||
config_config.processes[i].mode = PROCESS_MODE_SLAVE;
|
||||
addrType = ADDR_TYPE_IPV4_FACNO;
|
||||
break;
|
||||
case PROTOCOL_SUB_MODBUS_TCP:
|
||||
processSubModbustcpParam(params, i);
|
||||
config_config.processes[i].type = 3;
|
||||
config_config.processes[i].mode = PROCESS_MODE_SLAVE;
|
||||
addrType = ADDR_TYPE_IPV4;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -1904,15 +1945,557 @@ bool CRYDevice::dealConfigFile(const Json::Value jsonRoot)
|
||||
const Json::Value devices = link["devices"];
|
||||
if (devices.isArray()) {
|
||||
int size = devices.size();
|
||||
for (int j = 0; j < size; j++) {
|
||||
std::string id = devices[j].asCString();
|
||||
if (uid2pid_map.find(id) == uid2pid_map.end()) {
|
||||
uid2pid_map.insert(uid2pidmap::value_type(id, i));
|
||||
if (config_config.processes[i].mode == PROCESS_MODE_SLAVE)
|
||||
{
|
||||
attrvectorGroup attrsItem;
|
||||
for (int j = 0; j < size; j++) {
|
||||
const Json::Value device = devices[j];
|
||||
std::string id = "";
|
||||
std::string address = "";
|
||||
if (device["id"].isString()) {
|
||||
id = device["id"].asString();
|
||||
}
|
||||
if (device["addr"].isString()) {
|
||||
address = device["addr"].asString();
|
||||
}
|
||||
//此处先将数据缓存。然后在处理
|
||||
const Json::Value attrs = device["attrs"];
|
||||
if (!attrs.isNull()) {
|
||||
int size = attrs.size();
|
||||
for (int k = 0; k < size; k++) {
|
||||
const Json::Value attr = attrs[k];
|
||||
std::string type = "";
|
||||
if (attr["type"].isString()) type = attr["type"].asString();
|
||||
struct_attr name_param;
|
||||
name_param.name = "";
|
||||
name_param.highSpeed = 0;
|
||||
name_param.order = -1;
|
||||
if (attr["name"].isString()) name_param.name = id + attr["name"].asString();
|
||||
if (attr["order"].isInt()) name_param.order = attr["order"].asInt();
|
||||
if (attr["params"].isObject()) name_param.params = attr["params"];
|
||||
if (type == "yc") attrsItem.ycs.push_back(name_param);
|
||||
else if (type == "yx") attrsItem.yxs.push_back(name_param);
|
||||
else if (type == "ym") attrsItem.yms.push_back(name_param);
|
||||
}
|
||||
}
|
||||
const Json::Value services = device["services"];
|
||||
if (!services.isNull()) {
|
||||
int size = services.size();
|
||||
for (int k = 0; k < size; k++) {
|
||||
const Json::Value service = services[k];
|
||||
std::string type = "";
|
||||
if (service["type"].isString()) type = service["type"].asString();
|
||||
struct_attr name_param;
|
||||
name_param.name = "";
|
||||
name_param.order = -1;
|
||||
if (service["name"].isString()) name_param.name = id + service["name"].asString();
|
||||
if (service["order"].isInt()) name_param.order = service["order"].asInt();
|
||||
if (service["params"].isObject()) name_param.params = service["params"];
|
||||
if (type == "yk") attrsItem.yks.push_back(name_param);
|
||||
else if (type == "yt") attrsItem.yts.push_back(name_param);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (map_pid2attrserice.find(i) == map_pid2attrserice.end()) {
|
||||
map_pid2attrserice.insert(pid2attrvectormap::value_type(i, attrsItem));
|
||||
}
|
||||
}
|
||||
else if (config_config.processes[i].mode == PROCESS_MODE_MASTER)
|
||||
{
|
||||
for (int j = 0; j < size; j++) {
|
||||
const Json::Value device = devices[j];
|
||||
std::string id = "";
|
||||
std::string address = "";
|
||||
if (device["id"].isString()) {
|
||||
id = device["id"].asString();
|
||||
}
|
||||
if (device["addr"].isString()) {
|
||||
address = device["addr"].asString();
|
||||
}
|
||||
snprintf(config_static_units[uid].name, sizeof(config_static_units[uid].name), "device_%d", uid);
|
||||
snprintf(config_static_units[uid].model, sizeof(config_static_units[uid].model), "model_%d", uid);
|
||||
snprintf(config_static_units[uid].manufacturerId, sizeof(config_static_units[uid].manufacturerId), "%s", "iss");
|
||||
if (id != "") {
|
||||
snprintf(config_static_units[uid].deviceId, sizeof(config_static_units[uid].deviceId), "%s", id.c_str());
|
||||
} else {
|
||||
snprintf(config_static_units[uid].deviceId, sizeof(config_static_units[uid].deviceId), "iss_%d", uid);
|
||||
}
|
||||
|
||||
config_config.processes[i].units[j] = uid;
|
||||
//根据协议修改地址
|
||||
if (address != "") {
|
||||
if (addrType == ADDR_TYPE_HEX) {
|
||||
StringToHex(address.c_str(), config_config.units[uid].addr);
|
||||
} else if (addrType == ADDR_TYPE_IPV4) {
|
||||
DWORD addr;
|
||||
inet_pton(AF_INET, address.c_str(), (struct in_addr*)&addr);
|
||||
memcpy(config_config.units[uid].addr, &addr, sizeof(addr));
|
||||
} else if (addrType == ADDR_TYPE_IPV4_FACNO) {
|
||||
std::vector<std::string> tokens = split(address, ':');
|
||||
if (tokens.size() >= 2) {
|
||||
DWORD addr;
|
||||
inet_pton(AF_INET, tokens.at(0).c_str(), (struct in_addr*)&addr);
|
||||
memcpy(config_config.units[uid].addr, &addr, sizeof(addr));
|
||||
addr = (DWORD)atoi(tokens.at(1).c_str());
|
||||
memcpy(&config_config.units[uid].addr[4], &addr, sizeof(addr));
|
||||
} else {
|
||||
DWORD addr;
|
||||
inet_pton(AF_INET, tokens.at(0).c_str(), (struct in_addr*)&addr);
|
||||
memcpy(config_config.units[uid].addr, &addr, sizeof(addr));
|
||||
addr = 1;
|
||||
memcpy(&config_config.units[uid].addr[4], &addr, sizeof(addr));
|
||||
}
|
||||
} else {
|
||||
DWORD addr = (DWORD)atoi(address.c_str());
|
||||
memcpy(config_config.units[uid].addr, &addr, sizeof(addr));
|
||||
}
|
||||
}
|
||||
attrvector yxs, ycs, yms, yks, yts;
|
||||
const Json::Value attrs = device["attrs"];
|
||||
if (!attrs.isNull()) {
|
||||
int size = attrs.size();
|
||||
for (int k = 0; k < size; k++) {
|
||||
const Json::Value attr = attrs[k];
|
||||
std::string type = "";
|
||||
if (attr["type"].isString()) type = attr["type"].asString();
|
||||
struct_attr name_param;
|
||||
name_param.name = "";
|
||||
name_param.highSpeed = 0;
|
||||
name_param.order = -1;
|
||||
if (attr["name"].isString()) name_param.name = attr["name"].asString();
|
||||
if (attr["highSpeed"].isInt()) name_param.highSpeed = attr["highSpeed"].asInt();
|
||||
if (attr["order"].isInt()) name_param.order = attr["order"].asInt();
|
||||
if (attr["params"].isObject()) name_param.params = attr["params"];
|
||||
if (type == "yc") ycs.push_back(name_param);
|
||||
else if (type == "yx") yxs.push_back(name_param);
|
||||
else if (type == "ym") yms.push_back(name_param);
|
||||
}
|
||||
}
|
||||
const Json::Value services = device["services"];
|
||||
if (!services.isNull()) {
|
||||
int size = services.size();
|
||||
for (int k = 0; k < size; k++) {
|
||||
const Json::Value service = services[k];
|
||||
std::string type = "";
|
||||
if (service["type"].isString()) type = service["type"].asString();
|
||||
struct_attr name_param;
|
||||
name_param.name = "";
|
||||
name_param.order = -1;
|
||||
if (service["name"].isString()) name_param.name = service["name"].asString();
|
||||
if (service["order"].isInt()) name_param.order = service["order"].asInt();
|
||||
if (service["params"].isObject()) name_param.params = service["params"];
|
||||
if (type == "yk") yks.push_back(name_param);
|
||||
else if (type == "yt") yts.push_back(name_param);
|
||||
}
|
||||
}
|
||||
|
||||
config_config.units[uid].value = SPI_ON;
|
||||
config_config.units[uid].softdog = UNIT_WATCHDOG_TIME;
|
||||
config_config.units[uid].state = TRUE;
|
||||
config_config.units[uid].type = MASTER_UNIT;
|
||||
config_config.units[uid].yxcount = yxs.size();
|
||||
config_config.units[uid].yccount = ycs.size();
|
||||
config_config.units[uid].ymcount = yms.size();
|
||||
config_config.units[uid].ykcount = yks.size();
|
||||
config_config.units[uid].ytcount = yts.size();
|
||||
if (config_config.units[uid].yccount > 0) {
|
||||
config_config.units[uid].ycs = new struUnitYC[config_config.units[uid].yccount];
|
||||
if (NULL != config_config.units[uid].ycs) {
|
||||
memset(config_config.units[uid].ycs, 0, sizeof(struUnitYC) * config_config.units[uid].yccount);
|
||||
for (int k = 0; k < config_config.units[uid].yccount; k++) {
|
||||
snprintf(config_config.units[uid].ycs[k].name, sizeof(config_config.units[uid].ycs[k].name), "%s", ycs[k].name.c_str());
|
||||
config_config.units[uid].ycs[k].order = ycorder++;
|
||||
std::string idattrname = id + ycs[k].name;
|
||||
if (map_ycorders.find(idattrname) == map_ycorders.end()) {
|
||||
map_ycorders.insert(string2intmap::value_type(idattrname, config_config.units[uid].ycs[k].order));
|
||||
}
|
||||
config_config.units[uid].ycs[k].value = 0;
|
||||
config_config.units[uid].ycs[k].qds = 0x80; //默认为无效
|
||||
config_config.units[uid].ycs[k].factor = 1;
|
||||
config_config.units[uid].ycs[k].change_pos = 2;
|
||||
config_config.units[uid].ycs[k].coef = 1.0f;
|
||||
config_config.units[uid].ycs[k].base = 0;
|
||||
config_config.units[uid].ycs[k].upBound = 9999999.999f;
|
||||
config_config.units[uid].ycs[k].lowBound = -9999999.999f;
|
||||
config_config.units[uid].ycs[k].limit1Enable = FALSE;
|
||||
config_config.units[uid].ycs[k].limit1Low = 0;
|
||||
config_config.units[uid].ycs[k].limit1High = 0.0f;
|
||||
config_config.units[uid].ycs[k].limit2Enable = FALSE;
|
||||
config_config.units[uid].ycs[k].limit2Low = 0;
|
||||
config_config.units[uid].ycs[k].limit2High = 0.0f;
|
||||
config_config.units[uid].ycs[k].highSpeed = ycs[k].highSpeed;
|
||||
Json::Value param = ycs[k].params;
|
||||
if (!param.isNull()) {
|
||||
if (param["coef"].isDouble()) config_config.units[uid].ycs[k].coef = param["coef"].asFloat();
|
||||
if (param["base"].isDouble()) config_config.units[uid].ycs[k].base = param["base"].asFloat();
|
||||
if (param["base"].isDouble()) config_config.units[uid].ycs[k].base = param["base"].asFloat();
|
||||
if (param["upBound"].isDouble()) config_config.units[uid].ycs[k].upBound = param["upBound"].asFloat();
|
||||
if (param["lowBound"].isDouble()) config_config.units[uid].ycs[k].lowBound = param["lowBound"].asFloat();
|
||||
if (param["limit1Enable"].isInt()) config_config.units[uid].ycs[k].limit1Enable = param["limit1Enable"].asInt();
|
||||
if (param["limit2Enable"].isInt()) config_config.units[uid].ycs[k].limit2Enable = param["limit2Enable"].asInt();
|
||||
if (param["limit1Low"].isDouble()) config_config.units[uid].ycs[k].limit1Low = param["limit1Low"].asFloat();
|
||||
if (param["limit2Low"].isDouble()) config_config.units[uid].ycs[k].limit2Low = param["limit2Low"].asFloat();
|
||||
if (param["limit1High"].isDouble()) config_config.units[uid].ycs[k].limit1High = param["limit1High"].asFloat();
|
||||
if (param["limit2High"].isDouble()) config_config.units[uid].ycs[k].limit2High = param["limit2High"].asFloat();
|
||||
|
||||
//vLog(LOG_DEBUG, "config_config.units[%d].ycs[%d].coef is: %f\n", uid, k, config_config.units[uid].ycs[k].coef);
|
||||
switch (config_config.processes[i].proto) {
|
||||
case PROTOCOL_HOST_MODBUS_RTU:
|
||||
case PROTOCOL_HOST_MODBUS_TCP:
|
||||
case PROTOCOL_HOST_MODBUS_RTU_TCP:
|
||||
case PROTOCOL_HOST_BF_MODBUSTCP:
|
||||
processHostModbusPointParam(param, uid, k, POINT_TYPE_YC);
|
||||
break;
|
||||
case PROTOCOL_HOST_IEC104:
|
||||
break;
|
||||
case PROTOCOL_SUB_MODBUS_TCP:
|
||||
processSubModbusPointParam(param, uid, k, POINT_TYPE_YC);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (config_config.units[uid].type == MASTER_UNIT) {
|
||||
config_database.ycs[config_config.units[uid].ycs[k].order].coef = config_config.units[uid].ycs[k].coef;
|
||||
config_database.ycs[config_config.units[uid].ycs[k].order].base = config_config.units[uid].ycs[k].base;
|
||||
}
|
||||
if (pfdbycname) {
|
||||
fseek(pfdbycname, sizeof(struYCStatic) * config_config.units[uid].ycs[k].order, SEEK_SET);
|
||||
fwrite(ycs[k].name.c_str(), (MAX_NAME_SIZE << 2), 1, pfdbycname);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (config_config.units[uid].ymcount > 0) {
|
||||
config_config.units[uid].yms = new struUnitYM[config_config.units[uid].ymcount];
|
||||
if (NULL != config_config.units[uid].yms) {
|
||||
memset(config_config.units[uid].yms, 0, sizeof(struUnitYM) * config_config.units[uid].ymcount);
|
||||
for (int k = 0; k < config_config.units[uid].ymcount; k++) {
|
||||
snprintf(config_config.units[uid].yms[k].name, sizeof(config_config.units[uid].yms[k].name), "%s", yms[k].name.c_str());
|
||||
config_config.units[uid].yms[k].order = ymorder++;
|
||||
std::string idattrname = id + yms[k].name;
|
||||
if (map_ymorders.find(idattrname) == map_ymorders.end()) {
|
||||
map_ymorders.insert(string2intmap::value_type(idattrname, config_config.units[uid].yms[k].order));
|
||||
}
|
||||
config_config.units[uid].yms[k].value = 0;
|
||||
config_config.units[uid].yms[k].coef = 1.0f;
|
||||
config_config.units[uid].yms[k].base = 0;
|
||||
|
||||
Json::Value param = yms[k].params;
|
||||
if (!param.isNull()) {
|
||||
switch (config_config.processes[i].proto) {
|
||||
case PROTOCOL_HOST_MODBUS_RTU:
|
||||
case PROTOCOL_HOST_MODBUS_TCP:
|
||||
case PROTOCOL_HOST_MODBUS_RTU_TCP:
|
||||
case PROTOCOL_HOST_BF_MODBUSTCP:
|
||||
processHostModbusPointParam(param, uid, k, POINT_TYPE_YM);
|
||||
break;
|
||||
case PROTOCOL_HOST_IEC104:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (config_config.units[uid].type == MASTER_UNIT) {
|
||||
config_database.yms[config_config.units[uid].yms[k].order].coef = config_config.units[uid].yms[k].coef;
|
||||
config_database.yms[config_config.units[uid].yms[k].order].base = config_config.units[uid].yms[k].base;
|
||||
}
|
||||
|
||||
if (pfdbymname) {
|
||||
fseek(pfdbymname, sizeof(struYMStatic) * config_config.units[uid].yms[k].order, SEEK_SET);
|
||||
fwrite(yms[k].name.c_str(), (MAX_NAME_SIZE << 2), 1, pfdbymname);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (config_config.units[uid].ykcount > 0) {
|
||||
config_config.units[uid].yks = new struUnitYK[config_config.units[uid].ykcount];
|
||||
if (NULL != config_config.units[uid].yks) {
|
||||
memset(config_config.units[uid].yks, 0, sizeof(struUnitYK) * config_config.units[uid].ykcount);
|
||||
for (int k = 0; k < config_config.units[uid].ykcount; k++) {
|
||||
snprintf(config_config.units[uid].yks[k].name, sizeof(config_config.units[uid].yks[k].name), "%s", yks[k].name.c_str());
|
||||
config_config.units[uid].yks[k].order = ykorder++;
|
||||
std::string idserverrname = id + yks[k].name;
|
||||
if (map_ykorders.find(idserverrname) == map_ykorders.end()) {
|
||||
map_ykorders.insert(string2intmap::value_type(idserverrname, config_config.units[uid].yks[k].order));
|
||||
}
|
||||
|
||||
Json::Value param = yks[k].params;
|
||||
if (!param.isNull()) {
|
||||
switch (config_config.processes[i].proto) {
|
||||
case PROTOCOL_HOST_MODBUS_RTU:
|
||||
case PROTOCOL_HOST_MODBUS_TCP:
|
||||
case PROTOCOL_HOST_MODBUS_RTU_TCP:
|
||||
case PROTOCOL_HOST_BF_MODBUSTCP:
|
||||
processHostModbusPointParam(param, uid, k, POINT_TYPE_YK);
|
||||
break;
|
||||
case PROTOCOL_HOST_IEC104:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (pfdbykname) {
|
||||
fseek(pfdbykname, sizeof(struYKStatic) * config_config.units[uid].yks[k].order, SEEK_SET);
|
||||
fwrite(yks[k].name.c_str(), (MAX_NAME_SIZE << 2), 1, pfdbykname);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (config_config.units[uid].ytcount > 0) {
|
||||
config_config.units[uid].yts = new struUnitYT[config_config.units[uid].ytcount];
|
||||
if (NULL != config_config.units[uid].yts) {
|
||||
memset(config_config.units[uid].yts, 0, sizeof(struUnitYT) * config_config.units[uid].ytcount);
|
||||
for (int k = 0; k < config_config.units[uid].ytcount; k++) {
|
||||
snprintf(config_config.units[uid].yts[k].name, sizeof(config_config.units[uid].yts[k].name), "%s", yts[k].name.c_str());
|
||||
config_config.units[uid].yts[k].order = ytorder++;
|
||||
std::string idserverrname = id + yts[k].name;
|
||||
if (map_ytorders.find(idserverrname) == map_ytorders.end()) {
|
||||
map_ytorders.insert(string2intmap::value_type(idserverrname, config_config.units[uid].yts[k].order));
|
||||
}
|
||||
|
||||
Json::Value param = yts[k].params;
|
||||
if (!param.isNull()) {
|
||||
switch (config_config.processes[i].proto) {
|
||||
case PROTOCOL_HOST_MODBUS_RTU:
|
||||
case PROTOCOL_HOST_MODBUS_TCP:
|
||||
case PROTOCOL_HOST_MODBUS_RTU_TCP:
|
||||
case PROTOCOL_HOST_BF_MODBUSTCP:
|
||||
processHostModbusPointParam(param, uid, k, POINT_TYPE_YT);
|
||||
break;
|
||||
case PROTOCOL_HOST_IEC104:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (pfdbytname) {
|
||||
fseek(pfdbytname, sizeof(struYTStatic) * config_config.units[uid].yts[k].order, SEEK_SET);
|
||||
fwrite(yts[k].name.c_str(), (MAX_NAME_SIZE << 2), 1, pfdbytname);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (config_config.units[uid].yxcount > 0) {
|
||||
config_config.units[uid].yxs = new struUnitYX[config_config.units[uid].yxcount];
|
||||
if (NULL != config_config.units[uid].yxs) {
|
||||
memset(config_config.units[uid].yxs, 0, sizeof(struUnitYX) * config_config.units[uid].yxcount);
|
||||
for (int k = 0; k < config_config.units[uid].yxcount; k++) {
|
||||
snprintf(config_config.units[uid].yxs[k].name, sizeof(config_config.units[uid].yxs[k].name), "%s", yxs[k].name.c_str());
|
||||
config_config.units[uid].yxs[k].order = yxorder++;
|
||||
std::string idattrname = id + yxs[k].name;
|
||||
if (map_yxorders.find(idattrname) == map_yxorders.end()) {
|
||||
map_yxorders.insert(string2intmap::value_type(idattrname, config_config.units[uid].yxs[k].order));
|
||||
}
|
||||
config_config.units[uid].yxs[k].value = 0;
|
||||
config_config.units[uid].yxs[k].qds = 0x80; //默认为无效
|
||||
config_config.units[uid].yxs[k].invert = 0;
|
||||
config_database.yxs[config_config.units[uid].yxs[k].order].auto_reset = 0;
|
||||
|
||||
Json::Value param = yxs[k].params;
|
||||
if (!param.isNull()) {
|
||||
if (param["invert"].asInt()) config_config.units[uid].yxs[k].invert = param["invert"].asInt();
|
||||
switch (config_config.processes[i].proto) {
|
||||
case PROTOCOL_HOST_MODBUS_RTU:
|
||||
case PROTOCOL_HOST_MODBUS_TCP:
|
||||
case PROTOCOL_HOST_MODBUS_RTU_TCP:
|
||||
case PROTOCOL_HOST_BF_MODBUSTCP:
|
||||
processHostModbusPointParam(param, uid, k, POINT_TYPE_YX);
|
||||
break;
|
||||
case PROTOCOL_HOST_IEC104:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (pfdbyxname) {
|
||||
fseek(pfdbyxname, sizeof(struYKStatic) * config_config.units[uid].yxs[k].order, SEEK_SET);
|
||||
fwrite(yxs[k].name.c_str(), (MAX_NAME_SIZE << 2), 1, pfdbyxname);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
uid++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#if 1
|
||||
//判断从设备列表
|
||||
int sub_uid = uid;
|
||||
for (pid2attrvectormap::iterator it = map_pid2attrserice.begin(); it != map_pid2attrserice.end(); it++)
|
||||
{
|
||||
int pid = it->first;
|
||||
attrvectorGroup attrs = it->second;
|
||||
|
||||
switch (config_config.processes[pid].proto)
|
||||
{
|
||||
case PROTOCOL_SUB_MODBUS_TCP:
|
||||
config_config.units[sub_uid].addr[4] = 1;
|
||||
config_config.processes[pid].option.smodbus.defaultYCType = 1;
|
||||
break;
|
||||
case PROTOCOL_SUB_IEC104:
|
||||
config_config.units[sub_uid].addr[4] = 1;
|
||||
break;
|
||||
}
|
||||
config_config.units[sub_uid].value = SPI_ON;
|
||||
config_config.units[sub_uid].softdog = UNIT_WATCHDOG_TIME;
|
||||
config_config.units[sub_uid].state = TRUE;
|
||||
config_config.units[sub_uid].type = SLAVER_UNIT;
|
||||
config_config.units[sub_uid].yxcount = attrs.yxs.size();
|
||||
config_config.units[sub_uid].yccount = attrs.ycs.size();
|
||||
config_config.units[sub_uid].ymcount = attrs.yms.size();
|
||||
config_config.units[sub_uid].ykcount = attrs.yks.size();
|
||||
config_config.units[sub_uid].ytcount = attrs.yts.size();
|
||||
|
||||
config_config.processes[pid].units[0] = sub_uid;
|
||||
if (config_config.units[sub_uid].yccount > 0)
|
||||
{
|
||||
config_config.units[sub_uid].ycs = new struUnitYC[config_config.units[sub_uid].yccount];
|
||||
if (NULL != config_config.units[sub_uid].ycs) {
|
||||
memset(config_config.units[sub_uid].ycs, 0, sizeof(struUnitYC) * config_config.units[sub_uid].yccount);
|
||||
}
|
||||
for (int i = 0; i < config_config.units[sub_uid].yccount; i++) {
|
||||
std::string key = attrs.ycs[i].name;
|
||||
int order = -1;
|
||||
int point = i;
|
||||
if (map_ycorders.find(key) != map_ycorders.end())
|
||||
{
|
||||
order = map_ycorders[key];
|
||||
}
|
||||
Json::Value param = attrs.ycs[i].params;
|
||||
if (!param["order"].isNull())
|
||||
{
|
||||
if (param["order"].isInt()) point = param["order"].asInt();
|
||||
if (param["order"].isString()) point = atoi(param["order"].asCString());
|
||||
}
|
||||
snprintf(config_config.units[sub_uid].ycs[point].name, sizeof(config_config.units[sub_uid].ycs[point].name), "%s", key.c_str());
|
||||
config_config.units[sub_uid].ycs[point].order = order;
|
||||
config_config.units[sub_uid].ycs[point].value = 0;
|
||||
config_config.units[sub_uid].ycs[point].qds = 0x80; //默认为无效
|
||||
config_config.units[sub_uid].ycs[point].factor = 1;
|
||||
config_config.units[sub_uid].ycs[point].change_pos = 2;
|
||||
if (order >= 0) {
|
||||
config_config.units[sub_uid].ycs[point].coef = config_database.ycs[order].coef;
|
||||
config_config.units[sub_uid].ycs[point].base = config_database.ycs[order].base;
|
||||
} else {
|
||||
config_config.units[sub_uid].ycs[point].coef = 1.0f;
|
||||
config_config.units[sub_uid].ycs[point].base = 0.0f;
|
||||
}
|
||||
config_config.units[sub_uid].ycs[point].upBound = 9999999.999f;
|
||||
config_config.units[sub_uid].ycs[point].lowBound = -9999999.999f;
|
||||
config_config.units[sub_uid].ycs[point].limit1Enable = FALSE;
|
||||
config_config.units[sub_uid].ycs[point].limit1Low = 0;
|
||||
config_config.units[sub_uid].ycs[point].limit1High = 0.0f;
|
||||
config_config.units[sub_uid].ycs[point].limit2Enable = FALSE;
|
||||
config_config.units[sub_uid].ycs[point].limit2Low = 0;
|
||||
config_config.units[sub_uid].ycs[point].limit2High = 0.0f;
|
||||
config_config.units[sub_uid].ycs[point].highSpeed = FALSE;
|
||||
}
|
||||
}
|
||||
if (config_config.units[sub_uid].ymcount > 0)
|
||||
{
|
||||
config_config.units[sub_uid].yms = new struUnitYM[config_config.units[sub_uid].ymcount];
|
||||
if (NULL != config_config.units[sub_uid].yms) {
|
||||
memset(config_config.units[sub_uid].yms, 0, sizeof(struUnitYM) * config_config.units[sub_uid].ymcount);
|
||||
}
|
||||
for (int i = 0; i < config_config.units[sub_uid].ymcount; i++) {
|
||||
std::string key = attrs.yms[i].name;
|
||||
int order = -1;
|
||||
int point = i;
|
||||
if (map_ymorders.find(key) != map_ymorders.end())
|
||||
{
|
||||
order = map_ymorders[key];
|
||||
}
|
||||
Json::Value param = attrs.yms[i].params;
|
||||
if (!param["order"].isNull())
|
||||
{
|
||||
if (param["order"].isInt()) point = param["order"].asInt();
|
||||
if (param["order"].isString()) point = atoi(param["order"].asCString());
|
||||
}
|
||||
snprintf(config_config.units[sub_uid].yms[point].name, sizeof(config_config.units[sub_uid].yms[point].name), "%s", key.c_str());
|
||||
config_config.units[sub_uid].yms[point].order = order;
|
||||
config_config.units[sub_uid].yms[point].value = 0;
|
||||
if (order >= 0) {
|
||||
config_config.units[sub_uid].yms[point].coef = config_database.yms[order].coef;
|
||||
config_config.units[sub_uid].yms[point].base = config_database.yms[order].base;
|
||||
} else {
|
||||
config_config.units[sub_uid].yms[point].coef = 1.0f;
|
||||
config_config.units[sub_uid].yms[point].base = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (config_config.units[sub_uid].ykcount > 0)
|
||||
{
|
||||
config_config.units[sub_uid].yks = new struUnitYK[config_config.units[sub_uid].ykcount];
|
||||
if (NULL != config_config.units[sub_uid].yks) {
|
||||
memset(config_config.units[sub_uid].yks, 0, sizeof(struUnitYK) * config_config.units[sub_uid].ykcount);
|
||||
}
|
||||
for (int i = 0; i < config_config.units[sub_uid].ykcount; i++) {
|
||||
std::string key = attrs.yks[i].name;
|
||||
int order = -1;
|
||||
int point = i;
|
||||
if (map_ykorders.find(key) != map_ykorders.end())
|
||||
{
|
||||
order = map_ykorders[key];
|
||||
}
|
||||
Json::Value param = attrs.yks[i].params;
|
||||
if (!param["order"].isNull())
|
||||
{
|
||||
if (param["order"].isInt()) point = param["order"].asInt();
|
||||
if (param["order"].isString()) point = atoi(param["order"].asCString());
|
||||
}
|
||||
snprintf(config_config.units[sub_uid].yks[point].name, sizeof(config_config.units[sub_uid].yks[point].name), "%s", key.c_str());
|
||||
config_config.units[sub_uid].yks[point].order = order;
|
||||
}
|
||||
}
|
||||
if (config_config.units[sub_uid].ytcount > 0)
|
||||
{
|
||||
config_config.units[sub_uid].yts = new struUnitYT[config_config.units[sub_uid].ytcount];
|
||||
if (NULL != config_config.units[sub_uid].yts) {
|
||||
memset(config_config.units[sub_uid].yts, 0, sizeof(struUnitYT) * config_config.units[sub_uid].ytcount);
|
||||
}
|
||||
for (int i = 0; i < config_config.units[sub_uid].ytcount; i++) {
|
||||
std::string key = attrs.yts[i].name;
|
||||
int order = -1;
|
||||
int point = i;
|
||||
if (map_ytorders.find(key) != map_ytorders.end())
|
||||
{
|
||||
order = map_ytorders[key];
|
||||
}
|
||||
Json::Value param = attrs.yts[i].params;
|
||||
if (!param["order"].isNull())
|
||||
{
|
||||
if (param["order"].isInt()) point = param["order"].asInt();
|
||||
if (param["order"].isString()) point = atoi(param["order"].asCString());
|
||||
}
|
||||
snprintf(config_config.units[sub_uid].yts[point].name, sizeof(config_config.units[sub_uid].yts[point].name), "%s", key.c_str());
|
||||
config_config.units[sub_uid].yts[point].order = order;
|
||||
}
|
||||
}
|
||||
if (config_config.units[sub_uid].yxcount > 0)
|
||||
{
|
||||
config_config.units[sub_uid].yxs = new struUnitYX[config_config.units[sub_uid].yxcount];
|
||||
if (NULL != config_config.units[sub_uid].yxs) {
|
||||
memset(config_config.units[sub_uid].yxs, 0, sizeof(struUnitYX) * config_config.units[sub_uid].yxcount);
|
||||
}
|
||||
for (int i = 0; i < config_config.units[sub_uid].yxcount; i++) {
|
||||
std::string key = attrs.yxs[i].name;
|
||||
int order = -1;
|
||||
int point = i;
|
||||
if (map_yxorders.find(key) != map_yxorders.end())
|
||||
{
|
||||
order = map_yxorders[key];
|
||||
}
|
||||
Json::Value param = attrs.yxs[i].params;
|
||||
if (!param["order"].isNull())
|
||||
{
|
||||
if (param["order"].isInt()) point = param["order"].asInt();
|
||||
if (param["order"].isString()) point = atoi(param["order"].asCString());
|
||||
}
|
||||
snprintf(config_config.units[sub_uid].yxs[point].name, sizeof(config_config.units[sub_uid].yxs[point].name), "%s", key.c_str());
|
||||
config_config.units[sub_uid].yxs[point].order = order;
|
||||
config_config.units[sub_uid].yxs[point].value = 0;
|
||||
config_config.units[sub_uid].yxs[point].value = 0;
|
||||
config_config.units[sub_uid].yxs[point].qds = 0x80; //默认为无效
|
||||
config_config.units[sub_uid].yxs[point].invert = 0;
|
||||
|
||||
}
|
||||
}
|
||||
sub_uid++;
|
||||
}
|
||||
#endif
|
||||
#if 0
|
||||
//更新设备列表
|
||||
const Json::Value equipments = jsonRoot["equipments"];
|
||||
{
|
||||
@ -2020,7 +2603,7 @@ bool CRYDevice::dealConfigFile(const Json::Value jsonRoot)
|
||||
name_param.highSpeed = 0;
|
||||
if (attr["name"].isString()) name_param.name = attr["name"].asString();
|
||||
if (attr["highSpeed"].isInt()) name_param.highSpeed = attr["highSpeed"].asInt();
|
||||
if (attr["params"].isObject()) name_param.value = attr["params"];
|
||||
if (attr["params"].isObject()) name_param.params = attr["params"];
|
||||
if (type == "yc") ycs.push_back(name_param);
|
||||
else if (type == "yx") yxs.push_back(name_param);
|
||||
else if (type == "ym") yms.push_back(name_param);
|
||||
@ -2036,7 +2619,7 @@ bool CRYDevice::dealConfigFile(const Json::Value jsonRoot)
|
||||
struct_attr name_param;
|
||||
name_param.name = "";
|
||||
if (service["name"].isString()) name_param.name = service["name"].asString();
|
||||
if (service["params"].isObject()) name_param.value = service["params"];
|
||||
if (service["params"].isObject()) name_param.params = service["params"];
|
||||
if (type == "yk") yks.push_back(name_param);
|
||||
else if (type == "yt") yts.push_back(name_param);
|
||||
}
|
||||
@ -2074,7 +2657,7 @@ bool CRYDevice::dealConfigFile(const Json::Value jsonRoot)
|
||||
config_config.units[uid].ycs[k].limit2Low = 0;
|
||||
config_config.units[uid].ycs[k].limit2High = 0.0f;
|
||||
config_config.units[uid].ycs[k].highSpeed = ycs[k].highSpeed;
|
||||
Json::Value param = ycs[k].value;
|
||||
Json::Value param = ycs[k].params;
|
||||
if (!param.isNull()) {
|
||||
if (param["coef"].isDouble()) config_config.units[uid].ycs[k].coef = param["coef"].asFloat();
|
||||
if (param["base"].isDouble()) config_config.units[uid].ycs[k].base = param["base"].asFloat();
|
||||
@ -2124,7 +2707,7 @@ bool CRYDevice::dealConfigFile(const Json::Value jsonRoot)
|
||||
config_config.units[uid].yms[k].coef = 1.0f;
|
||||
config_config.units[uid].yms[k].base = 0;
|
||||
|
||||
Json::Value param = yms[k].value;
|
||||
Json::Value param = yms[k].params;
|
||||
if (!param.isNull()) {
|
||||
switch (config_config.processes[pid].proto) {
|
||||
case PROTOCOL_HOST_MODBUS_RTU:
|
||||
@ -2157,7 +2740,7 @@ bool CRYDevice::dealConfigFile(const Json::Value jsonRoot)
|
||||
snprintf(config_config.units[uid].yks[k].name, sizeof(config_config.units[uid].yks[k].name), "%s", yks[k].name.c_str());
|
||||
config_config.units[uid].yks[k].order = ykorder++;
|
||||
|
||||
Json::Value param = yks[k].value;
|
||||
Json::Value param = yks[k].params;
|
||||
if (!param.isNull()) {
|
||||
switch (config_config.processes[pid].proto) {
|
||||
case PROTOCOL_HOST_MODBUS_RTU:
|
||||
@ -2185,7 +2768,7 @@ bool CRYDevice::dealConfigFile(const Json::Value jsonRoot)
|
||||
snprintf(config_config.units[uid].yts[k].name, sizeof(config_config.units[uid].yts[k].name), "%s", yts[k].name.c_str());
|
||||
config_config.units[uid].yts[k].order = ytorder++;
|
||||
|
||||
Json::Value param = yts[k].value;
|
||||
Json::Value param = yts[k].params;
|
||||
if (!param.isNull()) {
|
||||
switch (config_config.processes[pid].proto) {
|
||||
case PROTOCOL_HOST_MODBUS_RTU:
|
||||
@ -2217,7 +2800,7 @@ bool CRYDevice::dealConfigFile(const Json::Value jsonRoot)
|
||||
config_config.units[uid].yxs[k].invert = 0;
|
||||
config_database.yxs[config_config.units[uid].yxs[k].order].auto_reset = 0;
|
||||
|
||||
Json::Value param = yxs[k].value;
|
||||
Json::Value param = yxs[k].params;
|
||||
if (!param.isNull()) {
|
||||
if (param["invert"].asInt()) config_config.units[uid].yxs[k].invert = param["invert"].asInt();
|
||||
switch (config_config.processes[pid].proto) {
|
||||
@ -2245,6 +2828,13 @@ bool CRYDevice::dealConfigFile(const Json::Value jsonRoot)
|
||||
if (pfdbykname) fclose(pfdbykname);
|
||||
if (pfdbytname) fclose(pfdbytname);
|
||||
}
|
||||
#endif
|
||||
//保存数据库静态数据
|
||||
if (pfdbyxname) fclose(pfdbyxname);
|
||||
if (pfdbycname) fclose(pfdbycname);
|
||||
if (pfdbymname) fclose(pfdbymname);
|
||||
if (pfdbykname) fclose(pfdbykname);
|
||||
if (pfdbytname) fclose(pfdbytname);
|
||||
//保存数据
|
||||
configWriteNodeCFG();
|
||||
configWriteSystemCFG();
|
||||
@ -2296,11 +2886,11 @@ void CRYDevice::on_message(const char *msg, const int size)
|
||||
Json::CharReaderBuilder builder;
|
||||
Json::CharReader* reader(builder.newCharReader());
|
||||
|
||||
vLog(LOG_DEBUG, "Received: %s.\n", msg);
|
||||
//vLog(LOG_DEBUG, "Received: %s.\n", msg);
|
||||
|
||||
do {
|
||||
if (!reader->parse(msg, msg + size, &jsonRoot, &err)) {
|
||||
vLog(LOG_ERROR, "reader->parse(msg, msg + size, &jsonRoot, &err) error<%d,%s>。\n", errno, err.c_str());
|
||||
vLog(LOG_ERROR, "on_message reader->parse(msg, msg + size, &jsonRoot, &err) error<%d,%s>。\n", errno, err.c_str());
|
||||
break;
|
||||
}
|
||||
if (jsonRoot["cmd"].isNull()) {
|
||||
@ -2522,6 +3112,7 @@ BOOLEAN CRYDevice::ry_init(const char *host, const int port, const char *nodeId,
|
||||
unitname2service_map.clear();
|
||||
for (int i = 0; i < UNIT_NUM; i++) {
|
||||
if (config.units[i].state != TRUE) continue;
|
||||
if ((config.units[i].type & 0x0f) == SLAVER_UNIT) continue;
|
||||
std::string unit_id = static_units[i].deviceId;
|
||||
name2servicemap name2service_map;
|
||||
for (int j = 0; j < config.units[i].ykcount; j++) {
|
||||
@ -2581,22 +3172,14 @@ bool CRYDevice::ry_run(void)
|
||||
|
||||
while ((msg[msg_count] = nopoll_conn_get_msg(conn)) != NULL) {
|
||||
#if 1
|
||||
vLog(LOG_DEBUG, "recv %d length = %d, %d\n", msg_count, nopoll_msg_get_payload_size(msg[msg_count]), nopoll_msg_is_final(msg[msg_count]));
|
||||
#endif
|
||||
#if 0
|
||||
char pathN[256];
|
||||
snprintf(pathN, sizeof(pathN), "0/_%d.txt", msg_count);
|
||||
FILE* pf = fopen(pathN, "w+");
|
||||
if (pf) {
|
||||
fwrite(nopoll_msg_get_payload(msg[msg_count]), nopoll_msg_get_payload_size(msg[msg_count]), 1, pf);
|
||||
fclose(pf);
|
||||
}
|
||||
vLog(LOG_DEBUG, "recv %d length = %d, final is: %d, fragment is: %d\n", msg_count, nopoll_msg_get_payload_size(msg[msg_count]), nopoll_msg_is_final(msg[msg_count]), nopoll_msg_is_fragment(msg[msg_count]));
|
||||
#endif
|
||||
if (nopoll_msg_is_final(msg[msg_count])) {
|
||||
msg_count++;
|
||||
if (msg_count > 0) {
|
||||
int buffer_len;
|
||||
BYTE *buffer = NULL;
|
||||
vLog(LOG_DEBUG, "here... msg count is: %d\n", msg_count);
|
||||
if (websocket_msg_join(msg, msg_count, buffer, buffer_len)) {
|
||||
if (buffer) {
|
||||
on_message((const char *)buffer, buffer_len);
|
||||
|
@ -46,11 +46,26 @@ typedef std::unordered_map<std::string, std::string> unitserviceName2cmdIdmap;
|
||||
|
||||
typedef struct {
|
||||
std::string name;
|
||||
Json::Value value;
|
||||
int highSpeed;
|
||||
Json::Value params;
|
||||
int highSpeed;
|
||||
int order;
|
||||
} struct_attr;
|
||||
typedef std::vector<struct_attr> attrvector;
|
||||
|
||||
//设备id和attrs/services名称对应的测点序号
|
||||
typedef std::unordered_map<std::string, int> string2intmap;
|
||||
|
||||
//设备unit和attrvector对应的关系
|
||||
typedef struct {
|
||||
attrvector yxs;
|
||||
attrvector ycs;
|
||||
attrvector yms;
|
||||
attrvector yks;
|
||||
attrvector yts;
|
||||
} attrvectorGroup;
|
||||
typedef std::unordered_map<int, attrvectorGroup> pid2attrvectormap;
|
||||
|
||||
|
||||
class CRYDevice
|
||||
{
|
||||
public:
|
||||
|
@ -642,6 +642,12 @@ typedef struct
|
||||
struModbusOption modbus;
|
||||
} struUnitModbusOption;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
struNetWorkOption net;
|
||||
BYTE defaultYCType;
|
||||
} struSubModbusTCPOption;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
BYTE addressLength;
|
||||
@ -858,6 +864,7 @@ typedef union
|
||||
struIEC104Option iec104;
|
||||
struIEC103Option iec103;
|
||||
struIEC101Option iec101;
|
||||
struSubModbusTCPOption smodbus;
|
||||
struRYModbusOption rymodbus;
|
||||
struRYFTP2MINIOOption ftp2minio;
|
||||
} unionProcOption;
|
||||
|
@ -123,30 +123,30 @@ BOOLEAN CSubModbusTcpProcess::OnPreCreate(int id)
|
||||
m_DiscreteTable.clear();
|
||||
m_HoldingRegTable.clear();
|
||||
m_InputRegTable.clear();
|
||||
#if 1
|
||||
//获取遥信数量
|
||||
int yxcount = GetUnitYXCount(uid);
|
||||
//获取coil和discrete寄存器
|
||||
for (j = 0; j < yxcount; j++) {
|
||||
BYTE* param = GetUnitYXParamByPoint(uid, j);
|
||||
if (param) {
|
||||
if (param[0] == 0 || param[0] == 1) {
|
||||
m_DiscreteTable.push_back(j);
|
||||
} else {
|
||||
m_CoilRegTable.push_back(j);
|
||||
}
|
||||
}
|
||||
m_DiscreteTable.push_back(j);
|
||||
}
|
||||
|
||||
int ykcount = GetUnitYKCount(uid);
|
||||
for (j = 0; j < ykcount; j++) {
|
||||
m_CoilRegTable.push_back(j);
|
||||
}
|
||||
|
||||
int yccount = GetUnitYCCount(uid);
|
||||
for (j = 0; j < yccount; j++) {
|
||||
BYTE* param = GetUnitYCParamByPoint(uid, j);
|
||||
if (param) {
|
||||
if (param[0] == 0 || param[0] == 1) {
|
||||
m_InputRegTable.push_back(j);
|
||||
} else {
|
||||
m_HoldingRegTable.push_back(j);
|
||||
}
|
||||
}
|
||||
m_InputRegTable.push_back(j);
|
||||
}
|
||||
int ymcount = GetUnitYMCount(uid);
|
||||
for (j = 0; j < ymcount; j++) {
|
||||
m_InputRegTable.push_back(j);
|
||||
}
|
||||
|
||||
int ytcount = GetUnitYTCount(uid);
|
||||
for (j = 0; j < ytcount; j++) {
|
||||
m_HoldingRegTable.push_back(j);
|
||||
}
|
||||
|
||||
if (m_CoilRegTable.size() > 0)
|
||||
@ -154,6 +154,7 @@ BOOLEAN CSubModbusTcpProcess::OnPreCreate(int id)
|
||||
pItem->m_CoilRegCount = m_CoilRegTable.size();
|
||||
pItem->m_pCoilRegTable = new BYTE[pItem->m_CoilRegCount];
|
||||
memset(pItem->m_pCoilRegTable, 0, sizeof(BYTE) * pItem->m_CoilRegCount);
|
||||
pItem->m_ykcount = ykcount;
|
||||
}
|
||||
if (m_DiscreteTable.size() > 0)
|
||||
{
|
||||
@ -165,25 +166,51 @@ BOOLEAN CSubModbusTcpProcess::OnPreCreate(int id)
|
||||
{
|
||||
int count = 0;
|
||||
if (m_YC_Type == M_ME_NC) count = (m_InputRegTable.size() << 1);
|
||||
else count = m_InputRegTable.size();
|
||||
else {
|
||||
count = yccount + (ymcount << 1);
|
||||
}
|
||||
pItem->m_InputregCount = count;
|
||||
pItem->m_pInputRegTable = new WORD[count];
|
||||
memset(pItem->m_pInputRegTable, 0, sizeof(WORD) * count);
|
||||
pItem->m_yccount = yccount;
|
||||
pItem->m_ymcount = ymcount;
|
||||
}
|
||||
int ymcount = GetUnitYMCount(uid);
|
||||
if (m_HoldingRegTable.size() > 0 || ymcount > 0)
|
||||
if (m_HoldingRegTable.size() > 0)
|
||||
{
|
||||
int count = m_HoldingRegTable.size();
|
||||
if (m_YC_Type == M_ME_NC) count = (count << 1);
|
||||
count += (ymcount << 1);
|
||||
pItem->m_HoldingRegCount = count;
|
||||
pItem->m_pHoldingRegTable = new WORD[count];
|
||||
memset(pItem->m_pHoldingRegTable, 0, sizeof(WORD) * count);
|
||||
pItem->m_ytcount = ytcount;
|
||||
}
|
||||
#else
|
||||
pItem->m_yxcount = GetUnitYXCount(uid);
|
||||
pItem->m_yccount = GetUnitYCCount(uid);
|
||||
pItem->m_ymcount = GetUnitYMCount(uid);
|
||||
pItem->m_ykcount = GetUnitYKCount(uid);
|
||||
pItem->m_ytcount = GetUnitYTCount(uid);
|
||||
|
||||
pItem->m_CoilRegCount = UNIT_YK_MAX;
|
||||
pItem->m_pCoilRegTable = new BYTE[pItem->m_CoilRegCount];
|
||||
memset(pItem->m_pCoilRegTable, 0, sizeof(BYTE) * pItem->m_CoilRegCount);
|
||||
|
||||
pItem->m_DiscreteRegCount = UNIT_YX_MAX;
|
||||
pItem->m_pDiscreteRegTable = new BYTE[pItem->m_DiscreteRegCount];
|
||||
memset(pItem->m_pDiscreteRegTable, 0, sizeof(BYTE) * pItem->m_DiscreteRegCount);
|
||||
|
||||
pItem->m_HoldingRegCount = UNIT_YT_MAX;
|
||||
pItem->m_pHoldingRegTable = new WORD[pItem->m_HoldingRegCount];
|
||||
memset(pItem->m_pHoldingRegTable, 0, sizeof(WORD) * pItem->m_HoldingRegCount);
|
||||
|
||||
pItem->m_InputregCount = 0x5700;
|
||||
pItem->m_pHoldingRegTable = new WORD[pItem->m_InputregCount];
|
||||
memset(pItem->m_pHoldingRegTable, 0, sizeof(WORD) * pItem->m_InputregCount);
|
||||
#endif
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
BOOLEAN CSubModbusTcpProcess::Run(void)
|
||||
{
|
||||
if (!CNetProcess::Run()) return FALSE;
|
||||
@ -198,72 +225,55 @@ BOOLEAN CSubModbusTcpProcess::Run(void)
|
||||
uid = pItem->GetUnitID();
|
||||
if (uid < 0) continue;
|
||||
//刷新寄存器
|
||||
WORD *wd_input = NULL;
|
||||
WORD *wd_hold = NULL;
|
||||
BYTE *bt_coil = NULL;
|
||||
BYTE *bt_discrete = NULL;
|
||||
WORD *wd_input = NULL;
|
||||
BYTE *bt_discrete = NULL;
|
||||
|
||||
if (pItem->m_pInputRegTable) {
|
||||
if (pItem->m_pInputRegTable)
|
||||
{
|
||||
wd_input = (WORD *)pItem->m_pInputRegTable;
|
||||
}
|
||||
if (pItem->m_pHoldingRegTable) {
|
||||
wd_hold = (WORD *)pItem->m_pHoldingRegTable;
|
||||
}
|
||||
for (j = 0; j < m_InputRegTable.size(); j++)
|
||||
{
|
||||
if (m_YC_Type == M_ME_NC)
|
||||
for (j = 0; j < pItem->m_yccount; j++)
|
||||
{
|
||||
union
|
||||
if (m_YC_Type == M_ME_NC)
|
||||
{
|
||||
float fv;
|
||||
DWORD dv;
|
||||
} val;
|
||||
|
||||
val.fv = GetUnitYCReal(uid, m_InputRegTable[j]);
|
||||
*wd_input = ((val.dv >> 16) & 0xffff); wd_input++;
|
||||
*wd_input = (val.dv & 0xffff); wd_input++;
|
||||
}
|
||||
else
|
||||
{
|
||||
*wd_input = (WORD)GetUnitYC(uid, m_InputRegTable[j]); wd_input++;
|
||||
}
|
||||
}
|
||||
for (j = 0; j < m_HoldingRegTable.size(); j++)
|
||||
{
|
||||
if (m_YC_Type == M_ME_NC)
|
||||
{
|
||||
union
|
||||
union
|
||||
{
|
||||
float fv;
|
||||
DWORD dv;
|
||||
} val;
|
||||
val.fv = GetUnitYCReal(uid, j);
|
||||
*wd_input = ((val.dv >> 16) & 0xffff); wd_input++;
|
||||
*wd_input = (val.dv & 0xffff); wd_input++;
|
||||
}
|
||||
else
|
||||
{
|
||||
float fv;
|
||||
DWORD dv;
|
||||
} val;
|
||||
|
||||
val.fv = GetUnitYCReal(uid, m_HoldingRegTable[j]);
|
||||
*wd_hold = ((val.dv >> 16) & 0xffff); wd_hold++;
|
||||
*wd_hold = (val.dv & 0xffff); wd_hold++;
|
||||
*wd_input = (WORD)GetUnitYC(uid, j); wd_input++;
|
||||
}
|
||||
}
|
||||
else
|
||||
for (j = 0; j < pItem->m_ymcount; j++)
|
||||
{
|
||||
*wd_hold = (WORD)GetUnitYC(uid, m_HoldingRegTable[j]); wd_hold++;
|
||||
if (m_YC_Type == M_ME_NC)
|
||||
{
|
||||
union
|
||||
{
|
||||
float fv;
|
||||
DWORD dv;
|
||||
} val;
|
||||
val.fv = GetUnitYMReal(uid, j);
|
||||
*wd_input = ((val.dv >> 16) & 0xffff); wd_input++;
|
||||
*wd_input = (val.dv & 0xffff); wd_input++;
|
||||
}
|
||||
else
|
||||
{
|
||||
DWORD value = GetUnitYM(uid, j);
|
||||
*wd_input = ((value >> 16) & 0xffff); wd_input++;
|
||||
*wd_input = (value & 0xffff); wd_input++;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (j = 0; j < GetUnitYMCount(uid); j++)
|
||||
{
|
||||
DWORD val = (DWORD)GetUnitYM(uid, j);
|
||||
*wd_hold = ((val >> 16) & 0xffff); wd_hold++;
|
||||
*wd_hold = (val & 0xffff); wd_hold++;
|
||||
}
|
||||
|
||||
if (pItem->m_pCoilRegTable) {
|
||||
bt_coil = (BYTE *)pItem->m_pCoilRegTable;
|
||||
for (j = 0; j < m_CoilRegTable.size(); j++)
|
||||
{
|
||||
*bt_coil = (BYTE)GetUnitYX(uid, m_CoilRegTable[j]); bt_coil++;
|
||||
}
|
||||
}
|
||||
if (pItem->m_pDiscreteRegTable) {
|
||||
bt_discrete = (BYTE *)pItem->m_pDiscreteRegTable;
|
||||
for (j = 0; j < m_DiscreteTable.size(); j++)
|
||||
for (j = 0; j < pItem->m_yxcount; j++)
|
||||
{
|
||||
*bt_discrete = (BYTE)GetUnitYX(uid, m_DiscreteTable[j]); bt_discrete++;
|
||||
}
|
||||
@ -433,7 +443,7 @@ int CSubModbusTcpProcess::OnPackageReceived(BYTE* pBuf, int count, int ord)
|
||||
ppucFrame[usLength++] = eException;
|
||||
}
|
||||
|
||||
eStatus = eMBTCPSend(ucRcvAddress, ppucFrame, usLength);
|
||||
eStatus = eMBTCPSend(ucRcvAddress, ppucFrame, usLength, ord);
|
||||
if (eStatus != MB_ENOERR)
|
||||
{
|
||||
vLog(LOG_ERROR, "modbus tcp send error(%d)\n", eStatus);
|
||||
@ -443,7 +453,7 @@ int CSubModbusTcpProcess::OnPackageReceived(BYTE* pBuf, int count, int ord)
|
||||
return (count);
|
||||
}
|
||||
|
||||
eMBErrorCode CSubModbusTcpProcess::eMBTCPSend(BYTE ucSlaveAddress, const BYTE *pucFrame, WORD usLength)
|
||||
eMBErrorCode CSubModbusTcpProcess::eMBTCPSend(BYTE ucSlaveAddress, const BYTE *pucFrame, WORD usLength, int ord)
|
||||
{
|
||||
eMBErrorCode eStatus = MB_ENOERR;
|
||||
BYTE *pucMBTCPFrame = (BYTE *) pucFrame - MB_TCP_FUNC;
|
||||
@ -451,7 +461,7 @@ eMBErrorCode CSubModbusTcpProcess::eMBTCPSend(BYTE ucSlaveAddress, const BYTE *p
|
||||
|
||||
pucMBTCPFrame[MB_TCP_LEN] = (usLength + 1) >> 8U;
|
||||
pucMBTCPFrame[MB_TCP_LEN + 1] = (usLength + 1) & 0xFF;
|
||||
if (WriteData(pucMBTCPFrame, usTCPLength, GetCurOrder()))
|
||||
if (WriteData(pucMBTCPFrame, usTCPLength, ord))
|
||||
{
|
||||
DisplayTxData(pucMBTCPFrame, usTCPLength, TRUE);
|
||||
}
|
||||
|
@ -5,14 +5,6 @@
|
||||
#include "modbus_def.h"
|
||||
#include <vector>
|
||||
|
||||
#pragma pack(1)
|
||||
typedef struct
|
||||
{
|
||||
struNetWorkOption net;
|
||||
BYTE defaultYCType;
|
||||
} struSubModbusTCPOption;
|
||||
#pragma pack()
|
||||
|
||||
typedef std::vector<int> vecInt;
|
||||
|
||||
class CSubModbusTcpProcessItem : public CNetProcessItem
|
||||
@ -30,6 +22,12 @@ public:
|
||||
BYTE *m_pDiscreteRegTable;
|
||||
WORD *m_pHoldingRegTable;
|
||||
WORD *m_pInputRegTable;
|
||||
|
||||
int m_yccount;
|
||||
int m_ymcount;
|
||||
int m_yxcount;
|
||||
int m_ykcount;
|
||||
int m_ytcount;
|
||||
|
||||
public:
|
||||
CSubModbusTcpProcessItem();
|
||||
@ -70,7 +68,7 @@ private:
|
||||
int OnPackageReceived(BYTE* pBuf, int count, int ord /* = -1 */);
|
||||
BOOLEAN OnReceiveData(CSubModbusTcpProcessItem *pItem, BYTE* pData, int count, int uid);
|
||||
|
||||
eMBErrorCode eMBTCPSend(BYTE ucSlaveAddress, const BYTE *pucFrame, WORD usLength);
|
||||
eMBErrorCode eMBTCPSend(BYTE ucSlaveAddress, const BYTE *pucFrame, WORD usLength, int);
|
||||
|
||||
eMBException prveMBError2Exception(eMBErrorCode eErrorCode);
|
||||
eMBException eMBFuncReadInputRegister(CSubModbusTcpProcessItem *pItem, BYTE* pucFrame, WORD* usLen);
|
||||
|
8
das-dn/third_party/nopoll/nopoll_conn.c
vendored
8
das-dn/third_party/nopoll/nopoll_conn.c
vendored
@ -3244,8 +3244,7 @@ noPollMsg * nopoll_conn_get_msg (noPollConn * conn)
|
||||
/* update remaining bytes */
|
||||
msg->payload_size = msg->remain_bytes;
|
||||
nopoll_free (msg->payload);
|
||||
nopoll_log (conn->ctx, NOPOLL_LEVEL_DEBUG, "reusing noPollMsg reference (%p) since last payload read was 0, remaining: %d", msg,
|
||||
msg->payload_size);
|
||||
nopoll_log (conn->ctx, NOPOLL_LEVEL_DEBUG, "reusing noPollMsg reference (%p) since last payload read was 0, remaining: %d", msg, msg->payload_size);
|
||||
}
|
||||
|
||||
/* nullify references */
|
||||
@ -3384,6 +3383,7 @@ noPollMsg * nopoll_conn_get_msg (noPollConn * conn)
|
||||
msg->payload_size = nopoll_get_16bit (buffer + 2);
|
||||
|
||||
nopoll_log (conn->ctx, NOPOLL_LEVEL_DEBUG, "Received (%d) bytes in header (size %d) for payload size indication, which finally is: %d", bytes, header_size,(int) msg->payload_size);
|
||||
fprintf(stderr, "Received (%d) bytes in header (size %d) for payload size indication, which finally is: %d\n", bytes, header_size,(int) msg->payload_size);
|
||||
|
||||
} else if (msg->payload_size == 127) {
|
||||
/* read more content (next 8 bytes) */
|
||||
@ -3395,7 +3395,7 @@ noPollMsg * nopoll_conn_get_msg (noPollConn * conn)
|
||||
return NULL;
|
||||
} /* end if */
|
||||
|
||||
len = (unsigned char*)buffer;
|
||||
len = (unsigned char*)buffer;
|
||||
msg->payload_size = 0;
|
||||
#if defined(NOPOLL_64BIT_PLATFORM)
|
||||
msg->payload_size |= ((long)(len[0]) << 56);
|
||||
@ -3479,6 +3479,8 @@ noPollMsg * nopoll_conn_get_msg (noPollConn * conn)
|
||||
|
||||
nopoll_log (conn->ctx, NOPOLL_LEVEL_DEBUG, "Detected incoming websocket frame: fin(%d), op_code(%d), is_masked(%d), payload size(%ld), mask=%d",
|
||||
msg->has_fin, msg->op_code, msg->is_masked, msg->payload_size, nopoll_get_32bit (msg->mask));
|
||||
fprintf(stderr, "Detected incoming websocket frame: fin(%d), op_code(%d), is_masked(%d), payload size(%ld), mask=%d\n",
|
||||
msg->has_fin, msg->op_code, msg->is_masked, msg->payload_size, nopoll_get_32bit (msg->mask));
|
||||
|
||||
/* check payload size */
|
||||
if (msg->payload_size == 0) {
|
||||
|
@ -809,7 +809,7 @@ BOOLEAN CZJD3100Process::OnSyntaxUnitYC(char *pData, int uid, int ord)
|
||||
}
|
||||
else
|
||||
{
|
||||
value = (float)config.units[uid].ycs[i].value * database.ycs[udb].coef + database.ycs[udb].base;
|
||||
value = (float)config.units[uid].ycs[i].value * config.units[uid].ycs[i].coef + config.units[uid].ycs[i].base;
|
||||
}
|
||||
sprintf(buffer, "%4d %5.3f %-2s\t", i, value, ((config.units[uid].ycs[i].qds & 0x80) ? "IV" : " "));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user