Add error handling to hackrf_trasfer argument parsing

This commit is contained in:
Dominic Spill
2016-01-14 17:33:00 +00:00
parent 327e08a16c
commit 57ee59ceea

View File

@ -483,6 +483,8 @@ int main(int argc, char** argv) {
char date_time[DATE_TIME_MAX_LEN]; char date_time[DATE_TIME_MAX_LEN];
const char* path = NULL; const char* path = NULL;
const char* serial_number = NULL; const char* serial_number = NULL;
char* endptr;
double f_hz;
int result; int result;
time_t rawtime; time_t rawtime;
struct tm * timeinfo; struct tm * timeinfo;
@ -516,33 +518,33 @@ int main(int argc, char** argv) {
break; break;
case 'f': case 'f':
{ f_hz = strtod(optarg, &endptr);
double f = atof(optarg); if (optarg == endptr) {
if (f < 0) result = HACKRF_ERROR_INVALID_PARAM;
break; break;
freq_hz = f;
automatic_tuning = true;
} }
freq_hz = f_hz;
automatic_tuning = true;
break; break;
case 'i': case 'i':
{ f_hz = strtod(optarg, &endptr);
double f = atof(optarg); if (optarg == endptr) {
if (f < 0) result = HACKRF_ERROR_INVALID_PARAM;
break; break;
if_freq_hz = f;
if_freq = true;
} }
if_freq_hz = f_hz;
if_freq = true;
break; break;
case 'o': case 'o':
{ f_hz = strtod(optarg, &endptr);
double f = atof(optarg); if (optarg == endptr) {
if (f < 0) result = HACKRF_ERROR_INVALID_PARAM;
break; break;
lo_freq_hz = f;
lo_freq = true;
} }
lo_freq_hz = f_hz;
lo_freq = true;
break; break;
case 'm': case 'm':
@ -573,13 +575,13 @@ int main(int argc, char** argv) {
break; break;
case 's': case 's':
{ f_hz = strtod(optarg, &endptr);
double f = atof(optarg); if (optarg == endptr) {
if (f < 0) result = HACKRF_ERROR_INVALID_PARAM;
break; break;
sample_rate_hz = f;
sample_rate = true;
} }
sample_rate_hz = f_hz;
sample_rate = true;
break; break;
case 'n': case 'n':
@ -589,14 +591,13 @@ int main(int argc, char** argv) {
break; break;
case 'b': case 'b':
{ f_hz = strtod(optarg, &endptr);
double f = atof(optarg); if (optarg == endptr) {
if (f < 0) result = HACKRF_ERROR_INVALID_PARAM;
break; break;
baseband_filter_bw_hz = f;
baseband_filter_bw = true;
} }
baseband_filter_bw_hz = f_hz;
baseband_filter_bw = true;
break; break;
case 'c': case 'c':