Exemple #1
0
        byte[] GetSwitchTable(GXDLMSSettings settings)
        {
            GXByteBuffer bb = new GXByteBuffer();

            bb.SetUInt8((byte)DataType.Array);
            if (SwitchTable == null)
            {
                GXCommon.SetObjectCount(0, bb);
            }
            else
            {
                GXCommon.SetObjectCount(SwitchTable.Length, bb);
                foreach (Int16 it in SwitchTable)
                {
                    GXCommon.SetData(settings, bb, DataType.Int16, it);
                }
            }
            return(bb.Array());
        }
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         return(GXCommon.LogicalNameToBytes(LogicalName));
     }
     if (e.Index == 2)
     {
         //If client set new value.
         if (!settings.IsServer && Scaler != 1 && Value != null)
         {
             DataType dt = base.GetDataType(2);
             if (dt == DataType.None && Value != null)
             {
                 dt = GXCommon.GetDLMSDataType(Value.GetType());
                 //If user has set initial value.
                 if (dt == DataType.String)
                 {
                     dt = DataType.None;
                 }
             }
             object tmp;
             tmp = Convert.ToDouble(Value) / Scaler;
             if (dt != DataType.None)
             {
                 tmp = Convert.ChangeType(tmp, GXCommon.GetDataType(dt));
             }
             return(tmp);
         }
         return(Value);
     }
     if (e.Index == 3)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Structure);
         data.SetUInt8(2);
         GXCommon.SetData(settings, data, DataType.Int8, scaler);
         GXCommon.SetData(settings, data, DataType.Enum, Unit);
         return(data.Array());
     }
     e.Error = ErrorCode.ReadWriteDenied;
     return(null);
 }
Exemple #3
0
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         return(this.LogicalName);
     }
     if (e.Index == 2)
     {
         GXByteBuffer bb = new GXByteBuffer();
         bb.SetUInt8(DataType.Structure);
         bb.SetUInt8(3);
         GXCommon.SetData(settings, bb, DataType.OctetString, SystemTitle);
         GXCommon.SetData(settings, bb, DataType.UInt16, MacAddress);
         GXCommon.SetData(settings, bb, DataType.UInt8, LSapSelector);
         return(bb.Array());
     }
     e.Error = ErrorCode.ReadWriteDenied;
     return(null);
 }
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         return(GXCommon.LogicalNameToBytes(LogicalName));
     }
     if (e.Index == 2)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Array);
         if (Entries == null)
         {
             data.SetUInt8(0);
         }
         else
         {
             int cnt = Entries.Length;
             //Add count
             GXCommon.SetObjectCount(cnt, data);
             if (cnt != 0)
             {
                 foreach (GXDLMSSpecialDay it in Entries)
                 {
                     data.SetUInt8((byte)DataType.Structure);
                     data.SetUInt8((byte)3); //Count
                     GXCommon.SetData(settings, data, DataType.UInt16, it.Index);
                     if (settings.Standard == Standard.SaudiArabia)
                     {
                         GXCommon.SetData(settings, data, DataType.Date, it.Date);
                     }
                     else
                     {
                         GXCommon.SetData(settings, data, DataType.OctetString, it.Date);
                     }
                     GXCommon.SetData(settings, data, DataType.UInt8, it.DayId);
                 }
             }
         }
         return(data.Array());
     }
     e.Error = ErrorCode.ReadWriteDenied;
     return(null);
 }
Exemple #5
0
        /// <summary>
        /// Agree on one or more symmetric keys using the key agreement algorithm.
        /// </summary>
        /// <param name="client"> DLMS client that is used to generate action.</param>
        /// <param name="list"> List of keys.</param>
        /// <returns>Generated action.</returns>
        public byte[][] keyAgreement(GXDLMSClient client, List <KeyValuePair <GlobalKeyType, byte[]> > list)
        {
            if (list == null || list.Count == 0)
            {
                throw new ArgumentException("Invalid list. It is empty.");
            }
            GXByteBuffer bb = new GXByteBuffer();

            bb.SetUInt8(DataType.Array);
            bb.SetUInt8((byte)list.Count);
            foreach (KeyValuePair <GlobalKeyType, byte[]> it in list)
            {
                bb.SetUInt8(DataType.Structure);
                bb.SetUInt8(2);
                GXCommon.SetData(client.Settings, bb, DataType.Enum, it.Key);
                GXCommon.SetData(client.Settings, bb, DataType.OctetString, it.Value);
            }
            return(client.Method(this, 3, bb.Array(), DataType.Array));
        }
Exemple #6
0
        /// <summary>
        /// Returns Association View.
        /// </summary>
        private GXByteBuffer GetObjects(GXDLMSSettings settings, ValueEventArgs e)
        {
            int          cnt  = ObjectList.Count;
            GXByteBuffer data = new GXByteBuffer();

            //Add count only for first time.
            if (settings.Index == 0)
            {
                settings.Count = (UInt16)cnt;
                data.SetUInt8((byte)DataType.Array);
                GXCommon.SetObjectCount(cnt, data);
            }
            ushort pos = 0;

            foreach (GXDLMSObject it in ObjectList)
            {
                ++pos;
                if (!(pos <= settings.Index))
                {
                    data.SetUInt8((byte)DataType.Structure);
                    //Count
                    data.SetUInt8((byte)4);
                    //base address.
                    GXCommon.SetData(settings, data, DataType.Int16, it.ShortName);
                    //ClassID
                    GXCommon.SetData(settings, data, DataType.UInt16, it.ObjectType);
                    //Version
                    GXCommon.SetData(settings, data, DataType.UInt8, it.Version);
                    GXCommon.SetData(settings, data, DataType.OctetString, GXCommon.LogicalNameToBytes(it.LogicalName));
                    ++settings.Index;
                    if (settings.IsServer)
                    {
                        //If PDU is full.
                        if (!e.SkipMaxPduSize && data.Size >= settings.MaxPduSize)
                        {
                            break;
                        }
                    }
                }
            }
            return(data);
        }
        static Object GetDayProfileTable(GXDLMSSettings settings, GXDLMSDayProfile[] target)
        {
            GXByteBuffer data = new GXByteBuffer();

            data.SetUInt8((byte)DataType.Array);
            if (target == null)
            {
                //Add count
                GXCommon.SetObjectCount(0, data);
            }
            else
            {
                int cnt = target.Length;
                //Add count
                GXCommon.SetObjectCount(cnt, data);
                foreach (GXDLMSDayProfile it in target)
                {
                    data.SetUInt8((byte)DataType.Structure);
                    data.SetUInt8(2);
                    GXCommon.SetData(settings, data, DataType.UInt8, it.DayId);
                    data.SetUInt8((byte)DataType.Array);
                    //Add count
                    if (it.DaySchedules == null)
                    {
                        data.SetUInt8(0);
                    }
                    else
                    {
                        GXCommon.SetObjectCount(it.DaySchedules.Length, data);
                        foreach (GXDLMSDayProfileAction action in it.DaySchedules)
                        {
                            data.SetUInt8((byte)DataType.Structure);
                            data.SetUInt8(3);
                            GXCommon.SetData(settings, data, DataType.OctetString, action.StartTime);
                            GXCommon.SetData(settings, data, DataType.OctetString, GXCommon.LogicalNameToBytes(action.ScriptLogicalName));
                            GXCommon.SetData(settings, data, DataType.UInt16, action.ScriptSelector);
                        }
                    }
                }
            }
            return(data.Array());
        }
