forked from upstream-mirrors/OpenTracks
-comments from http://code.google.com/r/nic-sensors/source/detail?r=7fd41979e22a99d8173fe91df25124e85c1766e9
This commit is contained in:
@@ -86,10 +86,8 @@ public class SensorUtils {
|
|||||||
|
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
if ((crc & 0x1) != 0x0) {
|
if ((crc & 0x1) != 0x0) {
|
||||||
// we have to do the OxFF mask because the right shift is
|
// Using a 0xFF bit assures that 0-bits are introduced during the shift operation.
|
||||||
// supposed to shift in a 0
|
// Otherwise, implicit casts to signed int could shift in 1-bits if the signed bit is 1.
|
||||||
// as crc gets implicitly casted to a
|
|
||||||
// signed int by >> it may be filled with 1s
|
|
||||||
crc = (byte) (((crc & 0xFF) >> 1) ^ 0x8C);
|
crc = (byte) (((crc & 0xFF) >> 1) ^ 0x8C);
|
||||||
} else {
|
} else {
|
||||||
crc = (byte) ((crc & 0xFF) >> 1);
|
crc = (byte) ((crc & 0xFF) >> 1);
|
||||||
|
|||||||
+10
-10
@@ -27,9 +27,9 @@ import com.google.android.apps.mytracks.content.Sensor;
|
|||||||
*/
|
*/
|
||||||
public class ZephyrMessageParser implements MessageParser {
|
public class ZephyrMessageParser implements MessageParser {
|
||||||
|
|
||||||
public static final int ZEPHYR_HXM_BYTE_STX = 0;
|
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_CRC = 58;
|
||||||
public static final int ZEPHYR_HXM_BYTE_ETX = 59;
|
public static final int ZEPHYR_HXM_BYTE_ETX = 59;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Sensor.SensorDataSet parseBuffer(byte[] buffer) {
|
public Sensor.SensorDataSet parseBuffer(byte[] buffer) {
|
||||||
@@ -63,13 +63,13 @@ public class ZephyrMessageParser implements MessageParser {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValid(byte[] buffer) {
|
public boolean isValid(byte[] buffer) {
|
||||||
if (buffer.length > ZEPHYR_HXM_BYTE_ETX) {
|
if (buffer.length > ZEPHYR_HXM_BYTE_ETX) {
|
||||||
// Check STX (Start of Text), ETX (End of Text) and CRC Checksum
|
// Check STX (Start of Text), ETX (End of Text) and CRC Checksum
|
||||||
return buffer[ZEPHYR_HXM_BYTE_STX] == 0x02
|
return buffer[ZEPHYR_HXM_BYTE_STX] == 0x02
|
||||||
&& buffer[ZEPHYR_HXM_BYTE_ETX] == 0x03
|
&& buffer[ZEPHYR_HXM_BYTE_ETX] == 0x03
|
||||||
&& SensorUtils.getCrc8(buffer, 3, 55) == buffer[ZEPHYR_HXM_BYTE_CRC];
|
&& SensorUtils.getCrc8(buffer, 3, 55) == buffer[ZEPHYR_HXM_BYTE_CRC];
|
||||||
} else
|
} else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user