Updated dlmstp project on Win32. Added rx_fsm.mak for Borland.
This commit is contained in:
@@ -45,6 +45,7 @@
|
|||||||
#include "dlmstp.h"
|
#include "dlmstp.h"
|
||||||
#include "rs485.h"
|
#include "rs485.h"
|
||||||
#include "npdu.h"
|
#include "npdu.h"
|
||||||
|
#include "bits.h"
|
||||||
|
|
||||||
/* Number of MS/TP Packets Rx/Tx */
|
/* Number of MS/TP Packets Rx/Tx */
|
||||||
uint16_t MSTP_Packets = 0;
|
uint16_t MSTP_Packets = 0;
|
||||||
@@ -281,7 +282,7 @@ uint16_t MSTP_Put_Receive(
|
|||||||
mstp_port->SourceAddress);
|
mstp_port->SourceAddress);
|
||||||
packet.pdu_len = pdu_len;
|
packet.pdu_len = pdu_len;
|
||||||
/* ready is not used in this scheme */
|
/* ready is not used in this scheme */
|
||||||
packet.ready = true;
|
packet.ready = true;
|
||||||
write(Receive_Server_SockFD, &packet, sizeof(packet));
|
write(Receive_Server_SockFD, &packet, sizeof(packet));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -371,7 +372,7 @@ uint16_t MSTP_Get_Send(
|
|||||||
&mstp_port->OutputBuffer[0], /* <-- loading this */
|
&mstp_port->OutputBuffer[0], /* <-- loading this */
|
||||||
mstp_port->OutputBufferSize,
|
mstp_port->OutputBufferSize,
|
||||||
packet.frame_type,
|
packet.frame_type,
|
||||||
destination,
|
destination,
|
||||||
mstp_port->This_Station,
|
mstp_port->This_Station,
|
||||||
&packet.pdu[0],
|
&packet.pdu[0],
|
||||||
packet.pdu_len);
|
packet.pdu_len);
|
||||||
@@ -399,7 +400,7 @@ bool dlmstp_same_bacnet_address(BACNET_ADDRESS * dest, BACNET_ADDRESS * src)
|
|||||||
if (dest->adr[i] != src->adr[i])
|
if (dest->adr[i] != src->adr[i])
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -412,8 +413,8 @@ bool dlmstp_compare_data_expecting_reply(
|
|||||||
BACNET_ADDRESS *dest_address)
|
BACNET_ADDRESS *dest_address)
|
||||||
{
|
{
|
||||||
uint16_t offset;
|
uint16_t offset;
|
||||||
/* One way to check the message is to compare NPDU
|
/* One way to check the message is to compare NPDU
|
||||||
src, dest, along with the APDU type, invoke id.
|
src, dest, along with the APDU type, invoke id.
|
||||||
Seems a bit overkill */
|
Seems a bit overkill */
|
||||||
struct DER_compare_t {
|
struct DER_compare_t {
|
||||||
BACNET_NPDU_DATA npdu_data;
|
BACNET_NPDU_DATA npdu_data;
|
||||||
@@ -428,7 +429,7 @@ bool dlmstp_compare_data_expecting_reply(
|
|||||||
/* decode the request data */
|
/* decode the request data */
|
||||||
request.address.mac[0] = src_address;
|
request.address.mac[0] = src_address;
|
||||||
request.address.mac_len = 1;
|
request.address.mac_len = 1;
|
||||||
offset = npdu_decode(&request_pdu[0],
|
offset = npdu_decode(&request_pdu[0],
|
||||||
NULL, &request.address, &request.npdu_data);
|
NULL, &request.address, &request.npdu_data);
|
||||||
if (request.npdu_data.network_layer_message) {
|
if (request.npdu_data.network_layer_message) {
|
||||||
return false;
|
return false;
|
||||||
@@ -445,12 +446,12 @@ bool dlmstp_compare_data_expecting_reply(
|
|||||||
request.service_choice = request_pdu[offset+3];
|
request.service_choice = request_pdu[offset+3];
|
||||||
/* decode the reply data */
|
/* decode the reply data */
|
||||||
dlmstp_copy_bacnet_address(&reply.address, dest_address);
|
dlmstp_copy_bacnet_address(&reply.address, dest_address);
|
||||||
offset = npdu_decode(&reply_pdu[0],
|
offset = npdu_decode(&reply_pdu[0],
|
||||||
&reply.address, NULL, &reply.npdu_data);
|
&reply.address, NULL, &reply.npdu_data);
|
||||||
if (reply.npdu_data.network_layer_message) {
|
if (reply.npdu_data.network_layer_message) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
/* reply could be a lot of things:
|
/* reply could be a lot of things:
|
||||||
confirmed, simple ack, abort, reject, error */
|
confirmed, simple ack, abort, reject, error */
|
||||||
reply.pdu_type = reply_pdu[offset] & 0xF0;
|
reply.pdu_type = reply_pdu[offset] & 0xF0;
|
||||||
switch (reply.pdu_type) {
|
switch (reply.pdu_type) {
|
||||||
@@ -508,7 +509,7 @@ bool dlmstp_compare_data_expecting_reply(
|
|||||||
if (!dlmstp_same_bacnet_address(&request.address, &reply.address)) {
|
if (!dlmstp_same_bacnet_address(&request.address, &reply.address)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
#include "dlmstp.h"
|
#include "dlmstp.h"
|
||||||
#include "rs485.h"
|
#include "rs485.h"
|
||||||
#include "npdu.h"
|
#include "npdu.h"
|
||||||
|
#include "bits.h"
|
||||||
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#define STRICT 1
|
#define STRICT 1
|
||||||
@@ -113,12 +114,11 @@ int dlmstp_send_pdu(BACNET_ADDRESS * dest, /* destination address */
|
|||||||
unsigned pdu_len)
|
unsigned pdu_len)
|
||||||
{ /* number of bytes of data */
|
{ /* number of bytes of data */
|
||||||
int bytes_sent = 0;
|
int bytes_sent = 0;
|
||||||
uint8_t destination = 0; /* destination address */
|
|
||||||
unsigned i = 0;
|
unsigned i = 0;
|
||||||
|
|
||||||
if (!Transmit_Packet.ready) {
|
if (!Transmit_Packet.ready) {
|
||||||
if (npdu_data->data_expecting_reply) {
|
if (npdu_data->data_expecting_reply) {
|
||||||
Transmit_Packet.frame_type =
|
Transmit_Packet.frame_type =
|
||||||
FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY;
|
FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY;
|
||||||
} else {
|
} else {
|
||||||
Transmit_Packet.frame_type =
|
Transmit_Packet.frame_type =
|
||||||
@@ -308,7 +308,7 @@ uint16_t MSTP_Get_Send(
|
|||||||
&mstp_port->OutputBuffer[0], /* <-- loading this */
|
&mstp_port->OutputBuffer[0], /* <-- loading this */
|
||||||
mstp_port->OutputBufferSize,
|
mstp_port->OutputBufferSize,
|
||||||
Transmit_Packet.frame_type,
|
Transmit_Packet.frame_type,
|
||||||
destination,
|
destination,
|
||||||
mstp_port->This_Station,
|
mstp_port->This_Station,
|
||||||
&Transmit_Packet.pdu[0],
|
&Transmit_Packet.pdu[0],
|
||||||
Transmit_Packet.pdu_len);
|
Transmit_Packet.pdu_len);
|
||||||
@@ -337,7 +337,7 @@ bool dlmstp_same_bacnet_address(BACNET_ADDRESS * dest, BACNET_ADDRESS * src)
|
|||||||
if (dest->adr[i] != src->adr[i])
|
if (dest->adr[i] != src->adr[i])
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -350,8 +350,8 @@ bool dlmstp_compare_data_expecting_reply(
|
|||||||
BACNET_ADDRESS *dest_address)
|
BACNET_ADDRESS *dest_address)
|
||||||
{
|
{
|
||||||
uint16_t offset;
|
uint16_t offset;
|
||||||
/* One way to check the message is to compare NPDU
|
/* One way to check the message is to compare NPDU
|
||||||
src, dest, along with the APDU type, invoke id.
|
src, dest, along with the APDU type, invoke id.
|
||||||
Seems a bit overkill */
|
Seems a bit overkill */
|
||||||
struct DER_compare_t {
|
struct DER_compare_t {
|
||||||
BACNET_NPDU_DATA npdu_data;
|
BACNET_NPDU_DATA npdu_data;
|
||||||
@@ -366,7 +366,7 @@ bool dlmstp_compare_data_expecting_reply(
|
|||||||
/* decode the request data */
|
/* decode the request data */
|
||||||
request.address.mac[0] = src_address;
|
request.address.mac[0] = src_address;
|
||||||
request.address.mac_len = 1;
|
request.address.mac_len = 1;
|
||||||
offset = npdu_decode(&request_pdu[0],
|
offset = npdu_decode(&request_pdu[0],
|
||||||
NULL, &request.address, &request.npdu_data);
|
NULL, &request.address, &request.npdu_data);
|
||||||
if (request.npdu_data.network_layer_message) {
|
if (request.npdu_data.network_layer_message) {
|
||||||
return false;
|
return false;
|
||||||
@@ -383,12 +383,12 @@ bool dlmstp_compare_data_expecting_reply(
|
|||||||
request.service_choice = request_pdu[offset+3];
|
request.service_choice = request_pdu[offset+3];
|
||||||
/* decode the reply data */
|
/* decode the reply data */
|
||||||
dlmstp_copy_bacnet_address(&reply.address, dest_address);
|
dlmstp_copy_bacnet_address(&reply.address, dest_address);
|
||||||
offset = npdu_decode(&reply_pdu[0],
|
offset = npdu_decode(&reply_pdu[0],
|
||||||
&reply.address, NULL, &reply.npdu_data);
|
&reply.address, NULL, &reply.npdu_data);
|
||||||
if (reply.npdu_data.network_layer_message) {
|
if (reply.npdu_data.network_layer_message) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
/* reply could be a lot of things:
|
/* reply could be a lot of things:
|
||||||
confirmed, simple ack, abort, reject, error */
|
confirmed, simple ack, abort, reject, error */
|
||||||
reply.pdu_type = reply_pdu[offset] & 0xF0;
|
reply.pdu_type = reply_pdu[offset] & 0xF0;
|
||||||
switch (reply.pdu_type) {
|
switch (reply.pdu_type) {
|
||||||
@@ -446,7 +446,7 @@ bool dlmstp_compare_data_expecting_reply(
|
|||||||
if (!dlmstp_same_bacnet_address(&request.address, &reply.address)) {
|
if (!dlmstp_same_bacnet_address(&request.address, &reply.address)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -700,6 +700,16 @@ bool dlmstp_init(char *ifname)
|
|||||||
|
|
||||||
#ifdef TEST_DLMSTP
|
#ifdef TEST_DLMSTP
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
void apdu_handler(BACNET_ADDRESS * src, /* source address */
|
||||||
|
uint8_t * apdu, /* APDU data */
|
||||||
|
uint16_t pdu_len) /* for confirmed messages */
|
||||||
|
{
|
||||||
|
(void)src;
|
||||||
|
(void)apdu;
|
||||||
|
(void)pdu_len;
|
||||||
|
}
|
||||||
|
|
||||||
/* returns a delta timestamp */
|
/* returns a delta timestamp */
|
||||||
uint32_t timestamp_ms(void)
|
uint32_t timestamp_ms(void)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,11 +3,12 @@
|
|||||||
<FileVersion major="1" minor="6" />
|
<FileVersion major="1" minor="6" />
|
||||||
<Project>
|
<Project>
|
||||||
<Option title="dlmstp" />
|
<Option title="dlmstp" />
|
||||||
|
<Option makefile="makefile" />
|
||||||
<Option pch_mode="2" />
|
<Option pch_mode="2" />
|
||||||
<Option compiler="gcc" />
|
<Option compiler="gcc" />
|
||||||
<Build>
|
<Build>
|
||||||
<Target title="Debug">
|
<Target title="Debug">
|
||||||
<Option output="bin\Debug\dlmstp.exe" prefix_auto="1" extension_auto="1" />
|
<Option output="bin\Debug\dlmstp" prefix_auto="1" extension_auto="1" />
|
||||||
<Option object_output="obj\Debug\" />
|
<Option object_output="obj\Debug\" />
|
||||||
<Option type="1" />
|
<Option type="1" />
|
||||||
<Option compiler="gcc" />
|
<Option compiler="gcc" />
|
||||||
@@ -16,7 +17,7 @@
|
|||||||
</Compiler>
|
</Compiler>
|
||||||
</Target>
|
</Target>
|
||||||
<Target title="Release">
|
<Target title="Release">
|
||||||
<Option output="bin\Release\dlmstp.exe" prefix_auto="1" extension_auto="1" />
|
<Option output="bin\Release\dlmstp" prefix_auto="1" extension_auto="1" />
|
||||||
<Option object_output="obj\Release\" />
|
<Option object_output="obj\Release\" />
|
||||||
<Option type="1" />
|
<Option type="1" />
|
||||||
<Option compiler="gcc" />
|
<Option compiler="gcc" />
|
||||||
@@ -43,6 +44,10 @@
|
|||||||
<Add directory="..\..\demo\object" />
|
<Add directory="..\..\demo\object" />
|
||||||
</Compiler>
|
</Compiler>
|
||||||
<Unit filename="..\..\bacdef.h" />
|
<Unit filename="..\..\bacdef.h" />
|
||||||
|
<Unit filename="..\..\bacint.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="..\..\bacint.h" />
|
||||||
<Unit filename="..\..\crc.c">
|
<Unit filename="..\..\crc.c">
|
||||||
<Option compilerVar="CC" />
|
<Option compilerVar="CC" />
|
||||||
</Unit>
|
</Unit>
|
||||||
@@ -61,6 +66,9 @@
|
|||||||
<Option compilerVar="CC" />
|
<Option compilerVar="CC" />
|
||||||
</Unit>
|
</Unit>
|
||||||
<Unit filename="..\..\mstptext.h" />
|
<Unit filename="..\..\mstptext.h" />
|
||||||
|
<Unit filename="..\..\npdu.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
<Unit filename="..\..\npdu.h" />
|
<Unit filename="..\..\npdu.h" />
|
||||||
<Unit filename="dlmstp.c">
|
<Unit filename="dlmstp.c">
|
||||||
<Option compilerVar="CC" />
|
<Option compilerVar="CC" />
|
||||||
@@ -72,6 +80,7 @@
|
|||||||
<Extensions>
|
<Extensions>
|
||||||
<code_completion />
|
<code_completion />
|
||||||
<envvars />
|
<envvars />
|
||||||
|
<debugger />
|
||||||
</Extensions>
|
</Extensions>
|
||||||
</Project>
|
</Project>
|
||||||
</CodeBlocks_project_file>
|
</CodeBlocks_project_file>
|
||||||
|
|||||||
@@ -0,0 +1,113 @@
|
|||||||
|
#
|
||||||
|
# Simple makefile to build an executable for Win32 console
|
||||||
|
#
|
||||||
|
# This makefile assumes Borland development environment
|
||||||
|
# on Windows NT/9x/2000/XP
|
||||||
|
# Tools: bcc32, make, ilink
|
||||||
|
|
||||||
|
!ifndef BORLAND_DIR
|
||||||
|
BORLAND_DIR_Not_Defined:
|
||||||
|
@echo .
|
||||||
|
@echo You must define environment variable BORLAND_DIR to compile.
|
||||||
|
!endif
|
||||||
|
|
||||||
|
PRODUCT = rx_fsm
|
||||||
|
PRODUCT_EXE = $(PRODUCT).exe
|
||||||
|
|
||||||
|
# Choose the Data Link Layer to Enable
|
||||||
|
DEFINES = -DBACDL_MSTP
|
||||||
|
|
||||||
|
SRCS = rs485.c \
|
||||||
|
rx_fsm.c \
|
||||||
|
..\..\mstp.c \
|
||||||
|
..\..\mstptext.c \
|
||||||
|
..\..\indtext.c \
|
||||||
|
..\..\crc.c
|
||||||
|
|
||||||
|
OBJS = $(SRCS:.c=.obj)
|
||||||
|
|
||||||
|
# Compiler definitions
|
||||||
|
#
|
||||||
|
BCC_CFG = bcc32.cfg
|
||||||
|
CC = $(BORLAND_DIR)\bin\bcc32 +$(BCC_CFG)
|
||||||
|
#LINK = $(BORLAND_DIR)\bin\tlink32
|
||||||
|
LINK = $(BORLAND_DIR)\bin\ilink32
|
||||||
|
TLIB = $(BORLAND_DIR)\bin\tlib
|
||||||
|
|
||||||
|
#
|
||||||
|
# Include directories
|
||||||
|
#
|
||||||
|
CC_DIR = $(BORLAND_DIR)\BIN
|
||||||
|
BACNET_INCL = ..\..\;..\..\demo\handler\;..\..\demo\object\;.
|
||||||
|
INCL_DIRS = -I$(BORLAND_DIR)\include;$(BACNET_INCL)
|
||||||
|
|
||||||
|
CFLAGS = $(INCL_DIRS) $(CS_FLAGS) $(DEFINES)
|
||||||
|
|
||||||
|
# Libraries
|
||||||
|
#
|
||||||
|
C_LIB_DIR = $(BORLAND_DIR)\lib
|
||||||
|
|
||||||
|
LIBS = $(C_LIB_DIR)\IMPORT32.lib \
|
||||||
|
$(C_LIB_DIR)\CW32MT.lib
|
||||||
|
|
||||||
|
#
|
||||||
|
# Main target
|
||||||
|
#
|
||||||
|
# This should be the first one in the makefile
|
||||||
|
|
||||||
|
all : $(BCC_CFG) $(PRODUCT_EXE)
|
||||||
|
|
||||||
|
# Linker specific: the link below is for BCC linker/compiler. If you link
|
||||||
|
# with a different linker - please change accordingly.
|
||||||
|
#
|
||||||
|
|
||||||
|
# need a temp response file (@&&) because command line is too long
|
||||||
|
$(PRODUCT_EXE) : $(OBJS)
|
||||||
|
@echo Running Linker for $(PRODUCT_EXE)
|
||||||
|
$(LINK) -L$(C_LIB_DIR) -m -c -s -v @&&| # temp response file, starts with |
|
||||||
|
$(BORLAND_DIR)\lib\c0x32.obj $** # $** lists each dependency
|
||||||
|
$<
|
||||||
|
$*.map
|
||||||
|
$(LIBS)
|
||||||
|
| # end of temp response file
|
||||||
|
|
||||||
|
#
|
||||||
|
# Utilities
|
||||||
|
|
||||||
|
clean :
|
||||||
|
@echo Deleting obj files, $(PRODUCT_EXE) and map files.
|
||||||
|
del $(OBJS)
|
||||||
|
del $(PRODUCT_EXE)
|
||||||
|
del *.map
|
||||||
|
del $(BCC_CFG)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Generic rules
|
||||||
|
#
|
||||||
|
.SUFFIXES: .cpp .c .sbr .obj
|
||||||
|
|
||||||
|
#
|
||||||
|
# cc generic rule
|
||||||
|
#
|
||||||
|
.c.obj:
|
||||||
|
$(CC) -o$@ $<
|
||||||
|
|
||||||
|
# Compiler configuration file
|
||||||
|
$(BCC_CFG) :
|
||||||
|
Copy &&|
|
||||||
|
$(CFLAGS)
|
||||||
|
-c
|
||||||
|
-y #include line numbers in OBJ's
|
||||||
|
-v #include debug info
|
||||||
|
-w+ #turn on all warnings
|
||||||
|
-Od #disable all optimizations
|
||||||
|
#-a4 #32 bit data alignment
|
||||||
|
#-M # generate link map
|
||||||
|
#-ls # linker options
|
||||||
|
#-WM- #not multithread
|
||||||
|
-WM #multithread
|
||||||
|
-w-aus # ignore warning assigned a value that is never used
|
||||||
|
-w-sig # ignore warning conversion may lose sig digits
|
||||||
|
| $@
|
||||||
|
|
||||||
|
# EOF: makefile
|
||||||
Reference in New Issue
Block a user