This file is indexed.

/usr/include/freesrp.hpp is in libfreesrp-dev 0.3.0-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
/*
 * Copyright 2017 by Lukas Lao Beyer <lukas@electronics.kitchen>
 *
 * This file is part of libfreesrp.
 *
 * libfreesrp 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.

 * libfreesrp 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 libfreesrp.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef LIBFREESRP_FREESRP_HPP
#define LIBFREESRP_FREESRP_HPP

#include <string>
#include <array>
#include <vector>
#include <stdexcept>
#include <iostream>
#include <memory>
#include <atomic>
#include <thread>
#include <functional>
#include <cstdint>

#define FREESRP_VENDOR_ID 0xe1ec
#define FREESRP_PRODUCT_ID 0xf5d0
#define FX3_VENDOR_ID 0x04b4
#define FX3_PRODUCT_ID 0x00f3

#define FREESRP_USB_TIMEOUT 4000

#define FREESRP_FPGA_UART_OUT 0x01
#define FREESRP_FPGA_UART_IN 0x81
#define FREESRP_TX_OUT 0x02
#define FREESRP_RX_IN 0x82

#define FREESRP_USB_CTRL_SIZE 64
#define FREESRP_UART_BUF_SIZE 16

#define FREESRP_BYTES_PER_SAMPLE 4

#define FREESRP_RX_TX_BUF_SIZE 1024 * 64
#define FREESRP_TX_BUF_SIZE 1024 * 32
#define FREESRP_RX_TX_TRANSFER_QUEUE_SIZE 128

#define FREESRP_RX_TX_QUEUE_SIZE FREESRP_RX_TX_BUF_SIZE * FREESRP_RX_TX_TRANSFER_QUEUE_SIZE

// FreeSRP vendor commands
#define FREESRP_GET_VERSION_REQ 0
#define FREESRP_FPGA_CONFIG_LOAD 0xB2
#define FREESRP_FPGA_CONFIG_STATUS 0xB1
#define FREESRP_FPGA_CONFIG_FINISH 0xB3


namespace FreeSRP
{
    struct rx_tx_buf
    {
        unsigned int size;
        std::array<unsigned char, FREESRP_RX_TX_BUF_SIZE> data;
    };

    struct sample
    {
        int16_t i;
        int16_t q;
    };

    typedef std::array<unsigned char, FREESRP_UART_BUF_SIZE> cmd_buf;

    class ConnectionError: public std::runtime_error
    {
    public:
        ConnectionError(std::string const& msg) : std::runtime_error(msg)
        {}
    };

    enum command_id
    {
        GET_REGISTER, 			/* 00: [UINT16_T] -> [UINT8_T] */
        GET_TX_LO_FREQ, 		/* 01:            -> [UINT64_T] */
        SET_TX_LO_FREQ, 		/* 02: [UINT64_T] -> [UINT64_T] */
        GET_TX_SAMP_FREQ, 		/* 03:            -> [UINT32_T] */
        SET_TX_SAMP_FREQ, 		/* 04: [UINT32_T] -> [UINT32_T] */
        GET_TX_RF_BANDWIDTH, 	/* 05:            -> [UINT32_T] */
        SET_TX_RF_BANDWIDTH, 	/* 06: [UINT32_T] -> [UINT32_T] */
        GET_TX_ATTENUATION, 	/* 07:            -> [UINT32_T] */
        SET_TX_ATTENUATION, 	/* 08: [UINT32_T] -> [UINT32_T] */
        GET_TX_FIR_EN, 			/* 09:            -> [UINT8_T] */
        SET_TX_FIR_EN, 			/* 10: [UINT8_T]  -> [UINT8_T] */
        GET_RX_LO_FREQ, 		/* 11:            -> [UINT64_T] */
        SET_RX_LO_FREQ, 		/* 12: [UINT64_T] -> [UINT64_T] */
        GET_RX_SAMP_FREQ, 		/* 13:            -> [UINT32_T] */
        SET_RX_SAMP_FREQ, 		/* 14: [UINT32_T] -> [UINT32_T] */
        GET_RX_RF_BANDWIDTH, 	/* 15:            -> [UINT32_T] */
        SET_RX_RF_BANDWIDTH, 	/* 16: [UINT32_T] -> [UINT32_T] */
        GET_RX_GC_MODE, 		/* 17:            -> [UINT8_T] */
        SET_RX_GC_MODE, 		/* 18: [UINT8_T]  -> [UINT8_T] */
        GET_RX_RF_GAIN,			/* 19:            -> [INT32_T] */
        SET_RX_RF_GAIN, 		/* 20: [INT32_T]  -> [INT32_T] */
        GET_RX_FIR_EN, 			/* 21:            -> [UINT8_T] */
        SET_RX_FIR_EN, 			/* 22: [UINT8_T]  -> [UINT8_T] */
        SET_DATAPATH_EN, 		/* 23: [UINT8_T]  -> [UINT8_T] */
        GET_FPGA_VERSION,       /* 24:            -> [UINT64_T] */
        SET_LOOPBACK_EN,        /* 25: [UINT8_T]  -> [UINT8_T] */
    };

    enum command_err
    {
        CMD_OK = 0,
        CMD_INVALID_PARAM,
        CMD_ENSM_ERR
    };

    enum gainctrl_mode
    {
        RF_GAIN_MGC = 0,        // Manual
        RF_GAIN_FASTATTACK_AGC, // AGC: Fast attack
        RF_GAIN_SLOWATTACK_AGC, // AGC: Slow attack
        RF_GAIN_HYBRID_AGC      // AGC: Hybrid
    };

    enum fpga_status
    {
        FPGA_CONFIG_DONE = 0,
        FPGA_CONFIG_ERROR,
        FPGA_CONFIG_SKIPPED
    };

    struct freesrp_version
    {
        std::string fx3;
        std::string fpga;

        friend std::ostream &operator<<(std::ostream &o, const freesrp_version v)
        {
            return o << "FX3 v" << v.fx3 << ", FPGA v" << v.fpga;
        }
    };

    struct command
    {
        command_id cmd;
        uint64_t param;

        friend std::ostream &operator<<(std::ostream &o, const command cmd)
        {
            return o << "command ID: " << cmd.cmd << "; parameter: " << cmd.param;
        }
    };

    struct response
    {
        command_id cmd;
        uint64_t param;
        command_err error;

        friend std::ostream &operator<<(std::ostream &o, const response res)
        {
            if(res.error == CMD_OK)
            {
                o << "command ID: " << res.cmd << "; parameter: " << res.param;
            }
            else
            {
                o << "command ID: " << res.cmd << "; error code: " << res.error;
            }
            return o;
        }
    };

    class FreeSRP
    {
	class impl;
	std::unique_ptr<impl> _impl;
	
    public:

	//! FreeSRP constructor.
	/*!
	 * Will attempt to find and connect to a FreeSRP and throw a ConnectionError if no FreeSRP
         * can be found or there is an error while communicating with it.
	 * \param serial_number: If specified, will try to connect to a FreeSRP that that contains
         *                       serial_number as a substring of or matches its serial number
	 */
        FreeSRP(std::string serial_number = "");

        ~FreeSRP();

	//! List serial numbers of all connected FreeSRPs
	/*!
	 * \return An std::vector containing the serial numbers of all available devices
	 */
	static std::vector<std::string> list_connected();

	//! Check if the FPGA has been loaded.
	/*!
         * \return true if the FPGA is configured, false if configuration is still needed.
         */
        bool fpga_loaded();

	//! Load the FPGA with the specified bitstream.
	/*!
         * \param filename: The filename of the bitstream to load onto the FPGA.
         * \returns An fpga_status value indicating wether the FPGA was successfully configured.
         */
        fpga_status load_fpga(std::string filename);

	//! Start receiving samples.
	/*!
	 * \param rx_callback: Optionally, specify a function to be called once a new sample buffer is available.
         */
        void start_rx(std::function<void(const std::vector<sample> &)> rx_callback = {});

	//! Stop receiving samples.
	/*!
	 *
	 */
        void stop_rx();

	//! Start transmitting samples.
	/*!
	 * \param tx_callback: Optionaly, specify a function to be called once a new sample buffer is available.
         */
        void start_tx(std::function<void(std::vector<sample> &)> tx_callback = {});

	//! Stop transmitting samples.
        void stop_tx();

	//! Check how many received samples are available.
	/*!
	 * Note: samples will not be written to the main buffer if a callback is specified in start_rx.
	 * \returns Number of samples available to read from the buffer.
	 */
        unsigned long available_rx_samples();

	//! Get sample from queue.
	/*
	 * Note: samples will only be available if no callback if specified in start_rx.
	 * \param s: A reference to the sample to be read.
         * \returns: true if a sample was read, false if the queue is empty.
	 */
        bool get_rx_sample(sample &s);

	//! Add a sample to the transmitter queue.
	/*!
	 * \param s: the sample to add to the transmitter queue
         * \returns: true if the sample was successfully added to the queue, false if the queue is full.
	 */
        bool submit_tx_sample(sample &s);

	//! Helper function to generate a FreeSRP::command
	/*!
         * \param command_id: the ID of the desired command
	 * \param param: Value of the parameter. Meaning varies depending on the command associated with this value.
	 * \returns The command.
	 */
        command make_command(command_id id, double param) const;

	//! Send a command to the FreeSRP
	/*!
	 * Note: this call will block until a response from the FreeSRP is received back.
	 * \param c: The command to send (see also make_command)
	 * \returns The response from the FreeSRP
	 */
        response send_cmd(command c) const;

	//! Get version information about the FreeSRP
	/*!
	 * \returns Version information the FreeSRP responded with.
	 */
        freesrp_version version();
    };

    namespace Util
    {
        //! This will look for an FX3 in bootloader mode.
	/*!
         * \param upload_firmware: If 'false', this function will return 'true' if an unprogrammed FX3 is found.
         *                          If 'true', it will attempt to program the FX3 with the specified firmware.
         * \param filename: Path to the image file to program the FX3 with.
         */
        bool find_fx3(bool upload_firmware=false, std::string filename="");
    };
}

#endif