From 3e672ca38c6df5c77443906331b427440697b530 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Sat, 16 Mar 2024 23:22:07 +0800 Subject: [PATCH] =?UTF-8?q?1078-=E6=94=AF=E6=8C=81=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=E6=B1=87=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/vmp/jt1078/bean/JTAlarmSign.java | 80 +++++++++++++++++++ .../iot/vmp/jt1078/bean/JTPositionInfo.java | 14 ++++ .../iot/vmp/jt1078/bean/JTStatus.java | 67 +++++++++++++++- .../iot/vmp/jt1078/proc/request/J0200.java | 54 ++++++------- .../iot/vmp/jt1078/util/BCDUtil.java | 17 ++++ 5 files changed, 202 insertions(+), 30 deletions(-) create mode 100644 src/main/java/com/genersoft/iot/vmp/jt1078/util/BCDUtil.java diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/bean/JTAlarmSign.java b/src/main/java/com/genersoft/iot/vmp/jt1078/bean/JTAlarmSign.java index a9775cd9a..6133090fd 100644 --- a/src/main/java/com/genersoft/iot/vmp/jt1078/bean/JTAlarmSign.java +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/bean/JTAlarmSign.java @@ -73,6 +73,49 @@ public class JTAlarmSign { @Schema(description = "侧翻预警") private boolean warningRollover; + public JTAlarmSign() { + } + + public JTAlarmSign(int alarmSignInt) { + if (alarmSignInt == 0) { + return; + } + // 解析alarm参数 + this.urgent = (alarmSignInt & 1) == 1; + this.alarmSpeeding = (alarmSignInt >> 1 & 1) == 1; + this.alarmTired = (alarmSignInt >> 2 & 1) == 1; + this.alarmDangerous = (alarmSignInt >> 3 & 1) == 1; + this.alarmGnssFault = (alarmSignInt >> 4 & 1) == 1; + this.alarmGnssBreak = (alarmSignInt >> 5 & 1) == 1; + this.alarmGnssShortCircuited = (alarmSignInt >> 6 & 1) == 1; + this.alarmUnderVoltage = (alarmSignInt >> 7 & 1) == 1; + this.alarmPowerOff = (alarmSignInt >> 8 & 1) == 1; + this.alarmLCD = (alarmSignInt >> 9 & 1) == 1; + this.alarmTtsFault = (alarmSignInt >> 10 & 1) == 1; + this.alarmCameraFault = (alarmSignInt >> 11 & 1) == 1; + this.alarmIcFault = (alarmSignInt >> 12 & 1) == 1; + this.warningSpeeding = (alarmSignInt >> 13 & 1) == 1; + this.warningTired = (alarmSignInt >> 14 & 1) == 1; + this.alarmwrong = (alarmSignInt >> 15 & 1) == 1; + this.warningTirePressure = (alarmSignInt >> 16 & 1) == 1; + this.alarmBlindZone = (alarmSignInt >> 17 & 1) == 1; + this.alarmDrivingTimeout = (alarmSignInt >> 18 & 1) == 1; + this.alarmParkingTimeout = (alarmSignInt >> 19 & 1) == 1; + this.alarmRegion = (alarmSignInt >> 20 & 1) == 1; + this.alarmRoute = (alarmSignInt >> 21 & 1) == 1; + this.alarmTravelTime = (alarmSignInt >> 22 & 1) == 1; + this.alarmRouteDeviation = (alarmSignInt >> 23 & 1) == 1; + this.alarmVSS = (alarmSignInt >> 24 & 1) == 1; + this.alarmOil = (alarmSignInt >> 25 & 1) == 1; + this.alarmStolen = (alarmSignInt >> 26 & 1) == 1; + this.alarmIllegalIgnition = (alarmSignInt >> 27 & 1) == 1; + this.alarmIllegalDisplacement = (alarmSignInt >> 28 & 1) == 1; + this.alarmRollover = (alarmSignInt >> 29 & 1) == 1; + this.warningRollover = (alarmSignInt >> 30 & 1) == 1; + + } + + public boolean isUrgent() { return urgent; } @@ -320,4 +363,41 @@ public class JTAlarmSign { public void setWarningRollover(boolean warningRollover) { this.warningRollover = warningRollover; } + + @Override + public String toString() { + return "状态报警标志位:" + + "\n 紧急报警:" + (urgent?"开":"关") + + "\n 超速报警:" + (alarmSpeeding?"开":"关") + + "\n 疲劳驾驶报警:" + (alarmTired?"开":"关") + + "\n 危险驾驶行为报警:" + (alarmDangerous?"开":"关") + + "\n GNSS 模块发生故障报警:" + (alarmGnssFault?"开":"关") + + "\n GNSS 天线未接或被剪断报警:" + (alarmGnssBreak?"开":"关") + + "\n GNSS 天线短路报警:" + (alarmGnssShortCircuited?"开":"关") + + "\n 终端主电源欠压报警:" + (alarmUnderVoltage?"开":"关") + + "\n 终端主电源掉电报警:" + (alarmPowerOff?"开":"关") + + "\n 终端LCD或显示器故障报警:" + (alarmLCD?"开":"关") + + "\n TTS 模块故障报警:" + (alarmTtsFault?"开":"关") + + "\n 摄像头故障报警:" + (alarmCameraFault?"开":"关") + + "\n 道路运输证IC卡模块故障报警:" + (alarmIcFault?"开":"关") + + "\n 超速预警:" + (warningSpeeding?"开":"关") + + "\n 疲劳驾驶预警:" + (warningTired?"开":"关") + + "\n 违规行驶报警:" + (alarmwrong?"开":"关") + + "\n 胎压预警:" + (warningTirePressure?"开":"关") + + "\n 右转盲区异常报警:" + (alarmBlindZone?"开":"关") + + "\n 当天累计驾驶超时报警:" + (alarmDrivingTimeout?"开":"关") + + "\n 超时停车报警:" + (alarmParkingTimeout?"开":"关") + + "\n 进出区域报警:" + (alarmRegion?"开":"关") + + "\n 进出路线报警:" + (alarmRoute?"开":"关") + + "\n 路段行驶时间不足/过长报警:" + (alarmTravelTime?"开":"关") + + "\n 路线偏离报警:" + (alarmRouteDeviation?"开":"关") + + "\n 车辆 VSS 故障:" + (alarmVSS?"开":"关") + + "\n 车辆油量异常报警:" + (alarmOil?"开":"关") + + "\n 车辆被盗报警(通过车辆防盗器):" + (alarmStolen?"开":"关") + + "\n 车辆非法点火报警:" + (alarmIllegalIgnition?"开":"关") + + "\n 车辆非法位移报警:" + (alarmIllegalDisplacement?"开":"关") + + "\n 碰撞侧翻报警:" + (alarmRollover?"开":"关") + + "\n 侧翻预警:" + (warningRollover?"开":"关") + + "\n "; + } } diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/bean/JTPositionInfo.java b/src/main/java/com/genersoft/iot/vmp/jt1078/bean/JTPositionInfo.java index 08c6f7a47..f8cdfb2e5 100644 --- a/src/main/java/com/genersoft/iot/vmp/jt1078/bean/JTPositionInfo.java +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/bean/JTPositionInfo.java @@ -116,4 +116,18 @@ public class JTPositionInfo { public void setTime(String time) { this.time = time; } + + @Override + public String toString() { + return "位置汇报信息: " + + " \n 报警标志:" + alarmSign.toString() + + " \n 状态:" + status.toString() + + " \n 经度:" + longitude + + " \n 纬度:" + latitude + + " \n 高程: " + altitude + + " \n 速度: " + speed + + " \n 方向: " + direction + + " \n 时间: " + time + + " \n"; + } } diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/bean/JTStatus.java b/src/main/java/com/genersoft/iot/vmp/jt1078/bean/JTStatus.java index ebe79cb49..3a508b539 100644 --- a/src/main/java/com/genersoft/iot/vmp/jt1078/bean/JTStatus.java +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/bean/JTStatus.java @@ -70,7 +70,39 @@ public class JTStatus { private boolean gaLiLeo; @Schema(description = "false:车辆处于停止状态;true:车辆处于行驶状态") - private boolean Driving; + private boolean driving; + + public JTStatus() { + } + + public JTStatus(int statusInt) { + if (statusInt == 0) { + return; + } + this.acc = (statusInt & 1) == 1; + this.positioning = (statusInt >> 1 & 1) == 1; + this.southLatitude = (statusInt >> 2 & 1) == 1; + this.wesLongitude = (statusInt >> 3 & 1) == 1; + this.outage = (statusInt >> 4 & 1) == 1; + this.positionEncryption = (statusInt >> 5 & 1) == 1; + this.warningFrontCrash = (statusInt >> 6 & 1) == 1; + this.warningShifting = (statusInt >> 7 & 1) == 1; + this.load = (statusInt >> 8 & 3); + this.oilWayBreak = (statusInt >> 10 & 1) == 1; + this.circuitBreak = (statusInt >> 11 & 1) == 1; + this.doorLocking = (statusInt >> 12 & 1) == 1; + this.door1Open = (statusInt >> 13 & 1) == 1; + this.door2Open = (statusInt >> 14 & 1) == 1; + this.door3Open = (statusInt >> 15 & 1) == 1; + this.door4Open = (statusInt >> 16 & 1) == 1; + this.door5Open = (statusInt >> 17 & 1) == 1; + this.gps = (statusInt >> 18 & 1) == 1; + this.beidou = (statusInt >> 19 & 1) == 1; + this.glonass = (statusInt >> 20 & 1) == 1; + this.gaLiLeo = (statusInt >> 21 & 1) == 1; + this.driving = (statusInt >> 22 & 1) == 1; + } + public boolean isAcc() { return acc; @@ -241,10 +273,39 @@ public class JTStatus { } public boolean isDriving() { - return Driving; + return driving; } public void setDriving(boolean driving) { - Driving = driving; + this.driving = driving; + } + + @Override + public String toString() { + return "状态位:" + + "\n acc状态:" + (acc?"开":"关") + + "\n 定位状态:" + (positioning?"定位":"未定位") + + "\n 南北纬:" + (southLatitude?"南纬":"北纬") + + "\n 东西经:" + (wesLongitude?"西经":"东经") + + "\n 运营状态:" + (outage?"停运":"运营") + + "\n 经纬度保密:" + (positionEncryption?"加密":"未加密") + + "\n 前撞预警:" + (warningFrontCrash?"紧急刹车系统采集的前撞预警":"无") + + "\n 车道偏移预警:" + (warningShifting?"车道偏移预警":"无") + + "\n 空/半/满载状态:" + (load == 0?"空车":(load == 1?"半载":(load == 3?"满载":"未定义状态"))) + + "\n 车辆油路状态:" + (oilWayBreak?"车辆油路断开":"车辆油路正常") + + "\n 车辆电路状态:" + (circuitBreak?"车辆电路断开":"车辆电路正常") + + "\n 门锁状态:" + (doorLocking?"车门加锁":"车门解锁") + + "\n 门1(前门)状态:" + (door1Open?"开":"关") + + "\n 门2(中门)状态:" + (door2Open?"开":"关") + + "\n 门3(后门)状态:" + (door3Open?"开":"关") + + "\n 门4(驾驶席门)状态:" + (door4Open?"开":"关") + + "\n 门5(自定义)状态:" + (door5Open?"开":"关") + + "\n GPS卫星定位状态: " + (gps?"使用":"未使用") + + "\n 北斗卫星定位状态: " + (beidou?"使用":"未使用") + + "\n GLONASS卫星定位状态: " + (glonass?"使用":"未使用") + + "\n GaLiLeo卫星定位状态: " + (gaLiLeo?"使用":"未使用") + + "\n GaLiLeo卫星定位状态: " + (gaLiLeo?"使用":"未使用") + + "\n 车辆行驶状态: " + (driving?"车辆行驶":"车辆停止") + + "\n "; } } diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/proc/request/J0200.java b/src/main/java/com/genersoft/iot/vmp/jt1078/proc/request/J0200.java index 7c4840d11..f418efd48 100644 --- a/src/main/java/com/genersoft/iot/vmp/jt1078/proc/request/J0200.java +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/proc/request/J0200.java @@ -1,13 +1,19 @@ package com.genersoft.iot.vmp.jt1078.proc.request; import com.genersoft.iot.vmp.jt1078.annotation.MsgId; +import com.genersoft.iot.vmp.jt1078.bean.JTAlarmSign; +import com.genersoft.iot.vmp.jt1078.bean.JTDevice; import com.genersoft.iot.vmp.jt1078.bean.JTPositionInfo; +import com.genersoft.iot.vmp.jt1078.bean.JTStatus; import com.genersoft.iot.vmp.jt1078.proc.Header; import com.genersoft.iot.vmp.jt1078.proc.response.J8001; import com.genersoft.iot.vmp.jt1078.proc.response.Rs; import com.genersoft.iot.vmp.jt1078.service.Ijt1078Service; import com.genersoft.iot.vmp.jt1078.session.Session; +import com.genersoft.iot.vmp.jt1078.util.BCDUtil; import io.netty.buffer.ByteBuf; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.context.ApplicationEvent; /** @@ -20,50 +26,44 @@ import org.springframework.context.ApplicationEvent; @MsgId(id = "0200") public class J0200 extends Re { + private final static Logger log = LoggerFactory.getLogger(J0100.class); private JTPositionInfo positionInfo; @Override protected Rs decode0(ByteBuf buf, Header header, Session session) { positionInfo = new JTPositionInfo(); int alarmSignInt = buf.readInt(); + positionInfo.setAlarmSign(new JTAlarmSign(alarmSignInt)); + int statusInt = buf.readInt(); - int latitudeInt = buf.readInt(); - int longitudeInt = buf.readInt(); - int altitudeInt = buf.readUnsignedShort(); - int speedInt = buf.readUnsignedShort(); - int directionInt = buf.readUnsignedShort(); + positionInfo.setStatus(new JTStatus(statusInt)); + + positionInfo.setLatitude(buf.readInt() * 0.000001D); + positionInfo.setLongitude(buf.readInt() * 0.000001D); + positionInfo.setAltitude(buf.readUnsignedShort()); + positionInfo.setSpeed(buf.readUnsignedShort()); + positionInfo.setDirection(buf.readUnsignedShort()); byte[] timeBytes = new byte[6]; buf.readBytes(timeBytes); - System.out.println(alarmSignInt); - System.out.println(statusInt); - System.out.println(latitudeInt); - System.out.println(longitudeInt); - System.out.println(altitudeInt); - System.out.println(speedInt); - System.out.println(directionInt); - // TODO 解析时间 -// for (byte timeByte : timeBytes) { -// for (int i = 0; i < 8; i++) { -// System.out.print(timeByte>>i & 1); -// } -// } - StringBuffer temp = new StringBuffer(timeBytes.length * 2); - for (int i = 0; i < timeBytes.length; i++) { - temp.append((byte) ((timeBytes[i] & 0xf0) >>> 4)); - temp.append((byte) (timeBytes[i] & 0x0f)); - } - - System.out.println(temp.toString().substring(0, 1).equalsIgnoreCase("0") ? temp - .toString().substring(1) : temp.toString()); + positionInfo.setTime(BCDUtil.transform(timeBytes)); + log.info("[JT-位置汇报]: {}", positionInfo.toString()); return null; } @Override protected Rs handler(Header header, Session session, Ijt1078Service service) { + JTDevice deviceInDb = service.getDevice(header.getTerminalId()); J8001 j8001 = new J8001(); j8001.setRespNo(header.getSn()); j8001.setRespId(header.getMsgId()); - j8001.setResult(J8001.SUCCESS); + if (deviceInDb == null) { + j8001.setResult(J8001.FAIL); + }else { + deviceInDb.setLongitude(positionInfo.getLongitude()); + deviceInDb.setLatitude(positionInfo.getLatitude()); + service.updateDevice(deviceInDb); + j8001.setResult(J8001.SUCCESS); + } return j8001; } diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/util/BCDUtil.java b/src/main/java/com/genersoft/iot/vmp/jt1078/util/BCDUtil.java new file mode 100644 index 000000000..b4ba8211c --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/util/BCDUtil.java @@ -0,0 +1,17 @@ +package com.genersoft.iot.vmp.jt1078.util; + +public class BCDUtil { + + public static String transform(byte[] bytes) { + if (bytes.length == 0) { + return null; + } + // BCD[6] 解析时间 + StringBuffer temp = new StringBuffer(bytes.length * 2); + for (int i = 0; i < bytes.length; i++) { + temp.append((byte) ((bytes[i] & 0xf0) >>> 4)); + temp.append((byte) (bytes[i] & 0x0f)); + } + return temp.toString(); + } +}