Exemple #1
0
 def connect(self, dialtone_check=True):
     """Use pppd to connect to the network."""
     # Modem is not connected if _pppd_pid is set to None.
     if not self._pppd_pid:
         data_port = self.data_port
         data_port.open()
         data_port.write(b'ATZ\r\n')
         data_port.return_data()
         if not dialtone_check:
             data_port.write(b'ATX3\r\n')
             data_port.return_data()
         data_port.write(('ATDT%s\r\n' % self._dial_num).encode())
         data_port.readline()
         status = data_port.readline()
         if status.startswith('CONNECT'):
             pppd_args = [defaults.PPPD_PATH, self.baudrate,
                          self.data_port.port] + self.pppd_params
             pid = os.fork()
             if pid:
                 self._pppd_pid = pid
             else:
                 try:
                     os.execv(defaults.PPPD_PATH, pppd_args)
                 except:
                     raise errors.PppdError('An error while starting pppd.')
     else:
         last_pppd_result = os.waitpid(self._pppd_pid, os.WNOHANG)
         if last_pppd_result != (0, 0):
             # Reconnect.
             self._pppd_pid = None
             self.connect(dialtone_check)
         else:
             # Modem already connected.   
             raise errors.HumodUsageError('Modem already connected.')
Exemple #2
0
 def disconnect(self):
     """Disconnect the modem."""
     if self._pppd_pid:
         os.kill(self._pppd_pid, 15)
         os.waitpid(self._pppd_pid, 0)
         self._pppd_pid = None
     else:
         raise errors.HumodUsageError('Not connected.')
Exemple #3
0
 def stop(self):
     """Stop the prober."""
     if self._feeder:
         self._stop_interpreter()
         self._feeder.stop()
         self._feeder = None
     else:
         raise errors.HumodUsageError('Prober not started.')
Exemple #4
0
    def start(self, patterns=None):
        """Start the prober.

        Starts two threads, an instance of QueueFeeder and Interpreter.
        """
        self.patterns = patterns
        if not patterns:
            self.patterns = actions.STANDARD_ACTIONS
        if self._feeder:
            raise errors.HumodUsageError('Prober already started.')
        else:
            self._feeder = QueueFeeder(self.queue, self.modem.ctrl_port, 
                                       self.modem.ctrl_lock)
            self._feeder.start()
            self._start_interpreter()