summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-12-03 06:13:13 +0300
committerDevaev Maxim <[email protected]>2020-12-03 06:13:13 +0300
commita694cbd240a436bb1de8c4647977c3ae47e7c73b (patch)
tree004d5d72cf459b03b86b58c2291035791618e62c
parent748900e649a3cfedaca24693577fd0d685b5ac04 (diff)
serial fixes
-rw-r--r--hid/src/main.cpp2
-rw-r--r--hid/src/proto.h1
-rw-r--r--kvmd/plugins/hid/serial.py15
3 files changed, 13 insertions, 5 deletions
diff --git a/hid/src/main.cpp b/hid/src/main.cpp
index e97bc37c..0442b448 100644
--- a/hid/src/main.cpp
+++ b/hid/src/main.cpp
@@ -255,7 +255,7 @@ static void _sendResponse(uint8_t code) {
}
uint8_t response[8] = {0};
- response[0] = PROTO::MAGIC;
+ response[0] = PROTO::MAGIC_RESP;
if (code & PROTO::PONG::OK) {
response[1] = PROTO::PONG::OK;
# ifdef HID_DYNAMIC
diff --git a/hid/src/proto.h b/hid/src/proto.h
index 6b8dffe7..38462ee5 100644
--- a/hid/src/proto.h
+++ b/hid/src/proto.h
@@ -25,6 +25,7 @@
namespace PROTO {
const uint8_t MAGIC = 0x33;
+ const uint8_t MAGIC_RESP = 0x34;
namespace RESP { // Plain responses
// const uint8_t OK = 0x20; // Legacy
diff --git a/kvmd/plugins/hid/serial.py b/kvmd/plugins/hid/serial.py
index da61f2c6..843be58f 100644
--- a/kvmd/plugins/hid/serial.py
+++ b/kvmd/plugins/hid/serial.py
@@ -52,9 +52,13 @@ class _SerialPhyConnection(BasePhyConnection):
self.__tty.read_all()
assert self.__tty.write(request) == 8
data = self.__tty.read(4)
- if data[0] == 0x34: # New response protocol
- data += self.__tty.read(4)
- return data
+ if len(data) == 4:
+ if data[0] == 0x34: # New response protocol
+ data += self.__tty.read(4)
+ if len(data) != 8:
+ return b""
+ return data
+ return b""
class _SerialPhy(BasePhy):
@@ -81,7 +85,10 @@ class _SerialPhy(BasePhy):
# =====
class Plugin(BaseMcuHid):
def __init__(self, **kwargs: Any) -> None:
- phy_kwargs: Dict = {key: kwargs.pop(key) for key in self.__get_phy_options()}
+ phy_kwargs: Dict = {
+ (option.unpack_as or key): kwargs.pop(option.unpack_as or key)
+ for (key, option) in self.__get_phy_options().items()
+ }
super().__init__(phy=_SerialPhy(**phy_kwargs), **kwargs)
@classmethod