feat(ft546): collect bounded read-only shadow facts
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
package com.ruoyi.shadow.facts;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public final class ShadowLegacyQueueResult {
|
||||
public enum Status { AVAILABLE, LEGACY_RESULT_UNAVAILABLE }
|
||||
public enum DataType { INT16, INT32 }
|
||||
|
||||
private final Status status;
|
||||
private final String reasonCode;
|
||||
private final List<LegacyRegisterWrite> writes;
|
||||
|
||||
private ShadowLegacyQueueResult(Status status, String reasonCode,
|
||||
List<LegacyRegisterWrite> writes) {
|
||||
this.status = status;
|
||||
this.reasonCode = reasonCode;
|
||||
this.writes = Collections.unmodifiableList(
|
||||
new ArrayList<LegacyRegisterWrite>(writes));
|
||||
}
|
||||
|
||||
public static ShadowLegacyQueueResult available(
|
||||
List<LegacyRegisterWrite> writes) {
|
||||
return new ShadowLegacyQueueResult(Status.AVAILABLE,
|
||||
"LEGACY_RESULT_AVAILABLE", writes);
|
||||
}
|
||||
|
||||
public static ShadowLegacyQueueResult unavailable(String missing) {
|
||||
return new ShadowLegacyQueueResult(Status.LEGACY_RESULT_UNAVAILABLE,
|
||||
"LEGACY_RESULT_UNAVAILABLE:" + missing,
|
||||
Collections.<LegacyRegisterWrite>emptyList());
|
||||
}
|
||||
|
||||
public Status getStatus() { return status; }
|
||||
public String getReasonCode() { return reasonCode; }
|
||||
public List<LegacyRegisterWrite> getWrites() { return writes; }
|
||||
|
||||
public String getWriteAddresses() {
|
||||
StringBuilder addresses = new StringBuilder();
|
||||
for (LegacyRegisterWrite write : writes) {
|
||||
if (addresses.length() > 0) {
|
||||
addresses.append(',');
|
||||
}
|
||||
addresses.append(write.getAddress());
|
||||
}
|
||||
return addresses.toString();
|
||||
}
|
||||
|
||||
public LegacyRegisterWrite write(String address) {
|
||||
for (LegacyRegisterWrite write : writes) {
|
||||
if (write.getAddress().equals(address)) {
|
||||
return write;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final class LegacyRegisterWrite {
|
||||
private final String address;
|
||||
private final DataType dataType;
|
||||
private final List<Integer> values;
|
||||
private final int writeSequence;
|
||||
private final boolean trigger;
|
||||
|
||||
LegacyRegisterWrite(String address, DataType dataType,
|
||||
List<Integer> values, int writeSequence,
|
||||
boolean trigger) {
|
||||
this.address = address;
|
||||
this.dataType = dataType;
|
||||
this.values = Collections.unmodifiableList(
|
||||
new ArrayList<Integer>(values));
|
||||
this.writeSequence = writeSequence;
|
||||
this.trigger = trigger;
|
||||
}
|
||||
|
||||
public String getAddress() { return address; }
|
||||
public DataType getDataType() { return dataType; }
|
||||
public List<Integer> getValues() { return values; }
|
||||
public int getWriteSequence() { return writeSequence; }
|
||||
public boolean isTrigger() { return trigger; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user