Esempio n. 1
0
def run(aprs_user='******', logfile='main.log', loglevel='INFO'):
    """Run the aprs client."""

    # User input validation
    if len(aprs_user) < 3 or len(aprs_user) > 9:
        print('aprs_user must be a string of 3-9 characters.')
        return
    if loglevel not in log_levels:
        print('loglevel must be an element of {}.'.format(log_levels))
        return

    # Enable logging
    log_handlers = [logging.StreamHandler()]
    if logfile:
        log_handlers.append(logging.FileHandler(logfile))
    logging.basicConfig(format=logging_formatstr, level=loglevel, handlers=log_handlers)

    print('Start ogn gateway')
    gateway = ognGateway(aprs_user)
    gateway.connect()

    def process_beacon(beacon):
        session.add(beacon)
        session.commit()

    try:
        gateway.run(callback=process_beacon, autoreconnect=True)
    except KeyboardInterrupt:
        print('\nStop ogn gateway')

    gateway.disconnect()
    logging.shutdown()
Esempio n. 2
0
 def test_disconnect(self, mock_socket):
     self.gw = ognGateway(aprs_user='******', aprs_filter='')
     self.gw.connect()
     self.gw.disconnect()
     self.gw.sock.shutdown.assert_called_once_with(0)
     self.gw.sock.close.assert_called_once_with()
Esempio n. 3
0
 def test_initialisation(self):
     self.gw = ognGateway(aprs_user='******', aprs_filter='')
     self.assertEqual(self.gw.aprs_user, 'testuser')
     self.assertEqual(self.gw.aprs_filter, '')
Esempio n. 4
0
 def test_connect(self, mock_socket):
     self.gw = ognGateway(aprs_user='******', aprs_filter='')
     self.gw.connect()
     self.gw.sock.send.assert_called_once_with('user testuser pass -1 vers {} {}\n'.format(APRS_APP_NAME, APRS_APP_VER).encode('ascii'))
     self.gw.sock.makefile.asser_called_once_with('rw')