Esempio n. 1
0
        public void RecieveMessage(Message message)
        {
            message.incoming = true;

            if (storeMessages)
                messagesLog.AddNewMessage(message);

            DebugTxRx($"RX: { message.ToString()}");

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


            if (message.isValid)
            {
                //Gateway ready
                if (message.messageType == MessageType.C_INTERNAL
                    && message.subType == (int)InternalDataType.I_GATEWAY_READY)
                    return;


                //Gateway log message
                if (message.messageType == MessageType.C_INTERNAL
                    && message.subType == (int)InternalDataType.I_LOG_MESSAGE)
                    return;

                //New ID request
                if (message.nodeId == 255)
                {
                    if (message.messageType == MessageType.C_INTERNAL
                        && message.subType == (int)InternalDataType.I_ID_REQUEST)
                        if (enableAutoAssignId)
                            SendNewIdResponse();

                    return;
                }

                //Metric system request
                if (message.messageType == MessageType.C_INTERNAL
                    && message.subType == (int)InternalDataType.I_CONFIG)
                    SendMetricResponse(message.nodeId);

                //Sensor request
                if (message.messageType == MessageType.C_REQ)
                    ProceedRequestMessage(message);


                UpdateNodeFromMessage(message);
                UpdateSensorFromMessage(message);
            }
        }
        private static void OnMessageSendEvent(Message message)
        {
            hub.Clients.All.OnMessageSendEvent(message.ToString());

        }
Esempio n. 3
0
        private void SendMessage(Message message)
        {
            message.incoming = false;

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

            UpdateSensorFromMessage(message);

            //todo if (message.messageType == MessageType.C_SET)
                //message = DeRemapMessage(message);

            DebugTxRx($"TX: {message.ToString()}");

            string ack = (message.ack) ? "1" : "0";
            string mes = $"{message.nodeId};{message.sensorId};{(int)message.messageType};{ack};{message.subType};{message.payload}\n";


            SendToSerial(mes);

            if (storeMessages)
                messagesLog.AddNewMessage(message);
        }