• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3.4
2#
3#   Copyright 2016 - The Android Open Source Project
4#
5#   Licensed under the Apache License, Version 2.0 (the "License");
6#   you may not use this file except in compliance with the License.
7#   You may obtain a copy of the License at
8#
9#       http://www.apache.org/licenses/LICENSE-2.0
10#
11#   Unless required by applicable law or agreed to in writing, software
12#   distributed under the License is distributed on an "AS IS" BASIS,
13#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14#   See the License for the specific language governing permissions and
15#   limitations under the License.
16
17"""Interface for a USB-connected Monsoon power meter
18(http://msoon.com/LabEquipment/PowerMonitor/).
19"""
20
21_Python3_author_ = 'angli@google.com (Ang Li)'
22_author_ = 'kens@google.com (Ken Shirriff)'
23
24import argparse
25import sys
26import time
27import collections
28
29from acts.controllers.monsoon import Monsoon
30
31def main(FLAGS):
32    """Simple command-line interface for Monsoon."""
33    if FLAGS.avg and FLAGS.avg < 0:
34        print("--avg must be greater than 0")
35        return
36
37    mon = Monsoon(serial=int(FLAGS.serialno[0]))
38
39    if FLAGS.voltage is not None:
40        mon.set_voltage(FLAGS.voltage)
41
42    if FLAGS.current is not None:
43        mon.set_max_current(FLAGS.current)
44
45    if FLAGS.status:
46        items = sorted(mon.status.items())
47        print("\n".join(["%s: %s" % item for item in items]))
48
49    if FLAGS.usbpassthrough:
50        mon.usb(FLAGS.usbpassthrough)
51
52    if FLAGS.startcurrent is not None:
53         mon.set_max_init_current(FLAGS.startcurrent)
54
55    if FLAGS.samples:
56        # Have to sleep a bit here for monsoon to be ready to lower the rate of
57        # socket read timeout.
58        time.sleep(1)
59        result = mon.take_samples(FLAGS.hz, FLAGS.samples,
60            sample_offset=FLAGS.offset, live=True)
61        print(repr(result))
62
63if __name__ == '__main__':
64    parser = argparse.ArgumentParser(description=("This is a python utility "
65                 "tool to control monsoon power measurement boxes."))
66    parser.add_argument("--status", action="store_true",
67        help="Print power meter status.")
68    parser.add_argument("-avg", "--avg", type=int, default=0,
69        help="Also report average over last n data points.")
70    parser.add_argument("-v", "--voltage", type=float,
71        help="Set output voltage (0 for off)")
72    parser.add_argument("-c", "--current", type=float,
73        help="Set max output current.")
74    parser.add_argument("-sc", "--startcurrent", type=float,
75        help="Set max power-up/inital current.")
76    parser.add_argument("-usb", "--usbpassthrough", choices=("on", "off",
77        "auto"), help="USB control (on, off, auto).")
78    parser.add_argument("-sp", "--samples", type=int,
79        help="Collect and print this many samples")
80    parser.add_argument("-hz", "--hz", type=int,
81        help="Sample this many times per second.")
82    parser.add_argument("-d", "--device", help="Use this /dev/ttyACM... file.")
83    parser.add_argument("-sn", "--serialno", type=int, nargs=1, required=True,
84        help="The serial number of the Monsoon to use.")
85    parser.add_argument("--offset", type=int, nargs='?', default=0,
86        help="The number of samples to discard when calculating average.")
87    parser.add_argument("-r", "--ramp", action="store_true", help=("Gradually "
88        "increase voltage to prevent tripping Monsoon overvoltage"))
89    args = parser.parse_args()
90    main(args)
91