GPS数据转换接收
parent
79771ee6e5
commit
5fbe3be8d2
@ -0,0 +1,104 @@
|
||||
package com.ruoyi.basetyre.controller;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.basetyre.domain.CollectMachineGps;
|
||||
import com.ruoyi.basetyre.service.ICollectMachineGpsService;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* GPS记录Controller
|
||||
*
|
||||
* @author Yangwl
|
||||
* @date 2023-02-28
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/basetyre/CollectMachineGps")
|
||||
public class CollectMachineGpsController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private ICollectMachineGpsService collectMachineGpsService;
|
||||
|
||||
/**
|
||||
* 查询GPS记录列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('basetyre:CollectMachineGps:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(CollectMachineGps collectMachineGps)
|
||||
{
|
||||
startPage();
|
||||
List<CollectMachineGps> list = collectMachineGpsService.selectCollectMachineGpsList(collectMachineGps);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出GPS记录列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('basetyre:CollectMachineGps:export')")
|
||||
@Log(title = "GPS记录", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, CollectMachineGps collectMachineGps)
|
||||
{
|
||||
List<CollectMachineGps> list = collectMachineGpsService.selectCollectMachineGpsList(collectMachineGps);
|
||||
ExcelUtil<CollectMachineGps> util = new ExcelUtil<CollectMachineGps>(CollectMachineGps.class);
|
||||
util.exportExcel(response, list, "GPS记录数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取GPS记录详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('basetyre:CollectMachineGps:query')")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") String id)
|
||||
{
|
||||
return success(collectMachineGpsService.selectCollectMachineGpsById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增GPS记录
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('basetyre:CollectMachineGps:add')")
|
||||
@Log(title = "GPS记录", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody CollectMachineGps collectMachineGps)
|
||||
{
|
||||
return toAjax(collectMachineGpsService.insertCollectMachineGps(collectMachineGps));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改GPS记录
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('basetyre:CollectMachineGps:edit')")
|
||||
@Log(title = "GPS记录", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody CollectMachineGps collectMachineGps)
|
||||
{
|
||||
return toAjax(collectMachineGpsService.updateCollectMachineGps(collectMachineGps));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除GPS记录
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('basetyre:CollectMachineGps:remove')")
|
||||
@Log(title = "GPS记录", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable String[] ids)
|
||||
{
|
||||
return toAjax(collectMachineGpsService.deleteCollectMachineGpsByIds(ids));
|
||||
}
|
||||
}
|
@ -0,0 +1,432 @@
|
||||
package com.ruoyi.basetyre.domain;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.ruoyi.common.annotation.Excel;
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* GPS记录对象 collect_machine_gps
|
||||
*
|
||||
* @author Yangwl
|
||||
* @date 2023-02-28
|
||||
*/
|
||||
public class CollectMachineGps extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** $column.columnComment */
|
||||
private String id;
|
||||
|
||||
/** 收发器id */
|
||||
@Excel(name = "收发器id")
|
||||
private String machineId;
|
||||
|
||||
/** 车辆id */
|
||||
@Excel(name = "车辆id")
|
||||
private String carId;
|
||||
|
||||
/** 车牌号 */
|
||||
@Excel(name = "车牌号")
|
||||
private String carLicense;
|
||||
|
||||
/** 紧急报警 */
|
||||
@Excel(name = "紧急报警")
|
||||
private Long emergencyAlarm;
|
||||
|
||||
/** 超速预警 */
|
||||
@Excel(name = "超速预警")
|
||||
private Long speedAlarm;
|
||||
|
||||
/** 疲劳驾驶 */
|
||||
@Excel(name = "疲劳驾驶")
|
||||
private Long fatigueDrivingAlarm;
|
||||
|
||||
/** 危险预警 */
|
||||
@Excel(name = "危险预警")
|
||||
private Long riskEarlyAlarm;
|
||||
|
||||
/** gnss模块 */
|
||||
@Excel(name = "gnss模块")
|
||||
private Long gnssModule;
|
||||
|
||||
/** 天线缺失 */
|
||||
@Excel(name = "天线缺失")
|
||||
private Long gnssLossAntenna;
|
||||
|
||||
/** 天线短路 */
|
||||
@Excel(name = "天线短路")
|
||||
private Long gnssAntennaShortcircuit;
|
||||
|
||||
/** 终端主电源欠压 */
|
||||
@Excel(name = "终端主电源欠压")
|
||||
private Long mainPowerLake;
|
||||
|
||||
/** 终端主电源掉电 */
|
||||
@Excel(name = "终端主电源掉电")
|
||||
private Long mainpowerloss;
|
||||
|
||||
/** $column.columnComment */
|
||||
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
|
||||
private Long accclose;
|
||||
|
||||
/** $column.columnComment */
|
||||
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
|
||||
private Long unpositioned;
|
||||
|
||||
/** 0北纬1南纬 */
|
||||
@Excel(name = "0北纬1南纬")
|
||||
private Long dimensionalNOrS;
|
||||
|
||||
/** 0东经1西经 */
|
||||
@Excel(name = "0东经1西经")
|
||||
private Long longitudinalEOrW;
|
||||
|
||||
/** $column.columnComment */
|
||||
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
|
||||
private Long dLIsencryption;
|
||||
|
||||
/** 纬度 */
|
||||
@Excel(name = "纬度")
|
||||
private double latitude;
|
||||
|
||||
/** 经度 */
|
||||
@Excel(name = "经度")
|
||||
private double longitude;
|
||||
|
||||
/** 海拔 */
|
||||
@Excel(name = "海拔")
|
||||
private Long altitude;
|
||||
|
||||
/** 速度 */
|
||||
@Excel(name = "速度")
|
||||
private Long speed;
|
||||
|
||||
/** 方向 */
|
||||
@Excel(name = "方向")
|
||||
private Long course;
|
||||
|
||||
/** $column.columnComment */
|
||||
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
|
||||
private Long gpsIntensity;
|
||||
|
||||
/** $column.columnComment */
|
||||
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
|
||||
private Long gpsSatellites;
|
||||
|
||||
/** GPS里程 */
|
||||
@Excel(name = "GPS里程")
|
||||
private Long gpsMileage;
|
||||
|
||||
/** 是否外接电源 */
|
||||
@Excel(name = "是否外接电源")
|
||||
private Long isOutPower;
|
||||
|
||||
/** 设备上传电池电压 */
|
||||
@Excel(name = "设备上传电池电压")
|
||||
private Long carPower;
|
||||
|
||||
/** 胎压设备是否正常工作 */
|
||||
@Excel(name = "胎压设备是否正常工作")
|
||||
private Long isSensorRun;
|
||||
|
||||
public void setId(String id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
public void setMachineId(String machineId)
|
||||
{
|
||||
this.machineId = machineId;
|
||||
}
|
||||
|
||||
public String getMachineId()
|
||||
{
|
||||
return machineId;
|
||||
}
|
||||
public void setCarId(String carId)
|
||||
{
|
||||
this.carId = carId;
|
||||
}
|
||||
|
||||
public String getCarId()
|
||||
{
|
||||
return carId;
|
||||
}
|
||||
public void setCarLicense(String carLicense)
|
||||
{
|
||||
this.carLicense = carLicense;
|
||||
}
|
||||
|
||||
public String getCarLicense()
|
||||
{
|
||||
return carLicense;
|
||||
}
|
||||
public void setEmergencyAlarm(Long emergencyAlarm)
|
||||
{
|
||||
this.emergencyAlarm = emergencyAlarm;
|
||||
}
|
||||
|
||||
public Long getEmergencyAlarm()
|
||||
{
|
||||
return emergencyAlarm;
|
||||
}
|
||||
public void setSpeedAlarm(Long speedAlarm)
|
||||
{
|
||||
this.speedAlarm = speedAlarm;
|
||||
}
|
||||
|
||||
public Long getSpeedAlarm()
|
||||
{
|
||||
return speedAlarm;
|
||||
}
|
||||
public void setFatigueDrivingAlarm(Long fatigueDrivingAlarm)
|
||||
{
|
||||
this.fatigueDrivingAlarm = fatigueDrivingAlarm;
|
||||
}
|
||||
|
||||
public Long getFatigueDrivingAlarm()
|
||||
{
|
||||
return fatigueDrivingAlarm;
|
||||
}
|
||||
public void setRiskEarlyAlarm(Long riskEarlyAlarm)
|
||||
{
|
||||
this.riskEarlyAlarm = riskEarlyAlarm;
|
||||
}
|
||||
|
||||
public Long getRiskEarlyAlarm()
|
||||
{
|
||||
return riskEarlyAlarm;
|
||||
}
|
||||
public void setGnssModule(Long gnssModule)
|
||||
{
|
||||
this.gnssModule = gnssModule;
|
||||
}
|
||||
|
||||
public Long getGnssModule()
|
||||
{
|
||||
return gnssModule;
|
||||
}
|
||||
public void setGnssLossAntenna(Long gnssLossAntenna)
|
||||
{
|
||||
this.gnssLossAntenna = gnssLossAntenna;
|
||||
}
|
||||
|
||||
public Long getGnssLossAntenna()
|
||||
{
|
||||
return gnssLossAntenna;
|
||||
}
|
||||
public void setGnssAntennaShortcircuit(Long gnssAntennaShortcircuit)
|
||||
{
|
||||
this.gnssAntennaShortcircuit = gnssAntennaShortcircuit;
|
||||
}
|
||||
|
||||
public Long getGnssAntennaShortcircuit()
|
||||
{
|
||||
return gnssAntennaShortcircuit;
|
||||
}
|
||||
public void setMainPowerLake(Long mainPowerLake)
|
||||
{
|
||||
this.mainPowerLake = mainPowerLake;
|
||||
}
|
||||
|
||||
public Long getMainPowerLake()
|
||||
{
|
||||
return mainPowerLake;
|
||||
}
|
||||
public void setMainpowerloss(Long mainpowerloss)
|
||||
{
|
||||
this.mainpowerloss = mainpowerloss;
|
||||
}
|
||||
|
||||
public Long getMainpowerloss()
|
||||
{
|
||||
return mainpowerloss;
|
||||
}
|
||||
public void setAccclose(Long accclose)
|
||||
{
|
||||
this.accclose = accclose;
|
||||
}
|
||||
|
||||
public Long getAccclose()
|
||||
{
|
||||
return accclose;
|
||||
}
|
||||
public void setUnpositioned(Long unpositioned)
|
||||
{
|
||||
this.unpositioned = unpositioned;
|
||||
}
|
||||
|
||||
public Long getUnpositioned()
|
||||
{
|
||||
return unpositioned;
|
||||
}
|
||||
public void setDimensionalNOrS(Long dimensionalNOrS)
|
||||
{
|
||||
this.dimensionalNOrS = dimensionalNOrS;
|
||||
}
|
||||
|
||||
public Long getDimensionalNOrS()
|
||||
{
|
||||
return dimensionalNOrS;
|
||||
}
|
||||
public void setLongitudinalEOrW(Long longitudinalEOrW)
|
||||
{
|
||||
this.longitudinalEOrW = longitudinalEOrW;
|
||||
}
|
||||
|
||||
public Long getLongitudinalEOrW()
|
||||
{
|
||||
return longitudinalEOrW;
|
||||
}
|
||||
public void setdLIsencryption(Long dLIsencryption)
|
||||
{
|
||||
this.dLIsencryption = dLIsencryption;
|
||||
}
|
||||
|
||||
public Long getdLIsencryption()
|
||||
{
|
||||
return dLIsencryption;
|
||||
}
|
||||
public void setLatitude(double latitude)
|
||||
{
|
||||
this.latitude = latitude;
|
||||
}
|
||||
|
||||
public double getLatitude()
|
||||
{
|
||||
return latitude;
|
||||
}
|
||||
public void setLongitude(double longitude)
|
||||
{
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
public double getLongitude()
|
||||
{
|
||||
return longitude;
|
||||
}
|
||||
public void setAltitude(Long altitude)
|
||||
{
|
||||
this.altitude = altitude;
|
||||
}
|
||||
|
||||
public Long getAltitude()
|
||||
{
|
||||
return altitude;
|
||||
}
|
||||
public void setSpeed(Long speed)
|
||||
{
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
public Long getSpeed()
|
||||
{
|
||||
return speed;
|
||||
}
|
||||
public void setCourse(Long course)
|
||||
{
|
||||
this.course = course;
|
||||
}
|
||||
|
||||
public Long getCourse()
|
||||
{
|
||||
return course;
|
||||
}
|
||||
public void setGpsIntensity(Long gpsIntensity)
|
||||
{
|
||||
this.gpsIntensity = gpsIntensity;
|
||||
}
|
||||
|
||||
public Long getGpsIntensity()
|
||||
{
|
||||
return gpsIntensity;
|
||||
}
|
||||
public void setGpsSatellites(Long gpsSatellites)
|
||||
{
|
||||
this.gpsSatellites = gpsSatellites;
|
||||
}
|
||||
|
||||
public Long getGpsSatellites()
|
||||
{
|
||||
return gpsSatellites;
|
||||
}
|
||||
public void setGpsMileage(Long gpsMileage)
|
||||
{
|
||||
this.gpsMileage = gpsMileage;
|
||||
}
|
||||
|
||||
public Long getGpsMileage()
|
||||
{
|
||||
return gpsMileage;
|
||||
}
|
||||
public void setIsOutPower(Long isOutPower)
|
||||
{
|
||||
this.isOutPower = isOutPower;
|
||||
}
|
||||
|
||||
public Long getIsOutPower()
|
||||
{
|
||||
return isOutPower;
|
||||
}
|
||||
public void setCarPower(Long carPower)
|
||||
{
|
||||
this.carPower = carPower;
|
||||
}
|
||||
|
||||
public Long getCarPower()
|
||||
{
|
||||
return carPower;
|
||||
}
|
||||
public void setIsSensorRun(Long isSensorRun)
|
||||
{
|
||||
this.isSensorRun = isSensorRun;
|
||||
}
|
||||
|
||||
public Long getIsSensorRun()
|
||||
{
|
||||
return isSensorRun;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("id", getId())
|
||||
.append("machineId", getMachineId())
|
||||
.append("carId", getCarId())
|
||||
.append("carLicense", getCarLicense())
|
||||
.append("emergencyAlarm", getEmergencyAlarm())
|
||||
.append("speedAlarm", getSpeedAlarm())
|
||||
.append("fatigueDrivingAlarm", getFatigueDrivingAlarm())
|
||||
.append("riskEarlyAlarm", getRiskEarlyAlarm())
|
||||
.append("gnssModule", getGnssModule())
|
||||
.append("gnssLossAntenna", getGnssLossAntenna())
|
||||
.append("gnssAntennaShortcircuit", getGnssAntennaShortcircuit())
|
||||
.append("mainPowerLake", getMainPowerLake())
|
||||
.append("mainpowerloss", getMainpowerloss())
|
||||
.append("accclose", getAccclose())
|
||||
.append("unpositioned", getUnpositioned())
|
||||
.append("dimensionalNOrS", getDimensionalNOrS())
|
||||
.append("longitudinalEOrW", getLongitudinalEOrW())
|
||||
.append("dLIsencryption", getdLIsencryption())
|
||||
.append("latitude", getLatitude())
|
||||
.append("longitude", getLongitude())
|
||||
.append("altitude", getAltitude())
|
||||
.append("speed", getSpeed())
|
||||
.append("course", getCourse())
|
||||
.append("createTime", getCreateTime())
|
||||
.append("gpsIntensity", getGpsIntensity())
|
||||
.append("gpsSatellites", getGpsSatellites())
|
||||
.append("gpsMileage", getGpsMileage())
|
||||
.append("isOutPower", getIsOutPower())
|
||||
.append("carPower", getCarPower())
|
||||
.append("isSensorRun", getIsSensorRun())
|
||||
.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package com.ruoyi.basetyre.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.basetyre.domain.CollectMachineGps;
|
||||
|
||||
/**
|
||||
* GPS记录Mapper接口
|
||||
*
|
||||
* @author Yangwl
|
||||
* @date 2023-02-28
|
||||
*/
|
||||
public interface CollectMachineGpsMapper
|
||||
{
|
||||
/**
|
||||
* 查询GPS记录
|
||||
*
|
||||
* @param id GPS记录主键
|
||||
* @return GPS记录
|
||||
*/
|
||||
public CollectMachineGps selectCollectMachineGpsById(String id);
|
||||
|
||||
/**
|
||||
* 查询GPS记录列表
|
||||
*
|
||||
* @param collectMachineGps GPS记录
|
||||
* @return GPS记录集合
|
||||
*/
|
||||
public List<CollectMachineGps> selectCollectMachineGpsList(CollectMachineGps collectMachineGps);
|
||||
|
||||
/**
|
||||
* 新增GPS记录
|
||||
*
|
||||
* @param collectMachineGps GPS记录
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertCollectMachineGps(CollectMachineGps collectMachineGps);
|
||||
|
||||
/**
|
||||
* 修改GPS记录
|
||||
*
|
||||
* @param collectMachineGps GPS记录
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateCollectMachineGps(CollectMachineGps collectMachineGps);
|
||||
|
||||
/**
|
||||
* 删除GPS记录
|
||||
*
|
||||
* @param id GPS记录主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteCollectMachineGpsById(String id);
|
||||
|
||||
/**
|
||||
* 批量删除GPS记录
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteCollectMachineGpsByIds(String[] ids);
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package com.ruoyi.basetyre.redislistener;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.ruoyi.basetyre.domain.CollectMachineGps;
|
||||
import com.ruoyi.basetyre.service.ICollectMachineGpsService;
|
||||
import com.ruoyi.common.t808.model.T0200;
|
||||
import com.ruoyi.common.t808.model.T0704;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.uuid.UUID;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.connection.Message;
|
||||
import org.springframework.data.redis.connection.MessageListener;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class RedisMessageListener implements MessageListener {
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
@Autowired
|
||||
private ICollectMachineGpsService iCollectMachineGpsService;
|
||||
|
||||
@Override
|
||||
public void onMessage(Message message, byte[] pattern) {
|
||||
// 获取消息
|
||||
byte[] messageBody = message.getBody();
|
||||
// 使用值序列化器转换
|
||||
Object msg = redisTemplate.getValueSerializer().deserialize(messageBody);
|
||||
// 获取监听的频道
|
||||
byte[] channelByte = message.getChannel();
|
||||
// 使用字符串序列化器转换
|
||||
Object channel = redisTemplate.getStringSerializer().deserialize(channelByte);
|
||||
// 渠道名称转换
|
||||
String patternStr = new String(pattern);
|
||||
System.out.println(patternStr);
|
||||
System.out.println("---频道---: " + channel);
|
||||
System.out.println("---消息内容---: " + msg);
|
||||
CollectMachineGps collectMachineGps =new CollectMachineGps();
|
||||
switch (patternStr){
|
||||
case "0704":
|
||||
T0704 t0704 = JSON.parseObject(JSON.toJSONString(msg),T0704.class);
|
||||
for (T0200 t0200:t0704.getItems()) {
|
||||
collectMachineGps.setId(UUID.randomUUID().toString());
|
||||
collectMachineGps.setMachineId(t0704.getClientId());
|
||||
collectMachineGps.setLatitude(((double)t0200.getLatitude()/1000000));
|
||||
collectMachineGps.setLongitude(((double)t0200.getLongitude()/1000000));
|
||||
collectMachineGps.setAltitude((long) t0200.getAltitude());
|
||||
collectMachineGps.setSpeed((long) t0200.getSpeed());
|
||||
collectMachineGps.setCreateTime(DateUtils.getNowDate());
|
||||
iCollectMachineGpsService.insertCollectMachineGps(collectMachineGps);
|
||||
}
|
||||
break;
|
||||
case "0200":
|
||||
List<T0200> t0200List = JSON.parseArray(JSON.toJSONString(msg),T0200.class);
|
||||
T0200 t0200 = t0200List.get(0);
|
||||
collectMachineGps.setId(UUID.randomUUID().toString());
|
||||
collectMachineGps.setMachineId(t0200.getClientId());
|
||||
collectMachineGps.setLatitude(((double)t0200.getLatitude()/1000000));
|
||||
collectMachineGps.setLongitude(((double)t0200.getLongitude()/1000000));
|
||||
collectMachineGps.setAltitude((long) t0200.getAltitude());
|
||||
collectMachineGps.setSpeed((long) t0200.getSpeed());
|
||||
collectMachineGps.setCreateTime(DateUtils.getNowDate());
|
||||
iCollectMachineGpsService.insertCollectMachineGps(collectMachineGps);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package com.ruoyi.basetyre.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.basetyre.domain.CollectMachineGps;
|
||||
|
||||
/**
|
||||
* GPS记录Service接口
|
||||
*
|
||||
* @author Yangwl
|
||||
* @date 2023-02-28
|
||||
*/
|
||||
public interface ICollectMachineGpsService
|
||||
{
|
||||
/**
|
||||
* 查询GPS记录
|
||||
*
|
||||
* @param id GPS记录主键
|
||||
* @return GPS记录
|
||||
*/
|
||||
public CollectMachineGps selectCollectMachineGpsById(String id);
|
||||
|
||||
/**
|
||||
* 查询GPS记录列表
|
||||
*
|
||||
* @param collectMachineGps GPS记录
|
||||
* @return GPS记录集合
|
||||
*/
|
||||
public List<CollectMachineGps> selectCollectMachineGpsList(CollectMachineGps collectMachineGps);
|
||||
|
||||
/**
|
||||
* 新增GPS记录
|
||||
*
|
||||
* @param collectMachineGps GPS记录
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertCollectMachineGps(CollectMachineGps collectMachineGps);
|
||||
|
||||
/**
|
||||
* 修改GPS记录
|
||||
*
|
||||
* @param collectMachineGps GPS记录
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateCollectMachineGps(CollectMachineGps collectMachineGps);
|
||||
|
||||
/**
|
||||
* 批量删除GPS记录
|
||||
*
|
||||
* @param ids 需要删除的GPS记录主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteCollectMachineGpsByIds(String[] ids);
|
||||
|
||||
/**
|
||||
* 删除GPS记录信息
|
||||
*
|
||||
* @param id GPS记录主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteCollectMachineGpsById(String id);
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
package com.ruoyi.basetyre.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.basetyre.mapper.CollectMachineGpsMapper;
|
||||
import com.ruoyi.basetyre.domain.CollectMachineGps;
|
||||
import com.ruoyi.basetyre.service.ICollectMachineGpsService;
|
||||
|
||||
/**
|
||||
* GPS记录Service业务层处理
|
||||
*
|
||||
* @author Yangwl
|
||||
* @date 2023-02-28
|
||||
*/
|
||||
@Service
|
||||
public class CollectMachineGpsServiceImpl implements ICollectMachineGpsService
|
||||
{
|
||||
@Autowired
|
||||
private CollectMachineGpsMapper collectMachineGpsMapper;
|
||||
|
||||
/**
|
||||
* 查询GPS记录
|
||||
*
|
||||
* @param id GPS记录主键
|
||||
* @return GPS记录
|
||||
*/
|
||||
@Override
|
||||
public CollectMachineGps selectCollectMachineGpsById(String id)
|
||||
{
|
||||
return collectMachineGpsMapper.selectCollectMachineGpsById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询GPS记录列表
|
||||
*
|
||||
* @param collectMachineGps GPS记录
|
||||
* @return GPS记录
|
||||
*/
|
||||
@Override
|
||||
public List<CollectMachineGps> selectCollectMachineGpsList(CollectMachineGps collectMachineGps)
|
||||
{
|
||||
return collectMachineGpsMapper.selectCollectMachineGpsList(collectMachineGps);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增GPS记录
|
||||
*
|
||||
* @param collectMachineGps GPS记录
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertCollectMachineGps(CollectMachineGps collectMachineGps)
|
||||
{
|
||||
return collectMachineGpsMapper.insertCollectMachineGps(collectMachineGps);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改GPS记录
|
||||
*
|
||||
* @param collectMachineGps GPS记录
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateCollectMachineGps(CollectMachineGps collectMachineGps)
|
||||
{
|
||||
return collectMachineGpsMapper.updateCollectMachineGps(collectMachineGps);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除GPS记录
|
||||
*
|
||||
* @param ids 需要删除的GPS记录主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteCollectMachineGpsByIds(String[] ids)
|
||||
{
|
||||
return collectMachineGpsMapper.deleteCollectMachineGpsByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除GPS记录信息
|
||||
*
|
||||
* @param id GPS记录主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteCollectMachineGpsById(String id)
|
||||
{
|
||||
return collectMachineGpsMapper.deleteCollectMachineGpsById(id);
|
||||
}
|
||||
}
|
@ -0,0 +1,198 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.basetyre.mapper.CollectMachineGpsMapper">
|
||||
|
||||
<resultMap type="CollectMachineGps" id="CollectMachineGpsResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="machineId" column="machine_id" />
|
||||
<result property="carId" column="car_id" />
|
||||
<result property="carLicense" column="car_license" />
|
||||
<result property="emergencyAlarm" column="emergency_alarm" />
|
||||
<result property="speedAlarm" column="speed_alarm" />
|
||||
<result property="fatigueDrivingAlarm" column="fatigue_driving_alarm" />
|
||||
<result property="riskEarlyAlarm" column="risk_early_alarm" />
|
||||
<result property="gnssModule" column="gnss_module" />
|
||||
<result property="gnssLossAntenna" column="gnss_loss_antenna" />
|
||||
<result property="gnssAntennaShortcircuit" column="gnss_antenna_shortcircuit" />
|
||||
<result property="mainPowerLake" column="main_power_lake" />
|
||||
<result property="mainpowerloss" column="mainpowerloss" />
|
||||
<result property="accclose" column="accclose" />
|
||||
<result property="unpositioned" column="unpositioned" />
|
||||
<result property="dimensionalNOrS" column="dimensional_n_or_s" />
|
||||
<result property="longitudinalEOrW" column="longitudinal_e_or_w" />
|
||||
<result property="dLIsencryption" column="d_l_isencryption" />
|
||||
<result property="latitude" column="latitude" />
|
||||
<result property="longitude" column="longitude" />
|
||||
<result property="altitude" column="altitude" />
|
||||
<result property="speed" column="speed" />
|
||||
<result property="course" column="course" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="gpsIntensity" column="gps_intensity" />
|
||||
<result property="gpsSatellites" column="gps_satellites" />
|
||||
<result property="gpsMileage" column="gps_mileage" />
|
||||
<result property="isOutPower" column="is_out_power" />
|
||||
<result property="carPower" column="car_power" />
|
||||
<result property="isSensorRun" column="is_sensor_run" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectCollectMachineGpsVo">
|
||||
select id, machine_id, car_id, car_license, emergency_alarm, speed_alarm, fatigue_driving_alarm, risk_early_alarm, gnss_module, gnss_loss_antenna, gnss_antenna_shortcircuit, main_power_lake, mainpowerloss, accclose, unpositioned, dimensional_n_or_s, longitudinal_e_or_w, d_l_isencryption, latitude, longitude, altitude, speed, course, create_time, gps_intensity, gps_satellites, gps_mileage, is_out_power, car_power, is_sensor_run from collect_machine_gps
|
||||
</sql>
|
||||
|
||||
<select id="selectCollectMachineGpsList" parameterType="CollectMachineGps" resultMap="CollectMachineGpsResult">
|
||||
<include refid="selectCollectMachineGpsVo"/>
|
||||
<where>
|
||||
<if test="machineId != null and machineId != ''"> and machine_id = #{machineId}</if>
|
||||
<if test="carId != null and carId != ''"> and car_id = #{carId}</if>
|
||||
<if test="carLicense != null and carLicense != ''"> and car_license = #{carLicense}</if>
|
||||
<if test="emergencyAlarm != null "> and emergency_alarm = #{emergencyAlarm}</if>
|
||||
<if test="speedAlarm != null "> and speed_alarm = #{speedAlarm}</if>
|
||||
<if test="fatigueDrivingAlarm != null "> and fatigue_driving_alarm = #{fatigueDrivingAlarm}</if>
|
||||
<if test="riskEarlyAlarm != null "> and risk_early_alarm = #{riskEarlyAlarm}</if>
|
||||
<if test="gnssModule != null "> and gnss_module = #{gnssModule}</if>
|
||||
<if test="gnssLossAntenna != null "> and gnss_loss_antenna = #{gnssLossAntenna}</if>
|
||||
<if test="gnssAntennaShortcircuit != null "> and gnss_antenna_shortcircuit = #{gnssAntennaShortcircuit}</if>
|
||||
<if test="mainPowerLake != null "> and main_power_lake = #{mainPowerLake}</if>
|
||||
<if test="mainpowerloss != null "> and mainpowerloss = #{mainpowerloss}</if>
|
||||
<if test="accclose != null "> and accclose = #{accclose}</if>
|
||||
<if test="unpositioned != null "> and unpositioned = #{unpositioned}</if>
|
||||
<if test="dimensionalNOrS != null "> and dimensional_n_or_s = #{dimensionalNOrS}</if>
|
||||
<if test="longitudinalEOrW != null "> and longitudinal_e_or_w = #{longitudinalEOrW}</if>
|
||||
<if test="dLIsencryption != null "> and d_l_isencryption = #{dLIsencryption}</if>
|
||||
<if test="latitude != null "> and latitude = #{latitude}</if>
|
||||
<if test="longitude != null "> and longitude = #{longitude}</if>
|
||||
<if test="altitude != null "> and altitude = #{altitude}</if>
|
||||
<if test="speed != null "> and speed = #{speed}</if>
|
||||
<if test="course != null "> and course = #{course}</if>
|
||||
<if test="createTime != null "> and create_time = #{createTime}</if>
|
||||
<if test="gpsIntensity != null "> and gps_intensity = #{gpsIntensity}</if>
|
||||
<if test="gpsSatellites != null "> and gps_satellites = #{gpsSatellites}</if>
|
||||
<if test="gpsMileage != null "> and gps_mileage = #{gpsMileage}</if>
|
||||
<if test="isOutPower != null "> and is_out_power = #{isOutPower}</if>
|
||||
<if test="carPower != null "> and car_power = #{carPower}</if>
|
||||
<if test="isSensorRun != null "> and is_sensor_run = #{isSensorRun}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectCollectMachineGpsById" parameterType="String" resultMap="CollectMachineGpsResult">
|
||||
<include refid="selectCollectMachineGpsVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<insert id="insertCollectMachineGps" parameterType="CollectMachineGps">
|
||||
insert into collect_machine_gps
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">id,</if>
|
||||
<if test="machineId != null">machine_id,</if>
|
||||
<if test="carId != null">car_id,</if>
|
||||
<if test="carLicense != null">car_license,</if>
|
||||
<if test="emergencyAlarm != null">emergency_alarm,</if>
|
||||
<if test="speedAlarm != null">speed_alarm,</if>
|
||||
<if test="fatigueDrivingAlarm != null">fatigue_driving_alarm,</if>
|
||||
<if test="riskEarlyAlarm != null">risk_early_alarm,</if>
|
||||
<if test="gnssModule != null">gnss_module,</if>
|
||||
<if test="gnssLossAntenna != null">gnss_loss_antenna,</if>
|
||||
<if test="gnssAntennaShortcircuit != null">gnss_antenna_shortcircuit,</if>
|
||||
<if test="mainPowerLake != null">main_power_lake,</if>
|
||||
<if test="mainpowerloss != null">mainpowerloss,</if>
|
||||
<if test="accclose != null">accclose,</if>
|
||||
<if test="unpositioned != null">unpositioned,</if>
|
||||
<if test="dimensionalNOrS != null">dimensional_n_or_s,</if>
|
||||
<if test="longitudinalEOrW != null">longitudinal_e_or_w,</if>
|
||||
<if test="dLIsencryption != null">d_l_isencryption,</if>
|
||||
<if test="latitude != null">latitude,</if>
|
||||
<if test="longitude != null">longitude,</if>
|
||||
<if test="altitude != null">altitude,</if>
|
||||
<if test="speed != null">speed,</if>
|
||||
<if test="course != null">course,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="gpsIntensity != null">gps_intensity,</if>
|
||||
<if test="gpsSatellites != null">gps_satellites,</if>
|
||||
<if test="gpsMileage != null">gps_mileage,</if>
|
||||
<if test="isOutPower != null">is_out_power,</if>
|
||||
<if test="carPower != null">car_power,</if>
|
||||
<if test="isSensorRun != null">is_sensor_run,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">#{id},</if>
|
||||
<if test="machineId != null">#{machineId},</if>
|
||||
<if test="carId != null">#{carId},</if>
|
||||
<if test="carLicense != null">#{carLicense},</if>
|
||||
<if test="emergencyAlarm != null">#{emergencyAlarm},</if>
|
||||
<if test="speedAlarm != null">#{speedAlarm},</if>
|
||||
<if test="fatigueDrivingAlarm != null">#{fatigueDrivingAlarm},</if>
|
||||
<if test="riskEarlyAlarm != null">#{riskEarlyAlarm},</if>
|
||||
<if test="gnssModule != null">#{gnssModule},</if>
|
||||
<if test="gnssLossAntenna != null">#{gnssLossAntenna},</if>
|
||||
<if test="gnssAntennaShortcircuit != null">#{gnssAntennaShortcircuit},</if>
|
||||
<if test="mainPowerLake != null">#{mainPowerLake},</if>
|
||||
<if test="mainpowerloss != null">#{mainpowerloss},</if>
|
||||
<if test="accclose != null">#{accclose},</if>
|
||||
<if test="unpositioned != null">#{unpositioned},</if>
|
||||
<if test="dimensionalNOrS != null">#{dimensionalNOrS},</if>
|
||||
<if test="longitudinalEOrW != null">#{longitudinalEOrW},</if>
|
||||
<if test="dLIsencryption != null">#{dLIsencryption},</if>
|
||||
<if test="latitude != null">#{latitude},</if>
|
||||
<if test="longitude != null">#{longitude},</if>
|
||||
<if test="altitude != null">#{altitude},</if>
|
||||
<if test="speed != null">#{speed},</if>
|
||||
<if test="course != null">#{course},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="gpsIntensity != null">#{gpsIntensity},</if>
|
||||
<if test="gpsSatellites != null">#{gpsSatellites},</if>
|
||||
<if test="gpsMileage != null">#{gpsMileage},</if>
|
||||
<if test="isOutPower != null">#{isOutPower},</if>
|
||||
<if test="carPower != null">#{carPower},</if>
|
||||
<if test="isSensorRun != null">#{isSensorRun},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateCollectMachineGps" parameterType="CollectMachineGps">
|
||||
update collect_machine_gps
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="machineId != null">machine_id = #{machineId},</if>
|
||||
<if test="carId != null">car_id = #{carId},</if>
|
||||
<if test="carLicense != null">car_license = #{carLicense},</if>
|
||||
<if test="emergencyAlarm != null">emergency_alarm = #{emergencyAlarm},</if>
|
||||
<if test="speedAlarm != null">speed_alarm = #{speedAlarm},</if>
|
||||
<if test="fatigueDrivingAlarm != null">fatigue_driving_alarm = #{fatigueDrivingAlarm},</if>
|
||||
<if test="riskEarlyAlarm != null">risk_early_alarm = #{riskEarlyAlarm},</if>
|
||||
<if test="gnssModule != null">gnss_module = #{gnssModule},</if>
|
||||
<if test="gnssLossAntenna != null">gnss_loss_antenna = #{gnssLossAntenna},</if>
|
||||
<if test="gnssAntennaShortcircuit != null">gnss_antenna_shortcircuit = #{gnssAntennaShortcircuit},</if>
|
||||
<if test="mainPowerLake != null">main_power_lake = #{mainPowerLake},</if>
|
||||
<if test="mainpowerloss != null">mainpowerloss = #{mainpowerloss},</if>
|
||||
<if test="accclose != null">accclose = #{accclose},</if>
|
||||
<if test="unpositioned != null">unpositioned = #{unpositioned},</if>
|
||||
<if test="dimensionalNOrS != null">dimensional_n_or_s = #{dimensionalNOrS},</if>
|
||||
<if test="longitudinalEOrW != null">longitudinal_e_or_w = #{longitudinalEOrW},</if>
|
||||
<if test="dLIsencryption != null">d_l_isencryption = #{dLIsencryption},</if>
|
||||
<if test="latitude != null">latitude = #{latitude},</if>
|
||||
<if test="longitude != null">longitude = #{longitude},</if>
|
||||
<if test="altitude != null">altitude = #{altitude},</if>
|
||||
<if test="speed != null">speed = #{speed},</if>
|
||||
<if test="course != null">course = #{course},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="gpsIntensity != null">gps_intensity = #{gpsIntensity},</if>
|
||||
<if test="gpsSatellites != null">gps_satellites = #{gpsSatellites},</if>
|
||||
<if test="gpsMileage != null">gps_mileage = #{gpsMileage},</if>
|
||||
<if test="isOutPower != null">is_out_power = #{isOutPower},</if>
|
||||
<if test="carPower != null">car_power = #{carPower},</if>
|
||||
<if test="isSensorRun != null">is_sensor_run = #{isSensorRun},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteCollectMachineGpsById" parameterType="String">
|
||||
delete from collect_machine_gps where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteCollectMachineGpsByIds" parameterType="String">
|
||||
delete from collect_machine_gps where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
@ -0,0 +1,51 @@
|
||||
package com.ruoyi.common.t808;
|
||||
|
||||
import com.ruoyi.common.t808.attribute.AlarmADAS;
|
||||
import com.ruoyi.common.t808.attribute.AlarmBSD;
|
||||
import com.ruoyi.common.t808.attribute.AlarmDSM;
|
||||
import com.ruoyi.common.t808.attribute.AlarmTPMS;
|
||||
import io.github.yezhihao.protostar.PrepareLoadStrategy;
|
||||
import io.github.yezhihao.protostar.ProtostarUtil;
|
||||
import io.github.yezhihao.protostar.schema.MapSchema;
|
||||
import io.github.yezhihao.protostar.schema.NumberSchema;
|
||||
|
||||
|
||||
/**
|
||||
* 位置附加信息转换器(苏标)
|
||||
* @author yezhihao
|
||||
* https://gitee.com/yezhihao/jt808-server
|
||||
*/
|
||||
public class AttributeConverter extends MapSchema<Number, Object> {
|
||||
|
||||
public AttributeConverter() {
|
||||
super(NumberSchema.BYTE_INT, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addSchemas(PrepareLoadStrategy<Number> schemaRegistry) {
|
||||
schemaRegistry
|
||||
.addSchema(AttributeKey.Mileage, NumberSchema.DWORD_LONG)
|
||||
.addSchema(AttributeKey.Fuel, NumberSchema.WORD_INT)
|
||||
.addSchema(AttributeKey.Speed, NumberSchema.WORD_INT)
|
||||
.addSchema(AttributeKey.AlarmEventId, NumberSchema.WORD_INT)
|
||||
.addSchema(AttributeKey.TirePressure, TirePressure.SCHEMA)
|
||||
.addSchema(AttributeKey.CarriageTemperature, NumberSchema.WORD_SHORT)
|
||||
|
||||
.addSchema(AttributeKey.OverSpeedAlarm, OverSpeedAlarm.SCHEMA)
|
||||
.addSchema(AttributeKey.InOutAreaAlarm, InOutAreaAlarm.SCHEMA)
|
||||
.addSchema(AttributeKey.RouteDriveTimeAlarm, RouteDriveTimeAlarm.SCHEMA)
|
||||
|
||||
.addSchema(AttributeKey.Signal, NumberSchema.DWORD_INT)
|
||||
.addSchema(AttributeKey.IoState, NumberSchema.WORD_INT)
|
||||
.addSchema(AttributeKey.AnalogQuantity, NumberSchema.DWORD_INT)
|
||||
.addSchema(AttributeKey.SignalStrength, NumberSchema.BYTE_INT)
|
||||
.addSchema(AttributeKey.GnssCount, NumberSchema.BYTE_INT)
|
||||
|
||||
|
||||
.addSchema(AttributeKey.AlarmADAS, ProtostarUtil.getRuntimeSchema(AlarmADAS.class, 0))
|
||||
.addSchema(AttributeKey.AlarmBSD, ProtostarUtil.getRuntimeSchema(AlarmBSD.class, 0))
|
||||
.addSchema(AttributeKey.AlarmDSM, ProtostarUtil.getRuntimeSchema(AlarmDSM.class, 0))
|
||||
.addSchema(AttributeKey.AlarmTPMS, ProtostarUtil.getRuntimeSchema(AlarmTPMS.class, 0))
|
||||
;
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package com.ruoyi.common.t808;
|
||||
|
||||
import com.ruoyi.common.t808.attribute.AlarmADAS;
|
||||
import com.ruoyi.common.t808.attribute.AlarmBSD;
|
||||
import com.ruoyi.common.t808.attribute.AlarmDSM;
|
||||
import com.ruoyi.common.t808.attribute.AlarmTPMS;
|
||||
import io.github.yezhihao.protostar.PrepareLoadStrategy;
|
||||
import io.github.yezhihao.protostar.ProtostarUtil;
|
||||
import io.github.yezhihao.protostar.schema.MapSchema;
|
||||
import io.github.yezhihao.protostar.schema.NumberSchema;
|
||||
|
||||
|
||||
/**
|
||||
* 位置附加信息转换器(粤标)
|
||||
* @author yezhihao
|
||||
* https://gitee.com/yezhihao/jt808-server
|
||||
*/
|
||||
public class AttributeConverterYue extends MapSchema<Number, Object> {
|
||||
|
||||
public AttributeConverterYue() {
|
||||
super(NumberSchema.BYTE_INT, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addSchemas(PrepareLoadStrategy<Number> schemaRegistry) {
|
||||
schemaRegistry
|
||||
.addSchema(AttributeKey.Mileage, NumberSchema.DWORD_LONG)
|
||||
.addSchema(AttributeKey.Fuel, NumberSchema.WORD_INT)
|
||||
.addSchema(AttributeKey.Speed, NumberSchema.WORD_INT)
|
||||
.addSchema(AttributeKey.AlarmEventId, NumberSchema.WORD_INT)
|
||||
.addSchema(AttributeKey.TirePressure, TirePressure.SCHEMA)
|
||||
.addSchema(AttributeKey.CarriageTemperature, NumberSchema.WORD_SHORT)
|
||||
|
||||
.addSchema(AttributeKey.OverSpeedAlarm, OverSpeedAlarm.SCHEMA)
|
||||
.addSchema(AttributeKey.InOutAreaAlarm, InOutAreaAlarm.SCHEMA)
|
||||
.addSchema(AttributeKey.RouteDriveTimeAlarm, RouteDriveTimeAlarm.SCHEMA)
|
||||
|
||||
.addSchema(AttributeKey.Signal, NumberSchema.DWORD_INT)
|
||||
.addSchema(AttributeKey.IoState, NumberSchema.WORD_INT)
|
||||
.addSchema(AttributeKey.AnalogQuantity, NumberSchema.DWORD_INT)
|
||||
.addSchema(AttributeKey.SignalStrength, NumberSchema.BYTE_INT)
|
||||
.addSchema(AttributeKey.GnssCount, NumberSchema.BYTE_INT)
|
||||
|
||||
|
||||
.addSchema(AttributeKey.AlarmADAS, ProtostarUtil.getRuntimeSchema(AlarmADAS.class, 1))
|
||||
.addSchema(AttributeKey.AlarmBSD, ProtostarUtil.getRuntimeSchema(AlarmBSD.class, 1))
|
||||
.addSchema(AttributeKey.AlarmDSM, ProtostarUtil.getRuntimeSchema(AlarmDSM.class, 1))
|
||||
.addSchema(AttributeKey.AlarmTPMS, ProtostarUtil.getRuntimeSchema(AlarmTPMS.class, 1))
|
||||
;
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.ruoyi.common.t808;
|
||||
|
||||
/**
|
||||
* 位置附加信息
|
||||
* @author yezhihao
|
||||
* https://gitee.com/yezhihao/jt808-server
|
||||
*/
|
||||
public interface AttributeKey {
|
||||
int Mileage = 1; // 0x01 里程,数据类型为DWORD,单位为1/10km,对应车上里程表读数
|
||||
int Fuel = 2; // 0x02 油量,数据类型为WORD,单位为1/10L,对应车上油量表读数
|
||||
int Speed = 3; // 0x03 行驶记录功能获取的速度,数据类型为WORD,单位为1/10km/h
|
||||
int AlarmEventId = 4; // 0x04 需要人工确认报警事件的ID,数据类型为WORD,从1开始计数
|
||||
int TirePressure = 5; // 0x05 胎压,单位为Pa,标定轮子的顺序为从车头开始从左到右顺序排列,多余的字节为0xFF,表示无效数据
|
||||
int CarriageTemperature = 6; // 0x06 车厢温度,单位为摄氏度,取值范围为-32767~+32767,最高位为1表示负数
|
||||
int OverSpeedAlarm = 17; // 0x11 超速报警附加信息见表28
|
||||
int InOutAreaAlarm = 18; // 0x12 进出区域/路线报警附加信息见表29
|
||||
int RouteDriveTimeAlarm = 19; // 0x13 路段行驶时间不足/过长报警附加信息见表30
|
||||
int Signal = 37; // 0x25 扩展车辆信号状态位,参数项格式和定义见表31
|
||||
int IoState = 42; // 0x2a I0状态位,参数项格式和定义见表32
|
||||
int AnalogQuantity = 43; // 0x2b 模拟量,bit[0~15],AD0;bit[l6~31],ADl
|
||||
int SignalStrength = 48; // 0x30 数据类型为BYTE,无线通信网络信号强度
|
||||
int GnssCount = 49; // 0x31 数据类型为BYTE,GNSS定位卫星数
|
||||
int AlarmADAS = 100; // 0x64 高级驾驶辅助系统报警
|
||||
int AlarmDSM = 101; // 0x65 驾驶员状态监测
|
||||
int AlarmTPMS = 102; // 0x66 轮胎气压监测系统
|
||||
int AlarmBSD = 103; // 0x67 盲点监测
|
||||
int InstallErrorMsg = 241; // 0xF1 安装异常信息,由厂家自定义(粤标)
|
||||
int AlgorithmErrorMsg = 242; // 0xF2 算法异常信息,由厂家自定义(粤标)
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.ruoyi.common.t808;
|
||||
|
||||
/**
|
||||
* 江苏省团体标准
|
||||
* 道路运输车辆主动安全智能防控系统(通讯协议规范)
|
||||
* @author yezhihao
|
||||
* https://gitee.com/yezhihao/jt808-server
|
||||
*/
|
||||
public interface JSATL12 {
|
||||
|
||||
int 报警附件上传指令 = 0x9208;
|
||||
int 文件上传完成消息应答 = 0x9212;
|
||||
int 报警附件信息消息 = 0x1210;
|
||||
int 文件信息上传 = 0x1211;
|
||||
int 文件上传完成消息 = 0x1212;
|
||||
int 文件数据上传 = 0x30316364;
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.ruoyi.common.t808;
|
||||
|
||||
/**
|
||||
* 中华人民共和国交通运输行业标准
|
||||
* 道路运输车辆卫星定位系统视频通信协议
|
||||
* @author yezhihao
|
||||
* https://gitee.com/yezhihao/jt808-server
|
||||
*/
|
||||
public interface JT1078 {
|
||||
|
||||
int 终端上传音视频属性 = 0x1003;
|
||||
int 终端上传乘客流量 = 0x1005;
|
||||
int 终端上传音视频资源列表 = 0x1205;
|
||||
int 文件上传完成通知 = 0x1206;
|
||||
int 查询终端音视频属性 = 0x9003;
|
||||
int 实时音视频传输请求 = 0x9101;
|
||||
int 音视频实时传输控制 = 0x9102;
|
||||
int 实时音视频传输状态通知 = 0x9105;
|
||||
int 平台下发远程录像回放请求 = 0x9201;
|
||||
int 平台下发远程录像回放控制 = 0x9202;
|
||||
int 查询资源列表 = 0x9205;
|
||||
int 文件上传指令 = 0x9206;
|
||||
int 文件上传控制 = 0x9207;
|
||||
int 云台旋转 = 0x9301;
|
||||
int 云台调整焦距控制 = 0x9302;
|
||||
int 云台调整光圈控制 = 0x9303;
|
||||
int 云台雨刷控制 = 0x9304;
|
||||
int 红外补光控制 = 0x9305;
|
||||
int 云台变倍控制 = 0x9306;
|
||||
int 实时音视频流及透传数据传输 = 0x30316364;
|
||||
String 平台手工唤醒请求_短消息 = "WAKEUP";
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
package com.ruoyi.common.t808;
|
||||
|
||||
/**
|
||||
* 中华人民共和国交通运输行业标准
|
||||
* 道路运输车辆卫星定位系统终端通信协议
|
||||
* @author yezhihao
|
||||
* https://gitee.com/yezhihao/jt808-server
|
||||
*/
|
||||
public interface JT808 {
|
||||
|
||||
int 终端通用应答 = 0x0001;
|
||||
int 终端心跳 = 0x0002;
|
||||
int 终端注销 = 0x0003;
|
||||
int 查询服务器时间 = 0x0004;//2019 new
|
||||
int 终端补传分包请求 = 0x0005;//2019 new
|
||||
int 终端注册 = 0x0100;
|
||||
int 终端鉴权 = 0x0102;//2019 modify
|
||||
int 查询终端参数应答 = 0x0104;
|
||||
int 查询终端属性应答 = 0x0107;
|
||||
int 终端升级结果通知 = 0x0108;
|
||||
int 位置信息汇报 = 0x0200;
|
||||
int 位置信息查询应答 = 0x0201;
|
||||
int 事件报告 = 0x0301;//2019 del
|
||||
int 提问应答 = 0x0302;//2019 del
|
||||
int 信息点播_取消 = 0x0303;//2019 del
|
||||
int 车辆控制应答 = 0x0500;
|
||||
int 查询区域或线路数据应答 = 0x0608;//2019 new
|
||||
int 行驶记录数据上传 = 0x0700;
|
||||
int 电子运单上报 = 0x0701;
|
||||
int 驾驶员身份信息采集上报 = 0x0702;//2019 modify
|
||||
int 定位数据批量上传 = 0x0704;
|
||||
int CAN总线数据上传 = 0x0705;
|
||||
int 多媒体事件信息上传 = 0x0800;
|
||||
int 多媒体数据上传 = 0x0801;
|
||||
int 存储多媒体数据检索应答 = 0x0802;
|
||||
int 摄像头立即拍摄命令应答 = 0x0805;
|
||||
int 数据上行透传 = 0x0900;
|
||||
int 数据压缩上报 = 0x0901;
|
||||
int 终端RSA公钥 = 0x0A00;
|
||||
|
||||
int 终端上行消息保留 = 0x0F00 - 0x0FFF;
|
||||
|
||||
int 平台通用应答 = 0x8001;
|
||||
int 服务器补传分包请求 = 0x8003;
|
||||
int 查询服务器时间应答 = 0x8004;//2019 new
|
||||
int 终端注册应答 = 0x8100;
|
||||
|
||||
int 设置终端参数 = 0x8103;
|
||||
int 查询终端参数 = 0x8104;
|
||||
int 终端控制 = 0x8105;
|
||||
int 查询指定终端参数 = 0x8106;
|
||||
int 查询终端属性 = 0x8107;
|
||||
int 下发终端升级包 = 0x8108;
|
||||
int 位置信息查询 = 0x8201;
|
||||
int 临时位置跟踪控制 = 0x8202;
|
||||
int 人工确认报警消息 = 0x8203;
|
||||
int 服务器向终端发起链路检测请求 = 0x8204;//2019 new
|
||||
int 文本信息下发 = 0x8300;//2019 modify
|
||||
int 事件设置 = 0x8301;//2019 del
|
||||
int 提问下发 = 0x8302;//2019 del
|
||||
int 信息点播菜单设置 = 0x8303;//2019 del
|
||||
int 信息服务 = 0x8304;//2019 del
|
||||
int 电话回拨 = 0x8400;
|
||||
int 设置电话本 = 0x8401;
|
||||
int 车辆控制 = 0x8500;//2019 modify
|
||||
int 设置圆形区域 = 0x8600;//2019 modify
|
||||
int 删除圆形区域 = 0x8601;
|
||||
int 设置矩形区域 = 0x8602;//2019 modify
|
||||
int 删除矩形区域 = 0x8603;
|
||||
int 设置多边形区域 = 0x8604;//2019 modify
|
||||
int 删除多边形区域 = 0x8605;
|
||||
int 设置路线 = 0x8606;
|
||||
int 删除路线 = 0x8607;
|
||||
int 查询区域或线路数据 = 0x8608;//2019 new
|
||||
int 行驶记录仪数据采集命令 = 0x8700;
|
||||
int 行驶记录仪参数下传命令 = 0x8701;
|
||||
int 上报驾驶员身份信息请求 = 0x8702;
|
||||
|
||||
int 多媒体数据上传应答 = 0x8800;
|
||||
|
||||
int 摄像头立即拍摄命令 = 0x8801;
|
||||
int 存储多媒体数据检索 = 0x8802;
|
||||
int 存储多媒体数据上传 = 0x8803;
|
||||
int 录音开始命令 = 0x8804;
|
||||
int 单条存储多媒体数据检索上传命令 = 0x8805;
|
||||
int 数据下行透传 = 0x8900;
|
||||
int 平台RSA公钥 = 0x8A00;
|
||||
|
||||
int 平台下行消息保留 = 0x8F00 - 0x8FFF;
|
||||
int 厂商自定义上行消息 = 0xE000 - 0xEFFF;//2019 new
|
||||
int 商自定义下行消息 = 0xF000 - 0xFFFF;//2019 new
|
||||
}
|
@ -0,0 +1,247 @@
|
||||
package com.ruoyi.common.t808;
|
||||
|
||||
import io.github.yezhihao.netmc.core.model.Message;
|
||||
import io.github.yezhihao.netmc.session.Session;
|
||||
import io.github.yezhihao.protostar.annotation.Field;
|
||||
import io.github.yezhihao.protostar.util.ToStringBuilder;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.beans.Transient;
|
||||
|
||||
/**
|
||||
* @author yezhihao
|
||||
* https://gitee.com/yezhihao/jt808-server
|
||||
*/
|
||||
public class JTMessage implements Message {
|
||||
|
||||
@Field(length = 2, desc = "消息ID")
|
||||
protected int messageId;
|
||||
@Field(length = 2, desc = "消息体属性")
|
||||
protected int properties;
|
||||
@Field(length = 1, desc = "协议版本号", version = 1)
|
||||
protected int protocolVersion;
|
||||
@Field(length = 6, charset = "BCD", desc = "终端手机号", version = {-1, 0})
|
||||
@Field(length = 10, charset = "BCD", desc = "终端手机号", version = 1)
|
||||
protected String clientId;
|
||||
@Field(length = 2, desc = "流水号")
|
||||
protected int serialNo;
|
||||
@Field(length = 2, desc = "消息包总数")
|
||||
protected Integer packageTotal;
|
||||
@Field(length = 2, desc = "包序号")
|
||||
protected Integer packageNo;
|
||||
/** bcc校验 */
|
||||
protected boolean verified = true;
|
||||
|
||||
protected transient Session session;
|
||||
|
||||
protected transient ByteBuf payload;
|
||||
|
||||
|
||||
public JTMessage() {
|
||||
}
|
||||
|
||||
public JTMessage(int messageId) {
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
public JTMessage copyBy(JTMessage that) {
|
||||
this.setClientId(that.getClientId());
|
||||
this.setProtocolVersion(that.getProtocolVersion());
|
||||
this.setVersion(that.isVersion());
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getMessageId() {
|
||||
return messageId;
|
||||
}
|
||||
|
||||
public void setMessageId(int messageId) {
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
public int getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public void setProperties(int properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public int getProtocolVersion() {
|
||||
return protocolVersion;
|
||||
}
|
||||
|
||||
public void setProtocolVersion(int protocolVersion) {
|
||||
this.protocolVersion = protocolVersion;
|
||||
}
|
||||
|
||||
public String getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public void setClientId(String clientId) {
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
||||
public int getSerialNo() {
|
||||
return serialNo;
|
||||
}
|
||||
|
||||
public void setSerialNo(int serialNo) {
|
||||
this.serialNo = serialNo;
|
||||
}
|
||||
|
||||
public Integer getPackageTotal() {
|
||||
if (isSubpackage())
|
||||
return packageTotal;
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setPackageTotal(Integer packageTotal) {
|
||||
this.packageTotal = packageTotal;
|
||||
}
|
||||
|
||||
public Integer getPackageNo() {
|
||||
if (isSubpackage())
|
||||
return packageNo;
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setPackageNo(Integer packageNo) {
|
||||
this.packageNo = packageNo;
|
||||
}
|
||||
|
||||
public boolean isVerified() {
|
||||
return verified;
|
||||
}
|
||||
|
||||
public void setVerified(boolean verified) {
|
||||
this.verified = verified;
|
||||
}
|
||||
|
||||
@Transient
|
||||
public Session getSession() {
|
||||
return session;
|
||||
}
|
||||
|
||||
public void setSession(Session session) {
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
@Transient
|
||||
public ByteBuf getPayload() {
|
||||
return payload;
|
||||
}
|
||||
|
||||
public void setPayload(ByteBuf payload) {
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
public int reflectMessageId() {
|
||||
if (messageId != 0)
|
||||
return messageId;
|
||||
return reflectMessageId(this.getClass());
|
||||
}
|
||||
|
||||
public static int reflectMessageId(Class<?> clazz) {
|
||||
io.github.yezhihao.protostar.annotation.Message messageType = clazz.getAnnotation(io.github.yezhihao.protostar.annotation.Message.class);
|
||||
if (messageType != null && messageType.value().length > 0)
|
||||
return messageType.value()[0];
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean transform() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean noBuffer() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static final int BODY_LENGTH = 0b0000_0011_1111_1111;
|
||||
private static final int ENCRYPTION = 0b00011_100_0000_0000;
|
||||
private static final int SUBPACKAGE = 0b0010_0000_0000_0000;
|
||||
private static final int VERSION = 0b0100_0000_0000_0000;
|
||||
private static final int RESERVED = 0b1000_0000_0000_0000;
|
||||
|
||||
/** 消息体长度 */
|
||||
public int getBodyLength() {
|
||||
return this.properties & BODY_LENGTH;
|
||||
}
|
||||
|
||||
public void setBodyLength(int bodyLength) {
|
||||
this.properties ^= (properties & BODY_LENGTH);
|
||||
this.properties |= bodyLength;
|
||||
}
|
||||
|
||||
/** 加密方式 */
|
||||
public int getEncryption() {
|
||||
return (properties & ENCRYPTION) >> 10;
|
||||
}
|
||||
|
||||
public void setEncryption(int encryption) {
|
||||
this.properties ^= (properties & ENCRYPTION);
|
||||
this.properties |= (encryption << 10);
|
||||
}
|
||||
|
||||
/** 是否分包 */
|
||||
public boolean isSubpackage() {
|
||||
return (properties & SUBPACKAGE) == SUBPACKAGE;
|
||||
}
|
||||
|
||||
public void setSubpackage(boolean subpackage) {
|
||||
if (subpackage)
|
||||
this.properties |= SUBPACKAGE;
|
||||
else
|
||||
this.properties ^= (properties & SUBPACKAGE);
|
||||
}
|
||||
|
||||
/** 是否有版本 */
|
||||
public boolean isVersion() {
|
||||
return (properties & VERSION) == VERSION;
|
||||
}
|
||||
|
||||
public void setVersion(boolean version) {
|
||||
if (version)
|
||||
this.properties |= VERSION;
|
||||
else
|
||||
this.properties ^= (properties & VERSION);
|
||||
}
|
||||
|
||||
/** 保留位 */
|
||||
public boolean isReserved() {
|
||||
return (properties & RESERVED) == RESERVED;
|
||||
}
|
||||
|
||||
public void setReserved(boolean reserved) {
|
||||
if (reserved)
|
||||
this.properties |= RESERVED;
|
||||
else
|
||||
this.properties ^= (properties & RESERVED);
|
||||
}
|
||||
|
||||
protected StringBuilder toStringHead() {
|
||||
final StringBuilder sb = new StringBuilder(768);
|
||||
sb.append(MessageId.getName(messageId));
|
||||
sb.append('[');
|
||||
sb.append("cid=").append(clientId);
|
||||
sb.append(",msgId=").append(messageId);
|
||||
sb.append(",version=").append(protocolVersion);
|
||||
sb.append(",serialNo=").append(serialNo);
|
||||
sb.append(",props=").append(properties);
|
||||
sb.append(",verified=").append(verified);
|
||||
if (isSubpackage()) {
|
||||
sb.append(",pt=").append(packageTotal);
|
||||
sb.append(",pn=").append(packageNo);
|
||||
}
|
||||
sb.append(']');
|
||||
sb.append(',');
|
||||
return sb;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String result = ToStringBuilder.toString(toStringHead(), this, false, "messageId", "clientId", "protocolVersion", "serialNo", "properties", "packageTotal", "packageNo");
|
||||
return result;
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package com.ruoyi.common.t808;
|
||||
|
||||
import io.github.yezhihao.protostar.annotation.Message;
|
||||
import io.github.yezhihao.protostar.util.ClassUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author yezhihao
|
||||
* https://gitee.com/yezhihao/jt808-server
|
||||
*/
|
||||
public class MessageId {
|
||||
|
||||
private static final Map<Integer, String> messageId = new HashMap<>(256);
|
||||
private static final Map<Integer, Class> messageClass = new HashMap<>(256);
|
||||
|
||||
static {
|
||||
for (Class clazz : new Class[]{JT808.class, JT1078.class, JSATL12.class}) {
|
||||
Field[] fields = clazz.getFields();
|
||||
for (Field field : fields) {
|
||||
try {
|
||||
if (!Integer.TYPE.isAssignableFrom(field.getType()))
|
||||
continue;
|
||||
int id = field.getInt(null);
|
||||
String hexId = leftPad(Integer.toHexString(id), 4, '0');
|
||||
String name = field.getName();
|
||||
messageId.put(id, "[" + hexId + "]" + name);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<Class> classList = ClassUtils.getClassList("org.yzh.protocol");
|
||||
for (Class<?> clazz : classList) {
|
||||
Message annotation = clazz.getAnnotation(Message.class);
|
||||
if (annotation != null) {
|
||||
int[] value = annotation.value();
|
||||
for (int i : value) {
|
||||
messageClass.put(i, clazz);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Class<JTMessage> getClass(Integer id) {
|
||||
return messageClass.get(id);
|
||||
}
|
||||
|
||||
public static String getName(int id) {
|
||||
String name = messageId.get(id);
|
||||
if (name != null) {
|
||||
return name;
|
||||
}
|
||||
return leftPad(Integer.toHexString(id), 4, '0');
|
||||
}
|
||||
|
||||
public static String leftPad(String str, int size, char ch) {
|
||||
int length = str.length();
|
||||
int pads = size - length;
|
||||
if (pads > 0) {
|
||||
char[] result = new char[size];
|
||||
str.getChars(0, length, result, pads);
|
||||
while (pads > 0)
|
||||
result[--pads] = ch;
|
||||
return new String(result);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package com.ruoyi.common.t808;
|
||||
|
||||
import io.github.yezhihao.protostar.Schema;
|
||||
import io.github.yezhihao.protostar.util.ByteBufUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 胎压 0x05
|
||||
* length 30
|
||||
*/
|
||||
public class TirePressure {
|
||||
|
||||
public static final int key = 5;
|
||||
|
||||
public static final Schema<TirePressure> SCHEMA = new TirePressureSchema();
|
||||
|
||||
private byte[] value;
|
||||
|
||||
public TirePressure() {
|
||||
}
|
||||
|
||||
public TirePressure(byte[] value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public byte[] getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(byte[] value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder(32);
|
||||
sb.append("TirePressure{value=").append(Arrays.toString(value));
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static class TirePressureSchema implements Schema<TirePressure> {
|
||||
|
||||
private TirePressureSchema() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TirePressure readFrom(ByteBuf input) {
|
||||
int len = input.readableBytes();
|
||||
if (len > 30)
|
||||
len = 30;
|
||||
byte[] value = new byte[len];
|
||||
input.readBytes(value);
|
||||
return new TirePressure(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(ByteBuf output, TirePressure message) {
|
||||
ByteBufUtils.writeFixedLength(output, 30, message.value);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,130 @@
|
||||
package com.ruoyi.common.t808.model;
|
||||
|
||||
import com.ruoyi.common.t808.AttributeConverter;
|
||||
import com.ruoyi.common.t808.AttributeConverterYue;
|
||||
import com.ruoyi.common.t808.JT808;
|
||||
import com.ruoyi.common.t808.JTMessage;
|
||||
import io.github.yezhihao.protostar.annotation.Field;
|
||||
import io.github.yezhihao.protostar.annotation.Message;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author yezhihao
|
||||
* https://gitee.com/yezhihao/jt808-server
|
||||
*/
|
||||
@Message(JT808.位置信息汇报)
|
||||
public class T0200 extends JTMessage {
|
||||
|
||||
/**
|
||||
* 使用 Bit.isTrue判断报警和状态标志位
|
||||
* @see
|
||||
*/
|
||||
@Field(length = 4, desc = "报警标志")
|
||||
private int warnBit;
|
||||
@Field(length = 4, desc = "状态")
|
||||
private int statusBit;
|
||||
@Field(length = 4, desc = "纬度")
|
||||
private int latitude;
|
||||
@Field(length = 4, desc = "经度")
|
||||
private int longitude;
|
||||
@Field(length = 2, desc = "高程(米)")
|
||||
private int altitude;
|
||||
@Field(length = 2, desc = "速度(1/10公里每小时)")
|
||||
private int speed;
|
||||
@Field(length = 2, desc = "方向")
|
||||
private int direction;
|
||||
@Field(length = 6, charset = "BCD", desc = "时间(YYMMDDHHMMSS)")
|
||||
private LocalDateTime deviceTime;
|
||||
@Field(converter = AttributeConverter.class, desc = "位置附加信息", version = {-1, 0})
|
||||
@Field(converter = AttributeConverterYue.class, desc = "位置附加信息(粤标)", version = 1)
|
||||
private Map<Integer, Object> attributes;
|
||||
|
||||
public int getWarnBit() {
|
||||
return warnBit;
|
||||
}
|
||||
|
||||
public void setWarnBit(int warnBit) {
|
||||
this.warnBit = warnBit;
|
||||
}
|
||||
|
||||
public int getStatusBit() {
|
||||
return statusBit;
|
||||
}
|
||||
|
||||
public void setStatusBit(int statusBit) {
|
||||
this.statusBit = statusBit;
|
||||
}
|
||||
|
||||
public int getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public void setLatitude(int latitude) {
|
||||
this.latitude = latitude;
|
||||
}
|
||||
|
||||
public int getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
public void setLongitude(int longitude) {
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
public int getAltitude() {
|
||||
return altitude;
|
||||
}
|
||||
|
||||
public void setAltitude(int altitude) {
|
||||
this.altitude = altitude;
|
||||
}
|
||||
|
||||
public int getSpeed() {
|
||||
return speed;
|
||||
}
|
||||
|
||||
public void setSpeed(int speed) {
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
public int getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
public void setDirection(int direction) {
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
public LocalDateTime getDeviceTime() {
|
||||
return deviceTime;
|
||||
}
|
||||
|
||||
public void setDeviceTime(LocalDateTime deviceTime) {
|
||||
this.deviceTime = deviceTime;
|
||||
}
|
||||
|
||||
public Map<Integer, Object> getAttributes() {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
public void setAttributes(Map<Integer, Object> attributes) {
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = toStringHead();
|
||||
sb.append("T0200{deviceTime=").append(deviceTime);
|
||||
sb.append(",longitude=").append(longitude);
|
||||
sb.append(",latitude=").append(latitude);
|
||||
sb.append(",altitude=").append(altitude);
|
||||
sb.append(",speed=").append(speed);
|
||||
sb.append(",direction=").append(direction);
|
||||
sb.append(",warnBit=").append(Integer.toBinaryString(warnBit));
|
||||
sb.append(",statusBit=").append(Integer.toBinaryString(statusBit));
|
||||
sb.append(",attributes=").append(attributes);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package com.ruoyi.framework.websocket;
|
||||
|
||||
import java.util.concurrent.Semaphore;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* 信号量相关处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class SemaphoreUtils
|
||||
{
|
||||
/**
|
||||
* SemaphoreUtils 日志控制器
|
||||
*/
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(SemaphoreUtils.class);
|
||||
|
||||
/**
|
||||
* 获取信号量
|
||||
*
|
||||
* @param semaphore
|
||||
* @return
|
||||
*/
|
||||
public static boolean tryAcquire(Semaphore semaphore)
|
||||
{
|
||||
boolean flag = false;
|
||||
|
||||
try
|
||||
{
|
||||
flag = semaphore.tryAcquire();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.error("获取信号量异常", e);
|
||||
}
|
||||
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 释放信号量
|
||||
*
|
||||
* @param semaphore
|
||||
*/
|
||||
public static void release(Semaphore semaphore)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
semaphore.release();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.error("释放信号量异常", e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.ruoyi.framework.websocket;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* websocket 配置
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Configuration
|
||||
public class WebSocketConfig
|
||||
{
|
||||
|
||||
|
||||
@Bean
|
||||
public ServerEndpointExporter serverEndpointExporter()
|
||||
{
|
||||
return new ServerEndpointExporter();
|
||||
}
|
||||
// @Bean
|
||||
// public EchoSocketServer echoSocketServer(){
|
||||
// return new EchoSocketServer(8691);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
package com.ruoyi.framework.websocket;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import javax.websocket.OnClose;
|
||||
import javax.websocket.OnError;
|
||||
import javax.websocket.OnMessage;
|
||||
import javax.websocket.OnOpen;
|
||||
import javax.websocket.Session;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* websocket 消息处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Component
|
||||
@ServerEndpoint("/websocket/message")
|
||||
public class WebSocketServer
|
||||
{
|
||||
/**
|
||||
* WebSocketServer 日志控制器
|
||||
*/
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketServer.class);
|
||||
|
||||
/**
|
||||
* 默认最多允许同时在线人数100
|
||||
*/
|
||||
public static int socketMaxOnlineCount = 100;
|
||||
|
||||
private static Semaphore socketSemaphore = new Semaphore(socketMaxOnlineCount);
|
||||
|
||||
/**
|
||||
* 连接建立成功调用的方法
|
||||
*/
|
||||
@OnOpen
|
||||
public void onOpen(Session session) throws Exception
|
||||
{
|
||||
boolean semaphoreFlag = false;
|
||||
// 尝试获取信号量
|
||||
semaphoreFlag = SemaphoreUtils.tryAcquire(socketSemaphore);
|
||||
if (!semaphoreFlag)
|
||||
{
|
||||
// 未获取到信号量
|
||||
LOGGER.error("\n 当前在线人数超过限制数- {}", socketMaxOnlineCount);
|
||||
WebSocketUsers.sendMessageToUserByText(session, "当前在线人数超过限制数:" + socketMaxOnlineCount);
|
||||
session.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 添加用户
|
||||
WebSocketUsers.put(session.getId(), session);
|
||||
LOGGER.info("\n 建立连接 - {}", session);
|
||||
LOGGER.info("\n 当前人数 - {}", WebSocketUsers.getUsers().size());
|
||||
WebSocketUsers.sendMessageToUserByText(session, "连接成功");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接关闭时处理
|
||||
*/
|
||||
@OnClose
|
||||
public void onClose(Session session)
|
||||
{
|
||||
LOGGER.info("\n 关闭连接 - {}", session);
|
||||
// 移除用户
|
||||
WebSocketUsers.remove(session.getId());
|
||||
// 获取到信号量则需释放
|
||||
SemaphoreUtils.release(socketSemaphore);
|
||||
}
|
||||
|
||||
/**
|
||||
* 抛出异常时处理
|
||||
*/
|
||||
@OnError
|
||||
public void onError(Session session, Throwable exception) throws Exception
|
||||
{
|
||||
if (session.isOpen())
|
||||
{
|
||||
// 关闭连接
|
||||
session.close();
|
||||
}
|
||||
String sessionId = session.getId();
|
||||
LOGGER.info("\n 连接异常 - {}", sessionId);
|
||||
LOGGER.info("\n 异常信息 - {}", exception);
|
||||
// 移出用户
|
||||
WebSocketUsers.remove(sessionId);
|
||||
// 获取到信号量则需释放
|
||||
SemaphoreUtils.release(socketSemaphore);
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务器接收到客户端消息时调用的方法
|
||||
*/
|
||||
@OnMessage
|
||||
public void onMessage(String message, Session session)
|
||||
{
|
||||
String msg = message.replace("你", "我").replace("吗", "");
|
||||
WebSocketUsers.sendMessageToUserByText(session, msg);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,140 @@
|
||||
package com.ruoyi.framework.websocket;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import javax.websocket.Session;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* websocket 客户端用户集
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class WebSocketUsers
|
||||
{
|
||||
/**
|
||||
* WebSocketUsers 日志控制器
|
||||
*/
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketUsers.class);
|
||||
|
||||
/**
|
||||
* 用户集
|
||||
*/
|
||||
private static Map<String, Session> USERS = new ConcurrentHashMap<String, Session>();
|
||||
|
||||
/**
|
||||
* 存储用户
|
||||
*
|
||||
* @param key 唯一键
|
||||
* @param session 用户信息
|
||||
*/
|
||||
public static void put(String key, Session session)
|
||||
{
|
||||
USERS.put(key, session);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除用户
|
||||
*
|
||||
* @param session 用户信息
|
||||
*
|
||||
* @return 移除结果
|
||||
*/
|
||||
public static boolean remove(Session session)
|
||||
{
|
||||
String key = null;
|
||||
boolean flag = USERS.containsValue(session);
|
||||
if (flag)
|
||||
{
|
||||
Set<Map.Entry<String, Session>> entries = USERS.entrySet();
|
||||
for (Map.Entry<String, Session> entry : entries)
|
||||
{
|
||||
Session value = entry.getValue();
|
||||
if (value.equals(session))
|
||||
{
|
||||
key = entry.getKey();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return remove(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移出用户
|
||||
*
|
||||
* @param key 键
|
||||
*/
|
||||
public static boolean remove(String key)
|
||||
{
|
||||
LOGGER.info("\n 正在移出用户 - {}", key);
|
||||
Session remove = USERS.remove(key);
|
||||
if (remove != null)
|
||||
{
|
||||
boolean containsValue = USERS.containsValue(remove);
|
||||
LOGGER.info("\n 移出结果 - {}", containsValue ? "失败" : "成功");
|
||||
return containsValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取在线用户列表
|
||||
*
|
||||
* @return 返回用户集合
|
||||
*/
|
||||
public static Map<String, Session> getUsers()
|
||||
{
|
||||
return USERS;
|
||||
}
|
||||
|
||||
/**
|
||||
* 群发消息文本消息
|
||||
*
|
||||
* @param message 消息内容
|
||||
*/
|
||||
public static void sendMessageToUsersByText(String message)
|
||||
{
|
||||
Collection<Session> values = USERS.values();
|
||||
for (Session value : values)
|
||||
{
|
||||
sendMessageToUserByText(value, message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送文本消息
|
||||
*
|
||||
* @param userName 自己的用户名
|
||||
* @param message 消息内容
|
||||
*/
|
||||
public static void sendMessageToUserByText(Session session, String message)
|
||||
{
|
||||
if (session != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
session.getBasicRemote().sendText(message);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
LOGGER.error("\n[发送消息异常]", e);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGGER.info("\n[你已离线]");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue