initialized decode service project

This commit is contained in:
strawmanbobi
2018-12-13 23:01:52 +08:00
parent b8b92d8bd9
commit a335769321
29 changed files with 1480 additions and 0 deletions

View File

@@ -0,0 +1,180 @@
package net.irext.collector;
/**
* Filename: Constants.java
* Revised: Date: 2017-12-08
* Revision: Revision: 1.0
* <p>
* Description: SDK Constants
* <p>
* Revision log:
* 2017-12-08: created by strawmanbobi
*/
public class Constants {
public static final int ERROR_CODE_SUCCESS = 0;
public static final int ERROR_CODE_NETWORK_ERROR = -1;
public static final int ERROR_CODE_AUTH_FAILURE = 1;
public static final int ERROR_CODE_INVALID_CATEGORY = 2;
public static final int ERROR_CODE_INVALID_BRAND = 3;
public static final int ERROR_CODE_INVALID_PARAMETER = 4;
public static final int LANG_ZH_CN = 0;
public static final int LANG_EN = 1;
public static final int LANG_TW_CN = 2;
public enum CategoryID {
AIR_CONDITIONER(1),
TV(2),
STB(3),
NET_BOX(4),
IPTV(5),
DVD(6),
FAN(7),
PROJECTOR(8),
STEREO(9),
LIGHT(10),
BSTB(11),
CLEANING_ROBOT(12),
AIR_CLEANER(13),
DYSON_SERIES(14);
private final int id;
CategoryID(int id) {
this.id = id;
}
public int getValue() {
return id;
}
}
public enum BinaryType {
TYPE_BINARY(0),
TYPE_HEXDECIMAL(1);
private final int type;
BinaryType(int type) {
this.type = type;
}
public int getValue() {
return type;
}
}
public enum ACPower {
POWER_ON(0),
POWER_OFF(1);
private final int power;
ACPower(int power) {
this.power = power;
}
public int getValue() {
return power;
}
}
public enum ACMode {
MODE_COOL(0),
MODE_HEAT(1),
MODE_AUTO(2),
MODE_FAN(3),
MODE_DEHUMIDITY(4);
private final int mode;
ACMode(int mode) {
this.mode = mode;
}
public int getValue() {
return mode;
}
}
public enum ACTemperature {
TEMP_16(0),
TEMP_17(1),
TEMP_18(2),
TEMP_19(3),
TEMP_20(4),
TEMP_21(5),
TEMP_22(6),
TEMP_23(7),
TEMP_24(8),
TEMP_25(9),
TEMP_26(10),
TEMP_27(11),
TEMP_28(12),
TEMP_29(13),
TEMP_30(14);
private final int temp;
ACTemperature(int temp) {
this.temp = temp;
}
public int getValue() {
return temp;
}
}
public enum ACWindSpeed {
SPEED_AUTO(0),
SPEED_LOW(1),
SPEED_MEDIUM(2),
SPEED_HIGH(3);
private final int speed;
ACWindSpeed(int speed) {
this.speed = speed;
}
public int getValue() {
return speed;
}
}
public enum ACSwing {
SWING_ON(0),
SWING_OFF(1);
private final int swing;
ACSwing(int swing) {
this.swing = swing;
}
public int getValue() {
return swing;
}
}
public enum ACFunction {
FUNCTION_SWITCH_POWER(1),
FUNCTION_CHANGE_MODE(2),
FUNCTION_TEMPERATURE_UP(3),
FUNCTION_TEMPERATURE_DOWN(4),
FUNCTION_SWITCH_WIND_SPEED(5),
FUNCTION_SWITCH_WIND_DIR(6),
FUNCTION_SWITCH_SWING(7);
private final int function;
ACFunction(int function) {
this.function = function;
}
public int getValue() {
return function;
}
}
}

View File

@@ -0,0 +1,27 @@
package net.irext.collector;
import net.irext.collector.model.CollectRemote;
import org.apache.ibatis.type.MappedTypes;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* Filename: SpringBootMybatisApplication
* Revised: Date: 2018-12-08
* Revision: Revision: 1.0
* <p>
* Description: IRext Code Collector Application
* <p>
* Revision log:
* 2018-12-08: created by strawmanbobi
*/
@MappedTypes(CollectRemote.class)
@MapperScan("net.irext.collector.mybatis.springbootmybatis.mapper")
@SpringBootApplication
public class SpringBootMybatisApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootMybatisApplication.class, args);
}
}

