}
@Override
protected boolean running()
{
ICosDataPointServer dpServer = CorbaHelper.getActiveDataPointServer(locationId);
if (dpServer == null)
{
logger.error("Can not get datapoint server for location " + locationId);
return false;
}
//get actual datapoint name
String[] items = new String[1];
items[0] = datapointName.replace(".Value", "");
//get the actual value
CosDpValueStruct[] values = new CosDpValueStruct[1];
values[0] = new CosDpValueStruct();
values[0].quality = CosDpQualityEnum.QualityGood;
values[0].timestamp = 0;
values[0].value = new CosDpValueUnion();
//storage for error
CosDpErrorSeqHolder errors = new CosDpErrorSeqHolder();
if (isDigitalControl)
{
//for digital control, anything other than 0 is treated as true value
//anyway we should never send digital control with value = false.
if (datapointValue == 0)
{
values[0].value.boolValue(false);
}
else
{
values[0].value.boolValue(true);
}
}
else
{
values[0].value.longValue(datapointValue);
}
//verbose
logger.info("Sending control. Datapoint: " + items[0] + ". Value: " + datapointValue);
//send the control
try
{
dpServer.cosSetControlItem2(items, values, errors);
//check the error code
if (errors.value[0].value() != CosDpErrorEnum.ErrNoError.value())
{
logger.error("Fail to send control. Error: "
+ CorbaHelper.DpErrorCodeToString(errors.value[0]));
return false;
}
}
catch(Exception ex)
{
logger.error("Fail to send control. Exception: " + ex.getMessage());
return false;
}
//check for return condition (only if it has return condition!)
if (rccTimeoutSec > 0)
{
//rcc timeout in msec
long timeoutMSec = (Calendar.getInstance().getTimeInMillis()) + (rccTimeoutSec * 1000);
//storage for RCC status
CosBooleanSeqHolder status = new CosBooleanSeqHolder();
boolean rccStatus = false;
int errorCounter = 0;
while(timeoutMSec > Calendar.getInstance().getTimeInMillis())
{
//check the return condition status
try
{
dpServer.cosGetItemReturnConditionStatus2(items, status, errors);
//check the error code
if (errors.value[0].value() != CosDpErrorEnum.ErrNoError.value())
{
logger.warn("Fail to get return condition status. Error: "
+ CorbaHelper.DpErrorCodeToString(errors.value[0]));