Enhanced the ATmega168 demo project to include WriteProperty service to the Analog Value and Device objects.
This commit is contained in:
@@ -114,6 +114,10 @@ extern "C" {
|
||||
bool characterstring_copy(
|
||||
BACNET_CHARACTER_STRING * dest,
|
||||
BACNET_CHARACTER_STRING * src);
|
||||
bool characterstring_ansi_copy(
|
||||
char * dest,
|
||||
size_t dest_max_len,
|
||||
BACNET_CHARACTER_STRING * src);
|
||||
/* returns true if the strings are the same length, encoding, value */
|
||||
bool characterstring_same(
|
||||
BACNET_CHARACTER_STRING * dest,
|
||||
|
||||
@@ -98,6 +98,10 @@ BFLAGS += -DBIG_ENDIAN=0
|
||||
BFLAGS += -DMAX_TSM_TRANSACTIONS=0
|
||||
#BFLAGS += -DCRC_USE_TABLE
|
||||
BFLAGS += -DBACAPP_REAL
|
||||
BFLAGS += -DBACAPP_OBJECT_ID
|
||||
BFLAGS += -DBACAPP_UNSIGNED
|
||||
BFLAGS += -DBACAPP_CHARACTER_STRING
|
||||
BFLAGS += -DWRITE_PROPERTY
|
||||
BFLAGS += -DMAX_ANALOG_VALUES=10
|
||||
CFLAGS = $(COMMON)
|
||||
# dead code removal
|
||||
|
||||
@@ -49,7 +49,7 @@ bool apdu_service_supported(
|
||||
if (service_supported == SERVICE_SUPPORTED_READ_PROPERTY) {
|
||||
status = true;
|
||||
}
|
||||
#if 0
|
||||
#ifdef WRITE_PROPERTY
|
||||
if (service_supported == SERVICE_SUPPORTED_WRITE_PROPERTY) {
|
||||
status = true;
|
||||
}
|
||||
@@ -109,7 +109,7 @@ void apdu_handler(
|
||||
handler_read_property(service_request, service_request_len,
|
||||
src, &service_data);
|
||||
}
|
||||
#if 0
|
||||
#ifdef WRITE_PROPERTY
|
||||
else if (service_choice == SERVICE_CONFIRMED_WRITE_PROPERTY) {
|
||||
handler_write_property(service_request,
|
||||
service_request_len, src, &service_data);
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "hardware.h"
|
||||
#include "bacdef.h"
|
||||
#include "bacdcode.h"
|
||||
#include "bacenum.h"
|
||||
@@ -182,6 +183,11 @@ bool Analog_Value_Write_Property(
|
||||
object_index =
|
||||
Analog_Value_Instance_To_Index(wp_data->object_instance);
|
||||
AV_Present_Value[object_index] = value.type.Real;
|
||||
if ((AV_Present_Value[0] < 1.0) && (AV_Present_Value[0] > -1.0)) {
|
||||
LED_GREEN_OFF();
|
||||
} else {
|
||||
LED_GREEN_ON();
|
||||
}
|
||||
status = true;
|
||||
} else {
|
||||
*error_class = ERROR_CLASS_PROPERTY;
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -358,12 +358,10 @@ int Device_Encode_Property_APDU(
|
||||
apdu_len =
|
||||
encode_application_unsigned(&apdu[0], dlmstp_max_master());
|
||||
break;
|
||||
#if 0
|
||||
case 9600:
|
||||
apdu_len =
|
||||
encode_application_unsigned(&apdu[0], RS485_Get_Baud_Rate());
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
*error_class = ERROR_CLASS_PROPERTY;
|
||||
*error_code = ERROR_CODE_UNKNOWN_PROPERTY;
|
||||
@@ -374,7 +372,6 @@ int Device_Encode_Property_APDU(
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
#if 0
|
||||
bool Device_Write_Property(
|
||||
BACNET_WRITE_PROPERTY_DATA * wp_data,
|
||||
BACNET_ERROR_CLASS * error_class,
|
||||
@@ -444,19 +441,15 @@ bool Device_Write_Property(
|
||||
case PROP_OBJECT_NAME:
|
||||
if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) {
|
||||
uint8_t encoding;
|
||||
size_t len;
|
||||
|
||||
encoding =
|
||||
characterstring_encoding(&value.type.Character_String);
|
||||
len = characterstring_length(&value.type.Character_String);
|
||||
if (encoding == CHARACTER_ANSI_X34) {
|
||||
if (len <= 20) {
|
||||
/* FIXME: set the name */
|
||||
/* Display_Set_Name(
|
||||
characterstring_value(&value.type.Character_String)); */
|
||||
/* FIXME: All the object names in a device must be unique.
|
||||
Disallow setting the Device Object Name to any objects in
|
||||
the device. */
|
||||
if (characterstring_ansi_copy(
|
||||
&Object_Name[0],
|
||||
sizeof(Object_Name),
|
||||
&value.type.Character_String)) {
|
||||
status = true;
|
||||
} else {
|
||||
*error_class = ERROR_CLASS_PROPERTY;
|
||||
*error_code = ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY;
|
||||
@@ -492,4 +485,3 @@ bool Device_Write_Property(
|
||||
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -82,7 +82,6 @@ void handler_write_property(
|
||||
true);
|
||||
} else {
|
||||
switch (wp_data.object_type) {
|
||||
#if 0
|
||||
case OBJECT_DEVICE:
|
||||
if (Device_Write_Property(&wp_data, &error_class, &error_code)) {
|
||||
len =
|
||||
@@ -97,6 +96,7 @@ void handler_write_property(
|
||||
error_code);
|
||||
}
|
||||
break;
|
||||
#if 0
|
||||
case OBJECT_ANALOG_INPUT:
|
||||
case OBJECT_BINARY_INPUT:
|
||||
error_class = ERROR_CLASS_PROPERTY;
|
||||
|
||||
@@ -40,4 +40,12 @@
|
||||
#include "iar2gcc.h"
|
||||
#include "avr035.h"
|
||||
|
||||
#define LED_NPDU_INIT() BIT_SET(DDRD, DDD5)
|
||||
#define LED_NPDU_ON() BIT_CLEAR(PORTD, PD5)
|
||||
#define LED_NPDU_OFF() BIT_SET(PORTD, PD5)
|
||||
|
||||
#define LED_GREEN_INIT() BIT_SET(DDRD, DDD4)
|
||||
#define LED_GREEN_ON() BIT_CLEAR(PORTD, PD4)
|
||||
#define LED_GREEN_OFF() BIT_SET(PORTD, PD4)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -40,14 +40,6 @@ const char *BACnet_Version = "1.0";
|
||||
/* For porting to IAR, see:
|
||||
http://www.avrfreaks.net/wiki/index.php/Documentation:AVR_GCC/IarToAvrgcc*/
|
||||
|
||||
#define LED_NPDU_INIT() BIT_SET(DDRD, DDD5)
|
||||
#define LED_NPDU_ON() BIT_CLEAR(PORTD, PD5)
|
||||
#define LED_NPDU_OFF() BIT_SET(PORTD, PD5)
|
||||
|
||||
#define LED_GREEN_INIT() BIT_SET(DDRD, DDD4)
|
||||
#define LED_GREEN_ON() BIT_CLEAR(PORTD, PD4)
|
||||
#define LED_GREEN_OFF() BIT_SET(PORTD, PD4)
|
||||
|
||||
/* dummy function */
|
||||
bool dcc_communication_enabled(
|
||||
void)
|
||||
@@ -98,9 +90,9 @@ static void init(
|
||||
/* default: off, output */
|
||||
LED_NPDU_OFF();
|
||||
LED_NPDU_INIT();
|
||||
/* Configure Software active LED */
|
||||
/* Configure Software LED */
|
||||
LED_GREEN_INIT();
|
||||
LED_GREEN_ON();
|
||||
LED_GREEN_OFF();
|
||||
|
||||
/* Configure Timer0 for millisecond timer */
|
||||
Timer_Initialize();
|
||||
@@ -142,14 +134,6 @@ static void input_switch_read(
|
||||
}
|
||||
}
|
||||
|
||||
static void Analog_Value_Task(
|
||||
void)
|
||||
{
|
||||
extern float AV_Present_Value[MAX_ANALOG_VALUES];
|
||||
|
||||
AV_Present_Value[0] = 3.14159F;
|
||||
}
|
||||
|
||||
static uint8_t PDUBuffer[MAX_MPDU];
|
||||
int main(
|
||||
void)
|
||||
@@ -167,7 +151,6 @@ int main(
|
||||
for (;;) {
|
||||
input_switch_read();
|
||||
task_milliseconds();
|
||||
Analog_Value_Task();
|
||||
/* other tasks */
|
||||
/* BACnet handling */
|
||||
pdu_len = datalink_receive(&src, &PDUBuffer[0], sizeof(PDUBuffer), 0);
|
||||
|
||||
@@ -246,6 +246,25 @@ bool characterstring_copy(
|
||||
characterstring_value(src), characterstring_length(src));
|
||||
}
|
||||
|
||||
bool characterstring_ansi_copy(
|
||||
char * dest,
|
||||
size_t dest_max_len,
|
||||
BACNET_CHARACTER_STRING * src)
|
||||
{
|
||||
size_t i; /* counter */
|
||||
|
||||
if (dest && src &&
|
||||
(src->encoding == CHARACTER_ANSI_X34) &&
|
||||
(src->length < dest_max_len)) {
|
||||
for (i = 0; i < src->length; i++) {
|
||||
dest[i] = src->value[i];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* returns true if the character encoding and string contents are the same */
|
||||
bool characterstring_same(
|
||||
BACNET_CHARACTER_STRING * dest,
|
||||
|
||||
Reference in New Issue
Block a user