diff --git a/src/lib/ebus/device.cpp b/src/lib/ebus/device.cpp index ff3559a5..35f88931 100755 --- a/src/lib/ebus/device.cpp +++ b/src/lib/ebus/device.cpp @@ -64,7 +64,7 @@ namespace ebusd { * @param readOnly whether to allow read access to the device only. * @param initialSend whether to send an initial @a ESC symbol in @a open(). * @param udp true for UDP, false to TCP. - * @param enhancedProto whether the device supports the ebusd enhanced protocol. + * @param enhancedProto whether to use the ebusd enhanced protocol. */ Device::Device(const char* name, bool checkDevice, bool readOnly, bool initialSend, bool enhancedProto) : m_name(name), m_checkDevice(checkDevice), m_readOnly(readOnly), m_initialSend(initialSend), @@ -84,20 +84,23 @@ Device::~Device() { } Device* Device::create(const char* name, bool checkDevice, bool readOnly, bool initialSend) { + bool enhanced = strncmp(name, "enh:", 4) == 0; + if (enhanced) { + name += 4; + } if (strchr(name, '/') == nullptr && strchr(name, ':') != nullptr) { char* in = strdup(name); bool udp = false; - bool enhanced = false; char* addrpos = in; char* portpos = strchr(addrpos, ':'); - if (portpos >= addrpos+3 && strncmp(addrpos, "enh", 3) == 0) { - enhanced = true; + if (!enhanced && portpos >= addrpos+3 && strncmp(addrpos, "enh", 3) == 0) { + enhanced = true; // support enhtcp:: and enhudp:: addrpos += 3; if (portpos == addrpos) { addrpos++; portpos = strchr(addrpos, ':'); } - } + } // else: support enh:: defaulting to TCP if (portpos == addrpos+3 && (strncmp(addrpos, "tcp", 3) == 0 || (udp=(strncmp(addrpos, "udp", 3) == 0)))) { addrpos += 4; portpos = strchr(addrpos, ':'); @@ -128,7 +131,8 @@ Device* Device::create(const char* name, bool checkDevice, bool readOnly, bool i address.sin_port = (in_port_t)htons((uint16_t)port); return new NetworkDevice(name, address, readOnly, initialSend, udp, enhanced); } - return new SerialDevice(name, checkDevice, readOnly, initialSend); + // support enh:/dev/ + return new SerialDevice(name, checkDevice, readOnly, initialSend, enhanced); } result_t Device::open() { diff --git a/src/lib/ebus/device.h b/src/lib/ebus/device.h index 84576291..8a2ede7e 100755 --- a/src/lib/ebus/device.h +++ b/src/lib/ebus/device.h @@ -79,7 +79,7 @@ class Device { * @param checkDevice whether to regularly check the device availability (only for serial devices). * @param readOnly whether to allow read access to the device only. * @param initialSend whether to send an initial @a ESC symbol in @a open(). - * @param enhancedProto whether the device supports the ebusd enhanced protocol. + * @param enhancedProto whether to use the ebusd enhanced protocol. */ Device(const char* name, bool checkDevice, bool readOnly, bool initialSend, bool enhancedProto=false); @@ -251,9 +251,10 @@ class SerialDevice : public Device { * @param checkDevice whether to regularly check the device availability (only for serial devices). * @param readOnly whether to allow read access to the device only. * @param initialSend whether to send an initial @a ESC symbol in @a open(). + * @param enhancedProto whether to use the ebusd enhanced protocol. */ - SerialDevice(const char* name, bool checkDevice, bool readOnly, bool initialSend) - : Device(name, checkDevice, readOnly, initialSend) {} + SerialDevice(const char* name, bool checkDevice, bool readOnly, bool initialSend, bool enhancedProto=false) + : Device(name, checkDevice, readOnly, initialSend, enhancedProto) {} // @copydoc result_t open() override; @@ -284,7 +285,7 @@ class NetworkDevice : public Device { * @param readOnly whether to allow read access to the device only. * @param initialSend whether to send an initial @a ESC symbol in @a open(). * @param udp true for UDP, false to TCP. - * @param enhancedProto whether the device supports the ebusd enhanced protocol. + * @param enhancedProto whether to use the ebusd enhanced protocol. */ NetworkDevice(const char* name, const struct sockaddr_in& address, bool readOnly, bool initialSend, bool udp, bool enhancedProto=false)