Bugfix/code clean using gcc warnings (#371)

* Enable extra GCC warnings to discover subtle bugs

* convert c++ comments to c comments

* cleanup pedantic compiler warnings

* Compile apps with GNU89 GNU99 GNU11 and GNU17

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
Steve Karg
2022-12-25 21:43:51 -06:00
committed by GitHub
parent 0728bc4390
commit b91735af13
66 changed files with 990 additions and 847 deletions
+39 -36
View File
@@ -38,7 +38,8 @@
#include <stdlib.h> /* for strtol */
#include <ctype.h> /* for isalnum */
#include <errno.h>
#ifdef __STDC_ISO_10646__
#include <math.h>
#if (__STDC_VERSION__ >= 199901L) && defined (__STDC_ISO_10646__)
#include <wchar.h>
#include <wctype.h>
#endif
@@ -1168,9 +1169,9 @@ int bacapp_decode_known_property(uint8_t *apdu,
{
int len = 0;
// NOTE:
// When adding impl for a new prop, also add its tag
// to bacapp_known_property_tag()
/* NOTE: */
/* When adding impl for a new prop, also add its tag */
/* to bacapp_known_property_tag() */
int tag = bacapp_known_property_tag(object_type, property);
if (tag != -1) {
@@ -1690,7 +1691,7 @@ static int bacapp_snprintf_weeklyschedule(char *str,
"Sun" };
const int loopend = ((arrayIndex == BACNET_ARRAY_ALL) ? 7 : 1);
// Find what inner type it uses
/* Find what inner type it uses */
int inner_tag = -1;
for (wi = 0; wi < loopend; wi++) {
BACNET_DAILY_SCHEDULE *ds = &ws->weeklySchedule[wi];
@@ -1837,7 +1838,7 @@ int bacapp_snprintf_value(
#if defined(BACAPP_OCTET_STRING) || defined(BACAPP_TYPES_EXTRA)
uint8_t *octet_str;
#endif
#ifdef __STDC_ISO_10646__
#if (__STDC_VERSION__ >= 199901L) && defined (__STDC_ISO_10646__)
/* Wide character (decoded from multi-byte character). */
wchar_t wc;
/* Wide character length in bytes. */
@@ -1917,7 +1918,7 @@ int bacapp_snprintf_value(
}
}
ret_val += slen;
#ifdef __STDC_ISO_10646__
#if (__STDC_VERSION__ >= 199901L) && defined (__STDC_ISO_10646__)
if (characterstring_encoding(&value->type.Character_String) ==
CHARACTER_UTF8) {
while (len > 0) {
@@ -2164,7 +2165,7 @@ int bacapp_snprintf_value(
ret_val += slen;
break;
case BACNET_APPLICATION_TAG_TIMESTAMP:
//ISO 8601 format
/*ISO 8601 format */
slen = snprintf(str, str_len, "%04u-%02u-%02uT%02u:%02u:%02u.%03u",
(unsigned) value->type.Time_Stamp.value.dateTime.date.year,
(unsigned) value->type.Time_Stamp.value.dateTime.date.month,
@@ -2358,10 +2359,12 @@ static char *ltrim(char *str, const char *trimmedchars)
static char *rtrim(char *str, const char *trimmedchars)
{
char *end;
if (str[0] == 0) {
return str;
}
char *end = str + strlen(str) - 1;
end = str + strlen(str) - 1;
while (strchr(trimmedchars, *end)) {
*end = 0;
if (end == str)
@@ -2380,7 +2383,7 @@ static char *trim(char *str, const char *trimmedchars)
static bool parse_weeklyschedule(
char *str, BACNET_APPLICATION_DATA_VALUE *value)
{
char *chunk, *comma, *space, *t, *v;
char *chunk, *comma, *space, *t, *v, *colonpos, *sqpos;
int daynum = 0, tvnum = 0;
unsigned int inner_tag;
BACNET_APPLICATION_DATA_VALUE dummy_value = { 0 };
@@ -2402,13 +2405,13 @@ static bool parse_weeklyschedule(
value->tag = BACNET_APPLICATION_TAG_WEEKLY_SCHEDULE;
// Parse the inner tag
/* Parse the inner tag */
chunk = strtok(str, ";");
chunk = ltrim(chunk, "(");
if (false ==
bacapp_parse_application_data(
BACNET_APPLICATION_TAG_UNSIGNED_INT, chunk, &dummy_value)) {
// Try searching it by name
/* Try searching it by name */
if (false == bactext_application_tag_index(chunk, &inner_tag)) {
return false;
}
@@ -2421,43 +2424,43 @@ static bool parse_weeklyschedule(
while (chunk != NULL) {
dsch = &value->type.Weekly_Schedule.weeklySchedule[daynum];
// Strip day name prefix, if present
char *colonpos = strchr(chunk, ':');
char *sqpos = strchr(chunk, '[');
/* Strip day name prefix, if present */
colonpos = strchr(chunk, ':');
sqpos = strchr(chunk, '[');
if (colonpos && colonpos < sqpos) {
chunk = colonpos + 1;
}
// Extract the inner list of time-values
/* Extract the inner list of time-values */
chunk = rtrim(ltrim(chunk, "([ "), " ])");
// The list can be empty
/* The list can be empty */
if (chunk[0] != 0) {
// loop through the time value pairs
/* loop through the time value pairs */
tvnum = 0;
do {
// Find the comma delimiter, replace with NUL (like strtok)
/* Find the comma delimiter, replace with NUL (like strtok) */
comma = strchr(chunk, ',');
if (comma) {
*comma = 0;
}
// trim the time-value pair and find the delimiter space
/* trim the time-value pair and find the delimiter space */
chunk = trim(chunk, " ");
space = strchr(chunk, ' ');
if (!space) {
// malformed time-value pair
/* malformed time-value pair */
return false;
}
*space = 0;
// Extract time and value
/* Extract time and value */
t = chunk;
// value starts one byte after the space, and there can be
// multiple spaces
/* value starts one byte after the space, and there can be */
/* multiple spaces */
chunk = ltrim(space + 1, " ");
v = chunk;
// Parse time
/* Parse time */
if (false ==
bacapp_parse_application_data(
BACNET_APPLICATION_TAG_TIME, t, &dummy_value)) {
@@ -2465,7 +2468,7 @@ static bool parse_weeklyschedule(
}
dsch->Time_Values[tvnum].Time = dummy_value.type.Time;
// Parse value
/* Parse value */
if (false ==
bacapp_parse_application_data(inner_tag, v, &dummy_value)) {
return false;
@@ -2476,7 +2479,7 @@ static bool parse_weeklyschedule(
return false;
}
// Advance past the comma to the next chunk
/* Advance past the comma to the next chunk */
if (comma) {
chunk = comma + 1;
}
@@ -2486,7 +2489,7 @@ static bool parse_weeklyschedule(
dsch->TV_Count = tvnum;
// Find the start of the next day
/* Find the start of the next day */
chunk = strtok(NULL, ";");
daynum++;
}
@@ -2506,11 +2509,11 @@ static bool strtol_checked(const char *s, long *out)
errno = 0;
*out = strtol(s, &end, 0);
if (end == s) {
// Conversion was not possible
/* Conversion was not possible */
return false;
}
if (errno == ERANGE) {
// Number too large
/* Number too large */
return false;
}
return true;
@@ -2524,11 +2527,11 @@ static bool strtoul_checked(const char *s, BACNET_UNSIGNED_INTEGER *out)
errno = 0;
*out = strtoul(s, &end, 0);
if (end == s) {
// Conversion was not possible
/* Conversion was not possible */
return false;
}
if (errno == ERANGE) {
// Number too large
/* Number too large */
return false;
}
return true;
@@ -2542,11 +2545,11 @@ static bool strtod_checked(const char *s, double *out)
errno = 0;
*out = strtod(s, &end);
if (end == s) {
// Conversion was not possible
/* Conversion was not possible */
return false;
}
if (errno == ERANGE) {
// Number too large
/* Number too large */
return false;
}
return true;
@@ -2869,14 +2872,14 @@ bool bacapp_same_value(BACNET_APPLICATION_DATA_VALUE *value,
#endif
#if defined(BACAPP_REAL)
case BACNET_APPLICATION_TAG_REAL:
if (test_value->type.Real == value->type.Real) {
if (!islessgreater(test_value->type.Real, value->type.Real)) {
status = true;
}
break;
#endif
#if defined(BACAPP_DOUBLE)
case BACNET_APPLICATION_TAG_DOUBLE:
if (test_value->type.Double == value->type.Double) {
if (!islessgreater(test_value->type.Double,value->type.Double)) {
status = true;
}
break;
+1 -1
View File
@@ -2066,7 +2066,7 @@ typedef enum BACnetColorTransition {
BACNET_COLOR_TRANSITION_NONE = 0,
BACNET_COLOR_TRANSITION_FADE = 1,
BACNET_COLOR_TRANSITION_RAMP = 2,
BACNET_COLOR_TRANSITION_MAX = 3,
BACNET_COLOR_TRANSITION_MAX = 3
} BACNET_COLOR_TRANSITION;
/* NOTE: BACNET_DAYS_OF_WEEK is different than BACNET_WEEKDAY */
+2
View File
@@ -900,6 +900,8 @@ bool utf8_isvalid(const char *str, size_t length)
return false;
}
break;
default:
break;
}
/* Check for valid bytes after the 2nd, if any; all must start 10 */
+3 -5
View File
@@ -79,6 +79,7 @@ int bacnet_time_value_encode(uint8_t *apdu, BACNET_TIME_VALUE *value)
int len;
int apdu_len = 0;
uint8_t *apdu_offset = NULL;
BACNET_APPLICATION_DATA_VALUE adv;
if (!value || !is_data_value_schedule_compatible(value->Value.tag)) {
return BACNET_STATUS_ERROR;
@@ -93,10 +94,7 @@ int bacnet_time_value_encode(uint8_t *apdu, BACNET_TIME_VALUE *value)
if (apdu) {
apdu_offset = &apdu[apdu_len];
}
BACNET_APPLICATION_DATA_VALUE adv;
bacnet_primitive_to_application_data_value(&adv, &value->Value);
len = bacapp_encode_application_data(apdu_offset, &adv);
apdu_len += len;
@@ -147,7 +145,7 @@ int bacnet_application_to_primitive_data_value(
struct BACnet_Primitive_Data_Value *dest,
const struct BACnet_Application_Data_Value *src)
{
// make sure the value passed is valid
/* make sure the value passed is valid */
if (!src || !dest || !is_data_value_schedule_compatible(src->tag)) {
return BACNET_STATUS_ERROR;
}
@@ -162,7 +160,7 @@ int bacnet_primitive_to_application_data_value(
struct BACnet_Application_Data_Value *dest,
const struct BACnet_Primitive_Data_Value *src)
{
// make sure the value passed is valid
/* make sure the value passed is valid */
if (!dest || !src) {
return BACNET_STATUS_ERROR;
}
+2 -6
View File
@@ -39,14 +39,10 @@
#include "bacnet/basic/services.h"
#include "bacnet/proplist.h"
#include "bacnet/timestamp.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/basic/object/ai.h"
#if PRINT_ENABLED
#include <stdio.h>
#define PRINTF(...) fprintf(stderr, __VA_ARGS__)
#else
#define PRINTF(...)
#endif
#define PRINTF debug_perror
#ifndef MAX_ANALOG_INPUTS
#define MAX_ANALOG_INPUTS 4
+4
View File
@@ -236,12 +236,14 @@ bool Analog_Value_Present_Value_Set(
unsigned index = 0;
bool status = false;
(void)priority;
index = Analog_Value_Instance_To_Index(object_instance);
if (index < MAX_ANALOG_VALUES) {
Analog_Value_COV_Detect(index, value);
AV_Descr[index].Present_Value = value;
status = true;
}
return status;
}
@@ -1136,6 +1138,8 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
CurrentAV->Event_Time_Stamps[TRANSITION_TO_NORMAL] =
event_data.timeStamp.value.dateTime;
break;
default:
break;
}
}
+3 -2
View File
@@ -657,6 +657,7 @@ int Channel_Value_Encode(
{
int apdu_len = BACNET_STATUS_ERROR;
(void)apdu_max;
if (!apdu || !value) {
return BACNET_STATUS_ERROR;
}
@@ -907,7 +908,7 @@ int Channel_Coerce_Data_Encode(uint8_t *apdu,
#if defined(BACAPP_REAL)
case BACNET_APPLICATION_TAG_REAL:
if (tag == BACNET_APPLICATION_TAG_BOOLEAN) {
if (value->type.Real != 0.0F) {
if (islessgreater(value->type.Real, 0.0F)) {
boolean_value = true;
}
apdu_len =
@@ -954,7 +955,7 @@ int Channel_Coerce_Data_Encode(uint8_t *apdu,
#if defined(BACAPP_DOUBLE)
case BACNET_APPLICATION_TAG_DOUBLE:
if (tag == BACNET_APPLICATION_TAG_BOOLEAN) {
if (value->type.Double != 0.0) {
if (islessgreater(value->type.Double, 0.0)) {
boolean_value = true;
}
apdu_len =
+1
View File
@@ -820,4 +820,5 @@ bool Command_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
void Command_Intrinsic_Reporting(uint32_t object_instance)
{
(void)object_instance;
}
+5 -12
View File
@@ -39,16 +39,9 @@
#include "bacnet/basic/object/ao.h"
#include "bacnet/wp.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#ifndef LOAD_CONTROL_DEBUG
#define LOAD_CONTROL_DEBUG 0
#endif
#if LOAD_CONTROL_DEBUG
#include <sys/PRINTF.h>
#define PRINTF(...) printk(__VA_ARGS__)
#else
#define PRINTF(...)
#endif
#define PRINTF debug_printf
/* number of demo objects */
#ifndef MAX_LOAD_CONTROLS
@@ -67,7 +60,7 @@ typedef enum BACnetShedLevelType {
#define DEFAULT_VALUE_PERCENT 100
#define DEFAULT_VALUE_LEVEL 0
#define DEFAULT_VALUE_AMOUNT 0
#define DEFAULT_VALUE_AMOUNT 0.0
/* The shed levels for the LEVEL choice of BACnetShedLevel
that have meaning for this particular Load Control object. */
@@ -423,7 +416,7 @@ void Load_Control_State_Machine(int object_index)
}
break;
case BACNET_SHED_TYPE_AMOUNT:
if (Requested_Shed_Level[object_index].value.amount ==
if (Requested_Shed_Level[object_index].value.amount <=
DEFAULT_VALUE_AMOUNT) {
Load_Control_State[object_index] = SHED_INACTIVE;
}
@@ -431,7 +424,7 @@ void Load_Control_State_Machine(int object_index)
case BACNET_SHED_TYPE_LEVEL:
default:
if (Requested_Shed_Level[object_index].value.level ==
DEFAULT_VALUE_LEVEL) {
DEFAULT_VALUE_LEVEL) {
Load_Control_State[object_index] = SHED_INACTIVE;
}
break;
+12 -2
View File
@@ -1228,7 +1228,12 @@ static void Lighting_Output_Ramp_Handler(struct lighting_output_object *pLight,
BACNET_LIGHTING_COMMAND *pCommand,
uint16_t milliseconds)
{
if (pLight && pCommand) { }
if (pLight && pCommand) {
/* FIXME: add ramp functionality */
(void)pLight;
(void)pCommand;
(void)milliseconds;
}
}
/**
@@ -1243,7 +1248,12 @@ static void Lighting_Output_Fade_Handler(struct lighting_output_object *pLight,
BACNET_LIGHTING_COMMAND *pCommand,
uint16_t milliseconds)
{
if (pLight && pCommand) { }
if (pLight && pCommand) {
/* FIXME: add fade functionality */
(void)pLight;
(void)pCommand;
(void)milliseconds;
}
}
/**
+1
View File
@@ -140,6 +140,7 @@ bool Multistate_Input_Valid_Instance(uint32_t object_instance)
static uint32_t Multistate_Input_Max_States(uint32_t instance)
{
(void)instance;
return MULTISTATE_NUMBER_OF_STATES;
}
+3 -7
View File
@@ -43,17 +43,13 @@
#include "bacnet/basic/object/device.h"
#include "bacnet/event.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/wp.h"
#include "bacnet/basic/object/nc.h"
#include "bacnet/datalink/datalink.h"
#if PRINT_ENABLED
#include <stdio.h>
#define PRINTF(...) fprintf(stderr, __VA_ARGS__)
#else
#define PRINTF(...)
#endif
#define PRINTF debug_perror
#ifndef MAX_NOTIFICATION_CLASSES
#define MAX_NOTIFICATION_CLASSES 2
@@ -747,8 +743,8 @@ bool Notification_Class_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
* &src); */
}
}
status = true;
break;
case PROP_OBJECT_NAME:
wp_data->error_class = ERROR_CLASS_PROPERTY;
+4
View File
@@ -2561,6 +2561,8 @@ bool Network_Port_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
*/
int Network_Port_Read_Range_BDT(uint8_t *apdu, BACNET_READ_RANGE_DATA *pRequest)
{
(void)apdu;
(void)pRequest;
return 0;
}
@@ -2574,6 +2576,8 @@ int Network_Port_Read_Range_BDT(uint8_t *apdu, BACNET_READ_RANGE_DATA *pRequest)
*/
int Network_Port_Read_Range_FDT(uint8_t *apdu, BACNET_READ_RANGE_DATA *pRequest)
{
(void)apdu;
(void)pRequest;
return 0;
}
+2
View File
@@ -140,6 +140,7 @@ bool OctetString_Value_Present_Value_Set(
unsigned index = 0;
bool status = false;
(void)priority;
index = OctetString_Value_Instance_To_Index(object_instance);
if (index < MAX_OCTETSTRING_VALUES) {
octetstring_copy(&OSV_Descr[index].Present_Value, value);
@@ -354,4 +355,5 @@ bool OctetString_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
void OctetString_Value_Intrinsic_Reporting(uint32_t object_instance)
{
(void)object_instance;
}
+3
View File
@@ -140,11 +140,13 @@ bool PositiveInteger_Value_Present_Value_Set(
unsigned index = 0;
bool status = false;
(void)priority;
index = PositiveInteger_Value_Instance_To_Index(object_instance);
if (index < MAX_POSITIVEINTEGER_VALUES) {
PIV_Descr[index].Present_Value = value;
status = true;
}
return status;
}
@@ -359,4 +361,5 @@ bool PositiveInteger_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
void PositiveInteger_Value_Intrinsic_Reporting(uint32_t object_instance)
{
(void)object_instance;
}
+3
View File
@@ -1498,6 +1498,9 @@ int TL_encode_entry(uint8_t *apdu, int iLog, int iEntry)
case TL_TYPE_ANY:
/* Should never happen as we don't support this at the moment */
break;
default:
break;
}
iLen += encode_closing_tag(&apdu[iLen], 1);
+2 -6
View File
@@ -39,14 +39,10 @@
#include "bacnet/basic/services.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/datalink/datalink.h"
#include "bacnet/basic/sys/debug.h"
/** @file h_ccov.c Handles Confirmed COV Notifications. */
#if PRINT_ENABLED
#include <stdio.h>
#define PRINTF(...) fprintf(stderr, __VA_ARGS__)
#else
#define PRINTF(...)
#endif
#define PRINTF debug_perror
/* max number of COV properties decoded in a COV notification */
#ifndef MAX_COV_PROPERTIES
+2
View File
@@ -65,6 +65,8 @@ void get_alarm_summary_ack_handler(uint8_t *service_request,
uint16_t len = 0;
BACNET_GET_ALARM_SUMMARY_DATA data;
(void)src;
(void)service_data;
while (service_len - len) {
apdu_len = get_alarm_summary_ack_decode_apdu_data(
&service_request[len], service_len - len, &data);
@@ -67,6 +67,8 @@ void handler_get_alarm_summary(uint8_t *service_request,
BACNET_NPDU_DATA npdu_data;
BACNET_GET_ALARM_SUMMARY_DATA getalarm_data;
(void)service_request;
(void)service_len;
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
+1 -1
View File
@@ -51,11 +51,11 @@ static get_event_info_function Get_Event_Info[MAX_BACNET_OBJECT_TYPE];
void ge_ack_print_data(
BACNET_GET_EVENT_INFORMATION_DATA *data, uint32_t device_id)
{
unsigned int count = 0;
BACNET_GET_EVENT_INFORMATION_DATA *act_data = data;
const char *state_strs[] = { "NO", "FA", "ON", "HL", "LL" };
printf("DeviceID\tType\tInstance\teventState\n");
printf("--------------- ------- --------------- ---------------\n");
unsigned int count = 0;
while (act_data) {
printf("%u\t\t%u\t%u\t\t%s\n", device_id,
act_data->objectIdentifier.type,
+2
View File
@@ -72,6 +72,8 @@ void get_event_ack_handler(uint8_t *service_request,
multiple get event data in APDU */
BACNET_GET_EVENT_INFORMATION_DATA get_event_data[MAX_NUMBER_OF_EVENTS];
(void)src;
(void)service_data;
for (i = 1; i < MAX_NUMBER_OF_EVENTS; i++) {
/* Create linked list */
get_event_data[i - 1].next = &get_event_data[i];
+3 -8
View File
@@ -38,15 +38,10 @@
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/sys/debug.h"
#if PRINT_ENABLED
#include <stdio.h>
#define PRINTF(...) fprintf(stdout, __VA_ARGS__)
#define PRINTF_ERR(...) fprintf(stderr, __VA_ARGS__)
#else
#define PRINTF(...)
#define PRINTF_ERR(...)
#endif
#define PRINTF debug_aprintf
#define PRINTF_ERR debug_perror
/** @file h_rp_a.c Handles Read Property Acknowledgments. */
+6 -11
View File
@@ -37,16 +37,11 @@
/* some demo stuff needed */
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/basic/tsm/tsm.h"
#if PRINT_ENABLED
#include <stdio.h>
#define PRINTF(...) fprintf(stdout, __VA_ARGS__)
#define PRINTF_ERR(...) fprintf(stderr, __VA_ARGS__)
#else
#define PRINTF(...)
#define PRINTF_ERR(...)
#endif
#define PRINTF debug_aprintf
#define PERROR debug_perror
/** @file h_rpm_a.c Handles Read Property Multiple Acknowledgments. */
@@ -130,7 +125,7 @@ int rpm_ack_decode_service_request(
/* If len == 0 then it's an empty structure, which is OK. */
if (len < 0) {
/* problem decoding */
PRINTF_ERR("RPM Ack: unable to decode! %s:%s\n",
PERROR("RPM Ack: unable to decode! %s:%s\n",
bactext_object_type_name(rpm_object->object_type),
bactext_property_name(
rpm_property->propertyIdentifier));
@@ -151,7 +146,7 @@ int rpm_ack_decode_service_request(
calloc(1, sizeof(BACNET_APPLICATION_DATA_VALUE));
old_value->next = value;
} else {
PRINTF_ERR("RPM Ack: decoded %s:%s len=%d\n",
PERROR("RPM Ack: decoded %s:%s len=%d\n",
bactext_object_type_name(rpm_object->object_type),
bactext_property_name(
rpm_property->propertyIdentifier),
@@ -362,7 +357,7 @@ void handler_read_property_multiple_ack(uint8_t *service_request,
rpm_data = rpm_data_free(rpm_data);
}
} else {
PRINTF_ERR("RPM Ack Malformed! Freeing memory...\n");
PERROR("RPM Ack Malformed! Freeing memory...\n");
while (rpm_data) {
rpm_data = rpm_data_free(rpm_data);
}
+2 -6
View File
@@ -36,15 +36,11 @@
#include "bacnet/cov.h"
#include "bacnet/bactext.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/basic/tsm/tsm.h"
/** @file h_ucov.c Handles Unconfirmed COV Notifications. */
#if PRINT_ENABLED
#include <stdio.h>
#define PRINTF(...) fprintf(stderr, __VA_ARGS__)
#else
#define PRINTF(...)
#endif
#define PRINTF debug_perror
#ifndef MAX_COV_PROPERTIES
#define MAX_COV_PROPERTIES 2
+1
View File
@@ -111,6 +111,7 @@ void handler_unconfirmed_private_transfer(
BACNET_PRIVATE_TRANSFER_DATA private_data;
int len = 0;
(void)src;
#if PRINT_ENABLED
fprintf(stderr, "Received Unconfirmed Private Transfer Request!\n");
#endif
+2 -6
View File
@@ -41,15 +41,11 @@
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h"
/** @file h_wpm.c Handles Write Property Multiple requests. */
#if PRINT_ENABLED
#include <stdio.h>
#define PRINTF(...) fprintf(stderr, __VA_ARGS__)
#else
#define PRINTF(...)
#endif
#define PRINTF debug_perror
/** Decoding for an object property.
*
+2 -6
View File
@@ -38,16 +38,12 @@
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/datalink/datalink.h"
/** @file s_ack_alarm.c Send an Alarm Acknowledgment. */
#if PRINT_ENABLED
#include <stdio.h>
#define PRINTF(...) fprintf(stderr, __VA_ARGS__)
#else
#define PRINTF(...)
#endif
#define PRINTF debug_perror
/** Sends an Confirmed Alarm Acknowledgment.
*
+4 -1
View File
@@ -5,7 +5,10 @@
#include "bacnet/basic/sys/bigend.h"
#ifndef BACNET_BIG_ENDIAN
#ifdef BACNET_BIG_ENDIAN
/* workaround: warning: ISO C forbids an empty translation unit [-Wpedantic] */
typedef int make_iso_compilers_happy;
#else
/* Big-Endian systems save the most significant byte first. */
/* Sun and Motorola processors, IBM-370s and PDP-10s are big-endian. */
/* "Network Byte Order" is also know as "Big-Endian Byte Order" */
+19 -14
View File
@@ -50,6 +50,8 @@ void color_rgb_to_xy(uint8_t r,
float *y_coordinate,
uint8_t *brightness)
{
float X, Y, Z;
float x, y;
/* Get the RGB values from your color object
and convert them to be between 0 and 1.
So the RGB color (255, 0, 100) becomes (1.0, 0.0, 0.39) */
@@ -76,13 +78,13 @@ void color_rgb_to_xy(uint8_t r,
/* Convert the RGB values to XYZ using the
Wide RGB D65 conversion formula */
float X = red * 0.649926f + green * 0.103455f + blue * 0.197109f;
float Y = red * 0.234327f + green * 0.743075f + blue * 0.022598f;
float Z = red * 0.0000000f + green * 0.053077f + blue * 1.035763f;
X = red * 0.649926f + green * 0.103455f + blue * 0.197109f;
Y = red * 0.234327f + green * 0.743075f + blue * 0.022598f;
Z = red * 0.0000000f + green * 0.053077f + blue * 1.035763f;
/* Calculate the xy values from the XYZ values */
float x = X / (X + Y + Z);
float y = Y / (X + Y + Z);
x = X / (X + Y + Z);
y = Y / (X + Y + Z);
x = clamp(x, 0.0f, 1.0f);
y = clamp(y, 0.0f, 1.0f);
@@ -122,20 +124,23 @@ void color_rgb_from_xy(uint8_t *red,
float y_coordinate,
uint8_t brightness)
{
float r, g, b;
float x, y, z, X, Y, Z;
/* Calculate XYZ values */
float x = x_coordinate;
float y = y_coordinate;
float z = 1.0f - x - y;
float Y = (float)brightness;
x = x_coordinate;
y = y_coordinate;
z = 1.0f - x - y;
Y = (float)brightness;
Y /= 255.0f;
float X = (Y / y) * x;
float Z = (Y / y) * z;
X = x * (Y / y);
Z = z * (Y / y);
/* Convert to RGB using Wide RGB D65 conversion
(THIS IS A D50 conversion currently) */
float r = X * 1.4628067f - Y * 0.1840623f - Z * 0.2743606f;
float g = -X * 0.5217933f + Y * 1.4472381f + Z * 0.0677227f;
float b = X * 0.0349342f - Y * 0.0968930f + Z * 1.2884099f;
r = X * 1.4628067f - Y * 0.1840623f - Z * 0.2743606f;
g = -X * 0.5217933f + Y * 1.4472381f + Z * 0.0677227f;
b = X * 0.0349342f - Y * 0.0968930f + Z * 1.2884099f;
/* Apply reverse gamma correction */
r = r <= 0.0031308f ? 12.92f * r
+56
View File
@@ -59,3 +59,59 @@ void debug_printf(const char *format, ...)
(void)format;
}
#endif
#if PRINT_ENABLED
int debug_aprintf(const char *format, ...)
{
int length = 0;
va_list ap;
va_start(ap, format);
length = vfprintf(stdout, format, ap);
va_end(ap);
fflush(stdout);
return length;
}
int debug_fprintf(FILE *stream, const char *format, ...)
{
int length = 0;
va_list ap;
va_start(ap, format);
length = vfprintf(stream, format, ap);
va_end(ap);
fflush(stream);
return length;
}
void debug_perror(const char *format, ...)
{
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
+13
View File
@@ -42,6 +42,19 @@ extern "C" {
void debug_printf(
const char *format,
...);
BACNET_STACK_EXPORT
int debug_aprintf(
const char *format,
...);
BACNET_STACK_EXPORT
int debug_fprintf(
FILE *stream,
const char *format,
...);
BACNET_STACK_EXPORT
void debug_perror(
const char *format,
...);
#if DEBUG_ENABLED
/* Nothing more here */
#else
+12
View File
@@ -18,6 +18,12 @@
#ifndef BACNET_SYS_PLATFORM_H
#define BACNET_SYS_PLATFORM_H
#include <math.h>
#ifndef islessgreater
#define islessgreater(x, y) ((x) < (y) || (x) > (y))
#endif
/* marking some code as 'deprecated' */
# if defined(_MSC_VER)
# define BACNET_STACK_DEPRECATED(message) __declspec(deprecated(message))
@@ -31,4 +37,10 @@
# define strcasecmp _stricmp
# endif
#if defined(__GNUC__)
#define BACNET_STACK_FALLTHROUGH() __attribute__ ((fallthrough))
#else
#define BACNET_STACK_FALLTHROUGH() /* fall through */
#endif
#endif
+3
View File
@@ -65,6 +65,7 @@ static int notify_encode_apdu(
BACNET_PROPERTY_VALUE *value = NULL; /* value in list */
BACNET_APPLICATION_DATA_VALUE *app_data = NULL;
(void)max_apdu_len;
if (apdu) {
/* tag 0 - subscriberProcessIdentifier */
len = encode_context_unsigned(
@@ -405,6 +406,7 @@ int cov_subscribe_encode_apdu(uint8_t *apdu,
int len = 0; /* length of each encoding */
int apdu_len = 0; /* total length of the apdu, return value */
(void)max_apdu_len;
if (apdu && data) {
apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST;
apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU);
@@ -554,6 +556,7 @@ int cov_subscribe_property_encode_apdu(uint8_t *apdu,
int len = 0; /* length of each encoding */
int apdu_len = 0; /* total length of the apdu, return value */
(void)max_apdu_len;
if (apdu && data) {
apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST;
apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU);
-3
View File
@@ -215,9 +215,6 @@ static int bbmd_register_as_foreign_device(void)
pEnv = getenv(bbmd_env);
if (pEnv) {
bdt_entry_port = strtol(pEnv, NULL, 0);
if (bdt_entry_port > 0xFFFF) {
bdt_entry_port = 0xBAC0;
}
if (entry_number == 1) {
if (BIP_DL_Debug) {
fprintf(stderr, "BBMD 1 port overridden %s=%s!\n",
+4 -8
View File
@@ -20,10 +20,6 @@
#include "bacnet/bacreal.h"
#include "bacnet/lighting.h"
#ifndef islessgreater
#define islessgreater(x, y) ((x) < (y) || (x) > (y))
#endif
/** @file lighting.c Manipulate BACnet lighting command values */
/**
@@ -604,8 +600,8 @@ bool xy_color_same(BACNET_XY_COLOR *value1, BACNET_XY_COLOR *value2)
bool status = false;
if (value1 && value2) {
if ((value1->x_coordinate == value2->x_coordinate) &&
(value1->y_coordinate == value2->y_coordinate)) {
if (!islessgreater(value1->x_coordinate, value2->x_coordinate) &&
!islessgreater(value1->y_coordinate, value2->y_coordinate)) {
status = true;
}
}
@@ -1096,9 +1092,9 @@ bool color_command_same(
status = true;
break;
case BACNET_COLOR_OPERATION_FADE_TO_COLOR:
if ((value1->target.color.x_coordinate ==
if (!islessgreater(value1->target.color.x_coordinate,
value2->target.color.x_coordinate) &&
(value1->target.color.y_coordinate ==
!islessgreater(value1->target.color.y_coordinate,
value2->target.color.y_coordinate) &&
(value1->transit.fade_time == value2->transit.fade_time)) {
status = true;
+11 -8
View File
@@ -155,24 +155,27 @@ int bacnet_weeklyschedule_context_decode(uint8_t *apdu,
bool bacnet_weeklyschedule_same(
BACNET_WEEKLY_SCHEDULE *value1, BACNET_WEEKLY_SCHEDULE *value2)
{
BACNET_APPLICATION_DATA_VALUE adv1, adv2;
BACNET_DAILY_SCHEDULE *ds1, *ds2;
BACNET_TIME_VALUE *tv1, *tv2;
int wi, ti;
for (wi = 0; wi < 7; wi++) {
BACNET_DAILY_SCHEDULE *ds1 = &value1->weeklySchedule[wi];
BACNET_DAILY_SCHEDULE *ds2 = &value2->weeklySchedule[wi];
ds1 = &value1->weeklySchedule[wi];
ds2 = &value2->weeklySchedule[wi];
if (ds1->TV_Count != ds2->TV_Count) {
return false;
}
for (ti = 0; ti < ds1->TV_Count; ti++) {
BACNET_TIME_VALUE *tv1 = &ds1->Time_Values[ti];
BACNET_TIME_VALUE *tv2 = &ds2->Time_Values[ti];
tv1 = &ds1->Time_Values[ti];
tv2 = &ds2->Time_Values[ti];
if (0 != datetime_compare_time(&tv1->Time, &tv2->Time)) {
return false;
}
// TODO the conversion can be avoided by adding a "primitive"
// variant of bacapp_same_value(),
// at the cost of some code duplication
BACNET_APPLICATION_DATA_VALUE adv1, adv2;
/* TODO the conversion can be avoided by adding a "primitive"
variant of bacapp_same_value(),
at the cost of some code duplication */
bacnet_primitive_to_application_data_value(&adv1, &tv1->Value);
bacnet_primitive_to_application_data_value(&adv2, &tv2->Value);