allow less than 8 bits for non-numeric types as well, corrected TTQ/TTH decoding

This commit is contained in:
john30
2017-03-19 14:26:49 +01:00
parent 3f974e9b47
commit b88922fb40
3 changed files with 15 additions and 4 deletions
+10 -4
View File
@@ -515,12 +515,18 @@ size_t SingleDataField::getLength(PartType partType, size_t maxLength) {
}
bool SingleDataField::hasFullByteOffset(bool after) {
if (m_length > 1 || !m_dataType->isNumeric()) {
if (m_length > 1) {
return true;
}
NumberDataType* num = reinterpret_cast<NumberDataType*>(m_dataType);
return (num->getBitCount() % 8) == 0
|| (after && num->getFirstBit() + (num->getBitCount() % 8) >= 8);
int16_t firstBit;
if (m_dataType->isNumeric()) {
NumberDataType* num = reinterpret_cast<NumberDataType*>(m_dataType);
firstBit = num->getFirstBit();
} else {
firstBit = 0;
}
return (m_dataType->getBitCount() % 8) == 0
|| (after && firstBit + (m_dataType->getBitCount() % 8) >= 8);
}
+3
View File
@@ -349,6 +349,9 @@ result_t DateTimeDataType::readSymbols(SymbolString& input,
output << setw(2) << dec << setfill('0') << static_cast<unsigned>(hour);
symbol = (symbol_t)(minutes % 60);
} else if (length == 1) { // truncated time
if (m_bitCount < 8) {
symbol = (symbol_t)((1 << m_bitCount) - 1);
}
if (i == 0) {
symbol = (symbol_t)(symbol/(60/m_resolution)); // convert to hours
index -= incr; // repeat for minutes
+2
View File
@@ -187,6 +187,8 @@ int main() {
{"x,,ttq", "-:-", "10fe07000100", "00", ""},
{"x,,ttq", "", "10fe07000161", "00", "rw"},
{"x,,ttq,2", "", "", "", "c"},
{"x,,ttq,,,,y,,bi7", "23:45;0", "10fe0700015f", "00", ""}, // bit combination
{"x,,ttq,,,,y,,bi7", "23:45;1", "10fe070001df", "00", ""}, // bit combination
{"x,,bdy", "Mon", "10fe07000100", "00", ""},
{"x,,bdy", "Sun", "10fe07000106", "00", ""},
{"x,,bdy", "8", "10fe07000108", "00", "w"},