diff --git a/modules/camera/include/ifm3d/camera/camera.h b/modules/camera/include/ifm3d/camera/camera.h index 91cecf4b..1b67406c 100644 --- a/modules/camera/include/ifm3d/camera/camera.h +++ b/modules/camera/include/ifm3d/camera/camera.h @@ -25,6 +25,7 @@ namespace ifm3d extern IFM3D_CAMERA_EXPORT const std::string DEFAULT_IP; extern IFM3D_CAMERA_EXPORT const std::uint16_t DEFAULT_XMLRPC_PORT; extern IFM3D_CAMERA_EXPORT const int DEFAULT_PCIC_PORT; + extern IFM3D_CAMERA_EXPORT const std::uint16_t DEFAULT_NAT_PCIC_PORT; extern IFM3D_CAMERA_EXPORT const std::string DEFAULT_PASSWORD; extern IFM3D_CAMERA_EXPORT const int MAX_HEARTBEAT; extern IFM3D_CAMERA_EXPORT const std::size_t SESSION_ID_SZ; diff --git a/modules/camera/src/libifm3d_camera/camera.cpp b/modules/camera/src/libifm3d_camera/camera.cpp index a05b29c8..1732214f 100644 --- a/modules/camera/src/libifm3d_camera/camera.cpp +++ b/modules/camera/src/libifm3d_camera/camera.cpp @@ -28,6 +28,7 @@ const std::string ifm3d::DEFAULT_PASSWORD = ""; const std::uint16_t ifm3d::DEFAULT_XMLRPC_PORT = 80; const int ifm3d::DEFAULT_PCIC_PORT = 50010; +const std::uint16_t ifm3d::DEFAULT_NAT_PCIC_PORT = 0; const std::string ifm3d::DEFAULT_IP = std::getenv("IFM3D_IP") == nullptr ? "192.168.0.69" : std::string(std::getenv("IFM3D_IP")); diff --git a/modules/framegrabber/include/ifm3d/fg/frame_grabber.h b/modules/framegrabber/include/ifm3d/fg/frame_grabber.h index 22c55915..0b9e8724 100644 --- a/modules/framegrabber/include/ifm3d/fg/frame_grabber.h +++ b/modules/framegrabber/include/ifm3d/fg/frame_grabber.h @@ -32,9 +32,14 @@ namespace ifm3d * @param[in] cam The camera instance to grab frames from * @param[in] mask A bitmask encoding the image acquisition schema * to stream in from the camera. + * @param[in] nat_pcic_port Port for devices behind NAT router, + * user must provide this value according to there + * NAT router configuration. */ - FrameGrabber(ifm3d::Camera::Ptr cam, - std::uint16_t mask = ifm3d::DEFAULT_SCHEMA_MASK); + FrameGrabber( + ifm3d::Camera::Ptr cam, + std::uint16_t mask = ifm3d::DEFAULT_SCHEMA_MASK, + const std::uint16_t nat_pcic_port = ifm3d::DEFAULT_NAT_PCIC_PORT); /** * Cleans up resources held by the framegrabbing thread object and blocks diff --git a/modules/framegrabber/src/libifm3d_framegrabber/frame_grabber.cpp b/modules/framegrabber/src/libifm3d_framegrabber/frame_grabber.cpp index 53d0873f..2e6abfbd 100644 --- a/modules/framegrabber/src/libifm3d_framegrabber/frame_grabber.cpp +++ b/modules/framegrabber/src/libifm3d_framegrabber/frame_grabber.cpp @@ -13,8 +13,10 @@ #include #include -ifm3d::FrameGrabber::FrameGrabber(ifm3d::Camera::Ptr cam, std::uint16_t mask) - : pImpl(new ifm3d::FrameGrabber::Impl(cam, mask)) +ifm3d::FrameGrabber::FrameGrabber(ifm3d::Camera::Ptr cam, + std::uint16_t mask, + const std::uint16_t nat_pcic_port) + : pImpl(new ifm3d::FrameGrabber::Impl(cam, mask, nat_pcic_port)) { } ifm3d::FrameGrabber::~FrameGrabber() = default; diff --git a/modules/framegrabber/src/libifm3d_framegrabber/frame_grabber_impl.hpp b/modules/framegrabber/src/libifm3d_framegrabber/frame_grabber_impl.hpp index c0c2cae9..7d0984b6 100644 --- a/modules/framegrabber/src/libifm3d_framegrabber/frame_grabber_impl.hpp +++ b/modules/framegrabber/src/libifm3d_framegrabber/frame_grabber_impl.hpp @@ -46,7 +46,9 @@ namespace ifm3d class FrameGrabber::Impl { public: - Impl(ifm3d::Camera::Ptr cam, std::uint16_t mask); + Impl(ifm3d::Camera::Ptr cam, + std::uint16_t mask, + const std::uint16_t& nat_pcic_port); ~Impl(); virtual void SWTrigger(); @@ -133,11 +135,15 @@ namespace ifm3d //------------------------------------- // ctor/dtor //------------------------------------- -ifm3d::FrameGrabber::Impl::Impl(ifm3d::Camera::Ptr cam, std::uint16_t mask) +ifm3d::FrameGrabber::Impl::Impl(ifm3d::Camera::Ptr cam, + std::uint16_t mask, + const std::uint16_t& nat_pcic_port) : cam_(cam), mask_(mask), cam_ip_(this->cam_->IP()), - cam_port_(ifm3d::DEFAULT_PCIC_PORT), + cam_port_(nat_pcic_port == ifm3d::DEFAULT_NAT_PCIC_PORT ? + ifm3d::DEFAULT_PCIC_PORT : + nat_pcic_port), io_service_(), sock_(io_service_), pcic_ready_(false) @@ -151,8 +157,11 @@ ifm3d::FrameGrabber::Impl::Impl(ifm3d::Camera::Ptr cam, std::uint16_t mask) try { this->cam_ip_ = this->cam_->IP(); - this->cam_port_ = - std::stoi(this->cam_->DeviceParameter("PcicTcpPort")); + if (cam_port_ != nat_pcic_port) + { + this->cam_port_ = + std::stoi(this->cam_->DeviceParameter("PcicTcpPort")); + } } catch (const ifm3d::error_t& ex) { diff --git a/modules/pcicclient/include/ifm3d/pcicclient/pcicclient.h b/modules/pcicclient/include/ifm3d/pcicclient/pcicclient.h index 4ce2be3e..92c543dd 100644 --- a/modules/pcicclient/include/ifm3d/pcicclient/pcicclient.h +++ b/modules/pcicclient/include/ifm3d/pcicclient/pcicclient.h @@ -32,8 +32,11 @@ namespace ifm3d * thread * * @param[in] cam The camera instance to grab frames from + * @param[in] nat_pcic_port pcic port for NAT configuartion */ - PCICClient(ifm3d::Camera::Ptr cam); + PCICClient( + ifm3d::Camera::Ptr cam, + const std::uint16_t nat_pcic_port = ifm3d::DEFAULT_NAT_PCIC_PORT); /** * Cleans up any resources held by the receive thread object and diff --git a/modules/pcicclient/src/libifm3d_pcicclient/pcicclient.cpp b/modules/pcicclient/src/libifm3d_pcicclient/pcicclient.cpp index b1e44447..21c5fe9b 100644 --- a/modules/pcicclient/src/libifm3d_pcicclient/pcicclient.cpp +++ b/modules/pcicclient/src/libifm3d_pcicclient/pcicclient.cpp @@ -12,8 +12,9 @@ #include #include -ifm3d::PCICClient::PCICClient(ifm3d::Camera::Ptr cam) - : pImpl(new ifm3d::PCICClient::Impl(cam)) +ifm3d::PCICClient::PCICClient(ifm3d::Camera::Ptr cam, + const std::uint16_t nat_pcic_port) + : pImpl(new ifm3d::PCICClient::Impl(cam, nat_pcic_port)) { } ifm3d::PCICClient::~PCICClient() = default; diff --git a/modules/pcicclient/src/libifm3d_pcicclient/pcicclient_impl.hpp b/modules/pcicclient/src/libifm3d_pcicclient/pcicclient_impl.hpp index d3c403d2..ca39bb42 100644 --- a/modules/pcicclient/src/libifm3d_pcicclient/pcicclient_impl.hpp +++ b/modules/pcicclient/src/libifm3d_pcicclient/pcicclient_impl.hpp @@ -43,7 +43,7 @@ namespace ifm3d class PCICClient::Impl { public: - Impl(ifm3d::Camera::Ptr cam); + Impl(ifm3d::Camera::Ptr cam, const std::uint16_t& nat_pcic_port); ~Impl(); /** @@ -404,7 +404,8 @@ const std::string ifm3d::PCICClient::Impl::init_command = //------------------------------------- // ctor/dtor //------------------------------------- -ifm3d::PCICClient::Impl::Impl(ifm3d::Camera::Ptr cam) +ifm3d::PCICClient::Impl::Impl(ifm3d::Camera::Ptr cam, + const std::uint16_t& nat_pcic_port) : cam_(cam), connected_(false), io_service_(), @@ -419,7 +420,15 @@ ifm3d::PCICClient::Impl::Impl(ifm3d::Camera::Ptr cam) try { this->cam_ip_ = this->cam_->IP(); - this->cam_port_ = std::stoi(this->cam_->DeviceParameter("PcicTcpPort")); + if (nat_pcic_port == ifm3d::DEFAULT_NAT_PCIC_PORT) + { + this->cam_port_ = nat_pcic_port; + } + else + { + this->cam_port_ = + std::stoi(this->cam_->DeviceParameter("PcicTcpPort")); + } } catch (const ifm3d::error_t& ex) { diff --git a/modules/swupdater/include/ifm3d/swupdater/swupdater.h b/modules/swupdater/include/ifm3d/swupdater/swupdater.h index 0289e2ae..2ee65c96 100644 --- a/modules/swupdater/include/ifm3d/swupdater/swupdater.h +++ b/modules/swupdater/include/ifm3d/swupdater/swupdater.h @@ -9,9 +9,13 @@ #include #include #include +#include namespace ifm3d { + /* const for the swupdate recovery port value */ + extern IFM3D_SWUPDATER_EXPORT const std::uint16_t SWUPDATER_RECOVERY_PORT; + class SWUpdater { public: @@ -34,9 +38,13 @@ namespace ifm3d * @param cam Camera object to manipulate * * @param cb Opitonal user-defined callback to handle status updates + * + * @param swupdate_recovery_port swupate recovery port for the device */ SWUpdater(ifm3d::Camera::Ptr cam, - const ifm3d::SWUpdater::FlashStatusCb& cb = {}); + const ifm3d::SWUpdater::FlashStatusCb& cb = {}, + const std::uint16_t swupdate_recovery_port = + ifm3d::SWUPDATER_RECOVERY_PORT); virtual ~SWUpdater(); diff --git a/modules/swupdater/src/libifm3d_swupdater/swupdater.cpp b/modules/swupdater/src/libifm3d_swupdater/swupdater.cpp index 0ddf6770..a379bc34 100644 --- a/modules/swupdater/src/libifm3d_swupdater/swupdater.cpp +++ b/modules/swupdater/src/libifm3d_swupdater/swupdater.cpp @@ -9,9 +9,14 @@ #include #include +const std::uint16_t ifm3d::SWUPDATER_RECOVERY_PORT = 8080; + ifm3d::SWUpdater::SWUpdater(ifm3d::Camera::Ptr cam, - const ifm3d::SWUpdater::FlashStatusCb& cb) - : pImpl(new ifm3d::SWUpdater::Impl(cam, cb)) + const ifm3d::SWUpdater::FlashStatusCb& cb, + const std::uint16_t swupdate_recovery_port) + : pImpl(new ifm3d::SWUpdater::Impl(cam, + cb, + std::to_string(swupdate_recovery_port))) { } ifm3d::SWUpdater::~SWUpdater() = default; diff --git a/modules/swupdater/src/libifm3d_swupdater/swupdater_impl.hpp b/modules/swupdater/src/libifm3d_swupdater/swupdater_impl.hpp index 1624ef26..ad0b45c8 100644 --- a/modules/swupdater/src/libifm3d_swupdater/swupdater_impl.hpp +++ b/modules/swupdater/src/libifm3d_swupdater/swupdater_impl.hpp @@ -24,7 +24,6 @@ namespace ifm3d const std::string SWUPDATER_REBOOT_URL_SUFFIX = "/reboot_to_live"; const std::string SWUPDATER_STATUS_URL_SUFFIX = "/getstatus.json"; const std::string SWUPDATER_CHECK_RECOVERY_URL_SUFFIX = "/id.lp"; - const std::string SWUPDATER_RECOVERY_PORT = "8080"; const std::string SWUPDATER_FILENAME_HEADER = "X_FILENAME: swupdate.swu"; const std::string SWUPDATER_CONTENT_TYPE_HEADER = "Content-Type: application/octet-stream"; @@ -45,7 +44,9 @@ namespace ifm3d class SWUpdater::Impl { public: - Impl(ifm3d::Camera::Ptr cam, const ifm3d::SWUpdater::FlashStatusCb& cb); + Impl(ifm3d::Camera::Ptr cam, + const ifm3d::SWUpdater::FlashStatusCb& cb, + const std::string& swupdate_recovery_port); ~Impl() = default; void RebootToRecovery(); @@ -218,16 +219,17 @@ namespace ifm3d // ctor //------------------------------------- ifm3d::SWUpdater::Impl::Impl(ifm3d::Camera::Ptr cam, - const ifm3d::SWUpdater::FlashStatusCb& cb) + const ifm3d::SWUpdater::FlashStatusCb& cb, + const std::string& swupdate_recovery_port) : cam_(cam), cb_(cb), - upload_url_("http://" + cam->IP() + ":" + SWUPDATER_RECOVERY_PORT + + upload_url_("http://" + cam->IP() + ":" + swupdate_recovery_port + SWUPDATER_UPLOAD_URL_SUFFIX), - reboot_url_("http://" + cam->IP() + ":" + SWUPDATER_RECOVERY_PORT + + reboot_url_("http://" + cam->IP() + ":" + swupdate_recovery_port + SWUPDATER_REBOOT_URL_SUFFIX), - status_url_("http://" + cam->IP() + ":" + SWUPDATER_RECOVERY_PORT + + status_url_("http://" + cam->IP() + ":" + swupdate_recovery_port + SWUPDATER_STATUS_URL_SUFFIX), - check_recovery_url_("http://" + cam->IP() + ":" + SWUPDATER_RECOVERY_PORT + + check_recovery_url_("http://" + cam->IP() + ":" + swupdate_recovery_port + SWUPDATER_CHECK_RECOVERY_URL_SUFFIX) { } diff --git a/modules/tools/src/libifm3d_tools/swupdater/swupdate_app.cpp b/modules/tools/src/libifm3d_tools/swupdater/swupdate_app.cpp index 32c8a313..7ab5df59 100644 --- a/modules/tools/src/libifm3d_tools/swupdater/swupdate_app.cpp +++ b/modules/tools/src/libifm3d_tools/swupdater/swupdate_app.cpp @@ -34,7 +34,9 @@ ifm3d::SWUpdateApp::SWUpdateApp(int argc, ("r,reboot","Reboot from recovery mode to productive mode", cxxopts::value()->default_value("false")) ("q,quiet","Disable status output", - cxxopts::value()->default_value("false")); + cxxopts::value()->default_value("false")) + ("swupdate-port","port for swupdate", + cxxopts::value()->default_value("8080")); // clang-format on this->_Parse(argc, argv); @@ -52,11 +54,16 @@ ifm3d::SWUpdateApp::Run() auto const check = (*this->vm_)["check"].as(); auto const recovery_reboot = (*this->vm_)["reboot"].as(); auto const quiet = (*this->vm_)["quiet"].as(); + auto const swupdate_port = + (*this->vm_)["swupdate-port"].as(); ifm3d::SWUpdater::Ptr swupdater; if (quiet) { - swupdater = std::make_shared(this->cam_); + swupdater = std::make_shared( + this->cam_, + [](float p, const std::string& msg) -> void {}, + swupdate_port); } else { @@ -90,7 +97,8 @@ ifm3d::SWUpdateApp::Run() { std::cout << msg << std::endl; } - }); + }, + swupdate_port); } if (check)