diff --git a/modem/NullModem.cpp b/modem/NullModem.cpp deleted file mode 100644 index 28a9d00e..00000000 --- a/modem/NullModem.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/** -* Digital Voice Modem - Host Software -* GPLv2 Open Source. Use is subject to license terms. -* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -* -* @package DVM / Host Software -* -*/ -// -// Based on code from the MMDVMHost project. (https://github.com/g4klx/MMDVMHost) -// Licensed under the GPLv2 License (https://opensource.org/licenses/GPL-2.0) -// -/* -* Copyright (C) 2011-2017 by Jonathan Naylor G4KLX -* Copyright (C) 2017-2020 by Bryan Biedenkapp N2PLL -* -* This program 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. -* -* This program 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 this program; if not, write to the Free Software -* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ -#include "Defines.h" -#include "modem/NullModem.h" -#include "Log.h" - -using namespace modem; - -// --------------------------------------------------------------------------- -// Public Class Members -// --------------------------------------------------------------------------- -/// -/// Initializes a new instance of the NullModem class. -/// -/// Serial port the modem DSP is connected to. -/// Flag indicating the modem is operating in duplex mode. -/// Flag indicating the Rx polarity should be inverted. -/// Flag indicating the Tx polarity should be inverted. -/// Flag indicating the PTT polarity should be inverted. -/// Flag indicating whether the DSP DC-level blocking should be enabled. -/// Flag indicating whether the COS signal should be used to lockout the modem. -/// Count of FDMA preambles to transmit before data. (P25/DMR DMO) -/// Compensate for delay in receiver audio chain in ms. Usually DSP based. -/// P25 Correlation Countdown. -/// Length of time in MS between packets to send to modem. -/// Flag indicating whether the ADC/DAC overflow reset logic is disabled. -/// Flag indicating whether modem DSP trace is enabled. -/// Flag indicating whether modem DSP debug is enabled. -NullModem::NullModem(const std::string& port, bool duplex, bool rxInvert, bool txInvert, bool pttInvert, bool dcBlocker, - bool cosLockout, uint8_t fdmaPreamble, uint8_t dmrRxDelay, uint8_t p25CorrCount, uint8_t packetPlayoutTime, bool disableOFlowReset, bool trace, bool debug) : - Modem(port, duplex, rxInvert, txInvert, pttInvert, dcBlocker, cosLockout, fdmaPreamble, dmrRxDelay, p25CorrCount, packetPlayoutTime, disableOFlowReset, trace, debug) -{ - /* stub */ -} - -/// -/// Finalizes a instance of the NullModem class. -/// -NullModem::~NullModem() -{ - /* stub */ -} - -/// -/// Opens connection to the modem DSP. -/// -/// True, if connection to modem is established, otherwise false. -bool NullModem::open() -{ - LogMessage(LOG_MODEM, "Initializing NULL modem"); - return true; -} diff --git a/modem/NullModem.h b/modem/NullModem.h deleted file mode 100644 index 19318aaf..00000000 --- a/modem/NullModem.h +++ /dev/null @@ -1,106 +0,0 @@ -/** -* Digital Voice Modem - Host Software -* GPLv2 Open Source. Use is subject to license terms. -* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -* -* @package DVM / Host Software -* -*/ -// -// Based on code from the MMDVMHost project. (https://github.com/g4klx/MMDVMHost) -// Licensed under the GPLv2 License (https://opensource.org/licenses/GPL-2.0) -// -/* -* Copyright (C) 2011-2017 by Jonathan Naylor G4KLX -* Copyright (C) 2017-2020 by Bryan Biedenkapp N2PLL -* -* This program 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. -* -* This program 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 this program; if not, write to the Free Software -* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ -#if !defined(__NULL_MODEM_H__) -#define __NULL_MODEM_H__ - -#include "Defines.h" -#include "modem/Modem.h" - -namespace modem -{ - // --------------------------------------------------------------------------- - // Class Declaration - // Implements the interface to a null modem. - // --------------------------------------------------------------------------- - - class HOST_SW_API NullModem : public Modem { - public: - /// Initializes a new instance of the NullModem class. - NullModem(const std::string& port, bool duplex, bool rxInvert, bool txInvert, bool pttInvert, bool dcBlocker, - bool cosLockout, uint8_t fdmaPreamble, uint8_t dmrRxDelay, uint8_t p25CorrCount, uint8_t packetPlayoutTime, bool disableOFlowReset, bool trace, bool debug); - /// Finalizes a instance of the NullModem class. - ~NullModem(); - - /// Sets the modem DSP RF DC offset parameters. - virtual void setDCOffsetParams(int txDCOffset, int rxDCOffset) { return; } - /// Sets the modem DSP enabled modes. - virtual void setModeParams(bool dmrEnabled, bool p25Enabled) { return; } - /// Sets the modem DSP RF deviation levels. - virtual void setLevels(float rxLevel, float cwIdTXLevel, float dmrTXLevel, float p25TXLevel) { return; } - /// Sets the modem DSP Symbol adjustment levels - virtual void setSymbolAdjust(int dmrSymLevel3Adj, int dmrSymLevel1Adj, int p25SymLevel3Adj, int p25SymLevel1Adj) { return; } - /// Sets the modem DSP DMR color code. - virtual void setDMRColorCode(uint32_t colorCode) { return; } - /// Sets the modem DSP RF receive deviation levels. - virtual void setRXLevel(float rxLevel) { return; } - - /// Opens connection to the modem DSP. - virtual bool open(); - - /// Updates the timer by the passed number of milliseconds. - virtual void clock(uint32_t ms) { return; } - - /// Closes connection to the modem DSP. - virtual void close() { return; } - - /// Flag indicating whether or not the modem DSP is transmitting. - virtual bool hasTX() const { return false; } - /// Flag indicating whether or not the modem DSP has carrier detect. - virtual bool hasCD() const { return false; } - - /// Flag indicating whether or not the modem DSP is currently locked out. - virtual bool hasLockout() const { return false; } - /// Flag indicating whether or not the modem DSP is currently in an error condition. - virtual bool hasError() const { return false; } - - /// Writes DMR Slot 1 frame data to the DMR Slot 1 ring buffer. - virtual bool writeDMRData1(const uint8_t* data, uint32_t length) { return true; } - /// Writes DMR Slot 2 frame data to the DMR Slot 2 ring buffer. - virtual bool writeDMRData2(const uint8_t* data, uint32_t length) { return true; } - /// Writes P25 frame data to the P25 ring buffer. - virtual bool writeP25Data(const uint8_t* data, uint32_t length) { return true; } - - /// Triggers the start of DMR transmit. - virtual bool writeDMRStart(bool tx) { return true; } - /// Writes a DMR short LC to the modem DSP. - virtual bool writeDMRShortLC(const uint8_t* lc) { return true; } - /// Writes a DMR abort message for the given slot to the modem DSP. - virtual bool writeDMRAbort(uint32_t slotNo) { return true; } - - /// Sets the current operating mode for the modem DSP. - virtual bool setMode(DVM_STATE state) { return true; } - - /// Transmits the given string as CW morse. - virtual bool sendCWId(const std::string& callsign) { return true; } - }; -} // namespace modem - -#endif // __NULL_MODEM_H__ diff --git a/modem/SerialController.cpp b/modem/SerialController.cpp deleted file mode 100644 index 7a12768a..00000000 --- a/modem/SerialController.cpp +++ /dev/null @@ -1,530 +0,0 @@ -/** -* Digital Voice Modem - Host Software -* GPLv2 Open Source. Use is subject to license terms. -* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -* -* @package DVM / Host Software -* -*/ -// -// Based on code from the MMDVMHost project. (https://github.com/g4klx/MMDVMHost) -// Licensed under the GPLv2 License (https://opensource.org/licenses/GPL-2.0) -// -/* -* Copyright (C) 2002-2004,2007-2011,2013,2014-2017 by Jonathan Naylor G4KLX -* Copyright (C) 1999-2001 by Thomas Sailor HB9JNX -* Copyright (C) 2020 by Bryan Biedenkapp N2PLL -* -* This program 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. -* -* This program 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 this program; if not, write to the Free Software -* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ -#include "Defines.h" -#include "modem/SerialController.h" -#include "Log.h" - -using namespace modem; - -#include -#include - -#include - -#if defined(_WIN32) || defined(_WIN64) -#include -#include -#else -#include -#include -#include -#include -#include -#include -#endif - -// --------------------------------------------------------------------------- -// Public Class Members -// --------------------------------------------------------------------------- - -#if defined(_WIN32) || defined(_WIN64) -/// -/// Initializes a new instance of the CSerialController class. -/// -/// Serial port device. -/// Serial port speed. -/// -CSerialController::CSerialController() : - m_handle(INVALID_HANDLE_VALUE) -{ - /* stub */ -} - -/// -/// Initializes a new instance of the CSerialController class. -/// -/// Serial port device. -/// Serial port speed. -/// -CSerialController::CSerialController(const std::string& device, SERIAL_SPEED speed, bool assertRTS) : - m_device(device), - m_speed(speed), - m_assertRTS(assertRTS), - m_handle(INVALID_HANDLE_VALUE) -{ - assert(!device.empty()); -} - -/// -/// Finalizes a instance of the CSerialController class. -/// -CSerialController::~CSerialController() -{ - /* stub */ -} - -/// -/// Opens a connection to the serial port. -/// -/// True, if connection is opened, otherwise false. -bool CSerialController::open() -{ - assert(!m_device.empty()); - assert(m_handle == INVALID_HANDLE_VALUE); - - DWORD errCode; - - // Convert "\\.\COM10" to "COM10" - std::string baseName = m_device.substr(4U); - - m_handle = ::CreateFileA(m_device.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (m_handle == INVALID_HANDLE_VALUE) { - LogError(LOG_MODEM, "Cannot open device - %s, err=%04lx", m_device.c_str(), ::GetLastError()); - return false; - } - - DCB dcb; - if (::GetCommState(m_handle, &dcb) == 0) { - LogError(LOG_MODEM, "Cannot get the attributes for %s, err=%04lx", m_device.c_str(), ::GetLastError()); - ::ClearCommError(m_handle, &errCode, NULL); - ::CloseHandle(m_handle); - return false; - } - - dcb.BaudRate = DWORD(m_speed); - dcb.ByteSize = 8; - dcb.Parity = NOPARITY; - dcb.fParity = FALSE; - dcb.StopBits = ONESTOPBIT; - dcb.fInX = FALSE; - dcb.fOutX = FALSE; - dcb.fOutxCtsFlow = FALSE; - dcb.fOutxDsrFlow = FALSE; - dcb.fDsrSensitivity = FALSE; - dcb.fDtrControl = DTR_CONTROL_DISABLE; - dcb.fRtsControl = RTS_CONTROL_DISABLE; - - if (::SetCommState(m_handle, &dcb) == 0) { - LogError(LOG_MODEM, "Cannot set the attributes for %s, err=%04lx", m_device.c_str(), ::GetLastError()); - ::ClearCommError(m_handle, &errCode, NULL); - ::CloseHandle(m_handle); - return false; - } - - COMMTIMEOUTS timeouts; - if (!::GetCommTimeouts(m_handle, &timeouts)) { - LogError(LOG_MODEM, "Cannot get the timeouts for %s, err=%04lx", m_device.c_str(), ::GetLastError()); - ::ClearCommError(m_handle, &errCode, NULL); - ::CloseHandle(m_handle); - return false; - } - - timeouts.ReadIntervalTimeout = MAXDWORD; - timeouts.ReadTotalTimeoutMultiplier = 0UL; - timeouts.ReadTotalTimeoutConstant = 0UL; - - if (!::SetCommTimeouts(m_handle, &timeouts)) { - LogError(LOG_MODEM, "Cannot set the timeouts for %s, err=%04lx", m_device.c_str(), ::GetLastError()); - ::ClearCommError(m_handle, &errCode, NULL); - ::CloseHandle(m_handle); - return false; - } - - if (::EscapeCommFunction(m_handle, CLRDTR) == 0) { - LogError(LOG_MODEM, "Cannot clear DTR for %s, err=%04lx", m_device.c_str(), ::GetLastError()); - ::ClearCommError(m_handle, &errCode, NULL); - ::CloseHandle(m_handle); - return false; - } - - if (::EscapeCommFunction(m_handle, m_assertRTS ? SETRTS : CLRRTS) == 0) { - LogError(LOG_MODEM, "Cannot set/clear RTS for %s, err=%04lx", m_device.c_str(), ::GetLastError()); - ::ClearCommError(m_handle, &errCode, NULL); - ::CloseHandle(m_handle); - return false; - } - - ::ClearCommError(m_handle, &errCode, NULL); - - return true; -} - -/// -/// Reads data from the serial port. -/// -/// Buffer to read data from the serial port to. -/// Length of data to read from the serial port. -/// Actual length of data read from serial port. -int CSerialController::read(uint8_t* buffer, uint32_t length) -{ - assert(m_handle != INVALID_HANDLE_VALUE); - assert(buffer != NULL); - - uint32_t ptr = 0U; - - while (ptr < length) { - int ret = readNonblock(buffer + ptr, length - ptr); - if (ret < 0) { - return ret; - } - else if (ret == 0) { - if (ptr == 0U) - return 0; - } - else { - ptr += ret; - } - } - - return int(length); -} - -/// -/// Writes data to the serial port. -/// -/// Buffer containing data to write to serial port. -/// Length of data to write to serial port. -/// Actual length of data written to the serial port. -int CSerialController::write(const uint8_t* buffer, uint32_t length) -{ - assert(m_handle != INVALID_HANDLE_VALUE); - assert(buffer != NULL); - - if (length == 0U) - return 0; - - uint32_t ptr = 0U; - - while (ptr < length) { - DWORD bytes = 0UL; - BOOL ret = ::WriteFile(m_handle, buffer + ptr, length - ptr, &bytes, NULL); - if (!ret) { - LogError(LOG_MODEM, "Error from WriteFile for %s: %04lx", m_device.c_str(), ::GetLastError()); - return -1; - } - - ptr += bytes; - } - - return int(length); -} - -/// -/// Closes the connection to the serial port. -/// -void CSerialController::close() -{ - assert(m_handle != INVALID_HANDLE_VALUE); - - ::CloseHandle(m_handle); - m_handle = INVALID_HANDLE_VALUE; -} -#else -/// -/// Initializes a new instance of the CSerialController class. -/// -/// Serial port device. -/// Serial port speed. -/// -CSerialController::CSerialController() : - m_fd(-1) -{ - /* stub */ -} -/// -/// Initializes a new instance of the CSerialController class. -/// -/// Serial port device. -/// Serial port speed. -/// -CSerialController::CSerialController(const std::string& device, SERIAL_SPEED speed, bool assertRTS) : - m_device(device), - m_speed(speed), - m_assertRTS(assertRTS), - m_fd(-1) -{ - assert(!device.empty()); -} - -/// -/// Finalizes a instance of the CSerialController class. -/// -CSerialController::~CSerialController() -{ - /* stub */ -} - -/// -/// Opens a connection to the serial port. -/// -/// True, if connection is opened, otherwise false. -bool CSerialController::open() -{ - assert(!m_device.empty()); - assert(m_fd == -1); - - m_fd = ::open(m_device.c_str(), O_RDWR | O_NOCTTY | O_NDELAY, 0); - if (m_fd < 0) { - LogError(LOG_MODEM, "Cannot open device - %s", m_device.c_str()); - return false; - } - - if (::isatty(m_fd) == 0) { - LogError(LOG_MODEM, "%s is not a TTY device", m_device.c_str()); - ::close(m_fd); - return false; - } - - termios termios; - if (::tcgetattr(m_fd, &termios) < 0) { - LogError(LOG_MODEM, "Cannot get the attributes for %s", m_device.c_str()); - ::close(m_fd); - return false; - } - - termios.c_lflag &= ~(ECHO | ECHOE | ICANON | IEXTEN | ISIG); - termios.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON | IXOFF | IXANY); - termios.c_cflag &= ~(CSIZE | CSTOPB | PARENB | CRTSCTS); - termios.c_cflag |= CS8; - termios.c_oflag &= ~(OPOST); - termios.c_cc[VMIN] = 0; - termios.c_cc[VTIME] = 10; - - switch (m_speed) { - case SERIAL_1200: - ::cfsetospeed(&termios, B1200); - ::cfsetispeed(&termios, B1200); - break; - case SERIAL_2400: - ::cfsetospeed(&termios, B2400); - ::cfsetispeed(&termios, B2400); - break; - case SERIAL_4800: - ::cfsetospeed(&termios, B4800); - ::cfsetispeed(&termios, B4800); - break; - case SERIAL_9600: - ::cfsetospeed(&termios, B9600); - ::cfsetispeed(&termios, B9600); - break; - case SERIAL_19200: - ::cfsetospeed(&termios, B19200); - ::cfsetispeed(&termios, B19200); - break; - case SERIAL_38400: - ::cfsetospeed(&termios, B38400); - ::cfsetispeed(&termios, B38400); - break; - case SERIAL_115200: - ::cfsetospeed(&termios, B115200); - ::cfsetispeed(&termios, B115200); - break; - case SERIAL_230400: - ::cfsetospeed(&termios, B230400); - ::cfsetispeed(&termios, B230400); - break; - default: - LogError(LOG_MODEM, "Unsupported serial port speed - %d", int(m_speed)); - ::close(m_fd); - return false; - } - - if (::tcsetattr(m_fd, TCSANOW, &termios) < 0) { - LogError(LOG_MODEM, "Cannot set the attributes for %s", m_device.c_str()); - ::close(m_fd); - return false; - } - - if (m_assertRTS) { - uint32_t y; - if (::ioctl(m_fd, TIOCMGET, &y) < 0) { - LogError(LOG_MODEM, "Cannot get the control attributes for %s", m_device.c_str()); - ::close(m_fd); - return false; - } - - y |= TIOCM_RTS; - - if (::ioctl(m_fd, TIOCMSET, &y) < 0) { - LogError(LOG_MODEM, "Cannot set the control attributes for %s", m_device.c_str()); - ::close(m_fd); - return false; - } - } - - return true; -} - -/// -/// Reads data from the serial port. -/// -/// Buffer to read data from the serial port to. -/// Length of data to read from the serial port. -/// Actual length of data read from serial port. -int CSerialController::read(uint8_t* buffer, uint32_t length) -{ - assert(buffer != NULL); - assert(m_fd != -1); - - if (length == 0U) - return 0; - - uint32_t offset = 0U; - - while (offset < length) { - fd_set fds; - FD_ZERO(&fds); - FD_SET(m_fd, &fds); - - int n; - if (offset == 0U) { - struct timeval tv; - tv.tv_sec = 0; - tv.tv_usec = 0; - - n = ::select(m_fd + 1, &fds, NULL, NULL, &tv); - if (n == 0) - return 0; - } - else { - n = ::select(m_fd + 1, &fds, NULL, NULL, NULL); - } - - if (n < 0) { - LogError(LOG_MODEM, "Error from select(), errno=%d", errno); - return -1; - } - - if (n > 0) { - ssize_t len = ::read(m_fd, buffer + offset, length - offset); - if (len < 0) { - if (errno != EAGAIN) { - LogError(LOG_MODEM, "Error from read(), errno=%d", errno); - return -1; - } - } - - if (len > 0) - offset += len; - } - } - - return length; -} - -/// -/// Writes data to the serial port. -/// -/// Buffer containing data to write to serial port. -/// Length of data to write to serial port. -/// Actual length of data written to the serial port. -int CSerialController::write(const uint8_t* buffer, uint32_t length) -{ - assert(buffer != NULL); - assert(m_fd != -1); - - if (length == 0U) - return 0; - - uint32_t ptr = 0U; - - while (ptr < length) { - ssize_t n = ::write(m_fd, buffer + ptr, length - ptr); - if (n < 0) { - if (errno != EAGAIN) { - LogError(LOG_MODEM, "Error returned from write(), errno=%d", errno); - return -1; - } - } - - if (n > 0) - ptr += n; - } - - return length; -} - -/// -/// Closes the connection to the serial port. -/// -void CSerialController::close() -{ - assert(m_fd != -1); - - ::close(m_fd); - m_fd = -1; -} -#endif - -// --------------------------------------------------------------------------- -// Private Class Members -// --------------------------------------------------------------------------- - -#if defined(_WIN32) || defined(_WIN64) -/// -/// -/// -/// -/// -/// -int CSerialController::readNonblock(uint8_t* buffer, uint32_t length) -{ - assert(m_handle != INVALID_HANDLE_VALUE); - assert(buffer != NULL); - - if (length == 0U) - return 0; - - DWORD errors; - COMSTAT status; - if (::ClearCommError(m_handle, &errors, &status) == 0) { - LogError(LOG_MODEM, "Error from ClearCommError for %s, err=%04lx", m_device.c_str(), ::GetLastError()); - return -1; - } - - if (status.cbInQue == 0UL) - return 0; - - DWORD readLength = status.cbInQue; - if (length < readLength) - readLength = length; - - DWORD bytes = 0UL; - BOOL ret = ::ReadFile(m_handle, buffer, readLength, &bytes, NULL); - if (!ret) { - LogError(LOG_MODEM, "Error from ReadFile for %s: %04lx", m_device.c_str(), ::GetLastError()); - return -1; - } - - return int(bytes); -} -#endif diff --git a/modem/SerialController.h b/modem/SerialController.h deleted file mode 100644 index e6802fb8..00000000 --- a/modem/SerialController.h +++ /dev/null @@ -1,105 +0,0 @@ -/** -* Digital Voice Modem - Host Software -* GPLv2 Open Source. Use is subject to license terms. -* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -* -* @package DVM / Host Software -* -*/ -// -// Based on code from the MMDVMHost project. (https://github.com/g4klx/MMDVMHost) -// Licensed under the GPLv2 License (https://opensource.org/licenses/GPL-2.0) -// -/* -* Copyright (C) 2002-2004,2007-2009,2011-2013,2015-2017 by Jonathan Naylor G4KLX -* Copyright (C) 1999-2001 by Thomas Sailor HB9JNX -* Copyright (C) 2020 by Bryan Biedenkapp N2PLL -* -* This program 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. -* -* This program 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 this program; if not, write to the Free Software -* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ -#if !defined(__SERIAL_CONTROLLER_H__) -#define __SERIAL_CONTROLLER_H__ - -#include "Defines.h" - -#include - -#if defined(_WIN32) || defined(_WIN64) -#define WIN32_LEAN_AND_MEAN -#include -#endif - -namespace modem -{ - // --------------------------------------------------------------------------- - // Constants - // --------------------------------------------------------------------------- - - enum SERIAL_SPEED { - SERIAL_1200 = 1200, - SERIAL_2400 = 2400, - SERIAL_4800 = 4800, - SERIAL_9600 = 9600, - SERIAL_19200 = 19200, - SERIAL_38400 = 38400, - SERIAL_76800 = 76800, - SERIAL_115200 = 115200, - SERIAL_230400 = 230400 - }; - - // --------------------------------------------------------------------------- - // Class Declaration - // This class implements low-level routines to communicate over a RS232 - // serial port. - // --------------------------------------------------------------------------- - - class HOST_SW_API CSerialController { - public: - /// Initializes a new instance of the CSerialController class. - CSerialController(); - /// Initializes a new instance of the CSerialController class. - CSerialController(const std::string& device, SERIAL_SPEED speed, bool assertRTS = false); - /// Finalizes a instance of the CSerialController class. - virtual ~CSerialController(); - - /// Opens a connection to the serial port. - virtual bool open(); - - /// Reads data from the serial port. - virtual int read(uint8_t* buffer, uint32_t length); - /// Writes data to the serial port. - virtual int write(const uint8_t* buffer, uint32_t length); - - /// Closes the connection to the serial port. - virtual void close(); - - private: - std::string m_device; - SERIAL_SPEED m_speed; - bool m_assertRTS; -#if defined(_WIN32) || defined(_WIN64) - HANDLE m_handle; -#else - int m_fd; -#endif - -#if defined(_WIN32) || defined(_WIN64) - /// - int readNonblock(uint8_t * buffer, uint32_t length); -#endif - }; -} // namespace Modem - -#endif // __SERIAL_CONTROLLER_H__