Class Command

All Implemented Interfaces:
Serializable, Named

public final class Command extends XmlExporter implements Named
This class models the command in Girr. A command is essentially an IR signal, given either by protocol/parameters or timing data, and a name.

Some protocols have toggles, a persistent variable that changes between invocations. If a such a protocol is used, there are two cases

  1. It the toggle parameter is explicitly specified, the signal is treated no different from other signals, and no particular treatment of the toggle parameter occurs.
  2. If the toggle parameter is not explicitly specified, the Pronto Hex and the raw versions are computed for all values of the toggle. They can be accessed by the version of the functions getProntoHex, toIrSignal, getIntro, getRepeat, getEnding taking an argument, corresponding to the value of the toggle parameter.

The member functions of class may throw IrpExceptions when they encounter erroneous data. The other classes in the package may not; they should just ignore individual unparseable commands.

See Also:
  • Field Details

    • INITIAL_HASHMAP_CAPACITY

      static final int INITIAL_HASHMAP_CAPACITY
      See Also:
    • TOGGLE_PARAMETER_NAME

      public static final String TOGGLE_PARAMETER_NAME
      Name of the parameter containing the toggle in the IRP protocol.
      See Also:
    • F_PARAMETER_NAME

      public static final String F_PARAMETER_NAME
      Name of the function name parameter.
      See Also:
    • D_PARAMETER_NAME

      public static final String D_PARAMETER_NAME
      Name of the parameter denoting device number.
      See Also:
    • S_PARAMETER_NAME

      public static final String S_PARAMETER_NAME
      Name of the subparameter parameter.
      See Also:
  • Constructor Details

    • Command

      public Command(Element element, String inheritProtocol, Map<String,Long> inheritParameters) throws GirrException
      This constructor is for importing from the Element as first argument, taking the inherited protocol name and parameters, given as parameters, into account.
      Parameters:
      element - of type "command".
      inheritProtocol -
      inheritParameters -
      Throws:
      GirrException
    • Command

      public Command(Element element) throws GirrException
      This constructor is for importing from the Element as first argument.
      Parameters:
      element - of type "command".
      Throws:
      GirrException
    • Command

      public Command(File file) throws GirrException, IOException, SAXException
      This constructor is used to read a Girr file into a Command.
      Parameters:
      file -
      Throws:
      GirrException
      IOException
      SAXException
    • Command

      public Command(Reader reader) throws IOException, SAXException, GirrException
      This constructor is used to read a Reader into a Command.
      Parameters:
      reader -
      Throws:
      GirrException
      IOException
      SAXException
    • Command

      public Command(String name, String comment, org.harctoolbox.ircore.IrSignal irSignal)
      Construct a Command from an IrSignal, i.e. timing data.
      Parameters:
      name - Name of command
      comment - textual comment
      irSignal - IrSignal
    • Command

      public Command(String name, String comment, String protocolName, Map<String,Long> parameters, boolean check) throws GirrException
      Construct a Command from protocolName and parameters.
      Parameters:
      name -
      comment -
      protocolName -
      parameters -
      check - If true, throw GirrException if the projectName cannot be made a protocol.
      Throws:
      GirrException
    • Command

      public Command(String name, String displayName, String comment, Map<String,String> notes, String protocolName, Map<String,Long> parameters, boolean check) throws GirrException
      Construct a Command from protocolName and parameters.
      Parameters:
      name -
      displayName -
      comment -
      notes -
      protocolName -
      parameters -
      check - If true, throw GirrException if the projectName cannot be made a protocol.
      Throws:
      GirrException
    • Command

      public Command(String name, String comment, String protocolName, Map<String,Long> parameters) throws GirrException
      Construct a Command from protocolName and parameters.
      Parameters:
      name -
      comment -
      protocolName -
      parameters -
      Throws:
      GirrException - if the projectName cannot be made a protocol.
    • Command

      public Command(String name, String comment, String prontoHex) throws GirrException
      Construct a Command from Pronto Hex form.
      Parameters:
      name -
      comment -
      prontoHex -
      Throws:
      GirrException
    • Command

      public Command(String name)
      Create an empty command with the given name.
      Parameters:
      name - Name of command.
    • Command

      public Command(String protocolName, Long device, Long subdevice)
    • Command

      public Command()
      Generate an empty command with a dummy name.
  • Method Details

    • setUseInheritanceForXml

      public static void setUseInheritanceForXml(boolean val)
      If set to true, tries to use protocol/parameter inheritance when generating XML code for Commands.
      Parameters:
      val -
    • isUseInheritanceForXml

      public static boolean isUseInheritanceForXml()
    • setAcceptEmptyCommands

      public static void setAcceptEmptyCommands(boolean acceptEmpties)
      If called with argument true, commands without a content, only a name, will be accepted.
      Parameters:
      acceptEmpties -
    • isAcceptEmptyCommands

      public static boolean isAcceptEmptyCommands()
    • setIrpDatabase

      public static void setIrpDatabase(org.harctoolbox.irp.IrpDatabase newIrpDatabase) throws org.harctoolbox.irp.IrpParseException
      Sets an global IrpDatabase instance, which will be used in subsequent transformations from parameter format, and for decodes.
      Parameters:
      newIrpDatabase - IrpDatabase instance
      Throws:
      org.harctoolbox.irp.IrpParseException
    • setDecoderParameters

      public static void setDecoderParameters(org.harctoolbox.irp.Decoder.DecoderParameters newDecoderParameters)
      Sets an global Decoder.DecoderParameters instance, which will be used in subsequent transformations from parameter format, and for decodes.
      Parameters:
      newDecoderParameters -
    • setIrpDatabase

      public static void setIrpDatabase(String irpProtocolsIniPath) throws IOException, org.harctoolbox.irp.IrpParseException, SAXException
      Creates and sets an global IrpDatabase instance, which will be used in subsequent transformations from parameter format, and for decodes.
      Parameters:
      irpProtocolsIniPath - Filename of IrpProtocols.xml
      Throws:
      IOException
      org.harctoolbox.irp.IrpParseException
      SAXException
    • concatenateAsSequence

      public static org.harctoolbox.ircore.ModulatedIrSequence concatenateAsSequence(Collection<Command> commands) throws org.harctoolbox.irp.IrpException, org.harctoolbox.ircore.IrCoreException
      Concatenates the Commands in the argument using IrSignal.toModulatedIrSequence.
      Parameters:
      commands - Collection of Commands to be concatenated.
      Returns:
      ModulatedIrSequence
      Throws:
      org.harctoolbox.ircore.IrCoreException
      org.harctoolbox.irp.IrpException
    • isKnownProtocol

      public static boolean isKnownProtocol(String protocolName)
    • getDutyCycle

      public double getDutyCycle() throws org.harctoolbox.irp.IrpException
      Returns:
      duty cycle, a number between 0 and 1.
      Throws:
      org.harctoolbox.irp.IrpException
    • getComment

      public String getComment()
      Returns:
      the comment
    • getNotes

      public String getNotes(String lang)
      Parameters:
      lang -
      Returns:
      the notes
    • getMasterType

      public Command.MasterType getMasterType()
      Returns:
      the masterType
    • getName

      public String getName()
      Description copied from interface: Named
      Return the name of the object.
      Specified by:
      getName in interface Named
      Returns:
      the name
    • getProtocolName

      public String getProtocolName() throws org.harctoolbox.irp.IrpException, org.harctoolbox.ircore.IrCoreException
      Returns:
      name of the protocol
      Throws:
      org.harctoolbox.ircore.InvalidArgumentException
      org.harctoolbox.irp.IrpException
      org.harctoolbox.ircore.Pronto.NonProntoFormatException
      org.harctoolbox.ircore.IrCoreException
    • getParameters

      public Map<String,Long> getParameters() throws org.harctoolbox.irp.IrpException, org.harctoolbox.ircore.IrCoreException
      Returns:
      the parameters
      Throws:
      org.harctoolbox.irp.IrpException
      org.harctoolbox.ircore.IrCoreException
    • getFrequency

      public double getFrequency() throws org.harctoolbox.irp.IrpException
      Returns:
      the frequency
      Throws:
      org.harctoolbox.irp.IrpException
    • getIntro

      public String getIntro() throws GirrException, org.harctoolbox.ircore.IrCoreException, org.harctoolbox.irp.IrpException
      Returns the first intro sequence. Equivalent to getIntro(0);
      Returns:
      the intro
      Throws:
      GirrException
      org.harctoolbox.ircore.IrCoreException
      org.harctoolbox.irp.IrpException
    • getIntro

      public String getIntro(int T) throws GirrException, org.harctoolbox.ircore.IrCoreException, org.harctoolbox.irp.IrpException
      Parameters:
      T - toggle value
      Returns:
      intro sequence corresponding to T.
      Throws:
      GirrException
      org.harctoolbox.ircore.IrCoreException
      org.harctoolbox.irp.IrpException
    • getRepeat

      public String getRepeat() throws GirrException, org.harctoolbox.ircore.IrCoreException, org.harctoolbox.irp.IrpException
      Returns the first repeat sequence. Equivalent to getRepeat(0);
      Returns:
      the repeat
      Throws:
      GirrException
      org.harctoolbox.ircore.IrCoreException
      org.harctoolbox.irp.IrpException
    • getRepeat

      public String getRepeat(int T) throws GirrException, org.harctoolbox.ircore.IrCoreException, org.harctoolbox.irp.IrpException
      Parameters:
      T - toggle value
      Returns:
      repeat sequence corresponding to T.
      Throws:
      GirrException
      org.harctoolbox.ircore.IrCoreException
      org.harctoolbox.irp.IrpException
    • getEnding

      public String getEnding() throws GirrException, org.harctoolbox.irp.IrpException, org.harctoolbox.ircore.IrCoreException
      Returns the first ending sequence. Equivalent to getEnding(0).
      Returns:
      the ending
      Throws:
      GirrException
      org.harctoolbox.irp.IrpException
      org.harctoolbox.ircore.IrCoreException
    • getEnding

      public String getEnding(int T) throws GirrException, org.harctoolbox.irp.IrpException, org.harctoolbox.ircore.IrCoreException
      Parameters:
      T - toggle value
      Returns:
      ending sequence corresponding to T.
      Throws:
      GirrException
      org.harctoolbox.irp.IrpException
      org.harctoolbox.ircore.IrCoreException
    • getProntoHex

      public String getProntoHex() throws GirrException, org.harctoolbox.irp.IrpException, org.harctoolbox.ircore.IrCoreException
      Returns the Pronto Hex version of the first signal. Equivalent to getProntoHex(0).
      Returns:
      Pronto Hex
      Throws:
      GirrException
      org.harctoolbox.irp.IrpException
      org.harctoolbox.ircore.IrCoreException
    • getProntoHex

      public String getProntoHex(int T) throws GirrException, org.harctoolbox.irp.IrpException, org.harctoolbox.ircore.IrCoreException
      Parameters:
      T - toggle value
      Returns:
      Pronto Hex corresponding to T
      Throws:
      GirrException
      org.harctoolbox.irp.IrpException
      org.harctoolbox.ircore.IrCoreException
    • getOtherFormats

      public Collection<String> getOtherFormats()
      Returns:
      Collection of the otherFormats
    • getFormat

      public String getFormat(String name)
      Returns an "other" format, identified by its name.
      Parameters:
      name - format name
      Returns:
      test string of the format.
    • getDisplayName

      public String getDisplayName()
    • toIrSignal

      public org.harctoolbox.ircore.IrSignal toIrSignal() throws org.harctoolbox.irp.IrpException, org.harctoolbox.ircore.IrCoreException
      Returns the IrSignal of the Command.
      Returns:
      IrSignal
      Throws:
      org.harctoolbox.irp.IrpException
      org.harctoolbox.ircore.IrCoreException
    • toIrSignal

      public org.harctoolbox.ircore.IrSignal toIrSignal(Integer toggle) throws org.harctoolbox.irp.IrpException, org.harctoolbox.ircore.IrCoreException
      Returns the IrSignal of the Command.
      Parameters:
      toggle - toggle value; use null for unspecified.
      Returns:
      IrSignal corresponding to the Command.
      Throws:
      org.harctoolbox.irp.IrpException
      org.harctoolbox.ircore.IrCoreException
    • nameProtocolParameterString

      public String nameProtocolParameterString()
      Returns:
      A "pretty" textual representation of the protocol and the parameters.
    • prettyValueString

      public String prettyValueString()
      Returns:
      Nicely formatted string the way the user would like to see it if truncated to "small" length.
    • toPrintString

      public String toPrintString() throws org.harctoolbox.irp.IrpException, org.harctoolbox.ircore.IrCoreException, GirrException
      Returns:
      Nicely formatted string the way the user would like to see it if truncated to "small" length.
      Throws:
      org.harctoolbox.irp.IrpException
      org.harctoolbox.ircore.IrCoreException
      GirrException
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • checkForParameters

      public void checkForParameters() throws org.harctoolbox.irp.IrpException, org.harctoolbox.ircore.IrCoreException
      Tries to generate the parameter version of the signal (decoding the signals), unless parameters already are present.
      Throws:
      org.harctoolbox.irp.IrpException
      org.harctoolbox.ircore.IrCoreException
    • numberOfToggleValues

      public int numberOfToggleValues()
      Returns the number of possible values of the toggle variable. Must be at least 1. Allowed values for the toggle are 0,...,numberOfToggleValues() - 1.
      Returns:
      the number of possible values.
    • addFormat

      public void addFormat(String name, String value)
      Add another format.
      Parameters:
      name - Name of format.
      value - Text string for value of format.
    • addFormat

      public void addFormat(Command.CommandTextFormat format, int repeatCount) throws org.harctoolbox.irp.IrpException, org.harctoolbox.ircore.IrCoreException
      Add an extra format to the Command.
      Parameters:
      format -
      repeatCount -
      Throws:
      org.harctoolbox.irp.IrpException
      org.harctoolbox.ircore.IrCoreException
    • toElement

      Element toElement(Document doc, boolean fatRaw, boolean generateParameters, boolean generateProntoHex, boolean generateRaw)
      Description copied from class: XmlExporter
      Exports the Object to an Element.
      Specified by:
      toElement in class XmlExporter
      Parameters:
      doc - Owner Document.
      fatRaw - If generating the raw form, generate it in the so-called fat form, with one element per duration.
      generateParameters - If true, generate the parameter form.
      generateProntoHex - If true, generate the Pronto Hex form.
      generateRaw - If true, generate the raw form.
      Returns:
      newly constructed element, belonging to the doc Document.
    • toElement

      Element toElement(Document doc, boolean fatRaw, boolean generateParameters, boolean generateProntoHex, boolean generateRaw, String inheritedProtocolName, Map<String,Long> inheritedParameters)
      XMLExport of the Command.
      Parameters:
      doc -
      fatRaw -
      generateParameters -
      generateProntoHex -
      generateRaw -
      inheritedProtocolName -
      inheritedParameters -
      Returns:
      XML Element with tag name "command".
    • actualMasterType

      Command.MasterType actualMasterType(boolean generateParameters, boolean generateProntoHex, boolean generateRaw)
      Returns the MasterType that is to be used.
      Parameters:
      generateParameters -
      generateProntoHex -
      generateRaw -
      Returns:
      MasterType to be used.
    • strip

      public void strip(Command.MasterType type) throws org.harctoolbox.irp.IrpException, GirrException, org.harctoolbox.ircore.IrCoreException
      Removes the forms different from the one given as argument.
      Parameters:
      type -
      Throws:
      org.harctoolbox.irp.IrpException
      GirrException
      org.harctoolbox.ircore.IrCoreException
    • strip

      public void strip()
      Removes the forms other than the master type of the Command.
    • transform

      public Command transform(String str) throws org.harctoolbox.irp.InvalidNameException, org.harctoolbox.irp.NameUnassignedException, GirrException
      Throws:
      org.harctoolbox.irp.InvalidNameException
      org.harctoolbox.irp.NameUnassignedException
      GirrException
    • transform

      public Command transform(Iterable<org.harctoolbox.irp.Assignment> transformations) throws org.harctoolbox.irp.NameUnassignedException, GirrException
      Throws:
      org.harctoolbox.irp.NameUnassignedException
      GirrException
    • transformParameters

      public Map<String,Long> transformParameters(Iterable<org.harctoolbox.irp.Assignment> transformations) throws org.harctoolbox.irp.NameUnassignedException
      Throws:
      org.harctoolbox.irp.NameUnassignedException