示例#1
0
        //Untested
        public void SetDeviceName(string newName)
        {
            name = newName;

            byte[] namePart = GetNamePart(newName, 1);
            if (namePart == null)
            {
                return;
            }
            CANInterface.SendMessage(this, Commands.CmdSysPName1, namePart);

            namePart = GetNamePart(newName, 2);
            if (namePart == null)
            {
                return;
            }
            CANInterface.SendMessage(this, Commands.CmdSysPName2, namePart);

            namePart = GetNamePart(newName, 3);
            if (namePart == null)
            {
                return;
            }
            CANInterface.SendMessage(this, Commands.CmdSysPName3, namePart);
        }
示例#2
0
        /// <summary>
        /// Polls the network with the given command, then fires the PollRecieved event with the results.
        /// </summary>
        /// <param name="sendCommand">The command to send.</param>
        /// <param name="nodes">The Nodes to poll. Leave null for all.</param>
        /// <param name="devices">The Devices to poll on each Node. Leave null for all, set to 0 to poll only Nodes.</param>
        public NewPing(Commands sendCommand, Dictionary <byte, List <byte> > nodeDevices)
        {
            expectedResult = responseCommands[sendCommand];

            //If given an empty list, ping just the nodes
            //Probably better to just throw an exception, actually
            if (nodeDevices.Count == 0)
            {
                for (byte i = 1; i < 127; i++)
                {
                    nodeDevices.Add(i, new List <byte>());
                }
            }

            foreach (byte node in nodeDevices.Keys)
            {
                lastMessage = CANInterface.SendMessage(node, 0, sendCommand);
                foreach (byte device in nodeDevices[node])
                {
                    lastMessage = CANInterface.SendMessage(node, device, sendCommand);
                }
            }

            CANInterface.MessageSent     += CANInterface_MessageSent;
            CANInterface.MessageReceived += CANInterface_MessageReceived;
            waitForResponse.Interval      = 100;
            waitForResponse.Tick         += WaitForResponse_Tick;
        }
示例#3
0
        private static void DevicePoll_Received(List <C4UFX.CANMessage> responses)
        {
            StatusUpdate?.Invoke("Querying names (1/3)...");


            foreach (C4UFX.CANMessage response in responses)
            {
                FndTnd address = CANInterface.IdToFndTnd(response.ID);
                if (address.FromDevice > 0)
                {
                    Node   currentNode = allResponses.First(x => x.NodeId == address.FromNode);
                    byte   fromNode    = CANInterface.IdToFndTnd(response.ID).FromNode;
                    byte   fromDevice  = CANInterface.IdToFndTnd(response.ID).FromDevice;
                    Device newDevice;
                    switch ((Signatures)response.Data[2])
                    {
                    case Signatures.MechanicalSwitch: newDevice = new MechanicalSwitch(fromNode, fromDevice); break;

                    case Signatures.StatusLED: newDevice = new StatusLED(fromNode, fromDevice); break;

                    case Signatures.InfraredInput: newDevice = new InfraredInput(fromNode, fromDevice); break;

                    case Signatures.DimmerOut: newDevice = new DimmerOut(fromNode, fromDevice); break;

                    case Signatures.LatLong: newDevice = new LatLong(fromNode, fromDevice); break;

                    case Signatures.TimerEvent: newDevice = new TimerEvent(fromNode, fromDevice); break;

                    case Signatures.Scene: newDevice = new Scene(fromNode, fromDevice); break;

                    case Signatures.RealTimeClock: newDevice = new RealTimeClock(fromNode, fromDevice); break;

                    default: newDevice = new UnknownDevice(fromNode, fromDevice); break;
                    }

                    currentNode.Devices.Add(newDevice);
                }
            }

            Dictionary <byte, List <byte> > sendList = new Dictionary <byte, List <byte> >();

            foreach (Node node in allResponses)
            {
                if (sendList.Keys.Contains(node.NodeId))
                {
                    break;
                }
                sendList.Add(node.NodeId, new List <byte>());
                for (byte i = 1; i < 127; i++)
                {
                    sendList[node.NodeId].Add(i);
                }
            }

            CANPing poll = new CANPing(Commands.CmdSysEName1, sendList);

            poll.ResponseReceived += Name1Poll_Received;
            PongsReceived?.Invoke(allResponses, false);
        }
