修正vc++编译时的各种警告,主要是有符号数和无符号数比较

This commit is contained in:
大石头X2 2017-02-27 17:23:57 +08:00
parent 835bcc3f15
commit 3f2747222c
32 changed files with 1261 additions and 766 deletions

View File

@ -5,9 +5,9 @@ int Button::ACZeroAdjTime = 2300;
Button::Button()
{
Name = nullptr;
Index = 0;
_Value = false;
Name = nullptr;
Index = 0;
_Value = false;
//_Handler = nullptr;
//_Param = nullptr;
@ -32,12 +32,12 @@ void Button::Set(Pin key, Pin led, bool ledInvert, Pin relay, bool relayInvert)
//Key.Register(Delegate2<InputPort&, bool>(&Button::OnPress, this))
Key.Open();
if(led != P0)
if (led != P0)
{
Led.Invert = ledInvert;
Led.Set(led).Open();
}
if(relay != P0)
if (relay != P0)
{
Relay.Invert = relayInvert;
Relay.Set(relay).Open();
@ -53,7 +53,7 @@ void Button::Set(Pin key, Pin led, bool ledInvert, Pin relay, bool relayInvert)
void Button::OnPress(InputPort& port, bool down)
{
// 每次按下弹起,都取反状态
if(!down)
if (!down)
{
SetValue(!_Value);
@ -80,7 +80,7 @@ bool Button::GetValue() { return _Value; }
int Button::OnWrite(byte data)
{
SetValue(data);
SetValue(data > 0);
return OnRead();
}
@ -93,7 +93,7 @@ byte Button::OnRead()
String Button::ToString() const
{
String str;
if(Name) str += Name;
if (Name) str += Name;
return str;
}
@ -101,31 +101,31 @@ String Button::ToString() const
bool CheckZero(const InputPort& port)
{
int retry = 200;
while(!port.Read() && retry-- > 0) Sys.Delay(100); // 检测下降沿 先去掉低电平 whileio==false
if(retry <= 0) return false;
while (!port.Read() && retry-- > 0) Sys.Delay(100); // 检测下降沿 先去掉低电平 whileio==false
if (retry <= 0) return false;
retry = 200;
while(port.Read() && retry-- > 0) Sys.Delay(100); // 当检测到 高电平结束 就是下降沿的到来
if(retry <= 0) return false;
while (port.Read() && retry-- > 0) Sys.Delay(100); // 当检测到 高电平结束 就是下降沿的到来
if (retry <= 0) return false;
return true;
}
void Button::SetValue(bool value)
{
if(!ACZero.Empty())
if (!ACZero.Empty())
{
if(CheckZero(ACZero)) Sys.Delay(ACZeroAdjTime);
if (CheckZero(ACZero)) Sys.Delay(ACZeroAdjTime);
// 经检测 过零检测电路的信号是 高电平12ms 低电平7ms 即下降沿后8.5ms 是下一个过零点
// 从给出信号到继电器吸合 测量得到的时间是 6.4ms 继电器抖动 1ms左右 即 平均在7ms上下
// 故这里添加1ms延时
// 这里有个不是问题的问题 一旦过零检测电路烧了 开关将不能正常工作
}
Led = value;
Relay = value;
Led = value;
Relay = value;
_Value = value;
_Value = value;
}
bool Button::SetACZeroPin(Pin aczero)
@ -133,12 +133,12 @@ bool Button::SetACZeroPin(Pin aczero)
auto& port = ACZero;
// 该方法可能被初级工程师多次调用,需要检查并释放旧的,避免内存泄漏
if(!port.Empty()) port.Close();
if (!port.Empty()) port.Close();
port.Set(aczero).Open();
// 需要检测是否有交流电,否则关闭
if(CheckZero(port)) return true;
if (CheckZero(port)) return true;
port.Close();
port.Clear();

View File

@ -21,9 +21,9 @@ static Button_GrayLevelConfig* ButtonConfig = nullptr;
/******************************** 调光配置 ********************************/
Button_GrayLevelConfig::Button_GrayLevelConfig()
{
_Name = "Gray";
_Start = &OnGrayLevel;
_End = &TagEnd;
_Name = "Gray";
_Start = &OnGrayLevel;
_End = &TagEnd;
Init();
OnGrayLevel = 0xff;
@ -209,7 +209,7 @@ void Button_GrayLevel::DelayClose2(int ms)
int Button_GrayLevel::OnWrite(byte data)
{
SetValue(data);
SetValue(data > 0);
return OnRead();
}

View File

@ -238,11 +238,11 @@ void Dimmer::Set(byte vs[4])
void Dimmer::SetPulse(byte vs[4])
{
auto& pwm = *_Pwm;
auto& cfg = *Config;
debug_printf("开始调节……\r\n");
if (cfg.Speed > 0&& !_Closing)
if (cfg.Speed > 0 && !_Closing)
{
// 等分计算步长
for (int i = 0; i < 4; i++)
@ -345,7 +345,7 @@ void Dimmer::AnimateTask()
auto& cfg = *Config;
if (cfg.Speed <= 0) return;
bool on = _AnimateData[1];
bool on = _AnimateData[1] > 0;
byte vs1[4];
byte vs2[4];
Buffer bs1(vs1, 4);

View File

@ -12,11 +12,11 @@ static PulsePort* Create(Pin pin)
{
auto pp = new PulsePort();
pp->Port = new InputPort();
pp->Port->Set(pin);
pp->Port->Set(pin);
pp->Port->Floating = false;
pp->Port->Pull = InputPort::DOWN;
pp->Port->HardEvent = true;
pp->Port->HardEvent = true;
return pp;
}
@ -195,7 +195,7 @@ void Raster::LineReport()
Buffer bs(&data, size);
// 如果满了,马上发送
if (bs.Length() > 256 - _Cache->Position())
if (bs.Length() > 256 - (int)_Cache->Position())
Report();
_Cache->Write(bs);

View File

@ -1,4 +1,4 @@
#include "AP0104.h"
#include "AP0104.h"
#include "Kernel\Task.h"

View File

@ -201,7 +201,7 @@ static void UnionPress(InputPort& port, bool down)
void IOK026X::Union(Pin pin1, Pin pin2)
{
Pin p[] = { pin1,pin2 };
for (size_t i = 0; i < 2; i++)
for (int i = 0; i < 2; i++)
{
auto port = new InputPort(p[i]);
port->Invert = true;

View File

@ -108,7 +108,7 @@ NetworkInterface* IOK027X::Create8266(Pin power)
esp->Mode = NetworkType::STA_AP;
}
if(!esp->Open())
if (!esp->Open())
{
delete esp;
return nullptr;
@ -201,7 +201,7 @@ static void UnionPress(InputPort& port, bool down)
void IOK027X::Union(Pin pin1, Pin pin2)
{
Pin p[] = { pin1,pin2 };
for (size_t i = 0; i < 2; i++)
for (int i = 0; i < 2; i++)
{
if (p[i] == P0) continue;

View File

@ -4,14 +4,14 @@
I2C::I2C()
{
Speed = 10000;
Retry = 200;
Error = 0;
Speed = 10000;
Retry = 200;
Error = 0;
Address = 0x00;
SubWidth= 0;
Address = 0x00;
SubWidth = 0;
Opened = false;
Opened = false;
}
I2C::~I2C()
@ -21,7 +21,7 @@ I2C::~I2C()
void I2C::Open()
{
if(Opened) return;
if (Opened) return;
OnOpen();
@ -30,7 +30,7 @@ void I2C::Open()
void I2C::Close()
{
if(!Opened) return;
if (!Opened) return;
OnClose();
@ -57,35 +57,35 @@ bool I2C::SendAddress(int addr, bool tx)
// 发送写入地址
ushort d = (tx || SubWidth > 0) ? Address : (Address | 0x01);
//debug_printf("I2C::SendAddr %02X \r\n", d);
WriteByte(d);
if(!WaitAck())
WriteByte((byte)d);
if (!WaitAck())
{
debug_printf("I2C::SendAddr %02X 可能设备未连接,或地址不对\r\n", d);
return false;
}
if(!SubWidth) return true;
if (!SubWidth) return true;
// 发送子地址
if(!SendSubAddr(addr))
if (!SendSubAddr(addr))
{
debug_printf("I2C::SendAddr %02X 发送子地址 0x%02X 失败\r\n", d, addr);
return false;
}
if(tx) return true;
if (tx) return true;
d = Address | 0x01;
// 多次尝试启动并发送读取地址
uint retry = 10;
bool rs = false;
while(retry-- && !rs)
while (retry-- && !rs)
{
Start();
WriteByte(d);
WriteByte((byte)d);
rs = WaitAck();
}
if(!rs)
if (!rs)
{
debug_printf("I2C::SendAddr %02X 发送读取地址失败\r\n", d);
return false;
@ -97,13 +97,13 @@ bool I2C::SendAddress(int addr, bool tx)
bool I2C::SendSubAddr(int addr)
{
// 发送子地址
if(SubWidth > 0)
if (SubWidth > 0)
{
// 逐字节发送
for(int k=SubWidth-1; k>=0; k--)
for (int k = SubWidth - 1; k >= 0; k--)
{
WriteByte(addr >> (k << 3));
if(!WaitAck()) return false;
if (!WaitAck()) return false;
}
}
@ -121,14 +121,14 @@ WEAK bool I2C::Write(int addr, const Buffer& bs)
I2CScope ics(this);
// 发送设备地址
if(!SendAddress(addr, true)) return false;
if (!SendAddress(addr, true)) return false;
uint len = bs.Length();
for(int i=0; i<len; i++)
int len = bs.Length();
for (int i = 0; i < len; i++)
{
WriteByte(bs[i]);
// 最后一次不要等待Ack
if(i < len - 1 && !WaitAck()) return false;
if (i < len - 1 && !WaitAck()) return false;
}
return true;
@ -142,11 +142,11 @@ WEAK uint I2C::Read(int addr, Buffer& bs)
I2CScope ics(this);
// 发送设备地址
if(!SendAddress(addr, false)) return 0;
if (!SendAddress(addr, false)) return 0;
uint rs = 0;
uint len = bs.Length();
for(int i=0; i<len; i++)
int len = bs.Length();
for (int i = 0; i < len; i++)
{
bs[i] = ReadByte();
rs++;
@ -159,21 +159,21 @@ bool I2C::Write(int addr, byte data) { return Write(addr, Buffer(&data, 1)); }
byte I2C::Read(int addr)
{
ByteArray bs(1);
if(!Read(addr, bs)) return 0;
if (!Read(addr, bs)) return 0;
return bs[0];
}
ushort I2C::Read2(int addr)
{
ByteArray bs(2);
if(!Read(addr, bs)) return 0;
if (!Read(addr, bs)) return 0;
return (bs[0] << 8) | bs[1];
}
uint I2C::Read4(int addr)
{
ByteArray bs(4);
if(!Read(addr, bs)) return 0;
if (!Read(addr, bs)) return 0;
return (bs[0] << 24) | (bs[1] << 16) | (bs[2] << 8) | bs[3];
}
@ -203,12 +203,12 @@ HardI2C::HardI2C(byte index, uint speedHz) : I2C()
void HardI2C::Init(byte index, uint speedHz)
{
_index = index;
Speed = speedHz;
_index = index;
Speed = speedHz;
OnInit();
debug_printf("HardI2C_%d::Init %dHz \r\n", _index + 1, speedHz);
debug_printf("HardI2C_%d::Init %dHz \r\n", _index + 1, speedHz);
}
HardI2C::~HardI2C()
@ -216,25 +216,25 @@ HardI2C::~HardI2C()
Close();
}
void HardI2C::SetPin(Pin scl , Pin sda )
void HardI2C::SetPin(Pin scl, Pin sda)
{
SCL.Set(scl);
SDA.Set(sda);
}
void HardI2C::GetPin(Pin* scl , Pin* sda )
void HardI2C::GetPin(Pin* scl, Pin* sda)
{
if(scl) *scl = SCL._Pin;
if(sda) *sda = SDA._Pin;
if (scl) *scl = SCL._Pin;
if (sda) *sda = SDA._Pin;
}
SoftI2C::SoftI2C(uint speedHz) : I2C()
{
Speed = speedHz;
_delay = Sys.Clock / speedHz;
Retry = 100;
Error = 0;
Address = 0x00;
Speed = speedHz;
_delay = Sys.Clock / speedHz;
Retry = 100;
Error = 0;
Address = 0x00;
}
SoftI2C::~SoftI2C()
@ -242,7 +242,7 @@ SoftI2C::~SoftI2C()
Close();
}
void SoftI2C::SetPin(Pin scl , Pin sda )
void SoftI2C::SetPin(Pin scl, Pin sda)
{
//SCL.Set(scl);
//SDA.Set(sda);
@ -253,10 +253,10 @@ void SoftI2C::SetPin(Pin scl , Pin sda )
SDA.Init(sda, false);
}
void SoftI2C::GetPin(Pin* scl , Pin* sda )
void SoftI2C::GetPin(Pin* scl, Pin* sda)
{
if(scl) *scl = SCL._Pin;
if(sda) *sda = SDA._Pin;
if (scl) *scl = SCL._Pin;
if (sda) *sda = SDA._Pin;
}
void SoftI2C::OnOpen()
@ -329,7 +329,7 @@ void SoftI2C::Stop()
// 等待Ack
bool SoftI2C::WaitAck(int retry)
{
if(!retry) retry = Retry;
if (!retry) retry = Retry;
// SDA 线上的数据必须在时钟的高电平周期保持稳定
SDA = true;
@ -337,9 +337,9 @@ bool SoftI2C::WaitAck(int retry)
Delay(1);
// 等待SDA低电平
while(SDA.ReadInput())
while (SDA.ReadInput())
{
if(retry-- <= 0)
if (retry-- <= 0)
{
//debug_printf("SoftI2C::WaitAck Retry=%d 无法等到ACK \r\n", Retry);
return false;
@ -382,9 +382,9 @@ void SoftI2C::WriteByte(byte dat)
{
// SDA 线上的数据必须在时钟的高电平周期保持稳定
SCL = false;
for(byte mask=0x80; mask>0; mask>>=1)
{
SDA = dat & mask;
for (byte mask = 0x80; mask > 0; mask >>= 1)
{
SDA = (dat & mask) > 0;
Delay(1);
// 置时钟线为高,通知被控器开始接收数据位
@ -392,7 +392,7 @@ void SoftI2C::WriteByte(byte dat)
Delay(1);
SCL = false;
Delay(1);
}
}
}
byte SoftI2C::ReadByte()
@ -400,19 +400,19 @@ byte SoftI2C::ReadByte()
// SDA 线上的数据必须在时钟的高电平周期保持稳定
SDA = true;
byte rs = 0;
for(byte mask=0x80; mask>0; mask>>=1)
for (byte mask = 0x80; mask > 0; mask >>= 1)
{
SCL = true; // 置时钟线为高使数据线上数据有效
//Delay(2);
// 等SCL变高
uint retry = 50;
while(!SCL.ReadInput())
while (!SCL.ReadInput())
{
if(retry-- <= 0) break;
if (retry-- <= 0) break;
Delay(1);
}
if(SDA.ReadInput()) rs |= mask; //读数据位
if (SDA.ReadInput()) rs |= mask; //读数据位
SCL = false; // 置时钟线为低,准备接收数据位
Delay(1);
}

View File

@ -1,4 +1,4 @@
#ifndef _Port_H_
#ifndef _Port_H_
#define _Port_H_
#include "Kernel\Sys.h"

View File

@ -1,8 +1,8 @@
#include "74HC165.h"
IC74HC165::IC74HC165(Pin pl, Pin sck, Pin in, Pin ce)
: _PL(pl),_SCK(sck),_In(in),_CE(ce)
IC74HC165::IC74HC165(Pin pl, Pin sck, Pin in, Pin ce)
: _PL(pl), _SCK(sck), _In(in), _CE(ce)
{
_PL.Invert = true;
_CE.Invert = true;
@ -23,40 +23,40 @@ bool IC74HC165::Close()
_PL.Close();
_SCK.Close();
_In.Close();
_CE.Close();
_CE.Close();
Opened = false;
return true;
}
bool IC74HC165::Read(byte *buf, byte count)
{
if(!buf) return false;
if(!Opened) Open();
if (!buf) return false;
if (!Opened) Open();
_PL = false; // 不采集
_CE = true; // 使能芯片
_CE = true; // 使能芯片
_PL = true; // 采集
_PL = false; // 采集
_SCK = false;
for(int i = 0; i < count; i++)
for (int i = 0; i < count; i++)
{
byte temp;
for(int j = 0; j < 8; j++)
byte temp = 0;
for (int j = 0; j < 8; j++)
{
temp <<= 1;
_SCK = true;
if(_In) temp |= 0x01;
if (_In) temp |= 0x01;
else temp &= 0xfe;
_SCK = false;
}
*buf = temp;
buf++;
}
_CE = false;
return true;
}

View File

@ -1,4 +1,4 @@
#ifndef _SHT30_H_
#ifndef _SHT30_H_
#define _SHT30_H_
#include "Device\Power.h"

View File

@ -677,7 +677,7 @@ bool W5500::WriteByte2(ushort addr, ushort dat, byte socket, byte block)
SpiScope sc(_spi);
SetAddress(addr, 1, socket, block);
_spi->Write(dat);
_spi->Write((byte)dat);
_spi->Write(dat >> 8);
return true;

View File

@ -49,7 +49,7 @@ extern const TTime Time;
class TimeWheel
{
public:
uint Expire; // 到期时间,毫秒
UInt64 Expire; // 到期时间,毫秒
ushort Sleep; // 睡眠时间默认0毫秒
TimeWheel(uint ms);

View File

@ -3,9 +3,9 @@
#include "Core\Environment.h"
#if defined(__CC_ARM)
#include <time.h>
#include <time.h>
#else
#include <ctime>
#include <ctime>
#endif
#define TIME_DEBUG 0
@ -21,30 +21,30 @@
TTime::TTime()
{
Seconds = 0;
Seconds = 0;
//Ticks = 0;
#if defined(STM32F0) || defined(GD32F150)
Index = 13;
Index = 13;
#else
Div = 0;
if(Sys.FlashSize > 0x80)
Index = 5;
Div = 0;
if (Sys.FlashSize > 0x80)
Index = 5;
else
Index = 1; // 错开开关的 TIM3 背光
Index = 1; // 错开开关的 TIM3 背光
#endif
BaseSeconds = 0;
OnInit = nullptr;
OnLoad = nullptr;
OnSave = nullptr;
OnSleep = nullptr;
OnInit = nullptr;
OnLoad = nullptr;
OnSave = nullptr;
OnSleep = nullptr;
}
void TTime::SetTime(UInt64 sec)
{
if(sec >= BASE_YEAR_US) sec -= BASE_YEAR_US;
if (sec >= BASE_YEAR_US) sec -= BASE_YEAR_US;
BaseSeconds = sec - Seconds;
BaseSeconds = (uint)(sec - Seconds);
#if DEBUG
/*DateTime dt(sec);
@ -53,77 +53,78 @@ void TTime::SetTime(UInt64 sec)
#endif
// 保存到RTC
if(OnSave) OnSave();
if (OnSave) OnSave();
}
// 关键性代码,放到开头
INROOT void TTime::Sleep(int ms, bool* running) const
{
// 睡眠时间太短
if(ms <= 0) return;
// 睡眠时间太短
if (ms <= 0) return;
// 结束时间
Int64 end = Current() + ms;
UInt64 end = Current() + ms;
// 较大的睡眠时间直接让CPU停下来
if(OnSleep && ms >= 10)
if (OnSleep && ms >= 10)
{
while(ms >= 10)
while (ms >= 10)
{
OnSleep(ms);
// 判断是否需要继续
if(running != nullptr && !*running) break;
if (running != nullptr && !*running) break;
// 重新计算剩下的时间
ms = (int)(end - Current());
ms = (int)(end - Current());
}
}
// 睡眠时间太短
if(!ms || (running && !*running)) return;
// 睡眠时间太短
if (!ms || (running && !*running)) return;
// 空转
while(true)
while (true)
{
if(Current() >= end) break;
if(running != nullptr && !*running) break;
if (Current() >= end) break;
if (running != nullptr && !*running) break;
}
}
INROOT void TTime::Delay(int us) const
{
// 睡眠时间太短
if(us <= 0) return;
// 睡眠时间太短
if (us <= 0) return;
// 较大的时间,按毫秒休眠
if(us >= 1000)
if (us >= 1000)
{
Sleep(us / 1000);
us %= 1000;
}
// 睡眠时间太短
if(!us) return;
// 睡眠时间太短
if (!us) return;
// 无需关闭中断,也能实现延迟
UInt64 ms = Current();
uint ticks = CurrentTicks() + UsToTicks(us);
uint max = UsToTicks(1000 - 1);
if(ticks >= max)
UInt64 ms = Current();
uint ticks = CurrentTicks() + UsToTicks(us);
uint max = UsToTicks(1000 - 1);
if (ticks >= max)
{
ms++;
ticks -= max;
}
while(true)
while (true)
{
int n = Current() - ms;
if(n > 0) break;
if(n == 0 && CurrentTicks() >= ticks) break;
int n = (int)(Current() - ms);
if (n > 0) break;
if (n == 0 && CurrentTicks() >= ticks) break;
}
}
extern "C"
{
#ifndef _MSC_VER
// 获取系统启动后经过的毫秒数
clock_t clock(void)
{
@ -133,34 +134,35 @@ extern "C"
// 实现C函数库的time函数
time_t time(time_t* sec)
{
uint s = Time.BaseSeconds + Time.Seconds;
if(sec) *sec = s;
uint s = Time.BaseSeconds + Time.Seconds;
if (sec) *sec = s;
return s;
}
#endif
}
/************************************************ TimeWheel ************************************************/
TimeWheel::TimeWheel(uint ms)
{
Sleep = 0;
Sleep = 0;
Reset(ms);
}
void TimeWheel::Reset(uint ms)
{
Expire = Time.Current() + + ms;
Expire = Time.Current() + ms;
}
// 是否已过期
bool TimeWheel::Expired()
{
UInt64 now = Time.Current();
if(now > Expire) return true;
if (now > Expire) return true;
// 睡眠释放CPU
if(Sleep) Sys.Sleep(Sleep);
if (Sleep) Sys.Sleep(Sleep);
return false;
}
@ -169,21 +171,21 @@ bool TimeWheel::Expired()
TimeCost::TimeCost()
{
Start = Time.Current();
StartTicks = Time.CurrentTicks();
Start = Time.Current();
StartTicks = Time.CurrentTicks();
}
// 逝去的时间,微秒
int TimeCost::Elapsed()
{
int ts = (int)(Time.CurrentTicks() - StartTicks);
int ms = (int)(Time.Current() - Start);
int ts = (int)(Time.CurrentTicks() - StartTicks);
int ms = (int)(Time.Current() - Start);
// 有可能滴答部分不是完整的一圈
if(ts > 0) return ms * 1000 + Time.TicksToUs(ts);
if (ts > 0) return ms * 1000 + Time.TicksToUs(ts);
// 如果毫秒部分也没有,那么可能是微小错误偏差
if(ms <= 0) return 0;
if (ms <= 0) return 0;
// 如果滴答是负数,则干脆减去
return ms * 1000 - Time.TicksToUs(-ts);
@ -191,6 +193,6 @@ int TimeCost::Elapsed()
void TimeCost::Show(cstring format)
{
if(!format) format = "执行 %dus\r\n";
if (!format) format = "执行 %dus\r\n";
debug_printf(format, Elapsed());
}

View File

@ -5,9 +5,9 @@
//#define DS_DEBUG DEBUG
#define DS_DEBUG 0
#if DS_DEBUG
#define ds_printf debug_printf
#define ds_printf debug_printf
#else
#define ds_printf(format, ...)
#define ds_printf(format, ...)
#endif
class Area
@ -32,30 +32,30 @@ public:
// 初始化
DataStore::DataStore()
{
Strict = true;
Strict = true;
}
// 写入数据
int DataStore::Write(uint offset, const Buffer& bs)
{
uint size = bs.Length();
if(size == 0) return 0;
int size = bs.Length();
if (size == 0) return 0;
uint realOffset = offset - VirAddrBase;
int realOffset = offset - VirAddrBase;
//起始位置越界
auto len = Data.Length();
if(realOffset >= len) return -1;
auto len = Data.Length();
if (realOffset >= len) return -1;
// 数据越界
if(Strict && realOffset + size >len) size = len - realOffset;
if (Strict && realOffset + size > len) size = len - realOffset;
// 从数据区读取数据
uint rs = Data.Copy(realOffset, bs, 0, size);
if(rs == 0) return rs;
if (rs == 0) return rs;
// 执行钩子函数
if(!OnHook(realOffset, rs, true)) return -1;
if (!OnHook(realOffset, rs, true)) return -1;
return rs;
}
@ -63,22 +63,22 @@ int DataStore::Write(uint offset, const Buffer& bs)
// 读取数据
int DataStore::Read(uint offset, Buffer& bs)
{
uint size = bs.Length();
if(size == 0) return 0;
int size = bs.Length();
if (size == 0) return 0;
uint realOffset = offset - VirAddrBase;
int remain = Data.Length() - realOffset;
int realOffset = offset - VirAddrBase;
int remain = Data.Length() - realOffset;
// 检查是否越界
// if(Strict && realOffset + size > Data.Length()) return -1;
// 只要起始位置在区间内都读,数据超长就返回能返回的!
if(Strict && remain <= 0) return -1; // 起始地址越界直接返回
if (Strict && remain <= 0) return -1; // 起始地址越界直接返回
// 最大只能读取这么多
if(size > remain) size = remain;
if (size > remain) size = remain;
// 执行钩子函数
if(!OnHook(realOffset, size, false)) return -1;
if (!OnHook(realOffset, size, false)) return -1;
// 从数据区读取数据
return bs.Copy(0, Data, realOffset, size);
@ -86,27 +86,27 @@ int DataStore::Read(uint offset, Buffer& bs)
bool DataStore::OnHook(uint offset, uint size, bool write)
{
for(int i=0; i<Areas.Count(); i++)
for (int i = 0; i < Areas.Count(); i++)
{
auto ar = *(Area*)Areas[i];
if(ar.Size == 0) continue;
if (ar.Size == 0) continue;
// 数据操作口只认可完整的当前区域
if(ar.Port && ar.In(offset, size))
if (ar.Port && ar.In(offset, size))
{
if(write)
if (write)
{
if(ar.Port->Write(&Data[ar.Offset]) <= 0) return false;
if (ar.Port->Write(&Data[ar.Offset]) <= 0) return false;
}
else
{
if(ar.Port->Read(&Data[ar.Offset]) <= 0) return false;
if (ar.Port->Read(&Data[ar.Offset]) <= 0) return false;
}
}
// 钩子函数不需要完整区域,只需要部分匹配即可
if(ar.Hook && ar.Any(offset, size))
if (ar.Hook && ar.Any(offset, size))
{
if(!ar.Hook(ar.Offset, ar.Size, write)) return false;
if (!ar.Hook(ar.Offset, ar.Size, write)) return false;
}
}
@ -116,29 +116,29 @@ bool DataStore::OnHook(uint offset, uint size, bool write)
// 注册某一块区域的读写钩子函数
void DataStore::Register(uint offset, uint size, Handler hook)
{
auto ar = new Area();
ar->Offset = offset;
ar->Size = size;
ar->Hook = hook;
auto ar = new Area();
ar->Offset = offset;
ar->Size = size;
ar->Hook = hook;
Areas.Add(ar);
}
void DataStore::Register(uint offset, IDataPort& port)
{
auto ar = new Area();
ar->Offset = offset;
ar->Size = port.Size();
ar->Port = &port;
auto ar = new Area();
ar->Offset = offset;
ar->Size = port.Size();
ar->Port = &port;
Areas.Add(ar);
}
Area::Area()
{
Offset = 0;
Size = 0;
Hook = nullptr;
Offset = 0;
Size = 0;
Hook = nullptr;
}
// 参数是读命令里面的偏移和大小
@ -152,14 +152,14 @@ bool Area::Any(uint start, uint len)
{
// 只要搭边就算数
//return start <= Offset + Size && start + len >= Offset;
return !(Offset > start + len -1 || Offset + Size < start);
return !(Offset > start + len - 1 || Offset + Size < start);
}
/****************************** 数据操作接口 ************************************/
ByteDataPort::ByteDataPort()
{
Busy = false;
Busy = false;
}
ByteDataPort::~ByteDataPort()
@ -169,75 +169,75 @@ ByteDataPort::~ByteDataPort()
int ByteDataPort::Write(byte* data)
{
Busy = false;
Busy = false;
byte cmd = *data;
if(cmd == 0xFF) return Read(data);
if (cmd == 0xFF) return Read(data);
ds_printf("控制0x%02X ", cmd);
switch(cmd)
switch (cmd)
{
case 1:
ds_printf("打开");
OnWrite(1);
break;
case 0:
ds_printf("关闭");
OnWrite(0);
break;
case 2:
ds_printf("反转");
OnWrite(!OnRead());
break;
default:
break;
case 1:
ds_printf("打开");
OnWrite(1);
break;
case 0:
ds_printf("关闭");
OnWrite(0);
break;
case 2:
ds_printf("反转");
OnWrite(!OnRead());
break;
default:
break;
}
int s = 0;
switch(cmd>>4)
switch (cmd >> 4)
{
// 普通指令
case 0:
// 关闭所有带有延迟效果的指令
Next = 0xFF;
break;
case 0:
// 关闭所有带有延迟效果的指令
Next = 0xFF;
break;
// 开关闪烁
case 1:
s = cmd - 0x10;
ds_printf("闪烁 %d 秒", s);
OnWrite(!OnRead());
Next = cmd;
StartAsync(s * 1000);
break;
case 1:
s = cmd - 0x10;
ds_printf("闪烁 %d 秒", s);
OnWrite(!OnRead());
Next = cmd;
StartAsync(s * 1000);
break;
// 开关闪烁(毫秒级)
case 2:
s = (cmd - 0x20) * 100;
ds_printf("闪烁 %d 毫秒", s);
OnWrite(!OnRead());
Next = cmd;
StartAsync(s);
break;
case 2:
s = (cmd - 0x20) * 100;
ds_printf("闪烁 %d 毫秒", s);
OnWrite(!OnRead());
Next = cmd;
StartAsync(s);
break;
// 打开,延迟一段时间后关闭
case 4:
case 5:
case 6:
case 7:
s = cmd - 0x40;
ds_printf("延迟 %d 秒关闭", s);
//OnWrite(1);
Next = 0;
StartAsync(s * 1000);
break;
case 4:
case 5:
case 6:
case 7:
s = cmd - 0x40;
ds_printf("延迟 %d 秒关闭", s);
//OnWrite(1);
Next = 0;
StartAsync(s * 1000);
break;
// 关闭,延迟一段时间后打开
case 8:
case 9:
case 10:
case 11:
s = cmd - 0x80;
ds_printf("延迟 %d 秒打开", s);
//OnWrite(0);
Next = 1;
StartAsync(s * 1000);
break;
case 8:
case 9:
case 10:
case 11:
s = cmd - 0x80;
ds_printf("延迟 %d 秒打开", s);
//OnWrite(0);
Next = 1;
StartAsync(s * 1000);
break;
}
#if DS_DEBUG
//Name.Show(true);
@ -250,7 +250,7 @@ int ByteDataPort::Write(byte* data)
obj->Show(true);
}
else*/
ds_printf("\r\n");
ds_printf("\r\n");
#endif
return Read(data);
@ -283,32 +283,32 @@ void ByteDataPort::DelayClose(int second)
void ByteDataPort::AsyncTask(void* param)
{
ByteDataPort* dp = (ByteDataPort*)param;
dp->Busy = false;
byte cmd = dp->Next;
if(cmd != 0xFF) dp->Write(&cmd);
dp->Busy = false;
byte cmd = dp->Next;
if (cmd != 0xFF) dp->Write(&cmd);
}
void ByteDataPort::StartAsync(int ms)
{
// 不允许0毫秒的异步事件
if(!ms) return;
if (!ms) return;
Busy = true;
if(!_tid) _tid = Sys.AddTask(AsyncTask, this, -1, -1, "定时开关");
Busy = true;
if (!_tid) _tid = Sys.AddTask(AsyncTask, this, -1, -1, "定时开关");
Sys.SetTask(_tid, true, ms);
}
int DataOutputPort::OnWrite(byte data)
{
if(!Port) return 0;
if (!Port) return 0;
Port->Write(data);
Port->Write(data > 0);
return OnRead();
};
byte DataOutputPort::OnRead()
{
if(!Port) return 0;
if (!Port) return 0;
return Port->Read() ? 1 : 0;
};
@ -316,30 +316,30 @@ byte DataOutputPort::OnRead()
String DataOutputPort::ToString() const
{
String str;
if(!Port) return str;
if (!Port) return str;
return Port->ToString();
}
int DataInputPort::Write(byte* data)
{
if(!Port) return 0;
if (!Port) return 0;
return Read(data);
};
int DataInputPort::Read(byte* data)
{
if(!Port) return 0;
if (!Port) return 0;
*data = Port->Read() ? 1 : 0;
*data = Port->Read() ? 1 : 0;
return Size();
};
String DataInputPort::ToString() const
{
String str;
if(!Port) return str;
if (!Port) return str;
return Port->ToString();
}

View File

@ -622,7 +622,7 @@ void JObject::Add(cstring key, JValue& value)
_items.Add(key, &value);
}
uint JObject::size() const
int JObject::size() const
{
return _items.Count();
}
@ -679,7 +679,7 @@ const JValue& JArray::operator[] (uint i) const
return *_array[i];
}
uint JArray::size() const
int JArray::size() const
{
return _array.Count();
}

View File

@ -116,7 +116,7 @@ public:
void Add(cstring key, JValue& value);
// 大小
uint size() const;
int size() const;
String ToString() const;
@ -146,7 +146,7 @@ public:
void Add(const JValue& n);
// 大小
uint size() const;
int size() const;
String ToString() const;
@ -191,7 +191,7 @@ public:
JValue& operator=(JValue&& v);
explicit operator double() const { return float_v; }
explicit operator int() const { return int_v; }
explicit operator int() const { return (int)int_v; }
explicit operator bool() const { return bool_v; }
explicit operator String() const { return string_v; }
@ -199,7 +199,7 @@ public:
operator JArray () const { return array_v; }
double as_float() const { return float_v; }
int as_int() const { return int_v; }
int as_int() const { return (int)int_v; }
bool as_bool() const { return bool_v; }
String as_string() const { return string_v; }

View File

@ -3,25 +3,25 @@
// 初始化消息各字段为0
MessageBase::MessageBase()
{
Reply = false;
Error = false;
Reply = false;
Error = false;
}
MessageBase::MessageBase(const MessageBase& msg)
{
Reply = msg.Reply;
Error = msg.Error;
Reply = msg.Reply;
Error = msg.Error;
}
bool MessageBase::ReadMessage(const Message& msg)
{
TS("MessageBase::ReadMessage");
Reply = msg.Reply;
Error = msg.Error;
Reply = msg.Reply > 0;
Error = msg.Error > 0;
//Stream ms(msg.Data, msg.Length);
auto ms = msg.ToStream();
auto ms = msg.ToStream();
return Read(ms);
}
@ -33,7 +33,7 @@ void MessageBase::WriteMessage(Message& msg) const
// 如果是令牌消息,这里就要自己小心了
//Stream ms(msg.Data, 256);
//MemoryStream ms;
auto ms = msg.ToStream();
auto ms = msg.ToStream();
Write(ms);

View File

@ -10,7 +10,7 @@ class WeakStore
{
public:
cstring Magic; // 幻数。用于唯一标识
uint MagicLength;
int MagicLength;
ByteArray Data; // 数据
// 初始化

View File

@ -270,7 +270,7 @@ bool parseDNSMSG(const Buffer& bs, Buffer& ip_from_dns)
/* Answer section */
for (int i = 0; i < hdr.ancount; i++)
{
if(!dns_answer(ms, ip_from_dns)) return -1;
if(!dns_answer(ms, ip_from_dns)) return false;
}
/* Name server (authority) section */

View File

@ -12,28 +12,28 @@
#define NET_DEBUG DEBUG
//#define NET_DEBUG 0
#if NET_DEBUG
#define net_printf debug_printf
#define net_printf debug_printf
#else
#define net_printf(format, ...)
#define net_printf(format, ...)
#endif
Dhcp::Dhcp(NetworkInterface& host) : Host(host)
{
_Socket = host.CreateSocket(NetType::Udp);
_Socket = host.CreateSocket(NetType::Udp);
_Socket->Local.Port = 68;
_Socket->Remote.Port = 67;
_Socket->Remote.Address = IPAddress::Broadcast();
_Socket->Local.Port = 68;
_Socket->Remote.Port = 67;
_Socket->Remote.Address = IPAddress::Broadcast();
IP = host.IP;
IP = host.IP;
Running = false;
Result = false;
Times = 0;
MaxTimes = 6;
ExpiredTime = 500 * 10;
Running = false;
Result = false;
Times = 0;
MaxTimes = 6;
ExpiredTime = 500 * 10;
taskID = 0;
taskID = 0;
auto port = dynamic_cast<ITransport*>(_Socket);
port->Register(OnReceive, this);
@ -47,28 +47,28 @@ Dhcp::~Dhcp()
void Dhcp::SendDhcp(byte* buf, uint len)
{
if(!Running) return;
if (!Running) return;
auto dhcp = (DHCP_HEADER*)buf;
auto p = dhcp->Next();
if(p[len - 1] != DHCP_OPT_End)
auto dhcp = (DHCP_HEADER*)buf;
auto p = dhcp->Next();
if (p[len - 1] != DHCP_OPT_End)
{
// 此时指向的是负载数据后的第一个字节所以第一个opt不许Next
auto opt = (DHCP_OPT*)(p + len);
auto opt = (DHCP_OPT*)(p + len);
opt = opt->SetClientId(Host.Mac);
if(!IP.IsAny())
opt = opt->Next()->SetData(DHCP_OPT_RequestedIP, IP.Value);
if (!IP.IsAny())
opt = opt->Next()->SetData(DHCP_OPT_RequestedIP, IP.Value);
// 构造产品名称把ID第一个字节附到最后
String name = "SmartOS_";
String name = "SmartOS_";
//name.Concat(Sys.ID[0], 16);
//name.Concat(Sys.ID[1], 16);
name += Buffer(Sys.ID, 2).ToHex();
name += Buffer(Sys.ID, 2).ToHex();
opt = opt->Next()->SetData(DHCP_OPT_HostName, name);
String vendor = "www.wslink.cn";
opt = opt->Next()->SetData(DHCP_OPT_Vendor, vendor);
byte ps[] = { 0x01, 0x06, 0x03, 0x2b}; // 需要参数 Mask/DNS/Router/Vendor
byte ps[] = { 0x01, 0x06, 0x03, 0x2b }; // 需要参数 Mask/DNS/Router/Vendor
opt = opt->Next()->SetData(DHCP_OPT_ParameterList, Buffer(ps, sizeof(ps)));
opt = opt->Next()->End();
@ -84,17 +84,17 @@ void Dhcp::SendDhcp(byte* buf, uint len)
// 找服务器
void Dhcp::Discover()
{
if(!Running) return;
if (!Running) return;
byte buf[sizeof(DHCP_HEADER) + 200];
auto dhcp = (DHCP_HEADER*)buf;
auto dhcp = (DHCP_HEADER*)buf;
net_printf("DHCP::Discover...\r\n");
//dhcpid = Sys.Ms();
dhcp->Init(dhcpid, false);
auto p = dhcp->Next();
auto opt = (DHCP_OPT*)p;
auto p = dhcp->Next();
auto opt = (DHCP_OPT*)p;
opt->SetType(DHCP_TYPE_Discover);
SendDhcp(buf, (byte*)opt->Next() - p);
@ -102,16 +102,16 @@ void Dhcp::Discover()
void Dhcp::Request()
{
if(!Running) return;
if (!Running) return;
byte buf[sizeof(DHCP_HEADER) + 200];
auto dhcp = (DHCP_HEADER*)buf;
auto dhcp = (DHCP_HEADER*)buf;
net_printf("DHCP::Request...\r\n");
dhcp->Init(dhcpid, false);
auto p = dhcp->Next();
auto opt = (DHCP_OPT*)p;
auto p = dhcp->Next();
auto opt = (DHCP_OPT*)p;
opt->SetType(DHCP_TYPE_Request);
opt = opt->Next()->SetData(DHCP_OPT_DHCPServer, Server.Value);
@ -122,21 +122,21 @@ void Dhcp::Request()
void Dhcp::Start()
{
UInt64 now = Sys.Ms();
_expired = now + ExpiredTime;
UInt64 now = Sys.Ms();
_expired = now + ExpiredTime;
Random ran(Time.CurrentTicks());
uint randnum = (ran.Next()<<16) & 0xffff0000;
dhcpid = now + randnum;
uint randnum = (ran.Next() << 16) & 0xffff0000;
dhcpid = (uint)now + randnum;
net_printf("Dhcp::Start ExpiredTime=%dms DhcpID=0x%08x\r\n", ExpiredTime, dhcpid);
// 使用DHCP之前最好清空本地IP地址KWF等软路由要求非常严格
// 严格路由要求默认请求的IP必须在本网段否则不予处理
if(!IP.IsAny())
if (!IP.IsAny())
{
// 这里无法关闭主机只能希望DHCP是第一个启动的Socket
//Host->Close();
Host.IP = IP = IPAddress::Any();
Host.IP = IP = IPAddress::Any();
Host.Config();
}
@ -145,7 +145,7 @@ void Dhcp::Start()
//if(port) port->Open();
// 创建任务每500ms发送一次Discover
if(!taskID)
if (!taskID)
taskID = Sys.AddTask(Loop, this, 0, 500, "DHCP获取");
else
{
@ -153,27 +153,27 @@ void Dhcp::Start()
Sys.SetTask(taskID, true);
}
Result = false;
Result = false;
Running = true;
}
void Dhcp::Stop()
{
if(!Running) return;
if (!Running) return;
auto port = dynamic_cast<ITransport*>(_Socket);
if(port) port->Close();
if (port) port->Close();
Running = false;
Running = false;
Sys.SetTask(taskID, false);
net_printf("Dhcp::Stop Result=%d DhcpID=0x%08x Times=%d MaxTimes=%d\r\n", Result, dhcpid, Times, MaxTimes);
auto& host = Host;
if(Result)
auto& host = Host;
if (Result)
{
// 成功后次数清零
Times = 0;
Times = 0;
// 获取IP成功重新设置参数
host.Config();
@ -182,7 +182,7 @@ void Dhcp::Stop()
else
{
// 如果未达到重试次数则重新开始
if(++Times < MaxTimes)
if (++Times < MaxTimes)
{
Start();
}
@ -191,7 +191,7 @@ void Dhcp::Stop()
net_printf("尝试次数 %d 超过最大允许次数 %d ", Times, MaxTimes);
// 恢复上一次设置,如果首次,则恢复出厂设置
if(host.LoadConfig())
if (host.LoadConfig())
net_printf("恢复上一次设置");
else
{
@ -210,23 +210,23 @@ void Dhcp::Stop()
//OnStop(*this);
// 异步调用OnStop
Sys.AddTask([](void* p){ auto d = (Dhcp*)p; d->OnStop(*d); }, this, 0, -1, "OnStop");
Sys.AddTask([](void* p) { auto d = (Dhcp*)p; d->OnStop(*d); }, this, 0, -1, "OnStop");
}
void Dhcp::Loop(void* param)
{
auto& dhcp = *(Dhcp*)param;
auto& dhcp = *(Dhcp*)param;
// 网络未就绪时不要处理
if(!dhcp.Host.Linked) return;
if (!dhcp.Host.Linked) return;
if(!dhcp.Running)
if (!dhcp.Running)
{
// 上一次是成功的这次定时任务可能就是重新获取IP
if(dhcp.Result) dhcp.Start();
if (dhcp.Result) dhcp.Start();
}
// 检查总等待时间
if(dhcp._expired < Sys.Ms())
if (dhcp._expired < Sys.Ms())
{
dhcp.Stop();
return;
@ -240,12 +240,12 @@ void Dhcp::Loop(void* param)
DHCP_OPT* GetOption(byte* p, int len, DHCP_OPTION option)
{
byte* end = p + len;
while(p < end)
while (p < end)
{
byte opt = *p++;
byte len = *p++;
if(opt == DHCP_OPT_End) return 0;
if(opt == option) return (DHCP_OPT*)(p - 2);
if (opt == DHCP_OPT_End) return 0;
if (opt == option) return (DHCP_OPT*)(p - 2);
p += len;
}
@ -255,35 +255,35 @@ DHCP_OPT* GetOption(byte* p, int len, DHCP_OPTION option)
void Dhcp::PareOption(Stream& ms)
{
auto& host = Host;
while(ms.Remain())
auto& host = Host;
while (ms.Remain())
{
byte opt = ms.ReadByte();
if(opt == DHCP_OPT_End) break;
if (opt == DHCP_OPT_End) break;
byte len = ms.ReadByte();
// 有些家用路由器会发送错误的len大于4字节导致覆盖前后数据
switch(opt)
switch (opt)
{
case DHCP_OPT_Mask: host.Mask = ms.ReadUInt32(); len -= 4; break;
case DHCP_OPT_Router: host.Gateway = ms.ReadUInt32(); len -= 4; break;
case DHCP_OPT_DHCPServer: Server = ms.ReadUInt32(); len -= 4; break;
case DHCP_OPT_DNSServer:
{
// 有可能有多个DNS只要第一个
IPAddress dns = ms.ReadUInt32();
// 成功获取DHCP信息后采用本地DNS为主DNS阿里公共DNS为备用DNS
IPAddress aliyun(223, 5, 5, 5);
//if(host.DNSServer != dns) host.DNSServer2 = host.DNSServer;
host.DNSServer2 = aliyun;
host.DNSServer = dns;
len -= 4;
break;
}
//default:
// net_printf("Unkown DHCP Option=%d Length=%d\r\n", opt, len);
case DHCP_OPT_Mask: host.Mask = ms.ReadUInt32(); len -= 4; break;
case DHCP_OPT_Router: host.Gateway = ms.ReadUInt32(); len -= 4; break;
case DHCP_OPT_DHCPServer: Server = ms.ReadUInt32(); len -= 4; break;
case DHCP_OPT_DNSServer:
{
// 有可能有多个DNS只要第一个
IPAddress dns = ms.ReadUInt32();
// 成功获取DHCP信息后采用本地DNS为主DNS阿里公共DNS为备用DNS
IPAddress aliyun(223, 5, 5, 5);
//if(host.DNSServer != dns) host.DNSServer2 = host.DNSServer;
host.DNSServer2 = aliyun;
host.DNSServer = dns;
len -= 4;
break;
}
//default:
// net_printf("Unkown DHCP Option=%d Length=%d\r\n", opt, len);
}
// DNS可能有多个IP就不止4长度了
if(len > 0) ms.Seek(len);
if (len > 0) ms.Seek(len);
}
}
@ -296,24 +296,24 @@ uint Dhcp::OnReceive(ITransport* port, Buffer& bs, void* param, void* param2)
void Dhcp::Process(Buffer& bs, const IPEndPoint& ep)
{
auto dhcp = (DHCP_HEADER*)bs.GetBuffer();
if(!dhcp->Valid()) return;
auto dhcp = (DHCP_HEADER*)bs.GetBuffer();
if (!dhcp->Valid()) return;
auto data = dhcp->Next();
uint len = bs.Length() - sizeof(DHCP_HEADER);
auto data = dhcp->Next();
uint len = bs.Length() - sizeof(DHCP_HEADER);
// 获取DHCP消息类型
auto opt = GetOption(data, len, DHCP_OPT_MessageType);
if(!opt) return;
if (!opt) return;
// 所有响应都需要检查事务ID
if(_REV(dhcp->TransID) != dhcpid) return;
if (_REV(dhcp->TransID) != dhcpid) return;
#if NET_DEBUG
auto& remote = ep.Address;
auto& remote = ep.Address;
#endif
if(opt->Data == DHCP_TYPE_Offer)
if (opt->Data == DHCP_TYPE_Offer)
{
Host.IP = IP = dhcp->YourIP;
Stream optData(dhcp->Next(), len);
@ -332,7 +332,7 @@ void Dhcp::Process(Buffer& bs, const IPEndPoint& ep)
Request();
}
else if(opt->Data == DHCP_TYPE_Ack)
else if (opt->Data == DHCP_TYPE_Ack)
{
Host.IP = IP = dhcp->YourIP;
#if NET_DEBUG
@ -349,7 +349,7 @@ void Dhcp::Process(Buffer& bs, const IPEndPoint& ep)
// 查找租约时间,提前续约
opt = GetOption(data, len, DHCP_OPT_IPLeaseTime);
if(opt)
if (opt)
{
// 续约时间,大字节序,时间单位秒
uint time = _REV(*(uint*)&opt->Data);
@ -357,7 +357,7 @@ void Dhcp::Process(Buffer& bs, const IPEndPoint& ep)
net_printf("DHCP IPLeaseTime:%ds\r\n", time);
// DHCP租约过期前提前一分钟重新获取IP地址
if(time > 0)
if (time > 0)
{
Sys.SetTaskPeriod(taskID, (UInt64)(time - 60) * 1000);
Sys.SetTask(taskID, true);
@ -365,7 +365,7 @@ void Dhcp::Process(Buffer& bs, const IPEndPoint& ep)
}
}
#if NET_DEBUG
else if(opt->Data == DHCP_TYPE_Nak)
else if (opt->Data == DHCP_TYPE_Nak)
{
// 导致Nak的原因
opt = GetOption(data, len, DHCP_OPT_Message);
@ -373,7 +373,7 @@ void Dhcp::Process(Buffer& bs, const IPEndPoint& ep)
IP.Show();
net_printf(" From ");
remote.Show();
if(opt)
if (opt)
{
net_printf(" ");
String((char*)&opt->Data, opt->Length).Show(true);

View File

@ -8,7 +8,7 @@
// 字节序
#ifndef LITTLE_ENDIAN
#define LITTLE_ENDIAN 1
#define LITTLE_ENDIAN 1
#endif
#pragma pack(push) // 保存对齐状态
@ -31,34 +31,34 @@ public:
MacAddr(UInt64 v = 0)
{
v4 = v;
v2 = v >> 32;
v4 = v & 0xFFFFFFFF;
v2 = (v >> 32) & 0xFFFF;
}
// 是否广播地址全0或全1
bool IsBroadcast() { return (!v4 && !v2) || (v4 == 0xFFFFFFFF && v2 == 0xFFFF); }
MacAddr& operator=(UInt64 v)
MacAddr& operator=(UInt64 v)
{
v4 = v;
v2 = v >> 32;
v4 = v & 0xFFFFFFFF;
v2 = (v >> 32) & 0xFFFF;
return *this;
}
UInt64 Value()
UInt64 Value()
{
UInt64 v = v4;
v |= ((UInt64)v2) << 32;
return v;
}
MacAddr& operator=(const MacAddress& v) { *this = v.Value; return *this; }
friend bool operator==(MacAddr& addr1, MacAddr& addr2)
MacAddr& operator=(const MacAddress& v) { *this = v.Value; return *this; }
friend bool operator==(MacAddr& addr1, MacAddr& addr2)
{
return addr1.v4 == addr2.v4 && addr1.v2 == addr2.v2;
}
friend bool operator!=(MacAddr& addr1, MacAddr& addr2)
friend bool operator!=(MacAddr& addr1, MacAddr& addr2)
{
return addr1.v4 != addr2.v4 || addr1.v2 != addr2.v2;
}
@ -71,9 +71,9 @@ public:
// 以太网协议类型
typedef enum
{
ETH_ARP = 0x0608,
ETH_IP = 0x0008,
ETH_IPv6 = 0xDD86,
ETH_ARP = 0x0608,
ETH_IP = 0x0008,
ETH_IPv6 = 0xDD86,
}ETH_TYPE;
#define IS_ETH_TYPE(type) (type == ETH_ARP || type == ETH_IP || type == ETH_IPv6)
@ -85,19 +85,19 @@ typedef struct _ETH_HEADER
MacAddr SrcMac; // 源mac地址
ETH_TYPE Type; // 以太网类型
uint Size() { return sizeof(this[0]); }
uint Offset() { return Size(); }
byte* Next() { return (byte*)this + Size(); }
uint Size() { return sizeof(this[0]); }
uint Offset() { return Size(); }
byte* Next() { return (byte*)this + Size(); }
}ETH_HEADER;
// IP协议类型
typedef enum
{
IP_NONE = 0,
IP_ICMP = 1,
IP_IGMP = 2,
IP_TCP = 6,
IP_UDP = 17,
IP_ICMP = 1,
IP_IGMP = 2,
IP_TCP = 6,
IP_UDP = 17,
}IP_TYPE;
#define IS_IP_TYPE(type) (type == IP_ICMP || type == IP_IGMP || type == IP_TCP || type == IP_UDP)
@ -105,13 +105,13 @@ typedef enum
// IP头部总长度20=0x14字节偏移14=0x0E。后面可能有可选数据Length决定头部总长度4的倍数
typedef struct _IP_HEADER
{
#if LITTLE_ENDIAN
byte Length:4; // 首部长度
byte Version:4; // 版本
#else
byte Version:4; // 版本
byte Length:4; // 首部长度。每个单位4个字节
#endif
#if LITTLE_ENDIAN
byte Length : 4; // 首部长度
byte Version : 4; // 版本
#else
byte Version : 4; // 版本
byte Length : 4; // 首部长度。每个单位4个字节
#endif
byte TypeOfService; // 服务类型
ushort TotalLength; // 总长度
ushort Identifier; // 标志
@ -133,24 +133,24 @@ typedef struct _IP_HEADER
TTL = 64;
Protocol = type;
if(recursion) Prev()->Type = ETH_IP;
if (recursion) Prev()->Type = ETH_IP;
}
uint Size() { return (Length <= 5) ? sizeof(this[0]) : (Length << 2); }
uint Offset() { return Prev()->Offset() + Size(); }
ETH_HEADER* Prev() { return (ETH_HEADER*)((byte*)this - sizeof(ETH_HEADER)); }
uint Size() { return (Length <= 5) ? sizeof(this[0]) : (Length << 2); }
uint Offset() { return Prev()->Offset() + Size(); }
ETH_HEADER* Prev() { return (ETH_HEADER*)((byte*)this - sizeof(ETH_HEADER)); }
//byte* Next() { return (byte*)this + sizeof(&this[0]); }
byte* Next() { return (byte*)this + Size(); }
byte* Next() { return (byte*)this + Size(); }
}IP_HEADER;
typedef enum
{
TCP_FLAGS_FIN = 1, // 结束连接请求标志位。为1表示结束连接请求数据包
TCP_FLAGS_SYN = 2, // 连接请求标志位。为1表示发起连接的请求数据包
TCP_FLAGS_RST = 4,
TCP_FLAGS_PUSH = 8, // 标志位为1表示此数据包应立即进行传递
TCP_FLAGS_ACK = 0x10, // 应答标志位为1表示确认数据包为应答数据包
TCP_FLAGS_URG = 0x20,
TCP_FLAGS_FIN = 1, // 结束连接请求标志位。为1表示结束连接请求数据包
TCP_FLAGS_SYN = 2, // 连接请求标志位。为1表示发起连接的请求数据包
TCP_FLAGS_RST = 4,
TCP_FLAGS_PUSH = 8, // 标志位为1表示此数据包应立即进行传递
TCP_FLAGS_ACK = 0x10, // 应答标志位为1表示确认数据包为应答数据包
TCP_FLAGS_URG = 0x20,
}TCP_FLAGS;
//TCP头部总长度20=0x14字节偏移34=0x22。后面可能有可选数据Length决定头部总长度4的倍数
@ -160,24 +160,24 @@ typedef struct _TCP_HEADER
ushort DestPort; // 目的端口号
uint Seq; // 序列号
uint Ack; // 确认号
#if LITTLE_ENDIAN
byte reserved_1:4; // 保留6位中的4位首部长度
byte Length:4; // tcp头部长度
byte Flags:6; // 6位标志
byte reserved_2:2; // 保留6位中的2位
#else
byte Length:4; // tcp头部长度
byte reserved_1:4; // 保留6位中的4位首部长度
byte reserved_2:2; // 保留6位中的2位
byte Flags:6; // 6位标志
#endif
#if LITTLE_ENDIAN
byte reserved_1 : 4; // 保留6位中的4位首部长度
byte Length : 4; // tcp头部长度
byte Flags : 6; // 6位标志
byte reserved_2 : 2; // 保留6位中的2位
#else
byte Length : 4; // tcp头部长度
byte reserved_1 : 4; // 保留6位中的4位首部长度
byte reserved_2 : 2; // 保留6位中的2位
byte Flags : 6; // 6位标志
#endif
ushort WindowSize; // 16位窗口大小
ushort Checksum; // 16位TCP检验和
ushort urgt_p; // 16为紧急指针
void Init(bool recursion = false)
{
Length = sizeof(this[0]) >> 2;
Length = sizeof(this[0]) >> 2;
reserved_1 = 0;
reserved_2 = 0;
@ -185,13 +185,13 @@ typedef struct _TCP_HEADER
WindowSize = _REV16(1024);
urgt_p = 0;
if(recursion) Prev()->Init(IP_TCP, recursion);
if (recursion) Prev()->Init(IP_TCP, recursion);
}
uint Size() { return (Length <= 5) ? sizeof(this[0]) : (Length << 2); }
uint Offset() { return Prev()->Offset() + Size(); }
IP_HEADER* Prev() { return (IP_HEADER*)((byte*)this - sizeof(IP_HEADER)); }
byte* Next() { return (byte*)this + Size(); }
uint Size() { return (Length <= 5) ? sizeof(this[0]) : (Length << 2); }
uint Offset() { return Prev()->Offset() + Size(); }
IP_HEADER* Prev() { return (IP_HEADER*)((byte*)this - sizeof(IP_HEADER)); }
byte* Next() { return (byte*)this + Size(); }
}TCP_HEADER;
//UDP头部总长度8字节偏移34=0x22
@ -206,13 +206,13 @@ typedef struct _UDP_HEADER
{
Length = sizeof(this[0]);
if(recursion) Prev()->Init(IP_UDP, recursion);
if (recursion) Prev()->Init(IP_UDP, recursion);
}
uint Size() { return sizeof(this[0]); }
uint Offset() { return Prev()->Offset() + Size(); }
IP_HEADER* Prev() { return (IP_HEADER*)((byte*)this - sizeof(IP_HEADER)); }
byte* Next() { return (byte*)this + Size(); }
uint Size() { return sizeof(this[0]); }
uint Offset() { return Prev()->Offset() + Size(); }
IP_HEADER* Prev() { return (IP_HEADER*)((byte*)this - sizeof(IP_HEADER)); }
byte* Next() { return (byte*)this + Size(); }
}UDP_HEADER;
//ICMP头部总长度8字节偏移34=0x22
@ -229,13 +229,13 @@ typedef struct _ICMP_HEADER
Type = 8;
Code = 0;
if(recursion) Prev()->Init(IP_ICMP, recursion);
if (recursion) Prev()->Init(IP_ICMP, recursion);
}
uint Size() { return sizeof(this[0]); }
uint Offset() { return Prev()->Offset() + Size(); }
IP_HEADER* Prev() { return (IP_HEADER*)((byte*)this - sizeof(IP_HEADER)); }
byte* Next() { return (byte*)this + Size(); }
uint Size() { return sizeof(this[0]); }
uint Offset() { return Prev()->Offset() + Size(); }
IP_HEADER* Prev() { return (IP_HEADER*)((byte*)this - sizeof(IP_HEADER)); }
byte* Next() { return (byte*)this + Size(); }
}ICMP_HEADER;
// ARP头部总长度28=0x1C字节偏移14=0x0E可能加18字节填充
@ -259,13 +259,13 @@ typedef struct _ARP_HEADER
HardLength = 6;
ProtocolLength = 4;
if(recursion) Prev()->Type = ETH_ARP;
if (recursion) Prev()->Type = ETH_ARP;
}
uint Size() { return sizeof(this[0]); }
uint Offset() { return Prev()->Offset() + Size(); }
ETH_HEADER* Prev() { return (ETH_HEADER*)((byte*)this - sizeof(ETH_HEADER)); }
byte* Next() { return (byte*)this + Size(); }
uint Size() { return sizeof(this[0]); }
uint Offset() { return Prev()->Offset() + Size(); }
ETH_HEADER* Prev() { return (ETH_HEADER*)((byte*)this - sizeof(ETH_HEADER)); }
byte* Next() { return (byte*)this + Size(); }
}ARP_HEADER;
// DHCP头部总长度240=0xF0字节偏移42=0x2A后面可选数据偏移282=0x11A
@ -292,24 +292,24 @@ typedef struct _DHCP_HEADER
// 为了安全,清空一次
Buffer(this, sizeof(this[0])).Clear();
MsgType = 1;
HardType = 1;
HardLength = 6;
Hops = 0;
TransID = _REV(dhcpid);
MsgType = 1;
HardType = 1;
HardLength = 6;
Hops = 0;
TransID = _REV(dhcpid);
//Flags = 0x80; // 从0-15bits最左一bit为1时表示server将以广播方式传送封包给 client其余尚未使用
SetMagic();
if(recursion) Prev()->Init(recursion);
if (recursion) Prev()->Init(recursion);
}
uint Size() { return sizeof(this[0]); }
uint Offset() { return Prev()->Offset() + Size(); }
UDP_HEADER* Prev() { return (UDP_HEADER*)((byte*)this - sizeof(UDP_HEADER)); }
byte* Next() { return (byte*)this + Size(); }
uint Size() { return sizeof(this[0]); }
uint Offset() { return Prev()->Offset() + Size(); }
UDP_HEADER* Prev() { return (UDP_HEADER*)((byte*)this - sizeof(UDP_HEADER)); }
byte* Next() { return (byte*)this + Size(); }
void SetMagic() { Magic = 0x63538263; }
bool Valid() { return Magic == 0x63538263; }
void SetMagic() { Magic = 0x63538263; }
bool Valid() { return Magic == 0x63538263; }
}DHCP_HEADER;
// DHCP后面可选数据格式为“代码+长度+数据”
@ -387,7 +387,7 @@ typedef struct _DHCP_OPT
{
Option = option;
Length = 4;
Buffer(&Data, 4) = &value;
Buffer(&Data, 4) = &value;
return this;
}

View File

@ -1,4 +1,4 @@
#include "Kernel\Sys.h"
#include "Kernel\Sys.h"
#include "IPAddress.h"

View File

@ -1,4 +1,4 @@
#include "IPEndPoint.h"
#include "IPEndPoint.h"
#define NET_DEBUG DEBUG
//#define NET_DEBUG 0

View File

@ -1,4 +1,4 @@
#include "Core\_Core.h"
#include "Core\_Core.h"
#include "Core\ByteArray.h"
#include "Core\SString.h"

View File

@ -61,6 +61,7 @@ String NetUri::ToString() const
case NetType::Tcp: str += "Tcp"; break;
case NetType::Udp: str += "Udp"; break;
case NetType::Http: str += "Http"; break;
default: break;
}
str += "://";

View File

@ -19,7 +19,7 @@ bool DeviceMessage::GetBaseInfo(Stream& ms)
{
BinaryPair bp(ms);
byte act;
if (!bp.Get("Action",act))return false;
if (!bp.Get("Action", act))return false;
Action = (DeviceAtions)act;
if (!bp.Get("ID", Id))return false;
return true;
@ -40,7 +40,7 @@ bool DeviceMessage::GetMsgInfo(Stream&ms, Device* dv)
}
byte login = 0;
if (bp.Get("Online", login))
pDev->Logined = login;
pDev->Logined = login > 0;
bp.Get("Kind", pDev->Kind);
bp.Get("LastActive", pDev->LastTime);
bp.Get("RegisterTime", pDev->RegTime);

View File

@ -565,7 +565,7 @@ void DevicesManagement::MaintainState()
if (Port->Status < 2) return;
SendDevicesIDs();
auto now = DateTime::Now().TotalSeconds();
uint now = DateTime::Now().TotalSeconds();
// 处理持久在线设备
byte len = Length();

View File

@ -25,28 +25,28 @@ static void BroadcastHelloTask(void* param);
TokenClient::TokenClient()
: Routes(String::Compare)
{
Token = 0;
Token = 0;
Opened = false;
Status = 0;
Opened = false;
Status = 0;
LoginTime = 0;
LastSend = 0;
LastActive = 0;
Delay = 0;
MaxNotActive = 0;
LoginTime = 0;
LastSend = 0;
LastActive = 0;
Delay = 0;
MaxNotActive = 0;
Master = nullptr;
Cfg = nullptr;
Master = nullptr;
Cfg = nullptr;
Received = nullptr;
Param = nullptr;
Received = nullptr;
Param = nullptr;
NextReport = -1;
ReportLength = 0;
NextReport = -1;
ReportLength = 0;
assert(!Current, "只能有一个令牌客户端实例");
Current = this;
Current = this;
}
void TokenClient::Open()
@ -76,10 +76,10 @@ void TokenClient::Close()
if (Master)
{
delete Master;
Master = nullptr;
Master = nullptr;
}
auto& cs = Controls;
auto& cs = Controls;
for (int i = 0; i < cs.Count(); i++)
{
delete cs[i];
@ -91,14 +91,14 @@ void TokenClient::Close()
static TokenController* AddMaster(TokenClient& client)
{
auto uri = client.Cfg->Uri();
auto uri = client.Cfg->Uri();
// 创建连接服务器的Socket
auto socket = Socket::CreateRemote(uri);
if(!socket) return nullptr;
auto socket = Socket::CreateRemote(uri);
if (!socket) return nullptr;
// 创建连接服务器的控制器
auto ctrl = new TokenController();
ctrl->_Socket = socket;
auto ctrl = new TokenController();
ctrl->_Socket = socket;
// 创建客户端
client.Master = ctrl;
@ -109,17 +109,17 @@ static TokenController* AddMaster(TokenClient& client)
static TokenController* AddControl(TokenClient& client, NetworkInterface* host, const NetUri& uri, ushort remotePort)
{
// 创建连接服务器的Socket
auto socket = host ? host->CreateClient(uri) : Socket::CreateClient(uri);
if(!socket) return nullptr;
auto socket = host ? host->CreateClient(uri) : Socket::CreateClient(uri);
if (!socket) return nullptr;
// 创建连接服务器的控制器
auto ctrl = new TokenController();
ctrl->_Socket = socket;
auto ctrl = new TokenController();
ctrl->_Socket = socket;
// 创建客户端
socket->Remote.Address = IPAddress::Broadcast();
socket->Remote.Port = remotePort;
ctrl->ShowRemote = true;
socket->Remote.Address = IPAddress::Broadcast();
socket->Remote.Port = remotePort;
ctrl->ShowRemote = true;
client.Controls.Add(ctrl);
return ctrl;
@ -127,79 +127,79 @@ static TokenController* AddControl(TokenClient& client, NetworkInterface* host,
void TokenClient::CheckNet()
{
auto mst = Master;
auto& cs = Controls;
auto mst = Master;
auto& cs = Controls;
//assert(cs.Count() > 0, "令牌客户端还没设置控制器呢");
// 现在是否已连接
bool linked = true;
bool linked = true;
// 检测主链接
if(!mst)
if (!mst)
{
linked = false;
auto ctrl = AddMaster(*this);
if(!ctrl) return;
linked = false;
auto ctrl = AddMaster(*this);
if (!ctrl) return;
debug_printf("TokenClient::CheckNet %s 成功创建主连接\r\n", ctrl->_Socket->Host->Name);
}
// 检测主链接是否已经断开
else if(!mst->_Socket->Host->Linked)
else if (!mst->_Socket->Host->Linked)
{
linked = false;
linked = false;
debug_printf("TokenClient::CheckNet %s断开切换主连接\r\n", mst->_Socket->Host->Name);
delete mst;
Master = nullptr;
Master = nullptr;
Status = 0;
Token = 0;
Status = 0;
Token = 0;
// 未连接时,加快网络检查速度
Sys.SetTaskPeriod(_task, 1000);
auto ctrl = AddMaster(*this);
if(!ctrl) return;
auto ctrl = AddMaster(*this);
if (!ctrl) return;
}
// 从未连接转为已连接
mst = Master;
mst = Master;
if (!linked && mst)
{
Delegate2<TokenMessage&, TokenController&> dlg(&TokenClient::OnReceive, this);
mst->Received = dlg;
mst->Open();
Cfg->ServerIP = mst->_Socket->Remote.Address.Value;
Cfg->ServerIP = mst->_Socket->Remote.Address.Value;
}
// 为其它网卡创建本地会话
// 启动本地控制器
if (_LocalReceive)
{
auto& nis = NetworkInterface::All;
auto& nis = NetworkInterface::All;
for (int k = 0; k < nis.Count(); k++)
{
// 检测该接口上是否创建了控制器
bool flag = false;
bool flag = false;
for (int i = 0; i < cs.Count(); i++)
{
if(cs[i]->_Socket->Host == nis[k])
if (cs[i]->_Socket->Host == nis[k])
{
flag = true;
flag = true;
break;
}
}
// 在该接口上创建控制器
if(!flag)
if (!flag)
{
debug_printf("TokenClient::CheckNet %s 创建本地监听 ", nis[k]->Name);
NetUri uri(NetType::Udp, IPAddress::Broadcast(), Cfg->Port);
auto ctrl = AddControl(*this, nis[k], uri, Cfg->Port);
if(ctrl)
auto ctrl = AddControl(*this, nis[k], uri, Cfg->Port);
if (ctrl)
{
ctrl->Received = _LocalReceive;
ctrl->Received = _LocalReceive;
ctrl->Open();
debug_printf("成功\r\n");
@ -233,7 +233,7 @@ bool TokenClient::Send(TokenMessage& msg, TokenController* ctrl)
if (msg.Code != 0x01 && msg.Code != 0x02 && msg.Code != 0x07) return false;
}
if (!ctrl) ctrl = Master;
if (!ctrl) ctrl = Master;
if (!ctrl) return false;
assert(ctrl, "TokenClient::Send");
@ -362,11 +362,11 @@ void TokenClient::LocalSend(int start, const Buffer& bs)
debug_printf("LocalSend\r\n");
TokenDataMessage dm;
dm.Start = start;
dm.Data = bs;
dm.Start = start;
dm.Data = bs;
TokenMessage msg;
msg.Code = 0x06;
msg.Code = 0x06;
dm.WriteMessage(msg);
Send(msg);
@ -406,13 +406,13 @@ void TokenClient::LoopTask()
// MaxNotActive 为零便不考虑重启
if (MaxNotActive != 0 && LastActive + MaxNotActive < Sys.Ms()) Sys.Reboot();
auto flag = Master;
auto flag = Master;
//if(!Master)
{
CheckNet();
if(!Master) return;
if (!Master) return;
if(!flag) Sys.SetTaskPeriod(_task, 5000);
if (!flag) Sys.SetTaskPeriod(_task, 5000);
}
// 状态。0准备、1握手完成、2登录后
@ -471,13 +471,13 @@ void TokenClient::SayHello(bool broadcast)
ext.Protocol = sock->Protocol == NetType::Udp ? 17 : 6;
}
ext.Cipher = "RC4";
ext.Name = Cfg->User();
ext.Cipher = "RC4";
ext.Name = Cfg->User();
// 未注册时采用系统名称
if (!ext.Name)
{
ext.Name = Sys.Name;
ext.Key = Buffer(Sys.ID, 16);
ext.Name = Sys.Name;
ext.Key = Buffer(Sys.ID, 16);
}
ext.WriteMessage(msg);
@ -510,7 +510,7 @@ bool TokenClient::OnHello(TokenMessage& msg, TokenController* ctrl)
// 解析数据
HelloMessage ext;
ext.Reply = msg.Reply;
ext.Reply = msg.Reply > 0;
ext.ReadMessage(msg);
ext.Show(true);
@ -522,8 +522,8 @@ bool TokenClient::OnHello(TokenMessage& msg, TokenController* ctrl)
TS("TokenClient::OnHello_Error");
Status = 0;
Token = 0;
Status = 0;
Token = 0;
// 未握手错误,马上重新握手
if (ext.ErrCode == 0x7F) Sys.SetTask(_task, true, 0);
@ -559,7 +559,7 @@ bool TokenClient::OnRedirect(HelloMessage& msg)
if (!(msg.ErrCode == 0xFE || msg.ErrCode == 0xFD)) return false;
Cookie = msg.Cookie;
Cookie = msg.Cookie;
// 0xFE永久改变厂商地址
if (msg.ErrCode == 0xFE)
@ -567,10 +567,10 @@ bool TokenClient::OnRedirect(HelloMessage& msg)
auto cfg = Cfg;
cfg->Show();
cfg->Protocol = msg.Uri.Type;
cfg->Server() = msg.Uri.Host;
cfg->ServerPort = msg.Uri.Port;
cfg->Token() = msg.Cookie;
cfg->Protocol = msg.Uri.Type;
cfg->Server() = msg.Uri.Host;
cfg->ServerPort = msg.Uri.Port;
cfg->Token() = msg.Cookie;
cfg->Save();
cfg->Show();
@ -669,18 +669,18 @@ void TokenClient::Login()
LoginMessage login;
auto cfg = Cfg;
login.User = cfg->User();
auto cfg = Cfg;
login.User = cfg->User();
// 原始密码对盐值进行加密,得到登录密码
// auto now = Sys.Ms();
auto now = DateTime::Now().TotalMs();
auto arr = Buffer(&now, 8);
auto now = DateTime::Now().TotalMs();
auto arr = Buffer(&now, 8);
// login.Salt = arr;
RC4::Encrypt(arr, cfg->Pass());
login.Pass = arr.ToHex();
login.Pass = arr.ToHex();
login.Cookie = Cookie;
login.Cookie = Cookie;
TokenMessage msg(2);
login.WriteMessage(msg);
@ -710,14 +710,14 @@ bool TokenClient::OnLogin(TokenMessage& msg, TokenController* ctrl)
if (result == 0xF7)
{
// 任何错误,重新握手
Status = 1;
Token = 0;
Status = 1;
Token = 0;
Register();
return false;
}
Token = 0;
Status = 0;
Token = 0;
Status = 0;
if (result == 0x7F) Sys.SetTask(_task, true, 0);
}
@ -884,15 +884,15 @@ void TokenClient::Write(int start, byte dat)
void TokenClient::ReportAsync(int start, uint length)
{
if (start + length > Store.Data.Length())
if (start + (int)length > Store.Data.Length())
{
debug_printf("布置异步上报数据失败\r\n");
debug_printf("sta:%d len:%d data.len:%d\r\n", start, length, Store.Data.Length());
return;
}
NextReport = start;
ReportLength = length;
NextReport = start;
ReportLength = length;
// 延迟上报,期间有其它上报任务到来将会覆盖
Sys.SetTask(_task, true, 20);
@ -902,13 +902,13 @@ bool TokenClient::CheckReport()
{
TS("TokenClient::CheckReport");
auto offset = NextReport;
uint len = ReportLength;
auto offset = NextReport;
int len = ReportLength;
if (offset < 0) return false;
// 检查索引,否则数组越界
auto& bs = Store.Data;
auto& bs = Store.Data;
if (bs.Length() >= offset + len)
{
if (len == 1)
@ -1130,7 +1130,7 @@ void TokenClient::Register(cstring action, InvokeHandler handler, void* param)
// 快速建立令牌客户端注册默认Api
TokenClient* TokenClient::CreateFast(const Buffer& store)
{
auto tc = new TokenClient();
auto tc = new TokenClient();
// 重启
tc->Register("Gateway/Restart", &TokenClient::InvokeRestart, tc);
@ -1143,7 +1143,7 @@ TokenClient* TokenClient::CreateFast(const Buffer& store)
// 获取所有Invoke命令
tc->Register("Api/All", &TokenClient::InvokeGetAllApi, tc);
if(store.Length()) tc->Store.Data.Set(store.GetBuffer(), store.Length());
if (store.Length()) tc->Store.Data.Set(store.GetBuffer(), store.Length());
tc->UseLocal();
@ -1204,12 +1204,12 @@ bool TokenClient::InvokeSetRemote(void * param, const Pair& args, Stream& result
// 永久改变地址
if (fixd)
{
auto cfg = client->Cfg;
auto cfg = client->Cfg;
cfg->Show();
cfg->Protocol = uri.Type;
cfg->Server() = uri.Host;
cfg->ServerPort = uri.Port;
cfg->Protocol = uri.Type;
cfg->Server() = uri.Host;
cfg->ServerPort = uri.Port;
cfg->Save();
cfg->Show();

View File

@ -51,8 +51,8 @@ TokenSession::TokenSession(TokenClient& client, TokenController& ctrl) :
HisSsNum++; // 历史Session个数
#endif
Status = 0;
LastActive = Sys.Ms();
Status = 0;
LastActive = Sys.Ms();
client.Sessions.Add(this);
}
@ -80,7 +80,7 @@ void TokenSession::OnReceive(TokenMessage& msg)
{
TS("TokenSession::OnReceive");
LastActive = Sys.Ms();
LastActive = Sys.Ms();
// if (Token == 0 && msg.Code > 1 && Key.Length() == 0)
if ((Token == 0 && msg.Code > 2) || msg.ErrorCode == DecryptError) // 解密失败 直接让他重新来过
{
@ -140,14 +140,14 @@ bool TokenSession::OnHello(TokenMessage& msg)
// 解析数据
HelloMessage ext;
ext.Reply = msg.Reply;
ext.Reply = msg.Reply > 0;
ext.ReadMessage(msg);
ext.Show(true);
TS("TokenSession::OnHello");
Name = ext.Name;
Name = ext.Name;
BinaryPair bp(msg.ToStream());
if (bp.Get("Action"))
@ -246,7 +246,7 @@ bool TokenSession::OnLogin(TokenMessage& msg)
}
else
{
Token = Sys.Ms();
Token = (uint)Sys.Ms();
login.Key = Control.Key;
login.Token = Token;
login.Reply = true;
@ -278,7 +278,7 @@ bool TokenSession::OnPing(TokenMessage& msg)
bool TokenSession::CheckExpired()
{
auto now = Sys.Ms();
auto now = Sys.Ms();
// 5分钟不活跃超时 LastActive为0的为特殊Session 不删除
if (LastActive + 5 * 60 * 1000 < now) return true;
@ -291,11 +291,11 @@ bool TokenSession::CheckExpired()
String TokenSession::ToString() const
{
String str;
int sec = (Sys.Ms() - LastActive) / 1000UL;
int sec = (int)(Sys.Ms() - LastActive) / 1000UL;
str = str + Remote + " " + Name + " LastActive " + sec + "s \t";
#if DEBUG
str += Stat;
str += Stat;
#endif
return str;

View File

@ -1,95 +1,221 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\Core\Array.cpp" />
<ClCompile Include="..\Core\Buffer.cpp" />
<ClCompile Include="..\Core\ByteArray.cpp" />
<ClCompile Include="..\Core\DateTime.cpp" />
<ClCompile Include="..\Core\Delegate.cpp" />
<ClCompile Include="..\Core\Dictionary.cpp" />
<ClCompile Include="..\Core\Environment.cpp" />
<ClCompile Include="..\Core\List.cpp" />
<ClCompile Include="..\Core\Queue.cpp" />
<ClCompile Include="..\Core\Random.cpp" />
<ClCompile Include="..\Core\Stream.cpp" />
<ClCompile Include="..\Core\String.cpp" />
<ClCompile Include="..\Core\TimeSpan.cpp" />
<ClCompile Include="..\Core\Type.cpp" />
<ClCompile Include="..\Core\Version.cpp" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{6C0D43A8-8411-48F3-989E-51C5379A5563}</ProjectGuid>
<RootNamespace>SmartOS</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="PropertySheet.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="PropertySheet.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<IncludePath>..\;$(IncludePath)</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BufferSecurityCheck>false</BufferSecurityCheck>
</ClCompile>
</ItemDefinitionGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<IncludePath>..\;$(IncludePath)</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<BufferSecurityCheck>false</BufferSecurityCheck>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\App\Alarm.cpp" />
<ClCompile Include="..\App\BlinkPort.cpp" />
<ClCompile Include="..\App\Button.cpp" />
<ClCompile Include="..\App\Button_GrayLevel.cpp" />
<ClCompile Include="..\App\Button_magnetic.cpp" />
<ClCompile Include="..\App\CommandPort.cpp" />
<ClCompile Include="..\App\Dimmer.cpp" />
<ClCompile Include="..\App\FlushPort.cpp" />
<ClCompile Include="..\App\IR.cpp" />
<ClCompile Include="..\App\IRcoding.cpp" />
<ClCompile Include="..\App\PowerUps.cpp" />
<ClCompile Include="..\App\PulsePort.cpp" />
<ClCompile Include="..\App\Raster.cpp" />
<ClCompile Include="..\App\Sensor.cpp" />
<ClCompile Include="..\App\Sound.cpp" />
<ClCompile Include="..\Board\AP0103.cpp" />
<ClCompile Include="..\Board\AP0104.cpp" />
<ClCompile Include="..\Board\AP0801.cpp" />
<ClCompile Include="..\Board\AP0802.cpp" />
<ClCompile Include="..\Board\BaseBoard.cpp" />
<ClCompile Include="..\Board\IOK026X.cpp" />
<ClCompile Include="..\Board\IOK027X.cpp" />
<ClCompile Include="..\Board\IOK0612.cpp" />
<ClCompile Include="..\Board\NH3_0317.cpp" />
<ClCompile Include="..\Board\Pandora.cpp" />
<ClCompile Include="..\Core\Array.cpp" />
<ClCompile Include="..\Core\Buffer.cpp" />
<ClCompile Include="..\Core\ByteArray.cpp" />
<ClCompile Include="..\Core\DateTime.cpp" />
<ClCompile Include="..\Core\Delegate.cpp" />
<ClCompile Include="..\Core\Dictionary.cpp" />
<ClCompile Include="..\Core\Environment.cpp" />
<ClCompile Include="..\Core\List.cpp" />
<ClCompile Include="..\Core\Queue.cpp" />
<ClCompile Include="..\Core\Random.cpp" />
<ClCompile Include="..\Core\Stream.cpp" />
<ClCompile Include="..\Core\String.cpp" />
<ClCompile Include="..\Core\TimeSpan.cpp" />
<ClCompile Include="..\Core\Type.cpp" />
<ClCompile Include="..\Core\Version.cpp" />
<ClCompile Include="..\Device\ADC.cpp" />
<ClCompile Include="..\Device\CAN.cpp" />
<ClCompile Include="..\Device\DAC.cpp" />
<ClCompile Include="..\Device\DMA.cpp" />
<ClCompile Include="..\Device\Flash.cpp" />
<ClCompile Include="..\Device\I2C.cpp" />
<ClCompile Include="..\Device\Port.cpp" />
<ClCompile Include="..\Device\Power.cpp" />
<ClCompile Include="..\Device\Proxy.cpp" />
<ClCompile Include="..\Device\ProxyConfig.cpp" />
<ClCompile Include="..\Device\Pwm.cpp" />
<ClCompile Include="..\Device\RTC.cpp" />
<ClCompile Include="..\Device\SerialPort.cpp" />
<ClCompile Include="..\Device\Spi.cpp" />
<ClCompile Include="..\Device\Timer.cpp" />
<ClCompile Include="..\Device\UTPort.cpp" />
<ClCompile Include="..\Device\WatchDog.cpp" />
<ClCompile Include="..\Drivers\74HC165.cpp" />
<ClCompile Include="..\Drivers\74HC165Monitor.cpp" />
<ClCompile Include="..\Drivers\AT24CXX.cpp" />
<ClCompile Include="..\Drivers\AT45DB.cpp" />
<ClCompile Include="..\Drivers\BH1750.cpp" />
<ClCompile Include="..\Drivers\BufferPort.cpp" />
<ClCompile Include="..\Drivers\DHT11.cpp" />
<ClCompile Include="..\Drivers\Enc28j60.cpp" />
<ClCompile Include="..\Drivers\HX711.cpp" />
<ClCompile Include="..\Drivers\JTW8953.cpp" />
<ClCompile Include="..\Drivers\NRF24L01.cpp" />
<ClCompile Include="..\Drivers\PMS5003.cpp" />
<ClCompile Include="..\Drivers\SHT30.cpp" />
<ClCompile Include="..\Drivers\ShunCom.cpp" />
<ClCompile Include="..\Drivers\Sim900A.cpp" />
<ClCompile Include="..\Drivers\UBlox.cpp" />
<ClCompile Include="..\Drivers\W5500.cpp" />
<ClCompile Include="..\Kernel\Heap.cpp" />
<ClCompile Include="..\Kernel\Interrupt.cpp" />
<ClCompile Include="..\Kernel\Sys.cpp" />
<ClCompile Include="..\Kernel\Task.cpp" />
<ClCompile Include="..\Kernel\Thread.cpp" />
<ClCompile Include="..\Kernel\Time.cpp" />
<ClCompile Include="..\Kernel\WaitHandle.cpp" />
<ClCompile Include="..\Message\BinaryPair.cpp" />
<ClCompile Include="..\Message\Controller.cpp" />
<ClCompile Include="..\Message\DataStore.cpp" />
<ClCompile Include="..\Message\Json.cpp" />
<ClCompile Include="..\Message\Message.cpp" />
<ClCompile Include="..\Message\MessageBase.cpp" />
<ClCompile Include="..\Message\Pair.cpp" />
<ClCompile Include="..\Message\ProxyFactory.cpp" />
<ClCompile Include="..\Message\UTPacket.cpp" />
<ClCompile Include="..\Message\WeakStore.cpp" />
<ClCompile Include="..\Net\Blu40.cpp" />
<ClCompile Include="..\Net\Dhcp.cpp" />
<ClCompile Include="..\Net\DNS.cpp" />
<ClCompile Include="..\Net\IPAddress.cpp" />
<ClCompile Include="..\Net\IPEndPoint.cpp" />
<ClCompile Include="..\Net\ITransport.cpp" />
<ClCompile Include="..\Net\MacAddress.cpp" />
<ClCompile Include="..\Net\NetUri.cpp" />
<ClCompile Include="..\Net\NetworkInterface.cpp" />
<ClCompile Include="..\Net\Socket.cpp" />
<ClCompile Include="..\Net\Zigbee.cpp" />
<ClCompile Include="..\Security\AES.cpp" />
<ClCompile Include="..\Security\Crc.cpp" />
<ClCompile Include="..\Security\Crc16.cpp" />
<ClCompile Include="..\Security\MD5.cpp" />
<ClCompile Include="..\Security\RC4.cpp" />
<ClCompile Include="..\Security\RC6.cpp" />
<ClCompile Include="..\Security\RSA.cpp" />
<ClCompile Include="..\Storage\Storage.cpp" />
<ClCompile Include="..\TinyNet\DataMessage.cpp" />
<ClCompile Include="..\TinyNet\JoinMessage.cpp" />
<ClCompile Include="..\TinyNet\PingMessage.cpp" />
<ClCompile Include="..\TinyNet\Tiny.cpp" />
<ClCompile Include="..\TinyNet\TinyClient.cpp" />
<ClCompile Include="..\TinyNet\TinyConfig.cpp" />
<ClCompile Include="..\TinyNet\TinyController.cpp" />
<ClCompile Include="..\TinyNet\TinyMessage.cpp" />
<ClCompile Include="..\TinyNet\TinyServer.cpp" />
<ClCompile Include="..\TokenNet\Device.cpp" />
<ClCompile Include="..\TokenNet\DeviceBody.cpp" />
<ClCompile Include="..\TokenNet\DeviceMessage.cpp" />
<ClCompile Include="..\TokenNet\DevicesManagement.cpp" />
<ClCompile Include="..\TokenNet\ErrorMessage.cpp" />
<ClCompile Include="..\TokenNet\Gateway.cpp" />
<ClCompile Include="..\TokenNet\HelloMessage.cpp" />
<ClCompile Include="..\TokenNet\LoginMessage.cpp" />
<ClCompile Include="..\TokenNet\RegisterMessage.cpp" />
<ClCompile Include="..\TokenNet\Token.cpp" />
<ClCompile Include="..\TokenNet\TokenClient.cpp" />
<ClCompile Include="..\TokenNet\TokenConfig.cpp" />
<ClCompile Include="..\TokenNet\TokenController.cpp" />
<ClCompile Include="..\TokenNet\TokenDataMessage.cpp" />
<ClCompile Include="..\TokenNet\TokenDevice.cpp" />
<ClCompile Include="..\TokenNet\TokenMessage.cpp" />
<ClCompile Include="..\TokenNet\TokenPingMessage.cpp" />
<ClCompile Include="..\TokenNet\TokenSession.cpp" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{6C0D43A8-8411-48F3-989E-51C5379A5563}</ProjectGuid>
<RootNamespace>SmartOS</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="PropertySheet.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="PropertySheet.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<IncludePath>..\;$(IncludePath)</IncludePath>
<TargetExt>.lib</TargetExt>
<OutDir>$(SolutionDir)..\</OutDir>
<TargetName>SmartOS_x86D</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<IncludePath>..\;$(IncludePath)</IncludePath>
<TargetExt>.lib</TargetExt>
<OutDir>$(SolutionDir)..\</OutDir>
<TargetName>SmartOS_x86</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -1,100 +1,466 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="App">
<UniqueIdentifier>{68cafcf9-0446-45fb-9ba0-e29094e97816}</UniqueIdentifier>
</Filter>
<Filter Include="Board">
<UniqueIdentifier>{55eaf1b2-508a-4bdb-8dff-4e99c96e458f}</UniqueIdentifier>
</Filter>
<Filter Include="Core">
<UniqueIdentifier>{da241b09-cddc-414b-a87a-9a22187f53b9}</UniqueIdentifier>
</Filter>
<Filter Include="Device">
<UniqueIdentifier>{ce8de3bb-b0e4-4d24-8899-96ed1dafc5c6}</UniqueIdentifier>
</Filter>
<Filter Include="Drivers">
<UniqueIdentifier>{ac8cd3cc-8f65-45e0-8b86-0cdb78b4bfdf}</UniqueIdentifier>
</Filter>
<Filter Include="Kernel">
<UniqueIdentifier>{1ec82080-7ddc-43ec-9171-4716b5a73bba}</UniqueIdentifier>
</Filter>
<Filter Include="Message">
<UniqueIdentifier>{50d9af31-12f9-4fe9-869c-a86e9db183bf}</UniqueIdentifier>
</Filter>
<Filter Include="Net">
<UniqueIdentifier>{9ce7a428-911e-41f6-9064-e5ddaa413bcb}</UniqueIdentifier>
</Filter>
<Filter Include="Platform">
<UniqueIdentifier>{ef28b1f5-18bf-4969-a50f-b7c0e0ab52ab}</UniqueIdentifier>
</Filter>
<Filter Include="Security">
<UniqueIdentifier>{46d87250-c97b-4733-834b-78c8cd385591}</UniqueIdentifier>
</Filter>
<Filter Include="Storage">
<UniqueIdentifier>{78919a0d-baca-4dc9-bb17-b451e78ef98a}</UniqueIdentifier>
</Filter>
<Filter Include="Test">
<UniqueIdentifier>{571c34d7-b9f1-4707-9a68-c4927ee96dc8}</UniqueIdentifier>
</Filter>
<Filter Include="TinyIP">
<UniqueIdentifier>{06ee290f-07a2-4f74-ba74-6af3b238d0db}</UniqueIdentifier>
</Filter>
<Filter Include="TinyNet">
<UniqueIdentifier>{8217de0f-89b4-4070-951a-ac0c7cb119f9}</UniqueIdentifier>
</Filter>
<Filter Include="TokenNet">
<UniqueIdentifier>{05569624-5acc-4f56-96eb-8f0c4aefd004}</UniqueIdentifier>
</Filter>
<Filter Include="Drivers\Esp8266">
<UniqueIdentifier>{5148c153-2531-43dd-b3d0-c6e56c956568}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\Core\Type.cpp">
<Filter>Core</Filter>
</ClCompile>
<ClCompile Include="..\Core\Version.cpp">
<Filter>Core</Filter>
</ClCompile>
<ClCompile Include="..\Core\Array.cpp">
<Filter>Core</Filter>
</ClCompile>
<ClCompile Include="..\Core\Buffer.cpp">
<Filter>Core</Filter>
</ClCompile>
<ClCompile Include="..\Core\ByteArray.cpp">
<Filter>Core</Filter>
</ClCompile>
<ClCompile Include="..\Core\DateTime.cpp">
<Filter>Core</Filter>
</ClCompile>
<ClCompile Include="..\Core\Delegate.cpp">
<Filter>Core</Filter>
</ClCompile>
<ClCompile Include="..\Core\Dictionary.cpp">
<Filter>Core</Filter>
</ClCompile>
<ClCompile Include="..\Core\Environment.cpp">
<Filter>Core</Filter>
</ClCompile>
<ClCompile Include="..\Core\List.cpp">
<Filter>Core</Filter>
</ClCompile>
<ClCompile Include="..\Core\Queue.cpp">
<Filter>Core</Filter>
</ClCompile>
<ClCompile Include="..\Core\Random.cpp">
<Filter>Core</Filter>
</ClCompile>
<ClCompile Include="..\Core\Stream.cpp">
<Filter>Core</Filter>
</ClCompile>
<ClCompile Include="..\Core\String.cpp">
<Filter>Core</Filter>
</ClCompile>
<ClCompile Include="..\Core\TimeSpan.cpp">
<Filter>Core</Filter>
</ClCompile>
</ItemGroup>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="App">
<UniqueIdentifier>{68cafcf9-0446-45fb-9ba0-e29094e97816}</UniqueIdentifier>
</Filter>
<Filter Include="Board">
<UniqueIdentifier>{55eaf1b2-508a-4bdb-8dff-4e99c96e458f}</UniqueIdentifier>
</Filter>
<Filter Include="Core">
<UniqueIdentifier>{da241b09-cddc-414b-a87a-9a22187f53b9}</UniqueIdentifier>
</Filter>
<Filter Include="Device">
<UniqueIdentifier>{ce8de3bb-b0e4-4d24-8899-96ed1dafc5c6}</UniqueIdentifier>
</Filter>
<Filter Include="Drivers">
<UniqueIdentifier>{ac8cd3cc-8f65-45e0-8b86-0cdb78b4bfdf}</UniqueIdentifier>
</Filter>
<Filter Include="Kernel">
<UniqueIdentifier>{1ec82080-7ddc-43ec-9171-4716b5a73bba}</UniqueIdentifier>
</Filter>
<Filter Include="Message">
<UniqueIdentifier>{50d9af31-12f9-4fe9-869c-a86e9db183bf}</UniqueIdentifier>
</Filter>
<Filter Include="Net">
<UniqueIdentifier>{9ce7a428-911e-41f6-9064-e5ddaa413bcb}</UniqueIdentifier>
</Filter>
<Filter Include="Platform">
<UniqueIdentifier>{ef28b1f5-18bf-4969-a50f-b7c0e0ab52ab}</UniqueIdentifier>
</Filter>
<Filter Include="Security">
<UniqueIdentifier>{46d87250-c97b-4733-834b-78c8cd385591}</UniqueIdentifier>
</Filter>
<Filter Include="Storage">
<UniqueIdentifier>{78919a0d-baca-4dc9-bb17-b451e78ef98a}</UniqueIdentifier>
</Filter>
<Filter Include="Test">
<UniqueIdentifier>{571c34d7-b9f1-4707-9a68-c4927ee96dc8}</UniqueIdentifier>
</Filter>
<Filter Include="TinyIP">
<UniqueIdentifier>{06ee290f-07a2-4f74-ba74-6af3b238d0db}</UniqueIdentifier>
</Filter>
<Filter Include="TinyNet">
<UniqueIdentifier>{8217de0f-89b4-4070-951a-ac0c7cb119f9}</UniqueIdentifier>
</Filter>
<Filter Include="TokenNet">
<UniqueIdentifier>{05569624-5acc-4f56-96eb-8f0c4aefd004}</UniqueIdentifier>
</Filter>
<Filter Include="Drivers\Esp8266">
<UniqueIdentifier>{5148c153-2531-43dd-b3d0-c6e56c956568}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\Core\Type.cpp">
<Filter>Core</Filter>
</ClCompile>
<ClCompile Include="..\Core\Version.cpp">
<Filter>Core</Filter>
</ClCompile>
<ClCompile Include="..\Core\Array.cpp">
<Filter>Core</Filter>
</ClCompile>
<ClCompile Include="..\Core\Buffer.cpp">
<Filter>Core</Filter>
</ClCompile>
<ClCompile Include="..\Core\ByteArray.cpp">
<Filter>Core</Filter>
</ClCompile>
<ClCompile Include="..\Core\DateTime.cpp">
<Filter>Core</Filter>
</ClCompile>
<ClCompile Include="..\Core\Delegate.cpp">
<Filter>Core</Filter>
</ClCompile>
<ClCompile Include="..\Core\Dictionary.cpp">
<Filter>Core</Filter>
</ClCompile>
<ClCompile Include="..\Core\Environment.cpp">
<Filter>Core</Filter>
</ClCompile>
<ClCompile Include="..\Core\List.cpp">
<Filter>Core</Filter>
</ClCompile>
<ClCompile Include="..\Core\Queue.cpp">
<Filter>Core</Filter>
</ClCompile>
<ClCompile Include="..\Core\Random.cpp">
<Filter>Core</Filter>
</ClCompile>
<ClCompile Include="..\Core\Stream.cpp">
<Filter>Core</Filter>
</ClCompile>
<ClCompile Include="..\Core\String.cpp">
<Filter>Core</Filter>
</ClCompile>
<ClCompile Include="..\Core\TimeSpan.cpp">
<Filter>Core</Filter>
</ClCompile>
<ClCompile Include="..\App\Sound.cpp">
<Filter>App</Filter>
</ClCompile>
<ClCompile Include="..\App\Alarm.cpp">
<Filter>App</Filter>
</ClCompile>
<ClCompile Include="..\App\BlinkPort.cpp">
<Filter>App</Filter>
</ClCompile>
<ClCompile Include="..\App\Button.cpp">
<Filter>App</Filter>
</ClCompile>
<ClCompile Include="..\App\Button_GrayLevel.cpp">
<Filter>App</Filter>
</ClCompile>
<ClCompile Include="..\App\Button_magnetic.cpp">
<Filter>App</Filter>
</ClCompile>
<ClCompile Include="..\App\CommandPort.cpp">
<Filter>App</Filter>
</ClCompile>
<ClCompile Include="..\App\Dimmer.cpp">
<Filter>App</Filter>
</ClCompile>
<ClCompile Include="..\App\FlushPort.cpp">
<Filter>App</Filter>
</ClCompile>
<ClCompile Include="..\App\IR.cpp">
<Filter>App</Filter>
</ClCompile>
<ClCompile Include="..\App\IRcoding.cpp">
<Filter>App</Filter>
</ClCompile>
<ClCompile Include="..\App\PowerUps.cpp">
<Filter>App</Filter>
</ClCompile>
<ClCompile Include="..\App\PulsePort.cpp">
<Filter>App</Filter>
</ClCompile>
<ClCompile Include="..\App\Raster.cpp">
<Filter>App</Filter>
</ClCompile>
<ClCompile Include="..\App\Sensor.cpp">
<Filter>App</Filter>
</ClCompile>
<ClCompile Include="..\Board\Pandora.cpp">
<Filter>Board</Filter>
</ClCompile>
<ClCompile Include="..\Board\AP0103.cpp">
<Filter>Board</Filter>
</ClCompile>
<ClCompile Include="..\Board\AP0104.cpp">
<Filter>Board</Filter>
</ClCompile>
<ClCompile Include="..\Board\AP0801.cpp">
<Filter>Board</Filter>
</ClCompile>
<ClCompile Include="..\Board\AP0802.cpp">
<Filter>Board</Filter>
</ClCompile>
<ClCompile Include="..\Board\BaseBoard.cpp">
<Filter>Board</Filter>
</ClCompile>
<ClCompile Include="..\Board\IOK026X.cpp">
<Filter>Board</Filter>
</ClCompile>
<ClCompile Include="..\Board\IOK027X.cpp">
<Filter>Board</Filter>
</ClCompile>
<ClCompile Include="..\Board\IOK0612.cpp">
<Filter>Board</Filter>
</ClCompile>
<ClCompile Include="..\Board\NH3_0317.cpp">
<Filter>Board</Filter>
</ClCompile>
<ClCompile Include="..\Device\Timer.cpp">
<Filter>Device</Filter>
</ClCompile>
<ClCompile Include="..\Device\UTPort.cpp">
<Filter>Device</Filter>
</ClCompile>
<ClCompile Include="..\Device\WatchDog.cpp">
<Filter>Device</Filter>
</ClCompile>
<ClCompile Include="..\Device\ADC.cpp">
<Filter>Device</Filter>
</ClCompile>
<ClCompile Include="..\Device\CAN.cpp">
<Filter>Device</Filter>
</ClCompile>
<ClCompile Include="..\Device\DAC.cpp">
<Filter>Device</Filter>
</ClCompile>
<ClCompile Include="..\Device\DMA.cpp">
<Filter>Device</Filter>
</ClCompile>
<ClCompile Include="..\Device\Flash.cpp">
<Filter>Device</Filter>
</ClCompile>
<ClCompile Include="..\Device\I2C.cpp">
<Filter>Device</Filter>
</ClCompile>
<ClCompile Include="..\Device\Port.cpp">
<Filter>Device</Filter>
</ClCompile>
<ClCompile Include="..\Device\Power.cpp">
<Filter>Device</Filter>
</ClCompile>
<ClCompile Include="..\Device\Proxy.cpp">
<Filter>Device</Filter>
</ClCompile>
<ClCompile Include="..\Device\ProxyConfig.cpp">
<Filter>Device</Filter>
</ClCompile>
<ClCompile Include="..\Device\Pwm.cpp">
<Filter>Device</Filter>
</ClCompile>
<ClCompile Include="..\Device\RTC.cpp">
<Filter>Device</Filter>
</ClCompile>
<ClCompile Include="..\Device\SerialPort.cpp">
<Filter>Device</Filter>
</ClCompile>
<ClCompile Include="..\Device\Spi.cpp">
<Filter>Device</Filter>
</ClCompile>
<ClCompile Include="..\Drivers\ShunCom.cpp">
<Filter>Drivers</Filter>
</ClCompile>
<ClCompile Include="..\Drivers\Sim900A.cpp">
<Filter>Drivers</Filter>
</ClCompile>
<ClCompile Include="..\Drivers\UBlox.cpp">
<Filter>Drivers</Filter>
</ClCompile>
<ClCompile Include="..\Drivers\W5500.cpp">
<Filter>Drivers</Filter>
</ClCompile>
<ClCompile Include="..\Drivers\74HC165.cpp">
<Filter>Drivers</Filter>
</ClCompile>
<ClCompile Include="..\Drivers\74HC165Monitor.cpp">
<Filter>Drivers</Filter>
</ClCompile>
<ClCompile Include="..\Drivers\AT24CXX.cpp">
<Filter>Drivers</Filter>
</ClCompile>
<ClCompile Include="..\Drivers\AT45DB.cpp">
<Filter>Drivers</Filter>
</ClCompile>
<ClCompile Include="..\Drivers\BH1750.cpp">
<Filter>Drivers</Filter>
</ClCompile>
<ClCompile Include="..\Drivers\BufferPort.cpp">
<Filter>Drivers</Filter>
</ClCompile>
<ClCompile Include="..\Drivers\DHT11.cpp">
<Filter>Drivers</Filter>
</ClCompile>
<ClCompile Include="..\Drivers\Enc28j60.cpp">
<Filter>Drivers</Filter>
</ClCompile>
<ClCompile Include="..\Drivers\HX711.cpp">
<Filter>Drivers</Filter>
</ClCompile>
<ClCompile Include="..\Drivers\JTW8953.cpp">
<Filter>Drivers</Filter>
</ClCompile>
<ClCompile Include="..\Drivers\NRF24L01.cpp">
<Filter>Drivers</Filter>
</ClCompile>
<ClCompile Include="..\Drivers\PMS5003.cpp">
<Filter>Drivers</Filter>
</ClCompile>
<ClCompile Include="..\Drivers\SHT30.cpp">
<Filter>Drivers</Filter>
</ClCompile>
<ClCompile Include="..\Kernel\WaitHandle.cpp">
<Filter>Kernel</Filter>
</ClCompile>
<ClCompile Include="..\Kernel\Heap.cpp">
<Filter>Kernel</Filter>
</ClCompile>
<ClCompile Include="..\Kernel\Interrupt.cpp">
<Filter>Kernel</Filter>
</ClCompile>
<ClCompile Include="..\Kernel\Sys.cpp">
<Filter>Kernel</Filter>
</ClCompile>
<ClCompile Include="..\Kernel\Task.cpp">
<Filter>Kernel</Filter>
</ClCompile>
<ClCompile Include="..\Kernel\Thread.cpp">
<Filter>Kernel</Filter>
</ClCompile>
<ClCompile Include="..\Kernel\Time.cpp">
<Filter>Kernel</Filter>
</ClCompile>
<ClCompile Include="..\Message\Pair.cpp">
<Filter>Message</Filter>
</ClCompile>
<ClCompile Include="..\Message\ProxyFactory.cpp">
<Filter>Message</Filter>
</ClCompile>
<ClCompile Include="..\Message\UTPacket.cpp">
<Filter>Message</Filter>
</ClCompile>
<ClCompile Include="..\Message\WeakStore.cpp">
<Filter>Message</Filter>
</ClCompile>
<ClCompile Include="..\Message\BinaryPair.cpp">
<Filter>Message</Filter>
</ClCompile>
<ClCompile Include="..\Message\Controller.cpp">
<Filter>Message</Filter>
</ClCompile>
<ClCompile Include="..\Message\DataStore.cpp">
<Filter>Message</Filter>
</ClCompile>
<ClCompile Include="..\Message\Json.cpp">
<Filter>Message</Filter>
</ClCompile>
<ClCompile Include="..\Message\Message.cpp">
<Filter>Message</Filter>
</ClCompile>
<ClCompile Include="..\Message\MessageBase.cpp">
<Filter>Message</Filter>
</ClCompile>
<ClCompile Include="..\Net\MacAddress.cpp">
<Filter>Net</Filter>
</ClCompile>
<ClCompile Include="..\Net\NetUri.cpp">
<Filter>Net</Filter>
</ClCompile>
<ClCompile Include="..\Net\NetworkInterface.cpp">
<Filter>Net</Filter>
</ClCompile>
<ClCompile Include="..\Net\Socket.cpp">
<Filter>Net</Filter>
</ClCompile>
<ClCompile Include="..\Net\Zigbee.cpp">
<Filter>Net</Filter>
</ClCompile>
<ClCompile Include="..\Net\Blu40.cpp">
<Filter>Net</Filter>
</ClCompile>
<ClCompile Include="..\Net\Dhcp.cpp">
<Filter>Net</Filter>
</ClCompile>
<ClCompile Include="..\Net\DNS.cpp">
<Filter>Net</Filter>
</ClCompile>
<ClCompile Include="..\Net\IPAddress.cpp">
<Filter>Net</Filter>
</ClCompile>
<ClCompile Include="..\Net\IPEndPoint.cpp">
<Filter>Net</Filter>
</ClCompile>
<ClCompile Include="..\Net\ITransport.cpp">
<Filter>Net</Filter>
</ClCompile>
<ClCompile Include="..\Security\RSA.cpp">
<Filter>Security</Filter>
</ClCompile>
<ClCompile Include="..\Security\AES.cpp">
<Filter>Security</Filter>
</ClCompile>
<ClCompile Include="..\Security\Crc.cpp">
<Filter>Security</Filter>
</ClCompile>
<ClCompile Include="..\Security\Crc16.cpp">
<Filter>Security</Filter>
</ClCompile>
<ClCompile Include="..\Security\MD5.cpp">
<Filter>Security</Filter>
</ClCompile>
<ClCompile Include="..\Security\RC4.cpp">
<Filter>Security</Filter>
</ClCompile>
<ClCompile Include="..\Security\RC6.cpp">
<Filter>Security</Filter>
</ClCompile>
<ClCompile Include="..\Storage\Storage.cpp">
<Filter>Storage</Filter>
</ClCompile>
<ClCompile Include="..\TinyNet\TinyController.cpp">
<Filter>TinyNet</Filter>
</ClCompile>
<ClCompile Include="..\TinyNet\TinyMessage.cpp">
<Filter>TinyNet</Filter>
</ClCompile>
<ClCompile Include="..\TinyNet\TinyServer.cpp">
<Filter>TinyNet</Filter>
</ClCompile>
<ClCompile Include="..\TinyNet\DataMessage.cpp">
<Filter>TinyNet</Filter>
</ClCompile>
<ClCompile Include="..\TinyNet\JoinMessage.cpp">
<Filter>TinyNet</Filter>
</ClCompile>
<ClCompile Include="..\TinyNet\PingMessage.cpp">
<Filter>TinyNet</Filter>
</ClCompile>
<ClCompile Include="..\TinyNet\Tiny.cpp">
<Filter>TinyNet</Filter>
</ClCompile>
<ClCompile Include="..\TinyNet\TinyClient.cpp">
<Filter>TinyNet</Filter>
</ClCompile>
<ClCompile Include="..\TinyNet\TinyConfig.cpp">
<Filter>TinyNet</Filter>
</ClCompile>
<ClCompile Include="..\TokenNet\TokenController.cpp">
<Filter>TokenNet</Filter>
</ClCompile>
<ClCompile Include="..\TokenNet\TokenDataMessage.cpp">
<Filter>TokenNet</Filter>
</ClCompile>
<ClCompile Include="..\TokenNet\TokenDevice.cpp">
<Filter>TokenNet</Filter>
</ClCompile>
<ClCompile Include="..\TokenNet\TokenMessage.cpp">
<Filter>TokenNet</Filter>
</ClCompile>
<ClCompile Include="..\TokenNet\TokenPingMessage.cpp">
<Filter>TokenNet</Filter>
</ClCompile>
<ClCompile Include="..\TokenNet\TokenSession.cpp">
<Filter>TokenNet</Filter>
</ClCompile>
<ClCompile Include="..\TokenNet\Device.cpp">
<Filter>TokenNet</Filter>
</ClCompile>
<ClCompile Include="..\TokenNet\DeviceBody.cpp">
<Filter>TokenNet</Filter>
</ClCompile>
<ClCompile Include="..\TokenNet\DeviceMessage.cpp">
<Filter>TokenNet</Filter>
</ClCompile>
<ClCompile Include="..\TokenNet\DevicesManagement.cpp">
<Filter>TokenNet</Filter>
</ClCompile>
<ClCompile Include="..\TokenNet\ErrorMessage.cpp">
<Filter>TokenNet</Filter>
</ClCompile>
<ClCompile Include="..\TokenNet\Gateway.cpp">
<Filter>TokenNet</Filter>
</ClCompile>
<ClCompile Include="..\TokenNet\HelloMessage.cpp">
<Filter>TokenNet</Filter>
</ClCompile>
<ClCompile Include="..\TokenNet\LoginMessage.cpp">
<Filter>TokenNet</Filter>
</ClCompile>
<ClCompile Include="..\TokenNet\RegisterMessage.cpp">
<Filter>TokenNet</Filter>
</ClCompile>
<ClCompile Include="..\TokenNet\Token.cpp">
<Filter>TokenNet</Filter>
</ClCompile>
<ClCompile Include="..\TokenNet\TokenClient.cpp">
<Filter>TokenNet</Filter>
</ClCompile>
<ClCompile Include="..\TokenNet\TokenConfig.cpp">
<Filter>TokenNet</Filter>
</ClCompile>
</ItemGroup>
</Project>