微网配置TinyConfig增加无线发射间隔和超时时间,编译通过,未测试

This commit is contained in:
nnhy 2015-12-31 10:09:15 +00:00
parent 850d199b55
commit 41d6e593ea
5 changed files with 88 additions and 50 deletions

View File

@ -74,6 +74,15 @@ ITransport* Create2401(SPI_TypeDef* spi_, Pin ce, Pin irq, Pin power, bool power
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;
@ -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)

View File

@ -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");

View File

@ -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();

View File

@ -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;

View File

@ -128,20 +128,9 @@ TinyServer* Token::CreateServer(ITransport* port)
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,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)
{
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);