Пример #1
0
        public ASdu(TypeId typeId, bool isSequenceOfElements, CauseOfTransmission causeOfTransmission, bool test,
            bool negativeConfirm, int originatorAddress, int commonAddress, InformationObject[] informationObjects)
        {
            IsSequenceOfElements = isSequenceOfElements;

            this.typeId = typeId;
            this.causeOfTransmission = causeOfTransmission;
            this.test = test;
            this.negativeConfirm = negativeConfirm;
            this.originatorAddress = originatorAddress;
            this.commonAddress = commonAddress;
            this.informationObjects = informationObjects;

            privateInformation = null;

            sequenceLength = isSequenceOfElements
                ? informationObjects[0].GetInformationElements().Length
                : informationObjects.Length;
        }
Пример #2
0
        public ASdu(BinaryReader reader, ConnectionSettings settings, int aSduLength)
        {
            int typeIdCode = reader.ReadByte();

            typeId = (TypeId)typeIdCode;

            int tempbyte = reader.ReadByte();

            IsSequenceOfElements = (tempbyte & 0x80) == 0x80;

            int numberOfSequenceElements;
            int numberOfInformationObjects;

            sequenceLength = tempbyte & 0x7f;
            if (IsSequenceOfElements)
            {
                numberOfSequenceElements   = sequenceLength;
                numberOfInformationObjects = 1;
            }
            else
            {
                numberOfInformationObjects = sequenceLength;
                numberOfSequenceElements   = 1;
            }

            tempbyte            = reader.ReadByte();
            causeOfTransmission = (CauseOfTransmission)(tempbyte & 0x3f);
            test            = (tempbyte & 0x80) == 0x80;
            negativeConfirm = (tempbyte & 0x40) == 0x40;

            if (settings.CotFieldLength == 2)
            {
                originatorAddress = reader.ReadByte();
                aSduLength--;
            }
            else
            {
                originatorAddress = -1;
            }

            if (settings.CommonAddressFieldLength == 1)
            {
                commonAddress = reader.ReadByte();
            }
            else
            {
                commonAddress = reader.ReadByte() + (reader.ReadByte() << 8);
                aSduLength--;
            }

            if (typeIdCode < 128)
            {
                informationObjects = new InformationObject[numberOfInformationObjects];

                for (var i = 0; i < numberOfInformationObjects; i++)
                {
                    informationObjects[i] = new InformationObject(reader, typeId, numberOfSequenceElements, settings);
                }

                privateInformation = null;
            }
            else
            {
                informationObjects = null;
                privateInformation = reader.ReadBytes(aSduLength - 4);
            }
        }
Пример #3
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);
        }
Пример #4
0
        public ASdu(BinaryReader reader, ConnectionSettings settings, int aSduLength)
        {
            int typeIdCode = reader.ReadByte();

            typeId = (TypeId) typeIdCode;

            int tempbyte = reader.ReadByte();

            IsSequenceOfElements = (tempbyte & 0x80) == 0x80;

            int numberOfSequenceElements;
            int numberOfInformationObjects;

            sequenceLength = tempbyte & 0x7f;
            if (IsSequenceOfElements)
            {
                numberOfSequenceElements = sequenceLength;
                numberOfInformationObjects = 1;
            }
            else
            {
                numberOfInformationObjects = sequenceLength;
                numberOfSequenceElements = 1;
            }

            tempbyte = reader.ReadByte();
            causeOfTransmission = (CauseOfTransmission) (tempbyte & 0x3f);
            test = (tempbyte & 0x80) == 0x80;
            negativeConfirm = (tempbyte & 0x40) == 0x40;

            if (settings.CotFieldLength == 2)
            {
                originatorAddress = reader.ReadByte();
                aSduLength--;
            }
            else
            {
                originatorAddress = -1;
            }

            if (settings.CommonAddressFieldLength == 1)
            {
                commonAddress = reader.ReadByte();
            }
            else
            {
                commonAddress = reader.ReadByte() + (reader.ReadByte() << 8);
                aSduLength--;
            }

            if (typeIdCode < 128)
            {
                informationObjects = new InformationObject[numberOfInformationObjects];

                for (var i = 0; i < numberOfInformationObjects; i++)
                {
                    informationObjects[i] = new InformationObject(reader, typeId, numberOfSequenceElements, settings);
                }

                privateInformation = null;
            }
            else
            {
                informationObjects = null;
                privateInformation = reader.ReadBytes(aSduLength - 4);
            }
        }