Example #1
1
 public ASdu(TypeId typeId, bool isSequenceOfElements, int sequenceLength,
     CauseOfTransmission causeOfTransmission, bool test, bool negativeConfirm, int originatorAddress,
     int commonAddress, byte[] privateInformation)
 {
     this.typeId = typeId;
     IsSequenceOfElements = isSequenceOfElements;
     this.causeOfTransmission = causeOfTransmission;
     this.test = test;
     this.negativeConfirm = negativeConfirm;
     this.originatorAddress = originatorAddress;
     this.commonAddress = commonAddress;
     informationObjects = null;
     this.privateInformation = privateInformation;
     this.sequenceLength = sequenceLength;
 }
Example #2
0
        public override void SendResetProcessCommand(CauseOfTransmission cot, int ca, byte qrp)
        {
            ASDU asdu = new ASDU(appLayerParameters, CauseOfTransmission.ACTIVATION, false, false, (byte)appLayerParameters.OA, ca, false);

            asdu.AddInformationObject(new ResetProcessCommand(0, qrp));

            EnqueueUserData(asdu);
        }
Example #3
0
        public override void SendCounterInterrogationCommand(CauseOfTransmission cot, int ca, byte qcc)
        {
            ASDU asdu = new ASDU(appLayerParameters, cot, false, false, (byte)appLayerParameters.OA, ca, false);

            asdu.AddInformationObject(new CounterInterrogationCommand(0, qcc));

            EnqueueUserData(asdu);
        }
Example #4
0
        public void CounterInterrogation(int commonAddress, CauseOfTransmission cot,
                                         IeQualifierOfCounterInterrogation qualifier)
        {
            var aSdu = new ASdu(TypeId.C_CI_NA_1, false, cot, false, false, originatorAddress, commonAddress,
                                new[] { new InformationObject(0, new[] { new InformationElement[] { qualifier } }) });

            Send(aSdu);
        }
Example #5
0
        /// <summary>
        /// Sends the control command.
        /// </summary>
        ///
        /// The type ID has to match the type of the InformationObject!
        ///
        /// C_SC_NA_1 -> SingleCommand
        /// C_DC_NA_1 -> DoubleCommand
        /// C_RC_NA_1 -> StepCommand
        /// C_SC_TA_1 -> SingleCommandWithCP56Time2a
        /// C_SE_NA_1 -> SetpointCommandNormalized
        /// C_SE_NB_1 -> SetpointCommandScaled
        /// C_SE_NC_1 -> SetpointCommandShort
        /// C_BO_NA_1 -> Bitstring32Command
        ///
        /// <param name="cot">Cause of transmission (use ACTIVATION to start a control sequence)</param>
        /// <param name="ca">Common address</param>
        /// <param name="sc">Information object of the command</param>
        /// <exception cref="ConnectionException">description</exception>
        public void SendControlCommand(CauseOfTransmission cot, int ca, InformationObject sc)
        {
            ASDU controlCommand = new ASDU(parameters, cot, false, false, (byte)parameters.OriginatorAddress, ca, false);

            controlCommand.AddInformationObject(sc);

            SendASDUInternal(controlCommand);
        }
Example #6
0
        /// <summary>
        /// Sends a delay acquisition command (C_CD_NA_1 typeID: 106).
        /// </summary>
        /// <param name="cot">Cause of transmission</param>
        /// <param name="ca">Common address</param>
        /// <param name="delay">delay for acquisition</param>
        /// <exception cref="ConnectionException">description</exception>
        public void SendDelayAcquisitionCommand(CauseOfTransmission cot, int ca, CP16Time2a delay)
        {
            ASDU asdu = new ASDU(parameters, CauseOfTransmission.ACTIVATION, false, false, (byte)parameters.OriginatorAddress, ca, false);

            asdu.AddInformationObject(new DelayAcquisitionCommand(0, delay));

            SendASDUInternal(asdu);
        }
Example #7
0
        /// <summary>
        /// Sends a reset process command (C_RP_NA_1 typeID: 105).
        /// </summary>
        /// <param name="cot">Cause of transmission</param>
        /// <param name="ca">Common address</param>
        /// <param name="qrp">Qualifier of reset process command</param>
        /// <exception cref="ConnectionException">description</exception>
        public void SendResetProcessCommand(CauseOfTransmission cot, int ca, byte qrp)
        {
            ASDU asdu = new ASDU(parameters, CauseOfTransmission.ACTIVATION, false, false, (byte)parameters.OriginatorAddress, ca, false);

            asdu.AddInformationObject(new ResetProcessCommand(0, qrp));

            SendASDUInternal(asdu);
        }
