private void AddMessageEvent(Message message)
        {
            UpdateCombos();

            if (filterNodeId != null
                && filterNodeId != message.nodeId)
                return;

            if (filterSensorId != null
                && filterSensorId != message.sensorId)
                return;

            if (filterMesType != null
                && filterMesType != message.messageType)
                return;

            AddMessage(message);

            scrollViewer1.UpdateLayout();
            scrollViewer1.ChangeView(0.0f, double.MaxValue, 1.0f);

            if (listView1.Items.Count > App.serialController.messagesLog.maxMessaages + 100)
            {
                foreach (var item in listView1.Items.Take(100))
                    listView1.Items.Remove(item);
            }
        }
Ejemplo n.º 2
0
        public void AddNewMessage(Message message)
        {
            if (messages.Count >= maxMessaages)
                messages.Remove(messages.First());

            messages.Add(message);

            if (OnNewMessageLogged != null)
                OnNewMessageLogged(message);
        }
Ejemplo n.º 3
0
        public void SendMessage(Message message)
        {
            message.incoming = false;

            if (OnMessageSendEvent != null)
                OnMessageSendEvent(message);

            string mes = String.Format("{0};{1};{2};{3};{4};{5}\n",
                message.nodeId,
                message.sensorId,
                (int)message.messageType,
                (message.ack) ? "1" : "0",
                message.subType,
                message.payload);

            SendMessage(mes);

            if (enableLogging)
                messagesLog.AddNewMessage(message);
        }
Ejemplo n.º 4
0
 public void OnNewMessage(Message message)
 {
     Stopwatch sw = new Stopwatch();
     sw.Start();
     conn.Insert(message);
     sw.Stop();
     Debug.WriteLine("Writing to DB: " + sw.ElapsedMilliseconds + " ms");
 }
Ejemplo n.º 5
0
 public void SendReboot(int nodeId)
 {
     Message message = new Message();
     message.ack = false;
     message.messageType = MessageType.C_INTERNAL;
     message.nodeId = nodeId;
     message.payload = "0";
     message.sensorId = 0;
     message.subType = (int)InternalDataType.I_REBOOT;
     message.isValid = true;
     SendMessage(message);
 }
Ejemplo n.º 6
0
 private void SendMetricResponse(int nodeId)
 {
     Message mess = new Message();
     mess.nodeId = nodeId;
     mess.sensorId = 255;
     mess.messageType = MessageType.C_INTERNAL;
     mess.ack = false;
     mess.subType = (int)InternalDataType.I_CONFIG;
     mess.payload = "M";
     mess.isValid = true;
     SendMessage(mess);
 }
Ejemplo n.º 7
0
        public void SendNewIdResponse()
        {
            int freeId = GetFreeNodeId();

            Message mess = new Message();
            mess.nodeId = 255;
            mess.sensorId = 255;
            mess.messageType = MessageType.C_INTERNAL;
            mess.ack = false;
            mess.subType = (int)InternalDataType.I_ID_RESPONSE;
            mess.payload = freeId.ToString();
            mess.isValid = true;
            SendMessage(mess);
        }
Ejemplo n.º 8
0
        public void SendSensorState(int nodeId, int sensorId, SensorData data)
        {
            Sensor sensor = GetNode(nodeId).GetSensor(sensorId);
            sensor.AddOrUpdateData(data);

            Message message = new Message();
            message.ack = false;
            message.messageType = MessageType.C_SET;
            message.nodeId = nodeId;
            message.payload = data.state;
            message.sensorId = sensorId;
            message.subType = (int)data.dataType;
            message.isValid = true;
            SendMessage(message);

            if (OnSensorUpdatedEvent != null)
                OnSensorUpdatedEvent(sensor);
        }
Ejemplo n.º 9
0
        public Message ParseMessageFromString(string message)
        {
            var mes = new Message();

            try
            {
                string[] arguments = message.Split(new char[] { ';' }, 6);
                mes.nodeId = Int32.Parse(arguments[0]);
                mes.sensorId = Int32.Parse(arguments[1]);
                mes.messageType = (MessageType)Int32.Parse(arguments[2]);
                mes.ack = arguments[3] == "1";
                mes.subType = Int32.Parse(arguments[4]);
                mes.payload = arguments[5];
                mes.isValid = true;
            }
            catch
            {
                mes = new Message();
                mes.isValid = false;
                mes.payload = message;
            }
            return mes;
        }
Ejemplo n.º 10
0
        public void UpdateSensorFromMessage(Message mes)
        {
            //if internal node message
            if (mes.sensorId == 255)
                return;

            if (mes.messageType != MessageType.C_PRESENTATION
             && mes.messageType != MessageType.C_SET)
                return;

            Node node = GetNode(mes.nodeId);

            Sensor sensor = node.GetSensor(mes.sensorId);
            bool isNewSensor = false;

            if (sensor == null)
            {
                sensor = node.AddSensor(mes.sensorId);
                isNewSensor = true;
            }

            if (mes.messageType == MessageType.C_SET)
            {
                SensorDataType dataType = (SensorDataType)mes.subType;
                sensor.AddOrUpdateData(dataType, mes.payload);
            }
            else if (mes.messageType == MessageType.C_PRESENTATION)
            {
                sensor.SetSensorType((SensorType)mes.subType);

                if (!String.IsNullOrEmpty(mes.payload))
                    sensor.description = mes.payload;
            }



            if (isNewSensor && OnNewSensorEvent != null)
                OnNewSensorEvent(sensor);
            else
            if (OnSensorUpdatedEvent != null)
                OnSensorUpdatedEvent(sensor);


        }
Ejemplo n.º 11
0
        private void UpdateNodeFromMessage(Message mes)
        {
            Node node = GetNode(mes.nodeId);

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

                if (OnNewNodeEvent != null)
                    OnNewNodeEvent(node);
            }

            node.UpdateLastSeenNow();
            if (OnNodeLastSeenUpdatedEvent != null)
                OnNodeLastSeenUpdatedEvent(node);


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


                    if (OnNodeUpdatedEvent != null)
                        OnNodeUpdatedEvent(node);
                }
                else if (mes.messageType == MessageType.C_INTERNAL)
                {
                    if (mes.subType == (int)InternalDataType.I_SKETCH_NAME)
                    {
                        node.name = mes.payload;

                        if (OnNodeUpdatedEvent != null)
                            OnNodeUpdatedEvent(node);
                    }
                    else if (mes.subType == (int)InternalDataType.I_SKETCH_VERSION)
                    {
                        node.version = mes.payload;

                        if (OnNodeUpdatedEvent != null)
                            OnNodeUpdatedEvent(node);
                    }
                    else if (mes.subType == (int)InternalDataType.I_BATTERY_LEVEL)
                    {
                        node.batteryLevel = Int32.Parse(mes.payload);
                        if (OnNodeBatteryUpdatedEvent != null)
                            OnNodeBatteryUpdatedEvent(node);
                        return;
                    }
                }
            }

        }
Ejemplo n.º 12
0
        private void ProceedRequestMessage(Message mes)
        {
            if (mes.messageType != MessageType.C_REQ)
                return;

            Node node = GetNode(mes.nodeId);
            if (node == null) return;

            Sensor sensor = node.GetSensor(mes.sensorId);
            if (sensor == null) return;

            SensorDataType dataType = (SensorDataType)mes.subType;
            SensorData data = sensor.GetData(dataType);
            if (data == null) return;

            SendSensorState(mes.nodeId, mes.sensorId, data);
        }
Ejemplo n.º 13
0
 private void AddMessage(Message message)
 {
     listView1.Items.Add(message.ToString());
 }