Package tcg.scada.iec

Examples of tcg.scada.iec.IecInfoElement


    name_ = name;
    address_ = address;
    dpType_ = type;
    if (dpType_ == EDataPointType.TYPE_DI)
    {
      value_ = new IecInfoElement(ETypeDiscriminator.TYPE_BOOLEAN);
    }
    else if (dpType_ == EDataPointType.TYPE_DDI
          || dpType_ == EDataPointType.TYPE_TDI
          || dpType_ == EDataPointType.TYPE_AI
          || dpType_ == EDataPointType.TYPE_UTC)
    {
      value_ = new IecInfoElement(ETypeDiscriminator.TYPE_INTEGER);
    }
    else if (dpType_ == EDataPointType.TYPE_MI)
    {
      value_ = new IecInfoElement(ETypeDiscriminator.TYPE_LONG);
    }
    else if (dpType_ == EDataPointType.TYPE_CX)
    {
      value_ = new IecInfoElement(ETypeDiscriminator.TYPE_STRING);
    }
    else
    {
      //TODO: print warning
      //default
      value_ = new IecInfoElement(ETypeDiscriminator.TYPE_INTEGER);
    }
    timestamp_ = new Date();
    value_.quality = 0;
  }
View Full Code Here


      {
        IecInfoObject infoObject = new IecInfoObject();
        infoObject.objectAddress = datapoint.getAddress();
        infoObject.timeTag = datapoint.getTimestamp();
        infoObject.infoElements = new IecInfoElement[1];
        infoObject.infoElements[0] = new IecInfoElement();
        infoObject.infoElements[0].setQuality(datapoint.getQuality());
        infoObject.infoElements[0].setBooleanValue(datapoint.getBooleanValue());
        //add the info object into the ASDU
        apdu.asdu.infoObjects.add(infoObject);
      }
      catch (Exception ex)
      {
        logger_.error("Can not create IEC message for datapoint: " + datapoint.getName());
        logger_.error("Exception: " + ex.getMessage());
      }     
    }
    else if (datapoint.getDataPointType() == EDataPointType.TYPE_DDI)
    {
      apdu.asdu.typeId = EIecTypeId.M_DP_TB_1;  //with CP56Time2a
      try
      {
        IecInfoObject infoObject = new IecInfoObject();
        infoObject.objectAddress = datapoint.getAddress();
        infoObject.timeTag = datapoint.getTimestamp();
        infoObject.infoElements = new IecInfoElement[1];
        infoObject.infoElements[0] = new IecInfoElement();
        infoObject.infoElements[0].setQuality(datapoint.getQuality());
        infoObject.infoElements[0].setIntValue(datapoint.getIntValue());
        //add the info object into the ASDU
        apdu.asdu.infoObjects.add(infoObject);
      }
      catch (Exception ex)
      {
        logger_.error("Can not create IEC message for datapoint: " + datapoint.getName());
        logger_.error("Exception: " + ex.getMessage());
      }     
    }
    else if (datapoint.getDataPointType() == EDataPointType.TYPE_TDI)
    {
      //NOTE: We send TDI as measured scaled value!
      apdu.asdu.typeId = EIecTypeId.M_ME_TE_1;  //with CP56Time2a
      try
      {
        IecInfoObject infoObject = new IecInfoObject();
        infoObject.objectAddress = datapoint.getAddress();
        infoObject.timeTag = datapoint.getTimestamp();
        infoObject.infoElements = new IecInfoElement[1];
        infoObject.infoElements[0] = new IecInfoElement();
        infoObject.infoElements[0].setQuality(datapoint.getQuality());
        infoObject.infoElements[0].setIntValue(datapoint.getIntValue());
        //add the info object into the ASDU
        apdu.asdu.infoObjects.add(infoObject);
      }
      catch (Exception ex)
      {
        logger_.error("Can not create IEC message for datapoint: " + datapoint.getName());
        logger_.error("Exception: " + ex.getMessage());
      }     
    }
    else if (datapoint.getDataPointType() == EDataPointType.TYPE_AI)
    {
      apdu.asdu.typeId = EIecTypeId.M_ME_TE_1;  //with CP56Time2a
      try
      {
        IecInfoObject infoObject = new IecInfoObject();
        infoObject.objectAddress = datapoint.getAddress();
        infoObject.timeTag = datapoint.getTimestamp();
        infoObject.infoElements = new IecInfoElement[1];
        infoObject.infoElements[0] = new IecInfoElement();
        infoObject.infoElements[0].setQuality(datapoint.getQuality());
        infoObject.infoElements[0].setIntValue(datapoint.getIntValue());
        //add the info object into the ASDU
        apdu.asdu.infoObjects.add(infoObject);
      }
      catch (Exception ex)
      {
        logger_.error("Can not create IEC message for datapoint: " + datapoint.getName());
        logger_.error("Exception: " + ex.getMessage());
      }     
    }
    else if (datapoint.getDataPointType() == EDataPointType.TYPE_UTC)
    {
      //NOTE: We send TDI as measured scaled value!
      apdu.asdu.typeId = EIecTypeId.M_ME_TE_1;  //with CP56Time2a
      try
      {
        IecInfoObject infoObject = new IecInfoObject();
        infoObject.objectAddress = datapoint.getAddress();
        infoObject.timeTag = datapoint.getTimestamp();
        infoObject.infoElements = new IecInfoElement[1];
        infoObject.infoElements[0] = new IecInfoElement();
        infoObject.infoElements[0].setQuality(datapoint.getQuality());
        infoObject.infoElements[0].setIntValue(datapoint.getIntValue());
        //add the info object into the ASDU
        apdu.asdu.infoObjects.add(infoObject);
      }
      catch (Exception ex)
      {
        logger_.error("Can not create IEC message for datapoint: " + datapoint.getName());
        logger_.error("Exception: " + ex.getMessage());
      }     
    }
    else if (datapoint.getDataPointType() == EDataPointType.TYPE_MI)
    {
      apdu.asdu.typeId = EIecTypeId.M_IT_TB_1;  //with CP56Time2a
      try
      {
        IecInfoObject infoObject = new IecInfoObject();
        infoObject.objectAddress = datapoint.getAddress();
        infoObject.timeTag = datapoint.getTimestamp();
        infoObject.infoElements = new IecInfoElement[1];
        infoObject.infoElements[0] = new IecInfoElement();
        infoObject.infoElements[0].setQuality(datapoint.getQuality());
        infoObject.infoElements[0].setIntValue(datapoint.getIntValue());
        //add the info object into the ASDU
        apdu.asdu.infoObjects.add(infoObject);
      }
View Full Code Here

              {
                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());
              infoObject.infoElements[0].setIntValue(dp.getIntValue());
              //add the info object into the ASDU
              response.asdu.infoObjects.add(infoObject);
            }
View Full Code Here

TOP

Related Classes of tcg.scada.iec.IecInfoElement

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.