Make most of functions const correct (#714)

* Make most of the functions const correct

Used clang-tidy and sonarlint to help find places where const could
pretty easily applied. Also lot of hand work.

This commit does not yet touch handlers and typedefs of those.

* Fix Arduino uno handler_who_is() has extra parenthesis

For some reason there is extra parenthesis. Remove it this is more
likely buildable.

* Bugfix/bacapp: Fix uninitilized array_index

We have changed bacapp_snprintf_value() to be const correct. After that
we got

```
/home/runner/work/bacnet-stack/bacnet-stack/src/bacnet/bacapp.c:3183:27: warning: 4th function call argument is an uninitialized value [core.CallAndMessage]
                ret_val = bacapp_snprintf_weeklyschedule(
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
```

So analyzer could now spot that we do not actually initilize array_index
at all. Fix this by setting array_index to zero. Note that I actually do
not know if zeroing is right thing to do here. I choose zero as if this
has worked before it is most likely that it will work with zero value.

* cmake: Add and ignore Wwrite-strings compiler option

Wwrite-strings helps find places where const correctness is broken.

Example it will warn about these

```C

void func1(char* str);

func("test") /* "test" is const so we should not pass it to func1().

char* func2()
{
  return "test"; /* func2() should return const char*.
}
```

We still need to ignore it as not all are fixed but let's add it already
so we remember that it should be opened at some point.

---------

Co-authored-by: Kari Argillander <kari.argillander@fidelix.com>
This commit is contained in:
Kari Argillander
2024-08-29 22:08:02 +03:00
committed by GitHub
parent 0177c59f4a
commit a2f1d6959d
408 changed files with 2608 additions and 2336 deletions
+3 -3
View File
@@ -74,14 +74,14 @@ static void Init_Service_Handlers(void)
apdu_set_reject_handler(MyRejectHandler);
}
static void print_usage(char *filename)
static void print_usage(const char *filename)
{
printf("Usage: %s [abort-reason [invoke-id [server]]]\n", filename);
printf(" [--dnet][--dadr][--mac]\n");
printf(" [--version][--help]\n");
}
static void print_help(char *filename)
static void print_help(const char *filename)
{
printf("Send BACnet Abort message to the network.\n");
printf("--mac A\n"
@@ -123,7 +123,7 @@ int main(int argc, char *argv[])
bool specific_address = false;
int argi = 0;
unsigned int target_args = 0;
char *filename = NULL;
const char *filename = NULL;
filename = filename_remove_path(argv[0]);
for (argi = 1; argi < argc; argi++) {
+3 -3
View File
@@ -141,7 +141,7 @@ static void Init_Service_Handlers(void)
apdu_set_reject_handler(MyRejectHandler);
}
static void print_usage(char *filename)
static void print_usage(const char *filename)
{
printf("Usage: %s device-id process-id\n"
" event-object-type event-object-instance event-state-acked\n"
@@ -151,7 +151,7 @@ static void print_usage(char *filename)
printf(" [--version][--help]\n");
}
static void print_help(char *filename)
static void print_help(const char *filename)
{
printf("Send BACnet AcknowledgedAlarm, message to a device.\n");
printf("device-id:\n"
@@ -222,7 +222,7 @@ int main(int argc, char *argv[])
bool specific_address = false;
int argi = 0;
unsigned int target_args = 0;
char *filename = NULL;
const char *filename = NULL;
filename = filename_remove_path(argv[0]);
for (argi = 1; argi < argc; argi++) {
+3 -3
View File
@@ -137,7 +137,7 @@ static void Init_Service_Handlers(void)
apdu_set_reject_handler(MyRejectHandler);
}
static void print_usage(char *filename)
static void print_usage(const char *filename)
{
printf("Usage: %s device-instance object-type object-instance "
"property array-index tag value\n",
@@ -146,7 +146,7 @@ static void print_usage(char *filename)
printf(" [--version][--help][--verbose]\n");
}
static void print_help(char *filename)
static void print_help(const char *filename)
{
printf("Add a BACnetLIST element to a property of an object\n"
"in a BACnet device.\n");
@@ -244,7 +244,7 @@ int main(int argc, char *argv[])
bool specific_address = false;
unsigned int target_args = 0;
int argi = 0;
char *filename = NULL;
const char *filename = NULL;
filename = filename_remove_path(argv[0]);
for (argi = 1; argi < argc; argi++) {
+4 -4
View File
@@ -123,7 +123,7 @@ static void init_service_handlers(void)
/**
* @brief Print the usage message
*/
static void print_usage(char *filename)
static void print_usage(const char *filename)
{
printf("Usage: %s", filename);
printf(" <device-instance> <hex-ASCII>\n");
@@ -135,7 +135,7 @@ static void print_usage(char *filename)
/**
* @brief Print the help message
*/
static void print_help(char *filename)
static void print_help(const char *filename)
{
printf("Send an arbitrary BACnet APDU to a device.\n");
printf("\n");
@@ -199,7 +199,7 @@ static void print_help(char *filename)
* @param buffer_len [in] The size of the buffer.
*/
static void Send_APDU_To_Network(
BACNET_ADDRESS *target_address, uint8_t *buffer, size_t buffer_len)
BACNET_ADDRESS *target_address, const uint8_t *buffer, size_t buffer_len)
{
int pdu_len = 0;
int bytes_sent = 0;
@@ -288,7 +288,7 @@ int main(int argc, char *argv[])
bool found = false;
int argi = 0;
unsigned int target_args = 0;
char *filename = NULL;
const char *filename = NULL;
bool repeat_forever = false;
long retry_count = 1;
+2 -2
View File
@@ -462,7 +462,7 @@ bool Device_Object_Name(
return status;
}
bool Device_Set_Object_Name(BACNET_CHARACTER_STRING *object_name)
bool Device_Set_Object_Name(const BACNET_CHARACTER_STRING *object_name)
{
bool status = false; /*return value */
@@ -1198,7 +1198,7 @@ int Device_Read_Property_Local(BACNET_READ_PROPERTY_DATA *rpdata)
* @return The length of the APDU on success, else BACNET_STATUS_ERROR
*/
static int Read_Property_Common(
struct object_functions *pObject, BACNET_READ_PROPERTY_DATA *rpdata)
const struct object_functions *pObject, BACNET_READ_PROPERTY_DATA *rpdata)
{
int apdu_len = BACNET_STATUS_ERROR;
BACNET_CHARACTER_STRING char_string;
+1 -1
View File
@@ -343,7 +343,7 @@ int main(int argc, char *argv[])
unsigned int target_args = 0;
uint32_t device_id = BACNET_MAX_INSTANCE;
int argi = 0;
char *filename = NULL;
const char *filename = NULL;
filename = filename_remove_path(argv[0]);
for (argi = 1; argi < argc; argi++) {
+3 -3
View File
@@ -175,7 +175,7 @@ static void Init_Service_Handlers(void)
apdu_set_reject_handler(MyRejectHandler);
}
static void print_usage(char *filename)
static void print_usage(const char *filename)
{
printf(
"Usage: %s device-instance object-type [object-instance]\n", filename);
@@ -183,7 +183,7 @@ static void print_usage(char *filename)
printf(" [--version][--help][--verbose]\n");
}
static void print_help(char *filename)
static void print_help(const char *filename)
{
printf("Create an object in a BACnet device.\n");
printf("\n");
@@ -232,7 +232,7 @@ int main(int argc, char *argv[])
bool specific_address = false;
unsigned int target_args = 0;
int argi = 0;
char *filename = NULL;
const char *filename = NULL;
filename = filename_remove_path(argv[0]);
for (argi = 1; argi < argc; argi++) {
+3 -3
View File
@@ -116,13 +116,13 @@ static void Init_Service_Handlers(void)
apdu_set_reject_handler(MyRejectHandler);
}
static void print_usage(char *filename)
static void print_usage(const char *filename)
{
printf("Usage: %s device-instance state [timeout [password]]\n", filename);
printf(" [--version][--help]\n");
}
static void print_help(char *filename)
static void print_help(const char *filename)
{
printf(
"Send BACnet DeviceCommunicationControl service to device.\n"
@@ -155,7 +155,7 @@ int main(int argc, char *argv[])
uint8_t invoke_id = 0;
bool found = false;
int argi = 0;
char *filename = NULL;
const char *filename = NULL;
filename = filename_remove_path(argv[0]);
for (argi = 1; argi < argc; argi++) {
+3 -3
View File
@@ -136,7 +136,7 @@ static void Init_Service_Handlers(void)
apdu_set_reject_handler(MyRejectHandler);
}
static void print_usage(char *filename)
static void print_usage(const char *filename)
{
printf("Usage: %s device-instance object-type object-instance\n",
filename);
@@ -144,7 +144,7 @@ static void print_usage(char *filename)
printf(" [--version][--help][--verbose]\n");
}
static void print_help(char *filename)
static void print_help(const char *filename)
{
printf("Create an object in a BACnet device.\n");
printf("\n");
@@ -193,7 +193,7 @@ int main(int argc, char *argv[])
bool specific_address = false;
unsigned int target_args = 0;
int argi = 0;
char *filename = NULL;
const char *filename = NULL;
filename = filename_remove_path(argv[0]);
for (argi = 1; argi < argc; argi++) {
+4 -4
View File
@@ -710,7 +710,7 @@ static void BuildPropRequest(BACNET_READ_ACCESS_DATA *rpm_object)
* of the property list.
*/
static uint8_t Read_Properties(
uint32_t device_instance, BACNET_OBJECT_ID *pMyObject)
uint32_t device_instance, const BACNET_OBJECT_ID *pMyObject)
{
uint8_t invoke_id = 0;
struct special_property_list_t PropertyListStruct;
@@ -884,7 +884,7 @@ static EPICS_STATES ProcessRPMData(
return nextState;
}
static void print_usage(char *filename)
static void print_usage(const char *filename)
{
printf("Usage: %s [-v] [-d] [-p sport] [-t target_mac [-n dnet]]"
" device-instance\n",
@@ -892,7 +892,7 @@ static void print_usage(char *filename)
printf(" [--version][--help]\n");
}
static void print_help(char *filename)
static void print_help(const char *filename)
{
(void)filename;
printf("Generates Full EPICS file, including Object and Property List\n");
@@ -921,7 +921,7 @@ static int CheckCommandLineArgs(int argc, char *argv[])
int i;
bool bFoundTarget = false;
int argi = 0;
char *filename = NULL;
const char *filename = NULL;
filename = filename_remove_path(argv[0]);
for (argi = 1; argi < argc; argi++) {
+3 -3
View File
@@ -75,7 +75,7 @@ static void Init_Service_Handlers(void)
apdu_set_reject_handler(MyRejectHandler);
}
static void print_usage(char *filename)
static void print_usage(const char *filename)
{
printf("Usage: %s [error-class error-code service-number invoke-id]\n",
filename);
@@ -83,7 +83,7 @@ static void print_usage(char *filename)
printf(" [--version][--help]\n");
}
static void print_help(char *filename)
static void print_help(const char *filename)
{
printf("Send BACnet Error message to the network.\n");
printf("--mac A\n"
@@ -125,7 +125,7 @@ int main(int argc, char *argv[])
bool specific_address = false;
int argi = 0;
unsigned int target_args = 0;
char *filename = NULL;
const char *filename = NULL;
filename = filename_remove_path(argv[0]);
for (argi = 1; argi < argc; argi++) {
+3 -3
View File
@@ -141,7 +141,7 @@ static void Init_Service_Handlers(void)
apdu_set_reject_handler(MyRejectHandler);
}
static void print_usage(char *filename)
static void print_usage(const char *filename)
{
printf("Usage: %s device-id process-id initiating-device-id\n"
" event-object-type event-object-instance\n"
@@ -154,7 +154,7 @@ static void print_usage(char *filename)
printf(" [--version][--help]\n");
}
static void print_help(char *filename)
static void print_help(const char *filename)
{
printf("Send BACnet ConfirmedEventNotification message to a device.\n");
printf("device-id:\n"
@@ -246,7 +246,7 @@ int main(int argc, char *argv[])
bool specific_address = false;
int argi = 0;
unsigned int target_args = 0;
char *filename = NULL;
const char *filename = NULL;
unsigned found_index = 0;
filename = filename_remove_path(argv[0]);
+1 -1
View File
@@ -160,7 +160,7 @@ static void Init_Service_Handlers(void)
apdu_set_reject_handler(MyRejectHandler);
}
static int print_help(char *exe_name)
static int print_help(const char *exe_name)
{
printf("Usage:\n"
"\n"
+3 -3
View File
@@ -78,7 +78,7 @@ static void Init_Service_Handlers(void)
apdu_set_reject_handler(MyRejectHandler);
}
static void print_usage(char *filename)
static void print_usage(const char *filename)
{
printf("Usage: %s [device-instance vendor-id max-apdu segmentation]\n",
filename);
@@ -86,7 +86,7 @@ static void print_usage(char *filename)
printf(" [--version][--help]\n");
}
static void print_help(char *filename)
static void print_help(const char *filename)
{
printf("Send BACnet I-Am message for a device.\n");
printf("--mac A\n"
@@ -149,7 +149,7 @@ int main(int argc, char *argv[])
unsigned timeout = 100; /* milliseconds */
int argi = 0;
unsigned int target_args = 0;
char *filename = NULL;
const char *filename = NULL;
long retry_count = 0;
filename = filename_remove_path(argv[0]);
+3 -3
View File
@@ -75,13 +75,13 @@ static void Init_Service_Handlers(void)
apdu_set_reject_handler(MyRejectHandler);
}
static void print_usage(char *filename)
static void print_usage(const char *filename)
{
printf("Usage: %s DNET [DNET] [DNET] [...]\n", filename);
printf(" [--version][--help]\n");
}
static void print_help(char *filename)
static void print_help(const char *filename)
{
printf("Send BACnet I-Am-Router-To-Network message for \n"
"one or more networks.\n"
@@ -99,7 +99,7 @@ int main(int argc, char *argv[])
{
unsigned arg_count = 0;
int argi = 0;
char *filename = NULL;
const char *filename = NULL;
filename = filename_remove_path(argv[0]);
for (argi = 1; argi < argc; argi++) {
+3 -3
View File
@@ -211,13 +211,13 @@ static void Init_Service_Handlers(void)
apdu_set_reject_handler(MyRejectHandler);
}
static void print_usage(char *filename)
static void print_usage(const char *filename)
{
printf("Usage: %s address [DNET ID Len Info]\n", filename);
printf(" [--version][--help]\n");
}
static void print_help(char *filename)
static void print_help(const char *filename)
{
printf(
"Send BACnet Initialize-Routing-Table message to a network\n"
@@ -286,7 +286,7 @@ int main(int argc, char *argv[])
time_t current_seconds = 0;
time_t timeout_seconds = 0;
int argi = 0;
char *filename = NULL;
const char *filename = NULL;
filename = filename_remove_path(argv[0]);
for (argi = 1; argi < argc; argi++) {
+14 -11
View File
@@ -121,7 +121,8 @@ struct mstp_statistics {
static struct mstp_statistics MSTP_Statistics[MAX_MSTP_DEVICES];
static uint32_t Invalid_Frame_Count;
static uint32_t timeval_diff_ms(struct timeval *old, struct timeval *now)
static uint32_t timeval_diff_ms(
const struct timeval *old, const struct timeval *now)
{
uint32_t ms = 0;
@@ -132,17 +133,18 @@ static uint32_t timeval_diff_ms(struct timeval *old, struct timeval *now)
return ms;
}
static void mstp_monitor_i_am(uint8_t mac, uint8_t *pdu, uint16_t pdu_len)
static void mstp_monitor_i_am(
uint8_t mac, const uint8_t *pdu, uint16_t pdu_len)
{
BACNET_ADDRESS src = { 0 };
BACNET_ADDRESS dest = { 0 };
BACNET_NPDU_DATA npdu_data = { 0 };
int apdu_offset = 0;
uint16_t apdu_len = 0;
uint8_t *apdu = NULL;
const uint8_t *apdu = NULL;
uint8_t pdu_type = 0;
uint8_t service_choice = 0;
uint8_t *service_request = NULL;
const uint8_t *service_request = NULL;
uint32_t device_id = 0;
int len = 0;
@@ -171,7 +173,8 @@ static void mstp_monitor_i_am(uint8_t mac, uint8_t *pdu, uint16_t pdu_len)
}
static void packet_statistics(
struct timeval *tv, struct mstp_port_struct_t *mstp_port)
const struct timeval *tv,
const struct mstp_port_struct_t *mstp_port)
{
static struct timeval old_tv = { 0 };
static uint8_t old_frame = 255;
@@ -423,7 +426,7 @@ uint16_t MSTP_Get_Send(
*/
void MSTP_Send_Frame(
struct mstp_port_struct_t *mstp_port,
uint8_t * buffer,
const uint8_t * buffer,
uint16_t nbytes)
{
(void)mstp_port;
@@ -443,7 +446,7 @@ static char Capture_Filename[64] = "mstp_20090123091200.cap";
static FILE *File_Handle = NULL; /* stream pointer */
#if defined(_WIN32)
static HANDLE Pipe_Handle = INVALID_HANDLE_VALUE; /* pipe handle */
static void named_pipe_create(char *pipe_name)
static void named_pipe_create(const char *pipe_name)
{
if (!Wireshark_Capture) {
fprintf(stdout, "mstpcap: Creating Named Pipe \"%s\"\n", pipe_name);
@@ -510,7 +513,7 @@ static size_t data_write_header(
}
#else
static int FD_Pipe = -1;
static void named_pipe_create(char *name)
static void named_pipe_create(const char *name)
{
int rv = 0;
rv = mkfifo(name, 0666);
@@ -915,7 +918,7 @@ static void signal_init(void)
}
#endif
static void print_usage(char *filename)
static void print_usage(const char *filename)
{
printf("Usage: %s", filename);
printf(" [--scan <filename>]\n");
@@ -925,7 +928,7 @@ static void print_usage(char *filename)
printf(" [--version][--help]\n");
}
static void print_help(char *filename)
static void print_help(const char *filename)
{
printf("%s --scan <filename>\n"
"perform statistic analysis on MS/TP capture file.\n",
@@ -986,7 +989,7 @@ int main(int argc, char *argv[])
uint32_t packet_count = 0;
uint32_t header_len = 0;
int argi = 0;
char *filename = NULL;
const char *filename = NULL;
MSTP_Port.InputBuffer = &RxBuffer[0];
MSTP_Port.InputBufferSize = sizeof(RxBuffer);
+3 -3
View File
@@ -444,7 +444,7 @@ bool Device_Object_Name(
return status;
}
bool Device_Set_Object_Name(BACNET_CHARACTER_STRING *object_name)
bool Device_Set_Object_Name(const BACNET_CHARACTER_STRING *object_name)
{
bool status = false; /*return value */
@@ -785,7 +785,7 @@ int Device_Object_List_Element_Encode(
* Object.
* @return True on success or else False if not found.
*/
bool Device_Valid_Object_Name(BACNET_CHARACTER_STRING *object_name1,
bool Device_Valid_Object_Name(const BACNET_CHARACTER_STRING *object_name1,
BACNET_OBJECT_TYPE *object_type,
uint32_t *object_instance)
{
@@ -1180,7 +1180,7 @@ int Device_Read_Property_Local(BACNET_READ_PROPERTY_DATA *rpdata)
* @return The length of the APDU on success, else BACNET_STATUS_ERROR
*/
static int Read_Property_Common(
struct object_functions *pObject, BACNET_READ_PROPERTY_DATA *rpdata)
const struct object_functions *pObject, BACNET_READ_PROPERTY_DATA *rpdata)
{
int apdu_len = BACNET_STATUS_ERROR;
BACNET_CHARACTER_STRING char_string;
+3 -3
View File
@@ -205,13 +205,13 @@ static void Init_Service_Handlers(void)
apdu_set_reject_handler(MyRejectHandler);
}
static void print_usage(char *filename)
static void print_usage(const char *filename)
{
printf("Usage: %s device-instance file-instance local-name\n", filename);
printf(" [--version][--help]\n");
}
static void print_help(char *filename)
static void print_help(const char *filename)
{
printf(
"Read a file from a BACnet device and save it locally.\n");
@@ -251,7 +251,7 @@ int main(int argc, char *argv[])
bool found = false;
uint16_t my_max_apdu = 0;
int argi = 0;
char *filename = NULL;
const char *filename = NULL;
/* print help if requested */
filename = filename_remove_path(argv[0]);
+3 -3
View File
@@ -147,7 +147,7 @@ static void Init_Service_Handlers(void)
apdu_set_reject_handler(MyRejectHandler);
}
static void print_usage(char *filename)
static void print_usage(const char *filename)
{
printf("Usage: %s device-instance object-type object-instance "
"property [index]\n",
@@ -156,7 +156,7 @@ static void print_usage(char *filename)
printf(" [--version][--help]\n");
}
static void print_help(char *filename)
static void print_help(const char *filename)
{
printf("Read a property from an object in a BACnet device\n"
"and print the value.\n");
@@ -255,7 +255,7 @@ int main(int argc, char *argv[])
unsigned object_type = 0;
unsigned object_property = 0;
unsigned int target_args = 0;
char *filename = NULL;
const char *filename = NULL;
filename = filename_remove_path(argv[0]);
for (argi = 1; argi < argc; argi++) {
+4 -4
View File
@@ -199,7 +199,7 @@ static void cleanup(void)
}
static void target_address_add(
long dnet, BACNET_MAC_ADDRESS *mac, BACNET_MAC_ADDRESS *adr)
long dnet, const BACNET_MAC_ADDRESS *mac, const BACNET_MAC_ADDRESS *adr)
{
BACNET_ADDRESS dest = { 0 };
@@ -234,7 +234,7 @@ static void target_address_add(
address_add(Target_Device_Object_Instance, MAX_APDU, &dest);
}
static void print_usage(char *filename)
static void print_usage(const char *filename)
{
printf("Usage: %s device-instance object-type object-instance "
"property[index][,property[index]] [object-type ...]\n",
@@ -243,7 +243,7 @@ static void print_usage(char *filename)
printf(" [--version][--help]\n");
}
static void print_help(char *filename)
static void print_help(const char *filename)
{
printf("Read one or more properties from one or more objects\n"
"in a BACnet device and print the value(s).\n");
@@ -350,7 +350,7 @@ int main(int argc, char *argv[])
bool specific_address = false;
unsigned int target_args = 0;
bool status = false;
char *filename = NULL;
const char *filename = NULL;
filename = filename_remove_path(argv[0]);
for (argi = 1; argi < argc; argi++) {
+3 -3
View File
@@ -121,7 +121,7 @@ static void Init_Service_Handlers(void)
apdu_set_reject_handler(MyRejectHandler);
}
static void print_usage(char *filename)
static void print_usage(const char *filename)
{
printf("Usage: %s device-instance object-type object-instance property\n",
filename);
@@ -129,7 +129,7 @@ static void print_usage(char *filename)
printf(" [--version][--help]\n");
}
static void print_help(char *filename)
static void print_help(const char *filename)
{
printf("Read a range of properties from an array or list property\n"
"in an object in a BACnet device and print the values.\n");
@@ -199,7 +199,7 @@ int main(int argc, char *argv[])
int year, month, day, wday;
unsigned object_type = 0;
unsigned object_property = 0;
char *filename = NULL;
const char *filename = NULL;
filename = filename_remove_path(argv[0]);
for (argi = 1; argi < argc; argi++) {
+3 -3
View File
@@ -137,7 +137,7 @@ static void Init_Service_Handlers(void)
apdu_set_reject_handler(MyRejectHandler);
}
static void print_usage(char *filename)
static void print_usage(const char *filename)
{
printf("Usage: %s device-instance object-type object-instance "
"property array-index tag value\n",
@@ -146,7 +146,7 @@ static void print_usage(char *filename)
printf(" [--version][--help][--verbose]\n");
}
static void print_help(char *filename)
static void print_help(const char *filename)
{
printf("Remove an element from a BACnetLIST property of an object\n"
"in a BACnet device.\n");
@@ -244,7 +244,7 @@ int main(int argc, char *argv[])
bool specific_address = false;
unsigned int target_args = 0;
int argi = 0;
char *filename = NULL;
const char *filename = NULL;
filename = filename_remove_path(argv[0]);
for (argi = 1; argi < argc; argi++) {
+12 -8
View File
@@ -156,7 +156,7 @@ static bool port_find(uint16_t snet, BACNET_ADDRESS *addr)
* @param snet - router port SNET
* @param addr - address of port at the net to be added
*/
static void port_add(uint16_t snet, BACNET_ADDRESS *addr)
static void port_add(uint16_t snet, const BACNET_ADDRESS *addr)
{
DNET *port = NULL;
DNET *dnet = NULL;
@@ -204,7 +204,7 @@ static void port_add(uint16_t snet, BACNET_ADDRESS *addr)
* @param net - net to be added
* @param addr - address of router at the net to be added
*/
static void dnet_add(uint16_t snet, uint16_t net, BACNET_ADDRESS *addr)
static void dnet_add(uint16_t snet, uint16_t net, const BACNET_ADDRESS *addr)
{
DNET *dnet = NULL;
DNET *port = NULL;
@@ -398,7 +398,8 @@ static void send_i_am_router_to_network(uint16_t snet, uint16_t net)
* Optionally may designate a particular router destination,
* especially when ACKing receipt of this message type.
*/
static void send_initialize_routing_table_ack(uint8_t snet, BACNET_ADDRESS *dst)
static void send_initialize_routing_table_ack(
uint8_t snet, const BACNET_ADDRESS *dst)
{
BACNET_ADDRESS dest;
bool data_expecting_reply = false;
@@ -458,7 +459,10 @@ static void send_initialize_routing_table_ack(uint8_t snet, BACNET_ADDRESS *dst)
* @param reject_reason [in] One of the BACNET_NETWORK_REJECT_REASONS codes.
*/
static void send_reject_message_to_network(
uint16_t snet, BACNET_ADDRESS *dst, uint8_t reject_reason, uint16_t dnet)
uint16_t snet,
const BACNET_ADDRESS *dst,
uint8_t reject_reason,
uint16_t dnet)
{
BACNET_ADDRESS dest;
bool data_expecting_reply = false;
@@ -571,9 +575,9 @@ static void send_who_is_router_to_network(uint16_t snet, uint16_t dnet)
* @param npdu_len [in] The length of the remaining NPDU message in npdu[].
*/
static void who_is_router_to_network_handler(uint16_t snet,
BACNET_ADDRESS *src,
BACNET_NPDU_DATA *npdu_data,
uint8_t *npdu,
const BACNET_ADDRESS *src,
const BACNET_NPDU_DATA *npdu_data,
const uint8_t *npdu,
uint16_t npdu_len)
{
DNET *port = NULL;
@@ -752,7 +756,7 @@ static void network_control_handler(uint16_t snet,
* @param src [in] The BACNET_ADDRESS of the message's original src.
*/
static void routed_src_address(
BACNET_ADDRESS *router_src, uint16_t snet, BACNET_ADDRESS *src)
BACNET_ADDRESS *router_src, uint16_t snet, const BACNET_ADDRESS *src)
{
unsigned int i = 0;
+12 -8
View File
@@ -177,7 +177,7 @@ static bool port_find(uint16_t snet, BACNET_ADDRESS *addr)
* @param snet - router port SNET
* @param addr - address of port at the net to be added
*/
static void port_add(uint16_t snet, BACNET_ADDRESS *addr)
static void port_add(uint16_t snet, const BACNET_ADDRESS *addr)
{
DNET *port = NULL;
DNET *dnet = NULL;
@@ -225,7 +225,7 @@ static void port_add(uint16_t snet, BACNET_ADDRESS *addr)
* @param net - net to be added
* @param addr - address of router at the net to be added
*/
static void dnet_add(uint16_t snet, uint16_t net, BACNET_ADDRESS *addr)
static void dnet_add(uint16_t snet, uint16_t net, const BACNET_ADDRESS *addr)
{
DNET *dnet = NULL;
DNET *port = NULL;
@@ -419,7 +419,8 @@ static void send_i_am_router_to_network(uint16_t snet, uint16_t net)
* Optionally may designate a particular router destination,
* especially when ACKing receipt of this message type.
*/
static void send_initialize_routing_table_ack(uint8_t snet, BACNET_ADDRESS *dst)
static void send_initialize_routing_table_ack(
uint8_t snet, const BACNET_ADDRESS *dst)
{
BACNET_ADDRESS dest;
bool data_expecting_reply = false;
@@ -479,7 +480,10 @@ static void send_initialize_routing_table_ack(uint8_t snet, BACNET_ADDRESS *dst)
* @param reject_reason [in] One of the BACNET_NETWORK_REJECT_REASONS codes.
*/
static void send_reject_message_to_network(
uint16_t snet, BACNET_ADDRESS *dst, uint8_t reject_reason, uint16_t dnet)
uint16_t snet,
const BACNET_ADDRESS *dst,
uint8_t reject_reason,
uint16_t dnet)
{
BACNET_ADDRESS dest;
bool data_expecting_reply = false;
@@ -592,9 +596,9 @@ static void send_who_is_router_to_network(uint16_t snet, uint16_t dnet)
* @param npdu_len [in] The length of the remaining NPDU message in npdu[].
*/
static void who_is_router_to_network_handler(uint16_t snet,
BACNET_ADDRESS *src,
BACNET_NPDU_DATA *npdu_data,
uint8_t *npdu,
const BACNET_ADDRESS *src,
const BACNET_NPDU_DATA *npdu_data,
const uint8_t *npdu,
uint16_t npdu_len)
{
DNET *port = NULL;
@@ -775,7 +779,7 @@ static void network_control_handler(uint16_t snet,
* @param src [in] The BACNET_ADDRESS of the message's original src.
*/
static void routed_src_address(
BACNET_ADDRESS *router_src, uint16_t snet, BACNET_ADDRESS *src)
BACNET_ADDRESS *router_src, uint16_t snet, const BACNET_ADDRESS *src)
{
unsigned int i = 0;
+4 -1
View File
@@ -199,7 +199,10 @@ bool dl_ip_init(ROUTER_PORT *port, IP_DATA *ip_data)
}
int dl_ip_send(
IP_DATA *data, BACNET_ADDRESS *dest, uint8_t *pdu, unsigned pdu_len)
IP_DATA *data,
const BACNET_ADDRESS *dest,
const uint8_t *pdu,
unsigned pdu_len)
{
struct sockaddr_in bip_dest = { 0 };
int buff_len = 0;
+2 -2
View File
@@ -45,8 +45,8 @@ bool dl_ip_init(
int dl_ip_send(
IP_DATA * data,
BACNET_ADDRESS * dest,
uint8_t * pdu,
const BACNET_ADDRESS * dest,
const uint8_t * pdu,
unsigned pdu_len);
int dl_ip_recv(
+8 -8
View File
@@ -43,7 +43,7 @@ int port_count;
void print_help(void);
bool read_config(char *filepath);
bool read_config(const char *filepath);
bool parse_cmd(int argc, char *argv[]);
@@ -53,7 +53,7 @@ bool init_router(void);
void cleanup(void);
void print_msg(BACMSG *msg);
void print_msg(const BACMSG *msg);
uint16_t process_msg(BACMSG *msg, MSG_DATA *data, uint8_t **buff);
@@ -61,7 +61,7 @@ uint16_t get_next_free_dnet(void);
int kbhit(void);
inline bool is_network_msg(BACMSG *msg);
inline bool is_network_msg(const BACMSG *msg);
int main(int argc, char *argv[])
{
@@ -201,7 +201,7 @@ void print_help(void)
"-s, --stopbits <1|2>\n\tspecify MSTP port stopbits\n");
}
bool read_config(char *filepath)
bool read_config(const char *filepath)
{
config_t cfg;
config_setting_t *setting;
@@ -725,11 +725,11 @@ void cleanup(void)
pthread_mutex_destroy(&msg_lock);
}
void print_msg(BACMSG *msg)
void print_msg(const BACMSG *msg)
{
if (msg->type == DATA) {
int i;
MSG_DATA *data = (MSG_DATA *)msg->data;
const MSG_DATA *data = (const MSG_DATA *)msg->data;
if (data->pdu_len) {
PRINT(DEBUG, "Message PDU: ");
@@ -821,10 +821,10 @@ int kbhit(void)
return bytesWaiting;
}
bool is_network_msg(BACMSG *msg)
bool is_network_msg(const BACMSG *msg)
{
uint8_t control_byte; /* NPDU control byte */
MSG_DATA *data = (MSG_DATA *)msg->data;
const MSG_DATA *data = (const MSG_DATA *)msg->data;
control_byte = data->pdu[1];
+2 -1
View File
@@ -14,7 +14,8 @@
#include "network_layer.h"
#include "bacnet/bacint.h"
uint16_t process_network_message(BACMSG *msg, MSG_DATA *data, uint8_t **buff)
uint16_t process_network_message(
const BACMSG *msg, MSG_DATA *data, uint8_t **buff)
{
BACNET_NPDU_DATA npdu_data;
ROUTER_PORT *srcport;
+1 -1
View File
@@ -25,7 +25,7 @@
#include "portthread.h"
uint16_t process_network_message(
BACMSG * msg,
const BACMSG * msg,
MSG_DATA * data,
uint8_t ** buff);
+3 -3
View File
@@ -161,14 +161,14 @@ static void cleanup(void)
}
}
static void print_usage(char *filename)
static void print_usage(const char *filename)
{
printf("Usage: %s device-id object-type object-instance "
"process-id <[un]confirmed lifetime|cancel>\n",
filename);
}
static void print_help(char *filename)
static void print_help(const char *filename)
{
printf("Subscribe to a BACnet object for Change-of-Value notifications\n"
"in a BACnet device and print the Change-of-Value notifications.\n");
@@ -226,7 +226,7 @@ int main(int argc, char *argv[])
time_t timeout_seconds = 0;
time_t delta_seconds = 0;
bool found = false;
char *filename = NULL;
const char *filename = NULL;
bool print_usage_terse = false;
bool print_usage_verbose = false;
BACNET_SUBSCRIBE_COV_DATA *cov_data = NULL;
+3 -3
View File
@@ -82,14 +82,14 @@ static void Init_Service_Handlers(void)
apdu_set_reject_handler(MyRejectHandler);
}
static void print_usage(char *filename)
static void print_usage(const char *filename)
{
printf("Usage: %s [--dnet][--dadr][--mac]\n", filename);
printf(" [--date][--time]\n");
printf(" [--version][--help]\n");
}
static void print_help(char *filename)
static void print_help(const char *filename)
{
printf("Send BACnet TimeSynchronization request.\n");
printf("\n");
@@ -157,7 +157,7 @@ int main(int argc, char *argv[])
BACNET_ADDRESS dest = { 0 };
bool global_broadcast = true;
int argi = 0;
char *filename = NULL;
const char *filename = NULL;
/* decode any command line parameters */
filename = filename_remove_path(argv[0]);
+1 -1
View File
@@ -47,7 +47,7 @@ static void Init_Service_Handlers(void)
SERVICE_CONFIRMED_READ_PROPERTY, handler_read_property);
}
static void print_usage(char *filename)
static void print_usage(const char *filename)
{
printf("Sends a BACnet Unconfirmed Change-of-Value Notification\n"
"to the network.\n");
+3 -3
View File
@@ -49,7 +49,7 @@ static void Init_Service_Handlers(void)
SERVICE_CONFIRMED_READ_PROPERTY, handler_read_property);
}
static void print_usage(char *filename)
static void print_usage(const char *filename)
{
printf("Usage: %s pid object-type object-instance \n"
" event-object-type event-object-instance \n"
@@ -63,7 +63,7 @@ static void print_usage(char *filename)
printf(" [--version][--help]\n");
}
static void print_help(char *filename)
static void print_help(const char *filename)
{
printf("Send BACnet UnconfirmedEventNotification message for a device.\n");
printf("--mac A\n"
@@ -99,7 +99,7 @@ int main(int argc, char *argv[])
bool specific_address = false;
int argi = 0;
unsigned int target_args = 0;
char *filename = NULL;
const char *filename = NULL;
filename = filename_remove_path(argv[0]);
for (argi = 1; argi < argc; argi++) {
+3 -3
View File
@@ -117,14 +117,14 @@ static void Init_Service_Handlers(void)
apdu_set_reject_handler(MyRejectHandler);
}
static void print_usage(char *filename)
static void print_usage(const char *filename)
{
printf("Usage: %s <device-instance|broadcast|dnet=> vendor-id"
" service-number tag value [tag value...]\n",
filename);
}
static void print_help(char *filename)
static void print_help(const char *filename)
{
printf("Send BACnet UnconfirmedPrivateTransfer message to the network.\n");
printf("device-instance:\n"
@@ -181,7 +181,7 @@ int main(int argc, char *argv[])
time_t timeout_seconds = 0;
time_t delta_seconds = 0;
bool found = false;
char *filename = NULL;
const char *filename = NULL;
char *value_string = NULL;
bool status = false;
int args_remaining = 0, tag_value_arg = 0, i = 0;
+2 -2
View File
@@ -85,14 +85,14 @@ static void Init_Service_Handlers(void)
apdu_set_reject_handler(MyRejectHandler);
}
static void print_usage(char *filename)
static void print_usage(const char *filename)
{
printf("Usage: %s [device-instance-min device-instance-min] "
"<object-type object-instance | object-name> [--help]\r\n",
filename);
}
static void print_help(char *filename)
static void print_help(const char *filename)
{
print_usage(filename);
printf("Send BACnet WhoHas request to devices, \r\n"
+5 -5
View File
@@ -73,7 +73,7 @@ static struct address_entry *alloc_address_entry(void)
}
static void address_table_add(
uint32_t device_id, unsigned max_apdu, BACNET_ADDRESS *src)
uint32_t device_id, unsigned max_apdu, const BACNET_ADDRESS *src)
{
struct address_entry *pMatch;
uint8_t flags = 0;
@@ -185,7 +185,7 @@ static void init_service_handlers(void)
apdu_set_reject_handler(MyRejectHandler);
}
static void print_macaddr(uint8_t *addr, int len)
static void print_macaddr(const uint8_t *addr, int len)
{
int j = 0;
@@ -246,7 +246,7 @@ static void print_address_cache(void)
}
}
static void print_usage(char *filename)
static void print_usage(const char *filename)
{
printf("Usage: %s", filename);
printf(" [device-instance-min [device-instance-max]]\n");
@@ -254,7 +254,7 @@ static void print_usage(char *filename)
printf(" [--version][--help]\n");
}
static void print_help(char *filename)
static void print_help(const char *filename)
{
printf("Send BACnet WhoIs service request to a device or multiple\n"
"devices, and wait for responses. Displays any devices found\n"
@@ -338,7 +338,7 @@ int main(int argc, char *argv[])
bool global_broadcast = true;
int argi = 0;
unsigned int target_args = 0;
char *filename = NULL;
const char *filename = NULL;
bool repeat_forever = false;
long retry_count = 0;
+2 -2
View File
@@ -136,14 +136,14 @@ static void Init_Service_Handlers(void)
apdu_set_reject_handler(MyRejectHandler);
}
static void print_usage(char *filename)
static void print_usage(const char *filename)
{
printf("Usage: %s device-instance object-type object-instance "
"property priority index tag value [tag value...]\n",
filename);
}
static void print_help(char *filename)
static void print_help(const char *filename)
{
printf(
"device-instance:\n"
+3 -3
View File
@@ -162,7 +162,7 @@ static void cleanup(void)
}
}
static void print_usage(char *filename)
static void print_usage(const char *filename)
{
printf("Usage: %s device-instance object-type object-instance "
"property[index] priority tag value [property[index] priority tag "
@@ -171,7 +171,7 @@ static void print_usage(char *filename)
printf(" [--version][--help]\n");
}
static void print_help(char *filename)
static void print_help(const char *filename)
{
printf("Write one or more properties to one or more objects\n"
"in a BACnet device.\n");
@@ -278,7 +278,7 @@ int main(int argc, char *argv[])
unsigned property_array_index = 0;
int scan_count = 0;
int argi = 0;
char *filename = NULL;
const char *filename = NULL;
filename = filename_remove_path(argv[0]);
for (argi = 1; argi < argc; argi++) {