예제 #1
0
        /// <summary>
        /// APDU初始化
        /// </summary>
        /// <param name="transmitSeqNum">发送序列号</param>
        /// <param name="ReceiveSeqNum">接收序列号</param>
        /// <param name="typeID">类型ID</param>
        /// <param name="isquense">是否序列号 true-序列化 false-非序列化</param>
        /// <param name="objectCount">信息对象数目数目</param>
        /// <param name="cot">传输原因</param>
        /// <param name="ASDUPublicAddress">公共地址</param>
        public APDU(UInt16 transmitSeqNum, UInt16 ReceiveSeqNum, TypeIdentification typeID, bool isquense, byte objectCount,
                    CauseOfTransmissionList cot, UInt16 ASDUPublicAddress, UInt32 objectAddress)
        {
            ASDU = new ApplicationServiceDataUnit((byte)typeID, objectCount, isquense, (byte)cot, ASDUPublicAddress);
            //信息对象地址为0
            ASDU.InformationObject[0] = ElementTool.GetBit7_0(objectAddress);
            ASDU.InformationObject[1] = ElementTool.GetBit15_8(objectAddress);
            ASDU.InformationObject[2] = ElementTool.GetBit23_16(objectAddress);
            var apduLen = 4 + ASDU.Length; //控制域长度4 + ASDU长度

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

            TimeStamp = DateTime.Now;
        }
 /// <summary>
 /// 针对序列化的SQ = 1,设置首地址地址
 /// </summary>
 /// <returns></returns>
 public bool SetSequenceFirstObjectAddress(UInt32 addrss)
 {
     if (IsSequence)
     {
         informationObject[0] = ElementTool.GetBit7_0(addrss);
         informationObject[1] = ElementTool.GetBit15_8(addrss);
         informationObject[2] = ElementTool.GetBit23_16(addrss);
         return(true);
     }
     else
     {
         return(false);
     }
 }
예제 #3
0
        /// <summary>
        /// 针对遥信信息,以此添加信息对象,单点,双点信息,非序列化
        /// </summary>
        /// <param name="telesignalisationAddress">遥信地址</param>
        /// <param name="qds">带品质描述单点或双点信息</param>
        public bool AddInformationObject(UInt32 telesignalisationAddress, byte qds)
        {
            bool state = false;

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

            data[0] = ElementTool.GetBit7_0(telesignalisationAddress);
            data[1] = ElementTool.GetBit15_8(telesignalisationAddress);
            data[2] = ElementTool.GetBit23_16(telesignalisationAddress);
            data[3] = qds;
            ASDU.AddInformationObject(data, 4);

            return(true);
        }
예제 #4
0
        /// <summary>
        /// 添加信息对象,非序列化,浮点数+地址+品质描述词
        /// </summary>
        /// <param name="Address">遥测地址</param>
        /// <param name="sf">浮点数</param>
        public bool AddInformationObject(UInt32 address, ShortFloating sf)
        {
            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);
            ASDU.AddInformationObject(data, (byte)data.Length);

            return(true);
        }
예제 #5
0
        /// <summary>
        /// 针对遥测信息,,非序列化
        /// </summary>
        /// <param name="Address">遥测地址</param>
        /// <param name="nve">归一化值</param>
        /// <param name="time">时间信标</param>
        public bool AddInformationObject(UInt32 address, NormalizationValue nve, CP56Time2a time)
        {
            bool state = false;

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

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

            return(true);
        }
예제 #6
0
        /// <summary>
        /// 针对遥信信息,以此添加信息对象,单点,双点信息,非序列化
        /// </summary>
        /// <param name="telesignalisationAddress">遥信地址</param>
        /// <param name="qds">带品质描述单点或双点信息</param>
        public bool AddInformationObject(UInt32 telesignalisationAddress, byte qds, CP56Time2a time)
        {
            bool state = false;

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

            data[0] = ElementTool.GetBit7_0(telesignalisationAddress);
            data[1] = ElementTool.GetBit15_8(telesignalisationAddress);
            data[2] = ElementTool.GetBit23_16(telesignalisationAddress);
            data[3] = qds;
            Array.Copy(time.GetDataArray(), 0, data, 4, time.GetDataArray().Length);

            ASDU.AddInformationObject(data, (byte)(4 + time.GetDataArray().Length));

            return(true);
        }
예제 #7
0
        /// <summary>
        /// 获取信息对象列表
        /// </summary>
        /// <returns>信息元素 元组中以此为序号,信息, 时标(可选)</returns>
        public List <Tuple <UInt32, object, object> > GetInformationList()
        {
            try
            {
                var list = new List <Tuple <UInt32, object, object> >();
                switch ((TypeIdentification)ASDU.TypeId)
                {
                //遥信信息
                case TypeIdentification.M_SP_NA_1:    //单点信息
                case TypeIdentification.M_DP_NA_1:    //双点信息
                {
                    if (ASDU.IsSequence)
                    {
                        // int len = 1;
                        var addr = ElementTool.CombinationByte(ASDU.InformationObject[0], ASDU.InformationObject[1], ASDU.InformationObject[2]);
                        for (int i = 0; i < ASDU.InformationObjectCount; i++)
                        {
                            var m = ASDU.InformationObject[3 + i];
                            list.Add(new Tuple <UInt32, object, object>((UInt32)(addr + i), m, null));
                        }
                    }
                    else
                    {
                        int len = 4;
                        for (int i = 0; i < ASDU.InformationObjectCount; i++)
                        {
                            var addr1 = ElementTool.CombinationByte(ASDU.InformationObject[0 + len * i],
                                                                    ASDU.InformationObject[1 + len * i], ASDU.InformationObject[2 + len * i]);
                            var m = ASDU.InformationObject[3 + len * i];

                            list.Add(new Tuple <UInt32, object, object>(addr1, m, null));
                        }
                    }
                    break;
                }

                case TypeIdentification.M_SP_TB_1:    //带CP56Time2a时标的单点信息
                case TypeIdentification.M_DP_TB_1:    //带CP56Time2a时标的双点信息
                {
                    if (ASDU.IsSequence)
                    {
                        int len  = 1 + 7;
                        var addr = ElementTool.CombinationByte(ASDU.InformationObject[0], ASDU.InformationObject[1], ASDU.InformationObject[2]);
                        for (int i = 0; i < ASDU.InformationObjectCount; i++)
                        {
                            var m    = ASDU.InformationObject[3 + i * len];
                            var data = new byte[7];
                            Array.Copy(ASDU.InformationObject, i * len + 4, data, 0, 7);
                            var t = new CP56Time2a(data);
                            list.Add(new Tuple <UInt32, object, object>((UInt32)(addr + i), m, t));
                        }
                    }
                    else
                    {
                        int len = 3 + 1 + 7;
                        for (int i = 0; i < ASDU.InformationObjectCount; i++)
                        {
                            var addr1 = ElementTool.CombinationByte(ASDU.InformationObject[0 + len * i],
                                                                    ASDU.InformationObject[1 + 8 * i], ASDU.InformationObject[2 + +len * i]);

                            var m    = ASDU.InformationObject[3 + len * i];
                            var data = new byte[7];
                            Array.Copy(ASDU.InformationObject, i * len + 4, data, 0, 7);
                            var t = new CP56Time2a(data);

                            list.Add(new Tuple <UInt32, object, object>(addr1, m, t));
                        }
                    }
                    break;
                }

                //遥测信息
                case TypeIdentification.M_ME_NA_1:    //测量值,归一化值
                {
                    break;
                }

                case TypeIdentification.M_ME_NC_1:    //测量值,短浮点数
                case TypeIdentification.M_IT_NA_1:    //累积量
                {
                    if (ASDU.IsSequence)
                    {
                        int len  = 4 + 1;
                        var addr = ElementTool.CombinationByte(ASDU.InformationObject[0], ASDU.InformationObject[1], ASDU.InformationObject[2]);
                        for (int i = 0; i < ASDU.InformationObjectCount; i++)
                        {
                            var data = new byte[5];
                            Array.Copy(ASDU.InformationObject, i * len + 3, data, 0, 5);
                            var m = new ShortFloating(data);
                            var q = new QualityDescription(data[4]);
                            list.Add(new Tuple <UInt32, object, object>((UInt32)(addr + i), m.Value, q));
                        }
                    }
                    else
                    {
                        int len = 12;        //4 + 1 + 7
                        for (int i = 0; i < ASDU.InformationObjectCount; i++)
                        {
                            var addr1 = ElementTool.CombinationByte(ASDU.InformationObject[0 + len * i],
                                                                    ASDU.InformationObject[1 + len * i], ASDU.InformationObject[2 + +len * i]);
                            var data = new byte[4];
                            Array.Copy(ASDU.InformationObject, i * len + 3, data, 0, 4);
                            var m = new ShortFloating(data);
                            list.Add(new Tuple <UInt32, object, object>(addr1, m, null));
                        }
                    }
                    break;
                }

                case TypeIdentification.M_ME_TD_1:    //带CP56Time2a时标的测量值,归一化值
                case TypeIdentification.M_ME_TF_1:    //带CP56Time2a时标的测量值,短浮点数
                {
                    break;
                }


                default:
                {
                    return(null);
                    //break;
                }
                }

                return(list);
            }
            catch (Exception)
            {
                return(null);
            }
        }