Skip to content

Commit

Permalink
fine tune send_packet
Browse files Browse the repository at this point in the history
  • Loading branch information
rayshobby committed Apr 28, 2015
1 parent 65d56c1 commit bd3eb0f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
9 changes: 4 additions & 5 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ void do_setup() {
MCUSR &= ~(1<<WDRF);

DEBUG_BEGIN(9600);
DEBUG_PRINTLN("started.");

os.begin(); // OpenSprinkler init
os.options_setup(); // Setup options
Expand Down Expand Up @@ -694,24 +693,24 @@ void schedule_all_stations(ulong curr_time) {
seq_start_time += pd.scheduled_stop_time[sid];
pd.scheduled_stop_time[sid] = seq_start_time;
seq_start_time += station_delay; // add station delay time
DEBUG_PRINT("[");
/*DEBUG_PRINT("[");
DEBUG_PRINT(sid);
DEBUG_PRINT(":");
DEBUG_PRINT(pd.scheduled_start_time[sid]);
DEBUG_PRINT(",");
DEBUG_PRINT(pd.scheduled_stop_time[sid]);
DEBUG_PRINTLN("]");
DEBUG_PRINTLN("]");*/
} else {
// concurrent scheduling
pd.scheduled_start_time[sid] = con_start_time;
pd.scheduled_stop_time[sid] = con_start_time + pd.scheduled_stop_time[sid];
DEBUG_PRINT("[");
/*DEBUG_PRINT("[");
DEBUG_PRINT(sid);
DEBUG_PRINT(":");
DEBUG_PRINT(pd.scheduled_start_time[sid]);
DEBUG_PRINT(",");
DEBUG_PRINT(pd.scheduled_stop_time[sid]);
DEBUG_PRINTLN("]");
DEBUG_PRINTLN("]");*/
}
os.status.program_busy = 1; // set program busy bit
}
Expand Down
28 changes: 15 additions & 13 deletions server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,33 +369,34 @@ boolean check_password(char *p)

void server_json_stations_attrib(const char* name, const byte* attrib)
{
bfill.emit_p(PSTR("],\"$F\":["), name);
bfill.emit_p(PSTR("\"$F\":["), name);
for(byte i=0;i<os.nboards;i++) {
bfill.emit_p(PSTR("$D"), attrib[i]);
if(i!=os.nboards-1)
bfill.emit_p(PSTR(","));
}
bfill.emit_p(PSTR("],"));
}

void server_json_stations_main()
{
server_json_stations_attrib(PSTR("masop"), os.masop_bits);
server_json_stations_attrib(PSTR("ignore_rain"), os.ignrain_bits);
server_json_stations_attrib(PSTR("masop2"), os.masop2_bits);
server_json_stations_attrib(PSTR("stn_dis"), os.stndis_bits);
server_json_stations_attrib(PSTR("rfstn"), os.rfstn_bits);
server_json_stations_attrib(PSTR("stn_seq"), os.stnseq_bits);
bfill.emit_p(PSTR("\"snames\":["));
byte sid;
for(sid=0;sid<os.nstations;sid++) {
os.get_station_name(sid, tmp_buffer);
bfill.emit_p(PSTR("\"$S\""), tmp_buffer);
if(sid!=os.nstations-1)
bfill.emit_p(PSTR(","));
if ((sid+1)%32 == 0) { // push out one packet every 32 stations
if (available_ether_buffer()<80) {
send_packet();
}
}
server_json_stations_attrib(PSTR("masop"), os.masop_bits);
server_json_stations_attrib(PSTR("ignore_rain"), os.ignrain_bits);
server_json_stations_attrib(PSTR("masop2"), os.masop2_bits);
server_json_stations_attrib(PSTR("stn_dis"), os.stndis_bits);
server_json_stations_attrib(PSTR("rfstn"), os.rfstn_bits);
server_json_stations_attrib(PSTR("stn_seq"), os.stnseq_bits);
bfill.emit_p(PSTR("],\"maxlen\":$D}"), STATION_NAME_SIZE);
}

Expand Down Expand Up @@ -771,7 +772,7 @@ void server_json_controller_main() {
bfill.emit_p(PSTR("[$D,$L,$L],"), pd.scheduled_program_index[sid], rem, pd.scheduled_start_time[sid]);
// if available ether buffer is getting small
// send out a packet
if(available_ether_buffer() < 50) {
if(available_ether_buffer() < 80) {
send_packet();
}
}
Expand Down Expand Up @@ -1160,7 +1161,8 @@ byte server_json_log(char *p) {
bfill.emit_p(PSTR("["));

char *s;
int res, count = 0;
int res;
//int count = 0;
bool first = true;
for(int i=start;i<=end;i++) {
itoa(i, tmp_buffer, 10);
Expand Down Expand Up @@ -1210,12 +1212,12 @@ byte server_json_log(char *p) {
// if this is the first record, do not print comma
if (first) { bfill.emit_p(PSTR("$S"), tmp_buffer); first=false;}
else { bfill.emit_p(PSTR(",$S"), tmp_buffer); }
count ++;
//count ++;
// if the available ether buffer size is getting small
// push out a packet
if (available_ether_buffer() < 50) {
if (available_ether_buffer() < 80) {
send_packet();
count = 0;
//count = 0;
}
}
}
Expand Down

0 comments on commit bd3eb0f

Please sign in to comment.