类名重构
This commit is contained in:
parent
72650698cc
commit
9855c823a7
@ -75,6 +75,12 @@
|
|||||||
<version>1.6</version>
|
<version>1.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<artifactId>leaf-boot-starter</artifactId>
|
||||||
|
<groupId>com.sankuai.inf.leaf</groupId>
|
||||||
|
<version>1.0.1-RELEASE</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@ -7,8 +7,6 @@ public class ServiceField {
|
|||||||
|
|
||||||
private String version;
|
private String version;
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
private String code;
|
private String code;
|
||||||
|
|
||||||
private Integer len;
|
private Integer len;
|
||||||
@ -43,14 +41,6 @@ public class ServiceField {
|
|||||||
this.version = version;
|
this.version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCode() {
|
public String getCode() {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,11 +18,11 @@ import org.slf4j.LoggerFactory;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class PPPBinaryHandler implements ClientBinaryHandler {
|
public class ChargingPileBinaryHandler implements ClientBinaryHandler {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(PPPBinaryHandler.class);
|
private static final Logger log = LoggerFactory.getLogger(ChargingPileBinaryHandler.class);
|
||||||
|
|
||||||
private static final String SERVICE_REGISTER = "1001";
|
private static final String SERVICE_REGISTER = "01";
|
||||||
private static final String SERVICE_LOGOUT = "1002";
|
private static final String SERVICE_LOGOUT = "1002";
|
||||||
|
|
||||||
private static final String DATA_TYPE_STRING = "string";
|
private static final String DATA_TYPE_STRING = "string";
|
||||||
@ -32,53 +32,47 @@ public class PPPBinaryHandler implements ClientBinaryHandler {
|
|||||||
|
|
||||||
private ServiceMainLogic servicemainLogic;
|
private ServiceMainLogic servicemainLogic;
|
||||||
|
|
||||||
public PPPBinaryHandler() {
|
public ChargingPileBinaryHandler() {
|
||||||
servicemainLogic = SpringContextHolder.getBean("ServiceMainLogic");
|
servicemainLogic = SpringContextHolder.getBean("ServiceMainLogic");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleBinary(ClientHandler handler, byte[] data) throws IOException {
|
public void handleBinary(ClientHandler handler, byte[] data) throws IOException {
|
||||||
|
|
||||||
String dataStr = HexUtils.toHex(data);
|
String dataStr = HexUtils.toHex(data);
|
||||||
String poleNo = PPPServer.getPoleNo(handler);
|
String poleNo = ChargingPileServer.getPoleNo(handler);
|
||||||
if (poleNo==null) {
|
if (data.length <= 2|| !dataStr.startsWith("68")) {
|
||||||
log.info("received message <<<< {}, len[{}]", dataStr, data.length);
|
log.info("received invalid data <<<< {}, len[{}]", dataStr, data.length);
|
||||||
} else if (!dataStr.startsWith("00101005000100040000000000000000")) {
|
return;
|
||||||
log.info("received pole [{}] message <<<< {}, len[{}]", poleNo, dataStr, data.length);
|
} else {
|
||||||
|
log.info("received data <<<< {}, from pole <<<< {}", dataStr, poleNo);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// CRC校验和
|
|
||||||
byte[] data2 = Arrays.copyOfRange(data, 2, data.length-2);
|
|
||||||
String crc1 = CRCCalculator.ModbusCRC(data2, data2.length);
|
|
||||||
// 检验长度
|
|
||||||
if (data.length <= 2) {
|
|
||||||
log.error("input data invalid. " + data);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int len = HexUtils.toInteger(data, 1, 2);
|
int len = HexUtils.toInteger(data, 1, 2);
|
||||||
if (data.length < len) {
|
if (data.length < len) {
|
||||||
log.error("input data length. " + data.length);
|
log.error("incorrect input data length {}", data.length);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
byte[] data2 = Arrays.copyOfRange(data, 2, data.length-2);
|
||||||
|
String crc = CRCCalculator.ModbusCRC(data2);
|
||||||
|
if (!dataStr.endsWith(crc)) {
|
||||||
|
log.error("incorrect input data crc {}", crc);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理粘包
|
|
||||||
List<byte[]> dataList = parseDataList(data);
|
List<byte[]> dataList = parseDataList(data);
|
||||||
|
|
||||||
for (byte[] d : dataList) {
|
for (byte[] d : dataList) {
|
||||||
process(handler, d);
|
process(handler, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (TxException e) {
|
} catch (TxException e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
private void process(ClientHandler handler, byte[] data) throws TxException, IOException {
|
private void process(ClientHandler handler, byte[] data) throws TxException, IOException {
|
||||||
|
|
||||||
String serviceName = HexUtils.toHex(data, 5, 6);
|
String serviceName = HexUtils.toHex(data, 5, 6);
|
||||||
String version = PPPServer.getVersion(handler.getName());
|
String version = ChargingPileServer.getVersion(handler.getName());
|
||||||
String poleNo = PPPServer.getPoleNo(handler);
|
String poleNo = ChargingPileServer.getPoleNo(handler);
|
||||||
Map<String, Object> req = analysis(data, serviceName, version);
|
Map<String, Object> req = analysis(data, serviceName, version);
|
||||||
// log.info("pole [{}] status: |{}|", StringUtils.isNotBlank(poleNo) ? poleNo : "null", req.get("status") != null ? MQPole.PoleStatus.toString((Long) req.get("status")) : "N/A");
|
// log.info("pole [{}] status: |{}|", StringUtils.isNotBlank(poleNo) ? poleNo : "null", req.get("status") != null ? MQPole.PoleStatus.toString((Long) req.get("status")) : "N/A");
|
||||||
ServiceParameter sp = new ServiceParameter(serviceName, poleNo, req);
|
ServiceParameter sp = new ServiceParameter(serviceName, poleNo, req);
|
||||||
@ -96,16 +90,14 @@ public class PPPBinaryHandler implements ClientBinaryHandler {
|
|||||||
log.info("server send msg >>>> [{}] |{}|", poleNo, HexUtils.toHex(result.getBinary()));
|
log.info("server send msg >>>> [{}] |{}|", poleNo, HexUtils.toHex(result.getBinary()));
|
||||||
handler.sendClientBinary(result.getBinary());
|
handler.sendClientBinary(result.getBinary());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 注册成功后需要将当前handler与设备关联
|
// 注册成功后需要将当前handler与设备关联
|
||||||
if (SERVICE_REGISTER.equals(serviceName)) {
|
if (SERVICE_REGISTER.equals(serviceName)) {
|
||||||
PPPServer.putHandler((String) req.get("poleNo"), handler);
|
ChargingPileServer.putHandler((String) req.get("poleNo"), handler);
|
||||||
PPPServer.putVersion(handler.getName(), (String) req.get("version"));
|
ChargingPileServer.putVersion(handler.getName(), (String) req.get("version"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 注销后将桩号对应关系解除
|
// 注销后将桩号对应关系解除
|
||||||
if (SERVICE_LOGOUT.equals(serviceName)) {
|
if (SERVICE_LOGOUT.equals(serviceName)) {
|
||||||
PPPServer.removeHandler(poleNo);
|
ChargingPileServer.removeHandler(poleNo);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -117,7 +109,7 @@ public class PPPBinaryHandler implements ClientBinaryHandler {
|
|||||||
int start = 0;
|
int start = 0;
|
||||||
while (start < data.length) {
|
while (start < data.length) {
|
||||||
if (len > data.length) {
|
if (len > data.length) {
|
||||||
log.error("input data[{}] len[{}]", data, data.length);
|
log.error("incorrect input data[{}] len[{}]", data, data.length);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
dataList.add(ArrayUtils.subarray(data, start, len));
|
dataList.add(ArrayUtils.subarray(data, start, len));
|
||||||
@ -126,7 +118,7 @@ public class PPPBinaryHandler implements ClientBinaryHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (dataList.size() > 1) {
|
if (dataList.size() > 1) {
|
||||||
log.info("detection stick package size[{}]", dataList.size());
|
log.info("detected stick package size[{}]", dataList.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
return dataList;
|
return dataList;
|
||||||
@ -139,13 +131,10 @@ public class PPPBinaryHandler implements ClientBinaryHandler {
|
|||||||
throw TxException.INNER_ERROR("field mapper not found");
|
throw TxException.INNER_ERROR("field mapper not found");
|
||||||
|
|
||||||
Map<String, Object> result = new HashMap<String, Object>();
|
Map<String, Object> result = new HashMap<String, Object>();
|
||||||
int pos = 4;
|
int pos = 6;
|
||||||
// TODO 终止充电详情原因
|
|
||||||
for (ServiceField field : fieldList) {
|
for (ServiceField field : fieldList) {
|
||||||
// 判断长度 某些报文不同版本长度不同
|
|
||||||
if (pos >= data.length || pos + field.getLen() > data.length)
|
if (pos >= data.length || pos + field.getLen() > data.length)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
switch (field.getDataType()) {
|
switch (field.getDataType()) {
|
||||||
case DATA_TYPE_STRING:
|
case DATA_TYPE_STRING:
|
||||||
result.put(field.getCode(), HexUtils.toString(data, pos, pos + field.getLen()));
|
result.put(field.getCode(), HexUtils.toString(data, pos, pos + field.getLen()));
|
||||||
@ -161,7 +150,6 @@ public class PPPBinaryHandler implements ClientBinaryHandler {
|
|||||||
}
|
}
|
||||||
pos += field.getLen();
|
pos += field.getLen();
|
||||||
}
|
}
|
||||||
// 原始报文
|
|
||||||
result.put("hex", HexUtils.toHex(data));
|
result.put("hex", HexUtils.toHex(data));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -10,11 +10,11 @@ import java.io.IOException;
|
|||||||
import java.net.SocketTimeoutException;
|
import java.net.SocketTimeoutException;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public class PPPCommandHandler implements ClientCommandHandler {
|
public class ChargingPileCommandHandler implements ClientCommandHandler {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(PPPCommandHandler.class);
|
private static final Logger log = LoggerFactory.getLogger(ChargingPileCommandHandler.class);
|
||||||
|
|
||||||
public PPPCommandHandler() {
|
public ChargingPileCommandHandler() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -12,10 +12,10 @@ import java.net.SocketTimeoutException;
|
|||||||
|
|
||||||
@Lazy(false)
|
@Lazy(false)
|
||||||
@Component
|
@Component
|
||||||
public class PPPEventHandler implements ClientEventHandler {
|
public class ChargingPileEventHandler implements ClientEventHandler {
|
||||||
private static final Logger log = LoggerFactory.getLogger(PPPEventHandler.class);
|
private static final Logger log = LoggerFactory.getLogger(ChargingPileEventHandler.class);
|
||||||
|
|
||||||
public PPPEventHandler() {
|
public ChargingPileEventHandler() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -27,11 +27,11 @@ public class PPPEventHandler implements ClientEventHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void lostConnection(ClientHandler handler) {
|
public void lostConnection(ClientHandler handler) {
|
||||||
String poleNo = PPPServer.getPoleNo(handler);
|
String poleNo = ChargingPileServer.getPoleNo(handler);
|
||||||
log.info("lost connection -> [{}] {} <- {}",
|
log.info("lost connection -> [{}] {} <- {}",
|
||||||
poleNo, handler.getName(), handler.getSocket().getRemoteSocketAddress().toString());
|
poleNo, handler.getName(), handler.getSocket().getRemoteSocketAddress().toString());
|
||||||
if (poleNo != null) {
|
if (poleNo != null) {
|
||||||
PPPServer.removeHandler(poleNo);
|
ChargingPileServer.removeHandler(poleNo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1,5 +1,6 @@
|
|||||||
package com.xhpc.pp.server;
|
package com.xhpc.pp.server;
|
||||||
|
|
||||||
|
import com.xhpc.pp.service.FieldService;
|
||||||
import com.xhpc.pp.utils.security.HexUtils;
|
import com.xhpc.pp.utils.security.HexUtils;
|
||||||
import org.quickserver.net.server.ClientHandler;
|
import org.quickserver.net.server.ClientHandler;
|
||||||
import org.quickserver.net.server.DataMode;
|
import org.quickserver.net.server.DataMode;
|
||||||
@ -24,17 +25,20 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
@Lazy(false)
|
@Lazy(false)
|
||||||
@Component
|
@Component
|
||||||
public class PPPServer {
|
public class ChargingPileServer {
|
||||||
|
|
||||||
public static final String default_version = "0A";
|
public static final String default_version = "0A";
|
||||||
private static final Logger log = LoggerFactory.getLogger(PPPServer.class);
|
private static final Logger log = LoggerFactory.getLogger(ChargingPileServer.class);
|
||||||
private static Map<String, ClientHandler> handlerMapper = new HashMap<>();
|
private static Map<String, ClientHandler> handlerMapper = new HashMap<>();
|
||||||
private static Map<String, String> versionMapper = new HashMap<>();
|
private static Map<String, String> versionMapper = new HashMap<>();
|
||||||
private static Map<String, String> poleMapper = new HashMap<>();
|
private static Map<String, String> poleMapper = new HashMap<>();
|
||||||
private QuickServer server;
|
private QuickServer server;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public PPPServer(@Value("${ppsvc.server}") String host, @Value("${ppsvc.port}") int port) {
|
private FieldService fieldService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public ChargingPileServer(@Value("${ppsvc.server}") String host, @Value("${ppsvc.port}") int port) {
|
||||||
try {
|
try {
|
||||||
QuickServerConfig config;
|
QuickServerConfig config;
|
||||||
server = new QuickServer();
|
server = new QuickServer();
|
||||||
@ -44,9 +48,9 @@ public class PPPServer {
|
|||||||
mode.setDataMode(DataMode.BINARY, DataType.IN);
|
mode.setDataMode(DataMode.BINARY, DataType.IN);
|
||||||
mode.setDataMode(DataMode.BINARY, DataType.OUT);
|
mode.setDataMode(DataMode.BINARY, DataType.OUT);
|
||||||
config.setDefaultDataMode(mode);
|
config.setDefaultDataMode(mode);
|
||||||
config.setClientEventHandler(PPPEventHandler.class.getName());
|
config.setClientEventHandler(ChargingPileEventHandler.class.getName());
|
||||||
config.setClientCommandHandler(PPPCommandHandler.class.getName());
|
config.setClientCommandHandler(ChargingPileCommandHandler.class.getName());
|
||||||
config.setClientBinaryHandler(PPPBinaryHandler.class.getName());
|
config.setClientBinaryHandler(ChargingPileBinaryHandler.class.getName());
|
||||||
config.getServerMode().setBlocking(true);
|
config.getServerMode().setBlocking(true);
|
||||||
config.setPort(port);
|
config.setPort(port);
|
||||||
config.setBindAddr(host);
|
config.setBindAddr(host);
|
||||||
@ -61,7 +65,6 @@ public class PPPServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void putHandler(String poleNo, ClientHandler handler) {
|
public static void putHandler(String poleNo, ClientHandler handler) {
|
||||||
poleNo = HexUtils.toIntString(poleNo, 4);
|
|
||||||
handlerMapper.put(poleNo, handler);
|
handlerMapper.put(poleNo, handler);
|
||||||
poleMapper.put(handler.getName(), poleNo);
|
poleMapper.put(handler.getName(), poleNo);
|
||||||
}
|
}
|
||||||
@ -2,7 +2,7 @@ package com.xhpc.pp.service;
|
|||||||
|
|
||||||
import com.xhpc.pp.domain.ServiceField;
|
import com.xhpc.pp.domain.ServiceField;
|
||||||
import com.xhpc.pp.mapper.ServiceFieldMapper;
|
import com.xhpc.pp.mapper.ServiceFieldMapper;
|
||||||
import com.xhpc.pp.server.PPPServer;
|
import com.xhpc.pp.server.ChargingPileServer;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@ -23,18 +23,20 @@ public class FieldService {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public FieldService(ServiceFieldMapper fieldMapper) {
|
public FieldService(ServiceFieldMapper fieldMapper) {
|
||||||
|
|
||||||
|
versionMapFields = new HashMap<>();
|
||||||
FieldService.fieldMapper = fieldMapper;
|
FieldService.fieldMapper = fieldMapper;
|
||||||
FieldService.refreshCache();
|
FieldService.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void refreshCache() {
|
public static void refreshCache() {
|
||||||
|
|
||||||
versionMapFields.clear();
|
versionMapFields.clear();
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
|
|
||||||
versionMapFields = new HashMap<>();
|
|
||||||
List<ServiceField> list = fieldMapper.query(null);
|
List<ServiceField> list = fieldMapper.query(null);
|
||||||
for (ServiceField field : list) {
|
for (ServiceField field : list) {
|
||||||
String version = field.getVersion();
|
String version = field.getVersion();
|
||||||
@ -47,21 +49,13 @@ public class FieldService {
|
|||||||
|
|
||||||
public static List<ServiceField> fieldList(String version, String service) {
|
public static List<ServiceField> fieldList(String version, String service) {
|
||||||
Map<String, List<ServiceField>> vermap = versionMapFields.get(version);
|
Map<String, List<ServiceField>> vermap = versionMapFields.get(version);
|
||||||
|
|
||||||
// 充电桩上送的版本未维护,使用默认版本
|
|
||||||
if (vermap == null)
|
if (vermap == null)
|
||||||
vermap = versionMapFields.get(PPPServer.default_version);
|
vermap = versionMapFields.get(ChargingPileServer.default_version);
|
||||||
|
|
||||||
if (vermap == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
// 上送的版本当前接口未维护,使用默认版本
|
|
||||||
List<ServiceField> fieldList = vermap.get(service);
|
List<ServiceField> fieldList = vermap.get(service);
|
||||||
if (fieldList == null || fieldList.isEmpty()) {
|
if (fieldList == null || fieldList.isEmpty()) {
|
||||||
vermap = versionMapFields.get(PPPServer.default_version);
|
vermap = versionMapFields.get(ChargingPileServer.default_version);
|
||||||
fieldList = vermap.get(service);
|
fieldList = vermap.get(service);
|
||||||
}
|
}
|
||||||
|
|
||||||
return fieldList;
|
return fieldList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -20,27 +20,17 @@ public class ServiceMainLogic {
|
|||||||
private Map<String, ServiceLogic> serviceLogics;
|
private Map<String, ServiceLogic> serviceLogics;
|
||||||
|
|
||||||
public ServiceResult process(ServiceParameter param) {
|
public ServiceResult process(ServiceParameter param) {
|
||||||
|
|
||||||
ServiceResult result;
|
ServiceResult result;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// 调用具体业务逻辑的创建逻辑
|
|
||||||
ServiceLogic logic = getServiceLogic(param.getServiceName());
|
ServiceLogic logic = getServiceLogic(param.getServiceName());
|
||||||
// 开启事务
|
|
||||||
startTransaction(param);
|
startTransaction(param);
|
||||||
|
|
||||||
// 开始服务
|
|
||||||
result = logic.service(param);
|
result = logic.service(param);
|
||||||
|
|
||||||
// 提交事务
|
|
||||||
commitTransaction(param);
|
commitTransaction(param);
|
||||||
} catch (TxException e) {
|
} catch (TxException e) {
|
||||||
log.error("服务请求失败:错误码[" + e.getReturnCode() + "],错误:{" + e.getMessage() + "}");
|
log.error("服务请求失败:错误码[" + e.getReturnCode() + "],错误:{" + e.getMessage() + "}");
|
||||||
|
|
||||||
// 记录错误日志
|
|
||||||
// saveErrorLog(param, e);
|
// saveErrorLog(param, e);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 回滚事务
|
|
||||||
terminateTransaction(param);
|
terminateTransaction(param);
|
||||||
result = new ServiceResult(e.getReturnCode(), e.getMessage());
|
result = new ServiceResult(e.getReturnCode(), e.getMessage());
|
||||||
} catch (Exception e1) {
|
} catch (Exception e1) {
|
||||||
@ -50,8 +40,6 @@ public class ServiceMainLogic {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
result = new ServiceResult(null, e.getMessage());
|
result = new ServiceResult(null, e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理结果
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,16 +2,15 @@ package com.xhpc.pp.utils.security;
|
|||||||
|
|
||||||
public class CRCCalculator {
|
public class CRCCalculator {
|
||||||
|
|
||||||
public static String ModbusCRC(byte[] pData, int len) {
|
public static String ModbusCRC(byte[] pData) {
|
||||||
int crc = 0xFFFF;
|
int crc = 0xFFFF;
|
||||||
for (int pos = 0; pos < len; pos++) {
|
for (byte pDatum : pData) {
|
||||||
crc ^= (int)pData[pos] & 0xFF; // XOR byte into least sig. byte of crc
|
crc ^= (int) pDatum & 0xFF; // XOR byte into least sig. byte of crc
|
||||||
for (int i = 8; i != 0; i--) { // Loop over each bit
|
for (int i = 8; i != 0; i--) { // Loop over each bit
|
||||||
if ((crc & 0x0001) != 0) { // If the LSB is set
|
if ((crc & 0x0001) != 0) { // If the LSB is set
|
||||||
crc >>= 1; // Shift right and XOR 0xA001
|
crc >>= 1; // Shift right and XOR 0xA001
|
||||||
crc ^= 0xA001;
|
crc ^= 0xA001;
|
||||||
}
|
} else // Else LSB is not set
|
||||||
else // Else LSB is not set
|
|
||||||
crc >>= 1; // Just shift right
|
crc >>= 1; // Just shift right
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,6 @@
|
|||||||
<id column="id" property="id" jdbcType="BIGINT"/>
|
<id column="id" property="id" jdbcType="BIGINT"/>
|
||||||
<result column="service_name" property="serviceName" jdbcType="VARCHAR"/>
|
<result column="service_name" property="serviceName" jdbcType="VARCHAR"/>
|
||||||
<result column="version" property="version" jdbcType="VARCHAR"/>
|
<result column="version" property="version" jdbcType="VARCHAR"/>
|
||||||
<result column="name" property="name" jdbcType="VARCHAR"/>
|
|
||||||
<result column="code" property="code" jdbcType="VARCHAR"/>
|
<result column="code" property="code" jdbcType="VARCHAR"/>
|
||||||
<result column="len" property="len" jdbcType="INTEGER"/>
|
<result column="len" property="len" jdbcType="INTEGER"/>
|
||||||
<result column="seq" property="seq" jdbcType="INTEGER"/>
|
<result column="seq" property="seq" jdbcType="INTEGER"/>
|
||||||
@ -15,7 +14,7 @@
|
|||||||
|
|
||||||
<sql id="Base_Column_List">
|
<sql id="Base_Column_List">
|
||||||
id
|
id
|
||||||
, service_name, version, name, code, len, seq, remark, data_type
|
, service_name, version, code, len, seq, remark, data_type
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<select id="querySQL" parameterType="java.util.Map" resultType="java.util.Map">
|
<select id="querySQL" parameterType="java.util.Map" resultType="java.util.Map">
|
||||||
@ -37,10 +36,10 @@
|
|||||||
|
|
||||||
<insert id="insert" parameterType="com.xhpc.pp.domain.ServiceField">
|
<insert id="insert" parameterType="com.xhpc.pp.domain.ServiceField">
|
||||||
insert into service_field (id, service_name, version,
|
insert into service_field (id, service_name, version,
|
||||||
name, code, len, seq,
|
code, len, seq,
|
||||||
remark)
|
remark)
|
||||||
values (#{id,jdbcType=BIGINT}, #{serviceName,jdbcType=VARCHAR}, #{version,jdbcType=VARCHAR},
|
values (#{id,jdbcType=BIGINT}, #{serviceName,jdbcType=VARCHAR}, #{version,jdbcType=VARCHAR},
|
||||||
#{name,jdbcType=VARCHAR}, #{code,jdbcType=VARCHAR}, #{len,jdbcType=INTEGER}, #{seq,jdbcType=INTEGER},
|
#{code,jdbcType=VARCHAR}, #{len,jdbcType=INTEGER}, #{seq,jdbcType=INTEGER},
|
||||||
#{remark,jdbcType=VARCHAR})
|
#{remark,jdbcType=VARCHAR})
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
@ -53,9 +52,6 @@
|
|||||||
<if test="version != null">
|
<if test="version != null">
|
||||||
version = #{version,jdbcType=VARCHAR},
|
version = #{version,jdbcType=VARCHAR},
|
||||||
</if>
|
</if>
|
||||||
<if test="name != null">
|
|
||||||
name = #{name,jdbcType=VARCHAR},
|
|
||||||
</if>
|
|
||||||
<if test="code != null">
|
<if test="code != null">
|
||||||
code = #{code,jdbcType=VARCHAR},
|
code = #{code,jdbcType=VARCHAR},
|
||||||
</if>
|
</if>
|
||||||
@ -83,9 +79,6 @@
|
|||||||
<if test="version != null">
|
<if test="version != null">
|
||||||
and version = #{version,jdbcType=VARCHAR}
|
and version = #{version,jdbcType=VARCHAR}
|
||||||
</if>
|
</if>
|
||||||
<if test="name != null">
|
|
||||||
and name = #{name,jdbcType=VARCHAR}
|
|
||||||
</if>
|
|
||||||
<if test="code != null">
|
<if test="code != null">
|
||||||
and code = #{code,jdbcType=VARCHAR}
|
and code = #{code,jdbcType=VARCHAR}
|
||||||
</if>
|
</if>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user