mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-17 02:48:34 +03:00
transport: Move printing of reader number/name to generic code
Let's avoid copy+pasting print statements everywhere. The instances do already have a __str__ method for the purpose of printing their name in a generic way. Change-Id: I663a9ea69bf7e7aaa6502896b6a71ef692f8d844
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
""" pySim: PCSC reader transport link base
|
||||
"""
|
||||
|
||||
import os
|
||||
import abc
|
||||
import argparse
|
||||
from typing import Optional, Tuple
|
||||
@@ -300,4 +301,10 @@ def init_reader(opts, **kwargs) -> LinkBase:
|
||||
print("No reader/driver specified; falling back to default (Serial reader)")
|
||||
from pySim.transport.serial import SerialSimLink
|
||||
sl = SerialSimLink(opts, **kwargs)
|
||||
|
||||
if os.environ.get('PYSIM_INTEGRATION_TEST') == "1":
|
||||
print("Using %s reader interface" % (sl.name))
|
||||
else:
|
||||
print("Using reader %s" % sl)
|
||||
|
||||
return sl
|
||||
|
||||
@@ -76,14 +76,11 @@ class L1CTLMessageSIM(L1CTLMessage):
|
||||
|
||||
class CalypsoSimLink(LinkBase):
|
||||
"""Transport Link for Calypso based phones."""
|
||||
name = 'Calypso-based (OsmocomBB) reader'
|
||||
|
||||
def __init__(self, opts: argparse.Namespace = argparse.Namespace(osmocon_sock="/tmp/osmocom_l2"), **kwargs):
|
||||
sock_path = opts.osmocon_sock
|
||||
super().__init__(**kwargs)
|
||||
if os.environ.get('PYSIM_INTEGRATION_TEST') == "1":
|
||||
print("Using Calypso-based (OsmocomBB) reader interface")
|
||||
else:
|
||||
print("Using Calypso-based (OsmocomBB) reader at socket %s" % sock_path)
|
||||
# Make sure that a given socket path exists
|
||||
if not os.path.exists(sock_path):
|
||||
raise ReaderError(
|
||||
|
||||
@@ -21,7 +21,6 @@ import serial
|
||||
import time
|
||||
import re
|
||||
import argparse
|
||||
import os
|
||||
from typing import Optional
|
||||
|
||||
from pySim.utils import Hexstr, ResTuple
|
||||
@@ -34,16 +33,13 @@ from pySim.exceptions import *
|
||||
|
||||
class ModemATCommandLink(LinkBase):
|
||||
"""Transport Link for 3GPP TS 27.007 compliant modems."""
|
||||
name = "modem for Generic SIM Access (3GPP TS 27.007)"
|
||||
|
||||
def __init__(self, opts: argparse.Namespace = argparse.Namespace(modem_dev='/dev/ttyUSB0',
|
||||
modem_baud=115200), **kwargs):
|
||||
device = opts.modem_dev
|
||||
baudrate = opts.modem_baud
|
||||
super().__init__(**kwargs)
|
||||
if os.environ.get('PYSIM_INTEGRATION_TEST') == "1":
|
||||
print("Using modem for Generic SIM Access (3GPP TS 27.007)")
|
||||
else:
|
||||
print("Using modem for Generic SIM Access (3GPP TS 27.007) at port %s" % device)
|
||||
self._sl = serial.Serial(device, baudrate, timeout=5)
|
||||
self._echo = False # this will be auto-detected by _check_echo()
|
||||
self._device = device
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import re
|
||||
from typing import Optional, Union
|
||||
|
||||
@@ -34,6 +33,7 @@ from pySim.utils import h2i, i2h, Hexstr, ResTuple
|
||||
|
||||
class PcscSimLink(LinkBase):
|
||||
""" pySim: PCSC reader transport link."""
|
||||
name = 'PC/SC'
|
||||
|
||||
def __init__(self, opts: argparse.Namespace = argparse.Namespace(pcsc_dev=0), **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
@@ -57,11 +57,6 @@ class PcscSimLink(LinkBase):
|
||||
|
||||
self._con = self._reader.createConnection()
|
||||
|
||||
if os.environ.get('PYSIM_INTEGRATION_TEST') == "1":
|
||||
print("Using PC/SC reader interface")
|
||||
else:
|
||||
print("Using PC/SC reader %s" % self)
|
||||
|
||||
def __del__(self):
|
||||
try:
|
||||
# FIXME: this causes multiple warnings in Python 3.5.3
|
||||
|
||||
@@ -29,14 +29,11 @@ from pySim.utils import h2b, b2h, Hexstr, ResTuple
|
||||
|
||||
class SerialSimLink(LinkBase):
|
||||
""" pySim: Transport Link for serial (RS232) based readers included with simcard"""
|
||||
name = 'Serial'
|
||||
|
||||
def __init__(self, opts = argparse.Namespace(device='/dev/ttyUSB0', baudrate=9600), rst: str = '-rts',
|
||||
debug: bool = False, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
if os.environ.get('PYSIM_INTEGRATION_TEST') == "1":
|
||||
print("Using serial reader interface")
|
||||
else:
|
||||
print("Using serial reader interface at port %s" % opts.device)
|
||||
if not os.path.exists(opts.device):
|
||||
raise ValueError("device file %s does not exist -- abort" % opts.device)
|
||||
self._sl = serial.Serial(
|
||||
|
||||
Reference in New Issue
Block a user