Example #1
0
 public void SendSetMessage(byte destNodeId, byte sensorId, string payload)
 {
     try
     {
         var strMessage = BaseMessage.BuildMessageString(destNodeId, sensorId, MessageType.SET, 1,
                                                         (byte)SensorDataType.V_LIGHT, payload);
         if (!string.IsNullOrEmpty(strMessage))
         {
             GatewayWrapper.CallParseAndSend(_unmanagedGateway, strMessage);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("Error sending message to {0} Type {1} SubType {2}", destNodeId, MessageType.SET, SensorDataType.V_LIGHT);
     }
 }
Example #2
0
        private void OnReceiveMessage(string messageFromGateway)
        {
            Task.Factory.StartNew(() =>
            {
                var parsedMessage = MessageFactory.ConstructMessageFromRaw(messageFromGateway);

                Console.WriteLine("Receive Message from {0} Type {1} SubType {2}", parsedMessage.NodeId == 0 ? "Gateway" : parsedMessage.NodeId.ToString(), parsedMessage.GetType().Name, parsedMessage.SubType);
                var messageProcessor = MessageProcessorFactory.CreateMessageProcessor(parsedMessage);
                if (messageProcessor != null)
                {
                    string responseMessageString = null;
                    var raiseEvent = messageProcessor.ProcessIncomingMessage(parsedMessage, out responseMessageString);
                    if (!string.IsNullOrEmpty(responseMessageString))
                    {
                        GatewayWrapper.CallParseAndSend(_unmanagedGateway, responseMessageString);
                    }
                    if (raiseEvent && OnReceiveMessageFromSensors != null)
                    {
                        OnReceiveMessageFromSensors(parsedMessage);
                    }
                }
            });
        }