示例#1
0
        public static void ResendOnWakeUp(ZWaveNode node, byte[] msg)
        {
            int minCommandLength = 8;

            if (msg.Length >= minCommandLength && !(msg[6] == (byte)CommandClass.WakeUp && msg[7] == (byte)Command.WakeUpNoMoreInfo))
            {
                byte[] command = new byte[minCommandLength];
                Array.Copy(msg, 0, command, 0, minCommandLength);
                // discard any message having same header and command (first 8 bytes = header + command class + command)
                var wakeUpResendQueue = GetResendQueueData(node);
                for (int i = wakeUpResendQueue.Count - 1; i >= 0; i--)
                {
                    byte[] queuedCommand = new byte[minCommandLength];
                    Array.Copy(wakeUpResendQueue[i], 0, queuedCommand, 0, minCommandLength);
                    if (queuedCommand.SequenceEqual(command))
                    {
                        Utility.logger.Trace("Removing old message {0}", BitConverter.ToString(wakeUpResendQueue[i]));
                        wakeUpResendQueue.RemoveAt(i);
                    }
                }
                Utility.logger.Trace("Adding message {0}", BitConverter.ToString(msg));
                wakeUpResendQueue.Add(msg);
                var wakeUpStatus = (WakeUpStatus)node.GetData("WakeUpStatus", new WakeUpStatus()).Value;
                if (!wakeUpStatus.IsSleeping)
                {
                    wakeUpStatus.IsSleeping = true;
                    var nodeEvent = new NodeEvent(node, EventParameter.WakeUpSleepingStatus, 1 /* 1 = sleeping, 0 = awake */, 0);
                    node.OnNodeUpdated(nodeEvent);
                }
            }
        }
示例#2
0
        public NodeEvent GetEvent(ZWaveNode node, byte[] message)
        {
            //Set up the color values array
            var colordata = node.GetData("ColorValues");
            if (colordata == null) { colordata = new NodeData("ColorValues", new List<ColorValue>()); }
            var colorvals = colordata.Value as List<ColorValue>;
            NodeEvent nodeEvent = null;
            byte cmdType = message[1];
            if (cmdType == (byte)Command.SwitchColorCapabilityReport)
            {
                for (int i = 2; i < 4; i++)
                {
                    for (int j = 0; j < 8; j++)
                    {
                        if ((message[i] & 0x1 << j) > 0)
                        {
                            var colnum = (ZWaveSwitchColorNumber)(8*i+j);
                            var exist = (from val in colorvals
                                         where val.ColorNumber == colnum
                                         select val).FirstOrDefault();
                            if (exist == null) { colorvals.Add(new ColorValue { ColorNumber = colnum, Value = 0 }); }
                            Get(node, 8 * i + j);
                        }
                    }
                }
            }
            else if (cmdType == (byte)Command.SwitchColorReport)
            {

            }
            node.UpdateData("ColorValues", colorvals);
            return nodeEvent;
        }
示例#3
0
 public static void ResendOnWakeUp(ZWaveNode node, byte[] msg)
 {
     int minCommandLength = 8;
     if (msg.Length >= minCommandLength)
     {
         byte[] command = new byte[minCommandLength];
         Array.Copy(msg, 0, command, 0, minCommandLength);
         // discard any message having same header and command (first 8 bytes = header + command class + command)
         var wakeUpResendQueue = GetResendQueueData(node);
         for (int i = wakeUpResendQueue.Count - 1; i >= 0; i--)
         {
             byte[] queuedCommand = new byte[minCommandLength];
             Array.Copy(wakeUpResendQueue[i], 0, queuedCommand, 0, minCommandLength);
             if (queuedCommand.SequenceEqual(command))
             {
                 Utility.logger.Trace("Removing old message {0}", BitConverter.ToString(wakeUpResendQueue[i]));
                 wakeUpResendQueue.RemoveAt(i);
             }
         }
         Utility.logger.Trace("Adding message {0}", BitConverter.ToString(msg));
         wakeUpResendQueue.Add(msg);
         var wakeUpStatus = (WakeUpStatus)node.GetData("WakeUpStatus", new WakeUpStatus()).Value;
         if (!wakeUpStatus.IsSleeping)
         {
             wakeUpStatus.IsSleeping = true;
             var nodeEvent = new NodeEvent(node, EventParameter.WakeUpSleepingStatus, 1 /* 1 = sleeping, 0 = awake */, 0);
             node.OnNodeUpdated(nodeEvent);
         }
     }
 }
示例#4
0
 public static void SetAlwaysAwake(ZWaveNode node, bool alwaysAwake)
 {
     node.GetData("WakeUpAlwaysAwake", false).Value = alwaysAwake;
     if (alwaysAwake)
     {
         WakeUpNode(node);
     }
 }
