summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Sanders <nsanders@chromium.org>2017-08-24 18:52:24 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-08-28 21:15:34 -0700
commit4fc9cf4c116d06153f7ab4a02533d4b5406248d3 (patch)
tree430a62ffe5e36b59db278156c6bf4cb70974d234
parent4e46386877adbc0f2f85e78670051d68143b5b1f (diff)
downloadchrome-ec-4fc9cf4c116d06153f7ab4a02533d4b5406248d3.tar.gz
sweetberry: converter tool for servo_ina
convert_servo_ina.py can convert power log config files from hdctools/servo/data into sweetberry configs BRANCH=None BUG=b:35578707 TEST=compare kevin_r0_loc.py output with kevin.board Change-Id: Iadc57fe4eb1f5b220c6bffe3a3fe8a10b0d6b5a2 Signed-off-by: Nick Sanders <nsanders@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/634486
-rw-r--r--extra/usb_power/board.README12
-rwxr-xr-xextra/usb_power/convert_servo_ina.py74
2 files changed, 86 insertions, 0 deletions
diff --git a/extra/usb_power/board.README b/extra/usb_power/board.README
index e253660496..65c1af74e3 100644
--- a/extra/usb_power/board.README
+++ b/extra/usb_power/board.README
@@ -8,6 +8,18 @@ a ".board" file, and one describing the particular rails you want to
monitor in this session, a ".scenario" file.
+Converting from servo_ina configs:
+
+Many configs can be found for the servo_ina_board in hdctools/servo/data/.
+Sweetberry is plug compatible with servo_ina headers, and config files
+can be converted with the following tool:
+
+./convert_servo_ina.py kevin_r0_loc.py
+
+This will produce kevin_r0_loc.board and kevin_r0_loc.scenario which
+can be used with powerlog.py.
+
+
Board files:
Board files contain a list of rails, supporting 48 channels each on up to two
diff --git a/extra/usb_power/convert_servo_ina.py b/extra/usb_power/convert_servo_ina.py
new file mode 100755
index 0000000000..188bae8799
--- /dev/null
+++ b/extra/usb_power/convert_servo_ina.py
@@ -0,0 +1,74 @@
+#!/usr/bin/python
+# Copyright 2017 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 power logging config from a servo_ina device
+ to a sweetberry config.
+"""
+
+
+import os
+import sys
+
+
+def fetch_records(basename):
+ """Import records from servo_ina file.
+
+ servo_ina files are python imports, and have a list of tuples with
+ the INA data.
+ (inatype, i2caddr, rail name, bus voltage, shunt ohms, mux, True)
+
+ Args:
+ basename: python import name (filename -.py)
+
+ Returns:
+ list of tuples as described above.
+ """
+ ina_desc = __import__(basename)
+ return ina_desc.inas
+
+
+def main(argv):
+ if len(argv) != 2:
+ print "usage:"
+ print " %s input.py" % argv[0]
+ return
+
+ inputf = argv[1]
+ basename = os.path.splitext(inputf)[0]
+ outputf = basename + '.board'
+ outputs = basename + '.scenario'
+
+ print "Converting %s to %s, %s" % (inputf, outputf, outputs)
+
+ inas = fetch_records(basename)
+
+
+ boardfile = open(outputf, 'w')
+ scenario = open(outputs, 'w')
+
+ boardfile.write('[\n')
+ scenario.write('[\n')
+ start = True
+
+ for rec in inas:
+ if start:
+ start = False
+ else:
+ boardfile.write(',\n')
+ scenario.write(',\n')
+
+ record = ' {"name": "%s", "rs": %f, "sweetberry": "A", "channel": %d}' % (
+ rec[2], rec[4], rec[1] - 64)
+ boardfile.write(record)
+ scenario.write('"%s"' % rec[2])
+
+ boardfile.write('\n')
+ boardfile.write(']')
+
+ scenario.write('\n')
+ scenario.write(']')
+
+if __name__ == "__main__":
+ main(sys.argv)