Indented project.

This commit is contained in:
skarg
2011-08-17 02:27:11 +00:00
parent 7e503510c7
commit 3e1cb1847f
125 changed files with 3548 additions and 3353 deletions
+1 -1
View File
@@ -55,7 +55,7 @@
static object_functions_t Object_Table[] = { static object_functions_t Object_Table[] = {
{DEVICE_OBJ_FUNCTIONS}, {DEVICE_OBJ_FUNCTIONS},
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL} NULL, NULL, NULL, NULL, NULL, NULL}
}; };
/* buffer used for receive */ /* buffer used for receive */
+6 -6
View File
@@ -66,7 +66,7 @@
static object_functions_t Object_Table[] = { static object_functions_t Object_Table[] = {
{DEVICE_OBJ_FUNCTIONS}, {DEVICE_OBJ_FUNCTIONS},
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL} NULL, NULL, NULL, NULL, NULL, NULL}
}; };
/* buffer used for receive */ /* buffer used for receive */
@@ -840,7 +840,7 @@ int CheckCommandLineArgs(
if (++i < argc) { if (++i < argc) {
#if defined(BACDL_BIP) #if defined(BACDL_BIP)
My_BIP_Port = (uint16_t) strtol(argv[i], NULL, 0); My_BIP_Port = (uint16_t) strtol(argv[i], NULL, 0);
/* Used strtol so sport can be either 0xBAC0 or 47808 */ /* Used strtol so sport can be either 0xBAC0 or 47808 */
#endif #endif
} }
break; break;
@@ -1172,11 +1172,11 @@ int main(
(invoke_id == (invoke_id ==
Read_Property_Multiple_Data.service_data.invoke_id)) { Read_Property_Multiple_Data.service_data.invoke_id)) {
Read_Property_Multiple_Data.new_data = false; Read_Property_Multiple_Data.new_data = false;
PrintReadPropertyData PrintReadPropertyData(Read_Property_Multiple_Data.
(Read_Property_Multiple_Data.rpm_data->object_type, rpm_data->object_type,
Read_Property_Multiple_Data.rpm_data->object_instance, Read_Property_Multiple_Data.rpm_data->object_instance,
Read_Property_Multiple_Data. Read_Property_Multiple_Data.rpm_data->
rpm_data->listOfProperties); listOfProperties);
if (tsm_invoke_id_free(invoke_id)) { if (tsm_invoke_id_free(invoke_id)) {
invoke_id = 0; invoke_id = 0;
} else { } else {
+1 -1
View File
@@ -101,7 +101,7 @@ static object_functions_t Object_Table[] = {
{FILE_OBJ_FUNCTIONS}, {FILE_OBJ_FUNCTIONS},
#endif #endif
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL} NULL, NULL, NULL, NULL, NULL, NULL}
}; };
/** Buffer used for receiving */ /** Buffer used for receiving */
+20 -16
View File
@@ -119,7 +119,6 @@ void handler_alarm_ack(
#endif #endif
goto AA_ABORT; goto AA_ABORT;
} }
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Alarm Ack Operation: Received acknowledge for object id (%d, %lu) from %s for process id %lu \n", "Alarm Ack Operation: Received acknowledge for object id (%d, %lu) from %s for process id %lu \n",
@@ -131,49 +130,54 @@ void handler_alarm_ack(
if (Alarm_Ack[data.eventObjectIdentifier.type]) { if (Alarm_Ack[data.eventObjectIdentifier.type]) {
ack_result = Alarm_Ack[data.eventObjectIdentifier.type](&data, &error_code); ack_result =
Alarm_Ack[data.eventObjectIdentifier.type] (&data, &error_code);
switch (ack_result) switch (ack_result) {
{
case 1: case 1:
len = encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], len =
service_data->invoke_id, SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM); encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Alarm Acknowledge: " "Sending Simple Ack!\n"); fprintf(stderr, "Alarm Acknowledge: " "Sending Simple Ack!\n");
#endif #endif
break; break;
case -1: case -1:
len = bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], len =
service_data->invoke_id, SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
ERROR_CLASS_OBJECT, error_code); service_data->invoke_id,
SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, ERROR_CLASS_OBJECT,
error_code);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Alarm Acknowledge: error %s!\n", fprintf(stderr, "Alarm Acknowledge: error %s!\n",
bactext_error_code_name(error_code)); bactext_error_code_name(error_code));
#endif #endif
break; break;
default: default:
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER, true); service_data->invoke_id, ABORT_REASON_OTHER, true);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Alarm Acknowledge: abort other!\n"); fprintf(stderr, "Alarm Acknowledge: abort other!\n");
#endif #endif
break; break;
} }
} } else {
else { len =
len = bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, service_data->invoke_id, SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM,
ERROR_CLASS_OBJECT, ERROR_CODE_NO_ALARM_CONFIGURED); ERROR_CLASS_OBJECT, ERROR_CODE_NO_ALARM_CONFIGURED);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Alarm Acknowledge: error %s!\n", fprintf(stderr, "Alarm Acknowledge: error %s!\n",
bactext_error_code_name(ERROR_CODE_NO_ALARM_CONFIGURED)); bactext_error_code_name(ERROR_CODE_NO_ALARM_CONFIGURED));
#endif #endif
} }
AA_ABORT: AA_ABORT:
pdu_len += len; pdu_len += len;
bytes_sent = bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
+13 -17
View File
@@ -419,32 +419,31 @@ void handler_cov_task(
COV_Subscriptions[index].monitoredObjectIdentifier.type; COV_Subscriptions[index].monitoredObjectIdentifier.type;
object_instance = object_instance =
COV_Subscriptions[index].monitoredObjectIdentifier.instance; COV_Subscriptions[index].monitoredObjectIdentifier.instance;
status = Device_Encode_Value_List( status =
object_type, Device_Encode_Value_List(object_type, object_instance,
object_instance,
&value_list[0]); &value_list[0]);
if (status) { if (status) {
COV_Subscriptions[index].send_requested = true; COV_Subscriptions[index].send_requested = true;
} }
if (COV_Subscriptions[index].send_requested) { if (COV_Subscriptions[index].send_requested) {
cov_send_request( cov_send_request(&COV_Subscriptions[index], &value_list[0]);
&COV_Subscriptions[index],
&value_list[0]);
COV_Subscriptions[index].send_requested = false; COV_Subscriptions[index].send_requested = false;
} }
if (status && ((index+1) < MAX_COV_SUBCRIPTIONS)) { if (status && ((index + 1) < MAX_COV_SUBCRIPTIONS)) {
/* if more than one subscription for this object instance */ /* if more than one subscription for this object instance */
for (index2 = index+1; index2 < MAX_COV_SUBCRIPTIONS; index2++) { for (index2 = index + 1; index2 < MAX_COV_SUBCRIPTIONS;
index2++) {
object_type2 = object_type2 =
COV_Subscriptions[index2].monitoredObjectIdentifier.type; COV_Subscriptions[index2].monitoredObjectIdentifier.
type;
object_instance2 = object_instance2 =
COV_Subscriptions[index2].monitoredObjectIdentifier.instance; COV_Subscriptions[index2].monitoredObjectIdentifier.
instance;
if ((COV_Subscriptions[index].lifetime) && if ((COV_Subscriptions[index].lifetime) &&
(COV_Subscriptions[index].valid) && (COV_Subscriptions[index].valid) &&
(object_type == object_type2) && (object_type == object_type2) &&
(object_instance == object_instance2)) { (object_instance == object_instance2)) {
cov_send_request( cov_send_request(&COV_Subscriptions[index2],
&COV_Subscriptions[index2],
&value_list[0]); &value_list[0]);
COV_Subscriptions[index2].send_requested = false; COV_Subscriptions[index2].send_requested = false;
} }
@@ -470,11 +469,8 @@ static bool cov_subscribe(
if (status) { if (status) {
status = Device_Value_List_Supported(object_type); status = Device_Value_List_Supported(object_type);
if (status) { if (status) {
status = cov_list_subscribe( status =
src, cov_list_subscribe(src, cov_data, error_class, error_code);
cov_data,
error_class,
error_code);
} else { } else {
*error_class = ERROR_CLASS_OBJECT; *error_class = ERROR_CLASS_OBJECT;
*error_code = ERROR_CODE_OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED; *error_code = ERROR_CODE_OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED;
+10 -10
View File
@@ -59,7 +59,7 @@ void handler_get_event_information(
BACNET_CONFIRMED_SERVICE_DATA * service_data) BACNET_CONFIRMED_SERVICE_DATA * service_data)
{ {
int len = 0; int len = 0;
int pdu_len = 0; int pdu_len = 0;
int apdu_len = 0; int apdu_len = 0;
BACNET_NPDU_DATA npdu_data; BACNET_NPDU_DATA npdu_data;
bool error = false; bool error = false;
@@ -116,8 +116,8 @@ void handler_get_event_information(
error = true; error = true;
goto GET_EVENT_ERROR; goto GET_EVENT_ERROR;
} }
pdu_len += len; pdu_len += len;
apdu_len = len; apdu_len = len;
for (i = 0; i < MAX_BACNET_OBJECT_TYPE; i++) { for (i = 0; i < MAX_BACNET_OBJECT_TYPE; i++) {
if (Get_Event_Info[i]) { if (Get_Event_Info[i]) {
for (j = 0; j < 0xffff; j++) { for (j = 0; j < 0xffff; j++) {
@@ -125,8 +125,10 @@ void handler_get_event_information(
if (valid_event > 0) { if (valid_event > 0) {
/* encode GetEvent_data only when type of object_id has max value */ /* encode GetEvent_data only when type of object_id has max value */
if (object_id.type != MAX_BACNET_OBJECT_TYPE) { if (object_id.type != MAX_BACNET_OBJECT_TYPE) {
if ((object_id.type == getevent_data.objectIdentifier.type) && if ((object_id.type ==
(object_id.instance == getevent_data.objectIdentifier.instance)) { getevent_data.objectIdentifier.type) &&
(object_id.instance ==
getevent_data.objectIdentifier.instance)) {
/* found 'Last Received Object Identifier' /* found 'Last Received Object Identifier'
so should set type of object_id to max value */ so should set type of object_id to max value */
object_id.type = MAX_BACNET_OBJECT_TYPE; object_id.type = MAX_BACNET_OBJECT_TYPE;
@@ -147,16 +149,14 @@ void handler_get_event_information(
if (apdu_len >= service_data->max_resp - 2) { if (apdu_len >= service_data->max_resp - 2) {
/* Device must be able to fit minimum one event information. /* Device must be able to fit minimum one event information.
Length of one event informations needs more than 50 octets. */ Length of one event informations needs more than 50 octets. */
if (service_data->max_resp < 128){ if (service_data->max_resp < 128) {
len = BACNET_STATUS_ABORT; len = BACNET_STATUS_ABORT;
error = true; error = true;
goto GET_EVENT_ERROR; goto GET_EVENT_ERROR;
} } else
else
more_events = true; more_events = true;
break; break;
} } else
else
pdu_len += len; pdu_len += len;
} else if (valid_event < 0) { } else if (valid_event < 0) {
break; break;
+1 -1
View File
@@ -128,7 +128,7 @@ void handler_read_property(
/* too big for the sender - send an abort /* too big for the sender - send an abort
* Setting of error code needed here as read property processing may * Setting of error code needed here as read property processing may
* have overriden the default set at start */ * have overriden the default set at start */
rpdata.error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED; rpdata.error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
len = BACNET_STATUS_ABORT; len = BACNET_STATUS_ABORT;
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "RP: Message too large.\n"); fprintf(stderr, "RP: Message too large.\n");
+6 -9
View File
@@ -319,9 +319,8 @@ void handler_read_property_multiple(
if (property_count == 0) { if (property_count == 0) {
/* handle the error code - but use the special property */ /* handle the error code - but use the special property */
len = len =
RPM_Encode_Property( RPM_Encode_Property(&Handler_Transmit_Buffer
&Handler_Transmit_Buffer[npdu_len], [npdu_len], (uint16_t) apdu_len, MAX_APDU,
(uint16_t) apdu_len, MAX_APDU,
&rpmdata); &rpmdata);
if (len > 0) { if (len > 0) {
apdu_len += len; apdu_len += len;
@@ -335,10 +334,9 @@ void handler_read_property_multiple(
RPM_Object_Property(&property_list, RPM_Object_Property(&property_list,
special_object_property, index); special_object_property, index);
len = len =
RPM_Encode_Property( RPM_Encode_Property(&Handler_Transmit_Buffer
&Handler_Transmit_Buffer[npdu_len], [npdu_len], (uint16_t) apdu_len, MAX_APDU,
(uint16_t) apdu_len, &rpmdata);
MAX_APDU, &rpmdata);
if (len > 0) { if (len > 0) {
apdu_len += len; apdu_len += len;
} else { } else {
@@ -352,8 +350,7 @@ void handler_read_property_multiple(
/* handle an individual property */ /* handle an individual property */
len = len =
RPM_Encode_Property(&Handler_Transmit_Buffer[npdu_len], RPM_Encode_Property(&Handler_Transmit_Buffer[npdu_len],
(uint16_t) apdu_len, (uint16_t) apdu_len, MAX_APDU, &rpmdata);
MAX_APDU, &rpmdata);
if (len > 0) { if (len > 0) {
apdu_len += len; apdu_len += len;
} else { } else {
+6 -6
View File
@@ -220,8 +220,8 @@ void rpm_ack_print_data(
#if PRINT_ENABLED #if PRINT_ENABLED
if (listOfProperties->propertyIdentifier < 512) { if (listOfProperties->propertyIdentifier < 512) {
fprintf(stdout, " %s: ", fprintf(stdout, " %s: ",
bactext_property_name bactext_property_name(listOfProperties->
(listOfProperties->propertyIdentifier)); propertyIdentifier));
} else { } else {
fprintf(stdout, " proprietary %u: ", fprintf(stdout, " proprietary %u: ",
(unsigned) listOfProperties->propertyIdentifier); (unsigned) listOfProperties->propertyIdentifier);
@@ -268,10 +268,10 @@ void rpm_ack_print_data(
#if PRINT_ENABLED #if PRINT_ENABLED
/* AccessError */ /* AccessError */
fprintf(stdout, "BACnet Error: %s: %s\r\n", fprintf(stdout, "BACnet Error: %s: %s\r\n",
bactext_error_class_name((int) listOfProperties->error. bactext_error_class_name((int) listOfProperties->
error_class), error.error_class),
bactext_error_code_name((int) listOfProperties->error. bactext_error_code_name((int) listOfProperties->
error_code)); error.error_code));
#endif #endif
} }
listOfProperties = listOfProperties->next; listOfProperties = listOfProperties->next;
+2 -2
View File
@@ -104,8 +104,8 @@ void handler_ucov_notification(
fprintf(stderr, "UCOV: "); fprintf(stderr, "UCOV: ");
if (pProperty_value->propertyIdentifier < 512) { if (pProperty_value->propertyIdentifier < 512) {
fprintf(stderr, "%s ", fprintf(stderr, "%s ",
bactext_property_name(pProperty_value-> bactext_property_name
propertyIdentifier)); (pProperty_value->propertyIdentifier));
} else { } else {
fprintf(stderr, "proprietary %u ", fprintf(stderr, "proprietary %u ",
pProperty_value->propertyIdentifier); pProperty_value->propertyIdentifier);
+3 -4
View File
@@ -64,10 +64,9 @@ static void match_name_or_object(
} }
} else { } else {
/* valid object_name copy in my device? */ /* valid object_name copy in my device? */
found = Device_Object_Name_Copy( found =
data->object.identifier.type, Device_Object_Name_Copy(data->object.identifier.type,
data->object.identifier.instance, data->object.identifier.instance, &object_name);
&object_name);
if (found) { if (found) {
Send_I_Have(Device_Object_Instance_Number(), Send_I_Have(Device_Object_Instance_Number(),
(BACNET_OBJECT_TYPE) data->object.identifier.type, (BACNET_OBJECT_TYPE) data->object.identifier.type,
+2 -2
View File
@@ -181,8 +181,8 @@ bool WPValidateString(
(!characterstring_printable(&pValue->type.Character_String))) { (!characterstring_printable(&pValue->type.Character_String))) {
/* assumption: non-empty also means must be "printable" */ /* assumption: non-empty also means must be "printable" */
*pErrorCode = ERROR_CODE_VALUE_OUT_OF_RANGE; *pErrorCode = ERROR_CODE_VALUE_OUT_OF_RANGE;
} else if (characterstring_length(&pValue->type. } else if (characterstring_length(&pValue->
Character_String) >= iMaxLen) { type.Character_String) >= iMaxLen) {
*pErrorClass = ERROR_CLASS_RESOURCES; *pErrorClass = ERROR_CLASS_RESOURCES;
*pErrorCode = ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY; *pErrorCode = ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY;
} else } else
+49 -52
View File
@@ -70,10 +70,10 @@ void handler_write_property_multiple(
BACNET_ADDRESS * src, BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_DATA * service_data) BACNET_CONFIRMED_SERVICE_DATA * service_data)
{ {
int len = 0; int len = 0;
int apdu_len = 0; int apdu_len = 0;
int npdu_len = 0; int npdu_len = 0;
int pdu_len = 0; int pdu_len = 0;
int decode_len = 0; int decode_len = 0;
bool error = false; bool error = false;
BACNET_WRITE_PROPERTY_DATA wp_data; BACNET_WRITE_PROPERTY_DATA wp_data;
@@ -84,9 +84,10 @@ void handler_write_property_multiple(
if (service_data->segmented_message) { if (service_data->segmented_message) {
len = abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len], len =
service_data->invoke_id, abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "WPM: Segmented message. Sending Abort!\n"); fprintf(stderr, "WPM: Segmented message. Sending Abort!\n");
#endif #endif
@@ -95,27 +96,25 @@ void handler_write_property_multiple(
/* decode service request */ /* decode service request */
decode_len = 0; decode_len = 0;
do do {
{
/* decode Object Identifier */ /* decode Object Identifier */
len = wpm_decode_object_id(&service_request[decode_len], len =
service_len - decode_len, &wp_data); wpm_decode_object_id(&service_request[decode_len],
if (len > 0) service_len - decode_len, &wp_data);
{ if (len > 0) {
uint8_t tag_number = 0; uint8_t tag_number = 0;
decode_len += len; decode_len += len;
/* Opening tag 1 - List of Properties */ /* Opening tag 1 - List of Properties */
if (decode_is_opening_tag_number(&service_request[decode_len++], 1)) if (decode_is_opening_tag_number(&service_request[decode_len++],
{ 1)) {
do do {
{
/* decode a 'Property Identifier'; (3) an optional 'Property Array Index' */ /* decode a 'Property Identifier'; (3) an optional 'Property Array Index' */
/* (4) a 'Property Value'; and (5) an optional 'Priority'. */ /* (4) a 'Property Value'; and (5) an optional 'Priority'. */
len = wpm_decode_object_property(&service_request[decode_len], len =
service_len - decode_len, &wp_data); wpm_decode_object_property(&service_request
if (len > 0) [decode_len], service_len - decode_len, &wp_data);
{ if (len > 0) {
decode_len += len; decode_len += len;
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
@@ -123,81 +122,79 @@ void handler_write_property_multiple(
(unsigned long) wp_data.object_type, (unsigned long) wp_data.object_type,
(unsigned long) wp_data.object_instance, (unsigned long) wp_data.object_instance,
(unsigned long) wp_data.object_property, (unsigned long) wp_data.object_property,
(unsigned long) wp_data.priority, (long) wp_data.array_index); (unsigned long) wp_data.priority,
(long) wp_data.array_index);
#endif #endif
if (Device_Write_Property(&wp_data) == false) if (Device_Write_Property(&wp_data) == false) {
{
error = true; error = true;
break; /* do while (decoding List of Properties) */ break; /* do while (decoding List of Properties) */
} }
} } else {
else
{
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "WPM: Bad Encoding!\n"); fprintf(stderr, "WPM: Bad Encoding!\n");
#endif #endif
wp_data.error_class = ERROR_CLASS_PROPERTY; wp_data.error_class = ERROR_CLASS_PROPERTY;
wp_data.error_code = ERROR_CODE_OTHER; wp_data.error_code = ERROR_CODE_OTHER;
error = true; error = true;
break; /* do while (decoding List of Properties) */ break; /* do while (decoding List of Properties) */
} }
/* Closing tag 1 - List of Properties */ /* Closing tag 1 - List of Properties */
if (decode_is_closing_tag_number(&service_request[decode_len], 1)) if (decode_is_closing_tag_number(&service_request
{ [decode_len], 1)) {
tag_number = 1; tag_number = 1;
decode_len++; decode_len++;
} } else
else
tag_number = 0; /* it was not tag 1, decode next Property Identifier ... */ tag_number = 0; /* it was not tag 1, decode next Property Identifier ... */
} }
while(tag_number != 1); /* end decoding List of Properties for "that" object */ while (tag_number != 1); /* end decoding List of Properties for "that" object */
if (error) if (error)
break; /*do while (decode service request) */ break; /*do while (decode service request) */
} }
} } else {
else
{
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "WPM: Bad Encoding!\n"); fprintf(stderr, "WPM: Bad Encoding!\n");
#endif #endif
wp_data.error_class = ERROR_CLASS_OBJECT; wp_data.error_class = ERROR_CLASS_OBJECT;
wp_data.error_code = ERROR_CODE_OTHER; wp_data.error_code = ERROR_CODE_OTHER;
error = true; error = true;
break; /*do while (decode service request) */ break; /*do while (decode service request) */
} }
} }
while(decode_len < service_len); while (decode_len < service_len);
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
npdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, npdu_len =
&npdu_data); npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
apdu_len = 0; apdu_len = 0;
if (error == false) { if (error == false) {
apdu_len = wpm_ack_encode_apdu_init(&Handler_Transmit_Buffer[npdu_len], apdu_len =
service_data->invoke_id); wpm_ack_encode_apdu_init(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "WPM: Sending Simple Ack!\n"); fprintf(stderr, "WPM: Sending Simple Ack!\n");
#endif #endif
} } else {
else { apdu_len =
apdu_len = wpm_error_ack_encode_apdu(&Handler_Transmit_Buffer[npdu_len], wpm_error_ack_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id, &wp_data); service_data->invoke_id, &wp_data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "WPM: Sending Error!\n"); fprintf(stderr, "WPM: Sending Error!\n");
#endif #endif
} }
WPM_ABORT: WPM_ABORT:
pdu_len = npdu_len + apdu_len; pdu_len = npdu_len + apdu_len;
bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], bytes_sent =
pdu_len); datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
} }
+1 -1
View File
@@ -57,7 +57,7 @@ void Send_I_Have(
uint32_t device_id, uint32_t device_id,
BACNET_OBJECT_TYPE object_type, BACNET_OBJECT_TYPE object_type,
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name) BACNET_CHARACTER_STRING * object_name)
{ {
int len = 0; int len = 0;
int pdu_len = 0; int pdu_len = 0;
+3 -2
View File
@@ -155,8 +155,9 @@ uint8_t Send_Write_Property_Request(
#if PRINT_ENABLED_DEBUG #if PRINT_ENABLED_DEBUG
fprintf(stderr, "WriteProperty service: " "%s tag=%d\n", fprintf(stderr, "WriteProperty service: " "%s tag=%d\n",
(object_value->context_specific ? "context" : "application"), (object_value->context_specific ? "context" : "application"),
(int) (object_value->context_specific ? object_value-> (int) (object_value->
context_tag : object_value->tag)); context_specific ? object_value->context_tag : object_value->
tag));
#endif #endif
len = bacapp_encode_data(&application_data[apdu_len], object_value); len = bacapp_encode_data(&application_data[apdu_len], object_value);
if ((len + apdu_len) < MAX_APDU) { if ((len + apdu_len) < MAX_APDU) {
+30 -31
View File
@@ -172,7 +172,8 @@ static void packet_statistics(
break; break;
case FRAME_TYPE_POLL_FOR_MASTER: case FRAME_TYPE_POLL_FOR_MASTER:
if (MSTP_Statistics[src].last_pfm_tokens) { if (MSTP_Statistics[src].last_pfm_tokens) {
npoll = MSTP_Statistics[src].token_received_count - npoll =
MSTP_Statistics[src].token_received_count -
MSTP_Statistics[src].last_pfm_tokens; MSTP_Statistics[src].last_pfm_tokens;
if (npoll > MSTP_Statistics[src].npoll) { if (npoll > MSTP_Statistics[src].npoll) {
MSTP_Statistics[src].npoll = npoll; MSTP_Statistics[src].npoll = npoll;
@@ -252,10 +253,8 @@ static void packet_statistics_print(
fprintf(stdout, "\r\n"); fprintf(stdout, "\r\n");
fprintf(stdout, "==== MS/TP Frame Counts ====\r\n"); fprintf(stdout, "==== MS/TP Frame Counts ====\r\n");
fprintf(stdout, "%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s", fprintf(stdout, "%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s", "MAC", "Tokens",
"MAC", "PFM", "RPFM", "DER", "Postpd", "DNER", "TestReq", "TestRsp");
"Tokens","PFM","RPFM","DER",
"Postpd","DNER","TestReq","TestRsp");
fprintf(stdout, "\r\n"); fprintf(stdout, "\r\n");
for (i = 0; i < 256; i++) { for (i = 0; i < 256; i++) {
/* check for masters or slaves */ /* check for masters or slaves */
@@ -280,9 +279,9 @@ static void packet_statistics_print(
node_count = 0; node_count = 0;
fprintf(stdout, "\r\n"); fprintf(stdout, "\r\n");
fprintf(stdout, "==== MS/TP Usage and Timing Maximums ====\r\n"); fprintf(stdout, "==== MS/TP Usage and Timing Maximums ====\r\n");
fprintf(stdout, "%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-7s", fprintf(stdout, "%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-7s", "MAC",
"MAC","MaxMstr","Retries","Npoll","Self", "MaxMstr", "Retries", "Npoll", "Self", "Treply", "Tusage", "Trpfm",
"Treply","Tusage","Trpfm","Tder","Tpostpd"); "Tder", "Tpostpd");
fprintf(stdout, "\r\n"); fprintf(stdout, "\r\n");
for (i = 0; i < 256; i++) { for (i = 0; i < 256; i++) {
/* check for masters or slaves */ /* check for masters or slaves */
@@ -552,8 +551,8 @@ static void write_received_packet(
(void) data_write((char *) &mstp_port->DataCRCActualLSB, 1, 1); (void) data_write((char *) &mstp_port->DataCRCActualLSB, 1, 1);
} }
} else { } else {
fprintf(stderr, "mstpcap[packet]: failed to open %s: %s\n", Capture_Filename, fprintf(stderr, "mstpcap[packet]: failed to open %s: %s\n",
strerror(errno)); Capture_Filename, strerror(errno));
} }
} }
@@ -561,61 +560,61 @@ static void write_received_packet(
static bool test_global_header( static bool test_global_header(
const char *filename) const char *filename)
{ {
uint32_t magic_number = 0; /* magic number */ uint32_t magic_number = 0; /* magic number */
uint16_t version_major = 0; /* major version number */ uint16_t version_major = 0; /* major version number */
uint16_t version_minor = 0; /* minor version number */ uint16_t version_minor = 0; /* minor version number */
int32_t thiszone = 0; /* GMT to local correction */ int32_t thiszone = 0; /* GMT to local correction */
uint32_t sigfigs = 0; /* accuracy of timestamps */ uint32_t sigfigs = 0; /* accuracy of timestamps */
uint32_t snaplen = 0; /* max length of captured packets, in octets */ uint32_t snaplen = 0; /* max length of captured packets, in octets */
uint32_t network = 0; /* data link type - BACNET_MS_TP */ uint32_t network = 0; /* data link type - BACNET_MS_TP */
size_t count = 0; size_t count = 0;
/* create a new file. */ /* create a new file. */
pFile = fopen(filename, "rb"); pFile = fopen(filename, "rb");
if (pFile) { if (pFile) {
count = fread(&magic_number, sizeof(magic_number), 1, pFile); count = fread(&magic_number, sizeof(magic_number), 1, pFile);
if ((count != 1) || (magic_number != 0xa1b2c3d4)) { if ((count != 1) || (magic_number != 0xa1b2c3d4)) {
fprintf(stderr, "mstpcap: invalid magic number\n"); fprintf(stderr, "mstpcap: invalid magic number\n");
fclose(pFile); fclose(pFile);
pFile = NULL; pFile = NULL;
return false; return false;
} }
count = fread(&version_major, sizeof(version_major), 1, pFile); count = fread(&version_major, sizeof(version_major), 1, pFile);
if ((count != 1) || (version_major != 2)) { if ((count != 1) || (version_major != 2)) {
fprintf(stderr, "mstpcap: invalid major version\n"); fprintf(stderr, "mstpcap: invalid major version\n");
fclose(pFile); fclose(pFile);
pFile = NULL; pFile = NULL;
return false; return false;
} }
count = fread(&version_minor, sizeof(version_minor), 1, pFile); count = fread(&version_minor, sizeof(version_minor), 1, pFile);
if ((count != 1) || (version_minor != 4)) { if ((count != 1) || (version_minor != 4)) {
fprintf(stderr, "mstpcap: invalid minor version\n"); fprintf(stderr, "mstpcap: invalid minor version\n");
fclose(pFile); fclose(pFile);
pFile = NULL; pFile = NULL;
return false; return false;
} }
count = fread(&thiszone, sizeof(thiszone), 1, pFile); count = fread(&thiszone, sizeof(thiszone), 1, pFile);
if ((count != 1) || (thiszone != 0)) { if ((count != 1) || (thiszone != 0)) {
fprintf(stderr, "mstpcap: invalid time zone\n"); fprintf(stderr, "mstpcap: invalid time zone\n");
fclose(pFile); fclose(pFile);
pFile = NULL; pFile = NULL;
return false; return false;
} }
count = fread(&sigfigs, sizeof(sigfigs), 1, pFile); count = fread(&sigfigs, sizeof(sigfigs), 1, pFile);
if ((count != 1) || (sigfigs != 0)) { if ((count != 1) || (sigfigs != 0)) {
fprintf(stderr, "mstpcap: invalid time stamp accuracy\n"); fprintf(stderr, "mstpcap: invalid time stamp accuracy\n");
fclose(pFile); fclose(pFile);
pFile = NULL; pFile = NULL;
return false; return false;
} }
count = fread(&snaplen, sizeof(snaplen), 1, pFile); count = fread(&snaplen, sizeof(snaplen), 1, pFile);
if ((count != 1) || (snaplen != 65535)) { if ((count != 1) || (snaplen != 65535)) {
fprintf(stderr, "mstpcap: invalid length of captured packets\n"); fprintf(stderr, "mstpcap: invalid length of captured packets\n");
fclose(pFile); fclose(pFile);
pFile = NULL; pFile = NULL;
return false; return false;
} }
count = fread(&network, sizeof(network), 1, pFile); count = fread(&network, sizeof(network), 1, pFile);
if ((count != 1) || (network != 165)) { if ((count != 1) || (network != 165)) {
fprintf(stderr, "mstpcap: invalid data link type (DLT)\n"); fprintf(stderr, "mstpcap: invalid data link type (DLT)\n");
fclose(pFile); fclose(pFile);
@@ -634,11 +633,11 @@ static bool test_global_header(
static bool read_received_packet( static bool read_received_packet(
volatile struct mstp_port_struct_t *mstp_port) volatile struct mstp_port_struct_t *mstp_port)
{ {
uint32_t ts_sec = 0; /* timestamp seconds */ uint32_t ts_sec = 0; /* timestamp seconds */
uint32_t ts_usec = 0; /* timestamp microseconds */ uint32_t ts_usec = 0; /* timestamp microseconds */
uint32_t incl_len = 0; /* number of octets of packet saved in file */ uint32_t incl_len = 0; /* number of octets of packet saved in file */
uint32_t orig_len = 0; /* actual length of packet */ uint32_t orig_len = 0; /* actual length of packet */
uint8_t header[8] = {0}; /* MS/TP header */ uint8_t header[8] = { 0 }; /* MS/TP header */
struct timeval tv; struct timeval tv;
size_t count = 0; size_t count = 0;
@@ -678,12 +677,12 @@ static bool read_received_packet(
mstp_port->FrameType = header[2]; mstp_port->FrameType = header[2];
mstp_port->DestinationAddress = header[3]; mstp_port->DestinationAddress = header[3];
mstp_port->SourceAddress = header[4]; mstp_port->SourceAddress = header[4];
mstp_port->DataLength = MAKE_WORD(header[6],header[5]); mstp_port->DataLength = MAKE_WORD(header[6], header[5]);
mstp_port->HeaderCRCActual = header[7]; mstp_port->HeaderCRCActual = header[7];
if (orig_len > 8) { if (orig_len > 8) {
mstp_port->DataLength = orig_len - 8 - 2; mstp_port->DataLength = orig_len - 8 - 2;
count = fread(mstp_port->InputBuffer, count =
mstp_port->DataLength, 1, pFile); fread(mstp_port->InputBuffer, mstp_port->DataLength, 1, pFile);
if (count != 1) { if (count != 1) {
fclose(pFile); fclose(pFile);
pFile = NULL; pFile = NULL;
@@ -811,9 +810,9 @@ int main(
if ((argc > 1) && (strcmp(argv[1], "--version") == 0)) { if ((argc > 1) && (strcmp(argv[1], "--version") == 0)) {
printf("mstpcap %s\r\n", BACNET_VERSION_TEXT); printf("mstpcap %s\r\n", BACNET_VERSION_TEXT);
printf("Copyright (C) 2011 by Steve Karg\r\n" printf("Copyright (C) 2011 by Steve Karg\r\n"
"This is free software; see the source for copying conditions.\r\n" "This is free software; see the source for copying conditions.\r\n"
"There is NO warranty; not even for MERCHANTABILITY or\r\n" "There is NO warranty; not even for MERCHANTABILITY or\r\n"
"FITNESS FOR A PARTICULAR PURPOSE.\r\n"); "FITNESS FOR A PARTICULAR PURPOSE.\r\n");
return 0; return 0;
} }
if ((argc > 1) && (strcmp(argv[1], "--scan") == 0)) { if ((argc > 1) && (strcmp(argv[1], "--scan") == 0)) {
+264 -231
View File
@@ -108,7 +108,7 @@ void Analog_Input_Init(
unsigned i, j; unsigned i, j;
for (i = 0; i < MAX_ANALOG_INPUTS; i++) { for (i = 0; i < MAX_ANALOG_INPUTS; i++) {
AI_Descr[i].Present_Value = 0.0f; AI_Descr[i].Present_Value = 0.0f;
AI_Descr[i].Out_Of_Service = false; AI_Descr[i].Out_Of_Service = false;
AI_Descr[i].Units = UNITS_PERCENT; AI_Descr[i].Units = UNITS_PERCENT;
AI_Descr[i].Reliability = RELIABILITY_NO_FAULT_DETECTED; AI_Descr[i].Reliability = RELIABILITY_NO_FAULT_DETECTED;
@@ -127,8 +127,7 @@ void Analog_Input_Init(
handler_get_event_information_set(OBJECT_ANALOG_INPUT, handler_get_event_information_set(OBJECT_ANALOG_INPUT,
Analog_Input_Event_Information); Analog_Input_Event_Information);
/* Set handler for AcknowledgeAlarm function */ /* Set handler for AcknowledgeAlarm function */
handler_alarm_ack_set(OBJECT_ANALOG_INPUT, handler_alarm_ack_set(OBJECT_ANALOG_INPUT, Analog_Input_Alarm_Ack);
Analog_Input_Alarm_Ack);
#endif #endif
} }
} }
@@ -207,7 +206,7 @@ void Analog_Input_Present_Value_Set(
bool Analog_Input_Object_Name( bool Analog_Input_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name) BACNET_CHARACTER_STRING * object_name)
{ {
static char text_string[32] = ""; /* okay for single thread */ static char text_string[32] = ""; /* okay for single thread */
unsigned int index; unsigned int index;
@@ -277,50 +276,61 @@ int Analog_Input_Read_Property(
bitstring_init(&bit_string); bitstring_init(&bit_string);
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM, bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM,
CurrentAI->Event_State ? true : false); CurrentAI->Event_State ? true : false);
#else #else
bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM, false); bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM, false);
#endif #endif
bitstring_set_bit(&bit_string, STATUS_FLAG_FAULT, false); bitstring_set_bit(&bit_string, STATUS_FLAG_FAULT, false);
bitstring_set_bit(&bit_string, STATUS_FLAG_OVERRIDDEN, false); bitstring_set_bit(&bit_string, STATUS_FLAG_OVERRIDDEN, false);
bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE, CurrentAI->Out_Of_Service); bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE,
CurrentAI->Out_Of_Service);
apdu_len = encode_application_bitstring(&apdu[0], &bit_string); apdu_len = encode_application_bitstring(&apdu[0], &bit_string);
break; break;
case PROP_EVENT_STATE: case PROP_EVENT_STATE:
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
apdu_len = encode_application_enumerated(&apdu[0], apdu_len =
CurrentAI->Event_State); encode_application_enumerated(&apdu[0],
CurrentAI->Event_State);
#else #else
apdu_len = encode_application_enumerated(&apdu[0], apdu_len =
EVENT_STATE_NORMAL); encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL);
#endif #endif
break; break;
case PROP_RELIABILITY: case PROP_RELIABILITY:
apdu_len = encode_application_enumerated(&apdu[0], CurrentAI->Reliability); apdu_len =
encode_application_enumerated(&apdu[0],
CurrentAI->Reliability);
break; break;
case PROP_OUT_OF_SERVICE: case PROP_OUT_OF_SERVICE:
apdu_len = encode_application_boolean(&apdu[0], CurrentAI->Out_Of_Service); apdu_len =
encode_application_boolean(&apdu[0],
CurrentAI->Out_Of_Service);
break; break;
case PROP_UNITS: case PROP_UNITS:
apdu_len = encode_application_enumerated(&apdu[0], CurrentAI->Units); apdu_len =
encode_application_enumerated(&apdu[0], CurrentAI->Units);
break; break;
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
case PROP_TIME_DELAY: case PROP_TIME_DELAY:
apdu_len = encode_application_unsigned(&apdu[0], CurrentAI->Time_Delay); apdu_len =
encode_application_unsigned(&apdu[0], CurrentAI->Time_Delay);
break; break;
case PROP_NOTIFICATION_CLASS: case PROP_NOTIFICATION_CLASS:
apdu_len = encode_application_unsigned(&apdu[0], CurrentAI->Notification_Class); apdu_len =
encode_application_unsigned(&apdu[0],
CurrentAI->Notification_Class);
break; break;
case PROP_HIGH_LIMIT: case PROP_HIGH_LIMIT:
apdu_len = encode_application_real(&apdu[0], CurrentAI->High_Limit); apdu_len =
encode_application_real(&apdu[0], CurrentAI->High_Limit);
break; break;
case PROP_LOW_LIMIT: case PROP_LOW_LIMIT:
@@ -334,21 +344,26 @@ int Analog_Input_Read_Property(
case PROP_LIMIT_ENABLE: case PROP_LIMIT_ENABLE:
bitstring_init(&bit_string); bitstring_init(&bit_string);
bitstring_set_bit(&bit_string, 0, bitstring_set_bit(&bit_string, 0,
(CurrentAI->Limit_Enable & EVENT_LOW_LIMIT_ENABLE ) ? true : false ); (CurrentAI->
Limit_Enable & EVENT_LOW_LIMIT_ENABLE) ? true : false);
bitstring_set_bit(&bit_string, 1, bitstring_set_bit(&bit_string, 1,
(CurrentAI->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) ? true : false ); (CurrentAI->
Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) ? true : false);
apdu_len = encode_application_bitstring(&apdu[0],&bit_string); apdu_len = encode_application_bitstring(&apdu[0], &bit_string);
break; break;
case PROP_EVENT_ENABLE: case PROP_EVENT_ENABLE:
bitstring_init(&bit_string); bitstring_init(&bit_string);
bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL, bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL,
(CurrentAI->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true : false ); (CurrentAI->
Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true : false);
bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT, bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT,
(CurrentAI->Event_Enable & EVENT_ENABLE_TO_FAULT ) ? true : false ); (CurrentAI->
Event_Enable & EVENT_ENABLE_TO_FAULT) ? true : false);
bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL, bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL,
(CurrentAI->Event_Enable & EVENT_ENABLE_TO_NORMAL ) ? true : false ); (CurrentAI->
Event_Enable & EVENT_ENABLE_TO_NORMAL) ? true : false);
apdu_len = encode_application_bitstring(&apdu[0], &bit_string); apdu_len = encode_application_bitstring(&apdu[0], &bit_string);
break; break;
@@ -356,62 +371,69 @@ int Analog_Input_Read_Property(
case PROP_ACKED_TRANSITIONS: case PROP_ACKED_TRANSITIONS:
bitstring_init(&bit_string); bitstring_init(&bit_string);
bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL, bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL,
CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked); CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
bIsAcked);
bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT, bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT,
CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked); CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked);
bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL, bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL,
CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked); CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked);
apdu_len = encode_application_bitstring(&apdu[0], &bit_string); apdu_len = encode_application_bitstring(&apdu[0], &bit_string);
break; break;
case PROP_NOTIFY_TYPE: case PROP_NOTIFY_TYPE:
apdu_len = encode_application_enumerated(&apdu[0], apdu_len =
CurrentAI->Notify_Type ? NOTIFY_EVENT : NOTIFY_ALARM); encode_application_enumerated(&apdu[0],
CurrentAI->Notify_Type ? NOTIFY_EVENT : NOTIFY_ALARM);
break; break;
case PROP_EVENT_TIME_STAMPS: case PROP_EVENT_TIME_STAMPS:
/* Array element zero is the number of elements in the array */ /* Array element zero is the number of elements in the array */
if (rpdata->array_index == 0) if (rpdata->array_index == 0)
apdu_len = encode_application_unsigned(&apdu[0], apdu_len =
MAX_BACNET_EVENT_TRANSITION); encode_application_unsigned(&apdu[0],
MAX_BACNET_EVENT_TRANSITION);
/* if no index was specified, then try to encode the entire list */ /* if no index was specified, then try to encode the entire list */
/* into one packet. */ /* into one packet. */
else if (rpdata->array_index == BACNET_ARRAY_ALL) { else if (rpdata->array_index == BACNET_ARRAY_ALL) {
for (i = 0; i < MAX_BACNET_EVENT_TRANSITION; i++) {; for (i = 0; i < MAX_BACNET_EVENT_TRANSITION; i++) {;
len = encode_opening_tag(&apdu[apdu_len], len =
TIME_STAMP_DATETIME); encode_opening_tag(&apdu[apdu_len],
len += encode_application_date(&apdu[apdu_len + len], TIME_STAMP_DATETIME);
&CurrentAI->Event_Time_Stamps[i].date); len +=
len += encode_application_time(&apdu[apdu_len + len], encode_application_date(&apdu[apdu_len + len],
&CurrentAI->Event_Time_Stamps[i].time); &CurrentAI->Event_Time_Stamps[i].date);
len += encode_closing_tag(&apdu[apdu_len + len], len +=
TIME_STAMP_DATETIME); encode_application_time(&apdu[apdu_len + len],
&CurrentAI->Event_Time_Stamps[i].time);
len +=
encode_closing_tag(&apdu[apdu_len + len],
TIME_STAMP_DATETIME);
/* add it if we have room */ /* add it if we have room */
if ((apdu_len + len) < MAX_APDU) if ((apdu_len + len) < MAX_APDU)
apdu_len += len; apdu_len += len;
else { else {
rpdata->error_class = ERROR_CLASS_SERVICES; rpdata->error_class = ERROR_CLASS_SERVICES;
rpdata->error_code = ERROR_CODE_NO_SPACE_FOR_OBJECT; rpdata->error_code = ERROR_CODE_NO_SPACE_FOR_OBJECT;
apdu_len = BACNET_STATUS_ERROR; apdu_len = BACNET_STATUS_ERROR;
break; break;
} }
} }
} } else if (rpdata->array_index <= MAX_BACNET_EVENT_TRANSITION) {
else if (rpdata->array_index <= MAX_BACNET_EVENT_TRANSITION) { apdu_len =
apdu_len = encode_opening_tag(&apdu[apdu_len], encode_opening_tag(&apdu[apdu_len], TIME_STAMP_DATETIME);
TIME_STAMP_DATETIME); apdu_len +=
apdu_len += encode_application_date(&apdu[apdu_len], encode_application_date(&apdu[apdu_len],
&CurrentAI->Event_Time_Stamps[rpdata->array_index].date); &CurrentAI->Event_Time_Stamps[rpdata->array_index].date);
apdu_len += encode_application_time(&apdu[apdu_len], apdu_len +=
&CurrentAI->Event_Time_Stamps[rpdata->array_index].time); encode_application_time(&apdu[apdu_len],
apdu_len += encode_closing_tag(&apdu[apdu_len], &CurrentAI->Event_Time_Stamps[rpdata->array_index].time);
TIME_STAMP_DATETIME); apdu_len +=
} encode_closing_tag(&apdu[apdu_len], TIME_STAMP_DATETIME);
else { } else {
rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_class = ERROR_CLASS_PROPERTY;
rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX;
apdu_len = BACNET_STATUS_ERROR; apdu_len = BACNET_STATUS_ERROR;
} }
break; break;
@@ -436,11 +458,10 @@ int Analog_Input_Read_Property(
break; break;
} }
/* only array properties can have array options */ /* only array properties can have array options */
if ((apdu_len >= 0) && if ((apdu_len >= 0) && (rpdata->object_property != PROP_EVENT_TIME_STAMPS)
(rpdata->object_property != PROP_EVENT_TIME_STAMPS) && && (rpdata->array_index != BACNET_ARRAY_ALL)) {
(rpdata->array_index != BACNET_ARRAY_ALL)) {
rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_class = ERROR_CLASS_PROPERTY;
rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
apdu_len = BACNET_STATUS_ERROR; apdu_len = BACNET_STATUS_ERROR;
} }
@@ -449,7 +470,7 @@ int Analog_Input_Read_Property(
/* returns true if successful */ /* returns true if successful */
bool Analog_Input_Write_Property( bool Analog_Input_Write_Property(
BACNET_WRITE_PROPERTY_DATA * wp_data) BACNET_WRITE_PROPERTY_DATA * wp_data)
{ {
bool status = false; /* return value */ bool status = false; /* return value */
unsigned int object_index = 0; unsigned int object_index = 0;
@@ -465,7 +486,7 @@ bool Analog_Input_Write_Property(
if (len < 0) { if (len < 0) {
/* error while decoding - a value larger than we can handle */ /* error while decoding - a value larger than we can handle */
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
return false; return false;
} }
@@ -484,11 +505,10 @@ bool Analog_Input_Write_Property(
if (status) { if (status) {
if (CurrentAI->Out_Of_Service == true) { if (CurrentAI->Out_Of_Service == true) {
Analog_Input_Present_Value_Set(wp_data->object_instance, Analog_Input_Present_Value_Set(wp_data->object_instance,
value.type.Real); value.type.Real);
} } else {
else {
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
status = false; status = false;
} }
} }
@@ -570,13 +590,12 @@ bool Analog_Input_Write_Property(
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
if(value.type.Bit_String.bits_used == 2) { if (value.type.Bit_String.bits_used == 2) {
CurrentAI->Limit_Enable = value.type.Bit_String.value[0]; CurrentAI->Limit_Enable = value.type.Bit_String.value[0];
} } else {
else { wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; status = false;
status = false;
} }
} }
break; break;
@@ -587,13 +606,12 @@ bool Analog_Input_Write_Property(
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
if(value.type.Bit_String.bits_used == 3) { if (value.type.Bit_String.bits_used == 3) {
CurrentAI->Event_Enable = value.type.Bit_String.value[0]; CurrentAI->Event_Enable = value.type.Bit_String.value[0];
} } else {
else { wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; status = false;
status = false;
} }
} }
break; break;
@@ -604,13 +622,12 @@ bool Analog_Input_Write_Property(
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
if(value.type.Bit_String.bits_used > NOTIFY_EVENT) { if (value.type.Bit_String.bits_used > NOTIFY_EVENT) {
CurrentAI->Event_Enable = value.type.Enumerated; CurrentAI->Event_Enable = value.type.Enumerated;
} } else {
else { wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; status = false;
status = false;
} }
} }
break; break;
@@ -618,7 +635,7 @@ bool Analog_Input_Write_Property(
default: default:
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
break; break;
} }
@@ -626,7 +643,8 @@ bool Analog_Input_Write_Property(
} }
void Analog_Input_Intrinsic_Reporting(uint32_t object_instance) void Analog_Input_Intrinsic_Reporting(
uint32_t object_instance)
{ {
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
BACNET_EVENT_NOTIFICATION_DATA event_data; BACNET_EVENT_NOTIFICATION_DATA event_data;
@@ -637,7 +655,7 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance)
uint8_t ToState; uint8_t ToState;
float ExceededLimit = 0.0f; float ExceededLimit = 0.0f;
float PresentVal = 0.0f; float PresentVal = 0.0f;
bool SendNotify = false; bool SendNotify = false;
object_index = Analog_Input_Instance_To_Index(object_instance); object_index = Analog_Input_Instance_To_Index(object_instance);
@@ -648,7 +666,7 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance)
/* check limits */ /* check limits */
if (!CurrentAI->Limit_Enable) if (!CurrentAI->Limit_Enable)
return; /* limits are not configured */ return; /* limits are not configured */
if (CurrentAI->Ack_notify_data.bSendAckNotify) { if (CurrentAI->Ack_notify_data.bSendAckNotify) {
@@ -659,8 +677,7 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance)
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Send Acknotification for (%s,%d).\n", fprintf(stderr, "Send Acknotification for (%s,%d).\n",
bactext_object_type_name(OBJECT_ANALOG_INPUT), bactext_object_type_name(OBJECT_ANALOG_INPUT), object_instance);
object_instance);
#endif /* PRINT_ENABLED */ #endif /* PRINT_ENABLED */
characterstring_init_ansi(&msgText, "AckNotification"); characterstring_init_ansi(&msgText, "AckNotification");
@@ -670,25 +687,23 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance)
/* Send EventNotification. */ /* Send EventNotification. */
SendNotify = true; SendNotify = true;
} } else {
else
{
/* actual Present_Value */ /* actual Present_Value */
PresentVal = Analog_Input_Present_Value(object_instance); PresentVal = Analog_Input_Present_Value(object_instance);
FromState = CurrentAI->Event_State; FromState = CurrentAI->Event_State;
switch (CurrentAI->Event_State) switch (CurrentAI->Event_State) {
{
case EVENT_STATE_NORMAL: case EVENT_STATE_NORMAL:
/* A TO-OFFNORMAL event is generated under these conditions: /* A TO-OFFNORMAL event is generated under these conditions:
(a) the Present_Value must exceed the High_Limit for a minimum (a) the Present_Value must exceed the High_Limit for a minimum
period of time, specified in the Time_Delay property, and period of time, specified in the Time_Delay property, and
(b) the HighLimitEnable flag must be set in the Limit_Enable property, and (b) the HighLimitEnable flag must be set in the Limit_Enable property, and
(c) the TO-OFFNORMAL flag must be set in the Event_Enable property. */ (c) the TO-OFFNORMAL flag must be set in the Event_Enable property. */
if ((PresentVal > CurrentAI->High_Limit) && if ((PresentVal > CurrentAI->High_Limit) &&
((CurrentAI->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) == EVENT_HIGH_LIMIT_ENABLE) && ((CurrentAI->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) ==
((CurrentAI->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) == EVENT_ENABLE_TO_OFFNORMAL)) EVENT_HIGH_LIMIT_ENABLE) &&
{ ((CurrentAI->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ==
if(!CurrentAI->Remaining_Time_Delay) EVENT_ENABLE_TO_OFFNORMAL)) {
if (!CurrentAI->Remaining_Time_Delay)
CurrentAI->Event_State = EVENT_STATE_HIGH_LIMIT; CurrentAI->Event_State = EVENT_STATE_HIGH_LIMIT;
else else
CurrentAI->Remaining_Time_Delay--; CurrentAI->Remaining_Time_Delay--;
@@ -696,15 +711,16 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance)
} }
/* A TO-OFFNORMAL event is generated under these conditions: /* A TO-OFFNORMAL event is generated under these conditions:
(a) the Present_Value must exceed the Low_Limit plus the Deadband (a) the Present_Value must exceed the Low_Limit plus the Deadband
for a minimum period of time, specified in the Time_Delay property, and for a minimum period of time, specified in the Time_Delay property, and
(b) the LowLimitEnable flag must be set in the Limit_Enable property, and (b) the LowLimitEnable flag must be set in the Limit_Enable property, and
(c) the TO-NORMAL flag must be set in the Event_Enable property. */ (c) the TO-NORMAL flag must be set in the Event_Enable property. */
if ((PresentVal < CurrentAI->Low_Limit) && if ((PresentVal < CurrentAI->Low_Limit) &&
((CurrentAI->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) == EVENT_LOW_LIMIT_ENABLE) && ((CurrentAI->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) ==
((CurrentAI->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) == EVENT_ENABLE_TO_OFFNORMAL)) EVENT_LOW_LIMIT_ENABLE) &&
{ ((CurrentAI->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ==
if(!CurrentAI->Remaining_Time_Delay) EVENT_ENABLE_TO_OFFNORMAL)) {
if (!CurrentAI->Remaining_Time_Delay)
CurrentAI->Event_State = EVENT_STATE_LOW_LIMIT; CurrentAI->Event_State = EVENT_STATE_LOW_LIMIT;
else else
CurrentAI->Remaining_Time_Delay--; CurrentAI->Remaining_Time_Delay--;
@@ -717,15 +733,16 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance)
case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_HIGH_LIMIT:
/* Once exceeded, the Present_Value must fall below the High_Limit minus /* Once exceeded, the Present_Value must fall below the High_Limit minus
the Deadband before a TO-NORMAL event is generated under these conditions: the Deadband before a TO-NORMAL event is generated under these conditions:
(a) the Present_Value must fall below the High_Limit minus the Deadband (a) the Present_Value must fall below the High_Limit minus the Deadband
for a minimum period of time, specified in the Time_Delay property, and for a minimum period of time, specified in the Time_Delay property, and
(b) the HighLimitEnable flag must be set in the Limit_Enable property, and (b) the HighLimitEnable flag must be set in the Limit_Enable property, and
(c) the TO-NORMAL flag must be set in the Event_Enable property. */ (c) the TO-NORMAL flag must be set in the Event_Enable property. */
if ((PresentVal < CurrentAI->High_Limit - CurrentAI->Deadband) && if ((PresentVal < CurrentAI->High_Limit - CurrentAI->Deadband)
((CurrentAI->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) == EVENT_HIGH_LIMIT_ENABLE) && && ((CurrentAI->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) ==
((CurrentAI->Event_Enable & EVENT_ENABLE_TO_NORMAL) == EVENT_ENABLE_TO_NORMAL)) EVENT_HIGH_LIMIT_ENABLE) &&
{ ((CurrentAI->Event_Enable & EVENT_ENABLE_TO_NORMAL) ==
if(!CurrentAI->Remaining_Time_Delay) EVENT_ENABLE_TO_NORMAL)) {
if (!CurrentAI->Remaining_Time_Delay)
CurrentAI->Event_State = EVENT_STATE_NORMAL; CurrentAI->Event_State = EVENT_STATE_NORMAL;
else else
CurrentAI->Remaining_Time_Delay--; CurrentAI->Remaining_Time_Delay--;
@@ -739,15 +756,16 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance)
/* Once the Present_Value has fallen below the Low_Limit, /* Once the Present_Value has fallen below the Low_Limit,
the Present_Value must exceed the Low_Limit plus the Deadband the Present_Value must exceed the Low_Limit plus the Deadband
before a TO-NORMAL event is generated under these conditions: before a TO-NORMAL event is generated under these conditions:
(a) the Present_Value must exceed the Low_Limit plus the Deadband (a) the Present_Value must exceed the Low_Limit plus the Deadband
for a minimum period of time, specified in the Time_Delay property, and for a minimum period of time, specified in the Time_Delay property, and
(b) the LowLimitEnable flag must be set in the Limit_Enable property, and (b) the LowLimitEnable flag must be set in the Limit_Enable property, and
(c) the TO-NORMAL flag must be set in the Event_Enable property. */ (c) the TO-NORMAL flag must be set in the Event_Enable property. */
if ((PresentVal > CurrentAI->Low_Limit + CurrentAI->Deadband) && if ((PresentVal > CurrentAI->Low_Limit + CurrentAI->Deadband)
((CurrentAI->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) == EVENT_LOW_LIMIT_ENABLE) && && ((CurrentAI->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) ==
((CurrentAI->Event_Enable & EVENT_ENABLE_TO_NORMAL) == EVENT_ENABLE_TO_NORMAL)) EVENT_LOW_LIMIT_ENABLE) &&
{ ((CurrentAI->Event_Enable & EVENT_ENABLE_TO_NORMAL) ==
if(!CurrentAI->Remaining_Time_Delay) EVENT_ENABLE_TO_NORMAL)) {
if (!CurrentAI->Remaining_Time_Delay)
CurrentAI->Event_State = EVENT_STATE_NORMAL; CurrentAI->Event_State = EVENT_STATE_NORMAL;
else else
CurrentAI->Remaining_Time_Delay--; CurrentAI->Remaining_Time_Delay--;
@@ -758,41 +776,36 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance)
break; break;
default: default:
return; /* shouldn't happen */ return; /* shouldn't happen */
} /* switch (FromState) */ } /* switch (FromState) */
ToState = CurrentAI->Event_State; ToState = CurrentAI->Event_State;
if (FromState != ToState) if (FromState != ToState) {
{
/* Event_State has changed. /* Event_State has changed.
Need to fill only the basic parameters of this type of event. Need to fill only the basic parameters of this type of event.
Other parameters will be filled in common function. */ Other parameters will be filled in common function. */
switch (ToState) switch (ToState) {
{
case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_HIGH_LIMIT:
ExceededLimit = CurrentAI->High_Limit; ExceededLimit = CurrentAI->High_Limit;
characterstring_init_ansi(&msgText, characterstring_init_ansi(&msgText, "Goes to high limit");
"Goes to high limit");
break; break;
case EVENT_STATE_LOW_LIMIT: case EVENT_STATE_LOW_LIMIT:
ExceededLimit = CurrentAI->Low_Limit; ExceededLimit = CurrentAI->Low_Limit;
characterstring_init_ansi(&msgText, characterstring_init_ansi(&msgText, "Goes to low limit");
"Goes to low limit");
break; break;
case EVENT_STATE_NORMAL: case EVENT_STATE_NORMAL:
if(FromState == EVENT_STATE_HIGH_LIMIT) { if (FromState == EVENT_STATE_HIGH_LIMIT) {
ExceededLimit = CurrentAI->High_Limit; ExceededLimit = CurrentAI->High_Limit;
characterstring_init_ansi(&msgText, characterstring_init_ansi(&msgText,
"Back to normal state from high limit"); "Back to normal state from high limit");
} } else {
else {
ExceededLimit = CurrentAI->Low_Limit; ExceededLimit = CurrentAI->Low_Limit;
characterstring_init_ansi(&msgText, characterstring_init_ansi(&msgText,
"Back to normal state from low limit"); "Back to normal state from low limit");
} }
break; break;
@@ -803,9 +816,9 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance)
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Event_State for (%s,%d) goes from %s to %s.\n", fprintf(stderr, "Event_State for (%s,%d) goes from %s to %s.\n",
bactext_object_type_name(OBJECT_ANALOG_INPUT), bactext_object_type_name(OBJECT_ANALOG_INPUT), object_instance,
object_instance, bactext_event_state_name(FromState), bactext_event_state_name(FromState),
bactext_event_state_name(ToState)); bactext_event_state_name(ToState));
#endif /* PRINT_ENABLED */ #endif /* PRINT_ENABLED */
/* Notify Type */ /* Notify Type */
@@ -817,8 +830,7 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance)
} }
if (SendNotify) if (SendNotify) {
{
/* Event Object Identifier */ /* Event Object Identifier */
event_data.eventObjectIdentifier.type = OBJECT_ANALOG_INPUT; event_data.eventObjectIdentifier.type = OBJECT_ANALOG_INPUT;
event_data.eventObjectIdentifier.instance = object_instance; event_data.eventObjectIdentifier.instance = object_instance;
@@ -829,22 +841,21 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance)
if (event_data.notifyType != NOTIFY_ACK_NOTIFICATION) { if (event_data.notifyType != NOTIFY_ACK_NOTIFICATION) {
/* fill Event_Time_Stamps */ /* fill Event_Time_Stamps */
switch (ToState) switch (ToState) {
{
case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_HIGH_LIMIT:
case EVENT_STATE_LOW_LIMIT: case EVENT_STATE_LOW_LIMIT:
CurrentAI->Event_Time_Stamps[TRANSITION_TO_OFFNORMAL] = CurrentAI->Event_Time_Stamps[TRANSITION_TO_OFFNORMAL] =
event_data.timeStamp.value.dateTime; event_data.timeStamp.value.dateTime;
break; break;
case EVENT_STATE_FAULT: case EVENT_STATE_FAULT:
CurrentAI->Event_Time_Stamps[TRANSITION_TO_FAULT] = CurrentAI->Event_Time_Stamps[TRANSITION_TO_FAULT] =
event_data.timeStamp.value.dateTime; event_data.timeStamp.value.dateTime;
break; break;
case EVENT_STATE_NORMAL: case EVENT_STATE_NORMAL:
CurrentAI->Event_Time_Stamps[TRANSITION_TO_NORMAL] = CurrentAI->Event_Time_Stamps[TRANSITION_TO_NORMAL] =
event_data.timeStamp.value.dateTime; event_data.timeStamp.value.dateTime;
break; break;
} }
} }
@@ -871,50 +882,57 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance)
/* Event Values */ /* Event Values */
if (event_data.notifyType != NOTIFY_ACK_NOTIFICATION) { if (event_data.notifyType != NOTIFY_ACK_NOTIFICATION) {
/* Value that exceeded a limit. */ /* Value that exceeded a limit. */
event_data.notificationParams.outOfRange.exceedingValue = PresentVal; event_data.notificationParams.outOfRange.exceedingValue =
PresentVal;
/* Status_Flags of the referenced object. */ /* Status_Flags of the referenced object. */
bitstring_init(&event_data.notificationParams.outOfRange.statusFlags); bitstring_init(&event_data.notificationParams.outOfRange.
bitstring_set_bit(&event_data.notificationParams.outOfRange.statusFlags, statusFlags);
STATUS_FLAG_IN_ALARM, CurrentAI->Event_State ? true : false); bitstring_set_bit(&event_data.notificationParams.outOfRange.
bitstring_set_bit(&event_data.notificationParams.outOfRange.statusFlags, statusFlags, STATUS_FLAG_IN_ALARM,
STATUS_FLAG_FAULT, false); CurrentAI->Event_State ? true : false);
bitstring_set_bit(&event_data.notificationParams.outOfRange.statusFlags, bitstring_set_bit(&event_data.notificationParams.outOfRange.
STATUS_FLAG_OVERRIDDEN, false); statusFlags, STATUS_FLAG_FAULT, false);
bitstring_set_bit(&event_data.notificationParams.outOfRange.statusFlags, bitstring_set_bit(&event_data.notificationParams.outOfRange.
STATUS_FLAG_OUT_OF_SERVICE, CurrentAI->Out_Of_Service); statusFlags, STATUS_FLAG_OVERRIDDEN, false);
bitstring_set_bit(&event_data.notificationParams.outOfRange.
statusFlags, STATUS_FLAG_OUT_OF_SERVICE,
CurrentAI->Out_Of_Service);
/* Deadband used for limit checking. */ /* Deadband used for limit checking. */
event_data.notificationParams.outOfRange.deadband = CurrentAI->Deadband; event_data.notificationParams.outOfRange.deadband =
CurrentAI->Deadband;
/* Limit that was exceeded. */ /* Limit that was exceeded. */
event_data.notificationParams.outOfRange.exceededLimit = ExceededLimit; event_data.notificationParams.outOfRange.exceededLimit =
ExceededLimit;
} }
/* add data from notification class */ /* add data from notification class */
Notification_Class_common_reporting_function(&event_data); Notification_Class_common_reporting_function(&event_data);
/* Ack required */ /* Ack required */
if ((event_data.notifyType != NOTIFY_ACK_NOTIFICATION) && if ((event_data.notifyType != NOTIFY_ACK_NOTIFICATION) &&
(event_data.ackRequired == true)) (event_data.ackRequired == true)) {
{ switch (event_data.toState) {
switch (event_data.toState)
{
case EVENT_STATE_OFFNORMAL: case EVENT_STATE_OFFNORMAL:
case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_HIGH_LIMIT:
case EVENT_STATE_LOW_LIMIT: case EVENT_STATE_LOW_LIMIT:
CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked = false; CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL].Time_Stamp = bIsAcked = false;
event_data.timeStamp.value.dateTime; CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
Time_Stamp = event_data.timeStamp.value.dateTime;
break; break;
case EVENT_STATE_FAULT: case EVENT_STATE_FAULT:
CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked = false; CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT].
CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT].Time_Stamp = bIsAcked = false;
event_data.timeStamp.value.dateTime; CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT].
Time_Stamp = event_data.timeStamp.value.dateTime;
break; break;
case EVENT_STATE_NORMAL: case EVENT_STATE_NORMAL:
CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked = false; CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL].
CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL].Time_Stamp = bIsAcked = false;
event_data.timeStamp.value.dateTime; CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL].
Time_Stamp = event_data.timeStamp.value.dateTime;
break; break;
} }
} }
@@ -924,12 +942,13 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance)
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
int Analog_Input_Event_Information(unsigned index, int Analog_Input_Event_Information(
BACNET_GET_EVENT_INFORMATION_DATA * getevent_data) unsigned index,
BACNET_GET_EVENT_INFORMATION_DATA * getevent_data)
{ {
bool IsNotAckedTransitions; bool IsNotAckedTransitions;
bool IsActiveEvent; bool IsActiveEvent;
int i; int i;
/* check index */ /* check index */
@@ -939,63 +958,75 @@ int Analog_Input_Event_Information(unsigned index,
/* Acked_Transitions property, which has at least one of the bits /* Acked_Transitions property, which has at least one of the bits
(TO-OFFNORMAL, TO-FAULT, TONORMAL) set to FALSE. */ (TO-OFFNORMAL, TO-FAULT, TONORMAL) set to FALSE. */
IsNotAckedTransitions = (AI_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked == false) | IsNotAckedTransitions =
(AI_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked == false) | (AI_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL].
(AI_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked == false); bIsAcked ==
} false) | (AI_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT].
else bIsAcked ==
return -1; /* end of list */ false) | (AI_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL].
bIsAcked == false);
} else
return -1; /* end of list */
if ((IsActiveEvent) || (IsNotAckedTransitions)) { if ((IsActiveEvent) || (IsNotAckedTransitions)) {
/* Object Identifier */ /* Object Identifier */
getevent_data->objectIdentifier.type = OBJECT_ANALOG_INPUT; getevent_data->objectIdentifier.type = OBJECT_ANALOG_INPUT;
getevent_data->objectIdentifier.instance = Analog_Input_Index_To_Instance(index); getevent_data->objectIdentifier.instance =
Analog_Input_Index_To_Instance(index);
/* Event State */ /* Event State */
getevent_data->eventState = AI_Descr[index].Event_State; getevent_data->eventState = AI_Descr[index].Event_State;
/* Acknowledged Transitions */ /* Acknowledged Transitions */
bitstring_init(&getevent_data->acknowledgedTransitions); bitstring_init(&getevent_data->acknowledgedTransitions);
bitstring_set_bit(&getevent_data->acknowledgedTransitions, TRANSITION_TO_OFFNORMAL, bitstring_set_bit(&getevent_data->acknowledgedTransitions,
AI_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked); TRANSITION_TO_OFFNORMAL,
bitstring_set_bit(&getevent_data->acknowledgedTransitions, TRANSITION_TO_FAULT, AI_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL].
AI_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked); bIsAcked);
bitstring_set_bit(&getevent_data->acknowledgedTransitions, TRANSITION_TO_NORMAL, bitstring_set_bit(&getevent_data->acknowledgedTransitions,
AI_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked); TRANSITION_TO_FAULT,
AI_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked);
bitstring_set_bit(&getevent_data->acknowledgedTransitions,
TRANSITION_TO_NORMAL,
AI_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked);
/* Event Time Stamps */ /* Event Time Stamps */
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
getevent_data->eventTimeStamps[i].tag = TIME_STAMP_DATETIME; getevent_data->eventTimeStamps[i].tag = TIME_STAMP_DATETIME;
getevent_data->eventTimeStamps[i].value.dateTime = getevent_data->eventTimeStamps[i].value.dateTime =
AI_Descr[index].Event_Time_Stamps[i]; AI_Descr[index].Event_Time_Stamps[i];
} }
/* Notify Type */ /* Notify Type */
getevent_data->notifyType = AI_Descr[index].Notify_Type; getevent_data->notifyType = AI_Descr[index].Notify_Type;
/* Event Enable */ /* Event Enable */
bitstring_init(&getevent_data->eventEnable); bitstring_init(&getevent_data->eventEnable);
bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_OFFNORMAL, bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_OFFNORMAL,
(AI_Descr[index].Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true : false ); (AI_Descr[index].
Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true : false);
bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_FAULT, bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_FAULT,
(AI_Descr[index].Event_Enable & EVENT_ENABLE_TO_FAULT ) ? true : false ); (AI_Descr[index].
Event_Enable & EVENT_ENABLE_TO_FAULT) ? true : false);
bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_NORMAL, bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_NORMAL,
(AI_Descr[index].Event_Enable & EVENT_ENABLE_TO_NORMAL ) ? true : false ); (AI_Descr[index].
Event_Enable & EVENT_ENABLE_TO_NORMAL) ? true : false);
/* Event Priorities */ /* Event Priorities */
Notification_Class_Get_Priorities(AI_Descr[index].Notification_Class, Notification_Class_Get_Priorities(AI_Descr[index].Notification_Class,
getevent_data->eventPriorities); getevent_data->eventPriorities);
return 1; /* active event */ return 1; /* active event */
} } else
else return 0; /* no active event at this index */
return 0; /* no active event at this index */
} }
int Analog_Input_Alarm_Ack(BACNET_ALARM_ACK_DATA * alarmack_data, int Analog_Input_Alarm_Ack(
BACNET_ERROR_CODE * error_code) BACNET_ALARM_ACK_DATA * alarmack_data,
BACNET_ERROR_CODE * error_code)
{ {
ANALOG_INPUT_DESCR *CurrentAI; ANALOG_INPUT_DESCR *CurrentAI;
unsigned int object_index; unsigned int object_index;
object_index = Analog_Input_Instance_To_Index( object_index =
alarmack_data->eventObjectIdentifier.instance); Analog_Input_Instance_To_Index(alarmack_data->eventObjectIdentifier.
instance);
if (object_index < MAX_ANALOG_INPUTS) if (object_index < MAX_ANALOG_INPUTS)
CurrentAI = &AI_Descr[object_index]; CurrentAI = &AI_Descr[object_index];
@@ -1004,71 +1035,73 @@ int Analog_Input_Alarm_Ack(BACNET_ALARM_ACK_DATA * alarmack_data,
return -1; return -1;
} }
switch (alarmack_data->eventStateAcked) switch (alarmack_data->eventStateAcked) {
{
case EVENT_STATE_OFFNORMAL: case EVENT_STATE_OFFNORMAL:
case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_HIGH_LIMIT:
case EVENT_STATE_LOW_LIMIT: case EVENT_STATE_LOW_LIMIT:
if(CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked == false) { if (CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
if(alarmack_data->eventTimeStamp.tag != TIME_STAMP_DATETIME){ bIsAcked == false) {
if (alarmack_data->eventTimeStamp.tag != TIME_STAMP_DATETIME) {
*error_code = ERROR_CODE_INVALID_TIME_STAMP; *error_code = ERROR_CODE_INVALID_TIME_STAMP;
return -1; return -1;
} }
if(datetime_compare(&CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL].Time_Stamp, if (datetime_compare(&CurrentAI->
&alarmack_data->eventTimeStamp.value.dateTime) > 0) Acked_Transitions[TRANSITION_TO_OFFNORMAL].Time_Stamp,
{ &alarmack_data->eventTimeStamp.value.dateTime) > 0) {
*error_code = ERROR_CODE_INVALID_TIME_STAMP; *error_code = ERROR_CODE_INVALID_TIME_STAMP;
return -1; return -1;
} }
/* FIXME: Send ack notification */ /* FIXME: Send ack notification */
CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked = true; CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
} bIsAcked = true;
else { } else {
*error_code = ERROR_CODE_INVALID_EVENT_STATE; *error_code = ERROR_CODE_INVALID_EVENT_STATE;
return -1; return -1;
} }
break; break;
case EVENT_STATE_FAULT: case EVENT_STATE_FAULT:
if(CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked == false) { if (CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked ==
if(alarmack_data->eventTimeStamp.tag != TIME_STAMP_DATETIME){ false) {
if (alarmack_data->eventTimeStamp.tag != TIME_STAMP_DATETIME) {
*error_code = ERROR_CODE_INVALID_TIME_STAMP; *error_code = ERROR_CODE_INVALID_TIME_STAMP;
return -1; return -1;
} }
if(datetime_compare(&CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL].Time_Stamp, if (datetime_compare(&CurrentAI->
&alarmack_data->eventTimeStamp.value.dateTime) > 0) Acked_Transitions[TRANSITION_TO_NORMAL].Time_Stamp,
{ &alarmack_data->eventTimeStamp.value.dateTime) > 0) {
*error_code = ERROR_CODE_INVALID_TIME_STAMP; *error_code = ERROR_CODE_INVALID_TIME_STAMP;
return -1; return -1;
} }
/* FIXME: Send ack notification */ /* FIXME: Send ack notification */
CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked = true; CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked =
} true;
else { } else {
*error_code = ERROR_CODE_INVALID_EVENT_STATE; *error_code = ERROR_CODE_INVALID_EVENT_STATE;
return -1; return -1;
} }
break; break;
case EVENT_STATE_NORMAL: case EVENT_STATE_NORMAL:
if(CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked == false) { if (CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked ==
if(alarmack_data->eventTimeStamp.tag != TIME_STAMP_DATETIME){ false) {
if (alarmack_data->eventTimeStamp.tag != TIME_STAMP_DATETIME) {
*error_code = ERROR_CODE_INVALID_TIME_STAMP; *error_code = ERROR_CODE_INVALID_TIME_STAMP;
return -1; return -1;
} }
if(datetime_compare(&CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT].Time_Stamp, if (datetime_compare(&CurrentAI->
&alarmack_data->eventTimeStamp.value.dateTime) > 0) Acked_Transitions[TRANSITION_TO_FAULT].Time_Stamp,
{ &alarmack_data->eventTimeStamp.value.dateTime) > 0) {
*error_code = ERROR_CODE_INVALID_TIME_STAMP; *error_code = ERROR_CODE_INVALID_TIME_STAMP;
return -1; return -1;
} }
/* FIXME: Send ack notification */ /* FIXME: Send ack notification */
CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked = true; CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked =
} true;
else { } else {
*error_code = ERROR_CODE_INVALID_EVENT_STATE; *error_code = ERROR_CODE_INVALID_EVENT_STATE;
return -1; return -1;
} }
+18 -15
View File
@@ -42,20 +42,20 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
typedef struct analog_input_descr { typedef struct analog_input_descr {
uint8_t Event_State : 3; uint8_t Event_State:3;
float Present_Value; float Present_Value;
BACNET_RELIABILITY Reliability; BACNET_RELIABILITY Reliability;
bool Out_Of_Service; bool Out_Of_Service;
uint8_t Units; uint8_t Units;
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
uint32_t Time_Delay; uint32_t Time_Delay;
uint32_t Notification_Class; uint32_t Notification_Class;
float High_Limit; float High_Limit;
float Low_Limit; float Low_Limit;
float Deadband; float Deadband;
uint8_t Limit_Enable : 2; uint8_t Limit_Enable:2;
uint8_t Event_Enable : 3; uint8_t Event_Enable:3;
uint8_t Notify_Type : 1; uint8_t Notify_Type:1;
ACKED_INFO Acked_Transitions[MAX_BACNET_EVENT_TRANSITION]; ACKED_INFO Acked_Transitions[MAX_BACNET_EVENT_TRANSITION];
BACNET_DATE_TIME Event_Time_Stamps[MAX_BACNET_EVENT_TRANSITION]; BACNET_DATE_TIME Event_Time_Stamps[MAX_BACNET_EVENT_TRANSITION];
/* time to generate event notification */ /* time to generate event notification */
@@ -83,7 +83,7 @@ extern "C" {
bool Analog_Input_Object_Name( bool Analog_Input_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name); BACNET_CHARACTER_STRING * object_name);
bool Analog_Input_Name_Set( bool Analog_Input_Name_Set(
uint32_t object_instance, uint32_t object_instance,
char *new_name); char *new_name);
@@ -112,14 +112,17 @@ extern "C" {
float value); float value);
/* note: header of Intrinsic_Reporting function is required /* note: header of Intrinsic_Reporting function is required
even when INTRINSIC_REPORTING is not defined */ even when INTRINSIC_REPORTING is not defined */
void Analog_Input_Intrinsic_Reporting(uint32_t object_instance); void Analog_Input_Intrinsic_Reporting(
uint32_t object_instance);
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
int Analog_Input_Event_Information(unsigned index, int Analog_Input_Event_Information(
unsigned index,
BACNET_GET_EVENT_INFORMATION_DATA * getevent_data); BACNET_GET_EVENT_INFORMATION_DATA * getevent_data);
int Analog_Input_Alarm_Ack(BACNET_ALARM_ACK_DATA * alarmack_data, int Analog_Input_Alarm_Ack(
BACNET_ALARM_ACK_DATA * alarmack_data,
BACNET_ERROR_CODE * error_code); BACNET_ERROR_CODE * error_code);
#endif #endif
+9 -9
View File
@@ -255,7 +255,7 @@ bool Analog_Output_Present_Value_Relinquish(
/* note: the object name must be unique within this device */ /* note: the object name must be unique within this device */
bool Analog_Output_Object_Name( bool Analog_Output_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name) BACNET_CHARACTER_STRING * object_name)
{ {
static char text_string[32] = ""; /* okay for single thread */ static char text_string[32] = ""; /* okay for single thread */
bool status = false; bool status = false;
@@ -447,11 +447,11 @@ bool Analog_Output_Write_Property(
if (status) { if (status) {
level = AO_LEVEL_NULL; level = AO_LEVEL_NULL;
object_index = object_index =
Analog_Output_Instance_To_Index(wp_data-> Analog_Output_Instance_To_Index
object_instance); (wp_data->object_instance);
status = status =
Analog_Output_Present_Value_Relinquish(wp_data-> Analog_Output_Present_Value_Relinquish
object_instance, wp_data->priority); (wp_data->object_instance, wp_data->priority);
if (!status) { if (!status) {
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
@@ -491,10 +491,10 @@ bool WPValidateArgType(
BACNET_ERROR_CLASS * pErrorClass, BACNET_ERROR_CLASS * pErrorClass,
BACNET_ERROR_CODE * pErrorCode) BACNET_ERROR_CODE * pErrorCode)
{ {
pValue=pValue; pValue = pValue;
ucExpectedTag=ucExpectedTag; ucExpectedTag = ucExpectedTag;
pErrorClass=pErrorClass; pErrorClass = pErrorClass;
pErrorCode=pErrorCode; pErrorCode = pErrorCode;
return false; return false;
} }
+1 -1
View File
@@ -65,7 +65,7 @@ extern "C" {
bool Analog_Output_Object_Name( bool Analog_Output_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name); BACNET_CHARACTER_STRING * object_name);
bool Analog_Output_Name_Set( bool Analog_Output_Name_Set(
uint32_t object_instance, uint32_t object_instance,
char *new_name); char *new_name);
+261 -232
View File
@@ -133,8 +133,7 @@ void Analog_Value_Init(
handler_get_event_information_set(OBJECT_ANALOG_VALUE, handler_get_event_information_set(OBJECT_ANALOG_VALUE,
Analog_Value_Event_Information); Analog_Value_Event_Information);
/* Set handler for AcknowledgeAlarm function */ /* Set handler for AcknowledgeAlarm function */
handler_alarm_ack_set(OBJECT_ANALOG_VALUE, handler_alarm_ack_set(OBJECT_ANALOG_VALUE, Analog_Value_Alarm_Ack);
Analog_Value_Alarm_Ack);
#endif #endif
} }
} }
@@ -196,8 +195,7 @@ bool Analog_Value_Present_Value_Set(
CurrentAV = &AV_Descr[index]; CurrentAV = &AV_Descr[index];
if (priority && (priority <= BACNET_MAX_PRIORITY) && if (priority && (priority <= BACNET_MAX_PRIORITY) &&
(priority != 6 /* reserved */ ) && (priority != 6 /* reserved */ ) &&
(value >= 0.0) && (value <= 100.0)) (value >= 0.0) && (value <= 100.0)) {
{
CurrentAV->Priority_Array[priority - 1] = (uint8_t) value; CurrentAV->Priority_Array[priority - 1] = (uint8_t) value;
/* Note: you could set the physical output here to the next /* Note: you could set the physical output here to the next
highest priority, or to the relinquish default if no highest priority, or to the relinquish default if no
@@ -240,7 +238,7 @@ float Analog_Value_Present_Value(
/* note: the object name must be unique within this device */ /* note: the object name must be unique within this device */
bool Analog_Value_Object_Name( bool Analog_Value_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name) BACNET_CHARACTER_STRING * object_name)
{ {
static char text_string[32] = ""; /* okay for single thread */ static char text_string[32] = ""; /* okay for single thread */
bool status = false; bool status = false;
@@ -310,24 +308,26 @@ int Analog_Value_Read_Property(
bitstring_init(&bit_string); bitstring_init(&bit_string);
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM, bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM,
CurrentAV->Event_State ? true : false); CurrentAV->Event_State ? true : false);
#else #else
bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM, false); bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM, false);
#endif #endif
bitstring_set_bit(&bit_string, STATUS_FLAG_FAULT, false); bitstring_set_bit(&bit_string, STATUS_FLAG_FAULT, false);
bitstring_set_bit(&bit_string, STATUS_FLAG_OVERRIDDEN, false); bitstring_set_bit(&bit_string, STATUS_FLAG_OVERRIDDEN, false);
bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE, CurrentAV->Out_Of_Service); bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE,
CurrentAV->Out_Of_Service);
apdu_len = encode_application_bitstring(&apdu[0], &bit_string); apdu_len = encode_application_bitstring(&apdu[0], &bit_string);
break; break;
case PROP_EVENT_STATE: case PROP_EVENT_STATE:
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
apdu_len = encode_application_enumerated(&apdu[0], apdu_len =
CurrentAV->Event_State); encode_application_enumerated(&apdu[0],
CurrentAV->Event_State);
#else #else
apdu_len = encode_application_enumerated(&apdu[0], apdu_len =
EVENT_STATE_NORMAL); encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL);
#endif #endif
break; break;
@@ -337,7 +337,8 @@ int Analog_Value_Read_Property(
break; break;
case PROP_UNITS: case PROP_UNITS:
apdu_len = encode_application_enumerated(&apdu[0], CurrentAV->Units); apdu_len =
encode_application_enumerated(&apdu[0], CurrentAV->Units);
break; break;
case PROP_PRIORITY_ARRAY: case PROP_PRIORITY_ARRAY:
@@ -363,7 +364,7 @@ int Analog_Value_Read_Property(
apdu_len += len; apdu_len += len;
else { else {
rpdata->error_class = ERROR_CLASS_SERVICES; rpdata->error_class = ERROR_CLASS_SERVICES;
rpdata->error_code = ERROR_CODE_NO_SPACE_FOR_OBJECT; rpdata->error_code = ERROR_CODE_NO_SPACE_FOR_OBJECT;
apdu_len = BACNET_STATUS_ERROR; apdu_len = BACNET_STATUS_ERROR;
break; break;
} }
@@ -371,11 +372,11 @@ int Analog_Value_Read_Property(
} else { } else {
if (rpdata->array_index <= BACNET_MAX_PRIORITY) { if (rpdata->array_index <= BACNET_MAX_PRIORITY) {
if (CurrentAV->Priority_Array[rpdata->array_index - 1] if (CurrentAV->Priority_Array[rpdata->array_index - 1]
== ANALOG_LEVEL_NULL) == ANALOG_LEVEL_NULL)
apdu_len = encode_application_null(&apdu[0]); apdu_len = encode_application_null(&apdu[0]);
else { else {
real_value = CurrentAV->Priority_Array real_value =
[rpdata->array_index - 1]; CurrentAV->Priority_Array[rpdata->array_index - 1];
apdu_len = apdu_len =
encode_application_real(&apdu[0], real_value); encode_application_real(&apdu[0], real_value);
} }
@@ -394,15 +395,19 @@ int Analog_Value_Read_Property(
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
case PROP_TIME_DELAY: case PROP_TIME_DELAY:
apdu_len = encode_application_unsigned(&apdu[0], CurrentAV->Time_Delay); apdu_len =
encode_application_unsigned(&apdu[0], CurrentAV->Time_Delay);
break; break;
case PROP_NOTIFICATION_CLASS: case PROP_NOTIFICATION_CLASS:
apdu_len = encode_application_unsigned(&apdu[0], CurrentAV->Notification_Class); apdu_len =
encode_application_unsigned(&apdu[0],
CurrentAV->Notification_Class);
break; break;
case PROP_HIGH_LIMIT: case PROP_HIGH_LIMIT:
apdu_len = encode_application_real(&apdu[0], CurrentAV->High_Limit); apdu_len =
encode_application_real(&apdu[0], CurrentAV->High_Limit);
break; break;
case PROP_LOW_LIMIT: case PROP_LOW_LIMIT:
@@ -416,21 +421,26 @@ int Analog_Value_Read_Property(
case PROP_LIMIT_ENABLE: case PROP_LIMIT_ENABLE:
bitstring_init(&bit_string); bitstring_init(&bit_string);
bitstring_set_bit(&bit_string, 0, bitstring_set_bit(&bit_string, 0,
(CurrentAV->Limit_Enable & EVENT_LOW_LIMIT_ENABLE ) ? true : false ); (CurrentAV->
Limit_Enable & EVENT_LOW_LIMIT_ENABLE) ? true : false);
bitstring_set_bit(&bit_string, 1, bitstring_set_bit(&bit_string, 1,
(CurrentAV->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) ? true : false ); (CurrentAV->
Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) ? true : false);
apdu_len = encode_application_bitstring(&apdu[0],&bit_string); apdu_len = encode_application_bitstring(&apdu[0], &bit_string);
break; break;
case PROP_EVENT_ENABLE: case PROP_EVENT_ENABLE:
bitstring_init(&bit_string); bitstring_init(&bit_string);
bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL, bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL,
(CurrentAV->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true : false ); (CurrentAV->
Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true : false);
bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT, bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT,
(CurrentAV->Event_Enable & EVENT_ENABLE_TO_FAULT ) ? true : false ); (CurrentAV->
Event_Enable & EVENT_ENABLE_TO_FAULT) ? true : false);
bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL, bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL,
(CurrentAV->Event_Enable & EVENT_ENABLE_TO_NORMAL ) ? true : false ); (CurrentAV->
Event_Enable & EVENT_ENABLE_TO_NORMAL) ? true : false);
apdu_len = encode_application_bitstring(&apdu[0], &bit_string); apdu_len = encode_application_bitstring(&apdu[0], &bit_string);
break; break;
@@ -438,62 +448,69 @@ int Analog_Value_Read_Property(
case PROP_ACKED_TRANSITIONS: case PROP_ACKED_TRANSITIONS:
bitstring_init(&bit_string); bitstring_init(&bit_string);
bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL, bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL,
CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked); CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
bIsAcked);
bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT, bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT,
CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked); CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked);
bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL, bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL,
CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked); CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked);
apdu_len = encode_application_bitstring(&apdu[0], &bit_string); apdu_len = encode_application_bitstring(&apdu[0], &bit_string);
break; break;
case PROP_NOTIFY_TYPE: case PROP_NOTIFY_TYPE:
apdu_len = encode_application_enumerated(&apdu[0], apdu_len =
CurrentAV->Notify_Type ? NOTIFY_EVENT : NOTIFY_ALARM); encode_application_enumerated(&apdu[0],
CurrentAV->Notify_Type ? NOTIFY_EVENT : NOTIFY_ALARM);
break; break;
case PROP_EVENT_TIME_STAMPS: case PROP_EVENT_TIME_STAMPS:
/* Array element zero is the number of elements in the array */ /* Array element zero is the number of elements in the array */
if (rpdata->array_index == 0) if (rpdata->array_index == 0)
apdu_len = encode_application_unsigned(&apdu[0], apdu_len =
MAX_BACNET_EVENT_TRANSITION); encode_application_unsigned(&apdu[0],
MAX_BACNET_EVENT_TRANSITION);
/* if no index was specified, then try to encode the entire list */ /* if no index was specified, then try to encode the entire list */
/* into one packet. */ /* into one packet. */
else if (rpdata->array_index == BACNET_ARRAY_ALL) { else if (rpdata->array_index == BACNET_ARRAY_ALL) {
for (i = 0; i < MAX_BACNET_EVENT_TRANSITION; i++) {; for (i = 0; i < MAX_BACNET_EVENT_TRANSITION; i++) {;
len = encode_opening_tag(&apdu[apdu_len], len =
TIME_STAMP_DATETIME); encode_opening_tag(&apdu[apdu_len],
len += encode_application_date(&apdu[apdu_len + len], TIME_STAMP_DATETIME);
&CurrentAV->Event_Time_Stamps[i].date); len +=
len += encode_application_time(&apdu[apdu_len + len], encode_application_date(&apdu[apdu_len + len],
&CurrentAV->Event_Time_Stamps[i].time); &CurrentAV->Event_Time_Stamps[i].date);
len += encode_closing_tag(&apdu[apdu_len + len], len +=
TIME_STAMP_DATETIME); encode_application_time(&apdu[apdu_len + len],
&CurrentAV->Event_Time_Stamps[i].time);
len +=
encode_closing_tag(&apdu[apdu_len + len],
TIME_STAMP_DATETIME);
/* add it if we have room */ /* add it if we have room */
if ((apdu_len + len) < MAX_APDU) if ((apdu_len + len) < MAX_APDU)
apdu_len += len; apdu_len += len;
else { else {
rpdata->error_class = ERROR_CLASS_SERVICES; rpdata->error_class = ERROR_CLASS_SERVICES;
rpdata->error_code = ERROR_CODE_NO_SPACE_FOR_OBJECT; rpdata->error_code = ERROR_CODE_NO_SPACE_FOR_OBJECT;
apdu_len = BACNET_STATUS_ERROR; apdu_len = BACNET_STATUS_ERROR;
break; break;
} }
} }
} } else if (rpdata->array_index <= MAX_BACNET_EVENT_TRANSITION) {
else if (rpdata->array_index <= MAX_BACNET_EVENT_TRANSITION) { apdu_len =
apdu_len = encode_opening_tag(&apdu[apdu_len], encode_opening_tag(&apdu[apdu_len], TIME_STAMP_DATETIME);
TIME_STAMP_DATETIME); apdu_len +=
apdu_len += encode_application_date(&apdu[apdu_len], encode_application_date(&apdu[apdu_len],
&CurrentAV->Event_Time_Stamps[rpdata->array_index].date); &CurrentAV->Event_Time_Stamps[rpdata->array_index].date);
apdu_len += encode_application_time(&apdu[apdu_len], apdu_len +=
&CurrentAV->Event_Time_Stamps[rpdata->array_index].time); encode_application_time(&apdu[apdu_len],
apdu_len += encode_closing_tag(&apdu[apdu_len], &CurrentAV->Event_Time_Stamps[rpdata->array_index].time);
TIME_STAMP_DATETIME); apdu_len +=
} encode_closing_tag(&apdu[apdu_len], TIME_STAMP_DATETIME);
else { } else {
rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_class = ERROR_CLASS_PROPERTY;
rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX;
apdu_len = BACNET_STATUS_ERROR; apdu_len = BACNET_STATUS_ERROR;
} }
break; break;
@@ -501,17 +518,16 @@ int Analog_Value_Read_Property(
default: default:
rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_class = ERROR_CLASS_PROPERTY;
rpdata->error_code = ERROR_CODE_UNKNOWN_PROPERTY; rpdata->error_code = ERROR_CODE_UNKNOWN_PROPERTY;
apdu_len = BACNET_STATUS_ERROR; apdu_len = BACNET_STATUS_ERROR;
break; break;
} }
/* only array properties can have array options */ /* only array properties can have array options */
if ((apdu_len >= 0) && if ((apdu_len >= 0) && (rpdata->object_property != PROP_PRIORITY_ARRAY) &&
(rpdata->object_property != PROP_PRIORITY_ARRAY) &&
(rpdata->object_property != PROP_EVENT_TIME_STAMPS) && (rpdata->object_property != PROP_EVENT_TIME_STAMPS) &&
(rpdata->array_index != BACNET_ARRAY_ALL)) { (rpdata->array_index != BACNET_ARRAY_ALL)) {
rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_class = ERROR_CLASS_PROPERTY;
rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
apdu_len = BACNET_STATUS_ERROR; apdu_len = BACNET_STATUS_ERROR;
} }
@@ -677,13 +693,12 @@ bool Analog_Value_Write_Property(
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
if(value.type.Bit_String.bits_used == 2) { if (value.type.Bit_String.bits_used == 2) {
CurrentAV->Limit_Enable = value.type.Bit_String.value[0]; CurrentAV->Limit_Enable = value.type.Bit_String.value[0];
} } else {
else { wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; status = false;
status = false;
} }
} }
break; break;
@@ -694,13 +709,12 @@ bool Analog_Value_Write_Property(
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
if(value.type.Bit_String.bits_used == 3) { if (value.type.Bit_String.bits_used == 3) {
CurrentAV->Event_Enable = value.type.Bit_String.value[0]; CurrentAV->Event_Enable = value.type.Bit_String.value[0];
} } else {
else { wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; status = false;
status = false;
} }
} }
break; break;
@@ -711,13 +725,12 @@ bool Analog_Value_Write_Property(
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
if(value.type.Bit_String.bits_used > NOTIFY_EVENT) { if (value.type.Bit_String.bits_used > NOTIFY_EVENT) {
CurrentAV->Event_Enable = value.type.Enumerated; CurrentAV->Event_Enable = value.type.Enumerated;
} } else {
else { wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; status = false;
status = false;
} }
} }
break; break;
@@ -725,7 +738,7 @@ bool Analog_Value_Write_Property(
default: default:
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
break; break;
} }
@@ -733,7 +746,8 @@ bool Analog_Value_Write_Property(
} }
void Analog_Value_Intrinsic_Reporting(uint32_t object_instance) void Analog_Value_Intrinsic_Reporting(
uint32_t object_instance)
{ {
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
BACNET_EVENT_NOTIFICATION_DATA event_data; BACNET_EVENT_NOTIFICATION_DATA event_data;
@@ -744,7 +758,7 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
uint8_t ToState; uint8_t ToState;
float ExceededLimit = 0.0f; float ExceededLimit = 0.0f;
float PresentVal = 0.0f; float PresentVal = 0.0f;
bool SendNotify = false; bool SendNotify = false;
object_index = Analog_Value_Instance_To_Index(object_instance); object_index = Analog_Value_Instance_To_Index(object_instance);
@@ -755,7 +769,7 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
/* check limits */ /* check limits */
if (!CurrentAV->Limit_Enable) if (!CurrentAV->Limit_Enable)
return; /* limits are not configured */ return; /* limits are not configured */
if (CurrentAV->Ack_notify_data.bSendAckNotify) { if (CurrentAV->Ack_notify_data.bSendAckNotify) {
@@ -766,8 +780,7 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Send Acknotification for (%s,%d).\n", fprintf(stderr, "Send Acknotification for (%s,%d).\n",
bactext_object_type_name(OBJECT_ANALOG_VALUE), bactext_object_type_name(OBJECT_ANALOG_VALUE), object_instance);
object_instance);
#endif /* PRINT_ENABLED */ #endif /* PRINT_ENABLED */
characterstring_init_ansi(&msgText, "AckNotification"); characterstring_init_ansi(&msgText, "AckNotification");
@@ -777,25 +790,23 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
/* Send EventNotification. */ /* Send EventNotification. */
SendNotify = true; SendNotify = true;
} } else {
else
{
/* actual Present_Value */ /* actual Present_Value */
PresentVal = Analog_Value_Present_Value(object_instance); PresentVal = Analog_Value_Present_Value(object_instance);
FromState = CurrentAV->Event_State; FromState = CurrentAV->Event_State;
switch (CurrentAV->Event_State) switch (CurrentAV->Event_State) {
{
case EVENT_STATE_NORMAL: case EVENT_STATE_NORMAL:
/* A TO-OFFNORMAL event is generated under these conditions: /* A TO-OFFNORMAL event is generated under these conditions:
(a) the Present_Value must exceed the High_Limit for a minimum (a) the Present_Value must exceed the High_Limit for a minimum
period of time, specified in the Time_Delay property, and period of time, specified in the Time_Delay property, and
(b) the HighLimitEnable flag must be set in the Limit_Enable property, and (b) the HighLimitEnable flag must be set in the Limit_Enable property, and
(c) the TO-OFFNORMAL flag must be set in the Event_Enable property. */ (c) the TO-OFFNORMAL flag must be set in the Event_Enable property. */
if ((PresentVal > CurrentAV->High_Limit) && if ((PresentVal > CurrentAV->High_Limit) &&
((CurrentAV->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) == EVENT_HIGH_LIMIT_ENABLE) && ((CurrentAV->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) ==
((CurrentAV->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) == EVENT_ENABLE_TO_OFFNORMAL)) EVENT_HIGH_LIMIT_ENABLE) &&
{ ((CurrentAV->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ==
if(!CurrentAV->Remaining_Time_Delay) EVENT_ENABLE_TO_OFFNORMAL)) {
if (!CurrentAV->Remaining_Time_Delay)
CurrentAV->Event_State = EVENT_STATE_HIGH_LIMIT; CurrentAV->Event_State = EVENT_STATE_HIGH_LIMIT;
else else
CurrentAV->Remaining_Time_Delay--; CurrentAV->Remaining_Time_Delay--;
@@ -803,15 +814,16 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
} }
/* A TO-OFFNORMAL event is generated under these conditions: /* A TO-OFFNORMAL event is generated under these conditions:
(a) the Present_Value must exceed the Low_Limit plus the Deadband (a) the Present_Value must exceed the Low_Limit plus the Deadband
for a minimum period of time, specified in the Time_Delay property, and for a minimum period of time, specified in the Time_Delay property, and
(b) the LowLimitEnable flag must be set in the Limit_Enable property, and (b) the LowLimitEnable flag must be set in the Limit_Enable property, and
(c) the TO-NORMAL flag must be set in the Event_Enable property. */ (c) the TO-NORMAL flag must be set in the Event_Enable property. */
if ((PresentVal < CurrentAV->Low_Limit) && if ((PresentVal < CurrentAV->Low_Limit) &&
((CurrentAV->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) == EVENT_LOW_LIMIT_ENABLE) && ((CurrentAV->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) ==
((CurrentAV->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) == EVENT_ENABLE_TO_OFFNORMAL)) EVENT_LOW_LIMIT_ENABLE) &&
{ ((CurrentAV->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ==
if(!CurrentAV->Remaining_Time_Delay) EVENT_ENABLE_TO_OFFNORMAL)) {
if (!CurrentAV->Remaining_Time_Delay)
CurrentAV->Event_State = EVENT_STATE_LOW_LIMIT; CurrentAV->Event_State = EVENT_STATE_LOW_LIMIT;
else else
CurrentAV->Remaining_Time_Delay--; CurrentAV->Remaining_Time_Delay--;
@@ -824,15 +836,16 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_HIGH_LIMIT:
/* Once exceeded, the Present_Value must fall below the High_Limit minus /* Once exceeded, the Present_Value must fall below the High_Limit minus
the Deadband before a TO-NORMAL event is generated under these conditions: the Deadband before a TO-NORMAL event is generated under these conditions:
(a) the Present_Value must fall below the High_Limit minus the Deadband (a) the Present_Value must fall below the High_Limit minus the Deadband
for a minimum period of time, specified in the Time_Delay property, and for a minimum period of time, specified in the Time_Delay property, and
(b) the HighLimitEnable flag must be set in the Limit_Enable property, and (b) the HighLimitEnable flag must be set in the Limit_Enable property, and
(c) the TO-NORMAL flag must be set in the Event_Enable property. */ (c) the TO-NORMAL flag must be set in the Event_Enable property. */
if ((PresentVal < CurrentAV->High_Limit - CurrentAV->Deadband) && if ((PresentVal < CurrentAV->High_Limit - CurrentAV->Deadband)
((CurrentAV->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) == EVENT_HIGH_LIMIT_ENABLE) && && ((CurrentAV->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) ==
((CurrentAV->Event_Enable & EVENT_ENABLE_TO_NORMAL) == EVENT_ENABLE_TO_NORMAL)) EVENT_HIGH_LIMIT_ENABLE) &&
{ ((CurrentAV->Event_Enable & EVENT_ENABLE_TO_NORMAL) ==
if(!CurrentAV->Remaining_Time_Delay) EVENT_ENABLE_TO_NORMAL)) {
if (!CurrentAV->Remaining_Time_Delay)
CurrentAV->Event_State = EVENT_STATE_NORMAL; CurrentAV->Event_State = EVENT_STATE_NORMAL;
else else
CurrentAV->Remaining_Time_Delay--; CurrentAV->Remaining_Time_Delay--;
@@ -846,15 +859,16 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
/* Once the Present_Value has fallen below the Low_Limit, /* Once the Present_Value has fallen below the Low_Limit,
the Present_Value must exceed the Low_Limit plus the Deadband the Present_Value must exceed the Low_Limit plus the Deadband
before a TO-NORMAL event is generated under these conditions: before a TO-NORMAL event is generated under these conditions:
(a) the Present_Value must exceed the Low_Limit plus the Deadband (a) the Present_Value must exceed the Low_Limit plus the Deadband
for a minimum period of time, specified in the Time_Delay property, and for a minimum period of time, specified in the Time_Delay property, and
(b) the LowLimitEnable flag must be set in the Limit_Enable property, and (b) the LowLimitEnable flag must be set in the Limit_Enable property, and
(c) the TO-NORMAL flag must be set in the Event_Enable property. */ (c) the TO-NORMAL flag must be set in the Event_Enable property. */
if ((PresentVal > CurrentAV->Low_Limit + CurrentAV->Deadband) && if ((PresentVal > CurrentAV->Low_Limit + CurrentAV->Deadband)
((CurrentAV->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) == EVENT_LOW_LIMIT_ENABLE) && && ((CurrentAV->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) ==
((CurrentAV->Event_Enable & EVENT_ENABLE_TO_NORMAL) == EVENT_ENABLE_TO_NORMAL)) EVENT_LOW_LIMIT_ENABLE) &&
{ ((CurrentAV->Event_Enable & EVENT_ENABLE_TO_NORMAL) ==
if(!CurrentAV->Remaining_Time_Delay) EVENT_ENABLE_TO_NORMAL)) {
if (!CurrentAV->Remaining_Time_Delay)
CurrentAV->Event_State = EVENT_STATE_NORMAL; CurrentAV->Event_State = EVENT_STATE_NORMAL;
else else
CurrentAV->Remaining_Time_Delay--; CurrentAV->Remaining_Time_Delay--;
@@ -865,41 +879,36 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
break; break;
default: default:
return; /* shouldn't happen */ return; /* shouldn't happen */
} /* switch (FromState) */ } /* switch (FromState) */
ToState = CurrentAV->Event_State; ToState = CurrentAV->Event_State;
if (FromState != ToState) if (FromState != ToState) {
{
/* Event_State has changed. /* Event_State has changed.
Need to fill only the basic parameters of this type of event. Need to fill only the basic parameters of this type of event.
Other parameters will be filled in common function. */ Other parameters will be filled in common function. */
switch (ToState) switch (ToState) {
{
case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_HIGH_LIMIT:
ExceededLimit = CurrentAV->High_Limit; ExceededLimit = CurrentAV->High_Limit;
characterstring_init_ansi(&msgText, characterstring_init_ansi(&msgText, "Goes to high limit");
"Goes to high limit");
break; break;
case EVENT_STATE_LOW_LIMIT: case EVENT_STATE_LOW_LIMIT:
ExceededLimit = CurrentAV->Low_Limit; ExceededLimit = CurrentAV->Low_Limit;
characterstring_init_ansi(&msgText, characterstring_init_ansi(&msgText, "Goes to low limit");
"Goes to low limit");
break; break;
case EVENT_STATE_NORMAL: case EVENT_STATE_NORMAL:
if(FromState == EVENT_STATE_HIGH_LIMIT) { if (FromState == EVENT_STATE_HIGH_LIMIT) {
ExceededLimit = CurrentAV->High_Limit; ExceededLimit = CurrentAV->High_Limit;
characterstring_init_ansi(&msgText, characterstring_init_ansi(&msgText,
"Back to normal state from high limit"); "Back to normal state from high limit");
} } else {
else {
ExceededLimit = CurrentAV->Low_Limit; ExceededLimit = CurrentAV->Low_Limit;
characterstring_init_ansi(&msgText, characterstring_init_ansi(&msgText,
"Back to normal state from low limit"); "Back to normal state from low limit");
} }
break; break;
@@ -910,9 +919,9 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Event_State for (%s,%d) goes from %s to %s.\n", fprintf(stderr, "Event_State for (%s,%d) goes from %s to %s.\n",
bactext_object_type_name(OBJECT_ANALOG_VALUE), bactext_object_type_name(OBJECT_ANALOG_VALUE), object_instance,
object_instance, bactext_event_state_name(FromState), bactext_event_state_name(FromState),
bactext_event_state_name(ToState)); bactext_event_state_name(ToState));
#endif /* PRINT_ENABLED */ #endif /* PRINT_ENABLED */
/* Notify Type */ /* Notify Type */
@@ -924,8 +933,7 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
} }
if (SendNotify) if (SendNotify) {
{
/* Event Object Identifier */ /* Event Object Identifier */
event_data.eventObjectIdentifier.type = OBJECT_ANALOG_VALUE; event_data.eventObjectIdentifier.type = OBJECT_ANALOG_VALUE;
event_data.eventObjectIdentifier.instance = object_instance; event_data.eventObjectIdentifier.instance = object_instance;
@@ -936,22 +944,21 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
if (event_data.notifyType != NOTIFY_ACK_NOTIFICATION) { if (event_data.notifyType != NOTIFY_ACK_NOTIFICATION) {
/* fill Event_Time_Stamps */ /* fill Event_Time_Stamps */
switch (ToState) switch (ToState) {
{
case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_HIGH_LIMIT:
case EVENT_STATE_LOW_LIMIT: case EVENT_STATE_LOW_LIMIT:
CurrentAV->Event_Time_Stamps[TRANSITION_TO_OFFNORMAL] = CurrentAV->Event_Time_Stamps[TRANSITION_TO_OFFNORMAL] =
event_data.timeStamp.value.dateTime; event_data.timeStamp.value.dateTime;
break; break;
case EVENT_STATE_FAULT: case EVENT_STATE_FAULT:
CurrentAV->Event_Time_Stamps[TRANSITION_TO_FAULT] = CurrentAV->Event_Time_Stamps[TRANSITION_TO_FAULT] =
event_data.timeStamp.value.dateTime; event_data.timeStamp.value.dateTime;
break; break;
case EVENT_STATE_NORMAL: case EVENT_STATE_NORMAL:
CurrentAV->Event_Time_Stamps[TRANSITION_TO_NORMAL] = CurrentAV->Event_Time_Stamps[TRANSITION_TO_NORMAL] =
event_data.timeStamp.value.dateTime; event_data.timeStamp.value.dateTime;
break; break;
} }
} }
@@ -978,50 +985,57 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
/* Event Values */ /* Event Values */
if (event_data.notifyType != NOTIFY_ACK_NOTIFICATION) { if (event_data.notifyType != NOTIFY_ACK_NOTIFICATION) {
/* Value that exceeded a limit. */ /* Value that exceeded a limit. */
event_data.notificationParams.outOfRange.exceedingValue = PresentVal; event_data.notificationParams.outOfRange.exceedingValue =
PresentVal;
/* Status_Flags of the referenced object. */ /* Status_Flags of the referenced object. */
bitstring_init(&event_data.notificationParams.outOfRange.statusFlags); bitstring_init(&event_data.notificationParams.outOfRange.
bitstring_set_bit(&event_data.notificationParams.outOfRange.statusFlags, statusFlags);
STATUS_FLAG_IN_ALARM, CurrentAV->Event_State ? true : false); bitstring_set_bit(&event_data.notificationParams.outOfRange.
bitstring_set_bit(&event_data.notificationParams.outOfRange.statusFlags, statusFlags, STATUS_FLAG_IN_ALARM,
STATUS_FLAG_FAULT, false); CurrentAV->Event_State ? true : false);
bitstring_set_bit(&event_data.notificationParams.outOfRange.statusFlags, bitstring_set_bit(&event_data.notificationParams.outOfRange.
STATUS_FLAG_OVERRIDDEN, false); statusFlags, STATUS_FLAG_FAULT, false);
bitstring_set_bit(&event_data.notificationParams.outOfRange.statusFlags, bitstring_set_bit(&event_data.notificationParams.outOfRange.
STATUS_FLAG_OUT_OF_SERVICE, CurrentAV->Out_Of_Service); statusFlags, STATUS_FLAG_OVERRIDDEN, false);
bitstring_set_bit(&event_data.notificationParams.outOfRange.
statusFlags, STATUS_FLAG_OUT_OF_SERVICE,
CurrentAV->Out_Of_Service);
/* Deadband used for limit checking. */ /* Deadband used for limit checking. */
event_data.notificationParams.outOfRange.deadband = CurrentAV->Deadband; event_data.notificationParams.outOfRange.deadband =
CurrentAV->Deadband;
/* Limit that was exceeded. */ /* Limit that was exceeded. */
event_data.notificationParams.outOfRange.exceededLimit = ExceededLimit; event_data.notificationParams.outOfRange.exceededLimit =
ExceededLimit;
} }
/* add data from notification class */ /* add data from notification class */
Notification_Class_common_reporting_function(&event_data); Notification_Class_common_reporting_function(&event_data);
/* Ack required */ /* Ack required */
if ((event_data.notifyType != NOTIFY_ACK_NOTIFICATION) && if ((event_data.notifyType != NOTIFY_ACK_NOTIFICATION) &&
(event_data.ackRequired == true)) (event_data.ackRequired == true)) {
{ switch (event_data.toState) {
switch (event_data.toState)
{
case EVENT_STATE_OFFNORMAL: case EVENT_STATE_OFFNORMAL:
case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_HIGH_LIMIT:
case EVENT_STATE_LOW_LIMIT: case EVENT_STATE_LOW_LIMIT:
CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked = false; CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].Time_Stamp = bIsAcked = false;
event_data.timeStamp.value.dateTime; CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
Time_Stamp = event_data.timeStamp.value.dateTime;
break; break;
case EVENT_STATE_FAULT: case EVENT_STATE_FAULT:
CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked = false; CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].
CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].Time_Stamp = bIsAcked = false;
event_data.timeStamp.value.dateTime; CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].
Time_Stamp = event_data.timeStamp.value.dateTime;
break; break;
case EVENT_STATE_NORMAL: case EVENT_STATE_NORMAL:
CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked = false; CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].
CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].Time_Stamp = bIsAcked = false;
event_data.timeStamp.value.dateTime; CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].
Time_Stamp = event_data.timeStamp.value.dateTime;
break; break;
} }
} }
@@ -1031,12 +1045,13 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
int Analog_Value_Event_Information(unsigned index, int Analog_Value_Event_Information(
BACNET_GET_EVENT_INFORMATION_DATA * getevent_data) unsigned index,
BACNET_GET_EVENT_INFORMATION_DATA * getevent_data)
{ {
bool IsNotAckedTransitions; bool IsNotAckedTransitions;
bool IsActiveEvent; bool IsActiveEvent;
int i; int i;
/* check index */ /* check index */
@@ -1046,62 +1061,74 @@ int Analog_Value_Event_Information(unsigned index,
/* Acked_Transitions property, which has at least one of the bits /* Acked_Transitions property, which has at least one of the bits
(TO-OFFNORMAL, TO-FAULT, TONORMAL) set to FALSE. */ (TO-OFFNORMAL, TO-FAULT, TONORMAL) set to FALSE. */
IsNotAckedTransitions = (AV_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked == false) | IsNotAckedTransitions =
(AV_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked == false) | (AV_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL].
(AV_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked == false); bIsAcked ==
} false) | (AV_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT].
else bIsAcked ==
return -1; /* end of list */ false) | (AV_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL].
bIsAcked == false);
} else
return -1; /* end of list */
if ((IsActiveEvent) || (IsNotAckedTransitions)) { if ((IsActiveEvent) || (IsNotAckedTransitions)) {
/* Object Identifier */ /* Object Identifier */
getevent_data->objectIdentifier.type = OBJECT_ANALOG_VALUE; getevent_data->objectIdentifier.type = OBJECT_ANALOG_VALUE;
getevent_data->objectIdentifier.instance = Analog_Value_Index_To_Instance(index); getevent_data->objectIdentifier.instance =
Analog_Value_Index_To_Instance(index);
/* Event State */ /* Event State */
getevent_data->eventState = AV_Descr[index].Event_State; getevent_data->eventState = AV_Descr[index].Event_State;
/* Acknowledged Transitions */ /* Acknowledged Transitions */
bitstring_init(&getevent_data->acknowledgedTransitions); bitstring_init(&getevent_data->acknowledgedTransitions);
bitstring_set_bit(&getevent_data->acknowledgedTransitions, TRANSITION_TO_OFFNORMAL, bitstring_set_bit(&getevent_data->acknowledgedTransitions,
AV_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked); TRANSITION_TO_OFFNORMAL,
bitstring_set_bit(&getevent_data->acknowledgedTransitions, TRANSITION_TO_FAULT, AV_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL].
AV_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked); bIsAcked);
bitstring_set_bit(&getevent_data->acknowledgedTransitions, TRANSITION_TO_NORMAL, bitstring_set_bit(&getevent_data->acknowledgedTransitions,
AV_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked); TRANSITION_TO_FAULT,
AV_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked);
bitstring_set_bit(&getevent_data->acknowledgedTransitions,
TRANSITION_TO_NORMAL,
AV_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked);
/* Event Time Stamps */ /* Event Time Stamps */
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
getevent_data->eventTimeStamps[i].tag = TIME_STAMP_DATETIME; getevent_data->eventTimeStamps[i].tag = TIME_STAMP_DATETIME;
getevent_data->eventTimeStamps[i].value.dateTime = getevent_data->eventTimeStamps[i].value.dateTime =
AV_Descr[index].Event_Time_Stamps[i]; AV_Descr[index].Event_Time_Stamps[i];
} }
/* Notify Type */ /* Notify Type */
getevent_data->notifyType = AV_Descr[index].Notify_Type; getevent_data->notifyType = AV_Descr[index].Notify_Type;
/* Event Enable */ /* Event Enable */
bitstring_init(&getevent_data->eventEnable); bitstring_init(&getevent_data->eventEnable);
bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_OFFNORMAL, bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_OFFNORMAL,
(AV_Descr[index].Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true : false ); (AV_Descr[index].
Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true : false);
bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_FAULT, bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_FAULT,
(AV_Descr[index].Event_Enable & EVENT_ENABLE_TO_FAULT ) ? true : false ); (AV_Descr[index].
Event_Enable & EVENT_ENABLE_TO_FAULT) ? true : false);
bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_NORMAL, bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_NORMAL,
(AV_Descr[index].Event_Enable & EVENT_ENABLE_TO_NORMAL ) ? true : false ); (AV_Descr[index].
Event_Enable & EVENT_ENABLE_TO_NORMAL) ? true : false);
/* Event Priorities */ /* Event Priorities */
Notification_Class_Get_Priorities(AV_Descr[index].Notification_Class, Notification_Class_Get_Priorities(AV_Descr[index].Notification_Class,
getevent_data->eventPriorities); getevent_data->eventPriorities);
return 1; /* active event */ return 1; /* active event */
} } else
else return 0; /* no active event at this index */
return 0; /* no active event at this index */
} }
int Analog_Value_Alarm_Ack(BACNET_ALARM_ACK_DATA * alarmack_data, int Analog_Value_Alarm_Ack(
BACNET_ERROR_CODE * error_code) BACNET_ALARM_ACK_DATA * alarmack_data,
BACNET_ERROR_CODE * error_code)
{ {
ANALOG_VALUE_DESCR *CurrentAV; ANALOG_VALUE_DESCR *CurrentAV;
unsigned int object_index; unsigned int object_index;
object_index = Analog_Value_Instance_To_Index( object_index =
alarmack_data->eventObjectIdentifier.instance); Analog_Value_Instance_To_Index(alarmack_data->eventObjectIdentifier.
instance);
if (object_index < MAX_ANALOG_VALUES) if (object_index < MAX_ANALOG_VALUES)
CurrentAV = &AV_Descr[object_index]; CurrentAV = &AV_Descr[object_index];
@@ -1110,71 +1137,73 @@ int Analog_Value_Alarm_Ack(BACNET_ALARM_ACK_DATA * alarmack_data,
return -1; return -1;
} }
switch (alarmack_data->eventStateAcked) switch (alarmack_data->eventStateAcked) {
{
case EVENT_STATE_OFFNORMAL: case EVENT_STATE_OFFNORMAL:
case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_HIGH_LIMIT:
case EVENT_STATE_LOW_LIMIT: case EVENT_STATE_LOW_LIMIT:
if(CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked == false) { if (CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
if(alarmack_data->eventTimeStamp.tag != TIME_STAMP_DATETIME){ bIsAcked == false) {
if (alarmack_data->eventTimeStamp.tag != TIME_STAMP_DATETIME) {
*error_code = ERROR_CODE_INVALID_TIME_STAMP; *error_code = ERROR_CODE_INVALID_TIME_STAMP;
return -1; return -1;
} }
if(datetime_compare(&CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].Time_Stamp, if (datetime_compare(&CurrentAV->
&alarmack_data->eventTimeStamp.value.dateTime) > 0) Acked_Transitions[TRANSITION_TO_OFFNORMAL].Time_Stamp,
{ &alarmack_data->eventTimeStamp.value.dateTime) > 0) {
*error_code = ERROR_CODE_INVALID_TIME_STAMP; *error_code = ERROR_CODE_INVALID_TIME_STAMP;
return -1; return -1;
} }
/* Clean transitions flag. */ /* Clean transitions flag. */
CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked = true; CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
} bIsAcked = true;
else { } else {
*error_code = ERROR_CODE_INVALID_EVENT_STATE; *error_code = ERROR_CODE_INVALID_EVENT_STATE;
return -1; return -1;
} }
break; break;
case EVENT_STATE_FAULT: case EVENT_STATE_FAULT:
if(CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked == false) { if (CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked ==
if(alarmack_data->eventTimeStamp.tag != TIME_STAMP_DATETIME){ false) {
if (alarmack_data->eventTimeStamp.tag != TIME_STAMP_DATETIME) {
*error_code = ERROR_CODE_INVALID_TIME_STAMP; *error_code = ERROR_CODE_INVALID_TIME_STAMP;
return -1; return -1;
} }
if(datetime_compare(&CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].Time_Stamp, if (datetime_compare(&CurrentAV->
&alarmack_data->eventTimeStamp.value.dateTime) > 0) Acked_Transitions[TRANSITION_TO_NORMAL].Time_Stamp,
{ &alarmack_data->eventTimeStamp.value.dateTime) > 0) {
*error_code = ERROR_CODE_INVALID_TIME_STAMP; *error_code = ERROR_CODE_INVALID_TIME_STAMP;
return -1; return -1;
} }
/* Clean transitions flag. */ /* Clean transitions flag. */
CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked = true; CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked =
} true;
else { } else {
*error_code = ERROR_CODE_INVALID_EVENT_STATE; *error_code = ERROR_CODE_INVALID_EVENT_STATE;
return -1; return -1;
} }
break; break;
case EVENT_STATE_NORMAL: case EVENT_STATE_NORMAL:
if(CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked == false) { if (CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked ==
if(alarmack_data->eventTimeStamp.tag != TIME_STAMP_DATETIME){ false) {
if (alarmack_data->eventTimeStamp.tag != TIME_STAMP_DATETIME) {
*error_code = ERROR_CODE_INVALID_TIME_STAMP; *error_code = ERROR_CODE_INVALID_TIME_STAMP;
return -1; return -1;
} }
if(datetime_compare(&CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].Time_Stamp, if (datetime_compare(&CurrentAV->
&alarmack_data->eventTimeStamp.value.dateTime) > 0) Acked_Transitions[TRANSITION_TO_FAULT].Time_Stamp,
{ &alarmack_data->eventTimeStamp.value.dateTime) > 0) {
*error_code = ERROR_CODE_INVALID_TIME_STAMP; *error_code = ERROR_CODE_INVALID_TIME_STAMP;
return -1; return -1;
} }
/* Clean transitions flag. */ /* Clean transitions flag. */
CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked = true; CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked =
} true;
else { } else {
*error_code = ERROR_CODE_INVALID_EVENT_STATE; *error_code = ERROR_CODE_INVALID_EVENT_STATE;
return -1; return -1;
} }
@@ -1205,10 +1234,10 @@ bool WPValidateArgType(
BACNET_ERROR_CLASS * pErrorClass, BACNET_ERROR_CLASS * pErrorClass,
BACNET_ERROR_CODE * pErrorCode) BACNET_ERROR_CODE * pErrorCode)
{ {
pValue=pValue; pValue = pValue;
ucExpectedTag=ucExpectedTag; ucExpectedTag = ucExpectedTag;
pErrorClass=pErrorClass; pErrorClass = pErrorClass;
pErrorCode=pErrorCode; pErrorCode = pErrorCode;
return false; return false;
} }
+17 -15
View File
@@ -43,23 +43,23 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
typedef struct analog_value_descr { typedef struct analog_value_descr {
uint8_t Event_State : 3; uint8_t Event_State:3;
bool Out_Of_Service; bool Out_Of_Service;
uint8_t Units; uint8_t Units;
/* Here is our Priority Array. They are supposed to be Real, but */ /* Here is our Priority Array. They are supposed to be Real, but */
/* we don't have that kind of memory, so we will use a single byte */ /* we don't have that kind of memory, so we will use a single byte */
/* and load a Real for returning the value when asked. */ /* and load a Real for returning the value when asked. */
uint8_t Priority_Array[BACNET_MAX_PRIORITY]; uint8_t Priority_Array[BACNET_MAX_PRIORITY];
float Relinquish_Default; float Relinquish_Default;
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
uint32_t Time_Delay; uint32_t Time_Delay;
uint32_t Notification_Class; uint32_t Notification_Class;
float High_Limit; float High_Limit;
float Low_Limit; float Low_Limit;
float Deadband; float Deadband;
uint8_t Limit_Enable : 2; uint8_t Limit_Enable:2;
uint8_t Event_Enable : 3; uint8_t Event_Enable:3;
uint8_t Notify_Type : 1; uint8_t Notify_Type:1;
ACKED_INFO Acked_Transitions[MAX_BACNET_EVENT_TRANSITION]; ACKED_INFO Acked_Transitions[MAX_BACNET_EVENT_TRANSITION];
BACNET_DATE_TIME Event_Time_Stamps[MAX_BACNET_EVENT_TRANSITION]; BACNET_DATE_TIME Event_Time_Stamps[MAX_BACNET_EVENT_TRANSITION];
/* time to generate event notification */ /* time to generate event notification */
@@ -85,7 +85,7 @@ extern "C" {
bool Analog_Value_Object_Name( bool Analog_Value_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name); BACNET_CHARACTER_STRING * object_name);
int Analog_Value_Read_Property( int Analog_Value_Read_Property(
BACNET_READ_PROPERTY_DATA * rpdata); BACNET_READ_PROPERTY_DATA * rpdata);
@@ -101,15 +101,17 @@ extern "C" {
uint32_t object_instance); uint32_t object_instance);
/* note: header of Intrinsic_Reporting function is required /* note: header of Intrinsic_Reporting function is required
even when INTRINSIC_REPORTING is not defined */ even when INTRINSIC_REPORTING is not defined */
void Analog_Value_Intrinsic_Reporting( void Analog_Value_Intrinsic_Reporting(
uint32_t object_instance); uint32_t object_instance);
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
int Analog_Value_Event_Information(unsigned index, int Analog_Value_Event_Information(
unsigned index,
BACNET_GET_EVENT_INFORMATION_DATA * getevent_data); BACNET_GET_EVENT_INFORMATION_DATA * getevent_data);
int Analog_Value_Alarm_Ack(BACNET_ALARM_ACK_DATA * alarmack_data, int Analog_Value_Alarm_Ack(
BACNET_ALARM_ACK_DATA * alarmack_data,
BACNET_ERROR_CODE * error_code); BACNET_ERROR_CODE * error_code);
#endif #endif
+8 -10
View File
@@ -94,7 +94,7 @@ void BACfile_Property_Lists(
return; return;
} }
static char * bacfile_name( static char *bacfile_name(
uint32_t instance) uint32_t instance)
{ {
uint32_t index = 0; uint32_t index = 0;
@@ -114,7 +114,7 @@ static char * bacfile_name(
bool bacfile_object_name( bool bacfile_object_name(
uint32_t instance, uint32_t instance,
BACNET_CHARACTER_STRING *object_name) BACNET_CHARACTER_STRING * object_name)
{ {
bool status = false; bool status = false;
char *filename = NULL; char *filename = NULL;
@@ -491,15 +491,13 @@ bool bacfile_read_ack_stream_data(
found = true; found = true;
pFile = fopen(pFilename, "rb"); pFile = fopen(pFilename, "rb");
if (pFile) { if (pFile) {
(void) fseek(pFile, data->type.stream.fileStartPosition, (void) fseek(pFile, data->type.stream.fileStartPosition, SEEK_SET);
SEEK_SET);
if (fwrite(octetstring_value(&data->fileData), if (fwrite(octetstring_value(&data->fileData),
octetstring_length(&data->fileData), 1, octetstring_length(&data->fileData), 1, pFile) != 1) {
pFile) != 1) { #if PRINT_ENABLED
#if PRINT_ENABLED fprintf(stderr, "Failed to write to %s (%lu)!\n", pFilename,
fprintf(stderr, "Failed to write to %s (%lu)!\n", (unsigned long) instance);
pFilename, (unsigned long) instance); #endif
#endif
} }
fclose(pFile); fclose(pFile);
} }
+1 -1
View File
@@ -54,7 +54,7 @@ extern "C" {
const int **pProprietary); const int **pProprietary);
bool bacfile_object_name( bool bacfile_object_name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name); BACNET_CHARACTER_STRING * object_name);
bool bacfile_valid_instance( bool bacfile_valid_instance(
uint32_t object_instance); uint32_t object_instance);
uint32_t bacfile_count( uint32_t bacfile_count(
+9 -9
View File
@@ -233,10 +233,10 @@ bool Binary_Input_Encode_Value_List(
value_list->value.context_specific = false; value_list->value.context_specific = false;
value_list->value.tag = BACNET_APPLICATION_TAG_BIT_STRING; value_list->value.tag = BACNET_APPLICATION_TAG_BIT_STRING;
bitstring_init(&value_list->value.type.Bit_String); bitstring_init(&value_list->value.type.Bit_String);
bitstring_set_bit(&value_list->value.type.Bit_String, STATUS_FLAG_IN_ALARM, bitstring_set_bit(&value_list->value.type.Bit_String,
false); STATUS_FLAG_IN_ALARM, false);
bitstring_set_bit(&value_list->value.type.Bit_String, STATUS_FLAG_FAULT, bitstring_set_bit(&value_list->value.type.Bit_String,
false); STATUS_FLAG_FAULT, false);
bitstring_set_bit(&value_list->value.type.Bit_String, bitstring_set_bit(&value_list->value.type.Bit_String,
STATUS_FLAG_OVERRIDDEN, false); STATUS_FLAG_OVERRIDDEN, false);
if (Binary_Input_Out_Of_Service(object_instance)) { if (Binary_Input_Out_Of_Service(object_instance)) {
@@ -292,7 +292,7 @@ static void Binary_Input_Out_Of_Service_Set(
bool Binary_Input_Object_Name( bool Binary_Input_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name) BACNET_CHARACTER_STRING * object_name)
{ {
static char text_string[32] = ""; /* okay for single thread */ static char text_string[32] = ""; /* okay for single thread */
bool status = false; bool status = false;
@@ -494,10 +494,10 @@ bool WPValidateArgType(
BACNET_ERROR_CLASS * pErrorClass, BACNET_ERROR_CLASS * pErrorClass,
BACNET_ERROR_CODE * pErrorCode) BACNET_ERROR_CODE * pErrorCode)
{ {
pValue=pValue; pValue = pValue;
ucExpectedTag=ucExpectedTag; ucExpectedTag = ucExpectedTag;
pErrorClass=pErrorClass; pErrorClass = pErrorClass;
pErrorCode=pErrorCode; pErrorCode = pErrorCode;
return false; return false;
} }
+1 -1
View File
@@ -54,7 +54,7 @@ extern "C" {
bool Binary_Input_Object_Name( bool Binary_Input_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name); BACNET_CHARACTER_STRING * object_name);
bool Binary_Input_Name_Set( bool Binary_Input_Name_Set(
uint32_t object_instance, uint32_t object_instance,
char *new_name); char *new_name);
+9 -9
View File
@@ -179,7 +179,7 @@ BACNET_BINARY_PV Binary_Output_Present_Value(
/* note: the object name must be unique within this device */ /* note: the object name must be unique within this device */
bool Binary_Output_Object_Name( bool Binary_Output_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name) BACNET_CHARACTER_STRING * object_name)
{ {
static char text_string[32] = ""; /* okay for single thread */ static char text_string[32] = ""; /* okay for single thread */
bool status = false; bool status = false;
@@ -376,8 +376,8 @@ bool Binary_Output_Write_Property(
(value.type.Enumerated <= MAX_BINARY_PV)) { (value.type.Enumerated <= MAX_BINARY_PV)) {
level = (BACNET_BINARY_PV) value.type.Enumerated; level = (BACNET_BINARY_PV) value.type.Enumerated;
object_index = object_index =
Binary_Output_Instance_To_Index(wp_data-> Binary_Output_Instance_To_Index
object_instance); (wp_data->object_instance);
priority--; priority--;
Binary_Output_Level[object_index][priority] = level; Binary_Output_Level[object_index][priority] = level;
/* Note: you could set the physical output here if we /* Note: you could set the physical output here if we
@@ -403,8 +403,8 @@ bool Binary_Output_Write_Property(
if (status) { if (status) {
level = BINARY_NULL; level = BINARY_NULL;
object_index = object_index =
Binary_Output_Instance_To_Index(wp_data-> Binary_Output_Instance_To_Index
object_instance); (wp_data->object_instance);
priority = wp_data->priority; priority = wp_data->priority;
if (priority && (priority <= BACNET_MAX_PRIORITY)) { if (priority && (priority <= BACNET_MAX_PRIORITY)) {
priority--; priority--;
@@ -455,10 +455,10 @@ bool WPValidateArgType(
BACNET_ERROR_CLASS * pErrorClass, BACNET_ERROR_CLASS * pErrorClass,
BACNET_ERROR_CODE * pErrorCode) BACNET_ERROR_CODE * pErrorCode)
{ {
pValue=pValue; pValue = pValue;
ucExpectedTag=ucExpectedTag; ucExpectedTag = ucExpectedTag;
pErrorClass=pErrorClass; pErrorClass = pErrorClass;
pErrorCode=pErrorCode; pErrorCode = pErrorCode;
return false; return false;
} }
+1 -1
View File
@@ -57,7 +57,7 @@ extern "C" {
bool Binary_Output_Object_Name( bool Binary_Output_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name); BACNET_CHARACTER_STRING * object_name);
bool Binary_Output_Name_Set( bool Binary_Output_Name_Set(
uint32_t object_instance, uint32_t object_instance,
char *new_name); char *new_name);
+9 -9
View File
@@ -176,7 +176,7 @@ static BACNET_BINARY_PV Binary_Value_Present_Value(
/* note: the object name must be unique within this device */ /* note: the object name must be unique within this device */
bool Binary_Value_Object_Name( bool Binary_Value_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name) BACNET_CHARACTER_STRING * object_name)
{ {
static char text_string[32] = ""; /* okay for single thread */ static char text_string[32] = ""; /* okay for single thread */
bool status = false; bool status = false;
@@ -359,8 +359,8 @@ bool Binary_Value_Write_Property(
(value.type.Enumerated <= MAX_BINARY_PV)) { (value.type.Enumerated <= MAX_BINARY_PV)) {
level = (BACNET_BINARY_PV) value.type.Enumerated; level = (BACNET_BINARY_PV) value.type.Enumerated;
object_index = object_index =
Binary_Value_Instance_To_Index(wp_data-> Binary_Value_Instance_To_Index
object_instance); (wp_data->object_instance);
priority--; priority--;
Binary_Value_Level[object_index][priority] = level; Binary_Value_Level[object_index][priority] = level;
/* Note: you could set the physical output here if we /* Note: you could set the physical output here if we
@@ -386,8 +386,8 @@ bool Binary_Value_Write_Property(
if (status) { if (status) {
level = BINARY_NULL; level = BINARY_NULL;
object_index = object_index =
Binary_Value_Instance_To_Index(wp_data-> Binary_Value_Instance_To_Index
object_instance); (wp_data->object_instance);
priority = wp_data->priority; priority = wp_data->priority;
if (priority && (priority <= BACNET_MAX_PRIORITY)) { if (priority && (priority <= BACNET_MAX_PRIORITY)) {
priority--; priority--;
@@ -437,10 +437,10 @@ bool WPValidateArgType(
BACNET_ERROR_CLASS * pErrorClass, BACNET_ERROR_CLASS * pErrorClass,
BACNET_ERROR_CODE * pErrorCode) BACNET_ERROR_CODE * pErrorCode)
{ {
pValue=pValue; pValue = pValue;
ucExpectedTag=ucExpectedTag; ucExpectedTag = ucExpectedTag;
pErrorClass=pErrorClass; pErrorClass = pErrorClass;
pErrorCode=pErrorCode; pErrorCode = pErrorCode;
return false; return false;
} }
+1 -1
View File
@@ -51,7 +51,7 @@ extern "C" {
bool Binary_Value_Object_Name( bool Binary_Value_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name); BACNET_CHARACTER_STRING * object_name);
void Binary_Value_Init( void Binary_Value_Init(
void); void);
+88 -82
View File
@@ -38,7 +38,7 @@
#include "apdu.h" #include "apdu.h"
#include "wp.h" /* WriteProperty handling */ #include "wp.h" /* WriteProperty handling */
#include "rp.h" /* ReadProperty handling */ #include "rp.h" /* ReadProperty handling */
#include "dcc.h" /* DeviceCommunicationControl handling */ #include "dcc.h" /* DeviceCommunicationControl handling */
#include "version.h" #include "version.h"
#include "device.h" /* me */ #include "device.h" /* me */
#include "handlers.h" #include "handlers.h"
@@ -86,72 +86,81 @@ extern bool Routed_Device_Write_Property_Local(
static object_functions_t Object_Table[] = { static object_functions_t Object_Table[] = {
{ {
OBJECT_DEVICE, NULL, Device_Count, /* don't init - recursive! */ OBJECT_DEVICE, NULL, Device_Count, /* don't init - recursive! */
Device_Index_To_Instance, Device_Valid_Object_Instance_Number, Device_Index_To_Instance, Device_Valid_Object_Instance_Number,
Device_Object_Name, Device_Read_Property_Local, Device_Object_Name, Device_Read_Property_Local,
Device_Write_Property_Local, Device_Property_Lists, Device_Write_Property_Local, Device_Property_Lists,
NULL, NULL, NULL, NULL}, { NULL, NULL, NULL, NULL}, {
OBJECT_ANALOG_INPUT, Analog_Input_Init, Analog_Input_Count, OBJECT_ANALOG_INPUT, Analog_Input_Init, Analog_Input_Count,
Analog_Input_Index_To_Instance, Analog_Input_Valid_Instance, Analog_Input_Index_To_Instance, Analog_Input_Valid_Instance,
Analog_Input_Object_Name, Analog_Input_Read_Property, Analog_Input_Object_Name, Analog_Input_Read_Property,
Analog_Input_Write_Property, Analog_Input_Property_Lists, Analog_Input_Write_Property, Analog_Input_Property_Lists,
NULL, NULL, NULL, Analog_Input_Intrinsic_Reporting}, { NULL, NULL, NULL, Analog_Input_Intrinsic_Reporting}, {
OBJECT_ANALOG_VALUE, Analog_Value_Init, Analog_Value_Count, OBJECT_ANALOG_VALUE, Analog_Value_Init, Analog_Value_Count,
Analog_Value_Index_To_Instance, Analog_Value_Valid_Instance, Analog_Value_Index_To_Instance, Analog_Value_Valid_Instance,
Analog_Value_Object_Name, Analog_Value_Read_Property, Analog_Value_Object_Name, Analog_Value_Read_Property,
Analog_Value_Write_Property, Analog_Value_Property_Lists, Analog_Value_Write_Property, Analog_Value_Property_Lists,
NULL, NULL, NULL, Analog_Value_Intrinsic_Reporting}, { NULL, NULL, NULL, Analog_Value_Intrinsic_Reporting}, {
OBJECT_BINARY_INPUT, Binary_Input_Init, Binary_Input_Count, OBJECT_BINARY_INPUT, Binary_Input_Init, Binary_Input_Count,
Binary_Input_Index_To_Instance, Binary_Input_Valid_Instance, Binary_Input_Index_To_Instance, Binary_Input_Valid_Instance,
Binary_Input_Object_Name, Binary_Input_Read_Property, Binary_Input_Object_Name, Binary_Input_Read_Property,
NULL, Binary_Input_Property_Lists, NULL, Binary_Input_Property_Lists,
NULL, NULL, NULL, NULL}, { NULL, NULL, NULL, NULL}, {
OBJECT_BINARY_VALUE, Binary_Value_Init, Binary_Value_Count, OBJECT_BINARY_VALUE, Binary_Value_Init, Binary_Value_Count,
Binary_Value_Index_To_Instance, Binary_Value_Valid_Instance, Binary_Value_Index_To_Instance, Binary_Value_Valid_Instance,
Binary_Value_Object_Name, Binary_Value_Read_Property, Binary_Value_Object_Name, Binary_Value_Read_Property,
Binary_Value_Write_Property, Binary_Value_Property_Lists, Binary_Value_Write_Property, Binary_Value_Property_Lists,
NULL, NULL, NULL, NULL}, { NULL, NULL, NULL, NULL}, {
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
OBJECT_NOTIFICATION_CLASS, Notification_Class_Init, Notification_Class_Count, OBJECT_NOTIFICATION_CLASS, Notification_Class_Init,
Notification_Class_Index_To_Instance, Notification_Class_Valid_Instance, Notification_Class_Count,
Notification_Class_Index_To_Instance,
Notification_Class_Valid_Instance,
Notification_Class_Object_Name, Notification_Class_Read_Property, Notification_Class_Object_Name, Notification_Class_Read_Property,
Notification_Class_Write_Property, Notification_Class_Property_Lists, Notification_Class_Write_Property,
NULL, NULL, NULL, NULL}, { Notification_Class_Property_Lists,
NULL, NULL, NULL, NULL}, {
#endif #endif
OBJECT_LIFE_SAFETY_POINT, Life_Safety_Point_Init, Life_Safety_Point_Count, OBJECT_LIFE_SAFETY_POINT, Life_Safety_Point_Init,
Life_Safety_Point_Index_To_Instance, Life_Safety_Point_Valid_Instance, Life_Safety_Point_Count,
Life_Safety_Point_Index_To_Instance,
Life_Safety_Point_Valid_Instance,
Life_Safety_Point_Object_Name, Life_Safety_Point_Read_Property, Life_Safety_Point_Object_Name, Life_Safety_Point_Read_Property,
Life_Safety_Point_Write_Property, Life_Safety_Point_Property_Lists, Life_Safety_Point_Write_Property, Life_Safety_Point_Property_Lists,
NULL, NULL, NULL, NULL}, { NULL, NULL, NULL, NULL}, {
OBJECT_LOAD_CONTROL, Load_Control_Init, Load_Control_Count, OBJECT_LOAD_CONTROL, Load_Control_Init, Load_Control_Count,
Load_Control_Index_To_Instance, Load_Control_Valid_Instance, Load_Control_Index_To_Instance, Load_Control_Valid_Instance,
Load_Control_Object_Name, Load_Control_Read_Property, Load_Control_Object_Name, Load_Control_Read_Property,
Load_Control_Write_Property, Load_Control_Property_Lists, Load_Control_Write_Property, Load_Control_Property_Lists,
NULL, NULL, NULL}, { NULL, NULL, NULL}, {
OBJECT_MULTI_STATE_OUTPUT, Multistate_Output_Init, Multistate_Output_Count, OBJECT_MULTI_STATE_OUTPUT, Multistate_Output_Init,
Multistate_Output_Index_To_Instance, Multistate_Output_Valid_Instance, Multistate_Output_Count,
Multistate_Output_Index_To_Instance,
Multistate_Output_Valid_Instance,
Multistate_Output_Object_Name, Multistate_Output_Read_Property, Multistate_Output_Object_Name, Multistate_Output_Read_Property,
Multistate_Output_Write_Property, Multistate_Output_Property_Lists, Multistate_Output_Write_Property, Multistate_Output_Property_Lists,
NULL, NULL, NULL, NULL}, { NULL, NULL, NULL, NULL}, {
OBJECT_MULTI_STATE_INPUT, Multistate_Input_Init, Multistate_Input_Count, OBJECT_MULTI_STATE_INPUT, Multistate_Input_Init,
Multistate_Input_Index_To_Instance, Multistate_Input_Valid_Instance, Multistate_Input_Count,
Multistate_Input_Index_To_Instance,
Multistate_Input_Valid_Instance,
Multistate_Input_Object_Name, Multistate_Input_Read_Property, Multistate_Input_Object_Name, Multistate_Input_Read_Property,
Multistate_Input_Write_Property, Multistate_Input_Property_Lists, Multistate_Input_Write_Property, Multistate_Input_Property_Lists,
NULL, NULL, NULL, NULL}, { NULL, NULL, NULL, NULL}, {
OBJECT_TRENDLOG, Trend_Log_Init, Trend_Log_Count, OBJECT_TRENDLOG, Trend_Log_Init, Trend_Log_Count,
Trend_Log_Index_To_Instance, Trend_Log_Valid_Instance, Trend_Log_Index_To_Instance, Trend_Log_Valid_Instance,
Trend_Log_Object_Name, Trend_Log_Read_Property, Trend_Log_Object_Name, Trend_Log_Read_Property,
Trend_Log_Write_Property, Trend_Log_Property_Lists, Trend_Log_Write_Property, Trend_Log_Property_Lists,
TrendLogGetRRInfo, NULL, NULL, NULL}, { TrendLogGetRRInfo, NULL, NULL, NULL}, {
#if defined(BACFILE) #if defined(BACFILE)
OBJECT_FILE, bacfile_init, bacfile_count, OBJECT_FILE, bacfile_init, bacfile_count,
bacfile_index_to_instance, bacfile_valid_instance, bacfile_index_to_instance, bacfile_valid_instance,
bacfile_object_name, bacfile_read_property, bacfile_object_name, bacfile_read_property,
bacfile_write_property, BACfile_Property_Lists, bacfile_write_property, BACfile_Property_Lists,
NULL, NULL, NULL, NULL}, { NULL, NULL, NULL, NULL}, {
#endif #endif
MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL} NULL, NULL, NULL, NULL}
}; };
@@ -474,7 +483,7 @@ bool Device_Valid_Object_Instance_Number(
bool Device_Object_Name( bool Device_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name) BACNET_CHARACTER_STRING * object_name)
{ {
bool status = false; bool status = false;
@@ -486,7 +495,7 @@ bool Device_Object_Name(
} }
bool Device_Set_Object_Name( bool Device_Set_Object_Name(
BACNET_CHARACTER_STRING *object_name) BACNET_CHARACTER_STRING * object_name)
{ {
bool status = false; /*return value */ bool status = false; /*return value */
@@ -816,7 +825,7 @@ bool Device_Object_List_Identifier(
* @return True on success or else False if not found. * @return True on success or else False if not found.
*/ */
bool Device_Valid_Object_Name( bool Device_Valid_Object_Name(
BACNET_CHARACTER_STRING *object_name1, BACNET_CHARACTER_STRING * object_name1,
int *object_type, int *object_type,
uint32_t * object_instance) uint32_t * object_instance)
{ {
@@ -835,7 +844,7 @@ bool Device_Valid_Object_Name(
pObject = Device_Objects_Find_Functions(type); pObject = Device_Objects_Find_Functions(type);
if ((pObject != NULL) && (pObject->Object_Name != NULL) && if ((pObject != NULL) && (pObject->Object_Name != NULL) &&
(pObject->Object_Name(instance, &object_name2) && (pObject->Object_Name(instance, &object_name2) &&
characterstring_same(object_name1, &object_name2))) { characterstring_same(object_name1, &object_name2))) {
found = true; found = true;
if (object_type) { if (object_type) {
*object_type = type; *object_type = type;
@@ -860,7 +869,7 @@ bool Device_Valid_Object_Id(
int object_type, int object_type,
uint32_t object_instance) uint32_t object_instance)
{ {
bool status = false; /* return value */ bool status = false; /* return value */
struct object_functions *pObject = NULL; struct object_functions *pObject = NULL;
pObject = Device_Objects_Find_Functions(object_type); pObject = Device_Objects_Find_Functions(object_type);
@@ -880,7 +889,7 @@ bool Device_Valid_Object_Id(
bool Device_Object_Name_Copy( bool Device_Object_Name_Copy(
int object_type, int object_type,
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name) BACNET_CHARACTER_STRING * object_name)
{ {
struct object_functions *pObject = NULL; struct object_functions *pObject = NULL;
bool found = false; bool found = false;
@@ -960,7 +969,8 @@ int tm_isdst Daylight Savings flag.
} }
} }
void Device_getCurrentDateTime(BACNET_DATE_TIME * DateTime) void Device_getCurrentDateTime(
BACNET_DATE_TIME * DateTime)
{ {
Update_Current_Time(); Update_Current_Time();
@@ -1265,8 +1275,8 @@ bool Device_Write_Property_Local(
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
if ((value.type.Object_Id.type == OBJECT_DEVICE) && if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
(Device_Set_Object_Instance_Number(value.type.Object_Id. (Device_Set_Object_Instance_Number(value.type.
instance))) { Object_Id.instance))) {
/* FIXME: we could send an I-Am broadcast to let the world know */ /* FIXME: we could send an I-Am broadcast to let the world know */
} else { } else {
status = false; status = false;
@@ -1299,8 +1309,8 @@ bool Device_Write_Property_Local(
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
/* FIXME: bounds check? */ /* FIXME: bounds check? */
Device_Set_Vendor_Identifier((uint16_t) value.type. Device_Set_Vendor_Identifier((uint16_t) value.
Unsigned_Int); type.Unsigned_Int);
} }
break; break;
case PROP_SYSTEM_STATUS: case PROP_SYSTEM_STATUS:
@@ -1325,15 +1335,14 @@ bool Device_Write_Property_Local(
case PROP_OBJECT_NAME: case PROP_OBJECT_NAME:
status = status =
WPValidateString(&value, WPValidateString(&value,
characterstring_capacity(&My_Object_Name), characterstring_capacity(&My_Object_Name), false,
false, &wp_data->error_class, &wp_data->error_code);
&wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
/* All the object names in a device must be unique. /* All the object names in a device must be unique.
Disallow setting the Device Object Name to any objects in Disallow setting the Device Object Name to any objects in
the device. */ the device. */
if (Device_Valid_Object_Name(&value.type.Character_String, if (Device_Valid_Object_Name(&value.type.Character_String,
NULL, NULL)) { NULL, NULL)) {
status = false; status = false;
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_DUPLICATE_NAME; wp_data->error_code = ERROR_CODE_DUPLICATE_NAME;
@@ -1347,8 +1356,8 @@ bool Device_Write_Property_Local(
WPValidateString(&value, MAX_DEV_LOC_LEN, true, WPValidateString(&value, MAX_DEV_LOC_LEN, true,
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
Device_Set_Location(characterstring_value(&value.type. Device_Set_Location(characterstring_value(&value.
Character_String), type.Character_String),
characterstring_length(&value.type.Character_String)); characterstring_length(&value.type.Character_String));
} }
break; break;
@@ -1358,8 +1367,8 @@ bool Device_Write_Property_Local(
WPValidateString(&value, MAX_DEV_DESC_LEN, true, WPValidateString(&value, MAX_DEV_DESC_LEN, true,
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
Device_Set_Description(characterstring_value(&value.type. Device_Set_Description(characterstring_value(&value.
Character_String), type.Character_String),
characterstring_length(&value.type.Character_String)); characterstring_length(&value.type.Character_String));
} }
break; break;
@@ -1368,8 +1377,8 @@ bool Device_Write_Property_Local(
WPValidateString(&value, MAX_DEV_MOD_LEN, true, WPValidateString(&value, MAX_DEV_MOD_LEN, true,
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
Device_Set_Model_Name(characterstring_value(&value.type. Device_Set_Model_Name(characterstring_value(&value.
Character_String), type.Character_String),
characterstring_length(&value.type.Character_String)); characterstring_length(&value.type.Character_String));
} }
break; break;
@@ -1381,8 +1390,8 @@ bool Device_Write_Property_Local(
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
if (value.type.Unsigned_Int <= 255) { if (value.type.Unsigned_Int <= 255) {
dlmstp_set_max_info_frames((uint8_t) value.type. dlmstp_set_max_info_frames((uint8_t) value.
Unsigned_Int); type.Unsigned_Int);
} else { } else {
status = false; status = false;
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
@@ -1464,9 +1473,9 @@ bool Device_Write_Property(
* @return True if the object instance supports this feature and value changed. * @return True if the object instance supports this feature and value changed.
*/ */
bool Device_Encode_Value_List( bool Device_Encode_Value_List(
BACNET_OBJECT_TYPE object_type, BACNET_OBJECT_TYPE object_type,
uint32_t object_instance, uint32_t object_instance,
BACNET_PROPERTY_VALUE * value_list) BACNET_PROPERTY_VALUE * value_list)
{ {
bool status = false; /* Ever the pessamist! */ bool status = false; /* Ever the pessamist! */
struct object_functions *pObject = NULL; struct object_functions *pObject = NULL;
@@ -1476,9 +1485,8 @@ bool Device_Encode_Value_List(
if (pObject->Object_Valid_Instance && if (pObject->Object_Valid_Instance &&
pObject->Object_Valid_Instance(object_instance)) { pObject->Object_Valid_Instance(object_instance)) {
if (pObject->Object_Value_List) { if (pObject->Object_Value_List) {
status = pObject->Object_Value_List( status =
object_instance, pObject->Object_Value_List(object_instance, value_list);
value_list);
} }
} }
} }
@@ -1488,29 +1496,27 @@ bool Device_Encode_Value_List(
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
void Device_local_reporting(void) void Device_local_reporting(
void)
{ {
struct object_functions *pObject; struct object_functions *pObject;
uint32_t objects_count; uint32_t objects_count;
uint32_t object_instance; uint32_t object_instance;
int object_type; int object_type;
uint32_t idx; uint32_t idx;
objects_count = Device_Object_List_Count(); objects_count = Device_Object_List_Count();
/* loop for all objects */ /* loop for all objects */
for (idx = 1; idx < objects_count; idx++) for (idx = 1; idx < objects_count; idx++) {
{ Device_Object_List_Identifier(idx, &object_type, &object_instance);
Device_Object_List_Identifier(idx, &object_type,
&object_instance);
pObject = Device_Objects_Find_Functions(object_type); pObject = Device_Objects_Find_Functions(object_type);
if (pObject != NULL) { if (pObject != NULL) {
if (pObject->Object_Valid_Instance && if (pObject->Object_Valid_Instance &&
pObject->Object_Valid_Instance(object_instance)) { pObject->Object_Valid_Instance(object_instance)) {
if (pObject->Object_Intrinsic_Reporting) { if (pObject->Object_Intrinsic_Reporting) {
pObject->Object_Intrinsic_Reporting( pObject->Object_Intrinsic_Reporting(object_instance);
object_instance);
} }
} }
} }
@@ -1555,7 +1561,7 @@ void Device_Init(
characterstring_init_ansi(&My_Object_Name, "SimpleServer"); characterstring_init_ansi(&My_Object_Name, "SimpleServer");
/* we don't use the object table passed in /* we don't use the object table passed in
since there is extra stuff we don't need in there. */ since there is extra stuff we don't need in there. */
(void)object_table; (void) object_table;
pObject = &Object_Table[0]; pObject = &Object_Table[0];
while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) { while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) {
if (pObject->Object_Init) { if (pObject->Object_Init) {
@@ -1653,10 +1659,10 @@ bool WPValidateArgType(
BACNET_ERROR_CLASS * pErrorClass, BACNET_ERROR_CLASS * pErrorClass,
BACNET_ERROR_CODE * pErrorCode) BACNET_ERROR_CODE * pErrorCode)
{ {
pValue=pValue; pValue = pValue;
ucExpectedTag=ucExpectedTag; ucExpectedTag = ucExpectedTag;
pErrorClass=pErrorClass; pErrorClass = pErrorClass;
pErrorCode=pErrorCode; pErrorCode = pErrorCode;
return false; return false;
} }
@@ -1668,11 +1674,11 @@ bool WPValidateString(
BACNET_ERROR_CLASS * pErrorClass, BACNET_ERROR_CLASS * pErrorClass,
BACNET_ERROR_CODE * pErrorCode) BACNET_ERROR_CODE * pErrorCode)
{ {
pValue=pValue; pValue = pValue;
iMaxLen=iMaxLen; iMaxLen = iMaxLen;
bEmptyAllowed=bEmptyAllowed; bEmptyAllowed = bEmptyAllowed;
pErrorClass=pErrorClass; pErrorClass = pErrorClass;
pErrorCode=pErrorCode; pErrorCode = pErrorCode;
return false; return false;
} }
@@ -1681,8 +1687,8 @@ int handler_cov_encode_subscriptions(
uint8_t * apdu, uint8_t * apdu,
int max_apdu) int max_apdu)
{ {
apdu=apdu; apdu = apdu;
max_apdu=max_apdu; max_apdu = max_apdu;
return 0; return 0;
} }
+14 -12
View File
@@ -73,9 +73,9 @@ typedef uint32_t(
*/ */
typedef bool( typedef bool(
*object_name_function) *object_name_function)
( (
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name); BACNET_CHARACTER_STRING * object_name);
/** Look in the table of objects of this type, and see if this is a valid /** Look in the table of objects of this type, and see if this is a valid
* instance number. * instance number.
@@ -116,9 +116,9 @@ typedef bool(
* @ingroup ObjHelpers * @ingroup ObjHelpers
* @param [in] Object instance. * @param [in] Object instance.
*/ */
typedef void( typedef void (
*object_intrinsic_reporting_function) ( *object_intrinsic_reporting_function) (
uint32_t object_instance); uint32_t object_instance);
/** Defines the group of object helper functions for any supported Object. /** Defines the group of object helper functions for any supported Object.
@@ -213,7 +213,8 @@ extern "C" {
rr_info_function Device_Objects_RR_Info( rr_info_function Device_Objects_RR_Info(
BACNET_OBJECT_TYPE object_type); BACNET_OBJECT_TYPE object_type);
void Device_getCurrentDateTime(BACNET_DATE_TIME * DateTime); void Device_getCurrentDateTime(
BACNET_DATE_TIME * DateTime);
void Device_Property_Lists( void Device_Property_Lists(
const int **pRequired, const int **pRequired,
@@ -250,14 +251,14 @@ extern "C" {
bool Device_Object_Name( bool Device_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name); BACNET_CHARACTER_STRING * object_name);
bool Device_Set_Object_Name( bool Device_Set_Object_Name(
BACNET_CHARACTER_STRING *object_name); BACNET_CHARACTER_STRING * object_name);
/* copy a child object name */ /* copy a child object name */
bool Device_Object_Name_Copy( bool Device_Object_Name_Copy(
int object_type, int object_type,
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name); BACNET_CHARACTER_STRING * object_name);
BACNET_DEVICE_STATUS Device_System_Status( BACNET_DEVICE_STATUS Device_System_Status(
void); void);
@@ -316,7 +317,7 @@ extern "C" {
void); void);
bool Device_Valid_Object_Name( bool Device_Valid_Object_Name(
BACNET_CHARACTER_STRING *object_name, BACNET_CHARACTER_STRING * object_name,
int *object_type, int *object_type,
uint32_t * object_instance); uint32_t * object_instance);
bool Device_Valid_Object_Id( bool Device_Valid_Object_Id(
@@ -338,7 +339,8 @@ extern "C" {
BACNET_WRITE_PROPERTY_DATA * wp_data); BACNET_WRITE_PROPERTY_DATA * wp_data);
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
void Device_local_reporting(void); void Device_local_reporting(
void);
#endif #endif
/* Prototypes for Routing functionality in the Device Object. /* Prototypes for Routing functionality in the Device Object.
@@ -411,11 +413,11 @@ extern "C" {
* - The interface between the implemented Objects and the BAC-stack services, * - The interface between the implemented Objects and the BAC-stack services,
* specifically the handlers, which are mediated through function calls to * specifically the handlers, which are mediated through function calls to
* the Device object. * the Device object.
*//** @defgroup ObjHelpers Object Helper Functions *//** @defgroup ObjHelpers Object Helper Functions
* @ingroup ObjFrmwk * @ingroup ObjFrmwk
* This section describes the function templates for the helper functions that * This section describes the function templates for the helper functions that
* provide common object support. * provide common object support.
*//** @defgroup ObjIntf Handler-to-Object Interface Functions *//** @defgroup ObjIntf Handler-to-Object Interface Functions
* @ingroup ObjFrmwk * @ingroup ObjFrmwk
* This section describes the fairly limited set of functions that link the * This section describes the fairly limited set of functions that link the
* BAC-stack handlers to the BACnet Object instances. All of these calls are * BAC-stack handlers to the BACnet Object instances. All of these calls are
+7 -12
View File
@@ -127,14 +127,10 @@ uint16_t Add_Routed_Device(
pDev->bacObj.mObject_Type = OBJECT_DEVICE; pDev->bacObj.mObject_Type = OBJECT_DEVICE;
pDev->bacObj.Object_Instance_Number = Object_Instance; pDev->bacObj.Object_Instance_Number = Object_Instance;
if (sObject_Name != NULL) if (sObject_Name != NULL)
Routed_Device_Set_Object_Name( Routed_Device_Set_Object_Name(CHARACTER_UTF8, sObject_Name,
CHARACTER_UTF8,
sObject_Name,
strlen(sObject_Name)); strlen(sObject_Name));
else else
Routed_Device_Set_Object_Name( Routed_Device_Set_Object_Name(CHARACTER_UTF8, "No Name",
CHARACTER_UTF8,
"No Name",
strlen("No Name")); strlen("No Name"));
if (sDescription != NULL) if (sDescription != NULL)
Routed_Device_Set_Description(sDescription, strlen(sDescription)); Routed_Device_Set_Description(sDescription, strlen(sDescription));
@@ -488,8 +484,8 @@ bool Routed_Device_Write_Property_Local(
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
if ((value.type.Object_Id.type == OBJECT_DEVICE) && if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
(Routed_Device_Set_Object_Instance_Number(value. (Routed_Device_Set_Object_Instance_Number(value.type.
type.Object_Id.instance))) { Object_Id.instance))) {
/* FIXME: we could send an I-Am broadcast to let the world know */ /* FIXME: we could send an I-Am broadcast to let the world know */
} else { } else {
status = false; status = false;
@@ -503,8 +499,8 @@ bool Routed_Device_Write_Property_Local(
WPValidateString(&value, MAX_DEV_NAME_LEN, false, WPValidateString(&value, MAX_DEV_NAME_LEN, false,
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
Routed_Device_Set_Object_Name( Routed_Device_Set_Object_Name(characterstring_encoding(&value.
characterstring_encoding(&value.type.Character_String), type.Character_String),
characterstring_value(&value.type.Character_String), characterstring_value(&value.type.Character_String),
characterstring_length(&value.type.Character_String)); characterstring_length(&value.type.Character_String));
} }
@@ -559,8 +555,7 @@ bool Routed_Device_Set_Object_Name(
bool status = false; /*return value */ bool status = false; /*return value */
DEVICE_OBJECT_DATA *pDev = &Devices[iCurrent_Device_Idx]; DEVICE_OBJECT_DATA *pDev = &Devices[iCurrent_Device_Idx];
if ((encoding == CHARACTER_UTF8) && if ((encoding == CHARACTER_UTF8) && (length < MAX_DEV_NAME_LEN)) {
(length < MAX_DEV_NAME_LEN)) {
/* Make the change and update the database revision */ /* Make the change and update the database revision */
memmove(pDev->bacObj.Object_Name, value, length); memmove(pDev->bacObj.Object_Name, value, length);
pDev->bacObj.Object_Name[length] = 0; pDev->bacObj.Object_Name[length] = 0;
+1 -1
View File
@@ -274,7 +274,7 @@ static BACNET_SHED_STATE Load_Control_Present_Value(
/* note: the object name must be unique within this device */ /* note: the object name must be unique within this device */
bool Load_Control_Object_Name( bool Load_Control_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name) BACNET_CHARACTER_STRING * object_name)
{ {
static char text_string[32] = ""; /* okay for single thread */ static char text_string[32] = ""; /* okay for single thread */
bool status = false; bool status = false;
+1 -1
View File
@@ -54,7 +54,7 @@ extern "C" {
bool Load_Control_Object_Name( bool Load_Control_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name); BACNET_CHARACTER_STRING * object_name);
void Load_Control_Init( void Load_Control_Init(
void); void);
+12 -12
View File
@@ -469,8 +469,8 @@ int Lighting_Output_Read_Property(
object_index = object_index =
Lighting_Output_Instance_To_Index(rpdata->object_instance); Lighting_Output_Instance_To_Index(rpdata->object_instance);
if (rpdata->array_index <= BACNET_MAX_PRIORITY) { if (rpdata->array_index <= BACNET_MAX_PRIORITY) {
if (Lighting_Output_Level[object_index][rpdata-> if (Lighting_Output_Level[object_index][rpdata->array_index
array_index - 1] == LIGHTING_LEVEL_NULL) - 1] == LIGHTING_LEVEL_NULL)
apdu_len = encode_application_null(&apdu[0]); apdu_len = encode_application_null(&apdu[0]);
else { else {
real_value = Lighting_Output_Level[object_index] real_value = Lighting_Output_Level[object_index]
@@ -554,11 +554,11 @@ bool Lighting_Output_Write_Property(
if (status) { if (status) {
level = LIGHTING_LEVEL_NULL; level = LIGHTING_LEVEL_NULL;
object_index = object_index =
Lighting_Output_Instance_To_Index(wp_data-> Lighting_Output_Instance_To_Index
object_instance); (wp_data->object_instance);
status = status =
Lighting_Output_Present_Value_Relinquish(wp_data-> Lighting_Output_Present_Value_Relinquish
object_instance, wp_data->priority); (wp_data->object_instance, wp_data->priority);
if (wp_data->priority == 6) { if (wp_data->priority == 6) {
/* Command priority 6 is reserved for use by Minimum On/Off /* Command priority 6 is reserved for use by Minimum On/Off
algorithm and may not be used for other purposes in any algorithm and may not be used for other purposes in any
@@ -585,8 +585,8 @@ bool Lighting_Output_Write_Property(
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
object_index = object_index =
Lighting_Output_Instance_To_Index(wp_data-> Lighting_Output_Instance_To_Index
object_instance); (wp_data->object_instance);
Lighting_Output_Out_Of_Service[object_index] = Lighting_Output_Out_Of_Service[object_index] =
value.type.Boolean; value.type.Boolean;
} }
@@ -612,10 +612,10 @@ bool WPValidateArgType(
BACNET_ERROR_CLASS * pErrorClass, BACNET_ERROR_CLASS * pErrorClass,
BACNET_ERROR_CODE * pErrorCode) BACNET_ERROR_CODE * pErrorCode)
{ {
pValue=pValue; pValue = pValue;
ucExpectedTag=ucExpectedTag; ucExpectedTag = ucExpectedTag;
pErrorClass=pErrorClass; pErrorClass = pErrorClass;
pErrorCode=pErrorCode; pErrorCode = pErrorCode;
return false; return false;
} }
+11 -10
View File
@@ -175,7 +175,7 @@ static BACNET_LIFE_SAFETY_STATE Life_Safety_Point_Present_Value(
/* note: the object name must be unique within this device */ /* note: the object name must be unique within this device */
bool Life_Safety_Point_Object_Name( bool Life_Safety_Point_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name) BACNET_CHARACTER_STRING * object_name)
{ {
static char text_string[32] = ""; /* okay for single thread */ static char text_string[32] = ""; /* okay for single thread */
bool status = false; bool status = false;
@@ -218,7 +218,8 @@ int Life_Safety_Point_Read_Property(
break; break;
case PROP_OBJECT_NAME: case PROP_OBJECT_NAME:
case PROP_DESCRIPTION: case PROP_DESCRIPTION:
Life_Safety_Point_Object_Name(rpdata->object_instance, &char_string); Life_Safety_Point_Object_Name(rpdata->object_instance,
&char_string);
apdu_len = apdu_len =
encode_application_character_string(&apdu[0], &char_string); encode_application_character_string(&apdu[0], &char_string);
break; break;
@@ -324,8 +325,8 @@ bool Life_Safety_Point_Write_Property(
if (status) { if (status) {
if (value.type.Enumerated <= MAX_LIFE_SAFETY_MODE) { if (value.type.Enumerated <= MAX_LIFE_SAFETY_MODE) {
object_index = object_index =
Life_Safety_Point_Instance_To_Index(wp_data-> Life_Safety_Point_Instance_To_Index
object_instance); (wp_data->object_instance);
Life_Safety_Point_Mode[object_index] = Life_Safety_Point_Mode[object_index] =
value.type.Enumerated; value.type.Enumerated;
} else { } else {
@@ -341,8 +342,8 @@ bool Life_Safety_Point_Write_Property(
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
object_index = object_index =
Life_Safety_Point_Instance_To_Index(wp_data-> Life_Safety_Point_Instance_To_Index
object_instance); (wp_data->object_instance);
Life_Safety_Point_Out_Of_Service[object_index] = Life_Safety_Point_Out_Of_Service[object_index] =
value.type.Boolean; value.type.Boolean;
} }
@@ -368,10 +369,10 @@ bool WPValidateArgType(
BACNET_ERROR_CLASS * pErrorClass, BACNET_ERROR_CLASS * pErrorClass,
BACNET_ERROR_CODE * pErrorCode) BACNET_ERROR_CODE * pErrorCode)
{ {
pValue=pValue; pValue = pValue;
ucExpectedTag=ucExpectedTag; ucExpectedTag = ucExpectedTag;
pErrorClass=pErrorClass; pErrorClass = pErrorClass;
pErrorCode=pErrorCode; pErrorCode = pErrorCode;
return false; return false;
} }
+1 -1
View File
@@ -50,7 +50,7 @@ extern "C" {
uint32_t object_instance); uint32_t object_instance);
bool Life_Safety_Point_Object_Name( bool Life_Safety_Point_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name); BACNET_CHARACTER_STRING * object_name);
void Life_Safety_Point_Init( void Life_Safety_Point_Init(
void); void);
+15 -14
View File
@@ -227,7 +227,7 @@ bool Multistate_Input_Description_Set(
bool Multistate_Input_Object_Name( bool Multistate_Input_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name) BACNET_CHARACTER_STRING * object_name)
{ {
unsigned index = 0; /* offset from instance lookup */ unsigned index = 0; /* offset from instance lookup */
bool status = false; bool status = false;
@@ -348,7 +348,8 @@ int Multistate_Input_Read_Property(
/* note: Name and Description don't have to be the same. /* note: Name and Description don't have to be the same.
You could make Description writable and different */ You could make Description writable and different */
case PROP_OBJECT_NAME: case PROP_OBJECT_NAME:
Multistate_Input_Object_Name(rpdata->object_instance, &char_string); Multistate_Input_Object_Name(rpdata->object_instance,
&char_string);
apdu_len = apdu_len =
encode_application_character_string(&apdu[0], &char_string); encode_application_character_string(&apdu[0], &char_string);
break; break;
@@ -403,8 +404,8 @@ int Multistate_Input_Read_Property(
/* if no index was specified, then try to encode the entire list */ /* if no index was specified, then try to encode the entire list */
/* into one packet. */ /* into one packet. */
object_index = object_index =
Multistate_Input_Instance_To_Index(rpdata-> Multistate_Input_Instance_To_Index
object_instance); (rpdata->object_instance);
for (i = 1; i <= MULTISTATE_NUMBER_OF_STATES; i++) { for (i = 1; i <= MULTISTATE_NUMBER_OF_STATES; i++) {
characterstring_init_ansi(&char_string, characterstring_init_ansi(&char_string,
Multistate_Input_State_Text(rpdata->object_instance, Multistate_Input_State_Text(rpdata->object_instance,
@@ -425,8 +426,8 @@ int Multistate_Input_Read_Property(
} }
} else { } else {
object_index = object_index =
Multistate_Input_Instance_To_Index(rpdata-> Multistate_Input_Instance_To_Index
object_instance); (rpdata->object_instance);
if (rpdata->array_index <= MULTISTATE_NUMBER_OF_STATES) { if (rpdata->array_index <= MULTISTATE_NUMBER_OF_STATES) {
characterstring_init_ansi(&char_string, characterstring_init_ansi(&char_string,
Multistate_Input_State_Text(rpdata->object_instance, Multistate_Input_State_Text(rpdata->object_instance,
@@ -486,8 +487,8 @@ bool Multistate_Input_Write_Property(
if (status) { if (status) {
if (Out_Of_Service[object_index]) { if (Out_Of_Service[object_index]) {
status = status =
Multistate_Input_Present_Value_Set(wp_data-> Multistate_Input_Present_Value_Set
object_instance, value.type.Unsigned_Int); (wp_data->object_instance, value.type.Unsigned_Int);
if (!status) { if (!status) {
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
@@ -505,8 +506,8 @@ bool Multistate_Input_Write_Property(
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
object_index = object_index =
Multistate_Input_Instance_To_Index(wp_data-> Multistate_Input_Instance_To_Index
object_instance); (wp_data->object_instance);
Out_Of_Service[object_index] = value.type.Boolean; Out_Of_Service[object_index] = value.type.Boolean;
} }
break; break;
@@ -531,10 +532,10 @@ bool WPValidateArgType(
BACNET_ERROR_CLASS * pErrorClass, BACNET_ERROR_CLASS * pErrorClass,
BACNET_ERROR_CODE * pErrorCode) BACNET_ERROR_CODE * pErrorCode)
{ {
pValue=pValue; pValue = pValue;
ucExpectedTag=ucExpectedTag; ucExpectedTag = ucExpectedTag;
pErrorClass=pErrorClass; pErrorClass = pErrorClass;
pErrorCode=pErrorCode; pErrorCode = pErrorCode;
return false; return false;
} }
+1 -1
View File
@@ -62,7 +62,7 @@ extern "C" {
bool Multistate_Input_Object_Name( bool Multistate_Input_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name); BACNET_CHARACTER_STRING * object_name);
bool Multistate_Input_Name_Set( bool Multistate_Input_Name_Set(
uint32_t object_instance, uint32_t object_instance,
char *new_name); char *new_name);
+17 -16
View File
@@ -182,7 +182,7 @@ static uint32_t Multistate_Output_Present_Value(
/* note: the object name must be unique within this device */ /* note: the object name must be unique within this device */
bool Multistate_Output_Object_Name( bool Multistate_Output_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name) BACNET_CHARACTER_STRING * object_name)
{ {
static char text_string[32] = ""; /* okay for single thread */ static char text_string[32] = ""; /* okay for single thread */
bool status = false; bool status = false;
@@ -224,7 +224,8 @@ int Multistate_Output_Read_Property(
You could make Description writable and different */ You could make Description writable and different */
case PROP_OBJECT_NAME: case PROP_OBJECT_NAME:
case PROP_DESCRIPTION: case PROP_DESCRIPTION:
Multistate_Output_Object_Name(rpdata->object_instance, &char_string); Multistate_Output_Object_Name(rpdata->object_instance,
&char_string);
apdu_len = apdu_len =
encode_application_character_string(&apdu[0], &char_string); encode_application_character_string(&apdu[0], &char_string);
break; break;
@@ -267,8 +268,8 @@ int Multistate_Output_Read_Property(
/* into one packet. */ /* into one packet. */
else if (rpdata->array_index == BACNET_ARRAY_ALL) { else if (rpdata->array_index == BACNET_ARRAY_ALL) {
object_index = object_index =
Multistate_Output_Instance_To_Index(rpdata-> Multistate_Output_Instance_To_Index
object_instance); (rpdata->object_instance);
for (i = 0; i < BACNET_MAX_PRIORITY; i++) { for (i = 0; i < BACNET_MAX_PRIORITY; i++) {
/* FIXME: check if we have room before adding it to APDU */ /* FIXME: check if we have room before adding it to APDU */
if (Multistate_Output_Level[object_index][i] == if (Multistate_Output_Level[object_index][i] ==
@@ -293,8 +294,8 @@ int Multistate_Output_Read_Property(
} }
} else { } else {
object_index = object_index =
Multistate_Output_Instance_To_Index(rpdata-> Multistate_Output_Instance_To_Index
object_instance); (rpdata->object_instance);
if (rpdata->array_index <= BACNET_MAX_PRIORITY) { if (rpdata->array_index <= BACNET_MAX_PRIORITY) {
if (Multistate_Output_Level[object_index] if (Multistate_Output_Level[object_index]
[rpdata->array_index - 1] == MULTISTATE_NULL) [rpdata->array_index - 1] == MULTISTATE_NULL)
@@ -376,8 +377,8 @@ bool Multistate_Output_Write_Property(
(value.type.Unsigned_Int <= MULTISTATE_NUMBER_OF_STATES)) { (value.type.Unsigned_Int <= MULTISTATE_NUMBER_OF_STATES)) {
level = value.type.Unsigned_Int; level = value.type.Unsigned_Int;
object_index = object_index =
Multistate_Output_Instance_To_Index(wp_data-> Multistate_Output_Instance_To_Index
object_instance); (wp_data->object_instance);
priority--; priority--;
Multistate_Output_Level[object_index][priority] = Multistate_Output_Level[object_index][priority] =
(uint8_t) level; (uint8_t) level;
@@ -404,8 +405,8 @@ bool Multistate_Output_Write_Property(
if (status) { if (status) {
level = MULTISTATE_NULL; level = MULTISTATE_NULL;
object_index = object_index =
Multistate_Output_Instance_To_Index(wp_data-> Multistate_Output_Instance_To_Index
object_instance); (wp_data->object_instance);
priority = wp_data->priority; priority = wp_data->priority;
if (priority && (priority <= BACNET_MAX_PRIORITY)) { if (priority && (priority <= BACNET_MAX_PRIORITY)) {
priority--; priority--;
@@ -431,8 +432,8 @@ bool Multistate_Output_Write_Property(
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
object_index = object_index =
Multistate_Output_Instance_To_Index(wp_data-> Multistate_Output_Instance_To_Index
object_instance); (wp_data->object_instance);
Multistate_Output_Out_Of_Service[object_index] = Multistate_Output_Out_Of_Service[object_index] =
value.type.Boolean; value.type.Boolean;
} }
@@ -458,10 +459,10 @@ bool WPValidateArgType(
BACNET_ERROR_CLASS * pErrorClass, BACNET_ERROR_CLASS * pErrorClass,
BACNET_ERROR_CODE * pErrorCode) BACNET_ERROR_CODE * pErrorCode)
{ {
pValue=pValue; pValue = pValue;
ucExpectedTag=ucExpectedTag; ucExpectedTag = ucExpectedTag;
pErrorClass=pErrorClass; pErrorClass = pErrorClass;
pErrorCode=pErrorCode; pErrorCode = pErrorCode;
return false; return false;
} }
+1 -1
View File
@@ -51,7 +51,7 @@ extern "C" {
bool Multistate_Output_Object_Name( bool Multistate_Output_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name); BACNET_CHARACTER_STRING * object_name);
void Multistate_Output_Init( void Multistate_Output_Init(
void); void);
+299 -259
View File
@@ -51,8 +51,7 @@
static NOTIFICATION_CLASS_INFO NC_Info[MAX_NOTIFICATION_CLASSES]; static NOTIFICATION_CLASS_INFO NC_Info[MAX_NOTIFICATION_CLASSES];
/* These three arrays are used by the ReadPropertyMultiple handler */ /* These three arrays are used by the ReadPropertyMultiple handler */
static const int Notification_Properties_Required[] = static const int Notification_Properties_Required[] = {
{
PROP_OBJECT_IDENTIFIER, PROP_OBJECT_IDENTIFIER,
PROP_OBJECT_NAME, PROP_OBJECT_NAME,
PROP_OBJECT_TYPE, PROP_OBJECT_TYPE,
@@ -63,14 +62,12 @@ static const int Notification_Properties_Required[] =
-1 -1
}; };
static const int Notification_Properties_Optional[] = static const int Notification_Properties_Optional[] = {
{
PROP_DESCRIPTION, PROP_DESCRIPTION,
-1 -1
}; };
static const int Notification_Properties_Proprietary[] = static const int Notification_Properties_Proprietary[] = {
{
-1 -1
}; };
@@ -88,12 +85,12 @@ void Notification_Class_Property_Lists(
return; return;
} }
void Notification_Class_Init(void) void Notification_Class_Init(
void)
{ {
uint8_t NotifyIdx = 0; uint8_t NotifyIdx = 0;
for (NotifyIdx = 0; NotifyIdx < MAX_NOTIFICATION_CLASSES; NotifyIdx++) for (NotifyIdx = 0; NotifyIdx < MAX_NOTIFICATION_CLASSES; NotifyIdx++) {
{
/* init with zeros */ /* init with zeros */
memset(&NC_Info[NotifyIdx], 0x00, sizeof(NOTIFICATION_CLASS_INFO)); memset(&NC_Info[NotifyIdx], 0x00, sizeof(NOTIFICATION_CLASS_INFO));
/* set the basic parameters */ /* set the basic parameters */
@@ -111,7 +108,7 @@ void Notification_Class_Init(void)
/* more complex, and then you need validate that the */ /* more complex, and then you need validate that the */
/* given instance exists */ /* given instance exists */
bool Notification_Class_Valid_Instance( bool Notification_Class_Valid_Instance(
uint32_t object_instance) uint32_t object_instance)
{ {
unsigned int index; unsigned int index;
@@ -124,7 +121,8 @@ bool Notification_Class_Valid_Instance(
/* we simply have 0-n object instances. Yours might be */ /* we simply have 0-n object instances. Yours might be */
/* more complex, and then count how many you have */ /* more complex, and then count how many you have */
unsigned Notification_Class_Count(void) unsigned Notification_Class_Count(
void)
{ {
return MAX_NOTIFICATION_CLASSES; return MAX_NOTIFICATION_CLASSES;
} }
@@ -132,7 +130,8 @@ unsigned Notification_Class_Count(void)
/* we simply have 0-n object instances. Yours might be */ /* we simply have 0-n object instances. Yours might be */
/* more complex, and then you need to return the instance */ /* more complex, and then you need to return the instance */
/* that correlates to the correct index */ /* that correlates to the correct index */
uint32_t Notification_Class_Index_To_Instance(unsigned index) uint32_t Notification_Class_Index_To_Instance(
unsigned index)
{ {
return index; return index;
} }
@@ -141,7 +140,7 @@ uint32_t Notification_Class_Index_To_Instance(unsigned index)
/* more complex, and then you need to return the index */ /* more complex, and then you need to return the index */
/* that correlates to the correct instance number */ /* that correlates to the correct instance number */
unsigned Notification_Class_Instance_To_Index( unsigned Notification_Class_Instance_To_Index(
uint32_t object_instance) uint32_t object_instance)
{ {
unsigned index = MAX_NOTIFICATION_CLASSES; unsigned index = MAX_NOTIFICATION_CLASSES;
@@ -152,8 +151,8 @@ unsigned Notification_Class_Instance_To_Index(
} }
bool Notification_Class_Object_Name( bool Notification_Class_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name) BACNET_CHARACTER_STRING * object_name)
{ {
static char text_string[32] = ""; /* okay for single thread */ static char text_string[32] = ""; /* okay for single thread */
unsigned int index; unsigned int index;
@@ -171,7 +170,7 @@ bool Notification_Class_Object_Name(
int Notification_Class_Read_Property( int Notification_Class_Read_Property(
BACNET_READ_PROPERTY_DATA * rpdata) BACNET_READ_PROPERTY_DATA * rpdata)
{ {
NOTIFICATION_CLASS_INFO *CurrentNotify; NOTIFICATION_CLASS_INFO *CurrentNotify;
BACNET_CHARACTER_STRING char_string; BACNET_CHARACTER_STRING char_string;
@@ -180,7 +179,7 @@ int Notification_Class_Read_Property(
uint8_t *apdu = NULL; uint8_t *apdu = NULL;
uint8_t u8Val; uint8_t u8Val;
int idx; int idx;
int apdu_len = 0; /* return value */ int apdu_len = 0; /* return value */
if ((rpdata == NULL) || (rpdata->application_data == NULL) || if ((rpdata == NULL) || (rpdata->application_data == NULL) ||
@@ -189,189 +188,200 @@ int Notification_Class_Read_Property(
} }
apdu = rpdata->application_data; apdu = rpdata->application_data;
CurrentNotify = &NC_Info[Notification_Class_Instance_To_Index(rpdata->object_instance)]; CurrentNotify =
&NC_Info[Notification_Class_Instance_To_Index(rpdata->
object_instance)];
switch (rpdata->object_property) switch (rpdata->object_property) {
{
case PROP_OBJECT_IDENTIFIER: case PROP_OBJECT_IDENTIFIER:
apdu_len = apdu_len =
encode_application_object_id(&apdu[0], OBJECT_NOTIFICATION_CLASS, encode_application_object_id(&apdu[0],
rpdata->object_instance); OBJECT_NOTIFICATION_CLASS, rpdata->object_instance);
break; break;
case PROP_OBJECT_NAME: case PROP_OBJECT_NAME:
case PROP_DESCRIPTION: case PROP_DESCRIPTION:
Notification_Class_Object_Name(rpdata->object_instance, &char_string); Notification_Class_Object_Name(rpdata->object_instance,
&char_string);
apdu_len = apdu_len =
encode_application_character_string(&apdu[0], &char_string); encode_application_character_string(&apdu[0], &char_string);
break; break;
case PROP_OBJECT_TYPE: case PROP_OBJECT_TYPE:
apdu_len = apdu_len =
encode_application_enumerated(&apdu[0], OBJECT_NOTIFICATION_CLASS); encode_application_enumerated(&apdu[0],
OBJECT_NOTIFICATION_CLASS);
break; break;
case PROP_NOTIFICATION_CLASS: case PROP_NOTIFICATION_CLASS:
apdu_len += encode_application_unsigned(&apdu[0], rpdata->object_instance); apdu_len +=
encode_application_unsigned(&apdu[0], rpdata->object_instance);
break; break;
case PROP_PRIORITY: case PROP_PRIORITY:
if (rpdata->array_index == 0) if (rpdata->array_index == 0)
apdu_len += encode_application_unsigned(&apdu[0], 3); apdu_len += encode_application_unsigned(&apdu[0], 3);
else else {
{ if (rpdata->array_index == BACNET_ARRAY_ALL) {
if (rpdata->array_index == BACNET_ARRAY_ALL)
{
/* TO-OFFNORMAL */ /* TO-OFFNORMAL */
apdu_len += encode_application_unsigned(&apdu[apdu_len], apdu_len +=
CurrentNotify->Priority[0]); encode_application_unsigned(&apdu[apdu_len],
CurrentNotify->Priority[0]);
/* TO-FAULT */ /* TO-FAULT */
apdu_len += encode_application_unsigned(&apdu[apdu_len], apdu_len +=
CurrentNotify->Priority[1]); encode_application_unsigned(&apdu[apdu_len],
CurrentNotify->Priority[1]);
/* TO-NORMAL */ /* TO-NORMAL */
apdu_len += encode_application_unsigned(&apdu[apdu_len], apdu_len +=
CurrentNotify->Priority[2]); encode_application_unsigned(&apdu[apdu_len],
} CurrentNotify->Priority[2]);
else if (rpdata->array_index <= 3) } else if (rpdata->array_index <= 3) {
{ apdu_len +=
apdu_len += encode_application_unsigned(&apdu[apdu_len], encode_application_unsigned(&apdu[apdu_len],
CurrentNotify->Priority[rpdata->array_index - 1]); CurrentNotify->Priority[rpdata->array_index - 1]);
} } else {
else
{
rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_class = ERROR_CLASS_PROPERTY;
rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX;
apdu_len = -1; apdu_len = -1;
} }
} }
break; break;
case PROP_ACK_REQUIRED: case PROP_ACK_REQUIRED:
u8Val = CurrentNotify->Ack_Required; u8Val = CurrentNotify->Ack_Required;
bitstring_init(&bit_string); bitstring_init(&bit_string);
bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL, bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL,
(u8Val & TRANSITION_TO_OFFNORMAL_MASKED) ? true : false ); (u8Val & TRANSITION_TO_OFFNORMAL_MASKED) ? true : false);
bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT, bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT,
(u8Val & TRANSITION_TO_FAULT_MASKED ) ? true : false ); (u8Val & TRANSITION_TO_FAULT_MASKED) ? true : false);
bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL, bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL,
(u8Val & TRANSITION_TO_NORMAL_MASKED ) ? true : false ); (u8Val & TRANSITION_TO_NORMAL_MASKED) ? true : false);
/* encode bitstring */ /* encode bitstring */
apdu_len += encode_application_bitstring(&apdu[apdu_len], &bit_string); apdu_len +=
encode_application_bitstring(&apdu[apdu_len], &bit_string);
break; break;
case PROP_RECIPIENT_LIST: case PROP_RECIPIENT_LIST:
/* encode all entry of Recipient_List */ /* encode all entry of Recipient_List */
for (idx = 0; idx < NC_MAX_RECIPIENTS; idx++) for (idx = 0; idx < NC_MAX_RECIPIENTS; idx++) {
{
BACNET_DESTINATION *RecipientEntry; BACNET_DESTINATION *RecipientEntry;
int i = 0; int i = 0;
/* get pointer of current element for Recipient_List - easier for use */ /* get pointer of current element for Recipient_List - easier for use */
RecipientEntry = &CurrentNotify->Recipient_List[idx]; RecipientEntry = &CurrentNotify->Recipient_List[idx];
if (RecipientEntry->Recipient.RecipientType != RECIPIENT_TYPE_NOTINITIALIZED) if (RecipientEntry->Recipient.RecipientType !=
{ RECIPIENT_TYPE_NOTINITIALIZED) {
/* Valid Days - BACnetDaysOfWeek - [bitstring] monday-sunday */ /* Valid Days - BACnetDaysOfWeek - [bitstring] monday-sunday */
u8Val = 0x01; u8Val = 0x01;
bitstring_init(&bit_string); bitstring_init(&bit_string);
for (i = 0; i < MAX_BACNET_DAYS_OF_WEEK; i++) for (i = 0; i < MAX_BACNET_DAYS_OF_WEEK; i++) {
{
if (RecipientEntry->ValidDays & u8Val) if (RecipientEntry->ValidDays & u8Val)
bitstring_set_bit(&bit_string, i, true); bitstring_set_bit(&bit_string, i, true);
else else
bitstring_set_bit(&bit_string, i, false); bitstring_set_bit(&bit_string, i, false);
u8Val <<= 1; /* next day */ u8Val <<= 1; /* next day */
} }
apdu_len += encode_application_bitstring(&apdu[apdu_len],&bit_string); apdu_len +=
encode_application_bitstring(&apdu[apdu_len],
&bit_string);
/* From Time */ /* From Time */
apdu_len += encode_application_time(&apdu[apdu_len], apdu_len +=
&RecipientEntry->FromTime); encode_application_time(&apdu[apdu_len],
&RecipientEntry->FromTime);
/* To Time */ /* To Time */
apdu_len += encode_application_time(&apdu[apdu_len], apdu_len +=
&RecipientEntry->ToTime); encode_application_time(&apdu[apdu_len],
&RecipientEntry->ToTime);
/* /*
BACnetRecipient ::= CHOICE { BACnetRecipient ::= CHOICE {
device [0] BACnetObjectIdentifier, device [0] BACnetObjectIdentifier,
address [1] BACnetAddress address [1] BACnetAddress
} */ } */
/* CHOICE - device [0] BACnetObjectIdentifier */ /* CHOICE - device [0] BACnetObjectIdentifier */
if (RecipientEntry->Recipient.RecipientType == RECIPIENT_TYPE_DEVICE) if (RecipientEntry->Recipient.RecipientType ==
{ RECIPIENT_TYPE_DEVICE) {
apdu_len += encode_context_object_id(&apdu[apdu_len], 0, OBJECT_DEVICE, apdu_len +=
RecipientEntry->Recipient._.DeviceIdentifier); encode_context_object_id(&apdu[apdu_len], 0,
OBJECT_DEVICE,
RecipientEntry->Recipient._.DeviceIdentifier);
} }
/* CHOICE - address [1] BACnetAddress */ /* CHOICE - address [1] BACnetAddress */
else if (RecipientEntry->Recipient.RecipientType == RECIPIENT_TYPE_ADDRESS) else if (RecipientEntry->Recipient.RecipientType ==
{ RECIPIENT_TYPE_ADDRESS) {
/* opening tag 1 */ /* opening tag 1 */
apdu_len += encode_opening_tag(&apdu[apdu_len], 1); apdu_len += encode_opening_tag(&apdu[apdu_len], 1);
/* network-number Unsigned16, */ /* network-number Unsigned16, */
apdu_len += encode_application_unsigned(&apdu[apdu_len], apdu_len +=
RecipientEntry->Recipient._.Address.net); encode_application_unsigned(&apdu[apdu_len],
RecipientEntry->Recipient._.Address.net);
/* mac-address OCTET STRING */ /* mac-address OCTET STRING */
if (RecipientEntry->Recipient._.Address.net) if (RecipientEntry->Recipient._.Address.net) {
{
octetstring_init(&octet_string, octetstring_init(&octet_string,
RecipientEntry->Recipient._.Address.adr, RecipientEntry->Recipient._.Address.adr,
RecipientEntry->Recipient._.Address.len); RecipientEntry->Recipient._.Address.len);
} } else {
else
{
octetstring_init(&octet_string, octetstring_init(&octet_string,
RecipientEntry->Recipient._.Address.mac, RecipientEntry->Recipient._.Address.mac,
RecipientEntry->Recipient._.Address.mac_len); RecipientEntry->Recipient._.Address.mac_len);
} }
apdu_len += encode_application_octet_string(&apdu[apdu_len], &octet_string); apdu_len +=
encode_application_octet_string(&apdu[apdu_len],
&octet_string);
/* closing tag 1 */ /* closing tag 1 */
apdu_len += encode_closing_tag(&apdu[apdu_len], 1); apdu_len += encode_closing_tag(&apdu[apdu_len], 1);
} } else {;
else {;} /* shouldn't happen */ } /* shouldn't happen */
/* Process Identifier - Unsigned32 */ /* Process Identifier - Unsigned32 */
apdu_len += encode_application_unsigned(&apdu[apdu_len], apdu_len +=
RecipientEntry->ProcessIdentifier); encode_application_unsigned(&apdu[apdu_len],
RecipientEntry->ProcessIdentifier);
/* Issue Confirmed Notifications - boolean */ /* Issue Confirmed Notifications - boolean */
apdu_len += encode_application_boolean(&apdu[apdu_len], apdu_len +=
RecipientEntry->ConfirmedNotify); encode_application_boolean(&apdu[apdu_len],
RecipientEntry->ConfirmedNotify);
/* Transitions - BACnet Event Transition Bits [bitstring] */ /* Transitions - BACnet Event Transition Bits [bitstring] */
u8Val = RecipientEntry->Transitions; u8Val = RecipientEntry->Transitions;
bitstring_init(&bit_string); bitstring_init(&bit_string);
bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL, bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL,
(u8Val & TRANSITION_TO_OFFNORMAL_MASKED) ? true : false ); (u8Val & TRANSITION_TO_OFFNORMAL_MASKED) ? true :
false);
bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT, bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT,
(u8Val & TRANSITION_TO_FAULT_MASKED ) ? true : false ); (u8Val & TRANSITION_TO_FAULT_MASKED) ? true : false);
bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL, bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL,
(u8Val & TRANSITION_TO_NORMAL_MASKED ) ? true : false ); (u8Val & TRANSITION_TO_NORMAL_MASKED) ? true : false);
apdu_len += encode_application_bitstring(&apdu[apdu_len], &bit_string); apdu_len +=
encode_application_bitstring(&apdu[apdu_len],
&bit_string);
} }
} }
break; break;
default: default:
rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_class = ERROR_CLASS_PROPERTY;
rpdata->error_code = ERROR_CODE_UNKNOWN_PROPERTY; rpdata->error_code = ERROR_CODE_UNKNOWN_PROPERTY;
apdu_len = -1; apdu_len = -1;
break; break;
} }
/* only array properties can have array options */ /* only array properties can have array options */
if ((apdu_len >= 0) && (rpdata->object_property != PROP_PRIORITY) && if ((apdu_len >= 0) && (rpdata->object_property != PROP_PRIORITY) &&
(rpdata->array_index != BACNET_ARRAY_ALL)) (rpdata->array_index != BACNET_ARRAY_ALL)) {
{
rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_class = ERROR_CLASS_PROPERTY;
rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
apdu_len = BACNET_STATUS_ERROR; apdu_len = BACNET_STATUS_ERROR;
} }
@@ -380,7 +390,7 @@ int Notification_Class_Read_Property(
bool Notification_Class_Write_Property( bool Notification_Class_Write_Property(
BACNET_WRITE_PROPERTY_DATA * wp_data) BACNET_WRITE_PROPERTY_DATA * wp_data)
{ {
NOTIFICATION_CLASS_INFO *CurrentNotify; NOTIFICATION_CLASS_INFO *CurrentNotify;
NOTIFICATION_CLASS_INFO TmpNotify; NOTIFICATION_CLASS_INFO TmpNotify;
@@ -392,15 +402,17 @@ bool Notification_Class_Write_Property(
CurrentNotify = &NC_Info[Notification_Class_Instance_To_Index(wp_data->object_instance)]; CurrentNotify =
&NC_Info[Notification_Class_Instance_To_Index(wp_data->
object_instance)];
/* decode the some of the request /* decode the some of the request
*/ */
len = bacapp_decode_application_data(wp_data->application_data, len =
wp_data->application_data_len, &value); bacapp_decode_application_data(wp_data->application_data,
wp_data->application_data_len, &value);
switch (wp_data->object_property) switch (wp_data->object_property) {
{
case PROP_PRIORITY: case PROP_PRIORITY:
status = status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT,
@@ -408,19 +420,16 @@ bool Notification_Class_Write_Property(
if (status) { if (status) {
if (wp_data->array_index == 0) { if (wp_data->array_index == 0) {
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; wp_data->error_code = ERROR_CODE_INVALID_ARRAY_INDEX;
} } else if (wp_data->array_index == BACNET_ARRAY_ALL) {
else if (wp_data->array_index == BACNET_ARRAY_ALL) {
/* FIXME: wite all array */ /* FIXME: wite all array */
} } else if (wp_data->array_index <= 3) {
else if (wp_data->array_index <= 3) {
CurrentNotify->Priority[wp_data->array_index - 1] = CurrentNotify->Priority[wp_data->array_index - 1] =
value.type.Unsigned_Int; value.type.Unsigned_Int;
} } else {
else { wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_INVALID_ARRAY_INDEX;
wp_data->error_code = ERROR_CODE_INVALID_ARRAY_INDEX;
} }
} }
break; break;
@@ -432,12 +441,11 @@ bool Notification_Class_Write_Property(
if (status) { if (status) {
if (value.type.Bit_String.bits_used == 3) { if (value.type.Bit_String.bits_used == 3) {
CurrentNotify->Ack_Required = CurrentNotify->Ack_Required =
value.type.Bit_String.value[0]; value.type.Bit_String.value[0];
} } else {
else { wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
} }
} }
break; break;
@@ -447,39 +455,42 @@ bool Notification_Class_Write_Property(
memset(&TmpNotify, 0x00, sizeof(NOTIFICATION_CLASS_INFO)); memset(&TmpNotify, 0x00, sizeof(NOTIFICATION_CLASS_INFO));
/* decode all packed */ /* decode all packed */
while (iOffset < wp_data->application_data_len) while (iOffset < wp_data->application_data_len) {
{
/* Decode Valid Days */ /* Decode Valid Days */
len = bacapp_decode_application_data( len =
&wp_data->application_data[iOffset], bacapp_decode_application_data(&wp_data->
wp_data->application_data_len, &value); application_data[iOffset], wp_data->application_data_len,
&value);
if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_BIT_STRING)) { if ((len == 0) ||
(value.tag != BACNET_APPLICATION_TAG_BIT_STRING)) {
/* Bad decode, wrong tag or following required parameter missing */ /* Bad decode, wrong tag or following required parameter missing */
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE;
return false; return false;
} }
if (value.type.Bit_String.bits_used == MAX_BACNET_DAYS_OF_WEEK) if (value.type.Bit_String.bits_used == MAX_BACNET_DAYS_OF_WEEK)
/* store value */ /* store value */
TmpNotify.Recipient_List[idx].ValidDays = value.type.Bit_String.value[0]; TmpNotify.Recipient_List[idx].ValidDays =
value.type.Bit_String.value[0];
else { else {
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_OTHER; wp_data->error_code = ERROR_CODE_OTHER;
return false; return false;
} }
iOffset += len; iOffset += len;
/* Decode From Time */ /* Decode From Time */
len = bacapp_decode_application_data( len =
&wp_data->application_data[iOffset], bacapp_decode_application_data(&wp_data->
wp_data->application_data_len, &value); application_data[iOffset], wp_data->application_data_len,
&value);
if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_TIME)) { if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_TIME)) {
/* Bad decode, wrong tag or following required parameter missing */ /* Bad decode, wrong tag or following required parameter missing */
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE;
return false; return false;
} }
/* store value */ /* store value */
@@ -487,14 +498,15 @@ bool Notification_Class_Write_Property(
iOffset += len; iOffset += len;
/* Decode To Time */ /* Decode To Time */
len = bacapp_decode_application_data( len =
&wp_data->application_data[iOffset], bacapp_decode_application_data(&wp_data->
wp_data->application_data_len, &value); application_data[iOffset], wp_data->application_data_len,
&value);
if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_TIME)) { if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_TIME)) {
/* Bad decode, wrong tag or following required parameter missing */ /* Bad decode, wrong tag or following required parameter missing */
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE;
return false; return false;
} }
/* store value */ /* store value */
@@ -502,140 +514,159 @@ bool Notification_Class_Write_Property(
iOffset += len; iOffset += len;
/* context tag [0] - Device */ /* context tag [0] - Device */
if (decode_is_context_tag(&wp_data->application_data[iOffset], 0)) if (decode_is_context_tag(&wp_data->application_data[iOffset],
{ 0)) {
TmpNotify.Recipient_List[idx].Recipient.RecipientType = RECIPIENT_TYPE_DEVICE; TmpNotify.Recipient_List[idx].Recipient.RecipientType =
RECIPIENT_TYPE_DEVICE;
/* Decode Network Number */ /* Decode Network Number */
len = bacapp_decode_context_data( len =
&wp_data->application_data[iOffset], bacapp_decode_context_data(&wp_data->
wp_data->application_data_len, &value, application_data[iOffset],
PROP_RECIPIENT_LIST); wp_data->application_data_len, &value,
PROP_RECIPIENT_LIST);
if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_OBJECT_ID)) { if ((len == 0) ||
(value.tag != BACNET_APPLICATION_TAG_OBJECT_ID)) {
/* Bad decode, wrong tag or following required parameter missing */ /* Bad decode, wrong tag or following required parameter missing */
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE;
return false; return false;
} }
/* store value */ /* store value */
TmpNotify.Recipient_List[idx].Recipient._.DeviceIdentifier = TmpNotify.Recipient_List[idx].Recipient._.
value.type.Object_Id.instance; DeviceIdentifier = value.type.Object_Id.instance;
iOffset += len; iOffset += len;
} }
/* opening tag [1] - Recipient */ /* opening tag [1] - Recipient */
else if (decode_is_opening_tag_number(&wp_data->application_data[iOffset], 1)) else if (decode_is_opening_tag_number(&wp_data->
{ application_data[iOffset], 1)) {
iOffset++; iOffset++;
TmpNotify.Recipient_List[idx].Recipient.RecipientType = RECIPIENT_TYPE_ADDRESS; TmpNotify.Recipient_List[idx].Recipient.RecipientType =
RECIPIENT_TYPE_ADDRESS;
/* Decode Network Number */ /* Decode Network Number */
len = bacapp_decode_application_data( len =
&wp_data->application_data[iOffset], bacapp_decode_application_data(&wp_data->
wp_data->application_data_len, &value); application_data[iOffset],
wp_data->application_data_len, &value);
if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_UNSIGNED_INT)) { if ((len == 0) ||
(value.tag != BACNET_APPLICATION_TAG_UNSIGNED_INT)) {
/* Bad decode, wrong tag or following required parameter missing */ /* Bad decode, wrong tag or following required parameter missing */
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE;
return false; return false;
} }
/* store value */ /* store value */
TmpNotify.Recipient_List[idx].Recipient._.Address.net = value.type.Unsigned_Int; TmpNotify.Recipient_List[idx].Recipient._.Address.net =
value.type.Unsigned_Int;
iOffset += len; iOffset += len;
/* Decode Address */ /* Decode Address */
len = bacapp_decode_application_data( len =
&wp_data->application_data[iOffset], bacapp_decode_application_data(&wp_data->
wp_data->application_data_len, &value); application_data[iOffset],
wp_data->application_data_len, &value);
if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_OCTET_STRING)) { if ((len == 0) ||
(value.tag != BACNET_APPLICATION_TAG_OCTET_STRING)) {
/* Bad decode, wrong tag or following required parameter missing */ /* Bad decode, wrong tag or following required parameter missing */
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE;
return false; return false;
} }
/* store value */ /* store value */
if (TmpNotify.Recipient_List[idx].Recipient._.Address.net == 0) { if (TmpNotify.Recipient_List[idx].Recipient._.Address.
memcpy(TmpNotify.Recipient_List[idx].Recipient._.Address.mac, net == 0) {
value.type.Octet_String.value, memcpy(TmpNotify.Recipient_List[idx].Recipient._.
value.type.Octet_String.length); Address.mac, value.type.Octet_String.value,
TmpNotify.Recipient_List[idx].Recipient._.Address.mac_len = value.type.Octet_String.length);
value.type.Octet_String.length; TmpNotify.Recipient_List[idx].Recipient._.Address.
} mac_len = value.type.Octet_String.length;
else { } else {
memcpy(TmpNotify.Recipient_List[idx].Recipient._.Address.adr, memcpy(TmpNotify.Recipient_List[idx].Recipient._.
value.type.Octet_String.value, Address.adr, value.type.Octet_String.value,
value.type.Octet_String.length); value.type.Octet_String.length);
TmpNotify.Recipient_List[idx].Recipient._.Address.len = TmpNotify.Recipient_List[idx].Recipient._.Address.len =
value.type.Octet_String.length; value.type.Octet_String.length;
} }
iOffset += len; iOffset += len;
/* closing tag [1] - Recipient */ /* closing tag [1] - Recipient */
if (decode_is_closing_tag_number(&wp_data->application_data[iOffset], 1)) if (decode_is_closing_tag_number(&wp_data->
application_data[iOffset], 1))
iOffset++; iOffset++;
else { else {
/* Bad decode, wrong tag or following required parameter missing */ /* Bad decode, wrong tag or following required parameter missing */
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE;
return false; return false;
} }
} } else {
else {
/* Bad decode, wrong tag or following required parameter missing */ /* Bad decode, wrong tag or following required parameter missing */
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE;
return false; return false;
} }
/* Process Identifier */ /* Process Identifier */
len = bacapp_decode_application_data( len =
&wp_data->application_data[iOffset], bacapp_decode_application_data(&wp_data->
wp_data->application_data_len, &value); application_data[iOffset], wp_data->application_data_len,
&value);
if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_UNSIGNED_INT)) { if ((len == 0) ||
(value.tag != BACNET_APPLICATION_TAG_UNSIGNED_INT)) {
/* Bad decode, wrong tag or following required parameter missing */ /* Bad decode, wrong tag or following required parameter missing */
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE;
return false; return false;
} }
/* store value */ /* store value */
TmpNotify.Recipient_List[idx].ProcessIdentifier = value.type.Unsigned_Int; TmpNotify.Recipient_List[idx].ProcessIdentifier =
value.type.Unsigned_Int;
iOffset += len; iOffset += len;
/* Issue Confirmed Notifications */ /* Issue Confirmed Notifications */
len = bacapp_decode_application_data( len =
&wp_data->application_data[iOffset], bacapp_decode_application_data(&wp_data->
wp_data->application_data_len, &value); application_data[iOffset], wp_data->application_data_len,
&value);
if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_BOOLEAN)) { if ((len == 0) ||
(value.tag != BACNET_APPLICATION_TAG_BOOLEAN)) {
/* Bad decode, wrong tag or following required parameter missing */ /* Bad decode, wrong tag or following required parameter missing */
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE;
return false; return false;
} }
/* store value */ /* store value */
TmpNotify.Recipient_List[idx].ConfirmedNotify = value.type.Boolean; TmpNotify.Recipient_List[idx].ConfirmedNotify =
value.type.Boolean;
iOffset += len; iOffset += len;
/* Transitions */ /* Transitions */
len = bacapp_decode_application_data( len =
&wp_data->application_data[iOffset], bacapp_decode_application_data(&wp_data->
wp_data->application_data_len, &value); application_data[iOffset], wp_data->application_data_len,
&value);
if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_BIT_STRING)) { if ((len == 0) ||
(value.tag != BACNET_APPLICATION_TAG_BIT_STRING)) {
/* Bad decode, wrong tag or following required parameter missing */ /* Bad decode, wrong tag or following required parameter missing */
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE;
return false; return false;
} }
if (value.type.Bit_String.bits_used == MAX_BACNET_EVENT_TRANSITION) if (value.type.Bit_String.bits_used ==
MAX_BACNET_EVENT_TRANSITION)
/* store value */ /* store value */
TmpNotify.Recipient_List[idx].Transitions = value.type.Bit_String.value[0]; TmpNotify.Recipient_List[idx].Transitions =
value.type.Bit_String.value[0];
else { else {
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_OTHER; wp_data->error_code = ERROR_CODE_OTHER;
return false; return false;
} }
iOffset += len; iOffset += len;
@@ -643,28 +674,32 @@ bool Notification_Class_Write_Property(
/* Increasing element of list */ /* Increasing element of list */
if (++idx >= NC_MAX_RECIPIENTS) { if (++idx >= NC_MAX_RECIPIENTS) {
wp_data->error_class = ERROR_CLASS_RESOURCES; wp_data->error_class = ERROR_CLASS_RESOURCES;
wp_data->error_code = ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY; wp_data->error_code =
ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY;
return false; return false;
} }
} }
/* Decoded all recipient list */ /* Decoded all recipient list */
/* copy elements from temporary object */ /* copy elements from temporary object */
for (idx = 0; idx < NC_MAX_RECIPIENTS; idx++) for (idx = 0; idx < NC_MAX_RECIPIENTS; idx++) {
{ BACNET_ADDRESS src = { 0 };
BACNET_ADDRESS src = {0}; unsigned max_apdu = 0;
unsigned max_apdu = 0; int32_t DeviceID;
int32_t DeviceID;
CurrentNotify->Recipient_List[idx] = TmpNotify.Recipient_List[idx]; CurrentNotify->Recipient_List[idx] =
TmpNotify.Recipient_List[idx];
if (CurrentNotify->Recipient_List[idx].Recipient.RecipientType == RECIPIENT_TYPE_DEVICE) { if (CurrentNotify->Recipient_List[idx].Recipient.
RecipientType == RECIPIENT_TYPE_DEVICE) {
/* copy Device_ID */ /* copy Device_ID */
DeviceID = CurrentNotify->Recipient_List[idx].Recipient._.DeviceIdentifier; DeviceID =
CurrentNotify->Recipient_List[idx].Recipient._.
DeviceIdentifier;
address_bind_request(DeviceID, &max_apdu, &src); address_bind_request(DeviceID, &max_apdu, &src);
} } else if (CurrentNotify->Recipient_List[idx].Recipient.
else if (CurrentNotify->Recipient_List[idx].Recipient.RecipientType == RECIPIENT_TYPE_ADDRESS) { RecipientType == RECIPIENT_TYPE_ADDRESS) {
/* copy Address */ /* copy Address */
/* src = CurrentNotify->Recipient_List[idx].Recipient._.Address; */ /* src = CurrentNotify->Recipient_List[idx].Recipient._.Address; */
/* address_bind_request(BACNET_MAX_INSTANCE, &max_apdu, &src); */ /* address_bind_request(BACNET_MAX_INSTANCE, &max_apdu, &src); */
@@ -673,11 +708,11 @@ bool Notification_Class_Write_Property(
status = true; status = true;
break; break;
default: default:
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_UNKNOWN_PROPERTY; wp_data->error_code = ERROR_CODE_UNKNOWN_PROPERTY;
break; break;
} }
@@ -686,7 +721,8 @@ bool Notification_Class_Write_Property(
void Notification_Class_Get_Priorities( void Notification_Class_Get_Priorities(
uint32_t Object_Instance, uint32_t *pPriorityArray) uint32_t Object_Instance,
uint32_t * pPriorityArray)
{ {
NOTIFICATION_CLASS_INFO *CurrentNotify; NOTIFICATION_CLASS_INFO *CurrentNotify;
uint32_t object_index; uint32_t object_index;
@@ -707,13 +743,14 @@ void Notification_Class_Get_Priorities(
} }
static bool IsRecipientActive(BACNET_DESTINATION * pBacDest, uint8_t EventToState) static bool IsRecipientActive(
BACNET_DESTINATION * pBacDest,
uint8_t EventToState)
{ {
BACNET_DATE_TIME DateTime; BACNET_DATE_TIME DateTime;
/* valid Transitions */ /* valid Transitions */
switch (EventToState) switch (EventToState) {
{
case EVENT_STATE_OFFNORMAL: case EVENT_STATE_OFFNORMAL:
case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_HIGH_LIMIT:
case EVENT_STATE_LOW_LIMIT: case EVENT_STATE_LOW_LIMIT:
@@ -732,7 +769,7 @@ static bool IsRecipientActive(BACNET_DESTINATION * pBacDest, uint8_t EventToStat
break; break;
default: default:
return false; /* shouldn't happen */ return false; /* shouldn't happen */
} }
/* get actual date and time */ /* get actual date and time */
@@ -755,7 +792,7 @@ static bool IsRecipientActive(BACNET_DESTINATION * pBacDest, uint8_t EventToStat
void Notification_Class_common_reporting_function( void Notification_Class_common_reporting_function(
BACNET_EVENT_NOTIFICATION_DATA * event_data) BACNET_EVENT_NOTIFICATION_DATA * event_data)
{ {
/* Fill the parameters common for all types of events. */ /* Fill the parameters common for all types of events. */
@@ -765,8 +802,8 @@ void Notification_Class_common_reporting_function(
uint8_t index; uint8_t index;
notify_index = Notification_Class_Instance_To_Index( notify_index =
event_data->notificationClass); Notification_Class_Instance_To_Index(event_data->notificationClass);
if (notify_index < MAX_NOTIFICATION_CLASSES) if (notify_index < MAX_NOTIFICATION_CLASSES)
CurrentNotify = &NC_Info[notify_index]; CurrentNotify = &NC_Info[notify_index];
@@ -777,49 +814,47 @@ void Notification_Class_common_reporting_function(
/* Initiating Device Identifier */ /* Initiating Device Identifier */
event_data->initiatingObjectIdentifier.type = OBJECT_DEVICE; event_data->initiatingObjectIdentifier.type = OBJECT_DEVICE;
event_data->initiatingObjectIdentifier.instance = event_data->initiatingObjectIdentifier.instance =
Device_Object_Instance_Number(); Device_Object_Instance_Number();
/* Priority and AckRequired*/ /* Priority and AckRequired */
switch (event_data->toState) switch (event_data->toState) {
{
case EVENT_STATE_NORMAL: case EVENT_STATE_NORMAL:
event_data->priority = event_data->priority = CurrentNotify->Priority[EVENT_STATE_NORMAL];
CurrentNotify->Priority[EVENT_STATE_NORMAL]; event_data->ackRequired =
event_data->ackRequired = (CurrentNotify->Ack_Required & (CurrentNotify->
TRANSITION_TO_NORMAL_MASKED) ? true : false; Ack_Required & TRANSITION_TO_NORMAL_MASKED) ? true : false;
break; break;
case EVENT_STATE_FAULT: case EVENT_STATE_FAULT:
event_data->priority = event_data->priority = CurrentNotify->Priority[EVENT_STATE_FAULT];
CurrentNotify->Priority[EVENT_STATE_FAULT]; event_data->ackRequired =
event_data->ackRequired = (CurrentNotify->Ack_Required & (CurrentNotify->
TRANSITION_TO_FAULT_MASKED) ? true : false; Ack_Required & TRANSITION_TO_FAULT_MASKED) ? true : false;
break; break;
case EVENT_STATE_OFFNORMAL: case EVENT_STATE_OFFNORMAL:
case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_HIGH_LIMIT:
case EVENT_STATE_LOW_LIMIT: case EVENT_STATE_LOW_LIMIT:
event_data->priority = event_data->priority =
CurrentNotify->Priority[EVENT_STATE_OFFNORMAL]; CurrentNotify->Priority[EVENT_STATE_OFFNORMAL];
event_data->ackRequired = (CurrentNotify->Ack_Required & event_data->ackRequired =
TRANSITION_TO_OFFNORMAL_MASKED) ? true : false; (CurrentNotify->
Ack_Required & TRANSITION_TO_OFFNORMAL_MASKED) ? true : false;
break; break;
default: /* shouldn't happen */ default: /* shouldn't happen */
break; break;
} }
/* send notifications for active recipients */ /* send notifications for active recipients */
/* pointer to first recipient */ /* pointer to first recipient */
pBacDest = &CurrentNotify->Recipient_List[0]; pBacDest = &CurrentNotify->Recipient_List[0];
for (index = 0; index < NC_MAX_RECIPIENTS; index++, pBacDest++) for (index = 0; index < NC_MAX_RECIPIENTS; index++, pBacDest++) {
{
/* check if recipient is defined */ /* check if recipient is defined */
if (pBacDest->Recipient.RecipientType == RECIPIENT_TYPE_NOTINITIALIZED) if (pBacDest->Recipient.RecipientType == RECIPIENT_TYPE_NOTINITIALIZED)
break; /* recipient doesn't defined - end of list */ break; /* recipient doesn't defined - end of list */
if (IsRecipientActive(pBacDest, event_data->toState) == true) if (IsRecipientActive(pBacDest, event_data->toState) == true) {
{
BACNET_ADDRESS dest; BACNET_ADDRESS dest;
uint32_t device_id; uint32_t device_id;
unsigned max_apdu; unsigned max_apdu;
@@ -835,17 +870,18 @@ void Notification_Class_common_reporting_function(
if (pBacDest->ConfirmedNotify == true) if (pBacDest->ConfirmedNotify == true)
Send_CEvent_Notify(device_id, event_data); Send_CEvent_Notify(device_id, event_data);
else if (address_get_by_device(device_id, &max_apdu, &dest)) else if (address_get_by_device(device_id, &max_apdu, &dest))
Send_UEvent_Notify(Handler_Transmit_Buffer, event_data, &dest); Send_UEvent_Notify(Handler_Transmit_Buffer, event_data,
} &dest);
else if (pBacDest->Recipient.RecipientType == RECIPIENT_TYPE_ADDRESS) { } else if (pBacDest->Recipient.RecipientType ==
RECIPIENT_TYPE_ADDRESS) {
/* send notification to the address indicated */ /* send notification to the address indicated */
if (pBacDest->ConfirmedNotify == true) { if (pBacDest->ConfirmedNotify == true) {
if (address_get_device_id(&dest, &device_id)) if (address_get_device_id(&dest, &device_id))
Send_CEvent_Notify(device_id, event_data); Send_CEvent_Notify(device_id, event_data);
} } else {
else {
dest = pBacDest->Recipient._.Address; dest = pBacDest->Recipient._.Address;
Send_UEvent_Notify(Handler_Transmit_Buffer, event_data, &dest); Send_UEvent_Notify(Handler_Transmit_Buffer, event_data,
&dest);
} }
} }
} }
@@ -854,33 +890,37 @@ void Notification_Class_common_reporting_function(
/* This function tries to find the addresses of the defined devices. */ /* This function tries to find the addresses of the defined devices. */
/* It should be called periodically (example once per minute). */ /* It should be called periodically (example once per minute). */
void Notification_Class_find_recipient(void) void Notification_Class_find_recipient(
void)
{ {
NOTIFICATION_CLASS_INFO *CurrentNotify; NOTIFICATION_CLASS_INFO *CurrentNotify;
BACNET_DESTINATION *pBacDest; BACNET_DESTINATION *pBacDest;
BACNET_ADDRESS src = {0}; BACNET_ADDRESS src = { 0 };
unsigned max_apdu = 0; unsigned max_apdu = 0;
uint32_t notify_index; uint32_t notify_index;
uint32_t DeviceID; uint32_t DeviceID;
uint8_t idx; uint8_t idx;
for (notify_index = 0; notify_index < MAX_NOTIFICATION_CLASSES; notify_index++) for (notify_index = 0; notify_index < MAX_NOTIFICATION_CLASSES;
{ notify_index++) {
/* pointer to current notification */ /* pointer to current notification */
CurrentNotify = &NC_Info[Notification_Class_Instance_To_Index(notify_index)]; CurrentNotify =
&NC_Info[Notification_Class_Instance_To_Index(notify_index)];
/* pointer to first recipient */ /* pointer to first recipient */
pBacDest = &CurrentNotify->Recipient_List[0]; pBacDest = &CurrentNotify->Recipient_List[0];
for (idx = 0; idx < NC_MAX_RECIPIENTS; idx++, pBacDest++) for (idx = 0; idx < NC_MAX_RECIPIENTS; idx++, pBacDest++) {
{ if (CurrentNotify->Recipient_List[idx].Recipient.RecipientType ==
if (CurrentNotify->Recipient_List[idx].Recipient.RecipientType == RECIPIENT_TYPE_DEVICE) { RECIPIENT_TYPE_DEVICE) {
/* Device ID */ /* Device ID */
DeviceID = CurrentNotify->Recipient_List[idx].Recipient._.DeviceIdentifier; DeviceID =
CurrentNotify->Recipient_List[idx].Recipient._.
DeviceIdentifier;
/* Send who_ is request only when address of device is unknown. */ /* Send who_ is request only when address of device is unknown. */
if (!address_bind_request(DeviceID, &max_apdu, &src)) if (!address_bind_request(DeviceID, &max_apdu, &src))
Send_WhoIs(DeviceID, DeviceID); Send_WhoIs(DeviceID, DeviceID);
} } else if (CurrentNotify->Recipient_List[idx].Recipient.
else if (CurrentNotify->Recipient_List[idx].Recipient.RecipientType == RECIPIENT_TYPE_ADDRESS) { RecipientType == RECIPIENT_TYPE_ADDRESS) {
} }
} }
+51 -48
View File
@@ -38,11 +38,11 @@ extern "C" {
/* max "length" of recipient_list */ /* max "length" of recipient_list */
#define NC_MAX_RECIPIENTS 10 #define NC_MAX_RECIPIENTS 10
/* Recipient types */ /* Recipient types */
typedef enum { typedef enum {
RECIPIENT_TYPE_NOTINITIALIZED = 0, RECIPIENT_TYPE_NOTINITIALIZED = 0,
RECIPIENT_TYPE_DEVICE = 1, RECIPIENT_TYPE_DEVICE = 1,
RECIPIENT_TYPE_ADDRESS = 2 RECIPIENT_TYPE_ADDRESS = 2
} NC_RECIPIENT_TYPE; } NC_RECIPIENT_TYPE;
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
@@ -53,47 +53,47 @@ BACnetRecipient ::= CHOICE {
address [1] BACnetAddress address [1] BACnetAddress
} }
*/ */
typedef struct BACnet_Recipient { typedef struct BACnet_Recipient {
uint8_t RecipientType; /* Type of Recipient */ uint8_t RecipientType; /* Type of Recipient */
union { union {
uint32_t DeviceIdentifier; uint32_t DeviceIdentifier;
BACNET_ADDRESS Address; BACNET_ADDRESS Address;
} _; } _;
} BACNET_RECIPIENT; } BACNET_RECIPIENT;
/* BACnetDestination structure */ /* BACnetDestination structure */
typedef struct BACnet_Destination { typedef struct BACnet_Destination {
uint8_t ValidDays; uint8_t ValidDays;
BACNET_TIME FromTime; BACNET_TIME FromTime;
BACNET_TIME ToTime; BACNET_TIME ToTime;
BACNET_RECIPIENT Recipient; BACNET_RECIPIENT Recipient;
uint32_t ProcessIdentifier; uint32_t ProcessIdentifier;
uint8_t Transitions; uint8_t Transitions;
bool ConfirmedNotify; bool ConfirmedNotify;
} BACNET_DESTINATION; } BACNET_DESTINATION;
/* Structure containing configuration for a Notification Class */ /* Structure containing configuration for a Notification Class */
typedef struct Notification_Class_info { typedef struct Notification_Class_info {
uint8_t Priority[3]; /* BACnetARRAY[3] of Unsigned */ uint8_t Priority[3]; /* BACnetARRAY[3] of Unsigned */
uint8_t Ack_Required; /* BACnetEventTransitionBits */ uint8_t Ack_Required; /* BACnetEventTransitionBits */
BACNET_DESTINATION Recipient_List[NC_MAX_RECIPIENTS]; /* List of BACnetDestination */ BACNET_DESTINATION Recipient_List[NC_MAX_RECIPIENTS]; /* List of BACnetDestination */
} NOTIFICATION_CLASS_INFO; } NOTIFICATION_CLASS_INFO;
/* Indicates whether the transaction has been confirmed */ /* Indicates whether the transaction has been confirmed */
typedef struct Acked_info { typedef struct Acked_info {
bool bIsAcked; /* true when transitions is acked */ bool bIsAcked; /* true when transitions is acked */
BACNET_DATE_TIME Time_Stamp;/* time stamp of when a alarm was generated */ BACNET_DATE_TIME Time_Stamp; /* time stamp of when a alarm was generated */
} ACKED_INFO; } ACKED_INFO;
/* Information needed to send AckNotification */ /* Information needed to send AckNotification */
typedef struct Ack_Notification { typedef struct Ack_Notification {
bool bSendAckNotify; /* true if need to send AckNotification */ bool bSendAckNotify; /* true if need to send AckNotification */
uint8_t EventState; uint8_t EventState;
} ACK_NOTIFICATION; } ACK_NOTIFICATION;
@@ -102,43 +102,46 @@ typedef struct Ack_Notification {
const int **pOptional, const int **pOptional,
const int **pProprietary); const int **pProprietary);
void Notification_Class_Init(void); void Notification_Class_Init(
void);
bool Notification_Class_Valid_Instance( bool Notification_Class_Valid_Instance(
uint32_t object_instance); uint32_t object_instance);
unsigned Notification_Class_Count(void); unsigned Notification_Class_Count(
uint32_t Notification_Class_Index_To_Instance(unsigned index); void);
uint32_t Notification_Class_Index_To_Instance(
unsigned index);
unsigned Notification_Class_Instance_To_Index( unsigned Notification_Class_Instance_To_Index(
uint32_t object_instance); uint32_t object_instance);
bool Notification_Class_Object_Name( bool Notification_Class_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name); BACNET_CHARACTER_STRING * object_name);
int Notification_Class_Read_Property( int Notification_Class_Read_Property(
BACNET_READ_PROPERTY_DATA * rpdata); BACNET_READ_PROPERTY_DATA * rpdata);
bool Notification_Class_Write_Property( bool Notification_Class_Write_Property(
BACNET_WRITE_PROPERTY_DATA * wp_data); BACNET_WRITE_PROPERTY_DATA * wp_data);
void Notification_Class_Get_Priorities( void Notification_Class_Get_Priorities(
uint32_t Object_Instance, uint32_t *pPriorityArray); uint32_t Object_Instance,
uint32_t * pPriorityArray);
void Notification_Class_common_reporting_function( void Notification_Class_common_reporting_function(
BACNET_EVENT_NOTIFICATION_DATA * event_data); BACNET_EVENT_NOTIFICATION_DATA * event_data);
void Notification_Class_find_recipient(void); void Notification_Class_find_recipient(
void);
#endif /* defined(INTRINSIC_REPORTING) */ #endif /* defined(INTRINSIC_REPORTING) */
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#define NOTIFICATION_CLASS_OBJ_FUNCTIONS \ #define NOTIFICATION_CLASS_OBJ_FUNCTIONS \
OBJECT_NOTIFICATION_CLASS, Notification_Class_Init, Notification_Class_Count, \ OBJECT_NOTIFICATION_CLASS, Notification_Class_Init, Notification_Class_Count, \
Notification_Class_Index_To_Instance, Notification_Class_Valid_Instance, \ Notification_Class_Index_To_Instance, Notification_Class_Valid_Instance, \
Notification_Class_Object_Name, Notification_Class_Read_Property, \ Notification_Class_Object_Name, Notification_Class_Read_Property, \
Notification_Class_Write_Property, Notification_Class_Property_Lists, \ Notification_Class_Write_Property, Notification_Class_Property_Lists, \
NULL, NULL, NULL NULL, NULL, NULL
#endif /* NC_H */ #endif /* NC_H */
+8 -8
View File
@@ -259,7 +259,7 @@ void Trend_Log_Init(
*/ */
bool Trend_Log_Object_Name( bool Trend_Log_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name) BACNET_CHARACTER_STRING * object_name)
{ {
static char text_string[32] = ""; /* okay for single thread */ static char text_string[32] = ""; /* okay for single thread */
bool status = false; bool status = false;
@@ -736,9 +736,9 @@ bool Trend_Log_Write_Property(
if (wp_data->application_data_len != 0) { if (wp_data->application_data_len != 0) {
iOffset += len; iOffset += len;
len = len =
bacapp_decode_context_data(&wp_data-> bacapp_decode_context_data(&wp_data->application_data
application_data[iOffset], wp_data->application_data_len, [iOffset], wp_data->application_data_len, &value,
&value, PROP_LOG_DEVICE_OBJECT_PROPERTY); PROP_LOG_DEVICE_OBJECT_PROPERTY);
if ((len == 0) || ((value.context_tag != 2) && if ((len == 0) || ((value.context_tag != 2) &&
(value.context_tag != 3))) { (value.context_tag != 3))) {
/* Bad decode or wrong tag */ /* Bad decode or wrong tag */
@@ -755,8 +755,8 @@ bool Trend_Log_Write_Property(
if (wp_data->application_data_len != 0) { if (wp_data->application_data_len != 0) {
iOffset += len; iOffset += len;
len = len =
bacapp_decode_context_data(&wp_data-> bacapp_decode_context_data
application_data[iOffset], (&wp_data->application_data[iOffset],
wp_data->application_data_len, &value, wp_data->application_data_len, &value,
PROP_LOG_DEVICE_OBJECT_PROPERTY); PROP_LOG_DEVICE_OBJECT_PROPERTY);
if ((len == 0) || (value.context_tag != 3)) { if ((len == 0) || (value.context_tag != 3)) {
@@ -1098,8 +1098,8 @@ int rr_trend_log_encode(
pRequest->ItemCount = 0; /* Start out with nothing */ pRequest->ItemCount = 0; /* Start out with nothing */
/* Bail out now if nowt - should never happen for a Trend Log but ... */ /* Bail out now if nowt - should never happen for a Trend Log but ... */
if (LogInfo[Trend_Log_Instance_To_Index(pRequest->object_instance)]. if (LogInfo[Trend_Log_Instance_To_Index(pRequest->
ulRecordCount == 0) object_instance)].ulRecordCount == 0)
return (0); return (0);
if ((pRequest->RequestType == RR_BY_POSITION) || if ((pRequest->RequestType == RR_BY_POSITION) ||
+1 -1
View File
@@ -141,7 +141,7 @@ extern "C" {
bool Trend_Log_Object_Name( bool Trend_Log_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name); BACNET_CHARACTER_STRING * object_name);
int Trend_Log_Read_Property( int Trend_Log_Read_Property(
BACNET_READ_PROPERTY_DATA * rpdata); BACNET_READ_PROPERTY_DATA * rpdata);
+1 -1
View File
@@ -70,7 +70,7 @@ uint8_t Send_Private_Transfer_Request(
static object_functions_t Object_Table[] = { static object_functions_t Object_Table[] = {
{DEVICE_OBJ_FUNCTIONS}, {DEVICE_OBJ_FUNCTIONS},
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL} NULL, NULL, NULL, NULL, NULL, NULL}
}; };
/* buffer used for receive */ /* buffer used for receive */
+1 -1
View File
@@ -54,7 +54,7 @@
static object_functions_t Object_Table[] = { static object_functions_t Object_Table[] = {
{DEVICE_OBJ_FUNCTIONS}, {DEVICE_OBJ_FUNCTIONS},
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL} NULL, NULL, NULL, NULL, NULL, NULL}
}; };
/* buffer used for receive */ /* buffer used for receive */
+1 -1
View File
@@ -57,7 +57,7 @@
static object_functions_t Object_Table[] = { static object_functions_t Object_Table[] = {
{DEVICE_OBJ_FUNCTIONS}, {DEVICE_OBJ_FUNCTIONS},
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL} NULL, NULL, NULL, NULL, NULL, NULL}
}; };
/* buffer used for receive */ /* buffer used for receive */
+1 -1
View File
@@ -58,7 +58,7 @@
static object_functions_t Object_Table[] = { static object_functions_t Object_Table[] = {
{DEVICE_OBJ_FUNCTIONS}, {DEVICE_OBJ_FUNCTIONS},
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL} NULL, NULL, NULL, NULL, NULL, NULL}
}; };
/* buffer used for receive */ /* buffer used for receive */
+1 -1
View File
@@ -84,7 +84,7 @@
static object_functions_t Object_Table[] = { static object_functions_t Object_Table[] = {
{DEVICE_OBJ_FUNCTIONS}, {DEVICE_OBJ_FUNCTIONS},
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL} NULL, NULL, NULL, NULL, NULL, NULL}
}; };
/* buffer used for receive */ /* buffer used for receive */
+1 -1
View File
@@ -55,7 +55,7 @@
static object_functions_t Object_Table[] = { static object_functions_t Object_Table[] = {
{DEVICE_OBJ_FUNCTIONS}, {DEVICE_OBJ_FUNCTIONS},
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL} NULL, NULL, NULL, NULL, NULL, NULL}
}; };
/* buffer used for receive */ /* buffer used for receive */
+2 -2
View File
@@ -123,7 +123,7 @@ static void Init_Service_Handlers(
handler_alarm_ack); handler_alarm_ack);
apdu_set_confirmed_handler(SERVICE_CONFIRMED_GET_EVENT_INFORMATION, apdu_set_confirmed_handler(SERVICE_CONFIRMED_GET_EVENT_INFORMATION,
handler_get_event_information); handler_get_event_information);
#endif /* defined(INTRINSIC_REPORTING) */ #endif /* defined(INTRINSIC_REPORTING) */
} }
/** Handler registered with atexit() inside main function to, well, cleanup. /** Handler registered with atexit() inside main function to, well, cleanup.
@@ -156,7 +156,7 @@ int main(
0 0
}; /* address where message came from */ }; /* address where message came from */
uint16_t pdu_len = 0; uint16_t pdu_len = 0;
unsigned timeout = 100; /* milliseconds */ unsigned timeout = 100; /* milliseconds */
time_t last_seconds = 0; time_t last_seconds = 0;
time_t current_seconds = 0; time_t current_seconds = 0;
uint32_t elapsed_seconds = 0; uint32_t elapsed_seconds = 0;
+1 -1
View File
@@ -50,7 +50,7 @@
static object_functions_t Object_Table[] = { static object_functions_t Object_Table[] = {
{DEVICE_OBJ_FUNCTIONS}, {DEVICE_OBJ_FUNCTIONS},
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL} NULL, NULL, NULL, NULL, NULL, NULL}
}; };
/* buffer used for receive */ /* buffer used for receive */
+1 -1
View File
@@ -54,7 +54,7 @@
static object_functions_t Object_Table[] = { static object_functions_t Object_Table[] = {
{DEVICE_OBJ_FUNCTIONS}, {DEVICE_OBJ_FUNCTIONS},
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL} NULL, NULL, NULL, NULL, NULL, NULL}
}; };
static void Init_Service_Handlers( static void Init_Service_Handlers(
+1 -1
View File
@@ -54,7 +54,7 @@
static object_functions_t Object_Table[] = { static object_functions_t Object_Table[] = {
{DEVICE_OBJ_FUNCTIONS}, {DEVICE_OBJ_FUNCTIONS},
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL} NULL, NULL, NULL, NULL, NULL, NULL}
}; };
/* buffer used for receive */ /* buffer used for receive */
+1 -1
View File
@@ -54,7 +54,7 @@
static object_functions_t Object_Table[] = { static object_functions_t Object_Table[] = {
{DEVICE_OBJ_FUNCTIONS}, {DEVICE_OBJ_FUNCTIONS},
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL} NULL, NULL, NULL, NULL, NULL, NULL}
}; };
/* buffer used for receive */ /* buffer used for receive */
+1 -1
View File
@@ -54,7 +54,7 @@
static object_functions_t Object_Table[] = { static object_functions_t Object_Table[] = {
{DEVICE_OBJ_FUNCTIONS}, {DEVICE_OBJ_FUNCTIONS},
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL} NULL, NULL, NULL, NULL, NULL, NULL}
}; };
/* buffer used for receive */ /* buffer used for receive */
+1 -1
View File
@@ -60,7 +60,7 @@
static object_functions_t Object_Table[] = { static object_functions_t Object_Table[] = {
{DEVICE_OBJ_FUNCTIONS}, {DEVICE_OBJ_FUNCTIONS},
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL} NULL, NULL, NULL, NULL, NULL, NULL}
}; };
/* buffer used for receive */ /* buffer used for receive */
+1 -1
View File
@@ -964,7 +964,7 @@ typedef enum {
} BACNET_VT_CLASS; } BACNET_VT_CLASS;
typedef enum { typedef enum {
CHARACTER_ANSI_X34 = 0, /* deprecated */ CHARACTER_ANSI_X34 = 0, /* deprecated */
CHARACTER_UTF8 = 0, CHARACTER_UTF8 = 0,
CHARACTER_MS_DBCS = 1, CHARACTER_MS_DBCS = 1,
CHARACTER_JISC_6226 = 2, CHARACTER_JISC_6226 = 2,
+1 -1
View File
@@ -97,7 +97,7 @@ extern "C" {
uint32_t device_id, uint32_t device_id,
BACNET_OBJECT_TYPE object_type, BACNET_OBJECT_TYPE object_type,
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name); BACNET_CHARACTER_STRING * object_name);
int Send_UCOV_Notify( int Send_UCOV_Notify(
uint8_t * buffer, uint8_t * buffer,
+1 -1
View File
@@ -143,7 +143,7 @@ extern "C" {
* chosen at runtime from among these choices. * chosen at runtime from among these choices.
* - Clause 10 POINT-TO-POINT (PTP) and Clause 11 EIA/CEA-709.1 ("LonTalk") LAN * - Clause 10 POINT-TO-POINT (PTP) and Clause 11 EIA/CEA-709.1 ("LonTalk") LAN
* are not currently supported by this project. * are not currently supported by this project.
*//** @defgroup DLTemplates DataLink Template Functions *//** @defgroup DLTemplates DataLink Template Functions
* @ingroup DataLink * @ingroup DataLink
* Most of the functions in this group are function templates which are assigned * Most of the functions in this group are function templates which are assigned
* to a specific DataLink network layer implementation either at compile time or * to a specific DataLink network layer implementation either at compile time or
+2 -2
View File
@@ -104,7 +104,7 @@ extern "C" {
* *
* The network management BIBBs prescribe the BACnet capabilities required to * The network management BIBBs prescribe the BACnet capabilities required to
* interoperably perform network management functions. * interoperably perform network management functions.
*//** @defgroup DMDCC Device Management-Device Communication Control (DM-DCC) *//** @defgroup DMDCC Device Management-Device Communication Control (DM-DCC)
* @ingroup RDMS * @ingroup RDMS
* 16.1 DeviceCommunicationControl Service <br> * 16.1 DeviceCommunicationControl Service <br>
* The DeviceCommunicationControl service is used by a client BACnet-user to * The DeviceCommunicationControl service is used by a client BACnet-user to
@@ -117,7 +117,7 @@ extern "C" {
* "indefinite," meaning communication must be re-enabled by a * "indefinite," meaning communication must be re-enabled by a
* DeviceCommunicationControl or, if supported, ReinitializeDevice service, * DeviceCommunicationControl or, if supported, ReinitializeDevice service,
* not by time. * not by time.
*//** @defgroup NMRC Network Management-Router Configuration (NM-RC) *//** @defgroup NMRC Network Management-Router Configuration (NM-RC)
* @ingroup RDMS * @ingroup RDMS
* The A device may query and change the configuration of routers and * The A device may query and change the configuration of routers and
* half-routers. * half-routers.
+2 -2
View File
@@ -213,7 +213,7 @@ extern "C" {
* These BIBBs prescribe the BACnet capabilities required to interoperably * These BIBBs prescribe the BACnet capabilities required to interoperably
* perform the alarm and event management functions enumerated in 22.2.1.2 * perform the alarm and event management functions enumerated in 22.2.1.2
* for the BACnet devices defined therein. * for the BACnet devices defined therein.
*//** @defgroup EVNOTFCN Alarm and Event-Notification (AE-N) *//** @defgroup EVNOTFCN Alarm and Event-Notification (AE-N)
* @ingroup ALMEVNT * @ingroup ALMEVNT
* 13.6 ConfirmedCOVNotification Service <br> * 13.6 ConfirmedCOVNotification Service <br>
* The ConfirmedCOVNotification service is used to notify subscribers about * The ConfirmedCOVNotification service is used to notify subscribers about
@@ -230,7 +230,7 @@ extern "C" {
* For unsubscribed notifications, the algorithm for determining when to issue * For unsubscribed notifications, the algorithm for determining when to issue
* this service is a local matter and may be based on a change of value, * this service is a local matter and may be based on a change of value,
* periodic updating, or some other criteria. * periodic updating, or some other criteria.
*//** @defgroup ALMACK Alarm and Event-ACK (AE-ACK) *//** @defgroup ALMACK Alarm and Event-ACK (AE-ACK)
* @ingroup ALMEVNT * @ingroup ALMEVNT
* 13.5 AcknowledgeAlarm Service <br> * 13.5 AcknowledgeAlarm Service <br>
* In some systems a device may need to know that an operator has seen the alarm * In some systems a device may need to know that an operator has seen the alarm
+1 -1
View File
@@ -172,7 +172,7 @@ extern "C" {
* These BIBBs prescribe the BACnet capabilities required to interoperably * These BIBBs prescribe the BACnet capabilities required to interoperably
* perform the trending functions enumerated in clause 22.2.1.4 for the * perform the trending functions enumerated in clause 22.2.1.4 for the
* BACnet devices defined therein. * BACnet devices defined therein.
*//** @defgroup TrendReadRange Trending -Read Range Service (eg, in T-VMT) *//** @defgroup TrendReadRange Trending -Read Range Service (eg, in T-VMT)
* @ingroup Trend * @ingroup Trend
* 15.8 ReadRange Service <br> * 15.8 ReadRange Service <br>
* The ReadRange service is used by a client BACnet-user to read a specific * The ReadRange service is used by a client BACnet-user to read a specific
+1 -1
View File
@@ -135,7 +135,7 @@ extern "C" {
* These BIBBs prescribe the BACnet capabilities required to interoperably * These BIBBs prescribe the BACnet capabilities required to interoperably
* perform the data sharing functions enumerated in 22.2.1.1 for the BACnet * perform the data sharing functions enumerated in 22.2.1.1 for the BACnet
* devices defined therein. * devices defined therein.
*//** @defgroup DSRP Data Sharing -Read Property Service (DS-RP) *//** @defgroup DSRP Data Sharing -Read Property Service (DS-RP)
* @ingroup DataShare * @ingroup DataShare
* 15.5 ReadProperty Service <br> * 15.5 ReadProperty Service <br>
* The ReadProperty service is used by a client BACnet-user to request the * The ReadProperty service is used by a client BACnet-user to request the
+1 -1
View File
@@ -41,7 +41,7 @@
typedef struct BACnet_Who_Has_Data { typedef struct BACnet_Who_Has_Data {
int32_t low_limit; /* deviceInstanceRange */ int32_t low_limit; /* deviceInstanceRange */
int32_t high_limit; int32_t high_limit;
bool is_object_name; /* true if a string */ bool is_object_name; /* true if a string */
union { union {
BACNET_OBJECT_ID identifier; BACNET_OBJECT_ID identifier;
BACNET_CHARACTER_STRING name; BACNET_CHARACTER_STRING name;
+15 -8
View File
@@ -38,19 +38,26 @@ extern "C" {
/* decode the service request only */ /* decode the service request only */
int wpm_decode_object_id(uint8_t * apdu, uint16_t apdu_len, int wpm_decode_object_id(
BACNET_WRITE_PROPERTY_DATA * data); uint8_t * apdu,
uint16_t apdu_len,
BACNET_WRITE_PROPERTY_DATA * data);
int wpm_decode_object_property(uint8_t * apdu, int wpm_decode_object_property(
uint16_t apdu_len, uint8_t * apdu,
BACNET_WRITE_PROPERTY_DATA * wpm_data); uint16_t apdu_len,
BACNET_WRITE_PROPERTY_DATA * wpm_data);
/* encode service */ /* encode service */
int wpm_ack_encode_apdu_init(uint8_t *apdu, uint8_t invoke_id); int wpm_ack_encode_apdu_init(
uint8_t * apdu,
uint8_t invoke_id);
int wpm_error_ack_encode_apdu(uint8_t * apdu, uint8_t invoke_id, int wpm_error_ack_encode_apdu(
BACNET_WRITE_PROPERTY_DATA * wp_data); uint8_t * apdu,
uint8_t invoke_id,
BACNET_WRITE_PROPERTY_DATA * wp_data);
#ifdef __cplusplus #ifdef __cplusplus
+1 -1
View File
@@ -109,7 +109,7 @@ uint32_t Analog_Input_Index_To_Instance(
bool Analog_Input_Object_Name( bool Analog_Input_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name) BACNET_CHARACTER_STRING * object_name)
{ {
static char text_string[16] = "AI-0"; /* okay for single thread */ static char text_string[16] = "AI-0"; /* okay for single thread */
bool status = false; bool status = false;
+3 -3
View File
@@ -167,7 +167,7 @@ float Analog_Value_Present_Value(
bool Analog_Value_Object_Name( bool Analog_Value_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name) BACNET_CHARACTER_STRING * object_name)
{ {
static char text_string[16] = "AV-0"; /* okay for single thread */ static char text_string[16] = "AV-0"; /* okay for single thread */
bool status = false; bool status = false;
@@ -360,8 +360,8 @@ bool Analog_Value_Write_Property(
(value.type.Real >= 0.0) && (value.type.Real <= 100.0)) { (value.type.Real >= 0.0) && (value.type.Real <= 100.0)) {
level = (uint8_t) value.type.Real; level = (uint8_t) value.type.Real;
object_index = object_index =
Analog_Value_Instance_To_Index(wp_data-> Analog_Value_Instance_To_Index
object_instance); (wp_data->object_instance);
priority--; priority--;
Present_Value[object_index] = level; Present_Value[object_index] = level;
/* Note: you could set the physical output here if we /* Note: you could set the physical output here if we
+1 -1
View File
@@ -146,7 +146,7 @@ BACNET_BINARY_PV Binary_Input_Present_Value(
bool Binary_Input_Object_Name( bool Binary_Input_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name) BACNET_CHARACTER_STRING * object_name)
{ {
static char text_string[16] = "BI-0"; /* okay for single thread */ static char text_string[16] = "BI-0"; /* okay for single thread */
bool status = false; bool status = false;
+3 -3
View File
@@ -141,7 +141,7 @@ static BACNET_BINARY_PV Binary_Value_Present_Value(
/* note: the object name must be unique within this device */ /* note: the object name must be unique within this device */
bool Binary_Value_Object_Name( bool Binary_Value_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name) BACNET_CHARACTER_STRING * object_name)
{ {
static char text_string[16] = "BV-0"; /* okay for single thread */ static char text_string[16] = "BV-0"; /* okay for single thread */
bool status = false; bool status = false;
@@ -271,8 +271,8 @@ bool Binary_Value_Write_Property(
(value.type.Enumerated <= MAX_BINARY_PV)) { (value.type.Enumerated <= MAX_BINARY_PV)) {
level = value.type.Enumerated; level = value.type.Enumerated;
object_index = object_index =
Binary_Value_Instance_To_Index(wp_data-> Binary_Value_Instance_To_Index
object_instance); (wp_data->object_instance);
priority--; priority--;
/* NOTE: this Binary value has no priority array */ /* NOTE: this Binary value has no priority array */
Present_Value[object_index] = level; Present_Value[object_index] = level;
+39 -42
View File
@@ -179,8 +179,7 @@ static int Read_Property_Common(
break; break;
case PROP_OBJECT_NAME: case PROP_OBJECT_NAME:
if (pObject->Object_Name) { if (pObject->Object_Name) {
(void)pObject->Object_Name( (void) pObject->Object_Name(rpdata->object_instance,
rpdata->object_instance,
&char_string); &char_string);
} else { } else {
characterstring_init_ansi(&char_string, ""); characterstring_init_ansi(&char_string, "");
@@ -213,13 +212,13 @@ int Device_Read_Property(
/* initialize the default return values */ /* initialize the default return values */
pObject = Device_Objects_Find_Functions(rpdata->object_type); pObject = Device_Objects_Find_Functions(rpdata->object_type);
if (pObject) { if (pObject) {
if (pObject->Object_Valid_Instance && if (pObject->Object_Valid_Instance &&
pObject->Object_Valid_Instance(rpdata->object_instance)) { pObject->Object_Valid_Instance(rpdata->object_instance)) {
apdu_len = Read_Property_Common(pObject, rpdata); apdu_len = Read_Property_Common(pObject, rpdata);
} else { } else {
rpdata->error_class = ERROR_CLASS_OBJECT; rpdata->error_class = ERROR_CLASS_OBJECT;
rpdata->error_code = ERROR_CODE_UNKNOWN_OBJECT; rpdata->error_code = ERROR_CODE_UNKNOWN_OBJECT;
} }
} else { } else {
rpdata->error_class = ERROR_CLASS_OBJECT; rpdata->error_class = ERROR_CLASS_OBJECT;
rpdata->error_code = ERROR_CODE_UNSUPPORTED_OBJECT_TYPE; rpdata->error_code = ERROR_CODE_UNSUPPORTED_OBJECT_TYPE;
@@ -237,18 +236,18 @@ bool Device_Write_Property(
/* initialize the default return values */ /* initialize the default return values */
pObject = Device_Objects_Find_Functions(wp_data->object_type); pObject = Device_Objects_Find_Functions(wp_data->object_type);
if (pObject) { if (pObject) {
if (pObject->Object_Valid_Instance && if (pObject->Object_Valid_Instance &&
pObject->Object_Valid_Instance(wp_data->object_instance)) { pObject->Object_Valid_Instance(wp_data->object_instance)) {
if (pObject->Object_Write_Property) { if (pObject->Object_Write_Property) {
status = pObject->Object_Write_Property(wp_data); status = pObject->Object_Write_Property(wp_data);
} else {
wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
}
} else { } else {
wp_data->error_class = ERROR_CLASS_OBJECT; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_UNKNOWN_OBJECT; wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
} }
} else {
wp_data->error_class = ERROR_CLASS_OBJECT;
wp_data->error_code = ERROR_CODE_UNKNOWN_OBJECT;
}
} else { } else {
wp_data->error_class = ERROR_CLASS_OBJECT; wp_data->error_class = ERROR_CLASS_OBJECT;
wp_data->error_code = ERROR_CODE_UNSUPPORTED_OBJECT_TYPE; wp_data->error_code = ERROR_CODE_UNSUPPORTED_OBJECT_TYPE;
@@ -340,7 +339,7 @@ uint32_t Device_Index_To_Instance(
bool Device_Object_Name( bool Device_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name) BACNET_CHARACTER_STRING * object_name)
{ {
bool status = false; bool status = false;
@@ -352,7 +351,7 @@ bool Device_Object_Name(
} }
bool Device_Set_Object_Name( bool Device_Set_Object_Name(
BACNET_CHARACTER_STRING *object_name) BACNET_CHARACTER_STRING * object_name)
{ {
bool status = false; /*return value */ bool status = false; /*return value */
@@ -394,13 +393,13 @@ BACNET_REINITIALIZED_STATE Device_Reinitialized_State(
} }
void Device_Init( void Device_Init(
object_functions_t * object_table) object_functions_t * object_table)
{ {
struct my_object_functions *pObject = NULL; struct my_object_functions *pObject = NULL;
/* we don't use the object table passed in /* we don't use the object table passed in
since there is extra stuff we don't need in there. */ since there is extra stuff we don't need in there. */
(void)object_table; (void) object_table;
/* our local object table */ /* our local object table */
pObject = &Object_Table[0]; pObject = &Object_Table[0];
while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) { while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) {
@@ -440,7 +439,7 @@ bool Device_Valid_Object_Instance_Number(
/* BACnet allows for a wildcard instance number */ /* BACnet allows for a wildcard instance number */
return ((Object_Instance_Number == object_id) || return ((Object_Instance_Number == object_id) ||
(object_id == BACNET_MAX_INSTANCE)); (object_id == BACNET_MAX_INSTANCE));
} }
BACNET_DEVICE_STATUS Device_System_Status( BACNET_DEVICE_STATUS Device_System_Status(
void) void)
@@ -461,25 +460,25 @@ int Device_Set_System_Status(
} }
return result; return result;
} }
uint16_t Device_Vendor_Identifier( uint16_t Device_Vendor_Identifier(
void) void)
{ {
return BACNET_VENDOR_ID; return BACNET_VENDOR_ID;
} }
BACNET_SEGMENTATION Device_Segmentation_Supported( BACNET_SEGMENTATION Device_Segmentation_Supported(
void) void)
{ {
return SEGMENTATION_NONE; return SEGMENTATION_NONE;
} }
uint32_t Device_Database_Revision( uint32_t Device_Database_Revision(
void) void)
{ {
return Database_Revision; return Database_Revision;
} }
void Device_Inc_Database_Revision( void Device_Inc_Database_Revision(
void) void)
@@ -542,7 +541,7 @@ bool Device_Object_List_Identifier(
} }
bool Device_Valid_Object_Name( bool Device_Valid_Object_Name(
BACNET_CHARACTER_STRING *object_name1, BACNET_CHARACTER_STRING * object_name1,
int *object_type, int *object_type,
uint32_t * object_instance) uint32_t * object_instance)
{ {
@@ -561,7 +560,7 @@ bool Device_Valid_Object_Name(
pObject = Device_Objects_Find_Functions(type); pObject = Device_Objects_Find_Functions(type);
if ((pObject != NULL) && (pObject->Object_Name != NULL) && if ((pObject != NULL) && (pObject->Object_Name != NULL) &&
(pObject->Object_Name(instance, &object_name2) && (pObject->Object_Name(instance, &object_name2) &&
characterstring_same(object_name1, &object_name2))) { characterstring_same(object_name1, &object_name2))) {
found = true; found = true;
if (object_type) { if (object_type) {
*object_type = type; *object_type = type;
@@ -581,7 +580,7 @@ bool Device_Valid_Object_Id(
int object_type, int object_type,
uint32_t object_instance) uint32_t object_instance)
{ {
bool status = false; /* return value */ bool status = false; /* return value */
struct my_object_functions *pObject = NULL; struct my_object_functions *pObject = NULL;
pObject = Device_Objects_Find_Functions(object_type); pObject = Device_Objects_Find_Functions(object_type);
@@ -595,7 +594,7 @@ bool Device_Valid_Object_Id(
bool Device_Object_Name_Copy( bool Device_Object_Name_Copy(
int object_type, int object_type,
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name) BACNET_CHARACTER_STRING * object_name)
{ {
struct my_object_functions *pObject = NULL; struct my_object_functions *pObject = NULL;
bool found = false; bool found = false;
@@ -851,8 +850,8 @@ bool Device_Write_Property_Local(
case PROP_OBJECT_IDENTIFIER: case PROP_OBJECT_IDENTIFIER:
if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) { if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) {
if ((value.type.Object_Id.type == OBJECT_DEVICE) && if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
(Device_Set_Object_Instance_Number(value.type.Object_Id. (Device_Set_Object_Instance_Number(value.type.
instance))) { Object_Id.instance))) {
/* we could send an I-Am broadcast to let the world know */ /* we could send an I-Am broadcast to let the world know */
status = true; status = true;
} else { } else {
@@ -895,22 +894,20 @@ bool Device_Write_Property_Local(
break; break;
case PROP_OBJECT_NAME: case PROP_OBJECT_NAME:
if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) { if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) {
length = characterstring_length( length = characterstring_length(&value.type.Character_String);
&value.type.Character_String);
if (length < characterstring_capacity(&My_Object_Name)) { if (length < characterstring_capacity(&My_Object_Name)) {
encoding = characterstring_encoding( encoding =
&value.type.Character_String); characterstring_encoding(&value.type.Character_String);
if (encoding < MAX_CHARACTER_STRING_ENCODING) { if (encoding < MAX_CHARACTER_STRING_ENCODING) {
/* All the object names in a device must be unique. */ /* All the object names in a device must be unique. */
if (Device_Valid_Object_Name( if (Device_Valid_Object_Name(&value.type.
&value.type.Character_String, Character_String, NULL, NULL)) {
NULL, NULL)) {
status = false; status = false;
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_DUPLICATE_NAME; wp_data->error_code = ERROR_CODE_DUPLICATE_NAME;
} else { } else {
Device_Set_Object_Name( Device_Set_Object_Name(&value.type.
&value.type.Character_String); Character_String);
} }
} else { } else {
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
+3 -3
View File
@@ -1177,9 +1177,9 @@ static void MSTP_Slave_Node_FSM(
} else if (MSTP_Flag.ReceivePacketPending) { } else if (MSTP_Flag.ReceivePacketPending) {
if (Ringbuf_Empty(&PDU_Queue)) { if (Ringbuf_Empty(&PDU_Queue)) {
/* If no reply will be available from the higher layers /* If no reply will be available from the higher layers
within Treply_delay after the reception of the final octet within Treply_delay after the reception of the final octet
of the requesting frame (the mechanism used to determine of the requesting frame (the mechanism used to determine
this is a local matter), then no reply is possible. */ this is a local matter), then no reply is possible. */
MSTP_Flag.ReceivePacketPending = false; MSTP_Flag.ReceivePacketPending = false;
} else { } else {
pkt = (struct mstp_pdu_packet *) Ringbuf_Pop_Front(&PDU_Queue); pkt = (struct mstp_pdu_packet *) Ringbuf_Pop_Front(&PDU_Queue);
+2 -2
View File
@@ -211,8 +211,8 @@ bool Binary_Value_Write_Property(
if ((value.type.Enumerated == BINARY_ACTIVE) || if ((value.type.Enumerated == BINARY_ACTIVE) ||
(value.type.Enumerated == BINARY_INACTIVE)) { (value.type.Enumerated == BINARY_INACTIVE)) {
object_index = object_index =
Binary_Value_Instance_To_Index(wp_data-> Binary_Value_Instance_To_Index
object_instance); (wp_data->object_instance);
/* NOTE: this Binary value has no priority array */ /* NOTE: this Binary value has no priority array */
Present_Value[object_index] = Present_Value[object_index] =
(BACNET_BINARY_PV) value.type.Enumerated; (BACNET_BINARY_PV) value.type.Enumerated;
+2 -2
View File
@@ -380,8 +380,8 @@ bool Device_Write_Property(
case PROP_OBJECT_IDENTIFIER: case PROP_OBJECT_IDENTIFIER:
if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) { if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) {
if ((value.type.Object_Id.type == OBJECT_DEVICE) && if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
(Device_Set_Object_Instance_Number(value.type.Object_Id. (Device_Set_Object_Instance_Number(value.type.
instance))) { Object_Id.instance))) {
/* we could send an I-Am broadcast to let the world know */ /* we could send an I-Am broadcast to let the world know */
status = true; status = true;
} else { } else {
+2 -2
View File
@@ -211,8 +211,8 @@ bool Binary_Value_Write_Property(
if ((value.type.Enumerated == BINARY_ACTIVE) || if ((value.type.Enumerated == BINARY_ACTIVE) ||
(value.type.Enumerated == BINARY_INACTIVE)) { (value.type.Enumerated == BINARY_INACTIVE)) {
object_index = object_index =
Binary_Value_Instance_To_Index(wp_data-> Binary_Value_Instance_To_Index
object_instance); (wp_data->object_instance);
/* NOTE: this Binary value has no priority array */ /* NOTE: this Binary value has no priority array */
Present_Value[object_index] = Present_Value[object_index] =
(BACNET_BINARY_PV) value.type.Enumerated; (BACNET_BINARY_PV) value.type.Enumerated;
+12 -11
View File
@@ -72,18 +72,18 @@ void adc_enable(
* Notes: none * Notes: none
**************************************************/ **************************************************/
uint8_t adc_result_8bit( uint8_t adc_result_8bit(
uint8_t channel) /* 0..7 = ADC0..ADC7, respectively */ uint8_t channel)
{ { /* 0..7 = ADC0..ADC7, respectively */
uint8_t value = 0; /* return value */ uint8_t value = 0; /* return value */
while ( ADCSRA & (1 << ADSC) ) ; while (ADCSRA & (1 << ADSC));
ADMUX = channel | (1 << ADLAR) | (0 << REFS1) | (1 << REFS0); ADMUX = channel | (1 << ADLAR) | (0 << REFS1) | (1 << REFS0);
/* Delay needed for the stabilization of the ADC input voltage */ /* Delay needed for the stabilization of the ADC input voltage */
_delay_us(10); _delay_us(10);
/* Start the analog to digital conversion */ /* Start the analog to digital conversion */
ADCSRA = (1 << ADEN) | (1 << ADSC) | (1 << ADIF) | ADPS_8BIT; ADCSRA = (1 << ADEN) | (1 << ADSC) | (1 << ADIF) | ADPS_8BIT;
/* Wait for the analog to digital conversion to complete */ /* Wait for the analog to digital conversion to complete */
while ( (ADCSRA & (1 << ADIF)) == 0 ) ; while ((ADCSRA & (1 << ADIF)) == 0);
value = ADCH; value = ADCH;
return value; return value;
@@ -95,18 +95,18 @@ uint8_t adc_result_8bit(
* Notes: none * Notes: none
**************************************************/ **************************************************/
uint16_t adc_result_10bit( uint16_t adc_result_10bit(
uint8_t channel) /* 0..7 = ADC0..ADC7, respectively */ uint8_t channel)
{ { /* 0..7 = ADC0..ADC7, respectively */
uint16_t value = 0; /* return value */ uint16_t value = 0; /* return value */
while ( ADCSRA & (1 << ADSC) ) ; while (ADCSRA & (1 << ADSC));
ADMUX = channel | (0 << ADLAR) | (0 << REFS1) | (1 << REFS0); ADMUX = channel | (0 << ADLAR) | (0 << REFS1) | (1 << REFS0);
/* Delay needed for the stabilization of the ADC input voltage */ /* Delay needed for the stabilization of the ADC input voltage */
_delay_us(10); _delay_us(10);
/* Start the analog to digital conversion */ /* Start the analog to digital conversion */
ADCSRA = (1 << ADEN) | (1 << ADSC) | (1 << ADIF) | ADPS_10BIT; ADCSRA = (1 << ADEN) | (1 << ADSC) | (1 << ADIF) | ADPS_10BIT;
/* Wait for the analog to digital conversion to complete */ /* Wait for the analog to digital conversion to complete */
while ( (ADCSRA & (1 << ADIF)) == 0 ) ; while ((ADCSRA & (1 << ADIF)) == 0);
value = ADCL; value = ADCL;
value |= (ADCH << 8); value |= (ADCH << 8);
@@ -118,11 +118,12 @@ uint16_t adc_result_10bit(
* Returns: none * Returns: none
* Notes: none * Notes: none
**************************************************/ **************************************************/
void adc_init(void) void adc_init(
void)
{ {
/* configure ADC for Free Running Mode - ADTS = 000 */ /* configure ADC for Free Running Mode - ADTS = 000 */
/* AIN1 is applied to the negative input of the Analog Comparator - ACME */ /* AIN1 is applied to the negative input of the Analog Comparator - ACME */
BITMASK_CLEAR(ADCSRB, _BV(ACME)|_BV(ADTS2)|_BV(ADTS1)|_BV(ADTS0)); BITMASK_CLEAR(ADCSRB, _BV(ACME) | _BV(ADTS2) | _BV(ADTS1) | _BV(ADTS0));
/* Digital input not needed on ADC0, so disable it to save power */ /* Digital input not needed on ADC0, so disable it to save power */
BIT_SET(DIDR0, ADC0D); BIT_SET(DIDR0, ADC0D);
/* Clear the Power Reduction bit to enable ADC */ /* Clear the Power Reduction bit to enable ADC */
+1 -1
View File
@@ -111,7 +111,7 @@ uint32_t Analog_Input_Index_To_Instance(
bool Analog_Input_Object_Name( bool Analog_Input_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name) BACNET_CHARACTER_STRING * object_name)
{ {
static char text_string[32]; /* okay for single thread */ static char text_string[32]; /* okay for single thread */
bool status = false; bool status = false;
+1 -1
View File
@@ -177,7 +177,7 @@ bool Analog_Value_Present_Value_Set(
/* note: the object name must be unique within this device */ /* note: the object name must be unique within this device */
bool Analog_Value_Object_Name( bool Analog_Value_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name) BACNET_CHARACTER_STRING * object_name)
{ {
static char text_string[32] = ""; /* okay for single thread */ static char text_string[32] = ""; /* okay for single thread */
unsigned index = 0; unsigned index = 0;
+1 -1
View File
@@ -159,7 +159,7 @@ bool Binary_Input_Present_Value_Set(
bool Binary_Input_Object_Name( bool Binary_Input_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name) BACNET_CHARACTER_STRING * object_name)
{ {
static char text_string[32]; /* okay for single thread */ static char text_string[32]; /* okay for single thread */
bool status = false; bool status = false;
+62 -53
View File
@@ -39,26 +39,36 @@
by Jeff Bezanson by Jeff Bezanson
placed in the public domain Fall 2005 */ placed in the public domain Fall 2005 */
static const char trailingBytesForUTF8[256] = { static const char trailingBytesForUTF8[256] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4,
4, 4, 4, 5, 5, 5, 5
}; };
/* based on the valid_utf8 routine from the PCRE library by Philip Hazel /* based on the valid_utf8 routine from the PCRE library by Philip Hazel
length is in bytes, since without knowing whether the string is valid length is in bytes, since without knowing whether the string is valid
it's hard to know how many characters there are! */ it's hard to know how many characters there are! */
static int utf8_isvalid(const char *str, int length) static int utf8_isvalid(
const char *str,
int length)
{ {
const unsigned char *p, *pend = (unsigned char*)str + length; const unsigned char *p, *pend = (unsigned char *) str + length;
unsigned char c; unsigned char c;
int ab; int ab;
for (p = (unsigned char*)str; p < pend; p++) { for (p = (unsigned char *) str; p < pend; p++) {
c = *p; c = *p;
/* null in middle of string */ /* null in middle of string */
if (c == 0) { if (c == 0) {
@@ -84,37 +94,42 @@ static int utf8_isvalid(const char *str, int length)
} }
/* Check for overlong sequences for each different length */ /* Check for overlong sequences for each different length */
switch (ab) { switch (ab) {
/* Check for xx00 000x */ /* Check for xx00 000x */
case 1: case 1:
if ((c & 0x3e) == 0) return 0; if ((c & 0x3e) == 0)
continue; /* We know there aren't any more bytes to check */ return 0;
continue; /* We know there aren't any more bytes to check */
/* Check for 1110 0000, xx0x xxxx */ /* Check for 1110 0000, xx0x xxxx */
case 2: case 2:
if (c == 0xe0 && (*p & 0x20) == 0) return 0; if (c == 0xe0 && (*p & 0x20) == 0)
break; return 0;
break;
/* Check for 1111 0000, xx00 xxxx */ /* Check for 1111 0000, xx00 xxxx */
case 3: case 3:
if (c == 0xf0 && (*p & 0x30) == 0) return 0; if (c == 0xf0 && (*p & 0x30) == 0)
break; return 0;
break;
/* Check for 1111 1000, xx00 0xxx */ /* Check for 1111 1000, xx00 0xxx */
case 4: case 4:
if (c == 0xf8 && (*p & 0x38) == 0) return 0; if (c == 0xf8 && (*p & 0x38) == 0)
break; return 0;
break;
/* Check for leading 0xfe or 0xff, /* Check for leading 0xfe or 0xff,
and then for 1111 1100, xx00 00xx */ and then for 1111 1100, xx00 00xx */
case 5: case 5:
if (c == 0xfe || c == 0xff || if (c == 0xfe || c == 0xff || (c == 0xfc && (*p & 0x3c) == 0))
(c == 0xfc && (*p & 0x3c) == 0)) return 0; return 0;
break; break;
} }
/* Check for valid bytes after the 2nd, if any; all must start 10 */ /* Check for valid bytes after the 2nd, if any; all must start 10 */
while (--ab > 0) { while (--ab > 0) {
if ((*(++p) & 0xc0) != 0x80) return 0; if ((*(++p) & 0xc0) != 0x80)
return 0;
} }
} }
@@ -144,7 +159,7 @@ static bool bacnet_name_isvalid(
bool bacnet_name_set( bool bacnet_name_set(
uint16_t offset, uint16_t offset,
BACNET_CHARACTER_STRING *char_string) BACNET_CHARACTER_STRING * char_string)
{ {
uint8_t encoding = 0; uint8_t encoding = 0;
uint8_t length = 0; uint8_t length = 0;
@@ -154,15 +169,9 @@ bool bacnet_name_set(
encoding = characterstring_encoding(char_string); encoding = characterstring_encoding(char_string);
str = characterstring_value(char_string); str = characterstring_value(char_string);
if (bacnet_name_isvalid(encoding, length, str)) { if (bacnet_name_isvalid(encoding, length, str)) {
seeprom_bytes_write( seeprom_bytes_write(NV_EEPROM_NAME_LENGTH(offset), &length, 1);
NV_EEPROM_NAME_LENGTH(offset), seeprom_bytes_write(NV_EEPROM_NAME_ENCODING(offset), &encoding, 1);
&length, 1); seeprom_bytes_write(NV_EEPROM_NAME_STRING(offset), (uint8_t *) str,
seeprom_bytes_write(
NV_EEPROM_NAME_ENCODING(offset),
&encoding, 1);
seeprom_bytes_write(
NV_EEPROM_NAME_STRING(offset),
(uint8_t *)str,
length); length);
return true; return true;
} }
@@ -172,9 +181,9 @@ bool bacnet_name_set(
bool bacnet_name_write( bool bacnet_name_write(
uint16_t offset, uint16_t offset,
BACNET_CHARACTER_STRING *char_string, BACNET_CHARACTER_STRING * char_string,
BACNET_ERROR_CLASS *error_class, BACNET_ERROR_CLASS * error_class,
BACNET_ERROR_CODE *error_code) BACNET_ERROR_CODE * error_code)
{ {
bool status = false; bool status = false;
size_t length = 0; size_t length = 0;
@@ -215,9 +224,9 @@ bool bacnet_name_write(
/* no required minumum length or duplicate checking */ /* no required minumum length or duplicate checking */
bool bacnet_name_write_other( bool bacnet_name_write_other(
uint16_t offset, uint16_t offset,
BACNET_CHARACTER_STRING *char_string, BACNET_CHARACTER_STRING * char_string,
BACNET_ERROR_CLASS *error_class, BACNET_ERROR_CLASS * error_class,
BACNET_ERROR_CODE *error_code) BACNET_ERROR_CODE * error_code)
{ {
bool status = false; bool status = false;
size_t length = 0; size_t length = 0;
@@ -247,16 +256,16 @@ bool bacnet_name_write_other(
void bacnet_name_init( void bacnet_name_init(
uint16_t offset, uint16_t offset,
BACNET_CHARACTER_STRING *char_string, BACNET_CHARACTER_STRING * char_string,
char *default_string) char *default_string)
{ {
characterstring_init_ansi(char_string, default_string); characterstring_init_ansi(char_string, default_string);
(void)bacnet_name_set(offset, char_string); (void) bacnet_name_set(offset, char_string);
} }
void bacnet_name( void bacnet_name(
uint16_t offset, uint16_t offset,
BACNET_CHARACTER_STRING *char_string, BACNET_CHARACTER_STRING * char_string,
char *default_string) char *default_string)
{ {
uint8_t encoding = 0; uint8_t encoding = 0;
+9 -9
View File
@@ -33,26 +33,26 @@ extern "C" {
bool bacnet_name_set( bool bacnet_name_set(
uint16_t eeprom_offset, uint16_t eeprom_offset,
BACNET_CHARACTER_STRING *char_string); BACNET_CHARACTER_STRING * char_string);
void bacnet_name_init( void bacnet_name_init(
uint16_t eeprom_offset, uint16_t eeprom_offset,
BACNET_CHARACTER_STRING *char_string, BACNET_CHARACTER_STRING * char_string,
char *default_string); char *default_string);
void bacnet_name( void bacnet_name(
uint16_t eeprom_offset, uint16_t eeprom_offset,
BACNET_CHARACTER_STRING *char_string, BACNET_CHARACTER_STRING * char_string,
char *default_string); char *default_string);
bool bacnet_name_write( bool bacnet_name_write(
uint16_t offset, uint16_t offset,
BACNET_CHARACTER_STRING *char_string, BACNET_CHARACTER_STRING * char_string,
BACNET_ERROR_CLASS *error_class, BACNET_ERROR_CLASS * error_class,
BACNET_ERROR_CODE *error_code); BACNET_ERROR_CODE * error_code);
/* no required minumum length or duplicate checking */ /* no required minumum length or duplicate checking */
bool bacnet_name_write_other( bool bacnet_name_write_other(
uint16_t offset, uint16_t offset,
BACNET_CHARACTER_STRING *char_string, BACNET_CHARACTER_STRING * char_string,
BACNET_ERROR_CLASS *error_class, BACNET_ERROR_CLASS * error_class,
BACNET_ERROR_CODE *error_code); BACNET_ERROR_CODE * error_code);
#ifdef __cplusplus #ifdef __cplusplus
} }
+3 -3
View File
@@ -231,7 +231,7 @@ bool Binary_Output_Out_Of_Service(
/* note: the object name must be unique within this device */ /* note: the object name must be unique within this device */
bool Binary_Output_Object_Name( bool Binary_Output_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name) BACNET_CHARACTER_STRING * object_name)
{ {
static char text_string[32]; /* okay for single thread */ static char text_string[32]; /* okay for single thread */
bool status = false; bool status = false;
@@ -439,8 +439,8 @@ bool Binary_Output_Write_Property(
priority = wp_data->priority; priority = wp_data->priority;
if (priority && (priority <= BACNET_MAX_PRIORITY)) { if (priority && (priority <= BACNET_MAX_PRIORITY)) {
priority--; priority--;
Binary_Output_Present_Value_Set(wp_data-> Binary_Output_Present_Value_Set
object_instance, level, priority); (wp_data->object_instance, level, priority);
} else if (priority == 6) { } else if (priority == 6) {
status = false; status = false;
/* Command priority 6 is reserved for use by Minimum On/Off /* Command priority 6 is reserved for use by Minimum On/Off
+26 -35
View File
@@ -195,12 +195,12 @@ static int Read_Property_Common(
} else { } else {
characterstring_init_ansi(&char_string, ""); characterstring_init_ansi(&char_string, "");
if (pObject->Object_Name) { if (pObject->Object_Name) {
(void)pObject->Object_Name( (void) pObject->Object_Name(rpdata->object_instance,
rpdata->object_instance,
&char_string); &char_string);
} }
apdu_len = apdu_len =
encode_application_character_string(&apdu[0], &char_string); encode_application_character_string(&apdu[0],
&char_string);
} }
break; break;
case PROP_OBJECT_TYPE: case PROP_OBJECT_TYPE:
@@ -361,7 +361,8 @@ uint32_t Device_Index_To_Instance(
return Object_Instance_Number; return Object_Instance_Number;
} }
static char *Device_Name_Default(void) static char *Device_Name_Default(
void)
{ {
static char text_string[32]; /* okay for single thread */ static char text_string[32]; /* okay for single thread */
@@ -372,15 +373,12 @@ static char *Device_Name_Default(void)
bool Device_Object_Name( bool Device_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name) BACNET_CHARACTER_STRING * object_name)
{ {
bool status = false; bool status = false;
if (object_instance == Object_Instance_Number) { if (object_instance == Object_Instance_Number) {
bacnet_name( bacnet_name(NV_EEPROM_DEVICE_NAME, object_name, Device_Name_Default());
NV_EEPROM_DEVICE_NAME,
object_name,
Device_Name_Default());
status = true; status = true;
} }
@@ -416,13 +414,13 @@ BACNET_REINITIALIZED_STATE Device_Reinitialized_State(
} }
void Device_Init( void Device_Init(
object_functions_t * object_table) object_functions_t * object_table)
{ {
struct my_object_functions *pObject = NULL; struct my_object_functions *pObject = NULL;
/* we don't use the object table passed in /* we don't use the object table passed in
since there is extra stuff we don't need in there. */ since there is extra stuff we don't need in there. */
(void)object_table; (void) object_table;
/* our local object table */ /* our local object table */
pObject = &Object_Table[0]; pObject = &Object_Table[0];
while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) { while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) {
@@ -574,7 +572,7 @@ bool Device_Object_List_Identifier(
} }
bool Device_Valid_Object_Name( bool Device_Valid_Object_Name(
BACNET_CHARACTER_STRING *object_name1, BACNET_CHARACTER_STRING * object_name1,
int *object_type, int *object_type,
uint32_t * object_instance) uint32_t * object_instance)
{ {
@@ -593,7 +591,7 @@ bool Device_Valid_Object_Name(
pObject = Device_Objects_Find_Functions(type); pObject = Device_Objects_Find_Functions(type);
if ((pObject != NULL) && (pObject->Object_Name != NULL) && if ((pObject != NULL) && (pObject->Object_Name != NULL) &&
(pObject->Object_Name(instance, &object_name2) && (pObject->Object_Name(instance, &object_name2) &&
characterstring_same(object_name1, &object_name2))) { characterstring_same(object_name1, &object_name2))) {
found = true; found = true;
if (object_type) { if (object_type) {
*object_type = type; *object_type = type;
@@ -613,7 +611,7 @@ bool Device_Valid_Object_Id(
int object_type, int object_type,
uint32_t object_instance) uint32_t object_instance)
{ {
bool status = false; /* return value */ bool status = false; /* return value */
struct my_object_functions *pObject = NULL; struct my_object_functions *pObject = NULL;
pObject = Device_Objects_Find_Functions(object_type); pObject = Device_Objects_Find_Functions(object_type);
@@ -627,7 +625,7 @@ bool Device_Valid_Object_Id(
bool Device_Object_Name_Copy( bool Device_Object_Name_Copy(
int object_type, int object_type,
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name) BACNET_CHARACTER_STRING * object_name)
{ {
struct my_object_functions *pObject = NULL; struct my_object_functions *pObject = NULL;
bool found = false; bool found = false;
@@ -673,17 +671,13 @@ int Device_Read_Property_Local(
apdu = rpdata->application_data; apdu = rpdata->application_data;
switch (rpdata->object_property) { switch (rpdata->object_property) {
case PROP_DESCRIPTION: case PROP_DESCRIPTION:
bacnet_name( bacnet_name(NV_EEPROM_DEVICE_DESCRIPTION, &char_string,
NV_EEPROM_DEVICE_DESCRIPTION,
&char_string,
"BACnet Development Kit"); "BACnet Development Kit");
apdu_len = apdu_len =
encode_application_character_string(&apdu[0], &char_string); encode_application_character_string(&apdu[0], &char_string);
break; break;
case PROP_LOCATION: case PROP_LOCATION:
bacnet_name( bacnet_name(NV_EEPROM_DEVICE_LOCATION, &char_string,
NV_EEPROM_DEVICE_LOCATION,
&char_string,
"default location"); "default location");
apdu_len = apdu_len =
encode_application_character_string(&apdu[0], &char_string); encode_application_character_string(&apdu[0], &char_string);
@@ -881,8 +875,8 @@ bool Device_Write_Property_Local(
case PROP_OBJECT_IDENTIFIER: case PROP_OBJECT_IDENTIFIER:
if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) { if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) {
if ((value.type.Object_Id.type == OBJECT_DEVICE) && if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
(Device_Set_Object_Instance_Number(value.type.Object_Id. (Device_Set_Object_Instance_Number(value.type.
instance))) { Object_Id.instance))) {
/* we could send an I-Am broadcast to let the world know */ /* we could send an I-Am broadcast to let the world know */
status = true; status = true;
} else { } else {
@@ -925,10 +919,9 @@ bool Device_Write_Property_Local(
break; break;
case PROP_OBJECT_NAME: case PROP_OBJECT_NAME:
if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) { if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) {
status = bacnet_name_write( status =
NV_EEPROM_DEVICE_NAME, bacnet_name_write(NV_EEPROM_DEVICE_NAME,
&value.type.Character_String, &value.type.Character_String, &wp_data->error_class,
&wp_data->error_class,
&wp_data->error_code); &wp_data->error_code);
} else { } else {
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
@@ -937,10 +930,9 @@ bool Device_Write_Property_Local(
break; break;
case PROP_DESCRIPTION: case PROP_DESCRIPTION:
if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) { if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) {
status = bacnet_name_write_other( status =
NV_EEPROM_DEVICE_DESCRIPTION, bacnet_name_write_other(NV_EEPROM_DEVICE_DESCRIPTION,
&value.type.Character_String, &value.type.Character_String, &wp_data->error_class,
&wp_data->error_class,
&wp_data->error_code); &wp_data->error_code);
} else { } else {
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
@@ -949,10 +941,9 @@ bool Device_Write_Property_Local(
break; break;
case PROP_LOCATION: case PROP_LOCATION:
if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) { if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) {
status = bacnet_name_write_other( status =
NV_EEPROM_DEVICE_LOCATION, bacnet_name_write_other(NV_EEPROM_DEVICE_LOCATION,
&value.type.Character_String, &value.type.Character_String, &wp_data->error_class,
&wp_data->error_class,
&wp_data->error_code); &wp_data->error_code);
} else { } else {
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
+50 -33
View File
@@ -91,7 +91,8 @@ static uint8_t Tusage_timeout = 60;
static struct timeval start; static struct timeval start;
static uint32_t Timer_Silence(void) static uint32_t Timer_Silence(
void)
{ {
struct timeval now, tmp_diff; struct timeval now, tmp_diff;
int32_t res; int32_t res;
@@ -105,14 +106,16 @@ static uint32_t Timer_Silence(void)
return (res >= 0 ? res : -res); return (res >= 0 ? res : -res);
} }
static void Timer_Silence_Reset(void) static void Timer_Silence_Reset(
void)
{ {
pthread_mutex_lock(&Timer_Mutex); pthread_mutex_lock(&Timer_Mutex);
gettimeofday(&start, NULL); gettimeofday(&start, NULL);
pthread_mutex_unlock(&Timer_Mutex); pthread_mutex_unlock(&Timer_Mutex);
} }
static void get_abstime(struct timespec *abstime, static void get_abstime(
struct timespec *abstime,
unsigned long milliseconds) unsigned long milliseconds)
{ {
struct timeval now, offset, result; struct timeval now, offset, result;
@@ -125,7 +128,8 @@ static void get_abstime(struct timespec *abstime,
abstime->tv_nsec = result.tv_usec * 1000; abstime->tv_nsec = result.tv_usec * 1000;
} }
void dlmstp_cleanup(void) void dlmstp_cleanup(
void)
{ {
pthread_cond_destroy(&Received_Frame_Flag); pthread_cond_destroy(&Received_Frame_Flag);
pthread_cond_destroy(&Receive_Packet_Flag); pthread_cond_destroy(&Receive_Packet_Flag);
@@ -137,12 +141,10 @@ void dlmstp_cleanup(void)
} }
/* returns number of bytes sent on success, zero on failure */ /* returns number of bytes sent on success, zero on failure */
int dlmstp_send_pdu(BACNET_ADDRESS * dest, /* destination address */ int dlmstp_send_pdu(
BACNET_ADDRESS * dest, /* destination address */
BACNET_NPDU_DATA * npdu_data, /* network information */ BACNET_NPDU_DATA * npdu_data, /* network information */
uint8_t * pdu, /* any data to be sent - may be null */ uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len) unsigned pdu_len)
{ /* number of bytes of data */ { /* number of bytes of data */
int bytes_sent = 0; int bytes_sent = 0;
@@ -168,12 +170,10 @@ int dlmstp_send_pdu(BACNET_ADDRESS * dest, /* destination address */
return bytes_sent; return bytes_sent;
} }
uint16_t dlmstp_receive(BACNET_ADDRESS * src, /* source address */ uint16_t dlmstp_receive(
BACNET_ADDRESS * src, /* source address */
uint8_t * pdu, /* PDU data */ uint8_t * pdu, /* PDU data */
uint16_t max_pdu, /* amount of space available in the PDU */ uint16_t max_pdu, /* amount of space available in the PDU */
unsigned timeout) unsigned timeout)
{ /* milliseconds to wait for a packet */ { /* milliseconds to wait for a packet */
uint16_t pdu_len = 0; uint16_t pdu_len = 0;
@@ -207,7 +207,8 @@ uint16_t dlmstp_receive(BACNET_ADDRESS * src, /* source address */
return pdu_len; return pdu_len;
} }
static void *dlmstp_master_fsm_task(void *pArg) static void *dlmstp_master_fsm_task(
void *pArg)
{ {
uint32_t silence = 0; uint32_t silence = 0;
bool run_master = false; bool run_master = false;
@@ -252,7 +253,8 @@ static void *dlmstp_master_fsm_task(void *pArg)
return NULL; return NULL;
} }
void dlmstp_fill_bacnet_address(BACNET_ADDRESS * src, void dlmstp_fill_bacnet_address(
BACNET_ADDRESS * src,
uint8_t mstp_address) uint8_t mstp_address)
{ {
int i = 0; int i = 0;
@@ -277,7 +279,8 @@ void dlmstp_fill_bacnet_address(BACNET_ADDRESS * src,
} }
/* for the MS/TP state machine to use for putting received data */ /* for the MS/TP state machine to use for putting received data */
uint16_t MSTP_Put_Receive(volatile struct mstp_port_struct_t *mstp_port) uint16_t MSTP_Put_Receive(
volatile struct mstp_port_struct_t *mstp_port)
{ {
uint16_t pdu_len = 0; uint16_t pdu_len = 0;
@@ -300,7 +303,8 @@ uint16_t MSTP_Put_Receive(volatile struct mstp_port_struct_t *mstp_port)
/* for the MS/TP state machine to use for getting data to send */ /* for the MS/TP state machine to use for getting data to send */
/* Return: amount of PDU data */ /* Return: amount of PDU data */
uint16_t MSTP_Get_Send(volatile struct mstp_port_struct_t * mstp_port, uint16_t MSTP_Get_Send(
volatile struct mstp_port_struct_t * mstp_port,
unsigned timeout) unsigned timeout)
{ /* milliseconds to wait for a packet */ { /* milliseconds to wait for a packet */
uint16_t pdu_len = 0; uint16_t pdu_len = 0;
@@ -329,7 +333,8 @@ uint16_t MSTP_Get_Send(volatile struct mstp_port_struct_t * mstp_port,
return pdu_len; return pdu_len;
} }
static bool dlmstp_compare_data_expecting_reply(uint8_t * request_pdu, static bool dlmstp_compare_data_expecting_reply(
uint8_t * request_pdu,
uint16_t request_pdu_len, uint16_t request_pdu_len,
uint8_t src_address, uint8_t src_address,
uint8_t * reply_pdu, uint8_t * reply_pdu,
@@ -445,7 +450,8 @@ static bool dlmstp_compare_data_expecting_reply(uint8_t * request_pdu,
} }
/* Get the reply to a DATA_EXPECTING_REPLY frame, or nothing */ /* Get the reply to a DATA_EXPECTING_REPLY frame, or nothing */
uint16_t MSTP_Get_Reply(volatile struct mstp_port_struct_t * mstp_port, uint16_t MSTP_Get_Reply(
volatile struct mstp_port_struct_t * mstp_port,
unsigned timeout) unsigned timeout)
{ /* milliseconds to wait for a packet */ { /* milliseconds to wait for a packet */
uint16_t pdu_len = 0; /* return value */ uint16_t pdu_len = 0; /* return value */
@@ -484,7 +490,8 @@ uint16_t MSTP_Get_Reply(volatile struct mstp_port_struct_t * mstp_port,
return pdu_len; return pdu_len;
} }
void dlmstp_set_mac_address(uint8_t mac_address) void dlmstp_set_mac_address(
uint8_t mac_address)
{ {
/* Master Nodes can only have address 0-127 */ /* Master Nodes can only have address 0-127 */
if (mac_address <= 127) { if (mac_address <= 127) {
@@ -501,7 +508,8 @@ void dlmstp_set_mac_address(uint8_t mac_address)
return; return;
} }
uint8_t dlmstp_mac_address(void) uint8_t dlmstp_mac_address(
void)
{ {
return MSTP_Port.This_Station; return MSTP_Port.This_Station;
} }
@@ -513,7 +521,8 @@ uint8_t dlmstp_mac_address(void)
/* nodes. This may be used to allocate more or less of the available link */ /* nodes. This may be used to allocate more or less of the available link */
/* bandwidth to particular nodes. If Max_Info_Frames is not writable in a */ /* bandwidth to particular nodes. If Max_Info_Frames is not writable in a */
/* node, its value shall be 1. */ /* node, its value shall be 1. */
void dlmstp_set_max_info_frames(uint8_t max_info_frames) void dlmstp_set_max_info_frames(
uint8_t max_info_frames)
{ {
if (max_info_frames >= 1) { if (max_info_frames >= 1) {
MSTP_Port.Nmax_info_frames = max_info_frames; MSTP_Port.Nmax_info_frames = max_info_frames;
@@ -527,7 +536,8 @@ void dlmstp_set_max_info_frames(uint8_t max_info_frames)
return; return;
} }
uint8_t dlmstp_max_info_frames(void) uint8_t dlmstp_max_info_frames(
void)
{ {
return MSTP_Port.Nmax_info_frames; return MSTP_Port.Nmax_info_frames;
} }
@@ -537,7 +547,8 @@ uint8_t dlmstp_max_info_frames(void)
/* allowable address for master nodes. The value of Max_Master shall be */ /* allowable address for master nodes. The value of Max_Master shall be */
/* less than or equal to 127. If Max_Master is not writable in a node, */ /* less than or equal to 127. If Max_Master is not writable in a node, */
/* its value shall be 127. */ /* its value shall be 127. */
void dlmstp_set_max_master(uint8_t max_master) void dlmstp_set_max_master(
uint8_t max_master)
{ {
if (max_master <= 127) { if (max_master <= 127) {
if (MSTP_Port.This_Station <= max_master) { if (MSTP_Port.This_Station <= max_master) {
@@ -553,23 +564,27 @@ void dlmstp_set_max_master(uint8_t max_master)
return; return;
} }
uint8_t dlmstp_max_master(void) uint8_t dlmstp_max_master(
void)
{ {
return MSTP_Port.Nmax_master; return MSTP_Port.Nmax_master;
} }
/* RS485 Baud Rate 9600, 19200, 38400, 57600, 115200 */ /* RS485 Baud Rate 9600, 19200, 38400, 57600, 115200 */
void dlmstp_set_baud_rate(uint32_t baud) void dlmstp_set_baud_rate(
uint32_t baud)
{ {
RS485_Set_Baud_Rate(baud); RS485_Set_Baud_Rate(baud);
} }
uint32_t dlmstp_baud_rate(void) uint32_t dlmstp_baud_rate(
void)
{ {
return RS485_Get_Baud_Rate(); return RS485_Get_Baud_Rate();
} }
void dlmstp_get_my_address(BACNET_ADDRESS * my_address) void dlmstp_get_my_address(
BACNET_ADDRESS * my_address)
{ {
int i = 0; /* counter */ int i = 0; /* counter */
@@ -584,7 +599,8 @@ void dlmstp_get_my_address(BACNET_ADDRESS * my_address)
return; return;
} }
void dlmstp_get_broadcast_address(BACNET_ADDRESS * dest) void dlmstp_get_broadcast_address(
BACNET_ADDRESS * dest)
{ /* destination address */ { /* destination address */
int i = 0; /* counter */ int i = 0; /* counter */
@@ -601,7 +617,8 @@ void dlmstp_get_broadcast_address(BACNET_ADDRESS * dest)
return; return;
} }
bool dlmstp_init(char *ifname) bool dlmstp_init(
char *ifname)
{ {
unsigned long hThread = 0; unsigned long hThread = 0;
int rv = 0; int rv = 0;
@@ -665,10 +682,9 @@ bool dlmstp_init(char *ifname)
#ifdef TEST_DLMSTP #ifdef TEST_DLMSTP
#include <stdio.h> #include <stdio.h>
void apdu_handler(BACNET_ADDRESS * src, /* source address */ void apdu_handler(
BACNET_ADDRESS * src, /* source address */
uint8_t * apdu, /* APDU data */ uint8_t * apdu, /* APDU data */
uint16_t pdu_len) uint16_t pdu_len)
{ /* for confirmed messages */ { /* for confirmed messages */
(void) src; (void) src;
@@ -678,7 +694,8 @@ void apdu_handler(BACNET_ADDRESS * src, /* source address */
static char *Network_Interface = NULL; static char *Network_Interface = NULL;
int main(int argc, int main(
int argc,
char *argv[]) char *argv[])
{ {
uint16_t pdu_len = 0; uint16_t pdu_len = 0;
+20 -12
View File
@@ -95,7 +95,8 @@ static pthread_mutex_t Reader_Mutex, IOMutex;
#define _POSIX_SOURCE 1 /* POSIX compliant source */ #define _POSIX_SOURCE 1 /* POSIX compliant source */
static void *rs485_read_task(void *arg) static void *rs485_read_task(
void *arg)
{ {
uint8_t buf[1 << 11]; uint8_t buf[1 << 11];
int count, n; int count, n;
@@ -134,7 +135,8 @@ static void *rs485_read_task(void *arg)
* ALGORITHM: none * ALGORITHM: none
* NOTES: none * NOTES: none
*********************************************************************/ *********************************************************************/
void RS485_Set_Interface(char *ifname) void RS485_Set_Interface(
char *ifname)
{ {
/* note: expects a constant char, or char from the heap */ /* note: expects a constant char, or char from the heap */
if (ifname) { if (ifname) {
@@ -148,7 +150,8 @@ void RS485_Set_Interface(char *ifname)
* ALGORITHM: none * ALGORITHM: none
* NOTES: none * NOTES: none
*********************************************************************/ *********************************************************************/
const char *RS485_Interface(void) const char *RS485_Interface(
void)
{ {
return RS485_Port_Name; return RS485_Port_Name;
} }
@@ -159,7 +162,8 @@ const char *RS485_Interface(void)
* ALGORITHM: none * ALGORITHM: none
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
uint32_t RS485_Get_Baud_Rate(void) uint32_t RS485_Get_Baud_Rate(
void)
{ {
switch (RS485_Baud) { switch (RS485_Baud) {
case B19200: case B19200:
@@ -182,7 +186,8 @@ uint32_t RS485_Get_Baud_Rate(void)
* ALGORITHM: none * ALGORITHM: none
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
bool RS485_Set_Baud_Rate(uint32_t baud) bool RS485_Set_Baud_Rate(
uint32_t baud)
{ {
bool valid = true; bool valid = true;
@@ -215,10 +220,9 @@ bool RS485_Set_Baud_Rate(uint32_t baud)
} }
/* Transmits a Frame on the wire */ /* Transmits a Frame on the wire */
void RS485_Send_Frame(volatile struct mstp_port_struct_t *mstp_port, /* port specific data */ void RS485_Send_Frame(
volatile struct mstp_port_struct_t *mstp_port, /* port specific data */
uint8_t * buffer, /* frame to send (up to 501 bytes of data) */ uint8_t * buffer, /* frame to send (up to 501 bytes of data) */
uint16_t nbytes) uint16_t nbytes)
{ /* number of bytes of data (up to 501) */ { /* number of bytes of data (up to 501) */
ssize_t written = 0; ssize_t written = 0;
@@ -246,7 +250,8 @@ void RS485_Send_Frame(volatile struct mstp_port_struct_t *mstp_port, /* port
} }
/* called by timer, interrupt(?) or other thread */ /* called by timer, interrupt(?) or other thread */
void RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port) void RS485_Check_UART_Data(
volatile struct mstp_port_struct_t *mstp_port)
{ {
if (mstp_port->ReceiveError == true) { if (mstp_port->ReceiveError == true) {
/* wait for state machine to clear this */ /* wait for state machine to clear this */
@@ -266,7 +271,8 @@ void RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port)
} }
} }
void RS485_Cleanup(void) void RS485_Cleanup(
void)
{ {
/* restore the old port settings */ /* restore the old port settings */
tcsetattr(RS485_Handle, TCSANOW, &RS485_oldtio); tcsetattr(RS485_Handle, TCSANOW, &RS485_oldtio);
@@ -276,7 +282,8 @@ void RS485_Cleanup(void)
} }
void RS485_Initialize(void) void RS485_Initialize(
void)
{ {
struct termios newtio; struct termios newtio;
unsigned long hThread = 0; unsigned long hThread = 0;
@@ -333,7 +340,8 @@ void RS485_Initialize(void)
#ifdef TEST_RS485 #ifdef TEST_RS485
#include <string.h> #include <string.h>
int main(int argc, int main(
int argc,
char *argv[]) char *argv[])
{ {
uint8_t buf[8]; uint8_t buf[8];
+2 -2
View File
@@ -325,8 +325,8 @@ bool Analog_Value_Write_Property(
(value.type.Real >= 0.0) && (value.type.Real <= 100.0)) { (value.type.Real >= 0.0) && (value.type.Real <= 100.0)) {
level = (uint8_t) value.type.Real; level = (uint8_t) value.type.Real;
object_index = object_index =
Analog_Value_Instance_To_Index(wp_data-> Analog_Value_Instance_To_Index
object_instance); (wp_data->object_instance);
priority--; priority--;
Present_Value[object_index] = level; Present_Value[object_index] = level;
/* Note: you could set the physical output here if we /* Note: you could set the physical output here if we
+2 -2
View File
@@ -237,8 +237,8 @@ bool Binary_Value_Write_Property(
(value.type.Enumerated <= MAX_BINARY_PV)) { (value.type.Enumerated <= MAX_BINARY_PV)) {
level = value.type.Enumerated; level = value.type.Enumerated;
object_index = object_index =
Binary_Value_Instance_To_Index(wp_data-> Binary_Value_Instance_To_Index
object_instance); (wp_data->object_instance);
priority--; priority--;
/* NOTE: this Binary value has no priority array */ /* NOTE: this Binary value has no priority array */
Present_Value[object_index] = level; Present_Value[object_index] = level;
+2 -2
View File
@@ -510,8 +510,8 @@ bool Device_Write_Property(
case PROP_OBJECT_IDENTIFIER: case PROP_OBJECT_IDENTIFIER:
if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) { if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) {
if ((value.type.Object_Id.type == OBJECT_DEVICE) && if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
(Device_Set_Object_Instance_Number(value.type.Object_Id. (Device_Set_Object_Instance_Number(value.type.
instance))) { Object_Id.instance))) {
/* we could send an I-Am broadcast to let the world know */ /* we could send an I-Am broadcast to let the world know */
status = true; status = true;
} else { } else {
+2 -1
View File
@@ -261,7 +261,8 @@ bool bip_init(
bip_set_port(htons((0xBAC0)); bip_set_port(htons((0xBAC0));
/* assumes that the driver has already been initialized */ /* assumes that the driver has already been initialized */
sock_fd = socket(AF_INET, SOCK_DGRAM, IPROTO_UDP); sock_fd = socket(AF_INET, SOCK_DGRAM, IPROTO_UDP);
bip_set_socket(sock_fd); if (sock_fd < 0) bip_set_socket(sock_fd);
if (sock_fd < 0)
return false; return false;
/* bind the socket to the local port number and IP address */ /* bind the socket to the local port number and IP address */
sin.sin_family = AF_INET; sin.sin_addr.s_addr = htonl(INADDR_ANY); sin.sin_family = AF_INET; sin.sin_addr.s_addr = htonl(INADDR_ANY);
+2 -2
View File
@@ -429,8 +429,8 @@ bool Binary_Output_Write_Property(
priority = wp_data->priority; priority = wp_data->priority;
if (priority && (priority <= BACNET_MAX_PRIORITY)) { if (priority && (priority <= BACNET_MAX_PRIORITY)) {
priority--; priority--;
Binary_Output_Present_Value_Set(wp_data-> Binary_Output_Present_Value_Set
object_instance, level, priority); (wp_data->object_instance, level, priority);
} else if (priority == 6) { } else if (priority == 6) {
status = false; status = false;
/* Command priority 6 is reserved for use by Minimum On/Off /* Command priority 6 is reserved for use by Minimum On/Off
+9 -9
View File
@@ -35,7 +35,7 @@
#include "apdu.h" #include "apdu.h"
#include "wp.h" /* WriteProperty handling */ #include "wp.h" /* WriteProperty handling */
#include "rp.h" /* ReadProperty handling */ #include "rp.h" /* ReadProperty handling */
#include "dcc.h" /* DeviceCommunicationControl handling */ #include "dcc.h" /* DeviceCommunicationControl handling */
#include "version.h" #include "version.h"
#include "device.h" /* me */ #include "device.h" /* me */
#include "handlers.h" #include "handlers.h"
@@ -833,8 +833,8 @@ bool Device_Write_Property_Local(
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
if ((value.type.Object_Id.type == OBJECT_DEVICE) && if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
(Device_Set_Object_Instance_Number(value.type.Object_Id. (Device_Set_Object_Instance_Number(value.type.
instance))) { Object_Id.instance))) {
/* we could send an I-Am broadcast to let the world know */ /* we could send an I-Am broadcast to let the world know */
status = true; status = true;
} else { } else {
@@ -868,8 +868,8 @@ bool Device_Write_Property_Local(
WPValidateString(&value, MAX_DEV_NAME_LEN, false, WPValidateString(&value, MAX_DEV_NAME_LEN, false,
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
Device_Set_Object_Name(characterstring_value(&value.type. Device_Set_Object_Name(characterstring_value(&value.
Character_String), type.Character_String),
characterstring_length(&value.type.Character_String)); characterstring_length(&value.type.Character_String));
} }
break; break;
@@ -878,8 +878,8 @@ bool Device_Write_Property_Local(
WPValidateString(&value, MAX_DEV_LOC_LEN, true, WPValidateString(&value, MAX_DEV_LOC_LEN, true,
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
Device_Set_Location(characterstring_value(&value.type. Device_Set_Location(characterstring_value(&value.
Character_String), type.Character_String),
characterstring_length(&value.type.Character_String)); characterstring_length(&value.type.Character_String));
} }
break; break;
@@ -889,8 +889,8 @@ bool Device_Write_Property_Local(
WPValidateString(&value, MAX_DEV_DESC_LEN, true, WPValidateString(&value, MAX_DEV_DESC_LEN, true,
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
Device_Set_Description(characterstring_value(&value.type. Device_Set_Description(characterstring_value(&value.
Character_String), type.Character_String),
characterstring_length(&value.type.Character_String)); characterstring_length(&value.type.Character_String));
} }
break; break;
+2 -2
View File
@@ -44,7 +44,7 @@ static uint8_t Ethernet_Broadcast[MAX_MAC_LEN] =
/* The OUI 00-00-5E has been allocated to IANA. */ /* The OUI 00-00-5E has been allocated to IANA. */
/* my local device data - MAC address */ /* my local device data - MAC address */
static uint8_t Ethernet_MAC_Address[MAX_MAC_LEN] = static uint8_t Ethernet_MAC_Address[MAX_MAC_LEN] =
{0x00, 0x00, 0x5E, 0x00, 0x00, 0x01}; { 0x00, 0x00, 0x5E, 0x00, 0x00, 0x01 };
/* status of the link */ /* status of the link */
static int32_t Ethernet_Status = R_ETHER_ERROR; static int32_t Ethernet_Status = R_ETHER_ERROR;
@@ -167,7 +167,7 @@ uint16_t ethernet_receive(
if (!ethernet_valid()) if (!ethernet_valid())
return 0; return 0;
received_bytes = R_Ether_Read(0, (void *)buf); received_bytes = R_Ether_Read(0, (void *) buf);
if (received_bytes == 0) if (received_bytes == 0)
return 0; return 0;
+24 -24
View File
@@ -42,40 +42,40 @@ void led_on(
{ {
switch (index) { switch (index) {
case 4: case 4:
R_IO_PORT_Write( LED4, LED_ON ); R_IO_PORT_Write(LED4, LED_ON);
break; break;
case 5: case 5:
R_IO_PORT_Write( LED5, LED_ON ); R_IO_PORT_Write(LED5, LED_ON);
break; break;
case 6: case 6:
R_IO_PORT_Write( LED6, LED_ON ); R_IO_PORT_Write(LED6, LED_ON);
break; break;
case 7: case 7:
R_IO_PORT_Write( LED7, LED_ON ); R_IO_PORT_Write(LED7, LED_ON);
break; break;
case 8: case 8:
R_IO_PORT_Write( LED8, LED_ON ); R_IO_PORT_Write(LED8, LED_ON);
break; break;
case 9: case 9:
R_IO_PORT_Write( LED9, LED_ON ); R_IO_PORT_Write(LED9, LED_ON);
break; break;
case 10: case 10:
R_IO_PORT_Write( LED10, LED_ON ); R_IO_PORT_Write(LED10, LED_ON);
break; break;
case 11: case 11:
R_IO_PORT_Write( LED11, LED_ON ); R_IO_PORT_Write(LED11, LED_ON);
break; break;
case 12: case 12:
R_IO_PORT_Write( LED12, LED_ON ); R_IO_PORT_Write(LED12, LED_ON);
break; break;
case 13: case 13:
R_IO_PORT_Write( LED13, LED_ON ); R_IO_PORT_Write(LED13, LED_ON);
break; break;
case 14: case 14:
R_IO_PORT_Write( LED14, LED_ON ); R_IO_PORT_Write(LED14, LED_ON);
break; break;
case 15: case 15:
R_IO_PORT_Write( LED15, LED_ON ); R_IO_PORT_Write(LED15, LED_ON);
break; break;
default: default:
break; break;
@@ -96,40 +96,40 @@ void led_off(
{ {
switch (index) { switch (index) {
case 4: case 4:
R_IO_PORT_Write( LED4, LED_OFF ); R_IO_PORT_Write(LED4, LED_OFF);
break; break;
case 5: case 5:
R_IO_PORT_Write( LED5, LED_OFF ); R_IO_PORT_Write(LED5, LED_OFF);
break; break;
case 6: case 6:
R_IO_PORT_Write( LED6, LED_OFF ); R_IO_PORT_Write(LED6, LED_OFF);
break; break;
case 7: case 7:
R_IO_PORT_Write( LED7, LED_OFF ); R_IO_PORT_Write(LED7, LED_OFF);
break; break;
case 8: case 8:
R_IO_PORT_Write( LED8, LED_OFF ); R_IO_PORT_Write(LED8, LED_OFF);
break; break;
case 9: case 9:
R_IO_PORT_Write( LED9, LED_OFF ); R_IO_PORT_Write(LED9, LED_OFF);
break; break;
case 10: case 10:
R_IO_PORT_Write( LED10, LED_OFF ); R_IO_PORT_Write(LED10, LED_OFF);
break; break;
case 11: case 11:
R_IO_PORT_Write( LED11, LED_OFF ); R_IO_PORT_Write(LED11, LED_OFF);
break; break;
case 12: case 12:
R_IO_PORT_Write( LED12, LED_OFF ); R_IO_PORT_Write(LED12, LED_OFF);
break; break;
case 13: case 13:
R_IO_PORT_Write( LED13, LED_OFF ); R_IO_PORT_Write(LED13, LED_OFF);
break; break;
case 14: case 14:
R_IO_PORT_Write( LED14, LED_OFF ); R_IO_PORT_Write(LED14, LED_OFF);
break; break;
case 15: case 15:
R_IO_PORT_Write( LED15, LED_OFF ); R_IO_PORT_Write(LED15, LED_OFF);
break; break;
default: default:
break; break;
+2 -1
View File
@@ -30,7 +30,8 @@
#include "led.h" #include "led.h"
/** Main function of BACnet demo for RX62N evaluation board */ /** Main function of BACnet demo for RX62N evaluation board */
int main(void) int main(
void)
{ {
InitialiseLCD(); InitialiseLCD();
ClearLCD(); ClearLCD();
+7 -11
View File
@@ -30,7 +30,8 @@
static volatile uint32_t Millisecond_Counter; static volatile uint32_t Millisecond_Counter;
static volatile uint8_t Millisecond_Counter_Byte; static volatile uint8_t Millisecond_Counter_Byte;
/* forward prototype for interrupt service routine */ /* forward prototype for interrupt service routine */
void int_cmt0_isr(void); void int_cmt0_isr(
void);
/************************************************************************* /*************************************************************************
* Description: Timer Interrupt Handler * Description: Timer Interrupt Handler
@@ -49,7 +50,8 @@ static void timer_interrupt_handler(
* Returns: nothing * Returns: nothing
* Notes: none * Notes: none
*************************************************************************/ *************************************************************************/
void int_cmt0_isr(void) void int_cmt0_isr(
void)
{ {
timer_interrupt_handler(); timer_interrupt_handler();
} }
@@ -92,15 +94,9 @@ void timer_init(
bool err = true; bool err = true;
/* CMT is configured for a 1ms interval, and executes the callback /* CMT is configured for a 1ms interval, and executes the callback
function CB_CompareMatch on every compare match */ function CB_CompareMatch on every compare match */
err &= R_CMT_Create( err &= R_CMT_Create(3, PDL_CMT_PERIOD, 1E-3, int_cmt0_isr, 3);
3,
PDL_CMT_PERIOD,
1E-3,
int_cmt0_isr,
3
);
/* Halt in while loop when RPDL errors detected */ /* Halt in while loop when RPDL errors detected */
while(!err); while (!err);
} }
+54 -42
View File
@@ -65,7 +65,8 @@ static bool Auto_Mode_Enabled;
* RETURN: true if automode enabled * RETURN: true if automode enabled
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
bool automac_enabled(void) bool automac_enabled(
void)
{ {
return Auto_Mode_Enabled; return Auto_Mode_Enabled;
} }
@@ -75,7 +76,8 @@ bool automac_enabled(void)
* RETURN: nothing * RETURN: nothing
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
void automac_enabled_set(bool status) void automac_enabled_set(
bool status)
{ {
Auto_Mode_Enabled = status; Auto_Mode_Enabled = status;
} }
@@ -85,7 +87,8 @@ void automac_enabled_set(bool status)
* RETURN: true if full * RETURN: true if full
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
bool automac_pfm_cycle_complete(void) bool automac_pfm_cycle_complete(
void)
{ {
return PFM_Cycle_Complete; return PFM_Cycle_Complete;
} }
@@ -95,13 +98,13 @@ bool automac_pfm_cycle_complete(void)
* RETURN: true if used * RETURN: true if used
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
static bool automac_address_used(uint8_t mac) static bool automac_address_used(
uint8_t mac)
{ {
bool status = false; bool status = false;
if (mac < MAC_SLOTS_MAX) { if (mac < MAC_SLOTS_MAX) {
if ((Auto_MAC_Data[mac].emitter) || if ((Auto_MAC_Data[mac].emitter) || (Auto_MAC_Data[mac].reserved) ||
(Auto_MAC_Data[mac].reserved) ||
(Auto_MAC_Data[mac].token)) { (Auto_MAC_Data[mac].token)) {
status = true; status = true;
} }
@@ -115,13 +118,13 @@ static bool automac_address_used(uint8_t mac)
* RETURN: true if valid * RETURN: true if valid
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
bool automac_free_address_valid(uint8_t mac) bool automac_free_address_valid(
uint8_t mac)
{ {
bool status = false; bool status = false;
if (mac < MAC_SLOTS_MAX) { if (mac < MAC_SLOTS_MAX) {
if ((Auto_MAC_Data[mac].pfm) && if ((Auto_MAC_Data[mac].pfm) && (!automac_address_used(mac))) {
(!automac_address_used(mac))) {
status = true; status = true;
} }
} }
@@ -134,11 +137,12 @@ bool automac_free_address_valid(uint8_t mac)
* RETURN: Next_Station, or 255 if there are no next stations * RETURN: Next_Station, or 255 if there are no next stations
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
uint8_t automac_next_station(uint8_t mac) uint8_t automac_next_station(
uint8_t mac)
{ {
uint8_t i = 0; /* loop counter */ uint8_t i = 0; /* loop counter */
uint8_t next_station = 255; /* return value */ uint8_t next_station = 255; /* return value */
uint8_t test_station = 0; /* station number to test for token */ uint8_t test_station = 0; /* station number to test for token */
test_station = (mac + 1) % 128; test_station = (mac + 1) % 128;
for (i = 0; i < MAC_SLOTS_MAX; i++) { for (i = 0; i < MAC_SLOTS_MAX; i++) {
@@ -157,7 +161,8 @@ uint8_t automac_next_station(uint8_t mac)
* RETURN: Number of free MAC addresses * RETURN: Number of free MAC addresses
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
uint8_t automac_free_address_count(void) uint8_t automac_free_address_count(
void)
{ {
uint8_t i = 0; uint8_t i = 0;
uint8_t slots = 0; uint8_t slots = 0;
@@ -176,7 +181,8 @@ uint8_t automac_free_address_count(void)
* RETURN: Number of free MAC addresses * RETURN: Number of free MAC addresses
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
uint8_t automac_free_address_mac(uint8_t count) uint8_t automac_free_address_mac(
uint8_t count)
{ {
uint8_t i = 0; uint8_t i = 0;
uint8_t slots = 0; uint8_t slots = 0;
@@ -200,7 +206,8 @@ uint8_t automac_free_address_mac(uint8_t count)
* RETURN: free MAC addresses * RETURN: free MAC addresses
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
uint8_t automac_free_address_random(void) uint8_t automac_free_address_random(
void)
{ {
uint8_t count = 0; uint8_t count = 0;
uint8_t random_count = 0; uint8_t random_count = 0;
@@ -208,7 +215,7 @@ uint8_t automac_free_address_random(void)
count = automac_free_address_count(); count = automac_free_address_count();
if (count) { if (count) {
random_count = rand()%count; random_count = rand() % count;
mac = automac_free_address_mac(random_count); mac = automac_free_address_mac(random_count);
} }
@@ -220,7 +227,8 @@ uint8_t automac_free_address_random(void)
* RETURN: MAC addresses * RETURN: MAC addresses
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
uint8_t automac_address(void) uint8_t automac_address(
void)
{ {
return My_MAC_Address; return My_MAC_Address;
} }
@@ -230,7 +238,8 @@ uint8_t automac_address(void)
* RETURN: MAC addresses * RETURN: MAC addresses
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
void automac_address_set(uint8_t mac) void automac_address_set(
uint8_t mac)
{ {
My_MAC_Address = mac; My_MAC_Address = mac;
} }
@@ -240,7 +249,8 @@ void automac_address_set(uint8_t mac)
* RETURN: MAC addresses * RETURN: MAC addresses
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
uint16_t automac_time_slot(void) uint16_t automac_time_slot(
void)
{ {
return My_Time_Slot; return My_Time_Slot;
} }
@@ -250,12 +260,14 @@ uint16_t automac_time_slot(void)
* RETURN: MAC addresses * RETURN: MAC addresses
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
void automac_address_init(void) void automac_address_init(
void)
{ {
My_MAC_Address = MAC_SLOTS_OFFSET + rand()%(MAC_SLOTS_MAX-MAC_SLOTS_OFFSET); My_MAC_Address =
MAC_SLOTS_OFFSET + rand() % (MAC_SLOTS_MAX - MAC_SLOTS_OFFSET);
/* at least as long as a dropped token - worst case */ /* at least as long as a dropped token - worst case */
My_Time_Slot = Tno_token + (MAC_SLOTS_MAX * Tslot); My_Time_Slot = Tno_token + (MAC_SLOTS_MAX * Tslot);
My_Time_Slot += (uint16_t)My_MAC_Address * Tslot; My_Time_Slot += (uint16_t) My_MAC_Address *Tslot;
} }
/**************************************************************************** /****************************************************************************
@@ -263,7 +275,8 @@ void automac_address_init(void)
* RETURN: nothing * RETURN: nothing
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
void automac_pfm_set(uint8_t mac) void automac_pfm_set(
uint8_t mac)
{ {
if (mac < MAC_SLOTS_MAX) { if (mac < MAC_SLOTS_MAX) {
if (Auto_MAC_Data[mac].pfm) { if (Auto_MAC_Data[mac].pfm) {
@@ -281,7 +294,8 @@ void automac_pfm_set(uint8_t mac)
* RETURN: nothing * RETURN: nothing
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
void automac_token_set(uint8_t mac) void automac_token_set(
uint8_t mac)
{ {
if (mac < MAC_SLOTS_MAX) { if (mac < MAC_SLOTS_MAX) {
Auto_MAC_Data[mac].token = true; Auto_MAC_Data[mac].token = true;
@@ -293,7 +307,8 @@ void automac_token_set(uint8_t mac)
* RETURN: nothing * RETURN: nothing
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
void automac_emitter_set(uint8_t mac) void automac_emitter_set(
uint8_t mac)
{ {
if (mac < MAC_SLOTS_MAX) { if (mac < MAC_SLOTS_MAX) {
Auto_MAC_Data[mac].emitter = true; Auto_MAC_Data[mac].emitter = true;
@@ -305,7 +320,8 @@ void automac_emitter_set(uint8_t mac)
* RETURN: nothing * RETURN: nothing
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
void automac_init(void) void automac_init(
void)
{ {
uint8_t i = 0; uint8_t i = 0;
@@ -359,34 +375,31 @@ void test_Auto_MAC(
srand(42); srand(42);
mac = automac_free_address_random(); mac = automac_free_address_random();
ct_test(pTest, mac == 255); ct_test(pTest, mac == 255);
automac_pfm_set(MAC_SLOTS_OFFSET+1); automac_pfm_set(MAC_SLOTS_OFFSET + 1);
mac = automac_free_address_mac(0); mac = automac_free_address_mac(0);
ct_test(pTest, mac == (MAC_SLOTS_OFFSET+1)); ct_test(pTest, mac == (MAC_SLOTS_OFFSET + 1));
mac = automac_free_address_random(); mac = automac_free_address_random();
ct_test(pTest, mac == (MAC_SLOTS_OFFSET+1)); ct_test(pTest, mac == (MAC_SLOTS_OFFSET + 1));
/* test 2 free addresses */ /* test 2 free addresses */
automac_pfm_set(MAC_SLOTS_OFFSET+2); automac_pfm_set(MAC_SLOTS_OFFSET + 2);
mac = automac_free_address_mac(0); mac = automac_free_address_mac(0);
ct_test(pTest, mac == (MAC_SLOTS_OFFSET+1)); ct_test(pTest, mac == (MAC_SLOTS_OFFSET + 1));
mac = automac_free_address_mac(1); mac = automac_free_address_mac(1);
ct_test(pTest, mac == (MAC_SLOTS_OFFSET+2)); ct_test(pTest, mac == (MAC_SLOTS_OFFSET + 2));
mac = automac_free_address_random(); mac = automac_free_address_random();
ct_test(pTest, ct_test(pTest, (mac == (MAC_SLOTS_OFFSET + 1)) ||
(mac == (MAC_SLOTS_OFFSET+1)) || (mac == (MAC_SLOTS_OFFSET + 2)));
(mac == (MAC_SLOTS_OFFSET+2)));
/* test 3 free addresses */ /* test 3 free addresses */
automac_pfm_set(126); automac_pfm_set(126);
mac = automac_free_address_mac(0); mac = automac_free_address_mac(0);
ct_test(pTest, mac == (MAC_SLOTS_OFFSET+1)); ct_test(pTest, mac == (MAC_SLOTS_OFFSET + 1));
mac = automac_free_address_mac(1); mac = automac_free_address_mac(1);
ct_test(pTest, mac == (MAC_SLOTS_OFFSET+2)); ct_test(pTest, mac == (MAC_SLOTS_OFFSET + 2));
mac = automac_free_address_mac(2); mac = automac_free_address_mac(2);
ct_test(pTest, mac == 126); ct_test(pTest, mac == 126);
mac = automac_free_address_random(); mac = automac_free_address_random();
ct_test(pTest, ct_test(pTest, (mac == (MAC_SLOTS_OFFSET + 1)) ||
(mac == (MAC_SLOTS_OFFSET+1))|| (mac == (MAC_SLOTS_OFFSET + 2)) || (mac == 126));
(mac == (MAC_SLOTS_OFFSET+2))||
(mac == 126));
/* test the stored address */ /* test the stored address */
mac = automac_address(); mac = automac_address();
ct_test(pTest, mac < MAC_SLOTS_MAX); ct_test(pTest, mac < MAC_SLOTS_MAX);
@@ -423,4 +436,3 @@ int main(
} }
#endif #endif
#endif #endif
+32 -17
View File
@@ -34,26 +34,41 @@
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
void automac_init(void); void automac_init(
void);
bool automac_free_address_valid(uint8_t mac); bool automac_free_address_valid(
uint8_t automac_free_address_count(void); uint8_t mac);
uint8_t automac_free_address_mac(uint8_t count); uint8_t automac_free_address_count(
uint8_t automac_free_address_random(void); void);
void automac_pfm_set(uint8_t mac); uint8_t automac_free_address_mac(
void automac_token_set(uint8_t mac); uint8_t count);
void automac_emitter_set(uint8_t mac); uint8_t automac_free_address_random(
uint8_t automac_next_station(uint8_t mac); void);
uint8_t automac_address(void); void automac_pfm_set(
void automac_address_set(uint8_t mac); uint8_t mac);
void automac_address_init(void); void automac_token_set(
uint16_t automac_time_slot(void); uint8_t mac);
bool automac_pfm_cycle_complete(void); void automac_emitter_set(
bool automac_enabled(void); uint8_t mac);
void automac_enabled_set(bool status); uint8_t automac_next_station(
uint8_t mac);
uint8_t automac_address(
void);
void automac_address_set(
uint8_t mac);
void automac_address_init(
void);
uint16_t automac_time_slot(
void);
bool automac_pfm_cycle_complete(
void);
bool automac_enabled(
void);
void automac_enabled_set(
bool status);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif #endif
+3 -3
View File
@@ -222,7 +222,7 @@ bool Binary_Output_Out_Of_Service(
/* note: the object name must be unique within this device */ /* note: the object name must be unique within this device */
bool Binary_Output_Object_Name( bool Binary_Output_Object_Name(
uint32_t object_instance, uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name) BACNET_CHARACTER_STRING * object_name)
{ {
static char text_string[16] = "BO-0"; /* okay for single thread */ static char text_string[16] = "BO-0"; /* okay for single thread */
bool status = false; bool status = false;
@@ -430,8 +430,8 @@ bool Binary_Output_Write_Property(
priority = wp_data->priority; priority = wp_data->priority;
if (priority && (priority <= BACNET_MAX_PRIORITY)) { if (priority && (priority <= BACNET_MAX_PRIORITY)) {
priority--; priority--;
Binary_Output_Present_Value_Set(wp_data-> Binary_Output_Present_Value_Set
object_instance, level, priority); (wp_data->object_instance, level, priority);
} else if (priority == 6) { } else if (priority == 6) {
status = false; status = false;
/* Command priority 6 is reserved for use by Minimum On/Off /* Command priority 6 is reserved for use by Minimum On/Off

Some files were not shown because too many files have changed in this diff Show More