Skip to content

Commit

Permalink
Close #351, close #354, close #347, close #352, close #345, close #355
Browse files Browse the repository at this point in the history
  • Loading branch information
Silver Valdvee committed Mar 24, 2023
1 parent 372286b commit 6f54490
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 44 deletions.
11 changes: 10 additions & 1 deletion yukon/domain/avatar.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,16 @@ def to_builtin(self) -> Any:
^ hash(frozenset(self._ports.sub))
^ hash(frozenset(self._ports.cln))
^ hash(frozenset(self._ports.srv))
^ hash(vendor_specific_status_code)
^ hash(
json.dumps(
{
"vendor_specific_status_code": vendor_specific_status_code,
"mode": mode_value,
"health": health_value,
},
sort_keys=True,
)
)
^ hash(self._info.name.tobytes().decode() if self._info is not None else None)
^ hash(self.random_str_for_forced_update) # This accounts for is_disappeared and is_being_queried
^ hash(self.disappeared_since)
Expand Down
2 changes: 1 addition & 1 deletion yukon/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2023.3.42"
__version__ = "2023.3.43"
2 changes: 1 addition & 1 deletion yukon/web/modules/context-menu.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ export function make_context_menus(yukon_state) {
},
click: async (e, elementOpenedOn) => {
const portNr = parseInt(elementOpenedOn.getAttribute("data-port"));
const datatypes = await getDatatypesForPort(portNr, yukon_state);
const datatypes = await getDatatypesForPort(portNr, "pub", yukon_state);
const response = await yukon_state.zubax_apij.make_simple_publisher_with_datatype_and_port_id(datatypes[0], portNr);
const portType = elementOpenedOn.getAttribute("data-port-type"); // sub or pub or cln or srv
if (response && response.success) {
Expand Down
50 changes: 50 additions & 0 deletions yukon/web/modules/meanings.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,54 @@ export function getRelatedLinks(port, port_type, yukon_state) {
}
}
return Array.from(new Set(links));
}
export function decodeTelegaVSSC(vssc) {
const high_number = vssc / 16;
const low_number = vssc % 16;
if (low_number !== 0) {
if(high_number === 0) {
return "Fault in Standby, fault code: " + low_number;
} else if (high_number == 1) {
// self test
return "Fault in Self test, fault code: " + low_number;
} else if (high_number == 2) {
return "Fault in Motor ID, fault code: " + low_number;
} else if (high_number == 5) {
// drive
if(low_number === 1) {
return "Torque control mode";
} else if(low_number === 2) {
return "Voltage control mode";
} else if(low_number === 3) {
return "Velocity control mode";
} else if(low_number === 9) {
// Ratiometric torque control mode
return "Ratiometric torque control mode";
} else if (low_number === 10) {
// Ratiometric voltage control mode
return "Ratiometric voltage control mode";
} else {
return "Fault in Drive, fault code: " + low_number;
}
} else if (high_number == 7) {
// servo
return "Fault in Servo, fault code: " + low_number;
}
} else {
if (high_number === 0) {
return "Standby";
} else if (high_number == 1) {
// self test
return "Self test";
} else if (high_number == 2) {
return "Motor ID";
} else if (high_number == 5) {
// drive
return "Drive";
} else if (high_number == 7) {
// servo
return "Servo";
}
}
return "Unknown code";
}
8 changes: 4 additions & 4 deletions yukon/web/modules/panels/monitor2/highlights.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ export function setPortStateAsUnhiglighted(portNr, yukon_state) {
}
export function highlightElement(element, color, settings, yukon_state) {
if (element.classList.contains("arrowhead")) {
element.style.setProperty("border-top-color", color);
element.style.setProperty("border-top-color", color, "important");
} else if (element.classList.contains("horizontal_line_label") && element.tagName === "LABEL") {
element.style.setProperty("background-color", settings.LinkLabelHighlightColor);
element.style.setProperty("color", settings.LinkLabelHighlightTextColor);
element.style.setProperty("background-color", settings.LinkLabelHighlightColor, "important");
element.style.setProperty("color", settings.LinkLabelHighlightTextColor, "important");
} else if (element.classList.contains("horizontal_line") || element.classList.contains("line") || element.classList.contains("circle")) {
element.style.setProperty("background-color", color);
element.style.setProperty("background-color", color, "important");
}
}
export function highlightElements(objects, settings, yukon_state) {
Expand Down
103 changes: 73 additions & 30 deletions yukon/web/modules/panels/monitor2/monitor2.module.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { areThereAnyNewOrMissingHashes, updateLastHashes } from "../../hash_checks.module.js";
import { getRelatedLinks } from "../../meanings.module.js";
import { getRelatedLinks, decodeTelegaVSSC } from "../../meanings.module.js";
import { waitForElm, getKnownDatatypes, doCommandFeedbackResult } from "../../utilities.module.js";
import {
getHoveredContainerElementAndContainerObject,
Expand Down Expand Up @@ -464,11 +464,9 @@ async function update_monitor2(containerElement, monitor2Div, yukon_state, force
let fixed_datatype_full = null;
if (datatypes_response["fixed_id_messages"] && datatypes_response["fixed_id_messages"][port.port] !== undefined) {
const type_of_interest = datatypes_response["fixed_id_messages"][port.port];
console.log(`Type of interest is ${type_of_interest} and is_service is ${type_of_interest.is_service}`);
const is_a_service_and_for_a_service = type_of_interest.is_service && (port.type === "cln" || port.type === "srv");
const is_a_message_and_for_a_message = !type_of_interest.is_service && (port.type === "pub" || port.type === "sub");
console.log(`Port type is ${port.type} and is_a_service_and_for_a_service is ${is_a_service_and_for_a_service} and is_a_message_and_for_a_message is ${is_a_message_and_for_a_message}, port id is ${port.port}`);
if(is_a_service_and_for_a_service || is_a_message_and_for_a_message) {
if (is_a_service_and_for_a_service || is_a_message_and_for_a_message) {
fixed_datatype_short = datatypes_response["fixed_id_messages"][port.port]["short_name"];
fixed_datatype_full = datatypes_response["fixed_id_messages"][port.port]["name"];
}
Expand Down Expand Up @@ -659,7 +657,7 @@ function createElementForNode(avatar, text, container, fieldsObject, get_up_to_d
// node.style.backgroundColor = avatar.color;
node.innerText = text;
if (avatar.is_being_queried) {
node.innerText += " (querying...)";
node.innerText += " (looking for registers...)";
} else if (!avatar.has_port_list) {
node.innerText += " (no port list)";
}
Expand All @@ -670,6 +668,9 @@ function createElementForNode(avatar, text, container, fieldsObject, get_up_to_d
const fieldDiv = document.createElement("div");
containerDiv.appendChild(fieldDiv);
fieldDiv.classList.add("d-inline-flex", "field");
if (field === "VSSC" && fieldsObject["Name"] === "com.zubax.telega") {
fieldsObject[field] = decodeTelegaVSSC(parseInt(fieldsObject[field])) + " (" + fieldsObject[field] + ")";
}
fieldDiv.innerHTML = field;
fieldDiv.style.fontWeight = "bold";
const valueDiv = document.createElement("div");
Expand All @@ -682,22 +683,36 @@ function createElementForNode(avatar, text, container, fieldsObject, get_up_to_d
if (field == Object.keys(fieldsObject)[Object.keys(fieldsObject).length - 1]) {
containerDiv.style.marginBottom = "6px";
}
valueDiv.style.removeProperty("color");
valueDiv.style.removeProperty("background-color");
// This is for Health status
if (fieldsObject[field] === "CAUTION") {
valueDiv.style.backgroundColor = "orange";
} else if (fieldsObject[field] === "WARNING") {
valueDiv.style.backgroundColor = "red";
} else if (fieldsObject[field] === "ADVISORY") {
valueDiv.style.backgroundColor = "yellow";
if (field === "Health") {
valueDiv.style.paddingLeft = "3px";
valueDiv.style.paddingRight = "3px";
if (fieldsObject[field] === "Nominal") {
valueDiv.style.backgroundColor = "green";
} else if (fieldsObject[field] === "CAUTION") {
valueDiv.style.backgroundColor = "orange";
} else if (fieldsObject[field] === "WARNING") {
valueDiv.style.backgroundColor = "red";
} else if (fieldsObject[field] === "ADVISORY") {
valueDiv.style.backgroundColor = "yellow";
valueDiv.style.color = "black";
}
}
if (fieldsObject[field] === "OPERATIONAL") {
valueDiv.style.backgroundColor = "green";
} else if (fieldsObject[field] === "INITIALIZATION") {
valueDiv.style.backgroundColor = "pink";
} else if (fieldsObject[field] === "MAINTENANCE") {
valueDiv.style.backgroundColor = "yellow";
} else if (fieldsObject[field] === "SOFTWARE_UPDATE") {
valueDiv.style.backgroundColor = "blue";
if (field === "Mode") {
valueDiv.style.paddingLeft = "3px";
valueDiv.style.paddingRight = "3px";
if (fieldsObject[field] === "OPERATIONAL") {
valueDiv.style.backgroundColor = "green";
} else if (fieldsObject[field] === "INITIALIZATION") {
valueDiv.style.backgroundColor = "pink";
} else if (fieldsObject[field] === "MAINTENANCE") {
valueDiv.style.backgroundColor = "yellow";
valueDiv.style.color = "black";
} else if (fieldsObject[field] === "SOFTWARE_UPDATE") {
valueDiv.style.backgroundColor = "blue";
}
}
if (field === "Uptime") {
let intervalId = null;
Expand Down Expand Up @@ -727,17 +742,15 @@ function createElementForNode(avatar, text, container, fieldsObject, get_up_to_d
// Make an input-group for the buttons
const inputGroup = document.createElement("div");
inputGroup.classList.add("input-group");
inputGroup.style.width = "100%";
inputGroup.style.setProperty("backgroundColor", "transparent", "important");
let neededButtons = [{ "name": "Restart", "command": "65535", "title": "Restart device" }, { "name": "Save", "command": "65530", "title": "Save persistent states" }, { "name": "Estop", "command": "65531", "title": "Emergency stop" }];
const telegaButtons = [{ "name": "Cancel", "command": "0", "title": "Cancel" }, { "name": "SelfTest", "command": "1", "title": "SelfTest" }, { "name": "MotorID", "command": "2", "title": "MotorID" }];
if (fieldsObject && fieldsObject["Name"] && fieldsObject["Name"].includes("telega")) {
neededButtons.push(...telegaButtons);
}
for (const button of neededButtons) {
const btnButton = document.createElement("button");
btnButton.style.fontSize = "12px";
btnButton.id = "btn" + avatar.node_id + "_" + button.name;
btnButton.classList.add("btn_button");
btnButton.style.flexGrow = "2";
btnButton.classList.add("btn");
btnButton.classList.add("btn-primary");
btnButton.classList.add("btn-sm");
Expand All @@ -750,6 +763,33 @@ function createElementForNode(avatar, text, container, fieldsObject, get_up_to_d
inputGroup.appendChild(btnButton);
}
node.appendChild(inputGroup);
const telegaButtons = [{ "name": "Cancel", "command": "0", "title": "Cancel" }, { "name": "SelfTest", "command": "1", "title": "SelfTest" }, { "name": "MotorID", "command": "2", "title": "MotorID" }];
if (fieldsObject && fieldsObject["Name"] && fieldsObject["Name"].includes("telega")) {
const telegaInputGroup = document.createElement("div");
telegaInputGroup.classList.add("input-group");
telegaInputGroup.style.width = "100%";
telegaInputGroup.style.setProperty("backgroundColor", "transparent", "important");
for (const button of telegaButtons) {
const btnButton = document.createElement("button");
btnButton.style.fontSize = "12px";
btnButton.id = "btn" + avatar.node_id + "_" + button.name;
btnButton.classList.add("btn_button");
btnButton.style.flexGrow = "2";
btnButton.classList.add("btn");
btnButton.classList.add("btn-primary");
btnButton.classList.add("btn-sm");
btnButton.innerHTML = button.name;
btnButton.title = button.title;
btnButton.onclick = async () => {
const result = await yukon_state.zubax_apij.send_command(avatar.node_id, button.command, "");
doCommandFeedbackResult(result, feedbackMessage);
};
telegaInputGroup.appendChild(btnButton);
}
node.appendChild(telegaInputGroup);
}



// Add an input-group input-group-text for command id and command text argument, both should have inputs. Then add a send command button
const customCommandInputGroup = document.createElement("div");
Expand Down Expand Up @@ -790,6 +830,8 @@ function createElementForNode(avatar, text, container, fieldsObject, get_up_to_d
inputGroup2.style.setProperty("backgroundColor", "transparent", "important");
// Add a button for firmware update
const btnFirmwareUpdate = document.createElement("button");
btnFirmwareUpdate.style.width = "100%";
btnFirmwareUpdate.title = "Please also enable firmware update in settings and choose the correct folder there."
btnFirmwareUpdate.style.fontSize = "12px";
btnFirmwareUpdate.classList.add("btn_button", "btn", "btn-secondary", "btn-sm");
btnFirmwareUpdate.innerHTML = "Choose firmware";
Expand All @@ -809,6 +851,7 @@ function createElementForNode(avatar, text, container, fieldsObject, get_up_to_d
btnMore.classList.add("btn_button", "btn", "btn-secondary", "btn-sm");
btnMore.innerHTML = "...";
btnMore.title = "More commands"
btnMore.style.display = "none";

btnMore.addEventListener("click", async function () {
yukon_state.commandsComponent.parent.parent.setActiveContentItem(yukon_state.commandsComponent.parent);
Expand Down Expand Up @@ -943,16 +986,16 @@ function addHorizontalElements(monitor2Div, matchingPort, currentLinkDsdlDatatyp
}
horizontal_line_label.innerHTML = currentLinkDsdlDatatype;
horizontal_line_label.style.zIndex = "3";
horizontal_line_label.style.backgroundColor = settings["LinkLabelColor"];
horizontal_line_label.style.color = settings["LinkLabelTextColor"];
// horizontal_line_label.style.backgroundColor = settings["LinkLabelColor"];
// horizontal_line_label.style.color = settings["LinkLabelTextColor"];
horizontal_line_label.addEventListener("mouseover", () => {
horizontal_line_label.style.backgroundColor = settings["LinkLabelHighlightColor"];
horizontal_line_label.style.color = settings["LinkLabelHighlightTextColor"];
horizontal_line_label.style.setProperty("background-color", settings["LinkLabelHighlightColor"], "important");
horizontal_line_label.style.setProperty("color", settings["LinkLabelHighlightTextColor"], "important");
});
horizontal_line_label.addEventListener("mouseout", () => {
if (!toggledOn.value) {
horizontal_line_label.style.backgroundColor = settings["LinkLabelColor"];
horizontal_line_label.style.color = settings["LinkLabelTextColor"];
horizontal_line_label.style.removeProperty("background-color");
horizontal_line_label.style.removeProperty("color");
}
});
if (settings.ShowLinkNameOnSeparateLine && settings.ShowNameAboveDatatype && link_name_label) {
Expand Down Expand Up @@ -1140,7 +1183,7 @@ function addVerticalLines(monitor2Div, ports, y_counter, containerElement, setti
potentialPopup.style.top = port_label.getBoundingClientRect().height + "px";
potentialPopup.style.left = "0px";
potentialPopup.style.border = "1px solid black";
potentialPopup.style.borderRadius = "5px";
potentialPopup.style.borderRadius = "0px";
potentialPopup.style.padding = "5px";
potentialPopup.style.zIndex = "5";
potentialPopup.style.width = "fit-content(400px)";
Expand Down
2 changes: 2 additions & 0 deletions yukon/web/modules/panels/monitor2/publishers.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ async function createPublisherFrame(publisher, yukon_state) {
async function typeWasChosen() {
// Create a vertical flexbox for holding rows of content
chooseTypeField.disabled = true;

const content = document.createElement('div');
content.classList.add("publisher-content");
frame.appendChild(content);
Expand All @@ -130,6 +131,7 @@ async function createPublisherFrame(publisher, yukon_state) {
portIdInput.classList.add("port-id-input");
portIdInput.placeholder = "Port ID";
portIdInput.title = "Port ID"
portIdInput.disabled = true;
// TODO: Get the port id value in case the datatype of the publisher
// uses a fixed port id
portIdInput.addEventListener('input', async () => {
Expand Down
4 changes: 4 additions & 0 deletions yukon/web/style/darkmode.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
background-size: 80% !important;
}

.horizontal_line_label {
color: lightblue !important;
}

.lm_content {
color: #ffffff
}
Expand Down
4 changes: 2 additions & 2 deletions yukon/web/style/monitor2.css
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
max-width: 700px;
background-color: rgb(165 66 66);
border: 1px solid #ccc;
border-radius: 4px;
border-radius: 0px;
padding: 0.5em;
margin-top: 0.5em;
box-shadow: 0 1px 4px 0 rgba(0, 0, 0, .2);
Expand Down Expand Up @@ -146,7 +146,7 @@
border-top-style: solid;
}
:root {
--line-color: rgb(178, 115, 33);
--line-color: silver;
}

@media (prefers-color-scheme: dark) {
Expand Down
14 changes: 9 additions & 5 deletions yukon/web/style/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
margin-left: 0px !important;
}

.horizontal_line_label {
color: darkblue !important;
}

.lm_header .lm_controls {
display: flex;
flex-direction: row;
Expand All @@ -43,15 +47,15 @@
}

label.port_number_label {
font-weight: 500;
font-weight: 400;
display: flex;
justify-content: flex-end;
align-items: center;
}

textarea.port_number_label,
input.port_number_label {
font-weight: 500;
font-weight: 400;
border: none;
border-left: 6px solid SlateBlue;
}
Expand Down Expand Up @@ -260,7 +264,7 @@ body {
#toolbar button {
border: 1px solid #000;
height: 1.7em;
border-radius: 0.25em;
border-radius: 0;
background-color: rgb(135, 135, 135);
color: #fff;
font-size: 1.5em;
Expand Down Expand Up @@ -312,7 +316,7 @@ button#btnShowHideToolbar {
width: 1em;
height: 1em;
border: 1px solid #000;
border-radius: 0.25em;
border-radius: 0em;
font-size: 1.5em;
padding: 0.25em 0.5em;
z-index: 3;
Expand Down Expand Up @@ -462,7 +466,7 @@ button#btnShowHideToolbar:active {
.my-modal-content {
margin-top: 10vh;
padding: 20px 10px;
border-radius: 10px;
border-radius: 0px;
width: 80%;
background-color: white;
}
Expand Down

0 comments on commit 6f54490

Please sign in to comment.