From 29583ad894a676ade133b525eed782aa60f76b8c Mon Sep 17 00:00:00 2001 From: Rayshobby Date: Mon, 15 Dec 2014 23:04:55 -0500 Subject: [PATCH] Check in firmware 2.1.2 source code. 2.1.2 fixes the following bugs: 1) /jp outputs incomplete data when number of programs is a multiple of 3 (this is likely a compiler bug); 2) program name does not handle the SPACE character correctly; 3) when using buttons to change port number, the range is limited to 255 (solution is to disable changing port number using buttons. no new features are introduced in firmware 2.1.2. --- EtherCard.h | 2 +- OpenSprinklerGen2.cpp | 6 ++-- defines.h | 6 ++-- examples/interval_program/server.ino | 48 +++++++++++++++++----------- webutil.cpp | 5 +-- 5 files changed, 41 insertions(+), 26 deletions(-) diff --git a/EtherCard.h b/EtherCard.h index bc0233d6..ade83b5f 100644 --- a/EtherCard.h +++ b/EtherCard.h @@ -506,7 +506,7 @@ class EtherCard : public Ethernet { // ray: modified to add support for key stored in pgm memory static uint8_t findKeyVal(const char *str,char *strbuf, uint8_t maxlen, const char *key, bool key_in_pgm = false, - uint8_t *keyfound = NULL); // ray: added keyfound return variable + uint8_t *keyfound = NULL, char** pos = NULL); // ray: added pos return variable /** @brief Decode a URL string e.g "hello%20joe" or "hello+joe" becomes "hello joe" * @param urlbuf Pointer to the null terminated URL diff --git a/OpenSprinklerGen2.cpp b/OpenSprinklerGen2.cpp index 02ab4c38..64330a5c 100644 --- a/OpenSprinklerGen2.cpp +++ b/OpenSprinklerGen2.cpp @@ -1086,12 +1086,14 @@ void OpenSprinkler::ui_set_options(int oid) switch (button & BUTTON_MASK) { case BUTTON_1: - if (i==OPTION_FW_VERSION || i==OPTION_HW_VERSION) break; // ignore non-editable options + if (i==OPTION_FW_VERSION || i==OPTION_HW_VERSION || + i==OPTION_HTTPPORT_0 || i==OPTION_HTTPPORT_1) break; // ignore non-editable options if (options[i].max != options[i].value) options[i].value ++; break; case BUTTON_2: - if (i==OPTION_FW_VERSION || i==OPTION_HW_VERSION) break; // ignore non-editable options + if (i==OPTION_FW_VERSION || i==OPTION_HW_VERSION || + i==OPTION_HTTPPORT_0 || i==OPTION_HTTPPORT_1) break; // ignore non-editable options if (options[i].value != 0) options[i].value --; break; diff --git a/defines.h b/defines.h index fae5914e..683bfb7a 100644 --- a/defines.h +++ b/defines.h @@ -2,7 +2,7 @@ /* Macro definitions and Arduino pin assignments Creative Commons Attribution-ShareAlike 3.0 license - Nov 2014 @ Rayshobby.net + Dec 2014 @ Rayshobby.net */ #ifndef _Defines_h @@ -11,7 +11,7 @@ // ================================================= // ====== Firmware Version and Maximal Values ====== // ================================================= -#define OS_FW_VERSION 211 // firmware version (211 means 2.1.1 etc) +#define OS_FW_VERSION 212 // firmware version (212 means 2.1.2 etc) // if this number is different from stored in EEPROM, // an EEPROM reset will be automatically triggered @@ -191,7 +191,7 @@ typedef enum { #if defined(__AVR_ATmega1284P__) #define ETHER_BUFFER_SIZE 1500 // 1284P has 16K RAM #else -#define ETHER_BUFFER_SIZE 850 // if buffer size is increased, you must check the total RAM consumption +#define ETHER_BUFFER_SIZE 900 // if buffer size is increased, you must check the total RAM consumption #endif // otherwise it may cause the program to crash #define TMP_BUFFER_SIZE 120 // scratch buffer size diff --git a/examples/interval_program/server.ino b/examples/interval_program/server.ino index be4fdd9b..aa377b38 100644 --- a/examples/interval_program/server.ino +++ b/examples/interval_program/server.ino @@ -203,7 +203,12 @@ byte server_view_scripturl(char *p) { return HTML_OK; } -void server_json_programs_main() { +/** + Output program data +*/ +byte server_json_programs(char *p) +{ + print_json_header_with_bracket(); bfill.emit_p(PSTR("\"nprogs\":$D,\"nboards\":$D,\"mnp\":$D,\"mnst\":$D,\"pnsize\":$D,\"pd\":["), pd.nprograms, os.nboards, MAX_NUMBER_PROGRAMS, MAX_NUM_STARTTIMES, PROGRAM_NAME_SIZE); byte pid, bid, i; @@ -230,25 +235,18 @@ void server_json_programs_main() { strncpy(tmp_buffer, prog.name, PROGRAM_NAME_SIZE); tmp_buffer[PROGRAM_NAME_SIZE] = 0; // make sure the string ends bfill.emit_p(PSTR("$S"), tmp_buffer); - if(pid!=pd.nprograms-1) + if(pid!=pd.nprograms-1) { bfill.emit_p(PSTR("\"],")); - else + } else { bfill.emit_p(PSTR("\"]")); - if (pid%3==2) { // push out a packet every 4 programs + } + if ((pid%4)==3) { // push out a packet every 4 programs ether.httpServerReply_with_flags(bfill.position(), TCP_FLAGS_ACK_V, 3); bfill=ether.tcpOffset(); } } - bfill.emit_p(PSTR("]}")); -} - -/** - Output program data -*/ -byte server_json_programs(char *p) -{ - print_json_header_with_bracket(); - server_json_programs_main(); + bfill.emit_p(PSTR("]}")); + delay(1); return HTML_OK; } @@ -375,7 +373,12 @@ byte server_moveup_program(char *p) { */ prog_char _str_program[] PROGMEM = "Program "; byte server_change_program(char *p) { - // decode url first + byte i; + // terminate the string at the first SPACE character + int j; + for(j=0;j maxlen=5 // ray: modified to add support for key stored in pgm memory -uint8_t EtherCard::findKeyVal (const char *str,char *strbuf, uint8_t maxlen,const char *key,bool key_in_pgm,uint8_t *keyfound) +uint8_t EtherCard::findKeyVal (const char *str,char *strbuf, uint8_t maxlen,const char *key,bool key_in_pgm,uint8_t *keyfound,char** pos) { uint8_t found=0; uint8_t i=0; @@ -80,7 +80,8 @@ uint8_t EtherCard::findKeyVal (const char *str,char *strbuf, uint8_t maxlen,cons } str++; } - } + } + if (pos) *pos = (char*)str; if (found==1){ // copy the value to a buffer and terminate it with '\0' while(*str && *str!=' ' && *str!='\n' && *str!='&' && i