Skip to content

Commit 2002413

Browse files
tpwrulestridge
authored andcommitted
introduce skeleton for table coding system
If the message structure is compatible, the DSDL compiler generates a table which describes its structure. If enabled, an interpreter is then used to follow the table description and encode or decode the message. This occupies substantially fewer bytes per message as the table is much smaller than the C function previously used. This translates to a large reduction in program memory usage, especially if many different message types need to be coded. This commit sets up all the hooks to enable and disable the system and defines the interpreter functions. However, they don't do anything as the system currently doesn't support any types.
1 parent 66760b3 commit 2002413

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

canard.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,39 @@ void canardEncodeScalar(void* destination,
994994
copyBitArray(&storage.bytes[0], 0, bit_length, (uint8_t*) destination, bit_offset);
995995
}
996996

997+
#if CANARD_ENABLE_TABLE_DECODING
998+
bool canardTableDecodeMessage(const CanardCodingTable* table,
999+
const CanardRxTransfer* transfer,
1000+
void* msg)
1001+
{
1002+
(void)table;
1003+
(void)transfer;
1004+
(void)msg;
1005+
1006+
return true;
1007+
}
1008+
#endif
1009+
1010+
#if CANARD_ENABLE_TABLE_ENCODING
1011+
uint32_t canardTableEncodeMessage(const CanardCodingTable* table,
1012+
uint8_t* buffer,
1013+
const void* msg
1014+
#if CANARD_ENABLE_TAO_OPTION
1015+
, bool tao
1016+
#endif
1017+
)
1018+
{
1019+
(void)table;
1020+
(void)buffer;
1021+
(void)msg;
1022+
#if CANARD_ENABLE_TAO_OPTION
1023+
(void)tao;
1024+
#endif
1025+
1026+
return 0;
1027+
}
1028+
#endif
1029+
9971030
void canardReleaseRxTransferPayload(CanardInstance* ins, CanardRxTransfer* transfer)
9981031
{
9991032
while (transfer->payload_middle != NULL)

canard.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@ extern "C" {
6666
#endif
6767
#endif
6868

69+
#ifndef CANARD_ENABLE_TABLE_CODING
70+
#define CANARD_ENABLE_TABLE_CODING 1
71+
#endif
72+
73+
#ifndef CANARD_ENABLE_TABLE_ENCODING
74+
#define CANARD_ENABLE_TABLE_ENCODING CANARD_ENABLE_TABLE_CODING
75+
#endif
76+
77+
#ifndef CANARD_ENABLE_TABLE_DECODING
78+
#define CANARD_ENABLE_TABLE_DECODING CANARD_ENABLE_TABLE_CODING
79+
#endif
80+
6981
/// By default this macro resolves to the standard assert(). The user can redefine this if necessary.
7082
#ifndef CANARD_ASSERT
7183
#ifdef CANARD_ENABLE_ASSERTS
@@ -451,6 +463,24 @@ struct CanardRxTransfer
451463
#endif
452464
};
453465

466+
#if CANARD_ENABLE_TABLE_DECODING || CANARD_ENABLE_TABLE_ENCODING
467+
/**
468+
* This structure describes the encoded form of part of a particular message. It
469+
* can be contained in ROM. It should be generated using dronecan_dsdlc.
470+
*/
471+
typedef struct {
472+
} CanardCodingTableEntry;
473+
474+
/**
475+
* This structure describes the encoded form of a particular message. It can be
476+
* contained in ROM. It should be generated using dronecan_dsdlc.
477+
*/
478+
typedef struct {
479+
size_t entries_max;
480+
CanardCodingTableEntry entries[];
481+
} CanardCodingTable;
482+
#endif
483+
454484
/**
455485
* Initializes a library instance.
456486
* Local node ID will be set to zero, i.e. the node will be anonymous.
@@ -682,6 +712,35 @@ void canardEncodeScalar(void* destination, ///< Destination buffer where th
682712
uint8_t bit_length, ///< Length of the value, in bits; see the table
683713
const void* value); ///< Pointer to the value; see the table
684714

715+
#if CANARD_ENABLE_TABLE_DECODING
716+
/**
717+
* This function can be used to extract a message structure from a transfer
718+
* using a coding table that describes the message layout.
719+
*
720+
* Returns true if there was an error during the decoding.
721+
*/
722+
bool canardTableDecodeMessage(const CanardCodingTable* table, ///< Table describing message layout
723+
const CanardRxTransfer* transfer, ///< Transfer containing the message data
724+
void* msg); ///< Pointer to the destination message structure
725+
#endif
726+
727+
#if CANARD_ENABLE_TABLE_ENCODING
728+
/**
729+
* This function can be used to encode a message structure into a buffer using a
730+
* coding table that describes the message layout. For a message type named
731+
* msg.type, the buffer must be at least MSG_TYPE_MAX_SIZE bytes.
732+
*
733+
* Returns the actual number of bytes stored into the buffer.
734+
*/
735+
uint32_t canardTableEncodeMessage(const CanardCodingTable* table, ///< Table describing message layout
736+
uint8_t* buffer, ///< Pointer to the destination buffer
737+
const void* msg ///< Pointer to message structure to be encoded
738+
#if CANARD_ENABLE_TAO_OPTION
739+
, bool tao ///< True if encoding should use tail array optimization (TAO)
740+
#endif
741+
);
742+
#endif
743+
685744
/**
686745
* This function can be invoked by the application to release pool blocks that are used
687746
* to store the payload of the transfer.

0 commit comments

Comments
 (0)