From af23c380ba56518a551311e11436f632d2b189fd Mon Sep 17 00:00:00 2001 From: Stricted Date: Thu, 12 Nov 2015 01:07:32 +0100 Subject: [PATCH] add/update ltepopup --- SpeedportHybridControl/App.xaml | 1 + .../Data/SpeedportHybrid.cs | 67 ++++-- SpeedportHybridControl/Model/LTECollection.cs | 10 + SpeedportHybridControl/Model/LTEData.cs | 9 + .../PageModel/ltepopupModel.cs | 208 ++++++++++++++++++ .../SpeedportHybridControl.csproj | 5 + SpeedportHybridControl/ltepopup.xaml | 30 ++- SpeedportHybridControl/ltepopup.xaml.cs | 111 +--------- 8 files changed, 302 insertions(+), 139 deletions(-) create mode 100644 SpeedportHybridControl/Model/LTECollection.cs create mode 100644 SpeedportHybridControl/Model/LTEData.cs create mode 100644 SpeedportHybridControl/PageModel/ltepopupModel.cs diff --git a/SpeedportHybridControl/App.xaml b/SpeedportHybridControl/App.xaml index 34c0c8c..17cacfb 100644 --- a/SpeedportHybridControl/App.xaml +++ b/SpeedportHybridControl/App.xaml @@ -20,6 +20,7 @@ + diff --git a/SpeedportHybridControl/Data/SpeedportHybrid.cs b/SpeedportHybridControl/Data/SpeedportHybrid.cs index cee3ed7..ac6a427 100644 --- a/SpeedportHybridControl/Data/SpeedportHybrid.cs +++ b/SpeedportHybridControl/Data/SpeedportHybrid.cs @@ -11,7 +11,7 @@ using SpeedportHybridControl.Implementations; namespace SpeedportHybridControl.Data { public class SpeedportHybrid { public SpeedportHybrid() { } - + public static void initOverview () { try { if (SpeedportHybridAPI.getInstance().checkLogin().Equals(false)) @@ -301,19 +301,13 @@ namespace SpeedportHybridControl.Data { LogManager.WriteToLog(ex.Message); } } - - public static void initLTE (bool popup = false) { + + public static void initLTE () { try { if (SpeedportHybridAPI.getInstance().checkLogin().Equals(false)) return; - LteInfoModel lte = null; - if (popup.Equals(true)) { - //lte = Application.Current.FindResource("LTE2") as LTE; - } - else { - lte = Application.Current.FindResource("LteInfoModel") as LteInfoModel; - } + LteInfoModel lte = Application.Current.FindResource("LteInfoModel") as LteInfoModel; string response = SpeedportHybridAPI.getInstance().sendEnryptedRequest("data/lteinfo.json"); if (response.IsNullOrEmpty()) @@ -350,9 +344,8 @@ namespace SpeedportHybridControl.Data { DateTime time = DateTime.Now; string format = "dd.MM.yyyy HH:mm:ss"; lte.datetime = time.ToString(format); - if (popup.Equals(false)) { - initSyslog(true); - } + + initSyslog(true); obj = null; } @@ -360,7 +353,39 @@ namespace SpeedportHybridControl.Data { LogManager.WriteToLog(ex.Message); } } - + + public static void initLtePopup () { + try { + if (SpeedportHybridAPI.getInstance().checkLogin().Equals(false)) + return; + + ltepopupModel lte = Application.Current.FindResource("ltepopupModel") as ltepopupModel; + + string response = SpeedportHybridAPI.getInstance().sendEnryptedRequest("data/lteinfo.json"); + if (response.IsNullOrEmpty()) + return; + + LteInfoModel obj = JsonConvert.DeserializeObject(response); + response = null; + + lte.phycellid = obj.phycellid; + lte.cellid = obj.cellid; + lte.rsrp = obj.rsrp; + lte.rsrp_bg = util.getRSRPColor(obj.rsrp.ToInt()); + lte.rsrq = obj.rsrq; + lte.rsrq_bg = util.getRSRQColor(obj.rsrq.ToInt()); + + DateTime time = DateTime.Now; + string format = "dd.MM.yyyy HH:mm:ss"; + lte.datetime = time.ToString(format); + + obj = null; + } + catch (Exception ex) { + LogManager.WriteToLog(ex.Message); + } + } + public static void initDSL () { if (SpeedportHybridAPI.getInstance().checkLogin().Equals(false)) return; @@ -370,7 +395,7 @@ namespace SpeedportHybridControl.Data { string response = SpeedportHybridAPI.getInstance().sendEnryptedRequest("data/dsl.json"); if (response.IsNullOrEmpty()) return; - + try { DslPageModel obj = JsonConvert.DeserializeObject(response); @@ -384,14 +409,14 @@ namespace SpeedportHybridControl.Data { obj.Line.uFECsec = Math.Ceiling(obj.Line.uFEC / difference); obj.Line.dFECsec = Math.Ceiling(obj.Line.dFEC / difference); - + dsl.Connection = obj.Connection; dsl.Line = obj.Line; DateTime time = DateTime.Now; string format = "dd.MM.yyyy HH:mm:ss"; dsl.datetime = time.ToString(format); - + obj = null; } catch (Exception ex) { @@ -407,7 +432,7 @@ namespace SpeedportHybridControl.Data { string response = SpeedportHybridAPI.getInstance().sendRequest("data/status.json"); if (response.IsNullOrEmpty()) return; - + JToken jArray = JToken.Parse(response); response = null; @@ -558,7 +583,7 @@ namespace SpeedportHybridControl.Data { LogManager.WriteToLog(ex.Message); } } - + public static void initSyslog (bool isLTE = false) { try { if (SpeedportHybridAPI.getInstance().checkLogin().Equals(false)) @@ -600,7 +625,6 @@ namespace SpeedportHybridControl.Data { // Funkzellen Info if (msg.ToString().Contains("(LT004)") && isLTE.Equals(true)) { LteInfoModel lte = Application.Current.FindResource("LteInfoModel") as LteInfoModel; - //LTE lte2 = Application.Current.FindResource("LTE2") as LTE; string[] parts = msg.ToString().Split(','); string frequenz = parts[2]; @@ -616,7 +640,6 @@ namespace SpeedportHybridControl.Data { } lte.frequenz = frequenz; - //lte2.frequenz = frequenz; varid = null; jArray = null; @@ -745,7 +768,7 @@ namespace SpeedportHybridControl.Data { LogManager.WriteToLog(ex.Message); } } - + public static void initLan () { try { if (SpeedportHybridAPI.getInstance().checkLogin().Equals(false)) diff --git a/SpeedportHybridControl/Model/LTECollection.cs b/SpeedportHybridControl/Model/LTECollection.cs new file mode 100644 index 0000000..cf59b3a --- /dev/null +++ b/SpeedportHybridControl/Model/LTECollection.cs @@ -0,0 +1,10 @@ +using Microsoft.Research.DynamicDataDisplay.Common; + +namespace SpeedportHybridControl.Model { + public class LTECollection : RingArray { + private const int TOTAL_POINTS = 200; + + public LTECollection () : base(TOTAL_POINTS) { + } + } +} diff --git a/SpeedportHybridControl/Model/LTEData.cs b/SpeedportHybridControl/Model/LTEData.cs new file mode 100644 index 0000000..74ff52b --- /dev/null +++ b/SpeedportHybridControl/Model/LTEData.cs @@ -0,0 +1,9 @@ +using System; + +namespace SpeedportHybridControl.Model { + public class LTEData { + public DateTime Date { get; set; } + + public int Data { get; set; } + } +} diff --git a/SpeedportHybridControl/PageModel/ltepopupModel.cs b/SpeedportHybridControl/PageModel/ltepopupModel.cs new file mode 100644 index 0000000..07e6ce8 --- /dev/null +++ b/SpeedportHybridControl/PageModel/ltepopupModel.cs @@ -0,0 +1,208 @@ +using System; +using SpeedportHybridControl.Data; +using SpeedportHybridControl.Model; +using SpeedportHybridControl.Implementations; +using Microsoft.Research.DynamicDataDisplay.DataSources; +using Microsoft.Research.DynamicDataDisplay.Charts; +using System.Timers; +using System.Windows.Media; +using System.IO; +using System.Windows; +using System.Threading; + +namespace SpeedportHybridControl.PageModel { + class ltepopupModel : SuperViewModel { + private System.Timers.Timer _timer; + private DelegateCommand _pinCommand; + private DelegateCommand _closeWindowCommand; + private bool _pinActive; + private bool _logActive; + + private bool _topmost = false; + private LTECollection _lteCollection; + private LTECollection _lteCollection2; + private EnumerableDataSource _rsrqGraph; + private EnumerableDataSource _rsrpGraph; + private HorizontalDateTimeAxis _dateTimeAxis1; + private HorizontalDateTimeAxis _dateTimeAxis2; + + private string _phycellid; + private string _cellid; + private string _rsrp; + private Brush _rsrp_bg = Brushes.Transparent; + private string _rsrq; + private Brush _rsrq_bg = Brushes.Transparent; + private string _datetime; + + public DelegateCommand PinCommand { + get { return _pinCommand; } + set { SetProperty(ref _pinCommand, value); } + } + + public DelegateCommand CloseWindowCommand { + get { return _closeWindowCommand; } + set { SetProperty(ref _closeWindowCommand, value); } + } + + public bool PinActive { + get { return _pinActive; } + set { SetProperty(ref _pinActive, value); } + } + + public bool LogActive { + get { return _logActive; } + set { SetProperty(ref _logActive, value); } + } + + public bool Topmost { + get { return _topmost; } + set { SetProperty(ref _topmost, value); } + } + + public LTECollection LTECollection { + get { return _lteCollection; } + set { SetProperty(ref _lteCollection, value); } + } + + public LTECollection LTECollection2 { + get { return _lteCollection2; } + set { SetProperty(ref _lteCollection2, value); } + } + + public EnumerableDataSource RsrqGraph { + get { return _rsrqGraph; } + set { SetProperty(ref _rsrqGraph, value); } + } + + public EnumerableDataSource RsrpGraph { + get { return _rsrpGraph; } + set { SetProperty(ref _rsrpGraph, value); } + } + + public HorizontalDateTimeAxis DateTimeAxis1 { + get { return _dateTimeAxis1; } + set { SetProperty(ref _dateTimeAxis1, value); } + } + + public HorizontalDateTimeAxis DateTimeAxis2 { + get { return _dateTimeAxis2; } + set { SetProperty(ref _dateTimeAxis2, value); } + } + + public string phycellid { + get { return _phycellid; } + set { SetProperty(ref _phycellid, value); } + } + + public string cellid { + get { return _cellid; } + set { SetProperty(ref _cellid, value); } + } + + public string rsrp { + get { return _rsrp; } + set { SetProperty(ref _rsrp, value); } + } + + public Brush rsrp_bg { + get { return _rsrp_bg; } + set { SetProperty(ref _rsrp_bg, value); } + } + + public string rsrq { + get { return _rsrq; } + set { SetProperty(ref _rsrq, value); } + } + + public Brush rsrq_bg { + get { return _rsrq_bg; } + set { SetProperty(ref _rsrq_bg, value); } + } + + public string datetime { + get { return _datetime; } + set { SetProperty(ref _datetime, value); } + } + + public void StopTimer () { + if (Object.Equals(_timer, null).Equals(false)) { + _timer.Stop(); + } + } + + private void StartTimer () { + _timer = new System.Timers.Timer { + Interval = 1000, // every second + }; + + _timer.Elapsed += timer_Elapsed; + _timer.Start(); + } + + void timer_Elapsed (object sender, ElapsedEventArgs e) { + new Thread(() => { + SpeedportHybrid.initLtePopup(); + Application.Current.Dispatcher.BeginInvoke(new Action(() => { + LTECollection.Add(new LTEData() { Date = DateTime.Now, Data = rsrq.ToInt() }); + LTECollection2.Add(new LTEData() { Date = DateTime.Now, Data = rsrp.ToInt() }); + + if (LogActive.Equals(true)) { + // log + log(string.Concat("Pysical Cell ID: ", phycellid, ", Cell ID: ", cellid, ", RSRP: ", rsrp, ", RSRQ: ", rsrq)); + } + })); + }).Start(); + } + + private void log (string value) { + DateTime time = DateTime.Now; + + if (Directory.Exists("log/").Equals(false)) + Directory.CreateDirectory("log/"); + + if (Directory.Exists("log/lte/").Equals(false)) + Directory.CreateDirectory("log/lte/"); + + StreamWriter file = new StreamWriter(string.Concat("log/lte/", time.ToString("dd.MM.yyyy"), ".txt"), true); + file.WriteLine(string.Concat("[", time.ToString("dd.MM.yyyy HH:mm:ss"), "]: ", value)); + file.Close(); + } + + private void OnPinCommandExecute () { + if (PinActive.Equals(true)) { + Topmost = true; + } + else { + Topmost = false; + } + } + + private void OnCloseWindowCommandExecute () { + StopTimer(); + } + + public ltepopupModel () { + PinCommand = new DelegateCommand(new Action(OnPinCommandExecute)); + CloseWindowCommand = new DelegateCommand(new Action(OnCloseWindowCommandExecute)); + + LTECollection = new LTECollection(); + LTECollection2 = new LTECollection(); + DateTimeAxis1 = new HorizontalDateTimeAxis(); + DateTimeAxis2 = new HorizontalDateTimeAxis(); + + var ds = new EnumerableDataSource(LTECollection); + ds.SetXMapping(x => DateTimeAxis1.ConvertToDouble(x.Date)); + ds.SetYMapping(y => y.Data); + + RsrqGraph = ds; + + var ds2 = new EnumerableDataSource(LTECollection2); + ds2.SetXMapping(x => DateTimeAxis1.ConvertToDouble(x.Date)); + ds2.SetYMapping(y => y.Data); + + RsrpGraph = ds2; + + StartTimer(); + } + } +} diff --git a/SpeedportHybridControl/SpeedportHybridControl.csproj b/SpeedportHybridControl/SpeedportHybridControl.csproj index 8b32518..3244f9e 100644 --- a/SpeedportHybridControl/SpeedportHybridControl.csproj +++ b/SpeedportHybridControl/SpeedportHybridControl.csproj @@ -48,6 +48,8 @@ + + @@ -74,6 +76,8 @@ + + @@ -83,6 +87,7 @@ + diff --git a/SpeedportHybridControl/ltepopup.xaml b/SpeedportHybridControl/ltepopup.xaml index cf17635..897bd05 100644 --- a/SpeedportHybridControl/ltepopup.xaml +++ b/SpeedportHybridControl/ltepopup.xaml @@ -6,17 +6,24 @@ xmlns:local="clr-namespace:SpeedportHybridControl" mc:Ignorable="d" xmlns:d3="http://research.microsoft.com/DynamicDataDisplay/1.0" + xmlns:ig="http://schemas.infragistics.com/xaml" + xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" Height="423.4" Width="530" - Closing="Window_Closing" Title="LteInfo" + DataContext="{StaticResource ltepopupModel}" + Topmost="{Binding Path=Topmost}" Icon="t-com icon.ico"> - diff --git a/SpeedportHybridControl/ltepopup.xaml.cs b/SpeedportHybridControl/ltepopup.xaml.cs index d7d9117..2ce635c 100644 --- a/SpeedportHybridControl/ltepopup.xaml.cs +++ b/SpeedportHybridControl/ltepopup.xaml.cs @@ -1,121 +1,12 @@ -using System; -using System.Windows; -using System.Windows.Media; -using System.Timers; -using Microsoft.Research.DynamicDataDisplay.DataSources; -using Microsoft.Research.DynamicDataDisplay; -using Microsoft.Research.DynamicDataDisplay.Common; -using System.ComponentModel; -using System.IO; -using SpeedportHybridControl.Data; -using SpeedportHybridControl.Model; +using System.Windows; namespace SpeedportHybridControl { - public class LTECollection : RingArray { - private const int TOTAL_POINTS = 200; - - public LTECollection () : base(TOTAL_POINTS) { - } - } - - public class LTEData { - public DateTime Date { get; set; } - - public int Data { get; set; } - } - /// /// Interaction logic for Window1.xaml /// public partial class ltepopup : Window { - public Timer _timer; - public LTECollection lteCollection; - public LTECollection lteCollection2; - public ltepopup () { InitializeComponent(); - /* - util.init("LTE2"); - - lteCollection = new LTECollection(); - lteCollection2 = new LTECollection(); - - var ds = new EnumerableDataSource(lteCollection); - ds.SetXMapping(x => dateAxis.ConvertToDouble(x.Date)); - ds.SetYMapping(y => y.Data); - plotter.AddLineGraph(ds, Colors.Green, 1, "rsrq"); - - var ds2 = new EnumerableDataSource(lteCollection2); - ds2.SetXMapping(x => dateAxis.ConvertToDouble(x.Date)); - ds2.SetYMapping(y => y.Data); - plotter2.AddLineGraph(ds2, Colors.Green, 1, "rsrp"); - - StartTimer(); - */ - } - - void Window_Closing (object sender, CancelEventArgs e) { - //StopTimer(); - } - /* - public void StopTimer () { - if (Object.Equals(_timer, null).Equals(false)) { - _timer.Stop(); - } - } - - private void StartTimer () { - _timer = new Timer { - Interval = 1000, // every second - }; - - _timer.Elapsed += timer_Elapsed; - _timer.Start(); - } - - private void log (string value) { - DateTime time = DateTime.Now; - - if (Directory.Exists("log/").Equals(false)) - Directory.CreateDirectory("log/"); - - if (Directory.Exists("log/lte/").Equals(false)) - Directory.CreateDirectory("log/lte/"); - - StreamWriter file = new StreamWriter(string.Concat("log/lte/", time.ToString("dd.MM.yyyy"), ".txt"), true); - file.WriteLine(string.Concat("[", time.ToString("dd.MM.yyyy HH:mm:ss"), "]: ", value)); - file.Close(); - } - - void timer_Elapsed (object sender, ElapsedEventArgs e) { - new System.Threading.Thread(() => { - util.init("LTE2"); - - LTE lte = Application.Current.FindResource("LTE2") as LTE; - int rsrq = lte.rsrq.ToInt(); - int rsrp = lte.rsrp.ToInt(); - Application.Current.Dispatcher.BeginInvoke(new Action(() => { - lteCollection.Add(new LTEData() { Date = DateTime.Now, Data = rsrq }); - lteCollection2.Add(new LTEData() { Date = DateTime.Now, Data = rsrp }); - - if (btnLog.IsChecked.Equals(true)) { - // log - log(string.Concat("Pysical Cell ID: ", lte.phycellid, ", Cell ID: ", lte.cellid, ", RSRP: ", lte.rsrp, ", RSRQ: ", lte.rsrq)); - } - })); - }).Start(); - } - - private void button_click (object sender, RoutedEventArgs e) { - if (sender.Equals(btnPin)) { - if (btnPin.IsChecked.Equals(true)) { - Topmost = true; - } - else { - Topmost = false; - } - } } - */ } } -- 2.20.1