def _init_gpio(): ret_value = True initconfig = Profile.get_initconfig() digital_io = Profile.get_ioes() if 'gpio' in initconfig.keys(): for io_id, param in initconfig['gpio'].iteritems(): try: device_path = digital_io[io_id]['path'] if Exgpio.dir_set(device_path, (param['dir'], )) is not False: logger.boot( 'set the %s gpio number %s direction:%s success' % (io_id, param['dir'][0], param['dir'][1])) if 'value' in param.keys(): if Exgpio.set(device_path, (param['value'], )) is not False: logger.boot( 'set the %s gpio number %s value:%s success' % (io_id, param['value'][0], param['value'][1])) else: logger.boot( 'warning: set the %s gpio number %s value:%s fail' % (io_id, param['value'][0], param['value'][1])) ret_value = False else: logger.boot( 'warning the %s gpio number %s direction:%s fail' % (io_id, param['dir'][0], param['dir'][1])) ret_value = False except Exception as e: logger.boot("error: %s _init_gpio execute error:\n%s" % (io_id, traceback.format_exc())) ret_value = False return ret_value
def __cmd_list_init(): global CMD_LIST CMD_LIST.clear() # print("----- init cmd list -----") try: if True == os.path.exists(os.path.dirname(sys.argv[0]) + "/handles_config.json"): json_file = '%s/handles_config.json'%(os.path.dirname(sys.argv[0])) else: json_file = '%s/command/handle/handles_config.json'%(os.environ.get("PYTHON_HOME", "/opt/seeing/app")) handles_file = open(json_file) except Exception as e: logger.error("open handles config file error !!!") return for each_line in handles_file : line = each_line.strip() line = line.strip(',') msg = None try: msg = json.loads(line) except Exception as e: continue __append_cmd(msg) logger.boot("cmd list is :" + str(CMD_LIST)) handles_file.close() return
def _create_subscriber(self, sub_filters): self._context = zmq.Context() subscriber = self._context.socket(zmq.SUB) subscriber.connect("tcp://localhost:22720") # set the subscribe filter for sub_filter in sub_filters: if sub_filter['type'] == "all" and sub_filter['chipnum'] == "all": logger.boot( "%s channel add subscriber filter: frame://%s:%s" % (self._name, sub_filter['type'], sub_filter['chipnum'])) subscriber.setsockopt(zmq.SUBSCRIBE, "") if self._controller is None: self._controller = self._context.socket(zmq.REQ) self._controller.connect("tcp://localhost:22770") libdaq.add_channel(255, 255) self._debug = subscriber break logger.boot( "%s channel add subscriber filter: frame://%d:%d" % (self._name, sub_filter['type'], sub_filter['chipnum'])) subscriber.setsockopt( zmq.SUBSCRIBE, "frame://%d:%d" % (sub_filter['type'], sub_filter['chipnum'])) if self._controller is None: self._controller = self._context.socket(zmq.REQ) self._controller.connect("tcp://localhost:22770") libdaq.add_channel(sub_filter['type'], sub_filter['chipnum']) return subscriber
def __append_cmd(cmd_message): global CMD_LIST try: CMD_LIST[cmd_message["cmd"]] = getattr(eval(cmd_message["module"]), cmd_message["handle"]) except Exception: logger.boot("%s have not handle"%(cmd_message["cmd"])) return
def _run(self): logger.init('daq.log') try: listener = self._create_listen_socket(self._port) except socket.error, e: logger.boot("%s channel create listen socket failed:%s" % (self._name, e)) return
def run(self): logger.boot('embedded engine starting') while True: try: self.rpc_server.serve_forever() except Exception: logger.warning("rpc server exception: %s"%(traceback.format_exc())) logger.info("embedded engine stopping")
def run(self): logger.init("daq.log") libdaq.sg_daq_create.restype = ctypes.POINTER(DAQ) daq = libdaq.sg_daq_create(self._dma_path, 0x7000000) if not daq: logger.boot("create daq failed") return None logger.boot("the data acquisitor is running") libdaq.sg_daqex_run(daq)
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 __init__(self, name, port, channelid, sub_filters, data_filters): super(DataChannel, self).__init__() logger.boot( "create %s channel port=%d, id=%d, sub_filters=%r, data_filters=%r" % (name, port, channelid, sub_filters, data_filters)) self._name = name self._port = port self._channelid = channelid self._connector = None self._sub_filters = sub_filters self._data_filters = data_filters self._channel_stop = False self._controller = None self._debug = None
def _init_net(): if False == os.path.exists(utility.get_config_path() + "/network.sh"): os.system("mkdir %s -p > /dev/null" % (utility.get_config_path())) os.system("touch %s/network.sh > /dev/null" % (utility.get_config_path())) os.system("chmod 775 %s/network.sh > /dev/null" % (utility.get_config_path())) with open(utility.get_config_path() + "/network.sh", 'w') as f: f.write(net.get_default_network_str()) if False == _write_default_net(): logger.boot("_init_net write default network false.") return False net_information_dict = net.read_network_information() if net.set_network() is False: logger.boot("_init_net set_network Failed.") else: logger.boot("_init_net set_network Success.") network_ip = net_information_dict[net_information_dict["mode"]]["ip"] get_ip = "ifconfig |egrep \'[1-9]+\.[1-9]+\.[0-9]+\.[0-9]+\'|awk -F: \'{print $2}\' |cut -d \" \" -f1|sed -n \'1p\'" result = subprocess.Popen(get_ip, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) strout, strerr = result.communicate() strout = strout.strip('\n') if strout != network_ip: logger.boot( "_init_net network phy is malfunctioning, try to set network again." ) os.system("%s/network.sh " % (utility.get_config_path())) return True
def _write_default_net(): net_num = _get_network_num() if net_num == -1: logger.boot('_init_net. get profile netio state error.') net_information_dict = net.read_network_information() if "user" == net_information_dict["mode"]: net.write_network_information( "default:ip", net_information_dict["PowerOn"]["ip"]) net.write_network_information( "default:mac", net_information_dict["PowerOn"]["mac"]) net.write_network_information( "default:mask", net_information_dict["PowerOn"]["mask"]) net.write_network_information( "default:gateway", net_information_dict["PowerOn"]["gateway"]) logger.boot('_init_net. read user modele and use user ip') return True with open(utility.get_config_path() + "/network.sh", 'w') as f: f.write(net.get_default_network_str()) os.system("%s/network.sh PowerOn > /dev/null" % (utility.get_config_path())) logger.boot('_init_net false, use exceptional ip:%s' % net.exceptional_ip) return False ip_list = net.default_ip.split(".") mac_list = net.default_mac.split(":") ip_num = int(ip_list[3]) + int(net_num) if ip_num > 254: ip_str = net.exceptional_ip else: del ip_list[3] ip_str = ".".join(ip_list) + '.' + str(ip_num) if net.set_network_information("default:ip", ip_str) == False: return False mac_num = int(mac_list[5].upper(), 16) + int(net_num) if mac_num > 254: mac_str = net.exceptional_mac else: del mac_list[5] mac_num = str(hex(mac_num))[2:] mac_str = ":".join(mac_list) + ":" + mac_num if net.set_network_information("default:mac", mac_str) == False: return False if net.set_network_information("default:mask", net.default_mask) == False: return False if net.set_network_information("default:gateway", net.default_gateway) == False: return False logger.boot( "_init_net write default network information in network.sh success.,ip:%s, mac:%s." % (ip_str, mac_str)) return True
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 run(self): logger.init("tcp2device.log") logger.setLevel("warning") try: self._server_socket = self._create_server_socket(self._port) except socket.error as e: logger.boot( "create tcp port %d to device server socket failed:%s" % (self._port, repr(e))) return else: logger.boot( "create tcp to device server,server socket fd=%s, port=%d" % (self._server_socket.fileno(), self._port)) self._inputs.append(self._server_socket) while not self._is_stop: '''nonboclking mode to poll the socket''' read_able_list = select.select(self._inputs, [], [], 0)[0] if self._server_socket in read_able_list: client, addr = self._server_socket.accept() self._del_connect_socket() self._add_connect_socket(client) continue if self._connect_socket in read_able_list: try: self._tcp_to_device() except Exception as e: logger.error("tcp port %s to deivce error:%s" % (self._port, repr(e))) break try: ret_device2tcp = self._device_to_tcp() except Exception as e: logger.error("device to tcp port %s error:%s" % (self._port, repr(e))) break if ret_device2tcp == 0 and len(read_able_list) == 0: time.sleep(0.1) self._del_connect_socket() self._server_socket.close()
def create_all_channel(): global data_channels try: board_channels = _get_board_channel() logger.boot("board channels %r" % (board_channels)) for channel in board_channels: name = channel['id'] data_filters = [] for data_filter in channel['filters']: if high_speed_flag == True: data_filters.append(data_filter) else: data_filters.append(getattr(Filter, data_filter)) sub_filters = [] frame_type = int(channel['frame_type'], 16) if True == isinstance(channel['chipnum'], int): sub_filter = { "type": frame_type, "chipnum": channel['chipnum'] } sub_filters.append(sub_filter) elif True == isinstance(channel['chipnum'], list): for i in range(0, len(channel['chipnum'])): sub_filter = { "type": frame_type, "chipnum": channel['chipnum'][i] } sub_filters.append(sub_filter) else: logger.error("%s channel chipnum type invalue" % (name)) continue if high_speed_flag == True: data_channels[name] = DataChannelEx(name, channel['port'], channel['ch'], sub_filters, data_filters) else: data_channels[name] = DataChannel(name, channel['port'], channel['ch'], sub_filters, data_filters) channel_name.append(name) except Exception as e: logger.error("create channel %r fail: %s" % (channel, repr(e))) return False else: return True
def run(self): logger.init("uart2net.log") logger.setLevel("warning") try: self._server_socket = self._create_server_socket(self._port) except socket.error as e: logger.boot("%s device create port %d server socket failed:%s" % (self._uartname, self._port, repr(e))) return else: logger.boot( "%s device create server socket fd=%s port=%d" % (self._uartname, self._server_socket.fileno(), self._port)) self._inputs.append(self._server_socket) while not self._uart_stop: '''nonboclking mode to poll the socket''' read_able_list = select.select(self._inputs, [], [], 0)[0] if self._server_socket in read_able_list: client, addr = self._server_socket.accept() self._del_connect_socket() self._add_connect_socket(client) continue if self._connect_socket in read_able_list: try: self._net_to_uart() except Exception as e: logger.error("%s net to uart error:%s" % (self._uartname, repr(e))) break try: ret_uart2net = self._uart_to_net() except Exception as e: logger.error("%s uart to net error:%s" % (self._uartname, repr(e))) break if ret_uart2net == 0 and len(read_able_list) == 0: time.sleep(0.05) self._del_connect_socket() self._server_socket.close()
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 init(): initok = True logger.boot('start init') if _create_chip_object() is False: initok = False if _create_board_object() is False: initok = False if _create_uart_object() is False: initok = False initconfig = Profile.get_initconfig() #init gpio if _init_gpio() is False: initok = False #initexitendio if initconfig.has_key('extendio'): if _init_extendio() is False: initok = False #init board if initconfig.has_key('boards'): if _init_board() is False: initok = False #init net try: if _init_net() is False: initok = False except Exception as e: logger.boot("error: _init_net execute error:\n%s" % (traceback.format_exc())) initok = False #init uart if initconfig.has_key('uart'): if _init_uart() is False: initok = False if not initok: logger.boot('error: init project fail') else: logger.boot("init project done") return initok
def _init_extendio(): ret_value = True extendios = Profile.get_extendio() initconfig = Profile.get_initconfig() for board_name, extendio_profile in extendios.iteritems(): for chip_name, bit in initconfig['extendio'][board_name].iteritems(): try: partno = extendio_profile[chip_name]['partno'] if Extendio.chip_dir_set(extendio_profile, chip_name, bit['dir']) is True: ret = Extendio.chip_set(extendio_profile, chip_name, bit['value']) if ret is False: logger.boot( 'error: set the %s board %s chip %s value:%s fail' % (board_name, partno, chip_name, logger.print_list2hex(bit['value']))) ret_value = False else: logger.boot( 'init the %s board extendio chip %s success, value is %s, direction is %s' % (board_name, chip_name, logger.print_list2hex(bit['value']), logger.print_list2hex(bit['dir']))) else: logger.boot( 'error: set the %s board %s chip %s direction:%s fail' % (board_name, partno, chip_name, logger.print_list2hex(bit['dir']))) ret_value = False except Exception: logger.boot("error: %s _init_extendio execute error:\n%s" % (chip_name, traceback.format_exc())) ret_value = False return ret_value
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
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 board_initial(self): """ board initial ADC chip initial: samplerate,work mode,channel config Agrs: 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 reset and initial failed. Raises: KeyError,ValueError """ logger.boot("%s board initial" % (self.profile["id"])) if not self.adc_device.single_sample_mode(): logger.warning( "%s board AD7175[%s] chip single sample mode set failed" % (self.profile["id"], self.profile["adc"]["path"])) return False #ADC chip initial logger.boot("%s board AD7175[%s] chip initial" % (self.profile["id"], self.profile["adc"]["path"])) if not self.adc_device.reset(): logger.warning("%s board AD7175[%s] chip reset failed." % (self.profile["id"], self.profile["adc"]["path"])) return False if not self.adc_device.is_comunication_ok(): logger.warning( "%s board AD7175[%s] chip communication is not ok" % (self.profile["id"], self.profile["adc"]["path"])) return False if not self.adc_device.single_sample_mode(): logger.warning( "%s board AD7175[%s] chip single sample mode set failed" % (self.profile["id"], self.profile["adc"]["path"])) return False #IFMODE register: channel_flag, data bits, if self.adc_device.ifmode_register_set("disable", "24bits") is False: logger.warning("%s board AD7175[%s] chip ifmode reg set failed" % (self.profile["id"], self.profile["adc"]["path"])) return False #Channel register: channel combination if self.adc_device.voltage_channel_disable("all") is False: logger.warning( "%s board AD7175[%s] chip channel reg all disable config failed" % (self.profile["id"], self.profile["adc"]["path"])) return False #setup register: code polar=bipolar,refrence=extern, buffer=enable if not self.adc_device.setup_register_set( _datalogger_board_description["channel"]["current"] ["adc_config"]["channel"], "bipolar", "extern", "enable"): logger.warning( "%s AD7175[%s] chip current channel setup configure failed" % (self.profile["id"], self.profile["adc"]["path"])) return False if not self.adc_device.setup_register_set( _datalogger_board_description["channel"]["voltage"] ["adc_config"]["channel"], "bipolar", "extern", "enable"): logger.warning( "%s AD7175[%s] chip voltage channel setup configure failed" % (self.profile["id"], self.profile["adc"]["path"])) return False #filter register: samplerate config if not self.adc_device.samplerate_set( _datalogger_board_description["channel"]["current"] ["adc_config"]["channel"], self.adc_samplerate["current"]): logger.warning( "%s AD7175[%s] chip current channel filter configure failed" % (self.profile["id"], self.profile["adc"]["path"])) return False if not self.adc_device.samplerate_set( _datalogger_board_description["channel"]["voltage"] ["adc_config"]["channel"], self.adc_samplerate["voltage"]): logger.warning( "%s AD7175[%s] chip voltage channel filter configure failed" % (self.profile["id"], self.profile["adc"]["path"])) return False #adc mode register: crystal clock if not self.adc_device.mode_register_set("crystal"): logger.warning("%s AD7175[%s] mode register configure failed" % (self.profile["id"], self.profile["adc"]["path"])) return False #the first one discarded if not self.adc_device.voltage_get( _datalogger_board_description["channel"]["current"] ["adc_config"]["channel"], _datalogger_board_description["channel"] ["current"]["adc_config"]["config"]): logger.warning( "%s board AD7175[%s] current channel first sample failed" % (self.profile["id"], self.profile["adc"]["path"])) return False if not self.adc_device.voltage_get( _datalogger_board_description["channel"]["voltage"] ["adc_config"]["channel"], _datalogger_board_description["channel"] ["voltage"]["adc_config"]["config"]): logger.warning( "%s board AD7175[%s] voltage channel first sample failed" % (self.profile["id"], self.profile["adc"]["path"])) return False if not self.adc_device.continue_mode_frame_config_set( self.chipnum, self.datalogger_samplerate[0]): logger.warning("%s AD7175[%s] chipno and samplerate set failed" % (self.profile["id"], self.profile["adc"]["path"])) return False #Channel register: channel combination if self.adc_device.voltage_channel_disable("all") is False: logger.warning( "%s board AD7175[%s] chip channel reg all disable config failed" % (self.profile["id"], self.profile["adc"]["path"])) return False self.initial_flag = True return True
def __init__(self, profile): self.profile = profile self.dac_device = dict() # self.dac_device['psu1_ocp']=AD5061(self.profile['psu1_ocp']['path'],self.profile['psu1_ocp']['vref']) # self.dac_device['psu1_ovp']=AD5061(self.profile['psu1_ovp']['path'],self.profile['psu1_ovp']['vref']) # self.dac_device['psu1_current']=AD5061(self.profile['psu1_current']['path'],self.profile['psu1_current']['vref']) # self.dac_device['psu1_voltage']=AD5061(self.profile['psu1_voltage']['path'],self.profile['psu1_voltage']['vref']) # self.dac_device['psu2_ocp']=AD5061(self.profile['psu2_ocp']['path'],self.profile['psu2_ocp']['vref']) # self.dac_device['psu2_ovp']=AD5061(self.profile['psu2_ovp']['path'],self.profile['psu2_ovp']['vref']) # self.dac_device['psu2_current']=AD5061(self.profile['psu2_current']['path'],self.profile['psu2_current']['vref']) # self.dac_device['psu2_voltage']=AD5061(self.profile['psu2_voltage']['path'],self.profile['psu2_voltage']['vref']) # self.dac_device['psu3_ocp']=AD5061(self.profile['psu3_ocp']['path'],self.profile['psu3_ocp']['vref']) # self.dac_device['psu3_ovp']=AD5061(self.profile['psu3_ovp']['path'],self.profile['psu3_ovp']['vref']) # self.dac_device['psu3_current']=AD5061(self.profile['psu3_current']['path'],self.profile['psu3_current']['vref']) # self.dac_device['psu3_voltage']=AD5061(self.profile['psu3_voltage']['path'],self.profile['psu3_voltage']['vref']) # self.dac_device['TP_board_voltage']=AD5601(self.profile['TP_board_voltage']['path'],self.profile['TP_board_voltage']['vref']) # self.dac_device['Base_Board']=AD5061(self.profile['Base_Board']['path'],self.profile['Base_Board']['vref']) self.gpio_device_name = Axi4Gpio(self.profile["switch_gpio_path"]) self.ad7175_device = AD7175(self.profile["adc7175_path"], self.profile["adc7175_vref"]) # self.gpio_device_name.gpio_set(self.profile["dacfunction"]["psu3_voltage"]['gpio']) # time.sleep(0.01) for key in self.profile['dacfunction']: # if self.profile['dacfunction'][key]['partno']=="AD5761": if self.profile['dacfunction'][key]['partno'] == "AD5761": self.gpio_device_name.gpio_set( self.profile["dacfunction"][key]['gpio']) self.dac_device[key] = eval( self.profile['dacfunction'][key]['partno'])( self.profile['dacfunction'][key]['path'], self.profile['dacfunction'][key]['vref']) self.ina231_device = dict() self.ina231_device["psu1_ina231"] = INA231( self.profile['psu1_ina231']['ina231_path'], self.profile['psu1_ina231']["ina231_addr"]) self.ina231_device["psu2_ina231"] = INA231( self.profile['psu2_ina231']['ina231_path'], self.profile['psu2_ina231']["ina231_addr"]) self.ina231_device["psu3_ina231"] = INA231( self.profile['psu3_ina231']['ina231_path'], self.profile['psu3_ina231']["ina231_addr"]) # self.adc_device=XadcDevice(self.profile["adc_path"] ) # self.adc_vref=self.profile["adc_vref"] # self.width_meter_device = dict() self.width_meter_device['ppulse'] = Axi4TimeDetect( self.profile["ppulse"]) self.protectwavemeasure_device = Axi4TimeDetect( self.profile["protectwavemeasure"]["path"]) self.frequncy_meter_device = dict() self.frequncy_meter_device['freq'] = Axi4SignalMeter( self.profile["freq"]) self.audio_frame_device = Axi4Frame(self.profile["frame_dev_path"]) # self.audio_fft_device=Axi4FftAnalyzer(self.profile["audio_dev_path"]) self.wave_measure_device = Axi4TimeDetect_v1( self.profile["wave_measure"]["path"]) self.aid_device = dict() for key in self.profile["AID"].keys(): self.aid_device[key] = eval(self.profile['AID'][key]['ipcore'])( self.profile['AID'][key]['path']) try: temp_ipcore_name = self.profile["temperature"]["ipcore"] temp_path_name = self.profile["temperature"]["path"] self.temperature_device = eval(temp_ipcore_name)(temp_path_name) except KeyError: logger.boot("not have \"%s\" chip" % ("temperature")) self.temperature_device = None self.swd_device = dict() try: for key in self.profile['swdrstctrl'].keys(): self.swd_device[key] = Axi4SwdCore( self.profile['swdrstctrl'][key]) except: logger.boot("not have swd_device")
def register_public_methods(self): for method in self._methods: logger.boot("register method: %r" % (method)) self.add_method(method) self.add_method(self.eval)
daq_daemon.start() logger.init("daq.log") logger.setLevel('WARNING') len_args = len(sys.argv) if (len_args < 2): dma_path = "/dev/AXI4_DMA" elif (len_args < 3): dma_path = sys.argv[1] else: dma_path = sys.argv[1] if sys.argv[2] == "high_speed": high_speed_flag = True logger.boot("the dma path is %s" % (dma_path)) if high_speed_flag == True: data_acquisitor = DataAcquisitorEx(dma_path) else: data_acquisitor = DataAcquisitor(dma_path) data_acquisitor.start() ''' add debug channel ''' debug_sub_filters = [{"type": "all", "chipnum": "all"}] if high_speed_flag == True: debug_data_filters = ["sg_output_filter"] debug_channel = DataChannelEx("debug", 22710, 255, debug_sub_filters, debug_data_filters) else: debug_data_filters = [Filter.output] debug_channel = DataChannel("debug", 22710, 255, debug_sub_filters,
def read_profile(self, hardware_function_profile): logger.boot("start parser, profile path:%s" % (hardware_function_profile)) try: profile = utility.load_json_file(hardware_function_profile, object_hook=_convert) except Exception as e: logger.boot("error: read json profile fail:%s" % (repr(e))) return None self._base_board_name = profile['base_board']['id'] Profile.set_base_board_name(self._base_board_name) for bus in profile['buses']: bus_name = bus['id'] try: self._parse_buses(bus) except Exception as e: logger.boot('error: parse the %s bus fail: %s' % (bus_name, repr(e))) else: logger.boot( 'parse the %s bus:%s' % (bus_name, _str_dict(Profile.get_bus_by_name(bus_name)))) if 'netconfig' in profile.keys(): initconfig = Profile.get_initconfig() initconfig['netconfig'] = profile['netconfig'] if 'digital_io' in profile.keys(): for io in profile['digital_io']: io_id = io['id'] try: self._parse_digital_io(io) except Exception as e: logger.boot("error: parse the %s digital io fail:%s" % (io_id, repr(e))) else: logger.boot("parse the %s digital io:%s" % (io_id, Profile.get_ioes()[io_id])) if "chips" in profile: for chip in profile['chips']: chipname = chip['id'] try: self._parse_chips(chip) except Exception as e: logger.boot('error: parser the %s chip fail: %s' % (chipname, repr(e))) else: try: str_chip_profile = _str_dict( Profile.get_chip_by_name(chipname)) except KeyError: str_chip_profile = _str_dict( Profile.get_eeprom_by_name(chipname)) logger.boot('parser the %s chip:%s' % (chipname, str_chip_profile)) if "boards" in profile: for board in profile['boards']: board_name = board['id'] if 'eeprom' in board.keys(): eeproms = board['eeprom'] if isinstance(eeproms, dict): eeproms = [eeproms] if isinstance(eeproms, list) is False: logger.boot( "error: can not parse the board eeprom,invalid format" ) else: for eeprom in eeproms: try: eeprom_id = eeprom["id"] self._parse_eeprom(board_name, eeprom) except Exception as e: logger.boot( 'error: parser the %s board eeprom fail: %s' % (board_name, repr(e))) else: logger.boot( 'parser the %s board eeprom:%s' % (board_name, _str_dict( Profile.get_eeprom_by_name(eeprom_id)) )) try: self._parse_boards(board) except Exception as e: logger.boot('error: parse the %s board fail: %s' % (board_name, repr(e))) else: logger.boot( 'parser board success, %s:%s' % (board_name, _str_dict(Profile.get_board_by_name(board_name)))) logger.boot('parse done') return True
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) led.start() uart_server_thread = Thread(target=uart_server.create_uart_server) uart_server_thread.start() ee.run()
def add_sub_filter(self, sub_filter): self._sub_filters.append(sub_filter) def set_data_filters(self, data_filters): self._data_filters = data_filters def _run(self): logger.init('daq.log') try: listener = self._create_listen_socket(self._port) except socket.error, e: logger.boot("%s channel create listen socket failed:%s" % (self._name, e)) return else: logger.boot("%s channel create listen socket fd=%d" % (self._name, listener.fileno())) subscriber = self._create_subscriber(self._sub_filters) poller = zmq.Poller() self._poller = poller poller.register(listener.fileno(), zmq.POLLIN) poller.register(subscriber, zmq.POLLIN) conn_addr = None while not self._channel_stop: socks = dict(poller.poll()) # accept the new connect if listener.fileno() in socks: conn, addr = listener.accept()