Exemple #8
0
 object IGXDLMSBase.GetValue(int index, int selector, object parameters)
 {
     if (index == 1)
     {
         return(this.LogicalName);
     }
     if (index == 2)
     {
         List <byte> stream = new List <byte>();
         stream.Add((byte)DataType.Structure);
         stream.Add(2);
         GXCommon.SetData(stream, DataType.OctetString, ASCIIEncoding.ASCII.GetBytes(ExecutedScriptLogicalName)); //Time
         GXCommon.SetData(stream, DataType.UInt16, ExecutedScriptSelector);                                       //Time
         return(stream.ToArray());
     }
     if (index == 3)
     {
         return(this.Type);
     }
     if (index == 4)
     {
         List <byte> stream = new List <byte>();
         stream.Add((byte)DataType.Array);
         if (ExecutionTime == null)
         {
             GXCommon.SetObjectCount(0, stream);
         }
         else
         {
             GXCommon.SetObjectCount(ExecutionTime.Length, stream);
             foreach (GXDateTime it in ExecutionTime)
             {
                 stream.Add((byte)DataType.Structure);
                 stream.Add((byte)2);                               //Count
                 GXCommon.SetData(stream, DataType.Time, it.Value); //Time
                 GXCommon.SetData(stream, DataType.Date, it.Value); //Date
             }
         }
         return(stream.ToArray());
     }
     throw new ArgumentException("GetValue failed. Invalid attribute index.");
 }
Exemple #9
0
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, int index, int selector, object parameters)
 {
     if (index == 1)
     {
         return(this.LogicalName);
     }
     if (index == 2)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Structure);
         data.SetUInt8(2);
         GXCommon.SetData(data, DataType.OctetString, ASCIIEncoding.ASCII.GetBytes(ExecutedScriptLogicalName)); //Time
         GXCommon.SetData(data, DataType.UInt16, ExecutedScriptSelector);                                       //Time
         return(data.Array());
     }
     if (index == 3)
     {
         return(this.Type);
     }
     if (index == 4)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Array);
         if (ExecutionTime == null)
         {
             GXCommon.SetObjectCount(0, data);
         }
         else
         {
             GXCommon.SetObjectCount(ExecutionTime.Length, data);
             foreach (GXDateTime it in ExecutionTime)
             {
                 data.SetUInt8((byte)DataType.Structure);
                 data.SetUInt8((byte)2);                          //Count
                 GXCommon.SetData(data, DataType.Time, it.Value); //Time
                 GXCommon.SetData(data, DataType.Date, it.Value); //Date
             }
         }
         return(data.Array());
     }
     throw new ArgumentException("GetValue failed. Invalid attribute index.");
 }
        /// <summary>
        /// Sends data to the M-Bus slave device.
        /// </summary>
        /// <param name="client">DLMS client settings.</param>
        /// <param name="data">data to send</param>
        /// <returns>Generated DLMS data.</returns>
        public byte[][] SendData(GXDLMSClient client, GXMBusClientData[] data)
        {
            GXByteBuffer bb = new GXByteBuffer();

            bb.SetUInt8(DataType.Array);
            bb.SetUInt8(DataType.Structure);
            GXCommon.SetObjectCount(data.Length, bb);
            foreach (GXMBusClientData it in data)
            {
                bb.SetUInt8(DataType.Structure);
                bb.SetUInt8(3);
                bb.SetUInt8(DataType.OctetString);
                GXCommon.SetObjectCount(it.DataInformation.Length, bb);
                bb.Set(it.DataInformation);
                bb.SetUInt8(DataType.OctetString);
                GXCommon.SetObjectCount(it.ValueInformation.Length, bb);
                bb.Set(it.ValueInformation);
                GXCommon.SetData(client.Settings, bb, GXDLMSConverter.GetDLMSDataType(it.Data), it.Data);
            }
            return(client.Method(this, 6, bb.Array(), DataType.Array));
        }
Exemple #11
0
 object IGXDLMSBase.GetValue(int index, int selector, object parameters)
 {
     if (index == 1)
     {
         return(this.LogicalName);
     }
     if (index == 2)
     {
         return(Value);
     }
     if (index == 3)
     {
         List <byte> data = new List <byte>();
         data.Add((byte)DataType.Structure);
         data.Add(2);
         GXCommon.SetData(data, DataType.Int8, m_Scaler);
         GXCommon.SetData(data, DataType.Enum, Unit);
         return(data.ToArray());
     }
     throw new ArgumentException("GetValue failed. Invalid attribute index.");
 }
Exemple #12
0
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, int index, int selector, object parameters)
 {
     if (index == 1)
     {
         return(this.LogicalName);
     }
     if (index == 2)
     {
         return(Value);
     }
     if (index == 3)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Structure);
         data.SetUInt8(2);
         GXCommon.SetData(data, DataType.Int8, _scaler);
         GXCommon.SetData(data, DataType.Enum, Unit);
         return(data.Array());
     }
     throw new ArgumentException("GetValue failed. Invalid attribute index.");
 }
Exemple #13
0
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         return(this.LogicalName);
     }
     if (e.Index == 2)
     {
         return(Value);
     }
     if (e.Index == 3)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Structure);
         data.SetUInt8(2);
         GXCommon.SetData(settings, data, DataType.Int8, scaler);
         GXCommon.SetData(settings, data, DataType.Enum, Unit);
         return(data.Array());
     }
     e.Error = ErrorCode.ReadWriteDenied;
     return(null);
 }
Exemple #14
0
        byte[] GetMulticastEntries(GXDLMSSettings settings)
        {
            GXByteBuffer bb = new GXByteBuffer();

            bb.SetUInt8((byte)DataType.Array);
            if (MulticastEntries == null)
            {
                GXCommon.SetObjectCount(0, bb);
            }
            else
            {
                GXCommon.SetObjectCount(MulticastEntries.Length, bb);
                foreach (GXMacMulticastEntry it in MulticastEntries)
                {
                    bb.SetUInt8((byte)DataType.Structure);
                    bb.SetUInt8(2);
                    GXCommon.SetData(settings, bb, DataType.Int8, it.Id);
                    GXCommon.SetData(settings, bb, DataType.Int16, it.Members);
                }
            }
            return(bb.Array());
        }