Example #8
0
        public override void SendDelayAcquisitionCommand(CauseOfTransmission cot, int ca, CP16Time2a delay)
        {
            ASDU asdu = new ASDU(appLayerParameters, CauseOfTransmission.ACTIVATION, false, false, (byte)appLayerParameters.OA, ca, false);

            asdu.AddInformationObject(new DelayAcquisitionCommand(0, delay));

            EnqueueUserData(asdu);
        }
Example #9
0
        public override void SendControlCommand(CauseOfTransmission cot, int ca, InformationObject sc)
        {
            ASDU controlCommand = new ASDU(appLayerParameters, cot, false, false, (byte)appLayerParameters.OA, ca, false);

            controlCommand.AddInformationObject(sc);

            EnqueueUserData(controlCommand);
        }
Example #10
0
        /// <summary>
        /// Sends the counter interrogation command (C_CI_NA_1 typeID: 101)
        /// </summary>
        /// <param name="cot">Cause of transmission</param>
        /// <param name="ca">Common address</param>
        /// <param name="qcc">Qualifier of counter interrogation command</param>
        /// <exception cref="ConnectionException">description</exception>
        public void SendCounterInterrogationCommand(CauseOfTransmission cot, int ca, byte qcc)
        {
            ASDU asdu = new ASDU(parameters, cot, false, false, (byte)parameters.OriginatorAddress, ca, false);

            asdu.AddInformationObject(new CounterInterrogationCommand(0, qcc));

            SendASDUInternal(asdu);
        }
Example #11
0
        /// <summary>
        /// 使用buff初始化一个ASDU,相当于解析
        /// </summary>
        /// <param name="parameters">链接参数</param>
        /// <param name="msg">接收到的消息内容(整个报文)里面自动跳掉头了。。</param>
        /// <param name="msgLength">消息长度(整个报文的长度,包括报文头)</param>
        public ASDU(ConnectionParameters parameters, byte[] msg, int msgLength)
        {
            //保存链接参数
            this.parameters = parameters.clone();

            //跳过报文头,68H+长度(2)+68H + 链路控制域(1) + 链路地址(2)
            int bufPos = 7;

            typeId = (TypeID)msg[bufPos++];     //类型标识

            vsq = msg[bufPos++];                //可变结构限定词

            this.hasTypeId = true;

            byte cotByte = msg[bufPos++];       //传送原因

            //测试标志--0 未试验(false),1  试验(true)
            if ((cotByte & 0x80) != 0)
            {
                isTest = true;
            }
            else
            {
                isTest = false;
            }

            //确认标志,0  肯定确认(false) ,1 否定确认(true)
            if ((cotByte & 0x40) != 0)
            {
                isNegative = true;
            }
            else
            {
                isNegative = false;
            }

            //传送原因
            cot = (CauseOfTransmission)(cotByte & 0x3f);

            //电能量数据终端设备地址(2字节)
            ca = msg[bufPos++];
            if (parameters.SizeOfCA > 1)
            {
                ca += (msg[bufPos++] * 0x100);
            }

            //记录地址
            ra = (RecordAddress)msg[bufPos++];        //类型标识

            int payloadSize = msgLength - bufPos - 2; //把最后的和校验和结束符去掉

            payload = new byte[payloadSize];

            /* save payload */
            Buffer.BlockCopy(msg, bufPos, payload, 0, payloadSize);
        }
Example #12
0
        public void DoubleCommand(int commonAddress, CauseOfTransmission cot, int informationObjectAddress,
                                  IeDoubleCommand doubleCommand)
        {
            var aSdu = new ASdu(TypeId.C_DC_NA_1, false, cot, false, false, originatorAddress, commonAddress,
                                new[]
            {
                new InformationObject(informationObjectAddress,
                                      new[] { new InformationElement[] { doubleCommand } })
            });

            Send(aSdu);
        }
