You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.1 KiB
C++

#include "data/DateTimeData.h"
#include "SetTimeRequestFrame.h"
#include "Utils.h"
SetTimeRequestFrame::SetTimeRequestFrame()
{
setCmd(FRAME_CMD_SET_TIME); // 时间请求固定命令字
setLen(6); // 设置时间请求的数据区固定长度6字节
}
SetTimeRequestFrame::~SetTimeRequestFrame()
{
}
// 从Byte字符串解析
bool SetTimeRequestFrame::fromByteStr(std::string str)
{
if(str.length() < 9)
{
return false;
}
if(!((unsigned char)str.at(0) == 0x5A && (unsigned char)str.at(1) == 0xA5))
{
return false;
}
int len = Utils::charToShort(str.at(5), str.at(6));
if(str.length() != (size_t)(7 + len + 2))
{
return false;
}
setHead(FRAME_HEAD);
setAddr(Utils::charToShort(str.at(2), str.at(3)));
setCmd(str.at(4));
setLen(len);
if(getLen() > 0 && getLen() < MAX_DATA_LEN) // 最大限制10K
{
getData()->fromByteStr(str.substr(7, getLen()));
}
setCrc(Utils::charToShort(str.at(getLen()) - 2, str.at(getLen()) - 1));
return true;
}