A UARTDriver class manages the baud rate configuration for a UART peripheral in an embedded system.
Due to hardware clock divider limitations, the UART supports only three discrete baud rates:
The driver currently exposes its baud_rate member publicly, allowing application code to assign arbitrary integer values. This can result in invalid clock configurations and UART communication failure.
Your task is to refactor the driver to protect its internal state and enforce valid hardware configurations.
You must:
baud_rate member.This problem simulates a common firmware requirement: protecting hardware configuration registers from invalid application-level input.
Program Flow:
UARTDriver instance (default baud rate: 9600).N — the number of baud rate update requests.N times:request_baud.Input Format:
N (number of commands)N lines: One integer request_baud per lineInput is provided via standard input (stdin).
Output Format:
For each command, print the active baud rate in the following format:
Active: <value> Each output must be printed on a new line.
Example:
Input
4
115200
500
19200
-1 Output
Active: 115200
Active: 115200
Active: 19200
Active: 19200 Constraints:
1 ≤ N ≤ 20-1,000,000 ≤ request_baud ≤ 1,000,000{9600, 19200, 115200}9600
Input
4 115200 500 19200 -1
Expected Output
Active: 115200 Active: 115200 Active: 19200 Active: 19200