Page 1 of 1

How to use DecodeIR standalone?

Posted: Sun Sep 16, 2012 3:15 am
by probono
I am working on an Arduino-based protocol analyzer widget that uses DecodeIR to interpret the raw codes.

Hence, I am looking for a way to, on the command line, enter

Code: Select all

decodeir -28394 +8950 -4450 +600 -500 +600 -550 +550 -1650 +600 -500 +550 -550 +600 -550 +600 -500 +550 -600 +550 -1650 +550 -1650 +600 -550 +550 -550 +600 -1600 +600 -1650 +600 -1650 +600 -1600 +550 -600 +550 -550 +600 -1650 +550 -550 +600 -1600 +600 -550 +600 -500 +550 -550 +600 -1600 +600 -1650 +600 -500 +600 -1650 +600 -500 +600 -1650 +600 -1650 +550 -1650 +550 
and get back

Code: Select all

Protocol=NEC  Device=4.243  OBC=20
	IRP form:	{0.0k,msb}<-575u|600u,-500u>(<1:-1|1:-2|1:-3|1:-4>(8945u,-4453u,A:64,552u)){A=$0800A0AA0880A22A}
	Single:	+8950 -4450 +600 -500 +600 -550 +550 -1650 +600 -500 +550 -550 +600 -550 +600 -500 +550 -600 +550 -1650 +550 -1650 +600 -550 +550 -550 +600 -1600 +600 -1650 +600 -1650 +600 -1600 +550 -600 +550 -550 +600 -1650 +550 -550 +600 -1600 +600 -550 +600 -500 +550 -550 +600 -1600 +600 -1650 +600 -500 +600 -1650 +600 -500 +600 -1650 +600 -1650 +550 -1650 +550 -0 
I believe this should be trivial using a tiny C program that uses libdecodeir.so but unfortunately I can't seem to find any C sample code.

Can you please point me toward the correct solution?
Also, it should be possible to call the library from Python using ctypes, if anyone knows how to do that, I'd be very much interested too.

Thanks!

Posted: Sun Sep 16, 2012 5:02 am
by Barf
Hi probono,

Here is what you are looking for. Possibly with the exception that it takes the CCF form as input, not the raw form you are using, modifying it should not present any problem for you. (Note that no-one of the replies understand (or care) for the content of the posting -- what a nice forum :cry: )

You can also use IrpMaster from the command line,

Code: Select all

$ irpmaster --analyze --decodeir --ccf 0000 006C 0022 0002 015B 00AD 0016 0016 0016 0016 0016 0041 0016 0041 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0041 0016 0016 0016 0016 0016 0016 0016 0041 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0041 0016 0041 0016 0041 0016 0016 0016 0016 0016 0041 0016 0041 0016 0041 0016 0016 0016 0016 0016 0016 0016 0041 0016 0041 0016 06A4 015B 0057 0016 0E6C
protocol = NEC1, device = 12, subdevice = 34, obc = 56
AnalyzeIR: {38.4k,573,msb}<1,-1|1,-3>(16,-8,A:32,1,^109m,(16,-4,1,^108m)+){A=0x30441ce3}
(The present version supports only CCF and UEI learned formats, the upcoming 0.2.2 also raw format:)

Code: Select all

java -jar dist/IrpMaster.jar  --decodeir --ccf  +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
protocol = NEC1, device = 12, subdevice = 34, obc = 56

Posted: Sun Sep 16, 2012 5:12 am
by probono
Hi Barf, thanks a lot. Unfortunately I have exactly zero Java skills, so I have to wait until you release your next version that supports raw decoding.

Posted: Sun Sep 16, 2012 5:17 am
by probono
Talking about IrpMaster, I would be very interested in a server-side version of it. Do you know how to do this? Running "java -jar IrpMaster.jar ... " on the server is slow, I am sure there must be a better way?

Posted: Sun Sep 16, 2012 8:13 am
by Barf
probono wrote:... Unfortunately I have exactly zero Java skills, so I have to wait until you release your next version that supports raw decoding.
The first part talked about a main routine in C++, so I do not understand that sentence as it stands.
Talking about IrpMaster, I would be very interested in a server-side version of it.
IrpMaster is first of all a library will reasonably well defined and documented API. That means that you can just "link" with it, see the API example in the documentation and the doc directory. At least as long as you write your program in Java! Writing an "IrpMaster server" would thus essentially be a matter of a few hours for an experienced Java programmer. Since I do not have a particular use case, I do not have it on my TODO-list.But feel free to try to persuade me :wink:

Posted: Sun Sep 16, 2012 8:44 am
by probono
That's probably because I'm a python guy ,-)

About the server, I think it could be very useful to build kind of a wiki for IR codes. People could upload their detected raw codes, they would be decoded and the clean version of the IR code would be displayed. This would also be integrated with a devices database. This way we could build the world's largest IR code database that would grow better and larger than any commercial database.

We would make it very easy to use: no software installation, automatic conversion of the codes into the most common formats. This coupled with very inexpensive and common devices, such as Arduino, should allow for rapid adoption.

One day, we could even design a fully open-source infrared remote control. What do you think?

Posted: Sun Sep 16, 2012 2:43 pm
by Barf
probono wrote:What do you think?
I have written down my thoughts here, which may also be a more appropriate place to take the discussion. After all, this is the forum for getting the maximum out out UEI remotes.

Posted: Sun May 26, 2013 1:03 pm
by probono
For my own reference, this is how it works:

Code: Select all

Generate signals 

ubuntu-gnome@ubuntu-gnome:~/Desktop$ java -jar '/home/ubuntu-gnome/Downloads/IrMaster-bin/lib/IrpMaster.jar' -c /home/ubuntu-gnome/Downloads/IrMaster-bin/IrpProtocols.ini -u -r -n NEC1 0 191 2
Device Code: 0.191 Function: 2
+9024 -4512 +564 -564 +564 -564 +564 -564 +564 -564 +564 -564 +564 -564 +564 -564 +564 -564 +564 -1692 +564 -1692 +564 -1692 +564 -1692 +564 -1692 +564 -1692 +564 -564 +564 -1692 +564 -564 +564 -1692 +564 -564 +564 -564 +564 -564 +564 -564 +564 -564 +564 -564 +564 -1692 +564 -564 +564 -1692 +564 -1692 +564 -1692 +564 -1692 +564 -1692 +564 -1692 +564 -43992
+9024 -2256 +564 -97572
00 00 2F 00 D0 06 11 A0 08 D0 01 1A 01 1A 01 1A 03 4E 01 1A 55 EC 11 A0 04 68 01 1A BE 92 22 01 11 11 11 12 22 22 21 21 21 11 11 12 12 22 22 23 82 45

Decode signals - NEED IrpMaster 0.2.2 WHICH IS INCLUDED IN IrMaster 0.3.1 BINARIES FOR THIS TO WORK!!!

ubuntu-gnome@ubuntu-gnome:~/Desktop$ java -jar IrpMaster.jar  --decodeir --ccf  +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
protocol = NEC1, device = 12, subdevice = 34, obc = 56

Posted: Sat Jun 01, 2013 10:11 am
by probono
And here is my tiny Python wrapper that collects the raw data from the Arduino and decodes it:

Code: Select all

#! /usr/bin/env python

import os, sys, serial, select

port = "/dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_0001-if00-port0"
here = os.path.abspath(os.path.dirname(__file__))

# This is important, otherwise we get no decodes
os.environ['LD_LIBRARY_PATH'] = here + "/IrMaster-bin-0.3.1/Linux-i386/"

class Arduino():
    def run(self, baud=9600):
        try:
            self.ser = serial.Serial(port, baud, timeout=1)
        except:
            print "Could not open the serial port " + port
            sys.exit(1)
        self.ser.flushInput()
        while True :
            inp, outp, err = select.select([sys.stdin, self.ser], [], [], .2)
            if self.ser in inp :
                line = self.ser.readline().strip()
                if("+" in line):
                    command = here + "/jre/bin/java -jar " + here + \
                    "/IrMaster-bin-0.3.1/lib/IrpMaster.jar --decodeir --ccf " + \
                    line + " -43992"
                    # print command
                    os.system(command)
                    
arduino = Arduino()
arduino.run()
If only I could get rid of all the Java overhead just to call that c++ library...

Posted: Sun Jun 02, 2013 10:27 am
by Barf
Hi probono,

congrats to your latest achievements!
If only I could get rid of all the Java overhead just to call that c++ library...
Agreed, it is not sound to call a Java program, firing up the JVM, just to invoke a C++ shared library. But In my first posting, second in the thread, I gave you (in the link) a C++-program that did almost exactly what you asked for, as expressed in the thread title. The only thing you need to do is the fairly trivial conversion from the Pronto type input to raw inputs. That should be quite simple with your programming knowledge. The other direction would be considerably harder.

It should also be possible to call shared libraries directly from Python. I just entered "shared libraries with python" in Google, and got interesting hits.

Posted: Sat Jun 08, 2013 5:41 am
by probono
Thanks Barf. In our link to the C++-program the first thing I had trouble with is the Java stuff in the Makefile. I can't even get this to compile, as it always complains about some JNI stuff I have no real clue about...

Posted: Sat Jun 08, 2013 6:08 am
by Barf
The "Java stuff" is DecodeIR's JNI connection, which we do not need here. You can just comment out/remove everything offending, like the include and all function starting with Java_com_hifiremote_decodeir. Possibly easier, in particular if you are not that familiar with C syntax, would be to install a JDK, Java Developer Kit, after which it should compile.

Posted: Mon Jun 10, 2013 3:48 pm
by probono
Thanks Barf, removing everything related to Java and Windows indeed did the trick for me. I now have a tiny Linux decodeir executable. If anyone else is interested, I have uploaded the modified source to https://github.com/probonopd/decodeir