Skip to content

Commit

Permalink
Merge pull request #66 from gskjold/dev-v1.2.3
Browse files Browse the repository at this point in the history
Dev v1.2.3
  • Loading branch information
gskjold authored Apr 19, 2020
2 parents 3984073 + cc72d0e commit 719ed56
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 81 deletions.
82 changes: 60 additions & 22 deletions lib/HanReader/src/HanReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,14 @@ time_t HanReader::getTime(int objectId) {
return getTime(objectId, buffer, 0, bytesRead);
}

int HanReader::getInt(int objectId) {
int32_t HanReader::getInt(int objectId) {
return getInt(objectId, buffer, 0, bytesRead);
}

uint32_t HanReader::getUint(int objectId) {
return getUint32(objectId, buffer, 0, bytesRead);
}

String HanReader::getString(int objectId) {
return getString(objectId, buffer, 0, bytesRead);
}
Expand Down Expand Up @@ -192,36 +196,70 @@ int HanReader::getInt(int dataPosition, byte *buffer, int start, int length) {
int valuePosition = findValuePosition(dataPosition, buffer, start, length);

if (valuePosition > 0) {
int value = 0;
int bytes = 0;
switch (buffer[valuePosition++]) {
case 0x01:
case 0x02:
case 0x16:
return getUint8(dataPosition, buffer, start, length);
case 0x0F:
return getInt8(dataPosition, buffer, start, length);
case 0x12:
return getUint16(dataPosition, buffer, start, length);
case 0x10:
bytes = 2;
break;
case 0x12:
bytes = 2;
break;
return getInt16(dataPosition, buffer, start, length);
case 0x06:
bytes = 4;
break;
case 0x02:
bytes = 1;
break;
return getUint32(dataPosition, buffer, start, length);
}
}
return 0;
}

int8_t HanReader::getInt8(int dataPosition, byte *buffer, int start, int length) {
int valuePosition = findValuePosition(dataPosition, buffer, start, length);
if (valuePosition > 0 && buffer[valuePosition++] == 0x0F) {
return buffer[valuePosition];
}
return 0;
}

int16_t HanReader::getInt16(int dataPosition, byte *buffer, int start, int length) {
int valuePosition = findValuePosition(dataPosition, buffer, start, length);
if (valuePosition > 0 && buffer[valuePosition++] == 0x10) {
return buffer[valuePosition] << 8 | buffer[valuePosition+1];
}
return 0;
}

uint8_t HanReader::getUint8(int dataPosition, byte *buffer, int start, int length) {
int valuePosition = findValuePosition(dataPosition, buffer, start, length);
if (valuePosition > 0) {
switch(buffer[valuePosition++]) {
case 0x01:
bytes = 1;
break;
case 0x0F:
bytes = 1;
break;
case 0x02:
case 0x16:
bytes = 1;
break;
return buffer[valuePosition];
}
}
return 0;
}

for (int i = valuePosition; i < valuePosition + bytes; i++) {
uint16_t HanReader::getUint16(int dataPosition, byte *buffer, int start, int length) {
int valuePosition = findValuePosition(dataPosition, buffer, start, length);
if (valuePosition > 0 && buffer[valuePosition++] == 0x12) {
return buffer[valuePosition] << 8 | buffer[valuePosition+1];
}
return 0;
}

uint32_t HanReader::getUint32(int dataPosition, byte *buffer, int start, int length) {
int valuePosition = findValuePosition(dataPosition, buffer, start, length);
if (valuePosition > 0) {
if(buffer[valuePosition++] != 0x06)
return 0;
uint32_t value = 0;
for (int i = valuePosition; i < valuePosition + 4; i++) {
value = value << 8 | buffer[i];
}

return value;
}
return 0;
Expand Down
8 changes: 7 additions & 1 deletion lib/HanReader/src/HanReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class HanReader
bool read(byte data);
int getListSize();
time_t getPackageTime();
int getInt(int objectId);
int32_t getInt(int objectId); // Use this for uint8, int8, uint16, int16
uint32_t getUint(int objectId); // Only for uint32
String getString(int objectId);
time_t getTime(int objectId);

Expand All @@ -43,6 +44,11 @@ class HanReader
time_t getTime(int dataPosition, byte *buffer, int start, int length);
time_t getTime(byte *buffer, int start, int length);
int getInt(int dataPosition, byte *buffer, int start, int length);
int8_t getInt8(int dataPosition, byte *buffer, int start, int length);
uint8_t getUint8(int dataPosition, byte *buffer, int start, int length);
int16_t getInt16(int dataPosition, byte *buffer, int start, int length);
uint16_t getUint16(int dataPosition, byte *buffer, int start, int length);
uint32_t getUint32(int dataPosition, byte *buffer, int start, int length);
String getString(int dataPosition, byte *buffer, int start, int length);

time_t toUnixTime(int year, int month, int day, int hour, int minute, int second);
Expand Down
Loading

0 comments on commit 719ed56

Please sign in to comment.