-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1980 arrays are not supported for s7 plcs (#2121)
* feat(#1980): Add advanced code block option to S7 adapter configuration * feat(#1980): Support advanced register input mode for plc s7 adapter * feat(#1980): Add array support for S7 PLC registers * Add migration, move S7 and modbus adapter to connectors-plc module * Fix checkstyle --------- Co-authored-by: Philipp Zehnder <[email protected]>
- Loading branch information
1 parent
2a7ac3f
commit 2c60d52
Showing
20 changed files
with
608 additions
and
105 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
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
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
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,81 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ 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 | ||
~ | ||
~ http://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. | ||
~ | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.apache.streampipes</groupId> | ||
<artifactId>streampipes-extensions</artifactId> | ||
<version>0.93.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>streampipes-connectors-plc</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.streampipes</groupId> | ||
<artifactId>streampipes-extensions-api</artifactId> | ||
<version>0.93.0-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.streampipes</groupId> | ||
<artifactId>streampipes-extensions-management</artifactId> | ||
<version>0.93.0-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.streampipes</groupId> | ||
<artifactId>streampipes-sdk</artifactId> | ||
<version>0.93.0-SNAPSHOT</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.plc4x</groupId> | ||
<artifactId>plc4j-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.plc4x</groupId> | ||
<artifactId>plc4j-connection-pool</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.plc4x</groupId> | ||
<artifactId>plc4j-driver-s7</artifactId> | ||
<scope>runtime</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>com.fasterxml.woodstox</groupId> | ||
<artifactId>woodstox-core</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.plc4x</groupId> | ||
<artifactId>plc4j-driver-modbus</artifactId> | ||
<scope>runtime</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
87 changes: 87 additions & 0 deletions
87
...he/streampipes/extensions/connectors/plc/adapter/migration/Plc4xS7AdapterMigrationV1.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,87 @@ | ||
/* | ||
* 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 | ||
* | ||
* http://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.streampipes.extensions.connectors.plc.adapter.migration; | ||
|
||
import org.apache.streampipes.extensions.api.extractor.IStaticPropertyExtractor; | ||
import org.apache.streampipes.extensions.api.migration.IAdapterMigrator; | ||
import org.apache.streampipes.model.connect.adapter.AdapterDescription; | ||
import org.apache.streampipes.model.extensions.svcdiscovery.SpServiceTagPrefix; | ||
import org.apache.streampipes.model.migration.MigrationResult; | ||
import org.apache.streampipes.model.migration.ModelMigratorConfig; | ||
import org.apache.streampipes.model.staticproperty.CollectionStaticProperty; | ||
import org.apache.streampipes.model.staticproperty.StaticProperty; | ||
import org.apache.streampipes.sdk.StaticProperties; | ||
import org.apache.streampipes.sdk.helpers.Alternatives; | ||
import org.apache.streampipes.sdk.helpers.CodeLanguage; | ||
import org.apache.streampipes.sdk.helpers.Labels; | ||
|
||
import java.util.List; | ||
|
||
import static org.apache.streampipes.extensions.connectors.plc.adapter.s7.Plc4xS7Adapter.CODE_TEMPLATE; | ||
import static org.apache.streampipes.extensions.connectors.plc.adapter.s7.Plc4xS7Adapter.PLC_CODE_BLOCK; | ||
import static org.apache.streampipes.extensions.connectors.plc.adapter.s7.Plc4xS7Adapter.PLC_NODES; | ||
import static org.apache.streampipes.extensions.connectors.plc.adapter.s7.Plc4xS7Adapter.PLC_NODE_INPUT_ALTERNATIVES; | ||
import static org.apache.streampipes.extensions.connectors.plc.adapter.s7.Plc4xS7Adapter.PLC_NODE_INPUT_CODE_BLOCK_ALTIVE; | ||
import static org.apache.streampipes.extensions.connectors.plc.adapter.s7.Plc4xS7Adapter.PLC_NODE_INPUT_COLLECTION_ALTERNATIVE; | ||
|
||
public class Plc4xS7AdapterMigrationV1 implements IAdapterMigrator { | ||
@Override | ||
public ModelMigratorConfig config() { | ||
return new ModelMigratorConfig( | ||
"org.apache.streampipes.connect.iiot.adapters.plc4x.s7", | ||
SpServiceTagPrefix.ADAPTER, | ||
0, | ||
1 | ||
); | ||
} | ||
|
||
@Override | ||
public MigrationResult<AdapterDescription> migrate(AdapterDescription element, | ||
IStaticPropertyExtractor extractor) throws RuntimeException { | ||
var newConfigs = new java.util.ArrayList<>(element.getConfig().stream().map(config -> { | ||
if (isCollectionConfig(config)) { | ||
return modifyCollection((CollectionStaticProperty) config); | ||
} else { | ||
return config; | ||
} | ||
}).toList()); | ||
|
||
newConfigs.removeIf(c -> c.getInternalName().equals(PLC_NODES)); | ||
element.setConfig(newConfigs); | ||
|
||
return MigrationResult.success(element); | ||
} | ||
|
||
private StaticProperty modifyCollection(CollectionStaticProperty collectionConfig) { | ||
|
||
var alternatives = List.of( | ||
Alternatives.from(Labels.withId(PLC_NODE_INPUT_COLLECTION_ALTERNATIVE), | ||
collectionConfig, | ||
true), | ||
Alternatives.from(Labels.withId(PLC_NODE_INPUT_CODE_BLOCK_ALTIVE), | ||
StaticProperties.codeStaticProperty(Labels.withId(PLC_CODE_BLOCK), CodeLanguage.None, CODE_TEMPLATE)) | ||
); | ||
|
||
return StaticProperties.alternatives(Labels.withId(PLC_NODE_INPUT_ALTERNATIVES), alternatives); | ||
} | ||
|
||
private boolean isCollectionConfig(StaticProperty config) { | ||
return config.getInternalName().equals(PLC_NODES); | ||
} | ||
} |
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
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
Oops, something went wrong.