Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend model classes with small int types, node type and string-based node query #110

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
4 changes: 2 additions & 2 deletions NOTICE-3RD-PARTY-CONTENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
|fasteners|0.19|Apache 2.0|
|filelock|3.16.1|The Unlicense (Unlicense)|
|gcovr|5.2|BSD|
|identify|2.6.1|MIT|
|identify|2.6.2|MIT|
|idna|3.10|BSD|
|jinja2|3.1.4|BSD|
|lxml|5.3.0|New BSD|
Expand All @@ -32,7 +32,7 @@
|PyYAML|6.0.2|MIT|
|requests|2.32.3|Apache 2.0|
|six|1.16.0|MIT|
|tqdm|4.66.6|MIT<br/>Mozilla Public License 2.0 (MPL 2.0)|
|tqdm|4.67.0|MIT<br/>Mozilla Public License 2.0 (MPL 2.0)|
|urllib3|1.26.20|MIT|
|virtualenv|20.27.1|MIT|
## Workflows
Expand Down
24 changes: 24 additions & 0 deletions sdk/include/sdk/DataPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "sdk/DataPointValue.h"
#include "sdk/Node.h"

#include <cassert>
#include <cstdint>
#include <functional>
#include <string>
Expand All @@ -39,16 +40,29 @@ namespace velocitas {
class DataPoint : public Node {
public:
using Node::Node;
DataPoint(const std::string& name, Type type, Node* parent = nullptr)
: Node{name, parent}
, m_type{type} {
assert(m_type != Type::BRANCH && m_type != Type::UNKNOWN_LEAF_TYPE);
}
~DataPoint() override = default;

DataPoint(const DataPoint&) = delete;
DataPoint(DataPoint&&) = delete;
DataPoint& operator=(const DataPoint&) = delete;
DataPoint& operator=(DataPoint&&) = delete;

[[nodiscard]] Type getType() const override { return m_type; }
erikbosch marked this conversation as resolved.
Show resolved Hide resolved
[[nodiscard]] virtual DataPointValue::Type getDataType() const = 0;

[[nodiscard]] const DataPoint* getDataPoint(const std::string& path) const override;

[[nodiscard]] virtual std::string toString() const = 0;

bool operator<(const DataPoint& rhs) const { return getPath() < rhs.getPath(); }

private:
const Type m_type = Type::UNKNOWN_LEAF_TYPE;
};

inline bool operator<(const std::reference_wrapper<DataPoint>& lhs,
Expand All @@ -73,6 +87,8 @@ template <typename T> class TypedDataPoint : public DataPoint {
TypedDataPoint& operator=(const TypedDataPoint&) = delete;
TypedDataPoint& operator=(TypedDataPoint&&) = delete;

[[nodiscard]] DataPointValue::Type getDataType() const override { return getValueType<T>(); }

[[nodiscard]] AsyncResultPtr_t<TypedDataPointValue<T>> get() const;
[[nodiscard]] AsyncResultPtr_t<Status> set(T value) const;

Expand All @@ -81,10 +97,18 @@ template <typename T> class TypedDataPoint : public DataPoint {

using DataPointBoolean = TypedDataPoint<bool>;
using DataPointBooleanArray = TypedDataPoint<std::vector<bool>>;
using DataPointInt8 = TypedDataPoint<int8_t>;
using DataPointInt8Array = TypedDataPoint<std::vector<int8_t>>;
using DataPointInt16 = TypedDataPoint<int16_t>;
using DataPointInt16Array = TypedDataPoint<std::vector<int16_t>>;
using DataPointInt32 = TypedDataPoint<int32_t>;
using DataPointInt32Array = TypedDataPoint<std::vector<int32_t>>;
using DataPointInt64 = TypedDataPoint<int64_t>;
using DataPointInt64Array = TypedDataPoint<std::vector<int64_t>>;
using DataPointUint8 = TypedDataPoint<uint8_t>;
using DataPointUint8Array = TypedDataPoint<std::vector<uint8_t>>;
using DataPointUint16 = TypedDataPoint<uint16_t>;
using DataPointUint16Array = TypedDataPoint<std::vector<uint16_t>>;
using DataPointUint32 = TypedDataPoint<uint32_t>;
using DataPointUint32Array = TypedDataPoint<std::vector<uint32_t>>;
using DataPointUint64 = TypedDataPoint<uint64_t>;
Expand Down
46 changes: 45 additions & 1 deletion sdk/include/sdk/DataPointValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,15 @@ class DataPointValue {
DOUBLE,
DOUBLE_ARRAY,
STRING,
STRING_ARRAY
STRING_ARRAY,
INT8,
INT8_ARRAY,
INT16,
INT16_ARRAY,
UINT8,
UINT8_ARRAY,
UINT16,
UINT16_ARRAY,
};

enum class Failure {
Expand Down Expand Up @@ -126,6 +134,18 @@ template <> inline DataPointValue::Type getValueType<bool>() { return DataPointV
template <> inline DataPointValue::Type getValueType<std::vector<bool>>() {
return DataPointValue::Type::BOOL_ARRAY;
}
template <> inline DataPointValue::Type getValueType<int8_t>() {
return DataPointValue::Type::INT8;
}
template <> inline DataPointValue::Type getValueType<std::vector<int8_t>>() {
return DataPointValue::Type::INT8_ARRAY;
}
template <> inline DataPointValue::Type getValueType<int16_t>() {
return DataPointValue::Type::INT16;
}
template <> inline DataPointValue::Type getValueType<std::vector<int16_t>>() {
return DataPointValue::Type::INT16_ARRAY;
}
template <> inline DataPointValue::Type getValueType<int32_t>() {
return DataPointValue::Type::INT32;
}
Expand All @@ -138,6 +158,18 @@ template <> inline DataPointValue::Type getValueType<int64_t>() {
template <> inline DataPointValue::Type getValueType<std::vector<int64_t>>() {
return DataPointValue::Type::INT64_ARRAY;
}
template <> inline DataPointValue::Type getValueType<uint8_t>() {
return DataPointValue::Type::UINT8;
}
template <> inline DataPointValue::Type getValueType<std::vector<uint8_t>>() {
return DataPointValue::Type::UINT8_ARRAY;
}
template <> inline DataPointValue::Type getValueType<uint16_t>() {
return DataPointValue::Type::UINT16;
}
template <> inline DataPointValue::Type getValueType<std::vector<uint16_t>>() {
return DataPointValue::Type::UINT16_ARRAY;
}
template <> inline DataPointValue::Type getValueType<uint32_t>() {
return DataPointValue::Type::UINT32;
}
Expand Down Expand Up @@ -212,12 +244,24 @@ template <typename T> std::string TypedDataPointValue<T>::getValueAsString() con
template <> inline std::string TypedDataPointValue<bool>::getValueAsString() const {
return m_value ? "true" : "false";
}
template <> inline std::string TypedDataPointValue<int8_t>::getValueAsString() const {
return std::to_string(m_value);
}
template <> inline std::string TypedDataPointValue<int16_t>::getValueAsString() const {
return std::to_string(m_value);
}
template <> inline std::string TypedDataPointValue<int32_t>::getValueAsString() const {
return std::to_string(m_value);
}
template <> inline std::string TypedDataPointValue<int64_t>::getValueAsString() const {
return std::to_string(m_value);
}
template <> inline std::string TypedDataPointValue<uint8_t>::getValueAsString() const {
return std::to_string(m_value);
}
template <> inline std::string TypedDataPointValue<uint16_t>::getValueAsString() const {
return std::to_string(m_value);
}
template <> inline std::string TypedDataPointValue<uint32_t>::getValueAsString() const {
return std::to_string(m_value);
}
Expand Down
25 changes: 23 additions & 2 deletions sdk/include/sdk/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,28 @@
#ifndef VEHICLE_APP_SDK_NODE_H
#define VEHICLE_APP_SDK_NODE_H

#include <memory>
#include <string>
#include <unordered_map>

namespace velocitas {

class DataPoint;

/**
* @brief A tree node.
*
*/
class Node {
public:
enum class Type {
BRANCH,
UNKNOWN_LEAF_TYPE,
Copy link
Contributor

@erikbosch erikbosch Nov 13, 2024

Choose a reason for hiding this comment

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

There exists in COVESA VSS also nodes for structs and properties. Any particular reason to limit this one to leaf types, or could we have it more general as UNKNOWN_TYPE? (And if so have it first?)

Copy link
Member Author

@BjoernAtBosch BjoernAtBosch Nov 13, 2024

Choose a reason for hiding this comment

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

Currently, we do not support structs and properties.
A general UNKNOWN_TYPE could be discussed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Having spent some time to think about this: I don't like defining an unknown for enums so much, as it always raises the question how to handle this value.
I introduced the UNKNOWN_LEAF_TYPE just for backwards compatibility reasons, means in case the SDK is used by a model generated before doing these extensions.

I've a question regarding your hint regarding structs and properties. At least for structs my understanding is that this isn't a node type but a data type: A struct represents a datapoint/signal of complex nature and can be either of type attribute, sensor, or actuator. I.e. those node types shall not be mixed within a single struct type.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, the struct/property VSS nodes will never appear in the same tree as signals and branches.

Thanks for the explanation. Possibly add a comment on UNKNOWN_LEAF_TYPE that it is there just for backward compatibility reasons

ATTRIBUTE,
SENSOR,
ACTUATOR,
};

/**
* @brief Construct a new Node object
*
Expand All @@ -48,15 +60,24 @@ class Node {
*/
[[nodiscard]] std::string getPath() const;

[[nodiscard]] virtual Type getType() const { return Type::BRANCH; }
Copy link
Contributor

@erikbosch erikbosch Nov 13, 2024

Choose a reason for hiding this comment

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

Why is branch always returned?

I assume it is because we only instantiate a Node for Branch, in all other case we have a subclass of Node that overrides this with something else, or? Maybe worth a comment?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, a "pure" Node always represents a branch. I'll add a comment ...


[[nodiscard]] virtual const DataPoint* getDataPoint(const std::string& path) const;

Node(const Node&) = delete;
Node(Node&&) = delete;
Node& operator=(const Node&) = delete;
Node& operator=(Node&&) = delete;

protected:
void registerChild(const Node& childNode);

private:
// TODO: Use std::weak_ptr ?
Node* m_parent;
std::string m_name;
Node* const m_parent;
erikbosch marked this conversation as resolved.
Show resolved Hide resolved
const std::string m_name;
using NodeMap = std::unordered_map<std::string, const Node*>;
std::unique_ptr<NodeMap> m_children;
};

} // namespace velocitas
Expand Down
8 changes: 8 additions & 0 deletions sdk/include/sdk/grpc/GrpcDataPointValueProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,18 @@ class GrpcDataPointValueProvider : public IDataPointValueProvider {
std::vector<float> getFloatArrayValue() const override;
double getDoubleValue() const override;
std::vector<double> getDoubleArrayValue() const override;
int8_t getInt8Value() const override;
std::vector<int8_t> getInt8ArrayValue() const override;
int16_t getInt16Value() const override;
std::vector<int16_t> getInt16ArrayValue() const override;
int32_t getInt32Value() const override;
std::vector<int32_t> getInt32ArrayValue() const override;
int64_t getInt64Value() const override;
std::vector<int64_t> getInt64ArrayValue() const override;
uint8_t getUint8Value() const override;
std::vector<uint8_t> getUint8ArrayValue() const override;
uint16_t getUint16Value() const override;
std::vector<uint16_t> getUint16ArrayValue() const override;
uint32_t getUint32Value() const override;
std::vector<uint32_t> getUint32ArrayValue() const override;
uint64_t getUint64Value() const override;
Expand Down
16 changes: 16 additions & 0 deletions sdk/include/sdk/vdb/IDataPointValueProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ class IDataPointValueProvider {

[[nodiscard]] virtual std::vector<double> getDoubleArrayValue() const = 0;

[[nodiscard]] virtual int8_t getInt8Value() const = 0;

[[nodiscard]] virtual std::vector<int8_t> getInt8ArrayValue() const = 0;

[[nodiscard]] virtual int16_t getInt16Value() const = 0;

[[nodiscard]] virtual std::vector<int16_t> getInt16ArrayValue() const = 0;

[[nodiscard]] virtual int32_t getInt32Value() const = 0;

[[nodiscard]] virtual std::vector<int32_t> getInt32ArrayValue() const = 0;
Expand All @@ -62,6 +70,14 @@ class IDataPointValueProvider {

[[nodiscard]] virtual std::vector<int64_t> getInt64ArrayValue() const = 0;

[[nodiscard]] virtual uint8_t getUint8Value() const = 0;

[[nodiscard]] virtual std::vector<uint8_t> getUint8ArrayValue() const = 0;

[[nodiscard]] virtual uint16_t getUint16Value() const = 0;

[[nodiscard]] virtual std::vector<uint16_t> getUint16ArrayValue() const = 0;

[[nodiscard]] virtual uint32_t getUint32Value() const = 0;

[[nodiscard]] virtual std::vector<uint32_t> getUint32ArrayValue() const = 0;
Expand Down
48 changes: 48 additions & 0 deletions sdk/src/sdk/DataPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ template <typename T> AsyncResultPtr_t<TypedDataPointValue<T>> TypedDataPoint<T>
[this](const DataPointReply& dataPointValues) { return *dataPointValues.get(*this); });
}

const DataPoint* DataPoint::getDataPoint(const std::string& path) const {
// We are at leaf level. Return nullptr if further child(ren) are expected
if (!path.empty()) {
return nullptr;
}
return this;
}

template <typename T> AsyncResultPtr_t<Status> TypedDataPoint<T>::set(T value) const {
std::vector<std::unique_ptr<DataPointValue>> vec;
vec.reserve(1);
Expand All @@ -56,6 +64,22 @@ template <> std::string TypedDataPoint<std::vector<bool>>::toString() const {
return fmt::format("DataPointBooleanArray: ('{}')", getName());
}

template <> std::string TypedDataPoint<int8_t>::toString() const {
return fmt::format("DataPointInt8: ('{}')", getName());
}

template <> std::string TypedDataPoint<std::vector<int8_t>>::toString() const {
return fmt::format("DataPointInt8Array: ('{}')", getName());
}

template <> std::string TypedDataPoint<int16_t>::toString() const {
return fmt::format("DataPointInt16: ('{}')", getName());
}

template <> std::string TypedDataPoint<std::vector<int16_t>>::toString() const {
return fmt::format("DataPointInt16Array: ('{}' : '{}')", getName());
}

template <> std::string TypedDataPoint<int32_t>::toString() const {
return fmt::format("DataPointInt32: ('{}')", getName());
}
Expand All @@ -72,6 +96,22 @@ template <> std::string TypedDataPoint<std::vector<int64_t>>::toString() const {
return fmt::format("DataPointInt64Array: ('{}' : '{}')", getName());
}

template <> std::string TypedDataPoint<uint8_t>::toString() const {
return fmt::format("DataPointUint8: ('{}')", getName());
}

template <> std::string TypedDataPoint<std::vector<uint8_t>>::toString() const {
return fmt::format("DataPointUint8Array: ('{}')", getName());
}

template <> std::string TypedDataPoint<uint16_t>::toString() const {
return fmt::format("DataPointUint16: ('{}')", getName());
}

template <> std::string TypedDataPoint<std::vector<uint16_t>>::toString() const {
return fmt::format("DataPointUint16Array: ('{}' : '{}')", getName());
}

template <> std::string TypedDataPoint<uint32_t>::toString() const {
return fmt::format("DataPointUint32: ('{}')", getName());
}
Expand Down Expand Up @@ -114,10 +154,18 @@ template <> std::string TypedDataPoint<std::vector<std::string>>::toString() con

template class TypedDataPoint<bool>;
template class TypedDataPoint<std::vector<bool>>;
template class TypedDataPoint<int8_t>;
template class TypedDataPoint<std::vector<int8_t>>;
template class TypedDataPoint<int16_t>;
template class TypedDataPoint<std::vector<int16_t>>;
template class TypedDataPoint<int32_t>;
template class TypedDataPoint<std::vector<int32_t>>;
template class TypedDataPoint<int64_t>;
template class TypedDataPoint<std::vector<int64_t>>;
template class TypedDataPoint<uint8_t>;
template class TypedDataPoint<std::vector<uint8_t>>;
template class TypedDataPoint<uint16_t>;
template class TypedDataPoint<std::vector<uint16_t>>;
template class TypedDataPoint<uint32_t>;
template class TypedDataPoint<std::vector<uint32_t>>;
template class TypedDataPoint<uint64_t>;
Expand Down
Loading