# Copyright (C) 2026 RemoteRF # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . """Template for a schema-generated RemoteRF custom device driver. Copy this file to ~/.config/remoterf/drivers/, replace the connection helper and vendor calls, then add a matching device_type entry to devices.yml. """ from remoteRF_server.common.idl import DeviceSchema, idl_expose, idl_register # Replace this with the vendor package, SDK, or local wrapper your device uses. # import vendor_device_api def connect_my_device(*, serial=None, address=None): """Open the physical device and return the vendor device object.""" try: # dev = vendor_device_api.open(serial=serial, address=address) # return dev raise NotImplementedError("replace with real connection code") except Exception as exc: print(f"Failed to open my_device: {exc}") return None @idl_register("my_device") class MyDeviceSchema(DeviceSchema): device_type = "my_device" client_class = "MyDevice" driver_version = "0.1.0" @staticmethod def make_device(**kwargs): return connect_my_device( serial=kwargs.get("serial"), address=kwargs.get("address"), ) @idl_expose(kind="get", doc="Center frequency in Hz.") def get_frequency(self): return self.device.frequency @idl_expose(kind="set") def set_frequency(self, value): self.device.frequency = int(value) @idl_expose(kind="call", doc="Capture samples from one channel.") def call_capture( self, count: int = 4096, *, channel: int = 0, timeout: float = 1.0, ): return self.device.capture( count=int(count), channel=int(channel), timeout=float(timeout), ) @idl_expose(kind="call", doc="Configure the device and return its state.") def call_configure( self, frequency: float, gain: float = 0.0, options: dict = None, ): options = {} if options is None else dict(options) return self.device.configure( frequency=float(frequency), gain=float(gain), options=options, ) @idl_expose def call_reset(self): self.device.reset() return 0