FREEDM DGI
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
freedm::broker::device::COpenDssAdapter Class Reference

Provides an interface for communicating with a opendss simulation model. More...

#include <COpenDssAdapter.hpp>

Inheritance diagram for freedm::broker::device::COpenDssAdapter:
freedm::broker::device::IBufferAdapter freedm::broker::device::IAdapter

Public Types

typedef boost::shared_ptr< COpenDssAdapterPointer
 Pointer to an COpenDssAdapter object. More...
 

Public Member Functions

 ~COpenDssAdapter ()
 Destructor. More...
 
std::set< std::string > GetDevices () const
 Get the list of registered device names. More...
 
SignalValue GetState (const std::string device, const std::string signal) const
 Retrieve data from rxBuffer. More...
 
void RegisterCommandInfo (const std::string device, const std::string signal, const std::size_t index)
 Registers a new device signal with the physical adapter. More...
 
void RegisterDevice (const std::string devid)
 Register a device name with the adapter. More...
 
void RegisterStateInfo (const std::string device, const std::string signal, const std::size_t index)
 Registers a new device signal with the physical adapter. More...
 
void SetCommand (const std::string device, const std::string signal, const SignalValue value)
 Set data in txBuffer. More...
 
void Start ()
 Starts the adapter. More...
 
void Stop ()
 Shut down communication to FPGA. More...
 

Static Public Member Functions

static IAdapter::Pointer Create (boost::asio::io_service &service, const boost::property_tree::ptree &ptree)
 Create a COpenDssAdapter object and returns a pointer to it. More...
 
static std::string GetData ()
 
static void sendCommand (std::string command)
 send commands More...
 

Static Public Attributes

static char buffer [BUFFER_SIZE] = ""
 
static unsigned int n = -1
 
static std::string openDss_data = ""
 variable to hold opendss data More...
 
static unsigned int sd = -1
 socket desciptor and int n for error handling More...
 

Protected Member Functions

void RevealDevices ()
 Reveals devices in the device manager. More...
 

Protected Attributes

bool m_buffer_initialized
 Flag that indicates whether the buffer is NaN. More...
 
std::map< const DeviceSignal, const std::size_t > m_commandInfo
 Translates a device signal into its txBuffer (command) index. More...
 
std::vector< SignalValuem_rxBuffer
 The "state table" buffer received from the external host. More...
 
boost::shared_mutex m_rxMutex
 Provides synchronization for m_rxBuffer. More...
 
std::map< const DeviceSignal, const std::size_t > m_stateInfo
 Translates a device signal into its rxBuffer (state) index. More...
 
std::vector< SignalValuem_txBuffer
 The "command table" buffer sent to the external host. More...
 
boost::shared_mutex m_txMutex
 Provides synchronization for m_txBuffer. More...
 

Private Member Functions

 COpenDssAdapter (boost::asio::io_service &service, const boost::property_tree::ptree &ptree)
 Constructor. More...
 
void Connect ()
 Creates a socket connection to the given hostname and port number. More...
 
void EndianSwapIfNeeded (std::vector< SignalValue > &v)
 Swaps the endianness of all SignalValues in a vector. More...
 
void ReverseBytes (char *buffer, const int numBytes)
 Reverses all of the bytes in a buffer. More...
 
void Run (const boost::system::error_code &e)
 Continuous loop for sending and receiving to/from opendss. More...
 

Private Attributes

std::string m_host
 The hostname of the remote host. More...
 
std::string m_port
 The port number of the remote host. More...
 
boost::asio::deadline_timer m_runTimer
 Timer object to set communication cycle pace. More...
 
boost::asio::ip::tcp::socket m_socket
 Socket to use for the TCP connection. More...
 

Static Private Attributes

static const unsigned int BUFFER_SIZE = 1024
 buffer size in bytes of the simulation packet More...
 

Detailed Description

This class handles communications to and from the opendss simulation model via a device server. It serves as client to the server, retrieving values from and transmitting commands to the opendss application.

Limitations:
Subject to improvement.

Member Typedef Documentation

Constructor & Destructor Documentation

freedm::broker::device::COpenDssAdapter::~COpenDssAdapter ( )

Closes the socket before destroying an object instance.

Precondition:
None.
Postcondition:
Closes m_socket.
Limitations:
None.
freedm::broker::device::COpenDssAdapter::COpenDssAdapter ( boost::asio::io_service &  io_service,
const boost::property_tree::ptree &  ptree 
)
private

Constructs an Opendss client.

Shared Memory Blocks:
Uses the passed io_service.
Precondition:
None.
Postcondition:
COpenDssAdapter created.
Limitations:
None

Member Function Documentation

void freedm::broker::device::COpenDssAdapter::Connect ( )
private

Creates a TCP socket connection to the adapter's target host and port.

Error Handling:
Throws a std::runtime_error for connection errors.
Precondition:
hostname and service specify a valid endpoint.
Postcondition:
m_socket is connected to the passed service.
Limitations:
None.
IAdapter::Pointer freedm::broker::device::COpenDssAdapter::Create ( boost::asio::io_service &  service,
const boost::property_tree::ptree &  ptree 
)
static

Creates an Opendss client on the given io_service.

Shared Memory Blocks:
Uses the passed io_service
Precondition:
None.
Postcondition:
COpenDssAdapter object is returned for use.
Returns
Shared pointer to the new COpenDssAdapter object.
Limitations:
None
void freedm::broker::device::COpenDssAdapter::EndianSwapIfNeeded ( std::vector< SignalValue > &  v)
private

Converts the SignalValues in the passed vector from big-endian to little-endian, or vice-versa, if the DGI is running on a little-endian system.

Precondition:
None.
Postcondition:
The elements of data are converted in endianness if the DGI is running on a little-endian system. Otherwise, nothing happens.
Parameters
vThe vector of SignalValues to be endian-swapped.
Limitations:
Assumes the existence of UNIX byte order macros.
std::string freedm::broker::device::COpenDssAdapter::GetData ( )
static

gets openDss data

Limitations:
None.
std::set< std::string > freedm::broker::device::IAdapter::GetDevices ( ) const
inherited

Accessor function for the registered device set.

Precondition:
None.
Postcondition:
Returns m_devices.
Returns
A set of device identifiers.
Limitations:
None.
SignalValue freedm::broker::device::IBufferAdapter::GetState ( const std::string  device,
const std::string  signal 
) const
virtualinherited

Read the specified value from the rxBuffer.

Error Handling:
Throws std::exception if the value cannot be found.
Precondition:
The passed signal must be recognized by the adapter.
Postcondition:
Returns the value of the signal stored in m_rxBuffer.
Parameters
deviceThe unique identifier of a physical device.
signalA power electronic reading related to the device.
Returns
SignalValue from the rxBuffer.
Limitations:
None.

Implements freedm::broker::device::IAdapter.

void freedm::broker::device::IBufferAdapter::RegisterCommandInfo ( const std::string  device,
const std::string  signal,
const std::size_t  index 
)
inherited

Registers a new device signal as command information with the adapter.

Error Handling:
Throws a std::runtime_error if the device signal is invalid or already registered with the adapter.
Precondition:
The parameters must not be empty.
Precondition:
The device signal must not already be registered.
Precondition:
The index must not be registered with another signal.
Postcondition:
m_commandInfo is updated to store the new device signal.
Parameters
deviceThe unique identifier of the device to register.
signalThe signal of the device that will be registered.
indexThe numeric index associated with the device signal.
Limitations:
None.
void freedm::broker::device::IAdapter::RegisterDevice ( const std::string  devid)
inherited

Adds a device name to the registered device set.

Precondition:
None.
Postcondition:
Inserts the device name into m_devices.
Parameters
devidThe name of the device to register.
Limitations:
None.
void freedm::broker::device::IBufferAdapter::RegisterStateInfo ( const std::string  device,
const std::string  signal,
const std::size_t  index 
)
inherited

Registers a new device signal as state information with the adapter.

Error Handling:
Throws a std::runtime_error if the device signal is invalid or already registered with the adapter.
Precondition:
The parameters must not be empty.
Precondition:
The device signal must not already be registered.
Precondition:
The index must not be registered with another signal.
Postcondition:
m_stateInfo is updated to store the new device signal.
Parameters
deviceThe unique identifier of the device to register.
signalThe signal of the device that will be registered.
indexThe numeric index associated with the device signal.
Limitations:
None.
void freedm::broker::device::IAdapter::RevealDevices ( )
protectedinherited

