Package org.harctoolbox.irp
Class Protocol
java.lang.Object
org.harctoolbox.irp.IrpObject
org.harctoolbox.irp.Protocol
- All Implemented Interfaces:
Serializable
,AggregateLister
,XmlExport
- Direct Known Subclasses:
NamedProtocol
This class implements the Protocol, per Chapter 1.6--1.7.
It essentially consists of the information in the IRP string.
Name and other properties is found in the derived class
NamedProtocol
.- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
This exception is thrown when trying to decode with a Protocol that is not decodeable.static class
This exception is thrown when trying to render with a Protocol that is not renderable. -
Constructor Summary
ConstructorDescriptionProtocol()
Generates an empty protocol.Parses the string given as argument and constructs a Protocol.Protocol
(GeneralSpec generalSpec, BitspecIrstream bitspecIrstream, NameEngine definitions, ParameterSpecs parameterSpecs) Protocol
(GeneralSpec generalSpec, BitspecIrstream bitspecIrstream, NameEngine definitions, ParameterSpecs parameterSpecs, IrpParser.ProtocolContext parseTree) Protocol
(GeneralSpec generalSpec, BitspecIrstream bitspecIrstream, NameEngine definitions, ParameterSpecs parameterSpecs, IrpParser.ProtocolContext parseTree, Class<? extends AbstractDecoder> decoderClass) The general constructor for Protocol.Protocol
(IrpParser.ProtocolContext parseTree) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
checkFrequency
(Double frequency, Decoder.DecoderParameters params) boolean
boolean
void
boolean
fillInDefaults
(Map<String, Long> parameters) Add the missing (= defaulted) parameter in the argument Map.protected double
getIrp()
Returns the IRP as found in the configuration file, including whitespace, comments, and the author's selection of radix.getParameterDefault
(String parameterName) long
getParameterMax
(String parameterName) long
getParameterMin
(String parameterName) double
getUnit()
guessParameterLength
(String name) boolean
int
hashCode()
boolean
boolean
hasParameter
(String name) boolean
hasParameterDefault
(String name) boolean
hasParameterMemory
(String parameterName) boolean
hasVariation
(IrSignal.Pass pass) boolean
boolean
boolean
boolean
boolean
isEmpty
(IrSignal.Pass pass) boolean
isPWM2()
boolean
isPWM4()
boolean
isRPlus()
boolean
A protocol is Sonytype if it is PWM2 with different flashes, and has interleaving flashes.boolean
boolean
isTrivial
(boolean inverted) double
boolean
boolean
normalForm
(IrSignal.Pass pass) normalFormElement
(Document document) normalFormIrpString
(int radix) int
propertiesMap
(GeneralSpec generalSpec, NameEngine nameEngine) randomParameters
(Random random) recognize
(IrSignal irSignal, boolean strict, double frequencyTolerance, double absoluteTolerance, double relativeTolerance, double minimumLeadout) Tries to match the IrSignal in the argument.If it matches, return the matching parametewith the found parameters with their actual values.If no match, throws a SignalRecognitionException.recognize
(IrSignal irSignal, Decoder.DecoderParameters parameters) recognize
(ModulatedIrSequence irSequence, boolean rejectNoRepeats, boolean strict) recognize
(ModulatedIrSequence irSequence, int beginPos, boolean rejectNoRepeats, Decoder.DecoderParameters params) Tries to match the ModulatedIrSequence in the argument, if match, return the matching parameters.void
removeDefaulteds
(Map<String, Long> params) boolean
Returns a Protocol with all of the variables which are constant literals in the Definitions replaced by their values.toIrpString
(int radix) Returns a computed IRP (-segment) string representation of current IrpObject.toIrpString
(int radix, boolean usePeriods) toIrpString
(int radix, boolean usePeriods, boolean tsvOptimized) toIrpString
(int radix, boolean usePeriods, String separator) toIrSignal
(Map<String, Long> params) toIrSignal
(NameEngine nameEngine) Renders the protocol.toModulatedIrSequence
(NameEngine nameEngine, IrSignal.Pass pass) Renders the protocol, but only for the pass given as second argument.org.antlr.v4.gui.TreeViewer
This is sort-of a version of classificationString, but for another audience.int
weight()
Returns a (somewhat arbitrary) measure of the complexity of the object.Methods inherited from class org.harctoolbox.irp.IrpObject
createParameterSpecs, getParseTree, numberOfBitSpecs, prerender, propertiesMap, toDocument, toIrpString, toString, toString, toStringTree, toStringTree, toTreeViewer, toTreeViewer, toTreeViewer, updateStateWhenEntering, updateStateWhenExiting
-
Constructor Details
-
Protocol
public Protocol(GeneralSpec generalSpec, BitspecIrstream bitspecIrstream, NameEngine definitions, ParameterSpecs parameterSpecs) -
Protocol
public Protocol(GeneralSpec generalSpec, BitspecIrstream bitspecIrstream, NameEngine definitions, ParameterSpecs parameterSpecs, IrpParser.ProtocolContext parseTree) -
Protocol
public Protocol(GeneralSpec generalSpec, BitspecIrstream bitspecIrstream, NameEngine definitions, ParameterSpecs parameterSpecs, IrpParser.ProtocolContext parseTree, Class<? extends AbstractDecoder> decoderClass) The general constructor for Protocol.- Parameters:
generalSpec
-bitspecIrstream
-definitions
-parameterSpecs
-parseTree
-decoderClass
-
-
Protocol
public Protocol()Generates an empty protocol. -
Protocol
public Protocol(String irpString) throws UnsupportedRepeatException, NameUnassignedException, InvalidNameException, IrpInvalidArgumentException Parses the string given as argument and constructs a Protocol.- Parameters:
irpString
-- Throws:
InvalidNameException
NameUnassignedException
UnsupportedRepeatException
IrpInvalidArgumentException
-
Protocol
public Protocol(IrpParser.ProtocolContext parseTree) throws UnsupportedRepeatException, NameUnassignedException, InvalidNameException, IrpInvalidArgumentException
-
-
Method Details
-
getDecoderName
-
toStringTree
-
toTreeViewer
public org.antlr.v4.gui.TreeViewer toTreeViewer() -
constantSequence
-
nonEmptySequence
-
constantNonEmptySequence
-
equals
-
hashCode
public int hashCode() -
substituteConstantVariables
Returns a Protocol with all of the variables which are constant literals in the Definitions replaced by their values. Does not change the containing object, but the returned protocol may share some objects with the original protocol.- Returns:
- Protocol.
-
normalFormProtocol
-
normalForm
-
normalBareIrStream
-
isEmpty
-
normalFormIrpString
-
toIrSignal
public IrSignal toIrSignal(NameEngine nameEngine) throws DomainViolationException, NameUnassignedException, IrpInvalidArgumentException, InvalidNameException, OddSequenceLengthException Renders the protocol. Parameter values that are free in the protocol are taken from the NameEngine given as argument.- Parameters:
nameEngine
- containing free names; may be changed in the call- Returns:
- rendered signal
- Throws:
ArithmeticException
NameUnassignedException
IrpInvalidArgumentException
InvalidNameException
OddSequenceLengthException
DomainViolationException
-
toIrSignal
public IrSignal toIrSignal(Map<String, Long> params) throws DomainViolationException, NameUnassignedException, IrpInvalidArgumentException, InvalidNameException, OddSequenceLengthException -
toModulatedIrSequence
public ModulatedIrSequence toModulatedIrSequence(NameEngine nameEngine, IrSignal.Pass pass) throws NameUnassignedException, IrpInvalidArgumentException, OddSequenceLengthException Renders the protocol, but only for the pass given as second argument.- Parameters:
nameEngine
- , NameEngine, may be altered.pass
- intro, repeat, or ending- Returns:
- rendered ModulatedIrSequence
- Throws:
NameUnassignedException
IrpInvalidArgumentException
OddSequenceLengthException
-
numberOfInfiniteRepeats
public int numberOfInfiniteRepeats()- Overrides:
numberOfInfiniteRepeats
in classIrpObject
-
getIrp
Returns the IRP as found in the configuration file, including whitespace, comments, and the author's selection of radix.- Returns:
- IRP string, as formatted iun the configuration file.
- See Also:
-
getBitDirection
-
getFrequency
-
getFrequencyWithDefault
protected double getFrequencyWithDefault() -
getUnit
public double getUnit() -
getDutyCycle
-
isPWM2
public boolean isPWM2() -
isPWM4
public boolean isPWM4() -
isBiphase
public boolean isBiphase() -
isTrivial
public boolean isTrivial(boolean inverted) -
isTrivial
public boolean isTrivial() -
interleavingOk
public boolean interleavingOk() -
interleavingFlashOk
public boolean interleavingFlashOk() -
interleavingGapOk
public boolean interleavingGapOk() -
isSonyType
public boolean isSonyType()A protocol is Sonytype if it is PWM2 with different flashes, and has interleaving flashes.- Returns:
-
isRPlus
public boolean isRPlus() -
startsWithFlash
public boolean startsWithFlash() -
hasVariation
-
hasExtent
public boolean hasExtent() -
getBitspecIrstream
-
toElement
-
normalFormElement
-
toIrpString
Description copied from class:IrpObject
Returns a computed IRP (-segment) string representation of current IrpObject. Numerical parameters, but not durations etc, will be printed using the radix in the argument.- Specified by:
toIrpString
in classIrpObject
- Parameters:
radix
- Radix for parameters.- Returns:
- Formatted string.
-
toIrpString
-
toIrpString
-
toIrpString
-
randomParameters
-
randomParameters
-
recognize
public Map<String,Long> recognize(IrSignal irSignal) throws SignalRecognitionException, Protocol.ProtocolNotDecodableException -
recognize
public Map<String,Long> recognize(IrSignal irSignal, boolean strict) throws SignalRecognitionException, Protocol.ProtocolNotDecodableException -
recognize
public Map<String,Long> recognize(IrSignal irSignal, boolean strict, double frequencyTolerance, double absoluteTolerance, double relativeTolerance, double minimumLeadout) throws SignalRecognitionException, Protocol.ProtocolNotDecodableException Tries to match the IrSignal in the argument.If it matches, return the matching parametewith the found parameters with their actual values.If no match, throws a SignalRecognitionException. If strict == false, allows matching the given intro part as a repeat of the protocol, but no other "creativeness" is used. For example, the IrSignal can not contain more than one rendering of the protocol, and the repeat portion cannot contain more than one rendering of the protocol's repeat.- Parameters:
irSignal
- IrSignal to test against the present protocol.strict
- Do not allow matching intro as repeat.frequencyTolerance
-absoluteTolerance
-relativeTolerance
-minimumLeadout
-- Returns:
- Directory of identified parameters. Never null.
- Throws:
SignalRecognitionException
- if the IrSignal did not match the present protocol.Protocol.ProtocolNotDecodableException
-
recognize
public Map<String,Long> recognize(IrSignal irSignal, Decoder.DecoderParameters parameters) throws SignalRecognitionException, Protocol.ProtocolNotDecodableException -
recognize
public Decoder.Decode recognize(ModulatedIrSequence irSequence, boolean rejectNoRepeats, boolean strict) throws SignalRecognitionException - Throws:
SignalRecognitionException
-
recognize
public Decoder.Decode recognize(ModulatedIrSequence irSequence, int beginPos, boolean rejectNoRepeats, Decoder.DecoderParameters params) throws SignalRecognitionException Tries to match the ModulatedIrSequence in the argument, if match, return the matching parameters. If no match, throws exception. The ModulatedIrSequence should contain intro or (one or many) repeat sequences, and possibly an ending sequence.- Parameters:
irSequence
- ModulatedIrSequence to be matchedbeginPos
- Where the match is supposed to start, normally 0.rejectNoRepeats
- If true, at least one repeat sequence must be matched in the sequence given.params
-- Returns:
- Decoder.Decode object, containing matching data.
- Throws:
SignalRecognitionException
-
checkFrequency
protected void checkFrequency(Double frequency, Decoder.DecoderParameters params) throws SignalRecognitionException - Throws:
SignalRecognitionException
-
weight
public int weight()Description copied from class:IrpObject
Returns a (somewhat arbitrary) measure of the complexity of the object. Can be used for determining if a decode is "simpler" than another decode. -
getGeneralSpec
-
getParameterSpecs
-
sort
-
getDefinitions
- Returns:
- the definitions
-
classificationString
-
warningsString
This is sort-of a version of classificationString, but for another audience.- Returns:
-
warningFrequency
-
warningStartsWithFlash
-
warningTrivialBitspec
-
warningRepeatPlus
-
warningsInterleaving
-
warningNonConstantLengthBitFields
-
warningNoParameterSpecs
-
propertiesMap
- Specified by:
propertiesMap
in interfaceAggregateLister
-
numberOfBits
- Overrides:
numberOfBits
in classIrpObject
-
nonConstantBitFieldLength
public boolean nonConstantBitFieldLength() -
guessParameterLength
-
allDurationsInMicros
-
minDurationDiff
public double minDurationDiff() -
hasParameter
-
hasParameterDefault
-
hasParameterMemory
-
getParameterDefault
-
getParameterMax
-
getParameterMin
-
removeDefaulteds
-
hasNonStandardParameters
public boolean hasNonStandardParameters() -
fillInDefaults
Add the missing (= defaulted) parameter in the argument Map.- Parameters:
parameters
-- Returns:
- Map with missing parameters filled in with their defaults.
- Throws:
NameUnassignedException
- if the defaults cannot be computed due to missing parameters (for example D in NEC1).
-
createParameterSpecsIfPossible
public void createParameterSpecsIfPossible()
-