aes70 1.5.4 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,15 +3,16 @@
3
3
  import { argv, exit } from 'process';
4
4
  import { RemoteDevice } from '../src/controller/remote_device.js';
5
5
  import { TCPConnection } from '../src/controller/tcp_connection.js';
6
- import { OcaBlock } from '../src/controller/ControlClasses/OcaBlock.js';
7
- import { Arguments } from '../src/controller/arguments.js';
6
+ import { UDPConnection } from '../src/controller/udp_connection.js';
7
+ import { fetchDeviceContent } from '../src/controller/fetch_device_content.js';
8
8
 
9
9
  function badArguments() {
10
- console.log('Usage: node print_tree.js [--json] <ip> <port>');
10
+ console.log('Usage: node print_tree.js [--json] [--udp] <ip> <port>');
11
11
  exit(1);
12
12
  }
13
13
 
14
14
  let jsonMode = false;
15
+ let useUdp = false;
15
16
  const rest = [];
16
17
 
17
18
  argv.slice(2).forEach((option) => {
@@ -23,6 +24,9 @@ argv.slice(2).forEach((option) => {
23
24
  case '--help':
24
25
  badArguments();
25
26
  break;
27
+ case '--udp':
28
+ useUdp = true;
29
+ break;
26
30
  default:
27
31
  rest.push(option);
28
32
  break;
@@ -36,25 +40,9 @@ const port = parseInt(rest[1]);
36
40
 
37
41
  if (!(port > 0 && port <= 0xffff)) badArguments();
38
42
 
39
- function formatPropertyValue(name, value) {
40
- if (typeof value === 'object') {
41
- if (value instanceof Arguments) {
42
- return {
43
- [name]: value.item(0),
44
- ['min' + name]: value.item(1),
45
- ['max' + name]: value.item(2),
46
- };
47
- } else if (value !== null && value.isEnum) {
48
- value = value.name;
49
- }
50
- }
51
-
52
- return {
53
- [name]: value,
54
- };
55
- }
43
+ const Connection = useUdp ? UDPConnection : TCPConnection;
56
44
 
57
- TCPConnection.connect({
45
+ Connection.connect({
58
46
  host: host,
59
47
  port: port,
60
48
  })
@@ -63,148 +51,39 @@ TCPConnection.connect({
63
51
  })
64
52
  .then(printDevice);
65
53
 
66
- async function fetchObjectInfo(o) {
67
- const info = {
68
- type: o.ClassName,
69
- };
70
-
71
- const classIdentification = await o.GetClassIdentification();
72
-
73
- Object.assign(info, classIdentification);
74
-
75
- await Promise.all(
76
- o.get_properties().forEach(async (p) => {
77
- const { name } = p;
78
- if (name === 'ClassID' || name === 'ClassVersion') return;
79
- if (o instanceof OcaBlock && name === 'Members') return;
80
- const getter = p.getter(o);
81
- if (!getter) return;
82
- try {
83
- const currentValue = await getter();
84
-
85
- Object.assign(info, formatPropertyValue(name, currentValue));
86
- } catch (err) {
87
- if (err.status != 8)
88
- console.error(
89
- 'Fetching property',
90
- o.ClassName,
91
- p.name,
92
- 'failed:',
93
- err
94
- );
95
- }
96
- })
97
- );
98
-
99
- return info;
100
- }
101
-
102
- async function printTree(objects, prefix) {
54
+ async function printTree(content, prefix) {
103
55
  if (!prefix) prefix = [];
104
56
 
105
- let lastPath;
106
-
107
- for (let i = 0; i < objects.length; i++) {
108
- const o = objects[i];
109
-
110
- if (Array.isArray(o)) {
111
- await printTree(o, lastPath);
112
- continue;
113
- }
114
-
115
- const roleName = await o.GetRole();
116
-
117
- const path = prefix.concat([roleName]);
118
-
119
- lastPath = path;
57
+ for (const info of content) {
58
+ const { Role, type, Members, ...Rest } = info;
59
+ const path = prefix.concat([Role]);
120
60
 
121
61
  console.log('Path: %s', path.join('/'));
122
62
 
123
- const info = await fetchObjectInfo(o);
124
-
125
- for (const name in info) {
126
- console.log(' %s: %O ', name, info[name]);
127
- }
128
- }
129
- }
130
-
131
- async function managerExists(manager) {
132
- try {
133
- await manager.GetClassIdentification();
134
- return true;
135
- } catch (err) {
136
- if (err.status != 5) {
137
- throw err;
63
+ for (const name in Rest) {
64
+ console.log(' %s: %O ', name, Rest[name]);
138
65
  }
139
66
 
140
- return false;
141
- }
142
- }
143
-
144
- async function generateJson(objects) {
145
- const result = [];
146
-
147
- for (let i = 0; i < objects.length; i++) {
148
- const o = objects[i];
149
-
150
- if (Array.isArray(o)) {
151
- await printTreeJson(o, lastPath);
152
- continue;
153
- }
154
-
155
- const info = await fetchObjectInfo(o);
156
-
157
- if (o instanceof OcaBlock) {
158
- const members = objects[i + 1];
159
- if (!Array.isArray(members)) {
160
- throw new Error('Member missing for OcaBlock.');
161
- }
162
- info.Members = await generateJson(members);
163
- i++;
67
+ if (Members) {
68
+ printTree(Members, path);
164
69
  }
165
-
166
- result.push(info);
167
70
  }
168
-
169
- return result;
170
71
  }
171
72
 
172
- async function printTreeJson(objects) {
173
- console.log(JSON.stringify(await generateJson(objects), undefined, 2));
73
+ function printTreeJson(content) {
74
+ console.log(JSON.stringify(content, undefined, 2));
174
75
  }
175
76
 
176
77
  async function printDevice(device) {
177
- const print = jsonMode ? printTreeJson : printTree;
178
78
  try {
179
- const objects = await device.GetDeviceTree();
180
- const managers = [
181
- device.DeviceManager,
182
- device.SecurityManager,
183
- device.FirmwareManager,
184
- device.SubscriptionManager,
185
- device.PowerManager,
186
- device.NetworkManager,
187
- device.MediaClockManager,
188
- device.LibraryManager,
189
- device.AudioProcessingManager,
190
- device.DeviceTimeManager,
191
- device.TaskManager,
192
- device.CodingManager,
193
- device.DiagnosticManager,
194
- ];
195
-
196
- for (const manager of managers) {
197
- if (await managerExists(manager)) objects.push(manager);
198
- }
79
+ const content = await fetchDeviceContent(device);
199
80
 
200
- await print(objects);
201
- exit(0);
202
- } catch (error) {
203
- if (error.status) {
204
- console.error('Failure: %s', error.status);
81
+ if (jsonMode) {
82
+ printTreeJson(content);
205
83
  } else {
206
- console.error('Failure: %o', error);
84
+ printTree(content);
207
85
  }
208
- exit(1);
86
+ } finally {
87
+ device.close();
209
88
  }
210
89
  }