Skip to content

Commit

Permalink
Merge pull request #3079 from SCADA-LTS/feature/#3035_Import_all_info…
Browse files Browse the repository at this point in the history
…rmations_from_the_Bacnet_Object_list1

#3035 Import all informations from the Bacnet Object list
  • Loading branch information
Limraj authored Feb 21, 2025
2 parents 9ec655d + 9caa3b9 commit 16f0307
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 23 deletions.
2 changes: 1 addition & 1 deletion WebContent/WEB-INF/dwr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
<convert converter="bean" match="com.serotonin.mango.vo.publish.persistent.*"/>
<convert converter="bean" match="com.serotonin.mango.vo.report.*"/>
<convert converter="xssDataPointVoConverter" match="com.serotonin.mango.vo.DataPointVO">
<param name="include" value="id,xid,name,extendedName,dataSourceId,enabled,dataTypeMessage,pointLocator"/>
<param name="include" value="id,xid,name,extendedName,dataSourceId,enabled,dataTypeMessage,pointLocator,engineeringUnits"/>
</convert>
<convert converter="xssDataPointBeanConverter" match="com.serotonin.mango.web.dwr.beans.DataPointBean">
<param name="include" value="id,xid,name,settable,dataType,dataTypeMessage,chartColour"/>
Expand Down
3 changes: 2 additions & 1 deletion WebContent/WEB-INF/jsp/dataSourceEdit/editBacnetIp.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,9 @@
locator.settable = $get("settable");
locator.writePriority = $get("writePriority");
locator.dataTypeId = $get("dataTypeId");
console.log("point.engineeringUnits: " + currentPoint.engineeringUnits);
DataSourceEditDwr.saveBACnetIPPointLocator(currentPoint.id, $get("xid"), $get("name"), locator, savePointCB);
DataSourceEditDwr.saveBACnetIPPointLocator(currentPoint.id, $get("xid"), $get("name"), currentPoint.engineeringUnits, locator, savePointCB);
}
function objectTypeChanged() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public BACnetIPDataSourceVO() {
// Create a local device object from which to get default values.
LocalDevice localDevice = new LocalDevice(0, null);
broadcastAddress = "255.255.255.255";
port = localDevice.getPort();
port = 0;
timeout = localDevice.getTimeout();
segTimeout = localDevice.getSegTimeout();
segWindow = localDevice.getSegWindow();
Expand Down
53 changes: 34 additions & 19 deletions src/com/serotonin/mango/web/dwr/DataSourceEditDwr.java
Original file line number Diff line number Diff line change
Expand Up @@ -339,28 +339,13 @@ private DataPointVO getPoint(int pointId, DataPointDefaulter defaulter) {
private DwrResponseI18n validatePoint(int id, String xid, String name,
PointLocatorVO locator, DataPointDefaulter defaulter) {
Permissions.ensureAdmin();
DwrResponseI18n response = new DwrResponseI18n();

DataPointVO dp = getPoint(id, defaulter);
dp.setXid(xid);
dp.setName(name);
dp.setPointLocator(locator);

DataPointService dataPointService = new DataPointService();
validateXid(response, dataPointService::isXidUnique, xid, id);

if (StringUtils.isEmpty(name))
response.addContextualMessage("name", "dsEdit.validate.required");

locator.validate(response, dp.getId());

if (!response.getHasMessages()) {
Common.ctx.getRuntimeManager().saveDataPoint(dp);
response.addData("id", dp.getId());
response.addData("points", getPoints());
}

return response;
return validateAndSaveDataPoint(dp);
}

//
Expand Down Expand Up @@ -1237,9 +1222,17 @@ public DwrResponseI18n saveBACnetIpDataSource(String name, String xid,
}


public DwrResponseI18n saveBACnetIPPointLocator(int id, String xid,
String name, BACnetIPPointLocatorVO locator) {
return validatePoint(id, xid, name, locator, null);
public DwrResponseI18n saveBACnetIPPointLocator(int id, String xid, String name, int engineeringUnits,
BACnetIPPointLocatorVO locator) {
Permissions.ensureAdmin();

DataPointVO dp = getPoint(id, null);
dp.setXid(xid);
dp.setName(name);
dp.setPointLocator(locator);
dp.setEngineeringUnits(engineeringUnits);

return validateAndSaveDataPoint(dp);
}


Expand Down Expand Up @@ -1348,6 +1341,7 @@ public DataPointVO addBacnetPoint(String ip, int port, int networkNumber,
BACnetIPPointLocatorVO locator = dp.getPointLocator();

dp.setName(bean.getObjectName());
dp.setEngineeringUnits(bean.getEngineeringUnitValue());

// Default some of the locator values.
locator.setRemoteDeviceIp(ip);
Expand Down Expand Up @@ -3115,4 +3109,25 @@ private DwrResponseI18n validateMultipleOpcUaPoints(OpcUaPointLocatorVO[] locato
}
return response;
}

public DwrResponseI18n validateAndSaveDataPoint(DataPointVO dp) {
Permissions.ensureAdmin();
DwrResponseI18n response = new DwrResponseI18n();
DataPointService dataPointService = new DataPointService();
validateXid(response, dataPointService::isXidUnique, dp.getXid(), dp.getId());

if (StringUtils.isEmpty(dp.getName()))
response.addContextualMessage("name", "dsEdit.validate.required");

PointLocatorVO locator = dp.getPointLocator();
locator.validate(response, dp.getId());

if (!response.getHasMessages()) {
Common.ctx.getRuntimeManager().saveDataPoint(dp);
response.addData("id", dp.getId());
response.addData("points", getPoints());
}

return response;
}
}
10 changes: 9 additions & 1 deletion src/com/serotonin/mango/web/dwr/beans/BACnetDiscovery.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Map;
import java.util.ResourceBundle;

import com.serotonin.bacnet4j.type.enumerated.EngineeringUnits;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

Expand Down Expand Up @@ -281,8 +282,15 @@ else if (ObjectType.multiStateInput.equals(oid.getObjectType())
bean.setObjectName(values.getString(oid, pid));
else if (pid.equals(PropertyIdentifier.presentValue))
bean.setPresentValue(values.getString(oid, pid));
else if (pid.equals(PropertyIdentifier.units))
else if (pid.equals(PropertyIdentifier.units)) {
bean.getUnitsDescription().add(values.getString(oid, pid));

Encodable e = values.getNullOnError(oid, pid);
if (e instanceof EngineeringUnits) {
EngineeringUnits engineeringUnits = (EngineeringUnits) e;
bean.setEngineeringUnitValue(engineeringUnits.intValue());
}
}
else if (pid.equals(PropertyIdentifier.inactiveText)) {
Encodable e = values.getNullOnError(oid, pid);
bean.getUnitsDescription().set(0, e == null ? "0" : e.toString());
Expand Down
10 changes: 10 additions & 0 deletions src/com/serotonin/mango/web/dwr/beans/BACnetObjectBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class BACnetObjectBean {
private int dataTypeId;
private List<String> unitsDescription = new ArrayList<String>();

private int engineeringUnitValue;

public String getPrettyPresentValue() {
if (objectTypeId == ObjectType.binaryInput.intValue() || objectTypeId == ObjectType.binaryOutput.intValue()
|| objectTypeId == ObjectType.binaryValue.intValue()) {
Expand Down Expand Up @@ -138,4 +140,12 @@ public boolean isCov() {
public void setCov(boolean cov) {
this.cov = cov;
}

public int getEngineeringUnitValue() {
return engineeringUnitValue;
}

public void setEngineeringUnitValue(int engineeringUnitValue) {
this.engineeringUnitValue = engineeringUnitValue;
}
}

0 comments on commit 16f0307

Please sign in to comment.