A main routine for DecodeIR
Posted: Sun Mar 14, 2010 2:47 pm
On fixing the Nokia12 bug in DecodeIR, I wrote a main routine, which possibly can be of use for other people fumbling around with DecodeIR. So I publish it here as a diff to the 2.40 sources. To compile define the preprocessor symbol MAIN and leave out the options for generating a shared object. Thus a command line program will be produced, that takes a signal in Pronto format as its argument. This is the Makefile I used:
I have only tested with Linux, however there should be absolutely nothing system dependent, so it should work also on other systems.
Code: Select all
NAME=DecodeIR
#INCLUDES=-I/usr/lib/jvm/java-6-sun/include -I/usr/lib/jvm/java-6-sun/include/linux -Icom/hifiremote/decodeir
INCLUDES=-Icom/hifiremote/decodeir
all: lib$(NAME).so
clean:
rm lib$(NAME).so
lib$(NAME).so: $(NAME).cpp
g++ -fPIC -shared -o $@ $(INCLUDES) $?
prog: $(NAME).cpp
g++ -DMAIN -o $@ $(INCLUDES) $<
install:
install lib$(NAME).so /usr/local/lib
# Nokia12 1 123
test: prog
./prog 0000 0073 0000 0008 000f 000a 0006 000a 0006 0010 0006 0010 0006 001c 0006 0016 0006 001c 0006 0fd2
Code: Select all
*** DecodeIR.cpp.orig Sun Mar 14 18:29:52 2010
--- DecodeIR.cpp Sun Mar 14 21:34:18 2010
***************
*** 17,22 ****
--- 17,25 ----
#include "JNIUtil.h"
#endif
+ #ifdef MAIN
+ #include <iostream>
+ #endif
static char const version_cstr[]="2.40"; // Version 2.40 by GD 2010
***************
*** 5570,5572 ****
--- 5573,5635 ----
&& JNU_SetString(env, obj, "miscMessage", TsMisc)
&& JNU_SetString(env, obj, "errorMessage", TsError);
}
+
+ #ifdef MAIN
+ #ifndef linux
+ #error this has not been tested outside of Linux. Feel free to do so, however.
+ #endif
+ int main(int argc, char* argv[])
+ {
+ unsigned int i = 1;
+ int type;
+ sscanf(argv[i++], "%x", &type);
+ if (type != 0)
+ {
+ std::cerr << "Can only handle type 0000\n";
+ exit(1);
+ }
+ int fcode;
+ sscanf(argv[i++], "%x", &fcode);
+ int frequency = (int) (1000000.0/((double)fcode * 0.241246));
+ int intro_length, rep_length;
+ sscanf(argv[i++], "%x", &intro_length);
+ sscanf(argv[i++], "%x", &rep_length);
+
+ int *data = new int[2*(intro_length+rep_length)];
+ for (int j = 0; j < 2*(intro_length+rep_length); j++)
+ {
+ int ncycles;
+ sscanf(argv[i++], "%x", &ncycles);
+ data[j] = (int)(1000000.0/frequency*ncycles);
+ }
+ unsigned int decodeir_context[2] = { 0, 0};
+ char protocol[255] = "";
+ int device = -1;
+ int subdevice = -1;
+ int obc = -1;
+ int hex[4] = { -1, -1, -1, -1};
+ char misc_message[255] = "";
+ char error_message[255] = "";
+
+ do
+ {
+ DecodeIR(decodeir_context, data, frequency, intro_length, rep_length,
+ protocol, &device, &subdevice, &obc, hex, misc_message,
+ error_message);
+
+ if (protocol[0] != '\0')
+ std::cout
+ << "protocol=" << protocol
+ << " device=" << device
+ << " subdevice=" << subdevice
+ << " obc=" << obc
+ << " hex0=" << hex[0]
+ << " hex1=" << hex[1]
+ << " hex2=" << hex[2]
+ << " hex3=" << hex[3]
+ << " misc=" << misc_message
+ << " error=" << error_message << "\n";
+ }
+ while (protocol[0] != '\0');
+ }
+ #endif