LRAUV  revA
ESPClient.h
Go to the documentation of this file.
1 
9 #ifndef ESPCLIENT_H_
10 #define ESPCLIENT_H_
11 
12 #include "ESPComm.h"
13 
14 
22 class ESPClient
23 {
24 public:
25 
39  ESPClient( ESPComm& espComm,
40  Logger& logger,
41  Timespan initialPromptTimeout,
42  Timespan loadCartridgeTimeout,
43  Timespan filterResultTimeout,
44  Timespan filterCompleteTimeout,
45  Timespan processResultTimeout,
46  Timespan processCompleteTimeout,
47  Timespan stopResultTimeout
48  );
49 
51  ~ESPClient();
52 
54  {
67  };
68 
69  const char* samplingStateName( SamplingState samplingState )
70  {
71  switch( samplingState )
72  {
73  case S_NONE:
74  return "S_NONE";
76  return "S_WAITING_INITIAL_PROMPT";
78  return "S_PREPARING_SHOW_LOG";
80  return "S_PREPARING_SHOW_STATUS";
82  return "S_LOADING_CARTRIDGE";
83  case S_FILTERING:
84  return "S_FILTERING";
86  return "S_WAITING_FOR_PAUSED";
87  case S_PROCESSING:
88  return "S_PROCESSING";
90  return "S_WAITING_FOR_PROCESSED";
91  case S_STOPPING:
92  return "S_STOPPING";
93  case S_IDLE:
94  return "S_IDLE";
95  case S_ERROR:
96  return "S_ERROR";
97  default:
98  return "(invalid SamplingState)";
99  }
100  }
101 
103  {
104  return samplingState_;
105  }
106 
108  {
110  }
111 
112  bool startSampling();
113 
118  bool isSampling();
119 
123  bool isSuccessfulSampling();
124 
126 
127  void setDebug( bool debugOn )
128  {
129  debug_ = debugOn;
130  }
131 
132 private:
133 
134  // disallow copy constructor
135  ESPClient( const ESPClient& old );
136 
138 
140 
148 
149  bool debug_;
150 
152 
154 
159 
161 
163 
164  // the latest received complete result
166 
167  // the latest received complete exception
169 
170  // advances the state machine
171  void advanceInteraction();
172 
184  void issueCommand( Str cmd, Timespan resultTimeout, Timespan completionTimeout = 10 );
185 
186  void consumeResult();
187 
188  // for reception of result of command
189  void checkCmdResultTimeout( bool issueStop = true );
190 
191  // for state transition indicating command completion
192  void checkCmdCompleteTimeout( bool issueStop = true );
193 
194  void handleException( bool awaitingResult, bool issueStop = true );
195 
196  void issueStopCommand();
197 
198  void setError( Str error );
199 
214  int getLine( Str& line, ESPComm::EspStream& stream );
215 
216  // convenience methods to facilitate testing outside of the regular LRAUV framework
217  void logDebug( Str msg );
218  void logError( Str msg );
219  void logFault( Str msg );
220 
221 };
222 
223 #endif /*ESPCLIENT_H_*/
Client-side interface for injecting log data into the log queue.
Definition: Logger.h:30
bool isSampling()
Advances the sampling interactions.
Definition: ESPClient.cpp:108
void setDebug(bool debugOn)
Definition: ESPClient.h:127
void logError(Str msg)
Definition: ESPClient.cpp:519
Definition: ESPClient.h:63
const Timespan filterCompleteTimeout_
Definition: ESPClient.h:144
const Timespan stopResultTimeout_
Definition: ESPClient.h:147
Definition: ESPClient.h:65
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 "com...
Definition: ESPClient.cpp:323
void checkCmdResultTimeout(bool issueStop=true)
Definition: ESPClient.cpp:340
Core logic for interactions with the ESP.
Definition: ESPClient.h:22
Definition: ESPClient.h:64
Definition: ESPClient.h:60
int getLine(Str &line, ESPComm::EspStream &stream)
Expects next line from the ESP.
Definition: ESPClient.cpp:443
Definition: ESPClient.h:61
const char * samplingStateName(SamplingState samplingState)
Definition: ESPClient.h:69
const Timespan processResultTimeout_
Definition: ESPClient.h:145
bool startSampling()
Definition: ESPClient.cpp:80
Timespan class, represents a delta of time.
Definition: Timestamp.h:248
const Timespan processCompleteTimeout_
Definition: ESPClient.h:146
Base socket-level interface to the ESP.
Definition: ESPComm.h:26
void logDebug(Str msg)
Definition: ESPClient.cpp:513
void checkCmdCompleteTimeout(bool issueStop=true)
Definition: ESPClient.cpp:360
bool debug_
Definition: ESPClient.h:149
Timespan cmdResultTimeout_
Definition: ESPClient.h:157
ESPComm class declaration.
const char * currentSamplingStateName()
Definition: ESPClient.h:107
Str samplingError_
Definition: ESPClient.h:162
Logger logger_
Definition: ESPClient.h:139
void handleException(bool awaitingResult, bool issueStop=true)
Definition: ESPClient.cpp:400
Str * latestResult_
Definition: ESPClient.h:165
Str issuedCmd_
Definition: ESPClient.h:155
SamplingState
Definition: ESPClient.h:53
Replacement for standard template class string.
Definition: Str.h:12
Definition: ESPClient.h:59
Str getSamplingError()
Definition: ESPClient.cpp:318
Definition: ESPClient.h:57
Definition: ESPClient.h:55
ESPClient(ESPComm &espComm, Logger &logger, Timespan initialPromptTimeout, Timespan loadCartridgeTimeout, Timespan filterResultTimeout, Timespan filterCompleteTimeout, Timespan processResultTimeout, Timespan processCompleteTimeout, Timespan stopResultTimeout)
Constructor.
Definition: ESPClient.cpp:36
Timespan cmdCompleteTimeout_
Definition: ESPClient.h:158
EspStream
the ESP virtual streams
Definition: ESPComm.h:169
bool isSuccessfulSampling()
Checks for successful completion once isSampling returns false.
Definition: ESPClient.cpp:313
const Timespan filterResultTimeout_
Definition: ESPClient.h:143
~ESPClient()
Destructor.
Definition: ESPClient.cpp:68
void advanceInteraction()
Definition: ESPClient.cpp:121
const Timespan initialPromptTimeout_
Definition: ESPClient.h:141
Str partialLine_
Definition: ESPClient.h:160
Timestamp startTimeForInitialPrompt_
Definition: ESPClient.h:153
Definition: ESPClient.h:62
Timestamp cmdIssueTime_
Definition: ESPClient.h:156
void issueStopCommand()
Definition: ESPClient.cpp:334
void consumeResult()
Definition: ESPClient.cpp:380
const Timespan loadCartridgeTimeout_
Definition: ESPClient.h:142
SamplingState samplingState_
Definition: ESPClient.h:151
Str * latestException_
Definition: ESPClient.h:168
Definition: ESPClient.h:56
Definition: ESPClient.h:66
void setError(Str error)
Definition: ESPClient.cpp:429
void logFault(Str msg)
Definition: ESPClient.cpp:525
SamplingState currentSamplingState()
Definition: ESPClient.h:102
Definition: ESPClient.h:58
Represents absolute times.
Definition: Timestamp.h:31
ESPComm & espComm_
Definition: ESPClient.h:137