|
@@ -1,6 +1,8 @@
|
|
|
package com.charging.chargingparking.utils;
|
|
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
|
|
|
public class LedTcProtocol {
|
|
|
|
|
@@ -104,6 +106,143 @@ public class LedTcProtocol {
|
|
|
return frame;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送多行文本到设备
|
|
|
+ * @param arr 多行文本
|
|
|
+ * @param displayModes 0立即显示,1由右向左滚动,2自动换行显示
|
|
|
+ * @return
|
|
|
+ * @throws UnsupportedEncodingException
|
|
|
+ */
|
|
|
+ public static byte[] sendMultilineText(String[] arr,int[] displayModes) throws UnsupportedEncodingException {
|
|
|
+ List<byte[]> areaList = new ArrayList<>();
|
|
|
+
|
|
|
+ int areaTotalLen = 0;
|
|
|
+
|
|
|
+ for(int i=0;i<arr.length;i++){
|
|
|
+ //显示文本
|
|
|
+ byte[] textBytes = arr[i].getBytes("GB2312");
|
|
|
+
|
|
|
+ //数据包
|
|
|
+ //区域编号(1)+显示类型(1)+区域X坐标(2)+区域Y坐标(2)+本区域使用宽度(2)+本区域使用高度(2)+字体大小(1)+字体颜色(1)
|
|
|
+ //+显示特效(1)+滚动速度(1)+文本显示时长(2)+显示退出特效(1)+显示本文的字节数(2)+文本
|
|
|
+ byte[] area = new byte[1+1+2+2+2+2+1+1+1+1+2+1+2+textBytes.length];
|
|
|
+
|
|
|
+ //00:区域本区域编号
|
|
|
+ area[0] = (byte)i;
|
|
|
+
|
|
|
+ //00:显示文本;01显示时间
|
|
|
+ area[1] = 0x00;
|
|
|
+
|
|
|
+ //0000:区域X坐标,高字节在前低字节在后;0~31
|
|
|
+ area[2] = 0x00;
|
|
|
+ area[3] = 0x00;
|
|
|
+
|
|
|
+ int y = 16*i;
|
|
|
+
|
|
|
+ //0000:区域Y坐标,高字节在前低字节在后;0~63
|
|
|
+ area[4] = (byte)(y>>8 & 0xff);
|
|
|
+ area[5] = (byte)(y & 0xff);
|
|
|
+
|
|
|
+ //0040:本区域使用宽度;16的倍数,默认为屏幕宽度(0x40 = 64)
|
|
|
+ area[6] = 0x00;
|
|
|
+ area[7] = 0x40;
|
|
|
+
|
|
|
+ //000F:本区域使用高度;16的倍数减1,默认为屏幕宽度(0x0F = 15)
|
|
|
+ area[8] = 0x00;
|
|
|
+ area[9] = 0x0F;
|
|
|
+
|
|
|
+ //10:字体大小;16字体或32字体。0x10 = 16
|
|
|
+ area[10] = 0x10;
|
|
|
+
|
|
|
+ //00:字体颜色,0红色,1绿色,2黄色,3蓝色,4紫色,5青色,6白色;需硬件支持
|
|
|
+ area[11] = 0x00;
|
|
|
+
|
|
|
+ //00:显示特效,0立即显示,1由右向左滚动,2自动换行显示,3向上滚动进入,4分屏显示
|
|
|
+ area[12] = (byte)displayModes[i];
|
|
|
+
|
|
|
+ //00:滚动速度,只有特效为滚动时才生效,取值范围0~10;
|
|
|
+ area[13] = 0x00;
|
|
|
+
|
|
|
+ //001E:文本显示时长,单位:秒;高字节在前低字节在后。
|
|
|
+ area[14] = 0x00;
|
|
|
+ area[15] = 0x1E;
|
|
|
+
|
|
|
+ //00:显示退出特效,00立即退出;
|
|
|
+ area[16] = 0x00;
|
|
|
+
|
|
|
+ //0008:显示本文的字节数,后续数据字节数;
|
|
|
+ area[17] = (byte)((textBytes.length>>8) & 0xff);
|
|
|
+ area[18] = (byte)(textBytes.length & 0xff);
|
|
|
+
|
|
|
+ //显示文本的字符内码
|
|
|
+ for (int j = 0; j < textBytes.length; j++) {
|
|
|
+ area[19+j] = textBytes[j];
|
|
|
+ }
|
|
|
+
|
|
|
+ areaList.add(area);
|
|
|
+ areaTotalLen += area.length;
|
|
|
+ }
|
|
|
+
|
|
|
+ //区域数量(1)+[区域1序号(1)+区域1数据字节数(1)+区域1数据,区域2序号+区域2数据字节数+区域2数据...]
|
|
|
+ byte[] section = new byte[1 + 2*areaList.size() + areaTotalLen];
|
|
|
+
|
|
|
+ //01 区域数量
|
|
|
+ int index = 0;
|
|
|
+ section[index] = (byte)areaList.size();
|
|
|
+ index++;
|
|
|
+
|
|
|
+ for (int i = 0; i < areaList.size(); i++) {
|
|
|
+ byte[] area = areaList.get(i);
|
|
|
+ //00:区域序号;从0开始
|
|
|
+ section[index] = 0;
|
|
|
+ index++;
|
|
|
+
|
|
|
+ //1B:第一个区域的数据长度,本区域后续数据字节数
|
|
|
+ section[index] = (byte)area.length;
|
|
|
+ index++;
|
|
|
+
|
|
|
+ //区域数据
|
|
|
+ for (int j = 0; j < area.length; j++) {
|
|
|
+ section[index] =area[j];
|
|
|
+ index++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+// byte[] programInfo = new byte[22];
|
|
|
+//
|
|
|
+// String hexStr = "46303154001E00000000235959201012312030123100";
|
|
|
+//
|
|
|
+// for (int i=0;i<programInfo.length;i++){
|
|
|
+// programInfo[i] = Integer.valueOf(hexStr.substring(i*2,i*2+2),16).byteValue();
|
|
|
+// }
|
|
|
+
|
|
|
+ //命令(1)+设备应答(1)+数据长度(2)+数据
|
|
|
+ byte[] dataField = new byte[1+1+2+section.length];
|
|
|
+
|
|
|
+ //0B:命令,显示屏显示文本,0D:下载节目信息
|
|
|
+ dataField[0] = (byte) 0x0B;
|
|
|
+
|
|
|
+ //00:设备无需应答;02则需要应答
|
|
|
+ dataField[1] = (byte) 0x00;
|
|
|
+
|
|
|
+ //后续数据长度
|
|
|
+ dataField[2] = (byte)(section.length >> 8);
|
|
|
+ dataField[3]= (byte)(section.length & 0xFF);
|
|
|
+
|
|
|
+// for (int i = 0; i < programInfo.length; i++) {
|
|
|
+// dataField[4 + i] = programInfo[i];
|
|
|
+// }
|
|
|
+
|
|
|
+ for (int i = 0; i < section.length; i++) {
|
|
|
+ dataField[4 +i] = section[i];
|
|
|
+ }
|
|
|
+
|
|
|
+ byte[] frame = createFrame(dataField);
|
|
|
+
|
|
|
+ return frame;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 创建帧数据
|
|
|
* @param dataField
|