From 45cf212c62cfa2c0ae3ee49c25ed482ecbb8a65a Mon Sep 17 00:00:00 2001 From: Lee_Ballard Date: Mon, 28 Jan 2019 12:50:14 -0600 Subject: [PATCH] #4: co-exist with PDA Introducing last active timer. This will release control 5 seconds after thread terminates until 30 seconds have expired and it's time to do another status update. --- aqualink.h | 2 -- aqualinkd.c | 19 ++++++++++++------- pda_menu.c | 15 ++++++++++++--- pda_menu.h | 1 + utils.c | 6 ------ 5 files changed, 25 insertions(+), 18 deletions(-) diff --git a/aqualink.h b/aqualink.h index 98b3732..9a074b8 100644 --- a/aqualink.h +++ b/aqualink.h @@ -115,10 +115,8 @@ struct aqualinkdata int open_websockets; //bool last_msg_was_status; //bool ar_swg_connected; - #ifdef AQ_DEBUG struct timespec last_active_time; struct timespec start_active_time; - #endif }; diff --git a/aqualinkd.c b/aqualinkd.c index 0d07cb6..ffe7fa7 100644 --- a/aqualinkd.c +++ b/aqualinkd.c @@ -832,7 +832,7 @@ int main(int argc, char *argv[]) exit(EXIT_SUCCESS); } -/* + void debugPacketPrint(unsigned char ID, unsigned char *packet_buffer, int packet_length) { char buff[1000]; @@ -859,9 +859,9 @@ void debugPacketPrint(unsigned char ID, unsigned char *packet_buffer, int packet cnt += sprintf(buff + cnt, "\n"); //logMessage(LOG_NOTICE, "- AQUA SWG - \n%s", buff); - if (_config_parameters.debug_RSProtocol_packets) - writePacketLog(buff); - else + //if (_config_parameters.debug_RSProtocol_packets) + // writePacketLog(buff); + //else logMessage(LOG_NOTICE, "%s", buff); } @@ -881,6 +881,7 @@ void debugPacket(unsigned char *packet_buffer, int packet_length) lastID = packet_buffer[PKT_DEST]; } +/* void logPacket(unsigned char *packet_buffer, int packet_length) { static unsigned char last_packet_buffer[AQ_MAXPKTLEN]; @@ -1138,17 +1139,21 @@ void main_loop() { blank_read = 0; changed = false; + if ((getLogLevel() >= LOG_DEBUG) && (packet_length > 0)) + { + debugPacketPrint(packet_buffer[PKT_DEST], packet_buffer, packet_length); + } /* 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) { - if (getLogLevel() >= LOG_DEBUG) - logMessage(LOG_DEBUG, "RS received packet of type %s length %d\n", get_packet_type(packet_buffer, packet_length), packet_length); + { + //logMessage(LOG_DEBUG, "RS received packet of type %s length %d\n", get_packet_type(packet_buffer, packet_length), packet_length); + } - //logMessage(LOG_DEBUG, "RS received packet of type %s length %d\n", get_packet_type(packet_buffer, packet_length), packet_length); //debugPacketPrint(0x00, packet_buffer, packet_length); //unsigned char ID, unsigned char *packet_buffer, int packet_length) /* diff --git a/pda_menu.c b/pda_menu.c index 86da6a3..5333194 100644 --- a/pda_menu.c +++ b/pda_menu.c @@ -176,8 +176,7 @@ bool process_pda_menu_packet(unsigned char* packet, int length) switch (packet[PKT_CMD]) { case CMD_PDA_CLEAR: - _hlightindex = -1; - memset(_menu, 0, PDA_LINES * (AQ_MSGLEN+1)); + rtn = pda_m_clear(); break; case CMD_MSG_LONG: if (packet[PKT_DATA] < 10) { @@ -305,4 +304,14 @@ bool NEW_process_pda_menu_packet_NEW(unsigned char* packet, int length) return rtn; } -#endif \ No newline at end of file +#endif + +/* +clear the menu +*/ +bool pda_m_clear() +{ + _hlightindex = -1; + memset(_menu, 0, PDA_LINES * (AQ_MSGLEN+1)); + return true; +} diff --git a/pda_menu.h b/pda_menu.h index 61c6f9d..92dff24 100644 --- a/pda_menu.h +++ b/pda_menu.h @@ -75,5 +75,6 @@ pda_menu_type pda_m_type(); int pda_find_m_index(char *text); int pda_find_m_index_case(char *text, int limit); //int pda_find_m_index_swcase(char *text, int limit); +bool pda_m_clear(); #endif diff --git a/utils.c b/utils.c index cea992d..69d4b38 100644 --- a/utils.c +++ b/utils.c @@ -29,9 +29,7 @@ #include #include -#ifdef AD_DEBUG #include -#endif #ifndef _UTILS_C_ #define _UTILS_C_ @@ -397,16 +395,12 @@ void logMessage(int msg_level, char *format, ...) if (msg_level == LOG_ERR) { fprintf(stderr, "%s", buffer); } else { -#ifndef AD_DEBUG - printf("%s", buffer); -#else struct timespec tspec; struct tm localtm; clock_gettime(CLOCK_REALTIME, &tspec); char timeStr[TIMESTAMP_LENGTH]; strftime(timeStr, sizeof(timeStr), "%H:%M:%S", localtime_r(&tspec.tv_sec, &localtm)); printf("%s.%03ld %s", timeStr, tspec.tv_nsec / 1000000L, buffer); -#endif } } }