コード例 #1
0
ファイル: TVOneCorio.cs プロジェクト: xielong87/Essentials
        /// <summary>
        /// Initiates the subscription process to the DSP
        /// </summary>



        /// <summary>
        /// Handles a response message from the DSP
        /// </summary>
        /// <param name="dev"></param>
        /// <param name="args"></param>
        void Port_LineReceived(object dev, GenericCommMethodReceiveTextArgs args)
        {
            Debug.Console(2, this, "TVOneCurio RX: '{0}'", args.Text);
            try
            {
                if (args.Text.IndexOf("login") > -1)
                {
                    SendLine(string.Format("Login({0},{1})", this.userName, this.password));
                }
                else if (args.Text.IndexOf("!Done Preset.Take =") > -1)
                {
                    string presetNumberParse = args.Text.Remove(0, args.Text.IndexOf("=") + 2);

                    Debug.Console(1, this, "Preset Parse: {0}", presetNumberParse);
                    CurrentPreset = ushort.Parse(presetNumberParse);
                    PresetFeedback.FireUpdate();
                }
            }
            catch (Exception e)
            {
                if (Debug.Level == 2)
                {
                    Debug.Console(2, this, "Error parsing response: '{0}'\n{1}", args.Text, e);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Recieve response message from DSP and queue for processing
        /// </summary>
        /// <param name="dev"></param>
        /// <param name="args"></param>
        private void lineReceived(object dev, GenericCommMethodReceiveTextArgs args)
        {
            Debug.Console(1, this, "RX: '{0}'", args.Text);

            try
            {
                if (String.IsNullOrEmpty(args.Text) || (args.Text == @"> ") || (args.Text == @"OK> "))
                {
                    //skip empty messages
                }
                else if (args.Text.IndexOf("ERROR", StringComparison.Ordinal) > -1)
                {
                    // Error response
                    Debug.Console(0, this, "Error From DSP: '{0}'", args.Text);
                }
                else
                {
                    _responseQueue.Enqueue(args.Text);
                }
            }
            catch (Exception e)
            {
                if (Debug.Level == 2)
                {
                    Debug.Console(2, this, "Error parsing response: '{0}'\n{1}", args.Text, e);
                }
            }
        }
コード例 #3
0
 void Port_LineReceived(object dev, GenericCommMethodReceiveTextArgs args)
 {
     if (Debug.Level == 2)
     {
         Debug.Console(2, this, "RX: '{0}'",
                       ShowHexResponse ? ComTextHelper.GetEscapedText(args.Text) : args.Text);
     }
 }
コード例 #4
0
 void Communication_TextReceived(object sender, GenericCommMethodReceiveTextArgs args)
 {
     try {
         foreach (var Output in Outputs)
         {
             Output.Api.Eisc.StringInput[Output.Join].StringValue = args.Text;
         }
     }
     catch (Exception) {
         throw new FormatException(string.Format("ERROR:{0}"));
     }
 }
コード例 #5
0
        void Port_LineReceived(object dev, GenericCommMethodReceiveTextArgs args)
        {
            if (Debug.Level == 2)
            {
                Debug.Console(2, this, "Received: '{0}'", ComTextHelper.GetEscapedText(args.Text));
            }

            if (args.Text == "DO SOMETHING HERE EVENTUALLY")
            {
                _IsMuted = true;
                MuteFeedback.FireUpdate();
            }
        }
コード例 #6
0
ファイル: etc.cs プロジェクト: michaelh1142/pdt-etc-epi
 void Port_LineReceived(object dev, GenericCommMethodReceiveTextArgs args)
 {
     try
     {
         Debug.Console(2, this, "Line Received :::: {0}", args.Text);
         DeviceRx = args.Text;
         CommandPassThruFeedback.FireUpdate();
         ParseRx(DeviceRx);
     }
     catch (Exception e)
     {
         CrestronConsole.PrintLine("{0}: Execption Thrown on Line Received {1},{2}", this, e, e.StackTrace);
     }
 }
コード例 #7
0
ファイル: LutronQuantum.cs プロジェクト: srmeteor/Essentials
        /// <summary>
        /// Handles all responses that contain the delimiter
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        void PortGather_LineReceived(object sender, GenericCommMethodReceiveTextArgs args)
        {
            Debug.Console(2, this, "Line Received: '{0}'", args.Text);

            try
            {
                if (args.Text.Contains("~AREA"))
                {
                    var response = args.Text.Split(',');

                    var integrationId = response[1];

                    if (integrationId != IntegrationId)
                    {
                        Debug.Console(2, this, "Response is not for correct Integration ID");
                        return;
                    }
                    else
                    {
                        var action = Int32.Parse(response[2]);

                        switch (action)
                        {
                        case (int)eAction.Scene:
                        {
                            var scene = response[3];
                            CurrentLightingScene = LightingScenes.FirstOrDefault(s => s.ID.Equals(scene));

                            OnLightingSceneChange();

                            break;
                        }

                        default:
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Debug.Console(2, this, "Error parsing response:\n{0}", e);
            }
        }
コード例 #8
0
ファイル: LutronQuantum.cs プロジェクト: srmeteor/Essentials
        /// <summary>
        /// Checks for responses that do not contain the delimiter
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        void Communication_TextReceived(object sender, GenericCommMethodReceiveTextArgs args)
        {
            Debug.Console(2, this, "Text Received: '{0}'", args.Text);

            if (args.Text.Contains("login:"******"password:"******"Access Granted"))
            {
                if (SubscribeAfterLogin != null)
                {
                    SubscribeAfterLogin.Stop();
                }
                SubscribeToFeedback();
            }
        }
コード例 #9
0
        /// <summary>
        /// Handles a response message from the DSP
        /// </summary>
        /// <param name="dev"></param>
        /// <param name="args"></param>
        void Port_LineReceived(object dev, GenericCommMethodReceiveTextArgs args)
        {
            if (Debug.Level == 2)
            {
                Debug.Console(2, this, "RX: '{0}'",
                              ShowHexResponse ? ComTextHelper.GetEscapedText(args.Text) : args.Text);
            }

            Debug.Console(1, this, "RX: '{0}'", args.Text);

            try
            {
                if (args.Text.IndexOf("Welcome to the Tesira Text Protocol Server...") > -1)
                {
                    // Indicates a new TTP session

                    SubscribeToAttributes();
                }
                else if (args.Text.IndexOf("publishToken") > -1)
                {
                    // response is from a subscribed attribute

                    string pattern = "! \"publishToken\":[\"](.*)[\"] \"value\":(.*)";

                    Match match = Regex.Match(args.Text, pattern);

                    if (match.Success)
                    {
                        string key;

                        string customName;

                        string value;

                        customName = match.Groups[1].Value;

                        // Finds the key (everything before the '~' character
                        key = customName.Substring(0, customName.IndexOf("~", 0) - 1);

                        value = match.Groups[2].Value;

                        foreach (KeyValuePair <string, TesiraForteLevelControl> controlPoint in LevelControlPoints)
                        {
                            if (customName == controlPoint.Value.LevelCustomName || customName == controlPoint.Value.MuteCustomName)
                            {
                                controlPoint.Value.ParseSubscriptionMessage(customName, value);
                                return;
                            }
                        }
                    }

                    /// same for dialers
                    /// same for switchers
                }
                else if (args.Text.IndexOf("+OK") > -1)
                {
                    if (args.Text == "+OK" || args.Text.IndexOf("list\":") > -1)        // Check for a simple "+OK" only 'ack' repsonse or a list response and ignore
                    {
                        return;
                    }

                    // response is not from a subscribed attribute.  From a get/set/toggle/increment/decrement command

                    if (!CommandQueue.IsEmpty)
                    {
                        if (CommandQueue.Peek() is QueuedCommand)
                        {
                            // Expected response belongs to a child class
                            QueuedCommand tempCommand = (QueuedCommand)CommandQueue.TryToDequeue();
                            //Debug.Console(1, this, "Command Dequeued. CommandQueue Size: {0}", CommandQueue.Count);

                            tempCommand.ControlPoint.ParseGetMessage(tempCommand.AttributeCode, args.Text);
                        }
                        else
                        {
                            // Expected response belongs to this class
                            string temp = (string)CommandQueue.TryToDequeue();
                            //Debug.Console(1, this, "Command Dequeued. CommandQueue Size: {0}", CommandQueue.Count);
                        }

                        if (CommandQueue.IsEmpty)
                        {
                            CommandQueueInProgress = false;
                        }
                        else
                        {
                            SendNextQueuedCommand();
                        }
                    }
                }
                else if (args.Text.IndexOf("-ERR") > -1)
                {
                    // Error response

                    switch (args.Text)
                    {
                    case "-ERR ALREADY_SUBSCRIBED":
                    {
                        ResetSubscriptionTimer();
                        break;
                    }

                    default:
                    {
                        Debug.Console(0, this, "Error From DSP: '{0}'", args.Text);
                        break;
                    }
                    }
                }
            }
            catch (Exception e)
            {
                if (Debug.Level == 2)
                {
                    Debug.Console(2, this, "Error parsing response: '{0}'\n{1}", args.Text, e);
                }
            }
        }
コード例 #10
0
        private void Port_LineReceived(object dev, GenericCommMethodReceiveTextArgs args)
        {
            if (Debug.Level == 2)
            {
                Debug.Console(2, this, "RX: '{0}'",
                              ShowHexResponse ? ComTextHelper.GetEscapedText(args.Text) : args.Text);
            }

            //Debug.Console(1, this, "RX: '{0}'", args.Text);

            try
            {
                DeviceRx = args.Text;

                CommandPassthruFeedback.FireUpdate();

                if (args.Text.IndexOf("Welcome to the Tesira Text Protocol Server...", StringComparison.Ordinal) > -1)
                {
                    // Indicates a new TTP session
                    // moved to CustomActivate() method
                    CommunicationMonitor.Start();
                    CrestronInvoke.BeginInvoke((o) => HandleAttributeSubscriptions());
                }
                else if (args.Text.IndexOf("! ", StringComparison.Ordinal) > -1)
                {
                    // response is from a subscribed attribute

                    //(if(args.Text

                    const string pattern = "! [\\\"](.*?[^\\\\])[\\\"] (.*)";

                    var match = Regex.Match(args.Text, pattern);

                    if (!match.Success)
                    {
                        return;
                    }

                    var customName = match.Groups[1].Value;
                    var value      = match.Groups[2].Value;

                    AdvanceQueue(args.Text);

                    foreach (var controlPoint in Faders.Where(controlPoint => customName == controlPoint.Value.LevelCustomName || customName == controlPoint.Value.MuteCustomName))
                    {
                        controlPoint.Value.ParseSubscriptionMessage(customName, value);
                        return;
                    }
                    foreach (var controlPoint in Dialers.Where(controlPoint => customName == controlPoint.Value.AutoAnswerCustomName || customName == controlPoint.Value.ControlStatusCustomName || customName == controlPoint.Value.DialerCustomName))
                    {
                        controlPoint.Value.ParseSubscriptionMessage(customName, value);
                        return;
                    }
                    foreach (var controlPoint in States.Where(controlPoint => customName == controlPoint.Value.StateCustomName))
                    {
                        controlPoint.Value.ParseSubscriptionMessage(customName, value);
                        return;
                    }

                    foreach (var controlPoint in Switchers.Where(controlPoint => customName == controlPoint.Value.SelectorCustomName))
                    {
                        controlPoint.Value.ParseSubscriptionMessage(customName, value);
                        return;
                    }

                    foreach (var controlPoint in Meters.Where(controlPoint => customName == controlPoint.Value.MeterCustomName))
                    {
                        controlPoint.Value.ParseSubscriptionMessage(customName, value);
                        return;
                    }

                    // same for dialers
                    // same for switchers
                }
                else if (args.Text.IndexOf("+OK", StringComparison.Ordinal) > -1)
                {
                    if (args.Text == "+OK")       // Check for a simple "+OK" only 'ack' repsonse or a list response and ignore
                    {
                        return;
                    }
                    // response is not from a subscribed attribute.  From a get/set/toggle/increment/decrement command
                    //string pattern = "(?<=\" )(.*?)(?=\\+)";
                    //string data = Regex.Replace(args.Text, pattern, "");

                    AdvanceQueue(args.Text);
                }
                else if (args.Text.IndexOf("-ERR", StringComparison.Ordinal) > -1)
                {
                    // Error response
                    Debug.Console(2, this, "Error From DSP: '{0}'", args.Text);
                    switch (args.Text)
                    {
                    case "-ERR ALREADY_SUBSCRIBED":
                    {
                        WatchDogSniffer = false;
                        AdvanceQueue(args.Text);
                        break;
                    }


                    default:
                    {
                        WatchDogSniffer = false;

                        AdvanceQueue(args.Text);
                        break;
                    }
                    }
                }
            }
            catch (Exception e)
            {
                if (Debug.Level == 2)
                {
                    Debug.Console(2, this, "Error parsing response: '{0}'\n{1}", args.Text, e);
                }
            }
        }
コード例 #11
0
        /// <summary>
        /// This method will run when the PortGather is satisfied.  Parse responses here.
        /// </summary>
        /// <param name="dev"></param>
        /// <param name="args"></param>
        void Port_LineReceived(object dev, GenericCommMethodReceiveTextArgs args)
        {
            if (Debug.Level == 2)
            {
                Debug.Console(2, this, "Received: '{0}'", ComTextHelper.GetEscapedText(args.Text));
            }
            char[] trimChars = { '\x02', '\x03' };
            var    FB        = args.Text.Trim(trimChars);

            Debug.Console(2, this, "Received cmd: '{0}'", FB);
            switch (FB)
            {
            case "PON":
            {
                _PowerIsOn = true;
                PowerIsOnFeedback.FireUpdate();
                InputNumberFeedback.FireUpdate();
                break;
            }

            case "POF":
            {
                _PowerIsOn = false;
                PowerIsOnFeedback.FireUpdate();
                InputNumber = 102;
                InputNumberFeedback.FireUpdate();
                break;
            }

            case "QPW:1":
            {
                _PowerIsOn = true;
                PowerIsOnFeedback.FireUpdate();
                InputNumberFeedback.FireUpdate();
                break;
            }

            case "QPW:0":
            {
                _PowerIsOn = false;
                PowerIsOnFeedback.FireUpdate();
                InputNumber = 102;
                InputNumberFeedback.FireUpdate();
                break;
            }

            case "QMI:HM1":
            {
                if (_PowerIsOn)
                {
                    InputNumber = 1;
                    InputNumberFeedback.FireUpdate();
                }
                break;
            }

            case "QMI:HM2":
            {
                if (_PowerIsOn)
                {
                    InputNumber = 2;
                    InputNumberFeedback.FireUpdate();
                }
                break;
            }

            case "QMI:DV1":
            {
                if (_PowerIsOn)
                {
                    InputNumber = 3;
                    InputNumberFeedback.FireUpdate();
                }
                break;
            }

            case "QMI:PC1":
            {
                if (_PowerIsOn)
                {
                    InputNumber = 4;
                    InputNumberFeedback.FireUpdate();
                }
                break;
            }
            }
        }
コード例 #12
0
        ///// <summary>
        ///// /
        ///// </summary>
        ///// <param name="sender"></param>
        //void Communication_BytesReceived(object sender, GenericCommMethodReceiveBytesArgs e)
        //{
        //    // This is probably not thread-safe buffering
        //    // Append the incoming bytes with whatever is in the buffer
        //    var newBytes = new byte[IncomingBuffer.Length + e.Bytes.Length];
        //    IncomingBuffer.CopyTo(newBytes, 0);
        //    e.Bytes.CopyTo(newBytes, IncomingBuffer.Length);

        //    if (Debug.Level == 2) // This check is here to prevent following string format from building unnecessarily on level 0 or 1
        //        Debug.Console(2, this, "Received:{0}", ComTextHelper.GetEscapedText(newBytes));

        //    // Need to find AA FF and have
        //    for (int i = 0; i < newBytes.Length; i++)
        //    {
        //        if (newBytes[i] == 0xAA && newBytes[i + 1] == 0xFF)
        //        {
        //            newBytes = newBytes.Skip(i).ToArray(); // Trim off junk if there's "dirt" in the buffer

        //            // parse it
        //            // If it's at least got the header, then process it,
        //            while (newBytes.Length > 4 && newBytes[0] == 0xAA && newBytes[1] == 0xFF)
        //            {
        //                var msgLen = newBytes[3];
        //                // if the buffer is shorter than the header (3) + message (msgLen) + checksum (1),
        //                // give and save it for next time
        //                if (newBytes.Length < msgLen + 4)
        //                    break;

        //                // Good length, grab the message
        //                var message = newBytes.Skip(4).Take(msgLen).ToArray();

        //                // At this point, the ack/nak is the first byte
        //                if (message[0] == 0x41)
        //                {
        //                    switch (message[1]) // type byte
        //                    {
        //                        case 0x00: // General status
        //                            UpdatePowerFB(message[2], message[5]); // "power" can be misrepresented when the display sleeps
        //                            UpdateInputFb(message[5]);
        //                            UpdateVolumeFB(message[3]);
        //                            UpdateMuteFb(message[4]);
        //                            UpdateInputFb(message[5]);
        //                            break;

        //                        case 0x11:
        //                            UpdatePowerFB(message[2]);
        //                            break;

        //                        case 0x12:
        //                            UpdateVolumeFB(message[2]);
        //                            break;

        //                        case 0x13:
        //                            UpdateMuteFb(message[2]);
        //                            break;

        //                        case 0x14:
        //                            UpdateInputFb(message[2]);
        //                            break;

        //                        default:
        //                            break;
        //                    }
        //                }
        //                // Skip over what we've used and save the rest for next time
        //                newBytes = newBytes.Skip(5 + msgLen).ToArray();
        //            }

        //            break; // parsing will mean we can stop looking for header in loop
        //        }
        //    }

        //    // Save whatever partial message is here
        //    IncomingBuffer = newBytes;
        //}

        void PortGather_LineReceived(object sender, GenericCommMethodReceiveTextArgs e)
        {
            Debug.Console(1, this, "Receivied: '{0}'", ComTextHelper.GetEscapedText(e.Text));

            if (e.Text.IndexOf("\x50\x4F\x57") > -1)
            {
                // Power Status Response

                var value = e.Text.ToCharArray();

                switch (value[6])
                {
                case '\x00':
                {
                    _PowerIsOn = false;
                    break;
                }

                case '\x01':
                {
                    _PowerIsOn = true;
                    break;
                }
                }

                PowerIsOnFeedback.FireUpdate();
                Debug.Console(1, this, "PowerIsOn State: {0}", PowerIsOnFeedback.BoolValue);
            }
            else if (e.Text.IndexOf("\x4D\x49\x4E") > -1)
            {
                var value = e.Text.ToCharArray();

                var b = value[6];

                var newInput = InputPorts.FirstOrDefault(i => i.FeedbackMatchObject.Equals(b));
                if (newInput != null && newInput != _CurrentInputPort)
                {
                    _CurrentInputPort = newInput;
                    CurrentInputFeedback.FireUpdate();
                    Debug.Console(1, this, "Current Input: {0}", CurrentInputFeedback.StringValue);
                }
            }
            else if (e.Text.IndexOf("\x56\x4F\x4C") > -1)
            {
                // Volume Status Response

                var value = e.Text.ToCharArray();

                var b = value[6];

                var newVol = (ushort)NumericalHelpers.Scale((double)b, 0, 100, 0, 65535);
                if (!VolumeIsRamping)
                {
                    _LastVolumeSent = newVol;
                }
                if (newVol != _VolumeLevelForSig)
                {
                    _VolumeLevelForSig = newVol;
                    VolumeLevelFeedback.FireUpdate();

                    if (_VolumeLevelForSig > 0)
                    {
                        _IsMuted = false;
                    }
                    else
                    {
                        _IsMuted = true;
                    }

                    MuteFeedback.FireUpdate();

                    Debug.Console(1, this, "Volume Level: {0}", VolumeLevelFeedback.IntValue);
                }
            }
        }
コード例 #13
0
ファイル: QscDsp.cs プロジェクト: xielong87/Essentials
        /// <summary>
        /// Handles a response message from the DSP
        /// </summary>
        /// <param name="dev"></param>
        /// <param name="args"></param>
        void Port_LineReceived(object dev, GenericCommMethodReceiveTextArgs args)
        {
            Debug.Console(2, this, "RX: '{0}'", args.Text);
            try
            {
                if (args.Text.IndexOf("sr ") > -1)
                {
                }
                else if (args.Text.IndexOf("cv") > -1)
                {
                    var changeMessage = args.Text.Split(null);

                    string changedInstance = changeMessage[1].Replace("\"", "");
                    Debug.Console(1, this, "cv parse Instance: {0}", changedInstance);
                    bool foundItFlag = false;
                    foreach (KeyValuePair <string, QscDspLevelControl> controlPoint in LevelControlPoints)
                    {
                        if (changedInstance == controlPoint.Value.LevelInstanceTag)
                        {
                            controlPoint.Value.ParseSubscriptionMessage(changedInstance, changeMessage[4]);
                            foundItFlag = true;
                            return;
                        }
                        else if (changedInstance == controlPoint.Value.MuteInstanceTag)
                        {
                            controlPoint.Value.ParseSubscriptionMessage(changedInstance, changeMessage[2].Replace("\"", ""));
                            foundItFlag = true;
                            return;
                        }
                    }
                    if (!foundItFlag)
                    {
                        foreach (var dialer in Dialers)
                        {
                            PropertyInfo[] properties = dialer.Value.Tags.GetType().GetCType().GetProperties();
                            //GetPropertyValues(Tags);
                            foreach (var prop in properties)
                            {
                                var propValue = prop.GetValue(dialer.Value.Tags, null) as string;
                                if (changedInstance == propValue)
                                {
                                    dialer.Value.ParseSubscriptionMessage(changedInstance, changeMessage[2].Replace("\"", ""));
                                    foundItFlag = true;
                                    return;
                                }
                            }
                            if (foundItFlag)
                            {
                                return;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (Debug.Level == 2)
                {
                    Debug.Console(2, this, "Error parsing response: '{0}'\n{1}", args.Text, e);
                }
            }
        }
 // TODO [ ] If not using an ASCII based API with no delimeter, delete the method below
 void Handle_TextReceived(object sender, GenericCommMethodReceiveTextArgs e)
 {
     // TODO [ ] Implement method
     throw new System.NotImplementedException();
 }
 // TODO [ ] If not using an API with a delimeter, delete the method below
 private void Handle_LineRecieved(object sender, GenericCommMethodReceiveTextArgs args)
 {
     // TODO [ ] Implement method
     throw new System.NotImplementedException();
 }
コード例 #16
0
ファイル: ElkPanel.cs プロジェクト: ryanww/Crestron-Elk
 private void TcpClientOnTextReceived(object sender, GenericCommMethodReceiveTextArgs genericCommMethodReceiveTextArgs)
 {
     ParseResponse(genericCommMethodReceiveTextArgs.Text);
 }