diff --git a/CHANGELOG.md b/CHANGELOG.md index 449f8ea..a9d2e91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,14 +1,44 @@ # Changelog All notable changes to this project will be documented in this file. -## Release 0.1.0 -- Initial commit +## Release 2.0.0 -### New features -- ... +### Improvements +- Renamed function 'setPingIpAddress' to 'setPingIPAddress' +- Using recursive helper functions to convert Container <-> Lua table + +## Release 1.4.0 ### Improvements -- ... +- Update to EmmyLua annotations +- Usage of lua diagnostics +- Documentation updates + +## Release 1.3.0 + +### Improvements +- Prepared for CSK_UserManagement user levels: Operator, Maintenance, Service, Admin to optionally hide content related to UserManagement module (using bool parameter) +- Module name added to log messages +- Renamed page folder accordingly to module name +- Hiding SOPAS Login +- Documentation updates (manifest, code internal, UI elements) +- camelCase renamed functions +- Minor code edits +- Using prefix for events ### Bugfix -- ... \ No newline at end of file +- UI events notified after pageLoad after 300ms instead of 100ms to not miss + +## Release 1.2.0 +- Initial commit + +### Improvements +- Hide IPs in the list if DHCP is enabled + +## Release 1.1.0 + +### New features +- Added IP utils + +## Release 1.0.0 +- Initial commit diff --git a/CSK_Module_DeviceNetworkConfig/pages/assets/legacy/resources.json b/CSK_Module_DeviceNetworkConfig/pages/assets/legacy/resources.json new file mode 100644 index 0000000..0637a08 --- /dev/null +++ b/CSK_Module_DeviceNetworkConfig/pages/assets/legacy/resources.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/CSK_Module_DeviceNetworkConfig/pages/assets/legacy/settings.json b/CSK_Module_DeviceNetworkConfig/pages/assets/legacy/settings.json new file mode 100644 index 0000000..939ec2a --- /dev/null +++ b/CSK_Module_DeviceNetworkConfig/pages/assets/legacy/settings.json @@ -0,0 +1,3 @@ +{ +"showLoginButton": false +} \ No newline at end of file diff --git a/CSK_Module_DeviceNetworkConfig/pages/global.css b/CSK_Module_DeviceNetworkConfig/pages/global.css new file mode 100644 index 0000000..e43ba5b --- /dev/null +++ b/CSK_Module_DeviceNetworkConfig/pages/global.css @@ -0,0 +1 @@ +/* Add project wide CSS settings here */ \ No newline at end of file diff --git a/CSK_Module_DeviceNetworkConfig/pages/i18n/de.json b/CSK_Module_DeviceNetworkConfig/pages/i18n/de.json new file mode 100644 index 0000000..0db3279 --- /dev/null +++ b/CSK_Module_DeviceNetworkConfig/pages/i18n/de.json @@ -0,0 +1,3 @@ +{ + +} diff --git a/CSK_Module_DeviceNetworkConfig/pages/i18n/en.json b/CSK_Module_DeviceNetworkConfig/pages/i18n/en.json new file mode 100644 index 0000000..0db3279 --- /dev/null +++ b/CSK_Module_DeviceNetworkConfig/pages/i18n/en.json @@ -0,0 +1,3 @@ +{ + +} diff --git a/CSK_Module_DeviceNetworkConfig/pages/package.json b/CSK_Module_DeviceNetworkConfig/pages/package.json new file mode 100644 index 0000000..74b18af --- /dev/null +++ b/CSK_Module_DeviceNetworkConfig/pages/package.json @@ -0,0 +1,11 @@ +{ + "name": "CSK_Module_DeviceNetworkConfig", + "version": "1.0.0", + "description": "Generated", + "components": [ + "@sick-davinci/basic-elements" + ], + "dependencies": { + "@sick-davinci/basic-elements": "^5.0.5" + } +} \ No newline at end of file diff --git a/CSK_Module_DeviceNetworkConfig/pages/pages/CSK_Module_DeviceNetworkConfig/CSK_Module_DeviceNetworkConfig.css b/CSK_Module_DeviceNetworkConfig/pages/pages/CSK_Module_DeviceNetworkConfig/CSK_Module_DeviceNetworkConfig.css new file mode 100644 index 0000000..eadc5e2 --- /dev/null +++ b/CSK_Module_DeviceNetworkConfig/pages/pages/CSK_Module_DeviceNetworkConfig/CSK_Module_DeviceNetworkConfig.css @@ -0,0 +1,10 @@ +.myCustomFrame_CSK_Module_DeviceNetworkConfig { + border-style: solid; + border-width: 1px; + border-color: grey; + margin: 6px; +} + +.myCustomMinWidth_CSK_Module_DeviceNetworkConfig { + min-width: 60px; +} diff --git a/CSK_Module_DeviceNetworkConfig/pages/pages/CSK_Module_DeviceNetworkConfig/CSK_Module_DeviceNetworkConfig.html b/CSK_Module_DeviceNetworkConfig/pages/pages/CSK_Module_DeviceNetworkConfig/CSK_Module_DeviceNetworkConfig.html new file mode 100644 index 0000000..e8948ec --- /dev/null +++ b/CSK_Module_DeviceNetworkConfig/pages/pages/CSK_Module_DeviceNetworkConfig/CSK_Module_DeviceNetworkConfig.html @@ -0,0 +1,226 @@ + + + + + + + + + + Applied network configuration will be saved persistently. + + + + + + + ... Currently processing ... + + + + + + + New config accepted + + + + + New config NOT accepted + + + + + + Refresh + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Apply new network configuration + + + + + +

Tools

