Added Binary Output objects to the demos.

This commit is contained in:
skarg
2006-03-23 15:43:15 +00:00
parent 49a9946ad9
commit 7e18086c73
28 changed files with 158 additions and 41 deletions
+4 -1
View File
@@ -245,8 +245,11 @@ typedef enum {
} BACNET_ACTION;
typedef enum {
MIN_BINARY_PV = 0, /* for validating incoming values */
BINARY_INACTIVE = 0,
BINARY_ACTIVE = 1
BINARY_ACTIVE = 1,
MAX_BINARY_PV = 1, /* for validating incoming values */
BINARY_NULL = 2 /* our homemade way of storing this info */
} BACNET_BINARY_PV;
typedef enum {
+2 -1
View File
@@ -34,8 +34,9 @@ SRCS = main.c \
$(BACNET_HANDLER)/s_dcc.c \
$(BACNET_OBJECT)/device.c \
$(BACNET_OBJECT)/ai.c \
$(BACNET_OBJECT)/bi.c \
$(BACNET_OBJECT)/ao.c \
$(BACNET_OBJECT)/bi.c \
$(BACNET_OBJECT)/bo.c \
$(BACNET_OBJECT)/bacfile.c \
$(BACNET_ROOT)/filename.c \
$(BACNET_ROOT)/rp.c \
+2 -1
View File
@@ -45,8 +45,9 @@ SRCS = main.c \
..\..\demo\object\bacfile.c \
..\..\demo\object\device.c \
..\..\demo\object\ai.c \
..\..\demo\object\bi.c \
..\..\demo\object\ao.c \
..\..\demo\object\bi.c \
..\..\demo\object\bo.c \
..\..\datalink.c \
..\..\tsm.c \
..\..\address.c \
+23 -1
View File
@@ -38,8 +38,9 @@
/* demo objects */
#include "device.h"
#include "ai.h"
#include "bi.h"
#include "ao.h"
#include "bi.h"
#include "bo.h"
#if BACFILE
#include "bacfile.h"
#endif
@@ -145,6 +146,27 @@ void handler_read_property(uint8_t * service_request,
} else
error = true;
break;
case OBJECT_BINARY_OUTPUT:
if (Binary_Output_Valid_Instance(data.object_instance)) {
len = Binary_Output_Encode_Property_APDU(&Temp_Buf[0],
data.object_instance,
data.object_property,
data.array_index, &error_class, &error_code);
if (len >= 0) {
/* encode the APDU portion of the packet */
data.application_data = &Temp_Buf[0];
data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */
pdu_len +=
rp_ack_encode_apdu(&Handler_Transmit_Buffer
[pdu_len], service_data->invoke_id, &data);
fprintf(stderr, "Sending Read Property Ack!\n");
send = true;
} else
error = true;
} else
error = true;
break;
case OBJECT_ANALOG_OUTPUT:
if (Analog_Output_Valid_Instance(data.object_instance)) {
len = Analog_Output_Encode_Property_APDU(&Temp_Buf[0],
+20
View File
@@ -39,6 +39,8 @@
#include "device.h"
#include "ai.h"
#include "ao.h"
#include "bi.h"
#include "bo.h"
#if BACFILE
#include "bacfile.h"
#endif
@@ -100,6 +102,7 @@ void handler_write_property(uint8_t * service_request,
}
break;
case OBJECT_ANALOG_INPUT:
case OBJECT_BINARY_INPUT:
error_class = ERROR_CLASS_PROPERTY;
error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
pdu_len +=
@@ -108,6 +111,23 @@ void handler_write_property(uint8_t * service_request,
error_class, error_code);
fprintf(stderr, "Sending Write Access Error!\n");
break;
case OBJECT_BINARY_OUTPUT:
if (Binary_Output_Write_Property(&wp_data, &error_class,
&error_code)) {
pdu_len +=
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY);
fprintf(stderr, "Sending Write Property Simple Ack!\n");
} else {
pdu_len +=
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
error_code);
fprintf(stderr, "Sending Write Access Error!\n");
}
break;
case OBJECT_ANALOG_OUTPUT:
if (Analog_Output_Write_Property(&wp_data, &error_class,
&error_code)) {
+24 -7
View File
@@ -53,14 +53,14 @@ static uint8_t
static bool Analog_Output_Out_Of_Service[MAX_ANALOG_OUTPUTS];
/* we need to have our arrays initialized before answering any calls */
static bool Analog_Ouput_Initialized = false;
static bool Analog_Output_Initialized = false;
void Analog_Output_Init(void)
{
unsigned i, j;
if (!Analog_Ouput_Initialized) {
Analog_Ouput_Initialized = true;
if (!Analog_Output_Initialized) {
Analog_Output_Initialized = true;
/* initialize all the analog output priority arrays to NULL */
for (i = 0; i < MAX_ANALOG_OUTPUTS; i++) {
@@ -163,6 +163,7 @@ int Analog_Output_Encode_Property_APDU(uint8_t * apdu,
float real_value = 1.414;
unsigned object_index = 0;
unsigned i = 0;
bool state = false;
Analog_Output_Init();
switch (property) {
@@ -196,7 +197,9 @@ int Analog_Output_Encode_Property_APDU(uint8_t * apdu,
apdu_len = encode_tagged_enumerated(&apdu[0], EVENT_STATE_NORMAL);
break;
case PROP_OUT_OF_SERVICE:
apdu_len = encode_tagged_boolean(&apdu[0], false);
object_index = Analog_Output_Instance_To_Index(object_instance);
state = Analog_Output_Out_Of_Service[object_index];
apdu_len = encode_tagged_boolean(&apdu[0], state);
break;
case PROP_UNITS:
apdu_len = encode_tagged_enumerated(&apdu[0], UNITS_PERCENT);
@@ -283,6 +286,9 @@ bool Analog_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
case PROP_PRESENT_VALUE:
if (wp_data->value.tag == BACNET_APPLICATION_TAG_REAL) {
priority = wp_data->priority;
/* Command priority 6 is reserved for use by Minimum On/Off
algorithm and may not be used for other purposes in any
object. */
if (priority && (priority <= BACNET_MAX_PRIORITY) &&
(priority != 6 /* reserved */ ) &&
(wp_data->value.type.Real >= 0.0) &&
@@ -293,11 +299,16 @@ bool Analog_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
object_instance);
priority--;
Analog_Output_Level[object_index][priority] = level;
/* if Out of Service is TRUE, then don't set the */
/* physical output. This comment may apply to the */
/* main loop (i.e. check out of service before changing output) */
/* Note: you could set the physical output here if we
are the highest priority.
However, if Out of Service is TRUE, then don't set the
physical output. This comment may apply to the
main loop (i.e. check out of service before changing output) */
status = true;
} else if (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 {
@@ -312,6 +323,12 @@ bool Analog_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
if (priority && (priority <= BACNET_MAX_PRIORITY)) {
priority--;
Analog_Output_Level[object_index][priority] = level;
/* Note: you could set the physical output here to the next
highest priority, or to the relinquish default if no
priorities are set.
However, if Out of Service is TRUE, then don't set the
physical output. This comment may apply to the
main loop (i.e. check out of service before changing output) */
status = true;
} else {
*error_class = ERROR_CLASS_PROPERTY;
+1 -1
View File
@@ -65,7 +65,7 @@ uint32_t Binary_Input_Index_To_Instance(unsigned index)
void Binary_Input_Init(void)
{
bool initialized = false;
static bool initialized = false;
unsigned i;
if (!initialized) {
+9 -9
View File
@@ -22,8 +22,8 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
#ifndef AO_H
#define AO_H
#ifndef BO_H
#define BO_H
#include <stdbool.h>
#include <stdint.h>
@@ -35,23 +35,23 @@
extern "C" {
#endif /* __cplusplus */
bool Analog_Output_Valid_Instance(uint32_t object_instance);
unsigned Analog_Output_Count(void);
uint32_t Analog_Output_Index_To_Instance(unsigned index);
char *Analog_Output_Name(uint32_t object_instance);
bool Binary_Output_Valid_Instance(uint32_t object_instance);
unsigned Binary_Output_Count(void);
uint32_t Binary_Output_Index_To_Instance(unsigned index);
char *Binary_Output_Name(uint32_t object_instance);
int Analog_Output_Encode_Property_APDU(uint8_t * apdu,
int Binary_Output_Encode_Property_APDU(uint8_t * apdu,
uint32_t object_instance,
BACNET_PROPERTY_ID property,
int32_t array_index,
BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code);
bool Analog_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
bool Binary_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code);
#ifdef TEST
#include "ctest.h"
void testAnalogOutput(Test * pTest);
void testBinaryOutput(Test * pTest);
#endif
#ifdef __cplusplus
+34 -1
View File
@@ -33,6 +33,7 @@
#include "apdu.h"
#include "ai.h" /* object list dependency */
#include "bi.h" /* object list dependency */
#include "bo.h" /* object list dependency */
#include "ao.h" /* object list dependency */
#include "wp.h" /* write property handling */
#include "device.h" /* me */
@@ -320,6 +321,7 @@ unsigned Device_Object_List_Count(void)
count += Analog_Input_Count();
count += Binary_Input_Count();
count += Binary_Output_Count();
count += Analog_Output_Count();
#if BACFILE
count += bacfile_count();
@@ -362,12 +364,24 @@ bool Device_Object_List_Identifier(unsigned array_index,
status = true;
}
}
/* analog output objects */
/* binary output objects */
if (!status) {
/* normalize the index since
we know it is not the previous objects */
object_index -= Binary_Input_Count();
/* is it a valid index for this object? */
if (object_index < Binary_Output_Count()) {
*object_type = OBJECT_BINARY_OUTPUT;
*instance = Binary_Output_Index_To_Instance(object_index);
status = true;
}
}
/* analog output objects */
if (!status) {
/* normalize the index since
we know it is not the previous objects */
object_index -= Binary_Output_Count();
/* is it a valid index for this object? */
if (object_index < Analog_Output_Count()) {
*object_type = OBJECT_ANALOG_OUTPUT;
*instance = Analog_Output_Index_To_Instance(object_index);
@@ -433,6 +447,9 @@ char *Device_Valid_Object_Id(int object_type, uint32_t object_instance)
case OBJECT_BINARY_INPUT:
name = Binary_Input_Name(object_instance);
break;
case OBJECT_BINARY_OUTPUT:
name = Binary_Output_Name(object_instance);
break;
case OBJECT_ANALOG_OUTPUT:
name = Analog_Output_Name(object_instance);
break;
@@ -822,6 +839,22 @@ uint32_t Binary_Input_Index_To_Instance(unsigned index)
return index;
}
char *Binary_Output_Name(uint32_t object_instance)
{
(void) object_instance;
return "";
}
unsigned Binary_Output_Count(void)
{
return 0;
}
uint32_t Binary_Output_Index_To_Instance(unsigned index)
{
return index;
}
char *Analog_Output_Name(uint32_t object_instance)
{
(void) object_instance;
+2 -1
View File
@@ -43,8 +43,9 @@ SRCS = readfile.c \
$(BACNET_ROOT)/filename.c \
$(BACNET_OBJECT)/device.c \
$(BACNET_OBJECT)/ai.c \
$(BACNET_OBJECT)/bi.c \
$(BACNET_OBJECT)/ao.c \
$(BACNET_OBJECT)/bi.c \
$(BACNET_OBJECT)/bo.c \
$(BACNET_OBJECT)/bacfile.c \
$(BACNET_ROOT)/arf.c \
$(BACNET_ROOT)/dcc.c \
+2 -1
View File
@@ -41,8 +41,9 @@ SRCS = readfile.c \
..\..\demo\object\bacfile.c \
..\..\demo\object\device.c \
..\..\demo\object\ai.c \
..\..\demo\object\bi.c \
..\..\demo\object\ao.c \
..\..\demo\object\bi.c \
..\..\demo\object\bo.c \
..\..\datalink.c \
..\..\tsm.c \
..\..\address.c \
+2 -1
View File
@@ -33,8 +33,9 @@ SRCS = readprop.c \
$(BACNET_HANDLER)/s_whois.c \
$(BACNET_OBJECT)/device.c \
$(BACNET_OBJECT)/ai.c \
$(BACNET_OBJECT)/bi.c \
$(BACNET_OBJECT)/ao.c \
$(BACNET_OBJECT)/bi.c \
$(BACNET_OBJECT)/bo.c \
$(BACNET_OBJECT)/bacfile.c \
$(BACNET_ROOT)/filename.c \
$(BACNET_ROOT)/rp.c \
+2 -1
View File
@@ -45,8 +45,9 @@ SRCS = readprop.c \
..\..\demo\object\bacfile.c \
..\..\demo\object\device.c \
..\..\demo\object\ai.c \
..\..\demo\object\bi.c \
..\..\demo\object\ao.c \
..\..\demo\object\bi.c \
..\..\demo\object\bo.c \
..\..\datalink.c \
..\..\tsm.c \
..\..\address.c \
+2 -1
View File
@@ -33,8 +33,9 @@ SRCS = main.c \
$(BACNET_HANDLER)/s_rd.c \
$(BACNET_OBJECT)/device.c \
$(BACNET_OBJECT)/ai.c \
$(BACNET_OBJECT)/bi.c \
$(BACNET_OBJECT)/ao.c \
$(BACNET_OBJECT)/bi.c \
$(BACNET_OBJECT)/bo.c \
$(BACNET_OBJECT)/bacfile.c \
$(BACNET_ROOT)/filename.c \
$(BACNET_ROOT)/rp.c \
+3 -1
View File
@@ -44,8 +44,10 @@ SRCS = main.c \
..\..\dcc.c \
..\..\demo\object\bacfile.c \
..\..\demo\object\device.c \
..\..\demo\object\bi.c \
..\..\demo\object\ai.c \
..\..\demo\object\ao.c \
..\..\demo\object\bi.c \
..\..\demo\object\bo.c \
..\..\datalink.c \
..\..\tsm.c \
..\..\address.c \
+2 -1
View File
@@ -36,8 +36,9 @@ SRCS = server.c \
$(BACNET_HANDLER)/s_ihave.c \
$(BACNET_OBJECT)/device.c \
$(BACNET_OBJECT)/ai.c \
$(BACNET_OBJECT)/bi.c \
$(BACNET_OBJECT)/ao.c \
$(BACNET_OBJECT)/bi.c \
$(BACNET_OBJECT)/bo.c \
$(BACNET_OBJECT)/bacfile.c \
$(BACNET_ROOT)/datalink.c \
$(BACNET_ROOT)/filename.c \
+2 -1
View File
@@ -53,8 +53,9 @@ SRCS = server.c \
..\..\demo\object\bacfile.c \
..\..\demo\object\device.c \
..\..\demo\object\ai.c \
..\..\demo\object\bi.c \
..\..\demo\object\ao.c \
..\..\demo\object\bi.c \
..\..\demo\object\bo.c \
..\..\datalink.c \
..\..\abort.c \
..\..\reject.c \
+2 -1
View File
@@ -33,8 +33,9 @@ SRCS = main.c \
$(BACNET_HANDLER)/s_ts.c \
$(BACNET_OBJECT)/device.c \
$(BACNET_OBJECT)/ai.c \
$(BACNET_OBJECT)/bi.c \
$(BACNET_OBJECT)/ao.c \
$(BACNET_OBJECT)/bi.c \
$(BACNET_OBJECT)/bo.c \
$(BACNET_OBJECT)/bacfile.c \
$(BACNET_ROOT)/filename.c \
$(BACNET_ROOT)/rp.c \
+2 -1
View File
@@ -35,8 +35,9 @@ SRCS = main.c \
$(BACNET_OBJECT)\bacfile.c \
$(BACNET_OBJECT)\device.c \
$(BACNET_OBJECT)\ai.c \
$(BACNET_OBJECT)\bi.c \
$(BACNET_OBJECT)\ao.c \
$(BACNET_OBJECT)\bi.c \
$(BACNET_OBJECT)\bo.c \
$(BACNET_ROOT)\address.c \
$(BACNET_ROOT)\filename.c \
$(BACNET_ROOT)\bacdcode.c \
+2 -1
View File
@@ -33,8 +33,9 @@ SRCS = main.c \
$(BACNET_HANDLER)/s_ihave.c \
$(BACNET_OBJECT)/device.c \
$(BACNET_OBJECT)/ai.c \
$(BACNET_OBJECT)/bi.c \
$(BACNET_OBJECT)/ao.c \
$(BACNET_OBJECT)/bi.c \
$(BACNET_OBJECT)/bo.c \
$(BACNET_OBJECT)/bacfile.c \
$(BACNET_ROOT)/filename.c \
$(BACNET_ROOT)/rp.c \
+2 -1
View File
@@ -47,8 +47,9 @@ SRCS = main.c \
..\..\demo\object\bacfile.c \
..\..\demo\object\device.c \
..\..\demo\object\ai.c \
..\..\demo\object\bi.c \
..\..\demo\object\ao.c \
..\..\demo\object\bi.c \
..\..\demo\object\bo.c \
..\..\datalink.c \
..\..\abort.c \
..\..\reject.c \
+2 -1
View File
@@ -34,8 +34,9 @@ SRCS = main.c \
$(BACNET_HANDLER)/s_whois.c \
$(BACNET_OBJECT)/device.c \
$(BACNET_OBJECT)/ai.c \
$(BACNET_OBJECT)/bi.c \
$(BACNET_OBJECT)/ao.c \
$(BACNET_OBJECT)/bi.c \
$(BACNET_OBJECT)/bo.c \
$(BACNET_OBJECT)/bacfile.c \
$(BACNET_ROOT)/filename.c \
$(BACNET_ROOT)/rp.c \
+2 -1
View File
@@ -34,8 +34,9 @@ SRCS = main.c \
$(BACNET_OBJECT)\bacfile.c \
$(BACNET_OBJECT)\device.c \
$(BACNET_OBJECT)\ai.c \
$(BACNET_OBJECT)\bi.c \
$(BACNET_OBJECT)\ao.c \
$(BACNET_OBJECT)\bi.c \
$(BACNET_OBJECT)\bo.c \
$(BACNET_ROOT)\address.c \
$(BACNET_ROOT)\filename.c \
$(BACNET_ROOT)\bacdcode.c \
+2 -1
View File
@@ -43,8 +43,9 @@ SRCS = writefile.c \
$(BACNET_ROOT)/address.c \
$(BACNET_OBJECT)/device.c \
$(BACNET_OBJECT)/ai.c \
$(BACNET_OBJECT)/bi.c \
$(BACNET_OBJECT)/ao.c \
$(BACNET_OBJECT)/bi.c \
$(BACNET_OBJECT)/bo.c \
$(BACNET_OBJECT)/bacfile.c \
$(BACNET_ROOT)/arf.c \
$(BACNET_ROOT)/awf.c \
+2 -1
View File
@@ -41,8 +41,9 @@ SRCS = writefile.c \
..\..\demo\object\bacfile.c \
..\..\demo\object\device.c \
..\..\demo\object\ai.c \
..\..\demo\object\bi.c \
..\..\demo\object\ao.c \
..\..\demo\object\bi.c \
..\..\demo\object\bo.c \
..\..\datalink.c \
..\..\tsm.c \
..\..\address.c \
+2 -1
View File
@@ -32,8 +32,9 @@ SRCS = writeprop.c \
$(BACNET_HANDLER)/s_whois.c \
$(BACNET_OBJECT)/device.c \
$(BACNET_OBJECT)/ai.c \
$(BACNET_OBJECT)/bi.c \
$(BACNET_OBJECT)/ao.c \
$(BACNET_OBJECT)/bi.c \
$(BACNET_OBJECT)/bo.c \
$(BACNET_OBJECT)/bacfile.c \
$(BACNET_ROOT)/filename.c \
$(BACNET_ROOT)/rp.c \
+2 -1
View File
@@ -44,8 +44,9 @@ SRCS = writeprop.c \
..\..\demo\object\bacfile.c \
..\..\demo\object\device.c \
..\..\demo\object\ai.c \
..\..\demo\object\bi.c \
..\..\demo\object\ao.c \
..\..\demo\object\bi.c \
..\..\demo\object\bo.c \
..\..\datalink.c \
..\..\tsm.c \
..\..\address.c \
+2 -1
View File
@@ -11,8 +11,9 @@ SRCS = address.c \
bigend.c \
demo/object/device.c \
demo/object/ai.c \
demo/object/bi.c \
demo/object/ao.c \
demo/object/bi.c \
demo/object/bo.c \
iam.c \
dcc.c \
npdu.c \