java.lang.Object
pl.polsl.rtsa.hardware.MockDeviceClient
- All Implemented Interfaces:
DeviceClient
Mock implementation of
DeviceClient for off-line testing.
Generates a synthetic 50 Hz sine wave (2.5 V DC offset, 2.0 Vpp) with a small amount of additive white noise. Data is produced in 1024-sample batches at the currently configured sample rate.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final SignalProcessingServiceDSP service used for FFT computation on the generated data.private ThreadBackground thread that produces synthetic samples.private final List<DataListener> Registered data/error listeners.private final AtomicBooleanFlag indicating whether the generator thread is active.private doubleCurrent sample rate in Hz. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(DataListener listener) Registers a listener to receive data and error events.booleanEstablishes a connection to the specified port.voidCloses the active connection and releases resources.Retrieves a list of currently available serial ports on the system.voidsendCommand(DeviceCommand cmd) Sends a command to the connected device.private voidSpawns a background thread that produces synthetic 50 Hz sine-wave batches with additive noise and dispatches them to all listeners.
-
Field Details
-
listeners
Registered data/error listeners. -
running
Flag indicating whether the generator thread is active. -
dspService
DSP service used for FFT computation on the generated data. -
generatorThread
Background thread that produces synthetic samples. -
sampleRate
private volatile double sampleRateCurrent sample rate in Hz.
-
-
Constructor Details
-
MockDeviceClient
public MockDeviceClient()
-
-
Method Details
-
connect
Establishes a connection to the specified port.Always succeeds — prints a diagnostic message to stdout.
- Specified by:
connectin interfaceDeviceClient- Parameters:
port- The system port name (e.g., "COM3", "/dev/ttyACM0").- Returns:
trueif the connection was successfully established,falseotherwise.
-
disconnect
public void disconnect()Closes the active connection and releases resources.- Specified by:
disconnectin interfaceDeviceClient
-
sendCommand
Sends a command to the connected device.- Specified by:
sendCommandin interfaceDeviceClient- Parameters:
cmd- TheDeviceCommandto send.
-
addListener
Registers a listener to receive data and error events.- Specified by:
addListenerin interfaceDeviceClient- Parameters:
listener- TheDataListenerto add.
-
getAvailablePorts
Retrieves a list of currently available serial ports on the system.Returns two hard-coded mock port names.
- Specified by:
getAvailablePortsin interfaceDeviceClient- Returns:
- A list of port names.
-
startGenerating
private void startGenerating()Spawns a background thread that produces synthetic 50 Hz sine-wave batches with additive noise and dispatches them to all listeners.
-