commander_core: support 2.10.219 firmware (#501)

Fixes: #464
Related: #455
This commit is contained in:
Meriemi 2022-09-13 18:45:22 +02:00 committed by GitHub
parent 9d85834411
commit a2b4391408
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 28 deletions

View File

@ -83,23 +83,10 @@ Response:
Note: the `0x01` Init/Wakeup command is exceptionally not necessary before this
command.
### `0x05` - Reset Channel
Needs to be run before changing the mode on a channel if there is a chance the
channel has already been used.
Command:
| Byte index | Description |
| ---------- | ----------- |
| 0x00 | 0x08 |
| 0x01 | 0x05 |
| 0x02 | 0x01 |
| 0x03 | Channel to reset |
### `0x0d` - Set Channel Mode
### `0x0d` - Open Endpoint
Sets the mode for the channel to use.
Needs to be run **before** a read or write operation.
`0x05` - Init/Wakeup will likely need to be run first.
@ -112,6 +99,19 @@ Command:
| 0x02 | Channel |
| 0x03 | New mode |
### `0x05` - Close Endpoint
Needs to be run **after** a read or write operation to close a previously opened endpoint.
Command:
| Byte index | Description |
| ---------- | ----------- |
| 0x00 | 0x08 |
| 0x01 | 0x05 |
| 0x02 | 0x01 |
| 0x03 | Channel to close |
## Mode Commands
These are the commands that are used in each of the modes.

View File

@ -27,8 +27,8 @@ _FAN_COUNT = 6
_CMD_WAKE = (0x01, 0x03, 0x00, 0x02)
_CMD_SLEEP = (0x01, 0x03, 0x00, 0x01)
_CMD_GET_FIRMWARE = (0x02, 0x13)
_CMD_RESET = (0x05, 0x01, 0x00)
_CMD_SET_MODE = (0x0d, 0x00)
_CMD_CLOSE_ENDPOINT = (0x05, 0x01, 0x00)
_CMD_OPEN_ENDPOINT = (0x0d, 0x00)
_CMD_READ = (0x08, 0x00)
_CMD_WRITE = (0x06, 0x00)
@ -199,10 +199,9 @@ class CommanderCore(UsbHidDriver):
return temps
def _read_data(self, mode, data_type):
self._send_command(_CMD_RESET)
self._send_command(_CMD_SET_MODE, mode)
self._send_command(_CMD_OPEN_ENDPOINT, mode)
raw_data = self._send_command(_CMD_READ)
self._send_command(_CMD_CLOSE_ENDPOINT)
if tuple(raw_data[3:5]) != data_type:
raise ExpectationNotMet('device returned incorrect data type')
@ -227,7 +226,10 @@ class CommanderCore(UsbHidDriver):
self.device.clear_enqueued_reports()
self.device.write(buf)
buf = bytes(self.device.read(_RESPONSE_LENGTH))
res = self.device.read(_RESPONSE_LENGTH)
while res[0] != 0x00:
res = self.device.read(_RESPONSE_LENGTH)
buf = bytes(res)
assert buf[1] == command[0], 'response does not match command'
return buf
@ -242,8 +244,7 @@ class CommanderCore(UsbHidDriver):
def _write_data(self, mode, data_type, data):
self._read_data(mode, data_type) # Will ensure we are writing the correct data type to avoid breakage
self._send_command(_CMD_RESET)
self._send_command(_CMD_SET_MODE, mode)
self._send_command(_CMD_OPEN_ENDPOINT, mode)
buf = bytearray(len(data) + len(data_type) + 4)
buf[0: 2] = int.to_bytes(len(data) + 2, length=2, byteorder="little", signed=False)
@ -251,6 +252,7 @@ class CommanderCore(UsbHidDriver):
buf[4 + len(data_type):] = data
self._send_command(_CMD_WRITE, buf)
self._send_command(_CMD_CLOSE_ENDPOINT)
def _fan_to_channel(self, fan):
if self._has_pump:

View File

@ -31,7 +31,6 @@ class MockCommanderCoreDevice:
self._last_write = bytes()
self._modes = {}
self._awake = False
self.response_prefix = ()
@ -52,7 +51,7 @@ class MockCommanderCoreDevice:
if self._awake:
if self._last_write[2] == 0x08: # Get data
channel = self._last_write[3]
mode = self._modes[channel]
mode = self._modes.get(channel)
if mode[1] == 0x00:
if mode[0] == 0x17: # Get speeds
data.extend([0x06, 0x00])
@ -111,11 +110,12 @@ class MockCommanderCoreDevice:
self._last_write = data
if data[0] != 0x00 or data[1] != 0x08:
raise ValueError('Start of packets going out should be 00:08')
if data[2] == 0x0d:
channel = data[3]
if self._modes[channel] is None:
if self._modes.get(channel) is None:
self._modes[channel] = data[4:6]
else:
raise ExpectationNotMet('Previous channel was not reset')
elif data[2] == 0x05 and data[3] == 0x01:
self._modes[data[4]] = None
elif data[2] == 0x01 and data[3] == 0x03 and data[4] == 0x00:
@ -123,7 +123,7 @@ class MockCommanderCoreDevice:
elif self._awake:
if data[2] == 0x06: # Write command
channel = data[3]
mode = self._modes[channel]
mode = self._modes.get(channel)
length = u16le_from(data[4:6])
data_type = data[8:10]
written_data = data[10:8+length]