所有NULL更换为nullptr,GCC要求更严格。

Sys.h头文件不再包含string.h,禁止SmartOS除了Type和String以外的地方使用内存管理函数
This commit is contained in:
nnhy 2016-03-14 04:28:04 +00:00
parent 63263d7891
commit d1f6245d9b
90 changed files with 415 additions and 412 deletions

View File

@ -6,12 +6,12 @@ int Button::ACZeroAdjTime = 2300;
Button::Button()
{
Name = NULL;
Name = nullptr;
Index = 0;
_Value = false;
_Handler = NULL;
_Param = NULL;
_Handler = nullptr;
_Param = nullptr;
}
Button::~Button()
@ -67,8 +67,8 @@ void Button::Register(EventHandler handler, void* param)
}
else
{
_Handler = NULL;
_Param = NULL;
_Handler = nullptr;
_Param = nullptr;
}
}

View File

@ -35,7 +35,7 @@ public:
bool GetValue();
void SetValue(bool value);
void Register(EventHandler handler, void* param = NULL);
void Register(EventHandler handler, void* param = nullptr);
virtual int OnWrite(byte data);
virtual byte OnRead();

View File

@ -11,7 +11,7 @@
#define btn_printf(format, ...)
#endif
InputPort* Button_GrayLevel::ACZero = NULL;
InputPort* Button_GrayLevel::ACZero = nullptr;
byte Button_GrayLevel::OnGrayLevel = 0xFF; // 开灯时 led 灰度
byte Button_GrayLevel::OffGrayLevel = 0x00; // 关灯时 led 灰度
int Button_GrayLevel::ACZeroAdjTime=2300;
@ -19,21 +19,21 @@ int Button_GrayLevel::ACZeroAdjTime=2300;
Button_GrayLevel::Button_GrayLevel() : ByteDataPort()
{
#if DEBUG
Name = NULL;
Name = nullptr;
#endif
Index = 0;
_Value = false;
_Pwm = NULL;
_Pwm = nullptr;
_Channel = 0;
_Handler = NULL;
_Param = NULL;
_Handler = nullptr;
_Param = nullptr;
_tid = 0;
Next = 0xFF;
OnPress = NULL;
OnPress = nullptr;
}
void Button_GrayLevel::Set(Pin key, Pin relay, bool relayInvert)
@ -100,8 +100,8 @@ void Button_GrayLevel::Register(EventHandler handler, void* param)
}
else
{
_Handler = NULL;
_Param = NULL;
_Handler = nullptr;
_Param = nullptr;
}
}
@ -251,7 +251,7 @@ void Button_GrayLevel::InitZero(Pin zero, int us)
debug_printf("所有开关按钮准备就绪!\r\n\r\n");
Sys.AddTask(ACZeroReset, NULL, 60000, 60000, "定时过零");
Sys.AddTask(ACZeroReset, nullptr, 60000, 60000, "定时过零");
}
bool Button_GrayLevel::UpdateLevel(byte* level, Button_GrayLevel* btns, byte count)

View File

@ -43,7 +43,7 @@ public:
bool GetValue();
void SetValue(bool value);
void RenewGrayLevel();
void Register(EventHandler handler, void* param = NULL);
void Register(EventHandler handler, void* param = nullptr);
virtual int OnWrite(byte data);
virtual byte OnRead();

View File

@ -2,15 +2,15 @@
void Button_magnetic::Init()
{
Key = NULL;
Led = NULL;
Relay_pack1 = NULL;
Relay_pack2 = NULL;
Key = nullptr;
Led = nullptr;
Relay_pack1 = nullptr;
Relay_pack2 = nullptr;
Name = NULL;
Name = nullptr;
_Value = false;
_Handler = NULL;
_Param = NULL;
_Handler = nullptr;
_Param = nullptr;
}
Button_magnetic::Button_magnetic(Pin key, Pin led, Pin relay_pin1, Pin relay_pin2)
@ -46,16 +46,16 @@ Button_magnetic::Button_magnetic(Pin key, Pin led, bool ledInvert, Pin relay_pin
Button_magnetic::~Button_magnetic()
{
if(Key) delete Key;
Key = NULL;
Key = nullptr;
if(Led) delete Led;
Led = NULL;
Led = nullptr;
if(Relay_pack1) delete Relay_pack1;
Relay_pack1 = NULL;
Relay_pack1 = nullptr;
if(Relay_pack2) delete Relay_pack2;
Relay_pack2 = NULL;
Relay_pack2 = nullptr;
}
@ -85,8 +85,8 @@ void Button_magnetic::Register(EventHandler handler, void* param)
}
else
{
_Handler = NULL;
_Param = NULL;
_Handler = nullptr;
_Param = nullptr;
}
}

View File

@ -40,7 +40,7 @@ public:
bool GetValue();
void SetValue(bool value);
void Register(EventHandler handler, void* param = NULL);
void Register(EventHandler handler, void* param = nullptr);
private:
bool _Value; // 状态

View File

@ -18,7 +18,7 @@ public:
String Name; // 名称
#endif
CommandPort(OutputPort* port, byte* data = NULL);
CommandPort(OutputPort* port, byte* data = nullptr);
~CommandPort();
void Set(byte cmd); // 根据命令执行动作

View File

@ -4,7 +4,7 @@
FlushPort::FlushPort()
{
_tid = 0;
Port = NULL;
Port = nullptr;
Fast = 50;
Slow = 1000;
Count = 0;

View File

@ -35,7 +35,7 @@ typedef enum
}IRStat;
IRStat Stat;
ushort * SendP = NULL;
ushort * SendP = nullptr;
ushort SendIndex;
ushort SendBufLen;
bool ErrorIRQ;
@ -46,7 +46,7 @@ bool IR::Send(const Buffer& bs)
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
TIM_DeInit(TIM2);
if(_Tim == NULL)
if(_Tim == nullptr)
{
// RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
_Tim = Timer::Create(0x01); // 直接占用TIMER2
@ -83,11 +83,11 @@ bool IR::Send(const Buffer& bs)
while(!tw.Expired() && Stat != SendOver) Sys.Sleep(50);
// 结束 不论是超时还是发送结束都关闭pwm和定时器
//_Pwm->Close();
_Tim->Register(NULL,NULL);
_Tim->Register(nullptr,nullptr);
_Tim->Close();
// 清空使用的数据
SendIndex = 0;
SendP = NULL;
SendP = nullptr;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, DISABLE);
#endif
@ -148,14 +148,14 @@ int IR::Receive(Buffer& bs, int sTimeout)
uint DmaLen = bufLen/2 -1;
// 捕获引脚初始化
if(_Port == NULL)
if(_Port == nullptr)
{
_Port = new AlternatePort(); // 在括号内直接写引脚会初始化失败
_Port->Set(PA1);
_Port->Open();
_Port->AFConfig(Port::AF_2);
}
if(_Tim == NULL) _Tim = Timer::Create(0x01); // 直接占用TIMER2
if(_Tim == nullptr) _Tim = Timer::Create(0x01); // 直接占用TIMER2
// RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, DISABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);

View File

@ -22,9 +22,9 @@
class IR
{
private:
PWM* _Pwm = NULL;
Timer* _Tim = NULL;
AlternatePort * _Port = NULL;
PWM* _Pwm = nullptr;
Timer* _Tim = nullptr;
AlternatePort * _Port = nullptr;
public:
IR(PWM * pwm);

View File

@ -29,7 +29,7 @@ public:
// 此位置存在不对齐问题 需要注意
public:
IRcoding(Storage* flash = NULL, uint blockSize = 0);
IRcoding(Storage* flash = nullptr, uint blockSize = 0);
//~IRcoding();
// 设置配置区所在位置
void SetCfgAddr(uint addr);

View File

@ -2,17 +2,17 @@
void Sensor::Init()
{
Key = NULL;
Led = NULL;
Buzzer = NULL;
Pir=NULL; //门磁
Pir=NULL; //人体感应
Key = nullptr;
Led = nullptr;
Buzzer = nullptr;
Pir=nullptr; //门磁
Pir=nullptr; //人体感应
Name = NULL;
Name = nullptr;
Index = 0;
_Value = false;
_Handler = NULL;
_Param = NULL;
_Handler = nullptr;
_Param = nullptr;
}
Sensor::Sensor(Pin key, Pin led, Pin buzzer)
@ -42,13 +42,13 @@ Sensor::Sensor(Pin key, Pin led, bool ledInvert, Pin buzzer, bool buzzerInvert)
Sensor::~Sensor()
{
if(Key) delete Key;
Key = NULL;
Key = nullptr;
if(Led) delete Led;
Led = NULL;
Led = nullptr;
if(Mag) delete Mag;
Mag = NULL;
Mag = nullptr;
}
void Sensor::OnPress(InputPort* port, bool down, void* param)
@ -77,8 +77,8 @@ void Sensor::Register(EventHandler handler, void* param)
}
else
{
_Handler = NULL;
_Param = NULL;
_Handler = nullptr;
_Param = nullptr;
}
}

View File

@ -32,7 +32,7 @@ public:
bool GetValue();
void SetValue(bool value);
void Register(EventHandler handler, void* param = NULL);
void Register(EventHandler handler, void* param = nullptr);
private:

View File

