17
17
#include "init_buttons.h"
18
18
19
19
bool waitForPDAMessageHighlight (struct aqualinkdata * aq_data , int highlighIndex , int numMessageReceived );
20
- bool waitForPDAMessageType (struct aqualinkdata * aq_data , unsigned char mtype , int numMessageReceived );
20
+ static bool waitForPDAMessageType (struct aqualinkdata * aq_data , unsigned char mtype ,
21
+ unsigned long sec , unsigned long msec );
21
22
bool goto_pda_menu (struct aqualinkdata * aq_data , pda_menu_type menu );
22
23
bool wait_pda_selected_item (struct aqualinkdata * aq_data );
23
24
bool waitForPDAnextMenu (struct aqualinkdata * aq_data );
@@ -30,7 +31,7 @@ static pda_type _PDA_Type;
30
31
bool wait_pda_selected_item (struct aqualinkdata * aq_data )
31
32
{
32
33
while (pda_m_hlightindex () == -1 ){
33
- waitForPDAMessageType (aq_data ,CMD_PDA_HIGHLIGHT ,10 );
34
+ waitForPDAMessageType (aq_data ,CMD_PDA_HIGHLIGHT ,2 , 0 );
34
35
}
35
36
36
37
if (pda_m_hlightindex () == -1 )
@@ -40,8 +41,8 @@ bool wait_pda_selected_item(struct aqualinkdata *aq_data)
40
41
}
41
42
42
43
bool waitForPDAnextMenu (struct aqualinkdata * aq_data ) {
43
- waitForPDAMessageType (aq_data ,CMD_PDA_CLEAR ,10 );
44
- return waitForPDAMessageType (aq_data ,CMD_PDA_HIGHLIGHT ,15 );
44
+ waitForPDAMessageType (aq_data ,CMD_PDA_CLEAR ,2 , 0 );
45
+ return waitForPDAMessageType (aq_data ,CMD_PDA_HIGHLIGHT ,3 , 0 );
45
46
}
46
47
47
48
bool loopover_devices (struct aqualinkdata * aq_data ) {
@@ -80,7 +81,7 @@ bool find_pda_menu_item(struct aqualinkdata *aq_data, char *menuText, int charli
80
81
send_cmd (KEY_PDA_DOWN );
81
82
//delay(500);
82
83
//wait_for_empty_cmd_buffer();
83
- waitForPDAMessageType (aq_data ,CMD_PDA_HIGHLIGHT ,2 );
84
+ waitForPDAMessageType (aq_data ,CMD_PDA_HIGHLIGHT ,0 , 500 );
84
85
//waitForMessage(aq_data, NULL, 1);
85
86
index = (charlimit == 0 )?pda_find_m_index (menuText ):pda_find_m_index_case (menuText , charlimit );
86
87
if (index >= 0 ) {
@@ -150,7 +151,7 @@ bool goto_pda_menu(struct aqualinkdata *aq_data, pda_menu_type menu) {
150
151
//logMessage(LOG_DEBUG, "******************PDA Device programmer selected back button\n",menu);
151
152
waitForPDAnextMenu (aq_data );
152
153
} else {
153
- waitForPDAMessageType (aq_data ,CMD_PDA_HIGHLIGHT ,15 );
154
+ waitForPDAMessageType (aq_data ,CMD_PDA_HIGHLIGHT ,3 , 0 );
154
155
}
155
156
//logMessage(LOG_DEBUG, "******************PDA Device programmer menu type %d\n",pda_m_type());
156
157
//if (!wait_for_empty_cmd_buffer() || i++ > 6)
@@ -436,32 +437,55 @@ bool waitForPDAMessageHighlight(struct aqualinkdata *aq_data, int highlighIndex,
436
437
}
437
438
438
439
439
- bool waitForPDAMessageType (struct aqualinkdata * aq_data , unsigned char mtype , int numMessageReceived )
440
+ bool waitForPDAMessageType (struct aqualinkdata * aq_data , unsigned char mtype ,
441
+ unsigned long sec , unsigned long msec )
440
442
{
441
- logMessage (LOG_DEBUG , "waitForPDAMessageType 0x%02hhx\n" ,mtype );
442
-
443
443
int i = 0 ;
444
+
444
445
pthread_mutex_init (& aq_data -> active_thread .thread_mutex , NULL );
445
- pthread_mutex_lock (& aq_data -> active_thread .thread_mutex );
446
446
447
- while ( ++ i <= numMessageReceived )
448
- {
449
- logMessage (LOG_DEBUG , "waitForPDAMessageType 0x%02hhx, last message type was 0x%02hhx (%d of %d)\n" ,mtype ,aq_data -> last_packet_type ,i ,numMessageReceived );
447
+ struct timespec max_wait ;
448
+ int ret = 0 ;
450
449
451
- if (aq_data -> last_packet_type == mtype ) break ;
450
+ logMessage (LOG_DEBUG , "waitForPDAMessageType 0x%02hhx, %lu.%03lu sec\n" ,
451
+ mtype , sec , msec );
452
+ if (msec > 999 )
453
+ {
454
+ logMessage (LOG_ERR , "waitForPDAMessageType INVALID msec value %lu\n" , msec );
455
+ }
456
+ clock_gettime (CLOCK_REALTIME , & max_wait );
457
+ max_wait .tv_sec += sec ;
458
+ max_wait .tv_nsec += msec * 1000000 ;
459
+ if (max_wait .tv_nsec > 999999999L )
460
+ {
461
+ max_wait .tv_nsec -= 1000000000L ;
462
+ max_wait .tv_sec ++ ;
463
+ }
452
464
453
- pthread_cond_init (& aq_data -> active_thread .thread_cond , NULL );
454
- pthread_cond_wait (& aq_data -> active_thread .thread_cond , & aq_data -> active_thread .thread_mutex );
455
- }
465
+ pthread_cond_init (& aq_data -> active_thread .thread_cond , NULL );
466
+
467
+ pthread_mutex_lock (& aq_data -> active_thread .thread_mutex );
468
+
469
+ do {
470
+ i ++ ;
471
+ logMessage (LOG_DEBUG , "waitForPDAMessageType 0x%02hhx, last message type was 0x%02hhx (%d)\n" ,
472
+ mtype ,aq_data -> last_packet_type ,i );
473
+
474
+ if ((ret = pthread_cond_timedwait (& aq_data -> active_thread .thread_cond ,
475
+ & aq_data -> active_thread .thread_mutex , & max_wait )))
476
+ {
477
+ logMessage (LOG_ERR , "waitForPDAMessageType: did not receive 0x%02hhx %s\n" ,
478
+ mtype , strerror (ret ));
479
+ break ;
480
+ }
481
+ } while (aq_data -> last_packet_type != mtype );
456
482
457
483
pthread_mutex_unlock (& aq_data -> active_thread .thread_mutex );
458
-
459
- if (aq_data -> last_packet_type != mtype ) {
460
- //logMessage(LOG_ERR, "Could not select MENU of Aqualink control panel\n");
461
- logMessage (LOG_DEBUG , "waitForPDAMessageType: did not receive 0x%02hhx\n" ,mtype );
462
- return false;
463
- } else
464
- logMessage (LOG_DEBUG , "waitForPDAMessageType: received 0x%02hhx\n" ,mtype );
484
+ if (ret )
485
+ {
486
+ return false;
487
+ }
488
+ logMessage (LOG_DEBUG , "waitForPDAMessageType: received 0x%02hhx\n" ,mtype );
465
489
466
490
return true;
467
491
}
@@ -474,7 +498,7 @@ bool set_PDA_numeric_field_value(struct aqualinkdata *aq_data, int val, int *cur
474
498
while ( strncasecmp (pda_m_hlight (), select_label , 8 ) != 0 ) {
475
499
send_cmd (KEY_PDA_DOWN );
476
500
delay (500 ); // Last message probably was CMD_PDA_HIGHLIGHT, so wait before checking.
477
- waitForPDAMessageType (aq_data ,CMD_PDA_HIGHLIGHT ,2 );
501
+ waitForPDAMessageType (aq_data ,CMD_PDA_HIGHLIGHT ,0 , 500 );
478
502
}
479
503
480
504
send_cmd (KEY_PDA_SELECT );
@@ -807,4 +831,4 @@ The SCALE setting is fixed to RPM for the Jandy ePumpTM DC, Jandy ePumpTM AC, an
807
831
The SCALE setting is fixed to GPM for the IntelliFlo® VF
808
832
809
833
There are eight (8) default speed presets for each variable speed pump.
810
- */
834
+ */
0 commit comments