implemented AC parameters query

This commit is contained in:
strawmanbobi
2019-02-15 19:41:48 +08:00
parent 106b4b8e58
commit 942ae8dba2
6 changed files with 251 additions and 36 deletions

View File

@@ -1,8 +1,10 @@
package net.irext.decode.service.businesslogic;
import com.squareup.okhttp.*;
import net.irext.decode.sdk.bean.TemperatureRange;
import net.irext.decode.service.cache.IDecodeSessionRepository;
import net.irext.decode.service.cache.IIRBinaryRepository;
import net.irext.decode.service.model.ACParameters;
import net.irext.decode.service.model.RemoteIndex;
import net.irext.decode.service.utils.FileUtil;
import net.irext.decode.service.utils.LoggerUtil;
@@ -28,6 +30,7 @@ import java.security.MessageDigest;
* Revision log:
* 2018-12-08: created by strawmanbobi
*/
@SuppressWarnings("Duplicates")
public class DecodeLogic {
private static final String TAG = DecodeLogic.class.getSimpleName();
@@ -96,7 +99,8 @@ public class DecodeLogic {
return null;
}
public int[] decode(RemoteIndex remoteIndex, ACStatus acStatus, int keyCode, int changeWindDirection) {
public int[] decode(RemoteIndex remoteIndex, ACStatus acStatus,
int keyCode, int changeWindDirection) {
int[] decoded = null;
if (null != remoteIndex) {
int categoryId = remoteIndex.getCategoryId();
@@ -113,6 +117,34 @@ public class DecodeLogic {
return null;
}
public ACParameters getACParameters(RemoteIndex remoteIndex, int mode) {
if (null != remoteIndex) {
ACParameters acParameters = new ACParameters();
int categoryId = remoteIndex.getCategoryId();
int subCate = remoteIndex.getSubCate();
byte[] binaryContent = remoteIndex.getBinaries();
IRDecode irDecode = IRDecode.getInstance();
int ret = irDecode.openBinary(categoryId, subCate, binaryContent, binaryContent.length);
if (0 == ret) {
int []supportedModes = irDecode.getACSupportedMode();
acParameters.setSupportedModes(supportedModes);
if (1 == supportedModes[mode]) {
// if this mode is really supported by this AC, get other parameters
TemperatureRange temperatureRange = irDecode.getTemperatureRange(mode);
int[] supportedWindSpeed = irDecode.getACSupportedWindSpeed(mode);
int[] supportedSwing = irDecode.getACSupportedSwing(mode);
acParameters.setTempMax(temperatureRange.getTempMax());
acParameters.setTempMin(temperatureRange.getTempMin());
acParameters.setSupportedWindSpeed(supportedWindSpeed);
acParameters.setSupportedSwing(supportedSwing);
}
}
irDecode.closeBinary();
return acParameters;
}
return null;
}
public void close(IDecodeSessionRepository decodeSessionRepository, String sessionId) {
decodeSessionRepository.delete(sessionId);
}

View File

@@ -0,0 +1,72 @@
package net.irext.decode.service.model;
/**
* Filename: ACParameters.java
* Revised: Date: 2019-02-14
* Revision: Revision: 1.0
* <p>
* Description: AC parameters entity
* <p>
* Revision log:
* 2018-12-29: created by strawmanbobi
*/
public class ACParameters {
private int tempMin;
private int tempMax;
private int [] supportedModes;
private int []supportedWindSpeed;
private int []supportedSwing;
public ACParameters(int tempMin, int tempMax, int[] supportedModes,
int[] supportedWindSpeed, int[] supportedSwing) {
this.tempMin = tempMin;
this.tempMax = tempMax;
this.supportedModes = supportedModes;
this.supportedWindSpeed = supportedWindSpeed;
this.supportedSwing = supportedSwing;
}
public ACParameters() {
}
public int getTempMin() {
return tempMin;
}
public void setTempMin(int tempMin) {
this.tempMin = tempMin;
}
public int getTempMax() {
return tempMax;
}
public void setTempMax(int tempMax) {
this.tempMax = tempMax;
}
public int[] getSupportedModes() {
return supportedModes;
}
public void setSupportedModes(int[] supportedModes) {
this.supportedModes = supportedModes;
}
public int[] getSupportedWindSpeed() {
return supportedWindSpeed;
}
public void setSupportedWindSpeed(int[] supportedWindSpeed) {
this.supportedWindSpeed = supportedWindSpeed;
}
public int[] getSupportedSwing() {
return supportedSwing;
}
public void setSupportedSwing(int[] supportedSwing) {
this.supportedSwing = supportedSwing;
}
}

View File

@@ -0,0 +1,52 @@
package net.irext.decode.service.request;
/**
* Filename: GetACParametersRequest.java
* Revised: Date: 2017-05-16
* Revision: Revision: 1.0
* <p>
* Description: HTTP decode online
* <p>
* Revision log:
* 2019-02-14: created by strawmanbobi
*/
public class GetACParametersRequest {
private int remoteIndexId;
private String sessionId;
private int mode;
public GetACParametersRequest(int remoteIndexId, String sessionId, int mode) {
this.remoteIndexId = remoteIndexId;
this.sessionId = sessionId;
this.mode = mode;
}
public GetACParametersRequest() {
}
public int getRemoteIndexId() {
return remoteIndexId;
}
public void setRemoteIndexId(int remoteIndexId) {
this.remoteIndexId = remoteIndexId;
}
public String getSessionId() {
return sessionId;
}
public void setSessionId(String sessionId) {
this.sessionId = sessionId;
}
public int getMode() {
return mode;
}
public void setMode(int mode) {
this.mode = mode;
}
}

View File

@@ -0,0 +1,36 @@
package net.irext.decode.service.response;
import net.irext.decode.service.model.ACParameters;
/**
* Filename: ACParametersResponse.java
* Revised: Date: 2017-05-16
* Revision: Revision: 1.0
* <p>
* Description: Air conditioner support parameters response
* <p>
* Revision log:
* 2019-02-14: created by strawmanbobi
*/
public class ACParametersResponse extends ServiceResponse {
ACParameters entity;
public ACParametersResponse(Status status, ACParameters entity) {
super(status);
this.entity = entity;
}
public ACParametersResponse() {
super(new Status());
this.entity = null;
}
public ACParameters getEntity() {
return entity;
}
public void setEntity(ACParameters entity) {
this.entity = entity;
}
}

View File

@@ -1,22 +1,21 @@
package net.irext.decode.service.service;
package net.irext.decode.service.restapi;
import net.irext.decode.service.businesslogic.DecodeLogic;
import net.irext.decode.service.cache.IDecodeSessionRepository;
import net.irext.decode.service.cache.IIRBinaryRepository;
import net.irext.decode.service.mapper.RemoteIndexMapper;
import net.irext.decode.service.model.ACParameters;
import net.irext.decode.service.model.DecodeSession;
import net.irext.decode.service.model.RemoteIndex;
import net.irext.decode.service.request.CloseRequest;
import net.irext.decode.service.request.DecodeRequest;
import net.irext.decode.service.request.GetACParametersRequest;
import net.irext.decode.service.request.OpenRequest;
import net.irext.decode.service.response.*;
import net.irext.decode.service.utils.LoggerUtil;
import net.irext.decode.service.utils.MD5Util;
import net.irext.decode.service.businesslogic.IndexLogic;
import net.irext.decode.service.response.DecodeResponse;
import net.irext.decode.service.response.ServiceResponse;
import net.irext.decode.service.response.Status;
import net.irext.decode.service.response.StringResponse;
import net.irext.decode.service.service.base.AbstractBaseService;
import net.irext.decode.service.restapi.base.AbstractBaseService;
import net.irext.decode.sdk.bean.ACStatus;
import net.irext.decode.sdk.utils.Constants;
import org.springframework.beans.factory.annotation.Autowired;
@@ -105,46 +104,51 @@ public class IRDecodeService extends AbstractBaseService {
}
}
@PostMapping("/get_ac_parameters")
public ACParametersResponse getACParameters(@RequestBody GetACParametersRequest getACParametersRequest) {
try {
int remoteIndexId = getACParametersRequest.getRemoteIndexId();
String sessionId = getACParametersRequest.getSessionId();
int mode = getACParametersRequest.getMode();
RemoteIndex cachedRemoteIndex = getCachedRemoteIndex(sessionId, remoteIndexId);
ACParametersResponse response = new ACParametersResponse();
if (null == cachedRemoteIndex) {
response.setEntity(null);
response.setStatus(new Status(Constants.ERROR_CODE_INVALID_SESSION,
Constants.ERROR_CODE_INVALID_SESSION_TEXT));
return response;
}
ACParameters acParameters = DecodeLogic.getInstance().getACParameters(cachedRemoteIndex, mode);
response.setStatus(new Status(Constants.ERROR_CODE_SUCCESS, Constants.ERROR_CODE_SUCESS_TEXT));
response.setEntity(acParameters);
return response;
} catch (Exception e) {
e.printStackTrace();
return getExceptionResponse(ACParametersResponse.class);
}
}
@PostMapping("/decode")
public DecodeResponse irDecode(@RequestBody DecodeRequest decodeRequest) {
try {
int indexId = decodeRequest.getRemoteIndexId();
int remoteIndexId = decodeRequest.getRemoteIndexId();
ACStatus acStatus = decodeRequest.getAcStatus();
int keyCode = decodeRequest.getKeyCode();
int changeWindDir = decodeRequest.getChangeWindDir();
String sessionId = decodeRequest.getSessionId();
RemoteIndex cachedRemoteIndex = null;
RemoteIndex cachedRemoteIndex = getCachedRemoteIndex(sessionId, remoteIndexId);;
DecodeResponse response = new DecodeResponse();
if (null == sessionId) {
LoggerUtil.getInstance().trace(TAG, "sessionId is not given, abort");
if (null == cachedRemoteIndex) {
response.setEntity(null);
response.setStatus(new Status(Constants.ERROR_CODE_INVALID_SESSION,
Constants.ERROR_CODE_INVALID_SESSION_TEXT));
} else {
Integer cachedRemoteIndexId = decodeSessionRepository.find(sessionId);
if (null == cachedRemoteIndexId) {
response.setEntity(null);
response.setStatus(new Status(Constants.ERROR_CODE_INVALID_SESSION,
Constants.ERROR_CODE_INVALID_SESSION_TEXT));
} else {
cachedRemoteIndex = irBinaryRepository.find(cachedRemoteIndexId);
if (null == cachedRemoteIndex) {
response.setEntity(null);
response.setStatus(new Status(Constants.ERROR_CODE_INVALID_SESSION,
Constants.ERROR_CODE_INVALID_SESSION_TEXT));
} else {
if (indexId != cachedRemoteIndex.getId()) {
response.setEntity(null);
response.setStatus(new Status(Constants.ERROR_CODE_INVALID_SESSION,
Constants.ERROR_CODE_INVALID_SESSION_TEXT));
}
}
}
}
if (response.getStatus().getCode() != Constants.ERROR_CODE_SUCCESS) {
return response;
}
@@ -175,4 +179,23 @@ public class IRDecodeService extends AbstractBaseService {
return getExceptionResponse(DecodeResponse.class);
}
}
private RemoteIndex getCachedRemoteIndex(String sessionId, int remoteIndexId) {
RemoteIndex cachedRemoteIndex = null;
if (null == sessionId) {
LoggerUtil.getInstance().trace(TAG, "sessionId is not given, abort");
} else {
Integer cachedRemoteIndexId = decodeSessionRepository.find(sessionId);
if (null != cachedRemoteIndexId) {
cachedRemoteIndex = irBinaryRepository.find(cachedRemoteIndexId);
if (null != cachedRemoteIndex) {
if (remoteIndexId != cachedRemoteIndex.getId()) {
cachedRemoteIndex = null;
}
}
}
}
return cachedRemoteIndex;
}
}

View File

@@ -1,4 +1,4 @@
package net.irext.decode.service.service.base;
package net.irext.decode.service.restapi.base;
import net.irext.decode.service.Constants;
import net.irext.decode.service.response.ServiceResponse;
@@ -11,7 +11,7 @@ import org.apache.commons.logging.LogFactory;
* Revised: Date: 2017-04-27
* Revision: Revision: 1.0
* <p>
* Description: Base service abstract class implemented service interface
* Description: Base restapi abstract class implemented restapi interface
* <p>
* Revision log:
* 2017-04-27: created by strawmanbobi