com.datecs.hub

## Class Hub

- java.lang.Object
- - com.datecs.hub.Hub

- All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

      public class Hub
      extends java.lang.Object
      implements java.io.Closeable

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `ERROR_COMMUNICATION` Communication error.
    `static int` | `ERROR_INVALID_COMMAND` Invalid command INS.
    `static int` | `ERROR_INVALID_LENGTH` Wrong data field length.
    `static int` | `ERROR_NVRAM` Error with NV memory.
    `static int` | `ERROR_SLAVE` Slave ID is not available.
    `static int` | `ERROR_TIMEOUT` Timeout occurred during command reception.
    `static int` | `EVENT_SLAVE_CONNECTED`
    `static int` | `EVENT_SLAVE_DATA_RECEIVED`
    `static int` | `EVENT_SLAVE_DISCONNECTED`
    `static int` | `EVENT_SLAVE_OVERCURRENT`
    `static int` | `SLAVE_STATE_DISCONNECTED` Slave is disconnected.
    `static int` | `SLAVE_STATE_ERROR` Slave error state (i.e.
    `static int` | `SLAVE_STATE_READY` Slave is ready.
    `static int` | `SLAVE_STATE_UNKNOWN` Slave state is unknown.
    `static int` | `SLAVE_TYPE_RS232` RS232 slave type.
    `static int` | `SLAVE_TYPE_USB` USB slave type.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Hub(java.io.FileDescriptor fd)` Constructs a new instance of this class from given FileDescriptor
    `Hub(java.io.InputStream inputStream, java.io.OutputStream outputStream)` Constructs a new instance of this class from given InputStream and OutputStream.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()`
    `java.io.InputStream` | `getDataInputStream(int slaveID)` Returns instance of InputStream associated with slave.
    `java.io.OutputStream` | `getDataOutputStream(int slaveID)` Returns instance of OutputStream associated with slave.
    `int` | `getSlaveState(int slaveID)` Get port state.
    `int` | `getSlaveType(int slaveID)` Get slave type.
    `byte[]` | `getUsbDeviceDescriptor(int slaveID)` Get USB device descriptor.
    `java.lang.String` | `getUsbStringDescriptor(int slaveID)` Get USB string descriptor.
    `byte[]` | `readNVRAM(int slaveID)` Read data from NV memory.
    `void` | `setAppleChargeCurrent(int current)` Set Apple devices charge current.
    `void` | `setBaudRate(int slaveID, int baudRate)` Set RS232 baud rate.
    `static void` | `setDebug(boolean on)` Enable or disable debug output.
    `void` | `setSlaveConnectionListener(SlaveConnection connection)` Set slave connection listener.
    `void` | `writeNVRAM(int slaveID, byte[] data)` Write data to NV memory.

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

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

- - ### Field Detail

    - #### ERROR_INVALID_LENGTH

          public static final int ERROR_INVALID_LENGTH

      Wrong data field length.
      See Also:
        Constant Field Values

    - #### ERROR_SLAVE

          public static final int ERROR_SLAVE

      Slave ID is not available.
      See Also:
        Constant Field Values

    - #### ERROR_INVALID_COMMAND

          public static final int ERROR_INVALID_COMMAND

      Invalid command INS.
      See Also:
        Constant Field Values

    - #### ERROR_TIMEOUT

          public static final int ERROR_TIMEOUT

      Timeout occurred during command reception.
      See Also:
        Constant Field Values

    - #### ERROR_COMMUNICATION

          public static final int ERROR_COMMUNICATION

      Communication error.
      See Also:
        Constant Field Values

    - #### ERROR_NVRAM

          public static final int ERROR_NVRAM

      Error with NV memory.
      See Also:
        Constant Field Values

    - #### SLAVE_TYPE_USB

          public static final int SLAVE_TYPE_USB

      USB slave type.
      See Also:
        Constant Field Values

    - #### SLAVE_TYPE_RS232

          public static final int SLAVE_TYPE_RS232

      RS232 slave type.
      See Also:
        Constant Field Values

    - #### SLAVE_STATE_DISCONNECTED

          public static final int SLAVE_STATE_DISCONNECTED

      Slave is disconnected.
      See Also:
        Constant Field Values

    - #### SLAVE_STATE_READY

          public static final int SLAVE_STATE_READY

      Slave is ready.
      See Also:
        Constant Field Values

    - #### SLAVE_STATE_UNKNOWN

          public static final int SLAVE_STATE_UNKNOWN

      Slave state is unknown.
      See Also:
        Constant Field Values

    - #### SLAVE_STATE_ERROR

          public static final int SLAVE_STATE_ERROR

      Slave error state (i.e. overcurrent condition).
      See Also:
        Constant Field Values

    - #### EVENT_SLAVE_CONNECTED

          public static final int EVENT_SLAVE_CONNECTED

      See Also:
        Constant Field Values

    - #### EVENT_SLAVE_DISCONNECTED

          public static final int EVENT_SLAVE_DISCONNECTED

      See Also:
        Constant Field Values

    - #### EVENT_SLAVE_DATA_RECEIVED

          public static final int EVENT_SLAVE_DATA_RECEIVED

      See Also:
        Constant Field Values

    - #### EVENT_SLAVE_OVERCURRENT

          public static final int EVENT_SLAVE_OVERCURRENT

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### Hub

          public Hub(java.io.InputStream inputStream,
                     java.io.OutputStream outputStream)

      Constructs a new instance of this class from given InputStream and OutputStream.
      Parameters:
        `inputStream` - the input stream.
        `outputStream` - the output stream.

    - #### Hub

          public Hub(java.io.FileDescriptor fd)

      Constructs a new instance of this class from given FileDescriptor
      Parameters:
        `fd` - the file descriptor.

  - ### Method Detail

    - #### close

          public void close()
                     throws java.io.IOException

      Specified by:
        `close` in interface `java.io.Closeable`
      Specified by:
        `close` in interface `java.lang.AutoCloseable`
      Throws:
        `java.io.IOException`

    - #### setDebug

          public static void setDebug(boolean on)

      Enable or disable debug output.
      Parameters:
        `on` - true to enable debug output.

    - #### setSlaveConnectionListener

          public void setSlaveConnectionListener(SlaveConnection connection)

      Set slave connection listener.
      Parameters:
        `connection` - the slave connection listener.

    - #### getSlaveType

          public int getSlaveType(int slaveID)
                           throws java.io.IOException

      Get slave type.
      Parameters:
        `slaveID` - slave identifier.
      Returns:
        slave type, one of the SLAVE_TYPE_* constant values.
      Throws:
        `java.io.IOException` - if an I/O error occurs.

    - #### getSlaveState

          public int getSlaveState(int slaveID)
                            throws java.io.IOException

      Get port state.
      Parameters:
        `slaveID` - slave identifier.
      Returns:
        port state, one of the SLAVE_STATE_* constant values.
      Throws:
        `java.io.IOException` - if an I/O error occurs.

    - #### writeNVRAM

          public void writeNVRAM(int slaveID,
                                 byte[] data)
                          throws java.io.IOException

      Write data to NV memory.

      This command preserves data for each slave in a separate slot. If there is already data in slot, it will be overwritten. Data to be written can be up to 128 bytes. If empty data field is sent, data will be erased.

      Parameters:
        `slaveID` - slave identifier.
        `data` - data to be written in NV memory.
      Throws:
        `java.io.IOException` - if an I/O error occurs.

    - #### readNVRAM

          public byte[] readNVRAM(int slaveID)
                           throws java.io.IOException

      Read data from NV memory.

      Return data written in NV memory for the selected slave ID.

      Parameters:
        `slaveID` - slave identifier.
      Returns:
        Data field contains all data read from the NV memory slot for the selected slave ID. If no data has been written, this field will be empty and Data field length will be 00h
      Throws:
        `java.io.IOException` - if an I/O error occurs.

    - #### setBaudRate

          public void setBaudRate(int slaveID,
                                  int baudRate)
                           throws java.io.IOException

      Set RS232 baud rate.
      Parameters:
        `slaveID` - slave identifier.
        `baudRate` - the baud rate.
      Throws:
        `java.io.IOException` - if an I/O error occurs.

    - #### getUsbDeviceDescriptor

          public byte[] getUsbDeviceDescriptor(int slaveID)
                                        throws java.io.IOException

      Get USB device descriptor.

      Return device descriptor from specified slave, which should be of USB type.

      Parameters:
        `slaveID` - slave identifier.
      Returns:
        device descriptor as is returned from slave.
      Throws:
        `java.io.IOException` - if an I/O error occurs.

    - #### getUsbStringDescriptor

          public java.lang.String getUsbStringDescriptor(int slaveID)
                                                  throws java.io.IOException

      Get USB string descriptor.
      Parameters:
        `slaveID` - slave identifier.
      Returns:
        ASCII string descriptor.
      Throws:
        `java.io.IOException` - if an I/O error occurs.

    - #### setAppleChargeCurrent

          public void setAppleChargeCurrent(int current)
                                     throws java.io.IOException

      Set Apple devices charge current.

      This settings is stored in NV memory and is used for all slave channels.

      Parameters:
        `current` - Charge current in mA.
      Throws:
        `java.io.IOException` - if an I/O error occurs.

    - #### getDataOutputStream

          public java.io.OutputStream getDataOutputStream(int slaveID)
                                                   throws java.io.IOException

      Returns instance of OutputStream associated with slave.
      Parameters:
        `slaveID` - slave identifier.
      Returns:
        the OutputStream instance.
      Throws:
        `java.io.IOException` - IOException if an I/O error occurs.

    - #### getDataInputStream

          public java.io.InputStream getDataInputStream(int slaveID)
                                                 throws java.io.IOException

      Returns instance of InputStream associated with slave.
      Parameters:
        `slaveID` - slave identifier.
      Returns:
        the InputStream instance.
      Throws:
        `java.io.IOException` - IOException if an I/O error occurs.