Exemple #15
0
        /// <summary>
        /// Removes X.509 v3 certificate from the server using entity.
        /// </summary>
        /// <param name="client">DLMS client that is used to generate action.</param>
        /// <param name="entity">Certificate entity type.</param>
        /// <param name="type">Certificate type.</param>
        /// <param name="systemTitle">System title.</param>
        /// <returns>Generated action.</returns>
        public byte[][] RemoveCertificateByEntity(GXDLMSClient client, CertificateEntity entity, CertificateType type, byte[] systemTitle)
        {
            GXByteBuffer bb = new GXByteBuffer();

            bb.SetUInt8(DataType.Structure);
            bb.SetUInt8(2);
            //Add enum
            bb.SetUInt8(DataType.Enum);
            bb.SetUInt8(0);
            //Add certificate_identification_by_entity
            bb.SetUInt8(DataType.Structure);
            bb.SetUInt8(3);
            //Add certificate_entity
            bb.SetUInt8(DataType.Enum);
            bb.SetUInt8(entity);
            //Add certificate_type
            bb.SetUInt8(DataType.Enum);
            bb.SetUInt8(type);
            //system_title
            GXCommon.SetData(client.Settings, bb, DataType.OctetString, systemTitle);
            return(client.Method(this, 8, bb.Array(), DataType.Structure));
        }
Exemple #16
0
        private object GetImageActivateInfo(GXDLMSSettings settings)
        {
            GXByteBuffer data = new GXByteBuffer();

            data.SetUInt8((byte)DataType.Array);
            //ImageActivateInfo is returned only after verification is succeeded.
            if (ImageTransferStatus != ImageTransferStatus.VerificationSuccessful || ImageActivateInfo == null)
            {
                GXCommon.SetObjectCount(0, data);
            }
            else
            {
                GXCommon.SetObjectCount(ImageActivateInfo.Length, data);
                foreach (GXDLMSImageActivateInfo it in ImageActivateInfo)
                {
                    data.SetUInt8((byte)DataType.Structure);
                    data.SetUInt8(3);
                    GXCommon.SetData(settings, data, DataType.UInt32, it.Size);
                    if (it.Identification == null)
                    {
                        GXCommon.SetData(settings, data, DataType.OctetString, null);
                    }
                    else
                    {
                        GXCommon.SetData(settings, data, DataType.OctetString, it.Identification);
                    }
                    if (it.Signature == null || it.Signature.Length == 0)
                    {
                        GXCommon.SetData(settings, data, DataType.OctetString, null);
                    }
                    else
                    {
                        GXCommon.SetData(settings, data, DataType.OctetString, it.Signature);
                    }
                }
            }
            return(data.Array());
        }
 private void AddEntry(GXDLMSSettings settings, GXScheduleEntry it, GXByteBuffer data)
 {
     data.SetUInt8((byte)DataType.Structure);
     data.SetUInt8(10);
     //Add index.
     data.SetUInt8((byte)DataType.UInt16);
     data.SetUInt16(it.Index);
     //Add enable.
     data.SetUInt8((byte)DataType.Boolean);
     data.SetUInt8((byte)(it.Enable ? 1 : 0));
     //Add logical Name.
     data.SetUInt8((byte)DataType.OctetString);
     data.SetUInt8(6);
     if (it.Script == null)
     {
         data.Set(new byte[] { 0, 0, 0, 0, 0, 0 });
     }
     else
     {
         data.Set(GXCommon.LogicalNameToBytes(it.Script.LogicalName));
     }
     //Add script selector.
     data.SetUInt8((byte)DataType.UInt16);
     data.SetUInt16(it.ScriptSelector);
     //Add switch time.
     GXCommon.SetData(settings, data, DataType.OctetString, it.SwitchTime);
     //Add validity window.
     data.SetUInt8((byte)DataType.UInt16);
     data.SetUInt16(it.ValidityWindow);
     //Add exec week days.
     GXCommon.SetData(settings, data, DataType.BitString, GXBitString.ToBitString((byte)it.ExecWeekdays, 7));
     //Add exec spec days.
     GXCommon.SetData(settings, data, DataType.BitString, it.ExecSpecDays);
     //Add begin date.
     GXCommon.SetData(settings, data, DataType.OctetString, it.BeginDate);
     //Add end date.
     GXCommon.SetData(settings, data, DataType.OctetString, it.EndDate);
 }
Exemple #18
0
        /// <summary>
        /// Returns Association View.
        /// </summary>
        private GXByteBuffer GetObjects(GXDLMSSettings settings, ValueEventArgs e)
        {
            GXByteBuffer data = new GXByteBuffer();

            //Add count only for first time.
            if (settings.Index == 0)
            {
                settings.Count = (UInt16)ObjectList.Count;
                data.SetUInt8((byte)DataType.Array);
                GXCommon.SetObjectCount(ObjectList.Count, data);
            }
            ushort pos = 0;

            foreach (GXDLMSObject it in ObjectList)
            {
                ++pos;
                if (!(pos <= settings.Index))
                {
                    data.SetUInt8((byte)DataType.Structure);
                    data.SetUInt8((byte)4);                                           //Count
                    GXCommon.SetData(settings, data, DataType.UInt16, it.ObjectType); //ClassID
                    GXCommon.SetData(settings, data, DataType.UInt8, it.Version);     //Version
                    //LN
                    GXCommon.SetData(settings, data, DataType.OctetString, GXCommon.LogicalNameToBytes(it.LogicalName));
                    GetAccessRights(settings, it, e.Server, data); //Access rights.
                    ++settings.Index;
                    if (settings.IsServer)
                    {
                        //If PDU is full.
                        if ((settings.NegotiatedConformance & Conformance.GeneralBlockTransfer) == 0 && !e.SkipMaxPduSize && data.Size >= settings.MaxPduSize)
                        {
                            break;
                        }
                    }
                }
            }
            return(data);
        }
        /// <summary>
        /// Returns captured objects.
        /// </summary>
        /// <param name="settings">DLMS settings.</param>
        /// <returns></returns>
        byte[] GetCaptureObjects(GXDLMSSettings settings)
        {
            GXByteBuffer data = new GXByteBuffer();

            data.SetUInt8((byte)DataType.Array);
            //Add count
            GXCommon.SetObjectCount(CaptureObjects.Count, data);
            foreach (var it in CaptureObjects)
            {
                data.SetUInt8((byte)DataType.Structure);
                //Count
                data.SetUInt8(4);
                //ClassID
                GXCommon.SetData(settings, data, DataType.UInt16, it.Key.ObjectType);
                //LN
                GXCommon.SetData(settings, data, DataType.OctetString, GXCommon.LogicalNameToBytes(it.Key.LogicalName));
                //Selected Attribute Index
                GXCommon.SetData(settings, data, DataType.Int8, it.Value.AttributeIndex);
                //Selected Data Index
                GXCommon.SetData(settings, data, DataType.UInt16, it.Value.DataIndex);
            }
            return(data.Array());
        }
        private object GetImageActivateInfo(GXDLMSSettings settings)
        {
            GXByteBuffer data = new GXByteBuffer();

            data.SetUInt8((byte)DataType.Array);
            if (ImageActivateInfo == null)
            {
                GXCommon.SetObjectCount(0, data);
            }
            else
            {
                GXCommon.SetObjectCount(ImageActivateInfo.Length, data);
                foreach (GXDLMSImageActivateInfo it in ImageActivateInfo)
                {
                    data.SetUInt8((byte)DataType.Structure);
                    data.SetUInt8(3);
                    GXCommon.SetData(settings, data, DataType.UInt32, it.Size);
                    if (it.Identification == null)
                    {
                        GXCommon.SetData(settings, data, DataType.OctetString, null);
                    }
                    else
                    {
                        GXCommon.SetData(settings, data, DataType.OctetString, ASCIIEncoding.ASCII.GetBytes(it.Identification));
                    }
                    if (it.Signature == null || it.Signature.Length == 0)
                    {
                        GXCommon.SetData(settings, data, DataType.OctetString, null);
                    }
                    else
                    {
                        GXCommon.SetData(settings, data, DataType.OctetString, ASCIIEncoding.ASCII.GetBytes(it.Signature));
                    }
                }
            }
            return(data.Array());
        }
