Feature/confirmed event notification app (#153)
* Initial ConfirmedEventNotification app * Fixed event argument processing * Adjust event argument processing. Move the common event arguments Enable text lookup for some event arguments. * Fix CMAKE for event app. Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
@@ -1228,6 +1228,25 @@ bool bactext_days_of_week_index(const char *search_name, unsigned *found_index)
|
||||
bacnet_days_of_week_names, search_name, found_index);
|
||||
}
|
||||
|
||||
INDTEXT_DATA bacnet_notify_type_names[] = {
|
||||
{ NOTIFY_ALARM, "alarm" },
|
||||
{ NOTIFY_EVENT, "event" },
|
||||
{ NOTIFY_ACK_NOTIFICATION, "ack-notification" },
|
||||
{ 0, NULL } };
|
||||
|
||||
const char *bactext_notify_type_name(unsigned index)
|
||||
{
|
||||
return indtext_by_index_default(
|
||||
bacnet_notify_type_names, index, ASHRAE_Reserved_String);
|
||||
}
|
||||
|
||||
bool bactext_notify_type_index(
|
||||
const char *search_name, unsigned *found_index)
|
||||
{
|
||||
return indtext_by_istring(
|
||||
bacnet_notify_type_names, search_name, found_index);
|
||||
}
|
||||
|
||||
INDTEXT_DATA bacnet_event_transition_names[] = { { TRANSITION_TO_OFFNORMAL,
|
||||
"offnormal" },
|
||||
{ TRANSITION_TO_NORMAL, "normal" }, { TRANSITION_TO_FAULT, "fault" },
|
||||
@@ -1257,6 +1276,50 @@ const char *bactext_event_state_name(unsigned index)
|
||||
bacnet_event_state_names, index, ASHRAE_Reserved_String);
|
||||
}
|
||||
|
||||
bool bactext_event_state_index(
|
||||
const char *search_name, unsigned *found_index)
|
||||
{
|
||||
return indtext_by_istring(
|
||||
bacnet_event_state_names, search_name, found_index);
|
||||
}
|
||||
|
||||
INDTEXT_DATA bacnet_event_type_names[] = {
|
||||
{ EVENT_CHANGE_OF_BITSTRING, "change-of-bitstring" },
|
||||
{ EVENT_CHANGE_OF_STATE, "change-of-state" },
|
||||
{ EVENT_CHANGE_OF_VALUE, "change-of-value" },
|
||||
{ EVENT_COMMAND_FAILURE, "command-failure" },
|
||||
{ EVENT_FLOATING_LIMIT, "floating-limit" },
|
||||
{ EVENT_CHANGE_OF_LIFE_SAFETY, "change-of-life-safety" },
|
||||
{ EVENT_EXTENDED, "extended" },
|
||||
{ EVENT_BUFFER_READY, "buffer-ready" },
|
||||
{ EVENT_UNSIGNED_RANGE, "unsigned-range" },
|
||||
{ EVENT_ACCESS_EVENT, "access-event" },
|
||||
{ EVENT_DOUBLE_OUT_OF_RANGE, "double-out-of-range" },
|
||||
{ EVENT_SIGNED_OUT_OF_RANGE, "signed-out-of-range" },
|
||||
{ EVENT_UNSIGNED_OUT_OF_RANGE, "unsigned-out-of-range" },
|
||||
{ EVENT_CHANGE_OF_CHARACTERSTRING, "change-of-characterstring" },
|
||||
{ EVENT_CHANGE_OF_STATUS_FLAGS, "change-of-status-flags" },
|
||||
{ EVENT_CHANGE_OF_RELIABILITY, "change-of-reliability" },
|
||||
{ EVENT_NONE, "none" },
|
||||
{ EVENT_CHANGE_OF_DISCRETE_VALUE, "change-of-discrete-value" },
|
||||
{ EVENT_CHANGE_OF_TIMER, "change-of-timer" },
|
||||
{ 0, NULL } };
|
||||
|
||||
const char *bactext_event_type_name(unsigned index)
|
||||
{
|
||||
return indtext_by_index_split_default(bacnet_event_type_names, index,
|
||||
EVENT_PROPRIETARY_MIN, ASHRAE_Reserved_String,
|
||||
Vendor_Proprietary_String);
|
||||
}
|
||||
|
||||
bool bactext_event_type_index(
|
||||
const char *search_name, unsigned *found_index)
|
||||
{
|
||||
return indtext_by_istring(
|
||||
bacnet_event_type_names, search_name, found_index);
|
||||
}
|
||||
|
||||
|
||||
INDTEXT_DATA bacnet_binary_present_value_names[] = {
|
||||
{ BINARY_INACTIVE, "inactive" }, { BINARY_ACTIVE, "active" }, { 0, NULL }
|
||||
};
|
||||
|
||||
@@ -119,9 +119,22 @@ extern "C" {
|
||||
const char *bactext_day_of_week_name(
|
||||
unsigned index);
|
||||
BACNET_STACK_EXPORT
|
||||
const char *bactext_notify_type_name(unsigned index);
|
||||
BACNET_STACK_EXPORT
|
||||
bool bactext_notify_type_index(
|
||||
const char *search_name, unsigned *found_index);
|
||||
BACNET_STACK_EXPORT
|
||||
const char *bactext_event_state_name(
|
||||
unsigned index);
|
||||
BACNET_STACK_EXPORT
|
||||
bool bactext_event_state_index(
|
||||
const char *search_name, unsigned *found_index);
|
||||
BACNET_STACK_EXPORT
|
||||
const char *bactext_event_type_name(unsigned index);
|
||||
BACNET_STACK_EXPORT
|
||||
bool bactext_event_type_index(
|
||||
const char *search_name, unsigned *found_index);
|
||||
BACNET_STACK_EXPORT
|
||||
const char *bactext_binary_present_value_name(
|
||||
unsigned index);
|
||||
BACNET_STACK_EXPORT
|
||||
|
||||
@@ -40,13 +40,15 @@
|
||||
/** Sends an Confirmed Alarm/Event Notification.
|
||||
* @ingroup EVNOTFCN
|
||||
*
|
||||
* @param device_id [in] ID of the destination device
|
||||
* @param pdu [in] the PDU buffer used for sending the message
|
||||
* @param pdu_size [in] Size of the PDU buffer
|
||||
* @param data [in] The information about the Event to be sent.
|
||||
* @param dest [in] BACNET_ADDRESS of the destination device
|
||||
* @return invoke id of outgoing message, or 0 if communication is disabled,
|
||||
* or no tsm slot is available.
|
||||
*/
|
||||
uint8_t Send_CEvent_Notify(
|
||||
uint32_t device_id, BACNET_EVENT_NOTIFICATION_DATA *data)
|
||||
uint8_t Send_CEvent_Notify_Address(uint8_t *pdu, uint16_t pdu_size,
|
||||
BACNET_EVENT_NOTIFICATION_DATA *data, BACNET_ADDRESS *dest)
|
||||
{
|
||||
int len = 0;
|
||||
int pdu_len = 0;
|
||||
@@ -54,45 +56,37 @@ uint8_t Send_CEvent_Notify(
|
||||
int bytes_sent = 0;
|
||||
#endif
|
||||
BACNET_NPDU_DATA npdu_data;
|
||||
BACNET_ADDRESS dest;
|
||||
BACNET_ADDRESS my_address;
|
||||
unsigned max_apdu = 0;
|
||||
bool status = false;
|
||||
uint8_t invoke_id = 0;
|
||||
|
||||
if (!dcc_communication_enabled()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* is the device bound? */
|
||||
status = address_get_by_device(device_id, &max_apdu, &dest);
|
||||
/* is there a tsm available? */
|
||||
if (status) {
|
||||
invoke_id = tsm_next_free_invokeID();
|
||||
if (!dest) {
|
||||
return 0;
|
||||
}
|
||||
/* is there a tsm available? */
|
||||
invoke_id = tsm_next_free_invokeID();
|
||||
if (invoke_id) {
|
||||
/* encode the NPDU portion of the packet */
|
||||
datalink_get_my_address(&my_address);
|
||||
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
|
||||
pdu_len = npdu_encode_pdu(
|
||||
&Handler_Transmit_Buffer[0], &dest, &my_address, &npdu_data);
|
||||
pdu_len = npdu_encode_pdu(pdu, dest, &my_address, &npdu_data);
|
||||
/* encode the APDU portion of the packet */
|
||||
len = cevent_notify_encode_apdu(
|
||||
&Handler_Transmit_Buffer[pdu_len], invoke_id, data);
|
||||
len = cevent_notify_encode_apdu(&pdu[pdu_len], invoke_id, data);
|
||||
pdu_len += len;
|
||||
/* will it fit in the sender?
|
||||
note: if there is a bottleneck router in between
|
||||
us and the destination, we won't know unless
|
||||
we have a way to check for that and update the
|
||||
max_apdu in the address binding table. */
|
||||
if ((unsigned)pdu_len < max_apdu) {
|
||||
tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest,
|
||||
&npdu_data, &Handler_Transmit_Buffer[0], (uint16_t)pdu_len);
|
||||
if ((uint16_t)pdu_len < pdu_size) {
|
||||
tsm_set_confirmed_unsegmented_transaction(invoke_id, dest,
|
||||
&npdu_data, pdu, (uint16_t)pdu_len);
|
||||
#if PRINT_ENABLED
|
||||
bytes_sent =
|
||||
#endif
|
||||
datalink_send_pdu(
|
||||
&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
|
||||
datalink_send_pdu(dest, &npdu_data, pdu, pdu_len);
|
||||
#if PRINT_ENABLED
|
||||
if (bytes_sent <= 0) {
|
||||
fprintf(stderr,
|
||||
@@ -113,3 +107,33 @@ uint8_t Send_CEvent_Notify(
|
||||
|
||||
return invoke_id;
|
||||
}
|
||||
|
||||
/** Sends an Confirmed Alarm/Event Notification.
|
||||
* @ingroup EVNOTFCN
|
||||
*
|
||||
* @param device_id [in] ID of the destination device
|
||||
* @param data [in] The information about the Event to be sent.
|
||||
* @return invoke id of outgoing message, or 0 if communication is disabled,
|
||||
* or no tsm slot is available.
|
||||
*/
|
||||
uint8_t Send_CEvent_Notify(
|
||||
uint32_t device_id, BACNET_EVENT_NOTIFICATION_DATA *data)
|
||||
{
|
||||
BACNET_ADDRESS dest = { 0 };
|
||||
unsigned max_apdu = 0;
|
||||
uint8_t invoke_id = 0;
|
||||
bool status = false;
|
||||
|
||||
/* is the device bound? */
|
||||
status = address_get_by_device(device_id, &max_apdu, &dest);
|
||||
if (status) {
|
||||
if (sizeof(Handler_Transmit_Buffer) < max_apdu) {
|
||||
max_apdu = sizeof(Handler_Transmit_Buffer);
|
||||
}
|
||||
invoke_id = Send_CEvent_Notify_Address(
|
||||
Handler_Transmit_Buffer, max_apdu,
|
||||
data, &dest);
|
||||
}
|
||||
|
||||
return invoke_id;
|
||||
}
|
||||
|
||||
@@ -46,6 +46,9 @@ extern "C" {
|
||||
BACNET_STACK_EXPORT
|
||||
uint8_t Send_CEvent_Notify(uint32_t device_id,
|
||||
BACNET_EVENT_NOTIFICATION_DATA* data);
|
||||
BACNET_STACK_EXPORT
|
||||
uint8_t Send_CEvent_Notify_Address(uint8_t *pdu, uint16_t pdu_size,
|
||||
BACNET_EVENT_NOTIFICATION_DATA *data, BACNET_ADDRESS *dest);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user