Skip to content

Commit

Permalink
Merge pull request #249 from ballle98/dev/pda-swg
Browse files Browse the repository at this point in the history
Fixes for PDA SWG issues
  • Loading branch information
sfeakes authored Mar 30, 2024
2 parents 4aedcc7 + a62b7fe commit 28a50be
Show file tree
Hide file tree
Showing 7 changed files with 255 additions and 143 deletions.
5 changes: 5 additions & 0 deletions aq_panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,9 @@ int PANEL_SIZE();
void initButtons_RS16(struct aqualinkdata *aqdata);
#endif

// Used in equiptment_update_cycle() for additional items on EQUIPMENT STATUS
// TOTAL_BUTTONS is at most 20 so bits 21-31 should be available
#define BOOST_INDEX 21
#define FREEZE_PROTECT_INDEX 22

#endif
8 changes: 4 additions & 4 deletions aq_programmer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,7 @@ void _aq_programmer(program_type r_type, char *args, struct aqualinkdata *aq_dat
LOG(PROG_LOG, LOG_ERR, "could not create thread\n");
return;
}
break;
#endif
#ifdef AQ_PDA
case AQ_PDA_INIT:
Expand Down Expand Up @@ -1381,10 +1382,9 @@ void *set_aqualink_SWG( void *ptr )

