forked from dmartinpro/RFLinkGateway
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProcessors.py
109 lines (97 loc) · 1.87 KB
/
Processors.py
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import RangeDict
cardinal_pts_mapping = [
"N",
"NNE",
"NE",
"ENE",
"E",
"ESE",
"SE",
"SSE",
"S",
"SSW",
"SW",
"WSW",
"W",
"WNW",
"NW",
"NNW"
]
uv_mapping = RangeDict.RangeDict({
range(0,3): 'LOW',
range(3,6): 'MED',
range(6,8): 'HI',
range(8,11): 'V.HI',
range(11,9999): 'EX.HI'
})
wind_mapping = RangeDict.RangeDict({
range(0,14): 'LIGHT',
range(14,42): 'MODERATE',
range(42,88): 'STRONG',
range(88,999): 'STORM'
})
def shex2dec(value):
try:
val = int(value, 16)
if val >= 0x8000: val = -1*(val - 0x8000)
return val
except:
pass
return value
def hex2dec(value):
try:
return int(value, 16)
except:
pass
return value
def str2dec(value):
try:
return int(value)
except:
pass
return value
def div10(value):
try:
return value / 10
except:
pass
return value
def dir2deg(value):
try:
v = int(value) * 22.5
return v
except:
pass
return value
def dir2car(value):
try:
dec = int(value)
v = cardinal_pts_mapping[dec]
return v
except:
pass
return value
def uv2level(value):
try:
dec = int(value)
return uv_mapping[dec]
except:
pass
return value
def wind2level(value):
try:
dec = int(value)
return wind_mapping[dec]
except:
pass
return value
processors = {
"shex2dec" : shex2dec,
"hex2dec" : hex2dec,
"str2dec" : str2dec,
"dir2deg" : dir2deg,
"dir2car" : dir2car,
"div10" : div10,
"uv2level" : uv2level,
"wind2level" : wind2level
}