Changed the API to pass the NPDU data down through the datalink layer in order to make the dlmstp work since it needs data-expecting-reply information. Of course, this affected all the demos, all the unit tests, and most of the demo handlers. Corrected some TSM leaks in confirmed messages. Refactored the AtomicReadFile and AtomicWriteFile demos by moving the Send_ functions to the demo/handlers directory and using the s_whois common handler. Added some common defines for the BACnet version and revision since several modules were using the info. Hopefully I didn't break too many things.

This commit is contained in:
skarg
2006-08-13 00:54:05 +00:00
parent 185d02a9ff
commit 5bb205dc03
46 changed files with 793 additions and 638 deletions
+35 -26
View File
@@ -132,22 +132,26 @@ uint8_t tsm_next_free_invokeID(void)
uint8_t invokeID = 0;
bool found = false;
while (!found) {
index = tsm_find_invokeID_index(current_invokeID);
/* not found - that is good! */
if (index == MAX_TSM_TRANSACTIONS) {
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].state = TSM_STATE_IDLE;
TSM_List[index].RequestTimer = Device_APDU_Timeout();
/* update for the next call or check */
current_invokeID++;
/* skip zero - we treat that internally as invalid or no free */
if (current_invokeID == 0)
current_invokeID = 1;
/* is there even space available? */
if (tsm_transaction_available())
{
while (!found) {
index = tsm_find_invokeID_index(current_invokeID);
/* not found - that is good! */
if (index == MAX_TSM_TRANSACTIONS) {
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].state = TSM_STATE_IDLE;
TSM_List[index].RequestTimer = Device_APDU_Timeout();
/* update for the next call or check */
current_invokeID++;
/* skip zero - we treat that internally as invalid or no free */
if (current_invokeID == 0)
current_invokeID = 1;
}
}
}
}
@@ -156,7 +160,8 @@ uint8_t tsm_next_free_invokeID(void)
}
void tsm_set_confirmed_unsegmented_transaction(uint8_t invokeID,
BACNET_ADDRESS * dest, uint8_t * pdu, uint16_t pdu_len)
BACNET_ADDRESS * dest, BACNET_NPDU_DATA * ndpu_data,
uint8_t * apdu, uint16_t apdu_len)
{
uint16_t j = 0;
uint8_t index;
@@ -170,10 +175,11 @@ void tsm_set_confirmed_unsegmented_transaction(uint8_t invokeID,
/* start the timer */
TSM_List[index].RequestTimer = Device_APDU_Timeout();
/* copy the data */
for (j = 0; j < pdu_len; j++) {
TSM_List[index].pdu[j] = pdu[j];
for (j = 0; j < apdu_len; j++) {
TSM_List[index].apdu[j] = apdu[j];
}
TSM_List[index].pdu_len = pdu_len;
TSM_List[index].apdu_len = apdu_len;
npdu_copy_data(&TSM_List[index].npdu_data, ndpu_data);
address_copy(&TSM_List[index].dest, dest);
}
}
@@ -184,7 +190,8 @@ void tsm_set_confirmed_unsegmented_transaction(uint8_t invokeID,
/* used to retrieve the transaction payload */
/* if we wanted to find out what we sent (i.e. when we get an ack) */
bool tsm_get_transaction_pdu(uint8_t invokeID,
BACNET_ADDRESS * dest, uint8_t * pdu, uint16_t * pdu_len)
BACNET_ADDRESS * dest, BACNET_NPDU_DATA * ndpu_data,
uint8_t * apdu, uint16_t * apdu_len)
{
uint16_t j = 0;
uint8_t index;
@@ -197,10 +204,11 @@ bool tsm_get_transaction_pdu(uint8_t invokeID,
/* FIXME: we may want to free the transaction so it doesn't timeout */
/* retrieve the transaction */
/* FIXME: bounds check the pdu_len? */
*pdu_len = TSM_List[index].pdu_len;
for (j = 0; j < *pdu_len; j++) {
pdu[j] = TSM_List[index].pdu[j];
*apdu_len = TSM_List[index].apdu_len;
for (j = 0; j < *apdu_len; j++) {
apdu[j] = TSM_List[index].apdu[j];
}
npdu_copy_data(ndpu_data,&TSM_List[index].npdu_data);
address_copy(dest, &TSM_List[index].dest);
found = true;
}
@@ -226,8 +234,9 @@ void tsm_timer_milliseconds(uint16_t milliseconds)
TSM_List[i].RetryCount--;
TSM_List[i].RequestTimer = Device_APDU_Timeout();
if (TSM_List[i].RetryCount) {
bytes_sent = datalink_send_pdu(&TSM_List[i].dest, /* destination address */
&TSM_List[i].pdu[0], TSM_List[i].pdu_len); /* number of bytes of data */
bytes_sent = datalink_send_pdu(&TSM_List[i].dest,
&TSM_List[i].npdu_data,
&TSM_List[i].apdu[0], TSM_List[i].apdu_len);
} else {
TSM_List[i].InvokeID = 0;
TSM_List[i].state = TSM_STATE_IDLE;