cleaned up compiler warnings

This commit is contained in:
skarg
2005-05-04 20:56:27 +00:00
parent be646af144
commit 4a98496478
13 changed files with 109 additions and 147 deletions
+1
View File
@@ -67,6 +67,7 @@ int Analog_Input_Encode_Property_APDU(
char text_string[32] = {""}; char text_string[32] = {""};
float value = 3.14159; float value = 3.14159;
(void)array_index;
switch (property) switch (property)
{ {
case PROP_OBJECT_IDENTIFIER: case PROP_OBJECT_IDENTIFIER:
+1
View File
@@ -157,6 +157,7 @@ void apdu_handler(
uint16_t service_request_len = 0; uint16_t service_request_len = 0;
uint16_t len = 0; // counts where we are in PDU uint16_t len = 0; // counts where we are in PDU
(void)data_expecting_reply;
if (apdu) if (apdu)
{ {
// PDU Type // PDU Type
+2 -1
View File
@@ -903,7 +903,8 @@ int encode_tagged_character_string(uint8_t * apdu, const char *char_string)
int decode_character_string(uint8_t * apdu, uint32_t len_value, int decode_character_string(uint8_t * apdu, uint32_t len_value,
char *char_string, size_t string_len) char *char_string, size_t string_len)
{ {
int len = 0, i = 0; int len = 0; // return value
uint32_t i = 0; // counter
// FIXME: issue warning? // FIXME: issue warning?
if (len_value > string_len) if (len_value > string_len)
+1 -1
View File
@@ -278,7 +278,7 @@ int Device_Encode_Property_APDU(
int apdu_len = 0; // return value int apdu_len = 0; // return value
int len = 0; // apdu len intermediate value int len = 0; // apdu len intermediate value
BACNET_BIT_STRING bit_string; BACNET_BIT_STRING bit_string;
int i = 0; unsigned i = 0;
int object_type = 0; int object_type = 0;
uint32_t instance = 0; uint32_t instance = 0;
unsigned count = 0; unsigned count = 0;
+1
View File
@@ -70,6 +70,7 @@ uint16_t ethernet_receive(
uint16_t max_pdu, // amount of space available in the PDU uint16_t max_pdu, // amount of space available in the PDU
unsigned timeout); // milliseconds to wait for a packet unsigned timeout); // milliseconds to wait for a packet
void ethernet_set_my_address(BACNET_ADDRESS *my_address);
void ethernet_get_my_address(BACNET_ADDRESS *my_address); void ethernet_get_my_address(BACNET_ADDRESS *my_address);
void ethernet_get_broadcast_address( void ethernet_get_broadcast_address(
BACNET_ADDRESS *dest); // destination address BACNET_ADDRESS *dest); // destination address
+12
View File
@@ -361,6 +361,18 @@ uint16_t ethernet_receive(
return pdu_len; return pdu_len;
} }
void ethernet_set_my_address(BACNET_ADDRESS *my_address)
{
int i = 0;
for (i = 0; i < 6; i++)
{
Ethernet_MAC_Address[i] = my_address->mac[i];
}
return;
}
void ethernet_get_my_address(BACNET_ADDRESS *my_address) void ethernet_get_my_address(BACNET_ADDRESS *my_address)
{ {
int i = 0; int i = 0;
+24 -106
View File
@@ -43,116 +43,29 @@ 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 }; uint8_t Ethernet_MAC_Address[MAX_MAC_LEN] = { 0, 0, 0, 0, 0, 0 };
// static IP address assignment (default)
static BYTE TargetIP[] = {192, 168, 0, 50};
// net mask - set to be subnet restrictive
static BYTE NetMask[] = {255, 255, 255, 0};
// gateway - set to zero if not available or required
static BYTE DefaultGateway[] = {0, 0, 0, 0};
// DNS - set to zero if not available or required
static BYTE DNSServer[] = {0, 0, 0, 0};
// the Interface for Ethernet
// SOCKET_ERROR means no open interface
static int Ethernet_Interface = SOCKET_ERROR;
static SOCKET Ethernet_Socket = -1; static SOCKET Ethernet_Socket = -1;
// used for binding 802.2 // used for binding 802.2
static struct sockaddr Ethernet_Address = { 0 }; static struct sockaddr Ethernet_Address = { 0 };
bool ethernet_valid(void) bool ethernet_valid(void)
{ {
return (Ethernet_Interface != SOCKET_ERROR); return (Ethernet_Socket != -1);
} }
void ethernet_cleanup(void) void ethernet_cleanup(void)
{ {
if (ethernet_valid()) if (ethernet_valid())
xn_interface_close(Ethernet_Interface); closesocket(Ethernet_Socket);
Ethernet_Interface = SOCKET_ERROR; Ethernet_Socket = -1;
return; return;
} }
/* function to find the local ethernet MAC address */
static int get_local_hwaddr(int iface, unsigned char *mac)
{
struct _iface_info ii; // contains the hwaddr of the Ethernet interface
/* determine the local MAC address */
xn_interface_info(iface, &ii);
mac[0] = ii.my_ethernet_address[0];
mac[1] = ii.my_ethernet_address[1];
mac[2] = ii.my_ethernet_address[2];
mac[3] = ii.my_ethernet_address[3];
mac[4] = ii.my_ethernet_address[4];
mac[5] = ii.my_ethernet_address[5];
return 0;
}
static void ethernet_error(const char *text)
{
fprintf(stderr,"%s, error code: %s\n",
text, xn_geterror_string(WSAGetLastError()));
exit(1);
}
bool ethernet_init(char *interface_name) bool ethernet_init(char *interface_name)
{ {
struct _iface_info ii; // contains the hwaddr of the Ethernet interface
int value = 1; int value = 1;
int Result = 0;
// FIXME: what about other drivers other than DAVICOM?
(void)interface_name; (void)interface_name;
RTKernelInit(0); // get the kernel going
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
RTKDelay(1);
RTCMOSSetSystemTime(); // get the right time-of-day
Result = xn_rtip_init(); // Initialize the RTIP stack
if (Result == SOCKET_ERROR)
ethernet_error("ethernet: xn_rtip_init failed");
atexit(ethernet_cleanup); // make sure the driver is shut down properly
RTCallDebugger(RT_DBG_CALLRESET, (DWORD)exit, 0); // even if we get restarted by the debugger
// tell RTIP what Ethernet driver we want
Result = xn_bind_davicom(MINOR_0);
if (Result != 0)
ethernet_error("ethernet: driver initialization failed");
// PCI device ignores the IRQ and IO parameters
Ethernet_Interface = xn_interface_open_config(
DAVICOM_DEVICE, MINOR_0, 0, 0, 0);
if (Ethernet_Interface == SOCKET_ERROR)
{
fprintf(stderr,"ethernet: Davicom driver failed to initialize\r\n");
return false;
}
if (xn_interface_opt(Ethernet_Interface,IO_802_2,
(const char *)&value,sizeof(value)))
fprintf(stderr,"ethernet: xn_interface_opt 802.2 failed \n");
xn_interface_info(Ethernet_Interface, &ii);
printf("ethernet: MAC address: %02x-%02x-%02x-%02x-%02x-%02x\n",
ii.my_ethernet_address[0], ii.my_ethernet_address[1],
ii.my_ethernet_address[2], ii.my_ethernet_address[3],
ii.my_ethernet_address[4], ii.my_ethernet_address[5]);
// Set the IP address and interface
printf("ethernet: static IP address %i.%i.%i.%i\n",
TargetIP[0], TargetIP[1], TargetIP[2], TargetIP[3]);
if (xn_set_ip(Ethernet_Interface, TargetIP, NetMask) == SOCKET_ERROR)
{
// FIXME: is this because of a duplicate address? Tell user...
fprintf(stderr,"ethernet: failed to set IP address!\r\n");
return false;
}
// add a route in the routing table
// ip_ffaddr is apparently some global...
xn_rt_add(RT_DEFAULT, ip_ffaddr, DefaultGateway, 1,
Ethernet_Interface, RT_INF);
xn_set_server_list((DWORD*)DNSServer, 1);
// setup the socket // setup the socket
Ethernet_Socket = socket(AF_INET, SOCK_RAW, 0); Ethernet_Socket = socket(AF_INET, SOCK_RAW, 0);
if (Ethernet_Socket < 0) if (Ethernet_Socket < 0)
@@ -168,14 +81,13 @@ bool ethernet_init(char *interface_name)
} }
/* function to send a packet out the 802.2 socket */ /* function to send a packet out the 802.2 socket */
/* returns 0 on success, non-zero on failure */ /* returns bytes sent on success, negative number on failure */
int ethernet_send( int ethernet_send(
BACNET_ADDRESS *dest, // destination address BACNET_ADDRESS *dest, // destination address
BACNET_ADDRESS *src, // source address BACNET_ADDRESS *src, // source address
uint8_t *pdu, // any data to be sent - may be null uint8_t *pdu, // any data to be sent - may be null
unsigned pdu_len) // number of bytes of data unsigned pdu_len) // number of bytes of data
{ {
int status = -1;
int bytes = 0; int bytes = 0;
uint8_t mtu[MAX_MPDU] = { 0 }; uint8_t mtu[MAX_MPDU] = { 0 };
int mtu_len = 0; int mtu_len = 0;
@@ -185,7 +97,7 @@ int ethernet_send(
if (Ethernet_Socket < 0) if (Ethernet_Socket < 0)
{ {
fprintf(stderr, "ethernet: 802.2 socket is invalid!\n"); fprintf(stderr, "ethernet: 802.2 socket is invalid!\n");
return status; return -1;
} }
/* load destination ethernet MAC address */ /* load destination ethernet MAC address */
if (dest->mac_len == 6) if (dest->mac_len == 6)
@@ -199,7 +111,7 @@ int ethernet_send(
else else
{ {
fprintf(stderr, "ethernet: invalid destination MAC address!\n"); fprintf(stderr, "ethernet: invalid destination MAC address!\n");
return status; return -2;
} }
/* load source ethernet MAC address */ /* load source ethernet MAC address */
@@ -214,12 +126,12 @@ int ethernet_send(
else else
{ {
fprintf(stderr, "ethernet: invalid source MAC address!\n"); fprintf(stderr, "ethernet: invalid source MAC address!\n");
return status; return -3;
} }
if ((14 + 3 + pdu_len) > MAX_MPDU) if ((14 + 3 + pdu_len) > MAX_MPDU)
{ {
fprintf(stderr, "ethernet: PDU is too big to send!\n"); fprintf(stderr, "ethernet: PDU is too big to send!\n");
return status; return -4;
} }
/* packet length */ /* packet length */
mtu_len += encode_unsigned16(&mtu[12], mtu_len += encode_unsigned16(&mtu[12],
@@ -236,20 +148,15 @@ int ethernet_send(
sendto(Ethernet_Socket, (const char *)&mtu, mtu_len, 0, sendto(Ethernet_Socket, (const char *)&mtu, mtu_len, 0,
&Ethernet_Address, sizeof(Ethernet_Address)); &Ethernet_Address, sizeof(Ethernet_Address));
/* did it get sent? */ /* did it get sent? */
if (bytes < 0) { if (bytes < 0)
fprintf(stderr,"ethernet: Error sending packet: %s\n", fprintf(stderr,"ethernet: Error sending packet: %s\n",
strerror(errno)); strerror(errno));
return status;
}
// got this far - must be good! return bytes;
status = 0;
return status;
} }
/* function to send a packet out the 802.2 socket */ /* function to send a packet out the 802.2 socket */
/* returns zero on success, non-zero on failure */ /* returns bytes sent on success, negative number on failure */
int ethernet_send_pdu( int ethernet_send_pdu(
BACNET_ADDRESS *dest, // destination address BACNET_ADDRESS *dest, // destination address
uint8_t *pdu, // any data to be sent - may be null uint8_t *pdu, // any data to be sent - may be null
@@ -374,7 +281,19 @@ void ethernet_get_my_address(BACNET_ADDRESS *my_address)
return; return;
} }
void ethernet_set_broadcast_address( void ethernet_set_my_address(BACNET_ADDRESS *my_address)
{
int i = 0;
for (i = 0; i < 6; i++)
{
Ethernet_MAC_Address[i] = my_address->mac[i];
}
return;
}
void ethernet_get_broadcast_address(
BACNET_ADDRESS *dest) // destination address BACNET_ADDRESS *dest) // destination address
{ {
int i = 0; // counter int i = 0; // counter
@@ -427,4 +346,3 @@ void ethernet_debug_address(
return; return;
} }
+33 -27
View File
@@ -25,31 +25,6 @@
// This is one way to use the embedded BACnet stack under RTOS-32 // This is one way to use the embedded BACnet stack under RTOS-32
// compiled with Borland C++ 5.02 // compiled with Borland C++ 5.02
#define WIN32_LEAN_AND_MEAN
#define STRICT
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <process.h>
#ifndef HOST
#include <rttarget.h>
#include <rtk32.h>
#include <clock.h>
#include <socket.h>
#include "netcfg.h"
int interface = SOCKET_ERROR; // SOCKET_ERROR means no open interface
#else
#include <winsock.h>
#endif
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
@@ -59,7 +34,20 @@
#include "apdu.h" #include "apdu.h"
#include "device.h" #include "device.h"
#include "handlers.h" #include "handlers.h"
#include "bip.h" #ifdef BACDL_ETHERNET
#include "ethernet.h"
#define bacdl_receive ethernet_receive
#endif
#ifdef BACDL_BIP
#include "bip.h"
#define bacdl_receive bip_receive
#endif
#include "net.h"
#ifndef HOST
#include "netcfg.h"
#endif
static int interface = SOCKET_ERROR; // SOCKET_ERROR means no open interface
// buffers used for transmit and receive // buffers used for transmit and receive
static uint8_t Rx_Buf[MAX_MPDU] = {0}; static uint8_t Rx_Buf[MAX_MPDU] = {0};
@@ -179,10 +167,21 @@ static void NetInitialize(void)
else else
{ {
struct _iface_info ii; struct _iface_info ii;
#ifdef BACDL_ETHERNET
BACNET_ADDRESS my_address;
unsigned i;
#endif
xn_interface_info(interface, &ii); xn_interface_info(interface, &ii);
printf("Interface opened, MAC address: %02x-%02x-%02x-%02x-%02x-%02x\n", printf("Interface opened, MAC address: %02x-%02x-%02x-%02x-%02x-%02x\n",
ii.my_ethernet_address[0], ii.my_ethernet_address[1], ii.my_ethernet_address[2], ii.my_ethernet_address[0], ii.my_ethernet_address[1], ii.my_ethernet_address[2],
ii.my_ethernet_address[3], ii.my_ethernet_address[4], ii.my_ethernet_address[5]); ii.my_ethernet_address[3], ii.my_ethernet_address[4], ii.my_ethernet_address[5]);
#ifdef BACDL_ETHERNET
for (i = 0; i < 6; i++)
{
my_address.mac[i] = ii.my_ethernet_address[i];
}
ethernet_set_my_address(&my_address);
#endif
} }
#if DEVICE_ID == PRISM_PCMCIA_DEVICE || DEVICE_ID == PRISM_DEVICE #if DEVICE_ID == PRISM_PCMCIA_DEVICE || DEVICE_ID == PRISM_DEVICE
@@ -255,9 +254,16 @@ int main(int argc, char *argv[])
Init_Service_Handlers(); Init_Service_Handlers();
// init the physical layer // init the physical layer
NetInitialize(); NetInitialize();
#ifdef BACDL_BIP
bip_set_address(TargetIP[0], TargetIP[1], TargetIP[2], TargetIP[3]); bip_set_address(TargetIP[0], TargetIP[1], TargetIP[2], TargetIP[3]);
if (!bip_init()) if (!bip_init())
return 1; return 1;
#endif
#ifdef BACDL_ETHERNET
if (!ethernet_init(NULL))
return 1;
#endif
// loop forever // loop forever
for (;;) for (;;)
@@ -265,7 +271,7 @@ int main(int argc, char *argv[])
// input // input
// returns 0 bytes on timeout // returns 0 bytes on timeout
pdu_len = bip_receive( pdu_len = bacdl_receive(
&src, &src,
&Rx_Buf[0], &Rx_Buf[0],
MAX_MPDU, MAX_MPDU,
+7 -5
View File
@@ -21,7 +21,7 @@ PRODUCT = bacnet
PRODUCT_RTB = $(PRODUCT).rtb PRODUCT_RTB = $(PRODUCT).rtb
PRODUCT_EXE = $(PRODUCT).exe PRODUCT_EXE = $(PRODUCT).exe
SRCS = init.c main.c bip.c \ SRCS = init.c main.c ethernet.c bip.c \
..\..\handlers.c \ ..\..\handlers.c \
..\..\bacdcode.c \ ..\..\bacdcode.c \
..\..\bigend.c \ ..\..\bigend.c \
@@ -52,7 +52,8 @@ LOCATE = $(RTOS32_DIR)\bin\rtloc
CC_DIR = $(BORLAND_DIR)\BIN CC_DIR = $(BORLAND_DIR)\BIN
CC_INCLDIR = $(BORLAND_DIR)\include CC_INCLDIR = $(BORLAND_DIR)\include
INCL_DIRS = -I$(BORLAND_DIR)\include;$(RTOS32_DIR)\include;../../; INCL_DIRS = -I$(BORLAND_DIR)\include;$(RTOS32_DIR)\include;../../;
DEFINES = -DDOC;BACDL_BIP=1 #DEFINES = -DDOC;BACDL_BIP=1
DEFINES = -DDOC;BACDL_ETHERNET=1
CFLAGS = $(INCL_DIRS) $(CS_FLAGS) $(DEFINES) CFLAGS = $(INCL_DIRS) $(CS_FLAGS) $(DEFINES)
@@ -104,7 +105,7 @@ $(PRODUCT_RTB): bcc32.cfg hardware.cfg software.cfg $(PRODUCT_EXE)
# need a temp response file (@&&) because command line is too long # need a temp response file (@&&) because command line is too long
$(PRODUCT_EXE) : $(OBJS) $(PRODUCT_EXE) : $(OBJS)
@echo Running Linker for $(PRODUCT_EXE) @echo Running Linker for $(PRODUCT_EXE)
$(LINK) -L$(LINKER_LIB) -m -c -s -v @&&| # temp response file, starts with | $(LINK) -L$(LINKER_LIB) -m -c -s -v @&&| # temp response file, starts with |
$(BORLAND_DIR)\lib\c0x32.obj $** # $** lists each dependency $(BORLAND_DIR)\lib\c0x32.obj $** # $** lists each dependency
$< $<
$*.map $*.map
@@ -135,12 +136,13 @@ install : $(PRODUCT)
# cc generic rule # cc generic rule
# #
.c.obj: .c.obj:
@echo Compiling $@ from $< $(CC) -o$@ $<
$(CC) $(CFLAGS) -c -o$@ $<
# Compiler configuration file # Compiler configuration file
bcc32.cfg : bcc32.cfg :
Copy &&| Copy &&|
$(CFLAGS)
-c
-y #include line numbers in OBJ's -y #include line numbers in OBJ's
-v #include debug info -v #include debug info
-w+ #turn on all warnings -w+ #turn on all warnings
+21 -1
View File
@@ -25,7 +25,27 @@
#ifndef NET_H #ifndef NET_H
#define NET_H #define NET_H
#include <socket.h> #define WIN32_LEAN_AND_MEAN
#define STRICT
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <process.h>
#ifndef HOST
#include <rttarget.h>
#include <rtk32.h>
#include <clock.h>
#include <socket.h>
#else
#include <winsock.h>
#endif
#define close closesocket #define close closesocket
#endif #endif
+3 -3
View File
@@ -84,7 +84,7 @@ int rp_decode_service_request(
BACNET_PROPERTY_ID *object_property, BACNET_PROPERTY_ID *object_property,
int32_t *array_index) int32_t *array_index)
{ {
int len = 0; unsigned len = 0;
uint8_t tag_number = 0; uint8_t tag_number = 0;
uint32_t len_value_type = 0; uint32_t len_value_type = 0;
int type = 0; // for decoding int type = 0; // for decoding
@@ -125,7 +125,7 @@ int rp_decode_service_request(
*array_index = BACNET_ARRAY_ALL; *array_index = BACNET_ARRAY_ALL;
} }
return len; return (int)len;
} }
int rp_decode_apdu( int rp_decode_apdu(
@@ -138,7 +138,7 @@ int rp_decode_apdu(
int32_t *array_index) int32_t *array_index)
{ {
int len = 0; int len = 0;
int offset = 0; unsigned offset = 0;
if (!apdu) if (!apdu)
return -1; return -1;
+2 -2
View File
@@ -88,7 +88,7 @@ int whois_decode_service_request(
if (tag_number != 0) if (tag_number != 0)
return -1; return -1;
len += decode_unsigned(&apdu[len], len_value, &decoded_value); len += decode_unsigned(&apdu[len], len_value, &decoded_value);
if ((decoded_value >= 0) && (decoded_value <= BACNET_MAX_INSTANCE)) if (decoded_value <= BACNET_MAX_INSTANCE)
{ {
if (pLow_limit) if (pLow_limit)
*pLow_limit = decoded_value; *pLow_limit = decoded_value;
@@ -98,7 +98,7 @@ int whois_decode_service_request(
return -1; return -1;
len += decode_unsigned(&apdu[len], len += decode_unsigned(&apdu[len],
len_value, &decoded_value); len_value, &decoded_value);
if ((decoded_value >= 0) && (decoded_value <= BACNET_MAX_INSTANCE)) if (decoded_value <= BACNET_MAX_INSTANCE)
{ {
if (pHigh_limit) if (pHigh_limit)
*pHigh_limit = decoded_value; *pHigh_limit = decoded_value;
+1 -1
View File
@@ -147,7 +147,7 @@ int wp_decode_apdu(
BACNET_WRITE_PROPERTY_DATA *data) BACNET_WRITE_PROPERTY_DATA *data)
{ {
int len = 0; int len = 0;
int offset = 0; unsigned offset = 0;
if (!apdu) if (!apdu)
return -1; return -1;