PDA-Update
sfeakes 2024-05-03 21:39:17 -05:00
parent 1365e76628
commit 54c8584c3f
10 changed files with 223 additions and 48 deletions

View File

@ -360,6 +360,9 @@ SPILLOVER IS DISABLED WHILE SPA IS ON
#define KEY_IAQTCH_PREV_PAGE 0x20
#define KEY_IAQTCH_NEXT_PAGE 0x21
#define KEY_IAQTCH_PREV_PAGE_ALTERNATE 0x1d // System setup prev
#define KEY_IAQTCH_NEXT_PAGE_ALTERNATE 0x1e // System setup next
// PAGE1 (Horosontal keys) (These are duplicate so probable delete)
#define KEY_IAQTCH_HOMEP_KEY01 0x11
#define KEY_IAQTCH_HOMEP_KEY02 0x12
@ -406,10 +409,13 @@ SPILLOVER IS DISABLED WHILE SPA IS ON
#define IAQ_PAGE_ONETOUCH 0x4d
#define IAQ_PAGE_COLOR_LIGHT 0x48
#define IAQ_PAGE_SYSTEM_SETUP 0x14
#define IAQ_PAGE_SYSTEM_SETUP2 0x49
#define IAQ_PAGE_SYSTEM_SETUP3 0x4a
#define IAQ_PAGE_VSP_SETUP 0x2d
#define IAQ_PAGE_FREEZE_PROTECT 0x11
#define IAQ_PAGE_LABEL_AUX 0x32
//#define IAQ_PAGE_START_BOOST 0x3f
#define IAQ_PAGE_DEGREES 0xFF // Added this as never want to actually select the page, just go to it.

View File

@ -1891,7 +1891,7 @@ void main_loop()
_aqualink_data.updated = true; // FORCE UPDATE SINCE THIS IS NOT WORKING YET
caculate_ack_packet(rs_fd, packet_buffer, IAQTOUCH);
}
if (_aqualink_data.simulator_active == SIM_NONE) {
else /*if (_aqualink_data.simulator_active == SIM_NONE)*/ {
caculate_ack_packet(rs_fd, packet_buffer, AQUAPDA);
}
}

View File

