import struct
from threading import RLock
from transport import PortgwSerial
from transport import PortgwTcp


class PortgwBase(object):
	def __init__(self, transport):
		self.uart_lock = RLock()
		self.tries = 1

		self.open = transport.open
		self.close = transport.close

		self.write = transport.write
		self.read = transport.read


class PortgwBaseSerial(PortgwBase):
	def __init__(self, _serial_port, _baudrate):
		transport = PortgwSerial(_serial_port, _baudrate)
		super(PortgwBaseSerial, self).__init__(transport)
		# self.transport = PortgwSerial(_serial_port, _baudrate)


class PortgwBaseTcp(PortgwBase):
	def __init__(self, _ip, _port):
		transport = PortgwTcp(_ip, _port)
		super(PortgwBaseTcp, self).__init__(transport)
		# self.transport = PortgwTcp(_ip, _port)
		
