Ran the indent and comment script to standardize the source files.
This commit is contained in:
+30
-31
@@ -114,8 +114,7 @@ int bacapp_encode_application_data(uint8_t * apdu,
|
||||
Return the number of octets consumed. */
|
||||
int bacapp_decode_data(uint8_t * apdu,
|
||||
uint8_t tag_data_type,
|
||||
uint32_t len_value_type,
|
||||
BACNET_APPLICATION_DATA_VALUE * value)
|
||||
uint32_t len_value_type, BACNET_APPLICATION_DATA_VALUE * value)
|
||||
{
|
||||
int len = 0;
|
||||
int object_type = 0;
|
||||
@@ -156,8 +155,7 @@ int bacapp_decode_data(uint8_t * apdu,
|
||||
len = decode_bacnet_time(&apdu[0], &value->type.Time);
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_OBJECT_ID:
|
||||
len = decode_object_id(&apdu[0],
|
||||
&object_type, &instance);
|
||||
len = decode_object_id(&apdu[0], &object_type, &instance);
|
||||
value->type.Object_Id.type = object_type;
|
||||
value->type.Object_Id.instance = instance;
|
||||
break;
|
||||
@@ -199,9 +197,7 @@ int bacapp_decode_application_data(uint8_t * apdu,
|
||||
len += tag_len;
|
||||
value->tag = tag_number;
|
||||
len += bacapp_decode_data(&apdu[len],
|
||||
tag_number,
|
||||
len_value_type,
|
||||
value);
|
||||
tag_number, len_value_type, value);
|
||||
}
|
||||
value->next = NULL;
|
||||
}
|
||||
@@ -209,22 +205,23 @@ int bacapp_decode_application_data(uint8_t * apdu,
|
||||
return len;
|
||||
}
|
||||
|
||||
int bacapp_encode_context_data_value(uint8_t * apdu, uint8_t context_tag_number,
|
||||
BACNET_APPLICATION_DATA_VALUE * value)
|
||||
int bacapp_encode_context_data_value(uint8_t * apdu,
|
||||
uint8_t context_tag_number, BACNET_APPLICATION_DATA_VALUE * value)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
if (value && apdu) {
|
||||
switch (value->tag) {
|
||||
case BACNET_APPLICATION_TAG_NULL:
|
||||
apdu_len = encode_context_null(&apdu[0], context_tag_number);
|
||||
apdu_len = encode_context_null(&apdu[0], context_tag_number);
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_BOOLEAN:
|
||||
apdu_len = encode_context_boolean(&apdu[0], context_tag_number,
|
||||
value->type.Boolean);
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_UNSIGNED_INT:
|
||||
apdu_len = encode_context_unsigned(&apdu[0], context_tag_number,
|
||||
apdu_len =
|
||||
encode_context_unsigned(&apdu[0], context_tag_number,
|
||||
value->type.Unsigned_Int);
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_SIGNED_INT:
|
||||
@@ -236,7 +233,8 @@ int bacapp_encode_context_data_value(uint8_t * apdu, uint8_t context_tag_number,
|
||||
value->type.Real);
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_ENUMERATED:
|
||||
apdu_len = encode_context_enumerated(&apdu[0], context_tag_number,
|
||||
apdu_len =
|
||||
encode_context_enumerated(&apdu[0], context_tag_number,
|
||||
value->type.Enumerated);
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_DATE:
|
||||
@@ -248,27 +246,31 @@ int bacapp_encode_context_data_value(uint8_t * apdu, uint8_t context_tag_number,
|
||||
&value->type.Time);
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_OBJECT_ID:
|
||||
apdu_len = encode_context_object_id(&apdu[0], context_tag_number,
|
||||
apdu_len =
|
||||
encode_context_object_id(&apdu[0], context_tag_number,
|
||||
value->type.Object_Id.type,
|
||||
value->type.Object_Id.instance);
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_OCTET_STRING:
|
||||
apdu_len = encode_context_octet_string(&apdu[0], context_tag_number,
|
||||
apdu_len =
|
||||
encode_context_octet_string(&apdu[0], context_tag_number,
|
||||
&value->type.Octet_String);
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_CHARACTER_STRING:
|
||||
apdu_len = encode_context_character_string(&apdu[0], context_tag_number,
|
||||
&value->type.Character_String);
|
||||
apdu_len =
|
||||
encode_context_character_string(&apdu[0],
|
||||
context_tag_number, &value->type.Character_String);
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_BIT_STRING:
|
||||
apdu_len = encode_context_bitstring(&apdu[0], context_tag_number,
|
||||
apdu_len =
|
||||
encode_context_bitstring(&apdu[0], context_tag_number,
|
||||
&value->type.Bit_String);
|
||||
break;
|
||||
#if 0
|
||||
case BACNET_APPLICATION_TAG_DOUBLE:
|
||||
/* FIXME: double is not implemented yet.*/
|
||||
/* FIXME: double is not implemented yet. */
|
||||
apdu_len = encode_context_double(&apdu[0], context_tag_number,
|
||||
value->type.Double);
|
||||
value->type.Double);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
@@ -280,8 +282,7 @@ int bacapp_encode_context_data_value(uint8_t * apdu, uint8_t context_tag_number,
|
||||
}
|
||||
|
||||
/* returns the fixed tag type for certain context tagged properties */
|
||||
BACNET_APPLICATION_TAG bacapp_context_tag_type(
|
||||
BACNET_PROPERTY_ID property,
|
||||
BACNET_APPLICATION_TAG bacapp_context_tag_type(BACNET_PROPERTY_ID property,
|
||||
uint8_t tag_number)
|
||||
{
|
||||
BACNET_APPLICATION_TAG tag = MAX_BACNET_APPLICATION_TAG;
|
||||
@@ -318,7 +319,7 @@ BACNET_APPLICATION_TAG bacapp_context_tag_type(
|
||||
case 8:
|
||||
tag = BACNET_APPLICATION_TAG_BOOLEAN;
|
||||
break;
|
||||
case 4: /* propertyValue: abstract syntax */
|
||||
case 4: /* propertyValue: abstract syntax */
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -331,8 +332,8 @@ BACNET_APPLICATION_TAG bacapp_context_tag_type(
|
||||
case 3:
|
||||
tag = BACNET_APPLICATION_TAG_UNSIGNED_INT;
|
||||
break;
|
||||
case 0: /* calendarEntry: abstract syntax + context */
|
||||
case 2: /* list of BACnetTimeValue: abstract syntax */
|
||||
case 0: /* calendarEntry: abstract syntax + context */
|
||||
case 2: /* list of BACnetTimeValue: abstract syntax */
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -345,14 +346,14 @@ BACNET_APPLICATION_TAG bacapp_context_tag_type(
|
||||
}
|
||||
|
||||
int bacapp_encode_context_data(uint8_t * apdu,
|
||||
BACNET_APPLICATION_DATA_VALUE * value,
|
||||
BACNET_PROPERTY_ID property)
|
||||
BACNET_APPLICATION_DATA_VALUE * value, BACNET_PROPERTY_ID property)
|
||||
{
|
||||
int apdu_len = 0;
|
||||
BACNET_APPLICATION_TAG tag_data_type;
|
||||
|
||||
if (value && apdu) {
|
||||
tag_data_type = bacapp_context_tag_type(property, value->context_tag);
|
||||
tag_data_type =
|
||||
bacapp_context_tag_type(property, value->context_tag);
|
||||
if (tag_data_type < MAX_BACNET_APPLICATION_TAG) {
|
||||
apdu_len = bacapp_encode_context_data_value(&apdu[0],
|
||||
value->context_tag, value);
|
||||
@@ -367,7 +368,7 @@ int bacapp_encode_context_data(uint8_t * apdu,
|
||||
}
|
||||
|
||||
int bacapp_decode_context_data(uint8_t * apdu,
|
||||
int max_apdu_len, BACNET_APPLICATION_DATA_VALUE * value,
|
||||
int max_apdu_len, BACNET_APPLICATION_DATA_VALUE * value,
|
||||
BACNET_PROPERTY_ID property)
|
||||
{
|
||||
int apdu_len = 0, len = 0;
|
||||
@@ -387,9 +388,7 @@ int bacapp_decode_context_data(uint8_t * apdu,
|
||||
value->tag = bacapp_context_tag_type(property, tag_number);
|
||||
if (value->tag < MAX_BACNET_APPLICATION_TAG) {
|
||||
len = bacapp_decode_data(&apdu[apdu_len],
|
||||
value->tag,
|
||||
len_value_type,
|
||||
value);
|
||||
value->tag, len_value_type, value);
|
||||
apdu_len += len;
|
||||
} else {
|
||||
/* FIXME: what now? */
|
||||
|
||||
@@ -43,8 +43,8 @@
|
||||
|
||||
struct BACnet_Application_Data_Value;
|
||||
typedef struct BACnet_Application_Data_Value {
|
||||
bool context_specific; /* true if context specific data */
|
||||
uint8_t context_tag; /* only used for context specific data */
|
||||
bool context_specific; /* true if context specific data */
|
||||
uint8_t context_tag; /* only used for context specific data */
|
||||
uint8_t tag; /* application tag data type */
|
||||
union {
|
||||
/* NULL - not needed as it is encoded in the tag alone */
|
||||
@@ -86,12 +86,10 @@ extern "C" {
|
||||
BACNET_PROPERTY_ID property);
|
||||
|
||||
int bacapp_encode_context_data_value(uint8_t * apdu,
|
||||
uint8_t context_tag_number,
|
||||
BACNET_APPLICATION_DATA_VALUE * value);
|
||||
uint8_t context_tag_number, BACNET_APPLICATION_DATA_VALUE * value);
|
||||
|
||||
BACNET_APPLICATION_TAG bacapp_context_tag_type(
|
||||
BACNET_PROPERTY_ID property,
|
||||
uint8_t tag_number);
|
||||
BACNET_APPLICATION_TAG bacapp_context_tag_type(BACNET_PROPERTY_ID
|
||||
property, uint8_t tag_number);
|
||||
|
||||
bool bacapp_copy(BACNET_APPLICATION_DATA_VALUE * dest_value,
|
||||
BACNET_APPLICATION_DATA_VALUE * src_value);
|
||||
|
||||
@@ -774,7 +774,7 @@ int encode_tagged_null(uint8_t * apdu)
|
||||
return encode_tag(&apdu[0], BACNET_APPLICATION_TAG_NULL, false, 0);
|
||||
}
|
||||
|
||||
int encode_context_null(uint8_t * apdu, int tag_number)
|
||||
int encode_context_null(uint8_t * apdu, int tag_number)
|
||||
{
|
||||
return encode_tag(&apdu[0], tag_number, true, 0);
|
||||
}
|
||||
@@ -875,14 +875,15 @@ int encode_tagged_bitstring(uint8_t * apdu, BACNET_BIT_STRING * bit_string)
|
||||
}
|
||||
|
||||
int encode_context_bitstring(uint8_t * apdu, int tag_number,
|
||||
BACNET_BIT_STRING * bit_string)
|
||||
BACNET_BIT_STRING * bit_string)
|
||||
{
|
||||
int len = 0;
|
||||
int bit_string_encoded_length = 1; /* 1 for the bits remaining octet */
|
||||
|
||||
/* bit string may use more than 1 octet for the tag, so find out how many */
|
||||
bit_string_encoded_length += bitstring_bytes_used(bit_string);
|
||||
len = encode_tag(&apdu[0], tag_number, true, bit_string_encoded_length);
|
||||
len =
|
||||
encode_tag(&apdu[0], tag_number, true, bit_string_encoded_length);
|
||||
len += encode_bitstring(&apdu[len], bit_string);
|
||||
|
||||
return len;
|
||||
@@ -1042,7 +1043,7 @@ int encode_octet_string(uint8_t * apdu, BACNET_OCTET_STRING * octet_string)
|
||||
{
|
||||
int len = 0; /* return value */
|
||||
uint8_t *value;
|
||||
int i = 0; /* loop counter */
|
||||
int i = 0; /* loop counter */
|
||||
|
||||
if (octet_string) {
|
||||
/* FIXME: might need to pass in the length of the APDU
|
||||
@@ -1128,7 +1129,7 @@ int encode_bacnet_character_string(uint8_t * apdu,
|
||||
apdu[0] = characterstring_encoding(char_string);
|
||||
pString = characterstring_value(char_string);
|
||||
for (i = 0; i < len; i++) {
|
||||
apdu[1+i] = pString[i];
|
||||
apdu[1 + i] = pString[i];
|
||||
}
|
||||
|
||||
return len + 1 /* for encoding */ ;
|
||||
@@ -1447,7 +1448,7 @@ int encode_tagged_time(uint8_t * apdu, BACNET_TIME * btime)
|
||||
return len;
|
||||
}
|
||||
|
||||
int encode_context_time(uint8_t * apdu, int tag_number,
|
||||
int encode_context_time(uint8_t * apdu, int tag_number,
|
||||
BACNET_TIME * btime)
|
||||
{
|
||||
int len = 0; /* return value */
|
||||
|
||||
@@ -72,7 +72,7 @@ extern "C" {
|
||||
|
||||
/* from clause 20.2.2 Encoding of a Null Value */
|
||||
int encode_tagged_null(uint8_t * apdu);
|
||||
int encode_context_null(uint8_t * apdu, int tag_number);
|
||||
int encode_context_null(uint8_t * apdu, int tag_number);
|
||||
|
||||
/* from clause 20.2.3 Encoding of a Boolean Value */
|
||||
int encode_tagged_boolean(uint8_t * apdu, bool boolean_value);
|
||||
@@ -90,7 +90,7 @@ extern "C" {
|
||||
int encode_tagged_bitstring(uint8_t * apdu,
|
||||
BACNET_BIT_STRING * bit_string);
|
||||
int encode_context_bitstring(uint8_t * apdu, int tag_number,
|
||||
BACNET_BIT_STRING * bit_string);
|
||||
BACNET_BIT_STRING * bit_string);
|
||||
|
||||
/* from clause 20.2.6 Encoding of a Real Number Value */
|
||||
/* and 20.2.1 General Rules for Encoding BACnet Tags */
|
||||
@@ -171,7 +171,7 @@ extern "C" {
|
||||
int encode_bacnet_time(uint8_t * apdu, BACNET_TIME * btime);
|
||||
int encode_tagged_time(uint8_t * apdu, BACNET_TIME * btime);
|
||||
int decode_bacnet_time(uint8_t * apdu, BACNET_TIME * btime);
|
||||
int encode_context_time(uint8_t * apdu, int tag_number,
|
||||
int encode_context_time(uint8_t * apdu, int tag_number,
|
||||
BACNET_TIME * btime);
|
||||
|
||||
/* BACnet Date */
|
||||
|
||||
@@ -639,7 +639,7 @@ INDTEXT_DATA bacnet_property_names[] = {
|
||||
{PROP_REQUESTED_UPDATE_INTERVAL, "requested-update-interval"}
|
||||
,
|
||||
{PROP_RESTART_NOTIFICATION_RECIPIENTS,
|
||||
"restart-notification-recipients"}
|
||||
"restart-notification-recipients"}
|
||||
,
|
||||
{PROP_TIME_OF_DEVICE_RESTART, "time-of-device-restart"}
|
||||
,
|
||||
@@ -648,7 +648,7 @@ INDTEXT_DATA bacnet_property_names[] = {
|
||||
{PROP_TRIGGER, "trigger"}
|
||||
,
|
||||
{PROP_UTC_TIME_SYNCHRONIZATION_RECIPIENTS,
|
||||
"UTC-time-synchronization-recipients"}
|
||||
"UTC-time-synchronization-recipients"}
|
||||
,
|
||||
{PROP_NODE_SUBTYPE, "node-subtype"}
|
||||
,
|
||||
|
||||
@@ -115,12 +115,12 @@ static void days_since_epoch_into_ymd(uint32_t days,
|
||||
year++;
|
||||
}
|
||||
|
||||
while (days >= (uint32_t)month_days(year, month)) {
|
||||
while (days >= (uint32_t) month_days(year, month)) {
|
||||
days -= month_days(year, month);
|
||||
month++;
|
||||
}
|
||||
|
||||
day += ((uint8_t)days);
|
||||
day += ((uint8_t) days);
|
||||
|
||||
if (pYear)
|
||||
*pYear = year;
|
||||
@@ -137,7 +137,7 @@ static void days_since_epoch_into_ymd(uint32_t days,
|
||||
/* wday 1=Monday...7=Sunday */
|
||||
static uint8_t day_of_week(uint16_t year, uint8_t month, uint8_t day)
|
||||
{
|
||||
return ((uint8_t)(days_since_epoch(year, month, day) % 7) + 1);
|
||||
return ((uint8_t) (days_since_epoch(year, month, day) % 7) + 1);
|
||||
}
|
||||
|
||||
/* if the date1 is the same as date2, return is 0
|
||||
@@ -292,9 +292,9 @@ static void seconds_since_midnight_into_hms(uint32_t seconds,
|
||||
uint8_t hour = 0;
|
||||
uint8_t minute = 0;
|
||||
|
||||
hour = (uint8_t)(seconds / (60 * 60));
|
||||
hour = (uint8_t) (seconds / (60 * 60));
|
||||
seconds -= (hour * 60 * 60);
|
||||
minute = (uint8_t)(seconds / 60);
|
||||
minute = (uint8_t) (seconds / 60);
|
||||
seconds -= (minute * 60);
|
||||
|
||||
if (pHours)
|
||||
@@ -302,7 +302,7 @@ static void seconds_since_midnight_into_hms(uint32_t seconds,
|
||||
if (pMinutes)
|
||||
*pMinutes = minute;
|
||||
if (pSeconds)
|
||||
*pSeconds = (uint8_t)seconds;
|
||||
*pSeconds = (uint8_t) seconds;
|
||||
}
|
||||
|
||||
void datetime_add_minutes(BACNET_DATE_TIME * bdatetime, uint32_t minutes)
|
||||
@@ -337,7 +337,7 @@ void datetime_add_minutes(BACNET_DATE_TIME * bdatetime, uint32_t minutes)
|
||||
|
||||
bool datetime_wildcard(BACNET_DATE_TIME * bdatetime)
|
||||
{
|
||||
bool wildcard_present = false;
|
||||
bool wildcard_present = false;
|
||||
|
||||
if (bdatetime) {
|
||||
if ((bdatetime->date.year == (1900 + 0xFF)) &&
|
||||
|
||||
@@ -38,13 +38,13 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef enum {
|
||||
BACNET_WEEKDAY_MONDAY = 1,
|
||||
BACNET_WEEKDAY_TUESDAY = 2,
|
||||
BACNET_WEEKDAY_WEDNESDAY = 3,
|
||||
BACNET_WEEKDAY_THURSDAY = 4,
|
||||
BACNET_WEEKDAY_FRIDAY = 5,
|
||||
BACNET_WEEKDAY_SATURDAY = 6,
|
||||
BACNET_WEEKDAY_SUNDAY = 7
|
||||
BACNET_WEEKDAY_MONDAY = 1,
|
||||
BACNET_WEEKDAY_TUESDAY = 2,
|
||||
BACNET_WEEKDAY_WEDNESDAY = 3,
|
||||
BACNET_WEEKDAY_THURSDAY = 4,
|
||||
BACNET_WEEKDAY_FRIDAY = 5,
|
||||
BACNET_WEEKDAY_SATURDAY = 6,
|
||||
BACNET_WEEKDAY_SUNDAY = 7
|
||||
} BACNET_WEEKDAY;
|
||||
|
||||
/* date */
|
||||
|
||||
@@ -309,7 +309,7 @@ void handler_write_property(uint8_t * service_request,
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
#endif /* BACFILE */
|
||||
#endif /* BACFILE */
|
||||
default:
|
||||
len =
|
||||
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||
|
||||
@@ -48,9 +48,8 @@ uint8_t Send_Write_Property_Request_Data(uint32_t device_id,
|
||||
BACNET_OBJECT_TYPE object_type,
|
||||
uint32_t object_instance,
|
||||
BACNET_PROPERTY_ID object_property,
|
||||
uint8_t *application_data,
|
||||
int application_data_len,
|
||||
uint8_t priority, int32_t array_index)
|
||||
uint8_t * application_data,
|
||||
int application_data_len, uint8_t priority, int32_t array_index)
|
||||
{
|
||||
BACNET_ADDRESS dest;
|
||||
BACNET_ADDRESS my_address;
|
||||
@@ -83,7 +82,8 @@ uint8_t Send_Write_Property_Request_Data(uint32_t device_id,
|
||||
data.object_property = object_property;
|
||||
data.array_index = array_index;
|
||||
data.application_data_len = application_data_len;
|
||||
memcpy(&data.application_data[0],&application_data[0], application_data_len);
|
||||
memcpy(&data.application_data[0], &application_data[0],
|
||||
application_data_len);
|
||||
data.priority = priority;
|
||||
len = wp_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||
invoke_id, &data);
|
||||
@@ -126,13 +126,12 @@ uint8_t Send_Write_Property_Request(uint32_t device_id,
|
||||
BACNET_APPLICATION_DATA_VALUE * object_value,
|
||||
uint8_t priority, int32_t array_index)
|
||||
{
|
||||
uint8_t application_data[MAX_APDU] = {0};
|
||||
uint8_t application_data[MAX_APDU] = { 0 };
|
||||
int apdu_len = 0, len = 0;
|
||||
|
||||
while (object_value) {
|
||||
len = bacapp_encode_data(
|
||||
&application_data[apdu_len],
|
||||
object_value);
|
||||
len = bacapp_encode_data(&application_data[apdu_len],
|
||||
object_value);
|
||||
if ((len + apdu_len) < MAX_APDU) {
|
||||
apdu_len += len;
|
||||
} else {
|
||||
@@ -141,13 +140,9 @@ uint8_t Send_Write_Property_Request(uint32_t device_id,
|
||||
object_value = object_value->next;
|
||||
}
|
||||
|
||||
return Send_Write_Property_Request_Data(
|
||||
device_id,
|
||||
return Send_Write_Property_Request_Data(device_id,
|
||||
object_type,
|
||||
object_instance,
|
||||
object_property,
|
||||
&application_data[0],
|
||||
apdu_len,
|
||||
priority,
|
||||
array_index);
|
||||
&application_data[0], apdu_len, priority, array_index);
|
||||
}
|
||||
|
||||
@@ -139,9 +139,9 @@ float Analog_Output_Present_Value(uint32_t object_instance)
|
||||
|
||||
unsigned Analog_Output_Present_Value_Priority(uint32_t object_instance)
|
||||
{
|
||||
unsigned index = 0; /* instance to index conversion */
|
||||
unsigned i = 0; /* loop counter */
|
||||
unsigned priority = 0; /* return value */
|
||||
unsigned index = 0; /* instance to index conversion */
|
||||
unsigned i = 0; /* loop counter */
|
||||
unsigned priority = 0; /* return value */
|
||||
|
||||
Analog_Output_Init();
|
||||
index = Analog_Output_Instance_To_Index(object_instance);
|
||||
@@ -157,10 +157,8 @@ unsigned Analog_Output_Present_Value_Priority(uint32_t object_instance)
|
||||
return priority;
|
||||
}
|
||||
|
||||
bool Analog_Output_Present_Value_Set(
|
||||
uint32_t object_instance,
|
||||
float value,
|
||||
unsigned priority)
|
||||
bool Analog_Output_Present_Value_Set(uint32_t object_instance,
|
||||
float value, unsigned priority)
|
||||
{
|
||||
unsigned index = 0;
|
||||
bool status = false;
|
||||
@@ -170,7 +168,7 @@ bool Analog_Output_Present_Value_Set(
|
||||
if (priority && (priority <= BACNET_MAX_PRIORITY) &&
|
||||
(priority != 6 /* reserved */ ) &&
|
||||
(value >= 0.0) && (value <= 100.0)) {
|
||||
Analog_Output_Level[index][priority] = (uint8_t)value;
|
||||
Analog_Output_Level[index][priority] = (uint8_t) value;
|
||||
/* Note: you could set the physical output here to the next
|
||||
highest priority, or to the relinquish default if no
|
||||
priorities are set.
|
||||
@@ -184,8 +182,7 @@ bool Analog_Output_Present_Value_Set(
|
||||
return status;
|
||||
}
|
||||
|
||||
bool Analog_Output_Present_Value_Relinquish(
|
||||
uint32_t object_instance,
|
||||
bool Analog_Output_Present_Value_Relinquish(uint32_t object_instance,
|
||||
int priority)
|
||||
{
|
||||
unsigned index = 0;
|
||||
@@ -366,10 +363,9 @@ bool Analog_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
|
||||
/* Command priority 6 is reserved for use by Minimum On/Off
|
||||
algorithm and may not be used for other purposes in any
|
||||
object. */
|
||||
status = Analog_Output_Present_Value_Set(
|
||||
wp_data->object_instance,
|
||||
value.type.Real,
|
||||
wp_data->priority);
|
||||
status =
|
||||
Analog_Output_Present_Value_Set(wp_data->object_instance,
|
||||
value.type.Real, wp_data->priority);
|
||||
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
|
||||
@@ -384,9 +380,9 @@ bool Analog_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
|
||||
level = AO_LEVEL_NULL;
|
||||
object_index =
|
||||
Analog_Output_Instance_To_Index(wp_data->object_instance);
|
||||
status = Analog_Output_Present_Value_Relinquish(
|
||||
wp_data->object_instance,
|
||||
wp_data->priority);
|
||||
status =
|
||||
Analog_Output_Present_Value_Relinquish(wp_data->
|
||||
object_instance, wp_data->priority);
|
||||
if (!status) {
|
||||
*error_class = ERROR_CLASS_PROPERTY;
|
||||
*error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
|
||||
|
||||
@@ -40,13 +40,11 @@ extern "C" {
|
||||
uint32_t Analog_Output_Index_To_Instance(unsigned index);
|
||||
char *Analog_Output_Name(uint32_t object_instance);
|
||||
float Analog_Output_Present_Value(uint32_t object_instance);
|
||||
unsigned Analog_Output_Present_Value_Priority(uint32_t object_instance);
|
||||
bool Analog_Output_Present_Value_Set(
|
||||
uint32_t object_instance,
|
||||
float value,
|
||||
unsigned priority);
|
||||
bool Analog_Output_Present_Value_Relinquish(
|
||||
uint32_t object_instance,
|
||||
unsigned Analog_Output_Present_Value_Priority(uint32_t
|
||||
object_instance);
|
||||
bool Analog_Output_Present_Value_Set(uint32_t object_instance,
|
||||
float value, unsigned priority);
|
||||
bool Analog_Output_Present_Value_Relinquish(uint32_t object_instance,
|
||||
int priority);
|
||||
|
||||
|
||||
|
||||
+116
-107
@@ -143,7 +143,7 @@ void Load_Control_Init(void)
|
||||
Shed_Duration[i] = 0;
|
||||
Duty_Window[i] = 0;
|
||||
Load_Control_Enable[i] = true;
|
||||
Full_Duty_Baseline[i] = 1.500; /* kilowatts */
|
||||
Full_Duty_Baseline[i] = 1.500; /* kilowatts */
|
||||
for (j = 0; j < MAX_SHED_LEVELS; j++) {
|
||||
/* FIXME: fake data for lighting application */
|
||||
/* The array shall be ordered by increasing shed amount. */
|
||||
@@ -254,12 +254,11 @@ struct tm {
|
||||
timer = time(NULL);
|
||||
tblock = localtime(&timer);
|
||||
datetime_set_values(bdatetime,
|
||||
(uint16_t)tblock->tm_year,
|
||||
(uint8_t)tblock->tm_mon,
|
||||
(uint8_t)tblock->tm_mday,
|
||||
(uint8_t)tblock->tm_hour,
|
||||
(uint8_t)tblock->tm_min,
|
||||
(uint8_t)tblock->tm_sec, 0);
|
||||
(uint16_t) tblock->tm_year,
|
||||
(uint8_t) tblock->tm_mon,
|
||||
(uint8_t) tblock->tm_mday,
|
||||
(uint8_t) tblock->tm_hour,
|
||||
(uint8_t) tblock->tm_min, (uint8_t) tblock->tm_sec, 0);
|
||||
}
|
||||
|
||||
/* convert the shed level request into an Analog Output Present_Value */
|
||||
@@ -270,62 +269,68 @@ static float Requested_Shed_Level_Value(int object_index)
|
||||
float requested_level = 0.0;
|
||||
|
||||
switch (Requested_Shed_Level[object_index].type) {
|
||||
case BACNET_SHED_TYPE_PERCENT:
|
||||
requested_level = (float)Requested_Shed_Level[object_index].value.percent;
|
||||
break;
|
||||
case BACNET_SHED_TYPE_AMOUNT:
|
||||
/* Assumptions: wattage is linear with analog output level */
|
||||
requested_level = Full_Duty_Baseline[object_index] - Requested_Shed_Level[object_index].value.amount;
|
||||
requested_level /= Full_Duty_Baseline[object_index];
|
||||
requested_level *= 100.0;
|
||||
break;
|
||||
case BACNET_SHED_TYPE_LEVEL:
|
||||
default:
|
||||
for (i = 0; i < MAX_SHED_LEVELS; i++) {
|
||||
if (Shed_Levels[object_index][i] <= Requested_Shed_Level[object_index].value.level)
|
||||
shed_level_index = i;
|
||||
}
|
||||
requested_level = Shed_Level_Values[shed_level_index];
|
||||
break;
|
||||
case BACNET_SHED_TYPE_PERCENT:
|
||||
requested_level =
|
||||
(float) Requested_Shed_Level[object_index].value.percent;
|
||||
break;
|
||||
case BACNET_SHED_TYPE_AMOUNT:
|
||||
/* Assumptions: wattage is linear with analog output level */
|
||||
requested_level =
|
||||
Full_Duty_Baseline[object_index] -
|
||||
Requested_Shed_Level[object_index].value.amount;
|
||||
requested_level /= Full_Duty_Baseline[object_index];
|
||||
requested_level *= 100.0;
|
||||
break;
|
||||
case BACNET_SHED_TYPE_LEVEL:
|
||||
default:
|
||||
for (i = 0; i < MAX_SHED_LEVELS; i++) {
|
||||
if (Shed_Levels[object_index][i] <=
|
||||
Requested_Shed_Level[object_index].value.level)
|
||||
shed_level_index = i;
|
||||
}
|
||||
requested_level = Shed_Level_Values[shed_level_index];
|
||||
break;
|
||||
}
|
||||
|
||||
return requested_level;
|
||||
}
|
||||
|
||||
static void Shed_Level_Copy(BACNET_SHED_LEVEL *dest, BACNET_SHED_LEVEL *src)
|
||||
static void Shed_Level_Copy(BACNET_SHED_LEVEL * dest,
|
||||
BACNET_SHED_LEVEL * src)
|
||||
{
|
||||
if (dest && src) {
|
||||
dest->type = src->type;
|
||||
switch (src->type) {
|
||||
case BACNET_SHED_TYPE_PERCENT:
|
||||
dest->value.percent = src->value.percent;
|
||||
break;
|
||||
case BACNET_SHED_TYPE_AMOUNT:
|
||||
dest->value.amount = src->value.amount;
|
||||
break;
|
||||
case BACNET_SHED_TYPE_LEVEL:
|
||||
default:
|
||||
dest->value.level = src->value.level;
|
||||
break;
|
||||
case BACNET_SHED_TYPE_PERCENT:
|
||||
dest->value.percent = src->value.percent;
|
||||
break;
|
||||
case BACNET_SHED_TYPE_AMOUNT:
|
||||
dest->value.amount = src->value.amount;
|
||||
break;
|
||||
case BACNET_SHED_TYPE_LEVEL:
|
||||
default:
|
||||
dest->value.level = src->value.level;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void Shed_Level_Default_Set(BACNET_SHED_LEVEL *dest, BACNET_SHED_LEVEL_TYPE type)
|
||||
static void Shed_Level_Default_Set(BACNET_SHED_LEVEL * dest,
|
||||
BACNET_SHED_LEVEL_TYPE type)
|
||||
{
|
||||
if (dest) {
|
||||
dest->type = type;
|
||||
switch (type) {
|
||||
case BACNET_SHED_TYPE_PERCENT:
|
||||
dest->value.percent = 100;
|
||||
break;
|
||||
case BACNET_SHED_TYPE_AMOUNT:
|
||||
dest->value.amount = 0.0;
|
||||
break;
|
||||
case BACNET_SHED_TYPE_LEVEL:
|
||||
default:
|
||||
dest->value.level = 0;
|
||||
break;
|
||||
case BACNET_SHED_TYPE_PERCENT:
|
||||
dest->value.percent = 100;
|
||||
break;
|
||||
case BACNET_SHED_TYPE_AMOUNT:
|
||||
dest->value.amount = 0.0;
|
||||
break;
|
||||
case BACNET_SHED_TYPE_LEVEL:
|
||||
default:
|
||||
dest->value.level = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -367,15 +372,15 @@ static LOAD_CONTROL_STATE Load_Control_State_Previously[MAX_LOAD_CONTROLS];
|
||||
static void Print_Load_Control_State(int object_index)
|
||||
{
|
||||
char *Load_Control_State_Text[MAX_LOAD_CONTROLS] = {
|
||||
"SHED_INACTIVE",
|
||||
"SHED_REQUEST_PENDING",
|
||||
"SHED_NON_COMPLIANT",
|
||||
"SHED_COMPLIANT"
|
||||
"SHED_INACTIVE",
|
||||
"SHED_REQUEST_PENDING",
|
||||
"SHED_NON_COMPLIANT",
|
||||
"SHED_COMPLIANT"
|
||||
};
|
||||
|
||||
if (object_index < MAX_LOAD_CONTROLS) {
|
||||
if (Load_Control_State[object_index] < MAX_LOAD_CONTROL_STATE) {
|
||||
printf("Load Control[%d]=%s\n",object_index,
|
||||
printf("Load Control[%d]=%s\n", object_index,
|
||||
Load_Control_State_Text[Load_Control_State[object_index]]);
|
||||
}
|
||||
}
|
||||
@@ -392,25 +397,26 @@ void Load_Control_State_Machine(int object_index)
|
||||
Load_Control_Request_Written[object_index] = false;
|
||||
/* request to cancel using default values? */
|
||||
switch (Requested_Shed_Level[object_index].type) {
|
||||
case BACNET_SHED_TYPE_PERCENT:
|
||||
if (Requested_Shed_Level[object_index].value.percent ==
|
||||
DEFAULT_VALUE_PERCENT)
|
||||
Load_Control_State[object_index] = SHED_INACTIVE;
|
||||
break;
|
||||
case BACNET_SHED_TYPE_AMOUNT:
|
||||
if (Requested_Shed_Level[object_index].value.amount ==
|
||||
DEFAULT_VALUE_AMOUNT)
|
||||
Load_Control_State[object_index] = SHED_INACTIVE;
|
||||
break;
|
||||
case BACNET_SHED_TYPE_LEVEL:
|
||||
default:
|
||||
if (Requested_Shed_Level[object_index].value.level ==
|
||||
DEFAULT_VALUE_LEVEL)
|
||||
Load_Control_State[object_index] = SHED_INACTIVE;
|
||||
break;
|
||||
case BACNET_SHED_TYPE_PERCENT:
|
||||
if (Requested_Shed_Level[object_index].value.percent ==
|
||||
DEFAULT_VALUE_PERCENT)
|
||||
Load_Control_State[object_index] = SHED_INACTIVE;
|
||||
break;
|
||||
case BACNET_SHED_TYPE_AMOUNT:
|
||||
if (Requested_Shed_Level[object_index].value.amount ==
|
||||
DEFAULT_VALUE_AMOUNT)
|
||||
Load_Control_State[object_index] = SHED_INACTIVE;
|
||||
break;
|
||||
case BACNET_SHED_TYPE_LEVEL:
|
||||
default:
|
||||
if (Requested_Shed_Level[object_index].value.level ==
|
||||
DEFAULT_VALUE_LEVEL)
|
||||
Load_Control_State[object_index] = SHED_INACTIVE;
|
||||
break;
|
||||
}
|
||||
if (Load_Control_State[object_index] == SHED_INACTIVE) {
|
||||
printf("Load Control[%d]:Requested Shed Level=Default\n",object_index);
|
||||
printf("Load Control[%d]:Requested Shed Level=Default\n",
|
||||
object_index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -431,7 +437,9 @@ void Load_Control_State_Machine(int object_index)
|
||||
if (diff < 0) {
|
||||
/* CancelShed */
|
||||
/* FIXME: stop shedding! i.e. relinquish */
|
||||
printf("Load Control[%d]:Current Time is after Start Time + Duration\n",object_index);
|
||||
printf
|
||||
("Load Control[%d]:Current Time is after Start Time + Duration\n",
|
||||
object_index);
|
||||
Load_Control_State[object_index] = SHED_INACTIVE;
|
||||
break;
|
||||
}
|
||||
@@ -439,33 +447,28 @@ void Load_Control_State_Machine(int object_index)
|
||||
if (diff < 0) {
|
||||
/* current time prior to start time */
|
||||
/* ReconfigurePending */
|
||||
Shed_Level_Copy(
|
||||
&Expected_Shed_Level[object_index],
|
||||
Shed_Level_Copy(&Expected_Shed_Level[object_index],
|
||||
&Requested_Shed_Level[object_index]);
|
||||
Shed_Level_Default_Set(
|
||||
&Actual_Shed_Level[object_index],
|
||||
Shed_Level_Default_Set(&Actual_Shed_Level[object_index],
|
||||
Requested_Shed_Level[object_index].type);
|
||||
} else if (diff > 0) {
|
||||
/* current time after to start time */
|
||||
printf("Load Control[%d]:Current Time is after Start Time\n",object_index);
|
||||
printf("Load Control[%d]:Current Time is after Start Time\n",
|
||||
object_index);
|
||||
/* AbleToMeetShed */
|
||||
if (Able_To_Meet_Shed_Request(object_index)) {
|
||||
Shed_Level_Copy(
|
||||
&Expected_Shed_Level[object_index],
|
||||
Shed_Level_Copy(&Expected_Shed_Level[object_index],
|
||||
&Requested_Shed_Level[object_index]);
|
||||
Analog_Output_Present_Value_Set(object_index,
|
||||
Requested_Shed_Level_Value(object_index), 4);
|
||||
Shed_Level_Copy(
|
||||
&Actual_Shed_Level[object_index],
|
||||
Shed_Level_Copy(&Actual_Shed_Level[object_index],
|
||||
&Requested_Shed_Level[object_index]);
|
||||
Load_Control_State[object_index] = SHED_COMPLIANT;
|
||||
} else {
|
||||
/* CannotMeetShed */
|
||||
Shed_Level_Default_Set(
|
||||
&Expected_Shed_Level[object_index],
|
||||
Shed_Level_Default_Set(&Expected_Shed_Level[object_index],
|
||||
Requested_Shed_Level[object_index].type);
|
||||
Shed_Level_Default_Set(
|
||||
&Actual_Shed_Level[object_index],
|
||||
Shed_Level_Default_Set(&Actual_Shed_Level[object_index],
|
||||
Requested_Shed_Level[object_index].type);
|
||||
Load_Control_State[object_index] = SHED_NON_COMPLIANT;
|
||||
}
|
||||
@@ -479,14 +482,17 @@ void Load_Control_State_Machine(int object_index)
|
||||
diff = datetime_compare(&End_Time[object_index], &Current_Time);
|
||||
if (diff < 0) {
|
||||
/* FinishedUnsuccessfulShed */
|
||||
printf("Load Control[%d]:Current Time is after Start Time + Duration\n",object_index);
|
||||
printf
|
||||
("Load Control[%d]:Current Time is after Start Time + Duration\n",
|
||||
object_index);
|
||||
Load_Control_State[object_index] = SHED_INACTIVE;
|
||||
break;
|
||||
}
|
||||
if (Load_Control_Request_Written[object_index] ||
|
||||
Start_Time_Property_Written[object_index]) {
|
||||
/* UnsuccessfulShedReconfigured */
|
||||
printf("Load Control[%d]:Control Property written\n",object_index);
|
||||
printf("Load Control[%d]:Control Property written\n",
|
||||
object_index);
|
||||
Load_Control_Request_Written[object_index] = false;
|
||||
Start_Time_Property_Written[object_index] = false;
|
||||
Load_Control_State[object_index] = SHED_REQUEST_PENDING;
|
||||
@@ -494,14 +500,13 @@ void Load_Control_State_Machine(int object_index)
|
||||
}
|
||||
if (Able_To_Meet_Shed_Request(object_index)) {
|
||||
/* CanNowComplyWithShed */
|
||||
printf("Load Control[%d]:Able to meet Shed Request\n",object_index);
|
||||
Shed_Level_Copy(
|
||||
&Expected_Shed_Level[object_index],
|
||||
printf("Load Control[%d]:Able to meet Shed Request\n",
|
||||
object_index);
|
||||
Shed_Level_Copy(&Expected_Shed_Level[object_index],
|
||||
&Requested_Shed_Level[object_index]);
|
||||
Analog_Output_Present_Value_Set(object_index,
|
||||
Requested_Shed_Level_Value(object_index), 4);
|
||||
Shed_Level_Copy(
|
||||
&Actual_Shed_Level[object_index],
|
||||
Shed_Level_Copy(&Actual_Shed_Level[object_index],
|
||||
&Requested_Shed_Level[object_index]);
|
||||
Load_Control_State[object_index] = SHED_COMPLIANT;
|
||||
}
|
||||
@@ -514,15 +519,18 @@ void Load_Control_State_Machine(int object_index)
|
||||
diff = datetime_compare(&End_Time[object_index], &Current_Time);
|
||||
if (diff < 0) {
|
||||
/* FinishedSuccessfulShed */
|
||||
printf("Load Control[%d]:Current Time is after Start Time + Duration\n",object_index);
|
||||
printf
|
||||
("Load Control[%d]:Current Time is after Start Time + Duration\n",
|
||||
object_index);
|
||||
datetime_wildcard_set(&Start_Time[i]);
|
||||
Load_Control_State[object_index] = SHED_INACTIVE;
|
||||
break;
|
||||
}
|
||||
if (Load_Control_Request_Written[object_index] ||
|
||||
Start_Time_Property_Written[object_index]) {
|
||||
Start_Time_Property_Written[object_index]) {
|
||||
/* UnsuccessfulShedReconfigured */
|
||||
printf("Load Control[%d]:Control Property written\n",object_index);
|
||||
printf("Load Control[%d]:Control Property written\n",
|
||||
object_index);
|
||||
Load_Control_Request_Written[object_index] = false;
|
||||
Start_Time_Property_Written[object_index] = false;
|
||||
Load_Control_State[object_index] = SHED_REQUEST_PENDING;
|
||||
@@ -530,12 +538,11 @@ void Load_Control_State_Machine(int object_index)
|
||||
}
|
||||
if (!Able_To_Meet_Shed_Request(object_index)) {
|
||||
/* CanNoLongerComplyWithShed */
|
||||
printf("Load Control[%d]:Not able to meet Shed Request\n",object_index);
|
||||
Shed_Level_Default_Set(
|
||||
&Expected_Shed_Level[object_index],
|
||||
printf("Load Control[%d]:Not able to meet Shed Request\n",
|
||||
object_index);
|
||||
Shed_Level_Default_Set(&Expected_Shed_Level[object_index],
|
||||
Requested_Shed_Level[object_index].type);
|
||||
Shed_Level_Default_Set(
|
||||
&Actual_Shed_Level[object_index],
|
||||
Shed_Level_Default_Set(&Actual_Shed_Level[object_index],
|
||||
Requested_Shed_Level[object_index].type);
|
||||
Load_Control_State[object_index] = SHED_NON_COMPLIANT;
|
||||
}
|
||||
@@ -543,13 +550,11 @@ void Load_Control_State_Machine(int object_index)
|
||||
case SHED_INACTIVE:
|
||||
default:
|
||||
if (Start_Time_Property_Written[object_index]) {
|
||||
printf("Load Control[%d]:Start Time written\n",object_index);
|
||||
printf("Load Control[%d]:Start Time written\n", object_index);
|
||||
Start_Time_Property_Written[object_index] = false;
|
||||
Shed_Level_Copy(
|
||||
&Expected_Shed_Level[object_index],
|
||||
Shed_Level_Copy(&Expected_Shed_Level[object_index],
|
||||
&Requested_Shed_Level[object_index]);
|
||||
Shed_Level_Default_Set(
|
||||
&Actual_Shed_Level[object_index],
|
||||
Shed_Level_Default_Set(&Actual_Shed_Level[object_index],
|
||||
Requested_Shed_Level[object_index].type);
|
||||
Load_Control_State[object_index] = SHED_REQUEST_PENDING;
|
||||
}
|
||||
@@ -829,19 +834,22 @@ bool Load_Control_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
|
||||
&value, PROP_REQUESTED_SHED_LEVEL);
|
||||
if (value.tag == 0) {
|
||||
/* percent - Unsigned */
|
||||
Requested_Shed_Level[object_index].type = BACNET_SHED_TYPE_PERCENT;
|
||||
Requested_Shed_Level[object_index].type =
|
||||
BACNET_SHED_TYPE_PERCENT;
|
||||
Requested_Shed_Level[object_index].value.percent =
|
||||
value.type.Unsigned_Int;
|
||||
status = true;
|
||||
} else if (value.tag == 1) {
|
||||
/* level - Unsigned */
|
||||
Requested_Shed_Level[object_index].type = BACNET_SHED_TYPE_LEVEL;
|
||||
Requested_Shed_Level[object_index].type =
|
||||
BACNET_SHED_TYPE_LEVEL;
|
||||
Requested_Shed_Level[object_index].value.level =
|
||||
value.type.Unsigned_Int;
|
||||
status = true;
|
||||
} else if (value.tag == 2) {
|
||||
/* amount - REAL */
|
||||
Requested_Shed_Level[object_index].type = BACNET_SHED_TYPE_AMOUNT;
|
||||
Requested_Shed_Level[object_index].type =
|
||||
BACNET_SHED_TYPE_AMOUNT;
|
||||
Requested_Shed_Level[object_index].value.amount =
|
||||
value.type.Real;
|
||||
status = true;
|
||||
@@ -966,8 +974,9 @@ void testLoadControlStateMachine(Test * pTest)
|
||||
}
|
||||
}
|
||||
|
||||
/**/
|
||||
status = Load_Control_Write_Property(&wp_data, &error_class, &error_code);
|
||||
/**/
|
||||
status =
|
||||
Load_Control_Write_Property(&wp_data, &error_class, &error_code);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#include <time.h> /* for time */
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h> /* toupper */
|
||||
#include <ctype.h> /* toupper */
|
||||
#include "bactext.h"
|
||||
#include "iam.h"
|
||||
#include "arf.h"
|
||||
@@ -62,7 +62,8 @@ static BACNET_PROPERTY_ID Target_Object_Property = PROP_ACKED_TRANSITIONS;
|
||||
/* array index value or BACNET_ARRAY_ALL */
|
||||
static int32_t Target_Object_Property_Index = BACNET_ARRAY_ALL;
|
||||
#define MAX_PROPERTY_VALUES 16
|
||||
static BACNET_APPLICATION_DATA_VALUE Target_Object_Property_Value[MAX_PROPERTY_VALUES];
|
||||
static BACNET_APPLICATION_DATA_VALUE
|
||||
Target_Object_Property_Value[MAX_PROPERTY_VALUES];
|
||||
|
||||
/* 0 if not set, 1..16 if set */
|
||||
static uint8_t Target_Object_Property_Priority = 0;
|
||||
@@ -269,7 +270,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
args_remaining = (argc - 7);
|
||||
for (i = 0; i < MAX_PROPERTY_VALUES; i++) {
|
||||
tag_value_arg = 7+(i*2);
|
||||
tag_value_arg = 7 + (i * 2);
|
||||
/* special case for context tagged values */
|
||||
if (toupper(argv[tag_value_arg][0]) == 'C') {
|
||||
context_tag = strtol(&argv[tag_value_arg][1], NULL, 0);
|
||||
@@ -281,10 +282,10 @@ int main(int argc, char *argv[])
|
||||
Target_Object_Property_Value[i].context_specific = false;
|
||||
}
|
||||
property_tag = strtol(argv[tag_value_arg], NULL, 0);
|
||||
value_string = argv[tag_value_arg+1];
|
||||
value_string = argv[tag_value_arg + 1];
|
||||
args_remaining -= 2;
|
||||
/* printf("tag[%d]=%u value[%d]=%s\r\n",
|
||||
i, property_tag, i, value_string); */
|
||||
i, property_tag, i, value_string); */
|
||||
if (property_tag >= MAX_BACNET_APPLICATION_TAG) {
|
||||
fprintf(stderr, "tag=%u - it must be less than %u\r\n",
|
||||
property_tag, MAX_BACNET_APPLICATION_TAG);
|
||||
@@ -299,11 +300,11 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
Target_Object_Property_Value[i].next = NULL;
|
||||
if (i > 0) {
|
||||
Target_Object_Property_Value[i-1].next =
|
||||
Target_Object_Property_Value[i - 1].next =
|
||||
&Target_Object_Property_Value[i];
|
||||
}
|
||||
if (args_remaining <= 0)
|
||||
break;
|
||||
break;
|
||||
}
|
||||
/* setup my info */
|
||||
Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE);
|
||||
@@ -345,12 +346,12 @@ int main(int argc, char *argv[])
|
||||
if (found) {
|
||||
if (invoke_id == 0) {
|
||||
invoke_id =
|
||||
Send_Write_Property_Request(
|
||||
Target_Device_Object_Instance, Target_Object_Type,
|
||||
Target_Object_Instance, Target_Object_Property,
|
||||
&Target_Object_Property_Value[0],
|
||||
Target_Object_Property_Priority,
|
||||
Target_Object_Property_Index);
|
||||
Send_Write_Property_Request
|
||||
(Target_Device_Object_Instance, Target_Object_Type,
|
||||
Target_Object_Instance, Target_Object_Property,
|
||||
&Target_Object_Property_Value[0],
|
||||
Target_Object_Property_Priority,
|
||||
Target_Object_Property_Index);
|
||||
} else if (tsm_invoke_id_free(invoke_id))
|
||||
break;
|
||||
else if (tsm_invoke_id_failed(invoke_id)) {
|
||||
|
||||
@@ -45,19 +45,13 @@ void INT0_Interrupt(void);
|
||||
void InterruptVectorHigh(void)
|
||||
{
|
||||
/* jump to interrupt routine */
|
||||
_asm goto InterruptHandlerHigh
|
||||
_endasm
|
||||
}
|
||||
|
||||
_asm goto InterruptHandlerHigh _endasm}
|
||||
#pragma code
|
||||
#pragma code InterruptVectorLow = 0x18
|
||||
void InterruptVectorLow(void)
|
||||
{
|
||||
/* jump to interrupt routine */
|
||||
_asm goto InterruptHandlerLow
|
||||
_endasm
|
||||
}
|
||||
|
||||
_asm goto InterruptHandlerLow _endasm}
|
||||
#pragma code
|
||||
#pragma interrupt InterruptHandlerHigh
|
||||
void InterruptHandlerHigh(void)
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
/* define this to enable ICD */
|
||||
/* #define USE_ICD */
|
||||
|
||||
// Configuration Bits
|
||||
/* Configuration Bits */
|
||||
#pragma config OSC = HS, OSCS = OFF
|
||||
#pragma config PWRT = ON
|
||||
#pragma config BOR = ON, BORV = 27
|
||||
@@ -82,12 +82,12 @@
|
||||
#pragma config EBTRB = OFF
|
||||
|
||||
#ifdef USE_ICD
|
||||
#pragma config WDT = OFF, WDTPS = 128
|
||||
#pragma config DEBUG = ON
|
||||
#pragma config WDT = OFF, WDTPS = 128
|
||||
#pragma config DEBUG = ON
|
||||
#else
|
||||
#pragma config WDT = ON, WDTPS = 128
|
||||
#pragma config DEBUG = OFF
|
||||
#endif /* USE_ICD */
|
||||
#pragma config WDT = ON, WDTPS = 128
|
||||
#pragma config DEBUG = OFF
|
||||
#endif /* USE_ICD */
|
||||
|
||||
volatile uint8_t Milliseconds = 0;
|
||||
volatile uint8_t Zero_Cross_Timeout = 0;
|
||||
@@ -103,14 +103,15 @@ static void BACnet_Service_Handlers_Init(void)
|
||||
handler_read_property);
|
||||
apdu_set_confirmed_handler(SERVICE_CONFIRMED_REINITIALIZE_DEVICE,
|
||||
handler_reinitialize_device);
|
||||
#if 0
|
||||
#if 0
|
||||
apdu_set_confirmed_handler(SERVICE_CONFIRMED_WRITE_PROPERTY,
|
||||
handler_write_property);
|
||||
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION,
|
||||
apdu_set_unconfirmed_handler
|
||||
(SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION,
|
||||
handler_timesync_utc);
|
||||
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION,
|
||||
handler_timesync);
|
||||
#endif
|
||||
#endif
|
||||
/* handle communication so we can shutup when asked */
|
||||
apdu_set_confirmed_handler
|
||||
(SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
|
||||
@@ -122,8 +123,7 @@ void Reinitialize(void)
|
||||
uint8_t i;
|
||||
char name = 0;
|
||||
|
||||
_asm reset _endasm
|
||||
return;
|
||||
_asm reset _endasm return;
|
||||
}
|
||||
|
||||
void Global_Int(enum INT_STATE state)
|
||||
@@ -151,100 +151,100 @@ void Global_Int(enum INT_STATE state)
|
||||
|
||||
void Hardware_Initialize(void)
|
||||
{
|
||||
/* PORTA.0 Input - Photocell PORTA.1 Output - LED Row6 PORTA.2 Output
|
||||
* - LED Row5 PORTA.3 Output - LED Row4 PORTA.4 Input - Square Wave
|
||||
* input from RTC PORTA.5 Output - LCD RW */
|
||||
TRISA = 0xD1;
|
||||
/* PORTA.0 Input - Photocell PORTA.1 Output - LED Row6 PORTA.2 Output
|
||||
* - LED Row5 PORTA.3 Output - LED Row4 PORTA.4 Input - Square Wave
|
||||
* input from RTC PORTA.5 Output - LCD RW */
|
||||
TRISA = 0xD1;
|
||||
|
||||
/* PORTB.0 Input - Zero Cross PORTB.1 Input - USB RXF# PORTB.2 Input
|
||||
* USB TXE# PORTB.3 Output - Keypad Row Enable (74HC373 Output Control)
|
||||
* PORTB.4 Output Keypad Row Gate (74HC373 Gate) PORTB.5 Output Switch
|
||||
* Input Latch & Keypad Column Gate (74HC373 Gate) PORTB.6 Input - ICD
|
||||
* connection PORTB.7 Input - ICD connection */
|
||||
TRISB = 0xC7;
|
||||
/* PORTB.0 Input - Zero Cross PORTB.1 Input - USB RXF# PORTB.2 Input
|
||||
* USB TXE# PORTB.3 Output - Keypad Row Enable (74HC373 Output Control)
|
||||
* PORTB.4 Output Keypad Row Gate (74HC373 Gate) PORTB.5 Output Switch
|
||||
* Input Latch & Keypad Column Gate (74HC373 Gate) PORTB.6 Input - ICD
|
||||
* connection PORTB.7 Input - ICD connection */
|
||||
TRISB = 0xC7;
|
||||
|
||||
/* PORTC.0 Output - Pilot Latch PORTC.1 Output - Pilot Output Enable
|
||||
* (low) PORTC.2 I/O - Piezo PORTC.3 Input - I2C clock PORTC.4 Input
|
||||
* I2C data PORTC.5 Output RS232 enable (low) PORTC.6 Output - RS232 Tx
|
||||
* PORTC.7 Input - RS232 Rx */
|
||||
TRISC = 0x9C;
|
||||
/* PORTC.0 Output - Pilot Latch PORTC.1 Output - Pilot Output Enable
|
||||
* (low) PORTC.2 I/O - Piezo PORTC.3 Input - I2C clock PORTC.4 Input
|
||||
* I2C data PORTC.5 Output RS232 enable (low) PORTC.6 Output - RS232 Tx
|
||||
* PORTC.7 Input - RS232 Rx */
|
||||
TRISC = 0x9C;
|
||||
|
||||
/* PORTD.0 I/O - Data bus PORTD.1 I/O - Data bus PORTD.2 I/O - Data
|
||||
* bus PORTD.3 I/O - Data bus PORTD.4 I/O - Data bus PORTD.5 I/O - Data
|
||||
* bus PORTD.6 I/O - Data bus PORTD.7 I/O - Data bus */
|
||||
TRISD = 0xFF;
|
||||
/* PORTD.0 I/O - Data bus PORTD.1 I/O - Data bus PORTD.2 I/O - Data
|
||||
* bus PORTD.3 I/O - Data bus PORTD.4 I/O - Data bus PORTD.5 I/O - Data
|
||||
* bus PORTD.6 I/O - Data bus PORTD.7 I/O - Data bus */
|
||||
TRISD = 0xFF;
|
||||
|
||||
/* PORTE.0 Input - USB RD PORTE.1 Input - USB WR PORTE.2 Output - LCD
|
||||
* RS PORTE.3 Output - 485 transmit enable PORTE.4 Output - Relay data
|
||||
* latch PORTE.5 Output Switch Input Clock PORTE.6 Output - Switch
|
||||
* Input High/Low PORTE.7 Input Switch Input Data */
|
||||
TRISE = 0x83;
|
||||
/* PORTE.0 Input - USB RD PORTE.1 Input - USB WR PORTE.2 Output - LCD
|
||||
* RS PORTE.3 Output - 485 transmit enable PORTE.4 Output - Relay data
|
||||
* latch PORTE.5 Output Switch Input Clock PORTE.6 Output - Switch
|
||||
* Input High/Low PORTE.7 Input Switch Input Data */
|
||||
TRISE = 0x83;
|
||||
|
||||
/* PORTF.0 Output - LED Row2 PORTF.1 Output - LED Row1 PORTF.2 Output
|
||||
* - LED Col5 PORTF.3 Output - LED Col4 PORTF.4 Output - LED Col3
|
||||
* PORTF.5 Output - LED Col2 PORTF.6 Output - LED Col1 PORTF.7 Output
|
||||
* LED Col0 */
|
||||
TRISF = 0x00;
|
||||
/* PORTF.0 Output - LED Row2 PORTF.1 Output - LED Row1 PORTF.2 Output
|
||||
* - LED Col5 PORTF.3 Output - LED Col4 PORTF.4 Output - LED Col3
|
||||
* PORTF.5 Output - LED Col2 PORTF.6 Output - LED Col1 PORTF.7 Output
|
||||
* LED Col0 */
|
||||
TRISF = 0x00;
|
||||
|
||||
/* PORTG.0 Output - 485 receive enable PORTG.1 Output - 485 Tx PORTG.2
|
||||
* Input 485 Rx PORTG.3 Output - LCD E PORTG.4 Output - LED Row0 */
|
||||
TRISG = 0xE6;
|
||||
/* PORTG.0 Output - 485 receive enable PORTG.1 Output - 485 Tx PORTG.2
|
||||
* Input 485 Rx PORTG.3 Output - LCD E PORTG.4 Output - LED Row0 */
|
||||
TRISG = 0xE6;
|
||||
|
||||
/* The initial state of the keypad enables and latches */
|
||||
KEYPAD_ROW_ENABLE = 1;
|
||||
KEYPAD_ROW_LATCH = 0;
|
||||
KEYPAD_COL_LATCH = 1;
|
||||
/* The initial state of the keypad enables and latches */
|
||||
KEYPAD_ROW_ENABLE = 1;
|
||||
KEYPAD_ROW_LATCH = 0;
|
||||
KEYPAD_COL_LATCH = 1;
|
||||
|
||||
RELAY_LATCH = 0;
|
||||
RELAY_LATCH = 0;
|
||||
|
||||
/* Setup to read the switch inputs */
|
||||
SWITCH_COM = 1;
|
||||
/* Setup to read the switch inputs */
|
||||
SWITCH_COM = 1;
|
||||
|
||||
/* Enable the RS232 transmitter */
|
||||
RS232_ENABLE = 0;
|
||||
/* Enable the RS232 transmitter */
|
||||
RS232_ENABLE = 0;
|
||||
|
||||
/* Turn all leds off. These are the hardware pins */
|
||||
LED_ROW1 = 1;
|
||||
LED_ROW2 = 1;
|
||||
LED_ROW3 = 1;
|
||||
LED_ROW4 = 1;
|
||||
LED_ROW5 = 1;
|
||||
LED_ROW6 = 1;
|
||||
LEDPORT = 0x03;
|
||||
/* Turn all leds off. These are the hardware pins */
|
||||
LED_ROW1 = 1;
|
||||
LED_ROW2 = 1;
|
||||
LED_ROW3 = 1;
|
||||
LED_ROW4 = 1;
|
||||
LED_ROW5 = 1;
|
||||
LED_ROW6 = 1;
|
||||
LEDPORT = 0x03;
|
||||
|
||||
/* The initial values for the signals to the LCD */
|
||||
LCD_E = 1;
|
||||
LCD_RW = 1;
|
||||
LCD_RS = 1;
|
||||
/* The initial values for the signals to the LCD */
|
||||
LCD_E = 1;
|
||||
LCD_RW = 1;
|
||||
LCD_RS = 1;
|
||||
|
||||
/* The following gives us a PWM frequency of 1.990KHz with a 50% duty
|
||||
* cycle It also serves to multiplex the LEDs. */
|
||||
PIEZO_OFF();
|
||||
CCPR1L = 0x4E;
|
||||
CCP1CON = 0x2F;
|
||||
setup_timer2(6, 156, 2);
|
||||
PIE1bits.TMR2IE = 1;
|
||||
/* The following gives us a PWM frequency of 1.990KHz with a 50% duty
|
||||
* cycle It also serves to multiplex the LEDs. */
|
||||
PIEZO_OFF();
|
||||
CCPR1L = 0x4E;
|
||||
CCP1CON = 0x2F;
|
||||
setup_timer2(6, 156, 2);
|
||||
PIE1bits.TMR2IE = 1;
|
||||
|
||||
/* We will use Timer4 as our system tick timer. Our system tick is set
|
||||
* to 1ms. Hold off on enabling the int. */
|
||||
setup_timer4(5, 250, 5);
|
||||
/* We will use Timer4 as our system tick timer. Our system tick is set
|
||||
* to 1ms. Hold off on enabling the int. */
|
||||
setup_timer4(5, 250, 5);
|
||||
|
||||
/* Setup our interrupt priorities */
|
||||
RCONbits.IPEN = 1;
|
||||
IPR1 = 0;
|
||||
IPR2 = 0;
|
||||
IPR3 = 0;
|
||||
/* Setup our interrupt priorities */
|
||||
RCONbits.IPEN = 1;
|
||||
IPR1 = 0;
|
||||
IPR2 = 0;
|
||||
IPR3 = 0;
|
||||
|
||||
/* Setup TMR0 to be high priority */
|
||||
INTCON2 = 0xFC;
|
||||
INTCON3 = 0;
|
||||
/* Setup TMR0 to be high priority */
|
||||
INTCON2 = 0xFC;
|
||||
INTCON3 = 0;
|
||||
|
||||
/* USART 1 high priority */
|
||||
IPR1bits.RC1IP = 1;
|
||||
IPR1bits.TX1IP = 1;
|
||||
/* USART 1 high priority */
|
||||
IPR1bits.RC1IP = 1;
|
||||
IPR1bits.TX1IP = 1;
|
||||
|
||||
/* Finally enable our ints */
|
||||
Global_Int(INT_ENABLED);
|
||||
/* Finally enable our ints */
|
||||
Global_Int(INT_ENABLED);
|
||||
}
|
||||
|
||||
void Initialize_Variables(void)
|
||||
|
||||
@@ -88,13 +88,13 @@ void RS485_Send_Frame(volatile struct mstp_port_struct_t *mstp_port, /* port
|
||||
|
||||
RS485_Comstat.TxHead = 0;
|
||||
memcpy((void *) &RS485_Tx_Buffer[0], (void *) buffer, nbytes);
|
||||
#if 0
|
||||
#if 0
|
||||
for (i = 0; i < nbytes; i++) {
|
||||
/* put the data into the buffer */
|
||||
RS485_Tx_Buffer[i] = *buffer;
|
||||
buffer++;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
RS485_Comstat.Tx_Bytes = nbytes;
|
||||
/* disable the receiver */
|
||||
PIE3bits.RC2IE = 0;
|
||||
@@ -201,7 +201,7 @@ void RS485_Interrupt_Tx(void)
|
||||
RS485_TX_ENABLE = 0;
|
||||
RS485_RX_DISABLE = 0;
|
||||
/* FIXME: might not be necessary
|
||||
*/
|
||||
*/
|
||||
PIE3bits.RC2IE = 1;
|
||||
RCSTA2bits.CREN = 1;
|
||||
}
|
||||
|
||||
@@ -114,6 +114,11 @@ make -f indtext.mak
|
||||
./indtext >> test.log
|
||||
make -f indtext.mak clean
|
||||
|
||||
make -f demo/object/lc.mak clean
|
||||
make -f demo/object/lc.mak
|
||||
./loadcontrol >> test.log
|
||||
make -f demo/object/lc.mak clean
|
||||
|
||||
make -f demo/object/lsp.mak clean
|
||||
make -f demo/object/lsp.mak
|
||||
./lsp >> test.log
|
||||
|
||||
Reference in New Issue
Block a user