mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 09:33:06 +02:00
-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++) {
|
||||
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);
|
||||
|
||||
+10
-10
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user