update
This commit is contained in:
parent
8e3e084954
commit
3c910cfdc8
@ -1,4 +1,5 @@
|
||||
#include "ry.h"
|
||||
#include <math.h>
|
||||
|
||||
CRYDevice::CRYDevice()
|
||||
{
|
||||
@ -275,10 +276,12 @@ BOOLEAN CRYDevice::websocket_msg_join(noPollMsg **msg, int msg_count, BYTE* &buf
|
||||
len += nopoll_msg_get_payload_size(msg[i]);
|
||||
}
|
||||
buffer[buffer_size] = 0;
|
||||
|
||||
vLog(LOG_DEBUG, "buffer size is: %ld.\n", buffer_size);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int CRYDevice::websocket_write(noPollConn* conn, const char * buffer, int buffer_len)
|
||||
int CRYDevice::websocket_write(const char * buffer, int buffer_len)
|
||||
{
|
||||
int result;
|
||||
result = nopoll_conn_send_text(conn, (const char *)buffer, buffer_len);
|
||||
@ -287,7 +290,7 @@ int CRYDevice::websocket_write(noPollConn* conn, const char * buffer, int buffer
|
||||
return (result == buffer_len) ? 0 : -1;
|
||||
}
|
||||
|
||||
bool CRYDevice::publish_sensor_data(noPollConn* conn, const std::string traceId, const char* command, const Json::Value payload)
|
||||
bool CRYDevice::publish_sensor_data(const std::string traceId, const char* command, const Json::Value payload)
|
||||
{
|
||||
Json::StreamWriterBuilder builder;
|
||||
builder["indentation"] = "";
|
||||
@ -311,8 +314,11 @@ bool CRYDevice::publish_sensor_data(noPollConn* conn, const std::string traceId,
|
||||
jsonRoot["data"] = payload;
|
||||
|
||||
std::string outputConfig = Json::writeString(builder, jsonRoot);
|
||||
vLog(LOG_DEBUG, "send cmd: %s, payload: %d\n", command, outputConfig.length());
|
||||
int rc = websocket_write(conn, outputConfig.c_str(), outputConfig.length());
|
||||
if (traceId != "")
|
||||
{
|
||||
vLog(LOG_DEBUG, "send cmd: %s, payload: %d, %128s\n", command, outputConfig.length(), outputConfig.c_str());
|
||||
}
|
||||
int rc = websocket_write(outputConfig.c_str(), outputConfig.length());
|
||||
if (rc != 0) {
|
||||
vLog(LOG_DEBUG, "websocket write is error<%d>,insert into database.\n", rc);
|
||||
//插入数据库
|
||||
@ -340,7 +346,39 @@ int CRYDevice::GetUnitYMCount(int uid)
|
||||
return config.units[uid].ymcount;
|
||||
}
|
||||
|
||||
float CRYDevice::GetUnitYCReal(int uid, int order)
|
||||
LONG CRYDevice::GetUnitYC(int uid, int order) const
|
||||
{
|
||||
int udb;
|
||||
LONG value;
|
||||
struUnit* pUnit;
|
||||
struUnitYC* pYC;
|
||||
|
||||
if (uid < 0 || uid >= UNIT_NUM) return 0;
|
||||
pUnit = &config.units[uid];
|
||||
if ((pUnit->state & 0x01) != TRUE) return 0;
|
||||
if (order < 0 || order >= pUnit->yccount) return 0;
|
||||
pYC = &pUnit->ycs[order];
|
||||
udb = pYC->order;
|
||||
if (udb < 0 || udb >= DATABASE_YC_NUM)
|
||||
{
|
||||
value = pYC->value;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = database.ycs[udb].value;
|
||||
pYC->value = value;
|
||||
pYC->update_time = database.ycs[udb].update_time;
|
||||
pYC->qds = database.ycs[udb].qds;
|
||||
}
|
||||
if (pYC->factor > 1 && (pUnit->type & 0x0f) == 0x00)
|
||||
{ //系数有效,且为转发单元
|
||||
value /= pYC->factor;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
float CRYDevice::GetUnitYCReal(int uid, int order) const
|
||||
{
|
||||
int udb;
|
||||
long value;
|
||||
@ -369,7 +407,7 @@ float CRYDevice::GetUnitYCReal(int uid, int order)
|
||||
return (float)((float)value * coef + base);
|
||||
}
|
||||
|
||||
float CRYDevice::GetUnitYCRealFromValue(int uid, int order, long value)
|
||||
float CRYDevice::GetUnitYCRealFromValue(int uid, int order, long value) const
|
||||
{
|
||||
int udb;
|
||||
float coef;
|
||||
@ -393,6 +431,64 @@ float CRYDevice::GetUnitYCRealFromValue(int uid, int order, long value)
|
||||
return (float)(value * coef + base);
|
||||
}
|
||||
|
||||
BOOLEAN CRYDevice::GetUnitYCIsFloat(int uid, int order) const
|
||||
{
|
||||
int udb;
|
||||
float coef = 1.0f;
|
||||
struUnit* pUnit;
|
||||
struUnitYC* pYC;
|
||||
if (uid < 0 || uid >= UNIT_NUM) return 0;
|
||||
pUnit = &config.units[uid];
|
||||
if ((pUnit->state & 0x01) != TRUE) return 0;
|
||||
if (order < 0 || order >= pUnit->yccount) return 0;
|
||||
pYC = &pUnit->ycs[order];
|
||||
udb = pYC->order;
|
||||
if (udb < 0 || udb >= DATABASE_YC_NUM)
|
||||
{
|
||||
coef = 1.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
coef = pYC->coef;
|
||||
}
|
||||
|
||||
if (fabsf(coef) <= 1E-8) coef = 1.0f;
|
||||
if (fabsf(coef - 1.0f) <= 1E-8) return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
float CRYDevice::GetUnitYCLimitReal(int uid, int order, int type) const
|
||||
{
|
||||
float limitValue;
|
||||
struUnit* pUnit;
|
||||
struUnitYC* pYC;
|
||||
if (uid < 0 || uid >= UNIT_NUM) return 0;
|
||||
pUnit = &config.units[uid];
|
||||
if ((pUnit->state & 0x01) != TRUE) return 0;
|
||||
if (order < 0 || order >= pUnit->yccount) return 0;
|
||||
pYC = &pUnit->ycs[order];
|
||||
|
||||
//1-越上限 2-越下限)
|
||||
if (type == 1)
|
||||
{
|
||||
limitValue = pYC->limit1High;
|
||||
}
|
||||
else if (type == 2)
|
||||
{
|
||||
limitValue = pYC->limit1Low;
|
||||
}
|
||||
else if (type == 3)
|
||||
{
|
||||
limitValue = pYC->limit2High;
|
||||
}
|
||||
else if (type == 4)
|
||||
{
|
||||
limitValue = pYC->limit2Low;
|
||||
}
|
||||
|
||||
return limitValue;
|
||||
}
|
||||
|
||||
float CRYDevice::GetUnitYMReal(int uid, int order)
|
||||
{
|
||||
int udb;
|
||||
@ -444,10 +540,13 @@ BYTE CRYDevice::GetUnitYX(int uid, int point)
|
||||
return value;
|
||||
}
|
||||
|
||||
int CRYDevice::GetUnitYXBW(int& uid, BOOLEAN& value, BYTE& qds, int& type, unionCP56Time& st)
|
||||
int CRYDevice::GetUnitYXBW(int& uid, BOOLEAN& value, unionCP56Time& st)
|
||||
{
|
||||
int order;
|
||||
int point;
|
||||
int type;
|
||||
BYTE qds;
|
||||
|
||||
|
||||
while (yxbw.GetYXBW(m_yxbwload, st, order, value, qds, uid, point, type))
|
||||
{
|
||||
@ -470,10 +569,11 @@ int CRYDevice::GetUnitSOE(int& uid, BOOLEAN& value, BYTE& qds, unionCP56Time& st
|
||||
return -1;
|
||||
}
|
||||
|
||||
int CRYDevice::GetUnitYCBW(int& uid, LONG& value, BYTE& qds, int& type, unionCP56Time& st)
|
||||
int CRYDevice::GetUnitYCBW(int& uid, LONG& value, int& type, unionCP56Time& st)
|
||||
{
|
||||
int order;
|
||||
int point;
|
||||
BYTE qds;
|
||||
|
||||
while (ycbw.GetYCBW(m_ycbwload, st, order, value, qds, uid, point, type)) {
|
||||
m_ycbwload++;
|
||||
@ -751,7 +851,7 @@ void CRYDevice::SetUnitYT(int uid, int order, DWORD value, BYTE act, BYTE result
|
||||
}
|
||||
}
|
||||
|
||||
int CRYDevice::MakeYKFrame(noPollConn* conn, int uid)
|
||||
int CRYDevice::MakeYKFrame(int uid)
|
||||
{
|
||||
int order;
|
||||
BYTE value, action, result;
|
||||
@ -790,13 +890,13 @@ int CRYDevice::MakeYKFrame(noPollConn* conn, int uid)
|
||||
jsonRoot["result"] = true;
|
||||
}
|
||||
|
||||
publish_sensor_data(conn, m_traceId, "deviceControlResp", jsonRoot);
|
||||
publish_sensor_data(m_traceId, "deviceControlResp", jsonRoot);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CRYDevice::MakeYTFrame(noPollConn* conn, int uid)
|
||||
int CRYDevice::MakeYTFrame(int uid)
|
||||
{
|
||||
int order;
|
||||
BYTE action, result;
|
||||
@ -834,7 +934,7 @@ int CRYDevice::MakeYTFrame(noPollConn* conn, int uid)
|
||||
jsonRoot["result"] = true;
|
||||
}
|
||||
|
||||
publish_sensor_data(conn, m_traceId, "deviceControlResp", jsonRoot);
|
||||
publish_sensor_data(m_traceId, "deviceControlResp", jsonRoot);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -1081,13 +1181,13 @@ BOOLEAN CRYDevice::processModbusPointParam(const Json::Value jsonRoot, int uid,
|
||||
} else {
|
||||
config_config.units[uid].ycs[point].m_param[0] = 0;
|
||||
}
|
||||
if (jsonRoot["col3"].isString()) {
|
||||
BYTE dataType = (BYTE)atoi(jsonRoot["col3"].asCString());
|
||||
if (jsonRoot["col2"].isString()) {
|
||||
BYTE dataType = (BYTE)atoi(jsonRoot["col2"].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["col3"].isInt()) {
|
||||
BYTE dataType = jsonRoot["col3"].asInt();
|
||||
} else if (jsonRoot["col2"].isInt()) {
|
||||
BYTE dataType = jsonRoot["col2"].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;
|
||||
@ -1095,11 +1195,11 @@ 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["col2"].isString()) {
|
||||
BYTE signMark = (BYTE)atoi(jsonRoot["col2"].asCString());
|
||||
if (jsonRoot["col3"].isString()) {
|
||||
BYTE signMark = (BYTE)atoi(jsonRoot["col3"].asCString());
|
||||
config_config.units[uid].ycs[point].m_param[5] = signMark;
|
||||
} else if (jsonRoot["col2"].isInt()) {
|
||||
BYTE signMark = jsonRoot["col2"].asInt();
|
||||
} else if (jsonRoot["col3"].isInt()) {
|
||||
BYTE signMark = jsonRoot["col3"].asInt();
|
||||
config_config.units[uid].ycs[point].m_param[5] = signMark;
|
||||
} else {
|
||||
config_config.units[uid].ycs[point].m_param[5] = 0;
|
||||
@ -1693,7 +1793,7 @@ bool CRYDevice::dealConfigFile(const Json::Value jsonRoot)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CRYDevice::OnReceivedSystemAction(noPollConn* conn, const std::string cmdId, const std::string cmd, const Json::Value data)
|
||||
bool CRYDevice::OnReceivedSystemAction(const std::string cmdId, const std::string cmd, const Json::Value data)
|
||||
{
|
||||
do {
|
||||
if (cmd == "configUpdate") { //配置更新
|
||||
@ -1710,7 +1810,7 @@ bool CRYDevice::OnReceivedSystemAction(noPollConn* conn, const std::string cmdId
|
||||
return true;
|
||||
}
|
||||
|
||||
void CRYDevice::on_message(noPollConn* conn, const char *msg, const int size)
|
||||
void CRYDevice::on_message(const char *msg, const int size)
|
||||
{
|
||||
if (msg == NULL) return;
|
||||
if (size <= 0) return;
|
||||
@ -1742,11 +1842,11 @@ void CRYDevice::on_message(noPollConn* conn, const char *msg, const int size)
|
||||
Json::Int64 mtime = jsonRoot["time"].asInt64();
|
||||
#endif
|
||||
Json::Value datas = jsonRoot["data"];
|
||||
OnReceivedSystemAction(conn, cmdId, cmd, datas);
|
||||
OnReceivedSystemAction(cmdId, cmd, datas);
|
||||
} while (0);
|
||||
}
|
||||
|
||||
void CRYDevice::heart_beat(noPollConn* conn, int status)
|
||||
void CRYDevice::heart_beat(int status)
|
||||
{
|
||||
//发送心跳报文
|
||||
Json::Value payload;
|
||||
@ -1756,7 +1856,6 @@ void CRYDevice::heart_beat(noPollConn* conn, int status)
|
||||
if (status == 1) {
|
||||
Json::Value jsonItem;
|
||||
Json::Value jsonValue;
|
||||
//for (int i = 0; i < static_cast<int>(m_gLinkIDs.size()); i++) {
|
||||
for (int i = 0; i < PROCESSES_NUM - 1; i++) {
|
||||
if (config.processes[i].state == TRUE) {
|
||||
char linkId[32];
|
||||
@ -1771,11 +1870,11 @@ void CRYDevice::heart_beat(noPollConn* conn, int status)
|
||||
}
|
||||
}
|
||||
|
||||
publish_sensor_data(conn, "", "heartbeat", payload);
|
||||
publish_sensor_data("", "heartbeat", payload);
|
||||
}
|
||||
|
||||
|
||||
bool CRYDevice::publishinitDeviceData(noPollConn* conn, int uid)
|
||||
bool CRYDevice::publishinitDeviceData(int uid)
|
||||
{
|
||||
if (uid < 0 || uid >= UNIT_NUM) return false;
|
||||
|
||||
@ -1813,12 +1912,12 @@ bool CRYDevice::publishinitDeviceData(noPollConn* conn, int uid)
|
||||
root["values"] = values;
|
||||
|
||||
config.units[uid].state |= 0x40;
|
||||
return publish_sensor_data(conn, "", "initDeviceData", root);
|
||||
return publish_sensor_data("", "initDeviceData", root);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CRYDevice::publishAnalogData(noPollConn* conn, int uid)
|
||||
bool CRYDevice::publishAnalogData(int uid)
|
||||
{
|
||||
if (uid < 0 || uid >= UNIT_NUM) return false;
|
||||
Json::Value root;
|
||||
@ -1826,7 +1925,11 @@ bool CRYDevice::publishAnalogData(noPollConn* conn, int uid)
|
||||
int count = GetUnitYCCount(uid);
|
||||
if (count) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (GetUnitYCIsFloat(uid, i)) {
|
||||
values[(const char *)config.units[uid].ycs[i].name] = GetUnitYCReal(uid, i);
|
||||
} else {
|
||||
values[(const char *)config.units[uid].ycs[i].name] = GetUnitYC(uid, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (values.size()) {
|
||||
@ -1835,12 +1938,12 @@ bool CRYDevice::publishAnalogData(noPollConn* conn, int uid)
|
||||
root["dataTime"] = datatime;
|
||||
root["deviceId"] = static_units[uid].deviceId;
|
||||
root["values"] = values;
|
||||
return publish_sensor_data(conn, "", "analogData", root);
|
||||
return publish_sensor_data("", "analogData", root);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CRYDevice::publishStateData(noPollConn* conn, int uid)
|
||||
bool CRYDevice::publishStateData(int uid)
|
||||
{
|
||||
if (uid < 0 || uid >= UNIT_NUM) return false;
|
||||
Json::Value root;
|
||||
@ -1857,35 +1960,65 @@ bool CRYDevice::publishStateData(noPollConn* conn, int uid)
|
||||
root["dataTime"] = datatime;
|
||||
root["deviceId"] = static_units[uid].deviceId;
|
||||
root["values"] = values;
|
||||
return publish_sensor_data(conn, "", "stateData", root);
|
||||
return publish_sensor_data("", "stateData", root);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CRYDevice::publishHistoryAnalogData(noPollConn* conn, int uid)
|
||||
bool CRYDevice::publishdeviceEventData(void)
|
||||
{
|
||||
if (uid < 0 || uid >= UNIT_NUM) return false;
|
||||
Json::Value root;
|
||||
Json::Value values;
|
||||
if (values.size()) {
|
||||
root["deviceId"] = static_units[uid].deviceId;
|
||||
root["values"] = values;
|
||||
return publish_sensor_data(conn, "", "historyAnalogData", root);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
int i;
|
||||
int uid;
|
||||
int yxbw_point;
|
||||
BOOLEAN yxbw_value;
|
||||
unionCP56Time yxbw_time;
|
||||
|
||||
bool CRYDevice::publishHistoryStateData(noPollConn* conn, int uid)
|
||||
{
|
||||
if (uid < 0 || uid >= UNIT_NUM) return false;
|
||||
Json::Value root;
|
||||
Json::Value values;
|
||||
if (values.size()) {
|
||||
root["deviceId"] = static_units[uid].deviceId;
|
||||
root["values"] = values;
|
||||
return publish_sensor_data(conn, "", "historyStateData", root);
|
||||
Json::Value value;
|
||||
|
||||
for (i = 0; i < DATABASE_YXBW_NUM; i++)
|
||||
{
|
||||
yxbw_point = GetUnitYXBW(uid, yxbw_value, yxbw_time);
|
||||
if (yxbw_point < 0) break;
|
||||
value["deviceId"] = static_units[uid].deviceId;
|
||||
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;
|
||||
value["limitValue"] = Json::Value::null;
|
||||
|
||||
root.append(value);
|
||||
}
|
||||
return false;
|
||||
|
||||
int ycbw_point;
|
||||
int ycbw_type;
|
||||
LONG ycbw_value;
|
||||
unionCP56Time ycbw_time;
|
||||
|
||||
for (i = 0; i < DATABASE_YCBW_NUM; i++)
|
||||
{
|
||||
ycbw_point = GetUnitYCBW(uid, ycbw_value, ycbw_type, ycbw_time);
|
||||
if (ycbw_point < 0) break;
|
||||
value["deviceId"] = static_units[uid].deviceId;
|
||||
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;
|
||||
value["limitValue"] = GetUnitYCLimitReal(uid, ycbw_point, ycbw_type);
|
||||
|
||||
root.append(value);
|
||||
}
|
||||
|
||||
if (root.size()) {
|
||||
//return publish_sensor_data("", "deviceEvent", root);
|
||||
vLog(LOG_DEBUG, "%s", root.toStyledString().c_str());
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void CRYDevice::releaseAllUnits(void)
|
||||
@ -1969,30 +2102,37 @@ bool CRYDevice::ry_run(void)
|
||||
nopoll_bool isOk = nopoll_conn_is_ready(conn);
|
||||
if (isOk) {
|
||||
last_connect_sec = system32.timers;
|
||||
int msg_count = 0;
|
||||
noPollMsg *msg[2048];
|
||||
|
||||
while ((msg[msg_count] = nopoll_conn_get_msg(conn)) != NULL) {
|
||||
vLog(LOG_DEBUG, "recv length = %d, %d\n", nopoll_msg_get_payload_size(msg[msg_count]), nopoll_msg_is_final(msg[msg_count]));
|
||||
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]));
|
||||
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);
|
||||
}
|
||||
if (nopoll_msg_is_final(msg[msg_count])) {
|
||||
msg_count++;
|
||||
break;
|
||||
} else {
|
||||
msg_count++;
|
||||
}
|
||||
}
|
||||
if (msg_count > 0) {
|
||||
int buffer_len;
|
||||
BYTE *buffer = NULL;
|
||||
if (websocket_msg_join(msg, msg_count, buffer, buffer_len)) {
|
||||
if (buffer) {
|
||||
on_message(conn, (const char *)buffer, buffer_len);
|
||||
on_message((const char *)buffer, buffer_len);
|
||||
delete [] buffer;
|
||||
buffer = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < msg_count; i++) {
|
||||
nopoll_msg_unref(msg[i]);
|
||||
msg_count = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
msg_count++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (last_connect_sec > 0 && system32.timers > (last_connect_sec + 30)) {
|
||||
@ -2015,19 +2155,20 @@ bool CRYDevice::ry_run(void)
|
||||
}
|
||||
if (sec_changed) {
|
||||
if ((last_sec % 20) == 0) {
|
||||
heart_beat(conn, status);
|
||||
heart_beat(status);
|
||||
}
|
||||
}
|
||||
publishdeviceEventData();
|
||||
for (int i = 0; i < UNIT_NUM; i++) {
|
||||
if ((config.units[i].state & 0x01) != TRUE) continue;
|
||||
MakeYKFrame(conn, i);
|
||||
MakeYTFrame(conn, i);
|
||||
MakeYKFrame(i);
|
||||
MakeYTFrame(i);
|
||||
if (sec_changed) {
|
||||
//publishinitDeviceData(conn, i);
|
||||
if ((last_sec % 60) == 0) { //更新数据
|
||||
publishAnalogData(conn, i);
|
||||
publishStateData(conn, i);
|
||||
}
|
||||
//publishinitDeviceData(i);
|
||||
// if ((last_sec % 10) == 0) { //更新数据
|
||||
publishAnalogData(i);
|
||||
publishStateData(i);
|
||||
// }
|
||||
}
|
||||
}
|
||||
return m_dataAcquisitionReload;
|
||||
|
@ -80,6 +80,9 @@ private:
|
||||
DWORD last_connect_sec = 0;
|
||||
int status;
|
||||
|
||||
int msg_count = 0;
|
||||
noPollMsg *msg[2048];
|
||||
|
||||
bool m_dataAcquisitionReload = false;
|
||||
|
||||
char m_host[256] = {"127.0.0.1"};
|
||||
@ -105,37 +108,43 @@ private:
|
||||
int GetUnitYXCount(int uid);
|
||||
int GetUnitYCCount(int uid);
|
||||
int GetUnitYMCount(int uid);
|
||||
float GetUnitYCReal(int uid, int order);
|
||||
float GetUnitYCRealFromValue(int uid, int order, long value);
|
||||
LONG GetUnitYC(int uid, int order) const;
|
||||
float GetUnitYCReal(int uid, int order) const;
|
||||
float GetUnitYCRealFromValue(int uid, int order, long value) const;
|
||||
BOOLEAN GetUnitYCIsFloat(int uid, int order) const;
|
||||
float GetUnitYCLimitReal(int uid, int order, int type = 1) const;
|
||||
float GetUnitYMReal(int uid, int order);
|
||||
BYTE GetUnitYX(int uid, int point);
|
||||
int GetUnitYXBW(int& uid, BOOLEAN& value, BYTE& qds, int& type, unionCP56Time& st);
|
||||
int GetUnitYXBW(int& uid, BOOLEAN& value, unionCP56Time& st);
|
||||
int GetUnitSOE(int& uid, BOOLEAN& value, BYTE& qds, unionCP56Time& st);
|
||||
int GetUnitYCBW(int& uid, LONG& value, BYTE& qds, int& type, unionCP56Time& st);
|
||||
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(noPollConn* conn, int uid);
|
||||
int MakeYTFrame(noPollConn* conn, int uid);
|
||||
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(noPollConn* conn, const std::string cmdId, const std::string cmd, const Json::Value data);
|
||||
void on_message(noPollConn* conn, const char *msg, const int size);
|
||||
bool OnReceivedSystemAction(const std::string cmdId, const std::string cmd, const Json::Value data);
|
||||
void on_message(const char *msg, const int size);
|
||||
|
||||
void heart_beat(noPollConn* conn, int status);
|
||||
bool publishinitDeviceData(noPollConn* conn, int uid);
|
||||
bool publishAnalogData(noPollConn* conn, int uid);
|
||||
bool publishStateData(noPollConn* conn, int uid);
|
||||
bool publishHistoryAnalogData(noPollConn* conn, int uid);
|
||||
bool publishHistoryStateData(noPollConn* conn, int uid);
|
||||
void heart_beat(int status);
|
||||
bool publishinitDeviceData(int uid);
|
||||
bool publishAnalogData(int uid);
|
||||
bool publishStateData(int uid);
|
||||
bool publishHistoryAnalogData(int uid);
|
||||
bool publishHistoryStateData(int uid);
|
||||
bool publishdeviceEventData(void);
|
||||
BOOLEAN publishYXBWData(int uid);
|
||||
BOOLEAN publishYCBWData(int uid);
|
||||
|
||||
BOOLEAN websocket_msg_join(noPollMsg **msg, int msg_count, BYTE* &buffer, int &buffer_size);
|
||||
int websocket_write(noPollConn* conn, const char * buffer, int buffer_len);
|
||||
bool publish_sensor_data(noPollConn* conn, const std::string traceId, const char* command, const Json::Value payload);
|
||||
int websocket_write(const char * buffer, int buffer_len);
|
||||
bool publish_sensor_data(const std::string traceId, const char* command, const Json::Value payload);
|
||||
};
|
||||
#endif //_RY_H_
|
@ -879,8 +879,6 @@ float CProcess::GetUnitYCRealFromValue(int uid, int order, long value) const
|
||||
base = 0.0f;
|
||||
}
|
||||
else {
|
||||
// coef = database.ycs[udb].coef;
|
||||
// base = database.ycs[udb].base;
|
||||
coef = pYC->coef;
|
||||
base = pYC->base;
|
||||
}
|
||||
@ -906,7 +904,6 @@ float CProcess::GetUnitYCCoef(int uid, int order) const
|
||||
}
|
||||
else
|
||||
{
|
||||
// coef = database.ycs[udb].coef;
|
||||
coef = pYC->coef;
|
||||
}
|
||||
|
||||
@ -933,7 +930,6 @@ float CProcess::GetUnitYCBase(int uid, int order) const
|
||||
}
|
||||
else
|
||||
{
|
||||
// base = database.ycs[udb].base;
|
||||
base = pYC->base;
|
||||
}
|
||||
|
||||
@ -1022,7 +1018,6 @@ float CProcess::GetUnitYMCoef(int uid, int order) const
|
||||
}
|
||||
else
|
||||
{
|
||||
// coef = database.yms[udb].coef;
|
||||
coef = pYM->coef;
|
||||
}
|
||||
|
||||
@ -1049,7 +1044,6 @@ float CProcess::GetUnitYMBase(int uid, int order) const
|
||||
}
|
||||
else
|
||||
{
|
||||
// base = database.yms[udb].base;
|
||||
base = pYM->base;
|
||||
}
|
||||
|
||||
|
@ -3,11 +3,7 @@
|
||||
#include <math.h>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
//Valid slave device addresses are in the range of 0 锟?C 247 decimal. //
|
||||
//The individual slave devices are assigned addresses in the range of 1 锟?C 247. //
|
||||
//Address 0 is used for the broadcast address, which all slave devices recognize.//
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef HAVE_FTP_PROCESS
|
||||
|
||||
#define MODBUSP_READ_ID 100 //读取文件及文件夹ID
|
||||
@ -43,9 +39,9 @@ struct {
|
||||
{ 2, 205 },
|
||||
{ 2, 206 },
|
||||
{ 2, 207 },
|
||||
{ 2, 208 },
|
||||
{ 2, 209 },
|
||||
{ 2, 210 },
|
||||
{ 2, 208 },
|
||||
{ 2, 211 },
|
||||
{ 2, 212 },
|
||||
{ 2, 213 },
|
||||
@ -183,7 +179,14 @@ struct {
|
||||
{ 2, 358 },
|
||||
{ 2, 359 },
|
||||
{ 2, 360 },
|
||||
{ 2, 361 }
|
||||
{ 2, 361 },
|
||||
{ 2, 362 },
|
||||
{ 2, 363 },
|
||||
{ 2, 364 },
|
||||
{ 2, 365 },
|
||||
{ 2, 366 },
|
||||
{ 2, 367 },
|
||||
{ 2, 368 }
|
||||
};
|
||||
|
||||
#include <curl/curl.h>
|
||||
@ -218,7 +221,7 @@ static bool publish_sensor_data(const noPollConn* conn, const char* command, con
|
||||
|
||||
std::string outputConfig = Json::writeString(builder, jsonRoot);
|
||||
int rc = websocket_write(conn, outputConfig.c_str(), outputConfig.length());
|
||||
vLog(LOG_DEBUG, "send cmd: %s, payload: %d\n%s\n", command, outputConfig.length(), outputConfig.c_str());
|
||||
//vLog(LOG_DEBUG, "send cmd: %s, payload: %d\n", command, outputConfig.length()/*, outputConfig.c_str()*/);
|
||||
if (rc != 0) {
|
||||
vLog(LOG_DEBUG, "websocket write is error<%d>,insert into database.\n", rc);
|
||||
//插入数据库
|
||||
@ -490,7 +493,7 @@ static size_t writefunc(void* ptr, size_t size, size_t nmemb, FILE* stream)
|
||||
|
||||
static int ftpget(const char* remote, const char* local, const char* user, const char* pwd, const long timeout = 3, struct memory* chunk = NULL)
|
||||
{
|
||||
vLog(LOG_DEBUG, "start to get %s to local %s, with name: %s, and password: %s.\n", remote, local, user, pwd);
|
||||
//vLog(LOG_DEBUG, "start to get %s to local %s, with name: %s, and password: %s.\n", remote, local, user, pwd);
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
CURL* curl = curl_easy_init();
|
||||
|
||||
@ -536,17 +539,18 @@ static int ftpget(const char* remote, const char* local, const char* user, const
|
||||
ret = curl_easy_perform(curl);
|
||||
#endif
|
||||
//vLog(LOG_DEBUG, "curl easy perform return value is: %d, and OK is: %d.\n", ret, CURLE_OK);
|
||||
#if 0
|
||||
int curl_state = 0;
|
||||
if (ret == CURLE_OK) curl_state = 1;
|
||||
else {
|
||||
vLog(LOG_ERROR, "%d,%s\n", ret, curl_easy_strerror(ret));
|
||||
//vLog(LOG_ERROR, "%d,%s\n", ret, curl_easy_strerror(ret));
|
||||
curl_state = 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
curl_easy_cleanup(curl);
|
||||
curl_global_cleanup();
|
||||
|
||||
return curl_state;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void* ryftp_process(void* param)
|
||||
@ -583,9 +587,10 @@ static void* ryftp_process(void* param)
|
||||
DWORD target_addr = mbt->target_addr;
|
||||
memset(ipaddress, '\0', sizeof(ipaddress));
|
||||
inet_ntop(AF_INET, &target_addr, ipaddress, 16);
|
||||
|
||||
#if 0
|
||||
struct timespec start, end;
|
||||
double elapsed_time = 0;
|
||||
#endif
|
||||
|
||||
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));
|
||||
@ -621,17 +626,17 @@ static void* ryftp_process(void* param)
|
||||
fields[len].start = reinterpret_cast<uintptr_t>(&t_data.iYPLevel) - reinterpret_cast<uintptr_t>(&t_data);
|
||||
fields[len].length = sizeof(t_data.iYPLevel);
|
||||
len++;
|
||||
fields[len].start = reinterpret_cast<uintptr_t>(&t_data.iGenSpeed1s) - reinterpret_cast<uintptr_t>(&t_data);
|
||||
fields[len].length = sizeof(t_data.iGenSpeed1s);
|
||||
fields[len].start = reinterpret_cast<uintptr_t>(&t_data.iWindSpeed_1sec) - reinterpret_cast<uintptr_t>(&t_data);
|
||||
fields[len].length = sizeof(t_data.iWindSpeed_1sec);
|
||||
len++;
|
||||
fields[len].start = reinterpret_cast<uintptr_t>(&t_data.iGenPower1s) - reinterpret_cast<uintptr_t>(&t_data);
|
||||
fields[len].length = sizeof(t_data.iGenPower1s);
|
||||
fields[len].start = reinterpret_cast<uintptr_t>(&t_data.iGenSpeed_1sec) - reinterpret_cast<uintptr_t>(&t_data);
|
||||
fields[len].length = sizeof(t_data.iGenSpeed_1sec);
|
||||
len++;
|
||||
fields[len].start = reinterpret_cast<uintptr_t>(&t_data.iWindSpeed1s) - reinterpret_cast<uintptr_t>(&t_data);
|
||||
fields[len].length = sizeof(t_data.iWindSpeed1s);
|
||||
fields[len].start = reinterpret_cast<uintptr_t>(&t_data.iGenPower_1sec) - reinterpret_cast<uintptr_t>(&t_data);
|
||||
fields[len].length = sizeof(t_data.iGenPower_1sec);
|
||||
len++;
|
||||
fields[len].start = reinterpret_cast<uintptr_t>(&t_data.iGenToruqe1s) - reinterpret_cast<uintptr_t>(&t_data);
|
||||
fields[len].length = sizeof(t_data.iGenToruqe1s);
|
||||
fields[len].start = reinterpret_cast<uintptr_t>(&t_data.iGenToruqe_1sec) - reinterpret_cast<uintptr_t>(&t_data);
|
||||
fields[len].length = sizeof(t_data.iGenToruqe_1sec);
|
||||
len++;
|
||||
fields[len].start = reinterpret_cast<uintptr_t>(&t_data.iRotorSpeed) - reinterpret_cast<uintptr_t>(&t_data);
|
||||
fields[len].length = sizeof(t_data.iRotorSpeed);
|
||||
@ -1044,6 +1049,27 @@ static void* ryftp_process(void* param)
|
||||
fields[len].start = reinterpret_cast<uintptr_t>(&t_data.SCW042) - reinterpret_cast<uintptr_t>(&t_data);
|
||||
fields[len].length = sizeof(t_data.SCW042);
|
||||
len++;
|
||||
fields[len].start = reinterpret_cast<uintptr_t>(&t_data.iGenSpeed_10sec) - reinterpret_cast<uintptr_t>(&t_data);
|
||||
fields[len].length = sizeof(t_data.iGenSpeed_10sec);
|
||||
len++;
|
||||
fields[len].start = reinterpret_cast<uintptr_t>(&t_data.iGenSpeed_30sec) - reinterpret_cast<uintptr_t>(&t_data);
|
||||
fields[len].length = sizeof(t_data.iGenSpeed_30sec);
|
||||
len++;
|
||||
fields[len].start = reinterpret_cast<uintptr_t>(&t_data.iGenPower_10sec) - reinterpret_cast<uintptr_t>(&t_data);
|
||||
fields[len].length = sizeof(t_data.iGenPower_10sec);
|
||||
len++;
|
||||
fields[len].start = reinterpret_cast<uintptr_t>(&t_data.iGenPower_30sec) - reinterpret_cast<uintptr_t>(&t_data);
|
||||
fields[len].length = sizeof(t_data.iGenPower_30sec);
|
||||
len++;
|
||||
fields[len].start = reinterpret_cast<uintptr_t>(&t_data.iWindSpeed_10sec) - reinterpret_cast<uintptr_t>(&t_data);
|
||||
fields[len].length = sizeof(t_data.iWindSpeed_10sec);
|
||||
len++;
|
||||
fields[len].start = reinterpret_cast<uintptr_t>(&t_data.iWindSpeed_30sec) - reinterpret_cast<uintptr_t>(&t_data);
|
||||
fields[len].length = sizeof(t_data.iWindSpeed_30sec);
|
||||
len++;
|
||||
fields[len].start = reinterpret_cast<uintptr_t>(&t_data.iAvailablePower) - reinterpret_cast<uintptr_t>(&t_data);
|
||||
fields[len].length = sizeof(t_data.iAvailablePower);
|
||||
len++;
|
||||
|
||||
|
||||
//判断是否链接单元
|
||||
@ -1085,7 +1111,7 @@ static void* ryftp_process(void* param)
|
||||
}
|
||||
|
||||
//根据实际配置表将
|
||||
|
||||
WORD ftpget_retry_count = 0;
|
||||
while (TRUE) {
|
||||
sleep(1); //每秒执行一次
|
||||
//ftp获取文件
|
||||
@ -1096,11 +1122,15 @@ static void* ryftp_process(void* param)
|
||||
|
||||
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);
|
||||
|
||||
#if 0
|
||||
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||
#endif
|
||||
struct memory chunk = {0}; // For storing the downloaded data
|
||||
if (ftpget(remote, name, user, password, 3, &chunk)) {
|
||||
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);
|
||||
ftpget_retry_count = 0;
|
||||
struRYDeviceData *data = (struRYDeviceData *)chunk.response;
|
||||
unionCP56Time st;
|
||||
int uid = mbt->GetCurUnitID();
|
||||
@ -1173,11 +1203,11 @@ static void* ryftp_process(void* param)
|
||||
}
|
||||
}
|
||||
if (chunk.response) free(chunk.response);
|
||||
//vLog(LOG_DEBUG, "get a file, then send to ws.\n");
|
||||
#if 0
|
||||
clock_gettime(CLOCK_MONOTONIC, &end);
|
||||
elapsed_time = (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) / 1e9;
|
||||
vLog(LOG_DEBUG, "Elapsed time: %.6f seconds\n", elapsed_time);
|
||||
|
||||
#endif
|
||||
mbt->m_lastFileNo = mbt->m_currentFileNo;
|
||||
mbt->m_currentFileNo++;
|
||||
if ((mbt->m_currentFileNo - mbt->m_lastStartFileNo) % 1000 == 0) {
|
||||
@ -1191,6 +1221,15 @@ static void* ryftp_process(void* param)
|
||||
#endif
|
||||
//保存文件信息
|
||||
}
|
||||
} else if (result == CURLE_REMOTE_FILE_NOT_FOUND) {
|
||||
//文件不存在,尝试60次(1分钟,正常情况下PLC10s生成一个文件)
|
||||
ftpget_retry_count++;
|
||||
if (ftpget_retry_count >= 60) {
|
||||
//重新通过modbus程序获取文件夹和最新文件信息
|
||||
mbt->m_iv = 0;
|
||||
mbt->m_currentDirNo = -1;
|
||||
mbt->m_currentFileNo = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1642,9 +1681,8 @@ BOOLEAN CHostModbusTcpProcess::OnPreCreate(int id)
|
||||
m_nTimeout = 200;
|
||||
calc2();
|
||||
|
||||
vLog(LOG_DEBUG, "file size is: %d\n", sizeof(struRYDeviceData) * 250 / 1024);
|
||||
|
||||
#ifdef HAVE_FTP_PROCESS
|
||||
vLog(LOG_DEBUG, "file size is: %d\n", sizeof(struRYDeviceData) * 250 / 1024);
|
||||
//启动后,创建ftp线程
|
||||
if (m_pid <= 0) {
|
||||
vLog(LOG_DEBUG, "create a ftp thread.\n");
|
||||
@ -2271,12 +2309,7 @@ BOOLEAN CHostModbusTcpProcess::OnReceiveIDData(CHostModbusTcpProcessItem *pItem,
|
||||
//当前文件夹下第一个文件
|
||||
m_lastStartFileNo = (DWORD)((pBuf[2] << 24) | (pBuf[3] << 16) | (pBuf[0] << 8) | pBuf[1]); pBuf += 4;
|
||||
|
||||
#if 0
|
||||
m_currentDirNo = 37;
|
||||
m_currentFileNo = 26901;
|
||||
m_lastStartFileNo = 26901;
|
||||
#endif
|
||||
vLog(LOG_DEBUG, "dir: %ld, file: %ld: start: %ld\n", m_currentDirNo, m_currentFileNo, m_lastStartFileNo);
|
||||
vLog(LOG_DEBUG, "最新文件夹编号: %ld, 最新文件名编号: %ld: 最新文件夹中第一个文件的编号: %ld\n", m_currentDirNo, m_currentFileNo, m_lastStartFileNo);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -2392,6 +2425,7 @@ BOOLEAN CHostModbusTcpProcess::OnReceiveYCData(CHostModbusTcpProcessItem *pItem,
|
||||
reg_count = pParam[3];
|
||||
value_type = pParam[4];
|
||||
sign_mark = pParam[5];
|
||||
//vLog(LOG_DEBUG, "here count is: %d, value type is: %d, and ", reg_count, value_type);
|
||||
if ((1 == reg_count) && (2 == value_type))
|
||||
{ //16位归一化值
|
||||
if (2 == value_type)
|
||||
@ -2399,6 +2433,7 @@ BOOLEAN CHostModbusTcpProcess::OnReceiveYCData(CHostModbusTcpProcessItem *pItem,
|
||||
if (sign_mark == 0) nValue = (DWORD)(WORD)((pBuf[0] << 8) | pBuf[1]);
|
||||
else nValue = (DWORD)(short)((pBuf[0] << 8) | pBuf[1]);
|
||||
SetUnitYC(uid, point, (LONG)nValue);
|
||||
//vLog(LOG_DEBUG, "value is: %ld.\n", nValue);
|
||||
}
|
||||
else if (8 == value_type)
|
||||
{
|
||||
@ -2429,6 +2464,7 @@ BOOLEAN CHostModbusTcpProcess::OnReceiveYCData(CHostModbusTcpProcessItem *pItem,
|
||||
{ //归一化值,高位在第一个寄存器
|
||||
nValue = (DWORD)(pBuf[0] << 24 | pBuf[1] << 16 | pBuf[2] << 8 | pBuf[3]);
|
||||
SetUnitYC(uid, point, (LONG)nValue);
|
||||
//vLog(LOG_DEBUG, "value is: %ld.\n", nValue);
|
||||
}
|
||||
else if (4 == value_type)
|
||||
{ //归一化值,高位在第二个寄存器
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include "netproc.h"
|
||||
#include "modbus_def.h"
|
||||
|
||||
#define HAVE_FTP_PROCESS
|
||||
//#define HAVE_FTP_PROCESS
|
||||
#ifdef HAVE_FTP_PROCESS
|
||||
#include <dirent.h>
|
||||
#include <nopoll.h>
|
||||
@ -21,10 +21,10 @@ typedef struct {
|
||||
WORD iTurbineOperationMode;// 运行模式 2 205 1 需要解析 1s 控制系统
|
||||
WORD iBPLevel;// 刹车等级 2 206 1 需要解析 1s 控制系统
|
||||
WORD iYPLevel;// 偏航运行模式 2 207 1 需要解析 1s 控制系统
|
||||
WORD iGenSpeed1s;// 发电机转速1秒均值 2 209 0.1 转/分 1s 控制系统
|
||||
WORD iGenPower1s;// 机组有功1秒均值 2 210 0.1 千瓦 1s 控制系统
|
||||
WORD iWindSpeed1s;// 风速1秒均值 2 208 0.01 米/秒 1s 控制系统
|
||||
WORD iGenToruqe1s;// 发电机扭矩1秒均值 2 211 0.1 牛米 1s 控制系统
|
||||
WORD iWindSpeed_1sec;// 风速1秒均值 2 208 0.01 米/秒 1s 控制系统
|
||||
WORD iGenSpeed_1sec;// 发电机转速1秒均值 2 209 0.1 转/分 1s 控制系统
|
||||
WORD iGenPower_1sec;// 机组有功1秒均值 2 210 0.1 千瓦 1s 控制系统
|
||||
WORD iGenToruqe_1sec;// 发电机扭矩1秒均值 2 211 0.1 牛米 1s 控制系统
|
||||
WORD iRotorSpeed;// 风轮转速 2 212 0.1 转/分 1s 控制系统
|
||||
WORD iTheoreticalPower;// 理论有功功率 2 213 0.1 千瓦 1s 控制系统
|
||||
WORD iReactivePower;// 无功功率 2 214 0.1 千乏 1s 控制系统
|
||||
@ -162,6 +162,13 @@ typedef struct {
|
||||
WORD SCW040;// 故障代码字40 2 359 1 1s 控制系统
|
||||
WORD SCW041;// 故障代码字41 2 360 1 1s 控制系统
|
||||
WORD SCW042;// 故障代码字42 2 361 1 1s 控制系统
|
||||
WORD iGenSpeed_10sec;// 发电机转速10秒均值 2 362
|
||||
WORD iGenSpeed_30sec;// 发电机转速30秒均值 2 363
|
||||
WORD iGenPower_10sec;// 机组有功10秒均值 2 364
|
||||
WORD iGenPower_30sec;// 机组有功30秒均值 2 365
|
||||
WORD iWindSpeed_10sec;// 风速10秒均值 2 366
|
||||
WORD iWindSpeed_30sec;// 风速30秒均值 2 367
|
||||
WORD iAvailablePower;// 可用有功功率 2 368
|
||||
} struRYDeviceData;
|
||||
#pragma pack()
|
||||
|
||||
|
@ -402,20 +402,52 @@ public:
|
||||
}
|
||||
} else if (database.ycs[udb].value != value) { //update value
|
||||
//此处增加越线判断
|
||||
float coef = pUnit->ycs[point].coef;
|
||||
float base = pUnit->ycs[point].base;
|
||||
float fValue = (float)((float)value * coef + base);
|
||||
if (pUnit->ycs[point].limit1Enable) {
|
||||
|
||||
if (fValue > pUnit->ycs[point].limit1High) { //越上限
|
||||
if (!pUnit->ycs[point].ycbw) {
|
||||
pUnit->ycs[point].ycbw = TRUE;
|
||||
ycbw.PushYCBW(system32.now, udb, value, qds, uid, point, 1);
|
||||
}
|
||||
} else if (fValue < pUnit->ycs[point].limit1Low) { //越下限
|
||||
if (!pUnit->ycs[point].ycbw) {
|
||||
pUnit->ycs[point].ycbw = TRUE;
|
||||
ycbw.PushYCBW(system32.now, udb, value, qds, uid, point, 2);
|
||||
}
|
||||
} else { //不越限
|
||||
if (pUnit->ycs[point].ycbw) {
|
||||
pUnit->ycs[point].ycbw = FALSE;
|
||||
ycbw.PushYCBW(system32.now, udb, value, qds, uid, point, 5);
|
||||
}
|
||||
}
|
||||
//默认二级越限必须大于一级越限
|
||||
if (pUnit->ycs[point].limit2Enable) {
|
||||
|
||||
if (fValue > pUnit->ycs[point].limit2High) { //越上限
|
||||
if (!pUnit->ycs[point].ycbw) {
|
||||
pUnit->ycs[point].ycbw = TRUE;
|
||||
ycbw.PushYCBW(system32.now, udb, value, qds, uid, point, 3);
|
||||
}
|
||||
} else if (fValue < pUnit->ycs[point].limit2Low) { //越下限
|
||||
if (!pUnit->ycs[point].ycbw) {
|
||||
pUnit->ycs[point].ycbw = TRUE;
|
||||
ycbw.PushYCBW(system32.now, udb, value, qds, uid, point, 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pUnit->ycs[point].value = value;
|
||||
pUnit->ycs[point].update_time = system32.timers;
|
||||
#if 0
|
||||
if (pUnit->ycs[point].change_pos >= 0 && bAddYCBW) {
|
||||
if (abs(pUnit->ycs[point].value - database.ycs[udb].value) >= pUnit->ycs[point].change_pos) { //40码值变化量认为是遥测变位
|
||||
pUnit->ycs[point].ycbw = TRUE;
|
||||
ycbw.PushYCBW(system32.now, udb, value, qds, uid, point, YCBWT_AUTO);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
database.ycs[udb].value = value;
|
||||
database.ycs[udb].op_unit = uid;
|
||||
database.ycs[udb].update_time = system32.timers; //设置刷新时间
|
||||
@ -458,12 +490,14 @@ public:
|
||||
}
|
||||
pUnit->ycs[point].value = nvalue;
|
||||
pUnit->ycs[point].update_time = system32.timers;
|
||||
#if 0
|
||||
if (pUnit->ycs[point].change_pos >= 0 && bAddYCBW) {
|
||||
if (abs(pUnit->ycs[point].value - database.ycs[udb].value) >= pUnit->ycs[point].change_pos) { //40码值变化量认为是遥测变位
|
||||
pUnit->ycs[point].ycbw = TRUE;
|
||||
ycbw.PushYCBW(system32.now, udb, nvalue, qds, uid, point, YCBWT_AUTO);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
database.ycs[udb].value = nvalue;
|
||||
database.ycs[udb].op_unit = uid;
|
||||
database.ycs[udb].update_time = system32.timers; //设置刷新时间
|
||||
|
@ -75,7 +75,7 @@ typedef int SOCKET;
|
||||
#define MAX_DISPLAY_BUFFER_SIZE 0x8000
|
||||
|
||||
#define HARDWARE_PORTS_NUM 20
|
||||
#define PROCESSES_NUM 64
|
||||
#define PROCESSES_NUM 256
|
||||
#define PROCESS_UNIT_NUM 256
|
||||
#define UNIT_NUM 256
|
||||
#define UNIT_YX_MAX 0x1500
|
||||
|
Loading…
Reference in New Issue
Block a user