Package org.harctoolbox.girr
Class Command
java.lang.Object
org.harctoolbox.girr.XmlExporter
org.harctoolbox.girr.Command
- All Implemented Interfaces:
Serializable
,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
- 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.
- 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:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
An implementation of this interface describes a way to format an IrSignal to a text string.static enum
This describes which representation of a Command constitutes the master, from which the other representations are derived.Nested classes/interfaces inherited from interface org.harctoolbox.girr.Named
Named.CompareNameCaseInsensitive, Named.CompareNameCaseSensitive
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Name of the parameter denoting device number.static final String
Name of the function name parameter.(package private) static final int
static final String
Name of the subparameter parameter.static final String
Name of the parameter containing the toggle in the IRP protocol. -
Constructor Summary
ConstructorDescriptionCommand()
Generate an empty command with a dummy name.This constructor is used to read a Girr file into a Command.This constructor is used to read a Reader into a Command.Create an empty command with the given name.Construct a Command from Pronto Hex form.Construct a Command from protocolName and parameters.Command
(String name, String comment, String protocolName, Map<String, Long> parameters, boolean check) Construct a Command from protocolName and parameters.Command
(String name, String displayName, String comment, Map<String, String> notes, String protocolName, Map<String, Long> parameters, boolean check) Construct a Command from protocolName and parameters.Construct a Command from an IrSignal, i.e. timing data.This constructor is for importing from the Element as first argument.This constructor is for importing from the Element as first argument, taking the inherited protocol name and parameters, given as parameters, into account. -
Method Summary
Modifier and TypeMethodDescription(package private) Command.MasterType
actualMasterType
(boolean generateParameters, boolean generateProntoHex, boolean generateRaw) Returns the MasterType that is to be used.void
Add another format.void
addFormat
(Command.CommandTextFormat format, int repeatCount) Add an extra format to the Command.void
Tries to generate the parameter version of the signal (decoding the signals), unless parameters already are present.static org.harctoolbox.ircore.ModulatedIrSequence
concatenateAsSequence
(Collection<Command> commands) Concatenates the Commands in the argument using IrSignal.toModulatedIrSequence.double
Returns the first ending sequence.getEnding
(int T) Returns an "other" format, identified by its name.double
getIntro()
Returns the first intro sequence.getIntro
(int T) getName()
Return the name of the object.Returns the Pronto Hex version of the first signal.getProntoHex
(int T) Returns the first repeat sequence.getRepeat
(int T) static boolean
static boolean
isKnownProtocol
(String protocolName) static boolean
int
Returns the number of possible values of the toggle variable.static void
setAcceptEmptyCommands
(boolean acceptEmpties) If called with argument true, commands without a content, only a name, will be accepted.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.static void
setIrpDatabase
(String irpProtocolsIniPath) Creates and sets an global IrpDatabase instance, which will be used in subsequent transformations from parameter format, and for decodes.static void
setIrpDatabase
(org.harctoolbox.irp.IrpDatabase newIrpDatabase) Sets an global IrpDatabase instance, which will be used in subsequent transformations from parameter format, and for decodes.static void
setUseInheritanceForXml
(boolean val) If set to true, tries to use protocol/parameter inheritance when generating XML code for Commands.void
strip()
Removes the forms other than the master type of the Command.void
strip
(Command.MasterType type) Removes the forms different from the one given as argument.(package private) Element
toElement
(Document doc, boolean fatRaw, boolean generateParameters, boolean generateProntoHex, boolean generateRaw) Exports the Object to an Element.(package private) Element
toElement
(Document doc, boolean fatRaw, boolean generateParameters, boolean generateProntoHex, boolean generateRaw, String inheritedProtocolName, Map<String, Long> inheritedParameters) XMLExport of the Command.org.harctoolbox.ircore.IrSignal
Returns the IrSignal of the Command.org.harctoolbox.ircore.IrSignal
toIrSignal
(Integer toggle) Returns the IrSignal of the Command.toString()
transformParameters
(Iterable<org.harctoolbox.irp.Assignment> transformations) Methods inherited from class org.harctoolbox.girr.XmlExporter
getElement, getElement, getElement, getElement, getElement, getElement, getElement, print, print, print, print, print, toDocument
-
Field Details
-
INITIAL_HASHMAP_CAPACITY
static final int INITIAL_HASHMAP_CAPACITY- See Also:
-
TOGGLE_PARAMETER_NAME
Name of the parameter containing the toggle in the IRP protocol.- See Also:
-
F_PARAMETER_NAME
Name of the function name parameter.- See Also:
-
D_PARAMETER_NAME
Name of the parameter denoting device number.- See Also:
-
S_PARAMETER_NAME
Name of the subparameter parameter.- See Also:
-
-
Constructor Details
-
Command
public Command(Element element, String inheritProtocol, Map<String, Long> inheritParameters) throws GirrExceptionThis 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
This constructor is for importing from the Element as first argument.- Parameters:
element
- of type "command".- Throws:
GirrException
-
Command
This constructor is used to read a Girr file into a Command.- Parameters:
file
-- Throws:
GirrException
IOException
SAXException
-
Command
This constructor is used to read a Reader into a Command.- Parameters:
reader
-- Throws:
GirrException
IOException
SAXException
-
Command
Construct a Command from an IrSignal, i.e. timing data.- Parameters:
name
- Name of commandcomment
- textual commentirSignal
- IrSignal
-
Command
public Command(String name, String comment, String protocolName, Map<String, Long> parameters, boolean check) throws GirrExceptionConstruct 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, throws GirrExceptionLong> parameters, boolean check) 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 GirrExceptionConstruct a Command from protocolName and parameters.- Parameters:
name
-comment
-protocolName
-parameters
-- Throws:
GirrException
- if the projectName cannot be made a protocol.
-
Command
Construct a Command from Pronto Hex form.- Parameters:
name
-comment
-prontoHex
-- Throws:
GirrException
-
Command
Create an empty command with the given name.- Parameters:
name
- Name of command.
-
Command
-
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
-
getDutyCycle
public double getDutyCycle() throws org.harctoolbox.irp.IrpException- Returns:
- duty cycle, a number between 0 and 1.
- Throws:
org.harctoolbox.irp.IrpException
-
getComment
- Returns:
- the comment
-
getNotes
- Parameters:
lang
-- Returns:
- the notes
-
getMasterType
- Returns:
- the masterType
-
getName
Description copied from interface:Named
Return the name of the object. -
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.IrpExceptionReturns 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.IrpExceptionReturns 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.IrCoreExceptionReturns 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.IrCoreExceptionReturns 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
- Returns:
- Collection of the otherFormats
-
getFormat
Returns an "other" format, identified by its name.- Parameters:
name
- format name- Returns:
- test string of the format.
-
getDisplayName
-
toIrSignal
public org.harctoolbox.ircore.IrSignal toIrSignal() throws org.harctoolbox.irp.IrpException, org.harctoolbox.ircore.IrCoreExceptionReturns 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
- Returns:
- A "pretty" textual representation of the protocol and the parameters.
-
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
-
checkForParameters
public void checkForParameters() throws org.harctoolbox.irp.IrpException, org.harctoolbox.ircore.IrCoreExceptionTries 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
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 classXmlExporter
- 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
-