Merge pull request #442 from Hootie81/VK6MST_Shield
Add support for VK6MST_Shield
This commit is contained in:
commit
d16a06db07
7 changed files with 86 additions and 12 deletions
16
Conf.cpp
16
Conf.cpp
|
@ -87,6 +87,8 @@ m_dmrIdLookupTime(0U),
|
||||||
m_nxdnIdLookupFile(),
|
m_nxdnIdLookupFile(),
|
||||||
m_nxdnIdLookupTime(0U),
|
m_nxdnIdLookupTime(0U),
|
||||||
m_modemPort(),
|
m_modemPort(),
|
||||||
|
m_modemProtocol("uart"),
|
||||||
|
m_modemAddress(0x22),
|
||||||
m_modemRXInvert(false),
|
m_modemRXInvert(false),
|
||||||
m_modemTXInvert(false),
|
m_modemTXInvert(false),
|
||||||
m_modemPTTInvert(false),
|
m_modemPTTInvert(false),
|
||||||
|
@ -405,6 +407,10 @@ bool CConf::read()
|
||||||
} else if (section == SECTION_MODEM) {
|
} else if (section == SECTION_MODEM) {
|
||||||
if (::strcmp(key, "Port") == 0)
|
if (::strcmp(key, "Port") == 0)
|
||||||
m_modemPort = value;
|
m_modemPort = value;
|
||||||
|
else if (::strcmp(key, "Protocol") == 0)
|
||||||
|
m_modemProtocol = value;
|
||||||
|
else if (::strcmp(key, "Address") == 0)
|
||||||
|
m_modemAddress = (unsigned int)::strtoul(value, NULL, 16);
|
||||||
else if (::strcmp(key, "RXInvert") == 0)
|
else if (::strcmp(key, "RXInvert") == 0)
|
||||||
m_modemRXInvert = ::atoi(value) == 1;
|
m_modemRXInvert = ::atoi(value) == 1;
|
||||||
else if (::strcmp(key, "TXInvert") == 0)
|
else if (::strcmp(key, "TXInvert") == 0)
|
||||||
|
@ -913,6 +919,16 @@ std::string CConf::getModemPort() const
|
||||||
return m_modemPort;
|
return m_modemPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CConf::getModemProtocol() const
|
||||||
|
{
|
||||||
|
return m_modemProtocol;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int CConf::getModemAddress() const
|
||||||
|
{
|
||||||
|
return m_modemAddress;
|
||||||
|
}
|
||||||
|
|
||||||
bool CConf::getModemRXInvert() const
|
bool CConf::getModemRXInvert() const
|
||||||
{
|
{
|
||||||
return m_modemRXInvert;
|
return m_modemRXInvert;
|
||||||
|
|
4
Conf.h
4
Conf.h
|
@ -70,6 +70,8 @@ public:
|
||||||
|
|
||||||
// The Modem section
|
// The Modem section
|
||||||
std::string getModemPort() const;
|
std::string getModemPort() const;
|
||||||
|
std::string getModemProtocol() const;
|
||||||
|
unsigned int getModemAddress() const;
|
||||||
bool getModemRXInvert() const;
|
bool getModemRXInvert() const;
|
||||||
bool getModemTXInvert() const;
|
bool getModemTXInvert() const;
|
||||||
bool getModemPTTInvert() const;
|
bool getModemPTTInvert() const;
|
||||||
|
@ -292,6 +294,8 @@ private:
|
||||||
unsigned int m_nxdnIdLookupTime;
|
unsigned int m_nxdnIdLookupTime;
|
||||||
|
|
||||||
std::string m_modemPort;
|
std::string m_modemPort;
|
||||||
|
std::string m_modemProtocol;
|
||||||
|
unsigned int m_modemAddress;
|
||||||
bool m_modemRXInvert;
|
bool m_modemRXInvert;
|
||||||
bool m_modemTXInvert;
|
bool m_modemTXInvert;
|
||||||
bool m_modemPTTInvert;
|
bool m_modemPTTInvert;
|
||||||
|
|
|
@ -1045,6 +1045,8 @@ int CMMDVMHost::run()
|
||||||
bool CMMDVMHost::createModem()
|
bool CMMDVMHost::createModem()
|
||||||
{
|
{
|
||||||
std::string port = m_conf.getModemPort();
|
std::string port = m_conf.getModemPort();
|
||||||
|
std::string protocol = m_conf.getModemProtocol();
|
||||||
|
unsigned int address = m_conf.getModemAddress();
|
||||||
bool rxInvert = m_conf.getModemRXInvert();
|
bool rxInvert = m_conf.getModemRXInvert();
|
||||||
bool txInvert = m_conf.getModemTXInvert();
|
bool txInvert = m_conf.getModemTXInvert();
|
||||||
bool pttInvert = m_conf.getModemPTTInvert();
|
bool pttInvert = m_conf.getModemPTTInvert();
|
||||||
|
@ -1074,6 +1076,10 @@ bool CMMDVMHost::createModem()
|
||||||
|
|
||||||
LogInfo("Modem Parameters");
|
LogInfo("Modem Parameters");
|
||||||
LogInfo(" Port: %s", port.c_str());
|
LogInfo(" Port: %s", port.c_str());
|
||||||
|
if (protocol == "i2c"){
|
||||||
|
LogInfo(" Protocol: %s", protocol.c_str());
|
||||||
|
LogInfo(" i2c Address: %u", address);
|
||||||
|
}
|
||||||
LogInfo(" RX Invert: %s", rxInvert ? "yes" : "no");
|
LogInfo(" RX Invert: %s", rxInvert ? "yes" : "no");
|
||||||
LogInfo(" TX Invert: %s", txInvert ? "yes" : "no");
|
LogInfo(" TX Invert: %s", txInvert ? "yes" : "no");
|
||||||
LogInfo(" PTT Invert: %s", pttInvert ? "yes" : "no");
|
LogInfo(" PTT Invert: %s", pttInvert ? "yes" : "no");
|
||||||
|
@ -1095,7 +1101,7 @@ bool CMMDVMHost::createModem()
|
||||||
LogInfo(" RX Frequency: %uHz (%uHz)", rxFrequency, rxFrequency + rxOffset);
|
LogInfo(" RX Frequency: %uHz (%uHz)", rxFrequency, rxFrequency + rxOffset);
|
||||||
LogInfo(" TX Frequency: %uHz (%uHz)", txFrequency, txFrequency + txOffset);
|
LogInfo(" TX Frequency: %uHz (%uHz)", txFrequency, txFrequency + txOffset);
|
||||||
|
|
||||||
m_modem = new CModem(port, m_duplex, rxInvert, txInvert, pttInvert, txDelay, dmrDelay, trace, debug);
|
m_modem = new CModem(port, protocol, address, m_duplex, rxInvert, txInvert, pttInvert, txDelay, dmrDelay, trace, debug);
|
||||||
m_modem->setModeParams(m_dstarEnabled, m_dmrEnabled, m_ysfEnabled, m_p25Enabled, m_nxdnEnabled, m_pocsagEnabled);
|
m_modem->setModeParams(m_dstarEnabled, m_dmrEnabled, m_ysfEnabled, m_p25Enabled, m_nxdnEnabled, m_pocsagEnabled);
|
||||||
m_modem->setLevels(rxLevel, cwIdTXLevel, dstarTXLevel, dmrTXLevel, ysfTXLevel, p25TXLevel, nxdnTXLevel, pocsagTXLevel);
|
m_modem->setLevels(rxLevel, cwIdTXLevel, dstarTXLevel, dmrTXLevel, ysfTXLevel, p25TXLevel, nxdnTXLevel, pocsagTXLevel);
|
||||||
m_modem->setRFParams(rxFrequency, rxOffset, txFrequency, txOffset, txDCOffset, rxDCOffset, rfLevel, pocsagFrequency);
|
m_modem->setRFParams(rxFrequency, rxOffset, txFrequency, txOffset, txDCOffset, rxDCOffset, rfLevel, pocsagFrequency);
|
||||||
|
|
|
@ -92,8 +92,10 @@ const unsigned int MAX_RESPONSES = 30U;
|
||||||
const unsigned int BUFFER_LENGTH = 2000U;
|
const unsigned int BUFFER_LENGTH = 2000U;
|
||||||
|
|
||||||
|
|
||||||
CModem::CModem(const std::string& port, bool duplex, bool rxInvert, bool txInvert, bool pttInvert, unsigned int txDelay, unsigned int dmrDelay, bool trace, bool debug) :
|
CModem::CModem(const std::string& port, const std::string& protocol, unsigned int address, bool duplex, bool rxInvert, bool txInvert, bool pttInvert, unsigned int txDelay, unsigned int dmrDelay, bool trace, bool debug) :
|
||||||
m_port(port),
|
m_port(port),
|
||||||
|
m_protocol(protocol),
|
||||||
|
m_address(address),
|
||||||
m_dmrColorCode(0U),
|
m_dmrColorCode(0U),
|
||||||
m_ysfLoDev(false),
|
m_ysfLoDev(false),
|
||||||
m_ysfTXHang(4U),
|
m_ysfTXHang(4U),
|
||||||
|
@ -124,7 +126,7 @@ m_nxdnEnabled(false),
|
||||||
m_pocsagEnabled(false),
|
m_pocsagEnabled(false),
|
||||||
m_rxDCOffset(0),
|
m_rxDCOffset(0),
|
||||||
m_txDCOffset(0),
|
m_txDCOffset(0),
|
||||||
m_serial(port, SERIAL_115200, true),
|
m_serial(port, SERIAL_115200, protocol, address, true),
|
||||||
m_buffer(NULL),
|
m_buffer(NULL),
|
||||||
m_length(0U),
|
m_length(0U),
|
||||||
m_offset(0U),
|
m_offset(0U),
|
||||||
|
|
4
Modem.h
4
Modem.h
|
@ -34,7 +34,7 @@ enum RESP_TYPE_MMDVM {
|
||||||
|
|
||||||
class CModem {
|
class CModem {
|
||||||
public:
|
public:
|
||||||
CModem(const std::string& port, bool duplex, bool rxInvert, bool txInvert, bool pttInvert, unsigned int txDelay, unsigned int dmrDelay, bool trace, bool debug);
|
CModem(const std::string& port, const std::string& protocol, unsigned int address, bool duplex, bool rxInvert, bool txInvert, bool pttInvert, unsigned int txDelay, unsigned int dmrDelay, bool trace, bool debug);
|
||||||
~CModem();
|
~CModem();
|
||||||
|
|
||||||
void setRFParams(unsigned int rxFrequency, int rxOffset, unsigned int txFrequency, int txOffset, int txDCOffset, int rxDCOffset, float rfLevel, unsigned int pocsagFrequency);
|
void setRFParams(unsigned int rxFrequency, int rxOffset, unsigned int txFrequency, int txOffset, int txDCOffset, int rxDCOffset, float rfLevel, unsigned int pocsagFrequency);
|
||||||
|
@ -96,6 +96,8 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_port;
|
std::string m_port;
|
||||||
|
std::string m_protocol;
|
||||||
|
unsigned int m_address;
|
||||||
unsigned int m_dmrColorCode;
|
unsigned int m_dmrColorCode;
|
||||||
bool m_ysfLoDev;
|
bool m_ysfLoDev;
|
||||||
unsigned int m_ysfTXHang;
|
unsigned int m_ysfTXHang;
|
||||||
|
|
|
@ -35,12 +35,13 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
|
#include <linux/i2c-dev.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
|
|
||||||
CSerialController::CSerialController(const std::string& device, SERIAL_SPEED speed, bool assertRTS) :
|
CSerialController::CSerialController(const std::string& device, SERIAL_SPEED speed, const std::string& protocol, unsigned int address, bool assertRTS) :
|
||||||
m_device(device),
|
m_device(device),
|
||||||
m_speed(speed),
|
m_speed(speed),
|
||||||
m_assertRTS(assertRTS),
|
m_assertRTS(assertRTS),
|
||||||
|
@ -221,9 +222,11 @@ void CSerialController::close()
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
CSerialController::CSerialController(const std::string& device, SERIAL_SPEED speed, bool assertRTS) :
|
CSerialController::CSerialController(const std::string& device, SERIAL_SPEED speed, const std::string& protocol, unsigned int address, bool assertRTS) :
|
||||||
m_device(device),
|
m_device(device),
|
||||||
m_speed(speed),
|
m_speed(speed),
|
||||||
|
m_protocol(protocol),
|
||||||
|
m_address(address),
|
||||||
m_assertRTS(assertRTS),
|
m_assertRTS(assertRTS),
|
||||||
m_fd(-1)
|
m_fd(-1)
|
||||||
{
|
{
|
||||||
|
@ -237,6 +240,26 @@ CSerialController::~CSerialController()
|
||||||
bool CSerialController::open()
|
bool CSerialController::open()
|
||||||
{
|
{
|
||||||
assert(m_fd == -1);
|
assert(m_fd == -1);
|
||||||
|
|
||||||
|
if (m_protocol == "i2c"){
|
||||||
|
m_fd = ::open(m_device.c_str(), O_RDWR);
|
||||||
|
if (m_fd < 0) {
|
||||||
|
LogError("Cannot open device - %s", m_device.c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (::ioctl(m_fd, I2C_TENBIT, 0) < 0) {
|
||||||
|
LogError("CI2C: failed to set 7bitaddress");
|
||||||
|
}
|
||||||
|
if (::ioctl(m_fd, I2C_SLAVE, m_address) < 0) {
|
||||||
|
LogError("CI2C: Failed to acquire bus access/talk to slave 0x%u", m_address);
|
||||||
|
::close(m_fd);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
LogError("Conntected to Modem via i2c");
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
m_fd = ::open(m_device.c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK); /*open in block mode under OSX*/
|
m_fd = ::open(m_device.c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK); /*open in block mode under OSX*/
|
||||||
#else
|
#else
|
||||||
|
@ -351,6 +374,7 @@ bool CSerialController::open()
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
setNonblock(false);
|
setNonblock(false);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -380,6 +404,19 @@ int CSerialController::read(unsigned char* buffer, unsigned int length)
|
||||||
unsigned int offset = 0U;
|
unsigned int offset = 0U;
|
||||||
|
|
||||||
while (offset < length) {
|
while (offset < length) {
|
||||||
|
if (m_protocol == "i2c"){
|
||||||
|
ssize_t n = ::read(m_fd, buffer + offset, 1U);
|
||||||
|
if (n < 0) {
|
||||||
|
if (errno != EAGAIN) {
|
||||||
|
LogError("Error returned from read(), errno=%d", errno);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n > 0)
|
||||||
|
offset += n;
|
||||||
|
} else {
|
||||||
|
|
||||||
fd_set fds;
|
fd_set fds;
|
||||||
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
||||||
FD_SET(m_fd, &fds);
|
FD_SET(m_fd, &fds);
|
||||||
|
@ -413,6 +450,7 @@ int CSerialController::read(unsigned char* buffer, unsigned int length)
|
||||||
offset += len;
|
offset += len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
@ -448,8 +486,12 @@ int CSerialController::write(const unsigned char* buffer, unsigned int length)
|
||||||
unsigned int ptr = 0U;
|
unsigned int ptr = 0U;
|
||||||
while (ptr < length) {
|
while (ptr < length) {
|
||||||
ssize_t n = 0U;
|
ssize_t n = 0U;
|
||||||
|
if (m_protocol == "i2c"){
|
||||||
|
n = ::write(m_fd, buffer + ptr, 1U);
|
||||||
|
} else {
|
||||||
if (canWrite())
|
if (canWrite())
|
||||||
n = ::write(m_fd, buffer + ptr, length - ptr);
|
n = ::write(m_fd, buffer + ptr, length - ptr);
|
||||||
|
}
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
if (errno != EAGAIN) {
|
if (errno != EAGAIN) {
|
||||||
LogError("Error returned from write(), errno=%d", errno);
|
LogError("Error returned from write(), errno=%d", errno);
|
||||||
|
|
|
@ -42,7 +42,7 @@ enum SERIAL_SPEED {
|
||||||
|
|
||||||
class CSerialController : public ISerialPort {
|
class CSerialController : public ISerialPort {
|
||||||
public:
|
public:
|
||||||
CSerialController(const std::string& device, SERIAL_SPEED speed, bool assertRTS = false);
|
CSerialController(const std::string& device, SERIAL_SPEED speed, const std::string& protocol = "uart", unsigned int address = 0x22, bool assertRTS = false);
|
||||||
virtual ~CSerialController();
|
virtual ~CSerialController();
|
||||||
|
|
||||||
virtual bool open();
|
virtual bool open();
|
||||||
|
@ -60,6 +60,8 @@ public:
|
||||||
private:
|
private:
|
||||||
std::string m_device;
|
std::string m_device;
|
||||||
SERIAL_SPEED m_speed;
|
SERIAL_SPEED m_speed;
|
||||||
|
std::string m_protocol;
|
||||||
|
unsigned int m_address;
|
||||||
bool m_assertRTS;
|
bool m_assertRTS;
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
HANDLE m_handle;
|
HANDLE m_handle;
|
||||||
|
|
Loading…
Reference in a new issue