+ + + + + + + PING + + + + + + + + + + + + + +
+
+
+ + + + + Please login with at least user level 'Maintenance' or higher to see this page. + + + + + + +
+ + + + +
+ +
diff --git a/CSK_Module_DeviceNetworkConfig/pages/pages/navigation.json b/CSK_Module_DeviceNetworkConfig/pages/pages/navigation.json new file mode 100644 index 0000000..3f3a226 --- /dev/null +++ b/CSK_Module_DeviceNetworkConfig/pages/pages/navigation.json @@ -0,0 +1,4 @@ +{ + "version": "1.0", + "pages": [] +} \ No newline at end of file diff --git a/CSK_Module_DeviceNetworkConfig/pages/src/converter.ts b/CSK_Module_DeviceNetworkConfig/pages/src/converter.ts new file mode 100644 index 0000000..e69de29 diff --git a/CSK_Module_DeviceNetworkConfig/pages/src/index.ts b/CSK_Module_DeviceNetworkConfig/pages/src/index.ts new file mode 100644 index 0000000..e69de29 diff --git a/CSK_Module_DeviceNetworkConfig/project.mf.xml b/CSK_Module_DeviceNetworkConfig/project.mf.xml new file mode 100644 index 0000000..68ac025 --- /dev/null +++ b/CSK_Module_DeviceNetworkConfig/project.mf.xml @@ -0,0 +1,158 @@ + + + + + This is an automatically generated CROWN (description not necessary). + + + + released + This module provides the possibility to setup the ethernet interfaces of the device. + +See following descriptions of events/functions regarding further information. + + + + Notify current subnet mask. + + + + Notify current IP. + + + + Notify interface table as JSON (e.g. for table in UI). + + + + Notify current DHCP status. + + + + Notify current 'Default Gateway' + + + + Notified to disable / enable 'IP' text field in UI. + + + + Notified to disable / enable 'Subnet mask' text field in UI. + + + + Notified to disable / enable 'Gateway' text field in UI. + + + + Highlights the 'IP' in UI if format of IP is not correct. + + + + Highlights the 'Subnet' field in UI if format is not correct. + + + + Highlights the 'Gateway field' in UI if format of gateway is not correct. + + + + Notified to disable / enable 'Apply new config' button in UI. + + + + Notify current configuration process status. + + + + Notified to disable / enable 'DHCP' checkbox in UI. + + + + Notify currently selected interface. + + + + Status of Operator userlevel. Used internally in combination with the CSK_UserManagement module if available. + + + + Status of Maintenance userlevel. Used internally in combination with the CSK_UserManagement module if available. + + + + Status of Service userlevel. Used internally in combination with the CSK_UserManagement module if available. + + + + Status of Admin userlevel. Used internally in combination with the CSK_UserManagement module if available. + + + + Notify result of executed ping command. + + + + Notify details of executed ping command. + + + + Function to register "OnResume" of the module UI (only as helper function). + + + + Preset subnet mask to be configured via 'applyConfig'. + + + + Preset IP to be configured via 'applyConfig'. + + + + Preset DHCP status to be configured via 'applyConfig'. + + + + Preset default gateway to be configured via 'applyConfig'. + + + + Select ethernet interface via table in UI. + + + + Get current configuration of Ethernet ports. + + + Apply preset network configuration to device when button in UI is pressed. + + + Applies new configuration of Ethernet interface. + + + + + + + + Get current network description of device in JSON format. + + + + Try to ping preset IP (see 'setPingIpAddress'). + + + Preset IP to ping (see 'ping' function). + + + + + SICK AG + 2.0.0 + low + false + false + false + true + + + diff --git a/CSK_Module_DeviceNetworkConfig/scripts/CSK_Module_DeviceNetworkConfig.lua b/CSK_Module_DeviceNetworkConfig/scripts/CSK_Module_DeviceNetworkConfig.lua new file mode 100644 index 0000000..4fff678 --- /dev/null +++ b/CSK_Module_DeviceNetworkConfig/scripts/CSK_Module_DeviceNetworkConfig.lua @@ -0,0 +1,59 @@ +--MIT License +-- +--Copyright (c) 2023 SICK AG +-- +--Permission is hereby granted, free of charge, to any person obtaining a copy +--of this software and associated documentation files (the "Software"), to deal +--in the Software without restriction, including without limitation the rights +--to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +--copies of the Software, and to permit persons to whom the Software is +--furnished to do so, subject to the following conditions: +-- +--The above copyright notice and this permission notice shall be included in all +--copies or substantial portions of the Software. +-- +--THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +--IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +--FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +--AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +--LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +--OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +--SOFTWARE. + +---@diagnostic disable: undefined-global, redundant-parameter, missing-parameter + +--************************************************************************** +--**********************Start Global Scope ********************************* +--************************************************************************** +----------------------------------------------------------- +-- Logger +_G.logger = Log.SharedLogger.create('ModuleLogger') +_G.logHandle = Log.Handler.create() +_G.logHandle:attachToSharedLogger('ModuleLogger') +_G.logHandle:setConsoleSinkEnabled(false) --> Set to TRUE if CSK_Logger module is not used +_G.logHandle:setLevel("ALL") +_G.logHandle:applyConfig() +----------------------------------------------------------- + +-- Loading script regarding DeviceNetworkConfig_Model +-- Check this script regarding DeviceNetworkConfig_Model parameters and functions +_G.deviceNetworkConfig_Model = require('Configuration/DeviceNetworkConfig/DeviceNetworkConfig_Model') + +--************************************************************************** +--**********************End Global Scope *********************************** +--************************************************************************** +--**********************Start Function Scope ******************************* +--************************************************************************** +_G.deviceNetworkConfig_Model.refreshInterfaces() + +--- Function to react on startup event of the app +local function main() + + CSK_DeviceNetworkConfig.pageCalled() + +end +Script.register("Engine.OnStarted", main) + +--************************************************************************** +--**********************End Function Scope ********************************* +--************************************************************************** diff --git a/CSK_Module_DeviceNetworkConfig/scripts/Configuration/DeviceNetworkConfig/DeviceNetworkConfig_Controller.lua b/CSK_Module_DeviceNetworkConfig/scripts/Configuration/DeviceNetworkConfig/DeviceNetworkConfig_Controller.lua new file mode 100644 index 0000000..f2ddbb1 --- /dev/null +++ b/CSK_Module_DeviceNetworkConfig/scripts/Configuration/DeviceNetworkConfig/DeviceNetworkConfig_Controller.lua @@ -0,0 +1,316 @@ +---@diagnostic disable: undefined-global, redundant-parameter, missing-parameter + +--*************************************************************** +-- Inside of this script, you will find the necessary functions, +-- variables and events to communicate with the DeviceNetworkConfig_Model +--*************************************************************** + +--************************************************************************** +--************************ Start Global Scope ****************************** +--************************************************************************** +local nameOfModule = 'CSK_DeviceNetworkConfig' + +-- Timer to update UI via events after page was loaded +local tmrDeviceNetworkConfig = Timer.create() +tmrDeviceNetworkConfig:setExpirationTime(300) +tmrDeviceNetworkConfig:setPeriodic(false) + +-- Currently selected / predefined values for network config +local currentInterfaceName = '-' +local currentIP = '-' +local currentSubnet = '-' +local currentGateway = '-' +local currentDHCP = false + +local interfacesTable = {} -- table to hold available interfaces +local jsonInterfaceListContent -- available interfaces as JSON + +-- Reference to global handle +local deviceNetworkConfig_Model + +-- ************************ UI Events Start ******************************** + +Script.serveEvent("CSK_DeviceNetworkConfig.OnNewEthernetConfigStatus", "DeviceNetworkConfig_OnNewEthernetConfigStatus") +Script.serveEvent("CSK_DeviceNetworkConfig.OnNewInterfaceTable", "DeviceNetworkConfig_OnNewInterfaceTable") +Script.serveEvent("CSK_DeviceNetworkConfig.OnNewIP", "DeviceNetworkConfig_OnNewIP") +Script.serveEvent("CSK_DeviceNetworkConfig.OnNewSubnetMask", "DeviceNetworkConfig_OnNewSubnetMask") +Script.serveEvent("CSK_DeviceNetworkConfig.OnNewDefaultGateway", "DeviceNetworkConfig_OnNewDefaultGateway") +Script.serveEvent("CSK_DeviceNetworkConfig.OnNewDHCPStatus", "DeviceNetworkConfig_OnNewDHCPStatus") +Script.serveEvent("CSK_DeviceNetworkConfig.OnIPDisabled", "DeviceNetworkConfig_OnIPDisabled") +Script.serveEvent("CSK_DeviceNetworkConfig.OnSubnetDisabled", "DeviceNetworkConfig_OnSubnetDisabled") +Script.serveEvent("CSK_DeviceNetworkConfig.OnGatewayDisabled", "DeviceNetworkConfig_OnGatewayDisabled") +Script.serveEvent("CSK_DeviceNetworkConfig.OnDHCPDisabled", "DeviceNetworkConfig_OnDHCPDisabled") +Script.serveEvent("CSK_DeviceNetworkConfig.OnIPError", "DeviceNetworkConfig_OnIPError") +Script.serveEvent("CSK_DeviceNetworkConfig.OnSubnetError", "DeviceNetworkConfig_OnSubnetError") +Script.serveEvent("CSK_DeviceNetworkConfig.OnGatewayError", "DeviceNetworkConfig_OnGatewayError") +Script.serveEvent("CSK_DeviceNetworkConfig.OnApplyButtonDisabled", "DeviceNetworkConfig_OnApplyButtonDisabled") +Script.serveEvent("CSK_DeviceNetworkConfig.OnNewInterfaceChoice", "DeviceNetworkConfig_OnNewInterfaceChoice") + +Script.serveEvent("CSK_DeviceNetworkConfig.OnUserLevelOperatorActive", "DeviceNetworkConfig_OnUserLevelOperatorActive") +Script.serveEvent("CSK_DeviceNetworkConfig.OnUserLevelMaintenanceActive", "DeviceNetworkConfig_OnUserLevelMaintenanceActive") +Script.serveEvent("CSK_DeviceNetworkConfig.OnUserLevelServiceActive", "DeviceNetworkConfig_OnUserLevelServiceActive") +Script.serveEvent("CSK_DeviceNetworkConfig.OnUserLevelAdminActive", "DeviceNetworkConfig_OnUserLevelAdminActive") + +Script.serveEvent("CSK_DeviceNetworkConfig.OnNewPingResult", "DeviceNetworkConfig_OnNewPingResult") +Script.serveEvent("CSK_DeviceNetworkConfig.OnNewPingDetails", "DeviceNetworkConfig_OnNewPingDetails") + +-- ************************ UI Events End ********************************** + +--************************************************************************** +--********************** End Global Scope ********************************** +--************************************************************************** +--**********************Start Function Scope ******************************* +--************************************************************************** + +-- Functions to forward logged in user roles via CSK_UserManagement module (if available) +-- *********************************************** +--- Function to react on status change of Operator user level +---@param status boolean Status if Operator level is active +local function handleOnUserLevelOperatorActive(status) + Script.notifyEvent("DeviceNetworkConfig_OnUserLevelOperatorActive", status) +end + +--- Function to react on status change of Maintenance user level +---@param status boolean Status if Maintenance level is active +local function handleOnUserLevelMaintenanceActive(status) + Script.notifyEvent("DeviceNetworkConfig_OnUserLevelMaintenanceActive", status) +end + +--- Function to react on status change of Service user level +---@param status boolean Status if Service level is active +local function handleOnUserLevelServiceActive(status) + Script.notifyEvent("DeviceNetworkConfig_OnUserLevelServiceActive", status) +end + +--- Function to react on status change of Admin user level +---@param status boolean Status if Admin level is active +local function handleOnUserLevelAdminActive(status) + Script.notifyEvent("DeviceNetworkConfig_OnUserLevelAdminActive", status) +end + +--- Function to check what options should be adjustable in UI +local function checkWhatToDisable() + if currentDHCP == true or (deviceNetworkConfig_Model.helperFuncs.checkIP(currentIP) and deviceNetworkConfig_Model.helperFuncs.checkIP(currentSubnet) and (deviceNetworkConfig_Model.helperFuncs.checkIP(currentGateway) or currentGateway == '')) then + Script.notifyEvent("DeviceNetworkConfig_OnApplyButtonDisabled", false) + else + Script.notifyEvent("DeviceNetworkConfig_OnApplyButtonDisabled", true) + end + if currentInterfaceName == '-' or nil then + Script.notifyEvent("DeviceNetworkConfig_OnIPDisabled", true) + Script.notifyEvent("DeviceNetworkConfig_OnSubnetDisabled", true) + Script.notifyEvent("DeviceNetworkConfig_OnGatewayDisabled", true) + Script.notifyEvent("DeviceNetworkConfig_OnDHCPDisabled", true) + else + Script.notifyEvent("DeviceNetworkConfig_OnDHCPDisabled", false) + if currentDHCP == true then -- when DHCP is ON, the rest of the fields are empty and can't be edited + Script.notifyEvent("DeviceNetworkConfig_OnIPError", false) + Script.notifyEvent("DeviceNetworkConfig_OnSubnetError", false) + Script.notifyEvent("DeviceNetworkConfig_OnGatewayError", false) + Script.notifyEvent("DeviceNetworkConfig_OnNewIP", '-') + Script.notifyEvent("DeviceNetworkConfig_OnNewSubnetMask", '-') + Script.notifyEvent("DeviceNetworkConfig_OnNewDefaultGateway", '-') + Script.notifyEvent("DeviceNetworkConfig_OnIPDisabled", true) + Script.notifyEvent("DeviceNetworkConfig_OnSubnetDisabled", true) + Script.notifyEvent("DeviceNetworkConfig_OnGatewayDisabled", true) + else + Script.notifyEvent("DeviceNetworkConfig_OnIPDisabled", false) + Script.notifyEvent("DeviceNetworkConfig_OnSubnetDisabled", false) + Script.notifyEvent("DeviceNetworkConfig_OnGatewayDisabled", false) + end + end +end + +--- Function to get access to the deviceNetworkConfig_Model object +---@param handle handle Handle of deviceNetworkConfig_Model object +local function setDeviceNetworkConfig_Model_Handle(handle) + deviceNetworkConfig_Model = handle + if deviceNetworkConfig_Model.userManagementModuleAvailable then + -- Register on events of CSK_UserManagement module if available + Script.register('CSK_UserManagement.OnUserLevelOperatorActive', handleOnUserLevelOperatorActive) + Script.register('CSK_UserManagement.OnUserLevelMaintenanceActive', handleOnUserLevelMaintenanceActive) + Script.register('CSK_UserManagement.OnUserLevelServiceActive', handleOnUserLevelServiceActive) + Script.register('CSK_UserManagement.OnUserLevelAdminActive', handleOnUserLevelAdminActive) + end + Script.releaseObject(handle) +end + +-- ********************* UI Setting / Submit Functions Start ******************** + +local function refresh() + interfacesTable = deviceNetworkConfig_Model.refreshInterfaces() + jsonInterfaceListContent = deviceNetworkConfig_Model.helperFuncs.createJsonList(interfacesTable) + Script.notifyEvent("DeviceNetworkConfig_OnNewInterfaceTable", jsonInterfaceListContent) + checkWhatToDisable() +end +Script.serveFunction("CSK_DeviceNetworkConfig.refresh", refresh) + +--- Function to update user levels +local function updateUserLevel() + if deviceNetworkConfig_Model.userManagementModuleAvailable then + -- Trigger CSK_UserManagement module to provide events regarding user role + CSK_UserManagement.pageCalled() + else + -- If CSK_UserManagement is not active, show everything + Script.notifyEvent("DeviceNetworkConfig_OnUserLevelOperatorActive", true) + Script.notifyEvent("DeviceNetworkConfig_OnUserLevelMaintenanceActive", true) + Script.notifyEvent("DeviceNetworkConfig_OnUserLevelServiceActive", true) + Script.notifyEvent("DeviceNetworkConfig_OnUserLevelAdminActive", true) + end +end + +--- Function to send all relevant values to UI on resume +local function handleOnExpiredTmrDeviceNetworkConfig() + + updateUserLevel() + + refresh() + currentInterfaceName = '-' + currentIP = '-' + currentSubnet = '-' + currentGateway = '-' + currentDHCP = false + Script.notifyEvent("DeviceNetworkConfig_OnNewDHCPStatus", false) + Script.notifyEvent("DeviceNetworkConfig_OnNewIP", '-') + Script.notifyEvent("DeviceNetworkConfig_OnNewSubnetMask", '-') + Script.notifyEvent("DeviceNetworkConfig_OnNewDefaultGateway", '-') + Script.notifyEvent("DeviceNetworkConfig_OnNewInterfaceChoice",'-') + Script.notifyEvent("DeviceNetworkConfig_OnNewEthernetConfigStatus", 'empty') + checkWhatToDisable() +end +Timer.register(tmrDeviceNetworkConfig, "OnExpired", handleOnExpiredTmrDeviceNetworkConfig) + +-- ********************* UI Setting / Submit Functions Start ******************** + +local function pageCalled() + updateUserLevel() -- try to hide user specific content asap + tmrDeviceNetworkConfig:start() + return '' +end +Script.serveFunction("CSK_DeviceNetworkConfig.pageCalled", pageCalled) + +local function selectInterface(row_selected) + Script.notifyEvent("DeviceNetworkConfig_OnNewEthernetConfigStatus", 'empty') + Script.notifyEvent("DeviceNetworkConfig_OnIPError", false) + Script.notifyEvent("DeviceNetworkConfig_OnSubnetError", false) + Script.notifyEvent("DeviceNetworkConfig_OnGatewayError", false) + local _, pos1 = string.find(row_selected, '"Interface":"') + local pos2, _ = string.find(row_selected, '"', pos1+1) + local selectedInterfaceName = string.sub(row_selected, pos1+1, pos2-1) + if selectedInterfaceName ~= '-' and selectedInterfaceName ~= '' then + currentIP = interfacesTable[selectedInterfaceName].ipAddress + currentSubnet = interfacesTable[selectedInterfaceName].subnetMask + currentGateway = interfacesTable[selectedInterfaceName].defaultGateway + currentDHCP = interfacesTable[selectedInterfaceName].dhcp + currentInterfaceName = selectedInterfaceName + Script.notifyEvent("DeviceNetworkConfig_OnNewIP", currentIP) + Script.notifyEvent("DeviceNetworkConfig_OnNewSubnetMask", currentSubnet) + Script.notifyEvent("DeviceNetworkConfig_OnNewDefaultGateway", currentGateway) + Script.notifyEvent("DeviceNetworkConfig_OnNewDHCPStatus", currentDHCP) + Script.notifyEvent("DeviceNetworkConfig_OnNewInterfaceChoice",currentInterfaceName) + end + if currentDHCP == true then + Script.notifyEvent("DeviceNetworkConfig_OnIPDisabled", true) + Script.notifyEvent("DeviceNetworkConfig_OnSubnetDisabled", true) + Script.notifyEvent("DeviceNetworkConfig_OnGatewayDisabled", true) + end + Script.sleep(100) + Script.notifyEvent("DeviceNetworkConfig_OnNewInterfaceTable", jsonInterfaceListContent) + checkWhatToDisable() +end +Script.serveFunction("CSK_DeviceNetworkConfig.selectInterface", selectInterface) + +local function setInterfaceIP(newIP) + currentIP = newIP + if deviceNetworkConfig_Model.helperFuncs.checkIP(newIP) then + Script.notifyEvent("DeviceNetworkConfig_OnIPError", false) + else + Script.notifyEvent("DeviceNetworkConfig_OnIPError", true) + end + checkWhatToDisable() +end +Script.serveFunction("CSK_DeviceNetworkConfig.setInterfaceIP", setInterfaceIP) + +local function setSubnetMask(newSubnetMask) + currentSubnet = newSubnetMask + if deviceNetworkConfig_Model.helperFuncs.checkIP(newSubnetMask) then + Script.notifyEvent("DeviceNetworkConfig_OnSubnetError", false) + else + Script.notifyEvent("DeviceNetworkConfig_OnSubnetError", true) + end + checkWhatToDisable() +end +Script.serveFunction("CSK_DeviceNetworkConfig.setSubnetMask", setSubnetMask) + +local function setDefaultGateway(newDefaultGateway) + currentGateway = newDefaultGateway + if newDefaultGateway == '' or deviceNetworkConfig_Model.helperFuncs.checkIP(newDefaultGateway) then + Script.notifyEvent("DeviceNetworkConfig_OnGatewayError", false) + else + Script.notifyEvent("DeviceNetworkConfig_OnGatewayError", true) + end + checkWhatToDisable() +end +Script.serveFunction("CSK_DeviceNetworkConfig.setDefaultGateway", setDefaultGateway) + +local function setDHCPState(newDHCPState) + currentDHCP = newDHCPState + if newDHCPState == false then + if currentIP == '-' then currentIP = '192.168.0.1' end + if currentSubnet == '-' then currentSubnet = '255.255.255.0' end + if currentGateway == '-' then currentGateway = '0.0.0.0' end + Script.notifyEvent("DeviceNetworkConfig_OnNewIP", currentIP) + Script.notifyEvent("DeviceNetworkConfig_OnNewSubnetMask", currentSubnet) + Script.notifyEvent("DeviceNetworkConfig_OnNewDefaultGateway", currentGateway) + end + checkWhatToDisable() +end +Script.serveFunction("CSK_DeviceNetworkConfig.setDHCPState", setDHCPState) + +local function setPingIPAddress(ping_ip) + deviceNetworkConfig_Model.ping_ip_adress = ping_ip +end +Script.serveFunction("CSK_DeviceNetworkConfig.setPingIPAddress", setPingIPAddress) + +local function ping() + local succes, time = Ethernet.ping(deviceNetworkConfig_Model.ping_ip_adress) + Script.notifyEvent("DeviceNetworkConfig_OnNewPingResult", succes) + if (time) then + Script.notifyEvent("DeviceNetworkConfig_OnNewPingDetails", tostring(time).." ms") + else + Script.notifyEvent("DeviceNetworkConfig_OnNewPingDetails", "No Connection") + end +end +Script.serveFunction("CSK_DeviceNetworkConfig.ping", ping) + +local function applyConfig() + if deviceNetworkConfig_Model.helperFuncs.checkIP(currentIP) and deviceNetworkConfig_Model.helperFuncs.checkIP(currentSubnet) and deviceNetworkConfig_Model.helperFuncs.checkIP(currentGateway) or currentGateway == '' then + Script.notifyEvent("DeviceNetworkConfig_OnNewEthernetConfigStatus", 'processing') + if currentDHCP == true then + _G.logger:info(nameOfModule .. ": Applying device's Ethernet config: \n Interface " .. currentInterfaceName .. " \n DHCP: " .. tostring(currentDHCP)) + deviceNetworkConfig_Model.applyEthernetConfig(currentInterfaceName, currentDHCP, nil, nil, nil) + else + _G.logger:info(nameOfModule .. ": Applying device's Ethernet config: \n Interface " .. currentInterfaceName .. " \n DHCP: " .. tostring(currentDHCP) .. " \n IP: " .. currentIP.. " \n Subnet: " .. currentSubnet .. " \n Gateway: " .. currentGateway) + deviceNetworkConfig_Model.applyEthernetConfig(currentInterfaceName, currentDHCP, currentIP, currentSubnet, currentGateway) + end + refresh() + Script.notifyEvent("DeviceNetworkConfig_OnNewEthernetConfigStatus", 'success') + else + Script.notifyEvent("DeviceNetworkConfig_OnNewEthernetConfigStatus", 'error') + end + _G.logger:info(nameOfModule .. ": Applying device's Ethernet config finished") +end +Script.serveFunction("CSK_DeviceNetworkConfig.applyConfig", applyConfig) + +--- Function to react 'Ethernet.Interface.OnLinkActiveChanged' event +local function handleOnLinkActiveChanged(ifName, linkActive) + refresh() + _G.logger:info(nameOfModule .. ': New link status = ' .. tostring(linkActive) .. ' on interface ' .. ifName) +end +Script.register("Ethernet.Interface.OnLinkActiveChanged", handleOnLinkActiveChanged) + +return setDeviceNetworkConfig_Model_Handle + +--************************************************************************** +--**********************End Function Scope ********************************* +--************************************************************************** + diff --git a/CSK_Module_DeviceNetworkConfig/scripts/Configuration/DeviceNetworkConfig/DeviceNetworkConfig_Model.lua b/CSK_Module_DeviceNetworkConfig/scripts/Configuration/DeviceNetworkConfig/DeviceNetworkConfig_Model.lua new file mode 100644 index 0000000..c176873 --- /dev/null +++ b/CSK_Module_DeviceNetworkConfig/scripts/Configuration/DeviceNetworkConfig/DeviceNetworkConfig_Model.lua @@ -0,0 +1,79 @@ +---@diagnostic disable: undefined-global, redundant-parameter, missing-parameter +--***************************************************************** +-- Inside of this script, you will find the module definition +-- including its parameters and functions +--***************************************************************** + +--************************************************************************** +--**********************Start Global Scope ********************************* +--************************************************************************** +local nameOfModule = 'CSK_DeviceNetworkConfig' + +local deviceNetworkConfig_Model = {} + +-- Check if CSK_UserManagement features can be used if wanted +deviceNetworkConfig_Model.userManagementModuleAvailable = CSK_UserManagement ~= nil or false + +-- Load script to communicate with the DeviceNetworkConfig_Model interface and give access +-- to the DeviceNetworkConfig_Model object. +-- Check / edit this script to see/edit functions which communicate with the UI +local setDeviceNetworkConfig_ModelHandle = require('Configuration/DeviceNetworkConfig/DeviceNetworkConfig_Controller') +setDeviceNetworkConfig_ModelHandle(deviceNetworkConfig_Model) + +--Loading helper functions if needed +deviceNetworkConfig_Model.helperFuncs = require('Configuration/DeviceNetworkConfig/helper/funcs') + +deviceNetworkConfig_Model.interfacesTable = {} -- table to hold setup of available ethernet interfaces +deviceNetworkConfig_Model.ping_ip_adress = "" -- IP address to check for ping + +--************************************************************************** +--********************** End Global Scope ********************************** +--************************************************************************** +--**********************Start Function Scope ******************************* +--************************************************************************** + +---Function to get current setting of ethernet interfaces +local function refreshInterfaces() + deviceNetworkConfig_Model.interfacesTable = {} + for _, enum in pairs(Ethernet.Interface.getInterfaces()) do + local dhcpEnabled, ipAddress, subnetMask, gateway = Ethernet.Interface.getAddressConfig(enum) + local isLinkActive = Ethernet.Interface.isLinkActive(enum) + local macAddress = Ethernet.Interface.getMACAddress(enum) + local interfaceConfig = {} + interfaceConfig.interfaceName = enum + interfaceConfig.dhcp = dhcpEnabled + interfaceConfig.macAddress = macAddress + interfaceConfig.isLinkActive = isLinkActive + interfaceConfig.ipAddress = ipAddress + interfaceConfig.subnetMask = subnetMask + interfaceConfig.defaultGateway = gateway + deviceNetworkConfig_Model.interfacesTable[enum] = interfaceConfig + end + return deviceNetworkConfig_Model.interfacesTable +end +deviceNetworkConfig_Model.refreshInterfaces = refreshInterfaces + +local function getNetworkDescription() + if deviceNetworkConfig_Model.interfacesTable ~= {} then + local jsonInterfacesTable = deviceNetworkConfig_Model.helperFuncs.json.encode(deviceNetworkConfig_Model.interfacesTable) + return jsonInterfacesTable + else + return nil + end +end +Script.serveFunction("CSK_DeviceNetworkConfig.getNetworkDescription", getNetworkDescription) + +local function applyEthernetConfig(interfaceName, dhcpEnabled, ipAddress, subnetMask, gateway) + if gateway == '' then gateway = nil end + Ethernet.Interface.setAddressConfig(interfaceName, dhcpEnabled, ipAddress, subnetMask, gateway) + Ethernet.Interface.applyAddressConfig(interfaceName) + Parameters.savePermanent() +end +Script.serveFunction("CSK_DeviceNetworkConfig.applyEthernetConfig", applyEthernetConfig) +deviceNetworkConfig_Model.applyEthernetConfig = applyEthernetConfig + +--************************************************************************* +--********************** End Function Scope ******************************* +--************************************************************************* + +return deviceNetworkConfig_Model diff --git a/CSK_Module_DeviceNetworkConfig/scripts/Configuration/DeviceNetworkConfig/helper/Json.lua b/CSK_Module_DeviceNetworkConfig/scripts/Configuration/DeviceNetworkConfig/helper/Json.lua new file mode 100644 index 0000000..711ef78 --- /dev/null +++ b/CSK_Module_DeviceNetworkConfig/scripts/Configuration/DeviceNetworkConfig/helper/Json.lua @@ -0,0 +1,388 @@ +-- +-- json.lua +-- +-- Copyright (c) 2020 rxi +-- +-- Permission is hereby granted, free of charge, to any person obtaining a copy of +-- this software and associated documentation files (the "Software"), to deal in +-- the Software without restriction, including without limitation the rights to +-- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +-- of the Software, and to permit persons to whom the Software is furnished to do +-- so, subject to the following conditions: +-- +-- The above copyright notice and this permission notice shall be included in all +-- copies or substantial portions of the Software. +-- +-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +-- SOFTWARE. +-- + +local json = { _version = "0.1.2" } + +------------------------------------------------------------------------------- +-- Encode +------------------------------------------------------------------------------- + +local encode + +local escape_char_map = { + [ "\\" ] = "\\", + [ "\"" ] = "\"", + [ "\b" ] = "b", + [ "\f" ] = "f", + [ "\n" ] = "n", + [ "\r" ] = "r", + [ "\t" ] = "t", +} + +local escape_char_map_inv = { [ "/" ] = "/" } +for k, v in pairs(escape_char_map) do + escape_char_map_inv[v] = k +end + + +local function escape_char(c) + return "\\" .. (escape_char_map[c] or string.format("u%04x", c:byte())) +end + + +local function encode_nil(val) + return "null" +end + + +local function encode_table(val, stack) + local res = {} + stack = stack or {} + + -- Circular reference? + if stack[val] then error("circular reference") end + + stack[val] = true + + if rawget(val, 1) ~= nil or next(val) == nil then + -- Treat as array -- check keys are valid and it is not sparse + local n = 0 + for k in pairs(val) do + if type(k) ~= "number" then + error("invalid table: mixed or invalid key types") + end + n = n + 1 + end + if n ~= #val then + error("invalid table: sparse array") + end + -- Encode + for i, v in ipairs(val) do + table.insert(res, encode(v, stack)) + end + stack[val] = nil + return "[" .. table.concat(res, ",") .. "]" + + else + -- Treat as an object + for k, v in pairs(val) do + if type(k) ~= "string" then + error("invalid table: mixed or invalid key types") + end + table.insert(res, encode(k, stack) .. ":" .. encode(v, stack)) + end + stack[val] = nil + return "{" .. table.concat(res, ",") .. "}" + end +end + + +local function encode_string(val) + return '"' .. val:gsub('[%z\1-\31\\"]', escape_char) .. '"' +end + + +local function encode_number(val) + -- Check for NaN, -inf and inf + if val ~= val or val <= -math.huge or val >= math.huge then + error("unexpected number value '" .. tostring(val) .. "'") + end + return string.format("%.14g", val) +end + + +local type_func_map = { + [ "nil" ] = encode_nil, + [ "table" ] = encode_table, + [ "string" ] = encode_string, + [ "number" ] = encode_number, + [ "boolean" ] = tostring, +} + + +encode = function(val, stack) + local t = type(val) + local f = type_func_map[t] + if f then + return f(val, stack) + end + error("unexpected type '" .. t .. "'") +end + + +function json.encode(val) + return ( encode(val) ) +end + + +------------------------------------------------------------------------------- +-- Decode +------------------------------------------------------------------------------- + +local parse + +local function create_set(...) + local res = {} + for i = 1, select("#", ...) do + res[ select(i, ...) ] = true + end + return res +end + +local space_chars = create_set(" ", "\t", "\r", "\n") +local delim_chars = create_set(" ", "\t", "\r", "\n", "]", "}", ",") +local escape_chars = create_set("\\", "/", '"', "b", "f", "n", "r", "t", "u") +local literals = create_set("true", "false", "null") + +local literal_map = { + [ "true" ] = true, + [ "false" ] = false, + [ "null" ] = nil, +} + + +local function next_char(str, idx, set, negate) + for i = idx, #str do + if set[str:sub(i, i)] ~= negate then + return i + end + end + return #str + 1 +end + + +local function decode_error(str, idx, msg) + local line_count = 1 + local col_count = 1 + for i = 1, idx - 1 do + col_count = col_count + 1 + if str:sub(i, i) == "\n" then + line_count = line_count + 1 + col_count = 1 + end + end + error( string.format("%s at line %d col %d", msg, line_count, col_count) ) +end + + +local function codepoint_to_utf8(n) + -- http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=iws-appendixa + local f = math.floor + if n <= 0x7f then + return string.char(n) + elseif n <= 0x7ff then + return string.char(f(n / 64) + 192, n % 64 + 128) + elseif n <= 0xffff then + return string.char(f(n / 4096) + 224, f(n % 4096 / 64) + 128, n % 64 + 128) + elseif n <= 0x10ffff then + return string.char(f(n / 262144) + 240, f(n % 262144 / 4096) + 128, + f(n % 4096 / 64) + 128, n % 64 + 128) + end + error( string.format("invalid unicode codepoint '%x'", n) ) +end + + +local function parse_unicode_escape(s) + local n1 = tonumber( s:sub(1, 4), 16 ) + local n2 = tonumber( s:sub(7, 10), 16 ) + -- Surrogate pair? + if n2 then + return codepoint_to_utf8((n1 - 0xd800) * 0x400 + (n2 - 0xdc00) + 0x10000) + else + return codepoint_to_utf8(n1) + end +end + + +local function parse_string(str, i) + local res = "" + local j = i + 1 + local k = j + + while j <= #str do + local x = str:byte(j) + + if x < 32 then + decode_error(str, j, "control character in string") + + elseif x == 92 then -- `\`: Escape + res = res .. str:sub(k, j - 1) + j = j + 1 + local c = str:sub(j, j) + if c == "u" then + local hex = str:match("^[dD][89aAbB]%x%x\\u%x%x%x%x", j + 1) + or str:match("^%x%x%x%x", j + 1) + or decode_error(str, j - 1, "invalid unicode escape in string") + res = res .. parse_unicode_escape(hex) + j = j + #hex + else + if not escape_chars[c] then + decode_error(str, j - 1, "invalid escape char '" .. c .. "' in string") + end + res = res .. escape_char_map_inv[c] + end + k = j + 1 + + elseif x == 34 then -- `"`: End of string + res = res .. str:sub(k, j - 1) + return res, j + 1 + end + + j = j + 1 + end + + decode_error(str, i, "expected closing quote for string") +end + + +local function parse_number(str, i) + local x = next_char(str, i, delim_chars) + local s = str:sub(i, x - 1) + local n = tonumber(s) + if not n then + decode_error(str, i, "invalid number '" .. s .. "'") + end + return n, x +end + + +local function parse_literal(str, i) + local x = next_char(str, i, delim_chars) + local word = str:sub(i, x - 1) + if not literals[word] then + decode_error(str, i, "invalid literal '" .. word .. "'") + end + return literal_map[word], x +end + + +local function parse_array(str, i) + local res = {} + local n = 1 + i = i + 1 + while 1 do + local x + i = next_char(str, i, space_chars, true) + -- Empty / end of array? + if str:sub(i, i) == "]" then + i = i + 1 + break + end + -- Read token + x, i = parse(str, i) + res[n] = x + n = n + 1 + -- Next token + i = next_char(str, i, space_chars, true) + local chr = str:sub(i, i) + i = i + 1 + if chr == "]" then break end + if chr ~= "," then decode_error(str, i, "expected ']' or ','") end + end + return res, i +end + + +local function parse_object(str, i) + local res = {} + i = i + 1 + while 1 do + local key, val + i = next_char(str, i, space_chars, true) + -- Empty / end of object? + if str:sub(i, i) == "}" then + i = i + 1 + break + end + -- Read key + if str:sub(i, i) ~= '"' then + decode_error(str, i, "expected string for key") + end + key, i = parse(str, i) + -- Read ':' delimiter + i = next_char(str, i, space_chars, true) + if str:sub(i, i) ~= ":" then + decode_error(str, i, "expected ':' after key") + end + i = next_char(str, i + 1, space_chars, true) + -- Read value + val, i = parse(str, i) + -- Set + res[key] = val + -- Next token + i = next_char(str, i, space_chars, true) + local chr = str:sub(i, i) + i = i + 1 + if chr == "}" then break end + if chr ~= "," then decode_error(str, i, "expected '}' or ','") end + end + return res, i +end + + +local char_func_map = { + [ '"' ] = parse_string, + [ "0" ] = parse_number, + [ "1" ] = parse_number, + [ "2" ] = parse_number, + [ "3" ] = parse_number, + [ "4" ] = parse_number, + [ "5" ] = parse_number, + [ "6" ] = parse_number, + [ "7" ] = parse_number, + [ "8" ] = parse_number, + [ "9" ] = parse_number, + [ "-" ] = parse_number, + [ "t" ] = parse_literal, + [ "f" ] = parse_literal, + [ "n" ] = parse_literal, + [ "[" ] = parse_array, + [ "{" ] = parse_object, +} + + +parse = function(str, idx) + local chr = str:sub(idx, idx) + local f = char_func_map[chr] + if f then + return f(str, idx) + end + decode_error(str, idx, "unexpected character '" .. chr .. "'") +end + + +function json.decode(str) + if type(str) ~= "string" then + error("expected argument of type string, got " .. type(str)) + end + local res, idx = parse(str, next_char(str, 1, space_chars, true)) + idx = next_char(str, idx, space_chars, true) + if idx <= #str then + decode_error(str, idx, "trailing garbage") + end + return res +end + + +return json diff --git a/CSK_Module_DeviceNetworkConfig/scripts/Configuration/DeviceNetworkConfig/helper/funcs.lua b/CSK_Module_DeviceNetworkConfig/scripts/Configuration/DeviceNetworkConfig/helper/funcs.lua new file mode 100644 index 0000000..a29d25c --- /dev/null +++ b/CSK_Module_DeviceNetworkConfig/scripts/Configuration/DeviceNetworkConfig/helper/funcs.lua @@ -0,0 +1,175 @@ +---@diagnostic disable: undefined-global, redundant-parameter, missing-parameter +--***************************************************************** +-- Inside of this script, you will find helper functions +--***************************************************************** + +--************************************************************************** +--**********************Start Global Scope ********************************* +--************************************************************************** + +local funcs = {} +-- Providing standard JSON functions +funcs.json = require('Configuration/DeviceNetworkConfig/helper/Json') + +--************************************************************************** +--********************** End Global Scope ********************************** +--************************************************************************** +--**********************Start Function Scope ******************************* +--************************************************************************** + +--- Function to check if inserted string is a valid IP +---@param ip string String to check for IP +---@return boolean status Result if IP is valid +local function checkIP(ip) + if not ip then return false end + local a,b,c,d=ip:match("^(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)$") + a=tonumber(a) + b=tonumber(b) + c=tonumber(c) + d=tonumber(d) + if not a or not b or not c or not d then return false end + if a<0 or 255= 1 then + list = list .. '"' .. tostring(1) .. '"' + end + if size >= 2 then + for i=2, size do + list = list .. ', ' .. '"' .. tostring(i) .. '"' + end + end + list = list .. "]" + return list +end +funcs.createStringListBySize = createStringListBySize + +--- Function to convert a table into a Container object +---@param content auto[] Lua Table to convert to Container +---@return Container cont Created Container +local function convertTable2Container(content) + local cont = Container.create() + for key, value in pairs(content) do + if type(value) == 'table' then + cont:add(key, convertTable2Container(value), nil) + else + cont:add(key, value, nil) + end + end + return cont +end +funcs.convertTable2Container = convertTable2Container + +--- Function to convert a Container into a table +---@param cont Container Container to convert to Lua table +---@return auto[] data Created Lua table +local function convertContainer2Table(cont) + local data = {} + local containerList = Container.list(cont) + local containerCheck = false + if tonumber(containerList[1]) then + containerCheck = true + end + for i=1, #containerList do + + local subContainer + + if containerCheck then + subContainer = Container.get(cont, tostring(i) .. '.00') + else + subContainer = Container.get(cont, containerList[i]) + end + if type(subContainer) == 'userdata' then + if Object.getType(subContainer) == "Container" then + + if containerCheck then + table.insert(data, convertContainer2Table(subContainer)) + else + data[containerList[i]] = convertContainer2Table(subContainer) + end + + else + if containerCheck then + table.insert(data, subContainer) + else + data[containerList[i]] = subContainer + end + end + else + if containerCheck then + table.insert(data, subContainer) + else + data[containerList[i]] = subContainer + end + end + end + return data +end +funcs.convertContainer2Table = convertContainer2Table + +return funcs + +--************************************************************************** +--**********************End Function Scope ********************************* +--************************************************************************** \ No newline at end of file diff --git a/README.md b/README.md index 168a273..abd4f68 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,17 @@ -# CSK_Module_[ModuleName] +# CSK_Module_DeviceNetworkConfig -Module / Application to provide [...] functionality. +Module to provide ethernet setup functionality. -*If available, please also add a screenshot/gif of the UI of the module here placed within /docu/media/ (see code)* -![](https://github.com/SICKAppSpaceCodingStarterKit/[REPO_OF_MODULE]/blob/main/docu/media/UI_Screenshot.png) +![](https://github.com/SICKAppSpaceCodingStarterKit/CSK_Module_DeviceNetworkConfig/blob/main/docu/media/UI_Screenshot.png) ## How to Run - -[***...please fill with informations...***] -For further information check out the [documentation](https://raw.githack.com/SICKAppSpaceCodingStarterKit/[REPO_OF_MODULE]/main/docu/CSK_Module_[MODULENAME].html) [update link] in the folder "docu". +The app includes an intuitive GUI to setup the ethernet setup of the device. +For further information check out the [documentation](https://raw.githack.com/SICKAppSpaceCodingStarterKit/CSK_Module_DeviceNetworkConfig/main/docu/CSK_Module_DeviceNetworkConfig.html) in the folder "docu". ## Information -Tested on: -[Device] - [firmware] -... - -[***optionally***] -Following CSK modules are used for this application via Git subtrees and should NOT be further developed within this repository (see [contribution guideline](https://github.com/SICKAppSpaceCodingStarterKit/.github/blob/main/Contribution_Guideline.md) of this GitHub organization): - - * CSK_Module_XYZ (release/tag v1.2.3) +Tested on: +1. SIM1012 - Firmware 2.2.0 This application / module is part of the SICK AppSpace Coding Starter Kit developing approach. It is programmed in an object oriented way. Some of the modules use kind of "classes" in Lua to make it possible to reuse code / classes in other projects. @@ -28,4 +20,4 @@ Please check the [documentation](https://github.com/SICKAppSpaceCodingStarterKit ## Topics -Coding Starter Kit, CSK, Module, SICK-AppSpace, [key_words] +Coding Starter Kit, CSK, Module, SICK-AppSpace, Ethernet, Interface, Config, Device diff --git a/docu/CSK_Module_DeviceNetworkConfig.html b/docu/CSK_Module_DeviceNetworkConfig.html new file mode 100644 index 0000000..011bc86 --- /dev/null +++ b/docu/CSK_Module_DeviceNetworkConfig.html @@ -0,0 +1,2623 @@ + + + + + + + + +Documentation - CSK_Module_DeviceNetworkConfig 2.0.0 + + + + + + +
+
+

