core

## Class IqrfDeviceModel

- java.lang.Object
- - core.IqrfDeviceModel

-     public class IqrfDeviceModel
      extends java.lang.Object

  Represents the IQRF TR-72D-WMB device.
  Author:
    David Hudec (dwdization@gmail.com)

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `IqrfDeviceModel.SleepMode` Operation modes supported by the IQRF device.
    `static class` | `IqrfDeviceModel.TransmitMode` Transmission modes supported by the IQRF device.
    `static class` | `IqrfDeviceModel.TransmitPower` Transmission powers supported by the IQRF device.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private java.lang.Byte` | `accessByte`
    `private java.lang.Byte[]` | `aesKey`
    `private static int` | `baudRate`
    `private static int` | `dataBits`
    `private java.lang.Byte` | `deviceType`
    `private static java.util.logging.Logger` | `LOG`
    `private java.lang.Byte[]` | `manID`
    `private static byte` | `messageTerminator`
    `private int` | `mode`
    `private static int` | `parity`
    `private java.lang.Byte[]` | `serial`
    `private jssc.SerialPort` | `serialPort`
    `private java.lang.Byte` | `statusByte`
    `private static int` | `stopBits`
    `private IqrfDeviceModel.TransmitMode` | `transmitMode`
    `private IqrfDeviceModel.TransmitPower` | `transmitPower`
    `private java.lang.Byte` | `version`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `IqrfDeviceModel()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `connect(java.lang.String commPortName)` Attempts to connect to the IQRF module on the given serial port.
    `java.lang.String` | `getPortName()`
    `boolean` | `isBatteryLow()` Reads battery status from the device.
    `static void` | `main(java.lang.String[] args)`
    `private java.lang.Byte[]` | `makeAddress()`
    `java.lang.Byte` | `readAccessByte()` Reads access byte from the device.
    `java.lang.Byte[]` | `readAesKey()` Reads AES key from the device.
    `void` | `readAll()` Reads all configuration parameters from the device and stores them in cache.
    `java.lang.String` | `readBytesUntilEOL()` Reads device response and logs it.
    `java.lang.Byte` | `readDeviceType()` Reads device type from the device.
    `java.lang.String` | `readFirmwareVersion()` Reads firmware version from the device.
    `private void` | `readLinkAddress()`
    `java.lang.Byte[]` | `readManID()` Reads manufacturer ID from the device.
    `private void` | `readMessageResponse()`
    `int` | `readMode()` Reads Wireless M-Bus mode from the device configuration.
    `java.lang.Byte[]` | `readSerial()` Reads serial number from the device.
    `IqrfDeviceModel.SleepMode` | `readSleepMode()` Reads operation mode from the device.
    `java.lang.Byte` | `readStatusByte()` Reads status byte from the device.
    `private void` | `readStatusResponse()`
    `IqrfDeviceModel.TransmitMode` | `readTransmissionMode()` Reads transmission mode from the device.
    `IqrfDeviceModel.TransmitPower` | `readTransmitPower()` Reads transmission power from the device.
    `java.lang.Byte` | `readVersion()` Reads version from the device.
    `void` | `restart()` Restarts the device.
    `java.lang.String[]` | `scanForPorts()` Scans for open serial ports.
    `void` | `setByFrame(Frame f)` Sets the device configuration to match given frame parameter's.
    `void` | `shutdown()` Terminates the connection and releases the serial port.
    `void` | `sleep()` Triggers sleep mode on the device, if it is awake.
    `void` | `wakeUp()` Awakes the device, if it is asleep.
    `void` | `writeAccessByte(java.lang.Byte accessByte)` Writes given access byte to the device.
    `void` | `writeAesKey(java.lang.Byte[] aesKey)` Writes given AES key to the device.
    `void` | `writeAll()` Writes all parameters stored in the cache of this model to the device configuration.
    `private void` | `writeApplicationAddress()`
    `void` | `writeDeviceType(java.lang.Byte deviceType)` Writes given device type to the device.
    `void` | `writeFrame(Frame f)` Sends given frame to the device for transmission.
    `private void` | `writeLinkAddress()`
    `void` | `writeManID(java.lang.Byte[] manID)` Writes given manufacturer ID to the device.
    `void` | `writeMode(int mode)` Writes given Wireless M-Bus mode to the device configuration.
    `private void` | `writeRaw(byte b)`
    `private void` | `writeRaw(byte[] bytes)`
    `void` | `writeSerial(java.lang.Byte[] serial)` Writes given serial number to the device.
    `void` | `writeStatusByte(java.lang.Byte statusByte)` Writes given status byte to the device.
    `void` | `writeTransmissionMode(IqrfDeviceModel.TransmitMode mode)` Writes given transmission mode to the device.
    `void` | `writeTransmitPower(IqrfDeviceModel.TransmitPower power)` Writes given transmission power to the device.
    `void` | `writeVersion(java.lang.Byte version)` Writes given version to the device.
    `private void` | `writeWords(java.lang.String input)` Separates the input String by comma (",") and sends the resulting words one by one with 2 ms gaps between them, ">" at the start and "\r" at the end.

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

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

