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 /*--------------------------------------------------------------*/
77 /*! \ingroup CLASSES
78  *
79  */
80 class gnmax
81 {
82 
83  private:
84 
85  /* First or second board */
86  int which;
87 
88  /* GN3S FX2 Stuff */
89  struct libusb_device *fx2_device;
90  struct libusb_device_handle *fx2_handle;
91  struct libusb_transfer *transfer[USB_NTRANSFERS];
92 
93  /* USB Stuff */
94  libusb_context *ctx = nullptr;
95 
96  struct libusb_device* usb_fx2_find(int vid, int pid);
97  bool usb_fx2_configure();
98  bool max2769_configure(gnmax_settings settings);
99  bool usb_fx2_start_transfers();
100  bool usb_fx2_cancel_transfers();
101  bool send_rx_cmd(char VRQ_TYPE, int start);
102  bool get_rx_status(int which, bool *trouble);
103  void set_bias_bit(int bias);
104  void set_ant_bit(int ant);
105  void set_freq_bit(int freq);
106  void set_bw_bit(int bw, int zeroif);
107 
108  public:
109 
110  gnmax(int _which, gnmax_settings settings); //!< Constructor
111  ~gnmax(); //!< Destructor
112 
113  /* FX2 functions */
114  int read(unsigned char *buff, int bytes);
115  int write_cmd(int request, int value, int index, unsigned char *bytes, int len);
116  bool start_xfer();
117  bool check_rx_overrun();
118  bool set_bias(int bias);
119  bool set_ant(int ant);
120  bool set_freq(int freq);
121  bool set_bw(int bw, int zeroif);
122 
123 };
124 /*--------------------------------------------------------------*/
125 
126 
127 #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:80
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()