Example #13
0
        public void ParameterActivation(int commonAddress, CauseOfTransmission cot, int informationObjectAddress,
                                        IeQualifierOfParameterActivation qualifier)
        {
            var aSdu = new ASdu(TypeId.P_AC_NA_1, false, cot, false, false, originatorAddress, commonAddress,
                                new[]
            {
                new InformationObject(informationObjectAddress,
                                      new[] { new InformationElement[] { qualifier } })
            });

            Send(aSdu);
        }
Example #14
0
        public void CallOrSelectFiles(int commonAddress, CauseOfTransmission cot, int informationObjectAddress,
                                      IeNameOfFile nameOfFile, IeNameOfSection nameOfSection, IeSelectAndCallQualifier qualifier)
        {
            var aSdu = new ASdu(TypeId.F_SC_NA_1, false, cot, false, false, originatorAddress, commonAddress,
                                new[]
            {
                new InformationObject(informationObjectAddress,
                                      new[] { new InformationElement[] { nameOfFile, nameOfSection, qualifier } })
            });

            Send(aSdu);
        }
Example #15
0
        public void RegulatingStepCommandWithTimeTag(int commonAddress, CauseOfTransmission cot,
                                                     int informationObjectAddress, IeRegulatingStepCommand regulatingStepCommand, IeTime56 timeTag)
        {
            var aSdu = new ASdu(TypeId.C_RC_TA_1, false, cot, false, false, originatorAddress, commonAddress,
                                new[]
            {
                new InformationObject(informationObjectAddress,
                                      new[] { new InformationElement[] { regulatingStepCommand, timeTag } })
            });

            Send(aSdu);
        }
Example #16
0
        public void BitStringCommand(int commonAddress, CauseOfTransmission cot, int informationObjectAddress,
            IeBinaryStateInformation binaryStateInformation)
        {
            var aSdu = new ASdu(TypeId.C_BO_NA_1, false, cot, false, false, originatorAddress, commonAddress,
                new[]
                {
                    new InformationObject(informationObjectAddress,
                        new[] {new InformationElement[] {binaryStateInformation}})
                });

            Send(aSdu);
        }
Example #17
0
        public void SetShortFloatCommand(int commonAddress, CauseOfTransmission cot, int informationObjectAddress,
                                         IeShortFloat shortFloat, IeQualifierOfSetPointCommand qualifier)
        {
            var aSdu = new ASdu(TypeId.C_SE_NC_1, false, cot, false, false, originatorAddress, commonAddress,
                                new[]
            {
                new InformationObject(informationObjectAddress,
                                      new[] { new InformationElement[] { shortFloat, qualifier } })
            });

            Send(aSdu);
        }
Example #18
0
        public void SetNormalizedValueCommand(int commonAddress, CauseOfTransmission cot, int informationObjectAddress,
                                              IeNormalizedValue normalizedValue, IeQualifierOfSetPointCommand qualifier)
        {
            var aSdu = new ASdu(TypeId.C_SE_NA_1, false, cot, false, false, originatorAddress, commonAddress,
                                new[]
            {
                new InformationObject(informationObjectAddress,
                                      new[] { new InformationElement[] { normalizedValue, qualifier } })
            });

            Send(aSdu);
        }
Example #19
0
        public void BitStringCommandWithTimeTag(int commonAddress, CauseOfTransmission cot, int informationObjectAddress,
                                                IeBinaryStateInformation binaryStateInformation, IeTime56 timeTag)
        {
            var aSdu = new ASdu(TypeId.C_BO_TA_1, false, cot, false, false, originatorAddress, commonAddress,
                                new[]
            {
                new InformationObject(informationObjectAddress,
                                      new[] { new InformationElement[] { binaryStateInformation, timeTag } })
            });

            Send(aSdu);
        }
