Completed the implementation of object-instance and object index differentiation object/basic/ai.c module. Thanks, GauiStori! (#607)
This commit is contained in:
@@ -1,31 +1,16 @@
|
|||||||
/**************************************************************************
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief Analog Input Objects - customize for your use
|
||||||
|
* @author Steve Karg <skarg@users.sourceforge.net>
|
||||||
|
* @author Krzysztof Malorny <malornykrzysztof@gmail.com>
|
||||||
|
* @date 2005
|
||||||
|
* @section LICENSE
|
||||||
*
|
*
|
||||||
* Copyright (C) 2005 Steve Karg <skarg@users.sourceforge.net>
|
* Copyright (C) 2005 Steve Karg <skarg@users.sourceforge.net>
|
||||||
* Copyright (C) 2011 Krzysztof Malorny <malornykrzysztof@gmail.com>
|
* Copyright (C) 2011 Krzysztof Malorny <malornykrzysztof@gmail.com>
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* SPDX-License-Identifier: MIT
|
||||||
* a copy of this software and associated documentation files (the
|
*/
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included
|
|
||||||
* in all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
||||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
||||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
||||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
||||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*
|
|
||||||
*********************************************************************/
|
|
||||||
|
|
||||||
/* Analog Input Objects customize for your use */
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -250,12 +235,14 @@ void Analog_Input_Present_Value_Set(uint32_t object_instance, float value)
|
|||||||
bool Analog_Input_Object_Name(
|
bool Analog_Input_Object_Name(
|
||||||
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
|
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
|
||||||
{
|
{
|
||||||
|
unsigned int index = 0;
|
||||||
static char text_string[32] = "";
|
static char text_string[32] = "";
|
||||||
bool status = false;
|
bool status = false;
|
||||||
|
|
||||||
if (object_instance < MAX_ANALOG_INPUTS) {
|
index = Analog_Input_Instance_To_Index(object_instance);
|
||||||
if (AI_Descr[object_instance].Object_Name) {
|
if (index < MAX_ANALOG_INPUTS) {
|
||||||
status = characterstring_init_ansi(object_name, AI_Descr[object_instance].Object_Name);
|
if (AI_Descr[index].Object_Name) {
|
||||||
|
status = characterstring_init_ansi(object_name, AI_Descr[index].Object_Name);
|
||||||
} else {
|
} else {
|
||||||
snprintf(text_string, sizeof(text_string), "ANALOG INPUT %u",
|
snprintf(text_string, sizeof(text_string), "ANALOG INPUT %u",
|
||||||
object_instance);
|
object_instance);
|
||||||
@@ -276,10 +263,13 @@ bool Analog_Input_Object_Name(
|
|||||||
*/
|
*/
|
||||||
bool Analog_Input_Name_Set(uint32_t object_instance, char *new_name)
|
bool Analog_Input_Name_Set(uint32_t object_instance, char *new_name)
|
||||||
{
|
{
|
||||||
|
unsigned int index = 0;
|
||||||
bool status = false;
|
bool status = false;
|
||||||
if (object_instance < MAX_ANALOG_INPUTS) {
|
|
||||||
|
index = Analog_Input_Instance_To_Index(object_instance);
|
||||||
|
if (index < MAX_ANALOG_INPUTS) {
|
||||||
status = true;
|
status = true;
|
||||||
AI_Descr[object_instance].Object_Name = new_name;
|
AI_Descr[index].Object_Name = new_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
@@ -317,9 +307,11 @@ unsigned Analog_Input_Event_State(uint32_t object_instance)
|
|||||||
char *Analog_Input_Description(uint32_t object_instance)
|
char *Analog_Input_Description(uint32_t object_instance)
|
||||||
{
|
{
|
||||||
char *name = NULL;
|
char *name = NULL;
|
||||||
|
unsigned index = 0;
|
||||||
|
|
||||||
if (object_instance < MAX_ANALOG_INPUTS) {
|
index = Analog_Input_Instance_To_Index(object_instance);
|
||||||
name = AI_Descr[object_instance].Description;
|
if (index < MAX_ANALOG_INPUTS) {
|
||||||
|
name = AI_Descr[index].Description;
|
||||||
}
|
}
|
||||||
|
|
||||||
return name;
|
return name;
|
||||||
@@ -334,10 +326,12 @@ char *Analog_Input_Description(uint32_t object_instance)
|
|||||||
bool Analog_Input_Description_Set(uint32_t object_instance, char *new_name)
|
bool Analog_Input_Description_Set(uint32_t object_instance, char *new_name)
|
||||||
{
|
{
|
||||||
bool status = false; /* return value */
|
bool status = false; /* return value */
|
||||||
|
unsigned index = 0;
|
||||||
|
|
||||||
if (object_instance < MAX_ANALOG_INPUTS && new_name) {
|
index = Analog_Input_Instance_To_Index(object_instance);
|
||||||
|
if (index < MAX_ANALOG_INPUTS && new_name) {
|
||||||
|
AI_Descr[index].Description = new_name;
|
||||||
status = true;
|
status = true;
|
||||||
AI_Descr[object_instance].Description = new_name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
@@ -433,9 +427,11 @@ void Analog_Input_COV_Increment_Set(uint32_t object_instance, float value)
|
|||||||
uint16_t Analog_Input_Units(uint32_t object_instance)
|
uint16_t Analog_Input_Units(uint32_t object_instance)
|
||||||
{
|
{
|
||||||
uint16_t units = UNITS_NO_UNITS;
|
uint16_t units = UNITS_NO_UNITS;
|
||||||
|
unsigned index = 0;
|
||||||
|
|
||||||
if (object_instance < MAX_ANALOG_INPUTS) {
|
index = Analog_Input_Instance_To_Index(object_instance);
|
||||||
units = AI_Descr[object_instance].Units;
|
if (index < MAX_ANALOG_INPUTS) {
|
||||||
|
units = AI_Descr[index].Units;
|
||||||
}
|
}
|
||||||
|
|
||||||
return units;
|
return units;
|
||||||
@@ -452,9 +448,11 @@ uint16_t Analog_Input_Units(uint32_t object_instance)
|
|||||||
bool Analog_Input_Units_Set(uint32_t object_instance, uint16_t units)
|
bool Analog_Input_Units_Set(uint32_t object_instance, uint16_t units)
|
||||||
{
|
{
|
||||||
bool status = false;
|
bool status = false;
|
||||||
|
unsigned index = 0;
|
||||||
|
|
||||||
if (object_instance < MAX_ANALOG_INPUTS) {
|
index = Analog_Input_Instance_To_Index(object_instance);
|
||||||
AI_Descr[object_instance].Units = units;
|
if (index < MAX_ANALOG_INPUTS) {
|
||||||
|
AI_Descr[index].Units = units;
|
||||||
status = true;
|
status = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user