Replies: 12 comments
-
Nice. The best resource is the Javadoc API documentation. There are also some examples here. Let me know if this is helps you. Good luck, |
Beta Was this translation helpful? Give feedback.
-
Thank you for providing some examples, however, those are for decoding. I need to encode, or render, as you call it. Im still struggling to find the solution here. I tried this: public int[] generateIr(String protocolName, int device, int subdevice, int function) {
// Initialize IrpDatabase
IrpDatabase irpDatabase = new IrpDatabase();
// Initialize NameEngine and define parameters
NameEngine nameEngine = new NameEngine();
try {
nameEngine.define("D", (long) device);
nameEngine.define("S", (long) subdevice);
nameEngine.define("F", (long) function);
} catch (InvalidNameException e) {
e.printStackTrace();
// Return an empty array or handle the error as needed
return new int[]{};
}
try {
// Retrieve the NamedProtocol based on the protocol name
NamedProtocol protocol = irpDatabase.getNamedProtocolExpandAlias(protocolName);
if (protocol == null) {
System.err.println("Protocol not found: " + protocolName);
return new int[]{};
}
// Render the IR signal using the protocol and NameEngine
IrSignal irSignal = protocol.render(nameEngine);
// Convert the IrSignal to an int array using toIntArray with a count of 1
// You can adjust the count as needed for multiple repetitions
return irSignal.toIntArray(1);
} catch (UnknownProtocolException e) {
System.err.println("Unknown protocol: " + protocolName);
e.printStackTrace();
} catch (OddSequenceLengthException | DomainViolationException | UnsupportedRepeatException |
IrpInvalidArgumentException | NameUnassignedException e) {
// Handle specific exceptions related to IR signal generation
e.printStackTrace();
} catch (Exception e) {
// Handle any other unforeseen exceptions
e.printStackTrace();
}
// Return an empty array in case of any errors
return new int[]{};
} And now I get a "Unknown Protocol error", from calling
|
Beta Was this translation helpful? Give feedback.
-
Use "NEC1" instead of "NEC". NEC is not considered a render-able protocol, since there is no repeat info; a decode of "NEC" normally is an incomplet learn. IrpProtocols.xml says
|
Beta Was this translation helpful? Give feedback.
-
Yes i had previously tried with NEC1 as well. It also gives the same error Could it be because I am in Android environment, it is not loading the IrpProtocols.xml properly? My current dependencies:
But is the function above correct as far as you can see? |
Beta Was this translation helpful? Give feedback.
-
I have found what the issue is. The XML parsing is not available on Android platform. public int[] generateIr(String protocolName, int device, int subdevice, int function) {
// Initialize IrpDatabase
IrpDatabase irpDatabase;
try {
// Initialize IrpDatabase
irpDatabase = new IrpDatabase((String) null);
} catch (IOException | IrpParseException | SAXException e) {
System.err.println("Error initializing IrpDatabase: " + e.getMessage());
e.printStackTrace();
return new int[]{};
}
// Initialize NameEngine and define parameters
NameEngine nameEngine = new NameEngine();
try {
nameEngine.define("D", (long) device);
nameEngine.define("S", (long) subdevice);
nameEngine.define("F", (long) function);
} catch (InvalidNameException e) {
e.printStackTrace();
// Return an empty array or handle the error as needed
return new int[]{};
}
try {
// Retrieve the NamedProtocol based on the protocol name
NamedProtocol protocol = irpDatabase.getNamedProtocolExpandAlias(protocolName);
if (protocol == null) {
System.err.println("Protocol not found: " + protocolName);
return new int[]{};
}
// Render the IR signal using the protocol and NameEngine
IrSignal irSignal = protocol.render(nameEngine);
// Convert the IrSignal to an int array using toIntArray with a count of 1
// You can adjust the count as needed for multiple repetitions
return irSignal.toIntArray(1);
} catch (UnknownProtocolException e) {
System.err.println("Unknown protocol: " + protocolName);
e.printStackTrace();
} catch (OddSequenceLengthException | DomainViolationException | UnsupportedRepeatException |
IrpInvalidArgumentException | NameUnassignedException e) {
// Handle specific exceptions related to IR signal generation
e.printStackTrace();
} catch (Exception e) {
// Handle any other unforeseen exceptions
e.printStackTrace();
}
// Return an empty array in case of any errors
return new int[]{};
}
So, is there any way to get around this without modifying the library? Thanks |
Beta Was this translation helpful? Give feedback.
-
If "The XML parsing is not available on Android platform" classes like javax.xml.validation.Schema would been missing, not misbehaving. The program would bomb immediately at start complaing about missing classes, instead of IllegalArgumentException. I get the impression that you are not using a debugger... |
Beta Was this translation helpful? Give feedback.
-
Sorry I cannot step line by line inside an external library from Android studio unfortunately. I can give you the full trace
I suspect Android might not include a full implementation of the W3C XML Schema validation (not parsing as I mistakenly said before). What are your thoughts? |
Beta Was this translation helpful? Give feedback.
-
It appears that the SchemaFactory sometimes fails and then throws IllegalArgumentException. I'll see if I can extend the code to take care of this case; stay tuned...
Current is 1.2.13. |
Beta Was this translation helpful? Give feedback.
-
Please try this, |
Beta Was this translation helpful? Give feedback.
-
Did it work for you? Anything else I can do for you? |
Beta Was this translation helpful? Give feedback.
-
Hello again, Sorry for the delayed response, only recently got the chance to try this. I downloaded and tried both: Predictably, the first gives existing the XML parsing error (the SchemaFactory issue). This is after building and trying to run the code for decoding a signal. The second fails even to build in my android environment. I am not sure why, but here is the trace:
Seems to be a NullPointerException in the IrSignal class, in the inner Pass class.
Weirdly, after building it a second time with additional logs, i got a more detailed version of the NullPointerException:
Thank you and I will paitiently await for your response |
Beta Was this translation helpful? Give feedback.
-
Try to download the sources of IrpTransmogrifier, branch |
Beta Was this translation helpful? Give feedback.
-
Hello,
I am trying to incorporate this API into a future open source Android app.
However, because i could not find example code for the API classes and functions, i am having trouble understanding what needs to be called.
What I am trying to do is very simple, its this exact functionality:
./irptransmogrifier.sh render --protocol NEC1 --nameengine "D=12,S=34,F=56" --raw
Freq=38400Hz[9024,4512,564,564,564,564,564,1692,564,1692,564,564,564,564,564,564,564,564,564,564,564,1692,564,564,564,564,564,564,564,1692,564,564,564,564,564,564,564,564,564,564,564,1692,564,1692,564,1692,564,564,564,564,564,1692,564,1692,564,1692,564,564,564,564,564,564,564,1692,564,1692,564,44268][9024,2256,564,96156][]
So all i need is a function that takes in the protocol, device, subdevice and function, and returns the start sequence int array
Could you please help me with this? Or perhaps tell me where I can find examples of API functions?
Thank you,
Luis
Beta Was this translation helpful? Give feedback.
All reactions