
package uk.co.wingpath.modbus;

/**
* Instances of this class are used within the Modbus package to represent
* Modbus "model" addresses.
* <p>A {@code ModelAddress} is an immutable object containing an
* {@code address} field and a {@code shift field}.
* The {@code address} field contains the address supplied by the user as
* a register address.
* The {@code shift} field is used to refer to an individual bit within the
* register, and specifies the right shift needed to extract the bit.
* The {@code shift} field is set to 0 when the whole register is being
* referenced.
* <p>The methods {@link AddressMap.Map#toModel AddressMap.Map.toModel} and
* {@link AddressMap.Map#fromModel AddressMap.Map.fromModel} convert between
* model addresses and the addresses used in Modbus messages.
*/
class ModelAddress
{
    private final int address;
    private final int shift;

    /**
    * Constructs a {@code ModelAddress} using the specified address and shift.
    * @param address the internal register address.
    * @param shift the bit position within the register.
    */
    public ModelAddress (int address, int shift)
    {
        this.address = address;
        this.shift = shift;
    }

    /**
    * Returns the address component.
    * @return the address.
    */
    public int getAddress ()
    {
        return address;
    }

    /**
    * Returns the shift component.
    * @return the shift.
    */
    public int getShift ()
    {
        return shift;
    }
}


