Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.

Commit

Permalink
Formatted with openHAB formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
GideonLeGrange committed Nov 17, 2015
1 parent 0ff9ad7 commit ee8f6df
Show file tree
Hide file tree
Showing 11 changed files with 297 additions and 318 deletions.
Expand Up @@ -11,25 +11,33 @@
import org.openhab.core.binding.BindingConfig;

/**
* This is the item binding config structure. It connects an item name with the
* panStamp specific setup details.
* This is the item binding config structure. It connects an item name with the panStamp specific setup details.
*
* @author Gideon le Grange
* @since 1.8.0
*/
public class PanStampBindingConfig<T> implements BindingConfig {

/** Create a new instance.

/**
* Create a new instance.
*
* @param itemName Item name
* @param address panStamp device address.
* @param manufacturerId panStamp manufacturer ID as configured.
* @param productId panStamp product ID as configured.
* @param register panStamp register defining item.
* @param endpoint panStamp endpoint defining item.
* @param unit Unit for endpoint ("" means default)
* @param itemName
* Item name
* @param address
* panStamp device address.
* @param manufacturerId
* panStamp manufacturer ID as configured.
* @param productId
* panStamp product ID as configured.
* @param register
* panStamp register defining item.
* @param endpoint
* panStamp endpoint defining item.
* @param unit
* Unit for endpoint ("" means default)
*/
public PanStampBindingConfig(String itemName, int address, int manufacturerId, int productId, int register, String endpoint, String unit) {
public PanStampBindingConfig(String itemName, int address, int manufacturerId, int productId, int register,
String endpoint, String unit) {
this.itemName = itemName;
this.manufacturerId = manufacturerId;
this.productId = productId;
Expand All @@ -38,75 +46,82 @@ public PanStampBindingConfig(String itemName, int address, int manufacturerId, i
this.endpoint = endpoint;
this.unit = unit;
}
/**

/**
* Get the item name associated with this item configuration
*
* @return The item name
*/
public String getItemName() {
return itemName;
}

/**
* Get the manufacturer ID configured for this item configuration
/**
* Get the manufacturer ID configured for this item configuration
*
* @return
*/
public int getManufacturerId() {
return manufacturerId;
}

/**
* Get the product ID configured for this item configuration
/**
* Get the product ID configured for this item configuration
*
* @return
*/
public int getProductId() {
return productId;
}

/**
* Get the device address configured for this item configuration
/**
* Get the device address configured for this item configuration
*
* @return
*/
*/
public int getAddress() {
return address;
}

/**
* Get the register ID for this item configuration
/**
* Get the register ID for this item configuration
*
* @return
*/
*/
public int getRegister() {
return register;
}

/**
* Get the end point name for this item configuration
/**
* Get the end point name for this item configuration
*
* @return
*/
*/
public String getEndpoint() {
return endpoint;
}

/**
* Get the unit for this item configuration

/**
* Get the unit for this item configuration
*
* @return
*/
*/
public String getUnit() {
return unit;
}

@Override
public String toString() {
return String.format("%s => (%d,%d,%s):%d/%d", itemName, address, register, endpoint, manufacturerId, productId);
public String toString() {
return String
.format("%s => (%d,%d,%s):%d/%d", itemName, address, register, endpoint, manufacturerId, productId);
}

private final String itemName;
private final int manufacturerId;
private final int productId;
private final int address;
private final int register;
private final String endpoint;
private final String unit;

}
Expand Up @@ -16,11 +16,13 @@
*/
public interface PanStampBindingProvider extends BindingProvider {

/**
/**
* Return the configuration for the named item
* @param itemName The item name for which to lookup the configuration.
*
* @param itemName
* The item name for which to lookup the configuration.
* @return The configuration
*/
public PanStampBindingConfig<?> getConfig(String itemName);

}
Expand Up @@ -17,24 +17,28 @@
import me.legrange.panstamp.Register;

/**
* This panStamp device store implementation is a simple product code lookup.
* This panStamp device store implementation is a simple product code lookup.
*
* @author Gideon le Grange
* @since 1.8.0
*/
class ConfigDeviceStore implements DeviceStateStore {

private static final Logger logger = LoggerFactory.getLogger(ConfigDeviceStore.class);
private final Map<Integer, byte[]> map = new HashMap<Integer, byte[]>();

ConfigDeviceStore() {
}
/**

/**
* Add the product code for a device.
* @param address Device address.
* @param manId Manufacturer ID for device.
* @param prodId Product ID for device.
*
* @param address
* Device address.
* @param manId
* Manufacturer ID for device.
* @param prodId
* Product ID for device.
*/
void addProductCode(int address, int manId, int prodId) {
byte val[] = new byte[8];
Expand All @@ -49,8 +53,8 @@ void addProductCode(int address, int manId, int prodId) {
if (map.containsKey(address)) {
byte oldVal[] = map.get(address);
if (Arrays.equals(oldVal, val)) {
logger.warn("Product code for device {} re-assigned from {}/{} to {}/{}.", address,
bytesToInt(oldVal, 0, 4), bytesToInt(oldVal,4,4), manId, prodId);
logger.warn("Product code for device {} re-assigned from {}/{} to {}/{}.", address,
bytesToInt(oldVal, 0, 4), bytesToInt(oldVal, 4, 4), manId, prodId);
}
}
map.put(address, val);
Expand All @@ -62,7 +66,7 @@ public byte[] getRegisterValue(Register reg) {
}

@Override
public boolean hasRegisterValue(Register reg) {
public boolean hasRegisterValue(Register reg) {
return (reg.getId() == 0) && map.get(reg.getDevice().getAddress()) != null;
}

Expand All @@ -72,14 +76,14 @@ public void setRegisterValue(Register reg, byte[] val) {
map.put(reg.getDevice().getAddress(), val);
}
}

private int bytesToInt(byte bytes[], int idx, int len) {
int val = 0;
for(int i = 0; i < len; ++len) {
for (int i = 0; i < len; ++len) {
val = val << 8;
val = val | bytes[idx+i];
val = val | bytes[idx + i];
}
return val;
}

}

0 comments on commit ee8f6df

Please sign in to comment.