- - ### Field Detail

    - #### accessByte

          private java.lang.Byte accessByte

    - #### aesKey

          private java.lang.Byte[] aesKey

    - #### baudRate

          private static final int baudRate

      See Also:
        Constant Field Values

    - #### dataBits

          private static final int dataBits

      See Also:
        Constant Field Values

    - #### deviceType

          private java.lang.Byte deviceType

    - #### LOG

          private static final java.util.logging.Logger LOG

    - #### manID

          private java.lang.Byte[] manID

    - #### messageTerminator

          private static final byte messageTerminator

    - #### mode

          private int mode

    - #### parity

          private static final int parity

      See Also:
        Constant Field Values

    - #### serial

          private java.lang.Byte[] serial

    - #### serialPort

          private jssc.SerialPort serialPort

    - #### statusByte

          private java.lang.Byte statusByte

    - #### stopBits

          private static final int stopBits

      See Also:
        Constant Field Values

    - #### transmitMode

          private IqrfDeviceModel.TransmitMode transmitMode

    - #### transmitPower

          private IqrfDeviceModel.TransmitPower transmitPower

    - #### version

          private java.lang.Byte version

  - ### Constructor Detail

    - #### IqrfDeviceModel

          public IqrfDeviceModel()

  - ### Method Detail

    - #### connect

          public void connect(java.lang.String commPortName)
                       throws jssc.SerialPortException

      Attempts to connect to the IQRF module on the given serial port.
      Parameters:
        `commPortName` - serial port name
      Throws:
        `jssc.SerialPortException` - when connection fails

    - #### getPortName

          public java.lang.String getPortName()

      Returns:
        name of the serial port used to communicate with the device

    - #### isBatteryLow

          public boolean isBatteryLow()
                               throws jssc.SerialPortException

      Reads battery status from the device.
      Returns:
        true if the battery's voltage is under 2.95 V
      Throws:
        `jssc.SerialPortException` - in case of read/write error

    - #### main

          public static void main(java.lang.String[] args)
                           throws jssc.SerialPortException

      Throws:
        `jssc.SerialPortException`

    - #### makeAddress

          private java.lang.Byte[] makeAddress()

    - #### readAccessByte

          public java.lang.Byte readAccessByte()
                                        throws jssc.SerialPortException,
                                               java.lang.NumberFormatException

      Reads access byte from the device. The result is also stored in cache of this model.
      Returns:
        access byte the device uses
      Throws:
        `jssc.SerialPortException` - in case of read/write error
        `java.lang.NumberFormatException`

    - #### readAesKey

          public java.lang.Byte[] readAesKey()
                                      throws jssc.SerialPortException

      Reads AES key from the device. The result is also stored in cache of this model.
      Returns:
        AES key the device uses
      Throws:
        `jssc.SerialPortException` - in case of read/write error

    - #### readAll

          public void readAll()
                       throws jssc.SerialPortException

      Reads all configuration parameters from the device and stores them in cache.
      Throws:
        `jssc.SerialPortException` - in case of read/write error

    - #### readBytesUntilEOL

          public java.lang.String readBytesUntilEOL()
                                             throws jssc.SerialPortException

      Reads device response and logs it. Blocks in case no response is given.
      Returns:
        Device response in String
      Throws:
        `jssc.SerialPortException` - in case of read/write error

    - #### readDeviceType

          public java.lang.Byte readDeviceType()
                                        throws jssc.SerialPortException

      Reads device type from the device. The result is also stored in cache of this model.
      Returns:
        device type the device uses
      Throws:
        `jssc.SerialPortException` - in case of read/write error

    - #### readFirmwareVersion

          public java.lang.String readFirmwareVersion()
                                               throws jssc.SerialPortException

      Reads firmware version from the device.
      Returns:
        firmware version of the device
      Throws:
        `jssc.SerialPortException` - in case of read/write error

    - #### readLinkAddress

          private void readLinkAddress()
                                throws jssc.SerialPortException

      Throws:
        `jssc.SerialPortException`

    - #### readManID

          public java.lang.Byte[] readManID()
                                     throws jssc.SerialPortException

      Reads manufacturer ID from the device. The result is also stored in cache of this model.
      Returns:
        manufacturer ID the device uses
      Throws:
        `jssc.SerialPortException` - in case of read/write error

    - #### readMessageResponse

          private void readMessageResponse()
                                    throws jssc.SerialPortException

      Throws:
        `jssc.SerialPortException`

    - #### readMode

          public int readMode()
                       throws jssc.SerialPortException,
                              java.lang.NumberFormatException

      Reads Wireless M-Bus mode from the device configuration. The result is also stored in cache of this model.
      Returns:
        mode the device is in
      Throws:
        `jssc.SerialPortException` - in case of read/write error
        `java.lang.NumberFormatException` - in case of invalid/unsupported response

    - #### readSerial

          public java.lang.Byte[] readSerial()
                                      throws jssc.SerialPortException

      Reads serial number from the device. The result is also stored in cache of this model.
      Returns:
        serial number the device uses
      Throws:
        `jssc.SerialPortException` - in case of read/write error

    - #### readSleepMode

          public IqrfDeviceModel.SleepMode readSleepMode()
                                                  throws jssc.SerialPortException

      Reads operation mode from the device.
      Returns:
        operation mode the device is in
      Throws:
        `jssc.SerialPortException` - in case of read/write error

    - #### readStatusByte

          public java.lang.Byte readStatusByte()
                                        throws jssc.SerialPortException,
                                               java.lang.NumberFormatException

      Reads status byte from the device. The result is also stored in cache of this model.
      Returns:
        status byte the device uses
      Throws:
        `jssc.SerialPortException` - in case of read/write error
        `java.lang.NumberFormatException`

    - #### readStatusResponse

          private void readStatusResponse()

    - #### readTransmissionMode

          public IqrfDeviceModel.TransmitMode readTransmissionMode()
                                                            throws jssc.SerialPortException

      Reads transmission mode from the device. The result is also stored in cache of this model.
      Returns:
        transmission mode the device uses
      Throws:
        `jssc.SerialPortException` - in case of read/write error

    - #### readTransmitPower

          public IqrfDeviceModel.TransmitPower readTransmitPower()
                                                          throws jssc.SerialPortException

      Reads transmission power from the device. The result is also stored in cache of this model.
      Returns:
        transmission power the device uses
      Throws:
        `jssc.SerialPortException` - in case of read/write error

    - #### readVersion

          public java.lang.Byte readVersion()
                                     throws jssc.SerialPortException

      Reads version from the device. The result is also stored in cache of this model.
      Returns:
        version the device uses
      Throws:
        `jssc.SerialPortException` - in case of read/write error

    - #### restart

          public void restart()
                       throws jssc.SerialPortException

      Restarts the device.
      Throws:
        `jssc.SerialPortException` - in case of read/write error

    - #### scanForPorts

          public java.lang.String[] scanForPorts()

      Scans for open serial ports.
      Returns:
        a list of names of found open serial ports

    - #### setByFrame

          public void setByFrame(Frame f)
                          throws jssc.SerialPortException

      Sets the device configuration to match given frame parameter's. Should be used before sending the frame.
      Parameters:
        `f` - frame to configure the device by
      Throws:
        `jssc.SerialPortException` - in case of read/write error

    - #### shutdown

          public void shutdown()

      Terminates the connection and releases the serial port.

    - #### sleep

          public void sleep()
                     throws jssc.SerialPortException

      Triggers sleep mode on the device, if it is awake.
      Throws:
        `jssc.SerialPortException` - in case of read/write error

    - #### wakeUp

          public void wakeUp()
                      throws jssc.SerialPortException

      Awakes the device, if it is asleep.
      Throws:
        `jssc.SerialPortException` - in case of read/write error

    - #### writeAccessByte

          public void writeAccessByte(java.lang.Byte accessByte)
                               throws jssc.SerialPortException

      Writes given access byte to the device. Cache of this model is updated as well.
      Parameters:
        `accessByte` - access byte to write
      Throws:
        `jssc.SerialPortException` - in case of read/write error

    - #### writeAesKey

          public void writeAesKey(java.lang.Byte[] aesKey)
                           throws jssc.SerialPortException

      Writes given AES key to the device. Cache of this model is updated as well.
      Parameters:
        `aesKey` - AES key to write
      Throws:
        `jssc.SerialPortException` - in case of read/write error

    - #### writeAll

          public void writeAll()
                        throws jssc.SerialPortException

      Writes all parameters stored in the cache of this model to the device configuration.
      Throws:
        `jssc.SerialPortException` - in case of read/write error

    - #### writeApplicationAddress

          private void writeApplicationAddress()
                                        throws jssc.SerialPortException

      Throws:
        `jssc.SerialPortException`

    - #### writeDeviceType

          public void writeDeviceType(java.lang.Byte deviceType)
                               throws jssc.SerialPortException

      Writes given device type to the device. Cache of this model is updated as well.
      Parameters:
        `deviceType` - device type to write
      Throws:
        `jssc.SerialPortException` - in case of read/write error

    - #### writeFrame

          public void writeFrame(Frame f)
                          throws jssc.SerialPortException

      Sends given frame to the device for transmission. Before sending the frame, you should set the device configuration to match the frame.
      Parameters:
        `f` - frame to send
      Throws:
        `jssc.SerialPortException` - in case of read/write error

    - #### writeLinkAddress

          private void writeLinkAddress()
                                 throws jssc.SerialPortException

      Throws:
        `jssc.SerialPortException`

    - #### writeManID

          public void writeManID(java.lang.Byte[] manID)
                          throws jssc.SerialPortException

      Writes given manufacturer ID to the device. Cache of this model is updated as well.
      Parameters:
        `manID` - manufacturer ID to write
      Throws:
        `jssc.SerialPortException` - in case of read/write error

    - #### writeMode

          public void writeMode(int mode)
                         throws jssc.SerialPortException

      Writes given Wireless M-Bus mode to the device configuration.
      Parameters:
        `mode` - to write
      Throws:
        `jssc.SerialPortException` - in case of read/write error

    - #### writeRaw

          private void writeRaw(byte b)
                         throws jssc.SerialPortException

      Throws:
        `jssc.SerialPortException`

    - #### writeRaw

          private void writeRaw(byte[] bytes)
                         throws jssc.SerialPortException

      Throws:
        `jssc.SerialPortException`

    - #### writeSerial

          public void writeSerial(java.lang.Byte[] serial)
                           throws jssc.SerialPortException

      Writes given serial number to the device. Cache of this model is updated as well.
      Parameters:
        `serial` - serial number to write
      Throws:
        `jssc.SerialPortException` - in case of read/write error

    - #### writeStatusByte

          public void writeStatusByte(java.lang.Byte statusByte)
                               throws jssc.SerialPortException

      Writes given status byte to the device. Cache of this model is updated as well.
      Parameters:
        `statusByte` - status byte to write
      Throws:
        `jssc.SerialPortException` - in case of read/write error

    - #### writeTransmissionMode

          public void writeTransmissionMode(IqrfDeviceModel.TransmitMode mode)
                                     throws jssc.SerialPortException

      Writes given transmission mode to the device. Cache of this model is updated as well.
      Parameters:
        `mode` - transmission mode to write
      Throws:
        `jssc.SerialPortException` - in case of read/write error

    - #### writeTransmitPower

          public void writeTransmitPower(IqrfDeviceModel.TransmitPower power)
                                  throws jssc.SerialPortException

      Writes given transmission power to the device. Cache of this model is updated as well.
      Parameters:
        `power` - transmission power to write
      Throws:
        `jssc.SerialPortException` - in case of read/write error

    - #### writeVersion

          public void writeVersion(java.lang.Byte version)
                            throws jssc.SerialPortException

      Writes given version to the device. Cache of this model is updated as well.
      Parameters:
        `version` - version to write
      Throws:
        `jssc.SerialPortException` - in case of read/write error

    - #### writeWords

          private void writeWords(java.lang.String input)
                           throws jssc.SerialPortException

      Separates the input String by comma (",") and sends the resulting words one by one with 2 ms gaps between them, ">" at the start and "\r" at the end. Used for configuration reading / writing.
      Parameters:
        `input` - words to send
      Throws:
        `jssc.SerialPortException` - in case of read/write error