LRAUV  revA
ESPComponent.h
Go to the documentation of this file.
1 
12 #ifndef ESPCOMPONENT_H_
13 #define ESPCOMPONENT_H_
14 
15 #include "ESPClient.h"
16 
18 #include "io/LoadControl.h"
19 #include "data/StrValue.h"
20 #include "logger/Logger.h"
21 #include "io/UartStream.h"
22 
23 
34 {
35 public:
36 
37  ESPComponent( const Module* module );
38 
39  virtual ~ESPComponent();
40 
41  virtual void run();
42 
45  virtual RunState start();
46 
48  virtual RunState starting();
49 
51  virtual RunState pause();
52 
54  virtual RunState paused();
55 
57  virtual RunState resume();
58 
60  virtual RunState resuming();
61 
63  virtual RunState runnable();
64 
66  virtual RunState resetting()
67  {
68  return start();
69  }
70 
72  virtual RunState stop();
73 
74  virtual RunState stopping();
75 
77  virtual RunState stopped();
78 
79  void uninitialize();
80 
82  virtual ConfigURI getConfigURI( ConfigOption configOption ) const;
83 
84 private:
85 
86  // disallow copy constructor
87  ESPComponent( const ESPComponent& old );
88 
96  {
102  };
104 
105  const char* startStateName( StartState startState )
106  {
107  switch( startState )
108  {
109  case SS_INIT:
110  return "SS_INIT";
112  return "SS_CONNECTING_AS_CLIENT";
114  return "SS_WAITING_FOR_ESP_TO_CONNECT";
116  return "SS_WAITING_FOR_PORT_NUMBER";
117  case SS_CONNECTED:
118  return "SS_CONNECTED";
119  default:
120  return "(invalid StartState)";
121  }
122  };
123 
127  ESPComm* espComm_;
128 
133 
135 
141  void createESPComm();
142 
146  void createESPClient();
147 
151  bool openServerSocket();
152 
156  bool powerUpESP();
157 
166  bool powerDownESP( bool setFailure = true );
167 
172 
179  bool scanEspServerPort( Str& line, int *espServerPort );
180 
184  void espReady();
185 
190 
204  int getLine( Str& line );
205 
206  // any partial line received so far from the ESP. Updated by getLine.
208 
209  // returns true if data is requested from one of the readers
210  bool isDataRequested();
211 
212  // Queries the LCBs for status
213  bool logVoltageAndCurrent();
214 
215  // Get simulation data
216  bool getSimulatedData();
217 
218  // Write data to the slate
219  void writeData();
220 
223  LoadControl* loadControl_; // as a pointer mainly to facilitate skipping it for testing
224 
225  // config readers
239 
240  // port to listen for ESP when we start as a TCP server
242 
251 
254 
256  Timespan poTimeout_; // powering up, including ESP connection
257  Timespan connectTimeout_; // when connecting as client to the ESP
258  Timespan sampleTimeout_; // complete sample sequence
259 
260  // timeouts for main steps within a complete sample sequence:
267 
269 
271 
274 
277 
280 
283 
284  // Indicates sampling is going on
287 
288  // Starts and stops pppd
289  void startPPP( void );
290  void stopPPP( void );
291 
293  bool debug_;
294 
295  // PPP connect/disconnect execution strings
298 
300 
301  // Command to start PPPD
303 
304  // Outputs to slate
307 
308  // Reads all configs
309  bool readConfigs();
310 
311  // Re-reads the config variables that are allowed to change without restarting the application.
312  bool readAdjustableConfigs();
313 
314  void logDebug( Str msg );
315 
316 };
317 #endif /*ESPCOMPONENT_H_*/
Definition: ESPComponent.h:99
int sampleNumber_
Definition: ESPComponent.h:286
bool debug_
Debugging outputs.
Definition: ESPComponent.h:293
virtual RunState stop()
Initial state – can be later followed by START.
Definition: ESPComponent.cpp:715
Contains the SyncComponent class definition.
void stopPPP(void)
Definition: ESPComponent.cpp:989
DataWriter * sampleNumberWriter_
Definition: ESPComponent.h:306
virtual RunState pause()
Pause for a short period (indicated by pauseTime)
Definition: ESPComponent.cpp:609
Contains the LoadControl class declaration.
void logDebug(Str msg)
Definition: ESPComponent.cpp:1030
bool logVoltageAndCurrent()
Definition: ESPComponent.cpp:887
Timespan lineTimeout_
Definition: ESPComponent.h:270
bool readConfigs()
Definition: ESPComponent.cpp:1004
Timespan processCompleteTimeout_
Definition: ESPComponent.h:266
ESPClient * espClient_
High-level logic for interactions with the ESP.
Definition: ESPComponent.h:132
ConfigReader * debugCfgReader_
Definition: ESPComponent.h:226
Abstract Base class for components that collect data for use later in the computation cycle...
Definition: SyncComponent.h:172
DataWriter * samplingActiveWriter_
Definition: ESPComponent.h:305
bool scanEspServerPort(Str &line, int *espServerPort)
Once the ESP is connected as a client, we expect a first line indicating the port it is listening on ...
Definition: ESPComponent.cpp:802
Sensor component to interface with the ESP.
Definition: ESPComponent.h:33
Timespan loadCartridgeTimeout_
Definition: ESPComponent.h:262
Str partialLine_
Definition: ESPComponent.h:207
Timespan initialPromptTimeout_
Definition: ESPComponent.h:261
Core logic for interactions with the ESP.
Definition: ESPClient.h:22
virtual ConfigURI getConfigURI(ConfigOption configOption) const
Should return [myNamespace]::SIMULATE_HARDWARE, or [myNamespace]::POWER, etc.
Definition: ESPComponent.cpp:1037
ConfigReader * socketServerPortCfgReader_
Definition: ESPComponent.h:227
Timestamp startTimeForLine_
Time prior to expecting a line from ESP:
Definition: ESPComponent.h:276
Timestamp sampleTime_
Time when sampling started.
Definition: ESPComponent.h:282
ESPComponent(const Module *module)
Testing with simulators on bufflehead and tethyssim:
Definition: ESPComponent.cpp:86
ConfigReader * stopResultTimeoutCfgReader_
Definition: ESPComponent.h:238
RunState
Definition: Component.h:115
bool openServerSocket()
opens server socket to listen for ESP connection
Definition: ESPComponent.cpp:253
Contains the UartStream class declaration.
Definition: ESPComponent.h:97
Timestamp startTimeConnecting_
Time prior to connecting as client to the ESP:
Definition: ESPComponent.h:279
ConfigReader * espServerHostCfgReader_
Definition: ESPComponent.h:228
UartStream uart_
Power and comms in this case.
Definition: ESPComponent.h:222
Timespan class, represents a delta of time.
Definition: Timestamp.h:248
Base socket-level interface to the ESP.
Definition: ESPComm.h:26
ConfigReader * filterResultTimeoutCfgReader_
Definition: ESPComponent.h:234
Definition: ESPComponent.h:100
ConfigReader * sampleTimeoutCfgReader_
Definition: ESPComponent.h:231
LoadControl * loadControl_
Definition: ESPComponent.h:223
ConfigReader * filterCompleteTimeoutCfgReader_
Definition: ESPComponent.h:235
StrValue espServerHost_
Typically this will the empty string from configuration, meaning that the LRAUV will power-up and dow...
Definition: ESPComponent.h:250
Implements both InStream and OutStream for the LPC3XXX Standard UART.
Definition: UartStream.h:26
StrValue pppFlow_
Definition: ESPComponent.h:297
virtual ~ESPComponent()
Definition: ESPComponent.cpp:191
bool getSimulatedData()
Definition: ESPComponent.cpp:925
A DataAccessor that writes values to the Slate via its associated DataElement.
Definition: DataWriter.h:27
void uninitialize()
Provide a space for uninitialization.
Definition: ESPComponent.cpp:954
Definition: ElementURI.h:166
void writeData()
Definition: ESPComponent.cpp:943
Contains the StrValue class definition.
Component::RunState waitForESPConnection()
Once the ESP is powered up, we wait for the ESP to connect.
Definition: ESPComponent.cpp:499
const char * startStateName(StartState startState)
Definition: ESPComponent.h:105
Timespan stopResultTimeout_
Definition: ESPComponent.h:268
Module is the abstract base class for a collection of Component objects that can be contained in a lo...
Definition: Module.h:45
ConfigReader * initialPromptTimeoutCfgReader_
Definition: ESPComponent.h:232
virtual RunState start()
Do what needs to be done to run Similar to initialize, in old init/run/uninit sequence.
Definition: ESPComponent.cpp:216
SamplingState
Definition: ESPClient.h:53
Replacement for standard template class string.
Definition: Str.h:12
StartState startState_
Definition: ESPComponent.h:103
ESPComm * espComm_
The base communications interface to the ESP.
Definition: ESPComponent.h:122
virtual RunState resuming()
Might follow a PAUSE...RESUME sequence.
Definition: ESPComponent.cpp:634
This class allows one to control loads on a load controller channel.
Definition: LoadControl.h:24
ConfigReader * connectTimeoutCfgReader_
Definition: ESPComponent.h:230
virtual RunState paused()
Should eventually follow a PAUSE request: should set continueTime.
Definition: ESPComponent.cpp:618
Timestamp startTimeAccept_
Time prior to accept ESP client connection:
Definition: ESPComponent.h:273
virtual RunState stopping()
Might follow a STOP request.
Definition: ESPComponent.cpp:760
virtual RunState starting()
Might follow a STOP...START sequence.
Definition: ESPComponent.cpp:310
void createESPClient()
Creates espClient_.
Definition: ESPComponent.cpp:827
int socketServerPort_
Definition: ESPComponent.h:241
Definition: ConfigReader.h:13
virtual void run()
The actual "payload" of the component.
Definition: ESPComponent.cpp:207
Component::RunState startSamplingPhase()
Starts a sampling phase.
Definition: ESPComponent.cpp:848
ESPClient::SamplingState samplingState_
Definition: ESPComponent.h:134
void createESPComm()
Creates espComm_ in specific mode (LRAUV either as server or client) depending on espServerHost_ (and...
Definition: ESPComponent.cpp:147
virtual RunState resetting()
Might occur in case of Error.
Definition: ESPComponent.h:66
bool samplingActive_
Definition: ESPComponent.h:285
Contains the Logger class definition.
StrValue connectExec_
Definition: ESPComponent.h:296
virtual RunState runnable()
Should eventually follow a START request or RESETTING.
Definition: ESPComponent.cpp:642
virtual RunState resume()
Resume from PAUSE.
Definition: ESPComponent.cpp:626
int getLine(Str &line)
Expects next line from the ESP.
Definition: ESPComponent.cpp:540
Definition: ESPComponent.h:98
Definition: ESPComponent.h:101
ConfigReader * poTimeoutCfgReader_
Definition: ESPComponent.h:229
void startPPP(void)
Definition: ESPComponent.cpp:970
virtual FailureMode::FailType setFailure(FailureMode::FailType failureType)
Definition: Component.cpp:228
Timespan filterCompleteTimeout_
Definition: ESPComponent.h:264
bool isDataRequested()
Definition: ESPComponent.cpp:918
bool powerDownESP(bool setFailure=true)
powers down ESP and brings down PPP link.
Definition: ESPComponent.cpp:282
void espReady()
ESP connection ready.
Definition: ESPComponent.cpp:586
bool powerUpESP()
powers up ESP and initiates PPP link
Definition: ESPComponent.cpp:263
bool readAdjustableConfigs()
Definition: ESPComponent.cpp:1023
StartState
Sub-states while in LRAUV framework's STARTING state.
Definition: ESPComponent.h:95
ConfigOption
Definition: Component.h:456
Str pppCmd_
Definition: ESPComponent.h:302
ESPClient class declaration.
ConfigReader * processResultTimeoutCfgReader_
Definition: ESPComponent.h:236
Wraps a string (see Str) as a DataValue, so strings can be written to and read from the slate...
Definition: StrValue.h:34
Timespan connectTimeout_
Definition: ESPComponent.h:257
Timespan poTimeout_
Timeouts.
Definition: ESPComponent.h:256
StrValue uartName_
Definition: ESPComponent.h:299
Timespan sampleTimeout_
Definition: ESPComponent.h:258
Timespan filterResultTimeout_
Definition: ESPComponent.h:263
Represents absolute times.
Definition: Timestamp.h:31
ConfigReader * loadCartridgeTimeoutCfgReader_
Definition: ESPComponent.h:233
ConfigReader * processCompleteTimeoutCfgReader_
Definition: ESPComponent.h:237
bool espAlwaysServer_
true if and only if espServerHost_ is non-empty and has the format "hostname:portNumber" ...
Definition: ESPComponent.h:253
Timespan processResultTimeout_
Definition: ESPComponent.h:265
virtual RunState stopped()
Initial state – can be later followed by START.
Definition: ESPComponent.cpp:790