This class is used for distinction of CAN FD packets.
| 173 | |
| 174 | |
| 175 | class CANFD(CAN): |
| 176 | """ |
| 177 | This class is used for distinction of CAN FD packets. |
| 178 | """ |
| 179 | fields_desc = [ |
| 180 | FlagsField('flags', 0, 3, ['error', |
| 181 | 'remote_transmission_request', |
| 182 | 'extended']), |
| 183 | XBitField('identifier', 0, 29), |
| 184 | FieldLenField('length', None, length_of='data', fmt='B'), |
| 185 | FlagsField('fd_flags', 4, 8, ['bit_rate_switch', |
| 186 | 'error_state_indicator', |
| 187 | 'fd_frame']), |
| 188 | ShortField('reserved', 0), |
| 189 | StrLenField('data', b'', length_from=lambda pkt: int(pkt.length)), |
| 190 | ] |
| 191 | |
| 192 | def post_build(self, pkt, pay): |
| 193 | # type: (bytes, bytes) -> bytes |
| 194 | |
| 195 | data = super(CANFD, self).post_build(pkt, pay) |
| 196 | |
| 197 | length = data[4] |
| 198 | |
| 199 | if 8 < length <= 24: |
| 200 | wire_length = length + (-length) % 4 |
| 201 | elif 24 < length <= 64: |
| 202 | wire_length = length + (-length) % 8 |
| 203 | elif length > 64: |
| 204 | raise NotImplementedError |
| 205 | else: |
| 206 | wire_length = length |
| 207 | |
| 208 | pad = b"\x00" * (wire_length - length) |
| 209 | |
| 210 | return data[0:4] + chb(wire_length) + data[5:] + pad |
| 211 | |
| 212 | |
| 213 | bind_layers(CookedLinux, CANFD, proto=13) |
no test coverage detected