Exemple #21
0
        /// <summary>
        /// Generates data notification message.
        /// </summary>
        /// <param name="date">Date time. Set To Min or Max if not added</param>
        /// <param name="objects">List of objects and attribute indexes to notify.</param>
        /// <returns>Generated data notification message(s).</returns>
        public byte[][] GenerateDataNotificationMessage(DateTime date, List <KeyValuePair <GXDLMSObject, int> > objects)
        {
            if (objects == null)
            {
                throw new ArgumentNullException("objects");
            }
            GXByteBuffer buff = new GXByteBuffer();

            if (date == DateTime.MinValue || date == DateTime.MaxValue)
            {
                buff.SetUInt8(DataType.None);
            }
            else
            {
                GXCommon.SetData(buff, DataType.DateTime, date);
            }
            buff.SetUInt8(DataType.Array);
            GXCommon.SetObjectCount(objects.Count, buff);
            foreach (KeyValuePair <GXDLMSObject, int> it in objects)
            {
                AddData(it.Key, it.Value, buff);
            }
            return(GXDLMS.SplitPdu(Settings, Command.DataNotification, 0, buff, ErrorCode.Ok, DateTime.MinValue)[0]);
        }
Exemple #22
0
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, int index, int selector, object parameters)
 {
     if (index == 1)
     {
         return(this.LogicalName);
     }
     if (index == 2)
     {
         return(this.DataLinkLayerReference);
     }
     if (index == 3)
     {
         return(this.IPAddress);
     }
     if (index == 4)
     {
         return(this.MulticastIPAddress);
     }
     if (index == 5)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Array);
         if (IPOptions == null)
         {
             data.SetUInt8(1);
         }
         else
         {
             GXCommon.SetObjectCount(IPOptions.Length, data);
             foreach (GXDLMSIp4SetupIpOption it in IPOptions)
             {
                 data.SetUInt8((byte)DataType.Structure);
                 data.SetUInt8(3);
                 GXCommon.SetData(data, DataType.UInt8, it.Type);
                 GXCommon.SetData(data, DataType.UInt8, it.Length);
                 GXCommon.SetData(data, DataType.OctetString, it.Data);
             }
         }
         return(data.Array());
     }
     if (index == 6)
     {
         return(this.SubnetMask);
     }
     if (index == 7)
     {
         return(this.GatewayIPAddress);
     }
     if (index == 8)
     {
         return(this.UseDHCP);
     }
     if (index == 9)
     {
         return(this.PrimaryDNSAddress);
     }
     if (index == 10)
     {
         return(this.SecondaryDNSAddress);
     }
     throw new ArgumentException("GetValue failed. Invalid attribute index.");
 }