Document metadata

+
+ ++++ + + + + + + + + + + + + + + + + + + +

Application name

CSK_Module_DeviceNetworkConfig

Version

2.0.0

Date

2023-06-14

Author

SICK AG

+
+
+
+

Crowns

+
+ +
+

CSK_DeviceNetworkConfig

+
+

Short description

+
+

This module provides the possibility to setup the ethernet interfaces of the device.
+See following descriptions of events/functions regarding further information.

+
+
+ +
+

Functions

+
+
CSK_DeviceNetworkConfig.applyConfig()
+
+
Short description
+
+

Apply preset network configuration to device when button in UI is pressed.

+
+
+
+
Sample (auto-generated)
+
+
+
CSK_DeviceNetworkConfig.applyConfig()
+
+
+
+
+
+
CSK_DeviceNetworkConfig.applyEthernetConfig()
+
+
Short description
+
+

Applies new configuration of Ethernet interface.

+
+
+
+
Parameters
+ ++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeMultiplicityDescription

interfaceName

STRING

1

Name of Ethernet interface to upload new configuration to, e.g. ETH1, ETH2 etc.

dhcpEnabled

BOOL

1

New DHCP state. If true, then IP, subnet mask and gateway must be nil.

ipAddress

STRING

1

New IP addres. Must be nil if DHCP is on.

