scan_collection.py
2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import re
import time
import functools
import logging
import traceback
from app.utils.g import shelfconfig
s_detail = {}
test_state = False
def logtime(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
start = time.perf_counter()
res = func(*args, **kwargs)
end = time.perf_counter()
print(f'函数 {func.__name__} 耗时 {(end - start) * 1000} ms')
return res
return wrapper
@logtime
def first_filter(origin_value):
cur_dict = transfer(origin_value)
return cur_dict,s_detail
def production_filter(origin_value):
cur_dict = transfer(origin_value)
return cur_dict
def transfer(origin_value):
cur_dict = {}
addrs=shelfconfig.addrs.split('@')
if origin_value:
try:
receive_data=origin_value.decode().split("\n")
for item in receive_data[::-1]:
if re.search('^A\d{1,2}\[[0-1]{100}\]$',item.strip())==None:
receive_data.remove(item)
print (item)
print("筛选后的数据:", receive_data)
if receive_data:
for line in receive_data:
line=line.strip()
# print ("-----------------line",line)
addr = re.search("(?<=A)\d{1,2}",line)
led = re.search("\[[0-1]{100}\]", line)
if led is None:
continue
if len(addr.group())==2:
if "B"+addr.group()[1] in addrs:
addrs.remove("B"+addr.group()[1])
else:
if "A"+addr.group() in addrs:
addrs.remove("A"+addr.group())
c_list = list(led.group())
# print ("-------------------c_list",c_list)
c_list.pop(0)
c_list.pop(-1)
keyword = 'A' + addr.group()
cur_dict[keyword] = c_list
print('cur_dict',keyword,cur_dict[keyword])
except Exception as e:
logging.warning("读取传感器状态出错:{}".format(repr(e)))
logging.warning("当前解析值:{}".format(receive_data))
msg = traceback.format_exc()
logging.warning(msg)
if len(addrs)>0:
logging.warning("当前解析值2:{},{}".format(len(addrs),origin_value))
return None
return cur_dict
def change_deatil(old_dict):
global s_detail
if old_dict:
s_detail = old_dict
# print ('------------------------',s_detail)
def reset_value():
s_detail = {}
print (s_detail)