Clean up the I2C code.

This commit is contained in:
Jonathan Naylor
2018-07-19 18:42:23 +01:00
parent d16a06db07
commit 03682b000a
6 changed files with 111 additions and 112 deletions

View File

@@ -44,6 +44,8 @@ Time=24
# Port=/dev/ttyACM0
# Port=/dev/ttyAMA0
Port=\\.\COM3
Protocol=uart
# Address=0x22
TXInvert=1
RXInvert=0
PTTInvert=0

View File

@@ -1076,10 +1076,9 @@ bool CMMDVMHost::createModem()
LogInfo("Modem Parameters");
LogInfo(" Port: %s", port.c_str());
if (protocol == "i2c"){
LogInfo(" Protocol: %s", protocol.c_str());
LogInfo(" i2c Address: %u", address);
}
if (protocol == "i2c")
LogInfo(" i2c Address: %02X", address);
LogInfo(" RX Invert: %s", rxInvert ? "yes" : "no");
LogInfo(" TX Invert: %s", txInvert ? "yes" : "no");
LogInfo(" PTT Invert: %s", pttInvert ? "yes" : "no");

View File

@@ -94,8 +94,6 @@ const unsigned int BUFFER_LENGTH = 2000U;
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_protocol(protocol),
m_address(address),
m_dmrColorCode(0U),
m_ysfLoDev(false),
m_ysfTXHang(4U),

View File

@@ -96,8 +96,6 @@ public:
private:
std::string m_port;
std::string m_protocol;
unsigned int m_address;
unsigned int m_dmrColorCode;
bool m_ysfLoDev;
unsigned int m_ysfTXHang;

View File

@@ -44,6 +44,8 @@
CSerialController::CSerialController(const std::string& device, SERIAL_SPEED speed, const std::string& protocol, unsigned int address, bool assertRTS) :
m_device(device),
m_speed(speed),
m_protocol(protocol),
m_address(address),
m_assertRTS(assertRTS),
m_handle(INVALID_HANDLE_VALUE)
{
@@ -247,19 +249,19 @@ bool CSerialController::open()
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");
if (::ioctl(m_fd, I2C_SLAVE, m_address) < 0) {
LogError("CI2C: Failed to acquire bus access/talk to slave 0x%02X", m_address);
::close(m_fd);
return false;
}
} else {
#if defined(__APPLE__)
m_fd = ::open(m_device.c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK); /*open in block mode under OSX*/
#else
@@ -283,7 +285,7 @@ bool CSerialController::open()
return false;
}
#if defined(__APPLE__)
#if defined(__APPLE__)
termios.c_cflag |= (CLOCAL | CREAD); /* ignore modem controls */
termios.c_cflag &= ~CSIZE;
termios.c_cflag |= CS8; /* 8-bit characters */

View File

@@ -42,7 +42,7 @@ enum SERIAL_SPEED {
class CSerialController : public ISerialPort {
public:
CSerialController(const std::string& device, SERIAL_SPEED speed, const std::string& protocol = "uart", unsigned int address = 0x22, bool assertRTS = false);
CSerialController(const std::string& device, SERIAL_SPEED speed, const std::string& protocol = "uart", unsigned int address = 0x22U, bool assertRTS = false);
virtual ~CSerialController();
virtual bool open();