Reveals the associated devices in the device manager.

Precondition:
No prior call has been made to this function.
Postcondition:
Calls CDeviceManger::RevealDevice for each known device.
Limitations:
This function can be called at most once.
void freedm::broker::device::COpenDssAdapter::ReverseBytes ( char *  buffer,
const int  numBytes 
)
private

A utility function for converting byte order from big endian to little endian and vice versa. This needs to be called on a SINGLE WORD of the data since it actually just reverses the bytes.

Precondition:
None
Postcondition:
The bytes in the buffer are now reversed
Parameters
bufferthe data to be reversed
numBytesthe number of bytes in the buffer
void freedm::broker::device::COpenDssAdapter::Run ( const boost::system::error_code &  e)
private
void freedm::broker::device::COpenDssAdapter::sendCommand ( std::string  command)
static

Sends a command to an openDss device

Precondition:
connection with a device
Postcondition:
command sent to an openDss device
Limitations:
Still under construction.
void freedm::broker::device::IBufferAdapter::SetCommand ( const std::string  device,
const std::string  signal,
const SignalValue  value 
)
virtualinherited

Update the specified value in the txBuffer.

Error Handling:
Throws std::exception if the value cannot be found.
Precondition:
The passed signal must be recognized by the adapter.
Postcondition:
Updates the value of the signal in m_txBuffer.
Parameters
deviceThe unique identifier of a physical device.
signalA power electronic reading related to the device.
valueThe desired new value for the device signal.
Limitations:
None.

Implements freedm::broker::device::IAdapter.

void freedm::broker::device::COpenDssAdapter::Start ( )
virtual

Starts sending and receiving data with the adapter.

Precondition:
The adapter has not yet been started.
Postcondition:
COpenDssAdapter::Run is called to start the adapter.
Limitations:
All devices must be added to the adapter before this call.

Implements freedm::broker::device::IAdapter.

void freedm::broker::device::COpenDssAdapter::Stop ( )
virtual

Stops the adapter. Thread-safe.

Precondition:
None.
Postcondition:
Adapter is stopped and can be freed
Limitations:
None.

Implements freedm::broker::device::IAdapter.

Member Data Documentation

char freedm::broker::device::COpenDssAdapter::buffer = ""
static
const unsigned int freedm::broker::device::COpenDssAdapter::BUFFER_SIZE = 1024
staticprivate
bool freedm::broker::device::IBufferAdapter::m_buffer_initialized
protectedinherited
std::map<const DeviceSignal, const std::size_t> freedm::broker::device::IBufferAdapter::m_commandInfo
protectedinherited
std::string freedm::broker::device::COpenDssAdapter::m_host
private
std::string freedm::broker::device::COpenDssAdapter::m_port
private
boost::asio::deadline_timer freedm::broker::device::COpenDssAdapter::m_runTimer
private
std::vector<SignalValue> freedm::broker::device::IBufferAdapter::m_rxBuffer
protectedinherited
boost::shared_mutex freedm::broker::device::IBufferAdapter::m_rxMutex
mutableprotectedinherited
boost::asio::ip::tcp::socket freedm::broker::device::COpenDssAdapter::m_socket
mutableprivate
std::map<const DeviceSignal, const std::size_t> freedm::broker::device::IBufferAdapter::m_stateInfo
protectedinherited
std::vector<SignalValue> freedm::broker::device::IBufferAdapter::m_txBuffer
protectedinherited
boost::shared_mutex freedm::broker::device::IBufferAdapter::m_txMutex
mutableprotectedinherited
unsigned int freedm::broker::device::COpenDssAdapter::n = -1
static
std::string freedm::broker::device::COpenDssAdapter::openDss_data = ""
static

This is the main communication engine.

Device I/O:
Opendss csv data
Error Handling:
Throws std::runtime_error if reading from or writing to socket fails.
Precondition:
Connection with FPGA is established.
Postcondition:
All values in the receive buffer are sent to the FPGA. All values in the send buffer are updated with data from the FPGA.
Limitations:
This function uses synchronous communication.
unsigned int freedm::broker::device::COpenDssAdapter::sd = -1
static

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