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
+33 -55
View File
@@ -43,29 +43,23 @@
/** @file iam.c Encode/Decode I-Am service */
/* encode I-Am service */
int iam_encode_apdu(
uint8_t * apdu,
uint32_t device_id,
unsigned max_apdu,
int segmentation,
uint16_t vendor_id)
int iam_encode_apdu(uint8_t *apdu, uint32_t device_id, unsigned max_apdu,
int segmentation, uint16_t vendor_id)
{
int len = 0; /* length of each encoding */
int apdu_len = 0; /* total length of the apdu, return value */
int len = 0; /* length of each encoding */
int apdu_len = 0; /* total length of the apdu, return value */
if (apdu) {
apdu[0] = PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST;
apdu[1] = SERVICE_UNCONFIRMED_I_AM; /* service choice */
apdu[1] = SERVICE_UNCONFIRMED_I_AM; /* service choice */
apdu_len = 2;
len =
encode_application_object_id(&apdu[apdu_len], OBJECT_DEVICE,
device_id);
len = encode_application_object_id(&apdu[apdu_len], OBJECT_DEVICE,
device_id);
apdu_len += len;
len = encode_application_unsigned(&apdu[apdu_len], max_apdu);
apdu_len += len;
len =
encode_application_enumerated(&apdu[apdu_len],
(uint32_t) segmentation);
len = encode_application_enumerated(&apdu[apdu_len],
(uint32_t)segmentation);
apdu_len += len;
len = encode_application_unsigned(&apdu[apdu_len], vendor_id);
apdu_len += len;
@@ -74,24 +68,20 @@ int iam_encode_apdu(
return apdu_len;
}
int iam_decode_service_request(
uint8_t * apdu,
uint32_t * pDevice_id,
unsigned *pMax_apdu,
int *pSegmentation,
uint16_t * pVendor_id)
int iam_decode_service_request(uint8_t *apdu, uint32_t *pDevice_id,
unsigned *pMax_apdu, int *pSegmentation,
uint16_t *pVendor_id)
{
int len = 0;
int apdu_len = 0; /* total length of the apdu, return value */
uint16_t object_type = 0; /* should be a Device Object */
int apdu_len = 0; /* total length of the apdu, return value */
uint16_t object_type = 0; /* should be a Device Object */
uint32_t object_instance = 0;
uint8_t tag_number = 0;
uint32_t len_value = 0;
uint32_t decoded_value = 0;
/* OBJECT ID - object id */
len =
decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &len_value);
len = decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &len_value);
apdu_len += len;
if (tag_number != BACNET_APPLICATION_TAG_OBJECT_ID)
return -1;
@@ -102,18 +92,16 @@ int iam_decode_service_request(
if (pDevice_id)
*pDevice_id = object_instance;
/* MAX APDU - unsigned */
len =
decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &len_value);
len = decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &len_value);
apdu_len += len;
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT)
return -1;
len = decode_unsigned(&apdu[apdu_len], len_value, &decoded_value);
apdu_len += len;
if (pMax_apdu)
*pMax_apdu = (unsigned) decoded_value;
*pMax_apdu = (unsigned)decoded_value;
/* Segmentation - enumerated */
len =
decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &len_value);
len = decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &len_value);
apdu_len += len;
if (tag_number != BACNET_APPLICATION_TAG_ENUMERATED)
return -1;
@@ -122,10 +110,9 @@ int iam_decode_service_request(
if (decoded_value >= MAX_BACNET_SEGMENTATION)
return -1;
if (pSegmentation)
*pSegmentation = (int) decoded_value;
*pSegmentation = (int)decoded_value;
/* Vendor ID - unsigned16 */
len =
decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &len_value);
len = decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &len_value);
apdu_len += len;
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT)
return -1;
@@ -134,7 +121,7 @@ int iam_decode_service_request(
if (decoded_value > 0xFFFF)
return -1;
if (pVendor_id)
*pVendor_id = (uint16_t) decoded_value;
*pVendor_id = (uint16_t)decoded_value;
return apdu_len;
}
@@ -144,14 +131,10 @@ int iam_decode_service_request(
#include <string.h>
#include "ctest.h"
int iam_decode_apdu(
uint8_t * apdu,
uint32_t * pDevice_id,
unsigned *pMax_apdu,
int *pSegmentation,
uint16_t * pVendor_id)
int iam_decode_apdu(uint8_t *apdu, uint32_t *pDevice_id, unsigned *pMax_apdu,
int *pSegmentation, uint16_t *pVendor_id)
{
int apdu_len = 0; /* total length of the apdu, return value */
int apdu_len = 0; /* total length of the apdu, return value */
/* valid data? */
if (!apdu)
@@ -161,17 +144,15 @@ int iam_decode_apdu(
return -1;
if (apdu[1] != SERVICE_UNCONFIRMED_I_AM)
return -1;
apdu_len =
iam_decode_service_request(&apdu[2], pDevice_id, pMax_apdu,
pSegmentation, pVendor_id);
apdu_len = iam_decode_service_request(&apdu[2], pDevice_id, pMax_apdu,
pSegmentation, pVendor_id);
return apdu_len;
}
void testIAm(
Test * pTest)
void testIAm(Test *pTest)
{
uint8_t apdu[480] = { 0 };
uint8_t apdu[480] = {0};
int len = 0;
uint32_t device_id = 42;
unsigned max_apdu = 480;
@@ -183,13 +164,11 @@ void testIAm(
uint16_t test_vendor_id = 0;
len =
iam_encode_apdu(&apdu[0], device_id, max_apdu, segmentation,
vendor_id);
iam_encode_apdu(&apdu[0], device_id, max_apdu, segmentation, vendor_id);
ct_test(pTest, len != 0);
len =
iam_decode_apdu(&apdu[0], &test_device_id, &test_max_apdu,
&test_segmentation, &test_vendor_id);
len = iam_decode_apdu(&apdu[0], &test_device_id, &test_max_apdu,
&test_segmentation, &test_vendor_id);
ct_test(pTest, len != -1);
ct_test(pTest, test_device_id == device_id);
@@ -199,8 +178,7 @@ void testIAm(
}
#ifdef TEST_IAM
int main(
void)
int main(void)
{
Test *pTest;
bool rc;
@@ -212,7 +190,7 @@ int main(
ct_setStream(pTest, stdout);
ct_run(pTest);
(void) ct_report(pTest);
(void)ct_report(pTest);
ct_destroy(pTest);
return 0;