&& it.hasNext())
{
dp = it.next();
try
{
IecInfoObject infoObject = new IecInfoObject();
infoObject.objectAddress = dp.getAddress();
infoObject.timeTag = dp.getTimestamp();
infoObject.infoElements = new IecInfoElement[1];
infoObject.infoElements[0] = new IecInfoElement();
infoObject.infoElements[0].setQuality(dp.getQuality());
infoObject.infoElements[0].setBooleanValue(dp.getBooleanValue());
//add the info object into the ASDU
response.asdu.infoObjects.add(infoObject);
}
catch (Exception ex)
{
logger_.error("Can not create IEC message for datapoint: " + dp.getName());
logger_.error("Exception: " + ex.getMessage());
}
}
//add APDU into the list of responses
responses.add(response);
}
}
//return all ddi (COT=20)
if (interroGroup == 0 || interroGroup == 2)
{
dpList = parent_.data_.getAllDDIPoints();
logger_.info("Sending all DDI datapoints (as double value). Number of datapoints: " + dpList.size());
it = dpList.iterator();
while(it.hasNext())
{
response = new IecApdu();
response.format = EIecApduFormat.I_FORMAT;
//response.asdu.typeId = EIecTypeId.M_DP_NA_1;
response.asdu.typeId = EIecTypeId.M_DP_TB_1; //with CP56Time2a
response.asdu.commonAddress = request.asdu.commonAddress;
response.asdu.sequenceType = EIecAsduSequenceType.SEQUENCE_OF_OBJECTS;
response.asdu.causeOfTransmission = cot;
//create the information objects
while(response.asdu.infoObjects.size() < MAX_INFO_OBJECT_ARRAY
&& it.hasNext())
{
dp = it.next();
try
{
IecInfoObject infoObject = new IecInfoObject();
infoObject.objectAddress = dp.getAddress();
infoObject.timeTag = dp.getTimestamp();
infoObject.infoElements = new IecInfoElement[1];
infoObject.infoElements[0] = new IecInfoElement();
infoObject.infoElements[0].setQuality(dp.getQuality());
infoObject.infoElements[0].setIntValue(dp.getIntValue());
//add the info object into the ASDU
response.asdu.infoObjects.add(infoObject);
}
catch (Exception ex)
{
logger_.error("Can not create IEC message for datapoint: " + dp.getName());
logger_.error("Exception: " + ex.getMessage());
}
}
//add APDU into the list of responses
responses.add(response);
}
}
//return all ai including tdi and utc
if (interroGroup == 0 || interroGroup == 3)
{
//return all tdi (COT=20)
//Note: we transfer TDI value as a measured scaled value (ie. as AI)
dpList = parent_.data_.getAllTDIPoints();
logger_.info("Sending all TDI datapoints (as measured scaled value). Number of datapoints: " + dpList.size());
it = dpList.iterator();
while(it.hasNext())
{
response = new IecApdu();
response.format = EIecApduFormat.I_FORMAT;
//response.asdu.typeId = EIecTypeId.M_ME_NB_1;
response.asdu.typeId = EIecTypeId.M_ME_TE_1; //with CP56Time2a
response.asdu.commonAddress = request.asdu.commonAddress;
response.asdu.sequenceType = EIecAsduSequenceType.SEQUENCE_OF_OBJECTS;
response.asdu.causeOfTransmission = cot;
//create the information objects
while(response.asdu.infoObjects.size() < MAX_INFO_OBJECT_ARRAY
&& it.hasNext())
{
dp = it.next();
try
{
IecInfoObject infoObject = new IecInfoObject();
infoObject.objectAddress = dp.getAddress();
infoObject.timeTag = dp.getTimestamp();
infoObject.infoElements = new IecInfoElement[1];
infoObject.infoElements[0] = new IecInfoElement();
infoObject.infoElements[0].setQuality(dp.getQuality());
infoObject.infoElements[0].setIntValue(dp.getIntValue());
//add the info object into the ASDU
response.asdu.infoObjects.add(infoObject);
}
catch (Exception ex)
{
logger_.error("Can not create IEC message for datapoint: " + dp.getName());
logger_.error("Exception: " + ex.getMessage());
}
}
//add APDU into the list of responses
responses.add(response);
}
//return all ai (COT=20)
dpList = parent_.data_.getAllAIPoints();
logger_.info("Sending all AI datapoints (as measured scaled value). Number of datapoints: " + dpList.size());
it = dpList.iterator();
while(it.hasNext())
{
response = new IecApdu();
response.format = EIecApduFormat.I_FORMAT;
//response.asdu.typeId = EIecTypeId.M_ME_NB_1;
response.asdu.typeId = EIecTypeId.M_ME_TE_1; //with CP56Time2a
response.asdu.commonAddress = request.asdu.commonAddress;
response.asdu.sequenceType = EIecAsduSequenceType.SEQUENCE_OF_OBJECTS;
response.asdu.causeOfTransmission = cot;
//create the information objects
while(response.asdu.infoObjects.size() < MAX_INFO_OBJECT_ARRAY
&& it.hasNext())
{
dp = it.next();
try
{
IecInfoObject infoObject = new IecInfoObject();
infoObject.objectAddress = dp.getAddress();
infoObject.timeTag = dp.getTimestamp();
infoObject.infoElements = new IecInfoElement[1];
infoObject.infoElements[0] = new IecInfoElement();
infoObject.infoElements[0].setQuality(dp.getQuality());
infoObject.infoElements[0].setIntValue(dp.getIntValue());
//add the info object into the ASDU
response.asdu.infoObjects.add(infoObject);
}
catch (Exception ex)
{
logger_.error("Can not create IEC message for datapoint: " + dp.getName());
logger_.error("Exception: " + ex.getMessage());
}
}
//add APDU into the list of responses
responses.add(response);
}
//return all utc (COT=20)
//Note: we transfer UTC value as a measured scaled value (ie. as AI)
dpList = parent_.data_.getAllUTCPoints();
logger_.info("Sending all UTC datapoints (as measured scaled value). Number of datapoints: " + dpList.size());
it = dpList.iterator();
while(it.hasNext())
{
response = new IecApdu();
response.format = EIecApduFormat.I_FORMAT;
//response.asdu.typeId = EIecTypeId.M_ME_NB_1;
response.asdu.typeId = EIecTypeId.M_ME_TE_1; //with CP56Time2a
response.asdu.commonAddress = request.asdu.commonAddress;
response.asdu.sequenceType = EIecAsduSequenceType.SEQUENCE_OF_OBJECTS;
response.asdu.causeOfTransmission = cot;
//create the information objects
while(response.asdu.infoObjects.size() < MAX_INFO_OBJECT_ARRAY
&& it.hasNext())
{
dp = it.next();
try
{
IecInfoObject infoObject = new IecInfoObject();
infoObject.objectAddress = dp.getAddress();
infoObject.timeTag = dp.getTimestamp();
infoObject.infoElements = new IecInfoElement[1];
infoObject.infoElements[0] = new IecInfoElement();
infoObject.infoElements[0].setQuality(dp.getQuality());
infoObject.infoElements[0].setIntValue(dp.getIntValue());
//add the info object into the ASDU
response.asdu.infoObjects.add(infoObject);
}
catch (Exception ex)
{
logger_.error("Can not create IEC message for datapoint: " + dp.getName());
logger_.error("Exception: " + ex.getMessage());
}
}
//add APDU into the list of responses
responses.add(response);
}
}
if (interroGroup == 0 || interroGroup == 4)
{
//return all mi (COT=20)
//Note: in real IEC-104 application (in POW subsystem), MI data will normally be
// counter data. (Thus, can be retrieved using counter interrogation command)
dpList = parent_.data_.getAllMIPoints();
logger_.info("Sending all MI datapoints (as integrated total). Number of datapoints: " + dpList.size());
it = dpList.iterator();
while(it.hasNext())
{
response = new IecApdu();
response.format = EIecApduFormat.I_FORMAT;
//response.asdu.typeId = EIecTypeId.M_IT_NA_1;
response.asdu.typeId = EIecTypeId.M_IT_TB_1; //with CP56Time2a
response.asdu.commonAddress = request.asdu.commonAddress;
response.asdu.sequenceType = EIecAsduSequenceType.SEQUENCE_OF_OBJECTS;
response.asdu.causeOfTransmission = cot;
//create the information objects
while(response.asdu.infoObjects.size() < MAX_INFO_OBJECT_ARRAY
&& it.hasNext())
{
dp = it.next();
try
{
IecInfoObject infoObject = new IecInfoObject();
infoObject.objectAddress = dp.getAddress();
infoObject.timeTag = dp.getTimestamp();
infoObject.infoElements = new IecInfoElement[1];
infoObject.infoElements[0] = new IecInfoElement();
infoObject.infoElements[0].setQuality(dp.getQuality());
infoObject.infoElements[0].setIntValue(dp.getIntValue());
//add the info object into the ASDU
response.asdu.infoObjects.add(infoObject);
}
catch (Exception ex)
{
logger_.error("Can not create IEC message for datapoint: " + dp.getName());
logger_.error("Exception: " + ex.getMessage());
}
}
//add APDU into the list of responses
responses.add(response);
}
}
// //return all cx (COT=20)
// //Note: in real IEC-104 application (in POW subsystem), there will never be CX data.
// dpList = parent_.data_.getAllCXPoints();
// logger_.info("Sending all CX datapoints. Number of datapoints: " + dpList.size());
//
// it = dpList.iterator();
// while(it.hasNext())
// {
// //TODO
// }
//interrogation command END (COT=10)
logger_.info("Sending interrogation command end (C_IC_NA_1, COT=10).");
response = new IecApdu();
response.format = EIecApduFormat.I_FORMAT;
response.asdu = new IecAsdu(request.asdu);
response.asdu.causeOfTransmission = EIecCauseOfTransmission.ACTIVATION_TERMINATE;
responses.add(response);
}
else if (request.asdu.typeId == EIecTypeId.C_CI_NA_1)
{
//counter interrogation command
logger_.info("Received counter interrogation command (C_CI_NA_1).");
//reply to data request only if the data transfer has been enabled
if (!isDataEnabled_)
{
logger_.warn("Data transfer is not enabled. It will be ignored.");
return false;
}
//ensure the COT=6
if (request.asdu.causeOfTransmission.value() != EIecCauseOfTransmission.ACTIVATION.value())
{
logger_.warn("Cause of Transmission is not ACTIVATION (6). Maybe we should ignore this message?");
logger_.warn("For now, we will just process it as if the correct COT is set.");
}
//counter interro command CON (COT=7)
logger_.info("Sending counter interrogation command confirm (C_CI_NA_1, COT=7).");
IecApdu response = new IecApdu();
response.format = EIecApduFormat.I_FORMAT;
response.asdu = new IecAsdu(request.asdu);
response.asdu.causeOfTransmission = EIecCauseOfTransmission.ACTIVATION_CONFIRM;
responses.add(response);
Iterator<DataPoint> it = null;
DataPoint dp = null;
Collection<DataPoint> dpList = null;
//return all mi (COT=20)
dpList = parent_.data_.getAllMIPoints();
logger_.info("Sending all MI datapoints. Number of datapoints: " + dpList.size());
it = dpList.iterator();
while(it.hasNext())
{
response = new IecApdu();
response.format = EIecApduFormat.I_FORMAT;
//response.asdu.typeId = EIecTypeId.M_IT_NA_1;
response.asdu.typeId = EIecTypeId.M_IT_TB_1; //with CP56Time2a
response.asdu.commonAddress = request.asdu.commonAddress;
response.asdu.sequenceType = EIecAsduSequenceType.SEQUENCE_OF_OBJECTS;
response.asdu.causeOfTransmission = EIecCauseOfTransmission.INTERROGATED_STATION;
//create the information objects
while(response.asdu.infoObjects.size() < MAX_INFO_OBJECT_ARRAY
&& it.hasNext())
{
dp = it.next();
try
{
IecInfoObject infoObject = new IecInfoObject();
infoObject.objectAddress = dp.getAddress();
infoObject.timeTag = dp.getTimestamp();
infoObject.infoElements = new IecInfoElement[1];
infoObject.infoElements[0] = new IecInfoElement();
infoObject.infoElements[0].setQuality(dp.getQuality());