Exemple #1
0
        public override void Encode(Frame frame, ApplicationLayerParameters parameters, bool isSequence)
        {
            base.Encode(frame, parameters, isSequence);

            frame.SetNextByte((byte)(this.sn & 0xff));
            frame.SetNextByte((byte)(this.sn / 0x100 & 0xff));
        }
Exemple #2
0
        internal void Encode(Frame frame, ApplicationLayerParameters parameters)
        {
            frame.SetNextByte((byte)typeId);
            frame.SetNextByte(vsq);

            byte cotByte = (byte)cot;

            if (isTest)
            {
                cotByte = (byte)(cotByte | 0x80);
            }

            if (isNegative)
            {
                cotByte = (byte)(cotByte | 0x40);
            }

            frame.SetNextByte(cotByte);

            if (parameters.SizeOfCOT == 2)
            {
                frame.SetNextByte((byte)oa);
            }

            frame.SetNextByte((byte)(ca % 256));

            if (parameters.SizeOfCA > 1)
            {
                frame.SetNextByte((byte)(ca / 256));
            }

            if (payload != null)
            {
                frame.AppendBytes(payload);
            }
            else
            {
                bool isFirst = true;

                foreach (InformationObject io in informationObjects)
                {
                    if (isFirst)
                    {
                        io.Encode(frame, parameters, false);
                        isFirst = false;
                    }
                    else
                    {
                        if (IsSequence)
                        {
                            io.Encode(frame, parameters, true);
                        }
                        else
                        {
                            io.Encode(frame, parameters, false);
                        }
                    }
                }
            }
        }
Exemple #3
0
        public FIleWriteActCon(ApplicationLayerParameters parameters, byte[] msg, int startIndex) : base(parameters, msg, startIndex)
        {
            startIndex += 2; /* skip IOA */
            startIndex += 1; /* skip AdditionalPacketType */

            if ((msg.Length - startIndex) < GetEncodedSize())
            {
                throw new ASDUParsingException("Message too small");
            }

            startIndex += 1; /* skip OPT */

            _result = (WriteFileActConResult)msg[startIndex++];

            _fileNameLength = msg[startIndex++];

            _fileName = "";
            for (int i = 0; i < _fileNameLength; i++)
            {
                _fileName += (char)msg[startIndex++];
            }

            _fileId  = msg[startIndex++];
            _fileId += msg[startIndex++] * 0x100;
            _fileId += msg[startIndex++] * 0x10000;
            _fileId += msg[startIndex++] * 0x1000000;

            _fileSize  = msg[startIndex++];
            _fileSize += (uint)msg[startIndex++] * 0x100;
            _fileSize += (uint)msg[startIndex++] * 0x10000;
            _fileSize += (uint)msg[startIndex++] * 0x100000;
        }
Exemple #4
0
        public FileCall(ApplicationLayerParameters parameters, byte[] msg, int startIndex) : base(parameters, msg, startIndex)
        {
            startIndex += 2; /* skip IOA */
            startIndex += 1; /* skip AdditionalPacketType */

            if ((msg.Length - startIndex) < GetEncodedSize())
            {
                throw new ASDUParsingException("Message too small");
            }

            startIndex += 1; /* skip OPT */

            _folderId  = msg[startIndex++];
            _folderId += msg[startIndex++] * 0x100;
            _folderId += msg[startIndex++] * 0x10000;
            _folderId += msg[startIndex++] * 0x1000000;

            _folderNameLength = msg[startIndex++];

            for (int i = 0; i < _folderNameLength; i++)
            {
                _folderName += (char)msg[startIndex++];
            }

            if ((msg.Length - startIndex) < 15)
            {
                throw new ASDUParsingException("Message too small");
            }

            _callFlag = (CallFlag)msg[startIndex++];

            _startTime  = new CP56Time2a(msg, startIndex);
            startIndex += 7;
            _endTime    = new CP56Time2a(msg, startIndex);
        }
