Indented.

This commit is contained in:
skarg
2008-11-24 12:48:09 +00:00
parent fdfd6a9f9f
commit d1a1c1c8a6
71 changed files with 6873 additions and 6754 deletions
+1 -1
View File
@@ -95,7 +95,7 @@ int arf_decode_service_request(
int tag_len = 0;
uint8_t tag_number = 0;
uint32_t len_value_type = 0;
uint16_t type = 0; /* for decoding */
uint16_t type = 0; /* for decoding */
/* check for value pointers */
if (apdu_len && data) {
+1 -1
View File
@@ -100,7 +100,7 @@ int awf_decode_service_request(
uint32_t len_value_type = 0;
int32_t signed_value = 0;
uint32_t unsigned_value = 0;
uint16_t type = 0; /* for decoding */
uint16_t type = 0; /* for decoding */
/* check for value pointers */
if (apdu_len && data) {
File diff suppressed because it is too large Load Diff
+235 -243
View File
@@ -1,243 +1,235 @@
/*####COPYRIGHTBEGIN####
-------------------------------------------
Copyright (C) 2008 John Minack
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
The Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA.
As a special exception, if other files instantiate templates or
use macros or inline functions from this file, or you compile
this file and link it with other works to produce a work based
on this file, this file does not by itself cause the resulting
work to be covered by the GNU General Public License. However
the source code for this file must still be made available in
accordance with section (3) of the GNU General Public License.
This exception does not invalidate any other reasons why a work
based on this file might be covered by the GNU General Public
License.
-------------------------------------------
####COPYRIGHTEND####*/
#include <assert.h>
#include "bacdcode.h"
#include "npdu.h"
#include "device.h"
#include "datalink.h"
#include "timestamp.h"
#include "bacdevobjpropref.h"
int bacapp_encode_context_device_obj_property_ref(
uint8_t * apdu,
uint8_t tag_number,
BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE * value)
{
int len;
int apdu_len = 0;
len = encode_opening_tag(&apdu[apdu_len], tag_number);
apdu_len += len;
len = bacapp_encode_device_obj_property_ref(&apdu[apdu_len], value);
apdu_len += len;
len = encode_closing_tag(&apdu[apdu_len], tag_number);
apdu_len += len;
return apdu_len;
}
int bacapp_encode_device_obj_property_ref(
uint8_t * apdu,
BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE * value)
{
int len;
int apdu_len = 0;
len = encode_context_object_id(&apdu[apdu_len], 0,
value->objectIdentifier.type,
value->objectIdentifier.instance);
apdu_len += len;
len = encode_context_enumerated(&apdu[apdu_len], 1,
value->propertyIdentifier);
apdu_len += len;
if ( value->arrayIndex > 0 )
{
len = encode_context_unsigned(&apdu[apdu_len], 2,
value->arrayIndex);
apdu_len += len;
}
len = encode_context_object_id(&apdu[apdu_len], 3,
value->deviceIndentifier.type,
value->deviceIndentifier.instance);
apdu_len += len;
return apdu_len;
}
int bacapp_decode_device_obj_property_ref(
uint8_t * apdu,
BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE * value)
{
int len;
int apdu_len = 0;
if ( -1 == ( len = decode_context_object_id(&apdu[apdu_len], 0,
&value->objectIdentifier.type,
&value->objectIdentifier.instance)) )
{
return -1;
}
apdu_len += len;
if ( -1 == ( len = decode_context_enumerated(&apdu[apdu_len], 1,
&value->propertyIdentifier)))
{
return -1;
}
apdu_len += len;
if ( decode_is_context_tag(&apdu[apdu_len], 2 ))
{
if ( -1 == ( len = decode_context_unsigned(&apdu[apdu_len], 2,
&value->arrayIndex)))
{
return -1;
}
apdu_len += len;
}
else
{
value->arrayIndex = 0;
}
if ( decode_is_context_tag(&apdu[apdu_len], 3 ))
{
if ( -1 == ( len = decode_context_object_id(&apdu[apdu_len], 3,
&value->deviceIndentifier.type,
&value->deviceIndentifier.instance)) )
{
return -1;
}
apdu_len += len;
}
else
{
value->deviceIndentifier.instance = 0;
value->deviceIndentifier.type = 0;
}
return apdu_len;
}
int bacapp_decode_context_device_obj_property_ref(
uint8_t * apdu,
uint8_t tag_number,
BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE * value)
{
int len = 0;
int section_length;
if (decode_is_opening_tag_number(&apdu[len], tag_number)) {
len++;
section_length = bacapp_decode_device_obj_property_ref(
&apdu[len], value);
if ( section_length == -1 )
{
len = -1;
}
else
{
len += section_length;
if (decode_is_closing_tag_number(&apdu[len], tag_number)) {
len++;
}
else
{
len = -1;
}
}
}
else
{
len = -1;
}
return len;
}
#ifdef TEST
void testDevIdPropRef(
Test * pTest)
{
BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE inData;
BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE outData;
uint8_t buffer[MAX_APDU];
int inLen;
int outLen;
inData.objectIdentifier.instance = 0x1234;
inData.objectIdentifier.type = 15;
inData.propertyIdentifier = 25;
inData.arrayIndex = 0x5678;
inData.deviceIndentifier.instance = 0x4343;
inData.deviceIndentifier.type = 28;
inLen = bacapp_encode_device_obj_property_ref(buffer, &inData);
outLen = bacapp_decode_device_obj_property_ref(buffer, &outData);
ct_test(pTest, outLen == inLen);
ct_test(pTest, inData.objectIdentifier.instance == outData.objectIdentifier.instance);
ct_test(pTest, inData.objectIdentifier.type == outData.objectIdentifier.type);
ct_test(pTest, inData.propertyIdentifier == outData.propertyIdentifier);
ct_test(pTest, inData.arrayIndex == outData.arrayIndex);
ct_test(pTest, inData.deviceIndentifier.instance == outData.deviceIndentifier.instance);
ct_test(pTest, inData.deviceIndentifier.type == outData.deviceIndentifier.type);
}
#ifdef TEST_DEV_ID_PROP_REF
int main(
void)
{
Test *pTest;
bool rc;
pTest = ct_create("BACnet Prop Ref", NULL);
/* individual tests */
rc = ct_addTestFunction(pTest, testDevIdPropRef);
assert(rc);
ct_setStream(pTest, stdout);
ct_run(pTest);
(void) ct_report(pTest);
ct_destroy(pTest);
return 0;
}
#endif // TEST_DEV_ID_PROP_REF
#endif // TEST
/*####COPYRIGHTBEGIN####
-------------------------------------------
Copyright (C) 2008 John Minack
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
The Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA.
As a special exception, if other files instantiate templates or
use macros or inline functions from this file, or you compile
this file and link it with other works to produce a work based
on this file, this file does not by itself cause the resulting
work to be covered by the GNU General Public License. However
the source code for this file must still be made available in
accordance with section (3) of the GNU General Public License.
This exception does not invalidate any other reasons why a work
based on this file might be covered by the GNU General Public
License.
-------------------------------------------
####COPYRIGHTEND####*/
#include <assert.h>
#include "bacdcode.h"
#include "npdu.h"
#include "device.h"
#include "datalink.h"
#include "timestamp.h"
#include "bacdevobjpropref.h"
int bacapp_encode_context_device_obj_property_ref(
uint8_t * apdu,
uint8_t tag_number,
BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE * value)
{
int len;
int apdu_len = 0;
len = encode_opening_tag(&apdu[apdu_len], tag_number);
apdu_len += len;
len = bacapp_encode_device_obj_property_ref(&apdu[apdu_len], value);
apdu_len += len;
len = encode_closing_tag(&apdu[apdu_len], tag_number);
apdu_len += len;
return apdu_len;
}
int bacapp_encode_device_obj_property_ref(
uint8_t * apdu,
BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE * value)
{
int len;
int apdu_len = 0;
len =
encode_context_object_id(&apdu[apdu_len], 0,
value->objectIdentifier.type, value->objectIdentifier.instance);
apdu_len += len;
len =
encode_context_enumerated(&apdu[apdu_len], 1,
value->propertyIdentifier);
apdu_len += len;
if (value->arrayIndex > 0) {
len = encode_context_unsigned(&apdu[apdu_len], 2, value->arrayIndex);
apdu_len += len;
}
len =
encode_context_object_id(&apdu[apdu_len], 3,
value->deviceIndentifier.type, value->deviceIndentifier.instance);
apdu_len += len;
return apdu_len;
}
int bacapp_decode_device_obj_property_ref(
uint8_t * apdu,
BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE * value)
{
int len;
int apdu_len = 0;
if (-1 == (len =
decode_context_object_id(&apdu[apdu_len], 0,
&value->objectIdentifier.type,
&value->objectIdentifier.instance))) {
return -1;
}
apdu_len += len;
if (-1 == (len =
decode_context_enumerated(&apdu[apdu_len], 1,
&value->propertyIdentifier))) {
return -1;
}
apdu_len += len;
if (decode_is_context_tag(&apdu[apdu_len], 2)) {
if (-1 == (len =
decode_context_unsigned(&apdu[apdu_len], 2,
&value->arrayIndex))) {
return -1;
}
apdu_len += len;
} else {
value->arrayIndex = 0;
}
if (decode_is_context_tag(&apdu[apdu_len], 3)) {
if (-1 == (len =
decode_context_object_id(&apdu[apdu_len], 3,
&value->deviceIndentifier.type,
&value->deviceIndentifier.instance))) {
return -1;
}
apdu_len += len;
} else {
value->deviceIndentifier.instance = 0;
value->deviceIndentifier.type = 0;
}
return apdu_len;
}
int bacapp_decode_context_device_obj_property_ref(
uint8_t * apdu,
uint8_t tag_number,
BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE * value)
{
int len = 0;
int section_length;
if (decode_is_opening_tag_number(&apdu[len], tag_number)) {
len++;
section_length =
bacapp_decode_device_obj_property_ref(&apdu[len], value);
if (section_length == -1) {
len = -1;
} else {
len += section_length;
if (decode_is_closing_tag_number(&apdu[len], tag_number)) {
len++;
} else {
len = -1;
}
}
} else {
len = -1;
}
return len;
}
#ifdef TEST
void testDevIdPropRef(
Test * pTest)
{
BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE inData;
BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE outData;
uint8_t buffer[MAX_APDU];
int inLen;
int outLen;
inData.objectIdentifier.instance = 0x1234;
inData.objectIdentifier.type = 15;
inData.propertyIdentifier = 25;
inData.arrayIndex = 0x5678;
inData.deviceIndentifier.instance = 0x4343;
inData.deviceIndentifier.type = 28;
inLen = bacapp_encode_device_obj_property_ref(buffer, &inData);
outLen = bacapp_decode_device_obj_property_ref(buffer, &outData);
ct_test(pTest, outLen == inLen);
ct_test(pTest,
inData.objectIdentifier.instance == outData.objectIdentifier.instance);
ct_test(pTest,
inData.objectIdentifier.type == outData.objectIdentifier.type);
ct_test(pTest, inData.propertyIdentifier == outData.propertyIdentifier);
ct_test(pTest, inData.arrayIndex == outData.arrayIndex);
ct_test(pTest,
inData.deviceIndentifier.instance ==
outData.deviceIndentifier.instance);
ct_test(pTest,
inData.deviceIndentifier.type == outData.deviceIndentifier.type);
}
#ifdef TEST_DEV_ID_PROP_REF
int main(
void)
{
Test *pTest;
bool rc;
pTest = ct_create("BACnet Prop Ref", NULL);
/* individual tests */
rc = ct_addTestFunction(pTest, testDevIdPropRef);
assert(rc);
ct_setStream(pTest, stdout);
ct_run(pTest);
(void) ct_report(pTest);
ct_destroy(pTest);
return 0;
}
#endif // TEST_DEV_ID_PROP_REF
#endif // TEST
+432 -403
View File
@@ -1,403 +1,432 @@
/*####COPYRIGHTBEGIN####
-------------------------------------------
Copyright (C) 2008 John Minack
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
The Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA.
As a special exception, if other files instantiate templates or
use macros or inline functions from this file, or you compile
this file and link it with other works to produce a work based
on this file, this file does not by itself cause the resulting
work to be covered by the GNU General Public License. However
the source code for this file must still be made available in
accordance with section (3) of the GNU General Public License.
This exception does not invalidate any other reasons why a work
based on this file might be covered by the GNU General Public
License.
-------------------------------------------
####COPYRIGHTEND####*/
#include <assert.h>
#include "bacdcode.h"
#include "npdu.h"
#include "device.h"
#include "datalink.h"
#include "timestamp.h"
#include "bacpropstates.h"
int bacapp_decode_property_state(
uint8_t * apdu,
BACNET_PROPERTY_STATE * value)
{
int len = 0;
uint32_t len_value_type;
int section_length;
section_length =
decode_tag_number_and_value(&apdu[len], (uint8_t*)&value->tag,
&len_value_type);
if ( -1 == section_length )
{
return -1;
}
len += section_length;
switch(value->tag)
{
case BOOLEAN_VALUE:
value->state.booleanValue = decode_boolean(len_value_type);
break;
case BINARY_VALUE:
if ( -1 == ( section_length = decode_enumerated(&apdu[len], len_value_type, &value->state.binaryValue)))
{
return -1;
}
break;
case EVENT_TYPE:
if ( -1 == ( section_length = decode_enumerated(&apdu[len], len_value_type, &value->state.eventType)))
{
return -1;
}
break;
case POLARITY:
if ( -1 == ( section_length = decode_enumerated(&apdu[len], len_value_type, &value->state.polarity)))
{
return -1;
}
break;
case PROGRAM_CHANGE:
if ( -1 == ( section_length = decode_enumerated(&apdu[len], len_value_type, &value->state.programChange)))
{
return -1;
}
break;
case PROGRAM_STATE:
if ( -1 == ( section_length = decode_enumerated(&apdu[len], len_value_type, &value->state.programState)))
{
return -1;
}
break;
case REASON_FOR_HALT:
if ( -1 == ( section_length = decode_enumerated(&apdu[len], len_value_type, &value->state.programError)))
{
return -1;
}
break;
case RELIABILITY:
if ( -1 == ( section_length = decode_enumerated(&apdu[len], len_value_type, &value->state.reliability)))
{
return -1;
}
break;
case STATE:
if ( -1 == ( section_length = decode_enumerated(&apdu[len], len_value_type, &value->state.state)))
{
return -1;
}
break;
case SYSTEM_STATUS:
if ( -1 == ( section_length = decode_enumerated(&apdu[len], len_value_type, &value->state.systemStatus)))
{
return -1;
}
break;
case UNITS:
if ( -1 == ( section_length = decode_enumerated(&apdu[len], len_value_type, &value->state.units)))
{
return -1;
}
break;
case UNSIGNED_VALUE:
if ( -1 == ( section_length = decode_unsigned(&apdu[len], len_value_type, &value->state.unsignedValue)))
{
return -1;
}
break;
case LIFE_SAFETY_MODE:
if ( -1 == ( section_length = decode_enumerated(&apdu[len], len_value_type, &value->state.lifeSafetyMode)))
{
return -1;
}
break;
case LIFE_SAFETY_STATE:
if ( -1 == ( section_length = decode_enumerated(&apdu[len], len_value_type, &value->state.lifeSafetyState)))
{
return -1;
}
break;
default:
return -1;
}
len += section_length;
return len;
}
int bacapp_decode_context_property_state(
uint8_t * apdu,
uint8_t tag_number,
BACNET_PROPERTY_STATE * value)
{
int len = 0;
int section_length;
if (decode_is_opening_tag_number(&apdu[len], tag_number)) {
len++;
section_length = bacapp_decode_property_state(
&apdu[len], value);
if ( section_length == -1 )
{
len = -1;
}
else
{
len += section_length;
if (decode_is_closing_tag_number(&apdu[len], tag_number)) {
len++;
}
else
{
len = -1;
}
}
}
else
{
len = -1;
}
return len;
}
int bacapp_encode_property_state(
uint8_t * apdu,
BACNET_PROPERTY_STATE * value)
{
int len = 0; /* length of each encoding */
if (value && apdu) {
switch(value->tag)
{
case BOOLEAN_VALUE:
len = encode_context_boolean(&apdu[0], 0, value->state.booleanValue);
break;
case BINARY_VALUE:
len = encode_context_enumerated(&apdu[0], 1, value->state.binaryValue);
break;
case EVENT_TYPE:
len = encode_context_enumerated(&apdu[0], 2, value->state.eventType);
break;
case POLARITY:
len = encode_context_enumerated(&apdu[0], 3, value->state.polarity);
break;
case PROGRAM_CHANGE:
len = encode_context_enumerated(&apdu[0], 4, value->state.programChange);
break;
case PROGRAM_STATE:
len = encode_context_enumerated(&apdu[0], 5, value->state.programState);
break;
case REASON_FOR_HALT:
len = encode_context_enumerated(&apdu[0], 6, value->state.programError);
break;
case RELIABILITY:
len = encode_context_enumerated(&apdu[0], 7, value->state.reliability);
break;
case STATE:
len = encode_context_enumerated(&apdu[0], 8, value->state.state);
break;
case SYSTEM_STATUS:
len = encode_context_enumerated(&apdu[0], 9, value->state.systemStatus);
break;
case UNITS:
len = encode_context_enumerated(&apdu[0], 10, value->state.units);
break;
case UNSIGNED_VALUE:
len = encode_context_unsigned(&apdu[0], 11, value->state.unsignedValue);
break;
case LIFE_SAFETY_MODE:
len = encode_context_enumerated(&apdu[0], 12, value->state.lifeSafetyMode);
break;
case LIFE_SAFETY_STATE:
len = encode_context_enumerated(&apdu[0], 13, value->state.lifeSafetyState);
break;
default:
assert(0);
break;
}
}
return len;
}
#ifdef TEST
void testPropStates(
Test * pTest)
{
BACNET_PROPERTY_STATE inData;
BACNET_PROPERTY_STATE outData;
uint8_t appMsg[MAX_APDU];
int inLen;
int outLen;
inData.tag = BOOLEAN_VALUE;
inData.state.booleanValue = true;
inLen = bacapp_encode_property_state(appMsg, &inData);
memset(&outData, 0, sizeof(outData));
outLen = bacapp_decode_property_state(appMsg, &outData);
ct_test(pTest, outLen == inLen);
ct_test(pTest, inData.tag == outData.tag );
ct_test(pTest, inData.state.booleanValue == outData.state.booleanValue );
/****************
*****************
****************/
inData.tag = BINARY_VALUE;
inData.state.binaryValue = BINARY_ACTIVE;
inLen = bacapp_encode_property_state(appMsg, &inData);
memset(&outData, 0, sizeof(outData));
outLen = bacapp_decode_property_state(appMsg, &outData);
ct_test(pTest, outLen == inLen);
ct_test(pTest, inData.tag == outData.tag );
ct_test(pTest, inData.state.binaryValue == outData.state.binaryValue );
/****************
*****************
****************/
inData.tag = EVENT_TYPE;
inData.state.eventType = EVENT_BUFFER_READY;
inLen = bacapp_encode_property_state(appMsg, &inData);
memset(&outData, 0, sizeof(outData));
outLen = bacapp_decode_property_state(appMsg, &outData);
ct_test(pTest, outLen == inLen);
ct_test(pTest, inData.tag == outData.tag );
ct_test(pTest, inData.state.eventType == outData.state.eventType );
/****************
*****************
****************/
inData.tag = POLARITY;
inData.state.polarity = POLARITY_REVERSE;
inLen = bacapp_encode_property_state(appMsg, &inData);
memset(&outData, 0, sizeof(outData));
outLen = bacapp_decode_property_state(appMsg, &outData);
ct_test(pTest, outLen == inLen);
ct_test(pTest, inData.tag == outData.tag );
ct_test(pTest, inData.state.polarity == outData.state.polarity );
/****************
*****************
****************/
inData.tag = PROGRAM_CHANGE;
inData.state.programChange = PROGRAM_REQUEST_RESTART;
inLen = bacapp_encode_property_state(appMsg, &inData);
memset(&outData, 0, sizeof(outData));
outLen = bacapp_decode_property_state(appMsg, &outData);
ct_test(pTest, outLen == inLen);
ct_test(pTest, inData.tag == outData.tag );
ct_test(pTest, inData.state.programChange == outData.state.programChange );
/****************
*****************
****************/
inData.tag = UNSIGNED_VALUE;
inData.state.unsignedValue = 0xdeadbeef;
inLen = bacapp_encode_property_state(appMsg, &inData);
memset(&outData, 0, sizeof(outData));
outLen = bacapp_decode_property_state(appMsg, &outData);
ct_test(pTest, outLen == inLen);
ct_test(pTest, inData.tag == outData.tag );
ct_test(pTest, inData.state.unsignedValue == outData.state.unsignedValue );
}
#ifdef TEST_PROP_STATES
int main(
void)
{
Test *pTest;
bool rc;
pTest = ct_create("BACnet Event", NULL);
/* individual tests */
rc = ct_addTestFunction(pTest, testPropStates);
assert(rc);
ct_setStream(pTest, stdout);
ct_run(pTest);
(void) ct_report(pTest);
ct_destroy(pTest);
return 0;
}
#endif // TEST_PROP_STATES
#endif // TEST
/*####COPYRIGHTBEGIN####
-------------------------------------------
Copyright (C) 2008 John Minack
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
The Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA.
As a special exception, if other files instantiate templates or
use macros or inline functions from this file, or you compile
this file and link it with other works to produce a work based
on this file, this file does not by itself cause the resulting
work to be covered by the GNU General Public License. However
the source code for this file must still be made available in
accordance with section (3) of the GNU General Public License.
This exception does not invalidate any other reasons why a work
based on this file might be covered by the GNU General Public
License.
-------------------------------------------
####COPYRIGHTEND####*/
#include <assert.h>
#include "bacdcode.h"
#include "npdu.h"
#include "device.h"
#include "datalink.h"
#include "timestamp.h"
#include "bacpropstates.h"
int bacapp_decode_property_state(
uint8_t * apdu,
BACNET_PROPERTY_STATE * value)
{
int len = 0;
uint32_t len_value_type;
int section_length;
section_length =
decode_tag_number_and_value(&apdu[len], (uint8_t *) & value->tag,
&len_value_type);
if (-1 == section_length) {
return -1;
}
len += section_length;
switch (value->tag) {
case BOOLEAN_VALUE:
value->state.booleanValue = decode_boolean(len_value_type);
break;
case BINARY_VALUE:
if (-1 == (section_length =
decode_enumerated(&apdu[len], len_value_type,
&value->state.binaryValue))) {
return -1;
}
break;
case EVENT_TYPE:
if (-1 == (section_length =
decode_enumerated(&apdu[len], len_value_type,
&value->state.eventType))) {
return -1;
}
break;
case POLARITY:
if (-1 == (section_length =
decode_enumerated(&apdu[len], len_value_type,
&value->state.polarity))) {
return -1;
}
break;
case PROGRAM_CHANGE:
if (-1 == (section_length =
decode_enumerated(&apdu[len], len_value_type,
&value->state.programChange))) {
return -1;
}
break;
case PROGRAM_STATE:
if (-1 == (section_length =
decode_enumerated(&apdu[len], len_value_type,
&value->state.programState))) {
return -1;
}
break;
case REASON_FOR_HALT:
if (-1 == (section_length =
decode_enumerated(&apdu[len], len_value_type,
&value->state.programError))) {
return -1;
}
break;
case RELIABILITY:
if (-1 == (section_length =
decode_enumerated(&apdu[len], len_value_type,
&value->state.reliability))) {
return -1;
}
break;
case STATE:
if (-1 == (section_length =
decode_enumerated(&apdu[len], len_value_type,
&value->state.state))) {
return -1;
}
break;
case SYSTEM_STATUS:
if (-1 == (section_length =
decode_enumerated(&apdu[len], len_value_type,
&value->state.systemStatus))) {
return -1;
}
break;
case UNITS:
if (-1 == (section_length =
decode_enumerated(&apdu[len], len_value_type,
&value->state.units))) {
return -1;
}
break;
case UNSIGNED_VALUE:
if (-1 == (section_length =
decode_unsigned(&apdu[len], len_value_type,
&value->state.unsignedValue))) {
return -1;
}
break;
case LIFE_SAFETY_MODE:
if (-1 == (section_length =
decode_enumerated(&apdu[len], len_value_type,
&value->state.lifeSafetyMode))) {
return -1;
}
break;
case LIFE_SAFETY_STATE:
if (-1 == (section_length =
decode_enumerated(&apdu[len], len_value_type,
&value->state.lifeSafetyState))) {
return -1;
}
break;
default:
return -1;
}
len += section_length;
return len;
}
int bacapp_decode_context_property_state(
uint8_t * apdu,
uint8_t tag_number,
BACNET_PROPERTY_STATE * value)
{
int len = 0;
int section_length;
if (decode_is_opening_tag_number(&apdu[len], tag_number)) {
len++;
section_length = bacapp_decode_property_state(&apdu[len], value);
if (section_length == -1) {
len = -1;
} else {
len += section_length;
if (decode_is_closing_tag_number(&apdu[len], tag_number)) {
len++;
} else {
len = -1;
}
}
} else {
len = -1;
}
return len;
}
int bacapp_encode_property_state(
uint8_t * apdu,
BACNET_PROPERTY_STATE * value)
{
int len = 0; /* length of each encoding */
if (value && apdu) {
switch (value->tag) {
case BOOLEAN_VALUE:
len =
encode_context_boolean(&apdu[0], 0,
value->state.booleanValue);
break;
case BINARY_VALUE:
len =
encode_context_enumerated(&apdu[0], 1,
value->state.binaryValue);
break;
case EVENT_TYPE:
len =
encode_context_enumerated(&apdu[0], 2,
value->state.eventType);
break;
case POLARITY:
len =
encode_context_enumerated(&apdu[0], 3,
value->state.polarity);
break;
case PROGRAM_CHANGE:
len =
encode_context_enumerated(&apdu[0], 4,
value->state.programChange);
break;
case PROGRAM_STATE:
len =
encode_context_enumerated(&apdu[0], 5,
value->state.programState);
break;
case REASON_FOR_HALT:
len =
encode_context_enumerated(&apdu[0], 6,
value->state.programError);
break;
case RELIABILITY:
len =
encode_context_enumerated(&apdu[0], 7,
value->state.reliability);
break;
case STATE:
len =
encode_context_enumerated(&apdu[0], 8, value->state.state);
break;
case SYSTEM_STATUS:
len =
encode_context_enumerated(&apdu[0], 9,
value->state.systemStatus);
break;
case UNITS:
len =
encode_context_enumerated(&apdu[0], 10,
value->state.units);
break;
case UNSIGNED_VALUE:
len =
encode_context_unsigned(&apdu[0], 11,
value->state.unsignedValue);
break;
case LIFE_SAFETY_MODE:
len =
encode_context_enumerated(&apdu[0], 12,
value->state.lifeSafetyMode);
break;
case LIFE_SAFETY_STATE:
len =
encode_context_enumerated(&apdu[0], 13,
value->state.lifeSafetyState);
break;
default:
assert(0);
break;
}
}
return len;
}
#ifdef TEST
void testPropStates(
Test * pTest)
{
BACNET_PROPERTY_STATE inData;
BACNET_PROPERTY_STATE outData;
uint8_t appMsg[MAX_APDU];
int inLen;
int outLen;
inData.tag = BOOLEAN_VALUE;
inData.state.booleanValue = true;
inLen = bacapp_encode_property_state(appMsg, &inData);
memset(&outData, 0, sizeof(outData));
outLen = bacapp_decode_property_state(appMsg, &outData);
ct_test(pTest, outLen == inLen);
ct_test(pTest, inData.tag == outData.tag);
ct_test(pTest, inData.state.booleanValue == outData.state.booleanValue);
/****************
*****************
****************/
inData.tag = BINARY_VALUE;
inData.state.binaryValue = BINARY_ACTIVE;
inLen = bacapp_encode_property_state(appMsg, &inData);
memset(&outData, 0, sizeof(outData));
outLen = bacapp_decode_property_state(appMsg, &outData);
ct_test(pTest, outLen == inLen);
ct_test(pTest, inData.tag == outData.tag);
ct_test(pTest, inData.state.binaryValue == outData.state.binaryValue);
/****************
*****************
****************/
inData.tag = EVENT_TYPE;
inData.state.eventType = EVENT_BUFFER_READY;
inLen = bacapp_encode_property_state(appMsg, &inData);
memset(&outData, 0, sizeof(outData));
outLen = bacapp_decode_property_state(appMsg, &outData);
ct_test(pTest, outLen == inLen);
ct_test(pTest, inData.tag == outData.tag);
ct_test(pTest, inData.state.eventType == outData.state.eventType);
/****************
*****************
****************/
inData.tag = POLARITY;
inData.state.polarity = POLARITY_REVERSE;
inLen = bacapp_encode_property_state(appMsg, &inData);
memset(&outData, 0, sizeof(outData));
outLen = bacapp_decode_property_state(appMsg, &outData);
ct_test(pTest, outLen == inLen);
ct_test(pTest, inData.tag == outData.tag);
ct_test(pTest, inData.state.polarity == outData.state.polarity);
/****************
*****************
****************/
inData.tag = PROGRAM_CHANGE;
inData.state.programChange = PROGRAM_REQUEST_RESTART;
inLen = bacapp_encode_property_state(appMsg, &inData);
memset(&outData, 0, sizeof(outData));
outLen = bacapp_decode_property_state(appMsg, &outData);
ct_test(pTest, outLen == inLen);
ct_test(pTest, inData.tag == outData.tag);
ct_test(pTest, inData.state.programChange == outData.state.programChange);
/****************
*****************
****************/
inData.tag = UNSIGNED_VALUE;
inData.state.unsignedValue = 0xdeadbeef;
inLen = bacapp_encode_property_state(appMsg, &inData);
memset(&outData, 0, sizeof(outData));
outLen = bacapp_decode_property_state(appMsg, &outData);
ct_test(pTest, outLen == inLen);
ct_test(pTest, inData.tag == outData.tag);
ct_test(pTest, inData.state.unsignedValue == outData.state.unsignedValue);
}
#ifdef TEST_PROP_STATES
int main(
void)
{
Test *pTest;
bool rc;
pTest = ct_create("BACnet Event", NULL);
/* individual tests */
rc = ct_addTestFunction(pTest, testPropStates);
assert(rc);
ct_setStream(pTest, stdout);
ct_run(pTest);
(void) ct_report(pTest);
ct_destroy(pTest);
return 0;
}
#endif // TEST_PROP_STATES
#endif // TEST
+11 -12
View File
@@ -78,23 +78,22 @@ int decode_real(
int decode_context_real(
uint8_t * apdu,
uint8_t tag_number,
uint8_t tag_number,
float *real_value)
{
uint32_t len_value;
int len = 0;
int len = 0;
if (decode_is_context_tag(&apdu[len], tag_number)) {
len += decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value);
len += decode_real(&apdu[len], real_value);
}
else
{
len = -1;
}
return len;
if (decode_is_context_tag(&apdu[len], tag_number)) {
len +=
decode_tag_number_and_value(&apdu[len], &tag_number, &len_value);
len += decode_real(&apdu[len], real_value);
} else {
len = -1;
}
return len;
}
/* from clause 20.2.6 Encoding of a Real Number Value */
/* returns the number of apdu bytes consumed */
int encode_bacnet_real(
+2 -2
View File
@@ -99,7 +99,7 @@ uint8_t bitstring_bits_used(
uint8_t bitstring_bytes_used(
BACNET_BIT_STRING * bit_string)
{
uint8_t len = 0; /* return value */
uint8_t len = 0; /* return value */
uint8_t used_bytes = 0;
uint8_t last_bit = 0;
@@ -544,7 +544,7 @@ bool octetstring_value_same(
BACNET_OCTET_STRING * octet_string1,
BACNET_OCTET_STRING * octet_string2)
{
size_t i = 0; /* loop counter */
size_t i = 0; /* loop counter */
if (octet_string1 && octet_string2) {
if ((octet_string1->length == octet_string2->length) &&
+3 -3
View File
@@ -174,7 +174,7 @@ int cov_notify_decode_service_request(
uint8_t tag_number = 0;
uint32_t len_value = 0;
uint32_t decoded_value = 0; /* for decoding */
uint16_t decoded_type = 0; /* for decoding */
uint16_t decoded_type = 0; /* for decoding */
int property = 0; /* for decoding */
BACNET_PROPERTY_VALUE *value = NULL; /* value in list */
@@ -373,7 +373,7 @@ int cov_subscribe_decode_service_request(
uint8_t tag_number = 0;
uint32_t len_value = 0;
uint32_t decoded_value = 0; /* for decoding */
uint16_t decoded_type = 0; /* for decoding */
uint16_t decoded_type = 0; /* for decoding */
if (apdu_len && data) {
/* tag 0 - subscriberProcessIdentifier */
@@ -519,7 +519,7 @@ int cov_subscribe_property_decode_service_request(
uint8_t tag_number = 0;
uint32_t len_value = 0;
uint32_t decoded_value = 0; /* for decoding */
uint16_t decoded_type = 0; /* for decoding */
uint16_t decoded_type = 0; /* for decoding */
int property = 0; /* for decoding */
if (apdu_len && data) {
+70 -80
View File
@@ -75,7 +75,7 @@ static uint8_t month_days(
if ((month == 2) && is_leap_year(year))
return 29;
else if (month >= 1 && month <= 12)
return (uint8_t)month_days[month];
return (uint8_t) month_days[month];
else
return 0;
}
@@ -435,48 +435,47 @@ int bacapp_encode_context_datetime(
uint8_t tag_number,
BACNET_DATE_TIME * value)
{
int len = 0;
int apdu_len = 0;
int len = 0;
int apdu_len = 0;
if ( apdu && value )
{
len = encode_opening_tag(&apdu[apdu_len], tag_number);
apdu_len += len;
if (apdu && value) {
len = encode_opening_tag(&apdu[apdu_len], tag_number);
apdu_len += len;
len = encode_application_date(&apdu[apdu_len], &value->date);
apdu_len += len;
len = encode_application_date(&apdu[apdu_len], &value->date);
apdu_len += len;
len = encode_application_time(&apdu[apdu_len], &value->time);
apdu_len += len;
len = encode_application_time(&apdu[apdu_len], &value->time);
apdu_len += len;
len = encode_closing_tag(&apdu[apdu_len], tag_number);
apdu_len += len;
}
return apdu_len;
len = encode_closing_tag(&apdu[apdu_len], tag_number);
apdu_len += len;
}
return apdu_len;
}
int bacapp_decode_datetime(
uint8_t * apdu,
BACNET_DATE_TIME * value)
{
int len = 0;
int section_len;
int len = 0;
int section_len;
if ( -1 == ( section_len = decode_application_date(&apdu[len], &value->date) ) )
{
return -1;
}
len += section_len;
if (-1 == (section_len =
decode_application_date(&apdu[len], &value->date))) {
return -1;
}
len += section_len;
if ( -1 == ( section_len = decode_application_time(&apdu[len], &value->time) ) )
{
return -1;
}
if (-1 == (section_len =
decode_application_time(&apdu[len], &value->time))) {
return -1;
}
len += section_len;
return len;
len += section_len;
return len;
}
int bacapp_decode_context_datetime(
@@ -484,35 +483,27 @@ int bacapp_decode_context_datetime(
uint8_t tag_number,
BACNET_DATE_TIME * value)
{
int apdu_len = 0;
int len;
int apdu_len = 0;
int len;
if (decode_is_opening_tag_number(&apdu[apdu_len], tag_number)) {
apdu_len++;
}
else
{
return -1;
}
if (decode_is_opening_tag_number(&apdu[apdu_len], tag_number)) {
apdu_len++;
} else {
return -1;
}
if ( -1 == (len = bacapp_decode_datetime(&apdu[apdu_len], value)))
{
return -1;
}
else
{
apdu_len += len;
}
if (-1 == (len = bacapp_decode_datetime(&apdu[apdu_len], value))) {
return -1;
} else {
apdu_len += len;
}
if (decode_is_closing_tag_number(&apdu[apdu_len], tag_number))
{
apdu_len++;
}
else
{
return -1;
}
return apdu_len;
if (decode_is_closing_tag_number(&apdu[apdu_len], tag_number)) {
apdu_len++;
} else {
return -1;
}
return apdu_len;
}
@@ -836,36 +827,36 @@ void testBACnetDayOfWeek(
void testDatetimeCodec(
Test * pTest)
{
uint8_t apdu[MAX_APDU];
BACNET_DATE_TIME datetimeIn;
BACNET_DATE_TIME datetimeOut;
int inLen;
int outLen;
uint8_t apdu[MAX_APDU];
BACNET_DATE_TIME datetimeIn;
BACNET_DATE_TIME datetimeOut;
int inLen;
int outLen;
datetimeIn.date.day = 1;
datetimeIn.date.month = 2;
datetimeIn.date.wday = 3;
datetimeIn.date.year = 1904;
datetimeIn.date.day = 1;
datetimeIn.date.month = 2;
datetimeIn.date.wday = 3;
datetimeIn.date.year = 1904;
datetimeIn.time.hour = 5;
datetimeIn.time.min = 6;
datetimeIn.time.sec = 7;
datetimeIn.time.hundredths = 8;
datetimeIn.time.hour = 5;
datetimeIn.time.min = 6;
datetimeIn.time.sec = 7;
datetimeIn.time.hundredths = 8;
inLen = bacapp_encode_context_datetime(apdu, 10, &datetimeIn);
outLen = bacapp_decode_context_datetime(apdu, 10, &datetimeOut);
inLen = bacapp_encode_context_datetime(apdu, 10, &datetimeIn);
outLen = bacapp_decode_context_datetime(apdu, 10, &datetimeOut);
ct_test(pTest, inLen == outLen );
ct_test(pTest, inLen == outLen);
ct_test(pTest, datetimeIn.date.day == datetimeOut.date.day);
ct_test(pTest, datetimeIn.date.month == datetimeOut.date.month);
ct_test(pTest, datetimeIn.date.wday == datetimeOut.date.wday);
ct_test(pTest, datetimeIn.date.year == datetimeOut.date.year);
ct_test(pTest, datetimeIn.date.day == datetimeOut.date.day);
ct_test(pTest, datetimeIn.date.month == datetimeOut.date.month);
ct_test(pTest, datetimeIn.date.wday == datetimeOut.date.wday);
ct_test(pTest, datetimeIn.date.year == datetimeOut.date.year);
ct_test(pTest, datetimeIn.time.hour == datetimeOut.time.hour);
ct_test(pTest, datetimeIn.time.min == datetimeOut.time.min);
ct_test(pTest, datetimeIn.time.sec == datetimeOut.time.sec);
ct_test(pTest, datetimeIn.time.hundredths == datetimeOut.time.hundredths);
ct_test(pTest, datetimeIn.time.hour == datetimeOut.time.hour);
ct_test(pTest, datetimeIn.time.min == datetimeOut.time.min);
ct_test(pTest, datetimeIn.time.sec == datetimeOut.time.sec);
ct_test(pTest, datetimeIn.time.hundredths == datetimeOut.time.hundredths);
}
@@ -909,4 +900,3 @@ int main(
#endif /* TEST_DATE_TIME */
#endif /* TEST */
+1534 -1387
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -37,7 +37,7 @@
char *filename_remove_path(
const char *filename_in)
{
char *filename_out = (char *)filename_in;
char *filename_out = (char *) filename_in;
/* allow the device ID to be set */
if (filename_in) {
+1 -1
View File
@@ -80,7 +80,7 @@ int iam_decode_service_request(
{
int len = 0;
int apdu_len = 0; /* total length of the apdu, return value */
uint16_t object_type = 0; /* should be a Device Object */
uint16_t object_type = 0; /* should be a Device Object */
uint32_t object_instance = 0;
uint8_t tag_number = 0;
uint32_t len_value = 0;
+1 -1
View File
@@ -77,7 +77,7 @@ int ihave_decode_service_request(
int len = 0;
uint8_t tag_number = 0;
uint32_t len_value = 0;
uint16_t decoded_type = 0; /* for decoding */
uint16_t decoded_type = 0; /* for decoding */
if (apdu_len && data) {
/* deviceIdentifier */
+10 -11
View File
@@ -36,12 +36,12 @@
/* copy len bytes from src to offset of dest if there is enough space. */
/* returns 0 if there is not enough space, or the number of bytes copied. */
size_t memcopy(
void * dest,
void * src,
size_t offset, /* where in dest to put the data */
void *dest,
void *src,
size_t offset, /* where in dest to put the data */
size_t len, /* amount of data to copy */
size_t max) /* total size of destination */
{
size_t max)
{ /* total size of destination */
size_t i;
size_t copy_len = 0;
char *s1, *s2;
@@ -73,15 +73,14 @@ void test_memcopy(
char big_buffer[480] = "";
size_t len = 0;
len = memcopy(&buffer[0], &data1[0], 0,
sizeof(data1), sizeof(buffer));
len = memcopy(&buffer[0], &data1[0], 0, sizeof(data1), sizeof(buffer));
ct_test(pTest, len == sizeof(data1));
ct_test(pTest, memcmp(&buffer[0], &data1[0], len) == 0);
len = memcopy(&buffer[0], &data2[0], len,
sizeof(data2), sizeof(buffer));
len = memcopy(&buffer[0], &data2[0], len, sizeof(data2), sizeof(buffer));
ct_test(pTest, len == sizeof(data2));
len = memcopy(&buffer[0], &big_buffer[0], 1,
sizeof(big_buffer), sizeof(buffer));
len =
memcopy(&buffer[0], &big_buffer[0], 1, sizeof(big_buffer),
sizeof(buffer));
ct_test(pTest, len == 0);
}
+3 -3
View File
@@ -81,7 +81,7 @@ int rp_decode_service_request(
unsigned len = 0;
uint8_t tag_number = 0;
uint32_t len_value_type = 0;
uint16_t type = 0; /* for decoding */
uint16_t type = 0; /* for decoding */
int property = 0; /* for decoding */
uint32_t array_value = 0; /* for decoding */
@@ -214,8 +214,8 @@ int rp_ack_decode_service_request(
uint32_t len_value_type = 0;
int tag_len = 0; /* length of tag decode */
int len = 0; /* total length of decodes */
uint16_t object = 0; /* object type */
int property = 0; /* for decoding */
uint16_t object = 0; /* object type */
int property = 0; /* for decoding */
uint32_t array_value = 0; /* for decoding */
/* FIXME: check apdu_len against the len during decode */
+16 -13
View File
@@ -110,13 +110,13 @@ int rpm_encode_apdu(
uint8_t * apdu,
size_t max_apdu,
uint8_t invoke_id,
BACNET_READ_ACCESS_DATA *read_access_data)
BACNET_READ_ACCESS_DATA * read_access_data)
{
int apdu_len = 0; /* total length of the apdu, return value */
int len = 0; /* length of the data */
BACNET_READ_ACCESS_DATA *rpm_object; /* current object */
uint8_t apdu_temp[16]; /* temp for data before copy */
BACNET_PROPERTY_REFERENCE *rpm_property; /* current property */
int len = 0; /* length of the data */
BACNET_READ_ACCESS_DATA *rpm_object; /* current object */
uint8_t apdu_temp[16]; /* temp for data before copy */
BACNET_PROPERTY_REFERENCE *rpm_property; /* current property */
len = rpm_encode_apdu_init(&apdu_temp[0], invoke_id);
len = memcopy(&apdu[0], &apdu_temp[0], apdu_len, len, max_apdu);
@@ -126,9 +126,9 @@ int rpm_encode_apdu(
apdu_len += len;
rpm_object = read_access_data;
while (rpm_object) {
len = encode_context_object_id(&apdu_temp[0], 0,
rpm_object->object_type,
rpm_object->object_instance);
len =
encode_context_object_id(&apdu_temp[0], 0, rpm_object->object_type,
rpm_object->object_instance);
len = memcopy(&apdu[0], &apdu_temp[0], apdu_len, len, max_apdu);
if (len == 0) {
return 0;
@@ -144,7 +144,8 @@ int rpm_encode_apdu(
rpm_property = rpm_object->listOfProperties;
while (rpm_property) {
/* stuff as many properties into it as APDU length will allow */
len = encode_context_enumerated(&apdu_temp[0], 0,
len =
encode_context_enumerated(&apdu_temp[0], 0,
rpm_property->propertyIdentifier);
len = memcopy(&apdu[0], &apdu_temp[0], apdu_len, len, max_apdu);
if (len == 0) {
@@ -153,9 +154,11 @@ int rpm_encode_apdu(
apdu_len += len;
/* optional array index */
if (rpm_property->propertyArrayIndex != BACNET_ARRAY_ALL) {
len = encode_context_unsigned(&apdu_temp[0], 1,
len =
encode_context_unsigned(&apdu_temp[0], 1,
rpm_property->propertyArrayIndex);
len = memcopy(&apdu[0], &apdu_temp[0], apdu_len, len, max_apdu);
len =
memcopy(&apdu[0], &apdu_temp[0], apdu_len, len, max_apdu);
if (len == 0) {
return 0;
}
@@ -183,7 +186,7 @@ int rpm_decode_object_id(
uint32_t * object_instance)
{
unsigned len = 0;
uint16_t type = 0; /* for decoding */
uint16_t type = 0; /* for decoding */
/* check for value pointers */
if (apdu && apdu_len && object_type && object_instance) {
@@ -383,7 +386,7 @@ int rpm_ack_decode_object_id(
uint32_t * object_instance)
{
unsigned len = 0;
uint16_t type = 0; /* for decoding */
uint16_t type = 0; /* for decoding */
/* check for value pointers */
if (apdu && apdu_len && object_type && object_instance) {
+2 -2
View File
@@ -43,8 +43,8 @@
void sbuf_init(
STATIC_BUFFER * b, /* static buffer structure */
char *data, /* data block */
unsigned size) /* actual size, in bytes, of the data block or array of data */
{
unsigned size)
{ /* actual size, in bytes, of the data block or array of data */
if (b) {
b->data = data;
b->size = size;
+301 -283
View File
@@ -1,283 +1,301 @@
/*####COPYRIGHTBEGIN####
-------------------------------------------
Copyright (C) 2008 John Minack
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
The Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA.
As a special exception, if other files instantiate templates or
use macros or inline functions from this file, or you compile
this file and link it with other works to produce a work based
on this file, this file does not by itself cause the resulting
work to be covered by the GNU General Public License. However
the source code for this file must still be made available in
accordance with section (3) of the GNU General Public License.
This exception does not invalidate any other reasons why a work
based on this file might be covered by the GNU General Public
License.
-------------------------------------------
####COPYRIGHTEND####*/
#include "assert.h"
#include "timestamp.h"
int bacapp_encode_context_timestamp(
uint8_t * apdu,
uint8_t tag_number,
BACNET_TIMESTAMP * value)
{
int len = 0; /* length of each encoding */
int apdu_len = 0;
if (value && apdu) {
len = encode_opening_tag(&apdu[apdu_len], tag_number);
apdu_len += len;
switch(value->tag)
{
case TIME_STAMP_TIME:
len = encode_context_time(&apdu[apdu_len], 0, &value->value.time);
break;
case TIME_STAMP_SEQUENCE:
len = encode_context_unsigned(&apdu[apdu_len], 1, value->value.sequenceNum);
break;
case TIME_STAMP_DATETIME:
len = bacapp_encode_context_datetime(&apdu[apdu_len], 2, &value->value.dateTime);
break;
default:
len = 0;
assert(0);
break;
}
apdu_len += len;
len = encode_closing_tag(&apdu[apdu_len], tag_number);
apdu_len += len;
}
return apdu_len;
}
int bacapp_decode_context_timestamp(
uint8_t * apdu,
uint8_t tag_number,
BACNET_TIMESTAMP * value)
{
int len = 0;
int section_len;
uint32_t len_value_type;
uint32_t sequenceNum;
if (decode_is_opening_tag_number(&apdu[len], tag_number)) {
len++;
section_len =
decode_tag_number_and_value(&apdu[len], &value->tag,
&len_value_type);
if ( -1 == section_len )
{
return -1;
}
switch( value->tag )
{
case TIME_STAMP_TIME:
if ( (section_len = decode_context_bacnet_time(&apdu[len], TIME_STAMP_TIME, &value->value.time)) == -1 )
{
return -1;
}
else
{
len += section_len;
}
break;
case TIME_STAMP_SEQUENCE:
if ( (section_len = decode_context_unsigned(&apdu[len], TIME_STAMP_SEQUENCE, &sequenceNum)) == -1 )
{
return -1;
}
else
{
if ( sequenceNum <= 0xffff )
{
len += section_len;
value->value.sequenceNum = (uint16_t)sequenceNum;
}
else
{
return -1;
}
}
break;
case TIME_STAMP_DATETIME:
if ( (section_len = bacapp_decode_context_datetime(&apdu[len], TIME_STAMP_DATETIME, &value->value.dateTime)) == -1 )
{
return -1;
}
else
{
len += section_len;
}
break;
default:
return -1;
}
if (decode_is_closing_tag_number(&apdu[len], tag_number)) {
len++;
}
else
{
return -1;
}
}
return len;
}
#ifdef TEST
#include <assert.h>
#include <string.h>
#include "ctest.h"
void testTimestampSequence(
Test * pTest)
{
BACNET_TIMESTAMP testTimestampIn;
BACNET_TIMESTAMP testTimestampOut;
uint8_t buffer[MAX_APDU];
int inLen;
int outLen;
testTimestampIn.tag = TIME_STAMP_SEQUENCE;
testTimestampIn.value.sequenceNum = 0x1234;
memset(&testTimestampOut, 0, sizeof(testTimestampOut));
inLen = bacapp_encode_context_timestamp(buffer, 2, &testTimestampIn);
outLen = bacapp_decode_context_timestamp(buffer, 2, &testTimestampOut);
ct_test(pTest, inLen == outLen);
ct_test(pTest, testTimestampIn.tag == testTimestampOut.tag);
ct_test(pTest, testTimestampIn.value.sequenceNum == testTimestampOut.value.sequenceNum);
}
void testTimestampTime(
Test * pTest)
{
BACNET_TIMESTAMP testTimestampIn;
BACNET_TIMESTAMP testTimestampOut;
uint8_t buffer[MAX_APDU];
int inLen;
int outLen;
testTimestampIn.tag = TIME_STAMP_TIME;
testTimestampIn.value.time.hour = 1;
testTimestampIn.value.time.min = 2;
testTimestampIn.value.time.sec = 3;
testTimestampIn.value.time.hundredths = 4;
memset(&testTimestampOut, 0, sizeof(testTimestampOut));
inLen = bacapp_encode_context_timestamp(buffer, 2, &testTimestampIn);
outLen = bacapp_decode_context_timestamp(buffer, 2, &testTimestampOut);
ct_test(pTest, inLen == outLen);
ct_test(pTest, testTimestampIn.tag == testTimestampOut.tag);
ct_test(pTest, testTimestampIn.value.time.hour == testTimestampOut.value.time.hour);
ct_test(pTest, testTimestampIn.value.time.min == testTimestampOut.value.time.min);
ct_test(pTest, testTimestampIn.value.time.sec == testTimestampOut.value.time.sec);
ct_test(pTest, testTimestampIn.value.time.hundredths == testTimestampOut.value.time.hundredths);
}
void testTimestampTimeDate(
Test * pTest)
{
BACNET_TIMESTAMP testTimestampIn;
BACNET_TIMESTAMP testTimestampOut;
uint8_t buffer[MAX_APDU];
int inLen;
int outLen;
testTimestampIn.tag = TIME_STAMP_DATETIME;
testTimestampIn.value.dateTime.time.hour = 1;
testTimestampIn.value.dateTime.time.min = 2;
testTimestampIn.value.dateTime.time.sec = 3;
testTimestampIn.value.dateTime.time.hundredths = 4;
testTimestampIn.value.dateTime.date.year = 1901;
testTimestampIn.value.dateTime.date.month = 1;
testTimestampIn.value.dateTime.date.wday = 2;
testTimestampIn.value.dateTime.date.day = 3;
memset(&testTimestampOut, 0, sizeof(testTimestampOut));
inLen = bacapp_encode_context_timestamp(buffer, 2, &testTimestampIn);
outLen = bacapp_decode_context_timestamp(buffer, 2, &testTimestampOut);
ct_test(pTest, inLen == outLen);
ct_test(pTest, testTimestampIn.tag == testTimestampOut.tag);
ct_test(pTest, testTimestampIn.value.dateTime.time.hour == testTimestampOut.value.dateTime.time.hour);
ct_test(pTest, testTimestampIn.value.dateTime.time.min == testTimestampOut.value.dateTime.time.min);
ct_test(pTest, testTimestampIn.value.dateTime.time.sec == testTimestampOut.value.dateTime.time.sec);
ct_test(pTest, testTimestampIn.value.dateTime.time.hundredths == testTimestampOut.value.dateTime.time.hundredths);
ct_test(pTest, testTimestampIn.value.dateTime.date.year == testTimestampOut.value.dateTime.date.year);
ct_test(pTest, testTimestampIn.value.dateTime.date.month == testTimestampOut.value.dateTime.date.month);
ct_test(pTest, testTimestampIn.value.dateTime.date.wday == testTimestampOut.value.dateTime.date.wday);
ct_test(pTest, testTimestampIn.value.dateTime.date.day == testTimestampOut.value.dateTime.date.day);
}
#ifdef TEST_TIME_STAMP
int main(
void)
{
Test *pTest;
bool rc;
pTest = ct_create("BACnet Time Stamp", NULL);
/* individual tests */
rc = ct_addTestFunction(pTest, testTimestampSequence);
assert(rc);
rc = ct_addTestFunction(pTest, testTimestampTime);
assert(rc);
rc = ct_addTestFunction(pTest, testTimestampTimeDate);
assert(rc);
ct_setStream(pTest, stdout);
ct_run(pTest);
(void) ct_report(pTest);
ct_destroy(pTest);
return 0;
}
#endif // TEST_TIME_STAMP
#endif // TEST
/*####COPYRIGHTBEGIN####
-------------------------------------------
Copyright (C) 2008 John Minack
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
The Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA.
As a special exception, if other files instantiate templates or
use macros or inline functions from this file, or you compile
this file and link it with other works to produce a work based
on this file, this file does not by itself cause the resulting
work to be covered by the GNU General Public License. However
the source code for this file must still be made available in
accordance with section (3) of the GNU General Public License.
This exception does not invalidate any other reasons why a work
based on this file might be covered by the GNU General Public
License.
-------------------------------------------
####COPYRIGHTEND####*/
#include "assert.h"
#include "timestamp.h"
int bacapp_encode_context_timestamp(
uint8_t * apdu,
uint8_t tag_number,
BACNET_TIMESTAMP * value)
{
int len = 0; /* length of each encoding */
int apdu_len = 0;
if (value && apdu) {
len = encode_opening_tag(&apdu[apdu_len], tag_number);
apdu_len += len;
switch (value->tag) {
case TIME_STAMP_TIME:
len =
encode_context_time(&apdu[apdu_len], 0,
&value->value.time);
break;
case TIME_STAMP_SEQUENCE:
len =
encode_context_unsigned(&apdu[apdu_len], 1,
value->value.sequenceNum);
break;
case TIME_STAMP_DATETIME:
len =
bacapp_encode_context_datetime(&apdu[apdu_len], 2,
&value->value.dateTime);
break;
default:
len = 0;
assert(0);
break;
}
apdu_len += len;
len = encode_closing_tag(&apdu[apdu_len], tag_number);
apdu_len += len;
}
return apdu_len;
}
int bacapp_decode_context_timestamp(
uint8_t * apdu,
uint8_t tag_number,
BACNET_TIMESTAMP * value)
{
int len = 0;
int section_len;
uint32_t len_value_type;
uint32_t sequenceNum;
if (decode_is_opening_tag_number(&apdu[len], tag_number)) {
len++;
section_len =
decode_tag_number_and_value(&apdu[len], &value->tag,
&len_value_type);
if (-1 == section_len) {
return -1;
}
switch (value->tag) {
case TIME_STAMP_TIME:
if ((section_len =
decode_context_bacnet_time(&apdu[len], TIME_STAMP_TIME,
&value->value.time)) == -1) {
return -1;
} else {
len += section_len;
}
break;
case TIME_STAMP_SEQUENCE:
if ((section_len =
decode_context_unsigned(&apdu[len],
TIME_STAMP_SEQUENCE, &sequenceNum)) == -1) {
return -1;
} else {
if (sequenceNum <= 0xffff) {
len += section_len;
value->value.sequenceNum = (uint16_t) sequenceNum;
} else {
return -1;
}
}
break;
case TIME_STAMP_DATETIME:
if ((section_len =
bacapp_decode_context_datetime(&apdu[len],
TIME_STAMP_DATETIME,
&value->value.dateTime)) == -1) {
return -1;
} else {
len += section_len;
}
break;
default:
return -1;
}
if (decode_is_closing_tag_number(&apdu[len], tag_number)) {
len++;
} else {
return -1;
}
}
return len;
}
#ifdef TEST
#include <assert.h>
#include <string.h>
#include "ctest.h"
void testTimestampSequence(
Test * pTest)
{
BACNET_TIMESTAMP testTimestampIn;
BACNET_TIMESTAMP testTimestampOut;
uint8_t buffer[MAX_APDU];
int inLen;
int outLen;
testTimestampIn.tag = TIME_STAMP_SEQUENCE;
testTimestampIn.value.sequenceNum = 0x1234;
memset(&testTimestampOut, 0, sizeof(testTimestampOut));
inLen = bacapp_encode_context_timestamp(buffer, 2, &testTimestampIn);
outLen = bacapp_decode_context_timestamp(buffer, 2, &testTimestampOut);
ct_test(pTest, inLen == outLen);
ct_test(pTest, testTimestampIn.tag == testTimestampOut.tag);
ct_test(pTest,
testTimestampIn.value.sequenceNum ==
testTimestampOut.value.sequenceNum);
}
void testTimestampTime(
Test * pTest)
{
BACNET_TIMESTAMP testTimestampIn;
BACNET_TIMESTAMP testTimestampOut;
uint8_t buffer[MAX_APDU];
int inLen;
int outLen;
testTimestampIn.tag = TIME_STAMP_TIME;
testTimestampIn.value.time.hour = 1;
testTimestampIn.value.time.min = 2;
testTimestampIn.value.time.sec = 3;
testTimestampIn.value.time.hundredths = 4;
memset(&testTimestampOut, 0, sizeof(testTimestampOut));
inLen = bacapp_encode_context_timestamp(buffer, 2, &testTimestampIn);
outLen = bacapp_decode_context_timestamp(buffer, 2, &testTimestampOut);
ct_test(pTest, inLen == outLen);
ct_test(pTest, testTimestampIn.tag == testTimestampOut.tag);
ct_test(pTest,
testTimestampIn.value.time.hour == testTimestampOut.value.time.hour);
ct_test(pTest,
testTimestampIn.value.time.min == testTimestampOut.value.time.min);
ct_test(pTest,
testTimestampIn.value.time.sec == testTimestampOut.value.time.sec);
ct_test(pTest,
testTimestampIn.value.time.hundredths ==
testTimestampOut.value.time.hundredths);
}
void testTimestampTimeDate(
Test * pTest)
{
BACNET_TIMESTAMP testTimestampIn;
BACNET_TIMESTAMP testTimestampOut;
uint8_t buffer[MAX_APDU];
int inLen;
int outLen;
testTimestampIn.tag = TIME_STAMP_DATETIME;
testTimestampIn.value.dateTime.time.hour = 1;
testTimestampIn.value.dateTime.time.min = 2;
testTimestampIn.value.dateTime.time.sec = 3;
testTimestampIn.value.dateTime.time.hundredths = 4;
testTimestampIn.value.dateTime.date.year = 1901;
testTimestampIn.value.dateTime.date.month = 1;
testTimestampIn.value.dateTime.date.wday = 2;
testTimestampIn.value.dateTime.date.day = 3;
memset(&testTimestampOut, 0, sizeof(testTimestampOut));
inLen = bacapp_encode_context_timestamp(buffer, 2, &testTimestampIn);
outLen = bacapp_decode_context_timestamp(buffer, 2, &testTimestampOut);
ct_test(pTest, inLen == outLen);
ct_test(pTest, testTimestampIn.tag == testTimestampOut.tag);
ct_test(pTest,
testTimestampIn.value.dateTime.time.hour ==
testTimestampOut.value.dateTime.time.hour);
ct_test(pTest,
testTimestampIn.value.dateTime.time.min ==
testTimestampOut.value.dateTime.time.min);
ct_test(pTest,
testTimestampIn.value.dateTime.time.sec ==
testTimestampOut.value.dateTime.time.sec);
ct_test(pTest,
testTimestampIn.value.dateTime.time.hundredths ==
testTimestampOut.value.dateTime.time.hundredths);
ct_test(pTest,
testTimestampIn.value.dateTime.date.year ==
testTimestampOut.value.dateTime.date.year);
ct_test(pTest,
testTimestampIn.value.dateTime.date.month ==
testTimestampOut.value.dateTime.date.month);
ct_test(pTest,
testTimestampIn.value.dateTime.date.wday ==
testTimestampOut.value.dateTime.date.wday);
ct_test(pTest,
testTimestampIn.value.dateTime.date.day ==
testTimestampOut.value.dateTime.date.day);
}
#ifdef TEST_TIME_STAMP
int main(
void)
{
Test *pTest;
bool rc;
pTest = ct_create("BACnet Time Stamp", NULL);
/* individual tests */
rc = ct_addTestFunction(pTest, testTimestampSequence);
assert(rc);
rc = ct_addTestFunction(pTest, testTimestampTime);
assert(rc);
rc = ct_addTestFunction(pTest, testTimestampTimeDate);
assert(rc);
ct_setStream(pTest, stdout);
ct_run(pTest);
(void) ct_report(pTest);
ct_destroy(pTest);
return 0;
}
#endif // TEST_TIME_STAMP
#endif // TEST
+1 -1
View File
@@ -88,7 +88,7 @@ int whohas_decode_service_request(
uint8_t tag_number = 0;
uint32_t len_value = 0;
uint32_t decoded_value = 0; /* for decoding */
uint16_t decoded_type = 0; /* for decoding */
uint16_t decoded_type = 0; /* for decoding */
if (apdu_len && data) {
/* optional limits - must be used as a pair */
+1 -1
View File
@@ -99,7 +99,7 @@ int wp_decode_service_request(
int tag_len = 0;
uint8_t tag_number = 0;
uint32_t len_value_type = 0;
uint16_t type = 0; /* for decoding */
uint16_t type = 0; /* for decoding */
int property = 0; /* for decoding */
uint32_t unsigned_value = 0;
int i = 0; /* loop counter */