BS120x Ethernet Library 1.0.0
BS120x Ethernet Library
Loading...
Searching...
No Matches
EthernetClient Class Reference

Ethernet client for communicating with the Bloomy Controls Battery Simulator (BS120x). More...

#include <EthernetClient.h>

Detailed Description

Ethernet client for communicating with the Bloomy Controls Battery Simulator (BS120x).

This class implements commands and readbacks for all BS120x IO, as well as configuration utilities.

Public Member Functions

 EthernetClient ()
 Default constructor.
 
 EthernetClient (const EthernetClient &)=delete
 
EthernetClientoperator= (const EthernetClient &)=delete
 
 EthernetClient (EthernetClient &&other) noexcept=delete
 
EthernetClientoperator= (EthernetClient &&rhs) noexcept=delete
 
 ~EthernetClient ()
 Default destructor.
 
ErrorCode Connect (std::string_view interface_ip, std::string_view device_ip, std::uint16_t udp_port, std::int32_t udp_timeout=1000, std::uint16_t tcp_port=12345) noexcept
 Connect to a unit.
 
void Disconnect () noexcept
 Disconnect from the unit.
 
ErrorCode SetDIOStates (std::span< const bool > outputs, std::span< const bool > directions) const
 Set the output states and directions for all DIO.
 
ErrorCode SetAnalogOutputs (std::span< const float > voltages) const
 Set the voltages for the all analog outputs.
 
ErrorCode SetOpModeConfig (OpModeConfig config) const
 Configures the operating mode of the unit.
 
ErrorCode SetAllCellCurrents (float isrc, float isnk) const
 Sets the sinking and sourcing current limits for all cells.
 
ErrorCode SetCellSinkCurrent (unsigned int cell, float isnk) const
 Sets the sinking current limit for a single cell.
 
ErrorCode SetCellSourceCurrent (unsigned int cell, float isrc) const
 Sets the sourcing current limit for a cell.
 
ErrorCode SetAllCellVoltage (float voltage) const
 Sets the voltage for all cells.
 
ErrorCode SetCellVoltage (unsigned int cell, float voltage) const
 Sets the voltage for a single cell.
 
ErrorCode EnableAllCells (bool enable) const
 Enables or disables all cells.
 
ErrorCode EnableCell (unsigned int cell, bool enable) const
 Enables or disables a single cell.
 
Result< float > GetCellVoltage (unsigned int cell) const
 Gets the voltage of a cell.
 
Result< std::array< float, kCellCount > > GetAllCellVoltage () const
 Gets the voltages of all cells.
 
ErrorCode GetAllCellVoltage (std::span< float > voltages) const
 Gets the voltages of all cells.
 
Result< float > GetCellCurrent (unsigned int cell) const
 Gets the current of a cell in Amps.
 
Result< std::array< float, kCellCount > > GetAllCellCurrent () const
 Get the currents of all cells in Amps.
 
ErrorCode GetAllCellCurrent (std::span< float > currents) const
 Get the currents of all cells in Amps.
 
Result< float > GetAnalogInput (unsigned int analog_input) const
 Gets the voltage of an analog input.
 
Result< std::array< float, kAnalogInputCount > > GetAllAnalogInput () const
 Gets the voltages of all analog inputs.
 
ErrorCode GetAllAnalogInput (std::span< float > analog_inputs) const
 Gets the voltages of all analog inputs.
 
Result< bool > GetDIOState (unsigned int dio) const
 Gets the state of a DIO.
 
Result< std::array< bool, kDioCount > > GetAllDIOState () const
 Gets the states of all DIO.
 
ErrorCode GetAllDIOState (std::span< bool > states) const
 Gets the states of all DIO.
 
Result< UnitStatusGetStatus () const
 Gets the status of the unit.
 
Result< UnitConfigGetUnitConfig () const
 Gets the configuration values of a unit.
 
ErrorCode Reset () const
 Commands the unit to reset.
 
ErrorCode SetIPAddress (std::string_view ip) const
 Sets the unit IP address.
 
ErrorCode QueryConfig () const
 Sends a request to the unit for its configuration information.
 
ErrorCode SetConfigOption (std::string_view opt, int value) const
 Sets a configuration option for the unit.
 
ErrorCode SetConfigOption (std::string_view opt, bool value) const
 Sets a configuration option for the unit.
 
ErrorCode SetConfigOption (std::string_view opt, std::string_view value) const
 Sets a configuration option for the unit.
 
ErrorCode SetConfigOption (std::string_view opt, double value) const
 Sets a configuration option for the unit.
 
ErrorCode EnableUDPData (bool enable) const
 Enables the UDP data broadcast for the unit.
 
ErrorCode SetUDPDataPort (std::uint16_t port) const
 Sets the port for the unit's UDP data broadcast.
 
ErrorCode SetUDPDataPeriod (std::uint32_t period) const
 Sets the period for the unit's UDP data broadcast.
 
ErrorCode SetBoxID (std::uint8_t id) const
 Sets the unit's box id.
 
ErrorCode SetCANPeriod (std::uint32_t period) const
 Sets the period for the unit's CAN broadcast.
 
ErrorCode EnableCellInhibit (bool enable) const
 Enables or disables the cell inhibit lines.
 
Result< bool > GetConfigValueBool (std::string_view opt) const
 Get a boolean configuration value.
 
Result< int > GetConfigValueInt (std::string_view opt) const
 Get an integer configuration value.
 
Result< float > GetConfigValueFloat (std::string_view opt) const
 Get a floating point configuration value.
 
Result< std::string > GetConfigValueString (std::string_view opt) const
 Get a string configuration value.
 

Static Public Member Functions

static unsigned int Version () noexcept
 Get the library version as a decimal integer.
 

Member Function Documentation

◆ Connect()

ErrorCode Connect ( std::string_view  interface_ip,
std::string_view  device_ip,
std::uint16_t  udp_port,
std::int32_t  udp_timeout = 1000,
std::uint16_t  tcp_port = 12345 
)
noexcept

Connect to a unit.

Parameters
[in]interface_ipIP address of the local NIC to connect from.
[in]device_ipIP address of the unit.
[in]udp_portUDP data port for the unit.
[in]udp_timeoutTimeout in milliseconds to receive UDP data broadcast. A negative value will wait infinitely.
[in]tcp_portTCP port to send commands on. BS120x default is 12345.
Returns
An error code.

◆ EnableAllCells()

ErrorCode EnableAllCells ( bool  enable) const

Enables or disables all cells.

Parameters
[in]enableThe state for the cells. A value of TRUE will enable all cells.
Returns
An error code.

◆ EnableCell()

ErrorCode EnableCell ( unsigned int  cell,
bool  enable 
) const

Enables or disables a single cell.

Parameters
[in]cellThe cell to target. Cells are 0-indexed.
[in]enableThe state for the cell. A value of TRUE will enable the cell.
Returns
An error code.

◆ EnableCellInhibit()

ErrorCode EnableCellInhibit ( bool  enable) const

Enables or disables the cell inhibit lines.

Parameters
[in]enableThe enable state for the cell inhibit lines.
Returns
An error code.

◆ EnableUDPData()

ErrorCode EnableUDPData ( bool  enable) const

Enables the UDP data broadcast for the unit.

Note
Unit must be reset for changes to take effect.
Parameters
[in]enableA value of TRUE will enable the UDP data broadcast.
Returns
An error code.

◆ GetAllAnalogInput() [1/2]

Result< std::array< float, kAnalogInputCount > > GetAllAnalogInput ( ) const

Gets the voltages of all analog inputs.

Note
The BS120x unit must have UDP data broadcast enabled for this method to return valid data.
Returns
Result containing an array of voltages or an error code.

◆ GetAllAnalogInput() [2/2]

ErrorCode GetAllAnalogInput ( std::span< float >  analog_inputs) const

Gets the voltages of all analog inputs.

Note
The BS120x unit must have UDP data broadcast enabled for this method to return valid data.
Parameters
[out]analog_inputsArray to store the returned voltages. Length must be equal to the number of analog inputs.
Returns
An error code.

◆ GetAllCellCurrent() [1/2]

Result< std::array< float, kCellCount > > GetAllCellCurrent ( ) const

Get the currents of all cells in Amps.

Note
The BS120x unit must have UDP data broadcast enabled for this method to return valid data.
Returns
Result containing an array of currents or an error code.

◆ GetAllCellCurrent() [2/2]

ErrorCode GetAllCellCurrent ( std::span< float >  currents) const

Get the currents of all cells in Amps.

Note
The BS120x unit must have UDP data broadcast enabled for this method to return valid data.
Parameters
[out]currentsArray to store the returned cell currents. Length must be equal to the number of cells.
Returns
An error code.

◆ GetAllCellVoltage() [1/2]

Result< std::array< float, kCellCount > > GetAllCellVoltage ( ) const

Gets the voltages of all cells.

Note
The BS120x unit must have UDP data broadcast enabled for this method to return valid data.
Returns
Result containing an array of voltages or an error code.

◆ GetAllCellVoltage() [2/2]

ErrorCode GetAllCellVoltage ( std::span< float >  voltages) const

Gets the voltages of all cells.

Note
The BS120x unit must have UDP data broadcast enabled for this method to return valid data.
Parameters
[out]voltagesArray to store the returned cell voltages. Length must be equal to the number of cells.
Returns
An error code.

◆ GetAllDIOState() [1/2]

Result< std::array< bool, kDioCount > > GetAllDIOState ( ) const

Gets the states of all DIO.

Note
The BS120x unit must have UDP data broadcast enabled for this method to return valid data.
Returns
Result containing an array of states or an error code.

◆ GetAllDIOState() [2/2]

ErrorCode GetAllDIOState ( std::span< bool >  states) const

Gets the states of all DIO.

Note
The BS120x unit must have UDP data broadcast enabled for this method to return valid data.
Parameters
[out]statesArray to store the returned states. Length must be equal to the number of DIO.
Returns
An error code.

◆ GetAnalogInput()

Result< float > GetAnalogInput ( unsigned int  analog_input) const

Gets the voltage of an analog input.

Note
The BS120x unit must have UDP data broadcast enabled for this method to return valid data.
Parameters
[in]analog_inputThe analog input to target.
Returns
Result containing a voltage or an error code.

◆ GetCellCurrent()

Result< float > GetCellCurrent ( unsigned int  cell) const

Gets the current of a cell in Amps.

Note
The BS120x unit must have UDP data broadcast enabled for this method to return valid data.
Parameters
[in]cellThe cell to target. Cells are 0-indexed.
Returns
Result containing the current or an error code.

◆ GetCellVoltage()

Result< float > GetCellVoltage ( unsigned int  cell) const

Gets the voltage of a cell.

Note
The BS120x unit must have UDP data broadcast enabled for this method to return valid data.
Parameters
[in]cellThe cell to target. Cells are 0-indexed.
Returns
Result containing the cell voltage or an error code.

◆ GetConfigValueBool()

Result< bool > GetConfigValueBool ( std::string_view  opt) const

Get a boolean configuration value.

Note
QueryConfig must be called prior to calling this method.
Parameters
[in]optThe configuration option to look up.
Returns
Result containing the value or an error code.

◆ GetConfigValueFloat()

Result< float > GetConfigValueFloat ( std::string_view  opt) const

Get a floating point configuration value.

Note
QueryConfig must be called prior to calling this method.
Parameters
[in]optThe configuration option to look up.
Returns
Result containing the value or an error code.

◆ GetConfigValueInt()

Result< int > GetConfigValueInt ( std::string_view  opt) const

Get an integer configuration value.

Note
QueryConfig must be called prior to calling this method.
Parameters
[in]optThe configuration option to look up.
Returns
Result containing the value or an error code.

◆ GetConfigValueString()

Result< std::string > GetConfigValueString ( std::string_view  opt) const

Get a string configuration value.

Note
QueryConfig must be called prior to calling this method.
Parameters
[in]optThe configuration option to look up.
Returns
Result containing the value or an error code.

◆ GetDIOState()

Result< bool > GetDIOState ( unsigned int  dio) const

Gets the state of a DIO.

Note
The BS120x unit must have UDP data broadcast enabled for this method to return valid data.
Parameters
[in]dioThe DIO to target.
Returns
Result containing a state or an error code.

◆ GetStatus()

Result< UnitStatus > GetStatus ( ) const

Gets the status of the unit.

Note
The BS120x unit must have UDP data broadcast enabled for this method to return valid data.
Returns
Result containing a UnitStatus structure or an error code.

◆ GetUnitConfig()

Result< UnitConfig > GetUnitConfig ( ) const

Gets the configuration values of a unit.

Note
QueryConfig must be called prior to calling this method.
Returns
Result containing a UnitConfig structure or an error code.

◆ QueryConfig()

ErrorCode QueryConfig ( ) const

Sends a request to the unit for its configuration information.

Returns
An error code.

◆ Reset()

ErrorCode Reset ( ) const

Commands the unit to reset.

Note
Disconnect and Connect must be called after this method to re-establish a connection with the unit.
Returns
An error code.

◆ SetAllCellCurrents()

ErrorCode SetAllCellCurrents ( float  isrc,
float  isnk 
) const

Sets the sinking and sourcing current limits for all cells.

Parameters
[in]isrcThe sourcing current limit in Amps.
[in]isnkThe sinking current limit in Amps.
Returns
An error code.

◆ SetAllCellVoltage()

ErrorCode SetAllCellVoltage ( float  voltage) const

Sets the voltage for all cells.

Parameters
[in]voltageThe voltage setpoint.
Returns
An error code.

◆ SetAnalogOutputs()

ErrorCode SetAnalogOutputs ( std::span< const float >  voltages) const

Set the voltages for the all analog outputs.

Parameters
[in]voltagesThe voltage setpoints for the analog outputs. Must have a length equal to the number of unit analog outputs.
Returns
An error code.

◆ SetBoxID()

ErrorCode SetBoxID ( std::uint8_t  id) const

Sets the unit's box id.

Note
Unit must be reset for changes to take effect.
Parameters
[in]idThe new box ID. Valid values are 0-15.
Returns
An error code.

◆ SetCANPeriod()

ErrorCode SetCANPeriod ( std::uint32_t  period) const

Sets the period for the unit's CAN broadcast.

Note
Unit must be reset for changes to take effect.
Parameters
[in]periodThe new period in milliseconds.
Returns
An error code.

◆ SetCellSinkCurrent()

ErrorCode SetCellSinkCurrent ( unsigned int  cell,
float  isnk 
) const

Sets the sinking current limit for a single cell.

Parameters
[in]cellThe cell to target. Cells are 0-indexed.
[in]isnkThe sinking current limit in Amps for the cell.
Returns
An error code.

◆ SetCellSourceCurrent()

ErrorCode SetCellSourceCurrent ( unsigned int  cell,
float  isrc 
) const

Sets the sourcing current limit for a cell.

Parameters
[in]cellThe cell to target. Cells are 0-indexed.
[in]isrcThe sourcing current limit in Amps for the cell.
Returns
An error code.

◆ SetCellVoltage()

ErrorCode SetCellVoltage ( unsigned int  cell,
float  voltage 
) const

Sets the voltage for a single cell.

Parameters
[in]cellThe cell to target. Cells are 0-indexed.
[in]voltageThe voltage setpoint.
Returns
An error code.

◆ SetConfigOption() [1/4]

ErrorCode SetConfigOption ( std::string_view  opt,
bool  value 
) const

Sets a configuration option for the unit.

Note
Unit must be reset for changes to take effect.
Parameters
[in]optThe configuration option to set.
[in]valueThe value to set the configuration option to.
Returns
An error code.

◆ SetConfigOption() [2/4]

ErrorCode SetConfigOption ( std::string_view  opt,
double  value 
) const

Sets a configuration option for the unit.

Note
Unit must be reset for changes to take effect.
Parameters
[in]optThe configuration option to set.
[in]valueThe value to set the configuration option to.
Returns
An error code.

◆ SetConfigOption() [3/4]

ErrorCode SetConfigOption ( std::string_view  opt,
int  value 
) const

Sets a configuration option for the unit.

Note
Unit must be reset for changes to take effect.
Parameters
[in]optThe configuration option to set.
[in]valueThe value to set the configuration option to.
Returns
An error code.

◆ SetConfigOption() [4/4]

ErrorCode SetConfigOption ( std::string_view  opt,
std::string_view  value 
) const

Sets a configuration option for the unit.

Note
Unit must be reset for changes to take effect.
Parameters
[in]optThe configuration option to set.
[in]valueThe value to set the configuration option to.
Returns
An error code.

◆ SetDIOStates()

ErrorCode SetDIOStates ( std::span< const bool >  outputs,
std::span< const bool >  directions 
) const

Set the output states and directions for all DIO.

Parameters
[in]outputsThe output states for the DIO. Must have a length equal to the number of unit DIO. A TRUE value corresponds to a HIGH output.
[in]directionsThe directions for the DIO. Must have a length equal to the number of unit DIO. A TRUE value corresponds to an output.
Returns
An error code.

◆ SetIPAddress()

ErrorCode SetIPAddress ( std::string_view  ip) const

Sets the unit IP address.

Note
Unit must be reset for changes to take effect.
Parameters
[in]ipNew IP address for the unit. Last octet may not have a value of 1 or 255.
Returns
An error code.

◆ SetOpModeConfig()

ErrorCode SetOpModeConfig ( OpModeConfig  config) const

Configures the operating mode of the unit.

Parameters
[in]configThe operating mode options to set.
Returns
An error code.

◆ SetUDPDataPeriod()

ErrorCode SetUDPDataPeriod ( std::uint32_t  period) const

Sets the period for the unit's UDP data broadcast.

Note
Unit must be reset for changes to take effect.
Parameters
[in]periodThe new period in milliseconds.
Returns
An error code.

◆ SetUDPDataPort()

ErrorCode SetUDPDataPort ( std::uint16_t  port) const

Sets the port for the unit's UDP data broadcast.

Note
Unit must be reset for changes to take effect.
Parameters
[in]portThe new UDP port.
Returns
An error code.

◆ Version()

static unsigned int Version ( )
staticnoexcept

Get the library version as a decimal integer.

For example, version 1.3.2 would return 10302.

Returns
Library version.

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