Exemple #5
0
        public FIleWriteTransfer(ApplicationLayerParameters parameters, byte[] msg, int startIndex) : base(parameters, msg, startIndex)
        {
            startIndex += 2; /* skip IOA */
            startIndex += 1; /* skip AdditionalPacketType */

            if ((msg.Length - startIndex) < GetEncodedSize())
            {
                throw new ASDUParsingException("Message too small");
            }

            startIndex += 1; /* skip OPT */

            _fileId  = msg[startIndex++];
            _fileId += msg[startIndex++] * 0x100;
            _fileId += msg[startIndex++] * 0x10000;
            _fileId += msg[startIndex++] * 0x1000000;

            _offset  = msg[startIndex++];
            _offset += msg[startIndex++] * 0x100;
            _offset += msg[startIndex++] * 0x10000;
            _offset += msg[startIndex++] * 0x1000000;

            _followup = msg[startIndex++] == 1;

            if (msg.Length - startIndex - 1 < 0)
            {
                throw new ASDUParsingException("File contents is empty");
            }

            _data = new byte[msg.Length - startIndex - 1];
            Array.Copy(msg, startIndex, _data, 0, _data.Length);

            _cs = msg[msg.Length - 1];
        }
        internal FileDirectory(ApplicationLayerParameters parameters, byte[] msg, int startIndex, bool isSequence)
            : base(parameters, msg, startIndex, isSequence)
        {
            if (!isSequence)
            {
                startIndex += parameters.SizeOfIOA; /* skip IOA */
            }
            if ((msg.Length - startIndex) < GetEncodedSize())
            {
                throw new ASDUParsingException("Message too small");
            }

            int nofValue;

            nofValue  = msg[startIndex++];
            nofValue += (msg[startIndex++] * 0x100);

            nof = (NameOfFile)nofValue;

            lengthOfFile  = msg[startIndex++];
            lengthOfFile += (msg[startIndex++] * 0x100);
            lengthOfFile += (msg[startIndex++] * 0x10000);

            sof = msg[startIndex++];

            /* parse CP56Time2a (creation time of file) */
            creationTime = new CP56Time2a(msg, startIndex);
        }
        internal SectionReady(ApplicationLayerParameters parameters, byte[] msg, int startIndex, bool isSequence)
            : base(parameters, msg, startIndex, isSequence)
        {
            if (!isSequence)
            {
                startIndex += parameters.SizeOfIOA; /* skip IOA */
            }
            if ((msg.Length - startIndex) < GetEncodedSize())
            {
                throw new ASDUParsingException("Message too small");
            }

            int nofValue;

            nofValue  = msg[startIndex++];
            nofValue += (msg[startIndex++] * 0x100);

            nof = (NameOfFile)nofValue;

            nameOfSection = msg[startIndex++];

            lengthOfSection  = msg[startIndex++];
            lengthOfSection += (msg[startIndex++] * 0x100);
            lengthOfSection += (msg[startIndex++] * 0x10000);

            /* parse SRQ (section read qualifier) */
            srq = msg[startIndex++];
        }
        internal FileLastSegmentOrSection(ApplicationLayerParameters parameters, byte[] msg, int startIndex, bool isSequence)
            : base(parameters, msg, startIndex, isSequence)
        {
            if (!isSequence)
            {
                startIndex += parameters.SizeOfIOA; /* skip IOA */
            }
            if ((msg.Length - startIndex) < GetEncodedSize())
            {
                throw new ASDUParsingException("Message too small");
            }

            int nofValue;

            nofValue  = msg[startIndex++];
            nofValue += (msg[startIndex++] * 0x100);

            nof = (NameOfFile)nofValue;

            nameOfSection = msg[startIndex++];

            /* parse LSQ (last section or segment qualifier) */
            lsq = (LastSectionOrSegmentQualifier)msg[startIndex++];

            chs = msg[startIndex++];
        }
        public override void Encode(Frame frame, ApplicationLayerParameters parameters, bool isSequence)
        {
            base.Encode(frame, parameters, isSequence);

            frame.SetNextByte(0xaa);
            frame.SetNextByte(0x55);
        }
 protected InformationObject(ApplicationLayerParameters parameters, byte[] msg, int startIndex, bool isSequence)
 {
     if (!isSequence)
     {
         objectAddress = ParseInformationObjectAddress(parameters, msg, startIndex);
     }
 }
Exemple #11
0
 public override void Encode(Frame frame, ApplicationLayerParameters parameters, bool isSequence)
 {
     frame.SetNextByte((byte)(ObjectAddress & 0xff));
     frame.SetNextByte((byte)((ObjectAddress / 0x100) & 0xff));
     frame.SetNextByte((byte)_additionalPacketType);
     frame.SetNextByte((byte)_opt);
 }
