indented.

This commit is contained in:
skarg
2006-08-13 00:57:17 +00:00
parent 5bb205dc03
commit a30d497669
41 changed files with 574 additions and 573 deletions
+1 -2
View File
@@ -272,8 +272,7 @@ uint16_t apdu_decode_confirmed_service_request(uint8_t * apdu, /* APDU data */
return len; return len;
} }
void apdu_handler(BACNET_ADDRESS * src, void apdu_handler(BACNET_ADDRESS * src, uint8_t * apdu, /* APDU data */
uint8_t * apdu, /* APDU data */
uint16_t apdu_len) uint16_t apdu_len)
{ {
BACNET_CONFIRMED_SERVICE_DATA service_data = { 0 }; BACNET_CONFIRMED_SERVICE_DATA service_data = { 0 };
+1 -1
View File
@@ -149,7 +149,7 @@ extern "C" {
uint8_t ** service_request, uint16_t * service_request_len); uint8_t ** service_request, uint16_t * service_request_len);
void apdu_handler(BACNET_ADDRESS * src, /* source address */ void apdu_handler(BACNET_ADDRESS * src, /* source address */
uint8_t * apdu, /* APDU data */ uint8_t * apdu, /* APDU data */
uint16_t pdu_len); /* for confirmed messages */ uint16_t pdu_len); /* for confirmed messages */
#ifdef __cplusplus #ifdef __cplusplus
+55 -58
View File
@@ -48,65 +48,61 @@ int bacapp_encode_application_data(uint8_t * apdu,
{ {
int apdu_len = 0; /* total length of the apdu, return value */ int apdu_len = 0; /* total length of the apdu, return value */
if (value && apdu) if (value && apdu) {
{
switch (value->tag) { switch (value->tag) {
case BACNET_APPLICATION_TAG_NULL: case BACNET_APPLICATION_TAG_NULL:
apdu[0] = value->tag; apdu[0] = value->tag;
apdu_len++; apdu_len++;
break; break;
case BACNET_APPLICATION_TAG_BOOLEAN: case BACNET_APPLICATION_TAG_BOOLEAN:
apdu_len = encode_tagged_boolean(&apdu[0], apdu_len = encode_tagged_boolean(&apdu[0],
value->type.Boolean); value->type.Boolean);
break; break;
case BACNET_APPLICATION_TAG_UNSIGNED_INT: case BACNET_APPLICATION_TAG_UNSIGNED_INT:
apdu_len = encode_tagged_unsigned(&apdu[0], apdu_len = encode_tagged_unsigned(&apdu[0],
value->type.Unsigned_Int); value->type.Unsigned_Int);
break; break;
case BACNET_APPLICATION_TAG_SIGNED_INT: case BACNET_APPLICATION_TAG_SIGNED_INT:
apdu_len = encode_tagged_signed(&apdu[0], apdu_len = encode_tagged_signed(&apdu[0],
value->type.Signed_Int); value->type.Signed_Int);
break; break;
case BACNET_APPLICATION_TAG_REAL: case BACNET_APPLICATION_TAG_REAL:
apdu_len = encode_tagged_real(&apdu[0], apdu_len = encode_tagged_real(&apdu[0], value->type.Real);
value->type.Real); break;
break; case BACNET_APPLICATION_TAG_ENUMERATED:
case BACNET_APPLICATION_TAG_ENUMERATED: apdu_len = encode_tagged_enumerated(&apdu[0],
apdu_len = encode_tagged_enumerated(&apdu[0], value->type.Enumerated);
value->type.Enumerated); break;
break; case BACNET_APPLICATION_TAG_DATE:
case BACNET_APPLICATION_TAG_DATE: apdu_len = encode_tagged_date(&apdu[0], &value->type.Date);
apdu_len = encode_tagged_date(&apdu[0], break;
&value->type.Date); case BACNET_APPLICATION_TAG_TIME:
break; apdu_len = encode_tagged_time(&apdu[0], &value->type.Time);
case BACNET_APPLICATION_TAG_TIME: break;
apdu_len = encode_tagged_time(&apdu[0], case BACNET_APPLICATION_TAG_OBJECT_ID:
&value->type.Time); apdu_len = encode_tagged_object_id(&apdu[0],
break; value->type.Object_Id.type,
case BACNET_APPLICATION_TAG_OBJECT_ID: value->type.Object_Id.instance);
apdu_len = encode_tagged_object_id(&apdu[0], break;
value->type.Object_Id.type, case BACNET_APPLICATION_TAG_OCTET_STRING:
value->type.Object_Id.instance); apdu_len = encode_tagged_octet_string(&apdu[0],
break; &value->type.Octet_String);
case BACNET_APPLICATION_TAG_OCTET_STRING: break;
apdu_len = encode_tagged_octet_string(&apdu[0], case BACNET_APPLICATION_TAG_CHARACTER_STRING:
&value->type.Octet_String); apdu_len = encode_tagged_character_string(&apdu[0],
break; &value->type.Character_String);
case BACNET_APPLICATION_TAG_CHARACTER_STRING: break;
apdu_len = encode_tagged_character_string(&apdu[0], case BACNET_APPLICATION_TAG_BIT_STRING:
&value->type.Character_String); apdu_len = encode_tagged_bitstring(&apdu[0],
break; &value->type.Bit_String);
case BACNET_APPLICATION_TAG_BIT_STRING: break;
apdu_len = encode_tagged_bitstring(&apdu[0], case BACNET_APPLICATION_TAG_DOUBLE:
&value->type.Bit_String); /* FIXME: double is not implemented yet.
break; apdu_len = encode_tagged_double(&apdu[0],
case BACNET_APPLICATION_TAG_DOUBLE: value->type.Double);
/* FIXME: double is not implemented yet. */
apdu_len = encode_tagged_double(&apdu[0], default:
value->type.Double); break;
*/
default:
break;
} }
} }
@@ -491,6 +487,7 @@ bool bacapp_same_time(BACNET_TIME * time1, BACNET_TIME * time2)
return status; return status;
} }
/* generic - can be used by other unit tests /* generic - can be used by other unit tests
returns true if matching or same, false if different */ returns true if matching or same, false if different */
bool bacapp_same_value(BACNET_APPLICATION_DATA_VALUE * value, bool bacapp_same_value(BACNET_APPLICATION_DATA_VALUE * value,
+5 -5
View File
@@ -73,11 +73,11 @@ extern "C" {
BACNET_APPLICATION_DATA_VALUE * src_value); BACNET_APPLICATION_DATA_VALUE * src_value);
#if PRINT_ENABLED #if PRINT_ENABLED
#define BACAPP_PRINT_ENABLED #define BACAPP_PRINT_ENABLED
#else #else
#ifdef TEST #ifdef TEST
#define BACAPP_PRINT_ENABLED #define BACAPP_PRINT_ENABLED
#endif #endif
#endif #endif
#ifdef BACAPP_PRINT_ENABLED #ifdef BACAPP_PRINT_ENABLED
@@ -96,7 +96,7 @@ extern "C" {
bool bacapp_same_value(BACNET_APPLICATION_DATA_VALUE * value, bool bacapp_same_value(BACNET_APPLICATION_DATA_VALUE * value,
BACNET_APPLICATION_DATA_VALUE * test_value); BACNET_APPLICATION_DATA_VALUE * test_value);
void testBACnetApplicationData(Test * pTest); void testBACnetApplicationData(Test * pTest);
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
+42 -42
View File
@@ -195,13 +195,13 @@ int encode_unsigned16(uint8_t * apdu, uint16_t value)
0}}; 0}};
short_data.value = value; short_data.value = value;
#if BIG_ENDIAN #if BIG_ENDIAN
apdu[0] = short_data.byte[0]; apdu[0] = short_data.byte[0];
apdu[1] = short_data.byte[1]; apdu[1] = short_data.byte[1];
#else #else
apdu[0] = short_data.byte[1]; apdu[0] = short_data.byte[1];
apdu[1] = short_data.byte[0]; apdu[1] = short_data.byte[0];
#endif #endif
return 2; return 2;
} }
@@ -214,13 +214,13 @@ int decode_unsigned16(uint8_t * apdu, uint16_t * value)
} short_data = { { } short_data = { {
0}}; 0}};
#if BIG_ENDIAN #if BIG_ENDIAN
short_data.byte[0] = apdu[0]; short_data.byte[0] = apdu[0];
short_data.byte[1] = apdu[1]; short_data.byte[1] = apdu[1];
#else #else
short_data.byte[1] = apdu[0]; short_data.byte[1] = apdu[0];
short_data.byte[0] = apdu[1]; short_data.byte[0] = apdu[1];
#endif #endif
if (value) if (value)
*value = short_data.value; *value = short_data.value;
@@ -236,15 +236,15 @@ int encode_unsigned24(uint8_t * apdu, uint32_t value)
0}}; 0}};
long_data.value = value; long_data.value = value;
#if BIG_ENDIAN #if BIG_ENDIAN
apdu[0] = long_data.byte[1]; apdu[0] = long_data.byte[1];
apdu[1] = long_data.byte[2]; apdu[1] = long_data.byte[2];
apdu[2] = long_data.byte[3]; apdu[2] = long_data.byte[3];
#else #else
apdu[0] = long_data.byte[2]; apdu[0] = long_data.byte[2];
apdu[1] = long_data.byte[1]; apdu[1] = long_data.byte[1];
apdu[2] = long_data.byte[0]; apdu[2] = long_data.byte[0];
#endif #endif
return 3; return 3;
} }
@@ -257,15 +257,15 @@ int decode_unsigned24(uint8_t * apdu, uint32_t * value)
} long_data = { { } long_data = { {
0}}; 0}};
#if BIG_ENDIAN #if BIG_ENDIAN
long_data.byte[1] = apdu[0]; long_data.byte[1] = apdu[0];
long_data.byte[2] = apdu[1]; long_data.byte[2] = apdu[1];
long_data.byte[3] = apdu[2]; long_data.byte[3] = apdu[2];
#else #else
long_data.byte[2] = apdu[0]; long_data.byte[2] = apdu[0];
long_data.byte[1] = apdu[1]; long_data.byte[1] = apdu[1];
long_data.byte[0] = apdu[2]; long_data.byte[0] = apdu[2];
#endif #endif
if (value) if (value)
*value = long_data.value; *value = long_data.value;
@@ -281,17 +281,17 @@ int encode_unsigned32(uint8_t * apdu, uint32_t value)
0}}; 0}};
long_data.value = value; long_data.value = value;
#if BIG_ENDIAN #if BIG_ENDIAN
apdu[0] = long_data.byte[0]; apdu[0] = long_data.byte[0];
apdu[1] = long_data.byte[1]; apdu[1] = long_data.byte[1];
apdu[2] = long_data.byte[2]; apdu[2] = long_data.byte[2];
apdu[3] = long_data.byte[3]; apdu[3] = long_data.byte[3];
#else #else
apdu[0] = long_data.byte[3]; apdu[0] = long_data.byte[3];
apdu[1] = long_data.byte[2]; apdu[1] = long_data.byte[2];
apdu[2] = long_data.byte[1]; apdu[2] = long_data.byte[1];
apdu[3] = long_data.byte[0]; apdu[3] = long_data.byte[0];
#endif #endif
return 4; return 4;
} }
@@ -304,17 +304,17 @@ int decode_unsigned32(uint8_t * apdu, uint32_t * value)
} long_data = { { } long_data = { {
0}}; 0}};
#if BIG_ENDIAN #if BIG_ENDIAN
long_data.byte[0] = apdu[0]; long_data.byte[0] = apdu[0];
long_data.byte[1] = apdu[1]; long_data.byte[1] = apdu[1];
long_data.byte[2] = apdu[2]; long_data.byte[2] = apdu[2];
long_data.byte[3] = apdu[3]; long_data.byte[3] = apdu[3];
#else #else
long_data.byte[3] = apdu[0]; long_data.byte[3] = apdu[0];
long_data.byte[2] = apdu[1]; long_data.byte[2] = apdu[1];
long_data.byte[1] = apdu[2]; long_data.byte[1] = apdu[2];
long_data.byte[0] = apdu[3]; long_data.byte[0] = apdu[3];
#endif #endif
if (value) if (value)
*value = long_data.value; *value = long_data.value;
@@ -359,13 +359,13 @@ int encode_signed16(uint8_t * apdu, int16_t value)
0}}; 0}};
short_data.value = value; short_data.value = value;
#if BIG_ENDIAN #if BIG_ENDIAN
apdu[0] = short_data.byte[0]; apdu[0] = short_data.byte[0];
apdu[1] = short_data.byte[1]; apdu[1] = short_data.byte[1];
#else #else
apdu[0] = short_data.byte[1]; apdu[0] = short_data.byte[1];
apdu[1] = short_data.byte[0]; apdu[1] = short_data.byte[0];
#endif #endif
return 2; return 2;
} }
@@ -378,13 +378,13 @@ int decode_signed16(uint8_t * apdu, int16_t * value)
} short_data = { { } short_data = { {
0}}; 0}};
#if BIG_ENDIAN #if BIG_ENDIAN
short_data.byte[0] = apdu[0]; short_data.byte[0] = apdu[0];
short_data.byte[1] = apdu[1]; short_data.byte[1] = apdu[1];
#else #else
short_data.byte[1] = apdu[0]; short_data.byte[1] = apdu[0];
short_data.byte[0] = apdu[1]; short_data.byte[0] = apdu[1];
#endif #endif
if (value) if (value)
*value = short_data.value; *value = short_data.value;
@@ -400,15 +400,15 @@ int encode_signed24(uint8_t * apdu, int32_t value)
0}}; 0}};
long_data.value = value; long_data.value = value;
#if BIG_ENDIAN #if BIG_ENDIAN
apdu[0] = long_data.byte[1]; apdu[0] = long_data.byte[1];
apdu[1] = long_data.byte[2]; apdu[1] = long_data.byte[2];
apdu[2] = long_data.byte[3]; apdu[2] = long_data.byte[3];
#else #else
apdu[0] = long_data.byte[2]; apdu[0] = long_data.byte[2];
apdu[1] = long_data.byte[1]; apdu[1] = long_data.byte[1];
apdu[2] = long_data.byte[0]; apdu[2] = long_data.byte[0];
#endif #endif
return 3; return 3;
} }
@@ -421,7 +421,7 @@ int decode_signed24(uint8_t * apdu, int32_t * value)
} long_data = { { } long_data = { {
0}}; 0}};
#if BIG_ENDIAN #if BIG_ENDIAN
/* negative - bit 7 is set */ /* negative - bit 7 is set */
if (apdu[0] & 0x80) if (apdu[0] & 0x80)
long_data.byte[0] = 0xFF; long_data.byte[0] = 0xFF;
@@ -429,7 +429,7 @@ int decode_signed24(uint8_t * apdu, int32_t * value)
long_data.byte[1] = apdu[0]; long_data.byte[1] = apdu[0];
long_data.byte[2] = apdu[1]; long_data.byte[2] = apdu[1];
long_data.byte[3] = apdu[2]; long_data.byte[3] = apdu[2];
#else #else
/* negative - bit 7 is set */ /* negative - bit 7 is set */
if (apdu[0] & 0x80) if (apdu[0] & 0x80)
long_data.byte[3] = 0xFF; long_data.byte[3] = 0xFF;
@@ -437,7 +437,7 @@ int decode_signed24(uint8_t * apdu, int32_t * value)
long_data.byte[2] = apdu[0]; long_data.byte[2] = apdu[0];
long_data.byte[1] = apdu[1]; long_data.byte[1] = apdu[1];
long_data.byte[0] = apdu[2]; long_data.byte[0] = apdu[2];
#endif #endif
if (value) if (value)
*value = long_data.value; *value = long_data.value;
@@ -453,17 +453,17 @@ int encode_signed32(uint8_t * apdu, int32_t value)
0}}; 0}};
long_data.value = value; long_data.value = value;
#if BIG_ENDIAN #if BIG_ENDIAN
apdu[0] = long_data.byte[0]; apdu[0] = long_data.byte[0];
apdu[1] = long_data.byte[1]; apdu[1] = long_data.byte[1];
apdu[2] = long_data.byte[2]; apdu[2] = long_data.byte[2];
apdu[3] = long_data.byte[3]; apdu[3] = long_data.byte[3];
#else #else
apdu[0] = long_data.byte[3]; apdu[0] = long_data.byte[3];
apdu[1] = long_data.byte[2]; apdu[1] = long_data.byte[2];
apdu[2] = long_data.byte[1]; apdu[2] = long_data.byte[1];
apdu[3] = long_data.byte[0]; apdu[3] = long_data.byte[0];
#endif #endif
return 4; return 4;
} }
@@ -476,17 +476,17 @@ int decode_signed32(uint8_t * apdu, int32_t * value)
} long_data = { { } long_data = { {
0}}; 0}};
#if BIG_ENDIAN #if BIG_ENDIAN
long_data.byte[0] = apdu[0]; long_data.byte[0] = apdu[0];
long_data.byte[1] = apdu[1]; long_data.byte[1] = apdu[1];
long_data.byte[2] = apdu[2]; long_data.byte[2] = apdu[2];
long_data.byte[3] = apdu[3]; long_data.byte[3] = apdu[3];
#else #else
long_data.byte[3] = apdu[0]; long_data.byte[3] = apdu[0];
long_data.byte[2] = apdu[1]; long_data.byte[2] = apdu[1];
long_data.byte[1] = apdu[2]; long_data.byte[1] = apdu[2];
long_data.byte[0] = apdu[3]; long_data.byte[0] = apdu[3];
#endif #endif
if (value) if (value)
*value = long_data.value; *value = long_data.value;
@@ -876,17 +876,17 @@ int decode_real(uint8_t * apdu, float *real_value)
} my_data; } my_data;
/* NOTE: assumes the compiler stores float as IEEE-754 float */ /* NOTE: assumes the compiler stores float as IEEE-754 float */
#if BIG_ENDIAN #if BIG_ENDIAN
my_data.byte[0] = apdu[0]; my_data.byte[0] = apdu[0];
my_data.byte[1] = apdu[1]; my_data.byte[1] = apdu[1];
my_data.byte[2] = apdu[2]; my_data.byte[2] = apdu[2];
my_data.byte[3] = apdu[3]; my_data.byte[3] = apdu[3];
#else #else
my_data.byte[0] = apdu[3]; my_data.byte[0] = apdu[3];
my_data.byte[1] = apdu[2]; my_data.byte[1] = apdu[2];
my_data.byte[2] = apdu[1]; my_data.byte[2] = apdu[1];
my_data.byte[3] = apdu[0]; my_data.byte[3] = apdu[0];
#endif #endif
*real_value = my_data.real_value; *real_value = my_data.real_value;
@@ -904,17 +904,17 @@ int encode_bacnet_real(float value, uint8_t * apdu)
/* NOTE: assumes the compiler stores float as IEEE-754 float */ /* NOTE: assumes the compiler stores float as IEEE-754 float */
my_data.real_value = value; my_data.real_value = value;
#if BIG_ENDIAN #if BIG_ENDIAN
apdu[0] = my_data.byte[0]; apdu[0] = my_data.byte[0];
apdu[1] = my_data.byte[1]; apdu[1] = my_data.byte[1];
apdu[2] = my_data.byte[2]; apdu[2] = my_data.byte[2];
apdu[3] = my_data.byte[3]; apdu[3] = my_data.byte[3];
#else #else
apdu[0] = my_data.byte[3]; apdu[0] = my_data.byte[3];
apdu[1] = my_data.byte[2]; apdu[1] = my_data.byte[2];
apdu[2] = my_data.byte[1]; apdu[2] = my_data.byte[1];
apdu[3] = my_data.byte[0]; apdu[3] = my_data.byte[0];
#endif #endif
return 4; return 4;
} }
+5 -7
View File
@@ -36,11 +36,11 @@
/* tiny implementations have no need to print */ /* tiny implementations have no need to print */
#if PRINT_ENABLED #if PRINT_ENABLED
#define BACTEXT_PRINT_ENABLED #define BACTEXT_PRINT_ENABLED
#else #else
#ifdef TEST #ifdef TEST
#define BACTEXT_PRINT_ENABLED #define BACTEXT_PRINT_ENABLED
#endif #endif
#endif #endif
#ifdef BACTEXT_PRINT_ENABLED #ifdef BACTEXT_PRINT_ENABLED
@@ -77,7 +77,5 @@ extern "C" {
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif /* BACTEXT_PRINT_ENABLED */
#endif /* BACTEXT_PRINT_ENABLED */
#endif #endif
+3 -3
View File
@@ -139,7 +139,7 @@ uint16_t bip_get_port(void)
/* function to send a packet out the BACnet/IP socket (Annex J) */ /* function to send a packet out the BACnet/IP socket (Annex J) */
/* returns number of bytes sent on success, negative number on failure */ /* returns number of bytes sent on success, negative number on failure */
int bip_send_pdu(BACNET_ADDRESS * dest, /* destination address */ int bip_send_pdu(BACNET_ADDRESS * dest, /* destination address */
BACNET_NPDU_DATA * npdu_data, /* network information */ BACNET_NPDU_DATA * npdu_data, /* network information */
uint8_t * pdu, /* any data to be sent - may be null */ uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len) unsigned pdu_len)
{ /* number of bytes of data */ { /* number of bytes of data */
@@ -152,7 +152,7 @@ int bip_send_pdu(BACNET_ADDRESS * dest, /* destination address */
/* assumes that the driver has already been initialized */ /* assumes that the driver has already been initialized */
if (BIP_Socket < 0) if (BIP_Socket < 0)
return BIP_Socket; return BIP_Socket;
mtu[0] = BVLL_TYPE_BACNET_IP; mtu[0] = BVLL_TYPE_BACNET_IP;
bip_dest.sin_family = AF_INET; bip_dest.sin_family = AF_INET;
if (dest->mac_len == 6) { if (dest->mac_len == 6) {
@@ -177,7 +177,7 @@ int bip_send_pdu(BACNET_ADDRESS * dest, /* destination address */
mtu_len += 4; mtu_len += 4;
memcpy(&mtu[mtu_len], pdu, pdu_len); memcpy(&mtu[mtu_len], pdu, pdu_len);
mtu_len += pdu_len; mtu_len += pdu_len;
encode_unsigned16(&mtu[2],mtu_len); encode_unsigned16(&mtu[2], mtu_len);
/* Send the packet */ /* Send the packet */
bytes_sent = sendto(BIP_Socket, (char *) mtu, mtu_len, 0, bytes_sent = sendto(BIP_Socket, (char *) mtu, mtu_len, 0,
+1 -1
View File
@@ -65,7 +65,7 @@ extern "C" {
/* function to send a packet out the BACnet/IP socket */ /* function to send a packet out the BACnet/IP socket */
/* returns zero on success, non-zero on failure */ /* returns zero on success, non-zero on failure */
int bip_send_pdu(BACNET_ADDRESS * dest, /* destination address */ int bip_send_pdu(BACNET_ADDRESS * dest, /* destination address */
BACNET_NPDU_DATA * npdu_data, /* network information */ BACNET_NPDU_DATA * npdu_data, /* network information */
uint8_t * pdu, /* any data to be sent - may be null */ uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len); /* number of bytes of data */ unsigned pdu_len); /* number of bytes of data */
+1 -1
View File
@@ -360,7 +360,7 @@ void npdu_encode_unconfirmed_apdu(BACNET_NPDU_DATA * npdu,
/* dummy function stubs */ /* dummy function stubs */
int datalink_send_pdu(BACNET_ADDRESS * dest, /* destination address */ int datalink_send_pdu(BACNET_ADDRESS * dest, /* destination address */
BACNET_NPDU_DATA * npdu_data, /* network information */ BACNET_NPDU_DATA * npdu_data, /* network information */
uint8_t * pdu, /* any data to be sent - may be null */ uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len) unsigned pdu_len)
{ /* number of bytes of data */ { /* number of bytes of data */
+1 -1
View File
@@ -42,7 +42,7 @@
/* returns number of bytes sent on success, negative on failure */ /* returns number of bytes sent on success, negative on failure */
int datalink_send_pdu(BACNET_ADDRESS * dest, /* destination address */ int datalink_send_pdu(BACNET_ADDRESS * dest, /* destination address */
BACNET_NPDU_DATA * npdu_data, /* network information */ BACNET_NPDU_DATA * npdu_data, /* network information */
uint8_t * pdu, /* any data to be sent - may be null */ uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len) unsigned pdu_len)
{ /* number of bytes of data */ { /* number of bytes of data */
+1 -1
View File
@@ -62,7 +62,7 @@ extern "C" {
/* returns number of bytes sent on success, negative on failure */ /* returns number of bytes sent on success, negative on failure */
int datalink_send_pdu(BACNET_ADDRESS * dest, /* destination address */ int datalink_send_pdu(BACNET_ADDRESS * dest, /* destination address */
BACNET_NPDU_DATA * npdu_data, /* network information */ BACNET_NPDU_DATA * npdu_data, /* network information */
uint8_t * pdu, /* any data to be sent - may be null */ uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len); /* number of bytes of data */ unsigned pdu_len); /* number of bytes of data */
+19 -16
View File
@@ -52,31 +52,32 @@ void handler_atomic_read_file(uint8_t * service_request,
int bytes_sent = 0; int bytes_sent = 0;
BACNET_NPDU_DATA npdu_data; BACNET_NPDU_DATA npdu_data;
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Received Atomic-Read-File Request!\n"); fprintf(stderr, "Received Atomic-Read-File Request!\n");
#endif #endif
len = arf_decode_service_request(service_request, service_len, &data); len = arf_decode_service_request(service_request, service_len, &data);
/* prepare a reply */ /* prepare a reply */
/* bad decoding - send an abort */ /* bad decoding - send an abort */
if (len < 0) { if (len < 0) {
pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0], pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, ABORT_REASON_OTHER); service_data->invoke_id, ABORT_REASON_OTHER);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Bad Encoding. Sending Abort!\n"); fprintf(stderr, "Bad Encoding. Sending Abort!\n");
#endif #endif
} else if (service_data->segmented_message) { } else if (service_data->segmented_message) {
pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0], pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Segmented Message. Sending Abort!\n"); fprintf(stderr, "Segmented Message. Sending Abort!\n");
#endif #endif
} else { } else {
if (data.access == FILE_STREAM_ACCESS) { if (data.access == FILE_STREAM_ACCESS) {
if (data.type.stream.requestedOctetCount < if (data.type.stream.requestedOctetCount <
octetstring_capacity(&data.fileData)) { octetstring_capacity(&data.fileData)) {
if (bacfile_read_data(&data)) { if (bacfile_read_data(&data)) {
pdu_len = arf_ack_encode_apdu(&Handler_Transmit_Buffer[0], pdu_len =
arf_ack_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, &data); service_data->invoke_id, &data);
} else { } else {
error = true; error = true;
@@ -86,27 +87,29 @@ void handler_atomic_read_file(uint8_t * service_request,
abort_encode_apdu(&Handler_Transmit_Buffer[0], abort_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Too Big To Send. Sending Abort!\n"); fprintf(stderr, "Too Big To Send. Sending Abort!\n");
#endif #endif
} }
} else { } else {
pdu_len = bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len =
service_data->invoke_id, SERVICE_CONFIRMED_ATOMIC_READ_FILE, bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
ERROR_CLASS_SERVICES, ERROR_CODE_INVALID_FILE_ACCESS_METHOD); service_data->invoke_id,
#if PRINT_ENABLED SERVICE_CONFIRMED_ATOMIC_READ_FILE, ERROR_CLASS_SERVICES,
ERROR_CODE_INVALID_FILE_ACCESS_METHOD);
#if PRINT_ENABLED
fprintf(stderr, "Record Access Requested. Sending Error!\n"); fprintf(stderr, "Record Access Requested. Sending Error!\n");
#endif #endif
} }
} }
npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
bytes_sent = datalink_send_pdu(src, &npdu_data, bytes_sent = datalink_send_pdu(src, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len); &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) { if (bytes_sent <= 0) {
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
} }
#endif #endif
return; return;
} }
+5 -6
View File
@@ -62,9 +62,9 @@ void handler_atomic_read_file_ack(uint8_t * service_request,
instance = bacfile_instance_from_tsm(service_data->invoke_id); instance = bacfile_instance_from_tsm(service_data->invoke_id);
len = arf_ack_decode_service_request(service_request, len = arf_ack_decode_service_request(service_request,
service_len, &data); service_len, &data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Received Read-File Ack!\n"); fprintf(stderr, "Received Read-File Ack!\n");
#endif #endif
if ((len > 0) && (instance <= BACNET_MAX_INSTANCE)) { if ((len > 0) && (instance <= BACNET_MAX_INSTANCE)) {
/* write the data received to the file specified */ /* write the data received to the file specified */
if (data.access == FILE_STREAM_ACCESS) { if (data.access == FILE_STREAM_ACCESS) {
@@ -76,12 +76,11 @@ void handler_atomic_read_file_ack(uint8_t * service_request,
data.type.stream.fileStartPosition, SEEK_SET); data.type.stream.fileStartPosition, SEEK_SET);
if (fwrite(octetstring_value(&data.fileData), if (fwrite(octetstring_value(&data.fileData),
octetstring_length(&data.fileData), 1, octetstring_length(&data.fileData), 1,
pFile) != 1) pFile) != 1) {
{ #if PRINT_ENABLED
#if PRINT_ENABLED
fprintf(stderr, "Failed to write to %s (%u)!\n", fprintf(stderr, "Failed to write to %s (%u)!\n",
pFilename, instance); pFilename, instance);
#endif #endif
} }
fclose(pFile); fclose(pFile);
} }
+14 -14
View File
@@ -55,46 +55,46 @@ void handler_device_communication_control(uint8_t * service_request,
/* decode the service request only */ /* decode the service request only */
len = dcc_decode_service_request(service_request, len = dcc_decode_service_request(service_request,
service_len, &timeDuration, &state, &password); service_len, &timeDuration, &state, &password);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "DeviceCommunicationControl!\n"); fprintf(stderr, "DeviceCommunicationControl!\n");
if (len > 0) if (len > 0)
fprintf(stderr, "DeviceCommunicationControl: " fprintf(stderr, "DeviceCommunicationControl: "
"timeout=%u state=%u password=%s\n", "timeout=%u state=%u password=%s\n",
(unsigned) timeDuration, (unsigned) timeDuration,
(unsigned) state, characterstring_value(&password)); (unsigned) state, characterstring_value(&password));
#endif #endif
/* bad decoding or something we didn't understand - send an abort */ /* bad decoding or something we didn't understand - send an abort */
if (len < 0) { if (len < 0) {
pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0], pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, ABORT_REASON_OTHER); service_data->invoke_id, ABORT_REASON_OTHER);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "DeviceCommunicationControl: " fprintf(stderr, "DeviceCommunicationControl: "
"Sending Abort - could not decode.\n"); "Sending Abort - could not decode.\n");
#endif #endif
} else if (service_data->segmented_message) { } else if (service_data->segmented_message) {
pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0], pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "DeviceCommunicationControl: " fprintf(stderr, "DeviceCommunicationControl: "
"Sending Abort - segmented message.\n"); "Sending Abort - segmented message.\n");
#endif #endif
} else if (state >= MAX_BACNET_COMMUNICATION_ENABLE_DISABLE) { } else if (state >= MAX_BACNET_COMMUNICATION_ENABLE_DISABLE) {
pdu_len = reject_encode_apdu(&Handler_Transmit_Buffer[0], pdu_len = reject_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, REJECT_REASON_UNDEFINED_ENUMERATION); service_data->invoke_id, REJECT_REASON_UNDEFINED_ENUMERATION);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "DeviceCommunicationControl: " fprintf(stderr, "DeviceCommunicationControl: "
"Sending Reject - undefined enumeration\n"); "Sending Reject - undefined enumeration\n");
#endif #endif
} else { } else {
if (characterstring_ansi_same(&password, My_Password)) { if (characterstring_ansi_same(&password, My_Password)) {
pdu_len = encode_simple_ack(&Handler_Transmit_Buffer[0], pdu_len = encode_simple_ack(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL); SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "DeviceCommunicationControl: " fprintf(stderr, "DeviceCommunicationControl: "
"Sending Simple Ack!\n"); "Sending Simple Ack!\n");
#endif #endif
dcc_set_status_duration(state, timeDuration); dcc_set_status_duration(state, timeDuration);
} else { } else {
pdu_len = pdu_len =
@@ -102,21 +102,21 @@ void handler_device_communication_control(uint8_t * service_request,
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
ERROR_CLASS_SERVICES, ERROR_CODE_PASSWORD_FAILURE); ERROR_CLASS_SERVICES, ERROR_CODE_PASSWORD_FAILURE);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"DeviceCommunicationControl: " "DeviceCommunicationControl: "
"Sending Error - password failure.\n"); "Sending Error - password failure.\n");
#endif #endif
} }
} }
npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
bytes_sent = datalink_send_pdu(src, &npdu_data, bytes_sent = datalink_send_pdu(src, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len); &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "DeviceCommunicationControl: " fprintf(stderr, "DeviceCommunicationControl: "
"Failed to send PDU (%s)!\n", strerror(errno)); "Failed to send PDU (%s)!\n", strerror(errno));
#endif #endif
return; return;
} }
+6 -6
View File
@@ -44,18 +44,18 @@ void handler_i_am_add(uint8_t * service_request,
(void) service_len; (void) service_len;
len = iam_decode_service_request(service_request, len = iam_decode_service_request(service_request,
&device_id, &max_apdu, &segmentation, &vendor_id); &device_id, &max_apdu, &segmentation, &vendor_id);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Received I-Am Request"); fprintf(stderr, "Received I-Am Request");
#endif #endif
if (len != -1) { if (len != -1) {
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, " from %u!\n", device_id); fprintf(stderr, " from %u!\n", device_id);
#endif #endif
address_add(device_id, max_apdu, src); address_add(device_id, max_apdu, src);
} else { } else {
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "!\n"); fprintf(stderr, "!\n");
#endif #endif
} }
return; return;
+4 -4
View File
@@ -43,17 +43,17 @@ void handler_i_have(uint8_t * service_request,
len = ihave_decode_service_request(service_request, len = ihave_decode_service_request(service_request,
service_len, &data); service_len, &data);
if (len != -1) { if (len != -1) {
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "I-Have: %s %d from %s %u!\r\n", fprintf(stderr, "I-Have: %s %d from %s %u!\r\n",
bactext_object_type_name(data.object_id.type), bactext_object_type_name(data.object_id.type),
data.object_id.instance, data.object_id.instance,
bactext_object_type_name(data.device_id.type), bactext_object_type_name(data.device_id.type),
data.device_id.instance); data.device_id.instance);
#endif #endif
} else { } else {
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "I-Have: received, but unable to decode!\n"); fprintf(stderr, "I-Have: received, but unable to decode!\n");
#endif #endif
} }
return; return;
+14 -14
View File
@@ -55,46 +55,46 @@ void handler_reinitialize_device(uint8_t * service_request,
/* decode the service request only */ /* decode the service request only */
len = rd_decode_service_request(service_request, len = rd_decode_service_request(service_request,
service_len, &state, &their_password); service_len, &state, &their_password);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "ReinitializeDevice!\n"); fprintf(stderr, "ReinitializeDevice!\n");
if (len > 0) if (len > 0)
fprintf(stderr, "ReinitializeDevice: state=%u password=%s\n", fprintf(stderr, "ReinitializeDevice: state=%u password=%s\n",
(unsigned) state, characterstring_value(&their_password)); (unsigned) state, characterstring_value(&their_password));
else else
fprintf(stderr, "ReinitializeDevice: Unable to decode request!\n"); fprintf(stderr, "ReinitializeDevice: Unable to decode request!\n");
#endif #endif
/* bad decoding or something we didn't understand - send an abort */ /* bad decoding or something we didn't understand - send an abort */
if (len < 0) { if (len < 0) {
pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0], pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, ABORT_REASON_OTHER); service_data->invoke_id, ABORT_REASON_OTHER);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"ReinitializeDevice: Sending Abort - could not decode.\n"); "ReinitializeDevice: Sending Abort - could not decode.\n");
#endif #endif
} else if (service_data->segmented_message) { } else if (service_data->segmented_message) {
pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0], pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"ReinitializeDevice: Sending Abort - segmented message.\n"); "ReinitializeDevice: Sending Abort - segmented message.\n");
#endif #endif
} else if (state >= MAX_BACNET_REINITIALIZED_STATE) { } else if (state >= MAX_BACNET_REINITIALIZED_STATE) {
pdu_len = reject_encode_apdu(&Handler_Transmit_Buffer[0], pdu_len = reject_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, REJECT_REASON_UNDEFINED_ENUMERATION); service_data->invoke_id, REJECT_REASON_UNDEFINED_ENUMERATION);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"ReinitializeDevice: Sending Reject - undefined enumeration\n"); "ReinitializeDevice: Sending Reject - undefined enumeration\n");
#endif #endif
} else { } else {
characterstring_init_ansi(&My_Password, Password); characterstring_init_ansi(&My_Password, Password);
if (characterstring_same(&their_password, &My_Password)) { if (characterstring_same(&their_password, &My_Password)) {
pdu_len = encode_simple_ack(&Handler_Transmit_Buffer[0], pdu_len = encode_simple_ack(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_REINITIALIZE_DEVICE); SERVICE_CONFIRMED_REINITIALIZE_DEVICE);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "ReinitializeDevice: Sending Simple Ack!\n"); fprintf(stderr, "ReinitializeDevice: Sending Simple Ack!\n");
#endif #endif
/* FIXME: now you can reboot, restart, quit, or something clever */ /* FIXME: now you can reboot, restart, quit, or something clever */
/* Note: you can use a mix of state and password to do specific stuff */ /* Note: you can use a mix of state and password to do specific stuff */
/* Note: if you don't do something clever like actually restart, /* Note: if you don't do something clever like actually restart,
@@ -105,20 +105,20 @@ void handler_reinitialize_device(uint8_t * service_request,
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_REINITIALIZE_DEVICE, SERVICE_CONFIRMED_REINITIALIZE_DEVICE,
ERROR_CLASS_SERVICES, ERROR_CODE_PASSWORD_FAILURE); ERROR_CLASS_SERVICES, ERROR_CODE_PASSWORD_FAILURE);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"ReinitializeDevice: Sending Error - password failure.\n"); "ReinitializeDevice: Sending Error - password failure.\n");
#endif #endif
} }
} }
npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
bytes_sent = datalink_send_pdu(src, &npdu_data, bytes_sent = datalink_send_pdu(src, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len); &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "ReinitializeDevice: Failed to send PDU (%s)!\n", fprintf(stderr, "ReinitializeDevice: Failed to send PDU (%s)!\n",
strerror(errno)); strerror(errno));
#endif #endif
return; return;
} }
+37 -36
View File
@@ -66,25 +66,25 @@ void handler_read_property(uint8_t * service_request,
BACNET_ERROR_CODE error_code = ERROR_CODE_UNKNOWN_OBJECT; BACNET_ERROR_CODE error_code = ERROR_CODE_UNKNOWN_OBJECT;
len = rp_decode_service_request(service_request, service_len, &data); len = rp_decode_service_request(service_request, service_len, &data);
#if PRINT_ENABLED #if PRINT_ENABLED
if (len <= 0) if (len <= 0)
fprintf(stderr, "Unable to decode Read-Property Request!\n"); fprintf(stderr, "Unable to decode Read-Property Request!\n");
#endif #endif
/* bad decoding - send an abort */ /* bad decoding - send an abort */
if (len < 0) { if (len < 0) {
pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0], pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, ABORT_REASON_OTHER); service_data->invoke_id, ABORT_REASON_OTHER);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Abort!\n"); fprintf(stderr, "Sending Abort!\n");
#endif #endif
send = true; send = true;
} else if (service_data->segmented_message) { } else if (service_data->segmented_message) {
pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0], pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Abort!\n"); fprintf(stderr, "Sending Abort!\n");
#endif #endif
send = true; send = true;
} else { } else {
switch (data.object_type) { switch (data.object_type) {
@@ -99,12 +99,13 @@ void handler_read_property(uint8_t * service_request,
data.application_data = &Temp_Buf[0]; data.application_data = &Temp_Buf[0];
data.application_data_len = len; data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */ /* FIXME: probably need a length limitation sent with encode */
pdu_len = rp_ack_encode_apdu(&Handler_Transmit_Buffer[0], pdu_len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, &data); service_data->invoke_id, &data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Sending Read Property Ack for Device!\n"); "Sending Read Property Ack for Device!\n");
#endif #endif
send = true; send = true;
} else } else
error = true; error = true;
@@ -125,9 +126,9 @@ void handler_read_property(uint8_t * service_request,
pdu_len = pdu_len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer[0], rp_ack_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, &data); service_data->invoke_id, &data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Read Property Ack for AI!\n"); fprintf(stderr, "Sending Read Property Ack for AI!\n");
#endif #endif
send = true; send = true;
} else } else
error = true; error = true;
@@ -148,9 +149,9 @@ void handler_read_property(uint8_t * service_request,
pdu_len = pdu_len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer[0], rp_ack_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, &data); service_data->invoke_id, &data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Read Property Ack for BI!\n"); fprintf(stderr, "Sending Read Property Ack for BI!\n");
#endif #endif
send = true; send = true;
} else } else
error = true; error = true;
@@ -168,11 +169,12 @@ void handler_read_property(uint8_t * service_request,
data.application_data = &Temp_Buf[0]; data.application_data = &Temp_Buf[0];
data.application_data_len = len; data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */ /* FIXME: probably need a length limitation sent with encode */
pdu_len = rp_ack_encode_apdu(&Handler_Transmit_Buffer[0], pdu_len =
service_data->invoke_id, &data); rp_ack_encode_apdu(&Handler_Transmit_Buffer[0],
#if PRINT_ENABLED service_data->invoke_id, &data);
#if PRINT_ENABLED
fprintf(stderr, "Sending Read Property Ack for BO!\n"); fprintf(stderr, "Sending Read Property Ack for BO!\n");
#endif #endif
send = true; send = true;
} else } else
error = true; error = true;
@@ -193,9 +195,9 @@ void handler_read_property(uint8_t * service_request,
pdu_len = pdu_len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer[0], rp_ack_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, &data); service_data->invoke_id, &data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Read Property Ack for BV!\n"); fprintf(stderr, "Sending Read Property Ack for BV!\n");
#endif #endif
send = true; send = true;
} else } else
error = true; error = true;
@@ -216,9 +218,9 @@ void handler_read_property(uint8_t * service_request,
pdu_len = pdu_len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer[0], rp_ack_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, &data); service_data->invoke_id, &data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Read Property Ack for AO!\n"); fprintf(stderr, "Sending Read Property Ack for AO!\n");
#endif #endif
send = true; send = true;
} else } else
error = true; error = true;
@@ -239,9 +241,9 @@ void handler_read_property(uint8_t * service_request,
pdu_len = pdu_len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer[0], rp_ack_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, &data); service_data->invoke_id, &data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Read Property Ack for AV!\n"); fprintf(stderr, "Sending Read Property Ack for AV!\n");
#endif #endif
send = true; send = true;
} else } else
error = true; error = true;
@@ -262,10 +264,10 @@ void handler_read_property(uint8_t * service_request,
pdu_len = pdu_len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer[0], rp_ack_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, &data); service_data->invoke_id, &data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Sending Read Property Ack for LSP!\n"); "Sending Read Property Ack for LSP!\n");
#endif #endif
send = true; send = true;
} else } else
error = true; error = true;
@@ -286,10 +288,10 @@ void handler_read_property(uint8_t * service_request,
pdu_len = pdu_len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer[0], rp_ack_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, &data); service_data->invoke_id, &data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Sending Read Property Ack for MSO!\n"); "Sending Read Property Ack for MSO!\n");
#endif #endif
send = true; send = true;
} else } else
error = true; error = true;
@@ -311,17 +313,17 @@ void handler_read_property(uint8_t * service_request,
pdu_len = pdu_len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer[0], rp_ack_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, &data); service_data->invoke_id, &data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Sending Read Property Ack for File!\n"); "Sending Read Property Ack for File!\n");
#endif #endif
send = true; send = true;
} else } else
error = true; error = true;
} else } else
error = true; error = true;
break; break;
#endif /* BACFILE */ #endif /* BACFILE */
default: default:
error = true; error = true;
break; break;
@@ -331,19 +333,18 @@ void handler_read_property(uint8_t * service_request,
pdu_len = bacerror_encode_apdu(&Handler_Transmit_Buffer[0], pdu_len = bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_READ_PROPERTY, error_class, error_code); SERVICE_CONFIRMED_READ_PROPERTY, error_class, error_code);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Read Property Error!\n"); fprintf(stderr, "Sending Read Property Error!\n");
#endif #endif
send = true; send = true;
} }
if (send) { if (send) {
npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
bytes_sent = datalink_send_pdu(src, &npdu_data, bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
&Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ #if PRINT_ENABLED
#if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
#endif #endif
} }
return; return;
+44 -44
View File
@@ -64,7 +64,7 @@ void handler_write_property(uint8_t * service_request,
/* decode the service request only */ /* decode the service request only */
len = wp_decode_service_request(service_request, len = wp_decode_service_request(service_request,
service_len, &wp_data); service_len, &wp_data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Received Write-Property Request!\n"); fprintf(stderr, "Received Write-Property Request!\n");
if (len > 0) if (len > 0)
fprintf(stderr, "type=%u instance=%u property=%u index=%d\n", fprintf(stderr, "type=%u instance=%u property=%u index=%d\n",
@@ -73,21 +73,21 @@ void handler_write_property(uint8_t * service_request,
wp_data.object_property, wp_data.array_index); wp_data.object_property, wp_data.array_index);
else else
fprintf(stderr, "Unable to decode Write-Property Request!\n"); fprintf(stderr, "Unable to decode Write-Property Request!\n");
#endif #endif
/* bad decoding or something we didn't understand - send an abort */ /* bad decoding or something we didn't understand - send an abort */
if (len <= 0) { if (len <= 0) {
pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0], pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, ABORT_REASON_OTHER); service_data->invoke_id, ABORT_REASON_OTHER);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Abort!\n"); fprintf(stderr, "Sending Abort!\n");
#endif #endif
} else if (service_data->segmented_message) { } else if (service_data->segmented_message) {
pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0], pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Abort!\n"); fprintf(stderr, "Sending Abort!\n");
#endif #endif
} else { } else {
switch (wp_data.object_type) { switch (wp_data.object_type) {
case OBJECT_DEVICE: case OBJECT_DEVICE:
@@ -96,20 +96,20 @@ void handler_write_property(uint8_t * service_request,
encode_simple_ack(&Handler_Transmit_Buffer[0], encode_simple_ack(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY); SERVICE_CONFIRMED_WRITE_PROPERTY);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Sending Write Property Simple Ack for Device!\n"); "Sending Write Property Simple Ack for Device!\n");
#endif #endif
} else { } else {
pdu_len = pdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[0], bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
error_code); error_code);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Sending Write Property Error for Device!\n"); "Sending Write Property Error for Device!\n");
#endif #endif
} }
break; break;
case OBJECT_ANALOG_INPUT: case OBJECT_ANALOG_INPUT:
@@ -120,9 +120,9 @@ void handler_write_property(uint8_t * service_request,
bacerror_encode_apdu(&Handler_Transmit_Buffer[0], bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY, service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
error_class, error_code); error_class, error_code);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Write Access Error!\n"); fprintf(stderr, "Sending Write Access Error!\n");
#endif #endif
break; break;
case OBJECT_BINARY_OUTPUT: case OBJECT_BINARY_OUTPUT:
if (Binary_Output_Write_Property(&wp_data, &error_class, if (Binary_Output_Write_Property(&wp_data, &error_class,
@@ -131,19 +131,19 @@ void handler_write_property(uint8_t * service_request,
encode_simple_ack(&Handler_Transmit_Buffer[0], encode_simple_ack(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY); SERVICE_CONFIRMED_WRITE_PROPERTY);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Sending Write Property Simple Ack for BO!\n"); "Sending Write Property Simple Ack for BO!\n");
#endif #endif
} else { } else {
pdu_len = pdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[0], bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
error_code); error_code);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Write Access Error for BO!\n"); fprintf(stderr, "Sending Write Access Error for BO!\n");
#endif #endif
} }
break; break;
case OBJECT_BINARY_VALUE: case OBJECT_BINARY_VALUE:
@@ -153,19 +153,19 @@ void handler_write_property(uint8_t * service_request,
encode_simple_ack(&Handler_Transmit_Buffer[0], encode_simple_ack(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY); SERVICE_CONFIRMED_WRITE_PROPERTY);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Sending Write Property Simple Ack for BV!\n"); "Sending Write Property Simple Ack for BV!\n");
#endif #endif
} else { } else {
pdu_len = pdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[0], bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
error_code); error_code);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Write Access Error for BV!\n"); fprintf(stderr, "Sending Write Access Error for BV!\n");
#endif #endif
} }
break; break;
case OBJECT_ANALOG_OUTPUT: case OBJECT_ANALOG_OUTPUT:
@@ -175,19 +175,19 @@ void handler_write_property(uint8_t * service_request,
encode_simple_ack(&Handler_Transmit_Buffer[0], encode_simple_ack(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY); SERVICE_CONFIRMED_WRITE_PROPERTY);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Sending Write Property Simple Ack for AO!\n"); "Sending Write Property Simple Ack for AO!\n");
#endif #endif
} else { } else {
pdu_len = pdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[0], bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
error_code); error_code);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Write Access Error for AO!\n"); fprintf(stderr, "Sending Write Access Error for AO!\n");
#endif #endif
} }
break; break;
case OBJECT_ANALOG_VALUE: case OBJECT_ANALOG_VALUE:
@@ -197,19 +197,19 @@ void handler_write_property(uint8_t * service_request,
encode_simple_ack(&Handler_Transmit_Buffer[0], encode_simple_ack(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY); SERVICE_CONFIRMED_WRITE_PROPERTY);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Sending Write Property Simple Ack for AV!\n"); "Sending Write Property Simple Ack for AV!\n");
#endif #endif
} else { } else {
pdu_len = pdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[0], bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
error_code); error_code);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Write Access Error for AV!\n"); fprintf(stderr, "Sending Write Access Error for AV!\n");
#endif #endif
} }
break; break;
case OBJECT_LIFE_SAFETY_POINT: case OBJECT_LIFE_SAFETY_POINT:
@@ -219,19 +219,19 @@ void handler_write_property(uint8_t * service_request,
encode_simple_ack(&Handler_Transmit_Buffer[0], encode_simple_ack(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY); SERVICE_CONFIRMED_WRITE_PROPERTY);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Sending Write Property Simple Ack for LSP!\n"); "Sending Write Property Simple Ack for LSP!\n");
#endif #endif
} else { } else {
pdu_len = pdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[0], bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
error_code); error_code);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Write Access Error for LSP!\n"); fprintf(stderr, "Sending Write Access Error for LSP!\n");
#endif #endif
} }
break; break;
case OBJECT_MULTI_STATE_OUTPUT: case OBJECT_MULTI_STATE_OUTPUT:
@@ -241,19 +241,19 @@ void handler_write_property(uint8_t * service_request,
encode_simple_ack(&Handler_Transmit_Buffer[0], encode_simple_ack(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY); SERVICE_CONFIRMED_WRITE_PROPERTY);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Sending Write Property Simple Ack for MSO!\n"); "Sending Write Property Simple Ack for MSO!\n");
#endif #endif
} else { } else {
pdu_len = pdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[0], bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
error_code); error_code);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Write Access Error for MSO!\n"); fprintf(stderr, "Sending Write Access Error for MSO!\n");
#endif #endif
} }
break; break;
#if BACFILE #if BACFILE
@@ -264,19 +264,19 @@ void handler_write_property(uint8_t * service_request,
encode_simple_ack(&Handler_Transmit_Buffer[0], encode_simple_ack(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY); SERVICE_CONFIRMED_WRITE_PROPERTY);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Sending Write Property Simple Ack for File!\n"); "Sending Write Property Simple Ack for File!\n");
#endif #endif
} else { } else {
pdu_len = pdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[0], bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
error_code); error_code);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Write Access Error for File!\n"); fprintf(stderr, "Sending Write Access Error for File!\n");
#endif #endif
} }
break; break;
#endif #endif
@@ -285,19 +285,19 @@ void handler_write_property(uint8_t * service_request,
bacerror_encode_apdu(&Handler_Transmit_Buffer[0], bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY, service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
error_class, error_code); error_class, error_code);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Unknown Object Error!\n"); fprintf(stderr, "Sending Unknown Object Error!\n");
#endif #endif
break; break;
} }
} }
npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
bytes_sent = datalink_send_pdu(src, &npdu_data, bytes_sent = datalink_send_pdu(src, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len); &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
#endif #endif
return; return;
} }
+2 -2
View File
@@ -53,10 +53,10 @@ void handler_unrecognized_service(uint8_t * service_request,
/* send the data */ /* send the data */
bytes_sent = datalink_send_pdu(dest, &npdu_data, bytes_sent = datalink_send_pdu(dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len); &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent > 0) if (bytes_sent > 0)
fprintf(stderr, "Sent Reject!\n"); fprintf(stderr, "Sent Reject!\n");
else else
fprintf(stderr, "Failed to Send Reject (%s)!\n", strerror(errno)); fprintf(stderr, "Failed to Send Reject (%s)!\n", strerror(errno));
#endif #endif
} }
+10 -8
View File
@@ -74,24 +74,26 @@ uint8_t Send_Atomic_Read_File_Stream(uint32_t device_id,
we have a way to check for that and update the we have a way to check for that and update the
max_apdu in the address binding table. */ max_apdu in the address binding table. */
if ((unsigned) pdu_len < max_apdu) { if ((unsigned) pdu_len < max_apdu) {
npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); npdu_encode_confirmed_apdu(&npdu_data,
tsm_set_confirmed_unsegmented_transaction(invoke_id, MESSAGE_PRIORITY_NORMAL);
&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest,
bytes_sent = datalink_send_pdu(&dest, &npdu_data, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
bytes_sent =
datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len); &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, fprintf(stderr,
"Failed to Send AtomicReadFile Request (%s)!\n", "Failed to Send AtomicReadFile Request (%s)!\n",
strerror(errno)); strerror(errno));
#endif #endif
} else { } else {
tsm_free_invoke_id(invoke_id); tsm_free_invoke_id(invoke_id);
invoke_id = 0; invoke_id = 0;
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Failed to Send AtomicReadFile Request " fprintf(stderr, "Failed to Send AtomicReadFile Request "
"(payload exceeds destination maximum APDU)!\n"); "(payload exceeds destination maximum APDU)!\n");
#endif #endif
} }
} }
+12 -11
View File
@@ -75,37 +75,38 @@ uint8_t Send_Atomic_Write_File_Stream(uint32_t device_id,
we have a way to check for that and update the we have a way to check for that and update the
max_apdu in the address binding table. */ max_apdu in the address binding table. */
if ((unsigned) pdu_len <= max_apdu) { if ((unsigned) pdu_len <= max_apdu) {
npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); npdu_encode_confirmed_apdu(&npdu_data,
tsm_set_confirmed_unsegmented_transaction(invoke_id, MESSAGE_PRIORITY_NORMAL);
&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest,
bytes_sent = datalink_send_pdu(&dest, &npdu_data, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
bytes_sent =
datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len); &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, fprintf(stderr,
"Failed to Send AtomicWriteFile Request (%s)!\n", "Failed to Send AtomicWriteFile Request (%s)!\n",
strerror(errno)); strerror(errno));
#endif #endif
} else { } else {
tsm_free_invoke_id(invoke_id); tsm_free_invoke_id(invoke_id);
invoke_id = 0; invoke_id = 0;
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Failed to Send AtomicWriteFile Request " fprintf(stderr, "Failed to Send AtomicWriteFile Request "
"(payload [%d] exceeds destination maximum APDU [%u])!\n", "(payload [%d] exceeds destination maximum APDU [%u])!\n",
pdu_len, max_apdu); pdu_len, max_apdu);
#endif #endif
} }
} else { } else {
tsm_free_invoke_id(invoke_id); tsm_free_invoke_id(invoke_id);
invoke_id = 0; invoke_id = 0;
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Failed to Send AtomicWriteFile Request " fprintf(stderr, "Failed to Send AtomicWriteFile Request "
"(payload [%d] exceeds octet string capacity)!\n", "(payload [%d] exceeds octet string capacity)!\n",
pdu_len); pdu_len);
#endif #endif
} }
} }
return invoke_id; return invoke_id;
} }
+10 -8
View File
@@ -73,25 +73,27 @@ uint8_t Send_Device_Communication_Control_Request(uint32_t device_id, uint16_t t
we have a way to check for that and update the we have a way to check for that and update the
max_apdu in the address binding table. */ max_apdu in the address binding table. */
if ((unsigned) pdu_len < max_apdu) { if ((unsigned) pdu_len < max_apdu) {
npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); npdu_encode_confirmed_apdu(&npdu_data,
tsm_set_confirmed_unsegmented_transaction(invoke_id, MESSAGE_PRIORITY_NORMAL);
&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest,
bytes_sent = datalink_send_pdu(&dest, &npdu_data, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
bytes_sent =
datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len); &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, fprintf(stderr,
"Failed to Send DeviceCommunicationControl Request (%s)!\n", "Failed to Send DeviceCommunicationControl Request (%s)!\n",
strerror(errno)); strerror(errno));
#endif #endif
} else { } else {
tsm_free_invoke_id(invoke_id); tsm_free_invoke_id(invoke_id);
invoke_id = 0; invoke_id = 0;
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Failed to Send DeviceCommunicationControl Request " "Failed to Send DeviceCommunicationControl Request "
"(exceeds destination maximum APDU)!\n"); "(exceeds destination maximum APDU)!\n");
#endif #endif
} }
} }
+3 -4
View File
@@ -67,11 +67,10 @@ void Send_I_Have(uint32_t device_id,
pdu_len = ihave_encode_apdu(&Handler_Transmit_Buffer[0], &data); pdu_len = ihave_encode_apdu(&Handler_Transmit_Buffer[0], &data);
/* send the data */ /* send the data */
npdu_encode_unconfirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); npdu_encode_unconfirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
bytes_sent = datalink_send_pdu(&dest, &npdu_data, bytes_sent = datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
&Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ #if PRINT_ENABLED
#if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "Failed to Send I-Have Reply (%s)!\n", fprintf(stderr, "Failed to Send I-Have Reply (%s)!\n",
strerror(errno)); strerror(errno));
#endif #endif
} }
+10 -8
View File
@@ -73,24 +73,26 @@ uint8_t Send_Reinitialize_Device_Request(uint32_t device_id,
we have a way to check for that and update the we have a way to check for that and update the
max_apdu in the address binding table. */ max_apdu in the address binding table. */
if ((unsigned) pdu_len < max_apdu) { if ((unsigned) pdu_len < max_apdu) {
npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); npdu_encode_confirmed_apdu(&npdu_data,
tsm_set_confirmed_unsegmented_transaction(invoke_id, MESSAGE_PRIORITY_NORMAL);
&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest,
bytes_sent = datalink_send_pdu(&dest, &npdu_data, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
bytes_sent =
datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len); &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, fprintf(stderr,
"Failed to Send ReinitializeDevice Request (%s)!\n", "Failed to Send ReinitializeDevice Request (%s)!\n",
strerror(errno)); strerror(errno));
#endif #endif
} else { } else {
tsm_free_invoke_id(invoke_id); tsm_free_invoke_id(invoke_id);
invoke_id = 0; invoke_id = 0;
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Failed to Send ReinitializeDevice Request " fprintf(stderr, "Failed to Send ReinitializeDevice Request "
"(exceeds destination maximum APDU)!\n"); "(exceeds destination maximum APDU)!\n");
#endif #endif
} }
} }
+10 -8
View File
@@ -79,24 +79,26 @@ uint8_t Send_Read_Property_Request(uint32_t device_id, /* destination device */
we have a way to check for that and update the we have a way to check for that and update the
max_apdu in the address binding table. */ max_apdu in the address binding table. */
if ((unsigned) pdu_len < max_apdu) { if ((unsigned) pdu_len < max_apdu) {
npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); npdu_encode_confirmed_apdu(&npdu_data,
tsm_set_confirmed_unsegmented_transaction(invoke_id, MESSAGE_PRIORITY_NORMAL);
&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest,
bytes_sent = datalink_send_pdu(&dest, &npdu_data, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
bytes_sent =
datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len); &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, fprintf(stderr,
"Failed to Send ReadProperty Request (%s)!\n", "Failed to Send ReadProperty Request (%s)!\n",
strerror(errno)); strerror(errno));
#endif #endif
} else { } else {
tsm_free_invoke_id(invoke_id); tsm_free_invoke_id(invoke_id);
invoke_id = 0; invoke_id = 0;
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Failed to Send ReadProperty Request " fprintf(stderr, "Failed to Send ReadProperty Request "
"(exceeds destination maximum APDU)!\n"); "(exceeds destination maximum APDU)!\n");
#endif #endif
} }
} }
+4 -4
View File
@@ -61,12 +61,12 @@ void Send_TimeSync(BACNET_DATE * bdate, BACNET_TIME * btime)
/* send it out the datalink */ /* send it out the datalink */
bytes_sent = datalink_send_pdu(&dest, &npdu_data, bytes_sent = datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len); &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, fprintf(stderr,
"Failed to Send Time-Synchronization Request (%s)!\n", "Failed to Send Time-Synchronization Request (%s)!\n",
strerror(errno)); strerror(errno));
#endif #endif
} }
void Send_TimeSyncUTC(BACNET_DATE * bdate, BACNET_TIME * btime) void Send_TimeSyncUTC(BACNET_DATE * bdate, BACNET_TIME * btime)
@@ -87,10 +87,10 @@ void Send_TimeSyncUTC(BACNET_DATE * bdate, BACNET_TIME * btime)
npdu_encode_unconfirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); npdu_encode_unconfirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
bytes_sent = datalink_send_pdu(&dest, &npdu_data, bytes_sent = datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len); &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, fprintf(stderr,
"Failed to Send UTC-Time-Synchronization Request (%s)!\n", "Failed to Send UTC-Time-Synchronization Request (%s)!\n",
strerror(errno)); strerror(errno));
#endif #endif
} }
+5 -6
View File
@@ -62,17 +62,16 @@ void Send_WhoHas_Name(int32_t low_limit,
data.high_limit = high_limit; data.high_limit = high_limit;
data.object_name = true; data.object_name = true;
characterstring_init_ansi(&data.object.name, object_name); characterstring_init_ansi(&data.object.name, object_name);
pdu_len = whohas_encode_apdu(&Handler_Transmit_Buffer[0], pdu_len = whohas_encode_apdu(&Handler_Transmit_Buffer[0], &data);
&data);
npdu_encode_unconfirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); npdu_encode_unconfirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
/* send the data */ /* send the data */
bytes_sent = datalink_send_pdu(&dest, &npdu_data, bytes_sent = datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len); &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "Failed to Send Who-Has Request (%s)!\n", fprintf(stderr, "Failed to Send Who-Has Request (%s)!\n",
strerror(errno)); strerror(errno));
#endif #endif
} }
/* find a specific device, or use -1 for limit if you want unlimited */ /* find a specific device, or use -1 for limit if you want unlimited */
@@ -101,9 +100,9 @@ void Send_WhoHas_Object(int32_t low_limit,
npdu_encode_unconfirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); npdu_encode_unconfirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
bytes_sent = datalink_send_pdu(&dest, &npdu_data, bytes_sent = datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len); &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "Failed to Send Who-Has Request (%s)!\n", fprintf(stderr, "Failed to Send Who-Has Request (%s)!\n",
strerror(errno)); strerror(errno));
#endif #endif
} }
+2 -2
View File
@@ -61,9 +61,9 @@ void Send_WhoIs(int32_t low_limit, int32_t high_limit)
npdu_encode_unconfirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); npdu_encode_unconfirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
bytes_sent = datalink_send_pdu(&dest, &npdu_data, bytes_sent = datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len); &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "Failed to Send Who-Is Request (%s)!\n", fprintf(stderr, "Failed to Send Who-Is Request (%s)!\n",
strerror(errno)); strerror(errno));
#endif #endif
} }
+10 -8
View File
@@ -83,24 +83,26 @@ uint8_t Send_Write_Property_Request(uint32_t device_id, /* destination device */
we have a way to check for that and update the we have a way to check for that and update the
max_apdu in the address binding table. */ max_apdu in the address binding table. */
if ((unsigned) pdu_len < max_apdu) { if ((unsigned) pdu_len < max_apdu) {
npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); npdu_encode_confirmed_apdu(&npdu_data,
tsm_set_confirmed_unsegmented_transaction(invoke_id, MESSAGE_PRIORITY_NORMAL);
&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest,
bytes_sent = datalink_send_pdu(&dest, &npdu_data, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
bytes_sent =
datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len); &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, fprintf(stderr,
"Failed to Send WriteProperty Request (%s)!\n", "Failed to Send WriteProperty Request (%s)!\n",
strerror(errno)); strerror(errno));
#endif #endif
} else { } else {
tsm_free_invoke_id(invoke_id); tsm_free_invoke_id(invoke_id);
invoke_id = 0; invoke_id = 0;
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Failed to Send WriteProperty Request " fprintf(stderr, "Failed to Send WriteProperty Request "
"(exceeds destination maximum APDU)!\n"); "(exceeds destination maximum APDU)!\n");
#endif #endif
} }
} }
+8 -8
View File
@@ -301,8 +301,8 @@ uint32_t bacfile_instance_from_tsm(uint8_t invokeID)
uint8_t *service_request = NULL; uint8_t *service_request = NULL;
uint16_t service_request_len = 0; uint16_t service_request_len = 0;
BACNET_ADDRESS dest; /* where the original packet was destined */ BACNET_ADDRESS dest; /* where the original packet was destined */
uint8_t apdu[MAX_PDU] = { 0 }; /* original APDU packet */ uint8_t apdu[MAX_PDU] = { 0 }; /* original APDU packet */
uint16_t apdu_len = 0; /* original APDU packet length */ uint16_t apdu_len = 0; /* original APDU packet length */
uint16_t len = 0; /* apdu header length */ uint16_t len = 0; /* apdu header length */
BACNET_ATOMIC_READ_FILE_DATA data = { 0 }; BACNET_ATOMIC_READ_FILE_DATA data = { 0 };
uint32_t object_instance = BACNET_MAX_INSTANCE + 1; /* return value */ uint32_t object_instance = BACNET_MAX_INSTANCE + 1; /* return value */
@@ -312,12 +312,12 @@ uint32_t bacfile_instance_from_tsm(uint8_t invokeID)
found = tsm_get_transaction_pdu(invokeID, &dest, &npdu_data, &apdu[0], found = tsm_get_transaction_pdu(invokeID, &dest, &npdu_data, &apdu[0],
&apdu_len); &apdu_len);
if (found) { if (found) {
if (!npdu_data.network_layer_message && npdu_data.confirmed_message && if (!npdu_data.network_layer_message && npdu_data.confirmed_message
(apdu[0] == PDU_TYPE_CONFIRMED_SERVICE_REQUEST)) { && (apdu[0] == PDU_TYPE_CONFIRMED_SERVICE_REQUEST)) {
len = apdu_decode_confirmed_service_request(&apdu[0], len =
apdu_len - apdu_offset, apdu_decode_confirmed_service_request(&apdu[0],
&service_data, apdu_len - apdu_offset, &service_data, &service_choice,
&service_choice, &service_request, &service_request_len); &service_request, &service_request_len);
if (service_choice == SERVICE_CONFIRMED_ATOMIC_READ_FILE) { if (service_choice == SERVICE_CONFIRMED_ATOMIC_READ_FILE) {
len = arf_decode_service_request(service_request, len = arf_decode_service_request(service_request,
service_request_len, &data); service_request_len, &data);
+2 -1
View File
@@ -239,7 +239,8 @@ int main(int argc, char *argv[])
timeout_seconds = (Device_APDU_Timeout() / 1000) * timeout_seconds = (Device_APDU_Timeout() / 1000) *
Device_Number_Of_APDU_Retries(); Device_Number_Of_APDU_Retries();
/* try to bind with the device */ /* try to bind with the device */
Send_WhoIs(Target_Device_Object_Instance,Target_Device_Object_Instance); Send_WhoIs(Target_Device_Object_Instance,
Target_Device_Object_Instance);
/* loop forever */ /* loop forever */
for (;;) { for (;;) {
/* increment timer - exit if timed out */ /* increment timer - exit if timed out */
+2 -1
View File
@@ -195,7 +195,8 @@ int main(int argc, char *argv[])
timeout_seconds = (Device_APDU_Timeout() / 1000) * timeout_seconds = (Device_APDU_Timeout() / 1000) *
Device_Number_Of_APDU_Retries(); Device_Number_Of_APDU_Retries();
/* try to bind with the device */ /* try to bind with the device */
Send_WhoIs(Target_Device_Object_Instance,Target_Device_Object_Instance); Send_WhoIs(Target_Device_Object_Instance,
Target_Device_Object_Instance);
/* loop forever */ /* loop forever */
for (;;) { for (;;) {
/* increment timer - exit if timed out */ /* increment timer - exit if timed out */
+9 -10
View File
@@ -44,13 +44,12 @@
#define MAX_HEADER (2+1+1+1+2+1+2+1) #define MAX_HEADER (2+1+1+1+2+1+2+1)
#define MAX_MPDU (MAX_HEADER+MAX_PDU) #define MAX_MPDU (MAX_HEADER+MAX_PDU)
typedef struct dlmstp_packet typedef struct dlmstp_packet {
{ bool ready; /* true if ready to be sent or received */
bool ready; /* true if ready to be sent or received */
bool data_expecting_reply; bool data_expecting_reply;
BACNET_ADDRESS address; /* src or dest address*/ BACNET_ADDRESS address; /* src or dest address */
unsigned pdu_len; /* packet length */ unsigned pdu_len; /* packet length */
uint8_t pdu[MAX_MPDU]; /* packet */ uint8_t pdu[MAX_MPDU]; /* packet */
} DLMSTP_PACKET; } DLMSTP_PACKET;
#ifdef __cplusplus #ifdef __cplusplus
@@ -72,13 +71,13 @@ extern "C" {
uint8_t * pdu, /* PDU data */ uint8_t * pdu, /* PDU data */
uint16_t max_pdu, /* amount of space available in the PDU */ uint16_t max_pdu, /* amount of space available in the PDU */
unsigned timeout); /* milliseconds to wait for a packet */ unsigned timeout); /* milliseconds to wait for a packet */
/* function for MS/TP state machine to use to get a packet /* function for MS/TP state machine to use to get a packet
to transmit. It returns the number of bytes in the to transmit. It returns the number of bytes in the
packet, or 0 if none. */ packet, or 0 if none. */
int dlmstp_get_transmit_pdu(BACNET_ADDRESS * dest, /* destination address */ int dlmstp_get_transmit_pdu(BACNET_ADDRESS * dest, /* destination address */
uint8_t * pdu); /* any data to be sent - may be null */ uint8_t * pdu); /* any data to be sent - may be null */
void dlmstp_set_my_address(uint8_t my_address); void dlmstp_set_my_address(uint8_t my_address);
void dlmstp_get_my_address(BACNET_ADDRESS * my_address); void dlmstp_get_my_address(BACNET_ADDRESS * my_address);
+2 -3
View File
@@ -151,8 +151,7 @@ int iam_send(uint8_t * buffer)
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
npdu_encode_unconfirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); npdu_encode_unconfirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
/* send data */ /* send data */
bytes_sent = datalink_send_pdu(&dest, &npdu_data, bytes_sent = datalink_send_pdu(&dest, &npdu_data, &buffer[0], pdu_len);
&buffer[0], pdu_len);
return bytes_sent; return bytes_sent;
} }
@@ -218,7 +217,7 @@ void datalink_get_broadcast_address(BACNET_ADDRESS * dest)
} }
int datalink_send_pdu(BACNET_ADDRESS * dest, /* destination address */ int datalink_send_pdu(BACNET_ADDRESS * dest, /* destination address */
BACNET_NPDU_DATA * npdu_data, /* network information */ BACNET_NPDU_DATA * npdu_data, /* network information */
uint8_t * pdu, /* any data to be sent - may be null */ uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len) unsigned pdu_len)
{ /* number of bytes of data */ { /* number of bytes of data */
+11 -14
View File
@@ -57,8 +57,7 @@ void npdu_copy_data(BACNET_NPDU_DATA * dest, BACNET_NPDU_DATA * src)
int npdu_encode_pdu(uint8_t * npdu, int npdu_encode_pdu(uint8_t * npdu,
BACNET_ADDRESS * dest, BACNET_ADDRESS * dest,
BACNET_ADDRESS * src, BACNET_ADDRESS * src, BACNET_NPDU_DATA * npdu_data)
BACNET_NPDU_DATA * npdu_data)
{ {
int len = 0; /* return value - number of octets loaded in this function */ int len = 0; /* return value - number of octets loaded in this function */
int i = 0; /* counter */ int i = 0; /* counter */
@@ -158,13 +157,12 @@ int npdu_encode_pdu(uint8_t * npdu,
void npdu_encode_confirmed_apdu(BACNET_NPDU_DATA * npdu_data, void npdu_encode_confirmed_apdu(BACNET_NPDU_DATA * npdu_data,
BACNET_MESSAGE_PRIORITY priority) BACNET_MESSAGE_PRIORITY priority)
{ {
if (npdu_data) if (npdu_data) {
{
npdu_data->confirmed_message = true; npdu_data->confirmed_message = true;
npdu_data->protocol_version = BACNET_PROTOCOL_VERSION; npdu_data->protocol_version = BACNET_PROTOCOL_VERSION;
npdu_data->network_layer_message = false; /* false if APDU */ npdu_data->network_layer_message = false; /* false if APDU */
npdu_data->network_message_type = 0; /* optional */ npdu_data->network_message_type = 0; /* optional */
npdu_data->vendor_id = 0; /* optional, if net message type is > 0x80 */ npdu_data->vendor_id = 0; /* optional, if net message type is > 0x80 */
npdu_data->priority = priority; npdu_data->priority = priority;
npdu_data->hop_count = 0; npdu_data->hop_count = 0;
} }
@@ -173,13 +171,12 @@ void npdu_encode_confirmed_apdu(BACNET_NPDU_DATA * npdu_data,
void npdu_encode_unconfirmed_apdu(BACNET_NPDU_DATA * npdu_data, void npdu_encode_unconfirmed_apdu(BACNET_NPDU_DATA * npdu_data,
BACNET_MESSAGE_PRIORITY priority) BACNET_MESSAGE_PRIORITY priority)
{ {
if (npdu_data) if (npdu_data) {
{
npdu_data->confirmed_message = false; npdu_data->confirmed_message = false;
npdu_data->protocol_version = BACNET_PROTOCOL_VERSION; npdu_data->protocol_version = BACNET_PROTOCOL_VERSION;
npdu_data->network_layer_message = false; /* false if APDU */ npdu_data->network_layer_message = false; /* false if APDU */
npdu_data->network_message_type = 0; /* optional */ npdu_data->network_message_type = 0; /* optional */
npdu_data->vendor_id = 0; /* optional, if net message type is > 0x80 */ npdu_data->vendor_id = 0; /* optional, if net message type is > 0x80 */
npdu_data->priority = priority; npdu_data->priority = priority;
npdu_data->hop_count = 0; npdu_data->hop_count = 0;
} }
@@ -339,7 +336,7 @@ void testNPDU2(Test * pTest)
BACNET_ADDRESS npdu_dest = { 0 }; BACNET_ADDRESS npdu_dest = { 0 };
BACNET_ADDRESS npdu_src = { 0 }; BACNET_ADDRESS npdu_src = { 0 };
int len = 0; int len = 0;
bool confirmed_message = true; /* true for confirmed messages */ bool confirmed_message = true; /* true for confirmed messages */
BACNET_MESSAGE_PRIORITY priority = MESSAGE_PRIORITY_NORMAL; BACNET_MESSAGE_PRIORITY priority = MESSAGE_PRIORITY_NORMAL;
BACNET_NPDU_DATA npdu_data = { 0 }; BACNET_NPDU_DATA npdu_data = { 0 };
int i = 0; /* counter */ int i = 0; /* counter */
@@ -403,7 +400,7 @@ void testNPDU1(Test * pTest)
BACNET_ADDRESS npdu_dest = { 0 }; BACNET_ADDRESS npdu_dest = { 0 };
BACNET_ADDRESS npdu_src = { 0 }; BACNET_ADDRESS npdu_src = { 0 };
int len = 0; int len = 0;
bool confirmed_message = false; /* true for confirmed messages */ bool confirmed_message = false; /* true for confirmed messages */
BACNET_MESSAGE_PRIORITY priority = MESSAGE_PRIORITY_NORMAL; BACNET_MESSAGE_PRIORITY priority = MESSAGE_PRIORITY_NORMAL;
BACNET_NPDU_DATA npdu_data = { 0 }; BACNET_NPDU_DATA npdu_data = { 0 };
int i = 0; /* counter */ int i = 0; /* counter */
+1 -1
View File
@@ -43,7 +43,7 @@
typedef struct bacnet_npdu_data_t { typedef struct bacnet_npdu_data_t {
uint8_t protocol_version; uint8_t protocol_version;
/* parts of the control octet: */ /* parts of the control octet: */
bool confirmed_message; /* true for confirmed messages */ bool confirmed_message; /* true for confirmed messages */
bool network_layer_message; /* false if APDU */ bool network_layer_message; /* false if APDU */
BACNET_MESSAGE_PRIORITY priority; BACNET_MESSAGE_PRIORITY priority;
/* optional network message info */ /* optional network message info */
+196 -198
View File
@@ -1,198 +1,196 @@
/************************************************************************** /**************************************************************************
* *
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net> * Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the * a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including * "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, * without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to * distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to * permit persons to whom the Software is furnished to do so, subject to
* the following conditions: * the following conditions:
* *
* The above copyright notice and this permission notice shall be included * The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software. * in all copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* *
*********************************************************************/ *********************************************************************/
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <string.h> #include <string.h>
#include "bacdef.h" #include "bacdef.h"
#include "mstp.h" #include "mstp.h"
#include "dlmstp.h" #include "dlmstp.h"
#include "rs485.h" #include "rs485.h"
static DLMSTP_PACKET Receive_Buffer; static DLMSTP_PACKET Receive_Buffer;
static DLMSTP_PACKET Transmit_Buffer; static DLMSTP_PACKET Transmit_Buffer;
volatile struct mstp_port_struct_t MSTP_Port; /* port data */ volatile struct mstp_port_struct_t MSTP_Port; /* port data */
static uint8_t MSTP_MAC_Address = 0x05; /* local MAC address */ static uint8_t MSTP_MAC_Address = 0x05; /* local MAC address */
void dlmstp_init(void) void dlmstp_init(void)
{ {
/* initialize buffer */ /* initialize buffer */
Receive_Buffer.ready = false; Receive_Buffer.ready = false;
Receive_Buffer.data_expecting_reply = false; Receive_Buffer.data_expecting_reply = false;
Receive_Buffer.pdu_len = 0; Receive_Buffer.pdu_len = 0;
/* initialize buffer */ /* initialize buffer */
Transmit_Buffer.ready = false; Transmit_Buffer.ready = false;
Transmit_Buffer.data_expecting_reply = false; Transmit_Buffer.data_expecting_reply = false;
Transmit_Buffer.pdu_len = 0; Transmit_Buffer.pdu_len = 0;
/* initialize hardware */ /* initialize hardware */
RS485_Initialize(); RS485_Initialize();
MSTP_Init(&MSTP_Port, MSTP_MAC_Address); MSTP_Init(&MSTP_Port, MSTP_MAC_Address);
} }
void dlmstp_cleanup(void) void dlmstp_cleanup(void)
{ {
/* nothing to do for static buffers */ /* nothing to do for static buffers */
} }
/* returns number of bytes sent on success, zero on failure */ /* returns number of bytes sent on success, zero on failure */
int dlmstp_send_pdu(BACNET_ADDRESS * dest, /* destination address */ int dlmstp_send_pdu(BACNET_ADDRESS * dest, /* destination address */
uint8_t * pdu, /* any data to be sent - may be null */ uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len) unsigned pdu_len)
{ /* number of bytes of data */ { /* number of bytes of data */
bool status; bool status;
int bytes_sent = 0; int bytes_sent = 0;
if (Transmit_Buffer.ready == false) if (Transmit_Buffer.ready == false) {
{ /* FIXME: how do we get data_expecting_reply? */
/* FIXME: how do we get data_expecting_reply? */ Transmit_Buffer.data_expecting_reply = false;
Transmit_Buffer.data_expecting_reply = false; Receive_Buffer.pdu_len = 0;
Receive_Buffer.pdu_len = 0; memmove(&Transmit_Buffer.address, dest,
memmove(&Transmit_Buffer.address,dest,sizeof(Transmit_Buffer.address)); sizeof(Transmit_Buffer.address));
Transmit_Buffer.pdu_len = pdu_len; Transmit_Buffer.pdu_len = pdu_len;
/* FIXME: copy the whole PDU or just the pdu_len? */ /* FIXME: copy the whole PDU or just the pdu_len? */
memmove(Transmit_Buffer.pdu,pdu,sizeof(Transmit_Buffer.pdu)); memmove(Transmit_Buffer.pdu, pdu, sizeof(Transmit_Buffer.pdu));
bytes_sent = pdu_len; bytes_sent = pdu_len;
Transmit_Buffer.ready = true; Transmit_Buffer.ready = true;
} }
return bytes_sent; return bytes_sent;
} }
/* function for MS/TP to use to get a packet to transmit /* function for MS/TP to use to get a packet to transmit
returns the number of bytes in the packet, or zero if none. */ returns the number of bytes in the packet, or zero if none. */
int dlmstp_get_transmit_pdu(BACNET_ADDRESS * dest, /* destination address */ int dlmstp_get_transmit_pdu(BACNET_ADDRESS * dest, /* destination address */
uint8_t * pdu) /* any data to be sent - may be null */ uint8_t * pdu)
{ { /* any data to be sent - may be null */
bool status; bool status;
DLMSTP_PACKET *packet; DLMSTP_PACKET *packet;
unsigned pdu_len = 0; unsigned pdu_len = 0;
if (Transmit_Buffer.ready) if (Transmit_Buffer.ready) {
{ memmove(dest, &packet->address, sizeof(packet->address));
memmove(dest,&packet->address,sizeof(packet->address)); pdu_len = packet->pdu_len;
pdu_len = packet->pdu_len; memmove(pdu, packet->pdu, sizeof(packet.pdu));
memmove(pdu,packet->pdu,sizeof(packet.pdu)); }
}
return pdu_len;
return pdu_len; }
}
int dlmstp_set_transmit_pdu_ready(bool ready)
int dlmstp_set_transmit_pdu_ready(bool ready) {
{ Transmit_Buffer.ready = ready;
Transmit_Buffer.ready = ready; }
}
void dlmstp_task(void)
void dlmstp_task(void) {
{ RS485_Check_UART_Data(&MSTP_Port);
RS485_Check_UART_Data(&MSTP_Port); MSTP_Receive_Frame_FSM(&MSTP_Port);
MSTP_Receive_Frame_FSM(&MSTP_Port);
RS485_Process_Tx_Message();
RS485_Process_Tx_Message(); MSTP_Master_Node_FSM(&MSTP_Port);
MSTP_Master_Node_FSM(&MSTP_Port); }
}
/* called about once a millisecond */
/* called about once a millisecond */ void dlmstp_millisecond_timer(void)
void dlmstp_millisecond_timer(void) {
{ MSTP_Millisecond_Timer(&MSTP_Port);
MSTP_Millisecond_Timer(&MSTP_Port); }
}
/* returns the number of octets in the PDU, or zero on failure */
/* returns the number of octets in the PDU, or zero on failure */ /* This function is expecting to be polled. */
/* This function is expecting to be polled. */ uint16_t dlmstp_receive(BACNET_ADDRESS * src, /* source address */
uint16_t dlmstp_receive(BACNET_ADDRESS * src, /* source address */ uint8_t * pdu, /* PDU data */
uint8_t * pdu, /* PDU data */ uint16_t max_pdu, /* amount of space available in the PDU */
uint16_t max_pdu, /* amount of space available in the PDU */ unsigned timeout)
unsigned timeout) {
{ DLMSTP_PACKET *packet;
DLMSTP_PACKET *packet;
(void) timeout;
(void) timeout; /* see if there is a packet available */
/* see if there is a packet available */ if (!Ringbuf_Empty(&Receive_Buffer)) {
if (!Ringbuf_Empty(&Receive_Buffer)) packet = (char *) Ringbuf_Pop_Front(&Receive_Buffer);
{ memmove(src, &packet->address, sizeof(packet->address));
packet = (char *)Ringbuf_Pop_Front(&Receive_Buffer); pdu_len = packet->pdu_len;
memmove(src,&packet->address,sizeof(packet->address)); memmove(pdu, packet->pdu, max_pdu);
pdu_len = packet->pdu_len; }
memmove(pdu,packet->pdu,max_pdu);
} return pdu_len;
}
return pdu_len;
} /* for the MS/TP state machine to use for putting received data */
uint16_t dlmstp_put_receive(BACNET_ADDRESS * src, /* source address */
/* for the MS/TP state machine to use for putting received data */ uint8_t * pdu, /* PDU data */
uint16_t dlmstp_put_receive(BACNET_ADDRESS * src, /* source address */ uint16_t pdu_len)
uint8_t * pdu, /* PDU data */ {
uint16_t pdu_len) bool status;
{ int bytes_put = 0;
bool status;
int bytes_put = 0; memmove(&Temp_Packet.address, src, sizeof(Temp_Packet.address));
Temp_Packet.pdu_len = pdu_len;
memmove(&Temp_Packet.address,src,sizeof(Temp_Packet.address)); memmove(Temp_Packet.pdu, pdu, sizeof(Temp_Packet.pdu));
Temp_Packet.pdu_len = pdu_len; status = Ringbuf_Put(&Receive_Buffer, &Temp_Packet);
memmove(Temp_Packet.pdu,pdu,sizeof(Temp_Packet.pdu)); if (status)
status = Ringbuf_Put(&Receive_Buffer, &Temp_Packet); bytes_put = pdu_len;
if (status)
bytes_put = pdu_len; return bytes_put;
}
return bytes_put;
} void dlmstp_set_my_address(uint8_t mac_address)
{
void dlmstp_set_my_address(uint8_t mac_address) /* FIXME: Master Nodes can only have address 1-127 */
{ MSTP_MAC_Address = mac_address;
/* FIXME: Master Nodes can only have address 1-127 */
MSTP_MAC_Address = mac_address; return;
}
return;
} void dlmstp_get_my_address(BACNET_ADDRESS * my_address)
{
void dlmstp_get_my_address(BACNET_ADDRESS * my_address) my_address->mac_len = 1;
{ my_address->mac[0] = MSTP_MAC_Address;
my_address->mac_len = 1; my_address->net = 0; /* local only, no routing */
my_address->mac[0] = MSTP_MAC_Address; my_address->len = 0;
my_address->net = 0; /* local only, no routing */ for (i = 0; i < MAX_MAC_LEN; i++) {
my_address->len = 0; my_address->adr[i] = 0;
for (i = 0; i < MAX_MAC_LEN; i++) { }
my_address->adr[i] = 0;
} return;
}
return;
} void dlmstp_get_broadcast_address(BACNET_ADDRESS * dest)
{ /* destination address */
void dlmstp_get_broadcast_address(BACNET_ADDRESS * dest) int i = 0; /* counter */
{ /* destination address */
int i = 0; /* counter */ if (dest) {
dest->mac_len = 1;
if (dest) { dest->mac[0] = MSTP_BROADCAST_ADDRESS;
dest->mac_len = 1; dest->net = BACNET_BROADCAST_NETWORK;
dest->mac[0] = MSTP_BROADCAST_ADDRESS; dest->len = 0; /* len=0 denotes broadcast address */
dest->net = BACNET_BROADCAST_NETWORK; for (i = 0; i < MAX_MAC_LEN; i++) {
dest->len = 0; /* len=0 denotes broadcast address */ dest->adr[i] = 0;
for (i = 0; i < MAX_MAC_LEN; i++) { }
dest->adr[i] = 0; }
}
} return;
}
return;
}
+3 -2
View File
@@ -52,8 +52,9 @@
static uint8_t Temp_Buf[MAX_APDU]; static uint8_t Temp_Buf[MAX_APDU];
/* buffer used for receiving */ /* buffer used for receiving */
static uint8_t Rx_Buf[MAX_MPDU] = { 0 }; static uint8_t Rx_Buf[MAX_MPDU] = { 0 };
/* address where message came from */ /* address where message came from */
static BACNET_ADDRESS src; static BACNET_ADDRESS src;
/* address used to send */ /* address used to send */
static BACNET_ADDRESS my_address; static BACNET_ADDRESS my_address;
@@ -170,7 +171,7 @@ void main(void)
Device_Set_Object_Instance_Number(5); Device_Set_Object_Instance_Number(5);
dlmstp_set_my_address(0x05); dlmstp_set_my_address(0x05);
dlmstp_init(); dlmstp_init();
init_hardware(); init_hardware();
/* broadcast an I-Am on startup */ /* broadcast an I-Am on startup */
+1 -1
View File
@@ -50,7 +50,7 @@ static struct {
/* Duplicate of the RCSTA reg used due to the double buffering of the */ /* Duplicate of the RCSTA reg used due to the double buffering of the */
/* fifo. Reading the RCREG reg will cause the second RCSTA reg to be */ /* fifo. Reading the RCREG reg will cause the second RCSTA reg to be */
/* loaded if there is one. */ /* loaded if there is one. */
struct _rcstabits { struct _rcstabits {
unsigned char RX9D:1; unsigned char RX9D:1;
unsigned char OERR:1; unsigned char OERR:1;
unsigned char FERR:1; unsigned char FERR:1;
+2 -3
View File
@@ -133,8 +133,7 @@ uint8_t tsm_next_free_invokeID(void)
bool found = false; bool found = false;
/* is there even space available? */ /* is there even space available? */
if (tsm_transaction_available()) if (tsm_transaction_available()) {
{
while (!found) { while (!found) {
index = tsm_find_invokeID_index(current_invokeID); index = tsm_find_invokeID_index(current_invokeID);
/* not found - that is good! */ /* not found - that is good! */
@@ -208,7 +207,7 @@ bool tsm_get_transaction_pdu(uint8_t invokeID,
for (j = 0; j < *apdu_len; j++) { for (j = 0; j < *apdu_len; j++) {
apdu[j] = TSM_List[index].apdu[j]; apdu[j] = TSM_List[index].apdu[j];
} }
npdu_copy_data(ndpu_data,&TSM_List[index].npdu_data); npdu_copy_data(ndpu_data, &TSM_List[index].npdu_data);
address_copy(dest, &TSM_List[index].dest); address_copy(dest, &TSM_List[index].dest);
found = true; found = true;
} }