LedHandlerYangBandV4d2.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package com.gzlh.device.led.handler.impl;
  2. import cn.hutool.core.math.MathUtil;
  3. import cn.hutool.core.util.NumberUtil;
  4. import cn.hutool.core.util.StrUtil;
  5. import com.gzlh.device.led.brand.LedBrandType;
  6. import com.gzlh.device.led.client.LedNettyConfig;
  7. import com.gzlh.device.led.handler.ILedHandler;
  8. import com.gzlh.device.led.tools.*;
  9. import com.gzlh.device.led.utils.ColorConver;
  10. import com.gzlh.device.led.utils.LedOptions;
  11. import com.gzlh.device.led.utils.SystemCharsets;
  12. import com.gzlh.device.led.utils.YangBandPackage;
  13. import com.gzlh.utils.WordHandlerUtils;
  14. import com.gzlh.utils.XorUtils;
  15. import lombok.extern.slf4j.Slf4j;
  16. import org.springframework.stereotype.Service;
  17. import javax.annotation.Resource;
  18. import java.nio.charset.StandardCharsets;
  19. import java.util.ArrayList;
  20. import java.util.List;
  21. /**
  22. * 上海仰邦科技股份有限公司BX-5(M)K/6K(YY)-V4.2 led发送处理器
  23. */
  24. @Service
  25. @Slf4j
  26. public class LedHandlerYangBandV4d2 implements ILedHandler {
  27. @Resource
  28. private LedNettyConfig ledNettyConfig;
  29. @Override
  30. public LedBrandType brandType() {
  31. return LedBrandType.SHANGHAI_YANGBAND_BX;
  32. }
  33. /**
  34. * 颜色支持 红 绿\\C 蓝
  35. *
  36. * @param content
  37. * @param ledOptions
  38. */
  39. @Override
  40. public void sendMsg(String content, LedOptions ledOptions) {
  41. String line = ledOptions.getLine();
  42. byte id = (byte) (Integer.parseInt(line) - 1);
  43. short x = 0;
  44. short w = 64;
  45. short h = 16;
  46. short y = (short) NumberUtil.mul(Integer.parseInt(line) - 1, 16);
  47. List<BxArea> areas = new ArrayList<>();
  48. byte[] datas = ("\\C" + Integer.parseInt(ledOptions.getColor()) + content).getBytes(SystemCharsets.GB2312);
  49. BxAreaDynamic BxArea = new BxAreaDynamic(id, x, y, w, h, datas, true);
  50. if (ledOptions.isSay()) {
  51. BxArea.setSoundMode((byte) 0x02);
  52. // 人声模式
  53. BxArea.setSoundPerson((byte) 0x00);
  54. // 重复次数
  55. BxArea.setSoundRepeat((byte) 0x01);
  56. // 发音速度
  57. BxArea.setSoundSpeed((byte) 0x02);
  58. // 音量
  59. BxArea.setSoundVolume((byte) 10);
  60. // 要发声的文字,仅在 soundMode = 0x02时有效
  61. BxArea.setSoundData(content.getBytes(SystemCharsets.GB2312));
  62. }
  63. // 显示方式,其定义如下:
  64. // 0x01——静止显示
  65. // 0x02——快速打出
  66. // 0x03——向左移动
  67. // 0x04——向右移动
  68. // 0x05——向上移动
  69. // 0x06——向下移动
  70. // 设置显示方式为 0x03 - 向左移动
  71. BxArea.setDispMode((byte) 0x03);
  72. // 设置停留时间
  73. BxArea.setHoldTime((byte) 0);
  74. areas.add(BxArea);
  75. // 创建一个发送动态区命令
  76. BxCmd cmd = new BxCmdSendDynamicArea(areas);
  77. // 对命令进行封装
  78. BxDataPack dataPack = new BxDataPack(cmd);
  79. // 生成命令序列
  80. byte[] seq = dataPack.pack();
  81. String pack = XorUtils.bytesToHex(seq);
  82. log.info(LedBrandType.SHANGHAI_YANGBAND_BX.getBrand() + "发送消息:{}", content);
  83. //String pack = YangBandPackage.buildPackage(ColorConver.NU_TO_HEX.get(1) + WordHandlerUtils.msgToASCII(content));
  84. log.info(LedBrandType.SHANGHAI_YANGBAND_BX.getBrand() + "转换后的数据:{}", pack);
  85. ledNettyConfig.send(pack);
  86. }
  87. /**
  88. * 特殊站位符 ${platNo}
  89. *
  90. * @param action
  91. */
  92. @Override
  93. public void handlerAction(String action) {
  94. log.info("action:{}", action);
  95. }
  96. public static void main(String[] args) {
  97. System.out.println((byte) (Integer.parseInt("02") - 1));
  98. }
  99. }