Exemplo n.º 1
0
        virtual public void processCode(String commandName, long code, int protocol, int bits)
        {
            if (commandName == null || commandName.Length == 0 || _ignoreCodes.Contains(code) || protocol == (int)IRProtocol.UNKNOWN)
            {
                return;
            }

            IRCode irc = new IRCode();

            if (_irCodes.ContainsKey(commandName))
            {
                //if there is already an ir code for this command then check if the actual code is different
                //from the original then store as an 'unkonwn' code for later inspection
                if (_irCodes[commandName].Code != code)
                {
                    irc.Code            = code;
                    irc.Protocol        = protocol;
                    irc.Bits            = bits;
                    _unknownCodes[code] = irc;
                }
            }
            else
            {
                irc.Code              = code;
                irc.Protocol          = protocol;
                irc.Bits              = bits;
                _irCodes[commandName] = irc;
            }
        }
Exemplo n.º 2
0
        public void WriteIRCodes()
        {
            if (DB == null)
            {
                throw new Exception("No database available");
            }
            WriteDevice();
            if (DBID == 0)
            {
                throw new Exception("No database ID value for device");
            }

            var commandAliases = Chetch.Database.IDMap <String> .Create(DB.SelectCommandAliases(), "command_alias");

            foreach (var kv in _irCodes)
            {
                IRCode irc = kv.Value;

                long caid;
                if (!commandAliases.ContainsKey(kv.Key))
                {
                    caid = DB.InsertCommandAlias(kv.Key);
                }
                else
                {
                    caid = commandAliases[kv.Key].ID;
                }

                try {
                    DB.InsertCommand(DBID, caid, irc.Code, irc.Protocol, irc.Bits);
                } catch (Exception e)
                {
                    //can happen if ir code is a duplicate
                    //Console.WriteLine(e.Message);
                    var row = DB.SelectCommand(DeviceName, kv.Key);
                    if (row == null)
                    {
                        throw e;
                    }
                    long cmdid = row.ID;
                    if (cmdid == 0)
                    {
                        throw new Exception("No ir command code found in database");
                    }
                    DB.UpdateCommand(cmdid, DBID, caid, irc.Code, irc.Protocol, irc.Bits);
                }
            }
        }
Exemplo n.º 3
0
        virtual public void processUnknownCode(String commandName, IRCode irc)
        {
            if (commandName == null || commandName.Length == 0)
            {
                return;
            }

            if (!_irCodes.ContainsKey(commandName))
            {
                _irCodes[commandName] = irc;
            }
            else
            {
                throw new Exception(commandName + " is not unknown");
            }
        }