def parse_board_profile(board): ''' "DATALOGGER": { "id": "DATALOGGER", "partno": "Scope-002-001", "daq_channel":[ {"ch": 0, "alias": "volt", "port": 7603}, {"ch": 1, "alias": "current", "port": 7604} ], "adc": {"partno": "AD7175", "path": "/dev/AXI4_DATALOGGER_AD7177"}, "eeprom": {"partno": "CAT24C08", "bus": "EEPROM_IIC", "switch_channel": "Datalogger-1", "addr": "0x53"} } ''' board_name = board['id'] boards = Profile.get_boards() boards[board_name] = dict() boards[board_name]['id'] = board_name boards[board_name]['partno'] = board['partno'] boards[board_name]['adc'] = board['adc'].copy() boards[board_name]['adc']['path'] = Utility.get_dev_path( ) + '/' + board['adc']['path'] boards[board_name]['daq_channel'] = copy.deepcopy(board['daq_channel']) boards[board_name]['frame_device_path'] = Utility.get_dev_path( ) + '/' + board['frame_device_path']
def set(device_name, gpio_out): """ set gpio level Args: device_name: str type, device name. gpio_out(list): the unit of list is (gpio_number,gpio_level) gpio_number for 0 to 127 set gpio_level to 1, the gpio output high level set gpio_level to 0, the gpio output low level Returns: Success return NONE, False otherwise. eg: Set the gpio2 a value of 0(output): set("XAI$_GPIO",((2,0),)) Set the gpio2 gpio3 a value of 0(output): set("XAI$_GPIO",((2,0),(3,0))) """ try: path = Utility.get_dev_path() + '/' + device_name gpio_device = Axi4Gpio(path) return gpio_device.gpio_set(gpio_out) except Exception as e: logger.error("error: gpio set False:" + repr(e)) return False
def dir_set(device_name, gpio_ctrl): """ set gpio to input or output Args: device_name: str type, device name. gpio_ctrl(list): the unit of list is (gpio_number,gpio_ctrl) gpio_number for 0 to 127 set gpio_ctrl to 1, the gpio is set to input set gpio_ctrl to 0, the gpio is set to output Returns: Success return NONE, False otherwise. eg: Set the direction of the gpio2 to 0(output): dir_set("XAI$_GPIO",((2,0),)) Set the direction of the gpio2 gpio3 to 0(output): dir_set("XAI$_GPIO",((2,0),(3,0))) """ try: path = Utility.get_dev_path() + '/' + device_name gpio_device = Axi4Gpio(path) return gpio_device.gpio_ctrl(gpio_ctrl) except Exception as e: logger.error("error: gpio dir set False:" + repr(e)) return False
def get(device_name, gpio_input): """ get gpio state Args: device_name: str type, device name. gpio_input(list) : the unit of list is (gpio_number,gpio_level) gpio_number for 0 to 127 set gpio_level to 255 Returns: success return gpio_input_data(list) : the unit of list is (gpio_number,gpio_level) gpio_number for 0 to 127 when gpio is high level, the gpio_level is 1 when gpio is low level, the gpio_level is 0 False otherwise. """ try: path = Utility.get_dev_path() + '/' + device_name gpio_device = Axi4Gpio(path) return gpio_device.gpio_get(gpio_input) except Exception as e: logger.error("error: gpio get False:" + repr(e)) return False
def _parse_buses(self, bus): bus_name = bus['id'] bus_type = bus['bus'] buses = Profile.get_buses() buses[bus_name] = dict() for key in bus.keys(): if key != 'id': buses[bus_name][key] = bus[key] if 'path' in bus.keys(): buses[bus_name]['path'] = utility.get_dev_path( ) + '/' + bus['path'] if bus_type == 'uart': initconfig = Profile.get_initconfig() initconfig['uart'] = initconfig.setdefault('uart', OrderedDict()) initconfig['uart'][bus_name] = dict(baudrate=bus['baudrate'], databits=bus['databits'], stopbits=bus['stopbits'], parity=bus['parity']) if 'timestamp' in bus.keys(): initconfig['uart'][bus_name]['timestamp'] = bus['timestamp']
def parse_board_profile(board): board_name = board['id'] boards = Profile.get_boards() boards[board_name] = dict() boards[board_name]['id'] = board_name boards[board_name]['partno'] = board['partno'] boards[board_name]['switch_gpio_path'] = utility.get_dev_path( ) + '/' + board['switch_gpio'] boards[board_name]['daq_channel'] = board['daq_channel'] boards[board_name]['dacfunction'] = copy.deepcopy(board['dacfunction']) for key in board['dacfunction'].keys(): # boards[board_name]['dacfunction'][key]["vref"] = board['dacfunction'][key]['vref'] boards[ board_name]['dacfunction'][key]['path'] = utility.get_dev_path( ) + '/' + board['dacfunction'][key]['path'] boards[board_name]['dacfunction'][key]['gpio'] = [ (board['dacfunction'][key]['gpio1'], board['dacfunction'][key]['gpio1_state']), (board['dacfunction'][key]['gpio0'], board['dacfunction'][key]['gpio0_state']) ] boards[board_name]['adc7175_path'] = utility.get_dev_path( ) + '/' + board['adc7175function']['path'] boards[board_name]['adc7175_vref'] = (board['adc7175function']['vref'], "mV") boards[board_name]['adc7175_samplerate'] = ( board['adc7175function']['samplerate'], "Hz") boards[board_name]['adc7175_config'] = copy.deepcopy( board['adc7175function']['config']) for key in board['ina231funtion'].keys(): boards[board_name][key] = dict() boards[board_name][key]['ina231_path'] = utility.get_dev_path( ) + '/' + board['ina231funtion'][key]['iic_path'] boards[board_name][key]['ina231_addr'] = int( board['ina231funtion'][key]['addr'], 16) # boards[board_name]['adc_path']= utility.get_dev_path() +'/' +board['adcfunction']['path'] # boards[board_name]['adc_vref']=board['adcfunction']['vref'] # boards[board_name]['iowidthfunction']= copy.deepcopy(board['iowidthfunction']) # for key in board['iowidthfunction'].keys(): # boards[board_name]['iowidthfunction'][key]["path"]=utility.get_dev_path() +'/' +board['iowidthfunction'][key]["path"] # boards[board_name]['protectwavemeasure'] = copy.deepcopy( board['protectwavemeasure']) boards[board_name]['protectwavemeasure'][ "path"] = utility.get_dev_path( ) + '/' + board['protectwavemeasure']["path"] boards[board_name]['wave_measure'] = copy.deepcopy( board['wave_measure']) boards[board_name]['wave_measure']["path"] = utility.get_dev_path( ) + '/' + board['wave_measure']['path'] boards[board_name]['freq'] = utility.get_dev_path( ) + '/' + board['meterfunction']['freq']['path'] boards[board_name]['ppulse'] = utility.get_dev_path( ) + '/' + board['meterfunction']['ppulse']['path'] boards[board_name]['frame_dev_path'] = utility.get_dev_path( ) + '/' + board['audiofunction']['frame_dev_path'] # boards[board_name]['audio_dev_path']= utility.get_dev_path() +'/' +board['audiofunction']['audio_dev_path'] boards[board_name]['audio_reset'] = board['audiofunction'][ 'reset_gpio'] boards[board_name]['audio_enable'] = board['audiofunction'][ 'enable_gpio'] boards[board_name]['AID'] = copy.deepcopy(board['AID']) for key in board['AID'].keys(): boards[board_name]['AID'][key]["path"] = utility.get_dev_path( ) + '/' + board['AID'][key]["path"] # boards[board_name]['audiofunction_path']= utility.get_dev_path() +'/' +board['audiofunction']['path'] # boards[board_name]['audio_reset']= board['audiofunction']['reset_gpio'] # boards[board_name]['audio_enable']= board['audiofunction']['enable_gpio'] # if "temperature" in board: boards[board_name]['temperature'] = copy.deepcopy( board['temperature']) boards[board_name]['temperature']["path"] = utility.get_dev_path( ) + '/' + board['temperature']["path"] boards[board_name]['swdrstctrl'] = copy.deepcopy(board['swdrstctrl']) for key in board['swdrstctrl'].keys(): boards[board_name]['swdrstctrl'][key] = utility.get_dev_path( ) + '/' + board['swdrstctrl'][key] boards[board_name]['gpio_control'] = copy.deepcopy( board['gpio_control'])