Package tcg.scada.cos

Examples of tcg.scada.cos.CosDpValueUnion


    boolean boolStatus = false;
    int intStatus = 0;
    long updateTs = Calendar.getInstance().getTimeInMillis();
    long sourceTs = updateTs;
    long outputTs = updateTs;
    CosDpValueUnion value = new CosDpValueUnion();
   
    // TODO: check for datastore notification!
   
    // REAL datapoint
   
    // real-boolean datapoint
    datapoint = new DataPointImpl(EDataPointType.TYPE_REAL,
        CosDpValueTypeEnum.TypeBoolean);
    datapoint.keyId = keyId++;
    datapoint.name = "real-boolean";
   
    // initial value
    Assert.assertEquals(false, datapoint.isInhibit());
    Assert.assertEquals(false, datapoint.getSourceValue().boolValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(CosDpQualityEnum.QualityGood, datapoint.getSourceQuality());
    Assert.assertEquals(false, datapoint.getValue().boolValue());
    Assert.assertEquals(0, datapoint.getTimestamp());
    Assert.assertEquals(CosDpQualityEnum.QualityGood, datapoint.getQuality());
    Assert.assertEquals(0, datapoint.getUpdateTimestamp());
   
    sourceTs = datapoint.getSourceTimestamp();
    outputTs = datapoint.getTimestamp();
    updateTs = Calendar.getInstance().getTimeInMillis();

    // set the inhibit flag
    boolStatus = datapoint.setAlarmInhibit();
    Assert.assertEquals(true, boolStatus);
    // inhibit flag is set
    Assert.assertEquals(true, datapoint.isInhibit());
    // no update on source value/quality/timestamp
    Assert.assertEquals(false, datapoint.getSourceValue().boolValue());
    Assert.assertTrue(datapoint.getSourceTimestamp() == sourceTs);
    Assert.assertEquals(CosDpQualityEnum.QualityGood, datapoint.getSourceQuality());
    // output quality is set to QualityInhibit
    Assert.assertEquals(false, datapoint.getValue().boolValue());
    Assert.assertTrue(datapoint.getTimestamp() == outputTs);
    Assert.assertEquals(CosDpQualityEnum.QualityInhibit, datapoint.getQuality());
    // update-timestamp is set to current time
    Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);
    //TODO: check for datapoint notification
   
    sourceTs = Calendar.getInstance().getTimeInMillis();
    outputTs = datapoint.getTimestamp();
    updateTs = Calendar.getInstance().getTimeInMillis();

    // set with new value with timestamp update
    intStatus = datapoint.setBooleanSourceValue(true, true);
    Assert.assertEquals(1, intStatus);
    // source value is updated, source timestamp is updated to current time
    Assert.assertEquals(true, datapoint.getSourceValue().boolValue());
    Assert.assertTrue(datapoint.getSourceTimestamp() >= sourceTs);
    Assert.assertEquals(CosDpQualityEnum.QualityGood, datapoint.getSourceQuality());
    // no update on output value/quality/timestamp
    Assert.assertEquals(false, datapoint.getValue().boolValue());
    Assert.assertTrue(datapoint.getTimestamp() == outputTs);
    Assert.assertEquals(CosDpQualityEnum.QualityInhibit, datapoint.getQuality());
    // update timestamp is updated to current time
    Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);
    //TODO: check for datapoint notification
   
    sourceTs = datapoint.getSourceTimestamp();
    outputTs = datapoint.getTimestamp();
    updateTs = datapoint.getUpdateTimestamp();

    // re-inhibit (fail)
    boolStatus = datapoint.setAlarmInhibit();
    Assert.assertEquals(false, boolStatus);
    // no update on source value/quality/timestamp
    Assert.assertEquals(true, datapoint.getSourceValue().boolValue());
    Assert.assertTrue(datapoint.getSourceTimestamp() == sourceTs);
    Assert.assertEquals(CosDpQualityEnum.QualityGood, datapoint.getSourceQuality());
    // no update on output value/quality/timestamp
    Assert.assertEquals(false, datapoint.getValue().boolValue());
    Assert.assertTrue(datapoint.getTimestamp() == outputTs);
    Assert.assertEquals(CosDpQualityEnum.QualityInhibit, datapoint.getQuality());
    // update-timestamp is not updated
    Assert.assertTrue(datapoint.getUpdateTimestamp() == updateTs);
    //TODO: check for datapoint notification
   
    sourceTs = Calendar.getInstance().getTimeInMillis();
    outputTs = datapoint.getTimestamp();
    updateTs = Calendar.getInstance().getTimeInMillis();

    // set new quality with timestamp update
    intStatus = datapoint.setSourceQuality(CosDpQualityEnum.QualityBad, true);
    Assert.assertEquals(1, intStatus);
    // source quality is updated, source timestamp is updated to current time
    Assert.assertEquals(true, datapoint.getSourceValue().boolValue());
    Assert.assertTrue(datapoint.getSourceTimestamp() >= sourceTs);
    Assert.assertEquals(CosDpQualityEnum.QualityBad, datapoint.getSourceQuality());
    // no update on output value/quality/timestamp
    Assert.assertEquals(false, datapoint.getValue().boolValue());
    Assert.assertTrue(datapoint.getTimestamp() == outputTs);
    Assert.assertEquals(CosDpQualityEnum.QualityInhibit, datapoint.getQuality());
    // update timestamp is updated to current time
    Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);
    //TODO: check for datapoint notification
   
    sourceTs = datapoint.getSourceTimestamp();
    outputTs = datapoint.getTimestamp();
    updateTs = datapoint.getUpdateTimestamp();

    //set override (mutually exclusive)
    value.boolValue(true);
    datapoint.setOverride(value);
    Assert.assertEquals(true, boolStatus);
    //inhibit and override state is mutually exclusive
    Assert.assertEquals(true, datapoint.isInhibit());
    Assert.assertEquals(false, datapoint.isOverride());
View Full Code Here


    boolean boolStatus = false;
    int intStatus = 0;
    long updateTs = Calendar.getInstance().getTimeInMillis();
    long outputTs = updateTs;
    long sourceTs = updateTs;
    CosDpValueUnion value = new CosDpValueUnion();
    // TODO: check for datastore notification!
   
    // REAL datapoint
   
    // real-boolean datapoint
    datapoint = new DataPointImpl(EDataPointType.TYPE_REAL,
        CosDpValueTypeEnum.TypeNumber);
    datapoint.keyId = keyId++;
    datapoint.name = "real-number";
   
    // initial value
    Assert.assertEquals(false, datapoint.isOverride());
    Assert.assertEquals(0, datapoint.getSourceValue().longValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(CosDpQualityEnum.QualityGood, datapoint.getSourceQuality());
    Assert.assertEquals(0, datapoint.getValue().longValue());
    Assert.assertEquals(0, datapoint.getTimestamp());
    Assert.assertEquals(CosDpQualityEnum.QualityGood, datapoint.getQuality());
    Assert.assertEquals(0, datapoint.getUpdateTimestamp());
   
    sourceTs = Calendar.getInstance().getTimeInMillis();
    updateTs = Calendar.getInstance().getTimeInMillis();
    outputTs = Calendar.getInstance().getTimeInMillis();

    // set override (bool value)
    value.longValue(10);
    boolStatus = datapoint.setOverride(value);
    Assert.assertEquals(true, boolStatus);
    // override flag is set
    Assert.assertEquals(true, datapoint.isOverride());
    // no update on source value/quality/timestamp
    Assert.assertEquals(0, datapoint.getSourceValue().longValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(CosDpQualityEnum.QualityGood, datapoint.getSourceQuality());
    // output quality is set to QualityOverride, output value set to override value
    // output timestamp set to current time
    Assert.assertEquals(10, datapoint.getValue().longValue());
    Assert.assertTrue(datapoint.getTimestamp() >= outputTs);
    Assert.assertEquals(CosDpQualityEnum.QualityOverride, datapoint.getQuality());
    // update-timestamp is set to current time
    Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);
    //TODO: check for datapoint notification
   
    sourceTs = Calendar.getInstance().getTimeInMillis();
    updateTs = Calendar.getInstance().getTimeInMillis();
    outputTs = datapoint.getTimestamp();
   
    // set source value with timestamp update
    intStatus = datapoint.setNumberSourceValue(-20, true);
    Assert.assertEquals(1, intStatus);
    // source value is updated, source timestamp is updated to current time
    Assert.assertEquals(-20, datapoint.getSourceValue().longValue());
    Assert.assertTrue(datapoint.getSourceTimestamp() >= sourceTs);
    Assert.assertEquals(CosDpQualityEnum.QualityGood, datapoint.getSourceQuality());
    // no update on output value/quality/timestamp
    Assert.assertEquals(10, datapoint.getValue().longValue());
    Assert.assertTrue(datapoint.getTimestamp() == outputTs);
    Assert.assertEquals(CosDpQualityEnum.QualityOverride, datapoint.getQuality());
    // update timestamp is updated to current time
    Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);
    //TODO: check for datapoint notification
   
    sourceTs = datapoint.getSourceTimestamp();
    updateTs = Calendar.getInstance().getTimeInMillis();
    outputTs = Calendar.getInstance().getTimeInMillis();

    // re-override with new value (succed with override value updated)
    value.longValue(110);
    boolStatus = datapoint.setOverride(value);
    Assert.assertEquals(true, boolStatus);
    // no update on source value/quality/timestamp
    Assert.assertEquals(-20, datapoint.getSourceValue().longValue());
    Assert.assertTrue(datapoint.getSourceTimestamp() == sourceTs);
