public APdu(int sendSeqNum, int receiveSeqNum, ApciType apciType, ASdu aSdu) { this.sendSeqNum = sendSeqNum; this.receiveSeqNum = receiveSeqNum; this.apciType = apciType; this.aSdu = aSdu; }
public APdu(BinaryReader reader, ConnectionSettings settings) { var length = reader.ReadByte() & 0xff; if (length < 4 || length > 253) { throw new IOException("APDU contain invalid length: " + length); } var aPduHeader = reader.ReadBytes(4); if ((aPduHeader[0] & 0x01) == 0) { apciType = ApciType.I_FORMAT; sendSeqNum = ((aPduHeader[0] & 0xfe) >> 1) + ((aPduHeader[1] & 0xff) << 7); receiveSeqNum = ((aPduHeader[2] & 0xfe) >> 1) + ((aPduHeader[3] & 0xff) << 7); aSdu = new ASdu(reader, settings, length - 4); } else if ((aPduHeader[0] & 0x02) == 0) { apciType = ApciType.S_FORMAT; receiveSeqNum = ((aPduHeader[2] & 0xfe) >> 1) + ((aPduHeader[3] & 0xff) << 7); } else { switch (aPduHeader[0]) { case 0x83: apciType = ApciType.TESTFR_CON; break; case 0x43: apciType = ApciType.TESTFR_ACT; break; case 0x23: apciType = ApciType.STOPDT_CON; break; case 0x13: apciType = ApciType.STOPDT_ACT; break; case 0x0B: apciType = ApciType.STARTDT_CON; break; default: apciType = ApciType.STARTDT_ACT; break; } } }
public APdu(BinaryReader reader, ConnectionSettings settings) { var length = reader.ReadByte() & 0xff; if (length < 4 || length > 253) { throw new IOException("APDU contain invalid length: " + length); } var aPduHeader = reader.ReadBytes(4); if ((aPduHeader[0] & 0x01) == 0) { apciType = ApciType.FORMAT; sendSeqNum = ((aPduHeader[0] & 0xfe) >> 1) + ((aPduHeader[1] & 0xff) << 7); receiveSeqNum = ((aPduHeader[2] & 0xfe) >> 1) + ((aPduHeader[3] & 0xff) << 7); aSdu = new ASdu(reader, settings, length - 4); } else if ((aPduHeader[0] & 0x02) == 0) { apciType = ApciType.S_FORMAT; receiveSeqNum = ((aPduHeader[2] & 0xfe) >> 1) + ((aPduHeader[3] & 0xff) << 7); } else { if (aPduHeader[0] == 0x83) { apciType = ApciType.TESTFR_CON; } else if (aPduHeader[0] == 0x43) { apciType = ApciType.TESTFR_ACT; } else if (aPduHeader[0] == 0x23) { apciType = ApciType.STOPDT_CON; } else if (aPduHeader[0] == 0x13) { apciType = ApciType.STOPDT_ACT; } else if (aPduHeader[0] == 0x0B) { apciType = ApciType.STARTDT_CON; } else { apciType = ApciType.STARTDT_ACT; } } }
public void AckFileOrSection(int commonAddress, int informationObjectAddress, IeNameOfFile nameOfFile, IeNameOfSection nameOfSection, IeAckFileOrSectionQualifier qualifier) { var aSdu = new ASdu(TypeId.F_AF_NA_1, false, CauseOfTransmission.FILE_TRANSFER, false, false, originatorAddress, commonAddress, new[] { new InformationObject( informationObjectAddress, new[] {new InformationElement[] {nameOfFile, nameOfSection, qualifier}}) }); Send(aSdu); }
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); }
public void SendSegment(int commonAddress, int informationObjectAddress, IeNameOfFile nameOfFile, IeNameOfSection nameOfSection, IeFileSegment segment) { var aSdu = new ASdu(TypeId.F_SG_NA_1, false, CauseOfTransmission.FILE_TRANSFER, false, false, originatorAddress, commonAddress, new[] { new InformationObject(informationObjectAddress, new[] {new InformationElement[] {nameOfFile, nameOfSection, segment}}) }); Send(aSdu); }
public void SendDirectory(int commonAddress, int informationObjectAddress, InformationElement[][] directory) { var aSdu = new ASdu(TypeId.F_DR_TA_1, false, CauseOfTransmission.FILE_TRANSFER, false, false, originatorAddress, commonAddress, new[] { new InformationObject( informationObjectAddress, directory) }); Send(aSdu); }
public void SendConfirmation(ASdu aSdu) { var cot = aSdu.GetCauseOfTransmission(); if (cot == CauseOfTransmission.ACTIVATION) { cot = CauseOfTransmission.ACTIVATION_CON; } else if (cot == CauseOfTransmission.DEACTIVATION) { cot = CauseOfTransmission.DEACTIVATION_CON; } Send(new ASdu(aSdu.GetTypeIdentification(), aSdu.IsSequenceOfElements, cot, aSdu.IsTestFrame(), aSdu.IsNegativeConfirm(), aSdu.GetOriginatorAddress(), aSdu.GetCommonAddress(), aSdu.GetInformationObjects())); }
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); }
public void TestCommandWithTimeTag(int commonAddress, IeTestSequenceCounter testSequenceCounter, IeTime56 time) { var aSdu = new ASdu(TypeId.C_TS_TA_1, false, CauseOfTransmission.ACTIVATION, false, false, originatorAddress, commonAddress, new[] { new InformationObject(0, new[] {new InformationElement[] {testSequenceCounter, time}}) }); Send(aSdu); }
public void SynchronizeClocks(int commonAddress, IeTime56 time) { var io = new InformationObject(0, new[] {new InformationElement[] {time}}); InformationObject[] ios = {io}; var aSdu = new ASdu(TypeId.C_CS_NA_1, false, CauseOfTransmission.ACTIVATION, false, false, originatorAddress, commonAddress, ios); Send(aSdu); }
public void ReadCommand(int commonAddress, int informationObjectAddress) { var aSdu = new ASdu(TypeId.C_RD_NA_1, false, CauseOfTransmission.REQUEST, false, false, originatorAddress, commonAddress, new[] { new InformationObject(informationObjectAddress, new InformationElement[][] {}) }); Send(aSdu); }
public void QueryLog(int commonAddress, int informationObjectAddress, IeNameOfFile nameOfFile, IeTime56 rangeStartTime, IeTime56 rangeEndTime) { var aSdu = new ASdu(TypeId.F_SC_NB_1, false, CauseOfTransmission.FILE_TRANSFER, false, false, originatorAddress, commonAddress, new[] { new InformationObject( informationObjectAddress, new[] {new InformationElement[] {nameOfFile, rangeStartTime, rangeEndTime}}) }); Send(aSdu); }
public void ParameterShortFloatCommand(int commonAddress, int informationObjectAddress, IeShortFloat shortFloat, IeQualifierOfParameterOfMeasuredValues qualifier) { var aSdu = new ASdu(TypeId.P_ME_NC_1, false, CauseOfTransmission.ACTIVATION, false, false, originatorAddress, commonAddress, new[] { new InformationObject(informationObjectAddress, new[] {new InformationElement[] {shortFloat, qualifier}}) }); Send(aSdu); }
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); }
public void LastSectionOrSegment(int commonAddress, int informationObjectAddress, IeNameOfFile nameOfFile, IeNameOfSection nameOfSection, IeLastSectionOrSegmentQualifier qualifier, IeChecksum checksum) { var aSdu = new ASdu(TypeId.F_LS_NA_1, false, CauseOfTransmission.FILE_TRANSFER, false, false, originatorAddress, commonAddress, new[] { new InformationObject( informationObjectAddress, new[] {new InformationElement[] {nameOfFile, nameOfSection, qualifier, checksum}}) }); Send(aSdu); }
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); }
public void FileReady(int commonAddress, int informationObjectAddress, IeNameOfFile nameOfFile, IeLengthOfFileOrSection lengthOfFile, IeFileReadyQualifier qualifier) { var aSdu = new ASdu(TypeId.F_FR_NA_1, false, CauseOfTransmission.FILE_TRANSFER, false, false, originatorAddress, commonAddress, new[] { new InformationObject(informationObjectAddress, new[] {new InformationElement[] {nameOfFile, lengthOfFile, qualifier}}) }); Send(aSdu); }
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); }
public void SingleCommandWithTimeTag(int commonAddress, int informationObjectAddress, IeSingleCommand singleCommand, IeTime56 timeTag) { var cot = singleCommand.IsCommandStateOn() ? CauseOfTransmission.ACTIVATION : CauseOfTransmission.DEACTIVATION; var aSdu = new ASdu(TypeId.C_SC_TA_1, false, cot, false, false, originatorAddress, commonAddress, new[] { new InformationObject(informationObjectAddress, new[] {new InformationElement[] {singleCommand, timeTag}}) }); Send(aSdu); }
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); }
public void TestCommand(int commonAddress) { var aSdu = new ASdu(TypeId.C_TS_NA_1, false, CauseOfTransmission.ACTIVATION, false, false, originatorAddress, commonAddress, new[] { new InformationObject(0, new[] {new InformationElement[] {new IeFixedTestBitPattern()}}) }); Send(aSdu); }
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); }
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); }
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); }
public void ResetProcessCommand(int commonAddress, IeQualifierOfResetProcessCommand qualifier) { var aSdu = new ASdu(TypeId.C_RP_NA_1, false, CauseOfTransmission.ACTIVATION, false, false, originatorAddress, commonAddress, new[] { new InformationObject(0, new[] {new InformationElement[] {qualifier}}) }); Send(aSdu); }
public void Send(ASdu aSdu) { acknowledgedReceiveSequenceNumber = receiveSequenceNumber; var requestAPdu = new APdu(sendSequenceNumber, receiveSequenceNumber, APdu.ApciType.FORMAT, aSdu); sendSequenceNumber = (sendSequenceNumber + 1)%32768; if (maxTimeNoAckSentFuture != null) { maxTimeNoAckSentFuture.Cancel(); maxTimeNoAckSentFuture = null; } if (maxTimeNoAckReceivedFuture == null) { ScheduleMaxTimeNoAckReceivedFuture(); } var length = requestAPdu.Encode(buffer, settings); writer.Write(buffer, 0, length); writer.Flush(); ResetMaxIdleTimeTimer(); }