Indented using indent script. Corrected any C++ comments using the comment script.

This commit is contained in:
skarg
2008-03-10 21:00:48 +00:00
parent 25b4979a28
commit cf9d15631a
33 changed files with 381 additions and 436 deletions
+51 -32
View File
@@ -457,7 +457,8 @@ static void MSTP_Receive_Frame_FSM(
switch (Receive_State) {
case MSTP_RECEIVE_STATE_IDLE:
/* In the IDLE state, the node waits for the beginning of a frame. */
/* In the IDLE state, the node waits
for the beginning of a frame. */
if (RS485_ReceiveError()) {
/* EatAnError */
Timer_Silence_Reset();
@@ -507,10 +508,12 @@ static void MSTP_Receive_Frame_FSM(
}
break;
case MSTP_RECEIVE_STATE_HEADER:
/* In the HEADER state, the node waits for the fixed message header. */
/* In the HEADER state, the node waits
for the fixed message header. */
if (Timer_Silence() > Tframe_abort) {
/* Timeout */
/* indicate that an error has occurred during the reception of a frame */
/* indicate that an error has occurred
during the reception of a frame */
MSTP_Flag.ReceivedInvalidFrame = true;
/* wait for the start of a frame. */
Receive_State = MSTP_RECEIVE_STATE_IDLE;
@@ -518,7 +521,8 @@ static void MSTP_Receive_Frame_FSM(
/* Error */
Timer_Silence_Reset();
INCREMENT_AND_LIMIT_UINT8(EventCount);
/* indicate that an error has occurred during the reception of a frame */
/* indicate that an error has occurred
during the reception of a frame */
MSTP_Flag.ReceivedInvalidFrame = true;
/* wait for the start of a frame. */
Receive_State = MSTP_RECEIVE_STATE_IDLE;
@@ -606,10 +610,12 @@ static void MSTP_Receive_Frame_FSM(
}
break;
case MSTP_RECEIVE_STATE_DATA:
/* In the DATA state, the node waits for the data portion of a frame. */
/* In the DATA state, the node waits
for the data portion of a frame. */
if (Timer_Silence() > Tframe_abort) {
/* Timeout */
/* indicate that an error has occurred during the reception of a frame */
/* indicate that an error has occurred
during the reception of a frame */
MSTP_Flag.ReceivedInvalidFrame = true;
/* wait for the start of the next frame. */
Receive_State = MSTP_RECEIVE_STATE_IDLE;
@@ -671,9 +677,9 @@ static bool MSTP_Master_Node_FSM(
/* When this counter reaches the value Nmax_info_frames, the node must */
/* pass the token. */
static uint8_t FrameCount;
/* "Next Station," the MAC address of the node to which This Station passes */
/* the token. If the Next_Station is unknown, Next_Station shall be equal to */
/* This_Station. */
/* "Next Station," the MAC address of the node to which This Station
passes the token. If the Next_Station is unknown, Next_Station shall
be equal to This_Station. */
static uint8_t Next_Station;
/* "Poll Station," the MAC address of the node to which This Station last */
/* sent a Poll For Master. This is used during token maintenance. */
@@ -681,10 +687,10 @@ static bool MSTP_Master_Node_FSM(
/* A counter of transmission retries used for Token and Poll For Master */
/* transmission. */
static unsigned RetryCount;
/* The number of tokens received by this node. When this counter reaches the */
/* value Npoll, the node polls the address range between TS and NS for */
/* additional master nodes. TokenCount is set to zero at the end of the */
/* polling process. */
/* The number of tokens received by this node. When this counter reaches */
/* the value Npoll, the node polls the address range between TS and NS */
/* for additional master nodes. TokenCount is set to zero at the end of */
/* the polling process. */
static unsigned TokenCount;
/* next-x-station calculations */
uint8_t next_poll_station = 0;
@@ -749,7 +755,7 @@ static bool MSTP_Master_Node_FSM(
MSTP_Flag.ReceivePacketPending = true;
break;
case FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY:
/* indicate successful reception to the higher layers */
/* indicate successful reception to higher layers */
MSTP_Flag.ReceivePacketPending = true;
/* broadcast DER just remains IDLE */
if (DestinationAddress != MSTP_BROADCAST_ADDRESS) {
@@ -759,8 +765,8 @@ static bool MSTP_Master_Node_FSM(
break;
case FRAME_TYPE_TEST_REQUEST:
MSTP_Send_Frame(FRAME_TYPE_TEST_RESPONSE,
SourceAddress, This_Station,
&InputBuffer[0], DataLength);
SourceAddress, This_Station, &InputBuffer[0],
DataLength);
break;
case FRAME_TYPE_TEST_RESPONSE:
default:
@@ -823,8 +829,10 @@ static bool MSTP_Master_Node_FSM(
FrameCount = Nmax_info_frames;
Master_State = MSTP_MASTER_STATE_DONE_WITH_TOKEN;
/* Any retry of the data frame shall await the next entry */
/* to the USE_TOKEN state. (Because of the length of the timeout, */
/* this transition will cause the token to be passed regardless */
/* to the USE_TOKEN state. */
/* (Because of the length of the timeout, */
/* this transition will cause the token to be */
/* passed regardless */
/* of the initial value of FrameCount.) */
transition_now = true;
} else {
@@ -848,8 +856,10 @@ static bool MSTP_Master_Node_FSM(
break;
case FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY:
/* ReceivedReply */
/* or a proprietary type that indicates a reply */
/* indicate successful reception to the higher layers */
/* or a proprietary type that indicates
a reply */
/* indicate successful reception to
the higher layers */
MSTP_Flag.ReceivePacketPending = true;
Master_State =
MSTP_MASTER_STATE_DONE_WITH_TOKEN;
@@ -891,7 +901,8 @@ static bool MSTP_Master_Node_FSM(
(Next_Station != next_this_station)) {
/* SoleMaster */
/* there are no other known master nodes to */
/* which the token may be sent (true master-slave operation). */
/* which the token may be sent
(true master-slave operation). */
FrameCount = 0;
TokenCount++;
Master_State = MSTP_MASTER_STATE_USE_TOKEN;
@@ -899,9 +910,12 @@ static bool MSTP_Master_Node_FSM(
} else {
/* SendToken */
/* Npoll changed in Errata SSPC-135-2004 */
/* The comparison of NS and TS+1 eliminates the Poll For Master */
/* if there are no addresses between TS and NS, since there is no */
/* address at which a new master node may be found in that case. */
/* The comparison of NS and TS+1
eliminates the Poll For Master
if there are no addresses between
TS and NS, since there is no
address at which a new master node
may be found in that case. */
TokenCount++;
/* transmit a Token frame to NS */
MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station,
@@ -949,7 +963,8 @@ static bool MSTP_Master_Node_FSM(
if (Timer_Silence() <= Tusage_timeout) {
if (EventCount > Nmin_octets) {
/* SawTokenUser */
/* Assume that a frame has been sent by the new token user. */
/* Assume that a frame has been sent by
the new token user. */
/* Enter the IDLE state to process the frame. */
Master_State = MSTP_MASTER_STATE_IDLE;
transition_now = true;
@@ -981,17 +996,19 @@ static bool MSTP_Master_Node_FSM(
}
}
break;
/* The NO_TOKEN state is entered if Timer_Silence() becomes greater */
/* than Tno_token, indicating that there has been no network activity */
/* for that period of time. The timeout is continued to determine */
/* whether or not this node may create a token. */
/* The NO_TOKEN state is entered if Timer_Silence()
becomes greater than Tno_token, indicating that
there has been no network activity for that period
of time. The timeout is continued to determine
whether or not this node may create a token. */
case MSTP_MASTER_STATE_NO_TOKEN:
my_timeout = Tno_token + (Tslot * This_Station);
if (Timer_Silence() < my_timeout) {
if (EventCount > Nmin_octets) {
/* SawFrame */
/* Some other node exists at a lower address. */
/* Enter the IDLE state to receive and process the incoming frame. */
/* Enter the IDLE state to receive and
process the incoming frame. */
Master_State = MSTP_MASTER_STATE_IDLE;
transition_now = true;
}
@@ -1010,7 +1027,8 @@ static bool MSTP_Master_Node_FSM(
RetryCount = 0;
TokenCount = 0;
/* EventCount = 0; removed Addendum 135-2004d-8 */
/* enter the POLL_FOR_MASTER state to find a new successor to TS. */
/* enter the POLL_FOR_MASTER state
to find a new successor to TS. */
Master_State = MSTP_MASTER_STATE_POLL_FOR_MASTER;
}
}
@@ -1075,7 +1093,8 @@ static bool MSTP_Master_Node_FSM(
/* Re-enter the current state. */
} else {
/* DeclareSoleMaster */
/* to indicate that this station is the only master */
/* to indicate that this station
is the only master */
MSTP_Flag.SoleMaster = true;
FrameCount = 0;
Master_State = MSTP_MASTER_STATE_USE_TOKEN;
+2 -2
View File
@@ -673,8 +673,8 @@ static bool MSTP_Master_Node_FSM(
break;
case FRAME_TYPE_TEST_REQUEST:
MSTP_Send_Frame(FRAME_TYPE_TEST_RESPONSE,
SourceAddress, This_Station,
&InputBuffer[0], DataLength);
SourceAddress, This_Station, &InputBuffer[0],
DataLength);
break;
case FRAME_TYPE_TEST_RESPONSE:
default:
+2 -2
View File
@@ -758,8 +758,8 @@ static bool MSTP_Master_Node_FSM(
break;
case FRAME_TYPE_TEST_REQUEST:
MSTP_Send_Frame(FRAME_TYPE_TEST_RESPONSE,
SourceAddress, This_Station,
&InputBuffer[0], DataLength);
SourceAddress, This_Station, &InputBuffer[0],
DataLength);
break;
case FRAME_TYPE_TEST_RESPONSE:
default:
+2 -1
View File
@@ -45,7 +45,8 @@ bool BIP_Debug = false;
a name that is a domain name
returns 0 if not found, or
an IP address in network byte order */
long bip_getaddrbyname(const char *host_name)
long bip_getaddrbyname(
const char *host_name)
{
struct hostent *host_ent;
+2 -2
View File
@@ -672,7 +672,7 @@ static int create_named_server_socket(
}
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &sock, sizeof(sock));
/* Bind a name to the socket. */
bzero((char *)&name, sizeof(name));
bzero((char *) &name, sizeof(name));
name.sun_family = AF_LOCAL;
strncpy(name.sun_path, filename, sizeof(name.sun_path));
/* The size of the address is
@@ -711,7 +711,7 @@ static int connect_named_server_socket(
#endif
exit(EXIT_FAILURE);
}
bzero((char *)&name, sizeof(name));
bzero((char *) &name, sizeof(name));
name.sun_family = AF_LOCAL;
strncpy(name.sun_path, filename, sizeof(name.sun_path));
/* The size of the address is
+33 -29
View File
@@ -49,7 +49,8 @@ bool BIP_Debug = false;
a name that is a domain name
returns 0 if not found, or
an IP address in network byte order */
long bip_getaddrbyname(const char *host_name)
long bip_getaddrbyname(
const char *host_name)
{
struct hostent *host_ent;
@@ -85,53 +86,56 @@ static long gethostaddr(
#if (!defined(USE_INADDR) || (USE_INADDR == 0)) && \
(!defined(USE_CLASSADDR) || (USE_CLASSADDR == 0))
/* returns the subnet mask in network byte order */
static uint32_t getIpMaskForIpAddress( uint32_t ipAddress )
static uint32_t getIpMaskForIpAddress(
uint32_t ipAddress)
{
/* Allocate information for up to 16 NICs */
IP_ADAPTER_INFO AdapterInfo[16];
IP_ADAPTER_INFO AdapterInfo[16];
/* Save memory size of buffer */
DWORD dwBufLen = sizeof(AdapterInfo);
DWORD dwBufLen = sizeof(AdapterInfo);
uint32_t ipMask = INADDR_BROADCAST;
PIP_ADAPTER_INFO pAdapterInfo;
/* GetAdapterInfo:
[out] buffer to receive data
[in] size of receive data buffer */
DWORD dwStatus = GetAdaptersInfo(
AdapterInfo,
&dwBufLen);
if( dwStatus == ERROR_SUCCESS ) {
[out] buffer to receive data
[in] size of receive data buffer */
DWORD dwStatus = GetAdaptersInfo(AdapterInfo,
&dwBufLen);
if (dwStatus == ERROR_SUCCESS) {
/* Verify return value is valid, no buffer overflow
Contains pointer to current adapter info */
pAdapterInfo = AdapterInfo;
pAdapterInfo = AdapterInfo;
do {
IP_ADDR_STRING* pIpAddressInfo = &pAdapterInfo->IpAddressList;
do {
unsigned long adapterAddress = inet_addr(pIpAddressInfo->IpAddress.String);
unsigned long adapterMask = inet_addr(pIpAddressInfo->IpMask.String);
if( adapterAddress == ipAddress ) {
ipMask = adapterMask;
IP_ADDR_STRING *pIpAddressInfo = &pAdapterInfo->IpAddressList;
do {
unsigned long adapterAddress =
inet_addr(pIpAddressInfo->IpAddress.String);
unsigned long adapterMask =
inet_addr(pIpAddressInfo->IpMask.String);
if (adapterAddress == ipAddress) {
ipMask = adapterMask;
break;
}
pIpAddressInfo = pIpAddressInfo->Next;
}
while(pIpAddressInfo);
if( ipMask != 0L ) {
while (pIpAddressInfo);
if (ipMask != 0L) {
break;
}
/* Progress through linked list */
pAdapterInfo = pAdapterInfo->Next;
/* Terminate on last adapter */
} while(pAdapterInfo);
/* Terminate on last adapter */
} while (pAdapterInfo);
}
return ipMask;
}
#endif
static void set_broadcast_address(uint32_t net_address)
static void set_broadcast_address(
uint32_t net_address)
{
#if defined(USE_INADDR) && USE_INADDR
/* Note: sometimes INADDR_BROADCAST does not let me get
@@ -154,20 +158,20 @@ static void set_broadcast_address(uint32_t net_address)
broadcast_address =
(ntohl(net_address) & ~IN_CLASSD_HOST) | IN_CLASSD_HOST;
else
broadcast_address = INADDR_BROADCAST;
broadcast_address = INADDR_BROADCAST;
bip_set_broadcast_addr(htonl(broadcast_address));
#else
/* these are network byte order variables */
long broadcast_address = 0;
long net_mask = 0;
net_mask = getIpMaskForIpAddress( net_address );
net_mask = getIpMaskForIpAddress(net_address);
if (BIP_Debug) {
struct in_addr address;
address.s_addr = net_mask;
printf("IP Mask: %s\n", inet_ntoa(address));
}
broadcast_address = (net_address & net_mask) | (~net_mask);
broadcast_address = (net_address & net_mask) | (~net_mask);
bip_set_broadcast_addr(broadcast_address);
#endif
}