Home | History | Annotate | Download | only in power_monitors
      1 #!/usr/bin/python
      2 
      3 # Copyright (C) 2014 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 from . import Abstract_Power_Monitor
     18 
     19 class Power_Monitor(Abstract_Power_Monitor):
     20   """
     21   Dummy implementation for internal use only to test host-to-device
     22   interactions without need for a real power monitor.  This is not
     23   to be used in any way as part of CtsVerifier or CTS verification
     24   activities in general.
     25   """
     26 
     27   
     28   def __init__(self, device = None, wait = False, log_file_id = None ):
     29       self._device = device
     30       self._usbpassthroughmode = 1
     31       self._voltage = 0.0
     32       self._data_active = False
     33       self._sequence = 0
     34       
     35   def __del__(self):
     36       self.Close()
     37 
     38   def Close(self):
     39       pass
     40     
     41   @staticmethod
     42   def Discover():
     43       return ["dummy_monitor"]
     44 
     45   def GetStatus(self):
     46     """ Requests and waits for status.  Returns status dictionary. """
     47     return {"usbPassthroughMode": self._usbpassthroughmode,
     48             "sampleRate":1}
     49 
     50 
     51   def RampVoltage(self, start, end):
     52       self._voltage = end   
     53 
     54   def SetVoltage(self, v):
     55     """ Set the output voltage, 0 to disable. """
     56     self._voltage = v
     57 
     58   def SetMaxCurrent(self, i):
     59     """Set the max output current."""
     60     self._max_current = i
     61     
     62   def SetUsbPassthrough(self, val):
     63     """ Set the USB passthrough mode: 0 = off, 1 = on,  2 = auto. """
     64     self._usbpassthroughmode = val
     65 
     66   def StartDataCollection(self):    
     67     """ Tell the device to start collecting and sending measurement data. """
     68     self._data_active = True
     69     
     70   def StopDataCollection(self):
     71     """ Tell the device to stop collecting measurement data. """
     72     self._data_active = False
     73     
     74   def CollectData(self, verbose = True):
     75     """ Return some current samples.  Call StartDataCollection() first. """
     76     #self.log("Collecting data ...", debug = True)
     77     import random
     78     if self._data_active:
     79         base = [0.003, 0.003, 0.003, (self._sequence%4)*0.0005]
     80         self._sequence += 1
     81         values = [ random.gauss(base[(self._sequence-1)%4], 0.0005) for _ in range(100)]
     82     else:
     83         values = None
     84     return values
     85