Indented using indent script.
This commit is contained in:
@@ -132,11 +132,10 @@ void dlenv_init(
|
||||
if (!datalink_init(getenv("BACNET_IFACE"))) {
|
||||
exit(1);
|
||||
}
|
||||
pEnv = getenv("BACNET_INVOKE_ID");
|
||||
if (pEnv) {
|
||||
tsm_invokeID_set((uint8_t)strtol(pEnv, NULL, 0));
|
||||
}
|
||||
|
||||
pEnv = getenv("BACNET_INVOKE_ID");
|
||||
if (pEnv) {
|
||||
tsm_invokeID_set((uint8_t) strtol(pEnv, NULL, 0));
|
||||
}
|
||||
#if defined(BACDL_BIP) && BBMD_ENABLED
|
||||
pEnv = getenv("BACNET_BBMD_PORT");
|
||||
if (pEnv) {
|
||||
|
||||
@@ -109,8 +109,9 @@ void handler_alarm_ack(
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr,
|
||||
"Alarm Ack Operation: Received acknowledge for object id %lu from %s for process id %lu for object %lu\n",
|
||||
(unsigned long)data.eventObjectIdentifier.instance, data.ackSource.value,
|
||||
(unsigned long)data.ackProcessIdentifier, (unsigned long)data.eventObjectIdentifier.instance);
|
||||
(unsigned long) data.eventObjectIdentifier.instance,
|
||||
data.ackSource.value, (unsigned long) data.ackProcessIdentifier,
|
||||
(unsigned long) data.eventObjectIdentifier.instance);
|
||||
#endif
|
||||
|
||||
len =
|
||||
|
||||
@@ -82,7 +82,7 @@ void handler_atomic_read_file_ack(
|
||||
pFile) != 1) {
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "Failed to write to %s (%lu)!\n",
|
||||
pFilename, (unsigned long)instance);
|
||||
pFilename, (unsigned long) instance);
|
||||
#endif
|
||||
}
|
||||
fclose(pFile);
|
||||
|
||||
@@ -344,9 +344,8 @@ 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;
|
||||
@@ -422,7 +421,7 @@ void handler_cov_task(
|
||||
COV_Subscriptions[index].lifetime -= elapsed_seconds;
|
||||
#if 0
|
||||
fprintf(stderr, "COVtask: subscription[%d].lifetime=%lu\n",
|
||||
index, (unsigned long)COV_Subscriptions[index].lifetime);
|
||||
index, (unsigned long) COV_Subscriptions[index].lifetime);
|
||||
#endif
|
||||
} else {
|
||||
COV_Subscriptions[index].lifetime = 0;
|
||||
@@ -463,8 +462,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 {
|
||||
|
||||
@@ -61,9 +61,9 @@ void handler_i_am_add(
|
||||
#endif
|
||||
if (len != -1) {
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, " from %lu, MAC = %d.%d.%d.%d.%d.%d\n", (unsigned long)device_id,
|
||||
src->mac[0], src->mac[1], src->mac[2], src->mac[3], src->mac[4],
|
||||
src->mac[5]);
|
||||
fprintf(stderr, " from %lu, MAC = %d.%d.%d.%d.%d.%d\n",
|
||||
(unsigned long) device_id, src->mac[0], src->mac[1], src->mac[2],
|
||||
src->mac[3], src->mac[4], src->mac[5]);
|
||||
#endif
|
||||
address_add(device_id, max_apdu, src);
|
||||
} else {
|
||||
|
||||
@@ -55,9 +55,9 @@ void handler_i_have(
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "I-Have: %s %lu from %s %lu!\r\n",
|
||||
bactext_object_type_name(data.object_id.type),
|
||||
(unsigned long)data.object_id.instance,
|
||||
(unsigned long) data.object_id.instance,
|
||||
bactext_object_type_name(data.device_id.type),
|
||||
(unsigned long)data.device_id.instance);
|
||||
(unsigned long) data.device_id.instance);
|
||||
#endif
|
||||
} else {
|
||||
#if PRINT_ENABLED
|
||||
|
||||
@@ -92,7 +92,8 @@ void handler_lso(
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr,
|
||||
"Life Safety Operation: Received operation %d from process id %lu for object %lu\n",
|
||||
data.operation, (unsigned long)data.processId, (unsigned long)data.targetObject.instance);
|
||||
data.operation, (unsigned long) data.processId,
|
||||
(unsigned long) data.targetObject.instance);
|
||||
#endif
|
||||
|
||||
len =
|
||||
|
||||
@@ -64,14 +64,14 @@ void npdu_handler(
|
||||
(uint16_t) (pdu_len - apdu_offset));
|
||||
} else {
|
||||
#if PRINT_ENABLED
|
||||
printf("NPDU: DNET=%u. Discarded!\n", (unsigned)dest.net);
|
||||
printf("NPDU: DNET=%u. Discarded!\n", (unsigned) dest.net);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
} else {
|
||||
#if PRINT_ENABLED
|
||||
printf("NPDU: BACnet Protocol Version=%u. Discarded!\n",
|
||||
(unsigned)pdu[0]);
|
||||
printf("NPDU: BACnet Protocol Version=%u. Discarded!\n",
|
||||
(unsigned) pdu[0]);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -72,10 +72,10 @@ void ProcessPT(
|
||||
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 (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) {
|
||||
/* Bail out early if wrong type */
|
||||
/* and signal unexpected error */
|
||||
data->serviceParametersLen = 0;
|
||||
data->serviceParametersLen = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -86,44 +86,45 @@ void ProcessPT(
|
||||
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 */
|
||||
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;
|
||||
|
||||
/* Signal success */
|
||||
iLen += encode_application_unsigned(&IOBufferPT[iLen], MY_ERR_OK);
|
||||
iLen += encode_application_unsigned(&IOBufferPT[iLen], MY_ERR_OK);
|
||||
/* Followed by the block number */
|
||||
iLen += encode_application_unsigned(&IOBufferPT[iLen],
|
||||
cBlockNumber);
|
||||
iLen +=
|
||||
encode_application_unsigned(&IOBufferPT[iLen], cBlockNumber);
|
||||
/* And Then the block contents */
|
||||
iLen += encode_application_unsigned(&IOBufferPT[iLen],
|
||||
MyData[(int8_t)cBlockNumber].cMyByte1);
|
||||
iLen +=
|
||||
encode_application_unsigned(&IOBufferPT[iLen],
|
||||
MyData[(int8_t)cBlockNumber].cMyByte2);
|
||||
MyData[(int8_t) cBlockNumber].cMyByte1);
|
||||
iLen +=
|
||||
encode_application_unsigned(&IOBufferPT[iLen],
|
||||
MyData[(int8_t) cBlockNumber].cMyByte2);
|
||||
iLen +=
|
||||
encode_application_real(&IOBufferPT[iLen],
|
||||
MyData[(int8_t)cBlockNumber].fMyReal);
|
||||
characterstring_init_ansi(&bsTemp,
|
||||
(char *)MyData[(int8_t)cBlockNumber].sMyString);
|
||||
MyData[(int8_t) cBlockNumber].fMyReal);
|
||||
characterstring_init_ansi(&bsTemp,
|
||||
(char *) MyData[(int8_t) cBlockNumber].sMyString);
|
||||
iLen +=
|
||||
encode_application_character_string(&IOBufferPT[iLen],
|
||||
&bsTemp);
|
||||
} else {
|
||||
} 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. */
|
||||
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],
|
||||
@@ -136,7 +137,7 @@ void ProcessPT(
|
||||
iLen +=
|
||||
decode_unsigned(&data->serviceParameters[iLen], len_value_type,
|
||||
&ulTemp);
|
||||
MyData[(int8_t)cBlockNumber].cMyByte1 = (char) ulTemp;
|
||||
MyData[(int8_t) cBlockNumber].cMyByte1 = (char) ulTemp;
|
||||
|
||||
tag_len =
|
||||
decode_tag_number_and_value(&data->serviceParameters[iLen],
|
||||
@@ -149,7 +150,7 @@ void ProcessPT(
|
||||
iLen +=
|
||||
decode_unsigned(&data->serviceParameters[iLen], len_value_type,
|
||||
&ulTemp);
|
||||
MyData[(int8_t)cBlockNumber].cMyByte2 = (char) ulTemp;
|
||||
MyData[(int8_t) cBlockNumber].cMyByte2 = (char) ulTemp;
|
||||
|
||||
tag_len =
|
||||
decode_tag_number_and_value(&data->serviceParameters[iLen],
|
||||
@@ -161,7 +162,7 @@ void ProcessPT(
|
||||
}
|
||||
iLen +=
|
||||
decode_real(&data->serviceParameters[iLen],
|
||||
&MyData[(int8_t)cBlockNumber].fMyReal);
|
||||
&MyData[(int8_t) cBlockNumber].fMyReal);
|
||||
|
||||
tag_len =
|
||||
decode_tag_number_and_value(&data->serviceParameters[iLen],
|
||||
@@ -174,16 +175,16 @@ void ProcessPT(
|
||||
decode_character_string(&data->serviceParameters[iLen],
|
||||
len_value_type, &bsTemp);
|
||||
/* Only copy as much as we can accept */
|
||||
strncpy((char *)MyData[(int8_t)cBlockNumber].sMyString,
|
||||
characterstring_value(&bsTemp), MY_MAX_STR);
|
||||
strncpy((char *) MyData[(int8_t) cBlockNumber].sMyString,
|
||||
characterstring_value(&bsTemp), MY_MAX_STR);
|
||||
/* Make sure it is nul terminated */
|
||||
MyData[(int8_t)cBlockNumber].sMyString[MY_MAX_STR] = '\0';
|
||||
MyData[(int8_t) cBlockNumber].sMyString[MY_MAX_STR] = '\0';
|
||||
/* Signal success */
|
||||
iLen = encode_application_unsigned(&IOBufferPT[0], MY_ERR_OK);
|
||||
iLen = encode_application_unsigned(&IOBufferPT[0], MY_ERR_OK);
|
||||
}
|
||||
} else {
|
||||
/* Signal bad index */
|
||||
iLen = encode_application_unsigned(&IOBufferPT[0], MY_ERR_BAD_INDEX);
|
||||
iLen = encode_application_unsigned(&IOBufferPT[0], MY_ERR_BAD_INDEX);
|
||||
}
|
||||
data->serviceParametersLen = iLen;
|
||||
data->serviceParameters = IOBufferPT;
|
||||
@@ -260,17 +261,17 @@ void handler_conf_private_trans(
|
||||
}
|
||||
|
||||
/* 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)) {
|
||||
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 */
|
||||
/* Will either return a result block or an app level status block */
|
||||
ProcessPT(&data);
|
||||
if (data.serviceParametersLen == 0) {
|
||||
ProcessPT(&data);
|
||||
if (data.serviceParametersLen == 0) {
|
||||
/* No respopnse means fatal error */
|
||||
error = true;
|
||||
error_class = ERROR_CLASS_SERVICES;
|
||||
|
||||
@@ -104,7 +104,8 @@ void DecodeBlock(
|
||||
return;
|
||||
|
||||
iLen += decode_character_string(&pData[iLen], len_value_type, &bsName);
|
||||
strncpy((char *)Response.sMyString, characterstring_value(&bsName), MY_MAX_STR);
|
||||
strncpy((char *) 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");
|
||||
@@ -168,13 +169,14 @@ void ProcessPTA(
|
||||
cBlockNumber = (char) ulTemp;
|
||||
DecodeBlock(cBlockNumber, &data->serviceParameters[iLen]);
|
||||
} else { /* Read error */
|
||||
printf("Private Transfer read operation returned error code: %lu\n",
|
||||
(unsigned long)uiErrorCode);
|
||||
printf
|
||||
("Private Transfer read operation returned error code: %lu\n",
|
||||
(unsigned long) uiErrorCode);
|
||||
return;
|
||||
}
|
||||
} else { /* Write I/O block - should just be an OK type message */
|
||||
printf("Private Transfer write operation returned error code: %lu\n",
|
||||
(unsigned long)uiErrorCode);
|
||||
(unsigned long) uiErrorCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -96,13 +96,13 @@ void handler_reinitialize_device(
|
||||
goto RD_ABORT;
|
||||
}
|
||||
/* decode the service request only */
|
||||
len = rd_decode_service_request(service_request, service_len,
|
||||
&rd_data.state,
|
||||
len =
|
||||
rd_decode_service_request(service_request, service_len, &rd_data.state,
|
||||
&rd_data.password);
|
||||
#if PRINT_ENABLED
|
||||
if (len > 0) {
|
||||
fprintf(stderr, "ReinitializeDevice: state=%u password=%s\n",
|
||||
(unsigned) rd_data.state,
|
||||
(unsigned) rd_data.state,
|
||||
characterstring_value(&rd_data.password));
|
||||
} else {
|
||||
fprintf(stderr, "ReinitializeDevice: Unable to decode request!\n");
|
||||
@@ -143,8 +143,7 @@ void handler_reinitialize_device(
|
||||
service_data->invoke_id, SERVICE_CONFIRMED_REINITIALIZE_DEVICE,
|
||||
rd_data.error_class, rd_data.error_code);
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr,
|
||||
"ReinitializeDevice: Sending Error.\n");
|
||||
fprintf(stderr, "ReinitializeDevice: Sending Error.\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,26 +113,26 @@ void handler_read_property(
|
||||
}
|
||||
/* assume that there is an error */
|
||||
error = true;
|
||||
apdu_len = rp_ack_encode_apdu_init(
|
||||
&Handler_Transmit_Buffer[npdu_len],
|
||||
service_data->invoke_id,
|
||||
&rpdata);
|
||||
apdu_len =
|
||||
rp_ack_encode_apdu_init(&Handler_Transmit_Buffer[npdu_len],
|
||||
service_data->invoke_id, &rpdata);
|
||||
/* configure our storage */
|
||||
rpdata.application_data = &Handler_Transmit_Buffer[npdu_len+apdu_len];
|
||||
rpdata.application_data_len =
|
||||
rpdata.application_data = &Handler_Transmit_Buffer[npdu_len + apdu_len];
|
||||
rpdata.application_data_len =
|
||||
sizeof(Handler_Transmit_Buffer) - (npdu_len + apdu_len);
|
||||
len = Device_Read_Property(&rpdata);
|
||||
len = Device_Read_Property(&rpdata);
|
||||
if (len >= 0) {
|
||||
apdu_len += len;
|
||||
len = rp_ack_encode_apdu_object_property_end(
|
||||
&Handler_Transmit_Buffer[npdu_len+apdu_len]);
|
||||
len =
|
||||
rp_ack_encode_apdu_object_property_end(&Handler_Transmit_Buffer
|
||||
[npdu_len + apdu_len]);
|
||||
apdu_len += len;
|
||||
if (apdu_len > service_data->max_resp) {
|
||||
/* too big for the sender - send an abort */
|
||||
apdu_len =
|
||||
abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
|
||||
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
|
||||
true);
|
||||
service_data->invoke_id,
|
||||
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "RP: Message too large. Sending Abort!\n");
|
||||
#endif
|
||||
@@ -163,11 +163,11 @@ void handler_read_property(
|
||||
fprintf(stderr, "RP: Sending Error!\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
RP_ABORT:
|
||||
pdu_len = npdu_len + apdu_len;
|
||||
bytes_sent =
|
||||
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
|
||||
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
|
||||
pdu_len);
|
||||
#if PRINT_ENABLED
|
||||
if (bytes_sent <= 0)
|
||||
|
||||
@@ -62,12 +62,12 @@ static void PrintReadPropertyData(
|
||||
if (data->array_index == BACNET_ARRAY_ALL)
|
||||
fprintf(stderr, "%s #%lu %s\n",
|
||||
bactext_object_type_name(data->object_type),
|
||||
(unsigned long)data->object_instance,
|
||||
(unsigned long) data->object_instance,
|
||||
bactext_property_name(data->object_property));
|
||||
else
|
||||
fprintf(stderr, "%s #%lu %s[%d]\n",
|
||||
bactext_object_type_name(data->object_type),
|
||||
(unsigned long)data->object_instance,
|
||||
(unsigned long) data->object_instance,
|
||||
bactext_property_name(data->object_property),
|
||||
data->array_index);
|
||||
#endif
|
||||
@@ -160,23 +160,22 @@ int rp_ack_fully_decode_service_request(
|
||||
{
|
||||
int decoded_len = 0; /* return value */
|
||||
BACNET_READ_PROPERTY_DATA rp1data;
|
||||
BACNET_PROPERTY_REFERENCE *rp1_property; /* single property */
|
||||
BACNET_PROPERTY_REFERENCE *rp1_property; /* single property */
|
||||
BACNET_APPLICATION_DATA_VALUE *value, *old_value;
|
||||
uint8_t * vdata;
|
||||
uint8_t *vdata;
|
||||
int vlen, len;
|
||||
|
||||
decoded_len = rp_ack_decode_service_request(apdu, apdu_len, &rp1data);
|
||||
if ( decoded_len > 0 )
|
||||
{
|
||||
/* Then we have to transfer to the BACNET_READ_ACCESS_DATA structure
|
||||
* and decode the value(s) portion
|
||||
*/
|
||||
read_access_data->object_type = rp1data.object_type;
|
||||
read_access_data->object_instance = rp1data.object_instance;
|
||||
if (decoded_len > 0) {
|
||||
/* Then we have to transfer to the BACNET_READ_ACCESS_DATA structure
|
||||
* and decode the value(s) portion
|
||||
*/
|
||||
read_access_data->object_type = rp1data.object_type;
|
||||
read_access_data->object_instance = rp1data.object_instance;
|
||||
rp1_property = calloc(1, sizeof(BACNET_PROPERTY_REFERENCE));
|
||||
read_access_data->listOfProperties = rp1_property;
|
||||
if ( rp1_property == NULL )
|
||||
return -1; /* can't proceed if calloc failed. */
|
||||
if (rp1_property == NULL)
|
||||
return -1; /* can't proceed if calloc failed. */
|
||||
rp1_property->propertyIdentifier = rp1data.object_property;
|
||||
rp1_property->propertyArrayIndex = rp1data.array_index;
|
||||
/* Is there no Error case possible here, as there is when decoding RPM? */
|
||||
@@ -184,7 +183,7 @@ int rp_ack_fully_decode_service_request(
|
||||
/* rp_ack_decode_service_request() processing already removed the
|
||||
* Opening and Closing '3' Tags.
|
||||
* note: if this is an array, there will be
|
||||
more than one element to decode */
|
||||
more than one element to decode */
|
||||
vdata = rp1data.application_data;
|
||||
vlen = rp1data.application_data_len;
|
||||
value = calloc(1, sizeof(BACNET_APPLICATION_DATA_VALUE));
|
||||
@@ -196,9 +195,7 @@ int rp_ack_fully_decode_service_request(
|
||||
bacapp_decode_context_data(vdata, vlen, value,
|
||||
rp1_property->propertyIdentifier);
|
||||
} else {
|
||||
len =
|
||||
bacapp_decode_application_data(vdata, vlen,
|
||||
value);
|
||||
len = bacapp_decode_application_data(vdata, vlen, value);
|
||||
}
|
||||
decoded_len += len;
|
||||
vlen -= len;
|
||||
@@ -212,17 +209,15 @@ int rp_ack_fully_decode_service_request(
|
||||
} else {
|
||||
/* nothing decoded and no closing tag, so malformed */
|
||||
if (len == 0) {
|
||||
free( value );
|
||||
free( rp1_property );
|
||||
free(value);
|
||||
free(rp1_property);
|
||||
read_access_data->listOfProperties = NULL;
|
||||
return -1;
|
||||
}
|
||||
if ( vlen > 0 ) /* If more values */
|
||||
{
|
||||
old_value = value;
|
||||
value =
|
||||
calloc(1, sizeof(BACNET_APPLICATION_DATA_VALUE));
|
||||
old_value->next = value;
|
||||
if (vlen > 0) { /* If more values */
|
||||
old_value = value;
|
||||
value = calloc(1, sizeof(BACNET_APPLICATION_DATA_VALUE));
|
||||
old_value->next = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ static BACNET_PROPERTY_ID RPM_Object_Property(
|
||||
}
|
||||
}
|
||||
|
||||
return (BACNET_PROPERTY_ID)property;
|
||||
return (BACNET_PROPERTY_ID) property;
|
||||
}
|
||||
|
||||
static unsigned RPM_Object_Property_Count(
|
||||
@@ -133,9 +133,9 @@ static int RPM_Encode_Property(
|
||||
rpdata.application_data_len = sizeof(Temp_Buf);
|
||||
len = Device_Read_Property(&rpdata);
|
||||
if (len < 0) {
|
||||
if ( len == -2 ) {
|
||||
return 0; /* Ie, Abort */
|
||||
}
|
||||
if (len == -2) {
|
||||
return 0; /* Ie, Abort */
|
||||
}
|
||||
/* error was returned - encode that for the response */
|
||||
len =
|
||||
rpm_ack_encode_apdu_object_property_error(&Temp_Buf[0],
|
||||
|
||||
@@ -71,7 +71,7 @@ int rpm_ack_decode_service_request(
|
||||
BACNET_APPLICATION_DATA_VALUE *value;
|
||||
BACNET_APPLICATION_DATA_VALUE *old_value;
|
||||
|
||||
assert( read_access_data != NULL );
|
||||
assert(read_access_data != NULL);
|
||||
rpm_object = read_access_data;
|
||||
old_rpm_object = rpm_object;
|
||||
while (rpm_object && apdu_len) {
|
||||
@@ -211,7 +211,7 @@ static void PrintReadPropertyMultipleData(
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stdout, "%s #%lu\r\n",
|
||||
bactext_object_type_name(rpm_data->object_type),
|
||||
(unsigned long)rpm_data->object_instance);
|
||||
(unsigned long) rpm_data->object_instance);
|
||||
fprintf(stdout, "{\r\n");
|
||||
#endif
|
||||
listOfProperties = rpm_data->listOfProperties;
|
||||
@@ -219,11 +219,11 @@ 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: ",
|
||||
(unsigned)listOfProperties->propertyIdentifier);
|
||||
(unsigned) listOfProperties->propertyIdentifier);
|
||||
}
|
||||
#endif
|
||||
if (listOfProperties->propertyArrayIndex != BACNET_ARRAY_ALL) {
|
||||
@@ -261,10 +261,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;
|
||||
|
||||
@@ -49,38 +49,38 @@ int Encode_RR_payload(
|
||||
BACNET_READ_RANGE_DATA * pRequest)
|
||||
{
|
||||
int apdu_len = -1;
|
||||
rr_info_function info_fn_ptr = NULL;
|
||||
rr_info_function info_fn_ptr = NULL;
|
||||
RR_PROP_INFO PropInfo;
|
||||
|
||||
/* initialize the default return values */
|
||||
pRequest->error_class = ERROR_CLASS_SERVICES;
|
||||
pRequest->error_code = ERROR_CODE_OTHER;
|
||||
|
||||
pRequest->error_code = ERROR_CODE_OTHER;
|
||||
|
||||
/* handle each object type */
|
||||
info_fn_ptr = Device_Objects_RR_Info(pRequest->object_type);
|
||||
|
||||
|
||||
if ((info_fn_ptr != NULL) && (info_fn_ptr(pRequest, &PropInfo) != false)) {
|
||||
/* We try and do some of the more generic error checking here to cut down on duplication of effort */
|
||||
|
||||
if((pRequest->RequestType == RR_BY_POSITION) && (pRequest->Range.RefIndex == 0)) {/* First index is 1 so can't accept 0 */
|
||||
pRequest->error_code = ERROR_CODE_OTHER; /* I couldn't see anything more appropriate so... */
|
||||
} else if(((PropInfo.RequestTypes & RR_ARRAY_OF_LISTS) == 0) && (pRequest->array_index != 0) && (pRequest->array_index != BACNET_ARRAY_ALL)) {
|
||||
|
||||
if ((pRequest->RequestType == RR_BY_POSITION) && (pRequest->Range.RefIndex == 0)) { /* First index is 1 so can't accept 0 */
|
||||
pRequest->error_code = ERROR_CODE_OTHER; /* I couldn't see anything more appropriate so... */
|
||||
} else if (((PropInfo.RequestTypes & RR_ARRAY_OF_LISTS) == 0) &&
|
||||
(pRequest->array_index != 0) &&
|
||||
(pRequest->array_index != BACNET_ARRAY_ALL)) {
|
||||
/* Array access attempted on a non array property */
|
||||
pRequest->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
|
||||
}
|
||||
else if((pRequest->RequestType != RR_READ_ALL) && ((PropInfo.RequestTypes & pRequest->RequestType) == 0)) {
|
||||
pRequest->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
|
||||
} else if ((pRequest->RequestType != RR_READ_ALL) &&
|
||||
((PropInfo.RequestTypes & pRequest->RequestType) == 0)) {
|
||||
/* By Time or By Sequence not supported - By Position is always required */
|
||||
pRequest->error_code = ERROR_CODE_OTHER; /* I couldn't see anything more appropriate so... */
|
||||
}
|
||||
else if((pRequest->Count == 0) && (pRequest->RequestType != RR_READ_ALL)) { /* Count cannot be zero */
|
||||
pRequest->error_code = ERROR_CODE_OTHER; /* I couldn't see anything more appropriate so... */
|
||||
}
|
||||
else if(PropInfo.Handler != NULL) {
|
||||
pRequest->error_code = ERROR_CODE_OTHER; /* I couldn't see anything more appropriate so... */
|
||||
} else if ((pRequest->Count == 0) && (pRequest->RequestType != RR_READ_ALL)) { /* Count cannot be zero */
|
||||
pRequest->error_code = ERROR_CODE_OTHER; /* I couldn't see anything more appropriate so... */
|
||||
} else if (PropInfo.Handler != NULL) {
|
||||
apdu_len = PropInfo.Handler(apdu, pRequest);
|
||||
}
|
||||
} else {
|
||||
/* Either we don't support RR for this property yet or it is not a list or array of lists */
|
||||
pRequest->error_code = ERROR_CODE_PROPERTY_IS_NOT_A_LIST;
|
||||
pRequest->error_code = ERROR_CODE_PROPERTY_IS_NOT_A_LIST;
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
@@ -119,7 +119,7 @@ void handler_read_range(
|
||||
#endif
|
||||
goto RR_ABORT;
|
||||
}
|
||||
memset(&data, 0, sizeof(data)); /* start with blank canvas */
|
||||
memset(&data, 0, sizeof(data)); /* start with blank canvas */
|
||||
len = rr_decode_service_request(service_request, service_len, &data);
|
||||
#if PRINT_ENABLED
|
||||
if (len <= 0)
|
||||
|
||||
@@ -103,7 +103,8 @@ void handler_ucov_notification(
|
||||
fprintf(stderr, "UCOV: ");
|
||||
if (pProperty_value->propertyIdentifier < 512) {
|
||||
fprintf(stderr, "%s ",
|
||||
bactext_property_name(pProperty_value->propertyIdentifier));
|
||||
bactext_property_name(pProperty_value->
|
||||
propertyIdentifier));
|
||||
} else {
|
||||
fprintf(stderr, "proprietary %u ",
|
||||
pProperty_value->propertyIdentifier);
|
||||
|
||||
@@ -97,8 +97,10 @@ void handler_write_property(
|
||||
if (len > 0)
|
||||
fprintf(stderr,
|
||||
"WP: type=%lu instance=%lu property=%lu priority=%lu index=%ld\n",
|
||||
(unsigned long)wp_data.object_type, (unsigned long)wp_data.object_instance,
|
||||
(unsigned long)wp_data.object_property, (unsigned long)wp_data.priority, (long)wp_data.array_index);
|
||||
(unsigned long) wp_data.object_type,
|
||||
(unsigned long) wp_data.object_instance,
|
||||
(unsigned long) wp_data.object_property,
|
||||
(unsigned long) wp_data.priority, (long) wp_data.array_index);
|
||||
else
|
||||
fprintf(stderr, "WP: Unable to decode Request!\n");
|
||||
#endif
|
||||
@@ -149,13 +151,13 @@ void handler_write_property(
|
||||
*/
|
||||
|
||||
bool WPValidateString(
|
||||
BACNET_APPLICATION_DATA_VALUE *pValue,
|
||||
BACNET_APPLICATION_DATA_VALUE * pValue,
|
||||
int iMaxLen,
|
||||
bool bEmptyAllowed,
|
||||
BACNET_ERROR_CLASS * pErrorClass,
|
||||
BACNET_ERROR_CODE * pErrorCode)
|
||||
{
|
||||
bool bResult;
|
||||
bool bResult;
|
||||
|
||||
/* Save on a bit of code duplication by pre selecting the most
|
||||
* common outcomes from the tests (not necessarily the most likely
|
||||
@@ -164,21 +166,25 @@ bool WPValidateString(
|
||||
bResult = false;
|
||||
*pErrorClass = ERROR_CLASS_PROPERTY;
|
||||
|
||||
if(pValue->tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) {
|
||||
if(characterstring_encoding(&pValue->type.Character_String) == CHARACTER_ANSI_X34) {
|
||||
if((bEmptyAllowed == false) && (characterstring_length(&pValue->type.Character_String) == 0)) {
|
||||
if (pValue->tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) {
|
||||
if (characterstring_encoding(&pValue->type.Character_String) ==
|
||||
CHARACTER_ANSI_X34) {
|
||||
if ((bEmptyAllowed == false) &&
|
||||
(characterstring_length(&pValue->type.Character_String) ==
|
||||
0)) {
|
||||
*pErrorCode = ERROR_CODE_VALUE_OUT_OF_RANGE;
|
||||
} else if(characterstring_length(&pValue->type.Character_String) >= iMaxLen) {
|
||||
} else if (characterstring_length(&pValue->type.
|
||||
Character_String) >= iMaxLen) {
|
||||
*pErrorClass = ERROR_CLASS_RESOURCES;
|
||||
*pErrorCode = ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY;
|
||||
} else
|
||||
bResult = true; /* It's all good! */
|
||||
bResult = true; /* It's all good! */
|
||||
} else
|
||||
*pErrorCode = ERROR_CODE_CHARACTER_SET_NOT_SUPPORTED;
|
||||
} else
|
||||
*pErrorCode = ERROR_CODE_INVALID_DATA_TYPE;
|
||||
|
||||
return(bResult);
|
||||
return (bResult);
|
||||
}
|
||||
|
||||
/** Perform simple validation of type of Write Property argument based
|
||||
@@ -187,23 +193,23 @@ bool WPValidateString(
|
||||
*/
|
||||
|
||||
bool WPValidateArgType(
|
||||
BACNET_APPLICATION_DATA_VALUE *pValue,
|
||||
BACNET_APPLICATION_DATA_VALUE * pValue,
|
||||
uint8_t ucExpectedTag,
|
||||
BACNET_ERROR_CLASS * pErrorClass,
|
||||
BACNET_ERROR_CODE * pErrorCode)
|
||||
{
|
||||
bool bResult;
|
||||
bool bResult;
|
||||
|
||||
/*
|
||||
* start out assuming success and only set up error
|
||||
* response if validation fails.
|
||||
*/
|
||||
bResult = true;
|
||||
if(pValue->tag != ucExpectedTag) {
|
||||
if (pValue->tag != ucExpectedTag) {
|
||||
bResult = false;
|
||||
*pErrorClass = ERROR_CLASS_PROPERTY;
|
||||
*pErrorCode = ERROR_CODE_INVALID_DATA_TYPE;
|
||||
}
|
||||
|
||||
return(bResult);
|
||||
return (bResult);
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ OBJECT_DEVICE_T *objects_device_new(
|
||||
} else {
|
||||
fprintf(stderr,
|
||||
"Objects: Unable to allocate device %lu buffer\n",
|
||||
(unsigned long)device_instance);
|
||||
(unsigned long) device_instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,7 +112,7 @@ OBJECT_DEVICE_T *objects_device_delete(
|
||||
pDevice = Keylist_Data_Delete_By_Index(Device_List, index);
|
||||
if (pDevice) {
|
||||
fprintf(stderr, "Objects: removing device %lu",
|
||||
(unsigned long)pDevice->Object_Identifier.instance);
|
||||
(unsigned long) pDevice->Object_Identifier.instance);
|
||||
if (pDevice->Object_List) {
|
||||
do {
|
||||
pObject =
|
||||
|
||||
@@ -124,10 +124,9 @@ uint8_t Send_COV_Subscribe(
|
||||
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
|
||||
&npdu_data);
|
||||
/* encode the APDU portion of the packet */
|
||||
len = cov_subscribe_encode_adpu(
|
||||
&Handler_Transmit_Buffer[pdu_len],
|
||||
invoke_id,
|
||||
cov_data);
|
||||
len =
|
||||
cov_subscribe_encode_adpu(&Handler_Transmit_Buffer[pdu_len],
|
||||
invoke_id, cov_data);
|
||||
pdu_len += len;
|
||||
/* will it fit in the sender?
|
||||
note: if there is a bottleneck router in between
|
||||
@@ -158,4 +157,3 @@ uint8_t Send_COV_Subscribe(
|
||||
|
||||
return invoke_id;
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ int iam_encode_pdu(
|
||||
int len = 0;
|
||||
int pdu_len = 0;
|
||||
|
||||
datalink_get_broadcast_address(dest);
|
||||
datalink_get_broadcast_address(dest);
|
||||
/* encode the NPDU portion of the packet */
|
||||
npdu_encode_npdu_data(npdu_data, false, MESSAGE_PRIORITY_NORMAL);
|
||||
pdu_len = npdu_encode_pdu(&buffer[0], dest, NULL, npdu_data);
|
||||
@@ -75,7 +75,7 @@ int iam_encode_pdu(
|
||||
* @param buffer [in] The buffer to use for building and sending the message.
|
||||
*/
|
||||
void Send_I_Am(
|
||||
uint8_t * buffer )
|
||||
uint8_t * buffer)
|
||||
{
|
||||
int pdu_len = 0;
|
||||
BACNET_ADDRESS dest;
|
||||
@@ -126,15 +126,13 @@ int iam_unicast_encode_pdu(
|
||||
BACNET_ADDRESS my_address;
|
||||
|
||||
/* The destination will be the same as the src, so copy it over. */
|
||||
memcpy( dest, src, sizeof( BACNET_ADDRESS ) );
|
||||
memcpy(dest, src, sizeof(BACNET_ADDRESS));
|
||||
dest->net = 0;
|
||||
|
||||
datalink_get_my_address(&my_address);
|
||||
/* encode the NPDU portion of the packet */
|
||||
npdu_encode_npdu_data(npdu_data, false, MESSAGE_PRIORITY_NORMAL);
|
||||
npdu_len =
|
||||
npdu_encode_pdu(&buffer[0], dest, &my_address,
|
||||
npdu_data);
|
||||
npdu_len = npdu_encode_pdu(&buffer[0], dest, &my_address, npdu_data);
|
||||
/* encode the APDU portion of the packet */
|
||||
apdu_len =
|
||||
iam_encode_apdu(&buffer[npdu_len], Device_Object_Instance_Number(),
|
||||
@@ -157,7 +155,7 @@ int iam_unicast_encode_pdu(
|
||||
*/
|
||||
void Send_I_Am_Unicast(
|
||||
uint8_t * buffer,
|
||||
BACNET_ADDRESS * src )
|
||||
BACNET_ADDRESS * src)
|
||||
{
|
||||
int pdu_len = 0;
|
||||
BACNET_ADDRESS dest;
|
||||
@@ -186,4 +184,3 @@ void Send_I_Am_Unicast(
|
||||
fprintf(stderr, "Failed to Send I-Am Reply (%s)!\n", strerror(errno));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -155,9 +155,8 @@ 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) {
|
||||
|
||||
Reference in New Issue
Block a user