subnetMask

STRING

1

New subnet mask. Must be nil if DHCP is on.

gateway

STRING

1

New default gateway. Must be nil if DHCP is on.

+
+
+
Sample (auto-generated)
+
+
+
CSK_DeviceNetworkConfig.applyEthernetConfig(interfaceName, dhcpEnabled, ipAddress, subnetMask, gateway)
+
+
+
+
+
+
CSK_DeviceNetworkConfig.getNetworkDescription()
+
+
Short description
+
+

Get current network description of device in JSON format.

+
+
+
+
Return values
+ ++++++ + + + + + + + + + + + + + + + + +
NameTypeMultiplicityDescription

jsonInterfacesTable

STRING

?

Network description as JSON.

+
+
+
Sample (auto-generated)
+
+
+
jsonInterfacesTable = CSK_DeviceNetworkConfig.getNetworkDescription()
+
+
+
+
+
+
CSK_DeviceNetworkConfig.pageCalled()
+
+
Short description
+
+

Function to register "OnResume" of the module UI (only as helper function).

+
+
+
+
Return values
+ ++++++ + + + + + + + + + + + + + + + + +
NameTypeMultiplicityDescription

empty

STRING

1

Empty string (only needed to simplify binding).

+
+
+
Sample (auto-generated)
+
+
+
empty = CSK_DeviceNetworkConfig.pageCalled()
+
+
+
+
+
+
CSK_DeviceNetworkConfig.ping()
+
+
Short description
+
+

