/*
    * Sdr.hpp
    * Software-defined radio receive syscalls.
    * SYS_SDR_COUNT / INFO / OPEN / CLOSE / START / STOP / READ / SETPARAM / GETPARAM
    * Thin syscall layer over the generic SDR subsystem (Drivers::Radio::Sdr).
    * Copyright (c) 2026 Daniel Hammer
*/

#pragma once
#include <cstdint>
#include <Drivers/Radio/Sdr.hpp>

#include "Syscall.hpp"

namespace montauk::abi {

    static int64_t Sys_SdrCount() {
        return (int64_t)Drivers::Radio::Sdr::Count();
    }

    static int64_t Sys_SdrInfo(int index, SdrDeviceInfo* out) {
        if (!out) return -1;
        return Drivers::Radio::Sdr::GetInfo(index, out) ? 0 : -1;
    }

    static int64_t Sys_SdrOpen(int index) {
        return (int64_t)Drivers::Radio::Sdr::Open(index);
    }

    static int64_t Sys_SdrClose(int handle) {
        return (int64_t)Drivers::Radio::Sdr::Close(handle);
    }

    static int64_t Sys_SdrStart(int handle) {
        return (int64_t)Drivers::Radio::Sdr::Start(handle);
    }

    static int64_t Sys_SdrStop(int handle) {
        return (int64_t)Drivers::Radio::Sdr::Stop(handle);
    }

    static int64_t Sys_SdrRead(int handle, uint8_t* buf, uint32_t len) {
        if (!buf) return -1;
        return (int64_t)Drivers::Radio::Sdr::Read(handle, buf, len);
    }

    static int64_t Sys_SdrSetParam(int handle, int param, uint64_t value) {
        return (int64_t)Drivers::Radio::Sdr::SetParam(handle, param, value);
    }

    static int64_t Sys_SdrGetParam(int handle, int param) {
        return (int64_t)Drivers::Radio::Sdr::GetParam(handle, param);
    }

}
