示例#1
0
        void IOWNEventListener.handleEvent(string message)
        {
            Logger.WriteLog(TAG, "Received message " + message);
            string[] msgSeparator = new string[] { "##" };
            string   msgPattern   = @"^\*(\d+)\*(\d+)\*(\d+)$";

            string[] messages = message.Split(msgSeparator, StringSplitOptions.None);
            foreach (string singleMessage in messages)
            {
                //Debug.WriteLine("Single message" + singleMessage);
                MatchCollection matches = Regex.Matches(singleMessage, msgPattern);

                foreach (Match match in matches)
                {
                    if (match.Groups.Count == 4)
                    {
                        int who  = int.Parse(match.Groups[1].Value);
                        int what = int.Parse(match.Groups[2].Value);
                        int where = int.Parse(match.Groups[3].Value);

                        try
                        {
                            OWNComponent component = components[where];
                            if (component != null)
                            {
                                Debug.WriteLine("===> Received event for existing component " + where);
                                component.Status = what;
                            }
                        }
                        catch (Exception exception)
                        {
                            Debug.WriteLine(exception.Message);
                        }
                    }
                }
            }
        }
示例#2
0
        public async void getStatus(OWNComponent component)
        {
            string[] statusMessages;

            if (component != null)
            {
                statusMessages = new string[] { component.getStatusCommand() };
            }
            else
            {
                statusMessages = new string[lights.components.Count + shutters.components.Count];

                for (int i = 0, j = 0; i < components.Length; i++)
                {
                    OWNComponent item = components[i];
                    if (item != null)
                    {
                        statusMessages[j++] = item.getStatusCommand();
                    }
                }
            }

            await _command.Send(statusMessages);
        }
示例#3
0
 public async void setStatus(OWNComponent component, int status)
 {
     await _command.Send(new string[] { component.getCommand(status) });
 }