Esempio n. 1
0
 public APdu(int sendSeqNum, int receiveSeqNum, ApciType apciType, ASdu aSdu)
 {
     this.sendSeqNum    = sendSeqNum;
     this.receiveSeqNum = receiveSeqNum;
     this.apciType      = apciType;
     this.aSdu          = aSdu;
 }
Esempio n. 2
0
 public APdu(int sendSeqNum, int receiveSeqNum, ApciType apciType, ASdu aSdu)
 {
     this.sendSeqNum = sendSeqNum;
     this.receiveSeqNum = receiveSeqNum;
     this.apciType = apciType;
     this.aSdu = aSdu;
 }
Esempio n. 3
0
        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;
                }
            }
        }
Esempio n. 4
0
        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;
                }
            }
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
 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);
 }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
        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()));
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        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);
        }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
        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);
        }
Esempio n. 14
0
        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);
        }
Esempio n. 15
0
        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);
        }
Esempio n. 16
0
        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);
        }
Esempio n. 17
0
        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);
        }
Esempio n. 18
0
        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);
        }
Esempio n. 19
0
        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);
        }
Esempio n. 20
0
        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);
        }
Esempio n. 21
0
        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);
        }
Esempio n. 22
0
        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);
        }
Esempio n. 23
0
        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);
        }
Esempio n. 24
0
        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);
        }
Esempio n. 25
0
        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);
        }
Esempio n. 26
0
        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);
        }
Esempio n. 27
0
        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);
        }
Esempio n. 28
0
        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();
        }