Commit 31b3817b by Heitbrink, David A

Added missing Heartbeat, and state ack to client

parent 2760b4b1
...@@ -29,7 +29,7 @@ namespace NDDSClient { ...@@ -29,7 +29,7 @@ namespace NDDSClient {
auto& cellIn = cell.second; auto& cellIn = cell.second;
cellIn->_sub->SwapBuffer(); cellIn->_sub->SwapBuffer();
size_t size = cellIn->_sub->GetSizeInByes(); size_t size = cellIn->_sub->GetSizeInByes();
if (cellIn->_size == size) { if (cellIn->_size >= size) { //the raw publication can be of variable length, DDS may trim un-needed data;
void* ptr = cellIn->_sub->GetRaw(); void* ptr = cellIn->_sub->GetRaw();
apex::memcpy(cellIn->_target, ptr, size); apex::memcpy(cellIn->_target, ptr, size);
} }
...@@ -89,14 +89,32 @@ namespace NDDSClient { ...@@ -89,14 +89,32 @@ namespace NDDSClient {
} }
} }
void DDSSimClient::RegisterStartup(DDSSimClient::TStartCBRef) { void DDSSimClient::RegisterStartup(DDSSimClient::TStartCBRef cb) {
_StartupCBs.push_back(cb);
} }
void DDSSimClient::RegisterFrameCB(DDSSimClient::TFrameCBRef) { void DDSSimClient::RegisterFrameCB(DDSSimClient::TFrameCBRef ref) {
_FrameCBs.push_back(ref);
} }
DDSSimClient::DDSSimClient() : NADSDDS::CState::Callback(), _currentFrame(-1), _Started(false) {} DDSSimClient::DDSSimClient() : NADSDDS::CState::Callback(), _currentFrame(-1), _Started(false) {}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \fn void DDSSimClient::OnFrame(int frame)
///
/// \brief Executes the frame action
/// This function:
/// Read in the Frame data, copies Publication data, out to host apps varaibles
/// Call back to the host App -> have it runs its frame
/// Write The Host Apps registered varaibles out as a publication
///
/// \author Simop
/// \date 5/1/2019
///
/// \param frame The frame.
////////////////////////////////////////////////////////////////////////////////////////////////////
void DDSSimClient::OnFrame(int frame) { void DDSSimClient::OnFrame(int frame) {
_currentFrame = frame; _currentFrame = frame;
NADSDDS::CState cs; NADSDDS::CState cs;
...@@ -109,10 +127,47 @@ namespace NDDSClient { ...@@ -109,10 +127,47 @@ namespace NDDSClient {
_HeartBeat->asShort()[0]++; _HeartBeat->asShort()[0]++;
_HeartBeat->Publish(); _HeartBeat->Publish();
} }
for (auto& cb : _FrameCBs) {
bool stateOK = true;
if (auto frameCB = cb.lock()) {
if (!frameCB->Frame(*this, state, frame))
stateOK = false;
}
if (!stateOK)
_StateAck->asInt()[0] = -1;
else
_StateAck->asInt()[0] = state;
_StateAck->Publish();
}
_omap.WriteOutputElements(); _omap.WriteOutputElements();
} }
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \fn void DDSSimClient::StartUp()
///
/// \brief Signal to connected clients its time to startup
///
/// This registration of publications and subscriptions should happen based on callbacks here
/// \author Simop
/// \date 5/1/2019
////////////////////////////////////////////////////////////////////////////////////////////////////
void DDSSimClient::StartUp() { void DDSSimClient::StartUp() {
string stateAck = "_StateAck_" + _name;
string heartBeat = "_HeartBeat_" + _name;
_HeartBeat = NADSDDS::CPublication::MakePublication(stateAck, -1, 1, 's');
_StateAck = NADSDDS::CPublication::MakePublication(heartBeat, -1, 1, 'i');
for (auto& cb : _StartupCBs) {
if (auto startCB = cb.lock()) {
startCB->Startup(*this);
}
}
_Started = true;
} }
void DDSSimClient::RegInputCell(const std::string& name, void* pnt, size_t size, char type) { void DDSSimClient::RegInputCell(const std::string& name, void* pnt, size_t size, char type) {
...@@ -139,9 +194,12 @@ namespace NDDSClient { ...@@ -139,9 +194,12 @@ namespace NDDSClient {
/// \returns A DDSSimClient::TRef. /// \returns A DDSSimClient::TRef.
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
DDSSimClient::TRef DDSSimClient::Make(TFrameCBRef frame, TStartCBRef startup) { DDSSimClient::TRef DDSSimClient::Make(TFrameCBRef frame, TStartCBRef startup, const std::string& name) {
//this most likely should use a proxy obj so we can use make_shared //this most likely should use a proxy obj so we can use make_shared
auto ptr = DDSSimClient::TRef(new DDSSimClient()); auto ptr = DDSSimClient::TRef(new DDSSimClient());
ptr->_name = name;
ptr->RegisterFrameCB(frame); ptr->RegisterFrameCB(frame);
ptr->RegisterStartup(startup); ptr->RegisterStartup(startup);
ptr->StartUp(); ptr->StartUp();
......
...@@ -135,7 +135,7 @@ namespace NDDSClient { ...@@ -135,7 +135,7 @@ namespace NDDSClient {
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, const std::string& name);
//char //char
void RegInputCell(const std::string& name, char* pnt, size_t cnt) { void RegInputCell(const std::string& name, char* pnt, size_t cnt) {
...@@ -222,11 +222,11 @@ namespace NDDSClient { ...@@ -222,11 +222,11 @@ namespace NDDSClient {
void StartUp(); void StartUp();
void RegInputCell(const std::string& name, void* pnt, size_t size, char type); void RegInputCell(const std::string& name, void* pnt, size_t size, char type);
void RegOutputCell(const std::string& name, void* pnt, size_t size, char type); void RegOutputCell(const std::string& name, void* pnt, size_t size, char type);
std::vector<TFrameCBRef> _FrameCBs; std::vector<TFrameCBWRef> _FrameCBs;
std::vector<TStartCBWRef> _StartupCBs; std::vector<TStartCBWRef> _StartupCBs;
NADSDDS::CPublication::TRef _heartBeat;
CCellInputMap _map; CCellInputMap _map;
CCellOutputMap _omap; CCellOutputMap _omap;
std::string _name;
int _currentFrame; int _currentFrame;
bool _Started; bool _Started;
}; };
......
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