refactored the Who-Is and I-Am handling, and cleaned up some comments.

This commit is contained in:
skarg
2006-02-20 16:17:46 +00:00
parent 16c2545f45
commit 676ecf77a2
9 changed files with 149 additions and 188 deletions
+10 -7
View File
@@ -33,9 +33,8 @@
#include "bacdcode.h" #include "bacdcode.h"
#include "whois.h" #include "whois.h"
#include "device.h" #include "device.h"
#include "client.h"
/* global flag to send an I-Am */ #include "txbuf.h"
bool I_Am_Request = true;
void handler_who_is(uint8_t * service_request, void handler_who_is(uint8_t * service_request,
uint16_t service_len, BACNET_ADDRESS * src) uint16_t service_len, BACNET_ADDRESS * src)
@@ -50,11 +49,15 @@ void handler_who_is(uint8_t * service_request,
/* in our simple system, we just set a flag and let the main loop /* in our simple system, we just set a flag and let the main loop
send the I-Am request. */ send the I-Am request. */
if (len == 0) if (len == 0)
I_Am_Request = true; iam_send(&Handler_Transmit_Buffer[0]);
else if (len != -1) { else if (len != -1) {
if ((Device_Object_Instance_Number() >= (uint32_t) low_limit) && /* is my device id within the limits? */
(Device_Object_Instance_Number() <= (uint32_t) high_limit)) if (((Device_Object_Instance_Number() >= (uint32_t) low_limit) &&
I_Am_Request = true; (Device_Object_Instance_Number() <= (uint32_t) high_limit)) ||
/* BACnet wildcard is the max instance number - everyone responds */
((BACNET_MAX_INSTANCE >= (uint32_t) low_limit) &&
(BACNET_MAX_INSTANCE <= (uint32_t) high_limit)))
iam_send(&Handler_Transmit_Buffer[0]);
} }
return; return;
-3
View File
@@ -32,9 +32,6 @@
#include "apdu.h" #include "apdu.h"
#include "bacapp.h" #include "bacapp.h"
/* flag requesting main loop to send an I-Am */
extern bool I_Am_Request;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
+1 -6
View File
@@ -609,9 +609,6 @@ int Device_Encode_Property_APDU(uint8_t * apdu,
return apdu_len; return apdu_len;
} }
/* we can send an I-Am when our device ID changes */
extern bool I_Am_Request;
/* returns true if successful */ /* returns true if successful */
bool Device_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data, bool Device_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code) BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code)
@@ -630,7 +627,7 @@ bool Device_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
if ((wp_data->value.type.Object_Id.type == OBJECT_DEVICE) && if ((wp_data->value.type.Object_Id.type == OBJECT_DEVICE) &&
(Device_Set_Object_Instance_Number(wp_data->value.type. (Device_Set_Object_Instance_Number(wp_data->value.type.
Object_Id.instance))) { Object_Id.instance))) {
I_Am_Request = true; /* we could send an I-Am broadcast to let the world know */
status = true; status = true;
} else { } else {
*error_class = ERROR_CLASS_PROPERTY; *error_class = ERROR_CLASS_PROPERTY;
@@ -808,8 +805,6 @@ uint32_t bacfile_index_to_instance(unsigned find_index)
return find_index; return find_index;
} }
bool I_Am_Request = false;
int main(void) int main(void)
{ {
Test *pTest; Test *pTest;
+1 -6
View File
@@ -23,7 +23,7 @@
* *
*********************************************************************/ *********************************************************************/
/* READFILE: command line tool that reads a file from a BACnet device. */ /* command line tool that sends a BACnet service, and displays the reply */
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
@@ -335,10 +335,6 @@ int main(int argc, char *argv[])
last_seconds) * 1000)); last_seconds) * 1000));
if (End_Of_File_Detected || Error_Detected) if (End_Of_File_Detected || Error_Detected)
break; break;
if (I_Am_Request) {
I_Am_Request = false;
iam_send(&Handler_Transmit_Buffer[0]);
} else {
/* wait until the device is bound, or timeout and quit */ /* wait until the device is bound, or timeout and quit */
found = address_bind_request(Target_Device_Object_Instance, found = address_bind_request(Target_Device_Object_Instance,
&max_apdu, &Target_Address); &max_apdu, &Target_Address);
@@ -372,7 +368,6 @@ int main(int argc, char *argv[])
if (elapsed_seconds > timeout_seconds) if (elapsed_seconds > timeout_seconds)
break; break;
} }
}
/* keep track of time for next check */ /* keep track of time for next check */
last_seconds = current_seconds; last_seconds = current_seconds;
} }
+1 -8
View File
@@ -23,7 +23,7 @@
* *
*********************************************************************/ *********************************************************************/
/* READPROP: command line tool that reads a property from a BACnet device. */ /* command line tool that sends a BACnet service, and displays the reply */
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
@@ -183,8 +183,6 @@ int main(int argc, char *argv[])
last_seconds = time(NULL); last_seconds = time(NULL);
timeout_seconds = (Device_APDU_Timeout() / 1000) * timeout_seconds = (Device_APDU_Timeout() / 1000) *
Device_Number_Of_APDU_Retries(); Device_Number_Of_APDU_Retries();
/* no need to spam the world */
I_Am_Request = false;
/* try to bind with the device */ /* try to bind with the device */
Send_WhoIs(Target_Device_Object_Instance, Send_WhoIs(Target_Device_Object_Instance,
Target_Device_Object_Instance); Target_Device_Object_Instance);
@@ -206,10 +204,6 @@ int main(int argc, char *argv[])
last_seconds) * 1000)); last_seconds) * 1000));
if (Error_Detected) if (Error_Detected)
break; break;
if (I_Am_Request) {
I_Am_Request = false;
iam_send(&Handler_Transmit_Buffer[0]);
} else {
/* wait until the device is bound, or timeout and quit */ /* wait until the device is bound, or timeout and quit */
found = address_bind_request(Target_Device_Object_Instance, found = address_bind_request(Target_Device_Object_Instance,
&max_apdu, &Target_Address); &max_apdu, &Target_Address);
@@ -228,7 +222,6 @@ int main(int argc, char *argv[])
if (elapsed_seconds > timeout_seconds) if (elapsed_seconds > timeout_seconds)
break; break;
} }
}
/* keep track of time for next check */ /* keep track of time for next check */
last_seconds = current_seconds; last_seconds = current_seconds;
} }
+1 -8
View File
@@ -23,7 +23,7 @@
* *
*********************************************************************/ *********************************************************************/
/* WRITEPROP: command line tool that writes a property to a BACnet device. */ /* command line tool that sends a BACnet service, and displays the reply */
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
@@ -213,8 +213,6 @@ int main(int argc, char *argv[])
last_seconds = time(NULL); last_seconds = time(NULL);
timeout_seconds = (Device_APDU_Timeout() / 1000) * timeout_seconds = (Device_APDU_Timeout() / 1000) *
Device_Number_Of_APDU_Retries(); Device_Number_Of_APDU_Retries();
/* don't send an I-Am unless asked */
I_Am_Request = false;
/* try to bind with the device */ /* try to bind with the device */
Send_WhoIs(Target_Device_Object_Instance, Send_WhoIs(Target_Device_Object_Instance,
Target_Device_Object_Instance); Target_Device_Object_Instance);
@@ -236,10 +234,6 @@ int main(int argc, char *argv[])
last_seconds) * 1000)); last_seconds) * 1000));
if (Error_Detected) if (Error_Detected)
break; break;
if (I_Am_Request) {
I_Am_Request = false;
iam_send(&Handler_Transmit_Buffer[0]);
} else {
/* wait until the device is bound, or timeout and quit */ /* wait until the device is bound, or timeout and quit */
found = address_bind_request(Target_Device_Object_Instance, found = address_bind_request(Target_Device_Object_Instance,
&max_apdu, &Target_Address); &max_apdu, &Target_Address);
@@ -257,7 +251,6 @@ int main(int argc, char *argv[])
if (elapsed_seconds > timeout_seconds) if (elapsed_seconds > timeout_seconds)
break; break;
} }
}
/* keep track of time for next check */ /* keep track of time for next check */
last_seconds = current_seconds; last_seconds = current_seconds;
} }
+2 -7
View File
@@ -45,7 +45,7 @@
#include "net.h" #include "net.h"
#include "txbuf.h" #include "txbuf.h"
/* This is an example application using the BACnet Stack */ /* This is an example server application using the BACnet Stack */
/* buffers used for receiving */ /* buffers used for receiving */
static uint8_t Rx_Buf[MAX_MPDU] = { 0 }; static uint8_t Rx_Buf[MAX_MPDU] = { 0 };
@@ -135,7 +135,7 @@ int main(int argc, char *argv[])
/* configure the timeout values */ /* configure the timeout values */
last_seconds = time(NULL); last_seconds = time(NULL);
/* broadcast an I-Am on startup */ /* broadcast an I-Am on startup */
I_Am_Request = true; iam_send(&Handler_Transmit_Buffer[0]);
/* loop forever */ /* loop forever */
for (;;) { for (;;) {
/* input */ /* input */
@@ -151,11 +151,6 @@ int main(int argc, char *argv[])
/* at least one second has passed */ /* at least one second has passed */
if (current_seconds != last_seconds) if (current_seconds != last_seconds)
dcc_timer_seconds(current_seconds - last_seconds); dcc_timer_seconds(current_seconds - last_seconds);
/* send out the I-Am if requested */
if (I_Am_Request) {
I_Am_Request = false;
iam_send(&Handler_Transmit_Buffer[0]);
}
/* output */ /* output */
/* blink LEDs, Turn on or off outputs, etc */ /* blink LEDs, Turn on or off outputs, etc */
+1 -6
View File
@@ -23,7 +23,7 @@
* *
*********************************************************************/ *********************************************************************/
/* READFILE: command line tool that writes a file to a BACnet device. */ /* command line tool that sends a BACnet service, and displays the reply */
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
@@ -299,10 +299,6 @@ int main(int argc, char *argv[])
printf("\r\n"); printf("\r\n");
break; break;
} }
if (I_Am_Request) {
I_Am_Request = false;
iam_send(&Handler_Transmit_Buffer[0]);
} else {
/* wait until the device is bound, or timeout and quit */ /* wait until the device is bound, or timeout and quit */
found = address_bind_request(Target_Device_Object_Instance, found = address_bind_request(Target_Device_Object_Instance,
&max_apdu, &Target_Address); &max_apdu, &Target_Address);
@@ -357,7 +353,6 @@ int main(int argc, char *argv[])
if (elapsed_seconds > timeout_seconds) if (elapsed_seconds > timeout_seconds)
break; break;
} }
}
/* keep track of time for next check */ /* keep track of time for next check */
last_seconds = current_seconds; last_seconds = current_seconds;
} }
+1 -6
View File
@@ -23,7 +23,7 @@
* *
*********************************************************************/ *********************************************************************/
/* WRITEPROP: command line tool that writes a property to a BACnet device. */ /* command line tool that sends a BACnet service, and displays the reply */
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
@@ -309,10 +309,6 @@ int main(int argc, char *argv[])
last_seconds) * 1000)); last_seconds) * 1000));
if (Error_Detected) if (Error_Detected)
break; break;
if (I_Am_Request) {
I_Am_Request = false;
iam_send(&Handler_Transmit_Buffer[0]);
} else {
/* wait until the device is bound, or timeout and quit */ /* wait until the device is bound, or timeout and quit */
found = address_bind_request(Target_Device_Object_Instance, found = address_bind_request(Target_Device_Object_Instance,
&max_apdu, &Target_Address); &max_apdu, &Target_Address);
@@ -333,7 +329,6 @@ int main(int argc, char *argv[])
if (elapsed_seconds > timeout_seconds) if (elapsed_seconds > timeout_seconds)
break; break;
} }
}
/* keep track of time for next check */ /* keep track of time for next check */
last_seconds = current_seconds; last_seconds = current_seconds;
} }