Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
谢明辉
/
recv_data_longhua
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 27b79990
authored
Sep 16, 2020
by
xmh
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
大端模式改为小端模式
1 parent
360652c3
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
129 additions
and
122 deletions
src/main/java/com/viontech/model/BaseModel.java
src/main/java/com/viontech/model/BehaviorModel.java
src/main/java/com/viontech/model/FlowModel.java
src/main/java/com/viontech/model/TrafficModel.java
src/main/java/com/viontech/netty/NettyReceiverHandler.java
src/main/java/com/viontech/netty/NettyServer.java
src/main/java/com/viontech/model/BaseModel.java
View file @
27b7999
...
...
@@ -32,10 +32,10 @@ public class BaseModel {
public
static
BaseModel
from
(
ByteBuf
byteBuf
)
{
long
deviceId
=
byteBuf
.
readUnsignedInt
();
long
length
=
byteBuf
.
readUnsignedInt
();
long
firstInt
=
byteBuf
.
readUnsignedInt
();
long
secondInt
=
byteBuf
.
readUnsignedInt
();
long
deviceId
=
byteBuf
.
readUnsignedInt
LE
();
long
length
=
byteBuf
.
readUnsignedInt
LE
();
long
firstInt
=
byteBuf
.
readUnsignedInt
LE
();
long
secondInt
=
byteBuf
.
readUnsignedInt
LE
();
BaseModel
model
;
switch
((
int
)
firstInt
)
{
...
...
@@ -65,15 +65,6 @@ public class BaseModel {
return
(
int
)
data
;
}
public
static
byte
[]
toBytes
(
int
n
)
{
byte
[]
b
=
new
byte
[
4
];
b
[
3
]
=
(
byte
)
(
n
&
0xff
);
b
[
2
]
=
(
byte
)
(
n
>>
8
&
0xff
);
b
[
1
]
=
(
byte
)
(
n
>>
16
&
0xff
);
b
[
0
]
=
(
byte
)
(
n
>>
24
&
0xff
);
return
b
;
}
/**
* 将 model 转换为 byteBuf
*
...
...
@@ -82,10 +73,10 @@ public class BaseModel {
public
void
to
(
ByteBuf
byteBuf
)
{
encodeData
();
byteBuf
.
writeInt
(
toInt
(
deviceId
));
byteBuf
.
writeInt
(
toInt
(
length
));
byteBuf
.
writeInt
(
toInt
(
protocol
));
byteBuf
.
writeInt
(
toInt
(
flag
));
byteBuf
.
writeInt
LE
(
toInt
(
deviceId
));
byteBuf
.
writeInt
LE
(
toInt
(
length
));
byteBuf
.
writeInt
LE
(
toInt
(
protocol
));
byteBuf
.
writeInt
LE
(
toInt
(
flag
));
if
(
data
!=
null
&&
data
.
length
>
0
)
{
byteBuf
.
writeBytes
(
data
);
}
...
...
src/main/java/com/viontech/model/BehaviorModel.java
View file @
27b7999
...
...
@@ -2,6 +2,10 @@ package com.viontech.model;
import
com.fasterxml.jackson.core.util.ByteArrayBuilder
;
import
com.viontech.Application
;
import
com.viontech.utils.Utils
;
import
io.netty.buffer.ByteBuf
;
import
io.netty.buffer.ByteBufAllocator
;
import
io.netty.buffer.ByteBufUtil
;
import
lombok.Getter
;
import
lombok.Setter
;
...
...
@@ -59,43 +63,45 @@ public class BehaviorModel extends BaseModel {
this
.
length
=
16L
+
448L
+
picture
.
length
;
this
.
protocol
=
0x00040006
L
;
this
.
flag
=
Application
.
REAL_TIME
;
ByteBuf
buffer
=
ByteBufAllocator
.
DEFAULT
.
buffer
();
buffer
.
writeIntLE
(
serialNum
);
buffer
.
writeIntLE
(
recordingStartSecond
);
buffer
.
writeIntLE
(
recordingStartMillisecond
);
buffer
.
writeIntLE
(
recordingEndSecond
);
buffer
.
writeIntLE
(
recordingEndMillisecond
);
buffer
.
writeIntLE
(
eventStartSecond
);
buffer
.
writeIntLE
(
eventStartMillisecond
);
buffer
.
writeIntLE
(
eventEndSecond
);
buffer
.
writeIntLE
(
eventEndMillisecond
);
buffer
.
writeIntLE
(
laneNo
);
buffer
.
writeIntLE
(
pictureSize
);
buffer
.
writeIntLE
(
pictureWidth
);
buffer
.
writeIntLE
(
pictureHeight
);
buffer
.
writeIntLE
(
x
);
buffer
.
writeIntLE
(
y
);
buffer
.
writeBytes
(
licensePlateText
);
buffer
.
writeBytes
(
recordingPath
);
buffer
.
writeIntLE
(
vehicleType
);
buffer
.
writeIntLE
(
color1
);
buffer
.
writeIntLE
(
speed
);
buffer
.
writeIntLE
(
direction
);
buffer
.
writeBytes
(
eventLocation
);
buffer
.
writeBytes
(
eventSnapshotPath
);
buffer
.
writeIntLE
(
color2
);
buffer
.
writeIntLE
(
color3
);
buffer
.
writeIntLE
(
color1Weights
);
buffer
.
writeIntLE
(
color2Weights
);
buffer
.
writeIntLE
(
color3Weights
);
buffer
.
writeIntLE
(
vehicleCategory
);
buffer
.
writeIntLE
(
reservedField
);
buffer
.
writeIntLE
(
recordingDuration
);
buffer
.
writeIntLE
(
faceWidth
);
buffer
.
writeIntLE
(
faceHeight
);
buffer
.
writeBytes
(
reservedField2
);
buffer
.
writeBytes
(
picture
);
ByteArrayBuilder
builder
=
new
ByteArrayBuilder
(
Math
.
toIntExact
(
this
.
length
-
16
));
builder
.
appendFourBytes
(
serialNum
);
builder
.
appendFourBytes
(
recordingStartSecond
);
builder
.
appendFourBytes
(
recordingStartMillisecond
);
builder
.
appendFourBytes
(
recordingEndSecond
);
builder
.
appendFourBytes
(
recordingEndMillisecond
);
builder
.
appendFourBytes
(
eventStartSecond
);
builder
.
appendFourBytes
(
eventStartMillisecond
);
builder
.
appendFourBytes
(
eventEndSecond
);
builder
.
appendFourBytes
(
eventEndMillisecond
);
builder
.
appendFourBytes
(
laneNo
);
builder
.
appendFourBytes
(
pictureSize
);
builder
.
appendFourBytes
(
pictureWidth
);
builder
.
appendFourBytes
(
pictureHeight
);
builder
.
appendFourBytes
(
x
);
builder
.
appendFourBytes
(
y
);
builder
.
write
(
licensePlateText
);
builder
.
write
(
recordingPath
);
builder
.
appendFourBytes
(
vehicleType
);
builder
.
appendFourBytes
(
color1
);
builder
.
appendFourBytes
(
speed
);
builder
.
appendFourBytes
(
direction
);
builder
.
write
(
eventLocation
);
builder
.
write
(
eventSnapshotPath
);
builder
.
appendFourBytes
(
color2
);
builder
.
appendFourBytes
(
color3
);
builder
.
appendFourBytes
(
color1Weights
);
builder
.
appendFourBytes
(
color2Weights
);
builder
.
appendFourBytes
(
color3Weights
);
builder
.
appendFourBytes
(
vehicleCategory
);
builder
.
appendFourBytes
(
reservedField
);
builder
.
appendFourBytes
(
recordingDuration
);
builder
.
appendFourBytes
(
faceWidth
);
builder
.
appendFourBytes
(
faceHeight
);
builder
.
write
(
reservedField2
);
builder
.
write
(
picture
);
this
.
data
=
builder
.
resetAndGetFirstSegment
();
this
.
data
=
new
byte
[
buffer
.
readableBytes
()];
buffer
.
readBytes
(
this
.
data
);
buffer
.
release
();
}
}
src/main/java/com/viontech/model/FlowModel.java
View file @
27b7999
package
com
.
viontech
.
model
;
import
com.fasterxml.jackson.core.util.ByteArrayBuilder
;
import
com.viontech.Application
;
import
io.netty.buffer.ByteBuf
;
import
io.netty.buffer.ByteBufAllocator
;
import
lombok.Getter
;
import
lombok.Setter
;
...
...
@@ -35,31 +36,32 @@ public class FlowModel extends BaseModel {
this
.
protocol
=
0x00040005
L
;
this
.
flag
=
Application
.
REAL_TIME
;
ByteArrayBuilder
builder
=
new
ByteArrayBuilder
(
Math
.
toIntExact
(
this
.
length
-
16
));
builder
.
appendFourBytes
(
serialNum
);
builder
.
appendFourBytes
(
time
);
builder
.
appendFourBytes
(
timeDuring
);
for
(
int
value
:
laneNoAndType
)
{
builder
.
appendFourBytes
(
value
);
ByteBuf
buffer
=
ByteBufAllocator
.
DEFAULT
.
buffer
();
buffer
.
writeIntLE
(
serialNum
);
buffer
.
writeIntLE
(
time
);
buffer
.
writeIntLE
(
timeDuring
);
for
(
int
i
:
laneNoAndType
)
{
buffer
.
writeIntLE
(
i
);
}
for
(
int
value
:
traffic
)
{
bu
ilder
.
appendFourBytes
(
value
);
for
(
int
i
:
traffic
)
{
bu
ffer
.
writeIntLE
(
i
);
}
for
(
int
value
:
avgSpeed
)
{
bu
ilder
.
appendFourBytes
(
value
);
for
(
int
i
:
avgSpeed
)
{
bu
ffer
.
writeIntLE
(
i
);
}
for
(
int
value
:
maxQueueLen
)
{
bu
ilder
.
appendFourBytes
(
value
);
for
(
int
i
:
maxQueueLen
)
{
bu
ffer
.
writeIntLE
(
i
);
}
for
(
int
value
:
avgDistanceBetweenVehicle
)
{
bu
ilder
.
appendFourBytes
(
value
);
for
(
int
i
:
avgDistanceBetweenVehicle
)
{
bu
ffer
.
writeIntLE
(
i
);
}
for
(
int
value
:
trafficSupplement
)
{
bu
ilder
.
appendFourBytes
(
value
);
for
(
int
i
:
trafficSupplement
)
{
bu
ffer
.
writeIntLE
(
i
);
}
builder
.
write
(
reservedField
);
this
.
data
=
builder
.
resetAndGetFirstSegment
();
buffer
.
writeBytes
(
reservedField
);
this
.
data
=
new
byte
[
buffer
.
readableBytes
()];
buffer
.
readBytes
(
this
.
data
);
buffer
.
release
();
}
}
src/main/java/com/viontech/model/TrafficModel.java
View file @
27b7999
package
com
.
viontech
.
model
;
import
com.fasterxml.jackson.core.util.ByteArrayBuilder
;
import
com.sun.xml.internal.stream.util.BufferAllocator
;
import
com.viontech.Application
;
import
io.netty.buffer.ByteBuf
;
import
io.netty.buffer.ByteBufAllocator
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.experimental.Accessors
;
...
...
@@ -99,53 +102,54 @@ public class TrafficModel extends BaseModel {
this
.
protocol
=
0x00020004
L
;
this
.
length
=
16L
+
452L
+
picture1
.
length
+
picture2
.
length
+
4
;
this
.
flag
=
Application
.
REAL_TIME
;
ByteBuf
buffer
=
ByteBufAllocator
.
DEFAULT
.
buffer
();
buffer
.
writeIntLE
(
serialNum
);
buffer
.
writeIntLE
(
discernTime
);
buffer
.
writeIntLE
(
discernMillisecondTime
);
buffer
.
writeBytes
(
plateText
);
buffer
.
writeIntLE
(
plateType
);
buffer
.
writeIntLE
(
confidence
);
buffer
.
writeIntLE
(
lane
);
buffer
.
writeIntLE
(
vehicleType
);
buffer
.
writeIntLE
(
secondPictureSize
);
buffer
.
writeIntLE
(
secondPictureWidth
);
buffer
.
writeIntLE
(
secondPictureHeight
);
buffer
.
writeIntLE
(
firstPictureSize
);
buffer
.
writeIntLE
(
firstPictureWidth
);
buffer
.
writeIntLE
(
firstPictureHeight
);
buffer
.
writeIntLE
(
patternLeft
);
buffer
.
writeIntLE
(
patternTop
);
buffer
.
writeIntLE
(
patternRight
);
buffer
.
writeIntLE
(
patternBottom
);
buffer
.
writeIntLE
(
color
);
buffer
.
writeIntLE
(
speed
);
buffer
.
writeIntLE
(
direction
);
buffer
.
writeIntLE
(
manufacturerLogo
);
buffer
.
writeBytes
(
routeLocation
);
buffer
.
writeBytes
(
videoPath
);
buffer
.
writeBytes
(
picturePath
);
buffer
.
writeIntLE
(
reservedField
);
buffer
.
writeIntLE
(
reservedField2
);
buffer
.
writeIntLE
(
reservedField3
);
buffer
.
writeIntLE
(
vehicleCategory
);
buffer
.
writeIntLE
(
plateStructure
);
buffer
.
writeIntLE
(
illegalType
);
buffer
.
writeIntLE
(
reservedField4
);
buffer
.
writeIntLE
(
secondPictureTime
);
buffer
.
writeIntLE
(
secondPictureMillisecondTime
);
buffer
.
writeIntLE
(
redLightBeginTime
);
buffer
.
writeIntLE
(
redLightBeginMillisecondTime
);
buffer
.
writeIntLE
(
redLightEndTime
);
buffer
.
writeIntLE
(
redLightEndMillisecondTime
);
buffer
.
writeIntLE
(
speedLimit
);
buffer
.
writeIntLE
(
overSpeedThreshold
);
buffer
.
writeBytes
(
reservedField5
);
buffer
.
writeBytes
(
picture1
);
buffer
.
writeBytes
(
picture2
);
byte
[]
bytes
=
new
byte
[
buffer
.
readableBytes
()];
buffer
.
readBytes
(
bytes
);
buffer
.
release
();
ByteArrayBuilder
builder
=
new
ByteArrayBuilder
(
Math
.
toIntExact
(
this
.
length
-
16
-
4
));
builder
.
appendFourBytes
(
serialNum
);
builder
.
appendFourBytes
(
discernTime
);
builder
.
appendFourBytes
(
discernMillisecondTime
);
builder
.
write
(
plateText
);
builder
.
appendFourBytes
(
plateType
);
builder
.
appendFourBytes
(
confidence
);
builder
.
appendFourBytes
(
lane
);
builder
.
appendFourBytes
(
vehicleType
);
builder
.
appendFourBytes
(
secondPictureSize
);
builder
.
appendFourBytes
(
secondPictureWidth
);
builder
.
appendFourBytes
(
secondPictureHeight
);
builder
.
appendFourBytes
(
firstPictureSize
);
builder
.
appendFourBytes
(
firstPictureWidth
);
builder
.
appendFourBytes
(
firstPictureHeight
);
builder
.
appendFourBytes
(
patternLeft
);
builder
.
appendFourBytes
(
patternTop
);
builder
.
appendFourBytes
(
patternRight
);
builder
.
appendFourBytes
(
patternBottom
);
builder
.
appendFourBytes
(
color
);
builder
.
appendFourBytes
(
speed
);
builder
.
appendFourBytes
(
direction
);
builder
.
appendFourBytes
(
manufacturerLogo
);
builder
.
write
(
routeLocation
);
builder
.
write
(
videoPath
);
builder
.
write
(
picturePath
);
builder
.
appendFourBytes
(
reservedField
);
builder
.
appendFourBytes
(
reservedField2
);
builder
.
appendFourBytes
(
reservedField3
);
builder
.
appendFourBytes
(
vehicleCategory
);
builder
.
appendFourBytes
(
plateStructure
);
builder
.
appendFourBytes
(
illegalType
);
builder
.
appendFourBytes
(
reservedField4
);
builder
.
appendFourBytes
(
secondPictureTime
);
builder
.
appendFourBytes
(
secondPictureMillisecondTime
);
builder
.
appendFourBytes
(
redLightBeginTime
);
builder
.
appendFourBytes
(
redLightBeginMillisecondTime
);
builder
.
appendFourBytes
(
redLightEndTime
);
builder
.
appendFourBytes
(
redLightEndMillisecondTime
);
builder
.
appendFourBytes
(
speedLimit
);
builder
.
appendFourBytes
(
overSpeedThreshold
);
builder
.
write
(
reservedField5
);
builder
.
write
(
picture1
);
builder
.
write
(
picture2
);
byte
[]
bytes
=
builder
.
resetAndGetFirstSegment
();
int
count
=
bytes
.
length
;
// crc32
CRC32
crc32
=
new
CRC32
();
...
...
src/main/java/com/viontech/netty/NettyReceiverHandler.java
View file @
27b7999
...
...
@@ -37,10 +37,11 @@ public class NettyReceiverHandler extends ChannelInboundHandlerAdapter {
if
(
PropertiesConfiguration
.
username
.
equals
(
logindata
.
getUsername
())
&&
PropertiesConfiguration
.
password
.
equals
(
logindata
.
getPassword
()))
{
log
.
info
(
"注册成功"
);
ChannelGroup
.
registered
(
deviceId
,
ctx
.
channel
());
result
.
setFlag
(
0L
);
}
else
{
log
.
info
(
"注册失败,用户名:[{}],密码:[{}]"
,
logindata
.
getUsername
(),
logindata
.
getPassword
());
result
.
setFlag
(
1L
);
}
ctx
.
writeAndFlush
(
result
).
await
();
...
...
src/main/java/com/viontech/netty/NettyServer.java
View file @
27b7999
...
...
@@ -15,6 +15,8 @@ import org.springframework.beans.factory.annotation.Value;
import
org.springframework.boot.CommandLineRunner
;
import
org.springframework.stereotype.Component
;
import
java.nio.ByteOrder
;
/**
* .
*
...
...
@@ -40,7 +42,8 @@ public class NettyServer implements CommandLineRunner {
.
childHandler
(
new
ChannelInitializer
<
SocketChannel
>()
{
@Override
protected
void
initChannel
(
SocketChannel
ch
)
{
ch
.
pipeline
().
addLast
(
new
LengthFieldBasedFrameDecoder
(
1024
*
1024
*
1000
,
4
,
4
,
-
8
,
0
));
ch
.
pipeline
().
addLast
(
new
LoggingHandler
(
LogLevel
.
INFO
));
ch
.
pipeline
().
addLast
(
new
LengthFieldBasedFrameDecoder
(
ByteOrder
.
LITTLE_ENDIAN
,
1024
*
1024
*
1000
,
4
,
4
,
-
8
,
0
,
true
));
ch
.
pipeline
().
addLast
(
new
ByteToMessageCodecHandler
());
ch
.
pipeline
().
addLast
(
new
NettyReceiverHandler
());
}
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment