/// <summary> /// MasterCommand初始化,将字节数组强制转化为MasterCommand /// </summary> /// <param name="dataArray"></param> public MasterCommand(byte[] dataArray) { if (dataArray.Length < 15) { throw new Exception("MasterCommand APDU(byte[] dataArray) 长度不应该小于15"); } TimeStamp = DateTime.Now; APCI = new APCITypeI(dataArray); var data = new byte[dataArray.Length - 6]; Array.Copy(dataArray, 6, data, 0, dataArray.Length - 6); FrameArray = dataArray; ASDU = new ApplicationServiceDataUnit(data); }
/// <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> public MasterCommand(UInt16 transmitSeqNum, UInt16 ReceiveSeqNum, TypeIdentification typeID, CauseOfTransmissionList cot, UInt16 asduPublicAddress) { ASDU = new ApplicationServiceDataUnit((byte)typeID, (byte)1, false, (byte)cot, asduPublicAddress); //信息对象地址为0 ASDU.InformationObject[0] = 0; ASDU.InformationObject[1] = 0; ASDU.InformationObject[2] = 0; var apduLen = 4 + ASDU.Length; //控制域长度4 + ASDU长度 APCI = new APCITypeI((byte)apduLen, transmitSeqNum, ReceiveSeqNum); TimeStamp = DateTime.Now; }
/// <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="objectAddress">信息对象地址</param> /// <param name="coi">初始化原因coi</param> public MasterCommand(UInt16 transmitSeqNum, UInt16 ReceiveSeqNum, TypeIdentification typeID, CauseOfTransmissionList cot, UInt16 asduPublicAddress, UInt32 objectAddress, CauseOfInitialization coi) { 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] = (byte)coi; var apduLen = 4 + ASDU.Length; //控制域长度4 + ASDU长度 APCI = new APCITypeI((byte)apduLen, transmitSeqNum, ReceiveSeqNum); TimeStamp = DateTime.Now; }
/// <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; }
/// <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; }
/// <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; }
/// <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; }
/// <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> /// <param name="dataArray">数据数组</param> public FilePacket(byte[] dataArray) { try { TimeStamp = DateTime.Now; if (dataArray.Length < 15) { throw new Exception("FilePacket APDU(byte[] dataArray) 长度不应该小于15"); } TimeStamp = DateTime.Now; APCI = new APCITypeI(dataArray); var data = new byte[dataArray.Length - 6]; Array.Copy(dataArray, 6, data, 0, dataArray.Length - 6); FrameArray = dataArray; ASDU = new ApplicationServiceDataUnit(data); PacketData = new byte[ASDU.InformationObject.Length - 3]; Array.Copy(ASDU.InformationObject, 3, PacketData, 0, PacketData.Length); } catch (Exception ex) { throw ex; } }
/// <summary> /// 文件服务 /// </summary> /// <param name="transmitSeqNum">发送序列号</param> /// <param name="receiveSeqNum">接收序列号</param> /// <param name="cot">传输原因</param> /// <param name="ASDUPublicAddress">ASDU公共地址</param> /// <param name="packet">包数据</param> public FilePacket(UInt16 transmitSeqNum, UInt16 receiveSeqNum, CauseOfTransmissionList cot, UInt16 ASDUPublicAddress, byte[] packet) { try { ASDU = new ApplicationServiceDataUnit((byte)TypeIdentification.F_FR_NA_1_NR, (byte)cot, ASDUPublicAddress, packet.Length + 3); ASDU.InformationObject[0] = 0; ASDU.InformationObject[1] = 0; ASDU.InformationObject[1] = 2;//文件传输 Array.Copy(packet, 0, ASDU.InformationObject, 3, packet.Length); var apduLen = 4 + (packet.Length + 3 + 6); //控制域长度4 + ASDU长度 APCI = new APCITypeI((byte)apduLen, transmitSeqNum, receiveSeqNum); PacketData = packet; TimeStamp = DateTime.Now; } catch (Exception ex) { throw ex; } }