@ -4,18 +4,18 @@
Music::Music(Timer* timer,OutputPort* pin)
{
Init();
if(timer!= NULL)
if(timer!= nullptr)
_timer = timer;
if(pin!= NULL)
if(pin!= nullptr)
_phonatePin = pin;
}
void Music::Init()
{
_tuneSet = NULL;
_tuneSet = nullptr;
_tuneNum = 0;
_timer = NULL;
_phonatePin = NULL;
_timer = nullptr;
_phonatePin = nullptr;
Sounding = false;
sound_cnt = 0;
music_beat = 0;
@ -30,22 +30,22 @@ void Music::Disposable()
delete(_timer);
}
if(_phonatePin)delete(_phonatePin);
_tuneSet = NULL;
_tuneSet = nullptr;
}
Music::~Music()
{
_tuneSet = NULL;
_tuneNum = NULL;
_tuneSet = nullptr;
_tuneNum = 0;
_timer->Close();
Sounding = false;
_timer = NULL;
Sounding = false;
_timer = nullptr;
}
void Music::Sound()
{
if(_timer!= NULL && _phonatePin != NULL && _tuneSet != NULL && _tuneNum != 0)
if(_timer!= nullptr && _phonatePin != nullptr && _tuneSet != nullptr && _tuneNum != 0)
{
_timer->SetFrequency(100000);
_timer->Register(TimerHander, this);
@ -66,13 +66,13 @@ void Music::Unsound()
Sounding = false;
}
void Music::SetTuneSet(const Tune* tune,int num)
void Music::SetTuneSet(const Tune* tune, int num)
{
if(Sounding) Unsound();
if(tune != NULL && num != NULL)
if(tune != nullptr && num != 0)
{
_tuneSet = (Tune*)tune;
_tuneSet = tune;
_tuneNum = num;
}
}
@ -84,7 +84,7 @@ bool Music::getStat()
void Music::TimerHander(void* sender,void* param)
{
if(param == NULL)return;
if(param == nullptr)return;
Music * music = (Music * )param;
music->phonate();
}

View File

@ -15,10 +15,10 @@ typedef struct // 单个音节
class Music
{
private:
Tune* _tuneSet; // 调子集合 就是曲子
int _tuneNum; // 有多少个调子
Timer* _timer; // 定时器
OutputPort* _phonatePin; // 输出引脚
const Tune* _tuneSet; // 调子集合 就是曲子
int _tuneNum; // 有多少个调子
Timer* _timer; // 定时器
OutputPort* _phonatePin; // 输出引脚
bool Sounding; // 作为判断的依据 最好只有Get 没有Set
public:

4
CAN.h
View File

@ -26,9 +26,9 @@ public:
virtual ~CAN()
{
if(_TxMsg) delete _TxMsg;
_TxMsg = NULL;
_TxMsg = nullptr;
if(_RxMsg) delete _RxMsg;
_RxMsg = NULL;
_RxMsg = nullptr;
}
void Send(byte* buf, uint len);

View File

@ -11,7 +11,7 @@
#define TS(name)
#endif
const Config* Config::Current = NULL;
const Config* Config::Current = nullptr;
/*================================ 配置块 ================================*/
@ -48,7 +48,7 @@ bool ConfigBlock::Valid() const
// 获取下一块。当前块必须有效,否则返回空,下一块不在乎有效无效
const ConfigBlock* ConfigBlock::Next() const
{
if(!Valid()) return NULL;
if(!Valid()) return nullptr;
// 确保数据部分2字节对齐便于Flash操作
uint s = (Size + 1) & 0xFFFE;
@ -75,7 +75,7 @@ uint ConfigBlock::CopyTo(Buffer& bs) const
// 构造一个新的配置块
bool ConfigBlock::Init(const char* name, const Buffer& bs)
{
if(name == NULL) return false;
if(name == nullptr) return false;
//assert_param2(name, "配置块名称不能为空");
TS("ConfigBlock::Init");
@ -173,16 +173,16 @@ const ConfigBlock* FindBlock(const Storage& st, uint addr, const char* name)
{
TS("Config::Find");
if(name == NULL) return NULL;
if(name == nullptr) return nullptr;
//assert_param2(name, "配置段名称不能为空");
if(!CheckSignature(st, addr, false)) return NULL;
if(!CheckSignature(st, addr, false)) return nullptr;
// 第一个配置块
auto cfg = (const ConfigBlock*)addr;
uint slen = strlen(name);
if(slen > sizeof(cfg->Name)) return NULL;
if(slen > sizeof(cfg->Name)) return nullptr;
//assert_param2(slen <= sizeof(cfg->Name), "配置段名称最大4个字符");
// 遍历链表,找到同名块
@ -193,7 +193,7 @@ const ConfigBlock* FindBlock(const Storage& st, uint addr, const char* name)
cfg = cfg->Next();
}
return NULL;
return nullptr;
}
// 创建一个指定大小的配置块。找一个满足该大小的空闲数据块,或者在最后划分一个
@ -201,7 +201,7 @@ const ConfigBlock* NewBlock(const Storage& st, uint addr, int size)
{
TS("Config::New");
if(!CheckSignature(st, addr, true)) return NULL;
if(!CheckSignature(st, addr, true)) return nullptr;
// 第一个配置块
auto cfg = (const ConfigBlock*)addr;
@ -233,7 +233,7 @@ const void* Config::New(int size) const
{
debug_printf("Config::New 0x%08X + %d + %d 配置区0x%08X, %d空间不足\r\n", cfg, sizeof(ConfigBlock), size, Address, Size);
return NULL;
return nullptr;
}
return cfg;
@ -245,7 +245,7 @@ bool Config::Remove(const char* name) const
//return Set(name, ByteArray(0));
TS("Config::Remove");
if(name == NULL) return NULL;
if(name == nullptr) return nullptr;
auto cfg = FindBlock(Device, Address, name);
if(!cfg) return false;
@ -262,13 +262,13 @@ const void* Config::Set(const char* name, const Buffer& bs) const
{
TS("Config::Set");
if(name == NULL) return NULL;
if(name == nullptr) return nullptr;
//assert_param2(name, "配置块名称不能为空");
//assert_param2(Device, "未指定配置段的存储设备");
auto cfg = FindBlock(Device, Address, name);
if(!cfg) cfg = NewBlock(Device, Address, bs.Length());
if(!cfg) return NULL;
if(!cfg) return nullptr;
// 重新搞一个配置头,使用新的数据去重新初始化
ConfigBlock header;
@ -283,7 +283,7 @@ bool Config::Get(const char* name, Buffer& bs) const
{
TS("Config::Get");
if(name == NULL) return false;
if(name == nullptr) return false;
//assert_param2(name, "配置块名称不能为空");
auto cfg = FindBlock(Device, Address, name);
@ -296,13 +296,13 @@ const void* Config::Get(const char* name) const
{
TS("Config::GetByName");
if(name == NULL) return NULL;
if(name == nullptr) return nullptr;
//assert_param2(name, "配置块名称不能为空");
auto cfg = FindBlock(Device, Address, name);
if(cfg && cfg->Size) return cfg->Data();
return NULL;
return nullptr;
}
/*// 获取配置数据,如果不存在则覆盖
@ -310,7 +310,7 @@ bool Config::GetOrSet(const char* name, Buffer& bs) const
{
TS("Config::GetOrSet");
if(name == NULL) return false;
if(name == nullptr) return false;
//assert_param2(name, "配置块名称不能为空");
// 输入数据已存在,直接返回
@ -351,12 +351,12 @@ ConfigBase::ConfigBase()
New = true;
_Name = NULL;
_Name = nullptr;
}
uint ConfigBase::Size() const
{
assert_param2(_End && _Start, "_Start & _End == NULL");
assert_param2(_End && _Start, "_Start & _End == nullptr");
return (uint)_End - (uint)_Start;
}

2
DMA.h
View File

@ -21,7 +21,7 @@ public:
bool WaitForStop(); // 停止
//typedef void (*TimerHandler)(Timer* tim, void* param);
//void Register(TimerHandler handler, void* param = NULL);
//void Register(TimerHandler handler, void* param = nullptr);
private:
//static void OnHandler(ushort num, void* param);

View File

@ -61,7 +61,7 @@ void* operator new(uint size)
size += 4 - (size & 0x03);
mem_printf("=> %d ", size);
}
void* p = NULL;
void* p = nullptr;
{
SmartIRQ irq;
p = malloc_(size);
@ -91,7 +91,7 @@ void* operator new[](uint size)
size += 4 - (size & 0x03);
mem_printf("=> %d ", size);
}
void* p = NULL;
void* p = nullptr;
{
SmartIRQ irq;
p = malloc_(size);

View File

@ -18,7 +18,7 @@
AT24CXX::AT24CXX()
{
IIC = NULL;
IIC = nullptr;
// 7位地址到了I2C那里需要左移1位
Address = 0x50;
@ -27,7 +27,7 @@ AT24CXX::AT24CXX()
AT24CXX::~AT24CXX()
{
delete IIC;
IIC = NULL;
IIC = nullptr;
}
void AT24CXX::Init()

View File

@ -39,7 +39,7 @@ AT45DB::AT45DB(Spi* spi)
AT45DB::~AT45DB()
{
if(_spi) delete _spi;
_spi = NULL;
_spi = nullptr;
}
// 设置操作地址

View File

@ -15,7 +15,7 @@
BH1750::BH1750()
{
IIC = NULL;
IIC = nullptr;
// 7位地址到了I2C那里需要左移1位
Address = 0x5C;
@ -25,7 +25,7 @@ BH1750::BH1750()
BH1750::~BH1750()
{
delete IIC;
IIC = NULL;
IIC = nullptr;
}
void BH1750::Init()

View File

@ -4,20 +4,20 @@
BufferPort::BufferPort() : Buf()
{
Name = "BufferPort";
Port = NULL;
Port = nullptr;
Com = COM_NONE;
Speed = 9600;
Opened = false;
Led = NULL;
Led = nullptr;
}
BufferPort::~BufferPort()
{
delete Port;
Port = NULL;
Port = nullptr;
}
bool BufferPort::Open()
@ -51,7 +51,7 @@ bool BufferPort::Open()
Port = sp;
}
if(!OnOpen(isNew) || Port == NULL) return false;
if(!OnOpen(isNew) || Port == nullptr) return false;
Port->Register(OnReceive, this);
@ -67,7 +67,7 @@ void BufferPort::Close()
if(Port)
{
Port->Close();
//Port->Register(NULL, NULL);
//Port->Register(nullptr, nullptr);
}
Opened = false;

View File

@ -335,7 +335,7 @@ Enc28j60::Enc28j60()
{
MaxSize = 1500;
_spi = NULL;
_spi = nullptr;
LastTime = Sys.Ms();
ResetPeriod = 6000;
@ -349,7 +349,7 @@ Enc28j60::Enc28j60()
Enc28j60::~Enc28j60()
{
delete _spi;
_spi = NULL;
_spi = nullptr;
Sys.RemoveTask(_ResetTask);
}

View File

@ -208,7 +208,7 @@ NRF24L01::NRF24L01()
{
MaxSize = 32;
_spi = NULL;
_spi = nullptr;
// 初始化地址
Buffer(Remote, ArrayLength(Remote)).Clear();
@ -226,8 +226,8 @@ NRF24L01::NRF24L01()
_tidOpen = 0;
_tidRecv = 0;
FixData = NULL;
Led = NULL;
FixData = nullptr;
Led = nullptr;
}
void NRF24L01::Init(Spi* spi, Pin ce, Pin irq, Pin power)
@ -263,13 +263,13 @@ NRF24L01::~NRF24L01()
Sys.RemoveTask(_tidOpen);
Sys.RemoveTask(_tidRecv);
Register(NULL);
Register(nullptr);
// 关闭电源
SetPowerMode(false);
delete _spi;
_spi = NULL;
_spi = nullptr;
}
byte NRF24L01::WriteBuf(byte reg, const Buffer& bs)

View File

@ -101,7 +101,7 @@ typedef union {
SHT30::SHT30()
{
IIC = NULL;
IIC = nullptr;
Address = 0x44; // ADDR=VSS
//Address = 0x45; // ADDR=VDD
@ -115,7 +115,7 @@ SHT30::~SHT30()
Pwr = false;
delete IIC;
IIC = NULL;
IIC = nullptr;
}
void SHT30::Init()

View File

@ -69,8 +69,8 @@ public:
ShunCom::ShunCom()
{
Led = NULL;
ExternalCfg = NULL;
Led = nullptr;
ExternalCfg = nullptr;
}
void ShunCom::Init(ITransport* port, Pin rst)

View File

@ -4,20 +4,20 @@
Sim900A::Sim900A()
{
Port = NULL;
Port = nullptr;
Com = COM_NONE;
Speed = 9600;
Inited = false;
APN = "CMNET";
Led = NULL;
Led = nullptr;
Domain = "pm25.peacemoon.cn";
}
Sim900A::~Sim900A()
{
delete Port;
Port = NULL;
Port = nullptr;
}
bool Sim900A::OnOpen()
@ -159,7 +159,7 @@ void Sim900A::Init(uint msTimeout)
SendDomain();
// 读取CONNECT OK
Inited = SendCmd(NULL, 5000);
Inited = SendCmd(nullptr, 5000);
//SendCmd("AT+CIPSHUT\r");
}
@ -197,7 +197,7 @@ bool Sim900A::Send(const Buffer& bs)
Port->Write(end);
// 把SEND OK读取回来
if(SendCmd(NULL))
if(SendCmd(nullptr))
{
//指示灯闪烁
//Led.Start();

View File

@ -4,7 +4,7 @@
UBlox::UBlox()
{
Name = "UBlox";
Header = NULL;
Header = nullptr;
}
bool UBlox::OnOpen(bool isNew)
@ -79,7 +79,7 @@ void UBlox::EnterConfig()
{
Open();
Port->Register(NULL, NULL);
Port->Register(nullptr, nullptr);
}
void UBlox::SaveConfig()
@ -131,7 +131,7 @@ void UBlox::OnReceive(const Buffer& bs, void* param)
if(Buf.Capacity() == 0) return;
// 必须美元开头,可以指定头部识别符
if(bs[0] == '$' && (Header == NULL || str.StartsWith(Header)))
if(bs[0] == '$' && (Header == nullptr || str.StartsWith(Header)))
{
//Buf.SetLength(bs.Length());
//Buf = bs;

View File

@ -211,8 +211,8 @@ W5500::~W5500()
// 初始化
void W5500::Init()
{
_spi = NULL;
Led = NULL;
_spi = nullptr;
Led = nullptr;
Buffer(_sockets, sizeof(_sockets)).Clear();
@ -645,7 +645,7 @@ byte W5500::GetSocket()
{
for(byte i = 0;i < 8;i ++)
{
if(_sockets[i] == NULL) return i;
if(_sockets[i] == nullptr) return i;
}
debug_printf("没有空余的Socket可用了 !\r\n");
@ -663,7 +663,7 @@ ISocket* W5500::CreateSocket(ProtocolType type)
return new UdpClient(*this);
default:
return NULL;
return nullptr;
}
}
@ -912,7 +912,7 @@ HardSocket::HardSocket(W5500& host, ProtocolType protocol) : _Host(host)
HardSocket::~HardSocket()
{
_Host.Register(Index, NULL);
_Host.Register(Index, nullptr);
}
byte HardSocket::ReadConfig() { return SocRegRead(CR); }
@ -1241,7 +1241,7 @@ void TcpClient::Init()
TcpClient::~TcpClient() //: ~HardSockets()
{
HardSocket::~HardSocket();
//HardSocket::~HardSocket();
Sys.RemoveTask(_tidRodyguard);
}
@ -1369,7 +1369,7 @@ void TcpClient::RaiseReceive()
if(size > 1500)return;
// 回调中断
OnReceive(bs, NULL);
OnReceive(bs, nullptr);
}
/****************************** UdpClient ************************************/

6
I2C.h
View File

@ -23,7 +23,7 @@ public:
virtual ~I2C();
virtual void SetPin(Pin scl, Pin sda) = 0;
virtual void GetPin(Pin* scl = NULL, Pin* sda = NULL) = 0;
virtual void GetPin(Pin* scl = nullptr, Pin* sda = nullptr) = 0;
virtual void Open(); // 打开设备
virtual void Close(); // 关闭设备
@ -85,7 +85,7 @@ public:
virtual ~HardI2C();
virtual void SetPin(Pin scl, Pin sda);
virtual void GetPin(Pin* scl = NULL, Pin* sda = NULL);
virtual void GetPin(Pin* scl = nullptr, Pin* sda = nullptr);
virtual void Start();
virtual void Stop();
@ -123,7 +123,7 @@ public:
virtual ~SoftI2C();
virtual void SetPin(Pin scl, Pin sda);
virtual void GetPin(Pin* scl = NULL, Pin* sda = NULL);
virtual void GetPin(Pin* scl = nullptr, Pin* sda = nullptr);
virtual void Start();
virtual void Stop();

View File

@ -371,7 +371,7 @@ bool Lock::Wait(int us)
#if DEBUG
static TArray<const char*, 0x40>* _TS = NULL;
static TArray<const char*, 0x40>* _TS = nullptr;
TraceStack::TraceStack(const char* name)
{
@ -384,7 +384,7 @@ TraceStack::TraceStack(const char* name)
TraceStack::~TraceStack()
{
// 清空最后一个项目,避免误判
(*_TS)[_TS->Length() - 1] = NULL;
(*_TS)[_TS->Length() - 1] = nullptr;
_TS->Pop();
}

View File

@ -28,7 +28,7 @@ public:
//~TInterrupt();
// 注册中断函数(中断号,函数,参数)
bool Activate(short irq, InterruptCallback isr, void* param = NULL);
bool Activate(short irq, InterruptCallback isr, void* param = nullptr);
// 解除中断注册
bool Deactivate(short irq);
// 开中断

View File

@ -11,12 +11,12 @@
// 构造控制器
Controller::Controller()
{
Port = NULL;
Port = nullptr;
MinSize = 0;
Opened = false;
Received = NULL;
Param = NULL;
Received = nullptr;
Param = nullptr;
}
Controller::~Controller()
@ -80,7 +80,7 @@ uint Controller::Dispatch(ITransport* port, Buffer& bs, void* param, void* param
len = ms.Remain();
#endif
// 如果不是有效数据包,则直接退出,避免产生死循环。当然,也可以逐字节移动测试,不过那样性能太差
if(!control->Dispatch(ms, NULL, param2))
if(!control->Dispatch(ms, nullptr, param2))
{
#if MSG_DEBUG
msg_printf("Controller::Error[%d] ", len);

View File

@ -106,7 +106,7 @@ DataStore::Area::Area()
{
Offset = 0;
Size = 0;
Hook = NULL;
Hook = nullptr;
}
bool DataStore::Area::Contain(uint offset, uint size)

View File

@ -5,10 +5,10 @@ Message::Message(byte code)
{
Code = code;
Length = 0;
Data = NULL;
Data = nullptr;
Reply = false;
Error = false;
State = NULL;
State = nullptr;
}
// 设置数据。

View File

@ -37,7 +37,7 @@ public:
// 设置数据
//void SetData(const void* buf, uint len, uint offset = 0);
void SetData(const Buffer& bs, uint offset = 0);
void SetError(byte errorCode, const char* msg = NULL);
void SetError(byte errorCode, const char* msg = nullptr);
// 负载数据转数据流
Stream ToStream();

View File

@ -15,7 +15,7 @@ public:
ByteArray Data; // 数据
// 初始化
WeakStore(const char* magic = NULL, byte* ptr = NULL, uint len = 0);
WeakStore(const char* magic = nullptr, byte* ptr = nullptr, uint len = 0);
// 检查并确保初始化,返回原来是否已初始化
bool Check();

View File

@ -10,7 +10,7 @@ Slave(ITransport* port)
Slave::~Slave()
{
delete _port;
_port = NULL;
_port = nullptr;
}
void Slave::OnReceive(ITransport* transport, byte* buf, uint len, void* param)

View File

@ -77,10 +77,10 @@ Blu40::Blu40(SerialPort *port,Pin rts ,/*Pin cts,*/ Pin sleep, OutputPort * rst
void Blu40::Init()
{
_rts = NULL;
//_cts = NULL;
_rts = nullptr;
//_cts = nullptr;
_baudRate = 0;
_sleep = NULL;
_sleep = nullptr;
}
void Blu40::Init(SerialPort *port ,Pin rts,/*Pin cts,*/Pin sleep, OutputPort * rst)
@ -88,7 +88,7 @@ void Blu40::Init(SerialPort *port ,Pin rts,/*Pin cts,*/Pin sleep, OutputPort * r
if(port) _port = port;
if(rts != P0)_rts = new OutputPort(rts); // 低电平有效
if(sleep!=P0)_sleep = new OutputPort(sleep);
if(_rts==NULL)debug_printf("关键引脚_rts不可忽略");
if(_rts==nullptr)debug_printf("关键引脚_rts不可忽略");
if(_sleep)*_sleep=false;
*_rts = true;
@ -241,7 +241,7 @@ bool Blu40::SetPID(ushort pid)
*_rts = false;
Sys.Delay(170);
_port->Write(Buffer((void*)AT_PID, sizeof(AT_PID)));
_port->Write(Buffer((byte*)pid, 2));
_port->Write(Buffer(&pid, 2));
bool ret = CheckSet();
*_rts = true;
return ret;

View File

@ -19,12 +19,12 @@ private:
public:
Blu40();
Blu40(SerialPort *port,Pin rts = P0 ,/*Pin cts = P0,*/Pin sleep=P0, OutputPort * rst = NULL);
Blu40(SerialPort *port,Pin rts = P0 ,/*Pin cts = P0,*/Pin sleep=P0, OutputPort * rst = nullptr);
virtual ~Blu40();
void Init();
void Init(SerialPort *port ,Pin rts = P0,/*Pin cts = P0,*/Pin sleep=P0, OutputPort * rst = NULL);
void Init(SerialPort *port ,Pin rts = P0,/*Pin cts = P0,*/Pin sleep=P0, OutputPort * rst = nullptr);
virtual void Register(TransportHandler handler, void* param = NULL);
virtual void Register(TransportHandler handler, void* param = nullptr);
virtual void Reset(void);
// 设置波特路

View File

@ -288,7 +288,7 @@ short dns_makequery(short op, const String& name, Buffer& bs)
const char* cp1 = strchr(dname, '.');
int len = 0;
if (cp1 != NULL)
if (cp1 != nullptr)
len = cp1 - dname; /* More to come */
else
len = dlen; /* Last component */
@ -302,7 +302,7 @@ short dns_makequery(short op, const String& name, Buffer& bs)
//strncpy((char *)cp, dname, len);
//cp += len;
ms.Write((const byte*)dname, 0, len);
if (cp1 == NULL)
if (cp1 == nullptr)
{
//*cp++ = 0; /* Last one; write null and finish */
// 最后一个,写空,完成
@ -367,7 +367,7 @@ IPAddress DNS::Query(const String& domain, int msTimeout)
break;
}
}
_Buffer = NULL;
_Buffer = nullptr;
return ip;
}

View File

@ -30,7 +30,7 @@ Dhcp::Dhcp(ISocketHost& host) : Host(host)
MaxTimes = 10;
ExpiredTime = 10000;
OnStop = NULL;
OnStop = nullptr;
taskID = 0;
//ITransport* port = (ITransport*)socket;
@ -192,7 +192,7 @@ void Dhcp::Stop()
Sys.Reset();
}
if(OnStop) OnStop(this, NULL);
if(OnStop) OnStop(this, nullptr);
}
void Dhcp::Loop(void* param)

View File

@ -177,7 +177,7 @@ typedef struct _TCP_HEADER
void Init(bool recursion = false)
{
Length = sizeof(this[0]);
Length = (byte)sizeof(this[0]);
reserved_1 = 0;
reserved_2 = 0;
//WindowSize = _REV16(8192);

View File

@ -11,8 +11,8 @@ ITransport::ITransport()
MinSize = 0;
MaxSize = 0;
_handler = NULL;
_param = NULL;
_handler = nullptr;
_param = nullptr;
}
// 析构函数确保关闭
@ -20,7 +20,7 @@ ITransport::~ITransport()
{
if(Opened) Close();
Register(NULL);
Register(nullptr);
}
// 打开传输口
@ -118,17 +118,17 @@ bool ITransport::OnWriteEx(const Buffer& bs, void* opt)
/******************************** PackPort ********************************/
PackPort::PackPort(){ Port = NULL; }
PackPort::PackPort(){ Port = nullptr; }
PackPort::~PackPort()
{
if(Port) Port->Register(NULL);
if(Port) Port->Register(nullptr);
delete Port;
}
void PackPort::Set(ITransport* port)
{
if(Port) Port->Register(NULL);
if(Port) Port->Register(nullptr);
Port = port;
if(Port)
{

View File

@ -41,7 +41,7 @@ public:
//Buffer Read();
// 注册回调函数
virtual void Register(TransportHandler handler, void* param = NULL);
virtual void Register(TransportHandler handler, void* param = nullptr);
#if DEBUG
virtual const char* ToString() const { return "ITransport"; }
@ -57,7 +57,7 @@ protected:
virtual uint OnRead(Buffer& bs) = 0;
// 是否有回调函数
bool HasHandler() { return _handler != NULL; }
bool HasHandler() { return _handler != nullptr; }
// 引发数据到达事件
virtual uint OnReceive(Buffer& bs, void* param);

View File

@ -319,5 +319,5 @@ bool ISocketHost::SaveConfig()
/*ISocket* ISocketHost::CreateSocket(ProtocolType type)
{
return NULL;
return nullptr;
}*/

View File

@ -2,7 +2,7 @@
Zigbee::Zigbee()
{
Set(NULL);
Set(nullptr);
}
Zigbee::Zigbee(ITransport* port, Pin rst)

View File

@ -27,7 +27,7 @@ _force_inline byte GroupToIndex(GPIO_TypeDef* group) { return (byte)(((int)group
Port::Port()
{
_Pin = P0;
Group = NULL;
Group = nullptr;
Mask = 0;
Opened = false;
}
@ -73,7 +73,7 @@ Port& Port::Set(Pin pin)
}
else
{
Group = NULL;
Group = nullptr;
Mask = 0;
}
@ -84,14 +84,14 @@ bool Port::Empty() const
{
if(_Pin != P0) return false;
if(Group == NULL || Mask == 0) return true;
if(Group == nullptr || Mask == 0) return true;
return false;
}
void Port::Clear()
{
Group = NULL;
Group = nullptr;
_Pin = P0;
Mask = 0;
}
@ -499,8 +499,8 @@ InputPort::InputPort(Pin pin, bool floating, PuPd pull) : Port()
HardEvent = false; */
_taskInput = 0;
Handler = NULL;
Param = NULL;
Handler = nullptr;
Param = nullptr;
_Value = 0;
_PressStart = 0;
@ -775,7 +775,7 @@ bool IsOnlyExOfInt(const InputPort* pt, int idx)
}
#endif
for(int i = s; i <= e; i++)
if(States[i].Port != NULL && States[i].Port != pt) return false;
if(States[i].Port != nullptr && States[i].Port != pt) return false;
return true;
}
@ -789,7 +789,7 @@ void InputPort::OnClose()
auto st = &States[idx];
if(st->Port == this)
{
st->Port = NULL;
st->Port = nullptr;
SetEXIT(idx, false, GetTrigger(Mode, Invert));
if(!IsOnlyExOfInt(this, idx))return;
@ -810,7 +810,7 @@ bool InputPort::Register(IOReadHandler handler, void* param)
{
for(int i=0; i<16; i++)
{
States[i].Port = NULL;
States[i].Port = nullptr;
}
hasInitState = true;
}
@ -821,7 +821,7 @@ bool InputPort::Register(IOReadHandler handler, void* param)
auto port = st->Port;
// 检查是否已经注册到别的引脚上
if(port != this && port != NULL)
if(port != this && port != nullptr)
{
#if DEBUG
debug_printf("中断线EXTI%d 不能注册到 P%c%d, 它已经注册到 P%c%d\r\n", gi, _PIN_NAME(_Pin), _PIN_NAME(port->_Pin));

6
Port.h
View File

@ -158,7 +158,7 @@ public:
virtual bool Read() const;
// 注册事件
bool Register(IOReadHandler handler, void* param = NULL);
bool Register(IOReadHandler handler, void* param = nullptr);
void OnPress(bool down);
operator bool() const { return Read(); }
@ -175,8 +175,8 @@ private:
UInt64 _PressLast = 0; // 最后一次按下时间
static void InputTask(void* param);
IOReadHandler Handler = NULL;
void* Param = NULL;
IOReadHandler Handler = nullptr;
void* Param = nullptr;
};
/******************************** AnalogInPort ********************************/

View File

@ -1,4 +1,6 @@
#include "RSA.h"
#include <stdint.h>
#include "RSA.h"
#define KeyLength 1024

View File

@ -19,13 +19,13 @@ SerialPort::SerialPort(COM index, int baudRate)
SerialPort::~SerialPort()
{
if(RS485) delete RS485;
RS485 = NULL;
RS485 = nullptr;
}
void SerialPort::Init()
{
_index = 0xFF;
RS485 = NULL;
RS485 = nullptr;
Error = 0;
#ifdef STM32F1XX
@ -359,7 +359,7 @@ void SerialPort::ReceiveTask(void* param)
uint len = sp->Read(bs);
if(len)
{
len = sp->OnReceive(bs, NULL);
len = sp->OnReceive(bs, nullptr);
// 如果有数据,则反馈回去
if(len) sp->Write(bs);
}
@ -493,13 +493,13 @@ SerialPort* SerialPort::GetMessagePort()
if(sp && Sys.MessagePort != sp->_index)
{
delete sp;
_printf_sp = NULL;
_printf_sp = nullptr;
}
if(!sp)
{
auto idx = Sys.MessagePort;
if(idx == COM_NONE) return NULL;
if(idx == COM_NONE) return nullptr;
sp = _printf_sp = new SerialPort(idx);
sp->Open();

View File

@ -60,7 +60,7 @@ public:
void GetPins(Pin* txPin, Pin* rxPin);
virtual void Register(TransportHandler handler, void* param = NULL);
virtual void Register(TransportHandler handler, void* param = nullptr);
// 电源等级变更(如进入低功耗模式)时调用
virtual void ChangePower(int level);

2
Spi.h
View File

@ -32,7 +32,7 @@ public:
void Init(SPI spi, uint speedHz = 9000000, bool useNss = true);
void SetPin(Pin clk = P0, Pin miso = P0, Pin mosi = P0, Pin nss = P0);
void GetPin(Pin* clk = NULL, Pin* miso = NULL, Pin* mosi = NULL, Pin* nss = NULL);
void GetPin(Pin* clk = nullptr, Pin* miso = nullptr, Pin* mosi = nullptr, Pin* nss = nullptr);
void Open();
void Close();

View File

@ -200,7 +200,7 @@ byte* Stream::ReadBytes(int count)
if(count < 0) count = Remain();
byte* p = Current();
if(!Seek(count)) return NULL;
if(!Seek(count)) return nullptr;
return p;
}
@ -364,7 +364,7 @@ MemoryStream::~MemoryStream()
//if(_Buffer != _Arr)
if(_needFree)
delete[] _Buffer;
_Buffer = NULL;
_Buffer = nullptr;
}
}

View File

@ -90,10 +90,10 @@ public:
{
int p = sizeof(T) + _Position;
// 允许移动到最后一个字节之后也就是Length
if(p < 0 || p > Length) return NULL;
if(p < 0 || p > Length) return nullptr;
T* pt = (T*)Current();
if(move && !Seek(sizeof(T))) return NULL;
if(move && !Seek(sizeof(T))) return nullptr;
return pt;
}

View File

@ -519,8 +519,8 @@ bool String::Equals(const String& s2) const
bool String::Equals(const char* cstr) const
{
if (_Length == 0) return cstr == NULL || *cstr == 0;
if (cstr == NULL) return _Arr[0] == 0;
if (_Length == 0) return cstr == nullptr || *cstr == 0;
if (cstr == nullptr) return _Arr[0] == 0;
return strcmp(_Arr, cstr) == 0;
}
@ -732,7 +732,7 @@ char *strrstr(const char* s, const char* str)
if ((*p == *str) && (memcmp(p, str, strlen(str)) == 0))
return p;
}
return NULL;
return nullptr;
}
int String::LastIndexOf(const String& str, int startIndex) const
@ -898,7 +898,7 @@ extern char* ltoa(Int64 value, char* string, int radix)
int sign;
char *sp;
if ( string == NULL ) return 0 ;
if ( string == nullptr ) return 0 ;
if (radix > 36 || radix <= 1) return 0 ;
@ -930,7 +930,7 @@ extern char* ltoa(Int64 value, char* string, int radix)
char* utohex(uint value, byte size, char* string, bool upper)
{
if (string == NULL ) return 0;
if (string == nullptr ) return 0;
// 字节数乘以2是字符个数
size <<= 1;
@ -958,7 +958,7 @@ extern char* utoa(uint value, char* string, int radix)
extern char* ultoa(UInt64 value, char* string, int radix)
{
if (string == NULL ) return 0;
if (string == nullptr ) return 0;
if (radix > 36 || radix <= 1) return 0;

View File

@ -165,7 +165,7 @@ TSys::TSys()
InitHeapStack(StackTop());
#endif
OnSleep = NULL;
OnSleep = nullptr;
#ifdef STM32F1
// 关闭JTAG仿真接口只打开SW仿真。
@ -452,7 +452,7 @@ void TSys::Start()
Started = true;
#if DEBUG
//AddTask(ShowTime, NULL, 2000000, 2000000);
//AddTask(ShowTime, nullptr, 2000000, 2000000);
#endif
Task::Scheduler()->Start();
}
@ -543,7 +543,7 @@ void TSys::Delay(uint us) const
//#if DEBUG
#include "Port.h"
static OutputPort* _trace = NULL;
static OutputPort* _trace = nullptr;
//#endif
void TSys::InitTrace(void* port) const
{

8
Sys.h
View File

@ -3,8 +3,8 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*#include <stdlib.h>
#include <string.h>*/
// 强迫内联
#define _force_inline __attribute__( ( always_inline ) ) __INLINE
@ -27,7 +27,7 @@ extern "C"
// 验证确保对象不为空,并且在有效的内存范围内
//extern void assert_failed(uint8_t* file, uint32_t line);
#define assert_ptr(expr) (assert_ptr_(expr) ? (void)0 : assert_failed2("ptr==NULL", (const char*)__FILE__, __LINE__))
#define assert_ptr(expr) (assert_ptr_(expr) ? (void)0 : assert_failed2("ptr==nullptr", (const char*)__FILE__, __LINE__))
bool assert_ptr_(const void* p);
void assert_failed2(const char* msg, const char* file, unsigned int line);
@ -99,7 +99,7 @@ public:
public:
// 创建任务返回任务编号。dueTime首次调度时间msperiod调度间隔ms-1表示仅处理一次
uint AddTask(Action func, void* param, int dueTime = 0, int period = 0, const char* name = NULL) const;
uint AddTask(Action func, void* param, int dueTime = 0, int period = 0, const char* name = nullptr) const;
void RemoveTask(uint& taskid) const;
// 设置任务的开关状态同时运行指定任务最近一次调度的时间0表示马上调度
bool SetTask(uint taskid, bool enable, int msNextTime = -1) const;

View File

@ -3,10 +3,10 @@
Task::Task()
{
Host = NULL;
Host = nullptr;
ID = 0;
Name = NULL;
Name = nullptr;
Times = 0;
CpuTime = 0;
SleepTime = 0;
@ -143,7 +143,7 @@ TaskScheduler::TaskScheduler(const char* name)
Name = name;
Running = false;
Current = NULL;
Current = nullptr;
Count = 0;
Cost = 0;
@ -164,7 +164,7 @@ void TaskScheduler::Set(Task* tasks, uint count)
uint TaskScheduler::Add(Action func, void* param, int dueTime, int period, const char* name)
{
// 查找是否有可用空闲任务
Task* task = NULL;
Task* task = nullptr;
for(int i=0; !task && i<_Tasks.Length(); i++)
{
if(!_Tasks[i])
@ -344,7 +344,7 @@ Task* TaskScheduler::operator[](int taskid)
if(task->ID == taskid) return task;
}
return NULL;
return nullptr;
}
#pragma arm section code

4
Task.h
View File

@ -70,14 +70,14 @@ public:
int Cost; // 平均执行时间us
int MaxCost; // 最大执行时间us
TaskScheduler(const char* name = NULL);
TaskScheduler(const char* name = nullptr);
//~TaskScheduler();
// 使用外部缓冲区初始化任务列表,避免频繁的堆分配
void Set(Task* tasks, uint count);
// 创建任务返回任务编号。dueTime首次调度时间ms-1表示事件型任务period调度间隔ms-1表示仅处理一次
uint Add(Action func, void* param, int dueTime = 0, int period = 0, const char* name = NULL);
uint Add(Action func, void* param, int dueTime = 0, int period = 0, const char* name = nullptr);
void Remove(uint taskid);
void Start();

View File

@ -66,9 +66,9 @@ void TestNRF24L01()
{
//nrf->Config();
//nrf->SetMode(true);
//Sys.AddTask(OnReceive, NULL, 0, 1);
//Sys.AddTask(OnReceive, nullptr, 0, 1);
//nrf->Register(OnReceive, nrf);
Sys.AddTask(OnSend, NULL, 0, 1000);
Sys.AddTask(OnSend, nullptr, 0, 1000);
}
debug_printf("TestNRF24L01 Finish!\r\n");

View File

@ -43,7 +43,7 @@ void TestTimer(OutputPort& leds)
Timer* timer2 = Timer::Create();
timer2->SetFrequency(10);
timer2->Register(TimerTask2, NULL);
timer2->Register(TimerTask2, nullptr);
timer2->Open();
debug_printf("\r\n TestTimer Finish!\r\n");

View File

@ -41,7 +41,7 @@ Thread::Thread(Action callback, void* state, uint stackSize)
if(g_ID >= 0xFFFF) g_ID = 0;
debug_printf("Thread::Create %d 0x%08x StackSize=0x%04x", ID, callback, stackSize);
Name = NULL;
Name = nullptr;
// 外部传入的stackSize参数只是用户可用的栈大小这里还需要加上保存寄存器所需要的stk部分
uint stkSize = STACK_Size;
@ -65,8 +65,8 @@ Thread::Thread(Action callback, void* state, uint stackSize)
DelayExpire = 0;
Next = NULL;
Prev = NULL;
Next = nullptr;
Prev = nullptr;
uint* stk = StackTop; // 加载栈指针
// 中断时自动保存一部分寄存器
@ -147,8 +147,8 @@ Thread::~Thread()
Stack = StackTop - (StackSize >> 2);
if(Stack) delete[] Stack;
Stack = NULL;
StackTop = NULL;
Stack = nullptr;
StackTop = nullptr;
}
void Thread::Start()
@ -282,8 +282,8 @@ void Thread::Add(Thread* thread)
{
Free = thread;
thread->Prev = NULL;
thread->Next = NULL;
thread->Prev = nullptr;
thread->Next = nullptr;
}
else
{
@ -304,7 +304,7 @@ void Thread::Remove(Thread* thread)
SmartIRQ irq;
// 如果其为头部,注意修改头部指针
if(thread->Prev == NULL)
if(thread->Prev == nullptr)
{
if(thread == Free)
Free = thread->Next;
@ -325,7 +325,7 @@ void Thread::Remove(Thread* thread)
// 如果刚好是当前线程则放弃时间片重新调度。因为PendSV优先级的原因不会马上调度
if(thread == Current) Switch();
// 如果就绪队列为空重新调度。这里其实不用操心Switch里面会准备好Busy
if(Busy == NULL) BuildReady();
if(Busy == nullptr) BuildReady();
}
// 查找最高优先级
@ -387,8 +387,8 @@ byte Thread::BuildReady()
pri = FindMax(Busy, pri);
// 根据最高优先级重构线程就绪队列
Thread* head = NULL;
Thread* tail = NULL;
Thread* head = nullptr;
Thread* tail = nullptr;
byte count = 0;
count += BuildList(Free, head, tail, pri);
count += BuildList(Busy, head, tail, pri);
@ -621,12 +621,12 @@ bool Thread::Inited = false;
uint Thread::g_ID = 0;
byte Thread::_running = 0;
byte Thread::_sleeps = 0;
Thread* Thread::Free = NULL;
Thread* Thread::Busy = NULL;
Thread* Thread::Current = NULL;
Thread* Thread::Free = nullptr;
Thread* Thread::Busy = nullptr;
Thread* Thread::Current = nullptr;
byte Thread::Count = 0;
Thread* Thread::Idle = NULL;
Thread* Thread::Main = NULL;
Thread* Thread::Idle = nullptr;
Thread* Thread::Main = nullptr;
void Thread::Init()
{
@ -637,19 +637,19 @@ void Thread::Init()
Inited = true;
Free = NULL;
Busy = NULL;
Current = NULL;
Free = nullptr;
Busy = nullptr;
Current = nullptr;
// 创建一个空闲线程,确保队列不为空
Thread* idle = new Thread(Idle_Handler, NULL, 0);
Thread* idle = new Thread(Idle_Handler, nullptr, 0);
idle->Name = "Idle";
idle->Priority = Lowest;
idle->Start();
Idle = idle;
// 多线程调度与Sys定时调度联动由多线程调度器的Main线程负责驱动Sys.Start实现传统定时任务。要小心线程栈溢出
Thread* main = new Thread(Main_Handler, NULL, 0x400);
Thread* main = new Thread(Main_Handler, nullptr, 0x400);
main->Name = "Main";
main->Priority = BelowNormal;
main->Start();
@ -691,7 +691,7 @@ public:
~ThreadItem()
{
delete _thread;
_thread = NULL;
_thread = nullptr;
}
static void OnWork(void* param)

View File

@ -40,7 +40,7 @@ public:
} Priorities;
Priorities Priority; // 优先级
Thread(Action callback, void* state = NULL, uint stackSize = 0x200);
Thread(Action callback, void* state = nullptr, uint stackSize = 0x200);
virtual ~Thread();
void Start();

View File

@ -28,10 +28,10 @@ TTime::TTime()
#endif
BaseSeconds = 0;
OnInit = NULL;
OnLoad = NULL;
OnSave = NULL;
OnSleep = NULL;
OnInit = nullptr;
OnLoad = nullptr;
OnSave = nullptr;
OnSleep = nullptr;
}
void TTime::Init()
@ -199,7 +199,7 @@ void TTime::Sleep(uint ms, bool* running) const
}
}
// 睡眠时间太短
if(!ms || running != NULL && !*running) return;
if(!ms || running != nullptr && !*running) return;
uint me = Current() + ms;
@ -207,7 +207,7 @@ void TTime::Sleep(uint ms, bool* running) const
{
if(Current() >= me) break;
if(running != NULL && !*running) break;
if(running != nullptr && !*running) break;
}
}

6
Time.h
View File

@ -38,7 +38,7 @@ public:
UInt64 Current() const; // 当前毫秒数
void SetTime(UInt64 seconds); // 设置时间
void Sleep(uint ms, bool* running = NULL) const;
void Sleep(uint ms, bool* running = nullptr) const;
// 微秒级延迟
void Delay(uint us) const;
@ -74,7 +74,7 @@ public:
TimeCost();
int Elapsed(); // 逝去的时间,微秒
void Show(const char* format = NULL);
void Show(const char* format = nullptr);
};
// 系统时钟
@ -113,7 +113,7 @@ public:
f短全部 M/d/yy HH:mm
F长全部 yyyy-MM-dd HH:mm:ss
*/
const char* GetString(byte kind = 'F', char* str = NULL);
const char* GetString(byte kind = 'F', char* str = nullptr);
};
/*

View File

@ -7,10 +7,10 @@ const byte Timer::TimerCount = ArrayLength(g_Timers);
// 已经实例化的定时器对象
static Timer* Timers[16] = {
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
};
Timer::Timer(TIMER index)
@ -29,17 +29,17 @@ Timer::Timer(TIMER index)
Opened = false;
_Handler = NULL;
_Param = NULL;
_Handler = nullptr;
_Param = nullptr;
}
Timer::~Timer()
{
Close();
if(_Handler) Register(NULL);
if(_Handler) Register(nullptr);
Timers[_index] = NULL;
Timers[_index] = nullptr;
}
// 创建指定索引的定时器如果已有则直接返回默认0xFF表示随机分配
@ -58,7 +58,7 @@ Timer* Timer::Create(byte index)
if(i >= tcount)
{
debug_printf("Timer::Create 失败!没有空闲定时器!\r\n");
return NULL;
return nullptr;
}
index = i;
@ -265,7 +265,7 @@ void Timer::Register(EventHandler handler, void* param)
_Handler = handler;
_Param = param;
SetHandler(handler != NULL);
SetHandler(handler != nullptr);
}
void Timer::OnHandler(ushort num, void* param)
@ -310,7 +310,7 @@ PWM::PWM(TIMER index) : Timer(index)
{
for(int i=0; i<4; i++) Pulse[i] = 0xFFFF;
Pulses = NULL;
Pulses = nullptr;
PulseCount = 0;
Channel = 0;
PulseIndex = 0xFF;
@ -472,13 +472,13 @@ TIM_SetIC4Prescaler ,
Capture::Capture(Timer * timer)
{
if(timer == NULL)return ;
if(timer == nullptr)return ;
tr = timer;
// HaveCap = 0x00;
for(int i =0;i<4;i++)
{
_Handler [i]=NULL; // 其实可以不赋值
_Param [i]=NULL;
_Handler [i]=nullptr; // 其实可以不赋值
_Param [i]=nullptr;
}
}
@ -508,7 +508,7 @@ void Capture::Register(int channel,EventHandler handler, void* param )
if(channel<1||channel>4) return ;
_Handler[channel-1] = handler;
_Param[channel-1]=param;
// if(handler != NULL)
// if(handler != nullptr)
// tr->Register (OnHandler ,this);
int irq;
if(handler)
@ -521,10 +521,10 @@ void Capture::Register(int channel,EventHandler handler, void* param )
}
else
{
_Handler[channel-1] = NULL ;
_Param [channel-1]=NULL;
_Handler[channel-1] = nullptr ;
_Param [channel-1]=nullptr;
for(int i =0 ;i<4;i++)
if(_Handler [i] != NULL )return ;
if(_Handler [i] != nullptr )return ;
Interrupt.Deactivate(irq);
}
}
@ -533,14 +533,14 @@ void Capture::Register(int channel,EventHandler handler, void* param )
//void Capture :: OnHandler(void* sender, void* param)
//{
// Capture * cap= (Capture*)param;
// if(cap->_Handler != NULL)
// if(cap->_Handler != nullptr)
// cap->_Handler(sender,cap->_Param );
//}
void Capture :: OnHandler(ushort num, void* param)
{
Capture * cap= (Capture*)param;
if(cap != NULL)
if(cap != nullptr)
cap->OnInterrupt();
}
@ -559,7 +559,7 @@ void Capture::OnInterrupt()
Capture::~Capture()
{
for(int i =0;i<4;i++)
Register(i,NULL, NULL );
Register(i,nullptr, nullptr );
delete(tr);
}
*/

View File

@ -30,7 +30,7 @@ public:
uint GetCounter();
void SetCounter(uint cnt); // 设置计数器值
void Register(EventHandler handler, void* param = NULL);
void Register(EventHandler handler, void* param = nullptr);
private:
static void OnHandler(ushort num, void* param);
@ -92,7 +92,7 @@ public:
// FlagStatus TIM_GetFlagStatus(TIM_TypeDef* TIMx, uint16_t TIM_FLAG);
// volatile int CapValue[4]; // 一个定时器又是四路
Capture(Timer * timer = NULL);
Capture(Timer * timer = nullptr);
~Capture();
uint GetCapture(int channel);
@ -105,7 +105,7 @@ private :
void* _Param[4];
public :
void Register(int Index,EventHandler handler, void* param = NULL);
void Register(int Index,EventHandler handler, void* param = nullptr);
};
//void (*EventHandler)(void* sender, void* param);
*/

View File

@ -30,7 +30,7 @@ ArpSocket::ArpSocket(TinyIP* tip) : TinySocket(tip, IP_NONE)
#elif defined(STM32F4)
Count = 64;
#endif
_Arps = NULL;
_Arps = nullptr;
Enable = true;
}
@ -38,7 +38,7 @@ ArpSocket::ArpSocket(TinyIP* tip) : TinySocket(tip, IP_NONE)
ArpSocket::~ArpSocket()
{
if(_Arps) delete _Arps;
_Arps = NULL;
_Arps = nullptr;
}
bool ArpSocket::Process(IP_HEADER& ip, Stream& ms)
@ -205,7 +205,7 @@ bool ArpSocket::Request(const IPAddress& ip, MacAddress& mac, int timeout)
return true;
}
_ArpSession = NULL;
_ArpSession = nullptr;
return false;
}
@ -223,7 +223,7 @@ bool ArpSocket::Resolve(const IPAddress& ip, MacAddress& mac)
//if((ip & Tip->Mask) != (Tip->IP & Tip->Mask)) ip = Tip->Gateway;
if(dest.GetSubNet(Tip->Mask) != Tip->IP.GetSubNet(Tip->Mask)) dest = Tip->Gateway;
ARP_ITEM* item = NULL; // 匹配项
ARP_ITEM* item = nullptr; // 匹配项
if(_Arps)
{
uint sNow = Sys.Ms() >> 10; // 当前时间,秒
@ -276,8 +276,8 @@ void ArpSocket::Add(const IPAddress& ip, const MacAddress& mac)
Buffer(_Arps, sizeof(ARP_ITEM) * Count).Clear();
}
ARP_ITEM* item = NULL;
ARP_ITEM* empty = NULL;
ARP_ITEM* item = nullptr;
ARP_ITEM* empty = nullptr;
// 在表中查找项
for(int i=0; i<Count; i++)
{

View File

@ -29,9 +29,9 @@ TcpSocket::TcpSocket(TinyIP* tip) : Socket(tip)
Status = Closed;
OnAccepted = NULL;
OnReceived = NULL;
OnDisconnected = NULL;
OnAccepted = nullptr;
OnReceived = nullptr;
OnDisconnected = nullptr;
}
const char* TcpSocket::ToString()

View File

@ -31,7 +31,7 @@ public:
};
// 用于等待Ping响应的会话
PingSession* _IcmpSession = NULL;
PingSession* _IcmpSession = nullptr;
IcmpSocket::IcmpSocket(TinyIP* tip) : TinySocket(tip, IP_ICMP)
{
@ -48,7 +48,7 @@ bool IcmpSocket::Process(IP_HEADER& ip, Stream& ms)
IPAddress remote = ip.SrcIP;
// 检查有没有会话等待
if(icmp->Type == 0 && _IcmpSession != NULL && _IcmpSession->Check(remote, icmp))
if(icmp->Type == 0 && _IcmpSession != nullptr && _IcmpSession->Check(remote, icmp))
{
_IcmpSession->Success = true;
return true;
@ -161,7 +161,7 @@ bool IcmpSocket::Ping(IPAddress& ip, uint payloadLength)
if(ps.Success) break;
}while(!tw.Expired());
_IcmpSession = NULL;
_IcmpSession = nullptr;
#if NET_DEBUG
uint cost = ct.Elapsed() / 1000;

View File

@ -29,9 +29,9 @@ TcpSocket::TcpSocket(TinyIP* tip) : TinySocket(tip, IP_TCP)
Status = Closed;
OnAccepted = NULL;
OnReceived = NULL;
OnDisconnected = NULL;
OnAccepted = nullptr;
OnReceived = nullptr;
OnDisconnected = nullptr;
}
const char* TcpSocket::ToString() const
@ -206,7 +206,7 @@ void TcpSocket::OnDataReceive(TCP_HEADER& tcp, uint len)
// 触发ITransport接口事件
Buffer bs(data, len);
uint len2 = OnReceive(bs, NULL);
uint len2 = OnReceive(bs, nullptr);
// 如果有返回,说明有数据要回复出去
if(len2)
{
@ -413,7 +413,7 @@ bool TcpSocket::Send(const Buffer& bs)
if(wait) break;
}while(!tw.Expired());
WaitAck = NULL;
WaitAck = nullptr;
#if NET_DEBUG
if(wait)
@ -479,7 +479,7 @@ bool TcpSocket::Connect(IPAddress& ip, ushort port)
if(wait) break;
}while(!tw.Expired());
WaitAck = NULL;
WaitAck = nullptr;
if(wait)
{

View File

@ -19,15 +19,15 @@ TinyIP::TinyIP(ITransport* port) : _Arr(0)
TinyIP::~TinyIP()
{
delete _port;
_port = NULL;
_port = nullptr;
delete Arp;
Arp = NULL;
Arp = nullptr;
}
void TinyIP::Init()
{
_port = NULL;
_port = nullptr;
_StartTime = 0;
// 以太网缓冲区先初始化为0然后再调整大小
@ -37,7 +37,7 @@ void TinyIP::Init()
DHCPServer = Gateway = DNSServer = IP = 0;
//Sockets.SetCapacity(0x10);
Arp = NULL;
Arp = nullptr;
}
void TinyIP::Init(ITransport* port)
@ -320,7 +320,7 @@ bool TinyIP::SendIP(IP_TYPE type, const IPAddress& remote, const byte* buf, uint
// 网络序是大端
ip->Checksum = 0;
ip->Checksum = _REV16(CheckSum(NULL, (byte*)ip, sizeof(IP_HEADER), 0));
ip->Checksum = _REV16(CheckSum(nullptr, (byte*)ip, sizeof(IP_HEADER), 0));
assert_ptr(Arp);
ArpSocket* arp = (ArpSocket*)Arp;
@ -363,7 +363,7 @@ ISocket* TinyIP::CreateSocket(ProtocolType type)
return new UdpSocket(this);
default:
return NULL;
return nullptr;
}
}
@ -442,14 +442,14 @@ TinySocket::TinySocket(TinyIP* tip, IP_TYPE type)
{
for(int i=0; i<tip->Sockets.Length(); i++)
{
if(tip->Sockets[i] == NULL)
if(tip->Sockets[i] == nullptr)
{
tip->Sockets[i] = this;
break;
}
}
}*/
//int idx = tip->Sockets.FindIndex(NULL);
//int idx = tip->Sockets.FindIndex(nullptr);
//if(idx >= 0) tip->Sockets[idx] = this;
}
@ -464,12 +464,12 @@ TinySocket::~TinySocket()
{
if(Tip->Sockets[i] == this)
{
Tip->Sockets[i] = NULL;
Tip->Sockets[i] = nullptr;
break;
}
}*/
//int idx = Tip->Sockets.FindIndex(this);
//if(idx >= 0) Tip->Sockets[idx] = NULL;
//if(idx >= 0) Tip->Sockets[idx] = nullptr;
}
TinySocket* SocketList::FindByType(ushort type)
@ -484,12 +484,12 @@ TinySocket* SocketList::FindByType(ushort type)
}
}
return NULL;
return nullptr;
}
void SocketList::Add(const TinySocket* socket)
{
int idx = FindIndex(NULL);
int idx = FindIndex(nullptr);
// 如果找不到空位,则加在最后
if(idx < 0) idx = Length();
SetAt(idx, (TinySocket*)socket);
@ -498,6 +498,6 @@ void SocketList::Add(const TinySocket* socket)
void SocketList::Remove(const TinySocket* socket)
{
int idx = FindIndex((TinySocket*)socket);
if(idx >= 0) (*this)[idx] = NULL;
if(idx >= 0) (*this)[idx] = nullptr;
}

View File

@ -33,7 +33,7 @@ Device::Device() :
Pass.Clear();
Store.Clear();
Cfg = NULL;
Cfg = nullptr;
LastRead = 0;
//LastWrite = 0;

View File

@ -14,12 +14,12 @@ void Setup(ushort code, const char* name, COM message = COM1, int baudRate = 0);
void* InitConfig(void* data, uint size);
void ClearConfig();
ITransport* Create2401(SPI spi, Pin ce, Pin irq, Pin power = P0, bool powerInvert = false, IDataPort* led = NULL);
ITransport* CreateShunCom(COM index, int baudRate, Pin rst, Pin power, Pin slp, Pin cfg, IDataPort* led = NULL);
ITransport* Create2401(SPI spi, Pin ce, Pin irq, Pin power = P0, bool powerInvert = false, IDataPort* led = nullptr);
ITransport* CreateShunCom(COM index, int baudRate, Pin rst, Pin power, Pin slp, Pin cfg, IDataPort* led = nullptr);
TinyClient* CreateTinyClient(ITransport* port);
bool CheckUserPress(InputPort* port, bool down, void* param = NULL);
bool CheckUserPress(InputPort* port, bool down, void* param = nullptr);
void InitButtonPress(Button_GrayLevel* btns, byte count);
void SetPower(ITransport* port);

View File

@ -7,7 +7,7 @@
#include "PingMessage.h"
#include "DataMessage.h"
TinyClient* TinyClient::Current = NULL;
TinyClient* TinyClient::Current = nullptr;
static void TinyClientTask(void* param);
//static void TinyClientReset();
@ -29,10 +29,10 @@ TinyClient::TinyClient(TinyController* control)
LastActive = 0;
Received = NULL;
Param = NULL;
Received = nullptr;
Param = nullptr;
Cfg = NULL;
Cfg = nullptr;
_TaskID = 0;
@ -77,8 +77,8 @@ void TinyClient::Close()
Sys.RemoveTask(_TaskID);
Control->Received = NULL;
Control->Param = NULL;
Control->Received = nullptr;
Control->Param = nullptr;
Control->Close();
@ -252,7 +252,7 @@ bool TinyClient::Report(uint offset, const Buffer& bs)
void TinyClient::ReportAsync(uint offset,uint length)
{
if(this == NULL) return;
if(this == nullptr) return;
if(offset + length >= Store.Data.Length()) return;
NextReport = offset;

View File

@ -1,7 +1,7 @@
#include "TinyConfig.h"
#include "Config.h"
TinyConfig* TinyConfig::Current = NULL;
TinyConfig* TinyConfig::Current = nullptr;
TinyConfig::TinyConfig() : ConfigBase()
{

View File

@ -236,7 +236,7 @@ TinyController::TinyController() : Controller()
}
_taskID = 0;
_Queue = NULL;
_Queue = nullptr;
QueueLength = 8;
// 默认屏蔽心跳日志
@ -249,7 +249,7 @@ TinyController::~TinyController()
Sys.RemoveTask(_taskID);
delete[] _Queue;
_Queue = NULL;
_Queue = nullptr;
}
void TinyController::ApplyConfig()

View File

@ -24,7 +24,7 @@ static void DeviceShow(void* param);
TinyServer::TinyServer(TinyController* control)
{
Control = control;
Cfg = NULL;
Cfg = nullptr;
DeviceType = Sys.Code;
Control->Received = OnServerReceived;
@ -33,10 +33,10 @@ TinyServer::TinyServer(TinyController* control)
Control->Mode = 2; // 服务端接收所有消息
Received = NULL;
Param = NULL;
Received = nullptr;
Param = nullptr;
Current = NULL;
Current = nullptr;
Study = false;
Devices.SetLength(0);
@ -145,7 +145,7 @@ bool TinyServer::OnReceive(TinyMessage& msg)
// 消息转发
if(Received) return Received(this, msg, Param);
Current = NULL;
Current = nullptr;
return true;
}
@ -219,7 +219,7 @@ bool TinyServer::Dispatch(TinyMessage& msg)
msg.SetData(Buffer(rs.Data, rs.Length));
}
Current = NULL;
Current = nullptr;
return rt;
}
@ -254,7 +254,7 @@ bool TinyServer::OnJoin(const TinyMessage& msg)
// 从1开始派ID
id = 1;
while(FindDevice(++id) != NULL && id < 0xFF);
while(FindDevice(++id) != nullptr && id < 0xFF);
debug_printf("发现节点设备 0x%04X ,为其分配 0x%02X\r\n", dm.Kind, id);
if(id == 0xFF) return false;
@ -281,7 +281,7 @@ bool TinyServer::OnJoin(const TinyMessage& msg)
{
//byte sum = st[0] && st[1] && st[2] && st[3] && st[4];
int sum = (int)st[0] + st[1] + st[2] + st[3] + st[4];
if(sum == 0 || sum == 0xFF * 5) st = NULL;
if(sum == 0 || sum == 0xFF * 5) st = nullptr;
}
if(!st)
dv->Mac.Copy(0, dv->HardID, 0, -1);
@ -410,7 +410,7 @@ bool TinyServer::OnPing(const TinyMessage& msg)
auto dv = FindDevice(msg.Src);
// 网关内没有相关节点信息时不鸟他
if(dv == NULL) return false;
if(dv == nullptr) return false;
auto rs = msg.CreateReply();
auto ms = msg.ToStream();
@ -551,7 +551,7 @@ bool TinyServer::OnWriteReply(const Message& msg, Device& dv)
TS("TinyServer::OnWriteReply");
DataMessage dm(msg, NULL);
DataMessage dm(msg, nullptr);
if(dm.Offset < 64)
dm.WriteData(dv.Store, false);
@ -582,13 +582,13 @@ void TinyServer::SetChannel(byte channel)
Device* TinyServer::FindDevice(byte id) const
{
if(id == 0) return NULL;
if(id == 0) return nullptr;
for(int i=0; i<Devices.Length(); i++)
{
if(id == Devices[i]->Address) return Devices[i];
}
return NULL;
return nullptr;
}
void GetDeviceKey(byte scr, Buffer& key, void* param)
@ -609,13 +609,13 @@ void GetDeviceKey(byte scr, Buffer& key, void* param)
Device* TinyServer::FindDevice(const Buffer& hardid) const
{
if(hardid.Length() == 0) return NULL;
if(hardid.Length() == 0) return nullptr;
for(int i=0; i<Devices.Length(); i++)
{
if(Devices[i] != NULL && hardid == Devices[i]->HardID) return Devices[i];
if(Devices[i] != nullptr && hardid == Devices[i]->HardID) return Devices[i];
}
return NULL;
return nullptr;
}
bool TinyServer::DeleteDevice(byte id)
@ -629,7 +629,7 @@ bool TinyServer::DeleteDevice(byte id)
int idx = Devices.FindIndex(dv);
debug_printf("idx~~~~~~~~~~~:%d\r\n",idx);
if(idx >= 0) Devices[idx] = NULL;
if(idx >= 0) Devices[idx] = nullptr;
delete dv;
SaveDevices();
@ -686,7 +686,7 @@ int TinyServer::LoadDevices()
if(fs)
{
int idx = Devices.FindIndex(NULL);
int idx = Devices.FindIndex(nullptr);
if(idx == -1)
{
if(dv->Valid())
@ -724,7 +724,7 @@ void TinyServer::SaveDevices() const
for(int i = 0; i<Devices.Length(); i++)
{
auto dv = Devices[i];
if(dv == NULL) continue;
if(dv == nullptr) continue;
num++;
}
// 设备个数
@ -734,7 +734,7 @@ void TinyServer::SaveDevices() const
for(int i = 0; i<Devices.Length(); i++)
{
auto dv = Devices[i];
if(dv == NULL) continue;
if(dv == nullptr) continue;
dv->Write(ms);
}
debug_printf("TinyServer::SaveDevices 保存 %d 个设备到 0x%08X\r\n", num, cfg.Address);
@ -788,7 +788,7 @@ void DeviceShow(void* param)
for(int i = 0; i < len; i++)
{
auto dv = svr->Devices[i];
if(dv == NULL) continue;
if(dv == nullptr) continue;
count++;
dv->Show();

View File

@ -9,14 +9,14 @@
bool TokenToTiny(const TokenMessage& msg, TinyMessage& msg2);
void TinyToToken(const TinyMessage& msg, TokenMessage& msg2);
Gateway* Gateway::Current = NULL;
Gateway* Gateway::Current = nullptr;
// 本地网和远程网一起实例化网关服务
Gateway::Gateway()
{
Server = NULL;
Client = NULL;
Led = NULL;
Server = nullptr;
Client = nullptr;
Led = nullptr;
Running = false;
}
@ -26,10 +26,10 @@ Gateway::~Gateway()
Stop();
delete Server;
Server = NULL;
Server = nullptr;
delete Client;
Client = NULL;
Client = nullptr;
}
// 启动网关。挂载本地和远程的消息事件
@ -80,10 +80,10 @@ void Gateway::Stop()
Sys.RemoveTask(_task);
Server->Received = NULL;
Server->Param = NULL;
Client->Received = NULL;
Client->Param = NULL;
Server->Received = nullptr;
Server->Param = nullptr;
Client->Received = nullptr;
Client->Param = nullptr;
Running = false;
}
@ -132,7 +132,7 @@ bool Gateway::OnRemote(const TokenMessage& msg)
if(msg.Reply && Client->Token != 0)
{
// 遍历发送所有设备信息
SendDevices(DeviceAtions::List, NULL);
SendDevices(DeviceAtions::List, nullptr);
}
break;
@ -179,7 +179,7 @@ bool Gateway::SendDevices(DeviceAtions act, const Device* dv)
for(int i = 0;i < len;i++)
{
if(Server->Devices[i] == NULL) continue;
if(Server->Devices[i] == nullptr) continue;
count++;
}
@ -200,7 +200,7 @@ bool Gateway::SendDevices(DeviceAtions act, const Device* dv)
for(int i=0; i<len; i++)
{
auto dv1 = Server->Devices[i];
if(dv1 == NULL ) continue;
if(dv1 == nullptr ) continue;
dv1->WriteMessage(ms);
}
}
@ -342,7 +342,7 @@ void Gateway::DeviceRequest(DeviceAtions act, const Device* dv)
{
debug_printf("节点删除~~ ID=0x%02X\r\n", id);
auto dv = Server->FindDevice(id);
if(dv == NULL) return;
if(dv == nullptr) return;
Server->DeleteDevice(id);
break;
}
@ -380,7 +380,7 @@ bool Gateway::DeviceProcess(const Message& msg)
{
case DeviceAtions::List:
{
SendDevices(act, NULL);
SendDevices(act, nullptr);
return true;
}
case DeviceAtions::Update:
@ -413,7 +413,7 @@ bool Gateway::DeviceProcess(const Message& msg)
debug_printf("节~~1点删除 ID=0x%02X\r\n", id);
{
auto dv = Server->FindDevice(id);
if(dv == NULL)
if(dv == nullptr)
{
rs.Error = true;
Client->Reply(rs);
@ -482,8 +482,8 @@ Gateway* Gateway::CreateGateway(TokenClient* client, TinyServer* server)
Gateway* gw = Current;
if(gw)
{
if( (client == NULL || gw->Client == client) &&
(server == NULL || gw->Server == server)) return gw;
if( (client == nullptr || gw->Client == client) &&
(server == nullptr || gw->Server == server)) return gw;
delete gw;
}

View File

@ -62,7 +62,7 @@ ISocketHost* Token::Create2860(SPI spi_, Pin irq, Pin rst)
_tip->Init(_enc);
_enc->Mac = _tip->Mac;
if(!_tip->Open()) return NULL;
if(!_tip->Open()) return nullptr;
Sys.Sleep(500);
if(!_enc->Linked()) debug_printf("未连接网线!\r\n");
@ -277,7 +277,7 @@ ITransport* Token::CreateShunCom(COM index, int baudRate, Pin rst, Pin power, Pi
void StartGateway(void* param)
{
ISocket* socket = NULL;
ISocket* socket = nullptr;
auto gw = Gateway::Current;
if(gw) socket = dynamic_cast<ISocket*>(gw->Client->Control->Port);

View File

@ -18,11 +18,11 @@ class Token
public:
static void Setup(ushort code, const char* name, COM message = COM1, int baudRate = 0);
static ISocketHost* CreateW5500(SPI spi, Pin irq, Pin rst = P0, Pin power = P0, IDataPort* led = NULL);
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 ITransport* Create2401(SPI spi, Pin ce, Pin irq, Pin power = P0, bool powerInvert = false, IDataPort* led = NULL);
static ITransport* CreateShunCom(COM index, int baudRate, Pin rst, Pin power, Pin slp, Pin cfg, IDataPort* led = NULL);
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);

View File

@ -25,12 +25,12 @@ TokenClient::TokenClient()
LastActive = 0;
Delay = 0;
Control = NULL;
Control = nullptr;
Received = NULL;
Param = NULL;
Received = nullptr;
Param = nullptr;
Local = NULL;
Local = nullptr;
}
void TokenClient::Open()
@ -476,7 +476,7 @@ bool TokenClient::ChangeIPEndPoint(const String& domain, ushort port)
domain.Show(true);
auto socket = dynamic_cast<ISocket*>(Control->Port);
if(socket == NULL) return false;
if(socket == nullptr) return false;
// 根据DNS获取云端IP地址
auto ip = DNS::Query(*(socket->Host), domain);

View File

@ -31,8 +31,8 @@ public:
void Close();
// 发送消息
bool Send(TokenMessage& msg, Controller* ctrl = NULL);
bool Reply(TokenMessage& msg, Controller* ctrl = NULL);
bool Send(TokenMessage& msg, Controller* ctrl = nullptr);
bool Reply(TokenMessage& msg, Controller* ctrl = nullptr);
bool OnReceive(TokenMessage& msg, Controller* ctrl);
// 收到功能消息时触发

View File

@ -2,7 +2,7 @@
#include "Net\Net.h"
#include "Config.h"
TokenConfig* TokenConfig::Current = NULL;
TokenConfig* TokenConfig::Current = nullptr;
TokenConfig::TokenConfig() : ConfigBase(),
User(_User, ArrayLength(_User)),

View File

@ -137,16 +137,16 @@ TokenController::TokenController() : Controller(), Key(0)
MinSize = TokenMessage::MinSize;
//MaxSize = 1500;
Server = NULL;
Server = nullptr;
// 默认屏蔽心跳日志和确认日志
Buffer(NoLogCodes, sizeof(NoLogCodes)).Clear();
NoLogCodes[0] = 0x03;
NoLogCodes[1] = 0x08;
_Response = NULL;
_Response = nullptr;
Stat = NULL;
Stat = nullptr;
Buffer(_Queue, ArrayLength(_Queue) * sizeof(_Queue[0])).Clear();
}
@ -183,7 +183,7 @@ void TokenController::Open()
void TokenController::Close()
{
delete Stat;
Stat = NULL;
Stat = nullptr;
Sys.RemoveTask(_taskID);
}
@ -382,7 +382,7 @@ bool TokenController::SendAndReceive(TokenMessage& msg, int retry, int msTimeout
debug_printf("\r\n");
#endif
_Response = NULL;
_Response = nullptr;
EndSendStat(code, rs);
@ -534,8 +534,8 @@ TokenStat::TokenStat()
Read = 0;
_Last = NULL;
_Total = NULL;*/
_Last = nullptr;
_Total = nullptr;*/
int start = offsetof(TokenStat, SendRequest);
Buffer((byte*)this + start, sizeof(TokenStat) - start).Clear();
@ -543,8 +543,8 @@ TokenStat::TokenStat()
TokenStat::~TokenStat()
{
if (_Last == NULL) delete _Last;
if (_Total == NULL) delete _Total;
if (_Last == nullptr) delete _Last;
if (_Total == nullptr) delete _Total;
}
int TokenStat::Percent() const
@ -591,8 +591,8 @@ int TokenStat::PercentReply() const
void TokenStat::Clear()
{
if (_Last == NULL) _Last = new TokenStat();
if (_Total == NULL) _Total = new TokenStat();
if (_Last == nullptr) _Last = new TokenStat();
if (_Total == nullptr) _Total = new TokenStat();
_Last->SendRequest = SendRequest;
_Last->RecvReply = RecvReply;

View File

@ -760,6 +760,7 @@ namespace NewLife.Reflection
ss.Add("in this scope", "在该范围");
ss.Add("In function", "在函数");
ss.Add("In member function", "在成员函数");
ss.Add("In static member function", "在静态成员函数");
ss.Add("In destructor", "在析构函数");
ss.Add("In instantiation of", "在初始化");
ss.Add("At global scope", "在全局范围");

38
Type.h
View File

@ -1,8 +1,8 @@
#ifndef __Type_H__
#define __Type_H__
#include <stdio.h>
#include <stdlib.h>
/*#include <stdio.h>
#include <stdlib.h>*/
/* 类型定义 */
typedef char sbyte;
@ -455,8 +455,8 @@ public:
void Initialize()
{
Next = NULL;
Prev = NULL;
Next = nullptr;
Prev = nullptr;
}
// 从链表中删除。需要修改前后节点的指针指向,但当前节点仍然指向之前的前后节点
@ -472,8 +472,8 @@ public:
if(Prev) Prev->Next = Next;
if(Next) Next->Prev = Prev;
Next = NULL;
Prev = NULL;
Next = nullptr;
Prev = nullptr;
}
// 把当前节点附加到另一个节点之后
@ -482,7 +482,7 @@ public:
node->Next = (T*)this;
Prev = node;
// 不能清空Next因为可能是两个链表的合并
//Next = NULL;
//Next = nullptr;
}
// 最后一个节点
@ -499,7 +499,7 @@ public:
{
Next = node;
node->Prev = (T*)this;
//node->Next = NULL;
//node->Next = nullptr;
}
};
@ -518,8 +518,8 @@ public:
Node()
{
Prev = NULL;
Next = NULL;
Prev = nullptr;
Next = nullptr;
}
// 从队列中脱离
@ -545,8 +545,8 @@ private:
void Init()
{
_Head = NULL;
_Tail = NULL;
_Head = nullptr;
_Tail = nullptr;
_Count = 0;
}
@ -650,15 +650,15 @@ public:
// 释放第一个有效节点
T& ExtractFirst()
{
if(!_Count) return NULL;
if(!_Count) return nullptr;
Node* node = _Head;
_Head = _Head->Next;
// 可能只有一个节点
if(!_Head)
_Tail = NULL;
_Tail = nullptr;
else
_Head->Prev = NULL;
_Head->Prev = nullptr;
T& item = node->Item;
delete node;
@ -670,15 +670,15 @@ public:
// 释放最后一个有效节点
T& ExtractLast()
{
if(!_Count) return NULL;
if(!_Count) return nullptr;
Node* node = _Tail;
_Tail = _Tail->Prev;
// 可能只有一个节点
if(!_Tail)
_Head = NULL;
_Head = nullptr;
else
_Tail->Next = NULL;
_Tail->Next = nullptr;
T& item = node->Item;
delete node;
@ -740,7 +740,7 @@ public:
if(!_ptr->Count)
{
delete _ptr;
_ptr = NULL;
_ptr = nullptr;
}
}

View File

@ -17,7 +17,7 @@ typedef struct
// 初始化内存池
bool _init_mem(void* pool, uint size)
{
if (pool == NULL || size < sizeof(MemBlock)) return false;
if (pool == nullptr || size < sizeof(MemBlock)) return false;
/*
poolsize
@ -28,7 +28,7 @@ bool _init_mem(void* pool, uint size)
*/
MemBlock* ptr = (MemBlock*)pool;
ptr->next = (MemBlock*)((uint)pool + size - sizeof(MemBlock));
ptr->next->next = NULL;
ptr->next->next = nullptr;
ptr->len = 0;
return true;
@ -37,7 +37,7 @@ bool _init_mem(void* pool, uint size)
// 分配内存
void* _alloc_mem(void* pool, uint size)
{
if (pool == NULL || size == 0) return NULL;
if (pool == nullptr || size == 0) return nullptr;
// 增加头部大小
size += sizeof(MemBlock);
@ -54,7 +54,7 @@ void* _alloc_mem(void* pool, uint size)
if (hole_size >= size) break;
p = p->next;
// 失败,位于列表尾部
if (p->next == NULL) return NULL;
if (p->next == nullptr) return nullptr;
}
if (p->len == 0)
@ -77,22 +77,22 @@ void* _alloc_mem(void* pool, uint size)
// 释放内存
bool _free_mem(void* pool, void *mem)
{
if (pool == NULL || mem == NULL) return false;
if (pool == nullptr || mem == nullptr) return false;
// 要释放的目标内存块
MemBlock* rs = (MemBlock*)((uint)mem - sizeof(MemBlock));
MemBlock* prv = NULL;
MemBlock* prv = nullptr;
MemBlock* p = (MemBlock*)pool;
while (p != rs)
{
prv = p;
p = p->next;
// 验证内存块不存在
if (p == NULL) return false;
if (p == nullptr) return false;
}
if (prv == NULL)
if (prv == nullptr)
// 第一块被释放仅仅设置长度为0
p->len = 0;
else