bit setter correction

This commit is contained in:
Robin Müller 2020-06-30 00:48:48 +02:00
parent 85cc936d5d
commit 3a85001855
2 changed files with 6 additions and 11 deletions

View File

@ -42,7 +42,7 @@ ReturnValue_t LocalDataSet::serializeWithValidityBuffer(uint8_t **buffer,
if(registeredVariables[count]->isValid()) { if(registeredVariables[count]->isValid()) {
// set validity buffer here. // set validity buffer here.
this->bitSetter(validityMask + validBufferIndex, this->bitSetter(validityMask + validBufferIndex,
validBufferIndexBit, true); validBufferIndexBit);
if(validBufferIndexBit == 7) { if(validBufferIndexBit == 7) {
validBufferIndex ++; validBufferIndex ++;
validBufferIndexBit = 0; validBufferIndexBit = 0;
@ -83,13 +83,12 @@ ReturnValue_t LocalDataSet::serializeLocalPoolIds(uint8_t** buffer,
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
void LocalDataSet::bitSetter(uint8_t* byte, uint8_t position, void LocalDataSet::bitSetter(uint8_t* byte, uint8_t position) const {
bool value) const {
if(position > 7) { if(position > 7) {
sif::debug << "Pool Raw Access: Bit setting invalid position" << std::endl; sif::debug << "Pool Raw Access: Bit setting invalid position" << std::endl;
return; return;
} }
uint8_t shiftNumber = position + (7 - 2 * position); uint8_t shiftNumber = position + (7 - 2 * position);
*byte |= 1UL << shiftNumber; *byte |= 1 << shiftNumber;
} }

View File

@ -98,14 +98,10 @@ private:
LocalDataPoolManager* hkManager; LocalDataPoolManager* hkManager;
/** /**
* Sets the bit at the bit-position of a byte provided by its address * Set n-th bit of a byte, with n being the position from 0
* to the specified value (zero or one). * (most significant bit) to 7 (least significant bit)
* @param byte Pointer to byte to bitset.
* @param position MSB first, 0 to 7 possible.
* @param value Value to set.
* @return
*/ */
void bitSetter(uint8_t* byte, uint8_t position, bool value) const; void bitSetter(uint8_t* byte, uint8_t position) const;
}; };
#endif /* FRAMEWORK_DATAPOOLLOCAL_LOCALDATASET_H_ */ #endif /* FRAMEWORK_DATAPOOLLOCAL_LOCALDATASET_H_ */