|
LRAUV
revA
|
Core logic for interactions with the ESP. More...
#include <ESPClient.h>

Public Member Functions | |
| ESPClient (ESPComm &espComm, Logger &logger, Timespan initialPromptTimeout, Timespan loadCartridgeTimeout, Timespan filterResultTimeout, Timespan filterCompleteTimeout, Timespan processResultTimeout, Timespan processCompleteTimeout, Timespan stopResultTimeout) | |
| Constructor. More... | |
| ~ESPClient () | |
| Destructor. More... | |
| const char * | samplingStateName (SamplingState samplingState) |
| SamplingState | currentSamplingState () |
| const char * | currentSamplingStateName () |
| bool | startSampling () |
| bool | isSampling () |
| Advances the sampling interactions. More... | |
| bool | isSuccessfulSampling () |
| Checks for successful completion once isSampling returns false. More... | |
| Str | getSamplingError () |
| void | setDebug (bool debugOn) |
Private Member Functions | |
| ESPClient (const ESPClient &old) | |
| void | advanceInteraction () |
| void | issueCommand (Str cmd, Timespan resultTimeout, Timespan completionTimeout=10) |
| Issues a command to the ESP, setting a timeout for the result and, optionally, a timeout for the "completion" of the command. More... | |
| void | consumeResult () |
| void | checkCmdResultTimeout (bool issueStop=true) |
| void | checkCmdCompleteTimeout (bool issueStop=true) |
| void | handleException (bool awaitingResult, bool issueStop=true) |
| void | issueStopCommand () |
| void | setError (Str error) |
| int | getLine (Str &line, ESPComm::EspStream &stream) |
| Expects next line from the ESP. More... | |
| void | logDebug (Str msg) |
| void | logError (Str msg) |
| void | logFault (Str msg) |
Core logic for interactions with the ESP.
Serves as a supporting class for ESPComponent.
See ESPClientTest.cpp for a demo program that exercises this client outside of the regular LRAUV framework.
| ESPClient::ESPClient | ( | ESPComm & | espComm, |
| Logger & | logger, | ||
| Timespan | initialPromptTimeout, | ||
| Timespan | loadCartridgeTimeout, | ||
| Timespan | filterResultTimeout, | ||
| Timespan | filterCompleteTimeout, | ||
| Timespan | processResultTimeout, | ||
| Timespan | processCompleteTimeout, | ||
| Timespan | stopResultTimeout | ||
| ) |
Constructor.
| espComm | ESPComm object. |
| logger | |
| initialPromptTimeout | |
| loadCartridgeTimeout | |
| filterResultTimeout | |
| filterCompleteTimeout | |
| processResultTimeout | |
| processCompleteTimeout | |
| stopResultTimeout |
| ESPClient::~ESPClient | ( | ) |
Destructor.
References latestException_, and latestResult_.
|
private |
|
private |
References checkCmdCompleteTimeout(), checkCmdResultTimeout(), consumeResult(), Timestamp::elapsed(), ESPComm::ES_PAUSED, ESPComm::ES_PROCESSED, espComm_, filterCompleteTimeout_, filterResultTimeout_, ESPComm::getCurrentStream(), ESPComm::getEspState(), getLine(), handleException(), initialPromptTimeout_, issueCommand(), issueStopCommand(), latestException_, latestResult_, loadCartridgeTimeout_, logError(), logFault(), processCompleteTimeout_, processResultTimeout_, ESPComm::PROMPT, S_ERROR, S_FILTERING, S_IDLE, S_LOADING_CARTRIDGE, S_PREPARING_SHOW_LOG, S_PREPARING_SHOW_STATUS, S_PROCESSING, S_STOPPING, S_WAITING_FOR_PAUSED, S_WAITING_FOR_PROCESSED, S_WAITING_INITIAL_PROMPT, samplingState_, samplingStateName(), setError(), Str::startsWith(), and startTimeForInitialPrompt_.
Referenced by isSampling().
|
private |
References cmdCompleteTimeout_, cmdIssueTime_, Str::cStr(), Timestamp::elapsed(), ESPComm::escape(), espComm_, issuedCmd_, issueStopCommand(), logFault(), S_ERROR, samplingState_, and setError().
Referenced by advanceInteraction().
|
private |
References cmdIssueTime_, cmdResultTimeout_, Str::cStr(), Timestamp::elapsed(), ESPComm::escape(), espComm_, issuedCmd_, issueStopCommand(), logFault(), S_ERROR, samplingState_, and setError().
Referenced by advanceInteraction().
|
private |
References cmdIssueTime_, Str::cStr(), debug_, Timestamp::elapsed(), ESPComm::escape(), espComm_, issuedCmd_, latestResult_, logDebug(), samplingState_, samplingStateName(), and Timespan::toString().
Referenced by advanceInteraction().
|
inline |
References samplingState_.
Referenced by ESPComponent::runnable(), and ESPComponent::startSamplingPhase().
|
inline |
References samplingState_, and samplingStateName().
|
private |
Expects next line from the ESP.
It internally handles possible reception of complete result.
| line | the receive line is reported here. Trailing NOT included. |
| stream | the current stream is reported here. The stream may be updated even when no new line is reported (this is the case when only an stream indicator is received internally). |
References Str::cStr(), debug_, ESPComm::escape(), espComm_, ESPComm::EXCEPTION, ESPComm::getLastException(), ESPComm::getLastResult(), latestException_, latestResult_, Str::length(), logDebug(), logError(), partialLine_, ESPComm::readLine(), ESPComm::RESULT, ESPComm::streamName(), and ESPComm::UNKNOWN.
Referenced by advanceInteraction().
| Str ESPClient::getSamplingError | ( | ) |
References samplingError_.
Referenced by ESPComponent::runnable(), and ESPComponent::startSamplingPhase().
|
private |
References cmdIssueTime_, Str::cStr(), Timestamp::elapsed(), ESPComm::escape(), espComm_, issuedCmd_, issueStopCommand(), latestException_, logError(), S_ERROR, samplingState_, samplingStateName(), setError(), and Timespan::toString().
Referenced by advanceInteraction().
| bool ESPClient::isSampling | ( | ) |
Advances the sampling interactions.
Returns false upon completion (either successful or not).
References advanceInteraction(), S_ERROR, S_IDLE, S_NONE, and samplingState_.
Referenced by ESPComponent::runnable().
| bool ESPClient::isSuccessfulSampling | ( | ) |
Checks for successful completion once isSampling returns false.
References Str::length(), and samplingError_.
Referenced by ESPComponent::runnable().
|
private |
Issues a command to the ESP, setting a timeout for the result and, optionally, a timeout for the "completion" of the command.
NOTE: not all commands use completeTimeout, e.g., "Cmd.stop". Only "Cmd.filter" and "Cmd.process" do.
| cmd | the command |
| resultTimeout | maximum time to wait for corresponding result |
| completionTimeout | maximum time to wait for corresponding state transition indicating completion |
References cmdCompleteTimeout_, cmdIssueTime_, cmdResultTimeout_, Str::cStr(), debug_, ESPComm::escape(), espComm_, issuedCmd_, logDebug(), Timestamp::Now(), and ESPComm::sendLine().
Referenced by advanceInteraction(), and issueStopCommand().
|
private |
References issueCommand(), S_STOPPING, samplingState_, and stopResultTimeout_.
Referenced by advanceInteraction(), checkCmdCompleteTimeout(), checkCmdResultTimeout(), and handleException().
|
private |
References Syslog::DEBUG, logger_, and Logger::syslog().
Referenced by consumeResult(), getLine(), issueCommand(), setError(), and startSampling().
|
private |
References Syslog::ERROR, logger_, and Logger::syslog().
Referenced by advanceInteraction(), getLine(), handleException(), and startSampling().
|
private |
References Syslog::FAULT, logger_, and Logger::syslog().
Referenced by advanceInteraction(), checkCmdCompleteTimeout(), and checkCmdResultTimeout().
|
inline |
References S_ERROR, S_FILTERING, S_IDLE, S_LOADING_CARTRIDGE, S_NONE, S_PREPARING_SHOW_LOG, S_PREPARING_SHOW_STATUS, S_PROCESSING, S_STOPPING, S_WAITING_FOR_PAUSED, S_WAITING_FOR_PROCESSED, and S_WAITING_INITIAL_PROMPT.
Referenced by advanceInteraction(), consumeResult(), currentSamplingStateName(), handleException(), ESPComponent::runnable(), startSampling(), and ESPComponent::startSamplingPhase().
|
inline |
References debug_.
Referenced by ESPComponent::createESPClient().
|
private |
References debug_, Str::length(), logDebug(), and samplingError_.
Referenced by advanceInteraction(), checkCmdCompleteTimeout(), checkCmdResultTimeout(), handleException(), and startSampling().
| bool ESPClient::startSampling | ( | ) |
References debug_, logDebug(), logError(), Timestamp::Now(), S_NONE, S_WAITING_INITIAL_PROMPT, samplingState_, samplingStateName(), setError(), and startTimeForInitialPrompt_.
Referenced by ESPComponent::startSamplingPhase().
|
private |
Referenced by checkCmdCompleteTimeout(), and issueCommand().
|
private |
Referenced by checkCmdCompleteTimeout(), checkCmdResultTimeout(), consumeResult(), handleException(), and issueCommand().
|
private |
Referenced by checkCmdResultTimeout(), and issueCommand().
|
private |
Referenced by consumeResult(), getLine(), issueCommand(), setDebug(), setError(), and startSampling().
|
private |
Referenced by advanceInteraction(), checkCmdCompleteTimeout(), checkCmdResultTimeout(), consumeResult(), getLine(), handleException(), and issueCommand().
|
private |
Referenced by advanceInteraction().
|
private |
Referenced by advanceInteraction().
|
private |
Referenced by advanceInteraction().
|
private |
Referenced by checkCmdCompleteTimeout(), checkCmdResultTimeout(), consumeResult(), handleException(), and issueCommand().
|
private |
Referenced by advanceInteraction(), getLine(), handleException(), and ~ESPClient().
|
private |
Referenced by advanceInteraction(), consumeResult(), getLine(), and ~ESPClient().
|
private |
Referenced by advanceInteraction().
|
private |
Referenced by logDebug(), logError(), and logFault().
|
private |
Referenced by advanceInteraction().
|
private |
Referenced by advanceInteraction().
|
private |
Referenced by getSamplingError(), isSuccessfulSampling(), and setError().
|
private |
|
private |
Referenced by advanceInteraction(), and startSampling().
|
private |
Referenced by issueStopCommand().