Fix glory simulator
This commit is contained in:
@ -142,31 +142,41 @@ class GlorySimulator:
|
||||
cmd = data.decode("ascii", errors="ignore").strip()
|
||||
|
||||
if cmd == "GT":
|
||||
# Get batch total
|
||||
# Get batch total (monetary value)
|
||||
# For simulator: reset and generate new counts for each GT request
|
||||
# This simulates a fresh batch counting session
|
||||
logger.info("GT received - resetting batch and simulating new count")
|
||||
self.batch_counts = {}
|
||||
self._simulate_counting()
|
||||
|
||||
total = sum(self.batch_counts.values())
|
||||
response = f"BT{total:08d}"
|
||||
logger.info(f"Get batch total: {total} coins")
|
||||
# Calculate total monetary value (sum of count × denomination for all coins)
|
||||
total_value = sum(
|
||||
count * int(denom)
|
||||
for denom, count in self.batch_counts.items()
|
||||
)
|
||||
response = f"BT{total_value:08d}"
|
||||
logger.info(f"Get batch total: ${total_value/100:.2f}")
|
||||
|
||||
return self.create_message(response)
|
||||
|
||||
elif cmd == "GS":
|
||||
# Get subtotal
|
||||
total = sum(self.sub_counts.values())
|
||||
response = f"BS{total:08d}"
|
||||
logger.info(f"Get subtotal: {total} coins")
|
||||
# Get subtotal (monetary value)
|
||||
total_value = sum(
|
||||
count * int(denom)
|
||||
for denom, count in self.sub_counts.items()
|
||||
)
|
||||
response = f"BS{total_value:08d}"
|
||||
logger.info(f"Get subtotal: ${total_value/100:.2f}")
|
||||
return self.create_message(response)
|
||||
|
||||
elif cmd == "GG":
|
||||
# Get grand total
|
||||
total = sum(self.grand_counts.values())
|
||||
response = f"BG{total:08d}"
|
||||
logger.info(f"Get grand total: {total} coins")
|
||||
# Get grand total (monetary value)
|
||||
total_value = sum(
|
||||
count * int(denom)
|
||||
for denom, count in self.grand_counts.items()
|
||||
)
|
||||
response = f"BG{total_value:08d}"
|
||||
logger.info(f"Get grand total: ${total_value/100:.2f}")
|
||||
return self.create_message(response)
|
||||
|
||||
elif cmd.startswith("GD"):
|
||||
@ -178,11 +188,14 @@ class GlorySimulator:
|
||||
return self.create_message(response)
|
||||
|
||||
elif cmd.startswith("GT") and len(cmd) > 2:
|
||||
# Get batch counts of denomination
|
||||
# Get batch value of denomination (monetary value, not count)
|
||||
denom_str = cmd[2:]
|
||||
count = self.batch_counts.get(denom_str, 0)
|
||||
response = f"BT{count:08d}"
|
||||
logger.info(f"Get batch count for {denom_str}: {count} coins")
|
||||
# Calculate monetary value: count × denomination (in cents)
|
||||
denom_value = int(denom_str) # e.g., "001" = 1 cent, "025" = 25 cents
|
||||
monetary_value = count * denom_value
|
||||
response = f"BT{monetary_value:08d}"
|
||||
logger.info(f"Get batch value for {denom_str}: {count} coins × ${denom_value/100:.2f} = ${monetary_value/100:.2f}")
|
||||
return self.create_message(response)
|
||||
|
||||
elif cmd == "GI":
|
||||
@ -255,26 +268,35 @@ class GlorySimulator:
|
||||
cmd = data.decode("ascii", errors="ignore").strip()
|
||||
|
||||
if cmd == "AB" or cmd == "Ab":
|
||||
# Accept batch
|
||||
total = sum(self.batch_counts.values())
|
||||
response = f"BT{total:08d}"
|
||||
logger.info(f"Accept batch: {total}")
|
||||
# Accept batch (monetary value)
|
||||
total_value = sum(
|
||||
count * int(denom)
|
||||
for denom, count in self.batch_counts.items()
|
||||
)
|
||||
response = f"BT{total_value:08d}"
|
||||
logger.info(f"Accept batch: ${total_value/100:.2f}")
|
||||
self.pending_message = response
|
||||
return self.create_message(response)
|
||||
|
||||
elif cmd == "AS" or cmd == "As":
|
||||
# Accept subtotal
|
||||
total = sum(self.sub_counts.values())
|
||||
response = f"BS{total:08d}"
|
||||
logger.info(f"Accept subtotal: {total}")
|
||||
# Accept subtotal (monetary value)
|
||||
total_value = sum(
|
||||
count * int(denom)
|
||||
for denom, count in self.sub_counts.items()
|
||||
)
|
||||
response = f"BS{total_value:08d}"
|
||||
logger.info(f"Accept subtotal: ${total_value/100:.2f}")
|
||||
self.pending_message = response
|
||||
return self.create_message(response)
|
||||
|
||||
elif cmd == "AG" or cmd == "Ag":
|
||||
# Accept grand total
|
||||
total = sum(self.grand_counts.values())
|
||||
response = f"BG{total:08d}"
|
||||
logger.info(f"Accept grand total: {total}")
|
||||
# Accept grand total (monetary value)
|
||||
total_value = sum(
|
||||
count * int(denom)
|
||||
for denom, count in self.grand_counts.items()
|
||||
)
|
||||
response = f"BG{total_value:08d}"
|
||||
logger.info(f"Accept grand total: ${total_value/100:.2f}")
|
||||
self.pending_message = response
|
||||
return self.create_message(response)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user