Fix: dry-run NPM silencieux (suppression print qui cassaient le JSON)
En mode --dry-run, les print d'erreur/warning/status sont desactives pour que seul le JSON soit envoye en sortie standard. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -113,7 +113,8 @@ try:
|
||||
|
||||
# Validate response length
|
||||
if len(byte_data) < response_length:
|
||||
print(f"[ERROR] Incomplete response received: {byte_data.hex()}")
|
||||
if not dry_run:
|
||||
print(f"[ERROR] Incomplete response received: {byte_data.hex()}")
|
||||
raise Exception("Incomplete response")
|
||||
|
||||
# Verify CRC
|
||||
@@ -121,7 +122,8 @@ try:
|
||||
calculated_crc = crc16(byte_data[:-2])
|
||||
|
||||
if received_crc != calculated_crc:
|
||||
print("[ERROR] CRC check failed! Corrupted data received.")
|
||||
if not dry_run:
|
||||
print("[ERROR] CRC check failed! Corrupted data received.")
|
||||
raise Exception("CRC check failed")
|
||||
|
||||
# Convert response to hex for debugging
|
||||
@@ -197,16 +199,20 @@ try:
|
||||
status_calc_crc = crc16(status_response[:-2])
|
||||
if status_recv_crc == status_calc_crc:
|
||||
npm_status = int.from_bytes(status_response[3:5], byteorder='big') & 0xFF
|
||||
print(f"NPM status: 0x{npm_status:02X} ({npm_status})")
|
||||
if not dry_run:
|
||||
print(f"NPM status: 0x{npm_status:02X} ({npm_status})")
|
||||
else:
|
||||
print("[WARNING] NPM status CRC check failed, keeping default")
|
||||
if not dry_run:
|
||||
print("[WARNING] NPM status CRC check failed, keeping default")
|
||||
else:
|
||||
print(f"[WARNING] NPM status incomplete response ({len(status_response)} bytes)")
|
||||
if not dry_run:
|
||||
print(f"[WARNING] NPM status incomplete response ({len(status_response)} bytes)")
|
||||
|
||||
ser.close()
|
||||
|
||||
except Exception as e:
|
||||
print(f"[ERROR] Sensor communication failed: {e}")
|
||||
if not dry_run:
|
||||
print(f"[ERROR] Sensor communication failed: {e}")
|
||||
# Variables already set to -1 at the beginning
|
||||
|
||||
finally:
|
||||
|
||||
Reference in New Issue
Block a user