diff --git a/bacnet-stack/demo/handler/s_iam.c b/bacnet-stack/demo/handler/s_iam.c index 46edb518..5b778aa8 100644 --- a/bacnet-stack/demo/handler/s_iam.c +++ b/bacnet-stack/demo/handler/s_iam.c @@ -27,8 +27,6 @@ #include #include #include "config.h" -#include "config.h" -#include "txbuf.h" #include "bacdef.h" #include "bacdcode.h" #include "address.h" @@ -40,34 +38,49 @@ #include "iam.h" /* some demo stuff needed */ #include "handlers.h" -#include "txbuf.h" -void Send_I_Am( - uint8_t * buffer) +int iam_encode_pdu( + uint8_t * buffer, + BACNET_ADDRESS * dest, + BACNET_NPDU_DATA * npdu_data) { int len = 0; int pdu_len = 0; - BACNET_ADDRESS dest; - int bytes_sent = 0; - BACNET_NPDU_DATA npdu_data; /* I-Am is a global broadcast */ - datalink_get_broadcast_address(&dest); + datalink_get_broadcast_address(dest); /* encode the NPDU portion of the packet */ - npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); - pdu_len = npdu_encode_pdu(&buffer[0], &dest, NULL, &npdu_data); + npdu_encode_npdu_data(npdu_data, false, MESSAGE_PRIORITY_NORMAL); + pdu_len = npdu_encode_pdu(&buffer[0], dest, NULL, npdu_data); /* encode the APDU portion of the packet */ len = iam_encode_apdu(&buffer[pdu_len], Device_Object_Instance_Number(), MAX_APDU, SEGMENTATION_NONE, Device_Vendor_Identifier()); 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 */ bytes_sent = datalink_send_pdu(&dest, &npdu_data, &buffer[0], pdu_len); + #if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, "Failed to Send I-Am Reply (%s)!\n", strerror(errno)); #endif - - return; + return bytes_sent; } diff --git a/bacnet-stack/include/client.h b/bacnet-stack/include/client.h index f1d5b182..54684ea5 100644 --- a/bacnet-stack/include/client.h +++ b/bacnet-stack/include/client.h @@ -41,6 +41,10 @@ extern "C" { /* unconfirmed requests */ void Send_I_Am( uint8_t * buffer); + int iam_encode_pdu( + uint8_t * buffer, + BACNET_ADDRESS * dest, + BACNET_NPDU_DATA * npdu_data); void Send_WhoIs( int32_t low_limit, diff --git a/bacnet-stack/ports/atmega168/bacnet.aps b/bacnet-stack/ports/atmega168/bacnet.aps index a39bd51c..26861917 100644 --- a/bacnet-stack/ports/atmega168/bacnet.aps +++ b/bacnet-stack/ports/atmega168/bacnet.aps @@ -1 +1 @@ -13-Aug-2007 15:08:2730-Oct-2008 15:54:44013-Aug-2007 15:08:2744, 13, 0, 528AVR GCC241bacnet13-Aug-2007 15:11:0713-Aug-2007 15:11:07241013-Aug-2007 15:11:0744, 13, 0, 528AVR GCCbacnet.elfC:\code\bacnet-stack\ports\atmega168\ATMEGA168falseR00R01R02R03R04R05R06R07R08R09R10R11R12R13R14R15R16R17R18R19R20R21R22R23R24R25R26R27R28R29R30R31AVR DragonAVR SimulatorATmega168.xmlAuto00property_lenobject_indexPresent_Valuevalue0main.crs485.ctimer.cdlmstp.cC:\code\bacnet-stack\demo\handler\txbuf.cdevice.cC:\code\bacnet-stack\src\crc.cC:\code\bacnet-stack\src\npdu.capdu.ch_rp.cC:\code\bacnet-stack\src\iam.cav.ch_wp.cC:\code\bacnet-stack\src\bacapp.cC:\code\bacnet-stack\src\bacstr.cbv.ch_whois.cC:\code\bacnet-stack\src\whois.cavr035.hhardware.hrs485.htimer.hC:\code\bacnet-stack\include\crc.hC:\code\bacnet-stack\include\dlmstp.hC:\code\bacnet-stack\include\iam.hC:\code\bacnet-stack\include\npdu.hC:\code\bacnet-stack\include\txbuf.hC:\code\bacnet-stack\include\bacenum.hC:\code\bacnet-stack\include\bacdcode.hC:\code\bacnet-stack\include\bacapp.hC:\code\bacnet-stack\include\bacstr.hMakefiledefaultYESMakefileatmega168100bacnet.elfdefault\0..\..\demo\handler\.\..\..\..\..\demo\object\-Wall -gdwarf-2 -DMAX_APDU=50 -DBACDL_MSTP -DBIG_ENDIAN=0 -DF_CPU=7372800UL -O0 -fsigned-chardefault1C:\WinAVR-20071221rc1\bin\avr-gcc.exeC:\WinAVR-20071221rc1\utils\bin\make.exe0282161937372800011000001920010000000001011main100000main.c25900001dlmstp.c25900002C:\code\bacnet-stack\src\crc.c25800003C:\code\bacnet-stack\src\bacstr.c25700004av.c25700005bv.c25800006h_whois.c25900007rs485.c25700008C:\code\bacnet-stack\demo\handler\h_npdu.c300009apdu.c300010C:\code\bacnet-stack\src\whois.c100011device.c1 +13-Aug-2007 15:08:2714-Nov-2008 08:40:02013-Aug-2007 15:08:2744, 13, 0, 528AVR GCC241bacnet13-Aug-2007 15:11:0713-Aug-2007 15:11:07241013-Aug-2007 15:11:0744, 13, 0, 528AVR GCCbacnet.elfC:\code\bacnet-stack\ports\atmega168\ATMEGA168falseR00R01R02R03R04R05R06R07R08R09R10R11R12R13R14R15R16R17R18R19R20R21R22R23R24R25R26R27R28R29R30R31AVR DragonAVR SimulatorATmega168.xmlAuto00property_lenobject_indexPresent_Valuevalue0main.crs485.ctimer.cdlmstp.cC:\code\bacnet-stack\demo\handler\txbuf.cdevice.cC:\code\bacnet-stack\src\crc.cC:\code\bacnet-stack\src\npdu.capdu.ch_rp.cC:\code\bacnet-stack\src\iam.cav.ch_wp.cC:\code\bacnet-stack\src\bacapp.cC:\code\bacnet-stack\src\bacstr.cbv.ch_whois.cC:\code\bacnet-stack\src\whois.cavr035.hhardware.hrs485.htimer.hC:\code\bacnet-stack\include\crc.hC:\code\bacnet-stack\include\dlmstp.hC:\code\bacnet-stack\include\iam.hC:\code\bacnet-stack\include\npdu.hC:\code\bacnet-stack\include\txbuf.hC:\code\bacnet-stack\include\bacenum.hC:\code\bacnet-stack\include\bacdcode.hC:\code\bacnet-stack\include\bacapp.hC:\code\bacnet-stack\include\bacstr.hMakefiledefaultYESMakefileatmega168100bacnet.elfdefault\0..\..\demo\handler\.\..\..\..\..\demo\object\-Wall -gdwarf-2 -DMAX_APDU=50 -DBACDL_MSTP -DBIG_ENDIAN=0 -DF_CPU=7372800UL -O0 -fsigned-chardefault1C:\WinAVR-20071221rc1\bin\avr-gcc.exeC:\WinAVR-20071221rc1\utils\bin\make.exe0282161937372800011000001920010000000001011main100000main.c25900001dlmstp.c25900002C:\code\bacnet-stack\src\crc.c25800003bv.c25800004C:\code\bacnet-stack\demo\handler\h_npdu.c25800005apdu.c25800006h_whois.c25700007h_wp.c257 diff --git a/bacnet-stack/ports/atmega168/dlmstp.c b/bacnet-stack/ports/atmega168/dlmstp.c index 9692bf55..3b82fefc 100644 --- a/bacnet-stack/ports/atmega168/dlmstp.c +++ b/bacnet-stack/ports/atmega168/dlmstp.c @@ -44,7 +44,7 @@ #include "bits.h" #include "bacaddr.h" /* special optimization - I-Am response in this module */ -#include "iam.h" +#include "client.h" #include "txbuf.h" /* This file has been customized for use with small microprocessors */ @@ -277,7 +277,7 @@ void dlmstp_fill_bacnet_address( } /* 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 */ static uint16_t dlmstp_encode_unconfirmed_frame( @@ -287,8 +287,8 @@ static uint16_t dlmstp_encode_unconfirmed_frame( BACNET_NPDU_DATA npdu_data; uint16_t len = 0; - if (Send_I_Am) { - Send_I_Am = false; + if (Send_I_Am_Flag) { + Send_I_Am_Flag = false; TransmitPacket = Handler_Transmit_Buffer; len = iam_encode_pdu(&TransmitPacket[0], &dest, &npdu_data); } diff --git a/bacnet-stack/ports/atmega168/h_whois.c b/bacnet-stack/ports/atmega168/h_whois.c index d273bab4..89418ab2 100644 --- a/bacnet-stack/ports/atmega168/h_whois.c +++ b/bacnet-stack/ports/atmega168/h_whois.c @@ -37,7 +37,7 @@ #include "client.h" #include "txbuf.h" -bool Send_I_Am = true; +bool Send_I_Am_Flag = true; void handler_who_is( uint8_t * service_request, @@ -54,7 +54,7 @@ void handler_who_is( whois_decode_service_request(service_request, service_len, &low_limit, &high_limit); if (len == 0) { - Send_I_Am = true; + Send_I_Am_Flag = true; } else if (len != -1) { /* is my device id within the limits? */ target_device = Device_Object_Instance_Number(); @@ -63,7 +63,7 @@ void handler_who_is( /* BACnet wildcard is the max instance number - everyone responds */ ((BACNET_MAX_INSTANCE >= (uint32_t) low_limit) && (BACNET_MAX_INSTANCE <= (uint32_t) high_limit))) { - Send_I_Am = true; + Send_I_Am_Flag = true; } } diff --git a/bacnet-stack/ports/atmega168/main.c b/bacnet-stack/ports/atmega168/main.c index 5a3d9989..b2010855 100644 --- a/bacnet-stack/ports/atmega168/main.c +++ b/bacnet-stack/ports/atmega168/main.c @@ -37,7 +37,7 @@ #include "av.h" /* From the WhoIs hander - performed by the DLMSTP module */ -extern bool Send_I_Am; +extern bool Send_I_Am_Flag; /* local version override */ const char *BACnet_Version = "1.0"; @@ -134,7 +134,7 @@ static void input_switch_read( dlmstp_set_mac_address(Address_Switch); #endif Device_Set_Object_Instance_Number(86000 + Address_Switch); - Send_I_Am = true; + Send_I_Am_Flag = true; } } }