diff --git a/bacnet-stack/ports/atmega168/device.c b/bacnet-stack/ports/atmega168/device.c index e62c01d4..4778ea7c 100644 --- a/bacnet-stack/ports/atmega168/device.c +++ b/bacnet-stack/ports/atmega168/device.c @@ -160,6 +160,11 @@ bool Device_Object_List_Identifier( return status; } +#if defined(__GNUC__) +extern uint8_t _end; +extern uint8_t __stack; +#endif + /* return the length of the apdu encoded or -1 for error */ int Device_Encode_Property_APDU( uint8_t * apdu, @@ -321,6 +326,42 @@ int Device_Encode_Property_APDU( apdu_len = encode_application_unsigned(&apdu[0], RS485_Get_Baud_Rate()); break; +#if defined(__GNUC__) + case 512: + count = 1 + (&__stack) - (&_end); + if (array_index == 0) { + /* Array element zero is the number of bytes of stack */ + apdu_len = encode_application_unsigned(&apdu[0], count); + } else if (array_index == BACNET_ARRAY_ALL) { + /* if no index was specified, then try to encode the entire list */ + /* into one packet. Note that more than likely you will have */ + /* to return an error if the number of encoded objects exceeds */ + /* your maximum APDU size. */ + for (i = 1; i <= count; i++) { + len = + encode_application_unsigned(&apdu[0], *(&_end+i)); + apdu_len += len; + /* assume next one is the same size as this one */ + /* can we all fit into the APDU? */ + if ((apdu_len + len) >= MAX_APDU) { + *error_class = ERROR_CLASS_SERVICES; + *error_code = ERROR_CODE_NO_SPACE_FOR_OBJECT; + apdu_len = -1; + break; + } + } + } else if (array_index <= count) { + apdu_len = encode_application_unsigned(&apdu[0], *(&_end+array_index)); + } else { + *error_class = ERROR_CLASS_PROPERTY; + *error_code = ERROR_CODE_INVALID_ARRAY_INDEX; + apdu_len = -1; + } + break; + case 513: + apdu_len = encode_application_unsigned(&apdu[0], __stack); + break; +#endif default: *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_UNKNOWN_PROPERTY; diff --git a/bacnet-stack/ports/atmega168/main.c b/bacnet-stack/ports/atmega168/main.c index c6e4598b..ab899595 100644 --- a/bacnet-stack/ports/atmega168/main.c +++ b/bacnet-stack/ports/atmega168/main.c @@ -139,7 +139,6 @@ static void input_switch_read( } /* stack checking */ -#if STACK_CHECK_ENABLED #if defined(__GNUC__) extern uint8_t _end; extern uint8_t __stack; @@ -171,28 +170,6 @@ void StackPaint(void) " breq .loop"::); #endif } - -static uint16_t StackCount(void) -{ - const uint8_t *p = &_end; - uint16_t c = 0; - - while(*p == STACK_CANARY && p <= &__stack) - { - p++; - c++; - } - - return c; -} - -static void Analog_Value_Task(void) -{ - extern float AV_Present_Value[MAX_ANALOG_VALUES]; - - AV_Present_Value[0] = (float)StackCount(); -} -#endif #endif static uint8_t PDUBuffer[MAX_MPDU]; @@ -216,9 +193,6 @@ int main( /* BACnet handling */ pdu_len = datalink_receive(&src, &PDUBuffer[0], sizeof(PDUBuffer), 0); if (pdu_len) { -#if STACK_CHECK_ENABLED - Analog_Value_Task(); -#endif LED_NPDU_ON(); npdu_handler(&src, &PDUBuffer[0], pdu_len); LED_NPDU_OFF();