def get(ctx, variable_path_set): """Retrieves current value of one or multiple PP parameters The parameter variable path must be specified in "/<param> notation", for example: \b upp get /FanTable/TargetTemperature /VddgfxLookupTable/7/Vdd The raw value of the parameter will be retrieved, decoded and displayed on console. Multiple PP parameters can be specified at the same time. """ debug = ctx.obj['DEBUG'] pp_file = ctx.obj['PPBINARY'] from_registry = ctx.obj['FROMREGISTRY'] if from_registry: pp_file = _get_pp_data_from_registry(from_registry) pp_bytes = decode._read_binary_file(pp_file) data = decode.select_pp_struct(pp_bytes, debug=debug) for set_pair_str in variable_path_set: var_path = _normalize_var_path(set_pair_str) res = decode.get_value(pp_file, var_path, data, debug=debug) if res: print(res['value']) else: print('ERROR: Incorrect variable path:', set_pair_str) return 2 return 0
def set(ctx, variable_path_set, to_registry, write): """Sets value to one or multiple PP parameters The parameter path and value must be specified in "/<param>=<value> notation", for example: \b upp set /PowerTuneTable/TDP=75 /SclkDependencyTable/7/Sclk=107000 Multiple PP parameters can be set at the same time. The PP tables will not be changed unless additional --write option is set. Optionally, if -t/--to-registry output is specified, an additional Windows registry format file with '.reg' extension will be generated, for example: \b upp set /PowerTuneTable/TDP=75 --to-registry=test will produce the file test.reg in the current working directory. """ debug = ctx.obj['DEBUG'] pp_file = ctx.obj['PPBINARY'] set_pairs = [] for set_pair_str in variable_path_set: var, val = _validate_set_pair(set_pair_str) if var and val: var_path = _normalize_var_path(var) res = decode.get_value(pp_file, var_path) if res: if (val.isdigit()): set_pairs += [var_path + [int(val)]] else: set_pairs += [var_path + [float(val)]] else: print('ERROR: Incorrect variable path:', var) return 2 else: return 2 pp_bytes = decode._read_binary_file(pp_file) data = decode.select_pp_struct(pp_bytes) for set_list in set_pairs: decode.set_value(pp_file, pp_bytes, set_list[:-1], set_list[-1], data_dict=data, write=False, debug=debug) if write: print("Commiting changes to '{}'.".format(pp_file)) decode._write_pp_tables_file(pp_file, pp_bytes) else: print("WARNING: Nothing was written to '{}'.".format(pp_file), "Add --write option to commit the changes for real!") if to_registry: _write_pp_to_reg_file(to_registry + '.reg', pp_bytes, debug=debug) return 0