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

Henning/vtd multi agent #12

Merged
merged 5 commits into from
Feb 4, 2021
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
5 changes: 3 additions & 2 deletions Makefile.all
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,9 @@ CONAN_OPTIONS += -o cloe:with_engine=False
endif

ifeq (${WITH_VTD},1)
ALL_PKGS := $(filter-out plugins/vtd, ${ALL_PKGS})
CONAN_OPTIONS += -o cloe:with_vtd=True
else
ALL_PKGS := $(filter-out plugins/vtd, ${ALL_PKGS})
endif

ifeq (${BUILD_TESTS},0)
Expand Down Expand Up @@ -249,7 +250,7 @@ help::
echo " Options:"
echo " USE_NPROC=(0|1) to build $(shell nproc) packages simultaneously (default=0)"
echo " WITH_ENGINE=(0|1) to build and deploy cloe-engine (default=1)"
echo " WITH_VTD=(0|1) to build and deploy cloe-plugin-vtd (default=1)"
echo " WITH_VTD=(0|1) to build and deploy cloe-plugin-vtd (default=0)"
echo " BUILD_TESTS=(0|1) to build and run unit tests (default=1)"
echo
echo " Defines:"
Expand Down
4 changes: 0 additions & 4 deletions plugins/vtd/src/rdb_codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,6 @@ void RdbCodec::process(RDB_MSG_t* msg, bool& restart, cloe::Duration& sim_time)
}

void RdbCodec::step(uint64_t frame_number, bool& restart, cloe::Duration& sim_time) {
// TODO(ben): For some reason, this loop here goes round and round with zero
// messages received. Either we should stop dumping the log message when
// there are no messages to process, or we should have the receive function
// only return when there are messages?
while (processing_frame_ || frame_number_ < frame_number || restart) {
auto messages = rdb_->receive();
rdb_logger()->trace("RdbCodec: processing {} messages [frame={}]", messages.size(),
Expand Down
5 changes: 5 additions & 0 deletions plugins/vtd/src/rdb_transceiver_tcp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include "rdb_transceiver.hpp" // for RdbTransceiver
#include "vtd_logger.hpp" // for rdb_logger

#define VTD_RDB_WAIT_SLEEP_MS 1

namespace vtd {

/**
Expand All @@ -50,6 +52,9 @@ class RdbTransceiverTcp : public RdbTransceiver, public cloe::utility::TcpTransc

std::vector<std::shared_ptr<RDB_MSG_t>> receive() override {
std::vector<std::shared_ptr<RDB_MSG_t>> msgs;
while (!this->has()) {
std::this_thread::sleep_for(cloe::Milliseconds{VTD_RDB_WAIT_SLEEP_MS});
}
while (this->has()) {
num_received_++;
msgs.push_back(this->receive_wait());
Expand Down
22 changes: 20 additions & 2 deletions plugins/vtd/src/scp_messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ const char* Pause = "<SimCtrl><Pause/></SimCtrl>";
const char* Restart = "<SimCtrl><Restart/></SimCtrl>";
const char* Apply = "<SimCtrl><Apply/></SimCtrl>";
const char* Config = "<SimCtrl><Config/></SimCtrl>";
const char* QueryInit = "<Query entity=\"taskControl\"><Init source=\"cloe\" /></Query>";
const char* AckInit = "<SimCtrl><InitDone source=\"cloe\" /></SimCtrl>";
const char* InitOperation = "<SimCtrl><Init mode=\"operation\" /></SimCtrl>";

std::string ParamServerConfig::to_scp() const {
std::string tc_config = fmt::format(R"SCP(
Expand Down Expand Up @@ -64,12 +67,11 @@ std::string ParamServerConfig::to_scp() const {
)SCP", tc_config);
}

std::string ScenarioStartConfig::to_scp() const {
std::string ScenarioConfig::to_scp() const {
return fmt::format(R"SCP(
<SimCtrl>
<UnloadSensors />
<LoadScenario filename="{}" />
<Start mode="operation" />
</SimCtrl>
)SCP", filename);
}
Expand Down Expand Up @@ -153,6 +155,15 @@ std::string SensorConfiguration::to_scp() const {
</Sensor>)SCP", sensor_id, port, player_id);
}

std::string DynamicsPluginConfig::to_scp() const {
return fmt::format(R"SCP(
<DynamicsPlugin name="viTrafficDyn_{0}" enable="true">
<Load lib="libModuleTrafficDyn.so" path=""/>
<Player name="{0}" />
<Debug enable="false" />
</DynamicsPlugin>)SCP", name);
}

std::string LabelVehicle::to_scp() const {
return fmt::format(R"SCP(
<Symbol name="{0}">
Expand All @@ -169,6 +180,13 @@ std::string RecordDat::to_scp() const {
</Record>)SCP", datfile_path.parent_path().string(), datfile_path.filename().string());
}

std::string QueryScenario::to_scp() const {
return fmt::format(R"SCP(
<Query entity="traffic">
<GetScenario filename="{0}"/>
</Query>)SCP", scenario);
}

// clang-format on
} // namespace scp
} // namespace vtd
15 changes: 14 additions & 1 deletion plugins/vtd/src/scp_messages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,17 @@ extern const char* Pause;
extern const char* Restart;
extern const char* Apply;
extern const char* Config;
extern const char* QueryInit;
extern const char* AckInit;
extern const char* InitOperation;

struct ParamServerConfig : public ScpMessage {
std::string sync_source = "RDB";
bool no_image_generator = false;
std::string to_scp() const override;
};

struct ScenarioStartConfig : public ScpMessage {
struct ScenarioConfig : public ScpMessage {
std::string filename;
std::string to_scp() const override;
};
Expand All @@ -66,6 +69,11 @@ struct SensorConfiguration : public ScpMessage {
std::string to_scp() const override;
};

struct DynamicsPluginConfig : public ScpMessage {
std::string name;
std::string to_scp() const override;
};

struct LabelVehicle : public ScpMessage {
std::string tethered_to_player;
std::string text;
Expand All @@ -85,5 +93,10 @@ struct RecordDat : public ScpMessage {
std::string to_scp() const override;
};

struct QueryScenario : public ScpMessage {
std::string scenario;
std::string to_scp() const override;
};

} // namespace scp
} // namespace vtd
Loading