Skip to content

Commit

Permalink
main,adcs: Enhancement of power command
Browse files Browse the repository at this point in the history
If an abnormal packet size or command code is received, the reply
telemetry was not sent previously. This commit addresses this by
ensuring the reply telemetry is sent. In such cases, the command
ID will be uniformly set to 0xFF, as this is necessary for
categorization on the Yamcs side.

Signed-off-by: Takuya Sasaki <takuya.sasaki@spacecubics.com>
  • Loading branch information
sasataku committed Oct 28, 2024
1 parent 34d4ec1 commit f83d4fc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
16 changes: 11 additions & 5 deletions adcs/src/cmd/pwrctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static int csp_power_cycle_cmd(uint8_t command_id, csp_packet_t *packet)

int csp_pwrctrl_handler(csp_packet_t *packet)
{
int ret;
int ret = 0;
uint8_t command_id;

if (packet == NULL) {
Expand All @@ -82,8 +82,9 @@ int csp_pwrctrl_handler(csp_packet_t *packet)

if (packet->length < PWRCTRL_CMD_MIN_SIZE) {
LOG_ERR("Invalide command size: %d", packet->length);
ret = -EINVAL;
goto free;
command_id = CSP_UNKNOWN_CMD_CODE;
ret = -EMSGSIZE;
goto reply;
}

command_id = packet->data[CSP_COMMAND_ID_OFFSET];
Expand All @@ -97,11 +98,16 @@ int csp_pwrctrl_handler(csp_packet_t *packet)
break;
default:
LOG_ERR("Unkown command code: %d", command_id);
command_id = CSP_UNKNOWN_CMD_CODE;
ret = -EINVAL;
break;
}

free:
csp_buffer_free(packet);
reply:
if (ret < 0) {
csp_send_std_reply(packet, command_id, ret);
csp_buffer_free(packet);
}

end:
return ret;
Expand Down
2 changes: 2 additions & 0 deletions include/sc_csp.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@
#define CSP_TELEMETRY_ID_OFFSET (0U)
#define CSP_COMMAND_ID_OFFSET (0U)
#define CSP_ERROR_CODE_OFFSET (1U)

#define CSP_UNKNOWN_CMD_CODE (255U)
15 changes: 10 additions & 5 deletions main/src/cmd/pwrctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static int csp_power_cycle_cmd(uint8_t command_id, csp_packet_t *packet)

int csp_pwrctrl_handler(csp_packet_t *packet)
{
int ret;
int ret = 0;
uint8_t command_id;

if (packet == NULL) {
Expand All @@ -82,8 +82,9 @@ int csp_pwrctrl_handler(csp_packet_t *packet)

if (packet->length < PWRCTRL_CMD_MIN_SIZE) {
LOG_ERR("Invalide command size: %d", packet->length);
ret = -EINVAL;
goto free;
command_id = CSP_UNKNOWN_CMD_CODE;
ret = -EMSGSIZE;
goto reply;
}

command_id = packet->data[CSP_COMMAND_ID_OFFSET];
Expand All @@ -97,12 +98,16 @@ int csp_pwrctrl_handler(csp_packet_t *packet)
break;
default:
LOG_ERR("Unkown command code: %d", command_id);
command_id = CSP_UNKNOWN_CMD_CODE;
ret = -EINVAL;
break;
}

free:
csp_buffer_free(packet);
reply:
if (ret < 0) {
csp_send_std_reply(packet, command_id, ret);
csp_buffer_free(packet);
}

end:
return ret;
Expand Down

0 comments on commit f83d4fc

Please sign in to comment.