Update drivers
This commit is contained in:
@ -12,6 +12,8 @@ from typing import Optional
|
||||
import serial
|
||||
from loguru import logger
|
||||
|
||||
from source.common import format_comm_debug
|
||||
|
||||
# Protocol constants
|
||||
STX = 0x02
|
||||
ETX = 0x03
|
||||
@ -151,8 +153,7 @@ class GlorySimulator:
|
||||
|
||||
# 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()
|
||||
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}")
|
||||
@ -162,8 +163,7 @@ class GlorySimulator:
|
||||
elif cmd == "GS":
|
||||
# Get subtotal (monetary value)
|
||||
total_value = sum(
|
||||
count * int(denom)
|
||||
for denom, count in self.sub_counts.items()
|
||||
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}")
|
||||
@ -172,8 +172,7 @@ class GlorySimulator:
|
||||
elif cmd == "GG":
|
||||
# Get grand total (monetary value)
|
||||
total_value = sum(
|
||||
count * int(denom)
|
||||
for denom, count in self.grand_counts.items()
|
||||
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}")
|
||||
@ -195,7 +194,9 @@ class GlorySimulator:
|
||||
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}")
|
||||
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":
|
||||
@ -270,8 +271,7 @@ class GlorySimulator:
|
||||
if cmd == "AB" or cmd == "Ab":
|
||||
# Accept batch (monetary value)
|
||||
total_value = sum(
|
||||
count * int(denom)
|
||||
for denom, count in self.batch_counts.items()
|
||||
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}")
|
||||
@ -281,8 +281,7 @@ class GlorySimulator:
|
||||
elif cmd == "AS" or cmd == "As":
|
||||
# Accept subtotal (monetary value)
|
||||
total_value = sum(
|
||||
count * int(denom)
|
||||
for denom, count in self.sub_counts.items()
|
||||
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}")
|
||||
@ -292,8 +291,7 @@ class GlorySimulator:
|
||||
elif cmd == "AG" or cmd == "Ag":
|
||||
# Accept grand total (monetary value)
|
||||
total_value = sum(
|
||||
count * int(denom)
|
||||
for denom, count in self.grand_counts.items()
|
||||
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}")
|
||||
@ -483,8 +481,9 @@ class GlorySimulator:
|
||||
message = bytes(buffer[stx_idx : etx_idx + 1])
|
||||
buffer = buffer[etx_idx + 1 :]
|
||||
|
||||
# logger.debug(f"RX: {' '.join(f'{b:02X}' for b in message)}")
|
||||
logger.debug(
|
||||
f"RX: {' '.join(f'{b:02X}' for b in message)}"
|
||||
format_comm_debug("RX", message, include_ascii=True)
|
||||
)
|
||||
|
||||
# Parse and handle message
|
||||
@ -493,7 +492,9 @@ class GlorySimulator:
|
||||
response = self.handle_command(parsed_data)
|
||||
if response:
|
||||
logger.debug(
|
||||
f"TX: {' '.join(f'{b:02X}' for b in response)}"
|
||||
format_comm_debug(
|
||||
"TX", response, include_ascii=True
|
||||
)
|
||||
)
|
||||
self.serial_conn.write(response)
|
||||
except ValueError:
|
||||
|
||||
Reference in New Issue
Block a user