微网配置TinyConfig增加无线发射间隔和超时时间,编译通过,未测试
This commit is contained in:
parent
850d199b55
commit
41d6e593ea
|
@ -74,6 +74,15 @@ ITransport* Create2401(SPI_TypeDef* spi_, Pin ce, Pin irq, Pin power, bool power
|
||||||
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;
|
||||||
|
@ -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();
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -128,20 +128,9 @@ TinyServer* Token::CreateServer(ITransport* port)
|
||||||
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,6 +234,16 @@ 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);
|
||||||
|
|
Loading…
Reference in New Issue