Skip to content

Commit

Permalink
More review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aasmune committed Mar 27, 2019
1 parent f780ae0 commit 368c1cf
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
7 changes: 1 addition & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,7 @@
# CMake build directory
build/
cmake-build-*/
CMakeFiles/
cmake_install.cmake
CMakeCache.txt
Makefile
demo
run_tests
build-avr/

# IDE and tools
.idea
Expand Down
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ matrix:
- gcc-7-multilib
- linux-libc-dev:i386
script:
- CC=gcc-7 && CXX=g++-7 && cd tests/ && cmake . && make
- mkdir tests/build/ cd tests/build/
- CC=gcc-7 && CXX=g++-7 && cmake .. && make
- ./run_tests --rng-seed time

#
Expand All @@ -37,9 +38,9 @@ matrix:
- linux-libc-dev:i386
- libc6-dev-i386
script:
- mkdir tests/build/ cd tests/build/
- clang++-5.0 -E -x c++ - -v < /dev/null # Print the Clang configuration for troubleshooting purposes
- cd tests/
- cmake -DCMAKE_C_COMPILER=clang-5.0 -DCMAKE_CXX_COMPILER=clang++-5.0 .
- cmake -DCMAKE_C_COMPILER=clang-5.0 -DCMAKE_CXX_COMPILER=clang++-5.0 ..
- make
- ./run_tests --rng-seed time

Expand Down
2 changes: 1 addition & 1 deletion DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Few things to note:
Value of the field dtid_tt_snid_dnid can be computed with the following helper macro:

```c
#define CANARD_MAKE_TRANSFER_DESCRIPTOR(data_type_id, transfer_type, \
#define CANARD_MAKE_SESSION_SPECIFIER(data_type_id, transfer_type, \
src_node_id, dst_node_id) \
((data_type_id) | ((transfer_type) << 16) | \
((src_node_id) << 18) | ((dst_node_id) << 25))
Expand Down
10 changes: 6 additions & 4 deletions canard.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
#define SERVICE_NOT_MSG_FROM_ID(x) ((bool) (((x) >> 25U) & 0x1U))
#define REQUEST_NOT_RESPONSE_FROM_ID(x) ((bool) (((x) >> 24U) & 0x1U))
#define DEST_ID_FROM_ID(x) ((uint8_t) (((x) >> 8U) & 0x7FU))
#define PRIORITY_FROM_ID(x) ((uint8_t) (((x) >> 26U) & 0x1FU))
#define PRIORITY_FROM_ID(x) ((uint8_t) (((x) >> 26U) & 0x7U))
#define SUBJECT_TYPE_FROM_ID(x) ((uint16_t)(((x) >> 8U) & 0x7FFFU))
#define SRV_TYPE_FROM_ID(x) ((uint8_t) (((x) >> 15U) & 0x1FFU))

#define MAKE_TRANSFER_DESCRIPTOR(port_id, transfer_type, src_node_id, dst_node_id) \
#define MAKE_SESSION_SPECIFIER(port_id, transfer_type, src_node_id, dst_node_id) \
(((uint32_t)(port_id)) | (((uint32_t)(transfer_type)) << 16U) | \
(((uint32_t)(src_node_id)) << 18U) | (((uint32_t)(dst_node_id)) << 25U))

Expand Down Expand Up @@ -151,7 +151,7 @@ int16_t canardBroadcast(CanardInstance* ins,
uint32_t can_id = 0;
uint16_t crc = 0xFFFFU;

can_id = ((uint32_t) priority << 26U) | ((uint32_t) data_type_id << 8U) | ((uint32_t) canardGetLocalNodeID(ins) << 1U);
can_id = ((uint32_t) priority << 26U) | ((uint32_t) data_type_id << 8U);

if (canardGetLocalNodeID(ins) == CANARD_BROADCAST_NODE_ID) // Anonymous message transfer
{
Expand All @@ -170,6 +170,8 @@ int16_t canardBroadcast(CanardInstance* ins,
crc = crcAddSignature(crc, data_type_signature);
crc = crcAdd(crc, payload, payload_len);
}

can_id |= ((uint32_t) (canardGetLocalNodeID(ins) & 0x7FU) << 1U);
}

const int16_t result = enqueueTxFrames(ins, can_id, inout_transfer_id, crc, payload, payload_len);
Expand Down Expand Up @@ -267,7 +269,7 @@ int16_t canardHandleRxFrame(CanardInstance* ins, const CanardCANFrame* frame, ui
const uint8_t source_node_id = SOURCE_ID_FROM_ID(frame->id);
const uint16_t data_type_id = extractDataType(frame->id);
const uint32_t transfer_descriptor =
MAKE_TRANSFER_DESCRIPTOR(data_type_id, transfer_type, source_node_id, destination_node_id);
MAKE_SESSION_SPECIFIER(data_type_id, transfer_type, source_node_id, destination_node_id);

const uint8_t tail_byte = frame->data[frame->data_len - 1];

Expand Down
6 changes: 3 additions & 3 deletions canard.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,14 +347,14 @@ void* canardGetUserReference(CanardInstance* ins);
* Assigns a new node ID value to the current node.
* Node ID can be assigned only once.
*
* Returns CANARD_OK if success, or negative error code if node ID is outside valid range.
* Returns CANARD_OK if success, or negative error code if node ID is outside valid range or already configured.
*/
int16_t canardSetLocalNodeID(CanardInstance* ins,
uint8_t self_node_id);
uint8_t self_node_id);

/**
* Returns node ID of the local node.
* Returns zero (broadcast) if the node ID is not set, i.e. if the local node is anonymous.
* Returns 255 (broadcast) if the node ID is not set, i.e. if the local node is anonymous.
*/
uint8_t canardGetLocalNodeID(const CanardInstance* ins);

Expand Down

0 comments on commit 368c1cf

Please sign in to comment.