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
+114 -145
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>
@@ -57,36 +57,27 @@ static BACNET_FILE_LISTING BACnet_File_Listing[] = {
{0, "temp_0.txt"},
{1, "temp_1.txt"},
{2, "temp_2.txt"},
{0, NULL} /* last file indication */
{0, NULL} /* last file indication */
};
/* These three arrays are used by the ReadPropertyMultiple handler */
static const int bacfile_Properties_Required[] = {
PROP_OBJECT_IDENTIFIER,
PROP_OBJECT_NAME,
PROP_OBJECT_TYPE,
PROP_FILE_TYPE,
PROP_FILE_SIZE,
PROP_MODIFICATION_DATE,
PROP_ARCHIVE,
PROP_READ_ONLY,
PROP_FILE_ACCESS_METHOD,
-1
};
static const int bacfile_Properties_Required[] = {PROP_OBJECT_IDENTIFIER,
PROP_OBJECT_NAME,
PROP_OBJECT_TYPE,
PROP_FILE_TYPE,
PROP_FILE_SIZE,
PROP_MODIFICATION_DATE,
PROP_ARCHIVE,
PROP_READ_ONLY,
PROP_FILE_ACCESS_METHOD,
-1};
static const int bacfile_Properties_Optional[] = {
PROP_DESCRIPTION,
-1
};
static const int bacfile_Properties_Optional[] = {PROP_DESCRIPTION, -1};
static const int bacfile_Properties_Proprietary[] = {
-1
};
static const int bacfile_Properties_Proprietary[] = {-1};
void BACfile_Property_Lists(
const int **pRequired,
const int **pOptional,
const int **pProprietary)
void BACfile_Property_Lists(const int **pRequired, const int **pOptional,
const int **pProprietary)
{
if (pRequired)
*pRequired = bacfile_Properties_Required;
@@ -98,8 +89,7 @@ void BACfile_Property_Lists(
return;
}
static char *bacfile_name(
uint32_t instance)
static char *bacfile_name(uint32_t instance)
{
uint32_t index = 0;
char *filename = NULL;
@@ -116,9 +106,8 @@ static char *bacfile_name(
return filename;
}
bool bacfile_object_name(
uint32_t instance,
BACNET_CHARACTER_STRING * object_name)
bool bacfile_object_name(uint32_t instance,
BACNET_CHARACTER_STRING *object_name)
{
bool status = false;
char *filename = NULL;
@@ -131,14 +120,12 @@ bool bacfile_object_name(
return status;
}
bool bacfile_valid_instance(
uint32_t object_instance)
bool bacfile_valid_instance(uint32_t object_instance)
{
return bacfile_name(object_instance) ? true : false;
}
uint32_t bacfile_count(
void)
uint32_t bacfile_count(void)
{
uint32_t index = 0;
@@ -150,8 +137,7 @@ uint32_t bacfile_count(
return index;
}
uint32_t bacfile_index_to_instance(
unsigned find_index)
uint32_t bacfile_index_to_instance(unsigned find_index)
{
uint32_t instance = BACNET_MAX_INSTANCE + 1;
uint32_t index = 0;
@@ -168,8 +154,7 @@ uint32_t bacfile_index_to_instance(
return instance;
}
static long fsize(
FILE * pFile)
static long fsize(FILE *pFile)
{
long size = 0;
long origin = 0;
@@ -183,8 +168,7 @@ static long fsize(
return (size);
}
unsigned bacfile_file_size(
uint32_t object_instance)
unsigned bacfile_file_size(uint32_t object_instance)
{
char *pFilename = NULL;
FILE *pFile = NULL;
@@ -203,11 +187,10 @@ unsigned bacfile_file_size(
}
/* return the number of bytes used, or -1 on error */
int bacfile_read_property(
BACNET_READ_PROPERTY_DATA * rpdata)
int bacfile_read_property(BACNET_READ_PROPERTY_DATA *rpdata)
{
int apdu_len = 0; /* return value */
char text_string[32] = { "" };
int apdu_len = 0; /* return value */
char text_string[32] = {""};
BACNET_CHARACTER_STRING char_string;
BACNET_DATE bdate;
BACNET_TIME btime;
@@ -220,13 +203,12 @@ int bacfile_read_property(
apdu = rpdata->application_data;
switch (rpdata->object_property) {
case PROP_OBJECT_IDENTIFIER:
apdu_len =
encode_application_object_id(&apdu[0], OBJECT_FILE,
rpdata->object_instance);
apdu_len = encode_application_object_id(&apdu[0], OBJECT_FILE,
rpdata->object_instance);
break;
case PROP_OBJECT_NAME:
sprintf(text_string, "FILE %lu",
(unsigned long) rpdata->object_instance);
(unsigned long)rpdata->object_instance);
characterstring_init_ansi(&char_string, text_string);
apdu_len =
encode_application_character_string(&apdu[0], &char_string);
@@ -236,7 +218,7 @@ int bacfile_read_property(
break;
case PROP_DESCRIPTION:
characterstring_init_ansi(&char_string,
bacfile_name(rpdata->object_instance));
bacfile_name(rpdata->object_instance));
apdu_len =
encode_application_character_string(&apdu[0], &char_string);
break;
@@ -246,16 +228,15 @@ int bacfile_read_property(
encode_application_character_string(&apdu[0], &char_string);
break;
case PROP_FILE_SIZE:
apdu_len =
encode_application_unsigned(&apdu[0],
bacfile_file_size(rpdata->object_instance));
apdu_len = encode_application_unsigned(
&apdu[0], bacfile_file_size(rpdata->object_instance));
break;
case PROP_MODIFICATION_DATE:
/* FIXME: get the actual value instead of April Fool's Day */
bdate.year = 2006; /* AD */
bdate.month = 4; /* 1=Jan */
bdate.day = 1; /* 1..31 */
bdate.wday = 6; /* 1=Monday */
bdate.year = 2006; /* AD */
bdate.month = 4; /* 1=Jan */
bdate.day = 1; /* 1..31 */
bdate.wday = 6; /* 1=Monday */
apdu_len = encode_application_date(&apdu[0], &bdate);
/* FIXME: get the actual value */
btime.hour = 7;
@@ -280,9 +261,8 @@ int bacfile_read_property(
apdu_len = encode_application_boolean(&apdu[0], true);
break;
case PROP_FILE_ACCESS_METHOD:
apdu_len =
encode_application_enumerated(&apdu[0],
FILE_RECORD_AND_STREAM_ACCESS);
apdu_len = encode_application_enumerated(
&apdu[0], FILE_RECORD_AND_STREAM_ACCESS);
break;
default:
rpdata->error_class = ERROR_CLASS_PROPERTY;
@@ -295,10 +275,9 @@ int bacfile_read_property(
}
/* returns true if successful */
bool bacfile_write_property(
BACNET_WRITE_PROPERTY_DATA * wp_data)
bool bacfile_write_property(BACNET_WRITE_PROPERTY_DATA *wp_data)
{
bool status = false; /* return value */
bool status = false; /* return value */
int len = 0;
BACNET_APPLICATION_DATA_VALUE value;
@@ -314,9 +293,8 @@ bool bacfile_write_property(
return false;
}
/* decode the some of the request */
len =
bacapp_decode_application_data(wp_data->application_data,
wp_data->application_data_len, &value);
len = bacapp_decode_application_data(wp_data->application_data,
wp_data->application_data_len, &value);
if (len < 0) {
/* error while decoding - a value larger than we can handle */
wp_data->error_class = ERROR_CLASS_PROPERTY;
@@ -334,7 +312,7 @@ bool bacfile_write_property(
Access Services since the last time the object was archived. */
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN,
&wp_data->error_class, &wp_data->error_code);
&wp_data->error_class, &wp_data->error_code);
if (status) {
if (value.type.Boolean) {
/* FIXME: do something to wp_data->object_instance */
@@ -349,7 +327,7 @@ bool bacfile_write_property(
shall be writable. */
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT,
&wp_data->error_class, &wp_data->error_code);
&wp_data->error_class, &wp_data->error_code);
if (status) {
/* FIXME: do something with value.type.Unsigned
to wp_data->object_instance */
@@ -375,8 +353,7 @@ bool bacfile_write_property(
return status;
}
uint32_t bacfile_instance(
char *filename)
uint32_t bacfile_instance(char *filename)
{
uint32_t index = 0;
uint32_t instance = BACNET_MAX_INSTANCE + 1;
@@ -399,36 +376,33 @@ uint32_t bacfile_instance(
/* Another way would be to store the */
/* invokeID and file instance in a list or table */
/* when the request was sent */
uint32_t bacfile_instance_from_tsm(
uint8_t invokeID)
uint32_t bacfile_instance_from_tsm(uint8_t invokeID)
{
BACNET_NPDU_DATA npdu_data = { 0 }; /* dummy for getting npdu length */
BACNET_CONFIRMED_SERVICE_DATA service_data = { 0 };
BACNET_NPDU_DATA npdu_data = {0}; /* dummy for getting npdu length */
BACNET_CONFIRMED_SERVICE_DATA service_data = {0};
uint8_t service_choice = 0;
uint8_t *service_request = NULL;
uint16_t service_request_len = 0;
BACNET_ADDRESS dest; /* where the original packet was destined */
uint8_t apdu[MAX_PDU] = { 0 }; /* original APDU packet */
uint16_t apdu_len = 0; /* original APDU packet length */
int len = 0; /* apdu header length */
BACNET_ATOMIC_READ_FILE_DATA data = { 0 };
BACNET_ADDRESS dest; /* where the original packet was destined */
uint8_t apdu[MAX_PDU] = {0}; /* original APDU packet */
uint16_t apdu_len = 0; /* original APDU packet length */
int len = 0; /* apdu header length */
BACNET_ATOMIC_READ_FILE_DATA data = {0};
uint32_t object_instance = BACNET_MAX_INSTANCE + 1; /* return value */
bool found = false;
found =
tsm_get_transaction_pdu(invokeID, &dest, &npdu_data, &apdu[0],
&apdu_len);
found = tsm_get_transaction_pdu(invokeID, &dest, &npdu_data, &apdu[0],
&apdu_len);
if (found) {
if (!npdu_data.network_layer_message && npdu_data.data_expecting_reply
&& (apdu[0] == PDU_TYPE_CONFIRMED_SERVICE_REQUEST)) {
len =
apdu_decode_confirmed_service_request(&apdu[0], apdu_len,
&service_data, &service_choice, &service_request,
&service_request_len);
if (!npdu_data.network_layer_message &&
npdu_data.data_expecting_reply &&
(apdu[0] == PDU_TYPE_CONFIRMED_SERVICE_REQUEST)) {
len = apdu_decode_confirmed_service_request(
&apdu[0], apdu_len, &service_data, &service_choice,
&service_request, &service_request_len);
if (service_choice == SERVICE_CONFIRMED_ATOMIC_READ_FILE) {
len =
arf_decode_service_request(service_request,
service_request_len, &data);
len = arf_decode_service_request(service_request,
service_request_len, &data);
if (len > 0) {
if (data.object_type == OBJECT_FILE)
object_instance = data.object_instance;
@@ -441,8 +415,7 @@ uint32_t bacfile_instance_from_tsm(
}
#endif
bool bacfile_read_stream_data(
BACNET_ATOMIC_READ_FILE_DATA * data)
bool bacfile_read_stream_data(BACNET_ATOMIC_READ_FILE_DATA *data)
{
char *pFilename = NULL;
bool found = false;
@@ -454,10 +427,9 @@ bool bacfile_read_stream_data(
found = true;
pFile = fopen(pFilename, "rb");
if (pFile) {
(void) fseek(pFile, data->type.stream.fileStartPosition, SEEK_SET);
len =
fread(octetstring_value(&data->fileData[0]), 1,
data->type.stream.requestedOctetCount, pFile);
(void)fseek(pFile, data->type.stream.fileStartPosition, SEEK_SET);
len = fread(octetstring_value(&data->fileData[0]), 1,
data->type.stream.requestedOctetCount, pFile);
if (len < data->type.stream.requestedOctetCount)
data->endOfFile = true;
else
@@ -476,8 +448,7 @@ bool bacfile_read_stream_data(
return found;
}
bool bacfile_write_stream_data(
BACNET_ATOMIC_WRITE_FILE_DATA * data)
bool bacfile_write_stream_data(BACNET_ATOMIC_WRITE_FILE_DATA *data)
{
char *pFilename = NULL;
bool found = false;
@@ -500,11 +471,11 @@ bool bacfile_write_stream_data(
}
if (pFile) {
if (data->type.stream.fileStartPosition != -1) {
(void) fseek(pFile, data->type.stream.fileStartPosition,
SEEK_SET);
(void)fseek(pFile, data->type.stream.fileStartPosition,
SEEK_SET);
}
if (fwrite(octetstring_value(&data->fileData[0]),
octetstring_length(&data->fileData[0]), 1, pFile) != 1) {
octetstring_length(&data->fileData[0]), 1, pFile) != 1) {
/* do something if it fails? */
}
fclose(pFile);
@@ -514,8 +485,7 @@ bool bacfile_write_stream_data(
return found;
}
bool bacfile_write_record_data(
BACNET_ATOMIC_WRITE_FILE_DATA * data)
bool bacfile_write_record_data(BACNET_ATOMIC_WRITE_FILE_DATA *data)
{
char *pFilename = NULL;
bool found = false;
@@ -542,7 +512,8 @@ bool bacfile_write_record_data(
if (pFile) {
if ((data->type.record.fileStartRecord != -1) &&
(data->type.record.fileStartRecord > 0)) {
for (i = 0; i < (uint32_t)data->type.record.fileStartRecord; i++) {
for (i = 0; i < (uint32_t)data->type.record.fileStartRecord;
i++) {
pData = fgets(&dummy_data[0], sizeof(dummy_data), pFile);
if ((pData == NULL) || feof(pFile)) {
break;
@@ -551,8 +522,8 @@ bool bacfile_write_record_data(
}
for (i = 0; i < data->type.record.returnedRecordCount; i++) {
if (fwrite(octetstring_value(&data->fileData[i]),
octetstring_length(&data->fileData[i]), 1,
pFile) != 1) {
octetstring_length(&data->fileData[i]), 1,
pFile) != 1) {
/* do something if it fails? */
}
}
@@ -563,9 +534,8 @@ bool bacfile_write_record_data(
return found;
}
bool bacfile_read_ack_stream_data(
uint32_t instance,
BACNET_ATOMIC_READ_FILE_DATA * data)
bool bacfile_read_ack_stream_data(uint32_t instance,
BACNET_ATOMIC_READ_FILE_DATA *data)
{
bool found = false;
FILE *pFile = NULL;
@@ -576,12 +546,12 @@ bool bacfile_read_ack_stream_data(
found = true;
pFile = fopen(pFilename, "rb");
if (pFile) {
(void) fseek(pFile, data->type.stream.fileStartPosition, SEEK_SET);
(void)fseek(pFile, data->type.stream.fileStartPosition, SEEK_SET);
if (fwrite(octetstring_value(&data->fileData[0]),
octetstring_length(&data->fileData[0]), 1, pFile) != 1) {
octetstring_length(&data->fileData[0]), 1, pFile) != 1) {
#if PRINT_ENABLED
fprintf(stderr, "Failed to write to %s (%lu)!\n", pFilename,
(unsigned long) instance);
(unsigned long)instance);
#endif
}
fclose(pFile);
@@ -591,15 +561,14 @@ bool bacfile_read_ack_stream_data(
return found;
}
bool bacfile_read_ack_record_data(
uint32_t instance,
BACNET_ATOMIC_READ_FILE_DATA * data)
bool bacfile_read_ack_record_data(uint32_t instance,
BACNET_ATOMIC_READ_FILE_DATA *data)
{
bool found = false;
FILE *pFile = NULL;
char *pFilename = NULL;
uint32_t i = 0;
char dummy_data[MAX_OCTET_STRING_BYTES] = { 0 };
char dummy_data[MAX_OCTET_STRING_BYTES] = {0};
char *pData = NULL;
pFilename = bacfile_name(instance);
@@ -608,7 +577,8 @@ bool bacfile_read_ack_record_data(
pFile = fopen(pFilename, "rb");
if (pFile) {
if (data->type.record.fileStartRecord > 0) {
for (i = 0; i < (uint32_t)data->type.record.fileStartRecord; i++) {
for (i = 0; i < (uint32_t)data->type.record.fileStartRecord;
i++) {
pData = fgets(&dummy_data[0], sizeof(dummy_data), pFile);
if ((pData == NULL) || feof(pFile)) {
break;
@@ -617,11 +587,11 @@ bool bacfile_read_ack_record_data(
}
for (i = 0; i < data->type.record.RecordCount; i++) {
if (fwrite(octetstring_value(&data->fileData[i]),
octetstring_length(&data->fileData[i]), 1,
pFile) != 1) {
octetstring_length(&data->fileData[i]), 1,
pFile) != 1) {
#if PRINT_ENABLED
fprintf(stderr, "Failed to write to %s (%lu)!\n",
pFilename, (unsigned long) instance);
fprintf(stderr, "Failed to write to %s (%lu)!\n", pFilename,
(unsigned long)instance);
#endif
}
}
@@ -632,7 +602,6 @@ bool bacfile_read_ack_record_data(
return found;
}
void bacfile_init(
void)
void bacfile_init(void)
{
}