Skip to content

Commit

Permalink
several fixes, added CMakeLists.txt and NetSDREmu
Browse files Browse the repository at this point in the history
* added 'basic' NetSDR emulation tool, streaming single carrier
* fixed timing, when to report 16/24 bit sampleformat to SDR software
* fixed compilation on Linux gcc, compiler warnings, ..

Signed-off-by: hayati ayguen <[email protected]>
  • Loading branch information
hayguen committed May 16, 2018
1 parent 54618bc commit ac700ad
Show file tree
Hide file tree
Showing 12 changed files with 642 additions and 159 deletions.
4 changes: 2 additions & 2 deletions ExtIO_NetSDR/ExtIO_NetSDR.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>Ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<Version>2018.2</Version>
<Version>2018.3</Version>
<ModuleDefinitionFile>..\src\ExtIO_RFspaceNetSDR.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
Expand All @@ -90,7 +90,7 @@
<GenerateDebugInformation>false</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<Version>2018.2</Version>
<Version>2018.3</Version>
<ModuleDefinitionFile>..\src\ExtIO_RFspaceNetSDR.def</ModuleDefinitionFile>
<StripPrivateSymbols>/PDBSTRIPPED</StripPrivateSymbols>
<AssemblyDebug>false</AssemblyDebug>
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ The hardware receiver was manufactured by RFspace.

See http://www.rfspace.com/

This software is dedicated only for the NetSDR model, which is out-of-production - NOT the 'plus' model.
This software was initially developed for for the NetSDR model.
It does also run with the NetSDR+.

Network protocol specification for the interface is available at
http://www.moetronix.com/svdownload.htm
Expand Down
125 changes: 125 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(extio)


SET(CLSOCKET_HEADERS
../../clsocket/src/ActiveSocket.h
../../clsocket/src/Host.h
../../clsocket/src/PassiveSocket.h
../../clsocket/src/SimpleSocket.h
../../clsocket/src/StatTimer.h
)

SET(CLSOCKET_SOURCES
../../clsocket/src/SimpleSocket.cpp
../../clsocket/src/PassiveSocket.cpp
)


SET(TTPP_HEADERS
../../tinythreadpp/source/tinythread.h
../../tinythreadpp/source/fast_mutex.h
)

SET(TTPP_SOURCES
../../tinythreadpp/source/tinythread.cpp
)


SET(EXTIO_HEADERS
ExtIO_Logging.h
ExtIO_RFspaceNetSDR.h
LC_ExtIO_Types.h
procitec_replacements.h
rfspace_netsdr_control.h
rfspace_netsdr_receiver.h
rfspace_netsdr_udpdata.h
)

SET(EXTIO_SOURCES
ExtIO_Logging.cpp
ExtIO_RFspaceNetSDR.cpp
procitec_replacements.cpp
rfspace_netsdr_control.cpp
rfspace_netsdr_receiver.cpp
rfspace_netsdr_udpdata.cpp
)

SET(NETSDREMU_HEADERS
LC_ExtIO_Types.h
ExtIO_Logging.h
rfspace_netsdr_control.h
)

SET(NETSDREMU_SOURCES
NetSDREmu.cpp
ExtIO_Logging.cpp
rfspace_netsdr_control.cpp
)


INCLUDE_DIRECTORIES( ../../clsocket/src ../../tinythreadpp/source )

# mark headers as headers...
SET_SOURCE_FILES_PROPERTIES( ${CLSOCKET_HEADERS} PROPERTIES HEADER_FILE_ONLY TRUE )
SET_SOURCE_FILES_PROPERTIES( ${TTPP_HEADERS} PROPERTIES HEADER_FILE_ONLY TRUE )
SET_SOURCE_FILES_PROPERTIES( ${EXTIO_HEADERS} PROPERTIES HEADER_FILE_ONLY TRUE )
SET_SOURCE_FILES_PROPERTIES( ${NETSDREMU_HEADERS} PROPERTIES HEADER_FILE_ONLY TRUE )

