Class MockDeviceClient

java.lang.Object
pl.polsl.rtsa.hardware.MockDeviceClient
All Implemented Interfaces:
DeviceClient

public class MockDeviceClient extends Object implements 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 Details

    • listeners

      private final List<DataListener> listeners
      Registered data/error listeners.
    • running

      private final AtomicBoolean running
      Flag indicating whether the generator thread is active.
    • dspService

      private final SignalProcessingService dspService
      DSP service used for FFT computation on the generated data.
    • generatorThread

      private Thread generatorThread
      Background thread that produces synthetic samples.
    • sampleRate

      private volatile double sampleRate
      Current sample rate in Hz.
  • Constructor Details

    • MockDeviceClient

      public MockDeviceClient()
  • Method Details

    • connect

      public boolean connect(String port)
      Establishes a connection to the specified port.

      Always succeeds — prints a diagnostic message to stdout.

      Specified by:
      connect in interface DeviceClient
      Parameters:
      port - The system port name (e.g., "COM3", "/dev/ttyACM0").
      Returns:
      true if the connection was successfully established, false otherwise.
    • disconnect

      public void disconnect()
      Closes the active connection and releases resources.
      Specified by:
      disconnect in interface DeviceClient
    • sendCommand

      public void sendCommand(DeviceCommand cmd)
      Sends a command to the connected device.
      Specified by:
      sendCommand in interface DeviceClient
      Parameters:
      cmd - The DeviceCommand to send.
    • addListener

      public void addListener(DataListener listener)
      Registers a listener to receive data and error events.
      Specified by:
      addListener in interface DeviceClient
      Parameters:
      listener - The DataListener to add.
    • getAvailablePorts

      public List<String> getAvailablePorts()
      Retrieves a list of currently available serial ports on the system.

      Returns two hard-coded mock port names.

      Specified by:
      getAvailablePorts in interface DeviceClient
      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.