From 3babd8790210ce046e81024080ee7d7468b3dd99 Mon Sep 17 00:00:00 2001 From: David Escalona Date: Mon, 4 Jul 2022 17:12:07 +0200 Subject: [PATCH] connectcore-demo-example: add dual ethernet support Signed-off-by: David Escalona --- connectcore-demo-example/demoserver.py | 6 +- connectcore-demo-example/index.html | 80 +++++++++++-- .../static/js/ccimx8m-nano.js | 25 ++-- .../static/js/ccimx8mm-dvk.js | 25 ++-- .../static/js/ccimx8x-sbc-pro.js | 38 ++++-- connectcore-demo-example/static/js/common.js | 18 ++- .../static/js/dashboard.js | 90 ++++++++++----- connectcore-demo-example/static/js/devices.js | 109 +++++++++++------- 8 files changed, 269 insertions(+), 122 deletions(-) diff --git a/connectcore-demo-example/demoserver.py b/connectcore-demo-example/demoserver.py index b2017ba..4b38a79 100755 --- a/connectcore-demo-example/demoserver.py +++ b/connectcore-demo-example/demoserver.py @@ -113,8 +113,10 @@ class RequestHandler(http.server.SimpleHTTPRequestHandler): "bluetooth_mac": get_bt_mac("hci0"), "wifi_mac": read_file("/sys/class/net/wlan0/address").strip().upper() if "wlan0" in list_net_ifaces() else ZERO_MAC, "wifi_ip": get_iface_ip("wlan0") if "wlan0" in list_net_ifaces() else ZERO_IP, - "ethernet_mac": read_file("/sys/class/net/eth0/address").strip().upper() if "eth0" in list_net_ifaces() else ZERO_MAC, - "ethernet_ip": get_iface_ip("eth0") if "eth0" in list_net_ifaces() else ZERO_IP, + "ethernet0_mac": read_file("/sys/class/net/eth0/address").strip().upper() if "eth0" in list_net_ifaces() else ZERO_MAC, + "ethernet0_ip": get_iface_ip("eth0") if "eth0" in list_net_ifaces() else ZERO_IP, + "ethernet1_mac": read_file("/sys/class/net/eth1/address").strip().upper() if "eth1" in list_net_ifaces() else ZERO_MAC, + "ethernet1_ip": get_iface_ip("eth1") if "eth1" in list_net_ifaces() else ZERO_IP, } # Send the JSON value. diff --git a/connectcore-demo-example/index.html b/connectcore-demo-example/index.html index 052fb89..9dd2141 100644 --- a/connectcore-demo-example/index.html +++ b/connectcore-demo-example/index.html @@ -541,16 +541,16 @@ Digi Demo - Dashboard -
- Ethernet stats - +
+ Ethernet 0 stats +
-
- +
+
- Ethernet stats -
+ Ethernet 0 stats +
@@ -559,7 +559,7 @@ Digi Demo - Dashboard Status: @@ -567,7 +567,7 @@ Digi Demo - Dashboard MAC address: @@ -575,7 +575,7 @@ Digi Demo - Dashboard IP address: @@ -583,7 +583,7 @@ Digi Demo - Dashboard Sent data: @@ -591,7 +591,63 @@ Digi Demo - Dashboard Received data: + +
- - + -
- - + -
- - + -
- - + -
- - + - +
+
+
+
+ Ethernet 1 stats + +
+
+ +
+ + Ethernet 1 stats +
+
+
+ + + + + + + + + + + + + + + + + + + +
+ Status: + + - +
+ MAC address: + + - +
+ IP address: + + - +
+ Sent data: + + - +
+ Received data: + + -
diff --git a/connectcore-demo-example/static/js/ccimx8m-nano.js b/connectcore-demo-example/static/js/ccimx8m-nano.js index 0e01b62..51ccb83 100644 --- a/connectcore-demo-example/static/js/ccimx8m-nano.js +++ b/connectcore-demo-example/static/js/ccimx8m-nano.js @@ -62,18 +62,18 @@ class CCIMX8MNANO extends ConnectCoreDevice { WIFI_BT_COMPONENT_AREA_WIDTH_PERCENT = 4; WIFI_BT_COMPONENT_AREA_HEIGHT_PERCENT = 6; - ETHERNET_COMPONENT_VISIBLE = true; - ETHERNET_COMPONENT_HAS_PANEL = true; - ETHERNET_COMPONENT_HAS_ARROW = true; - ETHERNET_COMPONENT_PANEL_ALWAYS_VISIBLE = false; - ETHERNET_COMPONENT_PANEL_ORIENTATION = VALUE_LEFT; - ETHERNET_COMPONENT_PANEL_HORIZONTAL_PERCENT = 21; - ETHERNET_COMPONENT_PANEL_VERTICAL_PERCENT = 70; - ETHERNET_COMPONENT_ARROW_PERCENT = 78; - ETHERNET_COMPONENT_AREA_TOP_PERCENT = 77; - ETHERNET_COMPONENT_AREA_LEFT_PERCENT = 11; - ETHERNET_COMPONENT_AREA_WIDTH_PERCENT = 8.5; - ETHERNET_COMPONENT_AREA_HEIGHT_PERCENT = 16; + ETHERNET0_COMPONENT_VISIBLE = true; + ETHERNET0_COMPONENT_HAS_PANEL = true; + ETHERNET0_COMPONENT_HAS_ARROW = true; + ETHERNET0_COMPONENT_PANEL_ALWAYS_VISIBLE = false; + ETHERNET0_COMPONENT_PANEL_ORIENTATION = VALUE_LEFT; + ETHERNET0_COMPONENT_PANEL_HORIZONTAL_PERCENT = 21; + ETHERNET0_COMPONENT_PANEL_VERTICAL_PERCENT = 70; + ETHERNET0_COMPONENT_ARROW_PERCENT = 78; + ETHERNET0_COMPONENT_AREA_TOP_PERCENT = 77; + ETHERNET0_COMPONENT_AREA_LEFT_PERCENT = 11; + ETHERNET0_COMPONENT_AREA_WIDTH_PERCENT = 8.5; + ETHERNET0_COMPONENT_AREA_HEIGHT_PERCENT = 16; CONSOLE_COMPONENT_VISIBLE = true; CONSOLE_COMPONENT_HAS_PANEL = false; @@ -138,6 +138,7 @@ class CCIMX8MNANO extends ConnectCoreDevice { // Capabilities SUPPORTS_VIDEO_BRIGHTNESS = false; + SUPPORTS_DUAL_ETHERNET = false; // Constructor. constructor(deviceData) { diff --git a/connectcore-demo-example/static/js/ccimx8mm-dvk.js b/connectcore-demo-example/static/js/ccimx8mm-dvk.js index 95b69c8..0fb4d9c 100644 --- a/connectcore-demo-example/static/js/ccimx8mm-dvk.js +++ b/connectcore-demo-example/static/js/ccimx8mm-dvk.js @@ -62,18 +62,18 @@ class CCIMX8MMINI extends ConnectCoreDevice { WIFI_BT_COMPONENT_AREA_WIDTH_PERCENT = 4; WIFI_BT_COMPONENT_AREA_HEIGHT_PERCENT = 6; - ETHERNET_COMPONENT_VISIBLE = true; - ETHERNET_COMPONENT_HAS_PANEL = true; - ETHERNET_COMPONENT_HAS_ARROW = true; - ETHERNET_COMPONENT_PANEL_ALWAYS_VISIBLE = false; - ETHERNET_COMPONENT_PANEL_ORIENTATION = VALUE_LEFT; - ETHERNET_COMPONENT_PANEL_HORIZONTAL_PERCENT = 21; - ETHERNET_COMPONENT_PANEL_VERTICAL_PERCENT = 70; - ETHERNET_COMPONENT_ARROW_PERCENT = 78; - ETHERNET_COMPONENT_AREA_TOP_PERCENT = 77; - ETHERNET_COMPONENT_AREA_LEFT_PERCENT = 11; - ETHERNET_COMPONENT_AREA_WIDTH_PERCENT = 8.5; - ETHERNET_COMPONENT_AREA_HEIGHT_PERCENT = 16; + ETHERNET0_COMPONENT_VISIBLE = true; + ETHERNET0_COMPONENT_HAS_PANEL = true; + ETHERNET0_COMPONENT_HAS_ARROW = true; + ETHERNET0_COMPONENT_PANEL_ALWAYS_VISIBLE = false; + ETHERNET0_COMPONENT_PANEL_ORIENTATION = VALUE_LEFT; + ETHERNET0_COMPONENT_PANEL_HORIZONTAL_PERCENT = 21; + ETHERNET0_COMPONENT_PANEL_VERTICAL_PERCENT = 70; + ETHERNET0_COMPONENT_ARROW_PERCENT = 78; + ETHERNET0_COMPONENT_AREA_TOP_PERCENT = 77; + ETHERNET0_COMPONENT_AREA_LEFT_PERCENT = 11; + ETHERNET0_COMPONENT_AREA_WIDTH_PERCENT = 8.5; + ETHERNET0_COMPONENT_AREA_HEIGHT_PERCENT = 16; CONSOLE_COMPONENT_VISIBLE = true; CONSOLE_COMPONENT_HAS_PANEL = false; @@ -138,6 +138,7 @@ class CCIMX8MMINI extends ConnectCoreDevice { // Capabilities SUPPORTS_VIDEO_BRIGHTNESS = false; + SUPPORTS_DUAL_ETHERNET = false; // Constructor. constructor(deviceData) { diff --git a/connectcore-demo-example/static/js/ccimx8x-sbc-pro.js b/connectcore-demo-example/static/js/ccimx8x-sbc-pro.js index a781cce..aac583a 100644 --- a/connectcore-demo-example/static/js/ccimx8x-sbc-pro.js +++ b/connectcore-demo-example/static/js/ccimx8x-sbc-pro.js @@ -62,18 +62,31 @@ class CCIMX8X extends ConnectCoreDevice { WIFI_BT_COMPONENT_AREA_WIDTH_PERCENT = 8.5; WIFI_BT_COMPONENT_AREA_HEIGHT_PERCENT = 10; - ETHERNET_COMPONENT_VISIBLE = true; - ETHERNET_COMPONENT_HAS_PANEL = true; - ETHERNET_COMPONENT_HAS_ARROW = true; - ETHERNET_COMPONENT_PANEL_ALWAYS_VISIBLE = false; - ETHERNET_COMPONENT_PANEL_ORIENTATION = VALUE_BOTTOM; - ETHERNET_COMPONENT_PANEL_HORIZONTAL_PERCENT = -7; - ETHERNET_COMPONENT_PANEL_VERTICAL_PERCENT = 34; - ETHERNET_COMPONENT_ARROW_PERCENT = 18; - ETHERNET_COMPONENT_AREA_TOP_PERCENT = 68; - ETHERNET_COMPONENT_AREA_LEFT_PERCENT = 12; - ETHERNET_COMPONENT_AREA_WIDTH_PERCENT = 17; - ETHERNET_COMPONENT_AREA_HEIGHT_PERCENT = 27; + ETHERNET0_COMPONENT_VISIBLE = true; + ETHERNET0_COMPONENT_HAS_PANEL = true; + ETHERNET0_COMPONENT_HAS_ARROW = true; + ETHERNET0_COMPONENT_PANEL_ALWAYS_VISIBLE = false; + ETHERNET0_COMPONENT_PANEL_ORIENTATION = VALUE_BOTTOM; + ETHERNET0_COMPONENT_PANEL_HORIZONTAL_PERCENT = -7; + ETHERNET0_COMPONENT_PANEL_VERTICAL_PERCENT = 34; + ETHERNET0_COMPONENT_ARROW_PERCENT = 18; + ETHERNET0_COMPONENT_AREA_TOP_PERCENT = 68; + ETHERNET0_COMPONENT_AREA_LEFT_PERCENT = 12; + ETHERNET0_COMPONENT_AREA_WIDTH_PERCENT = 17; + ETHERNET0_COMPONENT_AREA_HEIGHT_PERCENT = 27; + + ETHERNET1_COMPONENT_VISIBLE = true; + ETHERNET1_COMPONENT_HAS_PANEL = true; + ETHERNET1_COMPONENT_HAS_ARROW = true; + ETHERNET1_COMPONENT_PANEL_ALWAYS_VISIBLE = false; + ETHERNET1_COMPONENT_PANEL_ORIENTATION = VALUE_BOTTOM; + ETHERNET1_COMPONENT_PANEL_HORIZONTAL_PERCENT = 29; + ETHERNET1_COMPONENT_PANEL_VERTICAL_PERCENT = 34; + ETHERNET1_COMPONENT_ARROW_PERCENT = 35; + ETHERNET1_COMPONENT_AREA_TOP_PERCENT = 68; + ETHERNET1_COMPONENT_AREA_LEFT_PERCENT = 28.5; + ETHERNET1_COMPONENT_AREA_WIDTH_PERCENT = 17; + ETHERNET1_COMPONENT_AREA_HEIGHT_PERCENT = 27; CONSOLE_COMPONENT_VISIBLE = true; CONSOLE_COMPONENT_HAS_PANEL = false; @@ -138,6 +151,7 @@ class CCIMX8X extends ConnectCoreDevice { // Capabilities SUPPORTS_VIDEO_BRIGHTNESS = false; + SUPPORTS_DUAL_ETHERNET = true; // Constructor. constructor(deviceData) { diff --git a/connectcore-demo-example/static/js/common.js b/connectcore-demo-example/static/js/common.js index ab1ff99..b253264 100644 --- a/connectcore-demo-example/static/js/common.js +++ b/connectcore-demo-example/static/js/common.js @@ -50,12 +50,18 @@ const ID_ERROR = "error"; const ID_ERROR_GUIDE = "error_guide"; const ID_ERROR_MESSAGE = "error_msg"; const ID_ERROR_TITLE = "error_title"; -const ID_ETHERNET = "ethernet"; -const ID_ETHERNET_IP = "ethernet_ip"; -const ID_ETHERNET_MAC = "ethernet_mac"; -const ID_ETHERNET_READ_DATA = "ethernet_received_data"; -const ID_ETHERNET_SENT_DATA = "ethernet_sent_data"; -const ID_ETHERNET_STATE = "ethernet_state"; +const ID_ETHERNET0 = "ethernet0"; +const ID_ETHERNET1 = "ethernet1"; +const ID_ETHERNET0_IP = "ethernet0_ip"; +const ID_ETHERNET1_IP = "ethernet1_ip"; +const ID_ETHERNET0_MAC = "ethernet0_mac"; +const ID_ETHERNET1_MAC = "ethernet1_mac"; +const ID_ETHERNET0_READ_DATA = "ethernet0_received_data"; +const ID_ETHERNET1_READ_DATA = "ethernet1_received_data"; +const ID_ETHERNET0_SENT_DATA = "ethernet0_sent_data"; +const ID_ETHERNET1_SENT_DATA = "ethernet1_sent_data"; +const ID_ETHERNET0_STATE = "ethernet0_state"; +const ID_ETHERNET1_STATE = "ethernet1_state"; const ID_FILES = "files"; const ID_FLASH_MEMORY = "flash_memory"; const ID_FLASH_SIZE = "flash_size"; diff --git a/connectcore-demo-example/static/js/dashboard.js b/connectcore-demo-example/static/js/dashboard.js index 9cf6987..1bc2c15 100644 --- a/connectcore-demo-example/static/js/dashboard.js +++ b/connectcore-demo-example/static/js/dashboard.js @@ -31,10 +31,16 @@ const ID_DEVICE_INFO_TOGGLE_BUTTON = "device_info_toggle_button"; const ID_DEVICE_INFO_PANEL_HEADER = "device_info_panel_header"; const ID_DEVICE_INFO_PANEL_CONTAINER = "device_info_panel_container"; const ID_DEVICE_TOOLBAR = "device_toolbar"; -const ID_ETHERNET_PANEL = "ethernet_panel"; -const ID_ETHERNET_PANEL_AREA = "ethernet_panel_area"; -const ID_ETHERNET_PANEL_ARROW = "ethernet_panel_arrow"; -const ID_ETHERNET_PANEL_ICON = "ethernet_panel_icon"; +const ID_ETHERNET0_PANEL = "ethernet0_panel"; +const ID_ETHERNET0_PANEL_AREA = "ethernet0_panel_area"; +const ID_ETHERNET0_PANEL_ARROW = "ethernet0_panel_arrow"; +const ID_ETHERNET0_PANEL_ICON = "ethernet0_panel_icon"; +const ID_ETHERNET0_TITLE = "ethernet0_title"; +const ID_ETHERNET0_TOOLTIP = "ethernet0_tooltip"; +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_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"; @@ -61,7 +67,8 @@ const ID_WIFI_BT_PANEL_ARROW = "wifi_bt_panel_arrow"; const ID_WIFI_BT_PANEL_ICON = "wifi_bt_panel_icon"; const IFACE_BT = "hci0/"; -const IFACE_ETHERNET = "eth0/"; +const IFACE_ETHERNET0 = "eth0/"; +const IFACE_ETHERNET1 = "eth1/"; const IFACE_WIFI = "wlan0/"; const USER_LED = "user_led"; @@ -69,9 +76,12 @@ const USER_LED = "user_led"; const STREAM_CPU_FREQUENCY = PREFIX_STREAM + "frequency"; const STREAM_CPU_TEMPERATURE = PREFIX_STREAM + "cpu_temperature"; const STREAM_CPU_UPTIME = PREFIX_STREAM + "uptime"; -const STREAM_ETHERNET_READ_BYTES = PREFIX_STREAM + IFACE_ETHERNET + "rx_bytes"; -const STREAM_ETHERNET_SENT_BYTES = PREFIX_STREAM + IFACE_ETHERNET + "tx_bytes"; -const STREAM_ETHERNET_STATE = PREFIX_STREAM + IFACE_ETHERNET + "state"; +const STREAM_ETHERNET0_READ_BYTES = PREFIX_STREAM + IFACE_ETHERNET0 + "rx_bytes"; +const STREAM_ETHERNET0_SENT_BYTES = PREFIX_STREAM + IFACE_ETHERNET0 + "tx_bytes"; +const STREAM_ETHERNET0_STATE = PREFIX_STREAM + IFACE_ETHERNET0 + "state"; +const STREAM_ETHERNET1_READ_BYTES = PREFIX_STREAM + IFACE_ETHERNET1 + "rx_bytes"; +const STREAM_ETHERNET1_SENT_BYTES = PREFIX_STREAM + IFACE_ETHERNET1 + "tx_bytes"; +const STREAM_ETHERNET1_STATE = PREFIX_STREAM + IFACE_ETHERNET1 + "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"; @@ -260,7 +270,7 @@ function refreshDevice() { initializingDevice = false; return; } - device.refreshIPs(data[ID_ETHERNET_IP], data[ID_WIFI_IP]); + device.refreshIPs(data[ID_ETHERNET0_IP], data[ID_ETHERNET1_IP], data[ID_WIFI_IP]); updateInfoValues(); } ).fail(function(response) { @@ -322,7 +332,8 @@ function processDeviceStatusResponse(response) { } // Check if IP values are initialized. - if ((response[STREAM_ETHERNET_STATE] == 1 && device.getEthernetIP() == "0.0.0.0") + 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_WIFI_STATE] == 1 && device.getWifiIP() == "0.0.0.0")) { deviceInitialized = false; } @@ -413,13 +424,26 @@ 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 component. - var ethernetPanel = document.getElementById(ID_ETHERNET_PANEL); - var ethernetPanelArrow = document.getElementById(ID_ETHERNET_PANEL_ARROW); - var ethernetPanelArea = document.getElementById(ID_ETHERNET_PANEL_AREA); - var ethernetPanelIcon = document.getElementById(ID_ETHERNET_PANEL_ICON); - var ethernetInfo = {"panel": ethernetPanel, "arrow": ethernetPanelArrow, "area": ethernetPanelArea, "icon": ethernetPanelIcon, "data": device.getEthernetComponentData()}; - components[ID_ETHERNET] = ethernetInfo; + // 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); + 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); + 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 { + // 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"; + } // Video component. var videoPanel = document.getElementById(ID_VIDEO_PANEL); var videoPanelArrow = document.getElementById(ID_VIDEO_PANEL_ARROW); @@ -605,10 +629,13 @@ function updateInfoValues() { updateFieldValue(ID_MCA_FW_VERSION, device.getMCAFWVersion()); // Set MCA HW version. updateFieldValue(ID_MCA_HW_VERSION, device.getMCAHWVersion()); - // Set Ethernet MAC address. - updateFieldValue(ID_ETHERNET_MAC, device.getEthernetMAC()); - // Set Ethernet IP address. - updateFieldValue(ID_ETHERNET_IP, device.getEthernetIP()); + // Iterate Ethernet interfaces. + for (var index = 0; index < device.NUM_ETHERNET_INTERFACES; index++) { + // Set Ethernet MAC address. + updateFieldValue(eval("ID_ETHERNET" + index + "_MAC"), device.getEthernetMAC(index)); + // Set Ethernet IP address. + updateFieldValue(eval("ID_ETHERNET" + index + "_IP"), device.getEthernetIP(index)); + } // Set Wi-Fi MAC address. updateFieldValue(ID_WIFI_MAC, device.getWifiMAC()); // Set Wi-Fi IP address. @@ -658,14 +685,23 @@ function updateDataPointValue(streamID, value) { case STREAM_MEMORY_USED: updateValueWithEffect(ID_MEMORY_USED, kiloBytesToMegaBytes(value)); break; - case STREAM_ETHERNET_STATE: - updateValueWithEffect(ID_ETHERNET_STATE, onOffStatus(value)); + case STREAM_ETHERNET0_STATE: + updateValueWithEffect(ID_ETHERNET0_STATE, onOffStatus(value)); break; - case STREAM_ETHERNET_READ_BYTES: - updateValueWithEffect(ID_ETHERNET_READ_DATA, sizeToHumanRead(value)); + case STREAM_ETHERNET0_READ_BYTES: + updateValueWithEffect(ID_ETHERNET0_READ_DATA, sizeToHumanRead(value)); break; - case STREAM_ETHERNET_SENT_BYTES: - updateValueWithEffect(ID_ETHERNET_SENT_DATA, sizeToHumanRead(value)); + case STREAM_ETHERNET0_SENT_BYTES: + updateValueWithEffect(ID_ETHERNET0_SENT_DATA, sizeToHumanRead(value)); + break; + case STREAM_ETHERNET1_STATE: + updateValueWithEffect(ID_ETHERNET1_STATE, onOffStatus(value)); + break; + case STREAM_ETHERNET1_READ_BYTES: + updateValueWithEffect(ID_ETHERNET1_READ_DATA, sizeToHumanRead(value)); + break; + case STREAM_ETHERNET1_SENT_BYTES: + updateValueWithEffect(ID_ETHERNET1_SENT_DATA, sizeToHumanRead(value)); break; case STREAM_WIFI_STATE: updateValueWithEffect(ID_WIFI_STATE, onOffStatus(value)); diff --git a/connectcore-demo-example/static/js/devices.js b/connectcore-demo-example/static/js/devices.js index 534b832..c52cc40 100644 --- a/connectcore-demo-example/static/js/devices.js +++ b/connectcore-demo-example/static/js/devices.js @@ -81,19 +81,33 @@ class ConnectCoreDevice { WIFI_BT_COMPONENT_AREA_WIDTH_PERCENT = 0; WIFI_BT_COMPONENT_AREA_HEIGHT_PERCENT = 0; - // Ethernet panel. - ETHERNET_COMPONENT_VISIBLE = false; - ETHERNET_COMPONENT_HAS_PANEL = false; - ETHERNET_COMPONENT_HAS_ARROW = false; - ETHERNET_COMPONENT_PANEL_ALWAYS_VISIBLE = false; - ETHERNET_COMPONENT_PANEL_ORIENTATION = VALUE_TOP; - ETHERNET_COMPONENT_PANEL_HORIZONTAL_PERCENT = 0; - ETHERNET_COMPONENT_PANEL_VERTICAL_PERCENT = 0; - ETHERNET_COMPONENT_ARROW_PERCENT = 0; - ETHERNET_COMPONENT_AREA_TOP_PERCENT = 0; - ETHERNET_COMPONENT_AREA_LEFT_PERCENT = 0; - ETHERNET_COMPONENT_AREA_WIDTH_PERCENT = 0; - ETHERNET_COMPONENT_AREA_HEIGHT_PERCENT = 0; + // Ethernet0 panel. + ETHERNET0_COMPONENT_VISIBLE = false; + ETHERNET0_COMPONENT_HAS_PANEL = false; + ETHERNET0_COMPONENT_HAS_ARROW = false; + ETHERNET0_COMPONENT_PANEL_ALWAYS_VISIBLE = false; + ETHERNET0_COMPONENT_PANEL_ORIENTATION = VALUE_TOP; + ETHERNET0_COMPONENT_PANEL_HORIZONTAL_PERCENT = 0; + ETHERNET0_COMPONENT_PANEL_VERTICAL_PERCENT = 0; + ETHERNET0_COMPONENT_ARROW_PERCENT = 0; + ETHERNET0_COMPONENT_AREA_TOP_PERCENT = 0; + ETHERNET0_COMPONENT_AREA_LEFT_PERCENT = 0; + ETHERNET0_COMPONENT_AREA_WIDTH_PERCENT = 0; + ETHERNET0_COMPONENT_AREA_HEIGHT_PERCENT = 0; + + // Ethernet1 panel. + ETHERNET1_COMPONENT_VISIBLE = false; + ETHERNET1_COMPONENT_HAS_PANEL = false; + ETHERNET1_COMPONENT_HAS_ARROW = false; + ETHERNET1_COMPONENT_PANEL_ALWAYS_VISIBLE = false; + ETHERNET1_COMPONENT_PANEL_ORIENTATION = VALUE_TOP; + ETHERNET1_COMPONENT_PANEL_HORIZONTAL_PERCENT = 0; + ETHERNET1_COMPONENT_PANEL_VERTICAL_PERCENT = 0; + ETHERNET1_COMPONENT_ARROW_PERCENT = 0; + ETHERNET1_COMPONENT_AREA_TOP_PERCENT = 0; + ETHERNET1_COMPONENT_AREA_LEFT_PERCENT = 0; + ETHERNET1_COMPONENT_AREA_WIDTH_PERCENT = 0; + ETHERNET1_COMPONENT_AREA_HEIGHT_PERCENT = 0; // Console. CONSOLE_COMPONENT_VISIBLE = false; @@ -167,6 +181,9 @@ class ConnectCoreDevice { // Capabilities SUPPORTS_VIDEO_BRIGHTNESS; + SUPPORTS_DUAL_ETHERNET; + + NUM_ETHERNET_INTERFACES = 2; // Device information. #deviceType; @@ -180,8 +197,8 @@ class ConnectCoreDevice { #boardID; #mcaHWVersion; #mcaFWVersion; - #ethernetMAC; - #ethernetIP; + #ethernetMAC = []; + #ethernetIP = []; #wifiMAC; #wifiIP; #bluetoothMAC; @@ -209,8 +226,6 @@ class ConnectCoreDevice { this.#boardID = deviceData[ID_BOARD_ID]; this.#mcaHWVersion = deviceData[ID_MCA_HW_VERSION]; this.#mcaFWVersion = deviceData[ID_MCA_FW_VERSION]; - this.#ethernetMAC = deviceData[ID_ETHERNET_MAC]; - this.#ethernetIP = deviceData[ID_ETHERNET_IP]; this.#wifiMAC = deviceData[ID_WIFI_MAC]; this.#wifiIP = deviceData[ID_WIFI_IP]; this.#bluetoothMAC = deviceData[ID_BLUETOOTH_MAC]; @@ -219,10 +234,15 @@ 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")]; + } } - refreshIPs(eth_ip, wifi_ip) { - this.#ethernetIP = eth_ip; + refreshIPs(eth0_ip, eth1_ip, wifi_ip) { + this.#ethernetIP[0] = eth0_ip; + this.#ethernetIP[1] = eth1_ip; this.#wifiIP = wifi_ip; } @@ -291,14 +311,18 @@ class ConnectCoreDevice { return this.#mcaFWVersion; } - // Returns the device Ethernet MAC address. - getEthernetMAC() { - return this.#ethernetMAC; + // Returns the device Ethernet MAC address for the given interface index. + getEthernetMAC(index=0) { + if (index >= this.NUM_ETHERNET_INTERFACES) + return ""; + return this.#ethernetMAC[index]; } - // Returns the device Ethernet IP address. - getEthernetIP() { - return this.#ethernetIP; + // Returns the device Ethernet IP address for the given interface index. + getEthernetIP(index=0) { + if (index >= this.NUM_ETHERNET_INTERFACES) + return ""; + return this.#ethernetIP[index]; } // Returns the device WiFi MAC address. @@ -389,20 +413,22 @@ class ConnectCoreDevice { this.WIFI_BT_COMPONENT_AREA_HEIGHT_PERCENT)); } - // Returns the Ethernet panel data. - getEthernetComponentData() { - return JSON.parse(TEMPLATE_COMPONENT_DATA.format(this.ETHERNET_COMPONENT_VISIBLE, - this.ETHERNET_COMPONENT_HAS_PANEL, - this.ETHERNET_COMPONENT_HAS_ARROW, - this.ETHERNET_COMPONENT_PANEL_ALWAYS_VISIBLE, - this.ETHERNET_COMPONENT_PANEL_ORIENTATION, - this.ETHERNET_COMPONENT_PANEL_HORIZONTAL_PERCENT, - this.ETHERNET_COMPONENT_PANEL_VERTICAL_PERCENT, - this.ETHERNET_COMPONENT_ARROW_PERCENT, - this.ETHERNET_COMPONENT_AREA_TOP_PERCENT, - this.ETHERNET_COMPONENT_AREA_LEFT_PERCENT, - this.ETHERNET_COMPONENT_AREA_WIDTH_PERCENT, - this.ETHERNET_COMPONENT_AREA_HEIGHT_PERCENT)); + // Returns the Ethernet panel data for the given interface index. + getEthernetComponentData(index=0) { + if (index >= this.NUM_ETHERNET_INTERFACES) + return ""; + return JSON.parse(TEMPLATE_COMPONENT_DATA.format(eval("this.ETHERNET" + index + "_COMPONENT_VISIBLE"), + eval("this.ETHERNET" + index + "_COMPONENT_HAS_PANEL"), + eval("this.ETHERNET" + index + "_COMPONENT_HAS_ARROW"), + eval("this.ETHERNET" + index + "_COMPONENT_PANEL_ALWAYS_VISIBLE"), + eval("this.ETHERNET" + index + "_COMPONENT_PANEL_ORIENTATION"), + eval("this.ETHERNET" + index + "_COMPONENT_PANEL_HORIZONTAL_PERCENT"), + eval("this.ETHERNET" + index + "_COMPONENT_PANEL_VERTICAL_PERCENT"), + eval("this.ETHERNET" + index + "_COMPONENT_ARROW_PERCENT"), + eval("this.ETHERNET" + index + "_COMPONENT_AREA_TOP_PERCENT"), + eval("this.ETHERNET" + index + "_COMPONENT_AREA_LEFT_PERCENT"), + eval("this.ETHERNET" + index + "_COMPONENT_AREA_WIDTH_PERCENT"), + eval("this.ETHERNET" + index + "_COMPONENT_AREA_HEIGHT_PERCENT"))); } // Returns the Console panel data. @@ -489,4 +515,9 @@ class ConnectCoreDevice { supportsVideoBrightness() { return this.SUPPORTS_VIDEO_BRIGHTNESS; } + + // Returns whether the device supports dual ethernet or not. + supportsDualEthernet() { + return this.SUPPORTS_DUAL_ETHERNET; + } }