# append to sources so that dependency checks work on headers
LIST(APPEND CLSOCKET_SOURCES ${CLSOCKET_HEADERS})
LIST(APPEND TTPP_SOURCES ${TTPP_HEADERS})
LIST(APPEND EXTIO_SOURCES ${EXTIO_HEADERS})
LIST(APPEND NETSDREMU_SOURCES ${NETSDREMU_HEADERS})

add_definitions(-DEXTIO_EXPORTS)

# OS and compiler checks.
if(UNIX)
# linux / normal unix
add_definitions(-D_LINUX)
if(CYGWIN)
# Special Cygwin stuff here
elseif(APPLE)
# Special Apple stuff here
remove_definitions(-D_LINUX)
add_definitions(-D_DARWIN)
endif()
# assume GCC on Unix/Linux - here shared linking is no real issue
#set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -static -s")
#set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS} -static -s")
elseif(WIN32)
add_definitions(-DWIN32)
SET(PROJECT_LIBS Ws2_32.lib)
if(MINGW)
# Special MINGW stuff here
OPTION(CLSOCKET_OWN_INET_PTON "Use own inet_pton() implementation (required on MINGW)" ON)
if(CLSOCKET_OWN_INET_PTON)
add_definitions(-DCLSOCKET_OWN_INET_PTON)
endif()
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -static -static-libgcc -s")
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS} -static -static-libgcc -static-libstdc++ -s")
elseif(MSVC)
# Special MSVC stuff here
add_definitions(-D_WINSOCK_DEPRECATED_NO_WARNINGS)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -MT")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -MT")
set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -MT")
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -MT")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -MT")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -MT")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -MTd")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -MTd")
else()
# No idea what it is, but there's a good chance it's too weird.
MESSAGE( FATAL_ERROR "Using unknown WIN32 compiler... NOT. Please add to build system." )
endif()
endif()


ADD_LIBRARY( ExtIO_RFspaceNetSDR SHARED ${EXTIO_SOURCES} ${CLSOCKET_SOURCES} ${TTPP_SOURCES} )
TARGET_LINK_LIBRARIES( ExtIO_RFspaceNetSDR ${PROJECT_LIBS} )

ADD_EXECUTABLE( netsdremu ${NETSDREMU_SOURCES} ${CLSOCKET_SOURCES} )
TARGET_LINK_LIBRARIES( netsdremu ${PROJECT_LIBS} )

106 changes: 10 additions & 96 deletions src/ExtIO_RFspaceNetSDR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,100 +99,6 @@ static void ReceiverThreadProc( void* lpParameter )
}
gbExitControlThread = false;
gbControlThreadRunning = false;
return;

bool bProtocolOrTimeoutError = false;
while ( !gbExitControlThread )
{
//if ( !gbBoundTcpDataPort )
{
// wait until TCP data port is bound, when using TCP protocol
tthread::this_thread::sleep_for( tthread::chrono::milliseconds( 10 ) );
gpoReceiver->TimerProc(uiWaitMs);
continue;
}
if ( bProtocolOrTimeoutError )
{
// wait with reconnect .. until NetSDR might get ready!
LOG_PRO( LOG_PROTOCOL, "ControlThreadProc(): waiting 10 seconds before reconnecting to RFspace NetSDR");
tthread::this_thread::sleep_for( tthread::chrono::milliseconds( 10000 ) );
bProtocolOrTimeoutError = false;
}

uint64_t lastStrmCheck = currentMSecsSinceEpoch();
uint64_t lastRcvCheck = currentMSecsSinceEpoch();

// pre-processing
if ( true )
{
LOG_PRO( LOG_NORMAL, "ControlThreadProc(): established = OK" );

while ( 1 )
{
LOG_PRO( LOG_NORMAL, "ControlThreadProc()" );

LOG_PRO( LOG_NORMAL, "ControlThreadProc(): controlling to frq %.1f kHz with BW %.1f kHz with ATT %d dB"
, gpoSettings->iFrequency / 1000.0
, gpoSettings->uiBandwidth / 1000.0
, giRcvMGC
);
}

// restart
gbDataStreamTimeout = false;

break;
}

if ( !bProtocolOrTimeoutError )
{
LOG_PRO( LOG_NORMAL, "ControlThreadProc(): was STREAM ACTIVATED! Data reception can start. DataPort is %s"
, ( gbBoundTcpDataPort ? "bound" : "unbound" ) );
gbDataStreamActivated = true;

giLastRcvFreq = 0; // oConn.getLastReceiverFreq();
giLastRcvBW = 0; // oConn.getLastReceiverBW();
gbHaveLastRcvFreqAndBW = ( giLastRcvBW > 0 );
if ( giLastRcvBW <= 0 )
{
LOG_PRO( LOG_PROTOCOL, "ControlThreadProc(): received ReceiverBandWidth <= 0!" );
}
}

// processing
{
bool bExitProcLoop = bProtocolOrTimeoutError;
while ( !gbExitControlThread && !bExitProcLoop )
{
uint64_t uiCurr = currentMSecsSinceEpoch();
if ( ( uiCurr - lastStrmCheck ) >= 2000 )
{
//oConn.requestStreamState();
lastStrmCheck = uiCurr;
}
if ( ( uiCurr - lastRcvCheck ) >= 5000 )
{

lastRcvCheck = uiCurr;
}
if ( gbDataStreamTimeout )
{
gbDataStreamTimeout = false;
LOG_PRO( LOG_NORMAL, "ControlThreadProc(): STREAM TIMEOUT! Restarting .. " );
lastStrmCheck = uiCurr;
}
}
}

// post-processing

if ( gbExitControlThread )
break;
tthread::this_thread::sleep_for( tthread::chrono::milliseconds( 1000 ) );
}

gbExitControlThread = false;
gbControlThreadRunning = false;
}


Expand Down Expand Up @@ -348,6 +254,14 @@ int64_t EXTIO_CALL StartHW64( int64_t LOfreq )

LOG_PRO( LOG_DEBUG, "StartHW64(): %s", (bStartOK ? "successful":"failed") );

if (0)
{
int sampleFmt = gpoReceiver->getExtHwSampleFormat();
int bitDepth = gpoReceiver->getExtHwBitDepth();
LOG_PRO(LOG_PROTOCOL, "SEND STATUS CHANGE AT START TO SDR: NEW BIT DEPTH %d Bit.", bitDepth);
EXTIO_STATUS_CHANGE(gpfnExtIOCallbackPtr, sampleFmt);
}

// number of complex elements returned each
// invocation of the callback routine
return RFspaceNetReceiver::EXT_BLOCKLEN;
Expand Down Expand Up @@ -386,11 +300,11 @@ int EXTIO_CALL SetHWLO( long LOfreq )

int64_t EXTIO_CALL SetHWLO64( int64_t LOfreq )
{
LOG_PRO( LOG_DEBUG, "************************************** SetHWLO(%d) *********************************", LOfreq);
LOG_PRO( LOG_DEBUG, "************************************** SetHWLO(%ld) *********************************", long(LOfreq));
LOG_PRO( LOG_DEBUG, "SetHWLO64(%ld Hz) called", long(LOfreq) );
if ( !gpoReceiver )
{
LOG_PRO( LOG_DEBUG, "SetHWLO64(): ERROR: No Receiver", LOfreq);
LOG_PRO( LOG_DEBUG, "SetHWLO64(): ERROR: No Receiver");
return 1; // Error
}
gpoReceiver->setHWLO(LOfreq);
Expand Down
5 changes: 5 additions & 0 deletions src/LC_ExtIO_Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@
*
*/

#ifndef WIN32
#define __cdecl
#define __stdcall
#endif

// function implemented by Winrad / HDSDR; see enum extHWstatusT below
// IQoffs is no longer used (HDSDR >= 2.75), if ever used by any ExtIO!
// DC offset correction can be done inside HDSDR
Expand Down
Loading

0 comments on commit ac700ad

Please sign in to comment.