Exemple #23
0
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         return(this.LogicalName);
     }
     if (e.Index == 2)
     {
         return(MaxHops);
     }
     if (e.Index == 3)
     {
         return(WeakLqiValue);
     }
     if (e.Index == 4)
     {
         return(SecurityLevel);
     }
     if (e.Index == 5)
     {
         GXByteBuffer bb = new GXByteBuffer();
         bb.SetUInt8((byte)DataType.Array);
         if (PrefixTable == null)
         {
             bb.SetUInt8(0);
         }
         else
         {
             GXCommon.SetObjectCount(PrefixTable.Length, bb);
             foreach (var it in PrefixTable)
             {
                 GXCommon.SetData(settings, bb, GXCommon.GetValueType(it), it);
             }
         }
         return(bb.Array());
     }
     if (e.Index == 6)
     {
         GXByteBuffer bb = new GXByteBuffer();
         bb.SetUInt8((byte)DataType.Array);
         if (RoutingConfiguration == null)
         {
             bb.SetUInt8(0);
         }
         else
         {
             GXCommon.SetObjectCount(RoutingConfiguration.Count, bb);
             foreach (GXDLMSRoutingConfiguration it in RoutingConfiguration)
             {
                 bb.SetUInt8((byte)DataType.Structure);
                 bb.SetUInt8(14);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.NetTraversalTime);
                 GXCommon.SetData(settings, bb, DataType.UInt16, it.RoutingTableEntryTtl);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.Kr);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.Km);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.Kc);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.Kq);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.Kh);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.Krt);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.RreqRetries);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.RreqRerrWait);
                 GXCommon.SetData(settings, bb, DataType.UInt16, it.BlacklistTableEntryTtl);
                 GXCommon.SetData(settings, bb, DataType.Boolean, it.UnicastRreqGenEnable);
                 GXCommon.SetData(settings, bb, DataType.Boolean, it.RlcEnabled);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.AddRevLinkCost);
             }
         }
         return(bb.Array());
     }
     if (e.Index == 7)
     {
         return(BroadcastLogTableEntryTtl);
     }
     if (e.Index == 8)
     {
         GXByteBuffer bb = new GXByteBuffer();
         bb.SetUInt8((byte)DataType.Array);
         if (RoutingTable == null)
         {
             bb.SetUInt8(0);
         }
         else
         {
             GXCommon.SetObjectCount(RoutingTable.Count, bb);
             foreach (GXDLMSRoutingTable it in RoutingTable)
             {
                 bb.SetUInt8((byte)DataType.Structure);
                 bb.SetUInt8(6);
                 GXCommon.SetData(settings, bb, DataType.UInt16, it.DestinationAddress);
                 GXCommon.SetData(settings, bb, DataType.UInt16, it.NextHopAddress);
                 GXCommon.SetData(settings, bb, DataType.UInt16, it.RouteCost);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.HopCount);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.WeakLinkCount);
                 GXCommon.SetData(settings, bb, DataType.UInt16, it.ValidTime);
             }
         }
         return(bb.Array());
     }
     if (e.Index == 9)
     {
         GXByteBuffer bb = new GXByteBuffer();
         bb.SetUInt8((byte)DataType.Array);
         if (ContextInformationTable == null)
         {
             bb.SetUInt8(0);
         }
         else
         {
             GXCommon.SetObjectCount(ContextInformationTable.Count, bb);
             foreach (GXDLMSContextInformationTable it in ContextInformationTable)
             {
                 bb.SetUInt8((byte)DataType.Structure);
                 bb.SetUInt8(5);
                 GXCommon.SetData(settings, bb, DataType.BitString, it.CID);
                 if (it.Context == null)
                 {
                     GXCommon.SetData(settings, bb, DataType.UInt8, 0);
                 }
                 else
                 {
                     GXCommon.SetData(settings, bb, DataType.UInt8, it.Context.Length);
                 }
                 GXCommon.SetData(settings, bb, DataType.OctetString, it.Context);
                 GXCommon.SetData(settings, bb, DataType.Boolean, it.Compression);
                 GXCommon.SetData(settings, bb, DataType.UInt16, it.ValidLifetime);
             }
         }
         return(bb.Array());
     }
     if (e.Index == 10)
     {
         GXByteBuffer bb = new GXByteBuffer();
         bb.SetUInt8((byte)DataType.Array);
         if (BlacklistTable == null)
         {
             bb.SetUInt8(0);
         }
         else
         {
             GXCommon.SetObjectCount(BlacklistTable.Count, bb);
             foreach (var it in BlacklistTable)
             {
                 bb.SetUInt8((byte)DataType.Structure);
                 bb.SetUInt8(2);
                 GXCommon.SetData(settings, bb, DataType.UInt16, it.Key);
                 GXCommon.SetData(settings, bb, DataType.UInt16, it.Value);
             }
         }
         return(bb.Array());
     }
     if (e.Index == 11)
     {
         GXByteBuffer bb = new GXByteBuffer();
         bb.SetUInt8((byte)DataType.Array);
         if (BroadcastLogTable == null)
         {
             bb.SetUInt8(0);
         }
         else
         {
             GXCommon.SetObjectCount(BroadcastLogTable.Count, bb);
             foreach (GXDLMSBroadcastLogTable it in BroadcastLogTable)
             {
                 bb.SetUInt8((byte)DataType.Structure);
                 bb.SetUInt8(3);
                 GXCommon.SetData(settings, bb, DataType.UInt16, it.SourceAddress);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.SequenceNumber);
                 GXCommon.SetData(settings, bb, DataType.UInt16, it.ValidTime);
             }
         }
         return(bb.Array());
     }
     if (e.Index == 12)
     {
         GXByteBuffer bb = new GXByteBuffer();
         bb.SetUInt8((byte)DataType.Array);
         if (GroupTable == null)
         {
             bb.SetUInt8(0);
         }
         else
         {
             GXCommon.SetObjectCount(GroupTable.Length, bb);
             foreach (UInt16 it in GroupTable)
             {
                 GXCommon.SetData(settings, bb, DataType.UInt16, it);
             }
         }
         return(bb.Array());
     }
     if (e.Index == 13)
     {
         return(MaxJoinWaitTime);
     }
     if (e.Index == 14)
     {
         return(PathDiscoveryTime);
     }
     if (e.Index == 15)
     {
         return(ActiveKeyIndex);
     }
     if (e.Index == 16)
     {
         return(MetricType);
     }
     if (e.Index == 17)
     {
         return(CoordShortAddress);
     }
     if (e.Index == 18)
     {
         return(DisableDefaultRouting);
     }
     if (e.Index == 19)
     {
         return(DeviceType);
     }
     e.Error = ErrorCode.ReadWriteDenied;
     return(null);
 }
Exemple #24
0
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         return(GXCommon.LogicalNameToBytes(LogicalName));
     }
     else if (e.Index == 2)
     {
         return(InitiatorElectricalPhase);
     }
     else if (e.Index == 3)
     {
         return(DeltaElectricalPhase);
     }
     else if (e.Index == 4)
     {
         return(MaxReceivingGain);
     }
     else if (e.Index == 5)
     {
         return(MaxTransmittingGain);
     }
     else if (e.Index == 6)
     {
         return(SearchInitiatorThreshold);
     }
     else if (e.Index == 7)
     {
         GXByteBuffer bb = new GXByteBuffer();
         bb.SetUInt8(DataType.Structure);
         bb.SetUInt8(2);
         GXCommon.SetData(settings, bb, DataType.UInt32, MarkFrequency);
         GXCommon.SetData(settings, bb, DataType.UInt32, SpaceFrequency);
         return(bb.Array());
     }
     else if (e.Index == 8)
     {
         return(MacAddress);
     }
     else if (e.Index == 9)
     {
         GXByteBuffer bb = new GXByteBuffer();
         bb.SetUInt8(DataType.Array);
         if (MacGroupAddresses == null)
         {
             bb.SetUInt8(0);
         }
         else
         {
             GXCommon.SetObjectCount(MacGroupAddresses.Length, bb);
             foreach (UInt16 it in MacGroupAddresses)
             {
                 GXCommon.SetData(settings, bb, DataType.UInt16, it);
             }
         }
         return(bb.Array());
     }
     else if (e.Index == 10)
     {
         return(Repeater);
     }
     else if (e.Index == 11)
     {
         return(RepeaterStatus);
     }
     else if (e.Index == 12)
     {
         return(MinDeltaCredit);
     }
     else if (e.Index == 13)
     {
         return(InitiatorMacAddress);
     }
     else if (e.Index == 14)
     {
         return(SynchronizationLocked);
     }
     else if (e.Index == 15)
     {
         return(TransmissionSpeed);
     }
     e.Error = ErrorCode.ReadWriteDenied;
     return(null);
 }
