Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2917 Added Point locator test fields validation in Modbus IP #2919

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
e063ca3
#2917 Added Point locator test fields validation in Modbus IP
Patrykb0802 Jun 8, 2024
46e07bd
#2917 Added Point locator test fields validation in Modbus IP
Patrykb0802 Jun 12, 2024
790358f
#2917 Added Point locator test fields validation in Modbus IP
Patrykb0802 Jun 12, 2024
77ae878
#2917 Added Point locator test fields validation in Modbus IP
Patrykb0802 Jun 12, 2024
5184d5f
#2917 Added Point locator test fields validation in Modbus IP
Patrykb0802 Jun 14, 2024
05d7982
#2917 Added Point locator test fields validation in Modbus IP
Patrykb0802 Jun 19, 2024
d8bcbd7
#2917 Added Point locator test fields validation in Modbus IP
Patrykb0802 Jun 20, 2024
86b9e80
#2917 Added Point locator test fields validation in Modbus IP
Patrykb0802 Jun 20, 2024
363b9c0
#2917 Added Point locator test fields validation in Modbus IP
Patrykb0802 Jun 20, 2024
cbf1a8e
#2917 Added Point locator test fields validation in Modbus IP
Patrykb0802 Jun 21, 2024
fa49be3
#2845 Fixed message validation in event search
Patrykb0802 Jun 21, 2024
7fd2396
Merge branch 'release/2.7.8' into feature/#2917_Added_Point_locator_t…
Limraj Jun 21, 2024
ab16263
#2917 Added Point locator test fields validation in Modbus IP
Patrykb0802 Jun 27, 2024
e8865e7
#2917 Added Point locator test fields validation in Modbus IP
Patrykb0802 Jul 1, 2024
6805506
#2917 Added Point locator test fields validation in Modbus IP
Patrykb0802 Jul 2, 2024
d2ee637
#2917 Added Point locator test fields validation in Modbus IP
Patrykb0802 Jul 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 109 additions & 15 deletions WebContent/WEB-INF/jsp/dataSourceEdit/editModbus.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,72 @@
setDisabled("scanBtn", scanning);
setDisabled("scanCancelBtn", !scanning);
}

function validateLocatorTest(locator){

let messages = [];

validateValue("test_slaveId", "<fmt:message key='badIntegerFormat'/>", isPositiveInt, locator.slaveId, messages);
validateValue("test_range", "<fmt:message key='badIntegerFormat'/>", isPositiveInt, locator.range, messages);
validateValue("test_modbusDataType", "<fmt:message key='badIntegerFormat'/>", isPositiveInt, locator.modbusDataType, messages);
validateValue("test_offset", "<fmt:message key='badIntegerFormat'/>", isPositiveInt, locator.offset, messages);
validateValue("test_bit", "<fmt:message key='validate.invalidValue'/>", isPositiveByte, locator.bit, messages);
validateValue("test_registerCount", "<fmt:message key='badIntegerFormat'/>", isPositiveInt, locator.registerCount, messages);

return messages;
}

function validateValue(htmlId, messageText, validate, value, messages) {
if(!validate(value)) {
let message = createValidationMessage(htmlId, messageText);
messages.push(message);
}
}

function createLocatorConfigTemp(){
let temp = {};
temp.slaveId = $get("test_slaveId");
temp.range = $get("test_range");
temp.modbusDataType = $get("test_modbusDataType");
temp.offset = $get("test_offset");
temp.bit = $get("test_bit");
temp.registerCount = $get("test_registerCount");
temp.charset = $get("test_charset");

return temp;
}


function locatorTest() {

var locator = {};
locator.slaveId = $get("test_slaveId");
locator.range = $get("test_range");
locator.modbusDataType = $get("test_modbusDataType");
locator.offset = $get("test_offset");
locator.bit = $get("test_bit");
locator.registerCount = $get("test_registerCount");
locator.charset = $get("test_charset");

locatorTestImpl(locator);

let locatorConfigTemp = createLocatorConfigTemp();
let modbusConfigTemp = createModbusConfigTemp();

hideGenericMessages("locatorTestGeneric");
hideContextualMessages("locatorTestDiv");
hideContextualMessages("dataSourceProperties");

let modbusMessages = validateModbusConfig(modbusConfigTemp);

let messagesLocator = validateLocatorTest(locatorConfigTemp);

let messages = modbusMessages.concat(messagesLocator);

if(messages.length > 0) {
stopImageFader("dsSaveImg");
showDwrMessages(messages);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stopImageFader("dsSaveImg");

} else {
let locator = {};
locator.slaveId = parseInt(locatorConfigTemp.slaveId);
locator.range = parseInt(locatorConfigTemp.range);
locator.modbusDataType = parseInt(locatorConfigTemp.modbusDataType);
locator.offset = parseInt(locatorConfigTemp.offset);
locator.bit = parseInt(locatorConfigTemp.bit);
locator.registerCount = parseInt(locatorConfigTemp.registerCount);
locator.charset = locatorConfigTemp.charset;

locatorTestImpl(locator);
}
}

