Search in sources :

Example 1 with BigDecimalDataBlock

use of net.sf.mbus4j.dataframes.datablocks.BigDecimalDataBlock in project ma-modules-public by infiniteautomation.

the class MBusDataSourceRT method setValue.

protected boolean setValue(DataBlock db, boolean pointError, long time, DataPointRT point, final MBusPointLocatorRT locatorRT, final MBusPointLocatorVO locatorVo) {
    try {
        if ((db instanceof BcdValue) && ((BcdValue) db).isBcdError()) {
            pointError = true;
            LOG.fatal("BCD Error : " + ((BcdValue) db).getBcdError());
            raiseEvent(POINT_READ_EXCEPTION_EVENT, time, true, new TranslatableMessage("event.exception2", point.getVO().getExtendedName(), "BCD error value: " + ((BcdValue) db).getBcdError()));
            pointError = true;
        } else if (db instanceof ByteDataBlock) {
            point.updatePointValue(new PointValueTime(locatorRT.calcCorrectedValue(((ByteDataBlock) db).getValue(), db.getCorrectionExponent(locatorVo.effectiveSiPrefix()), db.getCorrectionConstant()), time));
        } else if (db instanceof ShortDataBlock) {
            point.updatePointValue(new PointValueTime(locatorRT.calcCorrectedValue(((ShortDataBlock) db).getValue(), db.getCorrectionExponent(locatorVo.effectiveSiPrefix()), db.getCorrectionConstant()), time));
        } else if (db instanceof IntegerDataBlock) {
            point.updatePointValue(new PointValueTime(locatorRT.calcCorrectedValue(((IntegerDataBlock) db).getValue(), db.getCorrectionExponent(locatorVo.effectiveSiPrefix()), db.getCorrectionConstant()), time));
        } else if (db instanceof LongDataBlock) {
            point.updatePointValue(new PointValueTime(locatorRT.calcCorrectedValue(((LongDataBlock) db).getValue(), db.getCorrectionExponent(locatorVo.effectiveSiPrefix()), db.getCorrectionConstant()), time));
        } else if (db instanceof RealDataBlock) {
            point.updatePointValue(new PointValueTime(locatorRT.calcCorrectedValue(((RealDataBlock) db).getValue(), db.getCorrectionExponent(locatorVo.effectiveSiPrefix()), db.getCorrectionConstant()), time));
        } else if (db instanceof BigDecimalDataBlock) {
            point.updatePointValue(new PointValueTime(locatorRT.calcCorrectedValue(((BigDecimalDataBlock) db).getValue().doubleValue(), db.getCorrectionExponent(locatorVo.effectiveSiPrefix()), db.getCorrectionConstant()), time));
        } else if (db instanceof StringDataBlock) {
            point.updatePointValue(new PointValueTime(((StringDataBlock) db).getValue(), time));
        } else {
            LOG.fatal("Dont know how to save: " + point.getVO().getExtendedName());
            raiseEvent(POINT_READ_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("event.exception2", point.getVO().getExtendedName(), "Dont know how to save"));
            pointError = true;
        }
    } catch (Exception ex) {
        LOG.fatal("Error during saving: " + vo.getName(), ex);
        raiseEvent(POINT_READ_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("event.exception2", point.getVO().getExtendedName(), "Ex: " + ex));
        pointError = true;
    }
    return pointError;
}
Also used : ShortDataBlock(net.sf.mbus4j.dataframes.datablocks.ShortDataBlock) IntegerDataBlock(net.sf.mbus4j.dataframes.datablocks.IntegerDataBlock) BigDecimalDataBlock(net.sf.mbus4j.dataframes.datablocks.BigDecimalDataBlock) StringDataBlock(net.sf.mbus4j.dataframes.datablocks.StringDataBlock) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) BcdValue(net.sf.mbus4j.dataframes.datablocks.BcdValue) RealDataBlock(net.sf.mbus4j.dataframes.datablocks.RealDataBlock) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) LongDataBlock(net.sf.mbus4j.dataframes.datablocks.LongDataBlock) ByteDataBlock(net.sf.mbus4j.dataframes.datablocks.ByteDataBlock) IOException(java.io.IOException)

Aggregations

TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)1 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)1 IOException (java.io.IOException)1 BcdValue (net.sf.mbus4j.dataframes.datablocks.BcdValue)1 BigDecimalDataBlock (net.sf.mbus4j.dataframes.datablocks.BigDecimalDataBlock)1 ByteDataBlock (net.sf.mbus4j.dataframes.datablocks.ByteDataBlock)1 IntegerDataBlock (net.sf.mbus4j.dataframes.datablocks.IntegerDataBlock)1 LongDataBlock (net.sf.mbus4j.dataframes.datablocks.LongDataBlock)1 RealDataBlock (net.sf.mbus4j.dataframes.datablocks.RealDataBlock)1 ShortDataBlock (net.sf.mbus4j.dataframes.datablocks.ShortDataBlock)1 StringDataBlock (net.sf.mbus4j.dataframes.datablocks.StringDataBlock)1