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
+3 -3
View File
@@ -49,7 +49,7 @@
#include "client.h"
#include "txbuf.h"
// buffer used for receive
/* buffer used for receive */
static uint8_t Rx_Buf[MAX_MPDU] = { 0 };
/* global variables used in this file */
@@ -125,9 +125,9 @@ static void Init_Service_Handlers(void)
int main(int argc, char *argv[])
{
BACNET_ADDRESS src = { 0 }; // address where message came from
BACNET_ADDRESS src = { 0 }; /* address where message came from */
uint16_t pdu_len = 0;
unsigned timeout = 100; // milliseconds
unsigned timeout = 100; /* milliseconds */
unsigned max_apdu = 0;
time_t elapsed_seconds = 0;
time_t last_seconds = 0;
+6 -6
View File
@@ -50,7 +50,7 @@
#include "client.h"
#include "txbuf.h"
// buffer used for receive
/* buffer used for receive */
static uint8_t Rx_Buf[MAX_MPDU] = { 0 };
/* global variables used in this file */
@@ -133,9 +133,9 @@ static void Init_Service_Handlers(void)
}
#ifdef BIP_DEBUG
static void print_address(char *name, BACNET_ADDRESS * dest) // destination address
{
int i = 0; // counter
static void print_address(char *name, BACNET_ADDRESS * dest)
{ /* destination address */
int i = 0; /* counter */
if (dest) {
printf("%s: ", name);
@@ -149,9 +149,9 @@ static void print_address(char *name, BACNET_ADDRESS * dest) // destination a
int main(int argc, char *argv[])
{
BACNET_ADDRESS src = { 0 }; // address where message came from
BACNET_ADDRESS src = { 0 }; /* address where message came from */
uint16_t pdu_len = 0;
unsigned timeout = 100; // milliseconds
unsigned timeout = 100; /* milliseconds */
unsigned max_apdu = 0;
time_t elapsed_seconds = 0;
time_t last_seconds = 0;
+12 -12
View File
@@ -82,9 +82,9 @@ static void cleanup(void)
datalink_cleanup();
}
static void print_address(char *name, BACNET_ADDRESS * dest) // destination address
{
int i = 0; // counter
static void print_address(char *name, BACNET_ADDRESS * dest)
{ /* destination address */
int i = 0; /* counter */
if (dest) {
printf("%s: ", name);
@@ -97,9 +97,9 @@ static void print_address(char *name, BACNET_ADDRESS * dest) // destination a
int main(int argc, char *argv[])
{
BACNET_ADDRESS src = { 0 }; // address where message came from
BACNET_ADDRESS src = { 0 }; /* address where message came from */
uint16_t pdu_len = 0;
unsigned timeout = 100; // milliseconds
unsigned timeout = 100; /* milliseconds */
BACNET_ADDRESS my_address, broadcast_address;
time_t last_seconds = 0;
time_t current_seconds = 0;
@@ -113,7 +113,7 @@ int main(int argc, char *argv[])
Device_Object_Instance_Number());
Init_Service_Handlers();
#ifdef BACDL_ETHERNET
// init the physical layer
/* init the physical layer */
if (!ethernet_init("eth0"))
return 1;
#endif
@@ -136,15 +136,15 @@ int main(int argc, char *argv[])
last_seconds = time(NULL);
/* broadcast an I-Am on startup */
I_Am_Request = true;
// loop forever
/* loop forever */
for (;;) {
// input
/* input */
current_seconds = time(NULL);
// returns 0 bytes on timeout
/* returns 0 bytes on timeout */
pdu_len = datalink_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout);
// process
/* process */
if (pdu_len) {
npdu_handler(&src, &Rx_Buf[0], pdu_len);
}
@@ -156,8 +156,8 @@ int main(int argc, char *argv[])
I_Am_Request = false;
iam_send(&Handler_Transmit_Buffer[0]);
}
// output
/* output */
// blink LEDs, Turn on or off outputs, etc
/* blink LEDs, Turn on or off outputs, etc */
}
}
+6 -6
View File
@@ -49,7 +49,7 @@
#include "client.h"
#include "txbuf.h"
// buffer used for receive
/* buffer used for receive */
static uint8_t Rx_Buf[MAX_MPDU] = { 0 };
/* global variables used in this file */
@@ -103,9 +103,9 @@ static void Init_Service_Handlers(void)
}
#ifdef BIP_DEBUG
static void print_address(char *name, BACNET_ADDRESS * dest) // destination address
{
int i = 0; // counter
static void print_address(char *name, BACNET_ADDRESS * dest)
{ /* destination address */
int i = 0; /* counter */
if (dest) {
printf("%s: ", name);
@@ -119,9 +119,9 @@ static void print_address(char *name, BACNET_ADDRESS * dest) // destination a
int main(int argc, char *argv[])
{
BACNET_ADDRESS src = { 0 }; // address where message came from
BACNET_ADDRESS src = { 0 }; /* address where message came from */
uint16_t pdu_len = 0;
unsigned timeout = 100; // milliseconds
unsigned timeout = 100; /* milliseconds */
time_t elapsed_seconds = 0;
time_t last_seconds = 0;
time_t current_seconds = 0;
+8 -8
View File
@@ -48,7 +48,7 @@
#include "handlers.h"
#include "txbuf.h"
// buffer used for receive
/* buffer used for receive */
static uint8_t Rx_Buf[MAX_MPDU] = { 0 };
/* global variables used in this file */
@@ -117,11 +117,11 @@ static uint8_t Send_Atomic_Write_File_Stream(uint32_t device_id,
status = tsm_transaction_available();
if (status) {
datalink_get_my_address(&my_address);
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, &my_address, true, // true for confirmed messages
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, &my_address, true, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL);
invoke_id = tsm_next_free_invokeID();
// load the data for the encoding
/* load the data for the encoding */
data.object_type = OBJECT_FILE;
data.object_instance = file_instance;
data.access = FILE_STREAM_ACCESS;
@@ -138,8 +138,8 @@ static uint8_t Send_Atomic_Write_File_Stream(uint32_t device_id,
if ((unsigned) pdu_len <= max_apdu) {
tsm_set_confirmed_unsegmented_transaction(invoke_id,
&dest, &Handler_Transmit_Buffer[0], pdu_len);
bytes_sent = datalink_send_pdu(&dest, // destination address
&Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data
bytes_sent = datalink_send_pdu(&dest, /* destination address */
&Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
if (bytes_sent <= 0)
fprintf(stderr,
"Failed to Send AtomicWriteFile Request (%s)!\n",
@@ -167,7 +167,7 @@ static void Send_WhoIs(uint32_t device_id)
datalink_get_broadcast_address(&dest);
/* encode the NPDU portion of the packet */
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, NULL, false, // true for confirmed messages
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, NULL, false, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL);
/* encode the APDU portion of the packet */
@@ -227,9 +227,9 @@ static void Init_Service_Handlers(void)
int main(int argc, char *argv[])
{
BACNET_ADDRESS src = { 0 }; // address where message came from
BACNET_ADDRESS src = { 0 }; /* address where message came from */
uint16_t pdu_len = 0;
unsigned timeout = 100; // milliseconds
unsigned timeout = 100; /* milliseconds */
unsigned max_apdu = 0;
time_t elapsed_seconds = 0;
time_t last_seconds = 0;
+3 -3
View File
@@ -49,7 +49,7 @@
#include "client.h"
#include "txbuf.h"
// buffer used for receive
/* buffer used for receive */
static uint8_t Rx_Buf[MAX_MPDU] = { 0 };
/* global variables used in this file */
@@ -142,9 +142,9 @@ static void Init_Service_Handlers(void)
int main(int argc, char *argv[])
{
BACNET_ADDRESS src = { 0 }; // address where message came from
BACNET_ADDRESS src = { 0 }; /* address where message came from */
uint16_t pdu_len = 0;
unsigned timeout = 100; // milliseconds
unsigned timeout = 100; /* milliseconds */
unsigned max_apdu = 0;
time_t elapsed_seconds = 0;
time_t last_seconds = 0;
+47 -47
View File
@@ -37,13 +37,13 @@
#include "arcnet.h"
#include "net.h"
// my local device data - MAC address
/* my local device data - MAC address */
uint8_t ARCNET_MAC_Address = 0;
// ARCNET file handle
/* ARCNET file handle */
static int ARCNET_Sock_FD = -1;
// ARCNET socket address (has the interface name)
/* ARCNET socket address (has the interface name) */
static struct sockaddr ARCNET_Socket_Address;
// Broadcast address
/* Broadcast address */
#define ARCNET_BROADCAST 0
/*
@@ -95,9 +95,9 @@ void arcnet_cleanup(void)
static int arcnet_bind(char *interface_name)
{
int sock_fd = -1; // return value
int sock_fd = -1; /* return value */
struct ifreq ifr;
int rv; // return value - error value from df or ioctl call
int rv; /* return value - error value from df or ioctl call */
int uid = 0;
/* check to see if we are being run as root */
@@ -109,10 +109,10 @@ static int arcnet_bind(char *interface_name)
return sock_fd;
}
fprintf(stderr, "arcnet: opening \"%s\"\n", interface_name);
// note: on some systems you may have to add or enable in
// modules.conf (or in modutils/alias on Debian with update-modules)
// alias net-pf-17 af_packet
// Then follow it by: # modprobe af_packet
/* note: on some systems you may have to add or enable in */
/* modules.conf (or in modutils/alias on Debian with update-modules) */
/* alias net-pf-17 af_packet */
/* Then follow it by: # modprobe af_packet */
if ((sock_fd = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_ALL))) < 0) {
/* Error occured */
fprintf(stderr,
@@ -129,7 +129,7 @@ static int arcnet_bind(char *interface_name)
if (ARCNET_Sock_FD >= 0) {
/* Bind the socket to an interface name so we only get packets from it */
ARCNET_Socket_Address.sa_family = ARPHRD_ARCNET;
//ARCNET_Socket_Address.sa_family = PF_INET;
/*ARCNET_Socket_Address.sa_family = PF_INET; */
/* Clear the memory before copying */
memset(ARCNET_Socket_Address.sa_data, '\0',
sizeof(ARCNET_Socket_Address.sa_data));
@@ -158,9 +158,9 @@ static int arcnet_bind(char *interface_name)
rv = ioctl(sock_fd, SIOCGIFHWADDR, &ifr);
if (rv != -1) /* worked okay */
ARCNET_MAC_Address = ifr.ifr_hwaddr.sa_data[0];
// copy this info into the local copy since bind wiped it out
/* copy this info into the local copy since bind wiped it out */
ARCNET_Socket_Address.sa_family = ARPHRD_ARCNET;
//ARCNET_Socket_Address.sa_family = PF_INET;
/*ARCNET_Socket_Address.sa_family = PF_INET; */
/* Clear the memory before copying */
memset(ARCNET_Socket_Address.sa_data, '\0',
sizeof(ARCNET_Socket_Address.sa_data));
@@ -184,17 +184,17 @@ bool arcnet_init(char *interface_name)
/* function to send a packet out the socket */
/* returns number of bytes sent on success, negative on failure */
int arcnet_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 arcnet_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[512] = { 0 };
int mtu_len = 0;
struct archdr *pkt = (struct archdr *) mtu;
// don't waste time if the socket is not valid
/* don't waste time if the socket is not valid */
if (ARCNET_Sock_FD < 0) {
fprintf(stderr, "arcnet: socket is invalid!\n");
return -1;
@@ -239,30 +239,30 @@ int arcnet_send(BACNET_ADDRESS * dest, // destination address
/* function to send a PDU out the socket */
/* returns number of bytes sent on success, negative on failure */
int arcnet_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
{
BACNET_ADDRESS src = { 0 }; // source address
int arcnet_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 */
BACNET_ADDRESS src = { 0 }; /* source address */
src.mac[0] = ARCNET_MAC_Address;
src.mac_len = 1;
return arcnet_send(dest, // destination address
&src, // source address
pdu, // any data to be sent - may be null
pdu_len); // number of bytes of data
return arcnet_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 framed packet
// returns the number of octets in the PDU, or zero on failure
uint16_t arcnet_receive(BACNET_ADDRESS * src, // source address
uint8_t * pdu, // PDU data
uint16_t max_pdu, // amount of space available in the PDU
unsigned timeout) // milliseconds to wait for a packet
{
/* receives an framed packet */
/* returns the number of octets in the PDU, or zero on failure */
uint16_t arcnet_receive(BACNET_ADDRESS * src, /* source address */
uint8_t * pdu, /* PDU data */
uint16_t max_pdu, /* amount of space available in the PDU */
unsigned timeout)
{ /* milliseconds to wait for a packet */
int received_bytes;
uint8_t buf[512] = { 0 }; // data
uint16_t pdu_len = 0; // return value
uint8_t buf[512] = { 0 }; /* data */
uint16_t pdu_len = 0; /* return value */
fd_set read_fds;
int max;
struct timeval select_timeout;
@@ -294,9 +294,9 @@ uint16_t arcnet_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",
@@ -344,10 +344,10 @@ uint16_t arcnet_receive(BACNET_ADDRESS * src, // source address
/* compute the PDU length */
pdu_len = received_bytes - ARC_HDR_SIZE;
pdu_len -= 4 /* SC, DSAP, SSAP, LLC Control */ ;
// copy the buffer into the PDU
/* copy the buffer into the PDU */
if (pdu_len < max_pdu)
memmove(&pdu[0], &pkt->soft.raw[4], pdu_len);
// silently ignore packets that are too large
/* silently ignore packets that are too large */
else
pdu_len = 0;
@@ -360,7 +360,7 @@ void arcnet_get_my_address(BACNET_ADDRESS * my_address)
my_address->mac_len = 1;
my_address->mac[0] = ARCNET_MAC_Address;
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;
@@ -369,15 +369,15 @@ void arcnet_get_my_address(BACNET_ADDRESS * my_address)
return;
}
void arcnet_get_broadcast_address(BACNET_ADDRESS * dest) // destination address
{
int i = 0; // counter
void arcnet_get_broadcast_address(BACNET_ADDRESS * dest)
{ /* destination address */
int i = 0; /* counter */
if (dest) {
dest->mac[0] = ARCNET_BROADCAST;
dest->mac_len = 1;
dest->net = BACNET_BROADCAST_NETWORK;
dest->len = 0; // len=0 denotes broadcast address
dest->len = 0; /* len=0 denotes broadcast address */
for (i = 0; i < MAX_MAC_LEN; i++) {
dest->adr[i] = 0;
}
+10 -10
View File
@@ -32,8 +32,8 @@
-------------------------------------------
####COPYRIGHTEND####*/
#include <stdint.h> // for standard integer types uint8_t etc.
#include <stdbool.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 "bacdcode.h"
#include "bip.h"
#include "net.h"
@@ -43,7 +43,7 @@ static int get_local_ifr_ioctl(char *ifname, struct ifreq *ifr,
int request)
{
int fd;
int rv; // return value
int rv; /* return value */
strncpy(ifr->ifr_name, ifname, sizeof(ifr->ifr_name));
fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
@@ -60,7 +60,7 @@ static int get_local_address_ioctl(char *ifname,
{
struct ifreq ifr = { {{0}} };
struct sockaddr_in *tcpip_address;
int rv; // return value
int rv; /* return value */
rv = get_local_ifr_ioctl(ifname, &ifr, request);
if (rv >= 0) {
@@ -93,18 +93,18 @@ void bip_set_interface(char *ifname)
bool bip_init(void)
{
int status = 0; // return from socket lib calls
int status = 0; /* return from socket lib calls */
struct sockaddr_in sin;
int sockopt = 0;
int sock_fd = -1;
// assumes that the driver has already been initialized
/* assumes that the driver has already been initialized */
sock_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
bip_set_socket(sock_fd);
if (sock_fd < 0)
return false;
// Allow us to use the same socket for sending and receiving
// This makes sure that the src port is correct when sending
/* Allow us to use the same socket for sending and receiving */
/* This makes sure that the src port is correct when sending */
sockopt = 1;
status = setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR,
&sockopt, sizeof(sockopt));
@@ -113,7 +113,7 @@ bool bip_init(void)
bip_set_socket(-1);
return status;
}
// allow us to send a broadcast
/* allow us to send a broadcast */
status = setsockopt(sock_fd, SOL_SOCKET, SO_BROADCAST,
&sockopt, sizeof(sockopt));
if (status < 0) {
@@ -121,7 +121,7 @@ bool bip_init(void)
bip_set_socket(-1);
return status;
}
// bind the socket to the local port number and IP address
/* bind the socket to the local port number and IP address */
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = htonl(INADDR_ANY);
sin.sin_port = htons(bip_get_port());
+54 -54
View File
@@ -32,25 +32,25 @@
-------------------------------------------
####COPYRIGHTEND####*/
#include <stdint.h> // for standard integer types uint8_t etc.
#include <stdbool.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 "net.h"
#include "bacdef.h"
#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 };
static int eth802_sockfd = -1; /* 802.2 file handle */
static struct sockaddr eth_addr = { 0 }; // used for binding 802.2
static struct sockaddr eth_addr = { 0 }; /* used for binding 802.2 */
bool ethernet_valid(void)
{
@@ -87,7 +87,7 @@ int setNonblocking(int fd)
/* opens an 802.2 socket to receive and send packets */
static int ethernet_bind(struct sockaddr *eth_addr, char *interface_name)
{
int sock_fd = -1; // return value
int sock_fd = -1; /* return value */
int uid = 0;
fprintf(stderr, "ethernet: opening \"%s\"\n", interface_name);
@@ -99,10 +99,10 @@ static int ethernet_bind(struct sockaddr *eth_addr, char *interface_name)
"Try running with root priveleges.\n");
return sock_fd;
}
// note: on some systems you may have to add or enable in
// modules.conf (or in modutils/alias on Debian with update-modules)
// alias net-pf-17 af_packet
// Then follow it by: # modprobe af_packet
/* note: on some systems you may have to add or enable in */
/* modules.conf (or in modutils/alias on Debian with update-modules) */
/* alias net-pf-17 af_packet */
/* Then follow it by: # modprobe af_packet */
/* Attempt to open the socket for 802.2 ethernet frames */
if ((sock_fd = socket(PF_INET, SOCK_PACKET, htons(ETH_P_802_2))) < 0) {
@@ -152,7 +152,7 @@ static int get_local_hwaddr(const char *ifname, unsigned char *mac)
{
struct ifreq ifr;
int fd;
int rv; // return value - error value from df or ioctl call
int rv; /* return value - error value from df or ioctl call */
/* determine the local MAC address */
strcpy(ifr.ifr_name, ifname);
@@ -178,17 +178,17 @@ bool ethernet_init(char *interface_name)
/* function to send a packet out the 802.2 socket */
/* returns bytes sent success, negative 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 (eth802_sockfd < 0) {
fprintf(stderr, "ethernet: 802.2 socket is invalid!\n");
return -1;
@@ -221,7 +221,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 */
@@ -242,12 +242,12 @@ int ethernet_send(BACNET_ADDRESS * dest, // destination address
/* function to send a packet out the 802.2 socket */
/* returns number of bytes sent on success, negative 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];
@@ -255,22 +255,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;
@@ -301,9 +301,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",
@@ -316,27 +316,27 @@ 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
/* ignore packets that are too large */
else
pdu_len = 0;
@@ -364,7 +364,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;
@@ -373,9 +373,9 @@ void ethernet_get_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++) {
@@ -383,7 +383,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;
}
@@ -394,7 +394,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);
+24 -24
View File
@@ -44,10 +44,10 @@
#include "net.h"
#include "txbuf.h"
// This is an example application using the BACnet Stack on Linux
/* This is an example application using the BACnet Stack on Linux */
bool Who_Is_Request = true;
// buffers used for receiving
/* buffers used for receiving */
static uint8_t Rx_Buf[MAX_MPDU] = { 0 };
static void LocalIAmHandler(uint8_t * service_request,
@@ -134,7 +134,7 @@ static void Read_Properties(void)
invoke ID from the sending of the request, and wait until we
got the reply with matching invoke ID or the TSM of the
invoke ID expired. This demo is doing things asynchronously. */
status = Send_Read_Property_Request(device_id, // destination device
status = Send_Read_Property_Request(device_id, /* destination device */
OBJECT_DEVICE,
device_id, object_props[property], BACNET_ARRAY_ALL);
if (status)
@@ -156,25 +156,25 @@ static void Read_Properties(void)
static void Init_Service_Handlers(void)
{
// we need to handle who-is to support dynamic device binding
/* 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_I_AM,
LocalIAmHandler);
// set the handler for all the services we don't implement
// It is required to send the proper reject message...
/* 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);
// Set the handlers for any confirmed services that we support.
// We must implement read property - it's required!
/* Set the handlers for any confirmed services that we support. */
/* We must implement read property - it's required! */
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY,
handler_read_property);
apdu_set_confirmed_handler(SERVICE_CONFIRMED_WRITE_PROPERTY,
handler_write_property);
apdu_set_confirmed_handler(SERVICE_CONFIRMED_ATOMIC_READ_FILE,
handler_atomic_read_file);
// handle the data coming back from confirmed requests
/* handle the data coming back from confirmed requests */
apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_READ_PROPERTY,
handler_read_property_ack);
apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_ATOMIC_READ_FILE,
@@ -223,23 +223,23 @@ static void sig_handler(int signo)
int main(int argc, char *argv[])
{
BACNET_ADDRESS src = { 0 }; // address where message came from
BACNET_ADDRESS src = { 0 }; /* address where message came from */
uint16_t pdu_len = 0;
unsigned timeout = 100; // milliseconds
unsigned count = 0; // milliseconds
unsigned timeout = 100; /* milliseconds */
unsigned count = 0; /* milliseconds */
time_t start_time;
time_t new_time = 0;
start_time = time(NULL); /* get current time */
// Linux specials
/* Linux specials */
signal(SIGINT, sig_handler);
signal(SIGHUP, sig_handler);
signal(SIGTERM, sig_handler);
// setup this BACnet Server device
/* setup this BACnet Server device */
Device_Set_Object_Instance_Number(111);
Init_Service_Handlers();
#ifdef BACDL_ETHERNET
// init the physical layer
/* init the physical layer */
if (!ethernet_init("eth0"))
return 1;
#endif
@@ -254,14 +254,14 @@ int main(int argc, char *argv[])
return 1;
#endif
// loop forever
/* loop forever */
for (;;) {
// input
/* input */
new_time = time(NULL);
// returns 0 bytes on timeout
/* returns 0 bytes on timeout */
pdu_len = datalink_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout);
// process
/* process */
if (pdu_len) {
npdu_handler(&src, &Rx_Buf[0], pdu_len);
}
@@ -276,13 +276,13 @@ int main(int argc, char *argv[])
Who_Is_Request = false;
Send_WhoIs(-1, -1);
}
// output
// some round robin task switching
/* output */
/* some round robin task switching */
count++;
switch (count) {
case 1:
// used for testing, but kind of noisy on the network
//Read_Properties();
/* used for testing, but kind of noisy on the network */
/*Read_Properties(); */
break;
case 2:
break;
@@ -291,7 +291,7 @@ int main(int argc, char *argv[])
break;
}
// blink LEDs, Turn on or off outputs, etc
/* blink LEDs, Turn on or off outputs, etc */
}
return 0;
+25 -25
View File
@@ -33,9 +33,9 @@
-------------------------------------------
####COPYRIGHTEND####*/
// The module handles sending data out the RS-485 port
// and handles receiving data from the RS-485 port.
// Customize this file for your specific hardware
/* The module handles sending data out the RS-485 port */
/* and handles receiving data from the RS-485 port. */
/* Customize this file for your specific hardware */
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
@@ -43,18 +43,18 @@
#include "mstp.h"
// Transmits a Frame on the wire
void RS485_Send_Frame(struct mstp_port_struct_t *mstp_port, // port specific data
uint8_t * buffer, // frame to send (up to 501 bytes of data)
uint16_t nbytes) // number of bytes of data (up to 501)
{
/* Transmits a Frame on the wire */
void RS485_Send_Frame(struct mstp_port_struct_t *mstp_port, /* port specific data */
uint8_t * buffer, /* frame to send (up to 501 bytes of data) */
uint16_t nbytes)
{ /* number of bytes of data (up to 501) */
// in order to avoid line contention
/* in order to avoid line contention */
while (mstp_port->Turn_Around_Waiting) {
// wait, yield, or whatever
/* wait, yield, or whatever */
}
// Disable the receiver, and enable the transmit line driver.
/* Disable the receiver, and enable the transmit line driver. */
while (nbytes) {
putc(*buffer, stderr);
@@ -62,32 +62,32 @@ void RS485_Send_Frame(struct mstp_port_struct_t *mstp_port, // port specific
nbytes--;
}
// Wait until the final stop bit of the most significant CRC octet
// has been transmitted but not more than Tpostdrive.
/* Wait until the final stop bit of the most significant CRC octet */
/* has been transmitted but not more than Tpostdrive. */
// Disable the transmit line driver.
/* Disable the transmit line driver. */
return;
}
// called by timer, interrupt(?) or other thread
/* called by timer, interrupt(?) or other thread */
void RS485_Check_UART_Data(struct mstp_port_struct_t *mstp_port)
{
if (mstp_port->ReceiveError == true) {
// wait for state machine to clear this
/* wait for state machine to clear this */
}
// wait for state machine to read from the DataRegister
/* wait for state machine to read from the DataRegister */
else if (mstp_port->DataAvailable == false) {
// check for data
/* check for data */
// if error,
// ReceiveError = TRUE;
// return;
/* if error, */
/* ReceiveError = TRUE; */
/* return; */
mstp_port->DataRegister = 0; // FIXME: Get this data from UART or buffer
mstp_port->DataRegister = 0; /* FIXME: Get this data from UART or buffer */
// if data is ready,
// DataAvailable = TRUE;
// return;
/* if data is ready, */
/* DataAvailable = TRUE; */
/* return; */
}
}
+11 -11
View File
@@ -115,13 +115,13 @@
#define SHIFTREG_CLK PORTCbits.RC1
#define SHIFTREG_DATA PORTCbits.RC0
#define NO_ANALOGS 0x06 // None
#define ALL_ANALOG 0x00 // RA0 RA1 RA2 RA3 RA5 RE0 RE1 RE2 Ref=Vdd
#define ANALOG_RA3_REF 0x01 // RA0 RA1 RA2 RA5 RE0 RE1 RE2 Ref=RA3
#define A_ANALOG 0x02 // RA0 RA1 RA2 RA3 RA5 Ref=Vdd
#define A_ANALOG_RA3_REF 0x03 // RA0 RA1 RA2 RA5 Ref=RA3
#define RA0_RA1_RA3_ANALOG 0x04 // RA0 RA1 RA3 Ref=Vdd
#define RA0_RA1_ANALOG_RA3_REF 0x05 // RA0 RA1 Ref=RA3
#define NO_ANALOGS 0x06 /* None */
#define ALL_ANALOG 0x00 /* RA0 RA1 RA2 RA3 RA5 RE0 RE1 RE2 Ref=Vdd */
#define ANALOG_RA3_REF 0x01 /* RA0 RA1 RA2 RA5 RE0 RE1 RE2 Ref=RA3 */
#define A_ANALOG 0x02 /* RA0 RA1 RA2 RA3 RA5 Ref=Vdd */
#define A_ANALOG_RA3_REF 0x03 /* RA0 RA1 RA2 RA5 Ref=RA3 */
#define RA0_RA1_RA3_ANALOG 0x04 /* RA0 RA1 RA3 Ref=Vdd */
#define RA0_RA1_ANALOG_RA3_REF 0x05 /* RA0 RA1 Ref=RA3 */
#define ANALOG_RA3_RA2_REF 0x08
#define ANALOG_NOT_RE1_RE2 0x09
@@ -132,7 +132,7 @@
#define RA0_ANALOG 0x0E
#define RA0_ANALOG_RA3_RA2_REF 0x0F
// Constants used for SETUP_ADC() are:
/* Constants used for SETUP_ADC() are: */
#define ADC_OFF 0
#define ADC_START 4
#define ADC_CLOCK_DIV_2 1
@@ -242,9 +242,9 @@
#define USART_TRANSMIT(x) TXREG = (x)
#define USART_RECEIVE() RCREG
#define USART_RX_FRAME_ERROR() rcstabits.FERR
// combine the sequence correctly
#define USART_RX_SETUP() PIE1bits.RCIE = 1; RCSTAbits.CREN = 1
/* combine the sequence correctly */
#define USART_RX_SETUP() PIE1bits.RCIE = 1; RCSTAbits.CREN = 1
#define USART_TX_SETUP() PIE1bits.TXIE = 1; TXSTAbits.TXEN = 1
#endif /* HARDWARE_H */
#endif /* HARDWARE_H */
+48 -49
View File
@@ -29,10 +29,10 @@
#include <stdint.h>
#include "hardware.h"
// define this to enable ICD
//#define USE_ICD
/* define this to enable ICD */
/*#define USE_ICD */
// Configuration Bits
/* Configuration Bits */
#pragma config OSC = HS
#pragma config PWRT = ON
#pragma config BOR = ON, BORV = 42
@@ -59,12 +59,12 @@
#pragma config EBTRB = OFF
#ifdef USE_ICD
#pragma config WDT = OFF, WDTPS = 128
#pragma config DEBUG = ON
#pragma config WDT = OFF, WDTPS = 128
#pragma config DEBUG = ON
#else
#pragma config WDT = ON, WDTPS = 128
#pragma config DEBUG = OFF
#endif /* USE_ICD */
#pragma config WDT = ON, WDTPS = 128
#pragma config DEBUG = OFF
#endif /* USE_ICD */
#pragma romdata
@@ -76,56 +76,55 @@
*****************************************************************************/
void init_hardware(void)
{
// If the processor gets a power on reset then we can do something.
// We should not get a reset unless there has been
// some kind of power line disturbance.
if (RCONbits.POR)
{
//do something special!
}
/* If the processor gets a power on reset then we can do something. */
/* We should not get a reset unless there has been */
/* some kind of power line disturbance. */
if (RCONbits.POR) {
/*do something special! */
}
GLOBAL_INT_DISABLE();
GLOBAL_INT_DISABLE();
/* Setup PORT A */
TRISA=PORT_A_TRIS_MASK;
/* Setup PORT A */
TRISA = PORT_A_TRIS_MASK;
/* PORT A can have analog inputs or digital IO */
ADCON1 = NO_ANALOGS;
/* PORT A can have analog inputs or digital IO */
ADCON1 = NO_ANALOGS;
/* Setup PORT B */
TRISB=PORT_B_TRIS_MASK;
/* Setup PORT B */
TRISB = PORT_B_TRIS_MASK;
/* Setup PORT C */
TRISC=PORT_C_TRIS_MASK;
/* Setup PORT C */
TRISC = PORT_C_TRIS_MASK;
/* setup zero cross interrupt to trigger on a low to high edge */
INTCON2bits.INTEDG0 = 1;
/* setup zero cross interrupt to trigger on a low to high edge */
INTCON2bits.INTEDG0 = 1;
// setup ABUS
//ABUS_LED_OFF();
//SSPADD = ABUS_DEFAULT_ADDR;
//SSPCON1 = (ABUS_SLAVE_MASK | ABUS_CLK_ENABLE | ABUS_MODE_SETUP);
//ABUS_Clear_SSPBUF();
/* setup ABUS */
/*ABUS_LED_OFF(); */
/*SSPADD = ABUS_DEFAULT_ADDR; */
/*SSPCON1 = (ABUS_SLAVE_MASK | ABUS_CLK_ENABLE | ABUS_MODE_SETUP); */
/*ABUS_Clear_SSPBUF(); */
// setup timer2 to reset every 1ms
CloseTimer2();
PR2 = 250;
OpenTimer2(T2_PS_1_4 & T2_POST_1_5 & 0x7F);
/* setup timer2 to reset every 1ms */
CloseTimer2();
PR2 = 250;
OpenTimer2(T2_PS_1_4 & T2_POST_1_5 & 0x7F);
// Setup our interrupt priorities ---------> all low priority
RCONbits.IPEN = 1;
IPR1 = 0;
IPR2 = 0;
INTCON2bits.TMR0IP = 0;
INTCON2bits.RBIP = 0;
INTCON3 = 0;
/* Setup our interrupt priorities ---------> all low priority */
RCONbits.IPEN = 1;
IPR1 = 0;
IPR2 = 0;
INTCON2bits.TMR0IP = 0;
INTCON2bits.RBIP = 0;
INTCON3 = 0;
/* Enable interrupts */
TIMER2_INT_ENABLE();
PERIPHERAL_INT_ENABLE();
GLOBAL_INT_ENABLE();
/* Enable interrupts */
TIMER2_INT_ENABLE();
PERIPHERAL_INT_ENABLE();
GLOBAL_INT_ENABLE();
// Turn on the Zero cross interrupt
INTCONbits.INT0F = 0;
INTCONbits.INT0E = 1;
/* Turn on the Zero cross interrupt */
INTCONbits.INT0F = 0;
INTCONbits.INT0E = 1;
}
+82 -98
View File
@@ -31,7 +31,7 @@
#include "hardware.h"
#include "timer.h"
// interrupt service routines
/* interrupt service routines */
extern void RS485_Receive_Interrupt(void);
extern void RS485_Transmit_Interrupt(void);
@@ -45,76 +45,65 @@ extern void RS485_Transmit_Interrupt(void);
#pragma interruptlow InterruptHandlerLow save=PROD, section(".tmpdata")
void InterruptHandlerLow(void)
{
// check for timer0 interrupt
if((INTCONbits.TMR0IF) && (INTCONbits.TMR0IE))
{
// clear interrupt flag
INTCONbits.TMR0IF = 0;
// call interrupt handler
}
//check for timer1 interrupt
if ((PIR1bits.TMR1IF) && (PIE1bits.TMR1IE))
{
PIR1bits.TMR1IF = 0;
// call interrupt handler
}
//check for timer2 interrupt
if ((PIR1bits.TMR2IF) && (PIE1bits.TMR2IE))
{
PIR1bits.TMR2IF = 0;
Timer_Millisecond_Interrupt();
}
//check for timer3 interrupt
if ((PIR2bits.TMR3IF) && (PIE2bits.TMR3IE))
{
PIR2bits.TMR3IF = 0;
// call interrupt handler
}
//check for compare 1 int
if ((PIR1bits.CCP1IF) && (PIE1bits.CCP1IE))
{
PIR1bits.CCP1IF = 0;
// call interrupt handler
}
//check for compare 2 int
if ((PIR2bits.CCP2IF) && (PIE2bits.CCP2IE))
{
PIR2bits.CCP2IF = 0;
// call interrupt handler
}
//check for USART Rx int
if ((PIR2bits.EEIF) && (PIE2bits.EEIE))
{
PIR2bits.EEIF = 0; //clear interrupt flag
EECON1bits.WREN = 0; // disable writes
// call interrupt handler
}
//check for USART Tx int
if ((PIR1bits.TXIF) && (PIE1bits.TXIE))
{
// call interrupt handler
RS485_Transmit_Interrupt();
}
//check for USART Rx int
if ((PIR1bits.RCIF) && (PIE1bits.RCIE))
{
// call interrupt handler
RS485_Receive_Interrupt();
}
//check for AD int
if ((PIR1bits.ADIF) && (PIE1bits.ADIE))
{
// call interrupt handler
PIR1bits.ADIF = 0;
}
//check for I2C receive int (MSSP int)
if ((PIR1bits.SSPIF) && (PIE1bits.SSPIE))
{
PIR1bits.SSPIF = 0;
// call interrupt handler
}
/* check for timer0 interrupt */
if ((INTCONbits.TMR0IF) && (INTCONbits.TMR0IE)) {
/* clear interrupt flag */
INTCONbits.TMR0IF = 0;
/* call interrupt handler */
}
/*check for timer1 interrupt */
if ((PIR1bits.TMR1IF) && (PIE1bits.TMR1IE)) {
PIR1bits.TMR1IF = 0;
/* call interrupt handler */
}
/*check for timer2 interrupt */
if ((PIR1bits.TMR2IF) && (PIE1bits.TMR2IE)) {
PIR1bits.TMR2IF = 0;
Timer_Millisecond_Interrupt();
}
/*check for timer3 interrupt */
if ((PIR2bits.TMR3IF) && (PIE2bits.TMR3IE)) {
PIR2bits.TMR3IF = 0;
/* call interrupt handler */
}
/*check for compare 1 int */
if ((PIR1bits.CCP1IF) && (PIE1bits.CCP1IE)) {
PIR1bits.CCP1IF = 0;
/* call interrupt handler */
}
/*check for compare 2 int */
if ((PIR2bits.CCP2IF) && (PIE2bits.CCP2IE)) {
PIR2bits.CCP2IF = 0;
/* call interrupt handler */
}
/*check for USART Rx int */
if ((PIR2bits.EEIF) && (PIE2bits.EEIE)) {
PIR2bits.EEIF = 0; /*clear interrupt flag */
EECON1bits.WREN = 0; /* disable writes */
/* call interrupt handler */
}
/*check for USART Tx int */
if ((PIR1bits.TXIF) && (PIE1bits.TXIE)) {
/* call interrupt handler */
RS485_Transmit_Interrupt();
}
/*check for USART Rx int */
if ((PIR1bits.RCIF) && (PIE1bits.RCIE)) {
/* call interrupt handler */
RS485_Receive_Interrupt();
}
/*check for AD int */
if ((PIR1bits.ADIF) && (PIE1bits.ADIE)) {
/* call interrupt handler */
PIR1bits.ADIF = 0;
}
/*check for I2C receive int (MSSP int) */
if ((PIR1bits.SSPIF) && (PIE1bits.SSPIE)) {
PIR1bits.SSPIF = 0;
/* call interrupt handler */
}
return;
return;
}
/****************************************************************************
@@ -128,26 +117,24 @@ void InterruptHandlerLow(void)
#pragma interrupt InterruptHandlerHigh
void InterruptHandlerHigh(void)
{
//check for external int
if ((INTCONbits.INT0IF) && (INTCONbits.INT0IE))
{
/* Test to ensure that we are not getting a false trigger on the
falling edge. Only trigger on Rising edge. */
if (ZERO_CROSS)
{
// timer used to determine when power is gone (no zero crosses)
// Power_Timeout = 30;
// if (ABUS_Current_Status.Zerox_Fail)
// {
// ABUS_Flags.SendStatus = TRUE;
// ABUS_Current_Status.Zerox_Fail = FALSE;
// }
// if we get here it means power is good
// System_Flags.PowerFail = FALSE;
/*check for external int */
if ((INTCONbits.INT0IF) && (INTCONbits.INT0IE)) {
/* Test to ensure that we are not getting a false trigger on the
falling edge. Only trigger on Rising edge. */
if (ZERO_CROSS) {
/* timer used to determine when power is gone (no zero crosses) */
/* Power_Timeout = 30; */
/* if (ABUS_Current_Status.Zerox_Fail) */
/* { */
/* ABUS_Flags.SendStatus = TRUE; */
/* ABUS_Current_Status.Zerox_Fail = FALSE; */
/* } */
/* if we get here it means power is good */
/* System_Flags.PowerFail = FALSE; */
}
INTCONbits.INT0IF = 0;
}
INTCONbits.INT0IF = 0;
}
return;
return;
}
/****************************************************************************
@@ -160,10 +147,9 @@ void InterruptHandlerHigh(void)
#pragma code InterruptVectorHigh = 0x08
void InterruptVectorHigh(void)
{
_asm
goto InterruptHandlerHigh //jump to interrupt routine
_endasm
}
_asm goto InterruptHandlerHigh /*jump to interrupt routine */
_endasm}
#pragma code
/****************************************************************************
@@ -176,9 +162,7 @@ void InterruptVectorHigh(void)
#pragma code InterruptVectorLow = 0x18
void InterruptVectorLow(void)
{
_asm
goto InterruptHandlerLow //jump to interrupt routine
_endasm
}
#pragma code
_asm goto InterruptHandlerLow /*jump to interrupt routine */
_endasm}
#pragma code
+26 -28
View File
@@ -34,8 +34,8 @@
#include "timer.h"
#include "hardware.h"
volatile struct mstp_port_struct_t MSTP_Port; // port data
static uint8_t MSTP_MAC_Address = 0x05; // local MAC address
volatile struct mstp_port_struct_t MSTP_Port; /* port data */
static uint8_t MSTP_MAC_Address = 0x05; /* local MAC address */
/****************************************************************************
* DESCRIPTION: Handles our calling our module level milisecond counters
@@ -46,40 +46,38 @@ static uint8_t MSTP_MAC_Address = 0x05; // local MAC address
*****************************************************************************/
static void Check_Timer_Milliseconds(void)
{
// We might have missed some so keep doing it until we have got them all
while (Milliseconds)
{
MSTP_Millisecond_Timer(&MSTP_Port);
Milliseconds--;
}
/* We might have missed some so keep doing it until we have got them all */
while (Milliseconds) {
MSTP_Millisecond_Timer(&MSTP_Port);
Milliseconds--;
}
}
void main(void)
{
init_hardware();
RS485_Initialize();
MSTP_Init(&MSTP_Port,MSTP_MAC_Address);
init_hardware();
RS485_Initialize();
MSTP_Init(&MSTP_Port, MSTP_MAC_Address);
// loop forever
for (;;)
{
WATCHDOG_TIMER();
/* loop forever */
for (;;) {
WATCHDOG_TIMER();
// input
Check_Timer_Milliseconds();
// note: also called by RS-485 Receive ISR
RS485_Check_UART_Data(&MSTP_Port);
MSTP_Receive_Frame_FSM(&MSTP_Port);
/* input */
Check_Timer_Milliseconds();
/* note: also called by RS-485 Receive ISR */
RS485_Check_UART_Data(&MSTP_Port);
MSTP_Receive_Frame_FSM(&MSTP_Port);
// process
/* process */
// output
RS485_Process_Tx_Message();
MSTP_Master_Node_FSM(&MSTP_Port);
}
return;
/* output */
RS485_Process_Tx_Message();
MSTP_Master_Node_FSM(&MSTP_Port);
}
return;
}
+222 -243
View File
@@ -23,63 +23,60 @@
*
*********************************************************************/
// The module handles sending data out the RS-485 port
// and handles receiving data from the RS-485 port.
// Customize this file for your specific hardware
/* The module handles sending data out the RS-485 port */
/* and handles receiving data from the RS-485 port. */
/* Customize this file for your specific hardware */
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include "hardware.h"
#include "mstp.h"
// public port info
/* public port info */
extern volatile struct mstp_port_struct_t MSTP_Port;
static uint32_t RS485_Baud_Rate = 9600;
// UART transmission buffer and index
/* UART transmission buffer and index */
static volatile uint8_t RS485_Tx_Buffer[MAX_MPDU];
static volatile uint8_t RS485_Tx_Index = 0;
static volatile uint8_t RS485_Tx_Length = 0;
static volatile char RS485_Tx_Postdrive_Delay = 0;
static struct
{
unsigned TransmitStart:1; // TRUE if we are requested to transmit
unsigned TransmitComplete:1; // TRUE if we are finished transmitting frame
static struct {
unsigned TransmitStart:1; /* TRUE if we are requested to transmit */
unsigned TransmitComplete:1; /* TRUE if we are finished transmitting frame */
} RS485_Flags;
// Duplicate of the RCSTA reg used due to the double buffering of the
// fifo. Reading the RCREG reg will cause the second RCSTA reg to be
// loaded if there is one. */
struct _rcstabits
{
unsigned char RX9D:1;
unsigned char OERR:1;
unsigned char FERR:1;
unsigned char ADDEN:1;
unsigned char CREN:1;
unsigned char SREN:1;
unsigned char RX9:1;
unsigned char SPEN:1;
/* Duplicate of the RCSTA reg used due to the double buffering of the */
/* fifo. Reading the RCREG reg will cause the second RCSTA reg to be */
/* loaded if there is one. */ */
struct _rcstabits {
unsigned char RX9D:1;
unsigned char OERR:1;
unsigned char FERR:1;
unsigned char ADDEN:1;
unsigned char CREN:1;
unsigned char SREN:1;
unsigned char RX9:1;
unsigned char SPEN:1;
};
volatile static enum
{
RS485_STATE_IDLE = 0,
RS485_STATE_RX_DATA = 1,
RS485_STATE_RX_CHECKSUM = 2,
RS485_STATE_RX_PROCESS = 3,
RS485_STATE_TX_DATA = 4,
RS485_STATE_WAIT_FOR_ACK = 5,
RS485_STATE_WAIT_COMPLETE = 6,
RS485_STATE_TX_GLOBAL_ACK = 7,
RS485_STATE_TX_POSTDRIVE_DELAY = 8,
RS485_STATE_ERROR = 9,
RS485_STATE_RX_TEST = 10,
RS485_STATE_RX_TEST_EEPROM = 11,
RS485_STATE_RX_TEST_DELAY = 12,
RS485_STATE_TX_TEST_WAIT = 13,
RS485_STATE_TX_TEST = 14
volatile static enum {
RS485_STATE_IDLE = 0,
RS485_STATE_RX_DATA = 1,
RS485_STATE_RX_CHECKSUM = 2,
RS485_STATE_RX_PROCESS = 3,
RS485_STATE_TX_DATA = 4,
RS485_STATE_WAIT_FOR_ACK = 5,
RS485_STATE_WAIT_COMPLETE = 6,
RS485_STATE_TX_GLOBAL_ACK = 7,
RS485_STATE_TX_POSTDRIVE_DELAY = 8,
RS485_STATE_ERROR = 9,
RS485_STATE_RX_TEST = 10,
RS485_STATE_RX_TEST_EEPROM = 11,
RS485_STATE_RX_TEST_DELAY = 12,
RS485_STATE_TX_TEST_WAIT = 13,
RS485_STATE_TX_TEST = 14
} RS485_State;
/****************************************************************************
@@ -88,45 +85,42 @@ volatile static enum
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
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)
uint16_t nbytes) // number of bytes of data (up to 501)
{
// do we check for tx buffer in-use?
// Or do we just stop the in-progress transmission?
// Drop any transmission in progress, but don't worry about
// cleaning up the hardware - the start routine will handle that
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) */
uint16_t nbytes)
{ /* number of bytes of data (up to 501) */
/* do we check for tx buffer in-use? */
/* Or do we just stop the in-progress transmission? */
/* Drop any transmission in progress, but don't worry about */
/* cleaning up the hardware - the start routine will handle that */
// Disable the interrupt since it depends on the global transmit buffer.
USART_TX_INT_DISABLE();
switch (RS485_State)
{
/* Disable the interrupt since it depends on the global transmit buffer. */
USART_TX_INT_DISABLE();
switch (RS485_State) {
case RS485_STATE_TX_DATA:
case RS485_STATE_WAIT_FOR_ACK:
case RS485_STATE_WAIT_COMPLETE:
case RS485_STATE_TX_GLOBAL_ACK:
RS485_State = RS485_STATE_IDLE;
break;
}
// load the frame
RS485_Tx_Length = 0;
while (buffer && nbytes)
{
RS485_Tx_Buffer[RS485_Tx_Length] = *buffer;
buffer++;
nbytes--;
RS485_Tx_Length++;
// check bounds - should this error be indicated somehow?
// perhaps not send the message?
if (RS485_Tx_Length >= MAX_MPDU)
break;
}
// signal the task to start sending when it is ready
RS485_Flags.TransmitStart = TRUE;
RS485_State = RS485_STATE_IDLE;
break;
}
return;
/* load the frame */
RS485_Tx_Length = 0;
while (buffer && nbytes) {
RS485_Tx_Buffer[RS485_Tx_Length] = *buffer;
buffer++;
nbytes--;
RS485_Tx_Length++;
/* check bounds - should this error be indicated somehow? */
/* perhaps not send the message? */
if (RS485_Tx_Length >= MAX_MPDU)
break;
}
/* signal the task to start sending when it is ready */
RS485_Flags.TransmitStart = TRUE;
return;
}
/****************************************************************************
@@ -137,55 +131,49 @@ void RS485_Send_Frame(
*****************************************************************************/
void RS485_Transmit_Interrupt(void)
{
uint8_t data; // data byte to send
switch (RS485_State)
{
uint8_t data; /* data byte to send */
switch (RS485_State) {
case RS485_STATE_TX_DATA:
RS485_Tx_Index++;
if (RS485_Tx_Index < RS485_Tx_Length)
{
data = RS485_Tx_Buffer[RS485_Tx_Index];
USART_TRANSMIT(data);
MSTP_Port.SilenceTimer = 0;
}
else
{
// wait until the last bit is sent
while (!USART_TX_EMPTY());
RS485_TRANSMIT_DISABLE();
// wait 2 characters after sending (min=15 bit times)
RS485_Tx_Postdrive_Delay = 2;
RS485_State = RS485_STATE_TX_POSTDRIVE_DELAY;
USART_TRANSMIT(0);
}
break;
RS485_Tx_Index++;
if (RS485_Tx_Index < RS485_Tx_Length) {
data = RS485_Tx_Buffer[RS485_Tx_Index];
USART_TRANSMIT(data);
MSTP_Port.SilenceTimer = 0;
} else {
/* wait until the last bit is sent */
while (!USART_TX_EMPTY());
RS485_TRANSMIT_DISABLE();
/* wait 2 characters after sending (min=15 bit times) */
RS485_Tx_Postdrive_Delay = 2;
RS485_State = RS485_STATE_TX_POSTDRIVE_DELAY;
USART_TRANSMIT(0);
}
break;
case RS485_STATE_TX_POSTDRIVE_DELAY:
// after the message is sent, we wait a certain
// number of character times to get a delay
if (RS485_Tx_Postdrive_Delay)
{
RS485_Tx_Postdrive_Delay--;
if (RS485_Tx_Postdrive_Delay == 0)
RS485_State = RS485_STATE_WAIT_COMPLETE;
USART_TRANSMIT(0);
}
else
RS485_State = RS485_STATE_WAIT_COMPLETE;
break;
/* after the message is sent, we wait a certain */
/* number of character times to get a delay */
if (RS485_Tx_Postdrive_Delay) {
RS485_Tx_Postdrive_Delay--;
if (RS485_Tx_Postdrive_Delay == 0)
RS485_State = RS485_STATE_WAIT_COMPLETE;
USART_TRANSMIT(0);
} else
RS485_State = RS485_STATE_WAIT_COMPLETE;
break;
case RS485_STATE_WAIT_COMPLETE:
// wait until the last delay bit is shifted
while (!USART_TX_EMPTY());
USART_TX_INT_DISABLE();
RS485_Flags.TransmitComplete = TRUE;
RS485_State = RS485_STATE_IDLE;
USART_RX_SETUP();
break;
/* wait until the last delay bit is shifted */
while (!USART_TX_EMPTY());
USART_TX_INT_DISABLE();
RS485_Flags.TransmitComplete = TRUE;
RS485_State = RS485_STATE_IDLE;
USART_RX_SETUP();
break;
default:
break;
}
return;
break;
}
return;
}
/****************************************************************************
@@ -196,28 +184,27 @@ void RS485_Transmit_Interrupt(void)
*****************************************************************************/
void RS485_Process_Tx_Message(void)
{
if (RS485_Flags.TransmitComplete)
RS485_Flags.TransmitComplete = FALSE;
// start a new transmisstion if we are ready
if (RS485_Flags.TransmitStart && (RS485_State == RS485_STATE_IDLE))
{
// Disable the receiver
USART_RX_INT_DISABLE();
USART_CONTINUOUS_RX_DISABLE();
// Enable the transmit line driver and interrupts
RS485_TRANSMIT_ENABLE();
RS485_State = RS485_STATE_TX_DATA;
// Configure the ISR handler for an outgoing message
RS485_Tx_Index = 0;
// update the flags for beginning a send
RS485_Flags.TransmitComplete = FALSE;
RS485_Flags.TransmitStart = FALSE;
// send the first byte
USART_TRANSMIT(RS485_Tx_Buffer[0]);
USART_TX_SETUP();
}
return;
if (RS485_Flags.TransmitComplete)
RS485_Flags.TransmitComplete = FALSE;
/* start a new transmisstion if we are ready */
if (RS485_Flags.TransmitStart && (RS485_State == RS485_STATE_IDLE)) {
/* Disable the receiver */
USART_RX_INT_DISABLE();
USART_CONTINUOUS_RX_DISABLE();
/* Enable the transmit line driver and interrupts */
RS485_TRANSMIT_ENABLE();
RS485_State = RS485_STATE_TX_DATA;
/* Configure the ISR handler for an outgoing message */
RS485_Tx_Index = 0;
/* update the flags for beginning a send */
RS485_Flags.TransmitComplete = FALSE;
RS485_Flags.TransmitStart = FALSE;
/* send the first byte */
USART_TRANSMIT(RS485_Tx_Buffer[0]);
USART_TX_SETUP();
}
return;
}
/****************************************************************************
@@ -228,40 +215,36 @@ void RS485_Process_Tx_Message(void)
*****************************************************************************/
void RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port)
{
struct _rcstabits rcstabits; // reading it more than once gets wrong data
struct _rcstabits rcstabits; /* reading it more than once gets wrong data */
// check for data
if (USART_RX_COMPLETE())
{
// Read the data and the Rx status reg
rcstabits = USART_RX_STATUS();
mstp_port->DataRegister = USART_RECEIVE();
/* check for data */
if (USART_RX_COMPLETE()) {
/* Read the data and the Rx status reg */
rcstabits = USART_RX_STATUS();
mstp_port->DataRegister = USART_RECEIVE();
// Check for buffer overrun error
if (rcstabits.OERR)
{
// clear the error
USART_CONTINUOUS_RX_DISABLE();
USART_CONTINUOUS_RX_ENABLE();
// let the state machine know
mstp_port->ReceiveError = TRUE;
/* Check for buffer overrun error */
if (rcstabits.OERR) {
/* clear the error */
USART_CONTINUOUS_RX_DISABLE();
USART_CONTINUOUS_RX_ENABLE();
/* let the state machine know */
mstp_port->ReceiveError = TRUE;
}
/* Check for framing errors */
else if (USART_RX_FRAME_ERROR()) {
/* let the state machine know */
mstp_port->FramingError = TRUE;
mstp_port->ReceiveError = TRUE;
}
/* We read a good byte */
else {
/* state machine will clear this */
mstp_port->DataAvailable = TRUE;
}
}
// Check for framing errors
else if (USART_RX_FRAME_ERROR())
{
// let the state machine know
mstp_port->FramingError = TRUE;
mstp_port->ReceiveError = TRUE;
}
// We read a good byte
else
{
// state machine will clear this
mstp_port->DataAvailable = TRUE;
}
}
return;
return;
}
/****************************************************************************
@@ -272,17 +255,16 @@ void RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port)
*****************************************************************************/
void RS485_Receive_Interrupt(void)
{
// get as many bytes as we can get
for (;;)
{
RS485_Check_UART_Data(&MSTP_Port);
if (MSTP_Port.ReceiveError || MSTP_Port.DataAvailable)
MSTP_Receive_Frame_FSM(&MSTP_Port);
else
break;
}
/* get as many bytes as we can get */
for (;;) {
RS485_Check_UART_Data(&MSTP_Port);
if (MSTP_Port.ReceiveError || MSTP_Port.DataAvailable)
MSTP_Receive_Frame_FSM(&MSTP_Port);
else
break;
}
return;
return;
}
/****************************************************************************
@@ -293,7 +275,7 @@ void RS485_Receive_Interrupt(void)
*****************************************************************************/
uint32_t RS485_Get_Baud_Rate(void)
{
return RS485_Baud_Rate;
return RS485_Baud_Rate;
}
/****************************************************************************
@@ -304,70 +286,69 @@ uint32_t RS485_Get_Baud_Rate(void)
*****************************************************************************/
void RS485_Set_Baud_Rate(uint32_t baud)
{
if (baud < 19200)
RS485_Baud_Rate = 9600;
else if (baud < 38400)
RS485_Baud_Rate = 19200;
else if (baud < 57600)
RS485_Baud_Rate = 38400;
else if (baud < 57600)
RS485_Baud_Rate = 57600;
else if (baud < 115200)
RS485_Baud_Rate = 76800;
else
RS485_Baud_Rate = 115200;
if (baud < 19200)
RS485_Baud_Rate = 9600;
else if (baud < 38400)
RS485_Baud_Rate = 19200;
else if (baud < 57600)
RS485_Baud_Rate = 38400;
else if (baud < 57600)
RS485_Baud_Rate = 57600;
else if (baud < 115200)
RS485_Baud_Rate = 76800;
else
RS485_Baud_Rate = 115200;
}
void RS485_Initialize_Baud(void)
{
// setup USART Baud Rate Generator
// see BAUD RATES FOR ASYNCHRONOUS MODE in Data Book
/* Fosc=20MHz
BRGH=1 BRGH=0
Rate SPBRG Rate SPBRG
------- ----- ------- -----
9615 129 9469 32
/* setup USART Baud Rate Generator */
/* see BAUD RATES FOR ASYNCHRONOUS MODE in Data Book */
/* Fosc=20MHz
BRGH=1 BRGH=0
Rate SPBRG Rate SPBRG
------- ----- ------- -----
9615 129 9469 32
19230 64 19530 15
37878 32 78130 3
56818 21 104200 2
113630 10 312500 0
250000 4
625000 1
1250000 0
*/
switch (RS485_Baud_Rate)
{
113630 10 312500 0
250000 4
625000 1
1250000 0
*/
switch (RS485_Baud_Rate) {
case 19200:
SPBRG = 64;
TXSTAbits.BRGH=1;
break;
SPBRG = 64;
TXSTAbits.BRGH = 1;
break;
case 38400:
SPBRG = 32;
TXSTAbits.BRGH=1;
break;
SPBRG = 32;
TXSTAbits.BRGH = 1;
break;
case 57600:
SPBRG = 21;
TXSTAbits.BRGH=1;
break;
SPBRG = 21;
TXSTAbits.BRGH = 1;
break;
case 76800:
SPBRG = 3;
TXSTAbits.BRGH=0;
break;
SPBRG = 3;
TXSTAbits.BRGH = 0;
break;
case 115200:
SPBRG = 10;
TXSTAbits.BRGH=1;
break;
SPBRG = 10;
TXSTAbits.BRGH = 1;
break;
case 9600:
default:
SPBRG = 129;
TXSTAbits.BRGH=1;
break;
}
/* select async mode */
TXSTAbits.SYNC=0;
/* serial port enable */
RCSTAbits.SPEN=1;
SPBRG = 129;
TXSTAbits.BRGH = 1;
break;
}
/* select async mode */
TXSTAbits.SYNC = 0;
/* serial port enable */
RCSTAbits.SPEN = 1;
}
/****************************************************************************
@@ -379,17 +360,15 @@ void RS485_Initialize_Baud(void)
*****************************************************************************/
void RS485_Initialize(void)
{
RS485_Initialize_Baud();
/* configure interrupts */
USART_TX_INT_DISABLE();
USART_RX_INT_ENABLE();
// configure USART for receiving
// since the TX will handle setting up for transmit
USART_CONTINUOUS_RX_ENABLE();
/* since we are using RS485,
we need to explicitly say
transmit enable or not */
RS485_TRANSMIT_DISABLE();
RS485_Initialize_Baud();
/* configure interrupts */
USART_TX_INT_DISABLE();
USART_RX_INT_ENABLE();
/* configure USART for receiving */
/* since the TX will handle setting up for transmit */
USART_CONTINUOUS_RX_ENABLE();
/* since we are using RS485,
we need to explicitly say
transmit enable or not */
RS485_TRANSMIT_DISABLE();
}
+14 -14
View File
@@ -1,28 +1,28 @@
#ifndef STDBOOL_H
#define STDBOOL_H
// C99 Boolean types for compilers without C99 support
/* C99 Boolean types for compilers without C99 support */
#ifndef __cplusplus
typedef int _Bool;
#ifndef bool
#define bool _Bool
#endif
#ifndef true
#define true 1
#endif
#ifndef false
#define false 0
#endif
#define __bool_true_false_are_defined 1
typedef int _Bool;
#ifndef bool
#define bool _Bool
#endif
#ifndef true
#define true 1
#endif
#ifndef false
#define false 0
#endif
#define __bool_true_false_are_defined 1
#endif
#ifndef FALSE
#define FALSE 0
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#define TRUE 1
#endif
#endif
+11 -11
View File
@@ -1,18 +1,18 @@
// Defines the standard integer types that are used in code
/* Defines the standard integer types that are used in code */
#ifndef STDINT_H
#define STDINT_H 1
#include <stddef.h>
typedef unsigned char uint8_t; // 1 byte 0 to 255
typedef signed char int8_t; // 1 byte -127 to 127
typedef unsigned short uint16_t; // 2 bytes 0 to 65535
typedef signed short int16_t; // 2 bytes -32767 to 32767
//typedef unsigned short long uint24_t; // 3 bytes 0 to 16777215
typedef unsigned long uint32_t; // 4 bytes 0 to 4294967295
typedef signed long int32_t; // 4 bytes -2147483647 to 2147483647
// typedef signed long long int64_t;
// typedef unsigned long long uint64_t;
typedef unsigned char uint8_t; /* 1 byte 0 to 255 */
typedef signed char int8_t; /* 1 byte -127 to 127 */
typedef unsigned short uint16_t; /* 2 bytes 0 to 65535 */
typedef signed short int16_t; /* 2 bytes -32767 to 32767 */
/*typedef unsigned short long uint24_t; // 3 bytes 0 to 16777215 */
typedef unsigned long uint32_t; /* 4 bytes 0 to 4294967295 */
typedef signed long int32_t; /* 4 bytes -2147483647 to 2147483647 */
/* typedef signed long long int64_t; */
/* typedef unsigned long long uint64_t; */
#endif // STDINT_H
#endif /* STDINT_H */
+5 -5
View File
@@ -25,7 +25,7 @@
*********************************************************************/
#include <stdint.h>
volatile uint8_t Milliseconds; // used for timing stuff - counts up to 0xFF.
volatile uint8_t Milliseconds; /* used for timing stuff - counts up to 0xFF. */
/****************************************************************************
* DESCRIPTION: Timer is set to go off every 1ms. We increment the counter,
@@ -37,9 +37,9 @@ volatile uint8_t Milliseconds; // used for timing stuff - counts up to 0xFF.
*****************************************************************************/
void Timer_Millisecond_Interrupt(void)
{
// Global Milisecond timer
if (Milliseconds < 0xFF)
Milliseconds++;
/* Global Milisecond timer */
if (Milliseconds < 0xFF)
Milliseconds++;
return;
return;
}
+1 -1
View File
@@ -26,7 +26,7 @@
#ifndef TIMER_H
#define TIMER_H
// used for timing stuff - counts up to 0xFF.
/* used for timing stuff - counts up to 0xFF. */
extern volatile uint8_t Milliseconds;
void Timer_Millisecond_Interrupt(void);
+41 -41
View File
@@ -32,12 +32,12 @@
-------------------------------------------
####COPYRIGHTEND####*/
#include <stdint.h> // for standard integer types uint8_t etc.
#include <stdbool.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 "bip.h"
#if (defined(BACDL_ETHERNET) || defined(BACDL_BIP))
static int interface = SOCKET_ERROR; // SOCKET_ERROR means no open interface
static int interface = SOCKET_ERROR; /* SOCKET_ERROR means no open interface */
#endif
void bip_set_interface(char *ifname)
@@ -73,50 +73,50 @@ void InterfaceCleanup(void)
#endif
static void NetInitialize(void)
// initialize the TCP/IP stack
/* initialize the TCP/IP stack */
{
int Result;
#ifndef HOST
RTKernelInit(0); // get the kernel going
RTKernelInit(0); /* get the kernel going */
if (!RTKDebugVersion()) // switch of all diagnostics and error messages of RTIP-32
if (!RTKDebugVersion()) /* switch of all diagnostics and error messages of RTIP-32 */
xn_callbacks()->cb_wr_screen_string_fnc = NULL;
CLKSetTimerIntVal(10 * 1000); // 10 millisecond tick
CLKSetTimerIntVal(10 * 1000); /* 10 millisecond tick */
RTKDelay(1);
RTCMOSSetSystemTime(); // get the right time-of-day
RTCMOSSetSystemTime(); /* get the right time-of-day */
#ifdef RTUSB_VER
RTURegisterCallback(USBAX172); // ax172 and ax772 drivers
RTURegisterCallback(USBAX172); /* ax172 and ax772 drivers */
RTURegisterCallback(USBAX772);
RTURegisterCallback(USBKeyboard); // support USB keyboards
FindUSBControllers(); // install USB host controllers
Sleep(2000); // give the USB stack time to enumerate devices
RTURegisterCallback(USBKeyboard); /* support USB keyboards */
FindUSBControllers(); /* install USB host controllers */
Sleep(2000); /* give the USB stack time to enumerate devices */
#endif
#ifdef DHCP
XN_REGISTER_DHCP_CLI() // and optionally the DHCP client
XN_REGISTER_DHCP_CLI() /* and optionally the DHCP client */
#endif
Result = xn_rtip_init(); // Initialize the RTIP stack
Result = xn_rtip_init(); /* Initialize the RTIP stack */
if (Result != 0)
Error("xn_rtip_init failed");
atexit(InterfaceCleanup); // make sure the driver is shut down properly
RTCallDebugger(RT_DBG_CALLRESET, (DWORD) exit, 0); // even if we get restarted by the debugger
atexit(InterfaceCleanup); /* make sure the driver is shut down properly */
RTCallDebugger(RT_DBG_CALLRESET, (DWORD) exit, 0); /* even if we get restarted by the debugger */
Result = BIND_DRIVER(MINOR_0); // tell RTIP what Ethernet driver we want (see netcfg.h)
Result = BIND_DRIVER(MINOR_0); /* tell RTIP what Ethernet driver we want (see netcfg.h) */
if (Result != 0)
Error("driver initialization failed");
#if DEVICE_ID == PRISM_PCMCIA_DEVICE
// if this is a PCMCIA device, start the PCMCIA driver
/* if this is a PCMCIA device, start the PCMCIA driver */
if (RTPCInit(-1, 0, 2, NULL) == 0)
Error("No PCMCIA controller found");
#endif
// Open the interface
/* Open the interface */
interface =
xn_interface_open_config(DEVICE_ID, MINOR_0, ED_IO_ADD, ED_IRQ,
ED_MEM_ADD);
@@ -143,29 +143,29 @@ static void NetInitialize(void)
}
#if DEVICE_ID == PRISM_PCMCIA_DEVICE || DEVICE_ID == PRISM_DEVICE
xn_wlan_setup(interface, // iface_no: value returned by xn_interface_open_config()
"network name", // SSID : network name set in the access point
"station name", // Name : name of this node
0, // Channel : 0 for access points, 1..14 for ad-hoc
0, // KeyIndex: 0 .. 3
"12345", // WEP Key : key to use (5 or 13 bytes)
0); // Flags : see manual and Wlanapi.h for details
Sleep(1000); // wireless devices need a little time before they can be used
#endif // WLAN device
xn_wlan_setup(interface, /* iface_no: value returned by xn_interface_open_config() */
"network name", /* SSID : network name set in the access point */
"station name", /* Name : name of this node */
0, /* Channel : 0 for access points, 1..14 for ad-hoc */
0, /* KeyIndex: 0 .. 3 */
"12345", /* WEP Key : key to use (5 or 13 bytes) */
0); /* Flags : see manual and Wlanapi.h for details */
Sleep(1000); /* wireless devices need a little time before they can be used */
#endif /* WLAN device */
#if defined(AUTO_IP) // use xn_autoip() to get an IP address
#if defined(AUTO_IP) /* use xn_autoip() to get an IP address */
Result = xn_autoip(interface, MinIP, MaxIP, NetMask, TargetIP);
if (Result == SOCKET_ERROR)
Error("xn_autoip failed");
else {
printf("Auto-assigned IP address %i.%i.%i.%i\n", TargetIP[0],
TargetIP[1], TargetIP[2], TargetIP[3]);
// define default gateway and DNS server
/* define default gateway and DNS server */
xn_rt_add(RT_DEFAULT, ip_ffaddr, DefaultGateway, 1, interface,
RT_INF);
xn_set_server_list((DWORD *) DNSServer, 1);
}
#elif defined(DHCP) // use DHCP
#elif defined(DHCP) /* use DHCP */
{
DHCP_param param[] = { {SUBNET_MASK, 1}
, {DNS_OP, 1}
@@ -174,11 +174,11 @@ static void NetInitialize(void)
DHCP_session DS;
DHCP_conf DC;
xn_init_dhcp_conf(&DC); // load default DHCP options
DC.plist = param; // add MASK, DNS, and gateway options
xn_init_dhcp_conf(&DC); /* load default DHCP options */
DC.plist = param; /* add MASK, DNS, and gateway options */
DC.plist_entries = sizeof(param) / sizeof(param[0]);
printf("Contacting DHCP server, please wait...\n");
Result = xn_dhcp(interface, &DS, &DC); // contact DHCP server
Result = xn_dhcp(interface, &DS, &DC); /* contact DHCP server */
if (Result == SOCKET_ERROR)
Error("xn_dhcp failed");
memcpy(TargetIP, DS.client_ip, 4);
@@ -186,16 +186,16 @@ static void NetInitialize(void)
TargetIP[2], TargetIP[3]);
}
#else
// Set the IP address and interface
/* Set the IP address and interface */
printf("Using static IP address %i.%i.%i.%i\n", TargetIP[0],
TargetIP[1], TargetIP[2], TargetIP[3]);
Result = xn_set_ip(interface, TargetIP, NetMask);
// define default gateway and DNS server
/* define default gateway and DNS server */
xn_rt_add(RT_DEFAULT, ip_ffaddr, DefaultGateway, 1, interface, RT_INF);
xn_set_server_list((DWORD *) DNSServer, 1);
#endif
#else // HOST defined, run on Windows
#else /* HOST defined, run on Windows */
WSADATA wd;
Result = WSAStartup(0x0101, &wd);
@@ -209,7 +209,7 @@ static void NetInitialize(void)
bool bip_init(void)
{
int rv = 0; // return from socket lib calls
int rv = 0; /* return from socket lib calls */
struct sockaddr_in sin = { -1 };
int value = 1;
int sock_fd = -1;
@@ -218,7 +218,7 @@ bool bip_init(void)
bip_set_address(TargetIP[0], TargetIP[1], TargetIP[2], TargetIP[3]);
// FIXME:
/* FIXME: */
#if 0
bip_set_address(NetMask[0], NetMask[1], NetMask[2], NetMask[3]);
extern unsigned long bip_get_addr(void);
@@ -232,13 +232,13 @@ bool bip_init(void)
bip_set_port(0xBAC0);
#endif
// assumes that the driver has already been initialized
/* assumes that the driver has already been initialized */
sock_fd = socket(AF_INET, SOCK_DGRAM, IPROTO_UDP);
bip_set_socket(sock_fd);
if (sock_fd < 0)
return false;
// bind the socket to the local port number and IP address
/* bind the socket to the local port number and IP address */
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = htonl(INADDR_ANY);
sin.sin_port = htons(bip_get_port());
+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);
+19 -19
View File
@@ -36,15 +36,15 @@ extern void RTEmuInit(void);
#endif
/* DISK SYSTEM */
#ifdef DOC // include DiskOnChip driver
#ifdef DOC /* include DiskOnChip driver */
#include <rtfiles.h>
#define RTF_MAX_FILES 16 // support for more open files (default is 8)
#define RTF_BUFFERS_IN_BSS // we do not need file I/O before the run-time
#include <rtfdata.c> // system is initialized
#define RTF_MAX_FILES 16 /* support for more open files (default is 8) */
#define RTF_BUFFERS_IN_BSS /* we do not need file I/O before the run-time */
#include <rtfdata.c> /* system is initialized */
//#define READ_HEAD_BUFFER_SIZE 2048+4
/*#define READ_HEAD_BUFFER_SIZE 2048+4 */
//static BYTE ReadAheadBuffer[READ_HEAD_BUFFER_SIZE];
/*static BYTE ReadAheadBuffer[READ_HEAD_BUFFER_SIZE]; */
static RTFDrvFLPYData FLPYDriveAData = { 0 };
static RTFDrvDOCData DOCDriveData = { 0 };
@@ -108,17 +108,17 @@ RTFileSystem *RTFileSystemList[] = {
/*-----------------------------------*/
VOIDEXPORT Init(void)
{
(void) RTSetFlags(RT_MM_VIRTUAL, 1); // this is the better method
(void) RTCMOSExtendHeap(); // get as much memory as we can
RTCMOSSetSystemTime(); // get the right date and time
RTEmuInit(); // set up floating point emulation
// pizza - RTHaltCPL3 appears to cause problems with file handling
//RTIdleHandler = (void RTTAPI *)RTHaltCPL3; // low power when idle
// not needed with pre-emptive
//RTKTimeSlice(2); // allow same priority task switch
RTKConfig.Flags |= RF_PREEMPTIVE; // preemptive multitasking
RTKConfig.Flags |= RF_WIN32MUTEX_MUTEX; // Win32 mutexes are RTK32 mutexes
RTKConfig.Flags |= RF_FPCONTEXT; // saves floating point context for tasks
RTKConfig.HookedIRQs |= 1 << 1; // hook the keyboard IRQ
RTKConfig.DefaultTaskStackSize = 1024 * 8; // for Win32 task stacks req = 0
(void) RTSetFlags(RT_MM_VIRTUAL, 1); /* this is the better method */
(void) RTCMOSExtendHeap(); /* get as much memory as we can */
RTCMOSSetSystemTime(); /* get the right date and time */
RTEmuInit(); /* set up floating point emulation */
/* pizza - RTHaltCPL3 appears to cause problems with file handling */
/*RTIdleHandler = (void RTTAPI *)RTHaltCPL3; // low power when idle */
/* not needed with pre-emptive */
/*RTKTimeSlice(2); // allow same priority task switch */
RTKConfig.Flags |= RF_PREEMPTIVE; /* preemptive multitasking */
RTKConfig.Flags |= RF_WIN32MUTEX_MUTEX; /* Win32 mutexes are RTK32 mutexes */
RTKConfig.Flags |= RF_FPCONTEXT; /* saves floating point context for tasks */
RTKConfig.HookedIRQs |= 1 << 1; /* hook the keyboard IRQ */
RTKConfig.DefaultTaskStackSize = 1024 * 8; /* for Win32 task stacks req = 0 */
}
+19 -19
View File
@@ -23,8 +23,8 @@
*
*********************************************************************/
// This is one way to use the embedded BACnet stack under RTOS-32
// compiled with Borland C++ 5.02
/* This is one way to use the embedded BACnet stack under RTOS-32 */
/* compiled with Borland C++ 5.02 */
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
@@ -36,23 +36,23 @@
#include "handlers.h"
#include "net.h"
// buffers used for transmit and receive
/* buffers used for transmit and receive */
static uint8_t Rx_Buf[MAX_MPDU] = { 0 };
#ifdef BACDL_MSTP
volatile struct mstp_port_struct_t MSTP_Port; // port data
static uint8_t MSTP_MAC_Address = 0x05; // local MAC address
volatile struct mstp_port_struct_t MSTP_Port; /* port data */
static uint8_t MSTP_MAC_Address = 0x05; /* local MAC address */
#endif
static void Init_Service_Handlers(void)
{
// we need to handle who-is to support dynamic device binding
/* we need to handle who-is to support dynamic device binding */
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, WhoIsHandler);
// set the handler for all the services we don't implement
// It is required to send the proper reject message...
/* 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
(UnrecognizedServiceHandler);
// we must implement read property - it's required!
/* we must implement read property - it's required! */
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY,
ReadPropertyHandler);
apdu_set_confirmed_handler(SERVICE_CONFIRMED_WRITE_PROPERTY,
@@ -61,15 +61,15 @@ static void Init_Service_Handlers(void)
int main(int argc, char *argv[])
{
BACNET_ADDRESS src = { 0 }; // address where message came from
BACNET_ADDRESS src = { 0 }; /* address where message came from */
uint16_t pdu_len = 0;
unsigned timeout = 100; // milliseconds
unsigned timeout = 100; /* milliseconds */
(void) argc;
(void) argv;
Device_Set_Object_Instance_Number(126);
Init_Service_Handlers();
// init the physical layer
/* init the physical layer */
#ifdef BACDL_BIP
if (!bip_init())
return 1;
@@ -84,22 +84,22 @@ int main(int argc, char *argv[])
#endif
// loop forever
/* loop forever */
for (;;) {
// input
/* input */
#ifdef BACDL_MSTP
MSTP_Millisecond_Timer(&MSTP_Port);
// note: also called by RS-485 Receive ISR
/* note: also called by RS-485 Receive ISR */
RS485_Check_UART_Data(&MSTP_Port);
MSTP_Receive_Frame_FSM(&MSTP_Port);
#endif
#if (defined(BACDL_ETHERNET) || defined(BACDL_BIP))
// returns 0 bytes on timeout
/* returns 0 bytes on timeout */
pdu_len = bacdl_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout);
#endif
// process
/* process */
if (pdu_len) {
npdu_handler(&src, &Rx_Buf[0], pdu_len);
@@ -108,11 +108,11 @@ int main(int argc, char *argv[])
I_Am_Request = false;
Send_IAm();
}
// output
/* output */
#ifdef BACDL_MSTP
MSTP_Master_Node_FSM(&MSTP_Port);
#endif
// blink LEDs, Turn on or off outputs, etc
/* blink LEDs, Turn on or off outputs, etc */
}
}
+23 -23
View File
@@ -28,41 +28,41 @@
*/
// #define AUTO_IP // use xn_autoip() to get an IP address
// #define DHCP // if you enable this, you must also link library dhcpc.lib
/* #define AUTO_IP // use xn_autoip() to get an IP address */
/* #define DHCP // if you enable this, you must also link library dhcpc.lib */
#if defined(AUTO_IP) // use xn_autoip() to get an IP address
static BYTE TargetIP[] = { 0, 0, 0, 0 }; // will be filled at run-time
#if defined(AUTO_IP) /* use xn_autoip() to get an IP address */
static BYTE TargetIP[] = { 0, 0, 0, 0 }; /* will be filled at run-time */
static BYTE NetMask[] = { 255, 255, 255, 0 };
static BYTE MinIP[] = { 192, 168, 1, 128 };
static BYTE MaxIP[] = { 192, 168, 1, 255 };
static BYTE DefaultGateway[] = { 192, 168, 1, 1 }; // set to zero if not available or required
static BYTE DNSServer[] = { 192, 168, 1, 1 }; // ditto
#elif defined(DHCP) // use DHCP
static BYTE DefaultGateway[] = { 192, 168, 1, 1 }; /* set to zero if not available or required */
static BYTE DNSServer[] = { 192, 168, 1, 1 }; /* ditto */
#elif defined(DHCP) /* use DHCP */
#include <dhcpcapi.h>
static BYTE TargetIP[] = { 0, 0, 0, 0 }; // will be filled at run-time
#else // static IP address assignment (default)
static BYTE TargetIP[] = { 0, 0, 0, 0 }; /* will be filled at run-time */
#else /* static IP address assignment (default) */
static BYTE TargetIP[] = { 192, 168, 0, 50 };
static BYTE NetMask[] = { 255, 255, 255, 0 };
static BYTE DefaultGateway[] = { 192, 168, 0, 1 }; // set to zero if not available or required
static BYTE DNSServer[] = { 192, 168, 0, 1 }; // ditto
static BYTE DefaultGateway[] = { 192, 168, 0, 1 }; /* set to zero if not available or required */
static BYTE DNSServer[] = { 192, 168, 0, 1 }; /* ditto */
#endif
#define DEVICE_ID DAVICOM_DEVICE // define your device type here
#define DEVICE_ID DAVICOM_DEVICE /* define your device type here */
#ifndef DEVICE_ID
#error You must define Ethernet driver/resources and IP address/net mask here
#endif
// The following values are ignored for PCI devices (the BIOS supplies
// them), but they must be set correctly for ISA/PCMCIA systems and for
// PCI devices if you do not have a BIOS
/* The following values are ignored for PCI devices (the BIOS supplies */
/* them), but they must be set correctly for ISA/PCMCIA systems and for */
/* PCI devices if you do not have a BIOS */
#define ED_IO_ADD 0x300 // I/O address of the device
#define ED_IRQ 5 // IRQ of the device
#define ED_MEM_ADD 0 // Memory Window (only some devices)
#define ED_IO_ADD 0x300 /* I/O address of the device */
#define ED_IRQ 5 /* IRQ of the device */
#define ED_MEM_ADD 0 /* Memory Window (only some devices) */
// Define function to pull in the required driver
/* Define function to pull in the required driver */
#if DEVICE_ID == NE2000_DEVICE
#define BIND_DRIVER xn_bind_ne2000
@@ -87,17 +87,17 @@ static BYTE DNSServer[] = { 192, 168, 0, 1 }; // ditto
#elif DEVICE_ID == RHINE_DEVICE
#define BIND_DRIVER xn_bind_rhine
#elif DEVICE_ID == AX172_DEVICE
#include <rtusb.h> // must also link Rtusb.lib and UsbInit.cpp
#include <rtusb.h> /* must also link Rtusb.lib and UsbInit.cpp */
#define BIND_DRIVER xn_bind_ax172
#elif DEVICE_ID == AX772_DEVICE
#include <rtusb.h> // must also link Rtusb.lib and UsbInit.cpp
#include <rtusb.h> /* must also link Rtusb.lib and UsbInit.cpp */
#define BIND_DRIVER xn_bind_ax772
#elif DEVICE_ID == PRISM_DEVICE
#include <wlanapi.h> // must also link Wlan.lib
#include <wlanapi.h> /* must also link Wlan.lib */
#define BIND_DRIVER xn_bind_prism
#elif DEVICE_ID == PRISM_PCMCIA_DEVICE
#include <rtpcmcia.h>
#include <wlanapi.h> // must also link Wlan.lib
#include <wlanapi.h> /* must also link Wlan.lib */
#define BIND_DRIVER xn_bind_prism_pcmcia
#else
#error Invalid DEVICE_ID value
+14 -14
View File
@@ -29,7 +29,7 @@
#include <itimer.h>
#include "mstp.h"
// note: use the RTKernel-C API so that it can use this library
/* note: use the RTKernel-C API so that it can use this library */
#define RS485_IO_ENABLE(p) ModemControl(p,0,DTR);
#define RS485_TRANSMIT_ENABLE(p) ModemControl(p,1,RTS);
@@ -101,11 +101,11 @@ void RS485_Initialize(void)
RS485_Open_Port(RS485_Port, RS485_Baud, RS485_Base, RS485_IRQ_Number);
}
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)
uint16_t nbytes) // number of bytes of data (up to 501)
{
bool status = true; // return value
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) */
uint16_t nbytes)
{ /* number of bytes of data (up to 501) */
bool status = true; /* return value */
(void) mstp_port;
RS485_TRANSMIT_ENABLE(RS485_Port);
@@ -119,23 +119,23 @@ void RS485_Send_Frame(volatile struct mstp_port_struct_t *mstp_port, // port
return;
}
void RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port) // port specific data
{
void RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port)
{ /* port specific data */
COMData com_data = 0; /* byte from COM driver */
unsigned timeout = 10; // milliseconds to wait for a character
unsigned timeout = 10; /* milliseconds to wait for a character */
Duration ticks; /* duration to wait for data */
if (mstp_port->ReceiveError) {
// wait for state machine to clear this
/* wait for state machine to clear this */
}
// wait for state machine to read from the DataRegister
/* wait for state machine to read from the DataRegister */
else if (!mstp_port->DataAvailable) {
// check for data
/* check for data */
ticks = MilliSecsToTicks(timeout);
if (!ticks)
ticks = 1;
if (RTKGetTimed(ReceiveBuffer[RS485_Port], &com_data, ticks)) {
// if error,
/* if error, */
if (com_data & (COM_OVERRUN << 8))
mstp_port->ReceiveError = true;
else if (com_data & (COM_FRAME << 8))
@@ -150,5 +150,5 @@ void RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port)
void RS485_Process_Tx_Message(void)
{
// nothing to do
/* nothing to do */
}
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef STDBOOL_H
#define STDBOOL_H
// C99 Boolean types for compilers without C99 support
/* C99 Boolean types for compilers without C99 support */
#ifndef __cplusplus
typedef int _Bool;
+12 -12
View File
@@ -1,19 +1,19 @@
// Defines the standard integer types that are used in code
// for the x86 processor and Borland Compiler
/* Defines the standard integer types that are used in code */
/* for the x86 processor and Borland Compiler */
#ifndef STDINT_H
#define STDINT_H
#include <stddef.h>
typedef unsigned char uint8_t; // 1 byte 0 to 255
typedef signed char int8_t; // 1 byte -127 to 127
typedef unsigned short uint16_t; // 2 bytes 0 to 65535
typedef signed short int16_t; // 2 bytes -32767 to 32767
//typedef unsigned short long uint24_t; // 3 bytes 0 to 16777215
typedef unsigned long uint32_t; // 4 bytes 0 to 4294967295
typedef signed long int32_t; // 4 bytes -2147483647 to 2147483647
// typedef signed long long int64_t;
// typedef unsigned long long uint64_t;
typedef unsigned char uint8_t; /* 1 byte 0 to 255 */
typedef signed char int8_t; /* 1 byte -127 to 127 */
typedef unsigned short uint16_t; /* 2 bytes 0 to 65535 */
typedef signed short int16_t; /* 2 bytes -32767 to 32767 */
/*typedef unsigned short long uint24_t; // 3 bytes 0 to 16777215 */
typedef unsigned long uint32_t; /* 4 bytes 0 to 4294967295 */
typedef signed long int32_t; /* 4 bytes -2147483647 to 2147483647 */
/* typedef signed long long int64_t; */
/* typedef unsigned long long uint64_t; */
#endif // STDINT_H
#endif /* STDINT_H */
+8 -8
View File
@@ -37,8 +37,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h> // for standard integer types uint8_t etc.
#include <stdbool.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 "bacdcode.h"
#include "bip.h"
#include "net.h"
@@ -102,7 +102,7 @@ void bip_set_interface(char *ifname)
bool bip_init(void)
{
int rv = 0; // return from socket lib calls
int rv = 0; /* return from socket lib calls */
struct sockaddr_in sin = { -1 };
int value = 1;
int sock_fd = -1;
@@ -112,7 +112,7 @@ bool bip_init(void)
struct in_addr address;
Result = WSAStartup((1 << 8) | 1, &wd);
//Result = WSAStartup(MAKEWORD(2,2), &wd);
/*Result = WSAStartup(MAKEWORD(2,2), &wd); */
if (Result != 0) {
Code = WSAGetLastError();
printf("TCP/IP stack initialization failed, error code: %i\n",
@@ -140,8 +140,8 @@ bool bip_init(void)
fprintf(stderr, "bip: failed to allocate a socket.\n");
return false;
}
// Allow us to use the same socket for sending and receiving
// This makes sure that the src port is correct when sending
/* Allow us to use the same socket for sending and receiving */
/* This makes sure that the src port is correct when sending */
rv = setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR,
(char *) &value, sizeof(value));
if (rv < 0) {
@@ -150,7 +150,7 @@ bool bip_init(void)
bip_set_socket(-1);
return false;
}
// allow us to send a broadcast
/* allow us to send a broadcast */
rv = setsockopt(sock_fd, SOL_SOCKET, SO_BROADCAST,
(char *) &value, sizeof(value));
if (rv < 0) {
@@ -159,7 +159,7 @@ bool bip_init(void)
bip_set_socket(-1);
return false;
}
// bind the socket to the local port number and IP address
/* bind the socket to the local port number and IP address */
sin.sin_family = AF_INET;
#if USE_INADDR
/* by setting sin.sin_addr.s_addr to INADDR_ANY,
+21 -21
View File
@@ -23,8 +23,8 @@
*
*********************************************************************/
// This is one way to use the embedded BACnet stack under Win32
// compiled with Borland C++ 5.02 or Visual C++ 6.0
/* This is one way to use the embedded BACnet stack under Win32 */
/* compiled with Borland C++ 5.02 or Visual C++ 6.0 */
#include <winsock2.h>
#include <stddef.h>
#include <stdint.h>
@@ -42,7 +42,7 @@
#include "datalink.h"
#include "txbuf.h"
// buffer used for receive
/* buffer used for receive */
static uint8_t Rx_Buf[MAX_MPDU] = { 0 };
/* send a whois to see who is on the network */
@@ -102,7 +102,7 @@ static void Read_Properties(void)
if (object_props[property] < 0)
next_device = true;
else {
status = Send_Read_Property_Request(device_id, // destination device
status = Send_Read_Property_Request(device_id, /* destination device */
OBJECT_DEVICE,
device_id, object_props[property], BACNET_ARRAY_ALL);
if (status)
@@ -147,29 +147,29 @@ static void LocalIAmHandler(uint8_t * service_request,
static void Init_Service_Handlers(void)
{
// we need to handle who-is to support dynamic device binding
/* 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_I_AM,
LocalIAmHandler);
// set the handler for all the services we don't implement
// It is required to send the proper reject message...
/* 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);
// we must implement read property - it's required!
/* we must implement read property - it's required! */
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY,
handler_read_property);
apdu_set_confirmed_handler(SERVICE_CONFIRMED_WRITE_PROPERTY,
handler_write_property);
// handle the data coming back from confirmed requests
/* handle the data coming back from confirmed requests */
apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_READ_PROPERTY,
handler_read_property_ack);
}
static void print_address(char *name, BACNET_ADDRESS * dest) // destination address
{
int i = 0; // counter
static void print_address(char *name, BACNET_ADDRESS * dest)
{ /* destination address */
int i = 0; /* counter */
if (dest) {
printf("%s: ", name);
@@ -203,16 +203,16 @@ static void print_address_cache(void)
int main(int argc, char *argv[])
{
BACNET_ADDRESS src = { 0 }; // address where message came from
BACNET_ADDRESS src = { 0 }; /* address where message came from */
uint16_t pdu_len = 0;
unsigned timeout = 100; // milliseconds
unsigned timeout = 100; /* milliseconds */
BACNET_ADDRESS my_address, broadcast_address;
(void) argc;
(void) argv;
Device_Set_Object_Instance_Number(124);
Init_Service_Handlers();
// init the data link layer
/* init the data link layer */
/* configure standard BACnet/IP port */
bip_set_port(0xBAC0);
if (!bip_init())
@@ -224,14 +224,14 @@ int main(int argc, char *argv[])
print_address("Address", &my_address);
printf("BACnet stack running...\n");
// loop forever
/* loop forever */
for (;;) {
// input
/* input */
// returns 0 bytes on timeout
/* returns 0 bytes on timeout */
pdu_len = bip_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout);
// process
/* process */
if (pdu_len) {
npdu_handler(&src, &Rx_Buf[0], pdu_len);
@@ -246,9 +246,9 @@ int main(int argc, char *argv[])
Read_Properties();
}
// output
/* output */
// blink LEDs, Turn on or off outputs, etc
/* blink LEDs, Turn on or off outputs, etc */
/* wait for ESC from keyboard before quitting */
if (kbhit() && (getch() == 0x1B))
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef STDBOOL_H
#define STDBOOL_H
// C99 Boolean types for compilers without C99 support
/* C99 Boolean types for compilers without C99 support */
#ifndef __cplusplus
typedef int _Bool;
+12 -12
View File
@@ -1,19 +1,19 @@
// Defines the standard integer types that are used in code
// for the x86 processor and Borland Compiler
/* Defines the standard integer types that are used in code */
/* for the x86 processor and Borland Compiler */
#ifndef STDINT_H
#define STDINT_H
#include <stddef.h>
typedef unsigned char uint8_t; // 1 byte 0 to 255
typedef signed char int8_t; // 1 byte -127 to 127
typedef unsigned short uint16_t; // 2 bytes 0 to 65535
typedef signed short int16_t; // 2 bytes -32767 to 32767
//typedef unsigned short long uint24_t; // 3 bytes 0 to 16777215
typedef unsigned long uint32_t; // 4 bytes 0 to 4294967295
typedef signed long int32_t; // 4 bytes -2147483647 to 2147483647
// typedef signed long long int64_t;
// typedef unsigned long long uint64_t;
typedef unsigned char uint8_t; /* 1 byte 0 to 255 */
typedef signed char int8_t; /* 1 byte -127 to 127 */
typedef unsigned short uint16_t; /* 2 bytes 0 to 65535 */
typedef signed short int16_t; /* 2 bytes -32767 to 32767 */
/*typedef unsigned short long uint24_t; // 3 bytes 0 to 16777215 */
typedef unsigned long uint32_t; /* 4 bytes 0 to 4294967295 */
typedef signed long int32_t; /* 4 bytes -2147483647 to 2147483647 */
/* typedef signed long long int64_t; */
/* typedef unsigned long long uint64_t; */
#endif // STDINT_H
#endif /* STDINT_H */
+106 -119
View File
@@ -7,119 +7,109 @@
#include <assert.h>
/* Number of tests to hold incrementally */
enum {CHUNK = 10};
enum { CHUNK = 10 };
Test* ct_create(const char* name, void (*init)(Test*))
Test *ct_create(const char *name, void (*init) (Test *))
{
int backOutLevel = 0;
Test* pTest = malloc(sizeof(Test));
if (pTest)
{
pTest->nPass = pTest->nFail = pTest->nTests = 0;
pTest->pStream = stdout;
int backOutLevel = 0;
Test *pTest = malloc(sizeof(Test));
if (pTest) {
pTest->nPass = pTest->nFail = pTest->nTests = 0;
pTest->pStream = stdout;
/* Allocate array of fptrs: */
assert(CHUNK);
pTest->pTestFuns = calloc(CHUNK, sizeof(TestFunc));
if (pTest->pTestFuns)
{
pTest->maxTests = CHUNK;
/* Allocate test name: */
assert(name);
pTest->name = malloc(strlen(name) + 1);
if (pTest->name)
strcpy(pTest->name, name);
else
++backOutLevel;
}
else
++backOutLevel;
}
/* Allocate array of fptrs: */
assert(CHUNK);
pTest->pTestFuns = calloc(CHUNK, sizeof(TestFunc));
if (pTest->pTestFuns) {
pTest->maxTests = CHUNK;
/* Allocate test name: */
assert(name);
pTest->name = malloc(strlen(name) + 1);
if (pTest->name)
strcpy(pTest->name, name);
else
++backOutLevel;
} else
++backOutLevel;
}
/* Back-out allocations if memory failed: */
if (backOutLevel)
{
switch(backOutLevel)
{
case 2:
free(pTest->pTestFuns);
pTest->pTestFuns = NULL;
case 1:
free(pTest);
pTest = NULL;
}
/* Back-out allocations if memory failed: */
if (backOutLevel) {
switch (backOutLevel) {
case 2:
free(pTest->pTestFuns);
pTest->pTestFuns = NULL;
case 1:
free(pTest);
pTest = NULL;
}
else if (init)
{
assert(pTest);
init(pTest);
}
return pTest;
}
void ct_destroy(Test* pTest)
{
} else if (init) {
assert(pTest);
assert(pTest->pTestFuns);
free(pTest->pTestFuns);
pTest->pTestFuns = NULL;
assert(pTest->name);
free(pTest->name);
pTest->name = NULL;
free(pTest);
init(pTest);
}
return pTest;
}
bool ct_addTestFunction(Test* pTest, TestFunc tfun)
void ct_destroy(Test * pTest)
{
assert(pTest);
assert(pTest->pTestFuns);
if (pTest->nTests == pTest->maxTests)
{
size_t newSize = pTest->nTests + CHUNK;
TestFunc* new_pTestFuns =
realloc(pTest->pTestFuns,
newSize * sizeof(TestFunc));
if (!new_pTestFuns)
return false;
pTest->pTestFuns = new_pTestFuns;
pTest->maxTests += CHUNK;
}
assert(pTest->nTests < pTest->maxTests);
pTest->pTestFuns[pTest->nTests++] = tfun;
return true;
assert(pTest);
assert(pTest->pTestFuns);
free(pTest->pTestFuns);
pTest->pTestFuns = NULL;
assert(pTest->name);
free(pTest->name);
pTest->name = NULL;
free(pTest);
}
void ct_setStream(Test* pTest, FILE* pStream)
bool ct_addTestFunction(Test * pTest, TestFunc tfun)
{
pTest->pStream = pStream;
assert(pTest);
assert(pTest->pTestFuns);
if (pTest->nTests == pTest->maxTests) {
size_t newSize = pTest->nTests + CHUNK;
TestFunc *new_pTestFuns = realloc(pTest->pTestFuns,
newSize * sizeof(TestFunc));
if (!new_pTestFuns)
return false;
pTest->pTestFuns = new_pTestFuns;
pTest->maxTests += CHUNK;
}
assert(pTest->nTests < pTest->maxTests);
pTest->pTestFuns[pTest->nTests++] = tfun;
return true;
}
FILE* ct_getStream(Test* pTest)
void ct_setStream(Test * pTest, FILE * pStream)
{
return pTest->pStream;
pTest->pStream = pStream;
}
long ct_report(Test* pTest)
FILE *ct_getStream(Test * pTest)
{
assert(pTest);
if (pTest->pStream)
{
fprintf(pTest->pStream,
"Test \"%s\":\n\tPassed: %ld\n\tFailed: %ld\n",
pTest->name, pTest->nPass, pTest->nFail);
}
return pTest->nFail;
return pTest->pStream;
}
void ct_succeed(Test* pTest)
long ct_report(Test * pTest)
{
assert(pTest);
++pTest->nPass;
assert(pTest);
if (pTest->pStream) {
fprintf(pTest->pStream,
"Test \"%s\":\n\tPassed: %ld\n\tFailed: %ld\n",
pTest->name, pTest->nPass, pTest->nFail);
}
return pTest->nFail;
}
void ct_do_test(Test* pTest, const char* str,
bool cond, const char* file, long line)
void ct_succeed(Test * pTest)
{
assert(pTest);
++pTest->nPass;
}
void ct_do_test(Test * pTest, const char *str,
bool cond, const char *file, long line)
{
assert(pTest);
if (!cond)
@@ -128,55 +118,52 @@ void ct_do_test(Test* pTest, const char* str,
ct_succeed(pTest);
}
void ct_do_fail(Test* pTest, const char* str,
const char* file, long line)
void ct_do_fail(Test * pTest, const char *str, const char *file, long line)
{
assert(pTest);
assert(pTest);
++pTest->nFail;
if (pTest->pStream)
{
if (pTest->pStream) {
fprintf(pTest->pStream,
"%s failure: (%s), %s (line %ld)\n",
pTest->name, str, file, line);
"%s failure: (%s), %s (line %ld)\n",
pTest->name, str, file, line);
}
}
long ct_getNumPassed(Test* pTest)
long ct_getNumPassed(Test * pTest)
{
assert(pTest);
return pTest->nPass;
assert(pTest);
return pTest->nPass;
}
long ct_getNumFailed(Test* pTest)
long ct_getNumFailed(Test * pTest)
{
assert(pTest);
return pTest->nFail;
assert(pTest);
return pTest->nFail;
}
long ct_run(Test* pTest)
long ct_run(Test * pTest)
{
size_t testNum;
assert(pTest);
for (testNum = 0; testNum < pTest->nTests; ++testNum)
pTest->pTestFuns[testNum](pTest);
return pTest->nFail;
size_t testNum;
assert(pTest);
for (testNum = 0; testNum < pTest->nTests; ++testNum)
pTest->pTestFuns[testNum] (pTest);
return pTest->nFail;
}
void ct_reset(Test* pTest)
void ct_reset(Test * pTest)
{
assert(pTest);
pTest->nFail = pTest->nPass = 0;
assert(pTest);
pTest->nFail = pTest->nPass = 0;
}
const char* ct_getName(Test* pTest)
const char *ct_getName(Test * pTest)
{
assert(pTest);
return (pTest->name);
assert(pTest);
return (pTest->name);
}
long ct_getNumTests(Test* pTest)
long ct_getNumTests(Test * pTest)
{
assert(pTest);
return pTest->nTests;
assert(pTest);
return pTest->nTests;
}
+26 -28
View File
@@ -15,47 +15,45 @@
typedef struct _Test Test;
typedef void (*TestFunc)(Test*);
typedef void (*TestFunc) (Test *);
struct _Test
{
char* name;
FILE* pStream;
size_t nTests;
size_t maxTests;
TestFunc* pTestFuns;
long nPass;
long nFail;
struct _Test {
char *name;
FILE *pStream;
size_t nTests;
size_t maxTests;
TestFunc *pTestFuns;
long nPass;
long nFail;
};
#ifdef __cplusplus
extern "C" {
#endif
Test* ct_create(const char* name, void (*init)(Test*));
void ct_destroy(Test* pTest);
Test *ct_create(const char *name, void (*init) (Test *));
void ct_destroy(Test * pTest);
const char* ct_getName(Test* pTest);
long ct_getNumPassed(Test* pTest);
long ct_getNumFailed(Test* pTest);
long ct_getNumTests(Test* pTest);
FILE* ct_getStream(Test* pTest);
void ct_setStream(Test* pTest, FILE* stream);
const char *ct_getName(Test * pTest);
long ct_getNumPassed(Test * pTest);
long ct_getNumFailed(Test * pTest);
long ct_getNumTests(Test * pTest);
FILE *ct_getStream(Test * pTest);
void ct_setStream(Test * pTest, FILE * stream);
bool ct_addTestFunction(Test* pTest, TestFunc tfun);
void ct_succeed(Test* pTest);
long ct_run(Test* pTest);
long ct_report(Test* pTest);
void ct_reset(Test* pTest);
bool ct_addTestFunction(Test * pTest, TestFunc tfun);
void ct_succeed(Test * pTest);
long ct_run(Test * pTest);
long ct_report(Test * pTest);
void ct_reset(Test * pTest);
/* Not intended for end-users: */
void ct_do_test(Test* pTest, const char* str,
bool cond, const char* file, long line);
void ct_do_fail(Test* pTest, const char* str,
const char* file, long line);
void ct_do_test(Test * pTest, const char *str,
bool cond, const char *file, long line);
void ct_do_fail(Test * pTest, const char *str,
const char *file, long line);
#ifdef __cplusplus
}
#endif
#endif