Fixed EOL, indent.
This commit is contained in:
@@ -117,10 +117,8 @@ static void Init_Service_Handlers(
|
||||
void)
|
||||
{
|
||||
Device_Init();
|
||||
handler_read_property_object_set(
|
||||
OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU,
|
||||
Device_Valid_Object_Instance_Number);
|
||||
handler_read_property_object_set(OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU, Device_Valid_Object_Instance_Number);
|
||||
/* we need to handle who-is
|
||||
to support dynamic device binding to us */
|
||||
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is);
|
||||
|
||||
@@ -242,10 +242,8 @@ static void Init_Service_Handlers(
|
||||
void)
|
||||
{
|
||||
Device_Init();
|
||||
handler_read_property_object_set(
|
||||
OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU,
|
||||
Device_Valid_Object_Instance_Number);
|
||||
handler_read_property_object_set(OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU, Device_Valid_Object_Instance_Number);
|
||||
/* we need to handle who-is
|
||||
to support dynamic device binding to us */
|
||||
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is);
|
||||
|
||||
@@ -327,8 +327,9 @@ static bool cov_send_request(
|
||||
value_list[1].next = NULL;
|
||||
switch (cov_subscription->monitoredObjectIdentifier.type) {
|
||||
case OBJECT_BINARY_INPUT:
|
||||
Binary_Input_Encode_Value_List(cov_subscription->
|
||||
monitoredObjectIdentifier.instance, &value_list[0]);
|
||||
Binary_Input_Encode_Value_List
|
||||
(cov_subscription->monitoredObjectIdentifier.instance,
|
||||
&value_list[0]);
|
||||
break;
|
||||
default:
|
||||
goto COV_FAILED;
|
||||
@@ -426,8 +427,8 @@ static bool cov_subscribe(
|
||||
|
||||
switch (cov_data->monitoredObjectIdentifier.type) {
|
||||
case OBJECT_BINARY_INPUT:
|
||||
if (Binary_Input_Valid_Instance(cov_data->
|
||||
monitoredObjectIdentifier.instance)) {
|
||||
if (Binary_Input_Valid_Instance
|
||||
(cov_data->monitoredObjectIdentifier.instance)) {
|
||||
status =
|
||||
cov_list_subscribe(src, cov_data, error_class, error_code);
|
||||
} else {
|
||||
|
||||
@@ -46,9 +46,9 @@ void handler_dcc_password_set(
|
||||
size_t i = 0; /* loop counter */
|
||||
|
||||
if (new_password) {
|
||||
for (i = 0; i < (sizeof(My_Password)-1); i++) {
|
||||
for (i = 0; i < (sizeof(My_Password) - 1); i++) {
|
||||
My_Password[i] = new_password[i];
|
||||
My_Password[i+1] = 0;
|
||||
My_Password[i + 1] = 0;
|
||||
if (new_password[i] == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -38,8 +38,7 @@
|
||||
#include "event.h"
|
||||
#include "getevent.h"
|
||||
|
||||
static get_event_info_function
|
||||
Get_Event_Info[MAX_BACNET_OBJECT_TYPE];
|
||||
static get_event_info_function Get_Event_Info[MAX_BACNET_OBJECT_TYPE];
|
||||
|
||||
void handler_get_event_information_set(
|
||||
BACNET_OBJECT_TYPE object_type,
|
||||
@@ -82,15 +81,14 @@ void handler_get_event_information(
|
||||
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
|
||||
true);
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "GetEventInformation: "
|
||||
"Segmented message. Sending Abort!\n");
|
||||
fprintf(stderr,
|
||||
"GetEventInformation: " "Segmented message. Sending Abort!\n");
|
||||
#endif
|
||||
goto GET_EVENT_ABORT;
|
||||
}
|
||||
|
||||
len = getevent_decode_service_request(
|
||||
service_request,
|
||||
service_len,
|
||||
len =
|
||||
getevent_decode_service_request(service_request, service_len,
|
||||
&object_id);
|
||||
if (len < 0) {
|
||||
/* bad decoding - send an abort */
|
||||
@@ -98,17 +96,17 @@ void handler_get_event_information(
|
||||
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||
service_data->invoke_id, ABORT_REASON_OTHER, true);
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "GetEventInformation: Bad Encoding. Sending Abort!\n");
|
||||
fprintf(stderr,
|
||||
"GetEventInformation: Bad Encoding. Sending Abort!\n");
|
||||
#endif
|
||||
goto GET_EVENT_ABORT;
|
||||
}
|
||||
|
||||
/* assume that there is an error */
|
||||
error = true;
|
||||
len = getevent_ack_encode_apdu_init(
|
||||
&Handler_Transmit_Buffer[pdu_len],
|
||||
sizeof(Handler_Transmit_Buffer) - pdu_len,
|
||||
service_data->invoke_id);
|
||||
len =
|
||||
getevent_ack_encode_apdu_init(&Handler_Transmit_Buffer[pdu_len],
|
||||
sizeof(Handler_Transmit_Buffer) - pdu_len, service_data->invoke_id);
|
||||
if (len <= 0) {
|
||||
error = true;
|
||||
goto GET_EVENT_ERROR;
|
||||
@@ -117,11 +115,11 @@ void handler_get_event_information(
|
||||
for (i = 0; i < MAX_BACNET_OBJECT_TYPE; i++) {
|
||||
if (Get_Event_Info[i]) {
|
||||
for (j = 0; j < 0xffff; j++) {
|
||||
valid_event = Get_Event_Info[i](j, &getevent_data);
|
||||
valid_event = Get_Event_Info[i] (j, &getevent_data);
|
||||
if (valid_event > 0) {
|
||||
len = getevent_ack_encode_apdu_data(
|
||||
&Handler_Transmit_Buffer[pdu_len],
|
||||
sizeof(Handler_Transmit_Buffer)-pdu_len,
|
||||
len =
|
||||
getevent_ack_encode_apdu_data(&Handler_Transmit_Buffer
|
||||
[pdu_len], sizeof(Handler_Transmit_Buffer) - pdu_len,
|
||||
&getevent_data);
|
||||
if (len <= 0) {
|
||||
error = true;
|
||||
@@ -134,10 +132,9 @@ void handler_get_event_information(
|
||||
}
|
||||
}
|
||||
}
|
||||
len = getevent_ack_encode_apdu_end(
|
||||
&Handler_Transmit_Buffer[pdu_len],
|
||||
sizeof(Handler_Transmit_Buffer)-pdu_len,
|
||||
false);
|
||||
len =
|
||||
getevent_ack_encode_apdu_end(&Handler_Transmit_Buffer[pdu_len],
|
||||
sizeof(Handler_Transmit_Buffer) - pdu_len, false);
|
||||
if (len <= 0) {
|
||||
error = true;
|
||||
goto GET_EVENT_ERROR;
|
||||
@@ -146,7 +143,7 @@ void handler_get_event_information(
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "GetEventInformation: Sending Ack!\n");
|
||||
#endif
|
||||
GET_EVENT_ERROR:
|
||||
GET_EVENT_ERROR:
|
||||
if (error) {
|
||||
if (len == -2) {
|
||||
/* BACnet APDU too small to fit data, so proper response is Abort */
|
||||
@@ -155,8 +152,8 @@ GET_EVENT_ERROR:
|
||||
service_data->invoke_id,
|
||||
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "GetEventInformation: "
|
||||
"Reply too big to fit into APDU!\n");
|
||||
fprintf(stderr,
|
||||
"GetEventInformation: " "Reply too big to fit into APDU!\n");
|
||||
#endif
|
||||
} else {
|
||||
len =
|
||||
@@ -168,7 +165,7 @@ GET_EVENT_ERROR:
|
||||
#endif
|
||||
}
|
||||
}
|
||||
GET_EVENT_ABORT:
|
||||
GET_EVENT_ABORT:
|
||||
pdu_len += len;
|
||||
bytes_sent =
|
||||
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
|
||||
|
||||
@@ -52,8 +52,8 @@ DATABLOCK MyData[MYMAXBLOCK];
|
||||
|
||||
uint8_t IOBufferPT[MAX_APDU]; /* Buffer for building response in */
|
||||
|
||||
void ProcessPT(BACNET_PRIVATE_TRANSFER_DATA *data)
|
||||
|
||||
void ProcessPT(
|
||||
BACNET_PRIVATE_TRANSFER_DATA * data)
|
||||
{
|
||||
int iLen; /* Index to current location in data */
|
||||
char cBlockNumber;
|
||||
@@ -67,17 +67,21 @@ void ProcessPT(BACNET_PRIVATE_TRANSFER_DATA *data)
|
||||
|
||||
/* Decode the block number */
|
||||
|
||||
tag_len = decode_tag_number_and_value(&data->serviceParameters[iLen], &tag_number, &len_value_type);
|
||||
tag_len =
|
||||
decode_tag_number_and_value(&data->serviceParameters[iLen],
|
||||
&tag_number, &len_value_type);
|
||||
iLen += tag_len;
|
||||
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) { /* Bail out early if wrong type */
|
||||
data->serviceParametersLen = 0; /* and signal unexpected error */
|
||||
return;
|
||||
}
|
||||
|
||||
iLen += decode_unsigned(&data->serviceParameters[iLen], len_value_type, &ulTemp);
|
||||
cBlockNumber = (char)ulTemp;
|
||||
if(cBlockNumber < MY_MAX_BLOCK) {
|
||||
if(data->serviceNumber == MY_SVC_READ) {
|
||||
iLen +=
|
||||
decode_unsigned(&data->serviceParameters[iLen], len_value_type,
|
||||
&ulTemp);
|
||||
cBlockNumber = (char) ulTemp;
|
||||
if (cBlockNumber < MY_MAX_BLOCK) {
|
||||
if (data->serviceNumber == MY_SVC_READ) {
|
||||
/* Read Response is an unsigned int with 0 for success or a non 0 error code */
|
||||
/* For a successful read the 0 success code is followed by the block number */
|
||||
/* and then the block contents which consist of 2 unsigned ints (in 0 to 255 */
|
||||
@@ -89,56 +93,75 @@ void ProcessPT(BACNET_PRIVATE_TRANSFER_DATA *data)
|
||||
iLen += encode_application_unsigned(&IOBufferPT[iLen], MY_ERR_OK); /* Signal success */
|
||||
iLen += encode_application_unsigned(&IOBufferPT[iLen], cBlockNumber); /* Followed by the block number */
|
||||
iLen += encode_application_unsigned(&IOBufferPT[iLen], MyData[cBlockNumber].cMyByte1); /* And Then the block contents */
|
||||
iLen += encode_application_unsigned(&IOBufferPT[iLen], MyData[cBlockNumber].cMyByte2);
|
||||
iLen += encode_application_real(&IOBufferPT[iLen], MyData[cBlockNumber].fMyReal);
|
||||
iLen +=
|
||||
encode_application_unsigned(&IOBufferPT[iLen],
|
||||
MyData[cBlockNumber].cMyByte2);
|
||||
iLen +=
|
||||
encode_application_real(&IOBufferPT[iLen],
|
||||
MyData[cBlockNumber].fMyReal);
|
||||
characterstring_init_ansi(&bsTemp, MyData[cBlockNumber].sMyString);
|
||||
iLen += encode_application_character_string(&IOBufferPT[iLen], &bsTemp);
|
||||
}
|
||||
else { /* Write operation */
|
||||
iLen +=
|
||||
encode_application_character_string(&IOBufferPT[iLen],
|
||||
&bsTemp);
|
||||
} else { /* Write operation */
|
||||
/* Write block consists of the block number followed by the block contents as */
|
||||
/* described above for the read operation. The returned result is an unsigned */
|
||||
/* response which is 0 for success and a non 0 error code otherwise. */
|
||||
|
||||
tag_len = decode_tag_number_and_value(&data->serviceParameters[iLen], &tag_number, &len_value_type);
|
||||
tag_len =
|
||||
decode_tag_number_and_value(&data->serviceParameters[iLen],
|
||||
&tag_number, &len_value_type);
|
||||
iLen += tag_len;
|
||||
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) {
|
||||
data->serviceParametersLen = 0;
|
||||
return;
|
||||
}
|
||||
iLen += decode_unsigned(&data->serviceParameters[iLen], len_value_type, &ulTemp);
|
||||
MyData[cBlockNumber].cMyByte1 = (char)ulTemp;
|
||||
iLen +=
|
||||
decode_unsigned(&data->serviceParameters[iLen], len_value_type,
|
||||
&ulTemp);
|
||||
MyData[cBlockNumber].cMyByte1 = (char) ulTemp;
|
||||
|
||||
tag_len = decode_tag_number_and_value(&data->serviceParameters[iLen], &tag_number, &len_value_type);
|
||||
tag_len =
|
||||
decode_tag_number_and_value(&data->serviceParameters[iLen],
|
||||
&tag_number, &len_value_type);
|
||||
iLen += tag_len;
|
||||
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) {
|
||||
data->serviceParametersLen = 0;
|
||||
return;
|
||||
}
|
||||
iLen += decode_unsigned(&data->serviceParameters[iLen], len_value_type, &ulTemp);
|
||||
MyData[cBlockNumber].cMyByte2 = (char)ulTemp;
|
||||
iLen +=
|
||||
decode_unsigned(&data->serviceParameters[iLen], len_value_type,
|
||||
&ulTemp);
|
||||
MyData[cBlockNumber].cMyByte2 = (char) ulTemp;
|
||||
|
||||
tag_len = decode_tag_number_and_value(&data->serviceParameters[iLen], &tag_number, &len_value_type);
|
||||
tag_len =
|
||||
decode_tag_number_and_value(&data->serviceParameters[iLen],
|
||||
&tag_number, &len_value_type);
|
||||
iLen += tag_len;
|
||||
if (tag_number != BACNET_APPLICATION_TAG_REAL) {
|
||||
data->serviceParametersLen = 0;
|
||||
return;
|
||||
}
|
||||
iLen += decode_real(&data->serviceParameters[iLen], &MyData[cBlockNumber].fMyReal);
|
||||
iLen +=
|
||||
decode_real(&data->serviceParameters[iLen],
|
||||
&MyData[cBlockNumber].fMyReal);
|
||||
|
||||
tag_len = decode_tag_number_and_value(&data->serviceParameters[iLen], &tag_number, &len_value_type);
|
||||
tag_len =
|
||||
decode_tag_number_and_value(&data->serviceParameters[iLen],
|
||||
&tag_number, &len_value_type);
|
||||
iLen += tag_len;
|
||||
if (tag_number != BACNET_APPLICATION_TAG_CHARACTER_STRING) {
|
||||
data->serviceParametersLen = 0;
|
||||
return;
|
||||
}
|
||||
decode_character_string(&data->serviceParameters[iLen], len_value_type, &bsTemp);
|
||||
decode_character_string(&data->serviceParameters[iLen],
|
||||
len_value_type, &bsTemp);
|
||||
strncpy(MyData[cBlockNumber].sMyString, characterstring_value(&bsTemp), MY_MAX_STR); /* Only copy as much as we can accept */
|
||||
MyData[cBlockNumber].sMyString[MY_MAX_STR] = '\0'; /* Make sure it is nul terminated */
|
||||
|
||||
iLen = encode_application_unsigned(&IOBufferPT[0], MY_ERR_OK); /* Signal success */
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
iLen = encode_application_unsigned(&IOBufferPT[0], MY_ERR_BAD_INDEX); /* Signal bad index */
|
||||
}
|
||||
data->serviceParametersLen = iLen;
|
||||
@@ -180,31 +203,37 @@ void handler_conf_private_trans(
|
||||
error_code = ERROR_CODE_UNKNOWN_OBJECT;
|
||||
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr,"Received Confirmed Private Transfer Request!\n");
|
||||
fprintf(stderr, "Received Confirmed Private Transfer Request!\n");
|
||||
#endif
|
||||
/* encode the NPDU portion of the response packet as it will be needed */
|
||||
/* no matter what the outcome. */
|
||||
|
||||
datalink_get_my_address(&my_address);
|
||||
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
|
||||
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
|
||||
pdu_len =
|
||||
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
|
||||
&npdu_data);
|
||||
|
||||
if (service_data->segmented_message)
|
||||
{
|
||||
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
|
||||
if (service_data->segmented_message) {
|
||||
len =
|
||||
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
|
||||
true);
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr,"CPT: Segmented Message. Sending Abort!\n");
|
||||
fprintf(stderr, "CPT: Segmented Message. Sending Abort!\n");
|
||||
#endif
|
||||
goto CPT_ABORT;
|
||||
}
|
||||
|
||||
len = ptransfer_decode_service_request(service_request, service_len, &data);
|
||||
len =
|
||||
ptransfer_decode_service_request(service_request, service_len, &data);
|
||||
/* bad decoding - send an abort */
|
||||
if (len < 0)
|
||||
{
|
||||
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_OTHER, true);
|
||||
if (len < 0) {
|
||||
len =
|
||||
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||
service_data->invoke_id, ABORT_REASON_OTHER, true);
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr,"CPT: Bad Encoding. Sending Abort!\n");
|
||||
fprintf(stderr, "CPT: Bad Encoding. Sending Abort!\n");
|
||||
#endif
|
||||
goto CPT_ABORT;
|
||||
}
|
||||
@@ -213,43 +242,45 @@ void handler_conf_private_trans(
|
||||
/* We also only support our own vendor ID. In theory we could support others */
|
||||
/* for compatability purposes but these interfaces are rarely documented... */
|
||||
|
||||
if((data.vendorID == BACNET_VENDOR_ID) && (data.serviceNumber <= MY_SVC_WRITE)){ /* We only try to understand our own IDs and service numbers */
|
||||
if ((data.vendorID == BACNET_VENDOR_ID) && (data.serviceNumber <= MY_SVC_WRITE)) { /* We only try to understand our own IDs and service numbers */
|
||||
ProcessPT(&data); /* Will either return a result block or an app level status block */
|
||||
if(data.serviceParametersLen == 0){ /* No respopnse means fatal error */
|
||||
if (data.serviceParametersLen == 0) { /* No respopnse means fatal error */
|
||||
error = true;
|
||||
error_class = ERROR_CLASS_SERVICES;
|
||||
error_code = ERROR_CODE_OTHER;
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr,"CPT: Error servicing request!\n");
|
||||
#endif
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "CPT: Error servicing request!\n");
|
||||
#endif
|
||||
}
|
||||
len = ptransfer_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &data);
|
||||
}
|
||||
else /* Not our vendor ID or bad service parameter */
|
||||
{
|
||||
len =
|
||||
ptransfer_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||
service_data->invoke_id, &data);
|
||||
} else { /* Not our vendor ID or bad service parameter */
|
||||
|
||||
error = true;
|
||||
error_class = ERROR_CLASS_SERVICES;
|
||||
error_code = ERROR_CODE_OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED;
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr,"CPT: Not our Vendor ID or invalid service code!\n");
|
||||
fprintf(stderr, "CPT: Not our Vendor ID or invalid service code!\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
if (error){
|
||||
len = ptransfer_error_encode_apdu(&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, error_class, error_code, &data);
|
||||
if (error) {
|
||||
len =
|
||||
ptransfer_error_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||
service_data->invoke_id, error_class, error_code, &data);
|
||||
}
|
||||
CPT_ABORT:
|
||||
pdu_len += len;
|
||||
bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
|
||||
CPT_ABORT:
|
||||
pdu_len += len;
|
||||
bytes_sent =
|
||||
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
|
||||
pdu_len);
|
||||
|
||||
#if PRINT_ENABLED
|
||||
if (bytes_sent <= 0)
|
||||
{
|
||||
fprintf(stderr,"Failed to send PDU (%s)!\n",
|
||||
strerror(errno));
|
||||
if (bytes_sent <= 0) {
|
||||
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
|
||||
}
|
||||
#endif
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,8 +48,9 @@
|
||||
extern uint8_t IOBufferPT[300]; /* Somewhere to build the encoded result block for Private Transfers */
|
||||
|
||||
|
||||
void DecodeBlock(char cBlockNum, uint8_t *pData)
|
||||
|
||||
void DecodeBlock(
|
||||
char cBlockNum,
|
||||
uint8_t * pData)
|
||||
{
|
||||
int iLen;
|
||||
uint32_t ulTemp;
|
||||
@@ -61,33 +62,41 @@ void DecodeBlock(char cBlockNum, uint8_t *pData)
|
||||
|
||||
iLen = 0;
|
||||
|
||||
if(cBlockNum >= MY_MAX_BLOCK)
|
||||
if (cBlockNum >= MY_MAX_BLOCK)
|
||||
return;
|
||||
|
||||
tag_len = decode_tag_number_and_value(&pData[iLen], &tag_number, &len_value_type);
|
||||
tag_len =
|
||||
decode_tag_number_and_value(&pData[iLen], &tag_number,
|
||||
&len_value_type);
|
||||
iLen += tag_len;
|
||||
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT)
|
||||
return;
|
||||
|
||||
iLen += decode_unsigned(&pData[iLen], len_value_type, &ulTemp);
|
||||
Response.cMyByte1 = (char)ulTemp;
|
||||
Response.cMyByte1 = (char) ulTemp;
|
||||
|
||||
tag_len = decode_tag_number_and_value(&pData[iLen], &tag_number, &len_value_type);
|
||||
tag_len =
|
||||
decode_tag_number_and_value(&pData[iLen], &tag_number,
|
||||
&len_value_type);
|
||||
iLen += tag_len;
|
||||
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT)
|
||||
return;
|
||||
|
||||
iLen += decode_unsigned(&pData[iLen], len_value_type, &ulTemp);
|
||||
Response.cMyByte2 = (char)ulTemp;
|
||||
Response.cMyByte2 = (char) ulTemp;
|
||||
|
||||
tag_len = decode_tag_number_and_value(&pData[iLen], &tag_number, &len_value_type);
|
||||
tag_len =
|
||||
decode_tag_number_and_value(&pData[iLen], &tag_number,
|
||||
&len_value_type);
|
||||
iLen += tag_len;
|
||||
if (tag_number != BACNET_APPLICATION_TAG_REAL)
|
||||
return;
|
||||
|
||||
iLen += decode_real(&pData[iLen], &Response.fMyReal);
|
||||
|
||||
tag_len = decode_tag_number_and_value(&pData[iLen], &tag_number, &len_value_type);
|
||||
tag_len =
|
||||
decode_tag_number_and_value(&pData[iLen], &tag_number,
|
||||
&len_value_type);
|
||||
iLen += tag_len;
|
||||
if (tag_number != BACNET_APPLICATION_TAG_CHARACTER_STRING)
|
||||
return;
|
||||
@@ -97,17 +106,17 @@ void DecodeBlock(char cBlockNum, uint8_t *pData)
|
||||
Response.sMyString[MY_MAX_STR] = '\0'; /* Make sure it is nul terminated */
|
||||
|
||||
printf("Private Transfer Read Block Response\n");
|
||||
printf("Data Block: %d\n", (int)cBlockNum);
|
||||
printf(" First Byte : %d\n", (int)Response.cMyByte1);
|
||||
printf(" Second Byte : %d\n", (int)Response.cMyByte2);
|
||||
printf("Data Block: %d\n", (int) cBlockNum);
|
||||
printf(" First Byte : %d\n", (int) Response.cMyByte1);
|
||||
printf(" Second Byte : %d\n", (int) Response.cMyByte2);
|
||||
printf(" Real : %f\n", Response.fMyReal);
|
||||
printf(" String : %s\n\n", Response.sMyString);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ProcessPTA(BACNET_PRIVATE_TRANSFER_DATA *data)
|
||||
|
||||
void ProcessPTA(
|
||||
BACNET_PRIVATE_TRANSFER_DATA * data)
|
||||
{
|
||||
int iLen; /* Index to current location in data */
|
||||
uint32_t uiErrorCode;
|
||||
@@ -121,7 +130,9 @@ void ProcessPTA(BACNET_PRIVATE_TRANSFER_DATA *data)
|
||||
|
||||
/* Error code is returned for read and write operations */
|
||||
|
||||
tag_len = decode_tag_number_and_value(&data->serviceParameters[iLen], &tag_number, &len_value_type);
|
||||
tag_len =
|
||||
decode_tag_number_and_value(&data->serviceParameters[iLen],
|
||||
&tag_number, &len_value_type);
|
||||
iLen += tag_len;
|
||||
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) {
|
||||
#if PRINT_ENABLED
|
||||
@@ -129,14 +140,18 @@ void ProcessPTA(BACNET_PRIVATE_TRANSFER_DATA *data)
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
iLen += decode_unsigned(&data->serviceParameters[iLen], len_value_type, &uiErrorCode);
|
||||
iLen +=
|
||||
decode_unsigned(&data->serviceParameters[iLen], len_value_type,
|
||||
&uiErrorCode);
|
||||
|
||||
if(data->serviceNumber == MY_SVC_READ) { /* Read I/O block so should be full block of data or error */
|
||||
if (data->serviceNumber == MY_SVC_READ) { /* Read I/O block so should be full block of data or error */
|
||||
/* Decode the error type and if necessary block number and then fetch the info */
|
||||
|
||||
if(uiErrorCode == MY_ERR_OK) {
|
||||
if (uiErrorCode == MY_ERR_OK) {
|
||||
/* Block Number */
|
||||
tag_len = decode_tag_number_and_value(&data->serviceParameters[iLen], &tag_number, &len_value_type);
|
||||
tag_len =
|
||||
decode_tag_number_and_value(&data->serviceParameters[iLen],
|
||||
&tag_number, &len_value_type);
|
||||
iLen += tag_len;
|
||||
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) {
|
||||
#if PRINT_ENABLED
|
||||
@@ -145,17 +160,19 @@ void ProcessPTA(BACNET_PRIVATE_TRANSFER_DATA *data)
|
||||
return;
|
||||
}
|
||||
|
||||
iLen += decode_unsigned(&data->serviceParameters[iLen], len_value_type, &ulTemp);
|
||||
cBlockNumber = (char)ulTemp;
|
||||
iLen +=
|
||||
decode_unsigned(&data->serviceParameters[iLen], len_value_type,
|
||||
&ulTemp);
|
||||
cBlockNumber = (char) ulTemp;
|
||||
DecodeBlock(cBlockNumber, &data->serviceParameters[iLen]);
|
||||
}
|
||||
else { /* Read error */
|
||||
printf("Private Transfer read operation returned error code: %u\n", uiErrorCode);
|
||||
} else { /* Read error */
|
||||
printf("Private Transfer read operation returned error code: %u\n",
|
||||
uiErrorCode);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else { /* Write I/O block - should just be an OK type message */
|
||||
printf("Private Transfer write operation returned error code: %u\n", uiErrorCode);
|
||||
} else { /* Write I/O block - should just be an OK type message */
|
||||
printf("Private Transfer write operation returned error code: %u\n",
|
||||
uiErrorCode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,8 +212,7 @@ void handler_conf_private_trans_ack(
|
||||
#endif
|
||||
|
||||
len = ptransfer_decode_service_request(service_request, service_len, &data); /* Same decode for ack as for service request! */
|
||||
if (len < 0)
|
||||
{
|
||||
if (len < 0) {
|
||||
#if PRINT_ENABLED
|
||||
printf("cpta: Bad Encoding!\n");
|
||||
#endif
|
||||
@@ -204,7 +220,7 @@ void handler_conf_private_trans_ack(
|
||||
|
||||
ProcessPTA(&data); /* See what to do with the response */
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
#if 0
|
||||
@@ -223,4 +239,3 @@ void PTErrorHandler(
|
||||
Error_Detected = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -39,11 +39,9 @@
|
||||
|
||||
static uint8_t Temp_Buf[MAX_APDU] = { 0 };
|
||||
|
||||
static read_property_function
|
||||
Read_Property[MAX_BACNET_OBJECT_TYPE];
|
||||
static read_property_function Read_Property[MAX_BACNET_OBJECT_TYPE];
|
||||
|
||||
static object_valid_instance_function
|
||||
Valid_Instance[MAX_BACNET_OBJECT_TYPE];
|
||||
static object_valid_instance_function Valid_Instance[MAX_BACNET_OBJECT_TYPE];
|
||||
|
||||
void handler_read_property_object_set(
|
||||
BACNET_OBJECT_TYPE object_type,
|
||||
@@ -79,11 +77,10 @@ int Encode_Property_APDU(
|
||||
object_rp = Read_Property[object_type];
|
||||
object_valid = Valid_Instance[object_type];
|
||||
}
|
||||
if (object_rp && object_valid &&
|
||||
object_valid(object_instance)) {
|
||||
apdu_len = object_rp(
|
||||
&apdu[0], object_instance, property,
|
||||
array_index, error_class, error_code);
|
||||
if (object_rp && object_valid && object_valid(object_instance)) {
|
||||
apdu_len =
|
||||
object_rp(&apdu[0], object_instance, property, array_index,
|
||||
error_class, error_code);
|
||||
} else {
|
||||
*error_class = ERROR_CLASS_OBJECT;
|
||||
*error_code = ERROR_CODE_UNSUPPORTED_OBJECT_TYPE;
|
||||
|
||||
@@ -41,8 +41,7 @@
|
||||
|
||||
static uint8_t Temp_Buf[MAX_APDU] = { 0 };
|
||||
|
||||
static rpm_property_lists_function
|
||||
RPM_Lists[MAX_BACNET_OBJECT_TYPE];
|
||||
static rpm_property_lists_function RPM_Lists[MAX_BACNET_OBJECT_TYPE];
|
||||
|
||||
struct property_list_t {
|
||||
const int *pList;
|
||||
@@ -93,10 +92,8 @@ static void RPM_Property_List(
|
||||
object_property_list = RPM_Lists[object_type];
|
||||
}
|
||||
if (object_property_list) {
|
||||
object_property_list(
|
||||
&pPropertyList->Required.pList,
|
||||
&pPropertyList->Optional.pList,
|
||||
&pPropertyList->Proprietary.pList);
|
||||
object_property_list(&pPropertyList->Required.pList,
|
||||
&pPropertyList->Optional.pList, &pPropertyList->Proprietary.pList);
|
||||
}
|
||||
/* fill the count */
|
||||
if (pPropertyList->Required.pList) {
|
||||
|
||||
@@ -208,8 +208,8 @@ static void PrintReadPropertyMultipleData(
|
||||
#if PRINT_ENABLED
|
||||
if (listOfProperties->propertyIdentifier < 512) {
|
||||
fprintf(stdout, " %s: ",
|
||||
bactext_property_name(
|
||||
listOfProperties->propertyIdentifier));
|
||||
bactext_property_name(listOfProperties->
|
||||
propertyIdentifier));
|
||||
} else {
|
||||
fprintf(stdout, " proprietary %u: ",
|
||||
listOfProperties->propertyIdentifier);
|
||||
@@ -250,10 +250,10 @@ static void PrintReadPropertyMultipleData(
|
||||
#if PRINT_ENABLED
|
||||
/* AccessError */
|
||||
fprintf(stdout, "BACnet Error: %s: %s\r\n",
|
||||
bactext_error_class_name((int) listOfProperties->error.
|
||||
error_class),
|
||||
bactext_error_code_name((int) listOfProperties->error.
|
||||
error_code));
|
||||
bactext_error_class_name((int) listOfProperties->
|
||||
error.error_class),
|
||||
bactext_error_code_name((int) listOfProperties->
|
||||
error.error_code));
|
||||
#endif
|
||||
}
|
||||
listOfProperties = listOfProperties->next;
|
||||
|
||||
@@ -43,7 +43,7 @@ static uint8_t Temp_Buf[MAX_APDU] = { 0 };
|
||||
or sets the error, and returns -1 */
|
||||
int Encode_RR_payload(
|
||||
uint8_t * apdu,
|
||||
BACNET_READ_RANGE_DATA *pRequest,
|
||||
BACNET_READ_RANGE_DATA * pRequest,
|
||||
BACNET_ERROR_CLASS * error_class,
|
||||
BACNET_ERROR_CODE * error_code)
|
||||
{
|
||||
@@ -91,10 +91,15 @@ void handler_read_range(
|
||||
/* encode the NPDU portion of the packet */
|
||||
datalink_get_my_address(&my_address);
|
||||
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
|
||||
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
|
||||
pdu_len =
|
||||
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
|
||||
&npdu_data);
|
||||
if (service_data->segmented_message) {
|
||||
/* we don't support segmentation - send an abort */
|
||||
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
|
||||
len =
|
||||
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
|
||||
true);
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "RR: Segmented message. Sending Abort!\n");
|
||||
#endif
|
||||
@@ -108,7 +113,9 @@ void handler_read_range(
|
||||
#endif
|
||||
if (len < 0) {
|
||||
/* bad decoding - send an abort */
|
||||
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_OTHER, true);
|
||||
len =
|
||||
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||
service_data->invoke_id, ABORT_REASON_OTHER, true);
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "RR: Bad Encoding. Sending Abort!\n");
|
||||
#endif
|
||||
@@ -123,7 +130,9 @@ void handler_read_range(
|
||||
data.application_data = &Temp_Buf[0];
|
||||
data.application_data_len = len;
|
||||
/* FIXME: probably need a length limitation sent with encode */
|
||||
len = rr_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &data);
|
||||
len =
|
||||
rr_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||
service_data->invoke_id, &data);
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "RR: Sending Ack!\n");
|
||||
#endif
|
||||
@@ -132,12 +141,18 @@ void handler_read_range(
|
||||
if (error) {
|
||||
if (len == -2) {
|
||||
/* BACnet APDU too small to fit data, so proper response is Abort */
|
||||
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
|
||||
len =
|
||||
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||
service_data->invoke_id,
|
||||
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "RR: Reply too big to fit into APDU!\n");
|
||||
#endif
|
||||
} else {
|
||||
len = bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, SERVICE_CONFIRMED_READ_PROPERTY, error_class, error_code);
|
||||
len =
|
||||
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||
service_data->invoke_id, SERVICE_CONFIRMED_READ_PROPERTY,
|
||||
error_class, error_code);
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "RR: Sending Error!\n");
|
||||
#endif
|
||||
@@ -145,7 +160,9 @@ void handler_read_range(
|
||||
}
|
||||
RR_ABORT:
|
||||
pdu_len += len;
|
||||
bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
|
||||
bytes_sent =
|
||||
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
|
||||
pdu_len);
|
||||
#if PRINT_ENABLED
|
||||
if (bytes_sent <= 0)
|
||||
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
|
||||
|
||||
@@ -58,7 +58,9 @@ static void PrintReadRangeData(
|
||||
/* FIXME: what if application_data_len is bigger than 255? */
|
||||
/* value? need to loop until all of the len is gone... */
|
||||
for (;;) {
|
||||
len = bacapp_decode_application_data(application_data, (uint8_t) application_data_len, &value);
|
||||
len =
|
||||
bacapp_decode_application_data(application_data,
|
||||
(uint8_t) application_data_len, &value);
|
||||
if (first_value && (len < application_data_len)) {
|
||||
first_value = false;
|
||||
#if PRINT_ENABLED
|
||||
|
||||
@@ -45,18 +45,17 @@ void handler_unconfirmed_private_transfer(
|
||||
int len = 0;
|
||||
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr,"Received Unconfirmed Private Transfer Request!\n");
|
||||
fprintf(stderr, "Received Unconfirmed Private Transfer Request!\n");
|
||||
#endif
|
||||
(void) src;
|
||||
len = ptransfer_decode_service_request(
|
||||
service_request, service_len, &private_data);
|
||||
len =
|
||||
ptransfer_decode_service_request(service_request, service_len,
|
||||
&private_data);
|
||||
if (len >= 0) {
|
||||
#if PRINT_ENABLED
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr,
|
||||
"UnconfirmedPrivateTransfer: "
|
||||
"vendorID=%u serviceNumber=%u\n",
|
||||
"UnconfirmedPrivateTransfer: " "vendorID=%u serviceNumber=%u\n",
|
||||
private_data.vendorID, private_data.serviceNumber);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,8 +37,7 @@
|
||||
#include "abort.h"
|
||||
#include "wp.h"
|
||||
|
||||
static write_property_function
|
||||
Write_Property[MAX_BACNET_OBJECT_TYPE];
|
||||
static write_property_function Write_Property[MAX_BACNET_OBJECT_TYPE];
|
||||
|
||||
void handler_write_property_object_set(
|
||||
BACNET_OBJECT_TYPE object_type,
|
||||
|
||||
@@ -62,13 +62,12 @@ uint8_t Send_CEvent_Notify(
|
||||
datalink_get_my_address(&my_address);
|
||||
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
|
||||
pdu_len =
|
||||
npdu_encode_pdu(
|
||||
&Handler_Transmit_Buffer[0],
|
||||
&dest, &my_address,
|
||||
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
|
||||
&npdu_data);
|
||||
/* encode the APDU portion of the packet */
|
||||
len = cevent_notify_encode_apdu(
|
||||
&Handler_Transmit_Buffer[pdu_len], invoke_id, data);
|
||||
len =
|
||||
cevent_notify_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||
invoke_id, data);
|
||||
pdu_len += len;
|
||||
/* will it fit in the sender?
|
||||
note: if there is a bottleneck router in between
|
||||
@@ -77,8 +76,7 @@ uint8_t Send_CEvent_Notify(
|
||||
max_apdu in the address binding table. */
|
||||
if ((unsigned) pdu_len < max_apdu) {
|
||||
tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest,
|
||||
&npdu_data, &Handler_Transmit_Buffer[0],
|
||||
(uint16_t) pdu_len);
|
||||
&npdu_data, &Handler_Transmit_Buffer[0], (uint16_t) pdu_len);
|
||||
bytes_sent =
|
||||
datalink_send_pdu(&dest, &npdu_data,
|
||||
&Handler_Transmit_Buffer[0], pdu_len);
|
||||
|
||||
@@ -51,9 +51,7 @@ uint8_t Send_Private_Transfer_Request(
|
||||
uint16_t vendor_id,
|
||||
uint32_t service_number,
|
||||
char block_number,
|
||||
DATABLOCK *block
|
||||
)
|
||||
|
||||
DATABLOCK * block)
|
||||
{ /* NULL=optional */
|
||||
BACNET_ADDRESS dest;
|
||||
BACNET_ADDRESS my_address;
|
||||
@@ -88,23 +86,27 @@ uint8_t Send_Private_Transfer_Request(
|
||||
|
||||
pt_block.vendorID = vendor_id;
|
||||
pt_block.serviceNumber = service_number;
|
||||
if(service_number == MY_SVC_READ)
|
||||
{
|
||||
if (service_number == MY_SVC_READ) {
|
||||
len += encode_application_unsigned(&pt_req_buffer[len], block_number); /* The block number we want to retrieve */
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
len += encode_application_unsigned(&pt_req_buffer[len], block_number); /* The block number */
|
||||
len += encode_application_unsigned(&pt_req_buffer[len], block->cMyByte1); /* And Then the block contents */
|
||||
len += encode_application_unsigned(&pt_req_buffer[len], block->cMyByte2);
|
||||
len += encode_application_real(&pt_req_buffer[len], block->fMyReal);
|
||||
len +=
|
||||
encode_application_unsigned(&pt_req_buffer[len],
|
||||
block->cMyByte2);
|
||||
len +=
|
||||
encode_application_real(&pt_req_buffer[len], block->fMyReal);
|
||||
characterstring_init_ansi(&bsTemp, block->sMyString);
|
||||
len += encode_application_character_string(&pt_req_buffer[len], &bsTemp);
|
||||
len +=
|
||||
encode_application_character_string(&pt_req_buffer[len],
|
||||
&bsTemp);
|
||||
}
|
||||
|
||||
pt_block.serviceParameters = &pt_req_buffer[0];
|
||||
pt_block.serviceParametersLen = len;
|
||||
len = ptransfer_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id, &pt_block);
|
||||
len =
|
||||
ptransfer_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id,
|
||||
&pt_block);
|
||||
pdu_len += len;
|
||||
|
||||
/* will it fit in the sender?
|
||||
|
||||
@@ -72,10 +72,14 @@ uint8_t Send_ReadRange_Request(
|
||||
/* encode the NPDU portion of the packet */
|
||||
datalink_get_my_address(&my_address);
|
||||
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
|
||||
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address, &npdu_data);
|
||||
pdu_len =
|
||||
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
|
||||
&npdu_data);
|
||||
|
||||
/* encode the APDU portion of the packet */
|
||||
len = rr_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id, read_access_data);
|
||||
len =
|
||||
rr_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id,
|
||||
read_access_data);
|
||||
if (len <= 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -87,18 +91,22 @@ uint8_t Send_ReadRange_Request(
|
||||
we have a way to check for that and update the
|
||||
max_apdu in the address binding table. */
|
||||
if ((unsigned) pdu_len < max_apdu) {
|
||||
tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0], (uint16_t)pdu_len);
|
||||
bytes_sent = datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
|
||||
tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest,
|
||||
&npdu_data, &Handler_Transmit_Buffer[0], (uint16_t) pdu_len);
|
||||
bytes_sent =
|
||||
datalink_send_pdu(&dest, &npdu_data,
|
||||
&Handler_Transmit_Buffer[0], pdu_len);
|
||||
#if PRINT_ENABLED
|
||||
if (bytes_sent <= 0)
|
||||
fprintf(stderr,
|
||||
"Failed to Send ReadRange Request (%s)!\n", strerror(errno));
|
||||
fprintf(stderr, "Failed to Send ReadRange Request (%s)!\n",
|
||||
strerror(errno));
|
||||
#endif
|
||||
} else {
|
||||
tsm_free_invoke_id(invoke_id);
|
||||
invoke_id = 0;
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "Failed to Send ReadRange Request (exceeds destination maximum APDU)!\n");
|
||||
fprintf(stderr,
|
||||
"Failed to Send ReadRange Request (exceeds destination maximum APDU)!\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
|
||||
void Send_UnconfirmedPrivateTransfer(
|
||||
BACNET_ADDRESS * dest,
|
||||
BACNET_PRIVATE_TRANSFER_DATA *private_data)
|
||||
BACNET_PRIVATE_TRANSFER_DATA * private_data)
|
||||
{
|
||||
int len = 0;
|
||||
int pdu_len = 0;
|
||||
@@ -60,8 +60,8 @@ void Send_UnconfirmedPrivateTransfer(
|
||||
pdu_len =
|
||||
npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest, NULL, &npdu_data);
|
||||
/* encode the APDU portion of the packet */
|
||||
len = uptransfer_encode_apdu(
|
||||
&Handler_Transmit_Buffer[pdu_len],
|
||||
len =
|
||||
uptransfer_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||
private_data);
|
||||
pdu_len += len;
|
||||
bytes_sent =
|
||||
|
||||
@@ -139,8 +139,9 @@ uint8_t Send_Write_Property_Request(
|
||||
#if PRINT_ENABLED_DEBUG
|
||||
fprintf(stderr, "WriteProperty service: " "%s tag=%d\n",
|
||||
(object_value->context_specific ? "context" : "application"),
|
||||
(int) (object_value->context_specific ? object_value->
|
||||
context_tag : object_value->tag));
|
||||
(int) (object_value->
|
||||
context_specific ? object_value->context_tag : object_value->
|
||||
tag));
|
||||
#endif
|
||||
len = bacapp_encode_data(&application_data[apdu_len], object_value);
|
||||
if ((len + apdu_len) < MAX_APDU) {
|
||||
|
||||
@@ -85,10 +85,8 @@ static void Init_Service_Handlers(
|
||||
void)
|
||||
{
|
||||
Device_Init();
|
||||
handler_read_property_object_set(
|
||||
OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU,
|
||||
Device_Valid_Object_Instance_Number);
|
||||
handler_read_property_object_set(OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU, Device_Valid_Object_Instance_Number);
|
||||
/* we need to handle who-is
|
||||
to support dynamic device binding to us */
|
||||
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is);
|
||||
|
||||
@@ -207,10 +207,8 @@ static void Init_Service_Handlers(
|
||||
void)
|
||||
{
|
||||
Device_Init();
|
||||
handler_read_property_object_set(
|
||||
OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU,
|
||||
Device_Valid_Object_Instance_Number);
|
||||
handler_read_property_object_set(OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU, Device_Valid_Object_Instance_Number);
|
||||
/* we need to handle who-is
|
||||
to support dynamic device binding to us */
|
||||
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is);
|
||||
|
||||
@@ -288,16 +288,13 @@ static FILE *pFile = NULL; /* stream pointer */
|
||||
#if defined(_WIN32)
|
||||
static HANDLE hPipe = NULL; /* pipe handle */
|
||||
|
||||
static void named_pipe_create(char *name)
|
||||
static void named_pipe_create(
|
||||
char *name)
|
||||
{
|
||||
fprintf(stdout, "mstpcap: Creating Named Pipe \"%s\"\n", name);
|
||||
hPipe = CreateNamedPipe(
|
||||
name,
|
||||
PIPE_ACCESS_OUTBOUND,
|
||||
PIPE_TYPE_MESSAGE | PIPE_WAIT,
|
||||
1, 65536, 65536,
|
||||
300,
|
||||
NULL);
|
||||
hPipe =
|
||||
CreateNamedPipe(name, PIPE_ACCESS_OUTBOUND,
|
||||
PIPE_TYPE_MESSAGE | PIPE_WAIT, 1, 65536, 65536, 300, NULL);
|
||||
if (hPipe == INVALID_HANDLE_VALUE) {
|
||||
RS485_Print_Error();
|
||||
return;
|
||||
@@ -305,14 +302,16 @@ static void named_pipe_create(char *name)
|
||||
ConnectNamedPipe(hPipe, NULL);
|
||||
}
|
||||
|
||||
size_t data_write(const void *ptr, size_t size, size_t nitems)
|
||||
size_t data_write(
|
||||
const void *ptr,
|
||||
size_t size,
|
||||
size_t nitems)
|
||||
{
|
||||
DWORD cbWritten = 0;
|
||||
if (hPipe != INVALID_HANDLE_VALUE) {
|
||||
(void)WriteFile(
|
||||
hPipe, /* handle to pipe */
|
||||
(void) WriteFile(hPipe, /* handle to pipe */
|
||||
ptr, /* buffer to write from */
|
||||
size*nitems, /* number of bytes to write */
|
||||
size * nitems, /* number of bytes to write */
|
||||
&cbWritten, /* number of bytes written */
|
||||
NULL); /* not overlapped I/O */
|
||||
}
|
||||
@@ -321,12 +320,12 @@ size_t data_write(const void *ptr, size_t size, size_t nitems)
|
||||
}
|
||||
#else
|
||||
static int FD_Pipe = -1;
|
||||
static void named_pipe_create(char *name)
|
||||
static void named_pipe_create(
|
||||
char *name)
|
||||
{
|
||||
int rv = 0;
|
||||
rv = mkfifo(name, 0666);
|
||||
if (( rv == -1) && (errno != EEXIST))
|
||||
{
|
||||
if ((rv == -1) && (errno != EEXIST)) {
|
||||
perror("Error creating named pipe");
|
||||
exit(1);
|
||||
}
|
||||
@@ -337,11 +336,14 @@ static void named_pipe_create(char *name)
|
||||
}
|
||||
}
|
||||
|
||||
size_t data_write(const void *ptr, size_t size, size_t nitems)
|
||||
size_t data_write(
|
||||
const void *ptr,
|
||||
size_t size,
|
||||
size_t nitems)
|
||||
{
|
||||
ssize_t bytes = 0;
|
||||
if (FD_Pipe != -1) {
|
||||
bytes = write(FD_Pipe, ptr, size*nitems);
|
||||
bytes = write(FD_Pipe, ptr, size * nitems);
|
||||
bytes = bytes;
|
||||
}
|
||||
return fwrite(ptr, size, nitems, pFile);
|
||||
|
||||
@@ -217,7 +217,8 @@ int Analog_Input_Encode_Property_APDU(
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
void Analog_Input_Init(void)
|
||||
void Analog_Input_Init(
|
||||
void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -433,8 +433,8 @@ bool Analog_Output_Write_Property(
|
||||
object_index =
|
||||
Analog_Output_Instance_To_Index(wp_data->object_instance);
|
||||
status =
|
||||
Analog_Output_Present_Value_Relinquish(wp_data->
|
||||
object_instance, wp_data->priority);
|
||||
Analog_Output_Present_Value_Relinquish
|
||||
(wp_data->object_instance, wp_data->priority);
|
||||
if (!status) {
|
||||
*error_class = ERROR_CLASS_PROPERTY;
|
||||
*error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
|
||||
|
||||
@@ -463,6 +463,7 @@ bool bacfile_write_stream_data(
|
||||
return found;
|
||||
}
|
||||
|
||||
void bacfile_init(void)
|
||||
void bacfile_init(
|
||||
void)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -364,8 +364,8 @@ bool Binary_Output_Write_Property(
|
||||
(value.type.Enumerated <= MAX_BINARY_PV)) {
|
||||
level = (BACNET_BINARY_PV) value.type.Enumerated;
|
||||
object_index =
|
||||
Binary_Output_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
Binary_Output_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
priority--;
|
||||
Binary_Output_Level[object_index][priority] = level;
|
||||
/* Note: you could set the physical output here if we
|
||||
|
||||
@@ -345,8 +345,8 @@ bool Binary_Value_Write_Property(
|
||||
(value.type.Enumerated <= MAX_BINARY_PV)) {
|
||||
level = (BACNET_BINARY_PV) value.type.Enumerated;
|
||||
object_index =
|
||||
Binary_Value_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
Binary_Value_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
priority--;
|
||||
Binary_Value_Level[object_index][priority] = level;
|
||||
/* Note: you could set the physical output here if we
|
||||
|
||||
@@ -42,12 +42,10 @@
|
||||
#include "bacfile.h" /* object list dependency */
|
||||
#endif
|
||||
|
||||
static object_count_function
|
||||
Object_Count[MAX_BACNET_OBJECT_TYPE];
|
||||
static object_count_function Object_Count[MAX_BACNET_OBJECT_TYPE];
|
||||
static object_index_to_instance_function
|
||||
Object_Index_To_Instance[MAX_BACNET_OBJECT_TYPE];
|
||||
static object_name_function
|
||||
Object_Name[MAX_BACNET_OBJECT_TYPE];
|
||||
static object_name_function Object_Name[MAX_BACNET_OBJECT_TYPE];
|
||||
|
||||
void Device_Object_Function_Set(
|
||||
BACNET_OBJECT_TYPE object_type,
|
||||
@@ -381,7 +379,7 @@ unsigned Device_Object_List_Count(
|
||||
|
||||
for (i = 0; i < MAX_BACNET_OBJECT_TYPE; i++) {
|
||||
if (Object_Count[i]) {
|
||||
count += Object_Count[i]();
|
||||
count += Object_Count[i] ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -417,10 +415,10 @@ bool Device_Object_List_Identifier(
|
||||
for (i = 0; i < MAX_BACNET_OBJECT_TYPE; i++) {
|
||||
if (Object_Count[i] && Object_Index_To_Instance[i]) {
|
||||
object_index -= count;
|
||||
count = Object_Count[i]();
|
||||
count = Object_Count[i] ();
|
||||
if (object_index < count) {
|
||||
*object_type = i;
|
||||
*instance = Object_Index_To_Instance[i](object_index);
|
||||
*instance = Object_Index_To_Instance[i] (object_index);
|
||||
status = true;
|
||||
break;
|
||||
}
|
||||
@@ -740,8 +738,8 @@ bool Device_Write_Property(
|
||||
case PROP_OBJECT_IDENTIFIER:
|
||||
if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) {
|
||||
if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
|
||||
(Device_Set_Object_Instance_Number(value.type.Object_Id.
|
||||
instance))) {
|
||||
(Device_Set_Object_Instance_Number(value.type.
|
||||
Object_Id.instance))) {
|
||||
/* FIXME: we could send an I-Am broadcast to let the world know */
|
||||
status = true;
|
||||
} else {
|
||||
@@ -776,8 +774,8 @@ bool Device_Write_Property(
|
||||
case PROP_VENDOR_IDENTIFIER:
|
||||
if (value.tag == BACNET_APPLICATION_TAG_UNSIGNED_INT) {
|
||||
/* FIXME: bounds check? */
|
||||
Device_Set_Vendor_Identifier((uint16_t) value.type.
|
||||
Unsigned_Int);
|
||||
Device_Set_Vendor_Identifier((uint16_t) value.
|
||||
type.Unsigned_Int);
|
||||
status = true;
|
||||
} else {
|
||||
*error_class = ERROR_CLASS_PROPERTY;
|
||||
@@ -787,8 +785,8 @@ bool Device_Write_Property(
|
||||
case PROP_SYSTEM_STATUS:
|
||||
if (value.tag == BACNET_APPLICATION_TAG_ENUMERATED) {
|
||||
/* FIXME: bounds check? */
|
||||
Device_Set_System_Status((BACNET_DEVICE_STATUS) value.type.
|
||||
Enumerated);
|
||||
Device_Set_System_Status((BACNET_DEVICE_STATUS) value.
|
||||
type.Enumerated);
|
||||
status = true;
|
||||
} else {
|
||||
*error_class = ERROR_CLASS_PROPERTY;
|
||||
@@ -802,8 +800,8 @@ bool Device_Write_Property(
|
||||
characterstring_encoding(&value.type.Character_String);
|
||||
if (encoding == CHARACTER_ANSI_X34) {
|
||||
status =
|
||||
Device_Set_Object_Name(characterstring_value(&value.
|
||||
type.Character_String),
|
||||
Device_Set_Object_Name(characterstring_value
|
||||
(&value.type.Character_String),
|
||||
characterstring_length(&value.type.Character_String));
|
||||
if (!status) {
|
||||
*error_class = ERROR_CLASS_PROPERTY;
|
||||
@@ -822,8 +820,8 @@ bool Device_Write_Property(
|
||||
case PROP_MAX_INFO_FRAMES:
|
||||
if (value.tag == BACNET_APPLICATION_TAG_UNSIGNED_INT) {
|
||||
if (value.type.Unsigned_Int <= 255) {
|
||||
dlmstp_set_max_info_frames((uint8_t) value.type.
|
||||
Unsigned_Int);
|
||||
dlmstp_set_max_info_frames((uint8_t) value.
|
||||
type.Unsigned_Int);
|
||||
status = true;
|
||||
} else {
|
||||
*error_class = ERROR_CLASS_PROPERTY;
|
||||
@@ -859,7 +857,8 @@ bool Device_Write_Property(
|
||||
return status;
|
||||
}
|
||||
|
||||
void Device_Init(void)
|
||||
void Device_Init(
|
||||
void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -127,6 +127,7 @@ static char *Shed_Level_Descriptions[MAX_SHED_LEVELS] = {
|
||||
"dim lights 20%",
|
||||
"dim lights 30%"
|
||||
};
|
||||
|
||||
static float Shed_Level_Values[MAX_SHED_LEVELS] = {
|
||||
90.0,
|
||||
80.0,
|
||||
|
||||
@@ -551,11 +551,11 @@ bool Lighting_Output_Write_Property(
|
||||
} else if (value.tag == BACNET_APPLICATION_TAG_NULL) {
|
||||
level = LIGHTING_LEVEL_NULL;
|
||||
object_index =
|
||||
Lighting_Output_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
Lighting_Output_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
status =
|
||||
Lighting_Output_Present_Value_Relinquish(wp_data->
|
||||
object_instance, wp_data->priority);
|
||||
Lighting_Output_Present_Value_Relinquish
|
||||
(wp_data->object_instance, wp_data->priority);
|
||||
if (wp_data->priority == 6) {
|
||||
/* Command priority 6 is reserved for use by Minimum On/Off
|
||||
algorithm and may not be used for other purposes in any
|
||||
@@ -580,8 +580,8 @@ bool Lighting_Output_Write_Property(
|
||||
case PROP_OUT_OF_SERVICE:
|
||||
if (value.tag == BACNET_APPLICATION_TAG_BOOLEAN) {
|
||||
object_index =
|
||||
Lighting_Output_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
Lighting_Output_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
Lighting_Output_Out_Of_Service[object_index] =
|
||||
value.type.Boolean;
|
||||
status = true;
|
||||
|
||||
@@ -317,8 +317,8 @@ bool Life_Safety_Point_Write_Property(
|
||||
if (value.tag == BACNET_APPLICATION_TAG_ENUMERATED) {
|
||||
if (value.type.Enumerated <= MAX_LIFE_SAFETY_MODE) {
|
||||
object_index =
|
||||
Life_Safety_Point_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
Life_Safety_Point_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
Life_Safety_Point_Mode[object_index] =
|
||||
value.type.Enumerated;
|
||||
status = true;
|
||||
@@ -334,8 +334,8 @@ bool Life_Safety_Point_Write_Property(
|
||||
case PROP_OUT_OF_SERVICE:
|
||||
if (value.tag == BACNET_APPLICATION_TAG_BOOLEAN) {
|
||||
object_index =
|
||||
Life_Safety_Point_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
Life_Safety_Point_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
Life_Safety_Point_Out_Of_Service[object_index] =
|
||||
value.type.Boolean;
|
||||
status = true;
|
||||
|
||||
@@ -44,8 +44,7 @@
|
||||
#define MULTISTATE_NUMBER_OF_STATES (254)
|
||||
#endif
|
||||
/* Here is our Present Value */
|
||||
static uint8_t
|
||||
Present_Value[MAX_MULTISTATE_INPUTS];
|
||||
static uint8_t Present_Value[MAX_MULTISTATE_INPUTS];
|
||||
/* Writable out-of-service allows others to manipulate our Present Value */
|
||||
static bool Out_Of_Service[MAX_MULTISTATE_INPUTS];
|
||||
static char Object_Name[MAX_MULTISTATE_INPUTS][64];
|
||||
@@ -375,8 +374,7 @@ int Multistate_Input_Encode_Property_APDU(
|
||||
encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL);
|
||||
break;
|
||||
case PROP_OUT_OF_SERVICE:
|
||||
object_index =
|
||||
Multistate_Input_Instance_To_Index(object_instance);
|
||||
object_index = Multistate_Input_Instance_To_Index(object_instance);
|
||||
state = Out_Of_Service[object_index];
|
||||
apdu_len = encode_application_boolean(&apdu[0], state);
|
||||
break;
|
||||
@@ -388,10 +386,10 @@ int Multistate_Input_Encode_Property_APDU(
|
||||
case PROP_STATE_TEXT:
|
||||
if (array_index == 0) {
|
||||
/* Array element zero is the number of elements in the array */
|
||||
apdu_len = encode_application_unsigned(&apdu[0],
|
||||
apdu_len =
|
||||
encode_application_unsigned(&apdu[0],
|
||||
MULTISTATE_NUMBER_OF_STATES);
|
||||
}
|
||||
else if (array_index == BACNET_ARRAY_ALL) {
|
||||
} else if (array_index == BACNET_ARRAY_ALL) {
|
||||
/* if no index was specified, then try to encode the entire list */
|
||||
/* into one packet. */
|
||||
object_index =
|
||||
@@ -400,8 +398,8 @@ int Multistate_Input_Encode_Property_APDU(
|
||||
characterstring_init_ansi(&char_string,
|
||||
Multistate_Input_State_Text(object_instance, i));
|
||||
/* FIXME: this might go beyond MAX_APDU length! */
|
||||
len = encode_application_character_string(
|
||||
&apdu[apdu_len],
|
||||
len =
|
||||
encode_application_character_string(&apdu[apdu_len],
|
||||
&char_string);
|
||||
/* add it if we have room */
|
||||
if ((apdu_len + len) < MAX_APDU) {
|
||||
@@ -419,11 +417,10 @@ int Multistate_Input_Encode_Property_APDU(
|
||||
if (array_index <= MULTISTATE_NUMBER_OF_STATES) {
|
||||
array_index--;
|
||||
characterstring_init_ansi(&char_string,
|
||||
Multistate_Input_State_Text(
|
||||
object_instance,
|
||||
Multistate_Input_State_Text(object_instance,
|
||||
array_index));
|
||||
apdu_len = encode_application_character_string(
|
||||
&apdu[0],
|
||||
apdu_len =
|
||||
encode_application_character_string(&apdu[0],
|
||||
&char_string);
|
||||
} else {
|
||||
*error_class = ERROR_CLASS_PROPERTY;
|
||||
@@ -469,9 +466,8 @@ bool Multistate_Input_Write_Property(
|
||||
case PROP_PRESENT_VALUE:
|
||||
if (value.tag == BACNET_APPLICATION_TAG_UNSIGNED_INT) {
|
||||
if (Out_Of_Service[object_index]) {
|
||||
if (Multistate_Input_Present_Value_Set(
|
||||
wp_data->object_instance,
|
||||
value.type.Unsigned_Int)) {
|
||||
if (Multistate_Input_Present_Value_Set(wp_data->
|
||||
object_instance, value.type.Unsigned_Int)) {
|
||||
status = true;
|
||||
} else {
|
||||
*error_class = ERROR_CLASS_PROPERTY;
|
||||
@@ -489,10 +485,9 @@ bool Multistate_Input_Write_Property(
|
||||
case PROP_OUT_OF_SERVICE:
|
||||
if (value.tag == BACNET_APPLICATION_TAG_BOOLEAN) {
|
||||
object_index =
|
||||
Multistate_Input_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
Out_Of_Service[object_index] =
|
||||
value.type.Boolean;
|
||||
Multistate_Input_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
Out_Of_Service[object_index] = value.type.Boolean;
|
||||
status = true;
|
||||
} else {
|
||||
*error_class = ERROR_CLASS_PROPERTY;
|
||||
|
||||
@@ -364,8 +364,8 @@ bool Multistate_Output_Write_Property(
|
||||
(value.type.Unsigned_Int <= MULTISTATE_NUMBER_OF_STATES)) {
|
||||
level = value.type.Unsigned_Int;
|
||||
object_index =
|
||||
Multistate_Output_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
Multistate_Output_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
priority--;
|
||||
Multistate_Output_Level[object_index][priority] =
|
||||
(uint8_t) level;
|
||||
@@ -388,8 +388,8 @@ bool Multistate_Output_Write_Property(
|
||||
} else if (value.tag == BACNET_APPLICATION_TAG_NULL) {
|
||||
level = MULTISTATE_NULL;
|
||||
object_index =
|
||||
Multistate_Output_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
Multistate_Output_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
priority = wp_data->priority;
|
||||
if (priority && (priority <= BACNET_MAX_PRIORITY)) {
|
||||
priority--;
|
||||
@@ -414,8 +414,8 @@ bool Multistate_Output_Write_Property(
|
||||
case PROP_OUT_OF_SERVICE:
|
||||
if (value.tag == BACNET_APPLICATION_TAG_BOOLEAN) {
|
||||
object_index =
|
||||
Multistate_Output_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
Multistate_Output_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
Multistate_Output_Out_Of_Service[object_index] =
|
||||
value.type.Boolean;
|
||||
status = true;
|
||||
|
||||
@@ -64,7 +64,7 @@ uint8_t Send_Private_Transfer_Request(
|
||||
uint16_t vendor_id,
|
||||
uint32_t service_number,
|
||||
char block_number,
|
||||
DATABLOCK *block);
|
||||
DATABLOCK * block);
|
||||
|
||||
|
||||
/* buffer used for receive */
|
||||
@@ -173,13 +173,14 @@ int main(
|
||||
int iCount = 0;
|
||||
int iType = 0;
|
||||
int iKey;
|
||||
static int iLimit[3] = {7, 11, 7};
|
||||
static int iLimit[3] = { 7, 11, 7 };
|
||||
|
||||
if (((argc != 2) && (argc != 3)) || ((argc >= 2) && (strcmp(argv[1], "--help") == 0))) {
|
||||
printf("%s\n",argv[0]);
|
||||
if (((argc != 2) && (argc != 3)) || ((argc >= 2) &&
|
||||
(strcmp(argv[1], "--help") == 0))) {
|
||||
printf("%s\n", argv[0]);
|
||||
printf("Usage: %s server local-device-instance\r\n or\r\n"
|
||||
" %s remote-device-instance\r\n"
|
||||
, filename_remove_path(argv[0]), filename_remove_path(argv[0]));
|
||||
" %s remote-device-instance\r\n",
|
||||
filename_remove_path(argv[0]), filename_remove_path(argv[0]));
|
||||
if ((argc > 1) && (strcmp(argv[1], "--help") == 0)) {
|
||||
printf("\r\nServer mode:\r\n\r\n"
|
||||
"local-device-instance determins the device id of the application\r\n"
|
||||
@@ -197,7 +198,7 @@ int main(
|
||||
return 0;
|
||||
}
|
||||
/* decode the command line parameters */
|
||||
if(_stricmp(argv[1], "server") == 0)
|
||||
if (_stricmp(argv[1], "server") == 0)
|
||||
Target_Mode = 1;
|
||||
else
|
||||
Target_Mode = 0;
|
||||
@@ -211,7 +212,7 @@ int main(
|
||||
}
|
||||
|
||||
/* setup my info */
|
||||
if(Target_Mode)
|
||||
if (Target_Mode)
|
||||
Device_Set_Object_Instance_Number(Target_Device_Object_Instance);
|
||||
else
|
||||
Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE);
|
||||
@@ -223,13 +224,13 @@ int main(
|
||||
last_seconds = time(NULL);
|
||||
timeout_seconds = (apdu_timeout() / 1000) * apdu_retries();
|
||||
|
||||
if(Target_Mode) {
|
||||
if (Target_Mode) {
|
||||
printf("Entering server mode. press q to quit program\r\n\r\n");
|
||||
|
||||
for (;;) {
|
||||
/* increment timer - exit if timed out */
|
||||
current_seconds = time(NULL);
|
||||
if(current_seconds != last_seconds) {
|
||||
if (current_seconds != last_seconds) {
|
||||
}
|
||||
|
||||
/* returns 0 bytes on timeout */
|
||||
@@ -243,19 +244,19 @@ int main(
|
||||
if (current_seconds != last_seconds) {
|
||||
putchar('.'); /* Just to show that time is passing... */
|
||||
last_seconds = current_seconds;
|
||||
tsm_timer_milliseconds(((current_seconds - last_seconds) * 1000));
|
||||
tsm_timer_milliseconds(((current_seconds -
|
||||
last_seconds) * 1000));
|
||||
}
|
||||
|
||||
if(_kbhit()) {
|
||||
if (_kbhit()) {
|
||||
iKey = toupper(_getch());
|
||||
if(iKey == 'Q') {
|
||||
if (iKey == 'Q') {
|
||||
printf("\r\nExiting program now\r\n");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
|
||||
/* try to bind with the device */
|
||||
found =
|
||||
@@ -279,79 +280,92 @@ int main(
|
||||
}
|
||||
/* at least one second has passed */
|
||||
if (current_seconds != last_seconds)
|
||||
tsm_timer_milliseconds(((current_seconds - last_seconds) * 1000));
|
||||
tsm_timer_milliseconds(((current_seconds -
|
||||
last_seconds) * 1000));
|
||||
if (Error_Detected)
|
||||
break;
|
||||
/* wait until the device is bound, or timeout and quit */
|
||||
if(!found)
|
||||
found = address_bind_request(Target_Device_Object_Instance, &max_apdu, &Target_Address);
|
||||
if (found)
|
||||
{
|
||||
if (!found)
|
||||
found =
|
||||
address_bind_request(Target_Device_Object_Instance,
|
||||
&max_apdu, &Target_Address);
|
||||
if (found) {
|
||||
if (invoke_id == 0) { /* Safe to send a new request */
|
||||
switch(iType) {
|
||||
switch (iType) {
|
||||
case 0: /* Write blocks to server */
|
||||
NewData.cMyByte1 = iCount;
|
||||
NewData.cMyByte2 = 255 - iCount;
|
||||
NewData.fMyReal = (float)iCount;
|
||||
NewData.fMyReal = (float) iCount;
|
||||
strcpy(NewData.sMyString, "Test Data - [x]");
|
||||
NewData.sMyString[13] = 'a' + iCount;
|
||||
printf("Sending block %d\n", iCount);
|
||||
invoke_id = Send_Private_Transfer_Request(Target_Device_Object_Instance, BACNET_VENDOR_ID, 1, iCount, &NewData);
|
||||
invoke_id =
|
||||
Send_Private_Transfer_Request
|
||||
(Target_Device_Object_Instance,
|
||||
BACNET_VENDOR_ID, 1, iCount, &NewData);
|
||||
break;
|
||||
|
||||
case 1: /* Read blocks from server */
|
||||
printf("Requesting block %d\n", iCount);
|
||||
invoke_id = Send_Private_Transfer_Request(Target_Device_Object_Instance, BACNET_VENDOR_ID, 0, iCount, &NewData);
|
||||
invoke_id =
|
||||
Send_Private_Transfer_Request
|
||||
(Target_Device_Object_Instance,
|
||||
BACNET_VENDOR_ID, 0, iCount, &NewData);
|
||||
break;
|
||||
|
||||
case 2: /* Generate some error responses */
|
||||
switch(iCount) {
|
||||
switch (iCount) {
|
||||
case 0: /* Bad service number i.e. 2 */
|
||||
case 2:
|
||||
case 4:
|
||||
case 6:
|
||||
case 8:
|
||||
printf("Requesting block %d with bad service number\n", iCount);
|
||||
invoke_id = Send_Private_Transfer_Request(Target_Device_Object_Instance, BACNET_VENDOR_ID, 2, iCount, &NewData);
|
||||
printf
|
||||
("Requesting block %d with bad service number\n",
|
||||
iCount);
|
||||
invoke_id =
|
||||
Send_Private_Transfer_Request
|
||||
(Target_Device_Object_Instance,
|
||||
BACNET_VENDOR_ID, 2, iCount, &NewData);
|
||||
break;
|
||||
|
||||
case 1: /* Bad vendor ID number */
|
||||
case 3:
|
||||
case 5:
|
||||
case 7:
|
||||
printf("Requesting block %d with invalid Vendor ID\n", iCount);
|
||||
invoke_id = Send_Private_Transfer_Request(Target_Device_Object_Instance, BACNET_VENDOR_ID + 1, 0, iCount, &NewData);
|
||||
printf
|
||||
("Requesting block %d with invalid Vendor ID\n",
|
||||
iCount);
|
||||
invoke_id =
|
||||
Send_Private_Transfer_Request
|
||||
(Target_Device_Object_Instance,
|
||||
BACNET_VENDOR_ID + 1, 0, iCount,
|
||||
&NewData);
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (tsm_invoke_id_free(invoke_id)) {
|
||||
if(iCount != MY_MAX_BLOCK) {
|
||||
} else if (tsm_invoke_id_free(invoke_id)) {
|
||||
if (iCount != MY_MAX_BLOCK) {
|
||||
iCount++;
|
||||
invoke_id = 0;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
iType++;
|
||||
iCount = 0;
|
||||
invoke_id = 0;
|
||||
|
||||
if(iType > 2)
|
||||
if (iType > 2)
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (tsm_invoke_id_failed(invoke_id))
|
||||
{
|
||||
} else if (tsm_invoke_id_failed(invoke_id)) {
|
||||
fprintf(stderr, "\rError: TSM Timeout!\r\n");
|
||||
tsm_free_invoke_id(invoke_id);
|
||||
Error_Detected = true;
|
||||
/* try again or abort? */
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* increment timer - exit if timed out */
|
||||
elapsed_seconds += (current_seconds - last_seconds);
|
||||
if (elapsed_seconds > timeout_seconds) {
|
||||
|
||||
@@ -176,10 +176,8 @@ static void Init_Service_Handlers(
|
||||
void)
|
||||
{
|
||||
Device_Init();
|
||||
handler_read_property_object_set(
|
||||
OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU,
|
||||
Device_Valid_Object_Instance_Number);
|
||||
handler_read_property_object_set(OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU, Device_Valid_Object_Instance_Number);
|
||||
/* we need to handle who-is
|
||||
to support dynamic device binding to us */
|
||||
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is);
|
||||
|
||||
@@ -113,10 +113,8 @@ static void Init_Service_Handlers(
|
||||
void)
|
||||
{
|
||||
Device_Init();
|
||||
handler_read_property_object_set(
|
||||
OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU,
|
||||
Device_Valid_Object_Instance_Number);
|
||||
handler_read_property_object_set(OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU, Device_Valid_Object_Instance_Number);
|
||||
/* we need to handle who-is
|
||||
to support dynamic device binding to us */
|
||||
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is);
|
||||
|
||||
@@ -111,10 +111,8 @@ static void Init_Service_Handlers(
|
||||
void)
|
||||
{
|
||||
Device_Init();
|
||||
handler_read_property_object_set(
|
||||
OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU,
|
||||
Device_Valid_Object_Instance_Number);
|
||||
handler_read_property_object_set(OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU, Device_Valid_Object_Instance_Number);
|
||||
/* we need to handle who-is
|
||||
to support dynamic device binding to us */
|
||||
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is);
|
||||
|
||||
@@ -78,7 +78,7 @@ uint8_t Send_Private_Transfer_Request(
|
||||
uint16_t vendor_id,
|
||||
uint32_t service_number,
|
||||
char block_number,
|
||||
DATABLOCK *block);
|
||||
DATABLOCK * block);
|
||||
|
||||
|
||||
/* buffer used for receive */
|
||||
@@ -145,145 +145,81 @@ static void Init_Object(
|
||||
object_index_to_instance_function index_function,
|
||||
object_name_function name_function)
|
||||
{
|
||||
handler_read_property_object_set(
|
||||
object_type,
|
||||
rp_function,
|
||||
handler_read_property_object_set(object_type, rp_function,
|
||||
object_valid_function);
|
||||
handler_write_property_object_set(
|
||||
object_type,
|
||||
wp_function);
|
||||
handler_read_property_multiple_list_set(
|
||||
object_type,
|
||||
rpm_list_function);
|
||||
Device_Object_Function_Set(
|
||||
object_type,
|
||||
count_function,
|
||||
index_function,
|
||||
handler_write_property_object_set(object_type, wp_function);
|
||||
handler_read_property_multiple_list_set(object_type, rpm_list_function);
|
||||
Device_Object_Function_Set(object_type, count_function, index_function,
|
||||
name_function);
|
||||
}
|
||||
|
||||
static void Init_Objects(void)
|
||||
static void Init_Objects(
|
||||
void)
|
||||
{
|
||||
Device_Init();
|
||||
Init_Object(
|
||||
OBJECT_DEVICE,
|
||||
Device_Property_Lists,
|
||||
Device_Encode_Property_APDU,
|
||||
Device_Valid_Object_Instance_Number,
|
||||
Device_Write_Property,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
Init_Object(OBJECT_DEVICE, Device_Property_Lists,
|
||||
Device_Encode_Property_APDU, Device_Valid_Object_Instance_Number,
|
||||
Device_Write_Property, NULL, NULL, NULL);
|
||||
|
||||
Analog_Input_Init();
|
||||
Init_Object(
|
||||
OBJECT_ANALOG_INPUT,
|
||||
Analog_Input_Property_Lists,
|
||||
Analog_Input_Encode_Property_APDU,
|
||||
Analog_Input_Valid_Instance,
|
||||
NULL,
|
||||
Analog_Input_Count,
|
||||
Analog_Input_Index_To_Instance,
|
||||
Analog_Input_Name);
|
||||
Init_Object(OBJECT_ANALOG_INPUT, Analog_Input_Property_Lists,
|
||||
Analog_Input_Encode_Property_APDU, Analog_Input_Valid_Instance, NULL,
|
||||
Analog_Input_Count, Analog_Input_Index_To_Instance, Analog_Input_Name);
|
||||
|
||||
Analog_Output_Init();
|
||||
Init_Object(
|
||||
OBJECT_ANALOG_OUTPUT,
|
||||
Analog_Output_Property_Lists,
|
||||
Analog_Output_Encode_Property_APDU,
|
||||
Analog_Output_Valid_Instance,
|
||||
Analog_Output_Write_Property,
|
||||
Analog_Output_Count,
|
||||
Analog_Output_Index_To_Instance,
|
||||
Analog_Output_Name);
|
||||
Init_Object(OBJECT_ANALOG_OUTPUT, Analog_Output_Property_Lists,
|
||||
Analog_Output_Encode_Property_APDU, Analog_Output_Valid_Instance,
|
||||
Analog_Output_Write_Property, Analog_Output_Count,
|
||||
Analog_Output_Index_To_Instance, Analog_Output_Name);
|
||||
|
||||
Analog_Value_Init();
|
||||
Init_Object(
|
||||
OBJECT_ANALOG_VALUE,
|
||||
Analog_Value_Property_Lists,
|
||||
Analog_Value_Encode_Property_APDU,
|
||||
Analog_Value_Valid_Instance,
|
||||
Analog_Value_Write_Property,
|
||||
Analog_Value_Count,
|
||||
Analog_Value_Index_To_Instance,
|
||||
Analog_Value_Name);
|
||||
Init_Object(OBJECT_ANALOG_VALUE, Analog_Value_Property_Lists,
|
||||
Analog_Value_Encode_Property_APDU, Analog_Value_Valid_Instance,
|
||||
Analog_Value_Write_Property, Analog_Value_Count,
|
||||
Analog_Value_Index_To_Instance, Analog_Value_Name);
|
||||
|
||||
Binary_Input_Init();
|
||||
Init_Object(
|
||||
OBJECT_BINARY_INPUT,
|
||||
Binary_Input_Property_Lists,
|
||||
Binary_Input_Encode_Property_APDU,
|
||||
Binary_Input_Valid_Instance,
|
||||
NULL,
|
||||
Binary_Input_Count,
|
||||
Binary_Input_Index_To_Instance,
|
||||
Binary_Input_Name);
|
||||
Init_Object(OBJECT_BINARY_INPUT, Binary_Input_Property_Lists,
|
||||
Binary_Input_Encode_Property_APDU, Binary_Input_Valid_Instance, NULL,
|
||||
Binary_Input_Count, Binary_Input_Index_To_Instance, Binary_Input_Name);
|
||||
|
||||
Binary_Output_Init();
|
||||
Init_Object(
|
||||
OBJECT_BINARY_OUTPUT,
|
||||
Binary_Output_Property_Lists,
|
||||
Binary_Output_Encode_Property_APDU,
|
||||
Binary_Output_Valid_Instance,
|
||||
Binary_Output_Write_Property,
|
||||
Binary_Output_Count,
|
||||
Binary_Output_Index_To_Instance,
|
||||
Binary_Output_Name);
|
||||
Init_Object(OBJECT_BINARY_OUTPUT, Binary_Output_Property_Lists,
|
||||
Binary_Output_Encode_Property_APDU, Binary_Output_Valid_Instance,
|
||||
Binary_Output_Write_Property, Binary_Output_Count,
|
||||
Binary_Output_Index_To_Instance, Binary_Output_Name);
|
||||
|
||||
Binary_Value_Init();
|
||||
Init_Object(
|
||||
OBJECT_BINARY_VALUE,
|
||||
Binary_Value_Property_Lists,
|
||||
Binary_Value_Encode_Property_APDU,
|
||||
Binary_Value_Valid_Instance,
|
||||
Binary_Value_Write_Property,
|
||||
Binary_Value_Count,
|
||||
Binary_Value_Index_To_Instance,
|
||||
Binary_Value_Name);
|
||||
Init_Object(OBJECT_BINARY_VALUE, Binary_Value_Property_Lists,
|
||||
Binary_Value_Encode_Property_APDU, Binary_Value_Valid_Instance,
|
||||
Binary_Value_Write_Property, Binary_Value_Count,
|
||||
Binary_Value_Index_To_Instance, Binary_Value_Name);
|
||||
|
||||
Life_Safety_Point_Init();
|
||||
Init_Object(
|
||||
OBJECT_LIFE_SAFETY_POINT,
|
||||
Life_Safety_Point_Property_Lists,
|
||||
Init_Object(OBJECT_LIFE_SAFETY_POINT, Life_Safety_Point_Property_Lists,
|
||||
Life_Safety_Point_Encode_Property_APDU,
|
||||
Life_Safety_Point_Valid_Instance,
|
||||
Life_Safety_Point_Write_Property,
|
||||
Life_Safety_Point_Count,
|
||||
Life_Safety_Point_Index_To_Instance,
|
||||
Life_Safety_Point_Valid_Instance, Life_Safety_Point_Write_Property,
|
||||
Life_Safety_Point_Count, Life_Safety_Point_Index_To_Instance,
|
||||
Life_Safety_Point_Name);
|
||||
|
||||
Load_Control_Init();
|
||||
Init_Object(
|
||||
OBJECT_LOAD_CONTROL,
|
||||
Load_Control_Property_Lists,
|
||||
Load_Control_Encode_Property_APDU,
|
||||
Load_Control_Valid_Instance,
|
||||
Load_Control_Write_Property,
|
||||
Load_Control_Count,
|
||||
Load_Control_Index_To_Instance,
|
||||
Load_Control_Name);
|
||||
Init_Object(OBJECT_LOAD_CONTROL, Load_Control_Property_Lists,
|
||||
Load_Control_Encode_Property_APDU, Load_Control_Valid_Instance,
|
||||
Load_Control_Write_Property, Load_Control_Count,
|
||||
Load_Control_Index_To_Instance, Load_Control_Name);
|
||||
|
||||
Multistate_Output_Init();
|
||||
Init_Object(
|
||||
OBJECT_MULTI_STATE_OUTPUT,
|
||||
Multistate_Output_Property_Lists,
|
||||
Init_Object(OBJECT_MULTI_STATE_OUTPUT, Multistate_Output_Property_Lists,
|
||||
Multistate_Output_Encode_Property_APDU,
|
||||
Multistate_Output_Valid_Instance,
|
||||
Multistate_Output_Write_Property,
|
||||
Multistate_Output_Count,
|
||||
Multistate_Output_Index_To_Instance,
|
||||
Multistate_Output_Valid_Instance, Multistate_Output_Write_Property,
|
||||
Multistate_Output_Count, Multistate_Output_Index_To_Instance,
|
||||
Multistate_Output_Name);
|
||||
|
||||
#if defined(BACFILE)
|
||||
bacfile_init();
|
||||
Init_Object(
|
||||
OBJECT_FILE,
|
||||
BACfile_Property_Lists,
|
||||
bacfile_encode_property_apdu,
|
||||
bacfile_valid_instance,
|
||||
bacfile_write_property,
|
||||
bacfile_count,
|
||||
bacfile_index_to_instance,
|
||||
Init_Object(OBJECT_FILE, BACfile_Property_Lists,
|
||||
bacfile_encode_property_apdu, bacfile_valid_instance,
|
||||
bacfile_write_property, bacfile_count, bacfile_index_to_instance,
|
||||
bacfile_name);
|
||||
#endif
|
||||
}
|
||||
@@ -305,14 +241,21 @@ static void Init_Service_Handlers(
|
||||
apdu_set_unrecognized_service_handler_handler
|
||||
(handler_unrecognized_service);
|
||||
/* we must implement read property - it's required! */
|
||||
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY, handler_read_property);
|
||||
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROP_MULTIPLE, handler_read_property_multiple);
|
||||
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_RANGE, handler_read_range);
|
||||
apdu_set_confirmed_handler(SERVICE_CONFIRMED_PRIVATE_TRANSFER, handler_conf_private_trans);
|
||||
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY,
|
||||
handler_read_property);
|
||||
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROP_MULTIPLE,
|
||||
handler_read_property_multiple);
|
||||
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_RANGE,
|
||||
handler_read_range);
|
||||
apdu_set_confirmed_handler(SERVICE_CONFIRMED_PRIVATE_TRANSFER,
|
||||
handler_conf_private_trans);
|
||||
/* handle the data coming back from confirmed requests */
|
||||
apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_READ_PROPERTY, handler_read_property_ack);
|
||||
apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_READ_RANGE, handler_read_range_ack);
|
||||
apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_PRIVATE_TRANSFER, handler_conf_private_trans_ack);
|
||||
apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_READ_PROPERTY,
|
||||
handler_read_property_ack);
|
||||
apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_READ_RANGE,
|
||||
handler_read_range_ack);
|
||||
apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_PRIVATE_TRANSFER,
|
||||
handler_conf_private_trans_ack);
|
||||
|
||||
/* handle any errors coming back */
|
||||
apdu_set_error_handler(SERVICE_CONFIRMED_READ_PROPERTY, MyErrorHandler);
|
||||
@@ -341,14 +284,15 @@ int main(
|
||||
int iCount = 0;
|
||||
int iType = 0;
|
||||
int iKey;
|
||||
static int iLimit[3] = {7, 11, 7};
|
||||
static int iLimit[3] = { 7, 11, 7 };
|
||||
|
||||
if (((argc != 2) && (argc != 3)) || ((argc >= 2) && (strcmp(argv[1], "--help") == 0))) {
|
||||
printf("%s\n",argv[0]);
|
||||
if (((argc != 2) && (argc != 3)) || ((argc >= 2) &&
|
||||
(strcmp(argv[1], "--help") == 0))) {
|
||||
printf("%s\n", argv[0]);
|
||||
printf("Usage: %s server local-device-instance\r\n or\r\n"
|
||||
" %s remote-device-instance\r\n"
|
||||
"--help gives further information\r\n"
|
||||
, filename_remove_path(argv[0]), filename_remove_path(argv[0]));
|
||||
"--help gives further information\r\n",
|
||||
filename_remove_path(argv[0]), filename_remove_path(argv[0]));
|
||||
if ((argc > 1) && (strcmp(argv[1], "--help") == 0)) {
|
||||
printf("\r\nServer mode:\r\n\r\n"
|
||||
"<local-device-instance> determins the device id of the application\r\n"
|
||||
@@ -363,7 +307,7 @@ int main(
|
||||
return 0;
|
||||
}
|
||||
/* decode the command line parameters */
|
||||
if(_stricmp(argv[1], "server") == 0)
|
||||
if (_stricmp(argv[1], "server") == 0)
|
||||
Target_Mode = 1;
|
||||
else
|
||||
Target_Mode = 0;
|
||||
@@ -377,7 +321,7 @@ int main(
|
||||
}
|
||||
|
||||
/* setup my info */
|
||||
if(Target_Mode)
|
||||
if (Target_Mode)
|
||||
Device_Set_Object_Instance_Number(Target_Device_Object_Instance);
|
||||
else
|
||||
Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE);
|
||||
@@ -390,13 +334,13 @@ int main(
|
||||
last_seconds = time(NULL);
|
||||
timeout_seconds = (apdu_timeout() / 1000) * apdu_retries();
|
||||
|
||||
if(Target_Mode) {
|
||||
if (Target_Mode) {
|
||||
printf("Entering server mode. press q to quit program\r\n\r\n");
|
||||
|
||||
for (;;) {
|
||||
/* increment timer - exit if timed out */
|
||||
current_seconds = time(NULL);
|
||||
if(current_seconds != last_seconds) {
|
||||
if (current_seconds != last_seconds) {
|
||||
}
|
||||
|
||||
/* returns 0 bytes on timeout */
|
||||
@@ -410,25 +354,28 @@ int main(
|
||||
if (current_seconds != last_seconds) {
|
||||
putchar('.'); /* Just to show that time is passing... */
|
||||
last_seconds = current_seconds;
|
||||
tsm_timer_milliseconds(((current_seconds - last_seconds) * 1000));
|
||||
tsm_timer_milliseconds(((current_seconds -
|
||||
last_seconds) * 1000));
|
||||
address_cache_timer(current_seconds - last_seconds);
|
||||
}
|
||||
|
||||
if(_kbhit()) {
|
||||
if (_kbhit()) {
|
||||
iKey = toupper(_getch());
|
||||
if(iKey == 'Q') {
|
||||
if (iKey == 'Q') {
|
||||
printf("\r\nExiting program now\r\n");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
|
||||
/* try to bind with the device */
|
||||
found = address_bind_request(Target_Device_Object_Instance, &max_apdu, &Target_Address);
|
||||
found =
|
||||
address_bind_request(Target_Device_Object_Instance, &max_apdu,
|
||||
&Target_Address);
|
||||
if (!found) {
|
||||
Send_WhoIs(Target_Device_Object_Instance, Target_Device_Object_Instance);
|
||||
Send_WhoIs(Target_Device_Object_Instance,
|
||||
Target_Device_Object_Instance);
|
||||
}
|
||||
/* loop forever */
|
||||
for (;;) {
|
||||
@@ -444,17 +391,20 @@ int main(
|
||||
}
|
||||
/* at least one second has passed */
|
||||
if (current_seconds != last_seconds) {
|
||||
tsm_timer_milliseconds(((current_seconds - last_seconds) * 1000));
|
||||
tsm_timer_milliseconds(((current_seconds -
|
||||
last_seconds) * 1000));
|
||||
address_cache_timer(current_seconds - last_seconds);
|
||||
}
|
||||
if (Error_Detected)
|
||||
break;
|
||||
/* wait until the device is bound, or timeout and quit */
|
||||
if(!found)
|
||||
found = address_bind_request(Target_Device_Object_Instance, &max_apdu, &Target_Address);
|
||||
if (!found)
|
||||
found =
|
||||
address_bind_request(Target_Device_Object_Instance,
|
||||
&max_apdu, &Target_Address);
|
||||
if (found) {
|
||||
if (invoke_id == 0) { /* Safe to send a new request */
|
||||
switch(iCount) {
|
||||
switch (iCount) {
|
||||
case 0:
|
||||
Request.RequestType = RR_BY_POSITION;
|
||||
Request.Range.RefIndex = 20;
|
||||
@@ -567,19 +517,17 @@ int main(
|
||||
break;
|
||||
}
|
||||
|
||||
invoke_id = Send_ReadRange_Request( Target_Device_Object_Instance, &Request);
|
||||
}
|
||||
else if (tsm_invoke_id_free(invoke_id)) {
|
||||
if(iCount != MY_MAX_BLOCK) {
|
||||
invoke_id =
|
||||
Send_ReadRange_Request(Target_Device_Object_Instance,
|
||||
&Request);
|
||||
} else if (tsm_invoke_id_free(invoke_id)) {
|
||||
if (iCount != MY_MAX_BLOCK) {
|
||||
iCount++;
|
||||
invoke_id = 0;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (tsm_invoke_id_failed(invoke_id))
|
||||
{
|
||||
} else if (tsm_invoke_id_failed(invoke_id)) {
|
||||
fprintf(stderr, "\rError: TSM Timeout!\r\n");
|
||||
tsm_free_invoke_id(invoke_id);
|
||||
/* Error_Detected = true; */
|
||||
@@ -587,9 +535,7 @@ int main(
|
||||
invoke_id = 0; /* Try next operation */
|
||||
/* break; */
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* increment timer - exit if timed out */
|
||||
elapsed_seconds += (current_seconds - last_seconds);
|
||||
if (elapsed_seconds > timeout_seconds) {
|
||||
|
||||
@@ -115,10 +115,8 @@ static void Init_Service_Handlers(
|
||||
void)
|
||||
{
|
||||
Device_Init();
|
||||
handler_read_property_object_set(
|
||||
OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU,
|
||||
Device_Valid_Object_Instance_Number);
|
||||
handler_read_property_object_set(OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU, Device_Valid_Object_Instance_Number);
|
||||
/* we need to handle who-is
|
||||
to support dynamic device binding to us */
|
||||
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is);
|
||||
|
||||
+44
-108
@@ -75,145 +75,81 @@ static void Init_Object(
|
||||
object_index_to_instance_function index_function,
|
||||
object_name_function name_function)
|
||||
{
|
||||
handler_read_property_object_set(
|
||||
object_type,
|
||||
rp_function,
|
||||
handler_read_property_object_set(object_type, rp_function,
|
||||
object_valid_function);
|
||||
handler_write_property_object_set(
|
||||
object_type,
|
||||
wp_function);
|
||||
handler_read_property_multiple_list_set(
|
||||
object_type,
|
||||
rpm_list_function);
|
||||
Device_Object_Function_Set(
|
||||
object_type,
|
||||
count_function,
|
||||
index_function,
|
||||
handler_write_property_object_set(object_type, wp_function);
|
||||
handler_read_property_multiple_list_set(object_type, rpm_list_function);
|
||||
Device_Object_Function_Set(object_type, count_function, index_function,
|
||||
name_function);
|
||||
}
|
||||
|
||||
static void Init_Objects(void)
|
||||
static void Init_Objects(
|
||||
void)
|
||||
{
|
||||
Device_Init();
|
||||
Init_Object(
|
||||
OBJECT_DEVICE,
|
||||
Device_Property_Lists,
|
||||
Device_Encode_Property_APDU,
|
||||
Device_Valid_Object_Instance_Number,
|
||||
Device_Write_Property,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
Init_Object(OBJECT_DEVICE, Device_Property_Lists,
|
||||
Device_Encode_Property_APDU, Device_Valid_Object_Instance_Number,
|
||||
Device_Write_Property, NULL, NULL, NULL);
|
||||
|
||||
Analog_Input_Init();
|
||||
Init_Object(
|
||||
OBJECT_ANALOG_INPUT,
|
||||
Analog_Input_Property_Lists,
|
||||
Analog_Input_Encode_Property_APDU,
|
||||
Analog_Input_Valid_Instance,
|
||||
NULL,
|
||||
Analog_Input_Count,
|
||||
Analog_Input_Index_To_Instance,
|
||||
Analog_Input_Name);
|
||||
Init_Object(OBJECT_ANALOG_INPUT, Analog_Input_Property_Lists,
|
||||
Analog_Input_Encode_Property_APDU, Analog_Input_Valid_Instance, NULL,
|
||||
Analog_Input_Count, Analog_Input_Index_To_Instance, Analog_Input_Name);
|
||||
|
||||
Analog_Output_Init();
|
||||
Init_Object(
|
||||
OBJECT_ANALOG_OUTPUT,
|
||||
Analog_Output_Property_Lists,
|
||||
Analog_Output_Encode_Property_APDU,
|
||||
Analog_Output_Valid_Instance,
|
||||
Analog_Output_Write_Property,
|
||||
Analog_Output_Count,
|
||||
Analog_Output_Index_To_Instance,
|
||||
Analog_Output_Name);
|
||||
Init_Object(OBJECT_ANALOG_OUTPUT, Analog_Output_Property_Lists,
|
||||
Analog_Output_Encode_Property_APDU, Analog_Output_Valid_Instance,
|
||||
Analog_Output_Write_Property, Analog_Output_Count,
|
||||
Analog_Output_Index_To_Instance, Analog_Output_Name);
|
||||
|
||||
Analog_Value_Init();
|
||||
Init_Object(
|
||||
OBJECT_ANALOG_VALUE,
|
||||
Analog_Value_Property_Lists,
|
||||
Analog_Value_Encode_Property_APDU,
|
||||
Analog_Value_Valid_Instance,
|
||||
Analog_Value_Write_Property,
|
||||
Analog_Value_Count,
|
||||
Analog_Value_Index_To_Instance,
|
||||
Analog_Value_Name);
|
||||
Init_Object(OBJECT_ANALOG_VALUE, Analog_Value_Property_Lists,
|
||||
Analog_Value_Encode_Property_APDU, Analog_Value_Valid_Instance,
|
||||
Analog_Value_Write_Property, Analog_Value_Count,
|
||||
Analog_Value_Index_To_Instance, Analog_Value_Name);
|
||||
|
||||
Binary_Input_Init();
|
||||
Init_Object(
|
||||
OBJECT_BINARY_INPUT,
|
||||
Binary_Input_Property_Lists,
|
||||
Binary_Input_Encode_Property_APDU,
|
||||
Binary_Input_Valid_Instance,
|
||||
NULL,
|
||||
Binary_Input_Count,
|
||||
Binary_Input_Index_To_Instance,
|
||||
Binary_Input_Name);
|
||||
Init_Object(OBJECT_BINARY_INPUT, Binary_Input_Property_Lists,
|
||||
Binary_Input_Encode_Property_APDU, Binary_Input_Valid_Instance, NULL,
|
||||
Binary_Input_Count, Binary_Input_Index_To_Instance, Binary_Input_Name);
|
||||
|
||||
Binary_Output_Init();
|
||||
Init_Object(
|
||||
OBJECT_BINARY_OUTPUT,
|
||||
Binary_Output_Property_Lists,
|
||||
Binary_Output_Encode_Property_APDU,
|
||||
Binary_Output_Valid_Instance,
|
||||
Binary_Output_Write_Property,
|
||||
Binary_Output_Count,
|
||||
Binary_Output_Index_To_Instance,
|
||||
Binary_Output_Name);
|
||||
Init_Object(OBJECT_BINARY_OUTPUT, Binary_Output_Property_Lists,
|
||||
Binary_Output_Encode_Property_APDU, Binary_Output_Valid_Instance,
|
||||
Binary_Output_Write_Property, Binary_Output_Count,
|
||||
Binary_Output_Index_To_Instance, Binary_Output_Name);
|
||||
|
||||
Binary_Value_Init();
|
||||
Init_Object(
|
||||
OBJECT_BINARY_VALUE,
|
||||
Binary_Value_Property_Lists,
|
||||
Binary_Value_Encode_Property_APDU,
|
||||
Binary_Value_Valid_Instance,
|
||||
Binary_Value_Write_Property,
|
||||
Binary_Value_Count,
|
||||
Binary_Value_Index_To_Instance,
|
||||
Binary_Value_Name);
|
||||
Init_Object(OBJECT_BINARY_VALUE, Binary_Value_Property_Lists,
|
||||
Binary_Value_Encode_Property_APDU, Binary_Value_Valid_Instance,
|
||||
Binary_Value_Write_Property, Binary_Value_Count,
|
||||
Binary_Value_Index_To_Instance, Binary_Value_Name);
|
||||
|
||||
Life_Safety_Point_Init();
|
||||
Init_Object(
|
||||
OBJECT_LIFE_SAFETY_POINT,
|
||||
Life_Safety_Point_Property_Lists,
|
||||
Init_Object(OBJECT_LIFE_SAFETY_POINT, Life_Safety_Point_Property_Lists,
|
||||
Life_Safety_Point_Encode_Property_APDU,
|
||||
Life_Safety_Point_Valid_Instance,
|
||||
Life_Safety_Point_Write_Property,
|
||||
Life_Safety_Point_Count,
|
||||
Life_Safety_Point_Index_To_Instance,
|
||||
Life_Safety_Point_Valid_Instance, Life_Safety_Point_Write_Property,
|
||||
Life_Safety_Point_Count, Life_Safety_Point_Index_To_Instance,
|
||||
Life_Safety_Point_Name);
|
||||
|
||||
Load_Control_Init();
|
||||
Init_Object(
|
||||
OBJECT_LOAD_CONTROL,
|
||||
Load_Control_Property_Lists,
|
||||
Load_Control_Encode_Property_APDU,
|
||||
Load_Control_Valid_Instance,
|
||||
Load_Control_Write_Property,
|
||||
Load_Control_Count,
|
||||
Load_Control_Index_To_Instance,
|
||||
Load_Control_Name);
|
||||
Init_Object(OBJECT_LOAD_CONTROL, Load_Control_Property_Lists,
|
||||
Load_Control_Encode_Property_APDU, Load_Control_Valid_Instance,
|
||||
Load_Control_Write_Property, Load_Control_Count,
|
||||
Load_Control_Index_To_Instance, Load_Control_Name);
|
||||
|
||||
Multistate_Output_Init();
|
||||
Init_Object(
|
||||
OBJECT_MULTI_STATE_OUTPUT,
|
||||
Multistate_Output_Property_Lists,
|
||||
Init_Object(OBJECT_MULTI_STATE_OUTPUT, Multistate_Output_Property_Lists,
|
||||
Multistate_Output_Encode_Property_APDU,
|
||||
Multistate_Output_Valid_Instance,
|
||||
Multistate_Output_Write_Property,
|
||||
Multistate_Output_Count,
|
||||
Multistate_Output_Index_To_Instance,
|
||||
Multistate_Output_Valid_Instance, Multistate_Output_Write_Property,
|
||||
Multistate_Output_Count, Multistate_Output_Index_To_Instance,
|
||||
Multistate_Output_Name);
|
||||
|
||||
#if defined(BACFILE)
|
||||
bacfile_init();
|
||||
Init_Object(
|
||||
OBJECT_FILE,
|
||||
BACfile_Property_Lists,
|
||||
bacfile_encode_property_apdu,
|
||||
bacfile_valid_instance,
|
||||
bacfile_write_property,
|
||||
bacfile_count,
|
||||
bacfile_index_to_instance,
|
||||
Init_Object(OBJECT_FILE, BACfile_Property_Lists,
|
||||
bacfile_encode_property_apdu, bacfile_valid_instance,
|
||||
bacfile_write_property, bacfile_count, bacfile_index_to_instance,
|
||||
bacfile_name);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -87,10 +87,8 @@ static void Init_Service_Handlers(
|
||||
void)
|
||||
{
|
||||
Device_Init();
|
||||
handler_read_property_object_set(
|
||||
OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU,
|
||||
Device_Valid_Object_Instance_Number);
|
||||
handler_read_property_object_set(OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU, Device_Valid_Object_Instance_Number);
|
||||
/* we need to handle who-is
|
||||
to support dynamic device binding to us */
|
||||
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is);
|
||||
|
||||
@@ -54,10 +54,8 @@ static void Init_Service_Handlers(
|
||||
void)
|
||||
{
|
||||
Device_Init();
|
||||
handler_read_property_object_set(
|
||||
OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU,
|
||||
Device_Valid_Object_Instance_Number);
|
||||
handler_read_property_object_set(OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU, Device_Valid_Object_Instance_Number);
|
||||
/* we need to handle who-is
|
||||
to support dynamic device binding to us */
|
||||
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is);
|
||||
|
||||
@@ -90,10 +90,8 @@ static void Init_Service_Handlers(
|
||||
void)
|
||||
{
|
||||
Device_Init();
|
||||
handler_read_property_object_set(
|
||||
OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU,
|
||||
Device_Valid_Object_Instance_Number);
|
||||
handler_read_property_object_set(OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU, Device_Valid_Object_Instance_Number);
|
||||
/* we need to handle who-is
|
||||
to support dynamic device binding to us */
|
||||
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is);
|
||||
@@ -111,9 +109,13 @@ static void Init_Service_Handlers(
|
||||
apdu_set_reject_handler(MyRejectHandler);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int main(
|
||||
int argc,
|
||||
char *argv[])
|
||||
{
|
||||
BACNET_ADDRESS src = {
|
||||
0}; /* address where message came from */
|
||||
0
|
||||
}; /* address where message came from */
|
||||
uint16_t pdu_len = 0;
|
||||
unsigned timeout = 100; /* milliseconds */
|
||||
time_t elapsed_seconds = 0;
|
||||
|
||||
@@ -90,10 +90,8 @@ static void Init_Service_Handlers(
|
||||
void)
|
||||
{
|
||||
Device_Init();
|
||||
handler_read_property_object_set(
|
||||
OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU,
|
||||
Device_Valid_Object_Instance_Number);
|
||||
handler_read_property_object_set(OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU, Device_Valid_Object_Instance_Number);
|
||||
/* Note: this applications doesn't need to handle who-is
|
||||
it is confusing for the user! */
|
||||
/* set the handler for all the services we don't implement
|
||||
@@ -159,9 +157,13 @@ static void print_address_cache(
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int main(
|
||||
int argc,
|
||||
char *argv[])
|
||||
{
|
||||
BACNET_ADDRESS src = {
|
||||
0}; /* address where message came from */
|
||||
0
|
||||
}; /* address where message came from */
|
||||
uint16_t pdu_len = 0;
|
||||
unsigned timeout = 100; /* milliseconds */
|
||||
time_t total_seconds = 0;
|
||||
|
||||
@@ -170,10 +170,8 @@ static void Init_Service_Handlers(
|
||||
void)
|
||||
{
|
||||
Device_Init();
|
||||
handler_read_property_object_set(
|
||||
OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU,
|
||||
Device_Valid_Object_Instance_Number);
|
||||
handler_read_property_object_set(OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU, Device_Valid_Object_Instance_Number);
|
||||
/* we need to handle who-is
|
||||
to support dynamic device binding to us */
|
||||
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is);
|
||||
@@ -192,8 +190,11 @@ static void Init_Service_Handlers(
|
||||
}
|
||||
|
||||
|
||||
static void address_parse(BACNET_ADDRESS * dst,
|
||||
int argc, char *argv[]) {
|
||||
static void address_parse(
|
||||
BACNET_ADDRESS * dst,
|
||||
int argc,
|
||||
char *argv[])
|
||||
{
|
||||
int dnet = 0;
|
||||
unsigned mac[6];
|
||||
int count = 0;
|
||||
@@ -240,9 +241,13 @@ static void address_parse(BACNET_ADDRESS * dst,
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int main(
|
||||
int argc,
|
||||
char *argv[])
|
||||
{
|
||||
BACNET_ADDRESS src = {
|
||||
0}; /* address where message came from */
|
||||
0
|
||||
}; /* address where message came from */
|
||||
uint16_t pdu_len = 0;
|
||||
unsigned timeout = 100; /* milliseconds */
|
||||
time_t total_seconds = 0;
|
||||
|
||||
@@ -133,10 +133,8 @@ static void Init_Service_Handlers(
|
||||
void)
|
||||
{
|
||||
Device_Init();
|
||||
handler_read_property_object_set(
|
||||
OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU,
|
||||
Device_Valid_Object_Instance_Number);
|
||||
handler_read_property_object_set(OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU, Device_Valid_Object_Instance_Number);
|
||||
/* we need to handle who-is
|
||||
to support dynamic device binding to us */
|
||||
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is);
|
||||
@@ -156,9 +154,13 @@ static void Init_Service_Handlers(
|
||||
apdu_set_reject_handler(MyRejectHandler);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int main(
|
||||
int argc,
|
||||
char *argv[])
|
||||
{
|
||||
BACNET_ADDRESS src = {
|
||||
0}; /* address where message came from */
|
||||
0
|
||||
}; /* address where message came from */
|
||||
uint16_t pdu_len = 0;
|
||||
unsigned timeout = 100; /* milliseconds */
|
||||
unsigned max_apdu = 0;
|
||||
|
||||
@@ -131,10 +131,8 @@ static void Init_Service_Handlers(
|
||||
void)
|
||||
{
|
||||
Device_Init();
|
||||
handler_read_property_object_set(
|
||||
OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU,
|
||||
Device_Valid_Object_Instance_Number);
|
||||
handler_read_property_object_set(OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU, Device_Valid_Object_Instance_Number);
|
||||
/* we need to handle who-is
|
||||
to support dynamic device binding to us */
|
||||
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is);
|
||||
@@ -156,9 +154,13 @@ static void Init_Service_Handlers(
|
||||
apdu_set_reject_handler(MyRejectHandler);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int main(
|
||||
int argc,
|
||||
char *argv[])
|
||||
{
|
||||
BACNET_ADDRESS src = {
|
||||
0}; /* address where message came from */
|
||||
0
|
||||
}; /* address where message came from */
|
||||
uint16_t pdu_len = 0;
|
||||
unsigned timeout = 100; /* milliseconds */
|
||||
unsigned max_apdu = 0;
|
||||
|
||||
@@ -81,7 +81,8 @@ extern "C" {
|
||||
uint32_t instance);
|
||||
|
||||
|
||||
void Analog_Output_Init(void);
|
||||
void Analog_Output_Init(
|
||||
void);
|
||||
|
||||
int Analog_Output_Encode_Property_APDU(
|
||||
uint8_t * apdu,
|
||||
|
||||
@@ -74,7 +74,8 @@ extern "C" {
|
||||
bool bacfile_write_stream_data(
|
||||
BACNET_ATOMIC_WRITE_FILE_DATA * data);
|
||||
|
||||
void bacfile_init(void);
|
||||
void bacfile_init(
|
||||
void);
|
||||
|
||||
/* handling for read property service */
|
||||
int bacfile_encode_property_apdu(
|
||||
|
||||
@@ -164,7 +164,7 @@ extern "C" {
|
||||
|
||||
void Send_UnconfirmedPrivateTransfer(
|
||||
BACNET_ADDRESS * dest,
|
||||
BACNET_PRIVATE_TRANSFER_DATA *private_data);
|
||||
BACNET_PRIVATE_TRANSFER_DATA * private_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -40,11 +40,17 @@
|
||||
#include "bacenum.h"
|
||||
#include "wp.h"
|
||||
|
||||
typedef unsigned (*object_count_function) (void);
|
||||
typedef uint32_t (*object_index_to_instance_function)
|
||||
(unsigned index);
|
||||
typedef char * (*object_name_function)
|
||||
(uint32_t object_instance);
|
||||
typedef unsigned (
|
||||
*object_count_function) (
|
||||
void);
|
||||
typedef uint32_t(
|
||||
*object_index_to_instance_function)
|
||||
(
|
||||
unsigned index);
|
||||
typedef char *(
|
||||
*object_name_function)
|
||||
(
|
||||
uint32_t object_instance);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -56,64 +56,65 @@ typedef struct BACnet_Get_Event_Information_Data {
|
||||
/* return 0 if no active event at this index
|
||||
return -1 if end of list
|
||||
return +1 if active event */
|
||||
typedef int (*get_event_info_function) (
|
||||
typedef int (
|
||||
*get_event_info_function) (
|
||||
unsigned index,
|
||||
BACNET_GET_EVENT_INFORMATION_DATA *getevent_data);
|
||||
BACNET_GET_EVENT_INFORMATION_DATA * getevent_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
int getevent_encode_apdu(
|
||||
int getevent_encode_apdu(
|
||||
uint8_t * apdu,
|
||||
uint8_t invoke_id,
|
||||
BACNET_OBJECT_ID * lastReceivedObjectIdentifier);
|
||||
|
||||
int getevent_decode_service_request(
|
||||
int getevent_decode_service_request(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
BACNET_OBJECT_ID * object_id);
|
||||
|
||||
int getevent_ack_encode_apdu_init(
|
||||
int getevent_ack_encode_apdu_init(
|
||||
uint8_t * apdu,
|
||||
size_t max_apdu,
|
||||
uint8_t invoke_id);
|
||||
|
||||
int getevent_ack_encode_apdu_data(
|
||||
int getevent_ack_encode_apdu_data(
|
||||
uint8_t * apdu,
|
||||
size_t max_apdu,
|
||||
BACNET_GET_EVENT_INFORMATION_DATA * get_event_data);
|
||||
|
||||
int getevent_ack_encode_apdu_end(
|
||||
int getevent_ack_encode_apdu_end(
|
||||
uint8_t * apdu,
|
||||
size_t max_apdu,
|
||||
bool moreEvents);
|
||||
|
||||
int getevent_ack_decode_service_request(
|
||||
int getevent_ack_decode_service_request(
|
||||
uint8_t * apdu,
|
||||
int apdu_len, /* total length of the apdu */
|
||||
BACNET_GET_EVENT_INFORMATION_DATA * get_event_data,
|
||||
bool *moreEvents);
|
||||
bool * moreEvents);
|
||||
|
||||
#ifdef TEST
|
||||
#include "ctest.h"
|
||||
int getevent_decode_apdu(
|
||||
int getevent_decode_apdu(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
uint8_t * invoke_id,
|
||||
BACNET_OBJECT_ID * lastReceivedObjectIdentifier);
|
||||
|
||||
int getevent_ack_decode_apdu(
|
||||
int getevent_ack_decode_apdu(
|
||||
uint8_t * apdu,
|
||||
int apdu_len, /* total length of the apdu */
|
||||
uint8_t * invoke_id,
|
||||
BACNET_GET_EVENT_INFORMATION_DATA * get_event_data,
|
||||
bool *moreEvents);
|
||||
bool * moreEvents);
|
||||
|
||||
void testGetEventInformationAck(
|
||||
void testGetEventInformationAck(
|
||||
Test * pTest);
|
||||
|
||||
void testGetEventInformation(
|
||||
void testGetEventInformation(
|
||||
Test * pTest);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -101,7 +101,7 @@ extern "C" {
|
||||
|
||||
|
||||
#if !defined(__BORLANDC__) && !defined(_MSC_VER)
|
||||
int stricmp(
|
||||
int stricmp(
|
||||
const char *s1,
|
||||
const char *s2);
|
||||
#endif
|
||||
|
||||
@@ -17,8 +17,5 @@ typedef struct MyData {
|
||||
uint8_t cMyByte1;
|
||||
uint8_t cMyByte2;
|
||||
float fMyReal;
|
||||
int8_t sMyString[MY_MAX_STR+1]; /* A little extra for the nul */
|
||||
int8_t sMyString[MY_MAX_STR + 1]; /* A little extra for the nul */
|
||||
} DATABLOCK;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -48,7 +48,8 @@ typedef struct BACnet_Read_Property_Data {
|
||||
int application_data_len;
|
||||
} BACNET_READ_PROPERTY_DATA;
|
||||
|
||||
typedef int (*read_property_function) (
|
||||
typedef int (
|
||||
*read_property_function) (
|
||||
uint8_t * apdu,
|
||||
uint32_t object_instance,
|
||||
BACNET_PROPERTY_ID property,
|
||||
@@ -56,7 +57,8 @@ typedef int (*read_property_function) (
|
||||
BACNET_ERROR_CLASS * error_class,
|
||||
BACNET_ERROR_CODE * error_code);
|
||||
|
||||
typedef bool (*object_valid_instance_function) (
|
||||
typedef bool(
|
||||
*object_valid_instance_function) (
|
||||
uint32_t object_instance);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -49,7 +49,8 @@ typedef struct BACnet_Read_Access_Data {
|
||||
struct BACnet_Read_Access_Data *next;
|
||||
} BACNET_READ_ACCESS_DATA;
|
||||
|
||||
typedef void (*rpm_property_lists_function) (
|
||||
typedef void (
|
||||
*rpm_property_lists_function) (
|
||||
const int **pRequired,
|
||||
const int **pOptional,
|
||||
const int **pProprietary);
|
||||
|
||||
@@ -53,7 +53,8 @@ typedef struct BACnet_Write_Property_Data {
|
||||
uint8_t priority; /* use BACNET_NO_PRIORITY if no priority */
|
||||
} BACNET_WRITE_PROPERTY_DATA;
|
||||
|
||||
typedef bool (*write_property_function) (
|
||||
typedef bool(
|
||||
*write_property_function) (
|
||||
BACNET_WRITE_PROPERTY_DATA * wp_data,
|
||||
BACNET_ERROR_CLASS * error_class,
|
||||
BACNET_ERROR_CODE * error_code);
|
||||
|
||||
@@ -313,8 +313,8 @@ bool Analog_Value_Write_Property(
|
||||
(value.type.Real >= 0.0) && (value.type.Real <= 100.0)) {
|
||||
level = (uint8_t) value.type.Real;
|
||||
object_index =
|
||||
Analog_Value_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
Analog_Value_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
priority--;
|
||||
Present_Value[object_index] = level;
|
||||
/* Note: you could set the physical output here if we
|
||||
|
||||
@@ -225,8 +225,8 @@ bool Binary_Value_Write_Property(
|
||||
(value.type.Enumerated <= MAX_BINARY_PV)) {
|
||||
level = value.type.Enumerated;
|
||||
object_index =
|
||||
Binary_Value_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
Binary_Value_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
priority--;
|
||||
/* NOTE: this Binary value has no priority array */
|
||||
Present_Value[object_index] = level;
|
||||
|
||||
@@ -492,8 +492,8 @@ bool Device_Write_Property(
|
||||
case PROP_OBJECT_IDENTIFIER:
|
||||
if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) {
|
||||
if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
|
||||
(Device_Set_Object_Instance_Number(value.type.Object_Id.
|
||||
instance))) {
|
||||
(Device_Set_Object_Instance_Number(value.type.
|
||||
Object_Id.instance))) {
|
||||
/* we could send an I-Am broadcast to let the world know */
|
||||
status = true;
|
||||
} else {
|
||||
|
||||
@@ -66,9 +66,8 @@ int Encode_Property_APDU(
|
||||
case OBJECT_DEVICE:
|
||||
if (Device_Valid_Object_Instance_Number(object_instance)) {
|
||||
apdu_len =
|
||||
Device_Encode_Property_APDU(&apdu[0],
|
||||
object_instance, property,
|
||||
array_index, error_class, error_code);
|
||||
Device_Encode_Property_APDU(&apdu[0], object_instance,
|
||||
property, array_index, error_class, error_code);
|
||||
}
|
||||
break;
|
||||
case OBJECT_ANALOG_INPUT:
|
||||
|
||||
@@ -143,7 +143,8 @@ static inline void bacnet_init(
|
||||
#endif
|
||||
Device_Set_Object_Instance_Number(22222);
|
||||
/* set up our confirmed service unrecognized service handler - required! */
|
||||
apdu_set_unrecognized_service_handler_handler(handler_unrecognized_service);
|
||||
apdu_set_unrecognized_service_handler_handler
|
||||
(handler_unrecognized_service);
|
||||
/* we need to handle who-is to support dynamic device binding */
|
||||
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is);
|
||||
/* Set the handlers for any confirmed services that we support. */
|
||||
|
||||
@@ -200,8 +200,8 @@ bool Binary_Value_Write_Property(
|
||||
if ((value.type.Enumerated == BINARY_ACTIVE) ||
|
||||
(value.type.Enumerated == BINARY_INACTIVE)) {
|
||||
object_index =
|
||||
Binary_Value_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
Binary_Value_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
/* NOTE: this Binary value has no priority array */
|
||||
Present_Value[object_index] =
|
||||
(BACNET_BINARY_PV) value.type.Enumerated;
|
||||
|
||||
@@ -364,8 +364,8 @@ bool Device_Write_Property(
|
||||
case PROP_OBJECT_IDENTIFIER:
|
||||
if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) {
|
||||
if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
|
||||
(Device_Set_Object_Instance_Number(value.type.Object_Id.
|
||||
instance))) {
|
||||
(Device_Set_Object_Instance_Number(value.type.
|
||||
Object_Id.instance))) {
|
||||
/* we could send an I-Am broadcast to let the world know */
|
||||
status = true;
|
||||
} else {
|
||||
|
||||
@@ -57,10 +57,8 @@ int Encode_Property_APDU(
|
||||
if (Device_Valid_Object_Instance_Number(rp_data->object_instance)) {
|
||||
apdu_len =
|
||||
Device_Encode_Property_APDU(&apdu[0],
|
||||
rp_data->object_instance,
|
||||
rp_data->object_property,
|
||||
rp_data->array_index,
|
||||
error_class, error_code);
|
||||
rp_data->object_instance, rp_data->object_property,
|
||||
rp_data->array_index, error_class, error_code);
|
||||
}
|
||||
break;
|
||||
case OBJECT_ANALOG_VALUE:
|
||||
|
||||
@@ -200,8 +200,8 @@ bool Binary_Value_Write_Property(
|
||||
if ((value.type.Enumerated == BINARY_ACTIVE) ||
|
||||
(value.type.Enumerated == BINARY_INACTIVE)) {
|
||||
object_index =
|
||||
Binary_Value_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
Binary_Value_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
/* NOTE: this Binary value has no priority array */
|
||||
Present_Value[object_index] =
|
||||
(BACNET_BINARY_PV) value.type.Enumerated;
|
||||
|
||||
@@ -61,10 +61,8 @@ int Encode_Property_APDU(
|
||||
if (Device_Valid_Object_Instance_Number(rp_data->object_instance)) {
|
||||
apdu_len =
|
||||
Device_Encode_Property_APDU(&apdu[0],
|
||||
rp_data->object_instance,
|
||||
rp_data->object_property,
|
||||
rp_data->array_index,
|
||||
error_class, error_code);
|
||||
rp_data->object_instance, rp_data->object_property,
|
||||
rp_data->array_index, error_class, error_code);
|
||||
}
|
||||
break;
|
||||
#if MAX_ANALOG_VALUES
|
||||
|
||||
@@ -143,8 +143,8 @@ void Device_Init(
|
||||
eeprom_bytes_write(NV_EEPROM_DEVICE_NAME_ENCODING,
|
||||
&Object_Name_Encoding, 1);
|
||||
sprintf(Object_Name, "DEVICE-%lu", Object_Instance_Number);
|
||||
eeprom_bytes_write(NV_EEPROM_DEVICE_NAME_0, (uint8_t *) & Object_Name[0],
|
||||
NV_EEPROM_DEVICE_NAME_SIZE);
|
||||
eeprom_bytes_write(NV_EEPROM_DEVICE_NAME_0,
|
||||
(uint8_t *) & Object_Name[0], NV_EEPROM_DEVICE_NAME_SIZE);
|
||||
Object_Name_Length = strlen(Object_Name);
|
||||
eeprom_bytes_write(NV_EEPROM_DEVICE_NAME_LENGTH, &Object_Name_Length,
|
||||
1);
|
||||
@@ -506,8 +506,8 @@ int Device_Encode_Property_APDU(
|
||||
apdu_len = encode_application_unsigned(&apdu[0], stack_unused());
|
||||
break;
|
||||
case 9600:
|
||||
apdu_len = encode_application_unsigned(&apdu[0],
|
||||
rs485_baud_rate());
|
||||
apdu_len =
|
||||
encode_application_unsigned(&apdu[0], rs485_baud_rate());
|
||||
break;
|
||||
default:
|
||||
*error_class = ERROR_CLASS_PROPERTY;
|
||||
@@ -543,8 +543,8 @@ bool Device_Write_Property(
|
||||
case PROP_OBJECT_IDENTIFIER:
|
||||
if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) {
|
||||
if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
|
||||
(Device_Set_Object_Instance_Number(value.type.Object_Id.
|
||||
instance))) {
|
||||
(Device_Set_Object_Instance_Number(value.type.
|
||||
Object_Id.instance))) {
|
||||
/* we could send an I-Am broadcast to let the world know */
|
||||
status = true;
|
||||
} else {
|
||||
@@ -605,8 +605,8 @@ bool Device_Write_Property(
|
||||
eeprom_bytes_write(NV_EEPROM_DEVICE_NAME_LENGTH,
|
||||
&Object_Name_Length, 1);
|
||||
pCharString =
|
||||
characterstring_value(&value.type.
|
||||
Character_String);
|
||||
characterstring_value(&value.
|
||||
type.Character_String);
|
||||
for (i = 0; i < Object_Name_Length; i++) {
|
||||
Object_Name[i] = pCharString[i];
|
||||
}
|
||||
|
||||
@@ -670,7 +670,8 @@ static void MSTP_Receive_Frame_FSM(
|
||||
#ifdef MSTP_DEBUG_STATES
|
||||
static MSTP_MASTER_STATE Master_State_Log[128];
|
||||
static unsigned master_state_log_index = 0;
|
||||
void log_master_state(MSTP_MASTER_STATE state)
|
||||
void log_master_state(
|
||||
MSTP_MASTER_STATE state)
|
||||
{
|
||||
Master_State_Log[master_state_log_index] = state;
|
||||
master_state_log_index++;
|
||||
@@ -679,7 +680,7 @@ void log_master_state(MSTP_MASTER_STATE state)
|
||||
}
|
||||
}
|
||||
#else
|
||||
#define log_master_state(n) (void)n;
|
||||
#define log_master_state(n) (void)n;
|
||||
#endif
|
||||
|
||||
/* returns true if we need to transition immediately */
|
||||
@@ -1362,7 +1363,8 @@ void dlmstp_get_broadcast_address(
|
||||
return;
|
||||
}
|
||||
|
||||
char *dlmstp_receive_state_text(void)
|
||||
char *dlmstp_receive_state_text(
|
||||
void)
|
||||
{
|
||||
switch (Receive_State) {
|
||||
case MSTP_RECEIVE_STATE_IDLE:
|
||||
@@ -1380,7 +1382,8 @@ char *dlmstp_receive_state_text(void)
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
char *dlmstp_master_state_text(void)
|
||||
char *dlmstp_master_state_text(
|
||||
void)
|
||||
{
|
||||
switch (Master_State) {
|
||||
case MSTP_MASTER_STATE_INITIALIZE:
|
||||
|
||||
@@ -53,7 +53,6 @@ FUSES = {
|
||||
any fuses listed below are cleared fuses,
|
||||
or are CKSEL or SUT bits that are zero. */
|
||||
.low = (FUSE_CKSEL3 & FUSE_SUT1),
|
||||
|
||||
/* == HIGH FUSE or HFUSE settings == */
|
||||
/* BOOTRST: Enable Bootloader Reset Vector */
|
||||
/* EESAVE: Enable preserve EEPROM on Chip Erase */
|
||||
@@ -72,9 +71,7 @@ FUSES = {
|
||||
/* note: fuses are enabled by clearing the bit, so
|
||||
any fuses listed below are cleared fuses,
|
||||
or are BOOTSZ bits that are zero. */
|
||||
.high =
|
||||
(FUSE_BOOTSZ1 & FUSE_EESAVE & FUSE_SPIEN & FUSE_JTAGEN),
|
||||
|
||||
.high = (FUSE_BOOTSZ1 & FUSE_EESAVE & FUSE_SPIEN & FUSE_JTAGEN),
|
||||
/* == EXTENDED FUSE or EFUSE settings == */
|
||||
/* BODLEVEL configuration
|
||||
BODLEVEL2 BODLEVEL1 BODLEVEL0 Voltage
|
||||
|
||||
@@ -66,9 +66,8 @@ int Encode_Property_APDU(
|
||||
case OBJECT_DEVICE:
|
||||
if (Device_Valid_Object_Instance_Number(object_instance)) {
|
||||
apdu_len =
|
||||
Device_Encode_Property_APDU(&apdu[0],
|
||||
object_instance, property,
|
||||
array_index, error_class, error_code);
|
||||
Device_Encode_Property_APDU(&apdu[0], object_instance,
|
||||
property, array_index, error_class, error_code);
|
||||
}
|
||||
break;
|
||||
case OBJECT_ANALOG_INPUT:
|
||||
|
||||
@@ -98,7 +98,8 @@ static void bacnet_init(
|
||||
Analog_Value_Init();
|
||||
|
||||
/* set up our confirmed service unrecognized service handler - required! */
|
||||
apdu_set_unrecognized_service_handler_handler(handler_unrecognized_service);
|
||||
apdu_set_unrecognized_service_handler_handler
|
||||
(handler_unrecognized_service);
|
||||
/* we need to handle who-is to support dynamic device binding */
|
||||
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is);
|
||||
/* Set the handlers for any confirmed services that we support. */
|
||||
@@ -190,7 +191,7 @@ void test_task(
|
||||
buffer[12] = (MSTP_MAC_Address & BIT4) ? '1' : '0';
|
||||
buffer[13] = (MSTP_MAC_Address & BIT5) ? '1' : '0';
|
||||
buffer[14] = (MSTP_MAC_Address & BIT6) ? '1' : '0';
|
||||
serial_bytes_send((uint8_t *)buffer, nbytes);
|
||||
serial_bytes_send((uint8_t *) buffer, nbytes);
|
||||
}
|
||||
if (serial_byte_get(&data_register)) {
|
||||
/* echo the character */
|
||||
@@ -215,21 +216,23 @@ void test_task(
|
||||
}
|
||||
if (data_register == 'm') {
|
||||
sprintf(buffer, "->Master State: ");
|
||||
nbytes = (uint8_t)strlen(buffer);
|
||||
serial_bytes_send((uint8_t *)buffer, nbytes);
|
||||
extern char *dlmstp_master_state_text(void);
|
||||
nbytes = (uint8_t) strlen(buffer);
|
||||
serial_bytes_send((uint8_t *) buffer, nbytes);
|
||||
extern char *dlmstp_master_state_text(
|
||||
void);
|
||||
pBuffer = dlmstp_master_state_text();
|
||||
nbytes = (uint8_t)strlen(pBuffer);
|
||||
serial_bytes_send((uint8_t *)pBuffer, nbytes);
|
||||
nbytes = (uint8_t) strlen(pBuffer);
|
||||
serial_bytes_send((uint8_t *) pBuffer, nbytes);
|
||||
}
|
||||
if (data_register == 'r') {
|
||||
sprintf(buffer, "->Receive State: ");
|
||||
nbytes = (uint8_t)strlen(buffer);
|
||||
serial_bytes_send((uint8_t *)buffer, nbytes);
|
||||
extern char *dlmstp_receive_state_text(void);
|
||||
nbytes = (uint8_t) strlen(buffer);
|
||||
serial_bytes_send((uint8_t *) buffer, nbytes);
|
||||
extern char *dlmstp_receive_state_text(
|
||||
void);
|
||||
pBuffer = dlmstp_receive_state_text();
|
||||
nbytes = (uint8_t)strlen(pBuffer);
|
||||
serial_bytes_send((uint8_t *)pBuffer, nbytes);
|
||||
nbytes = (uint8_t) strlen(pBuffer);
|
||||
serial_bytes_send((uint8_t *) pBuffer, nbytes);
|
||||
}
|
||||
serial_byte_send('\r');
|
||||
serial_byte_send('\n');
|
||||
|
||||
@@ -73,6 +73,7 @@ static uint16_t Timer_Silence(
|
||||
{
|
||||
return SilenceTime;
|
||||
}
|
||||
|
||||
static void Timer_Silence_Reset(
|
||||
void)
|
||||
{
|
||||
|
||||
@@ -163,10 +163,8 @@ static void Init_Service_Handlers(
|
||||
void)
|
||||
{
|
||||
Device_Init();
|
||||
handler_read_property_object_set(
|
||||
OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU,
|
||||
Device_Valid_Object_Instance_Number);
|
||||
handler_read_property_object_set(OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU, Device_Valid_Object_Instance_Number);
|
||||
/* we need to handle who-is to support dynamic device binding */
|
||||
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is);
|
||||
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, LocalIAmHandler);
|
||||
|
||||
@@ -65,6 +65,7 @@ static uint16_t Timer_Silence(
|
||||
{
|
||||
return SilenceTime;
|
||||
}
|
||||
|
||||
static void Timer_Silence_Reset(
|
||||
void)
|
||||
{
|
||||
|
||||
@@ -75,6 +75,7 @@ static uint16_t Timer_Silence(
|
||||
{
|
||||
return SilenceTime;
|
||||
}
|
||||
|
||||
static void Timer_Silence_Reset(
|
||||
void)
|
||||
{
|
||||
|
||||
@@ -310,8 +310,8 @@ bool Analog_Value_Write_Property(
|
||||
(value.type.Real >= 0.0) && (value.type.Real <= 100.0)) {
|
||||
level = (uint8_t) value.type.Real;
|
||||
object_index =
|
||||
Analog_Value_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
Analog_Value_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
priority--;
|
||||
Present_Value[object_index] = level;
|
||||
/* Note: you could set the physical output here if we
|
||||
|
||||
@@ -226,8 +226,8 @@ bool Binary_Value_Write_Property(
|
||||
(value.type.Enumerated <= MAX_BINARY_PV)) {
|
||||
level = value.type.Enumerated;
|
||||
object_index =
|
||||
Binary_Value_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
Binary_Value_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
priority--;
|
||||
/* NOTE: this Binary value has no priority array */
|
||||
Present_Value[object_index] = level;
|
||||
|
||||
@@ -504,8 +504,8 @@ bool Device_Write_Property(
|
||||
case PROP_OBJECT_IDENTIFIER:
|
||||
if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) {
|
||||
if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
|
||||
(Device_Set_Object_Instance_Number(value.type.Object_Id.
|
||||
instance))) {
|
||||
(Device_Set_Object_Instance_Number(value.type.
|
||||
Object_Id.instance))) {
|
||||
/* we could send an I-Am broadcast to let the world know */
|
||||
status = true;
|
||||
} else {
|
||||
|
||||
@@ -93,9 +93,8 @@ void handler_read_property(
|
||||
if (Device_Valid_Object_Instance_Number(data.object_instance)) {
|
||||
len =
|
||||
Device_Encode_Property_APDU(&Temp_Buf[0],
|
||||
data.object_instance,
|
||||
data.object_property, data.array_index, &error_class,
|
||||
&error_code);
|
||||
data.object_instance, data.object_property,
|
||||
data.array_index, &error_class, &error_code);
|
||||
if (len >= 0) {
|
||||
/* encode the APDU portion of the packet */
|
||||
data.application_data = &Temp_Buf[0];
|
||||
|
||||
@@ -68,12 +68,15 @@ RTFDevice RTFDeviceList[] = {
|
||||
#define MAXTYPES 32
|
||||
|
||||
RTW32Handle RTHandleTable[MAXHANDLES] = { {0} };
|
||||
|
||||
int RTHandleCount = MAXHANDLES;
|
||||
|
||||
RTW32Object RTObjectTable[MAXOBJECTS] = { {0} };
|
||||
|
||||
int RTObjectCount = MAXOBJECTS;
|
||||
|
||||
RTW32Types RTTypeTable[MAXTYPES] = { {0} };
|
||||
|
||||
int RTTypeCount = MAXTYPES;
|
||||
|
||||
#if 0
|
||||
|
||||
@@ -73,6 +73,7 @@ static uint16_t Timer_Silence(
|
||||
{
|
||||
return SilenceTime;
|
||||
}
|
||||
|
||||
static void Timer_Silence_Reset(
|
||||
void)
|
||||
{
|
||||
|
||||
+57
-118
@@ -68,145 +68,81 @@ static void Init_Object(
|
||||
object_index_to_instance_function index_function,
|
||||
object_name_function name_function)
|
||||
{
|
||||
handler_read_property_object_set(
|
||||
object_type,
|
||||
rp_function,
|
||||
handler_read_property_object_set(object_type, rp_function,
|
||||
object_valid_function);
|
||||
handler_write_property_object_set(
|
||||
object_type,
|
||||
wp_function);
|
||||
handler_read_property_multiple_list_set(
|
||||
object_type,
|
||||
rpm_list_function);
|
||||
Device_Object_Function_Set(
|
||||
object_type,
|
||||
count_function,
|
||||
index_function,
|
||||
handler_write_property_object_set(object_type, wp_function);
|
||||
handler_read_property_multiple_list_set(object_type, rpm_list_function);
|
||||
Device_Object_Function_Set(object_type, count_function, index_function,
|
||||
name_function);
|
||||
}
|
||||
|
||||
static void Init_Objects(void)
|
||||
static void Init_Objects(
|
||||
void)
|
||||
{
|
||||
Device_Init();
|
||||
Init_Object(
|
||||
OBJECT_DEVICE,
|
||||
Device_Property_Lists,
|
||||
Device_Encode_Property_APDU,
|
||||
Device_Valid_Object_Instance_Number,
|
||||
Device_Write_Property,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
Init_Object(OBJECT_DEVICE, Device_Property_Lists,
|
||||
Device_Encode_Property_APDU, Device_Valid_Object_Instance_Number,
|
||||
Device_Write_Property, NULL, NULL, NULL);
|
||||
|
||||
Analog_Input_Init();
|
||||
Init_Object(
|
||||
OBJECT_ANALOG_INPUT,
|
||||
Analog_Input_Property_Lists,
|
||||
Analog_Input_Encode_Property_APDU,
|
||||
Analog_Input_Valid_Instance,
|
||||
NULL,
|
||||
Analog_Input_Count,
|
||||
Analog_Input_Index_To_Instance,
|
||||
Analog_Input_Name);
|
||||
Init_Object(OBJECT_ANALOG_INPUT, Analog_Input_Property_Lists,
|
||||
Analog_Input_Encode_Property_APDU, Analog_Input_Valid_Instance, NULL,
|
||||
Analog_Input_Count, Analog_Input_Index_To_Instance, Analog_Input_Name);
|
||||
|
||||
Analog_Output_Init();
|
||||
Init_Object(
|
||||
OBJECT_ANALOG_OUTPUT,
|
||||
Analog_Output_Property_Lists,
|
||||
Analog_Output_Encode_Property_APDU,
|
||||
Analog_Output_Valid_Instance,
|
||||
Analog_Output_Write_Property,
|
||||
Analog_Output_Count,
|
||||
Analog_Output_Index_To_Instance,
|
||||
Analog_Output_Name);
|
||||
Init_Object(OBJECT_ANALOG_OUTPUT, Analog_Output_Property_Lists,
|
||||
Analog_Output_Encode_Property_APDU, Analog_Output_Valid_Instance,
|
||||
Analog_Output_Write_Property, Analog_Output_Count,
|
||||
Analog_Output_Index_To_Instance, Analog_Output_Name);
|
||||
|
||||
Analog_Value_Init();
|
||||
Init_Object(
|
||||
OBJECT_ANALOG_VALUE,
|
||||
Analog_Value_Property_Lists,
|
||||
Analog_Value_Encode_Property_APDU,
|
||||
Analog_Value_Valid_Instance,
|
||||
Analog_Value_Write_Property,
|
||||
Analog_Value_Count,
|
||||
Analog_Value_Index_To_Instance,
|
||||
Analog_Value_Name);
|
||||
Init_Object(OBJECT_ANALOG_VALUE, Analog_Value_Property_Lists,
|
||||
Analog_Value_Encode_Property_APDU, Analog_Value_Valid_Instance,
|
||||
Analog_Value_Write_Property, Analog_Value_Count,
|
||||
Analog_Value_Index_To_Instance, Analog_Value_Name);
|
||||
|
||||
Binary_Input_Init();
|
||||
Init_Object(
|
||||
OBJECT_BINARY_INPUT,
|
||||
Binary_Input_Property_Lists,
|
||||
Binary_Input_Encode_Property_APDU,
|
||||
Binary_Input_Valid_Instance,
|
||||
NULL,
|
||||
Binary_Input_Count,
|
||||
Binary_Input_Index_To_Instance,
|
||||
Binary_Input_Name);
|
||||
Init_Object(OBJECT_BINARY_INPUT, Binary_Input_Property_Lists,
|
||||
Binary_Input_Encode_Property_APDU, Binary_Input_Valid_Instance, NULL,
|
||||
Binary_Input_Count, Binary_Input_Index_To_Instance, Binary_Input_Name);
|
||||
|
||||
Binary_Output_Init();
|
||||
Init_Object(
|
||||
OBJECT_BINARY_OUTPUT,
|
||||
Binary_Output_Property_Lists,
|
||||
Binary_Output_Encode_Property_APDU,
|
||||
Binary_Output_Valid_Instance,
|
||||
Binary_Output_Write_Property,
|
||||
Binary_Output_Count,
|
||||
Binary_Output_Index_To_Instance,
|
||||
Binary_Output_Name);
|
||||
Init_Object(OBJECT_BINARY_OUTPUT, Binary_Output_Property_Lists,
|
||||
Binary_Output_Encode_Property_APDU, Binary_Output_Valid_Instance,
|
||||
Binary_Output_Write_Property, Binary_Output_Count,
|
||||
Binary_Output_Index_To_Instance, Binary_Output_Name);
|
||||
|
||||
Binary_Value_Init();
|
||||
Init_Object(
|
||||
OBJECT_BINARY_VALUE,
|
||||
Binary_Value_Property_Lists,
|
||||
Binary_Value_Encode_Property_APDU,
|
||||
Binary_Value_Valid_Instance,
|
||||
Binary_Value_Write_Property,
|
||||
Binary_Value_Count,
|
||||
Binary_Value_Index_To_Instance,
|
||||
Binary_Value_Name);
|
||||
Init_Object(OBJECT_BINARY_VALUE, Binary_Value_Property_Lists,
|
||||
Binary_Value_Encode_Property_APDU, Binary_Value_Valid_Instance,
|
||||
Binary_Value_Write_Property, Binary_Value_Count,
|
||||
Binary_Value_Index_To_Instance, Binary_Value_Name);
|
||||
|
||||
Life_Safety_Point_Init();
|
||||
Init_Object(
|
||||
OBJECT_LIFE_SAFETY_POINT,
|
||||
Life_Safety_Point_Property_Lists,
|
||||
Init_Object(OBJECT_LIFE_SAFETY_POINT, Life_Safety_Point_Property_Lists,
|
||||
Life_Safety_Point_Encode_Property_APDU,
|
||||
Life_Safety_Point_Valid_Instance,
|
||||
Life_Safety_Point_Write_Property,
|
||||
Life_Safety_Point_Count,
|
||||
Life_Safety_Point_Index_To_Instance,
|
||||
Life_Safety_Point_Valid_Instance, Life_Safety_Point_Write_Property,
|
||||
Life_Safety_Point_Count, Life_Safety_Point_Index_To_Instance,
|
||||
Life_Safety_Point_Name);
|
||||
|
||||
Load_Control_Init();
|
||||
Init_Object(
|
||||
OBJECT_LOAD_CONTROL,
|
||||
Load_Control_Property_Lists,
|
||||
Load_Control_Encode_Property_APDU,
|
||||
Load_Control_Valid_Instance,
|
||||
Load_Control_Write_Property,
|
||||
Load_Control_Count,
|
||||
Load_Control_Index_To_Instance,
|
||||
Load_Control_Name);
|
||||
Init_Object(OBJECT_LOAD_CONTROL, Load_Control_Property_Lists,
|
||||
Load_Control_Encode_Property_APDU, Load_Control_Valid_Instance,
|
||||
Load_Control_Write_Property, Load_Control_Count,
|
||||
Load_Control_Index_To_Instance, Load_Control_Name);
|
||||
|
||||
Multistate_Output_Init();
|
||||
Init_Object(
|
||||
OBJECT_MULTI_STATE_OUTPUT,
|
||||
Multistate_Output_Property_Lists,
|
||||
Init_Object(OBJECT_MULTI_STATE_OUTPUT, Multistate_Output_Property_Lists,
|
||||
Multistate_Output_Encode_Property_APDU,
|
||||
Multistate_Output_Valid_Instance,
|
||||
Multistate_Output_Write_Property,
|
||||
Multistate_Output_Count,
|
||||
Multistate_Output_Index_To_Instance,
|
||||
Multistate_Output_Valid_Instance, Multistate_Output_Write_Property,
|
||||
Multistate_Output_Count, Multistate_Output_Index_To_Instance,
|
||||
Multistate_Output_Name);
|
||||
|
||||
#if defined(BACFILE)
|
||||
bacfile_init();
|
||||
Init_Object(
|
||||
OBJECT_FILE,
|
||||
BACfile_Property_Lists,
|
||||
bacfile_encode_property_apdu,
|
||||
bacfile_valid_instance,
|
||||
bacfile_write_property,
|
||||
bacfile_count,
|
||||
bacfile_index_to_instance,
|
||||
Init_Object(OBJECT_FILE, BACfile_Property_Lists,
|
||||
bacfile_encode_property_apdu, bacfile_valid_instance,
|
||||
bacfile_write_property, bacfile_count, bacfile_index_to_instance,
|
||||
bacfile_name);
|
||||
#endif
|
||||
}
|
||||
@@ -320,10 +256,8 @@ static void Init_Service_Handlers(
|
||||
void)
|
||||
{
|
||||
Device_Init();
|
||||
handler_read_property_object_set(
|
||||
OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU,
|
||||
Device_Valid_Object_Instance_Number);
|
||||
handler_read_property_object_set(OBJECT_DEVICE,
|
||||
Device_Encode_Property_APDU, Device_Valid_Object_Instance_Number);
|
||||
/* we need to handle who-is to support dynamic device binding */
|
||||
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is);
|
||||
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, LocalIAmHandler);
|
||||
@@ -333,8 +267,10 @@ static void Init_Service_Handlers(
|
||||
apdu_set_unrecognized_service_handler_handler
|
||||
(handler_unrecognized_service);
|
||||
/* we must implement read property - it's required! */
|
||||
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY, handler_read_property);
|
||||
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROP_MULTIPLE, handler_read_property_multiple);
|
||||
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY,
|
||||
handler_read_property);
|
||||
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROP_MULTIPLE,
|
||||
handler_read_property_multiple);
|
||||
/* handle the data coming back from confirmed requests */
|
||||
apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_READ_PROPERTY,
|
||||
handler_read_property_ack);
|
||||
@@ -377,13 +313,16 @@ static void print_address_cache(
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int main(
|
||||
int argc,
|
||||
char *argv[])
|
||||
{
|
||||
BACNET_ADDRESS src = {
|
||||
0}; /* address where message came from */
|
||||
0
|
||||
}; /* address where message came from */
|
||||
uint16_t pdu_len = 0;
|
||||
unsigned timeout = 100; /* milliseconds */
|
||||
BACNET_ADDRESS my_address,
|
||||
broadcast_address;
|
||||
BACNET_ADDRESS my_address, broadcast_address;
|
||||
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
|
||||
@@ -89,7 +89,8 @@ static DWORD RS485_RTSControl = RTS_CONTROL_DISABLE;
|
||||
* ALGORITHM: none
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
void strupper(char *str)
|
||||
void strupper(
|
||||
char *str)
|
||||
{
|
||||
char *p;
|
||||
for (p = str; *p != '\0'; ++p) {
|
||||
@@ -398,7 +399,8 @@ static BOOL WINAPI CtrlCHandler(
|
||||
}
|
||||
#endif
|
||||
|
||||
static int ascii_hex_to_int(char ch)
|
||||
static int ascii_hex_to_int(
|
||||
char ch)
|
||||
{
|
||||
int rv = -1;
|
||||
|
||||
@@ -426,7 +428,7 @@ int main(
|
||||
char ch = ' ';
|
||||
int lsb = 0, msb = 0;
|
||||
long my_baud = 38400;
|
||||
uint8_t buffer[501] = {0};
|
||||
uint8_t buffer[501] = { 0 };
|
||||
|
||||
if (argc > 1) {
|
||||
RS485_Set_Interface(argv[1]);
|
||||
@@ -489,4 +491,3 @@ int main(
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -65,7 +65,8 @@ extern "C" {
|
||||
bool RS485_Set_Baud_Rate(
|
||||
uint32_t baud);
|
||||
|
||||
void RS485_Print_Error(void);
|
||||
void RS485_Print_Error(
|
||||
void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -87,6 +87,7 @@ static uint16_t Timer_Silence(
|
||||
{
|
||||
return SilenceTime;
|
||||
}
|
||||
|
||||
static void Timer_Silence_Reset(
|
||||
void)
|
||||
{
|
||||
|
||||
+84
-68
@@ -111,8 +111,9 @@ void address_remove_device(
|
||||
struct Address_Cache_Entry *pMatch;
|
||||
|
||||
pMatch = Address_Cache;
|
||||
while(pMatch <= &Address_Cache[MAX_ADDRESS_CACHE-1]) {
|
||||
if (((pMatch->Flags & BAC_ADDR_IN_USE) != 0) && (pMatch->device_id == device_id)) {
|
||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
if (((pMatch->Flags & BAC_ADDR_IN_USE) != 0) &&
|
||||
(pMatch->device_id == device_id)) {
|
||||
pMatch->Flags = 0;
|
||||
break;
|
||||
}
|
||||
@@ -131,7 +132,7 @@ void address_remove_device(
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
struct Address_Cache_Entry * address_remove_oldest(
|
||||
struct Address_Cache_Entry *address_remove_oldest(
|
||||
void)
|
||||
{
|
||||
struct Address_Cache_Entry *pMatch;
|
||||
@@ -144,9 +145,11 @@ struct Address_Cache_Entry * address_remove_oldest(
|
||||
/* First pass - try only in use and bound entries */
|
||||
|
||||
pMatch = Address_Cache;
|
||||
while(pMatch <= &Address_Cache[MAX_ADDRESS_CACHE-1]) {
|
||||
if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ | BAC_ADDR_STATIC)) == BAC_ADDR_IN_USE) {
|
||||
if(pMatch->TimeToLive <= ulTime) { /* Shorter lived entry found */
|
||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
if ((pMatch->
|
||||
Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ |
|
||||
BAC_ADDR_STATIC)) == BAC_ADDR_IN_USE) {
|
||||
if (pMatch->TimeToLive <= ulTime) { /* Shorter lived entry found */
|
||||
ulTime = pMatch->TimeToLive;
|
||||
pCandidate = pMatch;
|
||||
}
|
||||
@@ -154,17 +157,20 @@ struct Address_Cache_Entry * address_remove_oldest(
|
||||
pMatch++;
|
||||
}
|
||||
|
||||
if(pCandidate != NULL) { /* Found something to free up */
|
||||
if (pCandidate != NULL) { /* Found something to free up */
|
||||
pCandidate->Flags = BAC_ADDR_RESERVED;
|
||||
pCandidate->TimeToLive = BAC_ADDR_SHORT_TIME; /* only reserve it for a short while */
|
||||
return(pCandidate);
|
||||
return (pCandidate);
|
||||
}
|
||||
|
||||
/* Second pass - try in use and un bound as last resort */
|
||||
pMatch = Address_Cache;
|
||||
while(pMatch <= &Address_Cache[MAX_ADDRESS_CACHE-1]) {
|
||||
if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ | BAC_ADDR_STATIC)) == (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) {
|
||||
if(pMatch->TimeToLive <= ulTime) { /* Shorter lived entry found */
|
||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
if ((pMatch->
|
||||
Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ |
|
||||
BAC_ADDR_STATIC)) ==
|
||||
(BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) {
|
||||
if (pMatch->TimeToLive <= ulTime) { /* Shorter lived entry found */
|
||||
ulTime = pMatch->TimeToLive;
|
||||
pCandidate = pMatch;
|
||||
}
|
||||
@@ -172,12 +178,12 @@ struct Address_Cache_Entry * address_remove_oldest(
|
||||
pMatch++;
|
||||
}
|
||||
|
||||
if(pCandidate != NULL) { /* Found something to free up */
|
||||
if (pCandidate != NULL) { /* Found something to free up */
|
||||
pCandidate->Flags = BAC_ADDR_RESERVED;
|
||||
pCandidate->TimeToLive = BAC_ADDR_SHORT_TIME; /* only reserve it for a short while */
|
||||
}
|
||||
|
||||
return(pCandidate);
|
||||
return (pCandidate);
|
||||
}
|
||||
|
||||
|
||||
@@ -255,7 +261,7 @@ void address_init(
|
||||
struct Address_Cache_Entry *pMatch;
|
||||
|
||||
pMatch = Address_Cache;
|
||||
while(pMatch <= &Address_Cache[MAX_ADDRESS_CACHE-1] ) {
|
||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
pMatch->Flags = 0;
|
||||
pMatch++;
|
||||
}
|
||||
@@ -278,13 +284,14 @@ void address_init_partial(
|
||||
struct Address_Cache_Entry *pMatch;
|
||||
|
||||
pMatch = Address_Cache;
|
||||
while(pMatch <= &Address_Cache[MAX_ADDRESS_CACHE-1] ) {
|
||||
if((pMatch->Flags & BAC_ADDR_IN_USE) != 0) { /* It's in use so let's check further */
|
||||
if(((pMatch->Flags & BAC_ADDR_BIND_REQ) != 0) || (pMatch->TimeToLive == 0))
|
||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
if ((pMatch->Flags & BAC_ADDR_IN_USE) != 0) { /* It's in use so let's check further */
|
||||
if (((pMatch->Flags & BAC_ADDR_BIND_REQ) != 0) ||
|
||||
(pMatch->TimeToLive == 0))
|
||||
pMatch->Flags = 0;
|
||||
}
|
||||
|
||||
if((pMatch->Flags & BAC_ADDR_RESERVED) != 0) { /* Reserved entries should be cleared */
|
||||
if ((pMatch->Flags & BAC_ADDR_RESERVED) != 0) { /* Reserved entries should be cleared */
|
||||
pMatch->Flags = 0;
|
||||
}
|
||||
|
||||
@@ -311,19 +318,18 @@ void address_set_device_TTL(
|
||||
struct Address_Cache_Entry *pMatch;
|
||||
|
||||
pMatch = Address_Cache;
|
||||
while(pMatch <= &Address_Cache[MAX_ADDRESS_CACHE-1] ) {
|
||||
if (((pMatch->Flags & BAC_ADDR_IN_USE) != 0) && (pMatch->device_id == device_id)) {
|
||||
if((pMatch->Flags & BAC_ADDR_BIND_REQ) == 0) { /* If bound then we have either static or normaal */
|
||||
if(StaticFlag) {
|
||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
if (((pMatch->Flags & BAC_ADDR_IN_USE) != 0) &&
|
||||
(pMatch->device_id == device_id)) {
|
||||
if ((pMatch->Flags & BAC_ADDR_BIND_REQ) == 0) { /* If bound then we have either static or normaal */
|
||||
if (StaticFlag) {
|
||||
pMatch->Flags |= BAC_ADDR_STATIC;
|
||||
pMatch->TimeToLive = BAC_ADDR_FOREVER;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
pMatch->Flags &= ~BAC_ADDR_STATIC;
|
||||
pMatch->TimeToLive = TimeOut;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
pMatch->TimeToLive = TimeOut; /* For unbound we can only set the time to live */
|
||||
}
|
||||
break; /* Exit now if found at all - bound or unbound */
|
||||
@@ -342,10 +348,10 @@ bool address_get_by_device(
|
||||
bool found = false; /* return value */
|
||||
|
||||
pMatch = Address_Cache;
|
||||
while(pMatch <= &Address_Cache[MAX_ADDRESS_CACHE-1] ) {
|
||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
if (((pMatch->Flags & BAC_ADDR_IN_USE) != 0) &&
|
||||
(pMatch->device_id == device_id)) {
|
||||
if((pMatch->Flags & BAC_ADDR_BIND_REQ) == 0) { /* If bound then fetch data */
|
||||
if ((pMatch->Flags & BAC_ADDR_BIND_REQ) == 0) { /* If bound then fetch data */
|
||||
*src = pMatch->address;
|
||||
*max_apdu = pMatch->max_apdu;
|
||||
found = true; /* Prove we found it */
|
||||
@@ -368,7 +374,7 @@ bool address_get_device_id(
|
||||
bool found = false; /* return value */
|
||||
|
||||
pMatch = Address_Cache;
|
||||
while(pMatch <= &Address_Cache[MAX_ADDRESS_CACHE-1] ) {
|
||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) == BAC_ADDR_IN_USE) { /* If bound */
|
||||
if (bacnet_address_same(&pMatch->address, src)) {
|
||||
if (device_id) {
|
||||
@@ -400,18 +406,19 @@ void address_add(
|
||||
|
||||
/* existing device or bind request outstanding - update address */
|
||||
pMatch = Address_Cache;
|
||||
while(pMatch <= &Address_Cache[MAX_ADDRESS_CACHE-1] ) {
|
||||
if (((pMatch->Flags & BAC_ADDR_IN_USE) != 0) && (pMatch->device_id == device_id)) {
|
||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
if (((pMatch->Flags & BAC_ADDR_IN_USE) != 0) &&
|
||||
(pMatch->device_id == device_id)) {
|
||||
pMatch->address = *src;
|
||||
pMatch->max_apdu = max_apdu;
|
||||
|
||||
/* Pick the right time to live */
|
||||
|
||||
if((pMatch->Flags & BAC_ADDR_BIND_REQ) != 0) /* Bind requested so long time */
|
||||
if ((pMatch->Flags & BAC_ADDR_BIND_REQ) != 0) /* Bind requested so long time */
|
||||
pMatch->TimeToLive = BAC_ADDR_LONG_TIME;
|
||||
else if((pMatch->Flags & BAC_ADDR_STATIC) != 0) /* Static already so make sure it never expires */
|
||||
else if ((pMatch->Flags & BAC_ADDR_STATIC) != 0) /* Static already so make sure it never expires */
|
||||
pMatch->TimeToLive = BAC_ADDR_FOREVER;
|
||||
else if((pMatch->Flags & BAC_ADDR_SHORT_TTL) != 0) /* Opportunistic entry so leave on short fuse */
|
||||
else if ((pMatch->Flags & BAC_ADDR_SHORT_TTL) != 0) /* Opportunistic entry so leave on short fuse */
|
||||
pMatch->TimeToLive = BAC_ADDR_SHORT_TIME;
|
||||
else
|
||||
pMatch->TimeToLive = BAC_ADDR_LONG_TIME; /* Renewing existing entry */
|
||||
@@ -426,7 +433,7 @@ void address_add(
|
||||
/* new device - add to cache if there is room */
|
||||
if (!found) {
|
||||
pMatch = Address_Cache;
|
||||
while(pMatch <= &Address_Cache[MAX_ADDRESS_CACHE-1] ) {
|
||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
if ((pMatch->Flags & BAC_ADDR_IN_USE) == 0) {
|
||||
pMatch->Flags = BAC_ADDR_IN_USE;
|
||||
pMatch->device_id = device_id;
|
||||
@@ -443,7 +450,7 @@ void address_add(
|
||||
/* See if we can squeeze it in */
|
||||
if (!found) {
|
||||
pMatch = address_remove_oldest();
|
||||
if(pMatch != NULL) {
|
||||
if (pMatch != NULL) {
|
||||
pMatch->Flags = BAC_ADDR_IN_USE;
|
||||
pMatch->device_id = device_id;
|
||||
pMatch->max_apdu = max_apdu;
|
||||
@@ -466,43 +473,44 @@ bool address_bind_request(
|
||||
|
||||
/* existing device - update address info if currently bound */
|
||||
pMatch = Address_Cache;
|
||||
while(pMatch <= &Address_Cache[MAX_ADDRESS_CACHE-1] ) {
|
||||
if (((pMatch->Flags & BAC_ADDR_IN_USE) != 0) && (pMatch->device_id == device_id)) {
|
||||
if((pMatch->Flags & BAC_ADDR_BIND_REQ) == 0) { /* Already bound */
|
||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
if (((pMatch->Flags & BAC_ADDR_IN_USE) != 0) &&
|
||||
(pMatch->device_id == device_id)) {
|
||||
if ((pMatch->Flags & BAC_ADDR_BIND_REQ) == 0) { /* Already bound */
|
||||
found = true;
|
||||
*src = pMatch->address;
|
||||
*max_apdu = pMatch->max_apdu;
|
||||
if((pMatch->Flags & BAC_ADDR_SHORT_TTL) != 0) { /* Was picked up opportunistacilly */
|
||||
if ((pMatch->Flags & BAC_ADDR_SHORT_TTL) != 0) { /* Was picked up opportunistacilly */
|
||||
pMatch->Flags &= ~BAC_ADDR_SHORT_TTL; /* Convert to normal entry */
|
||||
pMatch->TimeToLive = BAC_ADDR_LONG_TIME; /* And give it a decent time to live */
|
||||
}
|
||||
}
|
||||
return(found); /* True if bound, false if bind request outstanding */
|
||||
return (found); /* True if bound, false if bind request outstanding */
|
||||
}
|
||||
pMatch++;
|
||||
}
|
||||
|
||||
/* Not there already so look for a free entry to put it in */
|
||||
pMatch = Address_Cache;
|
||||
while(pMatch <= &Address_Cache[MAX_ADDRESS_CACHE-1] ) {
|
||||
if ((pMatch->Flags & (BAC_ADDR_IN_USE |BAC_ADDR_RESERVED)) == 0) {
|
||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_RESERVED)) == 0) {
|
||||
pMatch->Flags = BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ; /* In use and awaiting binding */
|
||||
pMatch->device_id = device_id;
|
||||
pMatch->TimeToLive = BAC_ADDR_SHORT_TIME; /* No point in leaving bind requests in for long haul */
|
||||
/* now would be a good time to do a Who-Is request */
|
||||
return(false);
|
||||
return (false);
|
||||
}
|
||||
pMatch++;
|
||||
}
|
||||
|
||||
/* No free entries, See if we can squeeze it in by dropping an existing one */
|
||||
pMatch = address_remove_oldest();
|
||||
if(pMatch != NULL) {
|
||||
if (pMatch != NULL) {
|
||||
pMatch->Flags = BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ;
|
||||
pMatch->device_id = device_id;
|
||||
pMatch->TimeToLive = BAC_ADDR_SHORT_TIME; /* No point in leaving bind requests in for long haul */
|
||||
}
|
||||
return(false);
|
||||
return (false);
|
||||
}
|
||||
|
||||
|
||||
@@ -515,12 +523,13 @@ void address_add_binding(
|
||||
|
||||
/* existing device or bind request - update address */
|
||||
pMatch = Address_Cache;
|
||||
while(pMatch <= &Address_Cache[MAX_ADDRESS_CACHE-1] ) {
|
||||
if (((pMatch->Flags & BAC_ADDR_IN_USE) != 0) && (pMatch->device_id == device_id)) {
|
||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
if (((pMatch->Flags & BAC_ADDR_IN_USE) != 0) &&
|
||||
(pMatch->device_id == device_id)) {
|
||||
pMatch->address = *src;
|
||||
pMatch->max_apdu = max_apdu;
|
||||
pMatch->Flags &= ~BAC_ADDR_BIND_REQ; /* Clear bind request flag in case it was set */
|
||||
if((pMatch->Flags & BAC_ADDR_STATIC) == 0) /* Only update TTL if not static */
|
||||
if ((pMatch->Flags & BAC_ADDR_STATIC) == 0) /* Only update TTL if not static */
|
||||
pMatch->TimeToLive = BAC_ADDR_LONG_TIME; /* and set it on a long fuse */
|
||||
break;
|
||||
}
|
||||
@@ -540,7 +549,8 @@ bool address_get_by_index(
|
||||
|
||||
if (index < MAX_ADDRESS_CACHE) {
|
||||
pMatch = &Address_Cache[index];
|
||||
if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) == BAC_ADDR_IN_USE) {
|
||||
if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) ==
|
||||
BAC_ADDR_IN_USE) {
|
||||
*src = pMatch->address;
|
||||
*device_id = pMatch->device_id;
|
||||
*max_apdu = pMatch->max_apdu;
|
||||
@@ -558,7 +568,7 @@ unsigned address_count(
|
||||
unsigned count = 0; /* return value */
|
||||
|
||||
pMatch = Address_Cache;
|
||||
while(pMatch <= &Address_Cache[MAX_ADDRESS_CACHE-1] ) {
|
||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) == BAC_ADDR_IN_USE) /* Only count bound entries */
|
||||
count++;
|
||||
|
||||
@@ -576,7 +586,6 @@ unsigned address_count(
|
||||
int address_list_encode(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len)
|
||||
|
||||
{
|
||||
int iLen = 0;
|
||||
struct Address_Cache_Entry *pMatch;
|
||||
@@ -587,26 +596,33 @@ int address_list_encode(
|
||||
the packet to work with as at the moment it is just MAX_APDU */
|
||||
|
||||
pMatch = Address_Cache;
|
||||
while(pMatch <= &Address_Cache[MAX_ADDRESS_CACHE-1] ) {
|
||||
if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) == BAC_ADDR_IN_USE) {
|
||||
iLen += encode_application_object_id(&apdu[iLen], OBJECT_DEVICE, pMatch->device_id);
|
||||
iLen += encode_application_unsigned(&apdu[iLen], pMatch->address.net);
|
||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) ==
|
||||
BAC_ADDR_IN_USE) {
|
||||
iLen +=
|
||||
encode_application_object_id(&apdu[iLen], OBJECT_DEVICE,
|
||||
pMatch->device_id);
|
||||
iLen +=
|
||||
encode_application_unsigned(&apdu[iLen], pMatch->address.net);
|
||||
|
||||
/* pick the appropriate type of entry from the cache */
|
||||
|
||||
if(pMatch->address.len != 0) {
|
||||
octetstring_init(&MAC_Address, pMatch->address.adr, pMatch->address.len);
|
||||
iLen += encode_application_octet_string(&apdu[iLen], &MAC_Address);
|
||||
}
|
||||
else {
|
||||
octetstring_init(&MAC_Address, pMatch->address.mac, pMatch->address.mac_len);
|
||||
iLen += encode_application_octet_string(&apdu[iLen], &MAC_Address);
|
||||
if (pMatch->address.len != 0) {
|
||||
octetstring_init(&MAC_Address, pMatch->address.adr,
|
||||
pMatch->address.len);
|
||||
iLen +=
|
||||
encode_application_octet_string(&apdu[iLen], &MAC_Address);
|
||||
} else {
|
||||
octetstring_init(&MAC_Address, pMatch->address.mac,
|
||||
pMatch->address.mac_len);
|
||||
iLen +=
|
||||
encode_application_octet_string(&apdu[iLen], &MAC_Address);
|
||||
}
|
||||
}
|
||||
pMatch++;
|
||||
}
|
||||
|
||||
return(iLen);
|
||||
return (iLen);
|
||||
}
|
||||
|
||||
|
||||
@@ -618,15 +634,15 @@ return(iLen);
|
||||
****************************************************************************/
|
||||
|
||||
void address_cache_timer(
|
||||
uint16_t uSeconds) /* Approximate number of seconds since last call to this function */
|
||||
{
|
||||
uint16_t uSeconds)
|
||||
{ /* Approximate number of seconds since last call to this function */
|
||||
struct Address_Cache_Entry *pMatch;
|
||||
|
||||
pMatch = Address_Cache;
|
||||
while(pMatch <= &Address_Cache[MAX_ADDRESS_CACHE-1] ) {
|
||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
if (((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_RESERVED)) != 0)
|
||||
&& ((pMatch->Flags & BAC_ADDR_STATIC) != 0)) { /* Check all entries holding a slot except statics */
|
||||
if(pMatch->TimeToLive >= uSeconds)
|
||||
if (pMatch->TimeToLive >= uSeconds)
|
||||
pMatch->TimeToLive -= uSeconds;
|
||||
else
|
||||
pMatch->Flags = 0;
|
||||
|
||||
@@ -459,7 +459,7 @@ void apdu_handler(
|
||||
WritePropertyMultiple-Error and VTClose_Error but they may be left as
|
||||
is for now until support for these services is added */
|
||||
|
||||
if(service_choice == SERVICE_CONFIRMED_PRIVATE_TRANSFER) { /* skip over opening tag 0 */
|
||||
if (service_choice == SERVICE_CONFIRMED_PRIVATE_TRANSFER) { /* skip over opening tag 0 */
|
||||
if (decode_is_opening_tag_number(&apdu[len], 0)) {
|
||||
len++; /* a tag number of 0 is not extended so only one octet */
|
||||
}
|
||||
@@ -475,7 +475,7 @@ void apdu_handler(
|
||||
/* FIXME: we could validate that the tag is enumerated... */
|
||||
len += decode_enumerated(&apdu[len], len_value, &error_code);
|
||||
|
||||
if(service_choice == SERVICE_CONFIRMED_PRIVATE_TRANSFER) { /* skip over closing tag 0 */
|
||||
if (service_choice == SERVICE_CONFIRMED_PRIVATE_TRANSFER) { /* skip over closing tag 0 */
|
||||
if (decode_is_closing_tag_number(&apdu[len], 0)) {
|
||||
len++; /* a tag number of 0 is not extended so only one octet */
|
||||
}
|
||||
|
||||
+61
-62
@@ -185,12 +185,16 @@ int bacapp_decode_data(
|
||||
#endif
|
||||
#if defined (BACAPP_REAL)
|
||||
case BACNET_APPLICATION_TAG_REAL:
|
||||
len = decode_real_safe(&apdu[0], len_value_type, &(value->type.Real));
|
||||
len =
|
||||
decode_real_safe(&apdu[0], len_value_type,
|
||||
&(value->type.Real));
|
||||
break;
|
||||
#endif
|
||||
#if defined (BACAPP_DOUBLE)
|
||||
case BACNET_APPLICATION_TAG_DOUBLE:
|
||||
len = decode_double_safe(&apdu[0], len_value_type, &(value->type.Double));
|
||||
len =
|
||||
decode_double_safe(&apdu[0], len_value_type,
|
||||
&(value->type.Double));
|
||||
break;
|
||||
#endif
|
||||
#if defined (BACAPP_OCTET_STRING)
|
||||
@@ -223,12 +227,16 @@ int bacapp_decode_data(
|
||||
#endif
|
||||
#if defined (BACAPP_DATE)
|
||||
case BACNET_APPLICATION_TAG_DATE:
|
||||
len = decode_date_safe(&apdu[0], len_value_type, &value->type.Date);
|
||||
len =
|
||||
decode_date_safe(&apdu[0], len_value_type,
|
||||
&value->type.Date);
|
||||
break;
|
||||
#endif
|
||||
#if defined (BACAPP_TIME)
|
||||
case BACNET_APPLICATION_TAG_TIME:
|
||||
len = decode_bacnet_time_safe(&apdu[0], len_value_type, &value->type.Time);
|
||||
len =
|
||||
decode_bacnet_time_safe(&apdu[0], len_value_type,
|
||||
&value->type.Time);
|
||||
break;
|
||||
#endif
|
||||
#if defined (BACAPP_OBJECT_ID)
|
||||
@@ -236,7 +244,9 @@ int bacapp_decode_data(
|
||||
{
|
||||
uint16_t object_type = 0;
|
||||
uint32_t instance = 0;
|
||||
len = decode_object_id_safe(&apdu[0], len_value_type, &object_type, &instance);
|
||||
len =
|
||||
decode_object_id_safe(&apdu[0], len_value_type,
|
||||
&object_type, &instance);
|
||||
value->type.Object_Id.type = object_type;
|
||||
value->type.Object_Id.instance = instance;
|
||||
}
|
||||
@@ -247,8 +257,8 @@ int bacapp_decode_data(
|
||||
}
|
||||
}
|
||||
|
||||
if ( len == 0 && tag_data_type != BACNET_APPLICATION_TAG_NULL && tag_data_type != BACNET_APPLICATION_TAG_BOOLEAN )
|
||||
{
|
||||
if (len == 0 && tag_data_type != BACNET_APPLICATION_TAG_NULL &&
|
||||
tag_data_type != BACNET_APPLICATION_TAG_BOOLEAN) {
|
||||
value->tag = MAX_BACNET_APPLICATION_TAG;
|
||||
}
|
||||
return len;
|
||||
@@ -303,7 +313,7 @@ bool bacapp_decode_application_data_safe(
|
||||
BACNET_APPLICATION_DATA_VALUE * value)
|
||||
{
|
||||
/* The static variables that store the apdu buffer between function calls */
|
||||
static uint8_t * apdu = NULL;
|
||||
static uint8_t *apdu = NULL;
|
||||
static int32_t apdu_len_remaining = 0;
|
||||
static uint32_t apdu_len = 0;
|
||||
int len = 0;
|
||||
@@ -313,30 +323,30 @@ bool bacapp_decode_application_data_safe(
|
||||
|
||||
bool ret = false;
|
||||
|
||||
if ( new_apdu != NULL )
|
||||
{
|
||||
if (new_apdu != NULL) {
|
||||
apdu = new_apdu;
|
||||
apdu_len_remaining = new_apdu_len;
|
||||
apdu_len = 0;
|
||||
}
|
||||
|
||||
if (value && apdu_len_remaining > 0 && !IS_CONTEXT_SPECIFIC(apdu[apdu_len]) ) {
|
||||
if (value && apdu_len_remaining > 0 &&
|
||||
!IS_CONTEXT_SPECIFIC(apdu[apdu_len])) {
|
||||
value->context_specific = false;
|
||||
tag_len =
|
||||
decode_tag_number_and_value_safe(&apdu[apdu_len], apdu_len_remaining, &tag_number,
|
||||
&len_value_type);
|
||||
decode_tag_number_and_value_safe(&apdu[apdu_len],
|
||||
apdu_len_remaining, &tag_number, &len_value_type);
|
||||
/* If tag_len is zero, then the tag information is truncated */
|
||||
if (tag_len) {
|
||||
apdu_len += tag_len;
|
||||
apdu_len_remaining -= tag_len;
|
||||
/* The tag is boolean then len_value_type is interpreted as value, not length, so dont bother
|
||||
** checking with apdu_len_remaining */
|
||||
if ( tag_number == BACNET_APPLICATION_TAG_BOOLEAN || len_value_type <= apdu_len_remaining )
|
||||
{
|
||||
if (tag_number == BACNET_APPLICATION_TAG_BOOLEAN ||
|
||||
len_value_type <= apdu_len_remaining) {
|
||||
value->tag = tag_number;
|
||||
len =
|
||||
bacapp_decode_data(&apdu[apdu_len], tag_number, len_value_type,
|
||||
value);
|
||||
bacapp_decode_data(&apdu[apdu_len], tag_number,
|
||||
len_value_type, value);
|
||||
apdu_len += len;
|
||||
apdu_len_remaining -= len;
|
||||
|
||||
@@ -849,8 +859,8 @@ bool bacapp_print_value(
|
||||
case PROP_OBJECT_TYPE:
|
||||
if (value->type.Enumerated < MAX_ASHRAE_OBJECT_TYPE) {
|
||||
fprintf(stream, "%s",
|
||||
bactext_object_type_name(
|
||||
value->type.Enumerated));
|
||||
bactext_object_type_name(value->type.
|
||||
Enumerated));
|
||||
} else if (value->type.Enumerated < 128) {
|
||||
fprintf(stream, "reserved %u",
|
||||
value->type.Enumerated);
|
||||
@@ -866,17 +876,17 @@ bool bacapp_print_value(
|
||||
case PROP_UNITS:
|
||||
if (value->type.Enumerated < 256) {
|
||||
fprintf(stream, "%s",
|
||||
bactext_engineering_unit_name(value->type.
|
||||
Enumerated));
|
||||
bactext_engineering_unit_name(value->
|
||||
type.Enumerated));
|
||||
} else {
|
||||
fprintf(stream, "proprietary %u",value->type.
|
||||
Enumerated);
|
||||
fprintf(stream, "proprietary %u",
|
||||
value->type.Enumerated);
|
||||
}
|
||||
break;
|
||||
case PROP_PRESENT_VALUE:
|
||||
fprintf(stream, "%s",
|
||||
bactext_binary_present_value_name(value->type.
|
||||
Enumerated));
|
||||
bactext_binary_present_value_name(value->
|
||||
type.Enumerated));
|
||||
break;
|
||||
case PROP_RELIABILITY:
|
||||
fprintf(stream, "%s",
|
||||
@@ -884,8 +894,8 @@ bool bacapp_print_value(
|
||||
break;
|
||||
case PROP_SYSTEM_STATUS:
|
||||
fprintf(stream, "%s",
|
||||
bactext_device_status_name(value->type.
|
||||
Enumerated));
|
||||
bactext_device_status_name(value->
|
||||
type.Enumerated));
|
||||
break;
|
||||
case PROP_SEGMENTATION_SUPPORTED:
|
||||
fprintf(stream, "%s",
|
||||
@@ -1214,14 +1224,12 @@ void testBACnetApplicationData_Safe(
|
||||
BACNET_APPLICATION_DATA_VALUE value;
|
||||
|
||||
|
||||
for ( i = 0;i < 13; i++)
|
||||
{
|
||||
input_value[i].tag = (BACNET_APPLICATION_TAG)i;
|
||||
for (i = 0; i < 13; i++) {
|
||||
input_value[i].tag = (BACNET_APPLICATION_TAG) i;
|
||||
input_value[i].context_specific = 0;
|
||||
input_value[i].context_tag = 0;
|
||||
input_value[i].next = NULL;
|
||||
switch(input_value[i].tag)
|
||||
{
|
||||
switch (input_value[i].tag) {
|
||||
case BACNET_APPLICATION_TAG_NULL:
|
||||
/* NULL: no data */
|
||||
break;
|
||||
@@ -1245,11 +1253,13 @@ void testBACnetApplicationData_Safe(
|
||||
break;
|
||||
|
||||
case BACNET_APPLICATION_TAG_OCTET_STRING:
|
||||
octetstring_init(&input_value[i].type.Octet_String, "This is a o-string", strlen("This is a o-string"));
|
||||
octetstring_init(&input_value[i].type.Octet_String,
|
||||
"This is a o-string", strlen("This is a o-string"));
|
||||
break;
|
||||
|
||||
case BACNET_APPLICATION_TAG_CHARACTER_STRING:
|
||||
characterstring_init_ansi(&input_value[i].type.Character_String, "Hello There!");
|
||||
characterstring_init_ansi(&input_value[i].type.
|
||||
Character_String, "Hello There!");
|
||||
break;
|
||||
|
||||
case BACNET_APPLICATION_TAG_BIT_STRING:
|
||||
@@ -1289,16 +1299,14 @@ void testBACnetApplicationData_Safe(
|
||||
default:
|
||||
break;
|
||||
}
|
||||
single_length_segment = bacapp_encode_data(&apdu[len], &input_value[i]);;
|
||||
single_length_segment =
|
||||
bacapp_encode_data(&apdu[len], &input_value[i]);;
|
||||
assert(single_length_segment > 0);
|
||||
/* len_segment is accumulated length */
|
||||
if ( i == 0 )
|
||||
{
|
||||
if (i == 0) {
|
||||
len_segment[i] = single_length_segment;
|
||||
}
|
||||
else
|
||||
{
|
||||
len_segment[i] = single_length_segment + len_segment[i-1];
|
||||
} else {
|
||||
len_segment[i] = single_length_segment + len_segment[i - 1];
|
||||
}
|
||||
len = len_segment[i];
|
||||
}
|
||||
@@ -1306,40 +1314,31 @@ void testBACnetApplicationData_Safe(
|
||||
** Start processing packets at processivly truncated lengths
|
||||
*/
|
||||
|
||||
for ( apdu_len = len; apdu_len >=0; apdu_len--)
|
||||
{
|
||||
for (apdu_len = len; apdu_len >= 0; apdu_len--) {
|
||||
bool status;
|
||||
bool expected_status;
|
||||
for ( i = 0;i < 14; i++)
|
||||
{
|
||||
if ( i == 13 )
|
||||
{
|
||||
for (i = 0; i < 14; i++) {
|
||||
if (i == 13) {
|
||||
expected_status = false;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
|
||||
if ( apdu_len < len_segment[i] )
|
||||
{
|
||||
if (apdu_len < len_segment[i]) {
|
||||
expected_status = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
expected_status = true;
|
||||
}
|
||||
}
|
||||
status = bacapp_decode_application_data_safe(i == 0?apdu:NULL, apdu_len, &value);
|
||||
status =
|
||||
bacapp_decode_application_data_safe(i == 0 ? apdu : NULL,
|
||||
apdu_len, &value);
|
||||
|
||||
ct_test(pTest, status == expected_status);
|
||||
if ( status )
|
||||
{
|
||||
if (status) {
|
||||
ct_test(pTest, value.tag == i);
|
||||
ct_test(pTest,
|
||||
bacapp_same_value(&input_value[i], &value));
|
||||
ct_test(pTest, bacapp_same_value(&input_value[i], &value));
|
||||
ct_test(pTest, !value.context_specific);
|
||||
ct_test(pTest, value.next == NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
+44
-45
@@ -331,7 +331,7 @@ int decode_tag_number_safe(
|
||||
int len = 0; /* return value */
|
||||
|
||||
/* decode the tag number first */
|
||||
if ( apdu_len_remaining >= 1 ) {
|
||||
if (apdu_len_remaining >= 1) {
|
||||
if (IS_EXTENDED_TAG_NUMBER(apdu[0]) && apdu_len_remaining >= 2) {
|
||||
/* extended tag */
|
||||
if (tag_number) {
|
||||
@@ -423,7 +423,7 @@ int decode_tag_number_and_value_safe(
|
||||
|
||||
len = decode_tag_number_safe(&apdu[0], apdu_len_remaining, tag_number);
|
||||
|
||||
if ( len > 0 ) {
|
||||
if (len > 0) {
|
||||
apdu_len_remaining -= len;
|
||||
if (IS_EXTENDED_VALUE(apdu[0])) {
|
||||
/* tagged as uint32_t */
|
||||
@@ -450,8 +450,7 @@ int decode_tag_number_and_value_safe(
|
||||
*value = apdu[len];
|
||||
}
|
||||
len++;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
/* packet is truncated */
|
||||
len = 0;
|
||||
}
|
||||
@@ -477,7 +476,8 @@ bool decode_is_context_tag(
|
||||
uint8_t my_tag_number = 0;
|
||||
|
||||
decode_tag_number(apdu, &my_tag_number);
|
||||
return (bool) (IS_CONTEXT_SPECIFIC(*apdu) && (my_tag_number == tag_number));
|
||||
return (bool) (IS_CONTEXT_SPECIFIC(*apdu) &&
|
||||
(my_tag_number == tag_number));
|
||||
}
|
||||
|
||||
bool decode_is_context_tag_with_length(
|
||||
@@ -489,7 +489,8 @@ bool decode_is_context_tag_with_length(
|
||||
|
||||
*tag_length = decode_tag_number(apdu, &my_tag_number);
|
||||
|
||||
return (bool) (IS_CONTEXT_SPECIFIC(*apdu) && (my_tag_number == tag_number));
|
||||
return (bool) (IS_CONTEXT_SPECIFIC(*apdu) &&
|
||||
(my_tag_number == tag_number));
|
||||
}
|
||||
|
||||
/* from clause 20.2.1.3.2 Constructed Data */
|
||||
@@ -788,10 +789,9 @@ int decode_object_id_safe(
|
||||
uint16_t * object_type,
|
||||
uint32_t * instance)
|
||||
{
|
||||
if ( len_value != 4 ) {
|
||||
if (len_value != 4) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return decode_object_id(apdu, object_type, instance);
|
||||
}
|
||||
}
|
||||
@@ -1561,16 +1561,13 @@ int decode_bacnet_time_safe(
|
||||
uint32_t len_value,
|
||||
BACNET_TIME * btime)
|
||||
{
|
||||
if ( len_value != 4 )
|
||||
{
|
||||
if (len_value != 4) {
|
||||
btime->hour = 0;
|
||||
btime->hundredths = 0;
|
||||
btime->min = 0;
|
||||
btime->sec = 0;
|
||||
return len_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return decode_bacnet_time(apdu, btime);
|
||||
}
|
||||
}
|
||||
@@ -1697,14 +1694,13 @@ int decode_date_safe(
|
||||
uint32_t len_value,
|
||||
BACNET_DATE * bdate)
|
||||
{
|
||||
if ( len_value != 4 ) {
|
||||
if (len_value != 4) {
|
||||
bdate->day = 0;
|
||||
bdate->month = 0;
|
||||
bdate->wday = 0;
|
||||
bdate->year = 0;
|
||||
return len_value;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return decode_date(apdu, bdate);
|
||||
}
|
||||
}
|
||||
@@ -1872,8 +1868,7 @@ void testBACDCodeTags(
|
||||
&test_value);
|
||||
ct_test(pTest, tag_number == test_tag_number);
|
||||
ct_test(pTest, value == test_value);
|
||||
test_len =
|
||||
get_apdu_len(IS_EXTENDED_TAG_NUMBER(apdu[0]), value);
|
||||
test_len = get_apdu_len(IS_EXTENDED_TAG_NUMBER(apdu[0]), value);
|
||||
ct_test(pTest, len == test_len);
|
||||
/* stop at the the last value */
|
||||
if (value & BIT31) {
|
||||
@@ -2398,7 +2393,7 @@ void testUnsignedContextDecodes(
|
||||
|
||||
inLen = encode_context_unsigned(apdu, large_context_tag, in);
|
||||
outLen = decode_context_unsigned(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_unsigned(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_unsigned(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2414,7 +2409,7 @@ void testUnsignedContextDecodes(
|
||||
|
||||
inLen = encode_context_unsigned(apdu, large_context_tag, in);
|
||||
outLen = decode_context_unsigned(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_unsigned(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_unsigned(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2429,7 +2424,7 @@ void testUnsignedContextDecodes(
|
||||
|
||||
inLen = encode_context_unsigned(apdu, large_context_tag, in);
|
||||
outLen = decode_context_unsigned(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_unsigned(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_unsigned(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2444,7 +2439,7 @@ void testUnsignedContextDecodes(
|
||||
|
||||
inLen = encode_context_unsigned(apdu, large_context_tag, in);
|
||||
outLen = decode_context_unsigned(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_unsigned(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_unsigned(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2459,7 +2454,7 @@ void testUnsignedContextDecodes(
|
||||
|
||||
inLen = encode_context_unsigned(apdu, large_context_tag, in);
|
||||
outLen = decode_context_unsigned(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_unsigned(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_unsigned(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2493,7 +2488,7 @@ void testSignedContextDecodes(
|
||||
|
||||
inLen = encode_context_signed(apdu, large_context_tag, in);
|
||||
outLen = decode_context_signed(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_signed(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_signed(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2509,7 +2504,7 @@ void testSignedContextDecodes(
|
||||
|
||||
inLen = encode_context_signed(apdu, large_context_tag, in);
|
||||
outLen = decode_context_signed(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_signed(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_signed(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2525,7 +2520,7 @@ void testSignedContextDecodes(
|
||||
|
||||
inLen = encode_context_signed(apdu, large_context_tag, in);
|
||||
outLen = decode_context_signed(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_signed(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_signed(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2541,7 +2536,7 @@ void testSignedContextDecodes(
|
||||
|
||||
inLen = encode_context_signed(apdu, large_context_tag, in);
|
||||
outLen = decode_context_signed(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_signed(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_signed(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2557,7 +2552,7 @@ void testSignedContextDecodes(
|
||||
|
||||
inLen = encode_context_signed(apdu, large_context_tag, in);
|
||||
outLen = decode_context_signed(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_signed(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_signed(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2590,7 +2585,7 @@ void testEnumeratedContextDecodes(
|
||||
|
||||
inLen = encode_context_enumerated(apdu, large_context_tag, in);
|
||||
outLen = decode_context_enumerated(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_enumerated(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_enumerated(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2606,7 +2601,7 @@ void testEnumeratedContextDecodes(
|
||||
|
||||
inLen = encode_context_enumerated(apdu, large_context_tag, in);
|
||||
outLen = decode_context_enumerated(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_enumerated(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_enumerated(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2621,7 +2616,7 @@ void testEnumeratedContextDecodes(
|
||||
|
||||
inLen = encode_context_enumerated(apdu, large_context_tag, in);
|
||||
outLen = decode_context_enumerated(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_enumerated(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_enumerated(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2636,7 +2631,7 @@ void testEnumeratedContextDecodes(
|
||||
|
||||
inLen = encode_context_enumerated(apdu, large_context_tag, in);
|
||||
outLen = decode_context_enumerated(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_enumerated(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_enumerated(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2651,7 +2646,7 @@ void testEnumeratedContextDecodes(
|
||||
|
||||
inLen = encode_context_enumerated(apdu, large_context_tag, in);
|
||||
outLen = decode_context_enumerated(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_enumerated(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_enumerated(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2683,7 +2678,7 @@ void testFloatContextDecodes(
|
||||
|
||||
inLen = encode_context_real(apdu, large_context_tag, in);
|
||||
outLen = decode_context_real(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_real(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_real(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2699,7 +2694,7 @@ void testFloatContextDecodes(
|
||||
|
||||
inLen = encode_context_real(apdu, large_context_tag, in);
|
||||
outLen = decode_context_real(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_real(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_real(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2731,7 +2726,7 @@ void testDoubleContextDecodes(
|
||||
|
||||
inLen = encode_context_double(apdu, large_context_tag, in);
|
||||
outLen = decode_context_double(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_double(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_double(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2747,7 +2742,7 @@ void testDoubleContextDecodes(
|
||||
|
||||
inLen = encode_context_double(apdu, large_context_tag, in);
|
||||
outLen = decode_context_double(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_double(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_double(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2783,8 +2778,11 @@ static void testObjectIDContextDecodes(
|
||||
ct_test(pTest, outLen2 == -1);
|
||||
|
||||
inLen = encode_context_object_id(apdu, large_context_tag, in_type, in_id);
|
||||
outLen = decode_context_object_id(apdu, large_context_tag, &out_type, &out_id);
|
||||
outLen2 = decode_context_object_id(apdu, large_context_tag-1, &out_type, &out_id);
|
||||
outLen =
|
||||
decode_context_object_id(apdu, large_context_tag, &out_type, &out_id);
|
||||
outLen2 =
|
||||
decode_context_object_id(apdu, large_context_tag - 1, &out_type,
|
||||
&out_id);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in_type == out_type);
|
||||
@@ -2819,7 +2817,8 @@ static void testCharacterStringContextDecodes(
|
||||
|
||||
inLen = encode_context_character_string(apdu, large_context_tag, &in);
|
||||
outLen = decode_context_character_string(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_character_string(apdu, large_context_tag-1, &out);
|
||||
outLen2 =
|
||||
decode_context_character_string(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, outLen2 == -1);
|
||||
ct_test(pTest, inLen == outLen);
|
||||
@@ -2859,7 +2858,7 @@ void testBitStringContextDecodes(
|
||||
|
||||
inLen = encode_context_bitstring(apdu, large_context_tag, &in);
|
||||
outLen = decode_context_bitstring(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_bitstring(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_bitstring(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, outLen2 == -1);
|
||||
ct_test(pTest, inLen == outLen);
|
||||
@@ -2895,7 +2894,7 @@ void testOctetStringContextDecodes(
|
||||
|
||||
inLen = encode_context_octet_string(apdu, large_context_tag, &in);
|
||||
outLen = decode_context_octet_string(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_octet_string(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_octet_string(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, outLen2 == -1);
|
||||
ct_test(pTest, inLen == outLen);
|
||||
@@ -2934,7 +2933,7 @@ void testTimeContextDecodes(
|
||||
|
||||
inLen = encode_context_time(apdu, large_context_tag, &in);
|
||||
outLen = decode_context_bacnet_time(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_bacnet_time(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_bacnet_time(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, outLen2 == -1);
|
||||
ct_test(pTest, inLen == outLen);
|
||||
@@ -2978,7 +2977,7 @@ void testDateContextDecodes(
|
||||
/* Test large tags */
|
||||
inLen = encode_context_date(apdu, large_context_tag, &in);
|
||||
outLen = decode_context_date(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_date(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_date(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in.day == out.day);
|
||||
|
||||
@@ -82,13 +82,10 @@ int decode_real_safe(
|
||||
uint32_t len_value,
|
||||
float *real_value)
|
||||
{
|
||||
if ( len_value != 4 )
|
||||
{
|
||||
if (len_value != 4) {
|
||||
*real_value = 0.0f;
|
||||
return len_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return decode_real(apdu, real_value);
|
||||
}
|
||||
}
|
||||
@@ -181,13 +178,10 @@ int decode_double_safe(
|
||||
uint32_t len_value,
|
||||
double *double_value)
|
||||
{
|
||||
if ( len_value != 8 )
|
||||
{
|
||||
if (len_value != 8) {
|
||||
*double_value = 0.0;
|
||||
return len_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return decode_double(apdu, double_value);
|
||||
}
|
||||
}
|
||||
|
||||
+12
-13
@@ -201,22 +201,19 @@ bool bitstring_same(
|
||||
|
||||
if (bitstring1 && bitstring1) {
|
||||
if ((bitstring1->bits_used == bitstring2->bits_used) &&
|
||||
(bitstring1->bits_used/8 <= MAX_BITSTRING_BYTES))
|
||||
{
|
||||
int bytes_used = bitstring1->bits_used/8;
|
||||
uint8_t compare_mask = 0xFF >> (8 - (bitstring1->bits_used%8));
|
||||
(bitstring1->bits_used / 8 <= MAX_BITSTRING_BYTES)) {
|
||||
int bytes_used = bitstring1->bits_used / 8;
|
||||
uint8_t compare_mask = 0xFF >> (8 - (bitstring1->bits_used % 8));
|
||||
|
||||
for (i = 0; i < bytes_used; i++) {
|
||||
if (bitstring1->value[i] != bitstring2->value[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ( (bitstring1->value[bytes_used] & compare_mask) !=
|
||||
(bitstring2->value[bytes_used] & compare_mask) )
|
||||
{
|
||||
if ((bitstring1->value[bytes_used] & compare_mask) !=
|
||||
(bitstring2->value[bytes_used] & compare_mask)) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -631,7 +628,7 @@ void testBitString(
|
||||
ct_test(pTest, bitstring_bit(&bit_string, bit) == false);
|
||||
}
|
||||
|
||||
/* test for compare equals*/
|
||||
/* test for compare equals */
|
||||
srand(time(NULL));
|
||||
for (max_bit = 0; max_bit < (MAX_BITSTRING_BYTES * 8); max_bit++) {
|
||||
bitstring_init(&bit_string);
|
||||
@@ -643,7 +640,7 @@ void testBitString(
|
||||
}
|
||||
ct_test(pTest, bitstring_same(&bit_string, &bit_string2));
|
||||
}
|
||||
/* test for compare not equals*/
|
||||
/* test for compare not equals */
|
||||
for (max_bit = 1; max_bit < (MAX_BITSTRING_BYTES * 8); max_bit++) {
|
||||
bitstring_init(&bit_string);
|
||||
bitstring_init(&bit_string2);
|
||||
@@ -656,7 +653,8 @@ void testBitString(
|
||||
}
|
||||
/* Set the first bit of bit_string2 and the last bit of bit_string3 to be different */
|
||||
bitstring_set_bit(&bit_string2, 0, !bitstring_bit(&bit_string, 0));
|
||||
bitstring_set_bit(&bit_string3, max_bit-1, !bitstring_bit(&bit_string, max_bit-1));
|
||||
bitstring_set_bit(&bit_string3, max_bit - 1,
|
||||
!bitstring_bit(&bit_string, max_bit - 1));
|
||||
ct_test(pTest, !bitstring_same(&bit_string, &bit_string2));
|
||||
ct_test(pTest, !bitstring_same(&bit_string, &bit_string3));
|
||||
}
|
||||
@@ -772,7 +770,8 @@ void testOctetString(
|
||||
}
|
||||
|
||||
test_length = strlen((char *) test_append_value);
|
||||
status =octetstring_append(&bacnet_string, &test_append_value[0], test_length);
|
||||
status =
|
||||
octetstring_append(&bacnet_string, &test_append_value[0], test_length);
|
||||
strcat((char *) test_append_string, (char *) test_value);
|
||||
strcat((char *) test_append_string, (char *) test_append_value);
|
||||
test_length = strlen((char *) test_append_string);
|
||||
|
||||
+20
-26
@@ -251,9 +251,7 @@ bool bactext_object_type_index(
|
||||
const char *search_name,
|
||||
unsigned *found_index)
|
||||
{
|
||||
return indtext_by_istring(
|
||||
bacnet_object_type_names,
|
||||
search_name,
|
||||
return indtext_by_istring(bacnet_object_type_names, search_name,
|
||||
found_index);
|
||||
}
|
||||
|
||||
@@ -937,10 +935,7 @@ bool bactext_property_index(
|
||||
const char *search_name,
|
||||
unsigned *found_index)
|
||||
{
|
||||
return indtext_by_istring(
|
||||
bacnet_property_names,
|
||||
search_name,
|
||||
found_index);
|
||||
return indtext_by_istring(bacnet_property_names, search_name, found_index);
|
||||
}
|
||||
|
||||
INDTEXT_DATA bacnet_engineering_unit_names[] = {
|
||||
@@ -1348,9 +1343,7 @@ bool bactext_engineering_unit_index(
|
||||
const char *search_name,
|
||||
unsigned *found_index)
|
||||
{
|
||||
return indtext_by_istring(
|
||||
bacnet_engineering_unit_names,
|
||||
search_name,
|
||||
return indtext_by_istring(bacnet_engineering_unit_names, search_name,
|
||||
found_index);
|
||||
}
|
||||
|
||||
@@ -1729,13 +1722,20 @@ const char *bactext_day_of_week_name(
|
||||
|
||||
/* note: different than DayOfWeek bit string where 1=monday */
|
||||
INDTEXT_DATA bacnet_days_of_week_names[] = {
|
||||
{BACNET_DAYS_OF_WEEK_MONDAY, "Monday"},
|
||||
{BACNET_DAYS_OF_WEEK_TUESDAY, "Tuesday"},
|
||||
{BACNET_DAYS_OF_WEEK_WEDNESDAY, "Wednesday"},
|
||||
{BACNET_DAYS_OF_WEEK_THURSDAY, "Thursday"},
|
||||
{BACNET_DAYS_OF_WEEK_FRIDAY, "Friday"},
|
||||
{BACNET_DAYS_OF_WEEK_SATURDAY, "Saturday"},
|
||||
{BACNET_DAYS_OF_WEEK_SUNDAY, "Sunday"},
|
||||
{BACNET_DAYS_OF_WEEK_MONDAY, "Monday"}
|
||||
,
|
||||
{BACNET_DAYS_OF_WEEK_TUESDAY, "Tuesday"}
|
||||
,
|
||||
{BACNET_DAYS_OF_WEEK_WEDNESDAY, "Wednesday"}
|
||||
,
|
||||
{BACNET_DAYS_OF_WEEK_THURSDAY, "Thursday"}
|
||||
,
|
||||
{BACNET_DAYS_OF_WEEK_FRIDAY, "Friday"}
|
||||
,
|
||||
{BACNET_DAYS_OF_WEEK_SATURDAY, "Saturday"}
|
||||
,
|
||||
{BACNET_DAYS_OF_WEEK_SUNDAY, "Sunday"}
|
||||
,
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
@@ -1750,9 +1750,7 @@ bool bactext_days_of_week_index(
|
||||
const char *search_name,
|
||||
unsigned *found_index)
|
||||
{
|
||||
return indtext_by_istring(
|
||||
bacnet_days_of_week_names,
|
||||
search_name,
|
||||
return indtext_by_istring(bacnet_days_of_week_names, search_name,
|
||||
found_index);
|
||||
}
|
||||
|
||||
@@ -1777,9 +1775,7 @@ bool bactext_event_transition_index(
|
||||
const char *search_name,
|
||||
unsigned *found_index)
|
||||
{
|
||||
return indtext_by_istring(
|
||||
bacnet_event_transition_names,
|
||||
search_name,
|
||||
return indtext_by_istring(bacnet_event_transition_names, search_name,
|
||||
found_index);
|
||||
}
|
||||
|
||||
@@ -1823,9 +1819,7 @@ bool bactext_binary_present_value_index(
|
||||
const char *search_name,
|
||||
unsigned *found_index)
|
||||
{
|
||||
return indtext_by_istring(
|
||||
bacnet_binary_present_value_names,
|
||||
search_name,
|
||||
return indtext_by_istring(bacnet_binary_present_value_names, search_name,
|
||||
found_index);
|
||||
}
|
||||
|
||||
|
||||
@@ -546,11 +546,13 @@ static bool bvlc_create_bdt(
|
||||
for (i = 0; i < MAX_BBMD_ENTRIES; i++) {
|
||||
if (npdu_length >= 10) {
|
||||
BBMD_Table[i].valid = true;
|
||||
BBMD_Table[i].dest_address.s_addr = ntohl(*(long *)&npdu[pdu_offset]);
|
||||
BBMD_Table[i].dest_address.s_addr =
|
||||
ntohl(*(long *) &npdu[pdu_offset]);
|
||||
pdu_offset += 4;
|
||||
BBMD_Table[i].dest_port = ntohs(*(short *)&npdu[pdu_offset]);
|
||||
BBMD_Table[i].dest_port = ntohs(*(short *) &npdu[pdu_offset]);
|
||||
pdu_offset += 2;
|
||||
BBMD_Table[i].broadcast_mask.s_addr = ntohl(*(long *)&npdu[pdu_offset]);
|
||||
BBMD_Table[i].broadcast_mask.s_addr =
|
||||
ntohl(*(long *) &npdu[pdu_offset]);
|
||||
pdu_offset += 4;
|
||||
npdu_length -= 10;
|
||||
} else {
|
||||
@@ -673,8 +675,8 @@ static void bvlc_bdt_forward_npdu(
|
||||
mask in the BDT entry and logically ORing it with the
|
||||
BBMD address of the same entry. */
|
||||
bip_dest.sin_addr.s_addr =
|
||||
htonl(((~BBMD_Table[i].broadcast_mask.s_addr) | BBMD_Table[i].
|
||||
dest_address.s_addr));
|
||||
htonl(((~BBMD_Table[i].broadcast_mask.
|
||||
s_addr) | BBMD_Table[i].dest_address.s_addr));
|
||||
bip_dest.sin_port = htons(BBMD_Table[i].dest_port);
|
||||
/* don't send to my broadcast address and same port */
|
||||
if ((bip_dest.sin_addr.s_addr == htonl(bip_get_broadcast_addr()))
|
||||
|
||||
@@ -63,6 +63,7 @@ static uint16_t Timer_Silence(
|
||||
{
|
||||
return SilenceTime;
|
||||
}
|
||||
|
||||
static void Timer_Silence_Reset(
|
||||
void)
|
||||
{
|
||||
|
||||
+139
-134
@@ -190,14 +190,14 @@ int event_notify_encode_service_request(
|
||||
|
||||
len =
|
||||
encode_context_bitstring(&apdu[apdu_len], 0,
|
||||
&data->notificationParams.changeOfBitstring.
|
||||
referencedBitString);
|
||||
&data->notificationParams.
|
||||
changeOfBitstring.referencedBitString);
|
||||
apdu_len += len;
|
||||
|
||||
len =
|
||||
encode_context_bitstring(&apdu[apdu_len], 1,
|
||||
&data->notificationParams.changeOfBitstring.
|
||||
statusFlags);
|
||||
&data->notificationParams.
|
||||
changeOfBitstring.statusFlags);
|
||||
apdu_len += len;
|
||||
|
||||
len = encode_closing_tag(&apdu[apdu_len], 0);
|
||||
@@ -221,8 +221,8 @@ int event_notify_encode_service_request(
|
||||
|
||||
len =
|
||||
encode_context_bitstring(&apdu[apdu_len], 1,
|
||||
&data->notificationParams.changeOfState.
|
||||
statusFlags);
|
||||
&data->notificationParams.
|
||||
changeOfState.statusFlags);
|
||||
apdu_len += len;
|
||||
|
||||
len = encode_closing_tag(&apdu[apdu_len], 1);
|
||||
@@ -240,8 +240,8 @@ int event_notify_encode_service_request(
|
||||
case CHANGE_OF_VALUE_REAL:
|
||||
len =
|
||||
encode_context_real(&apdu[apdu_len], 1,
|
||||
data->notificationParams.changeOfValue.
|
||||
newValue.changeValue);
|
||||
data->notificationParams.
|
||||
changeOfValue.newValue.changeValue);
|
||||
apdu_len += len;
|
||||
break;
|
||||
|
||||
@@ -249,8 +249,8 @@ int event_notify_encode_service_request(
|
||||
len =
|
||||
encode_context_bitstring(&apdu[apdu_len],
|
||||
0,
|
||||
&data->notificationParams.changeOfValue.
|
||||
newValue.changedBits);
|
||||
&data->notificationParams.
|
||||
changeOfValue.newValue.changedBits);
|
||||
apdu_len += len;
|
||||
break;
|
||||
|
||||
@@ -263,8 +263,8 @@ int event_notify_encode_service_request(
|
||||
|
||||
len =
|
||||
encode_context_bitstring(&apdu[apdu_len], 1,
|
||||
&data->notificationParams.changeOfValue.
|
||||
statusFlags);
|
||||
&data->notificationParams.
|
||||
changeOfValue.statusFlags);
|
||||
apdu_len += len;
|
||||
|
||||
len = encode_closing_tag(&apdu[apdu_len], 2);
|
||||
@@ -278,20 +278,20 @@ int event_notify_encode_service_request(
|
||||
|
||||
len =
|
||||
encode_context_real(&apdu[apdu_len], 0,
|
||||
data->notificationParams.floatingLimit.
|
||||
referenceValue);
|
||||
data->notificationParams.
|
||||
floatingLimit.referenceValue);
|
||||
apdu_len += len;
|
||||
|
||||
len =
|
||||
encode_context_bitstring(&apdu[apdu_len], 1,
|
||||
&data->notificationParams.floatingLimit.
|
||||
statusFlags);
|
||||
&data->notificationParams.
|
||||
floatingLimit.statusFlags);
|
||||
apdu_len += len;
|
||||
|
||||
len =
|
||||
encode_context_real(&apdu[apdu_len], 2,
|
||||
data->notificationParams.floatingLimit.
|
||||
setPointValue);
|
||||
data->notificationParams.
|
||||
floatingLimit.setPointValue);
|
||||
apdu_len += len;
|
||||
|
||||
len =
|
||||
@@ -310,8 +310,8 @@ int event_notify_encode_service_request(
|
||||
|
||||
len =
|
||||
encode_context_real(&apdu[apdu_len], 0,
|
||||
data->notificationParams.outOfRange.
|
||||
exceedingValue);
|
||||
data->notificationParams.
|
||||
outOfRange.exceedingValue);
|
||||
apdu_len += len;
|
||||
|
||||
len =
|
||||
@@ -339,26 +339,26 @@ int event_notify_encode_service_request(
|
||||
|
||||
len =
|
||||
encode_context_enumerated(&apdu[apdu_len], 0,
|
||||
data->notificationParams.changeOfLifeSafety.
|
||||
newState);
|
||||
data->notificationParams.
|
||||
changeOfLifeSafety.newState);
|
||||
apdu_len += len;
|
||||
|
||||
len =
|
||||
encode_context_enumerated(&apdu[apdu_len], 1,
|
||||
data->notificationParams.changeOfLifeSafety.
|
||||
newMode);
|
||||
data->notificationParams.
|
||||
changeOfLifeSafety.newMode);
|
||||
apdu_len += len;
|
||||
|
||||
len =
|
||||
encode_context_bitstring(&apdu[apdu_len], 2,
|
||||
&data->notificationParams.changeOfLifeSafety.
|
||||
statusFlags);
|
||||
&data->notificationParams.
|
||||
changeOfLifeSafety.statusFlags);
|
||||
apdu_len += len;
|
||||
|
||||
len =
|
||||
encode_context_enumerated(&apdu[apdu_len], 3,
|
||||
data->notificationParams.changeOfLifeSafety.
|
||||
operationExpected);
|
||||
data->notificationParams.
|
||||
changeOfLifeSafety.operationExpected);
|
||||
apdu_len += len;
|
||||
|
||||
len = encode_closing_tag(&apdu[apdu_len], 8);
|
||||
@@ -372,20 +372,20 @@ int event_notify_encode_service_request(
|
||||
len =
|
||||
bacapp_encode_context_device_obj_property_ref(&apdu
|
||||
[apdu_len], 0,
|
||||
&data->notificationParams.bufferReady.
|
||||
bufferProperty);
|
||||
&data->notificationParams.
|
||||
bufferReady.bufferProperty);
|
||||
apdu_len += len;
|
||||
|
||||
len =
|
||||
encode_context_unsigned(&apdu[apdu_len], 1,
|
||||
data->notificationParams.bufferReady.
|
||||
previousNotification);
|
||||
data->notificationParams.
|
||||
bufferReady.previousNotification);
|
||||
apdu_len += len;
|
||||
|
||||
len =
|
||||
encode_context_unsigned(&apdu[apdu_len], 2,
|
||||
data->notificationParams.bufferReady.
|
||||
currentNotification);
|
||||
data->notificationParams.
|
||||
bufferReady.currentNotification);
|
||||
apdu_len += len;
|
||||
|
||||
len = encode_closing_tag(&apdu[apdu_len], 10);
|
||||
@@ -397,20 +397,20 @@ int event_notify_encode_service_request(
|
||||
|
||||
len =
|
||||
encode_context_unsigned(&apdu[apdu_len], 0,
|
||||
data->notificationParams.unsignedRange.
|
||||
exceedingValue);
|
||||
data->notificationParams.
|
||||
unsignedRange.exceedingValue);
|
||||
apdu_len += len;
|
||||
|
||||
len =
|
||||
encode_context_bitstring(&apdu[apdu_len], 1,
|
||||
&data->notificationParams.unsignedRange.
|
||||
statusFlags);
|
||||
&data->notificationParams.
|
||||
unsignedRange.statusFlags);
|
||||
apdu_len += len;
|
||||
|
||||
len =
|
||||
encode_context_unsigned(&apdu[apdu_len], 2,
|
||||
data->notificationParams.unsignedRange.
|
||||
exceededLimit);
|
||||
data->notificationParams.
|
||||
unsignedRange.exceededLimit);
|
||||
apdu_len += len;
|
||||
|
||||
len = encode_closing_tag(&apdu[apdu_len], 11);
|
||||
@@ -591,16 +591,18 @@ int event_notify_decode_service_request(
|
||||
case EVENT_CHANGE_OF_BITSTRING:
|
||||
if (-1 == (section_length =
|
||||
decode_context_bitstring(&apdu[len], 0,
|
||||
&data->notificationParams.
|
||||
changeOfBitstring.referencedBitString))) {
|
||||
&data->
|
||||
notificationParams.changeOfBitstring.
|
||||
referencedBitString))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
|
||||
if (-1 == (section_length =
|
||||
decode_context_bitstring(&apdu[len], 1,
|
||||
&data->notificationParams.
|
||||
changeOfBitstring.statusFlags))) {
|
||||
&data->
|
||||
notificationParams.changeOfBitstring.
|
||||
statusFlags))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
@@ -611,16 +613,16 @@ int event_notify_decode_service_request(
|
||||
if (-1 == (section_length =
|
||||
bacapp_decode_context_property_state(&apdu
|
||||
[len], 0,
|
||||
&data->notificationParams.changeOfState.
|
||||
newState))) {
|
||||
&data->notificationParams.
|
||||
changeOfState.newState))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
|
||||
if (-1 == (section_length =
|
||||
decode_context_bitstring(&apdu[len], 1,
|
||||
&data->notificationParams.changeOfState.
|
||||
statusFlags))) {
|
||||
&data->notificationParams.
|
||||
changeOfState.statusFlags))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
@@ -638,8 +640,9 @@ int event_notify_decode_service_request(
|
||||
|
||||
if (-1 == (section_length =
|
||||
decode_context_bitstring(&apdu[len], 0,
|
||||
&data->notificationParams.
|
||||
changeOfValue.newValue.changedBits))) {
|
||||
&data->
|
||||
notificationParams.changeOfValue.
|
||||
newValue.changedBits))) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -650,8 +653,9 @@ int event_notify_decode_service_request(
|
||||
CHANGE_OF_VALUE_REAL)) {
|
||||
if (-1 == (section_length =
|
||||
decode_context_real(&apdu[len], 1,
|
||||
&data->notificationParams.
|
||||
changeOfValue.newValue.changeValue))) {
|
||||
&data->
|
||||
notificationParams.changeOfValue.
|
||||
newValue.changeValue))) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -669,8 +673,8 @@ int event_notify_decode_service_request(
|
||||
|
||||
if (-1 == (section_length =
|
||||
decode_context_bitstring(&apdu[len], 1,
|
||||
&data->notificationParams.changeOfValue.
|
||||
statusFlags))) {
|
||||
&data->notificationParams.
|
||||
changeOfValue.statusFlags))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
@@ -679,31 +683,31 @@ int event_notify_decode_service_request(
|
||||
case EVENT_FLOATING_LIMIT:
|
||||
if (-1 == (section_length =
|
||||
decode_context_real(&apdu[len], 0,
|
||||
&data->notificationParams.floatingLimit.
|
||||
referenceValue))) {
|
||||
&data->notificationParams.
|
||||
floatingLimit.referenceValue))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
|
||||
if (-1 == (section_length =
|
||||
decode_context_bitstring(&apdu[len], 1,
|
||||
&data->notificationParams.floatingLimit.
|
||||
statusFlags))) {
|
||||
&data->notificationParams.
|
||||
floatingLimit.statusFlags))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
if (-1 == (section_length =
|
||||
decode_context_real(&apdu[len], 2,
|
||||
&data->notificationParams.floatingLimit.
|
||||
setPointValue))) {
|
||||
&data->notificationParams.
|
||||
floatingLimit.setPointValue))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
|
||||
if (-1 == (section_length =
|
||||
decode_context_real(&apdu[len], 3,
|
||||
&data->notificationParams.floatingLimit.
|
||||
errorLimit))) {
|
||||
&data->notificationParams.
|
||||
floatingLimit.errorLimit))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
@@ -712,31 +716,31 @@ int event_notify_decode_service_request(
|
||||
case EVENT_OUT_OF_RANGE:
|
||||
if (-1 == (section_length =
|
||||
decode_context_real(&apdu[len], 0,
|
||||
&data->notificationParams.outOfRange.
|
||||
exceedingValue))) {
|
||||
&data->notificationParams.
|
||||
outOfRange.exceedingValue))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
|
||||
if (-1 == (section_length =
|
||||
decode_context_bitstring(&apdu[len], 1,
|
||||
&data->notificationParams.outOfRange.
|
||||
statusFlags))) {
|
||||
&data->notificationParams.
|
||||
outOfRange.statusFlags))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
if (-1 == (section_length =
|
||||
decode_context_real(&apdu[len], 2,
|
||||
&data->notificationParams.outOfRange.
|
||||
deadband))) {
|
||||
&data->notificationParams.
|
||||
outOfRange.deadband))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
|
||||
if (-1 == (section_length =
|
||||
decode_context_real(&apdu[len], 3,
|
||||
&data->notificationParams.outOfRange.
|
||||
exceededLimit))) {
|
||||
&data->notificationParams.
|
||||
outOfRange.exceededLimit))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
@@ -764,8 +768,9 @@ int event_notify_decode_service_request(
|
||||
|
||||
if (-1 == (section_length =
|
||||
decode_context_bitstring(&apdu[len], 2,
|
||||
&data->notificationParams.
|
||||
changeOfLifeSafety.statusFlags))) {
|
||||
&data->
|
||||
notificationParams.changeOfLifeSafety.
|
||||
statusFlags))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
@@ -775,8 +780,8 @@ int event_notify_decode_service_request(
|
||||
&value))) {
|
||||
return -1;
|
||||
}
|
||||
data->notificationParams.changeOfLifeSafety.
|
||||
operationExpected =
|
||||
data->notificationParams.
|
||||
changeOfLifeSafety.operationExpected =
|
||||
(BACNET_LIFE_SAFETY_OPERATION) value;
|
||||
len += section_length;
|
||||
break;
|
||||
@@ -785,24 +790,24 @@ int event_notify_decode_service_request(
|
||||
if (-1 == (section_length =
|
||||
bacapp_decode_context_device_obj_property_ref
|
||||
(&apdu[len], 0,
|
||||
&data->notificationParams.bufferReady.
|
||||
bufferProperty))) {
|
||||
&data->notificationParams.
|
||||
bufferReady.bufferProperty))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
|
||||
if (-1 == (section_length =
|
||||
decode_context_unsigned(&apdu[len], 1,
|
||||
&data->notificationParams.bufferReady.
|
||||
previousNotification))) {
|
||||
&data->notificationParams.
|
||||
bufferReady.previousNotification))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
|
||||
if (-1 == (section_length =
|
||||
decode_context_unsigned(&apdu[len], 2,
|
||||
&data->notificationParams.bufferReady.
|
||||
currentNotification))) {
|
||||
&data->notificationParams.
|
||||
bufferReady.currentNotification))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
@@ -811,24 +816,24 @@ int event_notify_decode_service_request(
|
||||
case EVENT_UNSIGNED_RANGE:
|
||||
if (-1 == (section_length =
|
||||
decode_context_unsigned(&apdu[len], 0,
|
||||
&data->notificationParams.unsignedRange.
|
||||
exceedingValue))) {
|
||||
&data->notificationParams.
|
||||
unsignedRange.exceedingValue))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
|
||||
if (-1 == (section_length =
|
||||
decode_context_bitstring(&apdu[len], 1,
|
||||
&data->notificationParams.unsignedRange.
|
||||
statusFlags))) {
|
||||
&data->notificationParams.
|
||||
unsignedRange.statusFlags))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
|
||||
if (-1 == (section_length =
|
||||
decode_context_unsigned(&apdu[len], 2,
|
||||
&data->notificationParams.unsignedRange.
|
||||
exceededLimit))) {
|
||||
&data->notificationParams.
|
||||
unsignedRange.exceededLimit))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
@@ -1085,16 +1090,16 @@ void testEventEventState(
|
||||
|
||||
data.eventType = EVENT_CHANGE_OF_BITSTRING;
|
||||
|
||||
bitstring_init(&data.notificationParams.changeOfBitstring.
|
||||
referencedBitString);
|
||||
bitstring_set_bit(&data.notificationParams.changeOfBitstring.
|
||||
referencedBitString, 0, true);
|
||||
bitstring_set_bit(&data.notificationParams.changeOfBitstring.
|
||||
referencedBitString, 1, false);
|
||||
bitstring_set_bit(&data.notificationParams.changeOfBitstring.
|
||||
referencedBitString, 2, true);
|
||||
bitstring_set_bit(&data.notificationParams.changeOfBitstring.
|
||||
referencedBitString, 2, false);
|
||||
bitstring_init(&data.notificationParams.
|
||||
changeOfBitstring.referencedBitString);
|
||||
bitstring_set_bit(&data.notificationParams.
|
||||
changeOfBitstring.referencedBitString, 0, true);
|
||||
bitstring_set_bit(&data.notificationParams.
|
||||
changeOfBitstring.referencedBitString, 1, false);
|
||||
bitstring_set_bit(&data.notificationParams.
|
||||
changeOfBitstring.referencedBitString, 2, true);
|
||||
bitstring_set_bit(&data.notificationParams.
|
||||
changeOfBitstring.referencedBitString, 2, false);
|
||||
|
||||
bitstring_init(&data.notificationParams.changeOfBitstring.statusFlags);
|
||||
|
||||
@@ -1180,16 +1185,16 @@ void testEventEventState(
|
||||
|
||||
data.notificationParams.changeOfValue.tag = CHANGE_OF_VALUE_BITS;
|
||||
|
||||
bitstring_init(&data.notificationParams.changeOfValue.newValue.
|
||||
changedBits);
|
||||
bitstring_set_bit(&data.notificationParams.changeOfValue.newValue.
|
||||
changedBits, 0, true);
|
||||
bitstring_set_bit(&data.notificationParams.changeOfValue.newValue.
|
||||
changedBits, 1, false);
|
||||
bitstring_set_bit(&data.notificationParams.changeOfValue.newValue.
|
||||
changedBits, 2, false);
|
||||
bitstring_set_bit(&data.notificationParams.changeOfValue.newValue.
|
||||
changedBits, 3, false);
|
||||
bitstring_init(&data.notificationParams.changeOfValue.
|
||||
newValue.changedBits);
|
||||
bitstring_set_bit(&data.notificationParams.changeOfValue.
|
||||
newValue.changedBits, 0, true);
|
||||
bitstring_set_bit(&data.notificationParams.changeOfValue.
|
||||
newValue.changedBits, 1, false);
|
||||
bitstring_set_bit(&data.notificationParams.changeOfValue.
|
||||
newValue.changedBits, 2, false);
|
||||
bitstring_set_bit(&data.notificationParams.changeOfValue.
|
||||
newValue.changedBits, 3, false);
|
||||
|
||||
memset(buffer, 0, MAX_APDU);
|
||||
inLen = event_notify_encode_service_request(&buffer[0], &data);
|
||||
@@ -1429,12 +1434,12 @@ void testEventEventState(
|
||||
data.notificationParams.bufferReady.currentNotification = 2345;
|
||||
data.notificationParams.bufferReady.bufferProperty.deviceIndentifier.type =
|
||||
OBJECT_DEVICE;
|
||||
data.notificationParams.bufferReady.bufferProperty.deviceIndentifier.
|
||||
instance = 500;
|
||||
data.notificationParams.bufferReady.bufferProperty.
|
||||
deviceIndentifier.instance = 500;
|
||||
data.notificationParams.bufferReady.bufferProperty.objectIdentifier.type =
|
||||
OBJECT_ANALOG_INPUT;
|
||||
data.notificationParams.bufferReady.bufferProperty.objectIdentifier.
|
||||
instance = 100;
|
||||
data.notificationParams.bufferReady.bufferProperty.
|
||||
objectIdentifier.instance = 100;
|
||||
data.notificationParams.bufferReady.bufferProperty.propertyIdentifier =
|
||||
PROP_PRESENT_VALUE;
|
||||
data.notificationParams.bufferReady.bufferProperty.arrayIndex = 0;
|
||||
@@ -1459,34 +1464,34 @@ void testEventEventState(
|
||||
|
||||
|
||||
ct_test(pTest,
|
||||
data.notificationParams.bufferReady.bufferProperty.deviceIndentifier.
|
||||
type ==
|
||||
data2.notificationParams.bufferReady.bufferProperty.deviceIndentifier.
|
||||
type);
|
||||
|
||||
ct_test(pTest,
|
||||
data.notificationParams.bufferReady.bufferProperty.deviceIndentifier.
|
||||
instance ==
|
||||
data2.notificationParams.bufferReady.bufferProperty.deviceIndentifier.
|
||||
instance);
|
||||
|
||||
ct_test(pTest,
|
||||
data.notificationParams.bufferReady.bufferProperty.objectIdentifier.
|
||||
instance ==
|
||||
data2.notificationParams.bufferReady.bufferProperty.objectIdentifier.
|
||||
instance);
|
||||
|
||||
ct_test(pTest,
|
||||
data.notificationParams.bufferReady.bufferProperty.objectIdentifier.
|
||||
type ==
|
||||
data2.notificationParams.bufferReady.bufferProperty.objectIdentifier.
|
||||
type);
|
||||
data.notificationParams.bufferReady.bufferProperty.
|
||||
deviceIndentifier.type ==
|
||||
data2.notificationParams.bufferReady.bufferProperty.
|
||||
deviceIndentifier.type);
|
||||
|
||||
ct_test(pTest,
|
||||
data.notificationParams.bufferReady.bufferProperty.
|
||||
propertyIdentifier ==
|
||||
deviceIndentifier.instance ==
|
||||
data2.notificationParams.bufferReady.bufferProperty.
|
||||
propertyIdentifier);
|
||||
deviceIndentifier.instance);
|
||||
|
||||
ct_test(pTest,
|
||||
data.notificationParams.bufferReady.bufferProperty.
|
||||
objectIdentifier.instance ==
|
||||
data2.notificationParams.bufferReady.bufferProperty.
|
||||
objectIdentifier.instance);
|
||||
|
||||
ct_test(pTest,
|
||||
data.notificationParams.bufferReady.bufferProperty.
|
||||
objectIdentifier.type ==
|
||||
data2.notificationParams.bufferReady.bufferProperty.
|
||||
objectIdentifier.type);
|
||||
|
||||
ct_test(pTest,
|
||||
data.notificationParams.bufferReady.
|
||||
bufferProperty.propertyIdentifier ==
|
||||
data2.notificationParams.bufferReady.
|
||||
bufferProperty.propertyIdentifier);
|
||||
|
||||
ct_test(pTest,
|
||||
data.notificationParams.bufferReady.bufferProperty.arrayIndex ==
|
||||
|
||||
+87
-67
@@ -78,12 +78,12 @@ int getevent_decode_service_request(
|
||||
/* Tag 0: Object ID - optional */
|
||||
if (!decode_is_context_tag(&apdu[len++], 0))
|
||||
return -1;
|
||||
len += decode_object_id(&apdu[len],
|
||||
&lastReceivedObjectIdentifier->type,
|
||||
len +=
|
||||
decode_object_id(&apdu[len], &lastReceivedObjectIdentifier->type,
|
||||
&lastReceivedObjectIdentifier->instance);
|
||||
}
|
||||
|
||||
return (int)len;
|
||||
return (int) len;
|
||||
}
|
||||
|
||||
int getevent_ack_encode_apdu_init(
|
||||
@@ -119,32 +119,39 @@ int getevent_ack_encode_apdu_data(
|
||||
event_data = get_event_data;
|
||||
while (event_data) {
|
||||
/* Tag 0: objectIdentifier */
|
||||
apdu_len += encode_context_object_id(&apdu[apdu_len], 0,
|
||||
apdu_len +=
|
||||
encode_context_object_id(&apdu[apdu_len], 0,
|
||||
event_data->objectIdentifier.type,
|
||||
event_data->objectIdentifier.instance);
|
||||
/* Tag 1: eventState */
|
||||
apdu_len += encode_context_enumerated(&apdu[apdu_len], 1,
|
||||
apdu_len +=
|
||||
encode_context_enumerated(&apdu[apdu_len], 1,
|
||||
event_data->eventState);
|
||||
/* Tag 2: acknowledgedTransitions */
|
||||
apdu_len += encode_context_bitstring(&apdu[apdu_len], 2,
|
||||
apdu_len +=
|
||||
encode_context_bitstring(&apdu[apdu_len], 2,
|
||||
&event_data->acknowledgedTransitions);
|
||||
/* Tag 3: eventTimeStamps */
|
||||
apdu_len += encode_opening_tag(&apdu[apdu_len], 3);
|
||||
for (i = 0; i < 3; i++) {
|
||||
apdu_len += bacapp_encode_timestamp(&apdu[apdu_len],
|
||||
apdu_len +=
|
||||
bacapp_encode_timestamp(&apdu[apdu_len],
|
||||
&event_data->eventTimeStamps[i]);
|
||||
}
|
||||
apdu_len += encode_closing_tag(&apdu[apdu_len], 3);
|
||||
/* Tag 4: notifyType */
|
||||
apdu_len += encode_context_enumerated(&apdu[apdu_len], 4,
|
||||
apdu_len +=
|
||||
encode_context_enumerated(&apdu[apdu_len], 4,
|
||||
event_data->notifyType);
|
||||
/* Tag 5: eventEnable */
|
||||
apdu_len += encode_context_bitstring(&apdu[apdu_len], 5,
|
||||
apdu_len +=
|
||||
encode_context_bitstring(&apdu[apdu_len], 5,
|
||||
&event_data->eventEnable);
|
||||
/* Tag 6: eventPriorities */
|
||||
apdu_len += encode_opening_tag(&apdu[apdu_len], 6);
|
||||
for (i = 0; i < 3; i++) {
|
||||
apdu_len += encode_application_unsigned(&apdu[apdu_len],
|
||||
apdu_len +=
|
||||
encode_application_unsigned(&apdu[apdu_len],
|
||||
event_data->eventPriorities[i]);
|
||||
}
|
||||
apdu_len += encode_closing_tag(&apdu[apdu_len], 6);
|
||||
@@ -174,13 +181,13 @@ int getevent_ack_decode_service_request(
|
||||
uint8_t * apdu,
|
||||
int apdu_len, /* total length of the apdu */
|
||||
BACNET_GET_EVENT_INFORMATION_DATA * get_event_data,
|
||||
bool *moreEvents)
|
||||
bool * moreEvents)
|
||||
{
|
||||
uint8_t tag_number = 0;
|
||||
uint32_t len_value = 0;
|
||||
int len = 0; /* total length of decodes */
|
||||
uint32_t enum_value = 0; /* for decoding */
|
||||
BACNET_GET_EVENT_INFORMATION_DATA * event_data;
|
||||
BACNET_GET_EVENT_INFORMATION_DATA *event_data;
|
||||
unsigned i = 0; /* counter */
|
||||
|
||||
/* FIXME: check apdu_len against the len during decode */
|
||||
@@ -193,9 +200,11 @@ int getevent_ack_decode_service_request(
|
||||
while (event_data) {
|
||||
/* Tag 0: objectIdentifier */
|
||||
if (decode_is_context_tag(&apdu[len], 0)) {
|
||||
len += decode_tag_number_and_value(&apdu[len],
|
||||
&tag_number, &len_value);
|
||||
len += decode_object_id(&apdu[len],
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
len +=
|
||||
decode_object_id(&apdu[len],
|
||||
&event_data->objectIdentifier.type,
|
||||
&event_data->objectIdentifier.instance);
|
||||
} else {
|
||||
@@ -203,88 +212,102 @@ int getevent_ack_decode_service_request(
|
||||
}
|
||||
/* Tag 1: eventState */
|
||||
if (decode_is_context_tag(&apdu[len], 1)) {
|
||||
len += decode_tag_number_and_value(&apdu[len],
|
||||
&tag_number, &len_value);
|
||||
len += decode_enumerated(&apdu[len], len_value,
|
||||
&enum_value);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
len += decode_enumerated(&apdu[len], len_value, &enum_value);
|
||||
event_data->eventState = enum_value;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
/* Tag 2: acknowledgedTransitions */
|
||||
if (decode_is_context_tag(&apdu[len], 2)) {
|
||||
len += decode_tag_number_and_value(&apdu[len],
|
||||
&tag_number, &len_value);
|
||||
len += decode_bitstring(&apdu[len], len_value,
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
len +=
|
||||
decode_bitstring(&apdu[len], len_value,
|
||||
&event_data->acknowledgedTransitions);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
/* Tag 3: eventTimeStamps */
|
||||
if (decode_is_opening_tag_number(&apdu[len], 3)) {
|
||||
len += decode_tag_number_and_value(&apdu[len],
|
||||
&tag_number, &len_value);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
for (i = 0; i < 3; i++) {
|
||||
len += bacapp_decode_timestamp(&apdu[len],
|
||||
len +=
|
||||
bacapp_decode_timestamp(&apdu[len],
|
||||
&event_data->eventTimeStamps[i]);
|
||||
}
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
if (decode_is_closing_tag_number(&apdu[len], 3)) {
|
||||
len += decode_tag_number_and_value(&apdu[len],
|
||||
&tag_number, &len_value);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
/* Tag 4: notifyType */
|
||||
if (decode_is_context_tag(&apdu[len], 4)) {
|
||||
len += decode_tag_number_and_value(&apdu[len],
|
||||
&tag_number, &len_value);
|
||||
len += decode_enumerated(&apdu[apdu_len], len_value,
|
||||
&enum_value);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
len +=
|
||||
decode_enumerated(&apdu[apdu_len], len_value, &enum_value);
|
||||
event_data->notifyType = enum_value;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
/* Tag 5: eventEnable */
|
||||
if (decode_is_context_tag(&apdu[len], 5)) {
|
||||
len += decode_tag_number_and_value(&apdu[len],
|
||||
&tag_number, &len_value);
|
||||
len += decode_bitstring(&apdu[len], len_value,
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
len +=
|
||||
decode_bitstring(&apdu[len], len_value,
|
||||
&event_data->eventEnable);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
/* Tag 6: eventPriorities */
|
||||
if (decode_is_opening_tag_number(&apdu[len], 6)) {
|
||||
len += decode_tag_number_and_value(&apdu[len],
|
||||
&tag_number, &len_value);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
for (i = 0; i < 3; i++) {
|
||||
len += decode_tag_number_and_value(&apdu[len],
|
||||
&tag_number, &len_value);
|
||||
len += decode_unsigned(&apdu[len], len_value,
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
len +=
|
||||
decode_unsigned(&apdu[len], len_value,
|
||||
&event_data->eventPriorities[i]);
|
||||
}
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
if (decode_is_closing_tag_number(&apdu[len], 6)) {
|
||||
len += decode_tag_number_and_value(&apdu[len],
|
||||
&tag_number, &len_value);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
if (decode_is_closing_tag_number(&apdu[len], 0)) {
|
||||
len += decode_tag_number_and_value(&apdu[len],
|
||||
&tag_number, &len_value);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
event_data->next = NULL;
|
||||
}
|
||||
event_data = event_data->next;
|
||||
}
|
||||
if (decode_is_context_tag(&apdu[len], 1)) {
|
||||
len += decode_tag_number_and_value(&apdu[len],
|
||||
&tag_number, &len_value);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
*moreEvents = decode_boolean(len_value);
|
||||
} else {
|
||||
return -1;
|
||||
@@ -320,8 +343,9 @@ int getevent_decode_apdu(
|
||||
offset = 4;
|
||||
|
||||
if (apdu_len > offset) {
|
||||
len = getevent_decode_service_request(&apdu[offset],
|
||||
apdu_len - offset, lastReceivedObjectIdentifier);
|
||||
len =
|
||||
getevent_decode_service_request(&apdu[offset], apdu_len - offset,
|
||||
lastReceivedObjectIdentifier);
|
||||
}
|
||||
|
||||
return len;
|
||||
@@ -332,7 +356,7 @@ int getevent_ack_decode_apdu(
|
||||
int apdu_len, /* total length of the apdu */
|
||||
uint8_t * invoke_id,
|
||||
BACNET_GET_EVENT_INFORMATION_DATA * get_event_data,
|
||||
bool *moreEvents)
|
||||
bool * moreEvents)
|
||||
{
|
||||
int len = 0;
|
||||
int offset = 0;
|
||||
@@ -348,8 +372,8 @@ int getevent_ack_decode_apdu(
|
||||
offset = 3;
|
||||
if (apdu_len > offset) {
|
||||
len =
|
||||
getevent_ack_decode_service_request(&apdu[offset], apdu_len - offset,
|
||||
get_event_data, moreEvents);
|
||||
getevent_ack_decode_service_request(&apdu[offset],
|
||||
apdu_len - offset, get_event_data, moreEvents);
|
||||
}
|
||||
|
||||
return len;
|
||||
@@ -375,8 +399,8 @@ void testGetEventInformationAck(
|
||||
bitstring_init(&event_data.acknowledgedTransitions);
|
||||
bitstring_set_bit(&event_data.acknowledgedTransitions,
|
||||
TRANSITION_TO_OFFNORMAL, false);
|
||||
bitstring_set_bit(&event_data.acknowledgedTransitions,
|
||||
TRANSITION_TO_FAULT, false);
|
||||
bitstring_set_bit(&event_data.acknowledgedTransitions, TRANSITION_TO_FAULT,
|
||||
false);
|
||||
bitstring_set_bit(&event_data.acknowledgedTransitions,
|
||||
TRANSITION_TO_NORMAL, false);
|
||||
for (i = 0; i < 3; i++) {
|
||||
@@ -385,18 +409,16 @@ void testGetEventInformationAck(
|
||||
}
|
||||
event_data.notifyType = NOTIFY_ALARM;
|
||||
bitstring_init(&event_data.eventEnable);
|
||||
bitstring_set_bit(&event_data.eventEnable,
|
||||
TRANSITION_TO_OFFNORMAL, true);
|
||||
bitstring_set_bit(&event_data.eventEnable,
|
||||
TRANSITION_TO_FAULT, true);
|
||||
bitstring_set_bit(&event_data.eventEnable,
|
||||
TRANSITION_TO_NORMAL, true);
|
||||
bitstring_set_bit(&event_data.eventEnable, TRANSITION_TO_OFFNORMAL, true);
|
||||
bitstring_set_bit(&event_data.eventEnable, TRANSITION_TO_FAULT, true);
|
||||
bitstring_set_bit(&event_data.eventEnable, TRANSITION_TO_NORMAL, true);
|
||||
for (i = 0; i < 3; i++) {
|
||||
event_data.eventPriorities[i] = 1;
|
||||
}
|
||||
event_data.next = NULL;
|
||||
|
||||
len = getevent_ack_encode_apdu(&apdu[0], sizeof(apdu), invoke_id,
|
||||
len =
|
||||
getevent_ack_encode_apdu(&apdu[0], sizeof(apdu), invoke_id,
|
||||
&event_data, moreEvents);
|
||||
ct_test(pTest, len != 0);
|
||||
ct_test(pTest, len != -1);
|
||||
@@ -413,9 +435,7 @@ void testGetEventInformationAck(
|
||||
event_data.objectIdentifier.instance ==
|
||||
test_event_data.objectIdentifier.instance);
|
||||
|
||||
ct_test(pTest,
|
||||
event_data.eventState ==
|
||||
test_event_data.eventState);
|
||||
ct_test(pTest, event_data.eventState == test_event_data.eventState);
|
||||
}
|
||||
|
||||
void testGetEventInformation(
|
||||
@@ -431,17 +451,17 @@ void testGetEventInformation(
|
||||
|
||||
lastReceivedObjectIdentifier.type = OBJECT_BINARY_INPUT;
|
||||
lastReceivedObjectIdentifier.instance = 12345;
|
||||
len = getevent_encode_apdu(&apdu[0], invoke_id,
|
||||
len =
|
||||
getevent_encode_apdu(&apdu[0], invoke_id,
|
||||
&lastReceivedObjectIdentifier);
|
||||
ct_test(pTest, len != 0);
|
||||
apdu_len = len;
|
||||
|
||||
len = getevent_decode_apdu(&apdu[0], apdu_len, &test_invoke_id,
|
||||
len =
|
||||
getevent_decode_apdu(&apdu[0], apdu_len, &test_invoke_id,
|
||||
&test_lastReceivedObjectIdentifier);
|
||||
ct_test(pTest, len != -1);
|
||||
ct_test(pTest,
|
||||
test_invoke_id ==
|
||||
invoke_id);
|
||||
ct_test(pTest, test_invoke_id == invoke_id);
|
||||
ct_test(pTest,
|
||||
test_lastReceivedObjectIdentifier.type ==
|
||||
lastReceivedObjectIdentifier.type);
|
||||
|
||||
@@ -1211,6 +1211,7 @@ static uint16_t Timer_Silence(
|
||||
{
|
||||
return SilenceTime;
|
||||
}
|
||||
|
||||
static void Timer_Silence_Reset(
|
||||
void)
|
||||
{
|
||||
|
||||
@@ -87,10 +87,8 @@ int ptransfer_encode_apdu(
|
||||
apdu[2] = invoke_id;
|
||||
apdu[3] = SERVICE_CONFIRMED_PRIVATE_TRANSFER;
|
||||
apdu_len = 4;
|
||||
apdu_len = pt_encode_apdu(
|
||||
&apdu[apdu_len],
|
||||
MAX_APDU-apdu_len,
|
||||
private_data);
|
||||
apdu_len =
|
||||
pt_encode_apdu(&apdu[apdu_len], MAX_APDU - apdu_len, private_data);
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
@@ -106,10 +104,8 @@ int uptransfer_encode_apdu(
|
||||
apdu[0] = PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST;
|
||||
apdu[1] = SERVICE_UNCONFIRMED_PRIVATE_TRANSFER;
|
||||
apdu_len = 2;
|
||||
apdu_len = pt_encode_apdu(
|
||||
&apdu[apdu_len],
|
||||
MAX_APDU-apdu_len,
|
||||
private_data);
|
||||
apdu_len =
|
||||
pt_encode_apdu(&apdu[apdu_len], MAX_APDU - apdu_len, private_data);
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
|
||||
+132
-54
@@ -79,13 +79,19 @@ int rr_encode_apdu(
|
||||
apdu[3] = SERVICE_CONFIRMED_READ_RANGE; /* service choice */
|
||||
apdu_len = 4;
|
||||
|
||||
apdu_len += encode_context_object_id(&apdu[apdu_len], 0, rrdata->object_type, rrdata->object_instance);
|
||||
apdu_len += encode_context_enumerated(&apdu[apdu_len], 1, rrdata->object_property);
|
||||
apdu_len +=
|
||||
encode_context_object_id(&apdu[apdu_len], 0, rrdata->object_type,
|
||||
rrdata->object_instance);
|
||||
apdu_len +=
|
||||
encode_context_enumerated(&apdu[apdu_len], 1,
|
||||
rrdata->object_property);
|
||||
|
||||
/* optional array index */
|
||||
|
||||
if (rrdata->array_index != BACNET_ARRAY_ALL) {
|
||||
apdu_len += encode_context_unsigned(&apdu[apdu_len], 2, rrdata->array_index);
|
||||
apdu_len +=
|
||||
encode_context_unsigned(&apdu[apdu_len], 2,
|
||||
rrdata->array_index);
|
||||
}
|
||||
|
||||
/* Build the appropriate (optional) range parameter based on the request type */
|
||||
@@ -93,23 +99,34 @@ int rr_encode_apdu(
|
||||
switch (rrdata->RequestType) {
|
||||
case RR_BY_POSITION:
|
||||
apdu_len += encode_opening_tag(&apdu[apdu_len], 3);
|
||||
apdu_len += encode_application_unsigned(&apdu[apdu_len], rrdata->Range.RefIndex);
|
||||
apdu_len += encode_application_signed(&apdu[apdu_len], rrdata->Count);
|
||||
apdu_len +=
|
||||
encode_application_unsigned(&apdu[apdu_len],
|
||||
rrdata->Range.RefIndex);
|
||||
apdu_len +=
|
||||
encode_application_signed(&apdu[apdu_len], rrdata->Count);
|
||||
apdu_len += encode_closing_tag(&apdu[apdu_len], 3);
|
||||
break;
|
||||
|
||||
case RR_BY_SEQUENCE:
|
||||
apdu_len += encode_opening_tag(&apdu[apdu_len], 6);
|
||||
apdu_len += encode_application_unsigned(&apdu[apdu_len], rrdata->Range.RefSeqNum);
|
||||
apdu_len += encode_application_signed(&apdu[apdu_len], rrdata->Count);
|
||||
apdu_len +=
|
||||
encode_application_unsigned(&apdu[apdu_len],
|
||||
rrdata->Range.RefSeqNum);
|
||||
apdu_len +=
|
||||
encode_application_signed(&apdu[apdu_len], rrdata->Count);
|
||||
apdu_len += encode_closing_tag(&apdu[apdu_len], 6);
|
||||
break;
|
||||
|
||||
case RR_BY_TIME:
|
||||
apdu_len += encode_opening_tag(&apdu[apdu_len], 7);
|
||||
apdu_len += encode_application_date(&apdu[apdu_len], &rrdata->Range.RefTime.date);
|
||||
apdu_len += encode_application_time(&apdu[apdu_len], &rrdata->Range.RefTime.time);
|
||||
apdu_len += encode_application_signed(&apdu[apdu_len], rrdata->Count);
|
||||
apdu_len +=
|
||||
encode_application_date(&apdu[apdu_len],
|
||||
&rrdata->Range.RefTime.date);
|
||||
apdu_len +=
|
||||
encode_application_time(&apdu[apdu_len],
|
||||
&rrdata->Range.RefTime.time);
|
||||
apdu_len +=
|
||||
encode_application_signed(&apdu[apdu_len], rrdata->Count);
|
||||
apdu_len += encode_closing_tag(&apdu[apdu_len], 7);
|
||||
break;
|
||||
|
||||
@@ -148,7 +165,9 @@ int rr_decode_service_request(
|
||||
len += decode_object_id(&apdu[len], &type, &rrdata->object_instance);
|
||||
rrdata->object_type = (BACNET_OBJECT_TYPE) type;
|
||||
/* Tag 1: Property ID */
|
||||
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value_type);
|
||||
if (tag_number != 1)
|
||||
return -1;
|
||||
len += decode_enumerated(&apdu[len], len_value_type, &UnsignedTemp);
|
||||
@@ -156,10 +175,13 @@ int rr_decode_service_request(
|
||||
/* Tag 2: Optional Array Index */
|
||||
rrdata->array_index = BACNET_ARRAY_ALL; /* Assuming this is the most common outcome... */
|
||||
if (len < apdu_len) {
|
||||
TagLen = decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
|
||||
TagLen =
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value_type);
|
||||
if (tag_number == 2) {
|
||||
len += TagLen;
|
||||
len += decode_unsigned(&apdu[len], len_value_type, &UnsignedTemp);
|
||||
len +=
|
||||
decode_unsigned(&apdu[len], len_value_type, &UnsignedTemp);
|
||||
rrdata->array_index = UnsignedTemp;
|
||||
}
|
||||
}
|
||||
@@ -173,35 +195,70 @@ int rr_decode_service_request(
|
||||
* This is so that if we receive a tag we don't recognise, we don't try to decode it
|
||||
* blindly and make a mess of it.
|
||||
*/
|
||||
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
|
||||
switch(tag_number) {
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value_type);
|
||||
switch (tag_number) {
|
||||
case 3: /* ReadRange by position */
|
||||
rrdata->RequestType = RR_BY_POSITION;
|
||||
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
|
||||
len += decode_unsigned(&apdu[len], len_value_type, &rrdata->Range.RefIndex);
|
||||
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
|
||||
len += decode_signed(&apdu[len], len_value_type, &rrdata->Count);
|
||||
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value_type);
|
||||
len +=
|
||||
decode_unsigned(&apdu[len], len_value_type,
|
||||
&rrdata->Range.RefIndex);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value_type);
|
||||
len +=
|
||||
decode_signed(&apdu[len], len_value_type,
|
||||
&rrdata->Count);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value_type);
|
||||
break;
|
||||
|
||||
case 6: /* ReadRange by sequence number */
|
||||
rrdata->RequestType = RR_BY_SEQUENCE;
|
||||
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
|
||||
len += decode_unsigned(&apdu[len], len_value_type, &rrdata->Range.RefSeqNum);
|
||||
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
|
||||
len += decode_signed(&apdu[len], len_value_type, &rrdata->Count);
|
||||
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value_type);
|
||||
len +=
|
||||
decode_unsigned(&apdu[len], len_value_type,
|
||||
&rrdata->Range.RefSeqNum);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value_type);
|
||||
len +=
|
||||
decode_signed(&apdu[len], len_value_type,
|
||||
&rrdata->Count);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value_type);
|
||||
break;
|
||||
|
||||
case 7: /* ReadRange by time stamp */
|
||||
rrdata->RequestType = RR_BY_TIME;
|
||||
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
|
||||
len += decode_date(&apdu[len], &rrdata->Range.RefTime.date);
|
||||
len += decode_bacnet_time(&apdu[len], &rrdata->Range.RefTime.time);
|
||||
len += decode_unsigned(&apdu[len], len_value_type, &rrdata->Range.RefIndex);
|
||||
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
|
||||
len += decode_signed(&apdu[len], len_value_type, &rrdata->Count);
|
||||
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value_type);
|
||||
len +=
|
||||
decode_date(&apdu[len], &rrdata->Range.RefTime.date);
|
||||
len +=
|
||||
decode_bacnet_time(&apdu[len],
|
||||
&rrdata->Range.RefTime.time);
|
||||
len +=
|
||||
decode_unsigned(&apdu[len], len_value_type,
|
||||
&rrdata->Range.RefIndex);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value_type);
|
||||
len +=
|
||||
decode_signed(&apdu[len], len_value_type,
|
||||
&rrdata->Count);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value_type);
|
||||
break;
|
||||
|
||||
default: /* If we don't recognise the tag then we do nothing here and try to return
|
||||
@@ -245,30 +302,41 @@ int rr_ack_encode_apdu(
|
||||
apdu[2] = SERVICE_CONFIRMED_READ_RANGE; /* service choice */
|
||||
apdu_len = 3;
|
||||
/* service ack follows */
|
||||
apdu_len += encode_context_object_id(&apdu[apdu_len], 0, rrdata->object_type, rrdata->object_instance);
|
||||
apdu_len += encode_context_enumerated(&apdu[apdu_len], 1, rrdata->object_property);
|
||||
apdu_len +=
|
||||
encode_context_object_id(&apdu[apdu_len], 0, rrdata->object_type,
|
||||
rrdata->object_instance);
|
||||
apdu_len +=
|
||||
encode_context_enumerated(&apdu[apdu_len], 1,
|
||||
rrdata->object_property);
|
||||
/* context 2 array index is optional */
|
||||
if (rrdata->array_index != BACNET_ARRAY_ALL) {
|
||||
apdu_len += encode_context_unsigned(&apdu[apdu_len], 2, rrdata->array_index);
|
||||
apdu_len +=
|
||||
encode_context_unsigned(&apdu[apdu_len], 2,
|
||||
rrdata->array_index);
|
||||
}
|
||||
/* Context 3 BACnet Result Flags */
|
||||
apdu_len += encode_context_bitstring(&apdu[apdu_len], 3, &rrdata->ResultFlags);
|
||||
apdu_len +=
|
||||
encode_context_bitstring(&apdu[apdu_len], 3, &rrdata->ResultFlags);
|
||||
/* Context 4 Item Count */
|
||||
apdu_len += encode_context_unsigned(&apdu[apdu_len], 4, rrdata->ItemCount);
|
||||
apdu_len +=
|
||||
encode_context_unsigned(&apdu[apdu_len], 4, rrdata->ItemCount);
|
||||
/* Context 5 Property list - reading the standard it looks like an empty list still
|
||||
* requires an opening and closing tag as the tagged parameter is not optional
|
||||
*/
|
||||
apdu_len += encode_opening_tag(&apdu[apdu_len], 5);
|
||||
if(rrdata->ItemCount != 0) {
|
||||
if (rrdata->ItemCount != 0) {
|
||||
for (len = 0; len < rrdata->application_data_len; len++) {
|
||||
apdu[apdu_len++] = rrdata->application_data[len];
|
||||
}
|
||||
}
|
||||
apdu_len += encode_closing_tag(&apdu[apdu_len], 5);
|
||||
|
||||
if((rrdata->ItemCount != 0) && (rrdata->RequestType != RR_BY_POSITION) && (rrdata->RequestType != RR_READ_ALL)) {
|
||||
if ((rrdata->ItemCount != 0) && (rrdata->RequestType != RR_BY_POSITION)
|
||||
&& (rrdata->RequestType != RR_READ_ALL)) {
|
||||
/* Context 6 Sequence number of first item */
|
||||
apdu_len += encode_context_unsigned(&apdu[apdu_len], 6, rrdata->FirstSequence);
|
||||
apdu_len +=
|
||||
encode_context_unsigned(&apdu[apdu_len], 6,
|
||||
rrdata->FirstSequence);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,14 +370,16 @@ int rr_ack_decode_service_request(
|
||||
rrdata->object_type = (BACNET_OBJECT_TYPE) object;
|
||||
|
||||
/* Tag 1: Property ID */
|
||||
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
|
||||
if (tag_number != 1)
|
||||
return -1;
|
||||
len += decode_enumerated(&apdu[len], len_value_type, &property);
|
||||
rrdata->object_property = (BACNET_PROPERTY_ID) property;
|
||||
|
||||
/* Tag 2: Optional Array Index */
|
||||
tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
|
||||
tag_len =
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
|
||||
if (tag_number == 2) {
|
||||
len += tag_len;
|
||||
len += decode_unsigned(&apdu[len], len_value_type, &array_value);
|
||||
@@ -318,14 +388,16 @@ int rr_ack_decode_service_request(
|
||||
rrdata->array_index = BACNET_ARRAY_ALL;
|
||||
|
||||
/* Tag 3: Result Flags */
|
||||
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
|
||||
if (tag_number != 3)
|
||||
return -1;
|
||||
|
||||
len += decode_bitstring(&apdu[len], len_value_type, &rrdata->ResultFlags);
|
||||
|
||||
/* Tag 4: Item count */
|
||||
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
|
||||
if (tag_number != 4)
|
||||
return -1;
|
||||
|
||||
@@ -337,30 +409,36 @@ int rr_ack_decode_service_request(
|
||||
* don't decode the application tag number or its data here */
|
||||
rrdata->application_data = &apdu[len];
|
||||
start_len = len;
|
||||
while(len < apdu_len) {
|
||||
if(IS_CONTEXT_SPECIFIC(apdu[len]) && (decode_is_closing_tag_number(&apdu[len], 5))) {
|
||||
while (len < apdu_len) {
|
||||
if (IS_CONTEXT_SPECIFIC(apdu[len]) &&
|
||||
(decode_is_closing_tag_number(&apdu[len], 5))) {
|
||||
rrdata->application_data_len = len - start_len;
|
||||
len++; /* Step over single byte closing tag */
|
||||
break;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
/* Don't care about tag number, just skipping over anyway */
|
||||
len += decode_tag_number_and_value(&apdu[len], NULL, &len_value_type);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], NULL,
|
||||
&len_value_type);
|
||||
len += len_value_type; /* Skip over data value as well */
|
||||
if(len >= apdu_len) /* APDU is exhausted so we have failed to find closing tag */
|
||||
return(-1);
|
||||
if (len >= apdu_len) /* APDU is exhausted so we have failed to find closing tag */
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
if(len < apdu_len) { /* Still something left to look at? */
|
||||
if (len < apdu_len) { /* Still something left to look at? */
|
||||
/* Tag 6: Item count */
|
||||
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value_type);
|
||||
if (tag_number != 6)
|
||||
return -1;
|
||||
|
||||
len += decode_unsigned(&apdu[len], len_value_type, &rrdata->FirstSequence);
|
||||
len +=
|
||||
decode_unsigned(&apdu[len], len_value_type,
|
||||
&rrdata->FirstSequence);
|
||||
}
|
||||
|
||||
len = apdu_len; /* There should be nothing left to see here */
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user