JLChen
2020-06-05 f86c8b5dcf5c84386745b009fc4115fa9db3b76d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
using System;
using System.Collections.Generic;
 
namespace Shared.SimpleControl.Phone
{
    public class SystemSensor : FrameLayout
    {
        void ReadStatus (Sensor sensor, Button btnContent)
        {
            System.Threading.Tasks.Task.Run (() => {
                var bytes = Control.ControlBytesSendHasReturn (Command.ReadDeviceLoopInfo, sensor.SubnetID, sensor.DeviceID, new byte [] { sensor.BigClass,sensor.MinClass,sensor.LoopID });
                Application.RunOnMainThread (() => {
                    switch (sensor.Type) {
                    case DeviceType.SensorLPG:
                        SensorLPG sensorLPG = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorLPG> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
                        btnContent.Text = sensorLPG.CurrentLPG.ToString () + " ppm";
                        break;
                    case DeviceType.SensorCH4:
                        SensorCH4 sensorCH4 = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorCH4> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
                        btnContent.Text = sensorCH4.CurrentCH4.ToString () + " ppm";
                        break;
                    case DeviceType.SensorCOH2:
                        SensorCOH2 sensorCOH2 = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorCOH2> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
                        btnContent.Text = sensorCOH2.CurrentCOH2.ToString () + " ppm";
                        break;
                    case DeviceType.SensorSmoke:
                        SensorSmoke sensorSmoke = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorSmoke> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
                        btnContent.TextID = sensorSmoke.CurrentStatus == 0 ? R.MyInternationalizationString.Close : R.MyInternationalizationString.Open;
                        break;
                    case DeviceType.SensorMobileDetection:
                        SensorMobileDetection sensorMobileDetection = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorMobileDetection> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
                        btnContent.TextID = sensorMobileDetection.Status == 0 ? R.MyInternationalizationString.Close : R.MyInternationalizationString.Open;
                        break;
                    case DeviceType.SensorTemperature:
                        SensorTemperature sensorTemperature = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorTemperature> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
                        btnContent.Text = sensorTemperature.CurrentTemperature.ToString () + " °";
                        break;
                    case DeviceType.SensorHumidity:
                        SensorHumidity sensorHumidity = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorHumidity> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
                        btnContent.Text = sensorHumidity.CurrentHumidity.ToString () + " %";
                        break;
                    case DeviceType.SensorIllumination:
                        SensorIllumination sensorIllumination = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorIllumination> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
                        btnContent.Text = sensorIllumination.CurrentIllumination.ToString () + " %";
                        break;
                    case DeviceType.SensorTVOC:
                        SensorTVOC SensorTVOC = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorTVOC> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
                        btnContent.Text = SensorTVOC.CurrentTVOC.ToString () + " mg/m3";
                        break;
                    case DeviceType.SensorPM25:
                        SensorPM25 sensorPM25 = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorPM25> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
                        btnContent.Text = sensorPM25.CurrentPM25.ToString ();
                        break;
                    case DeviceType.SensorCO2:
                        SensorCO2 sensorCO2 = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorCO2> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
                        btnContent.Text = sensorCO2.CurrentCO2.ToString () + " ppm";
                        break;
                    case DeviceType.SensorWindSpeed:
                        SensorWindSpeed sensorWindSpeed = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorWindSpeed> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
                        btnContent.Text = sensorWindSpeed.CurrentWindSpeed.ToString ();
                        break;
                    case DeviceType.SensorWindPressure:
                        SensorWindPressure sensorWindPressure = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorWindPressure> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
                        btnContent.Text = sensorWindPressure.CurrentWindPressure.ToString ();
                        break;
                    case DeviceType.SensorLiquidFlow:
                        SensorLiquidFlow sensorLiquidFlow = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorLiquidFlow> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
                        btnContent.Text = sensorLiquidFlow.CurrentLiquidFlow.ToString ();
                        break;
                    case DeviceType.SensorLiquidPressure:
                        SensorLiquidPressure sensorLiquidPressure = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorLiquidPressure> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
                        btnContent.Text = sensorLiquidPressure.CurrentLiquidPressure.ToString ();
                        break;
                    case DeviceType.SensorLiquidDepth:
                        SensorLiquidDepth sensorLiquidDepth = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorLiquidDepth> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
                        btnContent.Text = sensorLiquidDepth.CurrentLiquidDepth.ToString ();
                        break;
                    case DeviceType.SensorRainfall:
                        SensorRainfall sensorRainfall = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorRainfall> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
                        btnContent.Text = sensorRainfall.CurrentRainfall.ToString ();
                        break;
                    case DeviceType.SensorWeight:
                        SensorWeight sensorWeight = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorWeight> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
                        btnContent.Text = sensorWeight.CurrentWeight.ToString () + " KG";
                        break;
                    case DeviceType.SensorHeightLength:
                        SensorHeightLength sensorHeightLength = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorHeightLength> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
                        btnContent.Text = sensorHeightLength.CurrentHeightLength.ToString () + " mm";
                        break;
                    case DeviceType.SensorVelocity:
                        SensorVelocity sensorVelocity = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorVelocity> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
                        btnContent.Text = sensorVelocity.CurrentVelocity.ToString () + " m/s";
                        break;
                    case DeviceType.SensorVibration:
                        SensorVibration sensorVibration = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorVibration> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
                        btnContent.TextID = sensorVibration.CurrentVibration == 0 ? R.MyInternationalizationString.Close : R.MyInternationalizationString.Open;
                        break;
                    case DeviceType.SensorVoltage:
                        SensorVoltage sensorVoltage = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorVoltage> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
                        btnContent.Text = sensorVoltage.CurrentVoltage.ToString () + " V";
                        break;
                    case DeviceType.SensorCurrent:
                        SensorCurrent sensorCurrent = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorCurrent> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
                        btnContent.Text = sensorCurrent.CurrentCurrent.ToString () + " A";
                        break;
                    case DeviceType.SensorPower:
                        SensorPower sensorPower = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorPower> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
                        btnContent.Text = sensorPower.CurrentPower.ToString () + " W";
                        break;
                    }
                });
            });
        }
 
 
        public void SystemSensorShow (Sensor sensor, Common common)
        {
            byte [] lightDimmingBytes = new byte [26];
            #region  top
            RowLayout topTitleView = new RowLayout () {
                Height = Application.GetRealHeight (100),
                BackgroundColor = SkinStyle.Current.MainColor
            };
            AddChidren (topTitleView);
            Button backButton = new Button () {
                Height = Application.GetRealHeight (90),
                Width = Application.GetRealWidth (85),
                UnSelectedImagePath = "Item/Back.png",
                SelectedImagePath = "Item/BackSelected.png",
                Gravity = Gravity.CenterVertical,
            };
            backButton.MouseUpEventHandler += (sender, e) => {
                (Parent as PageLayout).PageIndex -= 1;
                //SystemEquipmentBase.RefreshView (common);
            };
            topTitleView.AddChidren (backButton);
 
            EditText textButton = new EditText () {
                X = Application.GetRealWidth (30) + backButton.Right,
                Height = Application.GetRealHeight (50),
                Width = Application.GetRealWidth (400),
                Text = sensor.Name,
                TextAlignment = TextAlignment.CenterLeft,
                Gravity = Gravity.CenterVertical,
                BackgroundColor = SkinStyle.Current.Transparent,
                SelectedBackgroundColor = SkinStyle.Current.SubtitleView,
                Enable = false,
                TextColor = SkinStyle.Current.TextColor1
            };
            topTitleView.AddChidren (textButton);
 
            Button editor = new Button () {
                X = Application.GetRealWidth (520),
                Height = Application.GetRealHeight (90),
                Width = Application.GetRealWidth (70),
                UnSelectedImagePath = "Item/Editor.png",
                SelectedImagePath = "Item/EditorSelected.png",
                Gravity = Gravity.CenterVertical,
            };
            topTitleView.AddChidren (editor);
            EventHandler<MouseEventArgs> eHandler = new EventHandler<MouseEventArgs> ((sender, e) => {
                if (editor.IsSelected) {
                    MainPage.Loading.Start ();
                    byte [] remakeBytes = CommonPage.MyEncodingGB2312.GetBytes (textButton.Text.Trim ());
                    textButton.IsSelected = editor.IsSelected = textButton.Enable = false;
                    System.Threading.Tasks.Task.Run (() => {
                        byte [] updateBytes = Control.ControlBytesSendHasReturn (Command.ReadDeviceLoopInfo, sensor.SubnetID, sensor.DeviceID, new byte [] {
                            sensor.BigClass,sensor.MinClass,sensor.LoopID
                        });
                        if (updateBytes == null) {
                            Application.RunOnMainThread (() => {
                                MainPage.Loading.Hide ();
                                new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                            });
                            return;
                        }
                        byte [] uBytes = new byte [20];
                        Array.Copy (remakeBytes, 0, uBytes, 0, remakeBytes.Length < 20 ? remakeBytes.Length : 20);
                        Array.Copy (uBytes, 0, updateBytes, 3, 20 < uBytes.Length ? 20 : uBytes.Length);
                        var reBytes = Control.ControlBytesSendHasReturn (Command.SetDeviceLoopInfo, sensor.SubnetID, sensor.DeviceID, updateBytes);
                        if (reBytes != null) {
                            Application.RunOnMainThread (() => {
                                sensor.Name = textButton.Text.Trim ();
                                IO.FileUtils.SaveEquipmentMessage (sensor, sensor.LoopID.ToString ());
                                MainPage.Loading.Hide ();
                            });
                        } else {
                            Application.RunOnMainThread (() => {
                                new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                                MainPage.Loading.Hide ();
                            });
                        }
                    });
                } else {
                    textButton.Enable = textButton.IsSelected = editor.IsSelected = true;
                }
            });
            editor.MouseUpEventHandler += eHandler;
            #endregion
 
            #region MyRegion
            FrameLayout frameLayoutBody = new FrameLayout () {
                Y = Application.GetRealHeight (100),
                Height = Application.GetRealHeight (700),
            };
            AddChidren (frameLayoutBody);
 
            FrameLayout ContentView = new FrameLayout (){
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight(80),
                Width = Application.GetMinRealAverage (300),
                Height = Application.GetMinRealAverage(200),
                BorderWidth = (uint)Application.GetMinRealAverage(3),
                BorderColor = SkinStyle.Current.TextColor1,
                Radius = (uint)Application.GetMinRealAverage(100),
            };
            frameLayoutBody.AddChidren (ContentView);
 
            Button btnTitle = new Button () { 
                Y = Application.GetMinRealAverage (20),
                Width = Application.GetMinRealAverage(300),
                Height = Application.GetMinRealAverage(80),
                TextAlignment = TextAlignment.Center,
                TextColor = SkinStyle.Current.TextColor1,
            };
            ContentView.AddChidren (btnTitle);
 
            Button btnContent = new Button () { 
                Y = btnTitle.Bottom,
                Width = Application.GetMinRealAverage(300),
                Height = Application.GetMinRealAverage(80),
                TextAlignment = TextAlignment.Center,
                TextColor = SkinStyle.Current.TextColor1,
                Text = "--"
            };
            ContentView.AddChidren (btnContent);
 
            switch (sensor.Type) {
            case DeviceType.SensorLPG:
                btnTitle.TextID = R.MyInternationalizationString.SensorLPG;
                break;
            case DeviceType.SensorCH4:
                btnTitle.TextID = R.MyInternationalizationString.SensorCH4;
                break;
            case DeviceType.SensorCOH2:
                btnTitle.TextID = R.MyInternationalizationString.SensorCOH2;
                break;
            case DeviceType.SensorSmoke:
                btnTitle.TextID = R.MyInternationalizationString.SensorSmoke;
                break;
            case DeviceType.SensorMobileDetection:
                btnTitle.TextID = R.MyInternationalizationString.SensorMobileDetection;
                break;
            case DeviceType.SensorTemperature:
                btnTitle.TextID = R.MyInternationalizationString.SensorTemperature;
                break;
            case DeviceType.SensorHumidity:
                btnTitle.TextID = R.MyInternationalizationString.SensorHumidity;
                break;
            case DeviceType.SensorIllumination:
                btnTitle.TextID = R.MyInternationalizationString.SensorIllumination;
                break;
            case DeviceType.SensorTVOC:
                btnTitle.TextID = R.MyInternationalizationString.SensorTVOC;
                break;
            case DeviceType.SensorPM25:
                btnTitle.TextID = R.MyInternationalizationString.SensorPM25;
                break;
            case DeviceType.SensorCO2:
                btnTitle.TextID = R.MyInternationalizationString.SensorCO2;
                break;
            case DeviceType.SensorWindSpeed:
                btnTitle.TextID = R.MyInternationalizationString.SensorWindSpeed;
                break;
            case DeviceType.SensorWindPressure:
                btnTitle.TextID = R.MyInternationalizationString.SensorWindPressure;
                break;
            case DeviceType.SensorLiquidFlow:
                btnTitle.TextID = R.MyInternationalizationString.SensorLiquidFlow;
                break;
            case DeviceType.SensorLiquidPressure:
                btnTitle.TextID = R.MyInternationalizationString.SensorLiquidPressure;
                break;
            case DeviceType.SensorLiquidDepth:
                btnTitle.TextID = R.MyInternationalizationString.SensorLiquidDepth;
                break;
            case DeviceType.SensorRainfall:
                btnTitle.TextID = R.MyInternationalizationString.SensorRainfall;
                break;
            case DeviceType.SensorWeight:
                btnTitle.TextID = R.MyInternationalizationString.SensorWeight;
                break;
            case DeviceType.SensorHeightLength:
                btnTitle.TextID = R.MyInternationalizationString.SensorHeightLength;
                break;
            case DeviceType.SensorVelocity:
                btnTitle.TextID = R.MyInternationalizationString.SensorVelocity;
                break;
            case DeviceType.SensorVibration:
                btnTitle.TextID = R.MyInternationalizationString.SensorVibration;
                break;
            case DeviceType.SensorVoltage:
                btnTitle.TextID = R.MyInternationalizationString.SensorVoltage;
                break;
            case DeviceType.SensorCurrent:
                btnTitle.TextID = R.MyInternationalizationString.SensorCurrent;
                break;
            case DeviceType.SensorPower:
                btnTitle.TextID = R.MyInternationalizationString.SensorPower;
                break;
            }
 
            #endregion
 
            ReadStatus (sensor, btnContent);
 
            //SystemMiddle.hideBottom ();
        }
   
    }
}