前置新增了装置心跳传输流程,每30秒自动发送一次心跳报文

This commit is contained in:
2026-03-05 13:53:17 +08:00
parent d460816195
commit 852245f8ac
5 changed files with 53 additions and 2 deletions

View File

@@ -479,6 +479,17 @@ void on_timer(uv_timer_t* handle) {
auto sendbuff = generate_statequerytime_message();//组装询问统计数据时间报文
ctx->add_action(DeviceState::READING_STATS_TIME, sendbuff);//将该状态以及待发送报文存入队列
}
//30秒一次 执行询问装置心跳
now = uv_now(ctx->loop);
if (ctx->current_state_ == DeviceState::IDLE && now - ctx->heartbeat_time >= 30000) {
//更新装置心跳最新发送时间
ctx->heartbeat_time = now;
auto sendbuff = generate_requestHeartBeat_message();//组装装置心跳报文
ctx->add_action(DeviceState::HEART_BEAT, sendbuff);//将该状态以及待发送报文存入队列
}
//一秒一次 执行实时数据询问 仅执行指定次数
now = uv_now(ctx->loop);
if (ctx->current_state_ == DeviceState::IDLE && now - ctx->real_state_query_time_ >= 1000 && ctx->real_state_count > 0) {
@@ -489,6 +500,7 @@ void on_timer(uv_timer_t* handle) {
auto sendbuff = generate_realstat_message(static_cast<unsigned char>(ctx->real_point_id_), static_cast<unsigned char>(0x01), static_cast<unsigned char>(0x01));//组装询问实时数据报文
ctx->add_action(DeviceState::READING_REALSTAT, sendbuff);//将该状态以及待发送报文存入队列
}
//30分钟一次 读取装置运行信息
now = uv_now(ctx->loop);
if (ctx->current_state_ == DeviceState::IDLE && now - ctx->read_runninginformationMsg >= 60000 * 30)
@@ -499,7 +511,8 @@ void on_timer(uv_timer_t* handle) {
auto sendbuff = generate_machinestatus_message();//组装读取装置运行信息报文
ctx->add_action(DeviceState::READING_RUNNINGINFORMATION_2, sendbuff);//将该状态以及待发送报文存入队列
}
//30分钟一次 启动装置对时 仅在台账开启对时且云协议版本大于1.5时开启对时 60000 * 30
//30分钟一次 启动装置对时 仅在台账开启对时且云协议版本大于等于1.5时开启对时 60000 * 30
now = uv_now(ctx->loop);
if (ctx->current_state_ == DeviceState::IDLE && now - ctx->right_time >= 60000 * 30 && ctx->device_info.righttime && isVersionGreaterOrEqual(ctx->dev_CloudProtocolVer,"V1.5"))
{
@@ -515,6 +528,7 @@ void on_timer(uv_timer_t* handle) {
//auto sendbuff = generate_machinestatus_message();//组装读取装置运行信息报文
//ctx->add_action(DeviceState::READING_RUNNINGINFORMATION_2, sendbuff);//将该状态以及待发送报文存入队列
}
//处理后续工作队列的工作 取出一个并执行
if (ctx->current_state_ == DeviceState::IDLE) {
ctx->process_next_action();
@@ -717,6 +731,7 @@ void on_connect(uv_connect_t* req, int status) {
ctx->state = ConnectionState::CONNECTED;
ctx->reconnect_attempts = 0;
// 新增:初始化各个计时时间戳
ctx->heartbeat_time = uv_now(ctx->loop);//初始化心跳报文时间戳
ctx->last_state_query_time_ = uv_now(ctx->loop);//初始化统计数据时间戳
ctx->real_state_query_time_ = uv_now(ctx->loop);//初始化实时数据时间戳
ctx->read_runninginformationMsg = uv_now(ctx->loop);//初始化读取装置运行信息时间戳