-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(asset.provider): Now the DataType sent to the driver depends on …
…the DataType of the channel and theDataType of the scaleOffsetDataType field and a new ScaleOffsetDataType, LONG, has been added [backport release-5.6.0] (#5440) * feat(asset.provider): Now the DataType sent to the driver depends on the DataType of the channel and theDataType of the scaleOffsetDataType field and a new ScaleOffsetDataType, LONG, has been added (#5432) * Now a dependent datatype is forwarded to the driver * fixed test * Added test for ChannelRecordHelper * Added test for dynamic valuetype * little code cleanup * Fixed bug on Long scale/offset * Fixed wrong import (cherry picked from commit bda665c) * Added copyright header * Updated Copyright year. --------- Co-authored-by: Salvatore Coppola <[email protected]> Co-authored-by: Salvatore Coppola <[email protected]>
- Loading branch information
1 parent
a4940f2
commit 6e5c879
Showing
9 changed files
with
271 additions
and
73 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
57 changes: 57 additions & 0 deletions
57
...er/src/main/java/org/eclipse/kura/internal/asset/provider/helper/ChannelRecordHelper.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,57 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Eurotech and/or its affiliates and others | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Eurotech | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.kura.internal.asset.provider.helper; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.eclipse.kura.asset.provider.AssetConstants; | ||
import org.eclipse.kura.channel.Channel; | ||
import org.eclipse.kura.channel.ChannelRecord; | ||
import org.eclipse.kura.channel.ScaleOffsetType; | ||
import org.eclipse.kura.type.DataType; | ||
|
||
public class ChannelRecordHelper { | ||
|
||
private ChannelRecordHelper() { | ||
// Private constructor to prevent instantiation | ||
} | ||
|
||
public static ChannelRecord createModifiedChannelRecord(Channel channel) { | ||
|
||
DataType actualDataType = channel.getScaleOffsetType() == ScaleOffsetType.DEFINED_BY_VALUE_TYPE | ||
? channel.getValueType() | ||
: toDataType(channel.getScaleOffsetType()); | ||
|
||
ChannelRecord channelRecord = ChannelRecord.createReadRecord(channel.getName(), actualDataType, | ||
channel.getUnit()); | ||
|
||
Map<String, Object> configMap = new HashMap<>(channel.getConfiguration()); | ||
configMap.put(AssetConstants.VALUE_TYPE.value(), actualDataType.name()); | ||
channelRecord.setChannelConfig(configMap); | ||
|
||
return channelRecord; | ||
} | ||
|
||
private static DataType toDataType(ScaleOffsetType scaleOffsetType) { | ||
switch (scaleOffsetType) { | ||
case DOUBLE: | ||
return DataType.DOUBLE; | ||
case LONG: | ||
return DataType.LONG; | ||
default: | ||
throw new IllegalArgumentException("Unsupported scale offset type: " + scaleOffsetType); | ||
} | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...st/src/main/java/org/eclipse/kura/asset/provider/helper/test/ChannelRecordHelperTest.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,76 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Eurotech and/or its affiliates and others | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Eurotech | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.kura.asset.provider.helper.test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.util.Collections; | ||
|
||
import org.eclipse.kura.channel.Channel; | ||
import org.eclipse.kura.channel.ChannelRecord; | ||
import org.eclipse.kura.channel.ChannelType; | ||
import org.eclipse.kura.channel.ScaleOffsetType; | ||
import org.eclipse.kura.internal.asset.provider.helper.ChannelRecordHelper; | ||
import org.eclipse.kura.type.DataType; | ||
import org.junit.Test; | ||
|
||
public class ChannelRecordHelperTest { | ||
|
||
private Channel channel; | ||
private ChannelRecord channelRecord; | ||
|
||
@Test | ||
public void shouldCreateChannelRecorWithDoubleValueType() { | ||
givenChannel(new Channel("test-channel", ChannelType.READ, DataType.INTEGER, ScaleOffsetType.DOUBLE, 3.3d, 3.1d, | ||
Collections.emptyMap())); | ||
|
||
whenCreatedChannelRecord(); | ||
|
||
thenChannelRecordValueTypeIs(DataType.DOUBLE); | ||
} | ||
|
||
@Test | ||
public void shouldCreateChannelRecorWithIntegerValueType() { | ||
givenChannel(new Channel("test-channel", ChannelType.READ, DataType.INTEGER, | ||
ScaleOffsetType.DEFINED_BY_VALUE_TYPE, 3.3d, 3.1d, Collections.emptyMap())); | ||
|
||
whenCreatedChannelRecord(); | ||
|
||
thenChannelRecordValueTypeIs(DataType.INTEGER); | ||
} | ||
|
||
@Test | ||
public void shouldCreateChannelRecorWithLongValueType() { | ||
givenChannel(new Channel("test-channel", ChannelType.READ, DataType.INTEGER, ScaleOffsetType.LONG, 3l, 4l, | ||
Collections.emptyMap())); | ||
|
||
whenCreatedChannelRecord(); | ||
|
||
thenChannelRecordValueTypeIs(DataType.LONG); | ||
} | ||
|
||
private void thenChannelRecordValueTypeIs(DataType datatype) { | ||
assertEquals(datatype, this.channelRecord.getValueType()); | ||
|
||
} | ||
|
||
private void givenChannel(Channel channel) { | ||
this.channel = channel; | ||
|
||
} | ||
|
||
private void whenCreatedChannelRecord() { | ||
this.channelRecord = ChannelRecordHelper.createModifiedChannelRecord(this.channel); | ||
} | ||
} |
Oops, something went wrong.