-
int dwm_node_id_get(uint64_t *p_node_id);
-
获取UWB node的地址.
-
-
uint64_t node_id;
-
dwm_node_id_get(&node_id);
-
printf(“node id:0x%llx \n”, node_id)
*******************************************************************************
-
int dwm_status_get(dwm_status_t* p_status);
-
读取系统状态.读完后系统状态会被自动清除.
-
-
dwm_status_t status;
-
int rv;
-
rv = dwm_status_get(&status);
-
if (rv == DWM_OK) {
-
printf("loc_data: %d\n", status.loc_data);
-
printf("uwbmac_joined: %d\n", status.uwbmac_joined);
-
printf("bh_data_ready: %d\n", status.bh_data_ready);
-
printf("bh_status_changed: %d\n", status.bh_status_changed);
-
printf("bh_initialized: %d\n", status.bh_initialized);
-
printf("uwb_scan_ready: %d\n", status.uwb_scan_ready);
-
printf("usr_data_ready: %d\n", status.usr_data_ready);
-
printf("usr_data_sent: %d\n", status.usr_data_sent);
-
printf("fwup_in_progress: %d\n", status.fwup_in_progress);
-
} else {
-
printf("error\n");
-
}
*******************************************************************************
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不能使用
*******************************************************************************
-
int dwm_enc_key_set(dwm_enc_key_t* p_key);
-
int dwm_enc_key_clear(void);
-
设置密钥/清除密钥. 密钥设置后自动生效, 同时BLE功能会被禁用.
-
-
dwm_enc_key_t key;
-
key.byte[0] = 0x00;
-
key.byte[1] = 0x11;
-
key.byte[2] = 0x22;
-
...
-
key.byte[15] = 0xFF;
-
dwm_enc_key_set(&key)
-
-
rv = dwm_enc_key_clear();
-
if (rv == DWM_ERR_INTERNAL)
-
printf(“internal error\n”)
*******************************************************************************
-
int dwm_nvm_usr_data_set(uint8_t* p_data, uint8_t len);
-
int dwm_usr_data_read(uint8_t* p_data, uint8_t* p_len);
-
读写用户区数据. 最大数据量为 250
-
-
uint8_t buf[DWM_NVM_USR_DATA_LEN_MAX];
-
uint8_t len = DWM_NVM_USR_DATA_LEN_MAX;
-
rv = dwm_nvm_usr_data_set(buf, len);
-
if ( DWM_OK == rv )
-
printf(“ok\n”);
-
else
-
printf(“error, %d”, rv);
-
-
len = DWM_USR_DATA_LEN_MAX;
-
dwm_usr_data_read(data, &len)
没有对应 UART/SPI TLV格式交互
*******************************************************************************
-
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);
-
设置某个PIN的函数回调
-
int dwm_gpio_irq_dis(dwm_gpio_idx_t idx);
-
去掉中断回调
-
-
void gpio_cb(void* p_data)
-
{
-
/* callback routine */
-
}
-
dwm_gpio_irq_cfg(DWM_GPIO_IDX_13, DWM_IRQ_TYPE_EDGE_RISING, &gpio_cb, NULL)
dwm_gpio_irq_dis(DWM_GPIO_IDX_13);
*******************************************************************************
-
int dwm_i2c_read(uint8_t addr, uint8_t* p_data, uint8_t len);
-
int dwm_i2c_write(uint8_t addr, uint8_t* p_data, uint8_t len, bool no_stop);
-
-
同 IIC slave 交互.
-
Address of a slave device (only 7 LSB)
-
no_stop: 0 or 1. If set to 1, the stop condition is not generated on the bus after the transfer has completed (allowing for a repeated start in the next transfer)
-
-
uint8_t data[2];
-
const uint8_t addr = 0x33; // some address of the slave device
-
dwm_i2c_read(addr, data, 2);
-
-
uint8_t data[2];
-
const uint8_t addr = 1; // some address of the slave device
-
data[0] = 0xAA;
-
data[1] = 0xBB;
-
dwm_i2c_write(addr, data, 2, true)
*******************************************************************************
-
void dwm_evt_listener_register(uint32_t evt_id_map, void* p_context);
-
注册时间的监听回调. 用户通过 dwm_evt_wait来等待事件. 事件会在LocationEngine计算位置结束后被触发.此API只能在用户程序中调用, 不能用于 UART/SPI TLV. 在休眠模式下, 此事件会唤醒node.
-
evt_id_map: 需要注意的事件组合.
-
p_context: 在回调函数中要引入的数据.
-
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.x, p_evt->loc.pos.y, p_evt->loc.pos.z, p_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); //递归调用.
}
}
*******************************************************************************
-
int dwm_wake_up(void);
-
防止线程进入sleep模式. 只能在 thread context被调用.
-
/* THREAD 1: sleep and block*/
-
dwm_sleep();
-
/*do something*/
-
...
-
/*THREAD 2: wait until event */
-
dwm_evt_wait(&evt);
-
/*unblock dwm_sleep()*/
-
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.
? : 显示帮助信息.
点击(此处)折叠或打开
-
dwm> ?
-
Usage: <command> [arg0] [arg1]
-
Build-in commands:
-
** Command group: Base **
-
?: this help
-
help: this help
-
quit: quit 退回到 Generic Mode.
-
-
** Command group: GPIO **
-
gc: GPIO clear 可以使用 gc 13: 把 gpio13置为 0
-
gg: GPIO get gg 13 --> gpio13: 0
-
gs: GPIO set gs 13 --> gpio13: 1
-
gt: GPIO toggle 反转指定的IO, 例如gt 13
-
-
** Command group: SYS **
-
f: Show free memory on the heap 返回 [000014.560 INF] mem: free=3888 alloc=9184 tot=13072
-
ps: Show running threads
-
pms: Show PM tasks
-
reset: Reboot the system 重启复位模块.
-
si: System info 包括BLE地址/ENC的使能标记/node配置/PANID/node addr/版本号等
-
ut: Show device uptime 已经运行的时间. uptime: 00:07:49.210 0 days (469210 ms)
-
frst: Factory reset
-
-
** Command group: SENS ** //加速计
-
twi: General purpose TWI read twi [bytes to read (1 or 2)] 读取寄存器值
-
例如: dwm> twi 0x33 0x0f 1 --> twi: addr=0x33, reg[0x0f]=0x33
-
aid: Read ACC device ID dwm> aid --> acc: 0x33
-
av: Read ACC values --> acc: x = 240, y = -3792, z = 16240
-
-
** Command group: LE ** //LocationEngine 结果显示
-
les: Show meas. and pos. 持续显示LE结果(tag的位置以及和各个anchor的距离), 同样命令可以终止显示, 在输入一次命令又开始显示. 类似的输出为. anchorID[anchorPos]=distance. est[估算的位置和置信度]
-
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]
-
lec: Show meas. and pos. in CSV
-
显示的类似输出
-
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 /*结果的置信度*/
-
-
lep: Show pos. in CSV 仅仅显示LE计算后的评估结果. 例如: POS,2.57,2.00,1.67,97
-
-
** Command group: UWBMAC ** //Node 设置. 命令之后需要敲入两次 Enter 按键.
-
nmg: Get node mode 返回: mode: tn (act,twr,np,nole)
-
nmp: Set mode to PN (passive)
-
nmo: Set mode to PN (off) Enable passive offline option and resets the node.
-
nma: Set mode to AN Configures node to as anchor, active and reset the node.
-
nmi: Set mode to AIN Configures node to as anchor - initiator, active and reset the node.
-
nmt: Set mode to TN Configures node to as tag, active and reset the node.
-
nmtl: Set mode to TN-LP Configures node to as tag, active, low power and resets the node.
-
nmb: Set mode to BN: bridge node.
-
bpc: Toggle BW/TxPWR comp
-
la: Show AN list Show anchor list.
-
lb: Show BN list Show bridge list.
-
nis: Set Network ID
-
nls: Set node label
-
stg: Get stats
-
stc: Clear stats
-
-
scs: Stationary configuration set. Sets sensitivity (valid args are 0,1,2)
-
scg: Stationary configuration get --> sensitivity=1
-
-
** Command group: API **
-
tlv: Send TLV frame: 例如 dwm> tlv type len [value]
-
aurs: Set upd rate aurs
-
aurg: Get upd rate
-
apg: Get pos Get position of the node 返回: x:100 y:120 z:2500 qf:100
-
aps: Set pos 例如: dwm> aps 100 120 2500
-
acas: Set anchor config acas
-
例如: dwm> acas 0 0 1 1 2 0
-
acts: Set tag config acts
-
例如: dwm> acts 0 1 0 1 1 0 0 0
-
aks: Sets encryption key
-
例如: aks 00112233445566778899aabbccddeeff
-
akc: Clears encryption key and disables encryption
-
ans: Writes user data to non-volatile memory
-
例如: dwm> ans 00112233445566778899aabbccddeeff00112233
-
ang: Reads data from non-volatile memory.
-
-
utpg: Get transmit power of the DW1000 查看发送功率 --> utpg: pg_delay=xC5 tx_power=x29496989
-
utps: Set transmit power of the DW1000 设置发送功率 utps
-
例如 utps 0xc2 0x28486888
-
udi: Toggle displaying of IoT data received via backhaul. 显示downlink的用户自定义数据.
-
uui: Send uplink IoT data via backhaul uui [cnt]
-
例如: uui 11223344 100 100位重复发送的次数.
-
-
** Tips **
-
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 的类型列表
阅读(5061) | 评论(0) | 转发(0) |