Added uBASIC-Plus program object example to STM32F4xx. (#967)

This commit is contained in:
Steve Karg
2025-04-16 12:03:42 -05:00
committed by GitHub
parent a923e3cec9
commit 54bf9b79c6
37 changed files with 7613 additions and 1112 deletions
+61 -41
View File
@@ -1,14 +1,11 @@
/**************************************************************************
*
* Copyright (C) 2011 Steve Karg <skarg@users.sourceforge.net>
*
* SPDX-License-Identifier: MIT
*
*********************************************************************/
/** @file device.c Base "class" for handling all BACnet objects belonging
* to a BACnet device, as well as Device-specific properties. */
/**
* @file
* @brief Base "class" for handling all BACnet objects belonging
* to a BACnet device, as well as Device-specific properties.
* @author Steve Karg
* @date 2021
* @copyright SPDX-License-Identifier: MIT
*/
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
@@ -33,12 +30,12 @@
#include "bacnet/basic/object/ms-input.h"
#include "bacnet/basic/object/mso.h"
#include "bacnet/basic/object/msv.h"
#include "bacnet/basic/object/program.h"
#if (BACNET_PROTOCOL_REVISION >= 17)
#include "bacnet/basic/object/netport.h"
#endif
#include "bacnet/basic/object/device.h"
/* clang-format off */
static struct my_object_functions {
BACNET_OBJECT_TYPE Object_Type;
@@ -93,6 +90,10 @@ static struct my_object_functions {
Multistate_Value_Index_To_Instance, Multistate_Value_Valid_Instance,
Multistate_Value_Object_Name, Multistate_Value_Read_Property,
Multistate_Value_Write_Property, Multistate_Value_Property_Lists},
{ OBJECT_PROGRAM, Program_Init, Program_Count,
Program_Index_To_Instance, Program_Valid_Instance,
Program_Object_Name, Program_Read_Property,
Program_Write_Property, Program_Property_Lists},
#if (BACNET_PROTOCOL_REVISION >= 17)
{ OBJECT_NETWORK_PORT, Network_Port_Init, Network_Port_Count,
Network_Port_Index_To_Instance, Network_Port_Valid_Instance,
@@ -121,14 +122,27 @@ static uint8_t Device_UUID[16];
static const int Device_Properties_Required[] = {
/* required properties for this object */
PROP_OBJECT_IDENTIFIER,
PROP_OBJECT_NAME, PROP_OBJECT_TYPE, PROP_SYSTEM_STATUS, PROP_VENDOR_NAME,
PROP_VENDOR_IDENTIFIER, PROP_MODEL_NAME, PROP_FIRMWARE_REVISION,
PROP_APPLICATION_SOFTWARE_VERSION, PROP_PROTOCOL_VERSION,
PROP_PROTOCOL_REVISION, PROP_PROTOCOL_SERVICES_SUPPORTED,
PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED, PROP_OBJECT_LIST,
PROP_MAX_APDU_LENGTH_ACCEPTED, PROP_SEGMENTATION_SUPPORTED,
PROP_APDU_TIMEOUT, PROP_NUMBER_OF_APDU_RETRIES, PROP_DEVICE_ADDRESS_BINDING,
PROP_DATABASE_REVISION, -1 };
PROP_OBJECT_NAME,
PROP_OBJECT_TYPE,
PROP_SYSTEM_STATUS,
PROP_VENDOR_NAME,
PROP_VENDOR_IDENTIFIER,
PROP_MODEL_NAME,
PROP_FIRMWARE_REVISION,
PROP_APPLICATION_SOFTWARE_VERSION,
PROP_PROTOCOL_VERSION,
PROP_PROTOCOL_REVISION,
PROP_PROTOCOL_SERVICES_SUPPORTED,
PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED,
PROP_OBJECT_LIST,
PROP_MAX_APDU_LENGTH_ACCEPTED,
PROP_SEGMENTATION_SUPPORTED,
PROP_APDU_TIMEOUT,
PROP_NUMBER_OF_APDU_RETRIES,
PROP_DEVICE_ADDRESS_BINDING,
PROP_DATABASE_REVISION,
-1
};
static const int Device_Properties_Optional[] = {
/* optional properties for this object */
@@ -141,7 +155,8 @@ static const int Device_Properties_Optional[] = {
PROP_LOCAL_TIME,
PROP_UTC_OFFSET,
PROP_DAYLIGHT_SAVINGS_STATUS,
-1 };
-1
};
static const int Device_Properties_Proprietary[] = { -1 };
@@ -153,8 +168,8 @@ static const int Device_Properties_Proprietary[] = { -1 };
* @return Pointer to the group of object helper functions that implement this
* type of Object.
*/
static struct my_object_functions *Device_Objects_Find_Functions(
BACNET_OBJECT_TYPE Object_Type)
static struct my_object_functions *
Device_Objects_Find_Functions(BACNET_OBJECT_TYPE Object_Type)
{
struct my_object_functions *pObject = NULL;
@@ -182,7 +197,8 @@ static struct my_object_functions *Device_Objects_Find_Functions(
* list, separately, the Required, Optional, and Proprietary object
* properties with their counts.
*/
void Device_Objects_Property_List(BACNET_OBJECT_TYPE object_type,
void Device_Objects_Property_List(
BACNET_OBJECT_TYPE object_type,
uint32_t object_instance,
struct special_property_list_t *pPropertyList)
{
@@ -200,8 +216,9 @@ void Device_Objects_Property_List(BACNET_OBJECT_TYPE object_type,
pObject = Device_Objects_Find_Functions(object_type);
if ((pObject != NULL) && (pObject->Object_RPM_List != NULL)) {
pObject->Object_RPM_List(&pPropertyList->Required.pList,
&pPropertyList->Optional.pList, &pPropertyList->Proprietary.pList);
pObject->Object_RPM_List(
&pPropertyList->Required.pList, &pPropertyList->Optional.pList,
&pPropertyList->Proprietary.pList);
}
/* Fetch the counts if available otherwise zero them */
@@ -430,8 +447,9 @@ bool Device_Set_Object_Instance_Number(uint32_t object_id)
if (object_id <= BACNET_MAX_INSTANCE) {
Object_Instance_Number = object_id;
} else
} else {
status = false;
}
return status;
}
@@ -656,7 +674,8 @@ int Device_Object_List_Element_Encode(
* Object.
* @return True on success or else False if not found.
*/
bool Device_Valid_Object_Name(const BACNET_CHARACTER_STRING *object_name1,
bool Device_Valid_Object_Name(
const BACNET_CHARACTER_STRING *object_name1,
BACNET_OBJECT_TYPE *object_type,
uint32_t *object_instance)
{
@@ -675,7 +694,7 @@ bool Device_Valid_Object_Name(const BACNET_CHARACTER_STRING *object_name1,
pObject = Device_Objects_Find_Functions((BACNET_OBJECT_TYPE)type);
if ((pObject != NULL) && (pObject->Object_Name != NULL) &&
(pObject->Object_Name(instance, &object_name2) &&
characterstring_same(object_name1, &object_name2))) {
characterstring_same(object_name1, &object_name2))) {
found = true;
if (object_type) {
*object_type = type;
@@ -716,7 +735,8 @@ bool Device_Valid_Object_Id(
* @param object_name [out] The Object Name found for this child Object.
* @return True on success or else False if not found.
*/
bool Device_Object_Name_Copy(BACNET_OBJECT_TYPE object_type,
bool Device_Object_Name_Copy(
BACNET_OBJECT_TYPE object_type,
uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name)
{
@@ -811,7 +831,8 @@ int Device_Read_Property_Local(BACNET_READ_PROPERTY_DATA *rpdata)
bitstring_init(&bit_string);
for (i = 0; i < MAX_BACNET_SERVICES_SUPPORTED; i++) {
/* automatic lookup based on handlers set */
bitstring_set_bit(&bit_string, (uint8_t)i,
bitstring_set_bit(
&bit_string, (uint8_t)i,
apdu_service_supported((BACNET_SERVICES_SUPPORTED)i));
}
apdu_len = encode_application_bitstring(&apdu[0], &bit_string);
@@ -836,9 +857,9 @@ int Device_Read_Property_Local(BACNET_READ_PROPERTY_DATA *rpdata)
break;
case PROP_OBJECT_LIST:
count = Device_Object_List_Count();
apdu_len = bacnet_array_encode(rpdata->object_instance,
rpdata->array_index, Device_Object_List_Element_Encode, count,
apdu, apdu_max);
apdu_len = bacnet_array_encode(
rpdata->object_instance, rpdata->array_index,
Device_Object_List_Element_Encode, count, apdu, apdu_max);
if (apdu_len == BACNET_STATUS_ABORT) {
rpdata->error_code =
ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
@@ -893,8 +914,7 @@ int Device_Read_Property_Local(BACNET_READ_PROPERTY_DATA *rpdata)
break;
case PROP_DAYLIGHT_SAVINGS_STATUS:
datetime_local(&bdate, &btime, &utc_offset_minutes, &dst_active);
apdu_len =
encode_application_boolean(&apdu[0], dst_active);
apdu_len = encode_application_boolean(&apdu[0], dst_active);
break;
default:
rpdata->error_class = ERROR_CLASS_PROPERTY;
@@ -949,16 +969,16 @@ static int Read_Property_Common(
encode_application_character_string(&apdu[0], &char_string);
break;
case PROP_OBJECT_TYPE:
apdu_len = encode_application_enumerated(
&apdu[0], rpdata->object_type);
apdu_len =
encode_application_enumerated(&apdu[0], rpdata->object_type);
break;
#if (BACNET_PROTOCOL_REVISION >= 14)
case PROP_PROPERTY_LIST:
Device_Objects_Property_List(
rpdata->object_type, rpdata->object_instance, &property_list);
apdu_len = property_list_encode(rpdata,
property_list.Required.pList, property_list.Optional.pList,
property_list.Proprietary.pList);
apdu_len = property_list_encode(
rpdata, property_list.Required.pList,
property_list.Optional.pList, property_list.Proprietary.pList);
break;
#endif
default: