Update glory simulator
This commit is contained in:
@ -143,14 +143,16 @@ class GlorySimulator:
|
|||||||
|
|
||||||
if cmd == "GT":
|
if cmd == "GT":
|
||||||
# Get batch total
|
# Get batch total
|
||||||
# If no counts, generate random simulation data
|
# For simulator: reset and generate new counts for each GT request
|
||||||
# if not self.batch_counts and self.motor_has_run:
|
# This simulates a fresh batch counting session
|
||||||
if True:
|
logger.info("GT received - resetting batch and simulating new count")
|
||||||
|
self.batch_counts = {}
|
||||||
self._simulate_counting()
|
self._simulate_counting()
|
||||||
|
|
||||||
total = sum(self.batch_counts.values())
|
total = sum(self.batch_counts.values())
|
||||||
response = f"BT{total:08d}"
|
response = f"BT{total:08d}"
|
||||||
logger.info(f"Get batch total: {total} coins")
|
logger.info(f"Get batch total: {total} coins")
|
||||||
|
|
||||||
return self.create_message(response)
|
return self.create_message(response)
|
||||||
|
|
||||||
elif cmd == "GS":
|
elif cmd == "GS":
|
||||||
@ -225,10 +227,11 @@ class GlorySimulator:
|
|||||||
cmd = data.decode("ascii", errors="ignore").strip()
|
cmd = data.decode("ascii", errors="ignore").strip()
|
||||||
|
|
||||||
if cmd == "MG":
|
if cmd == "MG":
|
||||||
# Start motor
|
# Start motor - reset batch counts for new counting session
|
||||||
self.motor_running = True
|
self.motor_running = True
|
||||||
self.motor_has_run = True
|
self.motor_has_run = True
|
||||||
logger.info("Motor started")
|
self.batch_counts = {} # Reset batch for new counting session
|
||||||
|
logger.info("Motor started - batch counts reset")
|
||||||
# Simulate coin counting
|
# Simulate coin counting
|
||||||
self._simulate_counting()
|
self._simulate_counting()
|
||||||
elif cmd == "MS":
|
elif cmd == "MS":
|
||||||
@ -318,18 +321,18 @@ class GlorySimulator:
|
|||||||
"""Simulate coin counting when motor runs"""
|
"""Simulate coin counting when motor runs"""
|
||||||
# Generate random counts for simulation
|
# Generate random counts for simulation
|
||||||
# Standard denominations with realistic count distributions
|
# Standard denominations with realistic count distributions
|
||||||
|
# All ranges start at 1 to ensure non-zero counts
|
||||||
denominations = {
|
denominations = {
|
||||||
"001": (20, 150), # Pennies - high count
|
"001": (20, 150), # Pennies - high count
|
||||||
"005": (10, 100), # Nickels
|
"005": (10, 100), # Nickels
|
||||||
"010": (10, 80), # Dimes
|
"010": (10, 80), # Dimes
|
||||||
"025": (5, 60), # Quarters
|
"025": (5, 60), # Quarters
|
||||||
"050": (0, 20), # Half dollars - rare
|
"050": (1, 20), # Half dollars - rare (changed from 0)
|
||||||
"100": (0, 10), # Dollar coins - rare
|
"100": (1, 10), # Dollar coins - rare (changed from 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
for denom, (min_count, max_count) in denominations.items():
|
for denom, (min_count, max_count) in denominations.items():
|
||||||
count = random.randint(min_count, max_count)
|
count = random.randint(min_count, max_count)
|
||||||
if count > 0:
|
|
||||||
# Update batch counts
|
# Update batch counts
|
||||||
self.batch_counts[denom] = self.batch_counts.get(denom, 0) + count
|
self.batch_counts[denom] = self.batch_counts.get(denom, 0) + count
|
||||||
# Update partial counts
|
# Update partial counts
|
||||||
|
|||||||
Reference in New Issue
Block a user