节点启动时使用保存的网关MAC作为远程地址,如果超过1分钟未能心跳成功,则节点抹去远程地址再重启

This commit is contained in:
nnhy 2015-12-16 14:34:03 +00:00
parent eb39120a1e
commit d246b8059a
2 changed files with 18 additions and 8 deletions

View File

@ -69,15 +69,19 @@ ITransport* Create2401(SPI_TypeDef* spi_, Pin ce, Pin irq, Pin power, bool power
auto spi = new Spi(spi_, 10000000, true);
auto nrf = new NRF24L01();
nrf->Init(spi, ce, irq, power);
//nrf->Power.Invert = powerInvert;
auto tc = TinyConfig::Current;
nrf->AutoAnswer = false;
nrf->PayloadWidth = 32;
nrf->Channel = TinyConfig::Current->Channel;
nrf->Speed = TinyConfig::Current->Speed;
//nrf->Channel = tc->Channel;
nrf->Channel = 120;
nrf->Speed = tc->Speed;
nrf->FixData= Fix2401;
nrf->Led = led;
nrf->FixData = Fix2401;
nrf->Led = led;
byte num = tc->Mac[0] && tc->Mac[1] && tc->Mac[2] && tc->Mac[3] && tc->Mac[4];
if(num != 0 && num != 0xFF) memcpy(nrf->Remote, tc->Mac, 5);
return nrf;
}

View File

@ -478,8 +478,9 @@ bool TinyClient::OnJoin(const TinyMessage& msg)
Cfg->Speed = dm.Speed * 10;
// 服务端组网密码,退网使用
Cfg->Mac[0] = dm.HardID.Length();
dm.HardID.Save(Cfg->Mac, ArrayLength(Cfg->Mac));
//Cfg->Mac[0] = dm.HardID.Length();
//dm.HardID.Save(Cfg->Mac, ArrayLength(Cfg->Mac));
dm.HardID.CopyTo(Cfg->Mac);
#if DEBUG
//debug_printf("组网成功!\r\n");
@ -567,6 +568,11 @@ void TinyClient::Ping()
// 掉线以后,重发组网信息,基本功能继续执行
Joining = true;
auto tc = TinyConfig::Current;
memset(tc->Mac, 0, 5);
tc->Save();
Sys.Reset();
//Server = 0;
//Password.SetLength(0);