Adding more functionality to Lighting Output object.
This commit is contained in:
+27
-25
@@ -538,10 +538,10 @@ typedef enum {
|
|||||||
UNITS_SQUARE_METERS_PER_NEWTON = 185,
|
UNITS_SQUARE_METERS_PER_NEWTON = 185,
|
||||||
UNITS_WATTS_PER_METER_PER_DEGREE_KELVIN = 189,
|
UNITS_WATTS_PER_METER_PER_DEGREE_KELVIN = 189,
|
||||||
UNITS_WATTS_PER_SQUARE_METER_DEGREE_KELVIN = 141
|
UNITS_WATTS_PER_SQUARE_METER_DEGREE_KELVIN = 141
|
||||||
/* Enumerated values 0-255 are reserved for definition by ASHRAE.
|
/* Enumerated values 0-255 are reserved for definition by ASHRAE. */
|
||||||
Enumerated values 256-65535 may be used by others subject to
|
/* Enumerated values 256-65535 may be used by others subject to */
|
||||||
the procedures and constraints described in Clause 23.
|
/* the procedures and constraints described in Clause 23. */
|
||||||
The last enumeration used in this version is 189. */
|
/* The last enumeration used in this version is 189. */
|
||||||
} BACNET_ENGINEERING_UNITS;
|
} BACNET_ENGINEERING_UNITS;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@@ -573,9 +573,9 @@ typedef enum {
|
|||||||
PROGRAM_ERROR_INTERNAL = 2,
|
PROGRAM_ERROR_INTERNAL = 2,
|
||||||
PROGRAM_ERROR_PROGRAM = 3,
|
PROGRAM_ERROR_PROGRAM = 3,
|
||||||
PROGRAM_ERROR_OTHER = 4
|
PROGRAM_ERROR_OTHER = 4
|
||||||
/* Enumerated values 0-63 are reserved for definition by ASHRAE. */
|
/* Enumerated values 0-63 are reserved for definition by ASHRAE. */
|
||||||
/* Enumerated values 64-65535 may be used by others subject to */
|
/* Enumerated values 64-65535 may be used by others subject to */
|
||||||
/* the procedures and constraints described in Clause 23. */
|
/* the procedures and constraints described in Clause 23. */
|
||||||
} BACNET_PROGRAM_ERROR;
|
} BACNET_PROGRAM_ERROR;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@@ -589,10 +589,12 @@ typedef enum {
|
|||||||
RELIABILITY_UNRELIABLE_OTHER = 7,
|
RELIABILITY_UNRELIABLE_OTHER = 7,
|
||||||
RELIABILITY_PROCESS_ERROR = 8,
|
RELIABILITY_PROCESS_ERROR = 8,
|
||||||
RELIABILITY_MULTI_STATE_FAULT = 9,
|
RELIABILITY_MULTI_STATE_FAULT = 9,
|
||||||
RELIABILITY_CONFIGURATION_ERROR = 10
|
RELIABILITY_CONFIGURATION_ERROR = 10,
|
||||||
/* Enumerated values 0-63 are reserved for definition by ASHRAE. */
|
RELIABILITY_COMMUNICATION_FAILURE = 12,
|
||||||
/* Enumerated values 64-65535 may be used by others subject to */
|
RELIABILITY_TRIPPED = 13
|
||||||
/* the procedures and constraints described in Clause 23. */
|
/* Enumerated values 0-63 are reserved for definition by ASHRAE. */
|
||||||
|
/* Enumerated values 64-65535 may be used by others subject to */
|
||||||
|
/* the procedures and constraints described in Clause 23. */
|
||||||
} BACNET_RELIABILITY;
|
} BACNET_RELIABILITY;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@@ -608,13 +610,13 @@ typedef enum {
|
|||||||
EVENT_EXTENDED = 9,
|
EVENT_EXTENDED = 9,
|
||||||
EVENT_BUFFER_READY = 10,
|
EVENT_BUFFER_READY = 10,
|
||||||
EVENT_UNSIGNED_RANGE = 11
|
EVENT_UNSIGNED_RANGE = 11
|
||||||
/* Enumerated values 0-63 are reserved for definition by ASHRAE. */
|
/* Enumerated values 0-63 are reserved for definition by ASHRAE. */
|
||||||
/* Enumerated values 64-65535 may be used by others subject to */
|
/* Enumerated values 64-65535 may be used by others subject to */
|
||||||
/* the procedures and constraints described in Clause 23. */
|
/* the procedures and constraints described in Clause 23. */
|
||||||
/* It is expected that these enumerated values will correspond to */
|
/* It is expected that these enumerated values will correspond to */
|
||||||
/* the use of the complex-event-type CHOICE [6] of the */
|
/* the use of the complex-event-type CHOICE [6] of the */
|
||||||
/* BACnetNotificationParameters production. */
|
/* BACnetNotificationParameters production. */
|
||||||
/* The last enumeration used in this version is 11. */
|
/* The last enumeration used in this version is 11. */
|
||||||
} BACNET_EVENT_TYPE;
|
} BACNET_EVENT_TYPE;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@@ -641,9 +643,9 @@ typedef enum {
|
|||||||
LIFE_SAFETY_MODE_AUTOMATIC_RELEASE_DISABLED = 13,
|
LIFE_SAFETY_MODE_AUTOMATIC_RELEASE_DISABLED = 13,
|
||||||
LIFE_SAFETY_MODE_DEFAULT = 14,
|
LIFE_SAFETY_MODE_DEFAULT = 14,
|
||||||
MAX_LIFE_SAFETY_MODE = 14
|
MAX_LIFE_SAFETY_MODE = 14
|
||||||
/* Enumerated values 0-255 are reserved for definition by ASHRAE. */
|
/* Enumerated values 0-255 are reserved for definition by ASHRAE. */
|
||||||
/* Enumerated values 256-65535 may be used by others subject to */
|
/* Enumerated values 256-65535 may be used by others subject to */
|
||||||
/* procedures and constraints described in Clause 23. */
|
/* procedures and constraints described in Clause 23. */
|
||||||
} BACNET_LIFE_SAFETY_MODE;
|
} BACNET_LIFE_SAFETY_MODE;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@@ -689,9 +691,9 @@ typedef enum {
|
|||||||
LIFE_SAFETY_STATE_SUPERVISORY = 22,
|
LIFE_SAFETY_STATE_SUPERVISORY = 22,
|
||||||
LIFE_SAFETY_STATE_TEST_SUPERVISORY = 23,
|
LIFE_SAFETY_STATE_TEST_SUPERVISORY = 23,
|
||||||
MAX_LIFE_SAFETY_STATE = 0
|
MAX_LIFE_SAFETY_STATE = 0
|
||||||
/* Enumerated values 0-255 are reserved for definition by ASHRAE. */
|
/* Enumerated values 0-255 are reserved for definition by ASHRAE. */
|
||||||
/* Enumerated values 256-65535 may be used by others subject to */
|
/* Enumerated values 256-65535 may be used by others subject to */
|
||||||
/* procedures and constraints described in Clause 23. */
|
/* procedures and constraints described in Clause 23. */
|
||||||
} BACNET_LIFE_SAFETY_STATE;
|
} BACNET_LIFE_SAFETY_STATE;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@@ -751,7 +753,7 @@ typedef enum {
|
|||||||
OBJECT_TREND_LOG_MULTIPLE = 27,
|
OBJECT_TREND_LOG_MULTIPLE = 27,
|
||||||
OBJECT_LOAD_CONTROL = 28,
|
OBJECT_LOAD_CONTROL = 28,
|
||||||
OBJECT_STRUCTURED_VIEW = 29,
|
OBJECT_STRUCTURED_VIEW = 29,
|
||||||
/* what is object type 30? */
|
/* what is object type 30? */
|
||||||
OBJECT_LIGHTING_OUTPUT = 31,
|
OBJECT_LIGHTING_OUTPUT = 31,
|
||||||
/* Enumerated values 0-127 are reserved for definition by ASHRAE. */
|
/* Enumerated values 0-127 are reserved for definition by ASHRAE. */
|
||||||
/* Enumerated values 128-1023 may be used by others subject to */
|
/* Enumerated values 128-1023 may be used by others subject to */
|
||||||
|
|||||||
@@ -49,12 +49,12 @@
|
|||||||
of the optional parameters, we represent them interally as
|
of the optional parameters, we represent them interally as
|
||||||
integers. */
|
integers. */
|
||||||
typedef struct LightingCommand {
|
typedef struct LightingCommand {
|
||||||
BACNET_LIGHTING_OPERATION operation;
|
BACNET_LIGHTING_OPERATION operation;
|
||||||
uint8_t level; /* 0..100 percent, 255=not used */
|
uint8_t level; /* 0..100 percent, 255=not used */
|
||||||
uint8_t ramp_rate; /* 0..100 percent-per-second, 255=not used */
|
uint8_t ramp_rate; /* 0..100 percent-per-second, 255=not used */
|
||||||
uint8_t step_increment; /* 0..100 amount to step, 255=not used */
|
uint8_t step_increment; /* 0..100 amount to step, 255=not used */
|
||||||
uint16_t fade_time; /* 1..65535 seconds to transition, 0=not used */
|
uint16_t fade_time; /* 1..65535 seconds to transition, 0=not used */
|
||||||
uint16_t duration; /* 1..65535 minutes until relinquish, 0=not used */
|
uint16_t duration; /* 1..65535 minutes until relinquish, 0=not used */
|
||||||
} BACNET_LIGHTING_COMMAND;
|
} BACNET_LIGHTING_COMMAND;
|
||||||
|
|
||||||
/* Here is our Priority Array. They are supposed to be Real, but */
|
/* Here is our Priority Array. They are supposed to be Real, but */
|
||||||
@@ -76,6 +76,101 @@ static BACNET_LIGHTING_COMMAND Lighting_Command[MAX_LIGHTING_OUTPUTS];
|
|||||||
/* we need to have our arrays initialized before answering any calls */
|
/* we need to have our arrays initialized before answering any calls */
|
||||||
static bool Lighting_Output_Initialized = false;
|
static bool Lighting_Output_Initialized = false;
|
||||||
|
|
||||||
|
int Lighting_Output_Encode_Lighting_Command(uint8_t * apdu,
|
||||||
|
BACNET_LIGHTING_COMMAND * data)
|
||||||
|
{
|
||||||
|
int apdu_len = 0; /* total length of the apdu, return value */
|
||||||
|
int len = 0; /* total length of the apdu, return value */
|
||||||
|
float real_value = 0.0;
|
||||||
|
uint32_t unsigned_value = 0;
|
||||||
|
|
||||||
|
if (apdu) {
|
||||||
|
len = encode_context_enumerated(&apdu[apdu_len], 0,
|
||||||
|
data->operation);
|
||||||
|
apdu_len += len;
|
||||||
|
/* optional level? */
|
||||||
|
if (data->level != 255) {
|
||||||
|
real_value = data->level;
|
||||||
|
len = encode_context_real(&apdu[apdu_len], 1,
|
||||||
|
real_value);
|
||||||
|
apdu_len += len;
|
||||||
|
}
|
||||||
|
/* optional ramp-rate */
|
||||||
|
if (data->ramp_rate != 255) {
|
||||||
|
real_value = data->ramp_rate;
|
||||||
|
len = encode_context_real(&apdu[apdu_len], 2,
|
||||||
|
real_value);
|
||||||
|
apdu_len += len;
|
||||||
|
}
|
||||||
|
/* optional step increment */
|
||||||
|
if (data->step_increment != 255) {
|
||||||
|
real_value = data->step_increment;
|
||||||
|
len = encode_context_real(&apdu[apdu_len], 3,
|
||||||
|
real_value);
|
||||||
|
apdu_len += len;
|
||||||
|
}
|
||||||
|
/* optional fade time */
|
||||||
|
if (data->fade_time != 0) {
|
||||||
|
real_value = data->fade_time;
|
||||||
|
len = encode_context_real(&apdu[apdu_len], 4,
|
||||||
|
real_value);
|
||||||
|
apdu_len += len;
|
||||||
|
}
|
||||||
|
/* optional duration */
|
||||||
|
if (data->duration != 0) {
|
||||||
|
unsigned_value = data->duration;
|
||||||
|
len = encode_context_unsigned(&apdu[apdu_len], 5,
|
||||||
|
unsigned_value);
|
||||||
|
apdu_len += len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return apdu_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Lighting_Output_Decode_Lighting_Command(uint8_t * apdu,
|
||||||
|
unsigned apdu_max_len, BACNET_LIGHTING_COMMAND * data)
|
||||||
|
{
|
||||||
|
int len = 0;
|
||||||
|
int apdu_len = 0;
|
||||||
|
int tag_len = 0;
|
||||||
|
uint8_t tag_number = 0;
|
||||||
|
uint32_t len_value_type = 0;
|
||||||
|
int type = 0; /* for decoding */
|
||||||
|
int property = 0; /* for decoding */
|
||||||
|
uint32_t unsigned_value = 0;
|
||||||
|
int i = 0; /* loop counter */
|
||||||
|
float real_value = 0.0;
|
||||||
|
|
||||||
|
/* check for value pointers */
|
||||||
|
if (apdu_len && data) {
|
||||||
|
/* Tag 0: operation */
|
||||||
|
if (!decode_is_context_tag(&apdu[apdu_len], 0))
|
||||||
|
return -1;
|
||||||
|
len = decode_tag_number_and_value(&apdu[apdu_len],
|
||||||
|
&tag_number, &len_value_type);
|
||||||
|
apdu_len += len;
|
||||||
|
len = decode_enumerated(&apdu[apdu_len], len_value_type, &data->operation);
|
||||||
|
apdu_len += len;
|
||||||
|
/* Tag 1: level - OPTIONAL */
|
||||||
|
if (decode_is_context_tag(&apdu[apdu_len], 1)) {
|
||||||
|
len = decode_tag_number_and_value(&apdu[apdu_len],
|
||||||
|
&tag_number, &len_value_type);
|
||||||
|
apdu_len += len;
|
||||||
|
len = decode_real(&apdu[apdu_len], &real_value);
|
||||||
|
apdu_len += len;
|
||||||
|
data->level = real_value;
|
||||||
|
/* FIXME: are we going to flag errors in decoding values here? */
|
||||||
|
}
|
||||||
|
/* FIXME: finish me! */
|
||||||
|
/* Tag 2: */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Lighting_Output_Init(void)
|
void Lighting_Output_Init(void)
|
||||||
{
|
{
|
||||||
unsigned i, j;
|
unsigned i, j;
|
||||||
@@ -282,8 +377,8 @@ int Lighting_Output_Encode_Property_APDU(uint8_t * apdu,
|
|||||||
break;
|
break;
|
||||||
case PROP_OBJECT_NAME:
|
case PROP_OBJECT_NAME:
|
||||||
case PROP_DESCRIPTION:
|
case PROP_DESCRIPTION:
|
||||||
/* object name must be unique in this device. */
|
/* object name must be unique in this device. */
|
||||||
/* FIXME: description could be writable and different than object name */
|
/* FIXME: description could be writable and different than object name */
|
||||||
characterstring_init_ansi(&char_string,
|
characterstring_init_ansi(&char_string,
|
||||||
Lighting_Output_Name(object_instance));
|
Lighting_Output_Name(object_instance));
|
||||||
apdu_len = encode_tagged_character_string(&apdu[0], &char_string);
|
apdu_len = encode_tagged_character_string(&apdu[0], &char_string);
|
||||||
@@ -300,6 +395,10 @@ int Lighting_Output_Encode_Property_APDU(uint8_t * apdu,
|
|||||||
real_value = Lighting_Output_Progress_Value(object_instance);
|
real_value = Lighting_Output_Progress_Value(object_instance);
|
||||||
apdu_len = encode_tagged_real(&apdu[0], real_value);
|
apdu_len = encode_tagged_real(&apdu[0], real_value);
|
||||||
break;
|
break;
|
||||||
|
case PROP_LIGHTING_COMMAND:
|
||||||
|
apdu_len = Lighting_Output_Encode_Lighting_Command(&apdu[0],
|
||||||
|
&Lighting_Command[object_instance]);
|
||||||
|
break;
|
||||||
case PROP_STATUS_FLAGS:
|
case PROP_STATUS_FLAGS:
|
||||||
bitstring_init(&bit_string);
|
bitstring_init(&bit_string);
|
||||||
bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM, false);
|
bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM, false);
|
||||||
@@ -428,7 +527,13 @@ bool Lighting_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
|
|||||||
status =
|
status =
|
||||||
Lighting_Output_Present_Value_Relinquish(wp_data->
|
Lighting_Output_Present_Value_Relinquish(wp_data->
|
||||||
object_instance, wp_data->priority);
|
object_instance, wp_data->priority);
|
||||||
if (!status) {
|
if (wp_data->priority == 6) {
|
||||||
|
/* Command priority 6 is reserved for use by Minimum On/Off
|
||||||
|
algorithm and may not be used for other purposes in any
|
||||||
|
object. */
|
||||||
|
*error_class = ERROR_CLASS_PROPERTY;
|
||||||
|
*error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
|
||||||
|
} else if (!status) {
|
||||||
*error_class = ERROR_CLASS_PROPERTY;
|
*error_class = ERROR_CLASS_PROPERTY;
|
||||||
*error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
|
*error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
|
||||||
}
|
}
|
||||||
@@ -437,6 +542,12 @@ bool Lighting_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
|
|||||||
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
|
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case PROP_LIGHTING_COMMAND:
|
||||||
|
/* FIXME: error checking? */
|
||||||
|
Lighting_Output_Decode_Lighting_Command(wp_data->application_data,
|
||||||
|
wp_data->application_data_len,
|
||||||
|
&Lighting_Command[wp_data->object_instance]);
|
||||||
|
break;
|
||||||
case PROP_OUT_OF_SERVICE:
|
case PROP_OUT_OF_SERVICE:
|
||||||
if (value.tag == BACNET_APPLICATION_TAG_BOOLEAN) {
|
if (value.tag == BACNET_APPLICATION_TAG_BOOLEAN) {
|
||||||
object_index =
|
object_index =
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user