Corrected rx_fsm MS/TP monitor demo.
This commit is contained in:
@@ -661,7 +661,7 @@ int main(int argc, char *argv[])
|
|||||||
nanosleep(&timeOut, &remains);
|
nanosleep(&timeOut, &remains);
|
||||||
#endif
|
#endif
|
||||||
bytes_received =
|
bytes_received =
|
||||||
dlmstp_receive(&src, &pdu[0], sizeof(pdu), 0);
|
dlmstp_receive(&src, &pdu[0], sizeof(pdu), 10000);
|
||||||
if (bytes_received) {
|
if (bytes_received) {
|
||||||
fprintf(stderr,"Received NPDU!\n");
|
fprintf(stderr,"Received NPDU!\n");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,13 +46,17 @@
|
|||||||
/* local includes */
|
/* local includes */
|
||||||
#include "bytes.h"
|
#include "bytes.h"
|
||||||
#include "rs485.h"
|
#include "rs485.h"
|
||||||
#include "mstp.h"
|
|
||||||
#include "crc.h"
|
#include "crc.h"
|
||||||
|
#include "mstp.h"
|
||||||
|
#include "mstptext.h"
|
||||||
|
|
||||||
#define INCREMENT_AND_LIMIT_UINT16(x) {if (x < 0xFFFF) x++;}
|
#define INCREMENT_AND_LIMIT_UINT16(x) {if (x < 0xFFFF) x++;}
|
||||||
|
|
||||||
/* local port data - shared with RS-485 */
|
/* local port data - shared with RS-485 */
|
||||||
volatile struct mstp_port_struct_t MSTP_Port;
|
static volatile struct mstp_port_struct_t MSTP_Port;
|
||||||
|
/* buffers needed by mstp port struct */
|
||||||
|
static uint8_t RxBuffer[MAX_MPDU];
|
||||||
|
static uint8_t TxBuffer[MAX_MPDU];
|
||||||
|
|
||||||
void *milliseconds_task(void *pArg)
|
void *milliseconds_task(void *pArg)
|
||||||
{
|
{
|
||||||
@@ -74,32 +78,61 @@ void dlmstp_millisecond_timer(void)
|
|||||||
INCREMENT_AND_LIMIT_UINT16(MSTP_Port.SilenceTimer);
|
INCREMENT_AND_LIMIT_UINT16(MSTP_Port.SilenceTimer);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t dlmstp_put_receive(
|
/* functions used by the MS/TP state machine to put or get data */
|
||||||
uint8_t src, /* source MS/TP address */
|
uint16_t MSTP_Put_Receive(
|
||||||
uint8_t * pdu, /* PDU data */
|
volatile struct mstp_port_struct_t *mstp_port)
|
||||||
uint16_t pdu_len)
|
|
||||||
{
|
{
|
||||||
(void)src;
|
(void)mstp_port;
|
||||||
(void)pdu;
|
|
||||||
(void)pdu_len;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t dlmstp_get_send(
|
/* for the MS/TP state machine to use for getting data to send */
|
||||||
uint8_t src, /* source MS/TP address for creating packet */
|
/* Return: amount of PDU data */
|
||||||
|
uint16_t MSTP_Get_Send(
|
||||||
|
uint8_t src, /* source MS/TP address for creating packet */
|
||||||
uint8_t * pdu, /* data to send */
|
uint8_t * pdu, /* data to send */
|
||||||
uint16_t max_pdu, /* amount of space available */
|
uint16_t max_pdu, /* amount of space available */
|
||||||
unsigned timeout) /* milliseconds to wait for a packet */
|
unsigned timeout) /* milliseconds to wait for a packet */
|
||||||
{
|
{
|
||||||
|
(void)src;
|
||||||
|
(void)pdu;
|
||||||
|
(void)max_pdu;
|
||||||
|
(void)timeout;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* returns a delta timestamp */
|
||||||
|
int timestamp_ms(void)
|
||||||
|
{
|
||||||
|
struct timeval tv;
|
||||||
|
int delta_ticks = 0;
|
||||||
|
long ticks = 0;
|
||||||
|
static long last_ticks = 0;
|
||||||
|
int rv = 0;
|
||||||
|
|
||||||
|
rv = gettimeofday(&tv,NULL);
|
||||||
|
if (rv == -1)
|
||||||
|
ticks = 0;
|
||||||
|
else
|
||||||
|
ticks = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
|
||||||
|
|
||||||
|
delta_ticks = ticks - last_ticks;
|
||||||
|
last_ticks = ticks;
|
||||||
|
|
||||||
|
return delta_ticks;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *Network_Interface = NULL;
|
||||||
|
|
||||||
static void print_received_packet(
|
static void print_received_packet(
|
||||||
volatile struct mstp_port_struct_t *mstp_port)
|
volatile struct mstp_port_struct_t *mstp_port)
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i = 0;
|
||||||
|
int timestamp = 0;
|
||||||
|
|
||||||
|
timestamp = timestamp_ms();
|
||||||
|
fprintf(stderr,"%03d ",timestamp);
|
||||||
/* Preamble: two octet preamble: X`55', X`FF' */
|
/* Preamble: two octet preamble: X`55', X`FF' */
|
||||||
/* Frame Type: one octet */
|
/* Frame Type: one octet */
|
||||||
/* Destination Address: one octet address */
|
/* Destination Address: one octet address */
|
||||||
@@ -128,6 +161,8 @@ static void print_received_packet(
|
|||||||
mstp_port->DataCRCActualMSB,
|
mstp_port->DataCRCActualMSB,
|
||||||
mstp_port->DataCRCActualLSB);
|
mstp_port->DataCRCActualLSB);
|
||||||
}
|
}
|
||||||
|
fprintf(stderr,"%s",
|
||||||
|
mstptext_frame_type(mstp_port->FrameType));
|
||||||
fprintf(stderr,"\n");
|
fprintf(stderr,"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,9 +177,12 @@ int main(void)
|
|||||||
/* mimic our pointer in the state machine */
|
/* mimic our pointer in the state machine */
|
||||||
mstp_port = &MSTP_Port;
|
mstp_port = &MSTP_Port;
|
||||||
/* initialize our interface */
|
/* initialize our interface */
|
||||||
RS485_Set_Interface("/dev/ttyS0");
|
|
||||||
RS485_Set_Baud_Rate(38400);
|
RS485_Set_Baud_Rate(38400);
|
||||||
RS485_Initialize();
|
RS485_Initialize();
|
||||||
|
MSTP_Port.InputBuffer = &RxBuffer[0];
|
||||||
|
MSTP_Port.InputBufferSize = sizeof(RxBuffer);
|
||||||
|
MSTP_Port.OutputBuffer = &TxBuffer[0];
|
||||||
|
MSTP_Port.OutputBufferSize = sizeof(TxBuffer);
|
||||||
MSTP_Init(mstp_port);
|
MSTP_Init(mstp_port);
|
||||||
mstp_port->Lurking = true;
|
mstp_port->Lurking = true;
|
||||||
/* start our MilliSec task */
|
/* start our MilliSec task */
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g
|
|||||||
|
|
||||||
SRCS = rs485.c \
|
SRCS = rs485.c \
|
||||||
rx_fsm.c \
|
rx_fsm.c \
|
||||||
mstp.c \
|
../../mstp.c \
|
||||||
|
../../mstptext.c \
|
||||||
|
../../indtext.c \
|
||||||
../../crc.c
|
../../crc.c
|
||||||
|
|
||||||
OBJS = ${SRCS:.c=.o}
|
OBJS = ${SRCS:.c=.o}
|
||||||
|
|||||||
@@ -335,7 +335,7 @@ void RS485_Check_UART_Data(struct mstp_port_struct_t *mstp_port)
|
|||||||
#ifdef TEST_RS485
|
#ifdef TEST_RS485
|
||||||
static void test_transmit_task(void *pArg)
|
static void test_transmit_task(void *pArg)
|
||||||
{
|
{
|
||||||
char *TxBuf = "BACnet MS/TP";
|
char *TxBuf = "BACnet MS/TP";
|
||||||
size_t len = strlen(TxBuf)+1;
|
size_t len = strlen(TxBuf)+1;
|
||||||
|
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
|
|||||||
Reference in New Issue
Block a user