|
39 | 39 | from .pattern import Pattern
|
40 | 40 | from ..preferences import Preferences
|
41 | 41 |
|
| 42 | +import struct |
| 43 | + |
42 | 44 |
|
43 | 45 | class Control(SignalSender):
|
44 | 46 | """
|
@@ -168,11 +170,41 @@ def check_serial_API6(self) -> tuple[Token, int]:
|
168 | 170 | self.__log_cnfInfo(msg)
|
169 | 171 | elif token == Token.indState:
|
170 | 172 | self.status.parse_device_state_API6(param, msg)
|
| 173 | + self.__log_indState(msg) |
171 | 174 | elif token == Token.testRes:
|
172 | 175 | if len(msg) > 0:
|
173 | 176 | self.emit_hw_test_writer(msg[1:].decode())
|
174 | 177 | return token, param
|
175 | 178 |
|
| 179 | + def __log_indState(self, msg: bytes) -> None: |
| 180 | + directionMap = {0x00: "Left ", 0x01: "Right", 0xFF: "?"} |
| 181 | + machineSideMap = {0x00: "? ", 0x01: "Left", 2: "Right"} |
| 182 | + beltShiftMap = {0x00: "?", 0x01: "Regular", 0x02: "Shifted"} |
| 183 | + carriageMap = {0x00: "K", 0x01: "L", 0x02: "G", 0x03: "K270", 0xFF: "None"} |
| 184 | + |
| 185 | + error = msg[1] |
| 186 | + state = msg[2] |
| 187 | + hallLeft = struct.unpack(">H", msg[3:5])[0] |
| 188 | + hallRight = struct.unpack(">H", msg[5:7])[0] |
| 189 | + carriage = carriageMap[msg[7]] |
| 190 | + position = msg[8] |
| 191 | + direction = directionMap[msg[9]] |
| 192 | + |
| 193 | + try: # AyabAsync supplies additional parameters |
| 194 | + hallActive = machineSideMap[msg[10]] |
| 195 | + beltShift = beltShiftMap[msg[11]] |
| 196 | + self.logger.info( |
| 197 | + f"IndState: {error:1d} {state:1d} {position:3d}" |
| 198 | + f" {carriage:5s} ({beltShift:11s},{direction:5s})" |
| 199 | + f" Hall:{hallActive:5s} ({hallLeft:5d}, {hallRight:5d})" |
| 200 | + ) |
| 201 | + except IndexError: |
| 202 | + self.logger.info( |
| 203 | + f"IndState: {error:1d} {state:1d} {position:3d}" |
| 204 | + f" {carriage:5s} ({direction:5s})" |
| 205 | + f" Hall:({hallLeft:5d}, {hallRight:5d})" |
| 206 | + ) |
| 207 | + |
176 | 208 | def __log_cnfInfo(self, msg: bytes) -> None:
|
177 | 209 | api = msg[1]
|
178 | 210 | log = "API v" + str(api)
|
|
0 commit comments