예제 #1
0
        /// <summary>
        /// Transmit an infrared command.
        /// </summary>
        /// <param name="port">Port to transmit on.</param>
        /// <param name="data">Data to transmit.</param>
        /// <returns><c>true</c> if successful, otherwise <c>false</c>.</returns>
        public bool Transmit(string port, byte[] data)
        {
            string xmlData = Encoding.ASCII.GetString(data);

            GirCommand blastCommand = GirCommand.FromXml(xmlData);

            return(_pluginWrapper.GirEvent(blastCommand, String.Empty, IntPtr.Zero, 0, String.Empty, 0));
        }
        /// <summary>
        /// GirEvent function.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="eventstring">The event string.</param>
        /// <param name="payload">The event payload.</param>
        /// <param name="len">The event payload length.</param>
        /// <param name="status">The event status.</param>
        /// <param name="statuslen">The event status length.</param>
        /// <returns><c>true</c> if successful, otherwise <c>false</c>.</returns>
        public bool GirEvent(GirCommand command, string eventstring, IntPtr payload, int len, string status, int statuslen)
        {
            if (_girEvent != null)
            {
                return(_girEvent(command, eventstring, payload, len, status, statuslen));
            }

            return(false);
        }
        private void set_command(GirCommand command) // GirCommand Ptr?
        {
#if TRACE
            Trace.WriteLine(String.Format("set_command()"));
#endif

            if (_commandSetCallback != null)
            {
                _commandSetCallback(command);
            }
        }
    /// <summary>
    /// Create a new GirCommand from the supplied XML data.
    /// </summary>
    /// <param name="xmlData">The xml data.</param>
    /// <returns>A new GirCommand object.</returns>
    public static GirCommand FromXml(string xmlData)
    {
      GirCommand newCommand = new GirCommand();
      newCommand.critical_section = new Mutex();

      XmlDocument doc = new XmlDocument();
      using (StringReader stringReader = new StringReader(xmlData))
      {
        doc.Load(stringReader);

        try
        {
          newCommand.name = doc.DocumentElement["Command"].Attributes["Name"].Value;
        }
        catch
        {
        }
        try
        {
          newCommand.actiontype = int.Parse(doc.DocumentElement["Command"].Attributes["ActionType"].Value);
        }
        catch
        {
        }
        try
        {
          newCommand.actionsubtype = int.Parse(doc.DocumentElement["Command"].Attributes["ActionSubType"].Value);
        }
        catch
        {
        }

        try
        {
          newCommand.svalue1 = doc.DocumentElement["Command"].Attributes["sValue1"].Value;
        }
        catch
        {
        }
        try
        {
          newCommand.svalue2 = doc.DocumentElement["Command"].Attributes["sValue2"].Value;
        }
        catch
        {
        }
        try
        {
          newCommand.svalue3 = doc.DocumentElement["Command"].Attributes["sValue3"].Value;
        }
        catch
        {
        }

        try
        {
          newCommand.bvalue1 = bool.Parse(doc.DocumentElement["Command"].Attributes["bValue1"].Value);
        }
        catch
        {
        }
        try
        {
          newCommand.bvalue2 = bool.Parse(doc.DocumentElement["Command"].Attributes["bValue2"].Value);
        }
        catch
        {
        }
        try
        {
          newCommand.bvalue3 = bool.Parse(doc.DocumentElement["Command"].Attributes["bValue3"].Value);
        }
        catch
        {
        }

        try
        {
          newCommand.ivalue1 = int.Parse(doc.DocumentElement["Command"].Attributes["iValue1"].Value);
        }
        catch
        {
        }
        try
        {
          newCommand.ivalue2 = int.Parse(doc.DocumentElement["Command"].Attributes["iValue2"].Value);
        }
        catch
        {
        }
        try
        {
          newCommand.ivalue3 = int.Parse(doc.DocumentElement["Command"].Attributes["iValue3"].Value);
        }
        catch
        {
        }

        try
        {
          newCommand.lvalue1 = int.Parse(doc.DocumentElement["Command"].Attributes["lValue1"].Value);
        }
        catch
        {
        }
        try
        {
          newCommand.lvalue2 = int.Parse(doc.DocumentElement["Command"].Attributes["lValue2"].Value);
        }
        catch
        {
        }
        try
        {
          newCommand.lvalue3 = int.Parse(doc.DocumentElement["Command"].Attributes["lValue3"].Value);
        }
        catch
        {
        }
      }

      return newCommand;
    }
    private void target_callback(IntPtr hw, GirCommand command) // GirCommand Ptr?
    {
#if TRACE
      Trace.WriteLine(String.Format("target_callback()"));
#endif
    }
    private void set_command(GirCommand command) // GirCommand Ptr?
    {
#if TRACE
      Trace.WriteLine(String.Format("set_command()"));
#endif

      if (_commandSetCallback != null)
        _commandSetCallback(command);
    }
    /// <summary>
    /// GirEvent function.
    /// </summary>
    /// <param name="command">The command.</param>
    /// <param name="eventstring">The event string.</param>
    /// <param name="payload">The event payload.</param>
    /// <param name="len">The event payload length.</param>
    /// <param name="status">The event status.</param>
    /// <param name="statuslen">The event status length.</param>
    /// <returns><c>true</c> if successful, otherwise <c>false</c>.</returns>
    public bool GirEvent(GirCommand command, string eventstring, IntPtr payload, int len, string status, int statuslen)
    {
      if (_girEvent != null)
        return _girEvent(command, eventstring, payload, len, status, statuslen);

      return false;
    }
        /// <summary>
        /// Create a new GirCommand from the supplied XML data.
        /// </summary>
        /// <param name="xmlData">The xml data.</param>
        /// <returns>A new GirCommand object.</returns>
        public static GirCommand FromXml(string xmlData)
        {
            GirCommand newCommand = new GirCommand();

            newCommand.critical_section = new Mutex();

            XmlDocument doc = new XmlDocument();

            using (StringReader stringReader = new StringReader(xmlData))
            {
                doc.Load(stringReader);

                try
                {
                    newCommand.name = doc.DocumentElement["Command"].Attributes["Name"].Value;
                }
                catch
                {
                }
                try
                {
                    newCommand.actiontype = int.Parse(doc.DocumentElement["Command"].Attributes["ActionType"].Value);
                }
                catch
                {
                }
                try
                {
                    newCommand.actionsubtype = int.Parse(doc.DocumentElement["Command"].Attributes["ActionSubType"].Value);
                }
                catch
                {
                }

                try
                {
                    newCommand.svalue1 = doc.DocumentElement["Command"].Attributes["sValue1"].Value;
                }
                catch
                {
                }
                try
                {
                    newCommand.svalue2 = doc.DocumentElement["Command"].Attributes["sValue2"].Value;
                }
                catch
                {
                }
                try
                {
                    newCommand.svalue3 = doc.DocumentElement["Command"].Attributes["sValue3"].Value;
                }
                catch
                {
                }

                try
                {
                    newCommand.bvalue1 = bool.Parse(doc.DocumentElement["Command"].Attributes["bValue1"].Value);
                }
                catch
                {
                }
                try
                {
                    newCommand.bvalue2 = bool.Parse(doc.DocumentElement["Command"].Attributes["bValue2"].Value);
                }
                catch
                {
                }
                try
                {
                    newCommand.bvalue3 = bool.Parse(doc.DocumentElement["Command"].Attributes["bValue3"].Value);
                }
                catch
                {
                }

                try
                {
                    newCommand.ivalue1 = int.Parse(doc.DocumentElement["Command"].Attributes["iValue1"].Value);
                }
                catch
                {
                }
                try
                {
                    newCommand.ivalue2 = int.Parse(doc.DocumentElement["Command"].Attributes["iValue2"].Value);
                }
                catch
                {
                }
                try
                {
                    newCommand.ivalue3 = int.Parse(doc.DocumentElement["Command"].Attributes["iValue3"].Value);
                }
                catch
                {
                }

                try
                {
                    newCommand.lvalue1 = int.Parse(doc.DocumentElement["Command"].Attributes["lValue1"].Value);
                }
                catch
                {
                }
                try
                {
                    newCommand.lvalue2 = int.Parse(doc.DocumentElement["Command"].Attributes["lValue2"].Value);
                }
                catch
                {
                }
                try
                {
                    newCommand.lvalue3 = int.Parse(doc.DocumentElement["Command"].Attributes["lValue3"].Value);
                }
                catch
                {
                }
            }

            return(newCommand);
        }
        private void target_callback(IntPtr hw, GirCommand command) // GirCommand Ptr?
        {
#if TRACE
            Trace.WriteLine(String.Format("target_callback()"));
#endif
        }