Fixed hackrf_transfer mode control logic.

This commit is contained in:
Michael Ossmann
2017-01-29 18:21:17 -07:00
parent 9211b70770
commit f494e0b890

View File

@ -357,6 +357,8 @@ bool repeat = false;
bool crystal_correct = false; bool crystal_correct = false;
uint32_t crystal_correct_ppm ; uint32_t crystal_correct_ppm ;
int requested_mode_count = 0;
int rx_callback(hackrf_transfer* transfer) { int rx_callback(hackrf_transfer* transfer) {
size_t bytes_to_write; size_t bytes_to_write;
size_t bytes_written; size_t bytes_written;
@ -555,15 +557,18 @@ int main(int argc, char** argv) {
break; break;
case 'w': case 'w':
receive_wav = true; receive_wav = true;
requested_mode_count++;
break; break;
case 'r': case 'r':
receive = true; receive = true;
requested_mode_count++;
path = optarg; path = optarg;
break; break;
case 't': case 't':
transmit = true; transmit = true;
requested_mode_count++;
path = optarg; path = optarg;
break; break;
@ -660,8 +665,8 @@ int main(int argc, char** argv) {
break; break;
case 'c': case 'c':
transmit = true;
signalsource = true; signalsource = true;
requested_mode_count++;
result = parse_u32(optarg, &amplitude); result = parse_u32(optarg, &amplitude);
break; break;
@ -820,28 +825,17 @@ int main(int argc, char** argv) {
} }
} }
if( (transmit == false) && (receive == receive_wav) ) if(requested_mode_count > 1) {
{ fprintf(stderr, "specify only one of: -t, -c, -r, -w\n");
fprintf(stderr, "receive -r and receive_wav -w options are mutually exclusive\n");
usage(); usage();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if( receive_wav == false ) if(requested_mode_count < 1) {
{ fprintf(stderr, "specify one of: -t, -c, -r, -w\n");
if( transmit == receive )
{
if( transmit == true )
{
fprintf(stderr, "receive -r and transmit -t options are mutually exclusive\n");
} else
{
fprintf(stderr, "specify either transmit -t or receive -r or receive_wav -w option\n");
}
usage(); usage();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
}
if( receive ) { if( receive ) {
transceiver_mode = TRANSCEIVER_MODE_RX; transceiver_mode = TRANSCEIVER_MODE_RX;
@ -854,7 +848,7 @@ int main(int argc, char** argv) {
if (signalsource) { if (signalsource) {
transceiver_mode = TRANSCEIVER_MODE_SS; transceiver_mode = TRANSCEIVER_MODE_SS;
if (amplitude >127) { if (amplitude >127) {
fprintf(stderr, "argument error: amplitude shall be in between 0 and 128.\n"); fprintf(stderr, "argument error: amplitude shall be in between 0 and 127.\n");
usage(); usage();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -1108,20 +1102,17 @@ int main(int argc, char** argv) {
time_diff = TimevalDiff(&t_end, &t_start); time_diff = TimevalDiff(&t_end, &t_start);
fprintf(stderr, "Total time: %5.5f s\n", time_diff); fprintf(stderr, "Total time: %5.5f s\n", time_diff);
if(device != NULL) if(device != NULL) {
{ if(receive || receive_wav) {
if( receive )
{
result = hackrf_stop_rx(device); result = hackrf_stop_rx(device);
if( result != HACKRF_SUCCESS ) { if( result != HACKRF_SUCCESS ) {
fprintf(stderr, "hackrf_stop_rx() failed: %s (%d)\n", hackrf_error_name(result), result); fprintf(stderr, "hackrf_stop_rx() failed: %s (%d)\n", hackrf_error_name(result), result);
}else { } else {
fprintf(stderr, "hackrf_stop_rx() done\n"); fprintf(stderr, "hackrf_stop_rx() done\n");
} }
} }
if( transmit ) if(transmit || signalsource) {
{
result = hackrf_stop_tx(device); result = hackrf_stop_tx(device);
if( result != HACKRF_SUCCESS ) { if( result != HACKRF_SUCCESS ) {
fprintf(stderr, "hackrf_stop_tx() failed: %s (%d)\n", hackrf_error_name(result), result); fprintf(stderr, "hackrf_stop_tx() failed: %s (%d)\n", hackrf_error_name(result), result);
@ -1131,10 +1122,9 @@ int main(int argc, char** argv) {
} }
result = hackrf_close(device); result = hackrf_close(device);
if( result != HACKRF_SUCCESS ) if(result != HACKRF_SUCCESS) {
{
fprintf(stderr, "hackrf_close() failed: %s (%d)\n", hackrf_error_name(result), result); fprintf(stderr, "hackrf_close() failed: %s (%d)\n", hackrf_error_name(result), result);
}else { } else {
fprintf(stderr, "hackrf_close() done\n"); fprintf(stderr, "hackrf_close() done\n");
} }