Added write BDT application (#170)
Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
@@ -66,9 +66,9 @@
|
||||
/** enable debugging */
|
||||
static bool BVLC_Debug = false;
|
||||
/** result from a client request */
|
||||
static uint16_t BVLC_Result_Code = BVLC_RESULT_SUCCESSFUL_COMPLETION;
|
||||
static uint16_t BVLC_Result_Code = BVLC_RESULT_INVALID;
|
||||
/** incoming function */
|
||||
static uint8_t BVLC_Function_Code = BVLC_RESULT;
|
||||
static uint8_t BVLC_Function_Code = BVLC_INVALID;
|
||||
/** Global IP address for NAT handling */
|
||||
static BACNET_IP_ADDRESS BVLC_Global_Address;
|
||||
/** Flag to indicate if NAT handling is enabled/disabled */
|
||||
@@ -1183,6 +1183,20 @@ int bvlc_bbmd_read_bdt(BACNET_IP_ADDRESS *bbmd_addr)
|
||||
return bip_send_mpdu(bbmd_addr, &BVLC_Buffer[0], BVLC_Buffer_Len);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the BDT to the indicated BBMD
|
||||
* @param bbmd_addr - IPv4 address of BBMD with which to read
|
||||
* @return Positive number (of bytes sent) on success
|
||||
*/
|
||||
int bvlc_bbmd_write_bdt(BACNET_IP_ADDRESS *bbmd_addr,
|
||||
BACNET_IP_BROADCAST_DISTRIBUTION_TABLE_ENTRY *bdt_list)
|
||||
{
|
||||
BVLC_Buffer_Len = bvlc_encode_write_broadcast_distribution_table(
|
||||
&BVLC_Buffer[0], sizeof(BVLC_Buffer), bdt_list);
|
||||
|
||||
return bip_send_mpdu(bbmd_addr, &BVLC_Buffer[0], BVLC_Buffer_Len);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the FDT from the indicated BBMD
|
||||
* @param bbmd_addr - IPv4 address of BBMD with which to read
|
||||
@@ -1211,6 +1225,15 @@ uint16_t bvlc_get_last_result(void)
|
||||
return BVLC_Result_Code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the last BVLL Result we received
|
||||
* @param result code
|
||||
*/
|
||||
void bvlc_set_last_result(uint16_t result_code)
|
||||
{
|
||||
BVLC_Result_Code = result_code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current BVLL Function Code we are processing.
|
||||
* We have to store this higher layer code for when the lower layers
|
||||
@@ -1224,6 +1247,15 @@ uint8_t bvlc_get_function_code(void)
|
||||
return BVLC_Function_Code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current BVLL Function Code
|
||||
* @param A BVLC_ code, such as BVLC_ORIGINAL_UNICAST_NPDU.
|
||||
*/
|
||||
void bvlc_set_function_code(uint8_t function_code)
|
||||
{
|
||||
BVLC_Function_Code = function_code;
|
||||
}
|
||||
|
||||
#if BBMD_ENABLED
|
||||
/**
|
||||
* @brief Get handle to broadcast distribution table (BDT).
|
||||
|
||||
@@ -68,9 +68,13 @@ int bvlc_send_pdu(BACNET_ADDRESS *dest,
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
uint16_t bvlc_get_last_result(void);
|
||||
BACNET_STACK_EXPORT
|
||||
void bvlc_set_last_result(uint16_t result_code);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
uint8_t bvlc_get_function_code(void);
|
||||
BACNET_STACK_EXPORT
|
||||
void bvlc_set_function_code(uint8_t function_code);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
void bvlc_maintenance_timer(uint16_t seconds);
|
||||
@@ -84,6 +88,9 @@ void bvlc_debug_enable(void);
|
||||
/* send a Read BDT request */
|
||||
BACNET_STACK_EXPORT
|
||||
int bvlc_bbmd_read_bdt(BACNET_IP_ADDRESS *bbmd_addr);
|
||||
BACNET_STACK_EXPORT
|
||||
int bvlc_bbmd_write_bdt(BACNET_IP_ADDRESS *bbmd_addr,
|
||||
BACNET_IP_BROADCAST_DISTRIBUTION_TABLE_ENTRY *bdt_list);
|
||||
/* send a Read FDT request */
|
||||
BACNET_STACK_EXPORT
|
||||
int bvlc_bbmd_read_fdt(BACNET_IP_ADDRESS *bbmd_addr);
|
||||
|
||||
@@ -2305,6 +2305,44 @@ int bvlc_decode_foreign_device_table_entry(uint8_t *pdu,
|
||||
return bytes_consumed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get a text name for each BVLC result code
|
||||
* @param result_code - BVLC result code
|
||||
* @return ASCII text name for each BVLC result code or empty string
|
||||
*/
|
||||
const char *bvlc_result_code_name(uint16_t result_code)
|
||||
{
|
||||
const char *name = "";
|
||||
|
||||
switch (result_code) {
|
||||
case BVLC_RESULT_SUCCESSFUL_COMPLETION:
|
||||
name = "Successful Completion";
|
||||
break;
|
||||
case BVLC_RESULT_WRITE_BROADCAST_DISTRIBUTION_TABLE_NAK:
|
||||
name= "Write-Broadcast-Distribution-Table NAK";
|
||||
break;
|
||||
case BVLC_RESULT_READ_BROADCAST_DISTRIBUTION_TABLE_NAK:
|
||||
name = "Read-Broadcast-Distribution-Table NAK";
|
||||
break;
|
||||
case BVLC_RESULT_REGISTER_FOREIGN_DEVICE_NAK:
|
||||
name = "Register-Foreign-Device NAK";
|
||||
break;
|
||||
case BVLC_RESULT_READ_FOREIGN_DEVICE_TABLE_NAK:
|
||||
name = "Read-Foreign-Device-Table NAK";
|
||||
break;
|
||||
case BVLC_RESULT_DELETE_FOREIGN_DEVICE_TABLE_ENTRY_NAK:
|
||||
name = "Delete-Foreign-Device-Table-Entry NAK";
|
||||
break;
|
||||
case BVLC_RESULT_DISTRIBUTE_BROADCAST_TO_NETWORK_NAK:
|
||||
name = "Distribute-Broadcast-To-Network NAK";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
#define BVLC_ORIGINAL_UNICAST_NPDU 10
|
||||
#define BVLC_ORIGINAL_BROADCAST_NPDU 11
|
||||
#define BVLC_SECURE_BVLL 12
|
||||
#define BVLC_INVALID 255
|
||||
|
||||
/** @} */
|
||||
|
||||
@@ -68,6 +69,7 @@
|
||||
#define BVLC_RESULT_READ_FOREIGN_DEVICE_TABLE_NAK 0x0040
|
||||
#define BVLC_RESULT_DELETE_FOREIGN_DEVICE_TABLE_ENTRY_NAK 0x0050
|
||||
#define BVLC_RESULT_DISTRIBUTE_BROADCAST_TO_NETWORK_NAK 0x0060
|
||||
#define BVLC_RESULT_INVALID 0xFFFF
|
||||
|
||||
/* number of bytes in the IPv4 address */
|
||||
#define IP_ADDRESS_MAX 4
|
||||
@@ -491,6 +493,9 @@ extern "C" {
|
||||
uint16_t npdu_size,
|
||||
uint16_t *npdu_len);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
const char *bvlc_result_code_name(uint16_t result_code);
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include "ctest.h"
|
||||
BACNET_STACK_EXPORT
|
||||
|
||||
Reference in New Issue
Block a user