BOSWatch 3
Python Script to receive and decode German BOS Information with rtl_fm and multimon-NG
 
Loading...
Searching...
No Matches
boswatch.wildcard Namespace Reference

Functions

def registerWildcard (wildcard, bwPacketField)
 Register a new additional wildcard.
 
def replaceWildcards (message, bwPacket)
 Replace the wildcards in a given message.
 

Variables

dict _additionalWildcards = {}
 

Detailed Description


/ __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ / / __ / / / /__ | | /| / / __ `/ __/ ___/ __ \ /_ < / /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ / /_____/____//____/ |__/|__/__,_/__/___/_/ /_/ /____/ German BOS Information Script by Bastian Schroll

Function Documentation

◆ registerWildcard()

def boswatch.wildcard.registerWildcard (   wildcard,
  bwPacketField 
)

Register a new additional wildcard.

@param wildcard: New wildcard string with format: '{WILDCARD}'
@param bwPacketField: Field of the bwPacket which is used for wildcard replacement
25def registerWildcard(wildcard, bwPacketField):
26 r"""!Register a new additional wildcard
27
28 @param wildcard: New wildcard string with format: '{WILDCARD}'
29 @param bwPacketField: Field of the bwPacket which is used for wildcard replacement"""
30 if wildcard in _additionalWildcards:
31 logging.error("wildcard always registered: %s", wildcard)
32 return
33 logging.debug("register new wildcard %s for field: %s", wildcard, bwPacketField)
34 _additionalWildcards[wildcard] = bwPacketField
35
36

◆ replaceWildcards()

def boswatch.wildcard.replaceWildcards (   message,
  bwPacket 
)

Replace the wildcards in a given message.

@param message: Message in which wildcards should be replaced
@param bwPacket: bwPacket instance with the replacement information
@return Input message with the replaced wildcards
37def replaceWildcards(message, bwPacket):
38 r"""!Replace the wildcards in a given message
39
40 @param message: Message in which wildcards should be replaced
41 @param bwPacket: bwPacket instance with the replacement information
42 @return Input message with the replaced wildcards"""
43
44 # Start with wildcards that are always available
45 _wildcards = {
46 # formatting wildcards
47 # todo check if br and par are needed - if not also change config
48 "{BR}": "\r\n",
49 "{LPAR}": "(",
50 "{RPAR}": ")",
51 "{TIME}": time.strftime("%d.%m.%Y %H:%M:%S"),
52
53 # info wildcards
54 # server
55 "{SNAME}": bwPacket.get("serverName"),
56 "{SVERS}": bwPacket.get("serverVersion"),
57 "{SDATE}": bwPacket.get("serverBuildDate"),
58 "{SBRCH}": bwPacket.get("serverBranch"),
59
60 # client
61 "{CNAME}": bwPacket.get("clientName"),
62 "{CIP}": bwPacket.get("clientIP"),
63 "{CVERS}": bwPacket.get("clientVersion"),
64 "{CDATE}": bwPacket.get("clientBuildDate"),
65 "{CBRCH}": bwPacket.get("clientBranch"),
66
67 # boswatch wildcards
68 "{INSRC}": bwPacket.get("inputSource"),
69 "{TIMES}": bwPacket.get("timestamp"),
70 "{FREQ}": bwPacket.get("frequency"),
71 "{MODE}": bwPacket.get("mode"),
72 }
73
74 # Get the packet mode to add specific wildcards
75 mode = bwPacket.get("mode")
76
77 # fms wildcards
78 if mode == "fms":
79 fms_wildcards = {
80 "{FMS}": bwPacket.get("fms"),
81 "{SERV}": bwPacket.get("service"),
82 "{COUNT}": bwPacket.get("country"),
83 "{LOC}": bwPacket.get("location"),
84 "{VEHC}": bwPacket.get("vehicle"),
85 "{STAT}": bwPacket.get("status"),
86 "{DIR}": bwPacket.get("direction"),
87 "{DIRT}": bwPacket.get("directionText"),
88 "{TACI}": bwPacket.get("tacticalInfo"),
89 }
90 _wildcards.update(fms_wildcards)
91
92 # pocsag wildcards
93 elif mode == "pocsag":
94 pocsag_wildcards = {
95 "{BIT}": bwPacket.get("bitrate"),
96 "{RIC}": bwPacket.get("ric"),
97 "{SRIC}": bwPacket.get("subric"),
98 "{SRICT}": bwPacket.get("subricText"),
99 "{MSG}": bwPacket.get("message"),
100 }
101 _wildcards.update(pocsag_wildcards)
102
103 # zvei wildcards
104 elif mode == "zvei":
105 zvei_wildcards = {
106 "{TONE}": bwPacket.get("tone"),
107 }
108 _wildcards.update(zvei_wildcards)
109
110 # msg wildcards
111 elif mode == "msg":
112 msg_wildcards = {
113 "{MSG}": bwPacket.get("message"),
114 }
115 _wildcards.update(msg_wildcards)
116
117 # Now, replace all collected wildcards
118 for wildcard, field in _wildcards.items():
119 # Only replace if the field was found in the packet (is not None)
120 if field is not None:
121 message = message.replace(wildcard, field)
122
123 # Handle additional, dynamically registered wildcards
124 for wildcard, fieldName in _additionalWildcards.items():
125 field = bwPacket.get(fieldName)
126 if field is not None:
127 message = message.replace(wildcard, field)
128
129 return message

Variable Documentation

◆ _additionalWildcards

dict boswatch.wildcard._additionalWildcards = {}
protected