Skip to content

Commit

Permalink
Fixed and cleanup datatypes classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian S. committed May 25, 2019
1 parent 79d4eb9 commit 73d3223
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public T decode(byte[] data) throws EBusTypeException {
if (data == null) {
throw new EBusTypeException("Input parameter byte-array is NULL!");
}

if (data.length != getTypeLength()) {
throw new EBusTypeException("Input parameter byte-array has size {0}, expected {1} for eBUS type {2}",
data.length, getTypeLength(), this.getClass().getSimpleName());
Expand Down Expand Up @@ -125,7 +125,7 @@ public T decodeInt(byte[] data) throws EBusTypeException {
@Override
public byte[] encode(Object data) throws EBusTypeException {

// return the replacec value
// return the replace value
if (data == null) {
return applyByteOrder(getReplaceValue());
}
Expand Down Expand Up @@ -235,13 +235,13 @@ public int getTypeLength() {
protected void setInstanceProperty(EBusAbstractType<T> instance, String property, Object value) {

if (property.equals("replaceValue")) {
if(value instanceof String) {
if (value instanceof String) {
try {
instance.setReplaceValue(EBusUtils.toByteArray((String)value));
instance.setReplaceValue(EBusUtils.toByteArray((String) value));
} catch (EBusTypeException e) {
logger.error("error!", e);
}
}
}

return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ public byte[] encodeInt(Object data) throws EBusTypeException {
calendar = (Calendar) data;
}

if (calendar == null) {
return applyByteOrder(getReplaceValue());
}

// set date to midnight
calendar = (Calendar) calendar.clone();
calendar.set(Calendar.HOUR_OF_DAY, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@ public EBusDateTime decodeInt(byte[] data) throws EBusTypeException {
EBusDateTime date = (EBusDateTime) dateType.decode(dateData);

if (time == null || date == null) {
logger.warn("DateTime Debug: data", EBusUtils.toHexDumpString(data));
logger.warn("DateTime Debug: variantTime", variantTime);
logger.warn("DateTime Debug: variantDate", variantDate);
logger.warn("DateTime Debug: data {}", EBusUtils.toHexDumpString(data));
logger.warn("DateTime Debug: variantTime {}", variantTime);
logger.warn("DateTime Debug: variantDate {}", variantDate);

throw new EBusTypeException("The decoded datetime part of datetime is null!");
logger.warn("The decoded date and/or time part of datetime is null!");
return null;
}

Calendar calendar = date.getCalendar();
Expand Down Expand Up @@ -108,6 +109,10 @@ public byte[] encodeInt(Object data) throws EBusTypeException {
calendar = (Calendar) data;
}

if (calendar == null) {
return applyByteOrder(getReplaceValue());
}

byte[] timeData = timeType.encode(calendar);
byte[] dateData = dateType.encode(calendar);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public BigDecimal decodeInt(byte[] data) throws EBusTypeException {
for (int i = 0; i <= x; i++) {

System.arraycopy(data, i * 2, dataNew, 0, dataNew.length);
// dataNew = applyByteOrder(dataNew);

BigDecimal value = types.decode(EBusTypeWord.TYPE_WORD, dataNew);

BigDecimal factor = this.multiplier.pow(i);
Expand Down Expand Up @@ -81,34 +81,14 @@ public byte[] encodeInt(Object data) throws EBusTypeException {
BigDecimal[] divideAndRemainder = value.divideAndRemainder(factor);

byte[] encode = types.encode(EBusTypeWord.TYPE_WORD, divideAndRemainder[0]);
// encode = applyByteOrder(encode);

value = divideAndRemainder[1];
System.arraycopy(encode, 0, result, i * 2, 2);
}

return result;
}

// @Override
// public IEBusType<BigDecimal> getInstance(Map<String, Object> properties) {
//
// if (properties.containsKey(IEBusType.LENGTH)) {
// EBusTypeMultiWord type = new EBusTypeMultiWord();
// type.types = this.types;
//
// type.length = (Integer) properties.get(IEBusType.LENGTH);
//
// if (properties.containsKey(BLOCK_MULTIPLIER)) {
// type.multiplier = NumberUtils.toBigDecimal(properties.get(BLOCK_MULTIPLIER));
// // type.factor = (Integer) properties.get(IEBusType.FACTOR);
// }
//
// return type;
// }
//
// return this;
// }

@Override
public String toString() {
return "EBusTypeMultiWord [length=" + length + ", multiplier=" + multiplier + ", replaceValue="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,6 @@ public int getTypeLength() {
return length;
}

// @Override
// public IEBusType<String> getInstance(Map<String, Object> properties) {
//
// if (properties.containsKey("length")) {
// EBusTypeString type = new EBusTypeString();
// type.types = this.types;
// type.length = (Integer) properties.get("length");
// return type;
// }
//
// return this;
// }

@Override
public String toString() {
return "EBusTypeString [length=" + length + "]";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ public byte[] encodeInt(Object data) throws EBusTypeException {
calendar = (Calendar) data;
}

if (calendar == null) {
return applyByteOrder(getReplaceValue());
}

// set date to 01.01.1970
calendar = (Calendar) calendar.clone();
calendar.set(1970, 0, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ public class EBusTypeVersion extends EBusAbstractType<BigDecimal> {

private static String[] supportedTypes = new String[] { TYPE_VERSION };

// public EBusTypeVersion() {
// replaceValue = new byte[] { (byte) 0xFF, (byte) 0xFF };
// }

@Override
public String[] getSupportedTypes() {
return supportedTypes;
Expand All @@ -42,10 +38,6 @@ public int getTypeLength() {
@Override
public BigDecimal decodeInt(byte[] data) throws EBusTypeException {

// if (data[0] == 0 && data[1] == 0) {
// return null;
// }

byte[] verData = new byte[] { data[0] };
byte[] revData = new byte[] { data[1] };

Expand All @@ -66,7 +58,7 @@ public byte[] encodeInt(Object data) throws EBusTypeException {
BigDecimal value = NumberUtils.toBigDecimal(data);

if (value == null) {
return new byte[getTypeLength()];
return applyByteOrder(getReplaceValue());
}

BigDecimal[] values = value.divideAndRemainder(BigDecimal.ONE);
Expand Down

0 comments on commit 73d3223

Please sign in to comment.