Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
NADS_DDSLIB
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
NADS-Public
NADS_DDSLIB
Commits
2760b4b1
Commit
2760b4b1
authored
Apr 30, 2019
by
Heitbrink, David A
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
$updated documentation
parent
9975ba72
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
264 additions
and
10 deletions
+264
-10
DDSSimClient.cpp
DDSSimClient.cpp
+50
-4
DDSSimClient.h
include/NadsDDSLib/DDSSimClient.h
+70
-1
nadsddsimpl.h
src/nadsddsimpl.h
+144
-5
No files found.
DDSSimClient.cpp
View file @
2760b4b1
#include "stdafx.h"
#include "stdafx.h"
#include ".\include\NadsDDSLib\DDSSimClient.h"
#include ".\include\NadsDDSLib\DDSSimClient.h"
#include "apex_memmove.h"
namespace
NDDSClient
{
namespace
NDDSClient
{
using
namespace
std
;
using
namespace
std
;
CCellInputMap
::
CCellInputMap
()
{}
CCellInputMap
::
CCellInputMap
()
{}
...
@@ -14,7 +14,16 @@ namespace NDDSClient {
...
@@ -14,7 +14,16 @@ namespace NDDSClient {
ref
->
_target
=
_pBuffer
;
ref
->
_target
=
_pBuffer
;
_cellsIn
[
name
]
=
std
::
move
(
ref
);
_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
()
{
void
CCellInputMap
::
ReadInputElements
()
{
for
(
auto
&
cell
:
_cellsIn
)
{
for
(
auto
&
cell
:
_cellsIn
)
{
auto
&
cellIn
=
cell
.
second
;
auto
&
cellIn
=
cell
.
second
;
...
@@ -22,11 +31,28 @@ namespace NDDSClient {
...
@@ -22,11 +31,28 @@ namespace NDDSClient {
size_t
size
=
cellIn
->
_sub
->
GetSizeInByes
();
size_t
size
=
cellIn
->
_sub
->
GetSizeInByes
();
if
(
cellIn
->
_size
==
size
)
{
if
(
cellIn
->
_size
==
size
)
{
void
*
ptr
=
cellIn
->
_sub
->
GetRaw
();
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
)
{
void
CCellOutputMap
::
RegInpElem
(
std
::
string
name
,
void
*
_pBuffer
,
const
unsigned
int
_BufferSize
,
char
_BufferType
)
{
TCellRef
ref
=
std
::
make_unique
<
CellOutput
>
();
TCellRef
ref
=
std
::
make_unique
<
CellOutput
>
();
size_t
elementSize
=
0
;
size_t
elementSize
=
0
;
...
@@ -96,11 +122,30 @@ namespace NDDSClient {
...
@@ -96,11 +122,30 @@ namespace NDDSClient {
void
DDSSimClient
::
RegOutputCell
(
const
std
::
string
&
name
,
void
*
pnt
,
size_t
size
,
char
type
)
{
void
DDSSimClient
::
RegOutputCell
(
const
std
::
string
&
name
,
void
*
pnt
,
size_t
size
,
char
type
)
{
_omap
.
RegInpElem
(
name
,
pnt
,
size
,
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
)
{
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
->
RegisterFrameCB
(
frame
);
ptr
->
RegisterStartup
(
startup
);
ptr
->
RegisterStartup
(
startup
);
ptr
->
StartUp
();
ptr
->
StartUp
();
ptr
->
_dds_state
.
Register
(
ptr
);
ptr
->
_dds_state
.
Register
(
ptr
);
return
ptr
;
}
}
}
}
\ No newline at end of file
include/NadsDDSLib/DDSSimClient.h
View file @
2760b4b1
...
@@ -3,6 +3,13 @@
...
@@ -3,6 +3,13 @@
#include <NadsDDSLib/NadsDDSLib.h>
#include <NadsDDSLib/NadsDDSLib.h>
#include <Windows.h>
#include <Windows.h>
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \namespace NDDSClient
///
/// \brief Helper client classes for doing DDS/Gateway interface
////////////////////////////////////////////////////////////////////////////////////////////////////
namespace
NDDSClient
{
namespace
NDDSClient
{
class
CellInput
{
class
CellInput
{
public
:
public
:
...
@@ -11,6 +18,16 @@ namespace NDDSClient {
...
@@ -11,6 +18,16 @@ namespace NDDSClient {
char
_type
;
char
_type
;
NADSDDS
::
CSubscription
::
TRef
_sub
;
NADSDDS
::
CSubscription
::
TRef
_sub
;
};
};
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \class CCellInputMap
///
/// \brief Map of cell inputs.
///
/// \author Simop
/// \date 4/26/2019
////////////////////////////////////////////////////////////////////////////////////////////////////
class
CCellInputMap
{
class
CCellInputMap
{
public
:
public
:
CCellInputMap
();
CCellInputMap
();
...
@@ -28,6 +45,14 @@ namespace NDDSClient {
...
@@ -28,6 +45,14 @@ namespace NDDSClient {
NADSDDS
::
CPublication
::
TRef
_sub
;
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
{
class
CCellOutputMap
{
public
:
public
:
...
@@ -39,6 +64,15 @@ namespace NDDSClient {
...
@@ -39,6 +64,15 @@ namespace NDDSClient {
std
::
map
<
std
::
string
,
TCellRef
>
_cellsOut
;
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
{
class
DDSSimClient
:
public
NADSDDS
::
CState
::
Callback
{
public
:
public
:
NADSDDS
::
CPublication
::
TRef
_HeartBeat
;
NADSDDS
::
CPublication
::
TRef
_HeartBeat
;
...
@@ -54,7 +88,15 @@ namespace NDDSClient {
...
@@ -54,7 +88,15 @@ namespace NDDSClient {
};
};
typedef
std
::
shared_ptr
<
StartUpCB
>
TStartCBRef
;
typedef
std
::
shared_ptr
<
StartUpCB
>
TStartCBRef
;
typedef
std
::
weak_ptr
<
StartUpCB
>
TStartCBWRef
;
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
);
void
RegisterStartup
(
TStartCBRef
);
class
FrameCB
{
class
FrameCB
{
...
@@ -64,6 +106,33 @@ namespace NDDSClient {
...
@@ -64,6 +106,33 @@ namespace NDDSClient {
};
};
typedef
std
::
shared_ptr
<
FrameCB
>
TFrameCBRef
;
typedef
std
::
shared_ptr
<
FrameCB
>
TFrameCBRef
;
typedef
std
::
weak_ptr
<
FrameCB
>
TFrameCBWRef
;
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
);
void
RegisterFrameCB
(
TFrameCBRef
);
virtual
void
OnFrame
(
int
frame
);
virtual
void
OnFrame
(
int
frame
);
static
TRef
Make
(
TFrameCBRef
,
TStartCBRef
);
static
TRef
Make
(
TFrameCBRef
,
TStartCBRef
);
...
...
src/nadsddsimpl.h
View file @
2760b4b1
...
@@ -25,9 +25,30 @@
...
@@ -25,9 +25,30 @@
#include <thread>
#include <thread>
#include <mutex>
#include <mutex>
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \namespace NADSDDS
///
/// \brief Namespace for Dealing DDS based communications
////////////////////////////////////////////////////////////////////////////////////////////////////
namespace
NADSDDS
{
namespace
NADSDDS
{
using
namespace
std
;
using
namespace
std
;
using
namespace
dds
::
all
;
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
{
template
<
class
T
>
class
CellPub
:
public
CellRoot
{
public
:
public
:
CellPub
(
std
::
string
name
,
dds
::
domain
::
DomainParticipant
&
dm
,
size_t
size
,
int
id
)
:
CellPub
(
std
::
string
name
,
dds
::
domain
::
DomainParticipant
&
dm
,
size_t
size
,
int
id
)
:
...
@@ -70,6 +91,17 @@ namespace NADSDDS {
...
@@ -70,6 +91,17 @@ namespace NADSDDS {
DDSDomainRepo
();
DDSDomainRepo
();
};
};
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \class DDSTopicInfo
///
/// \brief Information about the DDS topic.
///
/// A topic is basically a availible subscription.
///
/// \author Simop
/// \date 4/29/2019
////////////////////////////////////////////////////////////////////////////////////////////////////
class
DDSTopicInfo
{
class
DDSTopicInfo
{
public
:
public
:
typedef
std
::
tuple
<
std
::
string
,
char
>
TTypeInfo
;
typedef
std
::
tuple
<
std
::
string
,
char
>
TTypeInfo
;
...
@@ -87,6 +119,17 @@ namespace NADSDDS {
...
@@ -87,6 +119,17 @@ namespace NADSDDS {
//class CFloatPub : public CellPub<TypeFloat> {};
//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
{
class
CFloatPub
{
public
:
public
:
typedef
unique_ptr
<
CellPub
<
TypeFloat
>>
TRef
;
typedef
unique_ptr
<
CellPub
<
TypeFloat
>>
TRef
;
...
@@ -97,6 +140,15 @@ namespace NADSDDS {
...
@@ -97,6 +140,15 @@ namespace NADSDDS {
CellPub
<
TypeFloat
>*
operator
->
()
{
return
_ref
.
get
();
}
CellPub
<
TypeFloat
>*
operator
->
()
{
return
_ref
.
get
();
}
};
};
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \class CDoublePub
///
/// \brief A double pub.
///
/// \author Simop
/// \date 4/29/2019
////////////////////////////////////////////////////////////////////////////////////////////////////
class
CDoublePub
{
class
CDoublePub
{
public
:
public
:
typedef
unique_ptr
<
CellPub
<
TypeDouble
>>
TRef
;
typedef
unique_ptr
<
CellPub
<
TypeDouble
>>
TRef
;
...
@@ -107,6 +159,15 @@ namespace NADSDDS {
...
@@ -107,6 +159,15 @@ namespace NADSDDS {
CellPub
<
TypeDouble
>*
operator
->
()
{
return
_ref
.
get
();
}
CellPub
<
TypeDouble
>*
operator
->
()
{
return
_ref
.
get
();
}
};
};
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \class CCharPub
///
/// \brief A character pub.
///
/// \author Simop
/// \date 4/29/2019
////////////////////////////////////////////////////////////////////////////////////////////////////
class
CCharPub
{
class
CCharPub
{
public
:
public
:
typedef
unique_ptr
<
CellPub
<
TypeChar
>>
TRef
;
typedef
unique_ptr
<
CellPub
<
TypeChar
>>
TRef
;
...
@@ -119,6 +180,14 @@ namespace NADSDDS {
...
@@ -119,6 +180,14 @@ namespace NADSDDS {
CellPub
<
TypeChar
>*
operator
()()
{
return
_ref
.
get
();
}
CellPub
<
TypeChar
>*
operator
()()
{
return
_ref
.
get
();
}
};
};
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \class CIntPub
///
/// \brief An int pub.
///
/// \author Simop
/// \date 4/29/2019
////////////////////////////////////////////////////////////////////////////////////////////////////
class
CIntPub
{
class
CIntPub
{
public
:
public
:
...
@@ -130,6 +199,15 @@ namespace NADSDDS {
...
@@ -130,6 +199,15 @@ namespace NADSDDS {
CellPub
<
TypeInt
>*
operator
->
()
{
return
_ref
.
get
();
}
CellPub
<
TypeInt
>*
operator
->
()
{
return
_ref
.
get
();
}
};
};
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \class CShortPub
///
/// \brief A short pub.
///
/// \author Simop
/// \date 4/29/2019
////////////////////////////////////////////////////////////////////////////////////////////////////
class
CShortPub
{
class
CShortPub
{
public
:
public
:
typedef
unique_ptr
<
CellPub
<
TypeShort
>>
TRef
;
typedef
unique_ptr
<
CellPub
<
TypeShort
>>
TRef
;
...
@@ -155,6 +233,19 @@ namespace NADSDDS {
...
@@ -155,6 +233,19 @@ namespace NADSDDS {
typedef
std
::
shared_ptr
<
OnNewData
<
TypeFloat
>>
TFloatCB
;
typedef
std
::
shared_ptr
<
OnNewData
<
TypeFloat
>>
TFloatCB
;
typedef
std
::
shared_ptr
<
OnNewData
<
TypeDouble
>>
TDoubleCB
;
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
>
{
template
<
class
T
>
class
DataListener
:
public
dds
::
sub
::
NoOpDataReaderListener
<
T
>
{
public
:
public
:
typedef
std
::
shared_ptr
<
OnNewData
<
T
>>
TCbRef
;
typedef
std
::
shared_ptr
<
OnNewData
<
T
>>
TCbRef
;
...
@@ -179,7 +270,14 @@ namespace NADSDDS {
...
@@ -179,7 +270,14 @@ namespace NADSDDS {
TCbRef
_cb
;
TCbRef
_cb
;
};
};
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \class StreamBase
///
/// \brief base class for streams
///
/// \author Simop
/// \date 4/30/2019
////////////////////////////////////////////////////////////////////////////////////////////////////
class
StreamBase
{
class
StreamBase
{
public
:
public
:
...
@@ -189,6 +287,21 @@ namespace NADSDDS {
...
@@ -189,6 +287,21 @@ namespace NADSDDS {
std
::
string
_topicName
;
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
{
template
<
class
T
>
class
DataStream
:
public
StreamBase
{
public
:
public
:
typedef
std
::
shared_ptr
<
OnNewData
<
T
>>
TCbRef
;
typedef
std
::
shared_ptr
<
OnNewData
<
T
>>
TCbRef
;
...
@@ -212,9 +325,21 @@ namespace NADSDDS {
...
@@ -212,9 +325,21 @@ namespace NADSDDS {
};
};
//BufferedCellRoot: public CellRoot{
// BufferedCellRoot: public CellRoot{
// public:
// public:
// BufferedCellRoot(int id) : CellRoot(id) {}
// 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
>
{
template
<
class
T
,
class
Y
>
class
CellSubsScription
:
public
BufferedCellRoot
<
T
>
{
public
:
public
:
...
@@ -305,7 +430,20 @@ namespace NADSDDS {
...
@@ -305,7 +430,20 @@ namespace NADSDDS {
[](
TWp
cb
)
{
return
cb
.
expired
();
}),
[](
TWp
cb
)
{
return
cb
.
expired
();
}),
vec
.
end
());
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
{
class
CStatePriv
{
public
:
public
:
static
CStatePriv
&
Get
();
static
CStatePriv
&
Get
();
...
@@ -317,6 +455,7 @@ namespace NADSDDS {
...
@@ -317,6 +455,7 @@ namespace NADSDDS {
typedef
std
::
shared_ptr
<
Callback
>
TCBRef
;
typedef
std
::
shared_ptr
<
Callback
>
TCBRef
;
typedef
std
::
weak_ptr
<
Callback
>
TCBWRef
;
typedef
std
::
weak_ptr
<
Callback
>
TCBWRef
;
CStatePriv
();
CStatePriv
();
int
GetFrame
();
int
GetFrame
();
int
GetState
();
int
GetState
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment