PIByteArray checksumPlain invert flag

fix PISerial setBreak
This commit is contained in:
Andrey
2021-09-16 16:18:20 +03:00
parent ece3fb1536
commit 19a8ca84e6
3 changed files with 21 additions and 11 deletions

View File

@@ -221,22 +221,22 @@ PIByteArray & PIByteArray::decompressRLE(uchar threshold) {
}
uchar PIByteArray::checksumPlain8() const {
uchar PIByteArray::checksumPlain8(bool inverse) const {
uchar c = 0;
int sz = size_s();
for (int i = 0; i < sz; ++i)
c += at(i);
c = ~(c + 1);
if (inverse) c = ~(c + 1);
return c;
}
uint PIByteArray::checksumPlain32() const {
uint PIByteArray::checksumPlain32(bool inverse) const {
uint c = 0;
int sz = size_s();
for (int i = 0; i < sz; ++i)
c += at(i) * (i + 1);
c = ~(c + 1);
if (inverse) c = ~(c + 1);
return c;
}