30秒内发过数据,不再发送心跳
This commit is contained in:
parent
cce95a003d
commit
30b952a49e
|
@ -27,6 +27,7 @@ TinyClient::TinyClient(TinyController* control)
|
||||||
Server = 0;
|
Server = 0;
|
||||||
Type = Sys.Code;
|
Type = Sys.Code;
|
||||||
|
|
||||||
|
LastSend = 0;
|
||||||
LastActive = 0;
|
LastActive = 0;
|
||||||
|
|
||||||
Received = nullptr;
|
Received = nullptr;
|
||||||
|
@ -256,7 +257,7 @@ void TinyClient::ReportAsync(uint offset,uint length)
|
||||||
if(offset + length >= Store.Data.Length()) return;
|
if(offset + length >= Store.Data.Length()) return;
|
||||||
|
|
||||||
NextReport = offset;
|
NextReport = offset;
|
||||||
NextReportLength = length;
|
ReportLength = length;
|
||||||
// 延迟200ms上报,期间有其它上报任务到来将会覆盖
|
// 延迟200ms上报,期间有其它上报任务到来将会覆盖
|
||||||
Sys.SetTask(_TaskID, true, 200);
|
Sys.SetTask(_TaskID, true, 200);
|
||||||
}
|
}
|
||||||
|
@ -269,7 +270,7 @@ void TinyClientTask(void* param)
|
||||||
|
|
||||||
auto client = (TinyClient*)param;
|
auto client = (TinyClient*)param;
|
||||||
uint offset = client->NextReport;
|
uint offset = client->NextReport;
|
||||||
uint len = client->NextReportLength;
|
uint len = client->ReportLength;
|
||||||
assert(offset == 0 || offset < 0x10, "自动上报偏移量异常!");
|
assert(offset == 0 || offset < 0x10, "自动上报偏移量异常!");
|
||||||
|
|
||||||
if(offset)
|
if(offset)
|
||||||
|
@ -475,6 +476,9 @@ void TinyClient::Ping()
|
||||||
// 没有服务端时不要上报
|
// 没有服务端时不要上报
|
||||||
if(!Server) return;
|
if(!Server) return;
|
||||||
|
|
||||||
|
// 30秒内发过数据,不再发送心跳
|
||||||
|
if(LastSend > 0 && LastSend + 30000 > Sys.Ms()) return;
|
||||||
|
|
||||||
TinyMessage msg;
|
TinyMessage msg;
|
||||||
msg.Code = 3;
|
msg.Code = 3;
|
||||||
|
|
||||||
|
|
|
@ -21,9 +21,10 @@ public:
|
||||||
ushort Type; // 设备类型。两个字节可做二级分类
|
ushort Type; // 设备类型。两个字节可做二级分类
|
||||||
ByteArray Password; // 通讯密码
|
ByteArray Password; // 通讯密码
|
||||||
|
|
||||||
|
UInt64 LastSend; // 最后发送时间ms
|
||||||
UInt64 LastActive; // 最后活跃时间
|
UInt64 LastActive; // 最后活跃时间
|
||||||
ushort HardCrc; // 硬件ID校验
|
ushort HardCrc; // 硬件ID校验
|
||||||
bool Encryption; // 是否加密
|
bool Encryption; // 是否加密
|
||||||
|
|
||||||
TinyClient(TinyController* control);
|
TinyClient(TinyController* control);
|
||||||
|
|
||||||
|
@ -49,7 +50,7 @@ public:
|
||||||
bool Report(uint offset, const Buffer& bs);
|
bool Report(uint offset, const Buffer& bs);
|
||||||
|
|
||||||
uint NextReport; // 下次上报偏移,0不动
|
uint NextReport; // 下次上报偏移,0不动
|
||||||
uint NextReportLength; // 下次上报数据长度
|
uint ReportLength; // 下次上报数据长度
|
||||||
void ReportAsync(uint offset,uint length = 1);
|
void ReportAsync(uint offset,uint length = 1);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -60,7 +61,7 @@ private:
|
||||||
void OnRead(const TinyMessage& msg);
|
void OnRead(const TinyMessage& msg);
|
||||||
|
|
||||||
void GetDeviceKey(byte id, Buffer& key);
|
void GetDeviceKey(byte id, Buffer& key);
|
||||||
|
|
||||||
// 常用系统级消息
|
// 常用系统级消息
|
||||||
public:
|
public:
|
||||||
// 组网
|
// 组网
|
||||||
|
|
|
@ -26,7 +26,7 @@ TokenClient::TokenClient()
|
||||||
Status = 0;
|
Status = 0;
|
||||||
LoginTime = 0;
|
LoginTime = 0;
|
||||||
LastSend = 0;
|
LastSend = 0;
|
||||||
LastReceive = 0;
|
LastActive = 0;
|
||||||
Delay = 0;
|
Delay = 0;
|
||||||
MaxNotActive = 0;
|
MaxNotActive = 0;
|
||||||
|
|
||||||
|
@ -68,7 +68,8 @@ void TokenClient::Open()
|
||||||
// 令牌广播使用素数,避免跟别的任务重叠
|
// 令牌广播使用素数,避免跟别的任务重叠
|
||||||
if(cs.Count() > 0) _taskBroadcast = Sys.AddTask(BroadcastHelloTask, this, 7000, 37000, "令牌广播");
|
if(cs.Count() > 0) _taskBroadcast = Sys.AddTask(BroadcastHelloTask, this, 7000, 37000, "令牌广播");
|
||||||
|
|
||||||
//LastReceive = Sys.Ms();
|
// 启动时记为为后一次活跃接收
|
||||||
|
LastActive = Sys.Ms();
|
||||||
|
|
||||||
Opened = true;
|
Opened = true;
|
||||||
}
|
}
|
||||||
|
@ -132,7 +133,7 @@ void TokenClient::OnReceive(TokenMessage& msg, TokenController& ctrl)
|
||||||
{
|
{
|
||||||
TS("TokenClient::OnReceive");
|
TS("TokenClient::OnReceive");
|
||||||
|
|
||||||
LastReceive = Sys.Ms();
|
LastActive = Sys.Ms();
|
||||||
|
|
||||||
switch(msg.Code)
|
switch(msg.Code)
|
||||||
{
|
{
|
||||||
|
@ -210,7 +211,7 @@ void TokenClient::LoopTask()
|
||||||
// 最大不活跃时间ms,超过该时间时重启系统
|
// 最大不活跃时间ms,超过该时间时重启系统
|
||||||
// WiFi触摸开关建议5~10分钟,网关建议5分钟
|
// WiFi触摸开关建议5~10分钟,网关建议5分钟
|
||||||
// MaxNotActive 为零便不考虑重启
|
// MaxNotActive 为零便不考虑重启
|
||||||
if(MaxNotActive != 0 && LastReceive + MaxNotActive < Sys.Ms()) Sys.Reset();
|
if(MaxNotActive != 0 && LastActive + MaxNotActive < Sys.Ms()) Sys.Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BroadcastHelloTask(void* param)
|
void BroadcastHelloTask(void* param)
|
||||||
|
@ -580,7 +581,7 @@ void TokenClient::Ping()
|
||||||
{
|
{
|
||||||
TS("TokenClient::Ping");
|
TS("TokenClient::Ping");
|
||||||
|
|
||||||
if(LastReceive > 0 && LastReceive + 180000 < Sys.Ms())
|
if(LastActive > 0 && LastActive + 180000 < Sys.Ms())
|
||||||
{
|
{
|
||||||
// 30秒无法联系,服务端可能已经掉线,重启Hello任务
|
// 30秒无法联系,服务端可能已经掉线,重启Hello任务
|
||||||
debug_printf("180秒无法联系,服务端可能已经掉线,重新开始握手\r\n");
|
debug_printf("180秒无法联系,服务端可能已经掉线,重新开始握手\r\n");
|
||||||
|
@ -594,6 +595,9 @@ void TokenClient::Ping()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 30秒内发过数据,不再发送心跳
|
||||||
|
if(LastSend > 0 && LastSend + 30000 > Sys.Ms()) return;
|
||||||
|
|
||||||
TokenPingMessage pinMsg;
|
TokenPingMessage pinMsg;
|
||||||
|
|
||||||
TokenMessage msg(3);
|
TokenMessage msg(3);
|
||||||
|
|
|
@ -23,7 +23,7 @@ public:
|
||||||
|
|
||||||
UInt64 LoginTime; // 登录时间ms
|
UInt64 LoginTime; // 登录时间ms
|
||||||
UInt64 LastSend; // 最后发送时间ms
|
UInt64 LastSend; // 最后发送时间ms
|
||||||
UInt64 LastReceive;// 最后活跃时间ms
|
UInt64 LastActive; // 最后活跃时间ms
|
||||||
int Delay; // 心跳延迟。一条心跳指令从发出到收到所花费的时间
|
int Delay; // 心跳延迟。一条心跳指令从发出到收到所花费的时间
|
||||||
int MaxNotActive; // 最大不活跃时间ms,超过该时间时重启系统。默认0
|
int MaxNotActive; // 最大不活跃时间ms,超过该时间时重启系统。默认0
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ private:
|
||||||
|
|
||||||
byte NextReport; // 下次上报偏移,0不动
|
byte NextReport; // 下次上报偏移,0不动
|
||||||
byte ReportLength; // 下次上报数据长度
|
byte ReportLength; // 下次上报数据长度
|
||||||
|
|
||||||
void LoopTask();
|
void LoopTask();
|
||||||
bool CheckReport();
|
bool CheckReport();
|
||||||
};
|
};
|
||||||
|
@ -127,7 +127,7 @@ public:
|
||||||
|
|
||||||
int Status; // 状态。0准备、1握手完成、2登录后
|
int Status; // 状态。0准备、1握手完成、2登录后
|
||||||
UInt64 LoginTime; // 登录时间ms
|
UInt64 LoginTime; // 登录时间ms
|
||||||
UInt64 LastReceive; // 最后活跃时间ms
|
UInt64 LastActive; // 最后活跃时间ms
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue