Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
new-socketemulator
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李远洪
new-socketemulator
Commits
0130c085
Commit
0130c085
authored
Jul 30, 2020
by
liyuanhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
M500模拟器增加了数据补报功能
parent
cc2e2149
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
246 additions
and
3 deletions
+246
-3
data/messageTools/carData/012201500010.json
data/messageTools/carData/012201500010.json
+1
-1
data/protocolTools/carData/M202003060520.json
data/protocolTools/carData/M202003060520.json
+1
-1
lib/util/DelaySend.py
lib/util/DelaySend.py
+234
-0
templates/otherTools/maptool.html
templates/otherTools/maptool.html
+1
-1
views/protocolTools/M_carSimulater_process.py
views/protocolTools/M_carSimulater_process.py
+9
-0
No files found.
data/messageTools/carData/012201500010.json
View file @
0130c085
{
"time"
:
{
"dateTime"
:
"2020-07-30 10:17:57"
,
"date"
:
"2020-07-30"
,
"time"
:
"10:17:57"
},
"curDayTravel"
:
{
"todayTotalMilleage"
:
2981
,
"todayTotalOil"
:
206
,
"todayTotalTime"
:
185
,
"theMilleage"
:
2981
,
"theOil"
:
206
,
"theTime"
:
185
},
"travelData"
:
{
"totalMilleage"
:
129666
,
"totalOil"
:
11329
,
"totalTime"
:
7960
}}
\ No newline at end of file
{
"time"
:
{
"dateTime"
:
"2020-07-30 10:17:57"
,
"date"
:
"2020-07-30"
,
"time"
:
"10:17:57"
},
"curDayTravel"
:
{
"todayTotalMilleage"
:
4261
,
"todayTotalOil"
:
286
,
"todayTotalTime"
:
265
,
"theMilleage"
:
1280
,
"theOil"
:
80
,
"theTime"
:
80
},
"travelData"
:
{
"totalMilleage"
:
130946
,
"totalOil"
:
11409
,
"totalTime"
:
8040
}}
\ No newline at end of file
data/protocolTools/carData/M202003060520.json
View file @
0130c085
{
"time"
:
{
"dateTime"
:
"2020-07-30 10:05:57"
,
"date"
:
"2020-07-30"
,
"time"
:
"10:05:57"
},
"curDayTravel"
:
{
"todayTotalMilleage"
:
4454
,
"todayTotalOil"
:
284
,
"todayTotalTime"
:
278
,
"theMilleage"
:
3075
,
"theOil"
:
195
,
"theTime"
:
192
},
"travelData"
:
{
"totalMilleage"
:
638772
,
"totalOil"
:
56232
,
"totalTime"
:
38492
},
"event"
:
{
"threeRapid"
:
{
"totalRapidlyAccelerate"
:
55
,
"totalSharpSlowdown"
:
44
,
"totalSharpTurn"
:
46
}}}
\ No newline at end of file
{
"time"
:
{
"dateTime"
:
"2020-07-30 10:05:57"
,
"date"
:
"2020-07-30"
,
"time"
:
"10:05:57"
},
"curDayTravel"
:
{
"todayTotalMilleage"
:
4796
,
"todayTotalOil"
:
311
,
"todayTotalTime"
:
299
,
"theMilleage"
:
259
,
"theOil"
:
19
,
"theTime"
:
16
},
"travelData"
:
{
"totalMilleage"
:
639114
,
"totalOil"
:
56259
,
"totalTime"
:
38513
},
"event"
:
{
"threeRapid"
:
{
"totalRapidlyAccelerate"
:
55
,
"totalSharpSlowdown"
:
44
,
"totalSharpTurn"
:
46
}}}
\ No newline at end of file
lib/util/DelaySend.py
0 → 100644
View file @
0130c085
#coding: utf-8
import
binascii
import
os
import
socket
import
time
class
DelaySend
():
def
__init__
(
self
,
din
=
"M202003060520"
,
service
=
None
):
self
.
baseUrl
=
"data/protocolTools/sendMsg/"
self
.
din
=
din
self
.
service
=
service
def
setDin
(
self
,
din
):
self
.
din
=
din
def
setServer
(
self
,
data
):
self
.
service
=
data
#####################################################
# 数字转换为16进制字符串
#####################################################
def
int2hexString
(
self
,
num
):
hexStr
=
hex
(
num
)[
2
:]
if
(
len
(
hexStr
)
%
2
)
==
1
:
hexStr
=
"0"
+
hexStr
return
hexStr
#####################################################
# 数字转换为16进制字符串,通过传入字节数可自动补0
# 传入数据格式所占字节数
#####################################################
def
int2hexStringByBytes
(
self
,
num
,
bytescount
=
1
):
hexStr
=
hex
(
num
)[
2
:]
while
len
(
hexStr
)
<
(
bytescount
*
2
):
hexStr
=
"0"
+
hexStr
return
hexStr
#####################################################
# 设备id转换为16进制字符串
#####################################################
def
devid2hexString
(
self
,
id
):
# 获取第一个字符的ASCII值
ascii
=
ord
(
id
[
0
:
1
])
# 将10进制的ASCII值转换为16进制
ascii
=
self
.
int2hexString
(
int
(
ascii
))
devid
=
str
(
ascii
)
+
id
[
1
:]
return
devid
#####################################################
# 定义生成校验字段的函数
# inputStr:需要传入一个已经转换为16进制的字符串
#####################################################
# add crc 16 check at the end of the string
def
crc16
(
self
,
inputStr
):
inputStrByte
=
bytes
.
fromhex
(
inputStr
)
crc
=
0xFFFF
for
i
in
range
(
0
,
len
(
inputStrByte
)):
for
j
in
range
(
0
,
8
):
c15
=
(
crc
>>
15
)
==
1
bit
=
((
inputStrByte
[
i
]
>>
(
7
-
j
))
&
1
)
==
1
crc
<<=
1
crc
&=
0xFFFF
if
c15
^
bit
:
crc
^=
0x1021
crc
=
str
(
hex
(
crc
))
crc
=
self
.
leftPad
(
crc
[
2
:],
4
)
# outputStr = inputStr + crc
outputStr
=
crc
return
outputStr
# pad zero to the left of the string if not long enough
def
leftPad
(
self
,
inputStr
,
strLen
):
if
(
strLen
>
len
(
inputStr
)):
outputStr
=
"0000000000000000000000000000000000000000"
+
inputStr
outputStr
=
outputStr
[
len
(
outputStr
)
-
strLen
:]
return
outputStr
else
:
return
inputStr
# pad zero to the right of the string if not long enough
def
rightPad
(
self
,
inputStr
,
strLen
):
if
(
strLen
>
len
(
inputStr
)):
outputStr
=
inputStr
+
"0000000000000000000000000000000000000000"
outputStr
=
outputStr
[:
strLen
]
return
outputStr
else
:
return
inputStr
##############################################################################
def
getEventPkg
(
self
):
with
open
(
self
.
baseUrl
+
self
.
din
+
"/event.txt"
,
"r"
,
encoding
=
"utf-8"
)
as
fi
:
content
=
fi
.
readlines
()
pkg
=
""
msgs
=
[]
pkgCounts
=
0
for
i
in
content
:
onePkg
=
i
[
21
:]
.
replace
(
"
\n
"
,
""
)
onePkg
=
onePkg
[
30
:][:
-
4
]
onePkg
=
onePkg
[
2
:]
pkg
=
pkg
+
onePkg
pkgCounts
=
pkgCounts
+
1
if
len
(
pkg
)
>
2000
:
pkgCounts
=
self
.
int2hexStringByBytes
(
pkgCounts
)
HEADER
=
"4040"
WATER_CODE
=
self
.
int2hexStringByBytes
(
1
,
2
)
DEV_ID
=
self
.
devid2hexString
(
self
.
din
)
FUN_ID
=
"0021"
LENGTH
=
self
.
int2hexStringByBytes
(
int
(
len
(
WATER_CODE
+
DEV_ID
+
FUN_ID
+
pkgCounts
+
pkg
)
/
2
),
2
)
CHECK_CODE
=
self
.
crc16
(
HEADER
+
LENGTH
+
WATER_CODE
+
DEV_ID
+
FUN_ID
+
pkgCounts
+
pkg
)
msg
=
HEADER
+
LENGTH
+
WATER_CODE
+
DEV_ID
+
FUN_ID
+
pkgCounts
+
pkg
+
CHECK_CODE
msgs
.
append
(
msg
)
pkg
=
""
pkgCounts
=
0
pkgCounts
=
self
.
int2hexStringByBytes
(
pkgCounts
)
HEADER
=
"4040"
WATER_CODE
=
self
.
int2hexStringByBytes
(
1
,
2
)
DEV_ID
=
self
.
devid2hexString
(
self
.
din
)
FUN_ID
=
"0021"
LENGTH
=
self
.
int2hexStringByBytes
(
int
(
len
(
WATER_CODE
+
DEV_ID
+
FUN_ID
+
pkgCounts
+
pkg
)
/
2
),
2
)
CHECK_CODE
=
self
.
crc16
(
HEADER
+
LENGTH
+
WATER_CODE
+
DEV_ID
+
FUN_ID
+
pkgCounts
+
pkg
)
msg
=
HEADER
+
LENGTH
+
WATER_CODE
+
DEV_ID
+
FUN_ID
+
pkgCounts
+
pkg
+
CHECK_CODE
msgs
.
append
(
msg
)
with
open
(
self
.
baseUrl
+
self
.
din
+
"/event_big.txt"
,
"w"
,
encoding
=
"utf-8"
)
as
fi2
:
for
txt
in
msgs
:
fi2
.
write
(
txt
+
"
\n
"
)
return
msgs
def
getGpsPkg
(
self
):
with
open
(
self
.
baseUrl
+
self
.
din
+
"/gps.txt"
,
"r"
,
encoding
=
"utf-8"
)
as
fi
:
content
=
fi
.
readlines
()
pkg
=
""
msgs
=
[]
pkgCounts
=
0
for
i
in
content
:
onePkg
=
i
[
21
:]
.
replace
(
"
\n
"
,
""
)
onePkg
=
onePkg
[
30
:][:
-
4
]
onePkg
=
onePkg
[
2
:]
pkg
=
pkg
+
onePkg
pkgCounts
=
pkgCounts
+
1
if
len
(
pkg
)
>
2000
:
pkgCounts
=
self
.
int2hexStringByBytes
(
pkgCounts
)
HEADER
=
"4040"
WATER_CODE
=
self
.
int2hexStringByBytes
(
1
,
2
)
DEV_ID
=
self
.
devid2hexString
(
self
.
din
)
FUN_ID
=
"0010"
LENGTH
=
self
.
int2hexStringByBytes
(
int
(
len
(
WATER_CODE
+
DEV_ID
+
FUN_ID
+
pkgCounts
+
pkg
)
/
2
),
2
)
CHECK_CODE
=
self
.
crc16
(
HEADER
+
LENGTH
+
WATER_CODE
+
DEV_ID
+
FUN_ID
+
pkgCounts
+
pkg
)
msg
=
HEADER
+
LENGTH
+
WATER_CODE
+
DEV_ID
+
FUN_ID
+
pkgCounts
+
pkg
+
CHECK_CODE
msgs
.
append
(
msg
)
pkg
=
""
pkgCounts
=
0
pkgCounts
=
self
.
int2hexStringByBytes
(
pkgCounts
)
HEADER
=
"4040"
WATER_CODE
=
self
.
int2hexStringByBytes
(
1
,
2
)
DEV_ID
=
self
.
devid2hexString
(
self
.
din
)
FUN_ID
=
"0010"
LENGTH
=
self
.
int2hexStringByBytes
(
int
(
len
(
WATER_CODE
+
DEV_ID
+
FUN_ID
+
pkgCounts
+
pkg
)
/
2
),
2
)
CHECK_CODE
=
self
.
crc16
(
HEADER
+
LENGTH
+
WATER_CODE
+
DEV_ID
+
FUN_ID
+
pkgCounts
+
pkg
)
msg
=
HEADER
+
LENGTH
+
WATER_CODE
+
DEV_ID
+
FUN_ID
+
pkgCounts
+
pkg
+
CHECK_CODE
msgs
.
append
(
msg
)
with
open
(
self
.
baseUrl
+
self
.
din
+
"/gps_big.txt"
,
"w"
,
encoding
=
"utf-8"
)
as
fi2
:
for
txt
in
msgs
:
fi2
.
write
(
txt
+
"
\n
"
)
return
msgs
def
getObdPkg
(
self
):
with
open
(
self
.
baseUrl
+
self
.
din
+
"/obd.txt"
,
"r"
,
encoding
=
"utf-8"
)
as
fi
:
content
=
fi
.
readlines
()
pkg
=
""
msgs
=
[]
pkgCounts
=
0
for
i
in
content
:
onePkg
=
i
[
21
:]
.
replace
(
"
\n
"
,
""
)
onePkg
=
onePkg
[
30
:][:
-
4
]
onePkg
=
onePkg
[
2
:]
print
(
onePkg
)
pkg
=
pkg
+
onePkg
pkgCounts
=
pkgCounts
+
1
if
len
(
pkg
)
>
2000
:
pkgCounts
=
self
.
int2hexStringByBytes
(
pkgCounts
)
HEADER
=
"4040"
WATER_CODE
=
self
.
int2hexStringByBytes
(
1
,
2
)
DEV_ID
=
self
.
devid2hexString
(
self
.
din
)
FUN_ID
=
"0012"
LENGTH
=
self
.
int2hexStringByBytes
(
int
(
len
(
WATER_CODE
+
DEV_ID
+
FUN_ID
+
pkgCounts
+
pkg
)
/
2
),
2
)
CHECK_CODE
=
self
.
crc16
(
HEADER
+
LENGTH
+
WATER_CODE
+
DEV_ID
+
FUN_ID
+
pkgCounts
+
pkg
)
msg
=
HEADER
+
LENGTH
+
WATER_CODE
+
DEV_ID
+
FUN_ID
+
pkgCounts
+
pkg
+
CHECK_CODE
msgs
.
append
(
msg
)
pkg
=
""
pkgCounts
=
0
pkgCounts
=
self
.
int2hexStringByBytes
(
pkgCounts
)
HEADER
=
"4040"
WATER_CODE
=
self
.
int2hexStringByBytes
(
1
,
2
)
DEV_ID
=
self
.
devid2hexString
(
self
.
din
)
FUN_ID
=
"0012"
LENGTH
=
self
.
int2hexStringByBytes
(
int
(
len
(
WATER_CODE
+
DEV_ID
+
FUN_ID
+
pkgCounts
+
pkg
)
/
2
),
2
)
CHECK_CODE
=
self
.
crc16
(
HEADER
+
LENGTH
+
WATER_CODE
+
DEV_ID
+
FUN_ID
+
pkgCounts
+
pkg
)
msg
=
HEADER
+
LENGTH
+
WATER_CODE
+
DEV_ID
+
FUN_ID
+
pkgCounts
+
pkg
+
CHECK_CODE
msgs
.
append
(
msg
)
with
open
(
self
.
baseUrl
+
self
.
din
+
"/obd_big.txt"
,
"w"
,
encoding
=
"utf-8"
)
as
fi2
:
for
txt
in
msgs
:
fi2
.
write
(
txt
+
"
\n
"
)
return
msgs
def
getLenOfFile
(
self
):
with
open
(
self
.
baseUrl
+
"event_big.txt"
,
"r"
,
encoding
=
"utf-8"
)
as
fi
:
data
=
fi
.
readline
()
print
(
len
(
data
))
def
sendMsg
(
self
,
msgs
):
for
msg
in
msgs
:
msg
=
msg
.
replace
(
"
\n
"
,
""
)
self
.
service
.
serviceSendMsg
(
msg
,
"0"
)
def
sendDelayMsgs
(
self
):
time
.
sleep
(
0.1
)
self
.
service
.
websocket
.
sendMsgToClient
(
"-----------------------发送补报消息【开始】--------------------------"
,
self
.
service
.
websocketId
)
msg
=
self
.
getEventPkg
()
self
.
sendMsg
(
msg
)
time
.
sleep
(
0.1
)
msg
=
self
.
getGpsPkg
()
self
.
sendMsg
(
msg
)
time
.
sleep
(
0.1
)
msg
=
self
.
getObdPkg
()
self
.
sendMsg
(
msg
)
self
.
service
.
websocket
.
sendMsgToClient
(
"-----------------------发送补报消息【结束】--------------------------"
,
self
.
service
.
websocketId
)
for
fi
in
os
.
listdir
(
self
.
baseUrl
+
self
.
din
):
os
.
remove
(
self
.
baseUrl
+
self
.
din
+
"/"
+
fi
)
os
.
rmdir
(
self
.
baseUrl
+
self
.
din
)
templates/otherTools/maptool.html
View file @
0130c085
...
...
@@ -42,7 +42,7 @@
<a
href=
"#"
class=
"btn btn-default"
role=
"button"
id=
"ctrArea2"
onclick=
"ctrAreaShow(this)"
>
轨迹工具
</a>
<a
href=
"#"
class=
"btn btn-default"
role=
"button"
id=
"ctrArea3"
onclick=
"ctrAreaShow(this)"
>
其他工具
</a>
</div>
<div
id=
"ctrArea_1"
style=
"width:400px;height:
175
px;background:white;z-index:50;position:absolute;top:160px;right:40px;border-radius:5px;display:none;"
class=
"btn-group btn-group-justified"
role=
"group"
>
<div
id=
"ctrArea_1"
style=
"width:400px;height:
200
px;background:white;z-index:50;position:absolute;top:160px;right:40px;border-radius:5px;display:none;"
class=
"btn-group btn-group-justified"
role=
"group"
>
<div
style=
"border-width: 1px;border-bottom: 1px solid #eee;margin: 10px;padding-bottom: 5px;"
>
<label>
经 ,纬 度 :
</label><input
id=
"toLngLat"
type=
"text"
class=
"form-control"
value=
"106.54041,29.40268"
style=
"width:200px;"
>
<button
type=
"button"
class=
"btn btn-default"
onclick=
"setposition()"
>
定位
</button>
...
...
views/protocolTools/M_carSimulater_process.py
View file @
0130c085
...
...
@@ -16,6 +16,7 @@ import json
import
traceback
from
lib.socket.service.ProtocolSimulaterService
import
ProtocolSimulaterService
from
lib.util
import
fileUtil
from
lib.util.DelaySend
import
DelaySend
M_carSimulater_process
=
Blueprint
(
'M_carSimulater_process'
,
__name__
)
...
...
@@ -133,6 +134,14 @@ def login():
versionMsg
=
versionObj
.
generateVersionMsg
()
service
.
serviceSendMsg
(
versionMsg
,
"版本"
)
service
.
setSn
(
service
.
getSn
()
+
1
)
# 数据补报
if
(
os
.
path
.
exists
(
"data/protocolTools/sendMsg/"
+
params
[
"carId"
])):
ds
=
DelaySend
(
params
[
"carId"
],
service
)
ds
.
sendDelayMsgs
()
else
:
pass
data
[
"status"
]
=
"200"
data
[
"message"
]
=
"登录成功!"
except
BaseException
as
e
:
...
...
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