1 using SpeedportHybridControl.Data;
2 using SpeedportHybridControl.Implementations;
3 using SpeedportHybridControl.Model;
6 using System.Threading;
10 namespace SpeedportHybridControl.PageModel {
11 class DslPageModel : SuperViewModel {
12 private DelegateCommand _reloadCommand;
13 private DelegateCommand _autoReloadCommand;
14 private bool _autoReload;
16 private bool _logEnabled;
17 private System.Timers.Timer _timer;
19 private Connection _Connection;
21 private string _datetime;
23 private string _lastCRC;
24 private string _lastHEC;
25 private string _lastFEC;
28 public Connection Connection {
29 get { return _Connection; }
30 set { SetProperty(ref _Connection, value); }
35 set { SetProperty(ref _Line, value); }
38 public string datetime {
39 get { return _datetime; }
40 set { SetProperty(ref _datetime, value); }
43 public string lastCRC {
44 get { return _lastCRC; }
45 set { SetProperty(ref _lastCRC, value); }
48 public string lastFEC {
49 get { return _lastFEC; }
50 set { SetProperty(ref _lastFEC, value); }
53 public string lastHEC {
54 get { return _lastHEC; }
55 set { SetProperty(ref _lastHEC, value); }
59 public DelegateCommand ReloadCommand {
60 get { return _reloadCommand; }
61 set { SetProperty(ref _reloadCommand, value); }
64 public DelegateCommand AutoReloadCommand {
65 get { return _autoReloadCommand; }
66 set { SetProperty(ref _autoReloadCommand, value); }
68 public bool AutoReload {
69 get { return _autoReload; }
70 set { SetProperty(ref _autoReload, value); }
75 set { SetProperty(ref _log, value); }
78 public bool LogEnabled {
79 get { return _logEnabled; }
80 set { SetProperty(ref _logEnabled, value); }
83 private void OnReloadCommandExecute () {
84 new Thread(() => { SpeedportHybrid.initDSL(); }).Start();
87 private void OnAutoReloadCommandExecute () {
88 if (AutoReload.Equals(true)) {
97 public void StopTimer () {
98 if (Object.Equals(_timer, null).Equals(false)) {
102 if (AutoReload.Equals(true)) {
106 if (Log.Equals(true)) {
113 private void StartTimer () {
114 _timer = new System.Timers.Timer {
115 Interval = 1000, // every second
118 _timer.Elapsed += timer_Elapsed;
122 private void timer_Elapsed (object sender, ElapsedEventArgs e) {
123 SpeedportHybrid.initDSL();
125 Application.Current.Dispatcher.BeginInvoke(new Action(() => {
126 if (Log.Equals(true)) {
128 string prepare = "State: {0}, Actual Data Rate: up: {1} down: {2}, Attainable Data Rate: up: {3} down: {4}, SNR Margin up: {5} down: {6}, CRC error count: up: {7} down: {8}, HEC error count: up: {9} down: {10}, FEC error count: up: {11} down: {12}";
129 log(string.Format(prepare, Connection.state, Line.uactual, Line.dactual, Line.uattainable, Line.dattainable, Line.uSNR, Line.dSNR, Line.uCRC, Line.dCRC, Line.uHEC, Line.dHEC, Line.uFEC, Line.dFEC));
130 log(string.Format("CRC/min up: {0} down: {1}, HEC/min up: {2} down: {3}, FEC/min up: {4} down: {5}", Line.uCRCsec, Line.dCRCsec, Line.uHECsec, Line.dHECsec, Line.uFECsec, Line.dFECsec));
135 private void log (string value) {
136 DateTime time = DateTime.Now;
138 if (Directory.Exists("log/").Equals(false))
139 Directory.CreateDirectory("log/");
141 if (Directory.Exists("log/dsl/").Equals(false))
142 Directory.CreateDirectory("log/dsl/");
144 StreamWriter file = new StreamWriter(string.Concat("log/dsl/", time.ToString("dd.MM.yyyy"), ".txt"), true);
145 file.WriteLine(string.Concat("[", time.ToString("dd.MM.yyyy HH:mm:ss"), "]: ", value));
149 public DslPageModel () {
150 ReloadCommand = new DelegateCommand(new Action(OnReloadCommandExecute));
151 AutoReloadCommand = new DelegateCommand(new Action(OnAutoReloadCommandExecute));