mirror of
https://github.com/ARM-software/devlib.git
synced 2025-09-04 19:11:53 +01:00
JunoEnergyInstrument: Provide INSTANTANEOUS interface
This allows clients to use the instrument more easily from their code if they were previously used to using an HWMON-style interface. In order to provide the measurement, the existing readenergy binary is updated and changed so that if no output option is specified then we just print the current values and exit. Signed-off-by: Chris Redpath <chris.redpath@arm.com>
This commit is contained in:
Binary file not shown.
@@ -20,7 +20,7 @@ import time
|
||||
import pexpect
|
||||
|
||||
from devlib.platform import Platform
|
||||
from devlib.instrument import Instrument, InstrumentChannel, MeasurementsCsv, CONTINUOUS
|
||||
from devlib.instrument import Instrument, InstrumentChannel, MeasurementsCsv, Measurement, CONTINUOUS, INSTANTANEOUS
|
||||
from devlib.exception import TargetError, HostError
|
||||
from devlib.host import PACKAGE_BIN_DIRECTORY
|
||||
from devlib.utils.serial_port import open_serial_connection
|
||||
@@ -208,7 +208,7 @@ class TC2(VersatileExpressPlatform):
|
||||
class JunoEnergyInstrument(Instrument):
|
||||
|
||||
binname = 'readenergy'
|
||||
mode = CONTINUOUS
|
||||
mode = CONTINUOUS | INSTANTANEOUS
|
||||
|
||||
_channels = [
|
||||
InstrumentChannel('sys_curr', 'sys', 'current'),
|
||||
@@ -238,6 +238,7 @@ class JunoEnergyInstrument(Instrument):
|
||||
self.channels[chan.name] = chan
|
||||
self.on_target_file = self.target.tempfile('energy', '.csv')
|
||||
self.command = '{} -o {}'.format(self.binary, self.on_target_file)
|
||||
self.command2 = '{}'.format(self.binary)
|
||||
|
||||
def setup(self):
|
||||
self.binary = self.target.install(os.path.join(PACKAGE_BIN_DIRECTORY,
|
||||
@@ -281,4 +282,16 @@ class JunoEnergyInstrument(Instrument):
|
||||
|
||||
return MeasurementsCsv(output_file, self.active_channels)
|
||||
|
||||
def take_measurement(self):
|
||||
result = []
|
||||
output = self.target.execute(self.command2).split()
|
||||
reader=csv.reader(output)
|
||||
headings=reader.next()
|
||||
values = reader.next()
|
||||
for chan in self.active_channels:
|
||||
value = values[headings.index(chan.name)]
|
||||
result.append(Measurement(value, chan))
|
||||
print result
|
||||
return result
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user