parent
9523a0c4e2
commit
232caf7e34
|
@ -38,7 +38,7 @@ void IRcoding::SetCfgAddr(uint addr)
|
|||
}
|
||||
}
|
||||
|
||||
bool IRcoding::SaveCoding(byte index, const ByteArray& bs)
|
||||
bool IRcoding::SaveCoding(byte index, const Array& bs)
|
||||
{
|
||||
if(bs.Length() > CodingSize)return false;
|
||||
if(!_Medium)return false;
|
||||
|
@ -46,7 +46,7 @@ bool IRcoding::SaveCoding(byte index, const ByteArray& bs)
|
|||
return _Medium->Write(address, bs);
|
||||
}
|
||||
|
||||
bool IRcoding::GetCoding(byte index, ByteArray& bs)
|
||||
bool IRcoding::GetCoding(byte index, Array& bs)
|
||||
{
|
||||
if(bs.Length() > CodingSize)return false;
|
||||
if(!_Medium)return false;
|
||||
|
|
|
@ -34,8 +34,8 @@ public:
|
|||
// 设置配置区所在位置
|
||||
void SetCfgAddr(uint addr);
|
||||
|
||||
bool SaveCoding(byte index, const ByteArray& bs);
|
||||
bool GetCoding(byte index, ByteArray& bs);
|
||||
bool SaveCoding(byte index, const Array& bs);
|
||||
bool GetCoding(byte index, Array& bs);
|
||||
|
||||
};
|
||||
|
||||
|
|
20
Config.cpp
20
Config.cpp
|
@ -17,8 +17,8 @@ struct ConfigBlock
|
|||
const ConfigBlock* Next() const;
|
||||
const void* Data() const;
|
||||
|
||||
bool Init(const char* name, const ByteArray& bs);
|
||||
bool Write(Storage* storage, uint addr, const ByteArray& bs);
|
||||
bool Init(const char* name, const Array& bs);
|
||||
bool Write(Storage* storage, uint addr, const Array& bs);
|
||||
};
|
||||
|
||||
ushort ConfigBlock::GetHash() const
|
||||
|
@ -49,7 +49,7 @@ const void* ConfigBlock::Data() const
|
|||
}
|
||||
|
||||
// 构造一个新的配置块
|
||||
bool ConfigBlock::Init(const char* name, const ByteArray& bs)
|
||||
bool ConfigBlock::Init(const char* name, const Array& bs)
|
||||
{
|
||||
assert_param2(name, "配置块名称不能为空");
|
||||
|
||||
|
@ -74,7 +74,7 @@ bool ConfigBlock::Init(const char* name, const ByteArray& bs)
|
|||
}
|
||||
|
||||
// 更新块
|
||||
bool ConfigBlock::Write(Storage* storage, uint addr, const ByteArray& bs)
|
||||
bool ConfigBlock::Write(Storage* storage, uint addr, const Array& bs)
|
||||
{
|
||||
assert_ptr(storage);
|
||||
|
||||
|
@ -89,12 +89,12 @@ bool ConfigBlock::Write(Storage* storage, uint addr, const ByteArray& bs)
|
|||
|
||||
// 先写入头部,然后写入数据
|
||||
uint len = sizeof(ConfigBlock) - offsetof(ConfigBlock, HeaderCRC);
|
||||
if(!storage->Write(addr, ByteArray(&HeaderCRC, len))) return false;
|
||||
if(!storage->Write(addr, Array(&HeaderCRC, len))) return false;
|
||||
if(bs.Length() > 0)
|
||||
{
|
||||
uint len2 = bs.Length();
|
||||
if(len2 > Size) len2 = Size;
|
||||
if(!storage->Write(addr + len, ByteArray(bs.GetBuffer(), len2))) return false;
|
||||
if(!storage->Write(addr + len, Array(bs.GetBuffer(), len2))) return false;
|
||||
}
|
||||
|
||||
return rs;
|
||||
|
@ -121,7 +121,7 @@ const void* Config::Find(const char* name, int size)
|
|||
{
|
||||
if(!size) return NULL;
|
||||
|
||||
Device->Write(addr, ByteArray(&c_Version, sizeof(c_Version)));
|
||||
Device->Write(addr, Array(&c_Version, sizeof(c_Version)));
|
||||
}
|
||||
|
||||
addr += sizeof(c_Version);
|
||||
|
@ -160,7 +160,7 @@ bool Config::Invalid(const char* name)
|
|||
}
|
||||
|
||||
// 根据名称更新块
|
||||
const void* Config::Set(const char* name, const ByteArray& bs)
|
||||
const void* Config::Set(const char* name, const Array& bs)
|
||||
{
|
||||
//if(name == NULL) return NULL;
|
||||
assert_param2(name, "配置块名称不能为空");
|
||||
|
@ -181,7 +181,7 @@ const void* Config::Set(const char* name, const ByteArray& bs)
|
|||
}
|
||||
|
||||
// 获取配置数据
|
||||
bool Config::Get(const char* name, ByteArray& bs)
|
||||
bool Config::Get(const char* name, Array& bs)
|
||||
{
|
||||
//if(name == NULL) return false;
|
||||
assert_param2(name, "配置块名称不能为空");
|
||||
|
@ -199,7 +199,7 @@ bool Config::Get(const char* name, ByteArray& bs)
|
|||
}
|
||||
|
||||
// 获取配置数据,如果不存在则覆盖
|
||||
bool Config::GetOrSet(const char* name, ByteArray& bs)
|
||||
bool Config::GetOrSet(const char* name, Array& bs)
|
||||
{
|
||||
//if(name == NULL) return false;
|
||||
assert_param2(name, "配置块名称不能为空");
|
||||
|
|
6
Config.h
6
Config.h
|
@ -22,11 +22,11 @@ public:
|
|||
// 废弃。仅清空名称,并不删除数据区
|
||||
bool Invalid(const char* name);
|
||||
// 设置配置数据
|
||||
const void* Set(const char* name, const ByteArray& bs);
|
||||
const void* Set(const char* name, const Array& bs);
|
||||
// 获取配置数据
|
||||
bool Get(const char* name, ByteArray& bs);
|
||||
bool Get(const char* name, Array& bs);
|
||||
// 获取配置数据,如果不存在则覆盖
|
||||
bool GetOrSet(const char* name, ByteArray& bs);
|
||||
bool GetOrSet(const char* name, Array& bs);
|
||||
// 获取配置数据
|
||||
const void* Get(const char* name);
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ byte AT24CXX::Read(ushort addr)
|
|||
return IIC->Read(addr & 0xFF);
|
||||
}
|
||||
|
||||
bool AT24CXX::Write(uint addr, const ByteArray& bs)
|
||||
bool AT24CXX::Write(uint addr, const Array& bs)
|
||||
{
|
||||
if(!IIC) return false;
|
||||
|
||||
|
@ -65,7 +65,7 @@ bool AT24CXX::Write(uint addr, const ByteArray& bs)
|
|||
return IIC->Write((ushort)addr, bs);
|
||||
}
|
||||
|
||||
bool AT24CXX::Read(uint addr, ByteArray& bs)
|
||||
bool AT24CXX::Read(uint addr, Array& bs)
|
||||
{
|
||||
if(!IIC) return false;
|
||||
|
||||
|
|
|
@ -18,8 +18,8 @@ public:
|
|||
bool Write(ushort addr, byte data);
|
||||
byte Read(ushort addr);
|
||||
|
||||
virtual bool Write(uint addr, const ByteArray& bs);
|
||||
virtual bool Read(uint addr, ByteArray& bs);
|
||||
virtual bool Write(uint addr, const Array& bs);
|
||||
virtual bool Read(uint addr, Array& bs);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -56,8 +56,7 @@ void ShunCom::ShowConfig()
|
|||
Sys.Sleep(3000);
|
||||
|
||||
byte buf[] = { 0xFE, 0x00, 0x21, 0x15, 0x34 };
|
||||
ByteArray bs(buf, ArrayLength(buf));
|
||||
Write(bs);
|
||||
Write(CArray(buf));
|
||||
|
||||
Sys.Sleep(300);
|
||||
|
||||
|
|
|
@ -334,7 +334,7 @@ void W5500::Config()
|
|||
{
|
||||
// 读所有寄存器
|
||||
TGeneral gen;
|
||||
ByteArray bs((byte*)&gen, sizeof(gen));
|
||||
ByteArray bs(&gen, sizeof(gen));
|
||||
ReadFrame(0, bs);
|
||||
|
||||
// 设置地址、网关、掩码、MAC等
|
||||
|
@ -437,7 +437,7 @@ void W5500::StateShow()
|
|||
{
|
||||
// 一次性全部读出
|
||||
TGeneral gen;
|
||||
ByteArray bs((byte*)&gen, sizeof(gen));
|
||||
ByteArray bs(&gen, sizeof(gen));
|
||||
ReadFrame(0, bs);
|
||||
|
||||
debug_printf("\r\nW5500::State\r\n");
|
||||
|
@ -867,7 +867,7 @@ void HardSocket::WriteInterrupt(byte dat) { SocRegWrite(IR, dat); }
|
|||
void HardSocket::StateShow()
|
||||
{
|
||||
TSocket soc;
|
||||
ByteArray bs((byte*)&soc, sizeof(soc));
|
||||
ByteArray bs(&soc, sizeof(soc));
|
||||
|
||||
// 一次性全部读出
|
||||
_Host->ReadFrame(0, bs, Index, 0x01);
|
||||
|
@ -1286,7 +1286,7 @@ void TcpClient::OnProcess(byte reg)
|
|||
void TcpClient::RaiseReceive()
|
||||
{
|
||||
byte buf[1500];
|
||||
ByteArray bs(buf, ArrayLength(buf));
|
||||
Array bs(buf, ArrayLength(buf));
|
||||
int size = Receive(bs);
|
||||
if(size > 1500)return;
|
||||
|
||||
|
@ -1345,7 +1345,7 @@ void UdpClient::RaiseReceive()
|
|||
// UDP 异步只有一种情况 收到数据 可能有多个数据包
|
||||
// UDP接收到的数据结构: RemoteIP(4 byte) + RemotePort(2 byte) + Length(2 byte) + Data(Length byte)
|
||||
byte buf[1500];
|
||||
ByteArray bs(buf, ArrayLength(buf));
|
||||
Array bs(buf, ArrayLength(buf));
|
||||
ushort size = Receive(bs);
|
||||
Stream ms(bs.GetBuffer(), size);
|
||||
|
||||
|
|
6
I2C.cpp
6
I2C.cpp
|
@ -111,7 +111,7 @@ bool I2C::SendSubAddr(int addr)
|
|||
}
|
||||
|
||||
// 新会话向指定地址写入多个字节
|
||||
bool I2C::Write(int addr, const ByteArray& bs)
|
||||
bool I2C::Write(int addr, const Array& bs)
|
||||
{
|
||||
/*debug_printf("I2C::Write addr=0x%02X ", addr);
|
||||
bs.Show(true);*/
|
||||
|
@ -135,7 +135,7 @@ bool I2C::Write(int addr, const ByteArray& bs)
|
|||
}
|
||||
|
||||
// 新会话从指定地址读取多个字节
|
||||
uint I2C::Read(int addr, ByteArray& bs)
|
||||
uint I2C::Read(int addr, Array& bs)
|
||||
{
|
||||
Open();
|
||||
|
||||
|
@ -155,7 +155,7 @@ uint I2C::Read(int addr, ByteArray& bs)
|
|||
return rs;
|
||||
}
|
||||
|
||||
bool I2C::Write(int addr, byte data) { return Write(addr, ByteArray(&data, 1)); }
|
||||
bool I2C::Write(int addr, byte data) { return Write(addr, Array(&data, 1)); }
|
||||
byte I2C::Read(int addr)
|
||||
{
|
||||
ByteArray bs(1);
|
||||
|
|
4
I2C.h
4
I2C.h
|
@ -38,10 +38,10 @@ public:
|
|||
virtual bool WaitAck(int retry = 0) = 0; // 等待Ack,默认0表示采用全局Retry
|
||||
|
||||
// 新会话向指定地址写入
|
||||
virtual bool Write(int addr, const ByteArray& bs);
|
||||
virtual bool Write(int addr, const Array& bs);
|
||||
virtual bool Write(int addr, byte data);
|
||||
// 新会话从指定地址读取
|
||||
virtual uint Read(int addr, ByteArray& bs);
|
||||
virtual uint Read(int addr, Array& bs);
|
||||
virtual byte Read(int addr);
|
||||
virtual ushort Read2(int addr);
|
||||
virtual uint Read4(int addr);
|
||||
|
|
|
@ -11,7 +11,7 @@ Message::Message(byte code)
|
|||
State = NULL;
|
||||
}
|
||||
|
||||
// 设置数据。
|
||||
/*// 设置数据。
|
||||
void Message::SetData(const void* buf, uint len, uint offset)
|
||||
{
|
||||
//assert_param(len <= ArrayLength(Data));
|
||||
|
@ -23,9 +23,9 @@ void Message::SetData(const void* buf, uint len, uint offset)
|
|||
assert_ptr(Data);
|
||||
memcpy(Data + offset, buf, len);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
void Message::SetData(const ByteArray& bs, uint offset)
|
||||
void Message::SetData(const Array& bs, uint offset)
|
||||
{
|
||||
Length = bs.Length() + offset;
|
||||
if(Length > 0 && bs.GetBuffer() != Data + offset) bs.CopyTo(Data + offset, Length);
|
||||
|
|
|
@ -37,8 +37,8 @@ public:
|
|||
virtual bool Clone(const Message& msg);
|
||||
|
||||
// 设置数据
|
||||
void SetData(const void* buf, uint len, uint offset = 0);
|
||||
void SetData(const ByteArray& bs, uint offset = 0);
|
||||
//void SetData(const void* buf, uint len, uint offset = 0);
|
||||
void SetData(const Array& bs, uint offset = 0);
|
||||
void SetError(byte errorCode, const char* msg = NULL);
|
||||
|
||||
// 负载数据转数据流
|
||||
|
|
|
@ -142,9 +142,9 @@ bool Blu40::SetBP(int BP)
|
|||
*_rts = false;
|
||||
Sys.Delay(150);
|
||||
|
||||
const ByteArray bs(AT_BPS, sizeof(AT_BPS));
|
||||
const Array bs(AT_BPS, sizeof(AT_BPS));
|
||||
_port->Write(bs);
|
||||
_port->Write(ByteArray(&bpnumIndex, 1)); // 晕死,AT指令里面放非字符
|
||||
_port->Write(Array(&bpnumIndex, 1)); // 晕死,AT指令里面放非字符
|
||||
//_port->Write("\r\n",sizeof("\r\n")); // 无需回车
|
||||
*_rts = true;
|
||||
|
||||
|
@ -179,9 +179,9 @@ bool Blu40::SetBP(int BP)
|
|||
Sys.Delay(170);
|
||||
//_port->Write(AT_BPS,sizeof(AT_BPS));
|
||||
//_port->Write(&bpnumIndex,1); // 晕死,AT指令里面放非字符
|
||||
const ByteArray bs(AT_BPS, sizeof(AT_BPS));
|
||||
const Array bs(AT_BPS, sizeof(AT_BPS));
|
||||
_port->Write(bs);
|
||||
_port->Write(ByteArray(&bpnumIndex, 1));
|
||||
_port->Write(Array(&bpnumIndex, 1));
|
||||
//_port->Write("\r\n",sizeof("\r\n")); // 无需回车
|
||||
*_rts = true;
|
||||
|
||||
|
@ -232,8 +232,8 @@ bool Blu40::SetName(string name)
|
|||
{
|
||||
*_rts = false;
|
||||
Sys.Delay(170);
|
||||
_port->Write(ByteArray(AT_REN, sizeof(AT_REN)));
|
||||
_port->Write(ByteArray((byte*)name, sizeof(name)));
|
||||
_port->Write(Array(AT_REN, sizeof(AT_REN)));
|
||||
_port->Write(Array((byte*)name, sizeof(name)));
|
||||
bool ret = CheckSet();
|
||||
*_rts = true;
|
||||
return ret;
|
||||
|
@ -243,8 +243,8 @@ bool Blu40::SetPID(ushort pid)
|
|||
{
|
||||
*_rts = false;
|
||||
Sys.Delay(170);
|
||||
_port->Write(ByteArray(AT_PID, sizeof(AT_PID)));
|
||||
_port->Write(ByteArray((byte*)pid, 2));
|
||||
_port->Write(Array(AT_PID, sizeof(AT_PID)));
|
||||
_port->Write(Array((byte*)pid, 2));
|
||||
bool ret = CheckSet();
|
||||
*_rts = true;
|
||||
return ret;
|
||||
|
@ -260,9 +260,9 @@ bool Blu40::SetTPL(int TPLDB)
|
|||
}
|
||||
*_rts = false;
|
||||
Sys.Delay(170);
|
||||
_port->Write(ByteArray(AT_TPL, sizeof(AT_TPL)));
|
||||
_port->Write(Array(AT_TPL, sizeof(AT_TPL)));
|
||||
//byte temp = TPLNumIndex+'0';// 又是坑人的 非字符
|
||||
_port->Write(ByteArray(&TPLNumIndex,1));
|
||||
_port->Write(Array(&TPLNumIndex,1));
|
||||
bool ret = CheckSet();
|
||||
*_rts = true;
|
||||
return ret;
|
||||
|
|
|
@ -339,8 +339,8 @@ IPAddress DNS::Query(const String& domain, int msTimeout)
|
|||
#endif
|
||||
|
||||
byte buf[1024];
|
||||
ByteArray bs(buf, ArrayLength(buf));
|
||||
ByteArray rs(buf, ArrayLength(buf));
|
||||
Array bs(buf, ArrayLength(buf));
|
||||
Array rs(buf, ArrayLength(buf));
|
||||
// 同时作为响应缓冲区,别浪费了
|
||||
rs.SetLength(0);
|
||||
_Buffer = &rs;
|
||||
|
|
|
@ -18,7 +18,7 @@ private:
|
|||
static uint OnReceive(ITransport* port, Array& bs, void* param, void* param2);
|
||||
void Process(Array& bs, const IPEndPoint& server);
|
||||
|
||||
ByteArray* _Buffer;
|
||||
Array* _Buffer;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -54,8 +54,8 @@ void Dhcp::SendDhcp(byte* buf, uint len)
|
|||
String vendor = "http://www.NewLifeX.com";
|
||||
opt = opt->Next()->SetData(DHCP_OPT_Vendor, vendor);
|
||||
byte ps[] = { 0x01, 0x06, 0x03, 0x2b}; // 需要参数 Mask/DNS/Router/Vendor
|
||||
ByteArray bs(ps, ArrayLength(ps));
|
||||
opt = opt->Next()->SetData(DHCP_OPT_ParameterList, bs);
|
||||
//ByteArray bs(ps, ArrayLength(ps));
|
||||
opt = opt->Next()->SetData(DHCP_OPT_ParameterList, CArray(ps));
|
||||
opt = opt->Next()->End();
|
||||
|
||||
len = (byte*)opt + 1 - p;
|
||||
|
@ -65,7 +65,7 @@ void Dhcp::SendDhcp(byte* buf, uint len)
|
|||
dhcp->ClientMac[i] = Host->Mac[i];
|
||||
|
||||
//Send(*dhcp.Prev(), sizeof(DHCP_HEADER) + len, Remote.Address, Remote.Port, false);
|
||||
ByteArray bs((byte*)dhcp, sizeof(DHCP_HEADER) + len);
|
||||
Array bs(dhcp, sizeof(DHCP_HEADER) + len);
|
||||
Socket->Send(bs);
|
||||
}
|
||||
|
||||
|
|
|
@ -367,7 +367,7 @@ typedef struct _DHCP_OPT
|
|||
return this;
|
||||
}
|
||||
|
||||
struct _DHCP_OPT* SetData(DHCP_OPTION option, ByteArray& bs)
|
||||
struct _DHCP_OPT* SetData(DHCP_OPTION option, const Array& bs)
|
||||
{
|
||||
Option = option;
|
||||
Length = bs.Length();
|
||||
|
|
21
Net/Net.cpp
21
Net/Net.cpp
|
@ -17,7 +17,7 @@ IPAddress::IPAddress(byte ip1, byte ip2, byte ip3, byte ip4)
|
|||
Value = (ip4 << 24) + (ip3 << 16) + (ip2 << 8) + ip1;
|
||||
}
|
||||
|
||||
IPAddress::IPAddress(const ByteArray& arr)
|
||||
IPAddress::IPAddress(const Array& arr)
|
||||
{
|
||||
memcpy((byte*)&Value, arr.GetBuffer(), 4);
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ ByteArray IPAddress::ToArray() const
|
|||
//return ByteArray((byte*)&Value, 4);
|
||||
|
||||
// 要复制数据,而不是直接使用指针,那样会导致外部修改内部数据
|
||||
return ByteArray((byte*)&Value, 4, true);
|
||||
return ByteArray(&Value, 4, true);
|
||||
}
|
||||
|
||||
void IPAddress::CopyTo(byte* ips) const
|
||||
|
@ -102,7 +102,7 @@ IPEndPoint::IPEndPoint(const IPAddress& addr, ushort port)
|
|||
Port = port;
|
||||
}
|
||||
|
||||
IPEndPoint::IPEndPoint(const ByteArray& arr)
|
||||
IPEndPoint::IPEndPoint(const Array& arr)
|
||||
{
|
||||
byte* p = arr.GetBuffer();
|
||||
Address = p;
|
||||
|
@ -153,12 +153,13 @@ MacAddress::MacAddress(const byte* macs)
|
|||
{
|
||||
/*ByteArray bs(macs, 6);
|
||||
Value = bs.ToUInt64() & MAC_MASK;*/
|
||||
memcpy((byte*)&Value, macs, 6);
|
||||
memcpy(&Value, macs, 6);
|
||||
}
|
||||
|
||||
MacAddress::MacAddress(const ByteArray& arr)
|
||||
MacAddress::MacAddress(const Array& arr)
|
||||
{
|
||||
Value = arr.ToUInt64();
|
||||
ByteArray bs(arr.GetBuffer(), arr.Length());
|
||||
Value = bs.ToUInt64();
|
||||
Value &= MAC_MASK;
|
||||
}
|
||||
|
||||
|
@ -186,7 +187,7 @@ MacAddress& MacAddress::operator=(ulong v)
|
|||
|
||||
MacAddress& MacAddress::operator=(const byte* buf)
|
||||
{
|
||||
/*ByteArray bs(buf, 6);
|
||||
/*Array bs(buf, 6);
|
||||
Value = bs.ToUInt64() & MAC_MASK;*/
|
||||
memcpy((byte*)&Value, buf, 6);
|
||||
|
||||
|
@ -207,7 +208,7 @@ ByteArray MacAddress::ToArray() const
|
|||
//return ByteArray((byte*)&Value, 6);
|
||||
|
||||
// 要复制数据,而不是直接使用指针,那样会导致外部修改内部数据
|
||||
return ByteArray((byte*)&Value, 6, true);
|
||||
return ByteArray(&Value, 6, true);
|
||||
}
|
||||
|
||||
void MacAddress::CopyTo(byte* macs) const
|
||||
|
@ -262,7 +263,7 @@ bool ISocketHost::LoadConfig()
|
|||
if(!Config::Current) return false;
|
||||
|
||||
NetConfig nc;
|
||||
ByteArray bs(&nc, sizeof(nc));
|
||||
Array bs(&nc, sizeof(nc));
|
||||
if(!Config::Current->Get("NET", bs)) return false;
|
||||
|
||||
IP = nc.IP;
|
||||
|
@ -289,6 +290,6 @@ bool ISocketHost::SaveConfig()
|
|||
nc.DNSServer = DNSServer.Value;
|
||||
nc.Gateway = Gateway.Value;
|
||||
|
||||
ByteArray bs(&nc, sizeof(nc));
|
||||
Array bs(&nc, sizeof(nc));
|
||||
return Config::Current->Set("NET", bs);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ public:
|
|||
IPAddress(uint value = 0) { Value = value; }
|
||||
IPAddress(const byte* ips);
|
||||
IPAddress(byte ip1, byte ip2, byte ip3, byte ip4);
|
||||
IPAddress(const ByteArray& arr);
|
||||
IPAddress(const Array& arr);
|
||||
|
||||
IPAddress& operator=(int v) { Value = (uint)v; return *this; }
|
||||
IPAddress& operator=(uint v) { Value = v; return *this; }
|
||||
|
@ -49,7 +49,7 @@ public:
|
|||
|
||||
IPEndPoint();
|
||||
IPEndPoint(const IPAddress& addr, ushort port);
|
||||
IPEndPoint(const ByteArray& arr);
|
||||
IPEndPoint(const Array& arr);
|
||||
|
||||
// 输出对象的字符串表示方式
|
||||
virtual String& ToStr(String& str) const;
|
||||
|
@ -69,7 +69,7 @@ public:
|
|||
|
||||
MacAddress(ulong v = 0);
|
||||
MacAddress(const byte* macs);
|
||||
MacAddress(const ByteArray& arr);
|
||||
MacAddress(const Array& arr);
|
||||
|
||||
// 是否广播地址,全0或全1
|
||||
bool IsBroadcast() const;
|
||||
|
|
|
@ -40,9 +40,10 @@ static const uint c_CRCTable[ 256 ] =
|
|||
0xAFB010B1, 0xAB710D06, 0xA6322BDF, 0xA2F33668, 0xBCB4666D, 0xB8757BDA, 0xB5365D03, 0xB1F740B4
|
||||
};
|
||||
|
||||
uint Crc::Hash(const void* buf, uint len, uint crc)
|
||||
uint Crc::Hash(const Array& arr, uint crc)
|
||||
{
|
||||
byte* ptr = (byte*)buf;
|
||||
const byte* ptr = arr.GetBuffer();
|
||||
int len = arr.Length();
|
||||
while(len-- > 0)
|
||||
{
|
||||
crc = c_CRCTable[ ((crc >> 24) ^ (*ptr++)) & 0xFF ] ^ (crc << 8);
|
||||
|
|
|
@ -9,8 +9,8 @@ class Crc
|
|||
public:
|
||||
// CRC32校验
|
||||
//uint Crc(const void* buf, uint len);
|
||||
static uint Hash(const void* buf, uint len, uint crc = 0);
|
||||
static ushort Hash16(const void* buf, uint len, ushort crc = 0xFFFF);
|
||||
static uint Hash(const Array& arr, uint crc = 0);
|
||||
static ushort Hash16(const Array& arr, ushort crc = 0xFFFF);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -6,14 +6,17 @@ static const ushort c_CRC16Table[] =
|
|||
0xA001, 0x6C00, 0x7800, 0xB401, 0x5000, 0x9C01, 0x8801, 0x4400,
|
||||
};
|
||||
|
||||
ushort Crc::Hash16(const void* buf, uint len, ushort crc)
|
||||
ushort Crc::Hash16(const Array& arr, ushort crc)
|
||||
{
|
||||
const byte* buf = arr.GetBuffer();
|
||||
int len = arr.Length();
|
||||
|
||||
assert_param2(buf, "Crc16校验目标地址不能为空");
|
||||
if (!buf || !len) return 0;
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
byte b = ((byte*)buf)[i];
|
||||
byte b = buf[i];
|
||||
crc = (ushort)(c_CRC16Table[(b ^ crc) & 0x0F] ^ (crc >> 4));
|
||||
crc = (ushort)(c_CRC16Table[((b >> 4) ^ crc) & 0x0F] ^ (crc >> 4));
|
||||
}
|
||||
|
|
|
@ -226,7 +226,7 @@ void md5_finish(md5_context *ctx, byte digest[16] )
|
|||
PUT_UINT32( ctx->state[3], digest, 12 );
|
||||
}
|
||||
|
||||
ByteArray MD5::Hash(const ByteArray& data)
|
||||
ByteArray MD5::Hash(const Array& data)
|
||||
{
|
||||
md5_context context;
|
||||
md5_starts(&context);
|
||||
|
|
|
@ -8,7 +8,7 @@ class MD5
|
|||
{
|
||||
public:
|
||||
// 散列
|
||||
static ByteArray Hash(const ByteArray& data);
|
||||
static ByteArray Hash(const Array& data);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#define KeyLength 256
|
||||
|
||||
void GetKey(ByteArray& box, const ByteArray& pass)
|
||||
void GetKey(ByteArray& box, const Array& pass)
|
||||
{
|
||||
for (int i = 0; i < box.Length(); i++)
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ void GetKey(ByteArray& box, const ByteArray& pass)
|
|||
}
|
||||
}
|
||||
|
||||
ByteArray RC4::Encrypt(const ByteArray& data, const ByteArray& pass)
|
||||
ByteArray RC4::Encrypt(const Array& data, const Array& pass)
|
||||
{
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
|
|
|
@ -8,7 +8,7 @@ class RC4
|
|||
{
|
||||
public:
|
||||
// 加解密
|
||||
static ByteArray Encrypt(const ByteArray& data, const ByteArray& pass);
|
||||
static ByteArray Encrypt(const Array& data, const Array& pass);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#endif
|
||||
|
||||
/* 读取段数据 (起始段,字节数量,目标缓冲区) */
|
||||
bool BlockStorage::Read(uint address, ByteArray& bs)
|
||||
bool BlockStorage::Read(uint address, Array& bs)
|
||||
{
|
||||
uint len = bs.Length();
|
||||
if (!len) return true;
|
||||
|
@ -25,7 +25,7 @@ bool BlockStorage::Read(uint address, ByteArray& bs)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool BlockStorage::Write(uint address, const ByteArray& bs)
|
||||
bool BlockStorage::Write(uint address, const Array& bs)
|
||||
{
|
||||
assert_param2((address & 0x01) == 0x00, "Write起始地址必须是2字节对齐");
|
||||
|
||||
|
@ -212,14 +212,14 @@ bool BlockStorage::IsErased(uint address, uint len)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool CharStorage::Read(uint address, ByteArray& bs)
|
||||
bool CharStorage::Read(uint address, Array& bs)
|
||||
{
|
||||
bs.Copy((byte*)address);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CharStorage::Write(uint address, const ByteArray& bs)
|
||||
bool CharStorage::Write(uint address, const Array& bs)
|
||||
{
|
||||
bs.CopyTo((byte*)address);
|
||||
|
||||
|
|
|
@ -9,9 +9,9 @@ class Storage
|
|||
{
|
||||
public:
|
||||
// 读取
|
||||
virtual bool Read(uint address, ByteArray& bs) = 0;
|
||||
virtual bool Read(uint address, Array& bs) = 0;
|
||||
// 写入
|
||||
virtual bool Write(uint address, const ByteArray& bs) = 0;
|
||||
virtual bool Write(uint address, const Array& bs) = 0;
|
||||
};
|
||||
|
||||
// 块存储接口
|
||||
|
@ -24,9 +24,9 @@ public:
|
|||
bool ReadModifyWrite; // 是否读改写
|
||||
|
||||
// 读取
|
||||
virtual bool Read(uint address, ByteArray& bs);
|
||||
virtual bool Read(uint address, Array& bs);
|
||||
// 写入
|
||||
virtual bool Write(uint address, const ByteArray& bs);
|
||||
virtual bool Write(uint address, const Array& bs);
|
||||
// 清空
|
||||
virtual bool Memset(uint address, byte data, uint len);
|
||||
// 擦除
|
||||
|
@ -46,9 +46,9 @@ class CharStorage : public Storage
|
|||
{
|
||||
public:
|
||||
// 读取
|
||||
virtual bool Read(uint address, ByteArray& bs);
|
||||
virtual bool Read(uint address, Array& bs);
|
||||
// 写入
|
||||
virtual bool Write(uint address, const ByteArray& bs);
|
||||
virtual bool Write(uint address, const Array& bs);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -36,7 +36,7 @@ void TestFlash()
|
|||
|
||||
// 集成测试
|
||||
//flash.Erase(addr, 0x100);
|
||||
flash.Write(addr, ByteArray(buf, size));
|
||||
flash.Write(addr, Array(buf, size));
|
||||
|
||||
flash.Read(addr, bs);
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ void OnSend(void* param)
|
|||
Sys.ToHex(p, (byte*)&s, 4);
|
||||
|
||||
//nrf->SetMode(false);
|
||||
if(!nrf->Write(ByteArray(tx_buf, ArrayLength(tx_buf))))
|
||||
if(!nrf->Write(CArray(tx_buf)))
|
||||
{
|
||||
debug_printf ("Test Send Error 0x%02x\r\n", nrf->Status);
|
||||
nrf->ShowStatus();
|
||||
|
@ -33,7 +33,7 @@ void OnReceive(void* param)
|
|||
}
|
||||
}
|
||||
|
||||
uint OnReceive(ITransport* transport, ByteArray& bs, void* param, void* param2)
|
||||
uint OnReceive(ITransport* transport, Array& bs, void* param, void* param2)
|
||||
{
|
||||
bs.Show(true);
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "SerialPort.h"
|
||||
|
||||
uint OnUsartRead(ITransport* transport, ByteArray& bs, void* param, void* param2)
|
||||
uint OnUsartRead(ITransport* transport, Array& bs, void* param, void* param2)
|
||||
{
|
||||
debug_printf("收到:");
|
||||
bs.Show(true);
|
||||
|
@ -25,7 +25,7 @@ void TestSerial()
|
|||
sp1->Register(OnUsartRead);
|
||||
|
||||
char str[] = "http://www.NewLifeX.com \r\n";
|
||||
sp1->Write(ByteArray((byte*)str, ArrayLength(str)));
|
||||
sp1->Write(CArray(str));
|
||||
//Sys.Sleep(3000);
|
||||
|
||||
debug_printf("\r\nTestSerial Finish!\r\n");
|
||||
|
|
|
@ -65,7 +65,7 @@ void TinyIP::Init(ITransport* port)
|
|||
uint TinyIP::Fetch(Stream& ms)
|
||||
{
|
||||
// 获取缓冲区的包
|
||||
ByteArray bs(ms.Current(), ms.Remain());
|
||||
Array bs(ms.Current(), ms.Remain());
|
||||
int len = _port->Read(bs);
|
||||
// 如果缓冲器里面没有数据则转入下一次循环
|
||||
if(len < sizeof(ETH_HEADER)) return 0;
|
||||
|
@ -286,8 +286,7 @@ bool TinyIP::SendEthernet(ETH_TYPE type, const MacAddress& remote, const byte* b
|
|||
debug_printf("\r\n");*/
|
||||
/*ByteArray((byte*)eth->Next(), len).Show(true);*/
|
||||
|
||||
ByteArray bs((byte*)eth, len);
|
||||
return _port->Write(bs);
|
||||
return _port->Write(Array(eth, len));
|
||||
}
|
||||
|
||||
bool TinyIP::SendIP(IP_TYPE type, const IPAddress& remote, const byte* buf, uint len)
|
||||
|
|
|
@ -55,9 +55,9 @@ void TinyClient::Open()
|
|||
|
||||
Password.Load(Cfg->Password, ArrayLength(Cfg->Password));
|
||||
}
|
||||
|
||||
|
||||
if(Sys.Version > 1) Encryption = true;
|
||||
|
||||
|
||||
Control->Mode = 0; // 客户端只接收自己的消息
|
||||
Control->Open();
|
||||
|
||||
|
@ -169,9 +169,9 @@ void TinyClient::OnRead(const TinyMessage& msg)
|
|||
// 起始地址为7位压缩编码整数
|
||||
Stream ms = msg.ToStream();
|
||||
uint offset = ms.ReadEncodeInt();
|
||||
|
||||
|
||||
if(ReadCfg(offset,ms)) return;
|
||||
|
||||
|
||||
uint len = ms.ReadEncodeInt();
|
||||
|
||||
// 准备响应数据
|
||||
|
@ -204,16 +204,16 @@ void TinyClient::OnRead(const TinyMessage& msg)
|
|||
bool TinyClient::ReadCfg(uint offset, Stream ms)
|
||||
{
|
||||
if(offset < Cfg->StartSet) return false;
|
||||
|
||||
|
||||
//响应一条数据
|
||||
TinyMessage rs;
|
||||
rs.Code = 0x15;
|
||||
Stream ms2 = rs.ToStream();
|
||||
|
||||
ByteArray cfg(Cfg, Cfg->Length);
|
||||
|
||||
ByteArray cfg(Cfg, Cfg->Length);
|
||||
uint adrr=offset-Cfg->StartSet;
|
||||
uint len = ms.Remain();
|
||||
|
||||
|
||||
if((adrr+len)>Cfg->Length)
|
||||
{
|
||||
rs.Error = true;
|
||||
|
@ -244,8 +244,8 @@ void TinyClient::OnWrite(const TinyMessage& msg)
|
|||
// 起始地址为7位压缩编码整数
|
||||
Stream ms = msg.ToStream();
|
||||
uint offset = ms.ReadEncodeInt();
|
||||
|
||||
if(WriteCfg(offset,ms)) return;
|
||||
|
||||
if(WriteCfg(offset,ms)) return;
|
||||
// 准备响应数据
|
||||
TinyMessage rs;
|
||||
rs.Code = msg.Code;
|
||||
|
@ -260,14 +260,14 @@ void TinyClient::OnWrite(const TinyMessage& msg)
|
|||
ms2.Write((byte)2);
|
||||
ms2.WriteEncodeInt(offset);
|
||||
ms2.WriteEncodeInt(len);
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
ms2.WriteEncodeInt(offset);
|
||||
|
||||
if(len > remain) len = remain;
|
||||
ByteArray bs(ms.Current(), len);
|
||||
Array bs(ms.Current(), len);
|
||||
int count = Store.Write(offset, bs);
|
||||
ms2.WriteEncodeInt(count);
|
||||
}
|
||||
|
@ -279,13 +279,13 @@ void TinyClient::OnWrite(const TinyMessage& msg)
|
|||
bool TinyClient::WriteCfg(uint offset, Stream ms)
|
||||
{
|
||||
if(offset < Cfg->StartSet) return false;
|
||||
|
||||
|
||||
//响应一条数据
|
||||
TinyMessage rs;
|
||||
rs.Code = 0x16;
|
||||
Stream ms2 = rs.ToStream();
|
||||
|
||||
ByteArray cfg(Cfg, Cfg->Length);
|
||||
|
||||
ByteArray cfg(Cfg, Cfg->Length);
|
||||
uint adrr=offset-Cfg->StartSet;
|
||||
uint len = ms.Remain();
|
||||
if((adrr+len)>Cfg->Length)
|
||||
|
@ -294,27 +294,27 @@ bool TinyClient::WriteCfg(uint offset, Stream ms)
|
|||
ms2.Write((byte)2);
|
||||
ms2.WriteEncodeInt(offset);
|
||||
ms2.WriteEncodeInt(len);
|
||||
Reply(rs);
|
||||
Reply(rs);
|
||||
return true;//操作成功的意思
|
||||
}
|
||||
|
||||
ByteArray bs(ms.Current(), len);
|
||||
|
||||
Array bs(ms.Current(), len);
|
||||
bs.CopyTo(&cfg[adrr],len);
|
||||
|
||||
Cfg->Save();
|
||||
|
||||
|
||||
ms2.WriteEncodeInt(offset);
|
||||
ms2.WriteEncodeInt(len);
|
||||
rs.Length = ms2.Position();
|
||||
|
||||
Reply(rs);
|
||||
|
||||
|
||||
TinyClientReset();
|
||||
//Sys.Reset();
|
||||
|
||||
//修改配置区,重启系统
|
||||
|
||||
//修改配置区,重启系统
|
||||
//debug_printf("修改后的设备ID 0x%08X ,偏移量 %d\r\n", Cfg->Address,offset);
|
||||
//cfg.Show();
|
||||
//cfg.Show();
|
||||
return true;
|
||||
}
|
||||
void TinyClient::Report(Message& msg)
|
||||
|
@ -362,7 +362,7 @@ void TinyClient::ReportPing0x03(Message& msg)
|
|||
ms.Write((byte)Store.Data.Length()); // 长度
|
||||
ms.Write(Store.Data);
|
||||
msg.Length = ms.Position();
|
||||
|
||||
|
||||
}
|
||||
bool TinyClient::Report(uint offset, byte dat)
|
||||
{
|
||||
|
@ -377,7 +377,7 @@ bool TinyClient::Report(uint offset, byte dat)
|
|||
return Reply(msg);
|
||||
}
|
||||
|
||||
bool TinyClient::Report(uint offset, const ByteArray& bs)
|
||||
bool TinyClient::Report(uint offset, const Array& bs)
|
||||
{
|
||||
TinyMessage msg;
|
||||
msg.Code = 0x05;
|
||||
|
@ -425,7 +425,7 @@ void TinyClientReset()
|
|||
{
|
||||
//上报一条信息,让网关得一修改
|
||||
//Join();
|
||||
|
||||
|
||||
Sys.Reset();
|
||||
}
|
||||
|
||||
|
@ -438,7 +438,7 @@ void TinyClient::Join()
|
|||
|
||||
// 发送的广播消息,设备类型和系统ID
|
||||
JoinMessage dm;
|
||||
|
||||
|
||||
dm.Version = Sys.Version;
|
||||
dm.Kind = Type;
|
||||
dm.HardID = Sys.ID;
|
||||
|
@ -471,7 +471,7 @@ bool TinyClient::OnJoin(const TinyMessage& msg)
|
|||
|
||||
Cfg->SoftVer = dm.Version;
|
||||
if(Cfg->SoftVer < 2) Encryption=false;//小于2的版本加不加密
|
||||
|
||||
|
||||
Cfg->Address = dm.Address;
|
||||
Control->Address = dm.Address;
|
||||
Password = dm.Password;
|
||||
|
@ -528,16 +528,16 @@ void TinyClient::DisJoin()
|
|||
bool TinyClient::OnDisjoin(const TinyMessage& msg)
|
||||
{
|
||||
if(msg.Length < 2) return false;
|
||||
|
||||
Stream ms(msg.Data, msg.Length);
|
||||
|
||||
Stream ms(msg.Data, msg.Length);
|
||||
ushort crc=ms.ReadUInt16();
|
||||
|
||||
|
||||
if(crc!=HardCrc) return false;
|
||||
|
||||
Cfg->LoadDefault();
|
||||
Cfg->Save();
|
||||
debug_printf("设备退网3秒后重启\r\n");
|
||||
|
||||
|
||||
Sys.Sleep(3000);
|
||||
Sys.Reset();
|
||||
return true;
|
||||
|
@ -575,17 +575,17 @@ void TinyClient::Ping()
|
|||
{
|
||||
ReportPing0x01(msg);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
if(Store.Data.Length()<20)
|
||||
ReportPing0x02(msg);
|
||||
else
|
||||
ReportPing0x03(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
Report(msg);
|
||||
|
||||
Report(msg);
|
||||
|
||||
Send(msg);
|
||||
|
||||
if(LastActive == 0) LastActive = Sys.Ms();
|
||||
|
|
|
@ -47,7 +47,7 @@ public:
|
|||
|
||||
void Report(Message& msg);
|
||||
bool Report(uint offset, byte dat);
|
||||
bool Report(uint offset, const ByteArray& bs);
|
||||
bool Report(uint offset, const Array& bs);
|
||||
//特色心跳上报
|
||||
void ReportPing0x01(Message& msg);
|
||||
void ReportPing0x02(Message& msg);
|
||||
|
|
|
@ -26,7 +26,7 @@ void TinyConfig::Load()
|
|||
// 尝试加载配置区设置
|
||||
uint len = Length;
|
||||
if(!len) len = sizeof(this[0]);
|
||||
ByteArray bs(&Length, len);
|
||||
Array bs(&Length, len);
|
||||
if(!Config::Current->GetOrSet("TCFG", bs))
|
||||
debug_printf("TinyConfig::Load 首次运行,创建配置区!\r\n");
|
||||
else
|
||||
|
@ -48,7 +48,7 @@ void TinyConfig::Save()
|
|||
|
||||
debug_printf("TinyConfig::Save \r\n");
|
||||
|
||||
ByteArray bs(&Length, len);
|
||||
Array bs(&Length, len);
|
||||
Config::Current->Set("TCFG", bs);
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ void TinyConfig::Clear()
|
|||
|
||||
debug_printf("TinyConfig::Clear \r\n");
|
||||
|
||||
ByteArray bs(&Length, Length);
|
||||
Array bs(&Length, Length);
|
||||
Config::Current->Set("TCFG", bs);
|
||||
}
|
||||
|
||||
|
|
|
@ -163,8 +163,7 @@ void TinyMessage::Show() const
|
|||
{
|
||||
assert_ptr(Data);
|
||||
msg_printf(" Data[%d]=", Length);
|
||||
ByteArray bs(Data, Length);
|
||||
bs.Show();
|
||||
ByteArray(Data, Length).Show();
|
||||
}
|
||||
if(Checksum != Crc) msg_printf(" Crc Error 0x%04x [%04X]", Crc, __REV16(Crc));
|
||||
msg_printf("\r\n");
|
||||
|
@ -493,7 +492,7 @@ void TinyController::Loop()
|
|||
f->Retry++;
|
||||
|
||||
// 发送消息
|
||||
ByteArray bs(node.Data, node.Length);
|
||||
Array bs(node.Data, node.Length);
|
||||
Port->Write(bs);
|
||||
|
||||
// 增加发送次数统计
|
||||
|
|
|
@ -213,8 +213,7 @@ bool TinyServer::OnJoin(const TinyMessage& msg)
|
|||
dv->Show(true);
|
||||
|
||||
// 生成随机密码。当前时间的MD5
|
||||
ByteArray bs((byte*)&now, 8);
|
||||
dv->Pass = MD5::Hash(bs);
|
||||
dv->Pass = MD5::Hash(Array(&now, 8));
|
||||
dv->Pass.SetLength(8); // 小心不要超长
|
||||
|
||||
// 响应
|
||||
|
@ -264,8 +263,7 @@ bool TinyServer::ResetPassword(byte id)
|
|||
|
||||
|
||||
// 生成随机密码。当前时间的MD5
|
||||
ByteArray bs((byte*)&now, 8);
|
||||
dv->Pass = MD5::Hash(bs);
|
||||
dv->Pass = MD5::Hash(Array(&now, 8));
|
||||
dv->Pass.SetLength(8); // 小心不要超长
|
||||
|
||||
// 响应
|
||||
|
@ -567,7 +565,7 @@ Device* TinyServer::FindDevice(byte id)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
Device* TinyServer::FindDevice(const ByteArray& hardid)
|
||||
Device* TinyServer::FindDevice(const Array& hardid)
|
||||
{
|
||||
if(hardid.Length() == 0) return NULL;
|
||||
|
||||
|
@ -645,7 +643,7 @@ void TinyServer::SaveDevices()
|
|||
dv->Write(ms);
|
||||
}
|
||||
debug_printf("TinyServer::SaveDevices 保存 %d 个设备到 0x%08X!\r\n", count, addr);
|
||||
cfg.Set("Devs", ByteArray(ms.GetBuffer(), ms.Position()));
|
||||
cfg.Set("Devs", Array(ms.GetBuffer(), ms.Position()));
|
||||
}
|
||||
|
||||
void TinyServer::ClearDevices()
|
||||
|
@ -702,7 +700,7 @@ void TinyServer::SaveConfig()
|
|||
|
||||
debug_printf("TinyServer::SaveConfig 保存到 0x%08X!\r\n", addr);
|
||||
|
||||
cfg.Set("TCfg", ByteArray(ms.GetBuffer(), ms.Position()));
|
||||
cfg.Set("TCfg", Array(ms.GetBuffer(), ms.Position()));
|
||||
}
|
||||
|
||||
void TinyServer::ClearConfig()
|
||||
|
|
|
@ -38,7 +38,7 @@ public:
|
|||
|
||||
TArray<Device*> Devices;
|
||||
Device* FindDevice(byte id);
|
||||
Device* FindDevice(const ByteArray& hardid);
|
||||
Device* FindDevice(const Array& hardid);
|
||||
bool DeleteDevice(byte id);
|
||||
|
||||
int LoadDevices();
|
||||
|
|
|
@ -10,7 +10,7 @@ HelloMessage::HelloMessage() : Ciphers(1), Key(0)
|
|||
Version = Sys.Version;
|
||||
|
||||
ushort code = __REV16(Sys.Code);
|
||||
ByteArray bs((byte*)&code, 2);
|
||||
ByteArray bs(&code, 2);
|
||||
Type = bs.ToHex('\0');
|
||||
Name = Sys.Company;
|
||||
LocalTime = Time.Now().TotalMicroseconds();
|
||||
|
|
|
@ -340,7 +340,7 @@ void TokenClient::Ping()
|
|||
|
||||
ulong time = Sys.Ms();
|
||||
Stream ms = msg.ToStream();
|
||||
ms.WriteArray(ByteArray(&time, 8));
|
||||
ms.WriteArray(Array(&time, 8));
|
||||
msg.Length = ms.Position();
|
||||
|
||||
Send(msg);
|
||||
|
|
|
@ -23,7 +23,7 @@ bool TokenConfig::Load()
|
|||
// 尝试加载配置区设置
|
||||
uint len = Length;
|
||||
if(!len) len = sizeof(this[0]);
|
||||
ByteArray bs(&Length, len);
|
||||
Array bs(&Length, len);
|
||||
/*if(!Config::Current->GetOrSet("TKCF", bs))
|
||||
debug_printf("TokenConfig::Load 首次运行,创建配置区!\r\n");
|
||||
else
|
||||
|
@ -44,7 +44,7 @@ void TokenConfig::Save()
|
|||
|
||||
debug_printf("TokenConfig::Save \r\n");
|
||||
|
||||
ByteArray bs(&Length, len);
|
||||
Array bs(&Length, len);
|
||||
Config::Current->Set("TKCF", bs);
|
||||
}
|
||||
|
||||
|
|
|
@ -254,12 +254,12 @@ bool TokenController::Valid(const Message& msg)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Encrypt(Message& msg, const ByteArray& pass)
|
||||
bool Encrypt(Message& msg, const Array& pass)
|
||||
{
|
||||
// 加解密。握手不加密,握手响应不加密
|
||||
if(msg.Length > 0 && pass.Length() > 0 && !(msg.Code == 0x01 || msg.Code == 0x08))
|
||||
{
|
||||
ByteArray bs(msg.Data, msg.Length);
|
||||
Array bs(msg.Data, msg.Length);
|
||||
RC4::Encrypt(bs, pass);
|
||||
return true;
|
||||
}
|
||||
|
|
4
Type.cpp
4
Type.cpp
|
@ -278,7 +278,9 @@ byte& Array::operator[](int i) const
|
|||
assert_param2(_Arr && i >= 0 && i < _Length, "数组下标越界");
|
||||
|
||||
byte* buf = (byte*)_Arr;
|
||||
return buf[i * _Size];
|
||||
if(_Size > 1) i *= _Size;
|
||||
|
||||
return buf[i];
|
||||
}
|
||||
|
||||
// 检查容量。如果不足则扩大,并备份指定长度的数据
|
||||
|
|
Loading…
Reference in New Issue