diff --git a/docker-compose.yml b/docker-compose.yml index 186f792..fa76e45 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,7 +25,7 @@ services: sh -c "/blah2/bin/blah2 -c config/config.yml" container_name: blah2 - blah2_frontend: + blah2_web: restart: always image: httpd:2.4 ports: @@ -40,7 +40,5 @@ services: restart: always build: ./api image: blah2_api - ports: - - 3000:8080 network_mode: host container_name: blah2-api diff --git a/src/blah2.cpp b/src/blah2.cpp index 5d91ac9..eb60364 100644 --- a/src/blah2.cpp +++ b/src/blah2.cpp @@ -61,7 +61,8 @@ int main(int argc, char **argv) // setup capture uint32_t fs, fc; - std::string type, path, replayFile; + uint16_t port_capture; + std::string type, path, replayFile, ip_capture; bool saveIq, state, loop; tree["capture"]["fs"] >> fs; tree["capture"]["fc"] >> fc; @@ -71,6 +72,8 @@ int main(int argc, char **argv) tree["capture"]["replay"]["state"] >> state; tree["capture"]["replay"]["loop"] >> loop; tree["capture"]["replay"]["file"] >> replayFile; + tree["network"]["ip"] >> ip_capture; + tree["network"]["ports"]["api"] >> port_capture; Capture *capture = new Capture(type, fs, fc, path); if (state) { @@ -85,7 +88,8 @@ int main(int argc, char **argv) // run capture std::thread t1([&]{capture->process(buffer1, buffer2, - tree["capture"]["device"]);}); + tree["capture"]["device"], ip_capture, port_capture); + }); // setup process CPI double tCpi; diff --git a/src/capture/Capture.cpp b/src/capture/Capture.cpp index cf04fa5..28338c8 100644 --- a/src/capture/Capture.cpp +++ b/src/capture/Capture.cpp @@ -19,7 +19,8 @@ Capture::Capture(std::string _type, uint32_t _fs, uint32_t _fc, std::string _pat saveIq = false; } -void Capture::process(IqData *buffer1, IqData *buffer2, c4::yml::NodeRef config) +void Capture::process(IqData *buffer1, IqData *buffer2, c4::yml::NodeRef config, + std::string ip_capture, uint16_t port_capture) { std::cout << "Setting up device " + type << std::endl; @@ -29,7 +30,8 @@ void Capture::process(IqData *buffer1, IqData *buffer2, c4::yml::NodeRef config) std::thread t1([&]{ while (true) { - httplib::Client cli("http://127.0.0.1:3000"); + httplib::Client cli("http://" + ip_capture + ":" + + std::to_string(port_capture)); httplib::Result res = cli.Get("/capture"); // if capture status changed diff --git a/src/capture/Capture.h b/src/capture/Capture.h index 760d5bf..b105b64 100644 --- a/src/capture/Capture.h +++ b/src/capture/Capture.h @@ -59,8 +59,11 @@ public: /// @param buffer1 Buffer for reference samples. /// @param buffer2 Buffer for surveillance samples. /// @param config Yaml config for device. + /// @param ip_capture IP address of capture API. + /// @param port_capture Port of capture API. /// @return Void. - void process(IqData *buffer1, IqData *buffer2, c4::yml::NodeRef config); + void process(IqData *buffer1, IqData *buffer2, c4::yml::NodeRef config, + std::string ip_capture, uint16_t port_capture); std::unique_ptr factory_source(const std::string& type, c4::yml::NodeRef config); diff --git a/src/process/utility/Socket.cpp b/src/process/utility/Socket.cpp index 4b45bbf..0c20c1d 100644 --- a/src/process/utility/Socket.cpp +++ b/src/process/utility/Socket.cpp @@ -6,7 +6,12 @@ const uint32_t Socket::MTU = 1024; Socket::Socket(const std::string& ip, uint16_t port) : endpoint(asio::ip::address::from_string(ip), port), socket(io_context) { - socket.connect(endpoint); + try { + socket.connect(endpoint); + } catch (const std::exception& e) { + std::cerr << "Error connecting to endpoint: " << e.what() << std::endl; + throw; + } } Socket::~Socket()