示例#4
0
        /// <summary>
        /// Sets the brightness of the light as a percent.
        /// </summary>
        /// <param name="brightness">The brightness, as a value from 0-100.</param>
        private void SetBrightness(byte brightness)
        {
            if (brightness > 100)
            {
                throw new Exception("Cannot set light brightness higher than 100%.");
            }

            CANInterface.SendMessage(this, Commands.CmdConValue, new byte[] { brightness });
        }
示例#5
0
        /// <summary>
        /// Sends the given command to the given device, then fires the PollRecieved event with the result.
        /// </summary>
        /// <param name="sendCommand">The command to send.</param>
        /// <param name="nodeId">The Node to poll.</param>
        /// <param name="deviceId">The Device to poll on that Node.</param>
        public CANPing(Commands sendCommand, byte nodeId, byte deviceId)
        {
            expectedResult = responseCommands[sendCommand];

            lastMessage = CANInterface.SendMessage(nodeId, deviceId, sendCommand);

            CANInterface.MessageSent     += CANInterface_MessageSent;
            CANInterface.MessageReceived += CANInterface_MessageReceived;
            waitForResponse.Interval      = 100;
            waitForResponse.Tick         += WaitForResponse_Tick;
        }
示例#6
0
        /// <summary>
        /// Set brightness value over time.
        /// </summary>
        /// <param name="brightness">The brightness, as a value from 0-100.</param>
        /// <param name="time">The time in seconds to reach the brightness value, as a value between 0 - 65535.</param>
        public void SetFade(byte brightness, int time)
        {
            if (time < 0 || time > 65535)
            {
                throw new Exception("Time value for SetFade must be a value between 0 - 65535.");
            }

            byte time1 = BitConverter.GetBytes(time)[1];
            byte time2 = BitConverter.GetBytes(time)[0];

            CANInterface.SendMessage(this, Commands.CmdConSetFade, new byte[] { brightness, time1, time2 });
        }
示例#7
0
        private void CANInterface_MessageReceived(C4UFX.CANMessage message)
        {
            if (message.Data[0] == (byte)Commands.CmdStatLightValue && CANInterface.IdToFndTnd(message.ID).FromDevice == deviceId)
            {
                if (brightness != message.Data[1])
                {
                    BrightnessChanged?.Invoke(message.Data[1]);
                }

                brightness = message.Data[1];
            }
        }
示例#8
0
        private static void NodePoll_PollReceived(List <C4UFX.CANMessage> responses)
        {
            if (responses.Count == 0)
            {
                StatusUpdate?.Invoke("No Nodes found - Check your connection.");
                return;
            }

            StatusUpdate?.Invoke("Pinging devices...");

            foreach (C4UFX.CANMessage response in responses)
            {
                byte fromNode = CANInterface.IdToFndTnd(response.ID).FromNode;
                Node newNode;
                switch ((Signatures)response.Data[2])
                {
                case Signatures.SmartSwitch: newNode = new SmartSwitch(fromNode); break;

                case Signatures.ACDimmer: newNode = new ACDimmer(fromNode); break;

                case Signatures.TimerRTC: newNode = new TimerRTC(fromNode); break;

                case Signatures.SceneController: newNode = new SceneController(fromNode); break;

                default: newNode = new UnknownNode(fromNode); break;
                }

                allResponses.Add(newNode);
            }

            Dictionary <byte, List <byte> > sendList = new Dictionary <byte, List <byte> >();

            foreach (Node node in allResponses)
            {
                if (sendList.Keys.Contains(node.NodeId))
                {
                    break;
                }
                sendList.Add(node.NodeId, new List <byte>());
                for (byte i = 1; i < 127; i++)
                {
                    sendList[node.NodeId].Add(i);
                }
            }

            CANPing poll = new CANPing(Commands.CmdSysPing, sendList);

            poll.ResponseReceived += DevicePoll_Received;
            PongsReceived?.Invoke(allResponses, false);
        }
