From 1f9c13d37ba02d0fa93c20d03f9035aede27e68f Mon Sep 17 00:00:00 2001 From: skarg Date: Thu, 18 Feb 2010 03:06:03 +0000 Subject: [PATCH] Got rid of the handler-set functions for RP,RPM,WP,RD. Just referencing the device object functions directly. --- bacnet-stack/demo/handler/h_rd.c | 14 +- bacnet-stack/demo/handler/h_rp.c | 63 ++++----- bacnet-stack/demo/handler/h_rpm.c | 40 ++---- bacnet-stack/demo/object/device.c | 144 +++++++++++---------- bacnet-stack/demo/object/trendlog.c | 4 +- bacnet-stack/include/device.h | 11 +- bacnet-stack/include/handlers.h | 12 -- bacnet-stack/ports/at91sam7s/device.c | 87 +++++-------- bacnet-stack/ports/bdk-atxx4-mstp/Makefile | 8 +- bacnet-stack/ports/bdk-atxx4-mstp/device.c | 50 ++++--- 10 files changed, 196 insertions(+), 237 deletions(-) diff --git a/bacnet-stack/demo/handler/h_rd.c b/bacnet-stack/demo/handler/h_rd.c index f83c0f1f..f6974053 100644 --- a/bacnet-stack/demo/handler/h_rd.c +++ b/bacnet-stack/demo/handler/h_rd.c @@ -37,16 +37,11 @@ #include "abort.h" #include "reject.h" #include "rd.h" +/* custom handling in device object */ +#include "device.h" /** @file h_rd.c Handles Reinitialize Device requests. */ -static reinitialize_device_function Reinitialize_Device_Function; -void handler_reinitialize_device_function_set( - reinitialize_device_function pFunction) -{ - Reinitialize_Device_Function = pFunction; -} - void handler_reinitialize_device( uint8_t * service_request, uint16_t service_len, @@ -114,8 +109,7 @@ void handler_reinitialize_device( "ReinitializeDevice: Sending Reject - undefined enumeration\n"); #endif } else { - if (Reinitialize_Device_Function && - Reinitialize_Device_Function(&rd_data)) { + if (Device_Reinitialize(&rd_data)) { len = encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, @@ -130,7 +124,7 @@ void handler_reinitialize_device( rd_data.error_class, rd_data.error_code); #if PRINT_ENABLED fprintf(stderr, - "ReinitializeDevice: Sending Error - password failure.\n"); + "ReinitializeDevice: Sending Error.\n"); #endif } } diff --git a/bacnet-stack/demo/handler/h_rp.c b/bacnet-stack/demo/handler/h_rp.c index 097a64ee..1671ae9f 100644 --- a/bacnet-stack/demo/handler/h_rp.c +++ b/bacnet-stack/demo/handler/h_rp.c @@ -37,18 +37,11 @@ #include "npdu.h" #include "abort.h" #include "rp.h" +/* device object has custom handler for all objects */ +#include "device.h" /** @file h_rp.c Handles Read Property requests. */ -/* function that handles the reading of properties from objects */ -static read_property_function Read_Property_Function; - -void handler_read_property_function_set( - read_property_function pFunction) -{ - Read_Property_Function = pFunction; -} - void handler_read_property( uint8_t * service_request, uint16_t service_len, @@ -100,37 +93,35 @@ void handler_read_property( } /* assume that there is an error */ error = true; - if (Read_Property_Function) { - apdu_len = rp_ack_encode_apdu_init( - &Handler_Transmit_Buffer[npdu_len], - service_data->invoke_id, - &rpdata); - /* configure our storage */ - rpdata.application_data = &Handler_Transmit_Buffer[npdu_len+apdu_len]; - rpdata.application_data_len = - sizeof(Handler_Transmit_Buffer) - (npdu_len + apdu_len); - len = Read_Property_Function(&rpdata); - if (len >= 0) { - apdu_len += len; - len = rp_ack_encode_apdu_object_property_end( - &Handler_Transmit_Buffer[npdu_len+apdu_len]); - apdu_len += len; - if (apdu_len > service_data->max_resp) { - /* too big for the sender - send an abort */ - apdu_len = - abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len], - service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, - true); + apdu_len = rp_ack_encode_apdu_init( + &Handler_Transmit_Buffer[npdu_len], + service_data->invoke_id, + &rpdata); + /* configure our storage */ + rpdata.application_data = &Handler_Transmit_Buffer[npdu_len+apdu_len]; + rpdata.application_data_len = + sizeof(Handler_Transmit_Buffer) - (npdu_len + apdu_len); + len = Device_Read_Property(&rpdata); + if (len >= 0) { + apdu_len += len; + len = rp_ack_encode_apdu_object_property_end( + &Handler_Transmit_Buffer[npdu_len+apdu_len]); + apdu_len += len; + if (apdu_len > service_data->max_resp) { + /* too big for the sender - send an abort */ + apdu_len = + abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len], + service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, + true); #if PRINT_ENABLED - fprintf(stderr, "RP: Message too large. Sending Abort!\n"); + fprintf(stderr, "RP: Message too large. Sending Abort!\n"); #endif - goto RP_ABORT; - } else { + goto RP_ABORT; + } else { #if PRINT_ENABLED - fprintf(stderr, "RP: Sending Ack!\n"); + fprintf(stderr, "RP: Sending Ack!\n"); #endif - error = false; - } + error = false; } } if (error) { diff --git a/bacnet-stack/demo/handler/h_rpm.c b/bacnet-stack/demo/handler/h_rpm.c index f0887007..f2261502 100644 --- a/bacnet-stack/demo/handler/h_rpm.c +++ b/bacnet-stack/demo/handler/h_rpm.c @@ -38,25 +38,11 @@ #include "abort.h" #include "rpm.h" #include "handlers.h" +/* device object has custom handler for all objects */ +#include "device.h" /** @file h_rpm.c Handles Read Property Multiple requests. */ -/* function that handles the reading of properties from objects */ -static read_property_function Read_Property_Function; -static rpm_object_property_lists_function RPM_Property_List; - -void handler_rpm_function_set( - read_property_function pFunction) -{ - Read_Property_Function = pFunction; -} - -void handler_rpm_list_set( - rpm_object_property_lists_function pFunction) -{ - RPM_Property_List = pFunction; -} - static uint8_t Temp_Buf[MAX_APDU] = { 0 }; static BACNET_PROPERTY_ID RPM_Object_Property( @@ -137,17 +123,15 @@ static int RPM_Encode_Property( } apdu_len += len; len = 0; - if (Read_Property_Function) { - rpdata.error_class = ERROR_CLASS_OBJECT; - rpdata.error_code = ERROR_CODE_UNKNOWN_OBJECT; - rpdata.object_type = object_type; - rpdata.object_instance = object_instance; - rpdata.object_property = object_property; - rpdata.array_index = array_index; - rpdata.application_data = &Temp_Buf[0]; - rpdata.application_data_len = sizeof(Temp_Buf); - len = Read_Property_Function(&rpdata); - } + rpdata.error_class = ERROR_CLASS_OBJECT; + rpdata.error_code = ERROR_CODE_UNKNOWN_OBJECT; + rpdata.object_type = object_type; + rpdata.object_instance = object_instance; + rpdata.object_property = object_property; + rpdata.array_index = array_index; + rpdata.application_data = &Temp_Buf[0]; + rpdata.application_data_len = sizeof(Temp_Buf); + len = Device_Read_Property(&rpdata); if (len < 0) { /* error was returned - encode that for the response */ len = @@ -311,7 +295,7 @@ void handler_read_property_multiple( BACNET_PROPERTY_ID special_object_property; special_object_property = object_property; - RPM_Property_List(object_type, &property_list); + Device_Objects_Property_List(object_type, &property_list); property_count = RPM_Object_Property_Count(&property_list, special_object_property); diff --git a/bacnet-stack/demo/object/device.c b/bacnet-stack/demo/object/device.c index e17df734..b39e1033 100644 --- a/bacnet-stack/demo/object/device.c +++ b/bacnet-stack/demo/object/device.c @@ -65,6 +65,13 @@ long int timezone; #endif +/* forward prototypes */ +static int Device_Read_Property_Local( + BACNET_READ_PROPERTY_DATA *rpdata); +static bool Device_Write_Property_Local( + BACNET_WRITE_PROPERTY_DATA * wp_data); + +/* all object helper functions */ static struct object_functions { BACNET_OBJECT_TYPE Object_Type; object_init_function Object_Init; @@ -84,8 +91,8 @@ static struct object_functions { Device_Index_To_Instance, Device_Valid_Object_Instance_Number, Device_Name, - Device_Read_Property, - Device_Write_Property, + Device_Read_Property_Local, + Device_Write_Property_Local, Device_Property_Lists, DeviceGetRRInfo}, {OBJECT_ANALOG_INPUT, @@ -243,67 +250,6 @@ rr_info_function Device_Objects_RR_Info( return(pObject != NULL ? pObject->Object_RR_Info : NULL); } -/* Encodes the property APDU and returns the length, - or sets the error, and returns -1 */ -int Device_Objects_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata) -{ - int apdu_len = -1; - struct object_functions *pObject = NULL; - - /* initialize the default return values */ - rpdata->error_class = ERROR_CLASS_OBJECT; - rpdata->error_code = ERROR_CODE_UNKNOWN_OBJECT; - pObject = Device_Objects_Find_Functions(rpdata->object_type); - if (pObject != NULL) { - if (pObject->Object_Valid_Instance && - pObject->Object_Valid_Instance(rpdata->object_instance)) { - if (pObject->Object_Read_Property) { - apdu_len = pObject->Object_Read_Property(rpdata); - } - } else { - rpdata->error_class = ERROR_CLASS_OBJECT; - rpdata->error_code = ERROR_CODE_UNKNOWN_OBJECT; - } - } else { - rpdata->error_class = ERROR_CLASS_OBJECT; - rpdata->error_code = ERROR_CODE_UNSUPPORTED_OBJECT_TYPE; - } - - return apdu_len; -} - -bool Device_Objects_Write_Property( - BACNET_WRITE_PROPERTY_DATA * wp_data) -{ - int apdu_len = -1; - struct object_functions *pObject = NULL; - - /* initialize the default return values */ - wp_data->error_class = ERROR_CLASS_OBJECT; - wp_data->error_code = ERROR_CODE_UNKNOWN_OBJECT; - pObject = Device_Objects_Find_Functions(wp_data->object_type); - if (pObject != NULL) { - if (pObject->Object_Valid_Instance && - pObject->Object_Valid_Instance(wp_data->object_instance)) { - if (pObject->Object_Write_Property) { - apdu_len = pObject->Object_Write_Property(wp_data); - } else { - wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; - } - } else { - wp_data->error_class = ERROR_CLASS_OBJECT; - wp_data->error_code = ERROR_CODE_UNKNOWN_OBJECT; - } - } else { - wp_data->error_class = ERROR_CLASS_OBJECT; - wp_data->error_code = ERROR_CODE_UNSUPPORTED_OBJECT_TYPE; - } - - return apdu_len; -} - static unsigned property_list_count( const int *pList) { @@ -320,7 +266,7 @@ static unsigned property_list_count( } /* for a given object type, returns the special property list */ -static void Device_Objects_Property_List( +void Device_Objects_Property_List( BACNET_OBJECT_TYPE object_type, struct special_property_list_t *pPropertyList) { @@ -977,7 +923,7 @@ int tm_isdst Daylight Savings flag. /* return the length of the apdu encoded or -1 for error or -2 for abort message */ -int Device_Read_Property( +static int Device_Read_Property_Local( BACNET_READ_PROPERTY_DATA *rpdata) { int apdu_len = 0; /* return value */ @@ -1217,8 +1163,38 @@ int Device_Read_Property( return apdu_len; } +/* Encodes the property APDU and returns the length, + or sets the error, and returns -1 */ +int Device_Read_Property( + BACNET_READ_PROPERTY_DATA *rpdata) +{ + int apdu_len = -1; + struct object_functions *pObject = NULL; + + /* initialize the default return values */ + rpdata->error_class = ERROR_CLASS_OBJECT; + rpdata->error_code = ERROR_CODE_UNKNOWN_OBJECT; + pObject = Device_Objects_Find_Functions(rpdata->object_type); + if (pObject != NULL) { + if (pObject->Object_Valid_Instance && + pObject->Object_Valid_Instance(rpdata->object_instance)) { + if (pObject->Object_Read_Property) { + apdu_len = pObject->Object_Read_Property(rpdata); + } + } else { + rpdata->error_class = ERROR_CLASS_OBJECT; + rpdata->error_code = ERROR_CODE_UNKNOWN_OBJECT; + } + } else { + rpdata->error_class = ERROR_CLASS_OBJECT; + rpdata->error_code = ERROR_CODE_UNSUPPORTED_OBJECT_TYPE; + } + + return apdu_len; +} + /* returns true if successful */ -bool Device_Write_Property( +static bool Device_Write_Property_Local( BACNET_WRITE_PROPERTY_DATA * wp_data) { bool status = false; /* return value */ @@ -1383,17 +1359,43 @@ bool Device_Write_Property( return status; } +bool Device_Write_Property( + BACNET_WRITE_PROPERTY_DATA * wp_data) +{ + int apdu_len = -1; + struct object_functions *pObject = NULL; + + /* initialize the default return values */ + wp_data->error_class = ERROR_CLASS_OBJECT; + wp_data->error_code = ERROR_CODE_UNKNOWN_OBJECT; + pObject = Device_Objects_Find_Functions(wp_data->object_type); + if (pObject != NULL) { + if (pObject->Object_Valid_Instance && + pObject->Object_Valid_Instance(wp_data->object_instance)) { + if (pObject->Object_Write_Property) { + apdu_len = pObject->Object_Write_Property(wp_data); + } else { + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; + } + } else { + wp_data->error_class = ERROR_CLASS_OBJECT; + wp_data->error_code = ERROR_CODE_UNKNOWN_OBJECT; + } + } else { + wp_data->error_class = ERROR_CLASS_OBJECT; + wp_data->error_code = ERROR_CODE_UNSUPPORTED_OBJECT_TYPE; + } + + return apdu_len; +} + void Device_Init( void) { struct object_functions *pObject = NULL; - handler_read_property_function_set(Device_Objects_Read_Property); - handler_rpm_function_set(Device_Objects_Read_Property); - handler_rpm_list_set(Device_Objects_Property_List); - handler_write_property_function_set(Device_Objects_Write_Property); handler_rr_object_set(Device_Objects_RR_Info); - handler_reinitialize_device_function_set(Device_Reinitialize); pObject = &Object_Table[0]; while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) { diff --git a/bacnet-stack/demo/object/trendlog.c b/bacnet-stack/demo/object/trendlog.c index fae1575f..82e8e247 100644 --- a/bacnet-stack/demo/object/trendlog.c +++ b/bacnet-stack/demo/object/trendlog.c @@ -1595,7 +1595,7 @@ static int local_read_property( rpdata.object_property = Source->propertyIdentifier; rpdata.array_index = Source->arrayIndex; /* Try to fetch the required property */ - len = Device_Objects_Read_Property(&rpdata); + len = Device_Read_Property(&rpdata); if (len < 0) { *error_class = rpdata.error_class; *error_code = rpdata.error_code; @@ -1607,7 +1607,7 @@ static int local_read_property( rpdata.application_data_len = MAX_APDU; rpdata.object_property = PROP_STATUS_FLAGS; rpdata.array_index = BACNET_ARRAY_ALL; - len = Device_Objects_Read_Property(&rpdata); + len = Device_Read_Property(&rpdata); if (len < 0) { *error_class = rpdata.error_class; *error_code = rpdata.error_code; diff --git a/bacnet-stack/include/device.h b/bacnet-stack/include/device.h index 3e37d4e7..c5febd85 100644 --- a/bacnet-stack/include/device.h +++ b/bacnet-stack/include/device.h @@ -39,7 +39,9 @@ #include "bacdef.h" #include "bacenum.h" #include "wp.h" +#include "rd.h" #include "rp.h" +#include "rpm.h" #include "readrange.h" typedef void ( @@ -67,11 +69,17 @@ extern "C" { void Device_Init( void); + + bool Device_Reinitialize( + BACNET_REINITIALIZE_DEVICE_DATA *rd_data); void Device_Property_Lists( const int **pRequired, const int **pOptional, const int **pProprietary); + void Device_Objects_Property_List( + BACNET_OBJECT_TYPE object_type, + struct special_property_list_t *pPropertyList); uint32_t Device_Object_Instance_Number( void); @@ -160,9 +168,6 @@ extern "C" { int object_type, uint32_t object_instance); - int Device_Objects_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata); - int Device_Read_Property( BACNET_READ_PROPERTY_DATA *rpdata); bool Device_Write_Property( diff --git a/bacnet-stack/include/handlers.h b/bacnet-stack/include/handlers.h index a2de9a4e..da93ffd8 100644 --- a/bacnet-stack/include/handlers.h +++ b/bacnet-stack/include/handlers.h @@ -79,8 +79,6 @@ extern "C" { uint16_t service_len, BACNET_ADDRESS * src, BACNET_CONFIRMED_SERVICE_DATA * service_data); - void handler_read_property_function_set( - read_property_function pFunction); void handler_rr_object_set( get_rr_info_fn pFunction1); @@ -96,8 +94,6 @@ extern "C" { uint16_t service_len, BACNET_ADDRESS * src, BACNET_CONFIRMED_SERVICE_DATA * service_data); - void handler_write_property_function_set( - write_property_function pFunction); bool WPValidateString( BACNET_APPLICATION_DATA_VALUE *pValue, @@ -135,16 +131,12 @@ extern "C" { uint16_t service_len, BACNET_ADDRESS * src, BACNET_CONFIRMED_SERVICE_DATA * service_data); - void handler_reinitialize_device_function_set( - reinitialize_device_function pFunction); void handler_device_communication_control( uint8_t * service_request, uint16_t service_len, BACNET_ADDRESS * src, BACNET_CONFIRMED_SERVICE_DATA * service_data); - void handler_dcc_password_set( - char *new_password); void handler_i_have( uint8_t * service_request, @@ -166,10 +158,6 @@ extern "C" { uint16_t service_len, BACNET_ADDRESS * src, BACNET_CONFIRMED_SERVICE_DATA * service_data); - void handler_rpm_function_set( - read_property_function pFunction); - void handler_rpm_list_set( - rpm_object_property_lists_function pFunction); void handler_read_property_multiple_ack( uint8_t * service_request, diff --git a/bacnet-stack/ports/at91sam7s/device.c b/bacnet-stack/ports/at91sam7s/device.c index cfcbe1e4..bb2afc46 100644 --- a/bacnet-stack/ports/at91sam7s/device.c +++ b/bacnet-stack/ports/at91sam7s/device.c @@ -53,6 +53,12 @@ static char My_Object_Name[32] = "ARM7 Device"; static BACNET_DEVICE_STATUS System_Status = STATUS_OPERATIONAL; static BACNET_REINITIALIZED_STATE_OF_DEVICE Reinitialize_State = REINITIALIZED_STATE_IDLE; + +/* forward prototypes */ +int Device_Read_Property_Local( + BACNET_READ_PROPERTY_DATA *rpdata); +bool Device_Write_Property_Local( + BACNET_WRITE_PROPERTY_DATA * wp_data); static struct object_functions { BACNET_OBJECT_TYPE Object_Type; @@ -72,8 +78,8 @@ static struct object_functions { Device_Index_To_Instance, Device_Valid_Object_Instance_Number, Device_Name, - Device_Read_Property, - Device_Write_Property, + Device_Read_Property_Local, + Device_Write_Property_Local, Device_Property_Lists}, {OBJECT_ANALOG_INPUT, Analog_Input_Init, @@ -169,7 +175,7 @@ void Device_Property_Lists( /* Encodes the property APDU and returns the length, or sets the error, and returns -1 */ -int Device_Objects_Read_Property( +int Device_Read_Property( BACNET_READ_PROPERTY_DATA *rpdata) { int apdu_len = -1; @@ -207,7 +213,7 @@ int Device_Objects_Read_Property( return apdu_len; } -bool Device_Objects_Write_Property( +bool Device_Write_Property( BACNET_WRITE_PROPERTY_DATA * wp_data) { int apdu_len = -1; @@ -264,7 +270,7 @@ static unsigned property_list_count( } /* for a given object type, returns the special property list */ -static void Device_Objects_Property_List( +void Device_Objects_Property_List( BACNET_OBJECT_TYPE object_type, struct special_property_list_t *pPropertyList) { @@ -431,46 +437,6 @@ char *Device_Valid_Object_Id( return name; } -bool Device_Reinitialize( - BACNET_REINITIALIZE_DEVICE_DATA *rd_data) -{ - bool status = false; - - if (characterstring_ansi_same(&rd_data->password, "Jesus")) { - switch (rd_data->state) { - case REINITIALIZED_STATE_COLD_START: - break; - case REINITIALIZED_STATE_WARM_START: - break; - case REINITIALIZED_STATE_START_BACKUP: - break; - case REINITIALIZED_STATE_END_BACKUP: - break; - case REINITIALIZED_STATE_START_RESTORE: - break; - case REINITIALIZED_STATE_END_RESTORE: - break; - case REINITIALIZED_STATE_ABORT_RESTORE: - break; - default: - break; - } - Reinitialize_State = rd_data->state; - /* Note: you could use a mix of state - and password to multiple things */ - /* note: you probably want to restart *after* the - simple ack has been sent from the return handler - so just set a flag from here */ - dcc_set_status_duration(COMMUNICATION_ENABLE, 0); - status = true; - } else { - rd_data->error_class = ERROR_CLASS_SECURITY; - rd_data->error_code = ERROR_CODE_PASSWORD_FAILURE; - } - - return status; -} - unsigned Device_Count(void) { return 1; @@ -492,6 +458,28 @@ char *Device_Name( return NULL; } +bool Device_Reinitialize( + BACNET_REINITIALIZE_DEVICE_DATA *rd_data) +{ + bool status = false; + + if (characterstring_ansi_same(&rd_data->password, "filister")) { + Reinitialize_State = rd_data->state; + dcc_set_status_duration(COMMUNICATION_ENABLE, 0); + /* Note: you could use a mix of state + and password to multiple things */ + /* note: you probably want to restart *after* the + simple ack has been sent from the return handler + so just set a flag from here */ + status = true; + } else { + rd_data->error_class = ERROR_CLASS_SECURITY; + rd_data->error_code = ERROR_CODE_PASSWORD_FAILURE; + } + + return status; +} + void Device_Init( void) { @@ -505,11 +493,6 @@ void Device_Init( (char *)&Object_Instance_Number, sizeof(Object_Instance_Number), EEPROM_BACNET_ID_ADDR); */ - handler_read_property_function_set(Device_Objects_Read_Property); - handler_rpm_function_set(Device_Objects_Read_Property); - handler_rpm_list_set(Device_Objects_Property_List); - handler_write_property_function_set(Device_Objects_Write_Property); - handler_reinitialize_device_function_set(Device_Reinitialize); pObject = &Object_Table[0]; while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) { if (pObject->Object_Init) { @@ -604,7 +587,7 @@ uint32_t Device_Database_Revision( } /* return the length of the apdu encoded or -1 for error */ -int Device_Read_Property( +int Device_Read_Property_Local( BACNET_READ_PROPERTY_DATA *rpdata) { int apdu_len = 0; /* return value */ @@ -853,7 +836,7 @@ int Device_Read_Property( return apdu_len; } -bool Device_Write_Property( +bool Device_Write_Property_Local( BACNET_WRITE_PROPERTY_DATA * wp_data) { bool status = false; /* return value */ diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/Makefile b/bacnet-stack/ports/bdk-atxx4-mstp/Makefile index d4e5da5d..03f837d5 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/Makefile +++ b/bacnet-stack/ports/bdk-atxx4-mstp/Makefile @@ -59,7 +59,6 @@ CSRC = main.c \ eeprom.c \ seeprom.c \ dlmstp.c \ - h_rd.c \ device.c \ ai.c \ av.c \ @@ -68,13 +67,14 @@ CSRC = main.c \ # common demo files needed DEMOSRC = $(BACNET_DEMO)/handler/txbuf.c \ - $(BACNET_DEMO)/handler/h_npdu.c \ - $(BACNET_DEMO)/handler/h_whois.c \ $(BACNET_DEMO)/handler/h_dcc.c \ - $(BACNET_DEMO)/handler/h_wp.c \ + $(BACNET_DEMO)/handler/h_npdu.c \ + $(BACNET_DEMO)/handler/h_rd.c \ $(BACNET_DEMO)/handler/h_rp.c \ $(BACNET_DEMO)/handler/h_rpm.c \ $(BACNET_DEMO)/handler/h_whohas.c \ + $(BACNET_DEMO)/handler/h_whois.c \ + $(BACNET_DEMO)/handler/h_wp.c \ $(BACNET_DEMO)/handler/s_iam.c \ $(BACNET_DEMO)/handler/s_ihave.c \ $(BACNET_DEMO)/handler/noserv.c diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/device.c b/bacnet-stack/ports/bdk-atxx4-mstp/device.c index bf5b3ee3..8e8aa027 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/device.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/device.c @@ -46,6 +46,11 @@ #include "bi.h" #include "bo.h" +/* forward prototype */ +int Device_Read_Property_Local( + BACNET_READ_PROPERTY_DATA *rpdata); +bool Device_Write_Property_Local( + BACNET_WRITE_PROPERTY_DATA * wp_data); static struct object_functions { BACNET_OBJECT_TYPE Object_Type; @@ -65,8 +70,8 @@ static struct object_functions { Device_Index_To_Instance, Device_Valid_Object_Instance_Number, Device_Name, - Device_Read_Property, - Device_Write_Property, + Device_Read_Property_Local, + Device_Write_Property_Local, Device_Property_Lists}, {OBJECT_ANALOG_INPUT, Analog_Input_Init, @@ -225,7 +230,7 @@ static int Read_Property_Common( /* Encodes the property APDU and returns the length, or sets the error, and returns -1 */ -int Device_Objects_Read_Property( +int Device_Read_Property( BACNET_READ_PROPERTY_DATA *rpdata) { int apdu_len = -1; @@ -249,7 +254,7 @@ int Device_Objects_Read_Property( return apdu_len; } -bool Device_Objects_Write_Property( +bool Device_Write_Property( BACNET_WRITE_PROPERTY_DATA * wp_data) { int apdu_len = -1; @@ -294,7 +299,7 @@ static unsigned property_list_count( } /* for a given object type, returns the special property list */ -static void Device_Objects_Property_List( +void Device_Objects_Property_List( BACNET_OBJECT_TYPE object_type, struct special_property_list_t *pPropertyList) { @@ -366,11 +371,26 @@ char *Device_Name( return NULL; } -void Device_Reinit( - void) +bool Device_Reinitialize( + BACNET_REINITIALIZE_DEVICE_DATA *rd_data) { - dcc_set_status_duration(COMMUNICATION_ENABLE, 0); - Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE); + bool status = false; + + if (characterstring_ansi_same(&rd_data->password, "rehmite")) { + Reinitialize_State = rd_data->state; + dcc_set_status_duration(COMMUNICATION_ENABLE, 0); + /* Note: you could use a mix of state + and password to multiple things */ + /* note: you probably want to restart *after* the + simple ack has been sent from the return handler + so just set a flag from here */ + status = true; + } else { + rd_data->error_class = ERROR_CLASS_SECURITY; + rd_data->error_code = ERROR_CODE_PASSWORD_FAILURE; + } + + return status; } void Device_Init( @@ -378,11 +398,6 @@ void Device_Init( { struct object_functions *pObject = NULL; - handler_read_property_function_set(Device_Objects_Read_Property); - handler_rpm_function_set(Device_Objects_Read_Property); - handler_rpm_list_set(Device_Objects_Property_List); - handler_write_property_function_set(Device_Objects_Write_Property); - pObject = &Object_Table[0]; while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) { if (pObject->Object_Init) { @@ -390,9 +405,6 @@ void Device_Init( } pObject++; } - - Reinitialize_State = REINITIALIZED_STATE_IDLE; - dcc_set_status_duration(COMMUNICATION_ENABLE, 0); /* Get the data from the eeprom */ eeprom_bytes_read(NV_EEPROM_DEVICE_0, (uint8_t *) & Object_Instance_Number, @@ -598,7 +610,7 @@ char *Device_Valid_Object_Id( } /* return the length of the apdu encoded or -1 for error */ -int Device_Read_Property( +int Device_Read_Property_Local( BACNET_READ_PROPERTY_DATA *rpdata) { int apdu_len = 0; /* return value */ @@ -796,7 +808,7 @@ int Device_Read_Property( return apdu_len; } -bool Device_Write_Property( +bool Device_Write_Property_Local( BACNET_WRITE_PROPERTY_DATA * wp_data) { bool status = false; /* return value */