准备调整网络架构为多网络接口共存架构,有线无线网同时使用。
ISocketHost=>NetworkInterface ISocket=>Socket
This commit is contained in:
parent
925e40d32f
commit
1e5255699f
|
@ -131,7 +131,7 @@ void AP0103::InitButtons(const Delegate2<InputPort&, bool>& press)
|
|||
|
||||
/******************************** Token ********************************/
|
||||
|
||||
ISocketHost* AP0103::Create5500()
|
||||
NetworkInterface* AP0103::Create5500()
|
||||
{
|
||||
debug_printf("\r\nW5500::Create \r\n");
|
||||
auto tc = TinyConfig::Create();
|
||||
|
@ -147,19 +147,19 @@ ISocketHost* AP0103::Create5500()
|
|||
return host;
|
||||
}
|
||||
|
||||
ISocketHost* AP0103::Create8266(bool apOnly)
|
||||
NetworkInterface* AP0103::Create8266(bool apOnly)
|
||||
{
|
||||
auto host = new Esp8266(COM4, P0, P0);
|
||||
|
||||
// 初次需要指定模式 否则为 Wire
|
||||
bool join = host->SSID && *host->SSID;
|
||||
//if (!join) host->Mode = SocketMode::AP;
|
||||
//if (!join) host->Mode = NetworkType::AP;
|
||||
if (!join)
|
||||
{
|
||||
*host->SSID = "WSWL";
|
||||
*host->Pass = "12345678";
|
||||
|
||||
host->Mode = SocketMode::STA_AP;
|
||||
host->Mode = NetworkType::STA_AP;
|
||||
}
|
||||
|
||||
// 绑定委托,避免5500没有连接时导致没有启动客户端
|
||||
|
@ -227,7 +227,7 @@ void AP0103::Register(int index, IDataPort& dp)
|
|||
ds.Register(index, dp);
|
||||
}
|
||||
|
||||
void AP0103::OpenClient(ISocketHost& host)
|
||||
void AP0103::OpenClient(NetworkInterface& host)
|
||||
{
|
||||
assert(Client, "Client");
|
||||
|
||||
|
@ -306,7 +306,7 @@ void AP0103::OpenClient(ISocketHost& host)
|
|||
}
|
||||
}
|
||||
|
||||
TokenController* AP0103::AddControl(ISocketHost& host, const NetUri& uri, ushort localPort)
|
||||
TokenController* AP0103::AddControl(NetworkInterface& host, const NetUri& uri, ushort localPort)
|
||||
{
|
||||
// 创建连接服务器的Socket
|
||||
auto socket = host.CreateRemote(uri);
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include "Sys.h"
|
||||
#include "Net\ITransport.h"
|
||||
#include "Net\Socket.h"
|
||||
|
||||
#include "TokenNet\TokenClient.h"
|
||||
#include "TinyNet\TinyServer.h"
|
||||
#include "TokenNet\GateWay.h"
|
||||
|
@ -23,8 +25,8 @@ public:
|
|||
List<OutputPort*> Outputs;
|
||||
List<InputPort*> Inputs;
|
||||
|
||||
ISocketHost* Host; // 网络主机
|
||||
ISocketHost* HostAP; // 网络主机
|
||||
NetworkInterface* Host; // 网络主机
|
||||
NetworkInterface* HostAP; // 网络主机
|
||||
TokenClient* Client; // 令牌客户端
|
||||
|
||||
ITransport* Nrf; // NRF24L01传输口
|
||||
|
@ -48,9 +50,9 @@ public:
|
|||
void InitButtons(const Delegate2<InputPort&, bool>& press);
|
||||
|
||||
// 打开以太网W5500
|
||||
ISocketHost* Create5500();
|
||||
NetworkInterface* Create5500();
|
||||
// 打开Esp8266,作为主控或者纯AP
|
||||
ISocketHost* Create8266(bool apOnly);
|
||||
NetworkInterface* Create8266(bool apOnly);
|
||||
|
||||
void InitClient();
|
||||
void InitNet();
|
||||
|
@ -77,8 +79,8 @@ private:
|
|||
bool EspMaster;
|
||||
bool EspBra;
|
||||
|
||||
void OpenClient(ISocketHost& host);
|
||||
TokenController* AddControl(ISocketHost& host, const NetUri& uri, ushort localPort);
|
||||
void OpenClient(NetworkInterface& host);
|
||||
TokenController* AddControl(NetworkInterface& host, const NetUri& uri, ushort localPort);
|
||||
|
||||
static int Fix2401(const Buffer& bs);
|
||||
};
|
||||
|
|
|
@ -131,7 +131,7 @@ void AP0104::InitButtons(const Delegate2<InputPort&, bool>& press)
|
|||
|
||||
/******************************** Token ********************************/
|
||||
|
||||
ISocketHost* AP0104::Create5500()
|
||||
NetworkInterface* AP0104::Create5500()
|
||||
{
|
||||
debug_printf("\r\nW5500::Create \r\n");
|
||||
|
||||
|
@ -141,19 +141,19 @@ ISocketHost* AP0104::Create5500()
|
|||
return host;
|
||||
}
|
||||
|
||||
ISocketHost* AP0104::Create8266(bool apOnly)
|
||||
NetworkInterface* AP0104::Create8266(bool apOnly)
|
||||
{
|
||||
auto host = new Esp8266(COM4, P0, P0);
|
||||
|
||||
// 初次需要指定模式 否则为 Wire
|
||||
bool join = host->SSID && *host->SSID;
|
||||
//if (!join) host->Mode = SocketMode::AP;
|
||||
//if (!join) host->Mode = NetworkType::AP;
|
||||
if (!join)
|
||||
{
|
||||
*host->SSID = "WSWL";
|
||||
*host->Pass = "12345678";
|
||||
|
||||
host->Mode = SocketMode::STA_AP;
|
||||
host->Mode = NetworkType::STA_AP;
|
||||
}
|
||||
|
||||
// 绑定委托,避免5500没有连接时导致没有启动客户端
|
||||
|
@ -221,7 +221,7 @@ void AP0104::Register(int index, IDataPort& dp)
|
|||
ds.Register(index, dp);
|
||||
}
|
||||
|
||||
void AP0104::OpenClient(ISocketHost& host)
|
||||
void AP0104::OpenClient(NetworkInterface& host)
|
||||
{
|
||||
assert(Client, "Client");
|
||||
|
||||
|
@ -300,7 +300,7 @@ void AP0104::OpenClient(ISocketHost& host)
|
|||
}
|
||||
}
|
||||
|
||||
TokenController* AP0104::AddControl(ISocketHost& host, const NetUri& uri, ushort localPort)
|
||||
TokenController* AP0104::AddControl(NetworkInterface& host, const NetUri& uri, ushort localPort)
|
||||
{
|
||||
// 创建连接服务器的Socket
|
||||
auto socket = host.CreateRemote(uri);
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include "Sys.h"
|
||||
#include "Net\ITransport.h"
|
||||
#include "Net\Socket.h"
|
||||
|
||||
#include "TokenNet\TokenClient.h"
|
||||
#include "TinyNet\TinyServer.h"
|
||||
#include "TokenNet\GateWay.h"
|
||||
|
@ -23,8 +25,8 @@ public:
|
|||
List<OutputPort*> Outputs;
|
||||
List<InputPort*> Inputs;
|
||||
|
||||
ISocketHost* Host; // 网络主机
|
||||
ISocketHost* HostAP; // 网络主机
|
||||
NetworkInterface* Host; // 网络主机
|
||||
NetworkInterface* HostAP; // 网络主机
|
||||
TokenClient* Client; // 令牌客户端
|
||||
|
||||
ITransport* Nrf; // NRF24L01传输口
|
||||
|
@ -47,9 +49,9 @@ public:
|
|||
void InitButtons(const Delegate2<InputPort&, bool>& press);
|
||||
|
||||
// 打开以太网W5500
|
||||
ISocketHost* Create5500();
|
||||
NetworkInterface* Create5500();
|
||||
// 打开Esp8266,作为主控或者纯AP
|
||||
ISocketHost* Create8266(bool apOnly);
|
||||
NetworkInterface* Create8266(bool apOnly);
|
||||
|
||||
void InitClient();
|
||||
void InitNet();
|
||||
|
@ -76,8 +78,8 @@ private:
|
|||
bool EspMaster;
|
||||
bool EspBra;
|
||||
|
||||
void OpenClient(ISocketHost& host);
|
||||
TokenController* AddControl(ISocketHost& host, const NetUri& uri, ushort localPort);
|
||||
void OpenClient(NetworkInterface& host);
|
||||
TokenController* AddControl(NetworkInterface& host, const NetUri& uri, ushort localPort);
|
||||
|
||||
static int Fix2401(const Buffer& bs);
|
||||
};
|
||||
|
|
|
@ -129,7 +129,7 @@ void AP0801::InitButtons(const Delegate2<InputPort&, bool>& press)
|
|||
}
|
||||
}
|
||||
|
||||
ISocketHost* AP0801::Create5500()
|
||||
NetworkInterface* AP0801::Create5500()
|
||||
{
|
||||
debug_printf("\r\nW5500::Create \r\n");
|
||||
|
||||
|
@ -148,21 +148,21 @@ ISocketHost* AP0801::Create5500()
|
|||
tc->Register("SetWiFi", &Esp8266::SetWiFi, esp);
|
||||
}*/
|
||||
|
||||
ISocketHost* AP0801::Create8266(bool apOnly)
|
||||
NetworkInterface* AP0801::Create8266(bool apOnly)
|
||||
{
|
||||
auto host = new Esp8266(COM4, PE2, PD3);
|
||||
|
||||
// 初次需要指定模式 否则为 Wire
|
||||
bool join = host->SSID && *host->SSID;
|
||||
// host->Mode = SocketMode::Station;
|
||||
// if (!join) host->Mode = SocketMode::AP;
|
||||
// host->Mode = NetworkType::Station;
|
||||
// if (!join) host->Mode = NetworkType::AP;
|
||||
if (!join)
|
||||
{
|
||||
*host->SSID = "WSWL";
|
||||
*host->Pass = "12345678";
|
||||
|
||||
host->Mode = SocketMode::STA_AP;
|
||||
host->WorkMode = SocketMode::STA_AP;
|
||||
host->Mode = NetworkType::STA_AP;
|
||||
host->WorkMode = NetworkType::STA_AP;
|
||||
}
|
||||
|
||||
// 绑定委托,避免5500没有连接时导致没有启动客户端
|
||||
|
@ -245,7 +245,7 @@ void AP0801::Register(uint offset, uint size, Handler hook)
|
|||
ds.Register(offset, size, hook);
|
||||
}
|
||||
|
||||
void AP0801::OpenClient(ISocketHost& host)
|
||||
void AP0801::OpenClient(NetworkInterface& host)
|
||||
{
|
||||
assert(Client, "Client");
|
||||
// debug_printf("\r\n OpenClient Flag :0x%08X\r\n", Flag);
|
||||
|
@ -334,7 +334,7 @@ void AP0801::OpenClient(ISocketHost& host)
|
|||
// }
|
||||
}
|
||||
|
||||
void AP0801::AddControl(ISocketHost& host, const NetUri& uri, ushort localPort)
|
||||
void AP0801::AddControl(NetworkInterface& host, const NetUri& uri, ushort localPort)
|
||||
{
|
||||
// 创建连接服务器的Socket
|
||||
auto socket = host.CreateRemote(uri);
|
||||
|
|
|
@ -23,8 +23,8 @@ public:
|
|||
|
||||
// HardRTC* Rtc;
|
||||
|
||||
ISocketHost* Host; // 网络主机
|
||||
ISocketHost* HostAP; // 网络主机
|
||||
NetworkInterface* Host; // 网络主机
|
||||
NetworkInterface* HostAP; // 网络主机
|
||||
//TokenClient* Client; // 令牌客户端
|
||||
//ProxyFactory* ProxyFac; // 透传管理器
|
||||
Alarm* AlarmObj;
|
||||
|
@ -50,9 +50,9 @@ public:
|
|||
// void InitPort();
|
||||
|
||||
// 打开以太网W5500
|
||||
ISocketHost* Create5500();
|
||||
NetworkInterface* Create5500();
|
||||
// 打开Esp8266,作为主控或者纯AP
|
||||
ISocketHost* Create8266(bool apOnly);
|
||||
NetworkInterface* Create8266(bool apOnly);
|
||||
|
||||
// ITransport* Create2401();
|
||||
|
||||
|
@ -78,8 +78,8 @@ private:
|
|||
|
||||
// uint Flag; // 内部使用 标识Controller创建情况
|
||||
|
||||
void OpenClient(ISocketHost& host);
|
||||
void AddControl(ISocketHost& host, const NetUri& uri, ushort localPort);
|
||||
void OpenClient(NetworkInterface& host);
|
||||
void AddControl(NetworkInterface& host, const NetUri& uri, ushort localPort);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -162,7 +162,7 @@ void AP0802::InitButtons(const Delegate2<InputPort&, bool>& press)
|
|||
}
|
||||
}
|
||||
|
||||
ISocketHost* AP0802::Create5500()
|
||||
NetworkInterface* AP0802::Create5500()
|
||||
{
|
||||
debug_printf("\r\nW5500::Create \r\n");
|
||||
|
||||
|
@ -172,20 +172,20 @@ ISocketHost* AP0802::Create5500()
|
|||
return host;
|
||||
}
|
||||
|
||||
ISocketHost* AP0802::Create8266(bool apOnly)
|
||||
NetworkInterface* AP0802::Create8266(bool apOnly)
|
||||
{
|
||||
auto host = new Esp8266(COM4, PE0, PD3);
|
||||
|
||||
// 初次需要指定模式 否则为 Wire
|
||||
bool join = host->SSID && *host->SSID;
|
||||
//if (!join) host->Mode = SocketMode::AP;
|
||||
//if (!join) host->Mode = NetworkType::AP;
|
||||
if (!join)
|
||||
{
|
||||
*host->SSID = "WSWL";
|
||||
*host->Pass = "12345678";
|
||||
|
||||
host->Mode = SocketMode::STA_AP;
|
||||
host->WorkMode = SocketMode::STA_AP;
|
||||
host->Mode = NetworkType::STA_AP;
|
||||
host->WorkMode = NetworkType::STA_AP;
|
||||
}
|
||||
|
||||
// 绑定委托,避免5500没有连接时导致没有启动客户端
|
||||
|
@ -263,7 +263,7 @@ bool NetBra;
|
|||
bool EspMaster;
|
||||
bool EspBra;
|
||||
*/
|
||||
void AP0802::OpenClient(ISocketHost& host)
|
||||
void AP0802::OpenClient(NetworkInterface& host)
|
||||
{
|
||||
/*
|
||||
Flag 四个字节 最高字节标识esp作为Master 第二字节标识esp广播Controller
|
||||
|
@ -354,7 +354,7 @@ void AP0802::OpenClient(ISocketHost& host)
|
|||
// }
|
||||
}
|
||||
|
||||
TokenController* AP0802::AddControl(ISocketHost& host, const NetUri& uri, ushort localPort)
|
||||
TokenController* AP0802::AddControl(NetworkInterface& host, const NetUri& uri, ushort localPort)
|
||||
{
|
||||
// 创建连接服务器的Socket
|
||||
auto socket = host.CreateRemote(uri);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "Sys.h"
|
||||
#include "Net\ITransport.h"
|
||||
#include "Net\Socket.h"
|
||||
|
||||
#include "TokenNet\TokenClient.h"
|
||||
#include "Device\Port.h"
|
||||
|
@ -24,8 +25,8 @@ public:
|
|||
List<OutputPort*> Outputs;
|
||||
List<InputPort*> Inputs;
|
||||
|
||||
ISocketHost* Host; // 网络主机
|
||||
ISocketHost* HostAP; // 网络主机
|
||||
NetworkInterface* Host; // 网络主机
|
||||
NetworkInterface* HostAP; // 网络主机
|
||||
byte HardwareVer;
|
||||
|
||||
AP0802();
|
||||
|
@ -43,10 +44,10 @@ public:
|
|||
void InitPort();
|
||||
|
||||
// 打开以太网W5500
|
||||
ISocketHost* Create5500();
|
||||
NetworkInterface* Create5500();
|
||||
|
||||
// 打开Esp8266,作为主控或者纯AP
|
||||
ISocketHost* Create8266(bool apOnly);
|
||||
NetworkInterface* Create8266(bool apOnly);
|
||||
|
||||
ITransport* Create2401(SPI spi_, Pin ce, Pin irq, Pin power, bool powerInvert, IDataPort* led);
|
||||
ITransport* Create2401();
|
||||
|
@ -68,8 +69,8 @@ private:
|
|||
Alarm* AlarmObj;
|
||||
// uint Flag; // 内部使用 标识Controller创建情况
|
||||
|
||||
void OpenClient(ISocketHost& host);
|
||||
TokenController* AddControl(ISocketHost& host, const NetUri& uri, ushort localPort);
|
||||
void OpenClient(NetworkInterface& host);
|
||||
TokenController* AddControl(NetworkInterface& host, const NetUri& uri, ushort localPort);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -94,20 +94,20 @@ void IOK026X::InitLeds()
|
|||
}
|
||||
}
|
||||
|
||||
ISocketHost* IOK026X::CreateNet()
|
||||
NetworkInterface* IOK026X::CreateNet()
|
||||
{
|
||||
auto host = new Esp8266(COM2, PB2, PA1);
|
||||
|
||||
// 初次需要指定模式 否则为 Wire
|
||||
bool join = host->SSID && *host->SSID;
|
||||
//if (!join) host->Mode = SocketMode::AP;
|
||||
//if (!join) host->Mode = NetworkType::AP;
|
||||
|
||||
if (!join)
|
||||
{
|
||||
*host->SSID = "WSWL";
|
||||
*host->Pass = "12345678";
|
||||
|
||||
host->Mode = SocketMode::STA_AP;
|
||||
host->Mode = NetworkType::STA_AP;
|
||||
}
|
||||
// 绑定委托,避免5500没有连接时导致没有启动客户端
|
||||
host->NetReady.Bind(&IOK026X::OpenClient, this);
|
||||
|
@ -174,7 +174,7 @@ void IOK026X::Register(int index, IDataPort& dp)
|
|||
ds.Register(index, dp);
|
||||
}
|
||||
|
||||
void IOK026X::OpenClient(ISocketHost& host)
|
||||
void IOK026X::OpenClient(NetworkInterface& host)
|
||||
{
|
||||
assert(Client, "Client");
|
||||
|
||||
|
@ -203,7 +203,7 @@ void IOK026X::OpenClient(ISocketHost& host)
|
|||
Client->AttachControls();
|
||||
}
|
||||
|
||||
TokenController* IOK026X::AddControl(ISocketHost& host, const NetUri& uri, ushort localPort)
|
||||
TokenController* IOK026X::AddControl(NetworkInterface& host, const NetUri& uri, ushort localPort)
|
||||
{
|
||||
// 创建连接服务器的Socket
|
||||
auto socket = host.CreateRemote(uri);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "Sys.h"
|
||||
#include "Net\ITransport.h"
|
||||
#include "Net\Socket.h"
|
||||
|
||||
#include "TokenNet\TokenClient.h"
|
||||
#include "App\Alarm.h"
|
||||
|
@ -17,7 +18,7 @@ public:
|
|||
|
||||
byte LedsShow; // LED 显示状态开关 0 刚启动时候的20秒 1 使能 2 失能
|
||||
|
||||
ISocketHost* Host; // 网络主机
|
||||
NetworkInterface* Host; // 网络主机
|
||||
TokenClient* Client; //
|
||||
Alarm* AlarmObj;
|
||||
uint LedsTaskId;
|
||||
|
@ -34,7 +35,7 @@ public:
|
|||
|
||||
byte LedStat(byte showmode);
|
||||
|
||||
ISocketHost* CreateNet();
|
||||
NetworkInterface* CreateNet();
|
||||
|
||||
void InitClient();
|
||||
void InitNet();
|
||||
|
@ -50,8 +51,8 @@ private:
|
|||
void* Data;
|
||||
int Size;
|
||||
|
||||
void OpenClient(ISocketHost& host);
|
||||
TokenController* AddControl(ISocketHost& host, const NetUri& uri, ushort localPort);
|
||||
void OpenClient(NetworkInterface& host);
|
||||
TokenController* AddControl(NetworkInterface& host, const NetUri& uri, ushort localPort);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -93,19 +93,19 @@ void IOK027X::InitLeds()
|
|||
}
|
||||
}
|
||||
|
||||
ISocketHost* IOK027X::Create8266(Pin power)
|
||||
NetworkInterface* IOK027X::Create8266(Pin power)
|
||||
{
|
||||
auto host = new Esp8266(COM2, power, PA1);
|
||||
// 初次需要指定模式 否则为 Wire
|
||||
bool join = host->SSID && *host->SSID;
|
||||
//if (!join) host->Mode = SocketMode::AP;
|
||||
//if (!join) host->Mode = NetworkType::AP;
|
||||
|
||||
if (!join)
|
||||
{
|
||||
*host->SSID = "WSWL";
|
||||
*host->Pass = "12345678";
|
||||
|
||||
host->Mode = SocketMode::STA_AP;
|
||||
host->Mode = NetworkType::STA_AP;
|
||||
}
|
||||
// 绑定委托,避免5500没有连接时导致没有启动客户端
|
||||
host->NetReady.Bind(&IOK027X::OpenClient, this);
|
||||
|
@ -172,7 +172,7 @@ void IOK027X::Register(int index, IDataPort& dp)
|
|||
ds.Register(index, dp);
|
||||
}
|
||||
|
||||
void IOK027X::OpenClient(ISocketHost& host)
|
||||
void IOK027X::OpenClient(NetworkInterface& host)
|
||||
{
|
||||
assert(Client, "Client");
|
||||
|
||||
|
@ -201,7 +201,7 @@ void IOK027X::OpenClient(ISocketHost& host)
|
|||
Client->AttachControls();
|
||||
}
|
||||
|
||||
TokenController* IOK027X::AddControl(ISocketHost& host, const NetUri& uri, ushort localPort)
|
||||
TokenController* IOK027X::AddControl(NetworkInterface& host, const NetUri& uri, ushort localPort)
|
||||
{
|
||||
// 创建连接服务器的Socket
|
||||
auto socket = host.CreateRemote(uri);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "Sys.h"
|
||||
#include "Net\ITransport.h"
|
||||
#include "Net\Socket.h"
|
||||
|
||||
#include "TokenNet\TokenClient.h"
|
||||
#include "App\Alarm.h"
|
||||
|
@ -18,7 +19,7 @@ public:
|
|||
|
||||
byte LedsShow; // LED 显示状态开关 0 刚启动时候的20秒 1 使能 2 失能
|
||||
|
||||
ISocketHost* Host; // 网络主机
|
||||
NetworkInterface* Host; // 网络主机
|
||||
TokenClient* Client; //
|
||||
Alarm* AlarmObj;
|
||||
uint LedsTaskId;
|
||||
|
@ -35,7 +36,7 @@ public:
|
|||
|
||||
byte LedStat(byte showmode);
|
||||
|
||||
ISocketHost* Create8266(Pin power = PB2);
|
||||
NetworkInterface* Create8266(Pin power = PB2);
|
||||
|
||||
void InitClient();
|
||||
void InitNet(Pin power = PB2);
|
||||
|
@ -52,8 +53,8 @@ private:
|
|||
int Size;
|
||||
InputPort* RestPort;
|
||||
|
||||
void OpenClient(ISocketHost& host);
|
||||
TokenController* AddControl(ISocketHost& host, const NetUri& uri, ushort localPort);
|
||||
void OpenClient(NetworkInterface& host);
|
||||
TokenController* AddControl(NetworkInterface& host, const NetUri& uri, ushort localPort);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -114,21 +114,21 @@ void IOK0612::InitButtons(const Delegate2<InputPort&, bool>& press)
|
|||
}
|
||||
}
|
||||
|
||||
ISocketHost* IOK0612::Create8266()
|
||||
NetworkInterface* IOK0612::Create8266()
|
||||
{
|
||||
// auto host = new Esp8266(COM2, PB2, PA1); // 触摸开关的
|
||||
auto host = new Esp8266(COM2, PB12, PA1);
|
||||
|
||||
// 初次需要指定模式 否则为 Wire
|
||||
bool join = host->SSID && *host->SSID;
|
||||
//if (!join) host->Mode = SocketMode::AP;
|
||||
//if (!join) host->Mode = NetworkType::AP;
|
||||
|
||||
if (!join)
|
||||
{
|
||||
*host->SSID = "WSWL";
|
||||
*host->Pass = "12345678";
|
||||
|
||||
host->Mode = SocketMode::STA_AP;
|
||||
host->Mode = NetworkType::STA_AP;
|
||||
}
|
||||
// 绑定委托,避免5500没有连接时导致没有启动客户端
|
||||
host->NetReady.Bind(&IOK0612::OpenClient, this);
|
||||
|
@ -200,7 +200,7 @@ void IOK0612::Register(int index, IDataPort& dp)
|
|||
ds.Register(index, dp);
|
||||
}
|
||||
|
||||
void IOK0612::OpenClient(ISocketHost& host)
|
||||
void IOK0612::OpenClient(NetworkInterface& host)
|
||||
{
|
||||
assert(Client, "Client");
|
||||
|
||||
|
@ -229,7 +229,7 @@ void IOK0612::OpenClient(ISocketHost& host)
|
|||
Client->AttachControls();
|
||||
}
|
||||
|
||||
TokenController* IOK0612::AddControl(ISocketHost& host, const NetUri& uri, ushort localPort)
|
||||
TokenController* IOK0612::AddControl(NetworkInterface& host, const NetUri& uri, ushort localPort)
|
||||
{
|
||||
// 创建连接服务器的Socket
|
||||
auto socket = host.CreateRemote(uri);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "Sys.h"
|
||||
#include "Net\ITransport.h"
|
||||
#include "Net\Socket.h"
|
||||
|
||||
#include "TokenNet\TokenClient.h"
|
||||
#include "App\Alarm.h"
|
||||
|
@ -19,7 +20,7 @@ public:
|
|||
|
||||
bool LedsShow; // LED 显示状态开关
|
||||
|
||||
ISocketHost* Host; // 网络主机
|
||||
NetworkInterface* Host; // 网络主机
|
||||
TokenClient* Client; //
|
||||
Alarm* AlarmObj;
|
||||
uint LedsTaskId;
|
||||
|
@ -37,7 +38,7 @@ public:
|
|||
|
||||
bool LedStat(bool enable);
|
||||
|
||||
ISocketHost* Create8266();
|
||||
NetworkInterface* Create8266();
|
||||
|
||||
void InitClient();
|
||||
void InitNet();
|
||||
|
@ -52,8 +53,8 @@ private:
|
|||
void* Data;
|
||||
int Size;
|
||||
|
||||
void OpenClient(ISocketHost& host);
|
||||
TokenController* AddControl(ISocketHost& host, const NetUri& uri, ushort localPort);
|
||||
void OpenClient(NetworkInterface& host);
|
||||
TokenController* AddControl(NetworkInterface& host, const NetUri& uri, ushort localPort);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -114,21 +114,21 @@ void NH3_0317::InitButtons(const Delegate2<InputPort&, bool>& press)
|
|||
}
|
||||
}
|
||||
|
||||
ISocketHost* NH3_0317::Create8266()
|
||||
NetworkInterface* NH3_0317::Create8266()
|
||||
{
|
||||
// auto host = new Esp8266(COM2, PB2, PA1); // 触摸开关的
|
||||
auto host = new Esp8266(COM3, P0, PA5);
|
||||
|
||||
// 初次需要指定模式 否则为 Wire
|
||||
bool join = host->SSID && *host->SSID;
|
||||
//if (!join) host->Mode = SocketMode::AP;
|
||||
//if (!join) host->Mode = NetworkType::AP;
|
||||
|
||||
if (!join)
|
||||
{
|
||||
*host->SSID = "WSWL";
|
||||
*host->Pass = "12345678";
|
||||
|
||||
host->Mode = SocketMode::STA_AP;
|
||||
host->Mode = NetworkType::STA_AP;
|
||||
}
|
||||
// 绑定委托,避免5500没有连接时导致没有启动客户端
|
||||
host->NetReady.Bind(&NH3_0317::OpenClient, this);
|
||||
|
@ -203,7 +203,7 @@ void NH3_0317::Register(int index, IDataPort& dp)
|
|||
ds.Register(index, dp);
|
||||
}
|
||||
|
||||
void NH3_0317::OpenClient(ISocketHost& host)
|
||||
void NH3_0317::OpenClient(NetworkInterface& host)
|
||||
{
|
||||
assert(Client, "Client");
|
||||
|
||||
|
@ -230,7 +230,7 @@ void NH3_0317::OpenClient(ISocketHost& host)
|
|||
Client->AttachControls();
|
||||
}
|
||||
|
||||
TokenController* NH3_0317::AddControl(ISocketHost& host, const NetUri& uri, ushort localPort)
|
||||
TokenController* NH3_0317::AddControl(NetworkInterface& host, const NetUri& uri, ushort localPort)
|
||||
{
|
||||
// 创建连接服务器的Socket
|
||||
auto socket = host.CreateRemote(uri);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "Sys.h"
|
||||
#include "Net\ITransport.h"
|
||||
#include "Net\Socket.h"
|
||||
|
||||
#include "TokenNet\TokenClient.h"
|
||||
#include "App\Alarm.h"
|
||||
|
@ -19,7 +20,7 @@ public:
|
|||
|
||||
bool LedsShow; // LED 显示状态开关
|
||||
|
||||
ISocketHost* Host; // 网络主机
|
||||
NetworkInterface* Host; // 网络主机
|
||||
TokenClient* Client; //
|
||||
Alarm* AlarmObj;
|
||||
uint LedsTaskId;
|
||||
|
@ -37,7 +38,7 @@ public:
|
|||
|
||||
bool LedStat(bool enable);
|
||||
|
||||
ISocketHost* Create8266();
|
||||
NetworkInterface* Create8266();
|
||||
|
||||
void SetStore(void* data, int len);
|
||||
|
||||
|
@ -54,8 +55,8 @@ private:
|
|||
void* Data;
|
||||
int Size;
|
||||
|
||||
void OpenClient(ISocketHost& host);
|
||||
TokenController* AddControl(ISocketHost& host, const NetUri& uri, ushort localPort);
|
||||
void OpenClient(NetworkInterface& host);
|
||||
TokenController* AddControl(NetworkInterface& host, const NetUri& uri, ushort localPort);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -86,7 +86,7 @@ void PA0903::InitLeds()
|
|||
}
|
||||
}
|
||||
|
||||
ISocketHost* PA0903::Create5500()
|
||||
NetworkInterface* PA0903::Create5500()
|
||||
{
|
||||
debug_printf("\r\nW5500::Create \r\n");
|
||||
|
||||
|
@ -96,21 +96,21 @@ ISocketHost* PA0903::Create5500()
|
|||
return host;
|
||||
}
|
||||
|
||||
ISocketHost* PA0903::Create8266(bool apOnly)
|
||||
NetworkInterface* PA0903::Create8266(bool apOnly)
|
||||
{
|
||||
auto host = new Esp8266(COM4, PE2, PD3);
|
||||
|
||||
// 初次需要指定模式 否则为 Wire
|
||||
bool join = host->SSID && *host->SSID;
|
||||
// host->Mode = SocketMode::Station;
|
||||
// if (!join) host->Mode = SocketMode::AP;
|
||||
// host->Mode = NetworkType::Station;
|
||||
// if (!join) host->Mode = NetworkType::AP;
|
||||
if (!join)
|
||||
{
|
||||
*host->SSID = "WSWL";
|
||||
*host->Pass = "12345678";
|
||||
|
||||
host->Mode = SocketMode::STA_AP;
|
||||
host->WorkMode = SocketMode::STA_AP;
|
||||
host->Mode = NetworkType::STA_AP;
|
||||
host->WorkMode = NetworkType::STA_AP;
|
||||
}
|
||||
|
||||
// 绑定委托,避免5500没有连接时导致没有启动客户端
|
||||
|
@ -172,7 +172,7 @@ void PA0903::Register(int index, IDataPort& dp)
|
|||
ds.Register(index, dp);
|
||||
}
|
||||
|
||||
void PA0903::OpenClient(ISocketHost& host)
|
||||
void PA0903::OpenClient(NetworkInterface& host)
|
||||
{
|
||||
assert(Client, "Client");
|
||||
|
||||
|
@ -195,7 +195,7 @@ void PA0903::OpenClient(ISocketHost& host)
|
|||
}
|
||||
}
|
||||
|
||||
TokenController* PA0903::AddControl(ISocketHost& host, const NetUri& uri, ushort localPort)
|
||||
TokenController* PA0903::AddControl(NetworkInterface& host, const NetUri& uri, ushort localPort)
|
||||
{
|
||||
// 创建连接服务器的Socket
|
||||
auto socket = host.CreateRemote(uri);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "Sys.h"
|
||||
#include "Net\ITransport.h"
|
||||
#include "Net\Socket.h"
|
||||
|
||||
#include "Device\RTC.h"
|
||||
#include "TokenNet\TokenClient.h"
|
||||
|
@ -22,8 +23,8 @@ public:
|
|||
List<OutputPort*> Outputs;
|
||||
List<InputPort*> Inputs;
|
||||
|
||||
ISocketHost* Host; // 网络主机
|
||||
//ISocketHost* HostAP; // 网络主机
|
||||
NetworkInterface* Host; // 网络主机
|
||||
//NetworkInterface* HostAP; // 网络主机
|
||||
TokenClient* Client; // 令牌客户端
|
||||
ProxyFactory* ProxyFac; // 透传管理器
|
||||
Alarm* AlarmObj;
|
||||
|
@ -42,10 +43,10 @@ public:
|
|||
//void InitPort();
|
||||
|
||||
// 打开以太网W5500
|
||||
ISocketHost* Create5500();
|
||||
NetworkInterface* Create5500();
|
||||
|
||||
// 打开Esp8266,作为主控或者纯AP
|
||||
ISocketHost* Create8266(bool apOnly);
|
||||
NetworkInterface* Create8266(bool apOnly);
|
||||
//ITransport* Create2401();
|
||||
|
||||
void InitClient();
|
||||
|
@ -62,8 +63,8 @@ private:
|
|||
void* Data;
|
||||
int Size;
|
||||
|
||||
void OpenClient(ISocketHost& host);
|
||||
TokenController* AddControl(ISocketHost& host, const NetUri& uri, ushort localPort);
|
||||
void OpenClient(NetworkInterface& host);
|
||||
TokenController* AddControl(NetworkInterface& host, const NetUri& uri, ushort localPort);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -78,8 +78,8 @@ void Esp8266::Init(ITransport* port, Pin power, Pin rst)
|
|||
|
||||
Buffer(_sockets, 5 * 4).Clear();
|
||||
|
||||
Mode = SocketMode::STA_AP;
|
||||
WorkMode = SocketMode::STA_AP;
|
||||
Mode = NetworkType::STA_AP;
|
||||
WorkMode = NetworkType::STA_AP;
|
||||
|
||||
SSID = new String();
|
||||
Pass = new String();
|
||||
|
@ -162,7 +162,7 @@ bool Esp8266::OnOpen()
|
|||
|
||||
auto mode = WorkMode;
|
||||
// 默认Both
|
||||
if (mode == SocketMode::Wire) mode = SocketMode::STA_AP;
|
||||
if (mode == NetworkType::Wire) mode = NetworkType::STA_AP;
|
||||
|
||||
if (GetMode() != mode)
|
||||
{
|
||||
|
@ -183,7 +183,7 @@ bool Esp8266::OnOpen()
|
|||
// 等待WiFi自动连接
|
||||
if (!AutoConn || !WaitForCmd("WIFI CONNECTED", 3000))
|
||||
{
|
||||
if (!join || mode == SocketMode::STA_AP) OpenAP();
|
||||
if (!join || mode == NetworkType::STA_AP) OpenAP();
|
||||
if (join)
|
||||
{
|
||||
if (!_task2) _task2 = Sys.AddTask(LoopJoinTask, this, 0, 30 * 1000, "JoinAP");
|
||||
|
@ -273,7 +273,7 @@ void Esp8266::TryJoinAP()
|
|||
// 停止尝试
|
||||
Sys.RemoveTask(_task2);
|
||||
}
|
||||
else if (Mode != SocketMode::STA_AP)
|
||||
else if (Mode != NetworkType::STA_AP)
|
||||
{
|
||||
// 尝试若干次以后还是连接失败,则重启模块
|
||||
auto tsk = Task::Get(_task2);
|
||||
|
@ -313,7 +313,7 @@ void Esp8266::Config()
|
|||
SetAutoConn(AutoConn);
|
||||
}
|
||||
|
||||
ISocket* Esp8266::CreateSocket(NetType type)
|
||||
Socket* Esp8266::CreateSocket(NetType type)
|
||||
{
|
||||
auto es = (EspSocket**)_sockets;
|
||||
|
||||
|
@ -348,13 +348,13 @@ bool Esp8266::EnableDNS() { return true; }
|
|||
// 启用DHCP
|
||||
bool Esp8266::EnableDHCP()
|
||||
{
|
||||
//Mode = SocketMode::STA_AP;
|
||||
//Mode = NetworkType::STA_AP;
|
||||
//return true;
|
||||
//return SetDHCP(SocketMode::Both, true);
|
||||
//return SetDHCP(NetworkType::Both, true);
|
||||
|
||||
if (!Opened) return false;
|
||||
|
||||
if (!SetDHCP(SocketMode::STA_AP, true)) return false;
|
||||
if (!SetDHCP(NetworkType::STA_AP, true)) return false;
|
||||
|
||||
NetReady(*this);
|
||||
|
||||
|
@ -758,7 +758,7 @@ bool Esp8266::Restore()
|
|||
OK
|
||||
"
|
||||
*/
|
||||
bool Esp8266::SetMode(SocketMode mode)
|
||||
bool Esp8266::SetMode(NetworkType mode)
|
||||
{
|
||||
String cmd = "AT+CWMODE=";
|
||||
cmd += (byte)mode;
|
||||
|
@ -780,11 +780,11 @@ bool Esp8266::SetMode(SocketMode mode)
|
|||
OK
|
||||
"
|
||||
*/
|
||||
SocketMode Esp8266::GetMode()
|
||||
NetworkType Esp8266::GetMode()
|
||||
{
|
||||
TS("Esp8266::GetMode");
|
||||
|
||||
auto mod = SocketMode::Station;
|
||||
auto mod = NetworkType::Station;
|
||||
|
||||
auto rs = Send("AT+CWMODE?\r\n", "OK");
|
||||
if (!rs) return mod;
|
||||
|
@ -792,7 +792,7 @@ SocketMode Esp8266::GetMode()
|
|||
int p = rs.IndexOf(':');
|
||||
if (p < 0) return mod;
|
||||
|
||||
return (SocketMode)rs.Substring(p + 1, 1).ToInt();
|
||||
return (NetworkType)rs.Substring(p + 1, 1).ToInt();
|
||||
}
|
||||
|
||||
// +CWJAP:<ssid>,<bssid>,<channel>,<rssi>
|
||||
|
@ -928,18 +928,18 @@ bool Esp8266::GetDHCP(bool* sta, bool* ap)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Esp8266::SetDHCP(SocketMode mode, bool enable)
|
||||
bool Esp8266::SetDHCP(NetworkType mode, bool enable)
|
||||
{
|
||||
byte m = 0;
|
||||
switch (mode)
|
||||
{
|
||||
case SocketMode::Station:
|
||||
case NetworkType::Station:
|
||||
m = 1;
|
||||
break;
|
||||
case SocketMode::AP:
|
||||
case NetworkType::AP:
|
||||
m = 0;
|
||||
break;
|
||||
case SocketMode::STA_AP:
|
||||
case NetworkType::STA_AP:
|
||||
m = 2;
|
||||
break;
|
||||
default:
|
||||
|
@ -1071,9 +1071,9 @@ bool Esp8266::SetWiFi(const Pair& args, Stream& result)
|
|||
*Pass = pass;
|
||||
// 组网后单独STA模式,调试时使用混合模式
|
||||
//#if DEBUG
|
||||
// Mode = SocketMode::STA_AP;
|
||||
// Mode = NetworkType::STA_AP;
|
||||
//#else
|
||||
Mode = SocketMode::Station;
|
||||
Mode = NetworkType::Station;
|
||||
//#endif
|
||||
SaveConfig();
|
||||
}
|
||||
|
|
|
@ -9,12 +9,12 @@
|
|||
|
||||
// 最好打开 Soket 前 不注册中断,以免AT指令乱入到中断里面去 然后信息不对称
|
||||
// 安信可 ESP8266 模块固件版本 v1.3.0.2
|
||||
class Esp8266 : public PackPort, public ISocketHost
|
||||
class Esp8266 : public PackPort, public NetworkInterface
|
||||
{
|
||||
public:
|
||||
bool AutoConn; // 是否自动连接WiFi,默认false
|
||||
bool Joined; // 是否已连接热点
|
||||
SocketMode WorkMode; // 工作模式
|
||||
NetworkType WorkMode; // 工作模式
|
||||
|
||||
IDataPort* Led; // 指示灯
|
||||
|
||||
|
@ -32,7 +32,7 @@ public:
|
|||
void RemoveLed();
|
||||
|
||||
//virtual const String ToString() const { return String("Esp8266"); }
|
||||
virtual ISocket* CreateSocket(NetType type);
|
||||
virtual Socket* CreateSocket(NetType type);
|
||||
// 启用DNS
|
||||
virtual bool EnableDNS();
|
||||
// 启用DHCP
|
||||
|
@ -49,9 +49,9 @@ public:
|
|||
|
||||
/******************************** WiFi功能指令 ********************************/
|
||||
// 获取模式
|
||||
SocketMode GetMode();
|
||||
NetworkType GetMode();
|
||||
// 设置模式。需要重启
|
||||
bool SetMode(SocketMode mode);
|
||||
bool SetMode(NetworkType mode);
|
||||
|
||||
// 连接AP相关
|
||||
String GetJoinAP();
|
||||
|
@ -66,7 +66,7 @@ public:
|
|||
String LoadStations();
|
||||
|
||||
bool GetDHCP(bool* sta, bool* ap);
|
||||
bool SetDHCP(SocketMode mode, bool enable);
|
||||
bool SetDHCP(NetworkType mode, bool enable);
|
||||
|
||||
MacAddress GetMAC(bool sta);
|
||||
bool SetMAC(bool sta, const MacAddress& mac);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "Esp8266.h"
|
||||
|
||||
class EspSocket : public Object, public ITransport, public ISocket
|
||||
class EspSocket : public Object, public ITransport, public Socket
|
||||
{
|
||||
protected:
|
||||
Esp8266& _Host;
|
||||
|
|
|
@ -207,7 +207,7 @@ typedef struct : ByteStruct
|
|||
/****************************** 基础类 ************************************/
|
||||
|
||||
// 硬件Socket控制器
|
||||
class HardSocket : public Object, public ITransport, public ISocket
|
||||
class HardSocket : public Object, public ITransport, public Socket
|
||||
{
|
||||
private:
|
||||
W5500& _Host; // W5500公共部分控制器
|
||||
|
@ -751,7 +751,7 @@ bool W5500::CheckLink()
|
|||
return phy.LNK;
|
||||
}
|
||||
|
||||
ISocket* W5500::CreateSocket(NetType type)
|
||||
Socket* W5500::CreateSocket(NetType type)
|
||||
{
|
||||
if(Sockets.Count() >= 8)
|
||||
{
|
||||
|
@ -877,7 +877,7 @@ IPAddress W5500::QueryDNS(const String& domain)
|
|||
return ip;
|
||||
}
|
||||
|
||||
static IPAddress FullQueryDNS(ISocketHost* host, const String& domain)
|
||||
static IPAddress FullQueryDNS(NetworkInterface* host, const String& domain)
|
||||
{
|
||||
return DNS::Query(*host, domain);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "Net\Socket.h"
|
||||
|
||||
// W5500以太网驱动
|
||||
class W5500 : public ISocketHost
|
||||
class W5500 : public NetworkInterface
|
||||
{
|
||||
public:
|
||||
ushort RetryTime;
|
||||
|
@ -52,7 +52,7 @@ public:
|
|||
|
||||
cstring ToString() const { return "W5500"; }
|
||||
|
||||
virtual ISocket* CreateSocket(NetType type);
|
||||
virtual Socket* CreateSocket(NetType type);
|
||||
|
||||
// DNS解析。默认仅支持字符串IP地址解析
|
||||
virtual IPAddress QueryDNS(const String& domain);
|
||||
|
@ -71,12 +71,12 @@ private:
|
|||
OutputPort Rst;
|
||||
|
||||
// 8个硬件socket
|
||||
List<ISocket*> Sockets;
|
||||
List<Socket*> Sockets;
|
||||
|
||||
// spi 模式(默认变长)
|
||||
ushort PhaseOM;
|
||||
|
||||
typedef IPAddress (*DnsHandler)(ISocketHost* host, const String& domain);
|
||||
typedef IPAddress (*DnsHandler)(NetworkInterface* host, const String& domain);
|
||||
DnsHandler _Dns; // 解析域名为IP地址
|
||||
void* _Dhcp;
|
||||
|
||||
|
|
|
@ -356,7 +356,7 @@ short dns_makequery(short op, const String& name, Buffer& bs)
|
|||
return ms.Position();
|
||||
}
|
||||
|
||||
DNS::DNS(ISocketHost& host, const IPAddress& dns) : Host(host)
|
||||
DNS::DNS(NetworkInterface& host, const IPAddress& dns) : Host(host)
|
||||
{
|
||||
Socket = host.CreateSocket(NetType::Udp);
|
||||
|
||||
|
@ -437,7 +437,7 @@ void DNS::Process(Buffer& bs, const IPEndPoint& server)
|
|||
}
|
||||
|
||||
// 快捷查询。借助主机直接查询多次
|
||||
IPAddress DNS::Query(ISocketHost& host, const String& domain, int times, int msTimeout)
|
||||
IPAddress DNS::Query(NetworkInterface& host, const String& domain, int times, int msTimeout)
|
||||
{
|
||||
auto& any = IPAddress::Any();
|
||||
for(int k=0; k<2; k++)
|
||||
|
|
|
@ -7,21 +7,21 @@
|
|||
class DNS
|
||||
{
|
||||
public:
|
||||
ISocketHost& Host; // 主机
|
||||
NetworkInterface& Host; // 主机
|
||||
|
||||
DNS(ISocketHost& host, const IPAddress& dns);
|
||||
DNS(NetworkInterface& host, const IPAddress& dns);
|
||||
~DNS();
|
||||
|
||||
IPAddress Query(const String& domain, int msTimeout = 1000); // 解析
|
||||
|
||||
// 快捷查询。借助主机直接查询多次
|
||||
static IPAddress Query(ISocketHost& host, const String& domain, int times = 5, int msTimeout = 1000);
|
||||
static IPAddress Query(NetworkInterface& host, const String& domain, int times = 5, int msTimeout = 1000);
|
||||
|
||||
private:
|
||||
static uint OnReceive(ITransport* port, Buffer& bs, void* param, void* param2);
|
||||
void Process(Buffer& bs, const IPEndPoint& server);
|
||||
|
||||
ISocket* Socket;
|
||||
Socket* Socket;
|
||||
Array* _Buffer;
|
||||
};
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#define net_printf(format, ...)
|
||||
#endif
|
||||
|
||||
Dhcp::Dhcp(ISocketHost& host) : Host(host)
|
||||
Dhcp::Dhcp(NetworkInterface& host) : Host(host)
|
||||
{
|
||||
Socket = host.CreateSocket(NetType::Udp);
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ private:
|
|||
uint dhcpid; // 事务ID
|
||||
uint taskID; // 任务ID
|
||||
UInt64 _expired; // 目标过期时间,毫秒
|
||||
ISocket* Socket;
|
||||
Socket* Socket;
|
||||
|
||||
void Discover();
|
||||
void Request();
|
||||
|
@ -18,7 +18,7 @@ private:
|
|||
|
||||
static void Loop(void* param);
|
||||
public:
|
||||
ISocketHost& Host; // 主机
|
||||
NetworkInterface& Host; // 主机
|
||||
IPAddress IP; // 获取的IP地址
|
||||
|
||||
uint ExpiredTime; // 过期时间,默认5000毫秒
|
||||
|
@ -27,7 +27,7 @@ public:
|
|||
byte Times; // 运行次数
|
||||
byte MaxTimes; // 最大重试次数,默认6次,超过该次数仍然失败则恢复上一次设置
|
||||
|
||||
Dhcp(ISocketHost& host);
|
||||
Dhcp(NetworkInterface& host);
|
||||
~Dhcp();
|
||||
|
||||
void Start(); // 开始
|
||||
|
|
|
@ -0,0 +1,200 @@
|
|||
#include "NetworkInterface.h"
|
||||
#include "Config.h"
|
||||
|
||||
#define NET_DEBUG DEBUG
|
||||
//#define NET_DEBUG 0
|
||||
#if NET_DEBUG
|
||||
#define net_printf debug_printf
|
||||
#else
|
||||
#define net_printf(format, ...)
|
||||
#endif
|
||||
|
||||
/******************************** NetworkInterface ********************************/
|
||||
|
||||
struct NetConfig
|
||||
{
|
||||
uint IP; // 本地IP地址
|
||||
uint Mask; // 子网掩码
|
||||
byte Mac[6]; // 本地Mac地址
|
||||
byte Mode; // 无线模式。0不是无线,1是STA,2是AP,3是混合
|
||||
byte Reserved;
|
||||
|
||||
uint DHCPServer;
|
||||
uint DNSServer;
|
||||
uint DNSServer2;
|
||||
uint Gateway;
|
||||
|
||||
char SSID[32];
|
||||
char Pass[32];
|
||||
};
|
||||
|
||||
NetworkInterface::NetworkInterface()
|
||||
{
|
||||
Mode = NetworkType::Wire;
|
||||
|
||||
SSID = nullptr;
|
||||
Pass = nullptr;
|
||||
|
||||
//NetReady = nullptr;
|
||||
}
|
||||
|
||||
void NetworkInterface::InitConfig()
|
||||
{
|
||||
IPAddress defip(192, 168, 1, 1);
|
||||
|
||||
// 随机IP,取ID最后一个字节
|
||||
IP = defip;
|
||||
byte first = Sys.ID[0];
|
||||
if(first <= 1 || first >= 254) first = 2;
|
||||
IP[3] = first;
|
||||
|
||||
Mask = IPAddress(255, 255, 255, 0);
|
||||
DHCPServer = Gateway = defip;
|
||||
|
||||
// 修改为双DNS方案,避免单点故障。默认使用阿里和百度公共DNS。
|
||||
DNSServer = IPAddress(223, 5, 5, 5);
|
||||
DNSServer2 = IPAddress(180, 76, 76, 76);
|
||||
|
||||
auto& mac = Mac;
|
||||
// 随机Mac,前2个字节取自ASCII,最后4个字节取自后三个ID
|
||||
//mac[0] = 'W'; mac[1] = 'S';
|
||||
// 第一个字节最低位为1表示组播地址,所以第一个字节必须是偶数
|
||||
mac[0] = 'N'; mac[1] = 'X';
|
||||
for(int i=0; i< 4; i++)
|
||||
mac[2 + i] = Sys.ID[3 - i];
|
||||
|
||||
Mode = NetworkType::Wire;
|
||||
|
||||
if(SSID) SSID->Clear();
|
||||
if(Pass) Pass->Clear();
|
||||
}
|
||||
|
||||
bool NetworkInterface::LoadConfig()
|
||||
{
|
||||
if(!Config::Current) return false;
|
||||
|
||||
NetConfig nc;
|
||||
Buffer bs(&nc, sizeof(nc));
|
||||
if(!Config::Current->Get("NET", bs)) return false;
|
||||
|
||||
IP = nc.IP;
|
||||
Mask = nc.Mask;
|
||||
Mac = nc.Mac;
|
||||
Mode = (NetworkType)nc.Mode;
|
||||
|
||||
DHCPServer = nc.DHCPServer;
|
||||
DNSServer = nc.DNSServer;
|
||||
DNSServer2 = nc.DNSServer2;
|
||||
Gateway = nc.Gateway;
|
||||
|
||||
if(SSID) *SSID = nc.SSID;
|
||||
if(Pass) *Pass = nc.Pass;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NetworkInterface::SaveConfig()
|
||||
{
|
||||
if(!Config::Current) return false;
|
||||
|
||||
NetConfig nc;
|
||||
nc.IP = IP.Value;
|
||||
nc.Mask = Mask.Value;
|
||||
Mac.CopyTo(nc.Mac);
|
||||
nc.Mode = (byte)Mode;
|
||||
|
||||
nc.DHCPServer = DHCPServer.Value;
|
||||
nc.DNSServer = DNSServer.Value;
|
||||
nc.DNSServer2 = DNSServer2.Value;
|
||||
nc.Gateway = Gateway.Value;
|
||||
|
||||
if(SSID) SSID->CopyTo(0, nc.SSID, ArrayLength(nc.SSID) - 1);
|
||||
if (Pass)
|
||||
{
|
||||
Pass->CopyTo(0, nc.Pass, ArrayLength(nc.Pass) - 1);
|
||||
if (Pass->Length() == 0)nc.Pass[0] = 0x00; // 如果密码为空 写一个字节 弥补String Copy的问题
|
||||
}
|
||||
|
||||
Buffer bs(&nc, sizeof(nc));
|
||||
return Config::Current->Set("NET", bs);
|
||||
}
|
||||
|
||||
void NetworkInterface::ShowConfig()
|
||||
{
|
||||
#if NET_DEBUG
|
||||
net_printf(" MAC:\t");
|
||||
Mac.Show();
|
||||
net_printf("\r\n IP:\t");
|
||||
IP.Show();
|
||||
net_printf("\r\n Mask:\t");
|
||||
Mask.Show();
|
||||
net_printf("\r\n Gate:\t");
|
||||
Gateway.Show();
|
||||
net_printf("\r\n DHCP:\t");
|
||||
DHCPServer.Show();
|
||||
net_printf("\r\n DNS:\t");
|
||||
DNSServer.Show();
|
||||
if(!DNSServer2.IsAny())
|
||||
{
|
||||
net_printf("\r\n DNS2:\t");
|
||||
DNSServer2.Show();
|
||||
}
|
||||
net_printf("\r\n Mode:\t");
|
||||
switch(Mode)
|
||||
{
|
||||
case NetworkType::Wire:
|
||||
net_printf("有线");
|
||||
break;
|
||||
case NetworkType::Station:
|
||||
net_printf("无线Station");
|
||||
break;
|
||||
case NetworkType::AP:
|
||||
net_printf("无线AP热点");
|
||||
break;
|
||||
case NetworkType::STA_AP:
|
||||
net_printf("无线Station+AP热点");
|
||||
break;
|
||||
}
|
||||
//net_printf("\r\n");
|
||||
|
||||
if(SSID) { net_printf("\r\n SSID:\t"); SSID->Show(false); }
|
||||
if(Pass) { net_printf("\r\n Pass:\t"); Pass->Show(false); }
|
||||
|
||||
net_printf("\r\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
Socket* NetworkInterface::CreateClient(const NetUri& uri)
|
||||
{
|
||||
auto socket = CreateSocket(uri.Type);
|
||||
socket->Local.Address = uri.Address;
|
||||
socket->Local.Port = uri.Port;
|
||||
|
||||
return socket;
|
||||
}
|
||||
|
||||
Socket* NetworkInterface::CreateRemote(const NetUri& uri)
|
||||
{
|
||||
auto socket = CreateSocket(uri.Type);
|
||||
socket->Remote.Address = uri.Address;
|
||||
socket->Remote.Port = uri.Port;
|
||||
socket->Server = uri.Host;
|
||||
|
||||
return socket;
|
||||
}
|
||||
|
||||
// DNS解析。默认仅支持字符串IP地址解析
|
||||
IPAddress NetworkInterface::QueryDNS(const String& domain)
|
||||
{
|
||||
return IPAddress::Parse(domain);
|
||||
}
|
||||
|
||||
bool NetworkInterface::IsStation() const
|
||||
{
|
||||
return Mode == NetworkType::Station || Mode == NetworkType::STA_AP;
|
||||
}
|
||||
|
||||
bool NetworkInterface::IsAP() const
|
||||
{
|
||||
return Mode == NetworkType::AP || Mode == NetworkType::STA_AP;
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
#ifndef _NetworkInterface_H_
|
||||
#define _NetworkInterface_H_
|
||||
|
||||
#include "IPAddress.h"
|
||||
#include "IPEndPoint.h"
|
||||
#include "MacAddress.h"
|
||||
#include "NetUri.h"
|
||||
#include "Socket.h"
|
||||
|
||||
#include "Core\Delegate.h"
|
||||
|
||||
class Socket;
|
||||
|
||||
// 网络类型
|
||||
enum class NetworkType
|
||||
{
|
||||
Wire = 0,
|
||||
Station = 1,
|
||||
AP = 2,
|
||||
STA_AP = 3,
|
||||
};
|
||||
|
||||
// 网络接口
|
||||
class NetworkInterface
|
||||
{
|
||||
public:
|
||||
IPAddress IP; // 本地IP地址
|
||||
IPAddress Mask; // 子网掩码
|
||||
MacAddress Mac; // 本地Mac地址
|
||||
NetworkType Mode; // 无线模式。0不是无线,1是STA,2是AP,3是混合
|
||||
|
||||
IPAddress DHCPServer;
|
||||
IPAddress DNSServer;
|
||||
IPAddress DNSServer2;
|
||||
IPAddress Gateway;
|
||||
|
||||
String* SSID; // 无线SSID
|
||||
String* Pass; // 无线密码
|
||||
|
||||
Delegate<NetworkInterface&> NetReady; // 网络准备就绪。带this参数
|
||||
|
||||
NetworkInterface();
|
||||
// 加上虚析构函数,因为应用层可能要释放该接口
|
||||
virtual ~NetworkInterface() { }
|
||||
|
||||
// 应用配置
|
||||
virtual void Config() = 0;
|
||||
|
||||
// 保存和加载动态获取的网络配置到存储设备
|
||||
void InitConfig();
|
||||
bool LoadConfig();
|
||||
bool SaveConfig();
|
||||
void ShowConfig();
|
||||
|
||||
virtual Socket* CreateSocket(NetType type) = 0;
|
||||
virtual Socket* CreateClient(const NetUri& uri);
|
||||
virtual Socket* CreateRemote(const NetUri& uri);
|
||||
|
||||
// DNS解析。默认仅支持字符串IP地址解析
|
||||
virtual IPAddress QueryDNS(const String& domain);
|
||||
// 启用DNS
|
||||
virtual bool EnableDNS() { return false; }
|
||||
// 启用DHCP
|
||||
virtual bool EnableDHCP() { return false; }
|
||||
|
||||
bool IsStation() const;
|
||||
bool IsAP() const;
|
||||
};
|
||||
|
||||
#endif
|
190
Net/Socket.cpp
190
Net/Socket.cpp
|
@ -8,193 +8,3 @@
|
|||
#else
|
||||
#define net_printf(format, ...)
|
||||
#endif
|
||||
|
||||
/******************************** ISocketHost ********************************/
|
||||
|
||||
struct NetConfig
|
||||
{
|
||||
uint IP; // 本地IP地址
|
||||
uint Mask; // 子网掩码
|
||||
byte Mac[6]; // 本地Mac地址
|
||||
byte Mode; // 无线模式。0不是无线,1是STA,2是AP,3是混合
|
||||
byte Reserved;
|
||||
|
||||
uint DHCPServer;
|
||||
uint DNSServer;
|
||||
uint DNSServer2;
|
||||
uint Gateway;
|
||||
|
||||
char SSID[32];
|
||||
char Pass[32];
|
||||
};
|
||||
|
||||
ISocketHost::ISocketHost()
|
||||
{
|
||||
Mode = SocketMode::Wire;
|
||||
|
||||
SSID = nullptr;
|
||||
Pass = nullptr;
|
||||
|
||||
//NetReady = nullptr;
|
||||
}
|
||||
|
||||
void ISocketHost::InitConfig()
|
||||
{
|
||||
IPAddress defip(192, 168, 1, 1);
|
||||
|
||||
// 随机IP,取ID最后一个字节
|
||||
IP = defip;
|
||||
byte first = Sys.ID[0];
|
||||
if(first <= 1 || first >= 254) first = 2;
|
||||
IP[3] = first;
|
||||
|
||||
Mask = IPAddress(255, 255, 255, 0);
|
||||
DHCPServer = Gateway = defip;
|
||||
|
||||
// 修改为双DNS方案,避免单点故障。默认使用阿里和百度公共DNS。
|
||||
DNSServer = IPAddress(223, 5, 5, 5);
|
||||
DNSServer2 = IPAddress(180, 76, 76, 76);
|
||||
|
||||
auto& mac = Mac;
|
||||
// 随机Mac,前2个字节取自ASCII,最后4个字节取自后三个ID
|
||||
//mac[0] = 'W'; mac[1] = 'S';
|
||||
// 第一个字节最低位为1表示组播地址,所以第一个字节必须是偶数
|
||||
mac[0] = 'N'; mac[1] = 'X';
|
||||
for(int i=0; i< 4; i++)
|
||||
mac[2 + i] = Sys.ID[3 - i];
|
||||
|
||||
Mode = SocketMode::Wire;
|
||||
|
||||
if(SSID) SSID->Clear();
|
||||
if(Pass) Pass->Clear();
|
||||
}
|
||||
|
||||
bool ISocketHost::LoadConfig()
|
||||
{
|
||||
if(!Config::Current) return false;
|
||||
|
||||
NetConfig nc;
|
||||
Buffer bs(&nc, sizeof(nc));
|
||||
if(!Config::Current->Get("NET", bs)) return false;
|
||||
|
||||
IP = nc.IP;
|
||||
Mask = nc.Mask;
|
||||
Mac = nc.Mac;
|
||||
Mode = (SocketMode)nc.Mode;
|
||||
|
||||
DHCPServer = nc.DHCPServer;
|
||||
DNSServer = nc.DNSServer;
|
||||
DNSServer2 = nc.DNSServer2;
|
||||
Gateway = nc.Gateway;
|
||||
|
||||
if(SSID) *SSID = nc.SSID;
|
||||
if(Pass) *Pass = nc.Pass;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ISocketHost::SaveConfig()
|
||||
{
|
||||
if(!Config::Current) return false;
|
||||
|
||||
NetConfig nc;
|
||||
nc.IP = IP.Value;
|
||||
nc.Mask = Mask.Value;
|
||||
Mac.CopyTo(nc.Mac);
|
||||
nc.Mode = (byte)Mode;
|
||||
|
||||
nc.DHCPServer = DHCPServer.Value;
|
||||
nc.DNSServer = DNSServer.Value;
|
||||
nc.DNSServer2 = DNSServer2.Value;
|
||||
nc.Gateway = Gateway.Value;
|
||||
|
||||
if(SSID) SSID->CopyTo(0, nc.SSID, ArrayLength(nc.SSID) - 1);
|
||||
if (Pass)
|
||||
{
|
||||
Pass->CopyTo(0, nc.Pass, ArrayLength(nc.Pass) - 1);
|
||||
if (Pass->Length() == 0)nc.Pass[0] = 0x00; // 如果密码为空 写一个字节 弥补String Copy的问题
|
||||
}
|
||||
|
||||
Buffer bs(&nc, sizeof(nc));
|
||||
return Config::Current->Set("NET", bs);
|
||||
}
|
||||
|
||||
void ISocketHost::ShowConfig()
|
||||
{
|
||||
#if NET_DEBUG
|
||||
net_printf(" MAC:\t");
|
||||
Mac.Show();
|
||||
net_printf("\r\n IP:\t");
|
||||
IP.Show();
|
||||
net_printf("\r\n Mask:\t");
|
||||
Mask.Show();
|
||||
net_printf("\r\n Gate:\t");
|
||||
Gateway.Show();
|
||||
net_printf("\r\n DHCP:\t");
|
||||
DHCPServer.Show();
|
||||
net_printf("\r\n DNS:\t");
|
||||
DNSServer.Show();
|
||||
if(!DNSServer2.IsAny())
|
||||
{
|
||||
net_printf("\r\n DNS2:\t");
|
||||
DNSServer2.Show();
|
||||
}
|
||||
net_printf("\r\n Mode:\t");
|
||||
switch(Mode)
|
||||
{
|
||||
case SocketMode::Wire:
|
||||
net_printf("有线");
|
||||
break;
|
||||
case SocketMode::Station:
|
||||
net_printf("无线Station");
|
||||
break;
|
||||
case SocketMode::AP:
|
||||
net_printf("无线AP热点");
|
||||
break;
|
||||
case SocketMode::STA_AP:
|
||||
net_printf("无线Station+AP热点");
|
||||
break;
|
||||
}
|
||||
//net_printf("\r\n");
|
||||
|
||||
if(SSID) { net_printf("\r\n SSID:\t"); SSID->Show(false); }
|
||||
if(Pass) { net_printf("\r\n Pass:\t"); Pass->Show(false); }
|
||||
|
||||
net_printf("\r\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
ISocket* ISocketHost::CreateClient(const NetUri& uri)
|
||||
{
|
||||
auto socket = CreateSocket(uri.Type);
|
||||
socket->Local.Address = uri.Address;
|
||||
socket->Local.Port = uri.Port;
|
||||
|
||||
return socket;
|
||||
}
|
||||
|
||||
ISocket* ISocketHost::CreateRemote(const NetUri& uri)
|
||||
{
|
||||
auto socket = CreateSocket(uri.Type);
|
||||
socket->Remote.Address = uri.Address;
|
||||
socket->Remote.Port = uri.Port;
|
||||
socket->Server = uri.Host;
|
||||
|
||||
return socket;
|
||||
}
|
||||
|
||||
// DNS解析。默认仅支持字符串IP地址解析
|
||||
IPAddress ISocketHost::QueryDNS(const String& domain)
|
||||
{
|
||||
return IPAddress::Parse(domain);
|
||||
}
|
||||
|
||||
bool ISocketHost::IsStation() const
|
||||
{
|
||||
return Mode == SocketMode::Station || Mode == SocketMode::STA_AP;
|
||||
}
|
||||
|
||||
bool ISocketHost::IsAP() const
|
||||
{
|
||||
return Mode == SocketMode::AP || Mode == SocketMode::STA_AP;
|
||||
}
|
||||
|
|
64
Net/Socket.h
64
Net/Socket.h
|
@ -5,71 +5,17 @@
|
|||
#include "IPEndPoint.h"
|
||||
#include "MacAddress.h"
|
||||
#include "NetUri.h"
|
||||
#include "NetworkInterface.h"
|
||||
|
||||
#include "Core\Delegate.h"
|
||||
|
||||
class ISocket;
|
||||
|
||||
enum class SocketMode
|
||||
{
|
||||
Wire = 0,
|
||||
Station = 1,
|
||||
AP = 2,
|
||||
STA_AP = 3,
|
||||
};
|
||||
|
||||
// Socket主机
|
||||
class ISocketHost
|
||||
{
|
||||
public:
|
||||
IPAddress IP; // 本地IP地址
|
||||
IPAddress Mask; // 子网掩码
|
||||
MacAddress Mac; // 本地Mac地址
|
||||
SocketMode Mode; // 无线模式。0不是无线,1是STA,2是AP,3是混合
|
||||
|
||||
IPAddress DHCPServer;
|
||||
IPAddress DNSServer;
|
||||
IPAddress DNSServer2;
|
||||
IPAddress Gateway;
|
||||
|
||||
String* SSID; // 无线SSID
|
||||
String* Pass; // 无线密码
|
||||
|
||||
Delegate<ISocketHost&> NetReady; // 网络准备就绪。带this参数
|
||||
|
||||
ISocketHost();
|
||||
// 加上虚析构函数,因为应用层可能要释放该接口
|
||||
virtual ~ISocketHost() { }
|
||||
|
||||
// 应用配置
|
||||
virtual void Config() = 0;
|
||||
|
||||
// 保存和加载动态获取的网络配置到存储设备
|
||||
void InitConfig();
|
||||
bool LoadConfig();
|
||||
bool SaveConfig();
|
||||
void ShowConfig();
|
||||
|
||||
virtual ISocket* CreateSocket(NetType type) = 0;
|
||||
virtual ISocket* CreateClient(const NetUri& uri);
|
||||
virtual ISocket* CreateRemote(const NetUri& uri);
|
||||
|
||||
// DNS解析。默认仅支持字符串IP地址解析
|
||||
virtual IPAddress QueryDNS(const String& domain);
|
||||
// 启用DNS
|
||||
virtual bool EnableDNS() { return false; }
|
||||
// 启用DHCP
|
||||
virtual bool EnableDHCP() { return false; }
|
||||
|
||||
bool IsStation() const;
|
||||
bool IsAP() const;
|
||||
};
|
||||
class NetworkInterface;
|
||||
|
||||
// Socket接口
|
||||
class ISocket
|
||||
class Socket
|
||||
{
|
||||
public:
|
||||
ISocketHost* Host; // 主机
|
||||
NetworkInterface* Host; // 主机
|
||||
NetType Protocol; // 协议类型
|
||||
|
||||
IPEndPoint Local; // 本地地址。包含本地局域网IP地址,实际监听的端口,从1024开始累加
|
||||
|
@ -77,7 +23,7 @@ public:
|
|||
String Server; // 远程地址,字符串格式,可能是IP字符串
|
||||
|
||||
// 加上虚析构函数,因为应用层可能要释放该接口
|
||||
virtual ~ISocket() { }
|
||||
virtual ~Socket() { }
|
||||
|
||||
//// 应用配置,修改远程地址和端口
|
||||
//virtual bool Change(const String& remote, ushort port) { return false; };
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "TinyIP.h"
|
||||
|
||||
// Tcp会话
|
||||
class TcpSocket : public TinySocket, public ITransport, public ISocket
|
||||
class TcpSocket : public TinySocket, public ITransport, public Socket
|
||||
{
|
||||
private:
|
||||
uint Seq; // 序列号,本地发出数据包
|
||||
|
|
|
@ -317,7 +317,7 @@ bool TinyIP::SendIP(IP_TYPE type, const IPAddress& remote, const byte* buf, uint
|
|||
return SendEthernet(ETH_IP, mac, (byte*)ip, sizeof(IP_HEADER) + len);
|
||||
}
|
||||
|
||||
ISocket* TinyIP::CreateSocket(NetType type)
|
||||
Socket* TinyIP::CreateSocket(NetType type)
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
|
|
|
@ -26,7 +26,7 @@ public:
|
|||
};
|
||||
|
||||
// 精简以太网协议。封装以太网帧以及IP协议,不包含其它协议实现,仅提供底层支持。
|
||||
class TinyIP : public Object, public ISocketHost
|
||||
class TinyIP : public Object, public NetworkInterface
|
||||
{
|
||||
private:
|
||||
ITransport* _port;
|
||||
|
@ -66,7 +66,7 @@ public:
|
|||
bool SendIP(IP_TYPE type, const IPAddress& remote, const byte* buf, uint len);
|
||||
bool IsBroadcast(const IPAddress& ip); // 是否广播地址
|
||||
|
||||
virtual ISocket* CreateSocket(NetType type);
|
||||
virtual Socket* CreateSocket(NetType type);
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "TinyIP.h"
|
||||
|
||||
// Udp会话
|
||||
class UdpSocket : public TinySocket, public ITransport, public ISocket
|
||||
class UdpSocket : public TinySocket, public ITransport, public Socket
|
||||
{
|
||||
private:
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ static void OnDhcpStop(Dhcp& dhcp)
|
|||
}
|
||||
}
|
||||
|
||||
ISocketHost* Token::CreateW5500(SPI spi_, Pin irq, Pin rst, Pin power, IDataPort* led)
|
||||
NetworkInterface* Token::CreateW5500(SPI spi_, Pin irq, Pin rst, Pin power, IDataPort* led)
|
||||
{
|
||||
debug_printf("\r\nW5500::Create \r\n");
|
||||
|
||||
|
@ -60,7 +60,7 @@ ISocketHost* Token::CreateW5500(SPI spi_, Pin irq, Pin rst, Pin power, IDataPort
|
|||
return net;
|
||||
}
|
||||
|
||||
ISocketHost* Token::Create2860(SPI spi_, Pin irq, Pin rst)
|
||||
NetworkInterface* Token::Create2860(SPI spi_, Pin irq, Pin rst)
|
||||
{
|
||||
debug_printf("\r\nENC2860::Create \r\n");
|
||||
|
||||
|
@ -83,7 +83,7 @@ ISocketHost* Token::Create2860(SPI spi_, Pin irq, Pin rst)
|
|||
return _tip;
|
||||
}
|
||||
|
||||
TokenClient* Token::CreateClient(ISocketHost* host)
|
||||
TokenClient* Token::CreateClient(NetworkInterface* host)
|
||||
{
|
||||
debug_printf("\r\nCreateClient \r\n");
|
||||
|
||||
|
@ -308,16 +308,16 @@ ITransport* Token::CreateShunCom(COM index, int baudRate, Pin rst, Pin power, Pi
|
|||
|
||||
void StartGateway(void* param)
|
||||
{
|
||||
//ISocket* socket = nullptr;
|
||||
//Socket* socket = nullptr;
|
||||
auto gw = Gateway::Current;
|
||||
//if(gw) socket = dynamic_cast<ISocket*>(gw->Client->Control->Port);
|
||||
//if(gw) socket = dynamic_cast<Socket*>(gw->Client->Control->Port);
|
||||
|
||||
/*auto tk = TokenConfig::Current;
|
||||
|
||||
if(tk && tk->Server.Length() > 0)
|
||||
{
|
||||
// 根据DNS获取云端IP地址
|
||||
auto ip = DNS::Query(*(ISocketHost*)param, tk->Server);
|
||||
auto ip = DNS::Query(*(NetworkInterface*)param, tk->Server);
|
||||
if(ip == IPAddress::Any())
|
||||
{
|
||||
debug_printf("DNS::Query %s 失败!\r\n", tk->Server.GetBuffer());
|
||||
|
|
|
@ -19,14 +19,14 @@ class Token
|
|||
public:
|
||||
static void Setup(ushort code, cstring name, COM message = COM1, int baudRate = 0);
|
||||
|
||||
static ISocketHost* CreateW5500(SPI spi, Pin irq, Pin rst = P0, Pin power = P0, IDataPort* led = nullptr);
|
||||
static ISocketHost* Create2860(SPI spi, Pin irq, Pin rst);
|
||||
static NetworkInterface* CreateW5500(SPI spi, Pin irq, Pin rst = P0, Pin power = P0, IDataPort* led = nullptr);
|
||||
static NetworkInterface* Create2860(SPI spi, Pin irq, Pin rst);
|
||||
|
||||
static ITransport* Create2401(SPI spi, Pin ce, Pin irq, Pin power = P0, bool powerInvert = false, IDataPort* led = nullptr);
|
||||
static ITransport* CreateShunCom(COM index, int baudRate, Pin rst, Pin power, Pin slp, Pin cfg, IDataPort* led = nullptr);
|
||||
|
||||
static TokenClient* CreateClient(ISocketHost* host);
|
||||
static TokenClient* CreateClient2860(ISocketHost* host);
|
||||
static TokenClient* CreateClient(NetworkInterface* host);
|
||||
static TokenClient* CreateClient2860(NetworkInterface* host);
|
||||
static TinyServer* CreateServer(ITransport* port);
|
||||
|
||||
void SetPower(ITransport* port);
|
||||
|
|
|
@ -349,7 +349,7 @@ void TokenClient::LoopTask()
|
|||
if (MaxNotActive != 0 && LastActive + MaxNotActive < Sys.Ms())
|
||||
{
|
||||
Master->Close();
|
||||
//if (Master->Socket->Host->Mode != SocketMode::Wire)Sys.Reboot();
|
||||
//if (Master->Socket->Host->Mode != NetworkType::Wire)Sys.Reboot();
|
||||
Sys.Reboot();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -614,7 +614,7 @@ void StatTask(void* param)
|
|||
st->Clear();
|
||||
|
||||
// 向以太网广播
|
||||
/*auto sock = dynamic_cast<ISocket*>(Port);
|
||||
/*auto sock = dynamic_cast<Socket*>(Port);
|
||||
if(sock)
|
||||
{
|
||||
IPEndPoint ep(IPAddress::Broadcast(), 514);
|
||||
|
|
|
@ -24,7 +24,7 @@ protected:
|
|||
//virtual bool SendInternal(const Buffer& bs, const void* state);
|
||||
|
||||
public:
|
||||
ISocket* Socket;
|
||||
Socket* Socket;
|
||||
|
||||
uint Token; // 令牌
|
||||
ByteArray Key; // 通信密码
|
||||
|
|
Loading…
Reference in New Issue