package com.gzlh.device.led.handler.impl; import cn.hutool.core.math.MathUtil; import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.StrUtil; import com.gzlh.device.led.brand.LedBrandType; import com.gzlh.device.led.client.LedNettyConfig; import com.gzlh.device.led.handler.ILedHandler; import com.gzlh.device.led.tools.*; import com.gzlh.device.led.utils.ColorConver; import com.gzlh.device.led.utils.LedOptions; import com.gzlh.device.led.utils.SystemCharsets; import com.gzlh.device.led.utils.YangBandPackage; import com.gzlh.utils.WordHandlerUtils; import com.gzlh.utils.XorUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; /** * 上海仰邦科技股份有限公司BX-5(M)K/6K(YY)-V4.2 led发送处理器 */ @Service @Slf4j public class LedHandlerYangBandV4d2 implements ILedHandler { @Resource private LedNettyConfig ledNettyConfig; @Override public LedBrandType brandType() { return LedBrandType.SHANGHAI_YANGBAND_BX; } /** * 颜色支持 红 绿\\C 蓝 * * @param content * @param ledOptions */ @Override public void sendMsg(String content, LedOptions ledOptions) { String line = ledOptions.getLine(); byte id = (byte) (Integer.parseInt(line) - 1); short x = 0; short w = 64; short h = 16; short y = (short) NumberUtil.mul(Integer.parseInt(line) - 1, 16); List areas = new ArrayList<>(); byte[] datas = ("\\C" + Integer.parseInt(ledOptions.getColor()) + content).getBytes(SystemCharsets.GB2312); BxAreaDynamic BxArea = new BxAreaDynamic(id, x, y, w, h, datas, true); if (ledOptions.isSay()) { BxArea.setSoundMode((byte) 0x02); // 人声模式 BxArea.setSoundPerson((byte) 0x00); // 重复次数 BxArea.setSoundRepeat((byte) 0x01); // 发音速度 BxArea.setSoundSpeed((byte) 0x02); // 音量 BxArea.setSoundVolume((byte) 10); // 要发声的文字,仅在 soundMode = 0x02时有效 BxArea.setSoundData(content.getBytes(SystemCharsets.GB2312)); } // 显示方式,其定义如下: // 0x01——静止显示 // 0x02——快速打出 // 0x03——向左移动 // 0x04——向右移动 // 0x05——向上移动 // 0x06——向下移动 // 设置显示方式为 0x03 - 向左移动 BxArea.setDispMode((byte) 0x03); // 设置停留时间 BxArea.setHoldTime((byte) 0); areas.add(BxArea); // 创建一个发送动态区命令 BxCmd cmd = new BxCmdSendDynamicArea(areas); // 对命令进行封装 BxDataPack dataPack = new BxDataPack(cmd); // 生成命令序列 byte[] seq = dataPack.pack(); String pack = XorUtils.bytesToHex(seq); log.info(LedBrandType.SHANGHAI_YANGBAND_BX.getBrand() + "发送消息:{}", content); //String pack = YangBandPackage.buildPackage(ColorConver.NU_TO_HEX.get(1) + WordHandlerUtils.msgToASCII(content)); log.info(LedBrandType.SHANGHAI_YANGBAND_BX.getBrand() + "转换后的数据:{}", pack); ledNettyConfig.send(pack); } /** * 特殊站位符 ${platNo} * * @param action */ @Override public void handlerAction(String action) { log.info("action:{}", action); } public static void main(String[] args) { System.out.println((byte) (Integer.parseInt("02") - 1)); } }