Linux IEEE 802.15.4 and 6LoWPAN development
 help / color / mirror / Atom feed
From: Alexander Aring <alex.aring@gmail.com>
To: Christoffer Holmstedt <christoffer@christofferholmstedt.se>
Cc: linux-wpan@vger.kernel.org
Subject: Re: [PATCH wpan-tools 1/2] info: add cca mode descriptive text to output
Date: Thu, 4 Jun 2015 13:01:17 +0200	[thread overview]
Message-ID: <20150604110113.GA24599@omega> (raw)
In-Reply-To: <20150604092036.GA8041@probook-6560b>

On Thu, Jun 04, 2015 at 11:20:42AM +0200, Christoffer Holmstedt wrote:
> Signed-off-by: Christoffer Holmstedt <christoffer@christofferholmstedt.se>
> ---
>  src/info.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++--------------
>  1 file changed, 62 insertions(+), 18 deletions(-)
> 
> diff --git a/src/info.c b/src/info.c
> index 2434bef6a87f..d2e88febd20c 100644
> --- a/src/info.c
> +++ b/src/info.c
> @@ -146,6 +146,41 @@ static void print_freq_handler(int channel_page, int channel)
>  	}
>  }
>  
> +static void print_cca_mode_handler(enum nl802154_cca_modes cca_mode,
> +				   enum nl802154_cca_opts cca_opt)
> +{
> +	switch (cca_mode) {
> +	case NL802154_CCA_ENERGY:
> +		printf("energy above threshold");
> +		break;
> +	case NL802154_CCA_CARRIER:
> +		printf("carrier sense only");
> +		break;
> +	case NL802154_CCA_ENERGY_CARRIER:
> +		printf("carrier sense with energy above threshold");
> +		switch (cca_opt) {
> +		case NL802154_CCA_OPT_ENERGY_CARRIER_AND:
> +			printf(" (logical operator is 'and')");
> +			break;
> +		case NL802154_CCA_OPT_ENERGY_CARRIER_OR:
> +			printf(" (logical operator is 'or')");
> +			break;
> +		default:
> +			printf(" (logical operator is unknown)");
> +		}
> +		break;
> +	case NL802154_CCA_ALOHA:
> +		printf("ALOHA");
> +		break;
> +	case NL802154_CCA_UWB_SHR:
> +		printf("UWB preamble sense based on the SHR of a frame");
> +		break;
> +	case NL802154_CCA_UWB_MULTIPEXED:
> +		printf("UWB preamble sense based on the packet with the multiplexed preamble");
> +		break;
> +	}
> +}
> +

mhhh, there exists now two different styles to making some "enum" ->
string mapping. The first one was (and this is the original way which
was grabbed from wireless) to have some temp buffer and use sprintf to
put the string in there.

This is a more generic way. After calling the function we should use
printf to printout the string with some format string. You know what I
mean? We should change this.

So what I mean is here use in this function sprintf and put the mapping
string into a local buffer, not directly printf. You can do that after
calling this function.

>  static const char *commands[NL802154_CMD_MAX + 1] = {
>  	[NL802154_CMD_UNSPEC] = "unspec",
>  	[NL802154_CMD_GET_WPAN_PHY] = "get_wpan_phy",
> @@ -235,23 +270,14 @@ static int print_phy_handler(struct nl_msg *msg, void *arg)
>  	}
>  
>  	if (tb_msg[NL802154_ATTR_CCA_MODE]) {
> +		enum nl802154_cca_opts cca_opt;

init this with a invalid value, so default case will occur if not
NL802154_ATTR_CCA_OPT is there.

> +		if (tb_msg[NL802154_ATTR_CCA_OPT])
> +			cca_opt = nla_get_u32(tb_msg[NL802154_ATTR_CCA_OPT]);
> +
>  		cca_mode = nla_get_u32(tb_msg[NL802154_ATTR_CCA_MODE]);
> -		printf("cca_mode: %d", cca_mode);
> -		if (cca_mode == NL802154_CCA_ENERGY_CARRIER) {
> -			enum nl802154_cca_opts cca_opt;
>  
> -			cca_opt = nla_get_u32(tb_msg[NL802154_ATTR_CCA_OPT]);
> -			switch (cca_opt) {
> -			case NL802154_CCA_OPT_ENERGY_CARRIER_AND:
> -				printf(" logical and ");
> -				break;
> -			case NL802154_CCA_OPT_ENERGY_CARRIER_OR:
> -				printf(" logical or ");
> -				break;
> -			default:
> -				printf(" logical op mode unkown ");
> -			}
> -		}
> +		printf("cca_mode: %d, ", cca_mode);
> +		print_cca_mode_handler(cca_mode, cca_opt);
>  		printf("\n");

- Alex

  reply	other threads:[~2015-06-04 11:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-04  9:20 [PATCH wpan-tools 1/2] info: add cca mode descriptive text to output Christoffer Holmstedt
2015-06-04 11:01 ` Alexander Aring [this message]
2015-06-04 11:55   ` Christoffer Holmstedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150604110113.GA24599@omega \
    --to=alex.aring@gmail.com \
    --cc=christoffer@christofferholmstedt.se \
    --cc=linux-wpan@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox