Skip to content

Commit

Permalink
Merge pull request #2709 from haukepetersen/ng_scnetif_power
Browse files Browse the repository at this point in the history
shell/sc_netif: added means to control TX power
  • Loading branch information
miri64 committed Mar 27, 2015
2 parents eb00d37 + f2e2cfd commit ff5633e
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions sys/shell/commands/sc_netif.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ static void _set_usage(char *cmd_name)
" * \"nid\" - sets the network identifier (or the PAN ID)\n"
" * \"pan\" - alias for \"nid\"\n"
" * \"pan_id\" - alias for \"nid\"\n"
" * \"power\" - TX power in dBm\n"
" * \"src_len\" - sets the source address length in byte\n");
}

Expand Down Expand Up @@ -137,6 +138,10 @@ static void _print_netconf(ng_netconf_opt_t opt)
printf("network identifier");
break;

case NETCONF_OPT_TX_POWER:
printf("TX power [in dBm]");
break;

default:
/* we don't serve these options here */
break;
Expand All @@ -147,6 +152,7 @@ void _netif_list(kernel_pid_t dev)
{
uint8_t hwaddr[MAX_ADDR_LEN];
uint16_t u16;
int16_t i16;
int res;

printf("Iface %2d ", dev);
Expand All @@ -171,6 +177,12 @@ void _netif_list(kernel_pid_t dev)
printf(" NID: 0x%" PRIx16 " ", u16);
}

res = ng_netapi_get(dev, NETCONF_OPT_TX_POWER, 0, &i16, sizeof(i16));

if (res >= 0) {
printf(" TX-Power: %" PRIi16 "dBm ", i16);
}

printf("\n ");

res = ng_netapi_get(dev, NETCONF_OPT_ADDRESS_LONG, 0, hwaddr, sizeof(hwaddr));
Expand Down Expand Up @@ -240,6 +252,23 @@ static void _netif_set_u16(kernel_pid_t dev, ng_netconf_opt_t opt,
}
}

static void _netif_set_i16(kernel_pid_t dev, ng_netconf_opt_t opt,
char *i16_str)
{
int16_t val = (int16_t)atoi(i16_str);

if (ng_netapi_set(dev, opt, 0, (int16_t *)&val, sizeof(int16_t)) < 0) {
printf("error: unable to set ");
_print_netconf(opt);
puts("");
return;
}

printf("success: set ");
_print_netconf(opt);
printf(" on interface %" PRIkernel_pid " to %i\n", dev, val);
}

static void _netif_set_addr(kernel_pid_t dev, ng_netconf_opt_t opt,
char *addr_str)
{
Expand Down Expand Up @@ -282,6 +311,9 @@ static void _netif_set(char *cmd_name, kernel_pid_t dev, char *key, char *value)
(strcmp("pan_id", key) == 0)) {
_netif_set_u16(dev, NETCONF_OPT_NID, value);
}
else if (strcmp("power", key) == 0) {
_netif_set_i16(dev, NETCONF_OPT_TX_POWER, value);
}
else if (strcmp("src_len", key) == 0) {
_netif_set_u16(dev, NETCONF_OPT_SRC_LEN, value);
}
Expand Down

0 comments on commit ff5633e

Please sign in to comment.