static void JSONSchedule(const KVPairs & key_value_pairs, FILE * stream_file) { int sched_num = -1; freeMemory(); // Iterate through the kv pairs and search for the id. for (int i = 0; i < key_value_pairs.num_pairs; i++) { const char * key = key_value_pairs.keys[i]; const char * value = key_value_pairs.values[i]; if (strcmp(key, "id") == 0) { sched_num = atoi(value); } } // Now check to see if the id is in range. const uint8_t numSched = GetNumSchedules(); if ((sched_num < 0) || (sched_num >= numSched)) { ServeError(stream_file); return; } // Now construct the response and send it ServeHeader(stream_file, 200, "OK", false, "text/plain"); Schedule sched; LoadSchedule(sched_num, &sched); fprintf_P(stream_file, PSTR("{\n\t\"name\" : \"%s\",\n\t\"enabled\" : \"%s\",\n\t\"wadj\" : \"%s\",\n\t\"type\" : \"%s\",\n\t\"d1\" : \"%s\",\n\t\"d2\" : \"%s\""), sched.name, sched.IsEnabled() ? "on" : "off", sched.IsWAdj() ? "on" : "off", sched.IsInterval() ? "off" : "on", sched.day & 0x01 ? "on" : "off", sched.day & 0x02 ? "on" : "off"); fprintf_P(stream_file, PSTR(",\n\t\"d3\" : \"%s\",\n\t\"d4\" : \"%s\",\n\t\"d5\" : \"%s\",\n\t\"d6\" : \"%s\",\n\t\"d7\" : \"%s\",\n\t\"interval\" : \"%d\",\n\t\"times\" : [\n"), sched.day & 0x04 ? "on" : "off", sched.day & 0x08 ? "on" : "off", sched.day & 0x10 ? "on" : "off", sched.day & 0x20 ? "on" : "off", sched.day & 0x40 ? "on" : "off", sched.interval); for (int i = 0; i < 4; i++) { if (sched.time[i] == -1) { fprintf_P(stream_file, PSTR("%s\t\t{\"t\" : \"00:00\", \"e\" : \"off\" }"), (i == 0) ? "" : ",\n"); } else { fprintf_P(stream_file, PSTR("%s\t\t{\"t\" : \"%02d:%02d\", \"e\" : \"on\" }"), (i == 0) ? "" : ",\n", sched.time[i] / 60, sched.time[i] % 60); } } fprintf_P(stream_file, PSTR("\n\t],\n\t\"zones\" : [\n")); for (int i = 0; i < NUM_ZONES; i++) { FullZone zone; LoadZone(i, &zone); fprintf(stream_file, "%s\t\t{\"name\" : \"%s\", \"e\":\"%s\", \"duration\" : %d}", (i == 0) ? "" : ",\n", zone.name, zone.bEnabled ? "on" : "off", sched.zone_duration[i]); } fprintf(stream_file, " ]\n}"); }
static void JSONZones(const KVPairs & key_value_pairs, FILE * stream_file) { ServeHeader(stream_file, 200, "OK", false, "text/plain"); fprintf_P(stream_file, PSTR("{\n\"zones\" : [\n")); FullZone zone = {0}; for (int i = 0; i < NUM_ZONES; i++) { LoadZone(i, &zone); fprintf_P(stream_file, PSTR("%s\t{\"name\" : \"%s\", \"enabled\" : \"%s\", \"pump\" : \"%s\", \"state\" : \"%s\" }"), (i == 0) ? "" : ",\n", zone.name, zone.bEnabled ? "on" : "off", zone.bPump ? "on" : "off", isZoneOn(i + 1) ? "on" : "off"); } fprintf(stream_file, "\n]}"); }
void ZoneHandler::HandleMessage(MsgEntry* me) { psNewSectorMessage msg(me); Notify3(LOG_LOAD, "Crossed from sector %s to sector %s.", msg.oldSector.GetData(), msg.newSector.GetData()); csVector3 velocity = csVector3(0.0f); float yrot = 0.0f; // load current speed on sector crossing if the player is valid (not during game loading) if(celclient->GetMainPlayer()) { velocity = celclient->GetMainPlayer()->GetVelocity(); yrot = celclient->GetMainPlayer()->GetYRotation(); } LoadZone(msg.pos, yrot, msg.newSector, velocity); }
static void JSONState(const KVPairs & key_value_pairs, FILE * stream_file) { ServeHeader(stream_file, 200, "OK", false, "text/plain"); fprintf_P(stream_file, PSTR("{\n\t\"version\" : \"%s\",\n\t\"run\" : \"%s\",\n\t\"zones\" : \"%d\",\n\t\"schedules\" : \"%d\",\n\t\"timenow\" : \"%lu\",\n\t\"events\" : \"%d\""), VERSION, GetRunSchedules() ? "on" : "off", GetNumEnabledZones(), GetNumSchedules(), nntpTimeServer.LocalNow(), iNumEvents); if (runState.isSchedule() || runState.isManual()) { FullZone zone; LoadZone(runState.getZone() - 1, &zone); long time_check = runState.getEndTime() * 60L - (nntpTimeServer.LocalNow() - previousMidnight(nntpTimeServer.LocalNow())); if (runState.isManual()) time_check = 99999; fprintf_P(stream_file, PSTR(",\n\t\"onzone\" : \"%s\",\n\t\"offtime\" : \"%ld\""), zone.name, time_check); } fprintf_P(stream_file, (PSTR("\n}"))); }
static void ServeZonesPage(FILE * stream_file) { FullZone zone; ServeHeader(stream_file, 200, "OK", false); for (uint8_t iZoneNum = 0; iZoneNum < NUM_ZONES; iZoneNum++) { LoadZone(iZoneNum, &zone); fprintf_P(stream_file, PSTR("<hr/>Zone #%d<br/>"), iZoneNum); if (zone.bEnabled) fprintf_P(stream_file, PSTR("Enabled")); else fprintf_P(stream_file, PSTR("Not Enabled")); fprintf_P(stream_file, PSTR("<br/>Name:%s<br/>"), zone.name); if (zone.bPump) fprintf_P(stream_file, PSTR("Pump ON")); else fprintf_P(stream_file, PSTR("Pump OFF")); } }