public virtual bool Send(XPacket packet)
 {
     return base.Send(packet.ToBytes());
 }
        private void _msg_routing_GiveFactoryNum(XPacket packet, XRoutingManager manager)
        {
            if (packet.SourceAddr == 0 && packet.DestinationType == 1)
            {
                var fr = packet.ToFactoryRecord();
                XDevice device = KnownDevices.FirstOrDefault<XDevice>(xd => xd.FactoryRec == fr);
                if (device == null)
                {
                    device = new XDevice() { FactoryRec = fr };
                    byte addr = 01;
                    while (KnownDevices.FirstOrDefault<XDevice>(xd => xd.Addr == addr) != null)
                    {
                        addr++;
                        if (addr >= 255) throw new Exception("All addressed closed!");
                    }
                    device.Addr = addr;
                    KnownDevices.Add(device);
                }
                LastDeviceAddr = device.Addr;
                
                /*
                #dstAddr  00
                #dstType  02
                #srcAddr  254
                #srcType  A6
                FactoryNum
                */

                Send(new XPacket() { 
                    Data = packet.Data, 
                    SourceAddr = DeviceAddr, 
                    SourceType = device.Addr, 
                    DestinationType = 2 }
                );
                State = EDeviceState.Working;
            }
            if (packet.DestinationAddr == DeviceAddr && packet.DestinationType == 4)
            {
                XDevice device = KnownDevices.FirstOrDefault<XDevice>(xd => xd.Addr == packet.SourceAddr);
                if (device == null)
                {
                    device = new XDevice() { Addr = packet.SourceAddr, FactoryRec = packet.ToFactoryRecord() };
                    KnownDevices.Add(device);
                }
                if (packet.SourceAddr == 0)
                {
                    if (device.Addr == 0)
                    {
                        byte addr = 01;
                        while (KnownDevices.FirstOrDefault<XDevice>(xd => xd.Addr == addr) != null)
                        {
                            addr++;
                            if (addr >= 255) throw new Exception("All addressed closed!");
                        }
                        device.Addr = addr;
                    }

                    /*
                      #dstAddr  3F
                      #dstType  04
                      #srcAddr  23
                      #srcType  00
                      FactoryNum
                    */

                    Send(new XPacket()
                    {
                        Data = packet.Data,
                        SourceAddr = DeviceAddr,
                        SourceType = device.Addr,
                        DestinationType = 2
                    });
                }
                else
                {
                    if (packet.SourceAddr == DeviceAddr) DeviceAddr--;//ЕСЛИ В СЕТИ УЖЕ ЕСТЬ УСТРОЙСТВО С ТАКИМ АДРЕСОМ
                }
                LastDeviceAddr = device.Addr;
                State = EDeviceState.Working;
            }
            if (packet.DestinationType == 5)
            {
                Send(new XPacket()
                {
                    Data = FactoryRec,
                    SourceAddr = DeviceAddr,
                    SourceType = 05,
                    DestinationAddr = packet.DestinationAddr,
                    DestinationType = 4
                });
            }
        }
 protected virtual bool processXPacket(XPacket packet)
 {
     if (RoutingTable[packet.DestinationType] != null)
     {
         RoutingTable[packet.DestinationType](packet, this);
     }
     if (OnReceiveXPacket != null)
     {
         OnReceiveXPacket(packet, this);
     }
     return true;
 }