def test_read_profile(jsonfile): classes = globals() XObject.set_classes(classes) parser = ProfileParser() parser.read_profile(jsonfile) boards = Profile.get_boards() boards[power_profile['id']] = power_profile assert len(Profile.get_extendio()) == 1 assert len(Profile.get_busswitch()) == 9 assert len(Profile.get_eeprom()) == 8 assert len(Profile.get_boards()) == 5 assert len(Profile.get_buses()) == 8 assert len(Profile.get_chips()) == 12
def _create_chip_object(): ret_value = True for chip_name, profile in Profile.get_chips().iteritems(): try: partno = profile['partno'] if XObject.create_object(chip_name, partno, profile): logger.boot('create the %s chip object %s' % (chip_name, partno)) else: logger.boot( 'warning: can not find the %s chip class %s in this project code' % (chip_name, partno)) ret_value = False except Exception as e: logger.boot('error: create %s chip object fail:\n%s' % (chip_name, traceback.format_exc())) ret_value = False return ret_value
def parse_chip_profile(chip_profile, board_name): chipname = chip_profile['id'] extendios = Profile.get_extendio() extendios[board_name] = extendios.setdefault(board_name, OrderedDict()) extendio = extendios[board_name] extendio[chipname] = dict() extendio[chipname]['bus'] = Profile.get_bus_path(chip_profile['bus']) extendio[chipname]['addr'] = int(chip_profile['addr'], 16) extendio[chipname]['partno'] = chip_profile['partno'] extendio[chipname]['switch_channel'] = chip_profile['switch_channel'] chips = Profile.get_chips() chips[chipname] = extendio[chipname] bit_values = 0 bit_dir = 0 dir_value = {'input': 1, 'output': 0} for pin in chip_profile['property']: pinname = pin['id'] extendio[pinname] = dict() extendio[pinname]['pin'] = pin['pin'] extendio[pinname]['chip'] = chipname if 'default' in pin.keys(): bit_values |= (int(pin['default']) << (int(pin['pin']) - 1)) if 'dir' in pin.keys(): bit_dir |= (dir_value[pin['dir']] << (int(pin['pin']) - 1)) value_list = [] dir_list = [] for x in xrange(len(chip_profile['property']) / 8): value_list.append((bit_values >> (x * 8)) & 0xff) dir_list.append((bit_dir >> (x * 8)) & 0xff) initconfig = Profile.get_initconfig() initconfig['extendio'] = initconfig.setdefault('extendio', OrderedDict()) initconfig['extendio'][board_name] = initconfig['extendio'].setdefault( board_name, OrderedDict()) initconfig['extendio'][board_name][chipname] = dict(dir=dir_list, value=value_list)
def parse_chip_profile(chip_profile, board_name): """ Profile: { #public "id":string, "partno":"DemoChip", #private "init_msg":string } """ logger.error("chip_profile %s, board_name %s" % (chip_profile, board_name)) chip_name = chip_profile['id'] chips = Profile.get_chips() chips[chip_name] = dict() chips[chip_name]["init_msg"] = chip_profile["init_msg"] chips[chip_name]['partno'] = chip_profile['partno'] logger.error("chips = %s" % chips)