-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use nnvg generated logic for serialisation/deserialisation for Version
- Loading branch information
Showing
4 changed files
with
141 additions
and
40 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// UAVCAN data structure definition. +-+ +-+ | ||
// | | | | | ||
// AUTOGENERATED, DO NOT EDIT. \ - / | ||
// --- | ||
// o | ||
// +------------------------------------------------------------------------------------------------------------------+ | ||
// | ||
// Generator: | ||
// nunavut-0.3.9 (serialization was enabled) | ||
// | ||
// | ||
// Source File: | ||
// /home/alex/projects/107-systems/public_regulated_data_types/uavcan/node/Version.1.0.uavcan | ||
// | ||
// Template: | ||
// StructureType.j2 | ||
// | ||
// Generated at: 2020-09-15 13:51:28.069217 UTC | ||
// Is deprecated: no | ||
// Fixed port ID: None | ||
// Full name: uavcan.node.Version | ||
// Version: 1.0 | ||
|
||
#ifndef UAVCAN_NODE_VERSION_1_0_INCLUDED | ||
#define UAVCAN_NODE_VERSION_1_0_INCLUDED | ||
|
||
#include <nunavut/support/serialization.h> | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif /* __cplusplus */ | ||
|
||
|
||
typedef struct | ||
{ | ||
uint8_t major; | ||
uint8_t minor; | ||
} uavcan_node_Version_1_0; | ||
|
||
/// Initialize an uavcan_node_Version_1_0 instance to default values. | ||
/// No memory is allocated within this method. | ||
/// Does nothing if @ref out_instance is NULL. | ||
/// | ||
/// @param out_instance A structure instance to Initialize. | ||
static inline void uavcan_node_Version_1_0_init(uavcan_node_Version_1_0* const out_instance) | ||
{ | ||
if (out_instance != NULL) | ||
{ | ||
out_instance->major = 0; | ||
out_instance->minor = 0; | ||
} | ||
} | ||
|
||
/// Contains the maximum number of bytes needed to serialize a(n) uavcan_node_Version_1_0 | ||
/// instance. | ||
#define uavcan_node_Version_1_0_MAX_SERIALIZED_REPRESENTATION_SIZE_BYTES \ | ||
(2U) | ||
|
||
|
||
/// Serialization of uavcan_node_Version_1_0 instance into a byte array. | ||
/// | ||
/// @param in_instance A structure instance to serialize. | ||
/// @param offset Offset (in bits) of data type in message. | ||
/// @param out_buffer Output message buffer. | ||
/// | ||
/// @returns Size of encoded data (in bits) | ||
static inline int32_t uavcan_node_Version_1_0_serialize(const uavcan_node_Version_1_0* in_instance, uint32_t offset, uint8_t* const out_buffer) | ||
{ | ||
|
||
if (out_buffer == NULL) | ||
{ | ||
return -NUNAVUT_ERR_INVALID_BUF; | ||
} | ||
|
||
// Begin Structure: saturated uint8 | ||
nunavutSetUxx(out_buffer, offset, in_instance->major, 8); | ||
offset += 8; | ||
// End Structure: saturated uint8 | ||
// Begin Structure: saturated uint8 | ||
nunavutSetUxx(out_buffer, offset, in_instance->minor, 8); | ||
offset += 8; | ||
// End Structure: saturated uint8 | ||
|
||
return offset; | ||
} | ||
|
||
/// Deserialization of byte-array encoding into uavcan_node_Version_1_0 instance. | ||
/// | ||
/// @param out_instance Structure instance to write data to. | ||
/// @param offset Bit offset of structure in data buffer. | ||
/// @param in_buffer Message buffer to deserialize. | ||
/// @param buf_size_bytes Length of input buffer (in bytes) to avoid overflow. | ||
/// | ||
/// @returns Size of decoded data (in bits) | ||
static inline int32_t uavcan_node_Version_1_0_deserialize(uavcan_node_Version_1_0* const out_instance, uint32_t offset, uint8_t* const in_buffer, const size_t buf_size_bytes) | ||
{ | ||
|
||
if (in_buffer == NULL) | ||
{ | ||
return -NUNAVUT_ERR_INVALID_BUF; | ||
} | ||
|
||
// Begin Structure: saturated uint8 | ||
out_instance->major = nunavutGetU8(in_buffer, buf_size_bytes, offset, 8); | ||
offset += 8; | ||
// End Structure: saturated uint8 | ||
// Begin Structure: saturated uint8 | ||
out_instance->minor = nunavutGetU8(in_buffer, buf_size_bytes, offset, 8); | ||
offset += 8; | ||
// End Structure: saturated uint8 | ||
|
||
return offset; | ||
} | ||
|
||
|
||
#ifdef __cplusplus | ||
} /* End extern "C" */ | ||
#endif /* __cplusplus */ | ||
#endif /* UAVCAN_NODE_VERSION_1_0_INCLUDED */ |