def _create_uart_object(): ret_value = True for bus_name, bus in Profile.get_buses().iteritems(): try: if bus['bus'] == 'uart': device_path = bus['path'] if utility.mount_on_fpga(device_path): class_name = 'Axi4Uart' createok = XObject.create_object(bus_name, class_name, device_path) else: class_name = 'UartBus' createok = XObject.create_object(bus_name, class_name, device_path) if createok: logger.boot("create the %s uart object %s" % (bus_name, class_name)) else: logger.boot( "warning: can not find the %s uart class %s in this project code" % (bus_name, class_name)) ret_value = False except Exception as e: logger.boot("error: create %s uart object fail:\n%s" % (bus_name, traceback.format_exc())) ret_value = False return ret_value
def _parse_chips(self, module): chipname = module['id'] partno = module['partno'] method_name = 'parse_' + partno.lower() try: XObject.get_classes()[partno].parse_chip_profile( module, self._base_board_name) except AttributeError: logger.boot( 'warning: unable to parser the %s partno of the %s chip: has no the method %s' % (partno, chipname, method_name)) raise
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 uart_param_config(name, baud_rate, data_bits, parity, stop_bits, timestamp): """ Set uart bus parameter Args: baud_rate(int) : UART baud rate data_bits(int) : Data width 5/6/7/8 parity_type(str) : parity type. "ODD"/"EVNE"/"NONE" stop_bits(float) : stop bit width. 1/2 time_insert(str) : PL UART Insert timestamp Control, "TS"/"NONE" Returns: bool: True | False, True for success, False for adc read failed """ try: uart = XObject.get_object(name) isok = True if utility.mount_on_fpga(uart.name): uart.disable() uart.enable() uart.config(baud_rate, data_bits, parity, stop_bits, timestamp) else: isok = uart.config(baud_rate, data_bits, parity, stop_bits) return isok except Exception as e: logger.error("the %s uart param config execute error:%s" % (name, repr(e))) return False
def _parse_boards(self, board): initconfig = Profile.get_initconfig() initconfig['boards'] = initconfig.setdefault('boards', list()) board_name = board['id'] partno = board['partno'] partno_list = partno.replace('-', '_') method_name = 'parse_' + partno_list.lower() class_name = partno.replace('-', '') try: XObject.get_classes()[class_name].parse_board_profile(board) initconfig['boards'].append(board_name) except AttributeError: logger.boot( 'warning: unable to parser the %s partno of the %s board: has no the method %s' % (partno, board_name, method_name)) raise
def chip_dir_get_from_dev(name): chip = XObject.get_chip_object(name) if chip is not None: return chip.read_dir_config() # state = utility.list_convert_number(input_output_status) # return state else: return False
def __init__(self, uartname, port): super(UartServer, self).__init__() self._uartname = uartname self._port = port self._connect_socket = None self._uart_device = XObject.get_object(uartname) self._inputs = [] self._total_net_size = 0 self._total_uart_size = 0 self._uart_stop = False
def uart_close(uart_id): try: uart = XObject.get_object(uart_id) if utility.mount_on_fpga(uart.name): uart.disable() else: uart.close() return True except Exception as e: logger.error("close the %s uart error:%s" % (uart_id, repr(e))) return False
def eval(self, name, method, *args, **kwargs): try: obj = XObject.get_object(name) func = getattr(obj, method) if args: result = func(*args) elif kwargs: result = func(**kwargs) else: result = func() except Exception: logger.warning("%s" % (traceback.format_exc())) return result
def read(profile, addr, length): """ read data by the defined profile Args: profile: Dictionary of the hardware profile. addr: which addr will be write data in. length: Want to get the length of the data. Returns: list: success return datas which beed saved in a list. False otherwise. Raises: KeyError: If the key is invalid. """ eeprom = XObject.get_object(profile['partno'], profile) return eeprom.read(addr, length)
def write(profile, addr, data): """ write a list data by the defined profile Args: profile: Dictionary of the hardware profile. addr: which addr will be write data in. data: data type is list. Returns: bool: The return value. True for success, False otherwise. Raises: KeyError: If the key is invalid. """ eeprom = XObject.get_object(profile['partno'], profile) return eeprom.write(addr, data)
def _create_board_object(): ret_value = True for board_name, board_profile in Profile.get_boards().iteritems(): try: class_name = board_profile['partno'].replace('-', '') if XObject.create_object(board_name, class_name, board_profile): logger.boot('create the %s board object %s' % (board_name, class_name)) else: logger.boot( 'warning: can not find the %s board class %s in this project code' % (board_name, class_name)) ret_value = False except Exception as e: logger.boot("error: create %s board object fail:\n%s" % (board_name, traceback.format_exc())) ret_value = False return ret_value
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 measure_path_set(name, measurepath): '''Set the dmm board measure range Args: name:the dmm board's name measurepath:{"channel":channel,"range":range} channel:["current","voltage"] range: channel="current": range=("100uA","2mA") channel="voltage": range=("5V") Returns: bool: True | False, True for success, False for adc read failed ''' try: dmm = XObject.get_board_object(name) return dmm.measure_path_set(measurepath) except Exception as e: logger.error( "the %s board measure_path_set() measurepath:%s execute error: %s" % (name, str(measurepath), repr(e))) return False
def current_measure(name, measure_path=None): '''Get current measure channel result Args: name:the dmm board's name measure_path: default is None Returns: if success: result:(value,unit) value: current measure value unit: ('uA','mA','A') if fail: return False ''' try: dmm = XObject.get_board_object(name) return dmm.current_measure() except Exception as e: logger.error("the %s board current_measure() execute error: %s" % (name, repr(e))) return False
def calibration_work_mode_close(name): """The board work in normal mode,out of the calibration mode You need to out of the calibration mode, when you want to the result use the calibration parameters. The measure results of the return after calibration. Args: name: the dmm board's name Returns: bool: True | False, True for success, False for adc read failed """ try: dmm = XObject.get_board_object(name) dmm.calibration_work_mode_close() return True except Exception as e: logger.error( "the %s board calibration_work_mode_close() execute error: %s" % (name, repr(e))) return False
def measure_path_record(name, measure_path): """select board measure channel path,Just record Args: name: the dmm board's name measure_path:{"channle":channel,"range":range} channel:["current","voltage"] range: channel="current": range=("100uA","2mA") channel="voltage": range=("5V") Returns: bool: True | False, True for success, False for adc read failed """ try: dmm = XObject.get_board_object(name) return dmm.measure_path_record(measure_path) except Exception as e: logger.error("the %s board measure_path_record() execute error: %s" % (name, repr(e))) return False
def select_channel(channel_name): """ select which channel to operate Args: channel_name: which channel will be select, check it in profile. for example:'back-light Returns: object: return switch object. Raises: KeyError: If the key is invalid. ValueError: If the parameter is invalid """ busswitch = Profile.get_busswitch() chipname = busswitch[channel_name]['chip'] channel = busswitch[channel_name]['channel'] switcher = XObject.get_chip_object(chipname) if switcher.select_channel(channel) is False: logger.warning("select %s channel %s fail" % (chipname, channel_name)) return switcher
def measure_path_get(name): '''Get the dmm board measure range Args: name:the dmm board's name Returns: if success: dict: {"channel":value,"range":value} channel:["current","voltage"] range: channel="current": range=("100uA","2mA") channel="voltage": range=("5V") if fail: return False ''' try: dmm = XObject.get_board_object(name) return dmm.measure_path_get() except Exception as e: logger.error("the %s board measure_path_get() execute error: %s" % (name, repr(e))) return False
def calibration_work_mode_open(name): """ The board work in the calibration mode You need to enter the calibration mode, when you want to calibrate you results by other tools. The measure results of the return is original results, than you can use it to calculate the calibration parameters. Args: name: the dmm board's name Returns: bool: True | False, True for success, False for adc read failed """ try: dmm = XObject.get_board_object(name) dmm.calibration_work_mode_open() return True except Exception as e: logger.error( "the %s board calibration_work_mode_open() execute error: %s" % (name, repr(e))) return False
def _init_board(): ret_value = True initconfig = Profile.get_initconfig() for board_name in initconfig['boards']: try: obj = XObject.get_board_object(board_name) if obj is None: logger.boot('warning: can not find the %s object' % (board_name)) continue if obj.board_initial(): logger.boot('init the %s board success' % (board_name)) else: logger.boot('error: init the %s board fail' % (board_name)) ret_value = False except Exception: logger.boot('error: %s _init_board execute error:\n%s' % (board_name, traceback.format_exc())) ret_value = False return ret_value
def _init_uart(): ret_value = True initconfig = Profile.get_initconfig() for name, param in initconfig['uart'].iteritems(): try: obj = XObject.get_object(name) if obj is None: logger.boot("warning: can not find the %s uart object" % (name)) continue baudrate = int(param['baudrate']) databits = int(param['databits']) stopbits = int(param['stopbits']) parity = param['parity'].upper() if utility.mount_on_fpga(obj.name): timestamp = param['timestamp'].upper() obj.disable() obj.enable() ret = obj.config(baudrate, databits, parity, stopbits, timestamp) else: ret = obj.config(baudrate, databits, parity, stopbits) if ret is False: logger.boot("error: init the %s uart param:%s fail" % (name, param)) ret_value = False else: logger.boot("init the %s uart success, param:%s" % (name, param)) except Exception as e: logger.boot("error: %s _init_uart execute error:\n%s" % (name, traceback.format_exc())) ret_value = False return ret_value
time.sleep(1) gpio.write_value(0) time.sleep(1) if __name__ == '__main__': utility.register_signal_handle() ee_daemon = daemon.Daemon("ee") ee_daemon.start() logger.init("ee.log") logger.setLevel('WARNING') ''' 解决在xobj模块中引用chip和board类导致相互引用错误 ''' classes = globals() XObject.set_classes(classes) jsonfile = utility.get_profile_path() + "/Hardware_Function_Profile.json" parser = ProfileParser() ret = parser.read_profile(jsonfile) if ret is False: #print 'error parser profile fail' os._exit(ret) ret = ee.initializer.init() if ret is False: logger.boot("init project fail") #os._exit(ret) ee = EmbeddedEngine() led = Thread(target=led_flicker)
def test_get_class(): from ee.profile.xobj import XObject #assert len(XObject._objects.keys()) == 24 assert str(type( XObject.get_object("cp1"))) == "<class 'ee.chip.cat9555.CAT9555'>" assert str(type( XObject.get_object("cp2"))) == "<class 'ee.chip.cat9555.CAT9555'>" assert str(type( XObject.get_object("cp3"))) == "<class 'ee.chip.cat9555.CAT9555'>" assert str(type( XObject.get_object("cp4"))) == "<class 'ee.chip.cat9555.CAT9555'>" assert str(type( XObject.get_object("cp5"))) == "<class 'ee.chip.cat9555.CAT9555'>" assert str(type( XObject.get_object("cp6"))) == "<class 'ee.chip.cat9555.CAT9555'>" assert str(type( XObject.get_object("cp7"))) == "<class 'ee.chip.cat9555.CAT9555'>" assert str(type( XObject.get_object("cp8"))) == "<class 'ee.chip.cat9555.CAT9555'>" assert str(type(XObject.get_object( "dmm"))) == "<class 'ee.board.dmm001.dmm001001.Dmm001001'>" assert str(type(XObject.get_object("datalogger")) ) == "<class 'ee.board.scope002.scope002001A.Scope002001A'>" assert str(type(XObject.get_object( "freq"))) == "<class 'ee.board.vfreq001.vfreq001001.Vfreq001001'>" assert str(type(XObject.get_object( "voltage_output"))) == "<class 'ee.board.ins001.vvo001001.Vvo001001'>"
def chip_dir_set_to_dev(name, value): chip = XObject.get_chip_object(name) if chip is not None: return chip.write_dir_config(value) else: return False
def chip_set_to_dev(name, value): chip = XObject.get_chip_object(name) if chip is not None: return chip.write_outport(value) else: return False