示例#1
0
        public override void Write(byte[] data)
        {
            if (this.IsConnected())
            {
                // Instead of sending the data directly to the device, encapsulate the data 
                // and put it into the queue
                switch (data.Length)
                {
                    case 2:
                        {
                            var message = new KdmWriteMessage { OperationCode = data[0], Data = data[1] };
                            this.Log.Debug("A write message is added to the message queue");
                            this.EnqueueMessage(message);
                        }
                        break;
                    case 1:
                        {
                            var operationCode = data[0];
                            IKdmMessage message;

                            if (Constants.OperationCodes.IsRestartCommand(operationCode))
                            {
                                message = new KdmRestartMessage { OperationCode = operationCode };
                                this.Log.Debug("A restart message is added to message queue");
                            }
                            else
                            {
                                message = new KdmReadMessage { OperationCode = operationCode };
                                this.Log.Debug("A read message is added to the message queue");
                            }

                            this.EnqueueMessage(message);
                        }
                        break;
                    default:
                        this.Log.Error("Unknown message format");
                        break;
                }
            }
            else
            {
                this.Log.Error("Cannot send command because there is no connection available with the device");
            }
        }
示例#2
0
 /// <summary>
 /// This method is called if the operation code is sent to device and it's echo is received and the message is a read message
 /// </summary>
 /// <param name="message"></param>
 private void CheckForReadMessageStates(KdmReadMessage message)
 {
     if (message.OperationCode == Constants.OperationCodes.WriteCommands.OverrideLuminanceTemperatureLimit.Code ||
         message.OperationCode == Constants.OperationCodes.WriteCommands.CancelLuminanceTemperatureOverride.Code ||
         message.OperationCode == Constants.OperationCodes.WriteCommands.NoOperation.Code)
     {
         // If the operation code is one of the values in the if statement, then it means
         // the message is actually a write message but having no data byte. 
         // (It is interpretted as a read message since it does not have a data byte)
         this.Log.Debug($"Write message successfully processed. Retry count {this.OnProcessMessage.RetryCount}");
         message.IsMessageProcessingCompleted = true;
     }
     else if (message.IsResponseReceived)
     {
         // The best case scenario, everything worked fine
         this.Log.Debug($"Read message successfully processed and response received. Retry count {this.OnProcessMessage.RetryCount}");
         message.IsMessageProcessingCompleted = true;
         base.HandleMessageReceived(new[] { message.OperationCode, message.Response }); // Notify device proxy with the received response
     }
     else if (message.OperationCodeEchoReceiveTime.AddMilliseconds(this.waitResponseTimeout) < DateTime.Now)
     {
         // Wait for response timeout occurred.
         this.Log.Error("Timeout occurred while waiting for the read command data response");
         this.RetryOnProcessMessage();
     }
     else
     {
         // this.Log.Debug("Waiting for data response");
     }
 }
示例#3
0
        private void AddReadMessage(string settingName, List<KdmReadMessage> messageList)
        {
            var readIsEnabled = ApplicationSettings.GetBoolean(settingName);
            if (!readIsEnabled) return;

            var operationCode = Constants.OperationCodes.CommandOperationCodeDictionary[settingName];
            var readMessage = new KdmReadMessage {OperationCode = operationCode.Code};
            messageList.Add(readMessage);
        }