Files
venus/axiom-nmea/debug/find_twd_precise.py
dev 9756538f16 Initial commit: Venus OS boat addons monorepo
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
2026-03-16 17:04:16 +00:00

103 lines
3.3 KiB
Python

#!/usr/bin/env python3
"""Find all float values in 69-73 degree range more precisely."""
import struct
from collections import defaultdict
# Exact expected range: 69-73 degrees
TARGET_DEG_MIN = 68
TARGET_DEG_MAX = 74
TARGET_RAD_MIN = TARGET_DEG_MIN * 0.0174533
TARGET_RAD_MAX = TARGET_DEG_MAX * 0.0174533
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 PRECISELY for {TARGET_DEG_MIN}-{TARGET_DEG_MAX}° ({TARGET_RAD_MIN:.4f}-{TARGET_RAD_MAX:.4f} 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, 0x500)):
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(f"OFFSETS WITH VALUES IN {TARGET_DEG_MIN}-{TARGET_DEG_MAX}° RANGE")
print("=" * 70)
# Sort by number of hits
sorted_offsets = sorted(candidates.keys(), key=lambda x: -len(candidates[x]))
for offset in sorted_offsets[:30]:
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_deg = sum(degs) / len(degs)
min_deg = min(degs)
max_deg = max(degs)
print(f"\n 0x{offset:04x}: {len(hits):3d} hits, avg={avg_deg:.1f}°, range={min_deg:.1f}°-{max_deg:.1f}°")
print(f" Packet sizes: {pkt_sizes}")
# Also show what's at offset 0x0070 since it had good results
print("\n" + "=" * 70)
print("DETAILED CHECK OF OFFSET 0x0070 (from earlier analysis)")
print("=" * 70)
for pkt_len in [344, 446, 788, 888, 931, 1031, 1472]:
matching = [p for p in packets if len(p) == pkt_len][:5]
if matching:
vals = [decode_float(p, 0x0070) for p in matching]
degs = [v * 57.2958 if v else None for v in vals]
print(f" {pkt_len} bytes: {[f'{d:.1f}°' if d else 'N/A' for d in degs]}")