Converted to standard indent style.
This commit is contained in:
@@ -66,7 +66,7 @@ int dlmstp_send_pdu(BACNET_ADDRESS * dest, /* destination address */
|
||||
int bytes_sent = 0;
|
||||
uint8_t frame_type = 0;
|
||||
uint8_t destination = 0; /* destination address */
|
||||
BACNET_ADDRESS src;
|
||||
BACNET_ADDRESS src;
|
||||
unsigned mtu_len = 0;
|
||||
|
||||
if (MSTP_Port.TxReady == false) {
|
||||
@@ -84,23 +84,22 @@ int dlmstp_send_pdu(BACNET_ADDRESS * dest, /* destination address */
|
||||
fprintf(stderr, "mstp: invalid destination MAC address!\n");
|
||||
#endif
|
||||
return -2;
|
||||
}
|
||||
/* header len */
|
||||
}
|
||||
/* header len */
|
||||
mtu_len = 8;
|
||||
if ((mtu_len + pdu_len) > MAX_MPDU) {
|
||||
if ((mtu_len + pdu_len) > MAX_MPDU) {
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "mstp: PDU is too big to send!\n");
|
||||
#endif
|
||||
return -4;
|
||||
}
|
||||
memmove(&PDU_Buffer[mtu_len], pdu, pdu_len);
|
||||
}
|
||||
memmove(&PDU_Buffer[mtu_len], pdu, pdu_len);
|
||||
mtu_len += pdu_len;
|
||||
bytes_sent = MSTP_Create_Frame(
|
||||
(uint8_t *) & MSTP_Port.TxBuffer[0],
|
||||
sizeof(MSTP_Port.TxBuffer),
|
||||
MSTP_Port.TxFrameType,
|
||||
destination,
|
||||
MSTP_Port.This_Station, &PDU_Buffer[0], mtu_len);
|
||||
destination, MSTP_Port.This_Station, &PDU_Buffer[0], mtu_len);
|
||||
MSTP_Port.TxLength = bytes_sent;
|
||||
MSTP_Port.TxReady = true;
|
||||
}
|
||||
@@ -123,7 +122,7 @@ uint16_t dlmstp_receive(BACNET_ADDRESS * src, /* source address */
|
||||
{
|
||||
uint16_t pdu_len = 0;
|
||||
|
||||
(void) timeout;
|
||||
(void) timeout;
|
||||
/* only do receive state machine while we don't have a frame */
|
||||
if ((MSTP_Port.ReceivedValidFrame == false) &&
|
||||
(MSTP_Port.ReceivedInvalidFrame == false)) {
|
||||
@@ -132,7 +131,8 @@ uint16_t dlmstp_receive(BACNET_ADDRESS * src, /* source address */
|
||||
}
|
||||
/* only do master state machine while rx is 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 */
|
||||
if (Receive_Buffer.ready) {
|
||||
|
||||
@@ -96,7 +96,7 @@ int ethernet_send(BACNET_ADDRESS * dest, /* destination address */
|
||||
int mtu_len = 0;
|
||||
int i = 0;
|
||||
|
||||
(void)npdu_data;
|
||||
(void) npdu_data;
|
||||
/* don't waste time if the socket is not valid */
|
||||
if (Ethernet_Socket < 0) {
|
||||
fprintf(stderr, "ethernet: 802.2 socket is invalid!\n");
|
||||
|
||||
@@ -93,7 +93,7 @@ void RTOS_Initialize(void)
|
||||
RTKernelInit(5); /* get the kernel going */
|
||||
RTKeybrdInit();
|
||||
/*(void)CPUMoniInit(); /* not needed - just monitor idle task */ */
|
||||
RTComInit();
|
||||
RTComInit();
|
||||
ITimerInit();
|
||||
|
||||
if (RTCallDebugger(RT_DBG_MONITOR, 0, 0) != -1) {
|
||||
|
||||
@@ -56,13 +56,13 @@
|
||||
|
||||
/* debug print statements */
|
||||
#if PRINT_ENABLED
|
||||
#define PRINT_ENABLED_RECEIVE 0
|
||||
#define PRINT_ENABLED_RECEIVE_DATA 1
|
||||
#define PRINT_ENABLED_MASTER 0
|
||||
#define PRINT_ENABLED_RECEIVE 0
|
||||
#define PRINT_ENABLED_RECEIVE_DATA 1
|
||||
#define PRINT_ENABLED_MASTER 0
|
||||
#else
|
||||
#define PRINT_ENABLED_RECEIVE 0
|
||||
#define PRINT_ENABLED_RECEIVE_DATA 0
|
||||
#define PRINT_ENABLED_MASTER 0
|
||||
#define PRINT_ENABLED_RECEIVE 0
|
||||
#define PRINT_ENABLED_RECEIVE_DATA 0
|
||||
#define PRINT_ENABLED_MASTER 0
|
||||
#endif
|
||||
|
||||
/* MS/TP Frame Format */
|
||||
@@ -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. */
|
||||
mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE;
|
||||
} else {
|
||||
if ((mstp_port->DestinationAddress == mstp_port->This_Station)
|
||||
if ((mstp_port->DestinationAddress ==
|
||||
mstp_port->This_Station)
|
||||
|| (mstp_port->DestinationAddress ==
|
||||
MSTP_BROADCAST_ADDRESS)) {
|
||||
/* FrameTooLong */
|
||||
@@ -467,39 +468,42 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port)
|
||||
/* unacceptable data length has been received */
|
||||
mstp_port->ReceivedInvalidFrame = true;
|
||||
/* 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 */
|
||||
else if (mstp_port->DataLength == 0) {
|
||||
/* CHEAT: it is very difficult to respond to
|
||||
poll for master in the Master Node state machine
|
||||
before Tusage_timeout, so we will do it here. */
|
||||
if ((mstp_port->FrameType == FRAME_TYPE_POLL_FOR_MASTER) &&
|
||||
(mstp_port->DestinationAddress == mstp_port->This_Station) &&
|
||||
(mstp_port->master_state == MSTP_MASTER_STATE_IDLE))
|
||||
{
|
||||
if ((mstp_port->FrameType ==
|
||||
FRAME_TYPE_POLL_FOR_MASTER)
|
||||
&& (mstp_port->DestinationAddress ==
|
||||
mstp_port->This_Station)
|
||||
&& (mstp_port->master_state ==
|
||||
MSTP_MASTER_STATE_IDLE)) {
|
||||
MSTP_Create_And_Send_Frame(mstp_port,
|
||||
FRAME_TYPE_REPLY_TO_POLL_FOR_MASTER,
|
||||
mstp_port->SourceAddress, mstp_port->This_Station,
|
||||
NULL, 0);
|
||||
mstp_port->SourceAddress,
|
||||
mstp_port->This_Station, NULL, 0);
|
||||
/* don't indicate that a frame has been received */
|
||||
mstp_port->ReceivedInvalidFrame = false;
|
||||
mstp_port->ReceivedValidFrame = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* indicate that a frame with no data has been received */
|
||||
mstp_port->ReceivedValidFrame = true;
|
||||
}
|
||||
/* 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 */
|
||||
else {
|
||||
mstp_port->Index = 0;
|
||||
mstp_port->DataCRC = 0xFFFF;
|
||||
/* receive the data portion of the frame. */
|
||||
mstp_port->receive_state = MSTP_RECEIVE_STATE_DATA;
|
||||
mstp_port->receive_state =
|
||||
MSTP_RECEIVE_STATE_DATA;
|
||||
}
|
||||
}
|
||||
/* NotForUs */
|
||||
@@ -508,8 +512,8 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port)
|
||||
mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/* not per MS/TP standard, but it is a case not covered */
|
||||
else {
|
||||
@@ -681,7 +685,7 @@ char *mstp_frame_type_text(int type)
|
||||
#endif
|
||||
|
||||
/* returns true if we need to transition immediately */
|
||||
bool MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port)
|
||||
bool MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t * mstp_port)
|
||||
{
|
||||
int mtu_len = 0;
|
||||
int frame_type = 0;
|
||||
|
||||
@@ -23,9 +23,9 @@
|
||||
*
|
||||
*********************************************************************/
|
||||
#if PRINT_ENABLED
|
||||
#define PRINT_ENABLED_RS485 1
|
||||
#define PRINT_ENABLED_RS485 1
|
||||
#else
|
||||
#define PRINT_ENABLED_RS485 0
|
||||
#define PRINT_ENABLED_RS485 0
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
@@ -57,27 +57,24 @@ static FineTime RS485_Debug_Transmit_Timer;
|
||||
#endif
|
||||
|
||||
#if PRINT_ENABLED_RS485
|
||||
void RS485_Print_Frame(int port,
|
||||
FineTime timer,
|
||||
uint8_t * buffer, /* frame to send (up to 501 bytes of data) */
|
||||
void RS485_Print_Frame(int port, FineTime timer, uint8_t * buffer, /* frame to send (up to 501 bytes of data) */
|
||||
uint16_t nbytes)
|
||||
{
|
||||
uint16_t i; /* byte counter */
|
||||
unsigned long duration; /* measures the time from last output to this one */
|
||||
uint16_t i; /* byte counter */
|
||||
unsigned long duration; /* measures the time from last output to this one */
|
||||
unsigned long seconds;
|
||||
unsigned long milliseconds;
|
||||
|
||||
|
||||
duration = ElapsedMilliSecs(timer);
|
||||
seconds = duration / 1000U;
|
||||
milliseconds = duration - (seconds * 1000U);
|
||||
fprintf(stderr,"%0lu.%03lu: COM%d:",seconds,milliseconds,port+1);
|
||||
for (i = 0; i < nbytes; i++)
|
||||
{
|
||||
unsigned value;
|
||||
value = buffer[i];
|
||||
fprintf(stderr," %02X",value);
|
||||
fprintf(stderr, "%0lu.%03lu: COM%d:", seconds, milliseconds, port + 1);
|
||||
for (i = 0; i < nbytes; i++) {
|
||||
unsigned value;
|
||||
value = buffer[i];
|
||||
fprintf(stderr, " %02X", value);
|
||||
}
|
||||
fprintf(stderr,"\n");
|
||||
fprintf(stderr, "\n");
|
||||
fflush(stderr);
|
||||
}
|
||||
#endif
|
||||
@@ -179,10 +176,8 @@ void RS485_Send_Frame(volatile struct mstp_port_struct_t *mstp_port, /* port
|
||||
octet is transmitted. */
|
||||
mstp_port->SilenceTimer = 0;
|
||||
#if PRINT_ENABLED_RS485
|
||||
RS485_Print_Frame(RS485_Port,
|
||||
RS485_Debug_Transmit_Timer,
|
||||
buffer, /* frame to send (up to 501 bytes of data) */
|
||||
nbytes);
|
||||
RS485_Print_Frame(RS485_Port, RS485_Debug_Transmit_Timer, buffer, /* frame to send (up to 501 bytes of data) */
|
||||
nbytes);
|
||||
MarkTime(&RS485_Debug_Transmit_Timer);
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user