Array => Buffer

This commit is contained in:
nnhy 2016-03-11 13:03:38 +00:00
parent 23fbc28860
commit bdfd8e6273
37 changed files with 102 additions and 153 deletions

View File

@ -40,7 +40,7 @@ ushort SendIndex;
ushort SendBufLen;
bool ErrorIRQ;
bool IR::Send(const Array& bs)
bool IR::Send(const Buffer& bs)
{
#ifdef STM32F0
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
@ -140,7 +140,7 @@ void IR::OnSend(void* sender, void* param)
#endif
}
int IR::Receive(Array& bs, int sTimeout)
int IR::Receive(Buffer& bs, int sTimeout)
{
TS("IR::Receive");
#ifdef STM32F0

View File

@ -31,8 +31,8 @@ public:
bool Open();
bool Close();
bool Send(const Array& bs);
int Receive(Array& bs, int sTimeout = 10);
bool Send(const Buffer& bs);
int Receive(Buffer& bs, int sTimeout = 10);
private:
static void OnSend(void* sender, void* param);

View File

@ -38,7 +38,7 @@ void IRcoding::SetCfgAddr(uint addr)
}
}
bool IRcoding::SaveCoding(byte index, const Array& bs)
bool IRcoding::SaveCoding(byte index, const Buffer& bs)
{
if(bs.Length() > CodingSize)return false;
if(!_Medium)return false;
@ -46,7 +46,7 @@ bool IRcoding::SaveCoding(byte index, const Array& bs)
return _Medium->Write(address, bs);
}
bool IRcoding::GetCoding(byte index, Array& bs)
bool IRcoding::GetCoding(byte index, Buffer& bs)
{
if(bs.Length() > CodingSize)return false;
if(!_Medium)return false;

View File

@ -34,8 +34,8 @@ public:
// 设置配置区所在位置
void SetCfgAddr(uint addr);
bool SaveCoding(byte index, const Array& bs);
bool GetCoding(byte index, Array& bs);
bool SaveCoding(byte index, const Buffer& bs);
bool GetCoding(byte index, Buffer& bs);
};

View File

@ -5,7 +5,7 @@ PMS5003::PMS5003()
Name = "PMS5003";
}
/*void PMS5003::OnReceive(const Array& bs, void* param)
/*void PMS5003::OnReceive(const Buffer& bs, void* param)
{
}*/

View File

@ -13,7 +13,7 @@ public:
PMS5003();
protected:
//virtual void OnReceive(const Array& bs, void* param);
//virtual void OnReceive(const Buffer& bs, void* param);
};
#endif

View File

@ -12,10 +12,10 @@ Message::Message(byte code)
}
// 设置数据。
void Message::SetData(const Array& bs, uint offset)
void Message::SetData(const Buffer& bs, uint offset)
{
Length = bs.Length() + offset;
if(Length > 0 && bs.GetBuffer() != Data + offset) bs.CopyTo(0, Data + offset, Length);
if(Length > 0) bs.CopyTo(0, Data + offset, Length);
}
void Message::SetError(byte errorCode, const char* msg)

View File

@ -36,7 +36,7 @@ public:
// 设置数据
//void SetData(const void* buf, uint len, uint offset = 0);
void SetData(const Array& bs, uint offset = 0);
void SetData(const Buffer& bs, uint offset = 0);
void SetError(byte errorCode, const char* msg = NULL);
// 负载数据转数据流

View File

@ -35,5 +35,5 @@ void MessageBase::WriteMessage(Message& msg) const
Write(ms);
//msg.Length = ms.Position();
msg.SetData(Array(ms.GetBuffer(), ms.Position()));
msg.SetData(Buffer(ms.GetBuffer(), ms.Position()));
}

View File

