541 lines
20 KiB
Python
541 lines
20 KiB
Python
import logging
|
||
from datetime import datetime, timezone
|
||
from typing import Optional, List
|
||
import struct
|
||
|
||
from schemas import NormalizedVitals
|
||
from config import settings
|
||
|
||
logger = logging.getLogger(__name__)
|
||
|
||
# Contec CMS7000PLUS / CMS8000 / CMS9200PLUS OBX identifiers mapping to schema fields
|
||
CONTEC_PARAM_MAP = {
|
||
# Heart Rate / Pulse Rate
|
||
"HR": "heart_rate",
|
||
"HEART_RATE": "heart_rate",
|
||
"ECG_HR": "heart_rate",
|
||
"PR": "heart_rate",
|
||
"PULSE_RATE": "heart_rate",
|
||
"SPO2_PR": "heart_rate",
|
||
"ECGHR": "heart_rate",
|
||
"ECG-HR": "heart_rate",
|
||
"PULSERATE": "heart_rate",
|
||
|
||
# SpO2
|
||
"SPO2": "spo2",
|
||
"SAO2": "spo2",
|
||
"SPO2_PCT": "spo2",
|
||
"OXYGEN_SAT": "spo2",
|
||
"SPO2_VAL": "spo2",
|
||
"O2SAT": "spo2",
|
||
|
||
# Blood Pressure (NIBP)
|
||
"NIBP_SYS": "systolic_bp",
|
||
"NIBP_DIA": "diastolic_bp",
|
||
"NIBP_MEAN": "map_bp",
|
||
"NIBP_MAP": "map_bp",
|
||
"SYS": "systolic_bp",
|
||
"DIA": "diastolic_bp",
|
||
"MAP": "map_bp",
|
||
"NBP_S": "systolic_bp",
|
||
"NBP_D": "diastolic_bp",
|
||
"NBP_M": "map_bp",
|
||
"NIBP-S": "systolic_bp",
|
||
"NIBP-D": "diastolic_bp",
|
||
"NIBP-M": "map_bp",
|
||
"BP_SYS": "systolic_bp",
|
||
"BP_DIA": "diastolic_bp",
|
||
"BP_MEAN": "map_bp",
|
||
|
||
# Respiratory Rate
|
||
"RESP": "respiratory_rate",
|
||
"RESP_RATE": "respiratory_rate",
|
||
"RR": "respiratory_rate",
|
||
"BR": "respiratory_rate",
|
||
"RESPRATE": "respiratory_rate",
|
||
"RESP-RATE": "respiratory_rate",
|
||
|
||
# Temperature
|
||
"TEMP": "temperature",
|
||
"TEMP1": "temperature",
|
||
"TEMP2": "temperature",
|
||
"T1": "temperature",
|
||
"T2": "temperature",
|
||
"BODY_TEMP": "temperature",
|
||
"TEMP-1": "temperature",
|
||
"TEMP-2": "temperature",
|
||
"BODYTEMP": "temperature",
|
||
}
|
||
|
||
# Sentinel value used by Contec to mark an invalid/disconnected parameter
|
||
INVALID_SENTINEL_U16 = 9999 # 0x270F
|
||
INVALID_SENTINEL_F32 = 9999.0
|
||
|
||
|
||
def safe_float(value: str) -> Optional[float]:
|
||
try:
|
||
return float(value)
|
||
except (ValueError, TypeError):
|
||
return None
|
||
|
||
|
||
def is_valid_u16(val: Optional[int]) -> bool:
|
||
return val is not None and val != INVALID_SENTINEL_U16 and val != 255 and val != 65535
|
||
|
||
|
||
def is_valid_f32(val: Optional[float]) -> bool:
|
||
return val is not None and abs(val - INVALID_SENTINEL_F32) > 1.0
|
||
|
||
|
||
def read_u16_le(buf: bytes, offset: int) -> Optional[int]:
|
||
if offset + 2 <= len(buf):
|
||
return struct.unpack_from('<H', buf, offset)[0]
|
||
return None
|
||
|
||
|
||
def read_f32_le(buf: bytes, offset: int) -> Optional[float]:
|
||
if offset + 4 <= len(buf):
|
||
return struct.unpack_from('<f', buf, offset)[0]
|
||
return None
|
||
|
||
|
||
def parse_contec_hl7_text(raw_text: str, client_ip: str) -> Optional[NormalizedVitals]:
|
||
"""
|
||
Lightweight, native parser for Contec HL7 messages.
|
||
Splits segments and fields manually, avoiding third-party library dependencies.
|
||
"""
|
||
try:
|
||
# Strip MLLP framing if present (VT=0x0b, FS=0x1c, CR=0x0d)
|
||
clean_text = raw_text.strip()
|
||
if clean_text.startswith("\x0b"):
|
||
clean_text = clean_text[1:]
|
||
if "\x1c\x0d" in clean_text:
|
||
clean_text = clean_text.split("\x1c\x0d")[0]
|
||
|
||
# Split into segments by CR or LF
|
||
segments = [seg.strip() for seg in clean_text.replace("\n", "\r").split("\r") if seg.strip()]
|
||
|
||
if not segments or not segments[0].startswith("MSH"):
|
||
return None
|
||
|
||
# Parse MSH segment
|
||
model = settings.device_models.get(client_ip, settings.monitor_model)
|
||
msh_fields = segments[0].split("|")
|
||
device_id = msh_fields[2] if len(msh_fields) > 2 and msh_fields[2] else f"{model}_{client_ip}"
|
||
|
||
patient_id = "UNKNOWN"
|
||
vitals_dict = {
|
||
"device_id": device_id,
|
||
"patient_id": patient_id,
|
||
"timestamp": datetime.now(timezone.utc),
|
||
"ip_address": client_ip,
|
||
}
|
||
|
||
found_any = False
|
||
|
||
# Parse PID, PV1 and OBX segments
|
||
for seg in segments[1:]:
|
||
fields = seg.split("|")
|
||
if not fields:
|
||
continue
|
||
|
||
seg_name = fields[0]
|
||
|
||
if seg_name == "PID":
|
||
# PID-3: MRN / Patient ID
|
||
if len(fields) > 3 and fields[3]:
|
||
patient_id = fields[3].split("^")[0].strip()
|
||
vitals_dict["patient_id"] = patient_id
|
||
|
||
# PID-5: Patient Name (format: FamilyName^GivenName^...)
|
||
if len(fields) > 5 and fields[5]:
|
||
name_parts = fields[5].split("^")
|
||
family = name_parts[0].strip() if len(name_parts) > 0 else ""
|
||
given = name_parts[1].strip() if len(name_parts) > 1 else ""
|
||
full_name = f"{given} {family}".strip() or family or given
|
||
if full_name:
|
||
vitals_dict["patient_name"] = full_name
|
||
|
||
# PID-7: Date of Birth (YYYYMMDD or YYYY-MM-DD)
|
||
if len(fields) > 7 and fields[7]:
|
||
vitals_dict["patient_dob"] = fields[7].strip()
|
||
|
||
# PID-8: Administrative Sex (M / F / U / O)
|
||
if len(fields) > 8 and fields[8]:
|
||
vitals_dict["patient_gender"] = fields[8].strip().upper()
|
||
|
||
elif seg_name == "PV1":
|
||
# PV1-3: Assigned Patient Location (Room^Bed^...)
|
||
if len(fields) > 3 and fields[3]:
|
||
location_parts = fields[3].split("^")
|
||
# Use second component (Bed) if present, else first (Room)
|
||
bed = location_parts[1].strip() if len(location_parts) > 1 else location_parts[0].strip()
|
||
if bed:
|
||
vitals_dict["bed_id"] = bed
|
||
|
||
elif seg_name == "OBX":
|
||
if len(fields) > 5:
|
||
obs_val = fields[5].strip()
|
||
|
||
if not obs_val or obs_val == "---":
|
||
continue
|
||
|
||
val_float = safe_float(obs_val)
|
||
if val_float is None:
|
||
continue
|
||
|
||
# Split OBX-3 (Observation Identifier) by '^' and check all parts for parameter matches
|
||
obs_parts = [p.strip().upper() for p in fields[3].split("^") if p.strip()]
|
||
|
||
matched = False
|
||
for param_key, mapped_field in CONTEC_PARAM_MAP.items():
|
||
for part in obs_parts:
|
||
if param_key == part or param_key in part:
|
||
vitals_dict[mapped_field] = val_float
|
||
found_any = True
|
||
logger.info(f"Parsed Contec HL7 Vital: {mapped_field} = {val_float} (from OBX-3: {fields[3]})")
|
||
matched = True
|
||
break
|
||
if matched:
|
||
break
|
||
|
||
return NormalizedVitals(**vitals_dict) if found_any else None
|
||
|
||
except Exception as e:
|
||
logger.error(f"Error parsing Contec HL7 text: {e}")
|
||
return None
|
||
|
||
|
||
def _extract_vitals_block(data: bytes, offset: int, client_ip: str) -> Optional[NormalizedVitals]:
|
||
"""
|
||
Extract vitals from a Contec vitals block starting at the given offset.
|
||
|
||
Known Contec CMS7000PLUS binary vitals block layout (confirmed from packet captures):
|
||
|
||
PACKET TYPE B (header bytes [xx][00][04][46] or [xx][yy][04][46]):
|
||
-----------------------------------------------------------------------
|
||
Bytes 8-11 : float32 LE → NIBP Systolic (9999.0 = invalid)
|
||
Bytes 12-15 : float32 LE → NIBP Diastolic (9999.0 = invalid)
|
||
Bytes 16-19 : float32 LE → NIBP MAP (9999.0 = invalid)
|
||
Bytes 20-23 : float32 LE → Temperature 1 (°C, 9999.0 = invalid)
|
||
Bytes 24-27 : float32 LE → Temperature 2 (°C, 9999.0 = invalid)
|
||
|
||
Vitals summary block (at data[offset] position, found by scanning for SpO2+HR pattern):
|
||
Offset +0 : uint16 LE → SpO2 (%) (9999 = invalid)
|
||
Offset +2 : uint16 LE → Heart Rate (bpm)(9999 = invalid, ECG not connected)
|
||
Offset +4 : uint16 LE → Pulse Rate (bpm)(from SpO2 probe, also 9999 if invalid)
|
||
Offset +6 : uint16 LE → (SpO2 alarm/threshold)
|
||
Offset +8 : uint16 LE → (mode flags)
|
||
Offset +10 : uint16 LE → NIBP Systolic (9999 = invalid)
|
||
Offset +12 : uint16 LE → NIBP Diastolic (9999 = invalid)
|
||
"""
|
||
model = settings.device_models.get(client_ip, settings.monitor_model)
|
||
vitals_dict = {
|
||
"device_id": f"{model}_{client_ip}",
|
||
"patient_id": "UNKNOWN",
|
||
"timestamp": datetime.now(timezone.utc),
|
||
"ip_address": client_ip,
|
||
}
|
||
found = False
|
||
|
||
spo2 = read_u16_le(data, offset)
|
||
hr_ecg = read_u16_le(data, offset + 2)
|
||
hr_spo2 = read_u16_le(data, offset + 4)
|
||
|
||
# SpO2 value: valid range 50–100
|
||
if spo2 is not None and 50 <= spo2 <= 100:
|
||
vitals_dict["spo2"] = float(spo2)
|
||
found = True
|
||
|
||
# Heart rate: ECG HR at offset+2 is primary; SpO2 PR at offset+4 is fallback.
|
||
if is_valid_u16(hr_ecg) and 20 <= hr_ecg <= 300:
|
||
vitals_dict["heart_rate"] = float(hr_ecg)
|
||
found = True
|
||
elif is_valid_u16(hr_spo2) and 20 <= hr_spo2 <= 300:
|
||
vitals_dict["heart_rate"] = float(hr_spo2)
|
||
found = True
|
||
|
||
return NormalizedVitals(**vitals_dict) if found else None
|
||
|
||
|
||
def _parse_45_byte_packet(data: bytes, vitals_dict: dict) -> bool:
|
||
"""
|
||
Parse 45/47-byte packet (Subtype 22) — contains NIBP values and alarm limits.
|
||
|
||
Verified layout:
|
||
[0-1] Packet length LE u16 = 45 or 47
|
||
[2-3] Marker: 01 46 or 00 46
|
||
[4-7] Sub-header (00 00 16 00)
|
||
[8-9] Year LE u16
|
||
[10] Month, [11] Day, [12] Hour, [13] Minute, [14] Seconds
|
||
[15-16] NIBP Systolic (LE u16, 32767 / 9999 = no measurement / idle)
|
||
[17-18] NIBP Diastolic (LE u16, 32767 / 9999 = no measurement / idle)
|
||
[19-20] NIBP MAP (LE u16, 32767 / 9999 = no measurement / idle)
|
||
"""
|
||
if len(data) < 21:
|
||
return False
|
||
|
||
if "present_fields" not in vitals_dict:
|
||
vitals_dict["present_fields"] = []
|
||
|
||
nibp_sys = read_u16_le(data, 15)
|
||
nibp_dia = read_u16_le(data, 17)
|
||
nibp_map = read_u16_le(data, 19)
|
||
|
||
sentinels = (9999, 32767, 65535, 0)
|
||
|
||
if nibp_sys is not None and nibp_sys not in sentinels and 40 <= nibp_sys <= 260:
|
||
vitals_dict["systolic_bp"] = float(nibp_sys)
|
||
if "systolic_bp" not in vitals_dict["present_fields"]:
|
||
vitals_dict["present_fields"].append("systolic_bp")
|
||
|
||
if nibp_dia is not None and nibp_dia not in sentinels and 20 <= nibp_dia <= 200:
|
||
vitals_dict["diastolic_bp"] = float(nibp_dia)
|
||
if "diastolic_bp" not in vitals_dict["present_fields"]:
|
||
vitals_dict["present_fields"].append("diastolic_bp")
|
||
|
||
if nibp_map is not None and nibp_map not in sentinels and 20 <= nibp_map <= 250:
|
||
vitals_dict["map_bp"] = float(nibp_map)
|
||
if "map_bp" not in vitals_dict["present_fields"]:
|
||
vitals_dict["present_fields"].append("map_bp")
|
||
|
||
return True
|
||
|
||
|
||
def _parse_56_byte_packet(data: bytes, vitals_dict: dict) -> bool:
|
||
"""
|
||
Parse 56-byte packet (Subtype 23) — contains float32 Temperature values.
|
||
|
||
Verified layout:
|
||
[8-11] Temperature 1 (float32)
|
||
[12-15] Temperature 2 (float32)
|
||
[20-23] Temp 1 Alarm High Limit (float32)
|
||
[24-27] Temp 1 Alarm Low Limit (float32)
|
||
"""
|
||
if len(data) < 16:
|
||
return False
|
||
|
||
if "present_fields" not in vitals_dict:
|
||
vitals_dict["present_fields"] = []
|
||
|
||
found = False
|
||
|
||
temp1 = read_f32_le(data, 8)
|
||
temp2 = read_f32_le(data, 12)
|
||
|
||
def is_real_temp(t):
|
||
# Disconnected sentinel is 9999.0 or 3276.7 (0x7FFF)
|
||
return t is not None and is_valid_f32(t) and abs(t - 3276.7) > 1.0 and 20.0 < t < 45.0
|
||
|
||
if is_real_temp(temp1):
|
||
vitals_dict["temperature"] = round(temp1, 1)
|
||
if "temperature" not in vitals_dict["present_fields"]:
|
||
vitals_dict["present_fields"].append("temperature")
|
||
found = True
|
||
elif is_real_temp(temp2):
|
||
vitals_dict["temperature"] = round(temp2, 1)
|
||
if "temperature" not in vitals_dict["present_fields"]:
|
||
vitals_dict["present_fields"].append("temperature")
|
||
found = True
|
||
elif temp1 is not None or temp2 is not None:
|
||
# Sensor disconnected / off
|
||
vitals_dict["temperature"] = None
|
||
if "temperature" not in vitals_dict["present_fields"]:
|
||
vitals_dict["present_fields"].append("temperature")
|
||
found = True
|
||
|
||
return found
|
||
|
||
|
||
def _parse_spo2_waveform_packet(data: bytes, vitals_dict: dict) -> bool:
|
||
"""
|
||
Parse SpO2 & Pleth waveform packet (Subtype 21 for CMS7000PLUS / CMS8500).
|
||
SpO2% is located at offset 264. Disconnected sentinel is 65535, 32767, or 255.
|
||
Offsets 270+ contain alarm limits (100, 90) and must NOT be parsed as vitals.
|
||
"""
|
||
if len(data) < 266:
|
||
return False
|
||
|
||
if "present_fields" not in vitals_dict:
|
||
vitals_dict["present_fields"] = []
|
||
|
||
# Extract Pleth waveform samples (bytes 8..263)
|
||
vitals_dict["pleth_wave"] = list(data[8:min(264, len(data))])
|
||
if "pleth_wave" not in vitals_dict["present_fields"]:
|
||
vitals_dict["present_fields"].append("pleth_wave")
|
||
|
||
found = False
|
||
|
||
# Check SpO2 at standard offset 264
|
||
spo2_val = read_u16_le(data, 264)
|
||
|
||
# If 264 is disconnected sentinel, probe is NOT connected / off-finger
|
||
if spo2_val in (None, 65535, 32767, 255, 9999, 0):
|
||
vitals_dict["spo2"] = None
|
||
vitals_dict["heart_rate"] = None
|
||
if "spo2" not in vitals_dict["present_fields"]:
|
||
vitals_dict["present_fields"].append("spo2")
|
||
if "heart_rate" not in vitals_dict["present_fields"]:
|
||
vitals_dict["present_fields"].append("heart_rate")
|
||
return True
|
||
|
||
if 50 <= spo2_val <= 100:
|
||
vitals_dict["spo2"] = float(spo2_val)
|
||
if "spo2" not in vitals_dict["present_fields"]:
|
||
vitals_dict["present_fields"].append("spo2")
|
||
found = True
|
||
|
||
# ECG HR is at offset 266 in the 286-byte SpO2 waveform packet footer.
|
||
# Offset 268 is the SpO2 HIGH ALARM LIMIT (always 100) — NOT pulse rate!
|
||
# So we read ECG HR at 266 only.
|
||
ecg_hr = read_u16_le(data, 266)
|
||
|
||
logger.info(
|
||
f"SpO2 pkt: SpO2[264]={spo2_val} ECG_HR[266]={ecg_hr} alarm_hi[268]={read_u16_le(data,268)} alarm_lo[270]={read_u16_le(data,270) if len(data)>=272 else 'N/A'}"
|
||
)
|
||
|
||
if ecg_hr is not None and ecg_hr not in (9999, 65535, 32767, 0) and 20 <= ecg_hr <= 300:
|
||
vitals_dict["heart_rate"] = float(ecg_hr)
|
||
if "heart_rate" not in vitals_dict["present_fields"]:
|
||
vitals_dict["present_fields"].append("heart_rate")
|
||
|
||
return found
|
||
|
||
|
||
def _parse_286_byte_packet(data: bytes, vitals_dict: dict) -> bool:
|
||
return _parse_spo2_waveform_packet(data, vitals_dict)
|
||
|
||
|
||
def _parse_288_byte_packet(data: bytes, vitals_dict: dict) -> bool:
|
||
return _parse_spo2_waveform_packet(data, vitals_dict)
|
||
|
||
|
||
def _parse_341_byte_packet(data: bytes, vitals_dict: dict) -> bool:
|
||
return _parse_spo2_waveform_packet(data, vitals_dict)
|
||
|
||
|
||
def _parse_989_byte_packet(data: bytes, vitals_dict: dict) -> bool:
|
||
"""
|
||
Parse 989-byte waveform packet (Subtype 20 / 14h).
|
||
|
||
Verified layout:
|
||
[8..903] ECG waveform samples (8-bit unsigned, 896 samples @ ~250Hz)
|
||
[904-905] ECG Heart Rate (LE u16)
|
||
65535 or 9999 = invalid/disconnected
|
||
"""
|
||
if len(data) < 906:
|
||
return False
|
||
|
||
if "present_fields" not in vitals_dict:
|
||
vitals_dict["present_fields"] = []
|
||
|
||
# Extract ECG waveform samples (bytes 8..903), downsample to ~224 points for smooth real-time rendering
|
||
raw_ecg = list(data[8:904])
|
||
vitals_dict["ecg_wave"] = raw_ecg[::4]
|
||
if "ecg_wave" not in vitals_dict["present_fields"]:
|
||
vitals_dict["present_fields"].append("ecg_wave")
|
||
|
||
hr_val = read_u16_le(data, 904)
|
||
if hr_val is not None and hr_val not in (65535, 9999, 0) and 20 <= hr_val <= 300:
|
||
# Only use ECG HR if SpO2-probe PR has NOT already set heart_rate.
|
||
# SpO2 PR (from the pleth packet) matches the monitor display and wins.
|
||
if "heart_rate" not in vitals_dict.get("present_fields", []):
|
||
vitals_dict["heart_rate"] = float(hr_val)
|
||
vitals_dict.setdefault("present_fields", []).append("heart_rate")
|
||
|
||
return True
|
||
|
||
|
||
def _find_vitals_block_in_stream(data: bytes, client_ip: str) -> Optional[NormalizedVitals]:
|
||
"""
|
||
Scan the data stream for Contec CMS7000PLUS / CMS8500 sub-packets and parse them.
|
||
"""
|
||
model = settings.device_models.get(client_ip, settings.monitor_model)
|
||
vitals_dict = {
|
||
"device_id": f"{model}_{client_ip}",
|
||
"patient_id": "UNKNOWN",
|
||
"timestamp": datetime.now(timezone.utc),
|
||
"ip_address": client_ip,
|
||
}
|
||
found_any = False
|
||
|
||
i = 0
|
||
while i < len(data) - 8:
|
||
if (data[i + 2] == 0x04 or data[i + 2] == 0x01 or data[i + 2] == 0x00) and data[i + 3] == 0x46:
|
||
pkt_len = struct.unpack_from('<H', data, i)[0]
|
||
|
||
if 30 < pkt_len < 1050 and i + pkt_len <= len(data):
|
||
pkt_data = data[i:i + pkt_len]
|
||
|
||
if pkt_len in (45, 47):
|
||
if _parse_45_byte_packet(pkt_data, vitals_dict):
|
||
found_any = True
|
||
elif pkt_len == 56:
|
||
if _parse_56_byte_packet(pkt_data, vitals_dict):
|
||
found_any = True
|
||
elif pkt_len in (286, 288, 341):
|
||
if _parse_spo2_waveform_packet(pkt_data, vitals_dict):
|
||
found_any = True
|
||
elif pkt_len == 989:
|
||
if _parse_989_byte_packet(pkt_data, vitals_dict):
|
||
found_any = True
|
||
elif 100 < pkt_len < 600:
|
||
if _parse_spo2_waveform_packet(pkt_data, vitals_dict):
|
||
found_any = True
|
||
|
||
i += max(pkt_len, 4)
|
||
else:
|
||
i += 1
|
||
|
||
return NormalizedVitals(**vitals_dict) if found_any else None
|
||
|
||
|
||
def parse_contec_binary_packet(data: bytes, client_ip: str) -> Optional[NormalizedVitals]:
|
||
"""
|
||
Decodes the Contec CMS7000PLUS proprietary binary protocol.
|
||
|
||
The monitor sends two alternating TCP packets:
|
||
- Packet A (991 bytes): ECG waveform + SpO2 waveform + vitals footer
|
||
- Packet B (397 bytes): Resp waveform + vitals summary + param block
|
||
|
||
Both have the structure: [len_lo][len_hi][04][46][subtype][00][sublen][00]...[payload]...
|
||
"""
|
||
try:
|
||
return _find_vitals_block_in_stream(data, client_ip)
|
||
except Exception as e:
|
||
logger.error(f"Error parsing Contec binary packet: {e}")
|
||
return None
|
||
|
||
|
||
def parse_contec_data(raw_data: bytes, client_ip: str) -> Optional[NormalizedVitals]:
|
||
"""
|
||
Unified entry point for parsing data from a Contec CMS7000PLUS monitor.
|
||
Attempts HL7 text parsing first, falling back to proprietary binary parsing.
|
||
"""
|
||
if not raw_data:
|
||
return None
|
||
|
||
# Attempt 1: HL7 Text Decoding
|
||
try:
|
||
text = raw_data.decode("utf-8", errors="ignore").strip()
|
||
if "MSH" in text or "\x0bMSH" in text:
|
||
vitals = parse_contec_hl7_text(text, client_ip)
|
||
if vitals:
|
||
return vitals
|
||
else:
|
||
logger.warning(f"HL7 message detected but failed to parse. Content: {repr(text)}")
|
||
except Exception as e:
|
||
logger.warning(f"Failed decoding/parsing HL7: {e}")
|
||
|
||
# Attempt 2: Binary Parsing (Contec proprietary protocol)
|
||
vitals = parse_contec_binary_packet(raw_data, client_ip)
|
||
if vitals:
|
||
return vitals
|
||
|
||
# Logging fallback
|
||
logger.warning(
|
||
f"Data packet from {client_ip} unrecognized. "
|
||
f"Len: {len(raw_data)}, Hex head: {raw_data[:32].hex()}"
|
||
)
|
||
return None
|