Exemple #25
0
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         return(GXCommon.LogicalNameToBytes(LogicalName));
     }
     if (e.Index == 2)
     {
         return(GXCommon.LogicalNameToBytes(PHYReference));
     }
     if (e.Index == 3)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Array);
         if (LCPOptions == null)
         {
             data.SetUInt8(0);
         }
         else
         {
             data.SetUInt8((byte)LCPOptions.Length);
             foreach (GXDLMSPppSetupLcpOption it in LCPOptions)
             {
                 data.SetUInt8((byte)DataType.Structure);
                 data.SetUInt8((byte)3);
                 GXCommon.SetData(settings, data, DataType.UInt8, it.Type);
                 GXCommon.SetData(settings, data, DataType.UInt8, it.Length);
                 GXCommon.SetData(settings, data, GXDLMSConverter.GetDLMSDataType(it.Data), it.Data);
             }
         }
         return(data.Array());
     }
     if (e.Index == 4)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Array);
         if (IPCPOptions == null)
         {
             data.SetUInt8(0);
         }
         else
         {
             data.SetUInt8((byte)IPCPOptions.Length);
             foreach (GXDLMSPppSetupIPCPOption it in IPCPOptions)
             {
                 data.SetUInt8((byte)DataType.Structure);
                 data.SetUInt8((byte)3);
                 GXCommon.SetData(settings, data, DataType.UInt8, it.Type);
                 GXCommon.SetData(settings, data, DataType.UInt8, it.Length);
                 GXCommon.SetData(settings, data, GXDLMSConverter.GetDLMSDataType(it.Data), it.Data);
             }
         }
         return(data.Array());
     }
     else if (e.Index == 5)
     {
         if (UserName == null || UserName.Length == 0)
         {
             return(null);
         }
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Structure);
         data.SetUInt8(2);
         GXCommon.SetData(settings, data, DataType.OctetString, UserName);
         GXCommon.SetData(settings, data, DataType.OctetString, Password);
         return(data.Array());
     }
     e.Error = ErrorCode.ReadWriteDenied;
     return(null);
 }
Exemple #26
0
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         return(GXCommon.LogicalNameToBytes(LogicalName));
     }
     if (e.Index == 2)
     {
         return(ShortAddress);
     }
     if (e.Index == 3)
     {
         return(RcCoord);
     }
     if (e.Index == 4)
     {
         return(PANId);
     }
     if (e.Index == 5)
     {
         GXByteBuffer bb = new GXByteBuffer();
         bb.SetUInt8((byte)DataType.Array);
         if (KeyTable == null)
         {
             bb.SetUInt8(0);
         }
         else
         {
             GXCommon.SetObjectCount(KeyTable.Count, bb);
             foreach (GXKeyValuePair <byte, byte[]> it in KeyTable)
             {
                 bb.SetUInt8((byte)DataType.Structure);
                 bb.SetUInt8(2);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.Key);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.Value);
             }
         }
         return(bb.Array());
     }
     if (e.Index == 6)
     {
         return(FrameCounter);
     }
     if (e.Index == 7)
     {
         return(ToneMask);
     }
     if (e.Index == 8)
     {
         return(TmrTtl);
     }
     if (e.Index == 9)
     {
         return(MaxFrameRetries);
     }
     if (e.Index == 10)
     {
         return(NeighbourTableEntryTtl);
     }
     if (e.Index == 11)
     {
         GXByteBuffer bb = new GXByteBuffer();
         bb.SetUInt8((byte)DataType.Array);
         if (NeighbourTable == null)
         {
             bb.SetUInt8(0);
         }
         else
         {
             GXCommon.SetObjectCount(NeighbourTable.Length, bb);
             foreach (GXDLMSNeighbourTable it in NeighbourTable)
             {
                 bb.SetUInt8((byte)DataType.Structure);
                 bb.SetUInt8(11);
                 GXCommon.SetData(settings, bb, DataType.UInt16, it.ShortAddress);
                 GXCommon.SetData(settings, bb, DataType.Boolean, it.Enabled);
                 GXCommon.SetData(settings, bb, DataType.BitString, it.ToneMap);
                 GXCommon.SetData(settings, bb, DataType.Enum, it.Modulation);
                 GXCommon.SetData(settings, bb, DataType.Int8, it.TxGain);
                 GXCommon.SetData(settings, bb, DataType.Enum, it.TxRes);
                 GXCommon.SetData(settings, bb, DataType.BitString, it.TxCoeff);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.Lqi);
                 GXCommon.SetData(settings, bb, DataType.Int8, it.PhaseDifferential);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.TMRValidTime);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.NeighbourValidTime);
             }
         }
         return(bb.Array());
     }
     if (e.Index == 12)
     {
         return(HighPriorityWindowSize);
     }
     if (e.Index == 13)
     {
         return(CscmFairnessLimit);
     }
     if (e.Index == 14)
     {
         return(BeaconRandomizationWindowLength);
     }
     if (e.Index == 15)
     {
         return(A);
     }
     if (e.Index == 16)
     {
         return(K);
     }
     if (e.Index == 17)
     {
         return(MinCwAttempts);
     }
     if (e.Index == 18)
     {
         return(CenelecLegacyMode);
     }
     if (e.Index == 19)
     {
         return(FccLegacyMode);
     }
     if (e.Index == 20)
     {
         return(MaxBe);
     }
     if (e.Index == 21)
     {
         return(MaxCsmaBackoffs);
     }
     if (e.Index == 22)
     {
         return(MinBe);
     }
     e.Error = ErrorCode.ReadWriteDenied;
     return(null);
 }
