Chore/bacnet-sc-unrelated-cleanup (#620)
* Added required linux Ethernet library for ethernet build * Added .obj to gitignore * Fixed BACnet port for APPLE to use BSD in CMake * Changed format in CMake to enable cleaner SC merge * Added create-object and delete-object recipes in GCC Makefile * Added datalink timer to all example OS apps * Changed most microcontroller ports to use BACAPP_MINIMAL to specify which datatypes can be written. * Fixed zephyr OS for BACnet/IP warning * Fixed zephyr OS log to not require log_strdup * Added writefile API to file object example * Added API to device-client to make it more robust. * Added API in network-port object for getting the ASCII object-name * Added debug print with a timestamp option * Added debug print with hex dump print * Added API to network port object for activate and discard * Added default define for debug with timestamp * Added prototype in header for disabled debug printf. * Added fifo peek ahead function to peek at more than one byte. * Added get-mac value for network port that uses buffer rather than octetstring
This commit is contained in:
@@ -299,6 +299,23 @@ bool Network_Port_Name_Set(uint32_t object_instance, char *new_name)
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief For a given object instance-number, returns the ASCII object-name
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @return ASCII C string object name, or NULL if not found or not set.
|
||||
*/
|
||||
const char *Network_Port_Object_Name_ASCII(uint32_t object_instance)
|
||||
{
|
||||
unsigned index = 0; /* offset from instance lookup */
|
||||
|
||||
index = Network_Port_Instance_To_Index(object_instance);
|
||||
if (index < BACNET_NETWORK_PORTS_MAX) {
|
||||
return Object_List[index].Object_Name;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a given Network Port instance is valid
|
||||
*
|
||||
@@ -608,19 +625,19 @@ bool Network_Port_Quality_Set(
|
||||
|
||||
/**
|
||||
* For a given object instance-number, loads the mac-address into
|
||||
* an octet string.
|
||||
* a buffer and returns the length of the mac-address.
|
||||
* Note: depends on Network_Type being set for this object
|
||||
*
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @param mac_address - holds the mac-address retrieved
|
||||
* @param mac_size - size of the mac-address buffer
|
||||
*
|
||||
* @return true if mac-address was retrieved
|
||||
* @return the length of the mac-address retrieved, or zero if not found
|
||||
*/
|
||||
bool Network_Port_MAC_Address(
|
||||
uint32_t object_instance, BACNET_OCTET_STRING *mac_address)
|
||||
uint8_t Network_Port_MAC_Address_Value(
|
||||
uint32_t object_instance, uint8_t *mac_address, size_t mac_size)
|
||||
{
|
||||
unsigned index = 0; /* offset from instance lookup */
|
||||
bool status = false;
|
||||
uint8_t *mac = NULL;
|
||||
uint8_t ip_mac[4 + 2] = { 0 };
|
||||
size_t mac_len = 0;
|
||||
@@ -653,12 +670,39 @@ bool Network_Port_MAC_Address(
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (mac) {
|
||||
status = octetstring_init(mac_address, mac, mac_len);
|
||||
if (mac_len > 0) {
|
||||
if (mac_size >= mac_len) {
|
||||
memcpy(mac_address, mac, mac_len);
|
||||
} else {
|
||||
mac_len = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
return mac_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* For a given object instance-number, loads the mac-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 mac_address - holds the mac-address retrieved
|
||||
*
|
||||
* @return true if mac-address was retrieved
|
||||
*/
|
||||
bool Network_Port_MAC_Address(
|
||||
uint32_t object_instance, BACNET_OCTET_STRING *mac_address)
|
||||
{
|
||||
uint8_t mac_len = 0;
|
||||
|
||||
if (mac_address) {
|
||||
mac_len = Network_Port_MAC_Address_Value(object_instance,
|
||||
mac_address->value, sizeof(mac_address->value));
|
||||
}
|
||||
|
||||
return mac_len > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -838,6 +882,34 @@ bool Network_Port_Changes_Pending_Set(uint32_t object_instance, bool value)
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief For a given object instance-number, activates any pending changes
|
||||
* @param object_instance - object-instance number of the object
|
||||
*/
|
||||
void Network_Port_Changes_Pending_Activate(uint32_t object_instance)
|
||||
{
|
||||
unsigned index = 0;
|
||||
|
||||
index = Network_Port_Instance_To_Index(object_instance);
|
||||
if (index < BACNET_NETWORK_PORTS_MAX) {
|
||||
/* callback? something else? */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief For a given object instance-number, discards any pending changes
|
||||
* @param object_instance - object-instance number of the object
|
||||
*/
|
||||
void Network_Port_Changes_Pending_Discard(uint32_t object_instance)
|
||||
{
|
||||
unsigned index = 0;
|
||||
|
||||
index = Network_Port_Instance_To_Index(object_instance);
|
||||
if (index < BACNET_NETWORK_PORTS_MAX) {
|
||||
/* callback? something else? */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For a given object instance-number, gets the MS/TP Max_Master value
|
||||
* Note: depends on Network_Type being set to PORT_TYPE_MSTP for this object
|
||||
@@ -1127,6 +1199,33 @@ bool Network_Port_IP_DNS_Server(uint32_t object_instance,
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Encode a BACnetARRAY property element; a function template
|
||||
* @param object_instance [in] BACnet network port object instance number
|
||||
* @param index [in] array index requested:
|
||||
* 0 to (array size - 1) for individual array members
|
||||
* @param apdu [out] Buffer in which the APDU contents are built, or
|
||||
* NULL to return the length of buffer if it had been built
|
||||
* @return The length of the apdu encoded, or
|
||||
* BACNET_STATUS_ERROR for an invalid array index
|
||||
*/
|
||||
static int Network_Port_IP_DNS_Server_Encode(
|
||||
uint32_t object_instance, BACNET_ARRAY_INDEX index, uint8_t *apdu)
|
||||
{
|
||||
int apdu_len = 0;
|
||||
BACNET_OCTET_STRING ip_address = { 0 };
|
||||
|
||||
if (index >= BIP_DNS_MAX) {
|
||||
apdu_len = BACNET_STATUS_ERROR;
|
||||
} else {
|
||||
if (Network_Port_IP_DNS_Server(object_instance, index, &ip_address)) {
|
||||
apdu_len = encode_application_octet_string(apdu, &ip_address);
|
||||
}
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* For a given object instance-number, sets the ip-address
|
||||
* Note: depends on Network_Type being set for this object
|
||||
@@ -1882,6 +1981,33 @@ bool Network_Port_IPv6_DNS_Server(uint32_t object_instance,
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Encode a BACnetARRAY property element; a function template
|
||||
* @param object_instance [in] BACnet network port object instance number
|
||||
* @param index [in] array index requested:
|
||||
* 0 to (array size - 1) for individual array members
|
||||
* @param apdu [out] Buffer in which the APDU contents are built, or
|
||||
* NULL to return the length of buffer if it had been built
|
||||
* @return The length of the apdu encoded, or
|
||||
* BACNET_STATUS_ERROR for an invalid array index
|
||||
*/
|
||||
static int Network_Port_IPv6_DNS_Server_Encode(
|
||||
uint32_t object_instance, BACNET_ARRAY_INDEX index, uint8_t *apdu)
|
||||
{
|
||||
int apdu_len = 0;
|
||||
BACNET_OCTET_STRING ip_address = { 0 };
|
||||
|
||||
if (index >= BIP_DNS_MAX) {
|
||||
apdu_len = BACNET_STATUS_ERROR;
|
||||
} else {
|
||||
if (Network_Port_IPv6_DNS_Server(object_instance, index, &ip_address)) {
|
||||
apdu_len = encode_application_octet_string(apdu, &ip_address);
|
||||
}
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* For a given object instance-number, sets the ip-address
|
||||
* Note: depends on Network_Type being set for this object
|
||||
@@ -2186,6 +2312,34 @@ bool Network_Port_MSTP_Max_Info_Frames_Set(
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the object property is a BACnetARRAY datatype
|
||||
* @param object_property [in] BACnet object property
|
||||
* @return true if the object property is a BACnetARRAY datatype
|
||||
*/
|
||||
bool Network_Port_BACnetArray_Property(BACNET_PROPERTY_ID object_property)
|
||||
{
|
||||
bool status = false;
|
||||
|
||||
switch (object_property) {
|
||||
case PROP_EVENT_TIME_STAMPS:
|
||||
case PROP_EVENT_MESSAGE_TEXTS:
|
||||
case PROP_EVENT_MESSAGE_TEXTS_CONFIG:
|
||||
case PROP_PROPERTY_LIST:
|
||||
case PROP_TAGS:
|
||||
case PROP_LINK_SPEEDS:
|
||||
case PROP_IP_DNS_SERVER:
|
||||
case PROP_IPV6_DNS_SERVER:
|
||||
case PROP_ISSUER_CERTIFICATE_FILES:
|
||||
status = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* ReadProperty handler for this object. For the given ReadProperty
|
||||
* data, the application_data is loaded or the error flags are set.
|
||||
@@ -2328,32 +2482,13 @@ int Network_Port_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata)
|
||||
apdu_len = encode_application_octet_string(&apdu[0], &octet_string);
|
||||
break;
|
||||
case PROP_IP_DNS_SERVER:
|
||||
if (rpdata->array_index == 0) {
|
||||
/* Array element zero is the number of objects in the list */
|
||||
apdu_len = encode_application_unsigned(&apdu[0], BIP_DNS_MAX);
|
||||
} else if (rpdata->array_index == BACNET_ARRAY_ALL) {
|
||||
/* if no index was specified, then try to encode the entire list
|
||||
*/
|
||||
/* into one packet. */
|
||||
int len;
|
||||
unsigned index;
|
||||
for (index = 0; index < BIP_DNS_MAX; index++) {
|
||||
Network_Port_IP_DNS_Server(
|
||||
rpdata->object_instance, index, &octet_string);
|
||||
len = encode_application_octet_string(
|
||||
&apdu[apdu_len], &octet_string);
|
||||
apdu_len += len;
|
||||
}
|
||||
} else if (rpdata->array_index <= BIP_DNS_MAX) {
|
||||
/* index was specified; encode a single array element */
|
||||
unsigned index;
|
||||
index = rpdata->array_index - 1;
|
||||
Network_Port_IP_DNS_Server(
|
||||
rpdata->object_instance, index, &octet_string);
|
||||
apdu_len =
|
||||
encode_application_octet_string(&apdu[0], &octet_string);
|
||||
} else {
|
||||
/* index was specified, but out of range */
|
||||
apdu_len = bacnet_array_encode(rpdata->object_instance,
|
||||
rpdata->array_index, Network_Port_IP_DNS_Server_Encode,
|
||||
BIP_DNS_MAX, apdu, apdu_size);
|
||||
if (apdu_len == BACNET_STATUS_ABORT) {
|
||||
rpdata->error_code =
|
||||
ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
|
||||
} else if (apdu_len == BACNET_STATUS_ERROR) {
|
||||
rpdata->error_class = ERROR_CLASS_PROPERTY;
|
||||
rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX;
|
||||
apdu_len = BACNET_STATUS_ERROR;
|
||||
@@ -2412,32 +2547,13 @@ int Network_Port_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata)
|
||||
apdu_len = encode_application_octet_string(&apdu[0], &octet_string);
|
||||
break;
|
||||
case PROP_IPV6_DNS_SERVER:
|
||||
if (rpdata->array_index == 0) {
|
||||
/* Array element zero is the number of objects in the list */
|
||||
apdu_len = encode_application_unsigned(&apdu[0], BIP_DNS_MAX);
|
||||
} else if (rpdata->array_index == BACNET_ARRAY_ALL) {
|
||||
/* if no index was specified, then try to encode the entire list
|
||||
*/
|
||||
/* into one packet. */
|
||||
int len;
|
||||
unsigned index;
|
||||
for (index = 0; index < BIP_DNS_MAX; index++) {
|
||||
Network_Port_IPv6_DNS_Server(
|
||||
rpdata->object_instance, index, &octet_string);
|
||||
len = encode_application_octet_string(
|
||||
&apdu[apdu_len], &octet_string);
|
||||
apdu_len += len;
|
||||
}
|
||||
} else if (rpdata->array_index <= BIP_DNS_MAX) {
|
||||
/* index was specified; encode a single array element */
|
||||
unsigned index;
|
||||
index = rpdata->array_index - 1;
|
||||
Network_Port_IPv6_DNS_Server(
|
||||
rpdata->object_instance, index, &octet_string);
|
||||
apdu_len =
|
||||
encode_application_octet_string(&apdu[0], &octet_string);
|
||||
} else {
|
||||
/* index was specified, but out of range */
|
||||
apdu_len = bacnet_array_encode(rpdata->object_instance,
|
||||
rpdata->array_index, Network_Port_IPv6_DNS_Server_Encode,
|
||||
BIP_DNS_MAX, apdu, apdu_size);
|
||||
if (apdu_len == BACNET_STATUS_ABORT) {
|
||||
rpdata->error_code =
|
||||
ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
|
||||
} else if (apdu_len == BACNET_STATUS_ERROR) {
|
||||
rpdata->error_class = ERROR_CLASS_PROPERTY;
|
||||
rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX;
|
||||
apdu_len = BACNET_STATUS_ERROR;
|
||||
@@ -2469,6 +2585,14 @@ int Network_Port_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata)
|
||||
(void)apdu_size;
|
||||
break;
|
||||
}
|
||||
/* only array properties can have optional array indices */
|
||||
if ((apdu_len >= 0) &&
|
||||
(!Network_Port_BACnetArray_Property(rpdata->object_property)) &&
|
||||
(rpdata->array_index != BACNET_ARRAY_ALL)) {
|
||||
rpdata->error_class = ERROR_CLASS_PROPERTY;
|
||||
rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
|
||||
apdu_len = BACNET_STATUS_ERROR;
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
@@ -2596,6 +2720,14 @@ int Network_Port_Read_Range_FDT(uint8_t *apdu, BACNET_READ_RANGE_DATA *pRequest)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* ReadRange service handler
|
||||
*
|
||||
* @param apdu - place to encode the data
|
||||
* @param pInfo - RR_PROP_INFO data
|
||||
*
|
||||
* @return number of bytes encoded
|
||||
*/
|
||||
bool Network_Port_Read_Range(
|
||||
BACNET_READ_RANGE_DATA *pRequest, RR_PROP_INFO *pInfo)
|
||||
{
|
||||
@@ -2672,6 +2804,44 @@ bool Network_Port_Read_Range(
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Activate any of the changes pending for all network port objects
|
||||
*/
|
||||
void Network_Port_Changes_Activate(void)
|
||||
{
|
||||
unsigned i = 0;
|
||||
|
||||
for (i = 0; i < BACNET_NETWORK_PORTS_MAX; i++) {
|
||||
if (Object_List[i].Changes_Pending) {
|
||||
Network_Port_Changes_Pending_Activate(i);
|
||||
Object_List[i].Changes_Pending = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Activate any of the changes pending for all network port objects
|
||||
*/
|
||||
void Network_Port_Changes_Discard(void)
|
||||
{
|
||||
unsigned i = 0;
|
||||
|
||||
for (i = 0; i < BACNET_NETWORK_PORTS_MAX; i++) {
|
||||
if (Object_List[i].Changes_Pending) {
|
||||
Network_Port_Changes_Pending_Discard(i);
|
||||
Object_List[i].Changes_Pending = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Cleanup - useful if network port object are allocated on the heap
|
||||
*/
|
||||
void Network_Port_Cleanup(void)
|
||||
{
|
||||
/* do something interesting */
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the Network Port object data
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user