@ -63,7 +63,7 @@ const byte ATOK[] = {'A','T',':','O','K','\r','\n','\0'};
const int TPLNum[] = {-23,-6,0,4};
Blu40::Blu40()
{
Init();
@ -89,13 +89,13 @@ void Blu40::Init(SerialPort *port ,Pin rts,/*Pin cts,*/Pin sleep, OutputPort * r
if(rts != P0)_rts = new OutputPort(rts); // 低电平有效
if(sleep!=P0)_sleep = new OutputPort(sleep);
if(_rts==NULL)debug_printf("关键引脚_rts不可忽略");
if(_sleep)*_sleep=false;
*_rts = true;
/*if(cts != P0)_cts = new InputPort(cts);
_cts.Register();*/
if(!rst)_rst = rst;
Reset();
Reset();
}
Blu40::~Blu40()
@ -115,18 +115,19 @@ void Blu40::Reset()
*_rst = true;
}
int const BPreserve[] = {1200,2400,4800,9600,19200,38400,57600,115200}; // 不是简单*=2能搞定的
int const BPreserve[] = {1200,2400,4800,9600,19200,38400,57600,115200}; // 不是简单*=2能搞定的
bool Blu40::SetBP(int BP)
{
if(BP>115200)
{
debug_printf("Blu不支持如此高的波特率\r\n");
}
byte bpnumIndex;
for(bpnumIndex=0;BP!=BPreserve[bpnumIndex] && bpnumIndex<8;bpnumIndex++);
if(BPreserve[bpnumIndex] != BP)return false;
const Buffer bs((void*)AT_BPS, sizeof(AT_BPS));
//byte buf[40];
ByteArray ds;
//byte BPSOK[] = "AT:BPS SET AFTER 2S \r\n\0"; // 坑人的需要ASIIC
@ -138,16 +139,15 @@ bool Blu40::SetBP(int BP)
// 启用新波特率
_port->Close();
_port->Open();
*_rts = false;
Sys.Delay(150);
const Array bs(AT_BPS, sizeof(AT_BPS));
_port->Write(bs);
_port->Write(Array(&bpnumIndex, 1)); // 晕死AT指令里面放非字符
_port->Write(Buffer(&bpnumIndex, 1)); // 晕死AT指令里面放非字符
//_port->Write("\r\n",sizeof("\r\n")); // 无需回车
*_rts = true;
Sys.Delay(500);
_port->Read(ds);
@ -174,17 +174,14 @@ bool Blu40::SetBP(int BP)
// 启用新波特率
_port->Close();
_port->Open();
*_rts = false;
Sys.Delay(170);
//_port->Write(AT_BPS,sizeof(AT_BPS));
//_port->Write(&bpnumIndex,1); // 晕死AT指令里面放非字符
const Array bs(AT_BPS, sizeof(AT_BPS));
_port->Write(bs);
_port->Write(Array(&bpnumIndex, 1));
_port->Write(Buffer(&bpnumIndex, 1));
//_port->Write("\r\n",sizeof("\r\n")); // 无需回车
*_rts = true;
Sys.Delay(500);
_port->Read(ds);
//"AT:BPS SET AFTER 2S \r\n\0"
@ -194,7 +191,7 @@ bool Blu40::SetBP(int BP)
if(ds[j] != BPSOK[j])
{
if(i==7)
{
{
debug_printf("设置失败,请检查现在使用的波特率是否正确\r\n");
_baudRate = 0;
return false;
@ -206,7 +203,7 @@ bool Blu40::SetBP(int BP)
}
}
_baudRate = portBaudRateTemp;
}
}
debug_printf("设置成功2S后启用新波特率\r\n");
return true;
}
@ -232,8 +229,8 @@ bool Blu40::SetName(const char* name)
{
*_rts = false;
Sys.Delay(170);
_port->Write(Array(AT_REN, sizeof(AT_REN)));
_port->Write(Array(name, 0));
_port->Write(Buffer((void*)AT_REN, sizeof(AT_REN)));
_port->Write(String(name));
bool ret = CheckSet();
*_rts = true;
return ret;
@ -243,8 +240,8 @@ bool Blu40::SetPID(ushort pid)
{
*_rts = false;
Sys.Delay(170);
_port->Write(Array(AT_PID, sizeof(AT_PID)));
_port->Write(Array((byte*)pid, 2));
_port->Write(Buffer((void*)AT_PID, sizeof(AT_PID)));
_port->Write(Buffer((byte*)pid, 2));
bool ret = CheckSet();
*_rts = true;
return ret;
@ -260,9 +257,9 @@ bool Blu40::SetTPL(int TPLDB)
}
*_rts = false;
Sys.Delay(170);
_port->Write(Array(AT_TPL, sizeof(AT_TPL)));
_port->Write(Buffer((void*)AT_TPL, sizeof(AT_TPL)));
//byte temp = TPLNumIndex+'0';// 又是坑人的 非字符
_port->Write(Array(&TPLNumIndex,1));
_port->Write(Buffer(&TPLNumIndex, 1));
bool ret = CheckSet();
*_rts = true;
return ret;

View File

@ -2,7 +2,7 @@
#define KeyLength 256
void GetKey(ByteArray& box, const Array& pass)
void GetKey(ByteArray& box, const Buffer& pass)
{
for (int i = 0; i < box.Length(); i++)
{
@ -18,7 +18,7 @@ void GetKey(ByteArray& box, const Array& pass)
}
}
void RC4::Encrypt(Array& data, const Array& pass)
void RC4::Encrypt(Buffer& data, const Buffer& pass)
{
int i = 0;
int j = 0;
@ -40,7 +40,7 @@ void RC4::Encrypt(Array& data, const Array& pass)
}
}
ByteArray RC4::Encrypt(const Array& data, const Array& pass)
ByteArray RC4::Encrypt(const Buffer& data, const Buffer& pass)
{
ByteArray rs;
//rs.SetLength(data.Length());

View File

@ -8,8 +8,8 @@ class RC4
{
public:
// 加解密
static void Encrypt(Array& data, const Array& pass);
static ByteArray Encrypt(const Array& data, const Array& pass);
static void Encrypt(Buffer& data, const Buffer& pass);
static ByteArray Encrypt(const Buffer& data, const Buffer& pass);
};
#endif

View File

@ -85,7 +85,7 @@ void rc6_block_decrypt(uint *ct, uint *pt, uint* box)
pt[3] = D;
}
void GetKey(uint* box, const Array& pass)
void GetKey(uint* box, const Buffer& pass)
{
uint L[(32 + bytes - 1) / bytes]; /* Big enough for max b */
uint A, B;
@ -114,7 +114,7 @@ void GetKey(uint* box, const Array& pass)
}
}
ByteArray RC6::Encrypt(const Array& data, const Array& pass)
ByteArray RC6::Encrypt(const Buffer& data, const Buffer& pass)
{
uint box[KeyLength];
GetKey(box, pass);
@ -128,7 +128,7 @@ ByteArray RC6::Encrypt(const Array& data, const Array& pass)
return rs;
}
ByteArray RC6::Decrypt(const Array& data, const Array& pass)
ByteArray RC6::Decrypt(const Buffer& data, const Buffer& pass)
{
uint box[KeyLength];
GetKey(box, pass);

View File

@ -8,8 +8,8 @@ class RC6
{
public:
// 加解密
static ByteArray Encrypt(const Array& data, const Array& pass);
static ByteArray Decrypt(const Array& data, const Array& pass);
static ByteArray Encrypt(const Buffer& data, const Buffer& pass);
static ByteArray Decrypt(const Buffer& data, const Buffer& pass);
};
#endif

View File

@ -1168,7 +1168,7 @@ static void rsa_mul(uint32_t *des, uint8_t *des_len, uint32_t *sour, uint8_t *so
}
}
ByteArray RSA::Encrypt(const Array& data, const Array& pass)
ByteArray RSA::Encrypt(const Buffer& data, const Buffer& pass)
{
/*byte buf[KeyLength];
ByteArray box(buf, KeyLength);
@ -1195,7 +1195,7 @@ ByteArray RSA::Encrypt(const Array& data, const Array& pass)
return rs;
}
ByteArray RSA::Decrypt(const Array& data, const Array& pass)
ByteArray RSA::Decrypt(const Buffer& data, const Buffer& pass)
{
/*byte buf[KeyLength];
ByteArray box(buf, KeyLength);

View File

@ -8,8 +8,8 @@ class RSA
{
public:
// 加解密
static ByteArray Encrypt(const Array& data, const Array& pass);
static ByteArray Decrypt(const Array& data, const Array& pass);
static ByteArray Encrypt(const Buffer& data, const Buffer& pass);
static ByteArray Decrypt(const Buffer& data, const Buffer& pass);
};
#endif

View File

@ -39,7 +39,7 @@ void Init()
}
// 硬件实现的Crc
uint HardCrc(const Array& bs, uint crc)
uint HardCrc(const Buffer& bs, uint crc)
{
if (!inited) Init();
@ -76,8 +76,8 @@ void TestCrc()
uint temp = crc;
// 试试二次计算Crc
crc = Crc::Hash(Array(&crc, 4), 0);
crc2 = Crc::Hash(Array(&crc2, 4));
crc = Crc::Hash(Buffer(&crc, 4), 0);
crc2 = Crc::Hash(Buffer(&crc2, 4));
ByteArray(&temp, 4).Show();
debug_printf("\r\n\t");
debug_printf("SoftCrc:0x%08x HardCrc:0x%08x \r\n", crc, crc2);
@ -139,9 +139,9 @@ void TestCrc()
ByteArray bs7(DataBuffer, size*4);
crc = Crc::Hash(bs7, 0);
temp = crc;
crc = Crc::Hash(Array(&crc, 4), crc);
crc = Crc::Hash(Buffer(&crc, 4), crc);
//crc2 = HardCrc(bs7, 0);
//crc2 = HardCrc(Array(&crc2, 4), crc2);
//crc2 = HardCrc(Buffer(&crc2, 4), crc2);
bs7.Show();
debug_printf(" <= 0x%08x\r\n\t", temp);
debug_printf("SoftCrc:0x%08x HardCrc:0x%08x \r\n", crc, crc2);
@ -149,9 +149,9 @@ void TestCrc()
// 测试Crc16数据和crc部分一起计算crc16结果为0
debug_printf("\r\n");
byte data16[] = { 0x01, 0x08, 0x00, 0x00};
ushort crc16 = Crc::Hash16(Array(data16, 4));
ushort crc16 = Crc::Hash16(Buffer(data16, 4));
debug_printf("Crc::Hash16(#%08x) = 0x%04x\r\n", _REV(*(uint*)data16), crc16);
ushort crc17 = Crc::Hash16(Array(&crc16, 2), crc16);
ushort crc17 = Crc::Hash16(Buffer(&crc16, 2), crc16);
debug_printf("Crc::Hash16(#%08x, 0x%04x) = 0x%04x\r\n", _REV(*(uint*)data16), crc16, crc17);
debug_printf("\r\n");

View File

@ -36,7 +36,7 @@ void TestFlash()
// 集成测试
//flash.Erase(addr, 0x100);
flash.Write(addr, Array(buf, size));
flash.Write(addr, Buffer(buf, size));
flash.Read(addr, bs);

View File

@ -37,7 +37,7 @@ void OnReceive(void* param)
}
}
uint OnReceive(ITransport* transport, Array& bs, void* param, void* param2)
uint OnReceive(ITransport* transport, Buffer& bs, void* param, void* param2)
{
bs.Show(true);

View File

@ -8,9 +8,9 @@
#define NET_DEBUG DEBUG
TinyIP::TinyIP() : Buffer(0) { Init(); }
TinyIP::TinyIP() : _Arr(0) { Init(); }
TinyIP::TinyIP(ITransport* port) : Buffer(0)
TinyIP::TinyIP(ITransport* port) : _Arr(0)
{
Init();
Init(port);
@ -31,7 +31,7 @@ void TinyIP::Init()
_StartTime = 0;
// 以太网缓冲区先初始化为0然后再调整大小
Buffer.SetLength(1500);
_Arr.SetLength(1500);
Mask = 0x00FFFFFF;
DHCPServer = Gateway = DNSServer = IP = 0;
@ -68,7 +68,7 @@ void TinyIP::Init(ITransport* port)
uint TinyIP::Fetch(Stream& ms)
{
// 获取缓冲区的包
Array bs(ms.Current(), ms.Remain());
Buffer bs(ms.Current(), ms.Remain());
int len = _port->Read(bs);
// 如果缓冲器里面没有数据则转入下一次循环
if(len < sizeof(ETH_HEADER)) return 0;
@ -207,7 +207,7 @@ void TinyIP::Work(void* param)
if(tip)
{
// 注意此时指针位于0而内容长度为缓冲区长度
Stream ms(tip->Buffer);
Stream ms(tip->_Arr);
uint len = tip->Fetch(ms);
if(len)
{
@ -270,10 +270,10 @@ void TinyIP::ShowInfo()
bool TinyIP::SendEthernet(ETH_TYPE type, const MacAddress& remote, const byte* buf, uint len)
{
ETH_HEADER* eth = (ETH_HEADER*)(buf - sizeof(ETH_HEADER));
auto eth = (ETH_HEADER*)(buf - sizeof(ETH_HEADER));
assert_param2(IS_ETH_TYPE(type), "这个不是以太网类型");
eth->Type = type;
eth->Type = type;
eth->DestMac = remote;
eth->SrcMac = Mac;
@ -294,7 +294,7 @@ bool TinyIP::SendEthernet(ETH_TYPE type, const MacAddress& remote, const byte* b
debug_printf("\r\n");*/
/*ByteArray((byte*)eth->Next(), len).Show(true);*/
return _port->Write(Array(eth, len));
return _port->Write(Buffer(eth, len));
}
bool TinyIP::SendIP(IP_TYPE type, const IPAddress& remote, const byte* buf, uint len)

View File

@ -41,7 +41,7 @@ class TinyIP : public ISocketHost
private:
ITransport* _port;
UInt64 _StartTime;
ByteArray Buffer; // 缓冲区
ByteArray _Arr; // 缓冲区
// 循环调度的任务,捕获数据包,返回长度
uint Fetch(Stream& ms);

View File

@ -43,7 +43,7 @@ void Device::Write(Stream& ms) const
{
TS("Device::Write");
Array bs(&Address, offsetof(Device, Cfg) - offsetof(Device, Address));
Buffer bs((void*)&Address, offsetof(Device, Cfg) - offsetof(Device, Address));
ms.WriteArray(bs);
}
@ -52,7 +52,7 @@ void Device::Read(Stream& ms)
TS("Device::Read");
// 为了避免不同版本的配置兼容,指定长度避免覆盖过头
Array bs(&Address, offsetof(Device, Cfg) - offsetof(Device, Address));
Buffer bs(&Address, offsetof(Device, Cfg) - offsetof(Device, Address));
//bs = ms.ReadArray();
// 为了减少一个临时对象,直接传入外部包装给内部拷贝
uint len = ms.ReadEncodeInt();
@ -168,21 +168,3 @@ bool operator!=(const Device& d1, const Device& d2)
{
return d1.Address != d2.Address;
}
/*Array Device::GetHardID() { return Array(HardID, ArrayLength(HardID)); }
Array Device::GetName() { return Array(Name, ArrayLength(Name)); }
Array Device::GetPass() { return Array(Pass, ArrayLength(Pass)); }
Array Device::GetStore() { return Array(Store, ArrayLength(Store)); }
Array Device::GetConfig() { return Array(Cfg, sizeof(Cfg[0])); }
const Array Device::GetHardID() const { return Array(HardID, ArrayLength(HardID)); }
const Array Device::GetName() const { return Array(Name, ArrayLength(Name)); }
const Array Device::GetPass() const { return Array(Pass, ArrayLength(Pass)); }
const Array Device::GetStore() const { return Array(Store, ArrayLength(Store)); }
const Array Device::GetConfig() const { return Array(Cfg, sizeof(Cfg[0])); }
void Device::SetHardID(const Array& arr) { arr.CopyTo(HardID, ArrayLength(HardID)); }
void Device::SetName(const Array& arr) { arr.CopyTo(Name, ArrayLength(Name)); }
void Device::SetPass(const Array& arr) { arr.CopyTo(Pass, ArrayLength(Pass)); }
void Device::SetStore(const Array& arr) { arr.CopyTo(Store, ArrayLength(Store)); }
void Device::SetConfig(const Array& arr) { arr.CopyTo(Cfg, sizeof(Cfg[0])); }*/

View File

@ -65,24 +65,6 @@ public:
bool CanSleep() const { return SleepTime > 0; }
bool Valid() const;
/*Array GetHardID();
Array GetName();
Array GetPass();
Array GetStore();
Array GetConfig();
const Array GetHardID() const;
const Array GetName() const;
const Array GetPass() const;
const Array GetStore() const;
const Array GetConfig() const;
void SetHardID(const Array& arr);
void SetName(const Array& arr);
void SetPass(const Array& arr);
void SetStore(const Array& arr);
void SetConfig(const Array& arr);*/
#if DEBUG
virtual String& ToStr(String& str) const;
#endif

View File

@ -22,10 +22,6 @@ public:
void ReadData(Stream& ms, Buffer& bs) const;
void WriteData(Stream& ms, byte code, const Buffer& bs) const;
// 0x02 配置数据
/*void ReadConfig(Stream& ms, Array& bs);
void WriteConfig(Stream& ms, const Array& bs);*/
// 0x03 硬件校验
bool ReadHardCrc(Stream& ms, const Device& dv, ushort& crc) const;
void WriteHardCrc(Stream& ms, ushort crc) const;

View File

@ -11,7 +11,7 @@ TinyClient* TinyClient::Current = NULL;
static void TinyClientTask(void* param);
//static void TinyClientReset();
static void GetDeviceKey(byte id, Array& key, void* param);
static void GetDeviceKey(byte id, Buffer& key, void* param);
/******************************** 初始化和开关 ********************************/
@ -57,7 +57,7 @@ void TinyClient::Open()
Password.Load(Cfg->Password, ArrayLength(Cfg->Password));
}
HardCrc = Crc::Hash16(Array(Sys.ID, 16));
HardCrc = Crc::Hash16(Buffer(Sys.ID, 16));
if(Sys.Version > 1) Encryption = true;
Control->Mode = 0; // 客户端只接收自己的消息
@ -169,7 +169,7 @@ void TinyClient::OnRead(const TinyMessage& msg)
else if(dm.Offset < 128)
{
dm.Offset -= 64;
Array bs(Cfg, Cfg->Length);
Buffer bs(Cfg, Cfg->Length);
rt = dm.ReadData(bs);
}
@ -202,7 +202,7 @@ void TinyClient::OnWrite(const TinyMessage& msg)
else if(dm.Offset < 128)
{
dm.Offset -= 64;
Array bs(Cfg, Cfg->Length);
Buffer bs(Cfg, Cfg->Length);
rt = dm.WriteData(bs, true);
Cfg->Save();
@ -237,7 +237,7 @@ bool TinyClient::Report(uint offset, byte dat)
return Send(msg);
}
bool TinyClient::Report(uint offset, const Array& bs)
bool TinyClient::Report(uint offset, const Buffer& bs)
{
TinyMessage msg;
msg.Code = 0x06;
@ -293,7 +293,7 @@ void TinyClientTask(void* param)
if(client->Server != 0) client->Ping();
}
void GetDeviceKey(byte id, Array& key, void* param)
void GetDeviceKey(byte id, Buffer& key, void* param)
{
/*TS("TinyClient::GetDeviceKey");
//debug_printf("微网客户端获取密钥");
@ -487,7 +487,7 @@ void TinyClient::Ping()
pm.WriteData(ms, 0x01, Store.Data);
pm.WriteHardCrc(ms, HardCrc);
pm.WriteData(ms, 0x02, Array(Cfg, sizeof(Cfg[0])));
pm.WriteData(ms, 0x02, Buffer(Cfg, sizeof(Cfg[0])));
msg.Length = ms.Position();

View File

@ -46,7 +46,7 @@ public:
DataStore Store; // 数据存储区
bool Report(uint offset, byte dat);
bool Report(uint offset, const Array& bs);
bool Report(uint offset, const Buffer& bs);
uint NextReport; // 下次上报偏移0不动
uint NextReportLength; // 下次上报数据长度

View File

@ -78,7 +78,7 @@ bool TinyMessage::Read(Stream& ms)
//flag->TTL = 0;
flag->Retry = 0;
// 连续的可以直接计算Crc16
Crc = Crc::Hash16(Array(p, HeaderSize + Length));
Crc = Crc::Hash16(Buffer(p, HeaderSize + Length));
// 还原数据
p[3] = fs;
@ -113,7 +113,7 @@ void TinyMessage::Write(Stream& ms) const
//flag->TTL = 0;
flag->Retry = 0;
p->Checksum = p->Crc = Crc::Hash16(Array(buf, HeaderSize + len));
p->Checksum = p->Crc = Crc::Hash16(Buffer(buf, HeaderSize + len));
// 还原数据
buf[3] = fs;
@ -371,12 +371,12 @@ void TinyController::ShowMessage(const TinyMessage& msg, bool send, const ITrans
}
//加密。组网不加密,退网不加密
static bool Encrypt(Message& msg, Array& pass)
static bool Encrypt(Message& msg, Buffer& pass)
{
// 加解密。组网不加密,退网不加密
if(msg.Length > 0 && pass.Length() > 0 && !(msg.Code == 0x01 || msg.Code == 0x02))
{
Array bs(msg.Data, msg.Length);
Buffer bs(msg.Data, msg.Length);
RC4::Encrypt(bs, pass);
return true;
}
@ -739,7 +739,7 @@ void TinyController::Loop()
node.Times++;
// 发送消息
Array bs(node.Data, node.Length);
Buffer bs(node.Data, node.Length);
if(node.Length > 32)
{
debug_printf("node=0x%08x Length=%d Seq=0x%02X Times=%d Next=%d EndTime=%d\r\n", &node, node.Length, node.Seq, node.Times, (uint)node.Next, (uint)node.EndTime);

View File

@ -158,7 +158,7 @@ public:
void Loop();
// 获取密钥的回调
void (*GetKey)(byte id, Array& key, void* param);
void (*GetKey)(byte id, Buffer& key, void* param);
public:
// 统计。平均值=(LastCost + TotalCost)/(LastSend + TotalSend)。每一组完成以后TotalXXX整体复制给LastXXX

View File

@ -14,7 +14,7 @@
/******************************** TinyServer ********************************/
static bool OnServerReceived(void* sender, Message& msg, void* param);
static void GetDeviceKey(byte scr, Array& key,void* param);
static void GetDeviceKey(byte scr, Buffer& key,void* param);
#if DEBUG
// 输出所有设备
@ -216,7 +216,7 @@ bool TinyServer::Dispatch(TinyMessage& msg)
msg.Src = dv->Address;
msg.Reply = true;
msg.Error = rs.Error;
msg.SetData(Array(rs.Data, rs.Length));
msg.SetData(Buffer(rs.Data, rs.Length));
}
Current = NULL;
@ -591,7 +591,7 @@ Device* TinyServer::FindDevice(byte id) const
return NULL;
}
void GetDeviceKey(byte scr,Array& key,void* param)
void GetDeviceKey(byte scr, Buffer& key, void* param)
{
/*TS("TinyServer::GetDeviceKey");
@ -738,7 +738,7 @@ void TinyServer::SaveDevices() const
dv->Write(ms);
}
debug_printf("TinyServer::SaveDevices 保存 %d 个设备到 0x%08X\r\n", num, cfg.Address);
cfg.Set("Devs", Array(ms.GetBuffer(), ms.Position()));
cfg.Set("Devs", Buffer(ms.GetBuffer(), ms.Position()));
}
void TinyServer::ClearDevices()

View File

@ -31,7 +31,7 @@ void DeviceMessage::Write(Stream& ms) const
UInt64 now = Sys.Ms();
//Salt.Set((byte*)&now, 8);
//ms.WriteArray(Salt);
ms.WriteArray(Array(&now, 8));
ms.WriteArray(Buffer(&now, 8));
ms.Write(Local.Address.ToArray());
ms.Write((ushort)Local.Port);

View File

@ -60,8 +60,6 @@ void Gateway::Start()
dv->Kind = Sys.Code;
dv->LastTime = Sys.Seconds();
//dv->SetHardID(Array(Sys.ID, 16));
//dv->SetName(Array(Sys.Name, 0));
dv->HardID = Sys.ID;
dv->Name = Sys.Name;

View File

@ -38,7 +38,7 @@ void LoginMessage::Write(Stream& ms) const
else
{
UInt64 now = Sys.Ms();
ms.WriteArray(MD5::Hash(Array(&now, 8)));
ms.WriteArray(MD5::Hash(Buffer(&now, 8)));
}
}
else if(!Error)

View File

@ -33,7 +33,7 @@ void RegisterMessage::Write(Stream& ms) const
else
{
UInt64 now = Sys.Ms();
ms.WriteArray(MD5::Hash(Array(&now, 8)));
ms.WriteArray(MD5::Hash(Buffer(&now, 8)));
}
}
}

View File

@ -367,17 +367,7 @@ void TokenClient::Login()
auto cfg = TokenConfig::Current;
login.User = cfg->User;
//login.Key = cfg->Key;
//login.Pass = MD5::Hash(Array(cfg->Pass, ArrayLength(cfg->Pass))).ToHex(0, 0);
//login.Pass = MD5::Hash(String(cfg->Pass, ArrayLength(cfg->Pass)));
login.Pass = MD5::Hash(cfg->Pass);
/*// 临时代码,兼容旧云端
if(login.User.Length() < 4)
{
//Register();
login.User.Copy(Sys.ID, 16);
login.Pass.Copy(Sys.ID, 16);
}*/
TokenMessage msg(2);
login.WriteMessage(msg);
login.Show(true);
@ -466,7 +456,7 @@ void TokenClient::Ping()
UInt64 time = Sys.Ms();
Stream ms = msg.ToStream();
ms.WriteArray(Array(&time, 8));
ms.WriteArray(Buffer(&time, 8));
msg.Length = ms.Position();
Send(msg);

View File

@ -189,7 +189,7 @@ void TokenController::Close()
}
// 发送消息,传输口参数为空时向所有传输口发送消息
bool TokenController::Send(byte code, const Array& arr)
bool TokenController::Send(byte code, const Buffer& arr)
{
TokenMessage msg;
msg.Code = code;
@ -236,12 +236,12 @@ bool TokenController::Valid(const Message& msg)
return true;
}
static bool Encrypt(Message& msg, const Array& pass)
static bool Encrypt(Message& msg, const Buffer& pass)
{
// 加解密。握手不加密,握手响应不加密
if(msg.Length > 0 && pass.Length() > 0 && !(msg.Code == 0x01 || msg.Code == 0x08))
{
Array bs(msg.Data, msg.Length);
Buffer bs(msg.Data, msg.Length);
RC4::Encrypt(bs, pass);
return true;
}
@ -274,7 +274,7 @@ bool TokenController::OnReceive(Message& msg)
// 如果有等待响应,则交给它
if(msg.Reply && _Response && (msg.Code == _Response->Code || msg.Code == 0x08 && msg.Data[0] == _Response->Code))
{
_Response->SetData(Array(msg.Data, msg.Length));
_Response->SetData(Buffer(msg.Data, msg.Length));
_Response->Reply = true;
// 加解密。握手不加密,登录响应不加密

View File

@ -75,7 +75,7 @@ public:
// 发送消息,传输口参数为空时向所有传输口发送消息
virtual bool Send(Message& msg);
// 发送消息,传输口参数为空时向所有传输口发送消息
virtual bool Send(byte code, const Array& arr);
virtual bool Send(byte code, const Buffer& arr);
// 响应消息
private:

View File

@ -194,7 +194,11 @@ int Buffer::CopyTo(int srcIndex, void* data, int len) const
if(len < 0 || len > remain) len = remain;
// 拷贝数据
if(len) memcpy(data, (byte*)_Arr + srcIndex, len);
if(len)
{
if(data != (byte*)_Arr + srcIndex)
memcpy(data, (byte*)_Arr + srcIndex, len);
}
return len;
}