The attached patch replaces CTB with native calls on Win32 and *nix
systems (ie: Linux, OS X, FreeBSD, etc).
It also contains a small tweak to the CMakeLists file to allow searching
for portaudio in the default place that FreeBSD places it. Since
portaudio 1.7 and portaudio 2 can coexist, FreeBSD places it in
/usr/local/(lib|include)/portaudio2. The included change allows
locating it there as a hint.
I haven't actually tested the Win32 code yet since I currently don't
have a Windows box set up with a serial connection to something I can
test. If nobody else tests it first, I'll likely drag out a break-out
box and test it this weekend using a multimeter or something.
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt (revision 1468)
+++ CMakeLists.txt (working copy)
@@ -64,8 +64,6 @@
"Download and build static samplerate instead of the system library.")
set(USE_STATIC_SOX FALSE CACHE BOOL
"Download and build static sox instead of the system library.")
-set(USE_STATIC_LIBCTB FALSE CACHE BOOL
- "Download and build static libctb instead of the system library.")
set(USE_STATIC_CODEC2 FALSE CACHE BOOL
"Download and build static codec2 instead of the system library.")
set(BOOTSTRAP_WXWIDGETS FALSE CACHE BOOL
@@ -76,7 +74,6 @@
set(USE_STATIC_SNDFILE TRUE FORCE)
set(USE_STATIC_SAMPLERATE TRUE FORCE)
set(USE_STATIC_SOX TRUE FORCE)
- set(USE_STATIC_LIBCTB TRUE FORCE)
set(USE_STATIC_CODEC2 TRUE FORCE)
endif(USE_STATIC_DEPS)
@@ -133,7 +130,6 @@
libcodec2.dll
libportaudio-2.dll
libportaudiocpp-0.dll
- libctb-0.16.dll
libsox-2.dll
zlib1.dll
libusb0.dll
@@ -207,8 +203,8 @@
#
if(NOT USE_STATIC_PORTAUDIO)
message(STATUS "Looking for portaudio...")
- find_library(PORTAUDIO_LIBS NAMES libportaudio-2.dll portaudio)
- find_path(PORTAUDIO_INCLUDE_DIR portaudio.h)
+ find_library(PORTAUDIO_LIBS NAMES libportaudio-2.dll portaudio HINTS /usr/local/lib/portaudio2)
+ find_path(PORTAUDIO_INCLUDE_DIR portaudio.h HINTS /usr/local/include/portaudio2)
message(STATUS " portaudio library: ${PORTAUDIO_LIBS}")
message(STATUS " portaudio headers: ${PORTAUDIO_INCLUDE_DIR}")
if(PORTAUDIO_LIBS AND PORTAUDIO_INCLUDE_DIR)
@@ -395,47 +391,7 @@
include(cmake/BuildCodec2.cmake)
endif(NOT USE_STATIC_CODEC2)
-#
-# Find libctb. Assumes version 0.16
-#
-if(NOT USE_STATIC_LIBCTB)
- message(STATUS "Looking for libctb...")
- find_path(LIBCTB_INCLUDE_DIR NAMES ctb.h ctb-0.16/ctb.h)
- find_library(LIBCTB_LIBRARY NAMES ctb ctb-0.16)
- message(STATUS " libctb library: ${LIBCTB_LIBRARY}")
- message(STATUS " libctb headers: ${LIBCTB_INCLUDE_DIR}")
- if(LIBCTB_LIBRARY AND LIBCTB_INCLUDE_DIR)
- set(CMAKE_REQUIRED_LIBRARIES ${LIBCTB_LIBRARY})
- if(NOT CMAKE_CROSSCOMPILING)
- # Check to make sure linking with libctb works.
- include(CheckCXXSourceCompiles)
- check_cxx_source_compiles("
- #include <ctb-0.16/ctb.h>
- int main() {
- ctb::SerialPort* m_serialPort;
- m_serialPort = new ctb::SerialPort();
- };"
- LIBCTB_LINKS)
- if(NOT LIBCTB_LINKS)
- message(FATAL_ERROR "Linking libctb failed.")
- endif(NOT LIBCTB_LINKS)
- endif(NOT CMAKE_CROSSCOMPILING)
- else(LIBCTB_LIBRARY AND LIBCTB_INCLUDE_DIR)
- message(FATAL_ERROR "libctb not found.
-Linux:
- libctb may not be available in your distribution. Either build and install or use the cmake option to build statically.
-Windws:
-It's easiest to use the cmake option: USE_STATIC_LIBCTB"
- )
- endif(LIBCTB_LIBRARY AND LIBCTB_INCLUDE_DIR)
-else(NOT USE_STATIC_LIBCTB)
- include(cmake/BuildLibctb.cmake)
-endif(NOT USE_STATIC_LIBCTB)
-include_directories(${LIBCTB_INCLUDE_DIR})
-list(APPEND FREEDV_LINK_LIBS ${LIBCTB_LIBRARY})
-
-
# Freedv
add_subdirectory(src)
Index: src/fdmdv2_main.cpp
===================================================================
--- src/fdmdv2_main.cpp (revision 1468)
+++ src/fdmdv2_main.cpp (working copy)
@@ -323,6 +323,7 @@
wxGetApp().m_boolRTSPos = pConfig->ReadBool(wxT("/Rig/RTSPolarity"), true);
wxGetApp().m_boolUseDTR = pConfig->ReadBool(wxT("/Rig/UseDTR"), false);
wxGetApp().m_boolDTRPos = pConfig->ReadBool(wxT("/Rig/DTRPolarity"), false);
+ com_handle = COM_HANDLE_INVALID;
// -----------------------------------------------------------------------
@@ -556,6 +557,162 @@
delete wxConfigBase::Set((wxConfigBase *) NULL);
}
+//----------------------------------------------------------------
+// closeComPort() closes the currently open com port
+//----------------------------------------------------------------
+void MainFrame::closeComPort(void)
+{
+#ifdef _WIN32
+ CloseHandle(com_handle);
+#else
+ close(com_handle);
+#endif
+ com_handle = COM_HANDLE_INVALID;
+}
+
+//----------------------------------------------------------------
+// openComPort() opens the com port specified by the string
+// ie: "COM1" on Windows or "/dev/ttyu0" on FreeBSD
+//----------------------------------------------------------------
+bool MainFrame::openComPort(const char *name)
+{
+ if(com_handle != COM_HANDLE_INVALID)
+ closeComPort();
+#ifdef _WIN32
+ {
+ COMMTIMEOUTS timeouts;
+ DCB dcb;
+
+ if((com_handle=CreateFile(name
+ ,GENERIC_READ|GENERIC_WRITE /* Access */
+ ,0 /* Share mode */
+ ,NULL /* Security attributes */
+ ,OPEN_EXISTING /* Create access */
+ ,FILE_ATTRIBUTE_NORMAL /* File attributes */
+ ,NULL /* Template */
+ ))==INVALID_HANDLE_VALUE)
+ return false;
+
+ if(GetCommTimeouts(com_handle, &timeouts)) {
+ timeouts.ReadIntervalTimeout=MAXDWORD;
+ timeouts.ReadTotalTimeoutMultiplier=0;
+ timeouts.ReadTotalTimeoutConstant=0; // No-wait read timeout
+ timeouts.WriteTotalTimeoutMultiplier=0;
+ timeouts.WriteTotalTimeoutConstant=5000; // 5 seconds
+ SetCommTimeouts(com_handle,&timeouts);
+ }
+
+ /* Force N-8-1 mode: */
+ if(GetCommState(com_handle, &dcb)==TRUE) {
+ dcb.ByteSize = 8;
+ dcb.Parity = NOPARITY;
+ dcb.StopBits = ONESTOPBIT;
+ SetCommState(com_handle, &dcb);
+ }
+ }
+#else
+ {
+ struct termios t;
+
+ if((com_handle=open(name, O_NONBLOCK|O_RDWR))==COM_HANDLE_INVALID)
+ return false;
+
+ if(tcgetattr(com_handle, &t)==-1) {
+ close(com_handle);
+ com_handle = COM_HANDLE_INVALID;
+ return false;
+ }
+
+ t.c_iflag = (
+ IGNBRK /* ignore BREAK condition */
+ | IGNPAR /* ignore (discard) parity errors */
+ );
+ t.c_oflag = 0; /* No output processing */
+ t.c_cflag = (
+ CS8 /* 8 bits */
+ | CREAD /* enable receiver */
+ /*
+ Fun snippet from the FreeBSD manpage:
+
+ If CREAD is set, the receiver is enabled. Otherwise, no character is
+ received. Not all hardware supports this bit. In fact, this flag is
+ pretty silly and if it were not part of the termios specification it
+ would be omitted.
+ */
+ | CLOCAL /* ignore modem status lines */
+ );
+ t.c_lflag = 0; /* No local modes */
+ if(tcsetattr(com_handle, TCSANOW, &t)==-1) {
+ close(com_handle);
+ com_handle = COM_HANDLE_INVALID;
+ return false;
+ }
+
+ }
+#endif
+ return true;
+}
+
+
+//----------------------------------------------------------------
+// (raise|lower)(RTS|DTR)()
+//
+// Raises/lowers the specified signal
+//----------------------------------------------------------------
+void MainFrame::raiseDTR(void)
+{
+ if(com_handle == COM_HANDLE_INVALID)
+ return;
+#ifdef _WIN32
+ EscapeCommFunction(com_handle, SETDTR);
+#else
+ { // For C89 happiness
+ int flags = TIOCM_DTR;
+ ioctl(com_handle, TIOCMBIS, &flags);
+ }
+#endif
+}
+void MainFrame::raiseRTS(void)
+{
+ if(com_handle == COM_HANDLE_INVALID)
+ return;
+#ifdef _WIN32
+ EscapeCommFunction(com_handle, SETRTS);
+#else
+ { // For C89 happiness
+ int flags = TIOCM_RTS;
+ ioctl(com_handle, TIOCMBIS, &flags);
+ }
+#endif
+}
+void MainFrame::lowerDTR(void)
+{
+ if(com_handle == COM_HANDLE_INVALID)
+ return;
+#ifdef _WIN32
+ EscapeCommFunction(com_handle, CLRDTR);
+#else
+ { // For C89 happiness
+ int flags = TIOCM_DTR;
+ ioctl(com_handle, TIOCMBIC, &flags);
+ }
+#endif
+}
+void MainFrame::lowerRTS(void)
+{
+ if(com_handle == COM_HANDLE_INVALID)
+ return;
+#ifdef _WIN32
+ EscapeCommFunction(com_handle, CLRRTS);
+#else
+ { // For C89 happiness
+ int flags = TIOCM_RTS;
+ ioctl(com_handle, TIOCMBIC, &flags);
+ }
+#endif
+}
+
+
#ifdef _USE_TIMER
//----------------------------------------------------------------
// OnTimer()
@@ -976,20 +1133,20 @@
exclusive NOR
*/
- if(wxGetApp().m_boolUseSerialPTT && m_serialPort != NULL) {
+ if(wxGetApp().m_boolUseSerialPTT && com_handle != COM_HANDLE_INVALID) {
if (wxGetApp().m_boolUseRTS) {
printf("g_tx: %d m_boolRTSPos: %d serialLine: %d\n", g_tx, wxGetApp().m_boolRTSPos, g_tx == wxGetApp().m_boolRTSPos);
if (g_tx == wxGetApp().m_boolRTSPos)
- m_serialPort->SetLineState(ctb::LinestateRts);
+ raiseRTS();
else
- m_serialPort->ClrLineState(ctb::LinestateRts);
+ lowerRTS();
}
if (wxGetApp().m_boolUseDTR) {
printf("g_tx: %d m_boolDTRPos: %d serialLine: %d\n", g_tx, wxGetApp().m_boolDTRPos, g_tx == wxGetApp().m_boolDTRPos);
if (g_tx == wxGetApp().m_boolDTRPos)
- m_serialPort->SetLineState(ctb::LinestateDtr);
+ raiseDTR();
else
- m_serialPort->ClrLineState(ctb::LinestateDtr);
+ lowerDTR();
}
}
@@ -3091,25 +3248,16 @@
//----------------------------------------------------------------
void MainFrame::SetupSerialPort(void)
{
- long baudrate;
-
- baudrate = 10;
if(!wxGetApp().m_strRigCtrlPort.IsEmpty())
{
- wxString protocol = _("8N1");
- m_serialPort = new ctb::SerialPort();
- if(m_serialPort->Open(wxGetApp().m_strRigCtrlPort.c_str(), baudrate, protocol.c_str(), ctb::SerialPort::NoFlowControl ) >= 0 )
+ if(openComPort(wxGetApp().m_strRigCtrlPort.c_str()))
{
- m_device = m_serialPort;
// always start PTT in Rx state
SerialPTTRx();
}
else
{
- m_serialPort = NULL;
- m_device = NULL;
wxMessageBox("Couldn't open Serial Port", wxT("About"), wxOK | wxICON_ERROR, this);
-
}
}
}
@@ -3120,14 +3268,14 @@
wxGetApp().m_boolUseRTS, wxGetApp().m_boolRTSPos, wxGetApp().m_boolUseDTR, wxGetApp().m_boolDTRPos);
if(wxGetApp().m_boolRTSPos) // RTS cleared LOW
- m_serialPort->ClrLineState(ctb::LinestateRts);
+ lowerRTS();
else // RTS cleared HIGH
- m_serialPort->SetLineState(ctb::LinestateRts);
+ raiseRTS();
if(wxGetApp().m_boolDTRPos) // DTR cleared LOW
- m_serialPort->ClrLineState(ctb::LinestateDtr);
+ lowerDTR();
else // DTR cleared HIGH
- m_serialPort->SetLineState(ctb::LinestateDtr);
+ raiseDTR();
}
//----------------------------------------------------------------
@@ -3135,15 +3283,11 @@
//----------------------------------------------------------------
void MainFrame::CloseSerialPort(void)
{
- if (m_serialPort != NULL) {
+ if (com_handle != COM_HANDLE_INVALID) {
// always end with PTT in rx state
SerialPTTRx();
- if((m_serialPort != NULL) && m_serialPort->IsOpen()) {
- m_serialPort->Close();
- m_serialPort = NULL;
- m_device = NULL;
- }
+ closeComPort();
}
}
Index: src/fdmdv2_main.h
===================================================================
--- src/fdmdv2_main.h (revision 1468)
+++ src/fdmdv2_main.h (working copy)
@@ -52,10 +52,11 @@
#include <samplerate.h>
#include <hamlib.h>
-#include "ctb-0.16/ctb.h"
-#include "ctb-0.16/portscan.h"
-#include "ctb-0.16/serportx.h"
-#include "ctb-0.16/serport.h"
+#ifdef _WIN32
+#include <windows.h>
+#else
+#include <termios.h>
+#endif
#include "codec2.h"
#include "codec2_fdmdv.h"
@@ -97,6 +98,14 @@
#define EXCHANGE_DATA_IN 0
#define EXCHANGE_DATA_OUT 1
+#ifdef _WIN32
+#define COM_HANDLE_INVALID INVALID_HANDLE_VALUE
+typedef HANDLE com_handle_t;
+#else
+#define COM_HANDLE_INVALID -1
+typedef int com_handle_t;
+#endif
+
extern int g_nSoundCards;
extern int g_soundCard1InDeviceNum;
extern int g_soundCard1OutDeviceNum;
@@ -375,8 +384,19 @@
protected:
- ctb::IOBase* m_device;
- ctb::SerialPort* m_serialPort;
+#ifdef _WIN32
+#define COM_HANDLE_INVALID INVALID_HANDLE_VALUE
+ com_handle_t com_handle;
+#else
+#define COM_HANDLE_INVALID -1
+ com_handle_t com_handle;
+#endif
+ void raiseDTR(void);
+ void lowerDTR(void);
+ void raiseRTS(void);
+ void lowerRTS(void);
+ bool openComPort(const char *port);
+ void closeComPort(void);
void setsnrBeta(bool snrSlow);
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Freetel-codec2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freetel-codec2