LRAUV  revA
ESPClient Class Reference

Core logic for interactions with the ESP. More...

#include <ESPClient.h>

Collaboration diagram for ESPClient:

Public Types

enum  SamplingState {
  S_NONE, S_WAITING_INITIAL_PROMPT, S_PREPARING_SHOW_LOG, S_PREPARING_SHOW_STATUS,
  S_LOADING_CARTRIDGE, S_FILTERING, S_WAITING_FOR_PAUSED, S_PROCESSING,
  S_WAITING_FOR_PROCESSED, S_STOPPING, S_IDLE, S_ERROR
}
 

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)
 

Private Attributes

ESPCommespComm_
 
Logger logger_
 
const Timespan initialPromptTimeout_
 
const Timespan loadCartridgeTimeout_
 
const Timespan filterResultTimeout_
 
const Timespan filterCompleteTimeout_
 
const Timespan processResultTimeout_
 
const Timespan processCompleteTimeout_
 
const Timespan stopResultTimeout_
 
bool debug_
 
SamplingState samplingState_
 
Timestamp startTimeForInitialPrompt_
 
Str issuedCmd_
 
Timestamp cmdIssueTime_
 
Timespan cmdResultTimeout_
 
Timespan cmdCompleteTimeout_
 
Str partialLine_
 
Str samplingError_
 
StrlatestResult_
 
StrlatestException_
 

Detailed Description

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.

Member Enumeration Documentation

Enumerator
S_NONE 
S_WAITING_INITIAL_PROMPT 
S_PREPARING_SHOW_LOG 
S_PREPARING_SHOW_STATUS 
S_LOADING_CARTRIDGE 
S_FILTERING 
S_WAITING_FOR_PAUSED 
S_PROCESSING 
S_WAITING_FOR_PROCESSED 
S_STOPPING 
S_IDLE 
S_ERROR 

Constructor & Destructor Documentation

ESPClient::ESPClient ( ESPComm espComm,
Logger logger,
Timespan  initialPromptTimeout,
Timespan  loadCartridgeTimeout,
Timespan  filterResultTimeout,
Timespan  filterCompleteTimeout,
Timespan  processResultTimeout,
Timespan  processCompleteTimeout,
Timespan  stopResultTimeout 
)

Constructor.

Parameters
espCommESPComm object.
logger
initialPromptTimeout
loadCartridgeTimeout
filterResultTimeout
filterCompleteTimeout
processResultTimeout
processCompleteTimeout
stopResultTimeout
ESPClient::~ESPClient ( )

Destructor.

References latestException_, and latestResult_.

ESPClient::ESPClient ( const ESPClient old)
private

Member Function Documentation

void ESPClient::checkCmdCompleteTimeout ( bool  issueStop = true)
private
void ESPClient::checkCmdResultTimeout ( bool  issueStop = true)
private
SamplingState ESPClient::currentSamplingState ( )
inline
const char* ESPClient::currentSamplingStateName ( )
inline
int ESPClient::getLine ( Str line,
ESPComm::EspStream stream 
)
private

Expects next line from the ESP.

It internally handles possible reception of complete result.

Parameters
linethe receive line is reported here. Trailing
NOT included.
streamthe 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).
Returns
+1: a line was actually received in this call 0: still waiting for line <0: some error (in readLine)

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 ( )
void ESPClient::handleException ( bool  awaitingResult,
bool  issueStop = true 
)
private
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().

void ESPClient::issueCommand ( Str  cmd,
Timespan  resultTimeout,
Timespan  completionTimeout = 10 
)
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.

Parameters
cmdthe command
resultTimeoutmaximum time to wait for corresponding result
completionTimeoutmaximum 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().

void ESPClient::issueStopCommand ( )
private
void ESPClient::logDebug ( Str  msg)
private
void ESPClient::logError ( Str  msg)
private
void ESPClient::logFault ( Str  msg)
private
void ESPClient::setDebug ( bool  debugOn)
inline

References debug_.

Referenced by ESPComponent::createESPClient().

Member Data Documentation

Timespan ESPClient::cmdCompleteTimeout_
private
Timespan ESPClient::cmdResultTimeout_
private
bool ESPClient::debug_
private
const Timespan ESPClient::filterCompleteTimeout_
private

Referenced by advanceInteraction().

const Timespan ESPClient::filterResultTimeout_
private

Referenced by advanceInteraction().

const Timespan ESPClient::initialPromptTimeout_
private

Referenced by advanceInteraction().

Str* ESPClient::latestException_
private
Str* ESPClient::latestResult_
private
const Timespan ESPClient::loadCartridgeTimeout_
private

Referenced by advanceInteraction().

Logger ESPClient::logger_
private

Referenced by logDebug(), logError(), and logFault().

Str ESPClient::partialLine_
private

Referenced by getLine().

const Timespan ESPClient::processCompleteTimeout_
private

Referenced by advanceInteraction().

const Timespan ESPClient::processResultTimeout_
private

Referenced by advanceInteraction().

Str ESPClient::samplingError_
private
Timestamp ESPClient::startTimeForInitialPrompt_
private
const Timespan ESPClient::stopResultTimeout_
private

Referenced by issueStopCommand().


The documentation for this class was generated from the following files: