Skip to content

Commit

Permalink
Updated btcnt calc in bitsore class and disallow buffer move if no da…
Browse files Browse the repository at this point in the history
…ta will be left after move #62
  • Loading branch information
sidey79 committed Oct 17, 2017
1 parent 87b0372 commit 2958b4a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/_micro-api/libraries/bitstore/src/bitstore.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "Arduino.h"



template<uint8_t bufSize>
class BitStore
{
Expand Down Expand Up @@ -114,6 +115,7 @@ bool BitStore<bufSize>::addValue(byte value)
{
byte crcval = value;


if (bcnt == 7 && valcount > 0)
{
if (bytecount >= buffsize - 1) {
Expand Down Expand Up @@ -215,7 +217,7 @@ const uint16_t BitStore<bufSize>::getSize()
template<uint8_t bufSize>
bool BitStore<bufSize>::moveLeft(const uint16_t begin)
{
if (begin == 0 || begin > valcount) return false;
if (begin == 0 || begin >= valcount) return false;

uint8_t startbyte = begin*valuelen / 8;
byte crcval = this->getValue(begin);
Expand Down Expand Up @@ -258,10 +260,9 @@ bool BitStore<bufSize>::moveLeft(const uint16_t begin)
datastore[z] = datastore[i] << shift_left;

valcount = valcount - (8 / valuelen*startbyte);
if ((valcount*valuelen) % 8 == 0)
bcnt = 7;
else
bcnt = 7 - shift_left;
uint8_t val_bcnt = (valcount*valuelen) % 8;
if (val_bcnt > 0)
bcnt = 7 - val_bcnt;

bytecount = (valcount - 1)*valuelen / 8;
//bcnt = 7-shift_left;
Expand All @@ -287,6 +288,7 @@ bool BitStore<bufSize>::moveLeft(const uint16_t begin)


}

Serial.print(" after moveLeft "); Serial.print(" vc: "); Serial.print(valcount, DEC);
Serial.print(" bytec: "); Serial.print(bytecount, DEC);
Serial.print(" bitpos: "); Serial.print(bcnt, DEC);
Expand Down

0 comments on commit 2958b4a

Please sign in to comment.