View File

@@ -0,0 +1,52 @@
package net.irext.collector.businesslogic;
import net.irext.collector.model.IRCode;
import org.springframework.stereotype.Controller;
/**
* Filename: CollectCodeLogic
* Revised: Date: 2018-12-08
* Revision: Revision: 1.0
* <p>
* Description: IRext Code Collector Collect Code Logic
* <p>
* Revision log:
* 2018-12-08: created by strawmanbobi
*/
@Controller
public class CollectCodeLogic {
private Integer codeCollectState = 0;
private IRCode irCode;
private static CollectCodeLogic collectCodeLogic;
public static CollectCodeLogic getInstance(IRCode irCode) {
if (null == collectCodeLogic) {
collectCodeLogic = new CollectCodeLogic(irCode);
}
return collectCodeLogic;
}
public CollectCodeLogic(IRCode irCode) {
this.irCode = irCode;
}
public CollectCodeLogic() {
}
public boolean collectCodeWorkUnit() {
// step 1. figure out the category and brand for this code
// step 2. go through the FSM for remote in each category
codeCollectState++;
System.out.println("state = " + codeCollectState + " : " + irCode.getKey());
// step 3. record key code
// step 4. temporarily save to file
return true;
}
}

View File

@@ -0,0 +1,34 @@
package net.irext.collector.mapper;
import net.irext.collector.model.CollectRemote;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import java.util.List;
/**
* Filename: CollectRemoteMapper.java
* Revised: Date: 2018-12-08
* Revision: Revision: 1.0
* <p>
* Description: CollectRemote Mybatis Mapper
* <p>
* Revision log:
* 2018-12-08: created by strawmanbobi
*/
@Mapper
public interface CollectRemoteMapper {
@Select("select * from collect_remote")
List<CollectRemote> listCollectRemotes();
@Insert("INSERT INTO collect_remote(category_id, category_name, brand_id, brand_name, city_code, city_name, " +
"operator_id, operator_name, remote_map, protocol, remote) " +
"values(#{categoryId}, #{categoryName}, #{brandId}, #{brandName}, #{cityCode}, #{cityName}, " +
"#{operatorId}, #{operatorName}, #{remoteMap}, #{protocol}, #{remote})")
@SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id",
before = false, resultType = Integer.class)
void createCollectRemote(CollectRemote collectRemote);
}

View File

@@ -0,0 +1,72 @@
package net.irext.collector.model;
/**
* Filename: CollectKey.java
* Revised: Date: 2018-12-08
* Revision: Revision: 1.0
* <p>
* Description: CollectKey Model
* <p>
* Revision log:
* 2018-12-08: created by strawmanbobi
*/
public class CollectKey {
private Integer id;
private Integer collectRemoteId;
private Integer keyId;
private String keyName;
private String keyValue;
public CollectKey(Integer id, Integer collectRemoteId, Integer keyId, String keyName, String keyValue) {
this.id = id;
this.collectRemoteId = collectRemoteId;
this.keyId = keyId;
this.keyName = keyName;
this.keyValue = keyValue;
}
public CollectKey() {
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getCollectRemoteId() {
return collectRemoteId;
}
public void setCollectRemoteId(Integer collectRemoteId) {
this.collectRemoteId = collectRemoteId;
}
public Integer getKeyId() {
return keyId;
}
public void setKeyId(Integer keyId) {
this.keyId = keyId;
}
public String getKeyName() {
return keyName;
}
public void setKeyName(String keyName) {
this.keyName = keyName;
}
public String getKeyValue() {
return keyValue;
}
public void setKeyValue(String keyValue) {
this.keyValue = keyValue;
}
}

View File

@@ -0,0 +1,144 @@
package net.irext.collector.model;
/**
* Filename: CollectRemote.java
* Revised: Date: 2018-12-08
* Revision: Revision: 1.0
* <p>
* Description: CollectRemote Model
* <p>
* Revision log:
* 2018-12-08: created by strawmanbobi
*/
public class CollectRemote {
private Integer id;
private Integer categoryId;
private String categoryName;
private Integer brandId;
private String brandName;
private String cityCode;
private String cityName;
private Integer operatorId;
private String operatorName;
private String remoteMap;
private String protocol;
private String remote;
public CollectRemote(Integer id, Integer categoryId, String categoryName, Integer brandId, String brandName,
String cityCode, String cityName, Integer operatorId, String operatorName,
String remoteMap, String protocol, String remote) {
this.id = id;
this.categoryId = categoryId;
this.categoryName = categoryName;
this.brandId = brandId;
this.brandName = brandName;
this.cityCode = cityCode;
this.cityName = cityName;
this.operatorId = operatorId;
this.operatorName = operatorName;
this.remoteMap = remoteMap;
this.protocol = protocol;
this.remote = remote;
}
public CollectRemote() {
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getCategoryId() {
return categoryId;
}
public void setCategoryId(Integer categoryId) {
this.categoryId = categoryId;
}
public String getCategoryName() {
return categoryName;
}
public void setCategoryName(String categoryName) {
this.categoryName = categoryName;
}
public Integer getBrandId() {
return brandId;
}
public void setBrandId(Integer brandId) {
this.brandId = brandId;
}
public String getBrandName() {
return brandName;
}
public void setBrandName(String brandName) {
this.brandName = brandName;
}
public String getCityCode() {
return cityCode;
}
public void setCityCode(String cityCode) {
this.cityCode = cityCode;
}
public String getCityName() {
return cityName;
}
public void setCityName(String cityName) {
this.cityName = cityName;
}
public Integer getOperatorId() {
return operatorId;
}
public void setOperatorId(Integer operatorId) {
this.operatorId = operatorId;
}
public String getOperatorName() {
return operatorName;
}
public void setOperatorName(String operatorName) {
this.operatorName = operatorName;
}
public String getRemoteMap() {
return remoteMap;
}
public void setRemoteMap(String remoteMap) {
this.remoteMap = remoteMap;
}
public String getProtocol() {
return protocol;
}
public void setProtocol(String protocol) {
this.protocol = protocol;
}
public String getRemote() {
return remote;
}
public void setRemote(String remote) {
this.remote = remote;
}
}

View File

@@ -0,0 +1,54 @@
package net.irext.collector.model;
/**
* Filename: IRCode.java
* Revised: Date: 2018-12-08
* Revision: Revision: 1.0
* <p>
* Description: IR Code
* <p>
* Revision log:
* 2018-12-08: created by strawmanbobi
*/
public class IRCode {
private int id;
private String text;
private String key;
private String code;
public IRCode(int id, String text, String key, String code) {
this.id = id;
this.text = text;
this.key = key;
this.code = code;
}
public IRCode() {
}
public void setText(String text) {
this.text = text;
}
public void setKey(String key) {
this.key = key;
}
public void setCode(String code) {
this.code = code;
}
public String getText() {
return this.text;
}
public String getKey() {
return this.key;
}
public String getCode() {
return this.code;
}
}

View File

@@ -0,0 +1,36 @@
package net.irext.collector.response;
import net.irext.collector.model.CollectKey;
import java.util.List;
/**
* Filename: CollectKeysResponse.java
* Revised: Date: 2018-12-08
* Revision: Revision: 1.0
* <p>
* Description: HTTP Response class
* <p>
* Revision log:
* 2018-12-08: created by strawmanbobi
*/
public class CollectKeysResponse extends ServiceResponse {
List<CollectKey> entity;
public CollectKeysResponse(Status status, List<CollectKey> entity) {
super(status);
this.entity = entity;
}
public CollectKeysResponse() {
}
public List<CollectKey> getEntity() {
return entity;
}
public void setEntity(List<CollectKey> entity) {
this.entity = entity;
}
}

View File

@@ -0,0 +1,36 @@
package net.irext.collector.response;
import net.irext.collector.model.CollectRemote;
import java.util.List;
/**
* Filename: CollectRemotesResponse.java
* Revised: Date: 2018-12-08
* Revision: Revision: 1.0
* <p>
* Description: HTTP Response class
* <p>
* Revision log:
* 2018-12-08: created by strawmanbobi
*/
public class CollectRemotesResponse extends ServiceResponse {
List<CollectRemote> entity;
public CollectRemotesResponse(Status status, List<CollectRemote> entity) {
super(status);
this.entity = entity;
}
public CollectRemotesResponse() {
}
public List<CollectRemote> getEntity() {
return entity;
}
public void setEntity(List<CollectRemote> entity) {
this.entity = entity;
}
}

View File

@@ -0,0 +1,32 @@
package net.irext.collector.response;
/**
* Filename: ServiceResponse.java
* Revised: Date: 2018-12-08
* Revision: Revision: 1.0
* <p>
* Description: HTTP Response class
* <p>
* Revision log:
* 2018-12-08: created by strawmanbobi
*/
public class ServiceResponse {
private Status status;
public ServiceResponse(Status status) {
this.status = status;
}
public ServiceResponse() {
}
public Status getStatus() {
return status;
}
public void setStatus(Status status) {
this.status = status;
}
}

View File

@@ -0,0 +1,44 @@
package net.irext.collector.response;
import net.irext.collector.Constants;
/**
* Filename: Status.java
* Revised: Date: 2018-12-08
* Revision: Revision: 1.0
* <p>
* Description: HTTP response status
* <p>
* Revision log:
* 2018-12-08: created by strawmanbobi
*/
public class Status {
private int code;
private String cause;
public Status(int code, String cause) {
this.code = code;
this.cause = cause;
}
public Status() {
this.code = Constants.ERROR_CODE_SUCCESS;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getCause() {
return cause;
}
public void setCause(String cause) {
this.cause = cause;
}
}

View File

@@ -0,0 +1,46 @@
package net.irext.collector.service;
import net.irext.collector.mapper.CollectRemoteMapper;
import net.irext.collector.model.CollectRemote;
import net.irext.collector.response.CollectRemotesResponse;
import net.irext.collector.response.ServiceResponse;
import net.irext.collector.response.Status;
import org.springframework.web.bind.annotation.*;
/**
* Filename: CollectRemoteService
* Revised: Date: 2018-12-08
* Revision: Revision: 1.0
* <p>
* Description: IRext Remote Management Service
* <p>
* Revision log:
* 2018-12-08: created by strawmanbobi
*/
@RestController
@RequestMapping("/irext/collect")
public class CollectRemoteService {
private CollectRemoteMapper collectRemoteMapper;
public CollectRemoteService(CollectRemoteMapper collectRemoteMapper) {
this.collectRemoteMapper = collectRemoteMapper;
}
@GetMapping("/list_collect_remotes")
public CollectRemotesResponse listCollectRemotes() {
CollectRemotesResponse collectRemotesResponse = new CollectRemotesResponse();
collectRemotesResponse.setEntity(collectRemoteMapper.listCollectRemotes());
collectRemotesResponse.setStatus(new Status());
return collectRemotesResponse;
}
@PostMapping("/create_collect_remote")
private ServiceResponse createCollectRemote(@RequestBody CollectRemote collectRemote) {
ServiceResponse serviceResponse = new ServiceResponse();
collectRemoteMapper.createCollectRemote(collectRemote);
serviceResponse.setStatus(new Status());
return serviceResponse;
}
}

View File

@@ -0,0 +1,33 @@
package net.irext.collector.service;
import net.irext.collector.businesslogic.CollectCodeLogic;
import net.irext.collector.model.IRCode;
import net.irext.collector.response.ServiceResponse;
import net.irext.collector.response.Status;
import org.springframework.web.bind.annotation.*;
/**
* Filename: IRCodeService
* Revised: Date: 2018-12-08
* Revision: Revision: 1.0
* <p>
* Description: IRext Code Collector Service
* <p>
* Revision log:
* 2018-12-08: created by strawmanbobi
*/
@RestController
@RequestMapping("/irext/collect")
public class IRCodeService {
public IRCodeService() {
}
@PostMapping("/collect_code")
public ServiceResponse collectCode(@RequestBody IRCode irCode) {
CollectCodeLogic.getInstance(irCode).collectCodeWorkUnit();
ServiceResponse serviceResponse = new ServiceResponse();
serviceResponse.setStatus(new Status());
return serviceResponse;
}
}

View File

@@ -0,0 +1,5 @@
server.port=8081
spring.datasource.url=jdbc:mysql://localhost:3306/irext_collect
spring.datasource.username=root
spring.datasource.password=root