Cleaned up the BACnet text handling and added it to the read-property handler.
This commit is contained in:
@@ -36,6 +36,8 @@ SRCS = ports/linux/main.c \
|
||||
abort.c \
|
||||
reject.c \
|
||||
bacerror.c \
|
||||
indtext.c \
|
||||
bactext.c \
|
||||
apdu.c \
|
||||
npdu.c
|
||||
|
||||
|
||||
+65
-27
@@ -35,12 +35,10 @@
|
||||
#include "indtext.h"
|
||||
#include "bacenum.h"
|
||||
|
||||
static const char *bacapp_unknown_str = "unknown";
|
||||
static const char *bacapp_unknown_service_str = "unknown service";
|
||||
static const char *ASHRAE_Reserved_Fmt = "(%d) Reserved for Use by ASHRAE";
|
||||
static const char *Vendor_Proprietary_Fmt = "(%d) Vendor Proprietary Value";
|
||||
static const char *ASHRAE_Reserved_String = "Reserved for Use by ASHRAE";
|
||||
static const char *Vendor_Proprietary_String = "Vendor Proprietary Value";
|
||||
|
||||
const INDTEXT_DATA bacnet_confirmed_service_names[] = {
|
||||
INDTEXT_DATA bacnet_confirmed_service_names[] = {
|
||||
{ SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, "Acknowledge-Alarm" },
|
||||
{ SERVICE_CONFIRMED_COV_NOTIFICATION, "COV-Notification" },
|
||||
{ SERVICE_CONFIRMED_EVENT_NOTIFICATION, "Event-Notification" },
|
||||
@@ -74,7 +72,14 @@ const INDTEXT_DATA bacnet_confirmed_service_names[] = {
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
const INDTEXT_DATA bacnet_unconfirmed_service_names[] = {
|
||||
const char *bactext_confirmed_service_name(int index)
|
||||
{
|
||||
return indtext_by_index_default(
|
||||
bacnet_confirmed_service_names,
|
||||
index,ASHRAE_Reserved_String);
|
||||
}
|
||||
|
||||
INDTEXT_DATA bacnet_unconfirmed_service_names[] = {
|
||||
{ SERVICE_UNCONFIRMED_I_AM, "I-Am" },
|
||||
{ SERVICE_UNCONFIRMED_I_HAVE, "I-Have" },
|
||||
{ SERVICE_UNCONFIRMED_COV_NOTIFICATION, "COV-Notification" },
|
||||
@@ -88,7 +93,14 @@ const INDTEXT_DATA bacnet_unconfirmed_service_names[] = {
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
const INDTEXT_DATA bacnet_application_tag_names[] = {
|
||||
const char *bactext_unconfirmed_service_name(int index)
|
||||
{
|
||||
return indtext_by_index_default(
|
||||
bacnet_unconfirmed_service_names,
|
||||
index,ASHRAE_Reserved_String);
|
||||
}
|
||||
|
||||
INDTEXT_DATA bacnet_application_tag_names[] = {
|
||||
{ BACNET_APPLICATION_TAG_NULL, "Null" },
|
||||
{ BACNET_APPLICATION_TAG_BOOLEAN, "Boolean" },
|
||||
{ BACNET_APPLICATION_TAG_UNSIGNED_INT, "Unsigned Int" },
|
||||
@@ -108,7 +120,14 @@ const INDTEXT_DATA bacnet_application_tag_names[] = {
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
const INDTEXT_DATA bacnet_object_names[] = {
|
||||
const char *bactext_application_tag_name(int index)
|
||||
{
|
||||
return indtext_by_index_default(
|
||||
bacnet_application_tag_names,
|
||||
index,ASHRAE_Reserved_String);
|
||||
}
|
||||
|
||||
INDTEXT_DATA bacnet_object_type_names[] = {
|
||||
{ OBJECT_ANALOG_INPUT, "Analog Input" },
|
||||
{ OBJECT_ANALOG_OUTPUT, "Analog Output" },
|
||||
{ OBJECT_ANALOG_VALUE, "Analog Value" },
|
||||
@@ -135,9 +154,22 @@ const INDTEXT_DATA bacnet_object_names[] = {
|
||||
{ OBJECT_ACCUMULATOR, "Accumulator" },
|
||||
{ OBJECT_PULSE_CONVERTER, "Pulse-Converter" },
|
||||
{ 0, NULL }
|
||||
/* Enumerated values 0-127 are reserved for definition by ASHRAE.
|
||||
Enumerated values 128-1023 may be used by others subject to
|
||||
the procedures and constraints described in Clause 23. */
|
||||
};
|
||||
|
||||
const INDTEXT_DATA bacnet_property_names[] = {
|
||||
const char *bactext_object_type_name(int index)
|
||||
{
|
||||
return indtext_by_index_split_default(
|
||||
bacnet_object_type_names,
|
||||
index,
|
||||
128,
|
||||
ASHRAE_Reserved_String,
|
||||
Vendor_Proprietary_String);
|
||||
}
|
||||
|
||||
INDTEXT_DATA bacnet_property_names[] = {
|
||||
/* FIXME: use the enumerations from bacenum.h */
|
||||
{ 0, "acked-transitions"},
|
||||
{ 1, "ack-required"},
|
||||
@@ -309,9 +341,22 @@ const INDTEXT_DATA bacnet_property_names[] = {
|
||||
{ 167, "max-segments-accepted"},
|
||||
{ 168, "profile-name"},
|
||||
{ 0, NULL }
|
||||
/* Enumerated values 0-511 are reserved for definition by ASHRAE.
|
||||
Enumerated values 512-4194303 may be used by others subject to the
|
||||
procedures and constraints described in Clause 23. */
|
||||
};
|
||||
|
||||
const INDTEXT_DATA bacnet_engineering_unit_names[] = {
|
||||
const char *bactext_property_name(int index)
|
||||
{
|
||||
return indtext_by_index_split_default(
|
||||
bacnet_property_names,
|
||||
index,
|
||||
512,
|
||||
ASHRAE_Reserved_String,
|
||||
Vendor_Proprietary_String);
|
||||
}
|
||||
|
||||
INDTEXT_DATA bacnet_engineering_unit_names[] = {
|
||||
/* FIXME: add the first 144 names...*/
|
||||
/* FIXME: use the enumerations from bacenum.h */
|
||||
{145,"milliohms"},
|
||||
@@ -365,6 +410,16 @@ const INDTEXT_DATA bacnet_engineering_unit_names[] = {
|
||||
the procedures and constraints described in Clause 23. */
|
||||
};
|
||||
|
||||
const char *bactext_engineering_unit_name(int index)
|
||||
{
|
||||
return indtext_by_index_split_default(
|
||||
bacnet_engineering_unit_names,
|
||||
index,
|
||||
256,
|
||||
ASHRAE_Reserved_String,
|
||||
Vendor_Proprietary_String);
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* FIXME: add the value */
|
||||
/* FIXME: use the enumerations from bacenum.h */
|
||||
@@ -396,23 +451,6 @@ INDTEXT_DATA bacnet_abort_reason_name[] = {
|
||||
};
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
/* generic handling for proprietary range or reserved for ASHRAE */
|
||||
+val_to_split_str(guint32 val, guint32 split_val, const value_string *vs,
|
||||
+ const char *fmt, const char *split_fmt)
|
||||
+{
|
||||
+ if (val < split_val)
|
||||
+ return val_to_str(val, vs, fmt);
|
||||
+ else
|
||||
+ return val_to_str(val, vs, split_fmt);
|
||||
+};
|
||||
|
||||
+ val_to_split_str(index,\
|
||||
+ BACNET_REJECT_REASON_PROPRIETARY,\
|
||||
+ BACnetRejectReason,\
|
||||
+ ASHRAE_Reserved_Text,\
|
||||
+ Vendor_Proprietary_Text)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
+22
-10
@@ -30,6 +30,7 @@
|
||||
#include "config.h"
|
||||
#include "bacdef.h"
|
||||
#include "bacdcode.h"
|
||||
#include "bactext.h"
|
||||
#include "npdu.h"
|
||||
#include "apdu.h"
|
||||
#include "device.h"
|
||||
@@ -226,6 +227,25 @@ void WhoIsHandler(
|
||||
return;
|
||||
}
|
||||
|
||||
/* for debugging... */
|
||||
static void PrintReadPropertyData(BACNET_READ_PROPERTY_DATA *data)
|
||||
{
|
||||
if (data)
|
||||
{
|
||||
if (data->array_index == BACNET_ARRAY_ALL)
|
||||
fprintf(stderr,"%s #%u %s\n",
|
||||
bactext_object_type_name(data->object_type),
|
||||
data->object_instance,
|
||||
bactext_property_name(data->object_property));
|
||||
else
|
||||
fprintf(stderr,"%s #%u %s[%d]\n",
|
||||
bactext_object_type_name(data->object_type),
|
||||
data->object_instance,
|
||||
bactext_property_name(data->object_property),
|
||||
data->array_index);
|
||||
}
|
||||
}
|
||||
|
||||
void ReadPropertyAckHandler(
|
||||
uint8_t *service_request,
|
||||
uint16_t service_len,
|
||||
@@ -243,11 +263,7 @@ void ReadPropertyAckHandler(
|
||||
&data);
|
||||
fprintf(stderr,"Received Read-Property Ack!\n");
|
||||
if (len > 0)
|
||||
fprintf(stderr,"type=%u instance=%u property=%u index=%d\n",
|
||||
data.object_type,
|
||||
data.object_instance,
|
||||
data.object_property,
|
||||
data.array_index);
|
||||
PrintReadPropertyData(&data);
|
||||
}
|
||||
|
||||
void ReadPropertyHandler(
|
||||
@@ -272,11 +288,7 @@ void ReadPropertyHandler(
|
||||
&data);
|
||||
fprintf(stderr,"Received Read-Property Request!\n");
|
||||
if (len > 0)
|
||||
fprintf(stderr,"type=%u instance=%u property=%u index=%d\n",
|
||||
data.object_type,
|
||||
data.object_instance,
|
||||
data.object_property,
|
||||
data.array_index);
|
||||
PrintReadPropertyData(&data);
|
||||
else
|
||||
fprintf(stderr,"Unable to decode Read-Property Request!\n");
|
||||
// prepare a reply
|
||||
|
||||
@@ -145,6 +145,20 @@ const char *indtext_by_index_default(
|
||||
return pString?pString:default_string;
|
||||
}
|
||||
|
||||
const char *indtext_by_index_split_default(
|
||||
INDTEXT_DATA *data_list,
|
||||
int index,
|
||||
int split_index,
|
||||
const char *before_split_default_name,
|
||||
const char *default_name)
|
||||
{
|
||||
if (index < split_index)
|
||||
return indtext_by_index_default(data_list, index, before_split_default_name);
|
||||
else
|
||||
return indtext_by_index_default(data_list, index, default_name);
|
||||
};
|
||||
|
||||
|
||||
const char *indtext_by_index(
|
||||
INDTEXT_DATA *data_list,
|
||||
unsigned index)
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
#ifndef INDTEXT_H
|
||||
#define INDTEXT_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
/* index and text pairs */
|
||||
@@ -83,6 +85,17 @@ const char *indtext_by_index_default(
|
||||
INDTEXT_DATA *data_list,
|
||||
unsigned index,
|
||||
const char *default_name);
|
||||
/* for a given index, return the matching string,
|
||||
or default_name if not found.
|
||||
if the index is before the split,
|
||||
the before_split_default_name is used */
|
||||
const char *indtext_by_index_split_default(
|
||||
INDTEXT_DATA *data_list,
|
||||
int index,
|
||||
int split_index,
|
||||
const char *before_split_default_name,
|
||||
const char *default_name);
|
||||
|
||||
/* returns the number of elements in the list */
|
||||
unsigned indtext_count(
|
||||
INDTEXT_DATA *data_list);
|
||||
|
||||
Reference in New Issue
Block a user