@ -76,10 +76,9 @@ char _tableInformation[IAQ_MSG_TABLE_LINES][IAQT_TABLE_MSGLEN+1];
struct iaqt_page_button _pageButtons[IAQ_PAGE_BUTTONS];
struct iaqt_page_button _homeButtons[IAQ_PAGE_BUTTONS];
// Need to cache these two pages, as only get updates after initial load.
struct iaqt_page_button _devicePageButtons[IAQ_PAGE_BUTTONS];
//struct iaqt_page_button _devicePage2Buttons[IAQ_PAGE_BUTTONS];
struct iaqt_page_button _deviceSystemSetupButtons[IAQ_PAGE_BUTTONS];
// Need to cache these pages, as only get updates after initial load.
struct iaqt_page_button _devicePageButtons[3][IAQ_PAGE_BUTTONS];
struct iaqt_page_button _deviceSystemSetupButtons[3][IAQ_PAGE_BUTTONS];
unsigned char iaqtLastMsg()
{
@ -132,16 +131,22 @@ struct iaqt_page_button *iaqtFindButtonByIndex(int index) {
struct iaqt_page_button *buttons;
// NSF Need to merge this from iaqtFindButtonByLabel function
if (_currentPage == IAQ_PAGE_DEVICES ||
_currentPage == IAQ_PAGE_DEVICES2 ||
_currentPage == IAQ_PAGE_DEVICES3)
buttons = _devicePageButtons;
if (_currentPage == IAQ_PAGE_DEVICES)
buttons = _devicePageButtons[0];
else if (_currentPage == IAQ_PAGE_DEVICES2)
buttons = _devicePageButtons[1];
else if (_currentPage == IAQ_PAGE_DEVICES3)
buttons = _devicePageButtons[2];
/*
else if (_currentPage == IAQ_PAGE_DEVICES2 )
buttons = _devicePage2Buttons;
*/
else if (_currentPage == IAQ_PAGE_SYSTEM_SETUP )
buttons = _deviceSystemSetupButtons;
buttons = _deviceSystemSetupButtons[0];
else if (_currentPage == IAQ_PAGE_SYSTEM_SETUP2 )
buttons = _deviceSystemSetupButtons[1];
else if (_currentPage == IAQ_PAGE_SYSTEM_SETUP3 )
buttons = _deviceSystemSetupButtons[2];
else if (_currentPage == IAQ_PAGE_HOME )
buttons = _homeButtons;
else
@ -158,14 +163,21 @@ struct iaqt_page_button *iaqtFindButtonByLabel(char *label) {
int i;
struct iaqt_page_button *buttons;
if (_currentPage == IAQ_PAGE_DEVICES ||
_currentPage == IAQ_PAGE_DEVICES2 ||
_currentPage == IAQ_PAGE_DEVICES3)
buttons = _devicePageButtons;
if (_currentPage == IAQ_PAGE_DEVICES)
buttons = _devicePageButtons[0];
else if (_currentPage == IAQ_PAGE_DEVICES2)
buttons = _devicePageButtons[1];
else if (_currentPage == IAQ_PAGE_DEVICES3)
buttons = _devicePageButtons[2];
//else if (_currentPage == IAQ_PAGE_DEVICES2 )
// buttons = _devicePage2Buttons;
else if (_currentPage == IAQ_PAGE_SYSTEM_SETUP )
buttons = _deviceSystemSetupButtons;
buttons = _deviceSystemSetupButtons[0];
else if (_currentPage == IAQ_PAGE_SYSTEM_SETUP2 )
buttons = _deviceSystemSetupButtons[1];
else if (_currentPage == IAQ_PAGE_SYSTEM_SETUP3 )
buttons = _deviceSystemSetupButtons[2];
else if (_currentPage == IAQ_PAGE_HOME )
buttons = _homeButtons;
else
@ -279,19 +291,24 @@ void processPageButton(unsigned char *message, int length, struct aqualinkdata *
struct iaqt_page_button *button;
int index = (int)message[PKT_IAQT_BUTINDX];
if (_currentPageLoading == IAQ_PAGE_DEVICES ||
_currentPageLoading == IAQ_PAGE_DEVICES2 ||
_currentPageLoading == IAQ_PAGE_DEVICES3 )
button = &_devicePageButtons[index];
//else if (_currentPageLoading == IAQ_PAGE_DEVICES2 )
// button = &_devicePage2Buttons[index];
else if (_currentPageLoading == IAQ_PAGE_SYSTEM_SETUP )
button = &_deviceSystemSetupButtons[index];
if (_currentPageLoading == IAQ_PAGE_DEVICES)
button = &_devicePageButtons[0][index];
else if (_currentPageLoading == IAQ_PAGE_DEVICES2)
button = &_devicePageButtons[1][index];
else if (_currentPageLoading == IAQ_PAGE_DEVICES3)
button = &_devicePageButtons[2][index];
else if (_currentPageLoading == IAQ_PAGE_SYSTEM_SETUP)
button = &_deviceSystemSetupButtons[0][index];
else if (_currentPageLoading == IAQ_PAGE_SYSTEM_SETUP2)
button = &_deviceSystemSetupButtons[1][index];
else if (_currentPageLoading == IAQ_PAGE_SYSTEM_SETUP3)
button = &_deviceSystemSetupButtons[2][index];
else if (_currentPageLoading == IAQ_PAGE_HOME )
button = &_homeButtons[index];
else {
button = &_pageButtons[index];
LOG(IAQT_LOG,LOG_WARNING, "Not sure where to add Button %d %s - LoadingPage=%s\n",index,button->name,iaqt_page_name(_currentPageLoading));
// if _currentPageLoading = 0x00 then we should use current page
LOG(IAQT_LOG,LOG_WARNING, "Not sure where to add Button %d %s - LoadingPage = %s\n",index,button->name,iaqt_page_name(_currentPageLoading));
}
button->state = message[PKT_IAQT_BUTSTATE];
@ -309,15 +326,37 @@ void processPageButton(unsigned char *message, int length, struct aqualinkdata *
memset(button->name, 0, sizeof(button->name));
rsm_strncpy_nul2sp((char *)button->name, &message[PKT_IAQT_BUTDATA], IAQT_MSGLEN, length-PKT_IAQT_BUTDATA-3);
LOG(IAQT_LOG,LOG_DEBUG, "Added Button %d %s - LoadingPage=%s\n",index,button->name,iaqt_page_name(_currentPageLoading));
LOG(IAQT_LOG,LOG_DEBUG, "Added Button %d %s - LoadingPage = %s\n",index,button->name,iaqt_page_name(_currentPageLoading));
// This get's called or every device state change in PDA mode, since we page over all the devices.
// So capture and update the device state
if (isPDA_PANEL) {
for (int i = 0; i < aq_data->total_buttons; i++)
if (isPDA_PANEL || PANEL_SIZE() >= 16 ) {
int start = 0;
int end = aq_data->total_buttons;
#ifdef AQ_RS16
if (PANEL_SIZE() >= 16) {
start = aq_data->rs16_vbutton_start;
end = aq_data->rs16_vbutton_end + 1; // Using < in comparison and not <=, so +1
//printf("************ CHECK RS16 BUTTONS ************\n");
}
#endif
for (int i = start; i < end; i++)
{
if (rsm_strmatch(button->name, aq_data->aqbuttons[i].label) == 0)
int rtn=-1;
//LOG(IAQT_LOG,LOG_DEBUG, "Button compare '%s' to '%s'\n",button->name, aq_data->aqbuttons[i].label);
// If we are loading HOME page then simply button name is the label ie "Aux3"
// If loading DEVICES? page then button name + statusis "Aux3 OFF "
if (_currentPageLoading == IAQ_PAGE_HOME)
rtn = rsm_strmatch((const char *)button->name, aq_data->aqbuttons[i].label);
else
rtn = rsm_strmatch_ignore((const char *)button->name, aq_data->aqbuttons[i].label,5); // 5 = 3 chars and 2 spaces ' OFF '
if (rtn == 0)
{
LOG(IAQT_LOG,LOG_DEBUG, "*** Found Status for %s state 0x%02hhx\n", aq_data->aqbuttons[i].label, button->state);
switch(button->state) {
@ -528,6 +567,7 @@ void processPage(struct aqualinkdata *aq_data)
{
//static int _home_cnt = 0;
int i;
int dp = 0;
LOG(IAQT_LOG,LOG_INFO, "Page: %s | 0x%02hhx\n",iaqt_page_name(_currentPage),_currentPage);
@ -546,7 +586,7 @@ void processPage(struct aqualinkdata *aq_data)
iaqt_queue_cmd(KEY_IAQTCH_KEY02);
} else {
iaqt_pump_update(aq_data, -1); // Reset pumps.
if (isPDA_PANEL && !in_iaqt_programming_mode(aq_data) ) {
if ( (isPDA_PANEL || PANEL_SIZE() >= 16) && !in_iaqt_programming_mode(aq_data) ) {
iaqt_queue_cmd(KEY_IAQTCH_HOME);
}
}
@ -554,14 +594,20 @@ void processPage(struct aqualinkdata *aq_data)
case IAQ_PAGE_DEVICES:
case IAQ_PAGE_DEVICES2:
case IAQ_PAGE_DEVICES3:
if (_currentPage == IAQ_PAGE_DEVICES)
dp = 0;
else if (_currentPage == IAQ_PAGE_DEVICES2)
dp = 1;
else if (_currentPage == IAQ_PAGE_DEVICES3)
dp = 2;
//LOG(IAQT_LOG,LOG_INFO, "Devices Page #1:-\n");
debugPrintButtons(_devicePageButtons);
debugPrintButtons(_devicePageButtons[dp]);
// If Button 15 has type 0x02 then we have previous, if 0x00 nothing (previous send code KEY_IAQTCH_PREV_PAGE)
// If Button 16 has type 0x03 then we have next, if 0x00 nothing (next send code KEY_IAQTCH_NEXT_PAGE)
if (isPDA_PANEL && !in_iaqt_programming_mode(aq_data) ) {
printf("********* button 16 type = 0x%02hhx **********\n",_devicePageButtons[16].type);
if (_devicePageButtons[16].type == 0x03) {
if ( (isPDA_PANEL || PANEL_SIZE() >= 16) && !in_iaqt_programming_mode(aq_data) ) {
printf("********* button 16 type = 0x%02hhx **********\n",_devicePageButtons[dp][16].type);
if (_devicePageButtons[dp][16].type == 0x03) {
printf("********* NEXT PAGE FROM DEVICES **********\n");
iaqt_queue_cmd(KEY_IAQTCH_NEXT_PAGE);
} else {
@ -628,7 +674,15 @@ void processPage(struct aqualinkdata *aq_data)
break;
case IAQ_PAGE_SYSTEM_SETUP:
//LOG(IAQT_LOG,LOG_INFO, "System Setup :-\n");
debugPrintButtons(_deviceSystemSetupButtons);
debugPrintButtons(_deviceSystemSetupButtons[0]);
break;
case IAQ_PAGE_SYSTEM_SETUP2:
//LOG(IAQT_LOG,LOG_INFO, "System Setup :-\n");
debugPrintButtons(_deviceSystemSetupButtons[1]);
break;
case IAQ_PAGE_SYSTEM_SETUP3:
//LOG(IAQT_LOG,LOG_INFO, "System Setup :-\n");
debugPrintButtons(_deviceSystemSetupButtons[2]);
break;
case IAQ_PAGE_SET_VSP:
debugPrintButtons(_pageButtons);
@ -659,12 +713,14 @@ bool process_iaqtouch_packet(unsigned char *packet, int length, struct aqualinkd
static bool gotStatus = true;
//char buff[1024];
// NSF Take this out
if ( packet[3] != CMD_IAQ_POLL && getLogLevel(IAQT_LOG) >= LOG_DEBUG ) {
char buff[1000];
beautifyPacket(buff, packet, length, false);
LOG(IAQT_LOG,LOG_DEBUG, "Received message : %s", buff);
}
if (packet[PKT_CMD] == CMD_IAQ_PAGE_START) {
LOG(IAQT_LOG,LOG_DEBUG, "Turning IAQ SEND off\n");
set_iaq_cansend(false);
@ -673,7 +729,7 @@ bool process_iaqtouch_packet(unsigned char *packet, int length, struct aqualinkd
memset(_pageButtons, 0, IAQ_PAGE_BUTTONS * sizeof(struct iaqt_page_button));
memset(_deviceStatus, 0, sizeof(char) * IAQ_STATUS_PAGE_LINES * AQ_MSGLEN+1 );
memset(_tableInformation, 0, sizeof(char) * IAQ_MSG_TABLE_LINES * AQ_MSGLEN+1 );
memset(_devicePageButtons, 0, IAQ_PAGE_BUTTONS * sizeof(struct iaqt_page_button));
//memset(_devicePageButtons, 0, IAQ_PAGE_BUTTONS * sizeof(struct iaqt_page_button));
// Fix bug with control panel where after a few hours status page disapears and you need to hit menu.
if (gotStatus == false)
gotStatus = true;
@ -683,11 +739,20 @@ bool process_iaqtouch_packet(unsigned char *packet, int length, struct aqualinkd
LOG(IAQT_LOG,LOG_DEBUG, "Turning IAQ SEND on\n");
if (_currentPageLoading != NUL) {
_currentPage = _currentPageLoading;
_currentPageLoading = NUL;
//_currentPageLoading = NUL;
} else {
LOG(IAQT_LOG,LOG_DEBUG, "Page end message without proceding page start, ignoring!\n");
}
// Time is in the page end command
// 1/18/2011 13:42
//Hex |0x10|0x02|0x33|0x28|0x01|0x12|0x0b|0x0d|0x2a|0xc2|0x10|0x03|
//Dec | 16| 2| 51| 40| 1| 18| 11| 13| 42| 194| 16| 3
//Ascii | | | 3| (| | | | | *| | |
snprintf(aq_data->date, sizeof(aq_data->date), "%d/%d/%d", packet[4],packet[5],packet[6]);
snprintf(aq_data->time, sizeof(aq_data->date), "%d:%d", packet[7],packet[8]);
processPage(aq_data);
} else if (packet[PKT_CMD] == CMD_IAQ_TABLE_MSG) {
processTableMessage(packet, length);
} else if (packet[PKT_CMD] == CMD_IAQ_PAGE_MSG) {
@ -712,7 +777,7 @@ bool process_iaqtouch_packet(unsigned char *packet, int length, struct aqualinkd
//printf("** MANUAL PAGE END\n");
LOG(IAQT_LOG,LOG_DEBUG, "MANUAL PAGE END\n");
_currentPage = _currentPageLoading;
_currentPageLoading = NUL;
//_currentPageLoading = NUL;
processPage(aq_data);
set_iaq_cansend(true);
// Also END page here, as you can send commands.
@ -725,7 +790,8 @@ bool process_iaqtouch_packet(unsigned char *packet, int length, struct aqualinkd
//printf("***** iAqualink Touch STARTUP Message ******* \n");
if (gotInit == false) {
LOG(IAQT_LOG,LOG_DEBUG, "STARTUP Message\n");
//queueGetProgramData(IAQTOUCH, aq_data);
//LOG(IAQT_LOG,LOG_ERR, "STARTUP REMOVED GET PANEL DATA FOR TESTING\n");
queueGetProgramData(IAQTOUCH, aq_data);
gotInit = true;
}
@ -739,10 +805,13 @@ bool process_iaqtouch_packet(unsigned char *packet, int length, struct aqualinkd
//LOG(IAQT_LOG,LOG_DEBUG, "poll count %d\n",cnt);
// Load status page every 50 messages
if (cnt++ > REQUEST_STATUS_POLL_COUNT && in_programming_mode(aq_data) == false ) {
if (isPDA_PANEL) {
printf("********* START REQUEST LOOP **********\n");
if (isPDA_PANEL || PANEL_SIZE() >= 16) {
iaqt_queue_cmd(KEY_IAQTCH_HOMEP_KEY08);
printf("********* REQUEST OTHER DEVICES FROM HOME **********\n");
} else {
iaqt_queue_cmd(KEY_IAQTCH_STATUS);
printf("********* REQUEST OTHER SATUS FROM HOME **********\n");
}
gotStatus = false; // Reset if we got status page, for fix panel bug.
//aq_programmer(AQ_GET_IAQTOUCH_VSP_ASSIGNMENT, NULL, aq_data);
@ -784,9 +853,12 @@ bool process_iaqtouch_packet(unsigned char *packet, int length, struct aqualinkd
return true;
}
//char _namebuf[40];
const char *iaqt_page_name(const unsigned char page)
{
static char _namebuf[40];
switch (page){
case IAQ_PAGE_HOME:
return "HOME";
@ -839,6 +911,12 @@ const char *iaqt_page_name(const unsigned char page)
case IAQ_PAGE_SYSTEM_SETUP:
return "System Setup";
break;
case IAQ_PAGE_SYSTEM_SETUP2:
return "System Setup #2";
break;
case IAQ_PAGE_SYSTEM_SETUP3:
return "System Setup #3";
break;
case IAQ_PAGE_VSP_SETUP:
return "VSP Setup";
break;
@ -849,7 +927,9 @@ const char *iaqt_page_name(const unsigned char page)
return "Label Aux";
break;
default:
return "** Unknown **";
sprintf (_namebuf,"** Unknown 0x%02hhx **",page);
return _namebuf;
//return "** Unknown **";
break;
}
return "";

View File

@ -323,7 +323,8 @@ bool goto_iaqt_page(const unsigned char pageID, struct aqualinkdata *aq_data) {
LOG(IAQT_LOG, LOG_DEBUG, "IAQ Touch got to Device page\n");
return true;
} else if (pageID == IAQ_PAGE_MENU || pageID == IAQ_PAGE_SET_TEMP || pageID == IAQ_PAGE_SET_TIME || pageID == IAQ_PAGE_SET_SWG ||
pageID == IAQ_PAGE_SYSTEM_SETUP || pageID == IAQ_PAGE_FREEZE_PROTECT || pageID == IAQ_PAGE_LABEL_AUX || pageID == IAQ_PAGE_VSP_SETUP) {
pageID == IAQ_PAGE_SYSTEM_SETUP || pageID == IAQ_PAGE_FREEZE_PROTECT || pageID == IAQ_PAGE_LABEL_AUX ||
pageID == IAQ_PAGE_VSP_SETUP || pageID == IAQ_PAGE_DEGREES) {
// All other pages require us to go to Menu page
send_aqt_cmd(KEY_IAQTCH_MENU);
if (waitfor_iaqt_nextPage(aq_data) != IAQ_PAGE_MENU) {
@ -386,6 +387,9 @@ bool goto_iaqt_page(const unsigned char pageID, struct aqualinkdata *aq_data) {
case IAQ_PAGE_VSP_SETUP:
menuText = "VSP Setup";
break;
case IAQ_PAGE_DEGREES:
menuText = "Degrees";
break;
default:
LOG(IAQT_LOG, LOG_ERR, "IAQ Touch unknown menu '0x%02hhx'\n", pageID);
return false;
@ -394,8 +398,14 @@ bool goto_iaqt_page(const unsigned char pageID, struct aqualinkdata *aq_data) {
button = iaqtFindButtonByLabel(menuText);
if (button == NULL) {
LOG(IAQT_LOG, LOG_ERR, "IAQ Touch did not find '%s' button on page setup\n", menuText);
return false;
//send_aqt_cmd(KEY_IAQTCH_NEXT_PAGE);
// Try Next Page
//unsigned char page = waitfor_iaqt_nextPage(aq_data);
//LOG(IAQT_LOG, LOG_ERR, "PAGE RETURN IS 0x%02hhx\n",page);
//if (waitfor_iaqt_nextPage(aq_data) != pageID) {
LOG(IAQT_LOG, LOG_ERR, "IAQ Touch did not find '%s' button on page setup\n", menuText);
return false;
//}
}
// send_aqt_cmd(KEY_IAQTCH_KEY01);
send_aqt_cmd(button->keycode);
@ -444,7 +454,7 @@ struct programmingThreadCtrl *threadCtrl;
button = iaqtFindButtonByLabel(aq_data->aqbuttons[device].label);
// If not found see if page hax next
// If not found see if page has next
if (button == NULL && iaqtFindButtonByIndex(16)->type == 0x03 ) {
iaqt_queue_cmd(KEY_IAQTCH_NEXT_PAGE);
waitfor_iaqt_nextPage(aq_data);
@ -701,6 +711,40 @@ void *get_aqualink_iaqtouch_setpoints( void *ptr )
LOG(IAQT_LOG,LOG_NOTICE, "IAQ Touch Freeze Protection setpoint %d\n",frz);
}
// Get the temperature units if we are in iaq touch PDA mode
if (isPDA_PANEL) {
// If we are here, hit back then next button to get button with degrees on it.
// Only if in PDA mode
send_aqt_cmd(KEY_IAQTCH_BACK); // Clear the feeze protect menu and go back to system setup
if ( waitfor_iaqt_nextPage(aq_data) != IAQ_PAGE_SYSTEM_SETUP )
{
LOG(IAQT_LOG,LOG_ERR, "Couldn't get back to setup page, Temperature units unknown, default to DegF\n");
aq_data->temp_units = FAHRENHEIT;
goto f_end;
}
send_aqt_cmd(KEY_IAQTCH_NEXT_PAGE_ALTERNATE); // Go to page 2
if ( waitfor_iaqt_nextPage(aq_data) != IAQ_PAGE_SYSTEM_SETUP2 )
{
LOG(IAQT_LOG,LOG_ERR, "Couldn't get back to setup page, Temperature units unknown, default to DegF\n");
aq_data->temp_units = FAHRENHEIT;
goto f_end;
}
button = iaqtFindButtonByLabel("Degrees");
if (button != NULL) {
LOG(IAQT_LOG,LOG_NOTICE, "Temperature units are '%s'\n",button->name);
if (button->name[8] == 'C') {
aq_data->temp_units = CELSIUS;
} else {
aq_data->temp_units = FAHRENHEIT;
}
}
}
// Need to run over table messages and check ens with X for on off.
// Go to status page on startup to read devices

Binary file not shown.

View File

@ -49,6 +49,10 @@ debug_log_mask = 1024
#debug_log_mask = 2048
#debug_log_mask = 4096
# Log any packets from this device. (less outpit that DEBUG_SERIAL)
# debug_log_mask = 512 - MUST be set for this to work.
#RSSD_LOG_filter = 0x33
display_warnings_in_web = yes
rs485_frame_delay = 4

Binary file not shown.

View File

@ -203,6 +203,8 @@ int rsm_strcmp(const char *haystack, const char *needle)
// so 'spa' !- 'spa mode'
int rsm_strmatch(const char *haystack, const char *needle)
{
return rsm_strmatch_ignore(haystack, needle, 0);
/*
char *sp1 = (char *)haystack;
char *sp2 = (char *)needle;
@ -226,6 +228,44 @@ int rsm_strmatch(const char *haystack, const char *needle)
// Need to write this myself for speed
//LOG(AQUA_LOG,LOG_DEBUG, "Compare (reset)%d chars of '%s' to '%s'\n",strlen(sp2),sp1,sp2);
return strncasecmp(sp1, sp2, l2);
*/
}
// Match two strings, used for button labels
// exact character length once white space removed is used for match
// ignore_chars will delete the last X chars from haystack.
// use case insensative for match.
// so 'spa' !- 'spa mode'
int rsm_strmatch_ignore(const char *haystack, const char *needle, int ignore_chars)
{
char *sp1 = (char *)haystack;
char *sp2 = (char *)needle;
char *ep1 = (char *)sp1 + strlen(sp1) - 1;
char *ep2 = (char *)sp2 + strlen(sp2) - 1;
//int i=0;
// Get rid of all padding
while(isspace(*sp1)) sp1++;
while(isspace(*sp2)) sp2++;
while(isspace(*ep2) && (ep2 >= sp2)) ep2--;
if (ignore_chars > 0)
ep1 = ep1 - ignore_chars;
else
while(isspace(*ep1) && (ep1 >= sp1)) ep1--;
int l1 = ep1 - sp1 +1;
int l2 = ep2 - sp2 +1;
//printf("***** %s() Compare %d chars of '%s' to %d chars in '%s'\n",(ignore_chars==0?"rsm_strmatch":"rsm_strmatch_ignore"),l2,sp2,l1,sp1);
if ( l1 != l2 || (ep1 - sp1) <= 0 || (ep2 - sp2) <= 0 ) {
return -1;
}
// Need to write this myself for speed
//LOG(AQUA_LOG,LOG_DEBUG, "Compare (reset)%d chars of '%s' to '%s'\n",strlen(sp2),sp1,sp2);
return strncasecmp(sp1, sp2, l2);
}

View File

@ -12,6 +12,7 @@ char *rsm_strncasestr(const char *haystack, const char *needle, size_t length);
char *rsm_lastindexof(const char *haystack, const char *needle, size_t length);
int rsm_strmatch(const char *haystack, const char *needle);
int rsm_strmatch_ignore(const char *haystack, const char *needle, int ignore_chars);
int rsm_strncpy(char *dest, const unsigned char *src, int dest_len, int src_len);
int rsm_strcmp(const char *s1, const char *s2);

View File

@ -9,7 +9,7 @@
#define MAX_STACK 20
int _sim_stack_place = 0;
unsigned char _commands[MAX_STACK];
unsigned char _sim_commands[MAX_STACK];
bool push_simulator_cmd(unsigned char cmd);
@ -27,7 +27,7 @@ void simulator_send_cmd(unsigned char cmd)
bool push_simulator_cmd(unsigned char cmd)
{
if (_sim_stack_place < MAX_STACK) {
_commands[_sim_stack_place] = cmd;
_sim_commands[_sim_stack_place] = cmd;
_sim_stack_place++;
} else {
LOG(SIM_LOG, LOG_ERR, "Command queue overflow, too many unsent commands to RS control panel\n");
@ -42,9 +42,9 @@ unsigned char pop_simulator_cmd(unsigned char receive_type)
unsigned char cmd = NUL;
if (_sim_stack_place > 0 && receive_type == CMD_STATUS ) {
cmd = _commands[0];
cmd = _sim_commands[0];
_sim_stack_place--;
memmove(&_commands[0], &_commands[1], sizeof(unsigned char) * _sim_stack_place ) ;
memmove(&_sim_commands[0], &_sim_commands[1], sizeof(unsigned char) * _sim_stack_place ) ;
}
LOG(SIM_LOG,LOG_DEBUG, "Sending '0x%02hhx' to controller\n", cmd);