Beckhoff / ADS

Beckhoff protocol to communicate with TwinCAT devices.
MIT License
513 stars 194 forks source link

Sockets: LOG_INFO Connected to #48

Closed tboegi closed 7 years ago

tboegi commented 7 years ago

When connecting to the ADS system in Sockets.cpp there is a LOG_INFO giving "Info: Connecting to 192.168.1.2" When the connection fails, there is a LOG_ERROR.

When the connection succeeds, there is no printout, leaving the user in a state of user in a state of uncertainty. Add a LOG_INFO that show the successful connection like this: "Info: Connected to 192.168.1.2"

pbruenn commented 7 years ago

Thanks for your patch. I'd like to modify it a little:

index 818459e..9d00762 100644
--- a/AdsLib/Sockets.cpp
+++ b/AdsLib/Sockets.cpp
@@ -190,8 +190,6 @@ TcpSocket::TcpSocket(const IpV4 ip, const uint16_t port)
 uint32_t TcpSocket::Connect() const
 {
     const uint32_t addr = ntohl(m_SockAddress.sin_addr.s_addr);
-    LOG_INFO("Connecting to " << ((addr & 0xff000000) >> 24) << '.' << ((addr & 0xff0000) >> 16) << '.' <<
-             ((addr & 0xff00) >> 8) << '.' << (addr & 0xff));

     if (::connect(m_Socket, reinterpret_cast<const sockaddr*>(&m_SockAddress), sizeof(m_SockAddress))) {
         LOG_ERROR("Connect TCP socket failed with: " << WSAGetLastError());
@@ -205,6 +203,9 @@ uint32_t TcpSocket::Connect() const
         LOG_ERROR("Read local tcp/ip address failed");
         return 0;
     }
+    LOG_INFO("Connected to " << ((addr & 0xff000000) >> 24) << '.' << ((addr & 0xff0000) >> 16) << '.' <<
+             ((addr & 0xff00) >> 8) << '.' << (addr & 0xff));
+
     return ntohl(source.sin_addr.s_addr);
 }

Is it okay for you, if I merge that modified version under your name and with your commit message?

Regards, Patrick

tboegi commented 7 years ago

I'm OK with your version. The commit message needs to be updated as well, I think

pbruenn commented 7 years ago

merged with commit e75f064391f4f32a80199e08a18bed7655a14b07