forked from OpenLightingProject/rdm-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dump.py
executable file
·126 lines (100 loc) · 3.1 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.
#
# ola_rdm_get.py
# Copyright (C) 2010 Simon Newton
'''Get a PID from a UID.'''
__author__ = 'nomis52@gmail.com (Simon Newton)'
import getopt
import os.path
import sys
import textwrap
import pprint
from ola import PidStore
VALIDATOR_TO_VALUE = {
PidStore.RootDeviceValidator: 0,
PidStore.SubDeviceValidator: 1,
PidStore.NonBroadcastSubDeviceValiator: 2,
PidStore.SpecificSubDeviceValidator: 3
}
TYPE_TO_STRING = {
PidStore.Bool: 'bool',
PidStore.UInt8: 'uint8',
PidStore.UInt16: 'uint16',
PidStore.UInt32: 'uint32',
PidStore.String: 'string',
}
def BuildMessage(request):
output = {
'is_repeated': False,
'items': [],
}
if isinstance(request, PidStore.RepeatedGroup):
output['is_repeated'] = True
if request.max:
output['max_repeats'] = request.max
for item in request:
type = None
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,
}
if pid._get_validators:
pid_dict['get_sub_device_range'] = VALIDATOR_TO_VALUE[pid._get_validators[0]]
if pid._set_validators:
pid_dict['set_sub_device_range'] = VALIDATOR_TO_VALUE[pid._set_validators[0]]
if pid._get_request is not None:
output = BuildMessage(pid._get_request)
pid_dict['get_request'] = output
if pid._get_response is not None:
output = BuildMessage(pid._get_response)
pid_dict['get_response'] = output
if pid._set_request is not None:
output = BuildMessage(pid._set_request)
pid_dict['set_request'] = output
if pid._set_response is not None:
output = BuildMessage(pid._set_response)
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()