Skip to content

Commit

Permalink
Version 1.3.5b
Browse files Browse the repository at this point in the history
  • Loading branch information
sfeakes committed Aug 18, 2019
1 parent 30fff5c commit e13deac
Show file tree
Hide file tree
Showing 23 changed files with 405 additions and 155 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ CFLAGS = $(GCCFLAGS) $(DBG) $(LIBS) -D MG_DISABLE_MD5 -D MG_DISABLE_HTTP_DIGEST_
# Add inputs and outputs from these tool invocations to the build variables

# 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 pentair_messages.c mongoose.c
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 packetLogger.c pentair_messages.c mongoose.c
DBG_SRC = timespec_subtract.c

# If run with `make DEBUG=true` add debug files and pass parameter for compile
Expand All @@ -40,7 +40,7 @@ ifeq ($(DEBUG), true)
CFLAGS := $(CFLAGS) -D AQ_DEBUG
endif

SL_SRC = serial_logger.c aq_serial.c utils.c
SL_SRC = serial_logger.c aq_serial.c utils.c packetLogger.c
LR_SRC = log_reader.c aq_serial.c utils.c
PL_EXSRC = aq_serial.c
PL_EXOBJ = aq_serial_player.o
Expand Down
152 changes: 78 additions & 74 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion aq_programmer.c
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ void *set_aqualink_light_colormode( void *ptr )
aqkey *button = &aq_data->aqbuttons[btn];
unsigned char code = button->code;

logMessage(LOG_NOTICE, "Pool Light Programming #: %d, on button: %s, with pause mode: %f (initial on=%d, initial off=%d)\n", val, button->label, pmode, iOn, iOff);
logMessage(LOG_NOTICE, "Light Programming #: %d, on button: %s, with pause mode: %f (initial on=%d, initial off=%d)\n", val, button->label, pmode, iOn, iOff);

// Simply turn the light off if value is 0
if (val <= 0) {
Expand Down
92 changes: 73 additions & 19 deletions aq_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
#include "aq_serial.h"
#include "utils.h"
#include "config.h"
#include "packetLogger.h"

//#define BLOCKING_MODE
#define PENTAIR_LENGTH_FIX

static struct termios _oldtio;

Expand Down Expand Up @@ -73,23 +75,22 @@ void log_packet(int level, char *init_str, unsigned char* packet, int length)
cnt += sprintf(buff+cnt, "\n");
logMessage(level, buff);
//logMessage(LOG_DEBUG_SERIAL, buff);
/*
int i;
char temp_string[64];
char message_buffer[MAXLEN];
}













sprintf(temp_string, "Send 0x%02hhx|", packet[0]);
strcpy(message_buffer, temp_string);

for (i = 1; i < length; i++) {
sprintf(temp_string, "0x%02hhx|", packet[i]);
strcat(message_buffer, temp_string);
}

strcat(message_buffer, "\n");
logMessage(LOG_DEBUG, message_buffer);
*/
}

const char* get_packet_type(unsigned char* packet , int length)
{
Expand Down Expand Up @@ -593,8 +594,13 @@ bool check_pentair_checksum(unsigned char* packet, int length)
sum += (int) packet[i];
}

#ifndef PENTAIR_LENGTH_FIX
if (sum == (packet[length-1] * 256 + packet[length]))
return true;
#else
if (sum == (packet[length-2] * 256 + packet[length-1]))
return true;
#endif

return false;
}
Expand Down Expand Up @@ -674,7 +680,9 @@ int get_packet_new(int fd, unsigned char* packet)
{
endOfPacket = true;
PentairPreCnt = -1;
#ifndef PENTAIR_LENGTH_FIX
index--;
#endif
}
}
else if (byte == DLE && jandyPacketStarted == false)
Expand Down Expand Up @@ -731,24 +739,27 @@ int get_packet_new(int fd, unsigned char* packet)
// Break out of the loop if we exceed maximum packet
// length.
if (index >= AQ_MAXPKTLEN) {
logPacketError(packet, index);
logMessage(LOG_WARNING, "Serial packet too large\n");
log_packet(LOG_WARNING, "Bad receive packet ", packet, index);
//log_packet(LOG_WARNING, "Bad receive packet ", packet, index);
return 0;
break;
}
}

//logMessage(LOG_DEBUG, "Serial checksum, length %d got 0x%02hhx expected 0x%02hhx\n", index, packet[index-3], generate_checksum(packet, index));
if (jandyPacketStarted) {
if (generate_checksum(packet, index) != packet[index-3]){
if (check_jandy_checksum(packet, index) != true){
logPacketError(packet, index);
logMessage(LOG_WARNING, "Serial read bad Jandy checksum, ignoring\n");
log_packet(LOG_WARNING, "Bad receive packet ", packet, index);
//log_packet(LOG_WARNING, "Bad receive packet ", packet, index);
return 0;
}
} else if (pentairPacketStarted) {
if (check_pentair_checksum(packet, index) != true){
logPacketError(packet, index);
logMessage(LOG_WARNING, "Serial read bad Pentair checksum, ignoring\n");
log_packet(LOG_WARNING, "Bad receive packet ", packet, index);
//log_packet(LOG_WARNING, "Bad receive packet ", packet, index);
return 0;
}
}
Expand All @@ -758,12 +769,14 @@ int get_packet_new(int fd, unsigned char* packet)
log_packet(LOG_WARNING, "Bad receive packet ", packet, index);
return 0;
} else*/ if (index < AQ_MINPKTLEN && (jandyPacketStarted || pentairPacketStarted) ) { //NSF. Sometimes we get END sequence only, so just ignore.
logPacketError(packet, index);
logMessage(LOG_WARNING, "Serial read too small\n");
log_packet(LOG_WARNING, "Bad receive packet ", packet, index);
//log_packet(LOG_WARNING, "Bad receive packet ", packet, index);
return 0;
}

logMessage(LOG_DEBUG_SERIAL, "Serial read %d bytes\n",index);
logPacket(packet, index);
// Return the packet length.
return index;
}
Expand All @@ -773,6 +786,27 @@ int get_packet_new(int fd, unsigned char* packet)
#include <stdlib.h>
FILE *_fp;


bool check_pentair_checksum(unsigned char* packet, int length)
{
int i, sum, n;
n = packet[8] + 9;
sum = 0;
//printf("Pentair ");
for (i = 3; i < n; i++) {
sum += (int) packet[i];
//printf("+ (0x%02hhx) %d = %d ",packet[i],(int)packet[i],sum);
}

//printf("\nPentair checksum %d = %d (0x%02hhx) (0x%02hhx)\n",sum, (packet[length-1] * 256 + packet[length]),packet[length-1],packet[length]);

if (sum == (packet[length-1] * 256 + packet[length]))
return true;

return false;
}


int init_serial_port(char* file)
{
_fp = fopen ( file, "r" );
Expand Down Expand Up @@ -817,6 +851,23 @@ int get_packet(int fd, unsigned char* packet_buffer)
//printf("To 0x%02hhx, type %15.15s, length %2.2d ", packet_buffer[PKT_DEST], get_packet_type(packet_buffer, packet_length),packet_length);
//fputs ( line, stdout );

if (getProtocolType(packet_buffer)==JANDY) {
if (generate_checksum(packet_buffer, packet_length) != packet_buffer[packet_length-3]) {
logPacketError(packet_buffer, packet_length);
logMessage(LOG_WARNING, "Serial read bad Jandy checksum, ignoring\n");
} else
logPacket(packet_buffer, packet_length);
} else {
//check_pentair_checksum(packet_buffer, packet_length);
//check_pentair_checksum(packet_buffer, packet_length-1);
//check_pentair_checksum(packet_buffer, packet_length+1);
if (check_pentair_checksum(packet_buffer, packet_length-1) != true) {
logPacketError(packet_buffer, packet_length);
logMessage(LOG_WARNING, "Serial read bad Pentair checksum, ignoring\n");
} else
logPacket(packet_buffer, packet_length);
}

return packet_length;
}
return 0;
Expand Down Expand Up @@ -948,7 +999,10 @@ int get_packet_old(int fd, unsigned char* packet)
return 0;
}

//if (_config_parameters.debug_RSProtocol_packets || getLogLevel() >= LOG_DEBUG_SERIAL)
// logPacket(packet_buffer, packet_length);
logMessage(LOG_DEBUG_SERIAL, "Serial read %d bytes\n",index);

// Return the packet length.
return index;
}
Expand Down
3 changes: 0 additions & 3 deletions aq_serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,6 @@ SPILLOVER IS DISABLED WHILE SPA IS ON

/* AQUAPURE SWG */

// Number of set SWG % to 0 messages to ignore.
#define SWG_ZERO_IGNORE_COUNT 10

// These are madeup.
#define SWG_STATUS_OFF 0xFF
#define SWG_STATUS_UNKNOWN -128
Expand Down
43 changes: 32 additions & 11 deletions aqualinkd.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "pda.h"
#include "pentair_messages.h"
#include "pda_aq_programmer.h"
#include "packetLogger.h"
#include "version.h"


Expand Down Expand Up @@ -739,7 +740,10 @@ int main(int argc, char *argv[])
if (cmdln_debugRS485)
_config_parameters.debug_RSProtocol_packets = true;

setLoggingPrms(_config_parameters.log_level, _config_parameters.deamonize, _config_parameters.log_file);
if (_config_parameters.display_warnings_web == true)
setLoggingPrms(_config_parameters.log_level, _config_parameters.deamonize, _config_parameters.log_file, _aqualink_data.last_display_message);
else
setLoggingPrms(_config_parameters.log_level, _config_parameters.deamonize, _config_parameters.log_file, NULL);

logMessage(LOG_NOTICE, "%s v%s\n", AQUALINKD_NAME, AQUALINKD_VERSION);

Expand Down Expand Up @@ -779,6 +783,11 @@ int main(int argc, char *argv[])
//logMessage(LOG_NOTICE, "Use PDA 4 auxiliary info = %s\n", bool2text(_config_parameters.use_PDA_auxiliary));
logMessage(LOG_NOTICE, "Read Pentair Packets = %s\n", bool2text(_config_parameters.read_pentair_packets));
// logMessage (LOG_NOTICE, "Config serial_port = %s\n", config_parameters->serial_port);
logMessage(LOG_NOTICE, "Display warnings in web = %s\n", bool2text(_config_parameters.display_warnings_web));

if (_config_parameters.swg_zero_ignore > 0)
logMessage(LOG_NOTICE, "Ignore SWG 0 msg count = %d\n", _config_parameters.swg_zero_ignore);


for (i = 0; i < TOTAL_BUTONS; i++)
{
Expand All @@ -790,7 +799,15 @@ int main(int argc, char *argv[])
//printf("Pump %d %d %d\n",_aqualink_data.pumps[j].pumpID, _aqualink_data.pumps[j].buttonID, _aqualink_data.pumps[j].ptype);
}
}
logMessage(LOG_NOTICE, "Config BTN %-13s = label %-15s | VSP ID %-4s | PDAlabel %-15s | dzidx %d\n", _aqualink_data.aqbuttons[i].name, _aqualink_data.aqbuttons[i].label, vsp, _aqualink_data.aqbuttons[i].pda_label, _aqualink_data.aqbuttons[i].dz_idx);
if (!_config_parameters.pda_mode) {
logMessage(LOG_NOTICE, "Config BTN %-13s = label %-15s | VSP ID %-4s | dzidx %d | %s\n",
_aqualink_data.aqbuttons[i].name, _aqualink_data.aqbuttons[i].label, vsp, _aqualink_data.aqbuttons[i].dz_idx,
(i>0 && (i==_config_parameters.light_programming_button_pool || i==_config_parameters.light_programming_button_spa)?"Programable":"") );
} else {
logMessage(LOG_NOTICE, "Config BTN %-13s = label %-15s | VSP ID %-4s | PDAlabel %-15s | dzidx %d\n",
_aqualink_data.aqbuttons[i].name, _aqualink_data.aqbuttons[i].label, vsp,
_aqualink_data.aqbuttons[i].pda_label, _aqualink_data.aqbuttons[i].dz_idx );
}
//logMessage(LOG_NOTICE, "Button %d\n", i+1, _aqualink_data.aqbuttons[i].label , _aqualink_data.aqbuttons[i].dz_idx);
}

