Skip to content

Commit

Permalink
mask value after decoding shouldn't be required; it broke signed valu…
Browse files Browse the repository at this point in the history
…es too -> removed it
  • Loading branch information
sebi2k1 committed Oct 3, 2015
1 parent acb3b8a commit 72efb95
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
9 changes: 2 additions & 7 deletions socketcan.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,23 +257,18 @@ DatabaseService.prototype.onMessage = function (msg) {
// Let the C-Portition extract and convert the signal
for (i in m.signals) {
var s = m.signals[i];

if (s.value === undefined)
continue;

// if this is a mux signal and the muxor isnt in my list...
if (m.muxed && s.muxGroup && s.muxGroup.indexOf(b1mux) == -1) {
continue;
}

var mask = 0;
for (var j = 0; j < s.bitLength; j++) {
mask |= (1 << j);
}

var val = _signals.decode_signal(msg.data, s.bitOffset, s.bitLength,
s.endianess == 'little', s.type == 'signed');

val &= mask;

if (s.slope)
val *= s.slope;

Expand Down
24 changes: 12 additions & 12 deletions src/signals.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ static u_int64_t _getvalue(u_int8_t * data,
{
size_t bitsCopied = bitsLeft >= 8 ? 8 : bitsLeft;
if ( initial_pass && bitsLeft != intraByteOffset )
bitsCopied -= intraByteOffset;
bitsCopied -= intraByteOffset;

size_t shift = 56 - (8 * thisByte);
if( initial_pass )
shift += intraByteOffset;
shift += intraByteOffset;

uint64_t byteMask = ((1 << bitsCopied) - 1); // 0x1111

Expand Down Expand Up @@ -127,9 +127,9 @@ NAN_METHOD(DecodeSignal)
// Value shall be interpreted as signed (2's complement)
if (isSigned && val & (1 << (bitLength - 1))) {
int32_t tmp = -1 * (~((UINT64_MAX << bitLength) | val) + 1);
retval = Nan::New(tmp);
retval = Nan::New(tmp);
} else {
retval = Nan::New((u_int32_t)val);
retval = Nan::New((u_int32_t)val);
}

info.GetReturnValue().Set(retval);
Expand Down Expand Up @@ -160,16 +160,16 @@ void _setvalue(u_int32_t offset, u_int32_t bitLength, ENDIANESS endianess, u_int
// while there are bits to process
for ( ; bitsLeft > 0; )
{
// process 8 at a time
// what about starting at offset and moving 8 bits
// ? it would be 4 and 4
// bitsMoved =
// process 8 at a time
// what about starting at offset and moving 8 bits
// ? it would be 4 and 4
// bitsMoved =
size_t bitsMoved = bitsLeft < 8 ? bitsLeft : 8;
if ( initial_pass && bitsLeft != intraByteOffset)
bitsMoved -= intraByteOffset;
bitsMoved -= intraByteOffset;
size_t shift = 56 - ( 8 * thisByte );
if( initial_pass )
shift += intraByteOffset ;
if (initial_pass)
shift += intraByteOffset;

uint64_t byteMask = ((1 << bitsMoved) - 1);

Expand Down Expand Up @@ -240,7 +240,7 @@ NAN_METHOD(EncodeSignal)
}
}

raw_value = info[5]->ToNumber()->Uint32Value();
raw_value = info[5]->ToNumber()->Uint32Value();

size_t maxBytes = std::min<u_int32_t>(Buffer::Length(jsData), sizeof(data));

Expand Down

0 comments on commit 72efb95

Please sign in to comment.