Skip to content

Commit 910c3ae

Browse files
committed
fix according to review
1 parent 806a386 commit 910c3ae

File tree

4 files changed

+23
-39
lines changed

4 files changed

+23
-39
lines changed

.github/workflows/main.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ jobs:
9696
sudo apt-get update -y && sudo apt-get upgrade -y
9797
sudo apt-get install gcc-avr avr-libc
9898
avr-gcc --version
99-
- run: avr-gcc libcanard/*.c -isystem libcanard -c -std=c99 -mmcu=${{ env.mcu }} ${{ env.flags }}
100-
- run: avr-gcc libcanard/*.c -isystem libcanard -c -std=c11 -mmcu=${{ env.mcu }} ${{ env.flags }}
101-
- run: avr-gcc libcanard/*.c -isystem libcanard -c -std=gnu99 -mmcu=${{ env.mcu }} ${{ env.flags }}
102-
- run: avr-gcc libcanard/*.c -isystem libcanard -c -std=gnu11 -mmcu=${{ env.mcu }} ${{ env.flags }}
99+
- run: avr-gcc libcanard/*.c -isystem lib -c -std=c99 -mmcu=${{ env.mcu }} ${{ env.flags }}
100+
- run: avr-gcc libcanard/*.c -isystem lib -c -std=c11 -mmcu=${{ env.mcu }} ${{ env.flags }}
101+
- run: avr-gcc libcanard/*.c -isystem lib -c -std=gnu99 -mmcu=${{ env.mcu }} ${{ env.flags }}
102+
- run: avr-gcc libcanard/*.c -isystem lib -c -std=gnu11 -mmcu=${{ env.mcu }} ${{ env.flags }}
103103

104104
arm:
105105
if: github.event_name == 'push'
@@ -111,8 +111,8 @@ jobs:
111111
- run: |
112112
sudo apt-get update -y && sudo apt-get upgrade -y
113113
sudo apt-get install -y gcc-arm-none-eabi
114-
- run: arm-none-eabi-gcc libcanard/*.c -isystem libcanard -c -std=c99 ${{ env.flags }}
115-
- run: arm-none-eabi-gcc libcanard/*.c -isystem libcanard -c -std=c11 ${{ env.flags }}
114+
- run: arm-none-eabi-gcc libcanard/*.c -isystem lib -c -std=c99 ${{ env.flags }}
115+
- run: arm-none-eabi-gcc libcanard/*.c -isystem lib -c -std=c11 ${{ env.flags }}
116116

117117
style_check:
118118
if: github.event_name == 'push'
@@ -195,7 +195,7 @@ jobs:
195195
--define sonar.projectName=libcanard
196196
--define sonar.projectKey=libcanard
197197
--define sonar.sources=libcanard
198-
--define sonar.exclusions=libcanard/cavl2.h
198+
--define sonar.exclusions=lib/cavl2/cavl2.h
199199
--define sonar.cfamily.gcov.reportsPath=.
200200
--define sonar.cfamily.compile-commands="${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json"
201201
--define sonar.host.url="${{ env.SONAR_SERVER_URL }}"

esp_metadata/package_esp_component.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ cp LICENSE package/libcanard/LICENSE
1111
cp README.md package/libcanard/README.md
1212

1313
cp libcanard/canard.c package/libcanard/canard.c
14-
cp libcanard/cavl2.h package/libcanard/calv2.h
1514
cp libcanard/canard.h package/libcanard/include/canard.h
1615

1716
cp esp_metadata/CMakeLists.txt package/libcanard/CMakeLists.txt
File renamed without changes.

libcanard/canard.c

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
// --------------------------------------------- INTERNAL INCLUDES ----------------------------------------------
4242
// The internal includes are placed here after the config header is included and CANARD_ASSERT is defined.
4343
#define CAVL2_T struct CanardTreeNode
44-
#include <cavl2.h>
44+
#define CAVL2_ASSERT(x) CANARD_ASSERT(x)
45+
#include <../lib/cavl2/cavl2.h>
4546

4647
// --------------------------------------------- COMMON DEFINITIONS ---------------------------------------------
4748

@@ -76,12 +77,6 @@
7677
#define MUTABLE_CONTAINER_OF(type, ptr, member) \
7778
((type*) (((ptr) == NULL) ? NULL : (void*) (((char*) (ptr)) - offsetof(type, member))))
7879

79-
/// Used for inserting new items into AVL trees.
80-
CANARD_PRIVATE struct CanardTreeNode* avlTrivialFactory(void* const user_reference)
81-
{
82-
return (struct CanardTreeNode*) user_reference;
83-
}
84-
8580
// --------------------------------------------- TRANSFER CRC ---------------------------------------------
8681

8782
typedef uint16_t TransferCRC;
@@ -340,8 +335,8 @@ CANARD_PRIVATE struct CanardTxQueueItem* txAllocateQueueItem(struct CanardTxQueu
340335
/// Frames with identical CAN ID that are added later always compare greater than their counterparts with same CAN ID.
341336
/// This ensures that CAN frames with the same CAN ID are transmitted in the FIFO order.
342337
/// Frames that should be transmitted earlier compare smaller (i.e., put on the left side of the tree).
343-
CANARD_PRIVATE ptrdiff_t txAVLPriorityPredicate( //
344-
const void* user_reference, // NOSONAR Cavl API requires pointer to non-const.
338+
CANARD_PRIVATE ptrdiff_t txAVLPriorityPredicate( //
339+
const void* const user_reference,
345340
const struct CanardTreeNode* const node)
346341
{
347342
typedef struct CanardTxQueueItem TxItem;
@@ -405,7 +400,7 @@ CANARD_PRIVATE int32_t txPushSingleFrame(struct CanardTxQueue* const que,
405400
&tqi->priority_base,
406401
&txAVLPriorityPredicate,
407402
&tqi->priority_base,
408-
&avlTrivialFactory);
403+
&cavl2_trivial_factory);
409404
(void) priority_queue_res;
410405
CANARD_ASSERT(priority_queue_res == &tqi->priority_base);
411406

@@ -414,7 +409,7 @@ CANARD_PRIVATE int32_t txPushSingleFrame(struct CanardTxQueue* const que,
414409
&tqi->deadline_base,
415410
&txAVLDeadlinePredicate,
416411
&tqi->deadline_base,
417-
&avlTrivialFactory);
412+
&cavl2_trivial_factory);
418413
(void) deadline_queue_res;
419414
CANARD_ASSERT(deadline_queue_res == &tqi->deadline_base);
420415

@@ -562,7 +557,7 @@ CANARD_PRIVATE int32_t txPushMultiFrame(struct CanardTxQueue* const que,
562557
&next->priority_base,
563558
&txAVLPriorityPredicate,
564559
&next->priority_base,
565-
&avlTrivialFactory);
560+
&cavl2_trivial_factory);
566561
(void) priority_queue_res;
567562
CANARD_ASSERT(priority_queue_res == &next->priority_base);
568563
CANARD_ASSERT(que->priority_root != NULL);
@@ -571,7 +566,7 @@ CANARD_PRIVATE int32_t txPushMultiFrame(struct CanardTxQueue* const que,
571566
&next->deadline_base,
572567
&txAVLDeadlinePredicate,
573568
&next->deadline_base,
574-
&avlTrivialFactory);
569+
&cavl2_trivial_factory);
575570
(void) deadline_queue_res;
576571
CANARD_ASSERT(deadline_queue_res == &next->deadline_base);
577572
CANARD_ASSERT(que->deadline_root != NULL);
@@ -1353,12 +1348,9 @@ int8_t canardRxAccept(struct CanardInstance* const ins,
13531348
// This is the reason the function has a logarithmic time complexity of the number of subscriptions.
13541349
// Note also that this one of the two variable-complexity operations in the RX pipeline; the other one
13551350
// is memcpy(). Excepting these two cases, the entire RX pipeline contains neither loops nor recursion.
1356-
struct CanardTreeNode* const sub_node =
1357-
cavl2_find_or_insert(&ins->rx_subscriptions[(size_t) model.transfer_kind],
1358-
&model.port_id,
1359-
&rxSubscriptionPredicateOnPortID,
1360-
ins,
1361-
NULL);
1351+
struct CanardTreeNode* const sub_node = cavl2_find(ins->rx_subscriptions[(size_t) model.transfer_kind],
1352+
&model.port_id,
1353+
&rxSubscriptionPredicateOnPortID);
13621354
struct CanardRxSubscription* const sub =
13631355
MUTABLE_CONTAINER_OF(struct CanardRxSubscription, sub_node, base);
13641356
if (out_subscription != NULL)
@@ -1420,7 +1412,7 @@ int8_t canardRxSubscribe(struct CanardInstance* const ins,
14201412
&out_subscription->base,
14211413
&rxSubscriptionPredicateOnStruct,
14221414
out_subscription,
1423-
&avlTrivialFactory);
1415+
&cavl2_trivial_factory);
14241416
(void) res;
14251417
CANARD_ASSERT(res == &out_subscription->base);
14261418
out = (out > 0) ? 0 : 1;
@@ -1439,12 +1431,8 @@ int8_t canardRxUnsubscribe(struct CanardInstance* const ins,
14391431
{
14401432
CanardPortID port_id_mutable = port_id;
14411433

1442-
struct CanardTreeNode* const sub_node = cavl2_find_or_insert( //
1443-
&ins->rx_subscriptions[tk],
1444-
&port_id_mutable,
1445-
&rxSubscriptionPredicateOnPortID,
1446-
NULL,
1447-
NULL);
1434+
struct CanardTreeNode* const sub_node =
1435+
cavl2_find(ins->rx_subscriptions[tk], &port_id_mutable, &rxSubscriptionPredicateOnPortID);
14481436
if (sub_node != NULL)
14491437
{
14501438
struct CanardRxSubscription* const sub = MUTABLE_CONTAINER_OF(struct CanardRxSubscription, sub_node, base);
@@ -1483,11 +1471,8 @@ int8_t canardRxGetSubscription(struct CanardInstance* const ins,
14831471
{
14841472
CanardPortID port_id_mutable = port_id;
14851473

1486-
struct CanardTreeNode* const sub_node = cavl2_find_or_insert(&ins->rx_subscriptions[tk],
1487-
&port_id_mutable,
1488-
&rxSubscriptionPredicateOnPortID,
1489-
NULL,
1490-
NULL);
1474+
struct CanardTreeNode* const sub_node =
1475+
cavl2_find(ins->rx_subscriptions[tk], &port_id_mutable, &rxSubscriptionPredicateOnPortID);
14911476
if (sub_node != NULL)
14921477
{
14931478
struct CanardRxSubscription* const sub = MUTABLE_CONTAINER_OF(struct CanardRxSubscription, sub_node, base);

0 commit comments

Comments
 (0)