diff options
author | Ravi Chandra Sadineni <ravisadineni@chromium.org> | 2018-06-18 16:51:25 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-06-19 19:11:08 -0700 |
commit | 8400787279345a1810b2635ba0bab4ae3bd5e537 (patch) | |
tree | 4b0e3577acc538a692e5dcd15b69a7d09d05407b /extra | |
parent | d85ce46bfc674cd61b90230b0b26b64ab988ecb7 (diff) | |
download | chrome-ec-8400787279345a1810b2635ba0bab4ae3bd5e537.tar.gz |
Script to convert board file to servod config .py file.
Script to convert .board file (input to powerlog.py) into .py file which
can be used to generate .xml configuration file for servod.
BUG=none
BRANCH=none
TEST= convert a .board file to .py file and verify it works.
Change-Id: Ia67d1552c048895efee10d7a92830cfa25a51984
Signed-off-by: Ravi Chandra Sadineni <ravisadineni@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1105479
Reviewed-by: Puthikorn Voravootivat <puthik@google.com>
Diffstat (limited to 'extra')
-rw-r--r-- | extra/usb_power/convert_power_log_board.py | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/extra/usb_power/convert_power_log_board.py b/extra/usb_power/convert_power_log_board.py new file mode 100644 index 0000000000..3f0cfec014 --- /dev/null +++ b/extra/usb_power/convert_power_log_board.py @@ -0,0 +1,85 @@ +#!/usr/bin/python +# Copyright 2018 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +""" +Program to convert sweetberry config to servod config template. +""" + +import json +import os +import sys + +from powerlog import Spower + + +def fetch_records(board_file): + """Import records from servo_ina file. + + board files are json files, and have a list of tuples with + the INA data. + (name, rs, swetberry_num, net_name, channel) + + Args: + board_file: board file + + Returns: + list of tuples as described above. + """ + data = None + with open(board_file) as f: + data = json.load(f) + return data + + +def write_to_file(file, sweetberry, inas): + """Writes records of |sweetberry| to |file| + Args: + file: file to write to. + sweetberry: sweetberry type. A or B. + inas: list of inas read from board file. + """ + + with open(file, 'w') as pyfile: + + pyfile.write('inas = [\n') + + for rec in inas: + if rec['sweetberry'] != sweetberry: + continue + + # EX : ('sweetberry', 0x40, 'SB_FW_CAM_2P8', 5.0, 1.000, 3, False), + channel, i2c_addr = Spower.CHMAP[rec['channel']] + record = (" ('sweetberry', 0x%02x, '%s', 5.0, %f, %d, 'True')" + ",\n" % (i2c_addr, rec['name'], rec['rs'], channel)) + pyfile.write(record) + + pyfile.write(']\n') + + +def main(argv): + if len(argv) != 2: + print "usage:" + print " %s input.board" % argv[0] + return + + inputf = argv[1] + basename = os.path.splitext(inputf)[0] + + inas = fetch_records(inputf) + + sweetberry = set(rec['sweetberry'] for rec in inas) + + if len(sweetberry) == 2: + print "Converting %s to %s and %s" % (inputf, basename + '_a.py', + basename + '_b.py') + write_to_file(basename + '_a.py', 'A', inas) + write_to_file(basename + '_b.py', 'B', inas) + else: + print "Converting %s to %s" % (inputf, basename + '.py') + write_to_file(basename + '.py', sweetberry.pop(), inas) + + +if __name__ == "__main__": + main(sys.argv) |