Skip to content

Commit f6e78e4

Browse files
authored
Mac support (#8)
Support for OSX
1 parent 3d44e56 commit f6e78e4

18 files changed

Lines changed: 219 additions & 17 deletions

File tree

.github/workflows/build.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Build
2+
3+
on: [push, pull_request]
4+
5+
6+
jobs:
7+
build_wheels:
8+
name: Build wheels on ${{ matrix.os }}
9+
runs-on: ${{ matrix.os }}
10+
strategy:
11+
matrix:
12+
os: [ubuntu-18.04, macos-latest]
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
17+
- uses: actions/setup-python@v2
18+
name: Install Python
19+
with:
20+
python-version: '3.7'
21+
22+
- name: Install cibuildwheel
23+
run: |
24+
python -m pip install cibuildwheel==1.7.2
25+
26+
- name: Build wheels
27+
run: |
28+
python -m cibuildwheel --output-dir wheelhouse
29+
env:
30+
CIBW_SKIP: "cp35-* cp37-* cp38-* cp39-* pp*-*"
31+
32+
- uses: actions/upload-artifact@v2
33+
with:
34+
path: ./wheelhouse/*.whl

misty/bacnet-stack-0.8.4/Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,16 @@ DEFINES += $(MAKE_DEFINE)
4040
# BACnet Ports Directory
4141
BACNET_PORT ?= linux
4242

43+
ADDL_WARN_FLAGS =
44+
UNAME := $(shell uname)
45+
ifeq ($(UNAME), Darwin)
46+
ADDL_WARN_FLAGS = -Wno-self-assign
47+
endif
48+
4349
# Default compiler settings
4450
OPTIMIZATION = -Os
4551
DEBUGGING =
46-
WARNINGS = -Wall -Wmissing-prototypes
52+
WARNINGS = -Wall $(ADDL_WARN_FLAGS)
4753
ifeq (${BUILD},debug)
4854
OPTIMIZATION = -O0
4955
DEBUGGING = -g -DDEBUG_ENABLED=1

misty/bacnet-stack-0.8.4/demo/Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,17 @@ INCLUDE1 = -I$(BACNET_PORT_DIR) -I$(BACNET_OBJECT) -I$(BACNET_HANDLER)
2222
INCLUDE2 = -I$(BACNET_INCLUDE)
2323
INCLUDES = $(INCLUDE1) $(INCLUDE2)
2424
BACNET_LIB=-L$(BACNET_LIB_DIR),-l$(BACNET_LIB_NAME)
25+
26+
ADDL_WARN_FLAGS =
27+
UNAME := $(shell uname)
28+
ifeq ($(UNAME), Darwin)
29+
ADDL_WARN_FLAGS = -Wno-self-assign
30+
endif
31+
2532
ifeq (${BACNET_PORT},linux)
2633
PFLAGS = -pthread
2734
TARGET_EXT =
28-
SYSTEM_LIB=-lc,-lgcc,-lrt,-lm
35+
SYSTEM_LIB=-lc,-lm
2936
endif
3037
ifeq (${BACNET_PORT},bsd)
3138
PFLAGS = -pthread
@@ -45,7 +52,7 @@ OPTIMIZATION = -O0
4552
DEBUGGING = -g -DDEBUG_ENABLED=1
4653
endif
4754
# put all the flags together
48-
CFLAGS := -Wall $(DEBUGGING) $(OPTIMIZATION) $(INCLUDES) $(DEFINES)
55+
CFLAGS := -Wall $(ADDL_WARN_FLAGS) $(DEBUGGING) $(OPTIMIZATION) $(INCLUDES) $(DEFINES)
4956
LFLAGS := -Wl,$(BACNET_LIB),$(SYSTEM_LIB)
5057

5158
.EXPORT_ALL_VARIABLES:

misty/bacnet-stack-0.8.4/demo/mstpcap/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,8 +1228,8 @@ int main(
12281228
}
12291229
if (!Wireshark_Capture) {
12301230
if (!(packet_count % 100)) {
1231-
fprintf(stdout, "\r%hu packets, %hu invalid frames", packet_count,
1232-
Invalid_Frame_Count);
1231+
fprintf(stdout, "\r%hu packets, %hu invalid frames", (unsigned short)packet_count,
1232+
(unsigned short)Invalid_Frame_Count);
12331233
}
12341234
if (packet_count >= 65535) {
12351235
packet_statistics_print();

misty/bacnet-stack-0.8.4/demo/whois/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ static void print_address_cache(
288288
} else {
289289
print_macaddr(&local_sadr, 1);
290290
}
291-
printf(" %-4hu ", addr->max_apdu);
291+
printf(" %-4hu ", (unsigned short)addr->max_apdu);
292292
printf("\n");
293293

294294
addr = addr->next;

misty/bacnet-stack-0.8.4/include/debug.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,7 @@ extern "C" {
5454
#ifdef __cplusplus
5555
}
5656
#endif /* __cplusplus */
57+
void enable_debug_flag(char *fname);
58+
void status_debug_flag(void);
59+
void disable_debug_flag(void);
5760
#endif

misty/bacnet-stack-0.8.4/ports/linux/dlmstp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ void dlmstp_get_broadcast_address(
671671
bool dlmstp_init(
672672
char *ifname)
673673
{
674-
unsigned long hThread = 0;
674+
pthread_t hThread = 0;
675675
int rv = 0;
676676

677677
/* initialize PDU queue */

misty/bacnet-stack-0.8.4/ports/linux/dlmstp_linux.c

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
/* OS Specific include */
4141
#include "net.h"
4242
#include "ringbuf.h"
43+
#ifdef __APPLE__
44+
#include <dispatch/dispatch.h>
45+
#endif
4346

4447
/** @file linux/dlmstp.c Provides Linux-specific DataLink functions for MS/TP. */
4548

@@ -123,7 +126,12 @@ void dlmstp_cleanup(
123126
close(poSharedData->RS485_Handle);
124127

125128
pthread_cond_destroy(&poSharedData->Received_Frame_Flag);
129+
#ifdef __APPLE__
130+
dispatch_release(poSharedData->Receive_Packet_Flag);
131+
#endif
132+
#ifdef __linux__
126133
sem_destroy(&poSharedData->Receive_Packet_Flag);
134+
#endif
127135
pthread_cond_destroy(&poSharedData->Master_Done_Flag);
128136
pthread_mutex_destroy(&poSharedData->Received_Frame_Mutex);
129137
pthread_mutex_destroy(&poSharedData->Master_Done_Mutex);
@@ -175,7 +183,12 @@ uint16_t dlmstp_receive(
175183
unsigned timeout)
176184
{ /* milliseconds to wait for a packet */
177185
uint16_t pdu_len = 0;
186+
#ifdef __APPLE__
187+
dispatch_time_t dis_time;
188+
#endif
189+
#ifdef __linux__
178190
struct timespec abstime;
191+
#endif
179192
int rv = 0;
180193
SHARED_MSTP_DATA *poSharedData;
181194
struct mstp_port_struct_t *mstp_port =
@@ -190,8 +203,14 @@ uint16_t dlmstp_receive(
190203
(void) max_pdu;
191204
/* see if there is a packet available, and a place
192205
to put the reply (if necessary) and process it */
206+
#ifdef __APPLE__
207+
dis_time = dispatch_time(DISPATCH_TIME_NOW, timeout*1000000);
208+
rv = dispatch_semaphore_wait(poSharedData->Receive_Packet_Flag, dis_time);
209+
#endif
210+
#ifdef __linux__
193211
get_abstime(&abstime, timeout);
194212
rv = sem_timedwait(&poSharedData->Receive_Packet_Flag, &abstime);
213+
#endif
195214
if (rv == 0) {
196215
if (poSharedData->Receive_Packet.ready) {
197216
if (poSharedData->Receive_Packet.pdu_len) {
@@ -356,7 +375,12 @@ uint16_t MSTP_Put_Receive(
356375
mstp_port->SourceAddress);
357376
poSharedData->Receive_Packet.pdu_len = mstp_port->DataLength;
358377
poSharedData->Receive_Packet.ready = true;
378+
#ifdef __APPLE__
379+
dispatch_semaphore_signal(poSharedData->Receive_Packet_Flag);
380+
#endif
381+
#ifdef __linux__
359382
sem_post(&poSharedData->Receive_Packet_Flag);
383+
#endif
360384
}
361385

362386
return pdu_len;
@@ -870,7 +894,7 @@ bool dlmstp_init(
870894
void *poPort,
871895
char *ifname)
872896
{
873-
unsigned long hThread = 0;
897+
pthread_t hThread;
874898
int rv = 0;
875899
SHARED_MSTP_DATA *poSharedData;
876900
struct mstp_port_struct_t *mstp_port =
@@ -894,15 +918,19 @@ bool dlmstp_init(
894918
/* initialize packet queue */
895919
poSharedData->Receive_Packet.ready = false;
896920
poSharedData->Receive_Packet.pdu_len = 0;
921+
#ifdef __APPLE__
922+
poSharedData->Receive_Packet_Flag = dispatch_semaphore_create(0);
923+
#endif
924+
#ifdef __linux__
897925
rv = sem_init(&poSharedData->Receive_Packet_Flag, 0, 0);
926+
#endif
898927
if (rv != 0) {
899928
fprintf(stderr,
900929
"MS/TP Interface: %s\n cannot allocate PThread Condition.\n",
901930
ifname);
902931
exit(1);
903932
}
904933

905-
struct termios newtio;
906934
printf("RS485: Initializing %s", poSharedData->RS485_Port_Name);
907935
/*
908936
Open device for reading and writing.
@@ -922,6 +950,36 @@ bool dlmstp_init(
922950
/* efficient blocking for the read */
923951
fcntl(poSharedData->RS485_Handle, F_SETFL, 0);
924952
#endif
953+
954+
#ifdef __APPLE__
955+
struct termios options;
956+
957+
tcgetattr(poSharedData->RS485_Handle, &options);
958+
cfsetispeed(&options, poSharedData->RS485_Baud);
959+
cfsetospeed(&options, poSharedData->RS485_Baud);
960+
961+
//No parity 8N1
962+
options.c_cflag &= ~PARENB;
963+
options.c_cflag &= ~CSTOPB;
964+
options.c_cflag &= ~CSIZE;
965+
options.c_cflag |= CS8;
966+
967+
//No flow control
968+
options.c_cflag &= ~CRTSCTS;
969+
970+
//Turn off s/w flow control
971+
options.c_iflag &= ~(IXON | IXOFF | IXANY);
972+
973+
//Turn on read and ignore ctrl lines
974+
options.c_cflag |= (CLOCAL | CREAD);
975+
976+
if( tcsetattr(poSharedData->RS485_Handle, TCSANOW, &options) < 0) {
977+
perror(poSharedData->RS485_Port_Name);
978+
exit(-1);
979+
}
980+
#endif
981+
#ifdef __linux__
982+
struct termios newtio;
925983
/* save current serial port settings */
926984
tcgetattr(poSharedData->RS485_Handle, &poSharedData->RS485_oldtio);
927985
/* clear struct for new port settings */
@@ -943,6 +1001,9 @@ bool dlmstp_init(
9431001
newtio.c_lflag = 0;
9441002
/* activate the settings for the port after flushing I/O */
9451003
tcsetattr(poSharedData->RS485_Handle, TCSAFLUSH, &newtio);
1004+
1005+
#endif
1006+
9461007
/* flush any data waiting */
9471008
usleep(200000);
9481009
tcflush(poSharedData->RS485_Handle, TCIOFLUSH);

misty/bacnet-stack-0.8.4/ports/linux/dlmstp_linux.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626

2727
#include "mstp.h"
2828
/*#include "dlmstp.h" */
29+
#ifdef __linux__
2930
#include "bits/pthreadtypes.h"
31+
#endif
3032
#include <semaphore.h>
3133

3234
#include <stdbool.h>
@@ -37,6 +39,9 @@
3739
#include <termios.h>
3840
#include "fifo.h"
3941
#include "ringbuf.h"
42+
#ifdef __APPLE__
43+
#include <dispatch/dispatch.h>
44+
#endif
4045
/* defines specific to MS/TP */
4146
/* preamble+type+dest+src+len+crc8+crc16 */
4247
#define MAX_HEADER (2+1+1+1+2+1+2)
@@ -73,7 +78,12 @@ typedef struct shared_mstp_data {
7378
/*
7479
RT_SEM Receive_Packet_Flag;
7580
*/
81+
#ifdef __APPLE__
82+
dispatch_semaphore_t Receive_Packet_Flag;
83+
#endif
84+
#ifdef __linux__
7685
sem_t Receive_Packet_Flag;
86+
#endif
7787
/* mechanism to wait for a frame in state machine */
7888
/*
7989
RT_COND Received_Frame_Flag;

misty/bacnet-stack-0.8.4/ports/linux/net.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
#include <net/route.h>
7979
#include <net/if.h>
8080
#include <net/if_arp.h>
81+
#ifdef __linux__
8182
#include <features.h> /* for the glibc version number */
8283
#if __GLIBC__ >= 2 && __GLIBC_MINOR >= 1
8384
#include <netpacket/packet.h>
@@ -93,6 +94,7 @@
9394
#include <sys/un.h>
9495
#include <sys/ioctl.h>
9596
#include <netdb.h>
97+
#endif
9698

9799
/** @file linux/net.h Includes Linux network headers. */
98100

0 commit comments

Comments
 (0)