-
Notifications
You must be signed in to change notification settings - Fork 291
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
Changes from 1 commit
e063ca3
46e07bd
790358f
77ae878
5184d5f
05d7982
d8bcbd7
86b9e80
363b9c0
cbf1a8e
fa49be3
7fd2396
ab16263
e8865e7
6805506
d2ee637
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Added Modbus IP properties fields validation for integers - Changed validation mechanism
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,37 +65,87 @@ | |
setDisabled("scanBtn", scanning); | ||
setDisabled("scanCancelBtn", !scanning); | ||
} | ||
|
||
function validateLocatorTest(temp){ | ||
|
||
let messages = []; | ||
|
||
if (!isPositiveInt(temp.slaveId)) { | ||
messages.push(createValidationMessage("test_slaveId", "<fmt:message key='badIntegerFormat'/>")); | ||
} | ||
|
||
if(!isPositiveInt(temp.range)) { | ||
messages.push(createValidationMessage("test_range", "<fmt:message key='badIntegerFormat'/>")); | ||
} | ||
|
||
if(!isPositiveInt(temp.modbusDataType)) { | ||
messages.push(createValidationMessage("test_modbusDataType", "<fmt:message key='badIntegerFormat'/>")); | ||
} | ||
|
||
if (!isPositiveInt(temp.offset)) { | ||
messages.push(createValidationMessage("test_offset", "<fmt:message key='badIntegerFormat'/>")); | ||
} | ||
|
||
if(!isPositiveByte(temp.bit)) { | ||
messages.push(createValidationMessage("test_bit", "<fmt:message key='validate.invalidValue'/>")); | ||
} | ||
|
||
if(!isPositiveInt(temp.registerCount)) { | ||
messages.push(createValidationMessage("test_registerCount", "<fmt:message key='validate.invalidValue'/>")); | ||
} | ||
|
||
return messages; | ||
} | ||
|
||
function createTempLocator(){ | ||
let slaveId = $get("test_slaveId"); | ||
let range = $get("test_range"); | ||
let modbusDataType = $get("test_modbusDataType"); | ||
let offset = $get("test_offset"); | ||
let bit = $get("test_bit"); | ||
let registerCount = $get("test_registerCount"); | ||
let charset = $get("test_charset"); | ||
|
||
let temp = {}; | ||
temp.slaveId = slaveId; | ||
temp.range = range; | ||
temp.modbusDataType = modbusDataType; | ||
temp.offset = offset; | ||
temp.bit = bit; | ||
temp.registerCount = registerCount; | ||
temp.charset = charset; | ||
|
||
return temp; | ||
} | ||
|
||
|
||
function locatorTest() { | ||
setDisabled("locatorTestBtn", true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to remove this line: |
||
|
||
let slaveId = $get("test_slaveId"); | ||
let range = $get("test_range"); | ||
let modbusDataType = $get("test_modbusDataType"); | ||
let offset = $get("test_offset"); | ||
let bit = $get("test_bit"); | ||
let registerCount = $get("test_registerCount"); | ||
let charset = $get("test_charset"); | ||
let temp = createTempLocator(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. createLocatorConfigTemp |
||
let tempModbusData = createTempModbusData(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. createModbusConfigTemp |
||
|
||
hideGenericMessages("locatorTestGeneric"); | ||
hideContextualMessages("locatorTestDiv"); | ||
if (!isPositiveInt(slaveId)) { | ||
createAndDisplayValidationMessage("test_slaveId", "<fmt:message key='badIntegerFormat'/>"); | ||
} else if (!isPositiveInt(offset)) { | ||
createAndDisplayValidationMessage("test_offset", "<fmt:message key='badIntegerFormat'/>"); | ||
} else if(!isPositiveByte(bit)) { | ||
createAndDisplayValidationMessage("test_bit", "<fmt:message key='validate.invalidValue'/>"); | ||
} else if(!isPositiveInt(registerCount)) { | ||
createAndDisplayValidationMessage("test_registerCount", "<fmt:message key='badIntegerFormat'/>"); | ||
hideContextualMessages("dataSourceProperties"); | ||
|
||
let messagesModbus = validateModbusProperties(tempModbusData); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. modbusMessages, validateModbusConfig |
||
|
||
let messagesLocator = validateLocatorTest(temp); | ||
|
||
let messages = messagesModbus.concat(messagesLocator); | ||
|
||
if(messages.length > 0) { | ||
showDwrMessages(messages); | ||
} else { | ||
let locator = {}; | ||
locator.slaveId = parseInt(slaveId); | ||
locator.range = parseInt(range); | ||
locator.modbusDataType = parseInt(modbusDataType); | ||
locator.offset = parseInt(offset); | ||
locator.bit = parseInt(bit); | ||
locator.registerCount = parseInt(registerCount); | ||
locator.charset = charset; | ||
locator.slaveId = parseInt(temp.slaveId); | ||
locator.range = parseInt(temp.range); | ||
locator.modbusDataType = parseInt(temp.modbusDataType); | ||
locator.offset = parseInt(temp.offset); | ||
locator.bit = parseInt(temp.bit); | ||
locator.registerCount = parseInt(temp.registerCount); | ||
locator.charset = temp.charset; | ||
|
||
locatorTestImpl(locator); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,13 +55,118 @@ | |
DataSourceEditDwr.testModbusIpData($get("timeout"), $get("retries"), $get("transportType"), $get("host"), | ||
$get("port"), $get("encapsulated"), slaveId, range, offset, length, dataTestCB); | ||
} | ||
|
||
function validateModbusProperties(temp){ | ||
|
||
let messages = []; | ||
|
||
if (!isPositiveInt(temp.updatePeriods)){ | ||
messages.push(createValidationMessage("updatePeriods", "<fmt:message key='badIntegerFormat'/>")); | ||
} | ||
|
||
if (!isPositiveInt(temp.updatePeriodType)){ | ||
messages.push(createValidationMessage("updatePeriodType", "<fmt:message key='badIntegerFormat'/>")); | ||
} | ||
|
||
if (!isPositiveInt(temp.timeout)){ | ||
messages.push(createValidationMessage("timeout", "<fmt:message key='badIntegerFormat'/>")); | ||
} | ||
|
||
if(!isPositiveInt(temp.retries)) { | ||
messages.push(createValidationMessage("retries", "<fmt:message key='badIntegerFormat'/>")); | ||
} | ||
|
||
if(!isPositiveInt(temp.maxReadBitCount)) { | ||
messages.push(createValidationMessage("maxReadBitCount", "<fmt:message key='badIntegerFormat'/>")); | ||
} | ||
|
||
if(!isPositiveInt(temp.maxReadRegisterCount)) { | ||
messages.push(createValidationMessage("maxReadRegisterCount", "<fmt:message key='badIntegerFormat'/>")); | ||
} | ||
|
||
if(!isPositiveInt(temp.maxWriteRegisterCount)) { | ||
messages.push(createValidationMessage("maxWriteRegisterCount", "<fmt:message key='badIntegerFormat'/>")); | ||
} | ||
|
||
if(!isPositiveInt(temp.port)) { | ||
messages.push(createValidationMessage("port", "<fmt:message key='badIntegerFormat'/>")); | ||
} | ||
|
||
return messages; | ||
} | ||
|
||
function createTempModbusData(){ | ||
|
||
let dataSourceName = $get("dataSourceName"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no point in creating additional variables here, you get and immediately set them in the temp structure, you don't parse here, etc. |
||
let dataSourceXid = $get("dataSourceXid"); | ||
let updatePeriods = $get("updatePeriods"); | ||
let updatePeriodType = $get("updatePeriodType"); | ||
let quantize = $get("quantize"); | ||
let timeout = $get("timeout"); | ||
let retries = $get("retries"); | ||
let contiguousBatches = $get("contiguousBatches"); | ||
let createSlaveMonitorPoints = $get("createSlaveMonitorPoints"); | ||
let maxReadBitCount = $get("maxReadBitCount"); | ||
let maxReadRegisterCount = $get("maxReadRegisterCount"); | ||
let maxWriteRegisterCount = $get("maxWriteRegisterCount"); | ||
let transportType = $get("transportType"); | ||
let host = $get("host"); | ||
let port = $get("port"); | ||
let encapsulated = $get("encapsulated"); | ||
let createSocketMonitorPoint = $get("createSocketMonitorPoint"); | ||
|
||
let temp = {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. temp -> modbus |
||
temp.dataSourceName = dataSourceName; | ||
temp.dataSourceXid = dataSourceXid; | ||
temp.updatePeriods = updatePeriods; | ||
temp.updatePeriodType = updatePeriodType; | ||
temp.quantize = quantize; | ||
temp.timeout = timeout; | ||
temp.retries = retries; | ||
temp.contiguousBatches = contiguousBatches; | ||
temp.createSlaveMonitorPoints = createSlaveMonitorPoints; | ||
temp.maxReadBitCount = maxReadBitCount; | ||
temp.maxReadRegisterCount = maxReadRegisterCount; | ||
temp.maxWriteRegisterCount = maxWriteRegisterCount; | ||
temp.transportType = transportType | ||
temp.host = host; | ||
temp.port = port; | ||
temp.encapsulated = encapsulated; | ||
temp.createSocketMonitorPoint = createSocketMonitorPoint; | ||
|
||
return temp; | ||
} | ||
|
||
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 = createTempModbusData(); | ||
|
||
let messages = validateModbusProperties(temp); | ||
|
||
if(messages.length > 0) { | ||
showDwrMessages(messages); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The formatting needs to be improved |
||
} 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> | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
temp -> locator