Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<ClInclude Include="..\..\src_rtccmfd\TLIProcessor.h" />
<ClInclude Include="..\..\src_rtccmfd\TLMCC.h" />
<ClInclude Include="..\..\src_rtccmfd\RTCCTables.h" />
<ClInclude Include="..\..\src_sys\socket.h" />
<ClInclude Include="..\..\src_rtccmfd\TLTrajectoryComputers.h" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -68,6 +69,7 @@
<ClCompile Include="..\..\src_rtccmfd\TLIGuidanceSim.cpp" />
<ClCompile Include="..\..\src_rtccmfd\TLIProcessor.cpp" />
<ClCompile Include="..\..\src_rtccmfd\TLMCC.cpp" />
<ClCompile Include="..\..\src_sys\socket.cpp" />
<ClCompile Include="..\..\src_rtccmfd\TLTrajectoryComputers.cpp" />
<ClCompile Include="..\..\src_sys\thread.cpp" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@
<ClInclude Include="..\..\src_aux\nassputils.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src_sys\socket.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src_rtccmfd\TLIProcessor.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down Expand Up @@ -179,6 +182,9 @@
<ClCompile Include="..\..\src_sys\thread.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src_sys\socket.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src_rtccmfd\TLIProcessor.cpp">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down
1 change: 1 addition & 0 deletions Orbitersdk/samples/ProjectApollo/Build/VC2017/LEM.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="..\..\src_sys\pyro.cpp" />
<ClCompile Include="..\..\src_sys\socket.cpp" />
<ClCompile Include="..\..\src_sys\soundevents.cpp" />
<ClCompile Include="..\..\src_sys\soundlib.cpp">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@
<ClCompile Include="..\..\src_sys\inertial.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src_sys\socket.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 @@ -157,6 +157,7 @@
<ClInclude Include="..\..\src_mfd\ProjectApolloChecklistMFD.h" />
<ClInclude Include="..\..\src_mfd\ProjectApolloMFD.h" />
<ClInclude Include="..\..\src_mfd\ProjectApolloPlugin.h" />
<ClInclude Include="..\..\src_sys\socket.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\src_mfd\MFDResources.rc">
Expand All @@ -179,6 +180,7 @@
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="..\..\src_mfd\ProjectApolloPlugin.cpp" />
<ClCompile Include="..\..\src_sys\socket.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
<ClInclude Include="..\..\src_aux\nassputils.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src_sys\socket.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\src_mfd\MFDResources.rc">
Expand Down Expand Up @@ -72,5 +75,8 @@
<ClCompile Include="..\..\src_mfd\ProjectApolloMFDButtons.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src_sys\socket.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DebugInformationFormat Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ClCompile Include="..\..\src_sys\socket.cpp" />
<ClCompile Include="..\..\src_sys\soundevents.cpp">
<DebugInformationFormat Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">ProgramDatabase</DebugInformationFormat>
</ClCompile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@
<ClCompile Include="..\..\src_sys\inertial.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src_sys\socket.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src_aux\CueCard.cpp">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="..\..\src_sys\socket.cpp" />
<ClCompile Include="..\..\src_sys\soundevents.cpp" />
<ClCompile Include="..\..\src_sys\soundlib.cpp">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
Expand Down Expand Up @@ -474,6 +475,7 @@
<ClInclude Include="..\..\src_saturn\sii.h" />
<ClInclude Include="..\..\src_saturn\sivb.h" />
<ClInclude Include="..\..\src_csm\sm.h" />
<ClInclude Include="..\..\src_sys\socket.h" />
<ClInclude Include="..\..\src_sys\soundevents.h" />
<ClInclude Include="..\..\src_sys\soundlib.h" />
<ClInclude Include="..\..\src_csm\sps.h" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@
<ClCompile Include="..\..\src_sys\inertial.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src_sys\socket.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src_aux\CueCardManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down Expand Up @@ -470,6 +473,9 @@
<ClInclude Include="..\..\src_sys\inertial.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src_sys\socket.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src_aux\CueCardManager.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down
157 changes: 42 additions & 115 deletions Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "Orbitersdk.h"
#include <stdio.h>
#include <math.h>
#include <winsock.h> // TODO: Replace with winsock2 after yaAGC updates
#include "soundlib.h"
#include "resource.h"
#include "nasspdefs.h"
Expand Down Expand Up @@ -2025,15 +2024,10 @@ PCM::PCM()
last_rx = 0;
frame_addr = 0;
frame_count = 0;
m_socket = INVALID_SOCKET;
}

PCM::~PCM()
{
if (m_socket != INVALID_SOCKET) {
shutdown(m_socket, 2); // Shutdown both streams
closesocket(m_socket);
}
}

void PCM::Init(Saturn *vessel){
Expand All @@ -2045,46 +2039,16 @@ void PCM::Init(Saturn *vessel){
last_update = 0;
last_rx = MINUS_INFINITY;
word_addr = 0;
int iResult = WSAStartup( MAKEWORD(2,2), &wsaData );
if ( iResult != NO_ERROR ){
sprintf(wsk_emsg,"TELECOM: Error at WSAStartup()");
wsk_error = 1;
return;
}
m_socket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
if ( m_socket == INVALID_SOCKET ) {
sprintf(wsk_emsg,"TELECOM: Error at socket(): %ld", WSAGetLastError());
WSACleanup();
wsk_error = 1;
return;
}
// Be nonblocking
int iMode = 1; // 0 = BLOCKING, 1 = NONBLOCKING
if(ioctlsocket(m_socket, FIONBIO, (u_long FAR*) &iMode) != 0){
sprintf(wsk_emsg,"TELECOM: ioctlsocket() failed: %ld", WSAGetLastError());
if (!NetStartup()){
sprintf(wsk_emsg,"TELECOM: Error at NetStartup()");
wsk_error = 1;
closesocket(m_socket);
WSACleanup();
return;
}

// Set up incoming options
service.sin_family = AF_INET;
service.sin_addr.s_addr = htonl(INADDR_ANY);
service.sin_port = htons( 14242 );

if ( ::bind( m_socket, (SOCKADDR*) &service, sizeof(service) ) == SOCKET_ERROR ) {
sprintf(wsk_emsg,"Failed to start CSM telemetry. Please completely exit Orbiter and restart. Please file a bug report if this message persists.");
wsk_error = 1;
closesocket(m_socket);
WSACleanup();
return;
}
if ( listen( m_socket, 1 ) == SOCKET_ERROR ){
m_tcpserver = TcpService(14242); // CM on 14242, LM on 14243
if (m_tcpserver.Status() != TcpService::STARTED) {
sprintf(wsk_emsg, "TELECOM: Error starting server: %d", m_tcpserver.ErrorCode());
wsk_error = 1;
sprintf(wsk_emsg,"TELECOM: listen() failed: %ld", WSAGetLastError());
closesocket(m_socket);
WSACleanup();
return;
}

Expand Down Expand Up @@ -4996,73 +4960,52 @@ void PCM::perform_io(double simt){
}
}else{
// Try to accept
AcceptSocket = accept( m_socket, NULL, NULL );
if(AcceptSocket != INVALID_SOCKET){
m_connection = m_tcpserver.Accept();
if(m_connection.Status() == TcpConnection::CONNECTED){
conn_state = 2; // Accept this!
wsk_error = 0; // For now
}
}
// Otherwise loop and try again.
break;
case 2: // CONNECTED
int bytesSent,bytesRecv;

bytesSent = send(AcceptSocket, (char *)tx_data, tx_size, 0 );
if(bytesSent == SOCKET_ERROR){
long errnumber = WSAGetLastError();
switch(errnumber){
// KNOWN CODES that we can ignore
case 10035: // Operation Would Block
// We can ignore this entirely. It's not an error.
break;

case 10038: // Socket isn't a socket
case 10053: // Software caused connection abort
case 10054: // Connection reset by peer
closesocket(AcceptSocket);
conn_state = 1; // Accept another
uplink_state = 0; rx_offset = 0;
break;

default: // If unknown
wsk_error = 1; // do this
sprintf(wsk_emsg,"TELECOM: send() failed: %ld",errnumber);
closesocket(AcceptSocket);
conn_state = 1; // Accept another
uplink_state = 0; rx_offset = 0;
break;
}
case 2: // CONNECTED
switch (m_connection.Send((char*)tx_data, tx_size)) {
case TcpConnection::CONNECTION_ERROR:
conn_state = 1; // Accept another
uplink_state = 0; rx_offset = 0;
break;
case TcpConnection::UNEXPECTED_ERROR:
conn_state = 1; // Accept another
uplink_state = 0; rx_offset = 0;
wsk_error = 1;
sprintf(wsk_emsg, "CSM-TELECOM: Send failed : %d", m_connection.ErrorCode());
break;
default:
break;
}
// Should we recieve?

// Should we receive?
if ((fabs(simt - last_rx) / 0.005) < 1 || sat->agc.InterruptPending(ApolloGuidance::Interrupt::UPRUPT)) {
return; // No
}
last_rx = simt;
bytesRecv = recv( AcceptSocket, (char *)(rx_data+rx_offset), 1, 0 );
if(bytesRecv == SOCKET_ERROR){
long errnumber = WSAGetLastError();
switch(errnumber){
// KNOWN CODES that we can ignore
case 10035: // Operation Would Block
// We can ignore this entirely. It's not an error.
break;

case 10053: // Software caused connection abort
case 10038: // Socket isn't a socket
case 10054: // Connection reset by peer
closesocket(AcceptSocket);
conn_state = 1; // Accept another
uplink_state = 0; rx_offset = 0;
break;

default: // If unknown
wsk_error = 1; // do this
sprintf(wsk_emsg,"TELECOM: recv() failed: %ld",errnumber);
closesocket(AcceptSocket);
conn_state = 1; // Accept another
uplink_state = 0; rx_offset = 0;
break;
TcpConnection::CommandStatus status = m_connection.RecvChar((char *)(rx_data+rx_offset));
if(status != TcpConnection::OK){
switch (status) {
case TcpConnection::CONNECTION_ERROR:
conn_state = 1; // Accept another
uplink_state = 0; rx_offset = 0;
break;
case TcpConnection::UNEXPECTED_ERROR:
conn_state = 1; // Accept another
uplink_state = 0; rx_offset = 0;
wsk_error = 1;
sprintf(wsk_emsg, "CSM-TELECOM: Recv failed : %d", m_connection.ErrorCode());
break;
default:
break;
}

// Do we have data from MCC instead?
if (mcc_size > 0) {
// Yes. Take a byte
Expand All @@ -5079,28 +5022,12 @@ void PCM::perform_io(double simt){
mcc_offset = mcc_size = 0;
}
}
}else{
} else {
// If the telemetry data-path is disconnected
if(sat->UPTLMSwitch1.GetState() == TOGGLESWITCH_DOWN){
if(sat->UPTLMSwitch1.GetState() == TOGGLESWITCH_DOWN) {
return; // Discard the data
}
if(bytesRecv > 0){
handle_uplink();
} else {
// Do we have data from MCC instead?
if (mcc_size > 0) {
// Yes. Take a byte
rx_data[rx_offset] = mcc_data[mcc_offset];
mcc_offset++;
// Handle it
handle_uplink();
// Are we done?
if (mcc_offset >= mcc_size) {
// We reached the end of the MCC buffer.
mcc_offset = mcc_size = 0;
}
}
}
handle_uplink();
}
break;
}
Expand Down
9 changes: 4 additions & 5 deletions Orbitersdk/samples/ProjectApollo/src_csm/csm_telecom.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "RF_calc.h"
#include "paCBGmessageID.h"
#include "socket.h"

/* PCM DOWN-TELEMETRY

Expand Down Expand Up @@ -342,11 +343,9 @@ class PCM {
void TimeStep(double simt); // TimeStep
void SystemTimestep(double simdt); // System Timestep (consume power)

// Winsock2
WSADATA wsaData; // Winsock subsystem data
SOCKET m_socket; // TCP socket
sockaddr_in service; // SOCKADDR_IN
SOCKET AcceptSocket; // Accept Socket
// Network
TcpService m_tcpserver;
TcpConnection m_connection;
int conn_state; // Connection State
int uplink_state; // Uplink State
void perform_io(double simt); // Get data from here to there
Expand Down
Loading