Commit ccc19945 authored by p x's avatar p x
Browse files

调通车辆辅助驾驶信息

parent 4b522d9e
package com.cusc.adas.v2x.dto;
import com.cusc.adas.v2x.vo.AutomaticDriveInfo;
import com.cusc.adas.v2x.vo.VehicleStatusInfo;
public class VehicleBodyDto {
private VehicleInfoDto vehicleInfo;
private VehicleStatusInfo vehicleStatusInfo;
private VehicleStatusInfoDto vehicleStatusInfo;
private AutomaticDriveInfo automaticDriveInfo;
// private AutomaticDriveInfoDto automaticDriveInfo;
public VehicleInfoDto getVehicleInfo() {
return vehicleInfo;
}
public VehicleStatusInfoDto getVehicleStatusInfo() {
return vehicleStatusInfo;
}
}
......@@ -46,7 +46,7 @@ public class VehicleStatusInfoDto {
private short dmsFlag;
//里程
@Order(11)
private long mileage;
private double mileage;
//sweeping状态
@Order(12)
private short sweepingFlag;
......@@ -57,11 +57,11 @@ public class VehicleStatusInfoDto {
//油量 对应车辆油量表读数,单位:0.1 L,
@Order(14)
private int fuelGauge;
private float fuelGauge;
//电池剩余电量 0.01%,
@Order(15)
private int soc;
private float soc;
//电池温度 [0..200],单位:摄氏度(℃),
//数据偏移量 100,表示-100℃~100℃ ,0xFF 表示缺省
@Order(16)
......@@ -69,7 +69,7 @@ public class VehicleStatusInfoDto {
//预计续航里程 单位:千米(km),
@Order(17)
private long endurance;
private double endurance;
//车辆故障状态
@Order(18)
......@@ -80,7 +80,7 @@ public class VehicleStatusInfoDto {
private int motorspeed;
//电机转矩
@Order(20)
private long motortorque;
private double motortorque;
//运行模式 车辆运行模式,1:纯电驱动模式;2:混合驱动 模式;3:行车充电模式;4:能量回收模式;5:停车充电模式;6: 能量混合回充模式;
@Order(21)
private short vehMode;
......@@ -125,4 +125,11 @@ public class VehicleStatusInfoDto {
@Order(33)
private String userdefinedData;
public float getSoc() {
return soc;
}
public int getLights() {
return lights;
}
}
package com.cusc.adas.v2x.events
import com.cusc.adas.v2x.dto.VehicleInfoDto
import com.cusc.adas.v2x.dto.VehicleStatusInfoDto
/**车辆运行状态**/
class VehicleBodyEvent {
var vehicleInfo: VehicleInfoDto? = null
var vehicleStatusInfo: VehicleStatusInfoDto? = null
}
\ No newline at end of file
......@@ -23,11 +23,11 @@ public class Parse {
public static <T> T parse(ByteBuf data, T t) throws InstantiationException, IllegalAccessException, NoSuchFieldException, SecurityException, ClassNotFoundException {
Field [] fields = t.getClass().getDeclaredFields();
Field[] fields = t.getClass().getDeclaredFields();
List<Field> fList = new ArrayList<>();
SortedMap<Integer,Field> rstMap = new TreeMap<>();
SortedMap<Integer, Field> rstMap = new TreeMap<>();
for(Field field : fields) {
for (Field field : fields) {
if (field.isAnnotationPresent(Order.class)) {
......@@ -41,27 +41,27 @@ public class Parse {
}
});
for(Field field : fList) {
for (Field field : fList) {
field.setAccessible(true);
if (field.isAnnotationPresent(Order.class)) {
String fieldName = field.getName();
Order order = field.getAnnotation(Order.class);
System.out.println(fieldName);
// System.out.println(fieldName);
int num = order.value();
//基础数据类型 且 不是数组
if(field.getType().isPrimitive() && !field.getType().isArray() ) {
if (field.getType().isPrimitive() && !field.getType().isArray()) {
// data.re
// field.set(fList, rstMap);
readBuf(t,field,data);
}else if( field.getType().isArray()){
readBuf(t, field, data);
} else if (field.getType().isArray()) {
// 基础数据类型 且 是数组
readBuf(t,field,data);
}else if(List.class.isAssignableFrom(field.getType())) {
readBuf(t, field, data);
} else if (List.class.isAssignableFrom(field.getType())) {
// 集合类型
//读取属性的注解是否引用其他字段的长度
if( field.isAnnotationPresent(RefNumFlag.class) && !field.isAnnotationPresent(DynamicsClassDef.class) ) {
if (field.isAnnotationPresent(RefNumFlag.class) && !field.isAnnotationPresent(DynamicsClassDef.class)) {
RefNumFlag refNumFlag = field.getAnnotation(RefNumFlag.class);
String refField = refNumFlag.value();
......@@ -73,32 +73,33 @@ public class Parse {
if (genericType instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType) genericType;
Type[] actualTypes = pt.getActualTypeArguments();
if (actualTypes!=null && actualTypes.length > 0) {
if (actualTypes != null && actualTypes.length > 0) {
actualTypes[0].getClass();
long len = 0l;
if(nameField.getType()==short.class) {
short val= (short) nameField.get(t);
len = (long)val;
}else if(nameField.getType()==int.class) {
int val= (int) nameField.get(t);
len = (long)val;
}else if(nameField.getType()==long.class) {
if (nameField.getType() == short.class) {
short val = (short) nameField.get(t);
len = (long) val;
} else if (nameField.getType() == int.class) {
int val = (int) nameField.get(t);
len = (long) val;
} else if (nameField.getType() == long.class) {
len = (long) nameField.get(t);
}
//short len= (short) nameField.get(t);
if(len>0) {
if (len > 0) {
List list = new ArrayList<>();
for(int i=0;i<len;i++) {
for (int i = 0; i < len; i++) {
String classname = actualTypes[0].getTypeName();
Object obj = null;
if(classname.contains("Short") ) {
if (classname.contains("Short")) {
obj = data.readUnsignedByte();
}else if(classname.contains("Integer")) {
} else if (classname.contains("Integer")) {
obj = data.readUnsignedShort();
}else if(classname.contains("Long")) {
} else if (classname.contains("Long")) {
obj = data.readUnsignedInt();
}else {
Class<?> cls = Class.forName(actualTypes[0].getTypeName()); ;
} else {
Class<?> cls = Class.forName(actualTypes[0].getTypeName());
;
obj = cls.newInstance();
parse(data, obj);
}
......@@ -106,13 +107,13 @@ public class Parse {
list.add(obj);
}
System.out.println("actualTypes::"+actualTypes[0].getTypeName());
System.out.println("actualTypes::" + actualTypes[0].getTypeName());
field.set(t, list);
}
}
}
}else if(field.isAnnotationPresent(RefNumFlag.class) && field.isAnnotationPresent(DynamicsClassDef.class)) {
} else if (field.isAnnotationPresent(RefNumFlag.class) && field.isAnnotationPresent(DynamicsClassDef.class)) {
DynamicsClassDef dynamicsClassDef = field.getAnnotation(DynamicsClassDef.class);
String classtype = dynamicsClassDef.classtype();
......@@ -120,22 +121,22 @@ public class Parse {
String fieldname = dependencyDef.value();
Field tField2 = t.getClass().getDeclaredField(fieldname);
tField2.setAccessible(true);
Short value =(Short) tField2.get(t);
Short value = (Short) tField2.get(t);
RefNumFlag refNumFlag = field.getAnnotation(RefNumFlag.class);
String refFieldName = refNumFlag.value() ;
String refFieldName = refNumFlag.value();
Field tField = t.getClass().getDeclaredField(fieldname);
tField.setAccessible(true);
Field tField1 = t.getClass().getDeclaredField(refFieldName);
tField1.setAccessible(true);
Integer len= (Integer)tField1.get(t);
if(len>0) {
Class clazz1 =DynamicsClassMap.get(classtype,value );
Integer len = (Integer) tField1.get(t);
if (len > 0) {
Class clazz1 = DynamicsClassMap.get(classtype, value);
Class<?> cls = Class.forName(clazz1.getName());
List<Object> list = new ArrayList<>();
for(int i=0;i<len;i++) {
for (int i = 0; i < len; i++) {
Object obj = cls.newInstance();
System.out.println("clazz1 name::"+clazz1.getName());
System.out.println("clazz1 name::" + clazz1.getName());
parse(data, obj);
list.add(obj);
}
......@@ -145,16 +146,16 @@ public class Parse {
}
}else if(field.getType()==String.class) {
} else if (field.getType() == String.class) {
//类型为字符串
readBuf(t,field,data);
}else {
readBuf(t, field, data);
} else {
//其他对象类型
if(data.readerIndex()==data.maxCapacity() ) {
if (data.readerIndex() == data.maxCapacity()) {
return t;
}
if(field.isAnnotationPresent(DynamicsClassDef.class)) {
if (field.isAnnotationPresent(DynamicsClassDef.class)) {
DynamicsClassDef dynamicsClassDef = field.getAnnotation(DynamicsClassDef.class);
String classtype = dynamicsClassDef.classtype();
DependencyDef dependencyDef = field.getAnnotation(DependencyDef.class);
......@@ -163,15 +164,15 @@ public class Parse {
tField2.setAccessible(true);
Short key= (Short)tField2.get(t);
Class clazz1 =DynamicsClassMap.get(classtype,key );
Short key = (Short) tField2.get(t);
Class clazz1 = DynamicsClassMap.get(classtype, key);
Class<?> cls = Class.forName(clazz1.getName());
Object obj = cls.newInstance();
parse(data, obj);
field.set(t, obj);
}else {
} else {
Class<?> cls = Class.forName(field.getType().getName());
Object obj = cls.newInstance();
......@@ -180,10 +181,8 @@ public class Parse {
}
}
rstMap.put(num,field);
rstMap.put(num, field);
}
}
return t;
......@@ -191,6 +190,7 @@ public class Parse {
/**
* 读取字节流
*
* @param t
* @param field
* @param data
......@@ -199,63 +199,65 @@ public class Parse {
* @throws SecurityException
* @throws NoSuchFieldException
*/
public static void readBuf(Object t, Field field,ByteBuf data ) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
if(data.readerIndex()==data.maxCapacity() )
return ;
FieldDef fieldDef =null;
if(field.isAnnotationPresent(FieldDef.class)) {
public static void readBuf(Object t, Field field, ByteBuf data) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
if (data.readerIndex() == data.maxCapacity())
return;
FieldDef fieldDef = null;
if (field.isAnnotationPresent(FieldDef.class)) {
fieldDef = field.getAnnotation(FieldDef.class);
}
RefNumFlag refNumFlag =null;
if(field.isAnnotationPresent(RefNumFlag.class)) {
RefNumFlag refNumFlag = null;
if (field.isAnnotationPresent(RefNumFlag.class)) {
refNumFlag = field.getAnnotation(RefNumFlag.class);
}
Class<?> type = field.getType();
if(type==String.class && fieldDef!=null &&fieldDef.type().equals("BYTE")) {
byte[]by = new byte[fieldDef.length()];
if (type == String.class && fieldDef != null && fieldDef.type().equals("BYTE")) {
byte[] by = new byte[fieldDef.length()];
data.readBytes(by);
String str = new String(by, StandardCharsets.UTF_8);
field.set(t, str);
}else if(type==short.class) {
} else if (type == short.class) {
field.set(t, data.readUnsignedByte());
}else if(type==int.class) {
} else if (type == int.class) {
field.set(t, data.readUnsignedShort());
}else if(type==long.class && fieldDef==null ) {
} else if (type == long.class && fieldDef == null) {
field.set(t, data.readUnsignedInt());
}else if(type==long.class && fieldDef!=null &&fieldDef.type().equals("TIMESTAMP") && fieldDef.length()==8 ) {
} else if (type == long.class && fieldDef != null && fieldDef.type().equals("TIMESTAMP") && fieldDef.length() == 8) {
field.set(t, data.readLong());
}else if(type==long.class && fieldDef!=null &&fieldDef.type().equals("BYTE") ) {
} else if (type == long.class && fieldDef != null && fieldDef.type().equals("BYTE")) {
field.set(t, data.readLong());
}else if(field.getType().isArray()&& refNumFlag!=null) {
} else if (field.getType().isArray() && refNumFlag != null) {
Field tField = t.getClass().getDeclaredField(refNumFlag.value());
tField.setAccessible(true);
Class<?> type1 = tField.getType();
byte[] by = null;
if(type1==byte.class) {
Byte obj =(Byte) tField.get(t);
if (type1 == byte.class) {
Byte obj = (Byte) tField.get(t);
by = new byte[obj.byteValue()];
}else if(type1==short.class) {
Short obj =(Short) tField.get(t);
} else if (type1 == short.class) {
Short obj = (Short) tField.get(t);
by = new byte[obj.shortValue()];
}else if(type1==int.class) {
Integer obj =(Integer) tField.get(t);
} else if (type1 == int.class) {
Integer obj = (Integer) tField.get(t);
by = new byte[obj.intValue()];
}
data.readBytes(by);
field.set(t, by);
}
}
public static byte[] longToBytes(long value) {
ByteBuffer buffer = ByteBuffer.allocate(8);
buffer.order(ByteOrder.BIG_ENDIAN); // 指定小端模式
buffer.putLong(value); // 将long值存入buffer
return buffer.array(); // 获取byte数组
}
public static byte[] longToBytes1(long value) {
ByteBuffer buffer = ByteBuffer.allocate(4);
buffer.order(ByteOrder.BIG_ENDIAN); // 指定小端模式
......@@ -284,6 +286,7 @@ public class Parse {
// buffer.putLong(value); // 将long值存入buffer
// return buffer.array(); // 获取byte数组
}
public static String long2Hex(long num, int len) {
String hex = Long.toHexString(num);
int padLength = len * 2;
......@@ -294,7 +297,7 @@ public class Parse {
}
public static void main(String [] args) throws InstantiationException, IllegalAccessException, NoSuchFieldException, SecurityException, ClassNotFoundException {
public static void main(String[] args) throws InstantiationException, IllegalAccessException, NoSuchFieldException, SecurityException, ClassNotFoundException {
String hexString = "F20000000015018cb864640000000000";
......@@ -304,7 +307,7 @@ public class Parse {
//3600000000
// 1164916946
// byte [] bs = Long.toHexString(l);
String s = long2Hex(l,4);
String s = long2Hex(l, 4);
//longToBytes1(l);
long i = 250000;
String hex = Long.toHexString(i);
......@@ -335,101 +338,104 @@ public class Parse {
}
public static void convoterBean( Object source , Object target) throws IllegalArgumentException, IllegalAccessException, ClassNotFoundException, InstantiationException, NoSuchFieldException, SecurityException {
Field [] fields = source.getClass().getDeclaredFields();
// public static void convoterBean( Object source , Object target) throws IllegalArgumentException, IllegalAccessException, ClassNotFoundException, InstantiationException, NoSuchFieldException, SecurityException {
public static void convoterBean(Object source, Object target) {
Field tField = null;
try {
Field[] fields = source.getClass().getDeclaredFields();
//获取目标对象指定的属性
//List<Field> fList = new ArrayList<>();
//SortedMap<Integer,Field> rstMap = new TreeMap<>();
for(Field field : fields) {
for (Field field : fields) {
field.setAccessible(true);
Object o= field.get(source);
if(o==null) {
Object o = field.get(source);
if (o == null) {
continue;
}
OffsetDef offsetDef =null;
if(field.isAnnotationPresent(OffsetDef.class)) {
OffsetDef offsetDef = null;
if (field.isAnnotationPresent(OffsetDef.class)) {
offsetDef = field.getAnnotation(OffsetDef.class);
}
//获取目标对象指定的属性
Field tField = target.getClass().getDeclaredField(field.getName());
tField = target.getClass().getDeclaredField(field.getName());
tField.setAccessible(true);
if (field.isAnnotationPresent(Order.class)) {
if(field.getType().isPrimitive() && !field.getType().isArray() ) {
if (field.getType().isPrimitive() && !field.getType().isArray()) {
//如果属性添加了自定义注解 offset
Class<?> type = field.getType();
if(offsetDef!=null) {
double offset =offsetDef.value();
int type1 =offsetDef.type();
int minValidLength =offsetDef.minValidLength();
if (offsetDef != null) {
double offset = offsetDef.value();
int type1 = offsetDef.type();
int minValidLength = offsetDef.minValidLength();
//startindex
if(type==byte.class) {
if (type == byte.class) {
tField.set(target, o);
}else if(type==short.class) {
if(minValidLength>0 ) {
int len = String.valueOf((Short)o).length();
if(len<minValidLength) {
int subtract = minValidLength-len;
double f =(Short)o*Math.pow(10, subtract)*offset;
tField.set(target, (float)f);
}else {
double f =(Short)o*offset;
tField.set(target, (float)f);
}
}else {
double f =(Short)o*offset;
tField.set(target, (float)f);
}
}else if(type==int.class) {
if(minValidLength>0 ) {
int len = String.valueOf((Integer)o).length();
if(len<minValidLength) {
int subtract = minValidLength-len;
double f =(Integer)o*Math.pow(10, subtract)*offset;
tField.set(target, (float)f);
}else {
double f =(Integer)o*offset;
tField.set(target, (float)f);
}
}else {
double f =(Integer)o*offset;
tField.set(target, (float)f);
}
}else if(type==long.class) {
if(minValidLength>0 ) {
int len = String.valueOf((Long)o).length();
if(len<minValidLength) {
int subtract = minValidLength-len;
double f =(Long)o*Math.pow(10, subtract)*offset;
tField.set(target, (double)f);
}else {
double f =(Long)o*offset;
tField.set(target, (double)f);
}
}else {
double d =(Long)o*offset;
} else if (type == short.class) {
if (minValidLength > 0) {
int len = String.valueOf((Short) o).length();
if (len < minValidLength) {
int subtract = minValidLength - len;
double f = (Short) o * Math.pow(10, subtract) * offset;
tField.set(target, (float) f);
} else {
double f = (Short) o * offset;
tField.set(target, (float) f);
}
} else {
double f = (Short) o * offset;
tField.set(target, (float) f);
}
} else if (type == int.class) {
if (minValidLength > 0) {
int len = String.valueOf((Integer) o).length();
if (len < minValidLength) {
int subtract = minValidLength - len;
double f = (Integer) o * Math.pow(10, subtract) * offset;
tField.set(target, (float) f);
} else {
double f = (Integer) o * offset;
tField.set(target, (float) f);
}
} else {
double f = (Integer) o * offset;
tField.set(target, (float) f);
}
} else if (type == long.class) {
if (minValidLength > 0) {
int len = String.valueOf((Long) o).length();
if (len < minValidLength) {
int subtract = minValidLength - len;
double f = (Long) o * Math.pow(10, subtract) * offset;
tField.set(target, (double) f);
} else {
double f = (Long) o * offset;
tField.set(target, (double) f);
}
} else {
double d = (Long) o * offset;
tField.set(target, d);
}
}
}else {
} else {
tField.set(target, o);
}
}else if(field.getClass().isPrimitive() && field.getType().isArray()){
} else if (field.getClass().isPrimitive() && field.getType().isArray()) {
// 基础数据类型 且 是数组
}else if(List.class.isAssignableFrom(field.getType())) {
} else if (List.class.isAssignableFrom(field.getType())) {
// 集合类型
//读取属性的注解是否引用其他字段的长度
if( field.isAnnotationPresent(RefNumFlag.class)) {
if (field.isAnnotationPresent(RefNumFlag.class)) {
// RefNumFlag refNumFlag = field.getAnnotation(RefNumFlag.class);
// String refField = refNumFlag.value();
......@@ -451,7 +457,7 @@ public class Parse {
// }
}
}else if(field.getType()==String.class) {
} else if (field.getType() == String.class) {
//类型为字符串
// try {
// String s = (String)o;
......@@ -460,7 +466,7 @@ public class Parse {
// }catch(Exception e) {
// e.printStackTrace();
// }
}else {
} else {
//其他对象类型
Class<?> cls = Class.forName(tField.getType().getName());
......@@ -471,18 +477,23 @@ public class Parse {
}
}
}
} catch (Exception e) {
System.out.println("----convoterBean Exception " + e + " tField " + tField);
}
}
public static byte[] convoter(Byte[] bytes) {
byte [] bs = new byte[bytes.length];
int i=0;
for(Byte b :bytes ) {
byte[] bs = new byte[bytes.length];
int i = 0;
for (Byte b : bytes) {
bs[i++] = b;
}
return bs;
}
/**
* 16进制转2进制
*
* @param hex
* @return
*/
......
......@@ -11,7 +11,7 @@ import com.cusc.adas.v2x.utils.RefNumFlag;
/**
* 车辆辅助驾驶信息及状态信息
* @author huangml
*
* 车辆运行状态数据 2-车辆辅助驾驶系统信息及其他状态信息数据结构(续)
*/
public class VehicleStatusInfo {
@Order(1)
......@@ -48,8 +48,9 @@ public class VehicleStatusInfo {
//DMS 状态
@Order(10)
private short dmsFlag;
//里程
//里程单位:0.1km,
@Order(11)
@OffsetDef(value = 0.1)
private long mileage;
//sweeping状态
@Order(12)
......@@ -57,14 +58,13 @@ public class VehicleStatusInfo {
//watering状态
@Order(13)
private short wateringFlag;
// 车辆运行状态数据 2-车辆辅助驾驶系统信息及其他状态信息数据结构(续)
//油量 对应车辆油量表读数,单位:0.1 L,
@Order(14)
@OffsetDef(value = 0.1)
private int fuelGauge;
//电池剩余电量 0.01%,
@Order(15)
@OffsetDef(value = 1f)
@OffsetDef(value = 0.01)
private int soc;
//电池温度 [0..200],单位:摄氏度(℃),
//数据偏移量 100,表示-100℃~100℃ ,0xFF 表示缺省
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment