0803使用tokenbsp基类
This commit is contained in:
parent
4f975cd0dd
commit
8de821d190
|
@ -41,34 +41,6 @@ AP0103::AP0103()
|
|||
Current = this;
|
||||
}
|
||||
|
||||
void AP0103::Init(ushort code, cstring name, COM message)
|
||||
{
|
||||
auto& sys = (TSys&)Sys;
|
||||
sys.Code = code;
|
||||
sys.Name = (char*)name;
|
||||
|
||||
// RTC 提取时间
|
||||
auto Rtc = HardRTC::Instance();
|
||||
Rtc->LowPower = false;
|
||||
Rtc->External = false;
|
||||
Rtc->Init();
|
||||
Rtc->Start(false, false);
|
||||
|
||||
// 初始化系统
|
||||
sys.Init();
|
||||
#if DEBUG
|
||||
sys.MessagePort = message; // 指定printf输出的串口
|
||||
Sys.ShowInfo();
|
||||
|
||||
WatchDog::Start(20000, 10000);
|
||||
#else
|
||||
WatchDog::Start();
|
||||
#endif
|
||||
|
||||
// Flash最后一块作为配置区
|
||||
Config::Current = &Config::CreateFlash();
|
||||
}
|
||||
|
||||
void* AP0103::InitData(void* data, int size)
|
||||
{
|
||||
// 启动信息
|
||||
|
|
|
@ -34,9 +34,6 @@ public:
|
|||
|
||||
AP0103();
|
||||
|
||||
// 设置系统参数
|
||||
void Init(ushort code, cstring name, COM message = COM1);
|
||||
|
||||
// 设置数据区
|
||||
void* InitData(void* data, int size);
|
||||
void Register(int index, IDataPort& dp);
|
||||
|
|
|
@ -41,34 +41,6 @@ AP0104::AP0104()
|
|||
Current = this;
|
||||
}
|
||||
|
||||
void AP0104::Init(ushort code, cstring name, COM message)
|
||||
{
|
||||
auto& sys = (TSys&)Sys;
|
||||
sys.Code = code;
|
||||
sys.Name = (char*)name;
|
||||
|
||||
// RTC 提取时间
|
||||
auto Rtc = HardRTC::Instance();
|
||||
Rtc->LowPower = false;
|
||||
Rtc->External = false;
|
||||
Rtc->Init();
|
||||
Rtc->Start(false, false);
|
||||
|
||||
// 初始化系统
|
||||
sys.Init();
|
||||
#if DEBUG
|
||||
sys.MessagePort = message; // 指定printf输出的串口
|
||||
Sys.ShowInfo();
|
||||
|
||||
WatchDog::Start(20000, 10000);
|
||||
#else
|
||||
WatchDog::Start();
|
||||
#endif
|
||||
|
||||
// Flash最后一块作为配置区
|
||||
Config::Current = &Config::CreateFlash();
|
||||
}
|
||||
|
||||
void* AP0104::InitData(void* data, int size)
|
||||
{
|
||||
// 启动信息
|
||||
|
|
|
@ -33,8 +33,6 @@ public:
|
|||
Alarm* AlarmObj;
|
||||
|
||||
AP0104();
|
||||
// 设置系统参数
|
||||
void Init(ushort code, cstring name, COM message = COM1);
|
||||
|
||||
// 设置数据区
|
||||
void* InitData(void* data, int size);
|
||||
|
|
238
Board/AP0803.cpp
238
Board/AP0803.cpp
|
@ -1,22 +1,9 @@
|
|||
#include "AP0803.h"
|
||||
|
||||
#include "Kernel\Task.h"
|
||||
|
||||
#include "Device\WatchDog.h"
|
||||
#include "Config.h"
|
||||
|
||||
#include "Drivers\A67.h"
|
||||
|
||||
#include "TokenNet\TokenController.h"
|
||||
#include "TokenNet\TokenConfig.h"
|
||||
#include "TokenNet\TokenClient.h"
|
||||
|
||||
#include "Device\RTC.h"
|
||||
|
||||
#include "Message\ProxyFactory.h"
|
||||
|
||||
AP0803* AP0803::Current = nullptr;
|
||||
|
||||
static TokenClient* Client = nullptr; // 令牌客户端
|
||||
static ProxyFactory* ProxyFac = nullptr; // 透传管理器
|
||||
|
||||
|
@ -32,97 +19,11 @@ AP0803::AP0803()
|
|||
ProxyFac = nullptr;
|
||||
AlarmObj = nullptr;
|
||||
|
||||
Data = nullptr;
|
||||
Size = 0;
|
||||
|
||||
Current = this;
|
||||
}
|
||||
|
||||
void AP0803::Init(ushort code, cstring name, COM message)
|
||||
{
|
||||
auto& sys = (TSys&)Sys;
|
||||
sys.Code = code;
|
||||
sys.Name = (char*)name;
|
||||
|
||||
// RTC 提取时间
|
||||
HardRTC::Start(false, false);
|
||||
|
||||
// 初始化系统
|
||||
sys.Init();
|
||||
#if DEBUG
|
||||
sys.MessagePort = message; // 指定printf输出的串口
|
||||
Sys.ShowInfo();
|
||||
|
||||
WatchDog::Start(20000, 10000);
|
||||
#else
|
||||
WatchDog::Start();
|
||||
|
||||
// 系统休眠时自动进入低功耗
|
||||
// Power::AttachTimeSleep();
|
||||
#endif
|
||||
|
||||
// Flash最后一块作为配置区
|
||||
Config::Current = &Config::CreateFlash();
|
||||
}
|
||||
|
||||
void* AP0803::InitData(void* data, int size)
|
||||
{
|
||||
// 启动信息
|
||||
auto hot = &HotConfig::Current();
|
||||
hot->Times++;
|
||||
|
||||
data = hot->Next();
|
||||
if (hot->Times == 1)
|
||||
{
|
||||
Buffer ds(data, size);
|
||||
ds.Clear();
|
||||
ds[0] = size;
|
||||
}
|
||||
|
||||
Data = data;
|
||||
Size = size;
|
||||
|
||||
#if DEBUG
|
||||
debug_printf("数据区:");
|
||||
Buffer(Data, Size).Show(true);
|
||||
#endif
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
// 写入数据区并上报
|
||||
void AP0803::Write(uint offset, byte data)
|
||||
{
|
||||
auto client = Client;
|
||||
if (!client) return;
|
||||
|
||||
client->Store.Write(offset, data);
|
||||
client->ReportAsync(offset, 1);
|
||||
}
|
||||
|
||||
void AP0803::InitLeds()
|
||||
{
|
||||
for (int i = 0; i < LedPins.Count(); i++)
|
||||
{
|
||||
auto port = new OutputPort(LedPins[i]);
|
||||
port->Open();
|
||||
Leds.Add(port);
|
||||
}
|
||||
}
|
||||
|
||||
void AP0803::InitButtons(const Delegate2<InputPort&, bool>& press)
|
||||
{
|
||||
for (int i = 0; i < ButtonPins.Count(); i++)
|
||||
{
|
||||
auto port = new InputPort(ButtonPins[i]);
|
||||
port->Invert = true;
|
||||
port->ShakeTime = 40;
|
||||
port->Index = i;
|
||||
port->Press = press;
|
||||
port->UsePress();
|
||||
port->Open();
|
||||
Buttons.Add(port);
|
||||
}
|
||||
Gsm.Com = COM4;
|
||||
Gsm.Baudrate = 115200;
|
||||
Gsm.Power = PE0;
|
||||
Gsm.Reset = PD3;
|
||||
Gsm.LowPower = P0;
|
||||
}
|
||||
|
||||
NetworkInterface* AP0803::CreateGPRS()
|
||||
|
@ -130,8 +31,8 @@ NetworkInterface* AP0803::CreateGPRS()
|
|||
debug_printf("\r\nCreateGPRS::Create \r\n");
|
||||
|
||||
auto net = new A67();
|
||||
net->Init(COM4, 115200);
|
||||
net->Set(PE0, PD3, P0);
|
||||
net->Init(Gsm.Com, Gsm.Baudrate);
|
||||
net->Set(Gsm.Power, Gsm.Reset, Gsm.LowPower);
|
||||
net->SetLed(*Leds[0]);
|
||||
if (!net->Open())
|
||||
{
|
||||
|
@ -142,40 +43,6 @@ NetworkInterface* AP0803::CreateGPRS()
|
|||
return net;
|
||||
}
|
||||
|
||||
/******************************** Token ********************************/
|
||||
|
||||
void AP0803::InitClient()
|
||||
{
|
||||
if (Client) return;
|
||||
|
||||
// 初始化令牌网
|
||||
auto tk = TokenConfig::Create("smart.wslink.cn", NetType::Udp, 33333, 3377);
|
||||
|
||||
// 创建客户端
|
||||
auto tc = TokenClient::CreateFast(Buffer(Data, Size));
|
||||
tc->Cfg = tk;
|
||||
tc->MaxNotActive = 8 * 60 * 1000;
|
||||
//tc->UseLocal();
|
||||
|
||||
Client = tc;
|
||||
}
|
||||
|
||||
void AP0803::Register(uint offset, IDataPort& dp)
|
||||
{
|
||||
if (!Client) return;
|
||||
|
||||
auto& ds = Client->Store;
|
||||
ds.Register(offset, dp);
|
||||
}
|
||||
|
||||
void AP0803::Register(uint offset, uint size, Handler hook)
|
||||
{
|
||||
if (!Client) return;
|
||||
|
||||
auto& ds = Client->Store;
|
||||
ds.Register(offset, size, hook);
|
||||
}
|
||||
|
||||
static void OnInitNet(void* param)
|
||||
{
|
||||
auto& bsp = *(AP0803*)param;
|
||||
|
@ -190,14 +57,6 @@ void AP0803::InitNet()
|
|||
Sys.AddTask(OnInitNet, this, 0, -1, "InitNet");
|
||||
}
|
||||
|
||||
void AP0803::Invoke(const String& ation, const Buffer& bs)
|
||||
{
|
||||
if (!Client) return;
|
||||
|
||||
Client->Invoke(ation, bs);
|
||||
|
||||
}
|
||||
|
||||
void AP0803::InitProxy()
|
||||
{
|
||||
if (ProxyFac)return;
|
||||
|
@ -243,89 +102,6 @@ void AP0803::InitAlarm()
|
|||
AlarmObj->Start();
|
||||
}
|
||||
|
||||
/******************************** 2401 ********************************/
|
||||
|
||||
/*int Fix2401(const Buffer& bs)
|
||||
{
|
||||
//auto& bs = *(Buffer*)param;
|
||||
// 微网指令特殊处理长度
|
||||
uint rs = bs.Length();
|
||||
if(rs >= 8)
|
||||
{
|
||||
rs = bs[5] + 8;
|
||||
//if(rs < bs.Length()) bs.SetLength(rs);
|
||||
}
|
||||
return rs;
|
||||
}
|
||||
|
||||
ITransport* AP0803::Create2401(SPI spi_, Pin ce, Pin irq, Pin power, bool powerInvert, IDataPort* led)
|
||||
{
|
||||
debug_printf("\r\n Create2401 \r\n");
|
||||
|
||||
static Spi spi(spi_, 10000000, true);
|
||||
static NRF24L01 nrf;
|
||||
nrf.Init(&spi, ce, irq, power);
|
||||
|
||||
auto tc = TinyConfig::Create();
|
||||
if(tc->Channel == 0)
|
||||
{
|
||||
tc->Channel = 120;
|
||||
tc->Speed = 250;
|
||||
}
|
||||
if(tc->Interval == 0)
|
||||
{
|
||||
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;
|
||||
|
||||
if(WirelessLed) net->Led = CreateFlushPort(WirelessLed);
|
||||
|
||||
nrf.Master = true;
|
||||
|
||||
return &nrf;
|
||||
}*/
|
||||
|
||||
void AP0803::Restore()
|
||||
{
|
||||
if (!Client) return;
|
||||
|
||||
if (Client) Client->Reset("按键重置");
|
||||
}
|
||||
|
||||
int AP0803::GetStatus()
|
||||
{
|
||||
if (!Client) return 0;
|
||||
|
||||
return Client->Status;
|
||||
}
|
||||
|
||||
void AP0803::OnLongPress(InputPort* port, bool down)
|
||||
{
|
||||
if (down) return;
|
||||
|
||||
debug_printf("Press P%c%d Time=%d ms\r\n", _PIN_NAME(port->_Pin), port->PressTime);
|
||||
|
||||
ushort time = port->PressTime;
|
||||
auto client = Client;
|
||||
if (time >= 5000 && time < 10000)
|
||||
{
|
||||
if (client) client->Reset("按键重置");
|
||||
}
|
||||
else if (time >= 3000)
|
||||
{
|
||||
if (client) client->Reboot("按键重启");
|
||||
Sys.Reboot(1000);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
GPRS(COM4)
|
||||
|
|
|
@ -1,62 +1,32 @@
|
|||
#ifndef _AP0803_H_
|
||||
#define _AP0803_H_
|
||||
|
||||
#include "Kernel\Sys.h"
|
||||
#include "Net\ITransport.h"
|
||||
#include "TokenBoard.h"
|
||||
|
||||
#include "Net\Socket.h"
|
||||
|
||||
#include "Device\SerialPort.h"
|
||||
#include "App\Alarm.h"
|
||||
|
||||
// 阿波罗0803 GPRS通信
|
||||
class AP0803
|
||||
class AP0803 : public TokenBoard
|
||||
{
|
||||
public:
|
||||
List<Pin> LedPins;
|
||||
List<Pin> ButtonPins;
|
||||
List<OutputPort*> Leds;
|
||||
List<InputPort*> Buttons;
|
||||
|
||||
List<OutputPort*> Outputs;
|
||||
List<InputPort*> Inputs;
|
||||
|
||||
Alarm* AlarmObj;
|
||||
|
||||
SerialConfig Gsm;
|
||||
|
||||
AP0803();
|
||||
|
||||
// 设置系统参数
|
||||
void Init(ushort code, cstring name, COM message = COM1);
|
||||
|
||||
// 设置数据区
|
||||
void* InitData(void* data, int size);
|
||||
// 写入数据区并上报
|
||||
void Write(uint offset, byte data);
|
||||
//获取客户端的状态0,未握手,1已握手,2已经登陆
|
||||
int GetStatus();
|
||||
|
||||
typedef bool(*Handler)(uint offset, uint size, bool write);
|
||||
void Register(uint offset, uint size, Handler hook);
|
||||
void Register(uint offset, IDataPort& dp);
|
||||
|
||||
void InitLeds();
|
||||
void InitButtons(const Delegate2<InputPort&, bool>& press);
|
||||
|
||||
// 打开GPRS
|
||||
NetworkInterface* CreateGPRS();
|
||||
|
||||
void InitClient();
|
||||
void InitNet();
|
||||
void InitProxy();
|
||||
void InitAlarm();
|
||||
void Restore();
|
||||
// invoke指令
|
||||
void Invoke(const String& ation, const Buffer& bs);
|
||||
void OnLongPress(InputPort* port, bool down);
|
||||
|
||||
static AP0803* Current;
|
||||
|
||||
private:
|
||||
void* Data;
|
||||
int Size;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -18,11 +18,7 @@ void BaseBoard::Init(ushort code, cstring name)
|
|||
sys.Name = (char*)name;
|
||||
|
||||
// RTC 提取时间
|
||||
auto Rtc = HardRTC::Instance();
|
||||
Rtc->LowPower = false;
|
||||
Rtc->External = false;
|
||||
Rtc->Init();
|
||||
Rtc->Start(false, false);
|
||||
HardRTC::Start(false, false);
|
||||
|
||||
// 初始化系统
|
||||
sys.Init();
|
||||
|
@ -33,6 +29,7 @@ void BaseBoard::Init(ushort code, cstring name)
|
|||
|
||||
#if DEBUG
|
||||
Sys.ShowInfo();
|
||||
debug_printf("hot=%p \r\n", hot);
|
||||
|
||||
WatchDog::Start(20000, 10000);
|
||||
#else
|
||||
|
|
|
@ -31,37 +31,6 @@ IOK026X::IOK026X()
|
|||
Pass = "12345678";
|
||||
}
|
||||
|
||||
void IOK026X::Init(ushort code, cstring name, COM message)
|
||||
{
|
||||
auto& sys = (TSys&)Sys;
|
||||
sys.Code = code;
|
||||
sys.Name = (char*)name;
|
||||
|
||||
// RTC 提取时间
|
||||
auto Rtc = HardRTC::Instance();
|
||||
Rtc->LowPower = false;
|
||||
Rtc->External = false;
|
||||
Rtc->Init();
|
||||
Rtc->Start(false, false);
|
||||
|
||||
// 初始化系统
|
||||
sys.Init();
|
||||
#if DEBUG
|
||||
sys.MessagePort = message; // 指定printf输出的串口
|
||||
Sys.ShowInfo();
|
||||
|
||||
WatchDog::Start(20000, 10000);
|
||||
#else
|
||||
WatchDog::Start();
|
||||
|
||||
// 系统休眠时自动进入低功耗
|
||||
Power::AttachTimeSleep();
|
||||
#endif
|
||||
|
||||
// Flash最后一块作为配置区
|
||||
Config::Current = &Config::CreateFlash();
|
||||
}
|
||||
|
||||
void* IOK026X::InitData(void* data, int size)
|
||||
{
|
||||
// 启动信息
|
||||
|
|
|
@ -28,8 +28,6 @@ public:
|
|||
|
||||
IOK026X();
|
||||
|
||||
void Init(ushort code, cstring name, COM message = COM1);
|
||||
|
||||
void* InitData(void* data, int size);
|
||||
void InitWiFi(cstring ssid, cstring pass);
|
||||
void Register(int index, IDataPort& dp);
|
||||
|
|
|
@ -29,37 +29,6 @@ NH3_0317::NH3_0317()
|
|||
Current = this;
|
||||
}
|
||||
|
||||
void NH3_0317::Init(ushort code, cstring name, COM message)
|
||||
{
|
||||
auto& sys = (TSys&)Sys;
|
||||
sys.Code = code;
|
||||
sys.Name = (char*)name;
|
||||
|
||||
// RTC 提取时间
|
||||
auto Rtc = HardRTC::Instance();
|
||||
Rtc->LowPower = false;
|
||||
Rtc->External = false;
|
||||
Rtc->Init();
|
||||
Rtc->Start(false, false);
|
||||
|
||||
// 初始化系统
|
||||
sys.Init();
|
||||
#if DEBUG
|
||||
sys.MessagePort = message; // 指定printf输出的串口
|
||||
Sys.ShowInfo();
|
||||
|
||||
WatchDog::Start(20000, 10000);
|
||||
#else
|
||||
WatchDog::Start();
|
||||
|
||||
// 系统休眠时自动进入低功耗
|
||||
//Power::AttachTimeSleep();
|
||||
#endif
|
||||
|
||||
// Flash最后一块作为配置区
|
||||
Config::Current = &Config::CreateFlash();
|
||||
}
|
||||
|
||||
void* NH3_0317::InitData(void* data, int size)
|
||||
{
|
||||
// 启动信息
|
||||
|
|
|
@ -27,8 +27,6 @@ public:
|
|||
|
||||
NH3_0317();
|
||||
|
||||
void Init(ushort code, cstring name, COM message = COM1);
|
||||
|
||||
void* InitData(void* data, int size);
|
||||
void Register(int index, IDataPort& dp);
|
||||
|
||||
|
|
|
@ -29,33 +29,6 @@ PA0903::PA0903()
|
|||
Current = this;
|
||||
}
|
||||
|
||||
void PA0903::Init(ushort code, cstring name, COM message)
|
||||
{
|
||||
auto& sys = (TSys&)Sys;
|
||||
sys.Code = code;
|
||||
sys.Name = (char*)name;
|
||||
|
||||
// RTC 提取时间
|
||||
HardRTC::Start(false, false);
|
||||
|
||||
// 初始化系统
|
||||
sys.Init();
|
||||
#if DEBUG
|
||||
sys.MessagePort = message; // 指定printf输出的串口
|
||||
Sys.ShowInfo();
|
||||
|
||||
WatchDog::Start(20000, 10000);
|
||||
#else
|
||||
WatchDog::Start();
|
||||
|
||||
// 系统休眠时自动进入低功耗
|
||||
Power::AttachTimeSleep();
|
||||
#endif
|
||||
|
||||
// Flash最后一块作为配置区
|
||||
Config::Current = &Config::CreateFlash();
|
||||
}
|
||||
|
||||
void* PA0903::InitData(void* data, int size)
|
||||
{
|
||||
// 启动信息
|
||||
|
|
|
@ -26,9 +26,6 @@ public:
|
|||
|
||||
PA0903();
|
||||
|
||||
// 设置系统参数
|
||||
void Init(ushort code, cstring name, COM message = COM2);
|
||||
|
||||
// 设置数据区
|
||||
void* InitData(void* data, int size);
|
||||
// 写入数据区并上报
|
||||
|
|
|
@ -26,7 +26,7 @@ void* TokenBoard::InitData(void* data, int size)
|
|||
Size = size;
|
||||
|
||||
#if DEBUG
|
||||
debug_printf("数据区%d:", hot->Times);
|
||||
debug_printf("数据区[%d]:", hot->Times);
|
||||
Buffer(Data, Size).Show(true);
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue