| 1 |
/* |
| 2 |
* Copyright (C) 2010-2021 Team Kodi (https://kodi.tv) |
| 3 |
* Copyright (C) 2010 Alwin Esch (Team Kodi) |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSE.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "GUIWindowChannelScan.h" |
| 10 |
|
| 11 |
#include "RequestPacket.h" |
| 12 |
#include "ResponsePacket.h" |
| 13 |
#include "vnsicommand.h" |
| 14 |
|
| 15 |
#include <algorithm> |
| 16 |
#include <cctype> |
| 17 |
#include <kodi/General.h> |
| 18 |
#include <kodi/Network.h> |
| 19 |
#include <limits.h> |
| 20 |
#include <sstream> |
| 21 |
|
| 22 |
#define BUTTON_START 5 |
| 23 |
#define BUTTON_BACK 6 |
| 24 |
#define BUTTON_CANCEL 7 |
| 25 |
#define HEADER_LABEL 8 |
| 26 |
|
| 27 |
#define SPIN_CONTROL_SOURCE_TYPE 10 |
| 28 |
#define CONTROL_RADIO_BUTTON_TV 11 |
| 29 |
#define CONTROL_RADIO_BUTTON_RADIO 12 |
| 30 |
#define CONTROL_RADIO_BUTTON_FTA 13 |
| 31 |
#define CONTROL_RADIO_BUTTON_SCRAMBLED 14 |
| 32 |
#define CONTROL_RADIO_BUTTON_HD 15 |
| 33 |
#define CONTROL_SPIN_COUNTRIES 16 |
| 34 |
#define CONTROL_SPIN_SATELLITES 17 |
| 35 |
#define CONTROL_SPIN_DVBC_INVERSION 18 |
| 36 |
#define CONTROL_SPIN_DVBC_SYMBOLRATE 29 |
| 37 |
#define CONTROL_SPIN_DVBC_QAM 20 |
| 38 |
#define CONTROL_SPIN_DVBT_INVERSION 21 |
| 39 |
#define CONTROL_SPIN_ATSC_TYPE 22 |
| 40 |
|
| 41 |
#define LABEL_TYPE 30 |
| 42 |
#define LABEL_DEVICE 31 |
| 43 |
#define PROGRESS_DONE 32 |
| 44 |
#define LABEL_TRANSPONDER 33 |
| 45 |
#define LABEL_SIGNAL 34 |
| 46 |
#define PROGRESS_SIGNAL 35 |
| 47 |
#define LABEL_STATUS 36 |
| 48 |
|
| 49 |
cVNSIChannelScan::cVNSIChannelScan(kodi::addon::CInstancePVRClient& instance) |
| 50 |
: cVNSISession(instance), kodi::gui::CWindow("ChannelScan.xml", "skin.estuary", true, false) |
| 51 |
{ |
| 52 |
} |
| 53 |
|
| 54 |
bool cVNSIChannelScan::Open(const std::string& hostname, |
| 55 |
int port, |
| 56 |
const std::string& mac, |
| 57 |
const char* name) |
| 58 |
{ |
| 59 |
m_hostname = hostname; |
| 60 |
m_port = port; |
| 61 |
m_wolMac = mac; |
| 62 |
m_running = false; |
| 63 |
m_Canceled = false; |
| 64 |
m_stopped = true; |
| 65 |
|
| 66 |
if (!cVNSISession::Open(hostname, port, name)) |
| 67 |
return false; |
| 68 |
|
| 69 |
if (!cVNSISession::Login()) |
| 70 |
return false; |
| 71 |
|
| 72 |
m_abort = false; |
| 73 |
m_connectionLost = false; |
| 74 |
m_threadRunning = true; |
| 75 |
m_thread = std::thread([&] { Process(); }); |
| 76 |
|
| 77 |
kodi::gui::CWindow::DoModal(); |
| 78 |
|
| 79 |
delete m_spinSourceType; |
| 80 |
delete m_spinCountries; |
| 81 |
delete m_spinSatellites; |
| 82 |
delete m_spinDVBCInversion; |
| 83 |
delete m_spinDVBCSymbolrates; |
| 84 |
delete m_spinDVBCqam; |
| 85 |
delete m_spinDVBTInversion; |
| 86 |
delete m_spinATSCType; |
| 87 |
delete m_radioButtonTV; |
| 88 |
delete m_radioButtonRadio; |
| 89 |
delete m_radioButtonFTA; |
| 90 |
delete m_radioButtonScrambled; |
| 91 |
delete m_radioButtonHD; |
| 92 |
delete m_progressDone; |
| 93 |
delete m_progressSignal; |
| 94 |
|
| 95 |
m_threadRunning = false; |
| 96 |
if (m_thread.joinable()) |
| 97 |
m_thread.join(); |
| 98 |
kodi::gui::CWindow::Close(); |
| 99 |
|
| 100 |
return true; |
| 101 |
} |
| 102 |
|
| 103 |
bool cVNSIChannelScan::OnInit() |
| 104 |
{ |
| 105 |
m_spinSourceType = new kodi::gui::controls::CSpin(this, SPIN_CONTROL_SOURCE_TYPE); |
| 106 |
m_spinSourceType->AddLabel("DVB-T", DVB_TERR); |
| 107 |
m_spinSourceType->AddLabel("DVB-C", DVB_CABLE); |
| 108 |
m_spinSourceType->AddLabel("DVB-S/S2", DVB_SAT); |
| 109 |
m_spinSourceType->AddLabel("Analog TV", PVRINPUT); |
| 110 |
m_spinSourceType->AddLabel("Analog Radio", PVRINPUT_FM); |
| 111 |
m_spinSourceType->AddLabel("ATSC", DVB_ATSC); |
| 112 |
|
| 113 |
m_spinDVBCInversion = new kodi::gui::controls::CSpin(this, CONTROL_SPIN_DVBC_INVERSION); |
| 114 |
m_spinDVBCInversion->AddLabel("Auto", 0); |
| 115 |
m_spinDVBCInversion->AddLabel("On", 1); |
| 116 |
m_spinDVBCInversion->AddLabel("Off", 2); |
| 117 |
|
| 118 |
m_spinDVBCSymbolrates = new kodi::gui::controls::CSpin(this, CONTROL_SPIN_DVBC_SYMBOLRATE); |
| 119 |
m_spinDVBCSymbolrates->AddLabel("AUTO", 0); |
| 120 |
m_spinDVBCSymbolrates->AddLabel("6900", 1); |
| 121 |
m_spinDVBCSymbolrates->AddLabel("6875", 2); |
| 122 |
m_spinDVBCSymbolrates->AddLabel("6111", 3); |
| 123 |
m_spinDVBCSymbolrates->AddLabel("6250", 4); |
| 124 |
m_spinDVBCSymbolrates->AddLabel("6790", 5); |
| 125 |
m_spinDVBCSymbolrates->AddLabel("6811", 6); |
| 126 |
m_spinDVBCSymbolrates->AddLabel("5900", 7); |
| 127 |
m_spinDVBCSymbolrates->AddLabel("5000", 8); |
| 128 |
m_spinDVBCSymbolrates->AddLabel("3450", 9); |
| 129 |
m_spinDVBCSymbolrates->AddLabel("4000", 10); |
| 130 |
m_spinDVBCSymbolrates->AddLabel("6950", 11); |
| 131 |
m_spinDVBCSymbolrates->AddLabel("7000", 12); |
| 132 |
m_spinDVBCSymbolrates->AddLabel("6952", 13); |
| 133 |
m_spinDVBCSymbolrates->AddLabel("5156", 14); |
| 134 |
m_spinDVBCSymbolrates->AddLabel("4583", 15); |
| 135 |
m_spinDVBCSymbolrates->AddLabel("ALL (slow)", 16); |
| 136 |
|
| 137 |
m_spinDVBCqam = new kodi::gui::controls::CSpin(this, CONTROL_SPIN_DVBC_QAM); |
| 138 |
m_spinDVBCqam->AddLabel("AUTO", 0); |
| 139 |
m_spinDVBCqam->AddLabel("64", 1); |
| 140 |
m_spinDVBCqam->AddLabel("128", 2); |
| 141 |
m_spinDVBCqam->AddLabel("256", 3); |
| 142 |
m_spinDVBCqam->AddLabel("ALL (slow)", 4); |
| 143 |
|
| 144 |
m_spinDVBTInversion = new kodi::gui::controls::CSpin(this, CONTROL_SPIN_DVBT_INVERSION); |
| 145 |
m_spinDVBTInversion->AddLabel("Auto", 0); |
| 146 |
m_spinDVBTInversion->AddLabel("On", 1); |
| 147 |
m_spinDVBTInversion->AddLabel("Off", 2); |
| 148 |
|
| 149 |
m_spinATSCType = new kodi::gui::controls::CSpin(this, CONTROL_SPIN_ATSC_TYPE); |
| 150 |
m_spinATSCType->AddLabel("VSB (aerial)", 0); |
| 151 |
m_spinATSCType->AddLabel("QAM (cable)", 1); |
| 152 |
m_spinATSCType->AddLabel("VSB + QAM (aerial + cable)", 2); |
| 153 |
|
| 154 |
m_radioButtonTV = new kodi::gui::controls::CRadioButton(this, CONTROL_RADIO_BUTTON_TV); |
| 155 |
m_radioButtonTV->SetSelected(true); |
| 156 |
|
| 157 |
m_radioButtonRadio = new kodi::gui::controls::CRadioButton(this, CONTROL_RADIO_BUTTON_RADIO); |
| 158 |
m_radioButtonRadio->SetSelected(true); |
| 159 |
|
| 160 |
m_radioButtonFTA = new kodi::gui::controls::CRadioButton(this, CONTROL_RADIO_BUTTON_FTA); |
| 161 |
m_radioButtonFTA->SetSelected(true); |
| 162 |
|
| 163 |
m_radioButtonScrambled = |
| 164 |
new kodi::gui::controls::CRadioButton(this, CONTROL_RADIO_BUTTON_SCRAMBLED); |
| 165 |
m_radioButtonScrambled->SetSelected(true); |
| 166 |
|
| 167 |
m_radioButtonHD = new kodi::gui::controls::CRadioButton(this, CONTROL_RADIO_BUTTON_HD); |
| 168 |
m_radioButtonHD->SetSelected(true); |
| 169 |
|
| 170 |
m_progressDone = new kodi::gui::controls::CProgress(this, PROGRESS_DONE); |
| 171 |
m_progressSignal = new kodi::gui::controls::CProgress(this, PROGRESS_SIGNAL); |
| 172 |
|
| 173 |
if (!ReadCountries()) |
| 174 |
return false; |
| 175 |
|
| 176 |
if (!ReadSatellites()) |
| 177 |
return false; |
| 178 |
|
| 179 |
SetControlsVisible(DVB_TERR); |
| 180 |
return true; |
| 181 |
} |
| 182 |
|
| 183 |
bool cVNSIChannelScan::OnFocus(int controlId) |
| 184 |
{ |
| 185 |
return true; |
| 186 |
} |
| 187 |
|
| 188 |
bool cVNSIChannelScan::OnClick(int controlId) |
| 189 |
{ |
| 190 |
if (controlId == SPIN_CONTROL_SOURCE_TYPE) |
| 191 |
{ |
| 192 |
int value = m_spinSourceType->GetIntValue(); |
| 193 |
SetControlsVisible((scantype_t)value); |
| 194 |
} |
| 195 |
else if (controlId == BUTTON_BACK) |
| 196 |
{ |
| 197 |
kodi::gui::CWindow::Close(); |
| 198 |
} |
| 199 |
else if (controlId == BUTTON_START) |
| 200 |
{ |
| 201 |
try |
| 202 |
{ |
| 203 |
if (!m_running) |
| 204 |
{ |
| 205 |
m_running = true; |
| 206 |
m_stopped = false; |
| 207 |
m_Canceled = false; |
| 208 |
SetProperty("Scanning", "running"); |
| 209 |
SetControlLabel(BUTTON_START, kodi::addon::GetLocalizedString(222)); |
| 210 |
StartScan(); |
| 211 |
} |
| 212 |
else if (!m_stopped) |
| 213 |
{ |
| 214 |
m_stopped = true; |
| 215 |
m_Canceled = true; |
| 216 |
StopScan(); |
| 217 |
} |
| 218 |
else |
| 219 |
ReturnFromProcessView(); |
| 220 |
} |
| 221 |
catch (std::exception e) |
| 222 |
{ |
| 223 |
kodi::Log(ADDON_LOG_ERROR, "%s - %s", __func__, e.what()); |
| 224 |
return false; |
| 225 |
} |
| 226 |
} |
| 227 |
return true; |
| 228 |
} |
| 229 |
|
| 230 |
bool cVNSIChannelScan::OnAction(ADDON_ACTION actionId) |
| 231 |
{ |
| 232 |
if (actionId == ADDON_ACTION_NAV_BACK || actionId == ADDON_ACTION_PREVIOUS_MENU) |
| 233 |
OnClick(BUTTON_BACK); |
| 234 |
|
| 235 |
return true; |
| 236 |
} |
| 237 |
|
| 238 |
void cVNSIChannelScan::StartScan() |
| 239 |
{ |
| 240 |
m_header = kodi::addon::GetLocalizedString(30025); |
| 241 |
m_Signal = kodi::addon::GetLocalizedString(30029); |
| 242 |
SetProgress(0); |
| 243 |
SetSignal(0, false); |
| 244 |
|
| 245 |
int source = m_spinSourceType->GetIntValue(); |
| 246 |
switch (source) |
| 247 |
{ |
| 248 |
case DVB_TERR: |
| 249 |
SetControlLabel(LABEL_TYPE, "DVB-T"); |
| 250 |
break; |
| 251 |
case DVB_CABLE: |
| 252 |
SetControlLabel(LABEL_TYPE, "DVB-C"); |
| 253 |
break; |
| 254 |
case DVB_SAT: |
| 255 |
SetControlLabel(LABEL_TYPE, "DVB-S/S2"); |
| 256 |
break; |
| 257 |
case PVRINPUT: |
| 258 |
SetControlLabel(LABEL_TYPE, kodi::addon::GetLocalizedString(30032)); |
| 259 |
break; |
| 260 |
case PVRINPUT_FM: |
| 261 |
SetControlLabel(LABEL_TYPE, kodi::addon::GetLocalizedString(30033)); |
| 262 |
break; |
| 263 |
case DVB_ATSC: |
| 264 |
SetControlLabel(LABEL_TYPE, "ATSC"); |
| 265 |
break; |
| 266 |
} |
| 267 |
|
| 268 |
cRequestPacket vrp; |
| 269 |
uint32_t retCode = VNSI_RET_ERROR; |
| 270 |
vrp.init(VNSI_SCAN_START); |
| 271 |
vrp.add_U32(source); |
| 272 |
vrp.add_U8(m_radioButtonTV->IsSelected()); |
| 273 |
vrp.add_U8(m_radioButtonRadio->IsSelected()); |
| 274 |
vrp.add_U8(m_radioButtonFTA->IsSelected()); |
| 275 |
vrp.add_U8(m_radioButtonScrambled->IsSelected()); |
| 276 |
vrp.add_U8(m_radioButtonHD->IsSelected()); |
| 277 |
vrp.add_U32(m_spinCountries->GetIntValue()); |
| 278 |
vrp.add_U32(m_spinDVBCInversion->GetIntValue()); |
| 279 |
vrp.add_U32(m_spinDVBCSymbolrates->GetIntValue()); |
| 280 |
vrp.add_U32(m_spinDVBCqam->GetIntValue()); |
| 281 |
vrp.add_U32(m_spinDVBTInversion->GetIntValue()); |
| 282 |
vrp.add_U32(m_spinSatellites->GetIntValue()); |
| 283 |
vrp.add_U32(m_spinATSCType->GetIntValue()); |
| 284 |
|
| 285 |
{ |
| 286 |
auto vresp = ReadResult(&vrp); |
| 287 |
if (!vresp) |
| 288 |
goto SCANError; |
| 289 |
|
| 290 |
retCode = vresp->extract_U32(); |
| 291 |
if (retCode != VNSI_RET_OK) |
| 292 |
goto SCANError; |
| 293 |
} |
| 294 |
|
| 295 |
return; |
| 296 |
|
| 297 |
SCANError: |
| 298 |
kodi::Log(ADDON_LOG_ERROR, "%s - Return error after start (%i)", __func__, retCode); |
| 299 |
SetControlLabel(LABEL_STATUS, kodi::addon::GetLocalizedString(24071)); |
| 300 |
SetControlLabel(BUTTON_START, kodi::addon::GetLocalizedString(30024)); |
| 301 |
SetControlLabel(HEADER_LABEL, kodi::addon::GetLocalizedString(30043)); |
| 302 |
m_stopped = true; |
| 303 |
} |
| 304 |
|
| 305 |
void cVNSIChannelScan::StopScan() |
| 306 |
{ |
| 307 |
cRequestPacket vrp; |
| 308 |
vrp.init(VNSI_SCAN_STOP); |
| 309 |
|
| 310 |
auto vresp = ReadResult(&vrp); |
| 311 |
if (!vresp) |
| 312 |
return; |
| 313 |
|
| 314 |
uint32_t retCode = vresp->extract_U32(); |
| 315 |
if (retCode != VNSI_RET_OK) |
| 316 |
{ |
| 317 |
kodi::Log(ADDON_LOG_ERROR, "%s - Return error after stop (%i)", __func__, retCode); |
| 318 |
SetControlLabel(LABEL_STATUS, kodi::addon::GetLocalizedString(24071)); |
| 319 |
SetControlLabel(BUTTON_START, kodi::addon::GetLocalizedString(30024)); |
| 320 |
SetControlLabel(HEADER_LABEL, kodi::addon::GetLocalizedString(30043)); |
| 321 |
m_stopped = true; |
| 322 |
} |
| 323 |
return; |
| 324 |
} |
| 325 |
|
| 326 |
void cVNSIChannelScan::ReturnFromProcessView() |
| 327 |
{ |
| 328 |
if (m_running) |
| 329 |
{ |
| 330 |
m_running = false; |
| 331 |
ClearProperties(); |
| 332 |
SetControlLabel(BUTTON_START, kodi::addon::GetLocalizedString(30010)); |
| 333 |
SetControlLabel(HEADER_LABEL, kodi::addon::GetLocalizedString(30009)); |
| 334 |
|
| 335 |
m_progressDone->SetVisible(false); |
| 336 |
m_progressSignal->SetVisible(false); |
| 337 |
} |
| 338 |
} |
| 339 |
|
| 340 |
void cVNSIChannelScan::SetProgress(int percent) |
| 341 |
{ |
| 342 |
std::stringstream header; |
| 343 |
header << percent; |
| 344 |
|
| 345 |
SetControlLabel(HEADER_LABEL, header.str().c_str()); |
| 346 |
m_progressDone->SetPercentage((float)percent); |
| 347 |
} |
| 348 |
|
| 349 |
void cVNSIChannelScan::SetSignal(int percent, bool locked) |
| 350 |
{ |
| 351 |
std::stringstream signal; |
| 352 |
signal << percent; |
| 353 |
|
| 354 |
SetControlLabel(LABEL_SIGNAL, signal.str().c_str()); |
| 355 |
m_progressSignal->SetPercentage((float)percent); |
| 356 |
|
| 357 |
if (locked) |
| 358 |
SetProperty("Locked", "true"); |
| 359 |
else |
| 360 |
SetProperty("Locked", ""); |
| 361 |
} |
| 362 |
|
| 363 |
bool cVNSIChannelScan::ReadCountries() |
| 364 |
{ |
| 365 |
m_spinCountries = new kodi::gui::controls::CSpin(this, CONTROL_SPIN_COUNTRIES); |
| 366 |
|
| 367 |
std::string dvdlang = kodi::GetLanguage(LANG_FMT_ISO_639_1); |
| 368 |
std::transform(dvdlang.begin(), dvdlang.end(), dvdlang.begin(), |
| 369 |
[](unsigned char c) { return std::toupper(c); }); |
| 370 |
|
| 371 |
cRequestPacket vrp; |
| 372 |
vrp.init(VNSI_SCAN_GETCOUNTRIES); |
| 373 |
|
| 374 |
auto vresp = ReadResult(&vrp); |
| 375 |
if (!vresp) |
| 376 |
return false; |
| 377 |
|
| 378 |
int startIndex = -1; |
| 379 |
uint32_t retCode = vresp->extract_U32(); |
| 380 |
if (retCode == VNSI_RET_OK) |
| 381 |
{ |
| 382 |
while (vresp->getRemainingLength() >= 4 + 2) |
| 383 |
{ |
| 384 |
uint32_t index = vresp->extract_U32(); |
| 385 |
const char* isoName = vresp->extract_String(); |
| 386 |
const char* longName = vresp->extract_String(); |
| 387 |
m_spinCountries->AddLabel(longName, index); |
| 388 |
if (dvdlang == isoName) |
| 389 |
startIndex = index; |
| 390 |
} |
| 391 |
if (startIndex >= 0) |
| 392 |
m_spinCountries->SetIntValue(startIndex); |
| 393 |
} |
| 394 |
else |
| 395 |
{ |
| 396 |
kodi::Log(ADDON_LOG_ERROR, "%s - Return error after reading countries (%i)", __func__, retCode); |
| 397 |
} |
| 398 |
return retCode == VNSI_RET_OK; |
| 399 |
} |
| 400 |
|
| 401 |
bool cVNSIChannelScan::ReadSatellites() |
| 402 |
{ |
| 403 |
m_spinSatellites = new kodi::gui::controls::CSpin(this, CONTROL_SPIN_SATELLITES); |
| 404 |
|
| 405 |
cRequestPacket vrp; |
| 406 |
vrp.init(VNSI_SCAN_GETSATELLITES); |
| 407 |
|
| 408 |
auto vresp = ReadResult(&vrp); |
| 409 |
if (!vresp) |
| 410 |
return false; |
| 411 |
|
| 412 |
uint32_t retCode = vresp->extract_U32(); |
| 413 |
if (retCode == VNSI_RET_OK) |
| 414 |
{ |
| 415 |
while (vresp->getRemainingLength() >= 4 + 2) |
| 416 |
{ |
| 417 |
uint32_t index = vresp->extract_U32(); |
| 418 |
const char* shortName = vresp->extract_String(); |
| 419 |
const char* longName = vresp->extract_String(); |
| 420 |
m_spinSatellites->AddLabel(longName, index); |
| 421 |
} |
| 422 |
m_spinSatellites->SetIntValue(6); /* default to Astra 19.2 */ |
| 423 |
} |
| 424 |
else |
| 425 |
{ |
| 426 |
kodi::Log(ADDON_LOG_ERROR, "%s - Return error after reading satellites (%i)", __func__, |
| 427 |
retCode); |
| 428 |
} |
| 429 |
return retCode == VNSI_RET_OK; |
| 430 |
} |
| 431 |
|
| 432 |
void cVNSIChannelScan::SetControlsVisible(scantype_t type) |
| 433 |
{ |
| 434 |
m_spinCountries->SetVisible(type == DVB_TERR || type == DVB_CABLE || type == PVRINPUT); |
| 435 |
m_spinSatellites->SetVisible(type == DVB_SAT || type == DVB_ATSC); |
| 436 |
m_spinDVBCInversion->SetVisible(type == DVB_CABLE); |
| 437 |
m_spinDVBCSymbolrates->SetVisible(type == DVB_CABLE); |
| 438 |
m_spinDVBCqam->SetVisible(type == DVB_CABLE); |
| 439 |
m_spinDVBTInversion->SetVisible(type == DVB_TERR); |
| 440 |
m_spinATSCType->SetVisible(type == DVB_ATSC); |
| 441 |
m_radioButtonTV->SetVisible(type == DVB_TERR || type == DVB_CABLE || type == DVB_SAT || |
| 442 |
type == DVB_ATSC); |
| 443 |
m_radioButtonRadio->SetVisible(type == DVB_TERR || type == DVB_CABLE || type == DVB_SAT || |
| 444 |
type == DVB_ATSC); |
| 445 |
m_radioButtonFTA->SetVisible(type == DVB_TERR || type == DVB_CABLE || type == DVB_SAT || |
| 446 |
type == DVB_ATSC); |
| 447 |
m_radioButtonScrambled->SetVisible(type == DVB_TERR || type == DVB_CABLE || type == DVB_SAT || |
| 448 |
type == DVB_ATSC); |
| 449 |
m_radioButtonHD->SetVisible(type == DVB_TERR || type == DVB_CABLE || type == DVB_SAT || |
| 450 |
type == DVB_ATSC); |
| 451 |
} |
| 452 |
|
| 453 |
bool cVNSIChannelScan::OnResponsePacket(cResponsePacket* resp) |
| 454 |
{ |
| 455 |
uint32_t requestID = resp->getRequestID(); |
| 456 |
|
| 457 |
if (requestID == VNSI_SCANNER_PERCENTAGE) |
| 458 |
{ |
| 459 |
uint32_t percent = resp->extract_U32(); |
| 460 |
if (percent <= 100) |
| 461 |
SetProgress(percent); |
| 462 |
} |
| 463 |
else if (requestID == VNSI_SCANNER_SIGNAL) |
| 464 |
{ |
| 465 |
uint32_t strength = resp->extract_U32(); |
| 466 |
uint32_t locked = resp->extract_U32(); |
| 467 |
SetSignal(strength, (locked > 0)); |
| 468 |
} |
| 469 |
else if (requestID == VNSI_SCANNER_DEVICE) |
| 470 |
{ |
| 471 |
char* str = resp->extract_String(); |
| 472 |
SetControlLabel(LABEL_DEVICE, str); |
| 473 |
} |
| 474 |
else if (requestID == VNSI_SCANNER_TRANSPONDER) |
| 475 |
{ |
| 476 |
char* str = resp->extract_String(); |
| 477 |
SetControlLabel(LABEL_TRANSPONDER, str); |
| 478 |
} |
| 479 |
else if (requestID == VNSI_SCANNER_NEWCHANNEL) |
| 480 |
{ |
| 481 |
uint32_t isRadio = resp->extract_U32(); |
| 482 |
uint32_t isEncrypted = resp->extract_U32(); |
| 483 |
uint32_t isHD = resp->extract_U32(); |
| 484 |
char* str = resp->extract_String(); |
| 485 |
|
| 486 |
std::shared_ptr<kodi::gui::CListItem> item = std::make_shared<kodi::gui::CListItem>(str); |
| 487 |
|
| 488 |
if (isEncrypted) |
| 489 |
item->SetProperty("IsEncrypted", "yes"); |
| 490 |
if (isRadio) |
| 491 |
item->SetProperty("IsRadio", "yes"); |
| 492 |
if (isHD) |
| 493 |
item->SetProperty("IsHD", "yes"); |
| 494 |
|
| 495 |
AddListItem(item, 0); |
| 496 |
} |
| 497 |
else if (requestID == VNSI_SCANNER_FINISHED) |
| 498 |
{ |
| 499 |
if (!m_Canceled) |
| 500 |
{ |
| 501 |
SetControlLabel(HEADER_LABEL, kodi::addon::GetLocalizedString(30036)); |
| 502 |
SetControlLabel(BUTTON_START, kodi::addon::GetLocalizedString(30024)); |
| 503 |
SetControlLabel(LABEL_STATUS, kodi::addon::GetLocalizedString(30041)); |
| 504 |
} |
| 505 |
else |
| 506 |
{ |
| 507 |
SetControlLabel(HEADER_LABEL, kodi::addon::GetLocalizedString(30042)); |
| 508 |
} |
| 509 |
} |
| 510 |
else if (requestID == VNSI_SCANNER_STATUS) |
| 511 |
{ |
| 512 |
uint32_t status = resp->extract_U32(); |
| 513 |
if (status == 0) |
| 514 |
{ |
| 515 |
if (m_Canceled) |
| 516 |
SetControlLabel(LABEL_STATUS, kodi::addon::GetLocalizedString(16200)); |
| 517 |
else |
| 518 |
SetControlLabel(LABEL_STATUS, kodi::addon::GetLocalizedString(30040)); |
| 519 |
|
| 520 |
SetControlLabel(BUTTON_START, kodi::addon::GetLocalizedString(30024)); |
| 521 |
m_stopped = true; |
| 522 |
} |
| 523 |
else if (status == 1) |
| 524 |
{ |
| 525 |
SetControlLabel(LABEL_STATUS, kodi::addon::GetLocalizedString(30039)); |
| 526 |
} |
| 527 |
else if (status == 2) |
| 528 |
{ |
| 529 |
SetControlLabel(LABEL_STATUS, kodi::addon::GetLocalizedString(30037)); |
| 530 |
SetControlLabel(BUTTON_START, kodi::addon::GetLocalizedString(30024)); |
| 531 |
SetControlLabel(HEADER_LABEL, kodi::addon::GetLocalizedString(30043)); |
| 532 |
m_stopped = true; |
| 533 |
} |
| 534 |
else if (status == 3) |
| 535 |
{ |
| 536 |
SetControlLabel(LABEL_STATUS, kodi::addon::GetLocalizedString(30038)); |
| 537 |
} |
| 538 |
} |
| 539 |
else |
| 540 |
{ |
| 541 |
return false; |
| 542 |
} |
| 543 |
|
| 544 |
return true; |
| 545 |
} |
| 546 |
|
| 547 |
void cVNSIChannelScan::Process() |
| 548 |
{ |
| 549 |
std::unique_ptr<cResponsePacket> vresp; |
| 550 |
|
| 551 |
while (m_threadRunning) |
| 552 |
{ |
| 553 |
// try to reconnect |
| 554 |
if (m_connectionLost) |
| 555 |
{ |
| 556 |
// First wake up the VDR server in case a MAC-Address is specified |
| 557 |
if (!m_wolMac.empty()) |
| 558 |
{ |
| 559 |
if (!kodi::network::WakeOnLan(m_wolMac)) |
| 560 |
{ |
| 561 |
kodi::Log(ADDON_LOG_ERROR, "Error waking up VNSI Server at MAC-Address %s", |
| 562 |
m_wolMac.c_str()); |
| 563 |
} |
| 564 |
} |
| 565 |
|
| 566 |
cVNSISession::eCONNECTIONSTATE state = TryReconnect(); |
| 567 |
if (state != cVNSISession::CONN_ESABLISHED) |
| 568 |
{ |
| 569 |
std::this_thread::sleep_for(std::chrono::milliseconds(1000)); |
| 570 |
continue; |
| 571 |
} |
| 572 |
} |
| 573 |
|
| 574 |
// if there's anything in the buffer, read it |
| 575 |
if ((vresp = cVNSISession::ReadMessage(5, 10000)) == nullptr) |
| 576 |
{ |
| 577 |
std::this_thread::sleep_for(std::chrono::milliseconds(5)); |
| 578 |
continue; |
| 579 |
} |
| 580 |
|
| 581 |
if (!OnResponsePacket(vresp.get())) |
| 582 |
{ |
| 583 |
kodi::Log(ADDON_LOG_ERROR, "%s - Rxd a response packet on channel %lu !!", __func__, |
| 584 |
vresp->getChannelID()); |
| 585 |
} |
| 586 |
} |
| 587 |
} |