-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
zero: csp-handler: Add get version command handler
Adds the getting version command handler. Currently, it only returns a hard-coded version string. Additionally, the port number uses Port `16`, the same as the command for getting system-related information from the MAIN/ADCS board. Signed-off-by: Takuya Sasaki <takuya.sasaki@spacecubics.com>
- Loading branch information
Showing
7 changed files
with
125 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright (c) 2024 Space Cubics, LLC. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 */ | ||
|
||
#include "system.h" | ||
|
||
#include <systemd/sd-journal.h> | ||
#include <errno.h> | ||
#include "cspd.h" | ||
#include "version.h" | ||
|
||
/* Command size */ | ||
#define SYSTEM_CMD_MIN_SIZE (1U) | ||
|
||
/* Command ID */ | ||
#define SYSTEM_GET_VER_CMD (0U) | ||
|
||
static void send_system_err_reply(csp_packet_t *packet, uint8_t command_id, int err_code) | ||
{ | ||
struct system_err_telemetry tlm; | ||
|
||
tlm.telemetry_id = command_id; | ||
tlm.error_code = htole32(err_code); | ||
|
||
memcpy(packet->data, &tlm, sizeof(tlm)); | ||
packet->length = sizeof(tlm); | ||
|
||
csp_sendto_reply(packet, packet, CSP_O_SAME); | ||
} | ||
|
||
static void send_system_version_reply(csp_packet_t *packet, uint8_t command_id, int err_code) | ||
{ | ||
struct system_version_telemetry tlm; | ||
|
||
tlm.telemetry_id = command_id; | ||
tlm.error_code = htole32(err_code); | ||
strcpy(tlm.version, CSPD_VERSION); | ||
|
||
memcpy(packet->data, &tlm, sizeof(tlm)); | ||
packet->length = sizeof(tlm); | ||
|
||
csp_sendto_reply(packet, packet, CSP_O_SAME); | ||
} | ||
|
||
void system_handler(csp_packet_t *packet) | ||
{ | ||
int ret = 0; | ||
uint8_t command_id; | ||
|
||
if (packet == NULL) { | ||
command_id = CSP_UNKNOWN_COMMAND_ID; | ||
goto end; | ||
} | ||
|
||
if (packet->length < SYSTEM_CMD_MIN_SIZE) { | ||
sd_journal_print(LOG_ERR, "Invalide command size: %d", packet->length); | ||
ret = -EINVAL; | ||
command_id = CSP_UNKNOWN_COMMAND_ID; | ||
goto reply; | ||
} | ||
|
||
command_id = packet->data[CSP_COMMAND_ID_OFFSET]; | ||
|
||
switch (command_id) { | ||
case SYSTEM_GET_VER_CMD: | ||
send_system_version_reply(packet, command_id, 0); | ||
break; | ||
default: | ||
sd_journal_print(LOG_ERR, "Unkown command code: %d", command_id); | ||
ret = -EINVAL; | ||
command_id = CSP_UNKNOWN_COMMAND_ID; | ||
break; | ||
} | ||
|
||
reply: | ||
if (ret < 0) { | ||
send_system_err_reply(packet, command_id, ret); | ||
} | ||
|
||
end: | ||
return; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright (c) 2024 Space Cubics, LLC. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <csp/csp.h> | ||
|
||
#define SYSTEM_VERSION_STR_SIZE (16U) | ||
|
||
struct system_err_telemetry { | ||
uint8_t telemetry_id; | ||
uint32_t error_code; | ||
} __attribute__((__packed__)); | ||
|
||
struct system_version_telemetry { | ||
uint8_t telemetry_id; | ||
uint32_t error_code; | ||
char version[SYSTEM_VERSION_STR_SIZE]; | ||
} __attribute__((__packed__)); | ||
|
||
void system_handler(csp_packet_t *packet); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Copyright (c) 2024 Space Cubics, LLC. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#pragma once | ||
|
||
#define CSPD_VERSION "0.3.0" |