微网配置TinyConfig增加无线发射间隔和超时时间,编译通过,未测试
This commit is contained in:
parent
850d199b55
commit
41d6e593ea
|
@ -72,20 +72,29 @@ ITransport* Create2401(SPI_TypeDef* spi_, Pin ce, Pin irq, Pin power, bool power
|
||||||
auto spi = new Spi(spi_, 10000000, true);
|
auto spi = new Spi(spi_, 10000000, true);
|
||||||
auto nrf = new NRF24L01();
|
auto nrf = new NRF24L01();
|
||||||
nrf->Init(spi, ce, irq, power);
|
nrf->Init(spi, ce, irq, power);
|
||||||
|
|
||||||
auto tc = TinyConfig::Current;
|
auto tc = TinyConfig::Current;
|
||||||
|
if(tc->New)
|
||||||
|
{
|
||||||
|
tc->Channel = 120;
|
||||||
|
tc->Speed = 250;
|
||||||
|
|
||||||
|
tc->Interval= 40;
|
||||||
|
tc->Timeout = 1000;
|
||||||
|
}
|
||||||
|
|
||||||
nrf->AutoAnswer = false;
|
nrf->AutoAnswer = false;
|
||||||
nrf->DynPayload = false;
|
nrf->DynPayload = false;
|
||||||
nrf->Channel = tc->Channel;
|
nrf->Channel = tc->Channel;
|
||||||
//nrf->Channel = 120;
|
//nrf->Channel = 120;
|
||||||
nrf->Speed = tc->Speed;
|
nrf->Speed = tc->Speed;
|
||||||
|
|
||||||
nrf->FixData = Fix2401;
|
nrf->FixData = Fix2401;
|
||||||
nrf->Led = led;
|
nrf->Led = led;
|
||||||
|
|
||||||
byte num = tc->Mac[0] && tc->Mac[1] && tc->Mac[2] && tc->Mac[3] && tc->Mac[4];
|
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);
|
if(num != 0 && num != 0xFF) memcpy(nrf->Remote, tc->Mac, 5);
|
||||||
|
|
||||||
return nrf;
|
return nrf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,6 +121,16 @@ void ShunComExternalCfg(void * param)
|
||||||
|
|
||||||
ITransport* CreateShunCom(COM_Def index, int baudRate, Pin rst, Pin power, Pin slp, Pin cfg, IDataPort* led)
|
ITransport* CreateShunCom(COM_Def index, int baudRate, Pin rst, Pin power, Pin slp, Pin cfg, IDataPort* led)
|
||||||
{
|
{
|
||||||
|
auto tc = TinyConfig::Current;
|
||||||
|
if(tc->New)
|
||||||
|
{
|
||||||
|
tc->Channel = 0x0F;
|
||||||
|
tc->Speed = 250;
|
||||||
|
|
||||||
|
tc->Interval= 800;
|
||||||
|
tc->Timeout = 2400;
|
||||||
|
}
|
||||||
|
|
||||||
auto sp = new SerialPort(index, baudRate);
|
auto sp = new SerialPort(index, baudRate);
|
||||||
auto zb = new ShunCom();
|
auto zb = new ShunCom();
|
||||||
|
|
||||||
|
@ -137,28 +156,19 @@ TinyClient* CreateTinyClient(ITransport* port)
|
||||||
static TinyController ctrl;
|
static TinyController ctrl;
|
||||||
ctrl.Port = port;
|
ctrl.Port = port;
|
||||||
|
|
||||||
// 调整顺舟Zigbee的重发参数
|
// 新配置需要保存一下
|
||||||
if(strcmp(port->ToString(), "ShunCom") == 0)
|
auto tc = TinyConfig::Current;
|
||||||
{
|
if(tc && tc->New) tc->Save();
|
||||||
//ctrl.Timeout = -1;
|
|
||||||
ctrl.Interval = 800;
|
|
||||||
ctrl.Timeout = 2400;
|
|
||||||
}
|
|
||||||
else if(strcmp(port->ToString(), "R24") == 0)
|
|
||||||
{
|
|
||||||
ctrl.Interval = 40;
|
|
||||||
ctrl.Timeout = 1000;
|
|
||||||
}
|
|
||||||
|
|
||||||
static TinyClient tc(&ctrl);
|
static TinyClient client(&ctrl);
|
||||||
tc.Cfg = TinyConfig::Current;
|
client.Cfg = TinyConfig::Current;
|
||||||
|
|
||||||
TinyClient::Current = &tc;
|
TinyClient::Current = &client;
|
||||||
|
|
||||||
//ctrl.Mode = 3;
|
//ctrl.Mode = 3;
|
||||||
//ctrl.Open();
|
//ctrl.Open();
|
||||||
|
|
||||||
return &tc;
|
return &client;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* InitConfig(void* data, uint size)
|
void* InitConfig(void* data, uint size)
|
||||||
|
|
|
@ -10,7 +10,7 @@ TinyConfig::TinyConfig()
|
||||||
|
|
||||||
uint TinyConfig::Size() const
|
uint TinyConfig::Size() const
|
||||||
{
|
{
|
||||||
return (uint)&Cfg - (uint)&Length;
|
return (uint)&New - (uint)&Length;
|
||||||
}
|
}
|
||||||
|
|
||||||
Array TinyConfig::ToArray()
|
Array TinyConfig::ToArray()
|
||||||
|
@ -33,11 +33,11 @@ void TinyConfig::LoadDefault()
|
||||||
Kind = Sys.Code;
|
Kind = Sys.Code;
|
||||||
//Server = 0x01;
|
//Server = 0x01;
|
||||||
|
|
||||||
Channel = 120;
|
//Channel = 120;
|
||||||
Speed = 250;
|
//Speed = 250;
|
||||||
|
|
||||||
PingTime = 20;
|
//PingTime = 20;
|
||||||
OfflineTime = 60;
|
//OfflineTime = 60;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TinyConfig::Load()
|
void TinyConfig::Load()
|
||||||
|
@ -46,7 +46,8 @@ void TinyConfig::Load()
|
||||||
|
|
||||||
// 尝试加载配置区设置
|
// 尝试加载配置区设置
|
||||||
auto bs = ToArray();
|
auto bs = ToArray();
|
||||||
if(!Cfg->GetOrSet("TCFG", bs))
|
New = !Cfg->GetOrSet("TCFG", bs);
|
||||||
|
if(!New)
|
||||||
debug_printf("TinyConfig::Load 首次运行,创建配置区!\r\n");
|
debug_printf("TinyConfig::Load 首次运行,创建配置区!\r\n");
|
||||||
else
|
else
|
||||||
debug_printf("TinyConfig::Load 从配置区加载配置\r\n");
|
debug_printf("TinyConfig::Load 从配置区加载配置\r\n");
|
||||||
|
|
|
@ -25,12 +25,18 @@ public:
|
||||||
byte Server; // 网关ID
|
byte Server; // 网关ID
|
||||||
byte Channel; // 通道
|
byte Channel; // 通道
|
||||||
ushort Speed; // 传输速度
|
ushort Speed; // 传输速度
|
||||||
|
|
||||||
|
ushort Interval; // 重发间隔。毫秒
|
||||||
|
ushort Timeout; // 超时时间。毫秒
|
||||||
|
|
||||||
byte HardVer; // 硬件版本
|
byte HardVer; // 硬件版本
|
||||||
byte SoftVer; // 软件版本
|
byte SoftVer; // 软件版本
|
||||||
|
|
||||||
byte Password[16]; // 通信密码
|
byte Password[16]; // 通信密码
|
||||||
byte Mac[6]; // 无线物理地址
|
byte Mac[6]; // 无线物理地址
|
||||||
|
|
||||||
|
bool New; // 是否新创建的配置
|
||||||
|
|
||||||
TinyConfig();
|
TinyConfig();
|
||||||
void LoadDefault();
|
void LoadDefault();
|
||||||
|
|
||||||
|
@ -44,10 +50,10 @@ public:
|
||||||
|
|
||||||
static TinyConfig* Current;
|
static TinyConfig* Current;
|
||||||
static TinyConfig* Init();
|
static TinyConfig* Init();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Config* Cfg;
|
Config* Cfg;
|
||||||
|
|
||||||
uint Size() const;
|
uint Size() const;
|
||||||
Array ToArray();
|
Array ToArray();
|
||||||
const Array ToArray() const;
|
const Array ToArray() const;
|
||||||
|
|
|
@ -215,6 +215,19 @@ TinyController::TinyController() : Controller()
|
||||||
Mode = 0;
|
Mode = 0;
|
||||||
Interval = 20;
|
Interval = 20;
|
||||||
Timeout = 200;
|
Timeout = 200;
|
||||||
|
auto cfg = TinyConfig::Current;
|
||||||
|
if(cfg)
|
||||||
|
{
|
||||||
|
// 调整重发参数
|
||||||
|
if(cfg->New && cfg->Interval == 0)
|
||||||
|
{
|
||||||
|
cfg->Interval = Interval;
|
||||||
|
cfg->Timeout = Timeout;
|
||||||
|
}
|
||||||
|
Interval = cfg->Interval;
|
||||||
|
Timeout = cfg->Timeout;
|
||||||
|
cfg->Address= Address;
|
||||||
|
}
|
||||||
|
|
||||||
_taskID = 0;
|
_taskID = 0;
|
||||||
_Queue = NULL;
|
_Queue = NULL;
|
||||||
|
|
|
@ -127,21 +127,10 @@ TinyServer* Token::CreateServer(ITransport* port)
|
||||||
static TinyController ctrl;
|
static TinyController ctrl;
|
||||||
ctrl.Port = port;
|
ctrl.Port = port;
|
||||||
ctrl.QueueLength = 64;
|
ctrl.QueueLength = 64;
|
||||||
|
|
||||||
// 调整顺舟Zigbee的重发参数
|
// 新配置需要保存一下
|
||||||
if(strcmp(port->ToString(), "ShunCom") == 0)
|
|
||||||
{
|
|
||||||
//ctrl.Timeout = -1;
|
|
||||||
ctrl.Interval = 800;
|
|
||||||
ctrl.Timeout = 2400;
|
|
||||||
}
|
|
||||||
else if(strcmp(port->ToString(), "R24") == 0)
|
|
||||||
{
|
|
||||||
ctrl.Interval = 40;
|
|
||||||
ctrl.Timeout = 800;
|
|
||||||
}
|
|
||||||
auto tc = TinyConfig::Current;
|
auto tc = TinyConfig::Current;
|
||||||
tc->Address = ctrl.Address;
|
if(tc && tc->New) tc->Save();
|
||||||
|
|
||||||
static TinyServer server(&ctrl);
|
static TinyServer server(&ctrl);
|
||||||
server.Cfg = tc;
|
server.Cfg = tc;
|
||||||
|
@ -220,6 +209,15 @@ ITransport* Token::Create2401(SPI_TypeDef* spi_, Pin ce, Pin irq, Pin power, boo
|
||||||
nrf.Init(&spi, ce, irq, power);
|
nrf.Init(&spi, ce, irq, power);
|
||||||
|
|
||||||
auto tc = TinyConfig::Current;
|
auto tc = TinyConfig::Current;
|
||||||
|
if(tc->New)
|
||||||
|
{
|
||||||
|
tc->Channel = 120;
|
||||||
|
tc->Speed = 250;
|
||||||
|
|
||||||
|
tc->Interval= 40;
|
||||||
|
tc->Timeout = 1000;
|
||||||
|
}
|
||||||
|
|
||||||
nrf.AutoAnswer = false;
|
nrf.AutoAnswer = false;
|
||||||
nrf.DynPayload = false;
|
nrf.DynPayload = false;
|
||||||
nrf.Channel = tc->Channel;
|
nrf.Channel = tc->Channel;
|
||||||
|
@ -236,33 +234,43 @@ ITransport* Token::Create2401(SPI_TypeDef* spi_, Pin ce, Pin irq, Pin power, boo
|
||||||
|
|
||||||
ITransport* Token::CreateShunCom(COM_Def index, int baudRate, Pin rst, Pin power, Pin slp, Pin cfg, IDataPort* led)
|
ITransport* Token::CreateShunCom(COM_Def index, int baudRate, Pin rst, Pin power, Pin slp, Pin cfg, IDataPort* led)
|
||||||
{
|
{
|
||||||
|
auto tc = TinyConfig::Current;
|
||||||
|
if(tc->New)
|
||||||
|
{
|
||||||
|
tc->Channel = 0x0F;
|
||||||
|
tc->Speed = 250;
|
||||||
|
|
||||||
|
tc->Interval= 800;
|
||||||
|
tc->Timeout = 2400;
|
||||||
|
}
|
||||||
|
|
||||||
static SerialPort sp(index, baudRate);
|
static SerialPort sp(index, baudRate);
|
||||||
static ShunCom zb;
|
static ShunCom zb;
|
||||||
zb.Power.Set(power);
|
zb.Power.Set(power);
|
||||||
zb.Sleep.Init(slp, true);
|
zb.Sleep.Init(slp, true);
|
||||||
zb.Config.Init(cfg, true);
|
zb.Config.Init(cfg, true);
|
||||||
zb.Init(&sp, rst);
|
zb.Init(&sp, rst);
|
||||||
zb.Led = led;
|
zb.Led = led;
|
||||||
|
|
||||||
#if ShunComMaster
|
#if ShunComMaster
|
||||||
zb.AddrLength = 2;
|
zb.AddrLength = 2;
|
||||||
auto tc = TinyConfig::Current;
|
auto tc = TinyConfig::Current;
|
||||||
tc->Load();
|
tc->Load();
|
||||||
|
|
||||||
if(tc->Channel != 0x0F)
|
if(tc->Channel != 0x0F)
|
||||||
{
|
{
|
||||||
if(zb.EnterConfig())
|
if(zb.EnterConfig())
|
||||||
{
|
{
|
||||||
zb.ShowConfig();
|
zb.ShowConfig();
|
||||||
zb.SetDevice(0x00);
|
zb.SetDevice(0x00);
|
||||||
//zb.SetPanID(0x4444);
|
//zb.SetPanID(0x4444);
|
||||||
//zb.EraConfig();
|
//zb.EraConfig();
|
||||||
tc->Channel = 0x0F;
|
tc->Channel = 0x0F;
|
||||||
tc->Save();
|
tc->Save();
|
||||||
zb.SetSend(0x01);
|
zb.SetSend(0x01);
|
||||||
zb.PrintSrc(true);
|
zb.PrintSrc(true);
|
||||||
zb.ExitConfig();
|
zb.ExitConfig();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return &zb;
|
return &zb;
|
||||||
|
|
Loading…
Reference in New Issue