示例#5
0
        public static bool GetAlwaysAwake(ZWaveNode node)
        {
            var alwaysAwake = node.GetData("WakeUpAlwaysAwake");

            if (alwaysAwake != null && alwaysAwake.Value != null && ((bool)alwaysAwake.Value) == true)
            {
                return(true);
            }
            return(false);
        }
示例#6
0
 public static ZWaveMessage SendToSleep(ZWaveNode node)
 {
     ZWaveMessage msg = null;
     var wakeUpStatus = (WakeUpStatus)node.GetData("WakeUpStatus", new WakeUpStatus()).Value;
     if (!wakeUpStatus.IsSleeping)
     {
         // 0x01, 0x09, 0x00, 0x13, 0x2b, 0x02, 0x84, 0x08, 0x25, 0xee, 0x8b
         msg = node.SendDataRequest(new byte[] { 
             (byte)CommandClass.WakeUp, 
             (byte)Command.WakeUpNoMoreInfo,
             0x25
         }).Wait();
         wakeUpStatus.IsSleeping = true;
         var nodeEvent = new NodeEvent(node, EventParameter.WakeUpSleepingStatus, 1 /* 1 = sleeping, 0 = awake */, 0);
         node.OnNodeUpdated(nodeEvent);
     }
     return msg;
 }
示例#7
0
        public static ZWaveMessage SendToSleep(ZWaveNode node)
        {
            ZWaveMessage msg          = null;
            var          wakeUpStatus = (WakeUpStatus)node.GetData("WakeUpStatus", new WakeUpStatus()).Value;

            if (!wakeUpStatus.IsSleeping)
            {
                // 0x01, 0x09, 0x00, 0x13, 0x2b, 0x02, 0x84, 0x08, 0x25, 0xee, 0x8b
                msg = node.SendDataRequest(new byte[] {
                    (byte)CommandClass.WakeUp,
                    (byte)Command.WakeUpNoMoreInfo,
                    0x25
                }).Wait();
                wakeUpStatus.IsSleeping = true;
                var nodeEvent = new NodeEvent(node, EventParameter.WakeUpSleepingStatus, 1 /* 1 = sleeping, 0 = awake */, 0);
                node.OnNodeUpdated(nodeEvent);
            }
            return(msg);
        }
示例#8
0
        public NodeEvent GetEvent(ZWaveNode node, byte[] message)
        {
            //Set up the color values array
            var colordata = node.GetData("ColorValues");

            if (colordata == null)
            {
                colordata = new NodeData("ColorValues", new List <ColorValue>());
            }
            var       colorvals = colordata.Value as List <ColorValue>;
            NodeEvent nodeEvent = null;
            byte      cmdType   = message[1];

            if (cmdType == (byte)Command.SwitchColorCapabilityReport)
            {
                for (int i = 2; i < 4; i++)
                {
                    for (int j = 0; j < 8; j++)
                    {
                        if ((message[i] & 0x1 << j) > 0)
                        {
                            var colnum = (ZWaveSwitchColorNumber)(8 * i + j);
                            var exist  = (from val in colorvals
                                          where val.ColorNumber == colnum
                                          select val).FirstOrDefault();
                            if (exist == null)
                            {
                                colorvals.Add(new ColorValue {
                                    ColorNumber = colnum, Value = 0
                                });
                            }
                            Get(node, 8 * i + j);
                        }
                    }
                }
            }
            else if (cmdType == (byte)Command.SwitchColorReport)
            {
            }
            node.UpdateData("ColorValues", colorvals);
            return(nodeEvent);
        }
示例#9
0
        public static void WakeUpNode(ZWaveNode node)
        {
            // If node was marked as sleeping, reset the flag
            var wakeUpStatus = node.GetData("WakeUpStatus");

            if (wakeUpStatus != null && wakeUpStatus.Value != null && ((WakeUpStatus)wakeUpStatus.Value).IsSleeping)
            {
                ((WakeUpStatus)wakeUpStatus.Value).IsSleeping = false;
                var wakeEvent = new NodeEvent(node, EventParameter.WakeUpSleepingStatus, 0 /* 1 = sleeping, 0 = awake */, 0);
                node.OnNodeUpdated(wakeEvent);
                // Resend queued messages while node was asleep
                var wakeUpResendQueue = GetResendQueueData(node);
                for (int m = 0; m < wakeUpResendQueue.Count; m++)
                {
                    Utility.logger.Trace("Sending message {0} {1}", m, BitConverter.ToString(wakeUpResendQueue[m]));
                    node.SendMessage(wakeUpResendQueue[m]);
                }
                wakeUpResendQueue.Clear();
            }
        }
示例#10
0
 public static ZWaveValue GetSetPointData(ZWaveNode node)
 {
     return((ZWaveValue)node.GetData("SetPoint", new ZWaveValue()).Value);
 }
示例#11
0
 private static List <byte[]> GetResendQueueData(ZWaveNode node)
 {
     return((List <byte[]>)node.GetData("WakeUpResendQueue", new List <byte[]>()).Value);
 }
