Type12 message base class
| 279 | |
| 280 | |
| 281 | class EtherCatType12DLPDU(Packet): |
| 282 | """ |
| 283 | Type12 message base class |
| 284 | """ |
| 285 | def post_build(self, pkt, pay): |
| 286 | """ |
| 287 | |
| 288 | set next attr automatically if not set explicitly by user |
| 289 | |
| 290 | :param pkt: raw string containing the current layer |
| 291 | :param pay: raw string containing the payload |
| 292 | :return: <new current layer> + payload |
| 293 | """ |
| 294 | |
| 295 | data_len = len(self.data) |
| 296 | if data_len > 2047: |
| 297 | raise ValueError('payload size {} exceeds maximum length {} ' |
| 298 | 'of data size.'.format(data_len, 2047)) |
| 299 | |
| 300 | if self.next is not None: |
| 301 | has_next = True if self.next else False |
| 302 | else: |
| 303 | if pay: |
| 304 | has_next = True |
| 305 | else: |
| 306 | has_next = False |
| 307 | |
| 308 | if has_next: |
| 309 | next_flag = bytearray([pkt[7] | 0b10000000]) |
| 310 | else: |
| 311 | next_flag = bytearray([pkt[7] & 0b01111111]) |
| 312 | |
| 313 | return pkt[:7] + next_flag + pkt[8:] + pay |
| 314 | |
| 315 | def guess_payload_class(self, payload): |
| 316 | |
| 317 | try: |
| 318 | dlpdu_type = payload[0] |
| 319 | return EtherCat.ETHERCAT_TYPE12_DLPDU_TYPES[dlpdu_type] |
| 320 | |
| 321 | except KeyError: |
| 322 | log_runtime.error( |
| 323 | '{}.guess_payload_class() - unknown or invalid ' |
| 324 | 'DLPDU type'.format(self.__class__.__name__)) |
| 325 | return Packet.guess_payload_class(self, payload) |
| 326 | |
| 327 | # structure templates lacking leading cmd-attribute |
| 328 | PHYSICAL_ADDRESSING_DESC = [ |
| 329 | ByteField('idx', 0), |
| 330 | LEShortField('adp', 0), |
| 331 | LEShortField('ado', 0), |
| 332 | LEBitFieldLenField('len', None, 11, count_of='data'), |
| 333 | LEBitField('_reserved', 0, 3), |
| 334 | LEBitEnumField('c', 0, 1, ETHERCAT_TYPE_12_CIRCULATING_FRAME), |
| 335 | LEBitEnumField('next', None, 1, ETHERCAT_TYPE_12_NEXT_FRAME), |
| 336 | LEShortField('irq', 0), |
| 337 | FieldListField('data', [], ByteField('', 0x00), |
| 338 | count_from=lambda pkt: pkt.len), |
nothing calls this directly
no test coverage detected