Skip to content

Commit

Permalink
Added automatic detection of Ceton devices which are shown in the Cet…
Browse files Browse the repository at this point in the history
…on device address drop-down
  • Loading branch information
Craig Moksnes committed Mar 9, 2020
1 parent a02cf53 commit 9978812
Show file tree
Hide file tree
Showing 8 changed files with 679 additions and 95 deletions.
61 changes: 36 additions & 25 deletions ProxyFormUnit.fmx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ object MainForm: TMainForm
Top = 0
Caption = 'Ceton HDHomeRun Proxy'
ClientHeight = 507
ClientWidth = 472
ClientWidth = 400
Fill.Kind = Solid
Position = ScreenCenter
StyleBook = StyleBook1
Expand All @@ -16,21 +16,21 @@ object MainForm: TMainForm
DesignerMasterStyle = 0
object VertScrollBox1: TVertScrollBox
Align = Client
Size.Width = 472.000000000000000000
Size.Width = 400.000000000000000000
Size.Height = 507.000000000000000000
Size.PlatformDefault = False
TabOrder = 3
Viewport.Width = 472.000000000000000000
Viewport.Width = 400.000000000000000000
Viewport.Height = 507.000000000000000000
object OuterPanelContainer: TLayout
Align = Top
Size.Width = 472.000000000000000000
Size.Width = 400.000000000000000000
Size.Height = 505.000000000000000000
Size.PlatformDefault = False
TabOrder = 0
object PanelContainer: TLayout
Align = Top
Size.Width = 472.000000000000000000
Size.Width = 400.000000000000000000
Size.Height = 1000.000000000000000000
Size.PlatformDefault = False
TabOrder = 0
Expand All @@ -44,7 +44,7 @@ object MainForm: TMainForm
Position.X = 3.000000000000000000
Position.Y = 68.000000000000000000
ShowCheck = False
Size.Width = 466.000000000000000000
Size.Width = 394.000000000000000000
Size.Height = 20.000000000000000000
Size.PlatformDefault = False
Text = 'Advanced Settings'
Expand Down Expand Up @@ -111,13 +111,14 @@ object MainForm: TMainForm
Touch.InteractiveGestures = [LongTap, DoubleTap]
TabOrder = 0
ItemHeight = 19.000000000000000000
ItemWidth = 300.000000000000000000
ItemIndex = -1
Position.X = 210.000000000000000000
Position.Y = 9.000000000000000000
Hint =
'The local IP address that will be listened on for video data fro' +
'm the Ceton device. Leave blank to auto-detect.'
Size.Width = 220.000000000000000000
Size.Width = 150.000000000000000000
Size.Height = 22.000000000000000000
Size.PlatformDefault = False
OnChangeTracking = ceCetonListenIPChangeTracking
Expand All @@ -128,13 +129,14 @@ object MainForm: TMainForm
Touch.InteractiveGestures = [LongTap, DoubleTap]
TabOrder = 1
ItemHeight = 19.000000000000000000
ItemWidth = 300.000000000000000000
ItemIndex = -1
Position.X = 210.000000000000000000
Position.Y = 40.000000000000000000
Hint =
'The local IP address that will be listened on for all HDHomeRun ' +
'requests. Leave blank to auto-detect.'
Size.Width = 220.000000000000000000
Size.Width = 150.000000000000000000
Size.Height = 22.000000000000000000
Size.PlatformDefault = False
OnChangeTracking = ceHDHRListenIPChangeTracking
Expand Down Expand Up @@ -165,7 +167,7 @@ object MainForm: TMainForm
'The address that will be given to DVR software to use for HDHome' +
'Run HTTP video and lineup requests. Leave blank to auto-detect ' +
'based on each request received.'
Size.Width = 220.000000000000000000
Size.Width = 150.000000000000000000
Size.Height = 22.000000000000000000
Size.PlatformDefault = False
OnChangeTracking = eHDHRExternalAddressChangeTracking
Expand All @@ -180,6 +182,9 @@ object MainForm: TMainForm
Hint =
'The port that will be given to DVR software to use for HDHomeRun' +
' HTTP video and lineup requests.'
Size.Width = 71.000000000000000000
Size.Height = 22.000000000000000000
Size.PlatformDefault = False
OnChangeTracking = eHDHRExternalHTTPPortChangeTracking
OnMouseEnter = EditMouseEnter
OnMouseLeave = EditMouseLeave
Expand All @@ -194,30 +199,36 @@ object MainForm: TMainForm
Position.X = 3.000000000000000000
Position.Y = 3.000000000000000000
ShowCheck = False
Size.Width = 466.000000000000000000
Size.Width = 394.000000000000000000
Size.Height = 59.000000000000000000
Size.PlatformDefault = False
Text = 'Settings'
TabOrder = 2
OnMouseDown = PanelMouseDown
OnResized = PanelResizing
ContentSize = '39'
object eCetonTunerAddress: TEdit
object Label1: TLabel
Position.X = 15.000000000000000000
Position.Y = 12.000000000000000000
Text = 'Ceton tuner address:'
TabOrder = 1
end
object eCetonTunerAddress: TComboEdit
Touch.InteractiveGestures = [LongTap, DoubleTap]
TabOrder = 0
ItemHeight = 19.000000000000000000
ItemWidth = 300.000000000000000000
ItemIndex = -1
Position.X = 210.000000000000000000
Position.Y = 9.000000000000000000
Size.Width = 143.000000000000000000
Hint =
'The local IP address that will be listened on for video data fro' +
'm the Ceton device. Leave blank to auto-detect.'
Size.Width = 150.000000000000000000
Size.Height = 22.000000000000000000
Size.PlatformDefault = False
OnChangeTracking = eCetonTunerAddressChangeTracking
end
object Label1: TLabel
Position.X = 15.000000000000000000
Position.Y = 12.000000000000000000
Text = 'Ceton tuner address:'
TabOrder = 1
end
end
object pnlStatistics: TExpander
Align = Top
Expand All @@ -226,7 +237,7 @@ object MainForm: TMainForm
Position.X = 3.000000000000000000
Position.Y = 120.000000000000000000
ShowCheck = False
Size.Width = 466.000000000000000000
Size.Width = 394.000000000000000000
Size.Height = 354.000000000000000000
Size.PlatformDefault = False
Text = 'Statistics'
Expand All @@ -246,7 +257,7 @@ object MainForm: TMainForm
Margins.Left = 10.000000000000000000
Margins.Top = 9.000000000000000000
Margins.Right = 10.000000000000000000
Size.Width = 446.000000000000000000
Size.Width = 374.000000000000000000
Size.Height = 291.000000000000000000
Size.PlatformDefault = False
TabOrder = 0
Expand All @@ -255,7 +266,7 @@ object MainForm: TMainForm
object Layout2: TLayout
Align = Bottom
Position.Y = 300.000000000000000000
Size.Width = 466.000000000000000000
Size.Width = 394.000000000000000000
Size.Height = 34.000000000000000000
Size.PlatformDefault = False
TabOrder = 1
Expand All @@ -280,7 +291,7 @@ object MainForm: TMainForm
Position.X = 3.000000000000000000
Position.Y = 94.000000000000000000
ShowCheck = False
Size.Width = 466.000000000000000000
Size.Width = 394.000000000000000000
Size.Height = 20.000000000000000000
Size.PlatformDefault = False
Text = 'Channels'
Expand Down Expand Up @@ -351,7 +362,7 @@ object MainForm: TMainForm
MinSize = 20.000000000000000000
Position.Y = 114.000000000000000000
ShowGrip = False
Size.Width = 472.000000000000000000
Size.Width = 400.000000000000000000
Size.Height = 6.000000000000000000
Size.PlatformDefault = False
end
Expand All @@ -361,7 +372,7 @@ object MainForm: TMainForm
MinSize = 20.000000000000000000
Position.Y = 474.000000000000000000
ShowGrip = False
Size.Width = 472.000000000000000000
Size.Width = 400.000000000000000000
Size.Height = 6.000000000000000000
Size.PlatformDefault = False
end
Expand All @@ -374,7 +385,7 @@ object MainForm: TMainForm
Position.X = 3.000000000000000000
Position.Y = 480.000000000000000000
ShowCheck = False
Size.Width = 466.000000000000000000
Size.Width = 394.000000000000000000
Size.Height = 20.000000000000000000
Size.PlatformDefault = False
Text = 'Debug'
Expand Down
61 changes: 51 additions & 10 deletions ProxyFormUnit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ TMainForm = class(TForm, IServiceConfigEvents)
btnEditChannels: TButton;
StyleBook1: TStyleBook;
VertScrollBox1: TVertScrollBox;
eCetonTunerAddress: TEdit;
Label1: TLabel;
SaveTimer: TTimer;
Label2: TLabel;
Expand Down Expand Up @@ -99,6 +98,7 @@ TMainForm = class(TForm, IServiceConfigEvents)
Label8: TLabel;
HelpCallout: TCalloutRectangle;
lblHelp: TLabel;
eCetonTunerAddress: TComboEdit;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure lbChannelsChangeCheck(Sender: TObject);
Expand Down Expand Up @@ -130,8 +130,9 @@ TMainForm = class(TForm, IServiceConfigEvents)

