Merge remote-tracking branch 'upstream/master' into openelec-settings

Conflicts:
	packages/mediacenter/xbmc-addon-settings/config/default_settings.xml
	packages/mediacenter/xbmc-addon-settings/source/resources/language/English/strings.xml
	packages/mediacenter/xbmc-addon-settings/source/resources/settings.xml
	packages/mediacenter/xbmc/init.d/93_xbmc
This commit is contained in:
Stefan Saraev 2013-02-26 22:47:14 +02:00
commit 069196012a
25 changed files with 960 additions and 27 deletions

View File

@ -1,3 +1,7 @@
3.0.2
- added addon settings for
modifying tuner type (DVB-C, DVB-T, ATSC)
setting delays
3.0.1
- bump addon version
- binary files are stored with OpenELEC image

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 35 KiB

View File

@ -20,7 +20,7 @@
PKG_NAME="hdhomerun"
PKG_VERSION="3.0"
PKG_REV="1"
PKG_REV="2"
PKG_ARCH="any"
PKG_LICENSE="GPL"
PKG_SITE="http://www.silicondust.com/products/hdhomerun/dvbt/"
@ -31,8 +31,6 @@ PKG_PRIORITY="optional"
PKG_SECTION="driver/dvb"
PKG_SHORTDESC="A linux DVB driver for the HDHomeRun (http://www.silicondust.com)."
PKG_LONGDESC="A linux DVB driver for the HDHomeRun (http://www.silicondust.com)."
PKG_AUTORECONF="no"
PKG_IS_ADDON="yes"
PKG_ADDON_TYPE="xbmc.python.script"

View File

@ -0,0 +1,4 @@
<settings>
<setting id="PRE_WAIT" value="2" />
<setting id="POST_WAIT" value="1" />
</settings>

View File

@ -0,0 +1,28 @@
#!/bin/sh
################################################################################
# This file is part of OpenELEC - http://www.openelec.tv
# Copyright (C) 2009-2012 Stephan Raue (stephan@openelec.tv)
#
# 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, 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenELEC.tv; see the file COPYING. If not, write to
# the Free Software Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110, USA.
# http://www.gnu.org/copyleft/gpl.html
################################################################################
. /etc/profile
ADDON_DIR="$HOME/.xbmc/addons/driver.dvb.hdhomerun"
logger -t Hdhomerun "### Hdhomerun manual start ###"
. $ADDON_DIR/bin/userspace-driver.sh

View File

@ -0,0 +1,26 @@
#!/bin/sh
################################################################################
# This file is part of OpenELEC - http://www.openelec.tv
# Copyright (C) 2009-2012 Stephan Raue (stephan@openelec.tv)
#
# 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, 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenELEC.tv; see the file COPYING. If not, write to
# the Free Software Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110, USA.
# http://www.gnu.org/copyleft/gpl.html
################################################################################
. /etc/profile
logger -t Hdhomerun "### Hdhomerun manual stop ###"
killall userhdhomerun

View File

@ -0,0 +1,125 @@
"""
################################################################################
# This file is part of OpenELEC - http://www.openelec.tv
# Copyright (C) 2009-2013 Stephan Raue (stephan@openelec.tv)
# Copyright (C) 2013 ultraman/vpeter
#
# 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, 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenELEC.tv; see the file COPYING. If not, write to
# the Free Software Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110, USA.
# http://www.gnu.org/copyleft/gpl.html
################################################################################
"""
import os
import sys
import shutil
import xmlpp
import xbmcaddon
from xml.dom import minidom
from array import array
__settings__ = xbmcaddon.Addon(id='driver.dvb.hdhomerun')
__cwd__ = __settings__.getAddonInfo('path')
__settings_xml__ = xbmc.translatePath(os.path.join(__cwd__, 'resources', 'settings.xml'))
__hdhomerun_log__ = '/var/log/dvbhdhomerun.log'
# make backup settings only once
try:
with open(__settings_xml__ + '_orig') as f: pass
except IOError as e:
shutil.copyfile(__settings_xml__, __settings_xml__ + '_orig')
######################################################################################################
# get supported devices on a system (name)
tuners = []
try:
for line in open(__hdhomerun_log__, 'r'):
line = line.strip()
if line.startswith('Registered tuner'):
name = line.split(':');
name = name[2].strip()
tuners.append(name)
except IOError:
print 'Error reading log file ', __hdhomerun_log__
"""
root ~ # grep "Registered tuner" /var/log/dvbhdhomerun.log
Registered tuner, id from kernel: 0 name: 101ADD2B-0
Registered tuner, id from kernel: 1 name: 101ADD2B-1
Registered tuner, id from kernel: 2 name: 1031D75A-0
Registered tuner, id from kernel: 3 name: 1031D75A-1
"""
######################################################################################################
xmldoc = minidom.parse(__settings_xml__)
category = xmldoc.getElementsByTagName('category')
# remove all nodes with id started with ATTACHED_TUNER_
for node_cat in category:
setting = node_cat.getElementsByTagName('setting')
for node_set in setting :
if 'id' in node_set.attributes.keys() and not node_set.getAttribute('id').find('ATTACHED_TUNER_'):
node_set.parentNode.removeChild(node_set)
# add new ATTACHED_TUNER_ nodes for available tuners
for node_cat in category:
setting = node_cat.getElementsByTagName('setting')
for node_set in setting :
if 'label' in node_set.attributes.keys() and '9010' in node_set.getAttribute('label'):
for ix, tuner_name in enumerate(tuners):
tuner_name_var = tuner_name.replace('-', '_')
node1 = xmldoc.createElement("setting")
node1.setAttribute("id", 'ATTACHED_TUNER_' + tuner_name_var + '_DVBMODE')
node1.setAttribute("label", tuner_name)
node1.setAttribute("type", 'labelenum')
node1.setAttribute("default", 'auto')
node1.setAttribute("values", 'auto|ATSC|DVB-C|DVB-T')
node_cat.appendChild(node1)
node2 = xmldoc.createElement("setting")
node2.setAttribute("id", 'ATTACHED_TUNER_' + tuner_name_var + '_FULLNAME')
node2.setAttribute("label", '9020')
node2.setAttribute("type", 'bool')
node2.setAttribute("default", 'false')
node_cat.appendChild(node2)
node3 = xmldoc.createElement("setting")
node3.setAttribute("id", 'ATTACHED_TUNER_' + tuner_name_var + '_DISABLE')
node3.setAttribute("label", '9030')
node3.setAttribute("type", 'bool')
node3.setAttribute("default", 'false')
node_cat.appendChild(node3)
# for tuner
break
######################################################################################################
# save file back
try:
outputfile=open(__settings_xml__, 'w')
xmlpp.pprint(xmldoc.toxml(), output=outputfile, indent=2)
outputfile.close()
except IOError:
print 'Error writing file ', __settings_xml__
######################################################################################################
# dialog is closed already so just open settings again
xbmcaddon.Addon(id='driver.dvb.hdhomerun').openSettings()

View File

@ -24,6 +24,11 @@
ADDON_DIR="$HOME/.xbmc/addons/driver.dvb.hdhomerun"
ADDON_HOME="$HOME/.xbmc/userdata/addon_data/driver.dvb.hdhomerun"
ADDON_SETTINGS="$ADDON_HOME/settings.xml"
# modules are not automatically loaded
modprobe dvb_hdhomerun
modprobe dvb_hdhomerun_fe
mkdir -p $ADDON_HOME
@ -31,31 +36,84 @@ if [ ! -f "$ADDON_HOME/dvbhdhomerun.sample" ]; then
cp $ADDON_DIR/config/* $ADDON_HOME/
fi
if [ ! -f "$ADDON_SETTINGS" ]; then
cp $ADDON_DIR/settings-default.xml $ADDON_SETTINGS
fi
mkdir -p /var/config
cat "$ADDON_SETTINGS" | awk -F\" '{print $2"=\""$4"\""}' | sed '/^=/d' > /var/config/hdhomerun-addon.conf
. /var/config/hdhomerun-addon.conf
if [ -z "$(pidof userhdhomerun)" ]; then
if [ "$ENABLE_TUNER_TYPES" = "true" ]; then
DVBHDHOMERUN_CONF_TMP=/tmp/dvbhdhomerun.conf
touch $ADDON_HOME/dvbhdhomerun.conf
cp $ADDON_HOME/dvbhdhomerun.conf $DVBHDHOMERUN_CONF_TMP
# get tuner serial numbers
SERIALS=$(cat /var/config/hdhomerun-addon.conf | sed -n 's|^ATTACHED_TUNER_\(.*\)_\(.*\)_DVBMODE=.*|\1-\2|gp' | sort | uniq)
. /var/config/hdhomerun-addon.conf
for SERIAL in ${SERIALS[@]}; do
SERIAL_VAR=$(echo $SERIAL | sed 's|-|_|')
DVBMODE=$(eval echo \$ATTACHED_TUNER_${SERIAL_VAR}_DVBMODE)
FULLNAME=$(eval echo \$ATTACHED_TUNER_${SERIAL_VAR}_FULLNAME)
DISABLE=$(eval echo \$ATTACHED_TUNER_${SERIAL_VAR}_DISABLE)
[ "$DVBMODE" = "auto" ] && DVBMODE=""
# remove setttings for this tuner
awk -v val="[$SERIAL]" '$0 == val {flag=1; next} /^tuner_type=|^use_full_name=|^disable=|^#|^$/{if (flag==1) next} /.*/{flag=0; print}' $DVBHDHOMERUN_CONF_TMP >${DVBHDHOMERUN_CONF_TMP}-types
mv ${DVBHDHOMERUN_CONF_TMP}-types $DVBHDHOMERUN_CONF_TMP
echo "" >>$DVBHDHOMERUN_CONF_TMP
# remove empty lines at the end of file
sed -i '${/^$/d;}' $DVBHDHOMERUN_CONF_TMP
ADDNEW=true
if [ -n "$DVBMODE" ]; then
[ $ADDNEW = true ] && ADDNEW=false && echo "[$SERIAL]" >>$DVBHDHOMERUN_CONF_TMP
echo "tuner_type=$DVBMODE" >>$DVBHDHOMERUN_CONF_TMP
fi
if [ "$FULLNAME" = "true" ]; then
[ $ADDNEW = true ] && ADDNEW=false && echo "[$SERIAL]" >>$DVBHDHOMERUN_CONF_TMP
echo "use_full_name=true" >>$DVBHDHOMERUN_CONF_TMP
fi
if [ "$DISABLE" = "true" ]; then
[ $ADDNEW = true ] && ADDNEW=false && echo "[$SERIAL]" >>$DVBHDHOMERUN_CONF_TMP
echo "disable=true" >>$DVBHDHOMERUN_CONF_TMP
fi
echo "" >>$DVBHDHOMERUN_CONF_TMP
done
md5_1=$(md5sum -b $DVBHDHOMERUN_CONF_TMP | awk '{print $1}')
md5_2=$(md5sum -b $ADDON_HOME/dvbhdhomerun.conf | awk '{print $1}')
if [ "$md5_1" != "$md5_2" ]; then
# file changed - copy to addon home
cp $DVBHDHOMERUN_CONF_TMP $ADDON_HOME/dvbhdhomerun.conf
fi
fi
rm -f /tmp/dvbhdhomerun
if [ -f $ADDON_HOME/dvbhdhomerun.conf ]; then
ln -s $ADDON_HOME/dvbhdhomerun.conf /tmp/dvbhdhomerun
fi
# modules are not automatically loaded
modprobe dvb_hdhomerun
modprobe dvb_hdhomerun_fe
usleep 2000000
[ -z "$PRE_WAIT" ] && PRE_WAIT=0
PRE_WAIT=$(( $PRE_WAIT *1 ))
[ -z "$POST_WAIT" ] && POST_WAIT=0
POST_WAIT=$(( $POST_WAIT *1 ))
# could be useful
if [ -f $ADDON_HOME/pre-wait.sh ]; then
sh $ADDON_HOME/pre-wait.sh
fi
logger -t HDHomeRun "### Pre wait for $PRE_WAIT sec ###"
sleep $PRE_WAIT
mkdir -p /var/log/
rm -f /var/log/dvbhdhomerun.log
userhdhomerun -f
# how much time should we wait?
usleep 1000000
if [ -f $ADDON_HOME/post-wait.sh ]; then
sh $ADDON_HOME/post-wait.sh
fi
logger -t HDHomeRun "### Post wait for $POST_WAIT sec ###"
sleep $POST_WAIT
# save adapter names in background
(
@ -67,3 +125,5 @@ if [ -z "$(pidof userhdhomerun)" ]; then
fi
)&
fi
logger -t HDHomeRun "### HDHomeRun ready ###"

View File

@ -0,0 +1,161 @@
"""Pretty print an XML document.
LICENCE:
Copyright (c) 2008, Fredrik Ekholdt
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Fredrik Ekholdt nor the names of its contributors may be used to
endorse or promote products derived from this software without specific prior
written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE."""
import sys as _sys
import re as _re
def _usage(this_file):
return """SYNOPSIS: pretty print an XML document
USAGE: python %s <filename> \n""" % this_file
def _pprint_line(indent_level, line, width=100, output=_sys.stdout):
if line.strip():
start = ""
number_chars = 0
for l in range(indent_level):
start = start + " "
number_chars = number_chars + 1
try:
elem_start = _re.findall("(\<\W{0,1}\w+:\w+) ?", line)[0]
elem_finished = _re.findall("([?|\]\]/]*\>)", line)[0]
#should not have *
attrs = _re.findall("(\S*?\=\".*?\")", line)
output.write(start + elem_start)
number_chars = len(start + elem_start)
for attr in attrs:
if (attrs.index(attr) + 1) == len(attrs):
number_chars = number_chars + len(elem_finished)
if (number_chars + len(attr) + 1) > width:
output.write("\n")
for i in range(len(start + elem_start) + 1):
output.write(" ")
number_chars = len(start + elem_start) + 1
else:
output.write(" ")
number_chars = number_chars + 1
output.write(attr)
number_chars = number_chars + len(attr)
output.write(elem_finished + "\n")
except IndexError:
#give up pretty print this line
output.write(start + line + "\n")
def _pprint_elem_content(indent_level, line, output=_sys.stdout):
if line.strip():
for l in range(indent_level):
output.write(" ")
output.write(line + "\n")
def _get_next_elem(data):
start_pos = data.find("<")
end_pos = data.find(">") + 1
retval = data[start_pos:end_pos]
stopper = retval.rfind("/")
if stopper < retval.rfind("\""):
stopper = -1
single = (stopper > -1 and ((retval.find(">") - stopper) < (stopper - retval.find("<"))))
ignore_excl = retval.find("<!") > -1
ignore_question = retval.find("<?") > -1
if ignore_excl:
cdata = retval.find("<![CDATA[") > -1
if cdata:
end_pos = data.find("]]>")
if end_pos > -1:
end_pos = end_pos + len("]]>")
elif ignore_question:
end_pos = data.find("?>") + len("?>")
ignore = ignore_excl or ignore_question
no_indent = ignore or single
#print retval, end_pos, start_pos, stopper > -1, no_indent
return start_pos, \
end_pos, \
stopper > -1, \
no_indent
def get_pprint(xml, indent=4, width=80):
"""Returns the pretty printed xml """
class out:
output = ""
def write(self, string):
self.output += string
out = out()
pprint(xml, output=out, indent=indent, width=width)
return out.output
def pprint(xml, output=_sys.stdout, indent=4, width=80):
"""Pretty print xml.
Use output to select output stream. Default is sys.stdout
Use indent to select indentation level. Default is 4 """
data = xml
indent_level = 0
start_pos, end_pos, is_stop, no_indent = _get_next_elem(data)
while ((start_pos > -1 and end_pos > -1)):
_pprint_elem_content(indent_level, data[:start_pos].strip(),
output=output)
data = data[start_pos:]
if is_stop and not no_indent:
indent_level = indent_level - indent
_pprint_line(indent_level,
data[:end_pos - start_pos],
width=width,
output=output)
data = data[end_pos - start_pos:]
if not is_stop and not no_indent :
indent_level = indent_level + indent
if not data:
break
else:
start_pos, end_pos, is_stop, no_indent = _get_next_elem(data)
if __name__ == "__main__":
if "-h" in _sys.argv or "--help" in _sys.argv:
_sys.stderr.write(_usage(_sys.argv[0]))
_sys.exit(1)
if len(_sys.argv) < 2:
_sys.stderr.write(_usage(_sys.argv[0]))
_sys.exit(1)
else:
filename = _sys.argv[1]
fh = open(filename)
pprint(fh.read(), output=_sys.stdout, indent=4, width=80)

0
packages/addons/driver/hdhomerun/source/default.py Executable file → Normal file
View File

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<strings>
<string id="1000">General</string>
<string id="1020">Pre wait time [sec]</string>
<string id="1030">Post wait time [sec]</string>
<string id="9000">Tuner settings</string>
<string id="9005">Enable modifying settings</string>
<string id="9010">Refresh...</string>
<string id="9020"> use full name</string>
<string id="9030"> disabled</string>
</strings>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<settings>
<category label="1000" >
<setting type="sep" />
<setting id="PRE_WAIT" type="number" label="1020" default="2" />
<setting id="POST_WAIT" type="number" label="1030" default="1" />
</category>
<category label="9000">
<setting type="sep" />
<setting id="ENABLE_TUNER_TYPES" type="bool" label="9005" default="true" />
<setting label="9010" option="close" type="action" action="RunScript(/storage/.xbmc/addons/driver.dvb.hdhomerun/bin/refresh-tuners.py, false)" />
</category>
</settings>

View File

@ -23,22 +23,22 @@
. /etc/profile
LOCKDIR="/var/lock/"
LOCKFILE="hdhomerun"
LOCKFILE="$LOCKDIR/hdhomerun"
case "$1" in
hibernate|suspend)
if [ -n "$(pidof userhdhomerun)" ]; then
progress "Shutting down HDHomeRun driver for suspending..."
mkdir -p "$LOCKDIR"
touch "$LOCKDIR/$LOCKFILE"
touch "$LOCKFILE"
killall userhdhomerun
fi
;;
thaw|resume)
if [ -f "$LOCKDIR/$LOCKFILE" ]; then
if [ -f "$LOCKFILE" ]; then
# driver started within Tvheadend/VDR
rm -rf "$LOCKDIR/$LOCKFILE"
rm -f "$LOCKFILE"
fi
;;

View File

@ -1,3 +1,5 @@
3.0.3
added addon settings for modifying tuner type (DVB-C, DVB-T)
3.0.2
added addon settings
enable HW PID filter (enabled for RPi by default)

View File

@ -0,0 +1,32 @@
0x01 KEY_SELECT
0x02 KEY_3
0x03 KEY_EXIT
0x04 KEY_1
0x05 KEY_5
0x06 KEY_6
0x07 KEY_CHANNELDOWN
0x08 KEY_2
0x09 KEY_CHANNELUP
0x0a KEY_9
0x0b KEY_ZOOM
0x0c KEY_7
0x0d KEY_8
0x0e KEY_VOLUMEUP
0x0f KEY_4
0x10 KEY_BACK
0x11 KEY_0
0x12 KEY_ENTER
0x13 KEY_VOLUMEDOWN
0x14 KEY_RECORD
0x15 KEY_STOP
0x16 KEY_PLAY
0x17 KEY_MUTE
0x18 KEY_UP
0x19 KEY_DOWN
0x1a KEY_LEFT
0x1b KEY_RIGHT
0x1c KEY_RED
0x1d KEY_GREEN
0x1e KEY_YELLOW
0x1f KEY_BLUE
0x43 KEY_POWER

View File

@ -0,0 +1,32 @@
0x01 KEY_SELECT
0x02 KEY_3
0x03 KEY_EXIT
0x04 KEY_1
0x05 KEY_5
0x06 KEY_6
0x07 KEY_CHANNELDOWN
0x08 KEY_2
0x09 KEY_CHANNELUP
0x0a KEY_9
0x0b KEY_ZOOM
0x0c KEY_7
0x0d KEY_8
0x0e KEY_VOLUMEUP
0x0f KEY_4
0x10 KEY_BACK
0x11 KEY_0
0x12 KEY_OK
0x13 KEY_VOLUMEDOWN
0x14 KEY_RECORD
0x15 KEY_STOP
0x16 KEY_PLAY
0x17 KEY_MUTE
0x18 KEY_UP
0x19 KEY_DOWN
0x1a KEY_LEFT
0x1b KEY_RIGHT
0x1c KEY_RED
0x1d KEY_GREEN
0x1e KEY_YELLOW
0x1f KEY_BLUE
0x43 KEY_POWER

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

View File

@ -20,7 +20,7 @@
PKG_NAME="sundtek-mediatv"
PKG_VERSION="3.0"
PKG_REV="2"
PKG_REV="3"
PKG_ARCH="any"
PKG_LICENSE="nonfree"
PKG_SITE="http://support.sundtek.com/"

View File

@ -0,0 +1,172 @@
"""
################################################################################
# This file is part of OpenELEC - http://www.openelec.tv
# Copyright (C) 2009-2013 Stephan Raue (stephan@openelec.tv)
# Copyright (C) 2013 ultraman/vpeter
#
# 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, 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenELEC.tv; see the file COPYING. If not, write to
# the Free Software Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110, USA.
# http://www.gnu.org/copyleft/gpl.html
################################################################################
"""
import os
import sys
import shutil
import xmlpp
import xbmcaddon
from xml.dom import minidom
from array import array
__settings__ = xbmcaddon.Addon(id='driver.dvb.sundtek-mediatv')
__cwd__ = __settings__.getAddonInfo('path')
__mediaclient__ = xbmc.translatePath(os.path.join(__cwd__, 'bin', 'mediaclient'))
__ld_preload__ = xbmc.translatePath(os.path.join(__cwd__, 'lib', 'libmediaclient.so'))
__settings_xml__ = xbmc.translatePath(os.path.join(__cwd__, 'resources', 'settings.xml'))
__mediaclient_e__ = 'LD_PRELOAD=' + __ld_preload__ + ' ' + __mediaclient__ + ' -e'
# make backup settings only once
try:
with open(__settings_xml__ + '_orig') as f: pass
except IOError as e:
shutil.copyfile(__settings_xml__, __settings_xml__ + '_orig')
######################################################################################################
# get supported devices on a system (name, serial number, type)
tuners = []
p = os.popen(__mediaclient_e__, "r")
while 1:
line = p.readline()
if not line:
break
else:
str = line.strip()
if str.startswith('device '):
name = str[str.find("[")+1:str.find("]")]
tuners.append([name, 0, 's'])
if str.startswith('[SERIAL]:'):
line = p.readline()
str = line.strip()
if str.startswith('ID:'):
id = str.split(':');
id = id[1].strip()
tuners[len(tuners)-1] = [name, id, 's']
if str.startswith('[DVB-C]:'):
tuners[len(tuners)-1] = [name, id, 'c']
elif str.startswith('[DVB-T]:'):
tuners[len(tuners)-1] = [name, id, 'c']
elif str.startswith('[DVB-T2]:'):
tuners[len(tuners)-1] = [name, id, 'c']
"""
root ~ # mediaclient -e
**** List of Media Hardware Devices ****
device 0: [Sundtek MediaTV Pro (USB 2.0)] DVB-C, DVB-T, ANALOG-TV, FM-RADIO, REMOTE-CONTROL, OSS-AUDIO, RDS
[BUS]:
ID: 1-7
[SERIAL]:
ID: U110714145205
[DVB-C]:
FRONTEND: /dev/dvb/adapter0/frontend0
DVR: /dev/dvb/adapter0/dvr0
DMX: /dev/dvb/adapter0/demux0
[DVB-T]:
FRONTEND: /dev/dvb/adapter0/frontend0
DVR: /dev/dvb/adapter0/dvr0
DMX: /dev/dvb/adapter0/demux0
[ANALOG-TV]:
VIDEO0: /dev/video0
VBI0: /dev/vbi0
[FM-RADIO]:
RADIO0: /dev/radio0
RDS: /dev/rds0
[REMOTECONTROL]:
INPUT0: /dev/mediainput0
[OSS]:
OSS0: /dev/dsp0
"""
######################################################################################################
xmldoc = minidom.parse(__settings_xml__)
category = xmldoc.getElementsByTagName('category')
# remove all nodes with id started with ATTACHED_TUNER_
for node_cat in category:
setting = node_cat.getElementsByTagName('setting')
for node_set in setting :
if 'id' in node_set.attributes.keys() and not node_set.getAttribute('id').find('ATTACHED_TUNER_'):
node_set.parentNode.removeChild(node_set)
# add new ATTACHED_TUNER_ nodes for available tuners
for node_cat in category:
setting = node_cat.getElementsByTagName('setting')
for node_set in setting :
if 'label' in node_set.attributes.keys() and '9010' in node_set.getAttribute('label'):
for ix, tuner in enumerate(tuners):
tuner_name = tuner[0]
tuner_serial = tuner[1]
tuner_type = tuner[2]
node1 = xmldoc.createElement("setting")
node1.setAttribute("id", 'ATTACHED_TUNER_' + tuner_serial + '_DVBMODE')
node1.setAttribute("label", tuner_name + ", " + tuner_serial)
node1.setAttribute("type", 'labelenum')
if (tuner_type == 's'):
node1.setAttribute("default", 'DVB-S')
node1.setAttribute("values", 'DVB-S')
else:
node1.setAttribute("default", 'DVB-C')
node1.setAttribute("values", 'DVB-C|DVB-T')
node_cat.appendChild(node1)
node2 = xmldoc.createElement("setting")
node2.setAttribute("id", 'ATTACHED_TUNER_' + tuner_serial + '_IRPROT')
node2.setAttribute("label", '9020')
node2.setAttribute("type", 'labelenum')
node2.setAttribute("default", 'auto')
node2.setAttribute("values", 'auto|RC5|NEC|RC6')
node_cat.appendChild(node2)
node3 = xmldoc.createElement("setting")
node3.setAttribute("id", 'ATTACHED_TUNER_' + tuner_serial + '_KEYMAP')
node3.setAttribute("label", '9030')
node3.setAttribute("type", 'text')
node3.setAttribute("default", 'rc_key_ok')
node_cat.appendChild(node3)
# for tuner
break
######################################################################################################
# save file back
try:
outputfile=open(__settings_xml__, 'w')
xmlpp.pprint(xmldoc.toxml(), output=outputfile, indent=2)
outputfile.close()
except IOError:
print 'Error writing file ', __settings_xml__
######################################################################################################
# dialog is closed already so just open settings again
xbmcaddon.Addon(id='driver.dvb.sundtek-mediatv').openSettings()

View File

@ -46,7 +46,7 @@ else
if [ -z "$entry_set" ]; then
sed -i 's|^device_attach=.*|# device_attach not used anymore\n\n# enable HW PID filter\nuse_hwpidfilter=off\n\n# enable listening on network\nenablenetwork=off|g' $ADDON_HOME/sundtek.conf
sed -i 's|^#first_adapter=.*|first_adapter=0|g' $ADDON_HOME/sundtek.conf
sed -i 's|.*network tuner IP address (OpenELEC specific).*||g' $ADDON_HOME/sundtek.conf
sed -i 's|.*network_tuner_ip=.*||g' $ADDON_HOME/sundtek.conf
fi
@ -95,6 +95,7 @@ if [ ! -f $ADDON_DIR/bin/mediasrv ]; then
# enable HW PID filter on RPi by default
sed -i 's|^use_hwpidfilter=.*|use_hwpidfilter=on|g' $ADDON_DIR/config/sundtek.conf
sed -i 's|^use_hwpidfilter=.*|use_hwpidfilter=on|g' $ADDON_HOME/sundtek.conf
sed -i 's|.*id="ENABLE_HW_PID_FILTER".*|<setting id="ENABLE_HW_PID_FILTER" value="true" />|' $ADDON_DIR/settings-default.xml
sed -i 's|.*id="ENABLE_HW_PID_FILTER".*|<setting id="ENABLE_HW_PID_FILTER" value="true" />|' $ADDON_SETTINGS
else
logger -t Sundtek "### Unsupported architecture ###"
@ -214,7 +215,7 @@ if [ -z "$(pidof mediasrv)" ]; then
# remove empty lines at the end of file
sed -i '${/^$/d;}' $SUNDTEK_CONF_TMP
# add entries
echo "[NETWORK]" >>$SUNDTEK_CONF_TMP
echo -e "\n[NETWORK]" >>$SUNDTEK_CONF_TMP
for dev in $(seq 0 $DEVICE1_NUM); do
echo "device=$DEVICE1_IP:$dev" >>$SUNDTEK_CONF_TMP
done
@ -247,6 +248,53 @@ if [ -z "$(pidof mediasrv)" ]; then
sed -i '${/^$/d;}' $SUNDTEK_CONF_TMP
fi
if [ "$ENABLE_TUNER_TYPES" = "true" ]; then
# get tuner serial numbers
SERIALS=$(cat /var/config/sundtek-addon.conf | sed -n 's|^ATTACHED_TUNER_\(.*\)_DVBMODE=.*|\1|gp' | sort | uniq)
. /var/config/sundtek-addon.conf
for SERIAL in ${SERIALS[@]}; do
DVBMODE=$(eval echo \$ATTACHED_TUNER_${SERIAL}_DVBMODE)
IRPROT=$(eval echo \$ATTACHED_TUNER_${SERIAL}_IRPROT)
KEYMAP=$(eval echo \$ATTACHED_TUNER_${SERIAL}_KEYMAP)
if [ "$DVBMODE" = "DVB-T" ]; then
# only set DVB-T because default is DVB-C (and DVB-S is not set either)
DVBMODE="DVBT"
else
DVBMODE=""
fi
[ "$IRPROT" = "NEC" -o "$IRPROT" = "auto" ] && IRPROT=""
KEYMAP_FILE="$ADDON_HOME/$KEYMAP"
[ ! -f $KEYMAP_FILE ] && KEYMAP_FILE=""
# remove setttings for this tuner
awk -v val="[$SERIAL]" '$0 == val {flag=1; next} /^ir_protocol=|^rcmap=|^initial_dvb_mode=|^#|^$/{if (flag==1) next} /.*/{flag=0; print}' $SUNDTEK_CONF_TMP >${SUNDTEK_CONF_TMP}-types
mv ${SUNDTEK_CONF_TMP}-types $SUNDTEK_CONF_TMP
echo "" >>$SUNDTEK_CONF_TMP
# remove empty lines at the end of file
sed -i '${/^$/d;}' $SUNDTEK_CONF_TMP
ADDNEW=true
if [ -n "$DVBMODE" ]; then
[ $ADDNEW = true ] && ADDNEW=false && echo -e "\n[$SERIAL]" >>$SUNDTEK_CONF_TMP
echo "initial_dvb_mode=$DVBMODE" >>$SUNDTEK_CONF_TMP
fi
if [ -n "$IRPROT" ]; then
[ $ADDNEW = true ] && ADDNEW=false && echo -e "\n[$SERIAL]" >>$SUNDTEK_CONF_TMP
echo "ir_protocol=$IRPROT" >>$SUNDTEK_CONF_TMP
fi
if [ -n "$KEYMAP_FILE" ]; then
[ $ADDNEW = true ] && ADDNEW=false && echo -e "\n[$SERIAL]" >>$SUNDTEK_CONF_TMP
echo "rcmap=$KEYMAP_FILE" >>$SUNDTEK_CONF_TMP
fi
echo "" >>$SUNDTEK_CONF_TMP
done
fi
md5_1=$(md5sum -b $SUNDTEK_CONF_TMP | awk '{print $1}')
md5_2=$(md5sum -b $ADDON_HOME/sundtek.conf | awk '{print $1}')
if [ "$md5_1" != "$md5_2" ]; then

View File

@ -0,0 +1,161 @@
"""Pretty print an XML document.
LICENCE:
Copyright (c) 2008, Fredrik Ekholdt
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Fredrik Ekholdt nor the names of its contributors may be used to
endorse or promote products derived from this software without specific prior
written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE."""
import sys as _sys
import re as _re
def _usage(this_file):
return """SYNOPSIS: pretty print an XML document
USAGE: python %s <filename> \n""" % this_file
def _pprint_line(indent_level, line, width=100, output=_sys.stdout):
if line.strip():
start = ""
number_chars = 0
for l in range(indent_level):
start = start + " "
number_chars = number_chars + 1
try:
elem_start = _re.findall("(\<\W{0,1}\w+:\w+) ?", line)[0]
elem_finished = _re.findall("([?|\]\]/]*\>)", line)[0]
#should not have *
attrs = _re.findall("(\S*?\=\".*?\")", line)
output.write(start + elem_start)
number_chars = len(start + elem_start)
for attr in attrs:
if (attrs.index(attr) + 1) == len(attrs):
number_chars = number_chars + len(elem_finished)
if (number_chars + len(attr) + 1) > width:
output.write("\n")
for i in range(len(start + elem_start) + 1):
output.write(" ")
number_chars = len(start + elem_start) + 1
else:
output.write(" ")
number_chars = number_chars + 1
output.write(attr)
number_chars = number_chars + len(attr)
output.write(elem_finished + "\n")
except IndexError:
#give up pretty print this line
output.write(start + line + "\n")
def _pprint_elem_content(indent_level, line, output=_sys.stdout):
if line.strip():
for l in range(indent_level):
output.write(" ")
output.write(line + "\n")
def _get_next_elem(data):
start_pos = data.find("<")
end_pos = data.find(">") + 1
retval = data[start_pos:end_pos]
stopper = retval.rfind("/")
if stopper < retval.rfind("\""):
stopper = -1
single = (stopper > -1 and ((retval.find(">") - stopper) < (stopper - retval.find("<"))))
ignore_excl = retval.find("<!") > -1
ignore_question = retval.find("<?") > -1
if ignore_excl:
cdata = retval.find("<![CDATA[") > -1
if cdata:
end_pos = data.find("]]>")
if end_pos > -1:
end_pos = end_pos + len("]]>")
elif ignore_question:
end_pos = data.find("?>") + len("?>")
ignore = ignore_excl or ignore_question
no_indent = ignore or single
#print retval, end_pos, start_pos, stopper > -1, no_indent
return start_pos, \
end_pos, \
stopper > -1, \
no_indent
def get_pprint(xml, indent=4, width=80):
"""Returns the pretty printed xml """
class out:
output = ""
def write(self, string):
self.output += string
out = out()
pprint(xml, output=out, indent=indent, width=width)
return out.output
def pprint(xml, output=_sys.stdout, indent=4, width=80):
"""Pretty print xml.
Use output to select output stream. Default is sys.stdout
Use indent to select indentation level. Default is 4 """
data = xml
indent_level = 0
start_pos, end_pos, is_stop, no_indent = _get_next_elem(data)
while ((start_pos > -1 and end_pos > -1)):
_pprint_elem_content(indent_level, data[:start_pos].strip(),
output=output)
data = data[start_pos:]
if is_stop and not no_indent:
indent_level = indent_level - indent
_pprint_line(indent_level,
data[:end_pos - start_pos],
width=width,
output=output)
data = data[end_pos - start_pos:]
if not is_stop and not no_indent :
indent_level = indent_level + indent
if not data:
break
else:
start_pos, end_pos, is_stop, no_indent = _get_next_elem(data)
if __name__ == "__main__":
if "-h" in _sys.argv or "--help" in _sys.argv:
_sys.stderr.write(_usage(_sys.argv[0]))
_sys.exit(1)
if len(_sys.argv) < 2:
_sys.stderr.write(_usage(_sys.argv[0]))
_sys.exit(1)
else:
filename = _sys.argv[1]
fh = open(filename)
pprint(fh.read(), output=_sys.stdout, indent=4, width=80)

View File

@ -3,11 +3,12 @@
<string id="1000">General</string>
<string id="1011">Auto update binary driver</string>
<string id="1012">Enable analog TV</string>
<string id="1014">Extra settle time</string>
<string id="1014">Extra delay [sec]</string>
<string id="1015">Run user script</string>
<string id="1030">Enable hardware PID filter</string>
<string id="1035">Enable IR receiver</string>
<string id="1040">Lowest adapter number (/dev/dvb/adapterX/)</string>
<string id="2000">Networking</string>
<string id="2005">Share local tuner over network</string>
<string id="2010">Use network shared tuners</string>
@ -21,4 +22,10 @@
<string id="2051"> # of tuners</string>
<string id="2060">Server 5 IP address</string>
<string id="2061"> # of tuners</string>
<string id="9000">Tuner settings</string>
<string id="9005">Enable modifying settings</string>
<string id="9010">Refresh...</string>
<string id="9020"> IR protocol</string>
<string id="9030"> keymap filename</string>
</strings>

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<settings>
<category label="1000" >
<setting label="" type="lsep" />
<setting type="sep" />
<setting id="AUTO_UPDATE" type="bool" label="1011" default="false" />
<setting id="ANALOG_TV" type="bool" label="1012" default="false" enable="false" />
@ -12,7 +11,6 @@
<setting id="LOWEST_ADAPTER_NUM" type="number" label="1040" default="0" />
</category>
<category label="2000" >
<setting label="" type="lsep" />
<setting type="sep" />
<setting id="ALLOW_NET_USE" type="bool" label="2005" default="false" />
<setting id="USE_NET_TUNERS" type="bool" label="2010" default="false" />
@ -27,4 +25,9 @@
<setting id="DEVICE5_IP" type="ipaddress" label="2060" default="" visible="eq(-9,true)" />
<setting id="DEVICE5_NUM" type="labelenum" label="2061" default="1" values="1|5|4|3|2" visible="eq(-10,true)" />
</category>
<category label="9000">
<setting type="sep" />
<setting id="ENABLE_TUNER_TYPES" type="bool" label="9005" default="true" />
<setting label="9010" option="close" type="action" action="RunScript(/storage/.xbmc/addons/driver.dvb.sundtek-mediatv/bin/refresh-tuners.py, false)" />
</category>
</settings>

View File

@ -52,6 +52,15 @@ fi
# waiting for Xorg to start
wait_for_xorg
# wait for network
wait_for_inet_addr
# set cpu's to 'conservative'
( usleep 15000000
progress "set cpu's to 'ondemand'"
cpupower frequency-set -g ondemand > /dev/null 2>&1
)&
# prevent restrating XBMC at reboot or shutdown
LOCKDIR="/var/lock/"
LOCKFILE="xbmc.disabled"

View File

@ -0,0 +1,36 @@
################################################################################
# This file is part of OpenELEC - http://www.openelec.tv
# Copyright (C) 2009-2012 Stephan Raue (stephan@openelec.tv)
#
# 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, 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenELEC.tv; see the file COPYING. If not, write to
# the Free Software Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110, USA.
# http://www.gnu.org/copyleft/gpl.html
################################################################################
wait_for_inet_addr () {
if [ -f /var/config/settings.conf ]; then
. /var/config/settings.conf
fi
if [ "$WAIT_NETWORK" = "true" ] ; then
progress "Wait for network"
[ -z "$WAIT_NETWORK_TIME" ] && WAIT_NETWORK_TIME=10
LOOP_COUNT=$[$WAIT_NETWORK_TIME * 5]
for i in $(seq 1 $LOOP_COUNT) ; do
cnt=$(ifconfig | sed -e '/inet addr:/!d' -e '/127.0.0.1/d' |wc -l)
[ $cnt -gt 0 ] && break
usleep 200000
done
fi
}