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