diff --git a/Config.cpp b/Config.cpp index 6f423327..7bfe0cc3 100644 --- a/Config.cpp +++ b/Config.cpp @@ -76,8 +76,8 @@ bool ConfigBlock::Init(const String& name, const Buffer& bs) { if(!name) return false; - assert(name.Length() < sizeof(Name), "配置区名称太长"); - if(name.Length() >= sizeof(Name)) return false; + assert(name.Length() < (int)sizeof(Name), "配置区名称太长"); + if(name.Length() >= (int)sizeof(Name)) return false; //TS("ConfigBlock::Init"); @@ -181,8 +181,8 @@ const ConfigBlock* FindBlock(const Storage& st, uint addr, const String& name) if(!name) return nullptr; - assert(name.Length() < sizeof(ConfigBlock::Name), "配置区名称太长"); - if(name.Length() >= sizeof(ConfigBlock::Name)) return nullptr; + assert(name.Length() < (int)sizeof(ConfigBlock::Name), "配置区名称太长"); + if(name.Length() >= (int)sizeof(ConfigBlock::Name)) return nullptr; if(!CheckSignature(st, addr, false)) return nullptr; @@ -307,8 +307,8 @@ const void* Config::Set(const String& name, const Buffer& bs) const if(!name) return nullptr; - assert(name.Length() < sizeof(ConfigBlock::Name), "配置区名称太长"); - if(name.Length() >= sizeof(ConfigBlock::Name)) return nullptr; + assert(name.Length() < (int)sizeof(ConfigBlock::Name), "配置区名称太长"); + if(name.Length() >= (int)sizeof(ConfigBlock::Name)) return nullptr; auto cfg = FindBlock(Device, Address, name); if(!cfg) cfg = NewBlock(Device, Address, bs.Length()); diff --git a/Core/Type.h b/Core/Type.h index f2ad3e95..2e99a4c5 100644 --- a/Core/Type.h +++ b/Core/Type.h @@ -50,7 +50,7 @@ public: }; // 数组长度 -#define ArrayLength(arr) (sizeof(arr)/sizeof(arr[0])) +#define ArrayLength(arr) (int)(sizeof(arr)/sizeof(arr[0])) // 数组清零,固定长度 //#define ArrayZero(arr) memset(arr, 0, sizeof(arr)) diff --git a/Device/ADC.cpp b/Device/ADC.cpp index 4bd2d17e..6b7956df 100644 --- a/Device/ADC.cpp +++ b/Device/ADC.cpp @@ -3,7 +3,7 @@ //Pin _Pins[] = ADC1_PINS; -ADConverter::ADConverter(byte line, uint channel) +ADConverter::ADConverter(byte line, int channel) { assert(line >= 1 && line <= 3, "ADC Line"); @@ -12,7 +12,7 @@ ADConverter::ADConverter(byte line, uint channel) uint dat = 1; Count = 0; - for(int i=0; iAddress = Address << 1; - uint len = IIC->Read((ushort)addr, bs); + int len = IIC->Read((ushort)addr, bs); if(len == 0)return false; if(len != bs.Length()) bs.SetLength(len); diff --git a/Drivers/DHT11.cpp b/Drivers/DHT11.cpp index b00b8b7d..f687e56a 100644 --- a/Drivers/DHT11.cpp +++ b/Drivers/DHT11.cpp @@ -44,7 +44,7 @@ bool DHT11::Read(ushort& temp, ushort& humi) /*开始接收数据*/ byte buf[5]; - for(int i=0; iRead(0, bs); + + int len = IIC->Read(0, bs); if (len == 0)return false; if (len != bs.Length()) bs.SetLength(len); diff --git a/Kernel/Sys.cpp b/Kernel/Sys.cpp index 133c4622..49520ebe 100644 --- a/Kernel/Sys.cpp +++ b/Kernel/Sys.cpp @@ -149,7 +149,7 @@ INROOT UInt64 TSys::Ms() const { return Time.Current(); } // 系统绝对当前时间,秒 INROOT uint TSys::Seconds() const { return Time.Seconds + Time.BaseSeconds; } -INROOT void TSys::Sleep(uint ms) const +INROOT void TSys::Sleep(int ms) const { // 优先使用线程级睡眠 if(OnSleep) @@ -174,7 +174,7 @@ INROOT void TSys::Sleep(uint ms) const } } -INROOT void TSys::Delay(uint us) const +INROOT void TSys::Delay(int us) const { // 如果延迟微秒数太大,则使用线程级睡眠 if(OnSleep && us >= 2000) diff --git a/Kernel/Sys.h b/Kernel/Sys.h index 4d4798c7..936b0926 100644 --- a/Kernel/Sys.h +++ b/Kernel/Sys.h @@ -98,10 +98,10 @@ public: UInt64 Ms() const; // 系统启动后的毫秒数 uint Seconds() const; // 系统绝对当前时间,秒 - void Sleep(uint ms) const; // 毫秒级延迟 - void Delay(uint us) const; // 微秒级延迟 - typedef void (*FuncU32)(uint param); - FuncU32 OnSleep; + void Sleep(int ms) const; // 毫秒级延迟 + void Delay(int us) const; // 微秒级延迟 + typedef void (*FuncI32)(int param); + FuncI32 OnSleep; bool CheckMemory() const; diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp index b94aeb41..14c1ae6a 100644 --- a/Kernel/Thread.cpp +++ b/Kernel/Thread.cpp @@ -387,9 +387,9 @@ byte Thread::BuildReady() return count; } -void OnSleep(uint ms) +static void OnSleep(int ms) { - Thread* th = Thread::Current; + auto th = Thread::Current; if(th) th->Sleep(ms); } diff --git a/Message/Message.cpp b/Message/Message.cpp index fae2c182..797a5394 100644 --- a/Message/Message.cpp +++ b/Message/Message.cpp @@ -15,7 +15,7 @@ Message::Message(byte code) } // 设置数据。 -void Message::SetData(const Buffer& bs, uint offset) +void Message::SetData(const Buffer& bs, int offset) { Length = bs.Length() + offset; if(Length > 0) bs.CopyTo(0, Data + offset, Length); diff --git a/Message/Message.h b/Message/Message.h index b83ff318..61bfe5fe 100644 --- a/Message/Message.h +++ b/Message/Message.h @@ -11,7 +11,7 @@ public: byte Reply; // 是否响应 byte Error; // 是否错误 byte OneWay; // 是否单向 - ushort Length; // 数据长度 + short Length; // 数据长度 byte* Data; // 数据。指向子类内部声明的缓冲区 void* State; // 其它状态数据 @@ -20,9 +20,9 @@ public: Message(byte code = 0); // 消息所占据的指令数据大小。包括头部、负载数据、校验和附加数据 - virtual uint Size() const = 0; + virtual int Size() const = 0; // 最大数据大小 - virtual uint MaxDataSize() const = 0; + virtual int MaxDataSize() const = 0; // 从数据流中读取消息 virtual bool Read(Stream& ms) = 0; @@ -35,7 +35,7 @@ public: virtual bool Clone(const Message& msg); // 设置数据 - void SetData(const Buffer& bs, uint offset = 0); + void SetData(const Buffer& bs, int offset = 0); void SetError(byte errorCode, cstring msg = nullptr); // 负载数据转数据流 diff --git a/Net/Blu40.cpp b/Net/Blu40.cpp index 1d84d066..1628f6a8 100644 --- a/Net/Blu40.cpp +++ b/Net/Blu40.cpp @@ -153,7 +153,7 @@ bool Blu40::SetBP(int BP) Sys.Delay(500); Port->Read(ds); - for(int j=0;jRead(ds); //"AT:BPS SET AFTER 2S \r\n\0" //"AT:ERR\r\n\0" - for(int j=0;jRead(bs); - for(int i=0;i Start + Size) return false; @@ -29,7 +29,7 @@ bool BlockStorage::Write(uint address, const Buffer& bs) const assert((address & 0x01) == 0x00, "Write起始地址必须是2字节对齐"); auto buf = bs.GetBuffer(); - uint len = bs.Length(); + int len = bs.Length(); if (!len) return true; if(address < Start || address + len > Start + Size) return false; @@ -93,8 +93,8 @@ bool BlockStorage::Write(uint address, const Buffer& bs) const if(offset) { // 计算块起始地址和剩余大小 - uint blk = addr - offset; - uint size = Block - offset; + int blk = addr - offset; + int size = Block - offset; // 前段原始数据,中段来源数据,末段原始数据 ms.Copy(0, (byte*)blk, offset); if(size > remain) size = remain; @@ -141,7 +141,7 @@ bool BlockStorage::Write(uint address, const Buffer& bs) const return true; } -bool BlockStorage::Memset(uint address, byte data, uint len) const +bool BlockStorage::Memset(uint address, byte data, int len) const { assert((address & 0x01) == 0x00, "Memset起始地址必须是2字节对齐"); @@ -156,7 +156,7 @@ bool BlockStorage::Memset(uint address, byte data, uint len) const } // 擦除块。起始地址,字节数量默认0表示擦除全部 -bool BlockStorage::Erase(uint address, uint len) const +bool BlockStorage::Erase(uint address, int len) const { assert((address & 0x01) == 0x00, "Erase起始地址必须是2字节对齐"); @@ -173,7 +173,7 @@ bool BlockStorage::Erase(uint address, uint len) const uint end = address + len; // 需要检查是否擦除的范围,从第一段开始 uint addr = address; - uint len2 = blk + Block - address; + int len2 = blk + Block - address; // 如果还不够一段,则直接长度 if(len2 > len) len2 = len; while(blk < end) @@ -191,7 +191,7 @@ bool BlockStorage::Erase(uint address, uint len) const } /* 指定块是否被擦除 */ -bool BlockStorage::IsErased(uint address, uint len) const +bool BlockStorage::IsErased(uint address, int len) const { assert((address & 0x01) == 0x00, "IsErased起始地址必须是2字节对齐"); diff --git a/Storage/Storage.h b/Storage/Storage.h index 20ee4c44..b410d127 100644 --- a/Storage/Storage.h +++ b/Storage/Storage.h @@ -17,9 +17,9 @@ public: class BlockStorage : public Storage { public: - uint Size; // 容量大小,字节 + int Size; // 容量大小,字节 uint Start; // 起始地址 - uint Block; // 每块字节数 + int Block; // 每块字节数 bool ReadModifyWrite; // 是否读改写 // 读取 @@ -27,17 +27,17 @@ public: // 写入 virtual bool Write(uint address, const Buffer& bs) const; // 清空 - virtual bool Memset(uint address, byte data, uint len) const; + virtual bool Memset(uint address, byte data, int len) const; // 擦除 - virtual bool Erase(uint address, uint len) const; + virtual bool Erase(uint address, int len) const; protected: // 写入块 - virtual bool WriteBlock(uint address, const byte* buf, uint len, bool inc) const = 0; + virtual bool WriteBlock(uint address, const byte* buf, int len, bool inc) const = 0; // 擦除块 virtual bool EraseBlock(uint address) const = 0; // 指定块是否被擦除 - virtual bool IsErased(uint address, uint len) const; + virtual bool IsErased(uint address, int len) const; }; // 字符存储接口 diff --git a/TinyNet/TinyMessage.cpp b/TinyNet/TinyMessage.cpp index 3b69a564..cdb8a38b 100644 --- a/TinyNet/TinyMessage.cpp +++ b/TinyNet/TinyMessage.cpp @@ -60,7 +60,7 @@ bool TinyMessage::Read(Stream& ms) if(Dest == Src) return false; // 校验剩余长度 - ushort len = Length; + short len = Length; if(ms.Remain() < len + 2) return false; // 避免错误指令超长,导致溢出 @@ -145,12 +145,12 @@ bool TinyMessage::Valid() const } // 消息所占据的指令数据大小。包括头部、负载数据和附加数据 -uint TinyMessage::Size() const +int TinyMessage::Size() const { return MinSize + Length; } -uint TinyMessage::MaxDataSize() const +int TinyMessage::MaxDataSize() const { return Data == _Data ? ArrayLength(_Data) : Length; } diff --git a/TinyNet/TinyMessage.h b/TinyNet/TinyMessage.h index c0243d32..e06dfc1b 100644 --- a/TinyNet/TinyMessage.h +++ b/TinyNet/TinyMessage.h @@ -29,17 +29,17 @@ public: // 负载数据及校验部分,并非内存布局。 ushort Crc; // 整个消息的Crc16校验,计算前Checksum清零 - static const uint HeaderSize = 1 + 1 + 1 + 1 + 1 + 1; // 消息头部大小 - static const uint MinSize = HeaderSize + 0 + 2; // 最小消息大小 + static const int HeaderSize = 1 + 1 + 1 + 1 + 1 + 1; // 消息头部大小 + static const int MinSize = HeaderSize + 0 + 2; // 最小消息大小 public: // 初始化消息,各字段为0 TinyMessage(byte code = 0); // 消息所占据的指令数据大小。包括头部、负载数据和附加数据 - virtual uint Size() const; + virtual int Size() const; // 数据缓冲区大小 - virtual uint MaxDataSize() const; + virtual int MaxDataSize() const; // 分析数据,转为消息。负载数据部分将指向数据区,外部不要提前释放内存 virtual bool Read(Stream& ms); diff --git a/TokenNet/TokenController.cpp b/TokenNet/TokenController.cpp index 6bc73c12..47edec2d 100644 --- a/TokenNet/TokenController.cpp +++ b/TokenNet/TokenController.cpp @@ -216,7 +216,7 @@ bool TokenController::OnReceive(Message& msg) auto& tmsg = (TokenMessage&)msg; // 过滤重复请求。1秒内不接收重复指令 UInt64 start = Sys.Ms() - 5000; - for (int i = 0; i < (int)ArrayLength(_RecvQueue); i++) + for (int i = 0; i < ArrayLength(_RecvQueue); i++) { auto& qi = _RecvQueue[i]; if (qi.Code == msg.Code && qi.Seq == tmsg.Seq && qi.Time > start) @@ -225,7 +225,7 @@ bool TokenController::OnReceive(Message& msg) return true; } } - for (int i = 0; i < (int)ArrayLength(_RecvQueue); i++) + for (int i = 0; i < ArrayLength(_RecvQueue); i++) { auto& qi = _RecvQueue[i]; if (qi.Code == 0 || qi.Time <= start) @@ -314,7 +314,7 @@ void TokenController::ShowMessage(cstring action, const Message& msg) #if MSG_DEBUG TS("TokenController::ShowMessage"); - for (int i = 0; i < (int)ArrayLength(NoLogCodes); i++) + for (int i = 0; i < ArrayLength(NoLogCodes); i++) { if (msg.Code == NoLogCodes[i]) return; if (NoLogCodes[i] == 0) break; @@ -377,7 +377,7 @@ bool TokenController::StatSend(const Message& msg) // 超时指令也干掉 UInt64 end = Sys.Ms() - 5000; - for (int i = 0; i < (int)ArrayLength(_StatQueue); i++) + for (int i = 0; i < ArrayLength(_StatQueue); i++) { auto& qi = _StatQueue[i]; if (qi.Code == 0 || qi.Time <= end) @@ -408,7 +408,7 @@ bool TokenController::StatReceive(const Message& msg) if (msg.Reply) { bool rs = false; - for (int i = 0; i < (int)ArrayLength(_StatQueue); i++) + for (int i = 0; i < ArrayLength(_StatQueue); i++) { auto& qi = _StatQueue[i]; if (qi.Code == code) diff --git a/TokenNet/TokenMessage.cpp b/TokenNet/TokenMessage.cpp index 0f4f1883..9c9a9059 100644 --- a/TokenNet/TokenMessage.cpp +++ b/TokenNet/TokenMessage.cpp @@ -73,12 +73,12 @@ bool TokenMessage::Valid() const } // 消息总长度,包括头部、负载数据和校验 -uint TokenMessage::Size() const +int TokenMessage::Size() const { return HeaderSize + Length; } -uint TokenMessage::MaxDataSize() const +int TokenMessage::MaxDataSize() const { return Data == _Data ? ArrayLength(_Data) : Length; } diff --git a/TokenNet/TokenMessage.h b/TokenNet/TokenMessage.h index 0a07b320..a24c5b60 100644 --- a/TokenNet/TokenMessage.h +++ b/TokenNet/TokenMessage.h @@ -20,8 +20,8 @@ public: byte _Data[512]; // 数据 - static const uint HeaderSize = 1 + 1 + 1; // 消息头部大小 - static const uint MinSize = HeaderSize + 0; // 最小消息大小 + static const int HeaderSize = 1 + 1 + 1; // 消息头部大小 + static const int MinSize = HeaderSize + 0; // 最小消息大小 // 使用指定功能码初始化令牌消息 TokenMessage(byte code = 0); @@ -32,9 +32,9 @@ public: virtual void Write(Stream& ms) const; // 消息总长度,包括头部、负载数据和校验 - virtual uint Size() const; + virtual int Size() const; // 数据缓冲区大小 - virtual uint MaxDataSize() const; + virtual int MaxDataSize() const; // 验证消息校验码是否有效 virtual bool Valid() const; diff --git a/Tool/Build_SmartOS_M3_GCC.cs b/Tool/Build_SmartOS_M3_GCC.cs index 2d4c7bc1..9fc920a2 100644 --- a/Tool/Build_SmartOS_M3_GCC.cs +++ b/Tool/Build_SmartOS_M3_GCC.cs @@ -25,6 +25,7 @@ build.BuildLib("..\\libSmartOS_M3.a"); build.Debug = true; // 未使用参数和无符号整数比较太多了,过滤掉 -build.ExtCompiles = "-Wno-unused-parameter -Wno-sign-compare"; +//build.ExtCompiles = "-Wno-unused-parameter -Wno-sign-compare"; +build.ExtCompiles = "-Wno-unused-parameter"; build.CompileAll(); build.BuildLib("..\\libSmartOS_M3.a");