Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ballle98/AqualinkD#42: memcpy-param-overlap in PDA Shift processing #87

Merged
merged 1 commit into from
Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions pda_aq_programmer.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,23 @@ bool waitForPDAnextMenu(struct aqualinkdata *aq_data) {

bool loopover_devices(struct aqualinkdata *aq_data) {
int i;

int index = -1;
if (! goto_pda_menu(aq_data, PM_EQUIPTMENT_CONTROL)) {
//logMessage(LOG_ERR, "PDA :- can't find main menu\n");
logMessage(LOG_ERR, "loopover_devices :- can't goto PM_EQUIPTMENT_CONTROL menu\n");
//cleanAndTerminateThread(threadCtrl);
return false;
}

// Should look for message "ALL OFF", that's end of device list.
for (i=0; i < 18 && pda_find_m_index("ALL OFF") == -1 ; i++) {
for (i=0; i < 18 && (index = pda_find_m_index("ALL OFF")) == -1 ; i++) {
send_cmd(KEY_PDA_DOWN);
//while (get_aq_cmd_length() > 0) { delay(200); }
//waitForPDAMessageType(aq_data,CMD_PDA_HIGHLIGHT,3);
waitForMessage(aq_data, NULL, 1);
// Wait for highlight change or shift and update of current line
waitForPDAMessageTypes(aq_data,CMD_PDA_HIGHLIGHT,CMD_MSG_LONG,8);
}
if (index == -1) {
logMessage(LOG_ERR, "loopover_devices :- can't find ALL OFF\n");
return false;
}

return true;
}

Expand All @@ -170,7 +172,7 @@ bool find_pda_menu_item(struct aqualinkdata *aq_data, char *menuText, int charli
send_cmd(KEY_PDA_DOWN);
//delay(500);
//wait_for_empty_cmd_buffer();
waitForPDAMessageType(aq_data,CMD_PDA_HIGHLIGHT,2);
waitForPDAMessageTypes(aq_data,CMD_PDA_HIGHLIGHT,CMD_MSG_LONG,8);
//waitForMessage(aq_data, NULL, 1);
index = (charlimit == 0)?pda_find_m_index(menuText):pda_find_m_index_case(menuText, charlimit);
if (index >= 0) {
Expand All @@ -183,7 +185,8 @@ bool find_pda_menu_item(struct aqualinkdata *aq_data, char *menuText, int charli
return false;
}
} else {
logMessage(LOG_ERR, "PDA Device programmer couldn't find menu item '%s'\n",menuText);
logMessage(LOG_ERR, "PDA Device programmer couldn't find menu item '%s' in menu %d index %d\n",
menuText, pda_m_type(), index);
return false;
}
}
Expand Down Expand Up @@ -274,7 +277,7 @@ bool select_pda_menu_item(struct aqualinkdata *aq_data, char *menuText, bool wai
return true;
}

logMessage(LOG_ERR, "PDA Device programmer couldn't selected menu item '%s' at index %d\n",menuText, index);
logMessage(LOG_ERR, "PDA Device programmer couldn't select menu item '%s' menu %d\n",menuText, pda_m_type());
return false;
}

Expand Down Expand Up @@ -303,6 +306,10 @@ bool goto_pda_menu(struct aqualinkdata *aq_data, pda_menu_type menu) {

while (ret && (pda_m_type() != menu)) {
switch (menu) {
case PM_HOME:
send_cmd(KEY_PDA_BACK);
ret = waitForPDAnextMenu(aq_data);
break;
case PM_EQUIPTMENT_CONTROL:
if (pda_m_type() == PM_HOME) {
ret = select_pda_menu_item(aq_data, "EQUIPMENT ON/OFF", true);
Expand Down Expand Up @@ -410,7 +417,8 @@ bool goto_pda_menu(struct aqualinkdata *aq_data, pda_menu_type menu) {
menu, pda_m_type());
}
if (pda_m_type() != menu) {
logMessage(LOG_ERR, "PDA Device programmer didn't find a requested menu\n");
logMessage(LOG_ERR, "PDA Device programmer didn't find a requested menu %d, current %d\n",
menu, pda_m_type());
return false;
}

Expand Down Expand Up @@ -441,7 +449,7 @@ void *set_aqualink_PDA_device_on_off( void *ptr )
logMessage(LOG_INFO, "PDA Device On/Off, device '%s', state %d\n",aq_data->aqbuttons[device].pda_label,state);

if (! goto_pda_menu(aq_data, PM_EQUIPTMENT_CONTROL)) {
logMessage(LOG_ERR, "PDA Device On/Off :- can't find main menu\n");
logMessage(LOG_ERR, "PDA Device On/Off :- can't find EQUIPTMENT CONTROL menu\n");
cleanAndTerminateThread(threadCtrl);
return ptr;
}
Expand Down Expand Up @@ -497,8 +505,6 @@ void *set_aqualink_PDA_device_on_off( void *ptr )

}



void *get_aqualink_PDA_device_status( void *ptr )
{
struct programmingThreadCtrl *threadCtrl;
Expand Down Expand Up @@ -576,6 +582,10 @@ void *set_aqualink_PDA_init( void *ptr )
logMessage(LOG_ERR, "PDA Init :- Error getting freeze setpoints\n");
}

// shift line test
// goto_pda_menu(aq_data,PM_SYSTEM_SETUP);
// select_pda_menu_item(aq_data, "SERVICE INFO", true);

pda_reset_sleep();

cleanAndTerminateThread(threadCtrl);
Expand Down Expand Up @@ -747,7 +757,7 @@ bool set_PDA_numeric_field_value(struct aqualinkdata *aq_data, int val, int *cur
if (select_label != NULL) {
// :TODO: Should probably change below to call find_pda_menu_item(), rather than doing it here
// If we lease this, need to limit on the number of loops
while ( strncasecmp(pda_m_hlight(), select_label, 8) != 0 ) {
while ( strncasecmp(pda_m_hlight(), select_label, strlen(select_label)) != 0 ) {
send_cmd(KEY_PDA_DOWN);
delay(500); // Last message probably was CMD_PDA_HIGHLIGHT, so wait before checking.
waitForPDAMessageType(aq_data,CMD_PDA_HIGHLIGHT,2);
Expand Down
27 changes: 24 additions & 3 deletions pda_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ Line 0 = EQUIPMENT
bool process_pda_menu_packet(unsigned char* packet, int length)
{
bool rtn = true;
signed char first_line;
signed char last_line;
signed char line_shift;
signed char i;

switch (packet[PKT_CMD]) {
case CMD_PDA_CLEAR:
_hlightindex = -1;
Expand Down Expand Up @@ -200,9 +205,25 @@ bool process_pda_menu_packet(unsigned char* packet, int length)
if (getLogLevel() >= LOG_DEBUG){print_menu();}
break;
case CMD_PDA_SHIFTLINES:
memcpy(_menu[1], _menu[2], (PDA_LINES-1) * (AQ_MSGLEN+1) );
// press up from top - shift menu down by 1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix the other code is to test the fic

// PDA Shif | HEX: 0x10|0x02|0x62|0x0f|0x01|0x08|0x01|0x8d|0x10|0x03|
// press down from bottom - shift menu up by 1
// PDA Shif | HEX: 0x10|0x02|0x62|0x0f|0x01|0x08|0xff|0x8b|0x10|0x03|
first_line = (signed char)(packet[4]);
last_line = (signed char)(packet[5]);
line_shift = (signed char)(packet[6]);
logMessage(LOG_DEBUG, "\n");
if (line_shift < 0) {
for (i = first_line-line_shift; i <= last_line; i++) {
memcpy(_menu[i+line_shift], _menu[i], AQ_MSGLEN+1);
}
} else {
for (i = last_line; i >= first_line+line_shift; i--) {
memcpy(_menu[i], _menu[i-line_shift], AQ_MSGLEN+1);
}
}
if (getLogLevel() >= LOG_DEBUG){print_menu();}
break;
break;
}

return rtn;
Expand Down Expand Up @@ -284,4 +305,4 @@ bool NEW_process_pda_menu_packet_NEW(unsigned char* packet, int length)

return rtn;
}
#endif
#endif