Corrected Multi-State Input and Output object Present_Value and number of states handling after being reminded at the BACnet Plugfest that "The Present_Value property shall always have a value greater than zero."
This commit is contained in:
@@ -43,10 +43,11 @@
|
|||||||
#define MAX_MULTISTATE_INPUTS 1
|
#define MAX_MULTISTATE_INPUTS 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* how many states? 0-253 is 254 states */
|
/* how many states? 1 to 254 states - 0 is not allowed. */
|
||||||
#ifndef MULTISTATE_NUMBER_OF_STATES
|
#ifndef MULTISTATE_NUMBER_OF_STATES
|
||||||
#define MULTISTATE_NUMBER_OF_STATES (254)
|
#define MULTISTATE_NUMBER_OF_STATES (254)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Here is our Present Value */
|
/* Here is our Present Value */
|
||||||
static uint8_t Present_Value[MAX_MULTISTATE_INPUTS];
|
static uint8_t Present_Value[MAX_MULTISTATE_INPUTS];
|
||||||
/* Writable out-of-service allows others to manipulate our Present Value */
|
/* Writable out-of-service allows others to manipulate our Present Value */
|
||||||
@@ -100,7 +101,7 @@ void Multistate_Input_Init(
|
|||||||
|
|
||||||
/* initialize all the analog output priority arrays to NULL */
|
/* initialize all the analog output priority arrays to NULL */
|
||||||
for (i = 0; i < MAX_MULTISTATE_INPUTS; i++) {
|
for (i = 0; i < MAX_MULTISTATE_INPUTS; i++) {
|
||||||
Present_Value[i] = 0;
|
Present_Value[i] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -153,7 +154,7 @@ bool Multistate_Input_Valid_Instance(
|
|||||||
uint32_t Multistate_Input_Present_Value(
|
uint32_t Multistate_Input_Present_Value(
|
||||||
uint32_t object_instance)
|
uint32_t object_instance)
|
||||||
{
|
{
|
||||||
uint32_t value = 0;
|
uint32_t value = 1;
|
||||||
unsigned index = 0; /* offset from instance lookup */
|
unsigned index = 0; /* offset from instance lookup */
|
||||||
|
|
||||||
index = Multistate_Input_Instance_To_Index(object_instance);
|
index = Multistate_Input_Instance_To_Index(object_instance);
|
||||||
@@ -173,7 +174,7 @@ bool Multistate_Input_Present_Value_Set(
|
|||||||
|
|
||||||
index = Multistate_Input_Instance_To_Index(object_instance);
|
index = Multistate_Input_Instance_To_Index(object_instance);
|
||||||
if (index < MAX_MULTISTATE_INPUTS) {
|
if (index < MAX_MULTISTATE_INPUTS) {
|
||||||
if (value < MULTISTATE_NUMBER_OF_STATES) {
|
if ((value > 0) && (value <= MULTISTATE_NUMBER_OF_STATES)) {
|
||||||
Present_Value[index] = (uint8_t) value;
|
Present_Value[index] = (uint8_t) value;
|
||||||
status = true;
|
status = true;
|
||||||
}
|
}
|
||||||
@@ -277,7 +278,9 @@ static char *Multistate_Input_State_Text(
|
|||||||
|
|
||||||
index = Multistate_Input_Instance_To_Index(object_instance);
|
index = Multistate_Input_Instance_To_Index(object_instance);
|
||||||
if ((index < MAX_MULTISTATE_INPUTS) &&
|
if ((index < MAX_MULTISTATE_INPUTS) &&
|
||||||
(state_index < MULTISTATE_NUMBER_OF_STATES)) {
|
(state_index > 0) &&
|
||||||
|
(state_index <= MULTISTATE_NUMBER_OF_STATES)) {
|
||||||
|
state_index--;
|
||||||
pName = State_Text[index][state_index];
|
pName = State_Text[index][state_index];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,7 +299,9 @@ bool Multistate_Input_State_Text_Set(
|
|||||||
|
|
||||||
index = Multistate_Input_Instance_To_Index(object_instance);
|
index = Multistate_Input_Instance_To_Index(object_instance);
|
||||||
if ((index < MAX_MULTISTATE_INPUTS) &&
|
if ((index < MAX_MULTISTATE_INPUTS) &&
|
||||||
(state_index < MULTISTATE_NUMBER_OF_STATES)) {
|
(state_index > 0) &&
|
||||||
|
(state_index <= MULTISTATE_NUMBER_OF_STATES)) {
|
||||||
|
state_index--;
|
||||||
status = true;
|
status = true;
|
||||||
if (new_name) {
|
if (new_name) {
|
||||||
for (i = 0; i < sizeof(State_Text[index][state_index]); i++) {
|
for (i = 0; i < sizeof(State_Text[index][state_index]); i++) {
|
||||||
@@ -402,7 +407,7 @@ int Multistate_Input_Read_Property(
|
|||||||
object_index =
|
object_index =
|
||||||
Multistate_Input_Instance_To_Index
|
Multistate_Input_Instance_To_Index
|
||||||
(rpdata->object_instance);
|
(rpdata->object_instance);
|
||||||
for (i = 0; i < MULTISTATE_NUMBER_OF_STATES; i++) {
|
for (i = 1; i <= MULTISTATE_NUMBER_OF_STATES; i++) {
|
||||||
characterstring_init_ansi(&char_string,
|
characterstring_init_ansi(&char_string,
|
||||||
Multistate_Input_State_Text(rpdata->object_instance,
|
Multistate_Input_State_Text(rpdata->object_instance,
|
||||||
i));
|
i));
|
||||||
@@ -427,7 +432,7 @@ int Multistate_Input_Read_Property(
|
|||||||
if (rpdata->array_index <= MULTISTATE_NUMBER_OF_STATES) {
|
if (rpdata->array_index <= MULTISTATE_NUMBER_OF_STATES) {
|
||||||
characterstring_init_ansi(&char_string,
|
characterstring_init_ansi(&char_string,
|
||||||
Multistate_Input_State_Text(rpdata->object_instance,
|
Multistate_Input_State_Text(rpdata->object_instance,
|
||||||
rpdata->array_index - 1));
|
rpdata->array_index));
|
||||||
apdu_len =
|
apdu_len =
|
||||||
encode_application_character_string(&apdu[0],
|
encode_application_character_string(&apdu[0],
|
||||||
&char_string);
|
&char_string);
|
||||||
|
|||||||
@@ -48,7 +48,7 @@
|
|||||||
|
|
||||||
/* NULL part of the array */
|
/* NULL part of the array */
|
||||||
#define MULTISTATE_NULL (255)
|
#define MULTISTATE_NULL (255)
|
||||||
/* how many states? 0-253 is 254 states */
|
/* how many states? 1 to 254 states, 0 is not allowed */
|
||||||
#define MULTISTATE_NUMBER_OF_STATES (254)
|
#define MULTISTATE_NUMBER_OF_STATES (254)
|
||||||
/* Here is our Priority Array.*/
|
/* Here is our Priority Array.*/
|
||||||
static uint8_t
|
static uint8_t
|
||||||
@@ -371,6 +371,7 @@ bool Multistate_Output_Write_Property(
|
|||||||
object. */
|
object. */
|
||||||
if (priority && (priority <= BACNET_MAX_PRIORITY) &&
|
if (priority && (priority <= BACNET_MAX_PRIORITY) &&
|
||||||
(priority != 6 /* reserved */ ) &&
|
(priority != 6 /* reserved */ ) &&
|
||||||
|
(value.type.Unsigned_Int > 0) &&
|
||||||
(value.type.Unsigned_Int <= MULTISTATE_NUMBER_OF_STATES)) {
|
(value.type.Unsigned_Int <= MULTISTATE_NUMBER_OF_STATES)) {
|
||||||
level = value.type.Unsigned_Int;
|
level = value.type.Unsigned_Int;
|
||||||
object_index =
|
object_index =
|
||||||
|
|||||||
Reference in New Issue
Block a user