-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plc4j/api): Added a getArrayInfo() method to the PlcBrowseItem t…
…o provide information over array dimensions.
- Loading branch information
Showing
6 changed files
with
237 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcBrowseItemArrayInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.plc4x.java.api.messages; | ||
|
||
public interface PlcBrowseItemArrayInfo { | ||
|
||
/** | ||
* @return returns the size of the array | ||
*/ | ||
default long getSize() { | ||
return getUpperBound() - getLowerBound(); | ||
} | ||
|
||
/** | ||
* @return returns the lower bound of the array | ||
*/ | ||
long getLowerBound(); | ||
|
||
/** | ||
* @return returns the upper bound of the array | ||
*/ | ||
long getUpperBound(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultBrowseItemArrayInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.plc4x.java.spi.messages; | ||
|
||
import org.apache.plc4x.java.api.messages.PlcBrowseItemArrayInfo; | ||
|
||
public class DefaultBrowseItemArrayInfo implements PlcBrowseItemArrayInfo { | ||
|
||
private final long lowerBound; | ||
private final long upperBound; | ||
|
||
public DefaultBrowseItemArrayInfo(long lowerBound, long upperBound) { | ||
this.lowerBound = lowerBound; | ||
this.upperBound = upperBound; | ||
} | ||
|
||
@Override | ||
public long getLowerBound() { | ||
return lowerBound; | ||
} | ||
|
||
@Override | ||
public long getUpperBound() { | ||
return upperBound; | ||
} | ||
|
||
} |
90 changes: 90 additions & 0 deletions
90
plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultListPlcBrowseItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.plc4x.java.spi.messages; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
import org.apache.plc4x.java.api.messages.PlcBrowseItem; | ||
import org.apache.plc4x.java.api.messages.PlcBrowseItemArrayInfo; | ||
import org.apache.plc4x.java.api.types.PlcValueType; | ||
import org.apache.plc4x.java.api.value.PlcValue; | ||
import org.apache.plc4x.java.spi.generation.SerializationException; | ||
import org.apache.plc4x.java.spi.generation.WriteBuffer; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "className") | ||
public class DefaultListPlcBrowseItem extends DefaultPlcBrowseItem { | ||
|
||
private final List<PlcBrowseItemArrayInfo> arrayInfo; | ||
|
||
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES) | ||
public DefaultListPlcBrowseItem(@JsonProperty("address") String address, | ||
@JsonProperty("name") String name, | ||
@JsonProperty("dataType") PlcValueType dataType, | ||
@JsonProperty("arrayInfo") List<PlcBrowseItemArrayInfo> arrayInfo, | ||
@JsonProperty("readable") boolean readable, | ||
@JsonProperty("writable") boolean writable, | ||
@JsonProperty("subscribable") boolean subscribable, | ||
@JsonProperty("children") List<PlcBrowseItem> children, | ||
@JsonProperty("options") Map<String, PlcValue> options) { | ||
super(address, name, dataType, readable, writable, subscribable, children, options); | ||
this.arrayInfo = arrayInfo; | ||
} | ||
|
||
@Override | ||
public List<PlcBrowseItemArrayInfo> getArrayInfo() { | ||
return arrayInfo; | ||
} | ||
|
||
@Override | ||
public void serialize(WriteBuffer writeBuffer) throws SerializationException { | ||
writeBuffer.pushContext(getClass().getSimpleName()); | ||
writeBuffer.writeString("address", getAddress().getBytes(StandardCharsets.UTF_8).length * 8, StandardCharsets.UTF_8.name(), getAddress()); | ||
writeBuffer.writeString("name", getName().getBytes(StandardCharsets.UTF_8).length * 8, StandardCharsets.UTF_8.name(), getName()); | ||
// TODO: Find out how to serialize an enum. | ||
//writeBuffer.writeString("dataType", dataType.getBytes(StandardCharsets.UTF_8).length * 8, StandardCharsets.UTF_8.name(), dataType); | ||
if(getChildren() != null && !getChildren().isEmpty()) { | ||
writeBuffer.pushContext("children"); | ||
for (PlcBrowseItem child : getChildren()) { | ||
writeBuffer.pushContext("child"); | ||
((DefaultListPlcBrowseItem) child).serialize(writeBuffer); | ||
writeBuffer.popContext("child"); | ||
} | ||
writeBuffer.popContext("children"); | ||
} | ||
if(getOptions() != null && !getOptions().isEmpty()) { | ||
writeBuffer.pushContext("options"); | ||
for (Map.Entry<String, PlcValue> optionEntry : getOptions().entrySet()) { | ||
writeBuffer.pushContext("option"); | ||
writeBuffer.writeString("name", optionEntry.getKey().getBytes(StandardCharsets.UTF_8).length * 8, StandardCharsets.UTF_8.name(), optionEntry.getKey()); | ||
// TODO: Find out how to serialize a PlcValue | ||
//writeBuffer.writeString("value", optionEntry.getValue().getBytes(StandardCharsets.UTF_8).length * 8, StandardCharsets.UTF_8.name(), optionEntry.getValue()); | ||
((DefaultListPlcBrowseItem) optionEntry).serialize(writeBuffer); | ||
writeBuffer.popContext("option"); | ||
} | ||
writeBuffer.popContext("options"); | ||
} | ||
writeBuffer.popContext(getClass().getSimpleName()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters