fix blindscan blindscan and add firmwareupgrade plugin
authorkos <kos@dev3>
Fri, 9 Dec 2011 04:21:56 +0000 (13:21 +0900)
committerkos <kos@dev3>
Fri, 9 Dec 2011 04:21:56 +0000 (13:21 +0900)
configure.ac
lib/python/Plugins/SystemPlugins/Blindscan/plugin.py
lib/python/Plugins/SystemPlugins/FirmwareUpgrade/Makefile.am [new file with mode: 0644]
lib/python/Plugins/SystemPlugins/FirmwareUpgrade/__init__.py [new file with mode: 0644]
lib/python/Plugins/SystemPlugins/FirmwareUpgrade/_fu.so [new file with mode: 0644]
lib/python/Plugins/SystemPlugins/FirmwareUpgrade/fu.py [new file with mode: 0644]
lib/python/Plugins/SystemPlugins/FirmwareUpgrade/meta/Makefile.am [new file with mode: 0644]
lib/python/Plugins/SystemPlugins/FirmwareUpgrade/meta/plugin_firmwareupgrade.xml [new file with mode: 0644]
lib/python/Plugins/SystemPlugins/FirmwareUpgrade/plugin.py [new file with mode: 0644]
lib/python/Plugins/SystemPlugins/Makefile.am

index 5ca12a5..242f2d8 100644 (file)
@@ -244,6 +244,8 @@ lib/python/Plugins/SystemPlugins/HDMICEC/components/Makefile
 lib/python/Plugins/SystemPlugins/HDMICEC/meta/Makefile
 lib/python/Plugins/SystemPlugins/LEDBrightnessSetup/Makefile
 lib/python/Plugins/SystemPlugins/LEDBrightnessSetup/meta/Makefile
+lib/python/Plugins/SystemPlugins/FirmwareUpgrade/Makefile
+lib/python/Plugins/SystemPlugins/FirmwareUpgrade/meta/Makefile
 lib/python/Tools/Makefile
 lib/service/Makefile
 lib/components/Makefile
index c456f26..fb22f1e 100644 (file)
@@ -20,7 +20,7 @@ from enigma import eTimer, eDVBFrontendParametersSatellite, eComponentScan, eDVB
 
 class Blindscan(ConfigListScreen, Screen):
        skin="""
-               <screen name="Blindscan" position="center,center" size="560,290" title="Blindscan">
+               <screen name="Blindscan" position="center,center" size="560,370" title="Blindscan">
                        <ePixmap pixmap="Vu_HD/buttons/red.png" position="5,0" size="80,40" alphatest="on" />
                        <ePixmap pixmap="Vu_HD/buttons/green.png" position="186,0" size="80,40" alphatest="on" />
                        <ePixmap pixmap="Vu_HD/buttons/blue.png" position="372,0" size="80,40" alphatest="on" />
@@ -29,8 +29,8 @@ class Blindscan(ConfigListScreen, Screen):
                        <widget source="key_green" render="Label" position="213,0" zPosition="1" size="160,30" font="Regular;20" halign="center" valign="center" transparent="1"/>
                        <widget source="key_blue" render="Label" position="400,0" zPosition="1" size="160,30" font="Regular;20" halign="center" valign="center" transparent="1"/>
 
-                       <widget name="config" position="5,50" size="550,200" scrollbarMode="showOnDemand" />
-                       <widget name="introduction" position="0,265" size="560,20" font="Regular;20" halign="center" />
+                       <widget name="config" position="5,50" size="550,280" scrollbarMode="showOnDemand" />
+                       <widget name="introduction" position="0,345" size="560,20" font="Regular;20" halign="center" />
                </screen>
                """
        def __init__(self, session): 
@@ -43,6 +43,8 @@ class Blindscan(ConfigListScreen, Screen):
                for slot in nimmanager.nim_slots:
                        if slot.isCompatible("DVB-S"):
                                self.satList.append(nimmanager.getSatListForNim(slot.slot))
+                       else:
+                               self.satList.append(None)
 
                # make config
                self.createConfig()
@@ -61,7 +63,7 @@ class Blindscan(ConfigListScreen, Screen):
                                "cancel": self.keyCancel,
                        }, -2)
                        self["key_red"] = StaticText(_("Exit"))
-                       self["key_green"] = StaticText("Start")
+                       self["key_green"] = StaticText("Scan")
                        self["key_blue"] = StaticText("Scan All")
                        self["introduction"] = Label(_("Press Green/OK to start the scan"))
                        self.createSetup()
@@ -79,6 +81,17 @@ class Blindscan(ConfigListScreen, Screen):
                        self["key_blue"] = StaticText(" ")
                        self["introduction"] = Label(_("Please setup your tuner configuration."))
 
+               self.i2c_mapping_table = None
+               self.makeNimSocket()
+
+       def makeNimSocket(self):
+               self.i2c_mapping_table = {0:2, 1:3, 2:1, 3:0}
+
+       def getNimSocket(self, slot_number):
+               if slot_number < 0 or slot_number > 3:
+                       return -1
+               return self.i2c_mapping_table[slot_number]
+
        def keyNone(self):
                None
        def callbackNone(self, *retval):