function locatorTestCB(response) {
Expand All @@ -98,9 +151,50 @@
}

function dataTest() {
setDisabled("dataTestBtn", true);
dataTestImpl($get("dataTest_slaveId"), $get("dataTest_range"), $get("dataTest_offset"), $get("dataTest_length"));
hideGenericMessages("dataTestGeneric");
let dataTestConfigTemp = createTestDataTemp();
let modbusConfigTemp = createModbusConfigTemp();

hideContextualMessages("dataTestDiv");

let testDataMessages = validateTestData(dataTestConfigTemp);
let modbusMessages = validateModbusConfig(modbusConfigTemp);

let messages = modbusMessages.concat(testDataMessages);

if(messages.length > 0) {
showDwrMessages(messages);
} else {
let slaveId = parseInt(dataTestConfigTemp.slaveId);
let range = parseInt(dataTestConfigTemp.range);
let offset = parseInt(dataTestConfigTemp.offset);
let length = parseInt(dataTestConfigTemp.length);

dataTestImpl(slaveId, range, offset, length);
hideGenericMessages("dataTestGeneric");
}
}

function validateTestData(testData){

let messages = [];

validateValue("dataTest_slaveId", "<fmt:message key='badIntegerFormat'/>", isPositiveInt, testData.slaveId, messages);
validateValue("dataTest_range", "<fmt:message key='badIntegerFormat'/>", isPositiveInt, testData.range, messages);
validateValue("dataTest_offset", "<fmt:message key='badIntegerFormat'/>", isPositiveInt, testData.offset, messages);
validateValue("dataTest_length", "<fmt:message key='badIntegerFormat'/>", isPositiveInt, testData.length, messages);

return messages;
}

function createTestDataTemp(){
let temp = {};

temp.slaveId = $get("dataTest_slaveId");
temp.range = $get("dataTest_range");
temp.offset = $get("dataTest_offset");
temp.length = $get("dataTest_length");

return temp;
}

function dataTestCB(response) {
Expand Down Expand Up @@ -366,7 +460,7 @@
</table>
</div>

<div class="borderDiv marB marR" style="float:left;">
<div class="borderDiv marB marR" style="float:left;" id="dataTestDiv">
<table>
<tr><td colspan="2" class="smallTitle"><fmt:message key="dsEdit.modbus.dataTest"/></td></tr>

Expand Down
74 changes: 69 additions & 5 deletions WebContent/WEB-INF/jsp/dataSourceEdit/editModbusIp.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,77 @@
DataSourceEditDwr.testModbusIpData($get("timeout"), $get("retries"), $get("transportType"), $get("host"),
$get("port"), $get("encapsulated"), slaveId, range, offset, length, dataTestCB);
}

function validateModbusConfig(temp){

let messages = [];

validateValue("updatePeriods", "<fmt:message key='badIntegerFormat'/>", isPositiveInt, temp.updatePeriods, messages);
validateValue("updatePeriodType", "<fmt:message key='badIntegerFormat'/>", isPositiveInt, temp.updatePeriodType, messages);
validateValue("timeout", "<fmt:message key='badIntegerFormat'/>", isPositiveInt, temp.timeout, messages);
validateValue("retries", "<fmt:message key='badIntegerFormat'/>", isPositiveInt, temp.retries, messages);
validateValue("maxReadBitCount", "<fmt:message key='badIntegerFormat'/>", isPositiveInt, temp.maxReadBitCount, messages);
validateValue("maxReadRegisterCount", "<fmt:message key='badIntegerFormat'/>", isPositiveInt, temp.maxReadRegisterCount, messages);
validateValue("maxWriteRegisterCount", "<fmt:message key='badIntegerFormat'/>", isPositiveInt, temp.maxWriteRegisterCount, messages);
validateValue("port", "<fmt:message key='badIntegerFormat'/>", isPositiveInt, temp.port, messages);

return messages;
}

function createModbusConfigTemp(){
let modbus = {};
modbus.dataSourceName = $get("dataSourceName");
modbus.dataSourceXid = $get("dataSourceXid");
modbus.updatePeriods = $get("updatePeriods");
modbus.updatePeriodType = $get("updatePeriodType");
modbus.quantize = $get("quantize");
modbus.timeout = $get("timeout");
modbus.retries = $get("retries");
modbus.contiguousBatches = $get("contiguousBatches");
modbus.createSlaveMonitorPoints = $get("createSlaveMonitorPoints");
modbus.maxReadBitCount = $get("maxReadBitCount");
modbus.maxReadRegisterCount = $get("maxReadRegisterCount");
modbus.maxWriteRegisterCount = $get("maxWriteRegisterCount");
modbus.transportType = $get("transportType");
modbus.host = $get("host");
modbus.port = $get("port");
modbus.encapsulated = $get("encapsulated");
modbus.createSocketMonitorPoint = $get("createSocketMonitorPoint");

return modbus;
}

function saveDataSourceImpl() {
DataSourceEditDwr.saveModbusIpDataSource($get("dataSourceName"), $get("dataSourceXid"), $get("updatePeriods"),
$get("updatePeriodType"), $get("quantize"), $get("timeout"), $get("retries"), $get("contiguousBatches"),
$get("createSlaveMonitorPoints"), $get("maxReadBitCount"), $get("maxReadRegisterCount"),
$get("maxWriteRegisterCount"), $get("transportType"), $get("host"), $get("port"), $get("encapsulated"), $get("createSocketMonitorPoint"),
saveDataSourceCB);

let temp = createModbusConfigTemp();

let messages = validateModbusConfig(temp);

if(messages.length > 0) {
stopImageFader("dsSaveImg");
showDwrMessages(messages);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stopImageFader("dsSaveImg");

} else {
let dataSourceName = temp.dataSourceName;
let dataSourceXid = temp.dataSourceXid;
let updatePeriods = parseInt(temp.updatePeriods);
let updatePeriodType = parseInt(temp.updatePeriodType);
let quantize = temp.quantize;
let timeout = parseInt(temp.timeout);
let retries = parseInt(temp.retries);
let contiguousBatches = temp.contiguousBatches;
let createSlaveMonitorPoints = temp.createSlaveMonitorPoints;
let maxReadBitCount = parseInt(temp.maxReadBitCount);
let maxReadRegisterCount = parseInt(temp.maxReadRegisterCount);
let maxWriteRegisterCount = parseInt(temp.maxWriteRegisterCount);
let transportType = temp.transportType;
let host = temp.host;
let port = parseInt(temp.port);
let encapsulated = temp.encapsulated;
let createSocketMonitorPoint = temp.createSocketMonitorPoint;
DataSourceEditDwr.saveModbusIpDataSource(dataSourceName, dataSourceXid, updatePeriods,
updatePeriodType, quantize, timeout, retries, contiguousBatches, createSlaveMonitorPoints, maxReadBitCount, maxReadRegisterCount,
maxWriteRegisterCount, transportType, host, port, encapsulated, createSocketMonitorPoint, saveDataSourceCB);
}
}
</script>

Expand Down
7 changes: 5 additions & 2 deletions WebContent/resources/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -1043,8 +1043,6 @@ function createValidationMessage(node, message) {
return {contextKey:node, contextualMessage:message};
}



function updateChartComparatorComponent(idPrefix, width, height) {
var fromDate = $get(idPrefix+"_fromDate1");
var toDate = $get(idPrefix+"_toDate1");
Expand Down Expand Up @@ -1123,3 +1121,8 @@ function trim(value) {
return result;
}

function isPositiveByte(value) {
let trimValue = trim(value);
return isInt32(trimValue) && trimValue >= 0 && trimValue <= 127;
}

Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public void validate(DwrResponseI18n response) {

try {
Charset.forName(charset);
} catch (IllegalCharsetNameException e) {
} catch (Exception e) {
response.addContextualMessage("charset",
"validate.invalidCharset");
}
Expand Down
5 changes: 4 additions & 1 deletion src/com/serotonin/mango/web/dwr/DataSourceEditDwr.java
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,10 @@ private void testModbusPointLocator(ModbusMaster modbusMaster,
} catch (IllegalCharsetNameException e) {
response.addMessage(new LocalizableMessage(
"validate.invalidCharset"));
} finally {
} catch (Exception e) {
response.addMessage(new LocalizableMessage("common.default", e.getLocalizedMessage()));
} finally
{
modbusMaster.destroy();
}
}
Expand Down
Loading