lpcmanager

d0ed0039ea38
Parents 3350ed098c70
Children 4782e9507f71
Added support for remote updating DTB, kernel and rootfs images.
  • +142 -8
    LPCManager.py
  • --- a/LPCManager.py Fri Jun 19 20:18:11 2015 +0200
    +++ b/LPCManager.py Thu Jul 30 15:04:59 2015 +0200
    @@ -104,14 +104,14 @@
    from controls import TextCtrlAutoComplete
    havecanfestival = False
    -#try:
    -from canfestival import RootClass as CanOpenRootClass
    -from canfestival.canfestival import _SlaveCTN, _NodeListCTN, NodeManager
    -from canfestival.NetworkEditor import NetworkEditor
    -from canfestival.SlaveEditor import SlaveEditor
    -havecanfestival = True
    -#except:
    -# havecanfestival = False
    +try:
    + from canfestival import RootClass as CanOpenRootClass
    + from canfestival.canfestival import _SlaveCTN, _NodeListCTN, NodeManager
    + from canfestival.NetworkEditor import NetworkEditor
    + from canfestival.SlaveEditor import SlaveEditor
    + havecanfestival = True
    +except:
    + havecanfestival = False
    SCROLLBAR_UNIT = 10
    WINDOW_COLOUR = wx.Colour(240,240,240)
    @@ -360,6 +360,11 @@
    "shown" : False,
    "tooltip" : _("Disconnect from PLC"),
    "method" : "_Disconnect"},
    + {"bitmap" : "UpdateFw",
    + "name" : _("UpdateFw"),
    + "shown" : True,
    + "tooltip" : _("Update the PLC firmware"),
    + "method" : "_UpdateFw"},
    ]
    _MethodFromPLCState["Disconnected"] += [("_Connect", True),
    ("_Disconnect", False)]
    @@ -394,6 +399,9 @@
    self.SimulationBuildPath = None
    self.AbortTransferTimer = None
    +
    + # Firmware update running status
    + self.firmawreUpadateIsRunning = False
    def GetProjectInfos(self):
    infos = PLCControler.GetProjectInfos(self)
    @@ -974,6 +982,132 @@
    self.logger.write_error(_("Couldn't start PLC !\n"))
    self.UpdateMethodsFromPLCStatus()
    + def _UpdateFw(self):
    + """
    + Method called by user to flash the firmware of the PLC
    + """
    + from dialogs import FirmwareUpdateDialog
    + from dialogs import DiscoveryDialog
    + from HostFirmwareUpdater import HostFirmwareUpdater
    +
    + if self.firmawreUpadateIsRunning == True:
    + self.logger.write_error(_("Firmware update is already running!\n"))
    + return
    +
    + self.firmawreUpadateIsRunning = True
    + self.logger.write(_("Firmware update started\n"))
    +
    + # Launch the firmware selection dialog
    + dialog = FirmwareUpdateDialog(self.AppFrame)
    + answer = dialog.ShowModal()
    + imageFilePath = dialog.GetFirmwareImageFile()
    + updateType = dialog.GetFirmwareUpdateType()
    + chunksSize = dialog.GetChunksSize()
    + reboot = dialog.GetReboot()
    + dialog.Destroy()
    +
    + if answer == wx.ID_CANCEL:
    + self.logger.write_error(_("Firmware update canceled!\n"))
    + self.firmawreUpadateIsRunning = False
    + return
    +
    + if imageFilePath == None or imageFilePath == "":
    + self.logger.write_error(_("No firmware image file selected!\n"))
    + self.logger.write_error(_("Firmware update canceled!\n"))
    + self.firmawreUpadateIsRunning = False
    + return
    + else:
    + self.logger.write(_("Firmware image file: %s\n")%imageFilePath)
    +
    + if updateType == 1:
    + self.logger.write(_("Firmware update type: Linux kernel image\n"))
    + elif updateType == 2:
    + self.logger.write(_("Firmware update type: Linux DTB image\n"))
    + elif updateType == 3:
    + self.logger.write(_("Firmware update type: Root file system image\n"))
    + else:
    + self.logger.write_error(_("Unknown firmware update type!\n"))
    + self.logger.write_error(_("Firmware update canceled!\n"))
    + self.firmawreUpadateIsRunning = False
    + return
    +
    + if chunksSize < 1024 or chunksSize > 1024*1024:
    + self.logger.write_error(_("Bad chunks size : %d KiB!\n")%chunksSize)
    + self.logger.write_error(_("Firmware update canceled!\n"))
    + self.firmawreUpadateIsRunning = False
    + return
    + else:
    + self.logger.write(_("Chunks size : %d KiB\n")%chunksSize)
    +
    + self.logger.write(_("Reboot after update : %s\n")%("Yes" if reboot else "No"))
    + # Get the target PLC URI
    + # Check if an uri is already configured in the Beremiz project
    + uri = self.BeremizRoot.getURI_location()
    + if uri is not None and uri != "":
    + self.logger.write(_("PLC URI configured in the Beremiz project will be used: %s\n")%uri)
    + else:
    + # PLC URI is not configured in the Beremiz project
    + # Launch Service Discovery dialog
    + self.logger.write(_("PLC URI is not configured in the Beremiz project. Launching the Discover dialog\n"))
    + dialog = DiscoveryDialog(self.AppFrame)
    + answer = dialog.ShowModal()
    + uri = dialog.GetURI()
    + dialog.Destroy()
    +
    + # Nothing choosed or cancel button
    + if uri is None or answer == wx.ID_CANCEL:
    + self.logger.write_error(_("Connection canceled!\n"))
    + self.logger.write_error(_("Firmware update canceled!\n"))
    + self.firmawreUpadateIsRunning = False
    + return
    +
    + # Get connector from uri
    + self._connector = None
    + try:
    + self._SetConnector(connectors.ConnectorFactory(uri, self))
    + except Exception:
    + self.logger.write_error(_("Exception while connecting %s!\n")%uri)
    + self.logger.write_error(traceback.format_exc())
    + self.logger.write_error(_("Firmware update canceled!\n"))
    + self.firmawreUpadateIsRunning = False
    + return
    +
    + # Did connection success ?
    + if self._connector is None:
    + # Oups.
    + self.logger.write_error(_("Connection failed to %s!\n")%uri)
    + self.logger.write_error(_("Firmware update canceled!\n"))
    + self.firmawreUpadateIsRunning = False
    + return
    + else:
    + self.logger.write(_("Connected.\n"))
    +
    + # Last confirmation before firmware update
    + answer = wx.MessageBox(_('Are you sure to launch the firmware update for the selected PLC?'),
    + _('Firmware Update'), wx.YES_NO | wx.CENTRE |wx.NO_DEFAULT,
    + self.AppFrame)
    + if answer != wx.YES:
    + self.logger.write_error(_("Firmware update canceled!\n"))
    + self.firmawreUpadateIsRunning = False
    + return
    + # Some cosmetics
    + self.AppFrame.Refresh()
    + self.AppFrame.Update()
    +
    + # Lauch the firmaware update on the remote PLC
    + updater = HostFirmwareUpdater(self._connector, imageFilePath, updateType, chunksSize, reboot, self.logger)
    + try:
    + updater.update()
    + except Exception as e:
    + self.logger.write_error(str(e) + "\n")
    + self.logger.write_error(_("Firmware update canceled!\n"))
    + self.firmawreUpadateIsRunning = False
    + self._Disconnect()
    + return
    + self._Disconnect()
    + self.firmawreUpadateIsRunning = False
    + return True
    +
    #-------------------------------------------------------------------------------
    # LPCBeremiz Class
    #-------------------------------------------------------------------------------