| 73 | } |
| 74 | |
| 75 | void CanSignalDecoderPrivate::decodeFrame(const QCanBusFrame& frame, Direction const direction, bool) |
| 76 | { |
| 77 | bool littleEndian; |
| 78 | |
| 79 | const CANmessages_t::value_type* msgDesc = nullptr; |
| 80 | if (_db.getDb().count(frame.frameId()) > 0) { |
| 81 | auto iter = _db.getDb().find(frame.frameId()); |
| 82 | |
| 83 | if (iter != _db.getDb().end()) { |
| 84 | msgDesc = &(*iter); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | if (msgDesc) { |
| 89 | for (auto& sig : msgDesc->second) { |
| 90 | |
| 91 | switch (sig.byteOrder) { |
| 92 | case 0: |
| 93 | // Big endian |
| 94 | littleEndian = false; |
| 95 | break; |
| 96 | case 1: |
| 97 | // Little endian |
| 98 | littleEndian = true; |
| 99 | break; |
| 100 | |
| 101 | default: |
| 102 | cds_error("byte order {} not suppoerted", sig.byteOrder); |
| 103 | continue; |
| 104 | } |
| 105 | |
| 106 | // Calculate how many bits are used already before this signal. Calculations are different for |
| 107 | // little and big endian. Good overview on how big endian signals are aligned can be found |
| 108 | // here: https://github.com/eerimoq/cantools#the-dump-subcommand |
| 109 | uint8_t bitsBefore = 0; |
| 110 | |
| 111 | if (littleEndian) { |
| 112 | bitsBefore = sig.startBit; |
| 113 | } else { |
| 114 | bitsBefore = beTransTable[sig.startBit]; |
| 115 | } |
| 116 | |
| 117 | if (bitsBefore + sig.signalSize > (frame.payload().size() * 8)) { |
| 118 | cds_error( |
| 119 | "Invalid message size - startBit {}, sigSize {}, bitsBefore {}, payload size {}, littleEndian: {}", |
| 120 | sig.startBit, sig.signalSize, bitsBefore, frame.payload().size(), littleEndian); |
| 121 | continue; |
| 122 | } |
| 123 | |
| 124 | int64_t value = rawToSignal((const uint8_t*)frame.payload().constData(), sig.startBit, sig.signalSize, |
| 125 | littleEndian, sig.valueSigned); |
| 126 | |
| 127 | QVariant sigVal; |
| 128 | |
| 129 | if ((std::fmod(sig.factor, 1) == 0.0) && (std::fmod(sig.offset, 1) == 0.0)) { |
| 130 | // resulting number will be integer |
| 131 | value = value * sig.factor + sig.offset; |
| 132 | sigVal.setValue(value); |