FREEDM DGI
CRtdsAdapter.hpp
Go to the documentation of this file.
1 
26 #ifndef C_RTDS_ADAPTER_HPP
27 #define C_RTDS_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 
57  : public IBufferAdapter
58  , public boost::enable_shared_from_this<CRtdsAdapter>
59 {
60 public:
62  typedef boost::shared_ptr<CRtdsAdapter> Pointer;
63 
65  static IAdapter::Pointer Create(boost::asio::io_service & service,
66  const boost::property_tree::ptree & ptree);
67 
69  void Start();
70 
72  void Stop();
73 
75  ~CRtdsAdapter();
76 
77 private:
79  CRtdsAdapter(boost::asio::io_service & service,
80  const boost::property_tree::ptree & ptree);
81 
83  void Run(const boost::system::error_code & e);
84 
86  void ReverseBytes( char * buffer, const int numBytes );
87 
89  void EndianSwapIfNeeded(std::vector<SignalValue> & v);
90 
92  void Connect();
93 
95  boost::asio::deadline_timer m_runTimer;
96 
98  mutable boost::asio::ip::tcp::socket m_socket;
99 
101  std::string m_host;
102 
104  std::string m_port;
105 };
106 
107 } //namespace device
108 } //namespace broker
109 } //namespace freedm
110 
111 #endif // C_RTDS_ADAPTER_HPP
void Run(const boost::system::error_code &e)
Continuous loop for sending and receiving to/from RTDS.
Definition: CRtdsAdapter.cpp:158
boost::asio::deadline_timer m_runTimer
Timer object to set communication cycle pace.
Definition: CRtdsAdapter.hpp:95
std::string m_port
The port number of the remote host.
Definition: CRtdsAdapter.hpp:104
void EndianSwapIfNeeded(std::vector< SignalValue > &v)
Swaps the endianness of all SignalValues in a vector.
Definition: CRtdsAdapter.cpp:325
~CRtdsAdapter()
Destructor.
Definition: CRtdsAdapter.cpp:286
static IAdapter::Pointer Create(boost::asio::io_service &service, const boost::property_tree::ptree &ptree)
Create a CRtdsAdapter object and returns a pointer to it.
Definition: CRtdsAdapter.cpp:85
boost::asio::ip::tcp::socket m_socket
Socket to use for the TCP connection.
Definition: CRtdsAdapter.hpp:98
Provides an interface for communicating with a RTDS simulation model.
Definition: CRtdsAdapter.hpp:56
void Stop()
Shut down communication to FPGA.
Definition: CRtdsAdapter.cpp:259
std::string m_host
The hostname of the remote host.
Definition: CRtdsAdapter.hpp:101
Buffer adapter device interface.
Definition: IBufferAdapter.hpp:47
boost::shared_ptr< CRtdsAdapter > Pointer
Pointer to an CRtdsAdapter object.
Definition: CRtdsAdapter.hpp:62
void Start()
Starts the adapter.
Definition: CRtdsAdapter.cpp:123
General FREEDM Namespace.
Definition: CBroker.cpp:53
void ReverseBytes(char *buffer, const int numBytes)
Reverses all of the bytes in a buffer.
Definition: CRtdsAdapter.cpp:301
void Connect()
Creates a socket connection to the given hostname and port number.
Definition: CRtdsAdapter.cpp:355
CRtdsAdapter(boost::asio::io_service &service, const boost::property_tree::ptree &ptree)
Constructor.
Definition: CRtdsAdapter.cpp:105
boost::shared_ptr< IAdapter > Pointer
Pointer to a physical adapter.
Definition: IAdapter.hpp:72