View Full Code Here

   * .
   */
  public void testSetSourceValueCosDpValueUnion() {
    int keyId = 1;

    CosDpValueUnion value = new CosDpValueUnion();
    DataPointImpl datapoint = null;
    int status = 0;
    long updateTs = Calendar.getInstance().getTimeInMillis();
   
    // TODO: check for datastore notification!
   
    // set with null value
    datapoint = new DataPointImpl(EDataPointType.TYPE_REAL,
        CosDpValueTypeEnum.TypeBoolean);
    datapoint.keyId = keyId++;
    datapoint.name = "real-boolean";
    //initial state
    Assert.assertEquals(false, datapoint.getSourceValue().boolValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(false, datapoint.getValue().boolValue());
    Assert.assertEquals(0, datapoint.getTimestamp());
    //set without timestamp update
    status = datapoint.setSourceValue(null, false);
    Assert.assertEquals(-1, status);
    Assert.assertEquals(false, datapoint.getValue().boolValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(false, datapoint.getValue().boolValue());
    Assert.assertEquals(0, datapoint.getTimestamp());
    //set with timestamp update
    status = datapoint.setSourceValue(null, true);
    Assert.assertEquals(-1, status);
    Assert.assertEquals(false, datapoint.getValue().boolValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(false, datapoint.getValue().boolValue());
    Assert.assertEquals(0, datapoint.getTimestamp());

    // REAL datapoint
   
    // real-boolean datapoint
    datapoint = new DataPointImpl(EDataPointType.TYPE_REAL,
        CosDpValueTypeEnum.TypeBoolean);
    datapoint.keyId = keyId++;
    datapoint.name = "real-boolean";
   
    // initial value
    Assert.assertEquals(false, datapoint.getSourceValue().boolValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(false, datapoint.getValue().boolValue());
    Assert.assertEquals(0, datapoint.getTimestamp());
   
    // set without timestamp
    updateTs = Calendar.getInstance().getTimeInMillis();
    value.boolValue(true);
    status = datapoint.setSourceValue(value, false);
    Assert.assertEquals(1, status);
    // source value is updated, source timestamp is not updated
    Assert.assertEquals(true, datapoint.getSourceValue().boolValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    // output value/timestamp is synchronized with source value/timestamp
    Assert.assertEquals(true, datapoint.getValue().boolValue());
    Assert.assertEquals(0, datapoint.getTimestamp());
    // update-time is set to current time
    Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);

    // set with timestamp
    updateTs = Calendar.getInstance().getTimeInMillis();
    value.boolValue(false);
    status = datapoint.setSourceValue(value, true);
    Assert.assertEquals(1, status);
    // source value is updated, source timestamp is set to current time
    Assert.assertEquals(false, datapoint.getSourceValue().boolValue());
    Assert.assertTrue(datapoint.getSourceTimestamp() >= updateTs);
    // ouput value/timestamp is synchronized with source value/timestamp
    Assert.assertEquals(false, datapoint.getValue().boolValue());
    Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint.getTimestamp());
    // update-time is set to current time
    Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);
    //TODO: check for the same value
   
    // real-number datapoint
    datapoint = new DataPointImpl(EDataPointType.TYPE_REAL,
        CosDpValueTypeEnum.TypeNumber);
    datapoint.keyId = keyId++;
    datapoint.name = "real-number";

    // initial value
    Assert.assertEquals(0, datapoint.getSourceValue().longValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(0, datapoint.getValue().longValue());
    Assert.assertEquals(0, datapoint.getTimestamp());

    // set without timestamp
    updateTs = Calendar.getInstance().getTimeInMillis();
    value.longValue(11);
    status = datapoint.setSourceValue(value, false);
    Assert.assertEquals(1, status);
    // source value is updated, source timestamp is not updated
    Assert.assertEquals(11, datapoint.getSourceValue().longValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    // output value/timestamp is synchronized with source value/timestamp
    Assert.assertEquals(11, datapoint.getValue().longValue());
    Assert.assertEquals(0, datapoint.getTimestamp());
    // update-time is set to current time
    Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);

    // set with timestamp
    updateTs = Calendar.getInstance().getTimeInMillis();
    value.longValue(15);
    status = datapoint.setSourceValue(value, true);
    Assert.assertEquals(1, status);
    // source value is updated, source timestamp is set to current time
    Assert.assertEquals(15, datapoint.getSourceValue().longValue());
    Assert.assertTrue(datapoint.getSourceTimestamp() >= updateTs);
    // output value/timestamp is synchronized with source value/timestamp
    Assert.assertEquals(15, datapoint.getValue().longValue());
    Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint.getTimestamp());
    // update-time is set to current time
    Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);

    //TODO: check for the same value
    //TODO: check for engineering conversion
    //TODO: check for deadband

    // real-unsigned datapoint
    datapoint = new DataPointImpl(EDataPointType.TYPE_REAL,
        CosDpValueTypeEnum.TypeUnsigned);
    datapoint.keyId = keyId++;
    datapoint.name = "real-unsigned";

    // initial value
    Assert.assertEquals(0, datapoint.getSourceValue().unsignedValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(0, datapoint.getValue().unsignedValue());
    Assert.assertEquals(0, datapoint.getTimestamp());

    // set without timestamp
    updateTs = Calendar.getInstance().getTimeInMillis();
    value.unsignedValue(11);
    status = datapoint.setSourceValue(value, false);
    Assert.assertEquals(1, status);
    Assert.assertEquals(11, datapoint.getSourceValue().unsignedValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(11, datapoint.getValue().unsignedValue());
    Assert.assertEquals(0, datapoint.getTimestamp());
    // update-time is set to current time
    Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);

    // set with timestamp
    updateTs = Calendar.getInstance().getTimeInMillis();
    value.longValue(15);
    status = datapoint.setSourceValue(value, true);
    Assert.assertEquals(1, status);
    Assert.assertEquals(15, datapoint.getSourceValue().unsignedValue());
    Assert.assertTrue(datapoint.getSourceTimestamp() >= updateTs);
    Assert.assertEquals(15, datapoint.getValue().unsignedValue());
    Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint.getTimestamp());
    // update-time is set to current time
    Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);

    //TODO: check for the same value
    //TODO: check for engineering conversion
    //TODO: check for deadband

    // real-double datapoint
    datapoint = new DataPointImpl(EDataPointType.TYPE_REAL,
        CosDpValueTypeEnum.TypeDouble);
    datapoint.keyId = keyId++;
    datapoint.name = "real-double";

    // initial value
    Assert.assertEquals(0.0, datapoint.getSourceValue().dblValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(0.0, datapoint.getValue().dblValue());
    Assert.assertEquals(0, datapoint.getTimestamp());

    // set without timestamp
    updateTs = Calendar.getInstance().getTimeInMillis();
    value.dblValue(11.5);
    status = datapoint.setSourceValue(value, false);
    Assert.assertEquals(1, status);
    Assert.assertEquals(11.5, datapoint.getSourceValue().dblValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(11.5, datapoint.getValue().dblValue());
    Assert.assertEquals(0, datapoint.getTimestamp());
    // update-time is set to current time
    Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);

    // set with timestamp
    updateTs = Calendar.getInstance().getTimeInMillis();
    value.dblValue(15.7);
    status = datapoint.setSourceValue(value, true);
    Assert.assertEquals(1, status);
    Assert.assertEquals(15.7, datapoint.getSourceValue().dblValue());
    Assert.assertTrue(datapoint.getSourceTimestamp() >= updateTs);
    Assert.assertEquals(15.7, datapoint.getValue().dblValue());
    Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint.getTimestamp());
    // update-time is set to current time
    Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);

    //TODO: check for the same value
    //TODO: check for engineering conversion
    //TODO: check for deadband

    // real-string datapoint
    datapoint = new DataPointImpl(EDataPointType.TYPE_REAL,
        CosDpValueTypeEnum.TypeString);
    datapoint.keyId = keyId++;
    datapoint.name = "real-string";

    // initial value
    Assert.assertTrue(datapoint.getSourceValue().charValue().compareTo("") == 0);
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertTrue(datapoint.getValue().charValue().compareTo("") == 0);
    Assert.assertEquals(0, datapoint.getTimestamp());

    // set without timestamp
    updateTs = Calendar.getInstance().getTimeInMillis();
    value.charValue("Test");
    status = datapoint.setSourceValue(value, false);
    Assert.assertEquals(1, status);
    Assert.assertTrue(datapoint.getSourceValue().charValue().compareTo("Test") == 0);
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertTrue(datapoint.getValue().charValue().compareTo("Test") == 0);
    Assert.assertEquals(0, datapoint.getTimestamp());
    // update-time is set to current time
    Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);

    // set with timestamp
    updateTs = Calendar.getInstance().getTimeInMillis();
    value.charValue("TestTest");
    status = datapoint.setSourceValue(value, true);
    Assert.assertEquals(1, status);
    Assert.assertTrue(datapoint.getSourceValue().charValue().compareTo("TestTest") == 0);
    Assert.assertTrue(datapoint.getSourceTimestamp() >= updateTs);
    Assert.assertTrue(datapoint.getValue().charValue().compareTo("Test") == 0);
    Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint.getTimestamp());
    // update-time is set to current time
    Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);

    //TODO: check for the same value
   
    // VIRTUAL datapoint
    //TODO: implement proper;y 
   
    // virtual-boolean datapoint
    datapoint = new DataPointImpl(EDataPointType.TYPE_VIRTUAL,
        CosDpValueTypeEnum.TypeBoolean);
    datapoint.keyId = keyId++;
    datapoint.name = "virtual-boolean";

    //initial value
    Assert.assertEquals(false, datapoint.getSourceValue().boolValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(false, datapoint.getValue().boolValue());
    Assert.assertEquals(0, datapoint.getTimestamp());

    //set value (with timestamp)
    value.boolValue(true);
    status = datapoint.setSourceValue(value, true);
    Assert.assertEquals(-1, status);
    Assert.assertEquals(false, datapoint.getSourceValue().boolValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(false, datapoint.getValue().boolValue());
    Assert.assertEquals(0, datapoint.getTimestamp());
   
    // virtual-number datapoint
    datapoint = new DataPointImpl(EDataPointType.TYPE_VIRTUAL,
        CosDpValueTypeEnum.TypeNumber);
    datapoint.keyId = keyId++;
    datapoint.name = "virtual-number";
    //initial value
    Assert.assertEquals(0, datapoint.getSourceValue().longValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(0, datapoint.getValue().longValue());
    Assert.assertEquals(0, datapoint.getTimestamp());
    //set value (with timestamp)
    value.longValue(11);
    status = datapoint.setSourceValue(value, true);
    Assert.assertEquals(-1, status);
    Assert.assertEquals(0, datapoint.getSourceValue().longValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(0, datapoint.getValue().longValue());
    Assert.assertEquals(0, datapoint.getTimestamp());

    // virtual-unsigned datapoint
    datapoint = new DataPointImpl(EDataPointType.TYPE_VIRTUAL,
        CosDpValueTypeEnum.TypeUnsigned);
    datapoint.keyId = keyId++;
    datapoint.name = "virtual-unsigned";
    //initial value
    Assert.assertEquals(0, datapoint.getSourceValue().unsignedValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(0, datapoint.getValue().unsignedValue());
    Assert.assertEquals(0, datapoint.getTimestamp());
    //set value (with timestamp)
    value.unsignedValue(11);
    status = datapoint.setSourceValue(value, true);
    Assert.assertEquals(-1, status);
    Assert.assertEquals(0, datapoint.getSourceValue().unsignedValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(0, datapoint.getValue().unsignedValue());
    Assert.assertEquals(0, datapoint.getTimestamp());

    // virtual-double datapoint
    datapoint = new DataPointImpl(EDataPointType.TYPE_VIRTUAL,
        CosDpValueTypeEnum.TypeDouble);
    datapoint.keyId = keyId++;
    datapoint.name = "virtual-double";
    //initial value
    Assert.assertEquals(0.0, datapoint.getSourceValue().dblValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(0.0, datapoint.getValue().dblValue());
    Assert.assertEquals(0, datapoint.getTimestamp());
    //set value (with timestamp)
    value.dblValue(11.5);
    status = datapoint.setSourceValue(value, true);
    Assert.assertEquals(-1, status);
    Assert.assertEquals(0.0, datapoint.getSourceValue().dblValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(0.0, datapoint.getValue().dblValue());
    Assert.assertEquals(0, datapoint.getTimestamp());

    // virtual-string datapoint
    datapoint = new DataPointImpl(EDataPointType.TYPE_VIRTUAL,
        CosDpValueTypeEnum.TypeString);
    datapoint.keyId = keyId++;
    datapoint.name = "virtual-string";
    //initial state
    Assert.assertTrue(datapoint.getSourceValue().charValue().compareTo("") == 0);
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertTrue(datapoint.getValue().charValue().compareTo("") == 0);
    Assert.assertEquals(0, datapoint.getTimestamp());
    //set value with timestamp
    value.charValue("Test");
    status = datapoint.setSourceValue(value, true);
    Assert.assertEquals(-1, status);
    Assert.assertTrue(datapoint.getSourceValue().charValue().compareTo("") == 0);
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertTrue(datapoint.getValue().charValue().compareTo("") == 0);
    Assert.assertEquals(0, datapoint.getTimestamp());

    // CALCULATED datapoint
    // calculated-boolean datapoint
    datapoint = new DataPointImpl(EDataPointType.TYPE_CALCULATED,
        CosDpValueTypeEnum.TypeBoolean);
    datapoint.keyId = keyId++;
    datapoint.name = "calculated-boolean";

    // initial value
    Assert.assertEquals(false, datapoint.getSourceValue().boolValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(false, datapoint.getValue().boolValue());
    Assert.assertEquals(0, datapoint.getTimestamp());

    // set without timestamp
    updateTs = Calendar.getInstance().getTimeInMillis();
    value.boolValue(true);
    status = datapoint.setSourceValue(value, false);
    Assert.assertEquals(1, status);
    Assert.assertEquals(true, datapoint.getSourceValue().boolValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(true, datapoint.getValue().boolValue());
    Assert.assertEquals(0, datapoint.getTimestamp());
    // update-time is set to current time
    Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);

    // set with timestamp
    updateTs = Calendar.getInstance().getTimeInMillis();
    value.boolValue(false);
    status = datapoint.setSourceValue(value, true);
    Assert.assertEquals(1, status);
    Assert.assertEquals(false, datapoint.getSourceValue().boolValue());
    Assert.assertTrue(datapoint.getSourceTimestamp() >= updateTs);
    Assert.assertEquals(false, datapoint.getValue().boolValue());
    Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint.getTimestamp());
    // update-time is set to current time
    Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);

    // calculated-number datapoint
    datapoint = new DataPointImpl(EDataPointType.TYPE_CALCULATED,
        CosDpValueTypeEnum.TypeNumber);
    datapoint.keyId = keyId++;
    datapoint.name = "calculated-number";

    // initial value
    Assert.assertEquals(0, datapoint.getSourceValue().longValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(0, datapoint.getValue().longValue());
    Assert.assertEquals(0, datapoint.getTimestamp());

    // set without timestamp
    updateTs = Calendar.getInstance().getTimeInMillis();
    value.longValue(11);
    status = datapoint.setSourceValue(value, false);
    Assert.assertEquals(1, status);
    Assert.assertEquals(11, datapoint.getSourceValue().longValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(11, datapoint.getValue().longValue());
    Assert.assertEquals(0, datapoint.getTimestamp());
    // update-time is set to current time
    Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);

    // set with timestamp
    updateTs = Calendar.getInstance().getTimeInMillis();
    value.longValue(15);
    status = datapoint.setSourceValue(value, true);
    Assert.assertEquals(1, status);
    Assert.assertEquals(15, datapoint.getSourceValue().longValue());
    Assert.assertTrue(datapoint.getSourceTimestamp() >= updateTs);
    Assert.assertEquals(15, datapoint.getValue().longValue());
    Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint.getTimestamp());
    // update-time is set to current time
    Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);

    // calculated-unsigned datapoint
    datapoint = new DataPointImpl(EDataPointType.TYPE_CALCULATED,
        CosDpValueTypeEnum.TypeUnsigned);
    datapoint.keyId = keyId++;
    datapoint.name = "calculated-unsigned";

    // initial value
    Assert.assertEquals(0, datapoint.getSourceValue().unsignedValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(0, datapoint.getValue().unsignedValue());
    Assert.assertEquals(0, datapoint.getTimestamp());

    // set without timestamp
    updateTs = Calendar.getInstance().getTimeInMillis();
    value.unsignedValue(11);
    status = datapoint.setSourceValue(value, false);
    Assert.assertEquals(1, status);
    Assert.assertEquals(11, datapoint.getSourceValue().unsignedValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(11, datapoint.getValue().unsignedValue());
    Assert.assertEquals(0, datapoint.getTimestamp());
    // update-time is set to current time
    Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);

    // set with timestamp
    updateTs = Calendar.getInstance().getTimeInMillis();
    value.longValue(15);
    status = datapoint.setSourceValue(value, true);
    Assert.assertEquals(1, status);
    Assert.assertEquals(15, datapoint.getSourceValue().unsignedValue());
    Assert.assertTrue(datapoint.getSourceTimestamp() >= updateTs);
    Assert.assertEquals(15, datapoint.getValue().unsignedValue());
    Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint.getTimestamp());
    // update-time is set to current time
    Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);

    // calculated-double datapoint
    datapoint = new DataPointImpl(EDataPointType.TYPE_CALCULATED,
        CosDpValueTypeEnum.TypeDouble);
    datapoint.keyId = keyId++;
    datapoint.name = "calculated-double";

    // initial value
    Assert.assertEquals(0.0, datapoint.getSourceValue().dblValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(0.0, datapoint.getValue().dblValue());
    Assert.assertEquals(0, datapoint.getTimestamp());

    // set without timestamp
    updateTs = Calendar.getInstance().getTimeInMillis();
    value.dblValue(11.5);
    status = datapoint.setSourceValue(value, false);
    Assert.assertEquals(1, status);
    Assert.assertEquals(11.5, datapoint.getSourceValue().dblValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(11.5, datapoint.getValue().dblValue());
    Assert.assertEquals(0, datapoint.getTimestamp());
    // update-time is set to current time
    Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);

    // set with timestamp
    updateTs = Calendar.getInstance().getTimeInMillis();
    value.dblValue(15.7);
    status = datapoint.setSourceValue(value, true);
    Assert.assertEquals(1, status);
    Assert.assertEquals(15.7, datapoint.getSourceValue().dblValue());
    Assert.assertTrue(datapoint.getSourceTimestamp() >= updateTs);
    Assert.assertEquals(15.7, datapoint.getValue().dblValue());
    Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint.getTimestamp());
    // update-time is set to current time
    Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);

    // calculated-string datapoint
    datapoint = new DataPointImpl(EDataPointType.TYPE_CALCULATED,
        CosDpValueTypeEnum.TypeString);
    datapoint.keyId = keyId++;
    datapoint.name = "calculated-string";
   
    // initial value
    Assert.assertTrue(datapoint.getSourceValue().charValue().compareTo("") == 0);
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertTrue(datapoint.getValue().charValue().compareTo("") == 0);
    Assert.assertEquals(0, datapoint.getTimestamp());
   
    // set without timestamp
    updateTs = Calendar.getInstance().getTimeInMillis();
    value.charValue("Test");
    status = datapoint.setSourceValue(value, false);
    Assert.assertEquals(1, status);
    Assert.assertTrue(datapoint.getSourceValue().charValue().compareTo("Test") == 0);
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertTrue(datapoint.getValue().charValue().compareTo("Test") == 0);
    Assert.assertEquals(0, datapoint.getTimestamp());
    // update-time is set to current time
    Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);

    // set with timestamp
    updateTs = Calendar.getInstance().getTimeInMillis();
    value.charValue("TestTest");
    status = datapoint.setSourceValue(value, true);
    Assert.assertEquals(1, status);
    Assert.assertTrue(datapoint.getSourceValue().charValue().compareTo("TestTest") == 0);
    Assert.assertTrue(datapoint.getSourceTimestamp() >= updateTs);
    Assert.assertTrue(datapoint.getValue().charValue().compareTo("Test") == 0);
    Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint.getTimestamp());
    // update-time is set to current time
    Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);

    // METER datapoint
    // Meter datapoint is only supported for number/unsigned datatype
    // meter-boolean datapoint (not supported. reset to number type)
   
    // meter-number datapoint
    datapoint = new DataPointImpl(EDataPointType.TYPE_METER,
        CosDpValueTypeEnum.TypeNumber);
    datapoint.keyId = keyId++;
    datapoint.name = "meter-number";

    // initial value
    Assert.assertEquals(0, datapoint.getSourceValue().longValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(0, datapoint.getValue().longValue());
    Assert.assertEquals(0, datapoint.getTimestamp());

    // set without timestamp
    updateTs = Calendar.getInstance().getTimeInMillis();
    value.longValue(11);
    status = datapoint.setSourceValue(value, false);
    Assert.assertEquals(1, status);
    Assert.assertEquals(11, datapoint.getSourceValue().longValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(11, datapoint.getValue().longValue());
    Assert.assertEquals(0, datapoint.getTimestamp());
    // update-time is set to current time
    Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);

    // set with timestamp
    updateTs = Calendar.getInstance().getTimeInMillis();
    value.longValue(15);
    status = datapoint.setSourceValue(value, true);
    Assert.assertEquals(1, status);
    Assert.assertEquals(26, datapoint.getSourceValue().longValue());
    Assert.assertTrue(datapoint.getSourceTimestamp() >= updateTs);
    Assert.assertEquals(26, datapoint.getValue().longValue());
    Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint.getTimestamp());
    // update-time is set to current time
    Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);

    //TODO: check for reading rollover
    //TODO: check for datapoint rollover
   
    // meter-unsigned datapoint
    datapoint = new DataPointImpl(EDataPointType.TYPE_METER,
        CosDpValueTypeEnum.TypeUnsigned);
    datapoint.keyId = keyId++;
    datapoint.name = "real-unsigned";
   
    // initial value
    Assert.assertEquals(0, datapoint.getSourceValue().unsignedValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(0, datapoint.getValue().unsignedValue());
    Assert.assertEquals(0, datapoint.getTimestamp());
   
    // set without timestamp
    updateTs = Calendar.getInstance().getTimeInMillis();
    value.unsignedValue(11);
    status = datapoint.setSourceValue(value, false);
    Assert.assertEquals(1, status);
    Assert.assertEquals(11, datapoint.getSourceValue().unsignedValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(11, datapoint.getValue().unsignedValue());
    Assert.assertEquals(0, datapoint.getTimestamp());
    // update-time is set to current time
    Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);
   
    // set with timestamp
    updateTs = Calendar.getInstance().getTimeInMillis();
    value.longValue(15);
    status = datapoint.setSourceValue(value, true);
    Assert.assertEquals(1, status);
    Assert.assertEquals(26, datapoint.getSourceValue().unsignedValue());
    Assert.assertTrue(datapoint.getSourceTimestamp() >= updateTs);
    Assert.assertEquals(26, datapoint.getValue().unsignedValue());
    Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint.getTimestamp());
    // update-time is set to current time
    Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);
   
    //TODO: check for reading rollover
    //TODO: check for datapoint rollover
   
    // meter-double datapoint (not supported. reset to number type)
   
    // meter-string datapoint (not supported. reset to number type)

   
    // OUTPUT datapoint
    // Output datapoint is only supported for boolean/number datatype
   
    // output-boolean datapoint
    datapoint = new DataPointImpl(EDataPointType.TYPE_OUTPUT,
        CosDpValueTypeEnum.TypeBoolean);
    datapoint.keyId = keyId++;
    datapoint.name = "output-boolean";
    //initial value
    Assert.assertEquals(false, datapoint.getSourceValue().boolValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(false, datapoint.getValue().boolValue());
    Assert.assertEquals(0, datapoint.getTimestamp());
    //set value (with timestamp)
    value.boolValue(true);
    status = datapoint.setSourceValue(value, true);
    Assert.assertEquals(-1, status);
    Assert.assertEquals(false, datapoint.getSourceValue().boolValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(false, datapoint.getValue().boolValue());
    Assert.assertEquals(0, datapoint.getTimestamp());

    // output-number datapoint
    datapoint = new DataPointImpl(EDataPointType.TYPE_OUTPUT,
        CosDpValueTypeEnum.TypeNumber);
    datapoint.keyId = keyId++;
    datapoint.name = "output-number";
    //initial value
    Assert.assertEquals(0, datapoint.getSourceValue().longValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(0, datapoint.getValue().longValue());
    Assert.assertEquals(0, datapoint.getTimestamp());
    //set value (with timestamp)
    value.longValue(11);
    status = datapoint.setSourceValue(value, true);
    Assert.assertEquals(-1, status);
    Assert.assertEquals(0, datapoint.getSourceValue().longValue());
    Assert.assertEquals(0, datapoint.getSourceTimestamp());
    Assert.assertEquals(0, datapoint.getValue().longValue());
View Full Code Here

    // pass the set-value to underlying subsystem if necessary
    if (subsystem != null && subsystem.isSourceSetValue()
        && type == EDataPointType.TYPE_REAL)
    {
      // convert to associated structure
      CosDpValueUnion myValue = new CosDpValueUnion();
      myValue.boolValue(value);
      // pass to subsystem
      if (subsystem.setValue(this, myValue))
      {
        return +1;
      }
View Full Code Here

    // pass the set-value to underlying subsystem if necessary
    if (subsystem != null && subsystem.isSourceSetValue()
        && type == EDataPointType.TYPE_REAL)
    {
      // convert to associated structure
      CosDpValueUnion myValue = new CosDpValueUnion();
      myValue.longValue(value);
      // pass to subsystem
      if (subsystem.setValue(this, myValue))
      {
        return +1;
      }
View Full Code Here

    // pass the set-value to underlying subsystem if necessary
    if (subsystem != null && subsystem.isSourceSetValue()
        && type == EDataPointType.TYPE_REAL)
    {
      // convert to associated structure
      CosDpValueUnion myValue = new CosDpValueUnion();
      myValue.unsignedValue(value);
      // pass to subsystem
      if (subsystem.setValue(this, myValue))
      {
        return +1;
      }
View Full Code Here

    // pass the set-value to underlying subsystem if necessary
    if (subsystem != null && subsystem.isSourceSetValue()
        && type == EDataPointType.TYPE_REAL)
    {
      // convert to associated structure
      CosDpValueUnion myValue = new CosDpValueUnion();
      myValue.dblValue(value);
      // pass to subsystem
      if (subsystem.setValue(this, myValue))
      {
        return +1;
      }
View Full Code Here

    // pass the set-value to underlying subsystem if necessary
    if (subsystem != null && subsystem.isSourceSetValue()
        && type == EDataPointType.TYPE_REAL)
    {
      // convert to associated structure
      CosDpValueUnion myValue = new CosDpValueUnion();
      myValue.charValue(value);
      // pass to subsystem
      if (subsystem.setValue(this, myValue))
      {
        return +1;
      }
View Full Code Here

      {
        logger_.warn("Can not evaluate expression. Exception: " + ex.toString());
      }
     
      //convert it to CosDpValueUnion
      CosDpValueUnion expValue = Object2CosDpValueUnion(outputValue_.value.discriminator(), obj);
     
      // update the output value with the expression value
      int status1 = copy(outputValue_.value, expValue);;
     
      // recalculate the datapoint quality
View Full Code Here

  protected static CosDpValueUnion String2CosDpValueUnion(CosDpValueTypeEnum type, String str)
  {
    // validation is performed as part of the conversion

    CosDpValueUnion value = new CosDpValueUnion();

    switch (type.value())
    {
      case CosDpValueTypeEnum._TypeBoolean:
        if (str != null && str.compareToIgnoreCase("1") == 0)
        {
          value.boolValue(true);
        }
        else
        {
          value.boolValue(false);
        }
        break;
      case CosDpValueTypeEnum._TypeNumber:
        value.longValue(parse_int(str));
        break;
      case CosDpValueTypeEnum._TypeUnsigned:
        value.unsignedValue(parse_int(str));
        break;
      case CosDpValueTypeEnum._TypeDouble:
        value.dblValue(parse_dbl(str));
        break;
      case CosDpValueTypeEnum._TypeString:
        value.charValue(str);
        break;
      default:
        value.longValue(0);
    }

    return value;
  }
View Full Code Here

TOP

Related Classes of tcg.scada.cos.CosDpValueUnion

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.