-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiob_technistar_receiver.js
211 lines (181 loc) · 8.15 KB
/
iob_technistar_receiver.js
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
//// CONFIGURATION
///////////////////////////////////////////////////////
const STATE_PATH = "javascript.0.TechniSat.";
const tsHOST="127.0.0.1";
const tsPORT=8090;
const tsPIN=0000;
const net = require("dgram").createSocket("udp4");
const tsLOG = true; // true or false
///////////////////////////////////////////////////////
//// FUNCTIONALITY - DO NOT CHANGE BELOW THIS LINE ////
///////////////////////////////////////////////////////
let remoteMessage = "";
let tsAUTH = "ERROR";
// XML-Strings ...
const ts_deviceDiscoveryRequest = '<deviceDiscoveryRequest/>';
const ts_deviceInformationRequest = '<deviceInformationRequest/>';
const ts_keepAliveRequest = '<keepAliveRequest/>';
const ts_keepAliveResponse = '<keepAliveResponse/>';
let pCommands = [];
var inc = 0;
pCommands['Button: 0'] = [inc++]; // 0
pCommands['Button: 1'] = [inc++]; // 1
pCommands['Button: 2'] = [inc++];
pCommands['Button: 3'] = [inc++];
pCommands['Button: 4'] = [inc++];
pCommands['Button: 5'] = [inc++];
pCommands['Button: 6'] = [inc++];
pCommands['Button: 7'] = [inc++];
pCommands['Button: 8'] = [inc++];
pCommands['Button: 9'] = [inc++];
pCommands['Switch Dec'] = [inc++]; // 10
pCommands['Standby'] = [inc++];
pCommands['Mute'] = [inc++]; // 12
pCommands['NotUsed_13'] = [inc++]; // 13
pCommands['List'] = [inc++];
pCommands['Volume Up'] = [inc++]; // 15
pCommands['Volume Down'] = [inc++];
pCommands['Help'] = [inc++];
pCommands['Program Up'] = [inc++];
pCommands['Program Down'] = [inc++];
pCommands['Back'] = [inc++]; // 20
pCommands['Audio'] = [inc++];
pCommands['Still'] = [inc++];
pCommands['EPG'] = [inc++];
pCommands['EXT'] = [inc++];
pCommands['TXT'] = [inc++]; // 25
pCommands['OFF'] = [inc++];
pCommands['Toggle IRC'] = [inc++];
pCommands['TV SAT'] = [inc++];
pCommands['Info'] = [inc++];
pCommands['Up'] = [inc++]; // 30
pCommands['Down'] = [inc++];
pCommands['Menu'] = [inc++];
pCommands['TV Radio'] = [inc++];
pCommands['Left'] = [inc++];
pCommands['Right'] = [inc++]; // 35
pCommands['OK'] = [inc++];
pCommands['Red'] = [inc++];
pCommands['Green'] = [inc++];
pCommands['Yellow'] = [inc++];
pCommands['Blue'] = [inc++]; // 40
pCommands['Option'] = [inc++];
pCommands['Sleep'] = [inc++];
pCommands['Rec'] = [inc++];
pCommands['PIP'] = [inc++];
pCommands['Zoom'] = [inc++]; // 45
pCommands['Genre'] = [inc++];
pCommands['HDMI'] = [inc++];
pCommands['More'] = [inc++];
pCommands['Rewind'] = [inc++];
pCommands['Stop'] = [inc++]; // 50
pCommands['Play Pause'] = [inc++];
pCommands['Wind'] = [inc++];
init();
function init() {
// createStatus ...
let createCount = 0;
/**
* Command state Drop-down
*/
// create drop-down list
let dropdown = '';
for (let lpEntry of Object.keys(pCommands)) { // 'special' loop here to get the keys
dropdown += '"' + pCommands[lpEntry] + '":"' + lpEntry + '",'; // fill JSON string
}
dropdown = dropdown.substr(0, dropdown.length-1); // remove last comma ","
dropdown = '{' + dropdown + '}'; // finalize JSON string
let dropdownJSON = JSON.parse(dropdown); // convert to JSON
// Create state. Force is set to true, so we will always update the states if e.g. configuration in this script changed.
createCount++;
createState(STATE_PATH + 'Command', undefined, true, {'name':'Send Command to Receiver', 'type':'string', 'read':false, 'write':true, 'role':'value', 'states': dropdownJSON}, () => !--createCount && callback && callback());
createCount++;
createState(STATE_PATH + 'Toggle On Off', {'name':'Turn Receiver OnOff', 'type':'boolean', 'read':false, 'write':true, 'role':'button', 'def':false }, () => !--createCount && callback && callback());
// createCount++;
// createState(STATE_PATH + 'Off', {'name':'Turn Receiver Off', 'type':'boolean'});//, 'read':false, 'write':true, 'role':'button', 'def':false }, () => !--createCount && callback && callback());
createCount++;
createState(STATE_PATH + 'Power State', {'name':'PowerStatus', 'type':'boolean'});//, 'read':false, 'write':false, 'role':'state', 'def':false }, () => !--createCount && callback && callback());
createCount++;
createState(STATE_PATH + 'Type', undefined, true, {'name':'Receiver Type'});//, 'type':'string', 'read':false, 'write':true, 'role':'value', 'def':false });
// listen to Changes
////////////////////////////////////////////////////////
// Command pull-down menu state
on({id: STATE_PATH + 'Command', change: 'any', ack: false}, function (obj) {
sendMessage(obj.state.val);
});
// TechniStar on/off buttons
on({id: STATE_PATH + 'Toggle On Off', val: true, ack: false}, function (obj) {
//powerPhilipsTv(true);
sendMessage("Standby");
});
// Get Device Information
////////////////////////////////////////////////////////
sendMessage(ts_deviceInformationRequest);
// Discover Device(s)
////////////////////////////////////////////////////////
sendMessage(ts_deviceDiscoveryRequest);
// set Event Listeners for UDP-Socket ...
////////////////////////////////////////////////////////
net.on('end', function () {
if (tsLOG == true)
console.log('disconnected from server');
});
net.on('error', function (error) {
if (tsLOG == true)
console.error('error: ' + error);
net.close();
});
net.on('message', function (message, remote) {
if (tsLOG == true)
console.log('Message from ' + remote.address + ':' + remote.port +': ' + message);
if (message.indexOf("deviceInformationResponse") > 0) {
// Message Received Device Information ...
// <deviceInformationResponse name="TechniStar S3 ISIO" softwareVer="2.57.0.4 (2575i)" protocolVer="1.5" hardwareVer="47.2" serial="0008c92e481028f4"><capabilities><type>STB</type><rcu/><keyboard/><mouse/></capabilities></deviceInformationResponse>
} else if (message.indexOf("authenticationResponse") > 0 ) {
// Answer: Authentication
// <authenticationResponse result="SUCCESS" />
var msg = message.toString().match(/result="(.*?)"/i);
tsAUTH = msg[1];
if (tsLOG == true)
console.log("Authentication: " + msg[1]);
} else if (message.indexOf("deviceDiscoveryResponse") > 0 ) {
// Answer: DeviceInformation
// <deviceDiscoveryResponse name="TechniStar S3 ISIO" type="STB" serial="0008c92e481028f4"/>
var msg = message.toString().match(/name="(.*?)"/i);
setState(STATE_PATH + "Type", msg[1], true);
if (tsLOG == true)
console.log("ReceiverType: " + msg[1]);
}
else {
// everything else
}
});
net.on('listening', function () {
if (tsLOG == true) {
var address = net.address();
console.log('UDP Server listening on ' + address.address + ":" + address.port);
}
});
// first authentication
var auth = doAuth();
return true;
}
function sendMessage(message) {
var msg = "";
if (message.length <= 4)
msg = "<rcuButtonRequest code='"+ message +"' state='pressed'/>";
else
msg = message;
net.send(message, 0, message.length, tsPORT, tsHOST, function () {
if (tsLOG == true)
console.log("Nachricht [[" + msg + "]] abgesetzt");
if (message.length <= 4)
sendMessage("<rcuButtonRequest code='"+ message +"' state='released'/>");
});
}
function doAuth() {
if (tsPIN != "") {
sendMessage('<authenticationRequest pin="' + tsPIN +'" />');
} else
return false;
}