From 11ec1084fd24e999c8a43ebff6d89effc47ee0cf Mon Sep 17 00:00:00 2001 From: nnhy Date: Mon, 7 Mar 2016 10:46:10 +0000 Subject: [PATCH] =?UTF-8?q?ulong=20=3D>=20UInt64=20=5FREV/=5FREV16=20?= =?UTF-8?q?=E7=8B=AC=E7=AB=8B=E6=B1=87=E7=BC=96=E5=AE=9E=E7=8E=B0=EF=BC=8C?= =?UTF-8?q?=E4=B8=8D=E4=BE=9D=E8=B5=96=E5=9B=BA=E4=BB=B6=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Drivers/Enc28j60.h | 2 +- Net/Dhcp.cpp | 4 ++-- Net/Dhcp.h | 2 +- Net/Ethernet.h | 10 +++++----- Net/Net.cpp | 4 ++-- Net/Net.h | 6 +++--- Port.cpp | 2 +- Port.h | 6 +++--- RTC.cpp | 2 +- Stream.cpp | 10 +++++----- Stream.h | 6 +++--- String.cpp | 18 +++++++++--------- String.h | 10 +++++----- Sys.cpp | 2 +- Sys.h | 2 +- Task.cpp | 12 ++++++------ Task.h | 2 +- Test/CrcTest.cpp | 2 +- Thread.h | 2 +- Time.cpp | 20 ++++++++++---------- Time.h | 18 +++++++++--------- TinyIP/TinyIP.cpp | 2 +- TinyIP/TinyIP.h | 2 +- TinyNet/TinyClient.h | 2 +- TinyNet/TinyMessage.cpp | 6 +++--- TinyNet/TinyMessage.h | 10 +++++----- TokenNet/DeviceMessage.cpp | 2 +- TokenNet/HelloMessage.h | 2 +- TokenNet/LoginMessage.cpp | 2 +- TokenNet/RegisterMessage.cpp | 2 +- TokenNet/TokenClient.cpp | 6 +++--- TokenNet/TokenClient.h | 8 ++++---- TokenNet/TokenMessage.h | 2 +- Type.cpp | 28 +++++++++++++++++++--------- Type.h | 6 +++--- 35 files changed, 116 insertions(+), 106 deletions(-) diff --git a/Drivers/Enc28j60.h b/Drivers/Enc28j60.h index b8f67615..2dd8656b 100644 --- a/Drivers/Enc28j60.h +++ b/Drivers/Enc28j60.h @@ -17,7 +17,7 @@ private: uint NextPacketPtr; - ulong LastTime; // 记录最后一次收到数据的时间,超时重启 + UInt64 LastTime; // 记录最后一次收到数据的时间,超时重启 uint ResetPeriod; // 重启间隔,默认6000微秒 uint _ResetTask; // 重启任务 public: diff --git a/Net/Dhcp.cpp b/Net/Dhcp.cpp index 945951b7..6e420b77 100644 --- a/Net/Dhcp.cpp +++ b/Net/Dhcp.cpp @@ -128,7 +128,7 @@ void Dhcp::Request() void Dhcp::Start() { - ulong now = Sys.Ms(); + UInt64 now = Sys.Ms(); _expired = now + ExpiredTime; if(!dhcpid) dhcpid = now; @@ -327,7 +327,7 @@ void Dhcp::Process(Buffer& bs, const IPEndPoint& ep) // DHCP租约过了一半以后重新获取IP地址 if(time > 0) { - Sys.SetTaskPeriod(taskID, (ulong)time / 2 * 1000); + Sys.SetTaskPeriod(taskID, (UInt64)time / 2 * 1000); Sys.SetTask(taskID, true); } } diff --git a/Net/Dhcp.h b/Net/Dhcp.h index 50ae1a2e..82839ea9 100644 --- a/Net/Dhcp.h +++ b/Net/Dhcp.h @@ -9,7 +9,7 @@ class Dhcp private: uint dhcpid; // 事务ID uint taskID; // 任务ID - ulong _expired; // 目标过期时间,毫秒 + UInt64 _expired; // 目标过期时间,毫秒 ISocket* Socket; void Discover(); diff --git a/Net/Ethernet.h b/Net/Ethernet.h index ce660a3d..adaeb53e 100644 --- a/Net/Ethernet.h +++ b/Net/Ethernet.h @@ -29,7 +29,7 @@ public: uint v4; ushort v2; - MacAddr(ulong v = 0) + MacAddr(UInt64 v = 0) { v4 = v; v2 = v >> 32; @@ -38,17 +38,17 @@ public: // 是否广播地址,全0或全1 bool IsBroadcast() { return !v4 && !v2 || v4 == 0xFFFFFFFF && v2 == 0xFFFF; } - MacAddr& operator=(ulong v) + MacAddr& operator=(UInt64 v) { v4 = v; v2 = v >> 32; return *this; } - ulong Value() + UInt64 Value() { - ulong v = v4; - v |= ((ulong)v2) << 32; + UInt64 v = v4; + v |= ((UInt64)v2) << 32; return v; } diff --git a/Net/Net.cpp b/Net/Net.cpp index f0d3fde6..d865c517 100644 --- a/Net/Net.cpp +++ b/Net/Net.cpp @@ -175,7 +175,7 @@ bool operator!=(const IPEndPoint& addr1, const IPEndPoint& addr2) //const MacAddress MacAddress::Empty(0x0ull); //const MacAddress MacAddress::Full(MAC_MASK); -MacAddress::MacAddress(ulong v) +MacAddress::MacAddress(UInt64 v) { Value = v & MAC_MASK; } @@ -209,7 +209,7 @@ const MacAddress& MacAddress::Full() return _Full; } -MacAddress& MacAddress::operator=(ulong v) +MacAddress& MacAddress::operator=(UInt64 v) { Value = v & MAC_MASK; diff --git a/Net/Net.h b/Net/Net.h index fb6875ab..928cc243 100644 --- a/Net/Net.h +++ b/Net/Net.h @@ -82,16 +82,16 @@ class MacAddress : public Object { public: // 长整型转为Mac地址,取内存前6字节。因为是小字节序,需要v4在前,v2在后 - ulong Value; // 地址 + UInt64 Value; // 地址 - MacAddress(ulong v = 0); + MacAddress(UInt64 v = 0); MacAddress(const byte* macs); MacAddress(const Buffer& arr); // 是否广播地址,全0或全1 bool IsBroadcast() const; - MacAddress& operator=(ulong v); + MacAddress& operator=(UInt64 v); MacAddress& operator=(const byte* buf); MacAddress& operator=(const Buffer& arr); diff --git a/Port.cpp b/Port.cpp index dd19cf2d..610cf247 100644 --- a/Port.cpp +++ b/Port.cpp @@ -546,7 +546,7 @@ void InputPort::OnPress(bool down) 2,记录最近两次按下的时间,如果出现抖动且时间相差不是非常大,则使用上一次按下时间 3,也可能出现100抖动 */ - ulong now = Sys.Ms(); + UInt64 now = Sys.Ms(); // 预处理抖动。如果相邻两次间隔小于抖动时间,那么忽略上一次未处理的值(可能失败) bool shake = false; if(ShakeTime && ShakeTime > now - _PressLast) diff --git a/Port.h b/Port.h index f3ed7792..67c24596 100644 --- a/Port.h +++ b/Port.h @@ -170,9 +170,9 @@ protected: private: byte _Value = 0; uint _taskInput = 0; // 输入任务 - ulong _PressStart = 0; // 开始按下时间 - ulong _PressStart2 = 0; // 开始按下时间 - ulong _PressLast = 0; // 最后一次按下时间 + UInt64 _PressStart = 0; // 开始按下时间 + UInt64 _PressStart2 = 0; // 开始按下时间 + UInt64 _PressLast = 0; // 最后一次按下时间 static void InputTask(void* param); IOReadHandler Handler = NULL; diff --git a/RTC.cpp b/RTC.cpp index be573623..85e97e79 100644 --- a/RTC.cpp +++ b/RTC.cpp @@ -203,7 +203,7 @@ void HardRTC::LoadTicks() auto& time = (TTime&)Time; #ifdef STM32F1 // 加上计数器的值,注意计数器的单位是秒。注意必须转INT64,否则溢出 - ulong ms = RTC_GetCounter(); + UInt64 ms = RTC_GetCounter(); // 计数器调整为毫秒,采用第二个后备寄存器保存秒以上的数据 uint sec = ReadBackup(1); time.Seconds = sec; diff --git a/Stream.cpp b/Stream.cpp index 7d4cb120..ed3bb78a 100644 --- a/Stream.cpp +++ b/Stream.cpp @@ -312,11 +312,11 @@ uint Stream::ReadUInt32() return v; } -ulong Stream::ReadUInt64() +UInt64 Stream::ReadUInt64() { - ulong v; + UInt64 v; if(!Read((byte*)&v, 0, 8)) return 0; - if(!Little) v = _REV(v >> 32) | ((ulong)_REV(v & 0xFFFFFFFF) << 32); + if(!Little) v = _REV(v >> 32) | ((UInt64)_REV(v & 0xFFFFFFFF) << 32); return v; } @@ -339,9 +339,9 @@ bool Stream::Write(uint value) return Write((byte*)&value, 0, 4); } -bool Stream::Write(ulong value) +bool Stream::Write(UInt64 value) { - if(!Little) value = _REV(value >> 32) | ((ulong)_REV(value & 0xFFFFFFFF) << 32); + if(!Little) value = _REV(value >> 32) | ((UInt64)_REV(value & 0xFFFFFFFF) << 32); return Write((byte*)&value, 0, 8); } diff --git a/Stream.h b/Stream.h index f5c2667a..db822d3e 100644 --- a/Stream.h +++ b/Stream.h @@ -73,16 +73,16 @@ public: byte ReadByte(); ushort ReadUInt16(); uint ReadUInt32(); - ulong ReadUInt64(); + UInt64 ReadUInt64(); bool Write(byte value); bool Write(ushort value); bool Write(uint value); - bool Write(ulong value); + bool Write(UInt64 value); bool Write(sbyte value) { return Write((byte)value); } bool Write(short value) { return Write((ushort)value); } bool Write(int value) { return Write((uint)value); } - bool Write(Int64 value) { return Write((ulong)value); } + bool Write(Int64 value) { return Write((UInt64)value); } // 取回指定结构体指针,并移动游标位置 template diff --git a/String.cpp b/String.cpp index 891ea7a8..16ebf06e 100644 --- a/String.cpp +++ b/String.cpp @@ -10,7 +10,7 @@ extern char* itoa(int 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* ultoa(ulong value, char* string, int radix); +extern char* ultoa(UInt64 value, char* string, int radix); char* dtostrf(double val, char width, byte prec, char* sout); /******************************** String ********************************/ @@ -81,7 +81,7 @@ String::String(Int64 value, byte radix) ltoa(value, _Arr, radix); } -String::String(ulong value, byte radix) +String::String(UInt64 value, byte radix) { init(); @@ -313,9 +313,9 @@ bool String::Concat(Int64 num, byte radix) return Concat(buf, strlen(buf)); } -bool String::Concat(ulong num, byte radix) +bool String::Concat(UInt64 num, byte radix) { - char buf[1 + 3 * sizeof(ulong)]; + char buf[1 + 3 * sizeof(UInt64)]; ultoa(num, buf, radix); return Concat(buf, strlen(buf)); } @@ -391,7 +391,7 @@ StringHelper& operator + (const StringHelper& lhs, Int64 num) return a; } -StringHelper& operator + (const StringHelper& lhs, ulong num) +StringHelper& operator + (const StringHelper& lhs, UInt64 num) { auto& a = const_cast(lhs); if (!a.Concat(num)) a.release(); @@ -765,7 +765,7 @@ extern char* ltoa(Int64 value, char* string, int radix ) char tmp[33]; char *tp = tmp; Int64 i; - ulong v; + UInt64 v; int sign; char *sp; @@ -777,7 +777,7 @@ extern char* ltoa(Int64 value, char* string, int radix ) if (sign) v = -value; else - v = (ulong)value; + v = (UInt64)value; while (v || tp == tmp) { @@ -804,12 +804,12 @@ extern char* utoa(uint value, char* string, int radix) return ultoa(value, string, radix ) ; } -extern char* ultoa(ulong value, char* string, int radix) +extern char* ultoa(UInt64 value, char* string, int radix) { char tmp[33]; char *tp = tmp; Int64 i; - ulong v = value; + UInt64 v = value; char *sp; if ( string == NULL ) return 0; diff --git a/String.h b/String.h index c361ee20..a18890bb 100644 --- a/String.h +++ b/String.h @@ -22,7 +22,7 @@ public: explicit String(int value, byte radix = 10); explicit String(uint value, byte radix = 10); explicit String(Int64 value, byte radix = 10); - explicit String(ulong value, byte radix = 10); + explicit String(UInt64 value, byte radix = 10); explicit String(float value, byte decimalPlaces = 2); explicit String(double value, byte decimalPlaces = 2); virtual ~String(); @@ -49,7 +49,7 @@ public: bool Concat(int num, byte radix = 10); bool Concat(uint num, byte radix = 10); bool Concat(Int64 num, byte radix = 10); - bool Concat(ulong num, byte radix = 10); + bool Concat(UInt64 num, byte radix = 10); bool Concat(float num); bool Concat(double num); @@ -63,7 +63,7 @@ public: String& operator += (int num) {Concat(num); return (*this);} String& operator += (uint num) {Concat(num); return (*this);} String& operator += (Int64 num) {Concat(num); return (*this);} - String& operator += (ulong num) {Concat(num); return (*this);} + String& operator += (UInt64 num) {Concat(num); return (*this);} String& operator += (float num) {Concat(num); return (*this);} String& operator += (double num) {Concat(num); return (*this);} @@ -82,7 +82,7 @@ public: friend StringHelper& operator + (const StringHelper& lhs, int num); friend StringHelper& operator + (const StringHelper& lhs, uint num); friend StringHelper& operator + (const StringHelper& lhs, Int64 num); - friend StringHelper& operator + (const StringHelper& lhs, ulong num); + friend StringHelper& operator + (const StringHelper& lhs, UInt64 num); friend StringHelper& operator + (const StringHelper& lhs, float num); friend StringHelper& operator + (const StringHelper& lhs, double num); @@ -184,7 +184,7 @@ public: StringHelper(int num) : String(num) {} StringHelper(uint num) : String(num) {} StringHelper(Int64 num) : String(num) {} - StringHelper(ulong num) : String(num) {} + StringHelper(UInt64 num) : String(num) {} StringHelper(float num) : String(num) {} StringHelper(double num) : String(num) {} }; diff --git a/Sys.cpp b/Sys.cpp index d61b970d..8eb1f234 100644 --- a/Sys.cpp +++ b/Sys.cpp @@ -497,7 +497,7 @@ void TimeSleep(uint us) } // 系统启动后的毫秒数 -ulong TSys::Ms() const { return Time.Current(); } +UInt64 TSys::Ms() const { return Time.Current(); } // 系统绝对当前时间,秒 uint TSys::Seconds() const { return Time.Seconds + Time.BaseSeconds; } diff --git a/Sys.h b/Sys.h index 44cfc3b8..5546cc46 100644 --- a/Sys.h +++ b/Sys.h @@ -81,7 +81,7 @@ public: uint HeapBase() const; // 堆起始地址,前面是静态分配内存 uint StackTop() const; // 栈顶,后面是初始化不清零区域 - ulong Ms() const; // 系统启动后的毫秒数 + UInt64 Ms() const; // 系统启动后的毫秒数 uint Seconds() const; // 系统绝对当前时间,秒 void Sleep(uint ms) const; // 毫秒级延迟 diff --git a/Task.cpp b/Task.cpp index 072d77d6..7d082053 100644 --- a/Task.cpp +++ b/Task.cpp @@ -28,7 +28,7 @@ Task::~Task() #pragma arm section code = "SectionForSys" #endif -bool Task::Execute(ulong now) +bool Task::Execute(UInt64 now) { //TS("Task::Execute"); TS(Name); @@ -251,9 +251,9 @@ void TaskScheduler::Execute(uint msMax) { TS("Task::Execute"); - ulong now = Sys.Ms(); - ulong end = now + msMax; - ulong min = UInt64_Max; // 最小时间,这个时间就会有任务到来 + UInt64 now = Sys.Ms(); + UInt64 end = now + msMax; + UInt64 min = UInt64_Max; // 最小时间,这个时间就会有任务到来 TimeCost tc; @@ -278,8 +278,8 @@ void TaskScheduler::Execute(uint msMax) // 如果事件型任务还需要执行,那么就不要做任何等待 if(task->NextTime < 0) min = 0; - else if((ulong)task->NextTime < min) - min = (ulong)task->NextTime; + else if((UInt64)task->NextTime < min) + min = (UInt64)task->NextTime; } } diff --git a/Task.h b/Task.h index 4598d1a8..8a618def 100644 --- a/Task.h +++ b/Task.h @@ -39,7 +39,7 @@ public: ~Task(); // 执行任务。返回是否正常执行。 - bool Execute(ulong now); + bool Execute(UInt64 now); // 设置任务的开关状态,同时运行指定任务最近一次调度的时间,0表示马上调度 void Set(bool enable, int msNextTime = -1); // 显示状态 diff --git a/Test/CrcTest.cpp b/Test/CrcTest.cpp index 2ea39ea6..7d47e81f 100644 --- a/Test/CrcTest.cpp +++ b/Test/CrcTest.cpp @@ -96,7 +96,7 @@ void TestCrc() // 结果相同,但都不是0 // 连续测试。构建8字节,前面是data,后面是前面的crc - ulong data2 = temp; + UInt64 data2 = temp; data2 <<= 32; data2 += data; ByteArray bs2(&data2, 8); diff --git a/Thread.h b/Thread.h index caf5a1ae..85b80056 100644 --- a/Thread.h +++ b/Thread.h @@ -48,7 +48,7 @@ public: void Suspend(); void Resume(); - ulong DelayExpire; // 过期时间,单位微秒。睡眠的线程达到该时间后将恢复唤醒 + UInt64 DelayExpire; // 过期时间,单位微秒。睡眠的线程达到该时间后将恢复唤醒 void Sleep(uint ms); // 睡眠指定毫秒数。 // 静态管理 diff --git a/Time.cpp b/Time.cpp index cdd89248..5965c2e9 100644 --- a/Time.cpp +++ b/Time.cpp @@ -142,7 +142,7 @@ uint TTime::CurrentTicks() const } // 当前毫秒数 -ulong TTime::Current() const +UInt64 TTime::Current() const { uint cnt = g_Timers[Index]->CNT; #if ! (defined(STM32F0) || defined(GD32F150)) @@ -151,7 +151,7 @@ ulong TTime::Current() const return Milliseconds + cnt; } -void TTime::SetTime(ulong seconds) +void TTime::SetTime(UInt64 seconds) { if(seconds >= BASE_YEAR_US) seconds -= BASE_YEAR_US; BaseSeconds = seconds - Seconds; @@ -226,7 +226,7 @@ void TTime::Delay(uint us) const if(!us) return; // 无需关闭中断,也能实现延迟 - ulong ms = Current(); + UInt64 ms = Current(); uint ticks = CurrentTicks() + us * Ticks; if(ticks >= (1000 - 1) * Ticks) { @@ -261,7 +261,7 @@ const int CummulativeDaysForMonth[13] = {0, 31, 59, 90, 120, 151, 181, 212, 243, #define YEARS_TO_DAYS(y) ((NUMBER_OF_YEARS(y) * 365) + NUMBER_OF_LEAP_YEARS(y)) #define MONTH_TO_DAYS(y, m) (CummulativeDaysForMonth[m - 1] + ((IS_LEAP_YEAR(y) && (m > 2)) ? 1 : 0)) -DateTime& DateTime::Parse(ulong seconds) +DateTime& DateTime::Parse(UInt64 seconds) { DateTime& st = *this; @@ -305,7 +305,7 @@ DateTime& DateTime::Parse(ulong seconds) return st; } -DateTime& DateTime::ParseUs(ulong us) +DateTime& DateTime::ParseUs(UInt64 us) { Parse(us / 1000000ULL); uint n = us % 1000000ULL; @@ -320,7 +320,7 @@ DateTime::DateTime() memset(&Year, 0, &Microsecond - &Year + sizeof(Microsecond)); } -DateTime::DateTime(ulong seconds) +DateTime::DateTime(UInt64 seconds) { if(seconds == 0) memset(&Year, 0, &Microsecond - &Year + sizeof(Microsecond)); @@ -329,7 +329,7 @@ DateTime::DateTime(ulong seconds) } // 重载等号运算符 -DateTime& DateTime::operator=(ulong seconds) +DateTime& DateTime::operator=(UInt64 seconds) { Parse(seconds); @@ -347,9 +347,9 @@ uint DateTime::TotalSeconds() return s; } -ulong DateTime::TotalMicroseconds() +UInt64 DateTime::TotalMicroseconds() { - ulong sec = (ulong)TotalSeconds(); + UInt64 sec = (UInt64)TotalSeconds(); uint us = (uint)Millisecond * 1000 + Microsecond; return sec * 1000 + us; @@ -437,7 +437,7 @@ void TimeWheel::Reset(uint seconds, uint ms, uint us) // 是否已过期 bool TimeWheel::Expired() { - ulong now = Time.Current(); + UInt64 now = Time.Current(); if(now > Expire) return true; if(now == Expire && Time.CurrentTicks() >= Expire2) return true; diff --git a/Time.h b/Time.h index c5885cb9..531a9f3d 100644 --- a/Time.h +++ b/Time.h @@ -15,7 +15,7 @@ private: public: uint Seconds; // 全局秒数。累加 - ulong Milliseconds; // 全局毫秒数。累加 + UInt64 Milliseconds; // 全局毫秒数。累加 uint BaseSeconds; // 基准秒数。时间调节,影响Now() byte Ticks; // 每微秒的时钟滴答数 byte Index; // 定时器 @@ -35,8 +35,8 @@ public: void Init(); uint CurrentTicks() const; // 当前滴答时钟 - ulong Current() const; // 当前毫秒数 - void SetTime(ulong seconds); // 设置时间 + UInt64 Current() const; // 当前毫秒数 + void SetTime(UInt64 seconds); // 设置时间 void Sleep(uint ms, bool* running = NULL) const; // 微秒级延迟 @@ -68,7 +68,7 @@ public: class TimeCost { public: - ulong Start; // 开始时间,毫秒 + UInt64 Start; // 开始时间,毫秒 ushort StartTicks; // 开始滴答 TimeCost(); @@ -92,15 +92,15 @@ public: ushort Microsecond; DateTime(); - DateTime(ulong seconds); + DateTime(UInt64 seconds); // 重载等号运算符 - DateTime& operator=(ulong seconds); + DateTime& operator=(UInt64 seconds); - DateTime& Parse(ulong seconds); - DateTime& ParseUs(ulong us); + DateTime& Parse(UInt64 seconds); + DateTime& ParseUs(UInt64 us); uint TotalSeconds(); - ulong TotalMicroseconds(); + UInt64 TotalMicroseconds(); virtual String& ToStr(String& str) const; diff --git a/TinyIP/TinyIP.cpp b/TinyIP/TinyIP.cpp index 1bd9c0bc..480187cd 100644 --- a/TinyIP/TinyIP.cpp +++ b/TinyIP/TinyIP.cpp @@ -78,7 +78,7 @@ uint TinyIP::Fetch(Stream& ms) // 获取第一个结构体,不要移动指针 ETH_HEADER* eth = ms.Retrieve(false); - ulong v = eth->DestMac.Value(); + UInt64 v = eth->DestMac.Value(); // 广播地址有效,直接返回 if(!v || v == 0xFFFFFFFFFFFFFFFFull) return len; diff --git a/TinyIP/TinyIP.h b/TinyIP/TinyIP.h index fd6d33c7..805258d7 100644 --- a/TinyIP/TinyIP.h +++ b/TinyIP/TinyIP.h @@ -40,7 +40,7 @@ class TinyIP : public ISocketHost { private: ITransport* _port; - ulong _StartTime; + UInt64 _StartTime; ByteArray Buffer; // 缓冲区 // 循环调度的任务,捕获数据包,返回长度 diff --git a/TinyNet/TinyClient.h b/TinyNet/TinyClient.h index 74d45a74..512ef3f3 100644 --- a/TinyNet/TinyClient.h +++ b/TinyNet/TinyClient.h @@ -21,7 +21,7 @@ public: ushort Type; // 设备类型。两个字节可做二级分类 ByteArray Password; // 通讯密码 - ulong LastActive; // 最后活跃时间 + UInt64 LastActive; // 最后活跃时间 ushort HardCrc; // 硬件ID校验 bool Encryption; // 是否加密 diff --git a/TinyNet/TinyMessage.cpp b/TinyNet/TinyMessage.cpp index db548676..cbb5aee6 100644 --- a/TinyNet/TinyMessage.cpp +++ b/TinyNet/TinyMessage.cpp @@ -721,7 +721,7 @@ void TinyController::Loop() // 检查时间。至少发送一次 if(node.Times > 0) { - ulong now = Sys.Ms(); + UInt64 now = Sys.Ms(); // 已过期则删除 if(node.EndTime < now || node.Times > 50) @@ -771,7 +771,7 @@ void TinyController::Loop() // 计算下一次重发时间 { - ulong now = Sys.Ms(); + UInt64 now = Sys.Ms(); //node.LastSend = now; // 随机延迟。随机数1~5。每次延迟递增 @@ -834,7 +834,7 @@ void MessageNode::Set(const TinyMessage& msg, int msTimeout) Times = 0; //LastSend = 0; - ulong now = Sys.Ms(); + UInt64 now = Sys.Ms(); StartTime = now; EndTime = now + msTimeout; diff --git a/TinyNet/TinyMessage.h b/TinyNet/TinyMessage.h index 6af0b207..62f2acb4 100644 --- a/TinyNet/TinyMessage.h +++ b/TinyNet/TinyMessage.h @@ -64,7 +64,7 @@ class RingQueue public: int Index; ushort Arr[32]; - ulong Expired; // 过期时间,微秒 + UInt64 Expired; // 过期时间,微秒 RingQueue(); void Push(ushort item); @@ -104,10 +104,10 @@ public: byte Times; // 发送次数 byte Data[64]; byte Mac[6]; // 物理地址 - ulong StartTime; // 开始时间ms - ulong EndTime; // 过期时间ms - ulong Next; // 下一次重发时间ms - //ulong LastSend; // 最后一次发送时间ms + UInt64 StartTime; // 开始时间ms + UInt64 EndTime; // 过期时间ms + UInt64 Next; // 下一次重发时间ms + //UInt64 LastSend; // 最后一次发送时间ms void Set(const TinyMessage& msg, int msTimeout); }; diff --git a/TokenNet/DeviceMessage.cpp b/TokenNet/DeviceMessage.cpp index f5069756..e3405913 100644 --- a/TokenNet/DeviceMessage.cpp +++ b/TokenNet/DeviceMessage.cpp @@ -28,7 +28,7 @@ void DeviceMessage::Write(Stream& ms) const // 密码取MD5后传输 ms.WriteArray(MD5::Hash(Key)); - ulong now = Sys.Ms(); + UInt64 now = Sys.Ms(); //Salt.Set((byte*)&now, 8); //ms.WriteArray(Salt); ms.WriteArray(Array(&now, 8)); diff --git a/TokenNet/HelloMessage.h b/TokenNet/HelloMessage.h index 650bd30a..93eb6e50 100644 --- a/TokenNet/HelloMessage.h +++ b/TokenNet/HelloMessage.h @@ -14,7 +14,7 @@ public: ushort Version; // 版本 String Type; // 类型 String Name; // 名称 - ulong LocalTime; // 时间ms + UInt64 LocalTime; // 时间ms IPEndPoint EndPoint; ByteArray Ciphers; diff --git a/TokenNet/LoginMessage.cpp b/TokenNet/LoginMessage.cpp index d91041e4..4cf08545 100644 --- a/TokenNet/LoginMessage.cpp +++ b/TokenNet/LoginMessage.cpp @@ -37,7 +37,7 @@ void LoginMessage::Write(Stream& ms) const ms.WriteArray(Salt); else { - ulong now = Sys.Ms(); + UInt64 now = Sys.Ms(); ms.WriteArray(MD5::Hash(Array(&now, 8))); } } diff --git a/TokenNet/RegisterMessage.cpp b/TokenNet/RegisterMessage.cpp index a520457d..c8d4b4df 100644 --- a/TokenNet/RegisterMessage.cpp +++ b/TokenNet/RegisterMessage.cpp @@ -32,7 +32,7 @@ void RegisterMessage::Write(Stream& ms) const ms.WriteArray(Salt); else { - ulong now = Sys.Ms(); + UInt64 now = Sys.Ms(); ms.WriteArray(MD5::Hash(Array(&now, 8))); } } diff --git a/TokenNet/TokenClient.cpp b/TokenNet/TokenClient.cpp index 19704bc0..5be7978a 100644 --- a/TokenNet/TokenClient.cpp +++ b/TokenNet/TokenClient.cpp @@ -464,7 +464,7 @@ void TokenClient::Ping() TokenMessage msg(3); - ulong time = Sys.Ms(); + UInt64 time = Sys.Ms(); Stream ms = msg.ToStream(); ms.WriteArray(Array(&time, 8)); msg.Length = ms.Position(); @@ -479,8 +479,8 @@ bool TokenClient::OnPing(TokenMessage& msg, Controller* ctrl) Stream ms = msg.ToStream(); - ulong now = Sys.Ms(); - ulong start = ms.ReadArray().ToUInt64(); + UInt64 now = Sys.Ms(); + UInt64 start = ms.ReadArray().ToUInt64(); int cost = (int)(now - start); if(cost < 0) cost = -cost; if(cost > 1000) ((TTime&)Time).SetTime(start / 1000); diff --git a/TokenNet/TokenClient.h b/TokenNet/TokenClient.h index 779384df..eaef516e 100644 --- a/TokenNet/TokenClient.h +++ b/TokenNet/TokenClient.h @@ -19,8 +19,8 @@ public: int Status; // 状态。0准备、1握手完成、2登录后 - ulong LoginTime; // 登录时间ms - ulong LastActive; // 最后活跃时间ms + UInt64 LoginTime; // 登录时间ms + UInt64 LastActive; // 最后活跃时间ms int Delay; // 心跳延迟。一条心跳指令从发出到收到所花费的时间 Controller* Control; @@ -80,8 +80,8 @@ public: IPEndPoint Addr; // 地址 int Status; // 状态。0准备、1握手完成、2登录后 - ulong LoginTime; // 登录时间ms - ulong LastActive; // 最后活跃时间ms + UInt64 LoginTime; // 登录时间ms + UInt64 LastActive; // 最后活跃时间ms }; #endif diff --git a/TokenNet/TokenMessage.h b/TokenNet/TokenMessage.h index d0f4e92b..c36c4f87 100644 --- a/TokenNet/TokenMessage.h +++ b/TokenNet/TokenMessage.h @@ -100,7 +100,7 @@ private: { public: byte Code; - ulong Time; // 时间ms + UInt64 Time; // 时间ms }; QueueItem _Queue[16]; diff --git a/Type.cpp b/Type.cpp index 884de4e3..37c663dd 100644 --- a/Type.cpp +++ b/Type.cpp @@ -3,7 +3,6 @@ #include #include #include "Sys.h" -#include "Platform\stm32.h" /******************************** Object ********************************/ @@ -597,7 +596,7 @@ int ByteArray::Load(const void* data, int maxsize) // 从普通字节数据组加载,首字节为长度 int ByteArray::Save(void* data, int maxsize) const { - assert_param(_Length <= 0xFF); + assert_param2(_Length <= 0xFF, "_Length <= 0xFF"); byte* p = (byte*)data; int len = _Length <= maxsize ? _Length : maxsize; @@ -644,17 +643,17 @@ uint ByteArray::ToUInt32() const return p[0] | (p[1] << 8) | (p[2] << 0x10) | (p[3] << 0x18); } -ulong ByteArray::ToUInt64() const +UInt64 ByteArray::ToUInt64() const { auto p = GetBuffer(); // 字节对齐时才能之前转为目标整数 - if(((int)p & 0x07) == 0) return *(ulong*)p; + if(((int)p & 0x07) == 0) return *(UInt64*)p; uint n1 = p[0] | (p[1] << 8) | (p[2] << 0x10) | (p[3] << 0x18); p += 4; uint n2 = p[0] | (p[1] << 8) | (p[2] << 0x10) | (p[3] << 0x18); - return n1 | ((ulong)n2 << 0x20); + return n1 | ((UInt64)n2 << 0x20); } void ByteArray::Write(ushort value, int index) @@ -677,12 +676,23 @@ void ByteArray::Write(int value, int index) Copy(index, (byte*)&value, sizeof(int)); } -void ByteArray::Write(ulong value, int index) +void ByteArray::Write(UInt64 value, int index) { - Copy(index, (byte*)&value, sizeof(ulong)); + Copy(index, (byte*)&value, sizeof(UInt64)); } /******************************** REV ********************************/ -uint _REV(uint value) { return __REV(value); } -ushort _REV16(ushort value) { return __REV16(value); } +//uint _REV(uint value) { return __REV(value); } +//ushort _REV16(ushort value) { return __REV16(value); } +__asm uint _REV(uint value) +{ + rev16 r0, r0 + bx lr +} + +__asm ushort _REV16(ushort value) +{ + rev16 r0, r0 + bx lr +} diff --git a/Type.h b/Type.h index a56321ec..f2dace0d 100644 --- a/Type.h +++ b/Type.h @@ -9,7 +9,7 @@ typedef char sbyte; typedef unsigned char byte; typedef unsigned short ushort; typedef unsigned int uint; -typedef unsigned long long ulong; +typedef unsigned long long UInt64; typedef long long Int64; #define UInt64_Max 0xFFFFFFFFFFFFFFFFull @@ -348,12 +348,12 @@ public: ushort ToUInt16() const; uint ToUInt32() const; - ulong ToUInt64() const; + UInt64 ToUInt64() const; void Write(ushort value, int index = 0); void Write(short value, int index = 0); void Write(uint value, int index = 0); void Write(int value, int index = 0); - void Write(ulong value, int index = 0); + void Write(UInt64 value, int index = 0); //friend bool operator==(const ByteArray& bs1, const ByteArray& bs2); //friend bool operator!=(const ByteArray& bs1, const ByteArray& bs2);