API
MagAOX::app::dev::outletController< derivedT > Struct Template Referenceabstract

A generic outlet controller. More...

#include <outletController.hpp>

Collaboration diagram for MagAOX::app::dev::outletController< derivedT >:
Collaboration graph

Classes

struct  channelSpec
 Structure containing the specification of one channel. More...
 

Public Member Functions

int setupConfig (mx::app::appConfigurator &config)
 Setup an application configurator for an outletController. More...
 
int loadConfig (mx::app::appConfigurator &config)
 Load the [channel] sections from an application configurator. More...
 
int setNumberOfOutlets (int numOuts)
 Sets the number of outlets. This should be called by the derived class constructor. More...
 
int outletState (int outletNum)
 Get the currently stored outlet state, without updating from device. More...
 
virtual int updateOutletState (int outletNum)=0
 Get the state of the outlet from the device. More...
 
virtual int updateOutletStates ()
 Get the states of all outlets from the device. More...
 
virtual int turnOutletOn (int outletNum)=0
 Turn an outlet on. More...
 
virtual int turnOutletOff (int outletNum)=0
 Turn an outlet off. More...
 
size_t numChannels ()
 Get the number of channels. More...
 
std::vector< size_t > channelOutlets (const std::string &channel)
 Get the vector of outlet indices for a channel. More...
 
std::vector< size_t > channelOnOrder (const std::string &channel)
 Get the vector of outlet on orders for a channel. More...
 
std::vector< size_t > channelOffOrder (const std::string &channel)
 Get the vector of outlet off orders for a channel. More...
 
std::vector< unsigned > channelOnDelays (const std::string &channel)
 Get the vector of outlet on delays for a channel. More...
 
std::vector< unsigned > channelOffDelays (const std::string &channel)
 Get the vector of outlet off delays for a channel. More...
 
int channelState (const std::string &channel)
 Get the state of a channel. More...
 
int turnChannelOn (const std::string &channel)
 Turn a channel on. More...
 
int turnChannelOff (const std::string &channel)
 Turn a channel off. More...
 

Public Attributes

bool m_firstOne {false}
 Flag is true if the first outlet is numbered 1, otherwise assumes starting at 0. More...
 
std::vector< int > m_outletStates
 The current states of each outlet. These MUST be updated by derived classes in the overridden updatedOutletState. More...
 
pcf::IndiProperty m_indiP_outletStates
 Indi Property to show individual outlet states. More...
 
std::unordered_map< std::string, channelSpecm_channels
 The map of channel specifications, which can be accessed by their names. More...
 
pcf::IndiProperty m_indiP_chOutlets
 An INDI property which publishes the outlets associated with each channel. Useful for GUIs, etc. More...
 
pcf::IndiProperty m_indiP_chOnDelays
 An INDI property which publishes the total on delay for each channel. Useful for GUIs, etc. More...
 
pcf::IndiProperty m_indiP_chOffDelays
 An INDI property which publishes the total off delay for each channel. Useful for GUIs, etc. More...
 

Private Member Functions

derivedT & derived ()
 

INDI Setup

int newCallBack_channels (const pcf::IndiProperty &ipRecv)
 The callback called by the static version, to actually process the new request. More...
 
int setupINDI ()
 Setup the INDI properties for this device controller. More...
 
int updateINDI ()
 Update the INDI properties for this device controller. More...
 
static int st_newCallBack_channels (void *app, const pcf::IndiProperty &ipRecv)
 The static callback function to be registered for the channel properties. More...
 

Detailed Description

template<class derivedT>
struct MagAOX::app::dev::outletController< derivedT >

A generic outlet controller.

Controls a set of outlets on a device, such as A/C power outlets or digital outputs. The outlets are organized into channels, which could be made up of multiple outlets.

derivedT must be a MagAOXApp, and additionally it must implement the functions

int turnOutletOn( int outletNum );
int turnOutletOff( int outletNum );
int updateOutletState( int outletNum );
virtual int updateOutletState(int outletNum)=0
Get the state of the outlet from the device.
virtual int turnOutletOff(int outletNum)=0
Turn an outlet off.
virtual int turnOutletOn(int outletNum)=0
Turn an outlet on.

and optionally

virtual int updateOutletStates()
Get the states of all outlets from the device.

Other requirements:

  • call setNumberOfOutlets in the derived class constructor
Template Parameters
derivedTspecifies a MagAOXApp parent base class which is accessed with a static_cast (downcast) to perform various methods.
Todo:
finalize 0-counting vs 1-counting rules --> do we subtract one from config-ed outlet indices if m_firstOne is true?

Definition at line 68 of file outletController.hpp.


Class Documentation

◆ MagAOX::app::dev::outletController::channelSpec

struct MagAOX::app::dev::outletController::channelSpec

