Skip to content

Commit

Permalink
#65: SWG percentage setting not working for PDA
Browse files Browse the repository at this point in the history
  • Loading branch information
ballle98 committed Aug 7, 2023
1 parent 633040f commit f58d52a
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 137 deletions.
8 changes: 4 additions & 4 deletions aq_programmer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,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 @@ -1376,10 +1377,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 @@ -999,7 +999,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
14 changes: 14 additions & 0 deletions 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 @@ -278,6 +291,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
91 changes: 64 additions & 27 deletions pda.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,30 @@ void set_pda_led(struct aqualinkled *led, char state)
void equiptment_update_cycle(int eqID) {
// If you have a -1, it's a reset to clear / update information.
int i;
// :TODO: need to add freeze protect and boost support to bitmask, perhaps sercive_mode
// TOTAL_BUTTONS is 20 so bits 21-31 should be available
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\n");

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 (_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);
}
}
}
// :TODO: This needs to go into the equipment status processing to turn FP off
// if (_aqualink_data->frz_protect_state == ON) {
// _aqualink_data->frz_protect_state = ENABLE;
// }
// :TODO: This needs to go into the equipment status processing to turn boost off
// if (_aqualink_data->boost) {
// setSWGboost(_aqualink_data, false);
// }
update_equiptment_bitmask = 0;
} else {
update_equiptment_bitmask |= (1 << (eqID+1));
Expand Down Expand Up @@ -235,14 +245,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 @@ -387,29 +396,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 @@ -604,6 +627,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,6 +648,14 @@ void process_pda_packet_msg_long_equiptment_status(const char *msg_line, int lin
_aqualink_data->frz_protect_state = ON;
LOG(PDA_LOG,LOG_DEBUG, "Freeze Protect is on\n");
}
else if ((index = rsm_strncasestr(msg, "BOOST", AQ_MSGLEN)) != NULL)
{
setSWGboost(_aqualink_data, true);
}
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 @@ -835,7 +872,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 f58d52a

Please sign in to comment.