2018-07-10 10:59:41 +02:00
|
|
|
# Copyright (C) 2018 Kevin Weiss <kevin.weiss@haw-hamburg.de>
|
|
|
|
#
|
|
|
|
# This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
# General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
# directory for more details.
|
|
|
|
"""@package PyToAPI
|
|
|
|
This module assigns the drivers to the devices.
|
|
|
|
"""
|
|
|
|
import logging
|
2018-07-26 09:59:05 +02:00
|
|
|
from .serial_driver import SerialDriver
|
|
|
|
from .riot_driver import RiotDriver
|
2018-07-10 10:59:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
def driver_from_config(dev_type='serial', *args, **kwargs):
|
|
|
|
"""Returns driver instance given configuration"""
|
2018-08-06 10:19:43 +02:00
|
|
|
if dev_type == 'serial':
|
2018-07-10 10:59:41 +02:00
|
|
|
return SerialDriver(*args, **kwargs)
|
2018-08-06 10:19:43 +02:00
|
|
|
elif dev_type == 'riot':
|
2018-07-10 10:59:41 +02:00
|
|
|
return RiotDriver(*args, **kwargs)
|
2018-08-06 10:19:43 +02:00
|
|
|
elif dev_type == 'driver':
|
2018-07-10 10:59:41 +02:00
|
|
|
return kwargs['driver']
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
|
|
|
|
def available_configs(dev_type='serial', *args, **kwargs):
|
|
|
|
"""Returns possible configurations to attempt to connect to."""
|
2018-08-06 10:19:43 +02:00
|
|
|
if dev_type == 'serial':
|
2018-07-10 10:59:41 +02:00
|
|
|
return SerialDriver.get_configs(*args, **kwargs)
|
2018-08-06 10:19:43 +02:00
|
|
|
elif dev_type == 'riot':
|
2018-07-10 10:59:41 +02:00
|
|
|
return RiotDriver.get_configs(*args, **kwargs)
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
"""Tests basic usage of the class"""
|
|
|
|
logging.getLogger().setLevel(logging.DEBUG)
|
|
|
|
logging.debug(available_configs())
|
|
|
|
logging.debug(driver_from_config())
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|