Skip to content

Commit

Permalink
Allow user to set specific IP of hdhomerun unit
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzzard committed Dec 28, 2022
1 parent 0dd7a62 commit 99de229
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ msgstr ""
msgctxt "#32006"
msgid "Use HTTP discovery"
msgstr ""

msgctxt "#32007"
msgid "Set IP of device to use"
msgstr ""
8 changes: 8 additions & 0 deletions pvr.hdhomerun/resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
<default>false</default>
<control type="toggle"/>
</setting>
<setting id="force_ip" type="string" label="32007">
<level>0</level>
<default></default>
<constraints>
<allowempty>true</allowempty>
</constraints>
<control type="edit" format="string" />
</setting>
</group>
</category>
</section>
Expand Down
22 changes: 22 additions & 0 deletions src/HDHomeRunTuners.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,28 @@ bool HDHomeRunTuners::Update(int nMode)
nTunerCount = hdhomerun_discover_find_devices_custom_v2(
0, HDHOMERUN_DEVICE_TYPE_TUNER, HDHOMERUN_DEVICE_ID_WILDCARD, foundDevices, 16);

// If neither HTTPDiscovery or normal broadcast discovery do not find a device, if a
// user has entered an IP address in settings for a forced IP, do a search based on that
// specific IP. We only accomodate IPv4 addresses currently.
if (nTunerCount <= 0)
{
std::string strUserForcedIP = SettingsType::Get().GetForcedIP();
if (!strUserForcedIP.empty())
{
unsigned char addressbuf[sizeof(struct in6_addr)];

int s = inet_pton(AF_INET, strUserForcedIP.c_str(), addressbuf);
if (s > 0)
{
uint32_t ipaddress = (addressbuf[0] << 24) + (addressbuf[1] << 16) + (addressbuf[2] << 8) + addressbuf[3];
nTunerCount = hdhomerun_discover_find_devices_custom_v2(
ipaddress, HDHOMERUN_DEVICE_TYPE_TUNER, HDHOMERUN_DEVICE_ID_WILDCARD, foundDevices, 16);

KODI_LOG(ADDON_LOG_DEBUG, "Found %d HDHomeRun tuners on IP %s", nTunerCount, strUserForcedIP.c_str());
}
}
}

if (nTunerCount <= 0)
return false;

Expand Down
6 changes: 6 additions & 0 deletions src/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ bool SettingsType::ReadSettings()
bMarkNew = kodi::addon::GetSettingBoolean("mark_new", true);
bDebug = kodi::addon::GetSettingBoolean("debug", false);
bHttpDiscovery = kodi::addon::GetSettingBoolean("http_discovery", false);
strForcedIP = kodi::addon::GetSettingString("force_ip", "");

return true;
}
Expand All @@ -48,6 +49,11 @@ ADDON_STATUS SettingsType::SetSetting(const std::string& settingName,
bHttpDiscovery = settingValue.GetBoolean();
return ADDON_STATUS_NEED_RESTART;
}
else if (settingName == "force_ip")
{
strForcedIP = settingValue.GetString();
return ADDON_STATUS_NEED_RESTART;
}

return ADDON_STATUS_OK;
}
4 changes: 4 additions & 0 deletions src/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#pragma once

#include <string>

#include <kodi/AddonBase.h>

class ATTR_DLL_LOCAL SettingsType
Expand All @@ -24,6 +26,7 @@ class ATTR_DLL_LOCAL SettingsType
bool GetDebug() const { return bDebug; }
bool GetMarkNew() const { return bMarkNew; }
bool GetHttpDiscovery() const { return bHttpDiscovery; }
std::string GetForcedIP() const { return strForcedIP; }

private:
SettingsType() = default;
Expand All @@ -33,4 +36,5 @@ class ATTR_DLL_LOCAL SettingsType
bool bDebug = false;
bool bMarkNew = false;
bool bHttpDiscovery = false;
std::string strForcedIP;
};

0 comments on commit 99de229

Please sign in to comment.