@@ -150,6 +163,8 @@ class Blindscan(ConfigListScreen, Screen):
                self.blindscan_stop_frequency = ConfigInteger(default = 2150*1000000)
                self.blindscan_start_symbol = ConfigInteger(default = 2*1000000)
                self.blindscan_stop_symbol = ConfigInteger(default = 45*1000000)
+               self.scan_clearallservices = ConfigYesNo(default = False)
+               self.scan_onlyfree = ConfigYesNo(default = False)
 
                # collect all nims which are *not* set to "nothing"
                nim_list = []
@@ -162,8 +177,8 @@ class Blindscan(ConfigListScreen, Screen):
                                root_id = nimmanager.sec.getRoot(n.slot_id, int(n.config.connectedTo.value))
                                if n.type == nimmanager.nim_slots[root_id].type: # check if connected from a DVB-S to DVB-S2 Nim or vice versa
                                        continue
-                       nim_list.append((str(n.slot), n.friendly_full_description))
-
+                       if n.isCompatible("DVB-S"):
+                               nim_list.append((str(n.slot), n.friendly_full_description))
                self.scan_nims = ConfigSelection(choices = nim_list)
 
                # sat
@@ -185,6 +200,17 @@ class Blindscan(ConfigListScreen, Screen):
                                self.scan_satselection.append(getConfigSatlist(defaultSat["orbpos"], self.satList[slot.slot]))
                return True
 
+       def getSelectedSatIndex(self, v):
+               index    = 0
+               none_cnt = 0
+               for n in self.satList:
+                       if self.satList[index] == None:
+                               none_cnt = none_cnt + 1
+                       if index == int(v):
+                               return (index-none_cnt)
+                       index = index + 1
+               return -1
+
        def createSetup(self):
                self.list = []
                self.multiscanlist = []
@@ -203,13 +229,15 @@ class Blindscan(ConfigListScreen, Screen):
 
                self.scan_networkScan.value = False
                if nim.isCompatible("DVB-S") :
-                       self.list.append(getConfigListEntry(_('Satellite'), self.scan_satselection[index_to_scan]))
+                       self.list.append(getConfigListEntry(_('Satellite'), self.scan_satselection[self.getSelectedSatIndex(index_to_scan)]))
                        self.list.append(getConfigListEntry(_('Scan start frequency'), self.blindscan_start_frequency))
                        self.list.append(getConfigListEntry(_('Scan stop frequency'), self.blindscan_stop_frequency))
                        self.list.append(getConfigListEntry(_("Polarity"), self.scan_sat.polarization))
                        self.list.append(getConfigListEntry(_("Scan band"), self.blindscan_hi))
                        self.list.append(getConfigListEntry(_('Scan start symbolrate'), self.blindscan_start_symbol))
                        self.list.append(getConfigListEntry(_('Scan stop symbolrate'), self.blindscan_stop_symbol))
+                       self.list.append(getConfigListEntry(_("Clear before scan"), self.scan_clearallservices))
+                       self.list.append(getConfigListEntry(_("Only Free scan"), self.scan_onlyfree))
                        self["config"].list = self.list
                        self["config"].l.setList(self.list)
                        
@@ -271,8 +299,9 @@ class Blindscan(ConfigListScreen, Screen):
                self.tmp_tplist=[]
                tmp_pol = []
                tmp_band = []
-               tmp_list=[self.satList[0][self.scan_satselection[0].index]]
-               
+               idx_selected_sat = int(self.getSelectedSatIndex(self.scan_nims.value))
+               tmp_list=[self.satList[int(self.scan_nims.value)][self.scan_satselection[idx_selected_sat].index]]
+
                if self.blindscan_hi.value == "hi_low" :
                        tmp_band=["low","high"]
                else:
@@ -288,16 +317,16 @@ class Blindscan(ConfigListScreen, Screen):
        def keyGoAll(self):
                if self.checkSettings() == False:
                        return
-
                self.tmp_tplist=[]
                tmp_list=[]
                tmp_band=["low","high"]
                tmp_pol=["horizontal","vertical"]
+               
                for slot in nimmanager.nim_slots:
-                       if slot.isCompatible("DVB-S"):
-                               for s in self.satList[slot.slot]:
+                       device_name = "/dev/dvb/adapter0/frontend%d" % (slot.slot)
+                       if slot.isCompatible("DVB-S") and int(self.scan_nims.value) == slot.slot:
+                               for s in self.satList[slot.slot]:
                                        tmp_list.append(s)
-
                self.doRun(tmp_list, tmp_pol, tmp_band)
                
        def doRun(self, tmp_list, tmp_pol, tmp_band):
@@ -375,7 +404,11 @@ class Blindscan(ConfigListScreen, Screen):
                                         0)
                self.tuner.tune(returnvalue)
 
