private void LoadRoutingTable(GXXmlReader reader)
 {
     RoutingTable.Clear();
     if (reader.IsStartElement("RoutingTable", true))
     {
         while (reader.IsStartElement("Item", false))
         {
             GXDLMSRoutingTable it = new GXDLMSRoutingTable();
             RoutingTable.Add(it);
             it.DestinationAddress = (UInt16)reader.ReadElementContentAsInt("DestinationAddress");
             it.NextHopAddress     = (UInt16)reader.ReadElementContentAsInt("NextHopAddress");
             it.RouteCost          = (UInt16)reader.ReadElementContentAsInt("RouteCost");
             it.HopCount           = (byte)reader.ReadElementContentAsInt("HopCount");
             it.WeakLinkCount      = (byte)reader.ReadElementContentAsInt("WeakLinkCount");
             it.ValidTime          = (UInt16)reader.ReadElementContentAsInt("ValidTime");
         }
         reader.ReadEndElement("RoutingTable");
     }
 }
Esempio n. 2
0
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         if (e.Value is string)
         {
             LogicalName = e.Value.ToString();
         }
         else
         {
             LogicalName = GXDLMSClient.ChangeType((byte[])e.Value, DataType.OctetString).ToString();
         }
     }
     else if (e.Index == 2)
     {
         MaxHops = Convert.ToByte(e.Value);
     }
     else if (e.Index == 3)
     {
         WeakLqiValue = Convert.ToByte(e.Value);
     }
     else if (e.Index == 4)
     {
         SecurityLevel = Convert.ToByte(e.Value);
     }
     else if (e.Index == 5)
     {
         List <object> list = new List <object>();
         if (e.Value != null)
         {
             list.AddRange((object[])e.Value);
         }
         PrefixTable = list.ToArray();
     }
     else if (e.Index == 6)
     {
         RoutingConfiguration.Clear();
         if (e.Value != null)
         {
             foreach (object v in (object[])e.Value)
             {
                 object[] tmp = (object[])v;
                 GXDLMSRoutingConfiguration it = new GXDLMSRoutingConfiguration();
                 it.NetTraversalTime     = Convert.ToByte(tmp[0]);
                 it.RoutingTableEntryTtl = Convert.ToUInt16(tmp[1]);
                 it.Kr                     = Convert.ToByte(tmp[2]);
                 it.Km                     = Convert.ToByte(tmp[3]);
                 it.Kc                     = Convert.ToByte(tmp[4]);
                 it.Kq                     = Convert.ToByte(tmp[5]);
                 it.Kh                     = Convert.ToByte(tmp[6]);
                 it.Krt                    = Convert.ToByte(tmp[7]);
                 it.RreqRetries            = Convert.ToByte(tmp[8]);
                 it.RreqRerrWait           = Convert.ToByte(tmp[9]);
                 it.BlacklistTableEntryTtl = Convert.ToUInt16(tmp[10]);
                 it.UnicastRreqGenEnable   = Convert.ToBoolean(tmp[11]);
                 it.RlcEnabled             = Convert.ToBoolean(tmp[12]);
                 it.AddRevLinkCost         = Convert.ToByte(tmp[13]);
                 RoutingConfiguration.Add(it);
             }
         }
     }
     else if (e.Index == 7)
     {
         BroadcastLogTableEntryTtl = Convert.ToUInt16(e.Value);
     }
     else if (e.Index == 8)
     {
         RoutingTable.Clear();
         if (e.Value != null)
         {
             foreach (object v in (object[])e.Value)
             {
                 object[]           tmp = (object[])v;
                 GXDLMSRoutingTable it  = new GXDLMSRoutingTable();
                 it.DestinationAddress = Convert.ToUInt16(tmp[10]);
                 it.NextHopAddress     = Convert.ToUInt16(tmp[10]);
                 it.RouteCost          = Convert.ToUInt16(tmp[10]);
                 it.HopCount           = Convert.ToByte(tmp[10]);
                 it.WeakLinkCount      = Convert.ToByte(tmp[10]);
                 it.ValidTime          = Convert.ToUInt16(tmp[10]);
                 RoutingTable.Add(it);
             }
         }
     }
     else if (e.Index == 9)
     {
         ContextInformationTable.Clear();
         if (e.Value != null)
         {
             foreach (object v in (object[])e.Value)
             {
                 object[] tmp = (object[])v;
                 GXDLMSContextInformationTable it = new GXDLMSContextInformationTable();
                 it.CID           = (string)tmp[0];
                 it.Context       = (byte[])tmp[2];
                 it.Compression   = Convert.ToBoolean(tmp[3]);
                 it.ValidLifetime = Convert.ToUInt16(tmp[4]);
                 ContextInformationTable.Add(it);
             }
         }
     }
     else if (e.Index == 10)
     {
         List <GXKeyValuePair <UInt16, UInt16> > list = new List <GXKeyValuePair <UInt16, UInt16> >();
         if (e.Value != null)
         {
             foreach (object v in (object[])e.Value)
             {
                 object[] tmp = (object[])v;
                 list.Add(new GXKeyValuePair <UInt16, UInt16>(Convert.ToUInt16(tmp[0]), Convert.ToUInt16(tmp[1])));
             }
         }
         BlacklistTable = list;
     }
     else if (e.Index == 11)
     {
         BroadcastLogTable.Clear();
         if (e.Value != null)
         {
             foreach (object v in (object[])e.Value)
             {
                 object[] tmp = (object[])v;
                 GXDLMSBroadcastLogTable it = new GXDLMSBroadcastLogTable();
                 it.SourceAddress  = Convert.ToUInt16(tmp[0]);
                 it.SequenceNumber = Convert.ToByte(tmp[1]);
                 it.ValidTime      = Convert.ToUInt16(tmp[2]);
                 BroadcastLogTable.Add(it);
             }
         }
     }
     else if (e.Index == 12)
     {
         List <UInt16> list = new List <UInt16>();
         if (e.Value != null)
         {
             foreach (object it in (object[])e.Value)
             {
                 list.Add(Convert.ToUInt16(it));
             }
         }
         GroupTable = list.ToArray();
     }
     else if (e.Index == 13)
     {
         MaxJoinWaitTime = Convert.ToUInt16(e.Value);
     }
     else if (e.Index == 14)
     {
         PathDiscoveryTime = Convert.ToByte(e.Value);
     }
     else if (e.Index == 15)
     {
         ActiveKeyIndex = Convert.ToByte(e.Value);
     }
     else if (e.Index == 16)
     {
         MetricType = Convert.ToByte(e.Value);
     }
     else if (e.Index == 17)
     {
         CoordShortAddress = Convert.ToUInt16(e.Value);
     }
     else if (e.Index == 18)
     {
         DisableDefaultRouting = (bool)e.Value;
     }
     else if (e.Index == 19)
     {
         DeviceType = (DeviceType)Convert.ToInt32(e.Value);
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }