added I-Am reception to the linux port.

This commit is contained in:
skarg
2005-04-22 10:04:50 +00:00
parent d85487f237
commit ba7e028795
3 changed files with 61 additions and 10 deletions
+28 -10
View File
@@ -72,7 +72,7 @@ int iam_encode_apdu(
return apdu_len;
}
int iam_decode_apdu(
int iam_decode_service_request(
uint8_t *apdu,
uint32_t *pDevice_id,
unsigned *pMax_apdu,
@@ -88,16 +88,7 @@ int iam_decode_apdu(
unsigned int decoded_value = 0;
int decoded_integer = 0;
// valid data?
if (!apdu)
return -1;
// optional checking - most likely was already done prior to this call
if (apdu[0] != PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST)
return -1;
if (apdu[1] != SERVICE_UNCONFIRMED_I_AM)
return -1;
// OBJECT ID - object id
apdu_len = 2;
len = decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &len_value);
apdu_len += len;
if (tag_number != BACNET_APPLICATION_TAG_OBJECT_ID)
@@ -143,6 +134,33 @@ int iam_decode_apdu(
return apdu_len;
}
int iam_decode_apdu(
uint8_t *apdu,
uint32_t *pDevice_id,
unsigned *pMax_apdu,
int *pSegmentation,
uint16_t *pVendor_id)
{
int apdu_len = 0; // total length of the apdu, return value
// valid data?
if (!apdu)
return -1;
// optional checking - most likely was already done prior to this call
if (apdu[0] != PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST)
return -1;
if (apdu[1] != SERVICE_UNCONFIRMED_I_AM)
return -1;
apdu_len = iam_decode_service_request(
&apdu[2],
pDevice_id,
pMax_apdu,
pSegmentation,
pVendor_id);
return apdu_len;
}
#ifdef TEST
#include <assert.h>
#include <string.h>
+7
View File
@@ -44,6 +44,13 @@ int iam_encode_apdu(
int segmentation,
uint16_t vendor_id);
int iam_decode_service_request(
uint8_t *apdu,
uint32_t *pDevice_id,
unsigned *pMax_apdu,
int *pSegmentation,
uint16_t *pVendor_id);
int iam_decode_apdu(
uint8_t *apdu,
uint32_t *pDevice_id,
+26
View File
@@ -120,6 +120,29 @@ void WhoIsHandler(
return;
}
void IAmHandler(
uint8_t *service_request,
uint16_t service_len,
BACNET_ADDRESS *src)
{
int len = 0;
uint32_t device_id = 0;
unsigned max_apdu = 0;
int segmentation = 0;
uint16_t vendor_id = 0;
len = iam_decode_service_request(
service_request,
&device_id,
&max_apdu,
&segmentation,
&vendor_id);
if (len != -1)
fprintf(stderr,"Received I-Am Request from %u!\n",device_id);
return;
}
void ReadPropertyHandler(
uint8_t *service_request,
uint16_t service_len,
@@ -261,6 +284,9 @@ static void Init_Service_Handlers(void)
apdu_set_unconfirmed_handler(
SERVICE_UNCONFIRMED_WHO_IS,
WhoIsHandler);
apdu_set_unconfirmed_handler(
SERVICE_UNCONFIRMED_I_AM,
IAmHandler);
// set the handler for all the services we don't implement
// It is required to send the proper reject message...