Merge pull request #2862 from haukepetersen/fix_xbee

drivers/xbee: misc enhancements
This commit is contained in:
Oleg Hahm 2015-04-23 23:06:32 +02:00
commit 2f758a6a02
2 changed files with 16 additions and 19 deletions

View File

@ -329,17 +329,6 @@ static int _set_channel(xbee_t *dev, uint8_t *val, size_t len)
return -EINVAL;
}
static int _get_max_packet_size(xbee_t *dev, uint16_t *val, size_t max)
{
if (max < 2) {
return -EOVERFLOW;
}
*val = XBEE_MAX_PAYLOAD_LENGTH;
return 2;
}
static int _get_panid(xbee_t *dev, uint8_t *val, size_t max)
{
uint8_t cmd[2];
@ -468,14 +457,10 @@ int xbee_init(xbee_t *dev, uart_t uart, uint32_t baudrate,
/* get CPU ID */
uint8_t id[CPUID_ID_LEN];
cpuid_get(id);
/* compress to 2 byte */
/* set address */
memset(dev->addr_short, 0, 2);
int i;
for (i = 0; i < (CPUID_ID_LEN / 2); i++) {
dev->addr_short[0] ^= id[i];
}
for (; i < CPUID_ID_LEN; i++) {
dev->addr_short[1] ^= id[i];
for (int i = 0; i < CPUID_ID_LEN; i++) {
dev->addr_short[i & 0x01] ^= id[i];
}
#else
dev->addr_short[0] = (uint8_t)(XBEE_DEFAULT_SHORT_ADDR >> 8);
@ -620,10 +605,21 @@ static int _get(ng_netdev_t *netdev, ng_netconf_opt_t opt,
return _get_addr_short(dev, (uint8_t *)value, max_len);
case NETCONF_OPT_ADDRESS_LONG:
return _get_addr_long(dev, (uint8_t *)value, max_len);
case NETCONF_OPT_ADDR_LEN:
case NETCONF_OPT_SRC_LEN:
if (max_len < sizeof(uint16_t)) {
return -EOVERFLOW;
}
*((uint16_t *)value) = 2;
return sizeof(uint16_t);
case NETCONF_OPT_CHANNEL:
return _get_channel(dev, (uint8_t *)value, max_len);
case NETCONF_OPT_MAX_PACKET_SIZE:
return _get_max_packet_size(dev, (uint16_t *)value, max_len);
if (max_len < sizeof(uint16_t)) {
return -EOVERFLOW;
}
*((uint16_t *)value) = XBEE_MAX_PAYLOAD_LENGTH;
return sizeof(uint16_t);
case NETCONF_OPT_NID:
return _get_panid(dev, (uint8_t *)value, max_len);
case NETCONF_OPT_PROTO:

View File

@ -111,6 +111,7 @@ int main(void)
}
/* start the shell */
puts("Initialization OK, starting shell now");
shell_init(&shell, NULL, SHELL_BUFSIZE, shell_read, shell_put);
shell_run(&shell);