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:
@@ -294,7 +294,7 @@ static long fsize(FILE *pFile)
|
||||
/**
|
||||
* @brief Read the entire file into a buffer
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @param buffer - pointer to buffer pointer where heap data will be stored
|
||||
* @param buffer - data store from the file
|
||||
* @param buffer_size - in bytes
|
||||
* @return file size in bytes
|
||||
*/
|
||||
@@ -322,6 +322,35 @@ uint32_t bacfile_read(uint32_t object_instance, uint8_t *buffer,
|
||||
return (uint32_t)file_size;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write the entire file from a buffer
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @param buffer - data store for the file
|
||||
* @param buffer_size - in bytes
|
||||
* @return file size in bytes
|
||||
*/
|
||||
uint32_t bacfile_write(uint32_t object_instance, uint8_t *buffer,
|
||||
uint32_t buffer_size)
|
||||
{
|
||||
const char *pFilename = NULL;
|
||||
FILE *pFile = NULL;
|
||||
long file_size = 0;
|
||||
|
||||
pFilename = bacfile_pathname(object_instance);
|
||||
if (pFilename) {
|
||||
/* open the file as a clean slate when starting at 0 */
|
||||
pFile = fopen(pFilename, "wb");
|
||||
if (pFile) {
|
||||
if (fwrite(buffer, buffer_size, 1, pFile) == 1) {
|
||||
file_size = buffer_size;
|
||||
}
|
||||
fclose(pFile);
|
||||
}
|
||||
}
|
||||
|
||||
return (uint32_t)file_size;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Determines the file size for a given file
|
||||
* @param pFile - file handle
|
||||
@@ -1053,5 +1082,7 @@ void bacfile_cleanup(void)
|
||||
*/
|
||||
void bacfile_init(void)
|
||||
{
|
||||
Object_List = Keylist_Create();
|
||||
if (!Object_List) {
|
||||
Object_List = Keylist_Create();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,6 +173,11 @@ extern "C" {
|
||||
uint32_t object_instance,
|
||||
uint8_t *buffer,
|
||||
uint32_t buffer_size);
|
||||
BACNET_STACK_EXPORT
|
||||
uint32_t bacfile_write(
|
||||
uint32_t object_instance,
|
||||
uint8_t *buffer,
|
||||
uint32_t buffer_size);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
uint32_t bacfile_create(
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include "bacnet/apdu.h"
|
||||
#include "bacnet/proplist.h"
|
||||
#include "bacnet/rp.h" /* ReadProperty handling */
|
||||
#include "bacnet/dcc.h" /* DeviceCommunicationControl handling */
|
||||
#include "bacnet/version.h"
|
||||
#include "bacnet/basic/services.h"
|
||||
#include "bacnet/datalink/datalink.h"
|
||||
@@ -165,6 +166,25 @@ static struct object_functions *Device_Objects_Find_Functions(
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/** Try to find a rr_info_function helper function for the requested object
|
||||
* type.
|
||||
* @ingroup ObjIntf
|
||||
*
|
||||
* @param object_type [in] The type of BACnet Object the handler wants to
|
||||
* access.
|
||||
* @return Pointer to the object helper function that implements the
|
||||
* ReadRangeInfo function, Object_RR_Info, for this type of Object on
|
||||
* success, else a NULL pointer if the type of Object isn't supported
|
||||
* or doesn't have a ReadRangeInfo function.
|
||||
*/
|
||||
rr_info_function Device_Objects_RR_Info(BACNET_OBJECT_TYPE object_type)
|
||||
{
|
||||
struct object_functions *pObject = NULL;
|
||||
|
||||
pObject = Device_Objects_Find_Functions(object_type);
|
||||
return (pObject != NULL ? pObject->Object_RR_Info : NULL);
|
||||
}
|
||||
|
||||
/** For a given object type, returns the special property list.
|
||||
* This function is used for ReadPropertyMultiple calls which want
|
||||
* just Required, just Optional, or All properties.
|
||||
@@ -250,6 +270,80 @@ void Device_Property_Lists(
|
||||
return;
|
||||
}
|
||||
|
||||
static BACNET_REINITIALIZED_STATE Reinitialize_State = BACNET_REINIT_IDLE;
|
||||
static const char *Reinit_Password = "filister";
|
||||
|
||||
/** Commands a Device re-initialization, to a given state.
|
||||
* The request's password must match for the operation to succeed.
|
||||
* This implementation provides a framework, but doesn't
|
||||
* actually *DO* anything.
|
||||
* @note You could use a mix of states and passwords to multiple outcomes.
|
||||
* @note You probably want to restart *after* the simple ack has been sent
|
||||
* from the return handler, so just set a local flag here.
|
||||
* @ingroup ObjIntf
|
||||
*
|
||||
* @param rd_data [in,out] The information from the RD request.
|
||||
* On failure, the error class and code will be set.
|
||||
* @return True if succeeds (password is correct), else False.
|
||||
*/
|
||||
bool Device_Reinitialize(BACNET_REINITIALIZE_DEVICE_DATA *rd_data)
|
||||
{
|
||||
bool status = false;
|
||||
|
||||
/* Note: you could use a mix of state and password to multiple things */
|
||||
if (characterstring_ansi_same(&rd_data->password, Reinit_Password)) {
|
||||
switch (rd_data->state) {
|
||||
case BACNET_REINIT_COLDSTART:
|
||||
dcc_set_status_duration(COMMUNICATION_ENABLE, 0);
|
||||
/* note: you probably want to restart *after* the
|
||||
simple ack has been sent from the return handler
|
||||
so just set a flag from here */
|
||||
Reinitialize_State = rd_data->state;
|
||||
status = true;
|
||||
break;
|
||||
case BACNET_REINIT_WARMSTART:
|
||||
dcc_set_status_duration(COMMUNICATION_ENABLE, 0);
|
||||
/* note: restart *after* the simple ack has been sent */
|
||||
Reinitialize_State = rd_data->state;
|
||||
status = true;
|
||||
break;
|
||||
case BACNET_REINIT_STARTBACKUP:
|
||||
case BACNET_REINIT_ENDBACKUP:
|
||||
case BACNET_REINIT_STARTRESTORE:
|
||||
case BACNET_REINIT_ENDRESTORE:
|
||||
case BACNET_REINIT_ABORTRESTORE:
|
||||
if (dcc_communication_disabled()) {
|
||||
rd_data->error_class = ERROR_CLASS_SERVICES;
|
||||
rd_data->error_code = ERROR_CODE_COMMUNICATION_DISABLED;
|
||||
} else {
|
||||
rd_data->error_class = ERROR_CLASS_SERVICES;
|
||||
rd_data->error_code =
|
||||
ERROR_CODE_OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED;
|
||||
}
|
||||
break;
|
||||
case BACNET_REINIT_ACTIVATE_CHANGES:
|
||||
/* note: activate changes *after* the simple ack is sent */
|
||||
Reinitialize_State = rd_data->state;
|
||||
status = true;
|
||||
break;
|
||||
default:
|
||||
rd_data->error_class = ERROR_CLASS_SERVICES;
|
||||
rd_data->error_code = ERROR_CODE_PARAMETER_OUT_OF_RANGE;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
rd_data->error_class = ERROR_CLASS_SECURITY;
|
||||
rd_data->error_code = ERROR_CODE_PASSWORD_FAILURE;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
BACNET_REINITIALIZED_STATE Device_Reinitialized_State(void)
|
||||
{
|
||||
return Reinitialize_State;
|
||||
}
|
||||
|
||||
unsigned Device_Count(void)
|
||||
{
|
||||
return 1;
|
||||
@@ -323,6 +417,11 @@ bool Device_Set_Object_Name(BACNET_CHARACTER_STRING *object_name)
|
||||
return status;
|
||||
}
|
||||
|
||||
bool Device_Object_Name_ANSI_Init(const char *value)
|
||||
{
|
||||
return characterstring_init_ansi(&My_Object_Name, value);
|
||||
}
|
||||
|
||||
BACNET_DEVICE_STATUS Device_System_Status(void)
|
||||
{
|
||||
return System_Status;
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -68,6 +68,9 @@ extern "C" {
|
||||
bool Network_Port_Name_Set(
|
||||
uint32_t object_instance,
|
||||
char *new_name);
|
||||
BACNET_STACK_EXPORT
|
||||
const char *Network_Port_Object_Name_ASCII(
|
||||
uint32_t object_instance);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
char *Network_Port_Description(
|
||||
@@ -122,6 +125,11 @@ extern "C" {
|
||||
uint32_t object_instance,
|
||||
BACNET_OCTET_STRING *mac_address);
|
||||
BACNET_STACK_EXPORT
|
||||
uint8_t Network_Port_MAC_Address_Value(
|
||||
uint32_t object_instance,
|
||||
uint8_t *mac_address,
|
||||
size_t mac_size);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Network_Port_MAC_Address_Set(
|
||||
uint32_t object_instance,
|
||||
uint8_t *mac_src,
|
||||
@@ -369,6 +377,12 @@ extern "C" {
|
||||
bool Network_Port_Changes_Pending_Set(
|
||||
uint32_t instance,
|
||||
bool flag);
|
||||
BACNET_STACK_EXPORT
|
||||
void Network_Port_Changes_Pending_Activate(
|
||||
uint32_t instance);
|
||||
BACNET_STACK_EXPORT
|
||||
void Network_Port_Changes_Pending_Discard(
|
||||
uint32_t instance);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
bool Network_Port_Valid_Instance(
|
||||
@@ -408,6 +422,12 @@ extern "C" {
|
||||
bool Network_Port_Delete(
|
||||
uint32_t object_instance);
|
||||
BACNET_STACK_EXPORT
|
||||
void Network_Port_Changes_Activate(
|
||||
void);
|
||||
BACNET_STACK_EXPORT
|
||||
void Network_Port_Changes_Discard(
|
||||
void);
|
||||
BACNET_STACK_EXPORT
|
||||
void Network_Port_Cleanup(
|
||||
void);
|
||||
BACNET_STACK_EXPORT
|
||||
|
||||
+151
-27
@@ -37,81 +37,205 @@
|
||||
#include <stdio.h> /* Standard I/O */
|
||||
#include <stdlib.h> /* Standard Library */
|
||||
#include <stdarg.h>
|
||||
#if DEBUG_ENABLED
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#endif
|
||||
#include "bacnet/basic/sys/debug.h"
|
||||
|
||||
#if DEBUG_PRINTF_WITH_TIMESTAMP
|
||||
#include "bacnet/datetime.h"
|
||||
#endif
|
||||
/** @file debug.c Debug print function */
|
||||
|
||||
#if DEBUG_ENABLED
|
||||
#if DEBUG_PRINTF_WITH_TIMESTAMP
|
||||
/**
|
||||
* @brief Print timestamp with a printf string
|
||||
* @param format - printf format string
|
||||
* @param ... - variable arguments
|
||||
* @note This function is only available if
|
||||
* DEBUG_PRINTF_WITH_TIMESTAMP is non-zero
|
||||
* and DEBUG_ENABLED is non-zero
|
||||
*/
|
||||
void debug_printf(const char *format, ...)
|
||||
{
|
||||
#if DEBUG_ENABLED
|
||||
va_list ap;
|
||||
char stamp_str[64];
|
||||
char buf[1024];
|
||||
BACNET_DATE date;
|
||||
BACNET_TIME time;
|
||||
datetime_local(&date, &time, NULL, NULL);
|
||||
sprintf(stamp_str, "[%02d:%02d:%02d.%03d]: ", time.hour, time.min,
|
||||
time.sec, time.hundredths * 10);
|
||||
|
||||
va_start(ap, format);
|
||||
vsprintf(buf, format, ap);
|
||||
va_end(ap);
|
||||
printf("%s%s", stamp_str, buf);
|
||||
fflush(stdout);
|
||||
#else
|
||||
(void)format;
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
/**
|
||||
* @brief Print with a printf string
|
||||
* @param format - printf format string
|
||||
* @param ... - variable arguments
|
||||
* @note This function is only available if
|
||||
* DEBUG_ENABLED is non-zero
|
||||
*/
|
||||
void debug_printf(const char *format, ...)
|
||||
{
|
||||
#if DEBUG_ENABLED
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
vfprintf(stdout, format, ap);
|
||||
va_end(ap);
|
||||
fflush(stdout);
|
||||
|
||||
return;
|
||||
}
|
||||
#else
|
||||
void debug_printf(const char *format, ...)
|
||||
{
|
||||
(void)format;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if PRINT_ENABLED
|
||||
/**
|
||||
* @brief print format with HEX dump of a buffer
|
||||
* @param offset - starting address to print to the left side
|
||||
* @param buffer - buffer from which to print hex from
|
||||
* @param buffer_length - number of bytes from the buffer to print
|
||||
* @param format - printf format string
|
||||
* @param ... - variable arguments
|
||||
* @note This function is only available if DEBUG_ENABLED is non-zero
|
||||
*/
|
||||
void debug_printf_hex(
|
||||
uint32_t offset,
|
||||
const uint8_t *buffer,
|
||||
size_t buffer_length,
|
||||
const char *format, ...)
|
||||
{
|
||||
#if DEBUG_ENABLED
|
||||
size_t i = 0;
|
||||
bool new_line = true;
|
||||
char line[16+1] = {0};
|
||||
size_t remainder = 0;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
vfprintf(stdout, format, ap);
|
||||
va_end(ap);
|
||||
/* print the buffer after the formatted text */
|
||||
if (buffer && buffer_length) {
|
||||
for (i = 0; i < buffer_length; i++) {
|
||||
if (new_line) {
|
||||
new_line = false;
|
||||
printf("%08x ", (unsigned int)(offset+i));
|
||||
memset(line, '.', sizeof(line)-1);
|
||||
}
|
||||
printf("%02x ", buffer[i]);
|
||||
if (isprint(buffer[i])) {
|
||||
line[i%16] = buffer[i];
|
||||
}
|
||||
if ((i != 0) && (!((i+1)%16))) {
|
||||
printf(" %s\n", line);
|
||||
new_line = true;
|
||||
}
|
||||
}
|
||||
remainder = buffer_length%16;
|
||||
if (remainder) {
|
||||
for (i = 0; i < (16-remainder); i++) {
|
||||
printf(" ");
|
||||
}
|
||||
printf(" %s\n", line);
|
||||
}
|
||||
}
|
||||
fflush(stdout);
|
||||
#else
|
||||
(void)offset;
|
||||
(void)buffer;
|
||||
(void)buffer_length;
|
||||
(void)format;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Print with a printf string
|
||||
* @param format - printf format string
|
||||
* @param ... - variable arguments
|
||||
* @note This function is only available if
|
||||
* PRINT_ENABLED is non-zero
|
||||
* @return number of characters printed
|
||||
*/
|
||||
int debug_aprintf(const char *format, ...)
|
||||
{
|
||||
int length = 0;
|
||||
#if PRINT_ENABLED
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
length = vfprintf(stdout, format, ap);
|
||||
va_end(ap);
|
||||
fflush(stdout);
|
||||
|
||||
#else
|
||||
(void)format;
|
||||
#endif
|
||||
return length;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Print with a printf string
|
||||
* @param stream - file stream to print to
|
||||
* @param format - printf format string
|
||||
* @param ... - variable arguments
|
||||
* @note This function is only available if
|
||||
* PRINT_ENABLED is non-zero
|
||||
* @return number of characters printed
|
||||
*/
|
||||
int debug_fprintf(FILE *stream, const char *format, ...)
|
||||
{
|
||||
int length = 0;
|
||||
#if PRINT_ENABLED
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
length = vfprintf(stream, format, ap);
|
||||
va_end(ap);
|
||||
fflush(stream);
|
||||
|
||||
#else
|
||||
(void)format;
|
||||
#endif
|
||||
return length;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Print with a perror string
|
||||
* @param format - printf format string
|
||||
* @param ... - variable arguments
|
||||
* @note This function is only available if
|
||||
* PRINT_ENABLED is non-zero
|
||||
*/
|
||||
void debug_perror(const char *format, ...)
|
||||
{
|
||||
#if PRINT_ENABLED
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
vfprintf(stderr, format, ap);
|
||||
va_end(ap);
|
||||
fflush(stderr);
|
||||
}
|
||||
#else
|
||||
int debug_aprintf(const char *format, ...)
|
||||
{
|
||||
(void)format;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int debug_fprintf(FILE *stream, const char *format, ...)
|
||||
{
|
||||
(void)stream;
|
||||
(void)format;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void debug_perror(const char *format, ...)
|
||||
{
|
||||
(void)format;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Print with a printf string that does nothing
|
||||
* @param format - printf format string
|
||||
* @param ... - variable arguments
|
||||
* @note useful when used with defines such as PRINTF
|
||||
*/
|
||||
void debug_printf_disabled(const char *format, ...)
|
||||
{
|
||||
(void)format;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,10 @@
|
||||
#define DEBUG_ENABLED 0
|
||||
#endif
|
||||
|
||||
#ifndef DEBUG_PRINTF_WITH_TIMESTAMP
|
||||
#define DEBUG_PRINTF_WITH_TIMESTAMP 0
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
@@ -55,17 +59,18 @@ extern "C" {
|
||||
void debug_perror(
|
||||
const char *format,
|
||||
...);
|
||||
#if DEBUG_ENABLED
|
||||
/* Nothing more here */
|
||||
#else
|
||||
/* If your compiler supports it, this is more compact:
|
||||
inline void debug_printf(
|
||||
const char *format,
|
||||
...) {
|
||||
format = format;
|
||||
}
|
||||
*/
|
||||
#endif
|
||||
BACNET_STACK_EXPORT
|
||||
void debug_printf_hex(
|
||||
uint32_t offset,
|
||||
const uint8_t *buffer,
|
||||
size_t buffer_length,
|
||||
const char *format, ...);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
void debug_printf_disabled(
|
||||
const char *format,
|
||||
...);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@@ -172,6 +172,39 @@ uint8_t FIFO_Peek(FIFO_BUFFER const *b)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Peeks ahead from the front of the FIFO without removing any data.
|
||||
* Limit the number of bytes peeked to the number of bytes available.
|
||||
*
|
||||
* @param b - pointer to FIFO_BUFFER structure
|
||||
* @param buffer [out] - buffer to hold the peeked bytes
|
||||
* @param length [in] - number of bytes to peek from the FIFO
|
||||
* @return number of bytes peeked
|
||||
*/
|
||||
unsigned FIFO_Peek_Ahead(FIFO_BUFFER const *b, uint8_t* buffer, unsigned length)
|
||||
{
|
||||
unsigned count = 0;
|
||||
unsigned index;
|
||||
unsigned tail;
|
||||
unsigned i;
|
||||
|
||||
if (b) {
|
||||
count = FIFO_Count(b);
|
||||
if (count > length) {
|
||||
/* adjust to limit the number of bytes peeked */
|
||||
count = length;
|
||||
}
|
||||
tail = b->tail;
|
||||
for(i = 0; i < count; i++) {
|
||||
index = tail % b->buffer_len;
|
||||
buffer[i] = b->buffer[index];
|
||||
tail++;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a byte from the front of the FIFO, and removes it.
|
||||
* Use FIFO_Empty() or FIFO_Available() function to see if there is
|
||||
|
||||
@@ -77,6 +77,12 @@ extern "C" {
|
||||
uint8_t FIFO_Peek(
|
||||
FIFO_BUFFER const *b);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
unsigned FIFO_Peek_Ahead(
|
||||
FIFO_BUFFER const *b,
|
||||
uint8_t* data_bytes,
|
||||
unsigned length);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
uint8_t FIFO_Get(
|
||||
FIFO_BUFFER * b);
|
||||
|
||||
Reference in New Issue
Block a user