Example #1
0
bool AutoCal::Response::match_nodeReceived(const WirelessPacket& packet)
{
    WirelessPacket::Payload payload = packet.payload();

    //check the main bytes of the packet
    if(packet.deliveryStopFlags().toByte() != 0x07 ||	//delivery stop flag
            packet.type() != 0x20 ||							//app data type
            packet.nodeAddress() != m_nodeAddress ||			//node address
            payload.size() != 0x07							//payload length
      )
    {
        //failed to match some of the bytes
        return false;
    }

    //Command ID
    if(payload.read_uint16(0) != 0x0064)
    {
        return false;
    }

    //if the status flag is success (0)
    if(payload.read_uint8(2) == 0)
    {
        m_calStarted = true;

        //only want to read the time until completion if the cal has started
        m_timeUntilCompletion = payload.read_float(3);
    }

    return true;
}
Example #2
0
    bool AutoBalance_v2::Response::match(const WirelessPacket& packet)
    {
        WirelessPacket::Payload payload = packet.payload();

        //check the main bytes of the packet
        if(packet.deliveryStopFlags().toInvertedByte() != 0x07 ||               //delivery stop flag
           packet.type() != WirelessPacket::packetType_nodeSuccessReply ||      //app data type
           packet.nodeAddress() != m_nodeAddress ||                             //node address
           payload.size() != 0x10 ||                                            //payload length
           payload.read_uint16(0) != WirelessProtocol::cmdId_autoBalance_v2 ||  //command id
           payload.read_uint8(2) != m_channelNumber ||                          //channel number (echo)
           payload.read_float(3) != m_targetPercent                             //target percent (echo)
           )
        {
            //failed to match some of the bytes
            return false;
        }

        //if we made it here, the packet matches the response pattern

        //error code
        m_result.m_errorCode = static_cast<WirelessTypes::AutoBalanceErrorFlag>(payload.read_uint8(7));

        //sampled value
        m_result.m_percentAchieved = payload.read_float(8);

        //hardware offset
        m_result.m_hardwareOffset = static_cast<uint16>(payload.read_uint32(12));

        switch(m_result.m_errorCode)
        {
            case WirelessTypes::autobalance_success:
            case WirelessTypes::autobalance_maybeInvalid:
                m_success = true;

            default:
                m_success = false;
        }

        //we have fully matched the response
        m_fullyMatched = true;

        //notify that the response was matched
        m_matchCondition.notify();

        return true;
    }