package com.ld.igds.protocol.bhzn.inout;
|
|
import com.ld.igds.inout.ApiInoutService;
|
import com.ld.igds.inout.dto.ApiInoutData;
|
import com.ld.igds.inout.dto.InoutData;
|
import com.ld.igds.io.constant.ProtocolEnum;
|
import com.ld.igds.protocol.bhzn.inout.client.BHZNClientEngine;
|
import com.ld.igds.protocol.bhzn.utils.CRC16;
|
import com.ld.igds.util.BytesUtil;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.stereotype.Component;
|
|
import java.io.UnsupportedEncodingException;
|
|
/**
|
* @Desc: 地磅主控协议实现,出入库相关接口
|
*/
|
@Slf4j
|
@Component
|
public class BHZNWeightServiceImpl implements ApiInoutService {
|
|
// @Autowired
|
// private Inoutservice inoutservice;
|
|
@Override
|
public String getProtocol() {
|
return ProtocolEnum.TCP_BHZH_INOUT_V1.getCode();
|
}
|
|
/**
|
* @param param
|
* @return
|
*/
|
@Override
|
public ApiInoutData getPlateNum(ApiInoutData param) {
|
return param;
|
}
|
|
/**
|
* 不需要实现
|
*
|
* @param param
|
* @return
|
*/
|
@Override
|
public String initLpr(ApiInoutData param) {
|
return "当前模式无需初始化车牌识别";
|
}
|
|
|
/**
|
* 暂时不实现
|
*
|
* @param param deviceId和actionCode 不可为空
|
* @return
|
*/
|
@Override
|
public String gateControl(ApiInoutData param) {
|
try{
|
// ReqGate reqGate = new ReqGate();
|
BHZNClientEngine test = new BHZNClientEngine(
|
param.getIp(), param.getPort());
|
test.start();
|
String msg = "<BHZN>{\"cmd\":226,\"content\":{" +
|
"\"value\":[1,1]," +
|
"\"LEDValue\":[1,1]" +
|
"},\"orderId\":\"5009\",\"result\":\"\",\"sign\":\"0000\",\"stNum\":1,\"version\":\"V1.0000000\"}<END>";
|
|
// Thread.sleep(3000L);
|
|
test.send(BytesUtil.hexStrToBytes(msg));
|
}catch (Exception e){
|
log.error(e.getMessage(),e);
|
return "ERROR";
|
}
|
|
return "SUCCESS";
|
}
|
|
@Override
|
public String lightControl(ApiInoutData param) {
|
return null;
|
}
|
|
@Override
|
public String noticeRadio(ApiInoutData param, InoutData data) {
|
return null;
|
}
|
|
@Override
|
public String noticeLed(ApiInoutData param, InoutData data) {
|
// todo
|
|
return null;
|
}
|
|
/**
|
* 增加白名单 --调用子线程实现
|
*
|
* @param param deviceId和actionCode 不可为空
|
* @return
|
*/
|
public String addWhitePlate(ApiInoutData param) {
|
|
return "SUCCESS";
|
}
|
|
/**
|
* 删除白名单---调用子线程实现
|
*
|
* @param param
|
* @return
|
*/
|
public String delWhitePlate(ApiInoutData param) {
|
|
return "SUCCESS";
|
}
|
|
|
/**
|
* @param param
|
* @return
|
*/
|
@Override
|
public ApiInoutData getIcCardNum(ApiInoutData param) {
|
return param;
|
}
|
|
|
|
public static void main(String[] args) {
|
try{
|
String str1 = "许彬",str2="粤A123456",str3 = "3号仓" ,str4 = "小麦",str5="286000",str6 = "30000",str7 ="合格";
|
String test = "我爱中航软件";
|
//78340100290000000000000000 1400 0B00 01 02 00 01 0C 00
|
|
String lengh = BytesUtil.tran_LH(BytesUtil.intToHexStr(8+test.length()));
|
String msg = "78340100290000000000000000 " + lengh+ "0B00010200010C00";
|
msg = msg + convertStr(test);
|
msg = msg.toUpperCase();
|
|
// String t = "78 34 01 00 29 BC FD 00 00 00 00 00 00 14 00 01 00 01 02 06 01 0C 00 CE D2 B0 AE D6 D0 BA BD C8 ED BC FE";
|
// t = t.replaceAll(" ","");
|
String check = BytesUtil.tran_LH(BytesUtil.intToHexStr(CRC16.calcCrc16(BytesUtil.hexStrToBytes(msg))));
|
System.out.println(check);
|
|
msg+=check;
|
msg += "A5";
|
|
System.out.println(msg);
|
}catch (Exception e){
|
e.printStackTrace();
|
}
|
|
|
}
|
|
|
|
|
//hexToBytes方法:十六进制字符串转byte[],网上很多
|
//getRepair0方法:补0的,很简单,自己实现吧
|
/**
|
*
|
* new StringBuffer(str).reverse()
|
* 转ask码
|
* @param msg
|
* @return
|
* @throws UnsupportedEncodingException
|
*/
|
public static String convertStr(String msg) throws Exception {
|
//先把字符串按gb2312转成byte数组
|
byte[] bytes = msg.getBytes("gb2312");
|
StringBuilder gbString = new StringBuilder();
|
|
for (byte b : bytes)
|
{
|
// 再用Integer中的方法,把每个byte转换成16进制输出
|
String temp = Integer.toHexString(b);
|
//判断进行截取
|
if(temp.length()>=8){
|
temp = temp.substring(6, 8);
|
}
|
gbString.append(temp);
|
}
|
return gbString.toString();
|
}
|
}
|