Try to ping preset IP (see 'setPingIpAddress').

+
+
+
+
Sample (auto-generated)
+
+
+
CSK_DeviceNetworkConfig.ping()
+
+
+
+
+
+
CSK_DeviceNetworkConfig.refresh()
+
+
Short description
+
+

Get current configuration of Ethernet ports.

+
+
+
+
Sample (auto-generated)
+
+
+
CSK_DeviceNetworkConfig.refresh()
+
+
+
+
+
+
CSK_DeviceNetworkConfig.selectInterface()
+
+
Short description
+
+

Select ethernet interface via table in UI.

+
+
+
+
Parameters
+ ++++++ + + + + + + + + + + + + + + + + +
NameTypeMultiplicityDescription

row_selected

STRING

1

The string with chosen row’s content in JSON format.

+
+
+
Sample (auto-generated)
+
+
+
CSK_DeviceNetworkConfig.selectInterface(row_selected)
+
+
+
+
+
+
CSK_DeviceNetworkConfig.setDefaultGateway()
+
+
Short description
+
+

Preset default gateway to be configured via 'applyConfig'.

+
+
+
+
Parameters
+ ++++++ + + + + + + + + + + + + + + + + +
NameTypeMultiplicityDescription

newDefaultGateway

STRING

1

Gateway

+
+
+
Sample (auto-generated)
+
+
+
CSK_DeviceNetworkConfig.setDefaultGateway(newDefaultGateway)
+
+
+
+
+
+
CSK_DeviceNetworkConfig.setDHCPState()
+
+
Short description
+
+

Preset DHCP status to be configured via 'applyConfig'.

+
+
+
+
Parameters
+ ++++++ + + + + + + + + + + + + + + + + +
NameTypeMultiplicityDescription

newDHCPstate

BOOL

1

DHCP state (true to enable DHCP).

+
+
+
Sample (auto-generated)
+
+
+
CSK_DeviceNetworkConfig.setDHCPState(newDHCPstate)
+
+
+
+
+
+
CSK_DeviceNetworkConfig.setInterfaceIP()
+
+
Short description
+
+

Preset IP to be configured via 'applyConfig'.

+
+
+
+
Parameters
+ ++++++ + + + + + + + + + + + + + + + + +
NameTypeMultiplicityDescription

newIP

STRING

1

IP

+
+
+
Sample (auto-generated)
+
+
+
CSK_DeviceNetworkConfig.setInterfaceIP(newIP)
+
+
+
+
+
+
CSK_DeviceNetworkConfig.setPingIPAddress()
+
+
Short description
+
+

Preset IP to ping (see 'ping' function).

