use of com.google.cloud.aiplatform.v1beta1.Dataset in project OpenMUC by isc-konstanz.
the class Iec62056Listener method newRecord.
private synchronized void newRecord(List<DataSet> dataSets, long time) {
List<ChannelRecordContainer> newContainers = new ArrayList<>();
for (ChannelRecordContainer container : containers) {
for (DataSet dataSet : dataSets) {
if (dataSet.getAddress().equals(container.getChannelAddress())) {
String value = dataSet.getValue();
if (value != null) {
try {
container.setRecord(new Record(new DoubleValue(Double.parseDouble(dataSet.getValue())), time));
newContainers.add(container);
} catch (NumberFormatException e) {
container.setRecord(new Record(new StringValue(dataSet.getValue()), time));
}
}
break;
}
}
}
listener.newRecords(newContainers);
}
use of com.google.cloud.aiplatform.v1beta1.Dataset in project OpenMUC by isc-konstanz.
the class IecConnection method scanForChannels.
@Override
public List<ChannelScanInfo> scanForChannels(int timeout) {
List<ChannelScanInfo> channelInfos = new LinkedList<>();
logger.debug("scanning channels");
try {
byte[] frame = receiver.receiveMessage(timeout);
ModeDMessage message = ModeDMessage.parse(frame);
List<String> dataSets = message.getDataSets();
for (String data : dataSets) {
DataSet dataSet = new DataSet(data);
String channelAddress = dataSet.getAddress();
String description = "Current value: " + dataSet.parseValueAsDouble() + dataSet.getUnit();
ValueType valueType = ValueType.DOUBLE;
Integer valueTypeLength = null;
Boolean readable = true;
Boolean writable = false;
ChannelScanInfo channelInfo = new ChannelScanInfo(channelAddress, description, valueType, valueTypeLength, readable, writable);
channelInfos.add(channelInfo);
}
} catch (ParseException | IOException e) {
logger.warn("read failed", e);
}
return channelInfos;
}
use of com.google.cloud.aiplatform.v1beta1.Dataset in project OpenMUC by isc-konstanz.
the class Iec62056Connection method read.
private List<DataSet> read(List<ChannelRecordContainer> containers) {
List<DataSet> dataSetsRet = new ArrayList<>();
DataMessage dataMessage;
for (int i = 0; i <= retries; ++i) {
try {
dataMessage = iec21Port.read();
List<DataSet> dataSets = dataMessage.getDataSets();
if (dataSetsRet != null) {
i = retries;
dataSetsRet = dataSets;
}
} catch (IOException e) {
if (i >= retries) {
for (ChannelRecordContainer container : containers) {
container.setRecord(new Record(Flag.DRIVER_ERROR_READ_FAILURE));
}
}
}
}
return dataSetsRet;
}
use of com.google.cloud.aiplatform.v1beta1.Dataset in project openhab1-addons by openhab.
the class Iec6205621MeterBinding method execute.
/**
* @{inheritDoc
*/
@Override
protected void execute() {
// the frequently executed code (polling) goes here ...
Map<String, Map<String, DataSet>> cache = new HashMap<String, Map<String, DataSet>>();
for (Iec6205621MeterBindingProvider provider : providers) {
for (String itemName : provider.getItemNames()) {
for (Entry<String, Meter> entry : meterDeviceConfigurtions.entrySet()) {
Meter reader = entry.getValue();
String meterName = provider.getMeterName(itemName);
if (meterName != null && meterName.equals(entry.getKey())) {
Map<String, DataSet> dataSets;
if ((dataSets = cache.get(meterName)) == null) {
if (logger.isDebugEnabled()) {
logger.debug("Read meter: {}; {}", meterName, reader.getConfig().getSerialPort());
}
dataSets = reader.read();
cache.put(meterName, dataSets);
}
String obis = provider.getObis(itemName);
if (obis != null && dataSets.containsKey(obis)) {
DataSet dataSet = dataSets.get(obis);
if (logger.isDebugEnabled()) {
logger.debug("Updating item {} with OBIS code {} and value {}", itemName, obis, dataSet.getValue());
}
Class<? extends Item> itemType = provider.getItemType(itemName);
if (itemType.isAssignableFrom(NumberItem.class)) {
eventPublisher.postUpdate(itemName, new DecimalType(dataSet.getValue()));
}
if (itemType.isAssignableFrom(StringItem.class)) {
String value = dataSet.getValue();
eventPublisher.postUpdate(itemName, new StringType(value));
}
}
}
}
}
}
}
use of com.google.cloud.aiplatform.v1beta1.Dataset in project Protocol-Adapter-IEC61850 by OSGP.
the class Iec61850ClientSSLDEventListener method newReport.
@Override
public void newReport(final Report report) {
final DateTime timeOfEntry = this.getTimeOfEntry(report);
final String reportDescription = this.getReportDescription(report, timeOfEntry);
this.logger.info("newReport for {}", reportDescription);
boolean skipRecordBecauseOfOldSqNum = false;
if (report.isBufOvfl()) {
this.logger.warn("Buffer Overflow reported for {} - entries within the buffer may have been lost.", reportDescription);
}
if (this.firstNewSqNum != null && report.getSqNum() != null && report.getSqNum() < this.firstNewSqNum) {
skipRecordBecauseOfOldSqNum = true;
}
this.logReportDetails(report);
final DataSet dataSet = report.getDataSet();
if (dataSet == null) {
this.logger.warn("No DataSet available for {}", reportDescription);
return;
}
final List<FcModelNode> members = dataSet.getMembers();
if (members == null || members.isEmpty()) {
this.logger.warn("No members in DataSet available for {}", reportDescription);
return;
} else {
this.logger.debug("Handling {} DataSet members for {}", members.size(), reportDescription);
}
for (final FcModelNode member : members) {
if (member == null) {
this.logger.warn("Member == null in DataSet for {}", reportDescription);
continue;
}
this.logger.info("Handle member {} for {}", member.getReference(), reportDescription);
try {
if (skipRecordBecauseOfOldSqNum) {
this.logger.warn("Skipping report because SqNum: {} is less than what should be the first new value: {}", report.getSqNum(), this.firstNewSqNum);
} else {
this.addEventNotificationForReportedData(member, timeOfEntry, reportDescription);
}
} catch (final Exception e) {
this.logger.error("Error adding event notification for member {} from {}", member.getReference(), reportDescription, e);
}
}
}
Aggregations