com.atid.lib.transport

## Class ATransport

- java.lang.Object
- - com.atid.lib.transport.ATransport

- Direct Known Subclasses:
    ATransportBluetooth, ATransportBluetoothLe, ATransportUsb

      public abstract class ATransport
      extends java.lang.Object

  The Transport class is a class for abstracting connections with Reader devices.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static interface` | `ATransport.IBufferControlEventListener` The interface for software flow control according to the state of the Transport internal buffer while the Transport instance is communicating with the device.
    `static interface` | `ATransport.IConnectStateEventListener` It is an interface to notify the connection status with the equipment.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static int` | `DUMP`
    `protected static int` | `INFO`
    `protected static int` | `IO`
    `protected java.lang.String` | `mAddress`
    `protected ConnectType` | `mConnType`
    `protected java.lang.String` | `mDevName`
    `protected DeviceType` | `mDevType`
    `protected boolean` | `mIsAutoConnect`
    `protected boolean` | `mIsDeviceAttached`
    `protected java.lang.String` | `mMacAddress`
    `protected com.atid.lib.util.collections.ByteQueue` | `mQueue`
    `protected ConnectState` | `mState`
    `protected java.lang.String` | `TAG`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ATransport()` Create an instance of the Transport class
    `ATransport(DeviceType type, java.lang.String name, java.lang.String address)` Create an instance of the Transport class
    `ATransport(DeviceType type, java.lang.String name, java.lang.String address, boolean autoConnect)` Create an instance of the Transport class
    `ATransport(DeviceType type, java.lang.String name, java.lang.String mac, java.lang.String address)` Create an instance of the Transport class
    `ATransport(DeviceType type, java.lang.String name, java.lang.String mac, java.lang.String address, boolean autoConnect)` Create an instance of the Transport class

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `abstract int` | `available()` Returns the length of data that can be read with the read method.
    `protected void` | `checkBufferSize(int size)`
    `abstract boolean` | `connect()` Attempts to connect to the appliance using an instance of the Transport class.
    `abstract void` | `destroy()` ATransport Destroys the instance and returns the resource.
    `abstract void` | `disconnect()` An instance of the Transport class closes the connection to the device to which the device is connected.
    `java.lang.String` | `getAddress()` Returns the address of the device to which the ATransport instance is connected.
    `abstract boolean` | `getAutoConnect()` Returns whether automatically connect to the appliance using an instance of the Transport class.
    `ConnectType` | `getConnectType()` Returns the instance of Transport associated with device.
    `abstract boolean` | `getDeviceAttached()` Returns whether attached to the appliance using an instance of the Transport class.
    `java.lang.String` | `getDeviceName()` Returns the name of the Device to which the ATransport instance is connected.
    `DeviceType` | `getDeviceType()` ATransport Returns the type of device to which the instance will be connected.
    `java.lang.String` | `getMacAddress()` Returns the MAC address of the device to which the ATransport instance is connected.
    `ConnectState` | `getState()` The instance of ATransport returns the connection status with device.
    `abstract void` | `listen()` An instance of the ATransport class waits for the device to connect.
    `int` | `read(byte[] data)` Read data received from the device.
    `int` | `read(byte[] data, int length)` Read data received from the device.
    `abstract int` | `read(byte[] data, int offset, int length)` Read data received from the device.
    `abstract int` | `read(byte[] data, int offset, int length, int timeout)` Read data received from the device.
    `void` | `setAddress(java.lang.String address)` Sets the address of the device to which the ATransport instance is connected.
    `abstract void` | `setAutoConnect(boolean enabled)` Sets whether automatically connect to the appliance using an instance of the Transport class.
    `void` | `setBufferControlListener(int min, ATransport.IBufferControlEventListener listener)` Sets the listener to be notified of buffer status in order for an instance of the Transport class to dynamically control the buffer.
    `void` | `setBufferControlListener(int min, int max, ATransport.IBufferControlEventListener listener)` Sets the listener to be notified of buffer status in order for an instance of the Transport class to dynamically control the buffer.
    `void` | `setDeviceName(java.lang.String name)` Sets the name of the device to which the ATransport instance is connected.
    `void` | `setDeviceType(DeviceType type)` ATransport Sets the type of device to which the instance will be connected.
    `void` | `setMacAddress(java.lang.String mac)` Sets the MAC address of the device to which the ATransport instance is connected.
    `protected void` | `setState(ConnectState state, java.lang.Object params)`
    `void` | `setStateListener(ATransport.IConnectStateEventListener listener)` Sets the listener to receive the connection status of an instance of the ATransport class.
    `java.lang.String` | `toString()`
    `int` | `write(byte[] data)` Transfer data to the device.
    `int` | `write(byte[] data, int length)` Transfer data to the device.
    `abstract int` | `write(byte[] data, int offset, int length)` Transfer data to the device.
    `abstract int` | `write(byte[] data, int offset, int length, int timeout)` Transfer data to the device.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### INFO

          protected static final int INFO

      See Also:
        Constant Field Values

    - #### IO

          protected static final int IO

      See Also:
        Constant Field Values

    - #### DUMP

          protected static final int DUMP

      See Also:
        Constant Field Values

    - #### TAG

          protected java.lang.String TAG

    - #### mState

          protected volatile ConnectState mState

    - #### mConnType

          protected volatile ConnectType mConnType

    - #### mDevType

          protected volatile DeviceType mDevType

    - #### mDevName

          protected volatile java.lang.String mDevName

    - #### mMacAddress

          protected volatile java.lang.String mMacAddress

    - #### mAddress

          protected volatile java.lang.String mAddress

    - #### mIsAutoConnect

          protected volatile boolean mIsAutoConnect

    - #### mIsDeviceAttached

          protected volatile boolean mIsDeviceAttached

    - #### mQueue

          protected com.atid.lib.util.collections.ByteQueue mQueue

  - ### Constructor Detail

    - #### ATransport

          public ATransport()

      Create an instance of the Transport class

    - #### ATransport

          public ATransport(DeviceType type,
                            java.lang.String name,
                            java.lang.String address)

      Create an instance of the Transport class
      Parameters:
        `type` - A DeviceType enumeration that specifies the type of connected device using an instance of the Transport class.
        `name` - A string that specifies the name of the connected device using an instance of the Transport class.
        `address` - A string that specifies the address of the connected device by using an instance of the Transport class.

    - #### ATransport

          public ATransport(DeviceType type,
                            java.lang.String name,
                            java.lang.String address,
                            boolean autoConnect)

      Create an instance of the Transport class
      Parameters:
        `type` - A DeviceType enumeration that specifies the type of connected device using an instance of the Transport class.
        `name` - A string that specifies the name of the connected device using an instance of the Transport class.
        `address` - A string that specifies the address of the connected device by using an instance of the Transport class.
        `autoConnect` - A boolean that sets whether automatically connect to the device using an instance of the Transport class.

    - #### ATransport

          public ATransport(DeviceType type,
                            java.lang.String name,
                            java.lang.String mac,
                            java.lang.String address)

      Create an instance of the Transport class
      Parameters:
        `type` - A DeviceType enumeration that specifies the type of connected device using an instance of the Transport class.
        `name` - A string that specifies the name of the connected device using an instance of the Transport class.
        `mac` - A string that specifies the MAC address of the device to be connected using the instance of the ATransport class.
        `address` - A string that specifies the address of the connected device by using an instance of the Transport class.

    - #### ATransport

          public ATransport(DeviceType type,
                            java.lang.String name,
                            java.lang.String mac,
                            java.lang.String address,
                            boolean autoConnect)

      Create an instance of the Transport class
      Parameters:
        `type` - A DeviceType enumeration that specifies the type of connected device using an instance of the Transport class.
        `name` - A string that specifies the name of the connected device using an instance of the Transport class.
        `mac` - A string that specifies the MAC address of the device to be connected using the instance of the ATransport class.
        `address` - A string that specifies the address of the connected device by using an instance of the Transport class.
        `autoConnect` - A boolean that sets whether automatically connect to the device using an instance of the Transport class.

  - ### Method Detail

    - #### destroy

          public abstract void destroy()

      ATransport Destroys the instance and returns the resource.

    - #### setAutoConnect

          public abstract void setAutoConnect(boolean enabled)

      Sets whether automatically connect to the appliance using an instance of the Transport class. Supported the usb interface only.
      Parameters:
        `enabled` - A boolean specifying whether the device automatically connect.

    - #### getAutoConnect

          public abstract boolean getAutoConnect()

      Returns whether automatically connect to the appliance using an instance of the Transport class. Supported the usb interface only.
      Returns:
        Returns true if enabled the automatically connection, false if it disabled.

    - #### getDeviceAttached

          public abstract boolean getDeviceAttached()

      Returns whether attached to the appliance using an instance of the Transport class. Supported the usb interface only.
      Returns:
        Returns true if attached the usb device, false if it detached.

    - #### connect

          public abstract boolean connect()

      Attempts to connect to the appliance using an instance of the Transport class.
      Returns:
        Returns true if the connection attempt with the device is successful, false if it fails.

    - #### listen

          public abstract void listen()

      An instance of the ATransport class waits for the device to connect.

    - #### disconnect

          public abstract void disconnect()

      An instance of the Transport class closes the connection to the device to which the device is connected.

    - #### write

          public int write(byte[] data)

      Transfer data to the device.
      Parameters:
        `data` - A byte array that specifies the data to transfer to the Device.
      Returns:
        Returns the length of the data transferred to the Device.

    - #### write

          public int write(byte[] data,
                           int length)

      Transfer data to the device.
      Parameters:
        `data` - A byte array that specifies the data to transfer to the Device.
        `length` - An integer indicating the length of the data to be transferred to the Device.
      Returns:
        Returns the length of the data transferred to the Device.

    - #### write

          public abstract int write(byte[] data,
                                    int offset,
                                    int length)

      Transfer data to the device.
      Parameters:
        `data` - A byte array that specifies the data to transfer to the Device.
        `offset` - An integer indicating the start address of the data to be transferred to the Device.
        `length` - An integer indicating the length of the data to be transferred to the Device.
      Returns:
        Returns the length of the data transferred to the Device.

    - #### write

          public abstract int write(byte[] data,
                                    int offset,
                                    int length,
                                    int timeout)

      Transfer data to the device.
      Parameters:
        `data` - A byte array that specifies the data to transfer to the Device.
        `offset` - An integer indicating the start address of the data to be transferred to the Device.
        `length` - An integer indicating the length of the data to be transferred to the Device.
        `timeout` - An integer specifying the timeout of data transmission to the device.
      Returns:
        Returns the length of the data transferred to the Device.

    - #### available

          public abstract int available()

      Returns the length of data that can be read with the read method.
      Returns:
        Returns the length of data received from the device.

    - #### read

          public int read(byte[] data)

      Read data received from the device.
      Parameters:
        `data` - A byte array to store the data received from the device.
      Returns:
        Returns the length of data received from device and stored in a byte array.

    - #### read

          public int read(byte[] data,
                          int length)

      Read data received from the device.
      Parameters:
        `data` - A byte array to store the data received from the device.
        `length` - An integer specifying the maximum length at which data received from the device can be stored in a byte array.
      Returns:
        Returns the length of data received from device and stored in a byte array.

    - #### read

          public abstract int read(byte[] data,
                                   int offset,
                                   int length)

      Read data received from the device.
      Parameters:
        `data` - A byte array to store the data received from the device.
        `offset` - Integer specifying the start address at which data received from device will begin to be stored in a byte array.
        `length` - An integer specifying the maximum length at which data received from the device can be stored in a byte array.
      Returns:
        Returns the length of data received from device and stored in a byte array.

    - #### read

          public abstract int read(byte[] data,
                                   int offset,
                                   int length,
                                   int timeout)

      Read data received from the device.
      Parameters:
        `data` - A byte array to store the data received from the device.
        `offset` - Integer specifying the start address at which data received from device will begin to be stored in a byte array.
        `length` - An integer specifying the maximum length at which data received from the device can be stored in a byte array.
        `timeout` - An integer that specifies the timeout for reading data received from the device.
      Returns:
        Returns the length of data received from device and stored in a byte array.

    - #### setStateListener

          public void setStateListener(ATransport.IConnectStateEventListener listener)

      Sets the listener to receive the connection status of an instance of the ATransport class.
      Parameters:
        `listener` - An instance of ITransportStateEventListener to receive the connection status of an instance of the ATransport class.

    - #### setBufferControlListener

          public void setBufferControlListener(int min,
                                               ATransport.IBufferControlEventListener listener)

      Sets the listener to be notified of buffer status in order for an instance of the Transport class to dynamically control the buffer.
      Parameters:
        `min` - An integer representing the minimum state of the buffers of the ATransport instance.
        `listener` - An instance of the IBuffer Control Listener interface to receive notification of the state of the Transport class and the buffers of the instance.

    - #### setBufferControlListener

          public void setBufferControlListener(int min,
                                               int max,
                                               ATransport.IBufferControlEventListener listener)

      Sets the listener to be notified of buffer status in order for an instance of the Transport class to dynamically control the buffer.
      Parameters:
        `min` - An integer representing the minimum state of the buffers of the ATransport instance.
        `max` - An integer representing the maximum state of the buffers of the ATransport instance.
        `listener` - An instance of the IBuffer Control Listener interface to receive notification of the state of the Transport class and the buffers of the instance.

    - #### getConnectType

          public ConnectType getConnectType()

      Returns the instance of Transport associated with device.
      Returns:
        A ConnectType enumeration that indicates how the device is connected.

    - #### getDeviceType

          public DeviceType getDeviceType()

      ATransport Returns the type of device to which the instance will be connected.
      Returns:
        The DeviceType enumeration indicating the type of device.

    - #### setDeviceType

          public void setDeviceType(DeviceType type)

      ATransport Sets the type of device to which the instance will be connected.
      Parameters:
        `type` - The DeviceType enumeration indicating the type of device.

    - #### getDeviceName

          public java.lang.String getDeviceName()

      Returns the name of the Device to which the ATransport instance is connected.
      Returns:
        A string representing the name of the Device.

    - #### setDeviceName

          public void setDeviceName(java.lang.String name)

      Sets the name of the device to which the ATransport instance is connected.
      Parameters:
        `name` - A string representing the name of the Device.

    - #### getMacAddress

          public java.lang.String getMacAddress()

      Returns the MAC address of the device to which the ATransport instance is connected.
      Returns:
        A string representing the MAC address of the Device.

    - #### setMacAddress

          public void setMacAddress(java.lang.String mac)

      Sets the MAC address of the device to which the ATransport instance is connected.
      Parameters:
        `mac` - A string representing the MAC address of the Device.

    - #### getAddress

          public java.lang.String getAddress()

      Returns the address of the device to which the ATransport instance is connected.
      Returns:
        A string representing the address of the Device.

    - #### setAddress

          public void setAddress(java.lang.String address)

      Sets the address of the device to which the ATransport instance is connected.
      Parameters:
        `address` - A string representing the address of the Device.

    - #### getState

          public ConnectState getState()

      The instance of ATransport returns the connection status with device.
      Returns:
        A ConnectState enumeration indicating the device and its connection status.

    - #### setState

          protected void setState(ConnectState state,
                                  java.lang.Object params)

    - #### checkBufferSize

          protected void checkBufferSize(int size)

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`