Skip to content

Commit

Permalink
Use OSI naming convention for examples
Browse files Browse the repository at this point in the history
Signed-off-by: Timm Ruppert <[email protected]>
  • Loading branch information
TimmRuppert committed Nov 13, 2024
1 parent a03469d commit bb70dc2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
6 changes: 3 additions & 3 deletions examples/example_mcap_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "osi_version.pb.h"

std::string GenerateTempFilePath() {
const auto path = std::filesystem::temp_directory_path() / "example_mcap.mcap";
const auto path = std::filesystem::temp_directory_path() / "sv_example.mcap";
return path.string();
}

Expand All @@ -33,7 +33,7 @@ int main(int argc, const char** argv) {

// add a channel to store some data
const std::string topic = "Sensor_1_Input";
const std::unordered_map<std::string, std::string> channel_metadata = {{"description", "This channel contains the output of the sensor 1"}};
const std::unordered_map<std::string, std::string> channel_metadata = {{"description", "This channel contains the input data (SensorView) for sensor 1"}};
trace_file_writer.AddChannel(topic, osi3::SensorView::descriptor(), channel_metadata);

// create OSI data to store
Expand All @@ -59,7 +59,7 @@ int main(int argc, const char** argv) {
for (int i = 0; i < 10; ++i) {
// manipulate the data so not every message is the same
auto timestamp = sensor_view_1.timestamp().seconds() * 1000000000 + sensor_view_1.timestamp().nanos();
timestamp += 100000000;
timestamp += kTimeStepSizeS*1000000000;
sensor_view_1.mutable_timestamp()->set_nanos(timestamp % 1000000000);
sensor_view_1.mutable_timestamp()->set_seconds(timestamp / 1000000000);
ground_truth_1->mutable_timestamp()->set_nanos(timestamp % 1000000000);
Expand Down
21 changes: 19 additions & 2 deletions examples/example_native_binary_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,25 @@
#include "osi_sensordata.pb.h"
#include "osi_version.pb.h"

std::string GetCurrentTimeAsString() {
const auto now = std::chrono::system_clock::now();
const auto now_in_ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()) % 1000;

Check warning on line 15 in examples/example_native_binary_writer.cpp

View workflow job for this annotation

GitHub Actions / lint

examples/example_native_binary_writer.cpp:15:16 [clang-analyzer-deadcode.DeadStores]

Value stored to 'now_in_ms' during its initialization is never read

Check warning on line 15 in examples/example_native_binary_writer.cpp

View workflow job for this annotation

GitHub Actions / lint

examples/example_native_binary_writer.cpp:15:16 [clang-analyzer-deadcode.DeadStores]

Value stored to 'now_in_ms' during its initialization is never read
const auto timer = std::chrono::system_clock::to_time_t(now);
const std::tm utc_time_structure = *std::gmtime(&timer); // Greenwich Mean Time (GMT) is in Coordinated Universal Time (UTC) zone
std::ostringstream oss;
oss << std::put_time(&utc_time_structure, "%Y%m%dT%H%M%S");
oss << "Z"; // As GMT is used as a reference time zone, add Z to indicate UTC (+00:00)
return oss.str();
}

std::string GenerateTempFilePath() {
const auto path = std::filesystem::temp_directory_path() / "example_native_binary_writer.osi";
std::string file_name = GetCurrentTimeAsString();
const auto osi_version = osi3::InterfaceVersion::descriptor()->file()->options().GetExtension(osi3::current_interface_version);
file_name += "_" + std::to_string(osi_version.version_major()) + "." + std::to_string(osi_version.version_minor()) + "." + std::to_string(osi_version.version_patch());
file_name += "_" + google::protobuf::internal::VersionString(GOOGLE_PROTOBUF_VERSION);
file_name += "_10"; // 10 frames
file_name += "_example-native-binary-writer.osi";
const auto path = std::filesystem::temp_directory_path() / file_name;
return path.string();
}

Expand Down Expand Up @@ -47,7 +64,7 @@ int main(int argc, const char** argv) {
for (int i = 0; i < 10; ++i) {
// manipulate the data so not every message is the same
auto timestamp = sensor_view.timestamp().seconds() * 1000000000 + sensor_view.timestamp().nanos();
timestamp += 100000000;
timestamp += kTimeStepSizeS*1000000000; // 100000000;
sensor_view.mutable_timestamp()->set_nanos(timestamp % 1000000000);
sensor_view.mutable_timestamp()->set_seconds(timestamp / 1000000000);
ground_truth->mutable_timestamp()->set_nanos(timestamp % 1000000000);
Expand Down
21 changes: 19 additions & 2 deletions examples/example_txth_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,25 @@
#include "osi_sensordata.pb.h"
#include "osi_version.pb.h"

std::string GetCurrentTimeAsString() {
const auto now = std::chrono::system_clock::now();
const auto now_in_ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()) % 1000;

Check warning on line 14 in examples/example_txth_writer.cpp

View workflow job for this annotation

GitHub Actions / lint

examples/example_txth_writer.cpp:14:16 [clang-analyzer-deadcode.DeadStores]

Value stored to 'now_in_ms' during its initialization is never read

Check warning on line 14 in examples/example_txth_writer.cpp

View workflow job for this annotation

GitHub Actions / lint

examples/example_txth_writer.cpp:14:16 [clang-analyzer-deadcode.DeadStores]

Value stored to 'now_in_ms' during its initialization is never read
const auto timer = std::chrono::system_clock::to_time_t(now);
const std::tm utc_time_structure = *std::gmtime(&timer); // Greenwich Mean Time (GMT) is in Coordinated Universal Time (UTC) zone
std::ostringstream oss;
oss << std::put_time(&utc_time_structure, "%Y%m%dT%H%M%S");
oss << "Z"; // As GMT is used as a reference time zone, add Z to indicate UTC (+00:00)
return oss.str();
}

std::string GenerateTempFilePath() {
const auto path = std::filesystem::temp_directory_path() / "example_txth_writer.txth";
std::string file_name = GetCurrentTimeAsString();
const auto osi_version = osi3::InterfaceVersion::descriptor()->file()->options().GetExtension(osi3::current_interface_version);
file_name += "_" + std::to_string(osi_version.version_major()) + "." + std::to_string(osi_version.version_minor()) + "." + std::to_string(osi_version.version_patch());
file_name += "_" + google::protobuf::internal::VersionString(GOOGLE_PROTOBUF_VERSION);
file_name += "_10"; // 10 frames
file_name += "_example-txth-writer.txth";
const auto path = std::filesystem::temp_directory_path() / file_name;
return path.string();
}

Expand Down Expand Up @@ -46,7 +63,7 @@ int main(int argc, const char** argv) {
for (int i = 0; i < 10; ++i) {
// manipulate the data so not every message is the same
auto timestamp = sensor_view.timestamp().seconds() * 1000000000 + sensor_view.timestamp().nanos();
timestamp += 100000000;
timestamp += kTimeStepSizeS*1000000000;
sensor_view.mutable_timestamp()->set_nanos(timestamp % 1000000000);
sensor_view.mutable_timestamp()->set_seconds(timestamp / 1000000000);
ground_truth->mutable_timestamp()->set_nanos(timestamp % 1000000000);
Expand Down

0 comments on commit bb70dc2

Please sign in to comment.