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

feature: Adapt examples to app manifest v3 #67

Merged
merged 5 commits into from
Aug 22, 2023
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
20 changes: 10 additions & 10 deletions NOTICE-3RD-PARTY-CONTENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,39 @@
| Dependency | Version | License |
|:-----------|:-------:|--------:|
|bottle|0.12.25|MIT|
|certifi|2023.5.7|Mozilla Public License 2.0|
|cfgv|3.3.1|MIT|
|charset-normalizer|3.1.0|MIT|
|certifi|2023.7.22|Mozilla Public License 2.0|
|cfgv|3.4.0|MIT|
|charset-normalizer|3.2.0|MIT|
|colorama|0.4.6|BSD|
|conan|1.58.0|MIT|
|cpplint|1.6.1|New BSD|
|distlib|0.3.6|Python Software Foundation License|
|distlib|0.3.7|Python Software Foundation License|
|distro|1.7.0|Apache 2.0|
|fasteners|0.18|Apache 2.0|
|filelock|3.12.2|The Unlicense (Unlicense)|
|gcovr|5.2|BSD|
|identify|2.5.24|MIT|
|identify|2.5.26|MIT|
|idna|3.4|BSD|
|Jinja2|3.1.2|New BSD|
|lxml|4.9.3|New BSD|
|MarkupSafe|2.1.3|New BSD|
|node-semver|0.6.1|MIT|
|nodeenv|1.8.0|BSD|
|patch-ng|1.17.4|MIT|
|platformdirs|3.8.1|MIT|
|platformdirs|3.10.0|MIT|
|pluginbase|1.0.1|BSD|
|pre-commit|2.20.0|MIT|
|Pygments|2.15.1|Simplified BSD|
|PyJWT|2.7.0|MIT|
|Pygments|2.16.1|Simplified BSD|
|PyJWT|2.8.0|MIT|
|python-dateutil|2.8.2|Apache 2.0<br/>BSD|
|PyYAML|6.0|MIT|
|requests|2.31.0|Apache 2.0|
|setuptools|58.1.0|MIT|
|six|1.16.0|MIT|
|toml|0.10.2|MIT|
|tqdm|4.65.0|MIT<br/>Mozilla Public License 2.0 (MPL 2.0)|
|tqdm|4.66.1|MIT<br/>Mozilla Public License 2.0 (MPL 2.0)|
|urllib3|1.26.16|MIT|
|virtualenv|20.23.1|MIT|
|virtualenv|20.24.3|MIT|
## Workflows
| Dependency | Version | License |
|:-----------|:-------:|--------:|
Expand Down
56 changes: 32 additions & 24 deletions examples/seat-adjuster/AppManifest.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
[
{
"name": "seatadjuster",
"vehicleModel": {
"src": "https://github.com/COVESA/vehicle_signal_specification/releases/download/v3.0/vss_rel_3.0.json",
"datapoints": [
{
"path": "Vehicle.Cabin.Seat.Row1.Pos1.Position",
"required": "true",
"access": "read"
},
{
"path": "Vehicle.Speed",
"required": "true",
"access": "read"
{
"manifestVersion": "v3",
"name": "seatadjuster",
"interfaces": [
{
"type": "vehicle-signal-interface",
"config": {
"src": "https://github.com/COVESA/vehicle_signal_specification/releases/download/v3.0/vss_rel_3.0.json",
"datapoints": {
"required": [
{
"path": "Vehicle.Cabin.Seat.Row1.Pos1.Position",
"access": "read"
},
MP91 marked this conversation as resolved.
Show resolved Hide resolved
{
"path": "Vehicle.Speed",
"access": "read"
}
]
}
]
}
},
"runtime": [
"grpc://sdv.databroker.v1.Broker/GetDatapoints",
"grpc://sdv.databroker.v1.Broker/Subscribe",
"grpc://sdv.edge.comfort.seats.v1.Seats/MoveComponent",
"mqtt"
doosuu marked this conversation as resolved.
Show resolved Hide resolved
]
}
]
{
"type": "pubsub",
"config": {
"reads": [ "seatadjuster/setPosition/request" ],
"writes": [
"seatadjuster/setPosition/response",
"seatadjuster/currentPosition"
]
}
}
]
}
61 changes: 19 additions & 42 deletions examples/seat-adjuster/src/SeatAdjusterApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,13 @@ void SeatAdjusterApp::onStart() {
->onError(
[this](auto&& status) { onErrorDatapoint(std::forward<decltype(status)>(status)); });

// TODO: Do we need some kind of functionality to ensure that the Model
// in the VDB is actually the same as the one we are using? i.e. does it
// have the data points we are expecting???
// m_vehicleModel->verify();

subscribeToTopic(TOPIC_REQUEST)
->onItem([this](auto&& item) {
onSetPositionRequestReceived(std::forward<decltype(item)>(item));
})
->onError([this](auto&& status) { onErrorTopic(std::forward<decltype(status)>(status)); });
}

void SeatAdjusterApp::onSeatMovementRequested(const velocitas::VoidResult& status, int requestId,
float requestedPosition) {
velocitas::logger().info("Seat movement request processed...");

nlohmann::json respData(
{{JSON_FIELD_REQUEST_ID, requestId},
{JSON_FIELD_RESULT,
{{JSON_FIELD_MESSAGE, fmt::format("Called MoveComponent {}", requestedPosition)},
{JSON_FIELD_STATUS, STATUS_OK}}}});
publishToTopic(TOPIC_RESPONSE, respData.dump());
}

void SeatAdjusterApp::onSetPositionRequestReceived(const std::string& data) {
velocitas::logger().debug("position request: \"{}\"", data);
const auto jsonData = nlohmann::json::parse(data);
Expand All @@ -93,46 +76,40 @@ void SeatAdjusterApp::onSetPositionRequestReceived(const std::string& data) {
const auto desiredSeatPosition = jsonData[JSON_FIELD_POSITION].get<int>();
const auto requestId = jsonData[JSON_FIELD_REQUEST_ID].get<int>();

const auto vehicleSpeed = m_vehicleModel->Speed.get()->await().value();
nlohmann::json respData({{JSON_FIELD_REQUEST_ID, requestId}, {JSON_FIELD_RESULT, {}}});
const auto vehicleSpeed = m_vehicleModel->Speed.get()->await().value();
if (vehicleSpeed == 0) {
velocitas::vehicle::cabin::SeatService::SeatLocation location{1, 1};
m_vehicleModel->Cabin.SeatService
.moveComponent(location, velocitas::vehicle::cabin::SeatService::Component::Base,
desiredSeatPosition)
->onResult([this, requestId, desiredSeatPosition](auto&& result) {
onSeatMovementRequested(std::forward<decltype(result)>(result), requestId,
desiredSeatPosition);
})
->onError([this](auto&& status) { onError(std::forward<decltype(status)>(status)); });
m_vehicleModel->Cabin.Seat.Row1.Pos1.Position.set(desiredSeatPosition)->await();

respData[JSON_FIELD_RESULT][JSON_FIELD_STATUS] = STATUS_OK;
respData[JSON_FIELD_RESULT][JSON_FIELD_MESSAGE] =
fmt::format("Set Seat position to: {}", desiredSeatPosition);
} else {
const auto errorMsg = fmt::format(
"Not allowed to move seat because vehicle speed is {} and not 0", vehicleSpeed);
velocitas::logger().info(errorMsg);

nlohmann::json respData(
{{JSON_FIELD_REQUEST_ID, requestId},
{JSON_FIELD_RESULT,
{{JSON_FIELD_STATUS, STATUS_FAIL}, {JSON_FIELD_MESSAGE, errorMsg}}}});
publishToTopic(TOPIC_RESPONSE, respData.dump());
respData[JSON_FIELD_RESULT][JSON_FIELD_STATUS] = STATUS_FAIL;
respData[JSON_FIELD_RESULT][JSON_FIELD_MESSAGE] = errorMsg;
}

publishToTopic(TOPIC_RESPONSE, respData.dump());
}

void SeatAdjusterApp::onSeatPositionChanged(const velocitas::DataPointReply& dataPoints) {
const auto seatPositionValue =
dataPoints.get(m_vehicleModel->Cabin.Seat.Row1.Pos1.Position)->value();

nlohmann::json jsonResponse;
try {
nlohmann::json jsonResponse({JSON_FIELD_POSITION, seatPositionValue});

publishToTopic(TOPIC_CURRENT_POSITION, jsonResponse.dump());
const auto seatPositionValue =
dataPoints.get(m_vehicleModel->Cabin.Seat.Row1.Pos1.Position)->value();
jsonResponse[JSON_FIELD_POSITION] = seatPositionValue;
} catch (std::exception& exception) {
velocitas::logger().error("Unable to get Current Seat Position, Exception: {}",
exception.what());
nlohmann::json jsonResponse(
{{JSON_FIELD_STATUS, STATUS_FAIL}, {JSON_FIELD_MESSAGE, exception.what()}});

publishToTopic(TOPIC_CURRENT_POSITION, jsonResponse.dump());
jsonResponse[JSON_FIELD_STATUS] = STATUS_FAIL;
jsonResponse[JSON_FIELD_MESSAGE] = exception.what();
}

publishToTopic(TOPIC_CURRENT_POSITION, jsonResponse.dump());
}

void SeatAdjusterApp::onError(const velocitas::Status& status) {
Expand Down
55 changes: 27 additions & 28 deletions examples/set-data-points/AppManifest.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
[
{
"name": "set-data-points",
"vehicleModel": {
"src": "https://github.com/COVESA/vehicle_signal_specification/releases/download/v3.0/vss_rel_3.0.json",
"datapoints": [
{
"path": "Vehicle.Cabin.Seat.Row1.Pos1.Position",
"required": "true",
"access": "write"
},
{
"path": "Vehicle.Cabin.Seat.Row1.Pos2.Position",
"required": "true",
"access": "write"
},
{
"path": "Vehicle.Speed",
"required": "true",
"access": "write"
{
"manifestVersion": "v3",
"name": "set-data-points",
"interfaces": [
{
"type": "vehicle-signal-interface",
"config": {
"src": "https://github.com/COVESA/vehicle_signal_specification/releases/download/v3.0/vss_rel_3.0.json",
"datapoints": {
"required": [
{
"path": "Vehicle.Cabin.Seat.Row1.Pos1.Position",
"access": "write"
},
{
"path": "Vehicle.Cabin.Seat.Row1.Pos2.Position",
"access": "write"
},
{
"path": "Vehicle.Speed",
"access": "write"
}
]
}
]
},
"runtime": [
"grpc://sdv.databroker.v1.Broker/GetDatapoints",
"grpc://sdv.databroker.v1.Broker/SetDatapoints"
]
}
]
}
}
]
}
2 changes: 1 addition & 1 deletion install_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fi
# Enable Conan revision handling to enable pinning googleapis recipe revision (see conanfile.py)
export CONAN_REVISIONS_ENABLED=1

conan install \
conan install --update \
-pr:h ../.conan/profiles/linux_${HOST_ARCH}_${BUILD_VARIANT} \
${XCOMPILE_PROFILE} \
--build "${WHICH_DEPS_TO_BUILD}" ..
Loading