示例#12
0
 private static Dictionary<byte, int> GetConfigParamsData(ZWaveNode node)
 {
     return (Dictionary<byte, int>)node.GetData("ConfigParamsLength", new Dictionary<byte, int>()).Value;
 }
示例#13
0
 public static bool GetAlwaysAwake(ZWaveNode node)
 {
     var alwaysAwake = node.GetData("WakeUpAlwaysAwake");
     if (alwaysAwake != null && alwaysAwake.Value != null && ((bool)alwaysAwake.Value) == true)
         return true;
     return false;
 }
 private static UserCodeValue GetUserCodeData(ZWaveNode node)
 {
     return((UserCodeValue)node.GetData("UserCode", new UserCodeValue()).Value);
 }
 private static Dictionary <byte, int> GetConfigParamsData(ZWaveNode node)
 {
     return((Dictionary <byte, int>)node.GetData("ConfigParamsLength", new Dictionary <byte, int>()).Value);
 }
示例#16
0
 private int GetNodeLastLevel(ZWaveNode node)
 {
     return((int)node.GetData("LastLevel", 0).Value);
 }
示例#17
0
 public NodeEvent GetEvent(ZWaveNode node, byte[] message)
 {
     NodeEvent nodeEvent = null;
     byte cmdType = message[1];
     switch (cmdType)
     {
     case (byte)Command.WakeUpIntervalReport:
         if (message.Length > 4)
         {
             uint interval = ((uint)message[2]) << 16;
             interval |= (((uint)message[3]) << 8);
             interval |= (uint)message[4];
             nodeEvent = new NodeEvent(node, EventParameter.WakeUpInterval, interval, 0);
         }
         break;
     case (byte)Command.WakeUpNotification:
         // If node was marked as sleeping, reset the flag
         var wakeUpStatus = node.GetData("WakeUpStatus");
         if (wakeUpStatus != null && wakeUpStatus.Value != null && ((WakeUpStatus)wakeUpStatus.Value).IsSleeping)
         {
             ((WakeUpStatus)wakeUpStatus.Value).IsSleeping = false;
             var wakeEvent = new NodeEvent(node, EventParameter.WakeUpSleepingStatus, 0 /* 1 = sleeping, 0 = awake */, 0);
             node.OnNodeUpdated(wakeEvent);
         }
         // Resend queued messages while node was asleep
         var wakeUpResendQueue = GetResendQueueData(node);
         for (int m = 0; m < wakeUpResendQueue.Count; m++)
         {
             Utility.logger.Trace("Sending message {0} {1}", m, BitConverter.ToString(wakeUpResendQueue[m]));
             node.SendMessage(wakeUpResendQueue[m]);
         }
         wakeUpResendQueue.Clear();
         nodeEvent = new NodeEvent(node, EventParameter.WakeUpNotify, 1, 0);
         break;
     }
     return nodeEvent;
 }
示例#18
0
 public static SecurityData GetSecurityData(ZWaveNode node)
 {
     return((SecurityData)node.GetData("SecurityData", new SecurityData(node)).Value);
 }
示例#19
0
 public static void SetAlwaysAwake(ZWaveNode node, bool alwaysAwake)
 {
     node.GetData("WakeUpAlwaysAwake", false).Value = alwaysAwake;
     if (alwaysAwake)
         WakeUpNode(node);
 }
示例#20
0
 public static void WakeUpNode(ZWaveNode node)
 {
     // If node was marked as sleeping, reset the flag
     var wakeUpStatus = node.GetData("WakeUpStatus");
     if (wakeUpStatus != null && wakeUpStatus.Value != null && ((WakeUpStatus)wakeUpStatus.Value).IsSleeping)
     {
         ((WakeUpStatus)wakeUpStatus.Value).IsSleeping = false;
         var wakeEvent = new NodeEvent(node, EventParameter.WakeUpSleepingStatus, 0 /* 1 = sleeping, 0 = awake */, 0);
         node.OnNodeUpdated(wakeEvent);
         // Resend queued messages while node was asleep
         var wakeUpResendQueue = GetResendQueueData(node);
         for (int m = 0; m < wakeUpResendQueue.Count; m++)
         {
             Utility.logger.Trace("Sending message {0} {1}", m, BitConverter.ToString(wakeUpResendQueue[m]));
             node.SendMessage(wakeUpResendQueue[m]);
         }
         wakeUpResendQueue.Clear();
     }
 }
示例#21
0
 private static UserCodeValue GetUserCodeData(ZWaveNode node)
 {
     return (UserCodeValue)node.GetData("UserCode", new UserCodeValue()).Value;
 }
 private static List<byte[]> GetResendQueueData(ZWaveNode node)
 {
     return (List<byte[]>)node.GetData("WakeUpResendQueue", new List<byte[]>()).Value;
 }
 public static ZWaveValue GetSetPointData(ZWaveNode node)
 {
     return (ZWaveValue)node.GetData("SetPoint", new ZWaveValue()).Value;
 }