use decode_combo in order to fix some memory issue

This commit is contained in:
strawmanbobi
2019-03-04 23:41:33 +08:00
parent 4120da5db2
commit 4ede47f9b1
2 changed files with 98 additions and 57 deletions

View File

@@ -3,6 +3,7 @@ package net.irext.decode.sdk;
import net.irext.decode.sdk.bean.ACStatus; import net.irext.decode.sdk.bean.ACStatus;
import net.irext.decode.sdk.bean.TemperatureRange; import net.irext.decode.sdk.bean.TemperatureRange;
import net.irext.decode.sdk.utils.Constants; import net.irext.decode.sdk.utils.Constants;
import net.irext.decode.service.utils.LoggerUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
@@ -34,6 +35,9 @@ public class IRDecode {
private native void irClose(); private native void irClose();
private native int[] irDecodeCombo(int category, int subCate, byte[] binaries, int binLength,
int keyCode, ACStatus acStatus, int changeWindDirection);
private native TemperatureRange irACGetTemperatureRange(int acMode); private native TemperatureRange irACGetTemperatureRange(int acMode);
private native int irACGetSupportedMode(); private native int irACGetSupportedMode();
@@ -71,13 +75,38 @@ public class IRDecode {
int[] decoded; int[] decoded;
synchronized (mSync) { synchronized (mSync) {
if (null == acStatus) { if (null == acStatus) {
LoggerUtil.getInstance().trace(TAG, "AC Status is null, create a default one");
acStatus = new ACStatus(); acStatus = new ACStatus();
} else {
LoggerUtil.getInstance().trace(TAG, "AC Status = " +
acStatus.getAcPower() + ", " + acStatus.getAcMode() +
", " + acStatus.getAcTemp() + ", " + acStatus.getAcWindSpeed() +
", " + acStatus.getAcWindDir() + ", keyCode = " + keyCode);
} }
decoded = irDecode(keyCode, acStatus, changeWindDir); decoded = irDecode(keyCode, acStatus, changeWindDir);
} }
return decoded; return decoded;
} }
public int[] decodeBinary(int category, int subCate, byte[] binaries, int binLength,
int keyCode, ACStatus acStatus, int changeWindDir) {
int[] decoded;
synchronized (mSync) {
if (null == acStatus) {
LoggerUtil.getInstance().trace(TAG, "AC Status is null, create a default one");
acStatus = new ACStatus();
} else {
LoggerUtil.getInstance().trace(TAG, "AC Status = " +
acStatus.getAcPower() + ", " + acStatus.getAcMode() +
", " + acStatus.getAcTemp() + ", " + acStatus.getAcWindSpeed() +
", " + acStatus.getAcWindDir() + ", keyCode = " + keyCode);
}
decoded = irDecodeCombo(category, subCate, binaries, binLength,
keyCode, acStatus, changeWindDir);
}
return decoded;
}
public void closeBinary() { public void closeBinary() {
irClose(); irClose();
} }

View File

@@ -103,8 +103,9 @@ public class DecodeLogic {
public int[] decode(RemoteIndex remoteIndex, ACStatus acStatus, public int[] decode(RemoteIndex remoteIndex, ACStatus acStatus,
int keyCode, int changeWindDirection) { int keyCode, int changeWindDirection) {
try {
int[] decoded = null; int[] decoded = null;
synchronized(this) { synchronized (this) {
if (null != remoteIndex) { if (null != remoteIndex) {
int categoryId = remoteIndex.getCategoryId(); int categoryId = remoteIndex.getCategoryId();
int subCate = remoteIndex.getSubCate(); int subCate = remoteIndex.getSubCate();
@@ -115,14 +116,22 @@ public class DecodeLogic {
decoded = irDecode.decodeBinary(keyCode, acStatus, changeWindDirection); decoded = irDecode.decodeBinary(keyCode, acStatus, changeWindDirection);
} }
irDecode.closeBinary(); irDecode.closeBinary();
/*
decoded = irDecode.decodeBinary(categoryId, subCate, binaryContent, binaryContent.length,
keyCode, acStatus, changeWindDirection);
*/
return decoded; return decoded;
} }
} }
} catch (Exception ex) {
ex.printStackTrace();
}
return null; return null;
} }
public ACParameters getACParameters(RemoteIndex remoteIndex, int mode) { public ACParameters getACParameters(RemoteIndex remoteIndex, int mode) {
if (null != remoteIndex) { if (null != remoteIndex) {
try {
ACParameters acParameters = new ACParameters(); ACParameters acParameters = new ACParameters();
int categoryId = remoteIndex.getCategoryId(); int categoryId = remoteIndex.getCategoryId();
int subCate = remoteIndex.getSubCate(); int subCate = remoteIndex.getSubCate();
@@ -130,7 +139,7 @@ public class DecodeLogic {
IRDecode irDecode = IRDecode.getInstance(); IRDecode irDecode = IRDecode.getInstance();
int ret = irDecode.openBinary(categoryId, subCate, binaryContent, binaryContent.length); int ret = irDecode.openBinary(categoryId, subCate, binaryContent, binaryContent.length);
if (0 == ret) { if (0 == ret) {
int []supportedModes = irDecode.getACSupportedMode(); int[] supportedModes = irDecode.getACSupportedMode();
if (DEBUG) { if (DEBUG) {
LoggerUtil.getInstance().trace(TAG, "supported modes got : "); LoggerUtil.getInstance().trace(TAG, "supported modes got : ");
@@ -177,6 +186,9 @@ public class DecodeLogic {
} }
irDecode.closeBinary(); irDecode.closeBinary();
return acParameters; return acParameters;
} catch (Exception ex) {
ex.printStackTrace();
}
} }
return null; return null;
} }