Indented project.
This commit is contained in:
@@ -109,7 +109,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[16] = "AI-0"; /* okay for single thread */
|
||||
bool status = false;
|
||||
|
||||
@@ -167,7 +167,7 @@ float Analog_Value_Present_Value(
|
||||
|
||||
bool Analog_Value_Object_Name(
|
||||
uint32_t object_instance,
|
||||
BACNET_CHARACTER_STRING *object_name)
|
||||
BACNET_CHARACTER_STRING * object_name)
|
||||
{
|
||||
static char text_string[16] = "AV-0"; /* okay for single thread */
|
||||
bool status = false;
|
||||
@@ -360,8 +360,8 @@ bool Analog_Value_Write_Property(
|
||||
(value.type.Real >= 0.0) && (value.type.Real <= 100.0)) {
|
||||
level = (uint8_t) value.type.Real;
|
||||
object_index =
|
||||
Analog_Value_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
Analog_Value_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
priority--;
|
||||
Present_Value[object_index] = level;
|
||||
/* Note: you could set the physical output here if we
|
||||
|
||||
@@ -146,7 +146,7 @@ BACNET_BINARY_PV Binary_Input_Present_Value(
|
||||
|
||||
bool Binary_Input_Object_Name(
|
||||
uint32_t object_instance,
|
||||
BACNET_CHARACTER_STRING *object_name)
|
||||
BACNET_CHARACTER_STRING * object_name)
|
||||
{
|
||||
static char text_string[16] = "BI-0"; /* okay for single thread */
|
||||
bool status = false;
|
||||
|
||||
@@ -141,7 +141,7 @@ static BACNET_BINARY_PV Binary_Value_Present_Value(
|
||||
/* note: the object name must be unique within this device */
|
||||
bool Binary_Value_Object_Name(
|
||||
uint32_t object_instance,
|
||||
BACNET_CHARACTER_STRING *object_name)
|
||||
BACNET_CHARACTER_STRING * object_name)
|
||||
{
|
||||
static char text_string[16] = "BV-0"; /* okay for single thread */
|
||||
bool status = false;
|
||||
@@ -271,8 +271,8 @@ bool Binary_Value_Write_Property(
|
||||
(value.type.Enumerated <= MAX_BINARY_PV)) {
|
||||
level = value.type.Enumerated;
|
||||
object_index =
|
||||
Binary_Value_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
Binary_Value_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
priority--;
|
||||
/* NOTE: this Binary value has no priority array */
|
||||
Present_Value[object_index] = level;
|
||||
|
||||
@@ -179,8 +179,7 @@ static int Read_Property_Common(
|
||||
break;
|
||||
case PROP_OBJECT_NAME:
|
||||
if (pObject->Object_Name) {
|
||||
(void)pObject->Object_Name(
|
||||
rpdata->object_instance,
|
||||
(void) pObject->Object_Name(rpdata->object_instance,
|
||||
&char_string);
|
||||
} else {
|
||||
characterstring_init_ansi(&char_string, "");
|
||||
@@ -213,13 +212,13 @@ int Device_Read_Property(
|
||||
/* initialize the default return values */
|
||||
pObject = Device_Objects_Find_Functions(rpdata->object_type);
|
||||
if (pObject) {
|
||||
if (pObject->Object_Valid_Instance &&
|
||||
pObject->Object_Valid_Instance(rpdata->object_instance)) {
|
||||
if (pObject->Object_Valid_Instance &&
|
||||
pObject->Object_Valid_Instance(rpdata->object_instance)) {
|
||||
apdu_len = Read_Property_Common(pObject, rpdata);
|
||||
} else {
|
||||
rpdata->error_class = ERROR_CLASS_OBJECT;
|
||||
rpdata->error_code = ERROR_CODE_UNKNOWN_OBJECT;
|
||||
}
|
||||
} else {
|
||||
rpdata->error_class = ERROR_CLASS_OBJECT;
|
||||
rpdata->error_code = ERROR_CODE_UNKNOWN_OBJECT;
|
||||
}
|
||||
} else {
|
||||
rpdata->error_class = ERROR_CLASS_OBJECT;
|
||||
rpdata->error_code = ERROR_CODE_UNSUPPORTED_OBJECT_TYPE;
|
||||
@@ -237,18 +236,18 @@ bool Device_Write_Property(
|
||||
/* initialize the default return values */
|
||||
pObject = Device_Objects_Find_Functions(wp_data->object_type);
|
||||
if (pObject) {
|
||||
if (pObject->Object_Valid_Instance &&
|
||||
pObject->Object_Valid_Instance(wp_data->object_instance)) {
|
||||
if (pObject->Object_Write_Property) {
|
||||
status = pObject->Object_Write_Property(wp_data);
|
||||
} else {
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
|
||||
}
|
||||
if (pObject->Object_Valid_Instance &&
|
||||
pObject->Object_Valid_Instance(wp_data->object_instance)) {
|
||||
if (pObject->Object_Write_Property) {
|
||||
status = pObject->Object_Write_Property(wp_data);
|
||||
} else {
|
||||
wp_data->error_class = ERROR_CLASS_OBJECT;
|
||||
wp_data->error_code = ERROR_CODE_UNKNOWN_OBJECT;
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
|
||||
}
|
||||
} else {
|
||||
wp_data->error_class = ERROR_CLASS_OBJECT;
|
||||
wp_data->error_code = ERROR_CODE_UNKNOWN_OBJECT;
|
||||
}
|
||||
} else {
|
||||
wp_data->error_class = ERROR_CLASS_OBJECT;
|
||||
wp_data->error_code = ERROR_CODE_UNSUPPORTED_OBJECT_TYPE;
|
||||
@@ -340,7 +339,7 @@ uint32_t Device_Index_To_Instance(
|
||||
|
||||
bool Device_Object_Name(
|
||||
uint32_t object_instance,
|
||||
BACNET_CHARACTER_STRING *object_name)
|
||||
BACNET_CHARACTER_STRING * object_name)
|
||||
{
|
||||
bool status = false;
|
||||
|
||||
@@ -352,7 +351,7 @@ bool Device_Object_Name(
|
||||
}
|
||||
|
||||
bool Device_Set_Object_Name(
|
||||
BACNET_CHARACTER_STRING *object_name)
|
||||
BACNET_CHARACTER_STRING * object_name)
|
||||
{
|
||||
bool status = false; /*return value */
|
||||
|
||||
@@ -394,13 +393,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) {
|
||||
@@ -440,7 +439,7 @@ bool Device_Valid_Object_Instance_Number(
|
||||
/* BACnet allows for a wildcard instance number */
|
||||
return ((Object_Instance_Number == object_id) ||
|
||||
(object_id == BACNET_MAX_INSTANCE));
|
||||
}
|
||||
}
|
||||
|
||||
BACNET_DEVICE_STATUS Device_System_Status(
|
||||
void)
|
||||
@@ -461,25 +460,25 @@ int Device_Set_System_Status(
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t Device_Vendor_Identifier(
|
||||
void)
|
||||
{
|
||||
return BACNET_VENDOR_ID;
|
||||
}
|
||||
}
|
||||
|
||||
BACNET_SEGMENTATION Device_Segmentation_Supported(
|
||||
void)
|
||||
{
|
||||
return SEGMENTATION_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t Device_Database_Revision(
|
||||
void)
|
||||
{
|
||||
return Database_Revision;
|
||||
}
|
||||
}
|
||||
|
||||
void Device_Inc_Database_Revision(
|
||||
void)
|
||||
@@ -542,7 +541,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)
|
||||
{
|
||||
@@ -561,7 +560,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;
|
||||
@@ -581,7 +580,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);
|
||||
@@ -595,7 +594,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;
|
||||
@@ -851,8 +850,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 {
|
||||
@@ -895,22 +894,20 @@ bool Device_Write_Property_Local(
|
||||
break;
|
||||
case PROP_OBJECT_NAME:
|
||||
if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) {
|
||||
length = characterstring_length(
|
||||
&value.type.Character_String);
|
||||
length = characterstring_length(&value.type.Character_String);
|
||||
if (length < characterstring_capacity(&My_Object_Name)) {
|
||||
encoding = characterstring_encoding(
|
||||
&value.type.Character_String);
|
||||
encoding =
|
||||
characterstring_encoding(&value.type.Character_String);
|
||||
if (encoding < MAX_CHARACTER_STRING_ENCODING) {
|
||||
/* All the object names in a device must be unique. */
|
||||
if (Device_Valid_Object_Name(
|
||||
&value.type.Character_String,
|
||||
NULL, NULL)) {
|
||||
if (Device_Valid_Object_Name(&value.type.
|
||||
Character_String, NULL, NULL)) {
|
||||
status = false;
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
wp_data->error_code = ERROR_CODE_DUPLICATE_NAME;
|
||||
} else {
|
||||
Device_Set_Object_Name(
|
||||
&value.type.Character_String);
|
||||
Device_Set_Object_Name(&value.type.
|
||||
Character_String);
|
||||
}
|
||||
} else {
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
|
||||
@@ -1177,9 +1177,9 @@ static void MSTP_Slave_Node_FSM(
|
||||
} else if (MSTP_Flag.ReceivePacketPending) {
|
||||
if (Ringbuf_Empty(&PDU_Queue)) {
|
||||
/* If no reply will be available from the higher layers
|
||||
within Treply_delay after the reception of the final octet
|
||||
of the requesting frame (the mechanism used to determine
|
||||
this is a local matter), then no reply is possible. */
|
||||
within Treply_delay after the reception of the final octet
|
||||
of the requesting frame (the mechanism used to determine
|
||||
this is a local matter), then no reply is possible. */
|
||||
MSTP_Flag.ReceivePacketPending = false;
|
||||
} else {
|
||||
pkt = (struct mstp_pdu_packet *) Ringbuf_Pop_Front(&PDU_Queue);
|
||||
|
||||
@@ -211,8 +211,8 @@ bool Binary_Value_Write_Property(
|
||||
if ((value.type.Enumerated == BINARY_ACTIVE) ||
|
||||
(value.type.Enumerated == BINARY_INACTIVE)) {
|
||||
object_index =
|
||||
Binary_Value_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
Binary_Value_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
/* NOTE: this Binary value has no priority array */
|
||||
Present_Value[object_index] =
|
||||
(BACNET_BINARY_PV) value.type.Enumerated;
|
||||
|
||||
@@ -380,8 +380,8 @@ bool Device_Write_Property(
|
||||
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 {
|
||||
|
||||
@@ -211,8 +211,8 @@ bool Binary_Value_Write_Property(
|
||||
if ((value.type.Enumerated == BINARY_ACTIVE) ||
|
||||
(value.type.Enumerated == BINARY_INACTIVE)) {
|
||||
object_index =
|
||||
Binary_Value_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
Binary_Value_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
/* NOTE: this Binary value has no priority array */
|
||||
Present_Value[object_index] =
|
||||
(BACNET_BINARY_PV) value.type.Enumerated;
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,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,
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
||||
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5
|
||||
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, 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,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4,
|
||||
4, 4, 4, 5, 5, 5, 5
|
||||
};
|
||||
|
||||
/* based on the valid_utf8 routine 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;
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -91,7 +91,8 @@ static uint8_t Tusage_timeout = 60;
|
||||
|
||||
static struct timeval start;
|
||||
|
||||
static uint32_t Timer_Silence(void)
|
||||
static uint32_t Timer_Silence(
|
||||
void)
|
||||
{
|
||||
struct timeval now, tmp_diff;
|
||||
int32_t res;
|
||||
@@ -105,14 +106,16 @@ static uint32_t Timer_Silence(void)
|
||||
return (res >= 0 ? res : -res);
|
||||
}
|
||||
|
||||
static void Timer_Silence_Reset(void)
|
||||
static void Timer_Silence_Reset(
|
||||
void)
|
||||
{
|
||||
pthread_mutex_lock(&Timer_Mutex);
|
||||
gettimeofday(&start, NULL);
|
||||
pthread_mutex_unlock(&Timer_Mutex);
|
||||
}
|
||||
|
||||
static void get_abstime(struct timespec *abstime,
|
||||
static void get_abstime(
|
||||
struct timespec *abstime,
|
||||
unsigned long milliseconds)
|
||||
{
|
||||
struct timeval now, offset, result;
|
||||
@@ -125,7 +128,8 @@ static void get_abstime(struct timespec *abstime,
|
||||
abstime->tv_nsec = result.tv_usec * 1000;
|
||||
}
|
||||
|
||||
void dlmstp_cleanup(void)
|
||||
void dlmstp_cleanup(
|
||||
void)
|
||||
{
|
||||
pthread_cond_destroy(&Received_Frame_Flag);
|
||||
pthread_cond_destroy(&Receive_Packet_Flag);
|
||||
@@ -137,12 +141,10 @@ void dlmstp_cleanup(void)
|
||||
}
|
||||
|
||||
/* returns number of bytes sent on success, zero on failure */
|
||||
int dlmstp_send_pdu(BACNET_ADDRESS * dest, /* destination address */
|
||||
|
||||
int dlmstp_send_pdu(
|
||||
BACNET_ADDRESS * dest, /* destination address */
|
||||
BACNET_NPDU_DATA * npdu_data, /* network information */
|
||||
|
||||
uint8_t * pdu, /* any data to be sent - may be null */
|
||||
|
||||
unsigned pdu_len)
|
||||
{ /* number of bytes of data */
|
||||
int bytes_sent = 0;
|
||||
@@ -168,12 +170,10 @@ int dlmstp_send_pdu(BACNET_ADDRESS * dest, /* destination address */
|
||||
return bytes_sent;
|
||||
}
|
||||
|
||||
uint16_t dlmstp_receive(BACNET_ADDRESS * src, /* source address */
|
||||
|
||||
uint16_t dlmstp_receive(
|
||||
BACNET_ADDRESS * src, /* source address */
|
||||
uint8_t * pdu, /* PDU data */
|
||||
|
||||
uint16_t max_pdu, /* amount of space available in the PDU */
|
||||
|
||||
unsigned timeout)
|
||||
{ /* milliseconds to wait for a packet */
|
||||
uint16_t pdu_len = 0;
|
||||
@@ -207,7 +207,8 @@ uint16_t dlmstp_receive(BACNET_ADDRESS * src, /* source address */
|
||||
return pdu_len;
|
||||
}
|
||||
|
||||
static void *dlmstp_master_fsm_task(void *pArg)
|
||||
static void *dlmstp_master_fsm_task(
|
||||
void *pArg)
|
||||
{
|
||||
uint32_t silence = 0;
|
||||
bool run_master = false;
|
||||
@@ -252,7 +253,8 @@ static void *dlmstp_master_fsm_task(void *pArg)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void dlmstp_fill_bacnet_address(BACNET_ADDRESS * src,
|
||||
void dlmstp_fill_bacnet_address(
|
||||
BACNET_ADDRESS * src,
|
||||
uint8_t mstp_address)
|
||||
{
|
||||
int i = 0;
|
||||
@@ -277,7 +279,8 @@ void dlmstp_fill_bacnet_address(BACNET_ADDRESS * src,
|
||||
}
|
||||
|
||||
/* for the MS/TP state machine to use for putting received data */
|
||||
uint16_t MSTP_Put_Receive(volatile struct mstp_port_struct_t *mstp_port)
|
||||
uint16_t MSTP_Put_Receive(
|
||||
volatile struct mstp_port_struct_t *mstp_port)
|
||||
{
|
||||
uint16_t pdu_len = 0;
|
||||
|
||||
@@ -300,7 +303,8 @@ uint16_t MSTP_Put_Receive(volatile struct mstp_port_struct_t *mstp_port)
|
||||
|
||||
/* for the MS/TP state machine to use for getting data to send */
|
||||
/* Return: amount of PDU data */
|
||||
uint16_t MSTP_Get_Send(volatile struct mstp_port_struct_t * mstp_port,
|
||||
uint16_t MSTP_Get_Send(
|
||||
volatile struct mstp_port_struct_t * mstp_port,
|
||||
unsigned timeout)
|
||||
{ /* milliseconds to wait for a packet */
|
||||
uint16_t pdu_len = 0;
|
||||
@@ -329,7 +333,8 @@ uint16_t MSTP_Get_Send(volatile struct mstp_port_struct_t * mstp_port,
|
||||
return pdu_len;
|
||||
}
|
||||
|
||||
static bool dlmstp_compare_data_expecting_reply(uint8_t * request_pdu,
|
||||
static bool dlmstp_compare_data_expecting_reply(
|
||||
uint8_t * request_pdu,
|
||||
uint16_t request_pdu_len,
|
||||
uint8_t src_address,
|
||||
uint8_t * reply_pdu,
|
||||
@@ -445,7 +450,8 @@ static bool dlmstp_compare_data_expecting_reply(uint8_t * request_pdu,
|
||||
}
|
||||
|
||||
/* Get the reply to a DATA_EXPECTING_REPLY frame, or nothing */
|
||||
uint16_t MSTP_Get_Reply(volatile struct mstp_port_struct_t * mstp_port,
|
||||
uint16_t MSTP_Get_Reply(
|
||||
volatile struct mstp_port_struct_t * mstp_port,
|
||||
unsigned timeout)
|
||||
{ /* milliseconds to wait for a packet */
|
||||
uint16_t pdu_len = 0; /* return value */
|
||||
@@ -484,7 +490,8 @@ uint16_t MSTP_Get_Reply(volatile struct mstp_port_struct_t * mstp_port,
|
||||
return pdu_len;
|
||||
}
|
||||
|
||||
void dlmstp_set_mac_address(uint8_t mac_address)
|
||||
void dlmstp_set_mac_address(
|
||||
uint8_t mac_address)
|
||||
{
|
||||
/* Master Nodes can only have address 0-127 */
|
||||
if (mac_address <= 127) {
|
||||
@@ -501,7 +508,8 @@ void dlmstp_set_mac_address(uint8_t mac_address)
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t dlmstp_mac_address(void)
|
||||
uint8_t dlmstp_mac_address(
|
||||
void)
|
||||
{
|
||||
return MSTP_Port.This_Station;
|
||||
}
|
||||
@@ -513,7 +521,8 @@ uint8_t dlmstp_mac_address(void)
|
||||
/* nodes. This may be used to allocate more or less of the available link */
|
||||
/* bandwidth to particular nodes. If Max_Info_Frames is not writable in a */
|
||||
/* node, its value shall be 1. */
|
||||
void dlmstp_set_max_info_frames(uint8_t max_info_frames)
|
||||
void dlmstp_set_max_info_frames(
|
||||
uint8_t max_info_frames)
|
||||
{
|
||||
if (max_info_frames >= 1) {
|
||||
MSTP_Port.Nmax_info_frames = max_info_frames;
|
||||
@@ -527,7 +536,8 @@ void dlmstp_set_max_info_frames(uint8_t max_info_frames)
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t dlmstp_max_info_frames(void)
|
||||
uint8_t dlmstp_max_info_frames(
|
||||
void)
|
||||
{
|
||||
return MSTP_Port.Nmax_info_frames;
|
||||
}
|
||||
@@ -537,7 +547,8 @@ uint8_t dlmstp_max_info_frames(void)
|
||||
/* allowable address for master nodes. The value of Max_Master shall be */
|
||||
/* less than or equal to 127. If Max_Master is not writable in a node, */
|
||||
/* its value shall be 127. */
|
||||
void dlmstp_set_max_master(uint8_t max_master)
|
||||
void dlmstp_set_max_master(
|
||||
uint8_t max_master)
|
||||
{
|
||||
if (max_master <= 127) {
|
||||
if (MSTP_Port.This_Station <= max_master) {
|
||||
@@ -553,23 +564,27 @@ void dlmstp_set_max_master(uint8_t max_master)
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t dlmstp_max_master(void)
|
||||
uint8_t dlmstp_max_master(
|
||||
void)
|
||||
{
|
||||
return MSTP_Port.Nmax_master;
|
||||
}
|
||||
|
||||
/* RS485 Baud Rate 9600, 19200, 38400, 57600, 115200 */
|
||||
void dlmstp_set_baud_rate(uint32_t baud)
|
||||
void dlmstp_set_baud_rate(
|
||||
uint32_t baud)
|
||||
{
|
||||
RS485_Set_Baud_Rate(baud);
|
||||
}
|
||||
|
||||
uint32_t dlmstp_baud_rate(void)
|
||||
uint32_t dlmstp_baud_rate(
|
||||
void)
|
||||
{
|
||||
return RS485_Get_Baud_Rate();
|
||||
}
|
||||
|
||||
void dlmstp_get_my_address(BACNET_ADDRESS * my_address)
|
||||
void dlmstp_get_my_address(
|
||||
BACNET_ADDRESS * my_address)
|
||||
{
|
||||
int i = 0; /* counter */
|
||||
|
||||
@@ -584,7 +599,8 @@ void dlmstp_get_my_address(BACNET_ADDRESS * my_address)
|
||||
return;
|
||||
}
|
||||
|
||||
void dlmstp_get_broadcast_address(BACNET_ADDRESS * dest)
|
||||
void dlmstp_get_broadcast_address(
|
||||
BACNET_ADDRESS * dest)
|
||||
{ /* destination address */
|
||||
int i = 0; /* counter */
|
||||
|
||||
@@ -601,7 +617,8 @@ void dlmstp_get_broadcast_address(BACNET_ADDRESS * dest)
|
||||
return;
|
||||
}
|
||||
|
||||
bool dlmstp_init(char *ifname)
|
||||
bool dlmstp_init(
|
||||
char *ifname)
|
||||
{
|
||||
unsigned long hThread = 0;
|
||||
int rv = 0;
|
||||
@@ -665,10 +682,9 @@ bool dlmstp_init(char *ifname)
|
||||
#ifdef TEST_DLMSTP
|
||||
#include <stdio.h>
|
||||
|
||||
void apdu_handler(BACNET_ADDRESS * src, /* source address */
|
||||
|
||||
void apdu_handler(
|
||||
BACNET_ADDRESS * src, /* source address */
|
||||
uint8_t * apdu, /* APDU data */
|
||||
|
||||
uint16_t pdu_len)
|
||||
{ /* for confirmed messages */
|
||||
(void) src;
|
||||
@@ -678,7 +694,8 @@ void apdu_handler(BACNET_ADDRESS * src, /* source address */
|
||||
|
||||
static char *Network_Interface = NULL;
|
||||
|
||||
int main(int argc,
|
||||
int main(
|
||||
int argc,
|
||||
char *argv[])
|
||||
{
|
||||
uint16_t pdu_len = 0;
|
||||
|
||||
@@ -95,7 +95,8 @@ static pthread_mutex_t Reader_Mutex, IOMutex;
|
||||
|
||||
#define _POSIX_SOURCE 1 /* POSIX compliant source */
|
||||
|
||||
static void *rs485_read_task(void *arg)
|
||||
static void *rs485_read_task(
|
||||
void *arg)
|
||||
{
|
||||
uint8_t buf[1 << 11];
|
||||
int count, n;
|
||||
@@ -134,7 +135,8 @@ static void *rs485_read_task(void *arg)
|
||||
* ALGORITHM: none
|
||||
* NOTES: none
|
||||
*********************************************************************/
|
||||
void RS485_Set_Interface(char *ifname)
|
||||
void RS485_Set_Interface(
|
||||
char *ifname)
|
||||
{
|
||||
/* note: expects a constant char, or char from the heap */
|
||||
if (ifname) {
|
||||
@@ -148,7 +150,8 @@ void RS485_Set_Interface(char *ifname)
|
||||
* ALGORITHM: none
|
||||
* NOTES: none
|
||||
*********************************************************************/
|
||||
const char *RS485_Interface(void)
|
||||
const char *RS485_Interface(
|
||||
void)
|
||||
{
|
||||
return RS485_Port_Name;
|
||||
}
|
||||
@@ -159,7 +162,8 @@ const char *RS485_Interface(void)
|
||||
* ALGORITHM: none
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
uint32_t RS485_Get_Baud_Rate(void)
|
||||
uint32_t RS485_Get_Baud_Rate(
|
||||
void)
|
||||
{
|
||||
switch (RS485_Baud) {
|
||||
case B19200:
|
||||
@@ -182,7 +186,8 @@ uint32_t RS485_Get_Baud_Rate(void)
|
||||
* ALGORITHM: none
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
bool RS485_Set_Baud_Rate(uint32_t baud)
|
||||
bool RS485_Set_Baud_Rate(
|
||||
uint32_t baud)
|
||||
{
|
||||
bool valid = true;
|
||||
|
||||
@@ -215,10 +220,9 @@ bool RS485_Set_Baud_Rate(uint32_t baud)
|
||||
}
|
||||
|
||||
/* Transmits a Frame on the wire */
|
||||
void RS485_Send_Frame(volatile struct mstp_port_struct_t *mstp_port, /* port specific data */
|
||||
|
||||
void RS485_Send_Frame(
|
||||
volatile struct mstp_port_struct_t *mstp_port, /* port specific data */
|
||||
uint8_t * buffer, /* frame to send (up to 501 bytes of data) */
|
||||
|
||||
uint16_t nbytes)
|
||||
{ /* number of bytes of data (up to 501) */
|
||||
ssize_t written = 0;
|
||||
@@ -246,7 +250,8 @@ void RS485_Send_Frame(volatile struct mstp_port_struct_t *mstp_port, /* port
|
||||
}
|
||||
|
||||
/* called by timer, interrupt(?) or other thread */
|
||||
void RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port)
|
||||
void RS485_Check_UART_Data(
|
||||
volatile struct mstp_port_struct_t *mstp_port)
|
||||
{
|
||||
if (mstp_port->ReceiveError == true) {
|
||||
/* wait for state machine to clear this */
|
||||
@@ -266,7 +271,8 @@ void RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port)
|
||||
}
|
||||
}
|
||||
|
||||
void RS485_Cleanup(void)
|
||||
void RS485_Cleanup(
|
||||
void)
|
||||
{
|
||||
/* restore the old port settings */
|
||||
tcsetattr(RS485_Handle, TCSANOW, &RS485_oldtio);
|
||||
@@ -276,7 +282,8 @@ void RS485_Cleanup(void)
|
||||
}
|
||||
|
||||
|
||||
void RS485_Initialize(void)
|
||||
void RS485_Initialize(
|
||||
void)
|
||||
{
|
||||
struct termios newtio;
|
||||
unsigned long hThread = 0;
|
||||
@@ -333,7 +340,8 @@ void RS485_Initialize(void)
|
||||
|
||||
#ifdef TEST_RS485
|
||||
#include <string.h>
|
||||
int main(int argc,
|
||||
int main(
|
||||
int argc,
|
||||
char *argv[])
|
||||
{
|
||||
uint8_t buf[8];
|
||||
|
||||
@@ -325,8 +325,8 @@ bool Analog_Value_Write_Property(
|
||||
(value.type.Real >= 0.0) && (value.type.Real <= 100.0)) {
|
||||
level = (uint8_t) value.type.Real;
|
||||
object_index =
|
||||
Analog_Value_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
Analog_Value_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
priority--;
|
||||
Present_Value[object_index] = level;
|
||||
/* Note: you could set the physical output here if we
|
||||
|
||||
@@ -237,8 +237,8 @@ bool Binary_Value_Write_Property(
|
||||
(value.type.Enumerated <= MAX_BINARY_PV)) {
|
||||
level = value.type.Enumerated;
|
||||
object_index =
|
||||
Binary_Value_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
Binary_Value_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
priority--;
|
||||
/* NOTE: this Binary value has no priority array */
|
||||
Present_Value[object_index] = level;
|
||||
|
||||
@@ -510,8 +510,8 @@ bool Device_Write_Property(
|
||||
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 {
|
||||
|
||||
@@ -261,7 +261,8 @@ bool bip_init(
|
||||
bip_set_port(htons((0xBAC0));
|
||||
/* assumes that the driver has already been initialized */
|
||||
sock_fd = socket(AF_INET, SOCK_DGRAM, IPROTO_UDP);
|
||||
bip_set_socket(sock_fd); if (sock_fd < 0)
|
||||
bip_set_socket(sock_fd);
|
||||
if (sock_fd < 0)
|
||||
return false;
|
||||
/* bind the socket to the local port number and IP address */
|
||||
sin.sin_family = AF_INET; sin.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
|
||||
@@ -429,8 +429,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
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
#include "apdu.h"
|
||||
#include "wp.h" /* WriteProperty handling */
|
||||
#include "rp.h" /* ReadProperty handling */
|
||||
#include "dcc.h" /* DeviceCommunicationControl handling */
|
||||
#include "dcc.h" /* DeviceCommunicationControl handling */
|
||||
#include "version.h"
|
||||
#include "device.h" /* me */
|
||||
#include "handlers.h"
|
||||
@@ -833,8 +833,8 @@ bool Device_Write_Property_Local(
|
||||
&wp_data->error_class, &wp_data->error_code);
|
||||
if (status) {
|
||||
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 {
|
||||
@@ -868,8 +868,8 @@ bool Device_Write_Property_Local(
|
||||
WPValidateString(&value, MAX_DEV_NAME_LEN, false,
|
||||
&wp_data->error_class, &wp_data->error_code);
|
||||
if (status) {
|
||||
Device_Set_Object_Name(characterstring_value(&value.type.
|
||||
Character_String),
|
||||
Device_Set_Object_Name(characterstring_value(&value.
|
||||
type.Character_String),
|
||||
characterstring_length(&value.type.Character_String));
|
||||
}
|
||||
break;
|
||||
@@ -878,8 +878,8 @@ bool Device_Write_Property_Local(
|
||||
WPValidateString(&value, MAX_DEV_LOC_LEN, true,
|
||||
&wp_data->error_class, &wp_data->error_code);
|
||||
if (status) {
|
||||
Device_Set_Location(characterstring_value(&value.type.
|
||||
Character_String),
|
||||
Device_Set_Location(characterstring_value(&value.
|
||||
type.Character_String),
|
||||
characterstring_length(&value.type.Character_String));
|
||||
}
|
||||
break;
|
||||
@@ -889,8 +889,8 @@ bool Device_Write_Property_Local(
|
||||
WPValidateString(&value, MAX_DEV_DESC_LEN, true,
|
||||
&wp_data->error_class, &wp_data->error_code);
|
||||
if (status) {
|
||||
Device_Set_Description(characterstring_value(&value.type.
|
||||
Character_String),
|
||||
Device_Set_Description(characterstring_value(&value.
|
||||
type.Character_String),
|
||||
characterstring_length(&value.type.Character_String));
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -44,7 +44,7 @@ static uint8_t Ethernet_Broadcast[MAX_MAC_LEN] =
|
||||
/* The OUI 00-00-5E has been allocated to IANA. */
|
||||
/* my local device data - MAC address */
|
||||
static uint8_t Ethernet_MAC_Address[MAX_MAC_LEN] =
|
||||
{0x00, 0x00, 0x5E, 0x00, 0x00, 0x01};
|
||||
{ 0x00, 0x00, 0x5E, 0x00, 0x00, 0x01 };
|
||||
|
||||
/* status of the link */
|
||||
static int32_t Ethernet_Status = R_ETHER_ERROR;
|
||||
@@ -167,7 +167,7 @@ uint16_t ethernet_receive(
|
||||
if (!ethernet_valid())
|
||||
return 0;
|
||||
|
||||
received_bytes = R_Ether_Read(0, (void *)buf);
|
||||
received_bytes = R_Ether_Read(0, (void *) buf);
|
||||
|
||||
if (received_bytes == 0)
|
||||
return 0;
|
||||
|
||||
@@ -42,40 +42,40 @@ void led_on(
|
||||
{
|
||||
switch (index) {
|
||||
case 4:
|
||||
R_IO_PORT_Write( LED4, LED_ON );
|
||||
R_IO_PORT_Write(LED4, LED_ON);
|
||||
break;
|
||||
case 5:
|
||||
R_IO_PORT_Write( LED5, LED_ON );
|
||||
R_IO_PORT_Write(LED5, LED_ON);
|
||||
break;
|
||||
case 6:
|
||||
R_IO_PORT_Write( LED6, LED_ON );
|
||||
R_IO_PORT_Write(LED6, LED_ON);
|
||||
break;
|
||||
case 7:
|
||||
R_IO_PORT_Write( LED7, LED_ON );
|
||||
R_IO_PORT_Write(LED7, LED_ON);
|
||||
break;
|
||||
case 8:
|
||||
R_IO_PORT_Write( LED8, LED_ON );
|
||||
R_IO_PORT_Write(LED8, LED_ON);
|
||||
break;
|
||||
case 9:
|
||||
R_IO_PORT_Write( LED9, LED_ON );
|
||||
R_IO_PORT_Write(LED9, LED_ON);
|
||||
break;
|
||||
case 10:
|
||||
R_IO_PORT_Write( LED10, LED_ON );
|
||||
R_IO_PORT_Write(LED10, LED_ON);
|
||||
break;
|
||||
case 11:
|
||||
R_IO_PORT_Write( LED11, LED_ON );
|
||||
R_IO_PORT_Write(LED11, LED_ON);
|
||||
break;
|
||||
case 12:
|
||||
R_IO_PORT_Write( LED12, LED_ON );
|
||||
R_IO_PORT_Write(LED12, LED_ON);
|
||||
break;
|
||||
case 13:
|
||||
R_IO_PORT_Write( LED13, LED_ON );
|
||||
R_IO_PORT_Write(LED13, LED_ON);
|
||||
break;
|
||||
case 14:
|
||||
R_IO_PORT_Write( LED14, LED_ON );
|
||||
R_IO_PORT_Write(LED14, LED_ON);
|
||||
break;
|
||||
case 15:
|
||||
R_IO_PORT_Write( LED15, LED_ON );
|
||||
R_IO_PORT_Write(LED15, LED_ON);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -96,40 +96,40 @@ void led_off(
|
||||
{
|
||||
switch (index) {
|
||||
case 4:
|
||||
R_IO_PORT_Write( LED4, LED_OFF );
|
||||
R_IO_PORT_Write(LED4, LED_OFF);
|
||||
break;
|
||||
case 5:
|
||||
R_IO_PORT_Write( LED5, LED_OFF );
|
||||
R_IO_PORT_Write(LED5, LED_OFF);
|
||||
break;
|
||||
case 6:
|
||||
R_IO_PORT_Write( LED6, LED_OFF );
|
||||
R_IO_PORT_Write(LED6, LED_OFF);
|
||||
break;
|
||||
case 7:
|
||||
R_IO_PORT_Write( LED7, LED_OFF );
|
||||
R_IO_PORT_Write(LED7, LED_OFF);
|
||||
break;
|
||||
case 8:
|
||||
R_IO_PORT_Write( LED8, LED_OFF );
|
||||
R_IO_PORT_Write(LED8, LED_OFF);
|
||||
break;
|
||||
case 9:
|
||||
R_IO_PORT_Write( LED9, LED_OFF );
|
||||
R_IO_PORT_Write(LED9, LED_OFF);
|
||||
break;
|
||||
case 10:
|
||||
R_IO_PORT_Write( LED10, LED_OFF );
|
||||
R_IO_PORT_Write(LED10, LED_OFF);
|
||||
break;
|
||||
case 11:
|
||||
R_IO_PORT_Write( LED11, LED_OFF );
|
||||
R_IO_PORT_Write(LED11, LED_OFF);
|
||||
break;
|
||||
case 12:
|
||||
R_IO_PORT_Write( LED12, LED_OFF );
|
||||
R_IO_PORT_Write(LED12, LED_OFF);
|
||||
break;
|
||||
case 13:
|
||||
R_IO_PORT_Write( LED13, LED_OFF );
|
||||
R_IO_PORT_Write(LED13, LED_OFF);
|
||||
break;
|
||||
case 14:
|
||||
R_IO_PORT_Write( LED14, LED_OFF );
|
||||
R_IO_PORT_Write(LED14, LED_OFF);
|
||||
break;
|
||||
case 15:
|
||||
R_IO_PORT_Write( LED15, LED_OFF );
|
||||
R_IO_PORT_Write(LED15, LED_OFF);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -228,7 +228,7 @@ void led_init(
|
||||
void)
|
||||
{
|
||||
unsigned i = 0;
|
||||
|
||||
|
||||
for (i = 0; i < MAX_LEDS; i++) {
|
||||
led_on_interval(i, 500);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,8 @@
|
||||
#include "led.h"
|
||||
|
||||
/** Main function of BACnet demo for RX62N evaluation board */
|
||||
int main(void)
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
InitialiseLCD();
|
||||
ClearLCD();
|
||||
|
||||
@@ -30,7 +30,8 @@
|
||||
static volatile uint32_t Millisecond_Counter;
|
||||
static volatile uint8_t Millisecond_Counter_Byte;
|
||||
/* forward prototype for interrupt service routine */
|
||||
void int_cmt0_isr(void);
|
||||
void int_cmt0_isr(
|
||||
void);
|
||||
|
||||
/*************************************************************************
|
||||
* Description: Timer Interrupt Handler
|
||||
@@ -49,7 +50,8 @@ static void timer_interrupt_handler(
|
||||
* Returns: nothing
|
||||
* Notes: none
|
||||
*************************************************************************/
|
||||
void int_cmt0_isr(void)
|
||||
void int_cmt0_isr(
|
||||
void)
|
||||
{
|
||||
timer_interrupt_handler();
|
||||
}
|
||||
@@ -92,15 +94,9 @@ void timer_init(
|
||||
bool err = true;
|
||||
|
||||
/* CMT is configured for a 1ms interval, and executes the callback
|
||||
function CB_CompareMatch on every compare match */
|
||||
err &= R_CMT_Create(
|
||||
3,
|
||||
PDL_CMT_PERIOD,
|
||||
1E-3,
|
||||
int_cmt0_isr,
|
||||
3
|
||||
);
|
||||
function CB_CompareMatch on every compare match */
|
||||
err &= R_CMT_Create(3, PDL_CMT_PERIOD, 1E-3, int_cmt0_isr, 3);
|
||||
|
||||
/* Halt in while loop when RPDL errors detected */
|
||||
while(!err);
|
||||
while (!err);
|
||||
}
|
||||
|
||||
@@ -65,7 +65,8 @@ static bool Auto_Mode_Enabled;
|
||||
* RETURN: true if automode enabled
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
bool automac_enabled(void)
|
||||
bool automac_enabled(
|
||||
void)
|
||||
{
|
||||
return Auto_Mode_Enabled;
|
||||
}
|
||||
@@ -75,7 +76,8 @@ bool automac_enabled(void)
|
||||
* RETURN: nothing
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
void automac_enabled_set(bool status)
|
||||
void automac_enabled_set(
|
||||
bool status)
|
||||
{
|
||||
Auto_Mode_Enabled = status;
|
||||
}
|
||||
@@ -85,7 +87,8 @@ void automac_enabled_set(bool status)
|
||||
* RETURN: true if full
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
bool automac_pfm_cycle_complete(void)
|
||||
bool automac_pfm_cycle_complete(
|
||||
void)
|
||||
{
|
||||
return PFM_Cycle_Complete;
|
||||
}
|
||||
@@ -95,13 +98,13 @@ bool automac_pfm_cycle_complete(void)
|
||||
* RETURN: true if used
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
static bool automac_address_used(uint8_t mac)
|
||||
static bool automac_address_used(
|
||||
uint8_t mac)
|
||||
{
|
||||
bool status = false;
|
||||
|
||||
if (mac < MAC_SLOTS_MAX) {
|
||||
if ((Auto_MAC_Data[mac].emitter) ||
|
||||
(Auto_MAC_Data[mac].reserved) ||
|
||||
if ((Auto_MAC_Data[mac].emitter) || (Auto_MAC_Data[mac].reserved) ||
|
||||
(Auto_MAC_Data[mac].token)) {
|
||||
status = true;
|
||||
}
|
||||
@@ -115,13 +118,13 @@ static bool automac_address_used(uint8_t mac)
|
||||
* RETURN: true if valid
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
bool automac_free_address_valid(uint8_t mac)
|
||||
bool automac_free_address_valid(
|
||||
uint8_t mac)
|
||||
{
|
||||
bool status = false;
|
||||
|
||||
if (mac < MAC_SLOTS_MAX) {
|
||||
if ((Auto_MAC_Data[mac].pfm) &&
|
||||
(!automac_address_used(mac))) {
|
||||
if ((Auto_MAC_Data[mac].pfm) && (!automac_address_used(mac))) {
|
||||
status = true;
|
||||
}
|
||||
}
|
||||
@@ -134,11 +137,12 @@ bool automac_free_address_valid(uint8_t mac)
|
||||
* RETURN: Next_Station, or 255 if there are no next stations
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
uint8_t automac_next_station(uint8_t mac)
|
||||
uint8_t automac_next_station(
|
||||
uint8_t mac)
|
||||
{
|
||||
uint8_t i = 0; /* loop counter */
|
||||
uint8_t i = 0; /* loop counter */
|
||||
uint8_t next_station = 255; /* return value */
|
||||
uint8_t test_station = 0; /* station number to test for token */
|
||||
uint8_t test_station = 0; /* station number to test for token */
|
||||
|
||||
test_station = (mac + 1) % 128;
|
||||
for (i = 0; i < MAC_SLOTS_MAX; i++) {
|
||||
@@ -157,7 +161,8 @@ uint8_t automac_next_station(uint8_t mac)
|
||||
* RETURN: Number of free MAC addresses
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
uint8_t automac_free_address_count(void)
|
||||
uint8_t automac_free_address_count(
|
||||
void)
|
||||
{
|
||||
uint8_t i = 0;
|
||||
uint8_t slots = 0;
|
||||
@@ -176,7 +181,8 @@ uint8_t automac_free_address_count(void)
|
||||
* RETURN: Number of free MAC addresses
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
uint8_t automac_free_address_mac(uint8_t count)
|
||||
uint8_t automac_free_address_mac(
|
||||
uint8_t count)
|
||||
{
|
||||
uint8_t i = 0;
|
||||
uint8_t slots = 0;
|
||||
@@ -200,7 +206,8 @@ uint8_t automac_free_address_mac(uint8_t count)
|
||||
* RETURN: free MAC addresses
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
uint8_t automac_free_address_random(void)
|
||||
uint8_t automac_free_address_random(
|
||||
void)
|
||||
{
|
||||
uint8_t count = 0;
|
||||
uint8_t random_count = 0;
|
||||
@@ -208,7 +215,7 @@ uint8_t automac_free_address_random(void)
|
||||
|
||||
count = automac_free_address_count();
|
||||
if (count) {
|
||||
random_count = rand()%count;
|
||||
random_count = rand() % count;
|
||||
mac = automac_free_address_mac(random_count);
|
||||
}
|
||||
|
||||
@@ -220,7 +227,8 @@ uint8_t automac_free_address_random(void)
|
||||
* RETURN: MAC addresses
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
uint8_t automac_address(void)
|
||||
uint8_t automac_address(
|
||||
void)
|
||||
{
|
||||
return My_MAC_Address;
|
||||
}
|
||||
@@ -230,7 +238,8 @@ uint8_t automac_address(void)
|
||||
* RETURN: MAC addresses
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
void automac_address_set(uint8_t mac)
|
||||
void automac_address_set(
|
||||
uint8_t mac)
|
||||
{
|
||||
My_MAC_Address = mac;
|
||||
}
|
||||
@@ -240,7 +249,8 @@ void automac_address_set(uint8_t mac)
|
||||
* RETURN: MAC addresses
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
uint16_t automac_time_slot(void)
|
||||
uint16_t automac_time_slot(
|
||||
void)
|
||||
{
|
||||
return My_Time_Slot;
|
||||
}
|
||||
@@ -250,12 +260,14 @@ uint16_t automac_time_slot(void)
|
||||
* RETURN: MAC addresses
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
void automac_address_init(void)
|
||||
void automac_address_init(
|
||||
void)
|
||||
{
|
||||
My_MAC_Address = MAC_SLOTS_OFFSET + rand()%(MAC_SLOTS_MAX-MAC_SLOTS_OFFSET);
|
||||
My_MAC_Address =
|
||||
MAC_SLOTS_OFFSET + rand() % (MAC_SLOTS_MAX - MAC_SLOTS_OFFSET);
|
||||
/* at least as long as a dropped token - worst case */
|
||||
My_Time_Slot = Tno_token + (MAC_SLOTS_MAX * Tslot);
|
||||
My_Time_Slot += (uint16_t)My_MAC_Address * Tslot;
|
||||
My_Time_Slot += (uint16_t) My_MAC_Address *Tslot;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@@ -263,7 +275,8 @@ void automac_address_init(void)
|
||||
* RETURN: nothing
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
void automac_pfm_set(uint8_t mac)
|
||||
void automac_pfm_set(
|
||||
uint8_t mac)
|
||||
{
|
||||
if (mac < MAC_SLOTS_MAX) {
|
||||
if (Auto_MAC_Data[mac].pfm) {
|
||||
@@ -281,7 +294,8 @@ void automac_pfm_set(uint8_t mac)
|
||||
* RETURN: nothing
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
void automac_token_set(uint8_t mac)
|
||||
void automac_token_set(
|
||||
uint8_t mac)
|
||||
{
|
||||
if (mac < MAC_SLOTS_MAX) {
|
||||
Auto_MAC_Data[mac].token = true;
|
||||
@@ -293,7 +307,8 @@ void automac_token_set(uint8_t mac)
|
||||
* RETURN: nothing
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
void automac_emitter_set(uint8_t mac)
|
||||
void automac_emitter_set(
|
||||
uint8_t mac)
|
||||
{
|
||||
if (mac < MAC_SLOTS_MAX) {
|
||||
Auto_MAC_Data[mac].emitter = true;
|
||||
@@ -305,7 +320,8 @@ void automac_emitter_set(uint8_t mac)
|
||||
* RETURN: nothing
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
void automac_init(void)
|
||||
void automac_init(
|
||||
void)
|
||||
{
|
||||
uint8_t i = 0;
|
||||
|
||||
@@ -359,34 +375,31 @@ void test_Auto_MAC(
|
||||
srand(42);
|
||||
mac = automac_free_address_random();
|
||||
ct_test(pTest, mac == 255);
|
||||
automac_pfm_set(MAC_SLOTS_OFFSET+1);
|
||||
automac_pfm_set(MAC_SLOTS_OFFSET + 1);
|
||||
mac = automac_free_address_mac(0);
|
||||
ct_test(pTest, mac == (MAC_SLOTS_OFFSET+1));
|
||||
ct_test(pTest, mac == (MAC_SLOTS_OFFSET + 1));
|
||||
mac = automac_free_address_random();
|
||||
ct_test(pTest, mac == (MAC_SLOTS_OFFSET+1));
|
||||
ct_test(pTest, mac == (MAC_SLOTS_OFFSET + 1));
|
||||
/* test 2 free addresses */
|
||||
automac_pfm_set(MAC_SLOTS_OFFSET+2);
|
||||
automac_pfm_set(MAC_SLOTS_OFFSET + 2);
|
||||
mac = automac_free_address_mac(0);
|
||||
ct_test(pTest, mac == (MAC_SLOTS_OFFSET+1));
|
||||
ct_test(pTest, mac == (MAC_SLOTS_OFFSET + 1));
|
||||
mac = automac_free_address_mac(1);
|
||||
ct_test(pTest, mac == (MAC_SLOTS_OFFSET+2));
|
||||
ct_test(pTest, mac == (MAC_SLOTS_OFFSET + 2));
|
||||
mac = automac_free_address_random();
|
||||
ct_test(pTest,
|
||||
(mac == (MAC_SLOTS_OFFSET+1)) ||
|
||||
(mac == (MAC_SLOTS_OFFSET+2)));
|
||||
ct_test(pTest, (mac == (MAC_SLOTS_OFFSET + 1)) ||
|
||||
(mac == (MAC_SLOTS_OFFSET + 2)));
|
||||
/* test 3 free addresses */
|
||||
automac_pfm_set(126);
|
||||
mac = automac_free_address_mac(0);
|
||||
ct_test(pTest, mac == (MAC_SLOTS_OFFSET+1));
|
||||
ct_test(pTest, mac == (MAC_SLOTS_OFFSET + 1));
|
||||
mac = automac_free_address_mac(1);
|
||||
ct_test(pTest, mac == (MAC_SLOTS_OFFSET+2));
|
||||
ct_test(pTest, mac == (MAC_SLOTS_OFFSET + 2));
|
||||
mac = automac_free_address_mac(2);
|
||||
ct_test(pTest, mac == 126);
|
||||
mac = automac_free_address_random();
|
||||
ct_test(pTest,
|
||||
(mac == (MAC_SLOTS_OFFSET+1))||
|
||||
(mac == (MAC_SLOTS_OFFSET+2))||
|
||||
(mac == 126));
|
||||
ct_test(pTest, (mac == (MAC_SLOTS_OFFSET + 1)) ||
|
||||
(mac == (MAC_SLOTS_OFFSET + 2)) || (mac == 126));
|
||||
/* test the stored address */
|
||||
mac = automac_address();
|
||||
ct_test(pTest, mac < MAC_SLOTS_MAX);
|
||||
@@ -423,4 +436,3 @@ int main(
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
@@ -34,26 +34,41 @@
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
void automac_init(void);
|
||||
void automac_init(
|
||||
void);
|
||||
|
||||
bool automac_free_address_valid(uint8_t mac);
|
||||
uint8_t automac_free_address_count(void);
|
||||
uint8_t automac_free_address_mac(uint8_t count);
|
||||
uint8_t automac_free_address_random(void);
|
||||
void automac_pfm_set(uint8_t mac);
|
||||
void automac_token_set(uint8_t mac);
|
||||
void automac_emitter_set(uint8_t mac);
|
||||
uint8_t automac_next_station(uint8_t mac);
|
||||
uint8_t automac_address(void);
|
||||
void automac_address_set(uint8_t mac);
|
||||
void automac_address_init(void);
|
||||
uint16_t automac_time_slot(void);
|
||||
bool automac_pfm_cycle_complete(void);
|
||||
bool automac_enabled(void);
|
||||
void automac_enabled_set(bool status);
|
||||
bool automac_free_address_valid(
|
||||
uint8_t mac);
|
||||
uint8_t automac_free_address_count(
|
||||
void);
|
||||
uint8_t automac_free_address_mac(
|
||||
uint8_t count);
|
||||
uint8_t automac_free_address_random(
|
||||
void);
|
||||
void automac_pfm_set(
|
||||
uint8_t mac);
|
||||
void automac_token_set(
|
||||
uint8_t mac);
|
||||
void automac_emitter_set(
|
||||
uint8_t mac);
|
||||
uint8_t automac_next_station(
|
||||
uint8_t mac);
|
||||
uint8_t automac_address(
|
||||
void);
|
||||
void automac_address_set(
|
||||
uint8_t mac);
|
||||
void automac_address_init(
|
||||
void);
|
||||
uint16_t automac_time_slot(
|
||||
void);
|
||||
bool automac_pfm_cycle_complete(
|
||||
void);
|
||||
bool automac_enabled(
|
||||
void);
|
||||
void automac_enabled_set(
|
||||
bool status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
|
||||
@@ -222,7 +222,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[16] = "BO-0"; /* okay for single thread */
|
||||
bool status = false;
|
||||
@@ -430,8 +430,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
|
||||
|
||||
@@ -175,8 +175,7 @@ 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);
|
||||
}
|
||||
}
|
||||
@@ -343,7 +342,7 @@ uint32_t Device_Index_To_Instance(
|
||||
|
||||
bool Device_Object_Name(
|
||||
uint32_t object_instance,
|
||||
BACNET_CHARACTER_STRING *object_name)
|
||||
BACNET_CHARACTER_STRING * object_name)
|
||||
{
|
||||
bool status = false;
|
||||
|
||||
@@ -387,7 +386,7 @@ void Device_Init(
|
||||
{
|
||||
struct my_object_functions *pObject = NULL;
|
||||
|
||||
(void)object_table;
|
||||
(void) object_table;
|
||||
pObject = &Object_Table[0];
|
||||
while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) {
|
||||
if (pObject->Object_Init) {
|
||||
@@ -525,7 +524,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)
|
||||
{
|
||||
@@ -541,10 +540,10 @@ bool Device_Valid_Object_Name(
|
||||
for (i = 0; i < max_objects; i++) {
|
||||
check_id = Device_Object_List_Identifier(i, &type, &instance);
|
||||
if (check_id) {
|
||||
pObject = Device_Objects_Find_Functions((BACNET_OBJECT_TYPE)type);
|
||||
pObject = Device_Objects_Find_Functions((BACNET_OBJECT_TYPE) 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;
|
||||
@@ -564,10 +563,10 @@ 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((BACNET_OBJECT_TYPE)object_type);
|
||||
pObject = Device_Objects_Find_Functions((BACNET_OBJECT_TYPE) object_type);
|
||||
if ((pObject != NULL) && (pObject->Object_Valid_Instance != NULL)) {
|
||||
status = pObject->Object_Valid_Instance(object_instance);
|
||||
}
|
||||
@@ -578,7 +577,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;
|
||||
@@ -591,7 +590,7 @@ bool Device_Object_Name_Copy(
|
||||
for (i = 0; i < max_objects; i++) {
|
||||
check_id = Device_Object_List_Identifier(i, &type, &instance);
|
||||
if (check_id) {
|
||||
pObject = Device_Objects_Find_Functions((BACNET_OBJECT_TYPE)type);
|
||||
pObject = Device_Objects_Find_Functions((BACNET_OBJECT_TYPE) type);
|
||||
if ((pObject != NULL) && (pObject->Object_Name != NULL)) {
|
||||
found = pObject->Object_Name(instance, object_name);
|
||||
break;
|
||||
@@ -816,8 +815,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 {
|
||||
@@ -869,8 +868,8 @@ bool Device_Write_Property_Local(
|
||||
uint8_t encoding =
|
||||
characterstring_encoding(&value.type.Character_String);
|
||||
if (encoding < MAX_CHARACTER_STRING_ENCODING) {
|
||||
characterstring_copy(&My_Object_Name, &value.type.
|
||||
Character_String);
|
||||
characterstring_copy(&My_Object_Name,
|
||||
&value.type.Character_String);
|
||||
status = true;
|
||||
} else {
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
|
||||
@@ -206,22 +206,17 @@ static RING_BUFFER PDU_Queue;
|
||||
/* node, its value shall be 1. */
|
||||
static uint8_t Nmax_info_frames = MSTP_PDU_PACKET_COUNT;
|
||||
|
||||
void dlmstp_automac_hander(void);
|
||||
void dlmstp_automac_hander(
|
||||
void);
|
||||
|
||||
bool dlmstp_init(
|
||||
char *ifname)
|
||||
{
|
||||
ifname = ifname;
|
||||
Ringbuf_Init(
|
||||
&Transmit_Queue,
|
||||
(uint8_t *)&Transmit_Buffer,
|
||||
sizeof(struct mstp_tx_packet),
|
||||
MSTP_TRANSMIT_PACKET_COUNT);
|
||||
Ringbuf_Init(
|
||||
&PDU_Queue,
|
||||
(uint8_t *)&PDU_Buffer,
|
||||
sizeof(struct mstp_pdu_packet),
|
||||
MSTP_PDU_PACKET_COUNT);
|
||||
Ringbuf_Init(&Transmit_Queue, (uint8_t *) & Transmit_Buffer,
|
||||
sizeof(struct mstp_tx_packet), MSTP_TRANSMIT_PACKET_COUNT);
|
||||
Ringbuf_Init(&PDU_Queue, (uint8_t *) & PDU_Buffer,
|
||||
sizeof(struct mstp_pdu_packet), MSTP_PDU_PACKET_COUNT);
|
||||
rs485_init();
|
||||
automac_init();
|
||||
|
||||
@@ -366,25 +361,26 @@ static bool dlmstp_compare_data_expecting_reply(
|
||||
return true;
|
||||
}
|
||||
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
MSTP_TX_STATE_IDLE,
|
||||
MSTP_TX_STATE_SILENCE_WAIT,
|
||||
MSTP_TX_STATE_SEND_WAIT,
|
||||
MSTP_TX_STATE_STOP
|
||||
} MSTP_TX_STATE;
|
||||
static bool MSTP_Transmit_FSM(void)
|
||||
static bool MSTP_Transmit_FSM(
|
||||
void)
|
||||
{
|
||||
static MSTP_TX_STATE state = MSTP_TX_STATE_IDLE;
|
||||
static struct mstp_tx_packet *pkt;
|
||||
|
||||
MSTP_TX_START:
|
||||
MSTP_TX_START:
|
||||
switch (state) {
|
||||
case MSTP_TX_STATE_IDLE:
|
||||
if (!Ringbuf_Empty(&Transmit_Queue)) {
|
||||
/* get the packet - but don't remove it from queue */
|
||||
pkt = (struct mstp_tx_packet *)Ringbuf_Get_Front(
|
||||
&Transmit_Queue);
|
||||
pkt =
|
||||
(struct mstp_tx_packet *)
|
||||
Ringbuf_Get_Front(&Transmit_Queue);
|
||||
state = MSTP_TX_STATE_SILENCE_WAIT;
|
||||
}
|
||||
break;
|
||||
@@ -415,7 +411,7 @@ static bool MSTP_Transmit_FSM(void)
|
||||
if (rs485_byte_sent() && rs485_frame_sent()) {
|
||||
rs485_rts_enable(false);
|
||||
/* remove the packet from the queue */
|
||||
(void)Ringbuf_Pop_Front(&Transmit_Queue);
|
||||
(void) Ringbuf_Pop_Front(&Transmit_Queue);
|
||||
state = MSTP_TX_STATE_IDLE;
|
||||
}
|
||||
break;
|
||||
@@ -452,8 +448,7 @@ static void MSTP_Send_Frame(
|
||||
static struct mstp_tx_packet *pkt;
|
||||
uint16_t i = 0; /* used to calculate CRC for data */
|
||||
|
||||
pkt = (struct mstp_tx_packet *)Ringbuf_Alloc(
|
||||
&Transmit_Queue);
|
||||
pkt = (struct mstp_tx_packet *) Ringbuf_Alloc(&Transmit_Queue);
|
||||
if (pkt) {
|
||||
/* create the MS/TP header */
|
||||
pkt->buffer[0] = 0x55;
|
||||
@@ -474,11 +469,11 @@ static void MSTP_Send_Frame(
|
||||
/* calculate CRC for any data */
|
||||
for (i = 0; i < data_len; i++) {
|
||||
crc16 = CRC_Calc_Data(data[i], crc16);
|
||||
pkt->buffer[8+i] = data[i];
|
||||
pkt->buffer[8 + i] = data[i];
|
||||
}
|
||||
crc16 = ~crc16;
|
||||
pkt->buffer[8+data_len] = (crc16 & 0x00FF);
|
||||
pkt->buffer[8+data_len+1] = ((crc16 & 0xFF00) >> 8);
|
||||
pkt->buffer[8 + data_len] = (crc16 & 0x00FF);
|
||||
pkt->buffer[8 + data_len + 1] = ((crc16 & 0xFF00) >> 8);
|
||||
pkt->length += data_len;
|
||||
pkt->length += 2;
|
||||
}
|
||||
@@ -630,13 +625,15 @@ static void MSTP_Receive_Frame_FSM(
|
||||
} else {
|
||||
/* receive the data portion of the frame. */
|
||||
if ((DestinationAddress == This_Station) ||
|
||||
(DestinationAddress == MSTP_BROADCAST_ADDRESS)) {
|
||||
(DestinationAddress ==
|
||||
MSTP_BROADCAST_ADDRESS)) {
|
||||
if (DataLength <= InputBufferSize) {
|
||||
/* Data */
|
||||
Receive_State = MSTP_RECEIVE_STATE_DATA;
|
||||
} else {
|
||||
/* FrameTooLong */
|
||||
Receive_State = MSTP_RECEIVE_STATE_SKIP_DATA;
|
||||
Receive_State =
|
||||
MSTP_RECEIVE_STATE_SKIP_DATA;
|
||||
}
|
||||
} else {
|
||||
/* NotForUs */
|
||||
@@ -877,8 +874,7 @@ static bool MSTP_Master_Node_FSM(
|
||||
transition_now = true;
|
||||
} else {
|
||||
uint8_t frame_type;
|
||||
pkt = (struct mstp_pdu_packet *)Ringbuf_Pop_Front(
|
||||
&PDU_Queue);
|
||||
pkt = (struct mstp_pdu_packet *) Ringbuf_Pop_Front(&PDU_Queue);
|
||||
if (pkt->data_expecting_reply) {
|
||||
frame_type = FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY;
|
||||
} else {
|
||||
@@ -985,10 +981,9 @@ static bool MSTP_Master_Node_FSM(
|
||||
(Next_Station == This_Station)) {
|
||||
/* NextStationUnknown - added in Addendum 135-2008v-1 */
|
||||
/* then the next station to which the token
|
||||
should be sent is unknown - so PollForMaster */
|
||||
should be sent is unknown - so PollForMaster */
|
||||
Poll_Station = next_this_station;
|
||||
MSTP_Send_Frame(
|
||||
FRAME_TYPE_POLL_FOR_MASTER, Poll_Station,
|
||||
MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER, Poll_Station,
|
||||
This_Station, NULL, 0);
|
||||
RetryCount = 0;
|
||||
Master_State = MSTP_MASTER_STATE_POLL_FOR_MASTER;
|
||||
@@ -1214,12 +1209,11 @@ static bool MSTP_Master_Node_FSM(
|
||||
/* Note: we could wait for up to Treply_delay */
|
||||
matched = false;
|
||||
if (!Ringbuf_Empty(&PDU_Queue)) {
|
||||
pkt = (struct mstp_pdu_packet *)Ringbuf_Get_Front(
|
||||
&PDU_Queue);
|
||||
pkt = (struct mstp_pdu_packet *) Ringbuf_Get_Front(&PDU_Queue);
|
||||
matched =
|
||||
dlmstp_compare_data_expecting_reply(&InputBuffer[0],
|
||||
DataLength, SourceAddress, &pkt->buffer[0],
|
||||
pkt->length, pkt->destination_mac);
|
||||
DataLength, SourceAddress, &pkt->buffer[0], pkt->length,
|
||||
pkt->destination_mac);
|
||||
}
|
||||
if (matched) {
|
||||
/* Reply */
|
||||
@@ -1230,8 +1224,7 @@ static bool MSTP_Master_Node_FSM(
|
||||
/* then call MSTP_Send_Frame to transmit the reply frame */
|
||||
/* and enter the IDLE state to wait for the next frame. */
|
||||
uint8_t frame_type;
|
||||
pkt = (struct mstp_pdu_packet *)Ringbuf_Pop_Front(
|
||||
&PDU_Queue);
|
||||
pkt = (struct mstp_pdu_packet *) Ringbuf_Pop_Front(&PDU_Queue);
|
||||
if (pkt->data_expecting_reply) {
|
||||
frame_type = FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY;
|
||||
} else {
|
||||
@@ -1276,7 +1269,7 @@ int dlmstp_send_pdu(
|
||||
struct mstp_pdu_packet *pkt;
|
||||
uint16_t i = 0;
|
||||
|
||||
pkt = (struct mstp_pdu_packet *)Ringbuf_Alloc(&PDU_Queue);
|
||||
pkt = (struct mstp_pdu_packet *) Ringbuf_Alloc(&PDU_Queue);
|
||||
if (pkt) {
|
||||
pkt->data_expecting_reply = npdu_data->data_expecting_reply;
|
||||
for (i = 0; i < pdu_len; i++) {
|
||||
@@ -1300,7 +1293,8 @@ typedef enum {
|
||||
} AUTOMAC_STATE;
|
||||
/* buffer used to send and validate a response - size is min APDU size */
|
||||
static uint8_t AutoMAC_Test_Buffer[50];
|
||||
void dlmstp_automac_hander(void)
|
||||
void dlmstp_automac_hander(
|
||||
void)
|
||||
{
|
||||
static AUTOMAC_STATE state = AUTOMAC_STATE_IDLE;
|
||||
uint8_t mac = 0;
|
||||
@@ -1341,7 +1335,7 @@ void dlmstp_automac_hander(void)
|
||||
}
|
||||
} else if (rs485_silence_elapsed(automac_time_slot())) {
|
||||
/* long silence indicates we are alone or
|
||||
with other silent devices */
|
||||
with other silent devices */
|
||||
SourceAddress = automac_address();
|
||||
state = AUTOMAC_STATE_TESTING;
|
||||
}
|
||||
@@ -1360,7 +1354,8 @@ void dlmstp_automac_hander(void)
|
||||
automac_init();
|
||||
state = AUTOMAC_STATE_IDLE;
|
||||
} else if (mac == DestinationAddress) {
|
||||
MSTP_Send_Frame(FRAME_TYPE_REPLY_TO_POLL_FOR_MASTER,
|
||||
MSTP_Send_Frame
|
||||
(FRAME_TYPE_REPLY_TO_POLL_FOR_MASTER,
|
||||
SourceAddress, mac, NULL, 0);
|
||||
state = AUTOMAC_STATE_TOKEN;
|
||||
}
|
||||
@@ -1433,9 +1428,8 @@ void dlmstp_automac_hander(void)
|
||||
encode_unsigned16(&AutoMAC_Test_Buffer[0], vendor_id);
|
||||
serial_number = Device_Object_Instance_Number();
|
||||
encode_unsigned32(&AutoMAC_Test_Buffer[2], serial_number);
|
||||
MSTP_Send_Frame(FRAME_TYPE_TEST_REQUEST,
|
||||
SourceAddress, mac, &AutoMAC_Test_Buffer[0],
|
||||
6);
|
||||
MSTP_Send_Frame(FRAME_TYPE_TEST_REQUEST, SourceAddress, mac,
|
||||
&AutoMAC_Test_Buffer[0], 6);
|
||||
state = AUTOMAC_STATE_CONFIRM;
|
||||
break;
|
||||
case AUTOMAC_STATE_CONFIRM:
|
||||
@@ -1448,8 +1442,7 @@ void dlmstp_automac_hander(void)
|
||||
MSTP_Flag.ReceivedValidFrame = false;
|
||||
MSTP_Flag.ReceivedValidFrameNotForUs = false;
|
||||
mac = automac_address();
|
||||
if ((mac == DestinationAddress) &&
|
||||
(DataLength >= 6)) {
|
||||
if ((mac == DestinationAddress) && (DataLength >= 6)) {
|
||||
decode_unsigned16(&InputBuffer[0], &vendor_id);
|
||||
decode_unsigned32(&InputBuffer[2], &serial_number);
|
||||
if ((vendor_id == Device_Vendor_Identifier()) &&
|
||||
@@ -1511,18 +1504,14 @@ uint16_t dlmstp_receive(
|
||||
/* only do receive state machine while we don't have a frame */
|
||||
if ((MSTP_Flag.ReceivedValidFrame == false) &&
|
||||
(MSTP_Flag.ReceivedValidFrameNotForUs == false) &&
|
||||
(MSTP_Flag.ReceivedInvalidFrame == false) &&
|
||||
(transmitting == false)) {
|
||||
(MSTP_Flag.ReceivedInvalidFrame == false) && (transmitting == false)) {
|
||||
MSTP_Receive_Frame_FSM();
|
||||
}
|
||||
/* only do master state machine while rx is idle */
|
||||
if ((Receive_State == MSTP_RECEIVE_STATE_IDLE) &&
|
||||
(transmitting == false)) {
|
||||
if ((This_Station != 255) &&
|
||||
(MSTP_Flag.ReceivedValidFrameNotForUs)) {
|
||||
if ((Receive_State == MSTP_RECEIVE_STATE_IDLE) && (transmitting == false)) {
|
||||
if ((This_Station != 255) && (MSTP_Flag.ReceivedValidFrameNotForUs)) {
|
||||
MSTP_Flag.ReceivedValidFrameNotForUs = false;
|
||||
if ((SourceAddress == This_Station) &&
|
||||
automac_enabled()) {
|
||||
if ((SourceAddress == This_Station) && automac_enabled()) {
|
||||
/* duplicate MAC on the wire */
|
||||
automac_init();
|
||||
This_Station = 255;
|
||||
@@ -1602,8 +1591,7 @@ void dlmstp_set_max_master(
|
||||
uint8_t max_master)
|
||||
{
|
||||
if (max_master <= 127) {
|
||||
if ((This_Station == 255) ||
|
||||
(This_Station <= max_master)) {
|
||||
if ((This_Station == 255) || (This_Station <= max_master)) {
|
||||
Nmax_master = max_master;
|
||||
}
|
||||
}
|
||||
@@ -1651,7 +1639,8 @@ void dlmstp_get_broadcast_address(
|
||||
return;
|
||||
}
|
||||
|
||||
bool dlmstp_sole_master(void)
|
||||
bool dlmstp_sole_master(
|
||||
void)
|
||||
{
|
||||
if (MSTP_Flag.SoleMaster) {
|
||||
return true;
|
||||
@@ -1659,4 +1648,3 @@ bool dlmstp_sole_master(void)
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -89,7 +89,8 @@ void led_rx_off(
|
||||
* Returns: true if on, false if off.
|
||||
* Notes: none
|
||||
*************************************************************************/
|
||||
bool led_rx_state(void)
|
||||
bool led_rx_state(
|
||||
void)
|
||||
{
|
||||
return Rx_State;
|
||||
}
|
||||
@@ -99,7 +100,8 @@ bool led_rx_state(void)
|
||||
* Returns: true if on, false if off.
|
||||
* Notes: none
|
||||
*************************************************************************/
|
||||
bool led_tx_state(void)
|
||||
bool led_tx_state(
|
||||
void)
|
||||
{
|
||||
return Tx_State;
|
||||
}
|
||||
@@ -109,7 +111,8 @@ bool led_tx_state(void)
|
||||
* Returns: none
|
||||
* Notes: none
|
||||
*************************************************************************/
|
||||
void led_tx_toggle(void)
|
||||
void led_tx_toggle(
|
||||
void)
|
||||
{
|
||||
if (led_tx_state()) {
|
||||
led_tx_off();
|
||||
@@ -123,7 +126,8 @@ void led_tx_toggle(void)
|
||||
* Returns: none
|
||||
* Notes: none
|
||||
*************************************************************************/
|
||||
void led_rx_toggle(void)
|
||||
void led_rx_toggle(
|
||||
void)
|
||||
{
|
||||
if (led_rx_state()) {
|
||||
led_rx_off();
|
||||
@@ -247,7 +251,8 @@ void led_ld3_off(
|
||||
* Returns: true if on, false if off.
|
||||
* Notes: none
|
||||
*************************************************************************/
|
||||
bool led_ld3_state(void)
|
||||
bool led_ld3_state(
|
||||
void)
|
||||
{
|
||||
return LD3_State;
|
||||
}
|
||||
@@ -257,7 +262,8 @@ bool led_ld3_state(void)
|
||||
* Returns: none
|
||||
* Notes: none
|
||||
*************************************************************************/
|
||||
void led_ld3_toggle(void)
|
||||
void led_ld3_toggle(
|
||||
void)
|
||||
{
|
||||
if (led_ld3_state()) {
|
||||
led_ld3_off();
|
||||
|
||||
@@ -39,30 +39,40 @@ extern "C" {
|
||||
void);
|
||||
void led_ld4_off(
|
||||
void);
|
||||
bool led_ld3_state(void);
|
||||
void led_ld3_toggle(void);
|
||||
bool led_ld3_state(
|
||||
void);
|
||||
void led_ld3_toggle(
|
||||
void);
|
||||
|
||||
void led_tx_on(void);
|
||||
void led_rx_on(void);
|
||||
void led_tx_on(
|
||||
void);
|
||||
void led_rx_on(
|
||||
void);
|
||||
|
||||
void led_tx_on_interval(
|
||||
uint16_t interval_ms);
|
||||
void led_rx_on_interval(
|
||||
uint16_t interval_ms);
|
||||
|
||||
void led_tx_off(void);
|
||||
void led_rx_off(void);
|
||||
void led_tx_off(
|
||||
void);
|
||||
void led_rx_off(
|
||||
void);
|
||||
|
||||
void led_tx_off_delay(
|
||||
uint32_t delay_ms);
|
||||
void led_rx_off_delay(
|
||||
uint32_t delay_ms);
|
||||
|
||||
void led_tx_toggle(void);
|
||||
void led_rx_toggle(void);
|
||||
void led_tx_toggle(
|
||||
void);
|
||||
void led_rx_toggle(
|
||||
void);
|
||||
|
||||
bool led_tx_state(void);
|
||||
bool led_rx_state(void);
|
||||
bool led_tx_state(
|
||||
void);
|
||||
bool led_rx_state(
|
||||
void);
|
||||
|
||||
void led_task(
|
||||
void);
|
||||
|
||||
@@ -44,15 +44,16 @@ char *BACnet_Version = "1.0";
|
||||
* @param line: assert_param error line source number
|
||||
* @retval None
|
||||
*/
|
||||
void assert_failed(uint8_t* file, uint32_t line)
|
||||
void assert_failed(
|
||||
uint8_t * file,
|
||||
uint32_t line)
|
||||
{
|
||||
/* User can add his own implementation to report the file name and line number,
|
||||
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||
/* User can add his own implementation to report the file name and line number,
|
||||
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||
|
||||
/* Infinite loop */
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
/* Infinite loop */
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -60,7 +61,8 @@ void assert_failed(uint8_t* file, uint32_t line)
|
||||
#define LSE_FAIL_FLAG 0x80
|
||||
#define LSE_PASS_FLAG 0x100
|
||||
|
||||
void lse_init(void)
|
||||
void lse_init(
|
||||
void)
|
||||
{
|
||||
uint32_t LSE_Delay = 0;
|
||||
struct etimer Delay_Timer;
|
||||
@@ -70,42 +72,37 @@ void lse_init(void)
|
||||
/* Enable LSE (Low Speed External Oscillation) */
|
||||
RCC_LSEConfig(RCC_LSE_ON);
|
||||
|
||||
/* Check the LSE Status */
|
||||
while(1)
|
||||
{
|
||||
if(LSE_Delay < LSE_FAIL_FLAG)
|
||||
{
|
||||
timer_elapsed_start(&Delay_Timer);
|
||||
while (!timer_elapsed_milliseconds(&Delay_Timer,500)) {
|
||||
/* do nothing */
|
||||
}
|
||||
/* check whether LSE is ready, with 4 seconds timeout */
|
||||
LSE_Delay += 0x10;
|
||||
if(RCC_GetFlagStatus(RCC_FLAG_LSERDY) != RESET)
|
||||
{
|
||||
/* Set flag: LSE PASS */
|
||||
LSE_Delay |= LSE_PASS_FLAG;
|
||||
led_ld4_off();
|
||||
/* Disable LSE */
|
||||
RCC_LSEConfig(RCC_LSE_OFF);
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* Check the LSE Status */
|
||||
while (1) {
|
||||
if (LSE_Delay < LSE_FAIL_FLAG) {
|
||||
timer_elapsed_start(&Delay_Timer);
|
||||
while (!timer_elapsed_milliseconds(&Delay_Timer, 500)) {
|
||||
/* do nothing */
|
||||
}
|
||||
/* check whether LSE is ready, with 4 seconds timeout */
|
||||
LSE_Delay += 0x10;
|
||||
if (RCC_GetFlagStatus(RCC_FLAG_LSERDY) != RESET) {
|
||||
/* Set flag: LSE PASS */
|
||||
LSE_Delay |= LSE_PASS_FLAG;
|
||||
led_ld4_off();
|
||||
/* Disable LSE */
|
||||
RCC_LSEConfig(RCC_LSE_OFF);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* LSE_FAIL_FLAG = 0x80 */
|
||||
else if(LSE_Delay >= LSE_FAIL_FLAG)
|
||||
{
|
||||
if(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
|
||||
{
|
||||
/* Set flag: LSE FAIL */
|
||||
LSE_Delay |= LSE_FAIL_FLAG;
|
||||
led_ld4_on();
|
||||
}
|
||||
/* Disable LSE */
|
||||
RCC_LSEConfig(RCC_LSE_OFF);
|
||||
break;
|
||||
/* LSE_FAIL_FLAG = 0x80 */
|
||||
else if (LSE_Delay >= LSE_FAIL_FLAG) {
|
||||
if (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) {
|
||||
/* Set flag: LSE FAIL */
|
||||
LSE_Delay |= LSE_FAIL_FLAG;
|
||||
led_ld4_on();
|
||||
}
|
||||
/* Disable LSE */
|
||||
RCC_LSEConfig(RCC_LSE_OFF);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(
|
||||
@@ -114,17 +111,16 @@ int main(
|
||||
struct itimer Blink_Timer;
|
||||
|
||||
/*At this stage the microcontroller clock setting is already configured,
|
||||
this is done through SystemInit() function which is called from startup
|
||||
file (startup_stm32f10x_xx.s) before to branch to application main.
|
||||
To reconfigure the default setting of SystemInit() function, refer to
|
||||
system_stm32f10x.c file */
|
||||
this is done through SystemInit() function which is called from startup
|
||||
file (startup_stm32f10x_xx.s) before to branch to application main.
|
||||
To reconfigure the default setting of SystemInit() function, refer to
|
||||
system_stm32f10x.c file */
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
|
||||
led_init();
|
||||
RCC_APB2PeriphClockCmd(
|
||||
RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
|
||||
RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |
|
||||
RCC_APB2Periph_GPIOE, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
|
||||
RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE,
|
||||
ENABLE);
|
||||
timer_init();
|
||||
lse_init();
|
||||
led_init();
|
||||
|
||||
@@ -58,7 +58,8 @@ static uint32_t Baud_Rate = 38400;
|
||||
* Returns: nothing
|
||||
* Notes: none
|
||||
**************************************************************************/
|
||||
void rs485_silence_reset(void)
|
||||
void rs485_silence_reset(
|
||||
void)
|
||||
{
|
||||
timer_elapsed_start(&Silence_Timer);
|
||||
}
|
||||
@@ -68,7 +69,8 @@ void rs485_silence_reset(void)
|
||||
* Returns: true if the amount of time has elapsed
|
||||
* Notes: none
|
||||
**************************************************************************/
|
||||
bool rs485_silence_elapsed(uint32_t interval)
|
||||
bool rs485_silence_elapsed(
|
||||
uint32_t interval)
|
||||
{
|
||||
return timer_elapsed_milliseconds(&Silence_Timer, interval);
|
||||
}
|
||||
@@ -95,9 +97,7 @@ static uint16_t rs485_turnaround_time(
|
||||
bool rs485_turnaround_elapsed(
|
||||
void)
|
||||
{
|
||||
return timer_elapsed_milliseconds(
|
||||
&Silence_Timer,
|
||||
rs485_turnaround_time());
|
||||
return timer_elapsed_milliseconds(&Silence_Timer, rs485_turnaround_time());
|
||||
}
|
||||
|
||||
|
||||
@@ -112,20 +112,21 @@ bool rs485_receive_error(
|
||||
return false;
|
||||
}
|
||||
|
||||
/*********************************************************************//**
|
||||
/*********************************************************************//**
|
||||
* @brief USARTx interrupt handler sub-routine
|
||||
* @param[in] None
|
||||
* @return None
|
||||
**********************************************************************/
|
||||
void USART2_IRQHandler(void)
|
||||
void USART2_IRQHandler(
|
||||
void)
|
||||
{
|
||||
uint8_t data_byte;
|
||||
|
||||
|
||||
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) {
|
||||
if (USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) {
|
||||
/* Read one byte from the receive data register */
|
||||
data_byte = USART_ReceiveData(USART2);
|
||||
(void)FIFO_Put(&Receive_Buffer, data_byte);
|
||||
(void) FIFO_Put(&Receive_Buffer, data_byte);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +138,7 @@ void USART2_IRQHandler(void)
|
||||
bool rs485_byte_available(
|
||||
uint8_t * data_register)
|
||||
{
|
||||
bool data_available = false; /* return value */
|
||||
bool data_available = false; /* return value */
|
||||
|
||||
if (!FIFO_Empty(&Receive_Buffer)) {
|
||||
*data_register = FIFO_Get(&Receive_Buffer);
|
||||
@@ -154,7 +155,8 @@ bool rs485_byte_available(
|
||||
* RETURN: nothing
|
||||
* NOTES: none
|
||||
**************************************************************************/
|
||||
void rs485_byte_send(uint8_t tx_byte)
|
||||
void rs485_byte_send(
|
||||
uint8_t tx_byte)
|
||||
{
|
||||
led_tx_on_interval(10);
|
||||
USART_SendData(USART2, tx_byte);
|
||||
@@ -167,7 +169,8 @@ void rs485_byte_send(uint8_t tx_byte)
|
||||
* Returns: true if the USART register is empty
|
||||
* Notes: none
|
||||
**************************************************************************/
|
||||
bool rs485_byte_sent(void)
|
||||
bool rs485_byte_sent(
|
||||
void)
|
||||
{
|
||||
return USART_GetFlagStatus(USART2, USART_FLAG_TXE);
|
||||
}
|
||||
@@ -177,7 +180,8 @@ bool rs485_byte_sent(void)
|
||||
* Returns: true if the USART FIFO is empty
|
||||
* Notes: none
|
||||
**************************************************************************/
|
||||
bool rs485_frame_sent(void)
|
||||
bool rs485_frame_sent(
|
||||
void)
|
||||
{
|
||||
return USART_GetFlagStatus(USART2, USART_FLAG_TC);
|
||||
}
|
||||
@@ -188,9 +192,9 @@ bool rs485_frame_sent(void)
|
||||
* NOTES: none
|
||||
**************************************************************************/
|
||||
void rs485_bytes_send(
|
||||
uint8_t * buffer, /* data to send */
|
||||
uint16_t nbytes) /* number of bytes of data */
|
||||
{
|
||||
uint8_t * buffer, /* data to send */
|
||||
uint16_t nbytes)
|
||||
{ /* number of bytes of data */
|
||||
uint8_t tx_byte;
|
||||
|
||||
while (nbytes) {
|
||||
@@ -295,7 +299,8 @@ void rs485_rts_enable(
|
||||
* Returns: nothing
|
||||
* Notes: none
|
||||
**************************************************************************/
|
||||
void rs485_init(void)
|
||||
void rs485_init(
|
||||
void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
@@ -335,6 +340,6 @@ void rs485_init(void)
|
||||
USART_Cmd(USART2, ENABLE);
|
||||
|
||||
FIFO_Init(&Receive_Buffer, &Receive_Buffer_Data[0],
|
||||
(unsigned)sizeof(Receive_Buffer_Data));
|
||||
(unsigned) sizeof(Receive_Buffer_Data));
|
||||
timer_elapsed_start(&Silence_Timer);
|
||||
}
|
||||
|
||||
@@ -52,13 +52,17 @@ extern "C" {
|
||||
/* a granular approach */
|
||||
void rs485_byte_send(
|
||||
uint8_t data_register);
|
||||
bool rs485_byte_sent(void);
|
||||
bool rs485_frame_sent(void);
|
||||
bool rs485_byte_sent(
|
||||
void);
|
||||
bool rs485_frame_sent(
|
||||
void);
|
||||
bool rs485_turnaround_elapsed(
|
||||
void);
|
||||
|
||||
void rs485_silence_reset(void);
|
||||
bool rs485_silence_elapsed(uint32_t interval);
|
||||
void rs485_silence_reset(
|
||||
void);
|
||||
bool rs485_silence_elapsed(
|
||||
uint32_t interval);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
#include "stm32f10x_tim.h"
|
||||
#include "stm32f10x_usart.h"
|
||||
#include "stm32f10x_wwdg.h"
|
||||
#include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */
|
||||
#include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
@@ -62,11 +62,13 @@
|
||||
* If expr is true, it returns no value.
|
||||
* @retval None
|
||||
*/
|
||||
#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
|
||||
#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void assert_failed(uint8_t* file, uint32_t line);
|
||||
void assert_failed(
|
||||
uint8_t * file,
|
||||
uint32_t line);
|
||||
#else
|
||||
#define assert_param(expr) ((void)0)
|
||||
#define assert_param(expr) ((void)0)
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
#endif /* __STM32F10x_CONF_H */
|
||||
|
||||
@@ -47,7 +47,8 @@
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void NMI_Handler(void)
|
||||
void NMI_Handler(
|
||||
void)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -56,12 +57,12 @@ void NMI_Handler(void)
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void HardFault_Handler(void)
|
||||
void HardFault_Handler(
|
||||
void)
|
||||
{
|
||||
/* Go to infinite loop when Hard Fault exception occurs */
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
/* Go to infinite loop when Hard Fault exception occurs */
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,12 +70,12 @@ void HardFault_Handler(void)
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void MemManage_Handler(void)
|
||||
void MemManage_Handler(
|
||||
void)
|
||||
{
|
||||
/* Go to infinite loop when Memory Manage exception occurs */
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
/* Go to infinite loop when Memory Manage exception occurs */
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,12 +83,12 @@ void MemManage_Handler(void)
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void BusFault_Handler(void)
|
||||
void BusFault_Handler(
|
||||
void)
|
||||
{
|
||||
/* Go to infinite loop when Bus Fault exception occurs */
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
/* Go to infinite loop when Bus Fault exception occurs */
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,12 +96,12 @@ void BusFault_Handler(void)
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void UsageFault_Handler(void)
|
||||
void UsageFault_Handler(
|
||||
void)
|
||||
{
|
||||
/* Go to infinite loop when Usage Fault exception occurs */
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
/* Go to infinite loop when Usage Fault exception occurs */
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,7 +109,8 @@ void UsageFault_Handler(void)
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SVC_Handler(void)
|
||||
void SVC_Handler(
|
||||
void)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -117,7 +119,8 @@ void SVC_Handler(void)
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void DebugMon_Handler(void)
|
||||
void DebugMon_Handler(
|
||||
void)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -126,7 +129,8 @@ void DebugMon_Handler(void)
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void PendSV_Handler(void)
|
||||
void PendSV_Handler(
|
||||
void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -30,14 +30,22 @@
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
|
||||
void NMI_Handler(void);
|
||||
void HardFault_Handler(void);
|
||||
void MemManage_Handler(void);
|
||||
void BusFault_Handler(void);
|
||||
void UsageFault_Handler(void);
|
||||
void SVC_Handler(void);
|
||||
void DebugMon_Handler(void);
|
||||
void PendSV_Handler(void);
|
||||
void NMI_Handler(
|
||||
void);
|
||||
void HardFault_Handler(
|
||||
void);
|
||||
void MemManage_Handler(
|
||||
void);
|
||||
void BusFault_Handler(
|
||||
void);
|
||||
void UsageFault_Handler(
|
||||
void);
|
||||
void SVC_Handler(
|
||||
void);
|
||||
void DebugMon_Handler(
|
||||
void);
|
||||
void PendSV_Handler(
|
||||
void);
|
||||
|
||||
#endif /* __STM32F10x_IT_H */
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -61,7 +61,8 @@ static void timer_debug_off(
|
||||
* Returns: none
|
||||
* Notes: none
|
||||
*************************************************************************/
|
||||
void timer_debug_toggle(void)
|
||||
void timer_debug_toggle(
|
||||
void)
|
||||
{
|
||||
static bool state = false;
|
||||
|
||||
@@ -79,7 +80,8 @@ void timer_debug_toggle(void)
|
||||
* Returns: nothing
|
||||
* Notes: reserved name for ISR handlers
|
||||
*************************************************************************/
|
||||
void SysTick_Handler(void)
|
||||
void SysTick_Handler(
|
||||
void)
|
||||
{
|
||||
/* increment the tick count */
|
||||
Millisecond_Counter++;
|
||||
@@ -91,7 +93,8 @@ void SysTick_Handler(void)
|
||||
* Returns: none
|
||||
* Notes: none
|
||||
*************************************************************************/
|
||||
uint32_t timer_milliseconds(void)
|
||||
uint32_t timer_milliseconds(
|
||||
void)
|
||||
{
|
||||
return Millisecond_Counter;
|
||||
}
|
||||
@@ -101,7 +104,8 @@ uint32_t timer_milliseconds(void)
|
||||
* Returns: none
|
||||
* Notes: peripheral frequency defined in hardware.h
|
||||
*************************************************************************/
|
||||
void timer_init(void)
|
||||
void timer_init(
|
||||
void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ static object_functions_t Object_Table[] = {
|
||||
#if defined(BACFILE)
|
||||
{FILE_OBJ_FUNCTIONS},
|
||||
#endif
|
||||
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
||||
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
||||
};
|
||||
|
||||
/* buffer used for receive */
|
||||
@@ -189,7 +189,7 @@ static void LocalIAmHandler(
|
||||
static void Init_Service_Handlers(
|
||||
void)
|
||||
{
|
||||
Device_Initialize_Object_Functions(&Object_Table[0]);
|
||||
Device_Initialize_Object_Functions(&Object_Table[0]);
|
||||
Device_Init();
|
||||
|
||||
/* we need to handle who-is to support dynamic device binding */
|
||||
|
||||
@@ -38,9 +38,9 @@
|
||||
/* Offset between Windows epoch 1/1/1601 and
|
||||
Unix epoch 1/1/1970 in 100 nanosec units */
|
||||
#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
|
||||
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
|
||||
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
|
||||
#else
|
||||
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
|
||||
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
|
||||
#endif
|
||||
|
||||
/* counter for the various timers */
|
||||
@@ -81,16 +81,16 @@ int gettimeofday(
|
||||
usec_timer <<= 32;
|
||||
usec_timer |= ft.dwLowDateTime;
|
||||
/*converting file time to unix epoch 1970 */
|
||||
usec_timer /= 10; /*convert into microseconds*/
|
||||
usec_timer /= 10; /*convert into microseconds */
|
||||
usec_timer -= DELTA_EPOCH_IN_MICROSECS;
|
||||
tp->tv_sec = (long)(usec_timer / 1000000UL);
|
||||
tp->tv_usec = (long)(usec_timer % 1000000UL);
|
||||
tp->tv_sec = (long) (usec_timer / 1000000UL);
|
||||
tp->tv_usec = (long) (usec_timer % 1000000UL);
|
||||
time_start = timeGetTime();
|
||||
} else {
|
||||
elapsed_milliseconds = timeGetTime() - time_start;
|
||||
usec_elapsed = usec_timer + (elapsed_milliseconds * 1000UL);
|
||||
tp->tv_sec = (long)(usec_elapsed / 1000000UL);
|
||||
tp->tv_usec = (long)(usec_elapsed % 1000000UL);
|
||||
tp->tv_sec = (long) (usec_elapsed / 1000000UL);
|
||||
tp->tv_usec = (long) (usec_elapsed % 1000000UL);
|
||||
}
|
||||
if (tzp) {
|
||||
if (!tzflag) {
|
||||
@@ -207,8 +207,9 @@ void timer_init(
|
||||
/* configure for 1ms resolution - if possible */
|
||||
Timer_Period = min(max(tc.wPeriodMin, 1L), tc.wPeriodMax);
|
||||
if (Timer_Period != 1L) {
|
||||
fprintf(stderr, "Failed to set timer to 1ms. "
|
||||
"Time period set to %ums\n", (unsigned)Timer_Period);
|
||||
fprintf(stderr,
|
||||
"Failed to set timer to 1ms. " "Time period set to %ums\n",
|
||||
(unsigned) Timer_Period);
|
||||
}
|
||||
timeBeginPeriod(Timer_Period);
|
||||
atexit(timer_cleanup);
|
||||
@@ -234,7 +235,7 @@ int main(
|
||||
{
|
||||
long now = 0, last = 0, delta = 0;
|
||||
struct timeval tv;
|
||||
struct timeval old_tv = {0};
|
||||
struct timeval old_tv = { 0 };
|
||||
|
||||
timer_init();
|
||||
printf("Testing granularity of timeGetTime()...\n");
|
||||
|
||||
Reference in New Issue
Block a user