ResponsePattern
ResponsePattern
Response

A pattern matching the expected response from a device command (Base Class).

Creating your own command/response: - Create a custom "Response" class that inherits from this class.  - Create a custom version of one of the "match" functions that applies to your command.  - In the match function, if the bytes match the expected response, return true.  - Set m_success to whether the command succeeded (match a success response), or false (matched a fail response).  - Set m_fullyMatched to true when all packets/bytes have been matched. Set it to false if the packet was matched but there are still more packets/bytes remaining (the case when 1 command has multiple responses before it is complete).

Types
Response State
STATE_WAITING

The response has not yet been received.

STATE_FAIL_SHORTPING

The initial short ping has failed

STATE_FAIL_TIMEOUT

The response has timed out

STATE_FAIL

The response was a fail response

STATE_SUCCESS

The response was successfully received

Functions
ResponsePattern
explicit ResponsePattern(
std::weak_ptr<ResponseCollectorcollector
)

Creates a ResponsePattern attached to a collector.

Parameters
collector
std::weak_ptr<ResponseCollector>

The ResponseCollector to register and unregister this response with.

ResponsePattern
virtual ~ResponsePattern()

Destroys the ResponsePattern and unregisters this response from its ResponseCollector

setResponseCollector
void setResponseCollector(
std::weak_ptr<ResponseCollectorcollector
)

Sets the ResponseCollector for this pattern, and registers this pattern with the collector.

Parameters
collector
std::weak_ptr<ResponseCollector>

The ResponseCollector to assign this pattern to.

Variables
m_collector
std::weak_ptr<ResponseCollector> m_collector

The ResponseCollector that holds this response pattern

m_matchCondition
TimedCondition m_matchCondition

The TimedCondition for matching the response pattern

m_fullyMatched
bool m_fullyMatched

Whether or not the ResponsePattern has been fully matched.  Some commands have multiple parts to their response. This will not be true until all required parts have been matched.

m_success
bool m_success

Whether or not the command was a success (a success response was matched).

Functions
throwIfFailed
void throwIfFailed(
const std::string &commandName
) const

Throws an Error if the command has failed (if m_success is false).  Otherwise, no action is taken.

Parameters
commandName
const std::string&

The name of the command to put in the exception if necessary.

match
virtual bool match(
DataBuffer &data
)

Checks if the bytes passed in match the response pattern from their current read position.  If data was matched, the read position in the DataBuffer will be updated to be passed the bytes read.

Parameters
data

The DataBuffer containing the bytes in which to try to find the pattern

Returns

true if the response pattern was found, false otherwise.

match
virtual bool match(
const WirelessPacket &packet
)

Checks if the WirelessPacket passed in matches the response pattern's bytes

Parameters
packet

The WirelessPacket in which to try to find the pattern

Returns

true if the packet matches a response pattern, false otherwise.

match
virtual bool match(
const InertialDataField &field
)

Checks if the InertialDataField passed in matches the response pattern's bytes

Parameters
field

The InertialDataField in which to try to find the pattern

Returns

true if the packet matches a response pattern, false otherwise.

wait
virtual bool wait(
uint64 timeout
)

Waits for a certain amount of time for the response pattern to be matched

Parameters
timeout
uint64

The maximum amount of time (in milliseconds) to wait until the command times out and returns, if not found first.

Returns

true if the response pattern was matched, false otherwise

fullyMatched
bool fullyMatched() const

Checks whether the response pattern has been fully matched.  Some commands have multiple parts to their response. This checks whether all responses have been satisfied.

Returns

true if the response is fully matched, false otherwise

success
bool success() const

Gets whether or not the command was a success (a success response was matched).

Returns

true if the command was a success, false otherwise.