From e43af44115e95659bafcdd7e94db1a9632c344a7 Mon Sep 17 00:00:00 2001 From: Liu Shuo <49305054@qq.com> Date: Wed, 1 Jun 2022 16:45:52 +0800 Subject: [PATCH 1/6] [feature] add skyeye objects system --- utils/pycli/conf2.py | 231 ++++++++++++++++ utils/pycli/mips.py | 87 +++--- utils/pycli/objects.py | 256 ++++++++++++++++++ utils/pycli/skyeye_cli.py | 110 +++++--- utils/pycli/skyeye_command/_base_.py | 12 +- .../_object_command/machine_object_command.py | 40 +++ utils/pycli/skyeye_command/bp_create.py | 6 +- utils/pycli/skyeye_command/bp_delete.py | 6 +- utils/pycli/skyeye_command/bp_list.py | 6 +- utils/pycli/skyeye_command/define_conf.py | 12 +- .../skyeye_command/disable_device_work.py | 10 +- utils/pycli/skyeye_command/disassemble.py | 8 +- .../skyeye_command/enable_device_work.py | 10 +- utils/pycli/skyeye_command/fj_clear.py | 12 +- utils/pycli/skyeye_command/fj_list.py | 1 - utils/pycli/skyeye_command/fj_set.py | 12 +- utils/pycli/skyeye_command/get_pc.py | 11 +- utils/pycli/skyeye_command/list_attr.py | 3 +- utils/pycli/skyeye_command/list_class.py | 4 +- utils/pycli/skyeye_command/list_connect.py | 1 - utils/pycli/skyeye_command/list_cpu.py | 13 +- utils/pycli/skyeye_command/list_device.py | 39 ++- utils/pycli/skyeye_command/list_iface.py | 4 +- utils/pycli/skyeye_command/list_machines.py | 9 +- utils/pycli/skyeye_command/list_register.py | 42 ++- utils/pycli/skyeye_command/load_binary.py | 12 +- utils/pycli/skyeye_command/load_file.py | 15 +- utils/pycli/skyeye_command/md.py | 10 +- utils/pycli/skyeye_command/mm_info.py | 1 - .../pycli/skyeye_command/open_instr_record.py | 13 +- utils/pycli/skyeye_command/quit.py | 4 - utils/pycli/skyeye_command/remote_gdb.py | 1 - utils/pycli/skyeye_command/reset.py | 4 +- utils/pycli/skyeye_command/reverse.py | 13 +- utils/pycli/skyeye_command/reverse_disable.py | 4 +- utils/pycli/skyeye_command/reverse_enable.py | 8 +- utils/pycli/skyeye_command/run.py | 1 - utils/pycli/skyeye_command/run_command.py | 1 - utils/pycli/skyeye_command/run_script.py | 6 +- utils/pycli/skyeye_command/set_mode.py | 11 +- utils/pycli/skyeye_command/set_pc.py | 6 +- utils/pycli/skyeye_command/set_register.py | 45 ++- utils/pycli/skyeye_command/speed.py | 8 +- utils/pycli/skyeye_command/stepi.py | 6 +- utils/pycli/skyeye_command/stop.py | 1 - utils/pycli/skyeye_common_module.py | 4 + 46 files changed, 820 insertions(+), 299 deletions(-) create mode 100644 utils/pycli/conf2.py create mode 100644 utils/pycli/objects.py create mode 100644 utils/pycli/skyeye_command/_object_command/machine_object_command.py diff --git a/utils/pycli/conf2.py b/utils/pycli/conf2.py new file mode 100644 index 00000000..d7764e9f --- /dev/null +++ b/utils/pycli/conf2.py @@ -0,0 +1,231 @@ +import json +from collections import OrderedDict +from objects import Node, Root, Component, MethodNode, Machine, Cpu, Device, Linker +from skyeye_common_module import * + +class ConfParser: + def node_type(self, node): + assert node + if isinstance(node, dict): + if 'base' not in node: + ntype = 'root' + else: + ntype = 'component' + elif isinstance(node, list): + if 'iface' in node or all('iface' in child for child in node): + ntype = 'iface' + else: + ntype = 'attr' + else: + ntype = 'value' + + return ntype + + def parse_root_node(self, node): + node_type = self.node_type(node) + assert node_type == 'root' + + child_list = list(node.items()) + return child_list + + def parse_component_node(self, node): + node_type = self.node_type(node) + assert node_type == 'component' + + base = node['base'] + cls = node['class'] + child_list = [] + iface_list = [] + attr_list = [] + + for name, child in node.items(): + node_type = self.node_type(child) + if node_type == 'component': + child_list.append((name, child)) + elif node_type == 'iface': + iface_list.append((name, child)) + elif node_type == 'attr': + attr_list.append((name, child)) + + return base, cls, child_list, iface_list, attr_list + +class SkyeyeConf: + # singleton pattern + _skyeye_conf_obj = None + _config_done_callbacks = OrderedDict() + _config_clear_callbacks = OrderedDict() + + @staticmethod + def make_config(json_file_path): + SkyeyeConf._skyeye_conf_obj = SkyeyeConf(json_file_path) + SkyeyeConf.call_config_done_callbacks() + + @staticmethod + def clear_config(): + SkyeyeConf._skyeye_conf_obj = None + SkyeyeConf.call_config_clear_callbacks() + + @staticmethod + def get_config(): + return SkyeyeConf._skyeye_conf_obj + + @staticmethod + def add_config_done_callback(name, func): + SkyeyeConf._config_done_callbacks[name] = func + + @staticmethod + def del_config_done_callback(name): + SkyeyeConf._config_done_callbacks.pop(name) + + @staticmethod + def call_config_done_callbacks(): + for func in SkyeyeConf._config_done_callbacks.values(): + func() + + @staticmethod + def add_config_clear_callback(name, func): + SkyeyeConf._config_clear_callbacks[name] = func + + @staticmethod + def del_config_clear_callback(name): + SkyeyeConf._config_clear_callbacks.pop(name) + + @staticmethod + def call_config_clear_callbacks(): + for func in SkyeyeConf._config_clear_callbacks.values(): + func() + + def __init__(self, json_file_path): + self.machine_dict = OrderedDict() + self.cpu_dict = OrderedDict() + self.device_dict = OrderedDict() + self.linker_dict = OrderedDict() + self.components = OrderedDict() + self.config_done_callbacks = OrderedDict() + + self.data = self.load_json_file(json_file_path) + self.parser = ConfParser() + + self.build() + + def build(self): + self.root = Root() + self.create_node(None, self.data, self.root) + self.component_connect() + self.component_set_attr() + self.conf_commit() + + def load_json_file(self, json_path): + try: + with open(json_path) as f: + return json.load(f, object_pairs_hook=OrderedDict) + except Exception as e: + raise e + + def create_node(self, name, node, parent): + node_type = self.parser.node_type(node) + if node_type == 'root': + for name, component in self.parser.parse_root_node(node): + self.create_node(name, component, parent) + elif node_type == 'component': + base, cls, child_list, iface_list, attr_list = \ + self.parser.parse_component_node(node) + if base == 'mach': + obj = self.create_mach(name, parent, base, cls, iface_list, attr_list) + elif base == 'cpu': + obj =self.create_cpu(name, parent, base, cls, iface_list, attr_list) + elif base == 'device': + obj = self.create_device(name, parent, base, cls, iface_list, attr_list) + elif base == 'linker': + obj = self.create_linker(name, parent, base, cls, iface_list, attr_list) + + for name, child in child_list: + self.create_node(name, child, obj) + else: + raise Exception('BUG!') + + def create_mach(self, name, parent, base, cls, iface_list, attr_list): + mach = Machine(name, parent, base, cls, iface_list, attr_list) + self.machine_dict[name] = mach + self.components[name] = mach + return mach + + def create_cpu(self, name, parent, base, cls, iface_list, attr_list): + cpu = Cpu(name, parent, base, cls, iface_list, attr_list) + self.cpu_dict[name] = cpu + self.components[name] = cpu + return cpu + + def create_device(self, name, parent, base, cls, iface_list, attr_list): + device = Device(name, parent, base, cls, iface_list, attr_list) + self.device_dict[name] = device + self.components[name] = device + return device + + def create_linker(self, name, parent, base, cls, iface_list, attr_list): + linker = Linker(name, parent, base, cls, iface_list, attr_list) + self.linker_dict[name] = linker + self.components[name] = linker + return linker + + def component_connect(self): + for name, component in self.components.items(): + component.connect() + + def component_set_attr(self): + for name, component in self.components.items(): + component.set_attr() + + def conf_commit(self): + SkyEyeConfigConfObj() + + def get_object_tree(self): + return self.root + + def get_machines(self): + return self.machine_dict.copy() + + def get_cpus(self, machine=None): + if machine is None: + return self.cpu_dict.copy() + + mach_obj = self.machine_dict.get(machine, None) + if mach_obj: + return mach_obj.get_cpus() + + return None + + def get_devices(self, machine=None): + if machine is None: + return self.device_dict.copy() + + mach_obj = self.machine_dict.get(machine, None) + if mach_obj: + return mach_obj.get_devices() + + return None + + def get_linkers(self): + return self.linker_dict.copy() + + def get_machine(self, name): + return self.machine_dict.get(name, None) + + def get_cpu(self, name): + return self.cpu_dict.get(name, None) + + def get_device(self, name): + return self.device_dict.get(name, None) + + def get_linker(self, name): + return self.linker_dict.get(name, None) + +# API FUNC +make_config = SkyeyeConf.make_config +clear_config = SkyeyeConf.clear_config +get_config = SkyeyeConf.get_config + +add_config_done_callback = SkyeyeConf.add_config_done_callback +del_config_done_callback = SkyeyeConf.del_config_done_callback +add_config_clear_callback = SkyeyeConf.add_config_clear_callback +del_config_clear_callback = SkyeyeConf.del_config_clear_callback diff --git a/utils/pycli/mips.py b/utils/pycli/mips.py index d4394fcc..0ac5bee1 100644 --- a/utils/pycli/mips.py +++ b/utils/pycli/mips.py @@ -1,39 +1,50 @@ -import time -import threading -import conf - -time_num = 1 -mips_thread = None - -class mips(threading.Thread): - def __init__(self, win = None): - threading.Thread.__init__(self) - self.setDaemon(True) - self.thread_stop = False - self.win = win - self.info = {} - - def run(self): - while not self.thread_stop: - self.config = conf.GetGlobalConfig() - if not self.config: - time.sleep(0.1) - continue - for cpu in conf.Cpus: - try: - cpu.update_speed() - except: - pass - time.sleep(1) +import conf2 +from threading import Timer +from skyeye_common_module import SkyEyeGetCpuSteps +from collections import OrderedDict + +class MIPS: + _instance = None + + @staticmethod + def instance(): + if MIPS._instance is None: + MIPS._instance = MIPS() + return MIPS._instance + + def __init__(self): + conf2.add_config_done_callback('mips_start', self.start) + conf2.add_config_clear_callback('mips_stop', self.stop) + + def start(self): + self.running = True + Timer(1.0, self.update).start() + self.config = conf2.get_config() + self.cpus = self.config.get_cpus() + self.cpu_steps = OrderedDict() + self.cpu_mips = OrderedDict() + for cpu in self.cpus: + self.cpu_steps[cpu] = 0 + self.cpu_mips[cpu] = 0 + def stop(self): - self.thread_stop = 1 - -def get(cpuname = None): - global time_num - if cpuname: - pass - else: - mips = {} - for cpu in conf.Cpus: - mips[cpu.name] = cpu.speed * time_num - return mips + self.running = False + + def update(self): + if self.running: + Timer(1.0, self.update).start() + for cpu in self.cpus: + steps = SkyEyeGetCpuSteps(cpu) + self.cpu_mips[cpu] = steps - self.cpu_steps[cpu] + self.cpu_steps[cpu] = steps + + def get_mips(self): + return self.cpu_mips + +# API +def init(): + MIPS.instance() + +def get(): + obj = MIPS.instance() + return obj.get_mips() diff --git a/utils/pycli/objects.py b/utils/pycli/objects.py new file mode 100644 index 00000000..a89cc691 --- /dev/null +++ b/utils/pycli/objects.py @@ -0,0 +1,256 @@ +class Node: + def __init__(self, name=None, parent=None): + self.name = name + self.parent = parent + self.cli_attrs = {} + + def attach_to_parent(self, parent): + if parent: + parent.add_child(self.name, self) + + def add_child(self, name, child): + self.cli_attrs[name] = child + self.add_child_callback(child) + + # Implement this function if need + def add_child_callback(self, child): + pass + + def find_child(self, name): + return self.cli_attrs.get(name, None) + + def find_obj_by_path(self, path): + if path: + if '.' in path: + obj_name, path = path.split('.', 1) + else: + obj_name, path = path, '' + + if obj_name in self.cli_attrs: + obj = self.cli_attrs[obj_name].find_obj_by_path(path) + else: + obj = None + else: + obj = self + + return obj + + def match_cli_attr_name(self, text): + return [name for name in self.cli_attrs if name.startswith(text)] + +class Root(Node): + def __str__(self): + return '' + +class MethodNode(Node): + def __init__(self, name, parent, cmd): + super().__init__(name, parent) + self.cmd = cmd + self.attach_to_parent(parent) + + def __call__(self, arg=''): + self.cmd(arg=arg, obj=self.parent) + +class Component(Node): + def __init__(self, name, parent=None, base='', cls='', iface_list=(), attr_list=()): + super().__init__(name, parent) + self.base = base + self.cls = cls + self.iface_list = iface_list + self.attr_list = attr_list + self.attach_to_parent(parent) + self.instance() + self.register_method_commands() + + def instance(self): + raise NotImplementedError + + def register_method_commands(self): + pass + + def connect(self): + for iface_name, slots in self.iface_list: + if 'iface' in slots: + slots = [slots] + + if self.cls == 'memory_space' and iface_name == 'memory_space': + for index, slot in enumerate(slots): + j = slot.index('iface') + target = slot[j+1] + target_obj = self.parent.find_child(target) + if isinstance(slot[j+2], list): + for addr, length in slot[j+2]: + addr = int(addr, 0) + length = int(length, 0) + SkyEyeMpAddMapGroup(self.name, target, addr, length - 1, index) + target_obj.memory_space_map(self.name, addr, length) + else: + addr, length = slot[j+2:] + addr = int(addr, 0) + length = int(length, 0) + SkyEyeMpAddMap(self.name, target, addr, length - 1) + target_obj.memory_space_map(self.name, addr, length) + else: + for slot in slots: + j = slot.index('iface') + target = slot[j+1] + try: + index = int(slot[j+2], 0) + except IndexError: + index = 0 + SkyEyeConnect(self.name, target, iface_name, index) + + def set_attr(self): + for attr_name, (attr_type, value) in self.attr_list: + SkyEyeSetAttr(self.name, attr_name, attr_type, value) + + def __call__(self, *args): + print(self) + +from skyeye_common_module import * +from collections import OrderedDict +class Machine(Component): + def register_method_commands(self): + from skyeye_command._object_command.machine_object_command import \ + Machine_list_cpu, Machine_list_device + cmd = Machine_list_cpu('list_cpu') + MethodNode(name='list_cpu', parent=self, cmd=cmd) + + cmd = Machine_list_device('list_device') + MethodNode(name='list_device', parent=self, cmd=cmd) + + def instance(self): + SkyEyeCreateMach(self.name, self.cls) + + def __str__(self): + return '' % self.name + + def get_cpus(self): + res = OrderedDict() + for name, child in self.cli_attrs.items(): + if isinstance(child, Cpu): + res[name] = child + return res + + def get_devices(self): + res = OrderedDict() + for name, child in self.cli_attrs.items(): + if isinstance(child, Device): + res[name] = child + return res + +class Cpu(Component): + def instance(self): + SkyEyeCreateCpu(self.parent.name, self.name, self.cls) + + def __str__(self): + return '' % self.name + +class Device(Component): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self._space_maps = None + + def instance(self): + SkyEyeCreateDevice(self.parent.name, self.name, self.cls) + + def __str__(self): + return '' % self.name + + def memory_space_map(self, space_name, addr, length): + if self._space_maps is None: + self._space_maps = OrderedDict() + self._space_maps[addr] = (space_name, length) + self.create_register_list(addr) + + def has_registers(self): + num = 0 + try: + num = SkyEyeGetDevRegNum(None, self.name) + except: + pass + return num > 0 + + def create_register_list(self, base_addr): + if self.has_registers(): + RegisterList('regs', self, self.name, base_addr) + + def get_register_list(self): + return self.cli_attrs.get('regs', None) + +class Linker(Component): + def instance(self): + SkyEyeCreateLinker(self.name, self.cls) + + def __str__(self): + return '' % self.name + +class RegisterList(Node): + def __init__(self, name, parent, device_name, base_addr): + super().__init__(name, parent) + self.device_name = device_name + self.base_addr = base_addr + self.attach_to_parent(parent) + self.create_register() + + def create_register(self): + num = SkyEyeGetDevRegNum(None, self.device_name) + for reg_id in range(num): + reg_name = SkyEyeGetDevRegNameById(None, self.device_name, reg_id) + offset = SkyEyeGetDevRegOffsetById(None, self.device_name, reg_id) + if offset == 0xffffffff: + offset = reg_id * 4 + Register(reg_name, self, self.device_name, reg_id, self.base_addr+offset) + + def get_register(self, name): + return self.cli_attrs.get(name, None) + + def get_registers(self): + return self.cli_attrs.copy() + + def __call__(self, arg): + print(self) + self.show() + + def show(self): + print('%-25s%-25s%-15s' % ('register', 'value', 'address')) + for reg in self.cli_attrs.values(): + print('%-25s0x%-23x0x%-13x' % (reg.name, reg.value, reg.addr)) + + def __str__(self): + return '' % self.device_name + +class Register(Node): + def __init__(self, name, parent, device_name, reg_id, addr): + super().__init__(name, parent) + self.device_name = device_name + self.reg_id = reg_id + self.addr = addr + self.attach_to_parent(parent) + + @property + def value(self): + try: + value = SkyEyeGetDevRegValueById(None, self.device_name, self.reg_id) + except: + return None + return value + + @value.setter + def value(self): + pass + + def __call__(self, arg): + print(self) + self.show() + + def show(self): + print('%-25s%-15s' % ("value", "address")) + v = self.value + if v is not None: + print('0x%-23x0x%-13x' % (self.value, self.addr)) + else: + print('%-25s0x%-13x' % (self.value, self.addr)) + + def __str__(self): + return '' % (self.device_name, self.name) diff --git a/utils/pycli/skyeye_cli.py b/utils/pycli/skyeye_cli.py index 22e89551..677350e1 100755 --- a/utils/pycli/skyeye_cli.py +++ b/utils/pycli/skyeye_cli.py @@ -26,6 +26,10 @@ import skyeye_command sys.path.append(se_path.SkyEyeBin) +DEBUG = 0 +if DEBUG: + import traceback + def add_help_method(cls): attrs = dir(cls) if 'print_help' not in attrs: @@ -45,22 +49,22 @@ def add_help_method(cls): def add_do_command_method(cls): def create_command_method(command): def do_xxx(self, arg): - try: + if not DEBUG: + try: + command(arg=arg, cli=self) + except Exception as e: + if str(e): + print('[ERROR]', e) + except: + print('!!!BUG!!!') + else: command(arg=arg, cli=self) - except Exception as e: - if str(e): - print('[ERROR]', e) - except: - print('!!!BUG!!!') + return do_xxx def create_complete_method(command): def complete_xxx(self, text, line, begidx, endidx): return command.complete(text, line, begidx, endidx) - # try: - # return command.complete(text, line, begidx, endidx) - # except: - # return [] return complete_xxx for name, command in skyeye_command._commands.items(): @@ -74,7 +78,6 @@ def add_do_command_method(cls): @add_help_method @add_do_command_method class SkyEyeCli(cmd.Cmd): - Config = None # skyeye prompt prompt = '(skyeye) ' @@ -90,8 +93,6 @@ class SkyEyeCli(cmd.Cmd): # from skyeye_gui import * # win_control() RegisterLog(print) - mips.mips_thread = mips.mips() - mips.mips_thread.start() if(os.path.exists('.skyeyeinit')): tools.execute_skyeyeinit_file('.skyeyeinit') if tools.is_windows(): @@ -102,6 +103,9 @@ class SkyEyeCli(cmd.Cmd): print ("网络服务启动失败,检查GRPC服务是否配置正确!") pytimer.PyTmrInit() + # MIPS + mips.init() + # 为命令补齐配置readline self.readline_cfg() @@ -109,7 +113,7 @@ class SkyEyeCli(cmd.Cmd): self.cmd_parsers = {} # 参数补齐时不截断形如xxx-yyy的命令 - self.identchars += '-/' + self.identchars += '-/.' def print_welcome_message(self): os_info = platform.system() @@ -185,15 +189,28 @@ class SkyEyeCli(cmd.Cmd): parser.print_help() def completenames(self, text, *ignored): - # TODO: 补齐形如''对象名, - # if text.startswith('<'): - # pass + res1 = self.complete_obj_names(text) + res2 = self.complete_command_names(text) + return res1 + res2 + + def complete_obj_names(self, text): + res = [] + if self.config: + root = self.config.get_object_tree() + if '.' in text: + p, txt = text.rsplit('.', 1) + else: + p, txt = '', text + obj = root.find_obj_by_path(p) + if obj: + res = obj.match_cli_attr_name(txt) + res = [p+'.'+item if p else item for item in res] + return res - hack = False + def complete_command_names(self, text): if '-' in text: text = text.replace('-', '_') - hack = True - res = super().completenames(text, *ignored) + res = super().completenames(text) res = [s.replace('_', '-') for s in res] return res @@ -207,29 +224,36 @@ class SkyEyeCli(cmd.Cmd): return compfunc(text, line, begidx, endidx) return [] - def default(self, line): - print('[Error] Unknown command: %s\n'%line) - def complete(self, text, state): - #print('IN complete: text = "%s"' % text, state) return super().complete(text, state) - # def complete_get_pc(self, text, line, begidx, endidx): - # print('HOHOH') - # config = GetGlobalConfig() - # if not config: - # return None - # cpus = config.get_cpu_list() - # return [item for item in cpus if item.startswith(text)] - - # def do_t(self, arg): - # args = arg.split() - # print(args) - # try: - # #res = SkyEyeGetPC(*args) - # res = SkyEyeGetSocNum() - # print(res) - # except Exception as e: - # print(e) - # raise e - \ No newline at end of file + def default(self, line): + res = self.Do_object_command(line) + if not res: + print('[Error] Unknown command: %s\n'%line) + + def Do_object_command(self, line): + if self.config: + root = self.config.get_object_tree() + cmd, arg, line = self.parseline(line) + + obj = root.find_obj_by_path(cmd) + if obj: + try: + obj(arg) + except Exception as e: + if str(e): + print('[ERROR]', e) + return True + return False + + # Skyeye Config Object + _skyeye_conf_obj = None + + def update_config(self): + import conf2 + SkyEyeCli._skyeye_conf_obj = conf2.get_config() + + @property + def config(self): + return self._skyeye_conf_obj diff --git a/utils/pycli/skyeye_command/_base_.py b/utils/pycli/skyeye_command/_base_.py index 11f657c4..097bb6df 100644 --- a/utils/pycli/skyeye_command/_base_.py +++ b/utils/pycli/skyeye_command/_base_.py @@ -5,6 +5,7 @@ from state_machine.skyeye_state_machine import state_machine class SkyeyeCommand(ABC): export = [] need_check_arg = True + need_check_state = True def __init__(self, name=None): self.name = name @@ -44,9 +45,10 @@ class SkyeyeCommand(ABC): def __call__(self, *args, **kwargs): # CHECK - ## 2.check state - state_machine.check(self.name) - ## 1.check arg + ## 1.check state + if self.need_check_state: + state_machine.check(self.name) + ## 2.check arg if self.need_check_arg: kwargs['arg_ns'] = self.check_arg(kwargs['arg']) @@ -54,7 +56,9 @@ class SkyeyeCommand(ABC): res = self.call(*args, **kwargs) except Exception as e: raise e - state_machine.transition(self.name) + + if self.need_check_state: + state_machine.transition(self.name) # util func def convert_int(x): diff --git a/utils/pycli/skyeye_command/_object_command/machine_object_command.py b/utils/pycli/skyeye_command/_object_command/machine_object_command.py new file mode 100644 index 00000000..36bf066b --- /dev/null +++ b/utils/pycli/skyeye_command/_object_command/machine_object_command.py @@ -0,0 +1,40 @@ +from skyeye_command import SkyeyeCommand +import argparse + +class Machine_list_cpu(SkyeyeCommand): + need_check_state = False + + def create_argparser(self): + parser = argparse.ArgumentParser( + prog='Machine.list_cpu', + description='Show all available cpu on the machine.', + add_help=False) + + return parser + + def call(self, arg='', arg_ns=None, obj=None): + print ("%-20s%-20s" % ("ID", "CpuName")) + cpus = obj.get_cpus() + for i, cpu in enumerate(cpus, 1): + print ("%-20d%-20s" % (i, cpu)) + + return False + +class Machine_list_device(SkyeyeCommand): + need_check_state = False + + def create_argparser(self): + parser = argparse.ArgumentParser( + prog='Machine.list_device', + description='Show all current device.', + add_help=False) + + return parser + + def call(self, arg='', arg_ns=None, obj=None): + print ("%-20s%-20s" % ("ID", "DeviceName")) + devices = obj.get_devices() + for i, device in enumerate(devices, 1): + print ("%-20d%-20s" % (i, device)) + + return False diff --git a/utils/pycli/skyeye_command/bp_create.py b/utils/pycli/skyeye_command/bp_create.py index cd848662..76a2eca6 100644 --- a/utils/pycli/skyeye_command/bp_create.py +++ b/utils/pycli/skyeye_command/bp_create.py @@ -3,7 +3,7 @@ import argparse import os from skyeye_common_module import SkyEyeCreateBreakpoint from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import GetGlobalConfig +import conf2 class Command(SkyeyeCommand): export = ['cli'] @@ -34,10 +34,10 @@ class Command(SkyeyeCommand): return False def complete_arg_1(self, text, line, begidx, endidx): - config = GetGlobalConfig() + config = conf2.get_config() if not config: return [] - cpus = config.get_cpu_list() + cpus = config.get_cpus() return [item for item in cpus if item.startswith(text)] def complete_arg_2(self, text, line, begidx, endidx): diff --git a/utils/pycli/skyeye_command/bp_delete.py b/utils/pycli/skyeye_command/bp_delete.py index 8c7f3cd9..ff857d83 100644 --- a/utils/pycli/skyeye_command/bp_delete.py +++ b/utils/pycli/skyeye_command/bp_delete.py @@ -3,7 +3,7 @@ import argparse import os from skyeye_common_module import * from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import GetGlobalConfig +import conf2 class Command(SkyeyeCommand): export = ['cli'] @@ -34,10 +34,10 @@ class Command(SkyeyeCommand): return False def complete_arg_1(self, text, line, begidx, endidx): - config = GetGlobalConfig() + config = conf2.get_config() if not config: return [] - cpus = config.get_cpu_list() + cpus = config.get_cpus() return [item for item in cpus if item.startswith(text)] def complete_arg_2(self, text, line, begidx, endidx): diff --git a/utils/pycli/skyeye_command/bp_list.py b/utils/pycli/skyeye_command/bp_list.py index 4ce94791..a69b0a6a 100644 --- a/utils/pycli/skyeye_command/bp_list.py +++ b/utils/pycli/skyeye_command/bp_list.py @@ -3,7 +3,7 @@ import argparse import os from skyeye_common_module import SkyEyeGetBpNumbers, SkyEyeGetBreakpointAddrById from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import GetGlobalConfig +import conf2 class Command(SkyeyeCommand): export = ['cli'] @@ -34,8 +34,8 @@ class Command(SkyeyeCommand): return False def complete_arg_1(self, text, line, begidx, endidx): - config = GetGlobalConfig() + config = conf2.get_config() if not config: return [] - cpus = config.get_cpu_list() + cpus = config.get_cpus() return [item for item in cpus if item.startswith(text)] diff --git a/utils/pycli/skyeye_command/define_conf.py b/utils/pycli/skyeye_command/define_conf.py index 6e8497c5..6322b661 100644 --- a/utils/pycli/skyeye_command/define_conf.py +++ b/utils/pycli/skyeye_command/define_conf.py @@ -2,7 +2,8 @@ from . import SkyeyeCommand import argparse import os from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import json_conf, define_json_file, SetGlobalConfig +#from conf import json_conf, define_json_file, SetGlobalConfig +import conf2 class Command(SkyeyeCommand): export = ['cli'] @@ -31,12 +32,9 @@ class Command(SkyeyeCommand): if not os.path.exists(path): raise SkyeyeAPIException(['0x401c0002', path]) - Config = json_conf(parent=None, filename=path) - define_json_file[0] = path - Config.conf_check() - if not Config.instance(): - raise SkyeyeAPIException([ERROR_ALL_F, 'Config can\'t instance.']) - SetGlobalConfig(Config) + conf2.make_config(path) + if cli: + cli.update_config() if cli: cli.open_conf_flag = True diff --git a/utils/pycli/skyeye_command/disable_device_work.py b/utils/pycli/skyeye_command/disable_device_work.py index a08b35f2..cc7ae536 100644 --- a/utils/pycli/skyeye_command/disable_device_work.py +++ b/utils/pycli/skyeye_command/disable_device_work.py @@ -3,8 +3,8 @@ import argparse import os from skyeye_common_module import * from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import GetGlobalConfig import fault_inject as sfi +import conf2 class Command(SkyeyeCommand): export = ['cli'] @@ -24,12 +24,12 @@ class Command(SkyeyeCommand): return parser def call(self, arg='', arg_ns=None, cli=None, script=None, **meta): - config = GetGlobalConfig() + config = conf2.get_config() if not config: msg = 'Can\'t get the config.' raise SkyeyeAPIException([ERROR_ALL_F, msg]) - if arg_ns.device not in config.get_device_list(): + if arg_ns.device not in config.get_devices(): raise SkyeyeAPIException(['0x40050004', arg_ns.device]) try: SkyEyeDisableDeviceWork(arg_ns.device) @@ -39,8 +39,8 @@ class Command(SkyeyeCommand): return False def complete_arg_1(self, text, line, begidx, endidx): - config = GetGlobalConfig() + config = conf2.get_config() if not config: return [] - dl = config.get_device_list() + dl = config.get_devices() return [item for item in dl if item.startswith(text)] diff --git a/utils/pycli/skyeye_command/disassemble.py b/utils/pycli/skyeye_command/disassemble.py index 102e20b5..fcb2d081 100644 --- a/utils/pycli/skyeye_command/disassemble.py +++ b/utils/pycli/skyeye_command/disassemble.py @@ -3,8 +3,8 @@ import argparse import os from skyeye_common_module import * from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import GetGlobalConfig import fault_inject as sfi +import conf2 class Command(SkyeyeCommand): export = ['cli'] @@ -31,7 +31,7 @@ class Command(SkyeyeCommand): return parser def call(self, arg='', arg_ns=None, cli=None, script=None, **meta): - config = GetGlobalConfig() + config = conf2.get_config() if not config: msg = 'Can\'t get the config.' raise SkyeyeAPIException([ERROR_ALL_F, msg]) @@ -43,10 +43,10 @@ class Command(SkyeyeCommand): return False def complete_arg_1(self, text, line, begidx, endidx): - config = GetGlobalConfig() + config = conf2.get_config() if not config: return [] - cpus = config.get_cpu_list() + cpus = config.get_cpus() return [item for item in cpus if item.startswith(text)] def complete_arg_2(self, text, line, begidx, endidx): diff --git a/utils/pycli/skyeye_command/enable_device_work.py b/utils/pycli/skyeye_command/enable_device_work.py index 5b761f5f..a9f80196 100644 --- a/utils/pycli/skyeye_command/enable_device_work.py +++ b/utils/pycli/skyeye_command/enable_device_work.py @@ -3,8 +3,8 @@ import argparse import os from skyeye_common_module import * from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import GetGlobalConfig import fault_inject as sfi +import conf2 class Command(SkyeyeCommand): export = ['cli'] @@ -24,12 +24,12 @@ class Command(SkyeyeCommand): return parser def call(self, arg='', arg_ns=None, cli=None, script=None, **meta): - config = GetGlobalConfig() + config = conf2.get_config() if not config: msg = 'Can\'t get the config.' raise SkyeyeAPIException([ERROR_ALL_F, msg]) - if arg_ns.device not in config.get_device_list(): + if arg_ns.device not in config.get_devices(): raise SkyeyeAPIException(['0x40080004', arg_ns.device]) try: @@ -40,8 +40,8 @@ class Command(SkyeyeCommand): return False def complete_arg_1(self, text, line, begidx, endidx): - config = GetGlobalConfig() + config = conf2.get_config() if not config: return [] - dl = config.get_device_list() + dl = config.get_devices() return [item for item in dl if item.startswith(text)] diff --git a/utils/pycli/skyeye_command/fj_clear.py b/utils/pycli/skyeye_command/fj_clear.py index 8dc03b86..d1e743a7 100644 --- a/utils/pycli/skyeye_command/fj_clear.py +++ b/utils/pycli/skyeye_command/fj_clear.py @@ -3,8 +3,8 @@ import argparse import os from skyeye_common_module import * from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import GetGlobalConfig import fault_inject as sfi +import conf2 class Command(SkyeyeCommand): export = ['cli'] @@ -61,19 +61,19 @@ class Command(SkyeyeCommand): return False def complete_arg_1(self, text, line, begidx, endidx): - config = GetGlobalConfig() + config = conf2.get_config() if not config: return [] - ml = config.get_mach_list() + ml = config.get_machines() return [item for item in ml if item.startswith(text)] def complete_arg_2(self, text, line, begidx, endidx): - config = GetGlobalConfig() + config = conf2.get_config() if not config: return [] mach = line.split()[1] - device_list = config.get_device_list_by_mach(mach) - return [item for item in device_list if item.startswith(text)] + devices = config.get_devices(mach) + return [item for item in devices if item.startswith(text)] def complete_arg_3(self, text, line, begidx, endidx): if '0x'.startswith(text): diff --git a/utils/pycli/skyeye_command/fj_list.py b/utils/pycli/skyeye_command/fj_list.py index 3336cfbe..3bd30144 100644 --- a/utils/pycli/skyeye_command/fj_list.py +++ b/utils/pycli/skyeye_command/fj_list.py @@ -3,7 +3,6 @@ import argparse import os from skyeye_common_module import * from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import GetGlobalConfig import fault_inject as sfi class Command(SkyeyeCommand): diff --git a/utils/pycli/skyeye_command/fj_set.py b/utils/pycli/skyeye_command/fj_set.py index 26f1cdee..1b2ee01e 100644 --- a/utils/pycli/skyeye_command/fj_set.py +++ b/utils/pycli/skyeye_command/fj_set.py @@ -3,8 +3,8 @@ import argparse import os from skyeye_common_module import * from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import GetGlobalConfig import fault_inject as sfi +import conf2 class Command(SkyeyeCommand): export = ['cli'] @@ -61,19 +61,19 @@ class Command(SkyeyeCommand): return False def complete_arg_1(self, text, line, begidx, endidx): - config = GetGlobalConfig() + config = conf2.get_config() if not config: return [] - ml = config.get_mach_list() + ml = config.get_machines() return [item for item in ml if item.startswith(text)] def complete_arg_2(self, text, line, begidx, endidx): - config = GetGlobalConfig() + config = conf2.get_config() if not config: return [] mach = line.split()[1] - device_list = config.get_device_list_by_mach(mach) - return [item for item in device_list if item.startswith(text)] + devices = config.get_devices(mach) + return [item for item in devices if item.startswith(text)] def complete_arg_3(self, text, line, begidx, endidx): if '0x'.startswith(text): diff --git a/utils/pycli/skyeye_command/get_pc.py b/utils/pycli/skyeye_command/get_pc.py index 990586be..3abf8c04 100644 --- a/utils/pycli/skyeye_command/get_pc.py +++ b/utils/pycli/skyeye_command/get_pc.py @@ -3,9 +3,8 @@ import argparse import os from skyeye_common_module import * from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import GetGlobalConfig -import fault_inject as sfi import pytimer +import conf2 class Command(SkyeyeCommand): export = ['cli'] @@ -25,12 +24,12 @@ class Command(SkyeyeCommand): return parser def call(self, arg='', arg_ns=None, cli=None, script=None, **meta): - config = GetGlobalConfig() + config = conf2.get_config() if not config: msg = 'Can\'t get the config.' raise SkyeyeAPIException([ERROR_ALL_F, msg]) - if arg_ns.cpu not in config.get_cpu_list(): + if arg_ns.cpu not in config.get_cpus(): raise SkyeyeAPIException(['0x40200004', arg_ns.cpu]) try: pc = SkyEyeGetPC(arg_ns.cpu) @@ -41,8 +40,8 @@ class Command(SkyeyeCommand): return False def complete_arg_1(self, text, line, begidx, endidx): - config = GetGlobalConfig() + config = conf2.get_config() if not config: return [] - cpus = config.get_cpu_list() + cpus = config.get_cpus() return [item for item in cpus if item.startswith(text)] diff --git a/utils/pycli/skyeye_command/list_attr.py b/utils/pycli/skyeye_command/list_attr.py index 8e2b39cb..6ec0d814 100644 --- a/utils/pycli/skyeye_command/list_attr.py +++ b/utils/pycli/skyeye_command/list_attr.py @@ -1,9 +1,8 @@ from . import SkyeyeCommand, convert_int import argparse import os -from skyeye_common_module import SkyEyeGetClassList, SkyEyeGetClassAttrList, SkyEyeGetClassAttrInfo +from skyeye_common_module import * from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import GetGlobalConfig class Command(SkyeyeCommand): export = ['cli'] diff --git a/utils/pycli/skyeye_command/list_class.py b/utils/pycli/skyeye_command/list_class.py index 611ecd61..ddf80a69 100644 --- a/utils/pycli/skyeye_command/list_class.py +++ b/utils/pycli/skyeye_command/list_class.py @@ -2,9 +2,7 @@ from . import SkyeyeCommand, table_print import argparse import os from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import GetGlobalConfig -import fault_inject as sfi -from skyeye_common_module import SkyEyeGetClassList +from skyeye_common_module import * class Command(SkyeyeCommand): export = ['cli'] diff --git a/utils/pycli/skyeye_command/list_connect.py b/utils/pycli/skyeye_command/list_connect.py index f8a9c9d0..7eadcfd5 100644 --- a/utils/pycli/skyeye_command/list_connect.py +++ b/utils/pycli/skyeye_command/list_connect.py @@ -3,7 +3,6 @@ import argparse import os from skyeye_common_module import SkyEyeGetClassList, SkyEyeGetClassConnectList from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import GetGlobalConfig class Command(SkyeyeCommand): export = ['cli'] diff --git a/utils/pycli/skyeye_command/list_cpu.py b/utils/pycli/skyeye_command/list_cpu.py index 983a95e5..81ed85b5 100644 --- a/utils/pycli/skyeye_command/list_cpu.py +++ b/utils/pycli/skyeye_command/list_cpu.py @@ -3,7 +3,7 @@ import argparse import os from skyeye_common_module import SkyEyeCreateBreakpoint from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import GetGlobalConfig +import conf2 class Command(SkyeyeCommand): export = ['cli'] @@ -17,14 +17,15 @@ class Command(SkyeyeCommand): return parser def call(self, arg='', arg_ns=None, cli=None, script=None, **meta): - config = GetGlobalConfig() + config = conf2.get_config() if not config: msg = 'Can\'t get the config.' raise SkyeyeAPIException([ERROR_ALL_F, msg]) - cpus = config.get_cpu_list() - print ("%-20s%-20s" % ("ID", "CpuName")) - for i, cpu in enumerate(cpus, 1): - print ("%-20d%-20s" % (i, cpu)) + machines = config.get_machines() + print ("%-30s%-30s" % ("CpuName", "BelongBoard")) + for mach, mach_obj in machines.items(): + for cpu in mach_obj.get_cpus(): + print ("%-30s%-30s" % (cpu, mach)) return False diff --git a/utils/pycli/skyeye_command/list_device.py b/utils/pycli/skyeye_command/list_device.py index 1af8b05e..68e4b09f 100644 --- a/utils/pycli/skyeye_command/list_device.py +++ b/utils/pycli/skyeye_command/list_device.py @@ -2,8 +2,7 @@ from . import SkyeyeCommand, convert_int import argparse import os from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import GetGlobalConfig -import fault_inject as sfi +import conf2 class Command(SkyeyeCommand): export = ['cli'] @@ -24,37 +23,31 @@ class Command(SkyeyeCommand): return parser def call(self, arg='', arg_ns=None, cli=None, script=None, **meta): - config = GetGlobalConfig() + config = conf2.get_config() if not config: msg = 'Can\'t get the config.' raise SkyeyeAPIException([ERROR_ALL_F, msg]) + machines = config.get_machines() + print ("%-30s%-30s" % ("DeviceName", "BelongBoard")) if arg_ns.machine is None: - print ("%-30s%-30s" % ("DeviceName", "BelongBoard")) - machlist = config.get_mach_list() - for mach in machlist: - mach_cls = config.get_mach_classname(mach) - if mach_cls == 'pc_mach': - cpu = config.get_cpuname_by_mach(mach) - if cpu: - x86_obj = x86(cpu) - for device in x86_obj.devices: - print ("%-30s%-30s" % (device.name, mach)) - else: - device_list = config.get_device_list_by_mach(mach) - for device in device_list: - print ("%-30s%-30s" % (device, mach)) + n_mach = len(machines) + for i, mach in enumerate(machines, 1): + for device in config.get_devices(mach): + print ("%-30s%-30s" % (device, mach)) + if i < n_mach: + print() else: - print ("%-30s%-30s" % ("ID", "DeviceName")) - device_list = config.get_device_list_by_mach(arg_ns.machine) - for i in range(0, len(device_list)): - print ("%-30s%-30s" % (i+1, device_list[i])) + devices = config.get_devices(arg_ns.machine) + if devices: + for device in devices: + print ("%-30s%-30s" % (device, arg_ns.machine)) return False def complete_arg_1(self, text, line, begidx, endidx): - config = GetGlobalConfig() + config = conf2.get_config() if not config: return [] - ml = config.get_mach_list() + ml = config.get_machines() return [item for item in ml if item.startswith(text)] diff --git a/utils/pycli/skyeye_command/list_iface.py b/utils/pycli/skyeye_command/list_iface.py index 37656a61..caa39b85 100644 --- a/utils/pycli/skyeye_command/list_iface.py +++ b/utils/pycli/skyeye_command/list_iface.py @@ -2,9 +2,7 @@ from . import SkyeyeCommand, table_print import argparse import os from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import GetGlobalConfig -import fault_inject as sfi -from skyeye_common_module import SkyEyeGetClassIfaceList, SkyEyeGetClassList +from skyeye_common_module import * class Command(SkyeyeCommand): export = ['cli'] diff --git a/utils/pycli/skyeye_command/list_machines.py b/utils/pycli/skyeye_command/list_machines.py index cebf88af..9379dc0a 100644 --- a/utils/pycli/skyeye_command/list_machines.py +++ b/utils/pycli/skyeye_command/list_machines.py @@ -1,7 +1,7 @@ from . import SkyeyeCommand import argparse import os -from conf import GetGlobalConfig +import conf2 from exception import SkyeyeAPIException, ERROR_ALL_F class Command(SkyeyeCommand): @@ -16,14 +16,13 @@ class Command(SkyeyeCommand): return parser def call(self, arg='', arg_ns=None, cli=None, script=None, **meta): - config = GetGlobalConfig() + config = conf2.get_config() if not config: msg = 'Can\'t get the config.' raise SkyeyeAPIException([ERROR_ALL_F, msg]) - ml = config.get_mach_list() print("%-20s%-20s" % ("Id", "MachinesName")) - for i in range(len(ml)): - print("%-20s%-20s" % (i+1, ml[i])) + for i, mach in enumerate(config.get_machines(), 1): + print("%-20s%-20s" % (i, mach)) return False diff --git a/utils/pycli/skyeye_command/list_register.py b/utils/pycli/skyeye_command/list_register.py index a350a4bc..22cbd3ba 100644 --- a/utils/pycli/skyeye_command/list_register.py +++ b/utils/pycli/skyeye_command/list_register.py @@ -3,8 +3,10 @@ import argparse import os from skyeye_common_module import SkyEyeCreateBreakpoint from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import GetGlobalConfig import fault_inject as sfi +import conf2 + +from skyeye_common_module import * class Command(SkyeyeCommand): export = ['cli'] @@ -15,12 +17,6 @@ class Command(SkyeyeCommand): description='Show all registers of a device.', add_help=False) - parser.add_argument( - 'machine', - metavar='', - help='machine name', - ) - parser.add_argument( 'device', metavar='', @@ -30,32 +26,28 @@ class Command(SkyeyeCommand): return parser def call(self, arg='', arg_ns=None, cli=None, script=None, **meta): - config = GetGlobalConfig() + config = conf2.get_config() if not config: msg = 'Can\'t get the config.' raise SkyeyeAPIException([ERROR_ALL_F, msg]) - ret = sfi.get_device_register_info(arg_ns.machine, arg_ns.device) - if not ret: - print('Device "%s" doesn\'t have any register.' % arg_ns.device) - else: - print ("%-20s%-20s%-20s" % ("Register", "Value(HEX)", "Address(HEX)")) - for i in ret: - print ("%-20s%-20x%-20x" % (i, ret[i]["value"], ret[i]["addr"])) + device = config.get_device(arg_ns.device) + if device is None: + msg = 'No device "%s" in the current config.' % arg_ns.device + raise SkyeyeAPIException([ERROR_ALL_F, msg]) + regs = device.get_register_list() + if regs is None: + msg = 'No registers on the the device "%s".' % arg_ns.device + raise SkyeyeAPIException([ERROR_ALL_F, msg]) + + regs.show() return False def complete_arg_1(self, text, line, begidx, endidx): - config = GetGlobalConfig() + config = conf2.get_config() if not config: return [] - ml = config.get_mach_list() - return [item for item in ml if item.startswith(text)] - def complete_arg_2(self, text, line, begidx, endidx): - config = GetGlobalConfig() - if not config: - return [] - mach = line.split()[1] - device_list = config.get_device_list_by_mach(mach) - return [item for item in device_list if item.startswith(text)] + devices = config.get_devices() + return [item for item in devices if item.startswith(text)] diff --git a/utils/pycli/skyeye_command/load_binary.py b/utils/pycli/skyeye_command/load_binary.py index d8e7ea87..75dded37 100644 --- a/utils/pycli/skyeye_command/load_binary.py +++ b/utils/pycli/skyeye_command/load_binary.py @@ -2,8 +2,8 @@ from . import SkyeyeCommand import argparse import os from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import GetGlobalConfig, binary_l from skyeye_common_module import SkyEyeLoadBinary +import conf2 class Command(SkyeyeCommand): export = ['cli'] @@ -35,24 +35,23 @@ class Command(SkyeyeCommand): else: path = arg_ns.path - config = GetGlobalConfig() + config = conf2.get_config() if not config: msg = 'Can\'t get the config.' raise SkyeyeAPIException([ERROR_ALL_F, msg]) - if arg_ns.cpu not in config.get_cpu_list(): + if arg_ns.cpu not in config.get_cpus(): raise SkyeyeAPIException(['0x40030004', arg_ns.cpu]) if not os.path.exists(path): raise SkyeyeAPIException(['0x40030002', arg_ns.path]) ret = SkyEyeLoadBinary(arg_ns.cpu, path) - binary_l[arg_ns.cpu] = path return False def complete_arg_1(self, text, line, begidx, endidx): - config = GetGlobalConfig() + config = conf2.get_config() if not config: return [] - cpus = config.get_cpu_list() + cpus = config.get_cpus() return [item for item in cpus if item.startswith(text)] def complete_arg_2(self, text, line, begidx, endidx): @@ -67,4 +66,3 @@ class Command(SkyeyeCommand): files = [(os.path.join(dir_name, item)) for item in files] items = files + dirs return [item for item in items if item.startswith(text)] - diff --git a/utils/pycli/skyeye_command/load_file.py b/utils/pycli/skyeye_command/load_file.py index e5a1401c..01cafaf0 100644 --- a/utils/pycli/skyeye_command/load_file.py +++ b/utils/pycli/skyeye_command/load_file.py @@ -2,7 +2,7 @@ from . import SkyeyeCommand, convert_int import argparse import os from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import GetGlobalConfig +import conf2 from skyeye_common_module import SkyEyeLoadFile class Command(SkyeyeCommand): @@ -42,15 +42,14 @@ class Command(SkyeyeCommand): else: path = arg_ns.path - config = GetGlobalConfig() + #config = GetGlobalConfig() + config = conf2.get_config() + if not config: msg = 'Can\'t get the config.' raise SkyeyeAPIException([ERROR_ALL_F, msg]) - if not config: - raise SkyeyeAPIException(['0x40030003']) - - if arg_ns.cpu not in config.get_cpu_list(): + if arg_ns.cpu not in config.get_cpus(): raise SkyeyeAPIException(['0x40030004', arg_ns.cpu]) if not os.path.exists(path): @@ -60,10 +59,10 @@ class Command(SkyeyeCommand): return False def complete_arg_1(self, text, line, begidx, endidx): - config = GetGlobalConfig() + config = conf2.get_config() if not config: return [] - cpus = config.get_cpu_list() + cpus = config.get_cpus() return [item for item in cpus if item.startswith(text)] def complete_arg_2(self, text, line, begidx, endidx): diff --git a/utils/pycli/skyeye_command/md.py b/utils/pycli/skyeye_command/md.py index 6c7d0b19..b427fbe9 100644 --- a/utils/pycli/skyeye_command/md.py +++ b/utils/pycli/skyeye_command/md.py @@ -3,8 +3,8 @@ import argparse import os from skyeye_common_module import * from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import GetGlobalConfig import fault_inject as sfi +import conf2 class Command(SkyeyeCommand): export = ['cli'] @@ -31,22 +31,22 @@ class Command(SkyeyeCommand): return parser def call(self, arg='', arg_ns=None, cli=None, script=None, **meta): - config = GetGlobalConfig() + config = conf2.get_config() if not config: msg = 'Can\'t get the config.' raise SkyeyeAPIException([ERROR_ALL_F, msg]) ret = SkyEyeReadMemory8(arg_ns.cpu, arg_ns.addr) print ("%-20s%-20s" % ("Addr(HEX)", "Value(HEX)")) - print ("%-20x%-20x" % (arg_ns.addr, ret)) + print ("%-20x%-20.2x" % (arg_ns.addr, ret)) return False def complete_arg_1(self, text, line, begidx, endidx): - config = GetGlobalConfig() + config = conf2.get_config() if not config: return [] - cpus = config.get_cpu_list() + cpus = config.get_cpus() return [item for item in cpus if item.startswith(text)] def complete_arg_2(self, text, line, begidx, endidx): diff --git a/utils/pycli/skyeye_command/mm_info.py b/utils/pycli/skyeye_command/mm_info.py index f942e664..d72464b1 100644 --- a/utils/pycli/skyeye_command/mm_info.py +++ b/utils/pycli/skyeye_command/mm_info.py @@ -3,7 +3,6 @@ import argparse import os from skyeye_common_module import * from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import GetGlobalConfig class Command(SkyeyeCommand): export = ['cli'] diff --git a/utils/pycli/skyeye_command/open_instr_record.py b/utils/pycli/skyeye_command/open_instr_record.py index 9e28d3c5..1051dc9b 100644 --- a/utils/pycli/skyeye_command/open_instr_record.py +++ b/utils/pycli/skyeye_command/open_instr_record.py @@ -5,8 +5,8 @@ from skyeye_common_module import * from exception import SkyeyeAPIException, ERROR_ALL_F from conf import GetGlobalConfig import fault_inject as sfi -from conf import * import tools +import conf2 class Command(SkyeyeCommand): export = ['cli'] @@ -32,12 +32,12 @@ class Command(SkyeyeCommand): return parser def call(self, arg='', arg_ns=None, cli=None, script=None, **meta): - config = GetGlobalConfig() + config = conf2.get_config() if not config: msg = 'Can\'t get the config.' raise SkyeyeAPIException([ERROR_ALL_F, msg]) - if arg_ns.cpu not in config.get_cpu_list(): + if arg_ns.cpu not in config.get_cpus(): raise SkyeyeAPIException(['0x40210004', arg_ns.cpu]) print(arg_ns.cpu, arg_ns.log_file) try: @@ -48,3 +48,10 @@ class Command(SkyeyeCommand): raise SkyeyeAPIException(['0x40212101', e]) return False + + def complete_arg_1(self, text, line, begidx, endidx): + config = conf2.get_config() + if not config: + return [] + cpus = config.get_cpus() + return [item for item in cpus if item.startswith(text)] diff --git a/utils/pycli/skyeye_command/quit.py b/utils/pycli/skyeye_command/quit.py index 898134c0..198aedd8 100644 --- a/utils/pycli/skyeye_command/quit.py +++ b/utils/pycli/skyeye_command/quit.py @@ -3,8 +3,6 @@ import argparse import os from skyeye_common_module import * from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import GetGlobalConfig -import fault_inject as sfi import network_control as NetCtrl import mips @@ -21,8 +19,6 @@ class Command(SkyeyeCommand): def call(self, arg='', arg_ns=None, cli=None, script=None, **meta): cli.postloop() - if mips.mips_thread != None: - mips.mips_thread.stop() NetCtrl.server_stop() SkyEyeQuit() diff --git a/utils/pycli/skyeye_command/remote_gdb.py b/utils/pycli/skyeye_command/remote_gdb.py index 2d262458..29fb0362 100644 --- a/utils/pycli/skyeye_command/remote_gdb.py +++ b/utils/pycli/skyeye_command/remote_gdb.py @@ -3,7 +3,6 @@ import argparse import os from skyeye_common_module import * from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import GetGlobalConfig import fault_inject as sfi class Command(SkyeyeCommand): diff --git a/utils/pycli/skyeye_command/reset.py b/utils/pycli/skyeye_command/reset.py index 81965625..89b87633 100644 --- a/utils/pycli/skyeye_command/reset.py +++ b/utils/pycli/skyeye_command/reset.py @@ -3,9 +3,8 @@ import argparse import os from skyeye_common_module import * from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import GetGlobalConfig -import fault_inject as sfi import pytimer +import conf2 class Command(SkyeyeCommand): export = ['cli'] @@ -22,5 +21,6 @@ class Command(SkyeyeCommand): SkyEyeReset() pytimer.set_running(False) self.open_conf_flag = False + conf2.clear_config() return False diff --git a/utils/pycli/skyeye_command/reverse.py b/utils/pycli/skyeye_command/reverse.py index 5704601e..54bc4480 100644 --- a/utils/pycli/skyeye_command/reverse.py +++ b/utils/pycli/skyeye_command/reverse.py @@ -7,10 +7,10 @@ from conf import GetGlobalConfig import tools import os import sys -from conf import * import traceback import shutil from se_path import InstallDir +import conf2 class Command(SkyeyeCommand): export = ['cli'] @@ -37,7 +37,7 @@ class Command(SkyeyeCommand): return parser def call(self, arg='', arg_ns=None, cli=None, script=None, **meta): - config = GetGlobalConfig() + config = conf2.get_config() if not config: msg = 'Can\'t get the config.' raise SkyeyeAPIException([ERROR_ALL_F, msg]) @@ -55,11 +55,6 @@ class Command(SkyeyeCommand): raise SkyeyeAPIException(['0x40131301']) core = args[0] - config = GetGlobalConfig() - if not config: - msg = 'Can\'t get the config.' - raise SkyeyeAPIException([ERROR_ALL_F, msg]) - if arg_ns.cpu not in config.get_cpu_list(): raise SkyeyeAPIException(['0x40130004', arg_ns.cpu]) @@ -87,8 +82,8 @@ class Command(SkyeyeCommand): return False def complete_arg_1(self, text, line, begidx, endidx): - config = GetGlobalConfig() + config = conf2.get_config() if not config: return [] - cpus = config.get_cpu_list() + cpus = config.get_cpus() return [item for item in cpus if item.startswith(text)] diff --git a/utils/pycli/skyeye_command/reverse_disable.py b/utils/pycli/skyeye_command/reverse_disable.py index 55330432..9079d1b4 100644 --- a/utils/pycli/skyeye_command/reverse_disable.py +++ b/utils/pycli/skyeye_command/reverse_disable.py @@ -12,11 +12,11 @@ import shutil from se_path import InstallDir import errormessage -from conf import * from exception import * import traceback import shutil from se_path import InstallDir +import conf2 class Command(SkyeyeCommand): export = ['cli'] @@ -30,7 +30,7 @@ class Command(SkyeyeCommand): return parser def call(self, arg='', arg_ns=None, cli=None, script=None, **meta): - config = GetGlobalConfig() + config = conf2.get_config() if not config: msg = 'Can\'t get the config.' raise SkyeyeAPIException([ERROR_ALL_F, msg]) diff --git a/utils/pycli/skyeye_command/reverse_enable.py b/utils/pycli/skyeye_command/reverse_enable.py index dbce0f2f..a393355a 100644 --- a/utils/pycli/skyeye_command/reverse_enable.py +++ b/utils/pycli/skyeye_command/reverse_enable.py @@ -10,11 +10,11 @@ from conf import * import traceback import shutil from se_path import InstallDir -from conf import * from exception import * import traceback import shutil from se_path import InstallDir +import conf2 class Command(SkyeyeCommand): export = ['cli'] @@ -28,7 +28,7 @@ class Command(SkyeyeCommand): return parser def call(self, arg='', arg_ns=None, cli=None, script=None, **meta): - config = GetGlobalConfig() + config = conf2.get_config() if not config: msg = 'Can\'t get the config.' raise SkyeyeAPIException([ERROR_ALL_F, msg]) @@ -48,10 +48,10 @@ class Command(SkyeyeCommand): shutil.rmtree(ckpt) full_ckpt_dir = tools.create_chp_dir(ckpt) - mach_list = config.get_mach_list() + mach_list = config.get_machines() for mach in mach_list: cpu = config.get_cpuname_by_mach(mach) - device_list = config.get_device_list_by_mach(mach) + device_list = config.get_devices(mach) for device in device_list: cls = config.get_classname(device) if cls == "image": diff --git a/utils/pycli/skyeye_command/run.py b/utils/pycli/skyeye_command/run.py index 9cb492f2..63bd905e 100644 --- a/utils/pycli/skyeye_command/run.py +++ b/utils/pycli/skyeye_command/run.py @@ -3,7 +3,6 @@ import argparse import os from skyeye_common_module import * from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import GetGlobalConfig import fault_inject as sfi import pytimer diff --git a/utils/pycli/skyeye_command/run_command.py b/utils/pycli/skyeye_command/run_command.py index 4ca7beb9..0c073f8f 100644 --- a/utils/pycli/skyeye_command/run_command.py +++ b/utils/pycli/skyeye_command/run_command.py @@ -4,7 +4,6 @@ import os import cli from tools import SkyEyeSetScriptPath from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import SetGlobalScript import project_config as pc from importlib import import_module, reload diff --git a/utils/pycli/skyeye_command/run_script.py b/utils/pycli/skyeye_command/run_script.py index 454cc103..f68fd026 100644 --- a/utils/pycli/skyeye_command/run_script.py +++ b/utils/pycli/skyeye_command/run_script.py @@ -4,7 +4,6 @@ import os import cli from tools import SkyEyeSetScriptPath from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import SetGlobalScript import project_config as pc from importlib import import_module, reload @@ -26,19 +25,18 @@ class Command(SkyeyeCommand): return parser def call(self, arg='', arg_ns=None, cli=None, script=None, **meta): - SetGlobalScript(arg_ns.path) full_file_name = os.path.realpath(arg_ns.path) if not os.path.exists(arg_ns.path): raise SkyeyeAPIException(['0x40160002', arg_ns.path]) SkyEyeSetScriptPath(full_file_name) - commands = self._get_commands_form_script(full_file_name) + commands = self._get_commands_from_script(full_file_name) for command, arg in commands: command(arg=arg, cli=cli, script=full_file_name) return False - def _get_commands_form_script(self, path): + def _get_commands_from_script(self, path): skyeye_command = import_module('skyeye_command') commands = [] with open(path) as f: diff --git a/utils/pycli/skyeye_command/set_mode.py b/utils/pycli/skyeye_command/set_mode.py index c58da6c9..301992f3 100644 --- a/utils/pycli/skyeye_command/set_mode.py +++ b/utils/pycli/skyeye_command/set_mode.py @@ -3,8 +3,7 @@ import argparse import os from skyeye_common_module import * from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import GetGlobalConfig, SetAllToDyncom -import fault_inject as sfi +import conf2 class Command(SkyeyeCommand): export = ['cli'] @@ -26,13 +25,15 @@ class Command(SkyeyeCommand): return parser def call(self, arg='', arg_ns=None, cli=None, script=None, **meta): - config = GetGlobalConfig() + config = conf2.get_config() if not config: msg = 'Can\'t get the config.' raise SkyeyeAPIException([ERROR_ALL_F, msg]) - print ("--%d--" % arg_ns.mode) - SetAllToDyncom(arg_ns.mode) + cpus = config.get_cpus() + for cpu in cpus: + SkyEyeCpuSetMode(cpu, arg_ns.mode) + return False def complete_arg_1(self, text, line, begidx, endidx): diff --git a/utils/pycli/skyeye_command/set_pc.py b/utils/pycli/skyeye_command/set_pc.py index 705aabc4..4cb595d5 100644 --- a/utils/pycli/skyeye_command/set_pc.py +++ b/utils/pycli/skyeye_command/set_pc.py @@ -3,9 +3,9 @@ import argparse import os from skyeye_common_module import * from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import GetGlobalConfig import fault_inject as sfi import pytimer +import conf2 class Command(SkyeyeCommand): export = ['cli'] @@ -41,10 +41,10 @@ class Command(SkyeyeCommand): return False def complete_arg_1(self, text, line, begidx, endidx): - config = GetGlobalConfig() + config = conf2.get_config() if not config: return [] - cpus = config.get_cpu_list() + cpus = config.get_cpus() return [item for item in cpus if item.startswith(text)] def complete_arg_2(self, text, line, begidx, endidx): diff --git a/utils/pycli/skyeye_command/set_register.py b/utils/pycli/skyeye_command/set_register.py index e265d70d..07bca403 100644 --- a/utils/pycli/skyeye_command/set_register.py +++ b/utils/pycli/skyeye_command/set_register.py @@ -2,10 +2,9 @@ from . import SkyeyeCommand, convert_int import argparse import os from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import GetGlobalConfig import fault_inject as sfi - -from skyeye_common_module import SkyEyeGetDevRegIdByName, SkyEyeSetDevRegValueById +from skyeye_common_module import * +import conf2 class Command(SkyeyeCommand): export = ['cli'] @@ -16,12 +15,6 @@ class Command(SkyeyeCommand): description='Set a value to a register.', add_help=False) - parser.add_argument( - 'machine', - metavar='', - help='machine name', - ) - parser.add_argument( 'device', metavar='', @@ -44,36 +37,32 @@ class Command(SkyeyeCommand): return parser def call(self, arg='', arg_ns=None, cli=None, script=None, **meta): - regid = SkyEyeGetDevRegIdByName(arg_ns.machine, arg_ns.device, arg_ns.register) - ret = SkyEyeSetDevRegValueById(arg_ns.machine, arg_ns.device, arg_ns.value, regid) - + regid = SkyEyeGetDevRegIdByName(None, arg_ns.device, arg_ns.register) + ret = SkyEyeSetDevRegValueById(None, arg_ns.device, arg_ns.value, regid) return False def complete_arg_1(self, text, line, begidx, endidx): - config = GetGlobalConfig() + config = conf2.get_config() if not config: return [] - ml = config.get_mach_list() - return [item for item in ml if item.startswith(text)] + devices = config.get_devices() + return [item for item in devices if item.startswith(text)] def complete_arg_2(self, text, line, begidx, endidx): - config = GetGlobalConfig() - if not config: + _, device_name, *_ = line.split() + config = conf2.get_config() + device = config.get_device(device_name) + if not device: return [] - mach = line.split()[1] - device_list = config.get_device_list_by_mach(mach) - return [item for item in device_list if item.startswith(text)] - def complete_arg_3(self, text, line, begidx, endidx): - _, mach, device, *_ = line.split() - ret = sfi.get_device_register_info(mach, device) - if not ret: + reg_list = device.get_register_list() + if not reg_list: return [] - # FIXME - items = [item.decode('utf-8') for item in ret] - return [item for item in items if item.startswith(text)] - def complete_arg_4(self, text, line, begidx, endidx): + regs = reg_list.get_registers() + return [item for item in regs if item.startswith(text)] + + def complete_arg_3(self, text, line, begidx, endidx): if '0x'.startswith(text): return ['0x'] return [] diff --git a/utils/pycli/skyeye_command/speed.py b/utils/pycli/skyeye_command/speed.py index c0b19ea0..73d9ed4e 100644 --- a/utils/pycli/skyeye_command/speed.py +++ b/utils/pycli/skyeye_command/speed.py @@ -3,7 +3,6 @@ import argparse import os from skyeye_common_module import * from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import GetGlobalConfig import fault_inject as sfi import mips @@ -19,9 +18,8 @@ class Command(SkyeyeCommand): return parser def call(self, arg='', arg_ns=None, cli=None, script=None, **meta): - - mips_dic = mips.get() - for item in mips_dic: - print ("CPU:%20s SPEED:%d" % (item, mips_dic[item])) + mips_dict = mips.get() + for item in mips_dict: + print ("CPU:%20s SPEED:%d" % (item, mips_dict[item])) return False diff --git a/utils/pycli/skyeye_command/stepi.py b/utils/pycli/skyeye_command/stepi.py index 76ee1b91..69432786 100644 --- a/utils/pycli/skyeye_command/stepi.py +++ b/utils/pycli/skyeye_command/stepi.py @@ -3,9 +3,9 @@ import argparse import os from skyeye_common_module import * from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import GetGlobalConfig import fault_inject as sfi import pytimer +import conf2 class Command(SkyeyeCommand): export = ['cli'] @@ -37,8 +37,8 @@ class Command(SkyeyeCommand): return False def complete_arg_1(self, text, line, begidx, endidx): - config = GetGlobalConfig() + config = conf2.get_config() if not config: return [] - cpus = config.get_cpu_list() + cpus = config.get_cpus() return [item for item in cpus if item.startswith(text)] diff --git a/utils/pycli/skyeye_command/stop.py b/utils/pycli/skyeye_command/stop.py index 50613047..9aa07b99 100644 --- a/utils/pycli/skyeye_command/stop.py +++ b/utils/pycli/skyeye_command/stop.py @@ -3,7 +3,6 @@ import argparse import os from skyeye_common_module import * from exception import SkyeyeAPIException, ERROR_ALL_F -from conf import GetGlobalConfig import fault_inject as sfi import pytimer diff --git a/utils/pycli/skyeye_common_module.py b/utils/pycli/skyeye_common_module.py index 79b83ca0..8ba44082 100644 --- a/utils/pycli/skyeye_common_module.py +++ b/utils/pycli/skyeye_common_module.py @@ -77,6 +77,10 @@ class skyeye_api_result(Structure): ] class SkyeyeAPIResult(skyeye_api_result): + @property + def retStrValue(self): + return super().retStrValue.decode('utf-8') + @property def list(self): res = getattr(self, '_list', None) -- Gitee From 29a43ed81dc2d3c14ac6d04b00664d261482e1ae Mon Sep 17 00:00:00 2001 From: Liu Shuo <49305054@qq.com> Date: Tue, 7 Jun 2022 09:34:59 +0800 Subject: [PATCH 2/6] [fix] add config callback for updating cli.config --- utils/pycli/skyeye_cli.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/utils/pycli/skyeye_cli.py b/utils/pycli/skyeye_cli.py index 677350e1..bc414197 100755 --- a/utils/pycli/skyeye_cli.py +++ b/utils/pycli/skyeye_cli.py @@ -23,6 +23,7 @@ import fault_inject as sfi import argparse import network_control as NetCtrl import skyeye_command +import conf2 sys.path.append(se_path.SkyEyeBin) @@ -115,6 +116,9 @@ class SkyEyeCli(cmd.Cmd): # 参数补齐时不截断形如xxx-yyy的命令 self.identchars += '-/.' + #conf callback + self.register_config_callback() + def print_welcome_message(self): os_info = platform.system() if operator.eq(os_info, "Linux"): @@ -228,11 +232,11 @@ class SkyEyeCli(cmd.Cmd): return super().complete(text, state) def default(self, line): - res = self.Do_object_command(line) + res = self.object_system_access(line) if not res: print('[Error] Unknown command: %s\n'%line) - def Do_object_command(self, line): + def object_system_access(self, line): if self.config: root = self.config.get_object_tree() cmd, arg, line = self.parseline(line) @@ -251,9 +255,12 @@ class SkyEyeCli(cmd.Cmd): _skyeye_conf_obj = None def update_config(self): - import conf2 SkyEyeCli._skyeye_conf_obj = conf2.get_config() @property def config(self): return self._skyeye_conf_obj + + def register_config_callback(self): + conf2.add_config_done_callback('cli_config_update', self.update_config) + conf2.add_config_clear_callback('cli_config_update', self.update_config) -- Gitee From de5b05cbb1a8a669b4ba396de2df4830ac8ca105 Mon Sep 17 00:00:00 2001 From: Liu Shuo <49305054@qq.com> Date: Thu, 23 Jun 2022 11:41:38 +0800 Subject: [PATCH 3/6] [feature] add some object commands --- utils/pycli/objects.py | 116 ++++++++--------- utils/pycli/skyeye_command/_object_command.py | 122 ++++++++++++++++++ 2 files changed, 178 insertions(+), 60 deletions(-) create mode 100644 utils/pycli/skyeye_command/_object_command.py diff --git a/utils/pycli/objects.py b/utils/pycli/objects.py index a89cc691..d3eadf0e 100644 --- a/utils/pycli/objects.py +++ b/utils/pycli/objects.py @@ -1,8 +1,16 @@ +from exception import SkyeyeAPIException, ERROR_ALL_F +from skyeye_common_module import * +from collections import OrderedDict + class Node: - def __init__(self, name=None, parent=None): + def __init__(self, name=None, parent=None, **kwargs): self.name = name self.parent = parent + for k, v in kwargs.items(): + setattr(self, k, v) self.cli_attrs = {} + self.object_cmd, self.object_cmd_kwargs = self.create_obj_command() + self.attach_to_parent(parent) def attach_to_parent(self, parent): if parent: @@ -38,27 +46,34 @@ class Node: def match_cli_attr_name(self, text): return [name for name in self.cli_attrs if name.startswith(text)] + def create_obj_command(self): + from skyeye_command._object_command import ObjectCommand + if self.name: + cmd = ObjectCommand(self.name) + else: + cmd = None + cmd_kwargs = {'obj': self} + return cmd, cmd_kwargs + + def __call__(self, arg=''): + if self.object_cmd: + self.object_cmd(arg=arg, **self.object_cmd_kwargs) + class Root(Node): def __str__(self): return '' class MethodNode(Node): def __init__(self, name, parent, cmd): - super().__init__(name, parent) - self.cmd = cmd - self.attach_to_parent(parent) + super().__init__(name, parent, cmd=cmd) - def __call__(self, arg=''): - self.cmd(arg=arg, obj=self.parent) + def create_obj_command(self): + return self.cmd, {'obj': self.parent} class Component(Node): - def __init__(self, name, parent=None, base='', cls='', iface_list=(), attr_list=()): - super().__init__(name, parent) - self.base = base - self.cls = cls - self.iface_list = iface_list - self.attr_list = attr_list - self.attach_to_parent(parent) + def __init__(self, name, parent, base='', cls='', iface_list=(), attr_list=()): + super().__init__(name, parent, base=base, cls=cls, \ + iface_list=iface_list, attr_list=attr_list) self.instance() self.register_method_commands() @@ -104,24 +119,18 @@ class Component(Node): for attr_name, (attr_type, value) in self.attr_list: SkyEyeSetAttr(self.name, attr_name, attr_type, value) - def __call__(self, *args): - print(self) - -from skyeye_common_module import * -from collections import OrderedDict class Machine(Component): + def instance(self): + SkyEyeCreateMach(self.name, self.cls) + def register_method_commands(self): - from skyeye_command._object_command.machine_object_command import \ - Machine_list_cpu, Machine_list_device + from skyeye_command._object_command import Machine_list_cpu, Machine_list_device cmd = Machine_list_cpu('list_cpu') MethodNode(name='list_cpu', parent=self, cmd=cmd) cmd = Machine_list_device('list_device') MethodNode(name='list_device', parent=self, cmd=cmd) - def instance(self): - SkyEyeCreateMach(self.name, self.cls) - def __str__(self): return '' % self.name @@ -147,10 +156,6 @@ class Cpu(Component): return '' % self.name class Device(Component): - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self._space_maps = None - def instance(self): SkyEyeCreateDevice(self.parent.name, self.name, self.cls) @@ -158,7 +163,7 @@ class Device(Component): return '' % self.name def memory_space_map(self, space_name, addr, length): - if self._space_maps is None: + if not hasattr(self, '_space_name'): self._space_maps = OrderedDict() self._space_maps[addr] = (space_name, length) self.create_register_list(addr) @@ -187,10 +192,7 @@ class Linker(Component): class RegisterList(Node): def __init__(self, name, parent, device_name, base_addr): - super().__init__(name, parent) - self.device_name = device_name - self.base_addr = base_addr - self.attach_to_parent(parent) + super().__init__(name, parent, device_name=device_name, base_addr=base_addr) self.create_register() def create_register(self): @@ -202,31 +204,28 @@ class RegisterList(Node): offset = reg_id * 4 Register(reg_name, self, self.device_name, reg_id, self.base_addr+offset) - def get_register(self, name): - return self.cli_attrs.get(name, None) + def create_obj_command(self): + from skyeye_command._object_command import RegisterListCommand + cmd = RegisterListCommand(str(self)) + return cmd, {'obj': self} def get_registers(self): return self.cli_attrs.copy() - def __call__(self, arg): - print(self) - self.show() - - def show(self): - print('%-25s%-25s%-15s' % ('register', 'value', 'address')) - for reg in self.cli_attrs.values(): - print('%-25s0x%-23x0x%-13x' % (reg.name, reg.value, reg.addr)) + def get_register(self, name): + return self.cli_attrs.get(name, None) def __str__(self): return '' % self.device_name class Register(Node): def __init__(self, name, parent, device_name, reg_id, addr): - super().__init__(name, parent) - self.device_name = device_name - self.reg_id = reg_id - self.addr = addr - self.attach_to_parent(parent) + super().__init__(name, parent, device_name=device_name, reg_id=reg_id, addr=addr) + + def create_obj_command(self): + from skyeye_command._object_command import RegisterCommand + cmd = RegisterCommand(str(self)) + return cmd, {'obj': self} @property def value(self): @@ -237,20 +236,17 @@ class Register(Node): return value @value.setter - def value(self): + def value(self, v): pass - def __call__(self, arg): - print(self) - self.show() - - def show(self): - print('%-25s%-15s' % ("value", "address")) - v = self.value - if v is not None: - print('0x%-23x0x%-13x' % (self.value, self.addr)) - else: - print('%-25s0x%-13x' % (self.value, self.addr)) - def __str__(self): return '' % (self.device_name, self.name) + + def get_device_name(self): + return self.device_name + + def get_id(self): + return self.reg_id + + def get_addr(self): + return self.addr diff --git a/utils/pycli/skyeye_command/_object_command.py b/utils/pycli/skyeye_command/_object_command.py new file mode 100644 index 00000000..928825d0 --- /dev/null +++ b/utils/pycli/skyeye_command/_object_command.py @@ -0,0 +1,122 @@ +from . import SkyeyeCommand, convert_int +import argparse +from skyeye_common_module import * + +# Object common command +class ObjectCommand(SkyeyeCommand): + need_check_state = False + + def create_argparser(self): + parser = argparse.ArgumentParser( + prog=self.name, + description='', + add_help=False) + + return parser + + def call(self, arg='', arg_ns=None, obj=None): + print(obj) + return False + +# Command of machine method +class Machine_list_cpu(SkyeyeCommand): + need_check_state = False + + def create_argparser(self): + parser = argparse.ArgumentParser( + prog='Machine.list_cpu', + description='Show all available cpu on the machine.', + add_help=False) + + return parser + + def call(self, arg='', arg_ns=None, obj=None): + print ("%-20s%-20s" % ("ID", "CpuName")) + cpus = obj.get_cpus() + for i, cpu in enumerate(cpus, 1): + print ("%-20d%-20s" % (i, cpu)) + + return False + +class Machine_list_device(SkyeyeCommand): + need_check_state = False + + def create_argparser(self): + parser = argparse.ArgumentParser( + prog='Machine.list_device', + description='Show all current device.', + add_help=False) + + return parser + + def call(self, arg='', arg_ns=None, obj=None): + print ("%-20s%-20s" % ("ID", "DeviceName")) + devices = obj.get_devices() + for i, device in enumerate(devices, 1): + print ("%-20d%-20s" % (i, device)) + + return False + +# Command of RegisterList +class RegisterListCommand(SkyeyeCommand): + need_check_state = False + + def create_argparser(self): + parser = argparse.ArgumentParser( + prog=self.name, + description='', + add_help=False) + + return parser + + def call(self, arg='', arg_ns=None, obj=None): + print(obj) + self.show_all_registers(obj) + + def show_all_registers(self, obj): + print('%-25s%-25s%-15s' % ('register', 'value', 'address')) + for reg in obj.cli_attrs.values(): + print('%-25s0x%-23x0x%-13x' % (reg.name, reg.value, reg.addr)) + return False + +# Command of Register +class RegisterCommand(SkyeyeCommand): + need_check_state = False + + def create_argparser(self): + parser = argparse.ArgumentParser( + prog=self.name, + description='', + add_help=False) + + sub = parser.add_subparsers() + sub_parser = sub.add_parser('=', add_help=False) + sub_parser.add_argument( + 'value', + metavar='', + type=convert_int, + help='set a value to register.', + ) + + return parser + + def call(self, arg='', arg_ns=None, obj=None): + if 'value' in arg_ns: + # reg = value + self.set_register(obj, arg_ns.value) + + print(obj) + self.show_register(obj) + + def set_register(sef, obj, value): + device_name = obj.get_device_name() + reg_id = SkyEyeGetDevRegIdByName(None, device_name, obj.name) + SkyEyeSetDevRegValueById(None, device_name, value, reg_id) + + def show_register(self, obj): + print('%-25s%-15s' % ("value", "address")) + v = obj.value + if v is not None: + print('0x%-23x0x%-13x' % (v, obj.addr)) + else: + print('%-25s0x%-13x' % (v, obj.addr)) -- Gitee From f545c5a47c4d0ebb7efa011d7667ed5412d5fad3 Mon Sep 17 00:00:00 2001 From: Liu Shuo <49305054@qq.com> Date: Thu, 23 Jun 2022 11:48:13 +0800 Subject: [PATCH 4/6] [feature] add command 'run-pyfile' --- utils/pycli/skyeye_command/run_pyfile.py | 50 ++++++++++++++++++++++++ utils/pycli/state_machine/permission.py | 2 +- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 utils/pycli/skyeye_command/run_pyfile.py diff --git a/utils/pycli/skyeye_command/run_pyfile.py b/utils/pycli/skyeye_command/run_pyfile.py new file mode 100644 index 00000000..e0ca272c --- /dev/null +++ b/utils/pycli/skyeye_command/run_pyfile.py @@ -0,0 +1,50 @@ +from . import SkyeyeCommand +import argparse +from exception import SkyeyeAPIException, ERROR_ALL_F +from skyeye_common_module import * + +class Command(SkyeyeCommand): + export = ['cli'] + + def create_argparser(self): + parser = argparse.ArgumentParser( + prog='run_pyfile', + description='run a python script', + add_help=False) + + parser.add_argument( + 'path', + metavar='', + default='', + help='python file', + ) + + return parser + + def call(self, arg='', arg_ns=None, cli=None, script=None, **meta): + try: + self._exec_py_file(arg_ns.path) + except: + import traceback + raise SkyeyeAPIException([ERROR_ALL_F, traceback.format_exc()]) + + return False + + def _exec_py_file(self, path): + del self + with open(path) as f: + exec(f.read()) + + def complete_arg_1(self, text, line, begidx, endidx): + dir_name, last = os.path.split(text) + top = dir_name if dir_name else '.' + _, dirs, files, _ = next(os.fwalk(top)) + if last == '.': + dirs += ['.', '..'] + elif last == '..': + dirs += ['..'] + dirs = [(os.path.join(dir_name, item))+'/' for item in dirs] + files = [(os.path.join(dir_name, item)) for item in files + if os.path.splitext(item)[1] == '.py'] + items = files + dirs + return [item for item in items if item.startswith(text)] diff --git a/utils/pycli/state_machine/permission.py b/utils/pycli/state_machine/permission.py index f6490d4d..b8a405aa 100644 --- a/utils/pycli/state_machine/permission.py +++ b/utils/pycli/state_machine/permission.py @@ -2,7 +2,7 @@ class Permission: always_allow = { 'history', 'help', 'ls', 'cd', - 'shell', 'run_py', + 'shell', 'run_py', 'run_pyfile', 'quit', 'q', 'run_script', 'list_modules', 'list_class', 'list_attr', 'list_connect', 'list_iface', -- Gitee From ee02e8f16789256c6e87c8e52a4a65917e28a662 Mon Sep 17 00:00:00 2001 From: Liu Shuo <49305054@qq.com> Date: Thu, 23 Jun 2022 11:57:12 +0800 Subject: [PATCH 5/6] [feature] add new module pycallback instead of pytimer --- utils/pycli/pycallback.py | 94 +++++++++++++ utils/pycli/skyeye_cli.py | 2 +- utils/pycli/skyeye_common_module.py | 107 ++++++++------- utils/pytimer/pytimer.c | 198 +++++++++++----------------- utils/pytimer/pytimer.h | 12 +- 5 files changed, 233 insertions(+), 180 deletions(-) create mode 100644 utils/pycli/pycallback.py diff --git a/utils/pycli/pycallback.py b/utils/pycli/pycallback.py new file mode 100644 index 00000000..c48b9273 --- /dev/null +++ b/utils/pycli/pycallback.py @@ -0,0 +1,94 @@ +from skyeye_common_module import * +import _thread +import time +from conf import * +import ctypes +import threading + +CALLBACK_TYPE = CFUNCTYPE(None, ctypes.py_object) +WAIT_FUNC_TYPE = CFUNCTYPE(None) +NOTIFY_FUNC_TYPE = CFUNCTYPE(None) + +class PyCallback: + _instance = None + + @staticmethod + def instance(): + if PyCallback._instance is None: + PyCallback._instance = PyCallback() + return PyCallback._instance + + def __init__(self): + self.callback_current_id = 0 + self.callback_dict = {} + + def _create_wait_notify_func(self): + event = threading.Event() + def wait(): + event.wait() + def notify(): + if not event.is_set(): + event.set() + return wait, notify + + def create_timer_callback(self, cpu, ms, mode, callback, data): + wait, notify = self._create_wait_notify_func() + t = threading.Thread(target=self._thread_create_timer_callback, + args=[cpu, ms, mode, callback, data, wait, notify]) + t.start() + self.callback_current_id += 1 + self.callback_dict[self.callback_current_id] = notify + return self.callback_current_id + + def _thread_create_timer_callback(self, cpu, ms, mode, callback, data, wait, notify): + PythonTmrCreate(cpu, ms, mode, callback, data, wait, notify) + + def delete_timer_callback(self, callback_id): + if callback_id not in self.callback_dict: + print('PyCallback.delete_timer: No Timer ID is "%d"' % callback_id) + return + + notify = self.callback_dict.pop(callback_id) + PythonTmrDelete(notify) + + def create_watch_pc_callback(self, cpu, pc_addr, callback, data): + wait, notify = self._create_wait_notify_func() + t = threading.Thread(target=self._thread_create_watch_pc_callback, + args=[cpu, pc_addr, callback, data, wait, notify]) + t.start() + self.callback_current_id += 1 + self.callback_dict[self.callback_current_id] = notify + return self.callback_current_id + + def _thread_create_watch_pc_callback(self, cpu, pc_addr, callback, data, wait, notify): + SkyEyeSetWatchOnPc(cpu, pc_addr, callback, data, wait, notify) + + def delete_watch_pc_callback(self, callback_id): + if callback_id not in self.callback_dict: + print('PyCallback.delete_watch_pc: No callback ID is "%d"' % callback_id) + return + + notify = self.callback_dict.pop(callback_id) + SkyEyeUnWatchOnPc(notify) + + def create_watch_mm_callback(self, ms_name, mm_type, addr, data_type, length, callback, data): + wait, notify = self._create_wait_notify_func() + t = threading.Thread(target=self._thread_create_watch_mm_callback, + args=[ms_name, mm_type, addr, data_type, length, callback, data, wait, notify]) + t.start() + self.callback_current_id += 1 + self.callback_dict[self.callback_current_id] = notify + return self.callback_current_id + + def _thread_create_watch_mm_callback(self, ms_name, access_type, addr, data_type, length, + callback, data, wait, notify): + SkyEyeSetWatchOnMem(ms_name, access_type, addr, data_type, length, + callback, data, wait, notify) + + def delete_watch_mm_callback(self, callback_id): + if callback_id not in self.callback_dict: + print('PyCallback.delete_watch_mm: No callback ID is "%d"' % callback_id) + return + + notify = self.callback_dict.pop(callback_id) + SkyEyeUnWatchOnMem(notify) diff --git a/utils/pycli/skyeye_cli.py b/utils/pycli/skyeye_cli.py index bc414197..26bc0965 100755 --- a/utils/pycli/skyeye_cli.py +++ b/utils/pycli/skyeye_cli.py @@ -102,7 +102,7 @@ class SkyEyeCli(cmd.Cmd): NetCtrl.server_init() except: print ("网络服务启动失败,检查GRPC服务是否配置正确!") - pytimer.PyTmrInit() + #pytimer.PyTmrInit() # MIPS mips.init() diff --git a/utils/pycli/skyeye_common_module.py b/utils/pycli/skyeye_common_module.py index 8ba44082..c7dc059e 100644 --- a/utils/pycli/skyeye_common_module.py +++ b/utils/pycli/skyeye_common_module.py @@ -19,6 +19,8 @@ if operator.eq(os_info, 'Linux') == True: libcommon = CDLL(libcommon_path, RTLD_GLOBAL) libdisasm_path = os.getenv('SKYEYEBIN') + '/../lib/skyeye/libdisasm.so' libdisasm = CDLL(libdisasm_path, RTLD_LOCAL) + libpytimer_path = os.getenv('SKYEYEBIN') + '/../lib/skyeye/libpytimer.so' + libpytimer = CDLL(libpytimer_path, RTLD_LOCAL) else: skyeye_bin = se_path.SkyEyeBin libcommon_path = os.path.abspath(os.path.join(skyeye_bin, "libcommon-0.dll")) @@ -656,7 +658,7 @@ def SkyEyeGetDevRegIdByName(machname, devicename, regname): @exception_decorator def _SkyEyeGetDevRegIdByName(machname, devicename, regname): c_ret = libcommon.skyeye_get_regid_by_name(devicename.encode("utf-8"), regname.encode("utf-8")) - debug_clib_result(c_ret) + #debug_clib_result(c_ret) return c_ret libcommon.skyeye_get_regid_by_name.restype = SkyeyeAPIResult libcommon.skyeye_get_regid_by_name.argtypes = [c_char_p, c_char_p] @@ -1472,6 +1474,56 @@ def _SkyEyeTermWaitThenWrite(termname, wait_string, write_string): libcommon.skyeye_term_wait_then_write.restype = SkyeyeAPIResult libcommon.skyeye_term_wait_then_write.argtypes = [c_char_p, c_char_p, c_char_p] +################################################################### +#------------ APIs for pycallback -------------------------# +################################################################### +CALLBACK_TYPE = CFUNCTYPE(None, py_object) +WAIT_FUNC_TYPE = CFUNCTYPE(None) +NOTIFY_FUNC_TYPE = CFUNCTYPE(None) + +def PythonTmrCreate(cpu, ms, mode, py_cb_func, py_cb_data, wait, notify): + libpytimer.PythonTmrCreate( + cpu.encode("utf-8"), ms, mode, + CALLBACK_TYPE(py_cb_func), id(py_cb_data), + WAIT_FUNC_TYPE(wait), NOTIFY_FUNC_TYPE(notify)) +libpytimer.PythonTmrCreate.restype = None +libpytimer.PythonTmrCreate.argtypes = [c_char_p, c_uint, c_uint, CALLBACK_TYPE, py_object, \ + WAIT_FUNC_TYPE, NOTIFY_FUNC_TYPE] + +def PythonTmrDelete(notify): + libpytimer.PythonTmrDelete(NOTIFY_FUNC_TYPE(notify)) +libpytimer.PythonTmrDelete.restype = None +libpytimer.PythonTmrDelete.argtypes = [NOTIFY_FUNC_TYPE] + +def SkyEyeSetWatchOnPc(cpu, addr, py_cb_func, py_cb_data, wait, notify): + libpytimer.PythonSetWatchOnPc( + cpu.encode("utf-8"), addr, + CALLBACK_TYPE(py_cb_func), id(py_cb_data), + WAIT_FUNC_TYPE(wait), NOTIFY_FUNC_TYPE(notify)) +libpytimer.PythonSetWatchOnPc.restype = None +libpytimer.PythonSetWatchOnPc.argtypes = [c_char_p, c_uint32, CALLBACK_TYPE, py_object, \ + WAIT_FUNC_TYPE, NOTIFY_FUNC_TYPE] + +def SkyEyeUnWatchOnPc(notify): + libpytimer.PythonUnWatchOnPc(NOTIFY_FUNC_TYPE(notify)) +libpytimer.PythonUnWatchOnPc.restype = None +libpytimer.PythonUnWatchOnPc.argtypes = [NOTIFY_FUNC_TYPE] + +def SkyEyeSetWatchOnMem(memory_space, access_type, m_addr, data_type, m_length, + py_cb_func, py_cb_data, wait, notify): + libpytimer.PythonSetWatchonMemory( + memory_space.encode("utf-8"), access_type, + m_addr, data_type, m_length, + CALLBACK_TYPE(py_cb_func), id(py_cb_data), + WAIT_FUNC_TYPE(wait), NOTIFY_FUNC_TYPE(notify)) +libpytimer.PythonSetWatchonMemory.restpye = None +libpytimer.PythonSetWatchonMemory.argtypes = [c_char_p, c_int, c_uint32, c_uint32, c_uint32, + CALLBACK_TYPE, py_object, WAIT_FUNC_TYPE, NOTIFY_FUNC_TYPE] + +def SkyEyeUnWatchOnMem(notify): + libpytimer.PythonUnWatchOnMemory(NOTIFY_FUNC_TYPE(notify)) +libpytimer.PythonUnWatchOnMemory.restpye = None +libpytimer.PythonUnWatchOnMemory.argtypes = [NOTIFY_FUNC_TYPE] ################################################################### #------------ FIXME: APIs for X86 -------------------------# @@ -1746,59 +1798,6 @@ def SkyEyeWritePinState(device, index, state): libcommon.write_pin_state(device.encode("utf-8"), int(index), float(state)) return [True, True, None] -@swtich_try -def PythonTmrCreate(cpu, ms, mode): - libpytimer.PythonTmrCreate.restype = c_uint - libpytimer.PythonTmrCreate.argtypes = [c_char_p, c_uint, c_uint] - ret = libpytimer.PythonTmrCreate(cpu.encode("utf-8"), ms, mode) - return [True, ret, None] - -@swtich_try -def PythonTmrCheckHit(pytmr): - libpytimer.PythonTmrCheckHit.restype = c_uint - libpytimer.PythonTmrCheckHit.argtypes = [c_uint] - ret = libpytimer.PythonTmrCheckHit(pytmr) - return [True, ret, None] - -@swtich_try -def PythonTmrProcessOk(pytmr): - libpytimer.PythonTmrProcessOk.argtypes = [c_uint] - ret = libpytimer.PythonTmrProcessOk(pytmr) - return [True, ret, None] - -@swtich_try -def PythonTmrDelete(pytmr): - libpytimer.PythonTmrDelete.restype = c_bool - libpytimer.PythonTmrDelete.argtypes = [c_uint] - ret = libpytimer.PythonTmrDelete(pytmr) - return [True, ret, None] - -@swtich_try -def SkyEyeSetWatchOnPc(cpu,addr): - libpytimer.PythonSetWatchOnPc.restype = c_uint - libpytimer.PythonSetWatchOnPc.argtypes = [c_char_p, c_uint32] - ret = libpytimer.PythonSetWatchOnPc(cpu.encode("utf-8"),addr) - return [True, ret, None] - -@swtich_try -def SkyEyeUnWatchOnPc(cpu,addr): - libpytimer.PythonUnWatchOnPc.argtypes = [c_char_p, c_uint32] - libpytimer.PythonUnWatchOnPc(cpu.encode("utf-8"), addr) - return [True, True, None] - -@swtich_try -def SkyEyeSetWatchOnMem(memory_space, mm_type, m_addr, data_type, m_length): - libpytimer.PythonSetWatchonMemory.restpye = c_uint - libpytimer.PythonSetWatchonMemory.argtypes = [c_char_p, c_int, c_uint32, c_uint32, c_uint32] - ret = libpytimer.PythonSetWatchonMemory(memory_space.encode("utf-8"),mm_type,m_addr,data_type,m_length) - return [True, ret, None] - -@swtich_try -def SkyEyeUnWatchOnMem(memory_space, mm_type, m_addr,m_length): - libpytimer.PythonUnWatchOnMemory.argtypes = [c_char_p, c_int, c_uint32, c_uint32] - libpytimer.PythonUnWatchOnMemory(memory_space.encode("utf-8"),mm_type, m_addr,m_length) - return [True, True, None] - @swtich_try def SkyEyeGetNextLog(): libcommon.skyeye_get_next_logMsg.restype = SkyeyeAPIResult diff --git a/utils/pytimer/pytimer.c b/utils/pytimer/pytimer.c index a8b6ade8..f3449b00 100644 --- a/utils/pytimer/pytimer.c +++ b/utils/pytimer/pytimer.c @@ -27,18 +27,30 @@ static void PyMemoryWatchCallback(void *user_data); * *********************************************************************************************** */ -PYTMR *PyTmrCreate(conf_object_t * cpu, TM ms, PYTMR_MODE_T mode) + +void PythonTmrCreate(char *cpu_name, TM ms, PYTMR_MODE_T mode, + py_callback_t py_cb_func, void *py_cb_data, + wait_func_t wait, notify_func_t notify) { PYTMR *pytmr; + conf_object_t *cpu = get_conf_obj(cpu_name); + if (NULL == cpu) + { + skyeye_log(Error_log, __FUNCTION__, "Can not get obj for %s.\n", cpu_name); + return 0; + } + pytmr = skyeye_mm_zero(sizeof (struct pytmr)); pytmr->Mode = mode; pytmr->cpu = cpu; - RWLOCK_INIT(pytmr->Lock); + pytmr->py_cb_func = py_cb_func; + pytmr->py_cb_data = py_cb_data; + pytmr->wait = wait; + pytmr->notify = notify; conf_object_t *idle_device = ((sys_cpu_t *) cpu->sys_struct)->sys_soc->idle_device->dev; uint32_t flags = SCHED_MS; - switch (mode) { case PYTMR_ONE_SHOT: @@ -48,31 +60,60 @@ PYTMR *PyTmrCreate(conf_object_t * cpu, TM ms, PYTMR_MODE_T mode) flags |= SCHED_NORMAL; break; default: - return (PYTMR *) 0u; + return 0u; } - pytmr->TmrHandle = system_register_timer_handler_with_data(idle_device, pytmr, ms, PyTmrCallback, flags); - return pytmr; + time_handle_t handler = system_register_timer_handler_with_data(idle_device, pytmr, ms, PyTmrCallback, flags); + + /*waiting for notifying*/ + pytmr->wait(); + + /*clean up*/ + if (mode == PYTMR_PERIOD) + system_del_timer_handler(handler); +} + +void PythonTmrDelete(notify_func_t notify) +{ + notify(); } -PYTMR *PySetWatchOnPc(char *cpu_name, uint32_t pc_addr) +void PythonSetWatchOnPc(char *cpu_name, uint32_t pc_addr, + py_callback_t py_cb_func, void *py_cb_data, + wait_func_t wait, notify_func_t notify) { PYTMR *pytmr; - conf_object_t *obj = get_conf_obj(cpu_name); + conf_object_t *cpu = get_conf_obj(cpu_name); - if (NULL == obj) + if (NULL == cpu) { skyeye_log(Error_log, __FUNCTION__, "Can not get obj for %s.\n", cpu_name); - return 0; + return 0u; } pytmr = skyeye_mm_zero(sizeof (struct pytmr)); - pytmr->cpu = obj; - RWLOCK_INIT(pytmr->Lock); + pytmr->cpu = cpu; + pytmr->py_cb_func = py_cb_func; + pytmr->py_cb_data = py_cb_data; + pytmr->wait = wait; + pytmr->notify = notify; SkyEye_SetWatchOnPC(cpu_name, pc_addr, PyPcWatchCallback, pytmr); - return pytmr; + + /*waiting for notifying*/ + pytmr->wait(); + + /*clean up*/ + SkyEye_UnWatchOnPc(cpu_name, pc_addr); } -PYTMR *PySetWatchOnMemory(char *ms_name, int mm_type, uint32_t m_addr, uint32_t data_type, uint32_t m_length) +void PythonUnWatchOnPc(notify_func_t notify) +{ + notify(); +} + +void PythonSetWatchonMemory(char *ms_name, int mm_type, uint32_t m_addr, + uint32_t data_type, uint32_t m_length, + py_callback_t py_cb_func, void *py_cb_data, + wait_func_t wait, notify_func_t notify) { PYTMR *pytmr; conf_object_t *mm_obj = get_conf_obj(ms_name); @@ -84,13 +125,26 @@ PYTMR *PySetWatchOnMemory(char *ms_name, int mm_type, uint32_t m_addr, uint32_t } pytmr = skyeye_mm_zero(sizeof (struct pytmr)); pytmr->mm_space = mm_obj; - RWLOCK_INIT(pytmr->Lock); + pytmr->py_cb_func = py_cb_func; + pytmr->py_cb_data = py_cb_data; + pytmr->wait = wait; + pytmr->notify = notify; /*Enable dyncom memory watch */ SkyEye_SetDyncomWatchMemoryStatus(m_addr, 1); Py_SetWatchOnMemory(mm_obj, ms_name, mm_type, m_addr, data_type, m_length, PyMemoryWatchCallback, pytmr); - return pytmr; + + /*wait for notifying*/ + pytmr->wait(); + + /*clean up*/ + SkyEye_UnWatchOnMemory(ms_name, mm_type, m_addr, m_length); +} + +int PythonUnWatchOnMemory(notify_func_t notify) +{ + notify(); } /* @@ -108,120 +162,22 @@ PYTMR *PySetWatchOnMemory(char *ms_name, int mm_type, uint32_t m_addr, uint32_t *********************************************************************************************** */ -void PyMemoryWatchCallback(void *data) -{ - PYTMR *pytmr = (PYTMR *) (data); - - pytmr->Hit = True; - while(!pytmr->isSync) - { -#ifdef __WIN32__ - Sleep(1); -#else - usleep(1); -#endif - } - pytmr->isSync = False; -} - void PyTmrCallback(void *arg, time_data_t * data) { PYTMR *pytmr = (PYTMR *) (data->user_data); - - pytmr->Hit = True; - while(!pytmr->isSync) - { -#ifdef __WIN32__ - Sleep(1); -#else - usleep(1); -#endif - } - pytmr->isSync = False; + pytmr->py_cb_func(pytmr->py_cb_data); + if (pytmr->Mode == PYTMR_ONE_SHOT) + pytmr->notify(); } void PyPcWatchCallback(void *data) { PYTMR *pytmr = (PYTMR *) (data); - - pytmr->Hit = True; - while(!pytmr->isSync) - { -#ifdef __WIN32__ - Sleep(1); -#else - usleep(1); -#endif - } - pytmr->isSync = False; -} - -uint32_t PythonTmrCreate(char *cpu, TM ms, PYTMR_MODE_T mode) -{ - PYTMR *p_pytmr; - conf_object_t *obj = get_conf_obj(cpu); - - if (NULL == obj) - { - skyeye_log(Error_log, __FUNCTION__, "Can not get obj for %s.\n", cpu); - return 0; - } - p_pytmr = PyTmrCreate(obj, ms, mode); - return (uint32_t) p_pytmr; -} - -uint32_t PythonSetWatchOnPc(char *cpuname, uint32_t pc_addr) -{ - PYTMR *p_pytmr; - - p_pytmr = PySetWatchOnPc(cpuname, pc_addr); - return (uint32_t) p_pytmr; + pytmr->py_cb_func(pytmr->py_cb_data); } -void PythonUnWatchOnPc(char *cpuname, uint32_t pc_addr) -{ - SkyEye_UnWatchOnPc(cpuname, pc_addr); -} - -int PythonSetWatchonMemory(char *ms_name, int mm_type, uint32_t m_addr, uint32_t data_type, uint32_t m_length) -{ - PYTMR *p_pytmr; - - p_pytmr = PySetWatchOnMemory(ms_name, mm_type, m_addr, data_type, m_length); - return (uint32_t) p_pytmr; -} - -int PythonUnWatchOnMemory(char *ms_name, int mm_type, uint32_t m_addr, uint32_t m_length) -{ - PYTMR *p_pytmr; - - p_pytmr = SkyEye_UnWatchOnMemory(ms_name, mm_type, m_addr, m_length); - return (int) p_pytmr; -} - -void PythonTmrProcessOk(uint32_t ptr) -{ - PYTMR *p_pytmr = (PYTMR *) ptr; - - p_pytmr->isSync = True; - RW_UNLOCK(p_pytmr->Lock); -} - -bool_t PythonTmrCheckHit(uint32_t ptr) -{ - PYTMR *p_pytmr = (PYTMR *) ptr; - - if (p_pytmr->Hit) - { - p_pytmr->Hit = False; - return True; - } else - return False; -} - -bool_t PythonTmrDelete(uint32_t ptr) +void PyMemoryWatchCallback(void *data) { - PYTMR *p_pytmr = (PYTMR *) ptr; - - return system_del_timer_handler(p_pytmr->TmrHandle); + PYTMR *pytmr = (PYTMR *) (data); + pytmr->py_cb_func(pytmr->py_cb_data); } diff --git a/utils/pytimer/pytimer.h b/utils/pytimer/pytimer.h index bc87562c..6924c52d 100644 --- a/utils/pytimer/pytimer.h +++ b/utils/pytimer/pytimer.h @@ -8,6 +8,9 @@ typedef struct pytmr PYTMR; typedef uint32_t PYTMR_ID; typedef uint32_t TM; +typedef void (*py_callback_t) (void *data); +typedef void (*wait_func_t) (); +typedef void (*notify_func_t) (); typedef enum { @@ -18,14 +21,15 @@ typedef enum typedef struct pytmr { PYTMR_MODE_T Mode; - bool_t Hit; - bool_t isSync; PYTMR *NextPtr; PYTMR *PrevPtr; - RWLOCK_T Lock; + conf_object_t *cpu; conf_object_t *mm_space; - time_handle_t TmrHandle; + py_callback_t py_cb_func; + void *py_cb_data; + wait_func_t wait; + notify_func_t notify; }; #endif -- Gitee From c913f2d7b25dee56154a8865291109fc8eff733a Mon Sep 17 00:00:00 2001 From: Liu Shuo <49305054@qq.com> Date: Mon, 27 Jun 2022 09:10:07 +0800 Subject: [PATCH 6/6] [fix] remove unuseful code in 'utils/pycli/skyeye_command/_object_command/' --- .../_object_command/machine_object_command.py | 40 ------------------- 1 file changed, 40 deletions(-) delete mode 100644 utils/pycli/skyeye_command/_object_command/machine_object_command.py diff --git a/utils/pycli/skyeye_command/_object_command/machine_object_command.py b/utils/pycli/skyeye_command/_object_command/machine_object_command.py deleted file mode 100644 index 36bf066b..00000000 --- a/utils/pycli/skyeye_command/_object_command/machine_object_command.py +++ /dev/null @@ -1,40 +0,0 @@ -from skyeye_command import SkyeyeCommand -import argparse - -class Machine_list_cpu(SkyeyeCommand): - need_check_state = False - - def create_argparser(self): - parser = argparse.ArgumentParser( - prog='Machine.list_cpu', - description='Show all available cpu on the machine.', - add_help=False) - - return parser - - def call(self, arg='', arg_ns=None, obj=None): - print ("%-20s%-20s" % ("ID", "CpuName")) - cpus = obj.get_cpus() - for i, cpu in enumerate(cpus, 1): - print ("%-20d%-20s" % (i, cpu)) - - return False - -class Machine_list_device(SkyeyeCommand): - need_check_state = False - - def create_argparser(self): - parser = argparse.ArgumentParser( - prog='Machine.list_device', - description='Show all current device.', - add_help=False) - - return parser - - def call(self, arg='', arg_ns=None, obj=None): - print ("%-20s%-20s" % ("ID", "DeviceName")) - devices = obj.get_devices() - for i, device in enumerate(devices, 1): - print ("%-20d%-20s" % (i, device)) - - return False -- Gitee