root
    main
        centerfreq
        - min:  192500000.000000
        - max:  6000000000.000000
        - step: 1000.000000
        - unit: Frequency
        decimation
        -enum: Full;1 / 2;1 / 4;1 / 8;1 / 16;1 / 32;1 / 64;1 / 128;1 / 256;1 / 512
        reflevel
        - min:  -20.000000
        - max:  10.000000
        - step: 0.500000
        - unit: dBm
        transgain
        - min:  -100.000000
        - max:  10.000000
        - step: 0.010000
        - unit: dB
    device
        usbcompression
        -enum: auto;compressed;raw
        gaincontrol
        -enum: manual;peak;power
        loharmonic
        -enum: base;third;fifth
        outputformat
        -enum: iq;spectra;both;auto
        lowpower
        -bool
        fft0
            fftmergemode
            -enum: avg;sum;min;max
            fftaggregate
            - min:  1.000000
            - max:  65535.000000
            - step: 1.000000
            - unit:
            fftsizemode
            -enum: FFT;Bins;Step Frequency;RBW
            fftsize
            - min:  8.000000
            - max:  8192.000000
            - step: 1.000000
            - unit:
            fftbinsize
            - min:  32.000000
            - max:  8192.000000
            - step: 1.000000
            - unit:
            fftstepfreq
            - min:  1000.000000
            - max:  100000000.000000
            - step: 1000.000000
            - unit: Frequency
            fftrbwfreq
            - min:  0.001000
            - max:  100000000.000000
            - step: 0.001000
            - unit: Frequency
            fftwindow
            -enum: Hamming;Hann;Uniform;Blackman;Blackman Harris;Blackman Harris 7;Flat Top;Lanczos;Gaussion 0.5;Gaussion 0.4;Gaussian 0.3;Gaussion 0.2;Gaussian 0.1;Kaiser 6;Kaiser 12;Kaiser 18;Kaiser 36;Kaiser 72;Tukey 0.1;Tukey 0.3;Tukey 0.5;Tukey 0.7;Tukey 0.9
        fft1
            fftmergemode
            -enum: avg;sum;min;max
            fftaggregate
            - min:  1.000000
            - max:  65535.000000
            - step: 1.000000
            - unit:
            fftsizemode
            -enum: FFT;Bins;Step Frequency;RBW
            fftsize
            - min:  8.000000
            - max:  8192.000000
            - step: 1.000000
            - unit:
            fftbinsize
            - min:  32.000000
            - max:  8192.000000
            - step: 1.000000
            - unit:
            fftstepfreq
            - min:  1000.000000
            - max:  100000000.000000
            - step: 1000.000000
            - unit: Frequency
            fftrbwfreq
            - min:  0.001000
            - max:  100000000.000000
            - step: 0.001000
            - unit: Frequency
            fftwindow
            -enum: Hamming;Hann;Uniform;Blackman;Blackman Harris;Blackman Harris 7;Flat Top;Lanczos;Gaussion 0.5;Gaussion 0.4;Gaussian 0.3;Gaussion 0.2;Gaussian 0.1;Kaiser 6;Kaiser 12;Kaiser 18;Kaiser 36;Kaiser 72;Tukey 0.1;Tukey 0.3;Tukey 0.5;Tukey 0.7;Tukey 0.9
        receiverclock
        -enum: 92MHz;122MHz;184MHz;245MHz
        receiverchannel
        -enum: Rx1;Rx2;Rx1+Rx2;Rx1/Rx2;Rx Off;auto
        receiverchannelsel
        -enum: Rx1;Rx2;Rx2->1;Rx1->2
        transmittermode
        -enum: Off;Test;Stream;Reactive;Signal Generator;Pattern Generator
        transmitterclockvar
        - min:  0.000001
        - max:  1.000000
        - step: 0.000001
        - unit: Time
        generator
            type
            -enum: Relative Tone;Absolute Tone;Step;Sweep;Full Sweep;Center Sweep;Polytone;Relative Ditone;Absolute Ditone;Noise;Digital Noise;Off
            startfreq
            - min:  1000.000000
            - max:  20000000000.000000
            - step: 1.000000
            - unit: Frequency
            stopfreq
            - min:  1000.000000
            - max:  20000000000.000000
            - step: 1.000000
            - unit: Frequency
            stepfreq
            - min:  1.000000
            - max:  200000000.000000
            - step: 1.000000
            - unit: Frequency
            offsetfreq
            - min:  -60000000.000000
            - max:  60000000.000000
            - step: 1.000000
            - unit: Frequency
            duration
            - min:  0.000010
            - max:  3600.000000
            - step: 0.000010
            - unit: Time
            powerramp
            - min:  -150.000000
            - max:  150.000000
            - step: 0.100000
            - unit: dB
        sclksource
        -enum: Consumer;Oscillator;GPS;PPS;10MHz;Oscillator Provider;GPS Provider;PPS Provider
        triggeredge
        -enum: Off;High;Low;Rising;Falling;Changing
        triggerflag
        -enum: C0;C1;C2;C3
        gpsmode
        -enum: Disabled;Location;Time;Location and Time
        gpsrate
        - min:  0.100000
        - max:  5.000000
        - step: 0.100000
        - unit: Time
        tempfancontrol
        -bool
        serial
        -string
    calibration
        rffilter
        -enum: Calibration;Bypass;Auto;Auto Extended;75-145 (50);90-160 (50);110-195 (50);135-205 (50);155-270 (50);155-270 (100);155-280 (100);180-350 (100);230-460 (100);240-545;340-650;440-815;610-1055;850-1370;1162-2060;1850-3010;2800-4610;4400-6100
        preamp
        -enum: Disabled;Auto;None;Amp;Preamp;Both
        rftxfilter
        -enum: Calibration;Bypass;Auto;Auto Extended;75-145 (50);90-160 (50);110-195 (50);135-205 (50);155-270 (50);155-270 (100);155-280 (100);180-350 (100);230-460 (100);240-545;340-650;440-815;610-1055;850-1370;1162-2060;1850-3010;2800-4610;4400-6100
        calibrationmode
        -enum: Off;RX Attenuator;TX Attenuator;Tx No Amplifier;Tx Amplifier;Rx Thermal;Tx Thermal;Rx RTBW;Tx RTBW;Rx Filter;Rx Amplifier;Tx LO Leakage;Clock;Raw;Free
        txioffset
        - min:  -0.100000
        - max:  0.100000
        - step: 0.000100
        - unit: Number
        txqoffset
        - min:  -0.100000
        - max:  0.100000
        - step: 0.000100
        - unit: Number
        txexcent
        - min:  -0.100000
        - max:  0.100000
        - step: 0.000010
        - unit: Percentage
        txphaseskew
        - min:  -15.000000
        - max:  15.000000
        - step: 0.010000
        - unit: Degree
        clockscale
        - min:  -100.000000
        - max:  100.000000
        - step: 0.000001
        - unit: Frequency
        clockbygpsupdate
        -enum: Never;Once;Reset;On Startup;Slow;Fast;Realtime
        calibrationreload
        -bool




    void dumpConfig(std::wstring serial) {
        AARTSAAPI_Device dev;
        if (AARTSAAPI_OpenDevice(&api, &dev, L"spectranv6/raw", serial.c_str()) != AARTSAAPI_OK) {
            spdlog::error("Could not open device");
            return;
        }

        AARTSAAPI_Config root;
        if (AARTSAAPI_ConfigRoot(&dev, &root) != AARTSAAPI_OK) {
            spdlog::error("Could not get config root");
            return;
        }

        // Dump configuration recursively
        dumpConfig(dev, root);

        AARTSAAPI_CloseDevice(&api, &dev);
    }

    void dumpConfig(AARTSAAPI_Device& dev, AARTSAAPI_Config& conf, int depth = 0) {
        std::string prefix = "";
        std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;
        for (int i = 0; i < depth; i++) { prefix += "    "; }
        AARTSAAPI_ConfigInfo info;
        AARTSAAPI_ConfigGetInfo(&dev, &conf, &info);

        printf("%s%s\n", prefix.c_str(), conv.to_bytes(info.name).c_str());

        if (info.type == AARTSAAPI_CONFIG_TYPE_GROUP) {
            AARTSAAPI_Config item;
            AARTSAAPI_ConfigFirst(&dev, &conf, &item);
            do {
                dumpConfig(dev, item, depth + 1);
            }
            while (AARTSAAPI_ConfigNext(&dev, &conf, &item) == AARTSAAPI_OK);
        }
        else if (info.type == AARTSAAPI_CONFIG_TYPE_NUMBER) {
            printf("%s- min:  %lf\n", prefix.c_str(), info.minValue);
            printf("%s- max:  %lf\n", prefix.c_str(), info.maxValue);
            printf("%s- step: %lf\n", prefix.c_str(), info.stepValue);
            printf("%s- unit: %s\n", prefix.c_str(), conv.to_bytes(info.unit).c_str());
        }
        else if (info.type == AARTSAAPI_CONFIG_TYPE_BOOL) {
            printf("%s-bool\n", prefix.c_str());
        }
        else if (info.type == AARTSAAPI_CONFIG_TYPE_ENUM) {
            printf("%s-enum: %s\n", prefix.c_str(), conv.to_bytes(info.options).c_str());
        }
        else if (info.type == AARTSAAPI_CONFIG_TYPE_STRING) {
            printf("%s-string\n", prefix.c_str());
        }
    }
