From 00dba87ad6b8c075df27b7c159a331bdbf7e8db7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=9F=B3=E5=A4=B4?= Date: Tue, 5 Sep 2017 22:12:57 +0800 Subject: [PATCH] =?UTF-8?q?v4.0.2017.0905=09=E7=89=A9=E8=81=94=E5=8D=8F?= =?UTF-8?q?=E8=AE=AELink=E5=8F=96=E4=BB=A3=E4=BB=A4=E7=89=8C=E5=8D=8F?= =?UTF-8?q?=E8=AE=AE=EF=BC=8C=E7=BD=91=E7=BB=9C=E4=BC=98=E5=85=88=EF=BC=8C?= =?UTF-8?q?Json=E4=BC=98=E5=85=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Board/AP0801.cpp | 51 ---------- Board/AP0801.h | 12 --- Board/AP0803.cpp | 52 ---------- Board/AP0803.h | 7 -- Board/Pandora.cpp | 243 ++-------------------------------------------- Board/Pandora.h | 48 +-------- Kernel/Sys.h | 2 + 7 files changed, 15 insertions(+), 400 deletions(-) diff --git a/Board/AP0801.cpp b/Board/AP0801.cpp index e5677cc1..cdd47be5 100644 --- a/Board/AP0801.cpp +++ b/Board/AP0801.cpp @@ -4,10 +4,7 @@ #include "Drivers\W5500.h" #include "Drivers\Esp8266\Esp8266.h" -//#include "Message\ProxyFactory.h" - AP0801* AP0801::Current = nullptr; -//static ProxyFactory* ProxyFac = nullptr; // 透传管理器 AP0801::AP0801() { @@ -18,57 +15,9 @@ AP0801::AP0801() LedInvert = false; - //ProxyFac = nullptr; - //AlarmObj = nullptr; - Current = this; } -/*void AP0801::InitProxy() -{ - if (ProxyFac)return; - if (!Client) - { - debug_printf("请先初始化TokenClient!!\r\n"); - return; - } - ProxyFac = ProxyFactory::Create(); - - ProxyFac->Register(new ComProxy(COM2)); - - ProxyFac->Open(Client); - // ProxyFac->AutoStart(); // 自动启动的设备 需要保证Client已经开启,否则没有意义 -} - -static void OnAlarm(AlarmItem& item) -{ - // 1长度n + 1类型 + 1偏移 + (n-2)数据 - auto bs = item.GetData(); - debug_printf("OnAlarm "); - bs.Show(true); - - if (bs[1] == 0x06) - { - auto client = AP0801::Current->Client; - client->Store.Write(bs[2], bs.Sub(3, bs[0] - 2)); - - // 主动上报状态 - client->ReportAsync(bs[2], bs[0] - 2); - } -} - -void AP0801::InitAlarm() -{ - if (!Client)return; - - if (!AlarmObj) AlarmObj = new Alarm(); - Client->Register("Policy/AlarmSet", &Alarm::Set, AlarmObj); - Client->Register("Policy/AlarmGet", &Alarm::Get, AlarmObj); - - AlarmObj->OnAlarm = OnAlarm; - AlarmObj->Start(); -}*/ - /******************************** 2401 ********************************/ /*int Fix2401(const Buffer& bs) diff --git a/Board/AP0801.h b/Board/AP0801.h index e5850b2e..02e29eba 100644 --- a/Board/AP0801.h +++ b/Board/AP0801.h @@ -5,13 +5,6 @@ #include "W5500Module.h" #include "Esp8266Module.h" -#include "Net\Socket.h" - -#include "Device\Spi.h" -#include "Device\SerialPort.h" - -//#include "App\Alarm.h" - // 阿波罗0801 class AP0801 : public BaseBoard, public W5500Module, public Esp8266Module { @@ -19,13 +12,8 @@ public: List Outputs; List Inputs; - //Alarm* AlarmObj; - AP0801(); - //void InitProxy(); - //void InitAlarm(); - static AP0801* Current; }; diff --git a/Board/AP0803.cpp b/Board/AP0803.cpp index 11949fb5..cb041890 100644 --- a/Board/AP0803.cpp +++ b/Board/AP0803.cpp @@ -1,9 +1,6 @@ #include "AP0803.h" -//#include "Message\ProxyFactory.h" - AP0803* AP0803::Current = nullptr; -//static ProxyFactory* ProxyFac = nullptr; // 透传管理器 AP0803::AP0803() { @@ -13,10 +10,6 @@ AP0803::AP0803() ButtonPins.Add(PE9); ButtonPins.Add(PE14); - /*Client = nullptr; - ProxyFac = nullptr; - AlarmObj = nullptr;*/ - Gsm.Com = COM4; Gsm.Baudrate = 115200; Gsm.Power = PE0; // 0A04(170509)板上电源为PA4 @@ -26,51 +19,6 @@ AP0803::AP0803() Current = this; } -/*void AP0803::InitProxy() -{ - if (ProxyFac)return; - if (!Client) - { - debug_printf("请先初始化TokenClient!!\r\n"); - return; - } - ProxyFac = ProxyFactory::Create(); - - ProxyFac->Register(new ComProxy(COM2)); - - ProxyFac->Open(Client); - // ProxyFac->AutoStart(); // 自动启动的设备 需要保证Client已经开启,否则没有意义 -} - -static void OnAlarm(AlarmItem& item) -{ - // 1长度n + 1类型 + 1偏移 + (n-2)数据 - auto bs = item.GetData(); - debug_printf("OnAlarm "); - bs.Show(true); - - if (bs[1] == 0x06) - { - auto client = AP0803::Current->Client; - client->Store.Write(bs[2], bs.Sub(3, bs[0] - 2)); - - // 主动上报状态 - client->ReportAsync(bs[2], bs[0] - 2); - } -} - -void AP0803::InitAlarm() -{ - if (!Client)return; - - if (!AlarmObj) AlarmObj = new Alarm(); - Client->Register("Policy/AlarmSet", &Alarm::Set, AlarmObj); - Client->Register("Policy/AlarmGet", &Alarm::Get, AlarmObj); - - AlarmObj->OnAlarm = OnAlarm; - AlarmObj->Start(); -}*/ - /* GPRS(COM2) diff --git a/Board/AP0803.h b/Board/AP0803.h index bc115ef2..1e832b0a 100644 --- a/Board/AP0803.h +++ b/Board/AP0803.h @@ -4,8 +4,6 @@ #include "BaseBoard.h" #include "GsmModule.h" -//#include "App\Alarm.h" - // 阿波罗0803 GPRS通信 class AP0803 : public BaseBoard, public GsmModule { @@ -13,13 +11,8 @@ public: List Outputs; List Inputs; - //Alarm* AlarmObj; - AP0803(); - //void InitProxy(); - //void InitAlarm(); - static AP0803* Current; }; diff --git a/Board/Pandora.cpp b/Board/Pandora.cpp index 24f26596..5a1f30b1 100644 --- a/Board/Pandora.cpp +++ b/Board/Pandora.cpp @@ -1,246 +1,21 @@ #include "Pandora.h" -#include "Kernel\Task.h" - -#include "Device\WatchDog.h" -#include "Config.h" - -#include "Device\Spi.h" -#include "Drivers\W5500.h" -#include "Drivers\Esp8266\Esp8266.h" -#include "TokenNet\TokenController.h" - -#include "Device\RTC.h" - PA0903* PA0903::Current = nullptr; -static TokenClient* Client = nullptr; // 令牌客户端 PA0903::PA0903() { LedPins.Add(PB1); LedPins.Add(PB14); - Client = nullptr; - ProxyFac = nullptr; - AlarmObj = nullptr; + Net.Spi = Spi1; + Net.Irq = PA8; + Net.Reset = PA0; + + Esp.Com = COM4; + Esp.Baudrate = 115200; + Esp.Power = PE2; + Esp.Reset = PD3; + Esp.LowPower = P0; - Data = nullptr; - Size = 0; Current = this; } - -void* PA0903::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("数据区%d:", hot->Times); - Buffer(Data, Size).Show(true); -#endif - - return data; -} - -// 写入数据区并上报 -void PA0903::Write(uint offset, byte data) -{ - auto client = Client; - if (!client) return; - - client->Store.Write(offset, data); - client->ReportAsync(offset, 1); -} - -void PA0903::InitLeds() -{ - for (int i = 0; i < LedPins.Count(); i++) - { - auto port = new OutputPort(LedPins[i]); - port->Open(); - Leds.Add(port); - } -} - -void PA0903::InitButtons(const Delegate2& press) -{ - for (int i = 0; i < ButtonPins.Count(); i++) - { - auto port = new InputPort(); - port->Index = i; - port->Init(ButtonPins[i], true); - //port->ShakeTime = 40; - port->Press = press; - port->UsePress(); - port->Open(); - - Buttons.Add(port); - } -} - -NetworkInterface* PA0903::Create5500() -{ - debug_printf("\r\nW5500::Create \r\n"); - - auto net = new W5500(Spi1, PA8, PA0); - if(!net->Open()) - { - delete net; - return nullptr; - } - - net->SetLed(*Leds[0]); - net->EnableDNS(); - net->EnableDHCP(); - - return net; -} - -NetworkInterface* PA0903::Create8266() -{ - auto esp = new Esp8266(); - esp->Init(COM4); - esp->Set(PE2, PD3); - // 初次需要指定模式 否则为 Wire - bool join = esp->SSID && *esp->SSID; - // esp->Mode = NetworkType::Station; - // if (!join) esp->Mode = NetworkType::AP; - if (!join) - { - *esp->SSID = "WSWL"; - *esp->Pass = "12345678"; - - esp->Mode = NetworkType::STA_AP; - esp->WorkMode = NetworkType::STA_AP; - } - - if(!esp->Open()) - { - delete esp; - return nullptr; - } - - esp->SetLed(*Leds[1]); - Client->Register("SetWiFi", &Esp8266::SetWiFi, esp); - Client->Register("GetWiFi", &Esp8266::GetWiFi, esp); - - return esp; -} - -/******************************** Token ********************************/ - -void PA0903::InitClient() -{ - if (Client) return; - - // 创建客户端 - auto tc = TokenClient::Create("udp://smart.wslink.cn:33333", Buffer(Data, Size)); - tc->UseLocal(); - - Client = tc; -} - -void PA0903::Register(int index, IDataPort& dp) -{ - if (!Client) return; - - auto& ds = Client->Store; - ds.Register(index, dp); -} - -void OnInitNet(void* param) -{ - auto& bsp = *(PA0903*)param; - - bsp.Create5500(); - bsp.Create8266(); - - Client->Open(); -} - -void PA0903::InitNet() -{ - Sys.AddTask(OnInitNet, this, 0, -1, "InitNet"); -} - -void PA0903::InitProxy() -{ - if (ProxyFac)return; - if (!Client) - { - debug_printf("请先初始化TokenClient!!\r\n"); - return; - } - ProxyFac = ProxyFactory::Create(); - - ProxyFac->Register(new ComProxy(COM1)); - - ProxyFac->Open(Client); - // ProxyFac->AutoStart(); // 自动启动的设备 需要保证Client已经开启,否则没有意义 -} - -static void OnAlarm(AlarmItem& item) -{ - // 1长度n + 1类型 + 1偏移 + (n-2)数据 - auto bs = item.GetData(); - debug_printf("OnAlarm "); - bs.Show(true); - - if (bs[1] == 0x06) - { - auto client = Client; - client->Store.Write(bs[2], bs.Sub(3, bs[0] - 2)); - - // 主动上报状态 - client->ReportAsync(bs[2], bs[0] - 2); - } -} - -void PA0903::InitAlarm() -{ - if (!Client)return; - - if (!AlarmObj) AlarmObj = new Alarm(); - Client->Register("Policy/AlarmSet", &Alarm::Set, AlarmObj); - Client->Register("Policy/AlarmGet", &Alarm::Get, AlarmObj); - - AlarmObj->OnAlarm = OnAlarm; - AlarmObj->Start(); -} - -void PA0903::Restore() -{ - if (Client) Client->Reset("按键重置"); -} - - -void PA0903::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); - } -} diff --git a/Board/Pandora.h b/Board/Pandora.h index 0c1fa728..e53e0549 100644 --- a/Board/Pandora.h +++ b/Board/Pandora.h @@ -1,60 +1,20 @@ #ifndef _Pandora_H_ #define _Pandora_H_ -#include "Kernel\Sys.h" -#include "Net\ITransport.h" -#include "Net\Socket.h" - -#include "Device\RTC.h" -#include "Message\ProxyFactory.h" -#include "App\Alarm.h" +#include "BaseBoard.h" +#include "W5500Module.h" +#include "Esp8266Module.h" // 潘多拉0903 -class PA0903 +class PA0903 : public BaseBoard, public W5500Module, public Esp8266Module { public: - List LedPins; - List ButtonPins; - List Leds; - List Buttons; - //List Outputs; //List Inputs; - - ProxyFactory* ProxyFac; // 透传管理器 - Alarm* AlarmObj; PA0903(); - // 设置数据区 - void* InitData(void* data, int size); - // 写入数据区并上报 - void Write(uint offset, byte data); - void Register(int index, IDataPort& dp); - - void InitLeds(); - void InitButtons(const Delegate2& press); - - // 打开以太网W5500 - NetworkInterface* Create5500(); - - // 打开Esp8266,作为主控或者纯AP - NetworkInterface* Create8266(); - //ITransport* Create2401(); - - void InitClient(); - void InitNet(); - void InitProxy(); - void InitAlarm(); - - void Restore(); - void OnLongPress(InputPort* port, bool down); - static PA0903* Current; - -private: - void* Data; - int Size; }; #endif diff --git a/Kernel/Sys.h b/Kernel/Sys.h index 8c3dce7b..9fad5456 100644 --- a/Kernel/Sys.h +++ b/Kernel/Sys.h @@ -234,6 +234,8 @@ public: #endif //_Sys_H_ /* +v4.0.2017.0905 物联协议Link取代令牌协议,网络优先,Json优先 + v3.2.2016.0517 核心类独立到目录Core,平台无关,系统无关 v3.1.2015.1108 增加系统配置存储模块,增加电源管理模块