nic
2011-05-12 09:57:29 +02:00
parent fd5a1c5b4b
commit e759a14909
2 changed files with 12 additions and 14 deletions
@@ -86,10 +86,8 @@ public class SensorUtils {
for (int i = 0; i < 8; i++) {
if ((crc & 0x1) != 0x0) {
// we have to do the OxFF mask because the right shift is
// supposed to shift in a 0
// as crc gets implicitly casted to a
// signed int by >> it may be filled with 1s
// Using a 0xFF bit assures that 0-bits are introduced during the shift operation.
// Otherwise, implicit casts to signed int could shift in 1-bits if the signed bit is 1.
crc = (byte) (((crc & 0xFF) >> 1) ^ 0x8C);
} else {
crc = (byte) ((crc & 0xFF) >> 1);
@@ -27,9 +27,9 @@ import com.google.android.apps.mytracks.content.Sensor;
*/
public class ZephyrMessageParser implements MessageParser {
public static final int ZEPHYR_HXM_BYTE_STX = 0;
public static final int ZEPHYR_HXM_BYTE_CRC = 58;
public static final int ZEPHYR_HXM_BYTE_ETX = 59;
public static final int ZEPHYR_HXM_BYTE_STX = 0;
public static final int ZEPHYR_HXM_BYTE_CRC = 58;
public static final int ZEPHYR_HXM_BYTE_ETX = 59;
@Override
public Sensor.SensorDataSet parseBuffer(byte[] buffer) {
@@ -63,13 +63,13 @@ public class ZephyrMessageParser implements MessageParser {
@Override
public boolean isValid(byte[] buffer) {
if (buffer.length > ZEPHYR_HXM_BYTE_ETX) {
// Check STX (Start of Text), ETX (End of Text) and CRC Checksum
return buffer[ZEPHYR_HXM_BYTE_STX] == 0x02
&& buffer[ZEPHYR_HXM_BYTE_ETX] == 0x03
&& SensorUtils.getCrc8(buffer, 3, 55) == buffer[ZEPHYR_HXM_BYTE_CRC];
} else
return false;
if (buffer.length > ZEPHYR_HXM_BYTE_ETX) {
// Check STX (Start of Text), ETX (End of Text) and CRC Checksum
return buffer[ZEPHYR_HXM_BYTE_STX] == 0x02
&& buffer[ZEPHYR_HXM_BYTE_ETX] == 0x03
&& SensorUtils.getCrc8(buffer, 3, 55) == buffer[ZEPHYR_HXM_BYTE_CRC];
} else
return false;
}
@Override