Converted to standard indent style.

This commit is contained in:
skarg
2006-10-07 14:13:34 +00:00
parent 19c5a20205
commit 5dd8c6da91
37 changed files with 873 additions and 896 deletions
+2 -5
View File
@@ -103,9 +103,7 @@ int abort_decode_apdu(uint8_t * apdu,
} }
void testAbortAPDU(Test * pTest, void testAbortAPDU(Test * pTest,
uint8_t invoke_id, uint8_t invoke_id, uint8_t abort_reason, bool server)
uint8_t abort_reason,
bool server)
{ {
uint8_t apdu[480] = { 0 }; uint8_t apdu[480] = { 0 };
int len = 0; int len = 0;
@@ -144,8 +142,7 @@ void testAbort(Test * pTest)
ct_test(pTest, len != 0); ct_test(pTest, len != 0);
apdu_len = len; apdu_len = len;
len = abort_decode_apdu(&apdu[0], len = abort_decode_apdu(&apdu[0],
apdu_len, &test_invoke_id, &test_abort_reason, apdu_len, &test_invoke_id, &test_abort_reason, &test_server);
&test_server);
ct_test(pTest, len != -1); ct_test(pTest, len != -1);
ct_test(pTest, test_invoke_id == invoke_id); ct_test(pTest, test_invoke_id == invoke_id);
ct_test(pTest, test_abort_reason == abort_reason); ct_test(pTest, test_abort_reason == abort_reason);
+1 -2
View File
@@ -1042,8 +1042,7 @@ int encode_tagged_octet_string(uint8_t * apdu,
/* and 20.2.1 General Rules for Encoding BACnet Tags */ /* and 20.2.1 General Rules for Encoding BACnet Tags */
/* returns the number of apdu bytes consumed */ /* returns the number of apdu bytes consumed */
int encode_context_octet_string(uint8_t * apdu, int encode_context_octet_string(uint8_t * apdu,
int tag_number, int tag_number, BACNET_OCTET_STRING * octet_string)
BACNET_OCTET_STRING * octet_string)
{ {
int apdu_len = 0; int apdu_len = 0;
+1 -2
View File
@@ -109,8 +109,7 @@ extern "C" {
int encode_tagged_octet_string(uint8_t * apdu, int encode_tagged_octet_string(uint8_t * apdu,
BACNET_OCTET_STRING * octet_string); BACNET_OCTET_STRING * octet_string);
int encode_context_octet_string(uint8_t * apdu, int encode_context_octet_string(uint8_t * apdu,
int tag_number, int tag_number, BACNET_OCTET_STRING * octet_string);
BACNET_OCTET_STRING * octet_string);
int decode_octet_string(uint8_t * apdu, uint32_t len_value, int decode_octet_string(uint8_t * apdu, uint32_t len_value,
BACNET_OCTET_STRING * octet_string); BACNET_OCTET_STRING * octet_string);
+1 -2
View File
@@ -363,8 +363,7 @@ int npdu_encode_pdu(uint8_t * npdu,
} }
void npdu_encode_npdu_data(BACNET_NPDU_DATA * npdu, void npdu_encode_npdu_data(BACNET_NPDU_DATA * npdu,
bool data_expecting_reply, bool data_expecting_reply, BACNET_MESSAGE_PRIORITY priority)
BACNET_MESSAGE_PRIORITY priority)
{ {
} }
+4 -6
View File
@@ -132,14 +132,13 @@ void handler_atomic_read_file(uint8_t * service_request,
} else if (data.object_type == OBJECT_FILE) { } else if (data.object_type == OBJECT_FILE) {
if (!bacfile_valid_instance(data.object_instance)) { if (!bacfile_valid_instance(data.object_instance)) {
error = true; error = true;
} } else if (data.access == FILE_STREAM_ACCESS) {
else if (data.access == FILE_STREAM_ACCESS) {
if (data.type.stream.requestedOctetCount < if (data.type.stream.requestedOctetCount <
octetstring_capacity(&data.fileData)) { octetstring_capacity(&data.fileData)) {
if (bacfile_read_data(&data)) { if (bacfile_read_data(&data)) {
len = len =
arf_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len], arf_ack_encode_apdu(&Handler_Transmit_Buffer
service_data->invoke_id, &data); [pdu_len], service_data->invoke_id, &data);
} else { } else {
error = true; error = true;
error_class = ERROR_CLASS_OBJECT; error_class = ERROR_CLASS_OBJECT;
@@ -167,8 +166,7 @@ void handler_atomic_read_file(uint8_t * service_request,
error_class = ERROR_CLASS_SERVICES; error_class = ERROR_CLASS_SERVICES;
error_code = ERROR_CODE_FILE_ACCESS_DENIED; error_code = ERROR_CODE_FILE_ACCESS_DENIED;
} }
if (error) if (error) {
{
len = len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, service_data->invoke_id,
+20 -20
View File
@@ -105,8 +105,8 @@ void handler_read_property(uint8_t * service_request,
data.application_data_len = len; data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */ /* FIXME: probably need a length limitation sent with encode */
len = len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len], rp_ack_encode_apdu(&Handler_Transmit_Buffer
service_data->invoke_id, &data); [pdu_len], service_data->invoke_id, &data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Sending Read Property Ack for Device!\n"); "Sending Read Property Ack for Device!\n");
@@ -127,8 +127,8 @@ void handler_read_property(uint8_t * service_request,
data.application_data_len = len; data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */ /* FIXME: probably need a length limitation sent with encode */
len = len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len], rp_ack_encode_apdu(&Handler_Transmit_Buffer
service_data->invoke_id, &data); [pdu_len], service_data->invoke_id, &data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Read Property Ack for AI!\n"); fprintf(stderr, "Sending Read Property Ack for AI!\n");
#endif #endif
@@ -148,8 +148,8 @@ void handler_read_property(uint8_t * service_request,
data.application_data_len = len; data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */ /* FIXME: probably need a length limitation sent with encode */
len = len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len], rp_ack_encode_apdu(&Handler_Transmit_Buffer
service_data->invoke_id, &data); [pdu_len], service_data->invoke_id, &data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Read Property Ack for BI!\n"); fprintf(stderr, "Sending Read Property Ack for BI!\n");
#endif #endif
@@ -169,8 +169,8 @@ void handler_read_property(uint8_t * service_request,
data.application_data_len = len; data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */ /* FIXME: probably need a length limitation sent with encode */
len = len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len], rp_ack_encode_apdu(&Handler_Transmit_Buffer
service_data->invoke_id, &data); [pdu_len], service_data->invoke_id, &data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Read Property Ack for BO!\n"); fprintf(stderr, "Sending Read Property Ack for BO!\n");
#endif #endif
@@ -190,8 +190,8 @@ void handler_read_property(uint8_t * service_request,
data.application_data_len = len; data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */ /* FIXME: probably need a length limitation sent with encode */
len = len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len], rp_ack_encode_apdu(&Handler_Transmit_Buffer
service_data->invoke_id, &data); [pdu_len], service_data->invoke_id, &data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Read Property Ack for BV!\n"); fprintf(stderr, "Sending Read Property Ack for BV!\n");
#endif #endif
@@ -211,8 +211,8 @@ void handler_read_property(uint8_t * service_request,
data.application_data_len = len; data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */ /* FIXME: probably need a length limitation sent with encode */
len = len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len], rp_ack_encode_apdu(&Handler_Transmit_Buffer
service_data->invoke_id, &data); [pdu_len], service_data->invoke_id, &data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Read Property Ack for AO!\n"); fprintf(stderr, "Sending Read Property Ack for AO!\n");
#endif #endif
@@ -232,8 +232,8 @@ void handler_read_property(uint8_t * service_request,
data.application_data_len = len; data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */ /* FIXME: probably need a length limitation sent with encode */
len = len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len], rp_ack_encode_apdu(&Handler_Transmit_Buffer
service_data->invoke_id, &data); [pdu_len], service_data->invoke_id, &data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Sending Read Property Ack for AV!\n"); fprintf(stderr, "Sending Read Property Ack for AV!\n");
#endif #endif
@@ -253,8 +253,8 @@ void handler_read_property(uint8_t * service_request,
data.application_data_len = len; data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */ /* FIXME: probably need a length limitation sent with encode */
len = len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len], rp_ack_encode_apdu(&Handler_Transmit_Buffer
service_data->invoke_id, &data); [pdu_len], service_data->invoke_id, &data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Sending Read Property Ack for LSP!\n"); "Sending Read Property Ack for LSP!\n");
@@ -275,8 +275,8 @@ void handler_read_property(uint8_t * service_request,
data.application_data_len = len; data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */ /* FIXME: probably need a length limitation sent with encode */
len = len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len], rp_ack_encode_apdu(&Handler_Transmit_Buffer
service_data->invoke_id, &data); [pdu_len], service_data->invoke_id, &data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Sending Read Property Ack for MSO!\n"); "Sending Read Property Ack for MSO!\n");
@@ -298,8 +298,8 @@ void handler_read_property(uint8_t * service_request,
data.application_data_len = len; data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */ /* FIXME: probably need a length limitation sent with encode */
len = len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len], rp_ack_encode_apdu(&Handler_Transmit_Buffer
service_data->invoke_id, &data); [pdu_len], service_data->invoke_id, &data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Sending Read Property Ack for File!\n"); "Sending Read Property Ack for File!\n");
+4 -2
View File
@@ -76,8 +76,10 @@ uint8_t Send_Atomic_Write_File_Stream(uint32_t device_id,
if (status) { if (status) {
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, true,
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, MESSAGE_PRIORITY_NORMAL);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest,
&my_address, &npdu_data); &my_address, &npdu_data);
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
len = awf_encode_apdu(&Handler_Transmit_Buffer[pdu_len], len = awf_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
+2 -1
View File
@@ -313,7 +313,8 @@ uint32_t bacfile_instance_from_tsm(uint8_t invokeID)
found = tsm_get_transaction_pdu(invokeID, &dest, &npdu_data, &apdu[0], found = tsm_get_transaction_pdu(invokeID, &dest, &npdu_data, &apdu[0],
&apdu_len); &apdu_len);
if (found) { if (found) {
if (!npdu_data.network_layer_message && npdu_data.data_expecting_reply if (!npdu_data.network_layer_message
&& npdu_data.data_expecting_reply
&& (apdu[0] == PDU_TYPE_CONFIRMED_SERVICE_REQUEST)) { && (apdu[0] == PDU_TYPE_CONFIRMED_SERVICE_REQUEST)) {
len = len =
apdu_decode_confirmed_service_request(&apdu[0], apdu_decode_confirmed_service_request(&apdu[0],
+1 -2
View File
@@ -190,8 +190,7 @@ int npdu_encode_pdu(uint8_t * npdu,
/* Configure the NPDU portion of the packet for an APDU */ /* Configure the NPDU portion of the packet for an APDU */
/* This function does not handle the network messages, just APDUs. */ /* This function does not handle the network messages, just APDUs. */
void npdu_encode_npdu_data(BACNET_NPDU_DATA * npdu_data, void npdu_encode_npdu_data(BACNET_NPDU_DATA * npdu_data,
bool data_expecting_reply, bool data_expecting_reply, BACNET_MESSAGE_PRIORITY priority)
BACNET_MESSAGE_PRIORITY priority)
{ {
if (npdu_data) { if (npdu_data) {
npdu_data->data_expecting_reply = data_expecting_reply; npdu_data->data_expecting_reply = data_expecting_reply;
+1 -2
View File
@@ -63,8 +63,7 @@ extern "C" {
BACNET_ADDRESS * src, BACNET_NPDU_DATA * npdu_data); BACNET_ADDRESS * src, BACNET_NPDU_DATA * npdu_data);
void npdu_encode_npdu_data(BACNET_NPDU_DATA * npdu, void npdu_encode_npdu_data(BACNET_NPDU_DATA * npdu,
bool data_expecting_reply, bool data_expecting_reply, BACNET_MESSAGE_PRIORITY priority);
BACNET_MESSAGE_PRIORITY priority);
void npdu_copy_data(BACNET_NPDU_DATA * dest, BACNET_NPDU_DATA * src); void npdu_copy_data(BACNET_NPDU_DATA * dest, BACNET_NPDU_DATA * src);
+8 -4
View File
@@ -191,14 +191,16 @@ int Device_Encode_Property_APDU(uint8_t * apdu,
apdu_len = encode_tagged_character_string(&apdu[0], &char_string); apdu_len = encode_tagged_character_string(&apdu[0], &char_string);
break; break;
case PROP_SYSTEM_STATUS: case PROP_SYSTEM_STATUS:
apdu_len = encode_tagged_enumerated(&apdu[0], Device_System_Status()); apdu_len =
encode_tagged_enumerated(&apdu[0], Device_System_Status());
break; break;
case PROP_VENDOR_NAME: case PROP_VENDOR_NAME:
characterstring_init_ansi(&char_string, (char *) "ASHRAE"); characterstring_init_ansi(&char_string, (char *) "ASHRAE");
apdu_len = encode_tagged_character_string(&apdu[0], &char_string); apdu_len = encode_tagged_character_string(&apdu[0], &char_string);
break; break;
case PROP_VENDOR_IDENTIFIER: case PROP_VENDOR_IDENTIFIER:
apdu_len = encode_tagged_unsigned(&apdu[0], Device_Vendor_Identifier()); apdu_len =
encode_tagged_unsigned(&apdu[0], Device_Vendor_Identifier());
break; break;
case PROP_MODEL_NAME: case PROP_MODEL_NAME:
characterstring_init_ansi(&char_string, (char *) "GNU"); characterstring_init_ansi(&char_string, (char *) "GNU");
@@ -303,13 +305,15 @@ int Device_Encode_Property_APDU(uint8_t * apdu,
break; break;
case PROP_NUMBER_OF_APDU_RETRIES: case PROP_NUMBER_OF_APDU_RETRIES:
apdu_len = apdu_len =
encode_tagged_unsigned(&apdu[0], Device_Number_Of_APDU_Retries()); encode_tagged_unsigned(&apdu[0],
Device_Number_Of_APDU_Retries());
break; break;
case PROP_DEVICE_ADDRESS_BINDING: case PROP_DEVICE_ADDRESS_BINDING:
/* FIXME: encode the list here, if it exists */ /* FIXME: encode the list here, if it exists */
break; break;
case PROP_DATABASE_REVISION: case PROP_DATABASE_REVISION:
apdu_len = encode_tagged_unsigned(&apdu[0], Device_Database_Revision()); apdu_len =
encode_tagged_unsigned(&apdu[0], Device_Database_Revision());
break; break;
default: default:
*error_class = ERROR_CLASS_PROPERTY; *error_class = ERROR_CLASS_PROPERTY;
+17 -30
View File
@@ -60,22 +60,17 @@ static uint8_t EditField = 0;
ALGORITHM: none ALGORITHM: none
NOTES: Pass a #>0 to increment #<0 to decrement NOTES: Pass a #>0 to increment #<0 to decrement
*************************************************************************** */ *************************************************************************** */
void dlmstp_SetEditField( void dlmstp_SetEditField(signed char state)
signed char state) /* direction our editfield is moving */ { /* direction our editfield is moving */
{ if (state > 0) {
if (state > 0)
{
if (++EditField > MAX_EDIT_FIELD) if (++EditField > MAX_EDIT_FIELD)
EditField = 0; EditField = 0;
} } else if (state < 0) {
else if (state < 0)
{
if (EditField) if (EditField)
EditField--; EditField--;
else else
EditField = MAX_EDIT_FIELD; EditField = MAX_EDIT_FIELD;
} } else
else
EditField = 0; EditField = 0;
} }
@@ -114,23 +109,19 @@ void dlmstp_init(void)
RS485_Initialize(); RS485_Initialize();
MSTP_Port.InputBuffer = &Receive_Buffer.pdu[0]; MSTP_Port.InputBuffer = &Receive_Buffer.pdu[0];
MSTP_Init(&MSTP_Port); MSTP_Init(&MSTP_Port);
data = I2C_Read_Byte( data = I2C_Read_Byte(EEPROM_DEVICE_ADDRESS, EEPROM_MSTP_MAC_ADDR);
EEPROM_DEVICE_ADDRESS,
EEPROM_MSTP_MAC_ADDR);
if (data <= 127) if (data <= 127)
MSTP_Port.This_Station = data; MSTP_Port.This_Station = data;
else else
dlmstp_set_my_address(DEFAULT_MAC_ADDRESS); dlmstp_set_my_address(DEFAULT_MAC_ADDRESS);
data = I2C_Read_Byte( data = I2C_Read_Byte(EEPROM_DEVICE_ADDRESS,
EEPROM_DEVICE_ADDRESS,
EEPROM_MSTP_MAX_MASTER_ADDR); EEPROM_MSTP_MAX_MASTER_ADDR);
if (data <= 127) if (data <= 127)
MSTP_Port.Nmax_master = data; MSTP_Port.Nmax_master = data;
else else
dlmstp_set_max_master(DEFAULT_MAX_MASTER); dlmstp_set_max_master(DEFAULT_MAX_MASTER);
MSTP_Port.Nmax_info_frames = MSTP_Port.Nmax_info_frames =
I2C_Read_Byte( I2C_Read_Byte(EEPROM_DEVICE_ADDRESS,
EEPROM_DEVICE_ADDRESS,
EEPROM_MSTP_MAX_INFO_FRAMES_ADDR); EEPROM_MSTP_MAX_INFO_FRAMES_ADDR);
} }
@@ -173,8 +164,7 @@ int dlmstp_send_pdu(BACNET_ADDRESS * dest, /* destination address */
(uint8_t *) & MSTP_Port.TxBuffer[0], (uint8_t *) & MSTP_Port.TxBuffer[0],
sizeof(MSTP_Port.TxBuffer), sizeof(MSTP_Port.TxBuffer),
MSTP_Port.TxFrameType, MSTP_Port.TxFrameType,
destination, destination, MSTP_Port.This_Station, pdu, pdu_len);
MSTP_Port.This_Station, pdu, pdu_len);
MSTP_Port.TxLength = bytes_sent; MSTP_Port.TxLength = bytes_sent;
MSTP_Port.TxReady = true; MSTP_Port.TxReady = true;
MSTP_Packets++; MSTP_Packets++;
@@ -190,8 +180,7 @@ void dlmstp_task(void)
/* only do receive state machine while we don't have a frame */ /* only do receive state machine while we don't have a frame */
if ((MSTP_Port.ReceivedValidFrame == false) && if ((MSTP_Port.ReceivedValidFrame == false) &&
(MSTP_Port.ReceivedInvalidFrame == false)) (MSTP_Port.ReceivedInvalidFrame == false)) {
{
do { do {
bytes_remaining = RS485_Check_UART_Data(&MSTP_Port); bytes_remaining = RS485_Check_UART_Data(&MSTP_Port);
MSTP_Receive_Frame_FSM(&MSTP_Port); MSTP_Receive_Frame_FSM(&MSTP_Port);
@@ -203,7 +192,8 @@ void dlmstp_task(void)
} }
/* only do master state machine while rx is idle */ /* only do master state machine while rx is idle */
if (MSTP_Port.receive_state == MSTP_RECEIVE_STATE_IDLE) { if (MSTP_Port.receive_state == MSTP_RECEIVE_STATE_IDLE) {
while (MSTP_Master_Node_FSM(&MSTP_Port)) {}; while (MSTP_Master_Node_FSM(&MSTP_Port)) {
};
/*MSTP_Master_Node_FSM(&MSTP_Port); */ /*MSTP_Master_Node_FSM(&MSTP_Port); */
} }
/* see if there is a packet available, and a place /* see if there is a packet available, and a place
@@ -211,10 +201,8 @@ void dlmstp_task(void)
if (Receive_Buffer.ready && !MSTP_Port.TxReady) { if (Receive_Buffer.ready && !MSTP_Port.TxReady) {
if (Receive_Buffer.pdu_len) { if (Receive_Buffer.pdu_len) {
MSTP_Packets++; MSTP_Packets++;
npdu_handler( npdu_handler(&Receive_Buffer.address,
&Receive_Buffer.address, &Receive_Buffer.pdu[0], Receive_Buffer.pdu_len);
&Receive_Buffer.pdu[0],
Receive_Buffer.pdu_len);
} }
Receive_Buffer.ready = false; Receive_Buffer.ready = false;
} }
@@ -246,11 +234,10 @@ void dlmstp_fill_bacnet_address(BACNET_ADDRESS * src, uint8_t mstp_address)
} }
/* for the MS/TP state machine to use for putting received data */ /* for the MS/TP state machine to use for putting received data */
uint16_t dlmstp_put_receive( uint16_t dlmstp_put_receive(uint8_t src, /* source MS/TP address */
uint8_t src, /* source MS/TP address */
uint8_t * pdu, /* PDU data */ uint8_t * pdu, /* PDU data */
uint16_t pdu_len) /* amount of PDU data */ uint16_t pdu_len)
{ { /* amount of PDU data */
/* PDU is already in the Receive_Buffer */ /* PDU is already in the Receive_Buffer */
dlmstp_fill_bacnet_address(&Receive_Buffer.address, src); dlmstp_fill_bacnet_address(&Receive_Buffer.address, src);
Receive_Buffer.pdu_len = pdu_len; Receive_Buffer.pdu_len = pdu_len;
+2 -2
View File
@@ -101,8 +101,8 @@ void My_Read_Property_Handler(uint8_t * service_request,
data.application_data_len = len; data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */ /* FIXME: probably need a length limitation sent with encode */
len = len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len], rp_ack_encode_apdu(&Handler_Transmit_Buffer
service_data->invoke_id, &data); [pdu_len], service_data->invoke_id, &data);
} else } else
error = true; error = true;
} else } else
+8 -4
View File
@@ -450,7 +450,8 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port)
/* wait for the start of the next frame. */ /* wait for the start of the next frame. */
mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE;
} else { } else {
if ((mstp_port->DestinationAddress == mstp_port->This_Station) if ((mstp_port->DestinationAddress ==
mstp_port->This_Station)
|| (mstp_port->DestinationAddress == || (mstp_port->DestinationAddress ==
MSTP_BROADCAST_ADDRESS)) { MSTP_BROADCAST_ADDRESS)) {
/* FrameTooLong */ /* FrameTooLong */
@@ -459,21 +460,24 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port)
/* unacceptable data length has been received */ /* unacceptable data length has been received */
mstp_port->ReceivedInvalidFrame = true; mstp_port->ReceivedInvalidFrame = true;
/* wait for the start of the next frame. */ /* wait for the start of the next frame. */
mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; mstp_port->receive_state =
MSTP_RECEIVE_STATE_IDLE;
} }
/* NoData */ /* NoData */
else if (mstp_port->DataLength == 0) { else if (mstp_port->DataLength == 0) {
/* indicate that a frame with no data has been received */ /* indicate that a frame with no data has been received */
mstp_port->ReceivedValidFrame = true; mstp_port->ReceivedValidFrame = true;
/* wait for the start of the next frame. */ /* wait for the start of the next frame. */
mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; mstp_port->receive_state =
MSTP_RECEIVE_STATE_IDLE;
} }
/* Data */ /* Data */
else { else {
mstp_port->Index = 0; mstp_port->Index = 0;
mstp_port->DataCRC = 0xFFFF; mstp_port->DataCRC = 0xFFFF;
/* receive the data portion of the frame. */ /* receive the data portion of the frame. */
mstp_port->receive_state = MSTP_RECEIVE_STATE_DATA; mstp_port->receive_state =
MSTP_RECEIVE_STATE_DATA;
} }
} }
/* NotForUs */ /* NotForUs */
+21 -32
View File
@@ -59,8 +59,8 @@ volatile uint8_t RS485_Tx_Buffer[MAX_MPDU];
*****************************************************************************/ *****************************************************************************/
void RS485_Send_Frame(volatile struct mstp_port_struct_t *mstp_port, /* port specific data */ void RS485_Send_Frame(volatile struct mstp_port_struct_t *mstp_port, /* port specific data */
uint8_t * buffer, /* frame to send (up to 501 bytes of data) */ uint8_t * buffer, /* frame to send (up to 501 bytes of data) */
uint16_t nbytes) /* number of bytes of data (up to 501) */ uint16_t nbytes)
{ { /* number of bytes of data (up to 501) */
uint16_t i = 0; /* loop counter */ uint16_t i = 0; /* loop counter */
uint8_t turnaround_time; uint8_t turnaround_time;
@@ -72,7 +72,8 @@ void RS485_Send_Frame(volatile struct mstp_port_struct_t *mstp_port, /* port
return; return;
/* buffer is full. Wait for ISR to transmit. */ /* buffer is full. Wait for ISR to transmit. */
while (RS485_Comstat.Tx_Bytes) {}; while (RS485_Comstat.Tx_Bytes) {
};
/* wait 40 bit times since reception */ /* wait 40 bit times since reception */
if (RS485_Baud_Rate == 9600) if (RS485_Baud_Rate == 9600)
@@ -82,7 +83,8 @@ void RS485_Send_Frame(volatile struct mstp_port_struct_t *mstp_port, /* port
else else
turnaround_time = 1; turnaround_time = 1;
while (mstp_port->SilenceTimer < turnaround_time) {}; while (mstp_port->SilenceTimer < turnaround_time) {
};
RS485_Comstat.TxHead = 0; RS485_Comstat.TxHead = 0;
memcpy((void *) &RS485_Tx_Buffer[0], (void *) buffer, nbytes); memcpy((void *) &RS485_Tx_Buffer[0], (void *) buffer, nbytes);
@@ -114,11 +116,11 @@ void RS485_Send_Frame(volatile struct mstp_port_struct_t *mstp_port, /* port
* ALGORITHM: none * ALGORITHM: none
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
uint8_t RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port) uint8_t RS485_Check_UART_Data(volatile struct mstp_port_struct_t *
mstp_port)
{ {
/* check for data */ /* check for data */
if (RS485_Comstat.Rx_Bytes) if (RS485_Comstat.Rx_Bytes) {
{
mstp_port->DataRegister = RS485_Rx_Buffer[RS485_Comstat.RxTail]; mstp_port->DataRegister = RS485_Rx_Buffer[RS485_Comstat.RxTail];
if (RS485_Comstat.RxTail >= (sizeof(RS485_Rx_Buffer) - 1)) if (RS485_Comstat.RxTail >= (sizeof(RS485_Rx_Buffer) - 1))
RS485_Comstat.RxTail = 0; RS485_Comstat.RxTail = 0;
@@ -126,8 +128,7 @@ uint8_t RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port)
RS485_Comstat.RxTail++; RS485_Comstat.RxTail++;
RS485_Comstat.Rx_Bytes--; RS485_Comstat.Rx_Bytes--;
/* errors? let the state machine know */ /* errors? let the state machine know */
if (RS485_Comstat.Rx_Bufferoverrun) if (RS485_Comstat.Rx_Bufferoverrun) {
{
RS485_Comstat.Rx_Bufferoverrun = FALSE; RS485_Comstat.Rx_Bufferoverrun = FALSE;
mstp_port->ReceiveError = TRUE; mstp_port->ReceiveError = TRUE;
} }
@@ -138,6 +139,7 @@ uint8_t RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port)
return RS485_Comstat.Rx_Bytes; return RS485_Comstat.Rx_Bytes;
} }
/* ************************************************************************* /* *************************************************************************
DESCRIPTION: Receives RS485 data stream DESCRIPTION: Receives RS485 data stream
@@ -151,25 +153,20 @@ void RS485_Interrupt_Rx(void)
{ {
char dummy; char dummy;
if ((RCSTA2bits.FERR) || (RCSTA2bits.OERR)) if ((RCSTA2bits.FERR) || (RCSTA2bits.OERR)) {
{
/* Clear the error */ /* Clear the error */
RCSTA2bits.CREN = 0; RCSTA2bits.CREN = 0;
RCSTA2bits.CREN = 1; RCSTA2bits.CREN = 1;
RS485_Comstat.Rx_Bufferoverrun = TRUE; RS485_Comstat.Rx_Bufferoverrun = TRUE;
dummy = RCREG2; dummy = RCREG2;
} } else if (RS485_Comstat.Rx_Bytes < sizeof(RS485_Rx_Buffer)) {
else if (RS485_Comstat.Rx_Bytes < sizeof(RS485_Rx_Buffer))
{
RS485_Rx_Buffer[RS485_Comstat.RxHead] = RCREG2; RS485_Rx_Buffer[RS485_Comstat.RxHead] = RCREG2;
if (RS485_Comstat.RxHead >= (sizeof(RS485_Rx_Buffer) - 1)) if (RS485_Comstat.RxHead >= (sizeof(RS485_Rx_Buffer) - 1))
RS485_Comstat.RxHead = 0; RS485_Comstat.RxHead = 0;
else else
RS485_Comstat.RxHead++; RS485_Comstat.RxHead++;
RS485_Comstat.Rx_Bytes++; RS485_Comstat.Rx_Bytes++;
} } else {
else
{
RS485_Comstat.Rx_Bufferoverrun = TRUE; RS485_Comstat.Rx_Bufferoverrun = TRUE;
dummy = RCREG2; dummy = RCREG2;
(void) dummy; (void) dummy;
@@ -187,17 +184,14 @@ void RS485_Interrupt_Rx(void)
*************************************************************************** */ *************************************************************************** */
void RS485_Interrupt_Tx(void) void RS485_Interrupt_Tx(void)
{ {
if (RS485_Comstat.Tx_Bytes) if (RS485_Comstat.Tx_Bytes) {
{
/* Get the data byte */ /* Get the data byte */
TXREG2 = RS485_Tx_Buffer[RS485_Comstat.TxHead]; TXREG2 = RS485_Tx_Buffer[RS485_Comstat.TxHead];
/* point to the next byte */ /* point to the next byte */
RS485_Comstat.TxHead++; RS485_Comstat.TxHead++;
/* reduce the buffer size */ /* reduce the buffer size */
RS485_Comstat.Tx_Bytes--; RS485_Comstat.Tx_Bytes--;
} } else {
else
{
/* wait for the USART to be empty */ /* wait for the USART to be empty */
while (!TXSTA2bits.TRMT); while (!TXSTA2bits.TRMT);
/* disable this interrupt */ /* disable this interrupt */
@@ -243,11 +237,9 @@ void RS485_Set_Baud_Rate(uint32_t baud)
else else
RS485_Baud_Rate = 115200; RS485_Baud_Rate = 115200;
I2C_Write_Block( I2C_Write_Block(EEPROM_DEVICE_ADDRESS,
EEPROM_DEVICE_ADDRESS,
(char *) &RS485_Baud_Rate, (char *) &RS485_Baud_Rate,
sizeof(RS485_Baud_Rate), sizeof(RS485_Baud_Rate), EEPROM_MSTP_BAUD_RATE_ADDR);
EEPROM_MSTP_BAUD_RATE_ADDR);
} }
/**************************************************************************** /****************************************************************************
@@ -286,8 +278,7 @@ void RS485_Initialize_Port(void)
625000 1 625000 1
1250000 0 1250000 0
*/ */
switch (RS485_Baud_Rate) switch (RS485_Baud_Rate) {
{
case 19200: case 19200:
SPBRG2 = 64; SPBRG2 = 64;
TXSTA2bits.BRGH = 1; TXSTA2bits.BRGH = 1;
@@ -366,11 +357,9 @@ void RS485_Initialize(void)
RS485_Comstat.TxTail = 0; RS485_Comstat.TxTail = 0;
RS485_Comstat.Tx_Bytes = 0; RS485_Comstat.Tx_Bytes = 0;
I2C_Read_Block( I2C_Read_Block(EEPROM_DEVICE_ADDRESS,
EEPROM_DEVICE_ADDRESS,
(char *) &RS485_Baud_Rate, (char *) &RS485_Baud_Rate,
sizeof(RS485_Baud_Rate), sizeof(RS485_Baud_Rate), EEPROM_MSTP_BAUD_RATE_ADDR);
EEPROM_MSTP_BAUD_RATE_ADDR);
RS485_Initialize_Port(); RS485_Initialize_Port();
} }
+3 -3
View File
@@ -99,8 +99,7 @@ int dlmstp_send_pdu(BACNET_ADDRESS * dest, /* destination address */
(uint8_t *) & MSTP_Port.TxBuffer[0], (uint8_t *) & MSTP_Port.TxBuffer[0],
sizeof(MSTP_Port.TxBuffer), sizeof(MSTP_Port.TxBuffer),
MSTP_Port.TxFrameType, MSTP_Port.TxFrameType,
destination, destination, MSTP_Port.This_Station, &PDU_Buffer[0], mtu_len);
MSTP_Port.This_Station, &PDU_Buffer[0], mtu_len);
MSTP_Port.TxLength = bytes_sent; MSTP_Port.TxLength = bytes_sent;
MSTP_Port.TxReady = true; MSTP_Port.TxReady = true;
} }
@@ -132,7 +131,8 @@ uint16_t dlmstp_receive(BACNET_ADDRESS * src, /* source address */
} }
/* only do master state machine while rx is idle */ /* only do master state machine while rx is idle */
if (MSTP_Port.receive_state == MSTP_RECEIVE_STATE_IDLE) { if (MSTP_Port.receive_state == MSTP_RECEIVE_STATE_IDLE) {
while (MSTP_Master_Node_FSM(&MSTP_Port)) {}; while (MSTP_Master_Node_FSM(&MSTP_Port)) {
};
} }
/* see if there is a packet available */ /* see if there is a packet available */
if (Receive_Buffer.ready) { if (Receive_Buffer.ready) {
+17 -13
View File
@@ -458,7 +458,8 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port)
/* wait for the start of the next frame. */ /* wait for the start of the next frame. */
mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE;
} else { } else {
if ((mstp_port->DestinationAddress == mstp_port->This_Station) if ((mstp_port->DestinationAddress ==
mstp_port->This_Station)
|| (mstp_port->DestinationAddress == || (mstp_port->DestinationAddress ==
MSTP_BROADCAST_ADDRESS)) { MSTP_BROADCAST_ADDRESS)) {
/* FrameTooLong */ /* FrameTooLong */
@@ -467,39 +468,42 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port)
/* unacceptable data length has been received */ /* unacceptable data length has been received */
mstp_port->ReceivedInvalidFrame = true; mstp_port->ReceivedInvalidFrame = true;
/* wait for the start of the next frame. */ /* wait for the start of the next frame. */
mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; mstp_port->receive_state =
MSTP_RECEIVE_STATE_IDLE;
} }
/* NoData */ /* NoData */
else if (mstp_port->DataLength == 0) { else if (mstp_port->DataLength == 0) {
/* CHEAT: it is very difficult to respond to /* CHEAT: it is very difficult to respond to
poll for master in the Master Node state machine poll for master in the Master Node state machine
before Tusage_timeout, so we will do it here. */ before Tusage_timeout, so we will do it here. */
if ((mstp_port->FrameType == FRAME_TYPE_POLL_FOR_MASTER) && if ((mstp_port->FrameType ==
(mstp_port->DestinationAddress == mstp_port->This_Station) && FRAME_TYPE_POLL_FOR_MASTER)
(mstp_port->master_state == MSTP_MASTER_STATE_IDLE)) && (mstp_port->DestinationAddress ==
{ mstp_port->This_Station)
&& (mstp_port->master_state ==
MSTP_MASTER_STATE_IDLE)) {
MSTP_Create_And_Send_Frame(mstp_port, MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_REPLY_TO_POLL_FOR_MASTER, FRAME_TYPE_REPLY_TO_POLL_FOR_MASTER,
mstp_port->SourceAddress, mstp_port->This_Station, mstp_port->SourceAddress,
NULL, 0); mstp_port->This_Station, NULL, 0);
/* don't indicate that a frame has been received */ /* don't indicate that a frame has been received */
mstp_port->ReceivedInvalidFrame = false; mstp_port->ReceivedInvalidFrame = false;
mstp_port->ReceivedValidFrame = false; mstp_port->ReceivedValidFrame = false;
} } else {
else
{
/* indicate that a frame with no data has been received */ /* indicate that a frame with no data has been received */
mstp_port->ReceivedValidFrame = true; mstp_port->ReceivedValidFrame = true;
} }
/* wait for the start of the next frame. */ /* wait for the start of the next frame. */
mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; mstp_port->receive_state =
MSTP_RECEIVE_STATE_IDLE;
} }
/* Data */ /* Data */
else { else {
mstp_port->Index = 0; mstp_port->Index = 0;
mstp_port->DataCRC = 0xFFFF; mstp_port->DataCRC = 0xFFFF;
/* receive the data portion of the frame. */ /* receive the data portion of the frame. */
mstp_port->receive_state = MSTP_RECEIVE_STATE_DATA; mstp_port->receive_state =
MSTP_RECEIVE_STATE_DATA;
} }
} }
/* NotForUs */ /* NotForUs */
+3 -8
View File
@@ -57,9 +57,7 @@ static FineTime RS485_Debug_Transmit_Timer;
#endif #endif
#if PRINT_ENABLED_RS485 #if PRINT_ENABLED_RS485
void RS485_Print_Frame(int port, void RS485_Print_Frame(int port, FineTime timer, uint8_t * buffer, /* frame to send (up to 501 bytes of data) */
FineTime timer,
uint8_t * buffer, /* frame to send (up to 501 bytes of data) */
uint16_t nbytes) uint16_t nbytes)
{ {
uint16_t i; /* byte counter */ uint16_t i; /* byte counter */
@@ -71,8 +69,7 @@ void RS485_Print_Frame(int port,
seconds = duration / 1000U; seconds = duration / 1000U;
milliseconds = duration - (seconds * 1000U); milliseconds = duration - (seconds * 1000U);
fprintf(stderr, "%0lu.%03lu: COM%d:", seconds, milliseconds, port + 1); fprintf(stderr, "%0lu.%03lu: COM%d:", seconds, milliseconds, port + 1);
for (i = 0; i < nbytes; i++) for (i = 0; i < nbytes; i++) {
{
unsigned value; unsigned value;
value = buffer[i]; value = buffer[i];
fprintf(stderr, " %02X", value); fprintf(stderr, " %02X", value);
@@ -179,9 +176,7 @@ void RS485_Send_Frame(volatile struct mstp_port_struct_t *mstp_port, /* port
octet is transmitted. */ octet is transmitted. */
mstp_port->SilenceTimer = 0; mstp_port->SilenceTimer = 0;
#if PRINT_ENABLED_RS485 #if PRINT_ENABLED_RS485
RS485_Print_Frame(RS485_Port, RS485_Print_Frame(RS485_Port, RS485_Debug_Transmit_Timer, buffer, /* frame to send (up to 501 bytes of data) */
RS485_Debug_Transmit_Timer,
buffer, /* frame to send (up to 501 bytes of data) */
nbytes); nbytes);
MarkTime(&RS485_Debug_Transmit_Timer); MarkTime(&RS485_Debug_Transmit_Timer);
#endif #endif
+4 -4
View File
@@ -430,8 +430,8 @@ void ethernet_debug_address(const char *info, BACNET_ADDRESS * dest)
if (info) { if (info) {
sprintf(msgBuf, "%s", info); sprintf(msgBuf, "%s", info);
LogError(msgBuf); LogError(msgBuf);
} /* if */ }
/* if */
if (dest) { if (dest) {
sprintf(msgBuf, sprintf(msgBuf,
"Address:\n MAC Length=%d\n MAC Address=", dest->mac_len); "Address:\n MAC Length=%d\n MAC Address=", dest->mac_len);
@@ -449,7 +449,7 @@ void ethernet_debug_address(const char *info, BACNET_ADDRESS * dest)
LogInfo(msgBuf); LogInfo(msgBuf);
} /* for */ } /* for */
LogInfo("\n"); LogInfo("\n");
} /* if ( dest ) */ }
/* if ( dest ) */
return; return;
} }
+2 -1
View File
@@ -67,7 +67,8 @@ int wp_encode_apdu(uint8_t * apdu,
/* propertyValue */ /* propertyValue */
len = encode_opening_tag(&apdu[apdu_len], 3); len = encode_opening_tag(&apdu[apdu_len], 3);
apdu_len += len; apdu_len += len;
len = bacapp_encode_application_data(&apdu[apdu_len], &data->value); len =
bacapp_encode_application_data(&apdu[apdu_len], &data->value);
apdu_len += len; apdu_len += len;
len = encode_closing_tag(&apdu[apdu_len], 3); len = encode_closing_tag(&apdu[apdu_len], 3);
apdu_len += len; apdu_len += len;