corrected boolean context encoding. Added real context encoding.

This commit is contained in:
skarg
2006-10-24 03:24:15 +00:00
parent 4442ba82c2
commit 73b9c3eb24
2 changed files with 28 additions and 4 deletions
+25 -3
View File
@@ -733,11 +733,18 @@ int encode_tagged_boolean(uint8_t * apdu, bool boolean_value)
}
/* context tagged is encoded differently */
int encode_context_boolean(uint8_t * apdu, bool boolean_value)
int encode_context_boolean(uint8_t * apdu, int tag_number, bool boolean_value)
{
apdu[0] = boolean_value ? 1 : 0;
int len = 1; /* return value */
return 1;
apdu[1] = boolean_value ? 1 : 0;
/* we only reserved 1 byte for encoding the tag - check the limits */
if (tag_number <= 14)
len += encode_tag(&apdu[0], (uint8_t) tag_number, true, 1);
else
len = 0;
return len;
}
bool decode_context_boolean(uint8_t * apdu)
@@ -933,6 +940,21 @@ int encode_tagged_real(uint8_t * apdu, float value)
return len;
}
int encode_context_real(uint8_t * apdu, int tag_number, float value)
{
int len = 0;
/* assumes that the tag only consumes 1 octet */
len = encode_bacnet_real(value, &apdu[1]);
/* we only reserved 1 byte for encoding the tag - check the limits */
if (tag_number <= 14)
len += encode_tag(&apdu[0], (uint8_t) tag_number, true, len);
else
len = 0;
return len;
}
/* from clause 20.2.14 Encoding of an Object Identifier Value */
/* returns the number of apdu bytes consumed */
int decode_object_id(uint8_t * apdu, int *object_type, uint32_t * instance)
+3 -1
View File
@@ -70,7 +70,8 @@ extern "C" {
/* from clause 20.2.3 Encoding of a Boolean Value */
int encode_tagged_boolean(uint8_t * apdu, bool boolean_value);
bool decode_boolean(uint32_t len_value);
int encode_context_boolean(uint8_t * apdu, bool boolean_value);
int encode_context_boolean(uint8_t * apdu, int tag_number,
bool boolean_value);
bool decode_context_boolean(uint8_t * apdu);
/* from clause 20.2.10 Encoding of a Bit String Value */
@@ -88,6 +89,7 @@ extern "C" {
int decode_real(uint8_t * apdu, float *real_value);
int encode_bacnet_real(float value, uint8_t * apdu);
int encode_tagged_real(uint8_t * apdu, float value);
int encode_context_real(uint8_t * apdu, int tag_number, float value);
/* from clause 20.2.14 Encoding of an Object Identifier Value */
/* and 20.2.1 General Rules for Encoding BACnet Tags */