Provides an interface for communicating with a opendss simulation model.
More...
#include <COpenDssAdapter.hpp>
|
| 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...
|
|
|
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 const unsigned int | BUFFER_SIZE = 1024 |
| buffer size in bytes of the simulation packet More...
|
|
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.
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
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
-
v | The 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
-
device | The unique identifier of a physical device. |
signal | A 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
-
device | The unique identifier of the device to register. |
signal | The signal of the device that will be registered. |
index | The 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
-
devid | The 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
-
device | The unique identifier of the device to register. |
signal | The signal of the device that will be registered. |
index | The 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
-
buffer | the data to be reversed |
numBytes | the 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
-
device | The unique identifier of a physical device. |
signal | A power electronic reading related to the device. |
value | The 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.
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:
- /home/docs/checkouts/readthedocs.org/user_builds/freedm/checkouts/latest/Broker/src/device/COpenDssAdapter.hpp
- /home/docs/checkouts/readthedocs.org/user_builds/freedm/checkouts/latest/Broker/src/device/COpenDssAdapter.cpp