CrabtreeOn,印度客户定制APP,迁移2.0平台版本
陈嘉乐
2021-03-03 91c2194fce3958afed333119c3aeed3c49ef6bcf
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Shared.SimpleControl.Phone;
 
namespace Shared
{
    [System.Serializable]
    public class FoolHeat : Common
    {
        public FoolHeat ()
        {
            this.Type = DeviceType.FoolHeat; ;
            DeviceTextID = SimpleControl.R.MyInternationalizationString.FoolHeat;
        }
 
        /// <summary>
        /// 工作模式
        /// 0制热,1制冷,2,3
        /// </summary>
        public byte WorkingMode = 0;
        /// <summary>
        /// 温度模式
        /// </summary>
        public byte TemperatureTypeValue;
 
        /// <summary>
        /// 温度模式
        /// 1 = Normal, 2 = Day , 3 = Night, 4 = Away, 5 = Timer
        /// </summary>
        public byte TemperatureType;
 
        public byte NormalTemperature;
 
        public byte DayTemperature;
 
        public byte NightTemperature;
 
        public byte AwayTemperature;
 
        public byte Timer;//0 = Day, 1 = Night
 
        public byte Status;
        /// <summary>
        /// 阀的开关状态(0--关   1--开)
        /// </summary>
        public byte PWDStatus;
        public byte PWDValue;//0-100
 
        public byte WateringFlag;
 
        public byte WateringTime;
 
        /// <summary>
        /// 工作温度
        /// </summary>
        public byte WorkingTemperature = 5;
        public byte PIDSpeed;
        public byte IndoorTemperature;
        public byte FloorTemperature;
 
        public byte [] FH_Bytes;
 
        public FoolHeat Serverx_FH_CMD (CommandType commandType, byte [] updataBytes = null)
        {
            if (updataBytes != null)
                FH_Bytes = updataBytes;
            if (commandType == CommandType.Read) {
                FH_Bytes = Control.ControlBytesSendHasReturn (Command.ReadFoolHeat, SubnetID, DeviceID, new byte [] { LoopID });
                return this;
            }
            if (FH_Bytes == null)
                return this;
            if (commandType == CommandType.Switch || commandType == CommandType.WorkMode) {
                FH_Bytes = Control.ControlBytesSendHasReturn (Command.SetFoolHeat, SubnetID, DeviceID, new byte [] { LoopID, (byte)(Status + WorkingMode * 16), FH_Bytes [2], FH_Bytes [3], FH_Bytes [4], FH_Bytes [5], FH_Bytes [6], FH_Bytes [7], 0, 0 });
                return this;
            } else if (commandType == CommandType.Temperatrue) {
                switch (TemperatureType) {
                case 1://普通
                    FH_Bytes [4] = this.WorkingTemperature;
                    break;
                case 2://白天
                    FH_Bytes [5] = this.WorkingTemperature;
                    break;
                case 3://夜晚
                    FH_Bytes [6] = this.WorkingTemperature;
                    break;
                case 4://离开
                    FH_Bytes [7] = this.WorkingTemperature;
                    break;
                case 5://时间模式
                    if (FH_Bytes [8] == 1)//时间模式的时间段标志 (0:白天,1:夜晚) (1byte)     //20110112加时间段标志
                        FH_Bytes [4] = this.WorkingTemperature;
                    else
                        FH_Bytes [5] = this.WorkingTemperature;
                    break;
                }
                FH_Bytes = Control.ControlBytesSendHasReturn (Command.SetFoolHeat, SubnetID, DeviceID, new byte [] { LoopID, FH_Bytes [1], FH_Bytes [2], FH_Bytes [3], FH_Bytes [4], FH_Bytes [5], FH_Bytes [6], FH_Bytes [7], 0, 0 });
                return this;
            } else if (commandType == CommandType.TemperatrueMode) {
                FH_Bytes = Control.ControlBytesSendHasReturn (Command.SetFoolHeat, SubnetID, DeviceID, new byte [] { LoopID, FH_Bytes [1], FH_Bytes [2], TemperatureType, FH_Bytes [4], FH_Bytes [5], FH_Bytes [6], FH_Bytes [7], 0, 0 });
                return this;
            }
 
            this.WorkingMode = FH_Bytes [1] > 10 ? (byte)1 : (byte)0;
            this.Status = (byte)(FH_Bytes [1] % 2);
            this.TemperatureType = FH_Bytes [3];
            switch (FH_Bytes [3]) {
            case 1://普通
                this.WorkingTemperature = FH_Bytes [4];
                break;
            case 2://白天
                this.WorkingTemperature = FH_Bytes [5];
                break;
            case 3://夜晚
                this.WorkingTemperature = FH_Bytes [6];
                break;
            case 4://离开
                this.WorkingTemperature = FH_Bytes [7];
                break;
            case 5://时间模式
                if (FH_Bytes [8] == 1)//时间模式的时间段标志 (0:白天,1:夜晚) (1byte)     //20110112加时间段标志
                    this.WorkingTemperature = FH_Bytes [5];
                else
                    this.WorkingTemperature = FH_Bytes [6];
                break;
            }
            this.IndoorTemperature = FH_Bytes [9] > 128 ? (byte)(0 - (FH_Bytes [9] - 128)) : FH_Bytes [9];
            this.PWDStatus = FH_Bytes [10];
            this.PWDValue = FH_Bytes [11];
            this.WateringFlag = FH_Bytes [12];
            this.WateringTime = FH_Bytes [13];
            if (updataBytes != null && commandType == CommandType.Null) {
                if (Application.IsPad) {
                    //SimpleControl.Pad.UserFHPage.UpdateStatus (this);
                } else {
                    UserDeviceToFH.UpdateStatus (this);
                    UserFHPage.UpdateStatus (this);
                    UserRoom.UpdataDeviceStatus (this);
                }
            }
            IO.FileUtils.SaveEquipmentMessage (this, this.LoopID.ToString ());
            return this;
        }
 
        public enum CommandType
        {
            Read = 0,
            Switch = 1,
            Temperatrue = 3,
            TemperatrueMode = 7,
            WorkMode = 9,
            Null = 999,
        }
 
 
        /// <summary>
        /// 模式A协议属性
        /// </summary>
        /// <returns></returns>
        public string SetModeAttribute {
            get {
                //return TemperatureType switch {
                //    1 => "normal",
                //    2 => "day",
                //    3 => "night",
                //    4 => "away",
                //    5 => "timer",
                //    _ => "normal",
                //};
 
                string mode;
                switch (TemperatureType) {
                case 1:
                    mode = "normal";
                    break;
                case 2:
                    mode = "day";
                    break;
                case 3:
                    mode = "night";
                    break;
                case 4:
                    mode = "away";
                    break;
                case 5:
                    mode = "timer";
                    break;
                default:
                    mode = "normal";
                    break;
                }
                return mode;
            }
        }
 
    }
}