集体修改断言
This commit is contained in:
parent
106949adfc
commit
b0c7e1595c
2
ADC.cpp
2
ADC.cpp
|
@ -6,7 +6,7 @@ Pin ADC_Pins[] = ADC1_PINS;
|
|||
|
||||
ADConverter::ADConverter(byte line, uint channel)
|
||||
{
|
||||
assert_param2(line >= 1 && line <= 3, "ADC Line");
|
||||
assert(line >= 1 && line <= 3, "ADC Line");
|
||||
|
||||
Line = line;
|
||||
Channel = channel;
|
||||
|
|
|
@ -5,8 +5,8 @@ ushort IRcoding::CodingSize = 255;
|
|||
|
||||
IRcoding::IRcoding(Storage* flash, uint blockSize)
|
||||
{
|
||||
assert_param2(flash, "必须给出存储介质");
|
||||
assert_param2(blockSize, "必须给出具体块大小");
|
||||
assert(flash, "必须给出存储介质");
|
||||
assert(blockSize, "必须给出具体块大小");
|
||||
_Medium = flash;
|
||||
_BlockSize = blockSize;
|
||||
// 计算需要多少个 Block 存储一个 编码
|
||||
|
|
17
Config.cpp
17
Config.cpp
|
@ -67,9 +67,6 @@ uint ConfigBlock::CopyTo(Buffer& bs) const
|
|||
if(Size == 0 || Size > bs.Length()) return 0;
|
||||
|
||||
return bs.Copy(0, Data(), Size);
|
||||
//bs.SetLength(Size);
|
||||
|
||||
//return Size;
|
||||
}
|
||||
|
||||
// 构造一个新的配置块
|
||||
|
@ -77,10 +74,10 @@ bool ConfigBlock::Init(const String& name, const Buffer& bs)
|
|||
{
|
||||
if(!name) return false;
|
||||
|
||||
assert_param2(name.Length() < sizeof(Name), "配置区名称太长");
|
||||
assert(name.Length() < sizeof(Name), "配置区名称太长");
|
||||
if(name.Length() >= sizeof(Name)) return false;
|
||||
|
||||
TS("ConfigBlock::Init");
|
||||
//TS("ConfigBlock::Init");
|
||||
|
||||
// 配置块的大小,只有第一次能够修改,以后即使废弃也不能修改,仅仅清空名称
|
||||
if(bs.Length() > 0)
|
||||
|
@ -102,7 +99,7 @@ bool ConfigBlock::Write(const Storage& storage, uint addr, const Buffer& bs)
|
|||
// 如果大小超标,并且下一块有效,那么这是非法操作
|
||||
if(bs.Length() > Size && Next()->Valid())
|
||||
{
|
||||
debug_printf("ConfigBlock::Write 配置块 %s 大小 %d 小于要写入的数据大小 %d,并且下一块是有效配置块,不能覆盖! \r\n", Name, Size, bs.Length());
|
||||
debug_printf("ConfigBlock::Write 配置块 %s 大小 %d < %d \r\n", Name, Size, bs.Length());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -167,7 +164,7 @@ const ConfigBlock* FindBlock(const Storage& st, uint addr, const String& name)
|
|||
|
||||
if(!name) return nullptr;
|
||||
|
||||
assert_param2(name.Length() < sizeof(ConfigBlock::Name), "配置区名称太长");
|
||||
assert(name.Length() < sizeof(ConfigBlock::Name), "配置区名称太长");
|
||||
if(name.Length() >= sizeof(ConfigBlock::Name)) return nullptr;
|
||||
|
||||
if(!CheckSignature(st, addr, false)) return nullptr;
|
||||
|
@ -254,7 +251,7 @@ const void* Config::Set(const String& name, const Buffer& bs) const
|
|||
|
||||
if(!name) return nullptr;
|
||||
|
||||
assert_param2(name.Length() < sizeof(ConfigBlock::Name), "配置区名称太长");
|
||||
assert(name.Length() < sizeof(ConfigBlock::Name), "配置区名称太长");
|
||||
if(name.Length() >= sizeof(ConfigBlock::Name)) return nullptr;
|
||||
|
||||
auto cfg = FindBlock(Device, Address, name);
|
||||
|
@ -300,7 +297,7 @@ bool Config::GetOrSet(const String& name, Buffer& bs) const
|
|||
TS("Config::GetOrSet");
|
||||
|
||||
if(name == nullptr) return false;
|
||||
//assert_param2(name, "配置块名称不能为空");
|
||||
//assert(name, "配置块名称不能为空");
|
||||
|
||||
// 输入数据已存在,直接返回
|
||||
if(Get(name, bs)) return true;
|
||||
|
@ -345,7 +342,7 @@ ConfigBase::ConfigBase()
|
|||
|
||||
uint ConfigBase::Size() const
|
||||
{
|
||||
assert_param2(_End && _Start, "_Start & _End == nullptr");
|
||||
assert(_End && _Start, "_Start & _End == nullptr");
|
||||
|
||||
return (uint)_End - (uint)_Start;
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ void free_(void* p)
|
|||
{
|
||||
byte* bs = (byte*)p;
|
||||
bs -= 4;
|
||||
assert_param2(bs[0] == 'S' && bs[1] == 'M', "正在释放不是本系统申请的内存!");
|
||||
assert(bs[0] == 'S' && bs[1] == 'M', "正在释放不是本系统申请的内存!");
|
||||
|
||||
free(bs);
|
||||
}
|
||||
|
|
|
@ -707,7 +707,7 @@ byte Enc28j60::GetRevision()
|
|||
bool Enc28j60::OnWrite(const Buffer& bs)
|
||||
{
|
||||
uint len = bs.Length();
|
||||
assert_param2(len <= MAX_FRAMELEN, "以太网数据帧超大");
|
||||
assert(len <= MAX_FRAMELEN, "以太网数据帧超大");
|
||||
|
||||
if(!Linked())
|
||||
{
|
||||
|
|
|
@ -42,8 +42,8 @@ SCK上升沿驱动DOUT变动 即在SCK 下一次上升沿前读取DOUT便OK
|
|||
|
||||
HX711::HX711(Pin sck, Pin dout) : SCK(sck, true), DOUT(dout)
|
||||
{
|
||||
assert_param2(sck != P0, "SCK ERROR");
|
||||
assert_param2(dout != P0, "DOUT ERROR");
|
||||
assert(sck != P0, "SCK ERROR");
|
||||
assert(dout != P0, "DOUT ERROR");
|
||||
|
||||
// 关闭 模块
|
||||
/*SCK.Open();
|
||||
|
|
|
@ -364,7 +364,7 @@ bool ShunComMessage::Read(Stream& ms)
|
|||
{
|
||||
Kind = ms.ReadUInt16();
|
||||
Size = _REV16(ms.ReadUInt16());
|
||||
assert_param2(2 + 2 + Size == Length, "ShunComMessage::Read");
|
||||
assert(2 + 2 + Size == Length, "ShunComMessage::Read");
|
||||
//ms.Read(Data, 0, Size);
|
||||
bs.SetLength(Size);
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ void UBlox::SetBaudRate(int baudRate)
|
|||
{
|
||||
TS("UBlox::SetBaudRate");
|
||||
|
||||
assert_param2(baudRate == 115200, "目前仅支持115200波特率的设定");
|
||||
assert(baudRate == 115200, "目前仅支持115200波特率的设定");
|
||||
|
||||
// 构造波特率指令。默认115200
|
||||
byte cmd[] = {
|
||||
|
|
4
I2C.cpp
4
I2C.cpp
|
@ -209,7 +209,7 @@ void HardI2C::Init(byte index, uint speedHz)
|
|||
_index = index;
|
||||
|
||||
I2C_TypeDef* g_I2Cs[] = I2CS;
|
||||
assert_param2(_index < ArrayLength(g_I2Cs), "I2C::Init");
|
||||
assert(_index < ArrayLength(g_I2Cs), "I2C::Init");
|
||||
_IIC = g_I2Cs[_index];
|
||||
|
||||
SCL.OpenDrain = true;
|
||||
|
@ -494,7 +494,7 @@ void SoftI2C::GetPin(Pin* scl , Pin* sda )
|
|||
|
||||
void SoftI2C::OnOpen()
|
||||
{
|
||||
assert_param2(!SCL.Empty() && !SDA.Empty(), "未设置I2C引脚");
|
||||
assert(!SCL.Empty() && !SDA.Empty(), "未设置I2C引脚");
|
||||
|
||||
debug_printf("I2C::Open Addr=0x%02X \r\n", Address);
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ void Controller::Open()
|
|||
{
|
||||
if(Opened) return;
|
||||
|
||||
assert_param2(Port, "还没有传输口呢");
|
||||
assert(Port, "还没有传输口呢");
|
||||
|
||||
Port->MinSize = MinSize;
|
||||
// 注册收到数据事件
|
||||
|
@ -90,7 +90,7 @@ uint Controller::Dispatch(ITransport* port, Buffer& bs, void* param, void* param
|
|||
break;
|
||||
}
|
||||
|
||||
assert_param2(control, "控制器指针已被改变3");
|
||||
assert(control, "控制器指针已被改变3");
|
||||
assert_ptr(control);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ WeakStore::WeakStore(const char* magic, byte* ptr, uint len) : Data(0x40)
|
|||
// 检查并确保初始化,返回原来是否已初始化
|
||||
bool WeakStore::Check()
|
||||
{
|
||||
assert_param2(Magic, "未指定幻数");
|
||||
assert(Magic, "未指定幻数");
|
||||
|
||||
auto mg = (const char*)Data.GetBuffer();
|
||||
//return strcmp(mg, Magic) == 0;
|
||||
|
@ -38,7 +38,7 @@ bool WeakStore::Check()
|
|||
|
||||
void WeakStore::Init()
|
||||
{
|
||||
assert_param2(Magic, "未指定幻数");
|
||||
assert(Magic, "未指定幻数");
|
||||
|
||||
debug_printf("初始化 0x%08X,幻数 %s\r\n", Data.GetBuffer(), Magic);
|
||||
Data.Clear();
|
||||
|
|
4
Port.cpp
4
Port.cpp
|
@ -205,7 +205,7 @@ void Port::OnOpen(void* param)
|
|||
void Port::AFConfig(GPIO_AF GPIO_AF) const
|
||||
{
|
||||
#if defined(STM32F0) || defined(GD32F150) || defined(STM32F4)
|
||||
assert_param2(Opened, "打开后才能配置AF");
|
||||
assert(Opened, "打开后才能配置AF");
|
||||
|
||||
GPIO_PinAFConfig((GPIO_TypeDef*)Group, _PIN(_Pin), GPIO_AF);
|
||||
#endif
|
||||
|
@ -800,7 +800,7 @@ void InputPort::OnClose()
|
|||
// 注册回调 及中断使能
|
||||
bool InputPort::Register(IOReadHandler handler, void* param)
|
||||
{
|
||||
assert_param2(_Pin != P0, "输入注册必须先设置引脚");
|
||||
assert(_Pin != P0, "输入注册必须先设置引脚");
|
||||
|
||||
Handler = handler;
|
||||
Param = param;
|
||||
|
|
|
@ -11,7 +11,7 @@ ushort Crc::Hash16(const Buffer& arr, ushort crc)
|
|||
auto buf = arr.GetBuffer();
|
||||
int len = arr.Length();
|
||||
|
||||
assert_param2(buf, "Crc16校验目标地址不能为空");
|
||||
assert(buf, "Crc16校验目标地址不能为空");
|
||||
if (!buf || !len) return 0;
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
|
|
|
@ -345,7 +345,7 @@ void SerialPort::OnRxHandler()
|
|||
void SerialPort::ReceiveTask(void* param)
|
||||
{
|
||||
auto sp = (SerialPort*)param;
|
||||
assert_param2(sp, "串口 ReceiveTask param Error");
|
||||
assert(sp, "串口 ReceiveTask param Error");
|
||||
|
||||
//!!! 只要注释这一行,四位触摸开关就不会有串口溢出错误
|
||||
if(sp->Rx.Length() == 0) return;
|
||||
|
|
|
@ -26,7 +26,7 @@ bool BlockStorage::Read(uint address, Buffer& bs) const
|
|||
|
||||
bool BlockStorage::Write(uint address, const Buffer& bs) const
|
||||
{
|
||||
assert_param2((address & 0x01) == 0x00, "Write起始地址必须是2字节对齐");
|
||||
assert((address & 0x01) == 0x00, "Write起始地址必须是2字节对齐");
|
||||
|
||||
auto buf = bs.GetBuffer();
|
||||
uint len = bs.Length();
|
||||
|
@ -143,7 +143,7 @@ bool BlockStorage::Write(uint address, const Buffer& bs) const
|
|||
|
||||
bool BlockStorage::Memset(uint address, byte data, uint len) const
|
||||
{
|
||||
assert_param2((address & 0x01) == 0x00, "Memset起始地址必须是2字节对齐");
|
||||
assert((address & 0x01) == 0x00, "Memset起始地址必须是2字节对齐");
|
||||
|
||||
if(address < Start || address + len > Start + Size) return false;
|
||||
|
||||
|
@ -158,7 +158,7 @@ bool BlockStorage::Memset(uint address, byte data, uint len) const
|
|||
// 擦除块。起始地址,字节数量默认0表示擦除全部
|
||||
bool BlockStorage::Erase(uint address, uint len) const
|
||||
{
|
||||
assert_param2((address & 0x01) == 0x00, "Erase起始地址必须是2字节对齐");
|
||||
assert((address & 0x01) == 0x00, "Erase起始地址必须是2字节对齐");
|
||||
|
||||
if(address < Start || address + len > Start + Size) return false;
|
||||
|
||||
|
@ -193,7 +193,7 @@ bool BlockStorage::Erase(uint address, uint len) const
|
|||
/* 指定块是否被擦除 */
|
||||
bool BlockStorage::IsErased(uint address, uint len) const
|
||||
{
|
||||
assert_param2((address & 0x01) == 0x00, "IsErased起始地址必须是2字节对齐");
|
||||
assert((address & 0x01) == 0x00, "IsErased起始地址必须是2字节对齐");
|
||||
|
||||
if(address < Start || address + len > Start + Size) return false;
|
||||
|
||||
|
|
10
Stream.cpp
10
Stream.cpp
|
@ -45,7 +45,7 @@ bool Stream::CheckRemain(uint count)
|
|||
if(count > remain)
|
||||
{
|
||||
debug_printf("数据流 0x%08X 剩余容量 (%d - %d) = %d 不足 %d ,无法扩容!\r\n", this, _Capacity, _Position, remain, count);
|
||||
assert_param2(false, "无法扩容");
|
||||
assert(false, "无法扩容");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ uint Stream::Position() const { return _Position; }
|
|||
bool Stream::SetPosition(int p)
|
||||
{
|
||||
// 允许移动到最后一个字节之后,也就是Length
|
||||
//assert_param2(p <= Length, "设置的位置超出长度");
|
||||
//assert(p <= Length, "设置的位置超出长度");
|
||||
if(p < 0 && p > Length)
|
||||
{
|
||||
debug_printf("设置的位置 %d 超出长度 %d\r\n", p, Length);
|
||||
|
@ -94,7 +94,7 @@ byte* Stream::Current() const { return &_Buffer[_Position]; }
|
|||
/*// 从当前位置读取数据
|
||||
uint Stream::Read(void* buf, uint offset, int count)
|
||||
{
|
||||
assert_param2(buf, "Stream::Read buf Error");
|
||||
assert(buf, "Stream::Read buf Error");
|
||||
|
||||
if(count == 0) return 0;
|
||||
|
||||
|
@ -142,7 +142,7 @@ uint Stream::Read(Buffer& bs)
|
|||
/*// 把数据写入当前位置
|
||||
bool Stream::Write(const void* buf, uint offset, uint count)
|
||||
{
|
||||
assert_param2(buf, "Stream::Read buf Error");
|
||||
assert(buf, "Stream::Read buf Error");
|
||||
|
||||
if(!CanWrite) return false;
|
||||
if(!CheckRemain(count)) return false;
|
||||
|
@ -250,7 +250,7 @@ uint Stream::ReadArray(Buffer& bs)
|
|||
//if(len > 0x40)
|
||||
{
|
||||
debug_printf("Stream::ReadArray 缓冲区大小不足 读 %d > %d ", len, bs.Length());
|
||||
//assert_param2(len <= bs.Capacity(), "缓冲区大小不足");
|
||||
//assert(len <= bs.Capacity(), "缓冲区大小不足");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
4
Sys.cpp
4
Sys.cpp
|
@ -244,12 +244,12 @@ bool TSys::CheckMemory() const
|
|||
uint msp = __get_MSP();
|
||||
|
||||
//if(__microlib_freelist >= msp) return false;
|
||||
assert_param2(__microlib_freelist + 0x40 < msp, "堆栈相互穿透,内存已用完!可能是堆分配或野指针带来了内存泄漏!");
|
||||
assert(__microlib_freelist + 0x40 < msp, "堆栈相互穿透,内存已用完!可能是堆分配或野指针带来了内存泄漏!");
|
||||
|
||||
// 如果堆只剩下64字节,则报告失败,要求用户扩大堆空间以免不测
|
||||
//uint end = SRAM_BASE + (RAMSize << 10);
|
||||
//if(__microlib_freelist + 0x40 >= end) return false;
|
||||
assert_param2(__microlib_freelist + 0x40 < SRAM_BASE + (RAMSize << 10), "堆栈相互穿透,内存已用完!一定是堆分配带来了内存泄漏!");
|
||||
assert(__microlib_freelist + 0x40 < SRAM_BASE + (RAMSize << 10), "堆栈相互穿透,内存已用完!一定是堆分配带来了内存泄漏!");
|
||||
#endif
|
||||
|
||||
return true;
|
||||
|
|
4
Sys.h
4
Sys.h
|
@ -31,12 +31,12 @@ extern "C"
|
|||
bool assert_ptr_(const void* p);
|
||||
|
||||
void assert_failed2(const char* msg, const char* file, unsigned int line);
|
||||
#define assert_param2(expr, msg) ((expr) ? (void)0 : assert_failed2(msg, (const char*)__FILE__, __LINE__))
|
||||
#define assert(expr, msg) ((expr) ? (void)0 : assert_failed2(msg, (const char*)__FILE__, __LINE__))
|
||||
|
||||
#else
|
||||
|
||||
#define assert_ptr(expr) ((void)0)
|
||||
#define assert_param2(expr, msg) ((void)0)
|
||||
#define assert(expr, msg) ((void)0)
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -14,22 +14,22 @@ void TestArray()
|
|||
Array arr1(bs1,sizeof(bs1));
|
||||
arr1.Show(true);
|
||||
|
||||
assert_param2(arr1.GetBuffer() == (byte*)bs1&&arr1.Length()== sizeof(bs1),"Array(void* data, int len)");
|
||||
assert_param2(arr1[0] == 1, " byte& operator[](int i)");
|
||||
assert(arr1.GetBuffer() == (byte*)bs1&&arr1.Length()== sizeof(bs1),"Array(void* data, int len)");
|
||||
assert(arr1[0] == 1, " byte& operator[](int i)");
|
||||
|
||||
//Buffer buf(bs2,sizeof(bs2));
|
||||
arr1 = bs2;
|
||||
assert_param2(arr1[0] == bs2[0]&&arr1[3] == bs2[3], "Array& operator = (const void* p);");
|
||||
assert(arr1[0] == bs2[0]&&arr1[3] == bs2[3], "Array& operator = (const void* p);");
|
||||
|
||||
arr1.Clear();
|
||||
assert_param2(arr1[1] == 0, "virtual void Clear()");
|
||||
assert(arr1[1] == 0, "virtual void Clear()");
|
||||
|
||||
arr1.Set(bs1,sizeof(bs1));
|
||||
assert_param2(arr1== bs1, "bool Set(void* data, int len)");
|
||||
assert(arr1== bs1, "bool Set(void* data, int len)");
|
||||
|
||||
arr1.SetItem((void*)bs3,0,sizeof(bs3));
|
||||
arr1.Show(true);
|
||||
assert_param2(arr1[0] == 10&& arr1.Length() == sizeof(bs3) , "bool SetItem(const void* data, int index, int count);");
|
||||
assert(arr1[0] == 10&& arr1.Length() == sizeof(bs3) , "bool SetItem(const void* data, int index, int count);");
|
||||
|
||||
debug_printf("Array测试完毕....../r/n");
|
||||
|
||||
|
|
|
@ -10,8 +10,8 @@ void TestBuffer()
|
|||
char cs[] = "This is Buffer Test.";
|
||||
Buffer bs(cs, sizeof(cs));
|
||||
debug_printf("Buffer bs(cs, strlen(cs)) => %s\r\n", cs);
|
||||
assert_param2(bs.GetBuffer() == (byte*)cs, "Buffer(void* p = nullptr, int len = 0)");
|
||||
assert_param2(bs == cs, "Buffer(void* p = nullptr, int len = 0)");
|
||||
assert(bs.GetBuffer() == (byte*)cs, "Buffer(void* p = nullptr, int len = 0)");
|
||||
assert(bs == cs, "Buffer(void* p = nullptr, int len = 0)");
|
||||
|
||||
byte buf[5];
|
||||
buf[4] = '\0';
|
||||
|
@ -20,70 +20,70 @@ void TestBuffer()
|
|||
//bs2 = bs;
|
||||
bs2.Copy(0, bs, 0, -1);
|
||||
debug_printf("bs2 = bs => %s\r\n", buf);
|
||||
assert_param2(bs2.GetBuffer() != bs.GetBuffer(), "Buffer& operator = (const Buffer& rhs)");
|
||||
assert_param2(bs2 != bs, "Buffer& operator = (const Buffer& rhs)");
|
||||
assert_param2(bs2.Length() == 4, "Buffer& operator = (const Buffer& rhs)");
|
||||
assert_param2(bs2 == cs, "Buffer& operator = (const Buffer& rhs)");
|
||||
assert(bs2.GetBuffer() != bs.GetBuffer(), "Buffer& operator = (const Buffer& rhs)");
|
||||
assert(bs2 != bs, "Buffer& operator = (const Buffer& rhs)");
|
||||
assert(bs2.Length() == 4, "Buffer& operator = (const Buffer& rhs)");
|
||||
assert(bs2 == cs, "Buffer& operator = (const Buffer& rhs)");
|
||||
|
||||
// 从指针拷贝,使用我的长度
|
||||
bs2 = cs + 8;
|
||||
debug_printf("bs2 = cs + 8 => %s\r\n", buf);
|
||||
assert_param2(bs2.GetBuffer() != (byte*)(cs + 8), "Buffer& operator = (const void* p)");
|
||||
assert_param2(bs2.Length() == 4, "Buffer& operator = (const void* p)");
|
||||
assert_param2(bs2 == cs + 8, "Buffer& operator = (const void* p)");
|
||||
assert(bs2.GetBuffer() != (byte*)(cs + 8), "Buffer& operator = (const void* p)");
|
||||
assert(bs2.Length() == 4, "Buffer& operator = (const void* p)");
|
||||
assert(bs2 == cs + 8, "Buffer& operator = (const void* p)");
|
||||
|
||||
// 设置数组长度。只能缩小不能扩大,子类可以扩展以实现自动扩容
|
||||
bs.SetLength(11);
|
||||
cs[11] = '\0';
|
||||
debug_printf("SetLength(11) => %s\r\n", cs);
|
||||
assert_param2(bs.Length() == 11, "bool SetLength(int len, bool bak = false)");
|
||||
assert_param2(bs == cs, "bool SetLength(int len, bool bak = false)");
|
||||
assert(bs.Length() == 11, "bool SetLength(int len, bool bak = false)");
|
||||
assert(bs == cs, "bool SetLength(int len, bool bak = false)");
|
||||
|
||||
// 索引访问
|
||||
bs[8]++;
|
||||
debug_printf("bs[8]++ => %s\r\n", cs);
|
||||
assert_param2(cs[8] == 'C', "byte& operator[](int i)");
|
||||
assert_param2(bs == cs, "byte& operator[](int i)");
|
||||
assert(cs[8] == 'C', "byte& operator[](int i)");
|
||||
assert(bs == cs, "byte& operator[](int i)");
|
||||
|
||||
// 拷贝数据,默认-1长度表示当前长度
|
||||
char abc[] = "abcd";
|
||||
bs.Copy(5, abc, strlen(abc));
|
||||
debug_printf("Copy(5, \"abcd\", %d) => %s\r\n", strlen(abc), cs);
|
||||
assert_param2(cs[5] == 'a' && cs[8] == 'd', "int Copy(int destIndex, const void* src, int len)");
|
||||
assert(cs[5] == 'a' && cs[8] == 'd', "int Copy(int destIndex, const void* src, int len)");
|
||||
|
||||
// 把数据复制到目标缓冲区,默认-1长度表示当前长度
|
||||
char ef[4];
|
||||
ef[3] = 0;
|
||||
bs.CopyTo(1, ef, 3);
|
||||
debug_printf("CopyTo(1, ef, 3) => %s\r\n", ef);
|
||||
assert_param2(ef[0] == 'h' && ef[2] == 's', "int CopyTo(int srcIndex, void* dest, int len)");
|
||||
assert(ef[0] == 'h' && ef[2] == 's', "int CopyTo(int srcIndex, void* dest, int len)");
|
||||
|
||||
// 用指定字节设置初始化一个区域
|
||||
bs.Set('x', 3, 2);
|
||||
debug_printf("Set('x', 3, 2) => %s\r\n", cs);
|
||||
assert_param2(cs[3] == 'x' || cs[4] == 'x', "int Set(byte item, int index, int len)");
|
||||
assert(cs[3] == 'x' || cs[4] == 'x', "int Set(byte item, int index, int len)");
|
||||
|
||||
// 截取一个子缓冲区
|
||||
auto bs3 = bs.Sub(3, 2);
|
||||
debug_printf("bs.Sub(3, 2) => %s\r\n", bs3.GetBuffer());
|
||||
assert_param2(bs3.GetBuffer() == (byte*)(cs + 3), "Buffer Sub(int index, int len)");
|
||||
assert_param2(bs3[0] == 'x' || bs3[1] == 'x', "Buffer Sub(int index, int len)");
|
||||
assert(bs3.GetBuffer() == (byte*)(cs + 3), "Buffer Sub(int index, int len)");
|
||||
assert(bs3[0] == 'x' || bs3[1] == 'x', "Buffer Sub(int index, int len)");
|
||||
|
||||
bs.Clear();
|
||||
assert_param2(cs[0] == 0 && cs[bs.Length() - 1] == 0, "void Clear()");
|
||||
assert(cs[0] == 0 && cs[bs.Length() - 1] == 0, "void Clear()");
|
||||
|
||||
// 转为十六进制字符串
|
||||
byte bts[] = { 0xAB, 0x34, 0xfe };
|
||||
Buffer bs4(bts, 3);
|
||||
auto str = bs4.ToHex('#', 2);
|
||||
assert_param2(str == "AB#34\r\nFE", "String ToHex(char sep = 0, int newLine = 0)");
|
||||
assert(str == "AB#34\r\nFE", "String ToHex(char sep = 0, int newLine = 0)");
|
||||
auto str2 = bs4.ToString();
|
||||
assert_param2(str2 == "AB-34-FE", "String ToString()");
|
||||
assert(str2 == "AB-34-FE", "String ToString()");
|
||||
|
||||
Buffer bs5(cs);
|
||||
debug_printf("Buffer(T (&arr)[N]) => %s\r\n", cs);
|
||||
assert_param2(bs5.GetBuffer() == (byte*)cs, "Buffer(T (&arr)[N])");
|
||||
assert_param2(bs5 == cs, "Buffer(void* p = nullptr, int len = 0)");
|
||||
assert(bs5.GetBuffer() == (byte*)cs, "Buffer(T (&arr)[N])");
|
||||
assert(bs5 == cs, "Buffer(void* p = nullptr, int len = 0)");
|
||||
|
||||
Buffer bs7(cs);
|
||||
|
||||
|
|
|
@ -17,21 +17,21 @@ static void TestCtor()
|
|||
debug_printf("字符串构造函数测试\r\n");
|
||||
|
||||
String str1("456");
|
||||
assert_param2(str1 == "456", "String(const char* cstr)");
|
||||
assert_param2(str1.GetBuffer() != "456", "String(const char* cstr)");
|
||||
assert(str1 == "456", "String(const char* cstr)");
|
||||
assert(str1.GetBuffer() != "456", "String(const char* cstr)");
|
||||
|
||||
String str2(str1);
|
||||
assert_param2(str2 == str1, "String(const String& str)");
|
||||
assert_param2(str2.GetBuffer() != str1.GetBuffer(), "String(const String& str)");
|
||||
assert(str2 == str1, "String(const String& str)");
|
||||
assert(str2.GetBuffer() != str1.GetBuffer(), "String(const String& str)");
|
||||
|
||||
//StringHelper str3(str1);
|
||||
//assert_param2(str3 == str1, "String(StringHelper&& rval)");
|
||||
//assert_param2(str3.GetBuffer() != str1.GetBuffer(), "String(StringHelper&& rval)");
|
||||
//assert(str3 == str1, "String(StringHelper&& rval)");
|
||||
//assert(str3.GetBuffer() != str1.GetBuffer(), "String(StringHelper&& rval)");
|
||||
|
||||
char cs[] = "Hello Buffer";
|
||||
String str4(cs, sizeof(cs));
|
||||
assert_param2(str4 == cs, "String(char* str, int length)");
|
||||
assert_param2(str4.GetBuffer() == cs, "String(char* str, int length)");
|
||||
assert(str4 == cs, "String(char* str, int length)");
|
||||
assert(str4.GetBuffer() == cs, "String(char* str, int length)");
|
||||
|
||||
/*debug_printf("move测试\r\n");
|
||||
auto tt = TestMove(str1);
|
||||
|
@ -39,7 +39,7 @@ static void TestCtor()
|
|||
str1.Show(true);*/
|
||||
|
||||
String str5((char)'1');
|
||||
assert_param2(str5 == "1", "String(char c)");
|
||||
assert(str5 == "1", "String(char c)");
|
||||
}
|
||||
|
||||
void TestNum10()
|
||||
|
@ -48,33 +48,33 @@ void TestNum10()
|
|||
|
||||
debug_printf("10进制构造函数:.....\r\n");
|
||||
String str1((byte)123, 10);
|
||||
assert_param2(str1 == "123", "String(byte value, int radix = 10)");
|
||||
assert(str1 == "123", "String(byte value, int radix = 10)");
|
||||
|
||||
String str2((short)4567, 10);
|
||||
assert_param2(str2 == "4567", "String(short value, int radix = 10)");
|
||||
assert(str2 == "4567", "String(short value, int radix = 10)");
|
||||
|
||||
String str3((int)-88996677, 10);
|
||||
assert_param2(str3 == "-88996677", "String(int value, int radix = 10)");
|
||||
assert(str3 == "-88996677", "String(int value, int radix = 10)");
|
||||
|
||||
String str4((uint)0xFFFFFFFF, 10);
|
||||
assert_param2(str4 == "4294967295", "String(uint value, int radix = 10)");
|
||||
assert(str4 == "4294967295", "String(uint value, int radix = 10)");
|
||||
|
||||
String str5((Int64)-7744, 10);
|
||||
assert_param2(str5 == "-7744", "String(Int64 value, int radix = 10)");
|
||||
assert(str5 == "-7744", "String(Int64 value, int radix = 10)");
|
||||
|
||||
String str6((UInt64)331144, 10);
|
||||
assert_param2(str6 == "331144", "String(UInt64 value, int radix = 10)");
|
||||
assert(str6 == "331144", "String(UInt64 value, int radix = 10)");
|
||||
|
||||
// 默认2位小数,所以字符串要补零
|
||||
String str7((float)123.0);
|
||||
assert_param2(str7 == "123.00", "String(float value, int decimalPlaces = 2)");
|
||||
assert(str7 == "123.00", "String(float value, int decimalPlaces = 2)");
|
||||
|
||||
// 浮点数格式化的时候,如果超过要求小数位数,则会四舍五入
|
||||
String str8((double)456.784);
|
||||
assert_param2(str8 == "456.78", "String(double value, int decimalPlaces = 2)");
|
||||
assert(str8 == "456.78", "String(double value, int decimalPlaces = 2)");
|
||||
|
||||
String str9((double)456.789);
|
||||
assert_param2(str9 == "456.79", "String(double value, int decimalPlaces = 2)");
|
||||
assert(str9 == "456.79", "String(double value, int decimalPlaces = 2)");
|
||||
}
|
||||
|
||||
void TestNum16()
|
||||
|
@ -83,23 +83,23 @@ void TestNum16()
|
|||
|
||||
debug_printf("16进制构造函数:.....\r\n");
|
||||
String str1((byte)0xA3, 16);
|
||||
assert_param2(str1 == "a3", "String(byte value, int radix = 16)");
|
||||
assert_param2(String((byte)0xA3, -16) == "A3", "String(byte value, int radix = 16)");
|
||||
assert(str1 == "a3", "String(byte value, int radix = 16)");
|
||||
assert(String((byte)0xA3, -16) == "A3", "String(byte value, int radix = 16)");
|
||||
|
||||
String str2((short)0x4567, 16);
|
||||
assert_param2(str2 == "4567", "String(short value, int radix = 16)");
|
||||
assert(str2 == "4567", "String(short value, int radix = 16)");
|
||||
|
||||
String str3((int)-0x7799, 16);
|
||||
assert_param2(str3 == "ffff8867", "String(int value, int radix = 16)");
|
||||
assert(str3 == "ffff8867", "String(int value, int radix = 16)");
|
||||
|
||||
String str4((uint)0xFFFFFFFF, 16);
|
||||
assert_param2(str4 == "ffffffff", "String(uint value, int radix = 16)");
|
||||
assert(str4 == "ffffffff", "String(uint value, int radix = 16)");
|
||||
|
||||
String str5((Int64)0x331144997AC45566, 16);
|
||||
assert_param2(str5 == "331144997ac45566", "String(Int64 value, int radix = 16)");
|
||||
assert(str5 == "331144997ac45566", "String(Int64 value, int radix = 16)");
|
||||
|
||||
String str6((UInt64)0x331144997AC45566, -16);
|
||||
assert_param2(str6 == "331144997AC45566", "String(UInt64 value, int radix = 16)");
|
||||
assert(str6 == "331144997AC45566", "String(UInt64 value, int radix = 16)");
|
||||
}
|
||||
|
||||
static void TestAssign()
|
||||
|
@ -111,12 +111,12 @@ static void TestAssign()
|
|||
String str = "万家灯火,无声物联!";
|
||||
debug_printf("TestAssign: %s\r\n", str.GetBuffer());
|
||||
str = "无声物联";
|
||||
assert_param2(str == "无声物联", "String& operator = (const char* cstr)");
|
||||
assert(str == "无声物联", "String& operator = (const char* cstr)");
|
||||
|
||||
String str2 = "xxx";
|
||||
str2 = str;
|
||||
assert_param2(str == "无声物联", "String& operator = (const char* cstr)");
|
||||
assert_param2(str2.GetBuffer() != str.GetBuffer(), "String& operator = (const String& rhs)");
|
||||
assert(str == "无声物联", "String& operator = (const char* cstr)");
|
||||
assert(str2.GetBuffer() != str.GetBuffer(), "String& operator = (const String& rhs)");
|
||||
}
|
||||
|
||||
static void TestConcat()
|
||||
|
@ -135,13 +135,13 @@ static void TestConcat()
|
|||
str += now;
|
||||
//str.Show(true);
|
||||
// yyyy-MM-dd HH:mm:ss
|
||||
assert_param2(str.Length() == 19, "String& operator += (const Object& rhs)");
|
||||
assert(str.Length() == 19, "String& operator += (const Object& rhs)");
|
||||
|
||||
// 连接其它字符串
|
||||
int len = str.Length();
|
||||
String str2(" 中国时间");
|
||||
str += str2;
|
||||
assert_param2(str.Length() == len + str2.Length(), "String& operator += (const String& rhs)");
|
||||
assert(str.Length() == len + str2.Length(), "String& operator += (const String& rhs)");
|
||||
|
||||
// 连接C格式字符串
|
||||
str += " ";
|
||||
|
@ -149,7 +149,7 @@ static void TestConcat()
|
|||
// 连接整数
|
||||
len = str.Length();
|
||||
str += 1234;
|
||||
assert_param2(str.Length() == len + 4, "String& operator += (int num)");
|
||||
assert(str.Length() == len + 4, "String& operator += (int num)");
|
||||
|
||||
// 连接C格式字符串
|
||||
str += " ";
|
||||
|
@ -158,7 +158,7 @@ static void TestConcat()
|
|||
len = str.Length();
|
||||
str += -1234.8856; // 特别注意,默认2位小数,所以字符串是-1234.89
|
||||
str.Show(true);
|
||||
assert_param2(str.Length() == len + 8, "String& operator += (double num)");
|
||||
assert(str.Length() == len + 8, "String& operator += (double num)");
|
||||
}
|
||||
|
||||
static void TestConcat16()
|
||||
|
@ -180,7 +180,7 @@ static void TestConcat16()
|
|||
|
||||
str.Show(true);
|
||||
// 十六进制连接测试 20 @ 00000e3f # 00073F88
|
||||
assert_param2(str == "十六进制连接测试 20 @ 00000e3f # 00073F88", "bool Concat(int num, int radix = 16)");
|
||||
assert(str == "十六进制连接测试 20 @ 00000e3f # 00073F88", "bool Concat(int num, int radix = 16)");
|
||||
}
|
||||
|
||||
static void TestAdd()
|
||||
|
@ -191,7 +191,7 @@ static void TestAdd()
|
|||
str = str + 1234 + "#" + R("99xx") + '$' + -33.883 + "@" + Time.Now();
|
||||
str.Show(true);
|
||||
// 字符串连加 1234@0000-00-00 00:00:00#99xx
|
||||
assert_param2(str.Contains("字符串连加 1234#99xx$-33.88@"), "friend StringHelper& operator + (const StringHelper& lhs, const char* cstr)");
|
||||
assert(str.Contains("字符串连加 1234#99xx$-33.88@"), "friend StringHelper& operator + (const StringHelper& lhs, const char* cstr)");
|
||||
}
|
||||
|
||||
static void TestEquals()
|
||||
|
@ -202,8 +202,8 @@ static void TestEquals()
|
|||
|
||||
String str1 = "TestABC HH";
|
||||
String str2 = "TESTABC HH";
|
||||
assert_param2(str1 >= str2, "bool operator < (const String& rhs) const");
|
||||
assert_param2(str1.EqualsIgnoreCase(str2), "bool EqualsIgnoreCase(const String& s)");
|
||||
assert(str1 >= str2, "bool operator < (const String& rhs) const");
|
||||
assert(str1.EqualsIgnoreCase(str2), "bool EqualsIgnoreCase(const String& s)");
|
||||
}
|
||||
|
||||
static void TestSet()
|
||||
|
@ -213,45 +213,45 @@ static void TestSet()
|
|||
debug_printf("字符串设置测试\r\n");
|
||||
|
||||
String str = "ABCDEFG";
|
||||
assert_param2(str[3] == 'D', "char operator [] (int index)");
|
||||
assert(str[3] == 'D', "char operator [] (int index)");
|
||||
|
||||
str[5] = 'W';
|
||||
assert_param2(str[5] == 'W', "char& operator [] (int index)");
|
||||
assert(str[5] == 'W', "char& operator [] (int index)");
|
||||
//debug_printf("%s 的第 %d 个字符是 %c \r\n", str.GetBuffer(), 5, str[5]);
|
||||
|
||||
str = "我是ABC";
|
||||
int len = str.Length();
|
||||
auto bs = str.GetBytes();
|
||||
assert_param2(bs.Length() == str.Length(), "ByteArray GetBytes() const");
|
||||
assert_param2(bs[len - 1] == (byte)'C', "ByteArray GetBytes() const");
|
||||
//assert_param2(bs.GetBuffer() == (byte*)str.GetBuffer(), "ByteArray GetBytes() const");
|
||||
assert(bs.Length() == str.Length(), "ByteArray GetBytes() const");
|
||||
assert(bs[len - 1] == (byte)'C', "ByteArray GetBytes() const");
|
||||
//assert(bs.GetBuffer() == (byte*)str.GetBuffer(), "ByteArray GetBytes() const");
|
||||
|
||||
// 十六进制字符串转为二进制数组
|
||||
str = "36-1f-36-35-34-3F-31-31-32-30-32-34";
|
||||
auto bs2 = str.ToHex();
|
||||
bs2.Show(true);
|
||||
assert_param2(bs2.Length() == 12, "ByteArray ToHex()");
|
||||
assert_param2(bs2[1] == 0x1F, "ByteArray ToHex()");
|
||||
assert_param2(bs2[5] == 0x3F, "ByteArray ToHex()");
|
||||
assert(bs2.Length() == 12, "ByteArray ToHex()");
|
||||
assert(bs2[1] == 0x1F, "ByteArray ToHex()");
|
||||
assert(bs2[5] == 0x3F, "ByteArray ToHex()");
|
||||
|
||||
// 字符串搜索
|
||||
assert_param2(str.IndexOf("36") == 0, "int IndexOf(const char* str, int startIndex = 0)");
|
||||
assert_param2(str.IndexOf("36", 1) == 6, "int IndexOf(const char* str, int startIndex = 0)");
|
||||
assert_param2(str.LastIndexOf("36", 6) == 6, "int LastIndexOf(const char* str, int startIndex = 0)");
|
||||
assert_param2(str.LastIndexOf("36", 7) == -1, "int LastIndexOf(const char* str, int startIndex = 0)");
|
||||
assert_param2(str.Contains("34-3F-31"), "bool Contains(const char* str) const");
|
||||
assert_param2(str.StartsWith("36-"), "bool StartsWith(const char* str, int startIndex = 0)");
|
||||
assert_param2(str.EndsWith("-32-34"), "bool EndsWith(const char* str)");
|
||||
assert(str.IndexOf("36") == 0, "int IndexOf(const char* str, int startIndex = 0)");
|
||||
assert(str.IndexOf("36", 1) == 6, "int IndexOf(const char* str, int startIndex = 0)");
|
||||
assert(str.LastIndexOf("36", 6) == 6, "int LastIndexOf(const char* str, int startIndex = 0)");
|
||||
assert(str.LastIndexOf("36", 7) == -1, "int LastIndexOf(const char* str, int startIndex = 0)");
|
||||
assert(str.Contains("34-3F-31"), "bool Contains(const char* str) const");
|
||||
assert(str.StartsWith("36-"), "bool StartsWith(const char* str, int startIndex = 0)");
|
||||
assert(str.EndsWith("-32-34"), "bool EndsWith(const char* str)");
|
||||
|
||||
// 字符串截取
|
||||
str = " 36-1f-36-35-34\n";
|
||||
len = str.Length();
|
||||
str = str.Trim();
|
||||
assert_param2(str.Length() == len - 2, "String& Trim()");
|
||||
assert(str.Length() == len - 2, "String& Trim()");
|
||||
|
||||
str = str.Substring(3, 5).ToUpper();
|
||||
str.Show(true);
|
||||
assert_param2(str == "1F-36", "String Substring(int start, int _Length)");
|
||||
assert(str == "1F-36", "String Substring(int start, int _Length)");
|
||||
}
|
||||
|
||||
void TestString()
|
||||
|
|
|
@ -113,7 +113,7 @@ void Timer::Open()
|
|||
|
||||
uint fre = clk / Prescaler / Period;
|
||||
debug_printf("Timer%d::Open clk=%d Prescaler=%d Period=%d Fre=%d\r\n", _index + 1, clk, Prescaler, Period, fre);
|
||||
assert_param2(fre > 0, "频率超出范围");
|
||||
assert(fre > 0, "频率超出范围");
|
||||
#endif
|
||||
|
||||
// 打开时钟
|
||||
|
@ -215,7 +215,7 @@ void Timer::SetFrequency(uint frequency)
|
|||
Div++;
|
||||
}
|
||||
|
||||
assert_param2(frequency > 0 && frequency <= clk, "频率超出范围");
|
||||
assert(frequency > 0 && frequency <= clk, "频率超出范围");
|
||||
|
||||
Prescaler = psc;
|
||||
Period = prd;
|
||||
|
|
|
@ -107,7 +107,7 @@ bool IcmpSocket::Process(IP_HEADER& ip, Stream& ms)
|
|||
// Ping目的地址,附带a~z重复的负载数据
|
||||
bool IcmpSocket::Ping(IPAddress& ip, uint payloadLength)
|
||||
{
|
||||
assert_param2(this, "非法调用Icmp");
|
||||
assert(this, "非法调用Icmp");
|
||||
assert_ptr(this);
|
||||
|
||||
byte buf[sizeof(ETH_HEADER) + sizeof(IP_HEADER) + sizeof(ICMP_HEADER) + 64];
|
||||
|
|
|
@ -271,7 +271,7 @@ void TinyIP::ShowInfo()
|
|||
bool TinyIP::SendEthernet(ETH_TYPE type, const MacAddress& remote, const byte* buf, uint len)
|
||||
{
|
||||
auto eth = (ETH_HEADER*)(buf - sizeof(ETH_HEADER));
|
||||
assert_param2(IS_ETH_TYPE(type), "这个不是以太网类型");
|
||||
assert(IS_ETH_TYPE(type), "这个不是以太网类型");
|
||||
|
||||
eth->Type = type;
|
||||
eth->DestMac = remote;
|
||||
|
@ -300,7 +300,7 @@ bool TinyIP::SendEthernet(ETH_TYPE type, const MacAddress& remote, const byte* b
|
|||
bool TinyIP::SendIP(IP_TYPE type, const IPAddress& remote, const byte* buf, uint len)
|
||||
{
|
||||
IP_HEADER* ip = (IP_HEADER*)(buf - sizeof(IP_HEADER));
|
||||
assert_param2(IS_IP_TYPE(type), "这个不是IP消息类型");
|
||||
assert(IS_IP_TYPE(type), "这个不是IP消息类型");
|
||||
|
||||
ip->DestIP = remote.Value;
|
||||
ip->SrcIP = IP.Value;
|
||||
|
@ -430,7 +430,7 @@ bool TinyIP::IsBroadcast(const IPAddress& ip)
|
|||
|
||||
TinySocket::TinySocket(TinyIP* tip, IP_TYPE type)
|
||||
{
|
||||
assert_param2(tip, "空的Tip");
|
||||
assert(tip, "空的Tip");
|
||||
|
||||
Tip = tip;
|
||||
Type = type;
|
||||
|
@ -455,7 +455,7 @@ TinySocket::TinySocket(TinyIP* tip, IP_TYPE type)
|
|||
|
||||
TinySocket::~TinySocket()
|
||||
{
|
||||
assert_param2(Tip, "空的Tip");
|
||||
assert(Tip, "空的Tip");
|
||||
|
||||
Enable = false;
|
||||
// 从TinyIP中删除当前Socket
|
||||
|
|
|
@ -62,7 +62,7 @@ bool UdpSocket::Process(IP_HEADER& ip, Stream& ms)
|
|||
byte* data = udp->Next();
|
||||
uint len = ms.Remain();
|
||||
uint plen = _REV16(udp->Length);
|
||||
assert_param2(len + sizeof(UDP_HEADER) == plen, "UDP数据包标称长度与实际不符");
|
||||
assert(len + sizeof(UDP_HEADER) == plen, "UDP数据包标称长度与实际不符");
|
||||
#endif
|
||||
|
||||
OnProcess(ip, *udp, ms);
|
||||
|
@ -76,7 +76,7 @@ void UdpSocket::OnProcess(IP_HEADER& ip, UDP_HEADER& udp, Stream& ms)
|
|||
//uint len = ms.Remain();
|
||||
// 计算标称的数据长度
|
||||
uint len = _REV16(udp.Length) - sizeof(UDP_HEADER);
|
||||
assert_param2(len <= ms.Remain(), "UDP数据包不完整");
|
||||
assert(len <= ms.Remain(), "UDP数据包不完整");
|
||||
|
||||
// 触发ITransport接口事件
|
||||
Buffer bs(data, len);
|
||||
|
|
|
@ -89,8 +89,8 @@ void TinyClient::Close()
|
|||
/******************************** 收发中心 ********************************/
|
||||
bool TinyClient::Send(TinyMessage& msg)
|
||||
{
|
||||
assert_param2(this, "令牌客户端未初始化");
|
||||
assert_param2(Control, "令牌控制器未初始化");
|
||||
assert(this, "令牌客户端未初始化");
|
||||
assert(Control, "令牌控制器未初始化");
|
||||
|
||||
// 未组网时,禁止发其它消息。组网消息通过广播发出,不经过这里
|
||||
if(!Server) return false;
|
||||
|
@ -103,8 +103,8 @@ bool TinyClient::Send(TinyMessage& msg)
|
|||
|
||||
bool TinyClient::Reply(TinyMessage& msg)
|
||||
{
|
||||
assert_param2(this, "令牌客户端未初始化");
|
||||
assert_param2(Control, "令牌控制器未初始化");
|
||||
assert(this, "令牌客户端未初始化");
|
||||
assert(Control, "令牌控制器未初始化");
|
||||
|
||||
// 未组网时,禁止发其它消息。组网消息通过广播发出,不经过这里
|
||||
if(!Server) return false;
|
||||
|
@ -271,7 +271,7 @@ void TinyClientTask(void* param)
|
|||
auto client = (TinyClient*)param;
|
||||
uint offset = client->NextReport;
|
||||
uint len = client->NextReportLength;
|
||||
assert_param2(offset == 0 || offset < 0x10, "自动上报偏移量异常!");
|
||||
assert(offset == 0 || offset < 0x10, "自动上报偏移量异常!");
|
||||
|
||||
if(offset)
|
||||
{
|
||||
|
|
|
@ -94,9 +94,9 @@ bool TinyMessage::Read(Stream& ms)
|
|||
|
||||
void TinyMessage::Write(Stream& ms) const
|
||||
{
|
||||
assert_param2(Code, "微网指令码不能为空");
|
||||
assert_param2(Src, "微网源地址不能为空");
|
||||
//assert_param2(Src != Dest, "微网目的地址不能等于源地址");
|
||||
assert(Code, "微网指令码不能为空");
|
||||
assert(Src, "微网源地址不能为空");
|
||||
//assert(Src != Dest, "微网目的地址不能等于源地址");
|
||||
if(Src == Dest) return;
|
||||
|
||||
TS("TinyMessage::Write");
|
||||
|
@ -276,7 +276,7 @@ void TinyController::Open()
|
|||
{
|
||||
if(Opened) return;
|
||||
|
||||
assert_param2(Port, "还没有传输口呢");
|
||||
assert(Port, "还没有传输口呢");
|
||||
|
||||
#if MSG_DEBUG
|
||||
debug_printf("TinyNet::Inited Address=%d (0x%02X) 使用传输接口 ", Address, Address);
|
||||
|
|
|
@ -71,7 +71,7 @@ void TinyServer::Start()
|
|||
{
|
||||
TS("TinyServer::Start");
|
||||
|
||||
assert_param2(Cfg, "未指定微网服务器的配置");
|
||||
assert(Cfg, "未指定微网服务器的配置");
|
||||
|
||||
//LoadConfig();
|
||||
auto count = LoadDevices();
|
||||
|
|
|
@ -39,8 +39,8 @@ void Gateway::Start()
|
|||
|
||||
TS("Gateway::Start");
|
||||
|
||||
assert_param2(Server, "微网服务端未设置");
|
||||
assert_param2(Client, "令牌客户端未设置");
|
||||
assert(Server, "微网服务端未设置");
|
||||
assert(Client, "令牌客户端未设置");
|
||||
|
||||
Server->Received = [](void* s, Message& msg, void* p){ return ((Gateway*)p)->OnLocal((TinyMessage&)msg); };
|
||||
Server->Param = this;
|
||||
|
|
|
@ -35,7 +35,7 @@ TokenClient::TokenClient()
|
|||
|
||||
void TokenClient::Open()
|
||||
{
|
||||
assert_param2(Control, "令牌客户端还没设置控制器呢");
|
||||
assert(Control, "令牌客户端还没设置控制器呢");
|
||||
|
||||
Control->Received = OnTokenClientReceived;
|
||||
Control->Param = this;
|
||||
|
@ -74,7 +74,7 @@ bool TokenClient::Send(TokenMessage& msg, Controller* ctrl)
|
|||
}
|
||||
|
||||
if(!ctrl) ctrl = Control;
|
||||
assert_param2(ctrl, "TokenClient::Send");
|
||||
assert(ctrl, "TokenClient::Send");
|
||||
|
||||
return ctrl->Send(msg);
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ bool TokenClient::Reply(TokenMessage& msg, Controller* ctrl)
|
|||
}
|
||||
|
||||
if(!ctrl) ctrl = Control;
|
||||
assert_param2(ctrl, "TokenClient::Reply");
|
||||
assert(ctrl, "TokenClient::Reply");
|
||||
|
||||
return ctrl->Reply(msg);
|
||||
}
|
||||
|
|
|
@ -157,7 +157,7 @@ void TokenController::Open()
|
|||
{
|
||||
if(Opened) return;
|
||||
|
||||
assert_param2(Port, "还没有传输口呢");
|
||||
assert(Port, "还没有传输口呢");
|
||||
|
||||
debug_printf("TokenNet::Inited 使用传输接口 ");
|
||||
#if DEBUG
|
||||
|
|
28
Type.cpp
28
Type.cpp
|
@ -115,7 +115,7 @@ Buffer& Buffer::operator = (Buffer&& rval)
|
|||
// 重载索引运算符[],返回指定元素的第一个字节
|
||||
byte Buffer::operator[](int i) const
|
||||
{
|
||||
assert_param2(i >= 0 && i < _Length, "下标越界");
|
||||
assert(i >= 0 && i < _Length, "下标越界");
|
||||
|
||||
byte* buf = (byte*)_Arr;
|
||||
|
||||
|
@ -124,7 +124,7 @@ byte Buffer::operator[](int i) const
|
|||
|
||||
byte& Buffer::operator[](int i)
|
||||
{
|
||||
assert_param2(i >= 0 && i < _Length, "下标越界");
|
||||
assert(i >= 0 && i < _Length, "下标越界");
|
||||
|
||||
byte* buf = (byte*)_Arr;
|
||||
|
||||
|
@ -164,7 +164,7 @@ int Buffer::Copy(int destIndex, const void* src, int len)
|
|||
if(!SetLength(destIndex + len))
|
||||
{
|
||||
debug_printf("Buffer::Copy 缓冲区 0x%08X %d 太小,不足以拷贝 0x%08X %d \r\n", _Arr + destIndex, _Length, src, len);
|
||||
assert_param2(false, "Buffer::Copy 缓冲区太小");
|
||||
assert(false, "Buffer::Copy 缓冲区太小");
|
||||
|
||||
len = remain;
|
||||
}
|
||||
|
@ -241,7 +241,7 @@ void Buffer::Clear(byte item)
|
|||
Buffer Buffer::Sub(int index, int len)
|
||||
{
|
||||
if(len < 0) len = _Length - index;
|
||||
assert_param2(index + len <= _Length, "len <= _Length");
|
||||
assert(index + len <= _Length, "len <= _Length");
|
||||
|
||||
return Buffer((byte*)_Arr + index, len);
|
||||
|
||||
|
@ -255,7 +255,7 @@ Buffer Buffer::Sub(int index, int len)
|
|||
const Buffer Buffer::Sub(int index, int len) const
|
||||
{
|
||||
if(len < 0) len = _Length - index;
|
||||
assert_param2(index + len <= _Length, "len <= _Length");
|
||||
assert(index + len <= _Length, "len <= _Length");
|
||||
|
||||
return Buffer((byte*)_Arr + index, len);
|
||||
|
||||
|
@ -496,12 +496,12 @@ void Array::SetBuffer(const void* ptr, int len)
|
|||
// 设置数组元素为指定值,自动扩容
|
||||
bool Array::SetItem(const void* data, int index, int count)
|
||||
{
|
||||
assert_param2(_canWrite, "禁止SetItem修改");
|
||||
assert_param2(data, "Array::SetItem data Error");
|
||||
assert(_canWrite, "禁止SetItem修改");
|
||||
assert(data, "Array::SetItem data Error");
|
||||
|
||||
// count<=0 表示设置全部元素
|
||||
if(count <= 0) count = _Length - index;
|
||||
assert_param2(count > 0, "Array::SetItem count Error");
|
||||
assert(count > 0, "Array::SetItem count Error");
|
||||
|
||||
// 检查长度是否足够
|
||||
int len2 = index + count;
|
||||
|
@ -554,8 +554,8 @@ bool Array::Set(const void* data, int len)
|
|||
// 清空已存储数据。
|
||||
void Array::Clear()
|
||||
{
|
||||
assert_param2(_canWrite, "禁止Clear修改");
|
||||
assert_param2(_Arr, "Clear数据不能为空指针");
|
||||
assert(_canWrite, "禁止Clear修改");
|
||||
assert(_Arr, "Clear数据不能为空指针");
|
||||
|
||||
memset(_Arr, 0, _Size * _Length);
|
||||
}
|
||||
|
@ -563,7 +563,7 @@ void Array::Clear()
|
|||
// 设置指定位置的值,不足时自动扩容
|
||||
void Array::SetItemAt(int i, const void* item)
|
||||
{
|
||||
assert_param2(_canWrite, "禁止SetItemAt修改");
|
||||
assert(_canWrite, "禁止SetItemAt修改");
|
||||
|
||||
// 检查长度,不足时扩容
|
||||
CheckCapacity(i + 1, _Length);
|
||||
|
@ -576,7 +576,7 @@ void Array::SetItemAt(int i, const void* item)
|
|||
// 重载索引运算符[],返回指定元素的第一个字节
|
||||
byte Array::operator[](int i) const
|
||||
{
|
||||
assert_param2(_Arr && i >= 0 && i < _Length, "下标越界");
|
||||
assert(_Arr && i >= 0 && i < _Length, "下标越界");
|
||||
|
||||
byte* buf = (byte*)_Arr;
|
||||
if(_Size > 1) i *= _Size;
|
||||
|
@ -586,7 +586,7 @@ byte Array::operator[](int i) const
|
|||
|
||||
byte& Array::operator[](int i)
|
||||
{
|
||||
assert_param2(_Arr && i >= 0 && i < _Length, "下标越界");
|
||||
assert(_Arr && i >= 0 && i < _Length, "下标越界");
|
||||
|
||||
byte* buf = (byte*)_Arr;
|
||||
if(_Size > 1) i *= _Size;
|
||||
|
@ -765,7 +765,7 @@ int ByteArray::Load(const void* data, int maxsize)
|
|||
// 从普通字节数据组加载,首字节为长度
|
||||
int ByteArray::Save(void* data, int maxsize) const
|
||||
{
|
||||
assert_param2(_Length <= 0xFF, "_Length <= 0xFF");
|
||||
assert(_Length <= 0xFF, "_Length <= 0xFF");
|
||||
|
||||
byte* p = (byte*)data;
|
||||
int len = _Length <= maxsize ? _Length : maxsize;
|
||||
|
|
8
Type.h
8
Type.h
|
@ -252,7 +252,7 @@ public:
|
|||
// 初始化指定长度的数组。默认使用内部缓冲区
|
||||
TArray(int length = ArraySize) : Array(Arr, ArrayLength(Arr))
|
||||
{
|
||||
assert_param2(length <= 0x400, "禁止分配超过1k的数组");
|
||||
assert(length <= 0x400, "禁止分配超过1k的数组");
|
||||
if(length < 0) length = ArrayLength(Arr);
|
||||
|
||||
_Length = length;
|
||||
|
@ -301,7 +301,7 @@ public:
|
|||
// 末尾加入一个空数据,并返回引用,允许外部修改
|
||||
virtual T& Push()
|
||||
{
|
||||
assert_param2(_canWrite, "禁止修改");
|
||||
assert(_canWrite, "禁止修改");
|
||||
|
||||
int i = _Length;
|
||||
// 检查长度,不足时扩容
|
||||
|
@ -316,7 +316,7 @@ public:
|
|||
// 弹出最后一个数组元素,长度减一
|
||||
virtual T& Pop()
|
||||
{
|
||||
assert_param2(_canWrite, "禁止修改");
|
||||
assert(_canWrite, "禁止修改");
|
||||
|
||||
T* buf = (T*)_Arr;
|
||||
return buf[--_Length];
|
||||
|
@ -337,7 +337,7 @@ public:
|
|||
// 重载索引运算符[],让它可以像数组一样使用下标索引。
|
||||
virtual T& operator[](int i) const
|
||||
{
|
||||
assert_param2(_Arr && i >= 0 && i < _Length, "下标越界");
|
||||
assert(_Arr && i >= 0 && i < _Length, "下标越界");
|
||||
|
||||
T* buf = (T*)_Arr;
|
||||
return buf[i];
|
||||
|
|
Loading…
Reference in New Issue