OpenCyphal / nunavut

Generate code from DSDL using PyDSDL and Jinja2
https://nunavut.readthedocs.io/
Other
39 stars 24 forks source link

Fix cpp implementations #255

Closed asmfreak closed 2 years ago

asmfreak commented 2 years ago

This patch includes some quality-of-life improvements:

  1. All external methods in serialization support header-only library are now marked with inline to avoid linker errors if serialization code was included from several different translation units.
  2. Refactor bitspan constructors to make user code easier and should fix #254.
    
    uavcan::node::Heartbeat_1_0 hb{};
    std::array<uint8_t, uavcan::node::Heartbeat_1_0::SERIALIZATION_BUFFER_SIZE_BYTES> data;

// before change: hb.serialize({{data}, 0});

// after change: hb.serialize(data);

3. Change naming of service types from `uavcan::node::GetInfo_1_0::Request_1_0` to `uavcan::node::GetInfo::Request_1_0`
4. Add a special service type alongside `Request` and `Response` and some constexpr boolean traits to ease templating on services:
```cpp
namespace uavcan
{
namespace node
{
namespace GetInfo
{
struct Request_1_0 final
{
    // ...
    static constexpr bool IsServiceType = true;
    static constexpr bool IsService = false;
    static constexpr bool IsRequest = true;
    static constexpr bool IsResponse = false;
    // ...
};

struct Response_1_0 final
{
    // ...
    static constexpr bool IsServiceType = true;
    static constexpr bool IsService = false;
    static constexpr bool IsRequest = false;
    static constexpr bool IsResponse = true;
    // ...
};

struct Service_1_0 {
    static constexpr bool IsServiceType = true;
    static constexpr bool IsService = true;
    static constexpr bool IsRequest = false;
    static constexpr bool IsResponse = false;

    using Request = Request_1_0;
    using Response = Response_1_0;
};

} // namespace GetInfo_1_0
} // namespace node
} // namespace uavcan
sonarcloud[bot] commented 2 years ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

84.0% 84.0% Coverage
0.0% 0.0% Duplication