TwiceAsNice  2019-02-18
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Types | Private Member Functions | Private Attributes | List of all members
Basda::IODeviceWut Class Reference

#include <IODeviceWut.h>

Inheritance diagram for Basda::IODeviceWut:
Inheritance graph
Collaboration diagram for Basda::IODeviceWut:
Collaboration graph

Classes

struct  PropertyName
 
struct  PropertyValue
 
class  SetOutputPortCommand
 

Public Member Functions

 IODeviceWut (const Nice::JointPtr &_config)
 
virtual ~IODeviceWut ()
 
virtual void open ()
 initialize fundamental communication parameters. Define hostname, password and polling cycle. More...
 
virtual void close ()
 toggle an internal flag to disable further use. More...
 
virtual void reset (Basda::DeviceAsync &=Basda::Device::s_async)
 Tells the basda status to assume a reset state. More...
 
virtual void init (Basda::DeviceAsync &=Basda::Device::s_async)
 Initialize counters and values to an unknown status. More...
 
virtual void deinit (Basda::DeviceAsync &=Basda::Device::s_async)
 Tells the basda status to assume a de-initialized status. More...
 
virtual void activate (DeviceAsync &=s_async)
 dummy function which does nothing. More...
 
virtual void deactivate (DeviceAsync &=s_async)
 dummy function which does nothing. More...
 
virtual void version ()
 logs a version number into the logger. More...
 
virtual std::vector< double > read ()
 Reads out the device and updates the property tree. More...
 
virtual void write (std::vector< double >)
 dummy function. Does nothing. More...
 
virtual enum PortState readOutputPort (int index)
 Obtain a single port's status. More...
 
virtual void setOutputPort (int portIndex, enum PortState desiredState)
 Set a single output port to on or off. More...
 
virtual Nice::JointPtrVector description (void)
 get the part nodes More...
 
virtual bool isReachable ()
 
virtual void hardwareIsReachable ()
 Set the flag for reachability to true. More...
 
virtual void hardwareIsUnreachable ()
 Set the flag for reachability to false. More...
 
- Public Member Functions inherited from Basda::AnalogIODevice
 AnalogIODevice (const Nice::JointPtr &_config)
 
 AnalogIODevice (const Nice::JointPtr &_config)
 
 AnalogIODevice (const Nice::JointPtr &_config)
 
- Public Member Functions inherited from Basda::Device
 Device (const Nice::JointPtr &_config)
 constructor. This is an elementary (lazy) action which stores the name and gets configuration. More...
 
virtual ~Device ()
 destructor Does nothing More...
 
virtual void setConfig (const Nice::JointPtr &_config)
 init with config tree ptr More...
 
Nice::JointPtrconfig ()
 retrieve the property tree More...
 
std::string & name ()
 retrieve the name set at ctor time. More...
 
 Device (const Nice::JointPtr &_config)
 constructor. This is an elementary (lazy) action which stores the name and gets configuration. More...
 
virtual ~Device ()
 destructor Does nothing More...
 
virtual void setConfig (const Nice::JointPtr &_config)
 init with config tree ptr More...
 
Nice::JointPtrconfig ()
 retrieve the property tree More...
 
std::string & name ()
 retrieve the name set at ctor time. More...
 

Static Public Member Functions

static std::string toString (enum Basda::AnalogIODevice::PortState state)
 Convert the enumerated state to a human-readable string. More...
 

Protected Member Functions

void setReachablePropertyTo (bool reachable)
 
void injectWebSocketFactory (WebSocketFactoryPtr newFactory)
 
int cnvrtOutIndexToNodeIndex (const int index)
 reverse lookup of the device index in the vector of PART's More...
 

Protected Attributes

Nice::JointPtrVector m_partNodes
 
webIOInputVector m_input
 
webIOOutputVector m_output
 
bool readyForDeviceCommunication_
 
Nice::Mutex m_mtx
 
Nice::Mutex m_readMtx
 
Nice::Mutex m_writeMtx
 
unsigned m_maxAllowedNetworkServiceDelayInMicroSec
 
unsigned m_pollCycleTimeInMilliSec
 
Basda::WuT::LogPtr m_log
 
- Protected Attributes inherited from Basda::Device
Nice::JointPtr m_config
 