function GetClient: TCetonClient;

function GetLocalIPs: TArray<String>; overload;
procedure GetLocalIPs(const aComboEdit: TComboEdit); overload;
function GetLocalIPs: TArray<String>;
procedure UpdateLocalIPs(const aComboEdit: TComboEdit);
procedure UpdateDiscoveredCetonDevices(const aComboEdit: TComboEdit);

function ExtractIP(const aComboEdit: TComboEdit): String;

Expand All @@ -151,6 +152,7 @@ TMainForm = class(TForm, IServiceConfigEvents)
// IServiceConfigEvents
procedure Changed(const aSender: TObject; const aSections: TServiceConfigSections);
procedure Log(const aMessage: String);
procedure DiscoveredCetonDevicesChanged;
public
{ Public declarations }
end;
Expand Down Expand Up @@ -229,8 +231,9 @@ procedure TMainForm.FormCreate(Sender: TObject);
fConfigManager := ProxyServiceModule.ConfigManager;
fConfigManager.AddListener(Self);

GetLocalIPs(ceCetonListenIP);
GetLocalIPs(ceHDHRListenIP);
UpdateLocalIPs(ceCetonListenIP);
UpdateLocalIPs(ceHDHRListenIP);
UpdateDiscoveredCetonDevices(eCetonTunerAddress);

