| | |
| | | import io.netty.util.CharsetUtil; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springblade.modules.netty.business.entity.PoliceCarEquipment; |
| | | import org.springblade.modules.netty.business.service.PoliceCarEquipmentService; |
| | | import org.springblade.modules.netty.business.entity.TalkBackEquipment; |
| | | import org.springblade.modules.netty.business.service.TalkBackEquipmentService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import javax.annotation.PostConstruct; |
| | |
| | | private static UdpServerHandler udpServerHandler; |
| | | |
| | | @Autowired |
| | | private PoliceCarEquipmentService policeCarEquipmentService; |
| | | private TalkBackEquipmentService talkBackEquipmentService; |
| | | |
| | | @PostConstruct |
| | | public void init() { |
| | | udpServerHandler = this; |
| | | udpServerHandler.policeCarEquipmentService = this.policeCarEquipmentService; |
| | | udpServerHandler.talkBackEquipmentService = this.talkBackEquipmentService; |
| | | } |
| | | |
| | | @Override |
| | |
| | | // 字节转16进制字符串 |
| | | String s = bytesToHexString(req); |
| | | //获取字符串的长度 |
| | | // int length = s.length(); |
| | | int length = s.length(); |
| | | // System.out.println("数据长度>>>>>> = " + length); |
| | | //数据解析 |
| | | dataHandler(s); |
| | |
| | | private void dataHandler(String s) { |
| | | // s = "AAAACCCC220000000033373933343732393100000000000000000000000052D50451F77D5D406C04E275FD723C400000015F0000000507E70306103B0A"; |
| | | //创建设备对象 |
| | | PoliceCarEquipment backEquipment = new PoliceCarEquipment(); |
| | | TalkBackEquipment backEquipment = new TalkBackEquipment(); |
| | | if (s.substring(4,8).equals("CCCC")) { |
| | | backEquipment.setStatus(1); |
| | | } |
| | |
| | | backEquipment.setStatus(0); |
| | | } |
| | | //截取字符串 |
| | | String terminalNumber = hexStr2Str(s.substring(20, 60)); |
| | | // char[20] 后面跟了 \0000 空字符串 |
| | | // String trim = terminalNumber.trim(); |
| | | backEquipment.setTerminalNumber(terminalNumber); |
| | | backEquipment.setTerminalNumber(hexStr2Str(s.substring(20, 60))); |
| | | |
| | | backEquipment.setLongitude(Double.toString(getDouble(s.substring(60, 76)))); |
| | | |
| | |
| | | } |
| | | backEquipment.setUpdateTime(new Date()); |
| | | // 新增 |
| | | udpServerHandler.policeCarEquipmentService.save(backEquipment); |
| | | udpServerHandler.talkBackEquipmentService.save(backEquipment); |
| | | } |
| | | |
| | | /** |
| | |
| | | return sb.toString(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 捕获异常 |
| | | * @param ctx |