indented
This commit is contained in:
@@ -186,7 +186,7 @@ bool arcnet_init(char *interface_name)
|
||||
/* 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 */
|
||||
BACNET_NPDU_DATA * npdu_data, /* network information */
|
||||
BACNET_NPDU_DATA * npdu_data, /* network information */
|
||||
uint8_t * pdu, /* any data to be sent - may be null */
|
||||
unsigned pdu_len)
|
||||
{ /* number of bytes of data */
|
||||
@@ -230,7 +230,7 @@ int arcnet_send_pdu(BACNET_ADDRESS * dest, /* destination address */
|
||||
fprintf(stderr, "arcnet: PDU is too big to send!\n");
|
||||
return -4;
|
||||
}
|
||||
memcpy(&pkt->soft.raw[4+npdu_len], pdu, pdu_len);
|
||||
memcpy(&pkt->soft.raw[4 + npdu_len], pdu, pdu_len);
|
||||
/* Send the packet */
|
||||
bytes =
|
||||
sendto(ARCNET_Sock_FD, &mtu, mtu_len, 0,
|
||||
|
||||
@@ -179,14 +179,14 @@ bool ethernet_init(char *interface_name)
|
||||
/* 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 */
|
||||
BACNET_NPDU_DATA * npdu_data, /* network information */
|
||||
BACNET_NPDU_DATA * npdu_data, /* network information */
|
||||
uint8_t * pdu, /* any data to be sent - may be null */
|
||||
unsigned pdu_len)
|
||||
{ /* number of bytes of data */
|
||||
int i = 0; /* counter */
|
||||
int bytes = 0;
|
||||
BACNET_ADDRESS src = { 0 }; /* source address for npdu*/
|
||||
uint8_t mtu[MAX_MPDU] = { 0 }; /* our buffer */
|
||||
BACNET_ADDRESS src = { 0 }; /* source address for npdu */
|
||||
uint8_t mtu[MAX_MPDU] = { 0 }; /* our buffer */
|
||||
int mtu_len = 0;
|
||||
int npdu_len = 0;
|
||||
|
||||
@@ -221,9 +221,9 @@ int ethernet_send_pdu(BACNET_ADDRESS * dest, /* destination address */
|
||||
return -3;
|
||||
}
|
||||
/* Logical PDU portion */
|
||||
mtu[14] = 0x82; /* DSAP for BACnet */
|
||||
mtu[15] = 0x82; /* SSAP for BACnet */
|
||||
mtu[16] = 0x03; /* Control byte in header */
|
||||
mtu[14] = 0x82; /* DSAP for BACnet */
|
||||
mtu[15] = 0x82; /* SSAP for BACnet */
|
||||
mtu[16] = 0x03; /* Control byte in header */
|
||||
npdu_len = npdu_encode_pdu(&mtu[17], dest, &src, npdu_data);
|
||||
mtu_len = 17 + npdu_len;
|
||||
if ((mtu_len + pdu_len) > MAX_MPDU) {
|
||||
|
||||
@@ -31,13 +31,13 @@
|
||||
#include "dlmstp.h"
|
||||
#include "rs485.h"
|
||||
#include "npdu.h"
|
||||
|
||||
/* receive buffer */
|
||||
static DLMSTP_PACKET Receive_Buffer;
|
||||
|
||||
/* receive buffer */
|
||||
static DLMSTP_PACKET Receive_Buffer;
|
||||
/* temp buffer for NPDU insertion */
|
||||
static uint8_t PDU_Buffer[MAX_MPDU];
|
||||
/* local MS/TP port data */
|
||||
static volatile struct mstp_port_struct_t MSTP_Port;
|
||||
/* local MS/TP port data */
|
||||
static volatile struct mstp_port_struct_t MSTP_Port;
|
||||
|
||||
void dlmstp_init(void)
|
||||
{
|
||||
@@ -56,49 +56,47 @@ void dlmstp_cleanup(void)
|
||||
|
||||
/* returns number of bytes sent on success, zero on failure */
|
||||
int dlmstp_send_pdu(BACNET_ADDRESS * dest, /* destination address */
|
||||
BACNET_NPDU_DATA * npdu_data, /* network information */
|
||||
BACNET_NPDU_DATA * npdu_data, /* network information */
|
||||
uint8_t * pdu, /* any data to be sent - may be null */
|
||||
unsigned pdu_len)
|
||||
{ /* number of bytes of data */
|
||||
bool status;
|
||||
int bytes_sent = 0;
|
||||
int npdu_len = 0;
|
||||
int npdu_len = 0;
|
||||
uint8_t frame_type = 0;
|
||||
uint8_t destination = 0; /* destination address */
|
||||
uint8_t destination = 0; /* destination address */
|
||||
BACNET_ADDRESS src;
|
||||
|
||||
if (MSTP_Port.TxReady == false) {
|
||||
if (npdu_data->confirmed_message)
|
||||
MSTP_Port.TxFrameType = FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY;
|
||||
else
|
||||
MSTP_Port.TxFrameType = FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY;
|
||||
MSTP_Port.TxFrameType =
|
||||
FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY;
|
||||
|
||||
/* load destination MAC address */
|
||||
if (dest && dest->mac_len == 1) {
|
||||
destination = dest->mac[0];
|
||||
} else {
|
||||
#if PRINT_ENABLED
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "mstp: invalid destination MAC address!\n");
|
||||
#endif
|
||||
#endif
|
||||
return -2;
|
||||
}
|
||||
dlmstp_get_my_address(&src);
|
||||
npdu_len = npdu_encode_pdu(&PDU_Buffer[0], dest, &src, npdu_data);
|
||||
if ((8 /* header len */ + npdu_len + pdu_len) > MAX_MPDU) {
|
||||
#if PRINT_ENABLED
|
||||
if ((8 /* header len */ + npdu_len + pdu_len) > MAX_MPDU) {
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "mstp: PDU is too big to send!\n");
|
||||
#endif
|
||||
#endif
|
||||
return -4;
|
||||
}
|
||||
memmove(&PDU_Buffer[npdu_len], pdu, pdu_len);
|
||||
bytes_sent = MSTP_Create_Frame(
|
||||
&MSTP_Port.TxBuffer[0],
|
||||
}
|
||||
memmove(&PDU_Buffer[npdu_len], pdu, pdu_len);
|
||||
bytes_sent = MSTP_Create_Frame(&MSTP_Port.TxBuffer[0],
|
||||
sizeof(MSTP_Port.TxBuffer),
|
||||
MSTP_Port.TxFrameType,
|
||||
destination,
|
||||
MSTP_Port.This_Station,
|
||||
&PDU_Buffer[0],
|
||||
npdu_len + pdu_len);
|
||||
MSTP_Port.This_Station, &PDU_Buffer[0], npdu_len + pdu_len);
|
||||
MSTP_Port.TxLength = bytes_sent;
|
||||
MSTP_Port.TxReady = true;
|
||||
}
|
||||
@@ -127,17 +125,17 @@ uint16_t dlmstp_receive(BACNET_ADDRESS * src, /* source address */
|
||||
uint8_t * pdu, /* PDU data */
|
||||
uint16_t max_pdu, /* amount of space available in the PDU */
|
||||
unsigned timeout)
|
||||
{
|
||||
uint16_t pdu_len = 0;
|
||||
|
||||
{
|
||||
uint16_t pdu_len = 0;
|
||||
|
||||
(void) timeout;
|
||||
/* see if there is a packet available */
|
||||
if (Receive_Buffer.ready)
|
||||
{
|
||||
memmove(src, &Receive_Buffer.address, sizeof(Receive_Buffer.address));
|
||||
if (Receive_Buffer.ready) {
|
||||
memmove(src, &Receive_Buffer.address,
|
||||
sizeof(Receive_Buffer.address));
|
||||
pdu_len = Receive_Buffer.pdu_len;
|
||||
memmove(&pdu[0], &Receive_Buffer.pdu[0], max_pdu);
|
||||
Receive_Buffer.ready = false;
|
||||
Receive_Buffer.ready = false;
|
||||
}
|
||||
|
||||
return pdu_len;
|
||||
|
||||
@@ -95,7 +95,9 @@ void My_Read_Property_Handler(uint8_t * service_request,
|
||||
data.application_data = &Temp_Buf[0];
|
||||
data.application_data_len = len;
|
||||
/* FIXME: probably need a length limitation sent with encode */
|
||||
pdu_len = rp_ack_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, &data);
|
||||
pdu_len =
|
||||
rp_ack_encode_apdu(&Handler_Transmit_Buffer[0],
|
||||
service_data->invoke_id, &data);
|
||||
} else
|
||||
error = true;
|
||||
} else
|
||||
@@ -112,8 +114,7 @@ void My_Read_Property_Handler(uint8_t * service_request,
|
||||
SERVICE_CONFIRMED_READ_PROPERTY, error_class, error_code);
|
||||
}
|
||||
npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
|
||||
bytes_sent = datalink_send_pdu(src, &npdu_data,
|
||||
&Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
|
||||
bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ void RS485_Process_Tx_Message(void)
|
||||
*****************************************************************************/
|
||||
bool RS485_Tx_Complete(void)
|
||||
{
|
||||
return RS485_Flags.TransmitComplete;
|
||||
return RS485_Flags.TransmitComplete;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -42,7 +42,7 @@ static int interface = SOCKET_ERROR; /* SOCKET_ERROR means no open interface
|
||||
void bip_set_interface(char *ifname)
|
||||
{
|
||||
/*dummy function - to make the demos compile easier */
|
||||
(void)ifname;
|
||||
(void) ifname;
|
||||
}
|
||||
|
||||
/*-----------------------------------*/
|
||||
@@ -204,16 +204,15 @@ static void NetInitialize(void)
|
||||
* ALGORITHM: none
|
||||
* NOTES: none
|
||||
******************************************************************/
|
||||
static void RTIP_To_Network_Address(
|
||||
BYTE *octet_address,
|
||||
struct in_addr *addr)
|
||||
static void RTIP_To_Network_Address(BYTE * octet_address,
|
||||
struct in_addr *addr)
|
||||
{
|
||||
uint32_t ip_address = 0; /* for decoding the subnet mask */
|
||||
uint32_t ip_address = 0; /* for decoding the subnet mask */
|
||||
|
||||
decode_unsigned32(octet_address, &ip_address);
|
||||
addr->s_addr = htonl(ip_address);
|
||||
decode_unsigned32(octet_address, &ip_address);
|
||||
addr->s_addr = htonl(ip_address);
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
static void set_broadcast_address(uint32_t net_address)
|
||||
|
||||
@@ -26,21 +26,21 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#if PRINT_ENABLED
|
||||
#include <stdio.h>
|
||||
#if PRINT_ENABLED
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#include "bacdef.h"
|
||||
#include "mstp.h"
|
||||
#include "dlmstp.h"
|
||||
#include "rs485.h"
|
||||
#include "npdu.h"
|
||||
|
||||
/* receive buffer */
|
||||
static DLMSTP_PACKET Receive_Buffer;
|
||||
|
||||
/* receive buffer */
|
||||
static DLMSTP_PACKET Receive_Buffer;
|
||||
/* temp buffer for NPDU insertion */
|
||||
static uint8_t PDU_Buffer[MAX_MPDU];
|
||||
/* local MS/TP port data */
|
||||
static volatile struct mstp_port_struct_t MSTP_Port;
|
||||
/* local MS/TP port data */
|
||||
static volatile struct mstp_port_struct_t MSTP_Port;
|
||||
|
||||
void dlmstp_init(void)
|
||||
{
|
||||
@@ -59,49 +59,48 @@ void dlmstp_cleanup(void)
|
||||
|
||||
/* returns number of bytes sent on success, zero on failure */
|
||||
int dlmstp_send_pdu(BACNET_ADDRESS * dest, /* destination address */
|
||||
BACNET_NPDU_DATA * npdu_data, /* network information */
|
||||
BACNET_NPDU_DATA * npdu_data, /* network information */
|
||||
uint8_t * pdu, /* any data to be sent - may be null */
|
||||
unsigned pdu_len)
|
||||
{ /* number of bytes of data */
|
||||
int bytes_sent = 0;
|
||||
unsigned npdu_len = 0;
|
||||
unsigned npdu_len = 0;
|
||||
uint8_t frame_type = 0;
|
||||
uint8_t destination = 0; /* destination address */
|
||||
uint8_t destination = 0; /* destination address */
|
||||
BACNET_ADDRESS src;
|
||||
|
||||
if (MSTP_Port.TxReady == false) {
|
||||
if (npdu_data->confirmed_message)
|
||||
MSTP_Port.TxFrameType = FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY;
|
||||
else
|
||||
MSTP_Port.TxFrameType = FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY;
|
||||
MSTP_Port.TxFrameType =
|
||||
FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY;
|
||||
|
||||
/* load destination MAC address */
|
||||
if (dest && dest->mac_len == 1) {
|
||||
destination = dest->mac[0];
|
||||
} else {
|
||||
#if PRINT_ENABLED
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "mstp: invalid destination MAC address!\n");
|
||||
#endif
|
||||
#endif
|
||||
return -2;
|
||||
}
|
||||
dlmstp_get_my_address(&src);
|
||||
npdu_len = npdu_encode_pdu(&PDU_Buffer[0], dest, &src, npdu_data);
|
||||
if ((8 /* header len */ + npdu_len + pdu_len) > MAX_MPDU) {
|
||||
#if PRINT_ENABLED
|
||||
if ((8 /* header len */ + npdu_len + pdu_len) > MAX_MPDU) {
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "mstp: PDU is too big to send!\n");
|
||||
#endif
|
||||
#endif
|
||||
return -4;
|
||||
}
|
||||
memmove(&PDU_Buffer[npdu_len], pdu, pdu_len);
|
||||
}
|
||||
memmove(&PDU_Buffer[npdu_len], pdu, pdu_len);
|
||||
bytes_sent = MSTP_Create_Frame(
|
||||
(uint8_t *)&MSTP_Port.TxBuffer[0],
|
||||
(uint8_t *) & MSTP_Port.TxBuffer[0],
|
||||
sizeof(MSTP_Port.TxBuffer),
|
||||
MSTP_Port.TxFrameType,
|
||||
destination,
|
||||
MSTP_Port.This_Station,
|
||||
&PDU_Buffer[0],
|
||||
npdu_len + pdu_len);
|
||||
MSTP_Port.TxLength = bytes_sent;
|
||||
MSTP_Port.This_Station, &PDU_Buffer[0], npdu_len + pdu_len);
|
||||
MSTP_Port.TxLength = bytes_sent;
|
||||
MSTP_Port.TxReady = true;
|
||||
}
|
||||
|
||||
@@ -109,16 +108,15 @@ int dlmstp_send_pdu(BACNET_ADDRESS * dest, /* destination address */
|
||||
}
|
||||
|
||||
void dlmstp_task(void)
|
||||
{
|
||||
{
|
||||
RS485_Check_UART_Data(&MSTP_Port);
|
||||
/* only do receive state machine while we don't have a frame */
|
||||
if ((MSTP_Port.ReceivedValidFrame == false) &&
|
||||
(MSTP_Port.ReceivedInvalidFrame == false))
|
||||
{
|
||||
MSTP_Receive_Frame_FSM(&MSTP_Port);
|
||||
}
|
||||
/* only do master state machine while rx is idle */
|
||||
if (MSTP_Port.receive_state == MSTP_RECEIVE_STATE_IDLE)
|
||||
/* only do receive state machine while we don't have a frame */
|
||||
if ((MSTP_Port.ReceivedValidFrame == false) &&
|
||||
(MSTP_Port.ReceivedInvalidFrame == false)) {
|
||||
MSTP_Receive_Frame_FSM(&MSTP_Port);
|
||||
}
|
||||
/* only do master state machine while rx is idle */
|
||||
if (MSTP_Port.receive_state == MSTP_RECEIVE_STATE_IDLE)
|
||||
MSTP_Master_Node_FSM(&MSTP_Port);
|
||||
}
|
||||
|
||||
@@ -127,74 +125,70 @@ void dlmstp_millisecond_timer(void)
|
||||
{
|
||||
MSTP_Millisecond_Timer(&MSTP_Port);
|
||||
}
|
||||
|
||||
|
||||
/* returns the number of octets in the PDU, or zero on failure */
|
||||
/* This function is expecting to be polled. */
|
||||
uint16_t dlmstp_receive(BACNET_ADDRESS * src, /* source address */
|
||||
uint8_t * pdu, /* PDU data */
|
||||
uint16_t max_pdu, /* amount of space available in the PDU */
|
||||
unsigned timeout)
|
||||
{
|
||||
uint16_t pdu_len = 0;
|
||||
|
||||
{
|
||||
uint16_t pdu_len = 0;
|
||||
|
||||
(void) timeout;
|
||||
/* see if there is a packet available */
|
||||
if (Receive_Buffer.ready)
|
||||
{
|
||||
memmove(src, &Receive_Buffer.address, sizeof(Receive_Buffer.address));
|
||||
if (Receive_Buffer.ready) {
|
||||
memmove(src, &Receive_Buffer.address,
|
||||
sizeof(Receive_Buffer.address));
|
||||
pdu_len = Receive_Buffer.pdu_len;
|
||||
memmove(&pdu[0], &Receive_Buffer.pdu[0], max_pdu);
|
||||
Receive_Buffer.ready = false;
|
||||
Receive_Buffer.ready = false;
|
||||
}
|
||||
|
||||
return pdu_len;
|
||||
}
|
||||
|
||||
void dlmstp_fill_bacnet_address(BACNET_ADDRESS * src, uint8_t mstp_address)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
if (mstp_address == MSTP_BROADCAST_ADDRESS)
|
||||
{
|
||||
/* mac_len = 0 if broadcast address */
|
||||
src->mac_len = 0;
|
||||
src->mac[0] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
src->mac_len = 1;
|
||||
src->mac[0] = mstp_address;
|
||||
}
|
||||
/* fill with 0's starting with index 1; index 0 filled above */
|
||||
for (i = 1; i <MAX_MAC_LEN; i++) {
|
||||
src->mac[i] = 0;
|
||||
}
|
||||
src->net = 0;
|
||||
src->len = 0;
|
||||
for (i = 0; i < MAX_MAC_LEN; i++) {
|
||||
src->adr[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void dlmstp_fill_bacnet_address(BACNET_ADDRESS * src, uint8_t mstp_address)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
if (mstp_address == MSTP_BROADCAST_ADDRESS) {
|
||||
/* mac_len = 0 if broadcast address */
|
||||
src->mac_len = 0;
|
||||
src->mac[0] = 0;
|
||||
} else {
|
||||
src->mac_len = 1;
|
||||
src->mac[0] = mstp_address;
|
||||
}
|
||||
/* fill with 0's starting with index 1; index 0 filled above */
|
||||
for (i = 1; i < MAX_MAC_LEN; i++) {
|
||||
src->mac[i] = 0;
|
||||
}
|
||||
src->net = 0;
|
||||
src->len = 0;
|
||||
for (i = 0; i < MAX_MAC_LEN; i++) {
|
||||
src->adr[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* for the MS/TP state machine to use for putting received data */
|
||||
uint16_t dlmstp_put_receive(
|
||||
uint8_t src, /* source MS/TP address */
|
||||
uint16_t dlmstp_put_receive(uint8_t src, /* source MS/TP address */
|
||||
uint8_t * pdu, /* PDU data */
|
||||
uint16_t pdu_len)
|
||||
{
|
||||
if (Receive_Buffer.ready) {
|
||||
/* FIXME: what to do when we miss a message? */
|
||||
pdu_len = 0;
|
||||
} else if (pdu_len < sizeof(Receive_Buffer.pdu)) {
|
||||
dlmstp_fill_bacnet_address(&Receive_Buffer.address, src);
|
||||
{
|
||||
if (Receive_Buffer.ready) {
|
||||
/* FIXME: what to do when we miss a message? */
|
||||
pdu_len = 0;
|
||||
} else if (pdu_len < sizeof(Receive_Buffer.pdu)) {
|
||||
dlmstp_fill_bacnet_address(&Receive_Buffer.address, src);
|
||||
Receive_Buffer.pdu_len = pdu_len;
|
||||
memmove(Receive_Buffer.pdu, pdu, pdu_len);
|
||||
Receive_Buffer.ready = true;
|
||||
} else {
|
||||
/* FIXME: message too large? */
|
||||
pdu_len = 0;
|
||||
}
|
||||
|
||||
Receive_Buffer.ready = true;
|
||||
} else {
|
||||
/* FIXME: message too large? */
|
||||
pdu_len = 0;
|
||||
}
|
||||
|
||||
return pdu_len;
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ bool ethernet_init(char *interface_name)
|
||||
/* returns bytes sent on success, negative number on failure */
|
||||
int ethernet_send(BACNET_ADDRESS * dest, /* destination address */
|
||||
BACNET_ADDRESS * src, /* source address */
|
||||
BACNET_NPDU_DATA * npdu_data, /* network information */
|
||||
BACNET_NPDU_DATA * npdu_data, /* network information */
|
||||
uint8_t * pdu, /* any data to be sent - may be null */
|
||||
unsigned pdu_len)
|
||||
{ /* number of bytes of data */
|
||||
@@ -158,7 +158,7 @@ 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 */
|
||||
BACNET_NPDU_DATA * npdu_data, /* network information */
|
||||
BACNET_NPDU_DATA * npdu_data, /* network information */
|
||||
uint8_t * pdu, /* any data to be sent - may be null */
|
||||
unsigned pdu_len)
|
||||
{ /* number of bytes of data */
|
||||
@@ -169,14 +169,13 @@ int ethernet_send_pdu(BACNET_ADDRESS * dest, /* destination address */
|
||||
src.mac[i] = Ethernet_MAC_Address[i];
|
||||
src.mac_len++;
|
||||
}
|
||||
|
||||
|
||||
/* FIXME: npdu_data? */
|
||||
/* 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 */
|
||||
npdu_data,
|
||||
pdu, /* any data to be sent - may be null */
|
||||
npdu_data, pdu, /* any data to be sent - may be null */
|
||||
pdu_len); /* number of bytes of data */
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <conio.h> /* for kbhit */
|
||||
#include <conio.h> /* for kbhit */
|
||||
#include "config.h"
|
||||
#include "bacdef.h"
|
||||
#include "npdu.h"
|
||||
@@ -42,17 +42,17 @@
|
||||
/* RTOS-32 */
|
||||
#include "rtkernel.h"
|
||||
#if defined(RTK32_VER)
|
||||
#define _USER32_
|
||||
#define _KERNEL32_
|
||||
#include <windows.h>
|
||||
#include <rttarget.h> /* for RTCMOSSetSystemTime */
|
||||
#include <rtfiles.h> /* file system */
|
||||
#include <rtfsys.h> /* file system */
|
||||
#include <Rttbios.h>
|
||||
#define _USER32_
|
||||
#define _KERNEL32_
|
||||
#include <windows.h>
|
||||
#include <rttarget.h> /* for RTCMOSSetSystemTime */
|
||||
#include <rtfiles.h> /* file system */
|
||||
#include <rtfsys.h> /* file system */
|
||||
#include <Rttbios.h>
|
||||
#endif
|
||||
#include <rtcom.h> /* serial port driver */
|
||||
#include <itimer.h> /* time measurement & timer interrupt rate control */
|
||||
#include <rtkeybrd.h> /* interrupt handler for the keyboard */
|
||||
#include <rtcom.h> /* serial port driver */
|
||||
#include <itimer.h> /* time measurement & timer interrupt rate control */
|
||||
#include <rtkeybrd.h> /* interrupt handler for the keyboard */
|
||||
|
||||
/* buffers used for transmit and receive */
|
||||
static uint8_t Rx_Buf[MAX_MPDU] = { 0 };
|
||||
@@ -60,10 +60,12 @@ static uint8_t Rx_Buf[MAX_MPDU] = { 0 };
|
||||
static void Init_Service_Handlers(void)
|
||||
{
|
||||
/* 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_WHO_IS,
|
||||
handler_who_is);
|
||||
/* 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);
|
||||
apdu_set_unrecognized_service_handler_handler
|
||||
(handler_unrecognized_service);
|
||||
/* we must implement read property - it's required! */
|
||||
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY,
|
||||
handler_read_property);
|
||||
@@ -73,30 +75,28 @@ static void Init_Service_Handlers(void)
|
||||
|
||||
void millisecond_task(void)
|
||||
{
|
||||
Time ticks = 0; /* task cycle */
|
||||
int i = 0; /* loop counter */
|
||||
Time ticks = 0; /* task cycle */
|
||||
int i = 0; /* loop counter */
|
||||
|
||||
ticks = RTKGetTime() + MilliSecsToTicks(1);
|
||||
while (TRUE)
|
||||
{
|
||||
RTKDelayUntil(ticks);
|
||||
dlmstp_millisecond_timer();
|
||||
ticks += MilliSecsToTicks(1);
|
||||
}
|
||||
ticks = RTKGetTime() + MilliSecsToTicks(1);
|
||||
while (TRUE) {
|
||||
RTKDelayUntil(ticks);
|
||||
dlmstp_millisecond_timer();
|
||||
ticks += MilliSecsToTicks(1);
|
||||
}
|
||||
}
|
||||
|
||||
void RTOS_Initialize(void)
|
||||
{
|
||||
/* allow OS to setup IRQ 1 by using a dummy call */
|
||||
(void)kbhit();
|
||||
(void) kbhit();
|
||||
RTKernelInit(0); /* get the kernel going */
|
||||
RTKeybrdInit();
|
||||
//(void)CPUMoniInit(); /* not needed - just monitor idle task */
|
||||
RTComInit();
|
||||
ITimerInit();
|
||||
|
||||
if (RTCallDebugger(RT_DBG_MONITOR,0,0) != -1)
|
||||
{
|
||||
|
||||
if (RTCallDebugger(RT_DBG_MONITOR, 0, 0) != -1) {
|
||||
/* Win32 structured exception - if no handler is
|
||||
installed, TerminateProcess() will be called,
|
||||
which will reboot - a good thing in our case. */
|
||||
@@ -107,25 +107,25 @@ void RTOS_Initialize(void)
|
||||
RTRaiseCPUException(4); // Overflow INTO instruction.
|
||||
RTRaiseCPUException(5); // BOUND Range Exceeded BOUND instruction.
|
||||
RTRaiseCPUException(6); // Invalid Opcode (Undefined Opcode)
|
||||
// RTRaiseCPUException(7); // Device Not Available (No Math Coprocessor)
|
||||
// RTRaiseCPUException(7); // Device Not Available (No Math Coprocessor)
|
||||
RTRaiseCPUException(8); // Double Fault any exception instruction,NMI,INTR.
|
||||
RTRaiseCPUException(9); // Co-Processor overrun
|
||||
RTRaiseCPUException(10); // Invalid TSS Task switch or TSS access.
|
||||
RTRaiseCPUException(11); // Segment Not Present Loading segment registers
|
||||
RTRaiseCPUException(12); // Stack Seg Fault Stack ops /SS reg loads.
|
||||
RTRaiseCPUException(13); // General Protection Any memory reference
|
||||
RTRaiseCPUException(14); // Page Fault Any memory reference.
|
||||
RTRaiseCPUException(15); // reserved
|
||||
RTRaiseCPUException(16); // Floating-Point Error (Math Fault)
|
||||
RTRaiseCPUException(10); // Invalid TSS Task switch or TSS access.
|
||||
RTRaiseCPUException(11); // Segment Not Present Loading segment registers
|
||||
RTRaiseCPUException(12); // Stack Seg Fault Stack ops /SS reg loads.
|
||||
RTRaiseCPUException(13); // General Protection Any memory reference
|
||||
RTRaiseCPUException(14); // Page Fault Any memory reference.
|
||||
RTRaiseCPUException(15); // reserved
|
||||
RTRaiseCPUException(16); // Floating-Point Error (Math Fault)
|
||||
}
|
||||
/* setup 1ms timer tick */
|
||||
SetTimerIntVal(1000);
|
||||
/* per recommendation in manual */
|
||||
RTKDelay(1);
|
||||
RTCMOSSetSystemTime(); /* get the right time-of-day */
|
||||
|
||||
|
||||
/* create timer tick task */
|
||||
RTKCreateTask(millisecond_task,1,1024*8,"millisec task");
|
||||
RTKCreateTask(millisecond_task, 1, 1024 * 8, "millisec task");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@@ -138,7 +138,7 @@ int main(int argc, char *argv[])
|
||||
(void) argv;
|
||||
Device_Set_Object_Instance_Number(126);
|
||||
Init_Service_Handlers();
|
||||
RTOS_Initialize();
|
||||
RTOS_Initialize();
|
||||
/* init the physical layer */
|
||||
#ifdef BACDL_BIP
|
||||
if (!bip_init())
|
||||
@@ -166,7 +166,7 @@ int main(int argc, char *argv[])
|
||||
npdu_handler(&src, &Rx_Buf[0], pdu_len);
|
||||
}
|
||||
/* output */
|
||||
|
||||
|
||||
|
||||
|
||||
/* blink LEDs, Turn on or off outputs, etc */
|
||||
|
||||
@@ -66,9 +66,9 @@
|
||||
#define IN_CLASSC_HOST 0x000000ff
|
||||
|
||||
#define IN_CLASSD(i) (((long)(i) & 0xf0000000) == 0xe0000000)
|
||||
#define IN_CLASSD_NET 0xf0000000 /* These ones aren't really */
|
||||
#define IN_CLASSD_NSHIFT 28 /* net and host fields, but */
|
||||
#define IN_CLASSD_HOST 0x0fffffff /* routing needn't know. */
|
||||
#define IN_CLASSD_NET 0xf0000000 /* These ones aren't really */
|
||||
#define IN_CLASSD_NSHIFT 28 /* net and host fields, but */
|
||||
#define IN_CLASSD_HOST 0x0fffffff /* routing needn't know. */
|
||||
#define IN_MULTICAST(i) IN_CLASSD(i)
|
||||
|
||||
#else
|
||||
|
||||
@@ -158,8 +158,8 @@ void RS485_Send_Frame(volatile struct mstp_port_struct_t *mstp_port, /* port
|
||||
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 = 1; /* milliseconds to wait for a character */
|
||||
static Duration ticks = 0; /* duration to wait for data */
|
||||
unsigned timeout = 1; /* milliseconds to wait for a character */
|
||||
static Duration ticks = 0; /* duration to wait for data */
|
||||
|
||||
if (mstp_port->ReceiveError) {
|
||||
/* wait for state machine to clear this */
|
||||
@@ -167,8 +167,7 @@ void RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port)
|
||||
}
|
||||
/* wait for state machine to read from the DataRegister */
|
||||
else if (!mstp_port->DataAvailable) {
|
||||
if (!ticks)
|
||||
{
|
||||
if (!ticks) {
|
||||
ticks = MilliSecsToTicks(timeout);
|
||||
if (!ticks)
|
||||
ticks = 1;
|
||||
@@ -185,7 +184,6 @@ void RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port)
|
||||
mstp_port->DataAvailable = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
RTKScheduler();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user