コード例 #1
0
        /// <summary>
        /// Parses subscription-related responses
        /// </summary>
        /// <param name="customName">Subscription identifier</param>
        /// <param name="value">response data to be parsed</param>
        public void ParseSubscriptionMessage(string customName, string value)
        {
            // Check for valid subscription response

            if (customName == StateCustomName)
            {
                _state = bool.Parse(value);
                StateFeedback.FireUpdate();
                IsSubscribed = true;
            }
        }
コード例 #2
0
        public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
        {
            var joinMap = new TesiraStateJoinMapAdvancedStandalone(joinStart);

            var joinMapSerialized = JoinMapHelper.GetSerializedJoinMapForDevice(joinMapKey);

            if (!string.IsNullOrEmpty(joinMapSerialized))
            {
                joinMap = JsonConvert.DeserializeObject <TesiraStateJoinMapAdvancedStandalone>(joinMapSerialized);
            }

            if (bridge != null)
            {
                bridge.AddJoinMap(Key, joinMap);
            }

            if (!Enabled)
            {
                return;
            }

            Debug.Console(2, this, "Tesira State {0} is Enabled", Key);

            StateFeedback.LinkInputSig(trilist.BooleanInput[joinMap.Toggle.JoinNumber]);
            StateFeedback.LinkInputSig(trilist.BooleanInput[joinMap.On.JoinNumber]);
            StateFeedback.LinkComplementInputSig(trilist.BooleanInput[joinMap.Off.JoinNumber]);
            NameFeedback.LinkInputSig(trilist.StringInput[joinMap.Label.JoinNumber]);

            trilist.SetSigTrueAction(joinMap.Toggle.JoinNumber, StateToggle);
            trilist.SetSigTrueAction(joinMap.On.JoinNumber, StateOn);
            trilist.SetSigTrueAction(joinMap.Off.JoinNumber, StateOff);

            trilist.OnlineStatusChange += (d, args) =>
            {
                if (!args.DeviceOnLine)
                {
                    return;
                }

                foreach (var feedback in Feedbacks)
                {
                    feedback.FireUpdate();
                }
            };
        }
コード例 #3
0
        /// <summary>
        /// Parses a non subscription response
        /// </summary>
        /// <param name="attributeCode">The attribute code of the command</param>
        /// <param name="message">The message to parse</param>
        public override void ParseGetMessage(string attributeCode, string message)
        {
            try {
                Debug.Console(2, this, "Parsing Message - '{0}' : Message has an attributeCode of {1}", message, attributeCode);
                // Parse an "+OK" message
                var pattern = "[^ ]* (.*)";

                var match = Regex.Match(message, pattern);

                if (!match.Success)
                {
                    return;
                }

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

                Debug.Console(1, this, "Response: '{0}' Value: '{1}'", attributeCode, value);

                if (message.IndexOf("+OK", StringComparison.OrdinalIgnoreCase) <= -1)
                {
                    return;
                }

                if (attributeCode != "state")
                {
                    return;
                }

                _state = bool.Parse(value);
                StateFeedback.FireUpdate();
                IsSubscribed = true;
            }
            catch (Exception e) {
                Debug.Console(2, "Unable to parse message: '{0}'\n{1}", message, e);
            }
        }