BOSWatch 3
Python Script to receive and decode German BOS Information with rtl_fm and multimon-NG
 
Loading...
Searching...
No Matches
boswatch.decoder.pocsagDecoder.PocsagDecoder Class Reference

POCSAG decoder class. More...

Static Public Member Functions

def decode (data)
 Decodes POCSAG.
 

Static Protected Member Functions

def _getBitrateRicSubric (data)
 

Detailed Description

POCSAG decoder class.

This class decodes POCSAG data.
First step is to validate the data and _check if the format is correct.
In the last step a valid BOSWatch packet is created and returned

Member Function Documentation

◆ decode()

def boswatch.decoder.pocsagDecoder.PocsagDecoder.decode (   data)
static

Decodes POCSAG.

    @param data: POCSAG for decoding
    @return BOSWatch POCSAG packet or None
34 def decode(data):
35 r"""!Decodes POCSAG
36
37 @param data: POCSAG for decoding
38 @return BOSWatch POCSAG packet or None"""
39 bitrate, ric, subric = PocsagDecoder._getBitrateRicSubric(data)
40
41 # If no valid SubRIC (Function 0–3) detected → abort
42 if subric is None:
43 logging.warning("Invalid POCSAG function (not 0–3)")
44 return None
45
46 if ric and len(ric) == 7:
47 if "Alpha:" in data:
48 message = data.split('Alpha:')[1].strip()
49 message = re.sub(r'<\s*(?:NUL|EOT)\s*>?', '', message).strip()
50 else:
51 message = ""
52 subricText = subric.replace("1", "a").replace("2", "b").replace("3", "c").replace("4", "d")
53
54 logging.debug("found valid POCSAG")
55
56 bwPacket = Packet()
57 bwPacket.set("mode", "pocsag")
58 bwPacket.set("bitrate", bitrate)
59 bwPacket.set("ric", ric)
60 bwPacket.set("subric", subric)
61 bwPacket.set("subricText", subricText)
62 bwPacket.set("message", message)
63
64 return bwPacket
65
66 logging.warning("no valid POCSAG")
67 return None
68

◆ _getBitrateRicSubric()

def boswatch.decoder.pocsagDecoder.PocsagDecoder._getBitrateRicSubric (   data)
staticprotected
Gets the Bitrate, Ric and Subric from data using robust regex parsing.
70 def _getBitrateRicSubric(data):
71 """Gets the Bitrate, Ric and Subric from data using robust regex parsing."""
72 bitrate = "0"
73 ric = None
74 subric = None
75
76 # determine bitrate
77 if "POCSAG512:" in data:
78 bitrate = "512"
79 elif "POCSAG1200:" in data:
80 bitrate = "1200"
81 elif "POCSAG2400:" in data:
82 bitrate = "2400"
83
84 # extract RIC (address)
85 m_ric = re.search(r'Address:\s*(\d{1,7})(?=\s|$)', data)
86 if m_ric:
87 ric = m_ric.group(1).zfill(7)
88
89 # extract SubRIC (function)
90 m_sub = re.search(r'Function:\s*([0-3])', data)
91 if m_sub:
92 subric = str(int(m_sub.group(1)) + 1)
93
94 return bitrate, ric, subric