Skip to content

Commit

Permalink
Check in firmware 2.1.2 source code. 2.1.2 fixes the following bugs: …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
rayshobby committed Dec 16, 2014
1 parent 11303a8 commit 29583ad
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 26 deletions.
2 changes: 1 addition & 1 deletion EtherCard.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions OpenSprinklerGen2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
48 changes: 30 additions & 18 deletions examples/interval_program/server.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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<strlen(p);j++) {
if(p[j]==' '||p[j]=='\n'||p[j]=='\r') {p[j]=0; break;}
}
ether.urlDecode(p);
// parse program index
if (!ether.findKeyVal(p, tmp_buffer, TMP_BUFFER_SIZE, PSTR("pid"), true)) {
Expand All @@ -397,7 +400,7 @@ byte server_change_program(char *p) {
break;
}
}
byte i;

if(!found) return HTML_DATA_MISSING;
pv+=3;
// parse headers
Expand All @@ -419,8 +422,16 @@ byte server_change_program(char *p) {
pv++; // this should be a ']'
// parse program name

if (ether.findKeyVal(pv, tmp_buffer, TMP_BUFFER_SIZE, PSTR("name"), true)) {
ether.urlDecode(tmp_buffer);
char* pname;
uint8_t keyfound;
if (ether.findKeyVal(pv, tmp_buffer, TMP_BUFFER_SIZE, PSTR("name"), true, &keyfound, &pname) && pname) {
/* copy until the end of string or & */
j=0;
while(*pname && *pname!='&' && *pname!='\n') {
tmp_buffer[j++] = *pname++;
}
tmp_buffer[j]=0;
DEBUG_PRINTLN(tmp_buffer);
strncpy(prog.name, tmp_buffer, PROGRAM_NAME_SIZE);
} else {
strcpy_P(prog.name, _str_program);
Expand Down Expand Up @@ -931,6 +942,7 @@ byte server_json_log(char *p) {
}

bfill.emit_p(PSTR("]"));
delay(1);
return HTML_OK;
}

Expand Down
5 changes: 3 additions & 2 deletions webutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void EtherCard::printIp (const uint8_t *buf) {
// enough storage for strbuf, maxlen is the size of strbuf.
// I.e the value it is declated with: strbuf[5]-> 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;
Expand Down Expand Up @@ -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<maxlen-1){
Expand Down

0 comments on commit 29583ad

Please sign in to comment.