Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
p x
earlywarning
Commits
65b50318
Commit
65b50318
authored
Jun 10, 2025
by
p x
Browse files
解析DTO
parent
f2e07035
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/main/java/com/cusc/adas/v2x/dto/VehicleInfoDto.java
View file @
65b50318
...
...
@@ -36,7 +36,7 @@ public class VehicleInfoDto {
//档位
@Order
(
7
)
private
byte
tapPos
;
private
short
tapPos
;
//方向盘转角
@Order
(
8
)
private
double
steeringAngle
;
...
...
@@ -46,41 +46,41 @@ public class VehicleInfoDto {
//纵向加速度
@Order
(
10
)
private
float
accelerationLon
;
//横向加速度
@Order
(
11
)
private
float
accelerationLat
;
//垂向加速度
@Order
(
12
)
private
float
accelerationVer
;
//横摆角速度
@Order
(
13
)
private
float
yawRate
;
//油门开度
@Order
(
14
)
private
float
accelPos
;
//发动机输出转速
@Order
(
15
)
private
float
engineSpeed
;
//发动机扭矩
@Order
(
16
)
private
double
engineTorque
;
//制动踏板开关
@Order
(
17
)
private
short
brakeFlag
;
//制动踏板开度
@Order
(
18
)
private
float
brakePos
;
//制动主缸压力
@Order
(
19
)
private
in
t
brakePressure
;
private
floa
t
brakePressure
;
//油耗
@Order
(
20
)
...
...
src/main/java/com/cusc/adas/v2x/utils/Parse.java
View file @
65b50318
...
...
@@ -7,6 +7,8 @@ import java.nio.ByteBuffer;
import
java.nio.ByteOrder
;
import
java.nio.charset.StandardCharsets
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.List
;
import
java.util.SortedMap
;
import
java.util.TreeMap
;
...
...
@@ -15,286 +17,308 @@ import io.netty.buffer.ByteBuf;
import
io.netty.buffer.Unpooled
;
public
class
Parse
{
public
static
<
T
>
T
parse
(
ByteBuf
data
,
T
t
)
throws
InstantiationException
,
IllegalAccessException
,
NoSuchFieldException
,
SecurityException
,
ClassNotFoundException
{
Field
[]
fields
=
t
.
getClass
().
getDeclaredFields
();
List
<
Field
>
fList
=
new
ArrayList
<>();
SortedMap
<
Integer
,
Field
>
rstMap
=
new
TreeMap
<>();
for
(
Field
field
:
fields
)
{
field
.
setAccessible
(
true
);
if
(
field
.
isAnnotationPresent
(
Order
.
class
))
{
String
fieldName
=
field
.
getName
();
Order
order
=
field
.
getAnnotation
(
Order
.
class
);
int
num
=
order
.
value
();
//基础数据类型 且 不是数组
if
(
field
.
getType
().
isPrimitive
()
&&
!
field
.
getType
().
isArray
()
)
{
// data.re
// field.set(fList, rstMap);
readBuf
(
t
,
field
,
data
);
}
else
if
(
field
.
getClass
().
isPrimitive
()
&&
field
.
getType
().
isArray
()){
// 基础数据类型 且 是数组
}
else
if
(
List
.
class
.
isAssignableFrom
(
field
.
getType
()))
{
// 集合类型
//读取属性的注解是否引用其他字段的长度
if
(
field
.
isAnnotationPresent
(
RefNumFlag
.
class
))
{
RefNumFlag
refNumFlag
=
field
.
getAnnotation
(
RefNumFlag
.
class
);
String
refField
=
refNumFlag
.
value
();
Class
<?>
clazz1
=
t
.
getClass
();
Field
nameField
=
clazz1
.
getDeclaredField
(
refField
);
Type
genericType
=
nameField
.
getGenericType
();
nameField
.
setAccessible
(
true
);
if
(
genericType
instanceof
ParameterizedType
)
{
ParameterizedType
pt
=
(
ParameterizedType
)
genericType
;
Type
[]
actualTypes
=
pt
.
getActualTypeArguments
();
if
(
actualTypes
.
length
>
0
)
{
actualTypes
[
0
].
getClass
();
int
len
=
(
int
)
nameField
.
get
(
t
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
actualTypes
[
0
].
getClass
();
}
}
}
}
}
else
if
(
field
.
getType
()==
String
.
class
)
{
//类型为字符串
readBuf
(
t
,
field
,
data
);
}
else
{
//其他对象类型
Class
<?>
cls
=
Class
.
forName
(
field
.
getType
().
getName
());
Object
obj
=
cls
.
newInstance
();
parse
(
data
,
obj
);
field
.
set
(
t
,
obj
);
}
rstMap
.
put
(
num
,
field
);
}
}
return
t
;
}
/**
* 读取字节流
* @param t
* @param field
* @param data
* @throws IllegalArgumentException
* @throws IllegalAccessException
*/
public
static
void
readBuf
(
Object
t
,
Field
field
,
ByteBuf
data
)
throws
IllegalArgumentException
,
IllegalAccessException
{
if
(
data
.
readerIndex
()==
data
.
maxCapacity
()
)
return
;
FieldDef
fieldDef
=
null
;
if
(
field
.
isAnnotationPresent
(
FieldDef
.
class
))
{
fieldDef
=
field
.
getAnnotation
(
FieldDef
.
class
);
}
Class
<?>
type
=
field
.
getType
();
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
)
{
field
.
set
(
t
,
data
.
readUnsignedByte
());
}
else
if
(
type
==
int
.
class
)
{
field
.
set
(
t
,
data
.
readUnsignedShort
());
}
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
)
{
field
.
set
(
t
,
data
.
readLong
());
}
else
if
(
type
==
long
.
class
&&
fieldDef
!=
null
&&
fieldDef
.
type
().
equals
(
"BYTE"
)
)
{
field
.
set
(
t
,
data
.
readLong
());
}
}
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
);
// 指定小端模式
buffer
.
putLong
(
value
);
// 将long值存入buffer
return
buffer
.
array
();
// 获取byte数组
}
public
static
byte
[]
intToBytes
(
int
value
)
{
ByteBuffer
buffer
=
ByteBuffer
.
allocate
(
4
);
buffer
.
order
(
ByteOrder
.
BIG_ENDIAN
);
// 指定小端模式
buffer
.
putLong
(
value
);
// 将long值存入buffer
return
buffer
.
array
();
// 获取byte数组
}
public
static
String
byteToHexString
(
byte
[]
bytes
)
{
StringBuilder
sb
=
new
StringBuilder
();
for
(
byte
b
:
bytes
)
{
sb
.
append
(
String
.
format
(
"%02x"
,
b
));
}
return
sb
.
toString
();
//return null;
public
static
<
T
>
T
parse
(
ByteBuf
data
,
T
t
)
throws
InstantiationException
,
IllegalAccessException
,
NoSuchFieldException
,
SecurityException
,
ClassNotFoundException
{
Field
[]
fields
=
t
.
getClass
().
getDeclaredFields
();
List
<
Field
>
fList
=
new
ArrayList
<>();
SortedMap
<
Integer
,
Field
>
rstMap
=
new
TreeMap
<>();
for
(
Field
field
:
fields
)
{
if
(
field
.
isAnnotationPresent
(
Order
.
class
))
{
fList
.
add
(
field
);
}
}
Collections
.
sort
(
fList
,
new
Comparator
<
Field
>()
{
@Override
public
int
compare
(
Field
f1
,
Field
f2
)
{
return
f1
.
getAnnotation
(
Order
.
class
).
value
()
-
f2
.
getAnnotation
(
Order
.
class
).
value
();
}
});
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
);
int
num
=
order
.
value
();
//基础数据类型 且 不是数组
if
(
field
.
getType
().
isPrimitive
()
&&
!
field
.
getType
().
isArray
())
{
// data.re
// field.set(fList, rstMap);
readBuf
(
t
,
field
,
data
);
}
else
if
(
field
.
getClass
().
isPrimitive
()
&&
field
.
getType
().
isArray
())
{
// 基础数据类型 且 是数组
}
else
if
(
List
.
class
.
isAssignableFrom
(
field
.
getType
()))
{
// 集合类型
//读取属性的注解是否引用其他字段的长度
if
(
field
.
isAnnotationPresent
(
RefNumFlag
.
class
))
{
RefNumFlag
refNumFlag
=
field
.
getAnnotation
(
RefNumFlag
.
class
);
String
refField
=
refNumFlag
.
value
();
Class
<?>
clazz1
=
t
.
getClass
();
Field
nameField
=
clazz1
.
getDeclaredField
(
refField
);
Type
genericType
=
nameField
.
getGenericType
();
nameField
.
setAccessible
(
true
);
if
(
genericType
instanceof
ParameterizedType
)
{
ParameterizedType
pt
=
(
ParameterizedType
)
genericType
;
Type
[]
actualTypes
=
pt
.
getActualTypeArguments
();
if
(
actualTypes
.
length
>
0
)
{
actualTypes
[
0
].
getClass
();
int
len
=
(
int
)
nameField
.
get
(
t
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
actualTypes
[
0
].
getClass
();
}
}
}
}
}
else
if
(
field
.
getType
()
==
String
.
class
)
{
//类型为字符串
readBuf
(
t
,
field
,
data
);
}
else
{
//其他对象类型
Class
<?>
cls
=
Class
.
forName
(
field
.
getType
().
getName
());
Object
obj
=
cls
.
newInstance
();
parse
(
data
,
obj
);
field
.
set
(
t
,
obj
);
}
rstMap
.
put
(
num
,
field
);
}
}
return
t
;
}
/**
* 读取字节流
*
* @param t
* @param field
* @param data
* @throws IllegalArgumentException
* @throws IllegalAccessException
*/
public
static
void
readBuf
(
Object
t
,
Field
field
,
ByteBuf
data
)
throws
IllegalArgumentException
,
IllegalAccessException
{
if
(
data
.
readerIndex
()
==
data
.
maxCapacity
())
return
;
FieldDef
fieldDef
=
null
;
if
(
field
.
isAnnotationPresent
(
FieldDef
.
class
))
{
fieldDef
=
field
.
getAnnotation
(
FieldDef
.
class
);
}
Class
<?>
type
=
field
.
getType
();
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
)
{
field
.
set
(
t
,
data
.
readUnsignedByte
());
}
else
if
(
type
==
int
.
class
)
{
field
.
set
(
t
,
data
.
readUnsignedShort
());
}
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
)
{
field
.
set
(
t
,
data
.
readLong
());
}
else
if
(
type
==
long
.
class
&&
fieldDef
!=
null
&&
fieldDef
.
type
().
equals
(
"BYTE"
))
{
field
.
set
(
t
,
data
.
readLong
());
}
}
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
);
// 指定小端模式
buffer
.
putLong
(
value
);
// 将long值存入buffer
return
buffer
.
array
();
// 获取byte数组
}
public
static
byte
[]
intToBytes
(
int
value
)
{
ByteBuffer
buffer
=
ByteBuffer
.
allocate
(
4
);
buffer
.
order
(
ByteOrder
.
BIG_ENDIAN
);
// 指定小端模式
buffer
.
putLong
(
value
);
// 将long值存入buffer
return
buffer
.
array
();
// 获取byte数组
}
public
static
String
byteToHexString
(
byte
[]
bytes
)
{
StringBuilder
sb
=
new
StringBuilder
();
for
(
byte
b
:
bytes
)
{
sb
.
append
(
String
.
format
(
"%02x"
,
b
));
}
return
sb
.
toString
();
//return null;
// ByteBuffer buffer = ByteBuffer.allocate(8);
// buffer.order(ByteOrder.LITTLE_ENDIAN); // 指定小端模式
// 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
;
if
(
hex
.
length
()
>=
padLength
)
{
return
hex
.
substring
(
hex
.
length
()
-
padLength
);
// 超长时截断
}
return
String
.
format
(
"%0"
+
padLength
+
"d"
,
0
).
replace
(
"0"
,
"0"
)
+
hex
;
// 或直接格式化
}
public
static
void
main
(
String
[]
args
)
throws
InstantiationException
,
IllegalAccessException
,
NoSuchFieldException
,
SecurityException
,
ClassNotFoundException
{
String
hexString
=
"F20000000015018cb864640000000000"
;
byte
[]
bytes
=
HexStringToByteArray
.
hexStringToByteArray
(
hexString
);
ByteBuf
byteBuf
=
Unpooled
.
buffer
(
16
);
long
l
=
500000
;
//3600000000
// 1164916946
// byte [] bs = Long.toHexString(l);
String
s
=
long2Hex
(
l
,
4
);
//longToBytes1(l);
int
i
=
990
;
String
hex
=
Integer
.
toHexString
(
i
);
String
vid
=
"T1023459"
;
byte
[]
by1
=
vid
.
getBytes
();
s
=
byteToHexString
(
by1
);
System
.
out
.
println
(
s
);
}
public
static
String
long2Hex
(
long
num
,
int
len
)
{
String
hex
=
Long
.
toHexString
(
num
);
int
padLength
=
len
*
2
;
if
(
hex
.
length
()
>=
padLength
)
{
return
hex
.
substring
(
hex
.
length
()
-
padLength
);
// 超长时截断
}
return
String
.
format
(
"%0"
+
padLength
+
"d"
,
0
).
replace
(
"0"
,
"0"
)
+
hex
;
// 或直接格式化
}
public
static
void
main
(
String
[]
args
)
throws
InstantiationException
,
IllegalAccessException
,
NoSuchFieldException
,
SecurityException
,
ClassNotFoundException
{
String
hexString
=
"F20000000015018cb864640000000000"
;
byte
[]
bytes
=
HexStringToByteArray
.
hexStringToByteArray
(
hexString
);
ByteBuf
byteBuf
=
Unpooled
.
buffer
(
16
);
long
l
=
500000
;
//3600000000
// 1164916946
// byte [] bs = Long.toHexString(l);
String
s
=
long2Hex
(
l
,
4
);
//longToBytes1(l);
int
i
=
33
;
String
hex
=
Integer
.
toHexString
(
i
);
String
vid
=
"T1023459"
;
byte
[]
by1
=
vid
.
getBytes
();
s
=
byteToHexString
(
by1
);
System
.
out
.
println
(
s
);
//
//
// List<Byte> byteList = new ArrayList<Byte>();
//
// Byte[] bytes = byteList.toArray(new Byte[byteList.size()]);
//byte[] bs = convoter(bytes);
//byteBuf.writeBytes(bytes);
//VehicleMessage vehicleMessage = parse(byteBuf,new VehicleMessage());
//System.out.print(vehicleMessage);
}
public
static
void
convoterBean
(
Object
source
,
Object
target
)
throws
IllegalArgumentException
,
IllegalAccessException
,
ClassNotFoundException
,
InstantiationException
,
NoSuchFieldException
,
SecurityException
{
Field
[]
fields
=
source
.
getClass
().
getDeclaredFields
();
List
<
Field
>
fList
=
new
ArrayList
<>();
SortedMap
<
Integer
,
Field
>
rstMap
=
new
TreeMap
<>();
for
(
Field
field
:
fields
)
{
field
.
setAccessible
(
true
);
Object
o
=
field
.
get
(
source
);
if
(
o
==
null
)
{
continue
;
}
OffsetDef
offsetDef
=
null
;
if
(
field
.
isAnnotationPresent
(
OffsetDef
.
class
))
{
offsetDef
=
field
.
getAnnotation
(
OffsetDef
.
class
);
}
//获取目标对象指定的属性
Field
tField
=
target
.
getClass
().
getDeclaredField
(
field
.
getName
());
tField
.
setAccessible
(
true
);
if
(
field
.
isAnnotationPresent
(
Order
.
class
))
{
if
(
field
.
getType
().
isPrimitive
()
&&
!
field
.
getType
().
isArray
()
)
{
//如果属性添加了自定义注解 offset
Class
<?>
type
=
field
.
getType
();
if
(
offsetDef
!=
null
)
{
double
offset
=
offsetDef
.
value
();
int
ofsetType
=
offsetDef
.
type
();
int
minValidLength
=
offsetDef
.
minValidLength
();
//startindex
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;
float
f
=
(
float
)
((
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
,
(
float
)
f
);
}
else
{
double
f
=(
Long
)
o
*
offset
;
tField
.
set
(
target
,
(
float
)
f
);
}
}
else
{
double
d
=(
Long
)
o
*
offset
;
tField
.
set
(
target
,
d
);
}
}
}
else
{
tField
.
set
(
target
,
o
);
}
}
else
if
(
field
.
getClass
().
isPrimitive
()
&&
field
.
getType
().
isArray
()){
// 基础数据类型 且 是数组
}
else
if
(
List
.
class
.
isAssignableFrom
(
field
.
getType
()))
{
// 集合类型
//读取属性的注解是否引用其他字段的长度
if
(
field
.
isAnnotationPresent
(
RefNumFlag
.
class
))
{
//byte[] bs = convoter(bytes);
//byteBuf.writeBytes(bytes);
//VehicleMessage vehicleMessage = parse(byteBuf,new VehicleMessage());
//System.out.print(vehicleMessage);
}
public
static
void
convoterBean
(
Object
source
,
Object
target
)
{
Field
field
;
Field
tField
;
try
{
Field
[]
fields
=
source
.
getClass
().
getDeclaredFields
();
//List<Field> fList = new ArrayList<>();
//SortedMap<Integer,Field> rstMap = new TreeMap<>();
for
(
Field
cfield
:
fields
)
{
field
=
cfield
;
field
.
setAccessible
(
true
);
Object
o
=
field
.
get
(
source
);
if
(
o
==
null
)
{
continue
;
}
OffsetDef
offsetDef
=
null
;
if
(
field
.
isAnnotationPresent
(
OffsetDef
.
class
))
{
offsetDef
=
field
.
getAnnotation
(
OffsetDef
.
class
);
}
//获取目标对象指定的属性
tField
=
target
.
getClass
().
getDeclaredField
(
field
.
getName
());
tField
.
setAccessible
(
true
);
if
(
field
.
isAnnotationPresent
(
Order
.
class
))
{
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
();
//startindex
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
,
(
short
)
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
,
(
float
)
f
);
}
else
{
double
f
=
(
Long
)
o
*
offset
;
tField
.
set
(
target
,
(
float
)
f
);
}
}
else
{
double
d
=
(
Long
)
o
*
offset
;
tField
.
set
(
target
,
(
float
)
d
);
}
}
}
else
{
tField
.
set
(
target
,
o
);
}
}
else
if
(
field
.
getClass
().
isPrimitive
()
&&
field
.
getType
().
isArray
())
{
// 基础数据类型 且 是数组
}
else
if
(
List
.
class
.
isAssignableFrom
(
field
.
getType
()))
{
// 集合类型
//读取属性的注解是否引用其他字段的长度
if
(
field
.
isAnnotationPresent
(
RefNumFlag
.
class
))
{
// RefNumFlag refNumFlag = field.getAnnotation(RefNumFlag.class);
// String refField = refNumFlag.value();
// Class<?> clazz1 = t.getClass();
// Field nameField = clazz1.getDeclaredField(refField);
// Type genericType = nameField.getGenericType();
// nameField.setAccessible(true);
//
//
// if (genericType instanceof ParameterizedType) {
// ParameterizedType pt = (ParameterizedType) genericType;
// Type[] actualTypes = pt.getActualTypeArguments();
...
...
@@ -306,29 +330,51 @@ public class Parse {
// }
// }
// }
}
}
else
if
(
field
.
getType
()==
String
.
class
)
{
//类型为字符串
}
}
else
if
(
field
.
getType
()
==
String
.
class
)
{
//类型为字符串
// try {
// String s = (String)o;
// String s1 = new String(s.getBytes());
tField
.
set
(
target
,
o
);
tField
.
set
(
target
,
o
);
// }catch(Exception e) {
// e.printStackTrace();
// }
}
else
{
//其他对象类型
Class
<?>
cls
=
Class
.
forName
(
tField
.
getType
().
getName
());
Object
obj
=
cls
.
newInstance
();
convoterBean
(
o
,
obj
);
tField
.
set
(
target
,
obj
);
}
}
}
}
}
else
{
//其他对象类型
Class
<?>
cls
=
Class
.
forName
(
tField
.
getType
().
getName
());
Object
obj
=
cls
.
newInstance
();
convoterBean
(
o
,
obj
);
tField
.
set
(
target
,
obj
);
}
}
}
}
catch
(
IllegalArgumentException
e
)
{
System
.
out
.
println
(
"e = "
+
e
.
getMessage
());
}
catch
(
IllegalAccessException
e
)
{
System
.
out
.
println
(
"e = "
+
e
.
getMessage
());
}
catch
(
ClassNotFoundException
e
)
{
System
.
out
.
println
(
"e = "
+
e
.
getMessage
());
}
catch
(
InstantiationException
e
)
{
System
.
out
.
println
(
"e = "
+
e
.
getMessage
());
}
catch
(
NoSuchFieldException
e
)
{
System
.
out
.
println
(
"e = "
+
e
.
getMessage
());
}
catch
(
SecurityException
e
)
{
System
.
out
.
println
(
"e = "
+
e
.
getMessage
());
}
}
public
static
byte
[]
convoter
(
Byte
[]
bytes
)
{
byte
[]
bs
=
new
byte
[
bytes
.
length
];
int
i
=
0
;
for
(
Byte
b
:
bytes
)
{
bs
[
i
++]
=
b
;
}
return
bs
;
}
}
src/main/java/com/cusc/adas/v2x/vo/Position2D.java
View file @
65b50318
...
...
@@ -6,10 +6,10 @@ import com.cusc.adas.v2x.utils.Order;
public
class
Position2D
{
//经度
@Order
(
1
)
@OffsetDef
(
value
=
1
0000000
)
@OffsetDef
(
value
=
0.
000000
1
,
minValidLength
=
1
0
)
private
long
longitude
;
//纬度
@Order
(
2
)
@OffsetDef
(
value
=
1
000000
0
)
@OffsetDef
(
value
=
0.
000000
1
,
minValidLength
=
9
)
private
long
latitude
;
}
src/main/java/com/cusc/adas/v2x/vo/VehicleInfo.java
View file @
65b50318
...
...
@@ -7,118 +7,116 @@ import com.cusc.adas.v2x.utils.NumFlag;
import
com.cusc.adas.v2x.utils.OffsetDef
;
import
com.cusc.adas.v2x.utils.Order
;
import
com.cusc.adas.v2x.utils.RefNumFlag
;
/**
* 车辆基础信息
* @author huangml
*
* @author huangml
*/
public
class
VehicleInfo
{
//车辆编号
@Order
(
1
)
@FieldDef
(
type
=
"BYTE"
,
isArray
=
true
,
length
=
8
)
private
String
vehicleId
;
//消息编号
@Order
(
2
)
@FieldDef
(
type
=
"BYTE"
,
isArray
=
true
,
length
=
8
)
private
long
messageId
;
//GNSS 时间戳
@Order
(
3
)
@FieldDef
(
type
=
"TIMESTAMP"
,
isArray
=
false
,
length
=
8
)
private
long
timestampGNSS
;
//GNSS 速度 单位:0.01 m/s
@Order
(
4
)
@OffsetDef
(
value
=
0.036
,
type
=
2
)
private
int
velocityGNSS
;
//位置
@Order
(
5
)
private
Position
position
;
//航向角 单位为 1e-4 °
@Order
(
6
)
@OffsetDef
(
value
=
0.0001
,
type
=
2
)
private
int
heading
;
//档位
@Order
(
7
)
private
byte
tapPos
;
//方向盘转角 单位为 1e-4 °
@Order
(
8
)
@OffsetDef
(
value
=
0.0001
)
private
long
steeringAngle
;
//当前车速 单位:0.01m/s
@Order
(
9
)
@OffsetDef
(
value
=
0.036
,
type
=
2
)
private
int
velocity
;
//纵向加速度 单位:0.01m/s
@Order
(
10
)
@OffsetDef
(
value
=
36
,
type
=
2
)
private
int
accelerationLon
;
//横向加速度 单位:0.01m/s
@Order
(
11
)
@OffsetDef
(
value
=
36
,
type
=
2
)
private
int
accelerationLat
;
//垂向加速度 单位:0.01m/s
@Order
(
12
)
@OffsetDef
(
value
=
36
,
type
=
2
)
private
int
accelerationVer
;
//横摆角速度 单位:0.01m/s
@Order
(
13
)
@OffsetDef
(
value
=
36
,
type
=
2
)
private
int
yawRate
;
//油门开度 单位:0.1%
@Order
(
14
)
private
int
accelPos
;
//发动机输出转速 单位:r/min
@Order
(
15
)
private
int
engineSpeed
;
//发动机扭矩 单位:0.01Nm
@Order
(
16
)
private
long
engineTorque
;
//制动踏板开关
@Order
(
17
)
private
short
brakeFlag
;
//制动踏板开度 单位:0.1%
@Order
(
18
)
private
int
brakePos
;
//制动主缸压力 单位 0.01MPa
@Order
(
19
)
private
int
brakePressure
;
//油耗 单位 0.01L/100km
@Order
(
20
)
private
int
fuelConsumption
;
//车辆驾驶模式
@Order
(
21
)
private
byte
driveMode
;
//目的地位置
@Order
(
22
)
private
Position2D
destLocation
;
//途经点数量
@Order
(
23
)
@NumFlag
private
short
passPointsNum
;
//途经点
@Order
(
24
)
@RefNumFlag
(
value
=
"passPointsNum"
)
private
List
<
Position2D
>
passPoints
;
//车辆编号
@Order
(
1
)
@FieldDef
(
type
=
"BYTE"
,
isArray
=
true
,
length
=
8
)
private
String
vehicleId
;
//消息编号
@Order
(
2
)
@FieldDef
(
type
=
"BYTE"
,
isArray
=
true
,
length
=
8
)
private
long
messageId
;
//GNSS 时间戳
@Order
(
3
)
@FieldDef
(
type
=
"TIMESTAMP"
,
isArray
=
false
,
length
=
8
)
private
long
timestampGNSS
;
//GNSS 速度 单位:0.01 m/s
@Order
(
4
)
@OffsetDef
(
value
=
0.036
,
type
=
2
)
private
int
velocityGNSS
;
//位置
@Order
(
5
)
private
Position
position
;
/****[0..3600000],正北方向顺时针旋转至与车辆当前运动方向重合所转 过的角度,单位为 1e-4 ° , 不可缺省,0xFFFFFFFF 表示异常**/
@Order
(
6
)
@OffsetDef
(
value
=
0.0001
)
private
long
heading
;
/**
* 档位 枚举类型:[0..50],0:数据失效;1-20:表示手动档车辆前进档对 应档位,1 表示 1 档,2 表示 2 档,以此类推;21-30:表示手动挡车 辆倒档对应档位,
* 21 表示 R1 档,22 表示 R2 档,以此类推;31:D 档 (前进档);32:R 档(倒档);33:P 档(驻车档);34:N 档(空 档);
* 35:S 档(运动模式);36:L 档(低速档);37:H 档;38; HL 档;39-50:预留,不可缺省,0xFF 表示异常
*/
@Order
(
7
)
private
short
tapPos
;
//方向盘转角 单位为 1e-4 °
@Order
(
8
)
@OffsetDef
(
value
=
0.0001
)
private
long
steeringAngle
;
/**[0..20000],CAN 总线数据中的行驶速度,单位:0.01m/s,0xFFFF 表 示缺省***/
@Order
(
9
)
@OffsetDef
(
value
=
0.036
,
type
=
2
)
private
int
velocity
;
//纵向加速度 单位:0.01m/s
@Order
(
10
)
@OffsetDef
(
value
=
0.036
,
type
=
2
)
private
int
accelerationLon
;
//横向加速度 单位:0.01m/s
@Order
(
11
)
@OffsetDef
(
value
=
0.036
,
type
=
2
)
private
int
accelerationLat
;
//垂向加速度 单位:0.01m/s
@Order
(
12
)
@OffsetDef
(
value
=
0.036
,
type
=
2
)
private
int
accelerationVer
;
//横摆角速度 单位:0.01m/s
@Order
(
13
)
@OffsetDef
(
value
=
0.036
,
type
=
2
)
private
int
yawRate
;
//油门开度 单位:0.1%
@Order
(
14
)
private
int
accelPos
;
//发动机输出转速 单位:r/min
@Order
(
15
)
private
int
engineSpeed
;
//发动机扭矩 单位:0.01Nm
@Order
(
16
)
private
long
engineTorque
;
//制动踏板开关
@Order
(
17
)
private
short
brakeFlag
;
//制动踏板开度 单位:0.1%
@Order
(
18
)
private
int
brakePos
;
//制动主缸压力 单位 0.01MPa
@Order
(
19
)
private
int
brakePressure
;
//油耗 单位 0.01L/100km
@Order
(
20
)
private
int
fuelConsumption
;
//车辆驾驶模式
@Order
(
21
)
private
short
driveMode
;
//目的地位置
@Order
(
22
)
private
Position2D
destLocation
;
//途经点数量
@Order
(
23
)
@NumFlag
private
short
passPointsNum
;
//途经点
@Order
(
24
)
@RefNumFlag
(
value
=
"passPointsNum"
)
private
List
<
Position2D
>
passPoints
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment