mirror of
https://github.com/g4klx/MMDVMHost
synced 2025-12-21 23:45:49 +08:00
Clean up the I2C code.
This commit is contained in:
@@ -44,6 +44,8 @@ Time=24
|
||||
# Port=/dev/ttyACM0
|
||||
# Port=/dev/ttyAMA0
|
||||
Port=\\.\COM3
|
||||
Protocol=uart
|
||||
# Address=0x22
|
||||
TXInvert=1
|
||||
RXInvert=0
|
||||
PTTInvert=0
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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),
|
||||
|
||||
2
Modem.h
2
Modem.h
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user