Moved the iam_send to demo/handler/s_iam.c to keep application code out of the core encode/decode library.

This commit is contained in:
skarg
2008-11-14 14:41:28 +00:00
parent 29df527ec1
commit 0e9a805f75
6 changed files with 40 additions and 23 deletions
+26 -13
View File
@@ -27,8 +27,6 @@
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include "config.h" #include "config.h"
#include "config.h"
#include "txbuf.h"
#include "bacdef.h" #include "bacdef.h"
#include "bacdcode.h" #include "bacdcode.h"
#include "address.h" #include "address.h"
@@ -40,34 +38,49 @@
#include "iam.h" #include "iam.h"
/* some demo stuff needed */ /* some demo stuff needed */
#include "handlers.h" #include "handlers.h"
#include "txbuf.h"
void Send_I_Am( int iam_encode_pdu(
uint8_t * buffer) uint8_t * buffer,
BACNET_ADDRESS * dest,
BACNET_NPDU_DATA * npdu_data)
{ {
int len = 0; int len = 0;
int pdu_len = 0; int pdu_len = 0;
BACNET_ADDRESS dest;
int bytes_sent = 0;
BACNET_NPDU_DATA npdu_data;
/* I-Am is a global broadcast */ /* I-Am is a global broadcast */
datalink_get_broadcast_address(&dest); datalink_get_broadcast_address(dest);
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&buffer[0], &dest, NULL, &npdu_data); pdu_len = npdu_encode_pdu(&buffer[0], dest, NULL, npdu_data);
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
len = len =
iam_encode_apdu(&buffer[pdu_len], Device_Object_Instance_Number(), iam_encode_apdu(&buffer[pdu_len], Device_Object_Instance_Number(),
MAX_APDU, SEGMENTATION_NONE, Device_Vendor_Identifier()); MAX_APDU, SEGMENTATION_NONE, Device_Vendor_Identifier());
pdu_len += len; pdu_len += len;
return pdu_len;
}
void Send_I_Am(
uint8_t * buffer)
{
int pdu_len = 0;
BACNET_ADDRESS dest;
int bytes_sent = 0;
BACNET_NPDU_DATA npdu_data;
/* are we are forbidden to send? */
if (!dcc_communication_enabled())
return 0;
/* encode the data */
pdu_len = iam_encode_pdu(buffer, &dest, &npdu_data);
/* send data */ /* 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);
#if PRINT_ENABLED #if PRINT_ENABLED
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "Failed to Send I-Am Reply (%s)!\n", fprintf(stderr, "Failed to Send I-Am Reply (%s)!\n",
strerror(errno)); strerror(errno));
#endif #endif
return bytes_sent;
return;
} }
+4
View File
@@ -41,6 +41,10 @@ extern "C" {
/* unconfirmed requests */ /* unconfirmed requests */
void Send_I_Am( void Send_I_Am(
uint8_t * buffer); uint8_t * buffer);
int iam_encode_pdu(
uint8_t * buffer,
BACNET_ADDRESS * dest,
BACNET_NPDU_DATA * npdu_data);
void Send_WhoIs( void Send_WhoIs(
int32_t low_limit, int32_t low_limit,
File diff suppressed because one or more lines are too long
+4 -4
View File
@@ -44,7 +44,7 @@
#include "bits.h" #include "bits.h"
#include "bacaddr.h" #include "bacaddr.h"
/* special optimization - I-Am response in this module */ /* special optimization - I-Am response in this module */
#include "iam.h" #include "client.h"
#include "txbuf.h" #include "txbuf.h"
/* This file has been customized for use with small microprocessors */ /* This file has been customized for use with small microprocessors */
@@ -277,7 +277,7 @@ void dlmstp_fill_bacnet_address(
} }
/* I Am from handler */ /* I Am from handler */
extern bool Send_I_Am; extern bool Send_I_Am_Flag;
/* look at any of the unconfirmed message bits and encode if set */ /* look at any of the unconfirmed message bits and encode if set */
static uint16_t dlmstp_encode_unconfirmed_frame( static uint16_t dlmstp_encode_unconfirmed_frame(
@@ -287,8 +287,8 @@ static uint16_t dlmstp_encode_unconfirmed_frame(
BACNET_NPDU_DATA npdu_data; BACNET_NPDU_DATA npdu_data;
uint16_t len = 0; uint16_t len = 0;
if (Send_I_Am) { if (Send_I_Am_Flag) {
Send_I_Am = false; Send_I_Am_Flag = false;
TransmitPacket = Handler_Transmit_Buffer; TransmitPacket = Handler_Transmit_Buffer;
len = iam_encode_pdu(&TransmitPacket[0], &dest, &npdu_data); len = iam_encode_pdu(&TransmitPacket[0], &dest, &npdu_data);
} }
+3 -3
View File
@@ -37,7 +37,7 @@
#include "client.h" #include "client.h"
#include "txbuf.h" #include "txbuf.h"
bool Send_I_Am = true; bool Send_I_Am_Flag = true;
void handler_who_is( void handler_who_is(
uint8_t * service_request, uint8_t * service_request,
@@ -54,7 +54,7 @@ void handler_who_is(
whois_decode_service_request(service_request, service_len, &low_limit, whois_decode_service_request(service_request, service_len, &low_limit,
&high_limit); &high_limit);
if (len == 0) { if (len == 0) {
Send_I_Am = true; Send_I_Am_Flag = true;
} else if (len != -1) { } else if (len != -1) {
/* is my device id within the limits? */ /* is my device id within the limits? */
target_device = Device_Object_Instance_Number(); target_device = Device_Object_Instance_Number();
@@ -63,7 +63,7 @@ void handler_who_is(
/* BACnet wildcard is the max instance number - everyone responds */ /* BACnet wildcard is the max instance number - everyone responds */
((BACNET_MAX_INSTANCE >= (uint32_t) low_limit) && ((BACNET_MAX_INSTANCE >= (uint32_t) low_limit) &&
(BACNET_MAX_INSTANCE <= (uint32_t) high_limit))) { (BACNET_MAX_INSTANCE <= (uint32_t) high_limit))) {
Send_I_Am = true; Send_I_Am_Flag = true;
} }
} }
+2 -2
View File
@@ -37,7 +37,7 @@
#include "av.h" #include "av.h"
/* From the WhoIs hander - performed by the DLMSTP module */ /* From the WhoIs hander - performed by the DLMSTP module */
extern bool Send_I_Am; extern bool Send_I_Am_Flag;
/* local version override */ /* local version override */
const char *BACnet_Version = "1.0"; const char *BACnet_Version = "1.0";
@@ -134,7 +134,7 @@ static void input_switch_read(
dlmstp_set_mac_address(Address_Switch); dlmstp_set_mac_address(Address_Switch);
#endif #endif
Device_Set_Object_Instance_Number(86000 + Address_Switch); Device_Set_Object_Instance_Number(86000 + Address_Switch);
Send_I_Am = true; Send_I_Am_Flag = true;
} }
} }
} }