#ifdef AQ_PDA
if (isPDA_PANEL) {
if (set_PDA_aqualink_SWG_setpoint(aq_data, val))
setSWGpercent(aq_data, val); // Don't use chageSWGpercent as we are in programming mode.
cleanAndTerminateThread(threadCtrl);
return ptr;
set_PDA_aqualink_SWG_setpoint(aq_data, val);
cleanAndTerminateThread(threadCtrl);
return ptr;
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion aqualinkd.c
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ void action_delayed_request()
{
//LOG(AQUA_LOG,LOG_NOTICE, "SWG BOST to %d\n", _aqualink_data.unactioned.value);
//if (_aqualink_data.ar_swg_status == SWG_STATUS_OFF) {
if (_aqualink_data.swg_led_state == OFF) {
if ((_aqualink_data.swg_led_state == OFF) && (_aqualink_data.boost == false)) {
LOG(AQUA_LOG,LOG_ERR, "SWG is off, can't Boost pool\n");
} else if (_aqualink_data.unactioned.value == _aqualink_data.boost ) {
LOG(AQUA_LOG,LOG_ERR, "Request to turn Boost %s ignored, Boost is already %s\n",_aqualink_data.unactioned.value?"On":"Off", _aqualink_data.boost?"On":"Off");
Expand Down
19 changes: 18 additions & 1 deletion devices_jandy.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ bool processPacketToSWG(unsigned char *packet, int packet_length, struct aqualin
static int swg_zero_cnt = 0;
bool changedAnything = false;

if (getLogLevel(DJAN_LOG) == LOG_DEBUG) {
char buff[1024];
beautifyPacket(buff, packet, packet_length, false);
LOG(DJAN_LOG,LOG_DEBUG, "%s", buff);
}


// Only read message from controller to SWG to set SWG Percent if we are not programming, as we might be changing this
if (packet[3] == CMD_PERCENT && aqdata->active_thread.thread_id == 0 && packet[4] != 0xFF) {
// In service or timeout mode SWG set % message is very strange. AR %% | HEX: 0x10|0x02|0x50|0x11|0xff|0x72|0x10|0x03|
Expand Down Expand Up @@ -154,6 +161,12 @@ bool processPacketFromSWG(unsigned char *packet, int packet_length, struct aqual
bool changedAnything = false;
_swg_noreply_cnt = 0;

if (getLogLevel(DJAN_LOG) == LOG_DEBUG) {
char buff[1024];
beautifyPacket(buff, packet, packet_length, true);
LOG(DJAN_LOG,LOG_DEBUG, "%s", buff);
}

if (packet[PKT_CMD] == CMD_PPM) {
//aqdata->ar_swg_device_status = packet[5];
setSWGdeviceStatus(aqdata, JANDY_DEVICE, packet[5]);
Expand Down Expand Up @@ -206,10 +219,13 @@ bool isSWGDeviceErrorState(unsigned char status)
}

void setSWGdeviceStatus(struct aqualinkdata *aqdata, emulation_type requester, unsigned char status) {
if (aqdata->ar_swg_device_status == status) {
static unsigned char last_status = SWG_STATUS_UNKNOWN;

if ((aqdata->ar_swg_device_status == status) || (last_status == status)) {
//LOG(DJAN_LOG, LOG_DEBUG, "Set SWG device state to '0x%02hhx', request from %d\n", aqdata->ar_swg_device_status, requester);
return;
}
last_status = status;

// If we get (ALLBUTTON, SWG_STATUS_CHECK_PCB), it sends this for many status, like clean cell.
// So if we are in one of those states, don't use it.
Expand Down Expand Up @@ -278,6 +294,7 @@ bool setSWGboost(struct aqualinkdata *aqdata, bool on) {
} else {
aqdata->boost = true;
aqdata->swg_percent = 101;
aqdata->swg_led_state = ON;
}

return true;
Expand Down
119 changes: 89 additions & 30 deletions pda.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,27 +133,57 @@ void set_pda_led(struct aqualinkled *led, char state)
}
}

// :TODO: Test what happens if there are more devices on than can fit on the status page
// :TODO: If web page is up PDA will not sleep therefore there is no wake and seeing
// the equipment page. Need to add support for determining filter pump on/off based on home
void equiptment_update_cycle(int eqID) {
// If you have a -1, it's a reset to clear / update information.
// TOTAL_BUTTONS is 20 so bits 21-31 available for BOOST, FREEZE PROTECT, etc.
int i;
static uint32_t update_equiptment_bitmask = 0;

if (eqID == -1) {
LOG(PDA_LOG,LOG_DEBUG, "Start new equiptment cycle\n");
LOG(PDA_LOG,LOG_DEBUG, "Start new equipment cycle bitmask 0x%04x\n",
update_equiptment_bitmask);

for (i=0; i < _aqualink_data->total_buttons - 2 ; i++) { // total_buttons - 2 because we don't get heaters in this cycle
if ((update_equiptment_bitmask & (1 << (i+1))) != (1 << (i+1))) {
if ((update_equiptment_bitmask & (1 << (i))) != (1 << (i))) {
if (_aqualink_data->aqbuttons[i].led->state != OFF) {
_aqualink_data->aqbuttons[i].led->state = OFF;
_aqualink_data->updated = true;
LOG(PDA_LOG,LOG_DEBUG, "Turn off equiptment id %d %s not seen in last cycle\n", i, _aqualink_data->aqbuttons[i].name);
LOG(PDA_LOG,LOG_DEBUG, "Turn off equipment id %d %s not seen in last cycle\n", i, _aqualink_data->aqbuttons[i].name);
}
}
}

if ((_aqualink_data->frz_protect_state == ON) &&
(! (update_equiptment_bitmask & (1 << FREEZE_PROTECT_INDEX)))) {
LOG(PDA_LOG,LOG_DEBUG, "Turn off freeze protect not seen in last cycle\n");
_aqualink_data->frz_protect_state = ENABLE;
}

if ((_aqualink_data->boost) &&
(! (update_equiptment_bitmask & (1 << BOOST_INDEX)))) {
LOG(PDA_LOG,LOG_DEBUG, "Turn off BOOST not seen in last cycle\n");
setSWGboost(_aqualink_data, false);
}
update_equiptment_bitmask = 0;
} else if ((eqID >= 0) && (eqID < 32)) {
update_equiptment_bitmask |= (1 << (eqID));
char *eqName = NULL;
if (eqID < TOTAL_BUTTONS) {
eqName = _aqualink_data->aqbuttons[eqID].name;
} else if (eqID == FREEZE_PROTECT_INDEX) {
eqName = "FREEZE PROTECT";
} else if (eqID == BOOST_INDEX) {
eqName = "BOOST";
} else {
eqName = "UNKNOWN";
}
LOG(PDA_LOG,LOG_DEBUG, "Added equipment id %d %s to updated cycle bitmask 0x%04x\n",
eqID, eqName, update_equiptment_bitmask);
} else {
update_equiptment_bitmask |= (1 << (eqID+1));
LOG(PDA_LOG,LOG_DEBUG, "Added equiptment id %d %s to updated cycle\n", eqID, _aqualink_data->aqbuttons[eqID].name);
LOG(PDA_LOG,LOG_ERR, "equiptment_update_cycle(%d) - Invalid eqID\n", eqID);
}
}

Expand Down Expand Up @@ -237,14 +267,13 @@ void process_pda_packet_msg_long_equipment_control(const char *msg)
{
LOG(PDA_LOG,LOG_DEBUG, "*** Found EQ CTL Status for %s = '%.*s'\n", _aqualink_data->aqbuttons[i].label, AQ_MSGLEN, msg);
set_pda_led(_aqualink_data->aqbuttons[i].led, msg[AQ_MSGLEN - 1]);
// Force SWG off if pump is off.
if ((i==0) && (_aqualink_data->aqbuttons[0].led->state == OFF )) {
setSWGoff(_aqualink_data);
}
}
}

// Force SWG off if pump is off.
if (_aqualink_data->aqbuttons[0].led->state == OFF )
setSWGoff(_aqualink_data);
//_aqualink_data->ar_swg_status = SWG_STATUS_OFF;

// NSF I think we need to check TEMP1 and TEMP2 and set Pool HEater and Spa heater directly, to support single device.
if (isSINGLE_DEV_PANEL){
if (strcasecmp(stripwhitespace(labelBuff), "TEMP1") == 0)
Expand Down Expand Up @@ -389,29 +418,43 @@ void process_pda_packet_msg_long_freeze_protect(const char *msg)
}
}

void process_pda_packet_msg_long_SWG(const char *msg)
void process_pda_packet_msg_long_SWG(int index, const char *msg)
{
//PDA Line 0 = SET AquaPure
//PDA Line 1 =
//PDA Line 2 =
//PDA Line 3 = SET POOL TO: 45%
//PDA Line 4 = SET SPA TO: 0%

// If spa is on, read SWG for spa, if not set SWG for pool
if (_aqualink_data->aqbuttons[SPA_INDEX].led->state != OFF) {
if (strncasecmp(msg, "SET SPA TO:", 11) == 0)
{
//_aqualink_data->swg_percent = atoi(msg + 13);
setSWGpercent(_aqualink_data, atoi(msg + 13));
char *ptr = NULL;
// Single Setpoint
// PDA Line 0 = SET AquaPure
// PDA Line 1 =
// PDA Line 2 =
// PDA Line 3 = SET TO 100%

// PDA Line 0 = SET AquaPure
// PDA Line 1 =
// PDA Line 2 =
// PDA Line 3 = SET TO: 20%

// Dual Setpoint
// PDA Line 0 = SET AquaPure
// PDA Line 1 =
// PDA Line 2 =
// PDA Line 3 = SET POOL TO: 45%
// PDA Line 4 = SET SPA TO: 0%

// Note: use pda_m_line(index) instead of msg because it is NULL terminated
if ((ptr = strcasestr(pda_m_line(index), "SET TO")) != NULL) {
setSWGpercent(_aqualink_data, atoi(ptr+7));
LOG(PDA_LOG,LOG_DEBUG, "swg_percent = %d\n", _aqualink_data->swg_percent);
} else if ((ptr = strcasestr(pda_m_line(index), "SET SPA TO")) != NULL) {
if (_aqualink_data->aqbuttons[SPA_INDEX].led->state != OFF) {
setSWGpercent(_aqualink_data, atoi(ptr+11));
LOG(PDA_LOG,LOG_DEBUG, "SPA swg_percent = %d\n", _aqualink_data->swg_percent);
}
} else {
if (strncasecmp(msg, "SET POOL TO:", 12) == 0)
{
//_aqualink_data->swg_percent = atoi(msg + 13);
setSWGpercent(_aqualink_data, atoi(msg + 13));
} else if ((ptr = strcasestr(pda_m_line(index), "SET POOL TO")) != NULL) {
if (_aqualink_data->aqbuttons[SPA_INDEX].led->state == OFF) {
setSWGpercent(_aqualink_data, atoi(ptr + 12));
LOG(PDA_LOG,LOG_DEBUG, "POOL swg_percent = %d\n", _aqualink_data->swg_percent);
}
}
} else if (index == 3) {
LOG(PDA_LOG,LOG_ERR, "process msg SWG POOL idx %d unmatched %s\n", index, pda_m_line(index));
}
}

Expand Down Expand Up @@ -606,6 +649,12 @@ void process_pda_packet_msg_long_equiptment_status(const char *msg_line, int lin
// FILTER PUMP
// CLEANER
//
// EQUIPMENT STATUS
//
// BOOST
// 23:59 REMAIN
// SALT 25500 PPM
// FILTER PUMP

// VSP Pumps are not read here, since they are over multiple lines.

Expand All @@ -619,8 +668,18 @@ void process_pda_packet_msg_long_equiptment_status(const char *msg_line, int lin
else if ((index = rsm_strncasestr(msg, "FREEZE PROTECT", AQ_MSGLEN)) != NULL)
{
_aqualink_data->frz_protect_state = ON;
equiptment_update_cycle(FREEZE_PROTECT_INDEX);
LOG(PDA_LOG,LOG_DEBUG, "Freeze Protect is on\n");
}
else if ((index = rsm_strncasestr(msg, "BOOST", AQ_MSGLEN)) != NULL)
{
setSWGboost(_aqualink_data, true);
equiptment_update_cycle(BOOST_INDEX);
}
else if ((_aqualink_data->boost) && ((index = rsm_strncasestr(msg, "REMAIN", AQ_MSGLEN)) != NULL))
{
snprintf(_aqualink_data->boost_msg, sizeof(_aqualink_data->boost_msg), "%s", msg+2);
}
else if ((index = rsm_strncasestr(msg, MSG_SWG_PCT, AQ_MSGLEN)) != NULL)
{
changeSWGpercent(_aqualink_data, atoi(index + strlen(MSG_SWG_PCT)));
Expand Down Expand Up @@ -833,7 +892,7 @@ bool process_pda_packet(unsigned char *packet, int length)
process_pda_packet_msg_long_freeze_protect(msg);
break;
case PM_AQUAPURE:
process_pda_packet_msg_long_SWG(msg);
process_pda_packet_msg_long_SWG(index, msg);
break;
case PM_AUX_LABEL_DEVICE:
process_pda_packet_msg_long_level_aux_device(msg);
Expand Down
Loading

0 comments on commit 28a50be

Please sign in to comment.