From 5d801b0386aa2f68cdcda438ad30a8b621e4a710 Mon Sep 17 00:00:00 2001 From: Arturo Buzarra Date: Fri, 22 Mar 2024 12:22:03 +0100 Subject: [PATCH] connectcore-demo-example: add support to a third ethernet interface Signed-off-by: Arturo Buzarra --- connectcore-demo-example/demoserver.py | 22 +++--- connectcore-demo-example/index.html | 56 +++++++++++++ connectcore-demo-example/network.html | 78 +++++++++++++++++++ .../static/js/ccimx6qpsbc.js | 6 +- .../static/js/ccimx6sbc.js | 6 +- .../static/js/ccimx6ulsbc.js | 6 +- .../static/js/ccimx8m-nano.js | 4 +- .../static/js/ccimx8mm-dvk.js | 4 +- .../static/js/ccimx8x-sbc-pro.js | 4 +- .../static/js/ccimx93-dvk.js | 6 +- .../static/js/ccmp133-dvk.js | 4 +- .../static/js/ccmp157-dvk.js | 4 +- .../static/js/ccmp255-dvk.js | 15 +++- connectcore-demo-example/static/js/common.js | 7 ++ .../static/js/dashboard.js | 63 ++++++++++----- connectcore-demo-example/static/js/devices.js | 47 +++++++---- connectcore-demo-example/static/js/network.js | 6 +- 17 files changed, 266 insertions(+), 72 deletions(-) diff --git a/connectcore-demo-example/demoserver.py b/connectcore-demo-example/demoserver.py index 97bc1d8..0c9f3b2 100755 --- a/connectcore-demo-example/demoserver.py +++ b/connectcore-demo-example/demoserver.py @@ -186,24 +186,22 @@ class RequestHandler(http.server.SimpleHTTPRequestHandler): "ethernet0_ip": ZERO_IP, "ethernet1_mac": ZERO_MAC, "ethernet1_ip": ZERO_IP, + "ethernet2_mac": ZERO_MAC, + "ethernet2_ip": ZERO_IP, } # Fill ethernet interfaces data. try: interfaces = NetworkInterface.list_interfaces() - if interfaces and "eth0" in interfaces: + for iface in interfaces: + if iface not in ("eth0", "eth1", "eth2"): + continue try: - net_iface = NetworkInterface.get("eth0") - info["ethernet0_mac"] = str(net_iface.mac) - info["ethernet0_ip"] = str(net_iface.ipv4) + net_iface = NetworkInterface.get(iface) + index = iface[len("eth"):] + info["ethernet%s_mac" % index] = str(net_iface.mac) + info["ethernet%s_ip" % index] = str(net_iface.ipv4) except NetworkException as exc2: - log.error("Error reading interface 'eth0' data: %s", str(exc2)) - if interfaces and "eth1" in interfaces: - try: - net_iface = NetworkInterface.get("eth1") - info["ethernet1_mac"] = mac_to_human_string(net_iface.mac) - info["ethernet1_ip"] = str(net_iface.ipv4) - except NetworkException as exc2: - log.error("Error reading interface 'eth1' data: %s", str(exc2)) + log.error("Error reading interface '%s' data: %s", iface, str(exc2)) except DigiAPIXException as exc: log.error("Error listing network interfaces: %s", str(exc)) diff --git a/connectcore-demo-example/index.html b/connectcore-demo-example/index.html index 7a04e48..dc83c75 100644 --- a/connectcore-demo-example/index.html +++ b/connectcore-demo-example/index.html @@ -586,6 +586,62 @@ Digi Demo - Dashboard +
+ Ethernet 2 stats + +
+
+ +
+ + Ethernet 2 stats +
+
+
+ + + + + + + + + + + + + + + + + + + + + +
+ Status: + + - +
+ MAC: + + - +
+ IP: + + - +
+ TX data: + + - +
+ RX data: + + - +
+
+
Video info diff --git a/connectcore-demo-example/network.html b/connectcore-demo-example/network.html index 8cb7a3d..9c35ac7 100644 --- a/connectcore-demo-example/network.html +++ b/connectcore-demo-example/network.html @@ -240,6 +240,63 @@ Digi Demo - Network
+
+
+ + Ethernet 2 +
+
+ +
@@ -379,6 +436,27 @@ Digi Demo - Network $("#eth1_dns2_addr").on("input", function(event) { validateInterface("eth1"); }); + $('#eth2_enable').click(function(){ + updateInterfaceControls("eth2"); + }); + $("#eth2_ip_mode").on("change", function(event) { + updateInterfaceControls("eth2"); + }); + $("#eth2_ip_addr").on("input", function(event) { + validateInterface("eth2"); + }); + $("#eth2_subnet_mask").on("input", function(event) { + validateInterface("eth2"); + }); + $("#eth2_default_gateway").on("input", function(event) { + validateInterface("eth2"); + }); + $("#eth2_dns1_addr").on("input", function(event) { + validateInterface("eth2"); + }); + $("#eth2_dns2_addr").on("input", function(event) { + validateInterface("eth2"); + }); $('#wlan0_enable').click(function(){ updateInterfaceControls("wlan0"); }); diff --git a/connectcore-demo-example/static/js/ccimx6qpsbc.js b/connectcore-demo-example/static/js/ccimx6qpsbc.js index 7fcdd8e..394532e 100644 --- a/connectcore-demo-example/static/js/ccimx6qpsbc.js +++ b/connectcore-demo-example/static/js/ccimx6qpsbc.js @@ -1,5 +1,5 @@ /* - * Copyright 2023, Digi International Inc. + * Copyright 2023,2024 Digi International Inc. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -151,7 +151,7 @@ class CCIMX6QPSBC extends ConnectCoreDevice { // Capabilities SUPPORTS_VIDEO_BRIGHTNESS = false; - SUPPORTS_DUAL_ETHERNET = false; + SUPPORTS_NUM_ETHERNET = 1; // Misc info PCB_COLOR = ID_COLOR_GREEN; @@ -160,4 +160,4 @@ class CCIMX6QPSBC extends ConnectCoreDevice { constructor(deviceData) { super(CCIMX6QPSBC.DEVICE_TYPE, CCIMX6QPSBC.PLATFORM_NAME, deviceData); } -} \ No newline at end of file +} diff --git a/connectcore-demo-example/static/js/ccimx6sbc.js b/connectcore-demo-example/static/js/ccimx6sbc.js index 23d783d..21099db 100644 --- a/connectcore-demo-example/static/js/ccimx6sbc.js +++ b/connectcore-demo-example/static/js/ccimx6sbc.js @@ -1,5 +1,5 @@ /* - * Copyright 2023, Digi International Inc. + * Copyright 2023,2024 Digi International Inc. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -151,7 +151,7 @@ class CCIMX6SBC extends ConnectCoreDevice { // Capabilities SUPPORTS_VIDEO_BRIGHTNESS = false; - SUPPORTS_DUAL_ETHERNET = false; + SUPPORTS_NUM_ETHERNET = 1; // Misc info PCB_COLOR = ID_COLOR_GREEN; @@ -160,4 +160,4 @@ class CCIMX6SBC extends ConnectCoreDevice { constructor(deviceData) { super(CCIMX6SBC.DEVICE_TYPE, CCIMX6SBC.PLATFORM_NAME, deviceData); } -} \ No newline at end of file +} diff --git a/connectcore-demo-example/static/js/ccimx6ulsbc.js b/connectcore-demo-example/static/js/ccimx6ulsbc.js index 5d8a8ef..12169e5 100644 --- a/connectcore-demo-example/static/js/ccimx6ulsbc.js +++ b/connectcore-demo-example/static/js/ccimx6ulsbc.js @@ -1,5 +1,5 @@ /* - * Copyright 2022, 2023, Digi International Inc. + * Copyright 2022-2024, Digi International Inc. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -151,7 +151,7 @@ class CCIMX6ULSBC extends ConnectCoreDevice { // Capabilities SUPPORTS_VIDEO_BRIGHTNESS = false; - SUPPORTS_DUAL_ETHERNET = true; + SUPPORTS_NUM_ETHERNET = 2; // Misc info PCB_COLOR = ID_COLOR_BLUE; @@ -160,4 +160,4 @@ class CCIMX6ULSBC extends ConnectCoreDevice { constructor(deviceData) { super(CCIMX6ULSBC.DEVICE_TYPE, CCIMX6ULSBC.PLATFORM_NAME, deviceData); } -} \ No newline at end of file +} diff --git a/connectcore-demo-example/static/js/ccimx8m-nano.js b/connectcore-demo-example/static/js/ccimx8m-nano.js index 3adb61a..337d36d 100644 --- a/connectcore-demo-example/static/js/ccimx8m-nano.js +++ b/connectcore-demo-example/static/js/ccimx8m-nano.js @@ -1,5 +1,5 @@ /* - * Copyright 2022, 2023, Digi International Inc. + * Copyright 2022-2024, Digi International Inc. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -138,7 +138,7 @@ class CCIMX8MNANO extends ConnectCoreDevice { // Capabilities SUPPORTS_VIDEO_BRIGHTNESS = false; - SUPPORTS_DUAL_ETHERNET = false; + SUPPORTS_NUM_ETHERNET = 1; // Misc info PCB_COLOR = ID_COLOR_BLUE; diff --git a/connectcore-demo-example/static/js/ccimx8mm-dvk.js b/connectcore-demo-example/static/js/ccimx8mm-dvk.js index 5aad4ad..5c799ca 100644 --- a/connectcore-demo-example/static/js/ccimx8mm-dvk.js +++ b/connectcore-demo-example/static/js/ccimx8mm-dvk.js @@ -1,5 +1,5 @@ /* - * Copyright 2022, 2023, Digi International Inc. + * Copyright 2022-2024, Digi International Inc. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -138,7 +138,7 @@ class CCIMX8MMINI extends ConnectCoreDevice { // Capabilities SUPPORTS_VIDEO_BRIGHTNESS = false; - SUPPORTS_DUAL_ETHERNET = false; + SUPPORTS_NUM_ETHERNET = 1; // Misc info PCB_COLOR = ID_COLOR_BLUE; diff --git a/connectcore-demo-example/static/js/ccimx8x-sbc-pro.js b/connectcore-demo-example/static/js/ccimx8x-sbc-pro.js index 96bd87c..7b8e4c0 100644 --- a/connectcore-demo-example/static/js/ccimx8x-sbc-pro.js +++ b/connectcore-demo-example/static/js/ccimx8x-sbc-pro.js @@ -1,5 +1,5 @@ /* - * Copyright 2022, 2023, Digi International Inc. + * Copyright 2022-2024, Digi International Inc. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -151,7 +151,7 @@ class CCIMX8X extends ConnectCoreDevice { // Capabilities SUPPORTS_VIDEO_BRIGHTNESS = false; - SUPPORTS_DUAL_ETHERNET = true; + SUPPORTS_NUM_ETHERNET = 2; // Misc info PCB_COLOR = ID_COLOR_BLUE; diff --git a/connectcore-demo-example/static/js/ccimx93-dvk.js b/connectcore-demo-example/static/js/ccimx93-dvk.js index ddd1b06..7e8a805 100644 --- a/connectcore-demo-example/static/js/ccimx93-dvk.js +++ b/connectcore-demo-example/static/js/ccimx93-dvk.js @@ -1,5 +1,5 @@ /* - * Copyright 2023, Digi International Inc. + * Copyright 2022-2024, Digi International Inc. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -151,7 +151,7 @@ class CCIMX93 extends ConnectCoreDevice { // Capabilities SUPPORTS_VIDEO_BRIGHTNESS = false; - SUPPORTS_DUAL_ETHERNET = true; + SUPPORTS_NUM_ETHERNET = 2; // Misc info PCB_COLOR = ID_COLOR_BLUE; @@ -160,4 +160,4 @@ class CCIMX93 extends ConnectCoreDevice { constructor(deviceData) { super(CCIMX93.DEVICE_TYPE, CCIMX93.PLATFORM_NAME, deviceData); } -} \ No newline at end of file +} diff --git a/connectcore-demo-example/static/js/ccmp133-dvk.js b/connectcore-demo-example/static/js/ccmp133-dvk.js index 00eb059..69a0606 100644 --- a/connectcore-demo-example/static/js/ccmp133-dvk.js +++ b/connectcore-demo-example/static/js/ccmp133-dvk.js @@ -1,5 +1,5 @@ /* - * Copyright 2022, 2023, Digi International Inc. + * Copyright 2022-2024, Digi International Inc. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -138,7 +138,7 @@ class CCMP133 extends ConnectCoreDevice { // Capabilities SUPPORTS_VIDEO_BRIGHTNESS = false; - SUPPORTS_DUAL_ETHERNET = false; + SUPPORTS_NUM_ETHERNET = 1; // Misc info PCB_COLOR = ID_COLOR_BLUE; diff --git a/connectcore-demo-example/static/js/ccmp157-dvk.js b/connectcore-demo-example/static/js/ccmp157-dvk.js index fc2aa23..dc8803c 100644 --- a/connectcore-demo-example/static/js/ccmp157-dvk.js +++ b/connectcore-demo-example/static/js/ccmp157-dvk.js @@ -1,5 +1,5 @@ /* - * Copyright 2022, 2023, Digi International Inc. + * Copyright 2022-2024, Digi International Inc. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -138,7 +138,7 @@ class CCMP157 extends ConnectCoreDevice { // Capabilities SUPPORTS_VIDEO_BRIGHTNESS = false; - SUPPORTS_DUAL_ETHERNET = false; + SUPPORTS_NUM_ETHERNET = 1; // Misc info PCB_COLOR = ID_COLOR_BLUE; diff --git a/connectcore-demo-example/static/js/ccmp255-dvk.js b/connectcore-demo-example/static/js/ccmp255-dvk.js index 76b5922..6579c62 100644 --- a/connectcore-demo-example/static/js/ccmp255-dvk.js +++ b/connectcore-demo-example/static/js/ccmp255-dvk.js @@ -88,6 +88,19 @@ class CCMP255 extends ConnectCoreDevice { ETHERNET1_COMPONENT_AREA_WIDTH_PERCENT = 9.8; ETHERNET1_COMPONENT_AREA_HEIGHT_PERCENT = 17; + ETHERNET2_COMPONENT_VISIBLE = false; + ETHERNET2_COMPONENT_HAS_PANEL = true; + ETHERNET2_COMPONENT_HAS_ARROW = true; + ETHERNET2_COMPONENT_PANEL_ALWAYS_VISIBLE = false; + ETHERNET2_COMPONENT_PANEL_ORIENTATION = VALUE_TOP; + ETHERNET2_COMPONENT_PANEL_HORIZONTAL_PERCENT = 33; + ETHERNET2_COMPONENT_PANEL_VERTICAL_PERCENT = 22.5; + ETHERNET2_COMPONENT_ARROW_PERCENT = 47.5; + ETHERNET2_COMPONENT_AREA_TOP_PERCENT = 2; + ETHERNET2_COMPONENT_AREA_LEFT_PERCENT = 44; + ETHERNET2_COMPONENT_AREA_WIDTH_PERCENT = 9.8; + ETHERNET2_COMPONENT_AREA_HEIGHT_PERCENT = 17; + CONSOLE_COMPONENT_VISIBLE = true; CONSOLE_COMPONENT_HAS_PANEL = false; CONSOLE_COMPONENT_HAS_ARROW = false; @@ -151,7 +164,7 @@ class CCMP255 extends ConnectCoreDevice { // Capabilities SUPPORTS_VIDEO_BRIGHTNESS = false; - SUPPORTS_DUAL_ETHERNET = true; + SUPPORTS_NUM_ETHERNET = 2; // Misc info PCB_COLOR = ID_COLOR_BLUE; diff --git a/connectcore-demo-example/static/js/common.js b/connectcore-demo-example/static/js/common.js index eacfa67..bcf7ed2 100644 --- a/connectcore-demo-example/static/js/common.js +++ b/connectcore-demo-example/static/js/common.js @@ -55,16 +55,22 @@ const ID_ERROR_MESSAGE = "error_msg"; const ID_ERROR_TITLE = "error_title"; const ID_ETHERNET0 = "ethernet0"; const ID_ETHERNET1 = "ethernet1"; +const ID_ETHERNET2 = "ethernet2"; const ID_ETHERNET0_IP = "ethernet0_ip"; const ID_ETHERNET1_IP = "ethernet1_ip"; +const ID_ETHERNET2_IP = "ethernet2_ip"; const ID_ETHERNET0_MAC = "ethernet0_mac"; const ID_ETHERNET1_MAC = "ethernet1_mac"; +const ID_ETHERNET2_MAC = "ethernet2_mac"; const ID_ETHERNET0_READ_DATA = "ethernet0_received_data"; const ID_ETHERNET1_READ_DATA = "ethernet1_received_data"; +const ID_ETHERNET2_READ_DATA = "ethernet2_received_data"; const ID_ETHERNET0_SENT_DATA = "ethernet0_sent_data"; const ID_ETHERNET1_SENT_DATA = "ethernet1_sent_data"; +const ID_ETHERNET2_SENT_DATA = "ethernet2_sent_data"; const ID_ETHERNET0_STATE = "ethernet0_state"; const ID_ETHERNET1_STATE = "ethernet1_state"; +const ID_ETHERNET2_STATE = "ethernet2_state"; const ID_FILES = "files"; const ID_FLASH_MEMORY = "flash_memory"; const ID_FLASH_SIZE = "flash_size"; @@ -160,6 +166,7 @@ const ERROR_UNKNOWN_ERROR = "Unknown error. Make sure that the server is running const IFACE_BT = "hci0"; const IFACE_ETH0 = "eth0"; const IFACE_ETH1 = "eth1"; +const IFACE_ETH2 = "eth2"; const IFACE_WIFI = "wlan0"; const PREFIX_STREAM = "system_monitor/"; diff --git a/connectcore-demo-example/static/js/dashboard.js b/connectcore-demo-example/static/js/dashboard.js index 2ef8eb5..528fcf7 100644 --- a/connectcore-demo-example/static/js/dashboard.js +++ b/connectcore-demo-example/static/js/dashboard.js @@ -43,6 +43,10 @@ const ID_ETHERNET1_PANEL = "ethernet1_panel"; const ID_ETHERNET1_PANEL_AREA = "ethernet1_panel_area"; const ID_ETHERNET1_PANEL_ARROW = "ethernet1_panel_arrow"; const ID_ETHERNET1_PANEL_ICON = "ethernet1_panel_icon"; +const ID_ETHERNET2_PANEL = "ethernet2_panel"; +const ID_ETHERNET2_PANEL_AREA = "ethernet2_panel_area"; +const ID_ETHERNET2_PANEL_ARROW = "ethernet2_panel_arrow"; +const ID_ETHERNET2_PANEL_ICON = "ethernet2_panel_icon"; const ID_FLASH_MEMORY_PANEL = "flash_memory_panel"; const ID_FLASH_MEMORY_PANEL_AREA = "flash_memory_panel_area"; const ID_FLASH_MEMORY_PANEL_ARROW = "flash_memory_panel_arrow"; @@ -69,6 +73,11 @@ const ID_WIFI_BT_PANEL = "wifi_bt_panel"; const ID_WIFI_BT_PANEL_AREA = "wifi_bt_panel_area"; const ID_WIFI_BT_PANEL_ARROW = "wifi_bt_panel_arrow"; const ID_WIFI_BT_PANEL_ICON = "wifi_bt_panel_icon"; +const ID_ETHERNETX = "ethernet{index}"; +const ID_ETHERNETX_PANEL = "ethernet{index}_panel"; +const ID_ETHERNETX_PANEL_AREA = "ethernet{index}_panel_area"; +const ID_ETHERNETX_PANEL_ARROW = "ethernet{index}_panel_arrow"; +const ID_ETHERNETX_PANEL_ICON = "ethernet{index}_panel_icon"; const USER_LED = "user_led"; @@ -81,6 +90,9 @@ const STREAM_ETHERNET0_STATE = PREFIX_STREAM + IFACE_ETH0 + "/state"; const STREAM_ETHERNET1_READ_BYTES = PREFIX_STREAM + IFACE_ETH1 + "/rx_bytes"; const STREAM_ETHERNET1_SENT_BYTES = PREFIX_STREAM + IFACE_ETH1 + "/tx_bytes"; const STREAM_ETHERNET1_STATE = PREFIX_STREAM + IFACE_ETH1 + "/state"; +const STREAM_ETHERNET2_READ_BYTES = PREFIX_STREAM + IFACE_ETH2 + "/rx_bytes"; +const STREAM_ETHERNET2_SENT_BYTES = PREFIX_STREAM + IFACE_ETH2 + "/tx_bytes"; +const STREAM_ETHERNET2_STATE = PREFIX_STREAM + IFACE_ETH2 + "/state"; const STREAM_LED_STATUS = PREFIX_STREAM + "led_status"; const STREAM_MEMORY_USED = PREFIX_STREAM + "used_memory"; const STREAM_WIFI_READ_BYTES = PREFIX_STREAM + IFACE_WIFI + "/rx_bytes"; @@ -275,7 +287,7 @@ function refreshDevice() { initializingDevice = false; return; } - device.refreshIPs(data[ID_ETHERNET0_IP], data[ID_ETHERNET1_IP], data[ID_WIFI_IP]); + device.refreshIPs(data[ID_ETHERNET0_IP], data[ID_ETHERNET1_IP], data[ID_ETHERNET2_IP], data[ID_WIFI_IP]); updateInfoValues(); } ).fail(function(response) { @@ -339,6 +351,7 @@ function processDeviceStatusResponse(response) { // Check if IP values are initialized. if ((response[STREAM_ETHERNET0_STATE] == 1 && device.getEthernetIP(0) == "0.0.0.0") || (response[STREAM_ETHERNET1_STATE] == 1 && device.getEthernetIP(1) == "0.0.0.0") + || (response[STREAM_ETHERNET2_STATE] == 1 && device.getEthernetIP(2) == "0.0.0.0") || (response[STREAM_WIFI_STATE] == 1 && device.getWifiIP() == "0.0.0.0")) { deviceInitialized = false; } @@ -456,26 +469,25 @@ function initializeComponents() { var wifiBtPanelIcon = document.getElementById(ID_WIFI_BT_PANEL_ICON); var wifiBtInfo = {"panel": wifiBtPanel, "arrow": wifiBtPanelArrow, "area": wifiBtPanelArea, "icon": wifiBtPanelIcon, "data": device.getWifiBtComponentData()}; components[ID_WIFI_BT] = wifiBtInfo; - // Ethernet 0 component. - var ethernet0Panel = document.getElementById(ID_ETHERNET0_PANEL); - var ethernet0PanelArrow = document.getElementById(ID_ETHERNET0_PANEL_ARROW); - var ethernet0PanelArea = document.getElementById(ID_ETHERNET0_PANEL_AREA); - if (device.getPCBColor() == ID_COLOR_GREEN) - ethernet0PanelArea.classList.add(CLASS_PANEL_BLUE); - var ethernet0PanelIcon = document.getElementById(ID_ETHERNET0_PANEL_ICON); - var ethernet0Info = {"panel": ethernet0Panel, "arrow": ethernet0PanelArrow, "area": ethernet0PanelArea, "icon": ethernet0PanelIcon, "data": device.getEthernetComponentData(0)}; - components[ID_ETHERNET0] = ethernet0Info; - if (device.supportsDualEthernet()) { - // Ethernet 1 component. - var ethernet1Panel = document.getElementById(ID_ETHERNET1_PANEL); - var ethernet1PanelArrow = document.getElementById(ID_ETHERNET1_PANEL_ARROW); - var ethernet1PanelArea = document.getElementById(ID_ETHERNET1_PANEL_AREA); + // Ethernet components. + for (var i = 0; i < device.getEthernetNumSupported(); i++) { + var idEth = ID_ETHERNETX.replace('{index}', i); + var idEthPanel = ID_ETHERNETX_PANEL.replace('{index}', i); + var idEthPanelArea = ID_ETHERNETX_PANEL_AREA.replace('{index}', i); + var idEthPanelArrow = ID_ETHERNETX_PANEL_ARROW.replace('{index}', i); + var idEthPanelIcon = ID_ETHERNETX_PANEL_ICON.replace('{index}', i); + + var ethernetPanel = document.getElementById(idEthPanel); + var ethernetPanelArrow = document.getElementById(idEthPanelArrow); + var ethernetPanelArea = document.getElementById(idEthPanelArea); if (device.getPCBColor() == ID_COLOR_GREEN) - ethernet1PanelArea.classList.add(CLASS_PANEL_BLUE); - var ethernet1PanelIcon = document.getElementById(ID_ETHERNET1_PANEL_ICON); - var ethernet1Info = {"panel": ethernet1Panel, "arrow": ethernet1PanelArrow, "area": ethernet1PanelArea, "icon": ethernet1PanelIcon, "data": device.getEthernetComponentData(1)}; - components[ID_ETHERNET1] = ethernet1Info; - } else { + ethernetPanelArea.classList.add(CLASS_PANEL_BLUE); + var ethernetPanelIcon = document.getElementById(idEthPanelIcon); + var ethernetInfo = {"panel": ethernetPanel, "arrow": ethernetPanelArrow, "area": ethernetPanelArea, "icon": ethernetPanelIcon, "data": device.getEthernetComponentData(i)}; + components[idEth] = ethernetInfo; + } + + if (device.getEthernetNumSupported() <= 0) { // Update tooltip and title to reflect there is only one Ethernet interface. document.getElementById(ID_ETHERNET0_TOOLTIP).innerText = "Ethernet stats"; document.getElementById(ID_ETHERNET0_TITLE).innerText = "Ethernet stats"; @@ -678,7 +690,7 @@ function updateInfoValues() { // Set MCA HW version. updateFieldValue(ID_MCA_HW_VERSION, device.getMCAHWVersion()); // Iterate Ethernet interfaces. - for (var index = 0; index < device.NUM_ETHERNET_INTERFACES; index++) { + for (var index = 0; index < device.getEthernetNumSupported(); index++) { // Set Ethernet MAC address. updateFieldValue(eval("ID_ETHERNET" + index + "_MAC"), device.getEthernetMAC(index)); // Set Ethernet IP address. @@ -752,6 +764,15 @@ function updateDataPointValue(streamID, value) { case STREAM_ETHERNET1_SENT_BYTES: updateValueWithEffect(ID_ETHERNET1_SENT_DATA, sizeToHumanRead(value)); break; + case STREAM_ETHERNET2_STATE: + updateValueWithEffect(ID_ETHERNET2_STATE, onOffStatus(value)); + break; + case STREAM_ETHERNET2_READ_BYTES: + updateValueWithEffect(ID_ETHERNET2_READ_DATA, sizeToHumanRead(value)); + break; + case STREAM_ETHERNET2_SENT_BYTES: + updateValueWithEffect(ID_ETHERNET2_SENT_DATA, sizeToHumanRead(value)); + break; case STREAM_WIFI_STATE: updateValueWithEffect(ID_WIFI_STATE, onOffStatus(value)); break; diff --git a/connectcore-demo-example/static/js/devices.js b/connectcore-demo-example/static/js/devices.js index 831602a..53ea1aa 100644 --- a/connectcore-demo-example/static/js/devices.js +++ b/connectcore-demo-example/static/js/devices.js @@ -1,5 +1,5 @@ /* - * Copyright 2022, 2023, Digi International Inc. + * Copyright (C) 2022-2024, Digi International Inc. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -109,6 +109,20 @@ class ConnectCoreDevice { ETHERNET1_COMPONENT_AREA_WIDTH_PERCENT = 0; ETHERNET1_COMPONENT_AREA_HEIGHT_PERCENT = 0; + // Ethernet2 panel. + ETHERNET2_COMPONENT_VISIBLE = false; + ETHERNET2_COMPONENT_HAS_PANEL = false; + ETHERNET2_COMPONENT_HAS_ARROW = false; + ETHERNET2_COMPONENT_PANEL_ALWAYS_VISIBLE = false; + ETHERNET2_COMPONENT_PANEL_ORIENTATION = VALUE_TOP; + ETHERNET2_COMPONENT_PANEL_HORIZONTAL_PERCENT = 0; + ETHERNET2_COMPONENT_PANEL_VERTICAL_PERCENT = 0; + ETHERNET2_COMPONENT_ARROW_PERCENT = 0; + ETHERNET2_COMPONENT_AREA_TOP_PERCENT = 0; + ETHERNET2_COMPONENT_AREA_LEFT_PERCENT = 0; + ETHERNET2_COMPONENT_AREA_WIDTH_PERCENT = 0; + ETHERNET2_COMPONENT_AREA_HEIGHT_PERCENT = 0; + // Console. CONSOLE_COMPONENT_VISIBLE = false; CONSOLE_COMPONENT_HAS_PANEL = false; @@ -181,9 +195,9 @@ class ConnectCoreDevice { // Capabilities SUPPORTS_VIDEO_BRIGHTNESS; - SUPPORTS_DUAL_ETHERNET; + SUPPORTS_NUM_ETHERNET; - NUM_ETHERNET_INTERFACES = 2; + MAX_NUM_ETHERNET_INTERFACES = 3; // Device information. #deviceType; @@ -234,15 +248,18 @@ class ConnectCoreDevice { this.#videoResolution = deviceData[ID_VIDEO_RESOLUTION]; this.#sampleRate = deviceData[ID_SAMPLE_RATE]; this.#numSamplesUpload = deviceData[ID_NUM_SAMPLES_UPLOAD]; - for (var index = 0; index < this.NUM_ETHERNET_INTERFACES; index++) { - this.#ethernetMAC[index] = deviceData[eval("ID_ETHERNET" + index + "_MAC")]; - this.#ethernetIP[index] = deviceData[eval("ID_ETHERNET" + index + "_IP")]; + for (var index = 0; index < this.MAX_NUM_ETHERNET_INTERFACES; index++) { + if (deviceData[eval("ID_ETHERNET" + index + "_MAC")]) { + this.#ethernetMAC[index] = deviceData[eval("ID_ETHERNET" + index + "_MAC")]; + this.#ethernetIP[index] = deviceData[eval("ID_ETHERNET" + index + "_IP")]; + } } } - refreshIPs(eth0_ip, eth1_ip, wifi_ip) { + refreshIPs(eth0_ip, eth1_ip, eth2_ip, wifi_ip) { this.#ethernetIP[0] = eth0_ip; this.#ethernetIP[1] = eth1_ip; + this.#ethernetIP[2] = eth2_ip; this.#wifiIP = wifi_ip; } @@ -313,14 +330,14 @@ class ConnectCoreDevice { // Returns the device Ethernet MAC address for the given interface index. getEthernetMAC(index=0) { - if (index >= this.NUM_ETHERNET_INTERFACES) + if (index >= this.MAX_NUM_ETHERNET_INTERFACES) return ""; return this.#ethernetMAC[index]; } // Returns the device Ethernet IP address for the given interface index. getEthernetIP(index=0) { - if (index >= this.NUM_ETHERNET_INTERFACES) + if (index >= this.MAX_NUM_ETHERNET_INTERFACES) return ""; return this.#ethernetIP[index]; } @@ -420,7 +437,7 @@ class ConnectCoreDevice { // Returns the Ethernet panel data for the given interface index. getEthernetComponentData(index=0) { - if (index >= this.NUM_ETHERNET_INTERFACES) + if (index >= this.SUPPORTS_NUM_ETHERNET) return ""; return JSON.parse(TEMPLATE_COMPONENT_DATA.format(eval("this.ETHERNET" + index + "_COMPONENT_VISIBLE"), eval("this.ETHERNET" + index + "_COMPONENT_HAS_PANEL"), @@ -436,6 +453,11 @@ class ConnectCoreDevice { eval("this.ETHERNET" + index + "_COMPONENT_AREA_HEIGHT_PERCENT"))); } + // Returns number ethernet interfaces the device supports. + getEthernetNumSupported() { + return this.SUPPORTS_NUM_ETHERNET; + } + // Returns the Console panel data. getConsoleComponentData() { return JSON.parse(TEMPLATE_COMPONENT_DATA.format(this.CONSOLE_COMPONENT_VISIBLE, @@ -521,11 +543,6 @@ class ConnectCoreDevice { return this.SUPPORTS_VIDEO_BRIGHTNESS; } - // Returns whether the device supports dual ethernet or not. - supportsDualEthernet() { - return this.SUPPORTS_DUAL_ETHERNET; - } - // Returns the color of the device PCB. getPCBColor() { return this.PCB_COLOR; diff --git a/connectcore-demo-example/static/js/network.js b/connectcore-demo-example/static/js/network.js index 6fd2869..fc216f9 100644 --- a/connectcore-demo-example/static/js/network.js +++ b/connectcore-demo-example/static/js/network.js @@ -188,7 +188,10 @@ function fillNetworkInfo(response, parseElement) { if (parseElement == ALL_ELEMENTS) { if (numEthernetIfaces == 1) { document.getElementById(IFACE_ETH1).style.display = "none"; + document.getElementById(IFACE_ETH2).style.display = "none"; document.getElementById(ID_ETH0_TITLE).innerHTML = "Ethernet"; + } else if (numEthernetIfaces == 2) { + document.getElementById(IFACE_ETH2).style.display = "none"; } if (numWifiIfaces == 0) document.getElementById(IFACE_WIFI).style.display = "none"; @@ -203,6 +206,7 @@ function fillNetworkInfo(response, parseElement) { function updateAllControls() { updateInterfaceControls(IFACE_ETH0); updateInterfaceControls(IFACE_ETH1); + updateInterfaceControls(IFACE_ETH2); updateInterfaceControls(IFACE_WIFI); } @@ -456,4 +460,4 @@ function togglePanelVisibility(interface) { panelButton.classList.add(CLASS_ARROW_UP); }); } -} \ No newline at end of file +}