Example #20
0
        /// <summary>
        /// 使用buff初始化一个ASDU,相当于解析
        /// </summary>
        /// <param name="parameters"></param>
        /// <param name="msg"></param>
        /// <param name="msgLength"></param>
        public ASDU(ConnectionParameters parameters, byte[] msg, int msgLength)
        {
            this.parameters = parameters;

            int bufPos = 6;

            typeId = (TypeID)msg[bufPos++];
            vsq    = msg[bufPos++];

            this.hasTypeId = true;

            byte cotByte = msg[bufPos++];

            if ((cotByte & 0x80) != 0)
            {
                isTest = true;
            }
            else
            {
                isTest = false;
            }

            if ((cotByte & 0x40) != 0)
            {
                isNegative = true;
            }
            else
            {
                isNegative = false;
            }

            cot = (CauseOfTransmission)(cotByte & 0x3f);

            if (parameters.SizeOfCOT == 2)
            {
                oa = msg[bufPos++];
            }

            ca = msg[bufPos++];

            if (parameters.SizeOfCA > 1)
            {
                ca += (msg[bufPos++] * 0x100);
            }

            int payloadSize = msgLength - bufPos;

            payload = new byte[payloadSize];

            /* save payload */
            Buffer.BlockCopy(msg, bufPos, payload, 0, payloadSize);
        }
Example #21
0
        public void SetScaledValueCommandWithTimeTag(int commonAddress, CauseOfTransmission cot,
                                                     int informationObjectAddress, IeScaledValue scaledValue, IeQualifierOfSetPointCommand qualifier,
                                                     IeTime56 timeTag)
        {
            var aSdu = new ASdu(TypeId.C_SE_TB_1, false, cot, false, false, originatorAddress, commonAddress,
                                new[]
            {
                new InformationObject(informationObjectAddress,
                                      new[] { new InformationElement[] { scaledValue, qualifier, timeTag } })
            });

            Send(aSdu);
        }
Example #22
0
 public ASdu(TypeId typeId, bool isSequenceOfElements, int sequenceLength,
             CauseOfTransmission causeOfTransmission, bool test, bool negativeConfirm, int originatorAddress,
             int commonAddress, byte[] privateInformation)
 {
     this.typeId              = typeId;
     IsSequenceOfElements     = isSequenceOfElements;
     this.causeOfTransmission = causeOfTransmission;
     this.test               = test;
     this.negativeConfirm    = negativeConfirm;
     this.originatorAddress  = originatorAddress;
     this.commonAddress      = commonAddress;
     informationObjects      = null;
     this.privateInformation = privateInformation;
     this.sequenceLength     = sequenceLength;
 }
Example #23
0
        /// <summary>
        /// 发送控制命令Sends the control command.
        /// </summary>
        ///
        /// The type ID has to match the type of the InformationObject!
        ///
        /// C_SC_NA_1 -> SingleCommand                  单位遥控命令
        /// C_DC_NA_1 -> DoubleCommand                  双位遥控命令
        /// C_RC_NA_1 -> StepCommand                    档位调节命令
        /// C_SC_TA_1 -> SingleCommandWithCP56Time2a
        /// C_SE_NA_1 -> SetpointCommandNormalized      归一化设定值
        /// C_SE_NB_1 -> SetpointCommandScaled          标度化设定值
        /// C_SE_NC_1 -> SetpointCommandShort           短浮点设定值
        /// C_BO_NA_1 -> Bitstring32Command
        ///
        ///
        /// <param name="typeId">类型标识Type ID of the control command</param>
        /// <param name="cot">传送原因Cause of transmission (use ACTIVATION to start a control sequence)</param>
        /// <param name="ca">公共地址Common address</param>
        /// <param name="sc">信息体对象Information object of the command</param>
        /// <exception cref="ConnectionException">description</exception>
        public void SendControlCommand(TypeID typeId, CauseOfTransmission cot, int ca, InformationObject sc)
        {
            Frame frame = new T104Frame();

            EncodeIdentificationField(frame, typeId, 1 /* SQ:false; NumIX:1 */, cot, ca);

            sc.Encode(frame, parameters, false);

            if (debugOutput)
            {
                Console.WriteLine("Encoded " + typeId.ToString() + " with " + frame.GetMsgSize() + " bytes.");
            }

            sendIMessage(frame);
        }
