Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9464707
  • 博文数量: 1750
  • 博客积分: 12961
  • 博客等级: 上将
  • 技术积分: 20091
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-09 11:25
个人简介

偷得浮生半桶水(半日闲), 好记性不如抄下来(烂笔头). 信息爆炸的时代, 学习是一项持续的工作.

文章分类

全部博文(1750)

文章存档

2024年(26)

2023年(26)

2022年(112)

2021年(217)

2020年(157)

2019年(192)

2018年(81)

2017年(78)

2016年(70)

2015年(52)

2014年(40)

2013年(51)

2012年(85)

2011年(45)

2010年(231)

2009年(287)

分类: 其他平台

2019-09-11 14:51:56

  1. int dwm_node_id_get(uint64_t *p_node_id);
  2. 获取UWB node的地址.

  3. uint64_t node_id;
  4. dwm_node_id_get(&node_id);
  5. printf(“node id:0x%llx \n”, node_id)

*******************************************************************************

点击(此处)折叠或打开

  1. int dwm_status_get(dwm_status_t* p_status);
  2. 读取系统状态.读完后系统状态会被自动清除.

  3. dwm_status_t status;
  4. int rv;
  5. rv = dwm_status_get(&status);
  6. if (rv == DWM_OK) {
  7. printf("loc_data: %d\n", status.loc_data);
  8. printf("uwbmac_joined: %d\n", status.uwbmac_joined);
  9. printf("bh_data_ready: %d\n", status.bh_data_ready);
  10. printf("bh_status_changed: %d\n", status.bh_status_changed);
  11. printf("bh_initialized: %d\n", status.bh_initialized);
  12. printf("uwb_scan_ready: %d\n", status.uwb_scan_ready);
  13. printf("usr_data_ready: %d\n", status.usr_data_ready);
  14. printf("usr_data_sent: %d\n", status.usr_data_sent);
  15. printf("fwup_in_progress: %d\n", status.fwup_in_progress);
  16. } else {
  17. printf("error\n");
  18. }



*******************************************************************************
dwm_int_cfg_set : 把专用GPIO配置成事件/中断驱动.  使能或者禁用
dwm_int_cfg_get: 获取配置. TLV命令 0x35  0x00, 响应 0x40  0x02  0x03 0x00

GPIO pin CORE_INT1 配成 interrupts/events, 用户则可以使用此pin作为外部中断. 中断可以通过 dwm_status_get 获取从而做出新的处理动作. 此PIN状态读取后自动清除. 此命令仅支持在 UART/SPI接口中调用. UserApp不能使用


*******************************************************************************

点击(此处)折叠或打开

  1. int dwm_enc_key_set(dwm_enc_key_t* p_key);
  2. int dwm_enc_key_clear(void);
  3. 设置密钥/清除密钥. 密钥设置后自动生效, 同时BLE功能会被禁用.

  4. dwm_enc_key_t key;
  5. key.byte[0] = 0x00;
  6. key.byte[1] = 0x11;
  7. key.byte[2] = 0x22;
  8. ...
  9. key.byte[15] = 0xFF;
  10. dwm_enc_key_set(&key)

  11. rv = dwm_enc_key_clear();
  12. if (rv == DWM_ERR_INTERNAL)
  13. printf(“internal error\n”)



*******************************************************************************

点击(此处)折叠或打开

  1. int dwm_nvm_usr_data_set(uint8_t* p_data, uint8_t len);
  2. int dwm_usr_data_read(uint8_t* p_data, uint8_t* p_len);
  3. 读写用户区数据. 最大数据量为 250

  4. uint8_t buf[DWM_NVM_USR_DATA_LEN_MAX];
  5. uint8_t len = DWM_NVM_USR_DATA_LEN_MAX;
  6. rv = dwm_nvm_usr_data_set(buf, len);
  7. if ( DWM_OK == rv )
  8. printf(“ok\n”);
  9. else
  10. printf(“error, %d”, rv);

  11. len = DWM_USR_DATA_LEN_MAX;
  12. dwm_usr_data_read(data, &len)
没有对应 UART/SPI TLV格式交互
*******************************************************************************

点击(此处)折叠或打开

  1. int dwm_gpio_irq_cfg(dwm_gpio_idx_t idx, dwm_gpio_irq_type_t irq_type, dwm_gpio_cb_t* p_cb, void* p_data);
  2. 设置某个PIN的函数回调
  3. int dwm_gpio_irq_dis(dwm_gpio_idx_t idx);
  4. 去掉中断回调

  5. void gpio_cb(void* p_data)
  6. {
  7. /* callback routine */
  8. }
  9. dwm_gpio_irq_cfg(DWM_GPIO_IDX_13, DWM_IRQ_TYPE_EDGE_RISING, &gpio_cb, NULL)
  dwm_gpio_irq_dis(DWM_GPIO_IDX_13);


*******************************************************************************

点击(此处)折叠或打开

  1. int dwm_i2c_read(uint8_t addr, uint8_t* p_data, uint8_t len);
  2. int dwm_i2c_write(uint8_t addr, uint8_t* p_data, uint8_t len, bool no_stop);

  3. 同 IIC slave 交互.
  4. Address of a slave device (only 7 LSB)
  5. no_stop: 0 or 1. If set to 1, the stop condition is not generated on the bus after the transfer has completed (allowing forrepeated start in the next transfer)

  6. uint8_t data[2];
  7. const uint8_t addr = 0x33; // some address of the slave device
  8. dwm_i2c_read(addr, data, 2);

  9. uint8_t data[2];
  10. const uint8_t addr = 1; // some address of the slave device
  11. data[0] = 0xAA;
  12. data[1] = 0xBB;
  13. dwm_i2c_write(addr, data, 2, true)
*******************************************************************************

点击(此处)折叠或打开

  1. void dwm_evt_listener_register(uint32_t evt_id_map, void* p_context);
  2. 注册时间的监听回调. 用户通过 dwm_evt_wait来等待事件. 事件会在LocationEngine计算位置结束后被触发.此API只能在用户程序中调用, 不能用于 UART/SPI TLV. 在休眠模式下, 此事件会唤醒node.
  3. evt_id_map: 需要注意的事件组合.
  4. p_context: 在回调函数中要引入的数据.
  5. dwm_evt_listener_register(DWM_EVT_LOC_READY | DWM_EVT_USR_DATA_READY | DWM_EVT_USR_DATA_SENT DWM_EVT_UWB_SCAN_READY | DWM_EVT_BH_INITIALIZED | DWM_EVT_UWBMAC_JOINED_CHANGED, NULL)
*******************************************************************************

点击(此处)折叠或打开

int dwm_evt_wait(dwm_evt_t *p_evt);
等待 DWM 模块的事件发生, 内部有 event buffer, 可能溢出. 但 event buffer 为空时, dwm_evt_wait 会阻塞并进入sleep模式, 直到有 event 发生.

void on_dwm_evt(dwm_evt_t *p_evt)
{
  int i;
  switch (p_evt->header.id) {
      /* New location data */
      case DWM_EVT_LOC_READY: //LocateEngine 计算位置已经结束, 打印当前位置
        printf("\nT:%lu ", dwm_systime_us_get());
        if (p_evt->loc.pos_available) {
          printf("POS:[%ld,%ld,%ld,%u] ", p_evt->loc.pos.xp_evt->loc.pos.y, p_evt->loc.pos.zp_evt->loc.pos.qf);
        }
        
else {
           printf("Location engine is disabled\n");
        }
        for (i = 0; i < p_evt->loc.anchors.dist.cnt; ++i)
          //LocateEngine 计算位置已经结束, 打印与各个anchor之间的距离信息.

          printf("DIST%d:", i);
          printf("0x%04X", (unsigned int)(p_evt->loc.anchors.dist.addr[i] & 0xffff));
          if (i < p_evt->loc.anchors.an_pos.cnt) {
             printf("[%ld,%ld,%ld]",
             p_evt->loc.anchors.an_pos.pos[i].x,
             p_evt->loc.anchors.an_pos.pos[i].y,
             p_evt->loc.anchors.an_pos.pos[i].z);
           }
           printf("=[%lu,%u] ", p_evt->loc.anchors.dist.dist[i],
           p_evt->loc.anchors.dist.qf[i]);
        }
        printf("\n");
        break;

      case DWM_EVT_USR_DATA_READY: //有用户自定义数据来到
        printf("hex:");
        for (i = 0; i < p_evt->header.len - sizeof(dwm_evt_hdr_t); ++i) {
            printf("%02x ", p_evt->usr_data[i]);
        }
        printf("\n");
        break;

        case DWM_EVT_USR_DATA_SENT: //用户自定义数据发送完毕.
          printf("iot sent\n");
          break;

        case DWM_EVT_UWB_SCAN_READY: //UWB 扫描结束.扫描结果打印
          printf("[mode,rssi]: ");
          for (i = 0; i < p_evt->uwb_scan.cnt; ++i) {
            printf("[%u, %d]", p_evt->uwb_scan.mode[i], p_evt->uwb_scan.rssi[i]);
          }
          printf("\n");
          break;

        case DWM_EVT_BH_INITIALIZED_CHANGED:
          printf("backhaul available = %d\n", p_evt->bh_initialized);
          break;

        case DWM_EVT_UWBMAC_JOINED_CHANGED:
          printf("UWBMAC joined = %d\n", p_evt->uwbmac_joined);
          break;
        default:
          break;
        }
        /* Indicate the application has finished the tasks and can now */
        dwm_sleep();
      } //end switch
      
      int rv;
      dwm_evt_t evt;
      rv = dwm_evt_wait(&evt);
      if (rv == DWM_ERR_OVERRUN) {
        printf("event buffer overflow\n");
      }
      
