Skip to content

Commit 5f03f25

Browse files
canard: use 32-bit CAN-ID literals in tx encoders
1 parent 4fdd031 commit 5f03f25

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

libcanard/canard.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ bool canard_publish(canard_t* const self,
924924
(((iface_bitmap & CANARD_IFACE_BITMAP_ALL) != 0) && ((iface_bitmap & CANARD_IFACE_BITMAP_ALL) == iface_bitmap)) &&
925925
(subject_id <= CANARD_SUBJECT_ID_MAX);
926926
if (ok) {
927-
const uint32_t can_id = (((uint32_t)priority) << PRIO_SHIFT) | (subject_id << 8U) | (1UL << 7U);
927+
const uint32_t can_id = (((uint32_t)priority) << PRIO_SHIFT) | (subject_id << 8U) | (UINT32_C(1) << 7U);
928928
canard_txfer_t* const tr = txfer_new(self, deadline, transfer_id, can_id, self->tx.fd, context);
929929
ok = (tr != NULL) && tx_push(self, tr, false, iface_bitmap, payload, CRC_INITIAL);
930930
}
@@ -971,7 +971,8 @@ bool canard_1v0_publish(canard_t* const self,
971971
(((iface_bitmap & CANARD_IFACE_BITMAP_ALL) != 0) && ((iface_bitmap & CANARD_IFACE_BITMAP_ALL) == iface_bitmap)) &&
972972
(subject_id <= CANARD_SUBJECT_ID_MAX_1v0);
973973
if (ok) {
974-
const uint32_t can_id = (((uint32_t)priority) << PRIO_SHIFT) | (3UL << 21U) | (((uint32_t)subject_id) << 8U);
974+
const uint32_t can_id =
975+
(((uint32_t)priority) << PRIO_SHIFT) | (UINT32_C(3) << 21U) | (((uint32_t)subject_id) << 8U);
975976
canard_txfer_t* const tr = txfer_new(self, deadline, transfer_id, can_id, self->tx.fd, context);
976977
ok = (tr != NULL) && tx_push(self, tr, false, iface_bitmap, payload, CRC_INITIAL);
977978
}
@@ -992,8 +993,8 @@ static bool tx_1v0_service(canard_t* const self,
992993
(service_id <= CANARD_SERVICE_ID_MAX) && (destination_node_id <= CANARD_NODE_ID_MAX);
993994
if (ok) {
994995
const uint32_t can_id = (((uint32_t)priority) << PRIO_SHIFT) | //
995-
(1UL << 25U) | // service
996-
(request_not_response ? (1UL << 24U) : 0U) | (((uint32_t)service_id) << 14U) |
996+
(UINT32_C(1) << 25U) | // service
997+
(request_not_response ? (UINT32_C(1) << 24U) : 0U) | (((uint32_t)service_id) << 14U) |
997998
(((uint32_t)destination_node_id) << 7U);
998999
canard_txfer_t* const tr = txfer_new(self, deadline, transfer_id, can_id, self->tx.fd, context);
9991000
ok = (tr != NULL) && tx_push(self, tr, false, CANARD_IFACE_BITMAP_ALL, payload, CRC_INITIAL);
@@ -1040,7 +1041,8 @@ bool canard_0v1_publish(canard_t* const self,
10401041
(((iface_bitmap & CANARD_IFACE_BITMAP_ALL) != 0) && ((iface_bitmap & CANARD_IFACE_BITMAP_ALL) == iface_bitmap)) &&
10411042
(self->node_id != 0);
10421043
if (ok) {
1043-
const uint32_t can_id = (((uint32_t)priority) << PRIO_SHIFT) | (3UL << 24U) | ((uint32_t)data_type_id << 8U);
1044+
const uint32_t can_id =
1045+
(((uint32_t)priority) << PRIO_SHIFT) | (UINT32_C(3) << 24U) | ((uint32_t)data_type_id << 8U);
10441046
canard_txfer_t* const tr = txfer_new(self, deadline, transfer_id, can_id, false, context);
10451047
ok = (tr != NULL) && tx_push(self, tr, true, iface_bitmap, payload, crc_seed);
10461048
}
@@ -1061,9 +1063,9 @@ static bool tx_0v1_service(canard_t* const self,
10611063
bool ok = (self != NULL) && (priority < CANARD_PRIO_COUNT) && bytes_chain_valid(payload) && (self->node_id != 0U) &&
10621064
(destination_node_id > 0U) && (destination_node_id <= CANARD_NODE_ID_MAX);
10631065
if (ok) {
1064-
const uint32_t can_id = (((((uint32_t)priority) << 2U) | 3UL) << 24U) | //
1065-
(((uint32_t)data_type_id) << 16U) | (request_not_response ? (1UL << 15U) : 0U) |
1066-
(((uint32_t)destination_node_id) << 8U) | (1UL << 7U); // service
1066+
const uint32_t can_id = (((((uint32_t)priority) << 2U) | UINT32_C(3)) << 24U) | //
1067+
(((uint32_t)data_type_id) << 16U) | (request_not_response ? (UINT32_C(1) << 15U) : 0U) |
1068+
(((uint32_t)destination_node_id) << 8U) | (UINT32_C(1) << 7U); // service
10671069
canard_txfer_t* const tr = txfer_new(self, deadline, transfer_id, can_id, false, context);
10681070
ok = (tr != NULL) && tx_push(self, tr, true, CANARD_IFACE_BITMAP_ALL, payload, crc_seed);
10691071
}

0 commit comments

Comments
 (0)