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:
Steve Karg
2021-02-10 10:58:47 -06:00
committed by GitHub
parent 80114088f9
commit 117db88ce6
9 changed files with 825 additions and 23 deletions
+45 -21
View File
@@ -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;
}
+3
View File
@@ -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
}