+
+
+
+
Parameters
+ ++++++ + + + + + + + + + + + + + + + + +
NameTypeMultiplicityDescription

ping_ip

STRING

1

IP

+
+
+
Sample (auto-generated)
+
+
+
CSK_DeviceNetworkConfig.setPingIPAddress(ping_ip)
+
+
+
+
+
+
CSK_DeviceNetworkConfig.setSubnetMask()
+
+
Short description
+
+

Preset subnet mask to be configured via 'applyConfig'.

+
+
+
+
Parameters
+ ++++++ + + + + + + + + + + + + + + + + +
NameTypeMultiplicityDescription

newSubnetMask

STRING

1

Subnet mask

+
+
+
Sample (auto-generated)
+
+
+
CSK_DeviceNetworkConfig.setSubnetMask(newSubnetMask)
+
+
+
+
+
+
+

Events

+
+
CSK_DeviceNetworkConfig.OnApplyButtonDisabled
+
+
Short description
+
+

Notified to disable / enable 'Apply new config' button in UI.

+
+
+
+
Callback arguments
+ ++++++ + + + + + + + + + + + + + + + + +
NameTypeMultiplicityDescription

isDisabled

BOOL

1

Status

+
+
+
Sample (auto-generated)
+
+
+
function handleOnApplyButtonDisabled(isDisabled)
+  -- Do something
+end
+
+Script.register("CSK_DeviceNetworkConfig.OnApplyButtonDisabled", "handleOnApplyButtonDisabled")
+
+
+
+
+
+
CSK_DeviceNetworkConfig.OnDHCPDisabled
+
+
Short description
+
+

Notified to disable / enable 'DHCP' checkbox in UI.

+
+
+
+
Callback arguments
+ ++++++ + + + + + + + + + + + + + + + + +
NameTypeMultiplicityDescription

isDisabled

BOOL

1

Status

+
+
+
Sample (auto-generated)
+
+
+
function handleOnDHCPDisabled(isDisabled)
+  -- Do something
+end
+
+Script.register("CSK_DeviceNetworkConfig.OnDHCPDisabled", "handleOnDHCPDisabled")
+
+
+
+
+
+
CSK_DeviceNetworkConfig.OnGatewayDisabled
+
+
Short description
+
+

Notified to disable / enable 'Gateway' text field in UI.

+
+
+
+
Callback arguments
+ ++++++ + + + + + + + + + + + + + + + + +
NameTypeMultiplicityDescription

isDisabled

BOOL

1

Status

+
+
+
Sample (auto-generated)
+
+
+
function handleOnGatewayDisabled(isDisabled)
+  -- Do something
+end
+
+Script.register("CSK_DeviceNetworkConfig.OnGatewayDisabled", "handleOnGatewayDisabled")
+
+
+
+
+
+
CSK_DeviceNetworkConfig.OnGatewayError
+
+
Short description
+
+

Highlights the 'Gateway field' in UI if format of gateway is not correct.

+
+
+
+
Callback arguments
+ ++++++ + + + + + + + + + + + + + + + + +
NameTypeMultiplicityDescription

isError

BOOL

1

Status

+
+
+
Sample (auto-generated)
+
+
+
function handleOnGatewayError(isError)
+  -- Do something
+end
+
+Script.register("CSK_DeviceNetworkConfig.OnGatewayError", "handleOnGatewayError")
+
+
+
+
+
+
CSK_DeviceNetworkConfig.OnIPDisabled
+
+
Short description
+
+

Notified to disable / enable 'IP' text field in UI.

+
+
+
+
Callback arguments
+ ++++++ + + + + + + + + + + + + + + + + +
NameTypeMultiplicityDescription

isDisabled

BOOL

1

Status

+
+
+
Sample (auto-generated)
+
+
+
function handleOnIPDisabled(isDisabled)
+  -- Do something
+end
+
+Script.register("CSK_DeviceNetworkConfig.OnIPDisabled", "handleOnIPDisabled")
+
+
+
+
+
+
CSK_DeviceNetworkConfig.OnIPError
+
+
Short description
+
+

Highlights the 'IP' in UI if format of IP is not correct.

+
+
+
+
Callback arguments
+ ++++++ + + + + + + + + + + + + + + + + +
NameTypeMultiplicityDescription

isError

BOOL

1

Status

+
+
+
Sample (auto-generated)
+
+
+
function handleOnIPError(isError)
+  -- Do something
+end
+
+Script.register("CSK_DeviceNetworkConfig.OnIPError", "handleOnIPError")
+
+
+
+
+
+
CSK_DeviceNetworkConfig.OnNewDefaultGateway
+
+
Short description
+
+

Notify current 'Default Gateway'

+
+
+
+
Callback arguments
+ ++++++ + + + + + + + + + + + + + + + + +
NameTypeMultiplicityDescription

DefaultGateway

STRING

1

Default Gateway.

+
+
+
Sample (auto-generated)
+
+
+
function handleOnNewDefaultGateway(DefaultGateway)
+  -- Do something
+end
+
+Script.register("CSK_DeviceNetworkConfig.OnNewDefaultGateway", "handleOnNewDefaultGateway")
+
+
+
+
+
+
CSK_DeviceNetworkConfig.OnNewDHCPStatus
+
+
Short description
+
+

Notify current DHCP status.

+
+
+
+
Callback arguments
+ ++++++ + + + + + + + + + + + + + + + + +
NameTypeMultiplicityDescription

DHCPStatus

BOOL

1

Status

