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