indented using indent.sh script to get uniform looking code for release
This commit is contained in:
@@ -367,8 +367,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
|
||||
|
||||
@@ -278,8 +278,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;
|
||||
|
||||
@@ -855,8 +855,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 {
|
||||
@@ -908,13 +908,13 @@ bool Device_Write_Property_Local(
|
||||
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)) {
|
||||
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);
|
||||
status = true;
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -303,7 +303,7 @@ static void Timer0IrqHandler(
|
||||
{
|
||||
|
||||
volatile AT91PS_TC pTC = AT91C_BASE_TC0; /* pointer to timer channel 0 register structure */
|
||||
volatile unsigned int dummy; /* temporary */
|
||||
volatile unsigned int dummy; /* temporary */
|
||||
|
||||
/* read TC0 Status Register to clear interrupt */
|
||||
dummy = pTC->TC_SR;
|
||||
|
||||
@@ -218,8 +218,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;
|
||||
|
||||
@@ -386,8 +386,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;
|
||||
|
||||
@@ -169,13 +169,11 @@ int Analog_Input_Read_Property(
|
||||
case PROP_OBJECT_NAME:
|
||||
Analog_Input_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:
|
||||
apdu_len =
|
||||
encode_application_enumerated(&apdu[0],
|
||||
rpdata->object_type);
|
||||
encode_application_enumerated(&apdu[0], rpdata->object_type);
|
||||
break;
|
||||
case PROP_PRESENT_VALUE:
|
||||
apdu_len =
|
||||
|
||||
@@ -221,13 +221,11 @@ int Analog_Value_Read_Property(
|
||||
case PROP_OBJECT_NAME:
|
||||
Analog_Value_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:
|
||||
apdu_len =
|
||||
encode_application_enumerated(&apdu[0],
|
||||
rpdata->object_type);
|
||||
encode_application_enumerated(&apdu[0], rpdata->object_type);
|
||||
break;
|
||||
case PROP_PRESENT_VALUE:
|
||||
real_value = Analog_Value_Present_Value(rpdata->object_instance);
|
||||
|
||||
@@ -65,7 +65,8 @@ static bool seeprom_version_test(
|
||||
|
||||
rv = seeprom_bytes_read(NV_SEEPROM_TYPE_0, (uint8_t *) & id, 2);
|
||||
if (rv > 0) {
|
||||
rv = seeprom_bytes_read(NV_SEEPROM_VERSION_0, (uint8_t *) & version, 2);
|
||||
rv = seeprom_bytes_read(NV_SEEPROM_VERSION_0, (uint8_t *) & version,
|
||||
2);
|
||||
}
|
||||
|
||||
if ((rv > 0) && (id == SEEPROM_ID) && (version == SEEPROM_VERSION)) {
|
||||
|
||||
@@ -178,10 +178,10 @@ int Binary_Input_Read_Property(
|
||||
BACNET_READ_PROPERTY_DATA * rpdata)
|
||||
{
|
||||
int apdu_len = 0; /* return value */
|
||||
BACNET_BIT_STRING bit_string = {0};
|
||||
BACNET_BIT_STRING bit_string = { 0 };
|
||||
BACNET_POLARITY polarity = POLARITY_NORMAL;
|
||||
BACNET_BINARY_PV value = BINARY_INACTIVE;
|
||||
BACNET_CHARACTER_STRING char_string = {0};
|
||||
BACNET_CHARACTER_STRING char_string = { 0 };
|
||||
uint8_t *apdu = NULL;
|
||||
|
||||
if ((rpdata->application_data == NULL) ||
|
||||
@@ -198,13 +198,11 @@ int Binary_Input_Read_Property(
|
||||
case PROP_OBJECT_NAME:
|
||||
Binary_Input_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:
|
||||
apdu_len =
|
||||
encode_application_enumerated(&apdu[0],
|
||||
rpdata->object_type);
|
||||
encode_application_enumerated(&apdu[0], rpdata->object_type);
|
||||
break;
|
||||
case PROP_PRESENT_VALUE:
|
||||
value = Binary_Input_Present_Value(rpdata->object_instance);
|
||||
|
||||
@@ -250,8 +250,8 @@ int Binary_Output_Read_Property(
|
||||
{
|
||||
int len = 0;
|
||||
int apdu_len = 0; /* return value */
|
||||
BACNET_BIT_STRING bit_string = {0};
|
||||
BACNET_CHARACTER_STRING char_string = {0};
|
||||
BACNET_BIT_STRING bit_string = { 0 };
|
||||
BACNET_CHARACTER_STRING char_string = { 0 };
|
||||
BACNET_BINARY_PV present_value = BINARY_INACTIVE;
|
||||
unsigned object_index = 0;
|
||||
unsigned i = 0;
|
||||
@@ -272,13 +272,11 @@ int Binary_Output_Read_Property(
|
||||
case PROP_OBJECT_NAME:
|
||||
Binary_Output_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:
|
||||
apdu_len =
|
||||
encode_application_enumerated(&apdu[0],
|
||||
rpdata->object_type);
|
||||
encode_application_enumerated(&apdu[0], rpdata->object_type);
|
||||
break;
|
||||
case PROP_PRESENT_VALUE:
|
||||
present_value =
|
||||
@@ -461,8 +459,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
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
#if (__GNUC__ <= 4) && (__GNUC_MINOR__ < 3)
|
||||
|
||||
#if !defined(EEWE) && defined(EEPE)
|
||||
# define EEWE EEPE
|
||||
#define EEWE EEPE
|
||||
#endif
|
||||
|
||||
#if !defined(EEMWE) && defined(EEMPE)
|
||||
# define EEMWE EEMPE
|
||||
#define EEMWE EEMPE
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -20,55 +20,55 @@
|
||||
#if defined(__ICCAVR__)
|
||||
|
||||
/* IAR Embedded Workbench */
|
||||
# include <inavr.h>
|
||||
#include <inavr.h>
|
||||
|
||||
# define _GET_LOCK_BITS() __AddrToZByteToSPMCR_LPM( (void __flash *) 0x0001, 0x09 )
|
||||
# define _GET_LOW_FUSES() __AddrToZByteToSPMCR_LPM( (void __flash *) 0x0000, 0x09 )
|
||||
# define _GET_HIGH_FUSES() __AddrToZByteToSPMCR_LPM( (void __flash *) 0x0003, 0x09 )
|
||||
# define _GET_EXTENDED_FUSES() __AddrToZByteToSPMCR_LPM( (void __flash *) 0x0002, 0x09 )
|
||||
# define _SET_LOCK_BITS(data) __DataToR0ByteToSPMCR_SPM( data, 0x09 )
|
||||
# define _ENABLE_RWW_SECTION() __DataToR0ByteToSPMCR_SPM( 0x00, 0x11 )
|
||||
#define _GET_LOCK_BITS() __AddrToZByteToSPMCR_LPM( (void __flash *) 0x0001, 0x09 )
|
||||
#define _GET_LOW_FUSES() __AddrToZByteToSPMCR_LPM( (void __flash *) 0x0000, 0x09 )
|
||||
#define _GET_HIGH_FUSES() __AddrToZByteToSPMCR_LPM( (void __flash *) 0x0003, 0x09 )
|
||||
#define _GET_EXTENDED_FUSES() __AddrToZByteToSPMCR_LPM( (void __flash *) 0x0002, 0x09 )
|
||||
#define _SET_LOCK_BITS(data) __DataToR0ByteToSPMCR_SPM( data, 0x09 )
|
||||
#define _ENABLE_RWW_SECTION() __DataToR0ByteToSPMCR_SPM( 0x00, 0x11 )
|
||||
|
||||
# define _WAIT_FOR_SPM() while( SPMCR_REG & (1<<SPMEN) );
|
||||
#define _WAIT_FOR_SPM() while( SPMCR_REG & (1<<SPMEN) );
|
||||
|
||||
# ifndef LARGE_MEMORY
|
||||
# define _LOAD_PROGRAM_MEMORY(addr) __load_program_memory( (const unsigned char __flash *) (addr) )
|
||||
# define _FILL_TEMP_WORD(addr,data) __AddrToZWordToR1R0ByteToSPMCR_SPM( (void __flash *) (addr), data, 0x01 )
|
||||
# define _PAGE_ERASE(addr) __AddrToZByteToSPMCR_SPM( (void __flash *) (addr), 0x03 )
|
||||
# define _PAGE_WRITE(addr) __AddrToZByteToSPMCR_SPM( (void __flash *) (addr), 0x05 )
|
||||
# else /* LARGE_MEMORY */
|
||||
# define _LOAD_PROGRAM_MEMORY(addr) __extended_load_program_memory( (const unsigned char __farflash *) (addr) )
|
||||
# define _FILL_TEMP_WORD(addr,data) __AddrToZ24WordToR1R0ByteToSPMCR_SPM( (void __farflash *) (addr), data, 0x01 )
|
||||
# define _PAGE_ERASE(addr) __AddrToZ24ByteToSPMCR_SPM( (void __farflash *) (addr), 0x03 )
|
||||
# define _PAGE_WRITE(addr) __AddrToZ24ByteToSPMCR_SPM( (void __farflash *) (addr), 0x05 )
|
||||
# endif /* LARGE_MEMORY */
|
||||
#ifndef LARGE_MEMORY
|
||||
#define _LOAD_PROGRAM_MEMORY(addr) __load_program_memory( (const unsigned char __flash *) (addr) )
|
||||
#define _FILL_TEMP_WORD(addr,data) __AddrToZWordToR1R0ByteToSPMCR_SPM( (void __flash *) (addr), data, 0x01 )
|
||||
#define _PAGE_ERASE(addr) __AddrToZByteToSPMCR_SPM( (void __flash *) (addr), 0x03 )
|
||||
#define _PAGE_WRITE(addr) __AddrToZByteToSPMCR_SPM( (void __flash *) (addr), 0x05 )
|
||||
#else /* LARGE_MEMORY */
|
||||
#define _LOAD_PROGRAM_MEMORY(addr) __extended_load_program_memory( (const unsigned char __farflash *) (addr) )
|
||||
#define _FILL_TEMP_WORD(addr,data) __AddrToZ24WordToR1R0ByteToSPMCR_SPM( (void __farflash *) (addr), data, 0x01 )
|
||||
#define _PAGE_ERASE(addr) __AddrToZ24ByteToSPMCR_SPM( (void __farflash *) (addr), 0x03 )
|
||||
#define _PAGE_WRITE(addr) __AddrToZ24ByteToSPMCR_SPM( (void __farflash *) (addr), 0x05 )
|
||||
#endif /* LARGE_MEMORY */
|
||||
|
||||
#elif __GNUC__ > 0
|
||||
|
||||
/* AVR-GCC/avr-libc */
|
||||
# include <avr/boot.h>
|
||||
# include <avr/pgmspace.h>
|
||||
#include <avr/boot.h>
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
# if defined(GET_LOCK_BITS) /* avr-libc >= 1.2.5 */
|
||||
# define _GET_LOCK_BITS() boot_lock_fuse_bits_get(GET_LOCK_BITS)
|
||||
# define _GET_LOW_FUSES() boot_lock_fuse_bits_get(GET_LOW_FUSE_BITS)
|
||||
# define _GET_HIGH_FUSES() boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS)
|
||||
# define _GET_EXTENDED_FUSES() boot_lock_fuse_bits_get(GET_EXTENDED_FUSE_BITS)
|
||||
# endif /* defined(GET_LOCK_BITS) */
|
||||
# define _SET_LOCK_BITS(data) boot_lock_bits_set(~data)
|
||||
# define _ENABLE_RWW_SECTION() boot_rww_enable()
|
||||
#if defined(GET_LOCK_BITS) /* avr-libc >= 1.2.5 */
|
||||
#define _GET_LOCK_BITS() boot_lock_fuse_bits_get(GET_LOCK_BITS)
|
||||
#define _GET_LOW_FUSES() boot_lock_fuse_bits_get(GET_LOW_FUSE_BITS)
|
||||
#define _GET_HIGH_FUSES() boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS)
|
||||
#define _GET_EXTENDED_FUSES() boot_lock_fuse_bits_get(GET_EXTENDED_FUSE_BITS)
|
||||
#endif /* defined(GET_LOCK_BITS) */
|
||||
#define _SET_LOCK_BITS(data) boot_lock_bits_set(~data)
|
||||
#define _ENABLE_RWW_SECTION() boot_rww_enable()
|
||||
|
||||
# define _WAIT_FOR_SPM() boot_spm_busy_wait()
|
||||
#define _WAIT_FOR_SPM() boot_spm_busy_wait()
|
||||
|
||||
# ifndef LARGE_MEMORY
|
||||
# define _LOAD_PROGRAM_MEMORY(addr) pgm_read_byte_near(addr)
|
||||
# else /* LARGE_MEMORY */
|
||||
# define _LOAD_PROGRAM_MEMORY(addr) pgm_read_byte_far(addr)
|
||||
# endif /* LARGE_MEMORY */
|
||||
# define _FILL_TEMP_WORD(addr,data) boot_page_fill(addr, data)
|
||||
# define _PAGE_ERASE(addr) boot_page_erase(addr)
|
||||
# define _PAGE_WRITE(addr) boot_page_write(addr)
|
||||
#ifndef LARGE_MEMORY
|
||||
#define _LOAD_PROGRAM_MEMORY(addr) pgm_read_byte_near(addr)
|
||||
#else /* LARGE_MEMORY */
|
||||
#define _LOAD_PROGRAM_MEMORY(addr) pgm_read_byte_far(addr)
|
||||
#endif /* LARGE_MEMORY */
|
||||
#define _FILL_TEMP_WORD(addr,data) boot_page_fill(addr, data)
|
||||
#define _PAGE_ERASE(addr) boot_page_erase(addr)
|
||||
#define _PAGE_WRITE(addr) boot_page_write(addr)
|
||||
|
||||
#else
|
||||
# error "Don't know your compiler."
|
||||
#error "Don't know your compiler."
|
||||
#endif
|
||||
|
||||
@@ -46,9 +46,9 @@
|
||||
* smaller devices.
|
||||
*/
|
||||
#ifdef LARGE_MEMORY
|
||||
# define ADDR_T unsigned long
|
||||
#define ADDR_T unsigned long
|
||||
#else /* !LARGE_MEMORY */
|
||||
# define ADDR_T unsigned int
|
||||
#define ADDR_T unsigned int
|
||||
#endif /* LARGE_MEMORY */
|
||||
|
||||
#ifndef REMOVE_BLOCK_SUPPORT
|
||||
|
||||
@@ -561,8 +561,8 @@ int Device_Read_Property_Local(
|
||||
{
|
||||
int apdu_len = 0; /* return value */
|
||||
int len = 0; /* apdu len intermediate value */
|
||||
BACNET_BIT_STRING bit_string = {0};
|
||||
BACNET_CHARACTER_STRING char_string = {0};
|
||||
BACNET_BIT_STRING bit_string = { 0 };
|
||||
BACNET_CHARACTER_STRING char_string = { 0 };
|
||||
unsigned i = 0;
|
||||
int object_type = 0;
|
||||
uint32_t instance = 0;
|
||||
@@ -575,7 +575,7 @@ int Device_Read_Property_Local(
|
||||
return 0;
|
||||
}
|
||||
apdu = rpdata->application_data;
|
||||
switch ((int)rpdata->object_property) {
|
||||
switch ((int) rpdata->object_property) {
|
||||
case PROP_OBJECT_IDENTIFIER:
|
||||
apdu_len =
|
||||
encode_application_object_id(&apdu[0], rpdata->object_type,
|
||||
@@ -584,13 +584,11 @@ int Device_Read_Property_Local(
|
||||
case PROP_OBJECT_NAME:
|
||||
Device_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:
|
||||
apdu_len =
|
||||
encode_application_enumerated(&apdu[0],
|
||||
rpdata->object_type);
|
||||
encode_application_enumerated(&apdu[0], rpdata->object_type);
|
||||
break;
|
||||
case PROP_DESCRIPTION:
|
||||
bacnet_name(NV_EEPROM_DEVICE_DESCRIPTION, &char_string,
|
||||
@@ -801,12 +799,12 @@ bool Device_Write_Property_Local(
|
||||
wp_data->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
|
||||
return false;
|
||||
}
|
||||
switch ((int)wp_data->object_property) {
|
||||
switch ((int) wp_data->object_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))) {
|
||||
eeprom_bytes_write(NV_EEPROM_DEVICE_0,
|
||||
(uint8_t *) & value.type.Object_Id.instance, 4);
|
||||
/* we could send an I-Am broadcast to let the world know */
|
||||
@@ -855,10 +853,8 @@ bool Device_Write_Property_Local(
|
||||
if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) {
|
||||
status =
|
||||
bacnet_name_write_unique(NV_EEPROM_DEVICE_NAME,
|
||||
wp_data->object_type,
|
||||
wp_data->object_instance,
|
||||
&value.type.Character_String,
|
||||
&wp_data->error_class,
|
||||
wp_data->object_type, wp_data->object_instance,
|
||||
&value.type.Character_String, &wp_data->error_class,
|
||||
&wp_data->error_code);
|
||||
} else {
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
|
||||
@@ -1129,8 +1129,8 @@ static bool MSTP_Master_Node_FSM(
|
||||
if (pkt != NULL) {
|
||||
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);
|
||||
} else {
|
||||
matched = false;
|
||||
}
|
||||
@@ -1146,10 +1146,12 @@ static bool MSTP_Master_Node_FSM(
|
||||
if (pkt->data_expecting_reply) {
|
||||
frame_type = FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY;
|
||||
} else {
|
||||
frame_type = FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY;
|
||||
frame_type =
|
||||
FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY;
|
||||
}
|
||||
MSTP_Send_Frame(frame_type, pkt->destination_mac, This_Station,
|
||||
(uint8_t *) & pkt->buffer[0], pkt->length);
|
||||
MSTP_Send_Frame(frame_type, pkt->destination_mac,
|
||||
This_Station, (uint8_t *) & pkt->buffer[0],
|
||||
pkt->length);
|
||||
Master_State = MSTP_MASTER_STATE_IDLE;
|
||||
/* clear our flag we were holding for comparison */
|
||||
MSTP_Flag.ReceivedValidFrame = false;
|
||||
@@ -1354,4 +1356,3 @@ void dlmstp_get_broadcast_address(
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -330,12 +330,12 @@ unsigned char __uint8_eeprom_load(
|
||||
#define power_timer2_enable() (PRR0 &= (uint8_t)~(1 << PRTIM2))
|
||||
#endif
|
||||
#if (defined(__GNUC__) && ((__GNUC__ == 4) && (__GNUC_MINOR__ < 5)))
|
||||
#if defined(__AVR_ATmega644P__)
|
||||
#if defined(__AVR_ATmega644P__)
|
||||
/* bug in WinAVR - fixed in later versions */
|
||||
#define power_usart1_enable() (PRR &= (uint8_t)~(1 << PRUSART1))
|
||||
#elif defined(__AVR_ATmega1284P__)
|
||||
#define power_usart1_enable() (PRR0 &= (uint8_t)~(1 << PRUSART1))
|
||||
#endif
|
||||
#define power_usart1_enable() (PRR &= (uint8_t)~(1 << PRUSART1))
|
||||
#elif defined(__AVR_ATmega1284P__)
|
||||
#define power_usart1_enable() (PRR0 &= (uint8_t)~(1 << PRUSART1))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__CROSSWORKS_AVR)
|
||||
|
||||
@@ -43,14 +43,13 @@
|
||||
|
||||
bool BIP_Debug = true;
|
||||
|
||||
void *
|
||||
get_addr_ptr (struct sockaddr * sockaddr_ptr)
|
||||
void *get_addr_ptr(
|
||||
struct sockaddr *sockaddr_ptr)
|
||||
{
|
||||
void * addr_ptr;
|
||||
void *addr_ptr;
|
||||
if (sockaddr_ptr->sa_family == AF_INET) {
|
||||
addr_ptr = &((struct sockaddr_in *) sockaddr_ptr)->sin_addr;
|
||||
}
|
||||
else if (sockaddr_ptr->sa_family == AF_INET6) {
|
||||
addr_ptr = &((struct sockaddr_in *) sockaddr_ptr)->sin_addr;
|
||||
} else if (sockaddr_ptr->sa_family == AF_INET6) {
|
||||
addr_ptr = &((struct sockaddr_in6 *) sockaddr_ptr)->sin6_addr;
|
||||
}
|
||||
return addr_ptr;
|
||||
@@ -81,41 +80,41 @@ long bip_getaddrbyname(
|
||||
* @param request [in] addr broadaddr netmask
|
||||
*/
|
||||
static int get_local_address(
|
||||
char *ifname,struct in_addr *addr,char *request)
|
||||
char *ifname,
|
||||
struct in_addr *addr,
|
||||
char *request)
|
||||
{
|
||||
|
||||
char rv; /* return value */
|
||||
char rv; /* return value */
|
||||
|
||||
struct ifaddrs * ifaddrs_ptr;
|
||||
struct ifaddrs *ifaddrs_ptr;
|
||||
int status;
|
||||
status = getifaddrs (& ifaddrs_ptr);
|
||||
status = getifaddrs(&ifaddrs_ptr);
|
||||
if (status == -1) {
|
||||
fprintf (stderr, "Error in 'getifaddrs': %d (%s)\n",
|
||||
errno, strerror (errno));
|
||||
fprintf(stderr, "Error in 'getifaddrs': %d (%s)\n", errno,
|
||||
strerror(errno));
|
||||
}
|
||||
while (ifaddrs_ptr) {
|
||||
if ((ifaddrs_ptr->ifa_addr->sa_family == AF_INET) &&
|
||||
(strcmp(ifaddrs_ptr->ifa_name, ifname) == 0)) {
|
||||
void * addr_ptr;
|
||||
if (! ifaddrs_ptr->ifa_addr) {
|
||||
return rv;
|
||||
}
|
||||
if (strcmp(request, "addr") == 0) {
|
||||
addr_ptr = get_addr_ptr (ifaddrs_ptr->ifa_addr);
|
||||
}
|
||||
else if (strcmp(request, "broadaddr") == 0) {
|
||||
addr_ptr = get_addr_ptr (ifaddrs_ptr->ifa_broadaddr);
|
||||
}
|
||||
else if (strcmp(request, "netmask") == 0) {
|
||||
addr_ptr = get_addr_ptr (ifaddrs_ptr->ifa_netmask);
|
||||
}
|
||||
if (addr_ptr) {
|
||||
memcpy(addr, addr_ptr, sizeof(struct in_addr));
|
||||
}
|
||||
if ((ifaddrs_ptr->ifa_addr->sa_family == AF_INET) &&
|
||||
(strcmp(ifaddrs_ptr->ifa_name, ifname) == 0)) {
|
||||
void *addr_ptr;
|
||||
if (!ifaddrs_ptr->ifa_addr) {
|
||||
return rv;
|
||||
}
|
||||
ifaddrs_ptr = ifaddrs_ptr->ifa_next;
|
||||
if (strcmp(request, "addr") == 0) {
|
||||
addr_ptr = get_addr_ptr(ifaddrs_ptr->ifa_addr);
|
||||
} else if (strcmp(request, "broadaddr") == 0) {
|
||||
addr_ptr = get_addr_ptr(ifaddrs_ptr->ifa_broadaddr);
|
||||
} else if (strcmp(request, "netmask") == 0) {
|
||||
addr_ptr = get_addr_ptr(ifaddrs_ptr->ifa_netmask);
|
||||
}
|
||||
if (addr_ptr) {
|
||||
memcpy(addr, addr_ptr, sizeof(struct in_addr));
|
||||
}
|
||||
}
|
||||
ifaddrs_ptr = ifaddrs_ptr->ifa_next;
|
||||
}
|
||||
freeifaddrs (ifaddrs_ptr);
|
||||
freeifaddrs(ifaddrs_ptr);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -185,7 +184,7 @@ bool bip_init(
|
||||
|
||||
if (ifname) {
|
||||
bip_set_interface(ifname);
|
||||
printf("interface %s", ifname);
|
||||
printf("interface %s", ifname);
|
||||
} else {
|
||||
bip_set_interface("en0");
|
||||
}
|
||||
@@ -258,9 +257,9 @@ int bip_get_local_netmask(
|
||||
char *ifname = getenv("BACNET_IFACE"); /* will probably be null */
|
||||
if (ifname == NULL)
|
||||
ifname = "en0";
|
||||
printf("ifname %s",ifname);
|
||||
printf("ifname %s", ifname);
|
||||
char *request = "netmask";
|
||||
rv = get_local_address(ifname, netmask, request);
|
||||
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -46,28 +46,28 @@
|
||||
#include <sys/un.h> /* for Unix domain sockets */
|
||||
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
# include <sys/select.h> /* for convenience */
|
||||
#include <sys/select.h> /* for convenience */
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_POLL_H
|
||||
# include <poll.h> /* for convenience */
|
||||
#include <poll.h> /* for convenience */
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STRINGS_H
|
||||
# include <strings.h> /* for convenience */
|
||||
#include <strings.h> /* for convenience */
|
||||
#endif
|
||||
|
||||
/* Three headers are normally needed for socket/file ioctl's:
|
||||
* <sys/ioctl.h>, <sys/filio.h>, and <sys/sockio.h>.
|
||||
*/
|
||||
#ifdef HAVE_SYS_IOCTL_H
|
||||
# include <sys/ioctl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_FILIO_H
|
||||
# include <sys/filio.h>
|
||||
#include <sys/filio.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_SOCKIO_H
|
||||
# include <sys/sockio.h>
|
||||
#include <sys/sockio.h>
|
||||
#endif
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
@@ -100,7 +100,7 @@ static uint8_t Tusage_timeout = 60;
|
||||
static struct timeval start;
|
||||
|
||||
static uint32_t Timer_Silence(
|
||||
void * pArg)
|
||||
void *pArg)
|
||||
{
|
||||
struct timeval now, tmp_diff;
|
||||
int32_t res;
|
||||
@@ -113,7 +113,7 @@ static uint32_t Timer_Silence(
|
||||
}
|
||||
|
||||
static void Timer_Silence_Reset(
|
||||
void * pArg)
|
||||
void *pArg)
|
||||
{
|
||||
gettimeofday(&start, NULL);
|
||||
}
|
||||
|
||||
@@ -49,46 +49,44 @@
|
||||
|
||||
#define INCREMENT_AND_LIMIT_UINT16(x) {if (x < 0xFFFF) x++;}
|
||||
uint32_t Timer_Silence(
|
||||
void * poPort)
|
||||
void *poPort)
|
||||
{
|
||||
struct timeval now, tmp_diff;
|
||||
SHARED_MSTP_DATA * poSharedData;
|
||||
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort;
|
||||
if(!mstp_port)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
|
||||
if(!poSharedData)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
struct timeval now, tmp_diff;
|
||||
SHARED_MSTP_DATA *poSharedData;
|
||||
struct mstp_port_struct_t *mstp_port =
|
||||
(struct mstp_port_struct_t *) poPort;
|
||||
if (!mstp_port) {
|
||||
return -1;
|
||||
}
|
||||
poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
|
||||
if (!poSharedData) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t res;
|
||||
int32_t res;
|
||||
|
||||
gettimeofday(&now, NULL);
|
||||
timersub(&poSharedData->start, &now, &tmp_diff);
|
||||
res = ((tmp_diff.tv_sec) * 1000 + (tmp_diff.tv_usec) / 1000);
|
||||
gettimeofday(&now, NULL);
|
||||
timersub(&poSharedData->start, &now, &tmp_diff);
|
||||
res = ((tmp_diff.tv_sec) * 1000 + (tmp_diff.tv_usec) / 1000);
|
||||
|
||||
return (res >= 0 ? res : -res);
|
||||
return (res >= 0 ? res : -res);
|
||||
}
|
||||
|
||||
void Timer_Silence_Reset(
|
||||
void * poPort)
|
||||
void *poPort)
|
||||
{
|
||||
SHARED_MSTP_DATA * poSharedData;
|
||||
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort;
|
||||
if(!mstp_port)
|
||||
{
|
||||
return;
|
||||
}
|
||||
poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
|
||||
if(!poSharedData)
|
||||
{
|
||||
return;
|
||||
}
|
||||
SHARED_MSTP_DATA *poSharedData;
|
||||
struct mstp_port_struct_t *mstp_port =
|
||||
(struct mstp_port_struct_t *) poPort;
|
||||
if (!mstp_port) {
|
||||
return;
|
||||
}
|
||||
poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
|
||||
if (!poSharedData) {
|
||||
return;
|
||||
}
|
||||
|
||||
gettimeofday(&poSharedData->start, NULL);
|
||||
gettimeofday(&poSharedData->start, NULL);
|
||||
}
|
||||
|
||||
void get_abstime(
|
||||
@@ -106,22 +104,22 @@ void get_abstime(
|
||||
}
|
||||
|
||||
void dlmstp_cleanup(
|
||||
void * poPort)
|
||||
void *poPort)
|
||||
{
|
||||
SHARED_MSTP_DATA * poSharedData;
|
||||
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort;
|
||||
if(!mstp_port)
|
||||
{
|
||||
return;
|
||||
}
|
||||
poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
|
||||
if(!poSharedData)
|
||||
{
|
||||
return;
|
||||
}
|
||||
SHARED_MSTP_DATA *poSharedData;
|
||||
struct mstp_port_struct_t *mstp_port =
|
||||
(struct mstp_port_struct_t *) poPort;
|
||||
if (!mstp_port) {
|
||||
return;
|
||||
}
|
||||
poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
|
||||
if (!poSharedData) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* restore the old port settings */
|
||||
tcsetattr(poSharedData->RS485_Handle, TCSANOW, &poSharedData->RS485_oldtio);
|
||||
tcsetattr(poSharedData->RS485_Handle, TCSANOW,
|
||||
&poSharedData->RS485_oldtio);
|
||||
close(poSharedData->RS485_Handle);
|
||||
|
||||
pthread_cond_destroy(&poSharedData->Received_Frame_Flag);
|
||||
@@ -134,7 +132,7 @@ void dlmstp_cleanup(
|
||||
|
||||
/* returns number of bytes sent on success, zero on failure */
|
||||
int dlmstp_send_pdu(
|
||||
void * poPort,
|
||||
void *poPort,
|
||||
BACNET_ADDRESS * dest, /* destination address */
|
||||
uint8_t * pdu, /* any data to be sent - may be null */
|
||||
unsigned pdu_len)
|
||||
@@ -142,34 +140,34 @@ int dlmstp_send_pdu(
|
||||
int bytes_sent = 0;
|
||||
struct mstp_pdu_packet *pkt;
|
||||
unsigned i = 0;
|
||||
SHARED_MSTP_DATA * poSharedData;
|
||||
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort;
|
||||
if(!mstp_port)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
|
||||
if(!poSharedData)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
SHARED_MSTP_DATA *poSharedData;
|
||||
struct mstp_port_struct_t *mstp_port =
|
||||
(struct mstp_port_struct_t *) poPort;
|
||||
if (!mstp_port) {
|
||||
return 0;
|
||||
}
|
||||
poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
|
||||
if (!poSharedData) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
pkt = (struct mstp_pdu_packet *) Ringbuf_Alloc(&poSharedData->PDU_Queue);
|
||||
if (pkt) {
|
||||
pkt->data_expecting_reply = BACNET_DATA_EXPECTING_REPLY(pdu[BACNET_PDU_CONTROL_BYTE_OFFSET]);
|
||||
for (i = 0; i < pdu_len; i++) {
|
||||
pkt->buffer[i] = pdu[i];
|
||||
}
|
||||
pkt->length = pdu_len;
|
||||
pkt->destination_mac = dest->mac[0];
|
||||
bytes_sent = pdu_len;
|
||||
}
|
||||
pkt = (struct mstp_pdu_packet *) Ringbuf_Alloc(&poSharedData->PDU_Queue);
|
||||
if (pkt) {
|
||||
pkt->data_expecting_reply =
|
||||
BACNET_DATA_EXPECTING_REPLY(pdu[BACNET_PDU_CONTROL_BYTE_OFFSET]);
|
||||
for (i = 0; i < pdu_len; i++) {
|
||||
pkt->buffer[i] = pdu[i];
|
||||
}
|
||||
pkt->length = pdu_len;
|
||||
pkt->destination_mac = dest->mac[0];
|
||||
bytes_sent = pdu_len;
|
||||
}
|
||||
|
||||
return bytes_sent;
|
||||
return bytes_sent;
|
||||
}
|
||||
|
||||
uint16_t dlmstp_receive(
|
||||
void * poPort,
|
||||
void *poPort,
|
||||
BACNET_ADDRESS * src, /* source address */
|
||||
uint8_t * pdu, /* PDU data */
|
||||
uint16_t max_pdu, /* amount of space available in the PDU */
|
||||
@@ -178,60 +176,58 @@ uint16_t dlmstp_receive(
|
||||
uint16_t pdu_len = 0;
|
||||
struct timespec abstime;
|
||||
int rv = 0;
|
||||
SHARED_MSTP_DATA * poSharedData;
|
||||
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort;
|
||||
if(!mstp_port)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
|
||||
if(!poSharedData)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
SHARED_MSTP_DATA *poSharedData;
|
||||
struct mstp_port_struct_t *mstp_port =
|
||||
(struct mstp_port_struct_t *) poPort;
|
||||
if (!mstp_port) {
|
||||
return 0;
|
||||
}
|
||||
poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
|
||||
if (!poSharedData) {
|
||||
return 0;
|
||||
}
|
||||
(void) max_pdu;
|
||||
/* see if there is a packet available, and a place
|
||||
to put the reply (if necessary) and process it */
|
||||
get_abstime(&abstime, timeout);
|
||||
rv = pthread_cond_timedwait(&poSharedData->Receive_Packet_Flag, &poSharedData->Receive_Packet_Mutex,
|
||||
&abstime);
|
||||
if (rv == 0) {
|
||||
if (poSharedData->Receive_Packet.ready) {
|
||||
if (poSharedData->Receive_Packet.pdu_len) {
|
||||
poSharedData->MSTP_Packets++;
|
||||
if (src) {
|
||||
memmove(src, &poSharedData->Receive_Packet.address,
|
||||
sizeof(poSharedData->Receive_Packet.address));
|
||||
}
|
||||
if (pdu) {
|
||||
memmove(pdu, &poSharedData->Receive_Packet.pdu,
|
||||
sizeof(poSharedData->Receive_Packet.pdu));
|
||||
}
|
||||
pdu_len = poSharedData->Receive_Packet.pdu_len;
|
||||
rv = pthread_cond_timedwait(&poSharedData->Receive_Packet_Flag,
|
||||
&poSharedData->Receive_Packet_Mutex, &abstime);
|
||||
if (rv == 0) {
|
||||
if (poSharedData->Receive_Packet.ready) {
|
||||
if (poSharedData->Receive_Packet.pdu_len) {
|
||||
poSharedData->MSTP_Packets++;
|
||||
if (src) {
|
||||
memmove(src, &poSharedData->Receive_Packet.address,
|
||||
sizeof(poSharedData->Receive_Packet.address));
|
||||
}
|
||||
poSharedData->Receive_Packet.ready = false;
|
||||
if (pdu) {
|
||||
memmove(pdu, &poSharedData->Receive_Packet.pdu,
|
||||
sizeof(poSharedData->Receive_Packet.pdu));
|
||||
}
|
||||
pdu_len = poSharedData->Receive_Packet.pdu_len;
|
||||
}
|
||||
poSharedData->Receive_Packet.ready = false;
|
||||
}
|
||||
}
|
||||
|
||||
return pdu_len;
|
||||
return pdu_len;
|
||||
}
|
||||
|
||||
void *dlmstp_receive_fsm_task(
|
||||
void *pArg)
|
||||
{
|
||||
bool received_frame;
|
||||
SHARED_MSTP_DATA * poSharedData;
|
||||
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t*)pArg;
|
||||
if(!mstp_port)
|
||||
{
|
||||
return NULL;
|
||||
SHARED_MSTP_DATA *poSharedData;
|
||||
struct mstp_port_struct_t *mstp_port = (struct mstp_port_struct_t *) pArg;
|
||||
if (!mstp_port) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
poSharedData = (SHARED_MSTP_DATA *) ((struct mstp_port_struct_t*)pArg)->UserData;
|
||||
if(!poSharedData)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
poSharedData =
|
||||
(SHARED_MSTP_DATA *) ((struct mstp_port_struct_t *) pArg)->UserData;
|
||||
if (!poSharedData) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
/* only do receive state machine while we don't have a frame */
|
||||
@@ -239,9 +235,10 @@ void *dlmstp_receive_fsm_task(
|
||||
(mstp_port->ReceivedInvalidFrame == false)) {
|
||||
do {
|
||||
RS485_Check_UART_Data(mstp_port);
|
||||
MSTP_Receive_Frame_FSM((volatile struct mstp_port_struct_t*)pArg);
|
||||
MSTP_Receive_Frame_FSM((volatile struct mstp_port_struct_t *)
|
||||
pArg);
|
||||
received_frame = mstp_port->ReceivedValidFrame ||
|
||||
mstp_port->ReceivedInvalidFrame;
|
||||
mstp_port->ReceivedInvalidFrame;
|
||||
if (received_frame) {
|
||||
pthread_cond_signal(&poSharedData->Received_Frame_Flag);
|
||||
break;
|
||||
@@ -256,61 +253,60 @@ void *dlmstp_receive_fsm_task(
|
||||
void *dlmstp_master_fsm_task(
|
||||
void *pArg)
|
||||
{
|
||||
uint32_t silence = 0;
|
||||
bool run_master = false;
|
||||
SHARED_MSTP_DATA * poSharedData;
|
||||
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t*)pArg;
|
||||
if(!mstp_port)
|
||||
{
|
||||
return NULL;
|
||||
uint32_t silence = 0;
|
||||
bool run_master = false;
|
||||
SHARED_MSTP_DATA *poSharedData;
|
||||
struct mstp_port_struct_t *mstp_port = (struct mstp_port_struct_t *) pArg;
|
||||
if (!mstp_port) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
poSharedData = (SHARED_MSTP_DATA *) ((struct mstp_port_struct_t*)pArg)->UserData;
|
||||
if(!poSharedData)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
poSharedData =
|
||||
(SHARED_MSTP_DATA *) ((struct mstp_port_struct_t *) pArg)->UserData;
|
||||
if (!poSharedData) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
if (mstp_port->ReceivedValidFrame == false &&
|
||||
mstp_port->ReceivedInvalidFrame == false) {
|
||||
RS485_Check_UART_Data(mstp_port);
|
||||
MSTP_Receive_Frame_FSM(mstp_port);
|
||||
}
|
||||
if (mstp_port->ReceivedValidFrame || mstp_port->ReceivedInvalidFrame) {
|
||||
run_master = true;
|
||||
} else {
|
||||
silence = mstp_port->SilenceTimer(NULL);
|
||||
switch (mstp_port->master_state) {
|
||||
case MSTP_MASTER_STATE_IDLE:
|
||||
if (silence >= Tno_token)
|
||||
run_master = true;
|
||||
break;
|
||||
case MSTP_MASTER_STATE_WAIT_FOR_REPLY:
|
||||
if (silence >= poSharedData->Treply_timeout)
|
||||
run_master = true;
|
||||
break;
|
||||
case MSTP_MASTER_STATE_POLL_FOR_MASTER:
|
||||
if (silence >= poSharedData->Tusage_timeout)
|
||||
run_master = true;
|
||||
break;
|
||||
default:
|
||||
run_master = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (run_master) {
|
||||
if (mstp_port->This_Station <= DEFAULT_MAX_MASTER) {
|
||||
while (MSTP_Master_Node_FSM(mstp_port)) {
|
||||
/* do nothing while immediate transitioning */
|
||||
}
|
||||
} else if (mstp_port->This_Station < 255) {
|
||||
MSTP_Slave_Node_FSM(mstp_port);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (;;) {
|
||||
if (mstp_port->ReceivedValidFrame == false &&
|
||||
mstp_port->ReceivedInvalidFrame == false) {
|
||||
RS485_Check_UART_Data(mstp_port);
|
||||
MSTP_Receive_Frame_FSM(mstp_port);
|
||||
}
|
||||
if (mstp_port->ReceivedValidFrame || mstp_port->ReceivedInvalidFrame) {
|
||||
run_master = true;
|
||||
} else {
|
||||
silence = mstp_port->SilenceTimer(NULL);
|
||||
switch (mstp_port->master_state) {
|
||||
case MSTP_MASTER_STATE_IDLE:
|
||||
if (silence >= Tno_token)
|
||||
run_master = true;
|
||||
break;
|
||||
case MSTP_MASTER_STATE_WAIT_FOR_REPLY:
|
||||
if (silence >= poSharedData->Treply_timeout)
|
||||
run_master = true;
|
||||
break;
|
||||
case MSTP_MASTER_STATE_POLL_FOR_MASTER:
|
||||
if (silence >= poSharedData->Tusage_timeout)
|
||||
run_master = true;
|
||||
break;
|
||||
default:
|
||||
run_master = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (run_master) {
|
||||
if (mstp_port->This_Station <= DEFAULT_MAX_MASTER) {
|
||||
while (MSTP_Master_Node_FSM(mstp_port)) {
|
||||
/* do nothing while immediate transitioning */
|
||||
}
|
||||
} else if (mstp_port->This_Station < 255) {
|
||||
MSTP_Slave_Node_FSM(mstp_port);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void dlmstp_fill_bacnet_address(
|
||||
@@ -343,12 +339,11 @@ uint16_t MSTP_Put_Receive(
|
||||
volatile struct mstp_port_struct_t *mstp_port)
|
||||
{
|
||||
uint16_t pdu_len = 0;
|
||||
SHARED_MSTP_DATA * poSharedData = (SHARED_MSTP_DATA*)mstp_port->UserData;
|
||||
SHARED_MSTP_DATA *poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
|
||||
|
||||
if(!poSharedData)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (!poSharedData) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!poSharedData->Receive_Packet.ready) {
|
||||
/* bounds check - maybe this should send an abort? */
|
||||
@@ -373,42 +368,41 @@ 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;
|
||||
uint8_t frame_type = 0;
|
||||
struct mstp_pdu_packet *pkt;
|
||||
SHARED_MSTP_DATA * poSharedData = (SHARED_MSTP_DATA*)mstp_port->UserData;
|
||||
uint16_t pdu_len = 0;
|
||||
uint8_t frame_type = 0;
|
||||
struct mstp_pdu_packet *pkt;
|
||||
SHARED_MSTP_DATA *poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
|
||||
|
||||
if(!poSharedData)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (!poSharedData) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
(void) timeout;
|
||||
if (Ringbuf_Empty(&poSharedData->PDU_Queue)) {
|
||||
return 0;
|
||||
}
|
||||
pkt = (struct mstp_pdu_packet *) Ringbuf_Peek(&poSharedData->PDU_Queue);
|
||||
if (pkt->data_expecting_reply) {
|
||||
frame_type = FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY;
|
||||
} else {
|
||||
frame_type = FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY;
|
||||
}
|
||||
/* convert the PDU into the MSTP Frame */
|
||||
pdu_len = MSTP_Create_Frame(&mstp_port->OutputBuffer[0], /* <-- loading this */
|
||||
mstp_port->OutputBufferSize, frame_type, pkt->destination_mac,
|
||||
mstp_port->This_Station, (uint8_t *) & pkt->buffer[0], pkt->length);
|
||||
(void) timeout;
|
||||
if (Ringbuf_Empty(&poSharedData->PDU_Queue)) {
|
||||
return 0;
|
||||
}
|
||||
pkt = (struct mstp_pdu_packet *) Ringbuf_Peek(&poSharedData->PDU_Queue);
|
||||
if (pkt->data_expecting_reply) {
|
||||
frame_type = FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY;
|
||||
} else {
|
||||
frame_type = FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY;
|
||||
}
|
||||
/* convert the PDU into the MSTP Frame */
|
||||
pdu_len = MSTP_Create_Frame(&mstp_port->OutputBuffer[0], /* <-- loading this */
|
||||
mstp_port->OutputBufferSize, frame_type, pkt->destination_mac,
|
||||
mstp_port->This_Station, (uint8_t *) & pkt->buffer[0], pkt->length);
|
||||
(void) Ringbuf_Pop(&poSharedData->PDU_Queue, NULL);
|
||||
|
||||
return pdu_len;
|
||||
return pdu_len;
|
||||
}
|
||||
|
||||
bool dlmstp_compare_data_expecting_reply(
|
||||
uint8_t * request_pdu,
|
||||
uint16_t request_pdu_len,
|
||||
uint8_t src_address,
|
||||
uint8_t * reply_pdu,
|
||||
uint16_t reply_pdu_len,
|
||||
uint8_t dest_address)
|
||||
uint8_t * request_pdu,
|
||||
uint16_t request_pdu_len,
|
||||
uint8_t src_address,
|
||||
uint8_t * reply_pdu,
|
||||
uint16_t reply_pdu_len,
|
||||
uint8_t dest_address)
|
||||
{
|
||||
uint16_t offset;
|
||||
/* One way to check the message is to compare NPDU
|
||||
@@ -565,12 +559,11 @@ uint16_t MSTP_Get_Reply(
|
||||
bool matched = false;
|
||||
uint8_t frame_type = 0;
|
||||
struct mstp_pdu_packet *pkt;
|
||||
SHARED_MSTP_DATA * poSharedData = (SHARED_MSTP_DATA*)mstp_port->UserData;
|
||||
SHARED_MSTP_DATA *poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
|
||||
|
||||
if(!poSharedData)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (!poSharedData) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (Ringbuf_Empty(&poSharedData->PDU_Queue)) {
|
||||
return 0;
|
||||
@@ -599,15 +592,15 @@ uint16_t MSTP_Get_Reply(
|
||||
}
|
||||
|
||||
void dlmstp_set_mac_address(
|
||||
void * poPort,
|
||||
void *poPort,
|
||||
uint8_t mac_address)
|
||||
{
|
||||
/* SHARED_MSTP_DATA * poSharedData; */
|
||||
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort;
|
||||
if(!mstp_port)
|
||||
{
|
||||
return;
|
||||
}
|
||||
struct mstp_port_struct_t *mstp_port =
|
||||
(struct mstp_port_struct_t *) poPort;
|
||||
if (!mstp_port) {
|
||||
return;
|
||||
}
|
||||
/*
|
||||
poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
|
||||
if(!poSharedData)
|
||||
@@ -617,7 +610,7 @@ void dlmstp_set_mac_address(
|
||||
*/
|
||||
/* Master Nodes can only have address 0-127 */
|
||||
if (mac_address <= 127) {
|
||||
mstp_port->This_Station = mac_address;
|
||||
mstp_port->This_Station = mac_address;
|
||||
/* FIXME: implement your data storage */
|
||||
/* I2C_Write_Byte(
|
||||
EEPROM_DEVICE_ADDRESS,
|
||||
@@ -631,14 +624,14 @@ void dlmstp_set_mac_address(
|
||||
}
|
||||
|
||||
uint8_t dlmstp_mac_address(
|
||||
void * poPort)
|
||||
void *poPort)
|
||||
{
|
||||
/* SHARED_MSTP_DATA * poSharedData; */
|
||||
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort;
|
||||
if(!mstp_port)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
struct mstp_port_struct_t *mstp_port =
|
||||
(struct mstp_port_struct_t *) poPort;
|
||||
if (!mstp_port) {
|
||||
return 0;
|
||||
}
|
||||
/* poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
|
||||
if(!poSharedData)
|
||||
{
|
||||
@@ -657,15 +650,15 @@ uint8_t dlmstp_mac_address(
|
||||
/* 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(
|
||||
void * poPort,
|
||||
void *poPort,
|
||||
uint8_t max_info_frames)
|
||||
{
|
||||
/* SHARED_MSTP_DATA * poSharedData; */
|
||||
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort;
|
||||
if(!mstp_port)
|
||||
{
|
||||
return;
|
||||
}
|
||||
struct mstp_port_struct_t *mstp_port =
|
||||
(struct mstp_port_struct_t *) poPort;
|
||||
if (!mstp_port) {
|
||||
return;
|
||||
}
|
||||
/*
|
||||
poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
|
||||
if(!poSharedData)
|
||||
@@ -674,7 +667,7 @@ void dlmstp_set_max_info_frames(
|
||||
}
|
||||
*/
|
||||
if (max_info_frames >= 1) {
|
||||
mstp_port->Nmax_info_frames = max_info_frames;
|
||||
mstp_port->Nmax_info_frames = max_info_frames;
|
||||
/* FIXME: implement your data storage */
|
||||
/* I2C_Write_Byte(
|
||||
EEPROM_DEVICE_ADDRESS,
|
||||
@@ -686,14 +679,14 @@ void dlmstp_set_max_info_frames(
|
||||
}
|
||||
|
||||
uint8_t dlmstp_max_info_frames(
|
||||
void * poPort)
|
||||
void *poPort)
|
||||
{
|
||||
/* SHARED_MSTP_DATA * poSharedData; */
|
||||
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort;
|
||||
if(!mstp_port)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
struct mstp_port_struct_t *mstp_port =
|
||||
(struct mstp_port_struct_t *) poPort;
|
||||
if (!mstp_port) {
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
|
||||
if(!poSharedData)
|
||||
@@ -710,15 +703,15 @@ uint8_t dlmstp_max_info_frames(
|
||||
/* 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(
|
||||
void * poPort,
|
||||
void *poPort,
|
||||
uint8_t max_master)
|
||||
{
|
||||
/* SHARED_MSTP_DATA * poSharedData; */
|
||||
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort;
|
||||
if(!mstp_port)
|
||||
{
|
||||
return;
|
||||
}
|
||||
struct mstp_port_struct_t *mstp_port =
|
||||
(struct mstp_port_struct_t *) poPort;
|
||||
if (!mstp_port) {
|
||||
return;
|
||||
}
|
||||
/*
|
||||
poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
|
||||
if(!poSharedData)
|
||||
@@ -728,7 +721,7 @@ void dlmstp_set_max_master(
|
||||
*/
|
||||
if (max_master <= 127) {
|
||||
if (mstp_port->This_Station <= max_master) {
|
||||
mstp_port->Nmax_master = max_master;
|
||||
mstp_port->Nmax_master = max_master;
|
||||
/* FIXME: implement your data storage */
|
||||
/* I2C_Write_Byte(
|
||||
EEPROM_DEVICE_ADDRESS,
|
||||
@@ -741,14 +734,14 @@ void dlmstp_set_max_master(
|
||||
}
|
||||
|
||||
uint8_t dlmstp_max_master(
|
||||
void * poPort)
|
||||
void *poPort)
|
||||
{
|
||||
/* SHARED_MSTP_DATA * poSharedData; */
|
||||
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort;
|
||||
if(!mstp_port)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
struct mstp_port_struct_t *mstp_port =
|
||||
(struct mstp_port_struct_t *) poPort;
|
||||
if (!mstp_port) {
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
|
||||
if(!poSharedData)
|
||||
@@ -761,36 +754,35 @@ uint8_t dlmstp_max_master(
|
||||
|
||||
/* RS485 Baud Rate 9600, 19200, 38400, 57600, 115200 */
|
||||
void dlmstp_set_baud_rate(
|
||||
void * poPort,
|
||||
void *poPort,
|
||||
uint32_t baud)
|
||||
{
|
||||
SHARED_MSTP_DATA * poSharedData;
|
||||
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort;
|
||||
if(!mstp_port)
|
||||
{
|
||||
return;
|
||||
}
|
||||
poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
|
||||
if(!poSharedData)
|
||||
{
|
||||
return;
|
||||
}
|
||||
SHARED_MSTP_DATA *poSharedData;
|
||||
struct mstp_port_struct_t *mstp_port =
|
||||
(struct mstp_port_struct_t *) poPort;
|
||||
if (!mstp_port) {
|
||||
return;
|
||||
}
|
||||
poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
|
||||
if (!poSharedData) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (baud) {
|
||||
case 9600:
|
||||
poSharedData->RS485_Baud = B9600;
|
||||
poSharedData->RS485_Baud = B9600;
|
||||
break;
|
||||
case 19200:
|
||||
poSharedData->RS485_Baud = B19200;
|
||||
poSharedData->RS485_Baud = B19200;
|
||||
break;
|
||||
case 38400:
|
||||
poSharedData->RS485_Baud = B38400;
|
||||
poSharedData->RS485_Baud = B38400;
|
||||
break;
|
||||
case 57600:
|
||||
poSharedData->RS485_Baud = B57600;
|
||||
poSharedData->RS485_Baud = B57600;
|
||||
break;
|
||||
case 115200:
|
||||
poSharedData->RS485_Baud = B115200;
|
||||
poSharedData->RS485_Baud = B115200;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -798,19 +790,18 @@ void dlmstp_set_baud_rate(
|
||||
}
|
||||
|
||||
uint32_t dlmstp_baud_rate(
|
||||
void * poPort)
|
||||
void *poPort)
|
||||
{
|
||||
SHARED_MSTP_DATA * poSharedData;
|
||||
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort;
|
||||
if(!mstp_port)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
|
||||
if(!poSharedData)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
SHARED_MSTP_DATA *poSharedData;
|
||||
struct mstp_port_struct_t *mstp_port =
|
||||
(struct mstp_port_struct_t *) poPort;
|
||||
if (!mstp_port) {
|
||||
return false;
|
||||
}
|
||||
poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
|
||||
if (!poSharedData) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (poSharedData->RS485_Baud) {
|
||||
case B19200:
|
||||
@@ -828,21 +819,20 @@ uint32_t dlmstp_baud_rate(
|
||||
}
|
||||
|
||||
void dlmstp_get_my_address(
|
||||
void * poPort,
|
||||
void *poPort,
|
||||
BACNET_ADDRESS * my_address)
|
||||
{
|
||||
int i = 0; /* counter */
|
||||
SHARED_MSTP_DATA * poSharedData;
|
||||
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort;
|
||||
if(!mstp_port)
|
||||
{
|
||||
return;
|
||||
}
|
||||
poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
|
||||
if(!poSharedData)
|
||||
{
|
||||
return;
|
||||
}
|
||||
SHARED_MSTP_DATA *poSharedData;
|
||||
struct mstp_port_struct_t *mstp_port =
|
||||
(struct mstp_port_struct_t *) poPort;
|
||||
if (!mstp_port) {
|
||||
return;
|
||||
}
|
||||
poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
|
||||
if (!poSharedData) {
|
||||
return;
|
||||
}
|
||||
my_address->mac_len = 1;
|
||||
my_address->mac[0] = mstp_port->This_Station;
|
||||
my_address->net = 0; /* local only, no routing */
|
||||
@@ -873,28 +863,30 @@ void dlmstp_get_broadcast_address(
|
||||
}
|
||||
|
||||
bool dlmstp_init(
|
||||
void * poPort,
|
||||
void *poPort,
|
||||
char *ifname)
|
||||
{
|
||||
unsigned long hThread = 0;
|
||||
int rv = 0;
|
||||
SHARED_MSTP_DATA * poSharedData;
|
||||
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t*)poPort;
|
||||
if(!mstp_port)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
SHARED_MSTP_DATA *poSharedData;
|
||||
struct mstp_port_struct_t *mstp_port =
|
||||
(struct mstp_port_struct_t *) poPort;
|
||||
if (!mstp_port) {
|
||||
return false;
|
||||
}
|
||||
|
||||
poSharedData = (SHARED_MSTP_DATA *) ((struct mstp_port_struct_t*)mstp_port)->UserData;
|
||||
if(!poSharedData)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
poSharedData =
|
||||
(SHARED_MSTP_DATA *) ((struct mstp_port_struct_t *) mstp_port)->
|
||||
UserData;
|
||||
if (!poSharedData) {
|
||||
return false;
|
||||
}
|
||||
|
||||
poSharedData->RS485_Port_Name = ifname;
|
||||
poSharedData->RS485_Port_Name = ifname;
|
||||
/* initialize PDU queue */
|
||||
Ringbuf_Init(&poSharedData->PDU_Queue, (uint8_t *) & poSharedData->PDU_Buffer,
|
||||
sizeof(struct mstp_pdu_packet), MSTP_PDU_PACKET_COUNT);
|
||||
Ringbuf_Init(&poSharedData->PDU_Queue,
|
||||
(uint8_t *) & poSharedData->PDU_Buffer, sizeof(struct mstp_pdu_packet),
|
||||
MSTP_PDU_PACKET_COUNT);
|
||||
/* initialize packet queue */
|
||||
poSharedData->Receive_Packet.ready = false;
|
||||
poSharedData->Receive_Packet.pdu_len = 0;
|
||||
@@ -918,7 +910,9 @@ bool dlmstp_init(
|
||||
Open device for reading and writing.
|
||||
Blocking mode - more CPU effecient
|
||||
*/
|
||||
poSharedData->RS485_Handle = open(poSharedData->RS485_Port_Name, O_RDWR | O_NOCTTY | O_NONBLOCK/*| O_NDELAY */ );
|
||||
poSharedData->RS485_Handle =
|
||||
open(poSharedData->RS485_Port_Name,
|
||||
O_RDWR | O_NOCTTY | O_NONBLOCK /*| O_NDELAY */ );
|
||||
if (poSharedData->RS485_Handle < 0) {
|
||||
perror(poSharedData->RS485_Port_Name);
|
||||
exit(-1);
|
||||
@@ -941,7 +935,8 @@ bool dlmstp_init(
|
||||
CLOCAL : local connection, no modem contol
|
||||
CREAD : enable receiving characters
|
||||
*/
|
||||
newtio.c_cflag = poSharedData->RS485_Baud | poSharedData->RS485MOD | CLOCAL | CREAD;
|
||||
newtio.c_cflag =
|
||||
poSharedData->RS485_Baud | poSharedData->RS485MOD | CLOCAL | CREAD;
|
||||
/* Raw input */
|
||||
newtio.c_iflag = 0;
|
||||
/* Raw output */
|
||||
@@ -954,7 +949,8 @@ bool dlmstp_init(
|
||||
usleep(200000);
|
||||
tcflush(poSharedData->RS485_Handle, TCIOFLUSH);
|
||||
/* ringbuffer */
|
||||
FIFO_Init(&poSharedData->Rx_FIFO, poSharedData->Rx_Buffer, sizeof(poSharedData->Rx_Buffer));
|
||||
FIFO_Init(&poSharedData->Rx_FIFO, poSharedData->Rx_Buffer,
|
||||
sizeof(poSharedData->Rx_Buffer));
|
||||
printf("=success!\n");
|
||||
mstp_port->InputBuffer = &poSharedData->RxBuffer[0];
|
||||
mstp_port->InputBufferSize = sizeof(poSharedData->RxBuffer);
|
||||
@@ -967,7 +963,8 @@ bool dlmstp_init(
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "MS/TP MAC: %02X\n", mstp_port->This_Station);
|
||||
fprintf(stderr, "MS/TP Max_Master: %02X\n", mstp_port->Nmax_master);
|
||||
fprintf(stderr, "MS/TP Max_Info_Frames: %u\n", mstp_port->Nmax_info_frames);
|
||||
fprintf(stderr, "MS/TP Max_Info_Frames: %u\n",
|
||||
mstp_port->Nmax_info_frames);
|
||||
#endif
|
||||
|
||||
rv = pthread_create(&hThread, NULL, dlmstp_master_fsm_task, mstp_port);
|
||||
|
||||
@@ -62,91 +62,90 @@ struct mstp_pdu_packet {
|
||||
uint8_t buffer[MAX_MPDU];
|
||||
};
|
||||
|
||||
typedef struct shared_mstp_data
|
||||
{
|
||||
/* Number of MS/TP Packets Rx/Tx */
|
||||
uint16_t MSTP_Packets;
|
||||
typedef struct shared_mstp_data {
|
||||
/* Number of MS/TP Packets Rx/Tx */
|
||||
uint16_t MSTP_Packets;
|
||||
|
||||
/* packet queues */
|
||||
DLMSTP_PACKET Receive_Packet;
|
||||
DLMSTP_PACKET Transmit_Packet;
|
||||
/*
|
||||
RT_COND Receive_Packet_Flag;
|
||||
RT_MUTEX Receive_Packet_Mutex;
|
||||
*/
|
||||
pthread_cond_t Receive_Packet_Flag;
|
||||
pthread_mutex_t Receive_Packet_Mutex;
|
||||
/* mechanism to wait for a frame in state machine */
|
||||
/*
|
||||
RT_COND Received_Frame_Flag;
|
||||
RT_MUTEX Received_Frame_Mutex;
|
||||
*/
|
||||
pthread_cond_t Received_Frame_Flag;
|
||||
pthread_mutex_t Received_Frame_Mutex;
|
||||
pthread_cond_t Master_Done_Flag;
|
||||
pthread_mutex_t Master_Done_Mutex;
|
||||
/* buffers needed by mstp port struct */
|
||||
uint8_t TxBuffer[MAX_MPDU];
|
||||
uint8_t RxBuffer[MAX_MPDU];
|
||||
/* The minimum time without a DataAvailable or ReceiveError event */
|
||||
/* that a node must wait for a station to begin replying to a */
|
||||
/* confirmed request: 255 milliseconds. (Implementations may use */
|
||||
/* larger values for this timeout, not to exceed 300 milliseconds.) */
|
||||
uint16_t Treply_timeout;
|
||||
/* The minimum time without a DataAvailable or ReceiveError event that a */
|
||||
/* node must wait for a remote node to begin using a token or replying to */
|
||||
/* a Poll For Master frame: 20 milliseconds. (Implementations may use */
|
||||
/* larger values for this timeout, not to exceed 100 milliseconds.) */
|
||||
uint8_t Tusage_timeout;
|
||||
/* Timer that indicates line silence - and functions */
|
||||
uint16_t SilenceTime;
|
||||
/* packet queues */
|
||||
DLMSTP_PACKET Receive_Packet;
|
||||
DLMSTP_PACKET Transmit_Packet;
|
||||
/*
|
||||
RT_COND Receive_Packet_Flag;
|
||||
RT_MUTEX Receive_Packet_Mutex;
|
||||
*/
|
||||
pthread_cond_t Receive_Packet_Flag;
|
||||
pthread_mutex_t Receive_Packet_Mutex;
|
||||
/* mechanism to wait for a frame in state machine */
|
||||
/*
|
||||
RT_COND Received_Frame_Flag;
|
||||
RT_MUTEX Received_Frame_Mutex;
|
||||
*/
|
||||
pthread_cond_t Received_Frame_Flag;
|
||||
pthread_mutex_t Received_Frame_Mutex;
|
||||
pthread_cond_t Master_Done_Flag;
|
||||
pthread_mutex_t Master_Done_Mutex;
|
||||
/* buffers needed by mstp port struct */
|
||||
uint8_t TxBuffer[MAX_MPDU];
|
||||
uint8_t RxBuffer[MAX_MPDU];
|
||||
/* The minimum time without a DataAvailable or ReceiveError event */
|
||||
/* that a node must wait for a station to begin replying to a */
|
||||
/* confirmed request: 255 milliseconds. (Implementations may use */
|
||||
/* larger values for this timeout, not to exceed 300 milliseconds.) */
|
||||
uint16_t Treply_timeout;
|
||||
/* The minimum time without a DataAvailable or ReceiveError event that a */
|
||||
/* node must wait for a remote node to begin using a token or replying to */
|
||||
/* a Poll For Master frame: 20 milliseconds. (Implementations may use */
|
||||
/* larger values for this timeout, not to exceed 100 milliseconds.) */
|
||||
uint8_t Tusage_timeout;
|
||||
/* Timer that indicates line silence - and functions */
|
||||
uint16_t SilenceTime;
|
||||
|
||||
/* handle returned from open() */
|
||||
int RS485_Handle;
|
||||
/* baudrate settings are defined in <asm/termbits.h>, which is
|
||||
included by <termios.h> */
|
||||
unsigned int RS485_Baud;
|
||||
/* serial port name, /dev/ttyS0,
|
||||
/dev/ttyUSB0 for USB->RS485 from B&B Electronics USOPTL4 */
|
||||
char *RS485_Port_Name;
|
||||
/* serial I/O settings */
|
||||
struct termios RS485_oldtio;
|
||||
/* some terminal I/O have RS-485 specific functionality */
|
||||
tcflag_t RS485MOD;
|
||||
/* Ring buffer for incoming bytes, in order to speed up the receiving. */
|
||||
FIFO_BUFFER Rx_FIFO;
|
||||
/* buffer size needs to be a power of 2 */
|
||||
uint8_t Rx_Buffer[4096];
|
||||
struct timeval start;
|
||||
/* handle returned from open() */
|
||||
int RS485_Handle;
|
||||
/* baudrate settings are defined in <asm/termbits.h>, which is
|
||||
included by <termios.h> */
|
||||
unsigned int RS485_Baud;
|
||||
/* serial port name, /dev/ttyS0,
|
||||
/dev/ttyUSB0 for USB->RS485 from B&B Electronics USOPTL4 */
|
||||
char *RS485_Port_Name;
|
||||
/* serial I/O settings */
|
||||
struct termios RS485_oldtio;
|
||||
/* some terminal I/O have RS-485 specific functionality */
|
||||
tcflag_t RS485MOD;
|
||||
/* Ring buffer for incoming bytes, in order to speed up the receiving. */
|
||||
FIFO_BUFFER Rx_FIFO;
|
||||
/* buffer size needs to be a power of 2 */
|
||||
uint8_t Rx_Buffer[4096];
|
||||
struct timeval start;
|
||||
|
||||
RING_BUFFER PDU_Queue;
|
||||
RING_BUFFER PDU_Queue;
|
||||
|
||||
struct mstp_pdu_packet PDU_Buffer[MSTP_PDU_PACKET_COUNT];
|
||||
struct mstp_pdu_packet PDU_Buffer[MSTP_PDU_PACKET_COUNT];
|
||||
|
||||
}SHARED_MSTP_DATA;
|
||||
} SHARED_MSTP_DATA;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
bool dlmstp_init(
|
||||
void * poShared,
|
||||
void *poShared,
|
||||
char *ifname);
|
||||
void dlmstp_reset(
|
||||
void * poShared);
|
||||
void *poShared);
|
||||
void dlmstp_cleanup(
|
||||
void * poShared);
|
||||
void *poShared);
|
||||
|
||||
/* returns number of bytes sent on success, negative on failure */
|
||||
int dlmstp_send_pdu(
|
||||
void * poShared,
|
||||
void *poShared,
|
||||
BACNET_ADDRESS * dest, /* destination address */
|
||||
uint8_t * pdu, /* any data to be sent - may be null */
|
||||
unsigned pdu_len); /* number of bytes of data */
|
||||
|
||||
/* returns the number of octets in the PDU, or zero on failure */
|
||||
uint16_t dlmstp_receive(
|
||||
void * poShared,
|
||||
void *poShared,
|
||||
BACNET_ADDRESS * src, /* source address */
|
||||
uint8_t * pdu, /* PDU data */
|
||||
uint16_t max_pdu, /* amount of space available in the PDU */
|
||||
@@ -160,10 +159,10 @@ extern "C" {
|
||||
/* 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(
|
||||
void * poShared,
|
||||
void *poShared,
|
||||
uint8_t max_info_frames);
|
||||
uint8_t dlmstp_max_info_frames(
|
||||
void * poShared);
|
||||
void *poShared);
|
||||
|
||||
/* This parameter represents the value of the Max_Master property of the */
|
||||
/* node's Device object. The value of Max_Master specifies the highest */
|
||||
@@ -171,30 +170,30 @@ extern "C" {
|
||||
/* 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(
|
||||
void * poShared,
|
||||
void *poShared,
|
||||
uint8_t max_master);
|
||||
uint8_t dlmstp_max_master(
|
||||
void * poShared);
|
||||
void *poShared);
|
||||
|
||||
/* MAC address 0-127 */
|
||||
void dlmstp_set_mac_address(
|
||||
void * poShared,
|
||||
void *poShared,
|
||||
uint8_t my_address);
|
||||
uint8_t dlmstp_mac_address(
|
||||
void * poShared);
|
||||
void *poShared);
|
||||
|
||||
void dlmstp_get_my_address(
|
||||
void * poShared,
|
||||
void *poShared,
|
||||
BACNET_ADDRESS * my_address);
|
||||
void dlmstp_get_broadcast_address(
|
||||
BACNET_ADDRESS * dest); /* destination address */
|
||||
|
||||
/* RS485 Baud Rate 9600, 19200, 38400, 57600, 115200 */
|
||||
void dlmstp_set_baud_rate(
|
||||
void * poShared,
|
||||
void *poShared,
|
||||
uint32_t baud);
|
||||
uint32_t dlmstp_baud_rate(
|
||||
void * poShared);
|
||||
void *poShared);
|
||||
|
||||
void dlmstp_fill_bacnet_address(
|
||||
BACNET_ADDRESS * src,
|
||||
@@ -206,5 +205,4 @@ extern "C" {
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /*DLMSTP_LINUX_H*/
|
||||
#endif /*DLMSTP_LINUX_H */
|
||||
|
||||
@@ -46,28 +46,28 @@
|
||||
#include <sys/un.h> /* for Unix domain sockets */
|
||||
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
# include <sys/select.h> /* for convenience */
|
||||
#include <sys/select.h> /* for convenience */
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_POLL_H
|
||||
# include <poll.h> /* for convenience */
|
||||
#include <poll.h> /* for convenience */
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STRINGS_H
|
||||
# include <strings.h> /* for convenience */
|
||||
#include <strings.h> /* for convenience */
|
||||
#endif
|
||||
|
||||
/* Three headers are normally needed for socket/file ioctl's:
|
||||
* <sys/ioctl.h>, <sys/filio.h>, and <sys/sockio.h>.
|
||||
*/
|
||||
#ifdef HAVE_SYS_IOCTL_H
|
||||
# include <sys/ioctl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_FILIO_H
|
||||
# include <sys/filio.h>
|
||||
#include <sys/filio.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_SOCKIO_H
|
||||
# include <sys/sockio.h>
|
||||
#include <sys/sockio.h>
|
||||
#endif
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
+141
-145
@@ -54,8 +54,8 @@
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <sched.h>
|
||||
#include <linux/serial.h> /* for struct serial_struct */
|
||||
#include <math.h> /* for calculation of custom divisor */
|
||||
#include <linux/serial.h> /* for struct serial_struct */
|
||||
#include <math.h> /* for calculation of custom divisor */
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
/* Local includes */
|
||||
@@ -187,8 +187,8 @@ uint32_t RS485_Get_Baud_Rate(
|
||||
break;
|
||||
case B38400:
|
||||
if (!RS485_SpecBaud) {
|
||||
/* Linux asks for custom divisor
|
||||
only when baud is set on 38400 */
|
||||
/* Linux asks for custom divisor
|
||||
only when baud is set on 38400 */
|
||||
baud = 38400;
|
||||
} else {
|
||||
baud = 76800;
|
||||
@@ -217,14 +217,13 @@ uint32_t RS485_Get_Baud_Rate(
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
uint32_t RS485_Get_Port_Baud_Rate(
|
||||
volatile struct mstp_port_struct_t *mstp_port)
|
||||
volatile struct mstp_port_struct_t * mstp_port)
|
||||
{
|
||||
uint32_t baud = 0;
|
||||
SHARED_MSTP_DATA * poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
|
||||
if(!poSharedData)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
SHARED_MSTP_DATA *poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
|
||||
if (!poSharedData) {
|
||||
return 0;
|
||||
}
|
||||
switch (poSharedData->RS485_Baud) {
|
||||
case B0:
|
||||
baud = 0;
|
||||
@@ -387,66 +386,63 @@ 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) */
|
||||
{ /* number of bytes of data (up to 501) */
|
||||
uint32_t turnaround_time = Tturnaround * 1000;
|
||||
uint32_t baud;
|
||||
ssize_t written = 0;
|
||||
int greska;
|
||||
SHARED_MSTP_DATA * poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
|
||||
if(!poSharedData)
|
||||
{
|
||||
baud = RS485_Get_Baud_Rate();
|
||||
/* sleeping for turnaround time is necessary to give other devices
|
||||
time to change from sending to receiving state. */
|
||||
usleep(turnaround_time / baud);
|
||||
/*
|
||||
On success, the number of bytes written are returned (zero indicates
|
||||
nothing was written). On error, -1 is returned, and errno is set
|
||||
appropriately. If count is zero and the file descriptor refers to a
|
||||
regular file, 0 will be returned without causing any other effect. For
|
||||
a special file, the results are not portable.
|
||||
*/
|
||||
written = write(RS485_Handle, buffer, nbytes);
|
||||
greska = errno;
|
||||
if (written <= 0) {
|
||||
printf("write error: %s\n", strerror(greska));
|
||||
} else {
|
||||
/* wait until all output has been transmitted. */
|
||||
tcdrain(RS485_Handle);
|
||||
}
|
||||
/* tcdrain(RS485_Handle); */
|
||||
/* per MSTP spec, sort of */
|
||||
if (mstp_port) {
|
||||
mstp_port->SilenceTimerReset((void*)mstp_port);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
baud = RS485_Get_Port_Baud_Rate(mstp_port);
|
||||
/* sleeping for turnaround time is necessary to give other devices
|
||||
time to change from sending to receiving state. */
|
||||
usleep(turnaround_time / baud);
|
||||
/*
|
||||
On success, the number of bytes written are returned (zero indicates
|
||||
nothing was written). On error, -1 is returned, and errno is set
|
||||
appropriately. If count is zero and the file descriptor refers to a
|
||||
regular file, 0 will be returned without causing any other effect. For
|
||||
a special file, the results are not portable.
|
||||
*/
|
||||
written = write(poSharedData->RS485_Handle, buffer, nbytes);
|
||||
greska = errno;
|
||||
if (written <= 0) {
|
||||
printf("write error: %s\n", strerror(greska));
|
||||
} else {
|
||||
/* wait until all output has been transmitted. */
|
||||
tcdrain(poSharedData->RS485_Handle);
|
||||
}
|
||||
/* tcdrain(RS485_Handle); */
|
||||
/* per MSTP spec, sort of */
|
||||
if (mstp_port) {
|
||||
mstp_port->SilenceTimerReset((void*)mstp_port);
|
||||
}
|
||||
}
|
||||
SHARED_MSTP_DATA *poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
|
||||
if (!poSharedData) {
|
||||
baud = RS485_Get_Baud_Rate();
|
||||
/* sleeping for turnaround time is necessary to give other devices
|
||||
time to change from sending to receiving state. */
|
||||
usleep(turnaround_time / baud);
|
||||
/*
|
||||
On success, the number of bytes written are returned (zero indicates
|
||||
nothing was written). On error, -1 is returned, and errno is set
|
||||
appropriately. If count is zero and the file descriptor refers to a
|
||||
regular file, 0 will be returned without causing any other effect. For
|
||||
a special file, the results are not portable.
|
||||
*/
|
||||
written = write(RS485_Handle, buffer, nbytes);
|
||||
greska = errno;
|
||||
if (written <= 0) {
|
||||
printf("write error: %s\n", strerror(greska));
|
||||
} else {
|
||||
/* wait until all output has been transmitted. */
|
||||
tcdrain(RS485_Handle);
|
||||
}
|
||||
/* tcdrain(RS485_Handle); */
|
||||
/* per MSTP spec, sort of */
|
||||
if (mstp_port) {
|
||||
mstp_port->SilenceTimerReset((void *) mstp_port);
|
||||
}
|
||||
} else {
|
||||
baud = RS485_Get_Port_Baud_Rate(mstp_port);
|
||||
/* sleeping for turnaround time is necessary to give other devices
|
||||
time to change from sending to receiving state. */
|
||||
usleep(turnaround_time / baud);
|
||||
/*
|
||||
On success, the number of bytes written are returned (zero indicates
|
||||
nothing was written). On error, -1 is returned, and errno is set
|
||||
appropriately. If count is zero and the file descriptor refers to a
|
||||
regular file, 0 will be returned without causing any other effect. For
|
||||
a special file, the results are not portable.
|
||||
*/
|
||||
written = write(poSharedData->RS485_Handle, buffer, nbytes);
|
||||
greska = errno;
|
||||
if (written <= 0) {
|
||||
printf("write error: %s\n", strerror(greska));
|
||||
} else {
|
||||
/* wait until all output has been transmitted. */
|
||||
tcdrain(poSharedData->RS485_Handle);
|
||||
}
|
||||
/* tcdrain(RS485_Handle); */
|
||||
/* per MSTP spec, sort of */
|
||||
if (mstp_port) {
|
||||
mstp_port->SilenceTimerReset((void *) mstp_port);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -465,75 +461,73 @@ void RS485_Check_UART_Data(
|
||||
uint8_t buf[2048];
|
||||
int n;
|
||||
|
||||
SHARED_MSTP_DATA * poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
|
||||
if(!poSharedData)
|
||||
{
|
||||
if (mstp_port->ReceiveError == true) {
|
||||
/* do nothing but wait for state machine to clear the error */
|
||||
/* burning time, so wait a longer time */
|
||||
waiter.tv_sec = 0;
|
||||
waiter.tv_usec = 5000;
|
||||
} else if (mstp_port->DataAvailable == false) {
|
||||
/* wait for state machine to read from the DataRegister */
|
||||
if (FIFO_Count(&Rx_FIFO) > 0) {
|
||||
/* data is available */
|
||||
mstp_port->DataRegister = FIFO_Get(&Rx_FIFO);
|
||||
mstp_port->DataAvailable = true;
|
||||
/* FIFO is giving data - don't wait very long */
|
||||
waiter.tv_sec = 0;
|
||||
waiter.tv_usec = 10;
|
||||
} else {
|
||||
/* FIFO is empty - wait a longer time */
|
||||
waiter.tv_sec = 0;
|
||||
waiter.tv_usec = 5000;
|
||||
}
|
||||
}
|
||||
/* grab bytes and stuff them into the FIFO every time */
|
||||
FD_ZERO(&input);
|
||||
FD_SET(RS485_Handle, &input);
|
||||
n = select(RS485_Handle + 1, &input, NULL, NULL, &waiter);
|
||||
if (n < 0) {
|
||||
return;
|
||||
}
|
||||
if (FD_ISSET(RS485_Handle, &input)) {
|
||||
n = read(RS485_Handle, buf, sizeof(buf));
|
||||
FIFO_Add(&Rx_FIFO, &buf[0], n);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mstp_port->ReceiveError == true) {
|
||||
/* do nothing but wait for state machine to clear the error */
|
||||
/* burning time, so wait a longer time */
|
||||
waiter.tv_sec = 0;
|
||||
waiter.tv_usec = 5000;
|
||||
} else if (mstp_port->DataAvailable == false) {
|
||||
/* wait for state machine to read from the DataRegister */
|
||||
if (FIFO_Count(&poSharedData->Rx_FIFO) > 0) {
|
||||
/* data is available */
|
||||
mstp_port->DataRegister = FIFO_Get(&poSharedData->Rx_FIFO);
|
||||
mstp_port->DataAvailable = true;
|
||||
/* FIFO is giving data - don't wait very long */
|
||||
waiter.tv_sec = 0;
|
||||
waiter.tv_usec = 10;
|
||||
} else {
|
||||
/* FIFO is empty - wait a longer time */
|
||||
waiter.tv_sec = 0;
|
||||
waiter.tv_usec = 5000;
|
||||
}
|
||||
}
|
||||
/* grab bytes and stuff them into the FIFO every time */
|
||||
FD_ZERO(&input);
|
||||
FD_SET(poSharedData->RS485_Handle, &input);
|
||||
n = select(poSharedData->RS485_Handle + 1, &input, NULL, NULL, &waiter);
|
||||
if (n < 0) {
|
||||
return;
|
||||
}
|
||||
if (FD_ISSET(poSharedData->RS485_Handle, &input)) {
|
||||
n = read(poSharedData->RS485_Handle, buf, sizeof(buf));
|
||||
FIFO_Add(&poSharedData->Rx_FIFO, &buf[0], n);
|
||||
}
|
||||
}
|
||||
SHARED_MSTP_DATA *poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
|
||||
if (!poSharedData) {
|
||||
if (mstp_port->ReceiveError == true) {
|
||||
/* do nothing but wait for state machine to clear the error */
|
||||
/* burning time, so wait a longer time */
|
||||
waiter.tv_sec = 0;
|
||||
waiter.tv_usec = 5000;
|
||||
} else if (mstp_port->DataAvailable == false) {
|
||||
/* wait for state machine to read from the DataRegister */
|
||||
if (FIFO_Count(&Rx_FIFO) > 0) {
|
||||
/* data is available */
|
||||
mstp_port->DataRegister = FIFO_Get(&Rx_FIFO);
|
||||
mstp_port->DataAvailable = true;
|
||||
/* FIFO is giving data - don't wait very long */
|
||||
waiter.tv_sec = 0;
|
||||
waiter.tv_usec = 10;
|
||||
} else {
|
||||
/* FIFO is empty - wait a longer time */
|
||||
waiter.tv_sec = 0;
|
||||
waiter.tv_usec = 5000;
|
||||
}
|
||||
}
|
||||
/* grab bytes and stuff them into the FIFO every time */
|
||||
FD_ZERO(&input);
|
||||
FD_SET(RS485_Handle, &input);
|
||||
n = select(RS485_Handle + 1, &input, NULL, NULL, &waiter);
|
||||
if (n < 0) {
|
||||
return;
|
||||
}
|
||||
if (FD_ISSET(RS485_Handle, &input)) {
|
||||
n = read(RS485_Handle, buf, sizeof(buf));
|
||||
FIFO_Add(&Rx_FIFO, &buf[0], n);
|
||||
}
|
||||
} else {
|
||||
if (mstp_port->ReceiveError == true) {
|
||||
/* do nothing but wait for state machine to clear the error */
|
||||
/* burning time, so wait a longer time */
|
||||
waiter.tv_sec = 0;
|
||||
waiter.tv_usec = 5000;
|
||||
} else if (mstp_port->DataAvailable == false) {
|
||||
/* wait for state machine to read from the DataRegister */
|
||||
if (FIFO_Count(&poSharedData->Rx_FIFO) > 0) {
|
||||
/* data is available */
|
||||
mstp_port->DataRegister = FIFO_Get(&poSharedData->Rx_FIFO);
|
||||
mstp_port->DataAvailable = true;
|
||||
/* FIFO is giving data - don't wait very long */
|
||||
waiter.tv_sec = 0;
|
||||
waiter.tv_usec = 10;
|
||||
} else {
|
||||
/* FIFO is empty - wait a longer time */
|
||||
waiter.tv_sec = 0;
|
||||
waiter.tv_usec = 5000;
|
||||
}
|
||||
}
|
||||
/* grab bytes and stuff them into the FIFO every time */
|
||||
FD_ZERO(&input);
|
||||
FD_SET(poSharedData->RS485_Handle, &input);
|
||||
n = select(poSharedData->RS485_Handle + 1, &input, NULL, NULL,
|
||||
&waiter);
|
||||
if (n < 0) {
|
||||
return;
|
||||
}
|
||||
if (FD_ISSET(poSharedData->RS485_Handle, &input)) {
|
||||
n = read(poSharedData->RS485_Handle, buf, sizeof(buf));
|
||||
FIFO_Add(&poSharedData->Rx_FIFO, &buf[0], n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RS485_Cleanup(
|
||||
@@ -541,7 +535,7 @@ void RS485_Cleanup(
|
||||
{
|
||||
/* restore the old port settings */
|
||||
tcsetattr(RS485_Handle, TCSANOW, &RS485_oldtio);
|
||||
ioctl (RS485_Handle, TIOCSSERIAL, &RS485_oldserial);
|
||||
ioctl(RS485_Handle, TIOCSSERIAL, &RS485_oldserial);
|
||||
close(RS485_Handle);
|
||||
}
|
||||
|
||||
@@ -573,9 +567,9 @@ void RS485_Initialize(
|
||||
/* save current serial port settings */
|
||||
tcgetattr(RS485_Handle, &RS485_oldtio);
|
||||
/* we read the old serial setup */
|
||||
ioctl (RS485_Handle, TIOCGSERIAL, &RS485_oldserial);
|
||||
ioctl(RS485_Handle, TIOCGSERIAL, &RS485_oldserial);
|
||||
/* we need a copy of existing settings */
|
||||
memcpy (&newserial, &RS485_oldserial, sizeof (struct serial_struct));
|
||||
memcpy(&newserial, &RS485_oldserial, sizeof(struct serial_struct));
|
||||
/* clear struct for new port settings */
|
||||
bzero(&newtio, sizeof(newtio));
|
||||
/*
|
||||
@@ -599,19 +593,21 @@ void RS485_Initialize(
|
||||
/* 76800, custom divisor must be set */
|
||||
newserial.flags |= ASYNC_SPD_CUST;
|
||||
newserial.custom_divisor =
|
||||
round (((float)newserial.baud_base)/76800);
|
||||
round(((float) newserial.baud_base) / 76800);
|
||||
/* we must check that we calculated some sane value;
|
||||
small baud bases yield bad custom divisor values */
|
||||
baud_error = fabs (1 -((float)newserial.baud_base)/
|
||||
((float)newserial.custom_divisor)/76800);
|
||||
small baud bases yield bad custom divisor values */
|
||||
baud_error =
|
||||
fabs(1 -
|
||||
((float) newserial.baud_base) /
|
||||
((float) newserial.custom_divisor) / 76800);
|
||||
if ((newserial.custom_divisor == 0) || (baud_error > 0.02)) {
|
||||
/* bad divisor */
|
||||
fprintf (stderr, "bad custom divisor %d, base baud %d\n",
|
||||
fprintf(stderr, "bad custom divisor %d, base baud %d\n",
|
||||
newserial.custom_divisor, newserial.baud_base);
|
||||
exit (EXIT_FAILURE);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
/* if all goes well, set new divisor */
|
||||
ioctl (RS485_Handle, TIOCSSERIAL, &newserial);
|
||||
ioctl(RS485_Handle, TIOCSSERIAL, &newserial);
|
||||
}
|
||||
|
||||
/* destructor */
|
||||
|
||||
@@ -94,7 +94,7 @@ uint16_t bip_get_port(
|
||||
|
||||
static void bip_mac_to_addr(
|
||||
struct ip_addr *address,
|
||||
uint8_t *mac)
|
||||
uint8_t * mac)
|
||||
{
|
||||
if (mac && address) {
|
||||
address->addr = ((u32_t) ((((uint32_t) mac[0]) << 24) & 0xff000000));
|
||||
@@ -105,14 +105,14 @@ static void bip_mac_to_addr(
|
||||
}
|
||||
|
||||
static void bip_addr_to_mac(
|
||||
uint8_t *mac,
|
||||
uint8_t * mac,
|
||||
struct ip_addr *address)
|
||||
{
|
||||
if (mac && address) {
|
||||
mac[0] = (uint8_t)(address->addr >> 24);
|
||||
mac[1] = (uint8_t)(address->addr >> 16);
|
||||
mac[2] = (uint8_t)(address->addr >> 8);
|
||||
mac[3] = (uint8_t)(address->addr);
|
||||
mac[0] = (uint8_t) (address->addr >> 24);
|
||||
mac[1] = (uint8_t) (address->addr >> 16);
|
||||
mac[2] = (uint8_t) (address->addr >> 8);
|
||||
mac[3] = (uint8_t) (address->addr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ int bip_send_pdu(
|
||||
if (pkt == NULL) {
|
||||
return 0;
|
||||
}
|
||||
mtu = (uint8_t *)pkt->payload;
|
||||
mtu = (uint8_t *) pkt->payload;
|
||||
mtu[0] = BVLL_TYPE_BACNET_IP;
|
||||
if (dest->net == BACNET_BROADCAST_NETWORK) {
|
||||
/* broadcast */
|
||||
@@ -209,7 +209,7 @@ void bip_server_callback(
|
||||
}; /* address where message came from */
|
||||
struct ip_addr sin_addr;
|
||||
uint16_t sin_port = 0;
|
||||
uint8_t *pdu = (uint8_t *)pkt->payload;
|
||||
uint8_t *pdu = (uint8_t *) pkt->payload;
|
||||
|
||||
/* the signature of a BACnet/IP packet */
|
||||
if (pdu[0] != BVLL_TYPE_BACNET_IP) {
|
||||
@@ -219,8 +219,7 @@ void bip_server_callback(
|
||||
if ((function == BVLC_ORIGINAL_UNICAST_NPDU) ||
|
||||
(function == BVLC_ORIGINAL_BROADCAST_NPDU)) {
|
||||
/* ignore messages from me */
|
||||
if ((addr->addr == BIP_Address.s_addr) &&
|
||||
(port == BIP_Port)) {
|
||||
if ((addr->addr == BIP_Address.s_addr) && (port == BIP_Port)) {
|
||||
pdu_len = 0;
|
||||
} else {
|
||||
/* data in src->mac[] is in network format */
|
||||
@@ -236,8 +235,7 @@ void bip_server_callback(
|
||||
} else if (function == BVLC_FORWARDED_NPDU) {
|
||||
bip_mac_to_addr(&sin_addr, &pdu[4]);
|
||||
memcpy(&sin_port, &pdu[8], 2);
|
||||
if ((sin_addr.addr == BIP_Address.s_addr) &&
|
||||
(sin_port == BIP_Port)) {
|
||||
if ((sin_addr.addr == BIP_Address.s_addr) && (sin_port == BIP_Port)) {
|
||||
/* ignore forwarded messages from me */
|
||||
pdu_len = 0;
|
||||
} else {
|
||||
@@ -326,12 +324,13 @@ void bip_get_broadcast_address(
|
||||
bool bip_init(
|
||||
char *ifname)
|
||||
{
|
||||
(void)ifname;
|
||||
(void) ifname;
|
||||
/* Create a new UDP control block */
|
||||
Server_upcb = udp_new();
|
||||
if (Server_upcb == NULL) {
|
||||
/* increase MEMP_NUM_UDP_PCB in lwipopts.h */
|
||||
while(1) {};
|
||||
while (1) {
|
||||
};
|
||||
}
|
||||
/* Bind the upcb to the UDP_PORT port */
|
||||
/* Using IP_ADDR_ANY allow the upcb to be used by any local interface */
|
||||
|
||||
@@ -39,17 +39,17 @@
|
||||
|
||||
/* members are in network byte order */
|
||||
struct sockaddr_in {
|
||||
u8_t sin_len;
|
||||
u8_t sin_family;
|
||||
u16_t sin_port;
|
||||
struct in_addr sin_addr;
|
||||
char sin_zero[8];
|
||||
u8_t sin_len;
|
||||
u8_t sin_family;
|
||||
u16_t sin_port;
|
||||
struct in_addr sin_addr;
|
||||
char sin_zero[8];
|
||||
};
|
||||
|
||||
struct sockaddr {
|
||||
u8_t sa_len;
|
||||
u8_t sa_family;
|
||||
char sa_data[14];
|
||||
u8_t sa_len;
|
||||
u8_t sa_family;
|
||||
char sa_data[14];
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -73,7 +73,7 @@ char *Analog_Input_Name(
|
||||
static char text_string[16] = ""; /* okay for single thread */
|
||||
|
||||
if (object_instance < MAX_ANALOG_INPUTS) {
|
||||
sprintf(text_string, "AI-%lu", (unsigned long)object_instance);
|
||||
sprintf(text_string, "AI-%lu", (unsigned long) object_instance);
|
||||
return text_string;
|
||||
}
|
||||
|
||||
@@ -172,4 +172,3 @@ int Analog_Input_Read_Property(
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
|
||||
@@ -333,8 +333,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
|
||||
|
||||
@@ -158,7 +158,8 @@ int Binary_Value_Read_Property(
|
||||
encode_application_enumerated(&apdu[0], OBJECT_BINARY_VALUE);
|
||||
break;
|
||||
case PROP_PRESENT_VALUE:
|
||||
present_value = Binary_Value_Present_Value(rpdata->object_instance);
|
||||
present_value =
|
||||
Binary_Value_Present_Value(rpdata->object_instance);
|
||||
apdu_len = encode_application_enumerated(&apdu[0], present_value);
|
||||
break;
|
||||
case PROP_STATUS_FLAGS:
|
||||
@@ -245,8 +246,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;
|
||||
|
||||
@@ -85,7 +85,7 @@ BACNET_REINITIALIZED_STATE Device_Reinitialized_State(
|
||||
void Device_Init(
|
||||
object_functions_t * object_table)
|
||||
{
|
||||
(void)object_table;
|
||||
(void) object_table;
|
||||
Reinitialize_State = BACNET_REINIT_IDLE;
|
||||
dcc_set_status_duration(COMMUNICATION_ENABLE, 0);
|
||||
/* FIXME: Get the data from the eeprom */
|
||||
@@ -420,10 +420,8 @@ int Device_Read_Property_Local(
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (Device_Object_List_Identifier(
|
||||
rpdata->array_index,
|
||||
&object_type,
|
||||
&instance))
|
||||
if (Device_Object_List_Identifier(rpdata->array_index,
|
||||
&object_type, &instance))
|
||||
apdu_len =
|
||||
encode_application_object_id(&apdu[0], object_type,
|
||||
instance);
|
||||
@@ -586,8 +584,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 {
|
||||
@@ -646,11 +644,13 @@ bool Device_Write_Property_Local(
|
||||
the device. */
|
||||
} else {
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
wp_data->error_code = ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY;
|
||||
wp_data->error_code =
|
||||
ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY;
|
||||
}
|
||||
} else {
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
wp_data->error_code = ERROR_CODE_CHARACTER_SET_NOT_SUPPORTED;
|
||||
wp_data->error_code =
|
||||
ERROR_CODE_CHARACTER_SET_NOT_SUPPORTED;
|
||||
}
|
||||
} else {
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
|
||||
@@ -916,8 +916,7 @@ bool MSTP_Master_Node_FSM(
|
||||
should be sent is unknown - so PollForMaster */
|
||||
mstp_port->Poll_Station = next_this_station;
|
||||
MSTP_Create_And_Send_Frame(mstp_port,
|
||||
FRAME_TYPE_POLL_FOR_MASTER,
|
||||
mstp_port->Poll_Station,
|
||||
FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station,
|
||||
mstp_port->This_Station, NULL, 0);
|
||||
mstp_port->RetryCount = 0;
|
||||
mstp_port->master_state = MSTP_MASTER_STATE_POLL_FOR_MASTER;
|
||||
@@ -1150,10 +1149,10 @@ bool MSTP_Master_Node_FSM(
|
||||
see if the message is that same APDU type
|
||||
along with the matching src/dest and invoke ID */
|
||||
matched =
|
||||
mstp_compare_data_expecting_reply(&mstp_port->
|
||||
InputBuffer[0], mstp_port->DataLength,
|
||||
mstp_port->SourceAddress, &mstp_port->TxBuffer[0],
|
||||
mstp_port->TxLength, mstp_port->TxDestination);
|
||||
mstp_compare_data_expecting_reply(&mstp_port->InputBuffer
|
||||
[0], mstp_port->DataLength, mstp_port->SourceAddress,
|
||||
&mstp_port->TxBuffer[0], mstp_port->TxLength,
|
||||
mstp_port->TxDestination);
|
||||
}
|
||||
if (matched && mstp_port->TxReady) {
|
||||
/* Reply */
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -436,8 +436,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
|
||||
|
||||
@@ -838,8 +838,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 {
|
||||
@@ -873,8 +873,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;
|
||||
@@ -883,8 +883,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;
|
||||
@@ -894,8 +894,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;
|
||||
|
||||
@@ -437,8 +437,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
|
||||
|
||||
@@ -841,8 +841,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 {
|
||||
@@ -894,13 +894,13 @@ bool Device_Write_Property_Local(
|
||||
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)) {
|
||||
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);
|
||||
status = true;
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -112,7 +112,7 @@ bool rs485_receive_error(
|
||||
return false;
|
||||
}
|
||||
|
||||
/*********************************************************************//**
|
||||
/*********************************************************************//**
|
||||
* @brief USARTx interrupt handler sub-routine
|
||||
* @param[in] None
|
||||
* @return None
|
||||
|
||||
@@ -73,13 +73,13 @@ static uint8_t Tusage_timeout = 50;
|
||||
|
||||
/* Timer that indicates line silence - and functions */
|
||||
static uint32_t Timer_Silence(
|
||||
void * pArg)
|
||||
void *pArg)
|
||||
{
|
||||
return timer_milliseconds(TIMER_SILENCE);
|
||||
}
|
||||
|
||||
static void Timer_Silence_Reset(
|
||||
void * pArg)
|
||||
void *pArg)
|
||||
{
|
||||
timer_reset(TIMER_SILENCE);
|
||||
}
|
||||
@@ -259,7 +259,7 @@ uint16_t MSTP_Put_Receive(
|
||||
Receive_Packet.pdu_len = mstp_port->DataLength;
|
||||
Receive_Packet.ready = true;
|
||||
rc = ReleaseSemaphore(Receive_Packet_Flag, 1, NULL);
|
||||
(void)rc;
|
||||
(void) rc;
|
||||
}
|
||||
|
||||
return pdu_len;
|
||||
|
||||
Reference in New Issue
Block a user