fix ltepopup
[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 ltepopupModel lm = Application.Current.FindResource("ltepopupModel") as ltepopupModel;
97 lm.StartTimer();
98 }
99 }
100
101 public bool AutoReload {
102 get { return _autoReload; }
103 set { SetProperty(ref _autoReload, value); }
104 }
105
106 public void StopTimer () {
107 if (Object.Equals(_timer, null).Equals(false)) {
108 _timer.Stop();
109 }
110
111 if (AutoReload.Equals(true)) {
112 AutoReload = false;
113 }
114 }
115
116 private void StartTimer () {
117 _timer = new System.Timers.Timer {
118 Interval = 1000, // every second
119 };
120
121 _timer.Elapsed += timer_Elapsed;
122 _timer.Start();
123 }
124
125 private void timer_Elapsed (object sender, ElapsedEventArgs e) {
126 OnReloadCommandExecute();
127 }
128
129 public string imei {
130 get { return _imei; }
131 set { SetProperty(ref _imei, value); }
132 }
133
134 public string imsi {
135 get { return _imsi; }
136 set { SetProperty(ref _imsi, value); }
137 }
138
139 public string device_status {
140 get { return _device_status; }
141 set { SetProperty(ref _device_status, value); }
142 }
143
144 public string card_status {
145 get { return _card_status; }
146 set { SetProperty(ref _card_status, value); }
147 }
148
149 public string antenna_mode {
150 get { return _antenna_mode; }
151 set { SetProperty(ref _antenna_mode, value); }
152 }
153
154 public string antenna_mode2 {
155 get { return _antenna_mode2; }
156 set { SetProperty(ref _antenna_mode2, value); }
157 }
158
159 public string phycellid {
160 get { return _phycellid; }
161 set { SetProperty(ref _phycellid, value); }
162 }
163
164 public string cellid {
165 get { return _cellid; }
166 set { SetProperty(ref _cellid, value); }
167 }
168
169 public string rsrp {
170 get { return _rsrp; }
171 set { SetProperty(ref _rsrp, value); }
172 }
173
174 public Brush rsrp_bg {
175 get { return _rsrp_bg; }
176 set { SetProperty(ref _rsrp_bg, value); }
177 }
178
179 public string rsrq {
180 get { return _rsrq; }
181 set { SetProperty(ref _rsrq, value); }
182 }
183
184 public Brush rsrq_bg {
185 get { return _rsrq_bg; }
186 set { SetProperty(ref _rsrq_bg, value); }
187 }
188
189 public string service_status {
190 get { return _service_status; }
191 set { SetProperty(ref _service_status, value); }
192 }
193
194 public string tac {
195 get { return _tac; }
196 set { SetProperty(ref _tac, value); }
197 }
198
199 public string datetime {
200 get { return _datetime; }
201 set { SetProperty(ref _datetime, value); }
202 }
203
204 public string frequenz {
205 get { return _frequenz; }
206 set { SetProperty(ref _frequenz, value); }
207 }
208
209 public LteInfoModel () {
210 ReloadCommand = new DelegateCommand(new Action(OnReloadCommandExecute));
211 AutoReloadCommand = new DelegateCommand(new Action(OnAutoReloadCommandExecute));
212 SaveCommand = new DelegateCommand(new Action(OnSaveCommandExecute));
213 PopupCommand = new DelegateCommand(new Action(OnPopupCommandExecute));
214 }
215 }
216 }