added clang format C and H files.
This commit is contained in:
+91
-128
@@ -1,27 +1,27 @@
|
||||
/**************************************************************************
|
||||
*
|
||||
* Copyright (C) 2012 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) 2012 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.
|
||||
*
|
||||
*********************************************************************/
|
||||
|
||||
/* CharacterString Value Objects */
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#include "bacdcode.h"
|
||||
#include "bacenum.h"
|
||||
#include "bacapp.h"
|
||||
#include "config.h" /* the custom stuff */
|
||||
#include "config.h" /* the custom stuff */
|
||||
#include "rp.h"
|
||||
#include "wp.h"
|
||||
#include "csv.h"
|
||||
@@ -52,29 +52,17 @@ static char Object_Description[MAX_CHARACTERSTRING_VALUES][64];
|
||||
|
||||
/* These three arrays are used by the ReadPropertyMultiple handler */
|
||||
static const int Properties_Required[] = {
|
||||
PROP_OBJECT_IDENTIFIER,
|
||||
PROP_OBJECT_NAME,
|
||||
PROP_OBJECT_TYPE,
|
||||
PROP_PRESENT_VALUE,
|
||||
PROP_STATUS_FLAGS,
|
||||
-1
|
||||
};
|
||||
PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, PROP_OBJECT_TYPE,
|
||||
PROP_PRESENT_VALUE, PROP_STATUS_FLAGS, -1};
|
||||
|
||||
static const int Properties_Optional[] = {
|
||||
PROP_EVENT_STATE,
|
||||
PROP_OUT_OF_SERVICE,
|
||||
PROP_DESCRIPTION,
|
||||
-1
|
||||
};
|
||||
static const int Properties_Optional[] = {PROP_EVENT_STATE, PROP_OUT_OF_SERVICE,
|
||||
PROP_DESCRIPTION, -1};
|
||||
|
||||
static const int Properties_Proprietary[] = {
|
||||
-1
|
||||
};
|
||||
static const int Properties_Proprietary[] = {-1};
|
||||
|
||||
void CharacterString_Value_Property_Lists(
|
||||
const int **pRequired,
|
||||
const int **pOptional,
|
||||
const int **pProprietary)
|
||||
void CharacterString_Value_Property_Lists(const int **pRequired,
|
||||
const int **pOptional,
|
||||
const int **pProprietary)
|
||||
{
|
||||
if (pRequired)
|
||||
*pRequired = Properties_Required;
|
||||
@@ -86,17 +74,16 @@ void CharacterString_Value_Property_Lists(
|
||||
return;
|
||||
}
|
||||
|
||||
void CharacterString_Value_Init(
|
||||
void)
|
||||
void CharacterString_Value_Init(void)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
/* initialize all Present Values */
|
||||
for (i = 0; i < MAX_CHARACTERSTRING_VALUES; i++) {
|
||||
snprintf(&Object_Name[i][0], sizeof(Object_Name[i]),
|
||||
"CHARACTER STRING VALUE %u", i+1);
|
||||
"CHARACTER STRING VALUE %u", i + 1);
|
||||
snprintf(&Object_Description[i][0], sizeof(Object_Description[i]),
|
||||
"A Character String Value Example");
|
||||
"A Character String Value Example");
|
||||
characterstring_init_ansi(&Present_Value[i], "");
|
||||
}
|
||||
|
||||
@@ -106,8 +93,7 @@ void CharacterString_Value_Init(
|
||||
/* we simply have 0-n object instances. Yours might be */
|
||||
/* more complex, and then you need to return the index */
|
||||
/* that correlates to the correct instance number */
|
||||
unsigned CharacterString_Value_Instance_To_Index(
|
||||
uint32_t object_instance)
|
||||
unsigned CharacterString_Value_Instance_To_Index(uint32_t object_instance)
|
||||
{
|
||||
unsigned index = MAX_CHARACTERSTRING_VALUES;
|
||||
|
||||
@@ -121,22 +107,19 @@ unsigned CharacterString_Value_Instance_To_Index(
|
||||
/* we simply have 0-n object instances. Yours might be */
|
||||
/* more complex, and then you need to return the instance */
|
||||
/* that correlates to the correct index */
|
||||
uint32_t CharacterString_Value_Index_To_Instance(
|
||||
unsigned index)
|
||||
uint32_t CharacterString_Value_Index_To_Instance(unsigned index)
|
||||
{
|
||||
return index;
|
||||
}
|
||||
|
||||
/* we simply have 0-n object instances. Yours might be */
|
||||
/* more complex, and then count how many you have */
|
||||
unsigned CharacterString_Value_Count(
|
||||
void)
|
||||
unsigned CharacterString_Value_Count(void)
|
||||
{
|
||||
return MAX_CHARACTERSTRING_VALUES;
|
||||
}
|
||||
|
||||
bool CharacterString_Value_Valid_Instance(
|
||||
uint32_t object_instance)
|
||||
bool CharacterString_Value_Valid_Instance(uint32_t object_instance)
|
||||
{
|
||||
unsigned index = 0; /* offset from instance lookup */
|
||||
|
||||
@@ -148,9 +131,8 @@ bool CharacterString_Value_Valid_Instance(
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CharacterString_Value_Present_Value(
|
||||
uint32_t object_instance,
|
||||
BACNET_CHARACTER_STRING * object_name)
|
||||
bool CharacterString_Value_Present_Value(uint32_t object_instance,
|
||||
BACNET_CHARACTER_STRING *object_name)
|
||||
{
|
||||
bool status = false;
|
||||
unsigned index = 0; /* offset from instance lookup */
|
||||
@@ -164,8 +146,7 @@ bool CharacterString_Value_Present_Value(
|
||||
}
|
||||
|
||||
bool CharacterString_Value_Present_Value_Set(
|
||||
uint32_t object_instance,
|
||||
BACNET_CHARACTER_STRING * object_name)
|
||||
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
|
||||
{
|
||||
bool status = false;
|
||||
unsigned index = 0; /* offset from instance lookup */
|
||||
@@ -178,8 +159,7 @@ bool CharacterString_Value_Present_Value_Set(
|
||||
return status;
|
||||
}
|
||||
|
||||
bool CharacterString_Value_Out_Of_Service(
|
||||
uint32_t object_instance)
|
||||
bool CharacterString_Value_Out_Of_Service(uint32_t object_instance)
|
||||
{
|
||||
bool value = false;
|
||||
unsigned index = 0;
|
||||
@@ -192,9 +172,8 @@ bool CharacterString_Value_Out_Of_Service(
|
||||
return value;
|
||||
}
|
||||
|
||||
static void CharacterString_Value_Out_Of_Service_Set(
|
||||
uint32_t object_instance,
|
||||
bool value)
|
||||
static void CharacterString_Value_Out_Of_Service_Set(uint32_t object_instance,
|
||||
bool value)
|
||||
{
|
||||
unsigned index = 0;
|
||||
|
||||
@@ -206,8 +185,7 @@ static void CharacterString_Value_Out_Of_Service_Set(
|
||||
return;
|
||||
}
|
||||
|
||||
static char *CharacterString_Value_Description(
|
||||
uint32_t object_instance)
|
||||
static char *CharacterString_Value_Description(uint32_t object_instance)
|
||||
{
|
||||
unsigned index = 0; /* offset from instance lookup */
|
||||
char *pName = NULL; /* return value */
|
||||
@@ -220,13 +198,12 @@ static char *CharacterString_Value_Description(
|
||||
return pName;
|
||||
}
|
||||
|
||||
bool CharacterString_Value_Description_Set(
|
||||
uint32_t object_instance,
|
||||
char *new_name)
|
||||
bool CharacterString_Value_Description_Set(uint32_t object_instance,
|
||||
char *new_name)
|
||||
{
|
||||
unsigned index = 0; /* offset from instance lookup */
|
||||
size_t i = 0; /* loop counter */
|
||||
bool status = false; /* return value */
|
||||
unsigned index = 0; /* offset from instance lookup */
|
||||
size_t i = 0; /* loop counter */
|
||||
bool status = false; /* return value */
|
||||
|
||||
index = CharacterString_Value_Instance_To_Index(object_instance);
|
||||
if (index < MAX_CHARACTERSTRING_VALUES) {
|
||||
@@ -248,9 +225,8 @@ bool CharacterString_Value_Description_Set(
|
||||
return status;
|
||||
}
|
||||
|
||||
bool CharacterString_Value_Object_Name(
|
||||
uint32_t object_instance,
|
||||
BACNET_CHARACTER_STRING * object_name)
|
||||
bool CharacterString_Value_Object_Name(uint32_t object_instance,
|
||||
BACNET_CHARACTER_STRING *object_name)
|
||||
{
|
||||
unsigned index = 0; /* offset from instance lookup */
|
||||
bool status = false;
|
||||
@@ -264,13 +240,11 @@ bool CharacterString_Value_Object_Name(
|
||||
}
|
||||
|
||||
/* note: the object name must be unique within this device */
|
||||
bool CharacterString_Value_Name_Set(
|
||||
uint32_t object_instance,
|
||||
char *new_name)
|
||||
bool CharacterString_Value_Name_Set(uint32_t object_instance, char *new_name)
|
||||
{
|
||||
unsigned index = 0; /* offset from instance lookup */
|
||||
size_t i = 0; /* loop counter */
|
||||
bool status = false; /* return value */
|
||||
unsigned index = 0; /* offset from instance lookup */
|
||||
size_t i = 0; /* loop counter */
|
||||
bool status = false; /* return value */
|
||||
|
||||
index = CharacterString_Value_Instance_To_Index(object_instance);
|
||||
if (index < MAX_CHARACTERSTRING_VALUES) {
|
||||
@@ -294,10 +268,9 @@ bool CharacterString_Value_Name_Set(
|
||||
}
|
||||
|
||||
/* return apdu len, or BACNET_STATUS_ERROR on error */
|
||||
int CharacterString_Value_Read_Property(
|
||||
BACNET_READ_PROPERTY_DATA * rpdata)
|
||||
int CharacterString_Value_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata)
|
||||
{
|
||||
int apdu_len = 0; /* return value */
|
||||
int apdu_len = 0; /* return value */
|
||||
BACNET_BIT_STRING bit_string;
|
||||
BACNET_CHARACTER_STRING char_string;
|
||||
unsigned object_index = 0;
|
||||
@@ -311,32 +284,32 @@ int CharacterString_Value_Read_Property(
|
||||
apdu = rpdata->application_data;
|
||||
switch (rpdata->object_property) {
|
||||
case PROP_OBJECT_IDENTIFIER:
|
||||
apdu_len =
|
||||
encode_application_object_id(&apdu[0],
|
||||
OBJECT_CHARACTERSTRING_VALUE, rpdata->object_instance);
|
||||
apdu_len = encode_application_object_id(
|
||||
&apdu[0], OBJECT_CHARACTERSTRING_VALUE,
|
||||
rpdata->object_instance);
|
||||
break;
|
||||
/* note: Name and Description don't have to be the same.
|
||||
You could make Description writable and different */
|
||||
case PROP_OBJECT_NAME:
|
||||
CharacterString_Value_Object_Name(rpdata->object_instance,
|
||||
&char_string);
|
||||
&char_string);
|
||||
apdu_len =
|
||||
encode_application_character_string(&apdu[0], &char_string);
|
||||
break;
|
||||
case PROP_DESCRIPTION:
|
||||
characterstring_init_ansi(&char_string,
|
||||
characterstring_init_ansi(
|
||||
&char_string,
|
||||
CharacterString_Value_Description(rpdata->object_instance));
|
||||
apdu_len =
|
||||
encode_application_character_string(&apdu[0], &char_string);
|
||||
break;
|
||||
case PROP_OBJECT_TYPE:
|
||||
apdu_len =
|
||||
encode_application_enumerated(&apdu[0],
|
||||
OBJECT_CHARACTERSTRING_VALUE);
|
||||
apdu_len = encode_application_enumerated(
|
||||
&apdu[0], OBJECT_CHARACTERSTRING_VALUE);
|
||||
break;
|
||||
case PROP_PRESENT_VALUE:
|
||||
CharacterString_Value_Present_Value(rpdata->object_instance,
|
||||
&char_string);
|
||||
&char_string);
|
||||
apdu_len =
|
||||
encode_application_character_string(&apdu[0], &char_string);
|
||||
break;
|
||||
@@ -348,10 +321,10 @@ int CharacterString_Value_Read_Property(
|
||||
bitstring_set_bit(&bit_string, STATUS_FLAG_OVERRIDDEN, false);
|
||||
if (CharacterString_Value_Out_Of_Service(rpdata->object_instance)) {
|
||||
bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE,
|
||||
true);
|
||||
true);
|
||||
} else {
|
||||
bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE,
|
||||
false);
|
||||
false);
|
||||
}
|
||||
apdu_len = encode_application_bitstring(&apdu[0], &bit_string);
|
||||
break;
|
||||
@@ -361,9 +334,8 @@ int CharacterString_Value_Read_Property(
|
||||
encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL);
|
||||
break;
|
||||
case PROP_OUT_OF_SERVICE:
|
||||
object_index =
|
||||
CharacterString_Value_Instance_To_Index
|
||||
(rpdata->object_instance);
|
||||
object_index = CharacterString_Value_Instance_To_Index(
|
||||
rpdata->object_instance);
|
||||
state = Out_Of_Service[object_index];
|
||||
apdu_len = encode_application_boolean(&apdu[0], state);
|
||||
break;
|
||||
@@ -385,17 +357,15 @@ int CharacterString_Value_Read_Property(
|
||||
}
|
||||
|
||||
/* returns true if successful */
|
||||
bool CharacterString_Value_Write_Property(
|
||||
BACNET_WRITE_PROPERTY_DATA * wp_data)
|
||||
bool CharacterString_Value_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;
|
||||
|
||||
/* 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);
|
||||
/* FIXME: len < application_data_len: more data? */
|
||||
if (len < 0) {
|
||||
/* error while decoding - a value larger than we can handle */
|
||||
@@ -405,14 +375,12 @@ bool CharacterString_Value_Write_Property(
|
||||
}
|
||||
switch (wp_data->object_property) {
|
||||
case PROP_PRESENT_VALUE:
|
||||
status =
|
||||
WPValidateArgType(&value,
|
||||
BACNET_APPLICATION_TAG_CHARACTER_STRING, &wp_data->error_class,
|
||||
&wp_data->error_code);
|
||||
status = WPValidateArgType(
|
||||
&value, BACNET_APPLICATION_TAG_CHARACTER_STRING,
|
||||
&wp_data->error_class, &wp_data->error_code);
|
||||
if (status) {
|
||||
status =
|
||||
CharacterString_Value_Present_Value_Set
|
||||
(wp_data->object_instance, &value.type.Character_String);
|
||||
status = CharacterString_Value_Present_Value_Set(
|
||||
wp_data->object_instance, &value.type.Character_String);
|
||||
if (!status) {
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
|
||||
@@ -422,10 +390,10 @@ bool CharacterString_Value_Write_Property(
|
||||
case PROP_OUT_OF_SERVICE:
|
||||
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) {
|
||||
CharacterString_Value_Out_Of_Service_Set
|
||||
(wp_data->object_instance, value.type.Boolean);
|
||||
CharacterString_Value_Out_Of_Service_Set(
|
||||
wp_data->object_instance, value.type.Boolean);
|
||||
}
|
||||
break;
|
||||
case PROP_OBJECT_IDENTIFIER:
|
||||
@@ -446,17 +414,14 @@ bool CharacterString_Value_Write_Property(
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
#ifdef TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
bool WPValidateArgType(
|
||||
BACNET_APPLICATION_DATA_VALUE * pValue,
|
||||
uint8_t ucExpectedTag,
|
||||
BACNET_ERROR_CLASS * pErrorClass,
|
||||
BACNET_ERROR_CODE * pErrorCode)
|
||||
bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue,
|
||||
uint8_t ucExpectedTag, BACNET_ERROR_CLASS *pErrorClass,
|
||||
BACNET_ERROR_CODE *pErrorCode)
|
||||
{
|
||||
pValue = pValue;
|
||||
ucExpectedTag = ucExpectedTag;
|
||||
@@ -466,10 +431,9 @@ bool WPValidateArgType(
|
||||
return false;
|
||||
}
|
||||
|
||||
void testCharacterStringValue(
|
||||
Test * pTest)
|
||||
void testCharacterStringValue(Test *pTest)
|
||||
{
|
||||
uint8_t apdu[MAX_APDU] = { 0 };
|
||||
uint8_t apdu[MAX_APDU] = {0};
|
||||
int len = 0;
|
||||
uint32_t len_value = 0;
|
||||
uint8_t tag_number = 0;
|
||||
@@ -496,8 +460,7 @@ void testCharacterStringValue(
|
||||
}
|
||||
|
||||
#ifdef TEST_CHARACTERSTRING_VALUE
|
||||
int main(
|
||||
void)
|
||||
int main(void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
@@ -509,7 +472,7 @@ int main(
|
||||
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void) ct_report(pTest);
|
||||
(void)ct_report(pTest);
|
||||
ct_destroy(pTest);
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user