Пример #1
0
        public bool AddNode(Node node, bool writeInDb = true)
        {
            if (node.PanelId != MAIN_PANEL_ID && GetPanelNode(node.PanelId) == null)
            {
                LogEngineError($"Can`t create node [{node.GetType().Name}]. Panel [{node.PanelId}] does not exist.");
                return(false);
            }

            bool checkNodeCanBeAdded = node.OnAddToEngine(this);

            if (!checkNodeCanBeAdded)
            {
                LogEngineError($"Can`t create node [{node.GetType().Name}]. Aborted by node.");
                return(false);
            }

            lock (nodesLock)
                nodes.Add(node);

            if (writeInDb)
            {
                nodesDb?.AddNode(node);
            }

            LogEngineInfo($"New node [{node.GetType().Name}]");

            OnNewNode?.Invoke(node);

            return(true);
        }
Пример #2
0
        private void UpdateNodeFromMessage(Message mes)
        {
            Node node = GetNode(mes.nodeId);

            if (node == null)
            {
                node = new Node(mes.nodeId);

                nodes.Add(node);
                db?.AddNode(node);

                OnNewNode?.Invoke(node);
                LogInfo($"Node[{node.Id}] registered.");
            }

            node.UpdateLastSeenNow();

            if (mes.sensorId == 255)
            {
                if (mes.messageType == MessageType.C_PRESENTATION)
                {
                    if (mes.subType == (int)SensorType.S_ARDUINO_NODE)
                    {
                        node.isRepeatingNode = false;

                        OnNodeUpdated?.Invoke(node);
                    }
                    else if (mes.subType == (int)SensorType.S_ARDUINO_REPEATER_NODE)
                    {
                        node.isRepeatingNode = true;

                        OnNodeUpdated?.Invoke(node);
                    }
                }
                else if (mes.messageType == MessageType.C_INTERNAL)
                {
                    if (mes.subType == (int)InternalDataType.I_SKETCH_NAME)
                    {
                        node.name = mes.payload;
                        LogInfo($"Node[{node.Id}] name: [{node.name}]");

                        OnNodeUpdated?.Invoke(node);
                    }
                    else if (mes.subType == (int)InternalDataType.I_SKETCH_VERSION)
                    {
                        node.version = mes.payload;
                        LogInfo($"Node[{node.Id}] version: [{node.version}]");

                        OnNodeUpdated?.Invoke(node);
                    }
                    else if (mes.subType == (int)InternalDataType.I_BATTERY_LEVEL)
                    {
                        node.batteryLevel = Int32.Parse(mes.payload);
                        LogInfo($"Node[{node.Id}] battery level: [{node.batteryLevel}]");

                        OnNodeBatteryUpdated?.Invoke(node);
                    }
                }
            }

            OnNodeLastSeenUpdated?.Invoke(node);
            db?.UpdateNode(node);
        }
Пример #3
0
 protected virtual void NewNode(OWLOSNodeWrapperEventArgs e)
 {
     OnNewNode?.Invoke(this, e);
 }