-
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.
fix: Fixed asset scale and offset not being applied in listen mode [b…
…ackport release-5.3.0] (#4738) * fix: Fixed asset scale and offset not being applied in listen mode (#4736) * fix: Fixed asset scale and offset not being applied in listen mode Signed-off-by: Nicola Timeus <[email protected]> * Compute scale and offset only if needed Signed-off-by: Nicola Timeus <[email protected]> --------- Signed-off-by: Nicola Timeus <[email protected]> (cherry picked from commit f1973d9) * chore: Updated version in kura.build.properties Signed-off-by: MMaiero <[email protected]> * Updated wire.component.provider version in kura.properties --------- Signed-off-by: MMaiero <[email protected]> Co-authored-by: nicolatimeus <[email protected]> Co-authored-by: MMaiero <[email protected]>
- Loading branch information
1 parent
39a2d18
commit 65d08f1
Showing
9 changed files
with
728 additions
and
416 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
190 changes: 122 additions & 68 deletions
190
....eclipse.kura.asset.provider/src/main/java/org/eclipse/kura/asset/provider/BaseAsset.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
140 changes: 140 additions & 0 deletions
140
...ent.provider.test/src/main/java/org/eclipse/kura/internal/wire/asset/test/MockDriver.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,140 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022, 2023 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.wire.asset.test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.Optional; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import org.eclipse.kura.channel.ChannelFlag; | ||
import org.eclipse.kura.channel.ChannelRecord; | ||
import org.eclipse.kura.channel.ChannelStatus; | ||
import org.eclipse.kura.channel.listener.ChannelEvent; | ||
import org.eclipse.kura.channel.listener.ChannelListener; | ||
import org.eclipse.kura.driver.ChannelDescriptor; | ||
import org.eclipse.kura.driver.Driver; | ||
import org.eclipse.kura.driver.PreparedRead; | ||
import org.eclipse.kura.type.TypedValue; | ||
|
||
class MockDriver implements Driver { | ||
|
||
private final Map<String, List<TypedValue<?>>> values = new HashMap<>(); | ||
final Map<String, ChannelListener> listeners = new HashMap<>(); | ||
CompletableFuture<Void> preparedReadCalled = new CompletableFuture<>(); | ||
|
||
@Override | ||
public void connect() throws ConnectionException { | ||
} | ||
|
||
@Override | ||
public void disconnect() throws ConnectionException { | ||
} | ||
|
||
@Override | ||
public ChannelDescriptor getChannelDescriptor() { | ||
|
||
return new ChannelDescriptor() { | ||
|
||
@Override | ||
public Object getDescriptor() { | ||
return Collections.emptyList(); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public void read(List<ChannelRecord> records) throws ConnectionException { | ||
for (final ChannelRecord record : records) { | ||
final Optional<TypedValue<?>> value = Optional.ofNullable(values.get(record.getChannelName())) | ||
.flatMap(l -> { | ||
if (l.isEmpty()) { | ||
return Optional.empty(); | ||
} else { | ||
return Optional.of(l.remove(0)); | ||
} | ||
}); | ||
|
||
if (value.isPresent()) { | ||
record.setChannelStatus(new ChannelStatus(ChannelFlag.SUCCESS)); | ||
record.setValue(value.get()); | ||
} else { | ||
record.setChannelStatus(new ChannelStatus(ChannelFlag.FAILURE)); | ||
} | ||
|
||
record.setTimestamp(System.currentTimeMillis()); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public synchronized void registerChannelListener(Map<String, Object> channelConfig, ChannelListener listener) | ||
throws ConnectionException { | ||
synchronized (listeners) { | ||
listeners.put((String) channelConfig.get("+name"), listener); | ||
listeners.notifyAll(); | ||
} | ||
} | ||
|
||
@Override | ||
public void unregisterChannelListener(ChannelListener listener) throws ConnectionException { | ||
synchronized (listeners) { | ||
final Iterator<Entry<String, ChannelListener>> iter = listeners.entrySet().iterator(); | ||
|
||
while (iter.hasNext()) { | ||
final Entry<String, ChannelListener> e = iter.next(); | ||
|
||
if (e.getValue() == listener) { | ||
iter.remove(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void write(List<ChannelRecord> records) throws ConnectionException { | ||
} | ||
|
||
synchronized void addReadResult(final String channelName, final TypedValue<?> value) { | ||
this.values.computeIfAbsent(channelName, a -> new ArrayList<>()).add(value); | ||
} | ||
|
||
synchronized void emitChannelEvent(final String channelName, final TypedValue<?> value) { | ||
for (final Entry<String, ChannelListener> e : listeners.entrySet()) { | ||
|
||
if (!e.getKey().equals(channelName)) { | ||
continue; | ||
} | ||
|
||
final ChannelRecord record = ChannelRecord.createReadRecord(channelName, value.getType()); | ||
record.setValue(value); | ||
record.setChannelStatus(new ChannelStatus(ChannelFlag.SUCCESS)); | ||
record.setTimestamp(System.currentTimeMillis()); | ||
|
||
e.getValue().onChannelEvent(new ChannelEvent(record)); | ||
} | ||
} | ||
|
||
@Override | ||
public PreparedRead prepareRead(List<ChannelRecord> records) { | ||
preparedReadCalled.complete(null); | ||
|
||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
} |
Oops, something went wrong.