This commit is contained in:
skarg
2006-08-29 10:48:04 +00:00
parent 0f851d57f0
commit 3d0abf778a
25 changed files with 487 additions and 525 deletions
+2 -1
View File
@@ -1436,7 +1436,8 @@ int encode_tagged_date(uint8_t * apdu, BACNET_DATE * bdate)
}
int encode_context_date(uint8_t * apdu, int tag_number, BACNET_DATE * bdate)
int encode_context_date(uint8_t * apdu, int tag_number,
BACNET_DATE * bdate)
{
int len = 0; /* return value */
+2 -2
View File
@@ -49,8 +49,8 @@
#elif defined(BACDL_BIP)
#include "bip.h"
#else
#define MAX_HEADER (1 + 1 + 2)
#define MAX_MPDU (MAX_HEADER+MAX_PDU)
#define MAX_HEADER (1 + 1 + 2)
#define MAX_MPDU (MAX_HEADER+MAX_PDU)
#endif
#ifdef __cplusplus
+2 -4
View File
@@ -259,8 +259,7 @@ int main(int argc, char *argv[])
Communication_Password);
} else if (tsm_invoke_id_free(invoke_id))
break;
else if (tsm_invoke_id_failed(invoke_id))
{
else if (tsm_invoke_id_failed(invoke_id)) {
fprintf(stderr, "\rError: TSM Timeout!\r\n");
tsm_free_invoke_id(invoke_id);
/* try again or abort? */
@@ -269,8 +268,7 @@ int main(int argc, char *argv[])
} else {
/* increment timer - exit if timed out */
elapsed_seconds += (current_seconds - last_seconds);
if (elapsed_seconds > timeout_seconds)
{
if (elapsed_seconds > timeout_seconds) {
printf("\rError: APDU Timeout!\r\n");
break;
}
+2 -5
View File
@@ -285,9 +285,7 @@ int main(int argc, char *argv[])
Target_File_Object_Instance, fileStartPosition,
requestedOctetCount);
Current_Invoke_ID = invoke_id;
}
else if (tsm_invoke_id_failed(invoke_id))
{
} else if (tsm_invoke_id_failed(invoke_id)) {
fprintf(stderr, "\rError: TSM Timeout!\r\n");
tsm_free_invoke_id(invoke_id);
/* try again or abort? */
@@ -296,8 +294,7 @@ int main(int argc, char *argv[])
} else {
/* increment timer - exit if timed out */
elapsed_seconds += (current_seconds - last_seconds);
if (elapsed_seconds > timeout_seconds)
{
if (elapsed_seconds > timeout_seconds) {
fprintf(stderr, "\rError: APDU Timeout!\r\n");
break;
}
+3 -5
View File
@@ -187,7 +187,7 @@ int main(int argc, char *argv[])
if (!arcnet_init("arc0"))
return 1;
#else
#error Datalink (BACDL_ETHERNET,BACDL_BIP, or BACDL_ARCNET) undefined
#error Datalink (BACDL_ETHERNET,BACDL_BIP, or BACDL_ARCNET) undefined
#endif
/* configure the timeout values */
last_seconds = time(NULL);
@@ -226,8 +226,7 @@ int main(int argc, char *argv[])
Target_Object_Index);
} else if (tsm_invoke_id_free(invoke_id))
break;
else if (tsm_invoke_id_failed(invoke_id))
{
else if (tsm_invoke_id_failed(invoke_id)) {
fprintf(stderr, "\rError: TSM Timeout!\r\n");
tsm_free_invoke_id(invoke_id);
/* try again or abort? */
@@ -236,8 +235,7 @@ int main(int argc, char *argv[])
} else {
/* increment timer - exit if timed out */
elapsed_seconds += (current_seconds - last_seconds);
if (elapsed_seconds > timeout_seconds)
{
if (elapsed_seconds > timeout_seconds) {
printf("\rError: APDU Timeout!\r\n");
break;
}
+2 -4
View File
@@ -245,8 +245,7 @@ int main(int argc, char *argv[])
Reinitialize_Password);
} else if (tsm_invoke_id_free(invoke_id))
break;
else if (tsm_invoke_id_failed(invoke_id))
{
else if (tsm_invoke_id_failed(invoke_id)) {
fprintf(stderr, "\rError: TSM Timeout!\r\n");
tsm_free_invoke_id(invoke_id);
/* try again or abort? */
@@ -255,8 +254,7 @@ int main(int argc, char *argv[])
} else {
/* increment timer - exit if timed out */
elapsed_seconds += (current_seconds - last_seconds);
if (elapsed_seconds > timeout_seconds)
{
if (elapsed_seconds > timeout_seconds) {
fprintf(stderr, "\rError: APDU Timeout!\r\n");
break;
}
+2 -2
View File
@@ -112,10 +112,10 @@ int main(int argc, char *argv[])
/* allow the device ID to be set */
if (argc > 1)
Device_Set_Object_Instance_Number(strtol(argv[1], NULL, 0));
#if defined(BACDL_BIP)
#if defined(BACDL_BIP)
if (argc > 2)
bip_set_port(strtol(argv[2], NULL, 0));
#endif
#endif
printf("BACnet Server Demo - Device #%u\r\n",
Device_Object_Instance_Number());
Init_Service_Handlers();
+2 -5
View File
@@ -263,9 +263,7 @@ int main(int argc, char *argv[])
Target_File_Object_Instance, fileStartPosition,
&fileData);
Current_Invoke_ID = invoke_id;
}
else if (tsm_invoke_id_failed(invoke_id))
{
} else if (tsm_invoke_id_failed(invoke_id)) {
fprintf(stderr, "\rError: TSM Timeout!\r\n");
tsm_free_invoke_id(invoke_id);
/* try again or abort? */
@@ -274,8 +272,7 @@ int main(int argc, char *argv[])
} else {
/* increment timer - exit if timed out */
elapsed_seconds += (current_seconds - last_seconds);
if (elapsed_seconds > timeout_seconds)
{
if (elapsed_seconds > timeout_seconds) {
fprintf(stderr, "\rError: APDU Timeout!\r\n");
break;
}
+2 -4
View File
@@ -323,8 +323,7 @@ int main(int argc, char *argv[])
Target_Object_Property_Index);
} else if (tsm_invoke_id_free(invoke_id))
break;
else if (tsm_invoke_id_failed(invoke_id))
{
else if (tsm_invoke_id_failed(invoke_id)) {
fprintf(stderr, "\rError: TSM Timeout!\r\n");
tsm_free_invoke_id(invoke_id);
/* try again or abort? */
@@ -333,8 +332,7 @@ int main(int argc, char *argv[])
} else {
/* increment timer - exit if timed out */
elapsed_seconds += (current_seconds - last_seconds);
if (elapsed_seconds > timeout_seconds)
{
if (elapsed_seconds > timeout_seconds) {
printf("\rError: APDU Timeout!\r\n");
break;
}
+1 -2
View File
@@ -96,8 +96,7 @@ extern "C" {
void dlmstp_get_broadcast_address(BACNET_ADDRESS * dest); /* destination address */
/* MS/TP state machine functions */
uint16_t dlmstp_put_receive(
uint8_t src, /* source MS/TP address */
uint16_t dlmstp_put_receive(uint8_t src, /* source MS/TP address */
uint8_t * pdu, /* PDU data */
uint16_t pdu_len);
+94 -106
View File
@@ -206,7 +206,7 @@ void MSTP_Create_And_Send_Frame(volatile struct mstp_port_struct_t *mstp_port,
uint8_t * data, /* any data to be sent - may be null */
unsigned data_len)
{ /* number of bytes of data (up to 501) */
uint8_t buffer[MAX_MPDU] = {0}; /* buffer for sending */
uint8_t buffer[MAX_MPDU] = { 0 }; /* buffer for sending */
uint16_t len = 0; /* number of bytes to send */
len = (uint16_t) MSTP_Create_Frame(&buffer[0], /* where frame is loaded */
@@ -233,8 +233,7 @@ char *mstp_receive_state_text(int state)
{
char *text = "unknown";
switch (state)
{
switch (state) {
case MSTP_RECEIVE_STATE_IDLE:
text = "IDLE";
break;
@@ -260,30 +259,27 @@ char *mstp_receive_state_text(int state)
void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port)
{
#if PRINT_ENABLED_MASTER
#if PRINT_ENABLED_MASTER
static MSTP_RECEIVE_STATE receive_state = MSTP_RECEIVE_STATE_IDLE;
#endif
#endif
#if PRINT_ENABLED_RECEIVE
fprintf(stderr,"MSTP Rx: State=%s Data=%02X hCRC=%02X Index=%u EC=%u DateLen=%u Silence=%u\r\n",
#if PRINT_ENABLED_RECEIVE
fprintf(stderr,
"MSTP Rx: State=%s Data=%02X hCRC=%02X Index=%u EC=%u DateLen=%u Silence=%u\r\n",
mstp_receive_state_text(mstp_port->receive_state),
mstp_port->DataRegister,
mstp_port->HeaderCRC,
mstp_port->Index,
mstp_port->EventCount,
mstp_port->DataLength,
mstp_port->DataRegister, mstp_port->HeaderCRC, mstp_port->Index,
mstp_port->EventCount, mstp_port->DataLength,
mstp_port->SilenceTimer);
#endif
#if PRINT_ENABLED_RECEIVE_DATA
if (mstp_port->DataAvailable == true)
{
#endif
#if PRINT_ENABLED_RECEIVE_DATA
if (mstp_port->DataAvailable == true) {
if ((mstp_port->receive_state == MSTP_RECEIVE_STATE_IDLE) &&
(receive_state != MSTP_RECEIVE_STATE_IDLE))
fprintf(stderr,"MSTP Rx: ");
fprintf(stderr,"%02X ", mstp_port->DataRegister);
fprintf(stderr, "MSTP Rx: ");
fprintf(stderr, "%02X ", mstp_port->DataRegister);
}
receive_state = mstp_port->receive_state;
#endif
#endif
switch (mstp_port->receive_state) {
/* In the IDLE state, the node waits for the beginning of a frame. */
@@ -562,13 +558,12 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port)
mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE;
break;
}
#if PRINT_ENABLED_RECEIVE_DATA
#if PRINT_ENABLED_RECEIVE_DATA
if ((receive_state != MSTP_RECEIVE_STATE_IDLE) &&
(mstp_port->receive_state == MSTP_RECEIVE_STATE_IDLE))
{
fprintf(stderr,"\r\n");
(mstp_port->receive_state == MSTP_RECEIVE_STATE_IDLE)) {
fprintf(stderr, "\r\n");
}
#endif
#endif
return;
}
@@ -578,8 +573,7 @@ char *mstp_master_state_text(int state)
{
char *text = "unknown";
switch (state)
{
switch (state) {
case MSTP_MASTER_STATE_INITIALIZE:
text = "INITIALIZE";
break;
@@ -620,8 +614,7 @@ char *mstp_frame_type_text(int type)
{
char *text = "unknown";
switch (type)
{
switch (type) {
case FRAME_TYPE_TOKEN:
text = "TOKEN";
break;
@@ -665,9 +658,9 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port)
uint8_t next_this_station = 0;
uint8_t next_next_station = 0;
uint16_t my_timeout = 10, ns_timeout = 0;
#if PRINT_ENABLED_MASTER
#if PRINT_ENABLED_MASTER
static MSTP_MASTER_STATE master_state = MSTP_MASTER_STATE_INITIALIZE;
#endif
#endif
/* some calculations that several states need */
@@ -677,9 +670,8 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port)
(mstp_port->Nmax_master + 1);
next_next_station = (mstp_port->Next_Station + 1) %
(mstp_port->Nmax_master + 1);
#if PRINT_ENABLED_MASTER
if (mstp_port->master_state != master_state)
{
#if PRINT_ENABLED_MASTER
if (mstp_port->master_state != master_state) {
master_state = mstp_port->master_state;
fprintf(stderr,
"MSTP: TS=%02X[%02X] NS=%02X[%02X] PS=%02X[%02X] EC=%u TC=%u ST=%u %s\r\n",
@@ -694,7 +686,7 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port)
mstp_port->SilenceTimer,
mstp_master_state_text(mstp_port->master_state));
}
#endif
#endif
switch (mstp_port->master_state) {
case MSTP_MASTER_STATE_INITIALIZE:
@@ -723,9 +715,8 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port)
/* invalid frame was received */
mstp_port->ReceivedInvalidFrame = false;
/* wait for the next frame - remain in IDLE */
}
else if (mstp_port->ReceivedValidFrame == true) {
#if PRINT_ENABLED_MASTER
} else if (mstp_port->ReceivedValidFrame == true) {
#if PRINT_ENABLED_MASTER
fprintf(stderr,
"MSTP: ReceivedValidFrame Src=%02X Dest=%02X DataLen=%u FC=%u ST=%u Type=%s\r\n",
mstp_port->SourceAddress,
@@ -734,14 +725,13 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port)
mstp_port->FrameCount,
mstp_port->SilenceTimer,
mstp_frame_type_text(mstp_port->FrameType));
#endif
#endif
/* destined for me! */
if ((mstp_port->DestinationAddress ==
mstp_port->This_Station) ||
(mstp_port->DestinationAddress ==
MSTP_BROADCAST_ADDRESS)) {
switch (mstp_port->FrameType)
{
switch (mstp_port->FrameType) {
/* ReceivedToken */
case FRAME_TYPE_TOKEN:
/* tokens can't be broadcast */
@@ -762,16 +752,14 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port)
break;
case FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY:
/* indicate successful reception to the higher layers */
dlmstp_put_receive(
mstp_port->SourceAddress,
dlmstp_put_receive(mstp_port->SourceAddress,
(uint8_t *) & mstp_port->InputBuffer[0],
mstp_port->DataLength);
break;
case FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY:
mstp_port->ReplyPostponedTimer = 0;
/* indicate successful reception to the higher layers */
dlmstp_put_receive(
mstp_port->SourceAddress, /* source MS/TP address */
dlmstp_put_receive(mstp_port->SourceAddress, /* source MS/TP address */
(uint8_t *) & mstp_port->InputBuffer[0],
mstp_port->DataLength);
/* broadcast DER just remains IDLE */
@@ -799,27 +787,23 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port)
/* proprietary frames. */
case MSTP_MASTER_STATE_USE_TOKEN:
/* NothingToSend */
if (!mstp_port->TxReady)
{
if (!mstp_port->TxReady) {
mstp_port->FrameCount = mstp_port->Nmax_info_frames;
mstp_port->master_state = MSTP_MASTER_STATE_DONE_WITH_TOKEN;
}
else
{
} else {
uint8_t destination = mstp_port->TxBuffer[3];
RS485_Send_Frame(
mstp_port,
(uint8_t *) &mstp_port->TxBuffer[0],
mstp_port->TxLength);
RS485_Send_Frame(mstp_port,
(uint8_t *) & mstp_port->TxBuffer[0], mstp_port->TxLength);
mstp_port->FrameCount++;
switch (mstp_port->TxFrameType)
{
switch (mstp_port->TxFrameType) {
/* SendAndWait */
case FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY:
if (destination == MSTP_BROADCAST_ADDRESS)
mstp_port->master_state = MSTP_MASTER_STATE_DONE_WITH_TOKEN;
mstp_port->master_state =
MSTP_MASTER_STATE_DONE_WITH_TOKEN;
else
mstp_port->master_state = MSTP_MASTER_STATE_WAIT_FOR_REPLY;
mstp_port->master_state =
MSTP_MASTER_STATE_WAIT_FOR_REPLY;
break;
case FRAME_TYPE_TEST_REQUEST:
mstp_port->master_state = MSTP_MASTER_STATE_WAIT_FOR_REPLY;
@@ -828,7 +812,8 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port)
case FRAME_TYPE_TEST_RESPONSE:
case FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY:
default:
mstp_port->master_state = MSTP_MASTER_STATE_DONE_WITH_TOKEN;
mstp_port->master_state =
MSTP_MASTER_STATE_DONE_WITH_TOKEN;
break;
}
mstp_port->TxReady = false;
@@ -851,14 +836,16 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port)
/* InvalidFrame */
/* error in frame reception */
mstp_port->ReceivedInvalidFrame = false;
mstp_port->master_state = MSTP_MASTER_STATE_DONE_WITH_TOKEN;
mstp_port->master_state =
MSTP_MASTER_STATE_DONE_WITH_TOKEN;
} else if (mstp_port->ReceivedValidFrame == true) {
if (mstp_port->DestinationAddress == mstp_port->This_Station) {
switch (mstp_port->TxFrameType)
{
if (mstp_port->DestinationAddress ==
mstp_port->This_Station) {
switch (mstp_port->TxFrameType) {
case FRAME_TYPE_REPLY_POSTPONED:
/* ReceivedReplyPostponed */
mstp_port->master_state = MSTP_MASTER_STATE_DONE_WITH_TOKEN;
mstp_port->master_state =
MSTP_MASTER_STATE_DONE_WITH_TOKEN;
break;
case FRAME_TYPE_TEST_RESPONSE:
mstp_port->master_state = MSTP_MASTER_STATE_IDLE;
@@ -867,11 +854,11 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port)
/* ReceivedReply */
/* or a proprietary type that indicates a reply */
/* indicate successful reception to the higher layers */
dlmstp_put_receive(
mstp_port->SourceAddress, /* source MS/TP address */
dlmstp_put_receive(mstp_port->SourceAddress, /* source MS/TP address */
(uint8_t *) & mstp_port->InputBuffer[0],
mstp_port->DataLength);
mstp_port->master_state = MSTP_MASTER_STATE_DONE_WITH_TOKEN;
mstp_port->master_state =
MSTP_MASTER_STATE_DONE_WITH_TOKEN;
break;
default:
/* if proprietary frame was expected, you might
@@ -901,8 +888,7 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port)
mstp_port->master_state = MSTP_MASTER_STATE_USE_TOKEN;
}
/* Npoll changed in Errata SSPC-135-2004 */
else if (mstp_port->TokenCount < (Npoll-1))
{
else if (mstp_port->TokenCount < (Npoll - 1)) {
if ((mstp_port->SoleMaster == true) &&
(mstp_port->Next_Station != next_this_station)) {
/* SoleMaster */
@@ -911,8 +897,7 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port)
mstp_port->FrameCount = 0;
mstp_port->TokenCount++;
mstp_port->master_state = MSTP_MASTER_STATE_USE_TOKEN;
}
else {
} else {
/* SendToken */
/* Npoll changed in Errata SSPC-135-2004 */
/* The comparison of NS and TS+1 eliminates the Poll For Master */
@@ -928,8 +913,7 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port)
mstp_port->EventCount = 0;
mstp_port->master_state = MSTP_MASTER_STATE_PASS_TOKEN;
}
}
else if (next_poll_station == mstp_port->Next_Station) {
} else if (next_poll_station == mstp_port->Next_Station) {
if (mstp_port->SoleMaster == true) {
/* SoleMasterRestartMaintenancePFM */
mstp_port->Poll_Station = next_poll_station;
@@ -942,9 +926,9 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port)
mstp_port->TokenCount = 1; /* changed in Errata SSPC-135-2004 */
/* mstp_port->EventCount = 0; removed in Addendum 135-2004d-8 */
/* find a new successor to TS */
mstp_port->master_state = MSTP_MASTER_STATE_POLL_FOR_MASTER;
}
else {
mstp_port->master_state =
MSTP_MASTER_STATE_POLL_FOR_MASTER;
} else {
/* ResetMaintenancePFM */
mstp_port->Poll_Station = mstp_port->This_Station;
/* transmit a Token frame to NS */
@@ -957,14 +941,12 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port)
mstp_port->EventCount = 0;
mstp_port->master_state = MSTP_MASTER_STATE_PASS_TOKEN;
}
}
else {
} else {
/* SendMaintenancePFM */
mstp_port->Poll_Station = next_poll_station;
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_POLL_FOR_MASTER,
mstp_port->Poll_Station,
mstp_port->This_Station, NULL, 0);
mstp_port->Poll_Station, mstp_port->This_Station, NULL, 0);
mstp_port->RetryCount = 0;
mstp_port->master_state = MSTP_MASTER_STATE_POLL_FOR_MASTER;
}
@@ -986,7 +968,8 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port)
/* Transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_TOKEN,
mstp_port->Next_Station, mstp_port->This_Station, NULL, 0);
mstp_port->Next_Station, mstp_port->This_Station, NULL,
0);
mstp_port->EventCount = 0;
/* re-enter the current state to listen for NS */
/* to begin using the token. */
@@ -997,14 +980,16 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port)
/* Transmit a Poll For Master frame to PS. */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_POLL_FOR_MASTER,
mstp_port->Poll_Station, mstp_port->This_Station, NULL, 0);
mstp_port->Poll_Station, mstp_port->This_Station, NULL,
0);
/* no known successor node */
mstp_port->Next_Station = mstp_port->This_Station;
mstp_port->RetryCount = 0;
mstp_port->TokenCount = 0;
/* mstp_port->EventCount = 0; removed in Addendum 135-2004d-8 */
/* find a new successor to TS */
mstp_port->master_state = MSTP_MASTER_STATE_POLL_FOR_MASTER;
mstp_port->master_state =
MSTP_MASTER_STATE_POLL_FOR_MASTER;
}
}
break;
@@ -1021,9 +1006,9 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port)
/* Enter the IDLE state to receive and process the incoming frame. */
mstp_port->master_state = MSTP_MASTER_STATE_IDLE;
}
}
else {
ns_timeout = Tno_token + (Tslot * (mstp_port->This_Station + 1));
} else {
ns_timeout =
Tno_token + (Tslot * (mstp_port->This_Station + 1));
if (mstp_port->SilenceTimer < ns_timeout) {
/* GenerateToken */
/* Assume that this node is the lowest numerical address */
@@ -1032,14 +1017,16 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port)
/* Transmit a Poll For Master frame to PS. */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_POLL_FOR_MASTER,
mstp_port->Poll_Station, mstp_port->This_Station, NULL, 0);
mstp_port->Poll_Station, mstp_port->This_Station, NULL,
0);
/* indicate that the next station is unknown */
mstp_port->Next_Station = mstp_port->This_Station;
mstp_port->RetryCount = 0;
mstp_port->TokenCount = 0;
/* mstp_port->EventCount = 0; removed Addendum 135-2004d-8 */
/* enter the POLL_FOR_MASTER state to find a new successor to TS. */
mstp_port->master_state = MSTP_MASTER_STATE_POLL_FOR_MASTER;
mstp_port->master_state =
MSTP_MASTER_STATE_POLL_FOR_MASTER;
}
}
break;
@@ -1047,10 +1034,10 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port)
/* a previously sent Poll For Master frame in order to find */
/* a successor node. */
case MSTP_MASTER_STATE_POLL_FOR_MASTER:
if (mstp_port->ReceivedValidFrame == true)
{
if ((mstp_port->DestinationAddress == mstp_port->This_Station) &&
(mstp_port->FrameType == FRAME_TYPE_REPLY_TO_POLL_FOR_MASTER)) {
if (mstp_port->ReceivedValidFrame == true) {
if ((mstp_port->DestinationAddress == mstp_port->This_Station)
&& (mstp_port->FrameType ==
FRAME_TYPE_REPLY_TO_POLL_FOR_MASTER)) {
/* ReceivedReplyToPFM */
mstp_port->SoleMaster = false;
mstp_port->Next_Station = mstp_port->SourceAddress;
@@ -1058,13 +1045,13 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port)
/* Transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_TOKEN,
mstp_port->Next_Station, mstp_port->This_Station, NULL, 0);
mstp_port->Next_Station, mstp_port->This_Station, NULL,
0);
mstp_port->Poll_Station = mstp_port->This_Station;
mstp_port->TokenCount = 0;
mstp_port->RetryCount = 0;
mstp_port->master_state = MSTP_MASTER_STATE_PASS_TOKEN;
}
else {
} else {
/* ReceivedUnexpectedFrame */
/* An unexpected frame was received. */
/* This may indicate the presence of multiple tokens. */
@@ -1073,8 +1060,7 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port)
mstp_port->master_state = MSTP_MASTER_STATE_IDLE;
}
mstp_port->ReceivedValidFrame = false;
}
else if ((mstp_port->SilenceTimer >= Tusage_timeout) ||
} else if ((mstp_port->SilenceTimer >= Tusage_timeout) ||
(mstp_port->ReceivedInvalidFrame == true)) {
if (mstp_port->SoleMaster == true) {
/* SoleMaster */
@@ -1092,18 +1078,19 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port)
/* transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_TOKEN,
mstp_port->Next_Station, mstp_port->This_Station, NULL, 0);
mstp_port->Next_Station, mstp_port->This_Station,
NULL, 0);
mstp_port->RetryCount = 0;
mstp_port->master_state = MSTP_MASTER_STATE_PASS_TOKEN;
} else {
if (next_poll_station != mstp_port->This_Station)
{
if (next_poll_station != mstp_port->This_Station) {
/* SendNextPFM */
mstp_port->Poll_Station = next_poll_station;
/* Transmit a Poll For Master frame to PS. */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_POLL_FOR_MASTER,
mstp_port->Poll_Station, mstp_port->This_Station, NULL, 0);
mstp_port->Poll_Station,
mstp_port->This_Station, NULL, 0);
mstp_port->RetryCount = 0;
/* Re-enter the current state. */
} else {
@@ -1111,7 +1098,8 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port)
/* to indicate that this station is the only master */
mstp_port->SoleMaster = true;
mstp_port->FrameCount = 0;
mstp_port->master_state = MSTP_MASTER_STATE_USE_TOKEN;
mstp_port->master_state =
MSTP_MASTER_STATE_USE_TOKEN;
}
}
}
@@ -1130,11 +1118,11 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port)
/* (the mechanism used to determine this is a local matter), */
/* then call MSTP_Create_And_Send_Frame to transmit the reply frame */
/* and enter the IDLE state to wait for the next frame. */
if ((mstp_port->FrameType == FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY) &&
(mstp_port->TxReady)) {
RS485_Send_Frame(
mstp_port,
(uint8_t *) &mstp_port->TxBuffer[0],
if ((mstp_port->FrameType ==
FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY)
&& (mstp_port->TxReady)) {
RS485_Send_Frame(mstp_port,
(uint8_t *) & mstp_port->TxBuffer[0],
mstp_port->TxLength);
mstp_port->TxReady = false;
}
+1 -1
View File
@@ -230,7 +230,7 @@ int arcnet_send_pdu(BACNET_ADDRESS * dest, /* destination address */
fprintf(stderr, "arcnet: PDU is too big to send!\n");
return -4;
}
memcpy(&pkt->soft.raw[4+npdu_len], pdu, pdu_len);
memcpy(&pkt->soft.raw[4 + npdu_len], pdu, pdu_len);
/* Send the packet */
bytes =
sendto(ARCNET_Sock_FD, &mtu, mtu_len, 0,
+1 -1
View File
@@ -185,7 +185,7 @@ int ethernet_send_pdu(BACNET_ADDRESS * dest, /* destination address */
{ /* number of bytes of data */
int i = 0; /* counter */
int bytes = 0;
BACNET_ADDRESS src = { 0 }; /* source address for npdu*/
BACNET_ADDRESS src = { 0 }; /* source address for npdu */
uint8_t mtu[MAX_MPDU] = { 0 }; /* our buffer */
int mtu_len = 0;
int npdu_len = 0;
+11 -13
View File
@@ -71,34 +71,32 @@ int dlmstp_send_pdu(BACNET_ADDRESS * dest, /* destination address */
if (npdu_data->confirmed_message)
MSTP_Port.TxFrameType = FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY;
else
MSTP_Port.TxFrameType = FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY;
MSTP_Port.TxFrameType =
FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY;
/* load destination MAC address */
if (dest && dest->mac_len == 1) {
destination = dest->mac[0];
} else {
#if PRINT_ENABLED
#if PRINT_ENABLED
fprintf(stderr, "mstp: invalid destination MAC address!\n");
#endif
#endif
return -2;
}
dlmstp_get_my_address(&src);
npdu_len = npdu_encode_pdu(&PDU_Buffer[0], dest, &src, npdu_data);
if ((8 /* header len */ + npdu_len + pdu_len) > MAX_MPDU) {
#if PRINT_ENABLED
#if PRINT_ENABLED
fprintf(stderr, "mstp: PDU is too big to send!\n");
#endif
#endif
return -4;
}
memmove(&PDU_Buffer[npdu_len], pdu, pdu_len);
bytes_sent = MSTP_Create_Frame(
&MSTP_Port.TxBuffer[0],
bytes_sent = MSTP_Create_Frame(&MSTP_Port.TxBuffer[0],
sizeof(MSTP_Port.TxBuffer),
MSTP_Port.TxFrameType,
destination,
MSTP_Port.This_Station,
&PDU_Buffer[0],
npdu_len + pdu_len);
MSTP_Port.This_Station, &PDU_Buffer[0], npdu_len + pdu_len);
MSTP_Port.TxLength = bytes_sent;
MSTP_Port.TxReady = true;
}
@@ -132,9 +130,9 @@ uint16_t dlmstp_receive(BACNET_ADDRESS * src, /* source address */
(void) timeout;
/* see if there is a packet available */
if (Receive_Buffer.ready)
{
memmove(src, &Receive_Buffer.address, sizeof(Receive_Buffer.address));
if (Receive_Buffer.ready) {
memmove(src, &Receive_Buffer.address,
sizeof(Receive_Buffer.address));
pdu_len = Receive_Buffer.pdu_len;
memmove(&pdu[0], &Receive_Buffer.pdu[0], max_pdu);
Receive_Buffer.ready = false;
+4 -3
View File
@@ -95,7 +95,9 @@ void My_Read_Property_Handler(uint8_t * service_request,
data.application_data = &Temp_Buf[0];
data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */
pdu_len = rp_ack_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, &data);
pdu_len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, &data);
} else
error = true;
} else
@@ -112,8 +114,7 @@ void My_Read_Property_Handler(uint8_t * service_request,
SERVICE_CONFIRMED_READ_PROPERTY, error_class, error_code);
}
npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
bytes_sent = datalink_send_pdu(src, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
return;
}
+2 -3
View File
@@ -42,7 +42,7 @@ static int interface = SOCKET_ERROR; /* SOCKET_ERROR means no open interface
void bip_set_interface(char *ifname)
{
/*dummy function - to make the demos compile easier */
(void)ifname;
(void) ifname;
}
/*-----------------------------------*/
@@ -204,8 +204,7 @@ static void NetInitialize(void)
* ALGORITHM: none
* NOTES: none
******************************************************************/
static void RTIP_To_Network_Address(
BYTE *octet_address,
static void RTIP_To_Network_Address(BYTE * octet_address,
struct in_addr *addr)
{
uint32_t ip_address = 0; /* for decoding the subnet mask */
+16 -22
View File
@@ -73,34 +73,33 @@ int dlmstp_send_pdu(BACNET_ADDRESS * dest, /* destination address */
if (npdu_data->confirmed_message)
MSTP_Port.TxFrameType = FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY;
else
MSTP_Port.TxFrameType = FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY;
MSTP_Port.TxFrameType =
FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY;
/* load destination MAC address */
if (dest && dest->mac_len == 1) {
destination = dest->mac[0];
} else {
#if PRINT_ENABLED
#if PRINT_ENABLED
fprintf(stderr, "mstp: invalid destination MAC address!\n");
#endif
#endif
return -2;
}
dlmstp_get_my_address(&src);
npdu_len = npdu_encode_pdu(&PDU_Buffer[0], dest, &src, npdu_data);
if ((8 /* header len */ + npdu_len + pdu_len) > MAX_MPDU) {
#if PRINT_ENABLED
#if PRINT_ENABLED
fprintf(stderr, "mstp: PDU is too big to send!\n");
#endif
#endif
return -4;
}
memmove(&PDU_Buffer[npdu_len], pdu, pdu_len);
bytes_sent = MSTP_Create_Frame(
(uint8_t *)&MSTP_Port.TxBuffer[0],
(uint8_t *) & MSTP_Port.TxBuffer[0],
sizeof(MSTP_Port.TxBuffer),
MSTP_Port.TxFrameType,
destination,
MSTP_Port.This_Station,
&PDU_Buffer[0],
npdu_len + pdu_len);
MSTP_Port.This_Station, &PDU_Buffer[0], npdu_len + pdu_len);
MSTP_Port.TxLength = bytes_sent;
MSTP_Port.TxReady = true;
}
@@ -113,8 +112,7 @@ void dlmstp_task(void)
RS485_Check_UART_Data(&MSTP_Port);
/* only do receive state machine while we don't have a frame */
if ((MSTP_Port.ReceivedValidFrame == false) &&
(MSTP_Port.ReceivedInvalidFrame == false))
{
(MSTP_Port.ReceivedInvalidFrame == false)) {
MSTP_Receive_Frame_FSM(&MSTP_Port);
}
/* only do master state machine while rx is idle */
@@ -139,9 +137,9 @@ uint16_t dlmstp_receive(BACNET_ADDRESS * src, /* source address */
(void) timeout;
/* see if there is a packet available */
if (Receive_Buffer.ready)
{
memmove(src, &Receive_Buffer.address, sizeof(Receive_Buffer.address));
if (Receive_Buffer.ready) {
memmove(src, &Receive_Buffer.address,
sizeof(Receive_Buffer.address));
pdu_len = Receive_Buffer.pdu_len;
memmove(&pdu[0], &Receive_Buffer.pdu[0], max_pdu);
Receive_Buffer.ready = false;
@@ -154,19 +152,16 @@ void dlmstp_fill_bacnet_address(BACNET_ADDRESS * src, uint8_t mstp_address)
{
int i = 0;
if (mstp_address == MSTP_BROADCAST_ADDRESS)
{
if (mstp_address == MSTP_BROADCAST_ADDRESS) {
/* mac_len = 0 if broadcast address */
src->mac_len = 0;
src->mac[0] = 0;
}
else
{
} else {
src->mac_len = 1;
src->mac[0] = mstp_address;
}
/* fill with 0's starting with index 1; index 0 filled above */
for (i = 1; i <MAX_MAC_LEN; i++) {
for (i = 1; i < MAX_MAC_LEN; i++) {
src->mac[i] = 0;
}
src->net = 0;
@@ -177,8 +172,7 @@ void dlmstp_fill_bacnet_address(BACNET_ADDRESS * src, uint8_t mstp_address)
}
/* for the MS/TP state machine to use for putting received data */
uint16_t dlmstp_put_receive(
uint8_t src, /* source MS/TP address */
uint16_t dlmstp_put_receive(uint8_t src, /* source MS/TP address */
uint8_t * pdu, /* PDU data */
uint16_t pdu_len)
{
+1 -2
View File
@@ -175,8 +175,7 @@ int ethernet_send_pdu(BACNET_ADDRESS * dest, /* destination address */
/* returns 1 on success, 0 on failure */
return ethernet_send(dest, /* destination address */
&src, /* source address */
npdu_data,
pdu, /* any data to be sent - may be null */
npdu_data, pdu, /* any data to be sent - may be null */
pdu_len); /* number of bytes of data */
}
+15 -15
View File
@@ -42,13 +42,13 @@
/* RTOS-32 */
#include "rtkernel.h"
#if defined(RTK32_VER)
#define _USER32_
#define _KERNEL32_
#include <windows.h>
#include <rttarget.h> /* for RTCMOSSetSystemTime */
#include <rtfiles.h> /* file system */
#include <rtfsys.h> /* file system */
#include <Rttbios.h>
#define _USER32_
#define _KERNEL32_
#include <windows.h>
#include <rttarget.h> /* for RTCMOSSetSystemTime */
#include <rtfiles.h> /* file system */
#include <rtfsys.h> /* file system */
#include <Rttbios.h>
#endif
#include <rtcom.h> /* serial port driver */
#include <itimer.h> /* time measurement & timer interrupt rate control */
@@ -60,10 +60,12 @@ static uint8_t Rx_Buf[MAX_MPDU] = { 0 };
static void Init_Service_Handlers(void)
{
/* we need to handle who-is to support dynamic device binding */
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is);
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS,
handler_who_is);
/* set the handler for all the services we don't implement */
/* It is required to send the proper reject message... */
apdu_set_unrecognized_service_handler_handler(handler_unrecognized_service);
apdu_set_unrecognized_service_handler_handler
(handler_unrecognized_service);
/* we must implement read property - it's required! */
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY,
handler_read_property);
@@ -77,8 +79,7 @@ void millisecond_task(void)
int i = 0; /* loop counter */
ticks = RTKGetTime() + MilliSecsToTicks(1);
while (TRUE)
{
while (TRUE) {
RTKDelayUntil(ticks);
dlmstp_millisecond_timer();
ticks += MilliSecsToTicks(1);
@@ -88,15 +89,14 @@ void millisecond_task(void)
void RTOS_Initialize(void)
{
/* allow OS to setup IRQ 1 by using a dummy call */
(void)kbhit();
(void) kbhit();
RTKernelInit(0); /* get the kernel going */
RTKeybrdInit();
//(void)CPUMoniInit(); /* not needed - just monitor idle task */
RTComInit();
ITimerInit();
if (RTCallDebugger(RT_DBG_MONITOR,0,0) != -1)
{
if (RTCallDebugger(RT_DBG_MONITOR, 0, 0) != -1) {
/* Win32 structured exception - if no handler is
installed, TerminateProcess() will be called,
which will reboot - a good thing in our case. */
@@ -125,7 +125,7 @@ void RTOS_Initialize(void)
RTCMOSSetSystemTime(); /* get the right time-of-day */
/* create timer tick task */
RTKCreateTask(millisecond_task,1,1024*8,"millisec task");
RTKCreateTask(millisecond_task, 1, 1024 * 8, "millisec task");
}
int main(int argc, char *argv[])
+2 -4
View File
@@ -167,8 +167,7 @@ void RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port)
}
/* wait for state machine to read from the DataRegister */
else if (!mstp_port->DataAvailable) {
if (!ticks)
{
if (!ticks) {
ticks = MilliSecsToTicks(timeout);
if (!ticks)
ticks = 1;
@@ -185,7 +184,6 @@ void RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port)
mstp_port->DataAvailable = true;
}
}
}
else
} else
RTKScheduler();
}
+1 -2
View File
@@ -278,8 +278,7 @@ bool tsm_invoke_id_failed(uint8_t invokeID)
uint8_t index;
index = tsm_find_invokeID_index(invokeID);
if (index < MAX_TSM_TRANSACTIONS)
{
if (index < MAX_TSM_TRANSACTIONS) {
/* a valid invoke ID and the state is IDLE is a
message that failed to confirm */
if (TSM_List[index].state == TSM_STATE_IDLE)