diff --git a/Orbitersdk/samples/ProjectApollo/Build/VC2017/MCC.vcxproj b/Orbitersdk/samples/ProjectApollo/Build/VC2017/MCC.vcxproj index cf4bf197a1..ecf96b6760 100644 --- a/Orbitersdk/samples/ProjectApollo/Build/VC2017/MCC.vcxproj +++ b/Orbitersdk/samples/ProjectApollo/Build/VC2017/MCC.vcxproj @@ -160,6 +160,7 @@ + @@ -170,6 +171,7 @@ + @@ -211,6 +213,7 @@ + diff --git a/Orbitersdk/samples/ProjectApollo/Build/VC2017/MCC.vcxproj.filters b/Orbitersdk/samples/ProjectApollo/Build/VC2017/MCC.vcxproj.filters index 9dd0dc3e10..5f33418b2d 100644 --- a/Orbitersdk/samples/ProjectApollo/Build/VC2017/MCC.vcxproj.filters +++ b/Orbitersdk/samples/ProjectApollo/Build/VC2017/MCC.vcxproj.filters @@ -159,6 +159,12 @@ Source Files + + Source Files + + + Source Files + @@ -275,5 +281,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 4351d5b855..9b0bf0a22a 100644 --- a/Orbitersdk/samples/ProjectApollo/Build/VC2017/Saturn1b.vcxproj +++ b/Orbitersdk/samples/ProjectApollo/Build/VC2017/Saturn1b.vcxproj @@ -162,6 +162,7 @@ + diff --git a/Orbitersdk/samples/ProjectApollo/Build/VC2017/Saturn1b.vcxproj.filters b/Orbitersdk/samples/ProjectApollo/Build/VC2017/Saturn1b.vcxproj.filters index c87d2e1aa2..11010fed40 100644 --- a/Orbitersdk/samples/ProjectApollo/Build/VC2017/Saturn1b.vcxproj.filters +++ b/Orbitersdk/samples/ProjectApollo/Build/VC2017/Saturn1b.vcxproj.filters @@ -258,6 +258,9 @@ Source Files + + Source Files + diff --git a/Orbitersdk/samples/ProjectApollo/Build/VC2017/Saturn5NASP.vcxproj b/Orbitersdk/samples/ProjectApollo/Build/VC2017/Saturn5NASP.vcxproj index ba49fa7183..1249219aeb 100644 --- a/Orbitersdk/samples/ProjectApollo/Build/VC2017/Saturn5NASP.vcxproj +++ b/Orbitersdk/samples/ProjectApollo/Build/VC2017/Saturn5NASP.vcxproj @@ -163,6 +163,7 @@ + diff --git a/Orbitersdk/samples/ProjectApollo/Build/VC2017/Saturn5NASP.vcxproj.filters b/Orbitersdk/samples/ProjectApollo/Build/VC2017/Saturn5NASP.vcxproj.filters index 58dcd3ec32..e1ad0f612c 100644 --- a/Orbitersdk/samples/ProjectApollo/Build/VC2017/Saturn5NASP.vcxproj.filters +++ b/Orbitersdk/samples/ProjectApollo/Build/VC2017/Saturn5NASP.vcxproj.filters @@ -258,6 +258,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 44225ffe4c..bbf40e4690 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; + pMCC = 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)) + { + pMCC = ((MCCVessel*)pVessel)->mcc; + } + } } 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); } } @@ -4932,6 +4944,24 @@ void PCM::generate_stream_hbr(){ } void PCM::perform_io(double simt){ + + //very slow, done for testing only + if (!pMCC) { + for (unsigned int i = 0; i < oapiGetVesselCount(); i++) + { + OBJHANDLE hVessel = oapiGetVesselByIndex(i); + VESSEL* pVessel = oapiGetVesselInterface(hVessel); + if (utils::IsVessel(pVessel, utils::MCC)) + { + pMCC = ((MCCVessel*)pVessel)->mcc; + } + } + } + else { + int sent = pMCC->TelemetryDownlink(1, tx_data, tx_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..28ef5f92dc 100644 --- a/Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.h +++ b/Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.h @@ -25,6 +25,8 @@ #include "RF_calc.h" #include "paCBGmessageID.h" +#include "mcc.h" +#include "mccvessel.h" /* PCM DOWN-TELEMETRY @@ -348,6 +350,7 @@ class PCM { sockaddr_in service; // SOCKADDR_IN SOCKET AcceptSocket; // Accept Socket int conn_state; // Connection State + MCC *pMCC; 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..83617386c7 --- /dev/null +++ b/Orbitersdk/samples/ProjectApollo/src_launch/RemoteSiteProcessor.cpp @@ -0,0 +1,59 @@ +#include "RemoteSiteProcessor.h" +/*************************************************************************** + 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 "RemoteSiteProcessor.h" + +PCMTelemetryProcessor::PCMTelemetryProcessor(std::deque* 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 }; + ProcessorThread.detach(); +} + +PCMTelemetryProcessor::~PCMTelemetryProcessor() +{ + runProcessor = false; +} + +void PCMTelemetryProcessor::ProcessTelemetry() { + int i = 0; + while (runProcessor) { + 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 new file mode 100644 index 0000000000..a74f7cfa41 --- /dev/null +++ b/Orbitersdk/samples/ProjectApollo/src_launch/RemoteSiteProcessor.h @@ -0,0 +1,64 @@ +/*************************************************************************** + 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 +#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 { +public: + PCMTelemetryProcessor(std::deque* buffer, std::vector* output, std::mutex *mtex); + ~PCMTelemetryProcessor(); + + PCMDecommFormat* HBR_Format; + PCMDecommFormat* LBR_Format; + + std::deque* TelemetryBuffer; + std::vector* TelemetryOutput; + std::mutex* BufferMutex; + + void ProcessTelemetry(); + std::thread ProcessorThread; + bool runProcessor; +}; + + + + +#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..d6f5efd5e2 --- /dev/null +++ b/Orbitersdk/samples/ProjectApollo/src_launch/TelemetryDownlink.cpp @@ -0,0 +1,49 @@ +/*************************************************************************** + 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" +#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((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; + } +} \ 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 5c02b62481..5cbbcb7063 100644 --- a/Orbitersdk/samples/ProjectApollo/src_launch/mcc.cpp +++ b/Orbitersdk/samples/ProjectApollo/src_launch/mcc.cpp @@ -148,6 +148,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(){ @@ -599,6 +606,10 @@ void MCC::Init(){ // Uplink items uplink_size = 0; logfileinit = false; + + CSM_TelemetryBuffer = { 0 }; + LEM_TelemetryBuffer = { 0 }; + //IU_TelemetryBuffer = { 0 }; } void MCC::setState(int newState){ @@ -618,6 +629,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 +662,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 89e837283d..a1d325bf34 100644 --- a/Orbitersdk/samples/ProjectApollo/src_launch/mcc.h +++ b/Orbitersdk/samples/ProjectApollo/src_launch/mcc.h @@ -27,7 +27,10 @@ #include "MCCPADForms.h" #include #include +#include +#include #include "thread.h" +#include "RemoteSiteProcessor.h" // Save file strings #define MCC_START_STRING "MCC_BEGIN" @@ -241,6 +244,7 @@ class RTCC; class MCC { public: MCC(RTCC *rtc); // Cons + ~MCC(); char CSMName[64]; char LEMName[64]; @@ -265,6 +269,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 @@ -327,6 +332,25 @@ class MCC { bool GT_Enabled; // Ground tracking enable/disable bool MT_Enabled; // Mission status tracking enable/disable + //TELEMETRY PROCESSING +private: + std::deque CSM_TelemetryBuffer; //Type 1 + std::deque 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 int MissionState; // Major state