def cb_success(image_version): if self.label_version != None: self.label_version.setText(image_version) m = re.match(r'(\d+)\.(\d+)\s+\((.+)\)', image_version) if m != None: try: self.image_version.number = (int(m.group(1)), int(m.group(2))) self.image_version.flavor = m.group(3) self.image_version.string = image_version # set this last, because it is used as validity check except: self.label_discovering.setText( 'Error: Could not parse Image Version: {0}'.format( image_version)) else: self.widget_discovering.hide() self.tab_widget.show() if self.plugin_state == PluginBase.PLUGIN_STATE_RUNNING: self.tab_widget_current_changed( self.tab_widget.currentIndex()) self.device_info.firmware_version_installed = self.image_version.number + ( 0, ) inventory.sync() else: self.label_discovering.setText( 'Error: Could not parse Image Version: {0}'.format( image_version)) if next_function != None: QTimer.singleShot(250, next_function)
def get_wifi2_firmware_version_async(self, ext, version): self.wifi2_firmware_version = version self.device_info.extensions[ext].firmware_version_installed = version # Start the plugin before sending the device_info_changed signal, so that # the slot registered to the signal will already see the plugin in self.extension_tabs. self.wifi2_start() inventory.sync()
def is_present_async(extension_type, name, present): self.extension_type_present[extension_type] = present if not present: return if self.device_info.extensions['ext0'] == None: ext = 'ext0' elif self.device_info.extensions['ext1'] == None: ext = 'ext1' else: return # This should never be the case self.device_info.extensions[ext] = ExtensionInfo() self.device_info.extensions[ext].name = name self.device_info.extensions[ext].extension_type = extension_type self.device_info.extensions[ext].position = ext self.device_info.extensions[ext].master_info = self.device_info if extension_type == self.master.EXTENSION_TYPE_WIFI2: self.device_info.extensions[ext].url_part = 'wifi_v2' self.device_info.extensions[ ext].update_firmware_version_latest() label = QLabel( 'Waiting for WIFI Extension 2.0 firmware version...') label.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) wrapper = QWidget() layout = QVBoxLayout(wrapper) layout.addWidget(label) layout.setContentsMargins(0, 0, 0, 0) self.wifi2_tab_idx = self.tab_widget.addTab( wrapper, 'WIFI 2.0') # When WIFI2 extension firmware version is being requested the # extension might still not be done with booting and thus the # message won't be received by the extension. So we delay sending # the request which gives enough time to the extension to finish # booting. Note that this delay is only induced when there is a # WIFI2 extension present. async_call(self.master.get_wifi2_firmware_version, None, functools.partial( self.get_wifi2_firmware_version_async, ext), self.increase_error_count, delay=2.0) inventory.sync()
def bindings_version_success(self, result): okay, message = check_script_result(result) if not okay: get_main_window().show_status( 'Failed to query RED Brick bindings versions: ' + message, message_id='red_bindings_version_success_error') return try: versions = json.loads(result.stdout) except Exception as e: get_main_window().show_status( 'Failed to parse RED Brick bindings versions as JSON: ' + str(e), message_id='red_bindings_version_success_error') return get_main_window().hide_status('red_bindings_version_success_error') self.device_info.bindings_infos = [] for url_part, version in versions['bindings'].items(): bindings_info = BindingsInfo() bindings_info.name = get_bindings_name(url_part) bindings_info.url_part = url_part bindings_info.firmware_version_installed = tuple( int(i) for i in version.split('.')) bindings_info.update_firmware_version_latest() self.device_info.bindings_infos.append(bindings_info) brickv_info = ToolInfo() brickv_info.name = 'Brick Viewer' brickv_info.url_part = 'brickv' brickv_info.firmware_version_installed = tuple( int(i) for i in versions['brickv'].split('.')) brickv_info.update_firmware_version_latest() self.device_info.brickv_info = brickv_info inventory.sync()
def cb_file_read(ext, result): red_file[ext].release() self.completed_counter += 1 if result.error == None: config = config_parser.parse(result.data.decode('utf-8')) try: t = int(config['type']) except: t = 0 names = { 1: 'Chibi Extension', 2: 'RS485 Extension', 3: 'WIFI Extension', 4: 'Ethernet Extension', 5: 'WIFI Extension 2.0' } name = names[t] if t in names else 'Unknown' extension = 'ext' + str(ext) self.device_info.extensions[ext] = ExtensionInfo() self.device_info.extensions[ext].name = name self.device_info.extensions[ ext].extension_type = name + ' Extension' self.device_info.extensions[ext].position = extension self.device_info.extensions[ext].master_info = self.device_info self.extension_configs.append((ext, config)) inventory.sync() if self.completed_counter == len(red_file): self.tab_extension.extension_query_finished( self.extension_configs) if next_function != None: QTimer.singleShot(250, next_function)
def cb_enumerate(self, uid, connected_uid, position, hardware_version, firmware_version, device_identifier, enumeration_type): if self.ipcon.get_connection_state( ) != IPConnection.CONNECTION_STATE_CONNECTED: # ignore enumerate callbacks that arrived after the connection got closed return if enumeration_type in [ IPConnection.ENUMERATION_TYPE_AVAILABLE, IPConnection.ENUMERATION_TYPE_CONNECTED ]: device_info = inventory.get_info(uid) # If the enum_type is CONNECTED, the bricklet was restarted externally. # The plugin could now be in an inconsistent state. if enumeration_type == IPConnection.ENUMERATION_TYPE_CONNECTED and device_info is not None: if device_info.connected_uid != connected_uid: # Fix connections if bricklet was connected to another brick. parent_info = inventory.get_info(device_info.connected_uid) if parent_info is not None: parent_info.connections_remove_item( (device_info.position, device_info)) self.show_status( "Hot plugging is not supported! Please reset Brick with UID {} and reconnect Brick Viewer." .format(device_info.connected_uid), message_id='mainwindow_hotplug') device_info.reverse_connection = connected_uid elif device_info.position != position: # Bricklet was connected to the same brick, but to another port self.show_status( "Hot plugging is not supported! Please reset Brick with UID {} and reconnect Brick Viewer." .format(device_info.connected_uid), message_id='mainwindow_hotplug') # If the plugin is not running, pause will do nothing, so it is always save to call it. # The plugin will be (unconditionally) resumed later, as resume also only does something # if it was paused before (e.g. here). if device_info.plugin is not None: device_info.plugin.pause_plugin() if device_info == None: if device_identifier == BrickMaster.DEVICE_IDENTIFIER: device_info = BrickMasterInfo() elif device_identifier == BrickRED.DEVICE_IDENTIFIER: device_info = BrickREDInfo() elif hat_brick_supported and device_identifier == BrickHAT.DEVICE_IDENTIFIER: device_info = BrickHATInfo() elif hat_zero_brick_supported and device_identifier == BrickHATZero.DEVICE_IDENTIFIER: device_info = BrickHATZeroInfo() elif device_identifier == BrickletIsolator.DEVICE_IDENTIFIER: device_info = BrickletIsolatorInfo() elif str(device_identifier).startswith('20'): device_info = TNGInfo() elif '0' <= position <= '9': device_info = BrickInfo() else: device_info = BrickletInfo() position = position.lower() device_info.uid = uid device_info.connected_uid = connected_uid device_info.position = position device_info.hardware_version = hardware_version if device_identifier != BrickRED.DEVICE_IDENTIFIER: device_info.firmware_version_installed = firmware_version device_info.device_identifier = device_identifier device_info.enumeration_type = enumeration_type # Update connections and reverse_connection with new device for info in inventory.get_device_infos(): if info == device_info: continue def add_to_connections(info_to_add, connected_info): hotplug = connected_info.connections_add_item( (info_to_add.position, info_to_add)) info_to_add.reverse_connection = connected_info # '0' is the port where other stacks connected by RS485 extensions are connected. Multiple connections are allowed here. if hotplug and info_to_add.position != '0': self.show_status( "Hot plugging is not supported! Please reset Brick with UID {} and reconnect Brick Viewer." .format(connected_info.uid), message_id='mainwindow_hotplug') if info.uid != '' and info.uid == device_info.connected_uid: if device_info in info.connections_values( ): # device was already connected, but to another port info.connections_remove_value(device_info) if device_info not in info.connections_get( device_info.position): add_to_connections(device_info, info) if info.connected_uid != '' and info.connected_uid == device_info.uid: if info in device_info.connections_values( ): # device was already connected, but to another port device_info.connections_remove_value(info) if info not in device_info.connections_get(info.position): add_to_connections(info, device_info) if device_info.plugin == None: self.plugin_manager.create_plugin_instance( device_identifier, self.ipcon, device_info) device_info.tab_window = self.create_tab_window( device_info, self.ipcon) device_info.tab_window.setWindowFlags(Qt.Widget) device_info.tab_window.tab() inventory.add_info(device_info) device_info.update_firmware_version_latest() inventory.sync() # The plugin was paused before if it was reconnected. device_info.plugin.resume_plugin() elif enumeration_type == IPConnection.ENUMERATION_TYPE_DISCONNECTED: self.remove_device_tab(uid)
def get_connection_type_async(connection_type): self.device_info.connection_type = connection_type inventory.sync()