1#!/usr/bin/env python3
2
3class CCSDSException(BaseException):
4 """Bad class for CCSDS packet related exceptions."""
5 pass
6
7
8class CCSDSUnrecognisedPacket(CCSDSException):
9 """We tried to decode a packet with no PacketDef file."""
10 pass
11
12
13class CCSDSBadHeader(CCSDSException):
14 """Cannot head a header value."""
15 def __init__(self, name, actual_length, required_length):
16 self.name = name
17 self.actual_length = actual_length
18 self.required_length = required_length
19
20 def __str__(self):
21 return ('Cannot read header field {name} from packet of length {act} need '
22 '{req} bytes'.format(name=self.name,
23 act=self.actual_length,
24 req=self.required_length))
25
26
27class CCSDSParameterOutsidePacket(CCSDSException):
28 """An attempt was made to read a parameter after the maximum packet length.
29
30 Remember the last 2 bytes are the PEC."""
31 def __init__(self, field_info, byte_pos, bit_pos, ccsds_container, spid=None):
32 assert not isinstance(ccsds_container, int)
33 self.field_info = field_info
34 self.byte_pos = byte_pos
35 self.bit_pos = bit_pos
36 self.ccsds_container = ccsds_container
37
38 if spid == None:
39 # try getting from packet_def
40 if ccsds_container.packet_def is not None:
41 self.spid = ccsds_container.packet_def.spid
42
43 else:
44 self.spid = spid
45
46
47 def __str__(self):
48 return ('Cannot read PUS parameter {field} from {bb}.{b} in CCSDS packet length {l} '
49 'SPID {spid}').format(
50 field=self.field_info.name,
51 bb=self.byte_pos,
52 b=self.bit_pos,
53 l=len(self.ccsds_container.ccsds.buff),
54 spid=self.spid)