Added explicit datalink_cleanup to all demo applications.
Moved bip_cleanup() to port specific files. This works better for bacnet-stack DLLs.
This commit is contained in:
@@ -191,6 +191,7 @@ int main(
|
||||
address_init();
|
||||
Init_Service_Handlers();
|
||||
dlenv_init();
|
||||
atexit(datalink_cleanup);
|
||||
/* configure the timeout values */
|
||||
last_seconds = time(NULL);
|
||||
timeout_seconds = (apdu_timeout() / 1000) * apdu_retries();
|
||||
|
||||
@@ -1254,6 +1254,7 @@ int main(
|
||||
address_init();
|
||||
Init_Service_Handlers();
|
||||
dlenv_init();
|
||||
atexit(datalink_cleanup);
|
||||
|
||||
/* configure the timeout values */
|
||||
current_seconds = time(NULL);
|
||||
@@ -1619,6 +1620,7 @@ int main(
|
||||
printf("End of BACnet Protocol Implementation Conformance Statement\r\n");
|
||||
printf("\r\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -230,17 +230,6 @@ void Initialize_Device_Addresses(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Handler registered with atexit() inside main function to, well, cleanup.
|
||||
* Especially if we don't end normally.
|
||||
* @see datalink_cleanup
|
||||
*/
|
||||
static void cleanup(
|
||||
void)
|
||||
{
|
||||
datalink_cleanup();
|
||||
}
|
||||
|
||||
/** Main function of server demo.
|
||||
*
|
||||
* @see Device_Set_Object_Instance_Number, dlenv_init, Send_I_Am,
|
||||
@@ -289,9 +278,9 @@ int main(
|
||||
first_object_instance, MAX_APDU);
|
||||
Init_Service_Handlers(first_object_instance);
|
||||
dlenv_init();
|
||||
atexit(datalink_cleanup);
|
||||
Devices_Init(first_object_instance);
|
||||
Initialize_Device_Addresses();
|
||||
atexit(cleanup);
|
||||
|
||||
#ifdef BACNET_TEST_VMAC
|
||||
/* initialize vmac table and router device */
|
||||
|
||||
@@ -146,6 +146,7 @@ int main(
|
||||
Init_Service_Handlers();
|
||||
address_init();
|
||||
dlenv_init();
|
||||
atexit(datalink_cleanup);
|
||||
/* send the request */
|
||||
Send_I_Am_Router_To_Network(Target_Router_Networks);
|
||||
|
||||
|
||||
@@ -322,6 +322,7 @@ int main(
|
||||
Init_Service_Handlers();
|
||||
address_init();
|
||||
dlenv_init();
|
||||
atexit(datalink_cleanup);
|
||||
/* configure the timeout values */
|
||||
last_seconds = time(NULL);
|
||||
timeout_seconds = apdu_timeout() / 1000;
|
||||
|
||||
@@ -222,6 +222,7 @@ int main(
|
||||
address_init();
|
||||
Init_Service_Handlers();
|
||||
dlenv_init();
|
||||
atexit(datalink_cleanup);
|
||||
/* configure the timeout values */
|
||||
last_seconds = time(NULL);
|
||||
timeout_seconds = (apdu_timeout() / 1000) * apdu_retries();
|
||||
@@ -380,7 +381,6 @@ int main(
|
||||
last_seconds = current_seconds;
|
||||
}
|
||||
}
|
||||
|
||||
if (Error_Detected)
|
||||
return 1;
|
||||
return 0;
|
||||
|
||||
@@ -247,6 +247,7 @@ int main(
|
||||
address_init();
|
||||
Init_Service_Handlers();
|
||||
dlenv_init();
|
||||
atexit(datalink_cleanup);
|
||||
/* configure the timeout values */
|
||||
last_seconds = time(NULL);
|
||||
timeout_seconds = (apdu_timeout() / 1000) * apdu_retries();
|
||||
|
||||
@@ -254,6 +254,7 @@ int main(
|
||||
address_init();
|
||||
Init_Service_Handlers();
|
||||
dlenv_init();
|
||||
atexit(datalink_cleanup);
|
||||
/* configure the timeout values */
|
||||
last_seconds = time(NULL);
|
||||
timeout_seconds = (apdu_timeout() / 1000) * apdu_retries();
|
||||
|
||||
@@ -400,6 +400,7 @@ int main(
|
||||
address_init();
|
||||
Init_Service_Handlers();
|
||||
dlenv_init();
|
||||
atexit(datalink_cleanup);
|
||||
/* configure the timeout values */
|
||||
last_seconds = time(NULL);
|
||||
timeout_seconds = (apdu_timeout() / 1000) * apdu_retries();
|
||||
|
||||
@@ -249,6 +249,7 @@ int main(
|
||||
address_init();
|
||||
Init_Service_Handlers();
|
||||
dlenv_init();
|
||||
atexit(datalink_cleanup);
|
||||
/* configure the timeout values */
|
||||
last_seconds = time(NULL);
|
||||
timeout_seconds = (apdu_timeout() / 1000) * apdu_retries();
|
||||
|
||||
@@ -185,6 +185,7 @@ int main(
|
||||
address_init();
|
||||
Init_Service_Handlers();
|
||||
dlenv_init();
|
||||
atexit(datalink_cleanup);
|
||||
/* configure the timeout values */
|
||||
last_seconds = time(NULL);
|
||||
timeout_seconds = (apdu_timeout() / 1000) * apdu_retries();
|
||||
|
||||
@@ -300,6 +300,7 @@ int main(
|
||||
address_init();
|
||||
Init_Service_Handlers();
|
||||
dlenv_init();
|
||||
atexit(datalink_cleanup);
|
||||
/* configure the timeout values */
|
||||
last_seconds = time(NULL);
|
||||
timeout_seconds = (apdu_timeout() / 1000) * apdu_retries();
|
||||
|
||||
@@ -131,16 +131,6 @@ static void Init_Service_Handlers(
|
||||
#endif /* defined(INTRINSIC_REPORTING) */
|
||||
}
|
||||
|
||||
/** Handler registered with atexit() inside main function to, well, cleanup.
|
||||
* Especially if we don't end normally.
|
||||
* @see datalink_cleanup
|
||||
*/
|
||||
static void cleanup(
|
||||
void)
|
||||
{
|
||||
datalink_cleanup();
|
||||
}
|
||||
|
||||
/** Main function of server demo.
|
||||
*
|
||||
* @see Device_Set_Object_Instance_Number, dlenv_init, Send_I_Am,
|
||||
@@ -177,7 +167,7 @@ int main(
|
||||
Device_Object_Instance_Number(), MAX_APDU);
|
||||
Init_Service_Handlers();
|
||||
dlenv_init();
|
||||
atexit(cleanup);
|
||||
atexit(datalink_cleanup);
|
||||
/* configure the timeout values */
|
||||
last_seconds = time(NULL);
|
||||
/* broadcast an I-Am on startup */
|
||||
@@ -231,6 +221,7 @@ int main(
|
||||
|
||||
/* blink LEDs, Turn on or off outputs, etc */
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -148,6 +148,7 @@ int main(
|
||||
Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE);
|
||||
Init_Service_Handlers();
|
||||
dlenv_init();
|
||||
atexit(datalink_cleanup);
|
||||
/* configure the timeout values */
|
||||
last_seconds = time(NULL);
|
||||
timeout_seconds = apdu_timeout() / 1000;
|
||||
|
||||
@@ -192,6 +192,7 @@ int main(
|
||||
Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE);
|
||||
Init_Service_Handlers();
|
||||
dlenv_init();
|
||||
atexit(datalink_cleanup);
|
||||
Send_UCOV_Notify(&Handler_Transmit_Buffer[0], &cov_data);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -277,6 +277,7 @@ int main(
|
||||
address_init();
|
||||
Init_Service_Handlers();
|
||||
dlenv_init();
|
||||
atexit(datalink_cleanup);
|
||||
/* configure the timeout values */
|
||||
last_seconds = time(NULL);
|
||||
timeout_seconds = (apdu_timeout() / 1000) * apdu_retries();
|
||||
|
||||
@@ -153,6 +153,7 @@ int main(
|
||||
Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE);
|
||||
Init_Service_Handlers();
|
||||
dlenv_init();
|
||||
atexit(datalink_cleanup);
|
||||
/* configure the timeout values */
|
||||
last_seconds = time(NULL);
|
||||
timeout_seconds = apdu_timeout() / 1000;
|
||||
|
||||
@@ -234,6 +234,7 @@ int main(
|
||||
Init_Service_Handlers();
|
||||
address_init();
|
||||
dlenv_init();
|
||||
atexit(datalink_cleanup);
|
||||
/* configure the timeout values */
|
||||
last_seconds = time(NULL);
|
||||
timeout_seconds = apdu_timeout() / 1000;
|
||||
|
||||
@@ -290,6 +290,7 @@ int main(
|
||||
Init_Service_Handlers();
|
||||
address_init();
|
||||
dlenv_init();
|
||||
atexit(datalink_cleanup);
|
||||
/* configure the timeout values */
|
||||
last_seconds = time(NULL);
|
||||
timeout_seconds = apdu_timeout() / 1000;
|
||||
|
||||
@@ -204,6 +204,7 @@ int main(
|
||||
address_init();
|
||||
Init_Service_Handlers();
|
||||
dlenv_init();
|
||||
atexit(datalink_cleanup);
|
||||
/* configure the timeout values */
|
||||
last_seconds = time(NULL);
|
||||
timeout_seconds = (apdu_timeout() / 1000) * apdu_retries();
|
||||
|
||||
@@ -326,6 +326,7 @@ int main(
|
||||
address_init();
|
||||
Init_Service_Handlers();
|
||||
dlenv_init();
|
||||
atexit(datalink_cleanup);
|
||||
/* configure the timeout values */
|
||||
last_seconds = time(NULL);
|
||||
timeout_seconds = (apdu_timeout() / 1000) * apdu_retries();
|
||||
|
||||
@@ -58,10 +58,10 @@ extern "C" {
|
||||
on Windows, ifname is the dotted ip address of the interface */
|
||||
bool bip_init(
|
||||
char *ifname);
|
||||
|
||||
/* normal functions... */
|
||||
void bip_cleanup(
|
||||
void);
|
||||
|
||||
/* common BACnet/IP functions */
|
||||
void bip_set_socket(
|
||||
int sock_fd);
|
||||
int bip_socket(
|
||||
@@ -122,12 +122,12 @@ extern "C" {
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
/** @defgroup DLBIP BACnet/IP DataLink Network Layer
|
||||
/** @defgroup DLBIP BACnet/IP DataLink Network Layer
|
||||
* @ingroup DataLink
|
||||
* Implementation of the Network Layer using BACnet/IP as the transport, as
|
||||
* described in Annex J.
|
||||
* The functions described here fulfill the roles defined generically at the
|
||||
* DataLink level by serving as the implementation of the function templates.
|
||||
*
|
||||
*
|
||||
*/
|
||||
#endif
|
||||
|
||||
@@ -98,7 +98,7 @@ static int get_local_address_ioctl(
|
||||
|
||||
/** Gets the local IP address and local broadcast address from the system,
|
||||
* and saves it into the BACnet/IP data structures.
|
||||
*
|
||||
*
|
||||
* @param ifname [in] The named interface to use for the network layer.
|
||||
* Eg, for Linux, ifname is eth0, ath0, arc0, and others.
|
||||
*/
|
||||
@@ -140,12 +140,11 @@ static void bip_set_interface(
|
||||
* -# Opens a UDP socket
|
||||
* -# Configures the socket for sending and receiving
|
||||
* -# Configures the socket so it can send broadcasts
|
||||
* -# Binds the socket to the local IP address at the specified port for
|
||||
* -# Binds the socket to the local IP address at the specified port for
|
||||
* BACnet/IP (by default, 0xBAC0 = 47808).
|
||||
*
|
||||
*
|
||||
* @note For Linux, ifname is eth0, ath0, arc0, and others.
|
||||
For Windows, ifname is the dotted ip address of the interface.
|
||||
|
||||
*
|
||||
* @param ifname [in] The named interface to use for the network layer.
|
||||
* If NULL, the "eth0" interface is assigned.
|
||||
* @return True if the socket is successfully opened for BACnet/IP,
|
||||
@@ -204,6 +203,23 @@ bool bip_init(
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Cleanup and close out the BACnet/IP services by closing the socket.
|
||||
* @ingroup DLBIP
|
||||
*/
|
||||
void bip_cleanup(
|
||||
void)
|
||||
{
|
||||
int sock_fd = 0;
|
||||
|
||||
if (bip_valid()) {
|
||||
sock_fd = bip_socket();
|
||||
close(sock_fd);
|
||||
}
|
||||
bip_set_socket(-1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/** Get the netmask of the BACnet/IP's interface via an ioctl() call.
|
||||
* @param netmask [out] The netmask, in host order.
|
||||
* @return 0 on success, else the error from the ioctl() call.
|
||||
|
||||
@@ -173,13 +173,6 @@ static void set_broadcast_address(
|
||||
#endif
|
||||
}
|
||||
|
||||
static void cleanup(
|
||||
void)
|
||||
{
|
||||
WSACleanup();
|
||||
}
|
||||
|
||||
|
||||
/* on Windows, ifname is the dotted ip address of the interface */
|
||||
void bip_set_interface(
|
||||
char *ifname)
|
||||
@@ -318,6 +311,23 @@ static char *winsock_error_code_text(
|
||||
}
|
||||
}
|
||||
|
||||
/** Initialize the BACnet/IP services at the given interface.
|
||||
* @ingroup DLBIP
|
||||
* -# Gets the local IP address and local broadcast address from the system,
|
||||
* and saves it into the BACnet/IP data structures.
|
||||
* -# Opens a UDP socket
|
||||
* -# Configures the socket for sending and receiving
|
||||
* -# Configures the socket so it can send broadcasts
|
||||
* -# Binds the socket to the local IP address at the specified port for
|
||||
* BACnet/IP (by default, 0xBAC0 = 47808).
|
||||
*
|
||||
* @note For Windows, ifname is the dotted ip address of the interface.
|
||||
*
|
||||
* @param ifname [in] The named interface to use for the network layer.
|
||||
* If NULL, the "eth0" interface is assigned.
|
||||
* @return True if the socket is successfully opened for BACnet/IP,
|
||||
* else False if the socket functions fail.
|
||||
*/
|
||||
bool bip_init(
|
||||
char *ifname)
|
||||
{
|
||||
@@ -339,7 +349,7 @@ bool bip_init(
|
||||
Code, winsock_error_code_text(Code));
|
||||
exit(1);
|
||||
}
|
||||
atexit(cleanup);
|
||||
atexit(bip_cleanup);
|
||||
|
||||
if (ifname)
|
||||
bip_set_interface(ifname);
|
||||
@@ -443,3 +453,21 @@ bool bip_init(
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Cleanup and close out the BACnet/IP services by closing the socket.
|
||||
* @ingroup DLBIP
|
||||
*/
|
||||
void bip_cleanup(
|
||||
void)
|
||||
{
|
||||
int sock_fd = 0;
|
||||
|
||||
if (bip_valid()) {
|
||||
sock_fd = bip_socket();
|
||||
close(sock_fd);
|
||||
}
|
||||
bip_set_socket(-1);
|
||||
WSACleanup();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
+2
-15
@@ -79,19 +79,6 @@ bool bip_valid(
|
||||
return (BIP_Socket != -1);
|
||||
}
|
||||
|
||||
/** Cleanup and close out the BACnet/IP services by closing the socket.
|
||||
* @ingroup DLBIP
|
||||
*/
|
||||
void bip_cleanup(
|
||||
void)
|
||||
{
|
||||
if (bip_valid())
|
||||
close(BIP_Socket);
|
||||
BIP_Socket = -1;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void bip_set_addr(
|
||||
uint32_t net_address)
|
||||
{ /* in network byte order */
|
||||
@@ -181,8 +168,8 @@ int bip_send_pdu(
|
||||
mtu[0] = BVLL_TYPE_BACNET_IP;
|
||||
bip_dest.sin_family = AF_INET;
|
||||
function = bvlc_get_function_code(); /* What type of BVLC was it? */
|
||||
if ( (dest->net == BACNET_BROADCAST_NETWORK) ||
|
||||
(function == BVLC_FORWARDED_NPDU) ||
|
||||
if ( (dest->net == BACNET_BROADCAST_NETWORK) ||
|
||||
(function == BVLC_FORWARDED_NPDU) ||
|
||||
(function == BVLC_ORIGINAL_BROADCAST_NPDU) ) {
|
||||
/* broadcast */
|
||||
address.s_addr = BIP_Broadcast_Address.s_addr;
|
||||
|
||||
Reference in New Issue
Block a user