Esempio n. 1
0
bool CProtocolComm::SendResponseFrame(DWORD dwRequestPacketID, Packet &packet)
{
    Packet packet_remain;
    if (WaitPopLast(0, packet_remain))
    {
        WARNING("sendResponseFrame queue get test");
        // 如果是之前请求包的重发,则立即返回结果,否则丢弃结果包
        if (packet_remain.GetPacketID() != dwRequestPacketID)
        {
            // 丢弃返回包
            WARNING("sendResponseFrame queue find diff id packet");
            // 重新放入队列,等待处理
            m_queue.Push(packet_remain);
            return false;
        }
    }

    return SendFrame(packet.GetSrcAddr(), packet.GetDestAddr(),
                     packet.GetType(), packet.GetFunction(),
                     packet.GetData(), packet.GetDataLen(), false);
}
Esempio n. 2
0
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;
    }
}
Esempio n. 3
0
bool CProtocolComm::SendFrame(Packet &packet)
{
    return SendFrame(packet.GetSrcAddr(), packet.GetDestAddr(),
                     packet.GetType(), packet.GetFunction(),
                     packet.GetData(), packet.GetDataLen());
}