コード例 #1
0
        public FileCall(ApplicationLayerParameters parameters, byte[] msg, int startIndex) : base(parameters, msg, startIndex)
        {
            startIndex += 2; /* skip IOA */
            startIndex += 1; /* skip AdditionalPacketType */

            if ((msg.Length - startIndex) < GetEncodedSize())
            {
                throw new ASDUParsingException("Message too small");
            }

            startIndex += 1; /* skip OPT */

            _folderId  = msg[startIndex++];
            _folderId += msg[startIndex++] * 0x100;
            _folderId += msg[startIndex++] * 0x10000;
            _folderId += msg[startIndex++] * 0x1000000;

            _folderNameLength = msg[startIndex++];

            for (int i = 0; i < _folderNameLength; i++)
            {
                _folderName += (char)msg[startIndex++];
            }

            if ((msg.Length - startIndex) < 15)
            {
                throw new ASDUParsingException("Message too small");
            }

            _callFlag = (CallFlag)msg[startIndex++];

            _startTime  = new CP56Time2a(msg, startIndex);
            startIndex += 7;
            _endTime    = new CP56Time2a(msg, startIndex);
        }
コード例 #2
0
        public FileDirectory(int objectAddress, NameOfFile nof, int lengthOfFile, int status, bool LFD, bool FOR, bool FA, CP56Time2a creationTime)
            : base(objectAddress)
        {
            this.nof          = nof;
            this.lengthOfFile = lengthOfFile;

            if (status < 0)
            {
                status = 0;
            }
            else if (status > 31)
            {
                status = 31;
            }

            byte sof = (byte)status;

            if (LFD)
            {
                sof += 0x20;
            }

            if (FOR)
            {
                sof += 0x40;
            }

            if (FA)
            {
                sof += 0x80;
            }

            this.sof          = sof;
            this.creationTime = creationTime;
        }
コード例 #3
0
 public EventOfProtectionEquipmentWithCP56Time2a(int ioa, SingleEvent singleEvent, CP16Time2a elapsedTime, CP56Time2a timestamp)
     : base(ioa)
 {
     this.singleEvent = singleEvent;
     this.elapsedTime = elapsedTime;
     this.timestamp   = timestamp;
 }
コード例 #4
0
        internal FileDirectory(ApplicationLayerParameters parameters, byte[] msg, int startIndex, bool isSequence)
            : base(parameters, msg, startIndex, isSequence)
        {
            if (!isSequence)
            {
                startIndex += parameters.SizeOfIOA; /* skip IOA */
            }
            if ((msg.Length - startIndex) < GetEncodedSize())
            {
                throw new ASDUParsingException("Message too small");
            }

            int nofValue;

            nofValue  = msg[startIndex++];
            nofValue += (msg[startIndex++] * 0x100);

            nof = (NameOfFile)nofValue;

            lengthOfFile  = msg[startIndex++];
            lengthOfFile += (msg[startIndex++] * 0x100);
            lengthOfFile += (msg[startIndex++] * 0x10000);

            sof = msg[startIndex++];

            /* parse CP56Time2a (creation time of file) */
            creationTime = new CP56Time2a(msg, startIndex);
        }
コード例 #5
0
 /// <summary>
 /// 添加波形片段
 /// </summary>
 /// <param name="rwf">波形信息</param>
 /// <returns>添加结果 true-添加成功, fasle-添加失败</returns>
 public bool AddInformation(RecordWaveform rwf)
 {
     //判断通道号
     if (Channel == rwf.Channel)
     {
         if (TimeStamp == null)
         {
             //初始化时间戳
             TimeStamp = new CP56Time2a(rwf.TimeStamp.GetDataArray());
         }
         else
         {
             //判断时间戳是否相同,不同则返回
             if (!TimeStamp.IsEqual(rwf.TimeStamp))
             {
                 return(false);
             }
         }
         if (RecordMask[rwf.WaveformNum - 1][rwf.GroupNum - 1] == false)
         {
             RecordMask[rwf.WaveformNum - 1][rwf.GroupNum - 1] = true;
             //计算数据存储索引
             int index = (rwf.WaveformNum - 1) * WavePointNum + (rwf.GroupNum - 1) * 64;
             Array.Copy(rwf.RawAdcArray, 0, WaveDataAdc, index, rwf.RawAdcArray.Length);
             return(true);
         }
         else
         {
             throw new Exception("重复添加波形--RecordDataItem-AddInformation");
         }
     }
     return(false);
 }
コード例 #6
0
 /// <summary>
 /// 设置文件属性
 /// </summary>
 /// <param name="name">名称</param>
 /// <param name="size">文件大小</param>
 /// <param name="time">时间</param>
 public void SetFileAttribute(string name, UInt32 size, CP56Time2a time)
 {
     Name     = name;
     Size     = size;
     Time     = time;
     Property = 0;
 }
コード例 #7
0
        private static void AddToASDU(int objectAddress, float value, CP56Time2a time)
        {
            lock (_lastSentData)
            {
                if (_lastSentData.ContainsKey(objectAddress))
                {
                    if (Math.Abs(_lastSentData[objectAddress] - value) < 0.0000001)
                    {
                        return;
                    }

                    _lastSentData[objectAddress] = value;
                }
                else
                {
                    _lastSentData.Add(objectAddress, value);
                }
            }

            var io = new MeasuredValueShortWithCP56Time2a(objectAddress, value, _qd, time);

            if (!_asdu.AddInformationObject(io))
            {
                SendASDU();
                if (_asdu.AddInformationObject(io) == false)
                {
                    throw new Exception("Cannot add information object to ASDU");
                }
            }
        }
コード例 #8
0
 public FileDirectory(int objectAddress, NameOfFile nof, int lengthOfFile, byte sof, CP56Time2a creationTime)
     : base(objectAddress)
 {
     this.nof          = nof;
     this.lengthOfFile = lengthOfFile;
     this.sof          = sof;
     this.creationTime = creationTime;
 }
コード例 #9
0
ファイル: CS101Master.cs プロジェクト: riclolsen/json-scada
        public override void SendClockSyncCommand(int ca, CP56Time2a time)
        {
            ASDU asdu = new ASDU(appLayerParameters, CauseOfTransmission.ACTIVATION, false, false, (byte)appLayerParameters.OA, ca, false);

            asdu.AddInformationObject(new ClockSynchronizationCommand(0, time));

            EnqueueUserData(asdu);
        }
コード例 #10
0
 public PackedOutputCircuitInfoWithCP56Time2a(int objectAddress, OutputCircuitInfo oci, QualityDescriptorP qdp, CP16Time2a operatingTime, CP56Time2a timestamp)
     : base(objectAddress)
 {
     this.oci           = oci;
     this.qdp           = qdp;
     this.operatingTime = operatingTime;
     this.timestamp     = timestamp;
 }
コード例 #11
0
 public PackedStartEventsOfProtectionEquipmentWithCP56Time2a(int objectAddress, StartEvent spe, QualityDescriptorP qdp, CP16Time2a elapsedTime, CP56Time2a timestamp)
     : base(objectAddress)
 {
     this.spe         = spe;
     this.qdp         = qdp;
     this.elapsedTime = elapsedTime;
     this.timestamp   = timestamp;
 }
コード例 #12
0
ファイル: CS101Master.cs プロジェクト: riclolsen/json-scada
        public override void SendTestCommandWithCP56Time2a(int ca, ushort tsc, CP56Time2a time)
        {
            ASDU asdu = new ASDU(appLayerParameters, CauseOfTransmission.ACTIVATION, false, false, (byte)appLayerParameters.OA, ca, false);

            asdu.AddInformationObject(new TestCommandWithCP56Time2a(tsc, time));

            EnqueueUserData(asdu);
        }
コード例 #13
0
 public FileCall(int objectAddress, int folderId, string folderName, CallFlag callFlag, CP56Time2a startTime, CP56Time2a endTime) : base(objectAddress, AdditionalPacketType.FILE_TRANSFER, OptionID.CALL_FILES)
 {
     _folderId         = folderId;
     _folderNameLength = (byte)(folderName == null ? 0 : folderName.Length);
     _folderName       = folderName;
     _callFlag         = callFlag;
     _startTime        = startTime;
     _endTime          = endTime;
 }
コード例 #14
0
 /// <summary>
 /// 将数据局数组转换成对应元素属性
 /// </summary>
 private void AttributeDataToElement()
 {
     Name = UnicodeEncoding.ASCII.GetString(attributeData, 1, attributeData[0]);
     Size = ElementTool.CombinationByte(attributeData[NameLen + 1],
                                        attributeData[NameLen + 2], attributeData[NameLen + 3],
                                        attributeData[NameLen + 4]);
     Property = attributeData[NameLen + 5];
     Time     = new CP56Time2a(attributeData, NameLen + 6);
 }
コード例 #15
0
 /// <summary>
 /// 文件目录初始化
 /// </summary>
 /// <param name="id">目录ID</param>
 /// <param name="name">目录名称</param>
 /// <param name="flag">召唤标志</param>
 /// <param name="startTime">开始时间</param>
 /// <param name="endTime">结束时间</param>
 public FileDirectoryCalledPacket(UInt32 id, string name, FileCallFlag flag,
                                  CP56Time2a startTime, CP56Time2a endTime)
 {
     OperationSign     = OperatSign.ReadDirectory;
     DirectoryID       = id;
     DirectoryName     = name;
     CallFlag          = flag;
     QueryStartingTime = startTime;
     QueryEndTime      = endTime;
 }
コード例 #16
0
        public void Time(string t, bool isSubstituted, bool isSummerTime)
        {
            var dt       = DateTime.Parse(t);
            var expected = new CP56Time2a(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second, dt.Millisecond, isSubstituted, isSummerTime);
            var buffer   = new byte[7].AsSpan();

            expected.Write(buffer);
            var actual = CP56Time2a.ReadBuffer(buffer);

            Assert.Equal(expected, actual);
        }
コード例 #17
0
ファイル: C_CS_NA_1.cs プロジェクト: jdvor/IEC-60870-5-104
 public ErrorCode TryRead(ReadOnlySpan <byte> buffer)
 {
     try
     {
         Value = CP56Time2a.ReadBuffer(buffer);
         return(ErrorCode.None);
     }
     catch
     {
         return(ErrorCode.InvalidCP56Time2a);
     }
 }
コード例 #18
0
        internal ClockSynchronizationCommand(ApplicationLayerParameters parameters, byte[] msg, int startIndex)
            : base(parameters, msg, startIndex, false)
        {
            startIndex += parameters.SizeOfIOA; /* skip IOA */

            if ((msg.Length - startIndex) < GetEncodedSize())
            {
                throw new ASDUParsingException("Message too small");
            }

            /* parse CP56Time2a (time stamp) */
            newTime = new CP56Time2a(msg, startIndex);
        }
コード例 #19
0
ファイル: SetpointCommands.cs プロジェクト: lego92/EA104
        internal SetpointCommandScaledWithCP56Time2a(ApplicationLayerParameters parameters, byte[] msg, int startIndex) :
            base(parameters, msg, startIndex)
        {
            startIndex += parameters.SizeOfIOA;             /* skip IOA */

            if ((msg.Length - startIndex) < GetEncodedSize())
            {
                throw new ASDUParsingException("Message too small");
            }

            startIndex += 3;             /* scaled value + qualifier */

            this.timestamp = new CP56Time2a(msg, startIndex);
        }
コード例 #20
0
ファイル: SetpointCommands.cs プロジェクト: lego92/EA104
        internal Bitstring32CommandWithCP56Time2a(ApplicationLayerParameters parameters, byte[] msg, int startIndex) :
            base(parameters, msg, startIndex)
        {
            startIndex += parameters.SizeOfIOA;             /* skip IOA */

            if ((msg.Length - startIndex) < GetEncodedSize())
            {
                throw new ASDUParsingException("Message too small");
            }

            startIndex += 4;             /* bitstring */

            this.timestamp = new CP56Time2a(msg, startIndex);
        }
コード例 #21
0
ファイル: SetpointCommands.cs プロジェクト: lego92/EA104
        internal SetpointCommandShortWithCP56Time2a(ApplicationLayerParameters parameters, byte[] msg, int startIndex) :
            base(parameters, msg, startIndex)
        {
            startIndex += parameters.SizeOfIOA;

            if ((msg.Length - startIndex) < GetEncodedSize())
            {
                throw new ASDUParsingException("Message too small");
            }

            startIndex += 5;             /* skip IOA + float + QOS*/

            this.timestamp = new CP56Time2a(msg, startIndex);
        }
コード例 #22
0
        internal TestCommandWithCP56Time2a(ApplicationLayerParameters parameters, byte[] msg, int startIndex)
            : base(parameters, msg, startIndex, false)
        {
            startIndex += parameters.SizeOfIOA; /* skip IOA */

            if ((msg.Length - startIndex) < GetEncodedSize())
            {
                throw new ASDUParsingException("Message too small");
            }

            tsc  = msg[startIndex++];
            tsc += (ushort)(msg[startIndex++] * 256);

            time = new CP56Time2a(msg, startIndex);
        }
コード例 #23
0
        /// <summary>
        /// 针对遥信信息,以此添加信息对象,单点,双点信息,序列化
        /// </summary>
        /// <param name="telesignalisationAddress">遥信地址</param>
        /// <param name="qds">品质描述</param>
        public bool AddInformationObject(byte qds, CP56Time2a time)
        {
            bool state = false;

            if (ASDU.IsSequence == false)
            {
                return(state);
            }
            var data = new byte[1 + time.GetDataArray().Length];// 品质描述1 + 时间戳7

            data[0] = qds;
            Array.Copy(time.GetDataArray(), 0, data, 1, time.GetDataArray().Length);
            ASDU.AddInformationObject(data, 4);

            return(true);
        }
コード例 #24
0
        public IntegratedTotalsWithCP56Time2a(ApplicationLayerParameters parameters, byte[] msg, int startIndex, bool isSequence)
            : base(parameters, msg, startIndex, isSequence)
        {
            if (!isSequence)
            {
                startIndex += parameters.SizeOfIOA; /* skip IOA */
            }
            if ((msg.Length - startIndex) < GetEncodedSize())
            {
                throw new ASDUParsingException("Message too small");
            }

            startIndex += 5; /* BCR */

            timestamp = new CP56Time2a(msg, startIndex);
        }
コード例 #25
0
        /// <summary>
        /// 针对遥测信息,序列化
        /// <summary>
        /// <param name="sf">浮点数</param>
        /// <param name="time">时间信标</param>
        public bool AddInformationObject(ShortFloating sf, CP56Time2a time)
        {
            bool state = false;

            if (ASDU.IsSequence == true)
            {
                return(state);
            }
            var data = new byte[sf.GetDataArray().Length + time.GetDataArray().Length];

            Array.Copy(sf.GetDataArray(), 0, data, 0, sf.GetDataArray().Length);
            Array.Copy(time.GetDataArray(), 0 + sf.GetDataArray().Length, data, sf.GetDataArray().Length, time.GetDataArray().Length);

            ASDU.AddInformationObject(data, (byte)data.Length);
            return(true);
        }
