|
@@ -7,67 +7,73 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
@Slf4j
|
|
|
public class FengLiYuanPackUtils {
|
|
|
- private static final String HEADER_HEX="F501";
|
|
|
+ private static final String HEADER_HEX = "F501";
|
|
|
+
|
|
|
/**
|
|
|
* 构建
|
|
|
+ *
|
|
|
* @param message 发送的信息
|
|
|
- * @param line 行号
|
|
|
+ * @param line 行号
|
|
|
* @return 起始字 F501 长度(从[屏地址]到[数据]最后字节) 屏地址 00 命令 01 发送 01 数据 总包校
|
|
|
* 验
|
|
|
*/
|
|
|
- public static String build(String message, LedOptions options){
|
|
|
+ public static String build(String message, LedOptions options) {
|
|
|
+ return build(message, "02", options);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String build(String message, String type, LedOptions options) {
|
|
|
//消息的15进制
|
|
|
- String msgHex= WordHandlerUtils.msgToASCII(message);
|
|
|
- int msgLength= msgHex.length();
|
|
|
- String msgLenHex=Integer.toHexString(msgLength/2);
|
|
|
- if (msgLenHex.length()==1){
|
|
|
- msgLenHex="0"+msgLenHex;
|
|
|
- }
|
|
|
- String line= options.getLine();
|
|
|
- String showType= options.getShowType();
|
|
|
- if (StrUtil.isEmpty(showType)){
|
|
|
- showType="00";
|
|
|
+ String msgHex = WordHandlerUtils.msgToASCII(message);
|
|
|
+ int msgLength = msgHex.length();
|
|
|
+ String msgLenHex = Integer.toHexString(msgLength / 2);
|
|
|
+ if (msgLenHex.length() == 1) {
|
|
|
+ msgLenHex = "0" + msgLenHex;
|
|
|
+ }
|
|
|
+ String line = options.getLine();
|
|
|
+ String showType = options.getShowType();
|
|
|
+ if (StrUtil.isEmpty(showType)) {
|
|
|
+ showType = "00";
|
|
|
}
|
|
|
- String color= options.getColor();
|
|
|
- if (StrUtil.isEmpty(color)){
|
|
|
- color="01";
|
|
|
+ String color = options.getColor();
|
|
|
+ if (StrUtil.isEmpty(color)) {
|
|
|
+ color = "01";
|
|
|
}
|
|
|
//内容=行号(01->08)+显示方式(00左移入)+日期显示方式(00固定信息)+速度(00->02)+颜色(01红色)+固定信息长度(xx)+message
|
|
|
- String content=line+showType+"0001"+color+msgLenHex+msgHex;
|
|
|
- //屏地址-->数据包内容
|
|
|
- String packData="000101"+content;
|
|
|
- int packLength=packData.length();
|
|
|
- String packLengthHex= Integer.toHexString(packLength/2);
|
|
|
- if (packLengthHex.length()==2){
|
|
|
- packLengthHex="00"+packLengthHex;
|
|
|
- }else if (packLengthHex.length()==1){
|
|
|
- packLengthHex="000"+packLengthHex;
|
|
|
+ String content = line + showType + options.getTime() + "01" + color + msgLenHex + msgHex;
|
|
|
+ //屏地址-->数据包内容
|
|
|
+ String packData = "00" + type + "01" + content;
|
|
|
+ int packLength = packData.length();
|
|
|
+ String packLengthHex = Integer.toHexString(packLength / 2);
|
|
|
+ if (packLengthHex.length() == 2) {
|
|
|
+ packLengthHex = "00" + packLengthHex;
|
|
|
+ } else if (packLengthHex.length() == 1) {
|
|
|
+ packLengthHex = "000" + packLengthHex;
|
|
|
}
|
|
|
//长度->内容
|
|
|
- String dataContent= packLengthHex+packData;
|
|
|
+ String dataContent = packLengthHex + packData;
|
|
|
//异或校验
|
|
|
- String xor= XorUtils.xor(HEADER_HEX+dataContent);
|
|
|
+ String xor = XorUtils.xor(HEADER_HEX + dataContent);
|
|
|
//将特殊字节做处理
|
|
|
- String str=dataContent+xor;
|
|
|
- int len=str.length();
|
|
|
- StringBuilder sb=new StringBuilder();
|
|
|
- for (int i=0;i<len;i+=2){
|
|
|
- String hex= str.substring(i,i+2);
|
|
|
- if (hex.equals("F5")){
|
|
|
- hex="FA05";
|
|
|
- }else if (hex.equals("FA")){
|
|
|
- hex="FA0A";
|
|
|
+ String str = dataContent + xor;
|
|
|
+ int len = str.length();
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ for (int i = 0; i < len; i += 2) {
|
|
|
+ String hex = str.substring(i, i + 2);
|
|
|
+ if (hex.equals("F5")) {
|
|
|
+ hex = "FA05";
|
|
|
+ } else if (hex.equals("FA")) {
|
|
|
+ hex = "FA0A";
|
|
|
}
|
|
|
sb.append(hex);
|
|
|
}
|
|
|
|
|
|
- return HEADER_HEX+sb;
|
|
|
+ return HEADER_HEX + sb;
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
- LedOptions ledOptions=new LedOptions();
|
|
|
+ LedOptions ledOptions = new LedOptions();
|
|
|
ledOptions.setColor("05").setLine("02").setShowType("0B");
|
|
|
- System.out.println(build("桂A132V1",ledOptions));
|
|
|
+ System.out.println(build("桂A132V1", ledOptions));
|
|
|
|
|
|
}
|
|
|
|