Added ability to set starting invoke id from environment variable BACNET_INVOKE_ID

This commit is contained in:
brayra
2010-04-27 15:11:58 +00:00
parent 1c8a58f158
commit 37d048310c
3 changed files with 28 additions and 9 deletions
+6
View File
@@ -34,6 +34,7 @@
#include "datalink.h"
#include "handlers.h"
#include "client.h"
#include "tsm.h"
/** @file dlenv.c Initialize the DataLink configuration. */
@@ -131,6 +132,11 @@ void dlenv_init(
if (!datalink_init(getenv("BACNET_IFACE"))) {
exit(1);
}
pEnv = getenv("BACNET_INVOKE_ID");
if (pEnv) {
tsm_invokeID_set((uint8_t)strtol(pEnv, NULL, 0));
}
#if defined(BACDL_BIP) && BBMD_ENABLED
pEnv = getenv("BACNET_BBMD_PORT");
if (pEnv) {
+1
View File
@@ -106,6 +106,7 @@ extern "C" {
/* use these in tandem */
uint8_t tsm_next_free_invokeID(
void);
void tsm_invokeID_set(uint8_t invokeID);
/* returns the same invoke ID that was given */
void tsm_set_confirmed_unsegmented_transaction(
uint8_t invokeID,
+21 -9
View File
@@ -61,6 +61,9 @@
/* table rules: an Invoke ID = 0 is an unused spot in the table */
static BACNET_TSM_DATA TSM_List[MAX_TSM_TRANSACTIONS];
/* invoke ID for incrementing between subsequent calls. */
static uint8_t Current_Invoke_ID = 1;
/* returns MAX_TSM_TRANSACTIONS if not found */
static uint8_t tsm_find_invokeID_index(
uint8_t invokeID)
@@ -128,13 +131,22 @@ uint8_t tsm_transaction_idle_count(
return count;
}
/* sets the invokeID */
void tsm_invokeID_set(uint8_t invokeID)
{
if(invokeID == 0) {
invokeID = 1;
}
Current_Invoke_ID=invokeID;
}
/* gets the next free invokeID,
and reserves a spot in the table
returns 0 if none are available */
uint8_t tsm_next_free_invokeID(
void)
{
static uint8_t current_invokeID = 1; /* incremented... */
uint8_t index = 0;
uint8_t invokeID = 0;
bool found = false;
@@ -142,30 +154,30 @@ uint8_t tsm_next_free_invokeID(
/* is there even space available? */
if (tsm_transaction_available()) {
while (!found) {
index = tsm_find_invokeID_index(current_invokeID);
index = tsm_find_invokeID_index(Current_Invoke_ID);
if (index == MAX_TSM_TRANSACTIONS) {
/* Not found, so this invokeID is not used */
found = true;
/* set this id into the table */
index = tsm_find_first_free_index();
if (index != MAX_TSM_TRANSACTIONS) {
TSM_List[index].InvokeID = invokeID = current_invokeID;
TSM_List[index].InvokeID = invokeID = Current_Invoke_ID;
TSM_List[index].state = TSM_STATE_IDLE;
TSM_List[index].RequestTimer = apdu_timeout();
/* update for the next call or check */
current_invokeID++;
Current_Invoke_ID++;
/* skip zero - we treat that internally as invalid or no free */
if (current_invokeID == 0) {
current_invokeID = 1;
if (Current_Invoke_ID == 0) {
Current_Invoke_ID = 1;
}
}
} else {
/* found! This invokeID is already used */
/* try next one */
current_invokeID++;
Current_Invoke_ID++;
/* skip zero - we treat that internally as invalid or no free */
if (current_invokeID == 0) {
current_invokeID = 1;
if (Current_Invoke_ID == 0) {
Current_Invoke_ID = 1;
}
}
}