Skip to content

Commit

Permalink
Added support for NAT, resolved #69
Browse files Browse the repository at this point in the history
  • Loading branch information
inbangsa authored and graugans committed Nov 27, 2020
1 parent 8f74f15 commit 18ee04d
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 28 deletions.
1 change: 1 addition & 0 deletions modules/camera/include/ifm3d/camera/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions modules/camera/src/libifm3d_camera/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
9 changes: 7 additions & 2 deletions modules/framegrabber/include/ifm3d/fg/frame_grabber.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
#include <ifm3d/camera/err.h>
#include <frame_grabber_impl.hpp>

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)
Expand All @@ -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)
{
Expand Down
5 changes: 4 additions & 1 deletion modules/pcicclient/include/ifm3d/pcicclient/pcicclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions modules/pcicclient/src/libifm3d_pcicclient/pcicclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
#include <ifm3d/camera/err.h>
#include <pcicclient_impl.hpp>

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;
Expand Down
15 changes: 12 additions & 3 deletions modules/pcicclient/src/libifm3d_pcicclient/pcicclient_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

/**
Expand Down Expand Up @@ -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_(),
Expand All @@ -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)
{
Expand Down
10 changes: 9 additions & 1 deletion modules/swupdater/include/ifm3d/swupdater/swupdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
#include <memory>
#include <vector>
#include <ifm3d/camera/camera.h>
#include <ifm3d/swupdater/swupdater_export.h>

namespace ifm3d
{
/* const for the swupdate recovery port value */
extern IFM3D_SWUPDATER_EXPORT const std::uint16_t SWUPDATER_RECOVERY_PORT;

class SWUpdater
{
public:
Expand All @@ -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();

Expand Down
9 changes: 7 additions & 2 deletions modules/swupdater/src/libifm3d_swupdater/swupdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@
#include <ifm3d/camera/err.h>
#include <swupdater_impl.hpp>

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;
Expand Down
16 changes: 9 additions & 7 deletions modules/swupdater/src/libifm3d_swupdater/swupdater_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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();
Expand Down Expand Up @@ -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)
{ }

Expand Down
14 changes: 11 additions & 3 deletions modules/tools/src/libifm3d_tools/swupdater/swupdate_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ ifm3d::SWUpdateApp::SWUpdateApp(int argc,
("r,reboot","Reboot from recovery mode to productive mode",
cxxopts::value<bool>()->default_value("false"))
("q,quiet","Disable status output",
cxxopts::value<bool>()->default_value("false"));
cxxopts::value<bool>()->default_value("false"))
("swupdate-port","port for swupdate",
cxxopts::value<unsigned short>()->default_value("8080"));

// clang-format on
this->_Parse(argc, argv);
Expand All @@ -52,11 +54,16 @@ ifm3d::SWUpdateApp::Run()
auto const check = (*this->vm_)["check"].as<bool>();
auto const recovery_reboot = (*this->vm_)["reboot"].as<bool>();
auto const quiet = (*this->vm_)["quiet"].as<bool>();
auto const swupdate_port =
(*this->vm_)["swupdate-port"].as<unsigned short>();

ifm3d::SWUpdater::Ptr swupdater;
if (quiet)
{
swupdater = std::make_shared<ifm3d::SWUpdater>(this->cam_);
swupdater = std::make_shared<ifm3d::SWUpdater>(
this->cam_,
[](float p, const std::string& msg) -> void {},
swupdate_port);
}
else
{
Expand Down Expand Up @@ -90,7 +97,8 @@ ifm3d::SWUpdateApp::Run()
{
std::cout << msg << std::endl;
}
});
},
swupdate_port);
}

if (check)
Expand Down

0 comments on commit 18ee04d

Please sign in to comment.