基础类库和系统内核尽可能的使用int替代uint,方便计算,避免溢出了也不知道。

This commit is contained in:
大石头X2 2017-02-27 18:36:07 +08:00
parent 91229367f1
commit fc216e5f69
30 changed files with 325 additions and 312 deletions

9
.gitignore vendored Normal file
View File

@ -0,0 +1,9 @@
################################################################################
# 此 .gitignore 文件已由 Microsoft(R) Visual Studio 自动创建。
################################################################################
/vs/Debug
*.lib
*.db
*.opendb
*.suo

View File

@ -52,7 +52,7 @@ bool Alarm::Set(const Pair& args, Stream& result)
// 马上调度一次 // 马上调度一次
if (id) Sys.SetTask(_taskid, true, 0); if (id) Sys.SetTask(_taskid, true, 0);
return id; return id > 0;
} }
bool Alarm::Get(const Pair& args, Stream& result) bool Alarm::Get(const Pair& args, Stream& result)

View File

@ -59,7 +59,7 @@ public:
#endif #endif
protected: protected:
uint _Capacity; // 最大个数。非字节数 int _Capacity; // 最大个数。非字节数
bool _needFree; // 是否需要释放 bool _needFree; // 是否需要释放
bool _canWrite; // 是否可写 bool _canWrite; // 是否可写
ushort _Size; // 单个元素大小。字节 ushort _Size; // 单个元素大小。字节

View File

@ -91,7 +91,7 @@ void IList::Add(void* item)
} }
// 添加多个元素 // 添加多个元素
void IList::Add(void** items, uint count) void IList::Add(void** items, int count)
{ {
if(!items || !count) return; if(!items || !count) return;
@ -101,7 +101,7 @@ void IList::Add(void** items, uint count)
} }
// 删除指定位置元素 // 删除指定位置元素
void IList::RemoveAt(uint index) void IList::RemoveAt(int index)
{ {
int len = _Count; int len = _Count;
if(len <= 0 || index >= len) return; if(len <= 0 || index >= len) return;

View File

@ -23,10 +23,10 @@ public:
void Add(void* item); void Add(void* item);
// 添加多个元素 // 添加多个元素
void Add(void** items, uint count); void Add(void** items, int count);
// 删除指定位置元素 // 删除指定位置元素
void RemoveAt(uint index); void RemoveAt(int index);
// 删除指定元素 // 删除指定元素
int Remove(const void* item); int Remove(const void* item);
@ -49,8 +49,8 @@ public:
private: private:
void** _Arr; void** _Arr;
uint _Count; int _Count;
uint _Capacity; int _Capacity;
void* Arr[0x04]; void* Arr[0x04];

View File

@ -9,7 +9,7 @@ Queue::Queue() : _s((void*)nullptr, 0)
Clear(); Clear();
} }
void Queue::SetCapacity(uint len) void Queue::SetCapacity(int len)
{ {
_s.SetLength(len); _s.SetLength(len);
} }
@ -63,7 +63,7 @@ INROOT byte Queue::Dequeue()
return dat; return dat;
} }
uint Queue::Write(const Buffer& bs) int Queue::Write(const Buffer& bs)
{ {
int total = _s.Capacity(); int total = _s.Capacity();
if(!total) _s.SetLength(64); if(!total) _s.SetLength(64);
@ -77,17 +77,17 @@ uint Queue::Write(const Buffer& bs)
4 4
*/ */
uint len = bs.Length(); int len = bs.Length();
// 如果队列满了,不需要覆盖 // 如果队列满了,不需要覆盖
if(_size + len > total) if(_size + len > total)
len = total - _size; len = total - _size;
uint rs = 0; int rs = 0;
while(true) while(true)
{ {
// 计算这一个循环剩下的位置 // 计算这一个循环剩下的位置
uint remain = _s.Capacity() - _head; int remain = _s.Capacity() - _head;
// 如果要写入的数据足够存放 // 如果要写入的数据足够存放
if(len <= remain) if(len <= remain)
{ {
@ -113,7 +113,7 @@ uint Queue::Write(const Buffer& bs)
return rs; return rs;
} }
uint Queue::Read(Buffer& bs) int Queue::Read(Buffer& bs)
{ {
if(_size == 0) return 0; if(_size == 0) return 0;
@ -124,17 +124,17 @@ uint Queue::Read(Buffer& bs)
4 4
*/ */
uint len = bs.Length(); int len = bs.Length();
if(!len) return 0; if(!len) return 0;
if(len > _size) len = _size; if(len > _size) len = _size;
uint rs = 0; int rs = 0;
while(true) while(true)
{ {
int total = _s.Capacity(); int total = _s.Capacity();
// 计算这一个循环剩下的位置 // 计算这一个循环剩下的位置
uint remain = total - _tail; int remain = total - _tail;
// 如果要读取的数据都在这里 // 如果要读取的数据都在这里
if(len <= remain) if(len <= remain)
{ {

View File

@ -9,25 +9,25 @@ class Queue
{ {
private: private:
Array _s; // 数据流 Array _s; // 数据流
uint _head; // 头部位置 int _head; // 头部位置
uint _tail; // 尾部位置 int _tail; // 尾部位置
uint _size; // 长度 int _size; // 长度
public: public:
Queue(); Queue();
bool Empty() const { return _size == 0; } // 队列空 bool Empty() const { return _size == 0; } // 队列空
uint Capacity() const { return _s.Capacity(); } // 队列容量 int Capacity() const { return _s.Capacity(); } // 队列容量
uint Length() const { return _size; } // 队列大小 int Length() const { return _size; } // 队列大小
void SetCapacity(uint len); void SetCapacity(int len);
void Clear(); void Clear();
void Enqueue(byte dat); void Enqueue(byte dat);
byte Dequeue(); byte Dequeue();
uint Write(const Buffer& bs); // 批量写入 int Write(const Buffer& bs); // 批量写入
uint Read(Buffer& bs); // 批量读取 int Read(Buffer& bs); // 批量读取
}; };
#endif #endif

View File

@ -11,19 +11,19 @@ Random::Random()
srand((uint)time(NULL)); srand((uint)time(NULL));
} }
Random::Random(uint seed) Random::Random(int seed)
{ {
srand(seed); srand(seed);
} }
uint Random::Next() const int Random::Next() const
{ {
return rand(); return rand();
} }
uint Random::Next(uint max) const int Random::Next(int max) const
{ {
uint value = rand(); int value = rand();
if(max == 0x100) return value & 0xFF; if(max == 0x100) return value & 0xFF;

View File

@ -6,10 +6,10 @@ class Random
{ {
public: public:
Random(); Random();
Random(uint seed); Random(int seed);
uint Next() const; int Next() const;
uint Next(uint max) const; int Next(int max) const;
void Next(Buffer& bs) const; void Next(Buffer& bs) const;
}; };

View File

@ -158,14 +158,14 @@ private:
void init(); void init();
void release(); void release();
bool Concat(cstring cstr, uint length); bool Concat(cstring cstr, int length);
String& copy(cstring cstr, uint length); String& copy(cstring cstr, int length);
void move(String& rhs); void move(String& rhs);
bool CopyOrWrite(); bool CopyOrWrite();
using Array::CheckCapacity; using Array::CheckCapacity;
bool CheckCapacity(uint size); bool CheckCapacity(int size);
virtual void* Alloc(int len); virtual void* Alloc(int len);
int Search(cstring str, int len, int startIndex, bool rev) const; int Search(cstring str, int len, int startIndex, bool rev) const;

View File

@ -11,12 +11,12 @@ extern ushort _REV16(ushort);
extern uint _REV(uint); extern uint _REV(uint);
// 使用缓冲区初始化数据流。注意此时指针位于0而内容长度为缓冲区长度 // 使用缓冲区初始化数据流。注意此时指针位于0而内容长度为缓冲区长度
Stream::Stream(void* buf, uint len) Stream::Stream(void* buf, int len)
{ {
Init(buf, len); Init(buf, len);
} }
Stream::Stream(const void* buf, uint len) Stream::Stream(const void* buf, int len)
{ {
Init((void*)buf, len); Init((void*)buf, len);
@ -38,7 +38,7 @@ Stream::Stream(const Buffer& bs)
Stream::~Stream() { } Stream::~Stream() { }
void Stream::Init(void* buf, uint len) void Stream::Init(void* buf, int len)
{ {
assert(buf, "buf"); assert(buf, "buf");
@ -51,9 +51,9 @@ void Stream::Init(void* buf, uint len)
Little = true; Little = true;
} }
bool Stream::CheckRemain(uint count) bool Stream::CheckRemain(int count)
{ {
uint remain = _Capacity - _Position; int remain = _Capacity - _Position;
// 容量不够,需要扩容 // 容量不够,需要扩容
if (count > remain) if (count > remain)
{ {
@ -69,11 +69,11 @@ bool Stream::CheckRemain(uint count)
} }
// 数据流容量 // 数据流容量
uint Stream::Capacity() const { return _Capacity; } int Stream::Capacity() const { return _Capacity; }
void Stream::SetCapacity(uint len) { CheckRemain(len - _Position); } void Stream::SetCapacity(int len) { CheckRemain(len - _Position); }
// 当前位置 // 当前位置
uint Stream::Position() const { return _Position; } int Stream::Position() const { return _Position; }
// 设置位置 // 设置位置
bool Stream::SetPosition(int p) bool Stream::SetPosition(int p)
@ -91,7 +91,7 @@ bool Stream::SetPosition(int p)
} }
// 余下的有效数据流长度。0表示已经到达终点 // 余下的有效数据流长度。0表示已经到达终点
uint Stream::Remain() const { return Length - _Position; }; int Stream::Remain() const { return Length - _Position; };
// 尝试前后移动一段距离,返回成功或者失败。如果失败,不移动游标 // 尝试前后移动一段距离,返回成功或者失败。如果失败,不移动游标
bool Stream::Seek(int offset) bool Stream::Seek(int offset)
@ -108,9 +108,9 @@ byte* Stream::GetBuffer() const { return _Buffer; }
byte* Stream::Current() const { return &_Buffer[_Position]; } byte* Stream::Current() const { return &_Buffer[_Position]; }
// 读取7位压缩编码整数 // 读取7位压缩编码整数
uint Stream::ReadEncodeInt() int Stream::ReadEncodeInt()
{ {
uint value = 0; int value = 0;
// 同时计算最大4字节避免无限读取错误数据 // 同时计算最大4字节避免无限读取错误数据
for (int i = 0, k = 0; i < 4; i++, k += 7) for (int i = 0, k = 0; i < 4; i++, k += 7)
{ {
@ -124,7 +124,7 @@ uint Stream::ReadEncodeInt()
} }
// 读取数据到字节数组,由字节数组指定大小。不包含长度前缀 // 读取数据到字节数组,由字节数组指定大小。不包含长度前缀
uint Stream::Read(Buffer& bs) int Stream::Read(Buffer& bs)
{ {
if (bs.Length() == 0) return 0; if (bs.Length() == 0) return 0;
@ -140,7 +140,7 @@ uint Stream::Read(Buffer& bs)
} }
// 写入7位压缩编码整数 // 写入7位压缩编码整数
uint Stream::WriteEncodeInt(uint value) int Stream::WriteEncodeInt(int value)
{ {
if (!CanWrite) return 0; if (!CanWrite) return 0;
@ -168,7 +168,7 @@ bool Stream::Write(const Buffer& bs)
if (!CheckRemain(count)) return false; if (!CheckRemain(count)) return false;
Buffer ss(_Buffer, _Capacity); Buffer ss(_Buffer, _Capacity);
count = ss.Copy((uint)_Position, bs, 0, count); count = ss.Copy(_Position, bs, 0, count);
_Position += count; _Position += count;
// 内容长度不是累加,而是根据位置而扩大 // 内容长度不是累加,而是根据位置而扩大
@ -197,9 +197,9 @@ int Stream::Peek() const
} }
// 从数据流读取变长数据到字节数组。以压缩整数开头表示长度 // 从数据流读取变长数据到字节数组。以压缩整数开头表示长度
uint Stream::ReadArray(Buffer& bs) int Stream::ReadArray(Buffer& bs)
{ {
uint len = ReadEncodeInt(); int len = ReadEncodeInt();
if (!len) if (!len)
{ {
bs.SetLength(0); bs.SetLength(0);
@ -320,7 +320,7 @@ bool Stream::Write(UInt64 value)
/******************************** MemoryStream ********************************/ /******************************** MemoryStream ********************************/
MemoryStream::MemoryStream(uint len) : Stream(_Arr, ArrayLength(_Arr)) MemoryStream::MemoryStream(int len) : Stream(_Arr, ArrayLength(_Arr))
{ {
Length = 0; Length = 0;
_needFree = false; _needFree = false;
@ -332,7 +332,7 @@ MemoryStream::MemoryStream(uint len) : Stream(_Arr, ArrayLength(_Arr))
} }
} }
MemoryStream::MemoryStream(void* buf, uint len) : Stream(buf, len) MemoryStream::MemoryStream(void* buf, int len) : Stream(buf, len)
{ {
_needFree = false; _needFree = false;
} }
@ -347,17 +347,17 @@ MemoryStream::~MemoryStream()
} }
} }
bool MemoryStream::CheckRemain(uint count) bool MemoryStream::CheckRemain(int count)
{ {
uint remain = _Capacity - _Position; int remain = _Capacity - _Position;
// 容量不够,需要扩容 // 容量不够,需要扩容
if (count > remain) if (count > remain)
{ {
if (!CanResize) return Stream::CheckRemain(count); if (!CanResize) return Stream::CheckRemain(count);
// 原始容量成倍扩容 // 原始容量成倍扩容
uint total = _Position + count; int total = _Position + count;
uint size = _Capacity; int size = _Capacity;
if (size < 0x10) size = 0x10; if (size < 0x10) size = 0x10;
while (size < total) size <<= 1; while (size < total) size <<= 1;
@ -382,5 +382,5 @@ WEAK ushort _REV16(ushort value)
WEAK uint _REV(uint value) WEAK uint _REV(uint value)
{ {
return (_REV16(value & 0xFFFF) << 16) | (_REV16(value >> 16) >> 16); return (_REV16(value & 0xFFFF) << 16) | (_REV16(value >> 16));
} }

View File

@ -7,34 +7,34 @@ class Stream
{ {
protected: protected:
byte* _Buffer; // 数据缓冲区。扩容后会重新分配缓冲区 byte* _Buffer; // 数据缓冲区。扩容后会重新分配缓冲区
uint _Capacity; // 缓冲区容量 int _Capacity; // 缓冲区容量
uint _Position; // 游标位置 int _Position; // 游标位置
void Init(void* buf, uint len); void Init(void* buf, int len);
virtual bool CheckRemain(uint count); virtual bool CheckRemain(int count);
public: public:
uint Length; // 数据长度 int Length; // 数据长度
bool Little; // 默认小字节序。仅影响数据读写操作 bool Little; // 默认小字节序。仅影响数据读写操作
bool CanWrite; // 是否可写 bool CanWrite; // 是否可写
bool CanResize; // 是否可以自动扩容 bool CanResize; // 是否可以自动扩容
// 使用缓冲区初始化数据流。注意此时指针位于0而内容长度为缓冲区长度 // 使用缓冲区初始化数据流。注意此时指针位于0而内容长度为缓冲区长度
Stream(void* buf, uint len); Stream(void* buf, int len);
Stream(const void* buf, uint len); Stream(const void* buf, int len);
// 使用字节数组初始化数据流。注意此时指针位于0而内容长度为缓冲区长度 // 使用字节数组初始化数据流。注意此时指针位于0而内容长度为缓冲区长度
explicit Stream(Buffer& bs); explicit Stream(Buffer& bs);
explicit Stream(const Buffer& bs); explicit Stream(const Buffer& bs);
virtual ~Stream(); virtual ~Stream();
// 数据流容量 // 数据流容量
uint Capacity() const; int Capacity() const;
void SetCapacity(uint len); void SetCapacity(int len);
// 当前位置 // 当前位置
uint Position() const; int Position() const;
// 设置位置 // 设置位置
bool SetPosition(int p); bool SetPosition(int p);
// 余下的有效数据流长度。0表示已经到达终点 // 余下的有效数据流长度。0表示已经到达终点
uint Remain() const; int Remain() const;
// 尝试前后移动一段距离,返回成功或者失败。如果失败,不移动游标 // 尝试前后移动一段距离,返回成功或者失败。如果失败,不移动游标
bool Seek(int offset); bool Seek(int offset);
@ -44,17 +44,17 @@ public:
byte* Current() const; byte* Current() const;
// 读取7位压缩编码整数 // 读取7位压缩编码整数
uint ReadEncodeInt(); int ReadEncodeInt();
// 读取数据到字节数组,由字节数组指定大小。不包含长度前缀 // 读取数据到字节数组,由字节数组指定大小。不包含长度前缀
uint Read(Buffer& bs); int Read(Buffer& bs);
// 写入7位压缩编码整数 // 写入7位压缩编码整数
uint WriteEncodeInt(uint value); int WriteEncodeInt(int value);
// 把字节数组的数据写入到数据流。不包含长度前缀 // 把字节数组的数据写入到数据流。不包含长度前缀
bool Write(const Buffer& bs); bool Write(const Buffer& bs);
// 从数据流读取变长数据到字节数组。以压缩整数开头表示长度 // 从数据流读取变长数据到字节数组。以压缩整数开头表示长度
uint ReadArray(Buffer& bs); int ReadArray(Buffer& bs);
ByteArray ReadArray(int count); ByteArray ReadArray(int count);
// 把字节数组作为变长数据写入到数据流。以压缩整数开头表示长度 // 把字节数组作为变长数据写入到数据流。以压缩整数开头表示长度
bool WriteArray(const Buffer& bs); bool WriteArray(const Buffer& bs);
@ -105,13 +105,13 @@ private:
bool _needFree; // 是否自动释放 bool _needFree; // 是否自动释放
//bool _resize; // 是否可以自动扩容 //bool _resize; // 是否可以自动扩容
virtual bool CheckRemain(uint count); virtual bool CheckRemain(int count);
public: public:
// 分配指定大小的数据流 // 分配指定大小的数据流
MemoryStream(uint len = 0); MemoryStream(int len = 0);
// 使用缓冲区初始化数据流,支持自动扩容 // 使用缓冲区初始化数据流,支持自动扩容
MemoryStream(void* buf, uint len); MemoryStream(void* buf, int len);
// 销毁数据流 // 销毁数据流
virtual ~MemoryStream(); virtual ~MemoryStream();
}; };

View File

@ -17,7 +17,7 @@
#include "SString.h" #include "SString.h"
char* utohex(uint value, byte size, char* string, bool upper); char* utohex(uint value, byte size, char* string, bool upper);
extern char* itoa(int value, char* string, int radix); //extern char* itoa(int value, char* string, int radix);
extern char* ltoa(Int64 value, char* string, int radix); extern char* ltoa(Int64 value, char* string, int radix);
extern char* utoa(uint value, char* string, int radix); extern char* utoa(uint value, char* string, int radix);
extern char* ultoa(UInt64 value, char* string, int radix); extern char* ultoa(UInt64 value, char* string, int radix);
@ -173,7 +173,7 @@ void String::release()
init(); init();
} }
bool String::CheckCapacity(uint size) bool String::CheckCapacity(int size)
{ {
int old = _Capacity; int old = _Capacity;
CheckCapacity(size + 1, _Length); CheckCapacity(size + 1, _Length);
@ -201,7 +201,7 @@ void* String::Alloc(int len)
} }
} }
String& String::copy(cstring cstr, uint length) String& String::copy(cstring cstr, int length)
{ {
if (!cstr || !length) return *this; if (!cstr || !length) return *this;
@ -324,12 +324,12 @@ bool String::Concat(const String& s)
return Concat(s._Arr, s._Length); return Concat(s._Arr, s._Length);
} }
bool String::Concat(cstring cstr, uint length) bool String::Concat(cstring cstr, int length)
{ {
if (!cstr) return false; if (!cstr) return false;
if (length == 0) return true; if (length == 0) return true;
uint newlen = _Length + length; int newlen = _Length + length;
if (!CheckCapacity(newlen)) return false; if (!CheckCapacity(newlen)) return false;
//strcpy(_Arr + _Length, cstr); //strcpy(_Arr + _Length, cstr);

View File

@ -238,7 +238,9 @@ WEAK bool OutputPort::ReadInput() const
{ {
if (Empty()) return false; if (Empty()) return false;
return Port::Read() ^ Invert; bool v = Port::Read();
if (Invert)return !v;
return v;
} }
void OutputPort::Up(uint ms) const void OutputPort::Up(uint ms) const
@ -341,7 +343,9 @@ InputPort& InputPort::Init(Pin pin, bool invert)
// 读取本组所有引脚任意脚为true则返回true主要为单一引脚服务 // 读取本组所有引脚任意脚为true则返回true主要为单一引脚服务
bool InputPort::Read() const bool InputPort::Read() const
{ {
return Port::Read() ^ Invert; bool v = Port::Read();
if (Invert)return !v;
return v;
} }
void InputPort::OnPress(bool down) void InputPort::OnPress(bool down)
@ -367,7 +371,7 @@ void InputPort::OnPress(bool down)
if (down) if (down)
_Start = now; _Start = now;
else else
PressTime = now - _Start; PressTime = (ushort)(now - _Start);
/*if(down) /*if(down)
{ {

View File

@ -147,8 +147,8 @@ bool SerialPort::Flush(uint times)
// 从某个端口读取数据 // 从某个端口读取数据
uint SerialPort::OnRead(Buffer& bs) uint SerialPort::OnRead(Buffer& bs)
{ {
uint count = 0; int count = 0;
uint len = Rx.Length(); int len = Rx.Length();
// 如果没有数据,立刻返回,不要等待浪费时间 // 如果没有数据,立刻返回,不要等待浪费时间
if(!len) if(!len)
{ {

View File

@ -91,7 +91,7 @@ void Timer::Register(const Delegate<Timer&>& dlg)
{ {
OnTick = dlg; OnTick = dlg;
SetHandler(dlg.Method); SetHandler(dlg.Method != nullptr);
} }
void Timer::OnInterrupt() void Timer::OnInterrupt()

View File

@ -27,7 +27,7 @@ typedef struct MemoryBlock_
} MemoryBlock; } MemoryBlock;
/******************************** Heap ********************************/ /******************************** Heap ********************************/
Heap::Heap(uint addr, uint size) Heap::Heap(uint addr, int size)
{ {
Current = this; Current = this;
@ -55,11 +55,11 @@ Heap::Heap(uint addr, uint size)
debug_printf("Heap::Init(%p, %d) Free=%d \r\n", Address, Size, FreeSize()); debug_printf("Heap::Init(%p, %d) Free=%d \r\n", Address, Size, FreeSize());
} }
uint Heap::Used() const { return _Used; } int Heap::Used() const { return _Used; }
uint Heap::Count() const { return _Count; } int Heap::Count() const { return _Count; }
uint Heap::FreeSize() const { return Size - _Used; } int Heap::FreeSize() const { return Size - _Used; }
void* Heap::Alloc(uint size) void* Heap::Alloc(int size)
{ {
// 要申请的内存大小需要对齐 // 要申请的内存大小需要对齐
size = (size+MEMORY_ALIGN-1) & (~(MEMORY_ALIGN-1)); size = (size+MEMORY_ALIGN-1) & (~(MEMORY_ALIGN-1));
@ -73,7 +73,7 @@ void* Heap::Alloc(uint size)
#if DEBUG #if DEBUG
// 检查头部完整性 // 检查头部完整性
auto head = (MemoryBlock*)Address; auto head = (MemoryBlock*)Address;
assert(head->Used <= Size && (uint)head + head->Used <= (uint)head->Next, "堆头被破坏!"); assert(head->Used <= (uint)Size && (uint)head + head->Used <= (uint)head->Next, "堆头被破坏!");
assert(_Used <= Size, "Heap::Used异常"); assert(_Used <= Size, "Heap::Used异常");
#endif #endif

View File

@ -6,23 +6,23 @@ class Heap
{ {
public: public:
uint Address;// 开始地址 uint Address;// 开始地址
uint Size; // 大小 int Size; // 大小
Heap(uint addr, uint size); Heap(uint addr, int size);
uint Used() const; // 已使用内存数 int Used() const; // 已使用内存数
uint Count() const; // 已使用内存块数 int Count() const; // 已使用内存块数
uint FreeSize() const; // 可用内存数 int FreeSize() const; // 可用内存数
void* Alloc(uint size); void* Alloc(int size);
void Free(void* ptr); void Free(void* ptr);
// 当前堆 // 当前堆
static Heap* Current; static Heap* Current;
private: private:
uint _Used; int _Used;
uint _Count; int _Count;
void* _First; // 第一个有空闲的内存块,加速搜索 void* _First; // 第一个有空闲的内存块,加速搜索
}; };

View File

@ -179,7 +179,7 @@ TaskScheduler::TaskScheduler(cstring name)
} }
// 使用外部缓冲区初始化任务列表,避免频繁的堆分配 // 使用外部缓冲区初始化任务列表,避免频繁的堆分配
void TaskScheduler::Set(Task* tasks, uint count) void TaskScheduler::Set(Task* tasks, int count)
{ {
for(int i=0; i<count; i++) for(int i=0; i<count; i++)
{ {
@ -358,9 +358,9 @@ INROOT void TaskScheduler::Execute(uint msMax, bool& cancel)
Sleeping = true; Sleeping = true;
// 通知外部,需要睡眠若干毫秒 // 通知外部,需要睡眠若干毫秒
if(EnterSleep) if(EnterSleep)
EnterSleep(min); EnterSleep((int)min);
else else
Time.Sleep(min, &Sleeping); Time.Sleep((int)min, &Sleeping);
Sleeping = false; Sleeping = false;
// 累加睡眠时间 // 累加睡眠时间
@ -433,7 +433,7 @@ void TaskScheduler::ShowStatus()
debug_printf("Task::ShowStatus [%d]", ts); debug_printf("Task::ShowStatus [%d]", ts);
debug_printf(" 负载 %d.%d%%", p/100, p%100); debug_printf(" 负载 %d.%d%%", p/100, p%100);
debug_printf(" 平均 %dus 当前 ", ts ? ct/ts : 0); debug_printf(" 平均 %dus 当前 ", ts ? ct/ts : 0);
DateTime(now/1000).Show(); DateTime((int)(now/1000)).Show();
debug_printf(" 启动 "); debug_printf(" 启动 ");
TimeSpan(now).Show(false); TimeSpan(now).Show(false);

View File

@ -77,14 +77,14 @@ public:
UInt64 TotalSleep; // 所有任务的总睡眠时间ms UInt64 TotalSleep; // 所有任务的总睡眠时间ms
UInt64 LastTrace; // 最后统计跟踪时间ms UInt64 LastTrace; // 最后统计跟踪时间ms
typedef void (*SAction)(uint ms); typedef void (*SAction)(int ms);
SAction EnterSleep; // 通知外部,需要睡眠若干毫秒 SAction EnterSleep; // 通知外部,需要睡眠若干毫秒
Func ExitSleep; // 通知外部,要求退出睡眠,恢复调度 Func ExitSleep; // 通知外部,要求退出睡眠,恢复调度
TaskScheduler(cstring name = nullptr); TaskScheduler(cstring name = nullptr);
// 使用外部缓冲区初始化任务列表,避免频繁的堆分配 // 使用外部缓冲区初始化任务列表,避免频繁的堆分配
void Set(Task* tasks, uint count); void Set(Task* tasks, int count);
// 查找任务 返回使用此函数的首个任务的ID // 查找任务 返回使用此函数的首个任务的ID
uint FindID(Action func); uint FindID(Action func);
// 查找任务 返回使用此函数的首个任务 // 查找任务 返回使用此函数的首个任务

View File

@ -44,7 +44,7 @@ void TTime::SetTime(UInt64 sec)
{ {
if (sec >= BASE_YEAR_US) sec -= BASE_YEAR_US; if (sec >= BASE_YEAR_US) sec -= BASE_YEAR_US;
BaseSeconds = (uint)(sec - Seconds); BaseSeconds = (int)(sec - Seconds);
#if DEBUG #if DEBUG
/*DateTime dt(sec); /*DateTime dt(sec);

View File

@ -36,7 +36,7 @@ Buffer BinaryPair::Get(cstring name) const
String sn = name; String sn = name;
auto& ms = *_s; auto& ms = *_s;
uint p = ms.Position(); int p = ms.Position();
for(int i=0; i<2; i++) for(int i=0; i<2; i++)
{ {
while(ms.Remain() && (i ==0 || ms.Position() < p)) while(ms.Remain() && (i ==0 || ms.Position() < p))

View File

@ -225,7 +225,7 @@ bool NetworkInterface::SaveConfig() const
debug_printf("%s::Save %d 字节\r\n", Name, sizeof(nc)); debug_printf("%s::Save %d 字节\r\n", Name, sizeof(nc));
Buffer bs(&nc, sizeof(nc)); Buffer bs(&nc, sizeof(nc));
return cfg->Set(Name, bs); return cfg->Set(Name, bs) != nullptr;
} }
void NetworkInterface::ShowConfig() const void NetworkInterface::ShowConfig() const

View File

@ -1,4 +1,4 @@
#include "Kernel\Sys.h" #include "Kernel\Sys.h"
#if DEBUG #if DEBUG
static void TestAssign() static void TestAssign()

View File

@ -1,4 +1,4 @@
#include "Kernel\Sys.h" #include "Kernel\Sys.h"
#include "Core\Dictionary.h" #include "Core\Dictionary.h"
#if DEBUG #if DEBUG

View File

@ -7,7 +7,7 @@ void TestFlash()
debug_printf("TestFlash Start......\r\n"); debug_printf("TestFlash Start......\r\n");
byte buf[] = "STM32F10x SPI Firmware Library Example: communication with an AT45DB SPI FLASH"; byte buf[] = "STM32F10x SPI Firmware Library Example: communication with an AT45DB SPI FLASH";
uint size = ArrayLength(buf); int size = ArrayLength(buf);
Flash flash; Flash flash;
// 凑一个横跨两页的地址 // 凑一个横跨两页的地址

View File

@ -1,4 +1,4 @@
#include "Kernel\Sys.h" #include "Kernel\Sys.h"
#include "Message\Json.h" #include "Message\Json.h"
#if DEBUG #if DEBUG

View File

@ -1,4 +1,4 @@
#include "Kernel\Sys.h" #include "Kernel\Sys.h"
#include "Core\List.h" #include "Core\List.h"
#if DEBUG #if DEBUG

View File

@ -28,7 +28,7 @@ TinyController::TinyController() : Controller()
while(Address < 2 || Address > 254) while(Address < 2 || Address > 254)
{ {
Sys.Delay(30); Sys.Delay(30);
Address = Sys.Ms(); Address = (byte)Sys.Ms();
} }
// 接收模式。0只收自己1接收自己和广播2接收所有。默认0 // 接收模式。0只收自己1接收自己和广播2接收所有。默认0
@ -350,7 +350,7 @@ void TinyController::AckRequest(const TinyMessage& msg)
auto& node = _Queue[i]; auto& node = _Queue[i];
if(node.Using && node.Seq == msg.Seq) if(node.Using && node.Seq == msg.Seq)
{ {
int cost = Sys.Ms() - node.StartTime; int cost = (int)(Sys.Ms() - node.StartTime);
if(cost < 0) cost = -cost; if(cost < 0) cost = -cost;
Total.Cost += cost; Total.Cost += cost;

View File

@ -105,7 +105,7 @@ void TinyMessage::Write(Stream& ms) const
// 实际数据拷贝到占位符 // 实际数据拷贝到占位符
auto p = (TinyMessage*)this; auto p = (TinyMessage*)this;
p->_Code = Code; p->_Code = Code;
p->_Length = len; p->_Length = (byte)len;
p->_Reply = Reply; p->_Reply = Reply;
p->_Error = Error; p->_Error = Error;