From 0b14e5dda44e28ca04d3a21c87b574fe305c541b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sun, 4 Mar 2018 00:50:15 +0100 Subject: [PATCH] fix 1wire bugginess with addressing --- utils/payload_parser.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/utils/payload_parser.c b/utils/payload_parser.c index 274bd20..a6e4f5d 100644 --- a/utils/payload_parser.c +++ b/utils/payload_parser.c @@ -1,3 +1,4 @@ +#include #include "payload_parser.h" #define pp_check_capacity(pp, needed) \ @@ -58,32 +59,21 @@ uint32_t pp_u32(PayloadParser *pp) uint64_t pp_u64(PayloadParser *pp) { - pp_check_capacity(pp, 4); + pp_check_capacity(pp, 8); if (!pp->ok) return 0; - uint64_t x = 0; + uint32_t x0, x1; + uint64_t x; if (pp->bigendian) { - x |= (uint64_t) ((uint64_t) *pp->current++ << 56); - x |= (uint64_t) ((uint64_t) *pp->current++ << 48); - x |= (uint64_t) ((uint64_t) *pp->current++ << 40); - x |= (uint64_t) ((uint64_t) *pp->current++ << 32); - - x |= (uint64_t) (*pp->current++ << 24); - x |= (uint64_t) (*pp->current++ << 16); - x |= (uint64_t) (*pp->current++ << 8); - x |= *pp->current++; + x1 = pp_u32(pp); + x0 = pp_u32(pp); } else { - x |= *pp->current++; - x |= (uint64_t) (*pp->current++ << 8); - x |= (uint64_t) (*pp->current++ << 16); - x |= (uint64_t) (*pp->current++ << 24); - - x |= (uint64_t) ((uint64_t) *pp->current++ << 32); - x |= (uint64_t) ((uint64_t) *pp->current++ << 40); - x |= (uint64_t) ((uint64_t) *pp->current++ << 48); - x |= (uint64_t) ((uint64_t) *pp->current++ << 56); + x0 = pp_u32(pp); + x1 = pp_u32(pp); } + x = ((uint64_t)x1)<<32 | x0; + return x; }