-
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
#2917 Added Point locator test fields validation in Modbus IP #2919
Conversation
Added integer/byte validation for fields: - slave ID (int) - offset (int) - bit (byte) - register count (int) inside point locator test for modbus ip data source.
WebContent/resources/common.js
Outdated
let num = Number(value); | ||
|
||
if (!isNaN(num) && Number.isInteger(num)) { | ||
if (num >= -128 && num <= 127) { |
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.
Can this be a negative value?
You always try to follow what already exists, look at how it works and what the isInt32 function checks. You're not reinventing the wheel.
} else if(!isValid($get("test_bit"))) { | ||
let bitMessage = createValidationMessage("test_bit", "<fmt:message key='badIntegerFormat'/>"); | ||
showDwrMessages([bitMessage]); | ||
} else if(!isByte($get("test_bit"))) { |
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.
If the value is a byte, it also meets the isValid condition.
In the function that checks isByte, you can first check whether isValid is present and then add a limit on the value.
- Small tweaks to isByte function
WebContent/resources/common.js
Outdated
@@ -1123,3 +1123,8 @@ function trim(value) { | |||
return result; | |||
} | |||
|
|||
function isByte(value) { | |||
let num = Number(value); |
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.
What happens if an alphanumeric character enters here?
let registerCountMessage = createValidationMessage("test_registerCount", "<fmt:message key='badIntegerFormat'/>"); | ||
showDwrMessages([registerCountMessage]); | ||
} else { | ||
var locator = {}; |
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.
let :)
- changed how variables are stored inside locatorTest() function - Added createAndDisplayValidationMessage function for showing validation message on chosen node
- Added catching exception for invalid end offset for Modbus IP data source
@@ -532,7 +532,10 @@ private void testModbusPointLocator(ModbusMaster modbusMaster, | |||
} catch (IllegalCharsetNameException e) { | |||
response.addMessage(new LocalizableMessage( | |||
"validate.invalidCharset")); | |||
} finally { | |||
} catch (ModbusIdException e) { |
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.
Exception
let locator = {}; | ||
locator.slaveId = parseInt(slaveId); | ||
locator.range = range | ||
locator.modbusDataType = modbusDataType; |
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.
Aren't modbusDataType and range numeric types?
- Minor changes
- Added Modbus IP properties fields validation for integers - Changed validation mechanism
- Added validateValue() function for shorter code
|
||
locatorTestImpl(locator); | ||
|
||
let temp = createTempLocator(); |
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.
createLocatorConfigTemp
locatorTestImpl(locator); | ||
|
||
let temp = createTempLocator(); | ||
let tempModbusData = createTempModbusData(); |
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.
createModbusConfigTemp
|
||
function createTempModbusData(){ | ||
|
||
let dataSourceName = $get("dataSourceName"); |
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.
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 messages = validateModbusProperties(temp); | ||
|
||
if(messages.length > 0) { | ||
showDwrMessages(messages); |
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.
The formatting needs to be improved
hideContextualMessages("locatorTestDiv"); | ||
hideContextualMessages("dataSourceProperties"); | ||
|
||
let messagesModbus = validateModbusProperties(tempModbusData); |
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.
modbusMessages, validateModbusConfig
@@ -65,20 +65,80 @@ | |||
setDisabled("scanBtn", scanning); | |||
setDisabled("scanCancelBtn", !scanning); | |||
} | |||
|
|||
function validateLocatorTest(temp){ |
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
let encapsulated = $get("encapsulated"); | ||
let createSocketMonitorPoint = $get("createSocketMonitorPoint"); | ||
|
||
let temp = {}; |
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 -> modbus
- Variables names changes
- Fixed formatting
…est_fields_validation_in_Modbus_IP
} | ||
|
||
function createLocatorConfigTemp(){ | ||
let slaveId = $get("test_slaveId"); |
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.
Similarly to the previously submitted suggestion, this is unnecessary.
You should apply a given note to all changes you make so that you don't have to point out the same things one after the other.
- Optimized createLocatorConfigTemp() code
locator.charset = $get("test_charset"); | ||
|
||
locatorTestImpl(locator); | ||
setDisabled("locatorTestBtn", true); |
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.
You need to remove this line:
let messages = validateModbusConfig(temp); | ||
|
||
if(messages.length > 0) { | ||
showDwrMessages(messages); |
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.
stopImageFader("dsSaveImg");
let messages = modbusMessages.concat(messagesLocator); | ||
|
||
if(messages.length > 0) { | ||
showDwrMessages(messages); |
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.
stopImageFader("dsSaveImg");
- Added stopImageFader("dsSaveImg")
- Added validation for Modbus read data table
Added integer/byte validation for fields:
inside point locator test for modbus ip data source.