Commit 2760b4b1 by Heitbrink, David A

$updated documentation

parent 9975ba72
#include "stdafx.h"
#include ".\include\NadsDDSLib\DDSSimClient.h"
#include "apex_memmove.h"
namespace NDDSClient {
using namespace std;
CCellInputMap::CCellInputMap() {}
......@@ -15,6 +15,15 @@ namespace NDDSClient {
_cellsIn[name] = std::move(ref);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \fn void CCellInputMap::ReadInputElements()
///
/// \brief Memswap between registered cells, and user variables.
///
/// \author Simop
/// \date 4/30/2019
////////////////////////////////////////////////////////////////////////////////////////////////////
void CCellInputMap::ReadInputElements() {
for (auto& cell : _cellsIn) {
auto& cellIn = cell.second;
......@@ -22,11 +31,28 @@ namespace NDDSClient {
size_t size = cellIn->_sub->GetSizeInByes();
if (cellIn->_size == size) {
void* ptr = cellIn->_sub->GetRaw();
memcpy(cellIn->_target, ptr, size);
apex::memcpy(cellIn->_target, ptr, size);
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \fn void CCellOutputMap::RegInpElem(std::string name, void *_pBuffer, const unsigned int _BufferSize, char _BufferType)
///
/// \brief Registers the inp element
///
/// Registers the DDS subscription, and saves the reference to user variable, when ReadInputElements this will
/// copy the data from the registered user varaible to the publication.
///
/// \author Simop
/// \date 4/30/2019
///
/// \param name The name.
/// \param [in,out] _pBuffer If non-null, the buffer.
/// \param _BufferSize Size of the buffer.
/// \param _BufferType Type of the buffer.
////////////////////////////////////////////////////////////////////////////////////////////////////
void CCellOutputMap::RegInpElem(std::string name, void *_pBuffer, const unsigned int _BufferSize, char _BufferType) {
TCellRef ref = std::make_unique<CellOutput>();
size_t elementSize = 0;
......@@ -96,11 +122,30 @@ namespace NDDSClient {
void DDSSimClient::RegOutputCell(const std::string& name, void* pnt, size_t size, char type) {
_omap.RegInpElem(name, pnt, size, type);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \fn DDSSimClient::TRef DDSSimClient::Make(TFrameCBRef frame, TStartCBRef startup)
///
/// \brief Makes DDSSimClient + does startup sequence
/// If this sim is operating you should be getting callback - only call this when you are
/// ready for the CBs
///
/// \author Simop
/// \date 4/26/2019
///
/// \param frame The frame.
/// \param startup The startup.
///
/// \returns A DDSSimClient::TRef.
////////////////////////////////////////////////////////////////////////////////////////////////////
DDSSimClient::TRef DDSSimClient::Make(TFrameCBRef frame, TStartCBRef startup) {
auto ptr = std::make_shared<DDSSimClient>();
//this most likely should use a proxy obj so we can use make_shared
auto ptr = DDSSimClient::TRef(new DDSSimClient());
ptr->RegisterFrameCB(frame);
ptr->RegisterStartup(startup);
ptr->StartUp();
ptr->_dds_state.Register(ptr);
return ptr;
}
}
\ No newline at end of file
......@@ -3,6 +3,13 @@
#include <NadsDDSLib/NadsDDSLib.h>
#include <Windows.h>
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \namespace NDDSClient
///
/// \brief Helper client classes for doing DDS/Gateway interface
////////////////////////////////////////////////////////////////////////////////////////////////////
namespace NDDSClient {
class CellInput {
public:
......@@ -11,6 +18,16 @@ namespace NDDSClient {
char _type;
NADSDDS::CSubscription::TRef _sub;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \class CCellInputMap
///
/// \brief Map of cell inputs.
///
/// \author Simop
/// \date 4/26/2019
////////////////////////////////////////////////////////////////////////////////////////////////////
class CCellInputMap {
public:
CCellInputMap();
......@@ -28,6 +45,14 @@ namespace NDDSClient {
NADSDDS::CPublication::TRef _sub;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \class CCellOutputMap
///
/// \brief Holds Map of cell outputs.
/// Back end is a signlton, this can be used outside of DDSSimClient
/// \author Simop
/// \date 4/26/2019
////////////////////////////////////////////////////////////////////////////////////////////////////
class CCellOutputMap {
public:
......@@ -39,6 +64,15 @@ namespace NDDSClient {
std::map<std::string, TCellRef> _cellsOut;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \class DDSSimClient
///
/// \brief The DDS simulation client.
///
/// \author Simop
/// \date 4/26/2019
////////////////////////////////////////////////////////////////////////////////////////////////////
class DDSSimClient : public NADSDDS::CState::Callback {
public:
NADSDDS::CPublication::TRef _HeartBeat;
......@@ -55,6 +89,14 @@ namespace NDDSClient {
typedef std::shared_ptr<StartUpCB> TStartCBRef;
typedef std::weak_ptr<StartUpCB> TStartCBWRef;
template<class T> class StartUpC : public StartUpCB {
public:
StartUpC(T* par) :_par(par) {}
virtual void Startup(DDSSimClient& core) override{
_par->Startup(core);
}
T* _par;
};
void RegisterStartup(TStartCBRef);
class FrameCB {
......@@ -64,6 +106,33 @@ namespace NDDSClient {
};
typedef std::shared_ptr<FrameCB> TFrameCBRef;
typedef std::weak_ptr<FrameCB> TFrameCBWRef;
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \class Frame
///
/// \brief Template for receiving frame callbacks.
/// use example:
///
/// DDSSimClient::Ref client;
/// TFrameCBRef keep = TFrameCBRef(new DDSSimClient::Frame<MyClass>(this));
/// client->RegisterFrameCB(keep);
///
/// \author Simop
/// \date 4/26/2019
///
/// \typeparam T Host class to receive the callback.
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class T> class NewFrame : public FrameCB {
public:
NewFrame(T* par) :_par(par) {}
virtual int Frame(DDSSimClient& core, int state, int frameNum) override {
return _par->Frame(core,state,frameNum);
}
T* _par;
};
void RegisterFrameCB(TFrameCBRef);
virtual void OnFrame(int frame);
static TRef Make(TFrameCBRef, TStartCBRef);
......
......@@ -25,9 +25,30 @@
#include <thread>
#include <mutex>
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \namespace NADSDDS
///
/// \brief Namespace for Dealing DDS based communications
////////////////////////////////////////////////////////////////////////////////////////////////////
namespace NADSDDS {
using namespace std;
using namespace dds::all;
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \class CellPub
///
/// \brief Publication for Cell
///
/// This class handles the buffering scheme for DDS it holds a current value buffer
/// and the topic and writer
///
/// \author Simop
/// \date 4/29/2019
///
/// \tparam T DDS type, this comes from the DDS code generation
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class T> class CellPub : public CellRoot {
public:
CellPub(std::string name, dds::domain::DomainParticipant& dm, size_t size, int id) :
......@@ -70,6 +91,17 @@ namespace NADSDDS {
DDSDomainRepo();
};
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \class DDSTopicInfo
///
/// \brief Information about the DDS topic.
///
/// A topic is basically a availible subscription.
///
/// \author Simop
/// \date 4/29/2019
////////////////////////////////////////////////////////////////////////////////////////////////////
class DDSTopicInfo {
public:
typedef std::tuple<std::string, char> TTypeInfo;
......@@ -87,6 +119,17 @@ namespace NADSDDS {
//class CFloatPub : public CellPub<TypeFloat> {};
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \class CFloatPub
///
/// \brief A float pub.
///
/// Provides Interface to Float data, hides DDS calls
///
/// \author Simop
/// \date 4/29/2019
////////////////////////////////////////////////////////////////////////////////////////////////////
class CFloatPub {
public:
typedef unique_ptr<CellPub<TypeFloat>> TRef;
......@@ -97,6 +140,15 @@ namespace NADSDDS {
CellPub<TypeFloat>* operator->() { return _ref.get(); }
};
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \class CDoublePub
///
/// \brief A double pub.
///
/// \author Simop
/// \date 4/29/2019
////////////////////////////////////////////////////////////////////////////////////////////////////
class CDoublePub {
public:
typedef unique_ptr<CellPub<TypeDouble>> TRef;
......@@ -107,6 +159,15 @@ namespace NADSDDS {
CellPub<TypeDouble>* operator->() { return _ref.get(); }
};
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \class CCharPub
///
/// \brief A character pub.
///
/// \author Simop
/// \date 4/29/2019
////////////////////////////////////////////////////////////////////////////////////////////////////
class CCharPub {
public:
typedef unique_ptr<CellPub<TypeChar>> TRef;
......@@ -119,6 +180,14 @@ namespace NADSDDS {
CellPub<TypeChar>* operator()() { return _ref.get(); }
};
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \class CIntPub
///
/// \brief An int pub.
///
/// \author Simop
/// \date 4/29/2019
////////////////////////////////////////////////////////////////////////////////////////////////////
class CIntPub {
public:
......@@ -130,6 +199,15 @@ namespace NADSDDS {
CellPub<TypeInt>* operator->() { return _ref.get(); }
};
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \class CShortPub
///
/// \brief A short pub.
///
/// \author Simop
/// \date 4/29/2019
////////////////////////////////////////////////////////////////////////////////////////////////////
class CShortPub {
public:
typedef unique_ptr<CellPub<TypeShort>> TRef;
......@@ -155,6 +233,19 @@ namespace NADSDDS {
typedef std::shared_ptr<OnNewData<TypeFloat>> TFloatCB;
typedef std::shared_ptr<OnNewData<TypeDouble>> TDoubleCB;
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \class DataListener
///
/// \brief A data listener.
///
/// Implements a "no-op" reader/listener. This does not handle loss of data events, ect, it also
/// provides a basic buffering scheme. The user can provide a call back class
/// \author Simop
/// \date 4/29/2019
///
/// \tparam T Generic type parameter.
////////////////////////////////////////////////////////////////////////////////////////////////////
template < class T> class DataListener : public dds::sub::NoOpDataReaderListener<T> {
public:
typedef std::shared_ptr<OnNewData<T>> TCbRef;
......@@ -179,7 +270,14 @@ namespace NADSDDS {
TCbRef _cb;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \class StreamBase
///
/// \brief base class for streams
///
/// \author Simop
/// \date 4/30/2019
////////////////////////////////////////////////////////////////////////////////////////////////////
class StreamBase {
public:
......@@ -189,6 +287,21 @@ namespace NADSDDS {
std::string _topicName;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \class DataStream
///
/// \brief Handles the setting up the reader, and new data callback for the reader
///
/// Its really with the callback from our reader where most of our actual work is done.
/// This should likely be expanded in the future to properly setup the QOS settings, this is where
/// we would handle setting up data coherence.
///
/// \author Simop
/// \date 4/30/2019
///
/// \tparam T Generic type parameter.
////////////////////////////////////////////////////////////////////////////////////////////////////
template <class T> class DataStream : public StreamBase {
public:
typedef std::shared_ptr<OnNewData<T>> TCbRef;
......@@ -212,10 +325,22 @@ namespace NADSDDS {
};
//BufferedCellRoot: public CellRoot{
// BufferedCellRoot: public CellRoot{
// public:
// BufferedCellRoot(int id) : CellRoot(id) {}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \class CellSubsScription
///
/// \brief A cell subs scription.
///
/// \author Simop
/// \date 4/29/2019
///
/// \tparam T DDS type like TypeFloat - which is auto generated code
/// \tparam Y Base "C++" type, like float - which is viewable by host app
////////////////////////////////////////////////////////////////////////////////////////////////////
template <class T, class Y> class CellSubsScription : public BufferedCellRoot<T>{
public:
class CB : public OnNewData<Y> {
......@@ -306,6 +431,19 @@ namespace NADSDDS {
vec.end());
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \class CStatePriv
///
/// \brief Handles simulator state information
///
/// This class handles the simulator state information, and provides a callback for new frame.
/// This call back is more or less suposed to take the place of RunSubsystem method for Scramnet
/// based RTEX
///
/// \author Simop
/// \date 4/29/2019
////////////////////////////////////////////////////////////////////////////////////////////////////
class CStatePriv {
public:
static CStatePriv & Get();
......@@ -317,6 +455,7 @@ namespace NADSDDS {
typedef std::shared_ptr<Callback> TCBRef;
typedef std::weak_ptr<Callback> TCBWRef;
CStatePriv();
int GetFrame();
int GetState();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment