From 627fc867ec017be54451d030292e26e1b6d50c79 Mon Sep 17 00:00:00 2001 From: Matthew W Hume Date: Sun, 3 Mar 2024 10:38:34 -0500 Subject: [PATCH 1/5] first commit, telemetry processor; causes access violations --- .../ProjectApollo/Build/VC2017/MCC.vcxproj | 3 ++ .../Build/VC2017/MCC.vcxproj.filters | 9 ++++ .../Build/VC2017/Saturn1b.vcxproj | 1 + .../Build/VC2017/Saturn1b.vcxproj.filters | 3 ++ .../Build/VC2017/Saturn5NASP.vcxproj | 1 + .../Build/VC2017/Saturn5NASP.vcxproj.filters | 3 ++ .../ProjectApollo/src_csm/csm_telecom.cpp | 38 ++++++++++++-- .../ProjectApollo/src_csm/csm_telecom.h | 2 + .../src_launch/RemoteSiteProcessor.cpp | 24 +++++++++ .../src_launch/RemoteSiteProcessor.h | 49 +++++++++++++++++++ .../src_launch/TelemetryDownlink.cpp | 39 +++++++++++++++ .../samples/ProjectApollo/src_launch/mcc.cpp | 5 ++ .../samples/ProjectApollo/src_launch/mcc.h | 8 +++ 13 files changed, 182 insertions(+), 3 deletions(-) create mode 100644 Orbitersdk/samples/ProjectApollo/src_launch/RemoteSiteProcessor.cpp create mode 100644 Orbitersdk/samples/ProjectApollo/src_launch/RemoteSiteProcessor.h create mode 100644 Orbitersdk/samples/ProjectApollo/src_launch/TelemetryDownlink.cpp diff --git a/Orbitersdk/samples/ProjectApollo/Build/VC2017/MCC.vcxproj b/Orbitersdk/samples/ProjectApollo/Build/VC2017/MCC.vcxproj index 413fc8a8d4..1ab9c1d2e9 100644 --- a/Orbitersdk/samples/ProjectApollo/Build/VC2017/MCC.vcxproj +++ b/Orbitersdk/samples/ProjectApollo/Build/VC2017/MCC.vcxproj @@ -158,6 +158,7 @@ + @@ -168,6 +169,7 @@ + @@ -206,6 +208,7 @@ + diff --git a/Orbitersdk/samples/ProjectApollo/Build/VC2017/MCC.vcxproj.filters b/Orbitersdk/samples/ProjectApollo/Build/VC2017/MCC.vcxproj.filters index 2011396154..414136b419 100644 --- a/Orbitersdk/samples/ProjectApollo/Build/VC2017/MCC.vcxproj.filters +++ b/Orbitersdk/samples/ProjectApollo/Build/VC2017/MCC.vcxproj.filters @@ -150,6 +150,12 @@ Source Files + + Source Files + + + Source Files + @@ -254,5 +260,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/Orbitersdk/samples/ProjectApollo/Build/VC2017/Saturn1b.vcxproj b/Orbitersdk/samples/ProjectApollo/Build/VC2017/Saturn1b.vcxproj index 653b59a6ad..9bd390bf84 100644 --- a/Orbitersdk/samples/ProjectApollo/Build/VC2017/Saturn1b.vcxproj +++ b/Orbitersdk/samples/ProjectApollo/Build/VC2017/Saturn1b.vcxproj @@ -159,6 +159,7 @@ + diff --git a/Orbitersdk/samples/ProjectApollo/Build/VC2017/Saturn1b.vcxproj.filters b/Orbitersdk/samples/ProjectApollo/Build/VC2017/Saturn1b.vcxproj.filters index 356551dd53..66876d9211 100644 --- a/Orbitersdk/samples/ProjectApollo/Build/VC2017/Saturn1b.vcxproj.filters +++ b/Orbitersdk/samples/ProjectApollo/Build/VC2017/Saturn1b.vcxproj.filters @@ -246,6 +246,9 @@ Source Files + + Source Files + diff --git a/Orbitersdk/samples/ProjectApollo/Build/VC2017/Saturn5NASP.vcxproj b/Orbitersdk/samples/ProjectApollo/Build/VC2017/Saturn5NASP.vcxproj index f0243c86c8..bb2b8caeb1 100644 --- a/Orbitersdk/samples/ProjectApollo/Build/VC2017/Saturn5NASP.vcxproj +++ b/Orbitersdk/samples/ProjectApollo/Build/VC2017/Saturn5NASP.vcxproj @@ -160,6 +160,7 @@ + diff --git a/Orbitersdk/samples/ProjectApollo/Build/VC2017/Saturn5NASP.vcxproj.filters b/Orbitersdk/samples/ProjectApollo/Build/VC2017/Saturn5NASP.vcxproj.filters index b0284a34c7..14940a8e73 100644 --- a/Orbitersdk/samples/ProjectApollo/Build/VC2017/Saturn5NASP.vcxproj.filters +++ b/Orbitersdk/samples/ProjectApollo/Build/VC2017/Saturn5NASP.vcxproj.filters @@ -246,6 +246,9 @@ Source Files + + Source Files + diff --git a/Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.cpp b/Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.cpp index 6813ec066c..990bd9040e 100644 --- a/Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.cpp +++ b/Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.cpp @@ -1998,6 +1998,7 @@ PCM::PCM() frame_addr = 0; frame_count = 0; m_socket = INVALID_SOCKET; + MCCV = nullptr; } PCM::~PCM() @@ -2062,6 +2063,16 @@ void PCM::Init(Saturn *vessel){ conn_state = 1; // INITIALIZED, LISTENING uplink_state = 0; rx_offset = 0; + + for (unsigned int i = 0; i < oapiGetVesselCount(); i++) + { + OBJHANDLE hVessel = oapiGetVesselByIndex(i); + VESSEL* pVessel = oapiGetVesselInterface(hVessel); + if (utils::IsVessel(pVessel, utils::MCC)) + { + MCCV = (MCC*)pVessel; + } + } } void PCM::SystemTimestep(double simdt) { @@ -2123,11 +2134,12 @@ void PCM::TimeStep(double simt){ return; } */ + // Generate PCM datastream if(LowBitrateLogic()){ tx_size = (int)((simt - last_update) / 0.005); - // sprintf(oapiDebugString(),"Need to send %d bytes",tx_size); + //sprintf(oapiDebugString(),"Need to send %d bytes",tx_size); if(tx_size > 0){ last_update = simt; if(tx_size < 1024){ @@ -2143,7 +2155,7 @@ void PCM::TimeStep(double simt){ } else{ tx_size = (int)((simt - last_update) / 0.00015625); - // sprintf(oapiDebugString(),"Need to send %d bytes",tx_size); + //sprintf(oapiDebugString(),"Need to send %d bytes",tx_size); if(tx_size > 0){ last_update = simt; if(tx_size < 1024){ @@ -2151,7 +2163,7 @@ void PCM::TimeStep(double simt){ while(tx_offset < tx_size){ generate_stream_hbr(); tx_offset++; - } + } perform_io(simt); } } @@ -4934,6 +4946,26 @@ void PCM::generate_stream_hbr(){ } void PCM::perform_io(double simt){ + + //very slow, done for testing only + if (!MCCV) { + for (unsigned int i = 0; i < oapiGetVesselCount(); i++) + { + OBJHANDLE hVessel = oapiGetVesselByIndex(i); + VESSEL* pVessel = oapiGetVesselInterface(hVessel); + if (utils::IsVessel(pVessel, utils::MCC)) + { + MCCV = (MCC*)pVessel; + } + } + } + else { + int sent = MCCV->TelemetryDownlink(1, tx_data, tx_size); + //MCCV->CSM_TelemetryBuffer.push_back((unsigned char)05); for testing only + //sprintf(oapiDebugString(), "Status: %zu", MCCV->CSM_TelemetryBuffer.size()); + } + + // Do TCP IO switch(conn_state){ case 0: // UNINITIALIZED diff --git a/Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.h b/Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.h index c614ee7ca2..2042250179 100644 --- a/Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.h +++ b/Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.h @@ -25,6 +25,7 @@ #include "RF_calc.h" #include "paCBGmessageID.h" +#include "mcc.h" /* PCM DOWN-TELEMETRY @@ -348,6 +349,7 @@ class PCM { sockaddr_in service; // SOCKADDR_IN SOCKET AcceptSocket; // Accept Socket int conn_state; // Connection State + MCC *MCCV; int uplink_state; // Uplink State void perform_io(double simt); // Get data from here to there void handle_uplink(); // Handle incoming data diff --git a/Orbitersdk/samples/ProjectApollo/src_launch/RemoteSiteProcessor.cpp b/Orbitersdk/samples/ProjectApollo/src_launch/RemoteSiteProcessor.cpp new file mode 100644 index 0000000000..37a74736a2 --- /dev/null +++ b/Orbitersdk/samples/ProjectApollo/src_launch/RemoteSiteProcessor.cpp @@ -0,0 +1,24 @@ +/*************************************************************************** + This file is part of Project Apollo - NASSP + Copyright 2024 + + Remote Site Telemetry/Command Processor + + Project Apollo is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + Project Apollo is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Project Apollo; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + See https://github.com/orbiternassp/NASSP/blob/Orbiter2016/COPYING.txt + for more details. + + **************************************************************************/ \ No newline at end of file diff --git a/Orbitersdk/samples/ProjectApollo/src_launch/RemoteSiteProcessor.h b/Orbitersdk/samples/ProjectApollo/src_launch/RemoteSiteProcessor.h new file mode 100644 index 0000000000..4d1678d939 --- /dev/null +++ b/Orbitersdk/samples/ProjectApollo/src_launch/RemoteSiteProcessor.h @@ -0,0 +1,49 @@ +/*************************************************************************** + This file is part of Project Apollo - NASSP + Copyright 2024 + + Remote Site Telemetry/Command Processor + + Project Apollo is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + Project Apollo is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Project Apollo; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + See https://github.com/orbiternassp/NASSP/blob/Orbiter2016/COPYING.txt + for more details. + + **************************************************************************/ + +#include +#include +#ifndef _PA_REMOTE_SITE_PROCESSOR +#define _PA_REMOTE_SITE_PROCESSOR + +struct PCMDecommFormat { + std::array SyncWords; + uint8_t FrameLength; + uint8_t NumWords; +}; + +class PCMTelemetryProcessor { + PCMTelemetryProcessor(); + ~PCMTelemetryProcessor(); + + PCMDecommFormat HBR_Format; + PCMDecommFormat LBR_Format; + +}; + + + + +#endif // !_PA_REMOTE_SITE_PROCESSOR diff --git a/Orbitersdk/samples/ProjectApollo/src_launch/TelemetryDownlink.cpp b/Orbitersdk/samples/ProjectApollo/src_launch/TelemetryDownlink.cpp new file mode 100644 index 0000000000..10f471dd8f --- /dev/null +++ b/Orbitersdk/samples/ProjectApollo/src_launch/TelemetryDownlink.cpp @@ -0,0 +1,39 @@ +/*************************************************************************** + This file is part of Project Apollo - NASSP + Copyright 2020 + + Telemetry Downlink Function for MCC + + Project Apollo is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + Project Apollo is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Project Apollo; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + See https://github.com/orbiternassp/NASSP/blob/Orbiter2016/COPYING.txt + for more details. + + **************************************************************************/ +#include "mcc.h" + +int MCC::TelemetryDownlink(int type, const unsigned char* telemetryWords, int messageLength) { + switch (type) { + case 1: + for (int i = 0; i < messageLength; i++) + { + sprintf(oapiDebugString(), "Word: %d Length %d", telemetryWords[i], messageLength); + CSM_TelemetryBuffer.push_back(telemetryWords[i]); + } + return 1; + default: + return -1; + } +} \ No newline at end of file diff --git a/Orbitersdk/samples/ProjectApollo/src_launch/mcc.cpp b/Orbitersdk/samples/ProjectApollo/src_launch/mcc.cpp index b587eb7a75..5db728c03e 100644 --- a/Orbitersdk/samples/ProjectApollo/src_launch/mcc.cpp +++ b/Orbitersdk/samples/ProjectApollo/src_launch/mcc.cpp @@ -582,6 +582,11 @@ void MCC::Init(){ // Uplink items uplink_size = 0; logfileinit = false; + + CSM_TelemetryBuffer = { 0 }; + LEM_TelemetryBuffer = { 0 }; + IU_TelemetryBuffer = { 0 }; + CSM_TelemetryBuffer.reserve(10000000); } void MCC::setState(int newState){ diff --git a/Orbitersdk/samples/ProjectApollo/src_launch/mcc.h b/Orbitersdk/samples/ProjectApollo/src_launch/mcc.h index 4ddf0d28ac..cbf29652bb 100644 --- a/Orbitersdk/samples/ProjectApollo/src_launch/mcc.h +++ b/Orbitersdk/samples/ProjectApollo/src_launch/mcc.h @@ -266,6 +266,7 @@ class MCC { void pushLGCUplinkString(const char *str); // Send sequence to LM int LM_uplink(const unsigned char *data, int len); // Uplink string to LM int LM_uplink_buffer(); // Send uplink buffer to LM + int TelemetryDownlink(int type, const unsigned char *telemetryWords, int messageLength); void setState(int newState); // Set mission state void setSubState(int newState); // Set mission substate void drawPad(bool writetofile = true); // Draw PAD display @@ -323,6 +324,13 @@ class MCC { bool GT_Enabled; // Ground tracking enable/disable bool MT_Enabled; // Mission status tracking enable/disable + //TELEMETRY PROCESSING +//private: + std::vector CSM_TelemetryBuffer; //Type 1 + std::vector LEM_TelemetryBuffer; //Type 2 + std::vector IU_TelemetryBuffer; //Type 3 +//public: + // MISSION STATE int MissionType; // Mission Type int MissionState; // Major state From b5a186c00cd178a04030cda2cca608015f226ca9 Mon Sep 17 00:00:00 2001 From: Matthew W Hume Date: Sun, 3 Mar 2024 13:09:06 -0500 Subject: [PATCH 2/5] fix access violation --- Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.cpp | 6 ++---- Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.h | 1 + .../samples/ProjectApollo/src_launch/TelemetryDownlink.cpp | 2 +- Orbitersdk/samples/ProjectApollo/src_launch/mcc.h | 2 ++ 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.cpp b/Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.cpp index 990bd9040e..01bc2e4538 100644 --- a/Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.cpp +++ b/Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.cpp @@ -2070,7 +2070,7 @@ void PCM::Init(Saturn *vessel){ VESSEL* pVessel = oapiGetVesselInterface(hVessel); if (utils::IsVessel(pVessel, utils::MCC)) { - MCCV = (MCC*)pVessel; + MCCV = ((MCCVessel*)pVessel)->mcc; } } } @@ -4955,14 +4955,12 @@ void PCM::perform_io(double simt){ VESSEL* pVessel = oapiGetVesselInterface(hVessel); if (utils::IsVessel(pVessel, utils::MCC)) { - MCCV = (MCC*)pVessel; + MCCV = ((MCCVessel*)pVessel)->mcc; } } } else { int sent = MCCV->TelemetryDownlink(1, tx_data, tx_size); - //MCCV->CSM_TelemetryBuffer.push_back((unsigned char)05); for testing only - //sprintf(oapiDebugString(), "Status: %zu", MCCV->CSM_TelemetryBuffer.size()); } diff --git a/Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.h b/Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.h index 2042250179..10c97d7bcc 100644 --- a/Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.h +++ b/Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.h @@ -26,6 +26,7 @@ #include "RF_calc.h" #include "paCBGmessageID.h" #include "mcc.h" +#include "mccvessel.h" /* PCM DOWN-TELEMETRY diff --git a/Orbitersdk/samples/ProjectApollo/src_launch/TelemetryDownlink.cpp b/Orbitersdk/samples/ProjectApollo/src_launch/TelemetryDownlink.cpp index 10f471dd8f..9d9ba7a84e 100644 --- a/Orbitersdk/samples/ProjectApollo/src_launch/TelemetryDownlink.cpp +++ b/Orbitersdk/samples/ProjectApollo/src_launch/TelemetryDownlink.cpp @@ -29,7 +29,7 @@ int MCC::TelemetryDownlink(int type, const unsigned char* telemetryWords, int me case 1: for (int i = 0; i < messageLength; i++) { - sprintf(oapiDebugString(), "Word: %d Length %d", telemetryWords[i], messageLength); + sprintf(oapiDebugString(), "Word: %d Length %zu", telemetryWords[i], CSM_TelemetryBuffer.size()); CSM_TelemetryBuffer.push_back(telemetryWords[i]); } return 1; diff --git a/Orbitersdk/samples/ProjectApollo/src_launch/mcc.h b/Orbitersdk/samples/ProjectApollo/src_launch/mcc.h index cbf29652bb..fe135d09da 100644 --- a/Orbitersdk/samples/ProjectApollo/src_launch/mcc.h +++ b/Orbitersdk/samples/ProjectApollo/src_launch/mcc.h @@ -27,6 +27,7 @@ #include "MCCPADForms.h" #include #include +#include #include "thread.h" // Save file strings @@ -376,6 +377,7 @@ class MCC { // FRIEND CLASSES friend class RTCC; // RTCC can handle our data + friend class Saturn; }; #endif // _PA_MCC_H From 599c4055098c9609171084640cb520f0b88479b0 Mon Sep 17 00:00:00 2001 From: Matthew W Hume Date: Sun, 3 Mar 2024 13:10:19 -0500 Subject: [PATCH 3/5] rename MCCV to pMCC --- .../samples/ProjectApollo/src_csm/csm_telecom.cpp | 10 +++++----- Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.cpp b/Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.cpp index 01bc2e4538..7598407cee 100644 --- a/Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.cpp +++ b/Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.cpp @@ -1998,7 +1998,7 @@ PCM::PCM() frame_addr = 0; frame_count = 0; m_socket = INVALID_SOCKET; - MCCV = nullptr; + pMCC = nullptr; } PCM::~PCM() @@ -2070,7 +2070,7 @@ void PCM::Init(Saturn *vessel){ VESSEL* pVessel = oapiGetVesselInterface(hVessel); if (utils::IsVessel(pVessel, utils::MCC)) { - MCCV = ((MCCVessel*)pVessel)->mcc; + pMCC = ((MCCVessel*)pVessel)->mcc; } } } @@ -4948,19 +4948,19 @@ void PCM::generate_stream_hbr(){ void PCM::perform_io(double simt){ //very slow, done for testing only - if (!MCCV) { + if (!pMCC) { for (unsigned int i = 0; i < oapiGetVesselCount(); i++) { OBJHANDLE hVessel = oapiGetVesselByIndex(i); VESSEL* pVessel = oapiGetVesselInterface(hVessel); if (utils::IsVessel(pVessel, utils::MCC)) { - MCCV = ((MCCVessel*)pVessel)->mcc; + pMCC = ((MCCVessel*)pVessel)->mcc; } } } else { - int sent = MCCV->TelemetryDownlink(1, tx_data, tx_size); + int sent = pMCC->TelemetryDownlink(1, tx_data, tx_size); } diff --git a/Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.h b/Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.h index 10c97d7bcc..28ef5f92dc 100644 --- a/Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.h +++ b/Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.h @@ -350,7 +350,7 @@ class PCM { sockaddr_in service; // SOCKADDR_IN SOCKET AcceptSocket; // Accept Socket int conn_state; // Connection State - MCC *MCCV; + MCC *pMCC; int uplink_state; // Uplink State void perform_io(double simt); // Get data from here to there void handle_uplink(); // Handle incoming data From c1cf5c26d40b13440756090f713bdfa6641b6fd3 Mon Sep 17 00:00:00 2001 From: Matthew W Hume Date: Sun, 3 Mar 2024 16:08:49 -0500 Subject: [PATCH 4/5] threads and buffers in place --- .../src_launch/RemoteSiteProcessor.cpp | 32 ++++++++++++++++++- .../src_launch/RemoteSiteProcessor.h | 20 ++++++++++-- .../src_launch/TelemetryDownlink.cpp | 12 ++++++- .../samples/ProjectApollo/src_launch/mcc.cpp | 11 ++++++- .../samples/ProjectApollo/src_launch/mcc.h | 25 +++++++++++---- 5 files changed, 88 insertions(+), 12 deletions(-) diff --git a/Orbitersdk/samples/ProjectApollo/src_launch/RemoteSiteProcessor.cpp b/Orbitersdk/samples/ProjectApollo/src_launch/RemoteSiteProcessor.cpp index 37a74736a2..998faa337b 100644 --- a/Orbitersdk/samples/ProjectApollo/src_launch/RemoteSiteProcessor.cpp +++ b/Orbitersdk/samples/ProjectApollo/src_launch/RemoteSiteProcessor.cpp @@ -1,3 +1,4 @@ +#include "RemoteSiteProcessor.h" /*************************************************************************** This file is part of Project Apollo - NASSP Copyright 2024 @@ -21,4 +22,33 @@ See https://github.com/orbiternassp/NASSP/blob/Orbiter2016/COPYING.txt for more details. - **************************************************************************/ \ No newline at end of file + **************************************************************************/ + +#include "RemoteSiteProcessor.h" + +PCMTelemetryProcessor::PCMTelemetryProcessor(std::vector* buffer, std::vector* output, std::mutex *mtex) { + TelemetryBuffer = buffer; + TelemetryOutput = output; + BufferMutex = mtex; + + TelemetryOutput->resize(6400); + std::fill(TelemetryOutput->begin(), TelemetryOutput->end(), 0); + runProcessor = true; + ProcessorThread = std::thread{ &PCMTelemetryProcessor::ProcessTelemetry, this }; +} + +PCMTelemetryProcessor::~PCMTelemetryProcessor() +{ +} + +void PCMTelemetryProcessor::ProcessTelemetry() { + int i = 0; + while (runProcessor) { + if (TelemetryBuffer->size() > 0) { + BufferMutex->lock(); + TelemetryOutput[i] = TelemetryBuffer[TelemetryBuffer->front()]; + TelemetryBuffer->erase(TelemetryBuffer->end()); + BufferMutex->unlock(); + } + } +} diff --git a/Orbitersdk/samples/ProjectApollo/src_launch/RemoteSiteProcessor.h b/Orbitersdk/samples/ProjectApollo/src_launch/RemoteSiteProcessor.h index 4d1678d939..75e4852517 100644 --- a/Orbitersdk/samples/ProjectApollo/src_launch/RemoteSiteProcessor.h +++ b/Orbitersdk/samples/ProjectApollo/src_launch/RemoteSiteProcessor.h @@ -25,22 +25,36 @@ #include #include +#include +#include +#include + #ifndef _PA_REMOTE_SITE_PROCESSOR #define _PA_REMOTE_SITE_PROCESSOR + struct PCMDecommFormat { std::array SyncWords; uint8_t FrameLength; uint8_t NumWords; }; + class PCMTelemetryProcessor { - PCMTelemetryProcessor(); +public: + PCMTelemetryProcessor(std::vector* buffer, std::vector* output, std::mutex *mtex); ~PCMTelemetryProcessor(); - PCMDecommFormat HBR_Format; - PCMDecommFormat LBR_Format; + PCMDecommFormat* HBR_Format; + PCMDecommFormat* LBR_Format; + + std::vector* TelemetryBuffer; + std::vector* TelemetryOutput; + std::mutex* BufferMutex; + void ProcessTelemetry(); + std::thread ProcessorThread; + bool runProcessor; }; diff --git a/Orbitersdk/samples/ProjectApollo/src_launch/TelemetryDownlink.cpp b/Orbitersdk/samples/ProjectApollo/src_launch/TelemetryDownlink.cpp index 9d9ba7a84e..a6966f6f2b 100644 --- a/Orbitersdk/samples/ProjectApollo/src_launch/TelemetryDownlink.cpp +++ b/Orbitersdk/samples/ProjectApollo/src_launch/TelemetryDownlink.cpp @@ -23,16 +23,26 @@ **************************************************************************/ #include "mcc.h" +#include int MCC::TelemetryDownlink(int type, const unsigned char* telemetryWords, int messageLength) { switch (type) { case 1: for (int i = 0; i < messageLength; i++) { + CSM_BufferLock.lock(); sprintf(oapiDebugString(), "Word: %d Length %zu", telemetryWords[i], CSM_TelemetryBuffer.size()); - CSM_TelemetryBuffer.push_back(telemetryWords[i]); + CSM_TelemetryBuffer.push_back((uint8_t)telemetryWords[i]); + CSM_BufferLock.unlock(); } return 1; + case 2: + for (int i = 0; i < messageLength; i++) + { + //sprintf(oapiDebugString(), "Word: %d Length %zu", telemetryWords[i], LEM_TelemetryBuffer.size()); + LEM_TelemetryBuffer.push_back((uint8_t)telemetryWords[i]); + } + return 2; default: return -1; } diff --git a/Orbitersdk/samples/ProjectApollo/src_launch/mcc.cpp b/Orbitersdk/samples/ProjectApollo/src_launch/mcc.cpp index 5db728c03e..1f64c17ff2 100644 --- a/Orbitersdk/samples/ProjectApollo/src_launch/mcc.cpp +++ b/Orbitersdk/samples/ProjectApollo/src_launch/mcc.cpp @@ -145,6 +145,13 @@ MCC::MCC(RTCC *rtc) // Ground Systems Init Init(); + + CSMTelemetryProcessor = new PCMTelemetryProcessor(&CSM_TelemetryBuffer, &CSM_OutputBuffer, &CSM_BufferLock); +} + +MCC::~MCC() +{ + delete this->CSMTelemetryProcessor; } void MCC::Init(){ @@ -585,8 +592,10 @@ void MCC::Init(){ CSM_TelemetryBuffer = { 0 }; LEM_TelemetryBuffer = { 0 }; - IU_TelemetryBuffer = { 0 }; + //IU_TelemetryBuffer = { 0 }; CSM_TelemetryBuffer.reserve(10000000); + LEM_TelemetryBuffer.reserve(10000000); + //IU_TelemetryBuffer.reserve(10000000); } void MCC::setState(int newState){ diff --git a/Orbitersdk/samples/ProjectApollo/src_launch/mcc.h b/Orbitersdk/samples/ProjectApollo/src_launch/mcc.h index fe135d09da..f28f713ddb 100644 --- a/Orbitersdk/samples/ProjectApollo/src_launch/mcc.h +++ b/Orbitersdk/samples/ProjectApollo/src_launch/mcc.h @@ -29,6 +29,7 @@ #include #include #include "thread.h" +#include "RemoteSiteProcessor.h" // Save file strings #define MCC_START_STRING "MCC_BEGIN" @@ -244,6 +245,7 @@ class RTCC; class MCC { public: MCC(RTCC *rtc); // Cons + ~MCC(); char CSMName[64]; char LEMName[64]; @@ -326,11 +328,23 @@ class MCC { bool MT_Enabled; // Mission status tracking enable/disable //TELEMETRY PROCESSING -//private: - std::vector CSM_TelemetryBuffer; //Type 1 - std::vector LEM_TelemetryBuffer; //Type 2 - std::vector IU_TelemetryBuffer; //Type 3 -//public: +private: + std::vector CSM_TelemetryBuffer; //Type 1 + std::vector LEM_TelemetryBuffer; //Type 2 + //std::vector IU_TelemetryBuffer; //Type 3 + + std::vector CSM_OutputBuffer; //Type 1 + std::vector LEM_OutputBuffer; //Type 2 + //std::vector IU_OutputyBuffer; //Type 3 + + std::mutex CSM_BufferLock; + std::mutex LEM_BufferLock; + //std::mutex IU_BufferLock; + + PCMTelemetryProcessor* CSMTelemetryProcessor; + PCMTelemetryProcessor* LEMTelemetryProcessor; + //PCMTelemetryProcessor* LEMTelemetryProcessor; +public: // MISSION STATE int MissionType; // Mission Type @@ -377,7 +391,6 @@ class MCC { // FRIEND CLASSES friend class RTCC; // RTCC can handle our data - friend class Saturn; }; #endif // _PA_MCC_H From 5cc4f1867042084e370e93198d7eea1c9ac4bd05 Mon Sep 17 00:00:00 2001 From: Matthew W Hume Date: Sun, 3 Mar 2024 17:08:35 -0500 Subject: [PATCH 5/5] move data into output buffer with thread --- .../src_launch/RemoteSiteProcessor.cpp | 15 ++++++++++----- .../src_launch/RemoteSiteProcessor.h | 5 +++-- .../src_launch/TelemetryDownlink.cpp | 2 +- .../samples/ProjectApollo/src_launch/mcc.cpp | 9 +++++---- Orbitersdk/samples/ProjectApollo/src_launch/mcc.h | 5 +++-- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Orbitersdk/samples/ProjectApollo/src_launch/RemoteSiteProcessor.cpp b/Orbitersdk/samples/ProjectApollo/src_launch/RemoteSiteProcessor.cpp index 998faa337b..83617386c7 100644 --- a/Orbitersdk/samples/ProjectApollo/src_launch/RemoteSiteProcessor.cpp +++ b/Orbitersdk/samples/ProjectApollo/src_launch/RemoteSiteProcessor.cpp @@ -26,7 +26,7 @@ #include "RemoteSiteProcessor.h" -PCMTelemetryProcessor::PCMTelemetryProcessor(std::vector* buffer, std::vector* output, std::mutex *mtex) { +PCMTelemetryProcessor::PCMTelemetryProcessor(std::deque* buffer, std::vector* output, std::mutex *mtex) { TelemetryBuffer = buffer; TelemetryOutput = output; BufferMutex = mtex; @@ -35,20 +35,25 @@ PCMTelemetryProcessor::PCMTelemetryProcessor(std::vector* buffer, std:: std::fill(TelemetryOutput->begin(), TelemetryOutput->end(), 0); runProcessor = true; ProcessorThread = std::thread{ &PCMTelemetryProcessor::ProcessTelemetry, this }; + ProcessorThread.detach(); } PCMTelemetryProcessor::~PCMTelemetryProcessor() { + runProcessor = false; } void PCMTelemetryProcessor::ProcessTelemetry() { int i = 0; while (runProcessor) { - if (TelemetryBuffer->size() > 0) { - BufferMutex->lock(); - TelemetryOutput[i] = TelemetryBuffer[TelemetryBuffer->front()]; - TelemetryBuffer->erase(TelemetryBuffer->end()); + if (TelemetryBuffer->size() > 0 && BufferMutex->try_lock()) { + TelemetryOutput->at(i) = TelemetryBuffer->front(); + TelemetryBuffer->pop_front(); BufferMutex->unlock(); + i++; + if (i >= 6400) { + i = 0; + } } } } diff --git a/Orbitersdk/samples/ProjectApollo/src_launch/RemoteSiteProcessor.h b/Orbitersdk/samples/ProjectApollo/src_launch/RemoteSiteProcessor.h index 75e4852517..a74f7cfa41 100644 --- a/Orbitersdk/samples/ProjectApollo/src_launch/RemoteSiteProcessor.h +++ b/Orbitersdk/samples/ProjectApollo/src_launch/RemoteSiteProcessor.h @@ -27,6 +27,7 @@ #include #include #include +#include #include #ifndef _PA_REMOTE_SITE_PROCESSOR @@ -42,13 +43,13 @@ struct PCMDecommFormat { class PCMTelemetryProcessor { public: - PCMTelemetryProcessor(std::vector* buffer, std::vector* output, std::mutex *mtex); + PCMTelemetryProcessor(std::deque* buffer, std::vector* output, std::mutex *mtex); ~PCMTelemetryProcessor(); PCMDecommFormat* HBR_Format; PCMDecommFormat* LBR_Format; - std::vector* TelemetryBuffer; + std::deque* TelemetryBuffer; std::vector* TelemetryOutput; std::mutex* BufferMutex; diff --git a/Orbitersdk/samples/ProjectApollo/src_launch/TelemetryDownlink.cpp b/Orbitersdk/samples/ProjectApollo/src_launch/TelemetryDownlink.cpp index a6966f6f2b..d6f5efd5e2 100644 --- a/Orbitersdk/samples/ProjectApollo/src_launch/TelemetryDownlink.cpp +++ b/Orbitersdk/samples/ProjectApollo/src_launch/TelemetryDownlink.cpp @@ -31,7 +31,7 @@ int MCC::TelemetryDownlink(int type, const unsigned char* telemetryWords, int me for (int i = 0; i < messageLength; i++) { CSM_BufferLock.lock(); - sprintf(oapiDebugString(), "Word: %d Length %zu", telemetryWords[i], CSM_TelemetryBuffer.size()); + //sprintf(oapiDebugString(), "Word: %d Length %zu", telemetryWords[i], CSM_TelemetryBuffer.size()); CSM_TelemetryBuffer.push_back((uint8_t)telemetryWords[i]); CSM_BufferLock.unlock(); } diff --git a/Orbitersdk/samples/ProjectApollo/src_launch/mcc.cpp b/Orbitersdk/samples/ProjectApollo/src_launch/mcc.cpp index 1f64c17ff2..b6d50768f8 100644 --- a/Orbitersdk/samples/ProjectApollo/src_launch/mcc.cpp +++ b/Orbitersdk/samples/ProjectApollo/src_launch/mcc.cpp @@ -593,9 +593,6 @@ void MCC::Init(){ CSM_TelemetryBuffer = { 0 }; LEM_TelemetryBuffer = { 0 }; //IU_TelemetryBuffer = { 0 }; - CSM_TelemetryBuffer.reserve(10000000); - LEM_TelemetryBuffer.reserve(10000000); - //IU_TelemetryBuffer.reserve(10000000); } void MCC::setState(int newState){ @@ -615,6 +612,10 @@ void MCC::setSubState(int newState){ void MCC::TimeStep(double simdt){ int x=0,y=0,z=0; // Scratch + CSM_BufferLock.lock(); + sprintf(oapiDebugString(), "%d %d %d %d %d %d %d %d %d %d", CSM_OutputBuffer[1], CSM_OutputBuffer[2], CSM_OutputBuffer[3], CSM_OutputBuffer[4], CSM_OutputBuffer[5], CSM_OutputBuffer[6], CSM_OutputBuffer[7], CSM_OutputBuffer[8], CSM_OutputBuffer[9], CSM_OutputBuffer[10]); + CSM_BufferLock.unlock(); + /* AOS DETERMINATION */ LastAOSUpdate += simdt; if (LastAOSUpdate > 1.0) { @@ -647,7 +648,7 @@ void MCC::TimeStep(double simdt){ //debugging //sprintf(oapiDebugString(), "%d %d", TransmittingGroundStation[TrackingSlot::SlotCM], TransmittingGroundStation[TrackingSlot::SlotLM]); - + // MISSION STATE EVALUATOR if(MT_Enabled == true){ // Make sure ground tracking is also on diff --git a/Orbitersdk/samples/ProjectApollo/src_launch/mcc.h b/Orbitersdk/samples/ProjectApollo/src_launch/mcc.h index f28f713ddb..f2f9a1dea7 100644 --- a/Orbitersdk/samples/ProjectApollo/src_launch/mcc.h +++ b/Orbitersdk/samples/ProjectApollo/src_launch/mcc.h @@ -28,6 +28,7 @@ #include #include #include +#include #include "thread.h" #include "RemoteSiteProcessor.h" @@ -329,8 +330,8 @@ class MCC { //TELEMETRY PROCESSING private: - std::vector CSM_TelemetryBuffer; //Type 1 - std::vector LEM_TelemetryBuffer; //Type 2 + std::deque CSM_TelemetryBuffer; //Type 1 + std::deque LEM_TelemetryBuffer; //Type 2 //std::vector IU_TelemetryBuffer; //Type 3 std::vector CSM_OutputBuffer; //Type 1