File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -255,6 +255,49 @@ int parse_u32(char* s, uint32_t* const value)
255255 }
256256}
257257
258+ int parse_fp64 (char * s , uint8_t Qn , uint64_t * const value )
259+ {
260+ uint64_t m = 0 ;
261+ uint64_t n = 0 ;
262+ uint64_t div = 1 ;
263+ uint64_t div_max = log10 (1 << Qn ) * 10 ;
264+
265+ // parse integer component
266+ for (; (* s >= '0' ) && (* s <= '9' ); s ++ ) {
267+ m = (m * 10 ) + (* s - '0' );
268+ }
269+ * value = (m << Qn );
270+
271+ if (* s != '.' ) {
272+ return HACKRF_SUCCESS ;
273+ }
274+ s ++ ;
275+
276+ // parse fractional component
277+ for (; (* s >= '0' ) && (* s <= '9' ) && (div < div_max ); s ++ ) {
278+ n = (n * 10 ) + (* s - '0' );
279+ div *= 10 ;
280+ }
281+
282+ if (div == 1 ) {
283+ return HACKRF_SUCCESS ;
284+ }
285+
286+ * value += ((n << Qn ) + (div / 2 )) / div ;
287+
288+ return HACKRF_SUCCESS ;
289+ }
290+
291+ int parse_frequency_fp (char * optarg , fp_40_24_t * value )
292+ {
293+ return parse_fp64 (optarg , 24 , value );
294+ }
295+
296+ int parse_sample_rate_fp (char * optarg , fp_28_36_t * value )
297+ {
298+ return parse_fp64 (optarg , 36 , value );
299+ }
300+
258301/* Parse frequencies as doubles to take advantage of notation parsing */
259302int parse_frequency_i64 (char * optarg , char * endptr , int64_t * value )
260303{
You can’t perform that action at this time.
0 commit comments