Self Id
include/rid/self_id.h
Self ID message handling per ASTM F3411-22a.
Example usage:
rid_self_id_t self_id;
rid_self_id_init(&self_id);
rid_self_id_set_description_type(&self_id, RID_DESCRIPTION_TYPE_TEXT);
rid_self_id_set_description(&self_id, "Drone delivery test");
hexdump(&self_id, sizeof(self_id));
char description[RID_DESCRIPTION_SIZE + 1];
rid_self_id_get_description(&self_id, description, sizeof(description));
rid_description_type_t desc_type = rid_self_id_get_description_type(&self_id);
printf("Description: %s\n", description);
printf("Type: %d\n", desc_type);
Structures and Types
| Type | Name |
|---|---|
| enum | rid_description_type_t Description type classification per ASTM F3411-22a. |
| struct | rid_self_id_t Self ID message structure per ASTM F3411-22a. |
Functions
| Type | Name |
|---|---|
| const char * | rid_description_type_to_string (rid_description_type_t type) Convert description type to string representation. |
| int | rid_self_id_get_description (const rid_self_id_t *message, char *buffer, size_t buffer_size) Get the description from a Self ID message. |
| rid_description_type_t | rid_self_id_get_description_type (const rid_self_id_t *message) Get the description type from a Self ID message. |
| int | rid_self_id_init (rid_self_id_t *message) Initialize a Self ID message with default values. |
| int | rid_self_id_set_description (rid_self_id_t *message, const char *description) Set the description for a Self ID message. |
| int | rid_self_id_set_description_type (rid_self_id_t *message, rid_description_type_t type) Set the description type for a Self ID message. |
| int | rid_self_id_to_json (const rid_self_id_t *message, char *buffer, size_t buffer_size, size_t *needed_size) Format a Self ID message as a JSON string. |
| int | rid_self_id_validate (const rid_self_id_t *message) Validate a Self ID message structure. |
Macros
| Type | Name |
|---|---|
| define | RID_DESCRIPTION_SIZE 23 Self ID description field size in bytes per ASTM F3411-22a. |
Structures and Types Documentation
enum rid_description_type_t
Description type classification per ASTM F3411-22a.
enum rid_description_type_t {
RID_DESCRIPTION_TYPE_TEXT = 0,
RID_DESCRIPTION_TYPE_EMERGENCY = 1,
RID_DESCRIPTION_TYPE_EXTENDED_STATUS = 2,
RID_DESCRIPTION_TYPE_MAX = 255
};
struct rid_self_id_t
Self ID message structure per ASTM F3411-22a.
Variables:
-
char description
-
uint8_t description_type
-
uint8_t message_type
-
uint8_t protocol_version
Functions Documentation
function rid_description_type_to_string
Convert description type to string representation.
const char * rid_description_type_to_string (
rid_description_type_t type
)
Parameters:
typeThe description type to convert.
Returns:
String representation of the description type. Returns "UNKNOWN" for invalid values.
function rid_self_id_get_description
Get the description from a Self ID message.
int rid_self_id_get_description (
const rid_self_id_t *message,
char *buffer,
size_t buffer_size
)
Copies the description to the provided buffer as a null-terminated string.
Parameters:
messagePointer to the Self ID message structure.bufferBuffer to store the description.buffer_sizeSize of the buffer (must be at least RID_DESCRIPTION_SIZE + 1).
Return value:
RID_SUCCESSon success.RID_ERROR_NULL_POINTERif message or buffer is NULL.RID_ERROR_BUFFER_TOO_SMALLif buffer_size is insufficient.
function rid_self_id_get_description_type
Get the description type from a Self ID message.
rid_description_type_t rid_self_id_get_description_type (
const rid_self_id_t *message
)
Parameters:
messagePointer to the Self ID message structure.
Returns:
The description type or RID_DESCRIPTION_TYPE_TEXT if message is NULL.
function rid_self_id_init
Initialize a Self ID message with default values.
int rid_self_id_init (
rid_self_id_t *message
)
Sets protocol version to 2 and message type to SELF_ID. All other fields are set to zero.
Parameters:
messagePointer to the Self ID message structure.
Return value:
RID_SUCCESSon success.RID_ERROR_NULL_POINTERif message is NULL.
function rid_self_id_set_description
Set the description for a Self ID message.
int rid_self_id_set_description (
rid_self_id_t *message,
const char *description
)
The description is a null-terminated string up to RID_DESCRIPTION_SIZE characters.
Parameters:
messagePointer to the Self ID message structure.descriptionThe description string to set.
Return value:
RID_SUCCESSon success.RID_ERROR_NULL_POINTERif message or description is NULL.RID_ERROR_BUFFER_TOO_LARGEif description exceeds RID_DESCRIPTION_SIZE characters.RID_ERROR_INVALID_CHARACTERif description contains non-ASCII or control characters.
function rid_self_id_set_description_type
Set the description type for a Self ID message.
int rid_self_id_set_description_type (
rid_self_id_t *message,
rid_description_type_t type
)
Parameters:
messagePointer to the Self ID message structure.typeThe description type to set.
Return value:
RID_SUCCESSon success.RID_ERROR_NULL_POINTERif message is NULL.RID_ERROR_OUT_OF_RANGEif type exceeds RID_DESCRIPTION_TYPE_MAX.
function rid_self_id_to_json
Format a Self ID message as a JSON string.
int rid_self_id_to_json (
const rid_self_id_t *message,
char *buffer,
size_t buffer_size,
size_t *needed_size
)
Parameters:
messagePointer to the Self ID message structure.bufferBuffer to store the JSON string or NULL.buffer_sizeSize of the buffer.needed_sizeIf non-NULL receives the required buffer size.
Return value:
RID_SUCCESSon success.RID_ERROR_NULL_POINTERifmessageis NULL or if bothbufferandneeded_sizeare NULL.RID_ERROR_BUFFER_TOO_SMALLifbufferis too small.
function rid_self_id_validate
Validate a Self ID message structure.
int rid_self_id_validate (
const rid_self_id_t *message
)
Checks that all fields contain valid encoded values according to ASTM F3411-22a.
Parameters:
messagePointer to the Self ID message structure to validate.
Return value:
RID_SUCCESSif all fields are valid.RID_ERROR_NULL_POINTERif message is NULL.RID_ERROR_INVALID_PROTOCOL_VERSIONif protocol version is invalid.RID_ERROR_UNKNOWN_MESSAGE_TYPEif message type is not SELF_ID.RID_ERROR_INVALID_CHARACTERif description contains non-ASCII or control characters.
Macros Documentation
define RID_DESCRIPTION_SIZE
Self ID description field size in bytes per ASTM F3411-22a.
#define RID_DESCRIPTION_SIZE 23