微网配置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 nrf = new NRF24L01();
|
||||
nrf->Init(spi, ce, irq, power);
|
||||
|
||||
|
||||
auto tc = TinyConfig::Current;
|
||||
if(tc->New)
|
||||
{
|
||||
tc->Channel = 120;
|
||||
tc->Speed = 250;
|
||||
|
||||
tc->Interval= 40;
|
||||
tc->Timeout = 1000;
|
||||
}
|
||||
|
||||
nrf->AutoAnswer = false;
|
||||
nrf->DynPayload = false;
|
||||
nrf->Channel = tc->Channel;
|
||||
//nrf->Channel = 120;
|
||||
nrf->Speed = tc->Speed;
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
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 zb = new ShunCom();
|
||||
|
||||
|
@ -137,28 +156,19 @@ TinyClient* CreateTinyClient(ITransport* port)
|
|||
static TinyController ctrl;
|
||||
ctrl.Port = port;
|
||||
|
||||
// 调整顺舟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 = 1000;
|
||||
}
|
||||
// 新配置需要保存一下
|
||||
auto tc = TinyConfig::Current;
|
||||
if(tc && tc->New) tc->Save();
|
||||
|
||||
static TinyClient tc(&ctrl);
|
||||
tc.Cfg = TinyConfig::Current;
|
||||
static TinyClient client(&ctrl);
|
||||
client.Cfg = TinyConfig::Current;
|
||||
|
||||
TinyClient::Current = &tc;
|
||||
TinyClient::Current = &client;
|
||||
|
||||
//ctrl.Mode = 3;
|
||||
//ctrl.Open();
|
||||
|
||||
return &tc;
|
||||
return &client;
|
||||
}
|
||||
|
||||
void* InitConfig(void* data, uint size)
|
||||
|
|
|
@ -10,7 +10,7 @@ TinyConfig::TinyConfig()
|
|||
|
||||
uint TinyConfig::Size() const
|
||||
{
|
||||
return (uint)&Cfg - (uint)&Length;
|
||||
return (uint)&New - (uint)&Length;
|
||||
}
|
||||
|
||||
Array TinyConfig::ToArray()
|
||||
|
@ -33,11 +33,11 @@ void TinyConfig::LoadDefault()
|
|||
Kind = Sys.Code;
|
||||
//Server = 0x01;
|
||||
|
||||
Channel = 120;
|
||||
Speed = 250;
|
||||
//Channel = 120;
|
||||
//Speed = 250;
|
||||
|
||||
PingTime = 20;
|
||||
OfflineTime = 60;
|
||||
//PingTime = 20;
|
||||
//OfflineTime = 60;
|
||||
}
|
||||
|
||||
void TinyConfig::Load()
|
||||
|
@ -46,7 +46,8 @@ void TinyConfig::Load()
|
|||
|
||||
// 尝试加载配置区设置
|
||||
auto bs = ToArray();
|
||||
if(!Cfg->GetOrSet("TCFG", bs))
|
||||
New = !Cfg->GetOrSet("TCFG", bs);
|
||||
if(!New)
|
||||
debug_printf("TinyConfig::Load 首次运行,创建配置区!\r\n");
|
||||
else
|
||||
debug_printf("TinyConfig::Load 从配置区加载配置\r\n");
|
||||
|
|
|
@ -25,12 +25,18 @@ public:
|
|||
byte Server; // 网关ID
|
||||
byte Channel; // 通道
|
||||
ushort Speed; // 传输速度
|
||||
|
||||
ushort Interval; // 重发间隔。毫秒
|
||||
ushort Timeout; // 超时时间。毫秒
|
||||
|
||||
byte HardVer; // 硬件版本
|
||||
byte SoftVer; // 软件版本
|
||||
|
||||
byte Password[16]; // 通信密码
|
||||
byte Mac[6]; // 无线物理地址
|
||||
|
||||
bool New; // 是否新创建的配置
|
||||
|
||||
TinyConfig();
|
||||
void LoadDefault();
|
||||
|
||||
|
@ -44,10 +50,10 @@ public:
|
|||
|
||||
static TinyConfig* Current;
|
||||
static TinyConfig* Init();
|
||||
|
||||
|
||||
private:
|
||||
Config* Cfg;
|
||||
|
||||
|
||||
uint Size() const;
|
||||
Array ToArray();
|
||||
const Array ToArray() const;
|
||||
|
|
|
@ -215,6 +215,19 @@ TinyController::TinyController() : Controller()
|
|||
Mode = 0;
|
||||
Interval = 20;
|
||||
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;
|
||||
_Queue = NULL;
|
||||
|
|
|
@ -127,21 +127,10 @@ TinyServer* Token::CreateServer(ITransport* port)
|
|||
static TinyController ctrl;
|
||||
ctrl.Port = port;
|
||||
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;
|
||||
tc->Address = ctrl.Address;
|
||||
if(tc && tc->New) tc->Save();
|
||||
|
||||
static TinyServer server(&ctrl);
|
||||
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);
|
||||
|
||||
auto tc = TinyConfig::Current;
|
||||
if(tc->New)
|
||||
{
|
||||
tc->Channel = 120;
|
||||
tc->Speed = 250;
|
||||
|
||||
tc->Interval= 40;
|
||||
tc->Timeout = 1000;
|
||||
}
|
||||
|
||||
nrf.AutoAnswer = false;
|
||||
nrf.DynPayload = false;
|
||||
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)
|
||||
{
|
||||
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 ShunCom zb;
|
||||
zb.Power.Set(power);
|
||||
zb.Sleep.Init(slp, true);
|
||||
zb.Config.Init(cfg, true);
|
||||
zb.Init(&sp, rst);
|
||||
zb.Init(&sp, rst);
|
||||
zb.Led = led;
|
||||
|
||||
|
||||
#if ShunComMaster
|
||||
zb.AddrLength = 2;
|
||||
auto tc = TinyConfig::Current;
|
||||
tc->Load();
|
||||
|
||||
|
||||
if(tc->Channel != 0x0F)
|
||||
{
|
||||
if(zb.EnterConfig())
|
||||
{
|
||||
{
|
||||
zb.ShowConfig();
|
||||
zb.SetDevice(0x00);
|
||||
zb.SetDevice(0x00);
|
||||
//zb.SetPanID(0x4444);
|
||||
//zb.EraConfig();
|
||||
tc->Channel = 0x0F;
|
||||
tc->Channel = 0x0F;
|
||||
tc->Save();
|
||||
zb.SetSend(0x01);
|
||||
zb.PrintSrc(true);
|
||||
zb.PrintSrc(true);
|
||||
zb.ExitConfig();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return &zb;
|
||||
|
|
Loading…
Reference in New Issue