示例#9
0
        private static void Name1Poll_Received(List <C4UFX.CANMessage> responses)
        {
            StatusUpdate?.Invoke("Querying names (2/3)...");

            foreach (C4UFX.CANMessage response in responses)
            {
                FndTnd address  = CANInterface.IdToFndTnd(response.ID);
                string namePart = string.Empty;
                for (int i = 1; i < response.Data.Length; i++)
                {
                    namePart += (char)response.Data[i];
                }

                Node thisNode = allResponses.Find(x => x.NodeId == address.FromNode);
                //if (thisNode == null)
                //    allResponses.Add(new UnknownNode(address.FromNode));

                if (address.FromDevice == 0)
                {
                    allResponses.Find(x => x.NodeId == address.FromNode).SetNamePart(namePart, 1);
                }
                else
                {
                    allResponses.Find(x => x.NodeId == address.FromNode).Devices.Find(x => x.DeviceId == address.FromDevice).SetNamePart(namePart, 1);
                }
                //If the node/device isn't found, add it to the list
            }

            Dictionary <byte, List <byte> > sendList = new Dictionary <byte, List <byte> >();

            foreach (Node node in allResponses)
            {
                if (sendList.Keys.Contains(node.NodeId))
                {
                    break;
                }
                sendList.Add(node.NodeId, new List <byte>());
                foreach (Device device in node.Devices)
                {
                    sendList[node.NodeId].Add(device.DeviceId);
                }
            }

            CANPing poll = new CANPing(Commands.CmdSysEName2, sendList);

            poll.ResponseReceived += Name2Poll_Received;
            PongsReceived?.Invoke(allResponses, false);
        }
示例#10
0
        private static void Name3Poll_Received(List <C4UFX.CANMessage> responses)
        {
            StatusUpdate?.Invoke("Querying parameters (1/2)...");

            foreach (C4UFX.CANMessage response in responses)
            {
                FndTnd address  = CANInterface.IdToFndTnd(response.ID);
                string namePart = string.Empty;
                for (int i = 1; i < response.Data.Length; i++)
                {
                    namePart += (char)response.Data[i];
                }

                if (address.FromDevice == 0)
                {
                    allResponses.First(x => x.NodeId == address.FromNode).SetNamePart(namePart, 3);
                }
                else
                {
                    allResponses.First(x => x.NodeId == address.FromNode).Devices.First(x => x.DeviceId == address.FromDevice).SetNamePart(namePart, 3);
                }
            }

            Dictionary <byte, List <byte> > sendList = new Dictionary <byte, List <byte> >();

            foreach (Node node in allResponses)
            {
                if (sendList.Keys.Contains(node.NodeId))
                {
                    break;
                }
                sendList.Add(node.NodeId, new List <byte>());
                foreach (Device device in node.Devices)
                {
                    sendList[node.NodeId].Add(device.DeviceId);
                }
            }

            CANPing poll = new CANPing(Commands.CmdSysEPar, sendList);

            poll.ResponseReceived += Parameters1_Received;
            PongsReceived?.Invoke(allResponses, false);
        }
示例#11
0
        private static void Parameters1_Received(List <C4UFX.CANMessage> responses)
        {
            StatusUpdate?.Invoke("Querying parameters (2/2)...");

            foreach (C4UFX.CANMessage response in responses)
            {
                FndTnd address = CANInterface.IdToFndTnd(response.ID);
                for (int i = 0; i < response.DLC - 1; i++)
                {
                    if (address.FromDevice == 0)
                    {
                        allResponses.First(x => x.NodeId == address.FromNode).Parameters1[i] = response.Data[i + 1];
                    }
                    else
                    {
                        allResponses.First(x => x.NodeId == address.FromNode).Devices.First(x => x.DeviceId == address.FromDevice).Parameters1[i] = response.Data[i + 1];
                    }
                }
            }

            Dictionary <byte, List <byte> > sendList = new Dictionary <byte, List <byte> >();

            foreach (Node node in allResponses)
            {
                if (sendList.Keys.Contains(node.NodeId))
                {
                    break;
                }
                sendList.Add(node.NodeId, new List <byte>());
                foreach (Device device in node.Devices)
                {
                    sendList[node.NodeId].Add(device.DeviceId);
                }
            }

            CANPing poll = new CANPing(Commands.CmdSysEPar2, sendList);

            poll.ResponseReceived += Parameters2_Received;
            PongsReceived?.Invoke(allResponses, false);
        }
示例#12
0
        /// <summary>
        /// Polls the network with the given command, then fires the PollRecieved event with the results.
        /// </summary>
        /// <param name="sendCommand">The command to send.</param>
        /// <param name="nodes">The Nodes to poll.</param>
        /// <param name="devices">The Devices to poll on each Node.</param>
        public CANPing(Commands sendCommand, Dictionary <byte, List <byte> > nodeDevices)
        {
            if (nodeDevices.Count == 0)
            {
                throw new Exception("Cannot ping 0 nodes.");
            }

            expectedResult = responseCommands[sendCommand];

            foreach (byte node in nodeDevices.Keys)
            {
                lastMessage = CANInterface.SendMessage(node, 0, sendCommand);
                foreach (byte device in nodeDevices[node])
                {
                    lastMessage = CANInterface.SendMessage(node, device, sendCommand);
                }
            }

            CANInterface.MessageSent     += CANInterface_MessageSent;
            CANInterface.MessageReceived += CANInterface_MessageReceived;
            waitForResponse.Interval      = 100;
            waitForResponse.Tick         += WaitForResponse_Tick;
        }
示例#13
0
        private static void Parameters2_Received(List <C4UFX.CANMessage> responses)
        {
            StatusUpdate?.Invoke("Poll Complete!");

            foreach (C4UFX.CANMessage response in responses)
            {
                FndTnd address = CANInterface.IdToFndTnd(response.ID);
                for (int i = 0; i < response.DLC - 1; i++)
                {
                    if (address.FromDevice == 0)
                    {
                        allResponses.First(x => x.NodeId == address.FromNode).Parameters2[i] = response.Data[i + 1];
                    }
                    else
                    {
                        allResponses.First(x => x.NodeId == address.FromNode).Devices.First(x => x.DeviceId == address.FromDevice).Parameters2[i] = response.Data[i + 1];
                    }
                }
            }

            Dictionary <byte, List <byte> > sendList = new Dictionary <byte, List <byte> >();

            foreach (Node node in allResponses)
            {
                if (sendList.Keys.Contains(node.NodeId))
                {
                    break;
                }
                sendList.Add(node.NodeId, new List <byte>());
                foreach (Device device in node.Devices)
                {
                    sendList[node.NodeId].Add(device.DeviceId);
                }
            }

            PongsReceived?.Invoke(allResponses, true);
        }
示例#14
0
 public void FullOn()
 {
     CANInterface.SendMessage(this, Commands.CmdConDClk);
 }
示例#15
0
 /// <summary>
 /// Sets whether the light is on (at a preset brightness), or off.
 /// </summary>
 /// <param name="on">if set to <c>true</c>, the light is [on].</param>
 public void SetOnOff(bool on)
 {
     CANInterface.SendMessage(this, on ? Commands.CmdConOn : Commands.CmdConOff);
 }
示例#16
0
 /// <summary>
 /// Toggles the light on and off.
 /// </summary>
 public void ToggleOnOff()
 {
     CANInterface.SendMessage(this, Commands.CmdConOnOff);
 }
示例#17
0
 public void OnDeserializingMethod()
 {
     CANInterface.MessageReceived += CANInterface_MessageReceived;
     CANInterface.SendMessage(this, Commands.CmdSysEStateZZ);
 }
示例#18
0
 /// <summary>
 /// Sets the last “On” value to the current value. Used when a switch is
 /// dimming the output and is then released.
 /// </summary>
 public void Release()
 {
     CANInterface.SendMessage(this, Commands.CmdConRelease);
 }
示例#19
0
 /// <summary>
 /// Fade one step up or down and reverse direction when 0 or 100% is reached.
 /// </summary>
 public void FadeContinuous()
 {
     CANInterface.SendMessage(this, Commands.CmdConFadeCont);
 }
示例#20
0
 /// <summary>
 /// Fade up one step and stop when 100% is reached.
 /// </summary>
 public void FadeUp()
 {
     CANInterface.SendMessage(this, Commands.CmdConFadeUp);
 }
示例#21
0
 /// <summary>
 /// Fade down one step and stop when 0% is reached.
 /// </summary>
 public void FadeDown()
 {
     CANInterface.SendMessage(this, Commands.CmdConFadeDwn);
 }