Exemple #27
0
        ///<summary>
        /// Handle action request.
        ///</summary>
        public static void HandleMethodRequest(GXDLMSSettings settings, GXDLMSServer server, GXByteBuffer data, GXDLMSConnectionEventArgs connectionInfo, GXByteBuffer replyData, GXDLMSTranslatorStructure xml)
        {
            ErrorCode    error = ErrorCode.Ok;
            GXByteBuffer bb    = new GXByteBuffer();
            // Get type.
            ActionRequestType type = (ActionRequestType)data.GetUInt8();
            // Get invoke ID and priority.
            byte invokeId = data.GetUInt8();

            settings.UpdateInvokeId(invokeId);
            // CI
            ObjectType ci = (ObjectType)data.GetUInt16();

            byte[] ln = new byte[6];
            data.Get(ln);
            // Attribute Id
            byte id = data.GetUInt8();
            // Get parameters.
            object parameters = null;
            byte   selection  = data.GetUInt8();

            if (xml != null)
            {
                xml.AppendStartTag(Command.MethodRequest);
                if (type == ActionRequestType.Normal)
                {
                    xml.AppendStartTag(Command.MethodRequest, ActionRequestType.Normal);
                    xml.AppendLine(TranslatorTags.InvokeId, "Value", xml.IntegerToHex(invokeId, 2));
                    AppendMethodDescriptor(xml, (int)ci, ln, id);
                    if (selection != 0)
                    {
                        //MethodInvocationParameters
                        xml.AppendStartTag(TranslatorTags.MethodInvocationParameters);
                        GXDataInfo di = new GXDataInfo();
                        di.xml = xml;
                        GXCommon.GetData(settings, data, di);
                        xml.AppendEndTag(TranslatorTags.MethodInvocationParameters);
                    }
                    xml.AppendEndTag(Command.MethodRequest, ActionRequestType.Normal);
                }
                xml.AppendEndTag(Command.MethodRequest);
                return;
            }
            if (selection != 0)
            {
                GXDataInfo info = new GXDataInfo();
                parameters = GXCommon.GetData(settings, data, info);
            }

            GXDLMSObject obj = settings.Objects.FindByLN(ci, GXCommon.ToLogicalName(ln));

            if (settings.Connected == ConnectionState.None && !settings.CanAccess() && (ci != ObjectType.AssociationLogicalName || id != 1))
            {
                replyData.Set(GXDLMSServer.GenerateConfirmedServiceError(ConfirmedServiceError.InitiateError,
                                                                         ServiceError.Service, (byte)Service.Unsupported));
                return;
            }

            if (obj == null)
            {
                obj = server.NotifyFindObject(ci, 0, GXCommon.ToLogicalName(ln));
            }
            if (obj == null)
            {
                // Device reports a undefined object.
                error = ErrorCode.UndefinedObject;
            }
            else
            {
                ValueEventArgs e = new ValueEventArgs(server, obj, id, 0, parameters);
                e.InvokeId = invokeId;
                if (server.NotifyGetMethodAccess(e) == MethodAccessMode.NoAccess)
                {
                    error = ErrorCode.ReadWriteDenied;
                }
                else
                {
                    server.NotifyAction(new ValueEventArgs[] { e });
                    byte[] actionReply;
                    if (e.Handled)
                    {
                        actionReply = (byte[])e.Value;
                    }
                    else
                    {
                        actionReply = (obj as IGXDLMSBase).Invoke(settings, e);
                        server.NotifyPostAction(new ValueEventArgs[] { e });
                    }
                    //Set default action reply if not given.
                    if (actionReply != null && e.Error == 0)
                    {
                        //Add return parameters
                        bb.SetUInt8(1);
                        //Add parameters error code.
                        bb.SetUInt8(0);
                        GXCommon.SetData(settings, bb, GXDLMSConverter.GetDLMSDataType(actionReply), actionReply);
                    }
                    else
                    {
                        error = e.Error;
                        //Add return parameters
                        bb.SetUInt8(0);
                    }
                }
                invokeId = (byte)e.InvokeId;
            }

            GXDLMSLNParameters p = new GXDLMSLNParameters(null, settings, invokeId, Command.MethodResponse, 1, null, bb, (byte)error);

            GXDLMS.GetLNPdu(p, replyData);
            //If High level authentication fails.
            if (obj is GXDLMSAssociationLogicalName && id == 1)
            {
                if ((obj as GXDLMSAssociationLogicalName).AssociationStatus == Objects.Enums.AssociationStatus.Associated)
                {
                    server.NotifyConnected(connectionInfo);
                    settings.Connected |= ConnectionState.Dlms;
                }
                else
                {
                    server.NotifyInvalidConnection(connectionInfo);
                    settings.Connected &= ~ConnectionState.Dlms;
                }
            }
        }
Exemple #28
0
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         return(this.LogicalName);
     }
     if (e.Index == 2)
     {
         return(this.DataLinkLayerReference);
     }
     if (e.Index == 3)
     {
         return(AddressConfigMode);
     }
     if (e.Index == 4)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Array);
         if (UnicastIPAddress == null)
         {
             //Object count is zero.
             data.SetUInt8(0);
         }
         else
         {
             GXCommon.SetObjectCount(UnicastIPAddress.Length, data);
             foreach (IPAddress it in UnicastIPAddress)
             {
                 GXCommon.SetData(settings, data, DataType.OctetString, it.GetAddressBytes());
             }
         }
         return(data.Array());
     }
     if (e.Index == 5)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Array);
         if (MulticastIPAddress == null)
         {
             //Object count is zero.
             data.SetUInt8(0);
         }
         else
         {
             GXCommon.SetObjectCount(MulticastIPAddress.Length, data);
             foreach (IPAddress it in MulticastIPAddress)
             {
                 GXCommon.SetData(settings, data, DataType.OctetString, it.GetAddressBytes());
             }
         }
         return(data.Array());
     }
     if (e.Index == 6)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Array);
         if (GatewayIPAddress == null)
         {
             //Object count is zero.
             data.SetUInt8(0);
         }
         else
         {
             GXCommon.SetObjectCount(GatewayIPAddress.Length, data);
             foreach (IPAddress it in GatewayIPAddress)
             {
                 GXCommon.SetData(settings, data, DataType.OctetString, it.GetAddressBytes());
             }
         }
         return(data.Array());
     }
     if (e.Index == 7)
     {
         return(PrimaryDNSAddress.GetAddressBytes());
     }
     if (e.Index == 8)
     {
         return(SecondaryDNSAddress.GetAddressBytes());
     }
     if (e.Index == 9)
     {
         return(TrafficClass);
     }
     if (e.Index == 10)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Array);
         if (NeighborDiscoverySetup == null)
         {
             //Object count is zero.
             data.SetUInt8(0);
         }
         else
         {
             GXCommon.SetObjectCount(NeighborDiscoverySetup.Length, data);
             foreach (GXNeighborDiscoverySetup it in NeighborDiscoverySetup)
             {
                 data.SetUInt8((byte)DataType.Structure);
                 data.SetUInt8(3);
                 GXCommon.SetData(settings, data, DataType.UInt8, it.MaxRetry);
                 GXCommon.SetData(settings, data, DataType.UInt16, it.RetryWaitTime);
                 GXCommon.SetData(settings, data, DataType.UInt32, it.SendPeriod);
             }
         }
         return(data.Array());
     }
     e.Error = ErrorCode.ReadWriteDenied;
     return(null);
 }
