changed c++ comments to c comments using comment.sh script.

This commit is contained in:
skarg
2006-02-19 01:33:30 +00:00
parent dee63d45bc
commit b686fa7ca7
34 changed files with 975 additions and 1030 deletions
+54 -54
View File
@@ -23,10 +23,10 @@
*
*********************************************************************/
#include <stdint.h> // for standard integer types uint8_t etc.
#include <stdbool.h> // for the standard bool type.
#include <stdio.h> // for the standard bool type.
#include <stdlib.h> // for the standard bool type.
#include <stdint.h> /* for standard integer types uint8_t etc. */
#include <stdbool.h> /* for the standard bool type. */
#include <stdio.h> /* for the standard bool type. */
#include <stdlib.h> /* for the standard bool type. */
#include <rttarget.h>
#include <rtk32.h>
#include <clock.h>
@@ -35,17 +35,17 @@
#include "ethernet.h"
#include "bacdcode.h"
// commonly used comparison address for ethernet
/* commonly used comparison address for ethernet */
uint8_t Ethernet_Broadcast[MAX_MAC_LEN] =
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
// commonly used empty address for ethernet quick compare
/* commonly used empty address for ethernet quick compare */
uint8_t Ethernet_Empty_MAC[MAX_MAC_LEN] = { 0, 0, 0, 0, 0, 0 };
// my local device data - MAC address
/* my local device data - MAC address */
uint8_t Ethernet_MAC_Address[MAX_MAC_LEN] = { 0, 0, 0, 0, 0, 0 };
static SOCKET Ethernet_Socket = -1;
// used for binding 802.2
/* used for binding 802.2 */
static struct sockaddr Ethernet_Address = { 0 };
bool ethernet_valid(void)
@@ -67,9 +67,9 @@ bool ethernet_init(char *interface_name)
int value = 1;
(void) interface_name;
// setup the socket
/* setup the socket */
Ethernet_Socket = socket(AF_INET, SOCK_RAW, 0);
//Ethernet_Socket = socket(AF_INET, SOCK_STREAM, 0);
/*Ethernet_Socket = socket(AF_INET, SOCK_STREAM, 0); */
if (Ethernet_Socket < 0)
fprintf(stderr, "ethernet: failed to bind to socket!\r\n");
Ethernet_Address.sa_family = AF_INET;
@@ -77,24 +77,24 @@ bool ethernet_init(char *interface_name)
if (bind(Ethernet_Socket,
&Ethernet_Address, sizeof(Ethernet_Address)) == SOCKET_ERROR)
fprintf(stderr, "ethernet: failed to bind to socket!\r\n");
//setsockopt(Ethernet_Socket,SOL_SOCKET,SO_802_2,(char *)&value,sizeof(value));
/*setsockopt(Ethernet_Socket,SOL_SOCKET,SO_802_2,(char *)&value,sizeof(value)); */
return ethernet_valid();
}
/* function to send a packet out the 802.2 socket */
/* returns bytes sent on success, negative number on failure */
int ethernet_send(BACNET_ADDRESS * dest, // destination address
BACNET_ADDRESS * src, // source address
uint8_t * pdu, // any data to be sent - may be null
unsigned pdu_len) // number of bytes of data
{
int ethernet_send(BACNET_ADDRESS * dest, /* destination address */
BACNET_ADDRESS * src, /* source address */
uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len)
{ /* number of bytes of data */
int bytes = 0;
uint8_t mtu[MAX_MPDU] = { 0 };
int mtu_len = 0;
int i = 0;
// don't waste time if the socket is not valid
/* don't waste time if the socket is not valid */
if (Ethernet_Socket < 0) {
fprintf(stderr, "ethernet: 802.2 socket is invalid!\n");
return -1;
@@ -127,7 +127,7 @@ int ethernet_send(BACNET_ADDRESS * dest, // destination address
/* packet length */
mtu_len += encode_unsigned16(&mtu[12],
3 /*DSAP,SSAP,LLC */ + pdu_len);
// Logical PDU portion
/* Logical PDU portion */
mtu[mtu_len++] = 0x82; /* DSAP for BACnet */
mtu[mtu_len++] = 0x82; /* SSAP for BACnet */
mtu[mtu_len++] = 0x03; /* Control byte in header */
@@ -146,12 +146,12 @@ int ethernet_send(BACNET_ADDRESS * dest, // destination address
/* function to send a packet out the 802.2 socket */
/* returns bytes sent on success, negative number on failure */
int ethernet_send_pdu(BACNET_ADDRESS * dest, // destination address
uint8_t * pdu, // any data to be sent - may be null
unsigned pdu_len) // number of bytes of data
{
int i = 0; // counter
BACNET_ADDRESS src = { 0 }; // source address
int ethernet_send_pdu(BACNET_ADDRESS * dest, /* destination address */
uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len)
{ /* number of bytes of data */
int i = 0; /* counter */
BACNET_ADDRESS src = { 0 }; /* source address */
for (i = 0; i < 6; i++) {
src.mac[i] = Ethernet_MAC_Address[i];
@@ -159,22 +159,22 @@ int ethernet_send_pdu(BACNET_ADDRESS * dest, // destination address
}
/* function to send a packet out the 802.2 socket */
/* returns 1 on success, 0 on failure */
return ethernet_send(dest, // destination address
&src, // source address
pdu, // any data to be sent - may be null
pdu_len); // number of bytes of data
return ethernet_send(dest, /* destination address */
&src, /* source address */
pdu, /* any data to be sent - may be null */
pdu_len); /* number of bytes of data */
}
// receives an 802.2 framed packet
// returns the number of octets in the PDU, or zero on failure
uint16_t ethernet_receive(BACNET_ADDRESS * src, // source address
uint8_t * pdu, // PDU data
uint16_t max_pdu, // amount of space available in the PDU
unsigned timeout) // number of milliseconds to wait for a packet
{
/* receives an 802.2 framed packet */
/* returns the number of octets in the PDU, or zero on failure */
uint16_t ethernet_receive(BACNET_ADDRESS * src, /* source address */
uint8_t * pdu, /* PDU data */
uint16_t max_pdu, /* amount of space available in the PDU */
unsigned timeout)
{ /* number of milliseconds to wait for a packet */
int received_bytes;
uint8_t buf[MAX_MPDU] = { 0 }; // data
uint16_t pdu_len = 0; // return value
uint8_t buf[MAX_MPDU] = { 0 }; /* data */
uint16_t pdu_len = 0; /* return value */
fd_set read_fds;
int max;
struct timeval select_timeout;
@@ -206,9 +206,9 @@ uint16_t ethernet_receive(BACNET_ADDRESS * src, // source address
/* See if there is a problem */
if (received_bytes < 0) {
// EAGAIN Non-blocking I/O has been selected
// using O_NONBLOCK and no data
// was immediately available for reading.
/* EAGAIN Non-blocking I/O has been selected */
/* using O_NONBLOCK and no data */
/* was immediately available for reading. */
if (errno != EAGAIN)
fprintf(stderr,
"ethernet: Read error in receiving packet: %s\n",
@@ -221,28 +221,28 @@ uint16_t ethernet_receive(BACNET_ADDRESS * src, // source address
/* the signature of an 802.2 BACnet packet */
if ((buf[14] != 0x82) && (buf[15] != 0x82)) {
//fprintf(stderr,"ethernet: Non-BACnet packet\n");
/*fprintf(stderr,"ethernet: Non-BACnet packet\n"); */
return 0;
}
// copy the source address
/* copy the source address */
src->mac_len = 6;
memmove(src->mac, &buf[6], 6);
// check destination address for when
// the Ethernet card is in promiscious mode
/* check destination address for when */
/* the Ethernet card is in promiscious mode */
if ((memcmp(&buf[0], Ethernet_MAC_Address, 6) != 0)
&& (memcmp(&buf[0], Ethernet_Broadcast, 6) != 0)) {
//fprintf(stderr, "ethernet: This packet isn't for us\n");
/*fprintf(stderr, "ethernet: This packet isn't for us\n"); */
return 0;
}
(void) decode_unsigned16(&buf[12], &pdu_len);
pdu_len -= 3 /* DSAP, SSAP, LLC Control */ ;
// copy the buffer into the PDU
/* copy the buffer into the PDU */
if (pdu_len < max_pdu)
memmove(&pdu[0], &buf[17], pdu_len);
// ignore packets that are too large
// client should check my max apdu first
/* ignore packets that are too large */
/* client should check my max apdu first */
else
pdu_len = 0;
@@ -258,7 +258,7 @@ void ethernet_get_my_address(BACNET_ADDRESS * my_address)
my_address->mac[i] = Ethernet_MAC_Address[i];
my_address->mac_len++;
}
my_address->net = 0; // local only, no routing
my_address->net = 0; /* local only, no routing */
my_address->len = 0;
for (i = 0; i < MAX_MAC_LEN; i++) {
my_address->adr[i] = 0;
@@ -278,9 +278,9 @@ void ethernet_set_my_address(BACNET_ADDRESS * my_address)
return;
}
void ethernet_get_broadcast_address(BACNET_ADDRESS * dest) // destination address
{
int i = 0; // counter
void ethernet_get_broadcast_address(BACNET_ADDRESS * dest)
{ /* destination address */
int i = 0; /* counter */
if (dest) {
for (i = 0; i < 6; i++) {
@@ -288,7 +288,7 @@ void ethernet_get_broadcast_address(BACNET_ADDRESS * dest) // destination a
}
dest->mac_len = 6;
dest->net = BACNET_BROADCAST_NETWORK;
dest->len = 0; // denotes broadcast address
dest->len = 0; /* denotes broadcast address */
for (i = 0; i < MAX_MAC_LEN; i++) {
dest->adr[i] = 0;
}
@@ -299,7 +299,7 @@ void ethernet_get_broadcast_address(BACNET_ADDRESS * dest) // destination a
void ethernet_debug_address(const char *info, BACNET_ADDRESS * dest)
{
int i = 0; // counter
int i = 0; /* counter */
if (info)
fprintf(stderr, "%s", info);