Fix compile errors in Linux
This commit is contained in:
parent
6eb9727cb8
commit
02baff814e
|
@ -1,6 +1,10 @@
|
||||||
cmake_minimum_required (VERSION 2.6)
|
cmake_minimum_required (VERSION 2.6)
|
||||||
project (CarlaServer)
|
project (CarlaServer)
|
||||||
|
|
||||||
|
SET(CMAKE_CXX_COMPILER clang++)
|
||||||
|
SET(CMAKE_CXX_STANDARD 14)
|
||||||
|
SET(CMAKE_CXX_STANDARD_REQUIRED 14)
|
||||||
|
|
||||||
# Boost configuration
|
# Boost configuration
|
||||||
SET(Boost_USE_STATIC_LIBS ON)
|
SET(Boost_USE_STATIC_LIBS ON)
|
||||||
find_package(Boost REQUIRED system date_time regex)
|
find_package(Boost REQUIRED system date_time regex)
|
||||||
|
|
|
@ -3,6 +3,9 @@ BUILD_FOLDER=build
|
||||||
vsproject:
|
vsproject:
|
||||||
cmake -H. -B$(BUILD_FOLDER) -G "Visual Studio 14 2015 Win64"
|
cmake -H. -B$(BUILD_FOLDER) -G "Visual Studio 14 2015 Win64"
|
||||||
|
|
||||||
|
stproject:
|
||||||
|
cmake -H. -B$(BUILD_FOLDER) -G "Sublime Text 2 - Ninja"
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -Rf build CMakeFiles
|
rm -Rf build CMakeFiles
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace carla {
|
namespace carla {
|
||||||
namespace server {
|
namespace server {
|
||||||
// -- Static methods ---------------------------------------------------------
|
// -- Static methods ---------------------------------------------------------
|
||||||
|
|
||||||
template <typename ERROR_CODE>
|
template <typename ERROR_CODE>
|
||||||
|
@ -13,7 +13,7 @@ namespace carla {
|
||||||
|
|
||||||
|
|
||||||
// This is the thread that sends a string over the TCP socket.
|
// This is the thread that sends a string over the TCP socket.
|
||||||
static void serverWorkerThread(TCPServer &server, std::string &message) {
|
static void serverWorkerThread(TCPServer &server, const std::string &message) {
|
||||||
TCPServer::error_code error;
|
TCPServer::error_code error;
|
||||||
//message = message.size.c_ + message;
|
//message = message.size.c_ + message;
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ namespace carla {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void worldSendThread(TCPServer &server, std::string &message) {
|
static void worldSendThread(TCPServer &server, const std::string &message) {
|
||||||
TCPServer::error_code error;
|
TCPServer::error_code error;
|
||||||
//message = message.size + message;
|
//message = message.size + message;
|
||||||
|
|
||||||
|
@ -83,13 +83,16 @@ namespace carla {
|
||||||
_world(worldPort),
|
_world(worldPort),
|
||||||
_server(writePort),
|
_server(writePort),
|
||||||
_client(readPort),
|
_client(readPort),
|
||||||
_worldThread([this]() {return worldReceiveThread(this->_world); },
|
_worldThread{
|
||||||
[this](std::string &msg) { worldSendThread(this->_world, msg); },
|
[this]() { return worldReceiveThread(this->_world); },
|
||||||
[this]() {Connect(this->_world); }),
|
[this](const std::string &msg) { worldSendThread(this->_world, msg); },
|
||||||
_serverThread([this](std::string &str) { serverWorkerThread(this->_server, str); },
|
[this]() { Connect(this->_world); }},
|
||||||
[this]() {Connect(this->_server); }),
|
_serverThread{
|
||||||
_clientThread([this]() { return clientWorkerThread(this->_client); },
|
[this](const std::string &str) { serverWorkerThread(this->_server, str); },
|
||||||
[this]() {Connect(this->_client); })
|
[this]() { Connect(this->_server); }},
|
||||||
|
_clientThread{
|
||||||
|
[this]() { return clientWorkerThread(this->_client); },
|
||||||
|
[this]() { Connect(this->_client); }}
|
||||||
{
|
{
|
||||||
|
|
||||||
/*std::cout << "WorldPort: " << worldPort << std::endl;
|
/*std::cout << "WorldPort: " << worldPort << std::endl;
|
||||||
|
@ -138,5 +141,6 @@ namespace carla {
|
||||||
bool CarlaCommunication::tryReadWorldInfo(std::string &info) {
|
bool CarlaCommunication::tryReadWorldInfo(std::string &info) {
|
||||||
return _worldThread.tryPop(info);
|
return _worldThread.tryPop(info);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,13 @@
|
||||||
#include "carla/server/Protocol.h"
|
#include "carla/server/Protocol.h"
|
||||||
#include "carla/server/TCPServer.h"
|
#include "carla/server/TCPServer.h"
|
||||||
|
|
||||||
|
#include "carla/thread/AsyncReadWriteJobQueue.h"
|
||||||
#include "carla/thread/AsyncReaderJobQueue.h"
|
#include "carla/thread/AsyncReaderJobQueue.h"
|
||||||
#include "carla/thread/AsyncWriterJobQueue.h"
|
#include "carla/thread/AsyncWriterJobQueue.h"
|
||||||
#include "carla/thread/AsyncReadWriteJobQueue.h"
|
|
||||||
|
|
||||||
namespace carla {
|
namespace carla {
|
||||||
namespace server {
|
namespace server {
|
||||||
|
|
||||||
class CarlaCommunication : private NonCopyable {
|
class CarlaCommunication : private NonCopyable {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -39,7 +40,7 @@ namespace carla {
|
||||||
thread::AsyncWriterJobQueue<std::string> _clientThread;
|
thread::AsyncWriterJobQueue<std::string> _clientThread;
|
||||||
|
|
||||||
thread::AsyncReadWriteJobQueue<std::string, std::string> _worldThread;
|
thread::AsyncReadWriteJobQueue<std::string, std::string> _worldThread;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -7,7 +7,6 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace carla {
|
namespace carla {
|
||||||
|
|
||||||
namespace server {
|
namespace server {
|
||||||
|
|
||||||
// -- CarlaServer ------------------------------------------------------------
|
// -- CarlaServer ------------------------------------------------------------
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
namespace carla {
|
namespace carla {
|
||||||
namespace server {
|
namespace server {
|
||||||
|
|
||||||
|
|
||||||
struct Color {
|
struct Color {
|
||||||
char red;
|
char red;
|
||||||
char green;
|
char green;
|
||||||
|
@ -41,13 +40,14 @@ namespace server {
|
||||||
|
|
||||||
struct Scene_Values {
|
struct Scene_Values {
|
||||||
std::vector<Position> _possible_Positions;
|
std::vector<Position> _possible_Positions;
|
||||||
std::vector<const float*> _projection_Matrix;
|
std::vector<const float *> _projection_Matrix;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Mode {
|
enum Mode {
|
||||||
MONO = 0,
|
MONO = 0,
|
||||||
STEREO = 1
|
STEREO = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Asynchronous TCP server. Uses two ports, one for sending messages (write)
|
/// Asynchronous TCP server. Uses two ports, one for sending messages (write)
|
||||||
/// and one for receiving messages (read).
|
/// and one for receiving messages (read).
|
||||||
///
|
///
|
||||||
|
@ -85,27 +85,27 @@ namespace server {
|
||||||
////Try to read if the client has selected an end & start point. Return false if the queue is empty
|
////Try to read if the client has selected an end & start point. Return false if the queue is empty
|
||||||
bool tryReadEpisodeStart(float &start_index, float &end_index);
|
bool tryReadEpisodeStart(float &start_index, float &end_index);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int GetModesCount() const;
|
int GetModesCount() const;
|
||||||
|
|
||||||
int GetScenesCount() const;
|
int GetScenesCount() const;
|
||||||
|
|
||||||
void setMode(Mode mode);
|
void setMode(Mode mode);
|
||||||
|
|
||||||
Mode GetMode() const;
|
Mode GetMode() const;
|
||||||
|
|
||||||
void SetScene(int scene);
|
void SetScene(int scene);
|
||||||
|
|
||||||
int GetScene() const;
|
int GetScene() const;
|
||||||
|
|
||||||
void SetReset(bool reset);
|
void SetReset(bool reset);
|
||||||
bool Reset() const;
|
|
||||||
|
|
||||||
|
bool Reset() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
||||||
//std::mutex _mutex;
|
//std::mutex _mutex;
|
||||||
|
|
||||||
std::atomic<Mode> _mode = MONO;
|
std::atomic<Mode> _mode {MONO};
|
||||||
std::atomic_int _scene;
|
std::atomic_int _scene;
|
||||||
std::atomic_bool _reset;
|
std::atomic_bool _reset;
|
||||||
|
|
||||||
|
@ -115,7 +115,6 @@ namespace server {
|
||||||
const std::unique_ptr<CarlaCommunication> _communication;
|
const std::unique_ptr<CarlaCommunication> _communication;
|
||||||
|
|
||||||
const std::unique_ptr<Protocol> _proto;
|
const std::unique_ptr<Protocol> _proto;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace server
|
} // namespace server
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
#include "Carla.h"
|
|
||||||
#include <boost/asio.hpp>
|
|
||||||
#include <boost\bind.hpp>
|
|
||||||
|
|
||||||
namespace carla {
|
|
||||||
namespace server {
|
|
||||||
|
|
||||||
class TCPConnection : public boost::enable_shared_from_this<TCPConnection>
|
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
typedef boost::shared_ptr<TCPConnection> pointer;
|
|
||||||
|
|
||||||
static pointer create(boost::asio::io_service &io_service) {
|
|
||||||
return pointer(new TCPConnection(io_service));
|
|
||||||
}
|
|
||||||
|
|
||||||
boost::asio::ip::tcp::socket& socket() {
|
|
||||||
return socket_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Send(const std::string &message) {
|
|
||||||
message_ = message;
|
|
||||||
boost::asio::async_write(socket_, boost::asio::buffer(message_),
|
|
||||||
boost::bind(&TCPConnection::handle_write, shared_from_this()));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
TCPConnection(boost::asio::io_service& io_service)
|
|
||||||
: socket_(io_service)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void handle_write(const boost::system::error_code& /*error*/,
|
|
||||||
size_t /*bytes_transferred*/)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
std::string message_;
|
|
||||||
boost::asio::ip::tcp::socket socket_;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -13,7 +13,7 @@ namespace thread {
|
||||||
|
|
||||||
/// Executes the given job asynchronously. Every item that the job returns is
|
/// Executes the given job asynchronously. Every item that the job returns is
|
||||||
/// added to the queue.
|
/// added to the queue.
|
||||||
template <typename W, typename R>
|
template<typename W, typename R>
|
||||||
class CARLA_API AsyncReadWriteJobQueue {
|
class CARLA_API AsyncReadWriteJobQueue {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -21,7 +21,10 @@ namespace thread {
|
||||||
using ReadingJob = std::function<void(R)>;
|
using ReadingJob = std::function<void(R)>;
|
||||||
using ConnectJob = std::function<void()>;
|
using ConnectJob = std::function<void()>;
|
||||||
|
|
||||||
explicit AsyncReadWriteJobQueue(WritingJob &&writingJob, ReadingJob &&readingJob, ConnectJob &&connectJob) :
|
explicit AsyncReadWriteJobQueue(
|
||||||
|
WritingJob && writingJob,
|
||||||
|
ReadingJob && readingJob,
|
||||||
|
ConnectJob && connectJob) :
|
||||||
_done(false),
|
_done(false),
|
||||||
_writeJob(std::move(writingJob)),
|
_writeJob(std::move(writingJob)),
|
||||||
_readJob(std::move(readingJob)),
|
_readJob(std::move(readingJob)),
|
||||||
|
|
|
@ -30,7 +30,7 @@ static std::string daytimeString() {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
try {
|
try {
|
||||||
if (argc != 6) {
|
if (argc != 6) {
|
||||||
std::cerr << "Usage: server <send-port> <read-port>" << std::endl;
|
std::cerr << "Usage: server <send-port> <read-port>" << std::endl;
|
||||||
|
@ -44,7 +44,6 @@ int main(int argc, char* argv[]) {
|
||||||
|
|
||||||
// Let's simulate the game loop.
|
// Let's simulate the game loop.
|
||||||
|
|
||||||
|
|
||||||
Color c1;
|
Color c1;
|
||||||
c1.red = 255;
|
c1.red = 255;
|
||||||
c1.green = 0;
|
c1.green = 0;
|
||||||
|
@ -70,7 +69,7 @@ int main(int argc, char* argv[]) {
|
||||||
//c4.alpha = 0;
|
//c4.alpha = 0;
|
||||||
|
|
||||||
std::vector<Color> img;
|
std::vector<Color> img;
|
||||||
for (int i=0; i < 1024; ++i) img.push_back(c1);
|
for (int i = 0; i < 1024; ++i) img.push_back(c1);
|
||||||
|
|
||||||
std::vector<Color> img_2;
|
std::vector<Color> img_2;
|
||||||
for (int i = 0; i < 1024; ++i) img_2.push_back(c2);
|
for (int i = 0; i < 1024; ++i) img_2.push_back(c2);
|
||||||
|
@ -101,7 +100,6 @@ int main(int argc, char* argv[]) {
|
||||||
testData.depth_1 = depth_1;
|
testData.depth_1 = depth_1;
|
||||||
testData.depth_2 = depth_2;
|
testData.depth_2 = depth_2;
|
||||||
|
|
||||||
|
|
||||||
std::cout << "Server send World" << std::endl;
|
std::cout << "Server send World" << std::endl;
|
||||||
server.sendWorld();
|
server.sendWorld();
|
||||||
|
|
||||||
|
@ -111,16 +109,16 @@ int main(int argc, char* argv[]) {
|
||||||
std::cout << "Server wait scene init" << std::endl;
|
std::cout << "Server wait scene init" << std::endl;
|
||||||
do {
|
do {
|
||||||
end = server.tryReadSceneInit(mode, scene);
|
end = server.tryReadSceneInit(mode, scene);
|
||||||
}while (!end);
|
} while (!end);
|
||||||
|
|
||||||
std::vector<Position> positions;
|
std::vector<Position> positions;
|
||||||
std::vector<const float*> pMatrix;
|
std::vector<const float *> pMatrix;
|
||||||
|
|
||||||
positions.push_back(Position{ 0.0f, 0.0f });
|
positions.push_back(Position { 0.0f, 0.0f });
|
||||||
positions.push_back(Position{ 1.0f, 2.0f });
|
positions.push_back(Position { 1.0f, 2.0f });
|
||||||
positions.push_back(Position{ 3.0f, 4.0f });
|
positions.push_back(Position { 3.0f, 4.0f });
|
||||||
|
|
||||||
float list[16] = { 10.0, 10.0,10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0 };
|
float list[16] = { 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0 };
|
||||||
|
|
||||||
pMatrix.push_back(list);
|
pMatrix.push_back(list);
|
||||||
|
|
||||||
|
@ -141,8 +139,7 @@ int main(int argc, char* argv[]) {
|
||||||
do {
|
do {
|
||||||
|
|
||||||
end = server.tryReadEpisodeStart(startPoint, endPoint);
|
end = server.tryReadEpisodeStart(startPoint, endPoint);
|
||||||
}
|
} while (!end);
|
||||||
while (!end);
|
|
||||||
|
|
||||||
std::cout << "Server send end reset" << std::endl;
|
std::cout << "Server send end reset" << std::endl;
|
||||||
|
|
||||||
|
@ -156,22 +153,22 @@ int main(int argc, char* argv[]) {
|
||||||
std::cout << "------> RESET <------" << std::endl;
|
std::cout << "------> RESET <------" << std::endl;
|
||||||
std::cout << " --> Start: " << startPoint << " End: " << endPoint << std::endl;
|
std::cout << " --> Start: " << startPoint << " End: " << endPoint << std::endl;
|
||||||
server.sendEndReset();
|
server.sendEndReset();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
|
|
||||||
if (wait_control && server.tryReadControl(steer, gas)) {
|
if (wait_control && server.tryReadControl(steer, gas)) {
|
||||||
std::cout << "Steer: " << steer << "Gas: " << gas << std::endl;
|
std::cout << "Steer: " << steer << "Gas: " << gas << std::endl;
|
||||||
wait_control = false;
|
wait_control = false;
|
||||||
}
|
} else if (!wait_control) {
|
||||||
else if (!wait_control) {
|
|
||||||
server.sendReward(testData);
|
server.sendReward(testData);
|
||||||
wait_control = true;
|
wait_control = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Sleep(100);
|
{
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
std::this_thread::sleep_for(100ms);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
|
|
Loading…
Reference in New Issue