ProxyServerModule.StartServer;
end;
Expand Down Expand Up @@ -447,7 +450,7 @@ procedure TMainForm.eCetonTunerAddressChangeTracking(Sender: TObject);
begin
ConfigManager.LockConfig(lConfig);
try
lConfig.Ceton.TunerAddress := eCetonTunerAddress.Text;
lConfig.Ceton.TunerAddress := ExtractIP(eCetonTunerAddress);
finally
ConfigManager.UnlockConfig(lConfig);
end;
Expand Down Expand Up @@ -612,11 +615,17 @@ function TMainForm.GetLocalIPs: TArray<String>;
SetLength(Result, lCount);
end;

procedure TMainForm.GetLocalIPs(const aComboEdit: TComboEdit);
procedure TMainForm.UpdateLocalIPs(const aComboEdit: TComboEdit);
begin
aComboEdit.Items.Clear;
aComboEdit.Items.AddStrings(GetLocalIPs);
aComboEdit.RecalcSize;
aComboEdit.BeginUpdate;
try
aComboEdit.Items.Clear;
aComboEdit.Items.AddStrings(GetLocalIPs);
if aComboEdit.Count = 0 then
aComboEdit.Items.Add('');
finally
aComboEdit.EndUpdate;
end;
end;

function TMainForm.ExtractIP(const aComboEdit: TComboEdit): String;
Expand Down Expand Up @@ -752,4 +761,36 @@ procedure TMainForm.PanelMouseDown(Sender: TObject; Button: TMouseButton;
TExpander(Sender).IsExpanded := not TExpander(Sender).IsExpanded;
end;

procedure TMainForm.UpdateDiscoveredCetonDevices(const aComboEdit: TComboEdit);
var
lDevices: TArray<TDiscoveredCetonDevice>;
i: Integer;
begin
aComboEdit.BeginUpdate;
try
aComboEdit.Items.Clear;
lDevices := ProxyServiceModule.DiscoveredCetonDeviceList.ToArray;
for i := 0 to High(lDevices) do
begin
if lDevices[i].FriendlyName <> '' then
aComboEdit.Items.Add(Format('%s (%s)', [lDevices[i].IP, lDevices[i].FriendlyName]))
else
aComboEdit.Items.Add(Format('%s', [lDevices[i].IP]));
end;
if aComboEdit.Count = 0 then
aComboEdit.Items.Add('');
finally
aComboEdit.EndUpdate;
end;
end;

procedure TMainForm.DiscoveredCetonDevicesChanged;
begin
TThread.ForceQueue(nil,
procedure()
begin
UpdateDiscoveredCetonDevices(eCetonTunerAddress);
end);
end;

end.
6 changes: 4 additions & 2 deletions ProxyServerModuleUnit.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ object ProxyServerModule: TProxyServerModule
Left = 88
Top = 56
end
object ServiceTimer: TTimer
OnTimer = ServiceTimerTimer
object RestartServersTimer: TTimer
Enabled = False
Interval = 2000
OnTimer = RestartServersTimerTimer
Left = 144
Top = 56
end
Expand Down
Loading

0 comments on commit 9978812

Please sign in to comment.