indented to standard from script
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -193,10 +193,10 @@ static int Read_Property_Common(
|
||||
apdu_len = BACNET_STATUS_ERROR;
|
||||
} else {
|
||||
characterstring_init_ansi(&char_string, "");
|
||||
if (pObject->Object_Name) {
|
||||
(void) pObject->Object_Name(rpdata->object_instance,
|
||||
&char_string);
|
||||
}
|
||||
if (pObject->Object_Name) {
|
||||
(void) pObject->Object_Name(rpdata->object_instance,
|
||||
&char_string);
|
||||
}
|
||||
apdu_len =
|
||||
encode_application_character_string(&apdu[0],
|
||||
&char_string);
|
||||
@@ -615,7 +615,7 @@ bool Device_Valid_Object_Id(
|
||||
}
|
||||
|
||||
bool Device_Object_Name_Copy(
|
||||
BACNET_OBJECT_TYPE object_type,
|
||||
BACNET_OBJECT_TYPE object_type,
|
||||
uint32_t object_instance,
|
||||
BACNET_CHARACTER_STRING * object_name)
|
||||
{
|
||||
@@ -850,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 {
|
||||
@@ -903,13 +903,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 {
|
||||
|
||||
@@ -1119,8 +1119,7 @@ static bool MSTP_Master_Node_FSM(
|
||||
Master_State = MSTP_MASTER_STATE_IDLE;
|
||||
/* clear our flag we were holding for comparison */
|
||||
MSTP_Flag.ReceivedValidFrame = false;
|
||||
} else if ((Timer_Silence() > Treply_delay) ||
|
||||
(pkt != NULL)) {
|
||||
} else if ((Timer_Silence() > Treply_delay) || (pkt != NULL)) {
|
||||
/* DeferredReply */
|
||||
/* If no reply will be available from the higher layers */
|
||||
/* within Treply_delay after the reception of the */
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -49,7 +49,7 @@ static BACNET_DEVICE_STATUS System_Status = STATUS_OPERATIONAL;
|
||||
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 */
|
||||
|
||||
@@ -60,22 +60,17 @@ bool bacnet_name_save(
|
||||
char *str,
|
||||
uint8_t length)
|
||||
{
|
||||
uint8_t buffer[NV_EEPROM_NAME_SIZE] = {0};
|
||||
uint8_t buffer[NV_EEPROM_NAME_SIZE] = { 0 };
|
||||
uint8_t i = 0;
|
||||
|
||||
if (bacnet_name_isvalid(encoding, length, str)) {
|
||||
eeprom_bytes_write(
|
||||
NV_EEPROM_NAME_LENGTH(offset),
|
||||
&length, 1);
|
||||
eeprom_bytes_write(
|
||||
NV_EEPROM_NAME_ENCODING(offset),
|
||||
(uint8_t *)&encoding, 1);
|
||||
eeprom_bytes_write(NV_EEPROM_NAME_LENGTH(offset), &length, 1);
|
||||
eeprom_bytes_write(NV_EEPROM_NAME_ENCODING(offset),
|
||||
(uint8_t *) & encoding, 1);
|
||||
for (i = 0; i < length; i++) {
|
||||
buffer[i] = str[i];
|
||||
}
|
||||
eeprom_bytes_write(
|
||||
NV_EEPROM_NAME_STRING(offset),
|
||||
&buffer[0],
|
||||
eeprom_bytes_write(NV_EEPROM_NAME_STRING(offset), &buffer[0],
|
||||
NV_EEPROM_NAME_SIZE);
|
||||
return true;
|
||||
}
|
||||
@@ -118,8 +113,8 @@ bool bacnet_name_write_unique(
|
||||
} else if (length <= NV_EEPROM_NAME_SIZE) {
|
||||
encoding = characterstring_encoding(char_string);
|
||||
if (encoding < MAX_CHARACTER_STRING_ENCODING) {
|
||||
if (Device_Valid_Object_Name(char_string,
|
||||
&duplicate_type, &duplicate_instance)) {
|
||||
if (Device_Valid_Object_Name(char_string, &duplicate_type,
|
||||
&duplicate_instance)) {
|
||||
if ((duplicate_type == object_type) &&
|
||||
(duplicate_instance == object_instance)) {
|
||||
/* writing same name to same object */
|
||||
@@ -185,8 +180,8 @@ void bacnet_name_init(
|
||||
uint16_t offset,
|
||||
char *default_string)
|
||||
{
|
||||
(void)bacnet_name_save(offset, CHARACTER_UTF8,
|
||||
default_string, strlen(default_string));
|
||||
(void) bacnet_name_save(offset, CHARACTER_UTF8, default_string,
|
||||
strlen(default_string));
|
||||
}
|
||||
|
||||
void bacnet_name(
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -160,7 +160,7 @@ static int Read_Property_Common(
|
||||
BACNET_READ_PROPERTY_DATA * rpdata)
|
||||
{
|
||||
int apdu_len = BACNET_STATUS_ERROR;
|
||||
BACNET_CHARACTER_STRING char_string = {0};
|
||||
BACNET_CHARACTER_STRING char_string = { 0 };
|
||||
uint8_t *apdu = NULL;
|
||||
|
||||
if ((rpdata->application_data == NULL) ||
|
||||
@@ -579,7 +579,7 @@ 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))) {
|
||||
@@ -605,7 +605,7 @@ bool Device_Valid_Object_Id(
|
||||
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);
|
||||
}
|
||||
@@ -614,7 +614,7 @@ bool Device_Valid_Object_Id(
|
||||
}
|
||||
|
||||
bool Device_Object_Name_Copy(
|
||||
BACNET_OBJECT_TYPE object_type,
|
||||
BACNET_OBJECT_TYPE object_type,
|
||||
uint32_t object_instance,
|
||||
BACNET_CHARACTER_STRING * object_name)
|
||||
{
|
||||
@@ -650,7 +650,7 @@ int Device_Read_Property_Local(
|
||||
}
|
||||
apdu = rpdata->application_data;
|
||||
switch (rpdata->object_property) {
|
||||
/* object name, object id, object type are handled in Device object */
|
||||
/* object name, object id, object type are handled in Device object */
|
||||
case PROP_DESCRIPTION:
|
||||
bacnet_name(NV_EEPROM_DEVICE_DESCRIPTION, &char_string,
|
||||
"BACnet Development Kit");
|
||||
@@ -856,8 +856,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))) {
|
||||
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 */
|
||||
@@ -902,12 +902,10 @@ bool Device_Write_Property_Local(
|
||||
break;
|
||||
case PROP_OBJECT_NAME:
|
||||
if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) {
|
||||
status = bacnet_name_write_unique(
|
||||
NV_EEPROM_DEVICE_NAME,
|
||||
value.type.Object_Id.type,
|
||||
value.type.Object_Id.instance,
|
||||
&value.type.Character_String,
|
||||
&wp_data->error_class,
|
||||
status =
|
||||
bacnet_name_write_unique(NV_EEPROM_DEVICE_NAME,
|
||||
value.type.Object_Id.type, value.type.Object_Id.instance,
|
||||
&value.type.Character_String, &wp_data->error_class,
|
||||
&wp_data->error_code);
|
||||
} else {
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
|
||||
@@ -372,7 +372,7 @@ static void MSTP_Send_Frame(
|
||||
uint8_t crc8 = 0xFF; /* used to calculate the crc value */
|
||||
uint16_t crc16 = 0xFFFF; /* used to calculate the crc value */
|
||||
uint8_t buffer[8]; /* stores the header and header crc */
|
||||
uint8_t buffer_crc[2]; /* stores the data crc */
|
||||
uint8_t buffer_crc[2]; /* stores the data crc */
|
||||
uint16_t i = 0; /* used to calculate CRC for data */
|
||||
|
||||
/* create the MS/TP header */
|
||||
|
||||
@@ -273,8 +273,11 @@ typedef struct {
|
||||
#endif
|
||||
#elif defined (__CROSSWORKS_AVR)
|
||||
/* use functions defined in crt0.s to mimic IAR macros */
|
||||
void __uint8_eeprom_store(unsigned char byte, unsigned addr);
|
||||
unsigned char __uint8_eeprom_load(unsigned addr);
|
||||
void __uint8_eeprom_store(
|
||||
unsigned char byte,
|
||||
unsigned addr);
|
||||
unsigned char __uint8_eeprom_load(
|
||||
unsigned addr);
|
||||
#define __EEPUT(addr, var) \
|
||||
__uint8_eeprom_store((unsigned char)(var), (unsigned)(addr))
|
||||
#define __EEGET(var, addr) \
|
||||
|
||||
@@ -218,7 +218,7 @@ int seeprom_bytes_read(
|
||||
the slave, or it can leave the SDA line high (NACK), indicating to
|
||||
the slave that it is going to stop the transfer now.
|
||||
Assertion of ACK is handled by setting the TWEA bit in TWCR when
|
||||
starting the current transfer.*/
|
||||
starting the current transfer. */
|
||||
/* Next cycle(s): master receiver mode */
|
||||
/* send repeated start condition */
|
||||
TWCR = _BV(TWINT) | _BV(TWSTA) | _BV(TWEN);
|
||||
|
||||
@@ -163,19 +163,22 @@ void test_task(
|
||||
rs485_baud_rate_set(9600);
|
||||
break;
|
||||
case 'e':
|
||||
seeprom_bytes_read(NV_SEEPROM_TYPE_0, (uint8_t *) &id, 2);
|
||||
seeprom_bytes_read(NV_SEEPROM_TYPE_0, (uint8_t *) & id, 2);
|
||||
sprintf(Send_Buffer, "\r\n%04X", id);
|
||||
serial_bytes_send((uint8_t *) Send_Buffer, strlen(Send_Buffer));
|
||||
serial_bytes_send((uint8_t *) Send_Buffer,
|
||||
strlen(Send_Buffer));
|
||||
break;
|
||||
case 'b':
|
||||
sprintf(Send_Buffer, "\r\n%lubps",
|
||||
(unsigned long) rs485_baud_rate());
|
||||
serial_bytes_send((uint8_t *) Send_Buffer, strlen(Send_Buffer));
|
||||
serial_bytes_send((uint8_t *) Send_Buffer,
|
||||
strlen(Send_Buffer));
|
||||
break;
|
||||
case 'm':
|
||||
sprintf(Send_Buffer, "\r\nMax:%u",
|
||||
(unsigned) dlmstp_max_master());
|
||||
serial_bytes_send((uint8_t *) Send_Buffer, strlen(Send_Buffer));
|
||||
serial_bytes_send((uint8_t *) Send_Buffer,
|
||||
strlen(Send_Buffer));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -242,7 +242,7 @@ static void *dlmstp_master_fsm_task(
|
||||
}
|
||||
if (run_master) {
|
||||
if (MSTP_Port.This_Station <= DEFAULT_MAX_MASTER) {
|
||||
while (MSTP_Master_Node_FSM (&MSTP_Port)) {
|
||||
while (MSTP_Master_Node_FSM(&MSTP_Port)) {
|
||||
/* do nothing while immediate transitioning */
|
||||
}
|
||||
} else if (MSTP_Port.This_Station < 255) {
|
||||
@@ -323,14 +323,9 @@ uint16_t MSTP_Get_Send(
|
||||
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);
|
||||
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);
|
||||
|
||||
return pdu_len;
|
||||
}
|
||||
@@ -369,8 +364,7 @@ static bool dlmstp_compare_data_expecting_reply(
|
||||
if (request.npdu_data.network_layer_message) {
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr,
|
||||
"DLMSTP: DER Compare failed: "
|
||||
"Request is Network message.\n");
|
||||
"DLMSTP: DER Compare failed: " "Request is Network message.\n");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
@@ -378,8 +372,7 @@ static bool dlmstp_compare_data_expecting_reply(
|
||||
if (request.pdu_type != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) {
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr,
|
||||
"DLMSTP: DER Compare failed: "
|
||||
"Not Confirmed Request.\n");
|
||||
"DLMSTP: DER Compare failed: " "Not Confirmed Request.\n");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
@@ -398,8 +391,7 @@ static bool dlmstp_compare_data_expecting_reply(
|
||||
if (reply.npdu_data.network_layer_message) {
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr,
|
||||
"DLMSTP: DER Compare failed: "
|
||||
"Reply is Network message.\n");
|
||||
"DLMSTP: DER Compare failed: " "Reply is Network message.\n");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
@@ -445,26 +437,23 @@ static bool dlmstp_compare_data_expecting_reply(
|
||||
(reply.pdu_type == PDU_TYPE_ABORT)) {
|
||||
if (request.invoke_id != reply.invoke_id) {
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr,
|
||||
"DLMSTP: DER Compare failed: "
|
||||
"Invoke ID mismatch.\n");
|
||||
fprintf(stderr,
|
||||
"DLMSTP: DER Compare failed: " "Invoke ID mismatch.\n");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (request.invoke_id != reply.invoke_id) {
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr,
|
||||
"DLMSTP: DER Compare failed: "
|
||||
"Invoke ID mismatch.\n");
|
||||
fprintf(stderr,
|
||||
"DLMSTP: DER Compare failed: " "Invoke ID mismatch.\n");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
if (request.service_choice != reply.service_choice) {
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr,
|
||||
"DLMSTP: DER Compare failed: "
|
||||
"Service choice mismatch.\n");
|
||||
fprintf(stderr,
|
||||
"DLMSTP: DER Compare failed: " "Service choice mismatch.\n");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
@@ -480,16 +469,14 @@ static bool dlmstp_compare_data_expecting_reply(
|
||||
if (request.npdu_data.priority != reply.npdu_data.priority) {
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr,
|
||||
"DLMSTP: DER Compare failed: "
|
||||
"NPDU Priority mismatch.\n");
|
||||
"DLMSTP: DER Compare failed: " "NPDU Priority mismatch.\n");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
if (!bacnet_address_same(&request.address, &reply.address)) {
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr,
|
||||
"DLMSTP: DER Compare failed: "
|
||||
"BACnet Address mismatch.\n");
|
||||
"DLMSTP: DER Compare failed: " "BACnet Address mismatch.\n");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
@@ -514,13 +501,9 @@ uint16_t MSTP_Get_Reply(
|
||||
pkt = (struct mstp_pdu_packet *) Ringbuf_Get_Front(&PDU_Queue);
|
||||
/* is this the reply to the DER? */
|
||||
matched =
|
||||
dlmstp_compare_data_expecting_reply(
|
||||
&mstp_port->InputBuffer[0],
|
||||
mstp_port->DataLength,
|
||||
mstp_port->SourceAddress,
|
||||
(uint8_t *) & pkt->buffer[0],
|
||||
pkt->length,
|
||||
pkt->destination_mac);
|
||||
dlmstp_compare_data_expecting_reply(&mstp_port->InputBuffer[0],
|
||||
mstp_port->DataLength, mstp_port->SourceAddress,
|
||||
(uint8_t *) & pkt->buffer[0], pkt->length, pkt->destination_mac);
|
||||
if (!matched) {
|
||||
return 0;
|
||||
}
|
||||
@@ -531,14 +514,9 @@ uint16_t MSTP_Get_Reply(
|
||||
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);
|
||||
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);
|
||||
|
||||
return pdu_len;
|
||||
}
|
||||
@@ -678,8 +656,7 @@ bool dlmstp_init(
|
||||
|
||||
/* initialize PDU queue */
|
||||
Ringbuf_Init(&PDU_Queue, (uint8_t *) & PDU_Buffer,
|
||||
sizeof(struct mstp_pdu_packet),
|
||||
MSTP_PDU_PACKET_COUNT);
|
||||
sizeof(struct mstp_pdu_packet), MSTP_PDU_PACKET_COUNT);
|
||||
/* initialize packet queue */
|
||||
Receive_Packet.ready = false;
|
||||
Receive_Packet.pdu_len = 0;
|
||||
|
||||
@@ -83,7 +83,7 @@ static void Timer_Silence_Reset(
|
||||
|
||||
/* functions used by the MS/TP state machine to put or get data */
|
||||
uint16_t MSTP_Put_Receive(
|
||||
volatile struct mstp_port_struct_t * mstp_port)
|
||||
volatile struct mstp_port_struct_t *mstp_port)
|
||||
{
|
||||
(void) mstp_port;
|
||||
|
||||
@@ -203,7 +203,7 @@ static void snap_received_packet(
|
||||
}
|
||||
/* Ethernet length is data only - not address or length bytes */
|
||||
encode_unsigned16(&mtu[12], mtu_len - 14);
|
||||
(void)write(sockfd, &mtu[0], mtu_len);
|
||||
(void) write(sockfd, &mtu[0], mtu_len);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ uint32_t RS485_Get_Baud_Rate(
|
||||
baud = 200;
|
||||
break;
|
||||
case B300:
|
||||
baud =300;
|
||||
baud = 300;
|
||||
break;
|
||||
case B600:
|
||||
baud = 600;
|
||||
@@ -288,13 +288,13 @@ void RS485_Send_Frame(
|
||||
uint16_t nbytes)
|
||||
{ /* number of bytes of data (up to 501) */
|
||||
uint32_t turnaround_time = Tturnaround * 1000;
|
||||
uint32_t baud = RS485_Get_Baud_Rate ();
|
||||
uint32_t baud = RS485_Get_Baud_Rate();
|
||||
ssize_t written = 0;
|
||||
int greska;
|
||||
|
||||
/* sleeping for turnaround time is necessary to give other devices
|
||||
time to change from sending to receiving state. */
|
||||
usleep(turnaround_time/baud);
|
||||
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
|
||||
@@ -354,9 +354,9 @@ void RS485_Check_UART_Data(
|
||||
}
|
||||
}
|
||||
/* 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);
|
||||
FD_ZERO(&input);
|
||||
FD_SET(RS485_Handle, &input);
|
||||
n = select(RS485_Handle + 1, &input, NULL, NULL, &waiter);
|
||||
if (n < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -533,8 +533,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 {
|
||||
|
||||
@@ -115,13 +115,9 @@ int dlmstp_send_pdu(
|
||||
return -4;
|
||||
}
|
||||
bytes_sent =
|
||||
MSTP_Create_Frame(
|
||||
(uint8_t *) & MSTP_Port.TxBuffer[0],
|
||||
sizeof(MSTP_Port.TxBuffer),
|
||||
MSTP_Port.TxFrameType,
|
||||
MSTP_Port.TxDestination,
|
||||
MSTP_Port.This_Station,
|
||||
pdu, pdu_len);
|
||||
MSTP_Create_Frame((uint8_t *) & MSTP_Port.TxBuffer[0],
|
||||
sizeof(MSTP_Port.TxBuffer), MSTP_Port.TxFrameType,
|
||||
MSTP_Port.TxDestination, MSTP_Port.This_Station, pdu, pdu_len);
|
||||
MSTP_Port.TxLength = bytes_sent;
|
||||
MSTP_Port.TxReady = true;
|
||||
MSTP_Packets++;
|
||||
|
||||
@@ -1145,13 +1145,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 */
|
||||
@@ -1162,8 +1159,7 @@ bool MSTP_Master_Node_FSM(
|
||||
/* then call MSTP_Create_And_Send_Frame to transmit the reply frame */
|
||||
/* and enter the IDLE state to wait for the next frame. */
|
||||
RS485_Send_Frame(mstp_port,
|
||||
(uint8_t *) & mstp_port->TxBuffer[0],
|
||||
mstp_port->TxLength);
|
||||
(uint8_t *) & mstp_port->TxBuffer[0], mstp_port->TxLength);
|
||||
mstp_port->TxReady = false;
|
||||
mstp_port->master_state = MSTP_MASTER_STATE_IDLE;
|
||||
} else {
|
||||
|
||||
@@ -261,8 +261,7 @@ 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
|
||||
|
||||
@@ -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;
|
||||
@@ -948,13 +948,13 @@ bool Device_Write_Property(
|
||||
/** Initialize the Device Object and each of its child Object instances.
|
||||
* @ingroup ObjIntf
|
||||
*/
|
||||
void Device_Init(
|
||||
object_functions_t * object_table)
|
||||
void Device_Init(
|
||||
object_functions_t * object_table)
|
||||
{
|
||||
struct my_object_functions *pObject = NULL;
|
||||
|
||||
/* not using the standard table - using our own */
|
||||
(void)object_table;
|
||||
(void) object_table;
|
||||
pObject = &Object_Table[0];
|
||||
while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) {
|
||||
if (pObject->Object_Init) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -601,7 +601,7 @@ bool Device_Valid_Object_Id(
|
||||
}
|
||||
|
||||
bool Device_Object_Name_Copy(
|
||||
BACNET_OBJECT_TYPE object_type,
|
||||
BACNET_OBJECT_TYPE object_type,
|
||||
uint32_t object_instance,
|
||||
BACNET_CHARACTER_STRING * object_name)
|
||||
{
|
||||
@@ -836,8 +836,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 {
|
||||
@@ -889,13 +889,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 {
|
||||
|
||||
@@ -378,8 +378,7 @@ static bool MSTP_Transmit_FSM(
|
||||
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 *)
|
||||
pkt = (struct mstp_tx_packet *)
|
||||
Ringbuf_Get_Front(&Transmit_Queue);
|
||||
state = MSTP_TX_STATE_SILENCE_WAIT;
|
||||
}
|
||||
@@ -1235,8 +1234,7 @@ static bool MSTP_Master_Node_FSM(
|
||||
Master_State = MSTP_MASTER_STATE_IDLE;
|
||||
/* clear our flag we were holding for comparison */
|
||||
MSTP_Flag.ReceivedValidFrame = false;
|
||||
} else if (rs485_silence_elapsed(Treply_delay) ||
|
||||
(pkt != NULL)) {
|
||||
} else if (rs485_silence_elapsed(Treply_delay) || (pkt != NULL)) {
|
||||
/* DeferredReply */
|
||||
/* If no reply will be available from the higher layers */
|
||||
/* within Treply_delay after the reception of the */
|
||||
|
||||
@@ -112,7 +112,7 @@ bool rs485_receive_error(
|
||||
return false;
|
||||
}
|
||||
|
||||
/*********************************************************************//**
|
||||
/*********************************************************************//**
|
||||
* @brief USARTx interrupt handler sub-routine
|
||||
* @param[in] None
|
||||
* @return None
|
||||
|
||||
@@ -95,7 +95,7 @@ int gettimeofday(
|
||||
time_start = timeGetTime();
|
||||
} else {
|
||||
elapsed_milliseconds = timeGetTime() - time_start;
|
||||
usec_elapsed = usec_timer + ((LONGLONG)elapsed_milliseconds * 1000UL);
|
||||
usec_elapsed = usec_timer + ((LONGLONG) elapsed_milliseconds * 1000UL);
|
||||
tp->tv_sec = (long) (usec_elapsed / 1000000UL);
|
||||
tp->tv_usec = (long) (usec_elapsed % 1000000UL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user