diff options
| author | Sylvain Munaut <tnt@246tNt.com> | 2012-12-11 23:45:03 +0100 | 
|---|---|---|
| committer | Sylvain Munaut <tnt@246tNt.com> | 2012-12-11 23:45:03 +0100 | 
| commit | c44310e351bd7740b377dda83cae1d29a3dc8b76 (patch) | |
| tree | 696538ef19b5f7587a80884a13ce22372be062c9 /utils | |
| parent | 5572031749ffa4cdfa15e9c73b8897e39c3ddb0b (diff) | |
utils/osmo-arfcn: Implement option to get ARFCN from frequency
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Diffstat (limited to 'utils')
| -rw-r--r-- | utils/osmo-arfcn.c | 33 | 
1 files changed, 32 insertions, 1 deletions
| diff --git a/utils/osmo-arfcn.c b/utils/osmo-arfcn.c index b88db5af..2be3958e 100644 --- a/utils/osmo-arfcn.c +++ b/utils/osmo-arfcn.c @@ -58,6 +58,27 @@ static int arfcn2freq(int arfcn)  	return 0;  } +static int freq2arfcn(int freq10, int uplink) +{ +	uint16_t arfcn; + +	if (uplink != 0 && uplink != 1) { +		fprintf(stderr, "Need to specify uplink or downlink\n"); +		return -EINVAL; +	} + +	arfcn = gsm_freq102arfcn(freq10, uplink); + +	if (arfcn == 0xffff) { +		fprintf(stderr, "Unable to find matching ARFCN\n"); +		return -EINVAL; +	} + +	printf("%s: ARFCN %4d\n", +		gsm_band_name(gsm_arfcn2band(arfcn)), +		arfcn & ~ARFCN_FLAG_MASK); +} +  static void help(const char *progname)  {  	printf("Usage: %s [-h] [-p] [-a arfcn] [-f freq] [-u|-d]\n", @@ -66,7 +87,7 @@ static void help(const char *progname)  int main(int argc, char **argv)  { -	int arfcn, pcs = 0; +	int arfcn, freq, pcs = 0, uplink = -1;  	int opt;  	char *param;  	enum program_mode mode = MODE_NONE; @@ -84,6 +105,12 @@ int main(int argc, char **argv)  			mode = MODE_F2A;  			param = optarg;  			break; +		case 'u': +			uplink = 1; +			break; +		case 'd': +			uplink = 0; +			break;  		case 'h':  			help(argv[0]);  			exit(0); @@ -104,6 +131,10 @@ int main(int argc, char **argv)  			arfcn |= ARFCN_PCS;  		arfcn2freq(arfcn);  		break; +	case MODE_F2A: +		freq = (int)(atof(param) * 10.0f); +		freq2arfcn(freq, uplink); +		break;  	}  	exit(0); | 
