refactored the data link layer
This commit is contained in:
@@ -20,6 +20,7 @@ SRCS = ports/linux/main.c \
|
|||||||
rp.c \
|
rp.c \
|
||||||
wp.c \
|
wp.c \
|
||||||
tsm.c \
|
tsm.c \
|
||||||
|
datalink.c \
|
||||||
address.c \
|
address.c \
|
||||||
device.c \
|
device.c \
|
||||||
ai.c \
|
ai.c \
|
||||||
|
|||||||
+13
-46
@@ -44,32 +44,10 @@
|
|||||||
#include "bacerror.h"
|
#include "bacerror.h"
|
||||||
#include "address.h"
|
#include "address.h"
|
||||||
#include "tsm.h"
|
#include "tsm.h"
|
||||||
|
#include "datalink.h"
|
||||||
|
|
||||||
// Example handlers of services
|
// Example handlers of services
|
||||||
|
|
||||||
#ifdef BACDL_ETHERNET
|
|
||||||
#include "ethernet.h"
|
|
||||||
#define bacdl_get_broadcast_address ethernet_get_broadcast_address
|
|
||||||
#define bacdl_get_my_address ethernet_get_my_address
|
|
||||||
#define bacdl_send_pdu ethernet_send_pdu
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef BACDL_MSTP
|
|
||||||
#include "mstp.h"
|
|
||||||
#define bacdl_get_broadcast_address mstp_get_broadcast_address
|
|
||||||
#define bacdl_get_my_address mstp_get_my_address
|
|
||||||
#define bacdl_send_pdu mstp_send_pdu
|
|
||||||
#define bacdl_receive mstp_receive
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef BACDL_BIP
|
|
||||||
#include "bip.h"
|
|
||||||
#define bacdl_get_broadcast_address bip_get_broadcast_address
|
|
||||||
#define bacdl_get_my_address bip_get_my_address
|
|
||||||
#define bacdl_send_pdu bip_send_pdu
|
|
||||||
#define bacdl_receive bip_receive
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// flag to send an I-Am
|
// flag to send an I-Am
|
||||||
bool I_Am_Request = true;
|
bool I_Am_Request = true;
|
||||||
// flag to send a global Who-Is
|
// flag to send a global Who-Is
|
||||||
@@ -91,7 +69,7 @@ void UnrecognizedServiceHandler(
|
|||||||
|
|
||||||
(void)service_request;
|
(void)service_request;
|
||||||
(void)service_len;
|
(void)service_len;
|
||||||
bacdl_get_my_address(&src);
|
datalink_get_my_address(&src);
|
||||||
|
|
||||||
// encode the NPDU portion of the packet
|
// encode the NPDU portion of the packet
|
||||||
pdu_len = npdu_encode_apdu(
|
pdu_len = npdu_encode_apdu(
|
||||||
@@ -107,7 +85,7 @@ void UnrecognizedServiceHandler(
|
|||||||
service_data->invoke_id,
|
service_data->invoke_id,
|
||||||
REJECT_REASON_UNRECOGNIZED_SERVICE);
|
REJECT_REASON_UNRECOGNIZED_SERVICE);
|
||||||
|
|
||||||
bytes_sent = bacdl_send_pdu(
|
bytes_sent = datalink_send_pdu(
|
||||||
dest, // destination address
|
dest, // destination address
|
||||||
&Tx_Buf[0],
|
&Tx_Buf[0],
|
||||||
pdu_len); // number of bytes of data
|
pdu_len); // number of bytes of data
|
||||||
@@ -126,7 +104,7 @@ void Send_IAm(void)
|
|||||||
int bytes_sent = 0;
|
int bytes_sent = 0;
|
||||||
|
|
||||||
// I-Am is a global broadcast
|
// I-Am is a global broadcast
|
||||||
bacdl_get_broadcast_address(&dest);
|
datalink_get_broadcast_address(&dest);
|
||||||
|
|
||||||
// encode the NPDU portion of the packet
|
// encode the NPDU portion of the packet
|
||||||
pdu_len = npdu_encode_apdu(
|
pdu_len = npdu_encode_apdu(
|
||||||
@@ -144,7 +122,7 @@ void Send_IAm(void)
|
|||||||
SEGMENTATION_NONE,
|
SEGMENTATION_NONE,
|
||||||
Device_Vendor_Identifier());
|
Device_Vendor_Identifier());
|
||||||
|
|
||||||
bytes_sent = bacdl_send_pdu(
|
bytes_sent = datalink_send_pdu(
|
||||||
&dest, // destination address
|
&dest, // destination address
|
||||||
&Tx_Buf[0],
|
&Tx_Buf[0],
|
||||||
pdu_len); // number of bytes of data
|
pdu_len); // number of bytes of data
|
||||||
@@ -161,7 +139,7 @@ void Send_WhoIs(void)
|
|||||||
int bytes_sent = 0;
|
int bytes_sent = 0;
|
||||||
|
|
||||||
// Who-Is is a global broadcast
|
// Who-Is is a global broadcast
|
||||||
bacdl_get_broadcast_address(&dest);
|
datalink_get_broadcast_address(&dest);
|
||||||
|
|
||||||
// encode the NPDU portion of the packet
|
// encode the NPDU portion of the packet
|
||||||
pdu_len = npdu_encode_apdu(
|
pdu_len = npdu_encode_apdu(
|
||||||
@@ -177,7 +155,7 @@ void Send_WhoIs(void)
|
|||||||
-1, // send to all
|
-1, // send to all
|
||||||
-1);// send to all
|
-1);// send to all
|
||||||
|
|
||||||
bytes_sent = bacdl_send_pdu(
|
bytes_sent = datalink_send_pdu(
|
||||||
&dest, // destination address
|
&dest, // destination address
|
||||||
&Tx_Buf[0],
|
&Tx_Buf[0],
|
||||||
pdu_len); // number of bytes of data
|
pdu_len); // number of bytes of data
|
||||||
@@ -206,7 +184,7 @@ bool Send_Read_Property_Request(
|
|||||||
status = address_get_by_device(device_id, &max_apdu, &dest);
|
status = address_get_by_device(device_id, &max_apdu, &dest);
|
||||||
if (status)
|
if (status)
|
||||||
{
|
{
|
||||||
bacdl_get_my_address(&my_address);
|
datalink_get_my_address(&my_address);
|
||||||
pdu_len = npdu_encode_apdu(
|
pdu_len = npdu_encode_apdu(
|
||||||
&Tx_Buf[0],
|
&Tx_Buf[0],
|
||||||
&dest,
|
&dest,
|
||||||
@@ -229,7 +207,7 @@ bool Send_Read_Property_Request(
|
|||||||
&dest,
|
&dest,
|
||||||
&Tx_Buf[0],
|
&Tx_Buf[0],
|
||||||
pdu_len);
|
pdu_len);
|
||||||
bytes_sent = bacdl_send_pdu(
|
bytes_sent = datalink_send_pdu(
|
||||||
&dest, // destination address
|
&dest, // destination address
|
||||||
&Tx_Buf[0],
|
&Tx_Buf[0],
|
||||||
pdu_len); // number of bytes of data
|
pdu_len); // number of bytes of data
|
||||||
@@ -247,17 +225,6 @@ bool Send_Read_Property_Request(
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
int handler_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
|
|
||||||
{
|
|
||||||
return bacdl_send_pdu(
|
|
||||||
dest,
|
|
||||||
pdu,
|
|
||||||
pdu_len);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WhoIsHandler(
|
void WhoIsHandler(
|
||||||
uint8_t *service_request,
|
uint8_t *service_request,
|
||||||
uint16_t service_len,
|
uint16_t service_len,
|
||||||
@@ -375,7 +342,7 @@ void ReadPropertyHandler(
|
|||||||
else
|
else
|
||||||
fprintf(stderr,"Unable to decode Read-Property Request!\n");
|
fprintf(stderr,"Unable to decode Read-Property Request!\n");
|
||||||
// prepare a reply
|
// prepare a reply
|
||||||
bacdl_get_my_address(&my_address);
|
datalink_get_my_address(&my_address);
|
||||||
// encode the NPDU portion of the packet
|
// encode the NPDU portion of the packet
|
||||||
pdu_len = npdu_encode_apdu(
|
pdu_len = npdu_encode_apdu(
|
||||||
&Tx_Buf[0],
|
&Tx_Buf[0],
|
||||||
@@ -523,7 +490,7 @@ void ReadPropertyHandler(
|
|||||||
}
|
}
|
||||||
if (send)
|
if (send)
|
||||||
{
|
{
|
||||||
bytes_sent = bacdl_send_pdu(
|
bytes_sent = datalink_send_pdu(
|
||||||
src, // destination address
|
src, // destination address
|
||||||
&Tx_Buf[0],
|
&Tx_Buf[0],
|
||||||
pdu_len); // number of bytes of data
|
pdu_len); // number of bytes of data
|
||||||
@@ -563,7 +530,7 @@ void WritePropertyHandler(
|
|||||||
else
|
else
|
||||||
fprintf(stderr,"Unable to decode Write-Property Request!\n");
|
fprintf(stderr,"Unable to decode Write-Property Request!\n");
|
||||||
// prepare a reply
|
// prepare a reply
|
||||||
bacdl_get_my_address(&my_address);
|
datalink_get_my_address(&my_address);
|
||||||
// encode the NPDU portion of the packet
|
// encode the NPDU portion of the packet
|
||||||
pdu_len = npdu_encode_apdu(
|
pdu_len = npdu_encode_apdu(
|
||||||
&Tx_Buf[0],
|
&Tx_Buf[0],
|
||||||
@@ -654,7 +621,7 @@ void WritePropertyHandler(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bytes_sent = bacdl_send_pdu(
|
bytes_sent = datalink_send_pdu(
|
||||||
src, // destination address
|
src, // destination address
|
||||||
&Tx_Buf[0],
|
&Tx_Buf[0],
|
||||||
pdu_len); // number of bytes of data
|
pdu_len); // number of bytes of data
|
||||||
|
|||||||
@@ -36,11 +36,6 @@ extern bool I_Am_Request;
|
|||||||
// flag to send a global Who-Is
|
// flag to send a global Who-Is
|
||||||
extern bool Who_Is_Request;
|
extern bool Who_Is_Request;
|
||||||
|
|
||||||
int handler_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
|
|
||||||
|
|
||||||
void UnrecognizedServiceHandler(
|
void UnrecognizedServiceHandler(
|
||||||
uint8_t *service_request,
|
uint8_t *service_request,
|
||||||
uint16_t service_len,
|
uint16_t service_len,
|
||||||
|
|||||||
+2
-1
@@ -44,6 +44,7 @@
|
|||||||
#include "tsm.h"
|
#include "tsm.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
|
#include "datalink.h"
|
||||||
#include "handlers.h"
|
#include "handlers.h"
|
||||||
#include "address.h"
|
#include "address.h"
|
||||||
|
|
||||||
@@ -192,7 +193,7 @@ void tsm_timer_milliseconds(uint16_t milliseconds)
|
|||||||
TSM_List[i].RequestTimer = Device_APDU_Timeout();
|
TSM_List[i].RequestTimer = Device_APDU_Timeout();
|
||||||
if (TSM_List[i].RetryCount)
|
if (TSM_List[i].RetryCount)
|
||||||
{
|
{
|
||||||
bytes_sent = handler_send_pdu(
|
bytes_sent = datalink_send_pdu(
|
||||||
&TSM_List[i].dest, // destination address
|
&TSM_List[i].dest, // destination address
|
||||||
&TSM_List[i].pdu[0],
|
&TSM_List[i].pdu[0],
|
||||||
TSM_List[i].pdu_len); // number of bytes of data
|
TSM_List[i].pdu_len); // number of bytes of data
|
||||||
|
|||||||
Reference in New Issue
Block a user