Updated Lighting Output object. Added Channel object. Not complete and not fully tested.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,168 @@
|
||||
/**
|
||||
* @file
|
||||
* @author Steve Karg
|
||||
* @date 2013
|
||||
* @brief Channel objects, customize for your use
|
||||
*
|
||||
* @section DESCRIPTION
|
||||
*
|
||||
* The Channel object is a command object without a priority array, and the
|
||||
* present-value property uses a priority array and a single precision floating point
|
||||
* data type.
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* 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.
|
||||
*/
|
||||
#ifndef CHANNEL_H
|
||||
#define CHANNEL_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "bacdef.h"
|
||||
#include "rp.h"
|
||||
#include "wp.h"
|
||||
#include "lo.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* BACNET_CHANNEL_VALUE decodes WriteProperty service requests
|
||||
Choose the datatypes that your application supports */
|
||||
#if !(defined(CHANNEL_NUMERIC) || \
|
||||
defined(CHANNEL_NULL) || \
|
||||
defined(CHANNEL_BOOLEAN) || \
|
||||
defined(CHANNEL_UNSIGNED) || \
|
||||
defined(CHANNEL_SIGNED) || \
|
||||
defined(CHANNEL_REAL) || \
|
||||
defined(CHANNEL_DOUBLE) || \
|
||||
defined(CHANNEL_OCTET_STRING) || \
|
||||
defined(CHANNEL_CHARACTER_STRING) || \
|
||||
defined(CHANNEL_BIT_STRING) || \
|
||||
defined(CHANNEL_ENUMERATED) || \
|
||||
defined(CHANNEL_DATE) || \
|
||||
defined(CHANNEL_TIME) || \
|
||||
defined(CHANNEL_OBJECT_ID) || \
|
||||
defined(CHANNEL_LIGHTING_COMMAND))
|
||||
#define CHANNEL_NUMERIC
|
||||
#endif
|
||||
|
||||
#if defined (CHANNEL_NUMERIC)
|
||||
#define CHANNEL_NULL
|
||||
#define CHANNEL_BOOLEAN
|
||||
#define CHANNEL_UNSIGNED
|
||||
#define CHANNEL_SIGNED
|
||||
#define CHANNEL_REAL
|
||||
#define CHANNEL_DOUBLE
|
||||
#define CHANNEL_ENUMERATED
|
||||
#define CHANNEL_LIGHTING_COMMAND
|
||||
#endif
|
||||
|
||||
typedef struct BACnet_Channel_Value_t {
|
||||
uint8_t tag;
|
||||
union {
|
||||
/* NULL - not needed as it is encoded in the tag alone */
|
||||
#if defined (CHANNEL_BOOLEAN)
|
||||
bool Boolean;
|
||||
#endif
|
||||
#if defined (CHANNEL_UNSIGNED)
|
||||
uint32_t Unsigned_Int;
|
||||
#endif
|
||||
#if defined (CHANNEL_SIGNED)
|
||||
int32_t Signed_Int;
|
||||
#endif
|
||||
#if defined (CHANNEL_REAL)
|
||||
float Real;
|
||||
#endif
|
||||
#if defined (CHANNEL_DOUBLE)
|
||||
double Double;
|
||||
#endif
|
||||
#if defined (CHANNEL_OCTET_STRING)
|
||||
BACNET_OCTET_STRING Octet_String;
|
||||
#endif
|
||||
#if defined (CHANNEL_CHARACTER_STRING)
|
||||
BACNET_CHARACTER_STRING Character_String;
|
||||
#endif
|
||||
#if defined (CHANNEL_BIT_STRING)
|
||||
BACNET_BIT_STRING Bit_String;
|
||||
#endif
|
||||
#if defined (CHANNEL_ENUMERATED)
|
||||
uint32_t Enumerated;
|
||||
#endif
|
||||
#if defined (CHANNEL_DATE)
|
||||
BACNET_DATE Date;
|
||||
#endif
|
||||
#if defined (CHANNEL_TIME)
|
||||
BACNET_TIME Time;
|
||||
#endif
|
||||
#if defined (CHANNEL_OBJECT_ID)
|
||||
BACNET_OBJECT_ID Object_Id;
|
||||
#endif
|
||||
#if defined (CHANNEL_LIGHTING_COMMAND)
|
||||
BACNET_LIGHTING_COMMAND Lighting_Command;
|
||||
#endif
|
||||
} type;
|
||||
/* simple linked list if needed */
|
||||
struct BACnet_Channel_Value_t *next;
|
||||
} BACNET_CHANNEL_VALUE;
|
||||
|
||||
void Channel_Property_Lists(const int **pRequired,
|
||||
const int **pOptional,
|
||||
const int **pProprietary);
|
||||
bool Channel_Valid_Instance(uint32_t object_instance);
|
||||
unsigned Channel_Count(void);
|
||||
uint32_t Channel_Index_To_Instance(unsigned index);
|
||||
unsigned Channel_Instance_To_Index(uint32_t instance);
|
||||
bool Channel_Object_Instance_Add(uint32_t instance);
|
||||
|
||||
bool Channel_Object_Name(uint32_t object_instance,
|
||||
BACNET_CHARACTER_STRING * object_name);
|
||||
bool Channel_Name_Set(uint32_t object_instance,
|
||||
char *new_name);
|
||||
|
||||
int Channel_Read_Property(BACNET_READ_PROPERTY_DATA * rpdata);
|
||||
bool Channel_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data);
|
||||
|
||||
BACNET_CHANNEL_VALUE * Channel_Present_Value(uint32_t object_instance);
|
||||
bool Channel_Present_Value_Set(
|
||||
BACNET_WRITE_PROPERTY_DATA * wp_data,
|
||||
BACNET_APPLICATION_DATA_VALUE * value);
|
||||
|
||||
bool Channel_Out_Of_Service(uint32_t object_instance);
|
||||
void Channel_Out_Of_Service_Set(uint32_t object_instance,
|
||||
bool oos_flag);
|
||||
|
||||
unsigned Channel_Last_Priority(uint32_t object_instance);
|
||||
BACNET_WRITE_STATUS Channel_Write_Status(uint32_t object_instance);
|
||||
uint16_t Channel_Number(uint32_t object_instance);
|
||||
bool Channel_Number_Set(uint32_t object_instance, uint16_t value);
|
||||
|
||||
void Channel_Init(void);
|
||||
|
||||
#ifdef TEST
|
||||
#include "ctest.h"
|
||||
void testChannelObject(Test * pTest);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif
|
||||
@@ -54,6 +54,7 @@
|
||||
#include "bi.h"
|
||||
#include "bo.h"
|
||||
#include "bv.h"
|
||||
#include "channel.h"
|
||||
#include "csv.h"
|
||||
#include "lc.h"
|
||||
#include "lsp.h"
|
||||
@@ -197,7 +198,6 @@ static object_functions_t My_Object_Table[] = {
|
||||
NULL /* COV */ ,
|
||||
NULL /* COV Clear */ ,
|
||||
NULL /* Intrinsic Reporting */ },
|
||||
#if 0
|
||||
{OBJECT_CHARACTERSTRING_VALUE,
|
||||
CharacterString_Value_Init,
|
||||
CharacterString_Value_Count,
|
||||
@@ -213,7 +213,6 @@ static object_functions_t My_Object_Table[] = {
|
||||
NULL /* COV */ ,
|
||||
NULL /* COV Clear */ ,
|
||||
NULL /* Intrinsic Reporting */ },
|
||||
#endif
|
||||
#if defined(INTRINSIC_REPORTING)
|
||||
{OBJECT_NOTIFICATION_CLASS,
|
||||
Notification_Class_Init,
|
||||
@@ -291,7 +290,6 @@ static object_functions_t My_Object_Table[] = {
|
||||
NULL /* COV */ ,
|
||||
NULL /* COV Clear */ ,
|
||||
NULL /* Intrinsic Reporting */ },
|
||||
#if 0
|
||||
{OBJECT_MULTI_STATE_VALUE,
|
||||
Multistate_Value_Init,
|
||||
Multistate_Value_Count,
|
||||
@@ -307,7 +305,6 @@ static object_functions_t My_Object_Table[] = {
|
||||
NULL /* COV */ ,
|
||||
NULL /* COV Clear */ ,
|
||||
NULL /* Intrinsic Reporting */ },
|
||||
#endif
|
||||
{OBJECT_TRENDLOG,
|
||||
Trend_Log_Init,
|
||||
Trend_Log_Count,
|
||||
@@ -323,6 +320,36 @@ static object_functions_t My_Object_Table[] = {
|
||||
NULL /* COV */ ,
|
||||
NULL /* COV Clear */ ,
|
||||
NULL /* Intrinsic Reporting */ },
|
||||
{OBJECT_LIGHTING_OUTPUT,
|
||||
Lighting_Output_Init,
|
||||
Lighting_Output_Count,
|
||||
Lighting_Output_Index_To_Instance,
|
||||
Lighting_Output_Valid_Instance,
|
||||
Lighting_Output_Object_Name,
|
||||
Lighting_Output_Read_Property,
|
||||
Lighting_Output_Write_Property,
|
||||
Lighting_Output_Property_Lists,
|
||||
NULL /* ReadRangeInfo */ ,
|
||||
NULL /* Iterator */ ,
|
||||
NULL /* Value_Lists */ ,
|
||||
NULL /* COV */ ,
|
||||
NULL /* COV Clear */ ,
|
||||
NULL /* Intrinsic Reporting */ },
|
||||
{OBJECT_CHANNEL,
|
||||
Channel_Init,
|
||||
Channel_Count,
|
||||
Channel_Index_To_Instance,
|
||||
Channel_Valid_Instance,
|
||||
Channel_Object_Name,
|
||||
Channel_Read_Property,
|
||||
Channel_Write_Property,
|
||||
Channel_Property_Lists,
|
||||
NULL /* ReadRangeInfo */ ,
|
||||
NULL /* Iterator */ ,
|
||||
NULL /* Value_Lists */ ,
|
||||
NULL /* COV */ ,
|
||||
NULL /* COV Clear */ ,
|
||||
NULL /* Intrinsic Reporting */ },
|
||||
#if defined(BACFILE)
|
||||
{OBJECT_FILE,
|
||||
bacfile_init,
|
||||
|
||||
+967
-271
File diff suppressed because it is too large
Load Diff
@@ -22,8 +22,8 @@
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*********************************************************************/
|
||||
#ifndef LO_H
|
||||
#define LO_H
|
||||
#ifndef LIGHTING_OUTPUT_H
|
||||
#define LIGHTING_OUTPUT_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
@@ -36,14 +36,21 @@
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
bool Analog_Output_Valid_Instance(
|
||||
void Lighting_Output_Property_Lists(
|
||||
const int **pRequired,
|
||||
const int **pOptional,
|
||||
const int **pProprietary);
|
||||
bool Lighting_Output_Valid_Instance(
|
||||
uint32_t object_instance);
|
||||
unsigned Lighting_Output_Count(
|
||||
void);
|
||||
uint32_t Lighting_Output_Index_To_Instance(
|
||||
unsigned index);
|
||||
char *Lighting_Output_Name(
|
||||
uint32_t object_instance);
|
||||
unsigned Lighting_Output_Instance_To_Index(
|
||||
uint32_t instance);
|
||||
bool Lighting_Output_Object_Instance_Add(
|
||||
uint32_t instance);
|
||||
|
||||
float Lighting_Output_Present_Value(
|
||||
uint32_t object_instance);
|
||||
unsigned Lighting_Output_Present_Value_Priority(
|
||||
@@ -54,12 +61,106 @@ extern "C" {
|
||||
unsigned priority);
|
||||
bool Lighting_Output_Present_Value_Relinquish(
|
||||
uint32_t object_instance,
|
||||
int priority);
|
||||
unsigned priority);
|
||||
|
||||
float Lighting_Output_Relinquish_Default(
|
||||
uint32_t object_instance);
|
||||
bool Lighting_Output_Relinquish_Default_Set(
|
||||
uint32_t object_instance,
|
||||
float value);
|
||||
|
||||
bool Lighting_Output_Change_Of_Value(
|
||||
uint32_t instance);
|
||||
void Lighting_Output_Change_Of_Value_Clear(
|
||||
uint32_t instance);
|
||||
bool Lighting_Output_Encode_Value_List(
|
||||
uint32_t object_instance,
|
||||
BACNET_PROPERTY_VALUE * value_list);
|
||||
float Lighting_Output_COV_Increment(
|
||||
uint32_t instance);
|
||||
void Lighting_Output_COV_Increment_Set(
|
||||
uint32_t instance,
|
||||
float value);
|
||||
|
||||
bool Lighting_Output_Object_Name(
|
||||
uint32_t object_instance,
|
||||
BACNET_CHARACTER_STRING * object_name);
|
||||
bool Lighting_Output_Name_Set(
|
||||
uint32_t object_instance,
|
||||
char *new_name);
|
||||
|
||||
char *Lighting_Output_Description(
|
||||
uint32_t instance);
|
||||
bool Lighting_Output_Description_Set(
|
||||
uint32_t instance,
|
||||
char *new_name);
|
||||
|
||||
bool Lighting_Output_Out_Of_Service(
|
||||
uint32_t instance);
|
||||
void Lighting_Output_Out_Of_Service_Set(
|
||||
uint32_t instance,
|
||||
bool oos_flag);
|
||||
|
||||
bool Lighting_Output_Lighting_Command_Set(
|
||||
uint32_t object_instance,
|
||||
BACNET_LIGHTING_COMMAND *value);
|
||||
bool Lighting_Output_Lighting_Command(
|
||||
uint32_t object_instance,
|
||||
BACNET_LIGHTING_COMMAND *value);
|
||||
|
||||
BACNET_LIGHTING_IN_PROGRESS Lighting_Output_In_Progress(
|
||||
uint32_t object_instance);
|
||||
bool Lighting_Output_In_Progress_Set(
|
||||
uint32_t object_instance,
|
||||
BACNET_LIGHTING_IN_PROGRESS in_progress);
|
||||
|
||||
float Lighting_Output_Tracking_Value(
|
||||
uint32_t object_instance);
|
||||
bool Lighting_Output_Tracking_Value_Set(
|
||||
uint32_t object_instance,
|
||||
float value);
|
||||
|
||||
bool Lighting_Output_Blink_Warn_Enable(
|
||||
uint32_t object_instance);
|
||||
bool Lighting_Output_Blink_Warn_Enable_Set(
|
||||
uint32_t object_instance,
|
||||
bool enable);
|
||||
|
||||
uint32_t Lighting_Output_Egress_Time(
|
||||
uint32_t object_instance);
|
||||
bool Lighting_Output_Egress_Time_Set(
|
||||
uint32_t object_instance,
|
||||
uint32_t seconds);
|
||||
|
||||
uint32_t Lighting_Output_Default_Fade_Time(
|
||||
uint32_t object_instance);
|
||||
bool Lighting_Output_Default_Fade_Time_Set(
|
||||
uint32_t object_instance,
|
||||
uint32_t milliseconds);
|
||||
|
||||
float Lighting_Output_Default_Ramp_Rate(
|
||||
uint32_t object_instance);
|
||||
bool Lighting_Output_Default_Ramp_Rate_Set(
|
||||
uint32_t object_instance,
|
||||
float percent_per_second);
|
||||
|
||||
float Lighting_Output_Default_Step_Increment(
|
||||
uint32_t object_instance);
|
||||
bool Lighting_Output_Default_Step_Increment_Set(
|
||||
uint32_t object_instance,
|
||||
float step_increment);
|
||||
|
||||
unsigned Lighting_Output_Default_Priority(
|
||||
uint32_t object_instance);
|
||||
bool Lighting_Output_Default_Priority_Set(
|
||||
uint32_t object_instance,
|
||||
unsigned priority);
|
||||
|
||||
void Lighting_Output_Init(
|
||||
void);
|
||||
|
||||
/* ReadProperty service support */
|
||||
int Lighting_Output_Read_Property(
|
||||
BACNET_READ_PROPERTY_DATA * rpdata);
|
||||
/* WriteProperty service support */
|
||||
bool Lighting_Output_Write_Property(
|
||||
BACNET_WRITE_PROPERTY_DATA * wp_data);
|
||||
|
||||
|
||||
@@ -27,6 +27,8 @@ OBJECT_SRC = \
|
||||
$(BACNET_OBJECT)/msv.c \
|
||||
$(BACNET_OBJECT)/nc.c \
|
||||
$(BACNET_OBJECT)/trendlog.c \
|
||||
$(BACNET_OBJECT)/channel.c \
|
||||
$(BACNET_OBJECT)/lo.c \
|
||||
$(BACNET_OBJECT)/bacfile.c
|
||||
|
||||
SRCS = ${SRC} ${OBJECT_SRC}
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "bacdef.h"
|
||||
#include "bacstr.h"
|
||||
#include "datetime.h"
|
||||
#include "lighting.h"
|
||||
|
||||
struct BACnet_Application_Data_Value;
|
||||
typedef struct BACnet_Application_Data_Value {
|
||||
@@ -73,6 +74,9 @@ typedef struct BACnet_Application_Data_Value {
|
||||
#endif
|
||||
#if defined (BACAPP_OBJECT_ID)
|
||||
BACNET_OBJECT_ID Object_Id;
|
||||
#endif
|
||||
#if defined (BACAPP_LIGHTING_COMMAND)
|
||||
BACNET_LIGHTING_COMMAND Lighting_Command;
|
||||
#endif
|
||||
} type;
|
||||
/* simple linked list if needed */
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
/* Although this stack can implement a later revision,
|
||||
* sometimes another revision is desired */
|
||||
#ifndef BACNET_PROTOCOL_REVISION
|
||||
#define BACNET_PROTOCOL_REVISION 12
|
||||
#define BACNET_PROTOCOL_REVISION 14
|
||||
#endif
|
||||
|
||||
/* there are a few dependencies on the BACnet Protocol-Revision */
|
||||
|
||||
@@ -399,7 +399,7 @@ typedef enum {
|
||||
PROP_DEFAULT_FADE_TIME = 374,
|
||||
PROP_DEFAULT_RAMP_RATE = 375,
|
||||
PROP_DEFAULT_STEP_INCREMENT = 376,
|
||||
PROP_EGRESS_TIMER = 377,
|
||||
PROP_EGRESS_TIME = 377,
|
||||
PROP_IN_PROGRESS = 378,
|
||||
PROP_INSTANTANEOUS_POWER = 379,
|
||||
PROP_LIGHTING_COMMAND = 380,
|
||||
@@ -1689,7 +1689,12 @@ typedef enum BACnetLightingOperation {
|
||||
BACNET_LIGHTS_WARN = 7,
|
||||
BACNET_LIGHTS_WARN_OFF = 8,
|
||||
BACNET_LIGHTS_WARN_RELINQUISH = 9,
|
||||
BACNET_LIGHTS_STOP = 10
|
||||
BACNET_LIGHTS_STOP = 10,
|
||||
/* Enumerated values 0-255 are reserved for definition by ASHRAE.
|
||||
Enumerated values 256-65535 may be used by others subject to
|
||||
the procedures and constraints described in Clause 23 */
|
||||
BACNET_LIGHTS_PROPRIETARY_FIRST = 256,
|
||||
BACNET_LIGHTS_PROPRIETARY_LAST = 65535
|
||||
} BACNET_LIGHTING_OPERATION;
|
||||
|
||||
typedef enum BACnetLightingInProgress {
|
||||
@@ -1703,7 +1708,12 @@ typedef enum BACnetLightingInProgress {
|
||||
typedef enum BACnetLightingTransition {
|
||||
BACNET_LIGHTING_TRANSITION_IDLE = 0,
|
||||
BACNET_LIGHTING_TRANSITION_FADE = 1,
|
||||
BACNET_LIGHTING_TRANSITION_RAMP = 2
|
||||
BACNET_LIGHTING_TRANSITION_RAMP = 2,
|
||||
/* Enumerated values 0-63 are reserved for definition by ASHRAE.
|
||||
Enumerated values 64-255 may be used by others subject to
|
||||
the procedures and constraints described in Clause 23. */
|
||||
BACNET_LIGHTING_TRANSITION_PROPRIETARY_FIRST = 64,
|
||||
BACNET_LIGHTING_TRANSITION_PROPRIETARY_LAST = 255
|
||||
} BACNET_LIGHTING_TRANSITION;
|
||||
|
||||
/* NOTE: BACNET_DAYS_OF_WEEK is different than BACNET_WEEKDAY */
|
||||
|
||||
@@ -111,6 +111,9 @@ extern "C" {
|
||||
const char *bactext_network_layer_msg_name(
|
||||
unsigned index);
|
||||
|
||||
const char *bactext_lighting_operation_name(
|
||||
unsigned index);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@@ -125,6 +125,7 @@
|
||||
defined(BACAPP_ENUMERATED) || \
|
||||
defined(BACAPP_DATE) || \
|
||||
defined(BACAPP_TIME) || \
|
||||
defined(BACAPP_LIGHTING_COMMAND) || \
|
||||
defined(BACAPP_OBJECT_ID))
|
||||
#define BACAPP_ALL
|
||||
#endif
|
||||
@@ -143,6 +144,7 @@
|
||||
#define BACAPP_DATE
|
||||
#define BACAPP_TIME
|
||||
#define BACAPP_OBJECT_ID
|
||||
#define BACAPP_LIGHTING_COMMAND
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/**************************************************************************
|
||||
*
|
||||
* Copyright (C) 2012 Steve Karg <skarg@users.sourceforge.net>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* 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.
|
||||
*********************************************************************/
|
||||
#ifndef LIGHTING_H
|
||||
#define LIGHTING_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "bacenum.h"
|
||||
|
||||
/* BACnetLightingCommand ::= SEQUENCE {
|
||||
operation [0] BACnetLightingOperation,
|
||||
target-level [1] REAL (0.0..100.0) OPTIONAL,
|
||||
ramp-rate [2] REAL (0.1..100.0) OPTIONAL,
|
||||
step-increment [3] REAL (0.1..100.0) OPTIONAL,
|
||||
fade-time [4] Unsigned (100.. 86400000) OPTIONAL,
|
||||
priority [5] Unsigned (1..16) OPTIONAL
|
||||
}
|
||||
-- Note that the combination of level, ramp-rate, step-increment, and fade-time fields is
|
||||
-- dependent on the specific lighting operation. See Table 12-67.
|
||||
*/
|
||||
typedef struct BACnetLightingCommand {
|
||||
BACNET_LIGHTING_OPERATION operation;
|
||||
/* fields are optional */
|
||||
bool use_target_level:1;
|
||||
bool use_ramp_rate:1;
|
||||
bool use_step_increment:1;
|
||||
bool use_fade_time:1;
|
||||
bool use_priority:1;
|
||||
float target_level;
|
||||
float ramp_rate;
|
||||
float step_increment;
|
||||
uint32_t fade_time;
|
||||
uint8_t priority;
|
||||
} BACNET_LIGHTING_COMMAND;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
int lighting_command_encode(
|
||||
uint8_t * apdu,
|
||||
BACNET_LIGHTING_COMMAND * data);
|
||||
int lighting_command_encode_context(
|
||||
uint8_t * apdu,
|
||||
uint8_t tag_number,
|
||||
BACNET_LIGHTING_COMMAND * value);
|
||||
int lighting_command_decode(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_max_len,
|
||||
BACNET_LIGHTING_COMMAND * data);
|
||||
bool lighting_command_copy(
|
||||
BACNET_LIGHTING_COMMAND * dst,
|
||||
BACNET_LIGHTING_COMMAND * src);
|
||||
bool lighting_command_same(
|
||||
BACNET_LIGHTING_COMMAND * dst,
|
||||
BACNET_LIGHTING_COMMAND * src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif
|
||||
@@ -72,6 +72,7 @@ CORE_SRC = \
|
||||
$(BACNET_CORE)/get_alarm_sum.c \
|
||||
$(BACNET_CORE)/readrange.c \
|
||||
$(BACNET_CORE)/timestamp.c \
|
||||
$(BACNET_CORE)/lighting.c \
|
||||
$(BACNET_CORE)/version.c
|
||||
|
||||
HANDLER_SRC = \
|
||||
|
||||
@@ -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