Exemple #29
0
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         return(GXCommon.LogicalNameToBytes(LogicalName));
     }
     if (e.Index == 2)
     {
         return(GetObjects(settings, e).Array());
     }
     if (e.Index == 3)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Structure);
         //Add count
         data.SetUInt8(2);
         data.SetUInt8((byte)DataType.Int8);
         data.SetUInt8(ClientSAP);
         data.SetUInt8((byte)DataType.UInt16);
         data.SetUInt16(ServerSAP);
         return(data.Array());
     }
     if (e.Index == 4)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Structure);
         //Add count
         data.SetUInt8(0x7);
         GXCommon.SetData(settings, data, DataType.UInt8, ApplicationContextName.JointIsoCtt);
         GXCommon.SetData(settings, data, DataType.UInt8, ApplicationContextName.Country);
         GXCommon.SetData(settings, data, DataType.UInt16, ApplicationContextName.CountryName);
         GXCommon.SetData(settings, data, DataType.UInt8, ApplicationContextName.IdentifiedOrganization);
         GXCommon.SetData(settings, data, DataType.UInt8, ApplicationContextName.DlmsUA);
         GXCommon.SetData(settings, data, DataType.UInt8, ApplicationContextName.ApplicationContext);
         GXCommon.SetData(settings, data, DataType.UInt8, ApplicationContextName.ContextId);
         return(data.Array());
     }
     if (e.Index == 5)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Structure);
         data.SetUInt8(6);
         GXByteBuffer bb = new GXByteBuffer();
         bb.SetUInt32((UInt32)XDLMSContextInfo.Conformance);
         GXCommon.SetData(settings, data, DataType.BitString, bb.SubArray(1, 3));
         GXCommon.SetData(settings, data, DataType.UInt16, XDLMSContextInfo.MaxReceivePduSize);
         GXCommon.SetData(settings, data, DataType.UInt16, XDLMSContextInfo.MaxSendPduSize);
         GXCommon.SetData(settings, data, DataType.UInt8, XDLMSContextInfo.DlmsVersionNumber);
         GXCommon.SetData(settings, data, DataType.Int8, XDLMSContextInfo.QualityOfService);
         GXCommon.SetData(settings, data, DataType.OctetString, XDLMSContextInfo.CypheringInfo);
         return(data.Array());
     }
     if (e.Index == 6)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Structure);
         //Add count
         data.SetUInt8(0x7);
         GXCommon.SetData(settings, data, DataType.UInt8, AuthenticationMechanismName.JointIsoCtt);
         GXCommon.SetData(settings, data, DataType.UInt8, AuthenticationMechanismName.Country);
         GXCommon.SetData(settings, data, DataType.UInt16, AuthenticationMechanismName.CountryName);
         GXCommon.SetData(settings, data, DataType.UInt8, AuthenticationMechanismName.IdentifiedOrganization);
         GXCommon.SetData(settings, data, DataType.UInt8, AuthenticationMechanismName.DlmsUA);
         GXCommon.SetData(settings, data, DataType.UInt8, AuthenticationMechanismName.AuthenticationMechanismName);
         GXCommon.SetData(settings, data, DataType.UInt8, AuthenticationMechanismName.MechanismId);
         return(data.Array());
     }
     if (e.Index == 7)
     {
         return(Secret);
     }
     if (e.Index == 8)
     {
         return(AssociationStatus);
     }
     if (e.Index == 9)
     {
         return(GXCommon.LogicalNameToBytes(SecuritySetupReference));
     }
     if (e.Index == 10)
     {
         return(GetUserList(settings, e).Array());
     }
     if (e.Index == 11)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Structure);
         //Add structure size.
         data.SetUInt8(2);
         GXCommon.SetData(settings, data, DataType.UInt8, CurrentUser.Key);
         GXCommon.SetData(settings, data, DataType.String, CurrentUser.Value);
         return(data.Array());
     }
     e.Error = ErrorCode.ReadWriteDenied;
     return(null);
 }
        object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
        {
            if (e.Index == 1)
            {
                return(GXCommon.LogicalNameToBytes(LogicalName));
            }
            else if (e.Index == 2)
            {
                GXByteBuffer data = new GXByteBuffer();
                data.SetUInt8((byte)DataType.Structure);
                data.SetUInt8(3);
                if (MonitoredValue == null)
                {
                    GXCommon.SetData(settings, data, DataType.UInt16, 0);
                    GXCommon.SetData(settings, data, DataType.OctetString, GXCommon.LogicalNameToBytes(null));
                    GXCommon.SetData(settings, data, DataType.Int8, 0);
                }
                else
                {
                    GXCommon.SetData(settings, data, DataType.UInt16, MonitoredValue.ObjectType);
                    GXCommon.SetData(settings, data, DataType.OctetString, GXCommon.LogicalNameToBytes(MonitoredValue.LogicalName));
                    GXCommon.SetData(settings, data, DataType.Int8, MonitoredAttributeIndex);
                }
                return(data.Array());
            }
            else if (e.Index == 3)
            {
                return(ThresholdActive);
            }
            else if (e.Index == 4)
            {
                return(ThresholdNormal);
            }
            else if (e.Index == 5)
            {
                return(ThresholdEmergency);
            }
            else if (e.Index == 6)
            {
                return(MinOverThresholdDuration);
            }
            else if (e.Index == 7)
            {
                return(MinUnderThresholdDuration);
            }
            else if (e.Index == 8)
            {
                GXByteBuffer data = new GXByteBuffer();
                data.SetUInt8((byte)DataType.Structure);
                data.SetUInt8(3);
                GXCommon.SetData(settings, data, DataType.UInt16, EmergencyProfile.ID);
                GXCommon.SetData(settings, data, DataType.OctetString, EmergencyProfile.ActivationTime);
                GXCommon.SetData(settings, data, DataType.UInt32, EmergencyProfile.Duration);
                return(data.Array());
            }
            else if (e.Index == 9)
            {
                GXByteBuffer data = new GXByteBuffer();
                data.SetUInt8((byte)DataType.Array);
                if (EmergencyProfileGroupIDs == null)
                {
                    data.SetUInt8(0);
                }
                else
                {
                    data.SetUInt8((byte)EmergencyProfileGroupIDs.Length);
                    foreach (object it in EmergencyProfileGroupIDs)
                    {
                        GXCommon.SetData(settings, data, DataType.UInt16, it);
                    }
                }

                return(data.Array());
            }
            else if (e.Index == 10)
            {
                return(EmergencyProfileActive);
            }
            else if (e.Index == 11)
            {
                GXByteBuffer data = new GXByteBuffer();
                data.SetUInt8((byte)DataType.Structure);
                data.SetUInt8(2);
                data.SetUInt8((byte)DataType.Structure);
                data.SetUInt8(2);
                GXCommon.SetData(settings, data, DataType.OctetString, GXCommon.LogicalNameToBytes(ActionOverThreshold.LogicalName));
                GXCommon.SetData(settings, data, DataType.UInt16, ActionOverThreshold.ScriptSelector);
                data.SetUInt8((byte)DataType.Structure);
                data.SetUInt8(2);
                GXCommon.SetData(settings, data, DataType.OctetString, GXCommon.LogicalNameToBytes(ActionUnderThreshold.LogicalName));
                GXCommon.SetData(settings, data, DataType.UInt16, ActionUnderThreshold.ScriptSelector);
                return(data.Array());
            }
            e.Error = ErrorCode.ReadWriteDenied;
            return(null);
        }