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
+18 -7
View File
@@ -42,9 +42,11 @@ static int BIP_Socket = -1;
/* port to use - stored in network byte order */
static uint16_t BIP_Port = 0;
/* IP Address - stored in network byte order */
static struct in_addr BIP_Address = {{{-1}}};
static struct in_addr BIP_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)
{
@@ -85,7 +87,14 @@ void bip_set_address(uint8_t octet1, uint8_t octet2,
void bip_set_broadcast_address(uint8_t octet1, uint8_t octet2,
uint8_t octet3, uint8_t octet4)
{
set_network_address(&BIP_Broadcast_Address,
set_network_address(&BIP_Broadcast_Address,
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);
}
@@ -98,14 +107,16 @@ bool bip_init(void)
{
int rv = 0; // return from socket lib calls
struct sockaddr_in sin = {-1};
/* network global broadcast address */
set_network_address(&BIP_Broadcast_Address,255,255,255,255);
int value = 1;
/* local broadcast address */
BIP_Broadcast_Address.s_addr = BIP_Address.s_addr;
BIP_Broadcast_Address.s_addr |= ~(BIP_Subnet_Mask.s_addr);
/* configure standard BACnet/IP port */
bip_set_port(0xBAC0);
// 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)
return false;
+2 -2
View File
@@ -68,6 +68,7 @@ bool ethernet_init(char *interface_name)
(void)interface_name;
// setup the socket
Ethernet_Socket = socket(AF_INET, SOCK_RAW, 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;
@@ -145,8 +146,7 @@ int ethernet_send(
/* Send the packet */
bytes =
sendto(Ethernet_Socket, (const char *)&mtu, mtu_len, 0,
&Ethernet_Address, sizeof(Ethernet_Address));
send(Ethernet_Socket, (const char *)&mtu, mtu_len, 0);
/* did it get sent? */
if (bytes < 0)
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)
{
// 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_Identifier(42);
Device_Set_Model_Name("Simple BACnet Server");
@@ -273,6 +273,7 @@ int main(int argc, char *argv[])
#ifdef BACDL_BIP
NetInitialize();
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())
return 1;
#endif
+4 -3
View File
@@ -22,11 +22,12 @@ PRODUCT_RTB = $(PRODUCT).rtb
PRODUCT_EXE = $(PRODUCT).exe
# 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_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 \
..\..\crc.c \
..\..\handlers.c \