From ed7bf59a7affdda3fb9ef07d30d61c9398ac72aa Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sat, 12 Dec 2015 23:30:35 +0000 Subject: [PATCH] Add tuner-status call --- handler.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- handler.h | 1 + 2 files changed, 88 insertions(+), 1 deletion(-) mode change 100644 => 100755 handler.c diff --git a/handler.c b/handler.c old mode 100644 new mode 100755 index 144434d..2af3c2c --- a/handler.c +++ b/handler.c @@ -84,7 +84,7 @@ int jsonserver_request_handler(struct mg_connection *conn) else if (!strcmp(wvrequest, "timerset")) success = jsonserver_timerset(js, postData); else if (!strcmp(wvrequest, "timersetactive")) success = jsonserver_timersetactive(js, postData); else if (!strcmp(wvrequest, "timerisrecording")) success = jsonserver_timerisrecording(js, postData); - + else if (!strcmp(wvrequest, "tunersstatus")) success = jsonserver_tunersstatus(js, postData); if (!success) return 0; // the specific handler failed badly @@ -1286,3 +1286,89 @@ bool jsonserver_timerisrecording(Json::Value& js, const char* postData) js["Error"] = "Timer not found"; return true; } + +bool jsonserver_tunersstatus(Json::Value& js, const char* postData) +{ + Log* log = Log::getInstance(); + log->log("JSONServer", Log::DEBUG, "tunerstatus"); + + js["NumDevices"] = cDevice::NumDevices(); + + Json::Value jsdevices(Json::arrayValue); + + for (int i = 0; i < cDevice::NumDevices(); i++) + { + Json::Value oneDevice; + cDevice *d = cDevice::GetDevice(i); + oneDevice["Number"] = d->DeviceNumber(); + oneDevice["Type"] = (const char*)d->DeviceType(); + oneDevice["Name"] = (const char*)d->DeviceName(); + oneDevice["IsPrimary"] = d->IsPrimaryDevice(); + + const cChannel* cchannel = d->GetCurrentlyTunedTransponder(); + if (cchannel) + { + oneDevice["Frequency"] = cchannel->Frequency(); + oneDevice["SignalStrength"] = d->SignalStrength(); + oneDevice["SignalQuality"] = d->SignalQuality(); + + } + else + { + oneDevice["Frequency"] = 0; + oneDevice["SignalStrength"] = 0; + oneDevice["SignalQuality"] = 0; + } + + jsdevices.append(oneDevice); + } + + js["Devices"] = jsdevices; + + + Json::Value jstimers(Json::arrayValue); + int numTimers = Timers.Count(); + cTimer* timer; + for (int i = 0; i < numTimers; i++) + { + timer = Timers.Get(i); + + if (timer->Recording()) + { + Json::Value oneTimer; + oneTimer["Recording"] = timer->Recording(); + oneTimer["StartTime"] = (int)timer->StartTime(); + oneTimer["StopTime"] = (int)timer->StopTime(); + oneTimer["File"] = timer->File(); + + cRecordControl* crc = cRecordControls::GetRecordControl(timer); + if (crc) + { + cDevice* crcd = crc->Device(); + oneTimer["DeviceNumber"] = crcd->DeviceNumber(); + } + else + { + oneTimer["DeviceNumber"] = Json::Value::null; + } + + const cChannel* channel = timer->Channel(); + if (channel) + { + oneTimer["ChannelName"] = channel->Name(); + } + else + { + oneTimer["ChannelName"] = Json::Value::null; + } + + jstimers.append(oneTimer); + } + + } + js["CurrentRecordings"] = jstimers; + + + js["Result"] = true; + return true; +} diff --git a/handler.h b/handler.h index aa3159d..4d39a25 100644 --- a/handler.h +++ b/handler.h @@ -25,6 +25,7 @@ bool jsonserver_timerdel(Json::Value& js, const char* postData); bool jsonserver_timerset(Json::Value& js, const char* postData); bool jsonserver_timersetactive(Json::Value& js, const char* postData); bool jsonserver_timerisrecording(Json::Value& js, const char* postData); +bool jsonserver_tunersstatus(Json::Value& js, const char* postData); const cEvent* jsonserver_getEvent(Json::Value& js, int channelNumber, int eventID, int aroundTime); cTimer* jsonserver_findTimer(const char* rChannelID, const char* rName, const char* rStartTime, const char* rStopTime, const char* rWeekDays); -- 2.39.5