Remove %NODE_NAME% from variable names
This commit is contained in:
parent
7574cf9dd0
commit
ec17a10562
5 changed files with 74 additions and 74 deletions
|
@ -30,8 +30,8 @@ void OnTcpReceive(dword socket, long result, dword address, dword port, byte buf
|
||||||
{
|
{
|
||||||
// Size of zero indicates that the socket was closed by the communication peer.
|
// Size of zero indicates that the socket was closed by the communication peer.
|
||||||
writeLineEx(0, 2, "<%NODE_NAME%> OnTcpReceive: Socket closed by peer");
|
writeLineEx(0, 2, "<%NODE_NAME%> OnTcpReceive: Socket closed by peer");
|
||||||
g_%NODE_NAME%_Socket.Close();
|
gSocket.Close();
|
||||||
g_%NODE_NAME%_SocketState = CLOSED;
|
gSocketState = CLOSED;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -42,10 +42,10 @@ void OnTcpReceive(dword socket, long result, dword address, dword port, byte buf
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gIpLastErr = g_%NODE_NAME%_Socket.GetLastSocketError();
|
gIpLastErr = gSocket.GetLastSocketError();
|
||||||
g_%NODE_NAME%_Socket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
|
gSocket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
|
||||||
writeLineEx(0, 2, "<%NODE_NAME%> OnTcpReceive error (%d): %s", gIpLastErr, gIpLastErrStr);
|
writeLineEx(0, 2, "<%NODE_NAME%> OnTcpReceive error (%d): %s", gIpLastErr, gIpLastErrStr);
|
||||||
g_%NODE_NAME%_Socket.Close();
|
gSocket.Close();
|
||||||
g_%NODE_NAME%_SocketState = CLOSED;
|
gSocketState = CLOSED;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -30,8 +30,8 @@ void OnUdpReceiveFrom(dword socket, long result, dword address, dword port, byte
|
||||||
{
|
{
|
||||||
// Size of zero indicates that the socket was closed by the communication peer.
|
// Size of zero indicates that the socket was closed by the communication peer.
|
||||||
writeLineEx(0, 2, "<%BASE_FILE_NAME%> OnTcpReceive: Socket closed by peer");
|
writeLineEx(0, 2, "<%BASE_FILE_NAME%> OnTcpReceive: Socket closed by peer");
|
||||||
g_%NODE_NAME%_Socket.Close();
|
gSocket.Close();
|
||||||
g_%NODE_NAME%_SocketState = CLOSED;
|
gSocketState = CLOSED;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -42,10 +42,10 @@ void OnUdpReceiveFrom(dword socket, long result, dword address, dword port, byte
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gIpLastErr = g_%NODE_NAME%_Socket.GetLastSocketError();
|
gIpLastErr = gSocket.GetLastSocketError();
|
||||||
g_%NODE_NAME%_Socket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
|
gSocket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
|
||||||
writeLineEx(0, 2, "<%BASE_FILE_NAME%> OnTcpReceive error (%d): %s", gIpLastErr, gIpLastErrStr);
|
writeLineEx(0, 2, "<%BASE_FILE_NAME%> OnTcpReceive error (%d): %s", gIpLastErr, gIpLastErrStr);
|
||||||
g_%NODE_NAME%_Socket.Close();
|
gSocket.Close();
|
||||||
g_%NODE_NAME%_SocketState = CLOSED;
|
gSocketState = CLOSED;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -7,7 +7,7 @@ includes
|
||||||
|
|
||||||
variables
|
variables
|
||||||
{
|
{
|
||||||
TcpSocket g_%NODE_NAME%_Socket;
|
TcpSocket gSocket;
|
||||||
|
|
||||||
byte gRxBuffer[8192];
|
byte gRxBuffer[8192];
|
||||||
}
|
}
|
||||||
|
@ -30,19 +30,19 @@ word TcpOpenSocket()
|
||||||
// Try to open socket
|
// Try to open socket
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
g_%NODE_NAME%_Socket = TcpSocket::Open(localIp, localPort);
|
gSocket = TcpSocket::Open(localIp, localPort);
|
||||||
if (g_%NODE_NAME%_Socket.GetLastSocketError() != 0)
|
if (gSocket.GetLastSocketError() != 0)
|
||||||
{
|
{
|
||||||
g_%NODE_NAME%_Socket.GetLastSocketErrorAsString(errorText, elcount(errorText));
|
gSocket.GetLastSocketErrorAsString(errorText, elcount(errorText));
|
||||||
writeLineEx(0, 1, "<%NODE_NAME%> Error: could not open Tcp socket on %s:%d, %s (%d)!", Local_IP, localPort, errorText, g_%NODE_NAME%_Socket.GetLastSocketError());
|
writeLineEx(0, 1, "<%NODE_NAME%> Error: could not open Tcp socket on %s:%d, %s (%d)!", Local_IP, localPort, errorText, gSocket.GetLastSocketError());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (g_%NODE_NAME%_Socket.GetLastSocketError() != 0 && i++ < 9);
|
while (gSocket.GetLastSocketError() != 0 && i++ < 9);
|
||||||
|
|
||||||
if (g_%NODE_NAME%_Socket.GetLastSocketError() != 0)
|
if (gSocket.GetLastSocketError() != 0)
|
||||||
{
|
{
|
||||||
writeLineEx(0, 1, "<%NODE_NAME%> Error: could not open Tcp socket!");
|
writeLineEx(0, 1, "<%NODE_NAME%> Error: could not open Tcp socket!");
|
||||||
return g_%NODE_NAME%_Socket.GetLastSocketError();
|
return gSocket.GetLastSocketError();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -76,23 +76,23 @@ word TcpConnectTo(dword remoteIp, word remotePort)
|
||||||
fehler = TcpOpenSocket();
|
fehler = TcpOpenSocket();
|
||||||
if (fehler != 0)
|
if (fehler != 0)
|
||||||
{
|
{
|
||||||
g_%NODE_NAME%_SocketState = ERROR;
|
gSocketState = ERROR;
|
||||||
return fehler;
|
return fehler;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_%NODE_NAME%_RemoteIP = remoteIp;
|
gRemoteIP = remoteIp;
|
||||||
g_%NODE_NAME%_RemotePort = remotePort;
|
gRemotePort = remotePort;
|
||||||
|
|
||||||
|
|
||||||
// Connect to Server
|
// Connect to Server
|
||||||
if (g_%NODE_NAME%_Socket.Connect(remoteIp, remotePort) != 0)
|
if (gSocket.Connect(remoteIp, remotePort) != 0)
|
||||||
{
|
{
|
||||||
fehler = g_%NODE_NAME%_Socket.GetLastSocketError();
|
fehler = gSocket.GetLastSocketError();
|
||||||
|
|
||||||
if (fehler != WSAEWOULDBLOCK) // OnTcpConnect will be called otherwise
|
if (fehler != WSAEWOULDBLOCK) // OnTcpConnect will be called otherwise
|
||||||
{
|
{
|
||||||
write("<%NODE_NAME%> No Port-Connection: %d", fehler);
|
write("<%NODE_NAME%> No Port-Connection: %d", fehler);
|
||||||
g_%NODE_NAME%_SocketState = ERROR;
|
gSocketState = ERROR;
|
||||||
return fehler;
|
return fehler;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -100,7 +100,7 @@ word TcpConnectTo(dword remoteIp, word remotePort)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
writeLineEx(0, 1, "<%NODE_NAME%> Successfully connected to server");
|
writeLineEx(0, 1, "<%NODE_NAME%> Successfully connected to server");
|
||||||
g_%NODE_NAME%_SocketState = OK;
|
gSocketState = OK;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,15 +109,15 @@ void OnTcpConnect(dword socket, long result)
|
||||||
{
|
{
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
{
|
{
|
||||||
g_%NODE_NAME%_Socket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
|
gSocket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
|
||||||
writeLineEx(0, 2, "<%NODE_NAME%> OnTcpConnect error (%d): %s", g_%NODE_NAME%_Socket.GetLastSocketError(), gIpLastErrStr);
|
writeLineEx(0, 2, "<%NODE_NAME%> OnTcpConnect error (%d): %s", gSocket.GetLastSocketError(), gIpLastErrStr);
|
||||||
g_%NODE_NAME%_SocketState = ERROR;
|
gSocketState = ERROR;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
writeLineEx(0, 1, "<%NODE_NAME%> Successfully connected to server");
|
writeLineEx(0, 1, "<%NODE_NAME%> Successfully connected to server");
|
||||||
g_%NODE_NAME%_SocketState = OK;
|
gSocketState = OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,24 +125,24 @@ void TcpRecv()
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
if (g_%NODE_NAME%_SocketState != OK)
|
if (gSocketState != OK)
|
||||||
{
|
{
|
||||||
writeLineEx(0, 2, "TcpRecv: Socket status is not OK!");
|
writeLineEx(0, 2, "TcpRecv: Socket status is not OK!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = g_%NODE_NAME%_Socket.Receive(gRxBuffer, elcount(gRxBuffer));
|
result = gSocket.Receive(gRxBuffer, elcount(gRxBuffer));
|
||||||
|
|
||||||
if (result != 0) // Calling OnTcpReceive otherwise
|
if (result != 0) // Calling OnTcpReceive otherwise
|
||||||
{
|
{
|
||||||
gIpLastErr = g_%NODE_NAME%_Socket.GetLastSocketError();
|
gIpLastErr = gSocket.GetLastSocketError();
|
||||||
|
|
||||||
if (gIpLastErr != WSA_IO_PENDING) // Calling OnTcpReceive otherwise
|
if (gIpLastErr != WSA_IO_PENDING) // Calling OnTcpReceive otherwise
|
||||||
{
|
{
|
||||||
g_%NODE_NAME%_Socket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
|
gSocket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
|
||||||
writeLineEx(0, 2, "<%NODE_NAME%> TcpReceive error (%d): %s", gIpLastErr, gIpLastErrStr);
|
writeLineEx(0, 2, "<%NODE_NAME%> TcpReceive error (%d): %s", gIpLastErr, gIpLastErrStr);
|
||||||
g_%NODE_NAME%_Socket.Close();
|
gSocket.Close();
|
||||||
g_%NODE_NAME%_SocketState = CLOSED;
|
gSocketState = CLOSED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,11 +153,11 @@ void TcpSnd(byte buffer[])
|
||||||
{
|
{
|
||||||
char str[20*3];
|
char str[20*3];
|
||||||
|
|
||||||
switch (g_%NODE_NAME%_SocketState)
|
switch (gSocketState)
|
||||||
{
|
{
|
||||||
case CLOSED:
|
case CLOSED:
|
||||||
TcpConnectTo(g_%NODE_NAME%_RemoteIP, g_%NODE_NAME%_RemotePort);
|
TcpConnectTo(gRemoteIP, gRemotePort);
|
||||||
if (g_%NODE_NAME%_SocketState != OK)
|
if (gSocketState != OK)
|
||||||
{
|
{
|
||||||
writeLineEx(0, 2, "TcpSnd: Reconnecting failed!");
|
writeLineEx(0, 2, "TcpSnd: Reconnecting failed!");
|
||||||
return;
|
return;
|
||||||
|
@ -172,16 +172,16 @@ void TcpSnd(byte buffer[])
|
||||||
bin_to_strhex(buffer, str);
|
bin_to_strhex(buffer, str);
|
||||||
writeLineEx(0, 1, "<%NODE_NAME%> TcpSnd: %s (Länge: %d)", str, elCount(buffer));
|
writeLineEx(0, 1, "<%NODE_NAME%> TcpSnd: %s (Länge: %d)", str, elCount(buffer));
|
||||||
|
|
||||||
if (g_%NODE_NAME%_Socket.Send(buffer, elCount(buffer)) != 0)
|
if (gSocket.Send(buffer, elCount(buffer)) != 0)
|
||||||
{
|
{
|
||||||
gIpLastErr = g_%NODE_NAME%_Socket.GetLastSocketError();
|
gIpLastErr = gSocket.GetLastSocketError();
|
||||||
|
|
||||||
if (gIpLastErr != WSA_IO_PENDING)
|
if (gIpLastErr != WSA_IO_PENDING)
|
||||||
{
|
{
|
||||||
g_%NODE_NAME%_Socket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
|
gSocket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
|
||||||
writeLineEx(0, 2, "<%NODE_NAME%> TcpSnd error (%d): %s", gIpLastErr, gIpLastErrStr);
|
writeLineEx(0, 2, "<%NODE_NAME%> TcpSnd error (%d): %s", gIpLastErr, gIpLastErrStr);
|
||||||
g_%NODE_NAME%_Socket.Close();
|
gSocket.Close();
|
||||||
g_%NODE_NAME%_SocketState = CLOSED;
|
gSocketState = CLOSED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -10,10 +10,10 @@ variables
|
||||||
char gIpLastErrStr[512] = "";
|
char gIpLastErrStr[512] = "";
|
||||||
|
|
||||||
enum SocketState { NULL, OK, ERROR, CLOSED };
|
enum SocketState { NULL, OK, ERROR, CLOSED };
|
||||||
enum SocketState g_%NODE_NAME%_SocketState = NULL;
|
enum SocketState gSocketState = NULL;
|
||||||
|
|
||||||
dword g_%NODE_NAME%_RemoteIP = INVALID_IP;
|
dword gRemoteIP = INVALID_IP;
|
||||||
word g_%NODE_NAME%_RemotePort = 0;
|
word gRemotePort = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ includes
|
||||||
|
|
||||||
variables
|
variables
|
||||||
{
|
{
|
||||||
UdpSocket g_%NODE_NAME%_Socket;
|
UdpSocket gSocket;
|
||||||
|
|
||||||
byte gRxBuffer[8192];
|
byte gRxBuffer[8192];
|
||||||
}
|
}
|
||||||
|
@ -30,19 +30,19 @@ word UdpOpenSocket()
|
||||||
// Try to open socket
|
// Try to open socket
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
g_%NODE_NAME%_Socket = UdpSocket::Open(localIp, localPort);
|
gSocket = UdpSocket::Open(localIp, localPort);
|
||||||
if (g_%NODE_NAME%_Socket.GetLastSocketError() != 0)
|
if (gSocket.GetLastSocketError() != 0)
|
||||||
{
|
{
|
||||||
g_%NODE_NAME%_Socket.GetLastSocketErrorAsString(errorText, elcount(errorText));
|
gSocket.GetLastSocketErrorAsString(errorText, elcount(errorText));
|
||||||
writeLineEx(0, 1, "<%BASE_FILE_NAME%> Error: could not open Udp socket on %s:%d, %s (%d)!", Local_IP, localPort, errorText, g_%NODE_NAME%_Socket.GetLastSocketError());
|
writeLineEx(0, 1, "<%BASE_FILE_NAME%> Error: could not open Udp socket on %s:%d, %s (%d)!", Local_IP, localPort, errorText, gSocket.GetLastSocketError());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (g_%NODE_NAME%_Socket.GetLastSocketError() != 0 && i++ < 9);
|
while (gSocket.GetLastSocketError() != 0 && i++ < 9);
|
||||||
|
|
||||||
if (g_%NODE_NAME%_Socket.GetLastSocketError() != 0)
|
if (gSocket.GetLastSocketError() != 0)
|
||||||
{
|
{
|
||||||
writeLineEx(0, 1, "<%BASE_FILE_NAME%> Error: could not open Udp socket!");
|
writeLineEx(0, 1, "<%BASE_FILE_NAME%> Error: could not open Udp socket!");
|
||||||
return g_%NODE_NAME%_Socket.GetLastSocketError();
|
return gSocket.GetLastSocketError();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -76,13 +76,13 @@ word UdpConnectTo(dword remoteIp, word remotePort)
|
||||||
fehler = UdpOpenSocket();
|
fehler = UdpOpenSocket();
|
||||||
if (fehler != 0)
|
if (fehler != 0)
|
||||||
{
|
{
|
||||||
g_%NODE_NAME%_SocketState = ERROR;
|
gSocketState = ERROR;
|
||||||
return fehler;
|
return fehler;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_%NODE_NAME%_RemoteIP = remoteIp;
|
gRemoteIP = remoteIp;
|
||||||
g_%NODE_NAME%_RemotePort = remotePort;
|
gRemotePort = remotePort;
|
||||||
g_%NODE_NAME%_SocketState = OK;
|
gSocketState = OK;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,24 +90,24 @@ void UdpRecv()
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
if (g_%NODE_NAME%_SocketState != OK)
|
if (gSocketState != OK)
|
||||||
{
|
{
|
||||||
writeLineEx(0, 2, "UdpRecv: Socket status is not OK!");
|
writeLineEx(0, 2, "UdpRecv: Socket status is not OK!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = g_%NODE_NAME%_Socket.ReceiveFrom(gRxBuffer, elcount(gRxBuffer));
|
result = gSocket.ReceiveFrom(gRxBuffer, elcount(gRxBuffer));
|
||||||
|
|
||||||
if (result != 0) // Calling OnUdpReceive otherwise
|
if (result != 0) // Calling OnUdpReceive otherwise
|
||||||
{
|
{
|
||||||
gIpLastErr = g_%NODE_NAME%_Socket.GetLastSocketError();
|
gIpLastErr = gSocket.GetLastSocketError();
|
||||||
|
|
||||||
if (gIpLastErr != WSA_IO_PENDING) // Calling OnUdpReceive otherwise
|
if (gIpLastErr != WSA_IO_PENDING) // Calling OnUdpReceive otherwise
|
||||||
{
|
{
|
||||||
g_%NODE_NAME%_Socket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
|
gSocket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
|
||||||
writeLineEx(0, 2, "<%BASE_FILE_NAME%> UdpRecv Error (%d): %s", gIpLastErr, gIpLastErrStr);
|
writeLineEx(0, 2, "<%BASE_FILE_NAME%> UdpRecv Error (%d): %s", gIpLastErr, gIpLastErrStr);
|
||||||
g_%NODE_NAME%_Socket.Close();
|
gSocket.Close();
|
||||||
g_%NODE_NAME%_SocketState = CLOSED;
|
gSocketState = CLOSED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,11 +118,11 @@ void UdpSnd(byte buffer[])
|
||||||
{
|
{
|
||||||
char str[20*3];
|
char str[20*3];
|
||||||
|
|
||||||
switch (g_%NODE_NAME%_SocketState)
|
switch (gSocketState)
|
||||||
{
|
{
|
||||||
case CLOSED:
|
case CLOSED:
|
||||||
UdpConnectTo(g_%NODE_NAME%_RemoteIP, g_%NODE_NAME%_RemotePort);
|
UdpConnectTo(gRemoteIP, gRemotePort);
|
||||||
if (g_%NODE_NAME%_SocketState != OK)
|
if (gSocketState != OK)
|
||||||
{
|
{
|
||||||
writeLineEx(0, 2, "UdpSnd: Reconnecting failed!");
|
writeLineEx(0, 2, "UdpSnd: Reconnecting failed!");
|
||||||
return;
|
return;
|
||||||
|
@ -137,16 +137,16 @@ void UdpSnd(byte buffer[])
|
||||||
bin_to_strhex(buffer, str);
|
bin_to_strhex(buffer, str);
|
||||||
writeLineEx(0, 1, "<%BASE_FILE_NAME%> UdpSnd: %s (Länge: %d)", str, elCount(buffer));
|
writeLineEx(0, 1, "<%BASE_FILE_NAME%> UdpSnd: %s (Länge: %d)", str, elCount(buffer));
|
||||||
|
|
||||||
if (g_%NODE_NAME%_Socket.SendTo(g_%NODE_NAME%_RemoteIP, g_%NODE_NAME%_RemotePort, buffer, elCount(buffer)) != 0)
|
if (gSocket.SendTo(gRemoteIP, gRemotePort, buffer, elCount(buffer)) != 0)
|
||||||
{
|
{
|
||||||
gIpLastErr = g_%NODE_NAME%_Socket.GetLastSocketError();
|
gIpLastErr = gSocket.GetLastSocketError();
|
||||||
|
|
||||||
if (gIpLastErr != WSA_IO_PENDING)
|
if (gIpLastErr != WSA_IO_PENDING)
|
||||||
{
|
{
|
||||||
g_%NODE_NAME%_Socket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
|
gSocket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
|
||||||
writeLineEx(0, 2, "<%BASE_FILE_NAME%> UdpSnd error (%d): %s", gIpLastErr, gIpLastErrStr);
|
writeLineEx(0, 2, "<%BASE_FILE_NAME%> UdpSnd error (%d): %s", gIpLastErr, gIpLastErrStr);
|
||||||
g_%NODE_NAME%_Socket.Close();
|
gSocket.Close();
|
||||||
g_%NODE_NAME%_SocketState = CLOSED;
|
gSocketState = CLOSED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue