1078-支持位置汇报

This commit is contained in:
648540858
2024-03-16 23:22:07 +08:00
parent 9bc9dbe43b
commit 3e672ca38c
5 changed files with 202 additions and 30 deletions

View File

@@ -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 ";
}
}

View File

@@ -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";
}
}

View File

@@ -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 ";
}
}

View File

@@ -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;
}

View File

@@ -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();
}
}