Fixed EOL, indent.

This commit is contained in:
skarg
2009-10-24 17:02:59 +00:00
parent 857d0c185d
commit c04e69da8c
118 changed files with 2633 additions and 2629 deletions
+5 -4
View File
@@ -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 {
+4 -4
View File
@@ -43,12 +43,12 @@ static char My_Password[32] = "filister";
void handler_dcc_password_set(
char *new_password)
{
size_t i = 0; /* loop counter */
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;
}
+23 -26
View File
@@ -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,
@@ -48,7 +47,7 @@ void handler_get_event_information_set(
if (object_type < MAX_BACNET_OBJECT_TYPE) {
Get_Event_Info[object_type] = pFunction;
}
}
}
void handler_get_event_information(
uint8_t * service_request,
@@ -65,7 +64,7 @@ void handler_get_event_information(
BACNET_ERROR_CODE error_code = ERROR_CODE_UNKNOWN_OBJECT;
BACNET_ADDRESS my_address;
BACNET_OBJECT_ID object_id;
unsigned i = 0, j = 0; /* counter */
unsigned i = 0, j = 0; /* counter */
BACNET_GET_EVENT_INFORMATION_DATA getevent_data;
int valid_event = 0;
@@ -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],
+162 -131
View File
@@ -50,99 +50,122 @@
DATABLOCK MyData[MYMAXBLOCK];
uint8_t IOBufferPT[MAX_APDU]; /* Buffer for building response in */
void ProcessPT(BACNET_PRIVATE_TRANSFER_DATA *data)
uint8_t IOBufferPT[MAX_APDU]; /* Buffer for building response in */
void ProcessPT(
BACNET_PRIVATE_TRANSFER_DATA * data)
{
int iLen; /* Index to current location in data */
char cBlockNumber;
uint32_t ulTemp;
int tag_len;
uint8_t tag_number;
uint32_t len_value_type;
BACNET_CHARACTER_STRING bsTemp;
int iLen; /* Index to current location in data */
char cBlockNumber;
uint32_t ulTemp;
int tag_len;
uint8_t tag_number;
uint32_t len_value_type;
BACNET_CHARACTER_STRING bsTemp;
iLen = 0;
iLen = 0;
/* Decode the block number */
/* Decode the block number */
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;
}
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) {
/* 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 */
/* range as they are really chars) a single precision real and a string which */
/* will be up to 32 chars + a nul */
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 */
/* range as they are really chars) a single precision real and a string which */
/* will be up to 32 chars + a nul */
iLen = 0;
iLen = 0;
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);
characterstring_init_ansi(&bsTemp, MyData[cBlockNumber].sMyString);
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. */
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);
characterstring_init_ansi(&bsTemp, MyData[cBlockNumber].sMyString);
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);
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;
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;
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;
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;
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);
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);
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);
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 {
iLen = encode_application_unsigned(&IOBufferPT[0], MY_ERR_BAD_INDEX); /* Signal bad index */
}
data->serviceParametersLen = iLen;
data->serviceParameters = IOBufferPT;
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);
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 {
iLen = encode_application_unsigned(&IOBufferPT[0], MY_ERR_BAD_INDEX); /* Signal bad index */
}
data->serviceParametersLen = iLen;
data->serviceParameters = IOBufferPT;
}
/*
@@ -162,7 +185,7 @@ void handler_conf_private_trans(
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_DATA * service_data)
{
BACNET_PRIVATE_TRANSFER_DATA data;
BACNET_PRIVATE_TRANSFER_DATA data;
int len;
int pdu_len;
bool error;
@@ -180,76 +203,84 @@ 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. */
/* 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;
}
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;
}
goto CPT_ABORT;
}
/* Simple example with service number of 0 for read block and 1 for write block */
/* 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 */
ProcessPT(&data); /* Will either return a result block or an app level status block */
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
}
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 ((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 */
error = true;
error_class = ERROR_CLASS_SERVICES;
error_code = ERROR_CODE_OTHER;
#if PRINT_ENABLED
fprintf(stderr,"CPT: Not our Vendor ID or invalid service code!\n");
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 */
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);
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");
#endif
}
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);
#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;
}
+112 -97
View File
@@ -48,115 +48,132 @@
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;
int tag_len;
uint8_t tag_number;
uint32_t len_value_type;
BACNET_CHARACTER_STRING bsName;
DATABLOCK Response;
int iLen;
uint32_t ulTemp;
int tag_len;
uint8_t tag_number;
uint32_t len_value_type;
BACNET_CHARACTER_STRING bsName;
DATABLOCK Response;
iLen = 0;
iLen = 0;
if(cBlockNum >= MY_MAX_BLOCK)
return;
if (cBlockNum >= MY_MAX_BLOCK)
return;
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;
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;
iLen += decode_unsigned(&pData[iLen], len_value_type, &ulTemp);
Response.cMyByte1 = (char) ulTemp;
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;
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;
iLen += decode_unsigned(&pData[iLen], len_value_type, &ulTemp);
Response.cMyByte2 = (char) ulTemp;
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;
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);
iLen += decode_real(&pData[iLen], &Response.fMyReal);
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;
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;
iLen += decode_character_string(&pData[iLen], len_value_type, &bsName);
strncpy(Response.sMyString, characterstring_value(&bsName), MY_MAX_STR);
Response.sMyString[MY_MAX_STR] = '\0'; /* Make sure it is nul terminated */
iLen += decode_character_string(&pData[iLen], len_value_type, &bsName);
strncpy(Response.sMyString, characterstring_value(&bsName), MY_MAX_STR);
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(" Real : %f\n", Response.fMyReal);
printf(" String : %s\n\n", Response.sMyString);
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(" 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;
char cBlockNumber;
uint32_t ulTemp;
int tag_len;
uint8_t tag_number;
uint32_t len_value_type;
int iLen; /* Index to current location in data */
uint32_t uiErrorCode;
char cBlockNumber;
uint32_t ulTemp;
int tag_len;
uint8_t tag_number;
uint32_t len_value_type;
iLen = 0;
/* Error code is returned for read and write operations */
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) {
iLen = 0;
/* Error code is returned for read and write operations */
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
printf("CPTA: Bad Encoding!\n");
printf("CPTA: Bad Encoding!\n");
#endif
return;
}
iLen += decode_unsigned(&data->serviceParameters[iLen], len_value_type, &uiErrorCode);
return;
}
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 */
/* Decode the error type and if necessary block number and then fetch the info */
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) {
/* Block Number */
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 (uiErrorCode == MY_ERR_OK) {
/* Block Number */
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
printf("CPTA: Bad Encoding!\n");
printf("CPTA: Bad Encoding!\n");
#endif
return;
}
return;
}
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);
return;
}
}
else { /* Write I/O block - should just be an OK type message */
printf("Private Transfer write operation returned error code: %u\n", uiErrorCode);
}
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);
return;
}
} else { /* Write I/O block - should just be an OK type message */
printf("Private Transfer write operation returned error code: %u\n",
uiErrorCode);
}
}
@@ -183,28 +200,27 @@ void handler_conf_private_trans_ack(
* we were expecting. But this is just to silence some compiler
* warnings from Borland.
*/
src = src;
service_data = service_data;
src = src;
service_data = service_data;
len = 0;
len = 0;
#if PRINT_ENABLED
printf("Received Confirmed Private Transfer Ack!\n");
#endif
len = ptransfer_decode_service_request(service_request, service_len, &data); /* Same decode for ack as for service request! */
if (len < 0)
{
len = ptransfer_decode_service_request(service_request, service_len, &data); /* Same decode for ack as for service request! */
if (len < 0) {
#if PRINT_ENABLED
printf("cpta: Bad Encoding!\n");
printf("cpta: Bad Encoding!\n");
#endif
}
}
ProcessPTA(&data); /* See what to do with the response */
ProcessPTA(&data); /* See what to do with the response */
return;
return;
}
#if 0
@@ -223,4 +239,3 @@ void PTErrorHandler(
Error_Detected = true;
}
#endif
+7 -10
View File
@@ -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,
@@ -54,7 +52,7 @@ void handler_read_property_object_set(
Read_Property[object_type] = pFunction1;
Valid_Instance[object_type] = pFunction2;
}
}
}
/* Encodes the property APDU and returns the length,
or sets the error, and returns -1 */
@@ -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;
+12 -15
View File
@@ -41,9 +41,8 @@
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;
unsigned count;
@@ -77,27 +76,25 @@ void handler_read_property_multiple_list_set(
if (object_type < MAX_BACNET_OBJECT_TYPE) {
RPM_Lists[object_type] = pFunction;
}
}
}
/* for a given object type, returns the special property list */
static void RPM_Property_List(
BACNET_OBJECT_TYPE object_type,
struct special_property_list_t *pPropertyList)
{
rpm_property_lists_function object_property_list = NULL;
rpm_property_lists_function object_property_list = NULL;
pPropertyList->Required.pList = NULL;
pPropertyList->Optional.pList = NULL;
pPropertyList->Proprietary.pList = NULL;
if (object_type < MAX_BACNET_OBJECT_TYPE) {
object_property_list = RPM_Lists[object_type];
}
if (object_property_list) {
object_property_list(
&pPropertyList->Required.pList,
&pPropertyList->Optional.pList,
&pPropertyList->Proprietary.pList);
}
if (object_type < MAX_BACNET_OBJECT_TYPE) {
object_property_list = RPM_Lists[object_type];
}
if (object_property_list) {
object_property_list(&pPropertyList->Required.pList,
&pPropertyList->Optional.pList, &pPropertyList->Proprietary.pList);
}
/* fill the count */
if (pPropertyList->Required.pList) {
pPropertyList->Required.count =
+6 -6
View File
@@ -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;
+28 -11
View File
@@ -43,21 +43,21 @@ 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)
{
int apdu_len = -1;
/* FIXME: Stub function at the moment which just returns something
* for the sake of testing things out. Need to look at existing objects
* and see how we can do this for real.
*/
pRequest->ItemCount = 6;
bitstring_init(&pRequest->ResultFlags);
bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_FIRST_ITEM, true);
bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_LAST_ITEM, true);
bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_LAST_ITEM, true);
bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_MORE_ITEMS, false);
pRequest->FirstSequence = 0;
@@ -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));
+3 -1
View File
@@ -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
+61 -62
View File
@@ -1,62 +1,61 @@
/**************************************************************************
*
* Copyright (C) 2009 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "config.h"
#include "txbuf.h"
#include "bacdef.h"
#include "bacdcode.h"
#include "apdu.h"
#include "npdu.h"
#include "abort.h"
#include "ptransfer.h"
void handler_unconfirmed_private_transfer(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src)
{
BACNET_PRIVATE_TRANSFER_DATA private_data;
int len = 0;
#if PRINT_ENABLED
fprintf(stderr,"Received Unconfirmed Private Transfer Request!\n");
#endif
(void) src;
len = ptransfer_decode_service_request(
service_request, service_len, &private_data);
if (len >= 0) {
#if PRINT_ENABLED
fprintf(stderr,
"UnconfirmedPrivateTransfer: "
"vendorID=%u serviceNumber=%u\n",
private_data.vendorID, private_data.serviceNumber);
#endif
}
}
/**************************************************************************
*
* Copyright (C) 2009 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "config.h"
#include "txbuf.h"
#include "bacdef.h"
#include "bacdcode.h"
#include "apdu.h"
#include "npdu.h"
#include "abort.h"
#include "ptransfer.h"
void handler_unconfirmed_private_transfer(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src)
{
BACNET_PRIVATE_TRANSFER_DATA private_data;
int len = 0;
#if PRINT_ENABLED
fprintf(stderr, "Received Unconfirmed Private Transfer Request!\n");
#endif
(void) src;
len =
ptransfer_decode_service_request(service_request, service_len,
&private_data);
if (len >= 0) {
#if PRINT_ENABLED
fprintf(stderr,
"UnconfirmedPrivateTransfer: " "vendorID=%u serviceNumber=%u\n",
private_data.vendorID, private_data.serviceNumber);
#endif
}
}
+4 -5
View File
@@ -37,9 +37,8 @@
#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,
write_property_function pFunction)
@@ -47,7 +46,7 @@ void handler_write_property_object_set(
if (object_type < MAX_BACNET_OBJECT_TYPE) {
Write_Property[object_type] = pFunction;
}
}
}
void handler_write_property(
uint8_t * service_request,
@@ -87,7 +86,7 @@ void handler_write_property(
len = wp_decode_service_request(service_request, service_len, &wp_data);
#if PRINT_ENABLED
if (len > 0)
fprintf(stderr,
fprintf(stderr,
"WP: type=%u instance=%u property=%u priority=%u index=%d\n",
wp_data.object_type, wp_data.object_instance,
wp_data.object_property, wp_data.priority, wp_data.array_index);
+102 -104
View File
@@ -1,104 +1,102 @@
/**************************************************************************
*
* Copyright (C) 2005 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include "event.h"
#include "datalink.h"
#include "tsm.h"
#include "dcc.h"
#include "address.h"
/* some demo stuff needed */
#include "handlers.h"
#include "txbuf.h"
/* returns the invoke id, 0=unsuccessful */
uint8_t Send_CEvent_Notify(
uint32_t device_id,
BACNET_EVENT_NOTIFICATION_DATA * data)
{
int len = 0;
int pdu_len = 0;
int bytes_sent = 0;
BACNET_NPDU_DATA npdu_data;
BACNET_ADDRESS dest;
BACNET_ADDRESS my_address;
unsigned max_apdu = 0;
bool status = false;
uint8_t invoke_id = 0;
if (!dcc_communication_enabled())
return 0;
/* is the device bound? */
status = address_get_by_device(device_id, &max_apdu, &dest);
/* is there a tsm available? */
if (status)
invoke_id = tsm_next_free_invokeID();
if (invoke_id) {
/* 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);
/* encode the APDU portion of the packet */
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
us and the destination, we won't know unless
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);
#if PRINT_ENABLED
if (bytes_sent <= 0) {
fprintf(stderr,
"Failed to Send ConfirmedEventNotification Request (%s)!\n",
strerror(errno));
}
#endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(stderr,
"Failed to Send ConfirmedEventNotification Request "
"(exceeds destination maximum APDU)!\n");
#endif
}
}
return invoke_id;
}
/**************************************************************************
*
* Copyright (C) 2005 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include "event.h"
#include "datalink.h"
#include "tsm.h"
#include "dcc.h"
#include "address.h"
/* some demo stuff needed */
#include "handlers.h"
#include "txbuf.h"
/* returns the invoke id, 0=unsuccessful */
uint8_t Send_CEvent_Notify(
uint32_t device_id,
BACNET_EVENT_NOTIFICATION_DATA * data)
{
int len = 0;
int pdu_len = 0;
int bytes_sent = 0;
BACNET_NPDU_DATA npdu_data;
BACNET_ADDRESS dest;
BACNET_ADDRESS my_address;
unsigned max_apdu = 0;
bool status = false;
uint8_t invoke_id = 0;
if (!dcc_communication_enabled())
return 0;
/* is the device bound? */
status = address_get_by_device(device_id, &max_apdu, &dest);
/* is there a tsm available? */
if (status)
invoke_id = tsm_next_free_invokeID();
if (invoke_id) {
/* 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);
/* encode the APDU portion of the packet */
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
us and the destination, we won't know unless
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);
#if PRINT_ENABLED
if (bytes_sent <= 0) {
fprintf(stderr,
"Failed to Send ConfirmedEventNotification Request (%s)!\n",
strerror(errno));
}
#endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(stderr,
"Failed to Send ConfirmedEventNotification Request "
"(exceeds destination maximum APDU)!\n");
#endif
}
}
return invoke_id;
}
+28 -26
View File
@@ -50,10 +50,8 @@ uint8_t Send_Private_Transfer_Request(
uint32_t device_id,
uint16_t vendor_id,
uint32_t service_number,
char block_number,
DATABLOCK *block
)
char block_number,
DATABLOCK * block)
{ /* NULL=optional */
BACNET_ADDRESS dest;
BACNET_ADDRESS my_address;
@@ -64,9 +62,9 @@ uint8_t Send_Private_Transfer_Request(
int pdu_len = 0;
int bytes_sent = 0;
BACNET_NPDU_DATA npdu_data;
static uint8_t pt_req_buffer[300]; /* Somewhere to build the request packet */
BACNET_PRIVATE_TRANSFER_DATA pt_block;
BACNET_CHARACTER_STRING bsTemp;
static uint8_t pt_req_buffer[300]; /* Somewhere to build the request packet */
BACNET_PRIVATE_TRANSFER_DATA pt_block;
BACNET_CHARACTER_STRING bsTemp;
/* if we are forbidden to send, don't send! */
if (!dcc_communication_enabled())
@@ -86,28 +84,32 @@ uint8_t Send_Private_Transfer_Request(
&npdu_data);
/* encode the APDU portion of the packet */
pt_block.vendorID = vendor_id;
pt_block.serviceNumber = service_number;
if(service_number == MY_SVC_READ)
{
len += encode_application_unsigned(&pt_req_buffer[len], block_number); /* The block number we want to retrieve */
}
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);
characterstring_init_ansi(&bsTemp, block->sMyString);
len += encode_application_character_string(&pt_req_buffer[len], &bsTemp);
}
pt_block.vendorID = vendor_id;
pt_block.serviceNumber = service_number;
if (service_number == MY_SVC_READ) {
len += encode_application_unsigned(&pt_req_buffer[len], block_number); /* The block number we want to retrieve */
} 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);
characterstring_init_ansi(&bsTemp, block->sMyString);
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);
pt_block.serviceParameters = &pt_req_buffer[0];
pt_block.serviceParametersLen = len;
len =
ptransfer_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id,
&pt_block);
pdu_len += len;
/* will it fit in the sender?
/* will it fit in the sender?
note: if there is a bottleneck router in between
us and the destination, we won't know unless
we have a way to check for that and update the
+18 -10
View File
@@ -67,19 +67,23 @@ uint8_t Send_ReadRange_Request(
/* is there a tsm available? */
if (status)
invoke_id = tsm_next_free_invokeID();
if (invoke_id) {
/* 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;
}
pdu_len += len;
/* is it small enough for the the destination to receive?
note: if there is a bottleneck router in between
@@ -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
}
}
+76 -76
View File
@@ -1,76 +1,76 @@
/**************************************************************************
*
* Copyright (C) 2009 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
#include "config.h"
#include "config.h"
#include "txbuf.h"
#include "bacdef.h"
#include "bacdcode.h"
#include "address.h"
#include "tsm.h"
#include "npdu.h"
#include "apdu.h"
#include "device.h"
#include "datalink.h"
#include "dcc.h"
#include "ptransfer.h"
/* some demo stuff needed */
#include "handlers.h"
#include "txbuf.h"
void Send_UnconfirmedPrivateTransfer(
BACNET_ADDRESS * dest,
BACNET_PRIVATE_TRANSFER_DATA *private_data)
{
int len = 0;
int pdu_len = 0;
int bytes_sent = 0;
BACNET_NPDU_DATA npdu_data;
if (!dcc_communication_enabled())
return;
/* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
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],
private_data);
pdu_len += 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 UnconfirmedPrivateTransfer Request (%s)!\n",
strerror(errno));
#endif
}
/**************************************************************************
*
* Copyright (C) 2009 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
#include "config.h"
#include "config.h"
#include "txbuf.h"
#include "bacdef.h"
#include "bacdcode.h"
#include "address.h"
#include "tsm.h"
#include "npdu.h"
#include "apdu.h"
#include "device.h"
#include "datalink.h"
#include "dcc.h"
#include "ptransfer.h"
/* some demo stuff needed */
#include "handlers.h"
#include "txbuf.h"
void Send_UnconfirmedPrivateTransfer(
BACNET_ADDRESS * dest,
BACNET_PRIVATE_TRANSFER_DATA * private_data)
{
int len = 0;
int pdu_len = 0;
int bytes_sent = 0;
BACNET_NPDU_DATA npdu_data;
if (!dcc_communication_enabled())
return;
/* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
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],
private_data);
pdu_len += 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 UnconfirmedPrivateTransfer Request (%s)!\n",
strerror(errno));
#endif
}
+3 -2
View File
@@ -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) {