Added FD BBMD Address encoding. (#269)
* Added FD BBMD Address encoder and decoder * Added FD BBMD address to bacapp * Added FD BBMD address to network port object Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
@@ -70,6 +70,10 @@ struct bacnet_ipv4_port {
|
||||
bool BBMD_Accept_FD_Registrations;
|
||||
void *BBMD_BD_Table;
|
||||
void *BBMD_FD_Table;
|
||||
/* used for foreign device registration to remote BBMD */
|
||||
uint8_t BBMD_IP_Address[4];
|
||||
uint16_t BBMD_Port;
|
||||
uint16_t BBMD_Lifetime;
|
||||
};
|
||||
|
||||
#define IPV6_ADDR_SIZE 16
|
||||
@@ -1395,6 +1399,217 @@ bool Network_Port_BBMD_FD_Table_Set(
|
||||
return status;
|
||||
}
|
||||
|
||||
#if defined(BACDL_BIP) && BBMD_ENABLED
|
||||
/**
|
||||
* For a given object instance-number, gets the ip-address and port
|
||||
* Note: depends on Network_Type being set for this object
|
||||
*
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @param addr - holds the ip-address and port retrieved
|
||||
*
|
||||
* @return true if ip-address and port were retrieved
|
||||
*/
|
||||
static bool Network_Port_Remote_BBMD_IP_Address_And_Port(
|
||||
uint32_t object_instance, BACNET_IP_ADDRESS *addr)
|
||||
{
|
||||
unsigned index = 0; /* offset from instance lookup */
|
||||
bool status = false;
|
||||
|
||||
if (addr) {
|
||||
index = Network_Port_Instance_To_Index(object_instance);
|
||||
if (index < BACNET_NETWORK_PORTS_MAX) {
|
||||
if (Object_List[index].Network_Type == PORT_TYPE_BIP) {
|
||||
bvlc_address_set(addr,
|
||||
Object_List[index].Network.IPv4.BBMD_IP_Address[0],
|
||||
Object_List[index].Network.IPv4.BBMD_IP_Address[1],
|
||||
Object_List[index].Network.IPv4.BBMD_IP_Address[2],
|
||||
Object_List[index].Network.IPv4.BBMD_IP_Address[3]);
|
||||
addr->port = Object_List[index].Network.IPv4.BBMD_Port;
|
||||
status = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* For a given object instance-number, loads the ip-address into
|
||||
* an octet string.
|
||||
* Note: depends on Network_Type being set for this object
|
||||
*
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @param a - ip-address first octet
|
||||
* @param b - ip-address first octet
|
||||
* @param c - ip-address first octet
|
||||
* @param d - ip-address first octet
|
||||
*
|
||||
* @return true if ip-address was retrieved
|
||||
*/
|
||||
bool Network_Port_Remote_BBMD_IP_Address(
|
||||
uint32_t object_instance,
|
||||
uint8_t *a, uint8_t *b, uint8_t *c, uint8_t *d)
|
||||
{
|
||||
unsigned index = 0; /* offset from instance lookup */
|
||||
bool status = false;
|
||||
|
||||
index = Network_Port_Instance_To_Index(object_instance);
|
||||
if (index < BACNET_NETWORK_PORTS_MAX) {
|
||||
if (Object_List[index].Network_Type == PORT_TYPE_BIP) {
|
||||
if (a) {
|
||||
*a = Object_List[index].Network.IPv4.BBMD_IP_Address[0];
|
||||
}
|
||||
if (b) {
|
||||
*b = Object_List[index].Network.IPv4.BBMD_IP_Address[1];
|
||||
}
|
||||
if (c) {
|
||||
*c = Object_List[index].Network.IPv4.BBMD_IP_Address[2];
|
||||
}
|
||||
if (d) {
|
||||
*d = Object_List[index].Network.IPv4.BBMD_IP_Address[3];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* For a given object instance-number, sets the ip-address
|
||||
* Note: depends on Network_Type being set for this object
|
||||
*
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @param a - ip-address first octet
|
||||
* @param b - ip-address first octet
|
||||
* @param c - ip-address first octet
|
||||
* @param d - ip-address first octet
|
||||
*
|
||||
* @return true if ip-address was set
|
||||
*/
|
||||
bool Network_Port_Remote_BBMD_IP_Address_Set(
|
||||
uint32_t object_instance, uint8_t a, uint8_t b, uint8_t c, uint8_t d)
|
||||
{
|
||||
unsigned index = 0; /* offset from instance lookup */
|
||||
bool status = false;
|
||||
|
||||
index = Network_Port_Instance_To_Index(object_instance);
|
||||
if (index < BACNET_NETWORK_PORTS_MAX) {
|
||||
if (Object_List[index].Network_Type == PORT_TYPE_BIP) {
|
||||
Object_List[index].Network.IPv4.BBMD_IP_Address[0] = a;
|
||||
Object_List[index].Network.IPv4.BBMD_IP_Address[1] = b;
|
||||
Object_List[index].Network.IPv4.BBMD_IP_Address[2] = c;
|
||||
Object_List[index].Network.IPv4.BBMD_IP_Address[3] = d;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* For a given object instance-number, gets the BBMD UDP Port number
|
||||
* Note: depends on Network_Type being set to PORT_TYPE_BIP for this object
|
||||
*
|
||||
* @param object_instance - object-instance number of the object
|
||||
*
|
||||
* @return BBMD UDP Port number
|
||||
*/
|
||||
uint16_t Network_Port_Remote_BBMD_BIP_Port(uint32_t object_instance)
|
||||
{
|
||||
uint16_t value = 0;
|
||||
unsigned index = 0;
|
||||
|
||||
index = Network_Port_Instance_To_Index(object_instance);
|
||||
if (index < BACNET_NETWORK_PORTS_MAX) {
|
||||
if (Object_List[index].Network_Type == PORT_TYPE_BIP) {
|
||||
value = Object_List[index].Network.IPv4.BBMD_Port;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* For a given object instance-number, sets the BBMD UDP Port number
|
||||
* Note: depends on Network_Type being set to PORT_TYPE_BIP for this object
|
||||
*
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @param value - BBMD UDP Port number (default=0xBAC0)
|
||||
*
|
||||
* @return true if values are within range and property is set.
|
||||
*/
|
||||
bool Network_Port_Remote_BBMD_BIP_Port_Set(uint32_t object_instance,
|
||||
uint16_t value)
|
||||
{
|
||||
bool status = false;
|
||||
unsigned index = 0;
|
||||
|
||||
index = Network_Port_Instance_To_Index(object_instance);
|
||||
if (index < BACNET_NETWORK_PORTS_MAX) {
|
||||
if (Object_List[index].Network_Type == PORT_TYPE_BIP) {
|
||||
if (Object_List[index].Network.IPv4.BBMD_Port != value) {
|
||||
Object_List[index].Changes_Pending = true;
|
||||
}
|
||||
Object_List[index].Network.IPv4.BBMD_Port = value;
|
||||
status = true;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* For a given object instance-number, gets the BBMD lifetime seconds
|
||||
* Note: depends on Network_Type being set to PORT_TYPE_BIP for this object
|
||||
*
|
||||
* @param object_instance - object-instance number of the object
|
||||
*
|
||||
* @return BBMD lifetime seconds
|
||||
*/
|
||||
uint16_t Network_Port_Remote_BBMD_BIP_Lifetime(uint32_t object_instance)
|
||||
{
|
||||
uint16_t value = 0;
|
||||
unsigned index = 0;
|
||||
|
||||
index = Network_Port_Instance_To_Index(object_instance);
|
||||
if (index < BACNET_NETWORK_PORTS_MAX) {
|
||||
if (Object_List[index].Network_Type == PORT_TYPE_BIP) {
|
||||
value = Object_List[index].Network.IPv4.BBMD_Lifetime;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* For a given object instance-number, sets the BBMD lifetime seconds
|
||||
* Note: depends on Network_Type being set to PORT_TYPE_BIP for this object
|
||||
*
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @param value - BBMD lifetime seconds
|
||||
*
|
||||
* @return true if values are within range and property is set.
|
||||
*/
|
||||
bool Network_Port_Remote_BBMD_BIP_Lifetime_Set(uint32_t object_instance,
|
||||
uint16_t value)
|
||||
{
|
||||
bool status = false;
|
||||
unsigned index = 0;
|
||||
|
||||
index = Network_Port_Instance_To_Index(object_instance);
|
||||
if (index < BACNET_NETWORK_PORTS_MAX) {
|
||||
if (Object_List[index].Network_Type == PORT_TYPE_BIP) {
|
||||
if (Object_List[index].Network.IPv4.BBMD_Lifetime != value) {
|
||||
Object_List[index].Changes_Pending = true;
|
||||
}
|
||||
Object_List[index].Network.IPv4.BBMD_Lifetime = value;
|
||||
status = true;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* For a given object instance-number, gets the BACnet/IP UDP Port number
|
||||
* Note: depends on Network_Type being set to PORT_TYPE_BIP for this object
|
||||
@@ -1962,9 +2177,13 @@ bool Network_Port_MSTP_Max_Info_Frames_Set(
|
||||
int Network_Port_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata)
|
||||
{
|
||||
int apdu_len = 0;
|
||||
int apdu_size = 0;
|
||||
BACNET_BIT_STRING bit_string;
|
||||
BACNET_OCTET_STRING octet_string;
|
||||
BACNET_CHARACTER_STRING char_string;
|
||||
#if defined(BACDL_BIP) && BBMD_ENABLED
|
||||
BACNET_IP_ADDRESS ip_address;
|
||||
#endif
|
||||
uint8_t *apdu = NULL;
|
||||
const int *pRequired = NULL;
|
||||
const int *pOptional = NULL;
|
||||
@@ -1984,6 +2203,7 @@ int Network_Port_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata)
|
||||
return BACNET_STATUS_ERROR;
|
||||
}
|
||||
apdu = rpdata->application_data;
|
||||
apdu_size = rpdata->application_data_len;
|
||||
switch (rpdata->object_property) {
|
||||
case PROP_OBJECT_IDENTIFIER:
|
||||
apdu_len = encode_application_object_id(
|
||||
@@ -2133,6 +2353,17 @@ int Network_Port_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata)
|
||||
rpdata->application_data_len,
|
||||
Network_Port_BBMD_FD_Table(rpdata->object_instance));
|
||||
break;
|
||||
case PROP_FD_BBMD_ADDRESS:
|
||||
Network_Port_Remote_BBMD_IP_Address_And_Port(
|
||||
rpdata->object_instance, &ip_address);
|
||||
apdu_len = bvlc_foreign_device_bbmd_host_address_encode(&apdu[0],
|
||||
apdu_size, &ip_address);
|
||||
break;
|
||||
case PROP_FD_SUBSCRIPTION_LIFETIME:
|
||||
apdu_len = encode_application_unsigned(
|
||||
&apdu[0], Network_Port_Remote_BBMD_BIP_Lifetime(
|
||||
rpdata->object_instance));
|
||||
break;
|
||||
#endif
|
||||
case PROP_BACNET_IPV6_MODE:
|
||||
apdu_len = encode_application_enumerated(
|
||||
@@ -2214,6 +2445,7 @@ int Network_Port_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata)
|
||||
rpdata->error_class = ERROR_CLASS_PROPERTY;
|
||||
rpdata->error_code = ERROR_CODE_UNKNOWN_PROPERTY;
|
||||
apdu_len = BACNET_STATUS_ERROR;
|
||||
(void)apdu_size;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user