Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions include/thingset++/ThingSetGroup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ class ThingSetGroup : public IdentifiableThingSetParentNode<Id, ParentId, Name>,
std::function<bool(ThingSetNode *, ThingSetCallbackReason)> _callback;

public:
ThingSetGroup() : ThingSetGroup(defaultCallback){};
ThingSetGroup() : ThingSetGroup(defaultCallback)
{}
ThingSetGroup(std::function<bool(ThingSetNode *, ThingSetCallbackReason)> callback)
: IdentifiableThingSetParentNode<Id, ParentId, Name>(), _callback(callback){};
: IdentifiableThingSetParentNode<Id, ParentId, Name>(), _callback(callback)
{}

constexpr const std::string getType() const override
{
Expand Down
8 changes: 4 additions & 4 deletions include/thingset++/ThingSetRecordMember.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,13 +414,13 @@ class ThingSetRecordMember<Id, ParentId, Name, Access, std::array<Element, Size>
return Access;
}

bool findByName(const std::string &name, ThingSetNode **node, size_t *index) override
bool findByName(const std::string &childName, ThingSetNode **node, size_t *index) override
{
bool foundChild = ThingSetParentNode::findByName(name, node, index);
bool foundChild = ThingSetParentNode::findByName(childName, node, index);
// atoi is useless - it returns 0 on failure - so we check that the string actually
// contains a number before trying to parse it
if (name.c_str()[0] >= '0' && name.c_str()[0] <= '9') {
*index = std::atoi(name.c_str());
if (childName.c_str()[0] >= '0' && childName.c_str()[0] <= '9') {
*index = std::atoi(childName.c_str());
return true;
}

Expand Down
7 changes: 4 additions & 3 deletions include/thingset++/ThingSetServer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,12 @@ class ThingSetServer : public _ThingSetServer
ThingSetServerTransport<Identifier, Size, Encoder> &_transport;

public:
ThingSetServer(ThingSetServerTransport<Identifier, Size, Encoder> &transport) : ThingSetServer(transport, nullptr)
ThingSetServer(ThingSetServerTransport<Identifier, Size, Encoder> &serverTransport)
: ThingSetServer(serverTransport, nullptr)
{}

ThingSetServer(ThingSetServerTransport<Identifier, Size, Encoder> &transport, ThingSetForwarder *forwarder)
: _ThingSetServer(forwarder), _transport(transport)
ThingSetServer(ThingSetServerTransport<Identifier, Size, Encoder> &serverTransport, ThingSetForwarder *forwarder)
: _ThingSetServer(forwarder), _transport(serverTransport)
{}

bool listen() override
Expand Down
2 changes: 1 addition & 1 deletion include/thingset++/ThingSetValue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class ThingSetValue : public ThingSetEncodable,
template <class U, typename std::enable_if<std::is_convertible_v<U, T>, bool>::type = true>
auto &operator=(const U &value)
{
_value = value;
_value = static_cast<T>(value);
return *this;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ class ThingSetZephyrCanClientTransport : public ThingSetCanClientTransport
ThingSetZephyrCanClientTransport(ThingSetZephyrCanClientTransport &&) = delete;
ThingSetZephyrCanClientTransport(const ThingSetZephyrCanClientTransport &) = delete;
template <size_t RxSize, size_t TxSize>
ThingSetZephyrCanClientTransport(ThingSetZephyrCanInterface &canInterface, uint8_t targetNodeAddress,
std::array<uint8_t, RxSize> &rxBuffer, std::array<uint8_t, TxSize> &txBuffer) : ThingSetCanClientTransport(targetNodeAddress),
_requestResponseContext(canInterface, rxBuffer, txBuffer)
ThingSetZephyrCanClientTransport(ThingSetZephyrCanInterface &zephyrCanInterface, uint8_t targetNodeAddress,
std::array<uint8_t, RxSize> &rxStorage, std::array<uint8_t, TxSize> &txStorage)
: ThingSetCanClientTransport(targetNodeAddress),
_requestResponseContext(zephyrCanInterface, rxStorage, txStorage)
{
k_msgq_init(&_responseQueue, _responseQueueBuffer.data(), sizeof(ResponseMessage), 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class _ThingSetZephyrCanInterface : public ThingSetCanInterface
_ThingSetZephyrCanInterface(const device *const canDevice);

public:
const device *const getDevice();
const device *getDevice();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for this? The field is still const device *const.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was flagged by -Wextra because the function is returning a copy of the pointer and so the extra constraint doesn't actually do anything - i.e., the user could do whatever they like with their own copy. But aye, the field itself is still indeed constraint properly

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see. Fair enough.

};

class ThingSetZephyrCanStubInterface : public _ThingSetZephyrCanInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ class ThingSetZephyrCanRequestResponseContext {
std::function<int(const CanID &, uint8_t *, size_t, uint8_t *, size_t)> _inboundRequestCallback;

public:
template<size_t RxSize, size_t TxSize>
ThingSetZephyrCanRequestResponseContext(ThingSetZephyrCanInterface &canInterface, std::array<uint8_t, RxSize> &rxBuffer,
std::array<uint8_t, TxSize> &txBuffer) : _canInterface(canInterface), _rxBuffer(rxBuffer.data()), _rxBufferSize(RxSize),
_txBuffer(txBuffer.data()), _txBufferSize(TxSize)
template <size_t RxSize, size_t TxSize>
ThingSetZephyrCanRequestResponseContext(ThingSetZephyrCanInterface &zephyrCanInterface,
std::array<uint8_t, RxSize> &rxStorage,
std::array<uint8_t, TxSize> &txStorage)
: _canInterface(zephyrCanInterface), _rxBuffer(rxStorage.data()), _rxBufferSize(RxSize),
_txBuffer(txStorage.data()), _txBufferSize(TxSize)
{
_requestResponseContext.filter_id = THINGSET_PLUS_PLUS_ZEPHYR_CAN_FILTER_ID_NONE;
k_sem_init(&_lock, 1, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class ThingSetZephyrCanServerTransport : public Can::ThingSetCanServerTransport
ThingSetZephyrCanServerTransport(const ThingSetZephyrCanServerTransport &) = delete;

template <size_t RxSize, size_t TxSize>
ThingSetZephyrCanServerTransport(ThingSetZephyrCanInterface &canInterface, std::array<uint8_t, RxSize> &rxBuffer,
std::array<uint8_t, TxSize> &txBuffer) : ThingSetCanServerTransport(),
_requestResponseContext(canInterface, rxBuffer, txBuffer)
ThingSetZephyrCanServerTransport(ThingSetZephyrCanInterface &zephyrCanInterface,
std::array<uint8_t, RxSize> &rxStorage, std::array<uint8_t, TxSize> &txStorage)
: ThingSetCanServerTransport(), _requestResponseContext(zephyrCanInterface, rxStorage, txStorage)
{}
~ThingSetZephyrCanServerTransport();

Expand Down
2 changes: 1 addition & 1 deletion include/thingset++/internal/IntrusiveLinkedList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class IntrusiveLinkedList
Element *operator*() const
{
// https://github.com/boostorg/intrusive/blob/master/include/boost/intrusive/detail/parent_from_member.hpp
Element *const container = 0;
Element *const container = nullptr;
const char *const member = static_cast<const char*>(static_cast<const void*>(&(container->*Member)));
std::ptrdiff_t offset = member - static_cast<const char*>(static_cast<const void*>(container));
return std::launder(reinterpret_cast<Element *>(reinterpret_cast<std::size_t>(_node) - static_cast<std::size_t>(offset)));
Expand Down
7 changes: 7 additions & 0 deletions include/thingset++/ip/sockets/SocketEndpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@
#pragma once

#ifdef __ZEPHYR__
/* Zephyr's C headers declare functions named after the structs they take (fs_statvfs,
* net_if_mcast_monitor). In C++ that hides the struct's implicit constructor, which
* -Wshadow reports in every file that includes this header. Nothing here uses those
* constructors, so the check is suspended for these includes only. */
Comment on lines +9 to +12

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
#include <zephyr/net/net_if.h>
#include <zephyr/net/socket.h>
#pragma GCC diagnostic pop
#else
#include <arpa/inet.h>
#include <netinet/in.h>
Expand Down
2 changes: 1 addition & 1 deletion src/can/zephyr/ThingSetZephyrCanInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ _ThingSetZephyrCanInterface::_ThingSetZephyrCanInterface(const device *const can
_isBound = false;
}

const device *const _ThingSetZephyrCanInterface::getDevice()
const device *_ThingSetZephyrCanInterface::getDevice()
{
return _canDevice;
}
Expand Down
8 changes: 4 additions & 4 deletions src/can/zephyr/ThingSetZephyrCanRequestResponseContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ struct IsoTpFastAddress : public isotp_fast_addr {

IsoTpFastAddress &setId(const CanID &id)
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnarrowing"
ext_id = id.getId();
#pragma GCC diagnostic pop
/* ext_id is a 29-bit field and a CAN identifier is at most 29 bits, so the mask
* is lossless; it exists to make that explicit to the compiler
*/
ext_id = id.getId() & CAN_EXT_ID_MASK;
Comment on lines +21 to +24

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marvellous.

return *this;
}
};
Expand Down
6 changes: 6 additions & 0 deletions zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Nothing to build when the module is disabled; creating the library anyway makes
# Zephyr warn about a library with no sources.
if(NOT CONFIG_THINGSET_PLUS_PLUS)
return()
endif()
Comment thread
garethpotter marked this conversation as resolved.

zephyr_library_named("thingset++")

set(CMAKE_CXX_STANDARD 20)
Expand Down
Loading