-               cmd = "vuplus_blindscan %d %d %d %d %d %d %d" % (self.blindscan_start_frequency.value/1000000, self.blindscan_stop_frequency.value/1000000, self.blindscan_start_symbol.value/1000000, self.blindscan_stop_symbol.value/1000000, tab_pol[pol], tab_hilow[band], self.feid)
+               if self.getNimSocket(self.feid) < 0:
+                       print "can't find i2c number!!"
+                       return
+
+               cmd = "vuplus_blindscan %d %d %d %d %d %d %d %d" % (self.blindscan_start_frequency.value/1000000, self.blindscan_stop_frequency.value/1000000, self.blindscan_start_symbol.value/1000000, self.blindscan_stop_symbol.value/1000000, tab_pol[pol], tab_hilow[band], self.feid, self.getNimSocket(self.feid))
                print "prepared command : [%s]" % (cmd)
                self.blindscan_container = eConsoleAppContainer()
                self.blindscan_container.appClosed.append(self.blindscanContainerClose)
@@ -434,6 +467,8 @@ class Blindscan(ConfigListScreen, Screen):
                self.blindscan_session.close(True)
 
        def blindscanContainerAvail(self, str):
+               print str
+               #if str.startswith("OK"):
                self.full_data = self.full_data + str
 
        def blindscanSessionNone(self, *val):
@@ -469,7 +504,15 @@ class Blindscan(ConfigListScreen, Screen):
 
        def startScan(self, tlist, feid, networkid = 0):
                self.scan_session = None
-               self.session.open(ServiceScan, [{"transponders": tlist, "feid": feid, "flags": 0, "networkid": networkid}])
+
+               flags = 0
+               if self.scan_clearallservices.value:
+                       flags |= eComponentScan.scanRemoveServices
+               else:
+                       flags |= eComponentScan.scanDontRemoveUnscanned
+               if self.scan_onlyfree.value:
+                       flags |= eComponentScan.scanOnlyFree
+               self.session.open(ServiceScan, [{"transponders": tlist, "feid": feid, "flags": flags, "networkid": networkid}])
 
 def main(session, **kwargs):
        session.open(Blindscan)
diff --git a/lib/python/Plugins/SystemPlugins/FirmwareUpgrade/Makefile.am b/lib/python/Plugins/SystemPlugins/FirmwareUpgrade/Makefile.am
new file mode 100644 (file)
index 0000000..e47942c
--- /dev/null
@@ -0,0 +1,7 @@
+installdir = $(pkglibdir)/python/Plugins/SystemPlugins/FirmwareUpgrade
+
+SUBDIRS = meta
+
+install_PYTHON = __init__.py \
+                plugin.py
+
diff --git a/lib/python/Plugins/SystemPlugins/FirmwareUpgrade/__init__.py b/lib/python/Plugins/SystemPlugins/FirmwareUpgrade/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/lib/python/Plugins/SystemPlugins/FirmwareUpgrade/_fu.so b/lib/python/Plugins/SystemPlugins/FirmwareUpgrade/_fu.so
new file mode 100644 (file)
index 0000000..32b39c0
Binary files /dev/null and b/lib/python/Plugins/SystemPlugins/FirmwareUpgrade/_fu.so differ
diff --git a/lib/python/Plugins/SystemPlugins/FirmwareUpgrade/fu.py b/lib/python/Plugins/SystemPlugins/FirmwareUpgrade/fu.py
new file mode 100644 (file)
index 0000000..1cc0778
--- /dev/null
@@ -0,0 +1,92 @@
+# This file was automatically generated by SWIG (http://www.swig.org).
+# Version 1.3.39
+#
+# Do not make changes to this file unless you know what you are doing--modify
+# the SWIG interface file instead.
+# This file is compatible with both classic and new-style classes.
+
+from sys import version_info
+if version_info >= (2,6,0):
+    def swig_import_helper():
+        from os.path import dirname
+        import imp
+        fp = None
+        try:
+            fp, pathname, description = imp.find_module('_fu', [dirname(__file__)])
+        except ImportError:
+            import _fu
+            return _fu
+        if fp is not None:
+            try:
+                _mod = imp.load_module('_fu', fp, pathname, description)
+            finally:
+                fp.close()
+                return _mod
+    _fu = swig_import_helper()
+    del swig_import_helper
+else:
+    import _fu
+del version_info
+try:
+    _swig_property = property
+except NameError:
+    pass # Python < 2.2 doesn't have 'property'.
+def _swig_setattr_nondynamic(self,class_type,name,value,static=1):
+    if (name == "thisown"): return self.this.own(value)
+    if (name == "this"):
+        if type(value).__name__ == 'SwigPyObject':
+            self.__dict__[name] = value
+            return
+    method = class_type.__swig_setmethods__.get(name,None)
+    if method: return method(self,value)
+    if (not static) or hasattr(self,name):
+        self.__dict__[name] = value
+    else:
+        raise AttributeError("You cannot add attributes to %s" % self)
+
+def _swig_setattr(self,class_type,name,value):
+    return _swig_setattr_nondynamic(self,class_type,name,value,0)
+
+def _swig_getattr(self,class_type,name):
+    if (name == "thisown"): return self.this.own()
+    method = class_type.__swig_getmethods__.get(name,None)
+    if method: return method(self)
+    raise AttributeError(name)
+
+def _swig_repr(self):
+    try: strthis = "proxy of " + self.this.__repr__()
+    except: strthis = ""
+    return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
+
+try:
+    _object = object
+    _newclass = 1
+except AttributeError:
+    class _object : pass
+    _newclass = 0
+
+
+class FU(_object):
+    __swig_setmethods__ = {}
+    __setattr__ = lambda self, name, value: _swig_setattr(self, FU, name, value)
+    __swig_getmethods__ = {}
+    __getattr__ = lambda self, name: _swig_getattr(self, FU, name)
+    __repr__ = _swig_repr
+    def __init__(self): 
+        this = _fu.new_FU()
+        try: self.this.append(this)
+        except: self.this = this
+    def getStatus(self): return _fu.FU_getStatus(self)
+    def getInterval(self): return _fu.FU_getInterval(self)
+    def checkError(self): return _fu.FU_checkError(self)
+    def getErrorMessage(self, *args): return _fu.FU_getErrorMessage(self, *args)
+    def startUpgrade(self, *args): return _fu.FU_startUpgrade(self, *args)
+    def getDataPath(self): return _fu.FU_getDataPath(self)
+    def getDevicePath(self): return _fu.FU_getDevicePath(self)
+    __swig_destroy__ = _fu.delete_FU
+    __del__ = lambda self : None;
+FU_swigregister = _fu.FU_swigregister
+FU_swigregister(FU)
+
+
+
diff --git a/lib/python/Plugins/SystemPlugins/FirmwareUpgrade/meta/Makefile.am b/lib/python/Plugins/SystemPlugins/FirmwareUpgrade/meta/Makefile.am
new file mode 100644 (file)
index 0000000..42b7bc7
--- /dev/null
@@ -0,0 +1,3 @@
+installdir = $(datadir)/meta
+
+dist_install_DATA = plugin_firmwareupgrade.xml
diff --git a/lib/python/Plugins/SystemPlugins/FirmwareUpgrade/meta/plugin_firmwareupgrade.xml b/lib/python/Plugins/SystemPlugins/FirmwareUpgrade/meta/plugin_firmwareupgrade.xml
new file mode 100644 (file)
index 0000000..46d7b4f
--- /dev/null
@@ -0,0 +1,16 @@
+<default>
+         <prerequisites>
+                    <tag type="System" />
+         </prerequisites>
+          <info>
+                    <author>oskwon</author>
+                    <name>FirmwareUpgrade</name>
+                    <packagename>enigma2-plugin-systemplugins-firmwareupgrade</packagename>
+                    <shortdescription>Upgrade your system Firmware</shortdescription>
+                    <description>Upgrade your internal system Firmware.</description>
+          </info>
+
+         <files type="package"> <!-- without version, without .ipk -->
+               <file type="package" name="enigma2-plugin-systemplugins-firmwareupgrade" />
+       </files>
+</default>
diff --git a/lib/python/Plugins/SystemPlugins/FirmwareUpgrade/plugin.py b/lib/python/Plugins/SystemPlugins/FirmwareUpgrade/plugin.py
new file mode 100644 (file)
index 0000000..ff593de
--- /dev/null
@@ -0,0 +1,555 @@
+import os, urllib
+from urllib import urlretrieve
+
+from Plugins.Plugin import PluginDescriptor
+
+from Components.config import config, getConfigListEntry, ConfigSubsection, ConfigText, ConfigSelection, ConfigYesNo,ConfigText
+from Components.ConfigList import ConfigListScreen
+from Components.ActionMap import ActionMap
+from Components.Sources.StaticText import StaticText
+from Components.Pixmap import Pixmap
+from Components.Label import Label
+
+from Components.FileList import FileList 
+from Components.Slider import Slider
+
+from Screens.Screen import Screen
+from Screens.MessageBox import MessageBox
+
+from enigma import ePoint, eConsoleAppContainer, eTimer
+from Tools.Directories import resolveFilename, SCOPE_PLUGINS
+
+fwlist = None
+fwdata = None
+if os.path.exists("/proc/stb/info/vumodel"):
+       vumodel = open("/proc/stb/info/vumodel")
+       info = vumodel.read().strip()
+       vumodel.close()
+
+       if info == "ultimo":
+               fwlist= [
+                        ("fp", _("Front Processor"))
+                       ,("fpga", _("FPGA"))
+                       ]
+               fwdata= { 
+                        "fp"   : ["http://archive.vuplus.com/download/fp", "fp.files", "/dev/bcm_mu;"]
+                       ,"fpga" : ["http://archive.vuplus.com/download/fpga", "fpga.files", "/dev/fpga_dp;/dev/misc/dp;"]
+                       }
+       elif info == "uno":
+               fwlist= [
+                       ("fpga", _("FPGA"))
+                       ]
+               fwdata= { 
+                       "fpga" : ["http://archive.vuplus.com/download/fpga", "fpga.file", "/dev/fpga_dp;/dev/misc/dp;"]
+                       }
+
+class UpgradeStatus(Screen):
+       skin =  """
+               <screen position="center,center" size="450,100" title=" ">
+                       <widget name="name" position="10,0" size="430,20" font="Regular;18" halign="left" valign="bottom"/>
+                       <widget name="slider" position="10,25" size="430,30" backgroundColor="white"/>
+                       <widget name="status" position="10,25" zPosition="1" size="430,30" font="Regular;18" halign="center" valign="center" foregroundColor="black" backgroundColor="black" transparent="1"/>
+                       <widget source="info" render="Label" position="10,70" zPosition="1" size="430,30" font="Regular;22" halign="center" valign="center" backgroundColor="#a08500" transparent="1"/>
+               </screen>
+               """
+
+       def __init__(self, session, parent, firmware, datafile, device):
+               Screen.__init__(self,session)
+               self.session = session
+
+               self["actions"] = ActionMap(["OkCancelActions"],
+                {
+                       "ok": self.keyExit,
+                }, -1)
+
+               self.firmware = firmware
+               self.datafile = datafile
+               #print "[FirmwareUpgrade] - [%s][%s][%s]" % (self.datafile, firmware, device)
+
+               self["name"] = Label(_(" "))
+               self["info"] = StaticText(_("Can't cancel during upgrade!!"))
+
+               self["status"] = Label(_("Status : 0%"))
+
+               self.slider = Slider(0, 100)
+               self["slider"] = self.slider
+
+               self.callback = None
+
+               self.setTitle(firmware.upper() + " Upgrade Status")
+
+               import fu
+               self.FU = fu.FU()
+
+               self.old_status   = 0
+               self.status_exit  = None
+               self.check_status = eTimer()
+               self.check_status.callback.append(self.cbCheckStatus)
+               self.check_status.start(self.FU.getInterval())
+
+               self.exitTimerCallCount = 0;
+               self.upgradeLock = True
+               self.FU.startUpgrade(self.datafile, device, firmware)
+
+       def cbCheckStatus(self):
+               errmsg = ""
+               errno  = self.FU.checkError()
+               if errno:
+                       self.check_status.stop()
+                       errmsg = self.FU.getErrorMessage(errno, errmsg)
+                       print "[FirmwareUpgrade] - ERROR : [%d][%s]" % (errno, errmsg)
+                       self.session.open(MessageBox, _(errmsg), MessageBox.TYPE_INFO, timeout = 10)
+                       self.cbConfirmExit(False)
+                       return
+               status = self.FU.getStatus()
+               if self.old_status > status:
+                       self.session.open(MessageBox, _("Fail to upgrade!! Retry!!"), MessageBox.TYPE_INFO, timeout = 10)
+               self.slider.setValue(status)
+               self["status"].setText(_("%d / 100" % (status)))
+               if status == 100:
+                       self.check_status.stop()
+                       self["status"].setText(_("Success. Press OK to exit."))
+                       self.status_exit = eTimer()
+                       self.status_exit.callback.append(self.cbTimerExit)
+                       self.status_exit.start(1000)
+                       self.upgradeLock = False
+               self.old_status = status
+
+       def setCallback(self, cb):
+               self.callback = cb
+
+       def cbTimerExit(self):
+               if self.exitTimerCallCount < 10: # exit after 10 sec.
+                       self.exitTimerCallCount = self.exitTimerCallCount + 1
+                       self.setTitle("%s Upgrade Status (%d)" % (self.firmware.upper(), 10-self.exitTimerCallCount))
+                       return
+               if self.status_exit is not None:
+                       self.status_exit.stop()
+               self.keyExit()
+
+       def cbConfirmExit(self, ret):
+               if ret:
+                       os.system("rm -f %s %s.md5" % (self.datafile, self.datafile))
+               self.close()
+
+       def keyExit(self):
+               if self.upgradeLock:
+                       return
+               if self.callback is not None:
+                       self.callback("Reboot now for a successful upgrade.", True)
+               self.session.openWithCallback(self.cbConfirmExit, MessageBox, _("Do you want to remove binary data?"), MessageBox.TYPE_YESNO, timeout = 10, default = False)
+
+class Filebrowser(Screen):
+       skin =  """
+               <screen position="center,center" size="500,260" title="File Browser" >
+                       <ePixmap pixmap="Vu_HD/buttons/blue.png" position="5,7" size="80,40" alphatest="blend" />
+                       <widget source="key_blue" render="Label" position="40,0" zPosition="1" size="180,40" font="Regular;20" halign="left" valign="center" transparent="1"/>
+                       <widget name="file_list" position="0,50" size="500,160" scrollbarMode="showOnDemand" />
+
+                       <widget source="status" render="Label" position="0,220" zPosition="1" size="500,40" font="Regular;18" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
+                </screen>
+               """
+
+       def __init__(self, session, parent, firmware):
+               Screen.__init__(self, session)
+                self.session = session 
+               
+               self["key_blue"] = StaticText(_("Download"))
+
+               self["status"]    = StaticText(_(" "))
+               self["file_list"] = FileList("/", matchingPattern = "^.*")
+
+               self["actions"] = ActionMap(["OkCancelActions", "ShortcutActions", "WizardActions", "ColorActions", ],
+                {
+                       "ok":     self.onClickOk,
+                       "cancel": self.onClickCancel,
+                       "blue":   self.onClickBlue,
+                       "up":     self.onClickUp,
+                       "down":   self.onClickDown,
+                       "left":   self.onClickLeft,
+                       "right":  self.onClickRight,
+                }, -1) 
+
+               self.resetGUI()
+               self.firmware = firmware
+
+               self.callback = None
+               self.timer_downloading = None
+
+               self.downloadLock = False
+               self.setTitle(firmware.upper() + " File Browser")
+
+       def resetGUI(self):
+               self["status"].setText("Select to press OK, Exit to press Cancel.")
+
+       def setCallback(self, func):
+               self.callback = func
+
+       def onClickOk(self):
+               if self.downloadLock:
+                       return
+
+               if self["file_list"].canDescent() : # isDir
+                       self["file_list"].descent()
+                       return
+
+               # verify data
+               self.gbin = self["file_list"].getCurrentDirectory() + self["file_list"].getFilename()
+               if not os.path.exists(self.gbin):
+                       self.session.open(MessageBox, _("Can't found binary file."), MessageBox.TYPE_INFO, timeout = 10)
+                       return
+               if not os.path.exists(self.gbin+".md5"):
+                       self.session.open(MessageBox, _("Can't found MD5 file."), MessageBox.TYPE_INFO, timeout = 10)
+                       return
+               try:
+                       def checkExt(ext):
+                               name_ext = os.path.splitext(self["file_list"].getFilename())
+                               return len(name_ext)==2 and ext.startswith(name_ext[1])
+                       self.check_ext = False
+                       if (self.firmware == "fp" and checkExt(".bin")) or (self.firmware == "fpga" and checkExt(".dat")):
+                               self.check_ext = True
+                       if self.check_ext == False:
+                               self.session.open(MessageBox, _("You chose the incorrect file."), MessageBox.TYPE_INFO)
+                               return
+               except:
+                       self.session.open(MessageBox, _("You chose the incorrect file."), MessageBox.TYPE_INFO)
+                       return
+
+               if os.path.exists("/usr/bin/md5sum") == False:
+                       self.session.open(MessageBox, _("Can't find /usr/bin/md5sum"), MessageBox.TYPE_INFO, timeout = 10)
+                       return
+               md5sum_A = os.popen("md5sum %s | awk \'{print $1}\'"%(self.gbin)).readline().strip()
+               md5sum_B = os.popen("cat %s.md5 | awk \'{print $1}\'"%(self.gbin)).readline().strip()
+               #print "[FirmwareUpgrade] - Verify : file[%s], md5[%s]"%(md5sum_A,md5sum_B)
+
+               if md5sum_A != md5sum_B:
+                       self.session.open(MessageBox, _("Fail to verify data file. \nfile[%s]\nmd5[%s]"%(md5sum_A,md5sum_B)), MessageBox.TYPE_INFO, timeout = 10)
+                       return 
+
+               if self.callback is not None:
+                       self.callback(_(self.gbin))
+               self.close()
+
+       def onClickCancel(self):
+               self.close()
+
+       # uri : source file url(string)
+       # tf  : target file name(string)
+       # bd  : target base directory(string)
+       # cbfunc(string) : callback function(function)
+       def doDownload(self, uri, tf, bd='/tmp', cbfunc=None):
+               tar = bd + "/" + tf
+               #print "[FirmwareUpgrade] - Download Info : [%s][%s]" % (uri, tar)
+               def doHook(blockNumber, blockSize, totalSize) :
+                       if blockNumber*blockSize > totalSize and cbfunc is not None:
+                               cbfunc(tar)
+               opener = urllib.URLopener()
+               try:
+                       opener.open(uri)
+               except:
+                       self.session.open(MessageBox, _("File not found in this URL:\n%s"%(uri)), MessageBox.TYPE_INFO, timeout = 10)
+                       del opener
+                       return False
+               try :
+                       f, h = urlretrieve(uri, tar, doHook)
+               except IOError, msg:
+                       self.session.open(MessageBox, _(str(msg)), MessageBox.TYPE_INFO, timeout = 10)
+                       del opener
+                       return False
+               del opener
+               return True
+
+       def runDownloading(self) :
+               self.timer_downloading.stop()
+               machine = str(open("/proc/stb/info/vumodel").read().strip())
+
+               def cbDownloadDone(tar):
+                       try:
+                               if os.path.splitext(tar)[1] != ".files":
+                                       self["status"].setText("Downloaded : %s\nSelect to press OK, Exit to press Cancel."%(tar))
+                       except:
+                               pass
+               # target
+               global fwdata
+               root_uri  = fwdata[self.firmware][0]
+               root_file = fwdata[self.firmware][1]
+               if not self.doDownload("%s/%s"%(root_uri, root_file), root_file, cbfunc=cbDownloadDone):
+                       self.resetGUI()
+                       self.downloadLock = False
+                       return
+
+               target_path = ""
+               for l in file("/tmp/"+root_file).readlines():
+                       if l.startswith(machine):
+                               try:
+                                       target_path = l.split("=")[1].strip()
+                               except:
+                                       target_path = ""
+                                       pass
+               if target_path == "":
+                       self.session.open(MessageBox, _("Firmware does not exist."), MessageBox.TYPE_INFO)
+                       self.resetGUI()
+                       self.downloadLock = False
+                       return
+
+               self.guri = "%s/vu%s/%s"%(root_uri, machine, target_path)
+               self.gbin = os.path.basename(target_path)
+               #print "[FirmwareUpgrade] - uri[%s], data[%s], data_path[%s]" % (self.gbin, self.guri, target_path)
+               os.system("rm -f /tmp/" + root_file)
+
+               # md5
+               if not self.doDownload(self.guri+".md5", self.gbin+".md5", cbfunc=cbDownloadDone):
+                       self.resetGUI()
+                       self.downloadLock = False
+                       return
+               # data
+               if not self.doDownload(self.guri, self.gbin, cbfunc=cbDownloadDone):
+                       self.resetGUI()
+                       self.downloadLock = False
+                       return
+
+               t = ''
+               self["file_list"].changeDir("/tmp/")
+               self["file_list"].moveToIndex(0)
+               while cmp(self["file_list"].getFilename(), self.gbin) != 0 :
+                       self["file_list"].down()
+                       if cmp(t, self["file_list"].getFilename()) == 0:
+                               break
+                       t = self["file_list"].getFilename()
+
+               del self.timer_downloading
+               self.timer_downloading = None
+               self.downloadLock = False
+
+       def onClickBlue(self):
+               if self.downloadLock:
+                       return
+               self.downloadLock = True
+               if not os.path.exists("/proc/stb/info/vumodel"):
+                       self.session.open(MessageBox, _("Can't found model name."), MessageBox.TYPE_INFO, timeout = 10)
+                       self.downloadLock = False
+                       return
+               self["status"].setText("Please wait during download.")
+               self.timer_downloading = eTimer()
+               self.timer_downloading.callback.append(self.runDownloading)
+               self.timer_downloading.start(1000)
+
+       def onClickUp(self):
+               if self.downloadLock:
+                       return
+               self.resetGUI()
+               self["file_list"].up()
+
+       def onClickDown(self):
+               if self.downloadLock:
+                       return
+               self.resetGUI()
+               self["file_list"].down()
+
+       def onClickLeft(self):
+               if self.downloadLock:
+                       return
+               self.resetGUI()
+               self["file_list"].pageUp()
+
+       def onClickRight(self):
+               if self.downloadLock:
+                       return
+               self.resetGUI()
+               self["file_list"].pageDown()
+
+       def keyNone(self):
+               None
+
+class FirmwareUpgrade(Screen, ConfigListScreen):
+       skin =  """
+               <screen position="center,center" size="560,175" title="Firmware Upgrade" >
+                       <ePixmap pixmap="Vu_HD/buttons/red.png" position="125,7" size="80,40" alphatest="blend" />
+                       <ePixmap pixmap="Vu_HD/buttons/green.png" position="330,7" size="80,40" alphatest="blend" />
+
+                       <widget source="key_red" render="Label" position="160,0" zPosition="1" size="155,40" font="Regular;20" halign="left" valign="center" transparent="1" />
+                       <widget source="key_green" render="Label" position="365,0" zPosition="1" size="155,40" font="Regular;20" halign="left" valign="center" transparent="1" />
+
+                       <widget name="config" zPosition="2" position="0,50" itemHeight="36" size="540,40" scrollbarMode="showOnDemand" transparent="1" />
+                       <widget source="status" render="Label" position="0,100" zPosition="1" size="540,75" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
+                </screen>
+               """
+
+       def __init__(self, session): 
+               Screen.__init__(self, session)
+                self.session = session 
+
+               self["shortcuts"] = ActionMap(["ShortcutActions", "SetupActions" ],
+               {
+                       "ok":      self.keyGreen,
+                       "cancel":  self.keyRed,
+                       "red":     self.keyRed,
+                       "green":   self.keyGreen,
+                       "blue":    self.keyBlue,
+               }, -2)
+
+               self.list = []
+               self.updateFilePath = ""
+
+               self.rebootLock = False
+               self.rebootMessage = ""
+               self.cbRebootCallCount = 0;
+
+               ConfigListScreen.__init__(self, self.list, session=self.session)
+               self["key_red"] = StaticText(_("Close"))
+
+               self.logmode = None
+               self.old_blue_clicked = 0
+               self.fileopenmode = False
+               self.upgrade_auto_run_timer = eTimer()
+               self.upgrade_auto_run_timer.callback.append(self.keyGreen)
+
+               global fwlist
+               if fwlist is None:
+                       self["key_green"] = StaticText(_(" "))
+                       self["status"] = StaticText(_("This plugin is supported only the Ultimo/Uno."))
+               else:
+                       self["key_green"] = StaticText(_("Upgrade"))
+                       self["status"] = StaticText(_(" "))
+                       self.setupUI()
+
+       def setupUI(self):
+               global fwlist
+               self.list = []
+               self._item_firmware  = ConfigSelection(default=fwlist[0][0],  choices=fwlist)
+               self._entry_firmware = getConfigListEntry(_("Firmware"), self._item_firmware)
+               self.list.append(self._entry_firmware)
+               self["config"].list = self.list
+               self["config"].l.setList(self.list)
+               self.setupStatus()
+
+       def setupStatus(self,message=None,reboot=False):
+               self.updateFilePath = ""
+               if message is not None:
+                       self.rebootLock = reboot
+                       self["status"].setText(message)
+                       if reboot:
+                               self.rebootMessage = message
+                               self.reboot_timer = eTimer()
+                               self.reboot_timer.callback.append(self.cbReboot)
+                               self.reboot_timer.start(500)
+                       return
+               if not self.rebootLock:
+                       self["status"].setText("Press the Green/OK button")
+
+       def cbReboot(self):
+               if self.cbRebootCallCount < 6:
+                       self.cbRebootCallCount = self.cbRebootCallCount + 1
+                       self["status"].setText("%s (%d)"%(self.rebootMessage, 6-self.cbRebootCallCount))
+                       return
+               from Screens.Standby import TryQuitMainloop
+               self.session.open(TryQuitMainloop, 2)
+
+       # filebrowser window callback function
+       def cbSetStatus(self, data=None):
+               if data is not None:
+                       self["status"].setText("Press the Green/OK button, if you want to upgrade to this file:\n%s\n" % (data))
+                       self.updateFilePath = data
+                       if self.fileopenmode == False:
+                               self.upgrade_auto_run_timer.start(1000)
+
+       # upgrade window callback function
+       def cbFinishedUpgrade(self,message=None,reboot=False):
+               self.setupStatus(message=message,reboot=reboot)
+
+       def cbRunUpgrade(self, ret):
+               if ret == False:
+                       return
+
+               if self.updateFilePath == "":
+                       self.session.open(MessageBox, _("No selected binary data!!"), MessageBox.TYPE_INFO, timeout = 10)
+                       return
+               device = None
+               for d in fwdata[self._item_firmware.value][2].split(';'):
+                       if os.path.exists(d):
+                               device = d                      
+               if device is None:
+                       self.session.open(MessageBox, _("Can't found device file!!"), MessageBox.TYPE_INFO, timeout = 10)
+                       return
+               fbs = self.session.open(UpgradeStatus, self, self._item_firmware.value, self.updateFilePath, device)
+               fbs.setCallback(self.cbFinishedUpgrade)
+       
+       def doFileOpen(self):
+               fbs = self.session.open(Filebrowser, self, self._item_firmware.value)
+               fbs.setCallback(self.cbSetStatus)
+
+       def keyLeft(self):
+               if self.rebootLock:
+                       return
+               global fwlist
+               if fwlist is None:
+                       return
+               ConfigListScreen.keyLeft(self)
+               self.setupStatus()
+
+       def keyRight(self):
+               global fwlist
+               if fwlist is None:
+                       return
+               ConfigListScreen.keyRight(self)
+               self.setupStatus()
+
+       def keyGreen(self):
+               self.upgrade_auto_run_timer.stop()
+               if self.rebootLock:
+                       return
+               global fwlist
+               if fwlist is None:
+                       return
+               if self.updateFilePath == "":
+                       #self.session.open(MessageBox, _("No selected binary data!!"), MessageBox.TYPE_INFO)
+                       self.doFileOpen()
+                       return
+               msg = "You should not be stop during the upgrade.\nDo you want to upgrade?"
+               self.session.openWithCallback(self.cbRunUpgrade, MessageBox, _(msg), MessageBox.TYPE_YESNO, timeout = 15, default = True)
+               self.fileopenmode = False
+
+       def keyYellow(self):
+               if self.rebootLock:
+                       return
+               global fwlist
+               if fwlist is None:
+                       return
+               self.fileopenmode = True
+               self.doFileOpen()
+
+       def keyRed(self):
+               if self.rebootLock:
+                       return
+               self.close()
+
+       def cbLogMode(self):
+               if self.old_blue_clicked:
+                       return
+               self.logmode.stop()
+               if os.path.exists("/tmp/onlogmode"):
+                       return
+               os.system("touch /tmp/onlogmode")
+
+       def keyBlue(self):
+               if self.rebootLock:
+                       return
+               if self.logmode is not None and self.old_blue_clicked == 0:
+                       return
+               if self.old_blue_clicked:
+                       self.old_blue_clicked = 0
+                       return
+               self.old_blue_clicked = 1
+               self.logmode = eTimer()
+               self.logmode.callback.append(self.cbLogMode)
+               self.logmode.start(1000)
+               
+       def keyNone(self):
+               None
+
+def main(session, **kwargs):
+        session.open(FirmwareUpgrade)
+                                                           
+def Plugins(**kwargs):            
+       return PluginDescriptor(name=_("Firmware Upgrade"), description="Upgrade Firmware..", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=main)
+
index a5c4b50..802e6cc 100755 (executable)
@@ -5,7 +5,7 @@ SUBDIRS = SoftwareManager FrontprocessorUpgrade PositionerSetup Satfinder \
        DefaultServicesScanner NFIFlash DiseqcTester CommonInterfaceAssignment \
        CrashlogAutoSubmit CleanupWizard VideoEnhancement WirelessLan NetworkWizard \
        TempFanControl FactoryTest Fancontrol FPGAUpgrade WirelessLanSetup ManualFancontrol \
-       Blindscan RemoteControlCode UI3DSetup UIPositionSetup HDMICEC LEDBrightnessSetup
+       Blindscan RemoteControlCode UI3DSetup UIPositionSetup HDMICEC LEDBrightnessSetup FirmwareUpgrade
 
 install_PYTHON =       \
        __init__.py