Skip to content

Commit 53030a8

Browse files
committed
fix: decompression and MN
1 parent 9084234 commit 53030a8

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

signalduino/parser/base.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from ..exceptions import SignalduinoParserError
99

10-
_STX_ETX = re.compile(r"^\x02(M[s|u|o];.*;)\x03$")
10+
_STX_ETX = re.compile(r"^\x02(M[sSuUcCNOo];.*;)\x03$")
1111

1212

1313
def decompress_payload(compressed_payload: str) -> str:
@@ -16,7 +16,23 @@ def decompress_payload(compressed_payload: str) -> str:
1616
1717
The Perl logic is in 00_SIGNALduino.pm around line 1784.
1818
"""
19-
if not compressed_payload.upper().startswith(("MS;", "MU;", "MO;")):
19+
# Check if the message is actually compressed (contains high-bit chars)
20+
# The Perl logic runs a decompression loop on any MS/MU/MO, but the compression
21+
# logic only works if high-bit chars are present, otherwise it mangles standard fields.
22+
# We will only run decompression if we detect at least one high-bit character (ord > 127)
23+
# in any part that is not the header (first 3 chars).
24+
if not compressed_payload.upper().startswith(("MS;", "MU;", "MO;", "MN;")):
25+
return compressed_payload
26+
27+
# Check for compression marker (a character with high-bit set)
28+
is_compressed = False
29+
if len(compressed_payload) > 3:
30+
for char in compressed_payload[3:]:
31+
if ord(char) > 127:
32+
is_compressed = True
33+
break
34+
35+
if not is_compressed:
2036
return compressed_payload
2137

2238
# Split message parts by ';'

0 commit comments

Comments
 (0)