예제 #1
0
        public Node(ushort nodeId, Posistion posistion, Features features, Dictionary <ModelType, Model> primaryElementExtensionModels = null)
        {
            Id        = nodeId;
            Address   = new Address(AddressType.Unicast, nodeId);
            Posistion = posistion;
            Listener  = new Listener(nodeId);

            Elements = new Dictionary <ElementType, Element>()
            {
                { ElementType.primary, new Element()
                  {
                      Address = this.Address
                  } }
            };

            var serverModel = new ConfigurationServerModel(features)
            {
                ElementId = Elements[ElementType.primary].Address.Value
            };

            Elements[ElementType.primary].AddModel(ModelType.ConfigurationServer, serverModel);

            if (primaryElementExtensionModels != null)
            {
                foreach (var item in primaryElementExtensionModels)
                {
                    Elements[ElementType.primary].AddModel(item.Key, item.Value);
                }
            }
            StatusFlag = 0;
        }
예제 #2
0
        public BluetoothMeshContext()
        {
            GroupAddressesProvider.SeedList();

            Nodes = new List <Node>()
            {
                new Node(1, new Posistion(1, 1), new Features()
                {
                    Relay = false, Proxy = true, Friend = true
                }, GetClient()),
                new Node(2, new Posistion(27, 10), new Features()
                {
                    Relay = false, Proxy = false, Friend = true
                }, GetLightBulb()),
                new Node(3, new Posistion(8, 6), new Features()
                {
                    Relay = true, Proxy = false, Friend = true
                }),
                new Node(4, new Posistion(3, 13), new Features()
                {
                    Relay = false, Proxy = false, Friend = true
                }),
                new Node(5, new Posistion(21, 27), new Features()
                {
                    Relay = false, Proxy = false, Friend = true
                }, GetLightBulb()),
                new Node(6, new Posistion(15, 13), new Features()
                {
                    Relay = true, Proxy = false, Friend = true
                }),
                new Node(7, new Posistion(9, 21), new Features()
                {
                    Relay = false, Proxy = false, Friend = true
                }, GetLightBulb()),
                new Node(8, new Posistion(25, 16), new Features()
                {
                    Relay = true, Proxy = false, Friend = true
                }),
                new Node(9, new Posistion(33, 19), new Features()
                {
                    Relay = false, Proxy = false, Friend = true
                }),
            };

            NodeServers = new List <NodeBearer>();
            foreach (var node in Nodes)
            {
                var nodeServer = new NodeBearer(node);
                NodeServers.Add(nodeServer);
            }

            Nodes[0].Elements[ElementType.primary].Models[ModelType.ConfigurationServer].Procedures.Clear();
            #region default subscriptions

            Elements.Where(x => x.Models.ContainsKey(ModelType.Light)).ToList().ForEach(x =>
                                                                                        x.Subscriptions.Add(GroupAddressesProvider.Dictionary[GroupAddresses.AllLights]));

            foreach (var element in Elements.Where(x => x.Models.ContainsKey(ModelType.ConfigurationServer)))
            {
                ConfigurationServerModel configurationServer = (ConfigurationServerModel)element.Models[ModelType.ConfigurationServer];
                if (configurationServer != null)
                {
                    if (configurationServer.CompositionData.IsFriend)
                    {
                        element.Subscriptions.Add(GroupAddressesProvider.Dictionary[GroupAddresses.AllFriends]);
                    }
                    if (configurationServer.CompositionData.IsRelay)
                    {
                        element.Subscriptions.Add(GroupAddressesProvider.Dictionary[GroupAddresses.AllRelays]);
                    }
                    if (configurationServer.CompositionData.IsProxy)
                    {
                        element.Subscriptions.Add(GroupAddressesProvider.Dictionary[GroupAddresses.AllProxies]);
                    }
                    element.Subscriptions.Add(GroupAddressesProvider.Dictionary[GroupAddresses.AllNodes]);
                }
            }
            #endregion
        }