- All Known Implementing Classes:
SignalAnalyzerApiImpl
public interface SignalAnalyzerApi
Main API interface for the Signal Analyzer backend.
This interface defines the complete contract between the JavaFX frontend and the backend services. All methods are designed to be called from the UI thread and handle threading internally.
Usage Example:
SignalAnalyzerApi api = SignalAnalyzerApi.create();
// Subscribe to data updates
api.setDataCallback(data -> Platform.runLater(() -> updateCharts(data)));
// Connect and start
api.connect("/dev/ttyACM0");
api.startAcquisition();
// Cleanup
api.shutdown();
Thread Safety:
- All public methods are thread-safe
- Callbacks are invoked on a background thread
- Use
Platform.runLater()for UI updates in callbacks
-
Method Summary
Modifier and TypeMethodDescriptiondouble[]computeFFT(double[] voltageData, double sampleRate) Computes FFT for the given voltage data.computeStatistics(double[] voltageData, double[] freqData, double sampleRate) Computes signal statistics for the given data.voidConnects to a device on the specified port.double[]convertToVoltage(int[] rawData) Converts raw ADC values to voltage.static SignalAnalyzerApicreate()Creates a new API instance with real hardware support.static SignalAnalyzerApiCreates a new API instance with mock hardware for testing.voidDisconnects from the currently connected device.Gets the current acquisition configuration.Gets the list of available serial ports.Gets the current connection status.doubleGets the current sample rate.Gets the last received signal data.booleanChecks if acquisition is currently active.booleanChecks if a device is currently connected.booleanChecks if the API has been shut down.Refreshes the list of available serial ports.voidsetConnectionCallback(Consumer<ConnectionStatus> callback) Sets the callback for connection state changes.voidsetDataCallback(Consumer<SignalData> callback) Sets the callback for receiving signal data updates.voidsetErrorCallback(Consumer<String> callback) Sets the callback for receiving error notifications.voidSets the sample rate to 10 kHz.voidSets the sample rate to 1 kHz.voidSets the sample rate to 20 kHz (Turbo Mode).voidshutdown()Shuts down the API and releases all resources.voidStarts data acquisition.voidStops data acquisition.
-
Method Details
-
create
Creates a new API instance with real hardware support.- Returns:
- A new SignalAnalyzerApi instance.
-
createMock
Creates a new API instance with mock hardware for testing.- Returns:
- A new SignalAnalyzerApi instance using mock data.
-
getAvailablePorts
AvailablePorts getAvailablePorts()Gets the list of available serial ports.- Returns:
- AvailablePorts containing port names and metadata.
-
refreshPorts
AvailablePorts refreshPorts()Refreshes the list of available serial ports. Useful after plugging/unplugging devices.- Returns:
- Updated AvailablePorts.
-
connect
Connects to a device on the specified port.This method performs handshake validation and will throw if the device does not respond correctly.
- Parameters:
portName- The system port name (e.g., "COM3", "/dev/ttyACM0").- Throws:
ConnectionException- if connection fails.
-
disconnect
void disconnect()Disconnects from the currently connected device. Safe to call even if not connected. -
getConnectionStatus
ConnectionStatus getConnectionStatus()Gets the current connection status.- Returns:
- ConnectionStatus with connection details.
-
isConnected
boolean isConnected()Checks if a device is currently connected.- Returns:
- true if connected, false otherwise.
-
startAcquisition
void startAcquisition()Starts data acquisition. Must be connected first.- Throws:
DeviceException- if not connected or command fails.
-
stopAcquisition
void stopAcquisition()Stops data acquisition. Safe to call even if not acquiring. -
isAcquiring
boolean isAcquiring()Checks if acquisition is currently active.- Returns:
- true if acquiring data, false otherwise.
-
getAcquisitionConfig
AcquisitionConfig getAcquisitionConfig()Gets the current acquisition configuration.- Returns:
- AcquisitionConfig with current settings.
-
setSampleRate1kHz
void setSampleRate1kHz()Sets the sample rate to 1 kHz. -
setSampleRate10kHz
void setSampleRate10kHz()Sets the sample rate to 10 kHz. -
setSampleRate20kHz
void setSampleRate20kHz()Sets the sample rate to 20 kHz (Turbo Mode).Note: Turbo mode may have reduced impedance tolerance.
-
getCurrentSampleRate
double getCurrentSampleRate()Gets the current sample rate.- Returns:
- Sample rate in Hz.
-
setDataCallback
Sets the callback for receiving signal data updates.The callback is invoked on a background thread. Use
Platform.runLater()for UI updates.- Parameters:
callback- Consumer that receives SignalData updates, or null to clear.
-
setErrorCallback
Sets the callback for receiving error notifications.The callback is invoked on a background thread.
- Parameters:
callback- Consumer that receives error messages, or null to clear.
-
setConnectionCallback
Sets the callback for connection state changes.- Parameters:
callback- Consumer that receives ConnectionStatus updates, or null to clear.
-
getLastSignalData
SignalData getLastSignalData()Gets the last received signal data. Returns null if no data has been received yet.- Returns:
- The most recent SignalData, or null.
-
computeFFT
double[] computeFFT(double[] voltageData, double sampleRate) Computes FFT for the given voltage data. Useful for processing external data.- Parameters:
voltageData- Time-domain voltage samples.sampleRate- Sample rate used to capture the data.- Returns:
- FFT magnitude spectrum.
-
convertToVoltage
double[] convertToVoltage(int[] rawData) Converts raw ADC values to voltage.- Parameters:
rawData- Raw 10-bit ADC values (0-1023).- Returns:
- Voltage values (0.0-5.0V).
-
computeStatistics
Computes signal statistics for the given data.- Parameters:
voltageData- Time-domain voltage samples.freqData- Frequency-domain magnitude data.sampleRate- Sample rate in Hz.- Returns:
- Computed SignalStatistics.
-
shutdown
void shutdown()Shuts down the API and releases all resources.This method should be called when the application is closing. It stops acquisition, disconnects, and shuts down all background threads.
-
isShutdown
boolean isShutdown()Checks if the API has been shut down.- Returns:
- true if shutdown() has been called.
-