fixed decode algorithm for win and android jni

This commit is contained in:
2017-05-08 21:59:22 +08:00
parent 9ce38f3056
commit 18f75a2635
3 changed files with 62 additions and 159 deletions

View File

@@ -2,19 +2,13 @@ LIBRARY
EXPORTS EXPORTS
ir_ac_file_open @1 ir_file_open @1
ir_ac_lib_open @2 ir_binary_open @2
ir_ac_lib_parse @3 ir_decode @3
ir_ac_lib_control @4 ir_close @4
ir_ac_lib_close @5
ir_tv_file_open @6 get_temperature_range @5
ir_tv_lib_open @7 get_supported_mode @6
ir_tv_lib_parse @8 get_supported_wind_speed @7
ir_tv_lib_control @9 get_supported_swing @8
ir_tv_lib_close @19 get_supported_wind_direction @9
get_temperature_range @11
get_supported_mode @12
get_supported_wind_speed @13
get_supported_swing @14
get_supported_wind_direction @15

View File

@@ -20,20 +20,13 @@ Revision log:
extern size_t binary_length; extern size_t binary_length;
extern UINT8 *binary_content; extern UINT8 *binary_content;
JNIEXPORT jint JNICALL Java_net_irext_decodesdk_IRDecode_irACLibOpen JNIEXPORT jint JNICALL Java_net_irext_decodesdk_IRDecode_irOpen
(JNIEnv *env, jobject this_obj, jstring file_name) (JNIEnv *env, jobject this_obj, jint category_id, jint sub_cate, jstring file_name)
{ {
const char *n_file_name = (*env)->GetStringUTFChars(env, file_name, 0); const char *n_file_name = (*env)->GetStringUTFChars(env, file_name, 0);
if (IR_DECODE_FAILED == ir_ac_file_open(n_file_name)) if (IR_DECODE_FAILED == ir_file_open(category_id, sub_cate, n_file_name))
{ {
ir_ac_lib_close(); ir_close();
(*env)->ReleaseStringUTFChars(env, file_name, n_file_name);
return IR_DECODE_FAILED;
}
if (IR_DECODE_FAILED == ir_ac_lib_parse())
{
ir_ac_lib_close();
(*env)->ReleaseStringUTFChars(env, file_name, n_file_name); (*env)->ReleaseStringUTFChars(env, file_name, n_file_name);
return IR_DECODE_FAILED; return IR_DECODE_FAILED;
} }
@@ -42,8 +35,8 @@ JNIEXPORT jint JNICALL Java_net_irext_decodesdk_IRDecode_irACLibOpen
return IR_DECODE_SUCCEEDED; return IR_DECODE_SUCCEEDED;
} }
JNIEXPORT jintArray JNICALL Java_net_irext_decodesdk_IRDecode_irACControl JNIEXPORT jintArray JNICALL Java_net_irext_decodesdk_IRDecode_irDecode
(JNIEnv *env, jobject this_obj, jobject jni_ac_status, jint function_code, jint change_wind_direction) (JNIEnv *env, jobject this_obj, jint key_code, jobject jni_ac_status, jint change_wind_direction)
{ {
UINT16 user_data[USER_DATA_SIZE]; UINT16 user_data[USER_DATA_SIZE];
int i = 0; int i = 0;
@@ -51,41 +44,35 @@ JNIEXPORT jintArray JNICALL Java_net_irext_decodesdk_IRDecode_irACControl
remote_ac_status_t ac_status; remote_ac_status_t ac_status;
jclass n_ac_status = (*env)->GetObjectClass(env, jni_ac_status); jclass n_ac_status = (*env)->GetObjectClass(env, jni_ac_status);
jfieldID ac_power_fid = (*env)->GetFieldID(env, n_ac_status, "acPower", "I");
jint i_ac_power = (*env)->GetIntField(env, jni_ac_status, ac_power_fid);
jfieldID ac_mode_fid = (*env)->GetFieldID(env, n_ac_status, "acMode", "I"); if (NULL != n_ac_status)
jint i_ac_mode = (*env)->GetIntField(env, jni_ac_status, ac_mode_fid); {
jfieldID ac_power_fid = (*env)->GetFieldID(env, n_ac_status, "acPower", "I");
jint i_ac_power = (*env)->GetIntField(env, jni_ac_status, ac_power_fid);
jfieldID ac_temp_fid = (*env)->GetFieldID(env, n_ac_status, "acTemp", "I"); jfieldID ac_mode_fid = (*env)->GetFieldID(env, n_ac_status, "acMode", "I");
jint i_ac_temp = (*env)->GetIntField(env, jni_ac_status, ac_temp_fid); jint i_ac_mode = (*env)->GetIntField(env, jni_ac_status, ac_mode_fid);
jfieldID ac_wind_dir_fid = (*env)->GetFieldID(env, n_ac_status, "acWindDir", "I"); jfieldID ac_temp_fid = (*env)->GetFieldID(env, n_ac_status, "acTemp", "I");
jint i_ac_wind_dir = (*env)->GetIntField(env, jni_ac_status, ac_wind_dir_fid); jint i_ac_temp = (*env)->GetIntField(env, jni_ac_status, ac_temp_fid);
jfieldID ac_wind_speed_fid = (*env)->GetFieldID(env, n_ac_status, "acWindSpeed", "I"); jfieldID ac_wind_dir_fid = (*env)->GetFieldID(env, n_ac_status, "acWindDir", "I");
jint i_ac_wind_speed = (*env)->GetIntField(env, jni_ac_status, ac_wind_speed_fid); jint i_ac_wind_dir = (*env)->GetIntField(env, jni_ac_status, ac_wind_dir_fid);
ir_printf("\nget ac status : %d, %d, %d, %d, %d, %d\n", jfieldID ac_wind_speed_fid = (*env)->GetFieldID(env, n_ac_status, "acWindSpeed", "I");
i_ac_power, jint i_ac_wind_speed = (*env)->GetIntField(env, jni_ac_status, ac_wind_speed_fid);
i_ac_mode,
i_ac_temp, ac_status.acDisplay = 0;
i_ac_wind_dir, ac_status.acSleep = 0;
i_ac_wind_speed, ac_status.acTimer = 0;
function_code); ac_status.acPower = i_ac_power;
ac_status.acMode = i_ac_mode;
ac_status.acTemp = i_ac_temp;
ac_status.acWindDir = i_ac_wind_dir;
ac_status.acWindSpeed = i_ac_wind_speed;
}
ac_status.acDisplay = 0; int wave_code_length = ir_decode(key_code, user_data, &ac_status, change_wind_direction);
ac_status.acSleep = 0;
ac_status.acTimer = 0;
ac_status.acPower = i_ac_power;
ac_status.acMode = i_ac_mode;
ac_status.acTemp = i_ac_temp;
ac_status.acWindDir = i_ac_wind_dir;
ac_status.acWindSpeed = i_ac_wind_speed;
int wave_code_length = ir_ac_lib_control(ac_status, user_data, function_code, change_wind_direction);
ir_printf("\nsize of wave code = %d\n", wave_code_length);
jintArray result = (*env)->NewIntArray(env, wave_code_length); jintArray result = (*env)->NewIntArray(env, wave_code_length);
if (result == NULL) if (result == NULL)
@@ -97,17 +84,15 @@ JNIEXPORT jintArray JNICALL Java_net_irext_decodesdk_IRDecode_irACControl
copy_array[i] = (int)user_data[i]; copy_array[i] = (int)user_data[i];
} }
(*env)->SetIntArrayRegion(env, result, 0, wave_code_length, copy_array); (*env)->SetIntArrayRegion(env, result, 0, wave_code_length, copy_array);
(*env)->DeleteLocalRef(env, n_ac_status);
// temporary solution, close ac lib here in order to release memory
// ir_ac_lib_close();
return result; return result;
} }
JNIEXPORT void JNICALL Java_net_irext_decodesdk_IRDecode_irACLibClose JNIEXPORT void JNICALL Java_net_irext_decodesdk_IRDecode_irClose
(JNIEnv *env, jobject this_obj) (JNIEnv *env, jobject this_obj)
{ {
ir_ac_lib_close(); ir_close();
} }
JNIEXPORT jobject JNICALL Java_net_irext_decodesdk_IRDecode_irACGetTemperatureRange JNIEXPORT jobject JNICALL Java_net_irext_decodesdk_IRDecode_irACGetTemperatureRange
@@ -162,56 +147,4 @@ JNIEXPORT jint JNICALL Java_net_irext_decodesdk_IRDecode_irACGetSupportedWindDir
int supported_wind_direction = 0; int supported_wind_direction = 0;
get_supported_wind_direction((UINT8*)&supported_wind_direction); get_supported_wind_direction((UINT8*)&supported_wind_direction);
return supported_wind_direction; return supported_wind_direction;
}
JNIEXPORT jint JNICALL Java_net_irext_decodesdk_IRDecode_irTVLibOpen
(JNIEnv *env, jobject this_obj, jstring file_name, jint j_ir_hex_encode)
{
const char *n_file_name = (*env)->GetStringUTFChars(env, file_name, 0);
if (IR_DECODE_FAILED == ir_tv_file_open(n_file_name))
{
(*env)->ReleaseStringUTFChars(env, file_name, n_file_name);
return IR_DECODE_FAILED;
}
if (IR_DECODE_FAILED == ir_tv_lib_parse(j_ir_hex_encode))
{
(*env)->ReleaseStringUTFChars(env, file_name, n_file_name);
return IR_DECODE_FAILED;
}
(*env)->ReleaseStringUTFChars(env, file_name, n_file_name);
return IR_DECODE_SUCCEEDED;
}
JNIEXPORT jintArray JNICALL Java_net_irext_decodesdk_IRDecode_irTVControl
(JNIEnv *env, jobject this_obj, jint key_number)
{
UINT16 user_data[USER_DATA_SIZE];
int i = 0;
int copy_array[USER_DATA_SIZE] = {0};
int wave_code_length = ir_tv_lib_control(key_number, user_data);
ir_printf("\nsize of wave code = %d\n", wave_code_length);
jintArray result = (*env)->NewIntArray(env, wave_code_length);
if (result == NULL)
{
return NULL; /* out of memory error thrown */
}
for (i = 0; i < wave_code_length; i++)
{
copy_array[i] = (int)user_data[i];
}
(*env)->SetIntArrayRegion(env, result, 0, wave_code_length, copy_array);
return result;
}
JNIEXPORT void JNICALL Java_net_irext_decodesdk_IRDecode_irTVLibClose
(JNIEnv *env, jobject this_obj)
{
// do nothing
return;
} }

View File

@@ -1,9 +1,9 @@
/* DO NOT EDIT THIS FILE - it is machine generated */ /* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h> #include <jni.h>
/* Header for class net_irext_remote_service_DecodeService */ /* Header for class net_irext_decodesdk_IRDecode */
#ifndef _Included_net_irext_remote_service_DecodeService #ifndef _Included_net_irext_decodesdk_IRDecode
#define _Included_net_irext_remote_service_DecodeService #define _Included_net_irext_decodesdk_IRDecode
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@@ -56,39 +56,39 @@ extern "C" {
#undef net_irext_decodesdk_IRDecode_START_STICKY_COMPATIBILITY #undef net_irext_decodesdk_IRDecode_START_STICKY_COMPATIBILITY
#define net_irext_decodesdk_IRDecode_START_STICKY_COMPATIBILITY 0L #define net_irext_decodesdk_IRDecode_START_STICKY_COMPATIBILITY 0L
/* /*
* Class: net_irext_remote_service_DecodeService * Class: net_irext_decodesdk_IRDecode
* Method: irACLibOpen * Method: irOpen
* Signature: (Ljava/lang/String;)I * Signature: II(Ljava/lang/String;)
*/ */
JNIEXPORT jint JNICALL Java_net_irext_decodesdk_IRDecode_irACLibOpen JNIEXPORT jint JNICALL Java_net_irext_decodesdk_IRDecode_irOpen
(JNIEnv *, jobject, jstring); (JNIEnv *, jobject, jint, jint, jstring);
/* /*
* Class: net_irext_remote_service_DecodeService * Class: net_irext_decodesdk_IRDecode
* Method: irACControl * Method: irDecode
* Signature: (Lcom/irext/remote/bean/jnibean/JNIACStatus;II)[I * Signature: I(Lnet/irext/decodesdk/bean/ACStatus;I)[I
*/ */
JNIEXPORT jintArray JNICALL Java_net_irext_decodesdk_IRDecode_irACControl JNIEXPORT jintArray JNICALL Java_net_irext_decodesdk_IRDecode_irDecode
(JNIEnv *, jobject, jobject, jint, jint); (JNIEnv *, jobject, jint, jobject, jint);
/* /*
* Class: net_irext_remote_service_DecodeService * Class: net_irext_decodesdk_IRDecode
* Method: irACLibClose * Method: irClose
* Signature: ()V * Signature: ()V
*/ */
JNIEXPORT void JNICALL Java_net_irext_decodesdk_IRDecode_irACLibClose JNIEXPORT void JNICALL Java_net_irext_decodesdk_IRDecode_irACLibClose
(JNIEnv *, jobject); (JNIEnv *, jobject);
/* /*
* Class: net_irext_remote_service_DecodeService * Class: net_irext_decodesdk_IRDecode
* Method: irACGetTemperatureRange * Method: irACGetTemperatureRange
* Signature: (I)Lcom/irext/remote/bean/jnibean/JNITemperatureRange; * Signature: (I)Lcom/irext/remote/bean/jnibean/TemperatureRange;
*/ */
JNIEXPORT jobject JNICALL Java_net_irext_decodesdk_IRDecode_irACGetTemperatureRange JNIEXPORT jobject JNICALL Java_net_irext_decodesdk_IRDecode_irACGetTemperatureRange
(JNIEnv *, jobject, jint); (JNIEnv *, jobject, jint);
/* /*
* Class: net_irext_remote_service_DecodeService * Class: net_irext_decodesdk_IRDecode
* Method: irACGetSupportedMode * Method: irACGetSupportedMode
* Signature: ()I * Signature: ()I
*/ */
@@ -96,7 +96,7 @@ JNIEXPORT jint JNICALL Java_net_irext_decodesdk_IRDecode_irACGetSupportedMode
(JNIEnv *, jobject); (JNIEnv *, jobject);
/* /*
* Class: net_irext_remote_service_DecodeService * Class: net_irext_decodesdk_IRDecode
* Method: irACGetSupportedWindSpeed * Method: irACGetSupportedWindSpeed
* Signature: (I)I * Signature: (I)I
*/ */
@@ -104,7 +104,7 @@ JNIEXPORT jint JNICALL Java_net_irext_decodesdk_IRDecode_irACGetSupportedWindSpe
(JNIEnv *, jobject, jint); (JNIEnv *, jobject, jint);
/* /*
* Class: net_irext_remote_service_DecodeService * Class: net_irext_decodesdk_IRDecode
* Method: irACGetSupportedSwing * Method: irACGetSupportedSwing
* Signature: (I)I * Signature: (I)I
*/ */
@@ -112,37 +112,13 @@ JNIEXPORT jint JNICALL Java_net_irext_decodesdk_IRDecode_irACGetSupportedSwing
(JNIEnv *, jobject, jint); (JNIEnv *, jobject, jint);
/* /*
* Class: net_irext_remote_service_DecodeService * Class: net_irext_decodesdk_IRDecode
* Method: irACGetSupportedWindDirection * Method: irACGetSupportedWindDirection
* Signature: ()I * Signature: ()I
*/ */
JNIEXPORT jint JNICALL Java_net_irext_decodesdk_IRDecode_irACGetSupportedWindDirection JNIEXPORT jint JNICALL Java_net_irext_decodesdk_IRDecode_irACGetSupportedWindDirection
(JNIEnv *, jobject); (JNIEnv *, jobject);
/*
* Class: net_irext_remote_service_DecodeService
* Method: irTVLibOpen
* Signature: (Ljava/lang/String;I)I
*/
JNIEXPORT jint JNICALL Java_net_irext_decodesdk_IRDecode_irTVLibOpen
(JNIEnv *, jobject, jstring, jint);
/*
* Class: net_irext_remote_service_DecodeService
* Method: irTVControl
* Signature: (I)[I
*/
JNIEXPORT jintArray JNICALL Java_net_irext_decodesdk_IRDecode_irTVControl
(JNIEnv *, jobject, jint);
/*
* Class: net_irext_remote_service_DecodeService
* Method: irTVLibClose
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_net_irext_decodesdk_IRDecode_irTVLibClose
(JNIEnv *, jobject);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif