示例#1
0
 public ZWave()
 {
     controller = new ZWaveController();
     controller.ControllerStatusChanged += Controller_ControllerStatusChanged;
     controller.DiscoveryProgress += Controller_DiscoveryProgress;
     controller.NodeOperationProgress += Controller_NodeOperationProgress;
     controller.NodeUpdated += Controller_NodeUpdated;
 }
 internal void SetController(ZWaveController controller)
 {
     this.controller = controller;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ZWaveLib.ZWaveNode"/> class.
 /// </summary>
 /// <param name="controller">Controller.</param>
 /// <param name="nodeId">Node identifier.</param>
 /// <param name="genericType">Generic type.</param>
 public ZWaveNode(ZWaveController controller, byte nodeId, byte genericType) : this(controller, nodeId)
 {
     ProtocolInfo.GenericType = genericType;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ZWaveLib.ZWaveNode"/> class.
 /// </summary>
 /// <param name="controller">Controller.</param>
 /// <param name="nodeId">Node identifier.</param>
 public ZWaveNode(ZWaveController controller, byte nodeId) : this()
 {
     this.controller = controller;
     Id = nodeId;
 }
 static void StopNodeRemove(ZWaveController controller)
 {
     ToggleDebug(true);
     controller.StopNodeRemove();
     ToggleDebug(false);
 }
 static void StartNodeRemove(ZWaveController controller)
 {
     ToggleDebug(true);
     controller.BeginNodeRemove();
 }
        public static void Main(string[] cargs)
        {
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("\nZWaveLib Test Program\n");
            Console.ForegroundColor = ConsoleColor.White;

            var controller = new ZWaveController(serialPortName);
            // Register controller event handlers
            controller.ControllerStatusChanged += Controller_ControllerStatusChanged;;
            controller.DiscoveryProgress += Controller_DiscoveryProgress;
            controller.NodeOperationProgress += Controller_NodeOperationProgress;
            controller.NodeUpdated += Controller_NodeUpdated;

            // Main program loop
            string command = "";
            while (command != "!")
            {
                ShowMenu();
                // TODO: Allow issuing CommandClass commands on nodes from the console input
                // TODO: Add "Associate node to controller" option
                // TODO: Add "Query node parameters" based on implemented classes
                command = Console.ReadLine();
                switch (command)
                {
                case "0":
                    ToggleDebug(!showDebugOutput);
                    break;
                case "1":
                    ListNodes(controller);
                    break;
                case "2":
                    StartNodeAdd(controller);
                    break;
                case "3":
                    StopNodeAdd(controller);
                    break;
                case "4":
                    StartNodeRemove(controller);
                    break;
                case "5":
                    StopNodeRemove(controller);
                    break;
                case "6":
                    HealNetwork(controller);
                    break;
                case "7":
                    RunStressTest(controller);
                    break;
                case "8":
                    ShowZWaveLibApi();
                    break;
                case "9":
                    Discovery(controller);
                    break;
                case "?":
                    SetSerialPortName(controller);
                    break;
                case "+":
                    controller.Connect();
                    break;
                }
            }
            Console.WriteLine("\nCiao!\n");
            controller.Dispose();
        }
 private static void SetSerialPortName(ZWaveController controller)
 {
     Console.WriteLine("Enter the serial port name (eg. COM7 or /dev/ttyUSB0):");
     string port = Console.ReadLine().Trim();
     if (!String.IsNullOrWhiteSpace(port))
     {
         serialPortName = port;
         controller.PortName = serialPortName;
         controller.Connect();
     }
 }
        static void RunStressTest(ZWaveController controller)
        {
            ToggleDebug(true);
            // loop 10 times
            for (int x = 0; x < 10; x++)
            {
                foreach (var node in controller.Nodes)
                {
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("\nNode {0} Controller.GetNodeInformationFrame", node.Id);
                    Console.ForegroundColor = ConsoleColor.White;
                    controller.GetNodeInformationFrame(node.Id);

                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("\nNode {0} Controller.GetNeighborsRoutingInfo", node.Id);
                    Console.ForegroundColor = ConsoleColor.White;
                    controller.GetNeighborsRoutingInfo(node.Id);

                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("\nNode {0} CommandClass.ManufacturerSpecific.Get", node.Id);
                    Console.ForegroundColor = ConsoleColor.White;
                    ManufacturerSpecific.Get(node);

                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("\nNode {0} CommandClass.Basic.Get", node.Id);
                    Console.ForegroundColor = ConsoleColor.White;
                    Basic.Get(node);
                }
                // Pause 2 secods between each test pass
                Thread.Sleep(2000);
            }
            ToggleDebug(false);
        }
 static void ListNodes(ZWaveController controller)
 {
     foreach (var node in controller.Nodes)
     {
         Console.ForegroundColor = ConsoleColor.Cyan;
         Console.WriteLine("\nNode {0}", node.Id);
         Console.ForegroundColor = ConsoleColor.White;
         var mspecs = node.ManufacturerSpecific;
         Console.WriteLine("    Manufacturer Specific {0}-{1}-{2}", mspecs.ManufacturerId, mspecs.TypeId, mspecs.ProductId);
         Console.WriteLine("    Basic Type {0}", (GenericType)node.ProtocolInfo.BasicType);
         Console.WriteLine("    Generic Type {0}", (GenericType)node.ProtocolInfo.GenericType);
         Console.WriteLine("    Specific Type {0}", node.ProtocolInfo.SpecificType);
         Console.WriteLine("    Secure Info Frame {0}", BitConverter.ToString(node.SecuredNodeInformationFrame));
         Console.WriteLine("    Info Frame {0}", BitConverter.ToString(node.NodeInformationFrame));
         foreach (NodeCommandClass nodeCmdClass in node.CommandClasses)
         {
             string versionInfo = "";
             // TODO: GetCmdClassVersion version is not currently working
             if (node.SupportCommandClass(CommandClass.Version))
             {
                 versionInfo = String.Format("(version {0})", nodeCmdClass.Version);
             }
             if (!Enum.IsDefined(typeof(CommandClass), nodeCmdClass.Id))
             {
                 versionInfo += " [UNSUPPORTED]";
                 Console.ForegroundColor = ConsoleColor.Red;
             }
             else
             {
                 Console.ForegroundColor = ConsoleColor.White;
             }
             Console.WriteLine("        {0} {1}", nodeCmdClass.CommandClass, versionInfo);
         }
         Console.ForegroundColor = ConsoleColor.White;
         if (node.GetData("RoutingInfo") != null)
         {
             Console.WriteLine("    Routing Info {0}", BitConverter.ToString((byte[])node.GetData("RoutingInfo").Value));
         }
     }
     Console.WriteLine("\n");
 }
 static void HealNetwork(ZWaveController controller)
 {
     ToggleDebug(true);
     foreach (var node in controller.Nodes)
     {
         Console.ForegroundColor = ConsoleColor.Cyan;
         Console.WriteLine("\nHealing Node {0}", node.Id);
         Console.ForegroundColor = ConsoleColor.White;
         controller.RequestNeighborsUpdateOptions(node.Id);
         controller.RequestNeighborsUpdate(node.Id);
         controller.GetNeighborsRoutingInfo(node.Id);
     }
     ToggleDebug(false);
 }
 private static void Discovery(ZWaveController controller)
 {
     ToggleDebug(true);
     controller.Discovery();
     ToggleDebug(false);
 }
示例#13
0
 internal void SetController(ZWaveController controller)
 {
     this.controller = controller;
 }
示例#14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ZWaveLib.ZWaveNode"/> class.
 /// </summary>
 /// <param name="controller">Controller.</param>
 /// <param name="nodeId">Node identifier.</param>
 /// <param name="genericType">Generic type.</param>
 public ZWaveNode(ZWaveController controller, byte nodeId, byte genericType)
     : this(controller, nodeId)
 {
     ProtocolInfo.GenericType = genericType;
 }
示例#15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ZWaveLib.ZWaveNode"/> class.
 /// </summary>
 /// <param name="controller">Controller.</param>
 /// <param name="nodeId">Node identifier.</param>
 public ZWaveNode(ZWaveController controller, byte nodeId)
     : this()
 {
     this.controller = controller;
     Id = nodeId;
 }