Add multi-protocol scale support and admin COM monitor
The bridge becomes pure transport: it opens the port, writes a poll string it is given at runtime, and streams raw lines. Protocol definitions live in Django and parsing happens in the browser, so a new scale type never means a new binary on the station PCs. The poll loop stays in the bridge because a browser cannot be the heartbeat - hidden tabs get throttled and a closed tab would stop the scale. Every payload now carries a hex field. Toledo Continuous sends STX and bit-packed status, which UTF-8 decoding silently corrupts. Fixed-column protocols need the opposite care: a space can mean balanced, so the trailing whitespace must survive. Parsers for the simulator, fixed-column, Toledo Continuous and SICS return an explicit error rather than a guess on a frame that does not match, since a silently wrong weight on a weighbridge is worse than no weight. Toledo and SICS are written from documented structure and have not been validated against real hardware. The admin monitor shows the raw stream as text and hex, sends one-off probe commands, and builds fixed-column protocols against captured lines. Spaces render as middots because in some protocols a space is the stability flag. The test writer now simulates a weighing cycle - idle, ramp, balanced, drop - alternating empty and loaded trucks, quantised to the 20kg and 50kg divisions real truck scales use. Bridge logging rotates and per-reading lines drop to DEBUG; the old config had grown two log files totalling 368MB. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -12,13 +12,24 @@ BAUD_RATE = int(os.getenv('BAUD_RATE', 9600))
|
||||
TIMEOUT = int(os.getenv('TIMEOUT', 1))
|
||||
|
||||
# Test Data Settings
|
||||
WRITE_INTERVAL = float(os.getenv('WRITE_INTERVAL', 1.0)) # seconds between writes
|
||||
WRITE_INTERVAL = float(os.getenv('WRITE_INTERVAL', 0.2)) # seconds between writes
|
||||
TEST_DATA_TYPE = os.getenv('TEST_DATA_TYPE', 'scales') # 'scales', 'counter', 'random'
|
||||
|
||||
# Scales data
|
||||
SCALES_MIN = int(os.getenv('SCALES_MIN', 5000))
|
||||
SCALES_MAX = int(os.getenv('SCALES_MAX', 20000))
|
||||
SCALES_INCREMENT = float(os.getenv('SCALES_INCREMENT', 5.0))
|
||||
# Scales data - simulated weighing cycle: idle at 0, ramp up, hold stable, drop back
|
||||
EMPTY_MIN = int(os.getenv('EMPTY_MIN', 15000))
|
||||
EMPTY_MAX = int(os.getenv('EMPTY_MAX', 22000))
|
||||
FULL_MIN = int(os.getenv('FULL_MIN', 35000))
|
||||
FULL_MAX = int(os.getenv('FULL_MAX', 45000))
|
||||
IDLE_SECONDS = float(os.getenv('IDLE_SECONDS', 2.0)) # at 0 between trucks
|
||||
RAMP_SECONDS = float(os.getenv('RAMP_SECONDS', 1.5)) # 0 -> target
|
||||
STABLE_SECONDS = float(os.getenv('STABLE_SECONDS', 5.0)) # balanced at target
|
||||
DROP_SECONDS = float(os.getenv('DROP_SECONDS', 1.0)) # target -> 0
|
||||
|
||||
# Scale division (multi-interval): readings snap to DIVISION_SMALL below
|
||||
# DIVISION_THRESHOLD, DIVISION_LARGE at or above it.
|
||||
DIVISION_SMALL = int(os.getenv('DIVISION_SMALL', 20))
|
||||
DIVISION_LARGE = int(os.getenv('DIVISION_LARGE', 50))
|
||||
DIVISION_THRESHOLD = int(os.getenv('DIVISION_THRESHOLD', 40000))
|
||||
|
||||
# Application Settings
|
||||
DEBUG = os.getenv('DEBUG', 'True') == 'True'
|
||||
|
||||
Reference in New Issue
Block a user