Skip to content

Commit

Permalink
zero: csp-handler: Add sequence number for shell cmd reply
Browse files Browse the repository at this point in the history
Shell command reply telemetry may be divided into multiple
telemetries. In such cases, sequence numbers will be assigned to
facilitate association.

Signed-off-by: Takuya Sasaki <takuya.sasaki@spacecubics.com>
  • Loading branch information
sasataku committed Nov 22, 2024
1 parent d4efdc8 commit 185e230
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
16 changes: 11 additions & 5 deletions zero/meta-csp/recipes-cspd/csp-handler/files/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
static GQueue shell_work_queue;
static pthread_t shell_work;

void send_cmd_reply(csp_packet_t *packet, uint8_t command_id, int err_code, uint8_t *result)
void send_cmd_reply(csp_packet_t *packet, uint8_t command_id, int err_code, uint32_t seq_number,
uint8_t *result)
{
struct shell_cmd_reply_telemetry tlm;
csp_packet_t *clone;
Expand All @@ -46,7 +47,8 @@ void send_cmd_reply(csp_packet_t *packet, uint8_t command_id, int err_code, uint
clone = csp_buffer_clone(packet);

tlm.telemetry_id = command_id;
tlm.error_code = err_code;
tlm.error_code = htole32(err_code);
tlm.seq_number = htole32(seq_number);
if (result == NULL) {
memset(tlm.result, 0, SHELL_RESULT_BUF_SIZE);
} else {
Expand Down Expand Up @@ -85,6 +87,7 @@ static void shell_cmd(uint8_t command_id, csp_packet_t *packet)
int nfds;
size_t rsize;
uint8_t reply_count = 0;
static uint32_t seq_number = 0;

if (packet->length != SHELL_EXEC_CMD_MIN_SIZE) {
sd_journal_print(LOG_ERR, "Invalide command size: %d", packet->length);
Expand Down Expand Up @@ -127,12 +130,13 @@ static void shell_cmd(uint8_t command_id, csp_packet_t *packet)
if (rsize <= 0) {
if (reply_count == 0) {
strcpy(result, "No output");
send_cmd_reply(packet, command_id, rsize, (uint8_t *)result);
send_cmd_reply(packet, command_id, rsize, seq_number,
(uint8_t *)result);
sd_journal_print(LOG_DEBUG, "Send reply (No output)");
}
break;
}
send_cmd_reply(packet, command_id, 0, (uint8_t *)result);
send_cmd_reply(packet, command_id, 0, seq_number, (uint8_t *)result);
memset(result, 0, sizeof(result));
reply_count++;
sd_journal_print(LOG_DEBUG, "Send reply %d times", reply_count);
Expand All @@ -144,9 +148,11 @@ static void shell_cmd(uint8_t command_id, csp_packet_t *packet)

end:
if (ret < 0) {
send_cmd_reply(packet, command_id, ret, NULL);
send_cmd_reply(packet, command_id, ret, seq_number, NULL);
}

seq_number++;

/*
* Since the reply uses a clone for the response, the original is released manually.
*/
Expand Down
1 change: 1 addition & 0 deletions zero/meta-csp/recipes-cspd/csp-handler/files/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct shell_err_reply_telemetry {
struct shell_cmd_reply_telemetry {
uint8_t telemetry_id;
uint32_t error_code;
uint32_t seq_number;
uint8_t result[SHELL_RESULT_BUF_SIZE];
} __attribute__((__packed__));

Expand Down

0 comments on commit 185e230

Please sign in to comment.