GNU Radio's GNMAX2769 Package
gnmax.h
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------------------------*/
2 /*! \file gnmax.h
3 //
4 // FILENAME: gnmax.h
5 //
6 // DESCRIPTION: Defines the GN3S class.
7 //
8 // DEVELOPERS: Gregory W. Heckler (2003-2009)
9 // Wojciech Kazubski (2019)
10 //
11 // LICENSE TERMS: Copyright (c) Gregory W. Heckler 2009
12 // Copyright (c) Wojciech Kazubski 2019
13 //
14 // This file is based on gn3s.h file, a part of GN3S driver for gnss-sdr project
15 //
16 // This file is part of the GPS Software Defined Radio (GPS-SDR)
17 //
18 // The GPS-SDR is free software; you can redistribute it and/or modify it under the terms of the
19 // GNU General Public License as published by the Free Software Foundation; either version 2 of
20 // the License, or (at your option) any later version. The GPS-SDR is distributed in the hope that
21 // it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
22 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
23 // more details.
24 //
25 // Note: Comments within this file follow a syntax that is compatible with
26 // DOXYGEN and are utilized for automated document extraction
27 //
28 // Reference:
29 */
30 /*----------------------------------------------------------------------------------------------*/
31 
32 
33 #ifndef GNMAX_H_
34 #define GNMAX_H_
35 
36 #include "gnmax_defines.h"
37 
38 /* Includes */
39 /*--------------------------------------------------------------*/
40 #include <unistd.h>
41 #include <stdio.h>
42 #include <errno.h>
43 #include <string.h>
44 #include <math.h>
45 #include <libusb.h>
46 /*--------------------------------------------------------------*/
47 
48 
49 /* FX2 Stuff */
50 /*--------------------------------------------------------------*/
51 #define RX_ENDPOINT (0x86)
52 #define VRT_VENDOR_IN (0xC0)
53 #define VRT_VENDOR_OUT (0x40)
54 #define RX_INTERFACE (2)
55 #define RX_ALTINTERFACE (0)
56 #define VRQ_XFER (0x01)
57 #define VRQ_ENABLE (0x10)
58 #define VRQ_WRITE_CMD (0x20)
59 #define VRQ_GET_STATUS (0x80)
60 #define GS_RX_OVERRUN (1) //!< Returns 1 byte
61 /*--------------------------------------------------------------*/
62 
63 
64 /* GN3S Stuff */
65 /*--------------------------------------------------------------*/
66 #define GN3S_VID (0x1781)
67 #define GN3S_PID (0x0B3C)
68 #define PROG_SET_CMD (0xE600)
69 #define USB_BUFFER_SIZE (65536)
70 #define USB_BLOCK_SIZE (512)
71 #define USB_NBLOCKS (USB_BUFFER_SIZE / USB_BLOCK_SIZE)
72 #define USB_NTRANSFERS (16)
73 #define USB_TIMEOUT (1000)
74 /*--------------------------------------------------------------*/
75 
76 #define DEBUG 0
77 
78 /*--------------------------------------------------------------*/
79 /*! \ingroup CLASSES
80  *
81  */
82 class gnmax
83 {
84 
85  private:
86 
87  /* First or second board */
88  int which;
89 
90  /* GN3S FX2 Stuff */
91  struct libusb_device *fx2_device;
92  struct libusb_device_handle *fx2_handle;
93  struct libusb_transfer *transfer[USB_NTRANSFERS];
94 
95  /* USB Stuff */
96  libusb_context *ctx = nullptr;
97 
98  struct libusb_device* usb_fx2_find(int vid, int pid);
99  bool usb_fx2_configure();
100  bool max2769_configure(gnmax_settings settings);
101  bool usb_fx2_start_transfers();
102  bool usb_fx2_cancel_transfers();
103  bool send_rx_cmd(char VRQ_TYPE, int start);
104  bool get_rx_status(int which, bool *trouble);
105  void set_bias_bit(int bias);
106  void set_ant_bit(int ant);
107  void set_freq_bit(int freq);
108  void set_bw_bit(int bw, int zeroif);
109 
110  public:
111 
112  gnmax(int _which, gnmax_settings settings); //!< Constructor
113  ~gnmax(); //!< Destructor
114 
115  /* FX2 functions */
116  int read(unsigned char *buff, int bytes);
117  int write_cmd(int request, int value, int index, unsigned char *bytes, int len);
118  bool start_xfer();
119  bool check_rx_overrun();
120  bool set_bias(int bias);
121  bool set_ant(int ant);
122  bool set_freq(int freq);
123  bool set_bw(int bw, int zeroif);
124 
125 };
126 /*--------------------------------------------------------------*/
127 
128 
129 #endif /*GNMAX_H_ */
bool set_ant(int ant)
int write_cmd(int request, int value, int index, unsigned char *bytes, int len)
#define USB_NTRANSFERS
Definition: gnmax.h:72
bool set_freq(int freq)
Definition: gnmax.h:82
Definition: gnmax_defines.h:25
gnmax(int _which, gnmax_settings settings)
Constructor.
int read(unsigned char *buff, int bytes)
bool start_xfer()
~gnmax()
Destructor.
bool set_bias(int bias)
bool set_bw(int bw, int zeroif)
bool check_rx_overrun()