Skip to content

Commit 4bec645

Browse files
committed
Merge branch 'feat/modify_aps_send_raw_command' into 'main'
feat(cli): modify aps send raw command See merge request espressif/esp-zigbee-sdk!199
2 parents 94621ec + cd914f8 commit 4bec645

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

components/esp-zigbee-console/README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,15 @@ options:
106106
- `-e <u8:EID>`: Source endpoint of the command.
107107
- `--profile=<u16:PID>`: Profile id of the command.
108108
- `-c <u16:CID>`: Cluster id of the command.
109+
- `-p <hex:DATA>`: Payload of the command.
110+
- `--repeat <u16:REPEAT>`: Number of payload repetitions, default: 1.
109111

110112
Destination address mode selection: same as [`zcl`](#zcl)
111113

112114
```bash
113-
esp> aps send_raw -e 2 --dst-ep 3 -c 0x0006 -d 0x33d2 -p 0x11223344
115+
esp> aps send_raw -e 2 --dst-ep 3 -c 0x0006 -d 0x33d2 -p 0x11111111
116+
Send aps data frame successful
117+
esp> aps send_raw -e 2 --dst-ep 3 -c 0x0006 -d 0x33d2 -p 0x11 --repeat 4
114118
Send aps data frame successful
115119
```
116120

@@ -123,13 +127,13 @@ esp> aps dump open
123127
```
124128
Remote device send aps data frame.
125129
```bash
126-
esp> aps send_raw -d 0x90eb -e 2 --dst-ep 2 -c 0x0006 -p 0x1122
130+
esp> aps send_raw -d 0x90eb -e 2 --dst-ep 2 -c 0x0006 -p 0x01 --repeat 4
127131
Send aps data frame successful
128132
```
129133
Local device dump aps data frame.
130134
```bash
131135
Received aps data frame
132-
I (680692) : 0x40817760 11 22 |."|
136+
I (680692) : 0x40817760 01 01 01 01 |."|
133137
```
134138
135139

components/esp-zigbee-console/src/cli_cmd_aps.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,22 @@ static esp_err_t cli_aps_send_raw(esp_zb_cli_cmd_t *self, int argc, char **argv)
9494
{
9595
struct {
9696
esp_zb_cli_aps_argtable_t aps;
97-
arg_hex_t *payload;
98-
arg_u8_t *radius;
99-
arg_end_t *end;
97+
arg_hex_t *payload;
98+
arg_u16_t *repeat_count;
99+
arg_u8_t *radius;
100+
arg_end_t *end;
100101
} argtable = {
101102
.payload = arg_hexn("p", "payload", "<hex:DATA>", 0, 1, "APS payload of the command, raw HEX data"),
103+
.repeat_count = arg_u16n(NULL, "repeat", "<u16:REPEAT>", 0, 1, "Number of payload repetitions, default: 1"),
102104
.radius = arg_u8n("r", "radius", "<u8:RADIUS>", 0, 1, "Maximum transmission hops"),
103105
.end = arg_end(2),
104106
};
105107

106108
esp_zb_cli_fill_aps_argtable(&argtable.aps);
107109

108110
esp_err_t ret = ESP_ERR_NOT_FINISHED;
111+
uint16_t repeat_count = 1;
112+
109113
/* Default request settings */
110114
esp_zb_apsde_data_req_t req_params = {
111115
.dst_addr_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT,
@@ -129,11 +133,19 @@ static esp_err_t cli_aps_send_raw(esp_zb_cli_cmd_t *self, int argc, char **argv)
129133
&req_params.cluster_id,
130134
&req_params.profile_id));
131135

132-
req_params.dst_addr_mode = (uint8_t)addr_mode_temp;
136+
req_params.dst_addr_mode = (uint8_t)addr_mode_temp;
133137

134-
if (argtable.payload->count > 0) {
135-
req_params.asdu_length = argtable.payload->hsize[0];
136-
req_params.asdu = argtable.payload->hval[0];
138+
if (argtable.repeat_count->count > 0) {
139+
repeat_count = argtable.repeat_count->val[0];
140+
}
141+
if (argtable.payload->count > 0 && repeat_count > 0) {
142+
uint32_t repeat_length = argtable.payload->hsize[0];
143+
req_params.asdu_length = repeat_length * repeat_count;
144+
req_params.asdu = (uint8_t *)malloc(req_params.asdu_length);
145+
EXIT_ON_FALSE(req_params.asdu, ESP_ERR_NO_MEM, cli_output_line("no memory for aps send raw"));
146+
for (int i = 0; i < repeat_count; i++) {
147+
memcpy(req_params.asdu + i * repeat_length, argtable.payload->hval[0], repeat_length);
148+
}
137149
}
138150
if (argtable.radius->count > 0) {
139151
req_params.radius = argtable.radius->val[0];
@@ -143,6 +155,9 @@ static esp_err_t cli_aps_send_raw(esp_zb_cli_cmd_t *self, int argc, char **argv)
143155
esp_zb_aps_data_confirm_handler_register(&zb_apsde_data_confirm_handler);
144156

145157
exit:
158+
if (req_params.asdu) {
159+
free(req_params.asdu);
160+
}
146161
arg_hex_free(argtable.payload);
147162
ESP_ZB_CLI_FREE_ARGSTRUCT(&argtable);
148163
return ret;

0 commit comments

Comments
 (0)