Skip to content

Commit

Permalink
Release 2.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sfeakes committed Jun 20, 2023
1 parent 7fa7b55 commit 78fe018
Show file tree
Hide file tree
Showing 22 changed files with 740 additions and 742 deletions.
230 changes: 225 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,211 @@
#
# Options
#
# make // standard everything
# make debug // Give standard binary just with debugging
# make aqdebug // Compile with extra aqualink debug information like timings
# make slog // Serial logger
# make <other> // not documenting
#

# Valid flags for AQ_FLAGS
AQ_RS16 = true
AQ_PDA = true
AQ_ONETOUCH = true
AQ_IAQTOUCH = true
#AQ_MEMCMP = true // Not implimented correctly yet.

# Turn off threadded net services
AQ_NO_THREAD_NETSERVICE = false

# define the C compiler to use
CC = gcc

#LIBS := -lpthread -lm
LIBS := -l pthread -l m
#LIBS := -l pthread -l m -static # Take out -static, just for dev

# Standard compile flags
GCCFLAGS = -Wall -O3
#GCCFLAGS = -O3
#GCCFLAGS = -Wall -O3 -Wextra
#GCCFLAGS = -Wl,--gc-sections,--print-gc-sections
#GCCFLAGS = -Wall -O3 -ffunction-sections -fdata-sections

# Standard debug flags
DGCCFLAGS = -Wall -O0 -g

# Aqualink Debug flags
#DBGFLAGS = -g -O0 -Wall -fsanitize=address -D AQ_DEBUG -D AQ_TM_DEBUG
DBGFLAGS = -g -O0 -Wall -D AQ_DEBUG -D AQ_TM_DEBUG

# Mongoose flags
#MGFLAGS = -D MG_DISABLE_MD5 -D MG_DISABLE_HTTP_DIGEST_AUTH -D MG_DISABLE_MD5 -D MG_DISABLE_JSON_RPC
# Mongoose 6.18 flags
MGFLAGS = -D MG_ENABLE_HTTP_SSI=0 -D MG_ENABLE_DIRECTORY_LISTING=0 -D MG_ENABLE_HTTP_CGI=0
#MGFLAGS =

