Adding more functionality to Lighting Output object.
This commit is contained in:
@@ -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 {
|
||||||
@@ -589,7 +589,9 @@ 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,
|
||||||
|
RELIABILITY_COMMUNICATION_FAILURE = 12,
|
||||||
|
RELIABILITY_TRIPPED = 13
|
||||||
/* 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. */
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -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