Updated to work with RTOS-32 port; found that Ethernet PACKET does not work, but BACnet/IP works.

This commit is contained in:
skarg
2005-05-10 16:09:00 +00:00
parent 9c51ec2cd0
commit 7a6ef736c5
4 changed files with 26 additions and 13 deletions
+16 -5
View File
@@ -42,9 +42,11 @@ static int BIP_Socket = -1;
/* port to use - stored in network byte order */ /* port to use - stored in network byte order */
static uint16_t BIP_Port = 0; static uint16_t BIP_Port = 0;
/* IP Address - stored in network byte order */ /* IP Address - stored in network byte order */
static struct in_addr BIP_Address = {{{-1}}}; static struct in_addr BIP_Address;
/* Broadcast Address */ /* Broadcast Address */
static struct in_addr BIP_Broadcast_Address = {{{-1}}}; static struct in_addr BIP_Broadcast_Address;
/* Subnet Mask */
static struct in_addr BIP_Subnet_Mask;
bool bip_valid(void) bool bip_valid(void)
{ {
@@ -89,6 +91,13 @@ void bip_set_broadcast_address(uint8_t octet1, uint8_t octet2,
octet1, octet2, octet3, octet4); octet1, octet2, octet3, octet4);
} }
void bip_set_subnet_mask(uint8_t octet1, uint8_t octet2,
uint8_t octet3, uint8_t octet4)
{
set_network_address(&BIP_Subnet_Mask,
octet1, octet2, octet3, octet4);
}
void bip_set_port(uint16_t port) void bip_set_port(uint16_t port)
{ {
BIP_Port = htons(port); BIP_Port = htons(port);
@@ -98,14 +107,16 @@ 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}; struct sockaddr_in sin = {-1};
int value = 1;
/* network global broadcast address */ /* local broadcast address */
set_network_address(&BIP_Broadcast_Address,255,255,255,255); BIP_Broadcast_Address.s_addr = BIP_Address.s_addr;
BIP_Broadcast_Address.s_addr |= ~(BIP_Subnet_Mask.s_addr);
/* configure standard BACnet/IP port */ /* configure standard BACnet/IP port */
bip_set_port(0xBAC0); bip_set_port(0xBAC0);
// assumes that the driver has already been initialized // assumes that the driver has already been initialized
BIP_Socket = socket(AF_INET, SOCK_DGRAM, 0); BIP_Socket = socket(AF_INET, SOCK_DGRAM, IPROTO_UDP);
if (BIP_Socket < 0) if (BIP_Socket < 0)
return false; return false;
+2 -2
View File
@@ -68,6 +68,7 @@ bool ethernet_init(char *interface_name)
(void)interface_name; (void)interface_name;
// setup the socket // setup the socket
Ethernet_Socket = socket(AF_INET, SOCK_RAW, 0); Ethernet_Socket = socket(AF_INET, SOCK_RAW, 0);
//Ethernet_Socket = socket(AF_INET, SOCK_STREAM, 0);
if (Ethernet_Socket < 0) if (Ethernet_Socket < 0)
fprintf(stderr,"ethernet: failed to bind to socket!\r\n"); fprintf(stderr,"ethernet: failed to bind to socket!\r\n");
Ethernet_Address.sa_family = AF_INET; Ethernet_Address.sa_family = AF_INET;
@@ -145,8 +146,7 @@ int ethernet_send(
/* Send the packet */ /* Send the packet */
bytes = bytes =
sendto(Ethernet_Socket, (const char *)&mtu, mtu_len, 0, send(Ethernet_Socket, (const char *)&mtu, mtu_len, 0);
&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",
+2 -1
View File
@@ -70,7 +70,7 @@ static uint8_t MSTP_MAC_Address = 0x05; // local MAC address
static void Init_Device_Parameters(void) static void Init_Device_Parameters(void)
{ {
// configure my initial values // configure my initial values
Device_Set_Object_Instance_Number(112); Device_Set_Object_Instance_Number(126);
Device_Set_Vendor_Name("Lithonia Lighting"); Device_Set_Vendor_Name("Lithonia Lighting");
Device_Set_Vendor_Identifier(42); Device_Set_Vendor_Identifier(42);
Device_Set_Model_Name("Simple BACnet Server"); Device_Set_Model_Name("Simple BACnet Server");
@@ -273,6 +273,7 @@ int main(int argc, char *argv[])
#ifdef BACDL_BIP #ifdef BACDL_BIP
NetInitialize(); NetInitialize();
bip_set_address(TargetIP[0], TargetIP[1], TargetIP[2], TargetIP[3]); bip_set_address(TargetIP[0], TargetIP[1], TargetIP[2], TargetIP[3]);
bip_set_address(NetMask[0], NetMask[1], NetMask[2], NetMask[3]);
if (!bip_init()) if (!bip_init())
return 1; return 1;
#endif #endif
+4 -3
View File
@@ -22,11 +22,12 @@ PRODUCT_RTB = $(PRODUCT).rtb
PRODUCT_EXE = $(PRODUCT).exe PRODUCT_EXE = $(PRODUCT).exe
# Choose the Data Link Layer to Enable # Choose the Data Link Layer to Enable
#DEFINES = -DDOC;BACDL_BIP=1 DEFINES = -DDOC;BACDL_BIP=1
#DEFINES = -DDOC;BACDL_ETHERNET=1 #DEFINES = -DDOC;BACDL_ETHERNET=1
DEFINES = -DDOC;BACDL_MSTP=1 #DEFINES = -DDOC;BACDL_MSTP=1
SRCS = init.c main.c ethernet.c bip.c rs485.c \ SRCS = init.c main.c ethernet.c bip.c \
rs485.c \
..\..\mstp.c \ ..\..\mstp.c \
..\..\crc.c \ ..\..\crc.c \
..\..\handlers.c \ ..\..\handlers.c \