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
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -48,6 +47,7 @@ namespace server {
|
||||||
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_;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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)),
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -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();
|
||||||
|
|
||||||
|
@ -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