Skip to content

Commit 78fe018

Browse files
committed
Release 2.3.1
1 parent 7fa7b55 commit 78fe018

22 files changed

+740
-742
lines changed

Makefile

+225-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,211 @@
1+
#
2+
# Options
3+
#
4+
# make // standard everything
5+
# make debug // Give standard binary just with debugging
6+
# make aqdebug // Compile with extra aqualink debug information like timings
7+
# make slog // Serial logger
8+
# make <other> // not documenting
9+
#
10+
11+
# Valid flags for AQ_FLAGS
12+
AQ_RS16 = true
13+
AQ_PDA = true
14+
AQ_ONETOUCH = true
15+
AQ_IAQTOUCH = true
16+
#AQ_MEMCMP = true // Not implimented correctly yet.
17+
18+
# Turn off threadded net services
19+
AQ_NO_THREAD_NETSERVICE = false
20+
21+
# define the C compiler to use
22+
CC = gcc
23+
24+
#LIBS := -lpthread -lm
25+
LIBS := -l pthread -l m
26+
#LIBS := -l pthread -l m -static # Take out -static, just for dev
27+
28+
# Standard compile flags
29+
GCCFLAGS = -Wall -O3
30+
#GCCFLAGS = -O3
31+
#GCCFLAGS = -Wall -O3 -Wextra
32+
#GCCFLAGS = -Wl,--gc-sections,--print-gc-sections
33+
#GCCFLAGS = -Wall -O3 -ffunction-sections -fdata-sections
34+
35+
# Standard debug flags
36+
DGCCFLAGS = -Wall -O0 -g
37+
38+
# Aqualink Debug flags
39+
#DBGFLAGS = -g -O0 -Wall -fsanitize=address -D AQ_DEBUG -D AQ_TM_DEBUG
40+
DBGFLAGS = -g -O0 -Wall -D AQ_DEBUG -D AQ_TM_DEBUG
41+
42+
# Mongoose flags
43+
#MGFLAGS = -D MG_DISABLE_MD5 -D MG_DISABLE_HTTP_DIGEST_AUTH -D MG_DISABLE_MD5 -D MG_DISABLE_JSON_RPC
44+
# Mongoose 6.18 flags
45+
MGFLAGS = -D MG_ENABLE_HTTP_SSI=0 -D MG_ENABLE_DIRECTORY_LISTING=0 -D MG_ENABLE_HTTP_CGI=0
46+
#MGFLAGS =
47+
48+
# Detect OS and set some specifics
49+
ifeq ($(OS),Windows_NT)
50+
# Windows Make.
51+
RM = del /Q
52+
MKDIR = mkdir
53+
FixPath = $(subst /,\,$1)
54+
else
55+
UNAME_S := $(shell uname -s)
56+
# Linux
57+
ifeq ($(UNAME_S),Linux)
58+
RM = rm -f
59+
MKDIR = mkdir -p
60+
FixPath = $1
61+
# Get some system information
62+
PI_OS_VERSION = $(shell cat /etc/os-release | grep VERSION= | cut -d\" -f2)
63+
$(info OS: $(PI_OS_VERSION) )
64+
GLIBC_VERSION = $(shell ldd --version | grep ldd)
65+
$(info GLIBC build with: $(GLIBC_VERSION) )
66+
$(info GLIBC Prefered : 2.24-11+deb9u1 2.24 )
67+
endif
68+
# OSX
69+
ifeq ($(UNAME_S),Darwin)
70+
endif
71+
endif
72+
73+
74+
# Main source files
75+
SRCS = aqualinkd.c utils.c config.c aq_serial.c aq_panel.c aq_programmer.c net_services.c json_messages.c rs_msg_utils.c\
76+
devices_jandy.c packetLogger.c devices_pentair.c color_lights.c serialadapter.c aq_timer.c aq_scheduler.c web_config.c\
77+
mongoose.c
78+
79+
80+
AQ_FLAGS =
81+
# Add source and flags depending on protocols to support.
82+
ifeq ($(AQ_PDA), true)
83+
SRCS := $(SRCS) pda.c pda_menu.c pda_aq_programmer.c
84+
AQ_FLAGS := $(AQ_FLAGS) -D AQ_PDA
85+
endif
86+
87+
ifeq ($(AQ_ONETOUCH), true)
88+
SRCS := $(SRCS) onetouch.c onetouch_aq_programmer.c
89+
AQ_FLAGS := $(AQ_FLAGS) -D AQ_ONETOUCH
90+
endif
91+
92+
ifeq ($(AQ_IAQTOUCH), true)
93+
SRCS := $(SRCS) iaqtouch.c iaqtouch_aq_programmer.c
94+
AQ_FLAGS := $(AQ_FLAGS) -D AQ_IAQTOUCH
95+
endif
96+
97+
ifeq ($(AQ_RS16), true)
98+
AQ_FLAGS := $(AQ_FLAGS) -D AQ_RS16
99+
endif
100+
101+
ifeq ($(AQ_MEMCMP), true)
102+
AQ_FLAGS := $(AQ_FLAGS) -D AQ_MEMCMP
103+
endif
104+
105+
ifeq ($(AQ_NO_THREAD_NETSERVICE), true)
106+
AQ_FLAGS := $(AQ_FLAGS) -D AQ_NO_THREAD_NETSERVICE
107+
endif
108+
109+
110+
# Put all flags together.
111+
CFLAGS = $(GCCFLAGS) $(AQ_FLAGS) $(MGFLAGS)
112+
DFLAGS = $(DGCCFLAGS) $(AQ_FLAGS) $(MGFLAGS)
113+
DBG_CFLAGS = $(DBGFLAGS) $(AQ_FLAGS) $(MGFLAGS)
114+
115+
# Other sources.
116+
DBG_SRC = $(SRCS) debug_timer.c
117+
SL_SRC = serial_logger.c aq_serial.c utils.c packetLogger.c rs_msg_utils.c
118+
119+
# Build durectories
120+
OBJ_DIR := ./build
121+
DBG_OBJ_DIR := $(OBJ_DIR)/debug
122+
SL_OBJ_DIR := $(OBJ_DIR)/slog
123+
124+
# Object files
125+
OBJ_FILES := $(patsubst %.c,$(OBJ_DIR)/%.o,$(SRCS))
126+
DBG_OBJ_FILES := $(patsubst %.c,$(DBG_OBJ_DIR)/%.o,$(DBG_SRC))
127+
SL_OBJ_FILES := $(patsubst %.c,$(SL_OBJ_DIR)/%.o,$(SL_SRC))
128+
129+
130+
# define the executable file
131+
MAIN = ./release/aqualinkd
132+
SLOG = ./release/serial_logger
133+
DEBG = ./release/aqualinkd-debug
134+
#LOGR = ./release/log_reader
135+
#PLAY = ./release/aqualinkd-player
136+
137+
138+
# Rules to pass to make.
139+
all: $(MAIN) $(SLOG)
140+
$(info $(MAIN) has been compiled)
141+
$(info $(SLOG) has been compiled)
142+
143+
slog: $(SLOG)
144+
$(info $(SLOG) has been compiled)
145+
146+
aqdebug: $(DEBG)
147+
$(info $(DEBG) has been compiled)
148+
149+
#debug, Just change compile flags and call MAIN
150+
debug: CFLAGS = $(DFLAGS)
151+
debug: $(MAIN) $(SLOG)
152+
$(info $(MAIN) has been compiled (** DEBUG **))
153+
$(info $(SLOG) has been compiled (** DEBUG **))
154+
155+
install: $(MAIN)
156+
./release/install.sh
157+
158+
159+
# Rules to compile
160+
$(OBJ_DIR)/%.o: %.c | $(OBJ_DIR)
161+
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
162+
163+
$(DBG_OBJ_DIR)/%.o: %.c | $(DBG_OBJ_DIR)
164+
$(CC) $(DBG_CFLAGS) $(INCLUDES) -c -o $@ $<
165+
166+
$(SL_OBJ_DIR)/%.o: %.c | $(SL_OBJ_DIR)
167+
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
168+
169+
# Rules to link
170+
$(MAIN): $(OBJ_FILES)
171+
$(CC) $(CFLAGS) $(INCLUDES) $(LIBS) -o $@ $^
172+
173+
$(DEBG): $(DBG_OBJ_FILES)
174+
$(CC) $(DBG_CFLAGS) $(INCLUDES) $(LIBS) -o $@ $^
175+
176+
$(SLOG): CFLAGS := $(CFLAGS) -D SERIAL_LOGGER
177+
$(SLOG): $(SL_OBJ_FILES)
178+
$(CC) $(CFLAGS) $(INCLUDES) $(LIBS) -o $@ $^
179+
180+
# Rules to make object directories.
181+
$(OBJ_DIR):
182+
$(MKDIR) $@
183+
184+
$(SL_OBJ_DIR):
185+
$(MKDIR) $@
186+
187+
$(DBG_OBJ_DIR):
188+
$(MKDIR) $@
189+
190+
191+
# Clean rules
192+
.PHONY: clean
193+
clean:
194+
$(RM) *.o *~ $(MAIN) $(MAIN_U) $(PLAY) $(PL_EXOBJ) $(DEBG)
195+
$(RM) $(wildcard *.o) $(wildcard *~) $(OBJ_FILES) $(DBG_OBJ_FILES) $(SL_OBJ_FILES) $(MAIN) $(MAIN_U) $(PLAY) $(PL_EXOBJ) $(LOGR) $(PLAY) $(DEBG)
196+
197+
198+
199+
200+
201+
define DO_NOT_USE
202+
203+
# OLD MAKEFILE, STILL NEED TO MOVE THE BELOW OVER TO NEW Makefile
204+
LOGR = ./release/log_reader
205+
PLAY = ./release/aqualinkd-player
206+
207+
208+
1209
#
2210
# Options
3211
#
@@ -48,15 +256,18 @@ DGCCFLAGS = -Wall -O0 -g
48256
DBGFLAGS = -g -O0 -Wall -D AQ_DEBUG -D AQ_TM_DEBUG
49257

50258
# Mongoose flags
51-
MGFLAGS = -D MG_DISABLE_MD5 -D MG_DISABLE_HTTP_DIGEST_AUTH -D MG_DISABLE_MD5 -D MG_DISABLE_JSON_RPC
259+
#MGFLAGS = -D MG_DISABLE_MD5 -D MG_DISABLE_HTTP_DIGEST_AUTH -D MG_DISABLE_MD5 -D MG_DISABLE_JSON_RPC
260+
# Mongoose 6.18 flags
261+
MGFLAGS = -D MG_ENABLE_HTTP_SSI=0 -D MG_ENABLE_DIRECTORY_LISTING=0 -D MG_ENABLE_HTTP_CGI=0
52262
#MGFLAGS =
53263

54264
# define the C source files
55265
#SRCS = aqualinkd.c utils.c config.c aq_serial.c init_buttons.c aq_programmer.c net_services.c json_messages.c pda.c pda_menu.c \
56266
# pda_aq_programmer.c devices_jandy.c onetouch.c onetouch_aq_programmer.c packetLogger.c devices_pentair.c color_lights.c mongoose.c
57267

58268
SRCS = aqualinkd.c utils.c config.c aq_serial.c aq_panel.c aq_programmer.c net_services.c json_messages.c rs_msg_utils.c\
59-
devices_jandy.c packetLogger.c devices_pentair.c color_lights.c serialadapter.c aq_timer.c aq_scheduler.c web_config.c mongoose.c
269+
devices_jandy.c packetLogger.c devices_pentair.c color_lights.c serialadapter.c aq_timer.c aq_scheduler.c web_config.c\
270+
mongoose.c
60271

61272

62273
AQ_FLAGS =
@@ -110,15 +321,18 @@ SL_OBJS = $(SL_SRC:.c=.o)
110321
LR_OBJS = $(LR_SRC:.c=.o)
111322
PL_OBJS = $(PL_SRC:.c=.o)
112323

324+
113325
# define the executable file
114326
MAIN = ./release/aqualinkd
115327
SLOG = ./release/serial_logger
116328
LOGR = ./release/log_reader
117329
PLAY = ./release/aqualinkd-player
118330
DEBG = ./release/aqualinkd-debug
119331

120-
all: $(MAIN)
332+
333+
all: $(MAIN) $(SLOG)
121334
$(info $(MAIN) has been compiled)
335+
$(info $(SLOG) has been compiled)
122336

123337
# debug, Just change compile flags and call MAIN
124338
debug: CFLAGS = $(DFLAGS)
@@ -134,7 +348,8 @@ slog: $(SLOG)
134348

135349
$(SLOG): CFLAGS := $(CFLAGS) -D SERIAL_LOGGER
136350
$(SLOG): $(SL_OBJS)
137-
$(CC) $(CFLAGS) $(INCLUDES) -o $(SLOG) $(SL_OBJS)
351+
# $(CC) $(CFLAGS) $(INCLUDES) -o $(SLOG) $(SL_OBJS)
352+
$(CC) $(INCLUDES) -o $(SLOG) $(SL_OBJS)
138353

139354

140355
#.PHONY: clean_slog_o
@@ -181,7 +396,8 @@ git: clean $(MAIN) $(SLOG)
181396
# the rule(a .c file) and $@: the name of the target of the rule (a .o file)
182397
# (see the gnu make manual section about automatic variables)
183398
.c.o:
184-
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
399+
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
400+
185401

186402
.PHONY: clean
187403
clean:
@@ -194,3 +410,7 @@ depend: $(SRCS)
194410
install: $(MAIN)
195411
./release/install.sh
196412

413+
414+
415+
endef
416+

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,9 @@ Designed to mimic AqualinkRS6 All Button keypad and (like the keypad) is used to
7878
* Allow selecting of pre-defined VSP programs (Aqualink Touch & OneTouch protocols.)
7979
* Add set time to OneTouch protocol.
8080

81-
# Update in Release 2.3.0f (pre release)
82-
* This is pre-release, please treat it as such.
83-
* Proceed with caution on PDA panels <i>I have not been able to test it fully on all variants</i> and you may need to go back to your current (or previous) version of AqualinkD
81+
# Update in Release 2.3.1
8482
* Changed a lot of logic around different protocols.
85-
* Added low latency support for ITDI usb driver.
83+
* Added low latency support for FTDI usb driver.
8684
* AqualinkD will find out the fastest way to change something depending on the protocols available.
8785
* Added scheduler (click time in web ui). supports full calendar year (ie seasons), See wiki for details.
8886
* Added timers for devices (ie can turn on Pump for x minutes), Long press on device in WebUI.
@@ -97,6 +95,8 @@ Designed to mimic AqualinkRS6 All Button keypad and (like the keypad) is used to
9795
* Fix bug in IntelliBrite color lights
9896
* Install script checks for cron and it's config (needed for scheduler)
9997
* serial-logger will now give recommended values for aqualinkd.conf
98+
* Lock the serial port to stop duplicate process conflict.
99+
* Lots of code cleanup & modifying ready for AqualinkD Management console in a future release.
100100

101101
# Update in Release 2.2.2
102102
* Fixed some Web UI bugs

aq_serial.c

+34-1
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,33 @@ int set_port_low_latency(int fd, const char* tty)
368368
return 0;
369369
}
370370

