本文整理汇总了C++中Packet::GetPacketLen方法的典型用法代码示例。如果您正苦于以下问题:C++ Packet::GetPacketLen方法的具体用法?C++ Packet::GetPacketLen怎么用?C++ Packet::GetPacketLen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Packet
的用法示例。
在下文中一共展示了Packet::GetPacketLen方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetPacket
bool PacketBuffer::GetPacket(Packet &packet)
{
// check packet
if (PacketVaild())
{
Packet *pPacket = (Packet *)raw();
//INFO("Has a Packet");
// block unnecessary packet
if (PreProcess())
{
// delete a packet
del(pPacket->GetPacketLen());
return false;
}
else
{
// copy packet
//packet = *pPacket; // this may dangerous
::memcpy(&packet, pPacket, pPacket->GetPacketLen());
del(pPacket->GetPacketLen());
return true;
}
}
return false;
}
示例2: PacketVaild
bool PacketBuffer::PacketVaild()
{
if (size() > 0)
{
//DEBUG("recv: %d", size());
//DEBUG_HEX(raw(), size());
Packet *pPacket = (Packet *)raw();
// check length
if (size() >= Packet::PACKET_MINLEN &&
size() >= pPacket->GetPacketLen())
{
// check checksum and packet end
WORD wCRC = __le16_to_cpu(*(WORD *)&(pPacket->GetData()[pPacket->GetDataLen()]));
WORD wCalCRC = pPacket->CheckSUM(&pPacket->m_btAddr, pPacket->GetPacketLen()-2);
if (wCRC == wCalCRC)
{
DEBUG("recv: %d", size());
DEBUG_HEX(raw(), size());
return true;
}
ERROR("serialport packet checksum wrong calc:%04x recv:%04X", wCalCRC, wCRC);
DEBUG_HEX(raw(), size());
}
else
{
return false;
}
// throw exception
throw(Packet::EXCEPTION_PACKET);
}
else
{
return false;
}
}