bool BaseStation_ReadEeprom_v2::Response::matchFailResponse(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_baseErrorReply || //app data type packet.nodeAddress() != WirelessProtocol::BASE_STATION_ADDRESS || //node address payload.size() != 0x05 || //payload length payload.read_uint16(0) != WirelessProtocol::cmdId_base_readEeprom_v2 || //command ID payload.read_uint16(2) != m_eepromAddress //eeprom address ) { //failed to match some of the bytes return false; } //read the error code from the response m_errorCode = static_cast<WirelessPacket::ResponseErrorCode>(payload.read_uint8(4)); //set the result to failure m_success = false; return true; }
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; }
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; }
bool AutoCal::Response::match_shmLink(const WirelessPacket& packet) { WirelessPacket::Payload payload = packet.payload(); std::size_t payloadLen = payload.size(); //check the main bytes of the packet if(packet.deliveryStopFlags().toByte() != 0x07 || //delivery stop flag packet.type() != WirelessPacket::packetType_reply || //app data type packet.nodeAddress() != m_nodeAddress || //node address payloadLen != 22 //payload length ) { //failed to match some of the bytes return false; } //Command ID if(payload.read_uint16(0) != 0x0064) { return false; } //Pass/Fail Flag m_completionFlag = static_cast<WirelessTypes::AutoCalCompletionFlag>(payload.read_uint8(2)); //Info Bytes for(std::size_t i = 3; i < payloadLen; ++i) { //add all of the payload info bytes to m_infoBytes m_infoBytes.push_back(payload.read_uint8(i)); } //setting success to true if it got this packet, even if the cals applied might be bad m_success = true; return true; }
bool AsyncDigitalAnalogPacket::integrityCheck(const WirelessPacket& packet) { WirelessPacket::Payload payload = packet.payload(); //verify the payload size if(payload.size() < PAYLOAD_OFFSET_CHANNEL_DATA) { //payload is too small to be valid return false; } //verify the delivery stop flags are what we expected if(!packet.deliveryStopFlags().pc) { //packet not intended for the PC return false; } //read the data type uint8 dataType = payload.read_uint8(PAYLOAD_OFFSET_DATA_TYPE); //verify the data type if(dataType < WirelessTypes::dataType_first || dataType > WirelessTypes::dataType_last) { //the data type is invalid return false; } //verify the packet type is correct if(packet.type() != packetType_AsyncDigitalAnalog) { //packet is not an Async Digital packet return false; } //calculate the number of active channels uint32 channels = ChannelMask(payload.read_uint16(PAYLOAD_OFFSET_CHANNEL_MASK)).count(); //check that there are active channels if(channels == 0) { //no active channels return false; } //packet looks valid return true; }
bool BufferedLdcPacket::integrityCheck(const WirelessPacket& packet) { WirelessPacket::Payload payload = packet.payload(); //verify the payload size if(payload.size() < PAYLOAD_OFFSET_CHANNEL_DATA) { //payload must be at least a certain length return false; } //verify the app id if(payload.read_uint8(PAYLOAD_OFFSET_APP_ID) != APP_ID_VAL) { //application id is incorrect return false; } //verify the delivery stop flags are what we expected if(!packet.deliveryStopFlags().pc) { //packet not intended for the PC return false; } //read the data type uint8 dataType = payload.read_uint8(PAYLOAD_OFFSET_DATA_TYPE); //verify the data type if(dataType < WirelessTypes::dataType_first || dataType > WirelessTypes::dataType_last) { //the data type is invalid return false; } //verify the packet type is correct if(packet.type() != packetType_BufferedLDC) { //packet is not a Buffered LDC packet return false; } //calculate the number of active channels uint32 channels = ChannelMask(payload.read_uint8(PAYLOAD_OFFSET_CHANNEL_MASK)).count(); //calculate the size of a single data point uint32 dataSize = WirelessTypes::dataTypeSize(static_cast<WirelessTypes::DataType>(dataType)); uint32 recordSize = channels * dataSize; //if record size is zero, something is wrong. Bail now before divide by zero if(recordSize <= 0) { return false; } //the number of channel data bytes size_t numChannelBytes = payload.size() - PAYLOAD_OFFSET_CHANNEL_DATA; //verify that there are actually channel data bytes if(numChannelBytes == 0) { return false; } //verify the payload contains a correct number of bytes if(numChannelBytes % recordSize != 0) { return false; } //packet looks valid return true; }