else {
        on_dwm_evt(&evt); //递归调用.
      }
}
*******************************************************************************

点击(此处)折叠或打开

  1. int dwm_wake_up(void);
  2. 防止线程进入sleep模式. 只能在 thread context被调用.
  3. /* THREAD 1: sleep and block*/
  4. dwm_sleep();
  5. /*do something*/
  6. ...
  7. /*THREAD 2: wait until event */
  8. dwm_evt_wait(&evt);
  9. /*unblock dwm_sleep()*/
  10. dwm_wake_up()
*******************************************************************************

Backhaul API functions:  当 node 配置成 bridge 时. ( dwm_cfg_anchor_set 可以设置 uwb_mode)
通过SPI接口进行交互时. 使用这些API进行周期性的数据交互.
dwm_bh_status_get : 获取 Backhaul  状态.
dwm_backhaul_xfer: 发送数据, 读取数据.  downlink_byte_cnt
*******************************************************************************

*******************************************************************************
UART shell 的命令:
115200 8N1 进入. 1秒内三次Enter按键(或者发送三个0x0D), 把Uart从GenericMode切换到ShellMode.  敲入退回到GenericMode.
?  : 显示帮助信息.
点击(此处)折叠或打开
  1. dwm> ?
  2. Usage: <command> [arg0] [arg1]
  3. Build-in commands:
  4. ** Command group: Base **
  5. ?: this help
  6. help: this help
  7. quit: quit  退回到 Generic Mode.

  8. ** Command group: GPIO **
  9. gc: GPIO clear        可以使用 gc 13: 把 gpio13置为 0
  10. gg: GPIO get          gg 13  -->  gpio13: 0
  11. gs: GPIO set          gs 13 --> gpio13: 1
  12. gt: GPIO toggle       反转指定的IO, 例如gt 13

  13. ** Command group: SYS **
  14. f: Show free memory on the heap  返回 [000014.560 INF] mem: free=3888 alloc=9184 tot=13072
  15. ps: Show running threads
  16. pms: Show PM tasks
  17. reset: Reboot the system          重启复位模块.
  18. si: System info                   包括BLE地址/ENC的使能标记/node配置/PANID/node addr/版本号等
  19. ut: Show device uptime            已经运行的时间. uptime: 00:07:49.210 0 days (469210 ms)
  20. frst: Factory reset

  21. ** Command group: SENS **  //加速计 
  22. twi: General purpose TWI read      twi [bytes to read (1 or 2)] 读取寄存器值
  23.     例如: dwm> twi 0x33 0x0f 1  -->  twi: addr=0x33, reg[0x0f]=0x33
  24. aid: Read ACC device ID            dwm> aid --> acc: 0x33
  25. av: Read ACC values            --> acc: x = 240, y = -3792, z = 16240

  26. ** Command group: LE **  //LocationEngine 结果显示
  27. les: Show meas. and pos. 持续显示LE结果(tag的位置以及和各个anchor的距离), 同样命令可以终止显示, 在输入一次命令又开始显示. 类似的输出为. anchorID[anchorPos]=distance.  est[估算的位置和置信度]
  28.      1151[5.00,8.00,2.25]=6.48 0CA8[0.00,8.00,2.25]=6.51 111C[5.00,0.00,2.25]=3.18
         1150[0.00,0.00,2.25]=3.16 le_us=2576 est[2.57,1.98,1.68,100]
  29. lec: Show meas. and pos. in CSV
  30.     显示的类似输出
  31.         DIST,4 /*anchor的个数*/,AN0,1151/*AnchorID*/,5.00,8.00,2.25/*anchorPos*/,6.44/*distance*/,AN1,0CA8,0.00,8.00,2.25,6.50,AN2,111C,5.00,0.00,2.25,3.24,AN3,1150,0.00,0.00,2.25,3.19,POS,2.55,2.01,1.71/*LE计算之后评估位置*/,98 /*结果的置信度*/

  32. lep: Show pos. in CSV 仅仅显示LE计算后的评估结果.  例如: POS,2.57,2.00,1.67,97

  33. ** Command group: UWBMAC **  //Node 设置. 命令之后需要敲入两次 Enter 按键.
  34. nmg: Get node mode       返回: mode: tn (act,twr,np,nole)
  35. nmp: Set mode to PN (passive
  36. nmo: Set mode to PN (off)    Enable passive offline option and resets the node.
  37. nma: Set mode to AN          Configures node to as anchor, active and reset the node.
  38. nmi: Set mode to AIN         Configures node to as anchor - initiator, active and reset the node.    
  39. nmt: Set mode to TN          Configures node to as tag, active and reset the node.
  40. nmtl: Set mode to TN-LP      Configures node to as tag, active, low power and resets the node.
  41. nmb: Set mode to BN:  bridge node.
  42. bpc: Toggle BW/TxPWR comp
  43. la: Show AN list           Show anchor list.
  44. lb: Show BN list           Show bridge list.
  45. nis: Set Network ID
  46. nls: Set node label
  47. stg: Get stats
  48. stc: Clear stats

  49. scs: Stationary configuration set. Sets sensitivity (valid args are 0,1,2)
  50. scg: Stationary configuration get  --> sensitivity=1

  51. ** Command group: API **
  52. tlv: Send TLV frame:  例如 dwm> tlv type len [value]
  53. aurs: Set upd rate    aurs
  54. aurg: Get upd rate  
  55. apg: Get pos          Get position of the node 返回: x:100 y:120 z:2500 qf:100
  56. aps: Set pos          例如: dwm> aps 100 120 2500
  57. acas: Set anchor config   acas
  58.     例如:  dwm> acas 0 0 1 1 2 0
  59. acts: Set tag config      acts
  60.     例如:  dwm> acts 0 1 0 1 1 0 0 0
  61. aks: Sets encryption key    
  62.     例如: aks 00112233445566778899aabbccddeeff
  63. akc: Clears encryption key and disables encryption
  64. ans: Writes user data to non-volatile memory
  65.     例如: dwm> ans 00112233445566778899aabbccddeeff00112233
  66. ang: Reads data from non-volatile memory.

  67. utpg: Get transmit power of the DW1000 查看发送功率 --> utpg: pg_delay=xC5 tx_power=x29496989 
  68. utps: Set transmit power of the DW1000 设置发送功率 utps  
  69.     例如 utps 0xc2 0x28486888
  70. udi: Toggle displaying of IoT data received via backhaul. 显示downlink的用户自定义数据.
  71. uui: Send uplink IoT data via backhaul  uui [cnt]
  72.     例如: uui 11223344 100  100位重复发送的次数.

  73. ** Tips **
  74. Press Enter to repeat the last command  Enter键为重复上次的输入命令.
*******************************************************************************

*******************************************************************************
BLE API
BLE GATT Model: 数据为小端字节序.
network node service UUID   680c21d9-c946-4c1f-9c11-baa1c21329e7

uuid

name

length

value

flags

Std. GAP service, label  0x2A00

Label

Var

UTF-8 encoded string. 
label is part of the standard mandatory GAP service (0x1800) under the standard name characteristic (0x2A00).

RW

3f0afd88-7770-46b0-b5e7-9fc099598964

Operation mode

2 bytes

RW

80f9d8bc-3bff-45bb-a181-2d6a37991208

Network  ID

2 bytes

PAN ID

RW

a02b947e-df97-4516-996a-1882521e0ead

Location data mode

1 bytes

0 - Position

1 - Distances

2 - Position + distances

RW

003bbdf2-c634-4b3d-ab56-7ec889b89a37

Location data

106B max

 RO

f4a67d7d-379d-4183-9c03-4b6ea5103291

Proxy positions

76 B max

Used by the module as a notification about new tag positions for the BLE central
● 1 byte: number of elements (max 5)
● [sequence] tag position: 2-byte node id, 13-byte position

RO

1e63b1eb-d4ed-444e-af54-c1e965192501

Device Info

29 bytes

Node ID (8 bytes),

HW version (4 bytes),

FW1 version (4 bytes),

FW2 version (4 bytes),

FW1 checksum (4 bytes),

FW2 checksum (4 bytes),

Operation flags (1 byte)

RO

0eb2bc59-baf1-4c1c-8535-8a0204c69de5

Statistics

120 bytes

Node statistics

RO

5955aa10-e085-4030-8aa6-bdfac89ac32b

FW update push

37 B max

Used to send structured data (FW update packets) to the module (BLE peripheral), the size is set according to max transmission unit (MTU).

WO

9eed0e27-09c0-4d1c-bd92-7c441daba850

FW update poll

9 bytes

Used by the module as a response/notification for the BLE central

RO

ed83b848-da03-4a0a-a2dc-8b401080e473

Disconnect

1 bytes

Used to explicitly disconnect from BLE peripheral by writing value=1 (workaround due to android behavior)

WO





BLE 广播
    让其他的设备知道自己的存在. broadcast payload  为 [length, type, ]
    anchor/tag 广播的内容仅为  presence + operation mode, 因为BLE的报文太小不足以承载位置等信息.
   最大为31字节.
     1.  前 3 字节为 固定 flags.
     2.  剩下的 28 字节可以被用户自定义, 建议采用 [length, type, ]的组合.

*******************************************************************************

TLV 的类型列表


阅读(5087) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~