Organizes 11 projects for Cerbo GX/Venus OS into a single repository: - axiom-nmea: Raymarine LightHouse protocol decoder - dbus-generator-ramp: Generator current ramp controller - dbus-lightning: Blitzortung lightning monitor - dbus-meteoblue-forecast: Meteoblue weather forecast - dbus-no-foreign-land: noforeignland.com tracking - dbus-tides: Tide prediction from depth + harmonics - dbus-vrm-history: VRM cloud history proxy - dbus-windy-station: Windy.com weather upload - mfd-custom-app: MFD app deployment package - venus-html5-app: Custom Victron HTML5 app fork - watermaker: Watermaker PLC control UI Adds root README, .gitignore, project template, and per-project .gitignore files. Sensitive config files excluded via .gitignore with .example templates provided. Made-with: Cursor
94 lines
3.0 KiB
Python
94 lines
3.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Search for True Wind Direction values in the 69-73 degree range."""
|
|
|
|
import struct
|
|
from collections import defaultdict
|
|
|
|
# 69-73 degrees in radians
|
|
TARGET_DEG_MIN = 66 # slightly wider range
|
|
TARGET_DEG_MAX = 76
|
|
TARGET_RAD_MIN = TARGET_DEG_MIN * 0.0174533 # ~1.15 rad
|
|
TARGET_RAD_MAX = TARGET_DEG_MAX * 0.0174533 # ~1.33 rad
|
|
|
|
def decode_float(data, offset):
|
|
if offset + 4 > len(data):
|
|
return None
|
|
try:
|
|
val = struct.unpack('<f', data[offset:offset+4])[0]
|
|
if val != val: # NaN check
|
|
return None
|
|
return val
|
|
except:
|
|
return None
|
|
|
|
def read_pcap(filename):
|
|
packets = []
|
|
with open(filename, 'rb') as f:
|
|
header = f.read(24)
|
|
magic = struct.unpack('<I', header[0:4])[0]
|
|
swapped = magic == 0xd4c3b2a1
|
|
endian = '>' if swapped else '<'
|
|
|
|
while True:
|
|
pkt_header = f.read(16)
|
|
if len(pkt_header) < 16:
|
|
break
|
|
ts_sec, ts_usec, incl_len, orig_len = struct.unpack(f'{endian}IIII', pkt_header)
|
|
pkt_data = f.read(incl_len)
|
|
if len(pkt_data) < incl_len:
|
|
break
|
|
|
|
if len(pkt_data) > 42 and pkt_data[12:14] == b'\x08\x00':
|
|
ip_header_len = (pkt_data[14] & 0x0F) * 4
|
|
payload_start = 14 + ip_header_len + 8
|
|
if payload_start < len(pkt_data):
|
|
packets.append(pkt_data[payload_start:])
|
|
return packets
|
|
|
|
print(f"Reading raymarine_sample_twd_69-73.pcap...")
|
|
packets = read_pcap("raymarine_sample_twd_69-73.pcap")
|
|
print(f"Loaded {len(packets)} packets\n")
|
|
|
|
print(f"Searching for direction values {TARGET_DEG_MIN}-{TARGET_DEG_MAX}° ({TARGET_RAD_MIN:.3f}-{TARGET_RAD_MAX:.3f} rad)\n")
|
|
|
|
# Track candidates by offset
|
|
candidates = defaultdict(list)
|
|
|
|
for pkt_idx, pkt in enumerate(packets):
|
|
pkt_len = len(pkt)
|
|
if pkt_len < 100:
|
|
continue
|
|
|
|
for offset in range(0x30, min(pkt_len - 4, 0x400)):
|
|
val = decode_float(pkt, offset)
|
|
if val is None:
|
|
continue
|
|
|
|
# Check if in target radian range
|
|
if TARGET_RAD_MIN <= val <= TARGET_RAD_MAX:
|
|
deg = val * 57.2958
|
|
candidates[offset].append((pkt_idx, pkt_len, val, deg))
|
|
|
|
print("=" * 70)
|
|
print("WIND DIRECTION CANDIDATES (by offset, sorted by hit count)")
|
|
print("=" * 70)
|
|
|
|
# Sort by number of hits
|
|
sorted_offsets = sorted(candidates.keys(), key=lambda x: -len(candidates[x]))
|
|
|
|
for offset in sorted_offsets[:25]:
|
|
hits = candidates[offset]
|
|
values = [v for _, _, v, _ in hits]
|
|
degs = [d for _, _, _, d in hits]
|
|
pkt_sizes = sorted(set(s for _, s, _, _ in hits))
|
|
|
|
avg_rad = sum(values) / len(values)
|
|
avg_deg = sum(degs) / len(degs)
|
|
min_deg = min(degs)
|
|
max_deg = max(degs)
|
|
|
|
print(f"\n Offset 0x{offset:04x}: {len(hits):4d} hits")
|
|
print(f" Degrees: avg={avg_deg:.1f}°, range={min_deg:.1f}°-{max_deg:.1f}°")
|
|
print(f" Radians: avg={avg_rad:.4f}")
|
|
print(f" Packet sizes: {pkt_sizes[:8]}{'...' if len(pkt_sizes) > 8 else ''}")
|