Skip to content

Bugfix/revert syn escape #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions src/main/java/de/csdev/ebus/command/EBusCommandUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private EBusCommandUtils() {
}

/**
*
*
* @param data
* @return
* @throws EBusDataException
Expand Down Expand Up @@ -204,19 +204,12 @@ public static byte unescapeSymbol(byte reversedByte) {

// add the escaped bytes
for (byte b : masterData) {
// disable escaping the special characters as vaillant and wolf
// generates AA and A9 bytes!
// buf.put(escapeSymbol(b))
buf.put(b);
buf.put(escapeSymbol(b));
}

// calculate crc
byte crc8 = EBusUtils.crc8(buf.array(), buf.position());

// disable escaping the special characters as vaillant and wolf
// generates AA and A9 bytes!
// buf.put(escapeSymbol(b))
buf.put(crc8);
buf.put(escapeSymbol(crc8));

// set limit and reset position
buf.limit(buf.position());
Expand Down
62 changes: 62 additions & 0 deletions src/test/java/de/csdev/ebus/wip/SynEscapeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package de.csdev.ebus.wip;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.junit.Test;
import de.csdev.ebus.command.EBusCommandUtils;
import de.csdev.ebus.core.EBusDataException;
import de.csdev.ebus.utils.EBusUtils;

public class SynEscapeTest {

public void QuickCheck(byte source, byte target, String command, String masterData, String assertEscaped,
String assertUnescaped) throws EBusDataException {

byte[] masterTelegram = EBusUtils.toByteArray(EBusCommandUtils.buildPartMasterTelegram(
source, target,
EBusUtils.toByteArray(command),
EBusUtils.toByteArray(masterData)));

StringBuilder escaped = EBusUtils.toHexDumpString(masterTelegram);
assertEquals(assertEscaped, escaped.toString());

byte[] v = EBusCommandUtils.checkRawTelegram(masterTelegram);
StringBuilder unescaped = EBusUtils.toHexDumpString(v);
assertEquals(assertUnescaped, unescaped.toString());
}

@Test
public void SynByteInCrc() {
try {
QuickCheck((byte) 0x00, (byte) 0x00, "B5 13", "04 15 00",
"00 00 B5 13 03 04 15 00 A9 01",
"00 00 B5 13 03 04 15 00 AA");

} catch (NumberFormatException | EBusDataException e) {
fail(e.getMessage());
}
}

@Test
public void SynByteInMasterData() {
try {

QuickCheck((byte) 0xFF, (byte) 0x08, "00 00", "AA 26 02",
"FF 08 00 00 03 A9 01 26 02 78",
"FF 08 00 00 03 AA 26 02 78");

QuickCheck((byte) 0x01, (byte) 0xFE, "20 20", "62 73 AA 00",
"01 FE 20 20 04 62 73 A9 01 00 78",
"01 FE 20 20 04 62 73 AA 00 78");


QuickCheck((byte) 0x00, (byte) 0x00, "B5 13", "04 15 00",
"00 00 B5 13 03 04 15 00 A9 01",
"00 00 B5 13 03 04 15 00 AA");

} catch (NumberFormatException | EBusDataException e) {
fail(e.getMessage());
}
}

}
Loading