11#!/usr/bin/python
22# -*- coding: utf-8 -*-
33r"""!
4- ____ ____ ______ __ __ __ _____
5- / __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
4+ ____ ____ ______ __ __ __ _____
5+ / __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
66 / __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
77 / /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ /
88/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/
9- German BOS Information Script
10- by Bastian Schroll
9+ German BOS Information Script
10+ by Bastian Schroll
1111
12- @file: wildcard.py
13- @date: 15.01.2018
14- @author: Bastian Schroll
12+ @file: wildcard.py
13+ @date: 23.07.2025
14+ @author: Bastian Schroll
1515@description: Functions to replace wildcards in stings
1616"""
1717import logging
1818import time
1919
2020logging .debug ("- %s loaded" , __name__ )
2121
22- # todo check function - write an test
23-
2422_additionalWildcards = {}
2523
2624
@@ -42,6 +40,8 @@ def replaceWildcards(message, bwPacket):
4240 @param message: Message in which wildcards should be replaced
4341 @param bwPacket: bwPacket instance with the replacement information
4442 @return Input message with the replaced wildcards"""
43+
44+ # Start with wildcards that are always available
4545 _wildcards = {
4646 # formatting wildcards
4747 # todo check if br and par are needed - if not also change config
@@ -69,34 +69,59 @@ def replaceWildcards(message, bwPacket):
6969 "{TIMES}" : bwPacket .get ("timestamp" ),
7070 "{FREQ}" : bwPacket .get ("frequency" ),
7171 "{MODE}" : bwPacket .get ("mode" ),
72-
73- # fms wildcards
74- "{FMS}" : bwPacket .get ("fms" ),
75- "{SERV}" : bwPacket .get ("service" ),
76- "{COUNT}" : bwPacket .get ("country" ),
77- "{LOC}" : bwPacket .get ("location" ),
78- "{VEHC}" : bwPacket .get ("vehicle" ),
79- "{STAT}" : bwPacket .get ("status" ),
80- "{DIR}" : bwPacket .get ("direction" ),
81- "{DIRT}" : bwPacket .get ("directionText" ),
82- "{TACI}" : bwPacket .get ("tacticalInfo" ),
83-
84- # pocsag wildcards
85- "{BIT}" : bwPacket .get ("bitrate" ),
86- "{RIC}" : bwPacket .get ("ric" ),
87- "{SRIC}" : bwPacket .get ("subric" ),
88- "{SRICT}" : bwPacket .get ("subricText" ),
89- "{MSG}" : bwPacket .get ("message" ),
90-
91- # zvei wildcards
92- "{TONE}" : bwPacket .get ("tone" ),
93-
94- # message for MSG packet is done in poc
9572 }
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+
118+ # Now, replace all collected wildcards
96119 for wildcard , field in _wildcards .items ():
120+ # Only replace if the field was found in the packet (is not None)
97121 if field is not None :
98122 message = message .replace (wildcard , field )
99123
124+ # Handle additional, dynamically registered wildcards
100125 for wildcard , fieldName in _additionalWildcards .items ():
101126 field = bwPacket .get (fieldName )
102127 if field is not None :
0 commit comments