Added WriteGroup service and Channel object interfaces (#829)

This commit is contained in:
Steve Karg
2024-10-25 10:43:29 -05:00
committed by GitHub
parent 9397cfaafb
commit 3329dff337
89 changed files with 4334 additions and 1022 deletions
File diff suppressed because it is too large Load Diff
+12 -98
View File
@@ -15,89 +15,9 @@
/* BACnet Stack API */
#include "bacnet/rp.h"
#include "bacnet/wp.h"
#include "bacnet/write_group.h"
#include "bacnet/basic/object/lo.h"
/* BACNET_CHANNEL_VALUE decodes WriteProperty service requests
Choose the datatypes that your application supports */
#if !( \
defined(CHANNEL_NUMERIC) || defined(CHANNEL_NULL) || \
defined(CHANNEL_BOOLEAN) || defined(CHANNEL_UNSIGNED) || \
defined(CHANNEL_SIGNED) || defined(CHANNEL_REAL) || \
defined(CHANNEL_DOUBLE) || defined(CHANNEL_OCTET_STRING) || \
defined(CHANNEL_CHARACTER_STRING) || defined(CHANNEL_BIT_STRING) || \
defined(CHANNEL_ENUMERATED) || defined(CHANNEL_DATE) || \
defined(CHANNEL_TIME) || defined(CHANNEL_OBJECT_ID) || \
defined(CHANNEL_LIGHTING_COMMAND) || defined(CHANNEL_XY_COLOR) || \
defined(CHANNEL_COLOR_COMMAND))
#define CHANNEL_NUMERIC
#endif
#if defined(CHANNEL_NUMERIC)
#define CHANNEL_NULL
#define CHANNEL_BOOLEAN
#define CHANNEL_UNSIGNED
#define CHANNEL_SIGNED
#define CHANNEL_REAL
#define CHANNEL_DOUBLE
#define CHANNEL_ENUMERATED
#define CHANNEL_LIGHTING_COMMAND
#define CHANNEL_COLOR_COMMAND
#define CHANNEL_XY_COLOR
#endif
typedef struct BACnet_Channel_Value_t {
uint8_t tag;
union {
/* NULL - not needed as it is encoded in the tag alone */
#if defined(CHANNEL_BOOLEAN)
bool Boolean;
#endif
#if defined(CHANNEL_UNSIGNED)
uint32_t Unsigned_Int;
#endif
#if defined(CHANNEL_SIGNED)
int32_t Signed_Int;
#endif
#if defined(CHANNEL_REAL)
float Real;
#endif
#if defined(CHANNEL_DOUBLE)
double Double;
#endif
#if defined(CHANNEL_OCTET_STRING)
BACNET_OCTET_STRING Octet_String;
#endif
#if defined(CHANNEL_CHARACTER_STRING)
BACNET_CHARACTER_STRING Character_String;
#endif
#if defined(CHANNEL_BIT_STRING)
BACNET_BIT_STRING Bit_String;
#endif
#if defined(CHANNEL_ENUMERATED)
uint32_t Enumerated;
#endif
#if defined(CHANNEL_DATE)
BACNET_DATE Date;
#endif
#if defined(CHANNEL_TIME)
BACNET_TIME Time;
#endif
#if defined(CHANNEL_OBJECT_ID)
BACNET_OBJECT_ID Object_Id;
#endif
#if defined(CHANNEL_LIGHTING_COMMAND)
BACNET_LIGHTING_COMMAND Lighting_Command;
#endif
#if defined(CHANNEL_COLOR_COMMAND)
BACNET_COLOR_COMMAND Color_Command;
#endif
#if defined(CHANNEL_XY_COLOR)
BACNET_XY_COLOR XY_Color;
#endif
} type;
/* simple linked list if needed */
struct BACnet_Channel_Value_t *next;
} BACNET_CHANNEL_VALUE;
#include "bacnet/channel_value.h"
#ifdef __cplusplus
extern "C" {
@@ -128,13 +48,19 @@ BACNET_STACK_EXPORT
int Channel_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata);
BACNET_STACK_EXPORT
bool Channel_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data);
BACNET_STACK_EXPORT
void Channel_Write_Group(
BACNET_WRITE_GROUP_DATA *data,
uint32_t change_list_index,
BACNET_GROUP_CHANNEL_VALUE *change_list);
BACNET_STACK_EXPORT
BACNET_CHANNEL_VALUE *Channel_Present_Value(uint32_t object_instance);
BACNET_STACK_EXPORT
bool Channel_Present_Value_Set(
BACNET_WRITE_PROPERTY_DATA *wp_data,
const BACNET_APPLICATION_DATA_VALUE *value);
uint32_t object_instance,
uint8_t priority,
const BACNET_CHANNEL_VALUE *value);
BACNET_STACK_EXPORT
bool Channel_Out_Of_Service(uint32_t object_instance);
@@ -169,22 +95,10 @@ Channel_Control_Groups_Element(uint32_t object_instance, int32_t array_index);
BACNET_STACK_EXPORT
bool Channel_Control_Groups_Element_Set(
uint32_t object_instance, int32_t array_index, uint16_t value);
BACNET_STACK_EXPORT
bool Channel_Value_Copy(
BACNET_CHANNEL_VALUE *cvalue, const BACNET_APPLICATION_DATA_VALUE *value);
BACNET_STACK_EXPORT
int Channel_Value_Encode(
uint8_t *apdu, int apdu_max, const BACNET_CHANNEL_VALUE *value);
BACNET_STACK_EXPORT
int Channel_Coerce_Data_Encode(
uint8_t *apdu,
size_t apdu_size,
const BACNET_APPLICATION_DATA_VALUE *value,
BACNET_APPLICATION_TAG tag);
BACNET_STACK_EXPORT
bool Channel_Write_Member_Value(
BACNET_WRITE_PROPERTY_DATA *wp_data,
const BACNET_APPLICATION_DATA_VALUE *value);
BACNET_WRITE_PROPERTY_DATA *wp_data, const BACNET_CHANNEL_VALUE *value);
BACNET_STACK_EXPORT
void Channel_Write_Property_Internal_Callback_Set(write_property_function cb);
+111
View File
@@ -0,0 +1,111 @@
/**
* @file
* @brief The WriteGroup-Request service handler
* @author Steve Karg <skarg@users.sourceforge.net>
* @date October 2024
* @copyright SPDX-License-Identifier: MIT
*/
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
#include "bacnet/bacdcode.h"
#include "bacnet/apdu.h"
#include "bacnet/npdu.h"
#include "bacnet/abort.h"
#include "bacnet/write_group.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/sys/debug.h"
/* WriteGroup-Request notification callbacks list */
static BACNET_WRITE_GROUP_NOTIFICATION Write_Group_Notification_Head;
/**
* @brief Print the contents of a WriteGroup-Request
* @param data [in] The decoded WriteGroup-Request message
*/
void handler_write_group_print_data(BACNET_WRITE_GROUP_DATA *data)
{
if (!data) {
return;
}
debug_printf(
"WriteGroup:group-number=%lu\r\n", (unsigned long)data->group_number);
debug_printf(
"WriteGroup:write-priority=%lu\r\n",
(unsigned long)data->write_priority);
}
/**
* @brief generic callback for WriteGroup-Request iterator
* @param data [in] The contents of the WriteGroup-Request message
* @param change_list_index [in] The index of the current value in the change
* list
* @param change_list [in] The current value in the change list
*/
static void handler_write_group_notification_callback(
BACNET_WRITE_GROUP_DATA *data,
uint32_t change_list_index,
BACNET_GROUP_CHANNEL_VALUE *change_list)
{
BACNET_WRITE_GROUP_NOTIFICATION *head;
handler_write_group_print_data(data);
head = &Write_Group_Notification_Head;
do {
if (head->callback) {
head->callback(data, change_list_index, change_list);
}
head = head->next;
} while (head);
}
/**
* @brief Add a WriteGroup notification callback
* @param cb - WriteGroup notification callback to be added
*/
void handler_write_group_notification_add(BACNET_WRITE_GROUP_NOTIFICATION *cb)
{
BACNET_WRITE_GROUP_NOTIFICATION *head;
head = &Write_Group_Notification_Head;
do {
if (head->next == cb) {
/* already here! */
break;
} else if (!head->next) {
/* first available free node */
head->next = cb;
break;
}
head = head->next;
} while (head);
}
/**
* @brief A basic WriteGroup-Request service handler
* @param service_request [in] The contents of the service request
* @param service_len [in] The length of the service request
* @param src [in] The source of the message
*/
void handler_write_group(
uint8_t *service_request, uint16_t service_len, BACNET_ADDRESS *src)
{
BACNET_WRITE_GROUP_DATA data = { 0 };
int len = 0;
(void)src;
debug_printf("Received WriteGroup-Request!\n");
len = bacnet_write_group_service_request_decode_iterate(
service_request, service_len, &data,
handler_write_group_notification_callback);
if (len <= 0) {
debug_printf("WriteGroup-Request failed to decode!\n");
}
}
+36
View File
@@ -0,0 +1,36 @@
/**
* @file
* @brief The WriteGroup-Request service handler
* @author Steve Karg <skarg@users.sourceforge.net>
* @date October 2024
* @copyright SPDX-License-Identifier: MIT
*/
#ifndef HANDLER_WRITE_GROUP_H
#define HANDLER_WRITE_GROUP_H
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdint.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
#include "bacnet/apdu.h"
#include "bacnet/write_group.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
BACNET_STACK_EXPORT
void handler_write_group(
uint8_t *service_request, uint16_t service_len, BACNET_ADDRESS *src);
BACNET_STACK_EXPORT
void handler_write_group_print_data(BACNET_WRITE_GROUP_DATA *data);
BACNET_STACK_EXPORT
void handler_write_group_notification_add(BACNET_WRITE_GROUP_NOTIFICATION *cb);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+62
View File
@@ -0,0 +1,62 @@
/**
* @file
* @brief Header file for a basic BACnet WriteGroup-Reqeust service send
* @author Steve Karg
* @date October 2024
* @copyright SPDX-License-Identifier: MIT
*/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
#include "bacnet/bacdcode.h"
#include "bacnet/npdu.h"
#include "bacnet/apdu.h"
#include "bacnet/dcc.h"
#include "bacnet/write_group.h"
/* some demo stuff needed */
#include "bacnet/basic/binding/address.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/datalink/datalink.h"
int Send_Write_Group(BACNET_ADDRESS *dest, const BACNET_WRITE_GROUP_DATA *data)
{
int len = 0;
int pdu_len = 0;
int bytes_sent = 0;
BACNET_NPDU_DATA npdu_data;
BACNET_ADDRESS my_address;
size_t apdu_size;
if (!dcc_communication_enabled()) {
return bytes_sent;
}
datalink_get_my_address(&my_address);
/* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(
&Handler_Transmit_Buffer[0], dest, &my_address, &npdu_data);
/* encode the APDU portion of the packet */
Handler_Transmit_Buffer[pdu_len++] = PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST;
Handler_Transmit_Buffer[pdu_len++] = SERVICE_UNCONFIRMED_WRITE_GROUP;
apdu_size = sizeof(Handler_Transmit_Buffer) - pdu_len;
len = bacnet_write_group_service_request_encode(
&Handler_Transmit_Buffer[pdu_len], apdu_size, data);
pdu_len += len;
bytes_sent = datalink_send_pdu(
dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
#if PRINT_ENABLED
fprintf(
stderr, "Failed to Send WriteGroup-Request (%s)!\n",
strerror(errno));
#endif
}
return bytes_sent;
}
+30
View File
@@ -0,0 +1,30 @@
/**
* @file
* @brief Header file for a basic BACnet WriteGroup-Reqeust service send
* @author Steve Karg
* @date October 2024
* @copyright SPDX-License-Identifier: MIT
*/
#ifndef BACNET_SERVICE_SEND_WRITE_GROUP_H
#define BACNET_SERVICE_SEND_WRITE_GROUP_H
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdint.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
#include "bacnet/write_group.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
BACNET_STACK_EXPORT
int Send_Write_Group(BACNET_ADDRESS *dest, const BACNET_WRITE_GROUP_DATA *data);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+2
View File
@@ -52,6 +52,7 @@
#include "bacnet/basic/service/h_whois.h"
#include "bacnet/basic/service/h_wp.h"
#include "bacnet/basic/service/h_wpm.h"
#include "bacnet/basic/service/h_write_group.h"
/* application layer service send helpers */
#include "bacnet/basic/service/s_abort.h"
@@ -82,6 +83,7 @@
#include "bacnet/basic/service/s_whois.h"
#include "bacnet/basic/service/s_wp.h"
#include "bacnet/basic/service/s_wpm.h"
#include "bacnet/basic/service/s_write_group.h"
/** @defgroup MISCHNDLR Miscellaneous Service Handlers
* Various utilities and functions to support the service handlers