cleanup
[GitHub/Stricted/SpeedportHybridControl.git] / SpeedportHybridControl / PageModel / LteInfoModel.cs
1 using SpeedportHybridControl.Data;
2 using SpeedportHybridControl.Implementations;
3 using SpeedportHybridControl.Model;
4 using System;
5 using System.Threading;
6 using System.Timers;
7 using System.Windows;
8 using System.Windows.Controls;
9 using System.Windows.Media;
10
11 namespace SpeedportHybridControl.PageModel {
12 class LteInfoModel : SuperViewModel {
13 private DelegateCommand _reloadCommand;
14 private DelegateCommand _autoReloadCommand;
15 private DelegateCommand _saveCommand;
16 private DelegateCommand _popupCommand;
17 private System.Timers.Timer _timer;
18 private bool _autoReload;
19 private ltepopup _ltepopup;
20 private ComboBoxItem _selectedItem;
21
22
23 private string _imei;
24 private string _imsi;
25 private string _device_status;
26 private string _card_status;
27 private string _antenna_mode;
28 private string _antenna_mode2;
29 private string _phycellid;
30 private string _cellid;
31 private string _rsrp;
32 private Brush _rsrp_bg = Brushes.Transparent;
33 private string _rsrq;
34 private Brush _rsrq_bg = Brushes.Transparent;
35 private string _service_status;
36 private string _tac;
37 private string _datetime;
38 private string _frequenz;
39
40 public DelegateCommand ReloadCommand {
41 get { return _reloadCommand; }
42 set { SetProperty(ref _reloadCommand, value); }
43 }
44
45 public DelegateCommand AutoReloadCommand {
46 get { return _autoReloadCommand; }
47 set { SetProperty(ref _autoReloadCommand, value); }
48 }
49
50 public DelegateCommand SaveCommand {
51 get { return _saveCommand; }
52 set { SetProperty(ref _saveCommand, value); }
53 }
54
55 public DelegateCommand PopupCommand {
56 get { return _popupCommand; }
57 set { SetProperty(ref _popupCommand, value); }
58 }
59
60 public ComboBoxItem SelectedItem {
61 get { return _selectedItem; }
62 set { SetProperty(ref _selectedItem, value); }
63 }
64
65 private void OnReloadCommandExecute () {
66 new Thread(() => { SpeedportHybrid.initLTE(); }).Start();
67 }
68
69 private void OnAutoReloadCommandExecute () {
70 if (AutoReload.Equals(true)) {
71 StartTimer();
72 }
73 else {
74 StopTimer();
75 }
76 }
77
78 private void OnSaveCommandExecute () {
79 SpeedportHybridAPI.getInstance().setAntennaMode(SelectedItem.Name);
80 OnReloadCommandExecute();
81 }
82
83 private void OnPopupCommandExecute () {
84 if (Object.Equals(_ltepopup, null)) {
85 _ltepopup = new ltepopup();
86 }
87 else if (Object.Equals(_ltepopup, null).Equals(false) && _ltepopup.IsLoaded.Equals(false)) {
88 _ltepopup = null;
89 _ltepopup = new ltepopup();
90 }
91
92 if (_ltepopup.Visibility.Equals(Visibility.Visible).Equals(false)) {
93 _ltepopup.Show();
94 StopTimer();
95 }
96 }
97
98 public bool AutoReload {
99 get { return _autoReload; }
100 set { SetProperty(ref _autoReload, value); }
101 }
102
103 public void StopTimer () {
104 if (Object.Equals(_timer, null).Equals(false)) {
105 _timer.Stop();
106 }
107
108 if (AutoReload.Equals(true)) {
109 AutoReload = false;
110 }
111 }
112
113 private void StartTimer () {
114 _timer = new System.Timers.Timer {
115 Interval = 1000, // every second
116 };
117
118 _timer.Elapsed += timer_Elapsed;
119 _timer.Start();
120 }
121
122 private void timer_Elapsed (object sender, ElapsedEventArgs e) {
123 OnReloadCommandExecute();
124 }
125
126 public string imei {
127 get { return _imei; }
128 set { SetProperty(ref _imei, value); }
129 }
130
131 public string imsi {
132 get { return _imsi; }
133 set { SetProperty(ref _imsi, value); }
134 }
135
136 public string device_status {
137 get { return _device_status; }
138 set { SetProperty(ref _device_status, value); }
139 }
140
141 public string card_status {
142 get { return _card_status; }
143 set { SetProperty(ref _card_status, value); }
144 }
145
146 public string antenna_mode {
147 get { return _antenna_mode; }
148 set { SetProperty(ref _antenna_mode, value); }
149 }
150
151 public string antenna_mode2 {
152 get { return _antenna_mode2; }
153 set { SetProperty(ref _antenna_mode2, value); }
154 }
155
156 public string phycellid {
157 get { return _phycellid; }
158 set { SetProperty(ref _phycellid, value); }
159 }
160
161 public string cellid {
162 get { return _cellid; }
163 set { SetProperty(ref _cellid, value); }
164 }
165
166 public string rsrp {
167 get { return _rsrp; }
168 set { SetProperty(ref _rsrp, value); }
169 }
170
171 public Brush rsrp_bg {
172 get { return _rsrp_bg; }
173 set { SetProperty(ref _rsrp_bg, value); }
174 }
175
176 public string rsrq {
177 get { return _rsrq; }
178 set { SetProperty(ref _rsrq, value); }
179 }
180
181 public Brush rsrq_bg {
182 get { return _rsrq_bg; }
183 set { SetProperty(ref _rsrq_bg, value); }
184 }
185
186 public string service_status {
187 get { return _service_status; }
188 set { SetProperty(ref _service_status, value); }
189 }
190
191 public string tac {
192 get { return _tac; }
193 set { SetProperty(ref _tac, value); }
194 }
195
196 public string datetime {
197 get { return _datetime; }
198 set { SetProperty(ref _datetime, value); }
199 }
200
201 public string frequenz {
202 get { return _frequenz; }
203 set { SetProperty(ref _frequenz, value); }
204 }
205
206 public LteInfoModel () {
207 ReloadCommand = new DelegateCommand(new Action(OnReloadCommandExecute));
208 AutoReloadCommand = new DelegateCommand(new Action(OnAutoReloadCommandExecute));
209 SaveCommand = new DelegateCommand(new Action(OnSaveCommandExecute));
210 PopupCommand = new DelegateCommand(new Action(OnPopupCommandExecute));
211 }
212 }
213 }