예제 #1
0
파일: Program.cs 프로젝트: Yairg/ZWave
        static void Main(string[] args)
        {
            try
            {
                if (args.Length != 2)
                {
                    Console.WriteLine("Duplicate the ZWave network and setup channels to a new controller");
                    Console.WriteLine("Asumes that the ControlStick is installed");
                    Console.WriteLine("Usage:");
                    Console.WriteLine("       DuplicateZwaveNetwork.exe <Configuration File Name> <Controller Name>");
                    Console.WriteLine();
                    Console.WriteLine("       Configuration File Name - The path to the JSON file with the network ");
                    Console.WriteLine("                                 configuration details");
                    Console.WriteLine("       Controller Name - The name of the controller to duplicate (The controller");
                    Console.WriteLine("                          is expected to be defined in the config file");
                    return;
                }

                var ser = new DataContractJsonSerializer(typeof(ConfigurationFile.ConfigFile));
                var config = default(ConfigurationFile.ConfigFile);
                using (FileStream stream = new FileStream(args[0], FileMode.Open))
                {
                    // Skip the UTF8 headers in the file
                    while (stream.ReadByte() != '{') ;
                    stream.Seek(-1, SeekOrigin.Current);
                    config = ser.ReadObject(stream) as ConfigurationFile.ConfigFile;
                }

                ZWaveController cont = new ZWaveController();
                Console.WriteLine("Connecting to Think Stick");
                cont.Connect();
                Console.WriteLine("Connected");
                var controllerConfig = config.GetControllerByName(args[1]);
                Console.WriteLine("Copying network settings and channels to controller " + controllerConfig.Name);
                var replicationScenes = new List<ZWaveController.ReplicationScene>();
                foreach (var s in controllerConfig.Scenes)
                {
                    var repScene = new ZWaveController.ReplicationScene(s.Channell);
                    var Scene = config.GetSceneById(s.SceneId);
                    Console.WriteLine("Channel " + s.Channell + " --> " + Scene.Name);
                    foreach (var d in Scene.Devices)
                    {
                        var device = config.GetDeviceById(d.DeviceId);
                        Console.WriteLine("                       " + device.Name + " " + (d.Level == 0 ? "off" : "on"));
                        var deviceFromController = cont.Devices[device.NodeId - 1];
                        repScene.SceneItems.Add(deviceFromController, d.Level);
                    }
                    replicationScenes.Add(repScene);
                }
                Console.WriteLine("Make sure to put the controller in \"Receive Network Configuration\" state ");
                Console.WriteLine("to do so on HA07");
                Console.WriteLine(" * Press and hold the INCLUDE Button for 5 seconds. COPY will flash.");
                Console.WriteLine(" * Release the INCLUDE button.");
                Console.WriteLine(" * Press and release the channel 1 OFF/DIM.");
                Console.WriteLine("   The display will show \"RA\" which means \"Receive All Information\"");
                Console.WriteLine();
                Console.WriteLine("On the HA09 the steps are the same but the lights will flash instead");
                Console.WriteLine("of the display.");
                var addedController = cont.AddController(new ZWaveController.ReplicationGroup[] { }, replicationScenes.ToArray());
                if (addedController == null)
                {
                    throw new Exception("Failed to add controller");
                }
                Console.WriteLine("Done!!!");

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            try
            {
                if (args.Length != 2)
                {
                    Console.WriteLine("Duplicate the ZWave network and setup channels to a new controller");
                    Console.WriteLine("Asumes that the ControlStick is installed");
                    Console.WriteLine("Usage:");
                    Console.WriteLine("       DuplicateZwaveNetwork.exe <Configuration File Name> <Controller Name>");
                    Console.WriteLine();
                    Console.WriteLine("       Configuration File Name - The path to the JSON file with the network ");
                    Console.WriteLine("                                 configuration details");
                    Console.WriteLine("       Controller Name - The name of the controller to duplicate (The controller");
                    Console.WriteLine("                          is expected to be defined in the config file");
                    return;
                }

                var ser    = new DataContractJsonSerializer(typeof(ConfigurationFile.ConfigFile));
                var config = default(ConfigurationFile.ConfigFile);
                using (FileStream stream = new FileStream(args[0], FileMode.Open))
                {
                    // Skip the UTF8 headers in the file
                    while (stream.ReadByte() != '{')
                    {
                        ;
                    }
                    stream.Seek(-1, SeekOrigin.Current);
                    config = ser.ReadObject(stream) as ConfigurationFile.ConfigFile;
                }

                ZWaveController cont = new ZWaveController();
                Console.WriteLine("Connecting to Think Stick");
                cont.Connect();
                Console.WriteLine("Connected");
                var controllerConfig = config.GetControllerByName(args[1]);
                Console.WriteLine("Copying network settings and channels to controller " + controllerConfig.Name);
                var replicationScenes = new List <ZWaveController.ReplicationScene>();
                foreach (var s in controllerConfig.Scenes)
                {
                    var repScene = new ZWaveController.ReplicationScene(s.Channell);
                    var Scene    = config.GetSceneById(s.SceneId);
                    Console.WriteLine("Channel " + s.Channell + " --> " + Scene.Name);
                    foreach (var d in Scene.Devices)
                    {
                        var device = config.GetDeviceById(d.DeviceId);
                        Console.WriteLine("                       " + device.Name + " " + (d.Level == 0 ? "off" : "on"));
                        var deviceFromController = cont.Devices[device.NodeId - 1];
                        repScene.SceneItems.Add(deviceFromController, d.Level);
                    }
                    replicationScenes.Add(repScene);
                }
                Console.WriteLine("Make sure to put the controller in \"Receive Network Configuration\" state ");
                Console.WriteLine("to do so on HA07");
                Console.WriteLine(" * Press and hold the INCLUDE Button for 5 seconds. COPY will flash.");
                Console.WriteLine(" * Release the INCLUDE button.");
                Console.WriteLine(" * Press and release the channel 1 OFF/DIM.");
                Console.WriteLine("   The display will show \"RA\" which means \"Receive All Information\"");
                Console.WriteLine();
                Console.WriteLine("On the HA09 the steps are the same but the lights will flash instead");
                Console.WriteLine("of the display.");
                var addedController = cont.AddController(new ZWaveController.ReplicationGroup[] { }, replicationScenes.ToArray());
                if (addedController == null)
                {
                    throw new Exception("Failed to add controller");
                }
                Console.WriteLine("Done!!!");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }