-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvip222k_changer
84 lines (65 loc) · 1.76 KB
/
vip222k_changer
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
#!/usr/bin/env bash
if [ $# -eq 0 ] || [ $1 = '-h' ] ; then
echo 'Usage: vip222k_changer STB_IP TUNER Number Channel#'
echo 'Tuner 0 = HD Tuner'
echo 'Tuner 1 = SD TV2 Tuner'
echo 'Example: vip222k_changer 10.0.0.123 0 9475'
exit 0
fi
# Basic Settings
HOST=$1
PORT='49200'
QUERY='upnp/control/EchoSTB2'
SERVICE='urn:schemas-echostar-com:service:EchoSTB:2'
#Action to wake up a sleeping STB
WAKE_ACTION='WakeUp'
WAKE_ARGS='<Tuner>$2</Tuner>'
#Action to change the channel
CHANGE_ACTION='SetChannel'
CHANGE_ARGS="<Tuner>$2</Tuner><Channel>$3</Channel>"
#Disable Inactivity Standby
INACTIVE_ACTION='InactivityStandby'
INACTIVE_ARGS='<Enable_disable>Disable</Enable_disable><hours_4_to_8>8</hours_4_to_8>'
upnp_send()
{
local HOST=$1
local ACTION=$2
local UPNP_ARGS=$3
# prepare SOAP message
local CR=$'\r'
local MESSAGE='<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:'${ACTION}' xmlns:u="'${SERVICE}'">'${UPNP_ARGS}'</u:'${ACTION}'>
</s:Body>
</s:Envelope>'
exec 6<>/dev/tcp/$HOST/$PORT || {
echo "error: can not connect to $HOST:$PORT" >&2
return 1
}
cat <<EOF >&6
POST /$QUERY HTTP/1.0$CR
Host: $HOST:$PORT$CR
SOAPAction: "${SERVICE}#${ACTION}"$CR
Content-Type: text/xml; charset="utf-8"$CR
Content-Length: ${#MESSAGE}$CR
$CR
$MESSAGE
EOF
#Uncomment to debug
cat <&6
exec 6<&-
exec 6>&-
}
#Wake the STB up
upnp_send $HOST $WAKE_ACTION $WAKE_ARGS
#Wait for it to wake up
sleep .7
#Change the channel
upnp_send $HOST $CHANGE_ACTION $CHANGE_ARGS
sleep .1
#Disabled the inactivity timeout
upnp_send $HOST $INACTIVE_ACTION $INACTIVE_ARGS
#Sleep to allow the STB time to settle before the tuner tries to access (HD-PVR)
sleep .1