added clang format C and H files.

This commit is contained in:
Steve Karg
2019-10-24 16:23:10 -05:00
parent da91a11454
commit 710173d6e0
205 changed files with 19377 additions and 25754 deletions
+81 -103
View File
@@ -1,27 +1,27 @@
/**************************************************************************
*
* 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.
*
*********************************************************************/
*
* 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 <stdio.h>
@@ -50,12 +50,11 @@
DATABLOCK MyData[MYMAXBLOCK];
uint8_t IOBufferPT[MAX_APDU]; /* Buffer for building response in */
uint8_t IOBufferPT[MAX_APDU]; /* Buffer for building response in */
static void ProcessPT(
BACNET_PRIVATE_TRANSFER_DATA * data)
static void ProcessPT(BACNET_PRIVATE_TRANSFER_DATA *data)
{
int iLen; /* Index to current location in data */
int iLen; /* Index to current location in data */
char cBlockNumber;
uint32_t ulTemp;
int tag_len;
@@ -66,9 +65,8 @@ static void ProcessPT(
iLen = 0;
/* 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 */
@@ -77,10 +75,9 @@ static void ProcessPT(
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;
if (cBlockNumber < MY_MAX_BLOCK) {
if (data->serviceNumber == MY_SVC_READ) {
/* Read Response is an unsigned int with
@@ -101,20 +98,16 @@ static void ProcessPT(
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);
iLen += encode_application_real(
&IOBufferPT[iLen], MyData[(int8_t)cBlockNumber].fMyReal);
characterstring_init_ansi(
&bsTemp, (char *)MyData[(int8_t)cBlockNumber].sMyString);
iLen +=
encode_application_unsigned(&IOBufferPT[iLen],
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);
iLen +=
encode_application_character_string(&IOBufferPT[iLen],
&bsTemp);
encode_application_character_string(&IOBufferPT[iLen], &bsTemp);
} else {
/* Write operation */
/* Write block consists of the block number
@@ -124,59 +117,52 @@ static void ProcessPT(
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[(int8_t) cBlockNumber].cMyByte1 = (char) ulTemp;
iLen += decode_unsigned(&data->serviceParameters[iLen],
len_value_type, &ulTemp);
MyData[(int8_t)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[(int8_t) cBlockNumber].cMyByte2 = (char) ulTemp;
iLen += decode_unsigned(&data->serviceParameters[iLen],
len_value_type, &ulTemp);
MyData[(int8_t)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[(int8_t) cBlockNumber].fMyReal);
iLen += decode_real(&data->serviceParameters[iLen],
&MyData[(int8_t)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);
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);
}
@@ -198,12 +184,9 @@ static void ProcessPT(
*
*/
void handler_conf_private_trans(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_DATA * service_data)
void handler_conf_private_trans(uint8_t *service_request, uint16_t service_len,
BACNET_ADDRESS *src,
BACNET_CONFIRMED_SERVICE_DATA *service_data)
{
BACNET_PRIVATE_TRANSFER_DATA data;
int len;
@@ -230,28 +213,25 @@ void handler_conf_private_trans(
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);
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");
#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);
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");
#endif
@@ -278,10 +258,9 @@ void handler_conf_private_trans(
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;
@@ -292,15 +271,14 @@ void handler_conf_private_trans(
}
if (error) {
len =
ptransfer_error_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, error_class, error_code, &data);
len = ptransfer_error_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, error_class,
error_code, &data);
}
CPT_ABORT:
CPT_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) {