parent
1ed71078da
commit
057a2a5f39
|
@ -36,6 +36,7 @@ void TinyClient::Open()
|
||||||
Control->Received = OnClientReceived;
|
Control->Received = OnClientReceived;
|
||||||
Control->Param = this;
|
Control->Param = this;
|
||||||
|
|
||||||
|
Control->Mode = 0; // 客户端只接收自己的消息
|
||||||
Control->Open();
|
Control->Open();
|
||||||
|
|
||||||
TranID = (int)Time.Current();
|
TranID = (int)Time.Current();
|
||||||
|
|
|
@ -194,6 +194,8 @@ TinyController::TinyController() : Controller()
|
||||||
Address = Time.CurrentTicks();
|
Address = Time.CurrentTicks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 接收模式。0只收自己,1接收自己和广播,2接收所有。默认0
|
||||||
|
Mode = 0;
|
||||||
NoAck = false;
|
NoAck = false;
|
||||||
|
|
||||||
ArrayZero(_Queue);
|
ArrayZero(_Queue);
|
||||||
|
@ -291,7 +293,22 @@ bool TinyController::Valid(const Message& msg)
|
||||||
// 源地址是自己不要接收
|
// 源地址是自己不要接收
|
||||||
if(tmsg.Src == Address) return false;
|
if(tmsg.Src == Address) return false;
|
||||||
// 只处理本机消息或广播消息
|
// 只处理本机消息或广播消息
|
||||||
if(tmsg.Dest != Address && tmsg.Dest != 0) return false;
|
//if(tmsg.Dest != Address && tmsg.Dest != 0) return false;
|
||||||
|
switch(Mode)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// 不是自己的消息,并且没有设置接收全部
|
||||||
|
if(Mode < 2 && tmsg.Dest != Address)
|
||||||
|
{
|
||||||
|
// 如果不是广播或者不允许广播
|
||||||
|
if(Mode != 1 || tmsg.Dest != 0) return false;
|
||||||
|
}
|
||||||
|
|
||||||
#if MSG_DEBUG
|
#if MSG_DEBUG
|
||||||
// 调试版不过滤序列号为0的重复消息
|
// 调试版不过滤序列号为0的重复消息
|
||||||
|
@ -472,24 +489,11 @@ void TinyController::Loop()
|
||||||
count++;
|
count++;
|
||||||
node.Times++;
|
node.Times++;
|
||||||
|
|
||||||
ByteArray bs(node.Data, node.Length);
|
|
||||||
bs.Show(true);
|
|
||||||
#if MSG_DEBUG
|
|
||||||
//debug_printf("重发消息 Dest=0x%02X Seq=%d Times=%d\r\n", node.Data[0], node.Sequence, node.Times);
|
|
||||||
// 第6个字节表示长度
|
|
||||||
/*byte retry = node.Data[3] & 0x03;
|
|
||||||
retry++;
|
|
||||||
node.Data[3] &= ~0x03;
|
|
||||||
node.Data[3] |= retry & 0x03;*/
|
|
||||||
TFlags* f = (TFlags*)&node.Data[3];
|
TFlags* f = (TFlags*)&node.Data[3];
|
||||||
f->Retry++;
|
f->Retry++;
|
||||||
// 最后一个附加字节记录第几次重发
|
|
||||||
//if(node.Length > TinyMessage::MinSize + msg->Length) node.Data[node.Length - 1] = node.Times;
|
|
||||||
//ByteArray bs(node.Data, node.Length);
|
|
||||||
//bs.Show(true);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// 发送消息
|
// 发送消息
|
||||||
|
ByteArray bs(node.Data, node.Length);
|
||||||
Port->Write(bs);
|
Port->Write(bs);
|
||||||
|
|
||||||
// 增加发送次数统计
|
// 增加发送次数统计
|
||||||
|
|
|
@ -136,6 +136,7 @@ protected:
|
||||||
public:
|
public:
|
||||||
byte Address; // 本地地址
|
byte Address; // 本地地址
|
||||||
bool NoAck; // 是否不使用Ack,若为true,即使收到消息要求Ack也不发送Ack。默认false
|
bool NoAck; // 是否不使用Ack,若为true,即使收到消息要求Ack也不发送Ack。默认false
|
||||||
|
byte Mode; // 接收模式。0只收自己,1接收自己和广播,2接收所有。默认0
|
||||||
uint Interval; // 消息队列发送间隔ms
|
uint Interval; // 消息队列发送间隔ms
|
||||||
int Timeout; // 消息队列发送消息的默认超时时间ms。如果不需要超时重发,那么直接设置为-1
|
int Timeout; // 消息队列发送消息的默认超时时间ms。如果不需要超时重发,那么直接设置为-1
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,8 @@ TinyServer::TinyServer(TinyController* control)
|
||||||
Control->Received = OnServerReceived;
|
Control->Received = OnServerReceived;
|
||||||
Control->Param = this;
|
Control->Param = this;
|
||||||
|
|
||||||
|
Control->Mode = 2; // 服务端接收所有消息
|
||||||
|
|
||||||
Received = NULL;
|
Received = NULL;
|
||||||
Param = NULL;
|
Param = NULL;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue