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
ccc19945
Commit
ccc19945
authored
Jul 01, 2025
by
p x
Browse files
调通车辆辅助驾驶信息
parent
4b522d9e
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/main/java/com/cusc/adas/v2x/dto/VehicleBodyDto.java
View file @
ccc19945
package
com.cusc.adas.v2x.dto
;
package
com.cusc.adas.v2x.dto
;
import
com.cusc.adas.v2x.vo.AutomaticDriveInfo
;
import
com.cusc.adas.v2x.vo.VehicleStatusInfo
;
public
class
VehicleBodyDto
{
public
class
VehicleBodyDto
{
private
VehicleInfoDto
vehicleInfo
;
private
VehicleInfoDto
vehicleInfo
;
private
VehicleStatusInfo
vehicleStatusInfo
;
private
VehicleStatusInfo
Dto
vehicleStatusInfo
;
private
AutomaticDriveInfo
automaticDriveInfo
;
//
private AutomaticDriveInfo
Dto
automaticDriveInfo;
public
VehicleInfoDto
getVehicleInfo
()
{
public
VehicleInfoDto
getVehicleInfo
()
{
return
vehicleInfo
;
return
vehicleInfo
;
}
}
public
VehicleStatusInfoDto
getVehicleStatusInfo
()
{
return
vehicleStatusInfo
;
}
}
}
src/main/java/com/cusc/adas/v2x/dto/VehicleStatusInfoDto.java
View file @
ccc19945
...
@@ -46,7 +46,7 @@ public class VehicleStatusInfoDto {
...
@@ -46,7 +46,7 @@ public class VehicleStatusInfoDto {
private
short
dmsFlag
;
private
short
dmsFlag
;
//里程
//里程
@Order
(
11
)
@Order
(
11
)
private
long
mileage
;
private
double
mileage
;
//sweeping状态
//sweeping状态
@Order
(
12
)
@Order
(
12
)
private
short
sweepingFlag
;
private
short
sweepingFlag
;
...
@@ -56,31 +56,31 @@ public class VehicleStatusInfoDto {
...
@@ -56,31 +56,31 @@ public class VehicleStatusInfoDto {
// 车辆运行状态数据 2-车辆辅助驾驶系统信息及其他状态信息数据结构(续)
// 车辆运行状态数据 2-车辆辅助驾驶系统信息及其他状态信息数据结构(续)
//油量 对应车辆油量表读数,单位:0.1 L,
//油量 对应车辆油量表读数,单位:0.1 L,
@Order
(
14
)
@Order
(
14
)
private
in
t
fuelGauge
;
private
floa
t
fuelGauge
;
//电池剩余电量 0.01%,
//电池剩余电量 0.01%,
@Order
(
15
)
@Order
(
15
)
private
in
t
soc
;
private
floa
t
soc
;
//电池温度 [0..200],单位:摄氏度(℃),
//电池温度 [0..200],单位:摄氏度(℃),
//数据偏移量 100,表示-100℃~100℃ ,0xFF 表示缺省
//数据偏移量 100,表示-100℃~100℃ ,0xFF 表示缺省
@Order
(
16
)
@Order
(
16
)
private
short
temperature
;
private
short
temperature
;
//预计续航里程 单位:千米(km),
//预计续航里程 单位:千米(km),
@Order
(
17
)
@Order
(
17
)
private
long
endurance
;
private
double
endurance
;
//车辆故障状态
//车辆故障状态
@Order
(
18
)
@Order
(
18
)
private
int
vehFault
;
private
int
vehFault
;
//电机转速
//电机转速
@Order
(
19
)
@Order
(
19
)
private
int
motorspeed
;
private
int
motorspeed
;
//电机转矩
//电机转矩
@Order
(
20
)
@Order
(
20
)
private
long
motortorque
;
private
double
motortorque
;
//运行模式 车辆运行模式,1:纯电驱动模式;2:混合驱动 模式;3:行车充电模式;4:能量回收模式;5:停车充电模式;6: 能量混合回充模式;
//运行模式 车辆运行模式,1:纯电驱动模式;2:混合驱动 模式;3:行车充电模式;4:能量回收模式;5:停车充电模式;6: 能量混合回充模式;
@Order
(
21
)
@Order
(
21
)
private
short
vehMode
;
private
short
vehMode
;
...
@@ -124,5 +124,12 @@ public class VehicleStatusInfoDto {
...
@@ -124,5 +124,12 @@ public class VehicleStatusInfoDto {
//自定义字段内容
//自定义字段内容
@Order
(
33
)
@Order
(
33
)
private
String
userdefinedData
;
private
String
userdefinedData
;
public
float
getSoc
()
{
return
soc
;
}
public
int
getLights
()
{
return
lights
;
}
}
}
src/main/java/com/cusc/adas/v2x/events/VehicleBodyEvent.kt
View file @
ccc19945
package
com.cusc.adas.v2x.events
package
com.cusc.adas.v2x.events
import
com.cusc.adas.v2x.dto.VehicleInfoDto
import
com.cusc.adas.v2x.dto.VehicleInfoDto
import
com.cusc.adas.v2x.dto.VehicleStatusInfoDto
/**车辆运行状态**/
/**车辆运行状态**/
class
VehicleBodyEvent
{
class
VehicleBodyEvent
{
var
vehicleInfo
:
VehicleInfoDto
?
=
null
var
vehicleInfo
:
VehicleInfoDto
?
=
null
var
vehicleStatusInfo
:
VehicleStatusInfoDto
?
=
null
}
}
\ No newline at end of file
src/main/java/com/cusc/adas/v2x/utils/Parse.java
View file @
ccc19945
...
@@ -20,424 +20,430 @@ import io.netty.buffer.ByteBuf;
...
@@ -20,424 +20,430 @@ import io.netty.buffer.ByteBuf;
import
io.netty.buffer.Unpooled
;
import
io.netty.buffer.Unpooled
;
public
class
Parse
{
public
class
Parse
{
public
static
<
T
>
T
parse
(
ByteBuf
data
,
T
t
)
throws
InstantiationException
,
IllegalAccessException
,
NoSuchFieldException
,
SecurityException
,
ClassNotFoundException
{
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
<>();
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
))
{
if
(
field
.
isAnnotationPresent
(
Order
.
class
))
{
fList
.
add
(
field
);
fList
.
add
(
field
);
}
}
}
}
Collections
.
sort
(
fList
,
new
Comparator
<
Field
>()
{
Collections
.
sort
(
fList
,
new
Comparator
<
Field
>()
{
@Override
@Override
public
int
compare
(
Field
f1
,
Field
f2
)
{
public
int
compare
(
Field
f1
,
Field
f2
)
{
return
f1
.
getAnnotation
(
Order
.
class
).
value
()
-
f2
.
getAnnotation
(
Order
.
class
).
value
();
return
f1
.
getAnnotation
(
Order
.
class
).
value
()
-
f2
.
getAnnotation
(
Order
.
class
).
value
();
}
}
});
});
for
(
Field
field
:
fList
)
{
for
(
Field
field
:
fList
)
{
field
.
setAccessible
(
true
);
field
.
setAccessible
(
true
);
if
(
field
.
isAnnotationPresent
(
Order
.
class
))
{
if
(
field
.
isAnnotationPresent
(
Order
.
class
))
{
String
fieldName
=
field
.
getName
();
String
fieldName
=
field
.
getName
();
Order
order
=
field
.
getAnnotation
(
Order
.
class
);
Order
order
=
field
.
getAnnotation
(
Order
.
class
);
System
.
out
.
println
(
fieldName
);
// System.out.println(fieldName);
int
num
=
order
.
value
();
int
num
=
order
.
value
();
//基础数据类型 且 不是数组
//基础数据类型 且 不是数组
if
(
field
.
getType
().
isPrimitive
()
&&
!
field
.
getType
().
isArray
()
)
{
if
(
field
.
getType
().
isPrimitive
()
&&
!
field
.
getType
().
isArray
())
{
// data.re
// data.re
// field.set(fList, rstMap);
// field.set(fList, rstMap);
readBuf
(
t
,
field
,
data
);
readBuf
(
t
,
field
,
data
);
}
else
if
(
field
.
getType
().
isArray
()){
}
else
if
(
field
.
getType
().
isArray
())
{
// 基础数据类型 且 是数组
// 基础数据类型 且 是数组
readBuf
(
t
,
field
,
data
);
readBuf
(
t
,
field
,
data
);
}
else
if
(
List
.
class
.
isAssignableFrom
(
field
.
getType
()))
{
}
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
);
RefNumFlag
refNumFlag
=
field
.
getAnnotation
(
RefNumFlag
.
class
);
String
refField
=
refNumFlag
.
value
();
String
refField
=
refNumFlag
.
value
();
Class
<?>
clazz1
=
t
.
getClass
();
Class
<?>
clazz1
=
t
.
getClass
();
Field
nameField
=
clazz1
.
getDeclaredField
(
refField
);
Field
nameField
=
clazz1
.
getDeclaredField
(
refField
);
Type
genericType
=
field
.
getGenericType
();
Type
genericType
=
field
.
getGenericType
();
nameField
.
setAccessible
(
true
);
nameField
.
setAccessible
(
true
);
if
(
genericType
instanceof
ParameterizedType
)
{
if
(
genericType
instanceof
ParameterizedType
)
{
ParameterizedType
pt
=
(
ParameterizedType
)
genericType
;
ParameterizedType
pt
=
(
ParameterizedType
)
genericType
;
Type
[]
actualTypes
=
pt
.
getActualTypeArguments
();
Type
[]
actualTypes
=
pt
.
getActualTypeArguments
();
if
(
actualTypes
!=
null
&&
actualTypes
.
length
>
0
)
{
if
(
actualTypes
!=
null
&&
actualTypes
.
length
>
0
)
{
actualTypes
[
0
].
getClass
();
actualTypes
[
0
].
getClass
();
long
len
=
0
l
;
long
len
=
0
l
;
if
(
nameField
.
getType
()==
short
.
class
)
{
if
(
nameField
.
getType
()
==
short
.
class
)
{
short
val
=
(
short
)
nameField
.
get
(
t
);
short
val
=
(
short
)
nameField
.
get
(
t
);
len
=
(
long
)
val
;
len
=
(
long
)
val
;
}
else
if
(
nameField
.
getType
()==
int
.
class
)
{
}
else
if
(
nameField
.
getType
()
==
int
.
class
)
{
int
val
=
(
int
)
nameField
.
get
(
t
);
int
val
=
(
int
)
nameField
.
get
(
t
);
len
=
(
long
)
val
;
len
=
(
long
)
val
;
}
else
if
(
nameField
.
getType
()==
long
.
class
)
{
}
else
if
(
nameField
.
getType
()
==
long
.
class
)
{
len
=
(
long
)
nameField
.
get
(
t
);
len
=
(
long
)
nameField
.
get
(
t
);
}
}
//short len= (short) nameField.get(t);
//short len= (short) nameField.get(t);
if
(
len
>
0
)
{
if
(
len
>
0
)
{
List
list
=
new
ArrayList
<>();
List
list
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
String
classname
=
actualTypes
[
0
].
getTypeName
();
String
classname
=
actualTypes
[
0
].
getTypeName
();
Object
obj
=
null
;
Object
obj
=
null
;
if
(
classname
.
contains
(
"Short"
)
)
{
if
(
classname
.
contains
(
"Short"
))
{
obj
=
data
.
readUnsignedByte
();
obj
=
data
.
readUnsignedByte
();
}
else
if
(
classname
.
contains
(
"Integer"
))
{
}
else
if
(
classname
.
contains
(
"Integer"
))
{
obj
=
data
.
readUnsignedShort
();
obj
=
data
.
readUnsignedShort
();
}
else
if
(
classname
.
contains
(
"Long"
))
{
}
else
if
(
classname
.
contains
(
"Long"
))
{
obj
=
data
.
readUnsignedInt
();
obj
=
data
.
readUnsignedInt
();
}
else
{
}
else
{
Class
<?>
cls
=
Class
.
forName
(
actualTypes
[
0
].
getTypeName
());
;
Class
<?>
cls
=
Class
.
forName
(
actualTypes
[
0
].
getTypeName
());
obj
=
cls
.
newInstance
();
;
parse
(
data
,
obj
);
obj
=
cls
.
newInstance
();
}
parse
(
data
,
obj
);
}
list
.
add
(
obj
);
}
list
.
add
(
obj
);
System
.
out
.
println
(
"actualTypes::"
+
actualTypes
[
0
].
getTypeName
());
}
field
.
set
(
t
,
list
);
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
();
DynamicsClassDef
dynamicsClassDef
=
field
.
getAnnotation
(
DynamicsClassDef
.
class
);
DependencyDef
dependencyDef
=
field
.
getAnnotation
(
DependencyDef
.
class
);
String
classtype
=
dynamicsClassDef
.
classtype
();
String
fieldname
=
dependencyDef
.
value
();
DependencyDef
dependencyDef
=
field
.
getAnnotation
(
DependencyDef
.
class
);
Field
tField2
=
t
.
getClass
().
getDeclaredField
(
fieldname
);
String
fieldname
=
dependencyDef
.
value
();
tField2
.
setAccessible
(
true
);
Field
tField2
=
t
.
getClass
().
getDeclaredField
(
fieldname
);
Short
value
=(
Short
)
tField2
.
get
(
t
);
tField2
.
setAccessible
(
true
);
Short
value
=
(
Short
)
tField2
.
get
(
t
);
RefNumFlag
refNumFlag
=
field
.
getAnnotation
(
RefNumFlag
.
class
);
String
refFieldName
=
refNumFlag
.
value
()
;
RefNumFlag
refNumFlag
=
field
.
getAnnotation
(
RefNumFlag
.
class
);
Field
tField
=
t
.
getClass
().
getDeclaredField
(
fieldname
);
String
refFieldName
=
refNumFlag
.
value
();
tField
.
setAccessible
(
true
);
Field
tField
=
t
.
getClass
().
getDeclaredField
(
fieldname
);
Field
tField1
=
t
.
getClass
().
getDeclaredField
(
refFieldName
);
tField
.
setAccessible
(
true
);
tField1
.
setAccessible
(
true
);
Field
tField1
=
t
.
getClass
().
getDeclaredField
(
refFieldName
);
Integer
len
=
(
Integer
)
tField1
.
get
(
t
);
tField1
.
setAccessible
(
true
);
if
(
len
>
0
)
{
Integer
len
=
(
Integer
)
tField1
.
get
(
t
);
Class
clazz1
=
DynamicsClassMap
.
get
(
classtype
,
value
);
if
(
len
>
0
)
{
Class
<?>
cls
=
Class
.
forName
(
clazz1
.
getName
());
Class
clazz1
=
DynamicsClassMap
.
get
(
classtype
,
value
);
List
<
Object
>
list
=
new
ArrayList
<>();
Class
<?>
cls
=
Class
.
forName
(
clazz1
.
getName
());
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
List
<
Object
>
list
=
new
ArrayList
<>();
Object
obj
=
cls
.
newInstance
();
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
System
.
out
.
println
(
"clazz1 name::"
+
clazz1
.
getName
());
Object
obj
=
cls
.
newInstance
();
parse
(
data
,
obj
);
System
.
out
.
println
(
"clazz1 name::"
+
clazz1
.
getName
());
list
.
add
(
obj
);
parse
(
data
,
obj
);
}
list
.
add
(
obj
);
field
.
set
(
t
,
list
);
}
}
field
.
set
(
t
,
list
);
}
}
}
}
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
()
)
{
return
t
;
if
(
data
.
readerIndex
()
==
data
.
maxCapacity
())
{
}
return
t
;
if
(
field
.
isAnnotationPresent
(
DynamicsClassDef
.
class
))
{
}
DynamicsClassDef
dynamicsClassDef
=
field
.
getAnnotation
(
DynamicsClassDef
.
class
);
if
(
field
.
isAnnotationPresent
(
DynamicsClassDef
.
class
))
{
String
classtype
=
dynamicsClassDef
.
classtype
();
DynamicsClassDef
dynamicsClassDef
=
field
.
getAnnotation
(
DynamicsClassDef
.
class
);
DependencyDef
dependencyDef
=
field
.
getAnnotation
(
DependencyDef
.
class
);
String
classtype
=
dynamicsClassDef
.
classtype
();
String
fieldname
=
dependencyDef
.
value
();
DependencyDef
dependencyDef
=
field
.
getAnnotation
(
DependencyDef
.
class
);
Field
tField2
=
t
.
getClass
().
getDeclaredField
(
fieldname
);
String
fieldname
=
dependencyDef
.
value
();
tField2
.
setAccessible
(
true
);
Field
tField2
=
t
.
getClass
().
getDeclaredField
(
fieldname
);
tField2
.
setAccessible
(
true
);
Short
key
=
(
Short
)
tField2
.
get
(
t
);
Class
clazz1
=
DynamicsClassMap
.
get
(
classtype
,
key
);
Short
key
=
(
Short
)
tField2
.
get
(
t
);
Class
<?>
cls
=
Class
.
forName
(
clazz1
.
getName
());
Class
clazz1
=
DynamicsClassMap
.
get
(
classtype
,
key
);
Object
obj
=
cls
.
newInstance
();
Class
<?>
cls
=
Class
.
forName
(
clazz1
.
getName
());
parse
(
data
,
obj
);
Object
obj
=
cls
.
newInstance
();
field
.
set
(
t
,
obj
);
parse
(
data
,
obj
);
field
.
set
(
t
,
obj
);
}
else
{
Class
<?>
cls
=
Class
.
forName
(
field
.
getType
().
getName
());
}
else
{
Object
obj
=
cls
.
newInstance
();
Class
<?>
cls
=
Class
.
forName
(
field
.
getType
().
getName
());
Object
obj
=
cls
.
newInstance
();
parse
(
data
,
obj
);
field
.
set
(
t
,
obj
);
parse
(
data
,
obj
);
}
field
.
set
(
t
,
obj
);
}
}
}
rstMap
.
put
(
num
,
field
);
rstMap
.
put
(
num
,
field
);
}
}
}
}
return
t
;
return
t
;
}
}
/**
/**
* 读取字节流
* 读取字节流
*
* @param t
* @param t
* @param field
* @param field
* @param data
* @param data
* @throws IllegalArgumentException
* @throws IllegalArgumentException
* @throws IllegalAccessException
* @throws IllegalAccessException
* @throws SecurityException
* @throws SecurityException
* @throws NoSuchFieldException
* @throws NoSuchFieldException
*/
*/
public
static
void
readBuf
(
Object
t
,
Field
field
,
ByteBuf
data
)
throws
IllegalArgumentException
,
IllegalAccessException
,
NoSuchFieldException
,
SecurityException
{
public
static
void
readBuf
(
Object
t
,
Field
field
,
ByteBuf
data
)
throws
IllegalArgumentException
,
IllegalAccessException
,
NoSuchFieldException
,
SecurityException
{
if
(
data
.
readerIndex
()==
data
.
maxCapacity
()
)
if
(
data
.
readerIndex
()
==
data
.
maxCapacity
())
return
;
return
;
FieldDef
fieldDef
=
null
;
FieldDef
fieldDef
=
null
;
if
(
field
.
isAnnotationPresent
(
FieldDef
.
class
))
{
if
(
field
.
isAnnotationPresent
(
FieldDef
.
class
))
{
fieldDef
=
field
.
getAnnotation
(
FieldDef
.
class
);
fieldDef
=
field
.
getAnnotation
(
FieldDef
.
class
);
}
}
RefNumFlag
refNumFlag
=
null
;
RefNumFlag
refNumFlag
=
null
;
if
(
field
.
isAnnotationPresent
(
RefNumFlag
.
class
))
{
if
(
field
.
isAnnotationPresent
(
RefNumFlag
.
class
))
{
refNumFlag
=
field
.
getAnnotation
(
RefNumFlag
.
class
);
refNumFlag
=
field
.
getAnnotation
(
RefNumFlag
.
class
);
}
}
Class
<?>
type
=
field
.
getType
();
Class
<?>
type
=
field
.
getType
();
if
(
type
==
String
.
class
&&
fieldDef
!=
null
&&
fieldDef
.
type
().
equals
(
"BYTE"
))
{
if
(
type
==
String
.
class
&&
fieldDef
!=
null
&&
fieldDef
.
type
().
equals
(
"BYTE"
))
{
byte
[]
by
=
new
byte
[
fieldDef
.
length
()];
byte
[]
by
=
new
byte
[
fieldDef
.
length
()];
data
.
readBytes
(
by
);
data
.
readBytes
(
by
);
String
str
=
new
String
(
by
,
StandardCharsets
.
UTF_8
);
String
str
=
new
String
(
by
,
StandardCharsets
.
UTF_8
);
field
.
set
(
t
,
str
);
field
.
set
(
t
,
str
);
}
else
if
(
type
==
short
.
class
)
{
}
else
if
(
type
==
short
.
class
)
{
field
.
set
(
t
,
data
.
readUnsignedByte
());
field
.
set
(
t
,
data
.
readUnsignedByte
());
}
else
if
(
type
==
int
.
class
)
{
}
else
if
(
type
==
int
.
class
)
{
field
.
set
(
t
,
data
.
readUnsignedShort
());
field
.
set
(
t
,
data
.
readUnsignedShort
());
}
else
if
(
type
==
long
.
class
&&
fieldDef
==
null
)
{
}
else
if
(
type
==
long
.
class
&&
fieldDef
==
null
)
{
field
.
set
(
t
,
data
.
readUnsignedInt
());
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
());
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
());
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
());
Field
tField
=
t
.
getClass
().
getDeclaredField
(
refNumFlag
.
value
());
tField
.
setAccessible
(
true
);
tField
.
setAccessible
(
true
);
Class
<?>
type1
=
tField
.
getType
();
Class
<?>
type1
=
tField
.
getType
();
byte
[]
by
=
null
;
byte
[]
by
=
null
;
if
(
type1
==
byte
.
class
)
{
if
(
type1
==
byte
.
class
)
{
Byte
obj
=(
Byte
)
tField
.
get
(
t
);
Byte
obj
=
(
Byte
)
tField
.
get
(
t
);
by
=
new
byte
[
obj
.
byteValue
()];
by
=
new
byte
[
obj
.
byteValue
()];
}
else
if
(
type1
==
short
.
class
)
{
}
else
if
(
type1
==
short
.
class
)
{
Short
obj
=(
Short
)
tField
.
get
(
t
);
Short
obj
=
(
Short
)
tField
.
get
(
t
);
by
=
new
byte
[
obj
.
shortValue
()];
by
=
new
byte
[
obj
.
shortValue
()];
}
else
if
(
type1
==
int
.
class
)
{
}
else
if
(
type1
==
int
.
class
)
{
Integer
obj
=(
Integer
)
tField
.
get
(
t
);
Integer
obj
=
(
Integer
)
tField
.
get
(
t
);
by
=
new
byte
[
obj
.
intValue
()];
by
=
new
byte
[
obj
.
intValue
()];
}
}
data
.
readBytes
(
by
);
data
.
readBytes
(
by
);
field
.
set
(
t
,
by
);
field
.
set
(
t
,
by
);
}
}
}
}
public
static
byte
[]
longToBytes
(
long
value
)
{
ByteBuffer
buffer
=
ByteBuffer
.
allocate
(
8
);
public
static
byte
[]
longToBytes
(
long
value
)
{
buffer
.
order
(
ByteOrder
.
BIG_ENDIAN
);
// 指定小端模式
ByteBuffer
buffer
=
ByteBuffer
.
allocate
(
8
);
buffer
.
putLong
(
value
);
// 将long值存入buffer
buffer
.
order
(
ByteOrder
.
BIG_ENDIAN
);
// 指定小端模式
return
buffer
.
array
();
// 获取byte数组
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
);
// 指定小端模式
public
static
byte
[]
longToBytes1
(
long
value
)
{
buffer
.
putLong
(
value
);
// 将long值存入buffer
ByteBuffer
buffer
=
ByteBuffer
.
allocate
(
4
);
return
buffer
.
array
();
// 获取byte数组
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
);
// 指定小端模式
public
static
byte
[]
intToBytes
(
int
value
)
{
buffer
.
putLong
(
value
);
// 将long值存入buffer
ByteBuffer
buffer
=
ByteBuffer
.
allocate
(
4
);
return
buffer
.
array
();
// 获取byte数组
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
)
{
public
static
String
byteToHexString
(
byte
[]
bytes
)
{
sb
.
append
(
String
.
format
(
"%02x"
,
b
));
StringBuilder
sb
=
new
StringBuilder
();
}
for
(
byte
b
:
bytes
)
{
return
sb
.
toString
();
sb
.
append
(
String
.
format
(
"%02x"
,
b
));
}
//return null;
return
sb
.
toString
();
//return null;
// ByteBuffer buffer = ByteBuffer.allocate(8);
// ByteBuffer buffer = ByteBuffer.allocate(8);
// buffer.order(ByteOrder.LITTLE_ENDIAN); // 指定小端模式
// buffer.order(ByteOrder.LITTLE_ENDIAN); // 指定小端模式
// buffer.putLong(value); // 将long值存入buffer
// buffer.putLong(value); // 将long值存入buffer
// return buffer.array(); // 获取byte数组
// return buffer.array(); // 获取byte数组
}
}
public
static
String
long2Hex
(
long
num
,
int
len
)
{
String
hex
=
Long
.
toHexString
(
num
);
public
static
String
long2Hex
(
long
num
,
int
len
)
{
int
padLength
=
len
*
2
;
String
hex
=
Long
.
toHexString
(
num
);
if
(
hex
.
length
()
>=
padLength
)
{
int
padLength
=
len
*
2
;
return
hex
.
substring
(
hex
.
length
()
-
padLength
);
// 超长时截断
if
(
hex
.
length
()
>=
padLength
)
{
}
return
hex
.
substring
(
hex
.
length
()
-
padLength
);
// 超长时截断
return
String
.
format
(
"%0"
+
padLength
+
"d"
,
0
).
replace
(
"0"
,
"0"
)
+
hex
;
// 或直接格式化
}
}
return
String
.
format
(
"%0"
+
padLength
+
"d"
,
0
).
replace
(
"0"
,
"0"
)
+
hex
;
// 或直接格式化
}
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"
;
byte
[]
bytes
=
HexStringToByteArray
.
hexStringToByteArray
(
hexString
);
String
hexString
=
"F20000000015018cb864640000000000"
;
ByteBuf
byteBuf
=
Unpooled
.
buffer
(
16
);
byte
[]
bytes
=
HexStringToByteArray
.
hexStringToByteArray
(
hexString
);
long
l
=
500000
;
ByteBuf
byteBuf
=
Unpooled
.
buffer
(
16
);
//3600000000
long
l
=
500000
;
// 1164916946
//3600000000
// byte [] bs = Long.toHexString(l);
// 1164916946
String
s
=
long2Hex
(
l
,
4
);
// byte [] bs = Long.toHexString(l);
//longToBytes1(l);
String
s
=
long2Hex
(
l
,
4
);
long
i
=
250000
;
//longToBytes1(l);
String
hex
=
Long
.
toHexString
(
i
);
long
i
=
250000
;
String
hex
=
Long
.
toHexString
(
i
);
int
i1
=
1500
;
hex
=
Integer
.
toHexString
(
i1
);
int
i1
=
1500
;
hex
=
Integer
.
toHexString
(
i1
);
String
uuid
=
UUID
.
randomUUID
().
toString
();
byte
[]
by2
=
uuid
.
getBytes
();
String
uuid
=
UUID
.
randomUUID
().
toString
();
s
=
byteToHexString
(
by2
);
byte
[]
by2
=
uuid
.
getBytes
();
s
=
byteToHexString
(
by2
);
String
vid
=
"JL110001"
;
byte
[]
by1
=
vid
.
getBytes
();
String
vid
=
"JL110001"
;
s
=
byteToHexString
(
by1
);
byte
[]
by1
=
vid
.
getBytes
();
s
=
byteToHexString
(
by1
);
System
.
out
.
println
(
s
);
System
.
out
.
println
(
s
);
//
//
//
//
// List<Byte> byteList = new ArrayList<Byte>();
// List<Byte> byteList = new ArrayList<Byte>();
//
//
// Byte[] bytes = byteList.toArray(new Byte[byteList.size()]);
// Byte[] bytes = byteList.toArray(new Byte[byteList.size()]);
//byte[] bs = convoter(bytes);
//byte[] bs = convoter(bytes);
//byteBuf.writeBytes(bytes);
//byteBuf.writeBytes(bytes);
//VehicleMessage vehicleMessage = parse(byteBuf,new VehicleMessage());
//VehicleMessage vehicleMessage = parse(byteBuf,new VehicleMessage());
//System.out.print(vehicleMessage);
//System.out.print(vehicleMessage);
}
}
public
static
void
convoterBean
(
Object
source
,
Object
target
)
throws
IllegalArgumentException
,
IllegalAccessException
,
ClassNotFoundException
,
InstantiationException
,
NoSuchFieldException
,
SecurityException
{
// 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
)
{
//List<Field> fList = new ArrayList<>();
Field
tField
=
null
;
//SortedMap<Integer,Field> rstMap = new TreeMap<>();
try
{
for
(
Field
field
:
fields
)
{
Field
[]
fields
=
source
.
getClass
().
getDeclaredFields
();
field
.
setAccessible
(
true
);
//获取目标对象指定的属性
Object
o
=
field
.
get
(
source
);
//List<Field> fList = new ArrayList<>();
if
(
o
==
null
)
{
//SortedMap<Integer,Field> rstMap = new TreeMap<>();
continue
;
for
(
Field
field
:
fields
)
{
}
field
.
setAccessible
(
true
);
Object
o
=
field
.
get
(
source
);
OffsetDef
offsetDef
=
null
;
if
(
o
==
null
)
{
if
(
field
.
isAnnotationPresent
(
OffsetDef
.
class
))
{
continue
;
offsetDef
=
field
.
getAnnotation
(
OffsetDef
.
class
);
}
}
//获取目标对象指定的属性
OffsetDef
offsetDef
=
null
;
Field
tField
=
target
.
getClass
().
getDeclaredField
(
field
.
getName
());
if
(
field
.
isAnnotationPresent
(
OffsetDef
.
class
))
{
tField
.
setAccessible
(
true
);
offsetDef
=
field
.
getAnnotation
(
OffsetDef
.
class
);
if
(
field
.
isAnnotationPresent
(
Order
.
class
))
{
}
if
(
field
.
getType
().
isPrimitive
()
&&
!
field
.
getType
().
isArray
()
)
{
//获取目标对象指定的属性
//如果属性添加了自定义注解 offset
tField
=
target
.
getClass
().
getDeclaredField
(
field
.
getName
());
tField
.
setAccessible
(
true
);
Class
<?>
type
=
field
.
getType
();
if
(
field
.
isAnnotationPresent
(
Order
.
class
))
{
if
(
offsetDef
!=
null
)
{
if
(
field
.
getType
().
isPrimitive
()
&&
!
field
.
getType
().
isArray
())
{
double
offset
=
offsetDef
.
value
();
//如果属性添加了自定义注解 offset
int
type1
=
offsetDef
.
type
();
int
minValidLength
=
offsetDef
.
minValidLength
();
Class
<?>
type
=
field
.
getType
();
if
(
offsetDef
!=
null
)
{
//startindex
double
offset
=
offsetDef
.
value
();
int
type1
=
offsetDef
.
type
();
if
(
type
==
byte
.
class
)
{
int
minValidLength
=
offsetDef
.
minValidLength
();
tField
.
set
(
target
,
o
);
}
else
if
(
type
==
short
.
class
)
{
//startindex
if
(
minValidLength
>
0
)
{
if
(
type
==
byte
.
class
)
{
int
len
=
String
.
valueOf
((
Short
)
o
).
length
();
tField
.
set
(
target
,
o
);
if
(
len
<
minValidLength
)
{
}
else
if
(
type
==
short
.
class
)
{
int
subtract
=
minValidLength
-
len
;
double
f
=(
Short
)
o
*
Math
.
pow
(
10
,
subtract
)*
offset
;
if
(
minValidLength
>
0
)
{
tField
.
set
(
target
,
(
float
)
f
);
int
len
=
String
.
valueOf
((
Short
)
o
).
length
();
}
else
{
if
(
len
<
minValidLength
)
{
double
f
=(
Short
)
o
*
offset
;
int
subtract
=
minValidLength
-
len
;
tField
.
set
(
target
,
(
float
)
f
);
double
f
=
(
Short
)
o
*
Math
.
pow
(
10
,
subtract
)
*
offset
;
}
tField
.
set
(
target
,
(
float
)
f
);
}
else
{
}
else
{
double
f
=(
Short
)
o
*
offset
;
double
f
=
(
Short
)
o
*
offset
;
tField
.
set
(
target
,
(
float
)
f
);
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
)
{
}
else
if
(
type
==
int
.
class
)
{
int
subtract
=
minValidLength
-
len
;
if
(
minValidLength
>
0
)
{
double
f
=(
Integer
)
o
*
Math
.
pow
(
10
,
subtract
)*
offset
;
int
len
=
String
.
valueOf
((
Integer
)
o
).
length
();
tField
.
set
(
target
,
(
float
)
f
);
if
(
len
<
minValidLength
)
{
}
else
{
int
subtract
=
minValidLength
-
len
;
double
f
=(
Integer
)
o
*
offset
;
double
f
=
(
Integer
)
o
*
Math
.
pow
(
10
,
subtract
)
*
offset
;
tField
.
set
(
target
,
(
float
)
f
);
tField
.
set
(
target
,
(
float
)
f
);
}
}
else
{
}
else
{
double
f
=
(
Integer
)
o
*
offset
;
double
f
=(
Integer
)
o
*
offset
;
tField
.
set
(
target
,
(
float
)
f
);
tField
.
set
(
target
,
(
float
)
f
);
}
}
}
else
{
}
else
if
(
type
==
long
.
class
)
{
double
f
=
(
Integer
)
o
*
offset
;
if
(
minValidLength
>
0
)
{
tField
.
set
(
target
,
(
float
)
f
);
int
len
=
String
.
valueOf
((
Long
)
o
).
length
();
}
if
(
len
<
minValidLength
)
{
}
else
if
(
type
==
long
.
class
)
{
int
subtract
=
minValidLength
-
len
;
if
(
minValidLength
>
0
)
{
double
f
=(
Long
)
o
*
Math
.
pow
(
10
,
subtract
)*
offset
;
int
len
=
String
.
valueOf
((
Long
)
o
).
length
();
tField
.
set
(
target
,
(
double
)
f
);
if
(
len
<
minValidLength
)
{
}
else
{
int
subtract
=
minValidLength
-
len
;
double
f
=(
Long
)
o
*
offset
;
double
f
=
(
Long
)
o
*
Math
.
pow
(
10
,
subtract
)
*
offset
;
tField
.
set
(
target
,
(
double
)
f
);
tField
.
set
(
target
,
(
double
)
f
);
}
}
else
{
}
else
{
double
f
=
(
Long
)
o
*
offset
;
double
d
=(
Long
)
o
*
offset
;
tField
.
set
(
target
,
(
double
)
f
);
}
tField
.
set
(
target
,
d
);
}
else
{
}
double
d
=
(
Long
)
o
*
offset
;
}
tField
.
set
(
target
,
d
);
}
}
else
{
}
tField
.
set
(
target
,
o
);
}
}
else
{
}
else
if
(
field
.
getClass
().
isPrimitive
()
&&
field
.
getType
().
isArray
()){
tField
.
set
(
target
,
o
);
// 基础数据类型 且 是数组
}
}
else
if
(
List
.
class
.
isAssignableFrom
(
field
.
getType
()))
{
// 集合类型
}
else
if
(
field
.
getClass
().
isPrimitive
()
&&
field
.
getType
().
isArray
())
{
//读取属性的注解是否引用其他字段的长度
// 基础数据类型 且 是数组
if
(
field
.
isAnnotationPresent
(
RefNumFlag
.
class
))
{
}
else
if
(
List
.
class
.
isAssignableFrom
(
field
.
getType
()))
{
// 集合类型
//读取属性的注解是否引用其他字段的长度
if
(
field
.
isAnnotationPresent
(
RefNumFlag
.
class
))
{
// RefNumFlag refNumFlag = field.getAnnotation(RefNumFlag.class);
// RefNumFlag refNumFlag = field.getAnnotation(RefNumFlag.class);
// String refField = refNumFlag.value();
// String refField = refNumFlag.value();
// Class<?> clazz1 = t.getClass();
// Class<?> clazz1 = t.getClass();
// Field nameField = clazz1.getDeclaredField(refField);
// Field nameField = clazz1.getDeclaredField(refField);
// Type genericType = nameField.getGenericType();
// Type genericType = nameField.getGenericType();
// nameField.setAccessible(true);
// nameField.setAccessible(true);
//
//
// if (genericType instanceof ParameterizedType) {
// if (genericType instanceof ParameterizedType) {
// ParameterizedType pt = (ParameterizedType) genericType;
// ParameterizedType pt = (ParameterizedType) genericType;
// Type[] actualTypes = pt.getActualTypeArguments();
// Type[] actualTypes = pt.getActualTypeArguments();
...
@@ -449,44 +455,49 @@ public class Parse {
...
@@ -449,44 +455,49 @@ public class Parse {
// }
// }
// }
// }
// }
// }
}
}
}
else
if
(
field
.
getType
()==
String
.
class
)
{
}
else
if
(
field
.
getType
()
==
String
.
class
)
{
//类型为字符串
//类型为字符串
// try {
// try {
// String s = (String)o;
// String s = (String)o;
// String s1 = new String(s.getBytes());
// String s1 = new String(s.getBytes());
tField
.
set
(
target
,
o
);
tField
.
set
(
target
,
o
);
// }catch(Exception e) {
// }catch(Exception e) {
// e.printStackTrace();
// e.printStackTrace();
// }
// }
}
else
{
}
else
{
//其他对象类型
//其他对象类型
Class
<?>
cls
=
Class
.
forName
(
tField
.
getType
().
getName
());
Class
<?>
cls
=
Class
.
forName
(
tField
.
getType
().
getName
());
Object
obj
=
cls
.
newInstance
();
Object
obj
=
cls
.
newInstance
();
convoterBean
(
o
,
obj
);
convoterBean
(
o
,
obj
);
tField
.
set
(
target
,
obj
);
tField
.
set
(
target
,
obj
);
}
}
}
}
}
}
}
}
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
)
{
public
static
byte
[]
convoter
(
Byte
[]
bytes
)
{
bs
[
i
++]
=
b
;
byte
[]
bs
=
new
byte
[
bytes
.
length
];
}
int
i
=
0
;
return
bs
;
for
(
Byte
b
:
bytes
)
{
}
bs
[
i
++]
=
b
;
/**
}
* 16进制转2进制
return
bs
;
* @param hex
}
* @return
*/
/**
public
static
String
convertHexToBinary
(
String
hex
)
{
* 16进制转2进制
*
* @param hex
* @return
*/
public
static
String
convertHexToBinary
(
String
hex
)
{
// 将16进制数转换为10进制Integer
// 将16进制数转换为10进制Integer
int
decimal
=
Integer
.
parseInt
(
hex
,
16
);
int
decimal
=
Integer
.
parseInt
(
hex
,
16
);
// 将10进制数转换为2进制字符串
// 将10进制数转换为2进制字符串
...
...
src/main/java/com/cusc/adas/v2x/vo/VehicleStatusInfo.java
View file @
ccc19945
...
@@ -11,7 +11,7 @@ import com.cusc.adas.v2x.utils.RefNumFlag;
...
@@ -11,7 +11,7 @@ import com.cusc.adas.v2x.utils.RefNumFlag;
/**
/**
* 车辆辅助驾驶信息及状态信息
* 车辆辅助驾驶信息及状态信息
* @author huangml
* @author huangml
*
*
车辆运行状态数据 2-车辆辅助驾驶系统信息及其他状态信息数据结构(续)
*/
*/
public
class
VehicleStatusInfo
{
public
class
VehicleStatusInfo
{
@Order
(
1
)
@Order
(
1
)
...
@@ -48,8 +48,9 @@ public class VehicleStatusInfo {
...
@@ -48,8 +48,9 @@ public class VehicleStatusInfo {
//DMS 状态
//DMS 状态
@Order
(
10
)
@Order
(
10
)
private
short
dmsFlag
;
private
short
dmsFlag
;
//里程
//里程
单位:0.1km,
@Order
(
11
)
@Order
(
11
)
@OffsetDef
(
value
=
0.1
)
private
long
mileage
;
private
long
mileage
;
//sweeping状态
//sweeping状态
@Order
(
12
)
@Order
(
12
)
...
@@ -57,14 +58,13 @@ public class VehicleStatusInfo {
...
@@ -57,14 +58,13 @@ public class VehicleStatusInfo {
//watering状态
//watering状态
@Order
(
13
)
@Order
(
13
)
private
short
wateringFlag
;
private
short
wateringFlag
;
// 车辆运行状态数据 2-车辆辅助驾驶系统信息及其他状态信息数据结构(续)
//油量 对应车辆油量表读数,单位:0.1 L,
//油量 对应车辆油量表读数,单位:0.1 L,
@Order
(
14
)
@Order
(
14
)
@OffsetDef
(
value
=
0.1
)
@OffsetDef
(
value
=
0.1
)
private
int
fuelGauge
;
private
int
fuelGauge
;
//电池剩余电量 0.01%,
//电池剩余电量 0.01%,
@Order
(
15
)
@Order
(
15
)
@OffsetDef
(
value
=
1
f
)
@OffsetDef
(
value
=
0.0
1
)
private
int
soc
;
private
int
soc
;
//电池温度 [0..200],单位:摄氏度(℃),
//电池温度 [0..200],单位:摄氏度(℃),
//数据偏移量 100,表示-100℃~100℃ ,0xFF 表示缺省
//数据偏移量 100,表示-100℃~100℃ ,0xFF 表示缺省
...
...
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