From 11a9c1b3c88884cbc73908244e091a1089493bce Mon Sep 17 00:00:00 2001 From: redfast00 Date: Wed, 9 Sep 2020 23:14:50 +0200 Subject: [PATCH 1/3] Don't return None when unknown message type, add new messages for info module --- debugging_tool/server.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/debugging_tool/server.py b/debugging_tool/server.py index 228f207..4a580bb 100644 --- a/debugging_tool/server.py +++ b/debugging_tool/server.py @@ -43,7 +43,7 @@ class Message: return (self.received_from >> 0) & 0b1111_1111 def human_readable_type(self): - return ['controller', 'puzzle', 'needy', 'RESERVED TYPE'][self.sender_type()] + return [('controller' if self.sender_id() == 0 else 'info'), 'puzzle', 'needy', 'RESERVED TYPE'][self.sender_type()] def _parse_state_update(self): timeleft = self.payload[1] << 0x18 | self.payload[2] << 0x10 | self.payload[3] << 0x08 | self.payload[4] @@ -56,7 +56,7 @@ class Message: sender_type = self.sender_type() message_type = self.payload[0] try: - if sender_type == 0b00: # controller + if sender_type == 0b00 and self.sender_id() == 0: # controller if message_type == 0: return "ACK" elif message_type == 1: @@ -71,6 +71,8 @@ class Message: return "TIMEOUT " + self._parse_state_update() elif message_type == 6: return "STRIKEOUT " + self._parse_state_update() + elif message_type == 7: + return "INFO START" elif sender_type == 0b01: # puzzle if message_type == 0: return "REGISTER" @@ -78,9 +80,18 @@ class Message: return f"STRIKE {self.payload[1]}" elif message_type == 2: return f"SOLVED" + elif sender_type == 0b10: # needy + if message_type == 0: + return "REGISTER" + elif message_type == 1: + return f"STRIKE {self.payload[1]}" + elif sender_type == 0b00 and self.sender_id() != 0: # info + if message_type == 0: + return "FREE INFO MESSAGE" + except: print("Unexpected error: ", sys.exc_info()[0]) - return "PARSE ERROR" + return "PARSE ERROR" def serialize(self): return { From 9a2f9f8ced96c3cabf576fb91401ce6ff82dab23 Mon Sep 17 00:00:00 2001 From: redfast00 Date: Wed, 9 Sep 2020 23:32:42 +0200 Subject: [PATCH 2/3] Add option to only show last state update in series of state updates --- debugging_tool/static/index.html | 11 +++++++++-- debugging_tool/static/script.js | 8 +++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/debugging_tool/static/index.html b/debugging_tool/static/index.html index 9249f49..e63b53d 100644 --- a/debugging_tool/static/index.html +++ b/debugging_tool/static/index.html @@ -53,6 +53,10 @@ display:none; } + table.hide_consecutive_states .staterow + .staterow { + display: none; + } + tr:hover { background-color: #aaa; } @@ -92,8 +96,11 @@ - - + + + + + diff --git a/debugging_tool/static/script.js b/debugging_tool/static/script.js index 3a4df3c..b7b2c3d 100644 --- a/debugging_tool/static/script.js +++ b/debugging_tool/static/script.js @@ -16,10 +16,14 @@ let color_classes = { "needy": "needy", } -function updateShow() { +function updateShowRaw() { document.getElementById("message_table").classList.toggle("hide_raw", !document.getElementById('show_raw').checked); } +function updateShowStates() { + document.getElementById("message_table").classList.toggle("hide_consecutive_states", !document.getElementById('show_consecutive_states').checked); +} + function updateMessages() { fetch(`/${newest_message_index}/api.json`) .then( @@ -59,6 +63,8 @@ function updateMessages() { let parsed = row.insertCell(-1) if (current['parsed'].startsWith("PARSE ERROR")) { parsed.classList.add("error"); + } else if (current['parsed'].startsWith("STATE")) { + parsed.classList.add("staterow"); } parsed.innerHTML = current['parsed']; parsed.classList.add('parsed'); From 27552b6c1327de85a0d60e01265934b2517ea329 Mon Sep 17 00:00:00 2001 From: redfast00 Date: Fri, 11 Sep 2020 18:26:58 +0200 Subject: [PATCH 3/3] Fix wrong class --- debugging_tool/static/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debugging_tool/static/script.js b/debugging_tool/static/script.js index b7b2c3d..0e33f30 100644 --- a/debugging_tool/static/script.js +++ b/debugging_tool/static/script.js @@ -64,7 +64,7 @@ function updateMessages() { if (current['parsed'].startsWith("PARSE ERROR")) { parsed.classList.add("error"); } else if (current['parsed'].startsWith("STATE")) { - parsed.classList.add("staterow"); + row.classList.add("staterow"); } parsed.innerHTML = current['parsed']; parsed.classList.add('parsed');