Exemple #1
0
        /// <summary>
        /// 生成系数下载数据
        /// </summary>
        /// <param name="array">数据数组</param>
        /// <param name="len">数据长度</param>
        /// <returns>字节数组</returns>
        public byte[] MakeFactorDownloadData(UInt32[] array, int len)
        {
            int    alllen = 7 + len * 4 + 2;
            var    data = new byte[alllen];
            int    i = 7;
            byte   a = 0, b = 0, c = 0, d = 0;
            UInt16 checkSum = 0;
            var    datalen  = len * 4 + 3;

            data[0]   = 0x68;
            data[1]   = (byte)datalen;
            data[2]   = (byte)datalen;
            data[3]   = 0x68;
            data[4]   = 0x01;
            data[5]   = 0x41;
            data[6]   = 0x90;
            checkSum += data[4];
            checkSum += data[5];
            checkSum += data[6];
            //大端模式
            foreach (var m in array)
            {
                a         = data[i++] = ElementTool.GetBit31_24(m);
                b         = data[i++] = ElementTool.GetBit23_16(m);
                c         = data[i++] = ElementTool.GetBit15_8(m);
                d         = data[i++] = ElementTool.GetBit7_0(m);
                checkSum += (UInt16)(a + b + c + d);
            }
            data[alllen - 2] = ElementTool.GetBit7_0(checkSum);
            data[alllen - 1] = 0x16;
            return(data);
        }
        /// <summary>
        /// 获取报数据
        /// </summary>
        /// <returns>字节数组</returns>
        public byte[] GetPacketData()
        {
            if (DirectoryName.Length > 200)
            {
                throw new ArgumentException("字符过长");
            }
            //21+x
            int len   = 21 + DirectoryNameLen;
            int index = 0;

            packetData          = new byte[len];
            packetData[index++] = (byte)OperationSign;
            packetData[index++] = ElementTool.GetBit7_0(DirectoryID);
            packetData[index++] = ElementTool.GetBit15_8(DirectoryID);
            packetData[index++] = ElementTool.GetBit23_16(DirectoryID);
            packetData[index++] = ElementTool.GetBit31_24(DirectoryID);
            packetData[index++] = DirectoryNameLen;
            var name = UnicodeEncoding.ASCII.GetBytes(DirectoryName);

            Array.Copy(name, 0, packetData, index, name.Length);
            int offset = index + name.Length;
            var start  = QueryStartingTime.GetDataArray();
            var end    = QueryEndTime.GetDataArray();

            Array.Copy(start, 0, packetData, offset, 7);
            offset += 7;
            Array.Copy(end, 0, packetData, offset, 7);
            return(packetData);
        }
Exemple #3
0
        /// <summary>
        /// 获取报数据
        /// </summary>
        /// <returns></returns>
        public byte[] GetPacketData()
        {
            try
            {
                int index = 0;
                packetData          = new byte[FileData.Length + 11];
                packetData[index++] = (byte)OperationSign;
                packetData[index++] = ElementTool.GetBit7_0(FileID);
                packetData[index++] = ElementTool.GetBit15_8(FileID);
                packetData[index++] = ElementTool.GetBit23_16(FileID);
                packetData[index++] = ElementTool.GetBit31_24(FileID);
                packetData[index++] = ElementTool.GetBit7_0(FragmentNum);
                packetData[index++] = ElementTool.GetBit15_8(FragmentNum);
                packetData[index++] = ElementTool.GetBit23_16(FragmentNum);
                packetData[index++] = ElementTool.GetBit31_24(FragmentNum);
                packetData[index++] = (byte)Fllow;
                Array.Copy(FileData, 0, packetData, index, FileData.Length);
                packetData[packetData.Length - 1] = GetCheck(FileData);

                return(packetData);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #4
0
        /// <summary>
        /// MasterCommand 遥控单/双命令
        /// </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="objectAddress">信息对象地址</param>
        /// <param name="sco">单命令 SCO</param>
        public MasterCommand(UInt16 transmitSeqNum, UInt16 ReceiveSeqNum, TypeIdentification typeID,
                             CauseOfTransmissionList cot, UInt16 asduPublicAddress, UInt32 objectAddress, byte co)
        {
            ASDU = new ApplicationServiceDataUnit((byte)typeID, (byte)1, false, (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);
            ASDU.InformationObject[3] = co;

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

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

            TimeStamp = DateTime.Now;
        }
Exemple #5
0
        /// <summary>
        /// 获取数据数组
        /// </summary>
        /// <returns>数组</returns>
        public byte[] GetArrayData()
        {
            var data = new byte[NameLen + 13];

            data[0] = NameLen;
            var nameByte = UnicodeEncoding.ASCII.GetBytes(Name);

            Array.Copy(nameByte, 0, data, 1, NameLen);
            data[NameLen + 1] = ElementTool.GetBit7_0(Size);
            data[NameLen + 2] = ElementTool.GetBit15_8(Size);
            data[NameLen + 3] = ElementTool.GetBit23_16(Size);
            data[NameLen + 4] = ElementTool.GetBit31_24(Size);
            data[NameLen + 5] = Property;
            Array.Copy(Time.GetDataArray(), 0, data, NameLen + 6, 7);
            attributeData = data;
            return(data);
        }
Exemple #6
0
        /// <summary>
        /// 目录{空白或X,只在监视(标准)方向有效}
        /// </summary>
        /// <param name="transmitSeqNum">发送序列号</param>
        /// <param name="ReceiveSeqNum">接收序列号</param>
        /// <param name="cot">传输原因</param>
        /// <param name="ASDUPublicAddress">ASDU公共地址</param>
        /// <param name="objectAddress">对象地址</param>
        /// <param name="fileName">文件名称</param>
        /// <param name="sectionName">节名称</param>
        /// <param name="afq">节名字</param>
        public FileTransmit(UInt16 transmitSeqNum, UInt16 ReceiveSeqNum, byte informationObjectCount,
                            CauseOfTransmissionList cot, UInt16 ASDUPublicAddress, UInt32 objectAddress,
                            UInt16 fileName, byte sectionName, AckFileQulifier afq)
        {
            ASDU = new ApplicationServiceDataUnit((byte)TypeIdentification.F_DR_TA_1, informationObjectCount, true, (byte)cot, ASDUPublicAddress);

            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;
        }
Exemple #7
0
        /// <summary>
        /// 查询日志文件
        /// </summary>
        /// <param name="transmitSeqNum">发送序列号</param>
        /// <param name="ReceiveSeqNum">接收序列号</param>
        /// <param name="cot">传输原因</param>
        /// <param name="ASDUPublicAddress">ASDU公共地址</param>
        /// <param name="objectAddress">对象地址</param>
        /// <param name="fileName">文件名称</param>
        /// <param name="startTime">开始时间</param>
        /// <param name="endTime">结束时间</param>
        public FileTransmit(UInt16 transmitSeqNum, UInt16 ReceiveSeqNum,
                            CauseOfTransmissionList cot, UInt16 ASDUPublicAddress, UInt32 objectAddress,
                            UInt16 fileName, CP56Time2a startTime, CP56Time2a endTime)
        {
            ASDU = new ApplicationServiceDataUnit((byte)TypeIdentification.F_SC_NB_1, 1, false, (byte)cot, ASDUPublicAddress);

            ASDU.InformationObject[0] = ElementTool.GetBit7_0(objectAddress);
            ASDU.InformationObject[1] = ElementTool.GetBit15_8(objectAddress);
            ASDU.InformationObject[2] = ElementTool.GetBit23_16(objectAddress);
            ASDU.InformationObject[3] = ElementTool.GetBit7_0(fileName);
            ASDU.InformationObject[4] = ElementTool.GetBit15_8(fileName);
            Array.Copy(startTime.GetDataArray(), 0, ASDU.InformationObject, 5, 7);
            Array.Copy(endTime.GetDataArray(), 0, ASDU.InformationObject, 12, 7);

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

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

            TimeStamp = DateTime.Now;
        }
Exemple #8
0
        /// <summary>
        /// 最后的节,最后的段
        /// </summary>
        /// <param name="transmitSeqNum">发送序列号</param>
        /// <param name="ReceiveSeqNum">接收序列号</param>
        /// <param name="cot">传输原因</param>
        /// <param name="ASDUPublicAddress">ASDU公共地址</param>
        /// <param name="objectAddress">对象地址</param>
        /// <param name="fileName">文件名称</param>
        /// <param name="lsq">最后的节和段的限定词LSQ</param>
        /// <param name="chs">校验和</param>
        public FileTransmit(UInt16 transmitSeqNum, UInt16 ReceiveSeqNum,
                            CauseOfTransmissionList cot, UInt16 ASDUPublicAddress, UInt32 objectAddress,
                            UInt16 fileName, LastSectionQulifier lsq, byte chs)
        {
            ASDU = new ApplicationServiceDataUnit((byte)TypeIdentification.F_LS_NA_1, 1, false, (byte)cot, ASDUPublicAddress);

            ASDU.InformationObject[0] = ElementTool.GetBit7_0(objectAddress);
            ASDU.InformationObject[1] = ElementTool.GetBit15_8(objectAddress);
            ASDU.InformationObject[2] = ElementTool.GetBit23_16(objectAddress);
            ASDU.InformationObject[3] = ElementTool.GetBit7_0(fileName);
            ASDU.InformationObject[4] = ElementTool.GetBit15_8(fileName);
            ASDU.InformationObject[5] = (byte)lsq;
            ASDU.InformationObject[6] = chs;

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

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

            TimeStamp = DateTime.Now;
        }
Exemple #9
0
        /// <summary>
        /// 段
        /// </summary>
        /// <param name="transmitSeqNum">发送序列号</param>
        /// <param name="ReceiveSeqNum">接收序列号</param>
        /// <param name="cot">传输原因</param>
        /// <param name="ASDUPublicAddress">ASDU公共地址</param>
        /// <param name="objectAddress">对象地址</param>
        /// <param name="fileName">文件名称</param>
        /// <param name="sectionName">节名称</param>
        /// <param name="sectionLen">段的长度</param>
        /// <param name="dataArray">段数据数组</param>
        public FileTransmit(UInt16 transmitSeqNum, UInt16 ReceiveSeqNum,
                            CauseOfTransmissionList cot, UInt16 ASDUPublicAddress, UInt32 objectAddress,
                            UInt16 fileName, byte sectionName, byte sectionLen, byte[] dataArray)
        {
            ASDU = new ApplicationServiceDataUnit((byte)TypeIdentification.F_SG_NA_1, (byte)cot, ASDUPublicAddress,
                                                  (byte)(sectionLen + 2 + 1 + 1 + 3));

            ASDU.InformationObject[0] = ElementTool.GetBit7_0(objectAddress);
            ASDU.InformationObject[1] = ElementTool.GetBit15_8(objectAddress);
            ASDU.InformationObject[2] = ElementTool.GetBit23_16(objectAddress);
            ASDU.InformationObject[3] = ElementTool.GetBit7_0(fileName);
            ASDU.InformationObject[4] = ElementTool.GetBit15_8(fileName);
            ASDU.InformationObject[5] = sectionName;
            ASDU.InformationObject[6] = sectionLen;

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

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

            TimeStamp = DateTime.Now;
        }
Exemple #10
0
        /// <summary>
        /// 添加信息对象--针对目录
        /// </summary>
        /// <param name="fileName">文件名</param>
        /// <param name="fileLen">文件长度</param>
        /// <param name="sof">文件状态</param>
        /// <param name="time">时间</param>
        public bool AddInformationObject(UInt16 fileName, UInt32 fileLen, StatusOfFile sof, CP56Time2a time)
        {
            bool state = false;

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

            data[0] = ElementTool.GetBit7_0(fileName);
            data[1] = ElementTool.GetBit15_8(fileName);
            data[2] = ElementTool.GetBit7_0(fileLen);
            data[3] = ElementTool.GetBit15_8(fileLen);
            data[4] = ElementTool.GetBit23_16(fileLen);
            data[5] = sof.SOF;
            Array.Copy(time.GetDataArray(), 0, data, 6, 7);

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

            return(true);
        }
Exemple #11
0
        /// <summary>
        /// 节准备就绪
        /// </summary>
        /// <param name="transmitSeqNum">发送序列号</param>
        /// <param name="ReceiveSeqNum">接收序列号</param>
        /// <param name="cot">传输原因</param>
        /// <param name="ASDUPublicAddress">ASDU公共地址</param>
        /// <param name="objectAddress">对象地址</param>
        /// <param name="fileName">文件名称</param>
        /// <param name="sectionName">节名称</param>
        /// <param name="sectionLen">节长度</param>
        /// <param name="srq">节准备就绪限定词</param>
        public FileTransmit(UInt16 transmitSeqNum, UInt16 ReceiveSeqNum,
                            CauseOfTransmissionList cot, UInt16 ASDUPublicAddress, UInt32 objectAddress,
                            UInt16 fileName, byte sectionName, UInt32 sectionLen, SectionReadyQulifier srq)
        {
            ASDU = new ApplicationServiceDataUnit((byte)TypeIdentification.F_SR_NA_1, 1, false, (byte)cot, ASDUPublicAddress);

            ASDU.InformationObject[0] = ElementTool.GetBit7_0(objectAddress);
            ASDU.InformationObject[1] = ElementTool.GetBit15_8(objectAddress);
            ASDU.InformationObject[2] = ElementTool.GetBit23_16(objectAddress);
            ASDU.InformationObject[3] = ElementTool.GetBit7_0(fileName);
            ASDU.InformationObject[4] = ElementTool.GetBit15_8(fileName);
            ASDU.InformationObject[5] = sectionName;
            ASDU.InformationObject[6] = ElementTool.GetBit7_0(sectionLen);
            ASDU.InformationObject[7] = ElementTool.GetBit15_8(sectionLen);
            ASDU.InformationObject[8] = ElementTool.GetBit23_16(sectionLen);
            ASDU.InformationObject[9] = srq.SRQ;

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

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

            TimeStamp = DateTime.Now;
        }
        /// <summary>
        /// 写文件数据包
        /// </summary>
        /// <returns>文件数据包</returns>
        public byte[] GetPakcketData()
        {
            int len = NameLen + 10;

            pakcketData = new byte[len];
            int index = 0;

            pakcketData[index++] = (byte)OperationSign;
            pakcketData[index++] = NameLen;
            var nameStr = UnicodeEncoding.ASCII.GetBytes(Name);

            Array.Copy(nameStr, 0, pakcketData, index, NameLen);
            index += NameLen;
            pakcketData[index++] = ElementTool.GetBit7_0(FileID);
            pakcketData[index++] = ElementTool.GetBit15_8(FileID);
            pakcketData[index++] = ElementTool.GetBit23_16(FileID);
            pakcketData[index++] = ElementTool.GetBit31_24(FileID);
            pakcketData[index++] = ElementTool.GetBit7_0(Size);
            pakcketData[index++] = ElementTool.GetBit15_8(Size);
            pakcketData[index++] = ElementTool.GetBit23_16(Size);
            pakcketData[index++] = ElementTool.GetBit31_24(Size);
            return(pakcketData);
        }