Skip to content

Commit

Permalink
Merge pull request sfeakes#276 from sfeakes/Simulator-dev
Browse files Browse the repository at this point in the history
Simulator dev
  • Loading branch information
sfeakes authored Apr 22, 2024
2 parents 7cca421 + 9d580cb commit a033fc3
Show file tree
Hide file tree
Showing 34 changed files with 2,722 additions and 738 deletions.
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ AQ_PDA = true
AQ_ONETOUCH = true
AQ_IAQTOUCH = true
AQ_MANAGER =true
AQ_RS_EXTRA_OPTS = false
#AQ_RS_EXTRA_OPTS = false
#AQ_CONTAINER = false // this is for compiling for containers
#AQ_MEMCMP = true // Not implimented correctly yet.

# Turn off threadded net services
Expand Down Expand Up @@ -75,7 +76,7 @@ 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\
serial_logger.c mongoose.c timespec_subtract.c
serial_logger.c mongoose.c simulator.c timespec_subtract.c


AQ_FLAGS =
Expand Down Expand Up @@ -130,6 +131,7 @@ 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 timespec_subtract.c
#MG_SRC = mongoose.c

# Build durectories
OBJ_DIR := ./build
Expand All @@ -140,7 +142,7 @@ SL_OBJ_DIR := $(OBJ_DIR)/slog
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))

#MG_OBJ_FILES := $(patsubst %.c,$(OBJ_DIR)/%.o,$(MG_SRC))

# define the executable file
MAIN = ./release/aqualinkd
Expand All @@ -161,6 +163,12 @@ slog: $(SLOG)
aqdebug: $(DEBG)
$(info $(DEBG) has been compiled)

# Container, add container flag and compile
container: CFLAGS := $(CFLAGS) -D AQ_CONTAINER
container: $(MAIN) $(SLOG)
$(info $(MAIN) has been compiled (** For Container use **))
$(info $(SLOG) has been compiled (** For Container use **))

#debug, Just change compile flags and call MAIN
debug: CFLAGS = $(DFLAGS)
debug: $(MAIN) $(SLOG)
Expand Down
26 changes: 20 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ https://github.com/sfeakes/AqualinkD/wiki/Jandy-Aqualink-RS485-protocol
</td></tr>
</table>

### Simulator
Designed to mimic AqualinkRS6 All Button keypad and (like the keypad) is used to fully configure the master control panel<br>
<img src="extras/simulator.png?raw=true" width="550">
### Simulators
Designed to mimic AqualinkRS devices, used to fully configure the master control panel<br>
<img src="extras/onetouch_sim.png?raw=true">
<img src="extras/allbutton_sim.png?raw=true">

### In Apple Home app.
<img src="extras/HomeKit2.png?raw=true" width="800"></img>
Expand All @@ -71,13 +72,26 @@ Designed to mimic AqualinkRS6 All Button keypad and (like the keypad) is used to
## All Web interfaces.
* http://aqualink.ip/ <- (Standard WEB UI
* http://aqualink.ip/simple.html <- (Simple opion if you don't like the above)
* http://aqualink.ip/simulator.html <- (RS8 All Button Control Panel simulator)
* http://aqualink.ip/debug.html <- (Turn on/off debug/serial debug & download logs)
* http://aqualink.ip/simulator.html <- (Displays all simulators in one page with tabs)
* http://aqualink.ip/aqmanager.html <- (Manage AqualinkD configuration & runtime)
* http://aqualink.ip/allbutton_sim.html <- (All Button Simulator)
* http://aqualink.ip/onetouch_sim.html <- (One Touch Simulator)
* http://aqualink.ip/aquapda_sim.html <- (PDA simulator)
#<a name="release"></a>
# ToDo (future release)
* Allow selecting of pre-defined VSP programs (Aqualink Touch & OneTouch protocols.)
* Add set time to OneTouch protocol.
* Publish AqualinkD Management console. (Configure, Restart, run serial_logger) within AqualinkD.
* Update AqualinkD Management console to manage configuration
* Create iAqualink Touch Simulator

# Update in Release 2.3.4
* Changes for Docker
* Updated simulator code base and added new simulators for AllButton, OneTouch & PDA.
* <aqualinkd.ip>/allbutton_sim.html
* <aqualinkd.ip>/onetouch_sim.html
* <aqualinkd.ip>/aquapda_sim.html
* On PDA only panel AqualinkD has to share the same ID with the PDA simulator. There for AqualinkD will not respond to commands while simulator is active.
* Now you can completley program the control panel with the simulators removing the need to have Jandy device.

# Update in Release 2.3.3
* Introduced Aqualink Manager UI http://aqualink.ip/aqmanager.html
Expand Down
4 changes: 3 additions & 1 deletion aq_programmer.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
#define LIGHT_MODE_BUFER PTHREAD_ARG

typedef enum emulation_type{
SIM_NONE = -1,
ALLBUTTON,
RSSADAPTER,
ONETOUCH,
IAQTOUCH,
AQUAPDA, // AQUAPALM and PDA are taken as specific type.
JANDY_DEVICE // Very rarley used.
JANDY_DEVICE, // Very rarley used.
SIMULATOR
} emulation_type;

typedef enum {
Expand Down
6 changes: 5 additions & 1 deletion aq_scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ Example /etc/cron.d/aqualinkd
*/

bool remount_root_ro(bool readonly) {
// NSF Check if config is RO_ROOT set

#ifdef AQ_CONTAINER
// In container this is pointless
return false;
#endif

if (readonly) {
LOG(SCHD_LOG,LOG_INFO, "reMounting root RO\n");
Expand Down
48 changes: 4 additions & 44 deletions aq_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,30 +336,15 @@ int _init_serial_port(const char* tty, bool blocking, bool readahead);
int init_serial_port(const char* tty)
{
#ifdef AQ_NO_THREAD_NETSERVICE
if (_aqconfig_.rs_poll_speed < 0)
return init_blocking_serial_port(_aqconfig_.serial_port);
else if (_aqconfig_.readahead_b4_write)
return init_readahead_serial_port(_aqconfig_.serial_port);
else
return init_serial_port(_aqconfig_.serial_port);
#elif AQ_RS_EXTRA_OPTS
if (_aqconfig_.readahead_b4_write)
return init_readahead_serial_port(_aqconfig_.serial_port);
else
if (_aqconfig_.rs_poll_speed < 0) {
return init_blocking_serial_port(_aqconfig_.serial_port);
}
#else
return init_blocking_serial_port(_aqconfig_.serial_port);
#endif

}

#ifdef AQ_RS_EXTRA_OPTS
int init_readahead_serial_port(const char* tty)
{
return _init_serial_port(tty, false, true);
}
#endif

int init_blocking_serial_port(const char* tty)
{
_blocking_fds = _init_serial_port(tty, true, false);
Expand Down Expand Up @@ -767,14 +752,6 @@ void send_packet(int fd, unsigned char *packet, int length)
if (nwrite != length)
LOG(RSSD_LOG, LOG_ERR, "write to serial port failed\n");
} else {
#ifdef AQ_RS_EXTRA_OPTS
if (_aqconfig_.readahead_b4_write) {
if (cleanOutSerial(fd, false) != 0x00) {
LOG(RSSD_LOG, LOG_ERR, "ERROR on RS485, AqualinkD was too slow in replying to message! (please check for performance issues)\n");
cleanOutSerial(fd, true);
}
}
#endif
int nwrite, i;
for (i = 0; i < length; i += nwrite) {
nwrite = write(fd, packet + i, length - i);
Expand Down Expand Up @@ -1026,25 +1003,8 @@ int get_packet(int fd, unsigned char* packet)

// Clean out rest of buffer, make sure their is nothing else
/* Doesn't work for shit due to probe message speed, need to come back and re-think
if (_aqconfig_.readahead_b4_write) {
if (endOfPacket == true) {
do {
bytesRead = read(fd, &byte, 1);
//if (bytesRead==1) { LOG(RSSD_LOG,LOG_ERR, "Cleanout buffer read 0x%02hhx\n",byte); }
if (bytesRead==1 && byte != 0x00) {
LOG(RSSD_LOG,LOG_ERR, "SERIOUS ERROR on RS485, AqualinkD caught packet collision on bus, ignoring!\n");
LOG(RSSD_LOG,LOG_ERR, "Error Cleanout read 0x%02hhx\n",byte);
// Run the buffer out
do {
bytesRead = read(fd, &byte, 1);
if (bytesRead==1) { LOG(RSSD_LOG,LOG_ERR, "Error Cleanout read 0x%02hhx\n",byte); }
} while (bytesRead==1);
return 0;
}
} while (bytesRead==1);
}
}
*/
*/

//LOG(RSSD_LOG,LOG_DEBUG, "Serial checksum, length %d got 0x%02hhx expected 0x%02hhx\n", index, packet[index-3], generate_checksum(packet, index));
if (jandyPacketStarted) {
if (check_jandy_checksum(packet, index) != true){
Expand Down
2 changes: 1 addition & 1 deletion aq_serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ typedef enum {

int init_serial_port(const char* tty);
int init_blocking_serial_port(const char* tty);
int init_readahead_serial_port(const char* tty);
//int init_readahead_serial_port(const char* tty);

void close_serial_port(int file_descriptor);
void close_blocking_serial_port();
Expand Down
21 changes: 20 additions & 1 deletion aqualink.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ typedef enum pump_type {
} pump_type;
*/

/*
typedef enum simulator_type {
SIM_NONE,
SIM_ALLB,
SIM_ONET,
SIM_PDA,
SIM_IAQT
} simulator_type;
*/

#define PUMP_PRIMING -1
#define PUMP_OFFLINE -2
#define PUMP_ERROR -3
Expand Down Expand Up @@ -227,7 +237,16 @@ struct aqualinkdata
//unsigned short total_ordered_buttons;
unsigned char last_packet_type;
int swg_delayed_percent;
bool simulate_panel;
//bool simulate_panel; // NSF remove in future
unsigned char simulator_packet[AQ_MAXPKTLEN+1];
bool simulator_packet_updated;
int simulator_packet_length;

//bool simulator_active; // should be redundant with other two
unsigned char simulator_id;
//simulator_type simulator_active;
emulation_type simulator_active;

bool aqManagerActive;
int open_websockets;
struct programmingthread active_thread;
Expand Down
Loading

0 comments on commit a033fc3

Please sign in to comment.