コード例 #26
0
        /// <summary>
        /// MasterCommand APDU初始化,用于时钟同步
        /// </summary>
        /// <param name="typeID">类型ID</param>
        /// <param name="transmitSeqNum">发送序列号</param>
        /// <param name="ReceiveSeqNum">接收序列号</param>
        /// <param name="cot">传输原因</param>
        /// <param name="asduPublicAddress">ASDU公共地址</param>
        /// <param name="time">时间标识</param>
        public MasterCommand(UInt16 transmitSeqNum, UInt16 ReceiveSeqNum, TypeIdentification typeID,
                             CauseOfTransmissionList cot, UInt16 asduPublicAddress, CP56Time2a time)
        {
            ASDU = new ApplicationServiceDataUnit((byte)typeID, (byte)1, false, (byte)cot, asduPublicAddress);
            //信息对象地址为0
            ASDU.InformationObject[0] = 0;
            ASDU.InformationObject[1] = 0;
            ASDU.InformationObject[2] = 0;

            Array.Copy(time.GetDataArray(), 0, ASDU.InformationObject, 3, 7);

            var apduLen = 4 + ASDU.Length; //控制域长度4 + ASDU长度

            APCI = new APCITypeI((byte)apduLen, transmitSeqNum, ReceiveSeqNum);

            TimeStamp = DateTime.Now;
        }
コード例 #27
0
        internal SinglePointWithCP56Time2a(ApplicationLayerParameters parameters, byte[] msg, int startIndex, bool isSequence)
            : base(parameters, msg, startIndex, isSequence)
        {
            if (!isSequence)
            {
                startIndex += parameters.SizeOfIOA; /* skip IOA */
            }
            if ((msg.Length - startIndex) < GetEncodedSize())
            {
                throw new ASDUParsingException("Message too small");
            }

            startIndex += 1; /* skip SIQ */

            /* parse CP56Time2a (time stamp) */
            timestamp = new CP56Time2a(msg, startIndex);
        }
コード例 #28
0
        /// <summary>
        /// 针对遥测信息,,序列化
        /// </summary>
        /// <param name="nve">归一化值</param>
        /// <param name="time">时间信标</param>
        public bool AddInformationObject(NormalizationValue nve, CP56Time2a time)
        {
            bool state = false;

            if (ASDU.IsSequence == true)
            {
                return(state);
            }
            var data = new byte[nve.GetDataArray().Length + time.GetDataArray().Length];

            Array.Copy(nve.GetDataArray(), 0, data, 0, nve.GetDataArray().Length);
            Array.Copy(time.GetDataArray(), 0 + nve.GetDataArray().Length, data, nve.GetDataArray().Length, time.GetDataArray().Length);

            ASDU.AddInformationObject(data, (byte)data.Length);

            return(true);
        }
コード例 #29
0
        /// <summary>
        /// 发送时钟同步命令
        /// </summary>
        /// <param name="cot">传输原因</param>
        /// <param name="time">时间</param>
        private void SendMasterCommand(CauseOfTransmissionList cot, CP56Time2a time)
        {
            try
            {
                var id = TypeIdentification.C_CS_NA_1;//时钟同步
                eventTypeIDManager.AddEventProcess(new EventProperty(id));
                var frame = new MasterCommand(appMessageManager.TransmitSequenceNumber, appMessageManager.RealReceiveSequenceNumber,
                                              id, cot, appMessageManager.ASDUADdress, time);
                var array = frame.GetAPDUDataArray();

                MainTypeIProcess(array, array.Length, appMessageManager.WaitTime, id);
                appMessageManager.UpdateTransmitSequenceNumber();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "SendMasterCommand发送时钟同步命令");
            }
        }
コード例 #30
0
        /// <summary>
        /// 针对遥测信息,,非序列化
        /// </summary>
        /// <param name="Address">遥测地址</param>
        /// <param name="sf">浮点数</param>
        /// <param name="time">时间信标</param>
        public bool AddInformationObject(UInt32 address, ShortFloating sf, CP56Time2a time)
        {
            bool state = false;

            if (ASDU.IsSequence == true)
            {
                return(state);
            }
            var data = new byte[3 + sf.GetDataArray().Length];

            data[0] = ElementTool.GetBit7_0(address);
            data[1] = ElementTool.GetBit15_8(address);
            data[2] = ElementTool.GetBit23_16(address);
            Array.Copy(sf.GetDataArray(), 0, data, 3, sf.GetDataArray().Length);
            Array.Copy(time.GetDataArray(), 0, data, 3 + sf.GetDataArray().Length, time.GetDataArray().Length);
            ASDU.AddInformationObject(data, (byte)data.Length);

            return(true);
        }