Nice::JointPtr m_cfg
 
Nice::JointPtr m_var
 
std::string m_name
 

Private Types

typedef SetOutputPortCommand< PORT_STATE_OFFSetOffOutputPortCommand
 
typedef SetOutputPortCommand< PORT_STATE_ONSetOnOutputPortCommand
 

Private Member Functions

void usingNoOpForCheckingConnection (WebSocketPtr socket)
 
WebSocketPtr buildWebSocket ()
 define a socket by port and host. More...
 
WebSocketPtr getReadRequestWebSocket ()
 
WebSocketPtr getWriteRequestWebSocket ()
 
enum PortState convertStringToPortState (const std::string &portState)
 Convert the human-readable on or off string to a local enumerated state. More...
 
enum PortState readOutputPortOverNetwork (WebSocketPtr webSocket, int index)
 
void setOutputPortOverNetwork (WebSocketPtr webSocket, int portIndex, enum Basda::AnalogIODevice::PortState desiredState)
 Set a single output port to on or off. More...
 
std::vector< double > readOverNetworkAndUpdateProperties (WebSocketPtr webSocket)
 
void applyDefaultColorScheme (Nice::PropertyPtr statusProperty)
 define a black-on-yellow and black-on-grey color scheme for the two port states. More...
 
void installOutputPortSetterCommand (Nice::JointPtr config)
 
Nice::CompletionState executeOutputPortSetterCommand (Nice::CommandFun< IODeviceWut > *cmd, bool &abort)
 Actually forward the desired state to the device. The information which of the ports is set to which state is obtained from the local property tree and not forwarded by function arguments here. More...
 
void denoteCommandAsFinished (Nice::PropertyPtr commandProperty, const Nice::Completion c)
 
void denoteCommandAsFailed (Nice::PropertyPtr commandProperty)
 
void installSetOffOutputPortCommand (Nice::JointPtr config)
 
void installSetOnOutputPortCommand (Nice::JointPtr config)
 
Nice::PropertyPtr createCommandProperty (Nice::JointPtr config, const std::string &commandName)
 
void attachCompletionViewAttributes (Nice::PropertyPtr commandProperty, const std::string &label)
 
void configureMaxAllowedNetworkServiceDelay ()
 
void configurePollCycleTime ()
 
void markDeviceStateAsUnknown ()
 
void markDeviceStateAsUnknownAfterReadFailure ()
 
void markDeviceStateAsUnknownAfterWriteFailure ()
 
void createNameProperty ()
 
void setNumberOfPorts (const int inputPortCounter, const int outputPortCounter)
 

Private Attributes

std::vector< SetOffOutputPortCommand * > m_setOffOutputPortCommands
 
std::vector< SetOnOutputPortCommand * > m_setOnOutputPortCommands
 
WebSocketFactoryPtr m_webSocketFactory
 
WebSocketPtr m_readRequestWebSocket
 
WebSocketPtr m_writeRequestWebSocket
 
std::string m_hostname
 
std::string m_httpPasswd
 
int m_portNumber
 

Additional Inherited Members

- Public Types inherited from Basda::AnalogIODevice
enum  PortState {
  PORT_STATE_OFF = 0, PORT_STATE_ON = 1, PORT_STATE_UNKNOWN = -1, PORT_STATE_OFF = 0,
  PORT_STATE_ON = 1, PORT_STATE_UNKNOWN = -1, PORT_STATE_OFF = 0, PORT_STATE_ON = 1,
  PORT_STATE_UNKNOWN = -1
}
 
enum  PortState {
  PORT_STATE_OFF = 0, PORT_STATE_ON = 1, PORT_STATE_UNKNOWN = -1, PORT_STATE_OFF = 0,
  PORT_STATE_ON = 1, PORT_STATE_UNKNOWN = -1, PORT_STATE_OFF = 0, PORT_STATE_ON = 1,
  PORT_STATE_UNKNOWN = -1
}
 
enum  PortState {
  PORT_STATE_OFF = 0, PORT_STATE_ON = 1, PORT_STATE_UNKNOWN = -1, PORT_STATE_OFF = 0,
  PORT_STATE_ON = 1, PORT_STATE_UNKNOWN = -1, PORT_STATE_OFF = 0, PORT_STATE_ON = 1,
  PORT_STATE_UNKNOWN = -1
}
 
- Static Public Attributes inherited from Basda::Device
static DeviceAsyncImpl s_async
 

Member Typedef Documentation

◆ SetOffOutputPortCommand

◆ SetOnOutputPortCommand

Constructor & Destructor Documentation

◆ IODeviceWut()

Basda::IODeviceWut::IODeviceWut ( const Nice::JointPtr _config)

◆ ~IODeviceWut()

Basda::IODeviceWut::~IODeviceWut ( )
virtual

Member Function Documentation

◆ activate()

void Basda::IODeviceWut::activate ( DeviceAsync = s_async)
virtual

dummy function which does nothing.


Implements Basda::Device.

Reimplemented in Basda::IODeviceWutFake.

◆ applyDefaultColorScheme()

void Basda::IODeviceWut::applyDefaultColorScheme ( Nice::PropertyPtr  statusProperty)
private

define a black-on-yellow and black-on-grey color scheme for the two port states.


Parameters
statusProperty

◆ attachCompletionViewAttributes()

void Basda::IODeviceWut::attachCompletionViewAttributes ( Nice::PropertyPtr  commandProperty,
const std::string &  label 
)
private

◆ buildWebSocket()

WebSocketPtr Basda::IODeviceWut::buildWebSocket ( )
private

define a socket by port and host.


Returns
A pointer to the new socket.

◆ close()

void Basda::IODeviceWut::close ( void  )
virtual

toggle an internal flag to disable further use.


Implements Basda::Device.

Reimplemented in Basda::IODeviceWutFake.

◆ cnvrtOutIndexToNodeIndex()

int Basda::IODeviceWut::cnvrtOutIndexToNodeIndex ( const int  index)
protected

reverse lookup of the device index in the vector of PART's


Parameters
[in]indexOne of the OUTPUT index of the confguration tree.
Returns
The associated position in the BASDA device vector. -1 if absent.
Since
2018-03-28

◆ configureMaxAllowedNetworkServiceDelay()

void Basda::IODeviceWut::configureMaxAllowedNetworkServiceDelay ( )
private

◆ configurePollCycleTime()

void Basda::IODeviceWut::configurePollCycleTime ( )
private

◆ convertStringToPortState()

enum Basda::AnalogIODevice::PortState Basda::IODeviceWut::convertStringToPortState ( const std::string &  portState)
private

Convert the human-readable on or off string to a local enumerated state.


Parameters
[in]portStateA string "ON" or "OFF".
Returns
The local enumerated equivalent state.

◆ createCommandProperty()

Nice::PropertyPtr Basda::IODeviceWut::createCommandProperty ( Nice::JointPtr  config,
const std::string &  commandName 
)
private

◆ createNameProperty()

void Basda::IODeviceWut::createNameProperty ( )
private

◆ deactivate()

void Basda::IODeviceWut::deactivate ( DeviceAsync = s_async)
virtual

dummy function which does nothing.


Implements Basda::Device.

Reimplemented in Basda::IODeviceWutFake.

◆ deinit()

void Basda::IODeviceWut::deinit ( Basda::DeviceAsync _async = Basda::Device::s_async)
virtual

Tells the basda status to assume a de-initialized status.


Parameters
_asyncThe state keeper of the device status.

Implements Basda::Device.

Reimplemented in Basda::IODeviceWutFake.

◆ denoteCommandAsFailed()

void Basda::IODeviceWut::denoteCommandAsFailed ( Nice::PropertyPtr  commandProperty)
private

◆ denoteCommandAsFinished()

void Basda::IODeviceWut::denoteCommandAsFinished ( Nice::PropertyPtr  commandProperty,
const Nice::Completion  c 
)
private

◆ description()

Nice::JointPtrVector Basda::IODeviceWut::description ( void  )
virtual

get the part nodes

Returns
part nodes of the config tree

Returns

Implements Basda::AnalogIODevice.

◆ executeOutputPortSetterCommand()

Nice::CompletionState Basda::IODeviceWut::executeOutputPortSetterCommand ( Nice::CommandFun< IODeviceWut > *  cmd,
bool abort 
)
private

Actually forward the desired state to the device. The information which of the ports is set to which state is obtained from the local property tree and not forwarded by function arguments here.

Note
thread-safe

Returns
Nice::FATAL (if not initialized) or Nice::OK

◆ getReadRequestWebSocket()

WebSocketPtr Basda::IODeviceWut::getReadRequestWebSocket ( )
private

◆ getWriteRequestWebSocket()

WebSocketPtr Basda::IODeviceWut::getWriteRequestWebSocket ( )
private

◆ hardwareIsReachable()

void Basda::IODeviceWut::hardwareIsReachable ( )
virtual

Set the flag for reachability to true.

Note
thread-safe

◆ hardwareIsUnreachable()

void Basda::IODeviceWut::hardwareIsUnreachable ( )
virtual

Set the flag for reachability to false.

Note
thread-safe

◆ init()

void Basda::IODeviceWut::init ( Basda::DeviceAsync _async = Basda::Device::s_async)
virtual

Initialize counters and values to an unknown status.


Parameters
_asyncThe state keeper of the status. This is put into the INIT state here.

Implements Basda::Device.

Reimplemented in Basda::IODeviceWutFake.

◆ injectWebSocketFactory()

void Basda::IODeviceWut::injectWebSocketFactory ( WebSocketFactoryPtr  newFactory)
protected

◆ installOutputPortSetterCommand()

void Basda::IODeviceWut::installOutputPortSetterCommand ( Nice::JointPtr  config)
private

Parameters
config

◆ installSetOffOutputPortCommand()

void Basda::IODeviceWut::installSetOffOutputPortCommand ( Nice::JointPtr  config)
private

◆ installSetOnOutputPortCommand()

void Basda::IODeviceWut::installSetOnOutputPortCommand ( Nice::JointPtr  config)
private

◆ isReachable()

bool Basda::IODeviceWut::isReachable ( )
virtual
Note
thread-safe

Returns
True if reachable, false if not.

Implements Basda::AnalogIODevice.

◆ markDeviceStateAsUnknown()

void Basda::IODeviceWut::markDeviceStateAsUnknown ( )
private

◆ markDeviceStateAsUnknownAfterReadFailure()

void Basda::IODeviceWut::markDeviceStateAsUnknownAfterReadFailure ( )
private

◆ markDeviceStateAsUnknownAfterWriteFailure()

void Basda::IODeviceWut::markDeviceStateAsUnknownAfterWriteFailure ( )
private

◆ open()

void Basda::IODeviceWut::open ( void  )
virtual

initialize fundamental communication parameters. Define hostname, password and polling cycle.


Implements Basda::Device.

Reimplemented in Basda::IODeviceWutFake.

◆ read()

std::vector< double > Basda::IODeviceWut::read ( void  )
virtual

Reads out the device and updates the property tree.

Try to read all INPUT and OUTPUT ports.

Returns
data vector containing the readings
Note
thread-safe

Returns
A vector of zeros and ones for the INPUT's and OUTPUT's.

Implements Basda::AnalogIODevice.

Reimplemented in Basda::IODeviceWutFake.

◆ readOutputPort()

enum Basda::AnalogIODevice::PortState Basda::IODeviceWut::readOutputPort ( int  index)
virtual

Obtain a single port's status.

Note
thread-safe

Parameters
[in]indexThe individual index into the property tree of ports.
Returns
The on or off status.

Implements Basda::AnalogIODevice.

Reimplemented in Basda::IODeviceWutFake.

◆ readOutputPortOverNetwork()

enum Basda::AnalogIODevice::PortState Basda::IODeviceWut::readOutputPortOverNetwork ( WebSocketPtr  webSocket,
int  index 
)
private

Parameters
webSocket
index
Returns
the ON or OFF state in its enumerated representation.

◆ readOverNetworkAndUpdateProperties()

std::vector< double > Basda::IODeviceWut::readOverNetworkAndUpdateProperties ( WebSocketPtr  webSocket)
private

Parameters
webSocket
Returns
A vector of 1.0 and 0.0 representing the status. Alternatingly the INPUTs, then the OUTPUTs in the order of declaration in the configuration.
Since
2018-03-16 get output status only if configured.

◆ reset()

void Basda::IODeviceWut::reset ( Basda::DeviceAsync _async = Basda::Device::s_async)
virtual

Tells the basda status to assume a reset state.


Parameters
_asyncThe state keeper of the device status.

Implements Basda::Device.

Reimplemented in Basda::IODeviceWutFake.

◆ setNumberOfPorts()

void Basda::IODeviceWut::setNumberOfPorts ( const int  inputPortCounter,
const int  outputPortCounter 
)
private

◆ setOutputPort()

void Basda::IODeviceWut::setOutputPort ( int  portIndex,
enum PortState  desiredState 
)
virtual

Set a single output port to on or off.

Note
thread-safe

Parameters
portIndexThe output port number. This is not the index in the local C++ vector of ports but the one on the device.
desiredStateThe desired new on or off state.

Implements Basda::AnalogIODevice.

Reimplemented in Basda::IODeviceWutFake.

◆ setOutputPortOverNetwork()

void Basda::IODeviceWut::setOutputPortOverNetwork ( WebSocketPtr  webSocket,
int  portIndex,
enum Basda::AnalogIODevice::PortState  desiredState 
)
private

Set a single output port to on or off.


Parameters
webSocket
portIndexThe output port number. This is not the index in the local C++ vector of ports but the one on the device.
desiredStateThe desired new on or off state.

◆ setReachablePropertyTo()

void Basda::IODeviceWut::setReachablePropertyTo ( bool  reachable)
protected

◆ toString()

std::string Basda::IODeviceWut::toString ( enum Basda::AnalogIODevice::PortState  state)
static

Convert the enumerated state to a human-readable string.


Parameters
[in]stateOne of the on, off or unknown states.
Returns
"ON" or "OFF" or "UNKNOWN".

◆ usingNoOpForCheckingConnection()

void Basda::IODeviceWut::usingNoOpForCheckingConnection ( WebSocketPtr  socket)
private

◆ version()

void Basda::IODeviceWut::version ( void  )
virtual

logs a version number into the logger.


Implements Basda::Device.

Reimplemented in Basda::IODeviceWutFake.

◆ write()

void Basda::IODeviceWut::write ( std::vector< double >  )
virtual

dummy function. Does nothing.


Implements Basda::AnalogIODevice.

Member Data Documentation

◆ m_hostname

std::string Basda::IODeviceWut::m_hostname
private

◆ m_httpPasswd

std::string Basda::IODeviceWut::m_httpPasswd
private

◆ m_input

webIOInputVector Basda::IODeviceWut::m_input
protected

◆ m_log

Basda::WuT::LogPtr Basda::IODeviceWut::m_log
protected

◆ m_maxAllowedNetworkServiceDelayInMicroSec

unsigned Basda::IODeviceWut::m_maxAllowedNetworkServiceDelayInMicroSec
protected

◆ m_mtx

Nice::Mutex Basda::IODeviceWut::m_mtx
protected

◆ m_output

webIOOutputVector Basda::IODeviceWut::m_output
protected

◆ m_partNodes

Nice::JointPtrVector Basda::IODeviceWut::m_partNodes
protected

◆ m_pollCycleTimeInMilliSec

unsigned Basda::IODeviceWut::m_pollCycleTimeInMilliSec
protected

◆ m_portNumber

int Basda::IODeviceWut::m_portNumber
private

◆ m_readMtx

Nice::Mutex Basda::IODeviceWut::m_readMtx
protected

◆ m_readRequestWebSocket

WebSocketPtr Basda::IODeviceWut::m_readRequestWebSocket
private

◆ m_setOffOutputPortCommands

std::vector<SetOffOutputPortCommand *> Basda::IODeviceWut::m_setOffOutputPortCommands
private

◆ m_setOnOutputPortCommands

std::vector<SetOnOutputPortCommand *> Basda::IODeviceWut::m_setOnOutputPortCommands
private

◆ m_webSocketFactory

WebSocketFactoryPtr Basda::IODeviceWut::m_webSocketFactory
private

◆ m_writeMtx

Nice::Mutex Basda::IODeviceWut::m_writeMtx
protected

◆ m_writeRequestWebSocket

WebSocketPtr Basda::IODeviceWut::m_writeRequestWebSocket
private

◆ readyForDeviceCommunication_

bool Basda::IODeviceWut::readyForDeviceCommunication_
protected

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