FREEDM DGI
COpenDssAdapter.hpp
Go to the documentation of this file.
1 
26 #ifndef C_OPENDSS_ADAPTER_HPP
27 #define C_OPENDSS_ADAPTER_HPP
28 
29 #include "IBufferAdapter.hpp"
30 
31 #include <boost/enable_shared_from_this.hpp>
32 #include <boost/shared_ptr.hpp>
33 #include <boost/asio/io_service.hpp>
34 #include <boost/asio/ip/tcp.hpp>
35 #include <boost/asio/deadline_timer.hpp>
36 #include <boost/property_tree/ptree_fwd.hpp>
37 
38 namespace freedm {
39  namespace broker {
40  namespace device {
41 
53  : public IBufferAdapter
54  , public boost::enable_shared_from_this<COpenDssAdapter>
55  {
56  public:
58  typedef boost::shared_ptr<COpenDssAdapter> Pointer;
59 
61  static IAdapter::Pointer Create(boost::asio::io_service & service,
62  const boost::property_tree::ptree & ptree);
63 
65  void Start();
66 
68  void Stop();
69 
72 
74  static void sendCommand(std::string command);
75 
76  private:
78  COpenDssAdapter(boost::asio::io_service & service,
79  const boost::property_tree::ptree & ptree);
80 
82  void Run(const boost::system::error_code & e);
83 
85  void ReverseBytes( char * buffer, const int numBytes );
86 
88  void EndianSwapIfNeeded(std::vector<SignalValue> & v);
89 
91  void Connect();
92 
94  boost::asio::deadline_timer m_runTimer;
95 
97  mutable boost::asio::ip::tcp::socket m_socket;
98 
100  std::string m_host;
101 
103  std::string m_port;
104 
106  static const unsigned int BUFFER_SIZE = 1024;
107  public:
109  static unsigned int sd,n;
110 
111  //carries data received or data to be sent
112  static char buffer[BUFFER_SIZE];
113 
115  static std::string openDss_data;
116 
117  public:
118  static std::string GetData();
119  };
120 
121  } //namespace device
122  } //namespace broker
123 } //namespace freedm
124 
125 #endif // C_RTDS_ADAPTER_HPP
static std::string openDss_data
variable to hold opendss data
Definition: COpenDssAdapter.hpp:115
COpenDssAdapter(boost::asio::io_service &service, const boost::property_tree::ptree &ptree)
Constructor.
Definition: COpenDssAdapter.cpp:104
std::string m_host
The hostname of the remote host.
Definition: COpenDssAdapter.hpp:100
boost::asio::deadline_timer m_runTimer
Timer object to set communication cycle pace.
Definition: COpenDssAdapter.hpp:94
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.
Definition: COpenDssAdapter.cpp:86
void Run(const boost::system::error_code &e)
Continuous loop for sending and receiving to/from opendss.
Definition: COpenDssAdapter.cpp:152
static char buffer[BUFFER_SIZE]
Definition: COpenDssAdapter.hpp:112
static unsigned int sd
socket desciptor and int n for error handling
Definition: COpenDssAdapter.hpp:109
static std::string GetData()
Definition: COpenDssAdapter.cpp:187
static void sendCommand(std::string command)
send commands
Definition: COpenDssAdapter.cpp:225
static unsigned int n
Definition: COpenDssAdapter.hpp:109
boost::shared_ptr< COpenDssAdapter > Pointer
Pointer to an COpenDssAdapter object.
Definition: COpenDssAdapter.hpp:58
~COpenDssAdapter()
Destructor.
Definition: COpenDssAdapter.cpp:244
void Start()
Starts the adapter.
Definition: COpenDssAdapter.cpp:122
void ReverseBytes(char *buffer, const int numBytes)
Reverses all of the bytes in a buffer.
Definition: COpenDssAdapter.cpp:259
static const unsigned int BUFFER_SIZE
buffer size in bytes of the simulation packet
Definition: COpenDssAdapter.hpp:106
boost::asio::ip::tcp::socket m_socket
Socket to use for the TCP connection.
Definition: COpenDssAdapter.hpp:97
Buffer adapter device interface.
Definition: IBufferAdapter.hpp:47
std::string m_port
The port number of the remote host.
Definition: COpenDssAdapter.hpp:103
void Connect()
Creates a socket connection to the given hostname and port number.
Definition: COpenDssAdapter.cpp:313
void EndianSwapIfNeeded(std::vector< SignalValue > &v)
Swaps the endianness of all SignalValues in a vector.
Definition: COpenDssAdapter.cpp:283
void Stop()
Shut down communication to FPGA.
Definition: COpenDssAdapter.cpp:199
General FREEDM Namespace.
Definition: CBroker.cpp:53
Provides an interface for communicating with a opendss simulation model.
Definition: COpenDssAdapter.hpp:52
boost::shared_ptr< IAdapter > Pointer
Pointer to a physical adapter.
Definition: IAdapter.hpp:72