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).
explicit ResponsePattern( |
| ) |
Creates a ResponsePattern attached to a collector.
collector std::weak_ptr<ResponseCollector> | The ResponseCollector to register and unregister this response with. |
Destroys the ResponsePattern and unregisters this response from its ResponseCollector
void setResponseCollector( |
| ) |
Sets the ResponseCollector for this pattern, and registers this pattern with the collector.
collector std::weak_ptr<ResponseCollector> | The ResponseCollector to assign this pattern to. |
The ResponseCollector that holds this response pattern
The TimedCondition for matching the response pattern
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.
Whether or not the command was a success (a success response was matched).
void throwIfFailed( |
| ) const |
Throws an Error if the command has failed (if m_success is false). Otherwise, no action is taken.
commandName const std::string& | The name of the command to put in the exception if necessary. |
virtual bool match( |
| ) |
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.
data | The DataBuffer containing the bytes in which to try to find the pattern |
true if the response pattern was found, false otherwise.
virtual bool match( |
| ) |
Checks if the WirelessPacket passed in matches the response pattern's bytes
packet const WirelessPacket& | The WirelessPacket in which to try to find the pattern |
true if the packet matches a response pattern, false otherwise.
virtual bool match( |
| ) |
Checks if the InertialDataField passed in matches the response pattern's bytes
field const InertialDataField& | The InertialDataField in which to try to find the pattern |
true if the packet matches a response pattern, false otherwise.
virtual bool wait( |
| ) |
Waits for a certain amount of time for the response pattern to be matched
timeout uint64 | The maximum amount of time (in milliseconds) to wait until the command times out and returns, if not found first. |
true if the response pattern was matched, false otherwise
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.
true if the response is fully matched, false otherwise
Gets whether or not the command was a success (a success response was matched).
true if the command was a success, false otherwise.