示例#1
0
        private void SaveConfig()
        {
            string fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "lircconfig.xml");

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }
            var settings = new System.Xml.XmlWriterSettings();

            settings.Indent = true;
            var serializer = new System.Xml.Serialization.XmlSerializer(remotesConfig.GetType());
            var writer     = System.Xml.XmlWriter.Create(fileName, settings);

            serializer.Serialize(writer, remotesConfig);
            writer.Close();
            //
            try
            {
                string lircConfiguration = "";
                foreach (var remote in remotesConfig)
                {
                    lircConfiguration += GetString(remote.Configuration) + "\n";
                }
                File.WriteAllText("/etc/lirc/lircd.conf", lircConfiguration);
                MigService.ShellCommand("/etc/init.d/lirc", " force-reload");
            }
            catch
            {
            }
        }
示例#2
0
        public CameraInput()
        {
            string assemblyFolder = MigService.GetAssemblyDirectory(this.GetType().Assembly);

            // video 4 linux interop, try to detect Raspbian/Ubuntu
            if (Directory.Exists("/lib/arm-linux-gnueabi") || Directory.Exists("/lib/arm-linux-gnueabihf"))
            {
                MigService.ShellCommand("cp", " -f \"" + Path.Combine(assemblyFolder, "v4l/raspbian_libCameraCaptureV4L.so") + "\" \"" + Path.Combine(assemblyFolder, "libCameraCaptureV4L.so") + "\"");
                //
                //if (File.Exists("/usr/lib/libgdiplus.so") && !File.Exists("/usr/local/lib/libgdiplus.so"))
                //{
                //    ShellCommand("ln", " -s \"/usr/lib/libgdiplus.so\" \"/usr/local/lib/libgdiplus.so\"");
                //}
            }
            else // fallback (ubuntu and other 64bit debians)
            {
                string v4lfile = "v4l/debian64_libCameraCaptureV4L.so.gd3";
                if (!File.Exists("/usr/lib/x86_64-linux-gnu/libgd.so.3"))
                {
                    v4lfile = "v4l/debian64_libCameraCaptureV4L.so";
                }
                MigService.ShellCommand(
                    "cp",
                    " -f \"" + Path.Combine(
                        assemblyFolder,
                        v4lfile
                        ) + "\" \"" + Path.Combine(
                        assemblyFolder,
                        "libCameraCaptureV4L.so"
                        ) + "\""
                    );
            }
        }
示例#3
0
        public LircRemote()
        {
            // lirc client lib symlink
            string assemblyFolder = MigService.GetAssemblyDirectory(this.GetType().Assembly);
            var    liblirclink    = Path.Combine(assemblyFolder, "liblirc_client.so");

            if (File.Exists("/usr/lib/liblirc_client.so") && !File.Exists(liblirclink))
            {
                MigService.ShellCommand("ln", " -s \"/usr/lib/liblirc_client.so\" \"" + liblirclink + "\"");
            }
            else if (File.Exists("/usr/lib/liblirc_client.so.0") && !File.Exists(liblirclink))
            {
                MigService.ShellCommand("ln", " -s \"/usr/lib/liblirc_client.so.0\" \"" + liblirclink + "\"");
            }
            // create .lircrc file
            var lircrcFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), ".lircrc");

            if (!File.Exists(lircrcFile))
            {
                var lircrc = "begin\n" +
                             "        prog = homegenie\n" +
                             "        button = KEY_1\n" +
                             "        repeat = 3\n" +
                             "        config = KEY_1\n" +
                             "end\n";
                try
                {
                    File.WriteAllText(lircrcFile, lircrc);
                }
                catch { }
            }
            //
            remotesConfig = new List <LircRemoteData>();
            string configfile = Path.Combine(assemblyFolder, "lircconfig.xml");

            if (File.Exists(configfile))
            {
                var serializer = new XmlSerializer(typeof(List <LircRemoteData>));
                var reader     = new StreamReader(configfile);
                remotesConfig = (List <LircRemoteData>)serializer.Deserialize(reader);
                reader.Close();
            }
            //
            string remotesdb = Path.Combine(assemblyFolder, "lircremotes.xml");

            if (File.Exists(remotesdb))
            {
                var serializer = new XmlSerializer(typeof(List <LircRemoteData>));
                var reader     = new StreamReader(remotesdb);
                remotesData = (List <LircRemoteData>)serializer.Deserialize(reader);
                reader.Close();
            }
        }