# Detect OS and set some specifics
ifeq ($(OS),Windows_NT)
# Windows Make.
RM = del /Q
MKDIR = mkdir
FixPath = $(subst /,\,$1)
else
UNAME_S := $(shell uname -s)
# Linux
ifeq ($(UNAME_S),Linux)
RM = rm -f
MKDIR = mkdir -p
FixPath = $1
# Get some system information
PI_OS_VERSION = $(shell cat /etc/os-release | grep VERSION= | cut -d\" -f2)
$(info OS: $(PI_OS_VERSION) )
GLIBC_VERSION = $(shell ldd --version | grep ldd)
$(info GLIBC build with: $(GLIBC_VERSION) )
$(info GLIBC Prefered : 2.24-11+deb9u1 2.24 )
endif
# OSX
ifeq ($(UNAME_S),Darwin)
endif
endif


# Main source files
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\
devices_jandy.c packetLogger.c devices_pentair.c color_lights.c serialadapter.c aq_timer.c aq_scheduler.c web_config.c\
mongoose.c


AQ_FLAGS =
# Add source and flags depending on protocols to support.
ifeq ($(AQ_PDA), true)
SRCS := $(SRCS) pda.c pda_menu.c pda_aq_programmer.c
AQ_FLAGS := $(AQ_FLAGS) -D AQ_PDA
endif

ifeq ($(AQ_ONETOUCH), true)
SRCS := $(SRCS) onetouch.c onetouch_aq_programmer.c
AQ_FLAGS := $(AQ_FLAGS) -D AQ_ONETOUCH
endif

ifeq ($(AQ_IAQTOUCH), true)
SRCS := $(SRCS) iaqtouch.c iaqtouch_aq_programmer.c
AQ_FLAGS := $(AQ_FLAGS) -D AQ_IAQTOUCH
endif

ifeq ($(AQ_RS16), true)
AQ_FLAGS := $(AQ_FLAGS) -D AQ_RS16
endif

ifeq ($(AQ_MEMCMP), true)
AQ_FLAGS := $(AQ_FLAGS) -D AQ_MEMCMP
endif

ifeq ($(AQ_NO_THREAD_NETSERVICE), true)
AQ_FLAGS := $(AQ_FLAGS) -D AQ_NO_THREAD_NETSERVICE
endif


# Put all flags together.
CFLAGS = $(GCCFLAGS) $(AQ_FLAGS) $(MGFLAGS)
DFLAGS = $(DGCCFLAGS) $(AQ_FLAGS) $(MGFLAGS)
DBG_CFLAGS = $(DBGFLAGS) $(AQ_FLAGS) $(MGFLAGS)

# Other sources.
DBG_SRC = $(SRCS) debug_timer.c
SL_SRC = serial_logger.c aq_serial.c utils.c packetLogger.c rs_msg_utils.c

# Build durectories
OBJ_DIR := ./build
DBG_OBJ_DIR := $(OBJ_DIR)/debug
SL_OBJ_DIR := $(OBJ_DIR)/slog

# Object files
OBJ_FILES := $(patsubst %.c,$(OBJ_DIR)/%.o,$(SRCS))
DBG_OBJ_FILES := $(patsubst %.c,$(DBG_OBJ_DIR)/%.o,$(DBG_SRC))
SL_OBJ_FILES := $(patsubst %.c,$(SL_OBJ_DIR)/%.o,$(SL_SRC))


# define the executable file
MAIN = ./release/aqualinkd
SLOG = ./release/serial_logger
DEBG = ./release/aqualinkd-debug
#LOGR = ./release/log_reader
#PLAY = ./release/aqualinkd-player


# Rules to pass to make.
all: $(MAIN) $(SLOG)
$(info $(MAIN) has been compiled)
$(info $(SLOG) has been compiled)

slog: $(SLOG)
$(info $(SLOG) has been compiled)

aqdebug: $(DEBG)
$(info $(DEBG) has been compiled)

#debug, Just change compile flags and call MAIN
debug: CFLAGS = $(DFLAGS)
debug: $(MAIN) $(SLOG)
$(info $(MAIN) has been compiled (** DEBUG **))
$(info $(SLOG) has been compiled (** DEBUG **))

install: $(MAIN)
./release/install.sh


# Rules to compile
$(OBJ_DIR)/%.o: %.c | $(OBJ_DIR)
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<

$(DBG_OBJ_DIR)/%.o: %.c | $(DBG_OBJ_DIR)
$(CC) $(DBG_CFLAGS) $(INCLUDES) -c -o $@ $<

$(SL_OBJ_DIR)/%.o: %.c | $(SL_OBJ_DIR)
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<

# Rules to link
$(MAIN): $(OBJ_FILES)
$(CC) $(CFLAGS) $(INCLUDES) $(LIBS) -o $@ $^

$(DEBG): $(DBG_OBJ_FILES)
$(CC) $(DBG_CFLAGS) $(INCLUDES) $(LIBS) -o $@ $^

$(SLOG): CFLAGS := $(CFLAGS) -D SERIAL_LOGGER
$(SLOG): $(SL_OBJ_FILES)
$(CC) $(CFLAGS) $(INCLUDES) $(LIBS) -o $@ $^

# Rules to make object directories.
$(OBJ_DIR):
$(MKDIR) $@

$(SL_OBJ_DIR):
$(MKDIR) $@

$(DBG_OBJ_DIR):
$(MKDIR) $@


# Clean rules
.PHONY: clean
clean:
$(RM) *.o *~ $(MAIN) $(MAIN_U) $(PLAY) $(PL_EXOBJ) $(DEBG)
$(RM) $(wildcard *.o) $(wildcard *~) $(OBJ_FILES) $(DBG_OBJ_FILES) $(SL_OBJ_FILES) $(MAIN) $(MAIN_U) $(PLAY) $(PL_EXOBJ) $(LOGR) $(PLAY) $(DEBG)





define DO_NOT_USE

# OLD MAKEFILE, STILL NEED TO MOVE THE BELOW OVER TO NEW Makefile
LOGR = ./release/log_reader
PLAY = ./release/aqualinkd-player



#
# Options
#
Expand Down Expand Up @@ -48,15 +256,18 @@ DGCCFLAGS = -Wall -O0 -g
DBGFLAGS = -g -O0 -Wall -D AQ_DEBUG -D AQ_TM_DEBUG

# Mongoose flags
MGFLAGS = -D MG_DISABLE_MD5 -D MG_DISABLE_HTTP_DIGEST_AUTH -D MG_DISABLE_MD5 -D MG_DISABLE_JSON_RPC
#MGFLAGS = -D MG_DISABLE_MD5 -D MG_DISABLE_HTTP_DIGEST_AUTH -D MG_DISABLE_MD5 -D MG_DISABLE_JSON_RPC
# Mongoose 6.18 flags
MGFLAGS = -D MG_ENABLE_HTTP_SSI=0 -D MG_ENABLE_DIRECTORY_LISTING=0 -D MG_ENABLE_HTTP_CGI=0
#MGFLAGS =

# define the C source files
#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 \
# pda_aq_programmer.c devices_jandy.c onetouch.c onetouch_aq_programmer.c packetLogger.c devices_pentair.c color_lights.c mongoose.c

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\
devices_jandy.c packetLogger.c devices_pentair.c color_lights.c serialadapter.c aq_timer.c aq_scheduler.c web_config.c mongoose.c
devices_jandy.c packetLogger.c devices_pentair.c color_lights.c serialadapter.c aq_timer.c aq_scheduler.c web_config.c\
mongoose.c


AQ_FLAGS =
Expand Down Expand Up @@ -110,15 +321,18 @@ SL_OBJS = $(SL_SRC:.c=.o)
LR_OBJS = $(LR_SRC:.c=.o)
PL_OBJS = $(PL_SRC:.c=.o)


# define the executable file
MAIN = ./release/aqualinkd
SLOG = ./release/serial_logger
LOGR = ./release/log_reader
PLAY = ./release/aqualinkd-player
DEBG = ./release/aqualinkd-debug

all: $(MAIN)

all: $(MAIN) $(SLOG)
$(info $(MAIN) has been compiled)
$(info $(SLOG) has been compiled)

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

$(SLOG): CFLAGS := $(CFLAGS) -D SERIAL_LOGGER
$(SLOG): $(SL_OBJS)
$(CC) $(CFLAGS) $(INCLUDES) -o $(SLOG) $(SL_OBJS)
# $(CC) $(CFLAGS) $(INCLUDES) -o $(SLOG) $(SL_OBJS)
$(CC) $(INCLUDES) -o $(SLOG) $(SL_OBJS)


#.PHONY: clean_slog_o
Expand Down Expand Up @@ -181,7 +396,8 @@ git: clean $(MAIN) $(SLOG)
# the rule(a .c file) and $@: the name of the target of the rule (a .o file)
# (see the gnu make manual section about automatic variables)
.c.o:
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@


.PHONY: clean
clean:
Expand All @@ -194,3 +410,7 @@ depend: $(SRCS)
install: $(MAIN)
./release/install.sh



endef

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,9 @@ Designed to mimic AqualinkRS6 All Button keypad and (like the keypad) is used to
* Allow selecting of pre-defined VSP programs (Aqualink Touch & OneTouch protocols.)
* Add set time to OneTouch protocol.

# Update in Release 2.3.0f (pre release)
* This is pre-release, please treat it as such.
* 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
# Update in Release 2.3.1
* Changed a lot of logic around different protocols.
* Added low latency support for ITDI usb driver.
* Added low latency support for FTDI usb driver.
* AqualinkD will find out the fastest way to change something depending on the protocols available.
* Added scheduler (click time in web ui). supports full calendar year (ie seasons), See wiki for details.
* Added timers for devices (ie can turn on Pump for x minutes), Long press on device in WebUI.
Expand All @@ -97,6 +95,8 @@ Designed to mimic AqualinkRS6 All Button keypad and (like the keypad) is used to
* Fix bug in IntelliBrite color lights
* Install script checks for cron and it's config (needed for scheduler)
* serial-logger will now give recommended values for aqualinkd.conf
* Lock the serial port to stop duplicate process conflict.
* Lots of code cleanup & modifying ready for AqualinkD Management console in a future release.

# Update in Release 2.2.2
* Fixed some Web UI bugs
Expand Down
35 changes: 34 additions & 1 deletion aq_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,33 @@ int set_port_low_latency(int fd, const char* tty)
return 0;
}