Example #24
0
        /// <summary>
        /// 复位进程命令Sends a reset process command (C_RP_NA_1 typeID: 105).
        /// <para>1. 必须慎重使用复位进程命令</para>
        /// <para>2. 需要通信双方技术人员交流并去人复位条件方可进行</para>
        /// </summary>
        /// <param name="cot">
        /// 传送原因Cause of transmission
        /// <para>控制方向</para>
        /// <para>  6  激活</para>
        /// <para>监视方向</para>
        /// <para>  7  激活确认</para>
        /// <para>  10  激活终止</para>
        /// <para>  44  未知的类型标识</para>
        /// <para>  45  未知的传送原因</para>
        /// <para>  46  未知的应用服务数据单元公共地址 cot</para>
        /// <para>  47  未知的信息对象地址</para>
        /// </param>
        /// <param name="ca">公共地址Common address</param>
        /// <param name="qrp">
        /// 复位进程命令限定词Qualifier of reset process command
        /// <para>0:  未用</para>
        /// <para>1:  进程的总复位</para>
        /// <para>2:  复位时间缓冲区等待处理的带时标信息</para>
        /// </param>
        /// <exception cref="ConnectionException">description</exception>
        public void SendResetProcessCommand(CauseOfTransmission cot, int ca, byte qrp)
        {
            Frame frame = new T104Frame();

            EncodeIdentificationField(frame, TypeID.C_RP_NA_1, 1, cot, ca);

            EncodeIOA(frame, 0);

            frame.SetNextByte(qrp);

            if (debugOutput)
            {
                Console.WriteLine("Encoded C_RP_NA_1 with " + frame.GetMsgSize() + " bytes.");
            }

            sendIMessage(frame);
        }
Example #25
0
        /// <summary>
        /// Sends a delay acquisition command (C_CD_NA_1 typeID: 106).
        /// </summary>
        /// <param name="cot">Cause of transmission</param>
        /// <param name="ca">Common address</param>
        /// <param name="delay">delay for acquisition</param>
        /// <exception cref="ConnectionException">description</exception>
        public void SendDelayAcquisitionCommand(CauseOfTransmission cot, int ca, CP16Time2a delay)
        {
            Frame frame = new T104Frame();

            EncodeIdentificationField(frame, TypeID.C_CD_NA_1, 1, cot, ca);

            EncodeIOA(frame, 0);

            frame.AppendBytes(delay.GetEncodedValue());

            if (debugOutput)
            {
                Console.WriteLine("Encoded C_CD_NA_1 with " + frame.GetMsgSize() + " bytes.");
            }

            sendIMessage(frame);
        }
Example #26
0
        /// <summary>
        /// 发送站召唤(类型标识100),Sends the interrogation command.
        /// <para>站召唤和组召唤都行</para>
        /// <para>站端回答镜像报文确认或否定</para>
        /// </summary>
        /// <param name="cot">
        /// 传送原因Cause of transmission
        /// <para>控制方向</para>
        /// <para>  6  激活</para>
        /// <para>  8  停止激活</para>
        /// <para>监视方向</para>
        /// <para>  7  激活确认</para>
        /// <para>  9  停止激活确认</para>
        /// <para>  10  激活终止</para>
        /// <para>  44  未知的类型标识</para>
        /// <para>  45  未知的传送原因</para>
        /// <para>  46  未知的应用服务数据单元公共地址 cot</para>
        /// <para>  47  未知的信息对象地址</para>
        /// </param>
        /// <param name="ca">公共地址Common address</param>
        /// <param name="qoi">
        /// 召唤限定词(20全站召唤),Qualifier of interrogation (20 = station interrogation)
        /// <para>0  未用</para>
        /// <para>1-19  未定义</para>
        /// <para>20    全站召唤</para>
        /// <para>21-28    分别为召唤第1-8组信息(遥信信息)</para>
        /// <para>29-34    分别为召唤第9-14组信息(遥测信息)</para>
        /// <para>35    召唤第15组信息(档位信息)</para>
        /// <para>36    召唤第16组信息(远动中断状态信息)</para>
        /// <para>37-255    未定义</para>
        /// </param>
        /// <exception cref="ConnectionException">description</exception>
        public void SendInterrogationCommand(CauseOfTransmission cot, int ca, byte qoi)
        {
            Frame frame = new T104Frame();

            EncodeIdentificationField(frame, TypeID.C_IC_NA_1, 1, cot, ca);

            EncodeIOA(frame, 0);

            /* encode COI (7.2.6.21) */
            frame.SetNextByte(qoi); /* 20 = station interrogation */

            if (debugOutput)
            {
                Console.WriteLine("Encoded C_IC_NA_1 with " + frame.GetMsgSize() + " bytes.");
            }

            sendIMessage(frame);
        }
