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 Jul 20, 2019
1 parent d653388 commit 4af6056
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 22 deletions.
2 changes: 1 addition & 1 deletion aq_programmer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1510,4 +1510,4 @@ const char *ptypeName(program_type type)
return "Unknown";
break;
}
}
}
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
70 changes: 62 additions & 8 deletions aqualinkd.c
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,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 @@ -833,9 +833,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 @@ -855,6 +855,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 @@ -920,6 +921,56 @@ void logPacket(unsigned char *packet_buffer, int packet_length)
#define MAX_BLOCK_ACK 12
#define MAX_BUSY_ACK (50 + MAX_BLOCK_ACK)

// :TODO: enable last active
#if 0
bool bPDA_in_standby = false;
if (_aqualink_data.active_thread.thread_id == 0)
{
time_t now;
time (&now);
if (difftime (now, _aqualink_data.last_active_time) > 65)
{
aq_programmer (AQ_PDA_DEVICE_STATUS, NULL,
&_aqualink_data);
}
else if (difftime (now, _aqualink_data.last_active_time) > 5)
{
bPDA_in_standby = true;
pda_m_clear ();
}
}
// Can only send command to status message on PDA.
if (_config_parameters.pda_mode == true
&& packet_buffer[PKT_CMD] == CMD_STATUS)
{
if ((_aqualink_data.active_thread.thread_id == 0)
&& bPDA_in_standby)
{
logMessage (LOG_DEBUG, "NO STATUS ACK\n");
}
else
{
send_ack (rs_fd, pop_aq_cmd (&_aqualink_data));
}
}
else if (_config_parameters.pda_mode == true
&& packet_buffer[PKT_CMD] == CMD_PROBE)
{
if ((_aqualink_data.active_thread.thread_id == 0)
&& bPDA_in_standby)
{
logMessage (LOG_DEBUG, "NO PROBE ACK\n");
}
else
{
send_ack (rs_fd, NUL);
}
}
else
{
send_ack(rs_fd, NUL);
}
#endif

void caculate_ack_packet(int rs_fd, unsigned char *packet_buffer) {
static int delayAckCnt = 0;
Expand Down Expand Up @@ -1106,17 +1157,20 @@ 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 @@ -169,8 +169,7 @@ bool process_pda_menu_packet(unsigned char* packet, int length)
bool rtn = true;
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 @@ -282,4 +281,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
9 changes: 1 addition & 8 deletions utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@
#include <sys/stat.h>
#include <time.h>
#include <ctype.h>

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

#ifndef _UTILS_C_
#define _UTILS_C_
Expand Down Expand Up @@ -344,16 +341,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 Expand Up @@ -560,4 +553,4 @@ void writePacketLog(char *buffer) {
}
void closePacketLog() {
fclose(_packetLogFile);
}
}

0 comments on commit 4af6056

Please sign in to comment.