Merge pull request #10 from ZeusWPI/better-debugger

Debugger
This commit is contained in:
redfast00 2020-09-11 18:28:34 +02:00 committed by GitHub
commit 2750e2b8c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 6 deletions

View file

@ -43,7 +43,7 @@ class Message:
return (self.received_from >> 0) & 0b1111_1111 return (self.received_from >> 0) & 0b1111_1111
def human_readable_type(self): 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): def _parse_state_update(self):
timeleft = self.payload[1] << 0x18 | self.payload[2] << 0x10 | self.payload[3] << 0x08 | self.payload[4] 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() sender_type = self.sender_type()
message_type = self.payload[0] message_type = self.payload[0]
try: try:
if sender_type == 0b00: # controller if sender_type == 0b00 and self.sender_id() == 0: # controller
if message_type == 0: if message_type == 0:
return "ACK" return "ACK"
elif message_type == 1: elif message_type == 1:
@ -71,6 +71,8 @@ class Message:
return "TIMEOUT " + self._parse_state_update() return "TIMEOUT " + self._parse_state_update()
elif message_type == 6: elif message_type == 6:
return "STRIKEOUT " + self._parse_state_update() return "STRIKEOUT " + self._parse_state_update()
elif message_type == 7:
return "INFO START"
elif sender_type == 0b01: # puzzle elif sender_type == 0b01: # puzzle
if message_type == 0: if message_type == 0:
return "REGISTER" return "REGISTER"
@ -78,9 +80,18 @@ class Message:
return f"STRIKE {self.payload[1]}" return f"STRIKE {self.payload[1]}"
elif message_type == 2: elif message_type == 2:
return f"SOLVED" 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: except:
print("Unexpected error: ", sys.exc_info()[0]) print("Unexpected error: ", sys.exc_info()[0])
return "PARSE ERROR" return "PARSE ERROR"
def serialize(self): def serialize(self):
return { return {

View file

@ -53,6 +53,10 @@
display:none; display:none;
} }
table.hide_consecutive_states .staterow + .staterow {
display: none;
}
tr:hover { tr:hover {
background-color: #aaa; background-color: #aaa;
} }
@ -92,8 +96,11 @@
<body> <body>
<button onclick="toggle_logging()" id="toggle_button">Start</button> <button onclick="toggle_logging()" id="toggle_button">Start</button>
<input type="checkbox" id="show_raw" name="show_raw" checked autocomplete="off" onchange="updateShow()"> <input type="checkbox" id="show_raw" name="show_raw" checked autocomplete="off" onchange="updateShowRaw()">
<label for="show_raw">Show raw address and payload</label> <label for="show_raw">Show raw address and payload</label>
<input type="checkbox" id="show_consecutive_states" name="show_consecutive_states" checked autocomplete="off" onchange="updateShowStates()">
<label for="show_consecutive_states">Show consecutive state updates</label>
<table id="message_table"> <table id="message_table">
<tr id="table_header"> <tr id="table_header">

View file

@ -16,10 +16,14 @@ let color_classes = {
"needy": "needy", "needy": "needy",
} }
function updateShow() { function updateShowRaw() {
document.getElementById("message_table").classList.toggle("hide_raw", !document.getElementById('show_raw').checked); 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() { function updateMessages() {
fetch(`/${newest_message_index}/api.json`) fetch(`/${newest_message_index}/api.json`)
.then( .then(
@ -59,6 +63,8 @@ function updateMessages() {
let parsed = row.insertCell(-1) let parsed = row.insertCell(-1)
if (current['parsed'].startsWith("PARSE ERROR")) { if (current['parsed'].startsWith("PARSE ERROR")) {
parsed.classList.add("error"); parsed.classList.add("error");
} else if (current['parsed'].startsWith("STATE")) {
row.classList.add("staterow");
} }
parsed.innerHTML = current['parsed']; parsed.innerHTML = current['parsed'];
parsed.classList.add('parsed'); parsed.classList.add('parsed');