Example #27
0
        /// <summary>
        /// 发送累计量召唤命令,Sends the counter interrogation command (C_CI_NA_1 typeID: 101)
        /// </summary>
        /// <param name="cot">传送原因 Cause of transmission</param>
        /// <param name="ca">公共地址Common address</param>
        /// <param name="qcc">
        /// 召唤限定词(应该跟站召一样,下面列出来参考下)Qualifier of counter interrogation command
        /// <para>0  未用</para>
        /// <para>1-19  未定义</para>
        /// <para>20    全站召唤</para>
        /// <para>21-28    分别为召唤第1-8组信息(遥信信息)</para>
        /// <para>29-34    分别为召唤第9-14组信息(遥测信息)</para>
        /// <para>35    召唤第15组信息(档位信息)</para>
        /// <para>36    召唤第16组信息(远动中断状态信息)</para>
        /// <para>37-255    未定义</para>
        /// </param>
        /// <exception cref="ConnectionException">description</exception>
        public void SendCounterInterrogationCommand(CauseOfTransmission cot, int ca, byte qcc)
        {
            Frame frame = new T104Frame();

            EncodeIdentificationField(frame, TypeID.C_CI_NA_1, 1, cot, ca);

            EncodeIOA(frame, 0);

            /* encode QCC */
            frame.SetNextByte(qcc);

            if (debugOutput)
            {
                Console.WriteLine("Encoded C_CI_NA_1 with " + frame.GetMsgSize() + " bytes.");
            }

            sendIMessage(frame);
        }
Example #28
0
        public ASdu(TypeId typeId, bool isSequenceOfElements, CauseOfTransmission causeOfTransmission, bool test,
                    bool negativeConfirm, int originatorAddress, int commonAddress, InformationObject[] informationObjects)
        {
            IsSequenceOfElements = isSequenceOfElements;

            this.typeId = typeId;
            this.causeOfTransmission = causeOfTransmission;
            this.test               = test;
            this.negativeConfirm    = negativeConfirm;
            this.originatorAddress  = originatorAddress;
            this.commonAddress      = commonAddress;
            this.informationObjects = informationObjects;

            privateInformation = null;

            sequenceLength = isSequenceOfElements
                ? informationObjects[0].GetInformationElements().Length
                : informationObjects.Length;
        }
Example #29
0
        public ASdu(TypeId typeId, bool isSequenceOfElements, CauseOfTransmission causeOfTransmission, bool test,
            bool negativeConfirm, int originatorAddress, int commonAddress, InformationObject[] informationObjects)
        {
            IsSequenceOfElements = isSequenceOfElements;

            this.typeId = typeId;
            this.causeOfTransmission = causeOfTransmission;
            this.test = test;
            this.negativeConfirm = negativeConfirm;
            this.originatorAddress = originatorAddress;
            this.commonAddress = commonAddress;
            this.informationObjects = informationObjects;

            privateInformation = null;

            sequenceLength = isSequenceOfElements
                ? informationObjects[0].GetInformationElements().Length
                : informationObjects.Length;
        }
Example #30
0
        /// <summary>
        /// 编码“数据单元标识符”将类型标识、可变结构限定词,传送原因和公共地址编码进去
        /// <para>注:这里是ASDU的头,应该首先调用</para>
        /// </summary>
        /// <param name="frame">需要编码的帧</param>
        /// <param name="typeId">类型标识</param>
        /// <param name="vsq">
        /// <para> 可变结构限定词  SQ+number</para>
        /// <para> SQ 离散或者顺序,0:离散,1连续</para>
        /// <para> number,信息对象数目 0~127</para>
        /// </param>
        /// <param name="cot">传送原因</param>
        /// <param name="ca">公共地址</param>
        private void EncodeIdentificationField(Frame frame, TypeID typeId,
                                               int vsq, CauseOfTransmission cot, int ca)
        {
            frame.SetNextByte((byte)typeId);
            frame.SetNextByte((byte)vsq); /* SQ:false; NumIX:1 */

            /* encode COT */
            frame.SetNextByte((byte)cot);
            if (parameters.SizeOfCOT == 2)
            {
                frame.SetNextByte((byte)parameters.OriginatorAddress);
            }

            /* encode CA */
            frame.SetNextByte((byte)(ca & 0xff));
            if (parameters.SizeOfCA == 2)
            {
                frame.SetNextByte((byte)((ca & 0xff00) >> 8));
            }
        }
Example #31
0
        /// <summary>
        /// 初始化ASDU,使用一大堆参数
        /// </summary>
        /// <param name="typeId">类型标识</param>
        /// <param name="cot">传送原因</param>
        /// <param name="isTest">是否测试</param>
        /// <param name="isNegative">肯定/否定回答</param>
        /// <param name="ca"> 应用服务数据单元公共地址 </param>
        /// <param name="ra">记录地址</param>
        /// <param name="isSequence">是否连续单元(用于构造VSQ),数量根据添加来变</param>
        public ASDU(TypeID typeId, CauseOfTransmission cot, bool isTest, bool isNegative, int ca, RecordAddress ra, bool isSequence)
        {
            this.typeId     = typeId;
            this.cot        = cot;
            this.isTest     = isTest;
            this.isNegative = isNegative;
            this.ra         = ra;
            this.ca         = ca;

            if (isSequence)
            {
                this.vsq = 0x80;
            }
            else
            {
                this.vsq = 0;
            }

            this.hasTypeId = true;
        }
Example #32
0
        public ASDU(ConnectionParameters parameters, TypeID typeId, CauseOfTransmission cot, bool isTest, bool isNegative, byte oa, int ca, bool isSequence)
        {
            this.parameters = parameters;
            this.typeId     = typeId;
            this.cot        = cot;
            this.isTest     = isTest;
            this.isNegative = isNegative;
            this.oa         = oa;
            this.ca         = ca;
            this.spaceLeft  = IEC60870_5_104_MAX_ASDU_LENGTH -
                              parameters.SizeOfTypeId - parameters.SizeOfVSQ - parameters.SizeOfCA - parameters.SizeOfCOT;

            if (isSequence)
            {
                this.vsq = 0x80;
            }
            else
            {
                this.vsq = 0;
            }

            this.hasTypeId = true;
        }
Example #33
0
        internal ASDU(ApplicationLayerParameters parameters, TypeID typeId, CauseOfTransmission cot, bool isTest, bool isNegative, byte oa, int ca, bool isSequence)
        {
            this.parameters = parameters;
            this.typeId     = typeId;
            this.cot        = cot;
            this.isTest     = isTest;
            this.isNegative = isNegative;
            this.oa         = oa;
            this.ca         = ca;
            this.spaceLeft  = parameters.MaxAsduLength -
                              parameters.SizeOfTypeId - parameters.SizeOfVSQ - parameters.SizeOfCA - parameters.SizeOfCOT;

            if (isSequence)
            {
                this.vsq = 0x80;
            }
            else
            {
                this.vsq = 0;
            }

            this.hasTypeId = true;
        }
Example #34
0
        public void DoubleCommand(int commonAddress, CauseOfTransmission cot, int informationObjectAddress,
            IeDoubleCommand doubleCommand)
        {
            var aSdu = new ASdu(TypeId.C_DC_NA_1, false, cot, false, false, originatorAddress, commonAddress,
                new[]
                {
                    new InformationObject(informationObjectAddress,
                        new[] {new InformationElement[] {doubleCommand}})
                });

            Send(aSdu);
        }
Example #35
0
        public ASdu(BinaryReader reader, ConnectionSettings settings, int aSduLength)
        {
            int typeIdCode = reader.ReadByte();

            typeId = (TypeId) typeIdCode;

            int tempbyte = reader.ReadByte();

            IsSequenceOfElements = (tempbyte & 0x80) == 0x80;

            int numberOfSequenceElements;
            int numberOfInformationObjects;

            sequenceLength = tempbyte & 0x7f;
            if (IsSequenceOfElements)
            {
                numberOfSequenceElements = sequenceLength;
                numberOfInformationObjects = 1;
            }
            else
            {
                numberOfInformationObjects = sequenceLength;
                numberOfSequenceElements = 1;
            }

            tempbyte = reader.ReadByte();
            causeOfTransmission = (CauseOfTransmission) (tempbyte & 0x3f);
            test = (tempbyte & 0x80) == 0x80;
            negativeConfirm = (tempbyte & 0x40) == 0x40;

            if (settings.CotFieldLength == 2)
            {
                originatorAddress = reader.ReadByte();
                aSduLength--;
            }
            else
            {
                originatorAddress = -1;
            }

            if (settings.CommonAddressFieldLength == 1)
            {
                commonAddress = reader.ReadByte();
            }
            else
            {
                commonAddress = reader.ReadByte() + (reader.ReadByte() << 8);
                aSduLength--;
            }

            if (typeIdCode < 128)
            {
                informationObjects = new InformationObject[numberOfInformationObjects];

                for (var i = 0; i < numberOfInformationObjects; i++)
                {
                    informationObjects[i] = new InformationObject(reader, typeId, numberOfSequenceElements, settings);
                }

                privateInformation = null;
            }
            else
            {
                informationObjects = null;
                privateInformation = reader.ReadBytes(aSduLength - 4);
            }
        }
Example #36
0
        public void DelayAcquisitionCommand(int commonAddress, CauseOfTransmission cot, IeTime16 time)
        {
            var aSdu = new ASdu(TypeId.C_CD_NA_1, false, cot, false, false, originatorAddress, commonAddress,
                new[] {new InformationObject(0, new[] {new InformationElement[] {time}})});

            Send(aSdu);
        }
Example #37
0
        public void CallOrSelectFiles(int commonAddress, CauseOfTransmission cot, int informationObjectAddress,
            IeNameOfFile nameOfFile, IeNameOfSection nameOfSection, IeSelectAndCallQualifier qualifier)
        {
            var aSdu = new ASdu(TypeId.F_SC_NA_1, false, cot, false, false, originatorAddress, commonAddress,
                new[]
                {
                    new InformationObject(informationObjectAddress,
                        new[] {new InformationElement[] {nameOfFile, nameOfSection, qualifier}})
                });

            Send(aSdu);
        }
Example #38
0
        public void SetShortFloatCommandWithTimeTag(int commonAddress, CauseOfTransmission cot,
            int informationObjectAddress, IeShortFloat shortFloat, IeQualifierOfSetPointCommand qualifier,
            IeTime56 timeTag)
        {
            var aSdu = new ASdu(TypeId.C_SE_TC_1, false, cot, false, false, originatorAddress, commonAddress,
                new[]
                {
                    new InformationObject(informationObjectAddress,
                        new[] {new InformationElement[] {shortFloat, qualifier, timeTag}})
                });

            Send(aSdu);
        }
Example #39
0
        public void SetScaledValueCommand(int commonAddress, CauseOfTransmission cot, int informationObjectAddress,
            IeScaledValue scaledValue, IeQualifierOfSetPointCommand qualifier)
        {
            var aSdu = new ASdu(TypeId.C_SE_NB_1, false, cot, false, false, originatorAddress, commonAddress,
                new[]
                {
                    new InformationObject(informationObjectAddress,
                        new[] {new InformationElement[] {scaledValue, qualifier}})
                });

            Send(aSdu);
        }
Example #40
0
        public void RegulatingStepCommandWithTimeTag(int commonAddress, CauseOfTransmission cot,
            int informationObjectAddress, IeRegulatingStepCommand regulatingStepCommand, IeTime56 timeTag)
        {
            var aSdu = new ASdu(TypeId.C_RC_TA_1, false, cot, false, false, originatorAddress, commonAddress,
                new[]
                {
                    new InformationObject(informationObjectAddress,
                        new[] {new InformationElement[] {regulatingStepCommand, timeTag}})
                });

            Send(aSdu);
        }
Example #41
0
        public void ParameterActivation(int commonAddress, CauseOfTransmission cot, int informationObjectAddress,
            IeQualifierOfParameterActivation qualifier)
        {
            var aSdu = new ASdu(TypeId.P_AC_NA_1, false, cot, false, false, originatorAddress, commonAddress,
                new[]
                {
                    new InformationObject(informationObjectAddress,
                        new[] {new InformationElement[] {qualifier}})
                });

            Send(aSdu);
        }
Example #42
0
        public void Interrogation(int commonAddress, CauseOfTransmission cot, IeQualifierOfInterrogation qualifier)
        {
            var aSdu = new ASdu(TypeId.C_IC_NA_1, false, cot, false, false, originatorAddress, commonAddress,
                new[] {new InformationObject(0, new[] {new InformationElement[] {qualifier}})});

            Send(aSdu);
        }