Expand Down Expand Up @@ -875,7 +892,7 @@ void logPacket(unsigned char *packet_buffer, int packet_length)
}
}
*/

/*
void logPacket_new(unsigned char* packet_buffer, int packet_length)
{
char buff[1000];
Expand Down Expand Up @@ -918,7 +935,7 @@ void logPacket(unsigned char *packet_buffer, int packet_length)
else
logMessage(LOG_DEBUG_SERIAL, "%s", buff);
}

*/

#define MAX_BLOCK_ACK 12
#define MAX_BUSY_ACK (50 + MAX_BLOCK_ACK)
Expand Down Expand Up @@ -1046,6 +1063,8 @@ void main_loop()
exit(EXIT_FAILURE);
}

startPacketLogger(_config_parameters.debug_RSProtocol_packets, _config_parameters.read_pentair_packets);

signal(SIGINT, intHandler);
signal(SIGTERM, intHandler);

Expand Down Expand Up @@ -1113,10 +1132,10 @@ void main_loop()
{
blank_read = 0;
changed = false;

/*
if (_config_parameters.debug_RSProtocol_packets || getLogLevel() >= LOG_DEBUG_SERIAL)
logPacket(packet_buffer, packet_length);

*/
if (packet_length > 0 && packet_buffer[PKT_DEST] == _config_parameters.device_id)
{

Expand Down Expand Up @@ -1196,13 +1215,14 @@ void main_loop()
if (packet_buffer[3] == CMD_PERCENT && _aqualink_data.active_thread.thread_id == 0)
{
// SWG can get ~10 messages to set to 0 then go back again for some reason, so don't go to 0 until 10 messages are received
if (swg_zero_cnt <= SWG_ZERO_IGNORE_COUNT && packet_buffer[4] == 0x00 && packet_buffer[5] == 0x73) {
logMessage(LOG_DEBUG, "Ignoring SWG set to %d due to packet packet count %d <= %d from control panel to SWG 0x%02hhx 0x%02hhx\n", (int)packet_buffer[4],swg_zero_cnt,SWG_ZERO_IGNORE_COUNT,packet_buffer[4],packet_buffer[5]);
if (swg_zero_cnt < _config_parameters.swg_zero_ignore && packet_buffer[4] == 0x00 && packet_buffer[5] == 0x73) {
logMessage(LOG_DEBUG, "Ignoring SWG set to %d due to packet packet count %d <= %d from control panel to SWG 0x%02hhx 0x%02hhx\n", (int)packet_buffer[4],swg_zero_cnt,_config_parameters.swg_zero_ignore,packet_buffer[4],packet_buffer[5]);
swg_zero_cnt++;
} else if (swg_zero_cnt > SWG_ZERO_IGNORE_COUNT && packet_buffer[4] == 0x00 && packet_buffer[5] == 0x73) {
} else if (swg_zero_cnt > _config_parameters.swg_zero_ignore && packet_buffer[4] == 0x00 && packet_buffer[5] == 0x73) {
_aqualink_data.swg_percent = (int)packet_buffer[4];
changed = true;
//logMessage(LOG_DEBUG, "SWG set to %d due to packet from control panel to SWG 0x%02hhx 0x%02hhx\n", _aqualink_data.swg_percent,packet_buffer[4],packet_buffer[5]);
//logMessage(LOG_DEBUG, "SWG set to %d due to packet packet count %d <= %d from control panel to SWG 0x%02hhx 0x%02hhx\n", (int)packet_buffer[4],swg_zero_cnt,SWG_ZERO_IGNORE_COUNT,packet_buffer[4],packet_buffer[5]);
//swg_zero_cnt++;
} else {
swg_zero_cnt = 0;
_aqualink_data.swg_percent = (int)packet_buffer[4];
Expand Down Expand Up @@ -1259,7 +1279,8 @@ void main_loop()
//}
}

if (_config_parameters.debug_RSProtocol_packets) closePacketLog();
//if (_config_parameters.debug_RSProtocol_packets) stopPacketLogger();
stopPacketLogger();
// Reset and close the port.
close_serial_port(rs_fd);
// Clear webbrowser
Expand Down
Loading

0 comments on commit e13deac

Please sign in to comment.