Indented project.

This commit is contained in:
skarg
2011-08-17 02:27:11 +00:00
parent 7e503510c7
commit 3e1cb1847f
125 changed files with 3548 additions and 3353 deletions
+12 -11
View File
@@ -72,18 +72,18 @@ void adc_enable(
* Notes: none
**************************************************/
uint8_t adc_result_8bit(
uint8_t channel) /* 0..7 = ADC0..ADC7, respectively */
{
uint8_t value = 0; /* return value */
uint8_t channel)
{ /* 0..7 = ADC0..ADC7, respectively */
uint8_t value = 0; /* return value */
while ( ADCSRA & (1 << ADSC) ) ;
while (ADCSRA & (1 << ADSC));
ADMUX = channel | (1 << ADLAR) | (0 << REFS1) | (1 << REFS0);
/* Delay needed for the stabilization of the ADC input voltage */
_delay_us(10);
/* Start the analog to digital conversion */
ADCSRA = (1 << ADEN) | (1 << ADSC) | (1 << ADIF) | ADPS_8BIT;
/* Wait for the analog to digital conversion to complete */
while ( (ADCSRA & (1 << ADIF)) == 0 ) ;
while ((ADCSRA & (1 << ADIF)) == 0);
value = ADCH;
return value;
@@ -95,18 +95,18 @@ uint8_t adc_result_8bit(
* Notes: none
**************************************************/
uint16_t adc_result_10bit(
uint8_t channel) /* 0..7 = ADC0..ADC7, respectively */
{
uint8_t channel)
{ /* 0..7 = ADC0..ADC7, respectively */
uint16_t value = 0; /* return value */
while ( ADCSRA & (1 << ADSC) ) ;
while (ADCSRA & (1 << ADSC));
ADMUX = channel | (0 << ADLAR) | (0 << REFS1) | (1 << REFS0);
/* Delay needed for the stabilization of the ADC input voltage */
_delay_us(10);
/* Start the analog to digital conversion */
ADCSRA = (1 << ADEN) | (1 << ADSC) | (1 << ADIF) | ADPS_10BIT;
/* Wait for the analog to digital conversion to complete */
while ( (ADCSRA & (1 << ADIF)) == 0 ) ;
while ((ADCSRA & (1 << ADIF)) == 0);
value = ADCL;
value |= (ADCH << 8);
@@ -118,11 +118,12 @@ uint16_t adc_result_10bit(
* Returns: none
* Notes: none
**************************************************/
void adc_init(void)
void adc_init(
void)
{
/* configure ADC for Free Running Mode - ADTS = 000 */
/* AIN1 is applied to the negative input of the Analog Comparator - ACME */
BITMASK_CLEAR(ADCSRB, _BV(ACME)|_BV(ADTS2)|_BV(ADTS1)|_BV(ADTS0));
BITMASK_CLEAR(ADCSRB, _BV(ACME) | _BV(ADTS2) | _BV(ADTS1) | _BV(ADTS0));
/* Digital input not needed on ADC0, so disable it to save power */
BIT_SET(DIDR0, ADC0D);
/* Clear the Power Reduction bit to enable ADC */
+1 -1
View File
@@ -111,7 +111,7 @@ uint32_t Analog_Input_Index_To_Instance(
bool Analog_Input_Object_Name(
uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name)
BACNET_CHARACTER_STRING * object_name)
{
static char text_string[32]; /* okay for single thread */
bool status = false;
+1 -1
View File
@@ -177,7 +177,7 @@ bool Analog_Value_Present_Value_Set(
/* note: the object name must be unique within this device */
bool Analog_Value_Object_Name(
uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name)
BACNET_CHARACTER_STRING * object_name)
{
static char text_string[32] = ""; /* okay for single thread */
unsigned index = 0;
+1 -1
View File
@@ -159,7 +159,7 @@ bool Binary_Input_Present_Value_Set(
bool Binary_Input_Object_Name(
uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name)
BACNET_CHARACTER_STRING * object_name)
{
static char text_string[32]; /* okay for single thread */
bool status = false;
+62 -53
View File
@@ -39,26 +39,36 @@
by Jeff Bezanson
placed in the public domain Fall 2005 */
static const char trailingBytesForUTF8[256] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,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from the PCRE library by Philip Hazel
length is in bytes, since without knowing whether the string is valid
it's hard to know how many characters there are! */
static int utf8_isvalid(const char *str, int length)
static int utf8_isvalid(
const char *str,
int length)
{
const unsigned char *p, *pend = (unsigned char*)str + length;
const unsigned char *p, *pend = (unsigned char *) str + length;
unsigned char c;
int ab;
for (p = (unsigned char*)str; p < pend; p++) {
for (p = (unsigned char *) str; p < pend; p++) {
c = *p;
/* null in middle of string */
if (c == 0) {
@@ -84,37 +94,42 @@ static int utf8_isvalid(const char *str, int length)
}
/* Check for overlong sequences for each different length */
switch (ab) {
/* Check for xx00 000x */
case 1:
if ((c & 0x3e) == 0) return 0;
continue; /* We know there aren't any more bytes to check */
/* Check for xx00 000x */
case 1:
if ((c & 0x3e) == 0)
return 0;
continue; /* We know there aren't any more bytes to check */
/* Check for 1110 0000, xx0x xxxx */
case 2:
if (c == 0xe0 && (*p & 0x20) == 0) return 0;
break;
/* Check for 1110 0000, xx0x xxxx */
case 2:
if (c == 0xe0 && (*p & 0x20) == 0)
return 0;
break;
/* Check for 1111 0000, xx00 xxxx */
case 3:
if (c == 0xf0 && (*p & 0x30) == 0) return 0;
break;
/* Check for 1111 0000, xx00 xxxx */
case 3:
if (c == 0xf0 && (*p & 0x30) == 0)
return 0;
break;
/* Check for 1111 1000, xx00 0xxx */
case 4:
if (c == 0xf8 && (*p & 0x38) == 0) return 0;
break;
/* Check for 1111 1000, xx00 0xxx */
case 4:
if (c == 0xf8 && (*p & 0x38) == 0)
return 0;
break;
/* Check for leading 0xfe or 0xff,
and then for 1111 1100, xx00 00xx */
case 5:
if (c == 0xfe || c == 0xff ||
(c == 0xfc && (*p & 0x3c) == 0)) return 0;
break;
/* Check for leading 0xfe or 0xff,
and then for 1111 1100, xx00 00xx */
case 5:
if (c == 0xfe || c == 0xff || (c == 0xfc && (*p & 0x3c) == 0))
return 0;
break;
}
/* Check for valid bytes after the 2nd, if any; all must start 10 */
while (--ab > 0) {
if ((*(++p) & 0xc0) != 0x80) return 0;
if ((*(++p) & 0xc0) != 0x80)
return 0;
}
}
@@ -144,7 +159,7 @@ static bool bacnet_name_isvalid(
bool bacnet_name_set(
uint16_t offset,
BACNET_CHARACTER_STRING *char_string)
BACNET_CHARACTER_STRING * char_string)
{
uint8_t encoding = 0;
uint8_t length = 0;
@@ -154,15 +169,9 @@ bool bacnet_name_set(
encoding = characterstring_encoding(char_string);
str = characterstring_value(char_string);
if (bacnet_name_isvalid(encoding, length, str)) {
seeprom_bytes_write(
NV_EEPROM_NAME_LENGTH(offset),
&length, 1);
seeprom_bytes_write(
NV_EEPROM_NAME_ENCODING(offset),
&encoding, 1);
seeprom_bytes_write(
NV_EEPROM_NAME_STRING(offset),
(uint8_t *)str,
seeprom_bytes_write(NV_EEPROM_NAME_LENGTH(offset), &length, 1);
seeprom_bytes_write(NV_EEPROM_NAME_ENCODING(offset), &encoding, 1);
seeprom_bytes_write(NV_EEPROM_NAME_STRING(offset), (uint8_t *) str,
length);
return true;
}
@@ -172,9 +181,9 @@ bool bacnet_name_set(
bool bacnet_name_write(
uint16_t offset,
BACNET_CHARACTER_STRING *char_string,
BACNET_ERROR_CLASS *error_class,
BACNET_ERROR_CODE *error_code)
BACNET_CHARACTER_STRING * char_string,
BACNET_ERROR_CLASS * error_class,
BACNET_ERROR_CODE * error_code)
{
bool status = false;
size_t length = 0;
@@ -215,9 +224,9 @@ bool bacnet_name_write(
/* no required minumum length or duplicate checking */
bool bacnet_name_write_other(
uint16_t offset,
BACNET_CHARACTER_STRING *char_string,
BACNET_ERROR_CLASS *error_class,
BACNET_ERROR_CODE *error_code)
BACNET_CHARACTER_STRING * char_string,
BACNET_ERROR_CLASS * error_class,
BACNET_ERROR_CODE * error_code)
{
bool status = false;
size_t length = 0;
@@ -247,16 +256,16 @@ bool bacnet_name_write_other(
void bacnet_name_init(
uint16_t offset,
BACNET_CHARACTER_STRING *char_string,
BACNET_CHARACTER_STRING * char_string,
char *default_string)
{
characterstring_init_ansi(char_string, default_string);
(void)bacnet_name_set(offset, char_string);
(void) bacnet_name_set(offset, char_string);
}
void bacnet_name(
uint16_t offset,
BACNET_CHARACTER_STRING *char_string,
BACNET_CHARACTER_STRING * char_string,
char *default_string)
{
uint8_t encoding = 0;
+9 -9
View File
@@ -33,26 +33,26 @@ extern "C" {
bool bacnet_name_set(
uint16_t eeprom_offset,
BACNET_CHARACTER_STRING *char_string);
BACNET_CHARACTER_STRING * char_string);
void bacnet_name_init(
uint16_t eeprom_offset,
BACNET_CHARACTER_STRING *char_string,
BACNET_CHARACTER_STRING * char_string,
char *default_string);
void bacnet_name(
uint16_t eeprom_offset,
BACNET_CHARACTER_STRING *char_string,
BACNET_CHARACTER_STRING * char_string,
char *default_string);
bool bacnet_name_write(
uint16_t offset,
BACNET_CHARACTER_STRING *char_string,
BACNET_ERROR_CLASS *error_class,
BACNET_ERROR_CODE *error_code);
BACNET_CHARACTER_STRING * char_string,
BACNET_ERROR_CLASS * error_class,
BACNET_ERROR_CODE * error_code);
/* no required minumum length or duplicate checking */
bool bacnet_name_write_other(
uint16_t offset,
BACNET_CHARACTER_STRING *char_string,
BACNET_ERROR_CLASS *error_class,
BACNET_ERROR_CODE *error_code);
BACNET_CHARACTER_STRING * char_string,
BACNET_ERROR_CLASS * error_class,
BACNET_ERROR_CODE * error_code);
#ifdef __cplusplus
}
+3 -3
View File
@@ -231,7 +231,7 @@ bool Binary_Output_Out_Of_Service(
/* note: the object name must be unique within this device */
bool Binary_Output_Object_Name(
uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name)
BACNET_CHARACTER_STRING * object_name)
{
static char text_string[32]; /* okay for single thread */
bool status = false;
@@ -439,8 +439,8 @@ bool Binary_Output_Write_Property(
priority = wp_data->priority;
if (priority && (priority <= BACNET_MAX_PRIORITY)) {
priority--;
Binary_Output_Present_Value_Set(wp_data->
object_instance, level, priority);
Binary_Output_Present_Value_Set
(wp_data->object_instance, level, priority);
} else if (priority == 6) {
status = false;
/* Command priority 6 is reserved for use by Minimum On/Off
+26 -35
View File
@@ -195,12 +195,12 @@ static int Read_Property_Common(
} else {
characterstring_init_ansi(&char_string, "");
if (pObject->Object_Name) {
(void)pObject->Object_Name(
rpdata->object_instance,
(void) pObject->Object_Name(rpdata->object_instance,
&char_string);
}
apdu_len =
encode_application_character_string(&apdu[0], &char_string);
encode_application_character_string(&apdu[0],
&char_string);
}
break;
case PROP_OBJECT_TYPE:
@@ -361,7 +361,8 @@ uint32_t Device_Index_To_Instance(
return Object_Instance_Number;
}
static char *Device_Name_Default(void)
static char *Device_Name_Default(
void)
{
static char text_string[32]; /* okay for single thread */
@@ -372,15 +373,12 @@ static char *Device_Name_Default(void)
bool Device_Object_Name(
uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name)
BACNET_CHARACTER_STRING * object_name)
{
bool status = false;
if (object_instance == Object_Instance_Number) {
bacnet_name(
NV_EEPROM_DEVICE_NAME,
object_name,
Device_Name_Default());
bacnet_name(NV_EEPROM_DEVICE_NAME, object_name, Device_Name_Default());
status = true;
}
@@ -416,13 +414,13 @@ BACNET_REINITIALIZED_STATE Device_Reinitialized_State(
}
void Device_Init(
object_functions_t * object_table)
object_functions_t * object_table)
{
struct my_object_functions *pObject = NULL;
/* we don't use the object table passed in
since there is extra stuff we don't need in there. */
(void)object_table;
(void) object_table;
/* our local object table */
pObject = &Object_Table[0];
while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) {
@@ -574,7 +572,7 @@ bool Device_Object_List_Identifier(
}
bool Device_Valid_Object_Name(
BACNET_CHARACTER_STRING *object_name1,
BACNET_CHARACTER_STRING * object_name1,
int *object_type,
uint32_t * object_instance)
{
@@ -593,7 +591,7 @@ bool Device_Valid_Object_Name(
pObject = Device_Objects_Find_Functions(type);
if ((pObject != NULL) && (pObject->Object_Name != NULL) &&
(pObject->Object_Name(instance, &object_name2) &&
characterstring_same(object_name1, &object_name2))) {
characterstring_same(object_name1, &object_name2))) {
found = true;
if (object_type) {
*object_type = type;
@@ -613,7 +611,7 @@ bool Device_Valid_Object_Id(
int object_type,
uint32_t object_instance)
{
bool status = false; /* return value */
bool status = false; /* return value */
struct my_object_functions *pObject = NULL;
pObject = Device_Objects_Find_Functions(object_type);
@@ -627,7 +625,7 @@ bool Device_Valid_Object_Id(
bool Device_Object_Name_Copy(
int object_type,
uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name)
BACNET_CHARACTER_STRING * object_name)
{
struct my_object_functions *pObject = NULL;
bool found = false;
@@ -673,17 +671,13 @@ int Device_Read_Property_Local(
apdu = rpdata->application_data;
switch (rpdata->object_property) {
case PROP_DESCRIPTION:
bacnet_name(
NV_EEPROM_DEVICE_DESCRIPTION,
&char_string,
bacnet_name(NV_EEPROM_DEVICE_DESCRIPTION, &char_string,
"BACnet Development Kit");
apdu_len =
encode_application_character_string(&apdu[0], &char_string);
break;
case PROP_LOCATION:
bacnet_name(
NV_EEPROM_DEVICE_LOCATION,
&char_string,
bacnet_name(NV_EEPROM_DEVICE_LOCATION, &char_string,
"default location");
apdu_len =
encode_application_character_string(&apdu[0], &char_string);
@@ -881,8 +875,8 @@ bool Device_Write_Property_Local(
case PROP_OBJECT_IDENTIFIER:
if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) {
if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
(Device_Set_Object_Instance_Number(value.type.Object_Id.
instance))) {
(Device_Set_Object_Instance_Number(value.type.
Object_Id.instance))) {
/* we could send an I-Am broadcast to let the world know */
status = true;
} else {
@@ -925,10 +919,9 @@ bool Device_Write_Property_Local(
break;
case PROP_OBJECT_NAME:
if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) {
status = bacnet_name_write(
NV_EEPROM_DEVICE_NAME,
&value.type.Character_String,
&wp_data->error_class,
status =
bacnet_name_write(NV_EEPROM_DEVICE_NAME,
&value.type.Character_String, &wp_data->error_class,
&wp_data->error_code);
} else {
wp_data->error_class = ERROR_CLASS_PROPERTY;
@@ -937,10 +930,9 @@ bool Device_Write_Property_Local(
break;
case PROP_DESCRIPTION:
if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) {
status = bacnet_name_write_other(
NV_EEPROM_DEVICE_DESCRIPTION,
&value.type.Character_String,
&wp_data->error_class,
status =
bacnet_name_write_other(NV_EEPROM_DEVICE_DESCRIPTION,
&value.type.Character_String, &wp_data->error_class,
&wp_data->error_code);
} else {
wp_data->error_class = ERROR_CLASS_PROPERTY;
@@ -949,10 +941,9 @@ bool Device_Write_Property_Local(
break;
case PROP_LOCATION:
if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) {
status = bacnet_name_write_other(
NV_EEPROM_DEVICE_LOCATION,
&value.type.Character_String,
&wp_data->error_class,
status =
bacnet_name_write_other(NV_EEPROM_DEVICE_LOCATION,
&value.type.Character_String, &wp_data->error_class,
&wp_data->error_code);
} else {
wp_data->error_class = ERROR_CLASS_PROPERTY;