Skip to content

Commit

Permalink
Add skeleton for BACnet Command Object
Browse files Browse the repository at this point in the history
  • Loading branch information
abelino committed Feb 6, 2025
1 parent 1fb9f22 commit 72a0478
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ set(SOURCES
src/main.c
src/port.c
src/protocol/decode_call.c
src/protocol/enum.c)
src/protocol/enum.c
src/object/command.c)

# build
project(bacnetd)
Expand Down
23 changes: 23 additions & 0 deletions src/bacnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "bacnet.h"
#include "log.h"
#include "protocol/decode_call.h"
#include "object/command.h"

#define REPLY_OK(reply) \
ei_x_encode_atom(reply, "ok")
Expand Down Expand Up @@ -271,6 +272,28 @@ static object_functions_t SUPPORTED_OBJECT_TABLE[] = {
.Object_Delete = Routed_Multistate_Input_Delete,
.Object_Timer = NULL,
},
{
.Object_Type = OBJECT_COMMAND,
.Object_Init = command_init,
.Object_Count = command_count,
.Object_Index_To_Instance = command_index_to_instance,
.Object_Valid_Instance = command_valid_instance,
.Object_Name = command_object_name,
.Object_Read_Property = command_read_property,
.Object_Write_Property = command_write_property,
.Object_RPM_List = command_property_lists,
.Object_RR_Info = NULL,
.Object_Iterator = NULL,
.Object_Value_List = NULL,
.Object_COV = NULL,
.Object_COV_Clear = NULL,
.Object_Intrinsic_Reporting = NULL,
.Object_Add_List_Element = NULL,
.Object_Remove_List_Element = NULL,
.Object_Create = NULL,
.Object_Delete = NULL,
.Object_Timer = NULL,
},
};

static int init_service_handlers()
Expand Down
109 changes: 109 additions & 0 deletions src/object/command.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#include <bacnet/bacdef.h>
#include <bacnet/rp.h>
#include <bacnet/wp.h>

/**
* @brief Attempts to set required, optional and proprietary command properties.
*
* @note All params are sentinel terminated list of integers.
* @param required - BACnet required properties for a Command object.
* @param optional - BACnet optional properties for a Command object.
* @param proprietary - BACnet proprietary properties for a Command object.
*/
void command_property_lists(
const int **required,
const int **optional,
const int **proprietary
) {
static const int required_list[] = {
PROP_OBJECT_IDENTIFIER,
PROP_OBJECT_NAME,
PROP_OBJECT_TYPE,
PROP_PRESENT_VALUE,
PROP_IN_PROCESS,
PROP_ALL_WRITES_SUCCESSFUL,
PROP_ACTION,
-1
};

static const int optional_list[] = { -1 };
static const int proprietary_list[] = { -1 };

if (required) *required = required_list;
if (optional) *optional = optional_list;
if (proprietary) *proprietary = proprietary_list;
}

/**
* @brief Initializes a Command object.
*/
void command_init(void)
{
return;
}

/**
* @brief Returns the count of Command objects for the currently selected
* Device.
*/
unsigned command_count(void)
{
return -1;
}

/**
* @brief Get the Commands's instace number from its index.
*
* @param index - Index of Command object from within the Devices Object's list.
*
* @return BACnet Object instance number.
*/
uint32_t command_index_to_instance(unsigned index)
{
return -1;
}

/**
* @brief Checks if the Object instance is a valid Command Object.
*
* @param instance - Object instance number.
*/
bool command_valid_instance(uint32_t instance)
{
return false;
}

/**
* @brief Retrieve the name of a Command Object.
*
* @param[in] instance - Object instance number.
* @param[out] name - The Objects's name.
*/
bool command_object_name(uint32_t instance, BACNET_CHARACTER_STRING *name)
{
return false;
}

/**
* @brief BACnet read-property handler for a Command Object.
*
* @param[out] data - Holds request and reply data.
*
* @return Byte count of the APDU or BACNET_STATUS_ERROR.
*/
int command_read_property(BACNET_READ_PROPERTY_DATA *data)
{
return -1;
}

/**
* @brief BACnet write-property handler for a Command Object.
*
* @param[out] data - Holds request and reply data.
*
* @return true if no errors occur.
*/
bool command_write_property(BACNET_WRITE_PROPERTY_DATA *data)
{
return false;
}
17 changes: 17 additions & 0 deletions src/object/command.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef BACNET_OBJECT_COMMAND_H
#define BACNET_OBJECT_COMMAND_H

void command_init(void);
unsigned command_count(void);
uint32_t command_index_to_instance(unsigned index);
bool command_valid_instance(uint32_t instance);
bool command_object_name(uint32_t instance, BACNET_CHARACTER_STRING *name);
int command_read_property(BACNET_READ_PROPERTY_DATA *data);
bool command_write_property(BACNET_WRITE_PROPERTY_DATA *data);

void command_property_lists(
const int **required,
const int **optional,
const int **proprietary);

#endif /* BACNET_OBJECT_COMMAND_H */

0 comments on commit 72a0478

Please sign in to comment.