-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdump.py
executable file
·126 lines (99 loc) · 3.27 KB
/
dump.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/python
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# dump.py
# Copyright (C) 2010 Simon Newton
'''Dump PID data.'''
__author__ = '[email protected] (Simon Newton)'
import pprint
from ola import PidStore
VALIDATOR_TO_VALUE = {
PidStore.RootDeviceValidator: 0,
PidStore.SubDeviceValidator: 1,
PidStore.NonBroadcastSubDeviceValidator: 2,
PidStore.SpecificSubDeviceValidator: 3
}
TYPE_TO_STRING = {
PidStore.Bool: 'bool',
PidStore.Int8: 'int8',
PidStore.UInt8: 'uint8',
PidStore.Int16: 'int16',
PidStore.UInt16: 'uint16',
PidStore.Int32: 'int32',
PidStore.UInt32: 'uint32',
PidStore.String: 'string',
PidStore.UIDAtom: 'uid',
PidStore.MACAtom: 'mac',
PidStore.IPV4: 'ipv4',
PidStore.IPV6: 'ipv6',
PidStore.Group: 'group',
}
def BuildMessage(request):
output = {
'items': [],
}
for item in request.GetAtoms():
data = {
'name': item.name,
'type': TYPE_TO_STRING[item.__class__],
}
if item.size and item.size != 1:
data['size'] = item.size
output['items'].append(data)
return output
def BuildPid(pid):
pid_dict = {
'name': pid.name,
'value': pid.value,
}
print(pid.name)
if pid._validators[PidStore.RDM_GET]:
pid_dict['get_sub_device_range'] = VALIDATOR_TO_VALUE[pid._validators[PidStore.RDM_GET][0]]
if pid._validators[PidStore.RDM_SET]:
pid_dict['set_sub_device_range'] = VALIDATOR_TO_VALUE[pid._validators[PidStore.RDM_SET][0]]
if pid.GetRequest(PidStore.RDM_GET) is not None:
output = BuildMessage(pid.GetRequest(PidStore.RDM_GET))
pid_dict['get_request'] = output
if pid.GetResponse(PidStore.RDM_GET) is not None:
output = BuildMessage(pid.GetResponse(PidStore.RDM_GET))
pid_dict['get_response'] = output
if pid.GetRequest(PidStore.RDM_SET) is not None:
output = BuildMessage(pid.GetRequest(PidStore.RDM_SET))
pid_dict['set_request'] = output
if pid.GetResponse(PidStore.RDM_SET) is not None:
output = BuildMessage(pid.GetResponse(PidStore.RDM_SET))
pid_dict['set_response'] = output
return pid_dict
def main():
pid_store = PidStore.GetStore()
pids = []
manufacturers = []
for pid in pid_store.Pids():
pid_dict = BuildPid(pid)
pids.append(pid_dict)
for id, name in pid_store._manufacturer_id_to_name.iteritems():
manufacturer = {
'id': id,
'name': name,
'pids': []
}
for pid in pid_store._manufacturer_pids[id].values():
pid_dict = BuildPid(pid)
manufacturer['pids'].append(pid_dict)
manufacturers.append(manufacturer)
# pprint.pprint(manufacturers)
pprint.pprint(pids)
if __name__ == '__main__':
main()