#include <sys/file.h>

int lock_port(int fd, const char* tty)
{
if (ioctl (fd, TIOCEXCL) < 0) {
LOG(RSSD_LOG,LOG_ERR, "Can't put (%s) into exclusive mode (%d): %s\n", tty,errno, strerror( errno ));
return -1;
}

if (flock(fd, LOCK_EX | LOCK_NB) < 0) {
LOG(RSSD_LOG,LOG_ERR, "Can't lock (%s) (%d): %s\n", tty,errno, strerror( errno ));
return -1;
}

return 0;
}

int unlock_port(int fd)
{
if (flock(fd, LOCK_UN) < 0) {
LOG(RSSD_LOG,LOG_ERR, "Can't unlock serial port (%d): %s\n",errno, strerror( errno ));
return -1;
}
return 0;
}


// https://www.cmrr.umn.edu/~strupp/serial.html#2_5_2
// http://unixwiz.net/techtips/termios-vmin-vtime.html
//#define OLD_SERIAL_INIT
Expand Down Expand Up @@ -396,6 +423,11 @@ int _init_serial_port(const char* tty, bool blocking, bool readahead)
return -1;
}

if ( lock_port(fd, tty) < 0) {
//LOG(RSSD_LOG,LOG_ERR, "Unable to lock port: %s, error %d\n", tty, errno);
return -1;
}

if (_aqconfig_.ftdi_low_latency)
set_port_low_latency(fd, tty);

Expand Down Expand Up @@ -448,7 +480,7 @@ int _init_serial_port(const char* tty, bool blocking, bool readahead)
return -1;
}

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

return fd;
}
Expand Down Expand Up @@ -520,6 +552,7 @@ void close_blocking_serial_port()
/* close tty port */
void close_serial_port(int fd)
{
unlock_port(fd);
tcsetattr(fd, TCSANOW, &_oldtio);
close(fd);
LOG(RSSD_LOG,LOG_DEBUG_SERIAL, "Closed serial port\n");
Expand Down
Loading

0 comments on commit 78fe018

Please sign in to comment.