Commit 57a0c540 authored by liyuanhong's avatar liyuanhong

修改了不报数据导致连接断开的问题

parent a6cf06dd
......@@ -90,121 +90,132 @@ class DelaySend():
##############################################################################
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
if os.path.exists(self.baseUrl + self.din + '/event.txt'):
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
else:
print("event.txt is not exist")
return ["4040000b00034d1215010100010003f50b"]
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
if os.path.exists(self.baseUrl + self.din + '/gps.txt'):
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
else:
print("gps.txt is not exist")
return ["4040000b00034d1215010100010003f50b"]
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
if os.path.exists(self.baseUrl + self.din + '/obd.txt'):
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:]
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
else:
print("obd.txt is not exist")
return ["4040000b00034d1215010100010003f50b"]
def getLenOfFile(self):
with open(self.baseUrl + "event_big.txt", "r", encoding="utf-8") as fi:
......@@ -215,6 +226,7 @@ class DelaySend():
for msg in msgs:
msg = msg.replace("\n", "")
self.service.serviceSendMsg(msg,"0")
time.sleep(0.05)
def sendDelayMsgs(self):
time.sleep(0.1)
......
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