@@ -698,8 +698,8 @@ int config_hackrf(
698
698
hackrf_device *& device,
699
699
double & fs_programmed
700
700
) {
701
- unsigned int lna_gain=16 ; // default value
702
- unsigned int vga_gain=60 ; // default value
701
+ unsigned int lna_gain=32 ; // default value
702
+ unsigned int vga_gain=40 ; // default value
703
703
704
704
int result = hackrf_init ();
705
705
if ( result != HACKRF_SUCCESS ) {
@@ -1174,25 +1174,25 @@ double kalibrate(
1174
1174
return best.freq_superfine ;
1175
1175
}
1176
1176
1177
+ sampbuf_sync_t sampbuf_sync;
1178
+
1177
1179
#ifdef HAVE_HACKRF
1178
1180
1179
1181
static int hackrf_callback (hackrf_transfer* transfer)
1180
- {
1181
- sampbuf_sync_t & sampbuf_sync=*((sampbuf_sync_t *)(transfer->rx_ctx ));
1182
-
1183
- // cout << "Callback with " << len << " samples" << endl;
1184
-
1182
+ {
1183
+ // cout << "1\n";
1185
1184
if (transfer->valid_length ==0 ) {
1186
1185
cerr << " Error: received no samples from HACKRF device..." << endl;
1187
1186
ABORT (-1 );
1188
1187
}
1189
1188
1190
1189
boost::mutex::scoped_lock lock (sampbuf_sync.mutex );
1191
1190
for (uint32 t=0 ;t<(uint32)transfer->valid_length ;t++) {
1192
- sampbuf_sync.fifo .push_back (transfer->buffer [t]);
1191
+ sampbuf_sync.fifo .push_back ((int8) transfer->buffer [t]);
1193
1192
}
1194
1193
sampbuf_sync.fifo_peak_size =MAX (sampbuf_sync.fifo .size (),sampbuf_sync.fifo_peak_size );
1195
1194
sampbuf_sync.condition .notify_one ();
1195
+
1196
1196
return (0 );
1197
1197
}
1198
1198
@@ -1214,7 +1214,7 @@ static void rtlsdr_callback(
1214
1214
1215
1215
boost::mutex::scoped_lock lock (sampbuf_sync.mutex );
1216
1216
for (uint32 t=0 ;t<len;t++) {
1217
- sampbuf_sync.fifo .push_back (buf[t]);
1217
+ sampbuf_sync.fifo .push_back (buf[t]- 128 );
1218
1218
}
1219
1219
sampbuf_sync.fifo_peak_size =MAX (sampbuf_sync.fifo .size (),sampbuf_sync.fifo_peak_size );
1220
1220
sampbuf_sync.condition .notify_one ();
@@ -1305,8 +1305,32 @@ int main(
1305
1305
double initial_k_factor = 1 ;
1306
1306
double initial_freq_offset=kalibrate (fc_requested,fs_programmed,ppm,correction,correction_new,use_recorded_data,filename,rtl_sdr_format,noise_power,drop_secs,repeat,dev,hackrf_dev,dev_use,fc_programmed,initial_sampling_carrier_twist,initial_k_factor,record_bin_filename,load_bin_filename,opencl_platform,opencl_device,filter_workitem,xcorr_workitem,num_reserve);
1307
1307
1308
+ // // ---------------- stop and close hackrf
1309
+ // Real_Timer tt;
1310
+ // tt.tic();
1311
+ // while(tt.get_time()<2) {;}
1312
+ // if ( dev_use == dev_type_t::HACKRF ) {
1313
+ // #ifdef HAVE_HACKRF
1314
+ // int result = hackrf_stop_rx(hackrf_dev);
1315
+ // if( result != HACKRF_SUCCESS ) {
1316
+ // printf("hackrf_stop_rx() failed: %s (%d)\n", hackrf_error_name((hackrf_error)result), result);
1317
+ // ABORT(-1);
1318
+ // }
1319
+ // result = hackrf_close(hackrf_dev);
1320
+ // if( result != HACKRF_SUCCESS ) {
1321
+ // printf("hackrf_close() failed: %s (%d)\n", hackrf_error_name((hackrf_error)result), result);
1322
+ // ABORT(-1);
1323
+ // }
1324
+ // result = hackrf_exit();
1325
+ // if( result != HACKRF_SUCCESS ) {
1326
+ // printf("hackrf_exit() failed: %s (%d)\n", hackrf_error_name((hackrf_error)result), result);
1327
+ // ABORT(-1);
1328
+ // }
1329
+ // #endif
1330
+ // }
1331
+
1308
1332
// Data shared between threads
1309
- sampbuf_sync_t sampbuf_sync;
1333
+ // sampbuf_sync_t sampbuf_sync;
1310
1334
tracked_cell_list_t tracked_cell_list;
1311
1335
capbuf_sync_t capbuf_sync;
1312
1336
global_thread_data_t global_thread_data (fc_requested,fc_programmed,fs_programmed);
@@ -1322,6 +1346,8 @@ int main(
1322
1346
global_thread_data.frequency_offset (initial_freq_offset);
1323
1347
global_thread_data.initial_frequency_offset (initial_freq_offset);
1324
1348
1349
+ global_thread_data.dev_use (dev_use);
1350
+
1325
1351
global_thread_data.k_factor (initial_k_factor);
1326
1352
global_thread_data.correction (correction_new);
1327
1353
global_thread_data.sampling_carrier_twist (initial_sampling_carrier_twist);
@@ -1363,8 +1389,10 @@ int main(
1363
1389
// for (uint32 t=0;t<192000;t++) {
1364
1390
for (uint32 t=0 ;t<(uint32)( file_data.length () );t++) {
1365
1391
complex <double > samp=file_data[offset]+randn_c ()*sqrt (noise_power);
1366
- uint8 samp_real=RAIL (round_i (real (samp)*128.0 +128.0 ),0 ,255 ); // 127 should be 128?
1367
- uint8 samp_imag=RAIL (round_i (imag (samp)*128.0 +128.0 ),0 ,255 ); // 127 should be 128?
1392
+ // uint8 samp_real=RAIL(round_i(real(samp)*128.0+128.0),0,255); // 127 should be 128?
1393
+ // uint8 samp_imag=RAIL(round_i(imag(samp)*128.0+128.0),0,255); // 127 should be 128?
1394
+ int8 samp_real=round_i (real (samp)*128.0 ); // 127 should be 128?
1395
+ int8 samp_imag=round_i (imag (samp)*128.0 ); // 127 should be 128?
1368
1396
sampbuf_sync.fifo .push_back (samp_real);
1369
1397
sampbuf_sync.fifo .push_back (samp_imag);
1370
1398
offset++;
@@ -1394,32 +1422,58 @@ int main(
1394
1422
// Start the async read process. This should never return.
1395
1423
rtlsdr_read_async (dev,rtlsdr_callback,(void *)&sampbuf_sync,0 ,0 );
1396
1424
} else if (dev_use == dev_type_t ::HACKRF) {
1397
- #ifdef HAVE_HACKRF
1398
-
1399
- int result = hackrf_stop_rx (hackrf_dev);
1400
- if ( result != HACKRF_SUCCESS ) {
1401
- printf (" hackrf_stop_rx() failed: %s (%d)\n " , hackrf_error_name ((hackrf_error)result), result);
1402
- ABORT (-1 );
1403
- }
1404
-
1405
- result = hackrf_start_rx (hackrf_dev, hackrf_callback, (void *)&sampbuf_sync);
1406
-
1407
- if ( result != HACKRF_SUCCESS ) {
1408
- printf (" hackrf_start_rx() failed: %s (%d)\n " , hackrf_error_name ((hackrf_error)result), result);
1409
- ABORT (-1 );
1425
+ cvec capbuf;
1426
+ while (1 ) {
1427
+ capture_data (fc_requested,correction,false ,record_bin_filename,use_recorded_data,load_bin_filename," ." ,dev,hackrf_dev, dev_use,capbuf,fc_programmed,fs_programmed,false );
1428
+ // cout << "cap\n";
1429
+ boost::mutex::scoped_lock lock (sampbuf_sync.mutex );
1430
+ for (uint32 t=0 ;t<(uint32)length (capbuf);t++) {
1431
+ sampbuf_sync.fifo .push_back ( (int8)(round_i ( real ( capbuf[t] )*128 ) ) );
1432
+ sampbuf_sync.fifo .push_back ( (int8)(round_i ( imag ( capbuf[t] )*128 ) ) );
1433
+ }
1434
+ sampbuf_sync.fifo_peak_size =MAX (sampbuf_sync.fifo .size (),sampbuf_sync.fifo_peak_size );
1435
+ sampbuf_sync.condition .notify_one ();
1410
1436
}
1437
+ // #ifdef HAVE_HACKRF
1438
+ //
1439
+ // tt.tic();
1440
+ // while(tt.get_time()<10) {;}
1441
+ // if ( config_hackrf(initial_sampling_carrier_twist,correction,device_index,fc_requested,hackrf_dev,fs_programmed) != 0 ) {
1442
+ // cout << "HACKRF re-config failed!\n";
1443
+ // }
1444
+ // int result;
1445
+ // result = hackrf_stop_rx(hackrf_dev);
1446
+ // if( result != HACKRF_SUCCESS ) {
1447
+ // printf("hackrf_stop_rx() failed: %s (%d)\n", hackrf_error_name((hackrf_error)result), result);
1448
+ // ABORT(-1);
1449
+ // }
1450
+ //
1451
+ // result = hackrf_start_rx(hackrf_dev, hackrf_callback, NULL);
1452
+ //
1453
+ // if( result != HACKRF_SUCCESS ) {
1454
+ // printf("hackrf_start_rx() failed: %s (%d)\n", hackrf_error_name((hackrf_error)result), result);
1455
+ // ABORT(-1);
1456
+ // }
1457
+ //
1458
+ // // while(1);
1459
+ // int tmp_count=0;
1460
+ //
1461
+ // result = hackrf_is_streaming(hackrf_dev);
1462
+ // printf("hackrf_is_streaming() failed: %s (%d)\n", hackrf_error_name((hackrf_error)result), result);
1463
+ //
1464
+ // while(hackrf_is_streaming(hackrf_dev) == HACKRF_TRUE) {
1465
+ // cout << (++tmp_count) << "\n";
1466
+ // }
1467
+ //
1468
+ // cout << "HACKRF streaming exit abnormally!\n";
1469
+ // ABORT(-1);
1411
1470
1412
- while (hackrf_is_streaming (hackrf_dev) == HACKRF_TRUE) {;}
1413
-
1414
- cout << " HACKRF streaming exit abnormally!\n " ;
1415
- ABORT (-1 );
1416
-
1417
- #else
1418
-
1419
- cout << " HACKRF can't be used when lib is not included!\n " ;
1420
- ABORT (-1 );
1421
-
1422
- #endif
1471
+ // #else
1472
+ //
1473
+ // cout << "HACKRF can't be used when lib is not included!\n";
1474
+ // ABORT(-1);
1475
+ //
1476
+ // #endif
1423
1477
1424
1478
} else {
1425
1479
cout << " No valid device present.\n " ;
0 commit comments