Home | History | Annotate | Download | only in state_machines
      1 # Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 import random
      6 
      7 # Setup wardmodem package root and other autotest paths.
      8 import common
      9 
     10 from state_machines import call_machine
     11 
     12 class CallMachineE362(call_machine.CallMachine):
     13     """
     14     E362 specific extension to the call machine.
     15 
     16     """
     17     def __init__(self, state, transceiver, modem_conf):
     18         """
     19         @param state: The GlobalState object shared by all state machines.
     20 
     21         @param transceiver: The ATTransceiver object to interact with.
     22 
     23         @param modem_conf: A modem configuration object that contains
     24                 configuration data for different state machines.
     25 
     26         @raises: SetupException if we attempt to create an instance of a machine
     27                 that has not been completely specified (see
     28                 get_well_known_name).
     29 
     30         """
     31         super(CallMachineE362, self).__init__(state, transceiver, modem_conf)
     32 
     33         # Add all wardmodem response functions used by this machine.
     34         self._add_response_function('wm_response_qmi_call_result_success')
     35         self._add_response_function('wm_response_qmi_call_state_connected')
     36         self._add_response_function('wm_response_qmi_call_state_disconnected')
     37         self._add_response_function('wm_response_qmi_call_end_reason')
     38         self._add_response_function('wm_response_qmi_call_duration')
     39 
     40         random.seed()
     41         self._call_duration = 0
     42 
     43 
     44     # ##########################################################################
     45     # State machine API functions.
     46     def connect_call(self):
     47         """
     48         Connect a call with the registered network.
     49 
     50         Overrides CallMachine.connect_call
     51 
     52         """
     53         super(CallMachineE362, self).connect_call()
     54         self._update_state({'call_end_reason': 0})
     55         self._call_duration = 0
     56 
     57 
     58     def disconnect_call(self):
     59         """
     60         Disconnect an active call with the registered network.
     61 
     62         Overrides CallMachine.disconnect_call
     63 
     64         """
     65         super(CallMachineE362, self).disconnect_call()
     66         self._call_duration = 0
     67 
     68 
     69     def get_qmi_call_status(self):
     70         """
     71         Get the current call status as returned by the QMI call to E362.
     72 
     73         """
     74         if self._state['call_status'] == 'CONNECTED':
     75             # We randomly increment the call duration every time a status check
     76             # is made in a continuing call.
     77             self._call_duration += random.randint(0, 20)
     78 
     79             self._respond(self.wm_response_qmi_call_result_success)
     80             self._respond(self.wm_response_qmi_call_state_connected)
     81             self._respond(self.wm_response_qmi_call_end_reason, 0,
     82                           str(self._state['call_end_reason']))
     83             self._respond(self.wm_response_qmi_call_duration, 0,
     84                           self._call_duration)
     85             self._respond(self.wm_response_qmi_call_result_success)
     86             self._respond(self.wm_response_qmi_call_state_connected)
     87             self._respond(self.wm_response_qmi_call_end_reason, 0, '0')
     88             self._respond(self.wm_response_qmi_call_duration, 0,
     89                           self._call_duration)
     90             self._respond_ok()
     91         else:
     92             self._respond(self.wm_response_qmi_call_result_success)
     93             self._respond(self.wm_response_qmi_call_state_disconnected)
     94             self._respond(self.wm_response_qmi_call_end_reason, 0,
     95                           str(self._state['call_end_reason']))
     96             self._respond(self.wm_response_qmi_call_duration, 0,
     97                           self._call_duration)
     98             self._respond(self.wm_response_qmi_call_result_success)
     99             self._respond(self.wm_response_qmi_call_state_disconnected)
    100             self._respond(self.wm_response_qmi_call_end_reason, 0, '0')
    101             self._respond(self.wm_response_qmi_call_duration, 0,
    102                           self._call_duration)
    103             self._respond_ok()
    104