template<class derivedT>
struct MagAOX::app::dev::outletController< derivedT >::channelSpec

Structure containing the specification of one channel.

A channel may include more than one outlet, may specify the order in which outlets are turned on and/or off, and may specify a delay between turning outlets on and/or off.

Definition at line 81 of file outletController.hpp.

Collaboration diagram for MagAOX::app::dev::outletController< derivedT >::channelSpec:
Collaboration graph
Class Members
IndiProperty m_indiP_prop
vector< unsigned > m_offDelays [optional] The delays between outlets in a multi-oultet channel. The first entry is always ignored. The second entry is the dealy between the first and second outlet, etc.
vector< size_t > m_offOrder [optional] The order in which outlets are turned off. This contains the indices of m_outlets, not the outlet numbers of the device.
vector< unsigned > m_onDelays [optional] The delays between outlets in a multi-oultet channel. The first entry is always ignored. The second entry is the dealy between the first and second outlet, etc.
vector< size_t > m_onOrder [optional] The order in which outlets are turned on. This contains the indices of m_outlets, not the outlet numbers of the device.
vector< size_t > m_outlets The outlets in this channel.

Member Function Documentation

◆ channelOffDelays()

template<class derivedT >
std::vector< unsigned > MagAOX::app::dev::outletController< derivedT >::channelOffDelays ( const std::string &  channel)

Get the vector of outlet off delays for a channel.

Mainly used for testing.

Returns
the m_offDelays member of the channelSpec specified by its name.
Parameters
[in]channelthe name of the channel

Definition at line 472 of file outletController.hpp.

Referenced by outletController_tests::SCENARIO().

◆ channelOffOrder()

template<class derivedT >
std::vector< size_t > MagAOX::app::dev::outletController< derivedT >::channelOffOrder ( const std::string &  channel)

Get the vector of outlet off orders for a channel.

Mainly used for testing.

Returns
the m_offOrder member of the channelSpec specified by its name.
Parameters
[in]channelthe name of the channel

Definition at line 460 of file outletController.hpp.

Referenced by outletController_tests::SCENARIO().

◆ channelOnDelays()

template<class derivedT >
std::vector< unsigned > MagAOX::app::dev::outletController< derivedT >::channelOnDelays ( const std::string &  channel)

Get the vector of outlet on delays for a channel.

Mainly used for testing.

Returns
the m_onDelays member of the channelSpec specified by its name.
Parameters
[in]channelthe name of the channel

Definition at line 466 of file outletController.hpp.

Referenced by outletController_tests::SCENARIO().

◆ channelOnOrder()

template<class derivedT >
std::vector< size_t > MagAOX::app::dev::outletController< derivedT >::channelOnOrder ( const std::string &  channel)

Get the vector of outlet on orders for a channel.

Mainly used for testing.

Returns
the m_onOrder member of the channelSpec specified by its name.
Parameters
[in]channelthe name of the channel

Definition at line 454 of file outletController.hpp.

Referenced by outletController_tests::SCENARIO().

◆ channelOutlets()

template<class derivedT >
std::vector< size_t > MagAOX::app::dev::outletController< derivedT >::channelOutlets ( const std::string &  channel)

Get the vector of outlet indices for a channel.

Mainly used for testing.

Returns
the m_outlets member of the channelSpec specified by its name.
Parameters
[in]channelthe name of the channel

Definition at line 448 of file outletController.hpp.

Referenced by outletController_tests::SCENARIO().

◆ channelState()

template<class derivedT >
int MagAOX::app::dev::outletController< derivedT >::channelState ( const std::string &  channel)

Get the state of a channel.

Returns
OUTLET_STATE_UNKNOWN if the state is not known
OUTLET_STATE_OFF if the channel is off (all outlets off)
OUTLET_STATE_INTERMEDIATE if outlets are intermediate or not in the same state
OUTLET_STATE_ON if channel is on (all outlets on)
Parameters
[in]channelthe name of the channel

Definition at line 478 of file outletController.hpp.

Referenced by outletController_tests::SCENARIO().

◆ derived()

template<class derivedT >
derivedT& MagAOX::app::dev::outletController< derivedT >::derived ( )
inlineprivate

Definition at line 294 of file outletController.hpp.

◆ loadConfig()

template<class derivedT >
int MagAOX::app::dev::outletController< derivedT >::loadConfig ( mx::app::appConfigurator &  config)

Load the [channel] sections from an application configurator.

Any "unused" section from the config parser is analyzed to determine if it is a channel specification. If it contains the outlet or outlets keyword, then it is considered a channel. outlet and outlets are equivalent, and specify the one or more device outlets included in this channel (i.e. this may be a vector value entry).

This function then looks for onOrder and offOrder keywords, which specify the order outlets are turned on or off by their indices in the vector specified by the outlet/outlets keyword (i.e not the outlet numbers).

Next it looks for onDelays and offDelays, which specify the delays between outlet operations in milliseconds. The first entry is always ignored, then the second entry specifies the delay between the first and second outlet operation, etc.

An example config file section is:

[sue]           #this channel will be named sue
outlets=4,5     #this channel uses outlets 4 and 5
onOrder=1,0     #outlet 5 will be turned on first
offOrder=0,1    #Outlet 4 will be turned off first
onDelays=0,150  #a 150 msec delay between outlet turn on
offDelays=0,345 #a 345 msec delay between outlet turn off
Returns
0 on success
-1 on failure
Todo:
test this error
Todo:
error checking on outlets
Todo:
test this error
Todo:
error checking on offOrder, should complain if not same length
Todo:
error checking on onDelays, should complain if not same length
Todo:
error checking on offDelays, should complain if not same length
Parameters
[in]configan application configuration from which to load values

Definition at line 309 of file outletController.hpp.

Referenced by MagAOX::app::acronameUsbHub::loadConfig(), MagAOX::app::trippLitePDU::loadConfig(), MagAOX::app::xt1121DCDU::loadConfig(), and outletController_tests::SCENARIO().

◆ newCallBack_channels()

template<class derivedT >
int MagAOX::app::dev::outletController< derivedT >::newCallBack_channels ( const pcf::IndiProperty &  ipRecv)

The callback called by the static version, to actually process the new request.

Returns
0 on success.
-1 on error.
Parameters
[in]ipRecvthe INDI property sent with the the new property request.

Definition at line 642 of file outletController.hpp.

◆ numChannels()

template<class derivedT >
size_t MagAOX::app::dev::outletController< derivedT >::numChannels

Get the number of channels.

Returns
the number of entries in m_channels.

Definition at line 442 of file outletController.hpp.

Referenced by outletController_tests::SCENARIO().

◆ outletState()

template<class derivedT >
int MagAOX::app::dev::outletController< derivedT >::outletState ( int  outletNum)

Get the currently stored outlet state, without updating from device.

Definition at line 424 of file outletController.hpp.

Referenced by outletController_tests::SCENARIO().

◆ setNumberOfOutlets()

template<class derivedT >
int MagAOX::app::dev::outletController< derivedT >::setNumberOfOutlets ( int  numOuts)

Sets the number of outlets. This should be called by the derived class constructor.

Returns
0 on success
-1 on failure
Parameters
[in]numOutsthe number of outlets to allocate

Definition at line 417 of file outletController.hpp.

◆ setupConfig()

template<class derivedT >
int MagAOX::app::dev::outletController< derivedT >::setupConfig ( mx::app::appConfigurator &  config)

Setup an application configurator for an outletController.

This is currently a no-op

Returns
0 on success
-1 on failure
Parameters
[in]configan application configuration to setup

Definition at line 301 of file outletController.hpp.

Referenced by outletController_tests::SCENARIO(), MagAOX::app::acronameUsbHub::setupConfig(), MagAOX::app::trippLitePDU::setupConfig(), and MagAOX::app::xt1121DCDU::setupConfig().

◆ setupINDI()

template<class derivedT >
int MagAOX::app::dev::outletController< derivedT >::setupINDI

Setup the INDI properties for this device controller.

This should be called in the appStartup function of the derived MagAOXApp.

Todo:
change this to be appStartup like other devs.
Returns
0 on success.
-1 on error.

Definition at line 687 of file outletController.hpp.

◆ st_newCallBack_channels()

template<class derivedT >
int MagAOX::app::dev::outletController< derivedT >::st_newCallBack_channels ( void *  app,
const pcf::IndiProperty &  ipRecv 
)
static

The static callback function to be registered for the channel properties.

Returns
0 on success.
-1 on error.
Parameters
[in]appa pointer to this, will be static_cast-ed to derivedT.
[in]ipRecvthe INDI property sent with the the new property request.

Definition at line 634 of file outletController.hpp.

◆ turnChannelOff()

template<class derivedT >
int MagAOX::app::dev::outletController< derivedT >::turnChannelOff ( const std::string &  channel)

Turn a channel off.

This implements the outlet order and delay logic.

Returns
0 on success.
-1 on error.
Parameters
[in]channelthe name of the channel to turn on

Definition at line 564 of file outletController.hpp.

Referenced by outletController_tests::SCENARIO().

◆ turnChannelOn()

template<class derivedT >
int MagAOX::app::dev::outletController< derivedT >::turnChannelOn ( const std::string &  channel)

Turn a channel on.

This implements the outlet order and delay logic.

Returns
0 on success.
-1 on error.
Parameters
[in]channelthe name of the channel to turn on

Definition at line 491 of file outletController.hpp.

Referenced by outletController_tests::SCENARIO().

◆ turnOutletOff()

template<class derivedT >
virtual int MagAOX::app::dev::outletController< derivedT >::turnOutletOff ( int  outletNum)
pure virtual

Turn an outlet off.

This will be implemented in derived classes to turn an outlet off.

Returns
0 on success.
-1 on error.
Parameters
[in]outletNumthe outlet number to turn off

Implemented in outletController_tests::outletControllerTest, MagAOX::app::xt1121DCDU, MagAOX::app::trippLitePDU, and MagAOX::app::acronameUsbHub.

◆ turnOutletOn()

template<class derivedT >
virtual int MagAOX::app::dev::outletController< derivedT >::turnOutletOn ( int  outletNum)
pure virtual

Turn an outlet on.

This will be implemented in derived classes to turn an outlet on.

Returns
0 on success.
-1 on error.
Parameters
[in]outletNumthe outlet number to turn on

Implemented in outletController_tests::outletControllerTest, MagAOX::app::xt1121DCDU, MagAOX::app::trippLitePDU, and MagAOX::app::acronameUsbHub.

◆ updateINDI()

template<class derivedT >
int MagAOX::app::dev::outletController< derivedT >::updateINDI

Update the INDI properties for this device controller.

You should call this after updating the outlet states. It is not called automatically.

Returns
0 on success.
-1 on error.

Definition at line 804 of file outletController.hpp.

Referenced by MagAOX::app::acronameUsbHub::appLogic(), MagAOX::app::xt1121DCDU::appLogic(), MagAOX::app::acronameUsbHub::onPowerOff(), and MagAOX::app::trippLitePDU::updateOutletStates().

◆ updateOutletState()

template<class derivedT >
virtual int MagAOX::app::dev::outletController< derivedT >::updateOutletState ( int  outletNum)
pure virtual

Get the state of the outlet from the device.

This will be implemented in derived classes to update the outlet state.

Todo:
this is declared pure virtual, but there is an implementation.
Returns
0 on success.
-1 on error.
Parameters
[in]outletNumthe outlet number to update

Implemented in outletController_tests::outletControllerTest, MagAOX::app::xt1121DCDU, MagAOX::app::trippLitePDU, and MagAOX::app::acronameUsbHub.

◆ updateOutletStates()

template<class derivedT >
int MagAOX::app::dev::outletController< derivedT >::updateOutletStates
virtual

Get the states of all outlets from the device.

The default implementation for-loops through each outlet, calling updateOutletState. Can be re-implemented in derived classes to update the outlet states.

Returns
0 on success.
-1 on error.

Reimplemented in MagAOX::app::trippLitePDU.

Definition at line 430 of file outletController.hpp.

Referenced by MagAOX::app::acronameUsbHub::appLogic().

Member Data Documentation

◆ m_channels

template<class derivedT >
std::unordered_map<std::string, channelSpec> MagAOX::app::dev::outletController< derivedT >::m_channels

The map of channel specifications, which can be accessed by their names.

Definition at line 95 of file outletController.hpp.

◆ m_firstOne

template<class derivedT >
bool MagAOX::app::dev::outletController< derivedT >::m_firstOne {false}

Flag is true if the first outlet is numbered 1, otherwise assumes starting at 0.

Definition at line 70 of file outletController.hpp.

◆ m_indiP_chOffDelays

template<class derivedT >
pcf::IndiProperty MagAOX::app::dev::outletController< derivedT >::m_indiP_chOffDelays

An INDI property which publishes the total off delay for each channel. Useful for GUIs, etc.

Definition at line 104 of file outletController.hpp.

◆ m_indiP_chOnDelays

template<class derivedT >
pcf::IndiProperty MagAOX::app::dev::outletController< derivedT >::m_indiP_chOnDelays

An INDI property which publishes the total on delay for each channel. Useful for GUIs, etc.

Definition at line 101 of file outletController.hpp.

◆ m_indiP_chOutlets

template<class derivedT >
pcf::IndiProperty MagAOX::app::dev::outletController< derivedT >::m_indiP_chOutlets

An INDI property which publishes the outlets associated with each channel. Useful for GUIs, etc.

Definition at line 98 of file outletController.hpp.

◆ m_indiP_outletStates

template<class derivedT >
pcf::IndiProperty MagAOX::app::dev::outletController< derivedT >::m_indiP_outletStates

Indi Property to show individual outlet states.

Definition at line 74 of file outletController.hpp.

◆ m_outletStates

template<class derivedT >
std::vector<int> MagAOX::app::dev::outletController< derivedT >::m_outletStates

The current states of each outlet. These MUST be updated by derived classes in the overridden updatedOutletState.

Definition at line 72 of file outletController.hpp.

Referenced by outletController_tests::SCENARIO().


The documentation for this struct was generated from the following file: