Updated Lighting Output object. Added Channel object. Not complete and not fully tested.
This commit is contained in:
@@ -46,6 +46,7 @@
|
||||
#include "bactext.h"
|
||||
#include "datetime.h"
|
||||
#include "bacstr.h"
|
||||
#include "lighting.h"
|
||||
|
||||
/** @file bacapp.c Utilities for the BACnet_Application_Data_Value */
|
||||
|
||||
@@ -145,6 +146,13 @@ int bacapp_encode_application_data(
|
||||
(int) value->type.Object_Id.type,
|
||||
value->type.Object_Id.instance);
|
||||
break;
|
||||
#endif
|
||||
#if defined (BACAPP_LIGHTING_COMMAND)
|
||||
case BACNET_APPLICATION_TAG_LIGHTING_COMMAND:
|
||||
apdu_len =
|
||||
lighting_command_encode(&apdu[0],
|
||||
&value->type.Lighting_Command);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
@@ -258,6 +266,14 @@ int bacapp_decode_data(
|
||||
value->type.Object_Id.instance = instance;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#if defined (BACAPP_LIGHTING_COMMAND)
|
||||
case BACNET_APPLICATION_TAG_LIGHTING_COMMAND:
|
||||
len =
|
||||
lighting_command_decode(
|
||||
&apdu[0], len_value_type,
|
||||
&value->type.Lighting_Command);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
@@ -536,6 +552,14 @@ int bacapp_encode_context_data_value(
|
||||
(int) value->type.Object_Id.type,
|
||||
value->type.Object_Id.instance);
|
||||
break;
|
||||
#endif
|
||||
#if defined (BACAPP_LIGHTING_COMMAND)
|
||||
case BACNET_APPLICATION_TAG_LIGHTING_COMMAND:
|
||||
apdu_len =
|
||||
lighting_command_encode_context(
|
||||
&apdu[0], context_tag_number,
|
||||
&value->type.Lighting_Command);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
@@ -879,6 +903,13 @@ bool bacapp_copy(
|
||||
dest_value->type.Object_Id.instance =
|
||||
src_value->type.Object_Id.instance;
|
||||
break;
|
||||
#endif
|
||||
#if defined (BACAPP_LIGHTING_COMMAND)
|
||||
case BACNET_APPLICATION_TAG_LIGHTING_COMMAND:
|
||||
status = lighting_command_copy(
|
||||
&dest_value->type.Lighting_Command,
|
||||
&src_value->type.Lighting_Command);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
status = false;
|
||||
@@ -1299,6 +1330,21 @@ int bacapp_snprintf_value(
|
||||
/* bytes were written. */
|
||||
ret_val = str_len - rem_str_len;
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_LIGHTING_COMMAND:
|
||||
if (!append_str(&p_str, &rem_str_len, "("))
|
||||
break;
|
||||
if (!append_str(&p_str, &rem_str_len,
|
||||
bactext_lighting_operation_name(value->type.
|
||||
Lighting_Command.operation))) {
|
||||
break;
|
||||
}
|
||||
/* FIXME: add the Lighting Command optional values */
|
||||
if (!append_str(&p_str, &rem_str_len, ")"))
|
||||
break;
|
||||
/* If we get here, then everything is OK. Indicate how many */
|
||||
/* bytes were written. */
|
||||
ret_val = str_len - rem_str_len;
|
||||
break;
|
||||
default:
|
||||
ret_val = 0;
|
||||
break;
|
||||
@@ -1466,6 +1512,9 @@ bool bacapp_parse_application_data(
|
||||
status = false;
|
||||
}
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_LIGHTING_COMMAND:
|
||||
/* FIXME: add parsing for lighting command */
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -1586,7 +1635,13 @@ bool bacapp_same_value(
|
||||
&test_value->type.Bit_String);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined (BACAPP_LIGHTING_COMMAND)
|
||||
case BACNET_APPLICATION_TAG_BIT_STRING:
|
||||
status = lighting_command_same(
|
||||
&value->type.Lighting_Command,
|
||||
&test_value->type.Lighting_Command);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
status = false;
|
||||
break;
|
||||
|
||||
@@ -1005,7 +1005,7 @@ INDTEXT_DATA bacnet_property_names[] = {
|
||||
,
|
||||
{PROP_DEFAULT_STEP_INCREMENT, "default-step-increment"}
|
||||
,
|
||||
{PROP_EGRESS_TIMER, "egress-timer"}
|
||||
{PROP_EGRESS_TIME, "egress-time"}
|
||||
,
|
||||
{PROP_IN_PROGRESS, "in-progress"}
|
||||
,
|
||||
@@ -2221,3 +2221,41 @@ const char *bactext_network_layer_msg_name(
|
||||
else
|
||||
return "Invalid Network Layer Message";
|
||||
}
|
||||
|
||||
INDTEXT_DATA bacnet_lighting_operation_names[] = {
|
||||
{BACNET_LIGHTS_NONE, "none"}
|
||||
,
|
||||
{BACNET_LIGHTS_FADE_TO, "fade-to"}
|
||||
,
|
||||
{BACNET_LIGHTS_RAMP_TO, "ramp-to"}
|
||||
,
|
||||
{BACNET_LIGHTS_STEP_UP, "step-up"}
|
||||
,
|
||||
{BACNET_LIGHTS_STEP_DOWN, "step-down"}
|
||||
,
|
||||
{BACNET_LIGHTS_STEP_ON, "step-on"}
|
||||
,
|
||||
{BACNET_LIGHTS_STEP_OFF, "step-off"}
|
||||
,
|
||||
{BACNET_LIGHTS_WARN, "warn"}
|
||||
,
|
||||
{BACNET_LIGHTS_WARN_OFF, "warn-off"}
|
||||
,
|
||||
{BACNET_LIGHTS_WARN_RELINQUISH, "warn-relinquish"}
|
||||
,
|
||||
{BACNET_LIGHTS_STOP, "stop"}
|
||||
,
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
const char *bactext_lighting_operation_name(
|
||||
unsigned index)
|
||||
{
|
||||
if (index < BACNET_LIGHTS_PROPRIETARY_FIRST)
|
||||
return indtext_by_index_default(network_layer_msg_names, index,
|
||||
ASHRAE_Reserved_String);
|
||||
else if (index <= BACNET_LIGHTS_PROPRIETARY_LAST)
|
||||
return Vendor_Proprietary_String;
|
||||
else
|
||||
return "Invalid BACnetLightingOperation";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,343 @@
|
||||
/*####COPYRIGHTBEGIN####
|
||||
-------------------------------------------
|
||||
Copyright (C) 2013 Steve Karg <skarg@users.sourceforge.net>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to:
|
||||
The Free Software Foundation, Inc.
|
||||
59 Temple Place - Suite 330
|
||||
Boston, MA 02111-1307, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or
|
||||
use macros or inline functions from this file, or you compile
|
||||
this file and link it with other works to produce a work based
|
||||
on this file, this file does not by itself cause the resulting
|
||||
work to be covered by the GNU General Public License. However
|
||||
the source code for this file must still be made available in
|
||||
accordance with section (3) of the GNU General Public License.
|
||||
|
||||
This exception does not invalidate any other reasons why a work
|
||||
based on this file might be covered by the GNU General Public
|
||||
License.
|
||||
-------------------------------------------
|
||||
####COPYRIGHTEND####*/
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include "lighting.h"
|
||||
#include "bacdcode.h"
|
||||
|
||||
/** @file lighting.c Manipulate BACnet lighting command values */
|
||||
|
||||
|
||||
/**
|
||||
* Encodes into bytes from the lighting-command structure
|
||||
*
|
||||
* @param apdu - buffer to hold the bytes
|
||||
* @param value - lighting command value to encode
|
||||
*
|
||||
* @return number of bytes encoded, or 0 if unable to encode.
|
||||
*/
|
||||
int lighting_command_encode(
|
||||
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 */
|
||||
|
||||
if (apdu) {
|
||||
len = encode_context_enumerated(&apdu[apdu_len], 0,
|
||||
data->operation);
|
||||
apdu_len += len;
|
||||
/* optional target-level */
|
||||
if (data->use_target_level) {
|
||||
len = encode_context_real(&apdu[apdu_len], 1,
|
||||
data->target_level);
|
||||
apdu_len += len;
|
||||
}
|
||||
/* optional ramp-rate */
|
||||
if (data->use_ramp_rate) {
|
||||
len = encode_context_real(&apdu[apdu_len], 2,
|
||||
data->ramp_rate);
|
||||
apdu_len += len;
|
||||
}
|
||||
/* optional step increment */
|
||||
if (data->use_step_increment) {
|
||||
len = encode_context_real(&apdu[apdu_len], 3,
|
||||
data->step_increment);
|
||||
apdu_len += len;
|
||||
}
|
||||
/* optional fade time */
|
||||
if (data->use_fade_time) {
|
||||
len = encode_context_unsigned(&apdu[apdu_len], 4,
|
||||
data->fade_time);
|
||||
apdu_len += len;
|
||||
}
|
||||
/* optional priority */
|
||||
if (data->use_priority) {
|
||||
len = encode_context_unsigned(&apdu[apdu_len], 5,
|
||||
data->priority);
|
||||
apdu_len += len;
|
||||
}
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes into bytes from the lighting-command structure
|
||||
* a context tagged chunk (opening and closing tag)
|
||||
*
|
||||
* @param apdu - buffer to hold the bytes
|
||||
* @param tag_number - tag number to encode this chunk
|
||||
* @param value - lighting command value to encode
|
||||
*
|
||||
* @return number of bytes encoded, or 0 if unable to encode.
|
||||
*/
|
||||
int lighting_command_encode_context(
|
||||
uint8_t * apdu,
|
||||
uint8_t tag_number,
|
||||
BACNET_LIGHTING_COMMAND * value)
|
||||
{
|
||||
int apdu_len = 0;
|
||||
|
||||
apdu_len += encode_opening_tag(&apdu[apdu_len], tag_number);
|
||||
apdu_len += lighting_command_encode(&apdu[apdu_len], value);
|
||||
apdu_len += encode_closing_tag(&apdu[apdu_len], tag_number);
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes from bytes into the lighting-command structure
|
||||
*
|
||||
* @param apdu - buffer to hold the bytes
|
||||
* @param apdu_max_len - number of bytes in the buffer to decode
|
||||
* @param value - lighting command value to place the decoded values
|
||||
*
|
||||
* @return number of bytes encoded
|
||||
*/
|
||||
int lighting_command_decode(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_max_len,
|
||||
BACNET_LIGHTING_COMMAND * data)
|
||||
{
|
||||
int len = 0;
|
||||
int apdu_len = 0;
|
||||
uint8_t tag_number = 0;
|
||||
uint32_t len_value_type = 0;
|
||||
uint32_t unsigned_value = 0;
|
||||
float real_value = 0.0;
|
||||
|
||||
apdu_max_len = apdu_max_len;
|
||||
/* check for value pointers */
|
||||
if (apdu_len && data) {
|
||||
/* Tag 0: operation */
|
||||
if (!decode_is_context_tag(&apdu[apdu_len], 0))
|
||||
return BACNET_STATUS_ERROR;
|
||||
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, &unsigned_value);
|
||||
if (len > 0) {
|
||||
data->operation = unsigned_value;
|
||||
}
|
||||
apdu_len += len;
|
||||
/* Tag 1: target-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);
|
||||
data->target_level = real_value;
|
||||
apdu_len += len;
|
||||
data->use_target_level = true;
|
||||
} else {
|
||||
data->use_target_level = false;
|
||||
}
|
||||
/* Tag 2: ramp-rate - OPTIONAL */
|
||||
if (decode_is_context_tag(&apdu[apdu_len], 2)) {
|
||||
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);
|
||||
data->ramp_rate = real_value;
|
||||
data->use_ramp_rate = true;
|
||||
} else {
|
||||
data->use_ramp_rate = false;
|
||||
}
|
||||
/* Tag 3: step-increment - OPTIONAL */
|
||||
if (decode_is_context_tag(&apdu[apdu_len], 3)) {
|
||||
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);
|
||||
data->step_increment = real_value;
|
||||
data->use_step_increment = true;
|
||||
} else {
|
||||
data->use_step_increment = false;
|
||||
}
|
||||
/* Tag 4: fade-time - OPTIONAL */
|
||||
if (decode_is_context_tag(&apdu[apdu_len], 4)) {
|
||||
len =
|
||||
decode_tag_number_and_value(&apdu[apdu_len], &tag_number,
|
||||
&len_value_type);
|
||||
apdu_len += len;
|
||||
len = decode_unsigned(&apdu[apdu_len], len_value_type,
|
||||
&unsigned_value);
|
||||
data->fade_time = unsigned_value;
|
||||
data->use_fade_time = true;
|
||||
} else {
|
||||
data->use_fade_time = false;
|
||||
}
|
||||
/* Tag 5: priority - OPTIONAL */
|
||||
if (decode_is_context_tag(&apdu[apdu_len], 4)) {
|
||||
len =
|
||||
decode_tag_number_and_value(&apdu[apdu_len], &tag_number,
|
||||
&len_value_type);
|
||||
apdu_len += len;
|
||||
len = decode_unsigned(&apdu[apdu_len], len_value_type,
|
||||
&unsigned_value);
|
||||
data->priority = unsigned_value;
|
||||
data->use_priority = true;
|
||||
} else {
|
||||
data->use_priority = false;
|
||||
}
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies one lighting-command structure to another
|
||||
*
|
||||
* @param dst - lighting command value target
|
||||
* @param src - lighting command value source
|
||||
*
|
||||
* @return true if copy succeeded
|
||||
*/
|
||||
bool lighting_command_copy(
|
||||
BACNET_LIGHTING_COMMAND * dst,
|
||||
BACNET_LIGHTING_COMMAND * src)
|
||||
{
|
||||
bool status = false;
|
||||
|
||||
if (dst && src) {
|
||||
dst->operation = src->operation;
|
||||
dst->use_target_level = src->use_target_level;
|
||||
dst->use_ramp_rate = src->use_ramp_rate;
|
||||
dst->use_step_increment = src->use_step_increment;
|
||||
dst->use_fade_time = src->use_fade_time;
|
||||
dst->use_priority = src->use_priority;
|
||||
dst->target_level = src->target_level;
|
||||
dst->ramp_rate = src->ramp_rate;
|
||||
dst->step_increment = src->step_increment;
|
||||
dst->fade_time = src->fade_time;
|
||||
dst->priority = src->priority;
|
||||
status = true;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare one lighting-command structure to another
|
||||
*
|
||||
* @param dst - lighting command value target
|
||||
* @param src - lighting command value source
|
||||
*
|
||||
* @return true if lighting-commands are the same for values in-use
|
||||
*/
|
||||
bool lighting_command_same(
|
||||
BACNET_LIGHTING_COMMAND * dst,
|
||||
BACNET_LIGHTING_COMMAND * src)
|
||||
{
|
||||
bool status = false;
|
||||
|
||||
if (dst && src) {
|
||||
if ((dst->operation == src->operation) &&
|
||||
(dst->use_target_level == src->use_target_level) &&
|
||||
(dst->use_ramp_rate == src->use_ramp_rate) &&
|
||||
(dst->use_step_increment == src->use_step_increment) &&
|
||||
(dst->use_fade_time == src->use_fade_time) &&
|
||||
(dst->use_priority = src->use_priority)) {
|
||||
status = true;
|
||||
if ((dst->use_target_level) &&
|
||||
(dst->target_level != src->target_level)) {
|
||||
status = false;
|
||||
}
|
||||
if ((dst->use_ramp_rate) &&
|
||||
(dst->ramp_rate != src->ramp_rate)) {
|
||||
status = false;
|
||||
}
|
||||
if ((dst->use_step_increment) &&
|
||||
(dst->step_increment != src->step_increment)) {
|
||||
status = false;
|
||||
}
|
||||
if ((dst->use_fade_time) &&
|
||||
(dst->fade_time != src->fade_time)) {
|
||||
status = false;
|
||||
}
|
||||
if ((dst->use_priority) &&
|
||||
(dst->priority != src->priority)) {
|
||||
status = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
void testBACnetLightingCommand(
|
||||
Test * pTest)
|
||||
{
|
||||
bool status = false;
|
||||
|
||||
ct_test(pTest, status == true);
|
||||
}
|
||||
|
||||
#ifdef TEST_LIGHTING_COMMAND
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
|
||||
pTest = ct_create("BACnet Lighting Command", NULL);
|
||||
/* individual tests */
|
||||
rc = ct_addTestFunction(pTest, testBACnetLightingCommand);
|
||||
assert(rc);
|
||||
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void) ct_report(pTest);
|
||||
ct_destroy(pTest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif /* TEST */
|
||||
Reference in New Issue
Block a user