示例#4
0
        public X10()
        {
            if (Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX)
            {
                // Fix libusb symbolic link
                string assemblyFolder = MigService.GetAssemblyDirectory(this.GetType().Assembly);
                var    libUsbLink     = Path.Combine(assemblyFolder, "libusb-1.0.so");
                if (File.Exists(libUsbLink))
                {
                    File.Delete(libUsbLink);
                }
                // RaspBerry Pi arm-hf (hard-float) dependency check and needed symlink
                if (File.Exists("/lib/arm-linux-gnueabihf/libusb-1.0.so.0.1.0"))
                {
                    MigService.ShellCommand("ln", " -s \"/lib/arm-linux-gnueabihf/libusb-1.0.so.0.1.0\" \"" + libUsbLink + "\"");
                }
                // RaspBerry Pi arm-el dependency check and needed symlink
                else if (File.Exists("/lib/arm-linux-gnueabi/libusb-1.0.so.0.1.0"))
                {
                    MigService.ShellCommand("ln", " -s \"/lib/arm-linux-gnueabi/libusb-1.0.so.0.1.0\" \"" + libUsbLink + "\"");
                }
                // Debian/Ubuntu 64bit dependency and needed symlink check
                else if (File.Exists("/lib/x86_64-linux-gnu/libusb-1.0.so.0"))
                {
                    MigService.ShellCommand("ln", " -s \"/lib/x86_64-linux-gnu/libusb-1.0.so.0\" \"" + libUsbLink + "\"");
                }
                // Remove CM19 kernel drivers to allow access to the device
                MigService.ShellCommand("rmmod", " lirc_atiusb");
                MigService.ShellCommand("rmmod", " ati_remote");
                MigService.ShellCommand("rmmod", " rc_ati_x10");
            }

            // CM19 Transceiver driver
            // TODO: should "rmmod" CM19 kernel modules for CM19Lib to work (Linux)
            cm19Lib = new Cm19Manager();
            cm19Lib.RfCameraReceived   += Cm19LibOnRfCameraReceived;
            cm19Lib.RfDataReceived     += Cm19LibOnRfDataReceived;
            cm19Lib.RfCommandReceived  += Cm19LibOnRfCommandReceived;
            cm19Lib.RfSecurityReceived += Cm19LibOnRfSecurityReceived;

            // CM11 and CM15 PLC driver
            x10Lib = new XTenManager();
            x10Lib.ModuleChanged      += X10lib_ModuleChanged;
            x10Lib.RfDataReceived     += X10lib_RfDataReceived;
            x10Lib.RfSecurityReceived += X10lib_RfSecurityReceived;

            securityModules = new List <InterfaceModule>();
            // try loading cached security modules list
            DeserializeModules(SecurityModulesDb, securityModules);
            standardModules = new List <InterfaceModule>();
        }
示例#5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CameraInput"/> class.
        /// </summary>
        public CameraInput()
        {
            var assemblyFolder = MigService.GetAssemblyDirectory(this.GetType().Assembly);

            Log.Debug($"{this.GetDomain()} Attempting to determine OS for V4L Driver");

            // video 4 linux interop, try to detect Raspbian/Ubuntu
            if (Directory.Exists("/lib/arm-linux-gnueabi") || Directory.Exists("/lib/arm-linux-gnueabihf"))
            {
                Log.Debug($"{this.GetDomain()} /lib/arm-linux-gnueabi exists");
                var command     = "cp";
                var commandArgs = " -f \"" + Path.Combine(assemblyFolder, "v4l/raspbian_libCameraCaptureV4L.so") + "\" \"" + Path.Combine(assemblyFolder, "libCameraCaptureV4L.so") + "\"";
                Log.Debug($"{this.GetDomain()} Running: {command}{commandArgs}");
                MigService.ShellCommand(command, commandArgs);

                // if (File.Exists("/usr/lib/libgdiplus.so") && !File.Exists("/usr/local/lib/libgdiplus.so"))
                // {
                //    ShellCommand("ln", " -s \"/usr/lib/libgdiplus.so\" \"/usr/local/lib/libgdiplus.so\"");
                // }
            }
            else
            {
                Log.Debug($"{this.GetDomain()} /lib/arm-linux-gnueabi doesn't exist, using fallback");

                // fallback (ubuntu and other 64bit debians)
                var v4lfile = "v4l/debian64_libCameraCaptureV4L.so.gd3";
                if (!File.Exists("/usr/lib/x86_64-linux-gnu/libgd.so.3"))
                {
                    Log.Debug($"{this.GetDomain()} /usr/lib/x86_64-linux-gnu/libgd.so.3 doesn't exist");
                    v4lfile = "v4l/debian64_libCameraCaptureV4L.so";
                    Log.Debug($"{this.GetDomain()} v4lfile set to {v4lfile}");
                }

                var fallbackCommand = "cp";
                var fallbackArgs    = " -f \"" + Path.Combine(assemblyFolder, v4lfile) + "\" \"" + Path.Combine(assemblyFolder, "libCameraCaptureV4L.so") + "\"";
                Log.Debug($"{this.GetDomain()} Running: {fallbackCommand}{fallbackArgs}");
                MigService.ShellCommand(fallbackCommand, fallbackArgs);
            }
        }
示例#6
0
        public X10()
        {
            string assemblyFolder = MigService.GetAssemblyDirectory(this.GetType().Assembly);
            var    libusblink     = Path.Combine(assemblyFolder, "libusb-1.0.so");

            // RaspBerry Pi armel dependency check and needed symlink
            if ((File.Exists("/lib/arm-linux-gnueabi/libusb-1.0.so.0.1.0") || File.Exists("/lib/arm-linux-gnueabihf/libusb-1.0.so.0.1.0")) && !File.Exists(libusblink))
            {
                MigService.ShellCommand("ln", " -s \"/lib/arm-linux-gnueabi/libusb-1.0.so.0.1.0\" \"" + libusblink + "\"");
            }
            // Debian/Ubuntu 64bit dependency and needed symlink check
            if (File.Exists("/lib/x86_64-linux-gnu/libusb-1.0.so.0") && !File.Exists(libusblink))
            {
                MigService.ShellCommand("ln", " -s \"/lib/x86_64-linux-gnu/libusb-1.0.so.0\" \"" + libusblink + "\"");
            }

            x10lib = new XTenManager();
            x10lib.ModuleChanged      += X10lib_ModuleChanged;
            x10lib.RfDataReceived     += X10lib_RfDataReceived;
            x10lib.RfSecurityReceived += X10lib_RfSecurityReceived;
            securityModules            = new List <InterfaceModule>();
        }
        public LircRemote()
        {
            assemblyFolder = MigService.GetAssemblyDirectory(this.GetType().Assembly);
            // lirc client lib symlink
            var liblirclink = Path.Combine(assemblyFolder, "liblirc_client.so");

            if (File.Exists("/usr/lib/liblirc_client.so") && !File.Exists(liblirclink))
            {
                MigService.ShellCommand("ln", " -s \"/usr/lib/liblirc_client.so\" \"" + liblirclink + "\"");
            }
            else if (File.Exists("/usr/lib/liblirc_client.so.0") && !File.Exists(liblirclink))
            {
                MigService.ShellCommand("ln", " -s \"/usr/lib/liblirc_client.so.0\" \"" + liblirclink + "\"");
            }
            //
            remotesConfig = new List <LircRemoteData>();
            string configfile = Path.Combine(assemblyFolder, "lircconfig.xml");

            if (File.Exists(configfile))
            {
                var serializer = new XmlSerializer(typeof(List <LircRemoteData>));
                var reader     = new StreamReader(configfile);
                remotesConfig = (List <LircRemoteData>)serializer.Deserialize(reader);
                reader.Close();
            }
            //
            string remotesdb = Path.Combine(assemblyFolder, "lircremotes.xml");

            if (File.Exists(remotesdb))
            {
                var serializer = new XmlSerializer(typeof(List <LircRemoteData>));
                var reader     = new StreamReader(remotesdb);
                remotesData = (List <LircRemoteData>)serializer.Deserialize(reader);
                reader.Close();
            }
        }
示例#8
0
        public object InterfaceControl(MigInterfaceCommand request)
        {
            string response = ""; //default success value

            Commands command;

            Enum.TryParse <Commands>(request.Command.Replace(".", "_"), out command);

            switch (command)
            {
            case Commands.Remotes_Search:
                response = MigService.JsonSerialize(SearchRemotes(request.GetOption(0)));
                break;

            case Commands.Remotes_Add:
            {
                var remote = remotesData.Find(r => r.Manufacturer.ToLower() == request.GetOption(0).ToLower() && r.Model.ToLower() == request.GetOption(1).ToLower());
                if (remote != null && remotesConfig.Find(r => r.Model.ToLower() == remote.Model.ToLower() && r.Manufacturer.ToLower() == remote.Manufacturer.ToLower()) == null)
                {
                    var    webClient = new WebClient();
                    string config    = webClient.DownloadString("http://lirc.sourceforge.net/remotes/" + remote.Manufacturer + "/" + remote.Model);
                    remote.Configuration = GetBytes(config);
                    remotesConfig.Add(remote);
                    SaveConfig();
                }
            }
            break;

            case Commands.Remotes_Remove:
            {
                var remote = remotesConfig.Find(r => r.Manufacturer.ToLower() == request.GetOption(0).ToLower() && r.Model.ToLower() == request.GetOption(1).ToLower());
                if (remote != null)
                {
                    remotesConfig.Remove(remote);
                    SaveConfig();
                }
            }
            break;

            case Commands.Remotes_List:
                response = MigService.JsonSerialize(remotesConfig);
                break;

            case Commands.Control_IrSend:
                string commands = "";
                int    c        = 0;
                while (request.GetOption(c) != "")
                {
                    var options = request.GetOption(c).Split('/');
                    foreach (string o in options)
                    {
                        commands += "\"" + o + "\" ";
                    }
                    c++;
                }
                MigService.ShellCommand("irsend", "SEND_ONCE " + commands);
                break;
            }

            return(response);
        }