Skip to content

Commit 48f4ae8

Browse files
committed
[centralsystem] Add interfaces to get the IP address of a connected Charge Point
1 parent edb760e commit 48f4ae8

File tree

8 files changed

+55
-3
lines changed

8 files changed

+55
-3
lines changed

src/centralsystem/chargepoint/ChargePointProxy.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ ChargePointProxy::~ChargePointProxy() { }
7777

7878
// ICentralSystem::IChargePoint interface
7979

80+
/** @copydoc const std::string& ICentralSystem::IChargePoint::ipAddress() const */
81+
const std::string& ChargePointProxy::ipAddress() const
82+
{
83+
return m_rpc->ipAddress();
84+
}
85+
8086
/** @copydoc void ICentralSystem::IChargePoint::setTimeout(std::chrono::milliseconds) */
8187
void ChargePointProxy::setTimeout(std::chrono::milliseconds timeout)
8288
{

src/centralsystem/chargepoint/ChargePointProxy.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ class ChargePointProxy : public ICentralSystem::IChargePoint, public ocpp::rpc::
5959
/** @copydoc ICentralSystem&& ICentralSystem::IChargePoint::centralSystem() */
6060
ICentralSystem& centralSystem() override { return m_central_system; }
6161

62+
/** @copydoc const std::string& ICentralSystem::IChargePoint::ipAddress() const */
63+
const std::string& ipAddress() const override;
64+
6265
/** @copydoc const std::string& ICentralSystem::IChargePoint::identifier() const */
6366
const std::string& identifier() const override { return m_identifier; }
6467

src/centralsystem/interface/ICentralSystem.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ class ICentralSystem
125125
*/
126126
virtual ICentralSystem& centralSystem() = 0;
127127

128+
/**
129+
* @brief Get the IP address of the charge point
130+
* @return IP address of the charge point
131+
*/
132+
virtual const std::string& ipAddress() const = 0;
133+
128134
/**
129135
* @brief Get the charge point identifier
130136
* @return charge point identifier

src/rpc/RpcServer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ RpcServer::Client::~Client()
133133
RpcBase::stop();
134134
}
135135

136+
/** @brief Get the IP address of the client */
137+
const std::string& RpcServer::Client::ipAddress() const
138+
{
139+
return m_websocket->ipAddress();
140+
}
141+
136142
/** @brief Disconnect the client */
137143
bool RpcServer::Client::disconnect(bool notify_disconnected)
138144
{

src/rpc/RpcServer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ class RpcServer : public ocpp::websockets::IWebsocketServer::IListener
111111
/** @brief Destructor */
112112
virtual ~Client();
113113

114+
/**
115+
* @brief Get the IP address of the client
116+
* @return IP address of the client
117+
*/
118+
const std::string& ipAddress() const;
119+
114120
/**
115121
* @brief Disconnect the client
116122
* @param notify_disconnected Indicate if the listener must be notified when disconnected

src/websockets/IWebsocketServer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ class IWebsocketServer
102102
/** @brief Destructor */
103103
virtual ~IClient() { }
104104

105+
/**
106+
* @brief Get the IP address of the client
107+
* @return IP address of the client
108+
*/
109+
virtual const std::string& ipAddress() const = 0;
110+
105111
/**
106112
* @brief Disconnect the client
107113
* @param notify_disconnected Indicate if the listener must be notified owhen disconnected

src/websockets/libwebsockets/LibWebsocketServer.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,12 @@ int LibWebsocketServer::eventCallback(struct lws* wsi, enum lws_callback_reasons
365365

366366
case LWS_CALLBACK_ESTABLISHED:
367367
{
368+
// Get client IP address
369+
char ip_address[64];
370+
lws_get_peer_simple(wsi, ip_address, sizeof(ip_address));
371+
368372
// Instanciate a new client
369-
std::shared_ptr<IClient> client(new Client(wsi));
373+
std::shared_ptr<IClient> client(new Client(wsi, ip_address));
370374
server->m_clients[wsi] = client;
371375

372376
// Notify connection
@@ -465,13 +469,22 @@ int LibWebsocketServer::eventCallback(struct lws* wsi, enum lws_callback_reasons
465469
}
466470

467471
/** @brief Constructor */
468-
LibWebsocketServer::Client::Client(struct lws* wsi) : m_wsi(wsi), m_connected(true), m_listener(nullptr), m_send_msgs() { }
472+
LibWebsocketServer::Client::Client(struct lws* wsi, const char* ip_address)
473+
: m_wsi(wsi), m_ip_address(ip_address), m_connected(true), m_listener(nullptr), m_send_msgs()
474+
{
475+
}
469476
/** @brief Destructor */
470477
LibWebsocketServer::Client::~Client()
471478
{
472479
disconnect(true);
473480
}
474481

482+
/** @copydoc const std::string& IClient::ipAddress(bool) const */
483+
const std::string& LibWebsocketServer::Client::ipAddress() const
484+
{
485+
return m_ip_address;
486+
}
487+
475488
/** @copydoc bool IClient::disconnect(bool) */
476489
bool LibWebsocketServer::Client::disconnect(bool notify_disconnected)
477490
{

src/websockets/libwebsockets/LibWebsocketServer.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,15 @@ class LibWebsocketServer : public IWebsocketServer
8989
/**
9090
* @brief Constructor
9191
* @param wsi Client socket
92+
* @param ip_address IP address
9293
*/
93-
Client(struct lws* wsi);
94+
Client(struct lws* wsi, const char* ip_address);
9495
/** @brief Destructor */
9596
virtual ~Client();
9697

98+
/** @copydoc const std::string& IClient::ipAddress(bool) const */
99+
const std::string& ipAddress() const override;
100+
97101
/** @copydoc bool IClient::disconnect(bool) */
98102
bool disconnect(bool notify_disconnected) override;
99103

@@ -109,6 +113,8 @@ class LibWebsocketServer : public IWebsocketServer
109113
private:
110114
/** @brief Client socket */
111115
struct lws* m_wsi;
116+
/** @brief IP address */
117+
const std::string m_ip_address;
112118
/** @brief Connection status */
113119
bool m_connected;
114120
/** @brief Listener */

0 commit comments

Comments
 (0)