+
+
+
Sample (auto-generated)
+
+
+
function handleOnNewDHCPStatus(DHCPStatus)
+  -- Do something
+end
+
+Script.register("CSK_DeviceNetworkConfig.OnNewDHCPStatus", "handleOnNewDHCPStatus")
+
+
+
+
+
+
CSK_DeviceNetworkConfig.OnNewEthernetConfigStatus
+
+
Short description
+
+

Notify current configuration process status.

+
+
+
+
Callback arguments
+ ++++++ + + + + + + + + + + + + + + + + +
NameTypeMultiplicityDescription

newEthernetConfigStatus

STRING

1

Status

+
+
+
Sample (auto-generated)
+
+
+
function handleOnNewEthernetConfigStatus(newEthernetConfigStatus)
+  -- Do something
+end
+
+Script.register("CSK_DeviceNetworkConfig.OnNewEthernetConfigStatus", "handleOnNewEthernetConfigStatus")
+
+
+
+
+
+
CSK_DeviceNetworkConfig.OnNewInterfaceChoice
+
+
Short description
+
+

Notify currently selected interface.

+
+
+
+
Callback arguments
+ ++++++ + + + + + + + + + + + + + + + + +
NameTypeMultiplicityDescription

NewInterface

STRING

1

The selected interface.

+
+
+
Sample (auto-generated)
+
+
+
function handleOnNewInterfaceChoice(NewInterface)
+  -- Do something
+end
+
+Script.register("CSK_DeviceNetworkConfig.OnNewInterfaceChoice", "handleOnNewInterfaceChoice")
+
+
+
+
+
+
CSK_DeviceNetworkConfig.OnNewInterfaceTable
+
+
Short description
+
+

Notify interface table as JSON (e.g. for table in UI).

+
+
+
+
Callback arguments
+ ++++++ + + + + + + + + + + + + + + + + +
NameTypeMultiplicityDescription

InterfaceTable

STRING

1

Table of interfaces as a JSON string.

+
+
+
Sample (auto-generated)
+
+
+
function handleOnNewInterfaceTable(InterfaceTable)
+  -- Do something
+end
+
+Script.register("CSK_DeviceNetworkConfig.OnNewInterfaceTable", "handleOnNewInterfaceTable")
+
+
+
+
+
+
CSK_DeviceNetworkConfig.OnNewIP
+
+
Short description
+
+

Notify current IP.

+
+
+
+
Callback arguments
+ ++++++ + + + + + + + + + + + + + + + + +
NameTypeMultiplicityDescription

ip

STRING

1

IP

+
+
+
Sample (auto-generated)
+
+
+
function handleOnNewIP(ip)
+  -- Do something
+end
+
+Script.register("CSK_DeviceNetworkConfig.OnNewIP", "handleOnNewIP")
+
+
+
+
+
+
CSK_DeviceNetworkConfig.OnNewPingDetails
+
+
Short description
+
+

Notify details of executed ping command.

+
+
+
+
Callback arguments
+ ++++++ + + + + + + + + + + + + + + + + +
NameTypeMultiplicityDescription

details

STRING

1

Ping details.

+
+
+
Sample (auto-generated)
+
+
+
function handleOnNewPingDetails(details)
+  -- Do something
+end
+
+Script.register("CSK_DeviceNetworkConfig.OnNewPingDetails", "handleOnNewPingDetails")
+
+
+
+
+
+
CSK_DeviceNetworkConfig.OnNewPingResult
+
+
Short description
+
+

Notify result of executed ping command.

+
+
+
+
Callback arguments
+ ++++++ + + + + + + + + + + + + + + + + +
NameTypeMultiplicityDescription

result

BOOL

1

Result

+
+
+
Sample (auto-generated)
+
+
+
function handleOnNewPingResult(result)
+  -- Do something
+end
+
+Script.register("CSK_DeviceNetworkConfig.OnNewPingResult", "handleOnNewPingResult")
+
+
+
+
+
+
CSK_DeviceNetworkConfig.OnNewSubnetMask
+
+
Short description
+
+

Notify current subnet mask.

+
+
+
+
Callback arguments
+ ++++++ + + + + + + + + + + + + + + + + +
NameTypeMultiplicityDescription

SubnetMask

STRING

1

Subnet mask.

+
+
+
Sample (auto-generated)
+
+
+
function handleOnNewSubnetMask(SubnetMask)
+  -- Do something
+end
+
+Script.register("CSK_DeviceNetworkConfig.OnNewSubnetMask", "handleOnNewSubnetMask")
+
+
+
+
+
+
CSK_DeviceNetworkConfig.OnSubnetDisabled
+
+
Short description
+
+

Notified to disable / enable 'Subnet mask' text field in UI.

+
+
+
+
Callback arguments
+ ++++++ + + + + + + + + + + + + + + + + +
NameTypeMultiplicityDescription

isDisabled

BOOL

1

Status

+
+
+
Sample (auto-generated)
+
+
+
function handleOnSubnetDisabled(isDisabled)
+  -- Do something
+end
+
+Script.register("CSK_DeviceNetworkConfig.OnSubnetDisabled", "handleOnSubnetDisabled")
+
+
+
+
+
+
CSK_DeviceNetworkConfig.OnSubnetError
+
+
Short description
+
+

Highlights the 'Subnet' field in UI if format is not correct.

+
+
+
+
Callback arguments
+ ++++++ + + + + + + + + + + + + + + + + +
NameTypeMultiplicityDescription

isError

BOOL

1

Status

+
+
+
Sample (auto-generated)
+
+
+
function handleOnSubnetError(isError)
+  -- Do something
+end
+
+Script.register("CSK_DeviceNetworkConfig.OnSubnetError", "handleOnSubnetError")
+
+
+
+
+
+
CSK_DeviceNetworkConfig.OnUserLevelAdminActive
+
+
Short description
+
+

Status of Admin userlevel. Used internally in combination with the CSK_UserManagement module if available.

+
+
+
+
Callback arguments
+ ++++++ + + + + + + + + + + + + + + + + +
NameTypeMultiplicityDescription

status

BOOL

1

Status

+
+
+
Sample (auto-generated)
+
+
+
function handleOnUserLevelAdminActive(status)
+  -- Do something
+end
+
+Script.register("CSK_DeviceNetworkConfig.OnUserLevelAdminActive", "handleOnUserLevelAdminActive")
+
+
+
+
+
+
CSK_DeviceNetworkConfig.OnUserLevelMaintenanceActive
+
+
Short description
+
+

Status of Maintenance userlevel. Used internally in combination with the CSK_UserManagement module if available.

+
+
+
+
Callback arguments
+ ++++++ + + + + + + + + + + + + + + + + +
NameTypeMultiplicityDescription

status

BOOL

1

Status

+
+
+
Sample (auto-generated)
+
+
+
function handleOnUserLevelMaintenanceActive(status)
+  -- Do something
+end
+
+Script.register("CSK_DeviceNetworkConfig.OnUserLevelMaintenanceActive", "handleOnUserLevelMaintenanceActive")
+
+
+
+
+
+
CSK_DeviceNetworkConfig.OnUserLevelOperatorActive
+
+
Short description
+
+

Status of Operator userlevel. Used internally in combination with the CSK_UserManagement module if available.

+
+
+
+
Callback arguments
+ ++++++ + + + + + + + + + + + + + + + + +
NameTypeMultiplicityDescription

status

BOOL

1

Status

+
+
+
Sample (auto-generated)
+
+
+
function handleOnUserLevelOperatorActive(status)
+  -- Do something
+end
+
+Script.register("CSK_DeviceNetworkConfig.OnUserLevelOperatorActive", "handleOnUserLevelOperatorActive")
+
+
+
+
+
+
CSK_DeviceNetworkConfig.OnUserLevelServiceActive
+
+
Short description
+
+

Status of Service userlevel. Used internally in combination with the CSK_UserManagement module if available.

+
+
+
+
Callback arguments
+ ++++++ + + + + + + + + + + + + + + + + +
NameTypeMultiplicityDescription

status

BOOL

1

Status

+
+
+
Sample (auto-generated)
+
+
+
function handleOnUserLevelServiceActive(status)
+  -- Do something
+end
+
+Script.register("CSK_DeviceNetworkConfig.OnUserLevelServiceActive", "handleOnUserLevelServiceActive")
+
+
+
+
+
+
+
+

CSK_Module_DeviceNetworkConfig

+
+

Short description

+
+

This is an automatically generated CROWN (description not necessary).

+
+
+
+

Overview

+ +
+
+
+
+
+ + + + diff --git a/docu/media/UI_Screenshot.png b/docu/media/UI_Screenshot.png new file mode 100644 index 0000000..c6af2d9 Binary files /dev/null and b/docu/media/UI_Screenshot.png differ