Skip to content

Commit

Permalink
#4: co-exist with PDA
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Lee_Ballard authored and ballle98 committed Sep 6, 2019
1 parent 3063a86 commit 45cf212
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 18 deletions.
2 changes: 0 additions & 2 deletions aqualink.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};


Expand Down
19 changes: 12 additions & 7 deletions aqualinkd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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);
}

Expand All @@ -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];
Expand Down Expand Up @@ -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)
/*
Expand Down
15 changes: 12 additions & 3 deletions pda_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -305,4 +304,14 @@ bool NEW_process_pda_menu_packet_NEW(unsigned char* packet, int length)

return rtn;
}
#endif
#endif

/*
clear the menu
*/
bool pda_m_clear()
{
_hlightindex = -1;
memset(_menu, 0, PDA_LINES * (AQ_MSGLEN+1));
return true;
}
1 change: 1 addition & 0 deletions pda_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 0 additions & 6 deletions utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
#include <ctype.h>
#include <fcntl.h>

#ifdef AD_DEBUG
#include <sys/time.h>
#endif

#ifndef _UTILS_C_
#define _UTILS_C_
Expand Down Expand Up @@ -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
}
}
}
Expand Down

0 comments on commit 45cf212

Please sign in to comment.