Exemple #12
0
        internal StepPositionInformation(ApplicationLayerParameters parameters, byte[] msg, int startIndex, bool isSequence)
            : base(parameters, msg, startIndex, isSequence)
        {
            if (!isSequence)
            {
                startIndex += parameters.SizeOfIOA; /* skip IOA */
            }
            if ((msg.Length - startIndex) < GetEncodedSize())
            {
                throw new ASDUParsingException("Message too small");
            }

            /* parse VTI (value with transient state indication) */
            byte vti = msg[startIndex++];

            isTransient = ((vti & 0x80) == 0x80);

            value = (vti & 0x7f);

            if (value > 63)
            {
                value = value - 128;
            }

            quality = new QualityDescriptor(msg[startIndex++]);
        }
Exemple #13
0
        public ASDU(ApplicationLayerParameters parameters, byte[] msg, int bufPos, int msgLength)
        {
            this.parameters = parameters;

            int asduHeaderSize = 2 + parameters.SizeOfCOT + parameters.SizeOfCA;

            if ((msgLength - bufPos) < asduHeaderSize)
            {
                throw new ASDUParsingException("Message header too small");
            }

            typeId = (TypeID)msg[bufPos++];
            vsq    = msg[bufPos++];

            this.hasTypeId = true;

            byte cotByte = msg[bufPos++];

            if ((cotByte & 0x80) != 0)
            {
                isTest = true;
            }
            else
            {
                isTest = false;
            }

            if ((cotByte & 0x40) != 0)
            {
                isNegative = true;
            }
            else
            {
                isNegative = false;
            }

            cot = (CauseOfTransmission)(cotByte & 0x3f);

            if (parameters.SizeOfCOT == 2)
            {
                oa = msg[bufPos++];
            }

            ca = msg[bufPos++];

            if (parameters.SizeOfCA > 1)
            {
                ca += (msg[bufPos++] * 0x100);
            }

            int payloadSize = msgLength - bufPos;

            //TODO add plausibility check for payload length (using TypeID, SizeOfIOA, and VSQ)

            payload = new byte[payloadSize];

            /* save payload */
            Buffer.BlockCopy(msg, bufPos, payload, 0, payloadSize);
        }
Exemple #14
0
        public override void Encode(Frame frame, ApplicationLayerParameters parameters, bool isSequence)
        {
            base.Encode(frame, parameters, isSequence);

            frame.AppendBytes(scd.GetEncodedValue());

            frame.SetNextByte(qds.EncodedValue);
        }
Exemple #15
0
        public override void Encode(Frame frame, ApplicationLayerParameters parameters, bool isSequence)
        {
            base.Encode(frame, parameters, isSequence);

            frame.AppendBytes(System.BitConverter.GetBytes(value));

            frame.SetNextByte(this.qos.GetEncodedValue());
        }
Exemple #16
0
        public override void Encode(Frame frame, ApplicationLayerParameters parameters, bool isSequence)
        {
            base.Encode(frame, parameters, isSequence);

            frame.SetNextByte((byte)(value % 256));
            frame.SetNextByte((byte)((value / 0x100) % 256));
            frame.SetNextByte((byte)((value / 0x10000) % 256));
            frame.SetNextByte((byte)((value / 0x1000000) % 256));
        }
        public override void Encode(Frame frame, ApplicationLayerParameters parameters, bool isSequence)
        {
            base.Encode(frame, parameters, isSequence);

            frame.SetNextByte((byte)(tsc % 256));
            frame.SetNextByte((byte)(tsc / 256));

            frame.AppendBytes(time.GetEncodedValue());
        }
        public override void Encode(Frame frame, ApplicationLayerParameters parameters, bool isSequence)
        {
            base.Encode(frame, parameters, isSequence);

            byte val = quality.EncodedValue;

            val += (byte)value;

            frame.SetNextByte(val);
        }
        public override void Encode(Frame frame, ApplicationLayerParameters parameters, bool isSequence)
        {
            base.Encode(frame, parameters, isSequence);

            frame.SetNextByte(singleEvent.EncodedValue);

            frame.AppendBytes(elapsedTime.GetEncodedValue());

            frame.AppendBytes(timestamp.GetEncodedValue());
        }
Exemple #20
0
        private SinglePointWithCP56Time2aOfFault GetSignalElement(ApplicationLayerParameters parameters, byte[] msg, int startIndex)
        {
            ApplicationLayerParameters m_parameters = parameters.Clone();

            m_parameters.SizeOfIOA = 2;

            var retVal = new SinglePointWithCP56Time2aOfFault(m_parameters, msg, startIndex, false);

            return(retVal);
        }
Exemple #21
0
        public override void Encode(Frame frame, ApplicationLayerParameters parameters, bool isSequence)
        {
            base.Encode(frame, parameters, isSequence);

            frame.SetNextByte(_fileNameLength);

            for (int i = 0; i < _fileNameLength; i++)
            {
                frame.SetNextByte((byte)_fileName[i]);
            }
        }
        public override void Encode(Frame frame, ApplicationLayerParameters parameters, bool isSequence)
        {
            base.Encode(frame, parameters, isSequence);

            frame.SetNextByte((byte)((int)nof % 256));
            frame.SetNextByte((byte)((int)nof / 256));

            frame.SetNextByte(nameOfSection);

            frame.SetNextByte(afq);
        }
Exemple #23
0
        public override void Encode(Frame frame, ApplicationLayerParameters parameters, bool isSequence)
        {
            base.Encode(frame, parameters, isSequence);

            frame.SetNextByte(oci.EncodedValue);

            frame.SetNextByte(qdp.EncodedValue);

            frame.AppendBytes(operatingTime.GetEncodedValue());

            frame.AppendBytes(timestamp.GetEncodedValue());
        }
Exemple #24
0
        internal EndOfInitialization(ApplicationLayerParameters parameters, byte[] msg, int startIndex) :
            base(parameters, msg, startIndex, false)
        {
            startIndex += parameters.SizeOfIOA; /* skip IOA */

            if ((msg.Length - startIndex) < GetEncodedSize())
            {
                throw new ASDUParsingException("Message too small");
            }

            coi = msg[startIndex];
        }
        internal SoftwareUpdateCommand(ApplicationLayerParameters parameters, byte[] msg, int startIndex)
            : base(parameters, msg, startIndex, false)
        {
            startIndex += parameters.SizeOfIOA; /* skip IOA */

            if ((msg.Length - startIndex) < GetEncodedSize())
            {
                throw new ASDUParsingException("Message too small");
            }

            this.qos = new SetpointCommandQualifier(msg[startIndex++]);
        }
        internal ResetProcessCommand(ApplicationLayerParameters parameters, byte[] msg, int startIndex)
            : base(parameters, msg, startIndex, false)
        {
            startIndex += parameters.SizeOfIOA; /* skip IOA */

            if ((msg.Length - startIndex) < GetEncodedSize())
            {
                throw new ASDUParsingException("Message too small");
            }

            qrp = msg[startIndex++];
        }
        public static int GetMaxDataSize(ApplicationLayerParameters parameters)
        {
            int maxSize = parameters.MaxAsduLength
                          - parameters.SizeOfTypeId
                          - parameters.SizeOfVSQ
                          - parameters.SizeOfCA
                          - parameters.SizeOfCOT
                          - parameters.SizeOfIOA
                          - ENCODED_SIZE;

            return(maxSize);
        }
Exemple #28
0
        public WriteParameters(ApplicationLayerParameters parameters, byte[] msg, int startIndex) : base(parameters, msg, startIndex, true)
        {
            if ((msg.Length - startIndex) < GetEncodedSize())
            {
                throw new ASDUParsingException("Message too small");
            }

            _sn         = BitConverter.ToUInt16(msg, startIndex);
            startIndex += 2;

            _pi = new ParameterIdentification(msg[startIndex++]);
        }
Exemple #29
0
        internal SwitchSettingArea(ApplicationLayerParameters parameters, byte[] msg, int startIndex)
            : base(parameters, msg, startIndex, false)
        {
            startIndex += parameters.SizeOfIOA; /* skip IOA */

            if ((msg.Length - startIndex) < GetEncodedSize())
            {
                throw new ASDUParsingException("Message too small");
            }

            this.sn = BitConverter.ToUInt16(msg, startIndex++);
        }
        internal ParameterActivation(ApplicationLayerParameters parameters, byte[] msg, int startIndex) :
            base(parameters, msg, startIndex, false)
        {
            startIndex += parameters.SizeOfIOA;             /* skip IOA */

            if ((msg.Length - startIndex) < GetEncodedSize())
            {
                throw new ASDUParsingException("Message too small");
            }

            /* parse QPA */
            qpa = msg [startIndex++];
        }