├── .gitignore ├── AUTHORS ├── COPYING ├── Common ├── DongleArrays.h ├── MyMutex.h ├── Recognized Dongles.h ├── SharedMemoryFile.cpp └── SharedMemoryFile.h ├── IRtlSdr.h ├── ITuner.h ├── README ├── ReadMe.txt ├── RtlSdr Catalog ├── DongleListMaint.cpp ├── DongleListMaint.h ├── IRtlSdr.h ├── InvisibleWnd.cpp ├── InvisibleWnd.h ├── LoadDongle.cpp ├── LoadDongle.h ├── MyCommandLineInfo.cpp ├── MyCommandLineInfo.h ├── ReadMe.txt ├── RtlSdr Catalog.vcxproj ├── RtlSdr Catalog.vcxproj.filters ├── RtlSdrList.cpp ├── RtlSdrList.h ├── RtlSdr_Catalog.cpp ├── RtlSdr_Catalog.h ├── RtlSdr_Catalog.rc ├── RtlSdr_CatalogDlg.cpp ├── RtlSdr_CatalogDlg.h ├── SystemTray.cpp ├── SystemTray.h ├── TrayIconManager.cpp ├── TrayIconManager.h ├── res │ ├── RtlSdr_Catalog.ico │ └── RtlSdr_Catalog.rc2 ├── resource.h ├── stdafx.cpp ├── stdafx.h └── targetver.h ├── User Notes.txt ├── dllmain.cpp ├── librtlsdr.cpp ├── librtlsdr.h ├── librtlsdr_dongle_comms.cpp ├── librtlsdr_dongle_comms.h ├── librtlsdr_registryAndNames.cpp ├── librtlsdr_registryAndNames.h ├── libusb ├── MS32 │ ├── dll │ │ └── libusb-1.0.lib │ └── static │ │ └── libusb-1.0.lib ├── MS64 │ ├── dll │ │ └── libusb-1.0.lib │ └── static │ │ └── libusb-1.0.lib └── libusb.h ├── resource.h ├── rtl-sdr.h ├── rtl-sdr_export.h ├── rtlsdr.rc ├── rtlsdr_app.cpp ├── rtlsdr_app.h ├── rtsdr.sln ├── rtsdr.vcxproj ├── rtsdr.vcxproj.filters ├── stdafx.cpp ├── stdafx.h ├── targetver.h ├── tuner_Dummy.h ├── tuner_e4k.cpp ├── tuner_e4k.h ├── tuner_fc0012.cpp ├── tuner_fc0012.h ├── tuner_fc0013.cpp ├── tuner_fc0013.h ├── tuner_fc2580.cpp ├── tuner_fc2580.h ├── tuner_r82xx.cpp └── tuner_r82xx.h /.gitignore: -------------------------------------------------------------------------------- 1 | *.obj 2 | *.tlog 3 | *.sbd 4 | *.pc 5 | /rtsdr.sdf 6 | /rtsdr.vcxproj.user 7 | /rtsdr.opensdf 8 | /libusb/MS32/dll 9 | /libusb/MS64/dll/libusb-1.0.pdb 10 | /libusb/MS64/dll/libusb-1.0.dll 11 | /rtsdr.sln.docstates.suo 12 | /rtsdr.suo 13 | /ipch 14 | /x64 15 | /x64/debug 16 | /x64/Release 17 | /x64/Release/*.tlog 18 | /Win32 19 | /Win32/Debug 20 | /Win32/Release 21 | Release 22 | Debug 23 | */Debug/* 24 | */Release/* 25 | /RtlSdr Catalog/x86 26 | /RtlSdr Catalog/x64 27 | /x86 28 | /RtlSdr++ Distribution 29 | /*.zip 30 | /rtlsdr.aps 31 | /*.aps 32 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Steve Markgraf 2 | Dimitri Stolnikov 3 | Hoernchen 4 | Kyle Keen 5 | Oliver Jowette 6 | Leif Asbrink 7 | Joanne Dow 8 | -------------------------------------------------------------------------------- /Common/DongleArrays.h: -------------------------------------------------------------------------------- 1 | // DongleArrays.h 2 | 3 | #pragma once 4 | 5 | #define MAX_USB_PATH 7 6 | #define MAX_STR_SIZE 256 7 | 8 | class Dongle; 9 | 10 | class Return 11 | { 12 | public: 13 | Return() {} 14 | 15 | Return( const Return& r ) 16 | { 17 | *this = r; 18 | } 19 | 20 | void operator = ( const Return& r ) 21 | { 22 | memcpy( manfIdStr, r.manfIdStr, sizeof( Return )); 23 | } 24 | 25 | // As = except Does not overwrite string4, the usbpath 26 | void operator += ( const Return& r ) 27 | { 28 | memcpy( manfIdStr, r.manfIdStr, 3 * sizeof( manfIdStr )); 29 | vid = r.vid; 30 | pid = r.pid; 31 | duplicated = r.duplicated; 32 | busy = r.busy; 33 | found = r.found; 34 | Spare = r.Spare; 35 | tunerType = r.tunerType; 36 | } 37 | 38 | void operator = ( const Dongle& d ); 39 | 40 | // Make sure these are all null terminated. 41 | BYTE manfIdStr[ MAX_STR_SIZE ]; // Null terminated Manufacturer ID string 42 | BYTE prodIdStr[ MAX_STR_SIZE ]; // Null terminated Product ID string 43 | BYTE sernIdStr[ MAX_STR_SIZE ]; // Null terminated Serial Number ID string 44 | WORD vid; // Vendor ID word 45 | WORD pid; // Product ID word. 46 | BYTE usbpath[ MAX_USB_PATH ]; // Stores USB path through hubs to device 47 | bool duplicated; // LibUsb index for this device. 48 | BYTE busy; // Maintain file format. 49 | BYTE found; 50 | BYTE Spare; 51 | BYTE tunerType; // Type of tuner per enum rtlsdr_tuner 52 | }; 53 | 54 | class Dongle 55 | { 56 | public: 57 | Dongle() 58 | { 59 | busy = false; 60 | vid = 0; 61 | pid = 0; 62 | found = false; 63 | duplicated = false; 64 | } 65 | 66 | void Clear( void ) 67 | { 68 | busy = 0; 69 | vid = 0; 70 | pid = 0; 71 | tunerType = 0; 72 | found = -1; 73 | duplicated = false; 74 | memset( manfIdStr, 0, MAX_STR_SIZE ); 75 | memset( prodIdStr, 0, MAX_STR_SIZE ); 76 | memset( sernIdStr, 0, MAX_STR_SIZE ); 77 | memset( usbpath, 0, sizeof( usbpath )); 78 | } 79 | 80 | Dongle( const Dongle& d ) 81 | { 82 | *this = d; 83 | } 84 | 85 | Dongle( const Return& r ) 86 | { 87 | *this = r; 88 | } 89 | 90 | void operator = ( const Return& r ) 91 | { 92 | busy = r.busy != 0; // Determined other ways. 93 | found = r.found; 94 | vid = r.vid; 95 | pid = r.pid; 96 | tunerType = r.tunerType; 97 | found = -1; 98 | duplicated = r.duplicated; 99 | memcpy( &manfIdStr, r.manfIdStr, MAX_STR_SIZE ); 100 | memcpy( &prodIdStr, r.prodIdStr, MAX_STR_SIZE ); 101 | memcpy( &sernIdStr, r.sernIdStr, MAX_STR_SIZE ); 102 | memcpy( usbpath, r.usbpath, sizeof( usbpath )); 103 | } 104 | 105 | bool operator == ( const Dongle& d ) const 106 | { 107 | if ( busy || d.busy ) 108 | { 109 | // Make a best guess. If it's in the same slot it's the same thing. 110 | // This is the best guess I can make. 111 | return ( memcmp( &usbpath, &d.usbpath, sizeof( usbpath )) == 0 ) 112 | && ( vid == d.vid ) 113 | && ( pid == d.pid ) 114 | ; 115 | } 116 | else 117 | { 118 | return ( strcmp( manfIdStr, d.manfIdStr ) == 0 ) 119 | && ( strcmp( prodIdStr, d.prodIdStr ) == 0 ) 120 | && ( strcmp( sernIdStr, d.sernIdStr ) == 0 ) 121 | && ( vid == d.vid ) 122 | && ( pid == d.pid ) 123 | ; 124 | } 125 | } 126 | 127 | bool operator != ( const Dongle& d ) const 128 | { 129 | return !( *this == d ); 130 | } 131 | 132 | char manfIdStr[ MAX_STR_SIZE ]; // Null terminated Manufacturer ID string 133 | char prodIdStr[ MAX_STR_SIZE ]; // Null terminated Product ID string 134 | char sernIdStr[ MAX_STR_SIZE ]; // Null terminated Serial Number ID string 135 | WORD vid; // Manufacturer ID word 136 | WORD pid; // Product ID word. 137 | BYTE usbpath[ 7 ]; // Stores USB path through hubs to device 138 | bool busy; // Device is busy if true. 139 | BYTE tunerType; // Type of tuner per enum rtlsdr_tuner 140 | char found; // RTLSDR index for merging data 141 | bool duplicated; // Is this entry a name duplicate? 142 | }; 143 | 144 | __inline void Return::operator = ( const Dongle& d ) 145 | { 146 | memset( &manfIdStr, 0, sizeof( Return )); 147 | vid = d.vid; 148 | pid = d.pid; 149 | busy = d.busy; 150 | found = d.found; 151 | Spare = 0; 152 | tunerType = d.tunerType; 153 | duplicated = d.duplicated; 154 | 155 | memcpy( manfIdStr, d.manfIdStr, MAX_STR_SIZE ); 156 | memcpy( prodIdStr, d.prodIdStr, MAX_STR_SIZE ); 157 | memcpy( sernIdStr, d.sernIdStr, MAX_STR_SIZE ); 158 | memcpy( usbpath, d.usbpath, MAX_USB_PATH ); 159 | } 160 | 161 | class CDongleArray : public CArray< Dongle, Dongle > 162 | { 163 | public: 164 | CDongleArray() {} 165 | 166 | void operator = ( const CDongleArray& da ) 167 | { 168 | RemoveAll(); 169 | for( INT_PTR i = 0; i < da.GetSize(); i++ ) 170 | Add( da.GetAt( i )); 171 | } 172 | 173 | void operator += (const CDongleArray& da ) 174 | { 175 | for( INT_PTR i = 0; i < da.GetSize(); i++ ) 176 | { 177 | INT_PTR j = 0; 178 | for ( ; j < GetSize(); j++ ) 179 | { 180 | if ( GetAt( j ) == da.GetAt( i )) 181 | break; 182 | } 183 | if ( j >= GetSize()) 184 | Add( da.GetAt( i )); 185 | } 186 | } 187 | 188 | INT_PTR Add( const Dongle& dongle ) 189 | { 190 | // Look for a duplicate already present. 191 | for ( INT_PTR entry = 0; entry < GetSize(); entry++ ) 192 | { 193 | if ( dongle == GetAt( entry )) 194 | return entry; 195 | } 196 | return __super::Add( dongle ); 197 | } 198 | 199 | void SetAllNotFound( void ) 200 | { 201 | for ( INT_PTR i = 0; i < GetSize(); i++ ) 202 | { 203 | GetAt( i ).found = -1; 204 | } 205 | } 206 | 207 | // For this one we do not sort or any of the other nifty stuff. 208 | }; 209 | -------------------------------------------------------------------------------- /Common/MyMutex.h: -------------------------------------------------------------------------------- 1 | // MyMutex.h Wrapped CMutex with automatic locking. 2 | // 3 | #pragma once 4 | 5 | class CMyMutex : public CMutex 6 | { 7 | public: 8 | CMyMutex() 9 | : CMutex() 10 | { 11 | } 12 | CMyMutex( LPCTSTR in_name ) 13 | : CMutex( FALSE, in_name ) 14 | { 15 | } 16 | 17 | virtual ~CMyMutex() {} 18 | }; 19 | 20 | class CMutexLock 21 | { 22 | public: 23 | CMutexLock( CMyMutex* mutex ) 24 | { 25 | m_oMutex = mutex; 26 | mutex->Lock(); 27 | } 28 | 29 | CMutexLock( CMyMutex& mutex ) 30 | : m_oMutex( &mutex ) 31 | { 32 | mutex.Lock(); 33 | } 34 | 35 | virtual ~CMutexLock() 36 | { 37 | m_oMutex->Unlock(); 38 | } 39 | 40 | CMyMutex * m_oMutex; 41 | }; -------------------------------------------------------------------------------- /Common/Recognized Dongles.h: -------------------------------------------------------------------------------- 1 | // Recognized Dongles.h 2 | 3 | #pragma once 4 | 5 | // This is the structure defining the recognition data and device 6 | // name for the various dongle types rtlsdr.dll recognizes and can 7 | // properly manipulate. 8 | 9 | typedef struct rtlsdr_dongle 10 | { 11 | uint16_t vid; 12 | uint16_t pid; 13 | const char *name; 14 | const char *manfname; 15 | const char *prodname; 16 | } rtlsdr_dongle_t; 17 | 18 | extern const rtlsdr_dongle_t known_devices[]; 19 | #if defined( LIBSDRNAMES ) 20 | /* 21 | * Please add your device here and send a patch to osmocom-sdr@lists.osmocom.org 22 | */ 23 | const rtlsdr_dongle_t known_devices[] = 24 | { 25 | { 0x0bda, 0x2832, "* Generic RTL2832U" 26 | , "Generic", "RTL2832U" }, 27 | { 0x0bda, 0x2838, "* Generic RTL2832U OEM" 28 | , "Generic", "RTL2832U OEM" }, 29 | { 0x0413, 0x6680, "* DigitalNow Quad DVB-T PCI-E card" 30 | , "DigitalNow", "Quad DVB-T PCI-E card" }, 31 | { 0x0413, 0x6f0f, "* Leadtek WinFast DTV Dongle mini D" 32 | , "Leadtek", "WinFast DTV Dongle mini D" }, 33 | { 0x0458, 0x707f, "* Genius TVGo DVB-T03 USB dongle (Ver. B)" 34 | , "Genius", "TVGo DVB-T03 USB dongle (Ver. B)" }, 35 | { 0x0ccd, 0x00a9, "* Terratec Cinergy T Stick Black (rev 1)" 36 | , "Terratec", "Cinergy T Stick Black (rev 1)" }, 37 | { 0x0ccd, 0x00b3, "* Terratec NOXON DAB/DAB+ USB dongle (rev 1)" 38 | , "Terratec", "NOXON DAB/DAB+ USB dongle (rev 1)" }, 39 | { 0x0ccd, 0x00b4, "* Terratec Deutschlandradio DAB Stick" 40 | , "Terratec", "Deutschlandradio DAB Stick" }, 41 | { 0x0ccd, 0x00b5, "* Terratec NOXON DAB Stick - Radio Energy" 42 | , "* Terratec", "NOXON DAB Stick - Radio Energy" }, 43 | { 0x0ccd, 0x00b7, "* Terratec Media Broadcast DAB Stick" 44 | , "Terratec", "Media Broadcast DAB Stick" }, 45 | { 0x0ccd, 0x00b8, "* Terratec BR DAB Stick" 46 | , "Terratec", "BR DAB Stick" }, 47 | { 0x0ccd, 0x00b9, "* Terratec WDR DAB Stick" 48 | , "Terratec", "WDR DAB Stick" }, 49 | { 0x0ccd, 0x00c0, "* Terratec MuellerVerlag DAB Stick" 50 | , "Terratec", "MuellerVerlag DAB Stick" }, 51 | { 0x0ccd, 0x00c6, "* Terratec Fraunhofer DAB Stick" 52 | , "Terratec", "Fraunhofer DAB Stick" }, 53 | { 0x0ccd, 0x00d3, "* Terratec Cinergy T Stick RC (Rev.3)" 54 | , "Terratec", "Cinergy T Stick RC (Rev.3)" }, 55 | { 0x0ccd, 0x00d7, "* Terratec T Stick PLUS" 56 | , "Terratec", "T Stick PLUS" }, 57 | { 0x0ccd, 0x00e0, "* Terratec NOXON DAB/DAB+ USB dongle (rev 2)" 58 | , "Terratec", "NOXON DAB/DAB+ USB dongle (rev 2)" }, 59 | { 0x1554, 0x5020, "* PixelView PV-DT235U(RN)" 60 | , "PixelView", "PV-DT235U(RN)" }, 61 | { 0x15f4, 0x0131, "* Astrometa DVB-T/DVB-T2" 62 | , "Astrometa", "DVB-T/DVB-T2" }, 63 | { 0x15f4, 0x0133, "* HanfTek DAB+FM+DVB-T" 64 | , "HanfTek", "DAB+FM+DVB-T" }, 65 | { 0x185b, 0x0620, "* Compro Videomate U620F" 66 | , "Compro", "Videomate U620F"}, 67 | { 0x185b, 0x0650, "* Compro Videomate U650F" 68 | , "Compro", "Videomate U650F"}, 69 | { 0x185b, 0x0680, "* Compro Videomate U680F" 70 | , "Compro", "Videomate U680F"}, 71 | { 0x1b80, 0xd393, "* GIGABYTE GT-U7300" 72 | , "GIGABYTE", "GT-U7300" }, 73 | { 0x1b80, 0xd394, "* DIKOM USB-DVBT HD" 74 | , "DIKOM", "USB-DVBT HD" }, 75 | { 0x1b80, 0xd395, "* Peak 102569AGPK" 76 | , "Peak", "102569AGPK" }, 77 | { 0x1b80, 0xd397, "* KWorld KW-UB450-T USB DVB-T Pico TV" 78 | , "KWorld", "KW-UB450-T USB DVB-T Pico TV" }, 79 | { 0x1b80, 0xd398, "* Zaapa ZT-MINDVBZP" 80 | , "Zaapa", "ZT-MINDVBZP" }, 81 | { 0x1b80, 0xd39d, "* SVEON STV20 DVB-T USB & FM" 82 | , "SVEON", "STV20 DVB-T USB & FM" }, 83 | { 0x1b80, 0xd3a4, "* Twintech UT-40" 84 | , "Twintech", "UT-40" }, 85 | { 0x1b80, 0xd3a8, "* ASUS U3100MINI_PLUS_V2" 86 | , "ASUS", "U3100MINI_PLUS_V2" }, 87 | { 0x1b80, 0xd3af, "* SVEON STV27 DVB-T USB & FM" 88 | , "SVEON", "STV27 DVB-T USB & FM" }, 89 | { 0x1b80, 0xd3b0, "* SVEON STV21 DVB-T USB & FM" 90 | , "SVEON", "STV21 DVB-T USB & FM" }, 91 | { 0x1d19, 0x1101, "* Dexatek DK DVB-T Dongle (Logilink VG0002A)" 92 | , "Dexatek", "DK DVB-T Dongle (Logilink VG0002A)" }, 93 | { 0x1d19, 0x1102, "* Dexatek DK DVB-T Dongle (MSI DigiVox mini II V3.0)" 94 | , "Dexatek", "DK DVB-T Dongle (MSI DigiVox mini II V3.0)" }, 95 | { 0x1d19, 0x1103, "* Dexatek Technology Ltd. DK 5217 DVB-T Dongle" 96 | , "Dexatek", "Technology Ltd. DK 5217 DVB-T Dongle" }, 97 | { 0x1d19, 0x1104, "* MSI DigiVox Micro HD" 98 | , "MSI", "DigiVox Micro HD" }, 99 | { 0x1f4d, 0xa803, "* Sweex DVB-T USB" 100 | , "Sweex", "DVB-T USB" }, 101 | { 0x1f4d, 0xb803, "* GTek T803" 102 | , "GTek", "T803" }, 103 | { 0x1f4d, 0xc803, "* Lifeview LV5TDeluxe" 104 | , "Lifeview", "LV5TDeluxe" }, 105 | { 0x1f4d, 0xd286, "* MyGica TD312" 106 | , "MyGica", "TD312" }, 107 | { 0x1f4d, 0xd803, "* PROlectrix DV107669" 108 | , "PROlectrix", "DV107669" }, 109 | }; 110 | #endif 111 | -------------------------------------------------------------------------------- /Common/SharedMemoryFile.cpp: -------------------------------------------------------------------------------- 1 | #include "StdAfx.h" 2 | #include "SharedMemoryFile.h" 3 | #include 4 | 5 | #define NEED_MORE_INFO 6 | 7 | RtlSdrAreaDef TestDongles = 8 | { 9 | { 'R', 'T', 'L', '-', 'S', 'D', 'R', 0 }, 10 | false, false, 11 | 32, 0 12 | }; 13 | 14 | SharedMemoryFile::SharedMemoryFile( void ) 15 | : active( false ) 16 | , sharedHandle( NULL ) 17 | , sharedMem( NULL ) 18 | { 19 | Init(); 20 | } 21 | 22 | 23 | SharedMemoryFile::~SharedMemoryFile( void ) 24 | { 25 | TRACE( "~SharedMemoryFile: 0x%x ~SharedMemoryFile with ( 0x%x, 0x%x )\n", this, sharedMem, sharedHandle ); 26 | if ( sharedMem != NULL ) // have a shared area mapped? 27 | UnmapViewOfFile( sharedMem ); // unmap it 28 | sharedMem = NULL; // and forget it 29 | if ( sharedHandle != NULL ) // have a shared area? 30 | CloseHandle( sharedHandle ); // close it 31 | sharedHandle = NULL; // and forget it 32 | } 33 | 34 | bool SharedMemoryFile::Init( void )//* sysRef) 35 | { 36 | TRACE("0x%x SharedMemoryFile::Init\n", this ); 37 | 38 | #if defined( NEED_MORE_INFO ) 39 | TCHAR namebuf [256]; 40 | 41 | if (!GetModuleFileName( NULL, namebuf, sizeof namebuf )) 42 | TRACE("0x%x SharedMemoryFile unable to get name of caslling process!\n", this ); 43 | else 44 | { 45 | TRACE( _T( "0x%x SharedMemoryFile process %d (0x%X) is \"%s\"\n" ), this, 46 | GetCurrentProcessId(), GetCurrentProcessId(), namebuf); 47 | } 48 | #endif 49 | 50 | // This is ASIOInit, except that we only get the sysRef part of the 51 | // ASIODriverInfo structure. Note that we have to exist at the time this 52 | // function is called, so previous magic of some sort has caused us to 53 | // come into existance. 54 | // 55 | // The spec does NOT define what to do here if we have already been 56 | // initialized, nor if we are currently running. It might be reasonable 57 | // to tear down any structure and start over from scratch. But that is 58 | // not what the sample driver does. It just returns true. 59 | // 60 | // NOTE that this is about the only ASIO function that does not return 61 | // an ASIOError value! 62 | 63 | if ( active ) // already initialized? 64 | return true; // just ignore this attempt! 65 | 66 | // Creating the shared area will create the input and output structures 67 | // and hook up the various pointers. 68 | 69 | if ( !CreateSharedArea()) 70 | return false; 71 | 72 | active = true; // we are open for business! 73 | 74 | // Since we are returning true we do not need to set up the 75 | // error message value as it will never be referenced. 76 | 77 | return true; 78 | } 79 | 80 | 81 | 82 | //------------------------------------------------------------------------------------------ 83 | // Master setup function called from ASIOInit to set up for master operation. 84 | 85 | bool SharedMemoryFile::CreateSharedArea( void ) 86 | { 87 | alreadyexisted = false; 88 | // This is part of ASIOInit. We are setting up to be the master. 89 | // 90 | // Create the shared area, set up the basic information in the bottom of 91 | // the area, and set up the channel structures. Do this all in an order 92 | // that will prevent a user falling into a hole if he tries to open while 93 | // we are doing the setup. 94 | 95 | TRACE( "0x%x->SharedMemoryFile CreateSharedArea\n", this ); 96 | 97 | if ( sharedHandle != NULL || sharedMem != NULL ) 98 | { 99 | TRACE( "0x%x Shared area already open!\n", this ); 100 | return false; // looks like we are already open! 101 | } 102 | 103 | // First determine how big the shared area needs to be. 104 | 105 | int size = sizeof ( RtlSdrAreaDef ); 106 | 107 | // Now try to create the area. 108 | // Return value 109 | // If the function succeeds, the return value is a handle to the newly 110 | // created file mapping object. 111 | 112 | // If the object exists before the function call, the function returns a 113 | // handle to the existing object (with its current size, not the specified 114 | // size), and GetLastError returns ERROR_ALREADY_EXISTS. 115 | 116 | HANDLE area = CreateFileMapping( INVALID_HANDLE_VALUE// use the page file for backing 117 | , NULL // default security attributes for now 118 | , PAGE_READWRITE // protections 119 | | SEC_COMMIT // commit the pages 120 | , 0 // high DWORD of area size 121 | , size // low DWORD of area size 122 | , kSharedAreaName // the area file name 123 | ); 124 | if ( area == NULL ) 125 | { 126 | TRACE( "0x%x Shared area Create failure! %d\n", this, GetLastError()); 127 | return false; 128 | } 129 | 130 | if ( size != sizeof( RtlSdrAreaDef )) 131 | { 132 | TRACE( "0x%x Shared area existed wrong size.\n", this ); 133 | CloseHandle( area ); 134 | return false; 135 | } 136 | 137 | alreadyexisted = GetLastError() == ERROR_ALREADY_EXISTS; 138 | 139 | // We have the area open, see about mapping a view of the file. 140 | 141 | LPVOID sma = MapViewOfFile( area // shared area handle 142 | , FILE_MAP_ALL_ACCESS 143 | , 0 // base offset high DWORD 144 | , 0 // base offset low DWORD 145 | , 0 // map the entire file 146 | ); 147 | if ( sma == NULL ) 148 | { 149 | CloseHandle( area ); 150 | TRACE( "0x%x Shared area Mapping failure!\n", this ); 151 | return false; 152 | } 153 | 154 | sharedMem = (RtlSdrAreaDef*) sma; 155 | sharedHandle = area; // return sharead area handle too 156 | if ( alreadyexisted ) 157 | { 158 | TRACE( "0x%x Shared area already existed\n", this ); 159 | // check validity 160 | if ( strcmp( sharedMem->validityKey, kValidityKey ) != 0 ) 161 | { 162 | TRACE( "0x%x Shared memory found but not valid\n", this ); 163 | // Force valid for now. 164 | memset( sma, 0, sizeof( sma )); 165 | strcpy_s( sharedMem->validityKey, kValidityKey ); 166 | sharedMem->numEntries = 32; 167 | } 168 | } 169 | else 170 | { 171 | TRACE( "0x%x New shared area\n", this ); 172 | // Initialize 173 | memset( sma, 0, sizeof( sma )); 174 | strcpy_s( sharedMem->validityKey, kValidityKey ); 175 | sharedMem->numEntries = 32; 176 | sharedMem->MasterPresent = false; 177 | sharedMem->MasterUpdate = false; 178 | } 179 | 180 | // TODOTODO Open/create the access MUTEX here. 181 | 182 | TRACE( "0x%x SharedMemoryFile area @ %.8X for %X (%d)\n", this, sharedMem, size, size ); 183 | 184 | return true; // the open worked 185 | } 186 | 187 | 188 | void SharedMemoryFile::Close( void ) 189 | { 190 | } 191 | -------------------------------------------------------------------------------- /Common/SharedMemoryFile.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "DongleArrays.h" 4 | 5 | #define MAX_DONGLES 32 6 | 7 | typedef struct 8 | { 9 | char validityKey[ 8 ]; // 'RTL-SDR' 10 | BOOL MasterPresent; 11 | BOOL MasterUpdate; 12 | ULONG numEntries; // Total number of provisioned entries. 13 | ULONG activeEntries; // Current number of active entries 14 | Dongle dongleArray[ MAX_DONGLES ]; // Payload 15 | } RtlSdrAreaDef; 16 | 17 | #define kValidityKey "RTL-SDR" 18 | #define kSharedAreaName _T( "RtlSdr Shared Memory" ) 19 | 20 | class SharedMemoryFile 21 | { 22 | public: 23 | SharedMemoryFile ( void ); 24 | ~SharedMemoryFile ( void ); 25 | 26 | bool Init ( void );//* sysRef ) 27 | bool CreateSharedArea ( void ); 28 | void Close ( void ); 29 | 30 | 31 | 32 | RtlSdrAreaDef* sharedMem; 33 | bool active; 34 | bool alreadyexisted; 35 | 36 | protected: 37 | HANDLE sharedHandle; 38 | 39 | }; 40 | 41 | extern RtlSdrAreaDef TestDongles; 42 | extern RtlSdrAreaDef* RtlSdrArea; 43 | extern Dongle* Dongles; 44 | 45 | extern SharedMemoryFile SharedDongleData; 46 | -------------------------------------------------------------------------------- /IRtlSdr.h: -------------------------------------------------------------------------------- 1 | // IRtlSdr.h 2 | 3 | #pragma once 4 | 5 | #if !defined SDRDAPI 6 | #define SDRDAPI 7 | #endif 8 | 9 | #define EEPROM_SIZE 256 10 | typedef uint8_t eepromdata[ EEPROM_SIZE ]; 11 | 12 | class /*SDRDAPI*/ IRtlSdr 13 | { 14 | public: 15 | virtual 16 | int rtlsdr_set_xtal_freq ( uint32_t rtl_freq 17 | , uint32_t tuner_freq 18 | ) PURE; 19 | virtual 20 | int rtlsdr_get_xtal_freq ( uint32_t *rtl_freq 21 | , uint32_t *tuner_freq 22 | ) PURE; 23 | virtual 24 | int rtlsdr_write_eeprom ( uint8_t *data 25 | , uint8_t offset 26 | , uint16_t len 27 | ) PURE; 28 | virtual 29 | int rtlsdr_read_eeprom ( uint8_t *data 30 | , uint8_t offset 31 | , uint16_t len 32 | ) PURE; 33 | virtual 34 | int rtlsdr_read_eeprom ( eepromdata& data ) PURE; 35 | virtual 36 | int rtlsdr_set_center_freq ( uint32_t in_freq ) PURE; 37 | virtual 38 | uint32_t rtlsdr_get_center_freq ( void ) PURE; 39 | virtual 40 | int rtlsdr_set_freq_correction ( int ppm ) PURE; 41 | virtual 42 | int rtlsdr_get_freq_correction 43 | ( void ) PURE; 44 | virtual 45 | int rtlsdr_get_tuner_type ( void ) PURE; 46 | virtual 47 | int rtlsdr_get_tuner_gains ( int *gains ) PURE; 48 | virtual 49 | int rtlsdr_set_tuner_gain ( int gain ) PURE; 50 | virtual 51 | int rtlsdr_get_tuner_gain ( void ) PURE; 52 | virtual 53 | int rtlsdr_set_tuner_if_gain ( int stage 54 | , int gain 55 | ) PURE; 56 | virtual 57 | int rtlsdr_get_tuner_stage_gains( uint8_t stage 58 | , int32_t *gains 59 | , char *description 60 | ) PURE; 61 | virtual 62 | int rtlsdr_get_tuner_stage_count( void ) PURE; 63 | virtual 64 | int rtlsdr_set_tuner_stage_gain ( uint8_t stage 65 | , int32_t gain 66 | ) PURE; 67 | virtual 68 | int rtlsdr_get_tuner_stage_gain ( uint8_t stage ) PURE; 69 | virtual 70 | int rtlsdr_set_tuner_gain_mode ( int mode ) PURE; 71 | virtual 72 | int rtlsdr_set_sample_rate ( uint32_t samp_rate ) PURE; 73 | virtual 74 | uint32_t rtlsdr_get_sample_rate ( void ) PURE; 75 | virtual 76 | uint32_t rtlsdr_get_corr_sample_rate ( void ) PURE; 77 | virtual 78 | int rtlsdr_set_testmode ( int on ) PURE; 79 | virtual 80 | int rtlsdr_set_agc_mode ( int on ) PURE; 81 | virtual 82 | int rtlsdr_set_direct_sampling ( int on ) PURE; 83 | virtual 84 | int rtlsdr_get_direct_sampling 85 | ( void ) PURE; 86 | virtual 87 | int rtlsdr_set_offset_tuning ( int on ) PURE; 88 | virtual 89 | int rtlsdr_get_offset_tuning ( void ) PURE; 90 | virtual 91 | int rtlsdr_set_dithering ( int dither ) PURE; 92 | virtual 93 | // int rtlsdr_get_tuner_type ( int index ) PURE; 94 | // virtual 95 | int rtlsdr_open ( uint32_t index ) PURE; 96 | virtual 97 | int rtlsdr_close ( void ) PURE; 98 | virtual 99 | uint32_t rtlsdr_get_tuner_clock ( void ) PURE; 100 | virtual 101 | int rtlsdr_get_usb_strings ( char *manufact 102 | , char *product 103 | , char *serial 104 | ) PURE; 105 | virtual 106 | int rtlsdr_get_usb_cstrings ( CString& manufact 107 | , CString& product 108 | , CString& serial 109 | ) PURE; 110 | virtual 111 | int rtlsdr_reset_buffer ( void ) PURE; 112 | virtual 113 | int rtlsdr_read_sync ( BYTE *buf 114 | , int len 115 | , int *n_read 116 | ) PURE; 117 | virtual 118 | int rtlsdr_wait_async ( rtlsdr_read_async_cb_t cb 119 | , void *ctx 120 | ) PURE; 121 | virtual 122 | int rtlsdr_read_async ( rtlsdr_read_async_cb_t in_cb 123 | , void *in_ctx 124 | , uint32_t buf_num 125 | , uint32_t buf_len 126 | ) PURE; 127 | virtual 128 | int rtlsdr_cancel_async ( void ) PURE; 129 | virtual 130 | const char* rtlsdr_get_version ( void ) PURE; 131 | virtual 132 | unsigned __int64 133 | rtlsdr_get_version_int64 ( void ) PURE; 134 | virtual 135 | uint32_t rtlsdr_get_device_count ( void ) PURE; 136 | virtual 137 | const char *rtlsdr_get_device_name ( uint32_t index ) PURE; 138 | virtual 139 | int rtlsdr_get_device_usb_strings 140 | ( uint32_t index 141 | , char *manufact 142 | , char *product 143 | , char *serial 144 | ) PURE; 145 | virtual 146 | int rtlsdr_get_device_usb_cstrings 147 | ( uint32_t index 148 | , CString& manufact 149 | , CString& product 150 | , CString& serial 151 | ) PURE; 152 | virtual 153 | int rtlsdr_get_index_by_serial ( const char *serial ) PURE; 154 | }; 155 | -------------------------------------------------------------------------------- /ITuner.h: -------------------------------------------------------------------------------- 1 | // ITuner.h 2 | #pragma once 3 | 4 | #define PURE = 0 5 | 6 | class rtlsdr; 7 | 8 | class ITuner 9 | { 10 | public: 11 | // ITuner interface 12 | virtual int init ( rtlsdr* base ) PURE; // new? 13 | virtual int exit ( void ) PURE; // delete? 14 | virtual int set_freq ( uint32_t freq /* Hz */ 15 | , uint32_t *lo_freq_out 16 | ) PURE; 17 | virtual int set_bw ( int bw /* Hz */) PURE; 18 | virtual int get_gain ( void ) PURE; /* tenth dB. Computerd gain if necessary. */ 19 | virtual int set_gain ( int gain /* tenth dB */) PURE; 20 | virtual int set_if_gain ( int stage 21 | , int gain /* tenth dB */ 22 | ) PURE; 23 | virtual int get_tuner_stage_gains ( uint8_t stage 24 | , const int32_t **gains 25 | , const char **description 26 | ) PURE; 27 | virtual int get_tuner_stage_count ( void ) PURE; 28 | virtual int get_tuner_stage_gain ( uint8_t stage ) PURE; 29 | virtual int set_tuner_stage_gain ( uint8_t stage 30 | , int gain 31 | ) PURE; 32 | virtual int set_gain_mode ( int manual ) PURE; 33 | virtual int get_tuner_bandwidths ( const uint32_t **bandwidths 34 | , int *len 35 | ) PURE; 36 | virtual int get_bandwidth_set_name ( int nSet 37 | , char* pString 38 | ) PURE; 39 | virtual int set_bandwidth_set ( int nSet ) PURE; 40 | virtual int set_dither ( int dither ) PURE; 41 | 42 | virtual int get_xtal_frequency ( uint32_t& xtalfreq ) PURE; 43 | virtual int set_xtal_frequency ( uint32_t xtalfreq ) PURE; 44 | 45 | virtual int get_tuner_gains ( const int **ptr 46 | , int *len 47 | ) PURE; 48 | 49 | #if defined SET_SPECIAL_FILTER_VALUES 50 | virtual int SetFilterValuesDirect ( BYTE regA 51 | , BYTE regB 52 | , DWORD ifFreq 53 | ) PURE; 54 | #endif 55 | }; 56 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | rtl-sdr 2 | turns your Realtek RTL2832 based DVB dongle into a SDR receiver 3 | ====================================================================== 4 | 5 | For more information on base tree see: 6 | http://sdr.osmocom.org/trac/wiki/rtl-sdr 7 | 8 | 9 | Notes on the mutability tree (2014/09/29) 10 | ========================================= 11 | 12 | Since there seems to be some wider interest in this, some quick notes on 13 | my changes here. 14 | 15 | TL;DR: 16 | 17 | 0Hz 18 | . 19 | . "no mod direct sampling" 20 | . no mixing at all, tuner is mostly disabled, just ram as much signal 21 | . as you can at it and maybe some will leak through. 22 | . YMMV a lot 23 | . 24 | ~13MHz (PLL lower limit - 14MHz) 25 | . 26 | . normal tuning, large IF. 27 | . high-side mixing 28 | . you will see nasty aliasing / attentuation / harmonics 29 | . near the lower edge of the range 30 | . you will see lots of noise from the dongle itself near 14.4MHz 31 | . 32 | ~21MHz (PLL lower limit - 6MHz) <- upstream tuner lower limit 33 | . 34 | . normal tuning, regular IF 35 | . high-side mixing 36 | . this should behave much like upstream 37 | . 38 | ~1844Mhz (PLL upper limit - 6MHz) <- upstream tuner upper limit 39 | . 40 | . normal tuning, small IF (getting squashed against the PLL upper bound) 41 | . high-side mixing 42 | . 43 | ~1848MHz (PLL upper limit - 2MHz) 44 | . 45 | . tuning with low-side mixing (PLL frequency below tuned frequency) 46 | . you will see nasty aliasing / attentuation / harmonics 47 | . near the upper edge of the range 48 | . 49 | ~1864MHz (PLL upper limit + 14MHz) <- that's all, folks 50 | 51 | (PLL limits vary by dongle - some go as high as 1885MHz) 52 | 53 | This tree is a collection of random tuner hacks which are really exploratory 54 | more than anything. They may or may not work for you. 55 | 56 | First some background for those unfamiliar with the internals of the dongle: 57 | 58 | * The R820T tuner has a tunable PLL that can generate frequencies between 59 | around 27MHz .. 1850MHz. The exact range varies from dongle to dongle. 60 | * The tuner mixes the incoming RF signal with this PLL output. This shifts 61 | the RF signal down to a frequency that is the difference between the PLL 62 | frequency and the RF signal's frequency. 63 | * The tuner sends this intermediate frequency (IF) signal to the RTL2838U 64 | * The RTL2838U digitizes the IF signal and does a digital downconversion 65 | step to generate I/Q samples that are centered around "zero". The 66 | downconverter can theoretically handle IF signals up to 14.4MHz. 67 | 68 | The main change is to feed information about the actually-tuned frequency back 69 | from the tuner (R820T) code to the core (RTL2832U) code, allowing the core 70 | code to adjust to the actual IF in use, rather than requiring a fixed IF. The 71 | core code has also been taught how to handle low-side mixing, where the PLL 72 | frequency is lower than the requested frequency (e.g. the spectrum inversion 73 | changes then) 74 | 75 | When tuning, the R820T tuner will try to tune to the requested frequency + 76 | 6MHz, producing a 6MHz IF. If the PLL cannot handle that frequency, the tuner 77 | will try a few things to produce something useful. 78 | 79 | At the top of the tuning range: 80 | 81 | * It will tune as high as it can go normally, then stick there producing a 82 | smaller effective IF as the requested frequency gets higher and higher. 83 | * Once the IF starts getting too small (below about 1.5MHz things start to 84 | go bad), it will switch to low-side mixing and try to put the PLL frequency 85 | *below* the target frequency. This gives you another 14-15 MHz at the top 86 | of the range. 87 | 88 | I've had reports that some dongles can tune to within a whisker of 2000MHz 89 | with this. 90 | 91 | At the bottom of the range: 92 | 93 | * It will tune as low as it can go normally, then stick there producing a 94 | larger effective IF as the requested frequency gets lower and lower. 95 | * Once the required IF exceeds 14.4MHz, it will switch to a variant of tejeez' 96 | et al "no mod direct sampling" mode. This essentially disables the PLL in 97 | the tuner entirely, and relies on some RF signal leaking through the tuner 98 | unchanged. The tuner claims to be tuned to 0Hz in this mode, and the core 99 | does all the real tuning. The dongle is almost deaf in this mode, you will 100 | have to turn the RF gain WAY UP. You do not need to mess with direct sampling 101 | settings to enable this, it's integrated with normal tuning. 102 | 103 | The success of the "no mod direct sampling" mode seems to vary a lot from dongle 104 | to dongle. Mine is almost completely deaf so I can't test this much. Others have 105 | had success in tuning to shortwave stations as low as 3.5MHz. 106 | 107 | The actual PLL limits vary from dongle to dongle, and from day to day (they're 108 | probably temperature related). The tuner has three sets of tuning limits: 109 | 110 | * a hardcoded "do not exceed this" set of limits - see PLL_INITIAL_LOW / 111 | PLL_INITIAL_HIGH in tuner_r82xx.c. These are in place because, especially at 112 | the low end of the range, the PLL can get into a state where you ask for (for 113 | example) 25MHz, the PLL claims to be locked OK at that frequency, but in 114 | reality it's actually producing 27MHz, which screws up the core's calculations 115 | of the IF offset needed. 116 | * a hardcoded "known to be OK" set of limits - see PLL_SAFE_LOW / PLL_SAFE_HIGH 117 | in tuner_r82xx.c. This is a range where the PLL should always work; if the PLL 118 | doesn't work in this range it is treated as a tuning error and tuning fails. 119 | * a runtime "seems to be OK at the moment" set of limits. This varies from run 120 | to run and initially starts at the "do not exceed" limits. Whenever a failure 121 | to get PLL lock is seen, the runtime limits are shrunk accordingly and we try 122 | again. This allows the tuner to adapt to the particular dongle in use. 123 | 124 | Remember that at the extreme edges of these ranges you will be fighting an uphill 125 | battle against the dongle design itself, as you will be far out of the intended 126 | range of the filters etc and nothing works particularly well. 127 | 128 | You are likely to see small frequency shifts (maybe 1-2ppm) from what you get in 129 | upstream. This is because the tuner+2832 combination can be tuned a little more 130 | accurately than upstream does, so some errors that you will have previously been 131 | correcting for will disappear. 132 | 133 | 134 | -- Oliver (oliver.jowett@gmail.com / oliver@mutability.co.uk) 135 | 136 | Notes on the Joanne Dow tree (2014/10/24) 137 | ========================================= 138 | 139 | 140 | 141 | This tree is based on the mutability tree above. The changes involve making it a 142 | Windows specific tool, converting it to VS2010, converting it to C++, and adding 143 | a feature for supporting multiple dongles. Converting it back to work on 'ix should 144 | not be particularly difficult as long as you accept that it's in C++. As it sits it 145 | is 100% compatible with the base rtlsdr.dll. 146 | 147 | The added feature gives this version the ability to always know a dongle's 148 | particulars even if the dongle is busy. The best way to start using it is to 149 | replace all instances of the old rtlsdr.dll with this one. (Rename the old to 150 | make going back easier, if you find problems.) This has a pleasant side effect of 151 | requiring that you close all programs using the rtlsdr.dlls that you replace. 152 | 153 | Now when you open a program that uses the dongles when ever dongles are enumerated 154 | and some of the time when USB strings are read the polled data is reconciled with 155 | any data saved in the Windows registry. When the poll is completed and reconciled 156 | it is written to the Windows registry and locally cached. 157 | 158 | When a dongle is busy and its strings are requested the name is pulled from the 159 | local registry cache, an * is prefixed to the manufacturer string, and the results 160 | are returned to the main program. As a result you never get the embarrassing mess 161 | the base rtlsdr.dll leaves in tools like rtl_sdr.exe and rtl_tcp.exe. 162 | 163 | The information stored in the registry for each dongle contains the following: 164 | This version uses the Windows Registry to store USB string and path parameters 165 | for all discovered. Parameters stored are as follows: 166 | BYTE string1[ 256 ]; // Null terminated Manufacturer ID string 167 | BYTE string2[ 256 ]; // Null terminated Product ID string 168 | BYTE string3[ 256 ]; // Null terminated Serial Number ID string 169 | WORD mid; // Manufacturer ID word 170 | WORD pid; // Product ID word. 171 | BYTE usbpath[ MAX_USB_PATH ]; // Stores USB path through hubs to device 172 | char unusedc; // Ignored. 173 | bool unusedb; // Ignored. 174 | BYTE devindex; // LibUsb index for this device. 175 | BYTE iManufacturer; // Index of manufacturer string 176 | BYTE iProduct; // Index of product string 177 | BYTE iSerialNumber; // Index of serial number string 178 | BYTE tunerType; // Type of tuner per enum rtlsdr_tuner 179 | 180 | This version also features the option to directly access the rtlsdr class that is 181 | created and used by the classic static librtlsdr entry points. Some slight extra 182 | functionality is available. See librtlsdr.h for details. 183 | 184 | {^_^} Joanne (jdow@earthlink.net) 185 | 186 | 187 | 188 | Notes on the Joanne Dow tree (2016/10/26) 189 | ========================================= 190 | 191 | 192 | A variant on Leif Asbrink's excellent filter work has been included in this 193 | new version. These changes enable a variety of narrower analog filters that can 194 | reduce large signals that are causing problems and are far enough away from 195 | interfering signals. The basic entry points Leif generated behave the same. A 196 | new interface allows selection between sets of filters with different design 197 | philosophies. Only two sets are supported in this version, Leif's filters, which 198 | are offset to avoid the center spike if possible, and filters I generated which 199 | are centered around the center of the sampled bandwidth. 200 | 201 | New entry points supported: 202 | /*! 203 | * Get a list of bandwidths supported by the tuner. 204 | * 205 | * NOTE: The bandwidths argument must be preallocated by the caller. If NULL is 206 | * being given instead, the number of available bandwidth values will be returned. 207 | * 208 | * \param dev the device handle given by rtlsdr_open() 209 | * \param bandwidths array of bandwidth values in Hz. 210 | * \return <= 0 on error, number of available (returned) gain values otherwise 211 | */ 212 | RTLSDR_API int rtlsdr_get_tuner_bandwidths(rtlsdr_dev_t *dev, int *bandwidths); 213 | 214 | /*! 215 | * Set the bandwidth for the device. 216 | * 217 | * Valid bandwidth values may be queried with \ref rtlsdr_get_tuner_bandwidths function. 218 | * 219 | * \param dev the device handle given by rtlsdr_open() 220 | * \param bandwidth in Hz. 221 | * \return 0 on success 222 | */ 223 | RTLSDR_API int rtlsdr_set_tuner_bandwidth(rtlsdr_dev_t *dev, int bandwidth); 224 | 225 | /*! 226 | * Get the name for a set of IF filter bandwidths 227 | * 228 | * Query for bandwidth set N's name. Repeat for all values until the return 229 | * value is -1. 230 | * 231 | * \param dev the device handle given by rtlsdr_open() 232 | * \param nSet the index for the set to be recovered. 233 | * \param pString pointer to 80 BYTEs of storage to hold the bandwidth name. 234 | * \return 0 on success else -1. 235 | */ 236 | RTLSDR_API int rtlsdr_get_bandwidth_set_name( rtlsdr_dev_t *dev 237 | , int nSet 238 | , char* pString 239 | ); 240 | 241 | /*! 242 | * Select the IF bandwdith set desired. 243 | * 244 | * Set a new current value for the bandwidth set in use. Follow with a query 245 | * for bandwidths in the set using rtlsdr_get_tuner_bandwidths(). 246 | * 247 | * \param dev the device handle given by rtlsdr_open() 248 | * \param nSet Bandwidth set number 249 | * \return 0 on success -1 on error. 250 | */ 251 | RTLSDR_API int rtlsdr_set_bandwidth_set( rtlsdr_dev_t *dev, int nSet ); 252 | 253 | #if defined( SET_SPECIAL_FILTER_VALUES ) // For testing 254 | RTLSDR_API int rtlsdr_set_if_values ( rtlsdr_dev_t *dev 255 | , BYTE regA 256 | , BYTE regB 257 | , DWORD ifFreq 258 | ); 259 | 260 | #endif 261 | 262 | The last entry point is conditionally compiled and supports exploring the 263 | filter settings to generate new sets of filters. 264 | 265 | 266 | 267 | Notes on the Joanne Dow tree (2016/11/18) 268 | ========================================= 269 | 270 | This version adds bias tee setting and an automated direct sampling mode. 271 | As a note to the developer some of the basic features now interact with 272 | each other. It is best to set a dummy frequency value first, then the other 273 | variables pretty much in the order seen in the new rtlsdr_do_direct_sampling 274 | function. That way everything is initialized properly. 275 | 276 | New entry points include: 277 | /*! 278 | * Get a list of bandwidths supported by the tuner. 279 | * 280 | * NOTE: The bandwidths argument must be preallocated by the caller. If NULL is 281 | * being given instead, the number of available bandwidth values will be returned. 282 | * 283 | * \param dev the device handle given by rtlsdr_open() 284 | * \param bandwidths array of bandwidth values in Hz. 285 | * \return <= 0 on error, number of available (returned) gain values otherwise 286 | */ 287 | RTLSDR_API int rtlsdr_get_tuner_bandwidths(rtlsdr_dev_t *dev, int *bandwidths); 288 | 289 | /*! 290 | * Set the bandwidth for the device. 291 | * 292 | * Valid bandwidth values may be queried with \ref rtlsdr_get_tuner_bandwidths function. 293 | * 294 | * \param dev the device handle given by rtlsdr_open() 295 | * \param bandwidth in Hz. 296 | * \return 0 on success 297 | */ 298 | RTLSDR_API int rtlsdr_set_tuner_bandwidth(rtlsdr_dev_t *dev, int bandwidth); 299 | 300 | /*! 301 | * Get the name for a set of IF filter bandwidths 302 | * 303 | * Query for bandwidth set N's name. Repeat for all values until the return 304 | * value is -1. 305 | * 306 | * \param dev the device handle given by rtlsdr_open() 307 | * \param nSet the index for the set to be recovered. 308 | * \param pString pointer to 80 BYTEs of storage to hold the bandwidth name. 309 | * \return 0 on success else -1. 310 | */ 311 | RTLSDR_API int rtlsdr_get_bandwidth_set_name( rtlsdr_dev_t *dev 312 | , int nSet 313 | , char* pString 314 | ); 315 | 316 | /*! 317 | * Select the IF bandwdith set desired. 318 | * 319 | * Set a new current value for the bandwidth set in use. Follow with a query 320 | * for bandwidths in the set using rtlsdr_get_tuner_bandwidths(). 321 | * 322 | * \param dev the device handle given by rtlsdr_open() 323 | * \param nSet Bandwidth set number 324 | * \return 0 on success -1 on error. 325 | */ 326 | RTLSDR_API int rtlsdr_set_bandwidth_set( rtlsdr_dev_t *dev, int nSet ); 327 | 328 | /*! 329 | * Enable or disable the bias tee on GPIO PIN 0. 330 | */ 331 | RTLSDR_API int rtlsdr_set_bias_tee(rtlsdr_dev_t *dev, int on); 332 | 333 | 334 | {^_^} Joanne (jdow@earthlink.net) 335 | -------------------------------------------------------------------------------- /RtlSdr Catalog/DongleListMaint.cpp: -------------------------------------------------------------------------------- 1 | #include "StdAfx.h" 2 | #include "DongleListMaint.h" 3 | 4 | 5 | DongleListMaint::DongleListMaint(void) 6 | { 7 | } 8 | 9 | 10 | DongleListMaint::~DongleListMaint(void) 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /RtlSdr Catalog/DongleListMaint.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "SharedMemoryFile.h" 4 | 5 | class DongleListMaint 6 | { 7 | public: 8 | DongleListMaint (void); 9 | virtual ~DongleListMaint (void); 10 | 11 | 12 | }; 13 | 14 | -------------------------------------------------------------------------------- /RtlSdr Catalog/IRtlSdr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if !defined SDRDAPI 4 | #define SDRDAPI 5 | #endif 6 | 7 | #define EEPROM_SIZE 256 8 | typedef uint8_t eepromdata[ EEPROM_SIZE ]; 9 | #define STR_OFFSET 9 10 | 11 | 12 | class /*SDRDAPI*/ IRtlSdr 13 | { 14 | public: 15 | virtual 16 | int rtlsdr_set_xtal_freq ( uint32_t rtl_freq 17 | , uint32_t tuner_freq 18 | ) PURE; 19 | virtual 20 | int rtlsdr_get_xtal_freq ( uint32_t *rtl_freq 21 | , uint32_t *tuner_freq 22 | ) PURE; 23 | virtual 24 | int rtlsdr_write_eeprom ( uint8_t *data 25 | , uint8_t offset 26 | , uint16_t len 27 | ) PURE; 28 | virtual 29 | int rtlsdr_read_eeprom ( uint8_t *data 30 | , uint8_t offset 31 | , uint16_t len 32 | ) PURE; 33 | virtual 34 | int rtlsdr_read_eeprom ( eepromdata& data ) PURE; 35 | virtual 36 | int rtlsdr_set_center_freq ( uint32_t in_freq ) PURE; 37 | virtual 38 | uint32_t rtlsdr_get_center_freq ( void ) PURE; 39 | virtual 40 | int rtlsdr_set_freq_correction ( int ppm ) PURE; 41 | virtual 42 | int rtlsdr_get_freq_correction 43 | ( void ) PURE; 44 | virtual 45 | int rtlsdr_get_tuner_type ( void ) PURE; 46 | virtual 47 | int rtlsdr_get_tuner_gains ( int *gains ) PURE; 48 | virtual 49 | int rtlsdr_set_tuner_gain ( int gain ) PURE; 50 | virtual 51 | int rtlsdr_get_tuner_gain ( void ) PURE; 52 | virtual 53 | int rtlsdr_set_tuner_if_gain ( int stage 54 | , int gain 55 | ) PURE; 56 | virtual 57 | int rtlsdr_get_tuner_stage_gains( uint8_t stage 58 | , int32_t *gains 59 | , char *description 60 | ) PURE; 61 | virtual 62 | int rtlsdr_get_tuner_stage_count( void ) PURE; 63 | virtual 64 | int rtlsdr_set_tuner_stage_gain ( uint8_t stage 65 | , int32_t gain 66 | ) PURE; 67 | virtual 68 | int rtlsdr_get_tuner_stage_gain ( uint8_t stage ) PURE; 69 | virtual 70 | int rtlsdr_set_tuner_gain_mode ( int mode ) PURE; 71 | virtual 72 | int rtlsdr_set_sample_rate ( uint32_t samp_rate ) PURE; 73 | virtual 74 | uint32_t rtlsdr_get_sample_rate ( void ) PURE; 75 | virtual 76 | uint32_t rtlsdr_get_corr_sample_rate ( void ) PURE; 77 | virtual 78 | int rtlsdr_set_testmode ( int on ) PURE; 79 | virtual 80 | int rtlsdr_set_agc_mode ( int on ) PURE; 81 | virtual 82 | int rtlsdr_set_direct_sampling ( int on ) PURE; 83 | virtual 84 | int rtlsdr_get_direct_sampling 85 | ( void ) PURE; 86 | virtual 87 | int rtlsdr_set_offset_tuning ( int on ) PURE; 88 | virtual 89 | int rtlsdr_get_offset_tuning ( void ) PURE; 90 | virtual 91 | int rtlsdr_set_dithering ( int dither ) PURE; 92 | virtual 93 | // int rtlsdr_get_tuner_type ( int index ) PURE; 94 | // virtual 95 | int rtlsdr_open ( uint32_t index ) PURE; 96 | virtual 97 | int rtlsdr_close ( void ) PURE; 98 | virtual 99 | uint32_t rtlsdr_get_tuner_clock ( void ) PURE; 100 | virtual 101 | int rtlsdr_get_usb_strings ( char *manufact 102 | , char *product 103 | , char *serial 104 | ) PURE; 105 | virtual 106 | int rtlsdr_get_usb_strings ( CString& manufact 107 | , CString& product 108 | , CString& serial 109 | ) PURE; 110 | virtual 111 | int rtlsdr_reset_buffer ( void ) PURE; 112 | virtual 113 | int rtlsdr_read_sync ( BYTE *buf 114 | , int len 115 | , int *n_read 116 | ) PURE; 117 | virtual 118 | int rtlsdr_wait_async ( rtlsdr_read_async_cb_t cb 119 | , void *ctx 120 | ) PURE; 121 | virtual 122 | int rtlsdr_read_async ( rtlsdr_read_async_cb_t in_cb 123 | , void *in_ctx 124 | , uint32_t buf_num 125 | , uint32_t buf_len 126 | ) PURE; 127 | virtual 128 | int rtlsdr_cancel_async ( void ) PURE; 129 | virtual 130 | const char* rtlsdr_get_version ( void ) PURE; 131 | virtual 132 | unsigned __int64 133 | rtlsdr_get_version_int64 ( void ) PURE; 134 | virtual 135 | uint32_t rtlsdr_get_device_count ( void ) PURE; 136 | virtual 137 | const char *rtlsdr_get_device_name ( uint32_t index ) PURE; 138 | virtual 139 | int rtlsdr_get_device_usb_strings 140 | ( uint32_t index 141 | , char *manufact 142 | , char *product 143 | , char *serial 144 | ) PURE; 145 | virtual 146 | int rtlsdr_get_device_usb_strings 147 | ( uint32_t index 148 | , CString& manufact 149 | , CString& product 150 | , CString& serial 151 | ) PURE; 152 | virtual 153 | int rtlsdr_get_index_by_serial ( const char *serial ) PURE; 154 | }; 155 | -------------------------------------------------------------------------------- /RtlSdr Catalog/InvisibleWnd.cpp: -------------------------------------------------------------------------------- 1 | // InvisibleWnd.cpp : implementation file 2 | // 3 | 4 | #include "stdafx.h" 5 | #include "resource.h" 6 | #include "InvisibleWnd.h" 7 | 8 | #ifdef _DEBUG 9 | #define new DEBUG_NEW 10 | #undef THIS_FILE 11 | static char THIS_FILE[] = __FILE__; 12 | #endif 13 | 14 | ///////////////////////////////////////////////////////////////////////////// 15 | // CInvisibleWnd 16 | 17 | CInvisibleWnd::CInvisibleWnd() 18 | { 19 | prev_child = NULL; 20 | } 21 | 22 | CInvisibleWnd::~CInvisibleWnd() 23 | { 24 | // TRACE ("%.8X Deleting CInvisibleWnd\n", this); 25 | } 26 | 27 | 28 | UINT RegisteredConfigMessageId = 0; 29 | 30 | BEGIN_MESSAGE_MAP(CInvisibleWnd, CWnd) 31 | //{{AFX_MSG_MAP(CInvisibleWnd) 32 | ON_WM_WINDOWPOSCHANGING() 33 | //}}AFX_MSG_MAP 34 | ON_REGISTERED_MESSAGE (RegisteredConfigMessageId, OnNewLogMessage) 35 | ON_WM_QUERYENDSESSION() 36 | ON_WM_ENDSESSION() 37 | END_MESSAGE_MAP() 38 | 39 | 40 | ///////////////////////////////////////////////////////////////////////////// 41 | // CInvisibleWnd message handlers 42 | 43 | LRESULT CInvisibleWnd::OnNewLogMessage(WPARAM wParam, LPARAM lParam) 44 | { 45 | // Pass the log message to our child. When the main window is hidden and 46 | // we only have a tray icon, the main window is our child. When the main 47 | // window is showing we do not have a child. However we still have the 48 | // same name as the main window, and it is even bets whether we will get 49 | // a log message or it will go directly to the child. So save off the 50 | // handle of the window we find and send to it. 51 | 52 | TRACE ("Invisible window got a registered message!\n"); 53 | CWnd *child = GetWindow (GW_CHILD); 54 | if (child) 55 | { 56 | // Do not save the CWnd pointer, it is temporary and will vanish. 57 | // The actual window handle should remain viable as long as we are 58 | // around. 59 | 60 | prev_child = child->m_hWnd; 61 | } 62 | if (prev_child) 63 | { 64 | // Since we start out minimized we are pretty much guaranteed of 65 | // having a child window at near startup, so it should be almost 66 | // impossible to have a null window handle. However, there is a 67 | // thin slice of time where we can maybe get a message before the 68 | // child is first set... 69 | 70 | TRACE ("Invisible window sending message to child\n"); 71 | return ::SendMessage (prev_child, RegisteredConfigMessageId, wParam, lParam); 72 | } 73 | else 74 | { 75 | TRACE ("Invisble window doesn't have a child!\n"); 76 | } 77 | return 0; 78 | } 79 | 80 | void CInvisibleWnd::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos) 81 | { 82 | CWnd::OnWindowPosChanging(lpwndpos); 83 | 84 | #ifdef IS_SMA 85 | CWnd *child = GetWindow (GW_CHILD); 86 | if (child) 87 | prev_child = child->m_hWnd; 88 | if (prev_child && (lpwndpos->flags == 0x47))//& SWP_SHOWWINDOW)) 89 | { 90 | TRACE ("Got windowpos changing with %X on invisible window, trying to pass it on.\n", 91 | lpwndpos->flags); 92 | ::SendMessage (prev_child, REQUEST_DISPLAY, 0, 0); 93 | } 94 | #endif 95 | } 96 | 97 | BOOL CInvisibleWnd::OnQueryEndSession() 98 | { 99 | CWnd *child = GetWindow (GW_CHILD); 100 | if (child) 101 | { 102 | // Do not save the CWnd pointer, it is temporary and will vanish. 103 | // The actual window handle should remain viable as long as we are 104 | // around. 105 | 106 | prev_child = child->m_hWnd; 107 | } 108 | if (prev_child) 109 | { 110 | // Since we start out minimized we are pretty much guaranteed of 111 | // having a child window at near startup, so it should be almost 112 | // impossible to have a null window handle. However, there is a 113 | // thin slice of time where we can maybe get a message before the 114 | // child is first set... 115 | 116 | return ::SendMessage (prev_child, WM_QUERYENDSESSION, NULL, NULL ) != 0; 117 | } 118 | return TRUE; 119 | } 120 | 121 | void CInvisibleWnd::OnEndSession(BOOL bEnding) 122 | { 123 | CWnd *child = GetWindow (GW_CHILD); 124 | if (child) 125 | { 126 | // Do not save the CWnd pointer, it is temporary and will vanish. 127 | // The actual window handle should remain viable as long as we are 128 | // around. 129 | 130 | prev_child = child->m_hWnd; 131 | } 132 | if (prev_child) 133 | { 134 | // Since we start out minimized we are pretty much guaranteed of 135 | // having a child window at near startup, so it should be almost 136 | // impossible to have a null window handle. However, there is a 137 | // thin slice of time where we can maybe get a message before the 138 | // child is first set... 139 | 140 | ::SendMessage (prev_child, WM_ENDSESSION, bEnding, NULL ); 141 | } 142 | return; 143 | } 144 | -------------------------------------------------------------------------------- /RtlSdr Catalog/InvisibleWnd.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // InvisibleWnd.h : header file 4 | // 5 | 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // CInvisibleWnd window 8 | 9 | class CInvisibleWnd : public CWnd 10 | { 11 | // Construction 12 | public: 13 | CInvisibleWnd(); 14 | 15 | // Attributes 16 | public: 17 | 18 | // Operations 19 | public: 20 | 21 | // Overrides 22 | // ClassWizard generated virtual function overrides 23 | //{{AFX_VIRTUAL(CInvisibleWnd) 24 | public: 25 | //}}AFX_VIRTUAL 26 | 27 | // Implementation 28 | public: 29 | virtual ~CInvisibleWnd(); 30 | 31 | // Generated message map functions 32 | protected: 33 | //{{AFX_MSG(CInvisibleWnd) 34 | afx_msg void OnWindowPosChanging(WINDOWPOS FAR* lpwndpos); 35 | //}}AFX_MSG 36 | afx_msg LRESULT OnNewLogMessage (WPARAM wParam, LPARAM lParam); 37 | BOOL OnQueryEndSession(); 38 | void OnEndSession(BOOL bEnding); 39 | DECLARE_MESSAGE_MAP() 40 | 41 | HWND prev_child; 42 | }; 43 | 44 | -------------------------------------------------------------------------------- /RtlSdr Catalog/MyCommandLineInfo.cpp: -------------------------------------------------------------------------------- 1 | // MyCommandLineInfo.cpp: implementation of the MyCommandLineInfo class. 2 | // 3 | ////////////////////////////////////////////////////////////////////// 4 | 5 | #include "stdafx.h" 6 | #include "MyCommandLineInfo.h" 7 | 8 | #ifdef _DEBUG 9 | #undef THIS_FILE 10 | static char THIS_FILE[]=__FILE__; 11 | #define new DEBUG_NEW 12 | #endif 13 | 14 | 15 | extern const CString strings[]; 16 | extern const UINT commands[]; 17 | 18 | ////////////////////////////////////////////////////////////////////// 19 | // Construction/Destruction 20 | ////////////////////////////////////////////////////////////////////// 21 | 22 | MyCommandLineInfo::MyCommandLineInfo() 23 | : quiet( false ) 24 | { 25 | } 26 | 27 | MyCommandLineInfo::~MyCommandLineInfo() 28 | { 29 | 30 | } 31 | void MyCommandLineInfo::ParseParam( const TCHAR* pszParam 32 | , BOOL bFlag 33 | , BOOL bLast 34 | ) 35 | { 36 | TRACE( _T( "Param: \"%s\", flag %d, last %d" ), pszParam, bFlag, bLast ); 37 | 38 | if ( bFlag ) 39 | { 40 | TRACE( "cmp = %d\n", _tcsicmp( pszParam, _T( "quiet" ))); 41 | if ( _tcsicmp( pszParam, _T( "quiet" )) == 0 ) 42 | quiet = true; 43 | } 44 | 45 | CCommandLineInfo::ParseParam( pszParam, bFlag, bLast ); 46 | } -------------------------------------------------------------------------------- /RtlSdr Catalog/MyCommandLineInfo.h: -------------------------------------------------------------------------------- 1 | // MyCommandLineInfo.h: interface for the MyCommandLineInfo class. 2 | // 3 | ////////////////////////////////////////////////////////////////////// 4 | 5 | #pragma once 6 | 7 | class MyCommandLineInfo : public CCommandLineInfo 8 | { 9 | public: 10 | MyCommandLineInfo(); 11 | virtual ~MyCommandLineInfo(); 12 | 13 | void ParseParam(const TCHAR* pszParam, BOOL bFlag, BOOL bLast); 14 | 15 | public: 16 | bool quiet; 17 | }; 18 | -------------------------------------------------------------------------------- /RtlSdr Catalog/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | MICROSOFT FOUNDATION CLASS LIBRARY : rtlsdr_service_test Project Overview 3 | =============================================================================== 4 | 5 | The application wizard has created this rtlsdr_service_test application for 6 | you. This application not only demonstrates the basics of using the Microsoft 7 | Foundation Classes but is also a starting point for writing your application. 8 | 9 | This file contains a summary of what you will find in each of the files that 10 | make up your rtlsdr_service_test application. 11 | 12 | rtlsdr_service_test.vcxproj 13 | This is the main project file for VC++ projects generated using an application wizard. 14 | It contains information about the version of Visual C++ that generated the file, and 15 | information about the platforms, configurations, and project features selected with the 16 | application wizard. 17 | 18 | rtlsdr_service_test.vcxproj.filters 19 | This is the filters file for VC++ projects generated using an Application Wizard. 20 | It contains information about the association between the files in your project 21 | and the filters. This association is used in the IDE to show grouping of files with 22 | similar extensions under a specific node (for e.g. ".cpp" files are associated with the 23 | "Source Files" filter). 24 | 25 | rtlsdr_service_test.h 26 | This is the main header file for the application. It includes other 27 | project specific headers (including Resource.h) and declares the 28 | Crtlsdr_service_testApp application class. 29 | 30 | rtlsdr_service_test.cpp 31 | This is the main application source file that contains the application 32 | class Crtlsdr_service_testApp. 33 | 34 | rtlsdr_service_test.rc 35 | This is a listing of all of the Microsoft Windows resources that the 36 | program uses. It includes the icons, bitmaps, and cursors that are stored 37 | in the RES subdirectory. This file can be directly edited in Microsoft 38 | Visual C++. Your project resources are in 1033. 39 | 40 | res\rtlsdr_service_test.ico 41 | This is an icon file, which is used as the application's icon. This 42 | icon is included by the main resource file rtlsdr_service_test.rc. 43 | 44 | res\rtlsdr_service_test.rc2 45 | This file contains resources that are not edited by Microsoft 46 | Visual C++. You should place all resources not editable by 47 | the resource editor in this file. 48 | 49 | 50 | ///////////////////////////////////////////////////////////////////////////// 51 | 52 | The application wizard creates one dialog class: 53 | 54 | rtlsdr_service_testDlg.h, rtlsdr_service_testDlg.cpp - the dialog 55 | These files contain your Crtlsdr_service_testDlg class. This class defines 56 | the behavior of your application's main dialog. The dialog's template is 57 | in rtlsdr_service_test.rc, which can be edited in Microsoft Visual C++. 58 | 59 | 60 | ///////////////////////////////////////////////////////////////////////////// 61 | 62 | Other standard files: 63 | 64 | StdAfx.h, StdAfx.cpp 65 | These files are used to build a precompiled header (PCH) file 66 | named rtlsdr_service_test.pch and a precompiled types file named StdAfx.obj. 67 | 68 | Resource.h 69 | This is the standard header file, which defines new resource IDs. 70 | Microsoft Visual C++ reads and updates this file. 71 | 72 | rtlsdr_service_test.manifest 73 | Application manifest files are used by Windows XP to describe an applications 74 | dependency on specific versions of Side-by-Side assemblies. The loader uses this 75 | information to load the appropriate assembly from the assembly cache or private 76 | from the application. The Application manifest maybe included for redistribution 77 | as an external .manifest file that is installed in the same folder as the application 78 | executable or it may be included in the executable in the form of a resource. 79 | ///////////////////////////////////////////////////////////////////////////// 80 | 81 | Other notes: 82 | 83 | The application wizard uses "TODO:" to indicate parts of the source code you 84 | should add to or customize. 85 | 86 | If your application uses MFC in a shared DLL, you will need 87 | to redistribute the MFC DLLs. If your application is in a language 88 | other than the operating system's locale, you will also have to 89 | redistribute the corresponding localized resources MFC100XXX.DLL. 90 | For more information on both of these topics, please see the section on 91 | redistributing Visual C++ applications in MSDN documentation. 92 | 93 | ///////////////////////////////////////////////////////////////////////////// 94 | 95 | 96 | 97 | 98 | 99 | 100 | Device list dev_count 32 101 | xxxxx Device 0 0x8086 0x3a39: ICH10 Family USB Universal Host Controller 102 | xxxxx Device 1 0x8086 0x3a35: ICH10 Family USB Universal Host Controller 103 | xxxxx Device 2 0x8086 0x3a38: ICH10 Family USB Universal Host Controller 104 | xxxxx Device 3 0x8086 0x3a34: ICH10 Family USB Universal Host Controller 105 | xxxxx Device 4 0x8086 0x3a37: ICH10 Family USB Universal Host Controller 106 | xxxxx Device 5 0x8086 0x3a36: ICH10 Family USB Universal Host Controller 107 | xxxxx Device 6 0x8086 0x3a3a: ICH10 Family USB Universal Host Controller 108 | xxxxx Device 7 0x8086 0x3a3c: ICH10 Family USB Enhanced Host Controller 109 | 110 | x Device 15 0x05e3 0x0608: 0x1 Genesys Logic, Inc. hub 111 | xx Device 28 0x10d5 0x5a08: 0x1 0x1 Autologic Inc. / Uni Class Technology Co., Ltd (KVM?) where is kbd and mouse? 112 | 113 | x Device 30 0x1a40 0x0201: 0x2 Terminus Technology Inc. FE 2.1 7-port Hub 114 | xx Device 18 0x07f2 0x0001: 0x2 0x2 Microcomputer Applications, Inc. Keylock dongle. (Gilderboop?) 115 | xx Device 8 0x0403 0x6001: 0x2 0x4 Future Technology Devices International, Ltd FT232 Serial (UART) IC 116 | xx Device 29 0x1a40 0x0101: 0x2 0x5 Terminus Technology Inc 117 | xxx Device 24 0x0c45 0x167f: 0x2 0x5 0x1 Microdia Thingamabob Audio Hockey puck 118 | xx Device 23 0x0bda 0x2838: 0x2 0x6 Found Rafael Micro R820T tuner Sn dng 5 119 | 120 | x Device 9 0x0409 0x005a: 0x3 NEC Corp. HighSpeed Hub 121 | xx Device 10 0x0409 0x005a: 0x3 0x4 NEC Corp. HighSpeed Hub 122 | xxx Device 11 0x0409 0x005a: 0x3 0x4 0x1 NEC Corp. HighSpeed Hub 123 | xxxx Device 27 0x0ecd 0xa100: 0x3 0x4 0x1 0x1 Lite-On IT Corp LDW-411SX DVD/CD Rewritable Drive 124 | xxxx Device 13 0x0557 0x2011: 0x3 0x4 0x1 0x2 ATEN International Co., Ltd four port serial 125 | xxxx Device 14 0x0557 0x2011: 0x3 0x4 0x1 0x3 ATEN International Co., Ltd four port serial 126 | xxxx Device 21 0x0bda 0x2838: 0x3 0x4 0x1 0x4 Found Elonics E4000 tuner Sn dng 15 127 | xxx Device 25 0x0ccd 0x00d7: 0x3 0x4 0x3 Found Terratec T-Stick Plus sn 00000002 128 | xxx Device 12 0x0409 0x005a: 0x3 0x4 0x4 NEC Corp. HighSpeed Hub 129 | xxxx Device 19 0x096e 0x0201: 0x3 0x4 0x4 0x1 Feitian Technologies, Inc. security dongle 130 | xxxx Device 26 0x0d8c 0x000e: 0x3 0x4 0x4 0x2 C-Media Electronics, Inc 131 | 132 | x Device 16 0x05e3 0x0608: 0x4 Genesys Logic, Inc. hub - extender cable to East side LR 133 | xx Device 22 0x0bda 0x2838: 0x4 0x1 Found Rafael Micro R820T tuner Sn dng 3 134 | 135 | x Device 20 00xbda 0x2832: 0x5 Found Elonics E4000 tuner Sn dng 00000992 136 | 137 | USB 3.0 board 138 | x Device 20 0x096e 0x0201: 0x4 NC 139 | 140 | x Device 20 0x096e 0x0201: 0x5 NC 141 | 142 | x Device 17 0x05e3 0x0608: 0x6 Genesys Logic, Inc. hub - extender cable USB 3 #2 143 | xx Device 31 0x1d50 0x60a1: 0x6 0x1 AirSpy 144 | 145 | x Device 30 0x1a40 0x0101: 0x7 Terminus Technology Inc. hub (extender cable) USB 3 #3 146 | xx Device 33 0x1d50 0x60a1: 0x7 0x4 AirSpy 2 147 | 148 | 149 | 150 | In reinit dongles we try to open a dongle and try to find it in the database. If 151 | it is not in the database and we could open it, add it. Otherwise, perhaps, let 152 | it float. 153 | 154 | Cases to oonsider: 155 | Finding all dongles 156 | cannot open the dongle -> Ignore it. Get it later. 157 | if usbpath matches mark busy.... (Do NOT add to local db.) 158 | can open the dongle 159 | Get names 160 | * duplicated names Force a rename? What does that do to me? 161 | Stuff into temp database 162 | 163 | // So we need a de-duplicate feature in here. 164 | // Name may or may not appear in masterdb 165 | // name and path may or may not appear in masterdb 166 | // Name may or may not be a duplicate (but appears once in masterdb) 167 | // path may or may not match (Dongle may or may not be in original slot) 168 | 169 | while ( reinit_dongles.GetSize() > 0 ) 170 | if exact match to masterdb 171 | reinit_dongles.RemoveAt( 0 ) 172 | continue; 173 | else if !name in masterdb 174 | Add to masterdb 175 | reinit_dongles.RemoveAt( 0 ) 176 | continue; 177 | // Name is in db 178 | else if !duplicated 179 | fix path in masterdb 180 | reinit_dongles.RemoveAt( 0 ) 181 | else 182 | // Duplicated in local db and !exact match and not in db 183 | // So we have a duplicate - let's deal with it. 184 | // It might be a set of new dongles that duplicate what we have 185 | // or it might be a new duplicate matching one entry we already have. 186 | // Suppose I increment sn by 1 and retest for matches. Repeat until 187 | // no match and add to database. 188 | bool exact = false 189 | while (no name match in masterdb) 190 | if exact match 191 | exact = true 192 | write to dongle should be impossible but.... 193 | break 194 | fi 195 | elihw 196 | if !exact 197 | add to masterdb 198 | fi 199 | fi 200 | 201 | rof 202 | -------------------------------------------------------------------------------- /RtlSdr Catalog/RtlSdr Catalog.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {61333089-8BC9-4A2E-96B6-06A0578C2DA8} 23 | RtlSdr Catalog 24 | MFCProj 25 | RtlSdr Catalog 26 | 27 | 28 | 29 | Application 30 | true 31 | MultiByte 32 | Dynamic 33 | 34 | 35 | Application 36 | true 37 | MultiByte 38 | Dynamic 39 | 40 | 41 | Application 42 | false 43 | true 44 | MultiByte 45 | Dynamic 46 | 47 | 48 | Application 49 | false 50 | true 51 | MultiByte 52 | Dynamic 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | true 72 | $(ProjectDir)$(PlatformShortName)\$(Configuration)\ 73 | $(ProjectDir)$(PlatformShortName)\$(Configuration)\ 74 | 75 | 76 | true 77 | $(ProjectDir)$(PlatformName)\$(Configuration)\ 78 | $(ProjectDir)$(PlatformName)\$(Configuration)\ 79 | 80 | 81 | false 82 | $(ProjectDir)$(PlatformShortName)\$(Configuration)\ 83 | $(ProjectDir)$(PlatformShortName)\$(Configuration)\ 84 | 85 | 86 | false 87 | $(ProjectDir)$(PlatformName)\$(Configuration)\ 88 | $(ProjectDir)$(PlatformName)\$(Configuration)\ 89 | 90 | 91 | 92 | Use 93 | Level3 94 | Disabled 95 | WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) 96 | ..\Common 97 | 98 | 99 | Windows 100 | true 101 | 102 | 103 | false 104 | true 105 | _DEBUG;%(PreprocessorDefinitions) 106 | 107 | 108 | 0x0409 109 | _DEBUG;%(PreprocessorDefinitions) 110 | $(IntDir);%(AdditionalIncludeDirectories) 111 | 112 | 113 | 114 | 115 | Use 116 | Level3 117 | Disabled 118 | WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) 119 | ..\Common 120 | 121 | 122 | Windows 123 | true 124 | 125 | 126 | false 127 | _DEBUG;%(PreprocessorDefinitions) 128 | 129 | 130 | 0x0409 131 | _DEBUG;%(PreprocessorDefinitions) 132 | $(IntDir);%(AdditionalIncludeDirectories) 133 | 134 | 135 | 136 | 137 | Level3 138 | Use 139 | MaxSpeed 140 | true 141 | true 142 | WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) 143 | ..\Common 144 | 145 | 146 | Windows 147 | true 148 | true 149 | true 150 | 151 | 152 | false 153 | true 154 | NDEBUG;%(PreprocessorDefinitions) 155 | 156 | 157 | 0x0409 158 | NDEBUG;%(PreprocessorDefinitions) 159 | $(IntDir);%(AdditionalIncludeDirectories) 160 | 161 | 162 | 163 | 164 | Level3 165 | Use 166 | MaxSpeed 167 | true 168 | true 169 | WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) 170 | ..\Common 171 | 172 | 173 | Windows 174 | true 175 | true 176 | true 177 | 178 | 179 | false 180 | NDEBUG;%(PreprocessorDefinitions) 181 | 182 | 183 | 0x0409 184 | NDEBUG;%(PreprocessorDefinitions) 185 | $(IntDir);%(AdditionalIncludeDirectories) 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 | Create 219 | Create 220 | Create 221 | Create 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | -------------------------------------------------------------------------------- /RtlSdr Catalog/RtlSdr Catalog.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | Resource Files 21 | 22 | 23 | Resource Files 24 | 25 | 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | Header Files 35 | 36 | 37 | Header Files 38 | 39 | 40 | Header Files 41 | 42 | 43 | Header Files 44 | 45 | 46 | Header Files 47 | 48 | 49 | Header Files 50 | 51 | 52 | Header Files 53 | 54 | 55 | Header Files 56 | 57 | 58 | Header Files 59 | 60 | 61 | Header Files 62 | 63 | 64 | Header Files 65 | 66 | 67 | Header Files 68 | 69 | 70 | 71 | 72 | Source Files 73 | 74 | 75 | Source Files 76 | 77 | 78 | Source Files 79 | 80 | 81 | Source Files 82 | 83 | 84 | Source Files 85 | 86 | 87 | Source Files 88 | 89 | 90 | Source Files 91 | 92 | 93 | Source Files 94 | 95 | 96 | Source Files 97 | 98 | 99 | Source Files 100 | 101 | 102 | 103 | 104 | Resource Files 105 | 106 | 107 | -------------------------------------------------------------------------------- /RtlSdr Catalog/RtlSdrList.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "..\libusb/libusb.h" 3 | #include "Recognized Dongles.h" 4 | #include "..\Common\MyMutex.h" 5 | 6 | #include "SharedMemoryFile.h" 7 | 8 | typedef BYTE usbpath_t[ MAX_USB_PATH ]; 9 | 10 | #define EEPROM_SIZE 256 11 | typedef uint8_t eepromdata[ EEPROM_SIZE ]; 12 | 13 | enum rtlsdr_tuner 14 | { 15 | RTLSDR_TUNER_UNKNOWN = 0, 16 | RTLSDR_TUNER_E4000, 17 | RTLSDR_TUNER_FC0012, 18 | RTLSDR_TUNER_FC0013, 19 | RTLSDR_TUNER_FC2580, 20 | RTLSDR_TUNER_R820T, 21 | RTLSDR_TUNER_R828D 22 | }; 23 | 24 | class RtlSdrList 25 | { 26 | public: 27 | RtlSdrList ( void ); 28 | virtual ~RtlSdrList ( void ); 29 | 30 | bool IsSharedMemoryActive ( void ) 31 | { 32 | return Dongles != NULL && RtlSdrArea != NULL; 33 | } 34 | int GetCount ( void ); 35 | bool GetStrings ( int index 36 | , CString& man 37 | , CString& prd 38 | , CString& ser 39 | ); 40 | bool IsBusy ( DWORD index ); 41 | bool IsFound ( DWORD index ); 42 | void GetCatalog ( void ); 43 | void SetMasterPresent ( bool set = true ) 44 | { 45 | RtlSdrArea->MasterPresent = true; 46 | } 47 | int GetMasterUpdate ( void ) 48 | { 49 | BOOL update = RtlSdrArea->MasterUpdate; 50 | RtlSdrArea->MasterUpdate = false; 51 | return update; 52 | } 53 | bool SharedMemExistedOnStart ( void ) 54 | { 55 | // You get one and only one valid query. 56 | if ( SharedDongleData.alreadyexisted ) 57 | { 58 | SharedDongleData.alreadyexisted = false; 59 | return true; 60 | } 61 | return false; 62 | } 63 | void RemoveDongle ( int index ); 64 | 65 | protected: 66 | 67 | void ReadRegistry ( void ); 68 | void WriteRegistry ( void ); 69 | uint32_t WriteSingleRegistry ( int index ); 70 | void WriteRegLastCatalogTime ( void ); 71 | void reinitDongles ( void ); 72 | const rtlsdr_dongle_t * 73 | find_known_device ( uint16_t vid 74 | , uint16_t pid 75 | ); 76 | int rtlsdr_open ( uint32_t devindex ); 77 | void ClearVars ( void ); 78 | int basic_open ( uint32_t devindex ); 79 | int claim_opened_device ( void ); 80 | int rtlsdr_close ( void ); 81 | int open_requested_device ( libusb_context *ctx 82 | , uint32_t index 83 | , libusb_device_handle **ldevh 84 | ); 85 | void rtlsdr_set_i2c_repeater ( int on ); 86 | int rtlsdr_demod_write_reg ( uint8_t page 87 | , uint16_t addr 88 | , uint16_t val 89 | , uint8_t len 90 | ); 91 | uint16_t rtlsdr_demod_read_reg ( uint8_t page 92 | , uint16_t addr 93 | , uint8_t len 94 | ); 95 | void rtlsdr_init_baseband ( void ); 96 | int rtlsdr_deinit_baseband ( void ); 97 | uint16_t rtlsdr_read_reg ( uint8_t block 98 | , uint16_t addr 99 | , uint8_t len 100 | ); 101 | int rtlsdr_write_reg ( uint8_t block 102 | , uint16_t addr 103 | , uint16_t val 104 | , uint8_t len 105 | ); 106 | int rtlsdr_read_array ( uint8_t block 107 | , uint16_t addr 108 | , uint8_t *data 109 | , uint8_t len 110 | ); 111 | int rtlsdr_write_array ( uint8_t block 112 | , uint16_t addr 113 | , uint8_t *data 114 | , uint8_t len 115 | ); 116 | int rtlsdr_i2c_write_reg ( uint8_t i2c_addr 117 | , uint8_t reg 118 | , uint8_t val 119 | ); 120 | uint8_t rtlsdr_i2c_read_reg ( uint8_t i2c_addr 121 | , uint8_t reg 122 | ); 123 | void rtlsdr_set_gpio_bit ( uint8_t gpio 124 | , int val 125 | ); 126 | void rtlsdr_set_gpio_output ( uint8_t gpio ); 127 | int GetDongleIndexFromDongle( const Dongle dongle ); 128 | void mergeToMaster ( Dongle& tempd ); 129 | int rtlsdr_read_eeprom_raw ( eepromdata& data ); 130 | int GetEepromStrings ( uint8_t *data 131 | , int datalen 132 | , char* manf 133 | , char* prod 134 | , char* sern 135 | ); 136 | int GetEepromString ( const uint8_t *data 137 | , int datalen // Length to read. 138 | , int pos 139 | , char* string // BETTER be 256 bytes long 140 | ); 141 | bool CompareSparseRegAndData ( Dongle* dng 142 | , eepromdata& data 143 | ); 144 | int srtlsdr_eep_img_from_Dongle 145 | ( eepromdata& dat 146 | , Dongle* regentry 147 | ); 148 | int FindInMasterDB ( Dongle* dng 149 | , bool exact 150 | ); 151 | int FindGuessInMasterDB ( Dongle* dng ); 152 | 153 | Dongle m_dongle; 154 | time_t lastCatalog; 155 | libusb_context * ctx; 156 | struct libusb_device_handle *devh; 157 | enum rtlsdr_tuner tuner_type; 158 | int i2c_repeater_on; 159 | bool goodCatalog; 160 | bool dev_lost; 161 | 162 | // static RtlSdrAreaDef* RtlSdrArea; 163 | // static Dongle* Dongles; 164 | // static CMyMutex registry_mutex; 165 | // static CMyMutex dongle_mutex; 166 | static CMyMutex rtlsdr_mutex; 167 | }; 168 | 169 | -------------------------------------------------------------------------------- /RtlSdr Catalog/RtlSdr_Catalog.cpp: -------------------------------------------------------------------------------- 1 | 2 | // RtlSdr_Catalog.cpp : Defines the class behaviors for the application. 3 | // 4 | 5 | #include "stdafx.h" 6 | #include "RtlSdr_Catalog.h" 7 | #include "RtlSdr_CatalogDlg.h" 8 | #include "MyCommandLineInfo.h" 9 | 10 | #ifdef _DEBUG 11 | #define new DEBUG_NEW 12 | #endif 13 | 14 | 15 | // CRtlSdr_CatalogApp 16 | 17 | BEGIN_MESSAGE_MAP( CRtlSdr_CatalogApp, CWinApp ) 18 | ON_COMMAND( ID_HELP, &CWinApp::OnHelp ) 19 | END_MESSAGE_MAP() 20 | 21 | 22 | // CRtlSdr_CatalogApp construction 23 | 24 | CRtlSdr_CatalogApp::CRtlSdr_CatalogApp( void ) 25 | { 26 | // TODO: add construction code here, 27 | // Place all significant initialization in InitInstance 28 | } 29 | 30 | 31 | // The one and only CRtlSdr_CatalogApp object 32 | 33 | CRtlSdr_CatalogApp theApp; 34 | 35 | 36 | // CRtlSdr_CatalogApp initialization 37 | 38 | BOOL CRtlSdr_CatalogApp::InitInstance( void ) 39 | { 40 | // InitCommonControlsEx() is required on Windows XP if an application 41 | // manifest specifies use of ComCtl32.dll version 6 or later to enable 42 | // visual styles. Otherwise, any window creation will fail. 43 | INITCOMMONCONTROLSEX InitCtrls; 44 | InitCtrls.dwSize = sizeof(InitCtrls); 45 | // Set this to include all the common control classes you want to use 46 | // in your application. 47 | InitCtrls.dwICC = ICC_WIN95_CLASSES; 48 | InitCommonControlsEx(&InitCtrls); 49 | 50 | CWinApp::InitInstance(); 51 | 52 | // Parse command line for standard shell commands, DDE, file open 53 | MyCommandLineInfo cmdInfo; 54 | ParseCommandLine( cmdInfo ); 55 | 56 | // Create the shell manager, in case the dialog contains 57 | // any shell tree view or shell list view controls. 58 | CShellManager *pShellManager = new CShellManager; 59 | 60 | // Standard initialization 61 | // If you are not using these features and wish to reduce the size 62 | // of your final executable, you should remove from the following 63 | // the specific initialization routines you do not need 64 | // Change the registry key under which our settings are stored 65 | SetRegistryKey( _T( "RtlSdr Catalog" )); 66 | 67 | CRtlSdr_CatalogDlg dlg; 68 | m_pMainWnd = &dlg; 69 | if ( cmdInfo.quiet == true ) 70 | dlg.quiet = true; 71 | INT_PTR nResponse = dlg.DoModal(); 72 | 73 | _AFX_THREAD_STATE* pState = AfxGetThreadState(); 74 | ASSERT( pState ); 75 | if ( pState->m_msgCur.lParam == ID_TRUE_EXIT ) 76 | pState->m_msgCur.lParam = 0; 77 | 78 | // Delete the shell manager created above. 79 | if (pShellManager != NULL) 80 | { 81 | delete pShellManager; 82 | } 83 | 84 | // Since the dialog has been closed, return FALSE so that we exit the 85 | // application, rather than start the application's message pump. 86 | return FALSE; 87 | } 88 | 89 | -------------------------------------------------------------------------------- /RtlSdr Catalog/RtlSdr_Catalog.h: -------------------------------------------------------------------------------- 1 | 2 | // rtlsdr_service_test.h : main header file for the PROJECT_NAME application 3 | // 4 | 5 | #pragma once 6 | 7 | #ifndef __AFXWIN_H__ 8 | #error "include 'stdafx.h' before including this file for PCH" 9 | #endif 10 | 11 | #include "resource.h" // main symbols 12 | 13 | 14 | // Crtlsdr_service_testApp: 15 | // See rtlsdr_service_test.cpp for the implementation of this class 16 | // 17 | 18 | class CRtlSdr_CatalogApp : public CWinApp 19 | { 20 | public: 21 | CRtlSdr_CatalogApp(); 22 | 23 | // Overrides 24 | public: 25 | virtual BOOL InitInstance(); 26 | 27 | // Implementation 28 | 29 | DECLARE_MESSAGE_MAP() 30 | }; 31 | 32 | extern CRtlSdr_CatalogApp theApp; -------------------------------------------------------------------------------- /RtlSdr Catalog/RtlSdr_Catalog.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-jdow/rtlsdr-Cplusplus-VS2010/fba0ae3e8a0314c1581c07ac56ad67180fbec72f/RtlSdr Catalog/RtlSdr_Catalog.rc -------------------------------------------------------------------------------- /RtlSdr Catalog/RtlSdr_CatalogDlg.cpp: -------------------------------------------------------------------------------- 1 | 2 | // RtlSdr_CatalogDlg.cpp : implementation file 3 | // 4 | 5 | #include "stdafx.h" 6 | #include "RtlSdr_Catalog.h" 7 | #include "RtlSdr_CatalogDlg.h" 8 | #include "afxdialogex.h" 9 | #include "TrayIconManager.h" 10 | #include 11 | #include 12 | 13 | #ifdef _DEBUG 14 | #define new DEBUG_NEW 15 | #endif 16 | 17 | // Thread Utility function 18 | 19 | UINT flagthreadstarter( LPVOID pParam ) 20 | { 21 | CRtlSdr_CatalogDlg* data = (CRtlSdr_CatalogDlg*) pParam; 22 | data->FlagThreadFunction(); 23 | return 0; 24 | } 25 | 26 | UINT threadstarter( LPVOID pParam ) 27 | { 28 | CRtlSdr_CatalogDlg* data = (CRtlSdr_CatalogDlg*) pParam; 29 | data->ThreadFunction(); 30 | return 0; 31 | } 32 | 33 | 34 | // CAboutDlg dialog used for App About 35 | 36 | class CAboutDlg : public CDialogEx 37 | { 38 | public: 39 | CAboutDlg(); 40 | 41 | // Dialog Data 42 | enum { IDD = IDD_ABOUTBOX }; 43 | 44 | protected: 45 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support 46 | 47 | // Implementation 48 | protected: 49 | DECLARE_MESSAGE_MAP() 50 | }; 51 | 52 | CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD) 53 | { 54 | } 55 | 56 | void CAboutDlg::DoDataExchange(CDataExchange* pDX) 57 | { 58 | CDialogEx::DoDataExchange(pDX); 59 | } 60 | 61 | BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx) 62 | END_MESSAGE_MAP() 63 | 64 | 65 | // CRtlSdr_CatalogDlg dialog 66 | 67 | 68 | CRtlSdr_CatalogDlg::CRtlSdr_CatalogDlg(CWnd* pParent /*=NULL*/) 69 | : CDialogEx(CRtlSdr_CatalogDlg::IDD, pParent) 70 | , hDevNotify( NULL ) 71 | , threadRunning( NULL ) 72 | , threadPending( NULL ) 73 | , flagThread( NULL ) 74 | , flagThreadRunning( false ) 75 | , quiet( false ) 76 | { 77 | m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 78 | } 79 | 80 | void CRtlSdr_CatalogDlg::DoDataExchange(CDataExchange* pDX) 81 | { 82 | CDialogEx::DoDataExchange( pDX ); 83 | DDX_Control( pDX, IDC_FIND, m_ctlFind ); 84 | DDX_Control( pDX, IDC_RTLSDRLIST, m_ctl_MasterList ); 85 | } 86 | 87 | BEGIN_MESSAGE_MAP(CRtlSdr_CatalogDlg, CDialogEx) 88 | ON_WM_SYSCOMMAND() 89 | ON_WM_PAINT() 90 | ON_WM_QUERYDRAGICON() 91 | ON_WM_DESTROY() 92 | ON_BN_CLICKED(IDC_FIND, OnFind ) 93 | ON_WM_DEVICECHANGE() 94 | ON_CBN_DROPDOWN( IDC_DONGLE_LIST, OnCbnDropdownDongleList ) 95 | ON_COMMAND( ID_SHOW_MAIN_WND, OnShowWindow ) 96 | ON_COMMAND( ID_HIDE_MAIN_WND, OnHideWindow ) 97 | ON_WM_CLOSE() 98 | ON_COMMAND( ID_TRUE_EXIT, OnTrueExit ) 99 | ON_COMMAND(ID_EXIT, OnMenuExit) 100 | ON_BN_CLICKED(ID_REMOVE, OnBnClickedRemove ) 101 | ON_COMMAND( ID_UPDATELIST, OnUpdateStrings ) 102 | END_MESSAGE_MAP() 103 | 104 | 105 | // CRtlSdr_CatalogDlg message handlers 106 | 107 | BOOL CRtlSdr_CatalogDlg::OnInitDialog() 108 | { 109 | CDialogEx::OnInitDialog(); 110 | DWORD style = GetStyle(); 111 | // Add "About..." menu item to system menu. 112 | 113 | // IDM_ABOUTBOX must be in the system command range. 114 | ASSERT(( IDM_ABOUTBOX & 0xFFF0 ) == IDM_ABOUTBOX ); 115 | ASSERT( IDM_ABOUTBOX < 0xF000 ); 116 | 117 | CMenu* pSysMenu = GetSystemMenu( FALSE ); 118 | if ( pSysMenu != NULL ) 119 | { 120 | BOOL bNameValid; 121 | CString strAboutMenu; 122 | bNameValid = strAboutMenu.LoadString( IDS_ABOUTBOX ); 123 | ASSERT( bNameValid ); 124 | if ( !strAboutMenu.IsEmpty()) 125 | { 126 | pSysMenu->AppendMenu( MF_SEPARATOR ); 127 | pSysMenu->AppendMenu( MF_STRING, IDM_ABOUTBOX, strAboutMenu ); 128 | } 129 | } 130 | 131 | // Set the icon for this dialog. The framework does this automatically 132 | // when the application's main window is not a dialog 133 | SetIcon( m_hIcon, TRUE ); // Set big icon 134 | SetIcon( m_hIcon, FALSE ); // Set small icon 135 | 136 | // TODO: Add extra initialization here 137 | TRACE("I: Starting thread to create tray icon.\n"); 138 | 139 | TrayIcon = (CTrayIconManager*) 140 | AfxBeginThread( RUNTIME_CLASS( CTrayIconManager )); 141 | 142 | if ( !TrayIcon ) 143 | { 144 | TRACE( "W: FAILED TO CREATE TRAY THREAD!\n" ); 145 | PostQuitMessage( 0 ); 146 | } 147 | m_TrayIcon = &TrayIcon->m_TrayIcon; 148 | 149 | // The CWinThread will be automatically deleted on thread termination. 150 | 151 | if ( !donglelist.IsSharedMemoryActive()) 152 | { 153 | exit( 1 ); 154 | } 155 | RegisterForNotifications(); 156 | 157 | flagThreadRunning = true; 158 | flagThread = AfxBeginThread( flagthreadstarter, this ); 159 | if ( !quiet ) 160 | PostMessage( WM_COMMAND, ID_SHOW_MAIN_WND ); 161 | else 162 | PostMessage( WM_COMMAND, ID_HIDE_MAIN_WND ); 163 | 164 | PostMessage( WM_COMMAND, IDC_FIND ); 165 | 166 | return TRUE; // return TRUE unless you set the focus to a control 167 | } 168 | 169 | void CRtlSdr_CatalogDlg::OnSysCommand( UINT nID, LPARAM lParam ) 170 | { 171 | if (( nID & 0xFFF0 ) == IDM_ABOUTBOX ) 172 | { 173 | CAboutDlg dlgAbout; 174 | dlgAbout.DoModal(); 175 | } 176 | else 177 | { 178 | CDialogEx::OnSysCommand( nID, lParam ); 179 | } 180 | } 181 | 182 | // If you add a minimize button to your dialog, you will need the code below 183 | // to draw the icon. For MFC applications using the document/view model, 184 | // this is automatically done for you by the framework. 185 | 186 | void CRtlSdr_CatalogDlg::OnPaint( void ) 187 | { 188 | if ( IsIconic()) 189 | { 190 | CPaintDC dc( this ); // device context for painting 191 | 192 | SendMessage( WM_ICONERASEBKGND 193 | , reinterpret_cast ( dc.GetSafeHdc()) 194 | , 0 195 | ); 196 | 197 | // Center icon in client rectangle 198 | int cxIcon = GetSystemMetrics( SM_CXICON ); 199 | int cyIcon = GetSystemMetrics( SM_CYICON ); 200 | CRect rect; 201 | GetClientRect(&rect); 202 | int x = ( rect.Width() - cxIcon + 1 ) / 2; 203 | int y = ( rect.Height() - cyIcon + 1 ) / 2; 204 | 205 | // Draw the icon 206 | dc.DrawIcon( x, y, m_hIcon ); 207 | } 208 | else 209 | { 210 | CDialogEx::OnPaint(); 211 | } 212 | } 213 | 214 | // The system calls this function to obtain the cursor to display while the user drags 215 | // the minimized window. 216 | HCURSOR CRtlSdr_CatalogDlg::OnQueryDragIcon( void ) 217 | { 218 | return static_cast( m_hIcon ); 219 | } 220 | 221 | 222 | void CRtlSdr_CatalogDlg::OnDestroy( void ) 223 | { 224 | flagThreadRunning = false; 225 | int i = 0; 226 | while(( flagThread != NULL ) && ( i++ < 50 )) // One second to go away.... 227 | Sleep( 20 ); 228 | 229 | CDialogEx::OnDestroy(); 230 | 231 | if ( hDevNotify ) 232 | UnregisterDeviceNotification( hDevNotify ); 233 | } 234 | 235 | 236 | void CRtlSdr_CatalogDlg::OnFind( void ) 237 | { 238 | if ( threadRunning == NULL ) 239 | { 240 | m_ctlFind.EnableWindow( false ); 241 | m_ctl_MasterList.EnableWindow( false ); 242 | threadRunning = AfxBeginThread( threadstarter, this ); 243 | } 244 | else 245 | if ( threadPending == NULL ) 246 | threadPending = AfxBeginThread( threadstarter, this ); 247 | } 248 | 249 | 250 | void CRtlSdr_CatalogDlg::OnShowWindow( void ) 251 | { 252 | TRACE ("Tray maximizing\n"); 253 | if ( m_TrayIcon->WindowHidden()) 254 | CSystemTray::MaximiseFromTray( this ); 255 | else 256 | ShowWindow ( SW_NORMAL ); 257 | m_TrayIcon->SetMenuDefaultItem( ID_HIDE_MAIN_WND, FALSE ); 258 | } 259 | 260 | 261 | void CRtlSdr_CatalogDlg::OnHideWindow( void ) 262 | { 263 | TRACE ( "Tray minimizing\n" ); 264 | CSystemTray::MinimiseToTray( this ); 265 | m_TrayIcon->SetMenuDefaultItem( ID_SHOW_MAIN_WND, FALSE ); 266 | } 267 | 268 | 269 | void CRtlSdr_CatalogDlg::OnClose( void ) 270 | { 271 | OnHideWindow(); 272 | } 273 | 274 | 275 | void CRtlSdr_CatalogDlg::OnTrueExit( void ) 276 | { 277 | TrayIcon->PostThreadMessage( WM_QUIT, 0, 0 ); 278 | CDialog::OnCancel(); 279 | } 280 | 281 | 282 | void CRtlSdr_CatalogDlg::OnMenuExit( void ) 283 | { 284 | m_TrayIcon->PostMessage( WM_COMMAND, ID_TRUE_EXIT ); 285 | } 286 | 287 | 288 | void CRtlSdr_CatalogDlg::OnBnClickedRemove( void ) 289 | { 290 | // Remove entry from master list, dongle array, and registry 291 | // But do that only if the dongle is not found. 292 | int sel = m_ctl_MasterList.GetCurSel(); 293 | if ( sel < 0 ) 294 | return; 295 | // So it is an orphan entry. Remove it. 296 | // But ask first 297 | Dongle* dongle = &Dongles[ sel ]; 298 | if (( dongle->found < 0 ) 299 | // && ( dongle->vid != 0 ) // JD 20160336 let spurious entries 300 | // && ( dongle->pid != 0 ) // be deleted. 301 | ) 302 | { 303 | if ( dongle->busy ) 304 | { 305 | CString msg; 306 | msg = _T( "Dongle is in use." ); 307 | AfxMessageBox( msg, MB_ICONEXCLAMATION ); 308 | } 309 | if ( AfxMessageBox( _T( "Remove highlighted entry?" ), MB_OKCANCEL ) 310 | != IDOK ) 311 | return; 312 | // Dongles array - move entry + 1 to entry, until entry is empty. 313 | // And write updated registry. 314 | donglelist.RemoveDongle( sel ); 315 | m_ctl_MasterList.DeleteString( sel ); 316 | 317 | PostMessage( WM_COMMAND, IDC_FIND ); 318 | 319 | } 320 | } 321 | 322 | 323 | //#include 324 | //{A5DCBF10-6530-11D2-901F-00C04FB951ED} 325 | #define MY_DEFINE_GUID( name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8 ) \ 326 | EXTERN_C const GUID name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } 327 | 328 | MY_DEFINE_GUID( GUID_DEVINTERFACE_USB_DEVICE, 0xA5DCBF10L, 0x6530, 0x11D2, \ 329 | 0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED ); 330 | 331 | void CRtlSdr_CatalogDlg::RegisterForNotifications( void ) 332 | { 333 | if ( hDevNotify ) 334 | { 335 | return; 336 | } 337 | DEV_BROADCAST_DEVICEINTERFACE NotificationFilter; 338 | ZeroMemory( &NotificationFilter, sizeof( NotificationFilter )); 339 | NotificationFilter.dbcc_size = sizeof( DEV_BROADCAST_DEVICEINTERFACE ); 340 | NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; 341 | // assume we want to be notified with GUID_DEVINTERFACE_USB_DEVICE 342 | // to get notified with all interface on XP or above 343 | // ORed 3rd param with DEVICE_NOTIFY_ALL_INTERFACE_CLASSES and 344 | // dbcc_classguid will be ignored 345 | NotificationFilter.dbcc_classguid = GUID_DEVINTERFACE_USB_DEVICE; 346 | hDevNotify = RegisterDeviceNotification( this->GetSafeHwnd() 347 | , &NotificationFilter 348 | , DEVICE_NOTIFY_WINDOW_HANDLE 349 | ); 350 | if ( !hDevNotify ) 351 | { 352 | // error handling... 353 | TRACE( "RegisterDeviceNotification failed %d\n", GetLastError()); 354 | return; 355 | } 356 | TRACE( "\n" ); 357 | } 358 | 359 | BOOL CRtlSdr_CatalogDlg::OnDeviceChange( UINT nEvent 360 | , DWORD_PTR dwp 361 | ) 362 | { 363 | if ( !dwp ) 364 | return TRUE; // Do nothing. 365 | 366 | TRACE( "nEvent = %d (0x%x), dwp = 0x%x\n", nEvent, nEvent, dwp ); 367 | DEV_BROADCAST_HDR* hdr = (DEV_BROADCAST_HDR*) dwp; 368 | DEV_BROADCAST_DEVICEINTERFACE* di = (DEV_BROADCAST_DEVICEINTERFACE*) dwp; 369 | if ( dwp && ( hdr->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE )) 370 | { 371 | TRACE( "Device type %d (0x%x)\n", hdr->dbch_devicetype, hdr->dbch_devicetype ); 372 | switch( nEvent ) 373 | { 374 | case DBT_DEVICEARRIVAL: 375 | TRACE( "Info %s just appeared thread = 0x%x\n", di->dbcc_name, threadRunning ); 376 | // Start a thread to run GetCatalog() 377 | if ( threadRunning == NULL ) 378 | { 379 | m_ctl_MasterList.EnableWindow( false ); 380 | // Give USB time to get its beans in order. 381 | Sleep( 5000 ); 382 | threadRunning = AfxBeginThread( threadstarter, this ); 383 | } 384 | else 385 | if ( threadPending == NULL ) 386 | threadPending = AfxBeginThread( threadstarter, this ); 387 | break; 388 | case DBT_DEVICEREMOVECOMPLETE: 389 | TRACE( "Info %s just vanished thread = 0x%x\n", di->dbcc_name, threadRunning ); 390 | // Start a thread to run GetCatalog() 391 | if ( threadRunning == NULL ) 392 | threadRunning = AfxBeginThread( threadstarter, this ); 393 | else 394 | if ( threadPending == NULL ) 395 | threadPending = AfxBeginThread( threadstarter, this ); 396 | break; 397 | default: 398 | TRACE( "UNKNOWN EVENT TYPE\n" ); 399 | break; 400 | } 401 | } 402 | TRACE( "threadRunning = 0x%x this = 0x%x\n", threadRunning, this ); 403 | return TRUE; 404 | } 405 | 406 | 407 | void CRtlSdr_CatalogDlg::ThreadFunction( void ) 408 | { 409 | TRACE( "threadRunning = 0x%x this = 0x%x threadPending 0x%x\n" 410 | , threadRunning, this, threadPending ); 411 | m_ctlFind.EnableWindow( false ); 412 | 413 | DWORD one = threadPending != NULL ? ::GetThreadId( threadPending->m_hThread ) : NULL; 414 | DWORD two = ::GetCurrentThreadId(); 415 | TRACE( "Pending: %d this: %d\n", one, two ); 416 | while(( threadPending != NULL ) 417 | && ( ::GetThreadId( threadPending->m_hThread ) == ::GetCurrentThreadId())) 418 | { 419 | TRACE( "Pending: %d this: %d\n", one, two ); 420 | Sleep( 100 ); 421 | } 422 | TRACE( "Begin threadRunning 0x%x\n", threadRunning ); 423 | m_ctl_MasterList.EnableWindow( false ); 424 | m_ctl_MasterList.ResetContent(); 425 | donglelist.GetCatalog(); 426 | for( int i = 0; i < donglelist.GetCount(); i++ ) 427 | { 428 | CString manf; 429 | CString prod; 430 | CString sern; 431 | donglelist.GetStrings( i, manf, prod, sern ); 432 | char modifier = ' '; 433 | if ( !donglelist.IsFound( i )) 434 | modifier = '-'; 435 | else 436 | if ( donglelist.IsBusy( i )) 437 | modifier = 'B'; 438 | CString name; 439 | name.Format( _T( "%c%s" ) 440 | , modifier 441 | , _T( " " ) + manf + _T( "; " ) + prod + _T( "; " ) + sern 442 | ); 443 | m_ctl_MasterList.AddString( name ); 444 | } 445 | TRACE( "End threadRunning 0x%x\n", threadRunning ); 446 | if ( threadPending ) 447 | { 448 | TRACE( "Thread Pending\n" ); 449 | // Give USB time to get it's beans in order. 450 | Sleep( 5000 ); 451 | if ( threadPending ) 452 | // Let the pending thread run. 453 | threadRunning = threadPending; 454 | else 455 | m_ctl_MasterList.EnableWindow( true ); 456 | threadPending = NULL; 457 | return; 458 | } 459 | m_ctl_MasterList.EnableWindow( true ); 460 | threadRunning = NULL; 461 | m_ctlFind.EnableWindow( true ); 462 | } 463 | 464 | 465 | void CRtlSdr_CatalogDlg::OnCbnDropdownDongleList( void ) 466 | { 467 | while( threadRunning ) 468 | Sleep( 100 ); 469 | } 470 | 471 | 472 | void CRtlSdr_CatalogDlg::FlagThreadFunction( void ) 473 | { 474 | while( flagThreadRunning ) 475 | { 476 | donglelist.SetMasterPresent(); 477 | if ( donglelist.GetMasterUpdate()) 478 | { 479 | donglelist.SetMasterPresent(); 480 | PostMessage( WM_COMMAND, ID_UPDATELIST ); 481 | } 482 | Sleep( 10 ); 483 | } 484 | donglelist.SetMasterPresent( false ); 485 | flagThread = NULL; 486 | } 487 | 488 | 489 | void CRtlSdr_CatalogDlg::OnUpdateStrings( void ) 490 | { 491 | TRACE( "Update strings\n" ); 492 | Sleep( 300 ); 493 | m_ctl_MasterList.ResetContent(); 494 | for( int i = 0; i < donglelist.GetCount(); i++ ) 495 | { 496 | CString manf; 497 | CString prod; 498 | CString sern; 499 | donglelist.GetStrings( i, manf, prod, sern ); 500 | char modifier = ' '; 501 | if ( !donglelist.IsFound( i )) 502 | modifier = '-'; 503 | else 504 | if ( donglelist.IsBusy( i )) 505 | modifier = 'B'; 506 | CString name; 507 | name.Format( _T( "%c%s" ) 508 | , modifier 509 | , _T( " " ) + manf + _T( "; " ) + prod + _T( "; " ) + sern 510 | ); 511 | m_ctl_MasterList.AddString( name ); 512 | } 513 | } 514 | 515 | -------------------------------------------------------------------------------- /RtlSdr Catalog/RtlSdr_CatalogDlg.h: -------------------------------------------------------------------------------- 1 | 2 | // RtlSdr_CatalogDlg.h : header file 3 | // 4 | 5 | #pragma once 6 | #include "afxwin.h" 7 | #include "RtlSdrList.h" 8 | 9 | class CTrayIconManager; 10 | class CSystemTray; 11 | 12 | // CRtlSdr_CatalogDlg dialog 13 | class CRtlSdr_CatalogDlg : public CDialogEx 14 | { 15 | // Construction 16 | public: 17 | CRtlSdr_CatalogDlg ( CWnd* pParent = NULL ); // standard constructor 18 | 19 | // Dialog Data 20 | enum { IDD = IDD_RTLSDR_CATALOG_DIALOG }; 21 | 22 | protected: 23 | virtual void DoDataExchange ( CDataExchange* pDX ); // DDX/DDV support 24 | 25 | 26 | // Implementation 27 | protected: 28 | HICON m_hIcon; 29 | CButton m_ctlFind; 30 | CListBox m_ctl_MasterList; 31 | 32 | // Generated message map functions 33 | virtual BOOL OnInitDialog ( void ); 34 | afx_msg void OnSysCommand ( UINT nID 35 | , LPARAM lParam 36 | ); 37 | afx_msg void OnPaint ( void ); 38 | afx_msg HCURSOR OnQueryDragIcon ( void ); 39 | afx_msg void OnDestroy ( void ); 40 | afx_msg void OnFind ( void ); 41 | afx_msg BOOL OnDeviceChange ( UINT nEvent 42 | , DWORD_PTR dwp 43 | ); 44 | afx_msg void OnCbnDropdownDongleList ( void ); 45 | afx_msg void OnShowWindow ( void ); 46 | afx_msg void OnHideWindow ( void ); 47 | afx_msg void OnTrueExit ( void ); 48 | afx_msg void OnClose ( void ); 49 | afx_msg void OnMenuExit ( void ); 50 | afx_msg void OnBnClickedRemove ( void ); 51 | afx_msg void OnUpdateStrings ( void ); 52 | DECLARE_MESSAGE_MAP() 53 | 54 | void RegisterForNotifications( void ); 55 | 56 | public: 57 | void ThreadFunction ( void ); 58 | void FlagThreadFunction ( void ); 59 | 60 | protected: 61 | HDEVNOTIFY hDevNotify; 62 | RtlSdrList donglelist; 63 | CWinThread* threadRunning; 64 | CWinThread* threadPending; 65 | CWinThread* flagThread; 66 | CTrayIconManager* 67 | TrayIcon; 68 | CSystemTray* m_TrayIcon; 69 | bool flagThreadRunning; 70 | public: 71 | bool quiet; 72 | }; 73 | -------------------------------------------------------------------------------- /RtlSdr Catalog/SystemTray.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // SystemTray.h : header file 3 | // 4 | // Written by Chris Maunder (cmaunder@mail.com) 5 | // Copyright (c) 1998. 6 | // 7 | // This code may be used in compiled form in any way you desire. This 8 | // file may be redistributed unmodified by any means PROVIDING it is 9 | // not sold for profit without the authors written consent, and 10 | // providing that this notice and the authors name is included. If 11 | // the source code in this file is used in any commercial application 12 | // then acknowledgement must be made to the author of this file 13 | // (in whatever form you wish). 14 | // 15 | // This file is provided "as is" with no expressed or implied warranty. 16 | // 17 | // Expect bugs. 18 | // 19 | // Please use and enjoy. Please let me know of any bugs/mods/improvements 20 | // that you have found/implemented and I will fix/incorporate them into this 21 | // file. 22 | 23 | #pragma once 24 | 25 | #include 26 | #include // COleDateTime 27 | #include "InvisibleWnd.h" 28 | 29 | ///////////////////////////////////////////////////////////////////////////// 30 | // CSystemTray window 31 | 32 | class CSystemTray : public CWnd 33 | { 34 | // Construction/destruction 35 | public: 36 | CSystemTray ( void ); 37 | CSystemTray ( CWnd* pWnd 38 | , UINT uCallbackMessage 39 | , LPCTSTR szTip 40 | , HICON icon 41 | , UINT uID 42 | , BOOL bhidden = FALSE 43 | , LPCTSTR szBalloonTip = NULL 44 | , LPCTSTR szBalloonTitle = NULL 45 | , DWORD dwBalloonIcon = NIIF_NONE 46 | , UINT uBalloonTimeout = 10 47 | ); 48 | virtual ~CSystemTray(); 49 | 50 | DECLARE_DYNAMIC( CSystemTray ) 51 | 52 | // Operations 53 | public: 54 | BOOL Enabled ( void ) { return m_bEnabled; } 55 | BOOL Visible ( void ) { return !m_bHidden; } // icon state, not window state! 56 | BOOL WindowHidden ( void ) { return m_bWindowHidden; } 57 | 58 | // Create the tray icon 59 | BOOL Create ( CWnd* pParent 60 | , UINT uCallbackMessage 61 | , LPCTSTR szTip 62 | , HICON icon 63 | , UINT uID 64 | , BOOL bHidden = FALSE 65 | , LPCTSTR szBalloonTip = NULL 66 | , LPCTSTR szBalloonTitle = NULL 67 | , DWORD dwBalloonIcon = NIIF_NONE 68 | , UINT uBalloonTimeout = 10 69 | ); 70 | 71 | // Change or retrieve the Tooltip text 72 | BOOL SetTooltipText ( LPCTSTR pszTooltipText ); 73 | BOOL SetTooltipText ( UINT nID ); 74 | CString GetTooltipText ( void ) const; 75 | 76 | // Change or retrieve the icon displayed 77 | BOOL SetIcon ( HICON hIcon ); 78 | BOOL SetIcon ( LPCTSTR lpszIconName ); 79 | BOOL SetIcon ( UINT nIDResource ); 80 | BOOL SetStandardIcon ( LPCTSTR lpIconName ); 81 | BOOL SetStandardIcon ( UINT nIDResource ); 82 | HICON GetIcon ( void ) const; 83 | 84 | void SetFocus ( void ); 85 | BOOL HideIcon ( void ); 86 | BOOL ShowIcon ( void ); 87 | BOOL AddIcon ( void ); 88 | BOOL RemoveIcon ( void ); 89 | BOOL MoveToRight ( void ); 90 | 91 | BOOL ShowBalloon ( LPCTSTR szText 92 | , LPCTSTR szTitle = NULL 93 | , DWORD dwIcon = NIIF_NONE 94 | , UINT uTimeout = 10 95 | ); 96 | 97 | // For icon animation 98 | BOOL SetIconList ( UINT uFirstIconID 99 | , UINT uLastIconID 100 | ); 101 | BOOL SetIconList ( HICON* pHIconList 102 | , UINT nNumIcons 103 | ); 104 | BOOL Animate ( UINT nDelayMilliSeconds 105 | , int nNumSeconds = -1 106 | ); 107 | BOOL StepAnimation ( void ); 108 | BOOL StopAnimation ( void ); 109 | 110 | // Change menu default item 111 | void GetMenuDefaultItem ( UINT& uItem, BOOL& bByPos ); 112 | BOOL SetMenuDefaultItem ( UINT uItem, BOOL bByPos ); 113 | 114 | // Change or retrieve the window to send notification messages to 115 | BOOL SetNotificationWnd ( CWnd* pNotifyWnd ); 116 | CWnd* GetNotificationWnd ( void ) const; 117 | 118 | // Change or retrieve the window to send menu commands to 119 | BOOL SetTargetWnd ( CWnd* pTargetWnd ); 120 | CWnd* GetTargetWnd ( void ) const; 121 | 122 | // Change or retrieve notification messages sent to the window 123 | BOOL SetCallbackMessage ( UINT uCallbackMessage ); 124 | UINT GetCallbackMessage ( void ) const; 125 | 126 | UINT_PTR GetTimerID ( void ) const { return m_nTimerID; } 127 | 128 | // Static functions 129 | public: 130 | static void MinimiseToTray ( CWnd* pWnd 131 | , BOOL bForceAnimation = FALSE 132 | ); 133 | static void MaximiseFromTray ( CWnd* pWnd 134 | , BOOL bForceAnimation = FALSE 135 | ); 136 | 137 | public: 138 | // Default handler for tray notification message 139 | virtual LRESULT OnTrayNotification ( WPARAM uID 140 | , LPARAM lEvent 141 | ); 142 | 143 | // Overrides 144 | // ClassWizard generated virtual function overrides 145 | //{{AFX_VIRTUAL(CSystemTray) 146 | protected: 147 | virtual LRESULT WindowProc ( UINT message 148 | , WPARAM wParam 149 | , LPARAM lParam 150 | ); 151 | //}}AFX_VIRTUAL 152 | 153 | // Implementation 154 | protected: 155 | void Initialise ( void ); 156 | void InstallIconPending ( void ); 157 | 158 | virtual void CustomizeMenu ( CMenu* ) {} // Used for customizing the menu 159 | 160 | // Implementation 161 | protected: 162 | NOTIFYICONDATA m_tnd; 163 | BOOL m_bEnabled; // does O/S support tray icon? 164 | BOOL m_bHidden; // Has the icon been hidden? 165 | BOOL m_bRemoved; // Has the icon been removed? 166 | BOOL m_bShowIconPending; // Show the icon once tha taskbar has been created 167 | BOOL m_bWin2K; // Use new W2K features? 168 | CWnd* m_pTargetWnd; // Window that menu commands are sent 169 | 170 | CArray< HICON, HICON > m_IconList; 171 | UINT_PTR m_uIDTimer; 172 | INT_PTR m_nCurrentIcon; 173 | COleDateTime m_StartTime; 174 | UINT m_nAnimationPeriod; 175 | HICON m_hSavedIcon; 176 | UINT m_DefaultMenuItemID; 177 | BOOL m_DefaultMenuItemByPos; 178 | UINT m_uCreationFlags; 179 | 180 | // Static data 181 | protected: 182 | static BOOL RemoveTaskbarIcon ( CWnd* pWnd ); 183 | 184 | static const UINT m_nTimerID; 185 | static UINT m_nMaxTooltipLength; 186 | static const UINT m_nTaskbarCreatedMsg; 187 | static CInvisibleWnd m_wndInvisible; 188 | static BOOL m_bWindowHidden; // window is hidden 189 | 190 | static BOOL GetW2K ( void ); 191 | #ifndef _WIN32_WCE 192 | static void GetTrayWndRect ( LPRECT lprect ); 193 | static BOOL GetDoWndAnimation(); 194 | #endif 195 | 196 | // Generated message map functions 197 | protected: 198 | //{{AFX_MSG(CSystemTray) 199 | afx_msg void OnTimer ( UINT_PTR nIDEvent ); 200 | //}}AFX_MSG 201 | #ifndef _WIN32_WCE 202 | afx_msg void OnSettingChange ( UINT uFlags 203 | , LPCTSTR lpszSection 204 | ); 205 | #endif 206 | LRESULT OnTaskbarCreated ( WPARAM wParam 207 | , LPARAM lParam 208 | ); 209 | LRESULT OnDumpRequest ( WPARAM wParam 210 | , LPARAM lParam 211 | ); 212 | 213 | afx_msg void OnShowMainWnd ( void ); 214 | afx_msg void OnUpdateShowMainWnd ( CCmdUI* pCmdUI ); 215 | afx_msg void OnHideMainWnd ( void ); 216 | afx_msg void OnUpdateHideMainWnd ( CCmdUI* pCmdUI ); 217 | afx_msg void OnAppExit ( void ); 218 | afx_msg void OnAppAbout ( void ); 219 | 220 | DECLARE_MESSAGE_MAP() 221 | }; 222 | 223 | -------------------------------------------------------------------------------- /RtlSdr Catalog/TrayIconManager.cpp: -------------------------------------------------------------------------------- 1 | // TrayIconManager.cpp : implementation file 2 | // 3 | 4 | #include "stdafx.h" 5 | #include "RtlSdr_Catalog.h" 6 | #include "TrayIconManager.h" 7 | 8 | #ifdef _DEBUG 9 | #define new DEBUG_NEW 10 | #undef THIS_FILE 11 | static char THIS_FILE[] = __FILE__; 12 | #endif 13 | 14 | ///////////////////////////////////////////////////////////////////////////// 15 | // CTrayIconManager 16 | 17 | IMPLEMENT_DYNCREATE( CTrayIconManager, CWinThread ) 18 | 19 | CTrayIconManager::CTrayIconManager( void ) 20 | { 21 | 22 | } 23 | 24 | CTrayIconManager::~CTrayIconManager( void ) 25 | { 26 | } 27 | 28 | BOOL CTrayIconManager::InitInstance( void ) 29 | { 30 | HICON hIcon = ::LoadIcon( AfxGetResourceHandle() 31 | , MAKEINTRESOURCE( IDR_MAINFRAME ) // Icon to use 32 | ); 33 | 34 | TRACE ( "I: Creating Tray Notification icon.\n" ); 35 | // Create the tray icon 36 | 37 | if ( !m_TrayIcon.Create( NULL // Let icon deal with its own messages 38 | , WM_ICON_NOTIFY // Icon notify message to use 39 | , _T( "RtlSdr Catalog Control" ) // tooltip 40 | , hIcon 41 | , IDR_TRAY_POPUP // ID of tray icon 42 | , false 43 | , NULL //_T( "RtlSdr Catalog is starting" ), // balloon tip 44 | , _T( "RtlSdr Catalog" ) // balloon title 45 | , NIIF_INFO // balloon icon 46 | , 10 // balloon timeout 47 | )) 48 | { 49 | TRACE ( "W: Failed to create tray notification icon!\n" ); 50 | } 51 | else 52 | { 53 | TRACE ( "I: Tray notification icon created.\n" ); 54 | 55 | m_TrayIcon.ShowBalloon( _T( "Initializing\r\nThis may take a minute..." ) 56 | , _T( "RtlSdr Catalog" ) 57 | , NIIF_INFO 58 | , 10 // display time 59 | ); 60 | 61 | m_TrayIcon.SetMenuDefaultItem( 2, TRUE ); // default is minimize or show 62 | } 63 | return TRUE; 64 | } 65 | 66 | int CTrayIconManager::ExitInstance( void ) 67 | { 68 | // TODO: perform any per-thread cleanup here 69 | return CWinThread::ExitInstance(); 70 | } 71 | 72 | BEGIN_MESSAGE_MAP( CTrayIconManager, CWinThread ) 73 | //{{AFX_MSG_MAP(CTrayIconManager) 74 | // NOTE - the ClassWizard will add and remove mapping macros here. 75 | //}}AFX_MSG_MAP 76 | END_MESSAGE_MAP() 77 | 78 | ///////////////////////////////////////////////////////////////////////////// 79 | // CTrayIconManager message handlers 80 | 81 | bool CTrayIconManager::ShowBalloon( const char *body 82 | , const char *title 83 | , DWORD flags 84 | , int seconds 85 | ) 86 | { 87 | tray_message msg; 88 | msg.message = body; 89 | msg.header = title; 90 | msg.flags = flags; 91 | msg.time = seconds; 92 | 93 | message_queue.AddTail( msg ); 94 | 95 | return true; // it always works! 96 | } 97 | 98 | BOOL CTrayIconManager::OnIdle( LONG lCount ) 99 | { 100 | if ( m_TrayIcon.m_hWnd != NULL && message_queue.GetCount() > 0 ) 101 | { 102 | tray_message msg = message_queue.GetHead(); 103 | message_queue.RemoveHead(); 104 | 105 | m_TrayIcon.ShowBalloon( msg.message 106 | , msg.header 107 | , msg.flags 108 | , msg.time 109 | ); 110 | } 111 | 112 | return CWinThread::OnIdle( lCount ); 113 | } 114 | -------------------------------------------------------------------------------- /RtlSdr Catalog/TrayIconManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // TrayIconManager.h : header file 4 | // 5 | 6 | #include "SystemTray.h" 7 | 8 | 9 | ///////////////////////////////////////////////////////////////////////////// 10 | // CTrayIconManager thread 11 | 12 | class CTrayIconManager : public CWinThread 13 | { 14 | DECLARE_DYNCREATE( CTrayIconManager ) 15 | protected: 16 | CTrayIconManager ( void ); // protected constructor used by dynamic creation 17 | 18 | // Attributes 19 | public: 20 | CSystemTray m_TrayIcon; 21 | 22 | // Operations 23 | public: 24 | virtual bool ShowBalloon ( const char *body 25 | , const char* title 26 | , DWORD flags 27 | , int seconds = 10 28 | ); 29 | 30 | // Overrides 31 | public: 32 | virtual BOOL InitInstance ( void ); 33 | virtual int ExitInstance ( void ); 34 | virtual BOOL OnIdle ( LONG lCount ); 35 | 36 | // Implementation 37 | protected: 38 | virtual ~CTrayIconManager ( void ); 39 | 40 | DECLARE_MESSAGE_MAP() 41 | 42 | class tray_message 43 | { 44 | public: 45 | CString message; 46 | CString header; 47 | DWORD flags; 48 | DWORD time; 49 | }; 50 | 51 | CList < tray_message, tray_message& > message_queue; 52 | }; 53 | -------------------------------------------------------------------------------- /RtlSdr Catalog/res/RtlSdr_Catalog.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-jdow/rtlsdr-Cplusplus-VS2010/fba0ae3e8a0314c1581c07ac56ad67180fbec72f/RtlSdr Catalog/res/RtlSdr_Catalog.ico -------------------------------------------------------------------------------- /RtlSdr Catalog/res/RtlSdr_Catalog.rc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-jdow/rtlsdr-Cplusplus-VS2010/fba0ae3e8a0314c1581c07ac56ad67180fbec72f/RtlSdr Catalog/res/RtlSdr_Catalog.rc2 -------------------------------------------------------------------------------- /RtlSdr Catalog/resource.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-jdow/rtlsdr-Cplusplus-VS2010/fba0ae3e8a0314c1581c07ac56ad67180fbec72f/RtlSdr Catalog/resource.h -------------------------------------------------------------------------------- /RtlSdr Catalog/stdafx.cpp: -------------------------------------------------------------------------------- 1 | 2 | // stdafx.cpp : source file that includes just the standard includes 3 | // rtlsdr_service_test.pch will be the pre-compiled header 4 | // stdafx.obj will contain the pre-compiled type information 5 | 6 | #include "stdafx.h" 7 | 8 | 9 | -------------------------------------------------------------------------------- /RtlSdr Catalog/stdafx.h: -------------------------------------------------------------------------------- 1 | 2 | // stdafx.h : include file for standard system include files, 3 | // or project specific include files that are used frequently, 4 | // but are changed infrequently 5 | 6 | #pragma once 7 | 8 | #ifndef _SECURE_ATL 9 | #define _SECURE_ATL 1 10 | #endif 11 | 12 | #ifndef VC_EXTRALEAN 13 | #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers 14 | #endif 15 | 16 | #include "targetver.h" 17 | 18 | #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit 19 | 20 | // turns off MFC's hiding of some common and often safely ignored warning messages 21 | #define _AFX_ALL_WARNINGS 22 | 23 | #include // MFC core and standard components 24 | #include // MFC extensions 25 | 26 | 27 | 28 | 29 | 30 | #ifndef _AFX_NO_OLE_SUPPORT 31 | #include // MFC support for Internet Explorer 4 Common Controls 32 | #endif 33 | #ifndef _AFX_NO_AFXCMN_SUPPORT 34 | #include // MFC support for Windows Common Controls 35 | #endif // _AFX_NO_AFXCMN_SUPPORT 36 | 37 | #include // MFC support for ribbons and control bars 38 | 39 | #include "afxmt.h" // needed for MFC support for mutex. 40 | 41 | 42 | #define WM_ICON_NOTIFY ( WM_APP + 10 ) 43 | 44 | 45 | 46 | 47 | 48 | #ifdef _UNICODE 49 | #if defined _M_IX86 50 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") 51 | #elif defined _M_X64 52 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") 53 | #else 54 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") 55 | #endif 56 | #endif 57 | 58 | 59 | #if defined( _M_X64 ) 60 | #ifndef rtlsdr_STATIC 61 | #pragma comment( lib, "..\\libusb\\MS64\\dll\\libusb-1.0.lib" ) 62 | #else 63 | #pragma comment( lib, "..\\libusb\\MS64\\static\\libusb-1.0.lib" ) 64 | #endif 65 | #else 66 | #ifndef rtlsdr_STATIC 67 | #pragma comment( lib, "..\\libusb\\MS32\\dll\\libusb-1.0.lib" ) 68 | #else 69 | #pragma comment( lib, "..\\libusb\\MS32\\static\\libusb-1.0.lib" ) 70 | #endif 71 | #endif 72 | -------------------------------------------------------------------------------- /RtlSdr Catalog/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Including SDKDDKVer.h defines the highest available Windows platform. 4 | 5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and 6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /User Notes.txt: -------------------------------------------------------------------------------- 1 | PLEASE PLEASE read me. 2 | 3 | Some history 4 | ============ 5 | This version of rtlsdr.dll is rewritten, with considerable cut and paste, from 6 | Steve Markgraf's original distribution version source for rtlsdr.dll plus 7 | contributions from Oliver Jowette, Dimitri Stolnikov, 8 | Kyle Keen, and others. 9 | It was redone in Visual Studio 2010 as a C++ project. Joanne Dow added the dongle 10 | memory facility as registry entries. 11 | 12 | Source code is available on GitHub: 13 | https://github.com/ms-jdow/rtlsdr-Cplusplus-VS2010 14 | 15 | User Notes 16 | ========== 17 | This version provides two significantly different behaviors visible to users. 18 | 19 | The first is a memory in the registry for all dongles seen such that they can 20 | appear in application drop lists even if busy. This makes the user experience 21 | less confusing. 22 | 23 | The second overcomes a "feature" of Microsoft's WinUSB.sys and libusb_1.0.dll 24 | in combination. When renaming dongles with the old versions of rtlsdr.dll you 25 | had to remove the dongle and replace it to make the rename stick. The technique 26 | used in the old dongles to read the dongle particulars actually read from cached 27 | values rather than the dongle itself. This version of rtlsdr.dll reads directly 28 | from the dongles if it deems the stored data to be stale. 29 | 30 | Note that all known dongles are shown all the time. Those which are busy or are 31 | not present are displayed with a leading asterisk. '*'. on the device name and 32 | the Vendor ID. 33 | 34 | Unfortunately, the second feature means that the first time you accecss a batch 35 | of dongles via this family of dlls after a long enough delay involves going off 36 | and reading data from each dongle. Unfortunately this can take awhile with this 37 | version. If you have a batch of dongles it can take several seconds before 38 | applications wake up. On the other hand, subsequent accesses within about 3 39 | minutes are very fast as data cached in the Windows registry is considered 40 | valid and used instead of reading the dongle directly. 41 | 42 | With the correct SDRSharp.RTLUSB.dll (for SDRSharp) or SDRSourceRTL2832U.dll 43 | (for SDR-Radio) this DLL provides options for three stages of gain control 44 | direct access or three gain profiles for a unified gain control in addition 45 | to the registry based data caching. 46 | 47 | -------------------------------------------------------------------------------- /dllmain.cpp: -------------------------------------------------------------------------------- 1 | // dllmain.cpp : Defines the entry point for the DLL application. 2 | #include "stdafx.h" 3 | 4 | BOOL APIENTRY DllMain( HMODULE hModule, 5 | DWORD ul_reason_for_call, 6 | LPVOID lpReserved 7 | ) 8 | { 9 | switch (ul_reason_for_call) 10 | { 11 | case DLL_PROCESS_ATTACH: 12 | case DLL_THREAD_ATTACH: 13 | case DLL_THREAD_DETACH: 14 | case DLL_PROCESS_DETACH: 15 | break; 16 | } 17 | return TRUE; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /librtlsdr.h: -------------------------------------------------------------------------------- 1 | // librtlsdr.h // Defines the rtlsdr_dev class. 2 | 3 | #pragma once 4 | 5 | #define _DUMMY_ { return -1; } 6 | 7 | #include "libusb/libusb.h" 8 | #include "ITuner.h" 9 | #include "rtl-sdr.h" 10 | #include "DongleArrays.h" 11 | #include "Recognized Dongles.h" 12 | #include "MyMutex.h" 13 | #include "IRtlSdr.h" 14 | #include "SharedMemoryFile.h" 15 | 16 | #define FIR_LEN 16 17 | #define STATIC 18 | 19 | class e4kTuner; 20 | class fc0012Tuner; 21 | class fc0013Tuner; 22 | class fc2580Tuner; 23 | class r82xxTuner; 24 | 25 | typedef BYTE usbpath_t[ MAX_USB_PATH ]; 26 | 27 | // Stages is a private mode to emphasize per stage control. 28 | #define MAX_TUNER_GAIN_MODES GAIN_MODE_STAGES 29 | 30 | #define STR_OFFSET 9 // EEPROM string offset. 31 | 32 | class /*SDRDAPI */ rtlsdr : public IRtlSdr 33 | { 34 | public: 35 | rtlsdr ( void ); 36 | ~rtlsdr ( void ); // Unwind tuners. 37 | 38 | protected: 39 | friend e4kTuner; 40 | friend fc0012Tuner; 41 | friend fc0013Tuner; 42 | friend fc2580Tuner; 43 | friend r82xxTuner; 44 | 45 | // Registry and data parsing are handled in the registry and names class 46 | #include "librtlsdr_registryAndNames.h" 47 | // Dongle communications are handled by the rtlsdr_dongle_comms class 48 | #include "librtlsdr_dongle_comms.h" 49 | 50 | protected: // The real work. 51 | STATIC bool test_busy ( uint32_t index ); 52 | int basic_open ( uint32_t index 53 | , struct libusb_device_descriptor *out_dd 54 | , bool devindex 55 | ); 56 | int claim_opened_device ( void ); 57 | 58 | 59 | int rtlsdr_set_fir ( void ); 60 | int rtlsdr_set_if_freq ( uint32_t freq 61 | , uint32_t *freq_out 62 | ); 63 | int set_spectrum_inversion ( int inverted ); 64 | int rtlsdr_set_sample_freq_correction 65 | ( int ppm ); 66 | int rtlsdr_get_usb_strings_canonical 67 | ( CString& manufact 68 | , CString& product 69 | , CString& serial 70 | ); 71 | int rtlsdr_get_usb_strings_canonical 72 | ( char *manufact 73 | , char *product 74 | , char *serial 75 | ); 76 | int rtlsdr_open_ ( uint32_t index 77 | , bool devindex = true 78 | ); 79 | int rtlsdr_do_direct_sampling ( bool on ); 80 | 81 | public: 82 | int rtlsdr_set_xtal_freq ( uint32_t rtl_freq 83 | , uint32_t tuner_freq 84 | ); 85 | int rtlsdr_get_xtal_freq ( uint32_t *rtl_freq 86 | , uint32_t *tuner_freq 87 | ); 88 | int rtlsdr_write_eeprom ( uint8_t *data 89 | , uint8_t offset 90 | , uint16_t len 91 | ); 92 | int rtlsdr_read_eeprom ( uint8_t *data 93 | , uint8_t offset 94 | , uint16_t len 95 | ); 96 | int rtlsdr_read_eeprom ( eepromdata& data ); 97 | int rtlsdr_set_center_freq ( uint32_t in_freq ); 98 | uint32_t rtlsdr_get_center_freq ( void ); 99 | int rtlsdr_set_freq_correction ( int ppm ); 100 | int rtlsdr_get_freq_correction 101 | ( void ); 102 | int rtlsdr_get_tuner_type ( void ); 103 | int rtlsdr_get_tuner_gains ( int *gains ); 104 | int rtlsdr_set_tuner_gain ( int gain ); 105 | int rtlsdr_get_tuner_gain ( void ); 106 | int rtlsdr_set_tuner_if_gain ( int stage 107 | , int gain 108 | ); 109 | int rtlsdr_get_tuner_stage_gains( uint8_t stage 110 | , int32_t *gains 111 | , char *description 112 | ); 113 | int rtlsdr_get_tuner_stage_count( void ); 114 | int rtlsdr_set_tuner_stage_gain ( uint8_t stage 115 | , int32_t gain 116 | ); 117 | int rtlsdr_get_tuner_stage_gain ( uint8_t stage ); 118 | int rtlsdr_set_tuner_gain_mode ( int mode ); 119 | int rtlsdr_get_tuner_bandwidths ( int *bandwidths ); 120 | int rtlsdr_set_tuner_bandwidth ( int bandwidth ); 121 | int rtlsdr_get_tuner_bandwidths_safe 122 | ( int *bandwidths 123 | , int in_len 124 | ); 125 | int rtlsdr_get_bandwidth_set_name 126 | ( int nSet 127 | , char* pString 128 | ); 129 | int rtlsdr_set_bandwidth_set ( int nSet ); 130 | 131 | int rtlsdr_set_sample_rate ( uint32_t samp_rate ); 132 | uint32_t rtlsdr_get_sample_rate ( void ); 133 | uint32_t rtlsdr_get_corr_sample_rate ( void ); 134 | int rtlsdr_set_testmode ( int on ); 135 | int rtlsdr_set_agc_mode ( int on ); 136 | int rtlsdr_set_bias_tee ( int on ); 137 | int rtlsdr_set_gpio_bit ( int bit 138 | , int enable 139 | , int on 140 | ); 141 | int rtlsdr_get_gpio_bit ( int bit ); 142 | int rtlsdr_set_direct_sampling ( int on ); 143 | int rtlsdr_get_direct_sampling 144 | ( void ); 145 | int rtlsdr_set_offset_tuning ( int on ); 146 | int rtlsdr_get_offset_tuning ( void ); 147 | int rtlsdr_set_dithering ( int dither ); 148 | // int rtlsdr_get_tuner_type ( int index ); 149 | int rtlsdr_open ( uint32_t index ); 150 | int rtlsdr_close ( void ); 151 | uint32_t rtlsdr_get_tuner_clock ( void ); 152 | int rtlsdr_get_usb_strings ( char *manufact 153 | , char *product 154 | , char *serial 155 | ); 156 | int rtlsdr_get_usb_cstrings ( CString& manufact 157 | , CString& product 158 | , CString& serial 159 | ); 160 | uint32_t rtlsdr_get_device_count ( void ); 161 | const char *rtlsdr_get_device_name ( uint32_t index ); 162 | int rtlsdr_get_device_usb_strings 163 | ( uint32_t index 164 | , char *manufact 165 | , char *product 166 | , char *serial 167 | ); 168 | int rtlsdr_get_device_usb_cstrings 169 | ( uint32_t index 170 | , CString& manufact 171 | , CString& product 172 | , CString& serial 173 | ); 174 | int rtlsdr_get_index_by_serial ( const char *serial ); 175 | 176 | int rtlsdr_get_tuner_type ( int index ); 177 | #if defined SET_SPECIAL_FILTER_VALUES 178 | int rtlsdr_set_if_values ( rtlsdr_dev_t *dev 179 | , BYTE regA 180 | , BYTE regB 181 | , DWORD ifFreq 182 | ); 183 | #endif 184 | 185 | public: 186 | // Static functions 187 | STATIC uint32_t 188 | srtlsdr_get_device_count ( void ); 189 | STATIC const char * 190 | srtlsdr_get_device_name ( uint32_t index ); 191 | STATIC int srtlsdr_get_device_usb_strings 192 | ( uint32_t index 193 | , char *manufact 194 | , char *product 195 | , char *serial 196 | ); 197 | STATIC int srtlsdr_get_device_usb_strings 198 | ( uint32_t index 199 | , CString& manufact 200 | , CString& product 201 | , CString& serial 202 | ); 203 | STATIC int srtlsdr_get_index_by_serial ( const char *serial ); 204 | protected: 205 | STATIC int rtlsdr_static_get_tuner_type( int index ); 206 | STATIC int srtlsdr_eep_img_from_Dongle ( eepromdata& dat 207 | , Dongle* regentry 208 | ); 209 | STATIC void GetCatalog ( void ); 210 | STATIC bool reinitDongles ( void ); 211 | STATIC bool TestMaster ( void ); 212 | 213 | private: 214 | void ClearVars ( void ); 215 | 216 | private: 217 | STATIC SharedMemoryFile SharedDongleData; 218 | RtlSdrAreaDef* RtlSdrArea; 219 | Dongle* Dongles; 220 | /* rtl demod context */ 221 | uint32_t rate; /* Hz */ 222 | uint32_t rtl_xtal; /* Hz */ 223 | int fir[ FIR_LEN ]; 224 | int direct_sampling; 225 | int is_direct_sampling; 226 | /* tuner context */ 227 | enum rtlsdr_tuner tuner_type; 228 | ITuner * tuner; 229 | uint32_t tun_xtal; /* Hz */ 230 | uint32_t freq; /* Hz */ 231 | uint32_t offs_freq; /* Hz */ 232 | uint32_t effective_freq; /* Hz */ 233 | uint32_t nominal_if_freq; /* Hz */ 234 | int corr; /* ppm */ 235 | int gain; /* tenth dB */ 236 | int gain_mode; 237 | int rtl_gain_mode; 238 | int bias_tee; 239 | int ditheron; 240 | int tuner_bw_set; 241 | int tuner_bw_val; 242 | /* status */ 243 | ITuner* tunerset[ RTLSDR_TUNER_R828D + 1 ]; 244 | 245 | 246 | int tuner_initialized; 247 | int spectrum_inversion; 248 | int active_index; 249 | 250 | static int inReinitDongles; // conditions some fprintfs 251 | 252 | private: 253 | static CStringA RtlSdrVersionString; 254 | static __int64 RtlSdrVersion64; 255 | 256 | public: 257 | const char* rtlsdr_get_version ( void ); 258 | STATIC const char* 259 | srtlsdr_get_version ( void ); 260 | unsigned __int64 261 | rtlsdr_get_version_int64( void ); 262 | STATIC unsigned __int64 263 | srtlsdr_get_version_int64 264 | ( void ); 265 | }; 266 | 267 | extern IRtlSdr* myrtlsdr; 268 | -------------------------------------------------------------------------------- /librtlsdr_dongle_comms.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // NB. This is meant to be included in librtlsdr.h as part of the 4 | // rtlsdr class. It's broken out this way for over all clarity. 5 | 6 | enum rtlsdr_async_status 7 | { 8 | RTLSDR_INACTIVE = 0, 9 | RTLSDR_CANCELING, 10 | RTLSDR_RUNNING 11 | }; 12 | 13 | #define BULK_TIMEOUT 0 14 | 15 | typedef void(*rtlsdr_read_async_cb_t)(unsigned char *buf, uint32_t len, void *ctx); 16 | 17 | #if 0 18 | class rtlsdr_dongle_comms 19 | { 20 | public: 21 | rtlsdr_dongle_comms(void); 22 | ~rtlsdr_dongle_comms(void); 23 | #endif 24 | 25 | public: // Basic comms 26 | libusb_device_handle* 27 | GetDeviceHandle ( void ) { return devh; } 28 | 29 | protected: // Basic comms 30 | int rtlsdr_read_array ( uint8_t block 31 | , uint16_t addr 32 | , uint8_t *data 33 | , uint8_t len 34 | ); 35 | int rtlsdr_write_array ( uint8_t block 36 | , uint16_t addr 37 | , uint8_t *data 38 | , uint8_t len 39 | ); 40 | int rtlsdr_i2c_write_reg ( uint8_t i2c_addr 41 | , uint8_t reg 42 | , uint8_t val 43 | ); 44 | uint8_t rtlsdr_i2c_read_reg ( uint8_t i2c_addr 45 | , uint8_t reg 46 | ); 47 | int rtlsdr_i2c_write ( uint8_t i2c_addr 48 | , uint8_t *buffer 49 | , int len 50 | ); 51 | int rtlsdr_i2c_read ( uint8_t i2c_addr 52 | , uint8_t *buffer 53 | , int len 54 | ); 55 | uint16_t rtlsdr_read_reg ( uint8_t block 56 | , uint16_t addr 57 | , uint8_t len 58 | ); 59 | int rtlsdr_write_reg ( uint8_t block 60 | , uint16_t addr 61 | , uint16_t val 62 | , uint8_t len 63 | ); 64 | uint16_t rtlsdr_demod_read_reg ( uint8_t page 65 | , uint16_t addr 66 | , uint8_t len); 67 | int rtlsdr_demod_write_reg ( uint8_t page 68 | , uint16_t addr 69 | , uint16_t val 70 | , uint8_t len 71 | ); 72 | void _rtlsdr_set_gpio_bit ( uint8_t gpio 73 | , int val 74 | ); 75 | int _rtlsdr_get_gpio_bit ( uint8_t gpio ); 76 | void rtlsdr_set_gpio_output ( uint8_t gpio ); 77 | void rtlsdr_set_gpio_input ( uint8_t gpio ); 78 | int rtlsdr_get_gpio_output ( uint8_t gpio ); 79 | void rtlsdr_set_i2c_repeater ( int on ); 80 | int rtlsdr_i2c_write_fn ( uint8_t addr 81 | , uint8_t *buf 82 | , int len 83 | ); 84 | int rtlsdr_i2c_read_fn ( uint8_t addr 85 | , uint8_t *buf 86 | , int len 87 | ); 88 | int rtlsdr_write_eeprom_raw ( eepromdata& data ); 89 | int rtlsdr_read_eeprom_raw ( eepromdata& data ); 90 | 91 | public: 92 | int GetOpenedDeviceIndex ( void ) 93 | { 94 | return GetDongleIndexFromDongle( m_dongle ); 95 | } 96 | 97 | public: // Read and write bulk transfers 98 | int rtlsdr_reset_buffer ( void ); 99 | int rtlsdr_read_sync ( BYTE *buf 100 | , int len 101 | , int *n_read 102 | ); 103 | int rtlsdr_wait_async ( rtlsdr_read_async_cb_t cb 104 | , void *ctx 105 | ); 106 | int rtlsdr_read_async ( rtlsdr_read_async_cb_t in_cb 107 | , void *in_ctx 108 | , uint32_t buf_num 109 | , uint32_t buf_len 110 | ); 111 | int rtlsdr_cancel_async ( void ); 112 | 113 | protected: // Read and write bulk transfers 114 | void rtlsdr_init_baseband ( void ); 115 | int rtlsdr_deinit_baseband ( void ); 116 | int rtlsdr_alloc_async_buffers 117 | ( void ); 118 | int rtlsdr_free_async_buffers 119 | ( void ); 120 | 121 | protected: // Support functions 122 | bool dummy_write ( void ); 123 | STATIC bool CompareSparseRegAndData ( Dongle* dng 124 | , eepromdata& data 125 | ); 126 | 127 | public: // Read and write bulk transfers callback 128 | void LIBUSB_CALL 129 | libusb_callback ( struct libusb_transfer *xfer ); 130 | 131 | protected: // Basic variables. 132 | Dongle m_dongle; 133 | libusb_context * ctx; 134 | struct libusb_device_handle * devh; 135 | int i2c_repeater_on; 136 | uint32_t xfer_buf_num; 137 | uint32_t xfer_buf_len; 138 | struct libusb_transfer ** xfer; 139 | unsigned char ** xfer_buf; 140 | rtlsdr_read_async_cb_t cb; 141 | void * cb_ctx; 142 | enum rtlsdr_async_status async_status; 143 | int async_cancel; 144 | unsigned int xfer_errors; 145 | int dev_lost; 146 | 147 | // static CMyMutex registry_mutex; // Protect registry accesses 148 | // static CMyMutex dongle_mutex; // Protect shared memory accesses 149 | static CMyMutex rtlsdr_mutex; // Protect shared memory accesses 150 | -------------------------------------------------------------------------------- /librtlsdr_registryAndNames.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // NB. This is meant to be included in librtlsdr.h as part of the 4 | // rtlsdr class. It's broken out this way for over all clarity. 5 | 6 | typedef uint8_t usbportnums[ MAX_USB_PATH ]; 7 | 8 | protected: // Static functions Dongle array handling 9 | STATIC void FillDongleArraysAndComboBox 10 | ( CDongleArray * da 11 | , CComboBox * combo 12 | , LPCTSTR selected 13 | ); 14 | 15 | STATIC bool GetDongleIdString ( CString& string 16 | , int devindex 17 | ); 18 | STATIC int FindDongleByIdString ( LPCTSTR source ); 19 | 20 | protected: // Static functions Registry handling 21 | STATIC void WriteRegistry ( void ); 22 | STATIC uint32_t WriteSingleRegistry ( int index ); 23 | STATIC void WriteRegLastCatalogTime ( void ); 24 | STATIC void ReadRegistry ( void ); 25 | STATIC void mergeToMaster ( Dongle& tempd ); 26 | STATIC const rtlsdr_dongle_t * 27 | find_known_device ( uint16_t vid 28 | , uint16_t pid 29 | ); 30 | STATIC const char* 31 | find_requested_dongle_name 32 | ( libusb_context *ctx 33 | , uint32_t index 34 | ); 35 | STATIC int open_requested_device ( libusb_context *ctx 36 | , uint32_t index 37 | , libusb_device_handle **ldevh 38 | , bool devindex 39 | ); 40 | 41 | STATIC int GetDongleIndexFromNames ( const char * manufact 42 | , const char * product 43 | , const char * serial 44 | ); 45 | STATIC int GetDongleIndexFromNames ( const CString & manufact 46 | , const CString & product 47 | , const CString & serial 48 | ); 49 | STATIC int GetDongleIndexFromDongle( const Dongle dongle ); 50 | 51 | 52 | protected: // Class functions 53 | int GetEepromStrings ( const eepromdata& data 54 | , CString* manf 55 | , CString* prod 56 | , CString* sern 57 | ); 58 | int GetEepromStrings ( uint8_t *data 59 | , int datalen 60 | , char* manf 61 | , char* prod 62 | , char* sern 63 | ); 64 | int FullEepromParse ( const eepromdata& data 65 | , Dongle& tdongle 66 | ); 67 | int SafeFindDongle ( const Dongle& tdongle ); 68 | STATIC int FindInMasterDB ( Dongle* dng 69 | , bool exact 70 | ); 71 | STATIC int FindGuessInMasterDB ( Dongle* dng ); 72 | 73 | 74 | private: 75 | int GetEepromString ( const eepromdata& data 76 | , int pos 77 | , CString* string 78 | ); 79 | int GetEepromString ( const uint8_t *data 80 | , int datalen 81 | , int pos 82 | , char* string 83 | ); 84 | 85 | protected: // Static Registry/Dongle array 86 | static time_t lastCatalog; 87 | static bool noCatalog; 88 | static bool goodCatalog; 89 | 90 | -------------------------------------------------------------------------------- /libusb/MS32/dll/libusb-1.0.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-jdow/rtlsdr-Cplusplus-VS2010/fba0ae3e8a0314c1581c07ac56ad67180fbec72f/libusb/MS32/dll/libusb-1.0.lib -------------------------------------------------------------------------------- /libusb/MS32/static/libusb-1.0.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-jdow/rtlsdr-Cplusplus-VS2010/fba0ae3e8a0314c1581c07ac56ad67180fbec72f/libusb/MS32/static/libusb-1.0.lib -------------------------------------------------------------------------------- /libusb/MS64/dll/libusb-1.0.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-jdow/rtlsdr-Cplusplus-VS2010/fba0ae3e8a0314c1581c07ac56ad67180fbec72f/libusb/MS64/dll/libusb-1.0.lib -------------------------------------------------------------------------------- /libusb/MS64/static/libusb-1.0.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-jdow/rtlsdr-Cplusplus-VS2010/fba0ae3e8a0314c1581c07ac56ad67180fbec72f/libusb/MS64/static/libusb-1.0.lib -------------------------------------------------------------------------------- /resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by rtlsdr.rc 4 | 5 | // Next default values for new objects 6 | // 7 | #ifdef APSTUDIO_INVOKED 8 | #ifndef APSTUDIO_READONLY_SYMBOLS 9 | #define _APS_NEXT_RESOURCE_VALUE 101 10 | #define _APS_NEXT_COMMAND_VALUE 40001 11 | #define _APS_NEXT_CONTROL_VALUE 1001 12 | #define _APS_NEXT_SYMED_VALUE 101 13 | #endif 14 | #endif 15 | -------------------------------------------------------------------------------- /rtl-sdr_export.h: -------------------------------------------------------------------------------- 1 | /* 2 | * rtl-sdr, turns your Realtek RTL2832 based DVB dongle into a SDR receiver 3 | * Copyright (C) 2012 by Hoernchen 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef RTLSDR_EXPORT_H 20 | #define RTLSDR_EXPORT_H 21 | 22 | #if defined __GNUC__ 23 | # if __GNUC__ >= 4 24 | # define __SDR_EXPORT __attribute__((visibility("default"))) 25 | # define __SDR_IMPORT __attribute__((visibility("default"))) 26 | # else 27 | # define __SDR_EXPORT 28 | # define __SDR_IMPORT 29 | # endif 30 | #elif _MSC_VER 31 | # define __SDR_EXPORT __declspec(dllexport) 32 | # define __SDR_IMPORT __declspec(dllimport) 33 | #else 34 | # define __SDR_EXPORT 35 | # define __SDR_IMPORT 36 | #endif 37 | 38 | //#define RTSDR_EXPORTS 39 | 40 | #ifndef RTSDR_STATIC 41 | # ifdef RTSDR_EXPORT 42 | # define RTLSDR_API __SDR_EXPORT 43 | # else 44 | # define RTLSDR_API __SDR_IMPORT 45 | # endif 46 | #else 47 | #define RTLSDR_API 48 | #endif 49 | #endif /* RTLSDR_EXPORT_H */ 50 | -------------------------------------------------------------------------------- /rtlsdr.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-jdow/rtlsdr-Cplusplus-VS2010/fba0ae3e8a0314c1581c07ac56ad67180fbec72f/rtlsdr.rc -------------------------------------------------------------------------------- /rtlsdr_app.h: -------------------------------------------------------------------------------- 1 | // rtlsdr_app.h : main header file for the RTL Direct DLL 2 | // 3 | 4 | #pragma once 5 | 6 | #ifndef __AFXWIN_H__ 7 | #error "include 'stdafx.h' before including this file for PCH" 8 | #endif 9 | 10 | #include "resource.h" // main symbols 11 | #include "SharedMemoryFile.h" 12 | 13 | //#define THEAPP // If MFC dialogs are ever used anywhere this must be set. 14 | // This is also a handy way to get this module version. But 15 | // I am not sure I need it. 16 | 17 | // CRTLDirectApp 18 | // See RTL Direct.cpp for the implementation of this class 19 | // 20 | 21 | #if defined THEAPP 22 | class rtlsdr; 23 | extern CStringA RtlSdrVersionString; 24 | 25 | class rtlsdr_app : public CWinApp 26 | { 27 | public: 28 | rtlsdr_app(); 29 | ~rtlsdr_app(); 30 | 31 | rtlsdr* GetSdrDongle ( void ); 32 | void CloseSdrDongle ( rtlsdr* dongle ); 33 | rtlsdr* FindDongleByDeviceIndex ( int index ); 34 | LPCSTR GetRtlSdrVersionString ( void ) { return RtlSdrVersionString; } 35 | 36 | // Overrides 37 | public: 38 | virtual BOOL InitInstance(); 39 | virtual BOOL ExitInstance(); 40 | 41 | DECLARE_MESSAGE_MAP() 42 | 43 | // static CStringA RtlSdrVersionString; 44 | 45 | protected: 46 | }; 47 | 48 | extern rtlsdr_app theApp; 49 | #endif 50 | //extern RtlSdrAreaDef TestDongles; 51 | //extern RtlSdrAreaDef* RtlSdrArea; 52 | //extern Dongle* Dongles; -------------------------------------------------------------------------------- /rtsdr.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rtlsdr", "rtsdr.vcxproj", "{C6D5C104-8C62-400C-96DA-E3E15AC2C0F7}" 5 | EndProject 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RtlSdr Catalog", "RtlSdr Catalog\RtlSdr Catalog.vcxproj", "{61333089-8BC9-4A2E-96B6-06A0578C2DA8}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C3668B98-B6F4-4038-B2E8-B7C36A01FA5E}" 9 | ProjectSection(SolutionItems) = preProject 10 | RtlSdr++ and RtlSdr Catalog documentation.txt = RtlSdr++ and RtlSdr Catalog documentation.txt 11 | EndProjectSection 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|Win32 = Debug|Win32 16 | Debug|x64 = Debug|x64 17 | Release|Win32 = Release|Win32 18 | Release|x64 = Release|x64 19 | EndGlobalSection 20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 21 | {C6D5C104-8C62-400C-96DA-E3E15AC2C0F7}.Debug|Win32.ActiveCfg = Debug|Win32 22 | {C6D5C104-8C62-400C-96DA-E3E15AC2C0F7}.Debug|Win32.Build.0 = Debug|Win32 23 | {C6D5C104-8C62-400C-96DA-E3E15AC2C0F7}.Debug|x64.ActiveCfg = Debug|x64 24 | {C6D5C104-8C62-400C-96DA-E3E15AC2C0F7}.Debug|x64.Build.0 = Debug|x64 25 | {C6D5C104-8C62-400C-96DA-E3E15AC2C0F7}.Release|Win32.ActiveCfg = Release|Win32 26 | {C6D5C104-8C62-400C-96DA-E3E15AC2C0F7}.Release|Win32.Build.0 = Release|Win32 27 | {C6D5C104-8C62-400C-96DA-E3E15AC2C0F7}.Release|x64.ActiveCfg = Release|x64 28 | {C6D5C104-8C62-400C-96DA-E3E15AC2C0F7}.Release|x64.Build.0 = Release|x64 29 | {61333089-8BC9-4A2E-96B6-06A0578C2DA8}.Debug|Win32.ActiveCfg = Debug|Win32 30 | {61333089-8BC9-4A2E-96B6-06A0578C2DA8}.Debug|Win32.Build.0 = Debug|Win32 31 | {61333089-8BC9-4A2E-96B6-06A0578C2DA8}.Debug|x64.ActiveCfg = Debug|x64 32 | {61333089-8BC9-4A2E-96B6-06A0578C2DA8}.Debug|x64.Build.0 = Debug|x64 33 | {61333089-8BC9-4A2E-96B6-06A0578C2DA8}.Release|Win32.ActiveCfg = Release|Win32 34 | {61333089-8BC9-4A2E-96B6-06A0578C2DA8}.Release|Win32.Build.0 = Release|Win32 35 | {61333089-8BC9-4A2E-96B6-06A0578C2DA8}.Release|x64.ActiveCfg = Release|x64 36 | {61333089-8BC9-4A2E-96B6-06A0578C2DA8}.Release|x64.Build.0 = Release|x64 37 | EndGlobalSection 38 | GlobalSection(SolutionProperties) = preSolution 39 | HideSolutionNode = FALSE 40 | EndGlobalSection 41 | EndGlobal 42 | -------------------------------------------------------------------------------- /rtsdr.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | Header Files 27 | 28 | 29 | Header Files 30 | 31 | 32 | Header Files 33 | 34 | 35 | Header Files 36 | 37 | 38 | Header Files 39 | 40 | 41 | Header Files 42 | 43 | 44 | Header Files 45 | 46 | 47 | Header Files 48 | 49 | 50 | Header Files 51 | 52 | 53 | Header Files 54 | 55 | 56 | Header Files 57 | 58 | 59 | Header Files 60 | 61 | 62 | Header Files 63 | 64 | 65 | Header Files 66 | 67 | 68 | Header Files 69 | 70 | 71 | Header Files 72 | 73 | 74 | Header Files 75 | 76 | 77 | Header Files 78 | 79 | 80 | Header Files 81 | 82 | 83 | Header Files 84 | 85 | 86 | Header Files 87 | 88 | 89 | Header Files 90 | 91 | 92 | Header Files 93 | 94 | 95 | 96 | 97 | Source Files 98 | 99 | 100 | Source Files 101 | 102 | 103 | Source Files 104 | 105 | 106 | Source Files 107 | 108 | 109 | Source Files 110 | 111 | 112 | Source Files 113 | 114 | 115 | Source Files 116 | 117 | 118 | Source Files 119 | 120 | 121 | Source Files 122 | 123 | 124 | Source Files 125 | 126 | 127 | Source Files 128 | 129 | 130 | 131 | 132 | Resource Files 133 | 134 | 135 | -------------------------------------------------------------------------------- /stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // rtsdr.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | // TODO: reference any additional headers you need in STDAFX.H 8 | // and not in this file 9 | 10 | #if RELEASE_DEBUG_OUT 11 | void AfxMsgDbgOut( LPCTSTR lpszFormat, ...) 12 | { 13 | CString Format( lpszFormat ); 14 | TCHAR buf [4096]; 15 | va_list va; 16 | DWORD lastError; 17 | 18 | lastError = GetLastError(); // save current error 19 | _tcsncpy_s( buf, 4096, _T( "rtlsdr: " ), 8 ); 20 | 21 | va_start( va, lpszFormat ); 22 | int pt = _vstprintf_s( &buf[ 8 ], 4096 - 8, Format, va ) + 8; 23 | va_end( va ); 24 | 25 | buf[ pt ] = 0; 26 | OutputDebugString( buf ); 27 | // AfxMessageBox(buf); 28 | SetLastError (lastError); // restore current error 29 | } 30 | #endif 31 | -------------------------------------------------------------------------------- /stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | 8 | #define RELEASE_DEBUG_OUT 0 9 | 10 | #ifndef VC_EXTRALEAN 11 | #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers 12 | #endif 13 | 14 | #include "targetver.h" 15 | 16 | #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit 17 | 18 | #include // MFC core and standard components 19 | #include // MFC extensions 20 | 21 | #ifndef _AFX_NO_OLE_SUPPORT 22 | #include // MFC OLE classes 23 | #include // MFC OLE dialog classes 24 | #include // MFC Automation classes 25 | #endif // _AFX_NO_OLE_SUPPORT 26 | 27 | #ifndef _AFX_NO_DB_SUPPORT 28 | #include // MFC ODBC database classes 29 | #endif // _AFX_NO_DB_SUPPORT 30 | 31 | #ifndef _AFX_NO_DAO_SUPPORT 32 | #include // MFC DAO database classes 33 | #endif // _AFX_NO_DAO_SUPPORT 34 | 35 | #ifndef _AFX_NO_OLE_SUPPORT 36 | #include // MFC support for Internet Explorer 4 Common Controls 37 | #endif 38 | #ifndef _AFX_NO_AFXCMN_SUPPORT 39 | #include // MFC support for Windows Common Controls 40 | #endif // _AFX_NO_AFXCMN_SUPPORT 41 | 42 | #include // needed for MFC support for mutex. 43 | 44 | #ifndef MODE_STATIC 45 | #define MODE_STATIC 1 46 | #define MODE_EXPORT 2 47 | #define MODE_IMPORT 3 48 | #endif 49 | 50 | 51 | // Select from the above three definitions 52 | #ifndef MODE 53 | #define MODE MODE_EXPORT 54 | #endif 55 | 56 | 57 | #if MODE == MODE_STATIC 58 | #define SDRDAPI 59 | #elif MODE == MODE_EXPORT 60 | #define SDRDAPI __declspec(dllexport) 61 | #elif MODE == MODE_IMPORT 62 | #define SDRDAPI __declspec(dllimport) 63 | #else 64 | #pragma message( "Please define MODE above as one of the three values above it." ) 65 | THIS GUARANTEES AN ERROR WHEN COMPILING WITH "MODE" IMPROPERLY DEFINED! 66 | #endif 67 | 68 | #if defined( _M_X64 ) 69 | #ifndef rtlsdr_STATIC 70 | #pragma comment( lib, "libusb\\MS64\\dll\\libusb-1.0.lib" ) 71 | #else 72 | #pragma comment( lib, "libusb\\MS64\\static\\libusb-1.0.lib" ) 73 | #endif 74 | #else 75 | #ifndef rtlsdr_STATIC 76 | #pragma comment( lib, "libusb\\MS32\\dll\\libusb-1.0.lib" ) 77 | #else 78 | #pragma comment( lib, "libusb\\MS32\\static\\libusb-1.0.lib" ) 79 | #endif 80 | #endif 81 | 82 | typedef unsigned __int8 uint8_t; 83 | typedef unsigned __int16 uint16_t; 84 | typedef unsigned __int32 uint32_t; 85 | 86 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) 87 | #define MHZ( x ) (( x ) * 1000 * 1000) 88 | #define KHZ( x ) (( x ) * 1000 ) 89 | 90 | #define SELF_SHARED_MEMORY 91 | 92 | 93 | #if RELEASE_DEBUG_OUT && defined( NDEBUG ) 94 | #undef TRACE 95 | extern void AfxMsgDbgOut( LPCTSTR lpszFormat, ...); 96 | #define TRACE AfxMsgDbgOut 97 | #endif 98 | 99 | #define SET_SPECIAL_FILTER_VALUES TRUE 100 | 101 | -------------------------------------------------------------------------------- /targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Including SDKDDKVer.h defines the highest available Windows platform. 4 | 5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and 6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /tuner_Dummy.h: -------------------------------------------------------------------------------- 1 | // tuner_Dummy.h // Dummy do nothing tuner 2 | 3 | #include "stdafx.h" 4 | #include "librtlsdr.h" 5 | 6 | class dummy_Tuner : public ITuner 7 | { 8 | virtual int init ( rtlsdr* ) _DUMMY_ 9 | virtual int exit ( void ) _DUMMY_ 10 | virtual int set_freq ( uint32_t freq /* Hz */ 11 | , uint32_t * lo_freq 12 | ) _DUMMY_ 13 | virtual int set_bw ( int bw /* Hz */) _DUMMY_ 14 | virtual int get_gain ( void ) _DUMMY_ 15 | virtual int set_gain ( int gain /* tenth dB */) _DUMMY_ 16 | virtual int set_if_gain ( int stage 17 | , int gain /* tenth dB */ 18 | ) _DUMMY_ 19 | virtual int get_tuner_stage_count ( void ) _DUMMY_ 20 | 21 | virtual int get_tuner_stage_gains ( uint8_t stage 22 | , const int32_t **gains 23 | , const char **description 24 | ) _DUMMY_ 25 | virtual int get_tuner_stage_gain ( uint8_t stage ) _DUMMY_ 26 | virtual int set_tuner_stage_gain ( uint8_t stage 27 | , int gain 28 | ) _DUMMY_ 29 | virtual int set_gain_mode ( int manual ) _DUMMY_ 30 | virtual int get_tuner_bandwidths ( const uint32_t **bandwidths 31 | , int *len 32 | ) _DUMMY_ 33 | virtual int get_bandwidth_set_name ( int nSet 34 | , char* pString 35 | ) _DUMMY_ 36 | virtual int set_bandwidth_set ( int nSet ) _DUMMY_ 37 | virtual int set_dither ( int dither ) _DUMMY_ 38 | 39 | virtual int get_xtal_frequency ( uint32_t& xtalfreq ) _DUMMY_ 40 | virtual int set_xtal_frequency ( uint32_t xtalfreq ) _DUMMY_ 41 | virtual int get_tuner_gains ( const int **ptr 42 | , int *len 43 | ) _DUMMY_ 44 | #if defined SET_SPECIAL_FILTER_VALUES 45 | virtual int SetFilterValuesDirect ( BYTE regA 46 | , BYTE regB 47 | , DWORD ifFreq 48 | ) _DUMMY_ 49 | #endif 50 | }; -------------------------------------------------------------------------------- /tuner_e4k.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Elonics E4000 tuner driver 3 | * 4 | * (C) 2011-2012 by Harald Welte 5 | * (C) 2012 by Sylvain Munaut 6 | * (C) 2012 by Hoernchen 7 | * 8 | * All Rights Reserved 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | #pragma once 24 | 25 | #include "librtlsdr.h" 26 | 27 | #define E4K_I2C_ADDR 0xc8 28 | #define E4K_CHECK_ADDR 0x02 29 | #define E4K_CHECK_VAL 0x40 30 | 31 | enum e4k_reg 32 | { 33 | E4K_REG_MASTER1 = 0x00, 34 | E4K_REG_MASTER2 = 0x01, 35 | E4K_REG_MASTER3 = 0x02, 36 | E4K_REG_MASTER4 = 0x03, 37 | E4K_REG_MASTER5 = 0x04, 38 | E4K_REG_CLK_INP = 0x05, 39 | E4K_REG_REF_CLK = 0x06, 40 | E4K_REG_SYNTH1 = 0x07, 41 | E4K_REG_SYNTH2 = 0x08, 42 | E4K_REG_SYNTH3 = 0x09, 43 | E4K_REG_SYNTH4 = 0x0a, 44 | E4K_REG_SYNTH5 = 0x0b, 45 | E4K_REG_SYNTH6 = 0x0c, 46 | E4K_REG_SYNTH7 = 0x0d, 47 | E4K_REG_SYNTH8 = 0x0e, 48 | E4K_REG_SYNTH9 = 0x0f, 49 | E4K_REG_FILT1 = 0x10, 50 | E4K_REG_FILT2 = 0x11, 51 | E4K_REG_FILT3 = 0x12, 52 | // gap 53 | E4K_REG_GAIN1 = 0x14, 54 | E4K_REG_GAIN2 = 0x15, 55 | E4K_REG_GAIN3 = 0x16, 56 | E4K_REG_GAIN4 = 0x17, 57 | // gap 58 | E4K_REG_AGC1 = 0x1a, 59 | E4K_REG_AGC2 = 0x1b, 60 | E4K_REG_AGC3 = 0x1c, 61 | E4K_REG_AGC4 = 0x1d, 62 | E4K_REG_AGC5 = 0x1e, 63 | E4K_REG_AGC6 = 0x1f, 64 | E4K_REG_AGC7 = 0x20, 65 | E4K_REG_AGC8 = 0x21, 66 | // gap 67 | E4K_REG_AGC11 = 0x24, 68 | E4K_REG_AGC12 = 0x25, 69 | // gap 70 | E4K_REG_DC1 = 0x29, 71 | E4K_REG_DC2 = 0x2a, 72 | E4K_REG_DC3 = 0x2b, 73 | E4K_REG_DC4 = 0x2c, 74 | E4K_REG_DC5 = 0x2d, 75 | E4K_REG_DC6 = 0x2e, 76 | E4K_REG_DC7 = 0x2f, 77 | E4K_REG_DC8 = 0x30, 78 | // gap 79 | E4K_REG_QLUT0 = 0x50, 80 | E4K_REG_QLUT1 = 0x51, 81 | E4K_REG_QLUT2 = 0x52, 82 | E4K_REG_QLUT3 = 0x53, 83 | // gap 84 | E4K_REG_ILUT0 = 0x60, 85 | E4K_REG_ILUT1 = 0x61, 86 | E4K_REG_ILUT2 = 0x62, 87 | E4K_REG_ILUT3 = 0x63, 88 | // gap 89 | E4K_REG_DCTIME1 = 0x70, 90 | E4K_REG_DCTIME2 = 0x71, 91 | E4K_REG_DCTIME3 = 0x72, 92 | E4K_REG_DCTIME4 = 0x73, 93 | E4K_REG_PWM1 = 0x74, 94 | E4K_REG_PWM2 = 0x75, 95 | E4K_REG_PWM3 = 0x76, 96 | E4K_REG_PWM4 = 0x77, 97 | E4K_REG_BIAS = 0x78, 98 | E4K_REG_CLKOUT_PWDN = 0x7a, 99 | E4K_REG_CHFILT_CALIB = 0x7b, 100 | E4K_REG_I2C_REG_ADDR = 0x7d, 101 | // FIXME 102 | }; 103 | 104 | #define E4K_MASTER1_RESET (1 << 0) 105 | #define E4K_MASTER1_NORM_STBY (1 << 1) 106 | #define E4K_MASTER1_POR_DET (1 << 2) 107 | 108 | #define E4K_SYNTH1_PLL_LOCK (1 << 0) 109 | #define E4K_SYNTH1_BAND_SHIF 1 110 | 111 | #define E4K_SYNTH7_3PHASE_EN (1 << 3) 112 | 113 | #define E4K_SYNTH8_VCOCAL_UPD (1 << 2) 114 | 115 | #define E4K_FILT3_DISABLE (1 << 5) 116 | 117 | #define E4K_AGC1_LIN_MODE (1 << 4) 118 | #define E4K_AGC1_LNA_UPDATE (1 << 5) 119 | #define E4K_AGC1_LNA_G_LOW (1 << 6) 120 | #define E4K_AGC1_LNA_G_HIGH (1 << 7) 121 | 122 | #define E4K_AGC6_LNA_CAL_REQ (1 << 4) 123 | 124 | #define E4K_AGC7_MIX_GAIN_AUTO (1 << 0) 125 | #define E4K_AGC7_GAIN_STEP_5dB (1 << 5) 126 | 127 | #define E4K_AGC8_SENS_LIN_AUTO (1 << 0) 128 | 129 | #define E4K_AGC11_LNA_GAIN_ENH (1 << 0) 130 | 131 | #define E4K_DC1_CAL_REQ (1 << 0) 132 | 133 | #define E4K_DC5_I_LUT_EN (1 << 0) 134 | #define E4K_DC5_Q_LUT_EN (1 << 1) 135 | #define E4K_DC5_RANGE_DET_EN (1 << 2) 136 | #define E4K_DC5_RANGE_EN (1 << 3) 137 | #define E4K_DC5_TIMEVAR_EN (1 << 4) 138 | 139 | #define E4K_CLKOUT_DISABLE 0x96 140 | 141 | #define E4K_CHFCALIB_CMD (1 << 0) 142 | 143 | #define E4K_AGC1_MOD_MASK 0xF 144 | 145 | enum e4k_agc_mode 146 | { 147 | E4K_AGC_MOD_SERIAL = 0x0, 148 | E4K_AGC_MOD_IF_PWM_LNA_SERIAL = 0x1, 149 | E4K_AGC_MOD_IF_PWM_LNA_AUTONL = 0x2, 150 | E4K_AGC_MOD_IF_PWM_LNA_SUPERV = 0x3, 151 | E4K_AGC_MOD_IF_SERIAL_LNA_PWM = 0x4, 152 | E4K_AGC_MOD_IF_PWM_LNA_PWM = 0x5, 153 | E4K_AGC_MOD_IF_DIG_LNA_SERIAL = 0x6, 154 | E4K_AGC_MOD_IF_DIG_LNA_AUTON = 0x7, 155 | E4K_AGC_MOD_IF_DIG_LNA_SUPERV = 0x8, 156 | E4K_AGC_MOD_IF_SERIAL_LNA_AUTON = 0x9, 157 | E4K_AGC_MOD_IF_SERIAL_LNA_SUPERV = 0xa, 158 | }; 159 | 160 | enum e4k_band 161 | { 162 | E4K_BAND_VHF2 = 0, 163 | E4K_BAND_VHF3 = 1, 164 | E4K_BAND_UHF = 2, 165 | E4K_BAND_L = 3, 166 | }; 167 | 168 | enum e4k_mixer_filter_bw 169 | { 170 | E4K_F_MIX_BW_27M = 0, 171 | E4K_F_MIX_BW_4M6 = 8, 172 | E4K_F_MIX_BW_4M2 = 9, 173 | E4K_F_MIX_BW_3M8 = 10, 174 | E4K_F_MIX_BW_3M4 = 11, 175 | E4K_F_MIX_BW_3M = 12, 176 | E4K_F_MIX_BW_2M7 = 13, 177 | E4K_F_MIX_BW_2M3 = 14, 178 | E4K_F_MIX_BW_1M9 = 15, 179 | }; 180 | 181 | enum e4k_if_filter 182 | { 183 | E4K_IF_FILTER_MIX, 184 | E4K_IF_FILTER_CHAN, 185 | E4K_IF_FILTER_RC 186 | }; 187 | struct e4k_pll_params 188 | { 189 | uint32_t fosc; 190 | uint32_t intended_flo; 191 | uint32_t flo; 192 | uint16_t x; 193 | uint8_t z; 194 | uint8_t r; 195 | uint8_t r_idx; 196 | uint8_t threephase; 197 | }; 198 | 199 | class e4kTuner : public ITuner 200 | { 201 | public: 202 | e4kTuner( rtlsdr* in_dev ); 203 | ~e4kTuner() {} 204 | 205 | // ITuner interface 206 | virtual int init ( rtlsdr* base ); // new? 207 | virtual int exit ( void ); // delete? 208 | virtual int set_freq ( uint32_t freq /* Hz */ 209 | , uint32_t *lo_freq_out ); 210 | virtual int set_bw ( int bw /* Hz */) ; 211 | virtual int get_gain ( void ); /* tenth dB */ 212 | virtual int set_gain ( int gain /* tenth dB */); 213 | virtual int set_if_gain ( int stage 214 | , int gain /* tenth dB */ 215 | ); 216 | virtual int get_tuner_stage_count ( void ) { return 8; } 217 | virtual int get_tuner_stage_gains ( uint8_t stage 218 | , const int32_t **gains 219 | , const char **description 220 | ); 221 | virtual int get_tuner_stage_gain ( uint8_t stage ); 222 | virtual int set_tuner_stage_gain ( uint8_t stage 223 | , int gain 224 | ); 225 | virtual int set_gain_mode ( int manual ); 226 | virtual int get_tuner_bandwidths ( const uint32_t **bandwidths 227 | , int *len 228 | ) _DUMMY_ 229 | virtual int get_bandwidth_set_name ( int nSet 230 | , char* pString 231 | ) _DUMMY_ 232 | virtual int set_bandwidth_set ( int nSet ) _DUMMY_ 233 | virtual int set_dither ( int dither ) _DUMMY_; 234 | 235 | virtual int get_xtal_frequency ( uint32_t& xtalfreq ); 236 | virtual int set_xtal_frequency ( uint32_t xtalfreq ); 237 | virtual int get_tuner_gains ( const int **out_ptr 238 | , int *out_len 239 | ); 240 | 241 | protected: 242 | int e4k_reg_write ( uint8_t reg 243 | , uint8_t val 244 | ); 245 | int e4k_reg_read ( uint8_t reg ); 246 | int e4k_reg_set_mask ( uint8_t reg 247 | , uint8_t mask 248 | , uint8_t val 249 | ); 250 | int e4k_field_write ( const struct reg_field *field 251 | , uint8_t val 252 | ); 253 | int e4k_field_read ( const struct reg_field *field ); 254 | int closest_arr_idx ( const uint32_t *arr 255 | , unsigned int arr_size 256 | , uint32_t freq 257 | ); 258 | int choose_rf_filter ( enum e4k_band band 259 | , uint32_t freq 260 | ); 261 | int find_if_bw ( enum e4k_if_filter filter 262 | , uint32_t bw 263 | ); 264 | int is_fvco_valid ( uint32_t fvco_z ); 265 | int is_fosc_valid ( uint32_t fosc ); 266 | int is_z_valid ( uint32_t z ); 267 | int use_3ph_mixing ( uint32_t flo ); 268 | uint64_t compute_fvco ( uint32_t f_osc 269 | , uint8_t z 270 | , uint16_t x 271 | ); 272 | uint32_t compute_flo ( uint32_t f_osc 273 | , uint8_t z 274 | , uint16_t x 275 | , uint8_t r 276 | ); 277 | int e4k_band_set ( enum e4k_band band ); 278 | int find_stage_gain ( uint8_t stage 279 | , int16_t val 280 | ); 281 | int magic_init ( void ); 282 | 283 | int e4k_init ( void ); 284 | int e4k_standby ( int enable ); 285 | int e4k_if_gain_set ( int8_t stage 286 | , int16_t value 287 | ); 288 | int e4k_mixer_gain_set ( int16_t value ); 289 | int e4k_commonmode_set ( int8_t value ); 290 | int e4k_tune_freq ( uint32_t freq 291 | , uint32_t *lo_freq_out 292 | ); 293 | int e4k_tune_params ( struct e4k_pll_params *p ); 294 | uint32_t e4k_compute_pll_params ( struct e4k_pll_params *oscp 295 | , uint32_t fosc 296 | , uint32_t intended_flo 297 | ); 298 | int e4k_if_filter_bw_get ( enum e4k_if_filter filter ); 299 | int e4k_if_filter_bw_set ( enum e4k_if_filter filter 300 | , uint32_t bandwidth 301 | ); 302 | int e4k_if_filter_chan_enable 303 | ( int on ); 304 | int e4k_rf_filter_set ( void ); 305 | 306 | int e4k_manual_dc_offset ( int8_t iofs 307 | , int8_t irange 308 | , int8_t qofs 309 | , int8_t qrange 310 | ); 311 | int e4k_dc_offset_calibrate ( void ); 312 | #if defined( E4K_DC_OFFSET_CAL ) 313 | int e4k_dc_offset_gen_table ( void ); 314 | #endif 315 | int e4k_set_lna_gain ( int16_t gain ); 316 | 317 | int e4k_set_lna_mixer_if_gain( int16_t gain); 318 | 319 | void compute_gain_table ( void ); 320 | int e4k_get_tuner_gains ( const int **ptr 321 | , int *len 322 | ); 323 | int e4k_enable_manual_gain ( uint8_t manual ); 324 | int e4k_set_enh_gain ( int32_t gain ); 325 | 326 | uint32_t unsigned_delta ( uint32_t a 327 | , uint32_t b 328 | ); 329 | void set_default_if_gains ( void ); 330 | 331 | #if defined SET_SPECIAL_FILTER_VALUES 332 | virtual int SetFilterValuesDirect ( BYTE regA 333 | , BYTE regB 334 | , DWORD ifFreq 335 | ) _DUMMY_ 336 | #endif 337 | 338 | protected: // struct e4k_state 339 | void * i2c_dev; 340 | uint8_t i2c_addr; 341 | enum e4k_band band; 342 | struct e4k_pll_params vco; 343 | 344 | // Stage gains 345 | int gain_mode; 346 | int stagegains[ 8 ]; 347 | 348 | rtlsdr * rtldev; 349 | }; 350 | -------------------------------------------------------------------------------- /tuner_fc0012.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Fitipower FC0012 tuner driver 3 | * 4 | * Copyright (C) 2012 Hans-Frieder Vogt 5 | * 6 | * modified for use in librtlsdr 7 | * Copyright (C) 2012 Steve Markgraf 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | */ 23 | 24 | #include "stdafx.h" 25 | #include 26 | #include 27 | 28 | #include "librtlsdr.h" 29 | #include "tuner_fc0012.h" 30 | 31 | fc0012Tuner::fc0012Tuner( rtlsdr* in_dev ) 32 | : rtldev( in_dev ) 33 | , setgain( 0 ) 34 | { 35 | } 36 | 37 | fc0012Tuner::~fc0012Tuner() 38 | { 39 | } 40 | 41 | int fc0012Tuner::init( rtlsdr* base ) 42 | { 43 | if ( base == NULL ) 44 | return -1; 45 | rtldev = base; 46 | return fc0012_init(); 47 | } 48 | 49 | int fc0012Tuner::set_freq( uint32_t freq /* Hz */, uint32_t *lo_freq_out ) 50 | { 51 | if ( lo_freq_out ) 52 | *lo_freq_out = freq; 53 | 54 | rtldev->rtlsdr_set_gpio_bit( 6, 1, ( freq > 300000000 ) ? 1 : 0 ); 55 | return fc0012_set_params( freq, 6000000 ); 56 | } 57 | 58 | int fc0012Tuner::get_gain( void ) 59 | { 60 | return setgain; 61 | } 62 | 63 | int fc0012Tuner::set_gain( int gain /* tenth dB */) 64 | { 65 | int rc = fc0012_set_gain( gain ); 66 | if ( rc >= 0 ) 67 | setgain = gain; 68 | return rc; 69 | } 70 | 71 | static const int fc0012_gains[] = { -99, -40, 71, 179, 192 }; 72 | 73 | int fc0012Tuner::get_tuner_gains( const int **out_ptr 74 | , int *out_len 75 | ) 76 | { 77 | if ( !out_len ) 78 | return -1; 79 | 80 | *out_len = sizeof( fc0012_gains ); 81 | if ( out_ptr ) 82 | *out_ptr = fc0012_gains; 83 | return 0; 84 | } 85 | 86 | int set_dither( int dither ); 87 | 88 | int fc0012Tuner::get_xtal_frequency( uint32_t& xtalfreq ) 89 | { 90 | xtalfreq = 0; return 0; 91 | } 92 | 93 | 94 | int fc0012Tuner::fc0012_writereg( uint8_t reg, uint8_t val ) 95 | { 96 | uint8_t data[ 2 ]; 97 | data[ 0 ] = reg; 98 | data[ 1 ] = val; 99 | 100 | if ( rtldev->rtlsdr_i2c_write_fn( FC0012_I2C_ADDR, data, 2 ) < 0) 101 | return -1; 102 | 103 | return 0; 104 | } 105 | 106 | int fc0012Tuner::fc0012_readreg( uint8_t reg, uint8_t *val ) 107 | { 108 | uint8_t data = reg; 109 | 110 | if ( rtldev->rtlsdr_i2c_write_fn( FC0012_I2C_ADDR, &data, 1 ) < 0) 111 | return -1; 112 | 113 | if ( rtldev->rtlsdr_i2c_read_fn( FC0012_I2C_ADDR, &data, 1 ) < 0) 114 | return -1; 115 | 116 | *val = data; 117 | 118 | return 0; 119 | } 120 | 121 | /* Incomplete list of register settings: 122 | * 123 | * Name Reg Bits Desc 124 | * CHIP_ID 0x00 0-7 Chip ID (constant 0xA1) 125 | * RF_A 0x01 0-3 Number of count-to-9 cycles in RF 126 | * divider (suggested: 2..9) 127 | * RF_M 0x02 0-7 Total number of cycles (to-8 and to-9) 128 | * in RF divider 129 | * RF_K_HIGH 0x03 0-6 Bits 8..14 of fractional divider 130 | * RF_K_LOW 0x04 0-7 Bits 0..7 of fractional RF divider 131 | * RF_OUTDIV_A 0x05 3-7 Power of two required? 132 | * LNA_POWER_DOWN 0x06 0 Set to 1 to switch off low noise amp 133 | * RF_OUTDIV_B 0x06 1 Set to select 3 instead of 2 for the 134 | * RF output divider 135 | * VCO_SPEED 0x06 3 Select tuning range of VCO: 136 | * 0 = Low range, (ca. 1.1 - 1.5GHz) 137 | * 1 = High range (ca. 1.4 - 1.8GHz) 138 | * BANDWIDTH 0x06 6-7 Set bandwidth. 6MHz = 0x80, 7MHz=0x40 139 | * 8MHz=0x00 140 | * XTAL_SPEED 0x07 5 Set to 1 for 28.8MHz Crystal input 141 | * or 0 for 36MHz 142 | * 0x08 0-7 143 | * EN_CAL_RSSI 0x09 4 Enable calibrate RSSI 144 | * (Receive Signal Strength Indicator) 145 | * LNA_FORCE 0x0d 0 146 | * AGC_FORCE 0x0d ? 147 | * LNA_GAIN 0x13 3-4 Low noise amp gain 148 | * LNA_COMPS 0x15 3 ? 149 | * VCO_CALIB 0x0e 7 Set high then low to calibrate VCO 150 | * (fast lock?) 151 | * VCO_VOLTAGE 0x0e 0-6 Read Control voltage of VCO 152 | * (big value -> low freq) 153 | */ 154 | 155 | int fc0012Tuner::fc0012_init( void ) 156 | { 157 | int ret = 0; 158 | unsigned int i; 159 | uint8_t reg[] = 160 | { 161 | 0x00, /* dummy reg. 0 */ 162 | 0x05, /* reg. 0x01 */ 163 | 0x10, /* reg. 0x02 */ 164 | 0x00, /* reg. 0x03 */ 165 | 0x00, /* reg. 0x04 */ 166 | 0x0f, /* reg. 0x05: may also be 0x0a */ 167 | 0x00, /* reg. 0x06: divider 2, VCO slow */ 168 | 0x00, /* reg. 0x07: may also be 0x0f */ 169 | 0xff, /* reg. 0x08: AGC Clock divide by 256, AGC gain 1/256, 170 | Loop Bw 1/8 */ 171 | 0x6e, /* reg. 0x09: Disable LoopThrough, Enable LoopThrough: 0x6f */ 172 | 0xb8, /* reg. 0x0a: Disable LO Test Buffer */ 173 | 0x82, /* reg. 0x0b: Output Clock is same as clock frequency, 174 | may also be 0x83 */ 175 | 0xfc, /* reg. 0x0c: depending on AGC Up-Down mode, may need 0xf8 */ 176 | 0x02, /* reg. 0x0d: AGC Not Forcing & LNA Forcing, 0x02 for DVB-T */ 177 | 0x00, /* reg. 0x0e */ 178 | 0x00, /* reg. 0x0f */ 179 | 0x00, /* reg. 0x10: may also be 0x0d */ 180 | 0x00, /* reg. 0x11 */ 181 | 0x1f, /* reg. 0x12: Set to maximum gain */ 182 | 0x08, /* reg. 0x13: Set to Middle Gain: 0x08, 183 | Low Gain: 0x00, High Gain: 0x10, enable IX2: 0x80 */ 184 | 0x00, /* reg. 0x14 */ 185 | 0x04, /* reg. 0x15: Enable LNA COMPS */ 186 | }; 187 | 188 | #if 0 189 | switch ( rtlsdr_get_tuner_clock()) 190 | { 191 | case FC_XTAL_27_MHZ: 192 | case FC_XTAL_28_8_MHZ: 193 | reg[ 0x07 ] |= 0x20; 194 | break; 195 | case FC_XTAL_36_MHZ: 196 | default: 197 | break; 198 | } 199 | #endif 200 | reg[ 0x07 ] |= 0x20; 201 | 202 | // if (priv->dual_master) 203 | reg[ 0x0c ] |= 0x02; 204 | 205 | for ( i = 1; i < sizeof( reg ); i++ ) 206 | { 207 | ret = fc0012_writereg( i, reg[ i ]); 208 | if ( ret ) 209 | break; 210 | } 211 | 212 | return ret; 213 | } 214 | 215 | int fc0012Tuner::fc0012_set_params( uint32_t freq 216 | , uint32_t bandwidth 217 | ) 218 | { 219 | int i; 220 | int ret = 0; 221 | uint8_t reg[ 7 ]; 222 | uint8_t am; 223 | uint8_t pm; 224 | uint8_t multi; 225 | uint8_t tmp; 226 | uint64_t f_vco; 227 | uint32_t xtal_freq_div_2; 228 | uint16_t xin; 229 | uint16_t xdiv; 230 | int vco_select = 0; 231 | 232 | xtal_freq_div_2 = rtldev->rtlsdr_get_tuner_clock() / 2; 233 | 234 | /* select frequency divider and the frequency of VCO */ 235 | if ( freq < 37084000 ) 236 | { /* freq * 96 < 3560000000 */ 237 | multi = 96; 238 | reg[ 5 ] = 0x82; 239 | reg[ 6 ] = 0x00; 240 | } 241 | else 242 | if ( freq < 55625000 ) /* freq * 64 < 3560000000 */ 243 | { 244 | multi = 64; 245 | reg[ 5 ] = 0x82; 246 | reg[ 6] = 0x02; 247 | } 248 | else 249 | if ( freq < 74167000 ) /* freq * 48 < 3560000000 */ 250 | { 251 | multi = 48; 252 | reg[ 5 ] = 0x42; 253 | reg[ 6 ] = 0x00; 254 | } 255 | else 256 | if ( freq < 111250000 ) /* freq * 32 < 3560000000 */ 257 | { 258 | multi = 32; 259 | reg[ 5 ] = 0x42; 260 | reg[ 6 ] = 0x02; 261 | } 262 | else 263 | if ( freq < 148334000 ) /* freq * 24 < 3560000000 */ 264 | { 265 | multi = 24; 266 | reg[ 5 ] = 0x22; 267 | reg[ 6 ] = 0x00; 268 | } 269 | else 270 | if ( freq < 222500000 ) /* freq * 16 < 3560000000 */ 271 | { 272 | multi = 16; 273 | reg[ 5 ] = 0x22; 274 | reg[ 6 ] = 0x02; 275 | } 276 | else 277 | if ( freq < 296667000 ) /* freq * 12 < 3560000000 */ 278 | { 279 | multi = 12; 280 | reg[ 5 ] = 0x12; 281 | reg[ 6 ] = 0x00; 282 | } 283 | else 284 | if ( freq < 445000000 ) /* freq * 8 < 3560000000 */ 285 | { 286 | multi = 8; 287 | reg[ 5 ] = 0x12; 288 | reg[ 6 ] = 0x02; 289 | } 290 | else 291 | if ( freq < 593334000 ) /* freq * 6 < 3560000000 */ 292 | { 293 | multi = 6; 294 | reg[ 5 ] = 0x0a; 295 | reg[ 6 ] = 0x00; 296 | } 297 | else 298 | { 299 | multi = 4; 300 | reg[ 5 ] = 0x0a; 301 | reg[ 6 ] = 0x02; 302 | } 303 | 304 | f_vco = freq * multi; 305 | 306 | if ( f_vco >= 3060000000U ) 307 | { 308 | reg[ 6 ] |= 0x08; 309 | vco_select = 1; 310 | } 311 | 312 | /* From divided value (XDIV) determined the FA and FP value */ 313 | xdiv = (uint16_t) ( f_vco / xtal_freq_div_2 ); 314 | if (( f_vco - xdiv * xtal_freq_div_2 ) >= ( xtal_freq_div_2 / 2 )) 315 | xdiv++; 316 | 317 | pm = (uint8_t) ( xdiv / 8); 318 | am = (uint8_t) ( xdiv - ( 8 * pm )); 319 | 320 | if ( am < 2 ) 321 | { 322 | am += 8; 323 | pm--; 324 | } 325 | 326 | if ( pm > 31 ) 327 | { 328 | reg[ 1 ] = am + ( 8 * ( pm - 31 )); 329 | reg[ 2 ] = 31; 330 | } 331 | else 332 | { 333 | reg[ 1 ] = am; 334 | reg[ 2 ] = pm; 335 | } 336 | 337 | if (( reg[ 1 ] > 15 ) || ( reg[ 2 ] < 0x0b )) 338 | { 339 | fprintf(stderr, "[FC0012] no valid PLL combination " 340 | "found for %u Hz!\n", freq); 341 | return -1; 342 | } 343 | 344 | /* fix clock out */ 345 | reg[ 6 ] |= 0x20; 346 | 347 | /* From VCO frequency determines the XIN ( fractional part of Delta 348 | Sigma PLL) and divided value (XDIV) */ 349 | xin = (uint16_t) (( f_vco - ( f_vco / xtal_freq_div_2 ) * xtal_freq_div_2 ) / 1000 ); 350 | xin = ( xin << 15 ) / ( xtal_freq_div_2 / 1000 ); 351 | if ( xin >= 16384 ) 352 | xin += 32768; 353 | 354 | reg[ 3 ] = xin >> 8; /* xin with 9 bit resolution */ 355 | reg[ 4 ] = xin & 0xff; 356 | 357 | reg[ 6 ] &= 0x3f; /* bits 6 and 7 describe the bandwidth */ 358 | switch ( bandwidth ) 359 | { 360 | case 6000000: 361 | reg[ 6 ] |= 0x80; 362 | break; 363 | case 7000000: 364 | reg[ 6 ] |= 0x40; 365 | break; 366 | case 8000000: 367 | default: 368 | break; 369 | } 370 | 371 | /* modified for Realtek demod */ 372 | reg[ 5 ] |= 0x07; 373 | 374 | for ( i = 1; i <= 6; i++ ) 375 | { 376 | ret = fc0012_writereg( i, reg[ i ]); 377 | if ( ret ) 378 | goto exit; 379 | } 380 | 381 | /* VCO Calibration */ 382 | ret = fc0012_writereg( 0x0e, 0x80 ); 383 | if ( !ret ) 384 | ret = fc0012_writereg( 0x0e, 0x00 ); 385 | 386 | /* VCO Re-Calibration if needed */ 387 | if ( !ret ) 388 | ret = fc0012_writereg( 0x0e, 0x00 ); 389 | 390 | if ( !ret ) 391 | { 392 | // msleep(10); 393 | ret = fc0012_readreg( 0x0e, &tmp ); 394 | } 395 | if ( ret ) 396 | goto exit; 397 | 398 | /* vco selection */ 399 | tmp &= 0x3f; 400 | 401 | if ( vco_select ) 402 | { 403 | if ( tmp > 0x3c ) 404 | { 405 | reg[ 6 ] &= ~0x08; 406 | ret = fc0012_writereg( 0x06, reg[ 6 ]); 407 | if ( !ret ) 408 | ret = fc0012_writereg( 0x0e, 0x80 ); 409 | if ( !ret ) 410 | ret = fc0012_writereg( 0x0e, 0x00 ); 411 | } 412 | } 413 | else 414 | { 415 | if ( tmp < 0x02 ) 416 | { 417 | reg[ 6 ] |= 0x08; 418 | ret = fc0012_writereg( 0x06, reg[ 6 ]); 419 | if ( !ret ) 420 | ret = fc0012_writereg( 0x0e, 0x80 ); 421 | if ( !ret ) 422 | ret = fc0012_writereg( 0x0e, 0x00 ); 423 | } 424 | } 425 | 426 | exit: 427 | return ret; 428 | } 429 | 430 | int fc0012Tuner::fc0012_set_gain( int gain ) 431 | { 432 | int ret; 433 | uint8_t tmp = 0; 434 | 435 | ret = fc0012_readreg( 0x13, &tmp ); 436 | 437 | /* mask bits off */ 438 | tmp &= 0xe0; 439 | 440 | switch (gain) 441 | { 442 | case -99: /* -9.9 dB */ 443 | tmp |= 0x02; 444 | break; 445 | case -40: /* -4 dB */ 446 | break; 447 | case 71: 448 | tmp |= 0x08; /* 7.1 dB */ 449 | break; 450 | case 179: 451 | tmp |= 0x17; /* 17.9 dB */ 452 | break; 453 | case 192: 454 | default: 455 | tmp |= 0x10; /* 19.2 dB */ 456 | break; 457 | } 458 | 459 | ret = fc0012_writereg( 0x13, tmp ); 460 | 461 | return ret; 462 | } 463 | -------------------------------------------------------------------------------- /tuner_fc0012.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Fitipower FC0012 tuner driver 3 | * 4 | * Copyright (C) 2012 Hans-Frieder Vogt 5 | * 6 | * modified for use in librtlsdr 7 | * Copyright (C) 2012 Steve Markgraf 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | * 23 | */ 24 | 25 | #pragma once 26 | 27 | #define FC0012_I2C_ADDR 0xc6 28 | #define FC0012_CHECK_ADDR 0x00 29 | #define FC0012_CHECK_VAL 0xa1 30 | #include "librtlsdr.h" 31 | 32 | class fc0012Tuner : public ITuner 33 | { 34 | public: 35 | fc0012Tuner( rtlsdr* in_dev ); 36 | ~fc0012Tuner(); 37 | 38 | // ITuner interface 39 | virtual int init ( rtlsdr* base ); 40 | virtual int exit ( void ) _DUMMY_ 41 | virtual int set_freq ( uint32_t freq /* Hz */ 42 | , uint32_t *lo_freq_out ); 43 | virtual int set_bw ( int bw /* Hz */) _DUMMY_ 44 | virtual int get_gain ( void ); /* tenth dB */ 45 | virtual int set_gain ( int gain /* tenth dB */); 46 | virtual int set_if_gain ( int stage 47 | , int gain /* tenth dB */ 48 | ) _DUMMY_ 49 | virtual int get_tuner_stage_count ( void ) _DUMMY_ 50 | virtual int get_tuner_stage_gains ( uint8_t stage 51 | , const int32_t **gains 52 | , const char **description 53 | ) _DUMMY_ 54 | virtual int get_tuner_stage_gain ( uint8_t stage ) _DUMMY_ 55 | virtual int set_tuner_stage_gain ( uint8_t stage 56 | , int gain 57 | ) _DUMMY_ 58 | virtual int set_gain_mode ( int manual ) _DUMMY_ 59 | virtual int get_tuner_bandwidths ( const uint32_t **bandwidths 60 | , int *len 61 | ) _DUMMY_ 62 | virtual int get_bandwidth_set_name ( int nSet 63 | , char* pString 64 | ) _DUMMY_ 65 | virtual int set_bandwidth_set ( int nSet ) _DUMMY_ 66 | virtual int set_dither ( int dither ) _DUMMY_ 67 | 68 | virtual int get_xtal_frequency ( uint32_t& xtalfreq ); 69 | virtual int set_xtal_frequency ( uint32_t xtalfreq ) _DUMMY_ 70 | virtual int get_tuner_gains ( const int **ptr 71 | , int *len 72 | ); 73 | 74 | #if defined SET_SPECIAL_FILTER_VALUES 75 | virtual int SetFilterValuesDirect ( BYTE regA 76 | , BYTE regB 77 | , DWORD ifFreq 78 | ) _DUMMY_ 79 | #endif 80 | 81 | protected: 82 | int fc0012_writereg ( uint8_t reg 83 | , uint8_t val 84 | ); 85 | int fc0012_readreg ( uint8_t reg 86 | , uint8_t *val 87 | ); 88 | 89 | int fc0012_init ( void ); 90 | int fc0012_set_params ( uint32_t freq 91 | , uint32_t bandwidth 92 | ); 93 | int fc0012_set_gain ( int gain ); 94 | int fc0012_set_gain_mode ( int manual ); 95 | 96 | 97 | 98 | protected: 99 | int setgain; 100 | rtlsdr * rtldev; 101 | }; 102 | -------------------------------------------------------------------------------- /tuner_fc0013.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Fitipower FC0013 tuner driver 3 | * 4 | * Copyright (C) 2012 Hans-Frieder Vogt 5 | * partially based on driver code from Fitipower 6 | * Copyright (C) 2010 Fitipower Integrated Technology Inc 7 | * 8 | * modified for use in librtlsdr 9 | * Copyright (C) 2012 Steve Markgraf 10 | * 11 | * This program is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | #include "stdafx.h" 27 | #include 28 | #include 29 | 30 | typedef struct rtlsdr_dev rtlsdr_dev_t; 31 | #include "tuner_fc0013.h" 32 | 33 | fc0013Tuner::fc0013Tuner( rtlsdr* base ) 34 | : rtldev( base ) 35 | , setgain( 0 ) 36 | { 37 | } 38 | 39 | fc0013Tuner::~fc0013Tuner() 40 | { 41 | } 42 | 43 | 44 | int fc0013Tuner::init( rtlsdr* base ) 45 | { 46 | return fc0013_init(); 47 | } 48 | 49 | int fc0013Tuner::set_freq( uint32_t freq /* Hz */ 50 | , uint32_t *lo_freq_out 51 | ) 52 | { 53 | if ( lo_freq_out ) 54 | *lo_freq_out = freq; 55 | 56 | return fc0013_set_params( freq, 6000000 ); 57 | } 58 | 59 | int fc0013Tuner::get_gain( void ) 60 | { 61 | return setgain; 62 | } 63 | 64 | int fc0013Tuner::set_gain( int gain /* tenth dB */) 65 | { 66 | int rc = fc0013_set_lna_gain( gain ); 67 | if ( rc >= 0 ) 68 | setgain = gain; 69 | return rc; 70 | } 71 | 72 | static const int fc0013_gains[] = { -99, -73, -65, -63, -60, -58, -54, 58, 61, 73 | 63, 65, 67, 68, 70, 71, 179, 181, 182, 74 | 184, 186, 188, 191, 197 }; 75 | 76 | int fc0013Tuner::get_tuner_gains( const int **out_ptr 77 | , int *out_len 78 | ) 79 | { 80 | if ( !out_len ) 81 | return -1; 82 | 83 | *out_len = sizeof( fc0013_gains ); 84 | if ( out_ptr ) 85 | *out_ptr = fc0013_gains; 86 | return 0; 87 | } 88 | 89 | int fc0013Tuner::set_gain_mode( int manual ) 90 | { 91 | return fc0013_set_gain_mode( manual ); 92 | } 93 | 94 | int fc0013Tuner::get_xtal_frequency( uint32_t& xtalfreq ) 95 | { 96 | xtalfreq = 0; 97 | return 0; 98 | } 99 | 100 | int fc0013Tuner::fc0013_writereg( uint8_t reg, uint8_t val ) 101 | { 102 | uint8_t data[ 2 ]; 103 | data[ 0 ] = reg; 104 | data[ 1 ] = val; 105 | 106 | if ( rtldev->rtlsdr_i2c_write_fn( FC0013_I2C_ADDR, data, 2 ) < 0 ) 107 | return -1; 108 | 109 | return 0; 110 | } 111 | 112 | int fc0013Tuner::fc0013_readreg( uint8_t reg, uint8_t *val ) 113 | { 114 | uint8_t data = reg; 115 | 116 | if ( rtldev->rtlsdr_i2c_write_fn( FC0013_I2C_ADDR, &data, 1 ) < 0 ) 117 | return -1; 118 | 119 | if ( rtldev->rtlsdr_i2c_read_fn( FC0013_I2C_ADDR, &data, 1 ) < 0 ) 120 | return -1; 121 | 122 | *val = data; 123 | 124 | return 0; 125 | } 126 | 127 | int fc0013Tuner::fc0013_init( void ) 128 | { 129 | int ret = 0; 130 | unsigned int i; 131 | uint8_t reg[] = 132 | { 133 | 0x00, /* reg. 0x00: dummy */ 134 | 0x09, /* reg. 0x01 */ 135 | 0x16, /* reg. 0x02 */ 136 | 0x00, /* reg. 0x03 */ 137 | 0x00, /* reg. 0x04 */ 138 | 0x17, /* reg. 0x05 */ 139 | 0x02, /* reg. 0x06: LPF bandwidth */ 140 | 0x0a, /* reg. 0x07: CHECK */ 141 | 0xff, /* reg. 0x08: AGC Clock divide by 256, AGC gain 1/256, 142 | Loop Bw 1/8 */ 143 | 0x6e, /* reg. 0x09: Disable LoopThrough, Enable LoopThrough: 0x6f */ 144 | 0xb8, /* reg. 0x0a: Disable LO Test Buffer */ 145 | 0x82, /* reg. 0x0b: CHECK */ 146 | 0xfc, /* reg. 0x0c: depending on AGC Up-Down mode, may need 0xf8 */ 147 | 0x01, /* reg. 0x0d: AGC Not Forcing & LNA Forcing, may need 0x02 */ 148 | 0x00, /* reg. 0x0e */ 149 | 0x00, /* reg. 0x0f */ 150 | 0x00, /* reg. 0x10 */ 151 | 0x00, /* reg. 0x11 */ 152 | 0x00, /* reg. 0x12 */ 153 | 0x00, /* reg. 0x13 */ 154 | 0x50, /* reg. 0x14: DVB-t High Gain, UHF. 155 | Middle Gain: 0x48, Low Gain: 0x40 */ 156 | 0x01, /* reg. 0x15 */ 157 | }; 158 | 159 | #if 0 160 | switch ( rtldev->rtlsdr_get_tuner_clock()) 161 | { 162 | case FC_XTAL_27_MHZ: 163 | case FC_XTAL_28_8_MHZ: 164 | reg[ 0x07 ] |= 0x20; 165 | break; 166 | case FC_XTAL_36_MHZ: 167 | default: 168 | break; 169 | } 170 | #endif 171 | reg[ 0x07 ] |= 0x20; 172 | 173 | // if (dev->dual_master) 174 | reg[ 0x0c ] |= 0x02; 175 | 176 | for ( i = 1; i < sizeof( reg ); i++ ) 177 | { 178 | ret = fc0013_writereg( i, reg[ i ]); 179 | if ( ret < 0 ) 180 | break; 181 | } 182 | 183 | return ret; 184 | } 185 | 186 | int fc0013Tuner::fc0013_rc_cal_add( int rc_val ) 187 | { 188 | int ret; 189 | uint8_t rc_cal; 190 | int val; 191 | 192 | /* push rc_cal value, get rc_cal value */ 193 | ret = fc0013_writereg(0x10, 0x00 ); 194 | if ( ret ) 195 | goto error_out; 196 | 197 | /* get rc_cal value */ 198 | ret = fc0013_readreg( 0x10, &rc_cal ); 199 | if ( ret ) 200 | goto error_out; 201 | 202 | rc_cal &= 0x0f; 203 | 204 | val = (int) rc_cal + rc_val; 205 | 206 | /* forcing rc_cal */ 207 | ret = fc0013_writereg( 0x0d, 0x11 ); 208 | if ( ret ) 209 | goto error_out; 210 | 211 | /* modify rc_cal value */ 212 | if ( val > 15 ) 213 | ret = fc0013_writereg( 0x10, 0x0f ); 214 | else 215 | if ( val < 0 ) 216 | ret = fc0013_writereg( 0x10, 0x00 ); 217 | else 218 | ret = fc0013_writereg( 0x10, (uint8_t) val ); 219 | 220 | error_out: 221 | return ret; 222 | } 223 | 224 | int fc0013Tuner::fc0013_rc_cal_reset( void ) 225 | { 226 | int ret; 227 | 228 | ret = fc0013_writereg( 0x0d, 0x01 ); 229 | if ( !ret ) 230 | ret = fc0013_writereg( 0x10, 0x00 ); 231 | 232 | return ret; 233 | } 234 | 235 | int fc0013Tuner::fc0013_set_vhf_track( uint32_t freq ) 236 | { 237 | int ret; 238 | uint8_t tmp; 239 | 240 | ret = fc0013_readreg( 0x1d, &tmp ); 241 | if (ret) 242 | goto error_out; 243 | tmp &= 0xe3; 244 | if ( freq <= 177500000 ) 245 | { /* VHF Track: 7 */ 246 | ret = fc0013_writereg( 0x1d, tmp | 0x1c ); 247 | } 248 | else 249 | if ( freq <= 184500000 ) 250 | { /* VHF Track: 6 */ 251 | ret = fc0013_writereg( 0x1d, tmp | 0x18 ); 252 | } 253 | else 254 | if ( freq <= 191500000 ) 255 | { /* VHF Track: 5 */ 256 | ret = fc0013_writereg( 0x1d, tmp | 0x14 ); 257 | } 258 | else 259 | if ( freq <= 198500000 ) 260 | { /* VHF Track: 4 */ 261 | ret = fc0013_writereg( 0x1d, tmp | 0x10 ); 262 | } 263 | else 264 | if ( freq <= 205500000 ) 265 | { /* VHF Track: 3 */ 266 | ret = fc0013_writereg( 0x1d, tmp | 0x0c ); 267 | } 268 | else 269 | if ( freq <= 219500000 ) 270 | { /* VHF Track: 2 */ 271 | ret = fc0013_writereg( 0x1d, tmp | 0x08 ); 272 | } 273 | else 274 | if ( freq < 300000000 ) 275 | { /* VHF Track: 1 */ 276 | ret = fc0013_writereg( 0x1d, tmp | 0x04 ); 277 | } 278 | else 279 | { /* UHF and GPS */ 280 | ret = fc0013_writereg( 0x1d, tmp | 0x1c ); 281 | } 282 | 283 | error_out: 284 | return ret; 285 | } 286 | 287 | int fc0013Tuner::fc0013_set_params( uint32_t freq, uint32_t bandwidth ) 288 | { 289 | int i, ret = 0; 290 | uint8_t reg[ 7 ], am, pm, multi, tmp; 291 | uint64_t f_vco; 292 | uint32_t xtal_freq_div_2; 293 | uint16_t xin, xdiv; 294 | int vco_select = 0; 295 | 296 | xtal_freq_div_2 = rtldev->rtlsdr_get_tuner_clock() / 2; 297 | 298 | /* set VHF track */ 299 | ret = fc0013_set_vhf_track( freq ); 300 | if ( ret ) 301 | goto exit; 302 | 303 | if ( freq < 300000000 ) 304 | { 305 | /* enable VHF filter */ 306 | ret = fc0013_readreg( 0x07, &tmp ); 307 | if (ret) 308 | goto exit; 309 | ret = fc0013_writereg( 0x07, tmp | 0x10 ); 310 | if (ret) 311 | goto exit; 312 | 313 | /* disable UHF & disable GPS */ 314 | ret = fc0013_readreg( 0x14, &tmp ); 315 | if (ret) 316 | goto exit; 317 | ret = fc0013_writereg( 0x14, tmp & 0x1f ); 318 | if (ret) 319 | goto exit; 320 | } 321 | else 322 | if ( freq <= 862000000 ) 323 | { 324 | /* disable VHF filter */ 325 | ret = fc0013_readreg( 0x07, &tmp ); 326 | if (ret) 327 | goto exit; 328 | ret = fc0013_writereg( 0x07, tmp & 0xef ); 329 | if (ret) 330 | goto exit; 331 | 332 | /* enable UHF & disable GPS */ 333 | ret = fc0013_readreg( 0x14, &tmp ); 334 | if (ret) 335 | goto exit; 336 | ret = fc0013_writereg( 0x14, (tmp & 0x1f) | 0x40 ); 337 | if (ret) 338 | goto exit; 339 | } 340 | else 341 | { 342 | /* disable VHF filter */ 343 | ret = fc0013_readreg( 0x07, &tmp ); 344 | if ( ret ) 345 | goto exit; 346 | ret = fc0013_writereg( 0x07, tmp & 0xef ); 347 | if ( ret ) 348 | goto exit; 349 | 350 | /* disable UHF & enable GPS */ 351 | ret = fc0013_readreg( 0x14, &tmp ); 352 | if ( ret ) 353 | goto exit; 354 | ret = fc0013_writereg( 0x14, ( tmp & 0x1f ) | 0x20 ); 355 | if ( ret ) 356 | goto exit; 357 | } 358 | 359 | /* select frequency divider and the frequency of VCO */ 360 | if ( freq < 37084000 ) 361 | { /* freq * 96 < 3560000000 */ 362 | multi = 96; 363 | reg[ 5 ] = 0x82; 364 | reg[ 6 ] = 0x00; 365 | } 366 | else 367 | if ( freq < 55625000 ) 368 | { /* freq * 64 < 3560000000 */ 369 | multi = 64; 370 | reg[ 5 ] = 0x02; 371 | reg[ 6 ] = 0x02; 372 | } 373 | else 374 | if ( freq < 74167000 ) 375 | { /* freq * 48 < 3560000000 */ 376 | multi = 48; 377 | reg[ 5 ] = 0x42; 378 | reg[ 6 ] = 0x00; 379 | } 380 | else 381 | if ( freq < 111250000 ) 382 | { /* freq * 32 < 3560000000 */ 383 | multi = 32; 384 | reg[ 5 ] = 0x82; 385 | reg[ 6 ] = 0x02; 386 | } 387 | else 388 | if ( freq < 148334000 ) 389 | { /* freq * 24 < 3560000000 */ 390 | multi = 24; 391 | reg[ 5 ] = 0x22; 392 | reg[ 6 ] = 0x00; 393 | } 394 | else 395 | if ( freq < 222500000 ) 396 | { /* freq * 16 < 3560000000 */ 397 | multi = 16; 398 | reg[ 5 ] = 0x42; 399 | reg[ 6 ] = 0x02; 400 | } 401 | else 402 | if ( freq < 296667000 ) 403 | { /* freq * 12 < 3560000000 */ 404 | multi = 12; 405 | reg[ 5 ] = 0x12; 406 | reg[ 6 ] = 0x00; 407 | } 408 | else 409 | if ( freq < 445000000 ) 410 | { /* freq * 8 < 3560000000 */ 411 | multi = 8; 412 | reg[ 5 ] = 0x22; 413 | reg[ 6 ] = 0x02; 414 | } 415 | else 416 | if ( freq < 593334000 ) 417 | { /* freq * 6 < 3560000000 */ 418 | multi = 6; 419 | reg[ 5 ] = 0x0a; 420 | reg[ 6 ] = 0x00; 421 | } 422 | else 423 | if ( freq < 950000000 ) 424 | { /* freq * 4 < 3800000000 */ 425 | multi = 4; 426 | reg[ 5 ] = 0x12; 427 | reg[ 6 ] = 0x02; 428 | } 429 | else 430 | { 431 | multi = 2; 432 | reg[ 5 ] = 0x0a; 433 | reg[ 6 ] = 0x02; 434 | } 435 | 436 | f_vco = freq * multi; 437 | 438 | if ( f_vco >= 3060000000U ) 439 | { 440 | reg[ 6 ] |= 0x08; 441 | vco_select = 1; 442 | } 443 | 444 | /* From divided value (XDIV) determined the FA and FP value */ 445 | xdiv = (uint16_t) ( f_vco / xtal_freq_div_2 ); 446 | if (( f_vco - xdiv * xtal_freq_div_2 ) >= ( xtal_freq_div_2 / 2 )) 447 | xdiv++; 448 | 449 | pm = (uint8_t) ( xdiv / 8 ); 450 | am = (uint8_t) ( xdiv - ( 8 * pm )); 451 | 452 | if ( am < 2 ) 453 | { 454 | am += 8; 455 | pm--; 456 | } 457 | 458 | if ( pm > 31 ) 459 | { 460 | reg[ 1 ] = am + ( 8 * ( pm - 31 )); 461 | reg[ 2 ] = 31; 462 | } else { 463 | reg[ 1 ] = am; 464 | reg[ 2 ] = pm; 465 | } 466 | 467 | if (( reg[ 1 ] > 15 ) || (reg[ 2 ] < 0x0b )) 468 | { 469 | fprintf(stderr, "[FC0013] no valid PLL combination " 470 | "found for %u Hz!\n", freq); 471 | return -1; 472 | } 473 | 474 | /* fix clock out */ 475 | reg[ 6 ] |= 0x20; 476 | 477 | /* From VCO frequency determines the XIN ( fractional part of Delta 478 | Sigma PLL) and divided value (XDIV) */ 479 | xin = (uint16_t) (( f_vco - ( f_vco / xtal_freq_div_2 ) * xtal_freq_div_2 ) / 1000 ); 480 | xin = ( xin << 15 ) / ( xtal_freq_div_2 / 1000 ); 481 | if ( xin >= 16384 ) 482 | xin += 32768; 483 | 484 | reg[ 3 ] = xin >> 8; 485 | reg[ 4 ] = xin & 0xff; 486 | 487 | reg[ 6 ] &= 0x3f; /* bits 6 and 7 describe the bandwidth */ 488 | switch ( bandwidth ) 489 | { 490 | case 6000000: 491 | reg[ 6 ] |= 0x80; 492 | break; 493 | case 7000000: 494 | reg[ 6 ] |= 0x40; 495 | break; 496 | case 8000000: 497 | default: 498 | break; 499 | } 500 | 501 | /* modified for Realtek demod */ 502 | reg[ 5 ] |= 0x07; 503 | 504 | for ( i = 1; i <= 6; i++ ) 505 | { 506 | ret = fc0013_writereg( i, reg[ i ]); 507 | if ( ret ) 508 | goto exit; 509 | } 510 | 511 | ret = fc0013_readreg( 0x11, &tmp ); 512 | if ( ret ) 513 | goto exit; 514 | if ( multi == 64 ) 515 | ret = fc0013_writereg( 0x11, tmp | 0x04 ); 516 | else 517 | ret = fc0013_writereg( 0x11, tmp & 0xfb ); 518 | if ( ret ) 519 | goto exit; 520 | 521 | /* VCO Calibration */ 522 | ret = fc0013_writereg( 0x0e, 0x80 ); 523 | if ( !ret ) 524 | ret = fc0013_writereg( 0x0e, 0x00 ); 525 | 526 | /* VCO Re-Calibration if needed */ 527 | if ( !ret ) 528 | ret = fc0013_writereg( 0x0e, 0x00 ); 529 | 530 | if ( !ret ) 531 | { 532 | // msleep(10); 533 | ret = fc0013_readreg( 0x0e, &tmp ); 534 | } 535 | if ( ret ) 536 | goto exit; 537 | 538 | /* vco selection */ 539 | tmp &= 0x3f; 540 | 541 | if ( vco_select ) 542 | { 543 | if ( tmp > 0x3c ) 544 | { 545 | reg[ 6 ] &= ~0x08; 546 | ret = fc0013_writereg( 0x06, reg[ 6 ]); 547 | if ( !ret ) 548 | ret = fc0013_writereg( 0x0e, 0x80 ); 549 | if ( !ret ) 550 | ret = fc0013_writereg( 0x0e, 0x00 ); 551 | } 552 | } 553 | else 554 | { 555 | if ( tmp < 0x02 ) 556 | { 557 | reg[ 6 ] |= 0x08; 558 | ret = fc0013_writereg( 0x06, reg[ 6 ]); 559 | if (!ret) 560 | ret = fc0013_writereg( 0x0e, 0x80 ); 561 | if (!ret) 562 | ret = fc0013_writereg( 0x0e, 0x00 ); 563 | } 564 | } 565 | 566 | exit: 567 | return ret; 568 | } 569 | 570 | int fc0013Tuner::fc0013_set_gain_mode( int manual ) 571 | { 572 | int ret = 0; 573 | uint8_t tmp = 0; 574 | 575 | // For now set GAIN_MODE_MANUAL if not GAIN_MODE_AGC 576 | manual = min( GAIN_MODE_MANUAL, manual ); 577 | 578 | ret |= fc0013_readreg( 0x0d, &tmp ); 579 | 580 | if ( manual ) 581 | tmp |= ( 1 << 3 ); 582 | else 583 | tmp &= ~( 1 << 3 ); 584 | 585 | ret |= fc0013_writereg( 0x0d, tmp ); 586 | 587 | /* set a fixed IF-gain for now */ 588 | ret |= fc0013_writereg( 0x13, 0x0a ); 589 | 590 | return ret; 591 | } 592 | 593 | int fc0013_lna_gains[] = 594 | { 595 | -99, 0x02, 596 | -73, 0x03, 597 | -65, 0x05, 598 | -63, 0x04, 599 | -63, 0x00, 600 | -60, 0x07, 601 | -58, 0x01, 602 | -54, 0x06, 603 | 58, 0x0f, 604 | 61, 0x0e, 605 | 63, 0x0d, 606 | 65, 0x0c, 607 | 67, 0x0b, 608 | 68, 0x0a, 609 | 70, 0x09, 610 | 71, 0x08, 611 | 179, 0x17, 612 | 181, 0x16, 613 | 182, 0x15, 614 | 184, 0x14, 615 | 186, 0x13, 616 | 188, 0x12, 617 | 191, 0x11, 618 | 197, 0x10 619 | }; 620 | 621 | #define GAIN_CNT (sizeof(fc0013_lna_gains) / sizeof(int) / 2) 622 | 623 | int fc0013Tuner::fc0013_set_lna_gain( int gain ) 624 | { 625 | int ret = 0; 626 | unsigned int i; 627 | uint8_t tmp = 0; 628 | 629 | ret |= fc0013_readreg( 0x14, &tmp ); 630 | 631 | /* mask bits off */ 632 | tmp &= 0xe0; 633 | 634 | for ( i = 0; i < GAIN_CNT; i++ ) 635 | { 636 | if (( fc0013_lna_gains[ i * 2 ] >= gain ) || ( i + 1 == GAIN_CNT )) 637 | { 638 | tmp |= fc0013_lna_gains[ i * 2 + 1 ]; 639 | break; 640 | } 641 | } 642 | 643 | /* set gain */ 644 | ret |= fc0013_writereg( 0x14, tmp ); 645 | 646 | return ret; 647 | } 648 | -------------------------------------------------------------------------------- /tuner_fc0013.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Fitipower FC0013 tuner driver 3 | * 4 | * Copyright (C) 2012 Hans-Frieder Vogt 5 | * 6 | * modified for use in librtlsdr 7 | * Copyright (C) 2012 Steve Markgraf 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | * 23 | */ 24 | 25 | #pragma once 26 | 27 | #include "librtlsdr.h" 28 | 29 | #define FC0013_I2C_ADDR 0xc6 30 | #define FC0013_CHECK_ADDR 0x00 31 | #define FC0013_CHECK_VAL 0xa3 32 | 33 | class fc0013Tuner : public ITuner 34 | { 35 | public: 36 | fc0013Tuner( rtlsdr* in_dev ); 37 | ~fc0013Tuner(); 38 | 39 | // ITuner interface 40 | virtual int init ( rtlsdr* base ); 41 | virtual int exit ( void ) _DUMMY_ 42 | virtual int set_freq ( uint32_t freq /* Hz */ 43 | , uint32_t *lo_freq 44 | ); 45 | virtual int set_bw ( int bw /* Hz */) _DUMMY_ 46 | virtual int get_gain ( void ); /* tenth dB */ 47 | virtual int set_gain ( int gain /* tenth dB */); 48 | virtual int set_if_gain ( int stage 49 | , int gain /* tenth dB */ 50 | ) _DUMMY_ 51 | virtual int get_tuner_stage_count ( void ) _DUMMY_ 52 | virtual int get_tuner_stage_gains ( uint8_t stage 53 | , const int32_t **gains 54 | , const char **description 55 | ) _DUMMY_ 56 | virtual int get_tuner_stage_gain ( uint8_t stage ) _DUMMY_ 57 | virtual int set_tuner_stage_gain ( uint8_t stage 58 | , int gain 59 | ) _DUMMY_ 60 | virtual int set_gain_mode ( int manual ); 61 | virtual int get_tuner_bandwidths ( const uint32_t **bandwidths 62 | , int *len 63 | ) _DUMMY_ 64 | virtual int get_bandwidth_set_name ( int nSet 65 | , char* pString 66 | ) _DUMMY_ 67 | virtual int set_bandwidth_set ( int nSet ) _DUMMY_ 68 | virtual int set_dither ( int dither ) _DUMMY_ 69 | 70 | virtual int get_xtal_frequency ( uint32_t& xtalfreq ); 71 | virtual int set_xtal_frequency ( uint32_t xtalfreq ) _DUMMY_ 72 | virtual int get_tuner_gains ( const int **ptr 73 | , int *len 74 | ); 75 | 76 | #if defined SET_SPECIAL_FILTER_VALUES 77 | virtual int SetFilterValuesDirect ( BYTE regA 78 | , BYTE regB 79 | , DWORD ifFreq 80 | ) _DUMMY_ 81 | #endif 82 | 83 | protected: 84 | int fc0013_writereg ( uint8_t reg 85 | , uint8_t val 86 | ); 87 | int fc0013_readreg ( uint8_t reg 88 | , uint8_t *val 89 | ); 90 | int fc0013_rc_cal_add ( int rc_val ); 91 | int fc0013_rc_cal_reset ( void ); 92 | int fc0013_set_vhf_track ( uint32_t freq ); 93 | 94 | 95 | int fc0013_init ( void ); 96 | int fc0013_set_params ( uint32_t freq 97 | , uint32_t bandwidth 98 | ); 99 | int fc0013_set_gain_mode ( int manual ); 100 | int fc0013_set_lna_gain ( int gain ); 101 | 102 | protected: 103 | int setgain; 104 | rtlsdr* rtldev; 105 | }; 106 | -------------------------------------------------------------------------------- /tuner_fc2580.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "librtlsdr.h" 4 | 5 | #define BORDER_FREQ 2600000 //2.6GHz : The border frequency which determines whether Low VCO or High VCO is used 6 | #define USE_EXT_CLK 0 //0 : Use internal XTAL Oscillator / 1 : Use External Clock input 7 | #define OFS_RSSI 57 8 | 9 | #define FC2580_I2C_ADDR 0xac 10 | #define FC2580_CHECK_ADDR 0x01 11 | #define FC2580_CHECK_VAL 0x56 12 | 13 | typedef enum 14 | { 15 | FC2580_UHF_BAND, 16 | FC2580_L_BAND, 17 | FC2580_VHF_BAND, 18 | FC2580_NO_BAND 19 | } fc2580_band_type; 20 | 21 | typedef enum 22 | { 23 | FC2580_FCI_FAIL, 24 | FC2580_FCI_SUCCESS 25 | } fc2580_fci_result_type; 26 | 27 | enum FUNCTION_STATUS 28 | { 29 | FUNCTION_SUCCESS, 30 | FUNCTION_ERROR, 31 | }; 32 | 33 | 34 | class fc2580Tuner : public ITuner 35 | { 36 | public: 37 | fc2580Tuner( rtlsdr* base ); 38 | ~fc2580Tuner(); 39 | 40 | // ITuner interface 41 | virtual int init ( rtlsdr* base ); 42 | virtual int exit ( void ) _DUMMY_ 43 | virtual int set_freq ( uint32_t freq /* Hz */ 44 | , uint32_t *lo_freq_out 45 | ); 46 | virtual int set_bw ( int bw /* Hz */); 47 | virtual int get_gain ( void ) _DUMMY_ /* tenth dB */ 48 | virtual int set_gain ( int gain /* tenth dB */) _DUMMY_ 49 | virtual int set_if_gain ( int stage 50 | , int gain /* tenth dB */ 51 | ) _DUMMY_ 52 | virtual int get_tuner_stage_count ( void ) _DUMMY_ 53 | virtual int get_tuner_stage_gains ( uint8_t stage 54 | , const int32_t **gains 55 | , const char **description 56 | ) _DUMMY_ 57 | virtual int get_bandwidth_set_name ( int nSet 58 | , char* pString 59 | ) _DUMMY_ 60 | virtual int set_bandwidth_set ( int nSet ) _DUMMY_ 61 | virtual int get_tuner_stage_gain ( uint8_t stage ) _DUMMY_ 62 | virtual int set_tuner_stage_gain ( uint8_t stage 63 | , int gain 64 | ) _DUMMY_ 65 | virtual int set_gain_mode ( int manual ) _DUMMY_ 66 | virtual int get_tuner_bandwidths ( const uint32_t **bandwidths 67 | , int *len 68 | ) _DUMMY_ 69 | virtual int set_dither ( int dither ) _DUMMY_ 70 | 71 | virtual int get_xtal_frequency ( uint32_t& xtalfreq ); 72 | virtual int set_xtal_frequency ( uint32_t xtalfreq ) _DUMMY_ 73 | virtual int get_tuner_gains ( const int **ptr 74 | , int *len 75 | ); 76 | 77 | #if defined SET_SPECIAL_FILTER_VALUES 78 | virtual int SetFilterValuesDirect ( BYTE regA 79 | , BYTE regB 80 | , DWORD ifFreq 81 | ) _DUMMY_ 82 | #endif 83 | 84 | protected: 85 | fc2580_fci_result_type 86 | fc2580_i2c_write ( unsigned char reg 87 | , unsigned char val 88 | ); 89 | fc2580_fci_result_type 90 | fc2580_i2c_read ( unsigned char reg 91 | , unsigned char *read_data 92 | ); 93 | 94 | /*============================================================================== 95 | fc2580 initial setting 96 | 97 | This function is a generic function which gets called to initialize 98 | 99 | fc2580 in DVB-H mode or L-Band TDMB mode 100 | 101 | 102 | 103 | ifagc_mode 104 | type : integer 105 | 1 : Internal AGC 106 | 2 : Voltage Control Mode 107 | 108 | ==============================================================================*/ 109 | fc2580_fci_result_type 110 | fc2580_set_init ( int ifagc_mode 111 | , unsigned int freq_xtal 112 | ); 113 | 114 | /*============================================================================== 115 | fc2580 frequency setting 116 | 117 | This function is a generic function which gets called to change LO Frequency 118 | 119 | of fc2580 in DVB-H mode or L-Band TDMB mode 120 | 121 | 122 | 123 | f_lo 124 | Value of target LO Frequency in 'kHz' unit 125 | ex) 2.6GHz = 2600000 126 | 127 | ==============================================================================*/ 128 | fc2580_fci_result_type 129 | fc2580_set_freq ( unsigned int f_lo 130 | , unsigned int freq_xtal 131 | ); 132 | 133 | 134 | /*============================================================================== 135 | fc2580 filter BW setting 136 | 137 | This function is a generic function which gets called to change Bandwidth 138 | 139 | frequency of fc2580's channel selection filter 140 | 141 | 142 | 143 | filter_bw 144 | 1 : 1.53MHz(TDMB) 145 | 6 : 6MHz 146 | 7 : 7MHz 147 | 8 : 7.8MHz 148 | 149 | 150 | ==============================================================================*/ 151 | fc2580_fci_result_type 152 | fc2580_set_filter ( unsigned char filter_bw 153 | , unsigned int freq_xtal 154 | ); 155 | 156 | 157 | // Manipulaing functions 158 | int fc2580_Initialize ( void ); 159 | 160 | int fc2580_SetRfFreqHz ( unsigned long RfFreqHz ); 161 | 162 | // Extra manipulaing functions 163 | int fc2580_SetBandwidthMode ( int BandwidthMode ); 164 | 165 | void fc2580_wait_msec ( int a ); // noop for now 166 | protected: 167 | rtlsdr* rtldev; 168 | }; 169 | -------------------------------------------------------------------------------- /tuner_r82xx.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Rafael Micro R820T/R828D driver 3 | * 4 | * Copyright (C) 2013 Mauro Carvalho Chehab 5 | * Copyright (C) 2013 Steve Markgraf 6 | * 7 | * This driver is a heavily modified version of the driver found in the 8 | * Linux kernel: 9 | * http://git.linuxtv.org/linux-2.6.git/history/HEAD:/drivers/media/tuners/r820t.c 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 2 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #pragma once 26 | #include "librtlsdr.h" 27 | 28 | #define R820T_I2C_ADDR 0x34 29 | #define R828D_I2C_ADDR 0x74 30 | #define R828D_XTAL_FREQ 16000000 31 | 32 | #define R82XX_CHECK_ADDR 0x00 33 | #define R82XX_CHECK_VAL 0x69 34 | 35 | #define R82XX_DEFAULT_IF_FREQ 3570000 // was 6000000 jd: Leif 36 | #define R82XX_DEFAULT_IF_BW 2000000 37 | 38 | #define REG_SHADOW_START 5 39 | #define NUM_REGS 30 40 | #define NUM_IMR 5 41 | #define IMR_TRIAL 9 42 | 43 | #define VER_NUM 49 44 | 45 | #define REAL_MAX_GAIN_TABLE_SIZE 32 46 | 47 | enum r82xx_chip 48 | { 49 | CHIP_R820T, 50 | CHIP_R620D, 51 | CHIP_R828D, 52 | CHIP_R828, 53 | CHIP_R828S, 54 | CHIP_R820C, 55 | }; 56 | 57 | typedef enum r82xx_xtal_cap_value 58 | { 59 | XTAL_LOW_CAP_30P = 0, 60 | XTAL_LOW_CAP_20P, 61 | XTAL_LOW_CAP_10P, 62 | XTAL_LOW_CAP_0P, 63 | XTAL_HIGH_CAP_0P 64 | } r82xx_xtal_cap_val; 65 | 66 | typedef struct 67 | { 68 | DWORD Bandwidth; 69 | DWORD IfFreq; 70 | BYTE Reg0A; 71 | BYTE Reg0B; 72 | } tFilterInfo; 73 | 74 | class r82xxTuner : public ITuner 75 | { 76 | public: 77 | r82xxTuner( rtlsdr* base, enum rtlsdr_tuner rafaelTunerType ); 78 | ~r82xxTuner(); 79 | 80 | // ITuner interface 81 | virtual int init ( rtlsdr* base ); 82 | virtual int exit ( void ); 83 | virtual int set_freq ( uint32_t freq /* Hz */ 84 | , uint32_t *lo_freq_out 85 | ); 86 | virtual int set_bw ( int bw /* Hz */); 87 | virtual int get_gain ( void ); /* tenth dB */ 88 | virtual int set_gain ( int gain /* tenth dB */); 89 | virtual int set_if_gain ( int stage 90 | , int gain /* tenth dB */ 91 | ); 92 | virtual int get_tuner_stage_count ( void ) { return 3; } 93 | virtual int get_tuner_stage_gains ( uint8_t stage 94 | , const int32_t **gains 95 | , const char **description 96 | ); 97 | virtual int get_tuner_stage_gain ( uint8_t stage ); // TODOTODO 98 | virtual int set_tuner_stage_gain ( uint8_t stage 99 | , int32_t gain 100 | ); 101 | virtual int set_gain_mode ( int manual ); 102 | virtual int get_tuner_bandwidths ( const uint32_t **bandwidths 103 | , int *len 104 | ); 105 | virtual int get_bandwidth_set_name ( int nSet 106 | , char* pString 107 | ); 108 | virtual int set_bandwidth_set ( int nSet ); 109 | virtual int set_dither ( int dither ); 110 | 111 | virtual int get_xtal_frequency ( uint32_t& xtalfreq ); 112 | virtual int set_xtal_frequency ( uint32_t xtalfreq ); 113 | virtual int get_tuner_gains ( const int **ptr 114 | , int *len 115 | ); 116 | 117 | #if defined SET_SPECIAL_FILTER_VALUES 118 | virtual int SetFilterValuesDirect ( BYTE regA 119 | , BYTE regB 120 | , DWORD ifFreq 121 | ); 122 | #endif 123 | 124 | protected: 125 | void ClearVars ( void ); 126 | void shadow_store ( uint8_t reg 127 | , const uint8_t *val 128 | , int len 129 | ); 130 | int r82xx_write ( uint8_t reg 131 | , const uint8_t *val 132 | , unsigned int len 133 | ); 134 | int r82xx_write_reg ( uint8_t reg 135 | , uint8_t val 136 | ); 137 | int r82xx_read_cache_reg ( int reg ); 138 | int r82xx_write_reg_mask ( uint8_t reg 139 | , uint8_t val 140 | , uint8_t bit_mask 141 | ); 142 | int r82xx_write_batch_init ( void ); 143 | int r82xx_write_batch_sync ( void ); 144 | uint8_t r82xx_bitrev ( uint8_t byte ); 145 | int r82xx_read ( uint8_t reg 146 | , uint8_t *val 147 | , int len 148 | ); 149 | int r82xx_set_mux ( uint32_t freq ); 150 | int r82xx_set_pll ( uint32_t freq 151 | , uint32_t *freq_out 152 | ); 153 | int r82xx_sysfreq_sel ( void ); 154 | int r82xx_init_tv_standard ( void ); 155 | int update_if_filter ( uint32_t bw ); 156 | int r82xx_set_bw ( uint32_t bw ); 157 | int r82xx_read_gain ( void ); 158 | int r82xx_set_gain ( int gain ); 159 | int r82xx_set_freq ( uint32_t freq 160 | , uint32_t *lo_freq_out 161 | ); 162 | // int r82xx_xtal_check ( void ); // Done in r82xx_set_mux 163 | int r82xx_standby ( void ); 164 | int r82xx_init ( void ); 165 | // int r82xx_set_nomod ( void ); // Not used. 166 | int r82xx_get_tuner_bandwidths 167 | ( const uint32_t **bandwidths 168 | , int *len 169 | ); 170 | int r82xx_get_bandwidth_set_name 171 | ( int nSet 172 | , LPSTR pString 173 | ); 174 | int r82xx_set_bandwidth_set ( int nSet ); 175 | 176 | int r82xx_set_dither ( int dither ); 177 | 178 | int r82xx_enable_manual_gain( uint8_t manual); 179 | 180 | int r82xx_get_tuner_stage_gains 181 | ( uint8_t stage 182 | , const int32_t **gains 183 | , const char **description 184 | ); 185 | int r82xx_set_tuner_stage_gain 186 | ( uint8_t stage 187 | , int32_t gain 188 | ); 189 | void r82xx_calculate_stage_gains 190 | ( void ); 191 | void r82xx_compute_gain_table( void ); 192 | int r82xx_set_lna_gain ( int32_t gain ); 193 | int r82xx_set_mixer_gain ( int32_t gain ); 194 | int r82xx_set_VGA_gain ( int32_t gain ); 195 | 196 | int r82xx_calibrate ( int calibration_lo 197 | , uint8_t hp_cor 198 | ); // Calibrate tuner/TV standard 199 | void r82xx_SetBWValues ( int nSet ); 200 | 201 | protected: // config variables 202 | uint8_t m_i2c_addr; 203 | uint32_t m_xtal; 204 | enum r82xx_chip m_rafael_chip; 205 | unsigned int m_max_i2c_msg_len; 206 | 207 | protected: // private variables 208 | uint8_t m_regs[ NUM_REGS ]; 209 | uint8_t m_buf[ NUM_REGS + 1 ]; 210 | r82xx_xtal_cap_val m_xtal_cap_sel; 211 | uint16_t m_pll; /* kHz */ 212 | uint32_t m_nominal_int_freq; 213 | uint32_t m_asked_for_freq; 214 | uint8_t m_fil_cal_code; 215 | uint8_t m_input; 216 | int m_init_done; 217 | int m_disable_dither; 218 | int m_reg_cache; 219 | int m_reg_batch; 220 | int m_reg_low; 221 | int m_reg_high; 222 | 223 | /* Store current mode */ 224 | uint32_t m_delsys; 225 | 226 | uint32_t m_bw; /* in MHz */ 227 | uint32_t m_if_filter_freq; /* in Hz */ 228 | 229 | int m_pll_off; 230 | 231 | /* current PLL limits */ 232 | uint32_t m_pll_low_limit; 233 | uint32_t m_pll_high_limit; 234 | 235 | // Stage gains 236 | int gain_mode; 237 | int stagegains[ 3 ]; 238 | 239 | rtlsdr* rtldev; 240 | 241 | // Bandwidths reporting 242 | uint32_t* m_bandwidths; 243 | int m_CurBWSet; 244 | 245 | const tFilterInfo* m_FilterInfo; 246 | int m_FilterSetCount; 247 | int r82xx_gain_table_len; 248 | int r82xx_gain_table[ REAL_MAX_GAIN_TABLE_SIZE ]; 249 | 250 | protected: 251 | // Static data 252 | // One per set 253 | static const tFilterInfo 254 | m_FilterInfo0[]; // Centered 255 | static const tFilterInfo 256 | m_FilterInfo1[]; // High Side. 257 | 258 | static const CString 259 | BandwidthSetNames[]; 260 | static const DWORD BWSNcount; 261 | }; 262 | --------------------------------------------------------------------------------