371+
#include <sys/file.h>
372+
373+
int lock_port(int fd, const char* tty)
374+
{
375+
if (ioctl (fd, TIOCEXCL) < 0) {
376+
LOG(RSSD_LOG,LOG_ERR, "Can't put (%s) into exclusive mode (%d): %s\n", tty,errno, strerror( errno ));
377+
return -1;
378+
}
379+
380+
if (flock(fd, LOCK_EX | LOCK_NB) < 0) {
381+
LOG(RSSD_LOG,LOG_ERR, "Can't lock (%s) (%d): %s\n", tty,errno, strerror( errno ));
382+
return -1;
383+
}
384+
385+
return 0;
386+
}
387+
388+
int unlock_port(int fd)
389+
{
390+
if (flock(fd, LOCK_UN) < 0) {
391+
LOG(RSSD_LOG,LOG_ERR, "Can't unlock serial port (%d): %s\n",errno, strerror( errno ));
392+
return -1;
393+
}
394+
return 0;
395+
}
396+
397+
371398
// https://www.cmrr.umn.edu/~strupp/serial.html#2_5_2
372399
// http://unixwiz.net/techtips/termios-vmin-vtime.html
373400
//#define OLD_SERIAL_INIT
@@ -396,6 +423,11 @@ int _init_serial_port(const char* tty, bool blocking, bool readahead)
396423
return -1;
397424
}
398425

426+
if ( lock_port(fd, tty) < 0) {
427+
//LOG(RSSD_LOG,LOG_ERR, "Unable to lock port: %s, error %d\n", tty, errno);
428+
return -1;
429+
}
430+
399431
if (_aqconfig_.ftdi_low_latency)
400432
set_port_low_latency(fd, tty);
401433

@@ -448,7 +480,7 @@ int _init_serial_port(const char* tty, bool blocking, bool readahead)
448480
return -1;
449481
}
450482

451-
LOG(RSSD_LOG,LOG_INFO, "Set serial port %s I/O %s attributes\n",tty,_blocking_mode?"blocking":"non blocking");
483+
LOG(RSSD_LOG,LOG_INFO, "Port %s set I/O %s attributes\n",tty,_blocking_mode?"blocking":"non blocking");
452484

453485
return fd;
454486
}
@@ -520,6 +552,7 @@ void close_blocking_serial_port()
520552
/* close tty port */
521553
void close_serial_port(int fd)
522554
{
555+
unlock_port(fd);
523556
tcsetattr(fd, TCSANOW, &_oldtio);
524557
close(fd);
525558
LOG(RSSD_LOG,LOG_DEBUG_SERIAL, "Closed serial port\n");

0 commit comments

Comments
 (0)