Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Orbitersdk/samples/ProjectApollo/Build/VC2017/MCC.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
<ClCompile Include="..\..\src_launch\MCC_Mission_G.cpp" />
<ClCompile Include="..\..\src_launch\MCC_Mission_H1.cpp" />
<ClCompile Include="..\..\src_launch\MCC_Mission_SL.cpp" />
<ClCompile Include="..\..\src_launch\RemoteSiteProcessor.cpp" />
<ClCompile Include="..\..\src_launch\rtcc.cpp" />
<ClCompile Include="..\..\src_launch\RTCC_Mission_B.cpp" />
<ClCompile Include="..\..\src_launch\RTCC_Mission_C.cpp" />
Expand All @@ -170,6 +171,7 @@
<ClCompile Include="..\..\src_launch\RTCC_Mission_G.cpp" />
<ClCompile Include="..\..\src_launch\RTCC_Mission_H1.cpp" />
<ClCompile Include="..\..\src_launch\RTCC_Mission_SL.cpp" />
<ClCompile Include="..\..\src_launch\TelemetryDownlink.cpp" />
<ClCompile Include="..\..\src_rtccmfd\AnalyticEphemerisGenerator.cpp" />
<ClCompile Include="..\..\src_rtccmfd\ApolloGeneralizedOpticsProgram.cpp" />
<ClCompile Include="..\..\src_rtccmfd\AscentRendezvousMonitor.cpp" />
Expand Down Expand Up @@ -211,6 +213,7 @@
<ClInclude Include="..\..\src_launch\MCC_Mission_G.h" />
<ClInclude Include="..\..\src_launch\MCC_Mission_H1.h" />
<ClInclude Include="..\..\src_launch\MCC_Mission_SL.h" />
<ClInclude Include="..\..\src_launch\RemoteSiteProcessor.h" />
<ClInclude Include="..\..\src_launch\rtcc.h" />
<ClInclude Include="..\..\src_rtccmfd\AnalyticEphemerisGenerator.h" />
<ClInclude Include="..\..\src_rtccmfd\ApolloGeneralizedOpticsProgram.h" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@
<ClCompile Include="..\..\src_aux\Mission.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src_launch\RemoteSiteProcessor.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src_launch\TelemetryDownlink.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src_launch\mcc.h">
Expand Down Expand Up @@ -275,5 +281,8 @@
<ClInclude Include="..\..\src_aux\Mission.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src_launch\RemoteSiteProcessor.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
<ClCompile Include="..\..\src_csm\rhc.cpp" />
<ClCompile Include="..\..\src_csm\sce.cpp" />
<ClCompile Include="..\..\src_csm\smjc.cpp" />
<ClCompile Include="..\..\src_launch\TelemetryDownlink.cpp" />
<ClCompile Include="..\..\src_rtccmfd\OrbMech.cpp" />
<ClCompile Include="..\..\src_saturn\canard.cpp" />
<ClCompile Include="..\..\src_saturn\dcs.cpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@
<ClCompile Include="..\..\src_csm\eps.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src_launch\TelemetryDownlink.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src_sys\apolloguidance.h">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
<ClCompile Include="..\..\src_csm\rhc.cpp" />
<ClCompile Include="..\..\src_csm\sce.cpp" />
<ClCompile Include="..\..\src_csm\smjc.cpp" />
<ClCompile Include="..\..\src_launch\TelemetryDownlink.cpp" />
<ClCompile Include="..\..\src_rtccmfd\OrbMech.cpp" />
<ClCompile Include="..\..\src_saturn\canard.cpp" />
<ClCompile Include="..\..\src_saturn\dcs.cpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@
<ClCompile Include="..\..\src_csm\eps.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src_launch\TelemetryDownlink.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src_sys\apolloguidance.h">
Expand Down
36 changes: 33 additions & 3 deletions Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1998,6 +1998,7 @@ PCM::PCM()
frame_addr = 0;
frame_count = 0;
m_socket = INVALID_SOCKET;
pMCC = nullptr;
}

PCM::~PCM()
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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){
Expand All @@ -2143,15 +2155,15 @@ 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){
tx_offset = 0;
while(tx_offset < tx_size){
generate_stream_hbr();
tx_offset++;
}
}
perform_io(simt);
}
}
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

#include "RF_calc.h"
#include "paCBGmessageID.h"
#include "mcc.h"
#include "mccvessel.h"

/* PCM DOWN-TELEMETRY

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<uint8_t>* buffer, std::vector<uint8_t>* 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;
}
}
}
}
64 changes: 64 additions & 0 deletions Orbitersdk/samples/ProjectApollo/src_launch/RemoteSiteProcessor.h
Original file line number Diff line number Diff line change
@@ -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 <cstdint>
#include <array>
#include <vector>
#include <thread>
#include <deque>
#include <mutex>

#ifndef _PA_REMOTE_SITE_PROCESSOR
#define _PA_REMOTE_SITE_PROCESSOR


struct PCMDecommFormat {
std::array<uint8_t, 3> SyncWords;
uint8_t FrameLength;
uint8_t NumWords;
};


class PCMTelemetryProcessor {
public:
PCMTelemetryProcessor(std::deque<uint8_t>* buffer, std::vector<uint8_t>* output, std::mutex *mtex);
~PCMTelemetryProcessor();

PCMDecommFormat* HBR_Format;
PCMDecommFormat* LBR_Format;

std::deque<uint8_t>* TelemetryBuffer;
std::vector<uint8_t>* TelemetryOutput;
std::mutex* BufferMutex;

void ProcessTelemetry();
std::thread ProcessorThread;
bool runProcessor;
};




#endif // !_PA_REMOTE_SITE_PROCESSOR
49 changes: 49 additions & 0 deletions Orbitersdk/samples/ProjectApollo/src_launch/TelemetryDownlink.cpp
Original file line number Diff line number Diff line change
@@ -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 <mutex>

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;
}
}
Loading