Skip to content

Commit

Permalink
Initial values for SPNs and unknown fields will have all their bits s…
Browse files Browse the repository at this point in the history
…et to 1 as in certain cases an initial value of 0 is valid.
  • Loading branch information
famez committed Sep 16, 2018
1 parent 33a2d83 commit e41f50a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion J1939/J1939Frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void J1939Frame::encode(u32& identifier, u8* buffer, size_t& length) const {

identifier |= (prio << J1939_PRIORITY_OFFSET);

memset(buffer, 0 , length);
memset(buffer, 0xFF, length);

encodeData(buffer, length);

Expand Down
2 changes: 1 addition & 1 deletion J1939/SPN/SPNNumeric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace J1939 {

SPNNumeric::SPNNumeric(u32 number, const std::string& name, size_t offset, double formatGain, double formatOffset, u8 byteSize, const std::string& units) :
SPN(number, name, offset),
mFormatGain(formatGain), mFormatOffset(formatOffset), mByteSize(byteSize), mUnits(units), mValue(0) {
mFormatGain(formatGain), mFormatOffset(formatOffset), mByteSize(byteSize), mUnits(units), mValue(0xFFFFFFFF) {

ASSERT(byteSize > 0)
ASSERT(byteSize <= SPN_NUMERIC_MAX_BYTE_SYZE)
Expand Down
5 changes: 4 additions & 1 deletion J1939/SPN/SPNStatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@

namespace J1939 {

SPNStatus::SPNStatus(u32 number, const std::string& name, size_t offset, u8 bitOffset, u8 bitSize) : SPN(number, name, offset), mBitOffset(bitOffset), mBitSize(bitSize), mValue(0) {
SPNStatus::SPNStatus(u32 number, const std::string& name, size_t offset, u8 bitOffset, u8 bitSize) : SPN(number, name, offset), mBitOffset(bitOffset), mBitSize(bitSize) {

ASSERT(mBitSize > 0)
ASSERT(mBitOffset + mBitSize <= 8)

mValue = (0xFF >> (8 - mBitSize)); //Always initialized to invalid value

}

SPNStatus::~SPNStatus() {
Expand Down

0 comments on commit e41f50a

Please sign in to comment.