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
using FObjBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
/// <summary>
/// 公共类型
/// </summary>
namespace FLY.Thick.BulkDataModule
{
/// <summary>
/// 一幅数据是否有效
/// </summary>
public enum FR_DATA_TYPE
{
/// <summary>
/// 无效
/// </summary>
INVALID = 0,
/// <summary>
/// 有效
/// </summary>
VALID = 1
}
/// <summary>
///
/// </summary>
public class FR_DATA : IPack2
{
public FR_DATA_TYPE type;
public int bookmark;// bookmark ID
public DateTime timemark;
public int[] m_data;
public override string ToString()
{
return bookmark.ToString();
}
public FR_DATA(int bm, int[] data, FR_DATA_TYPE type)
{
bookmark = bm;
timemark = DateTime.Now;
m_data = (int[])data.Clone();
this.type = type;
}
public FR_DATA()
{
}
public bool TryParse(byte[] value, int index, out int cnt)
{
cnt = 4 + 8 + 4;
if (index + cnt > value.Length)
return false;
int idx = index;
bookmark = BitConverter.ToInt32(value, idx);
idx += 4;
try
{
timemark = new DateTime(BitConverter.ToInt64(value, idx));
}
catch
{
timemark = DateTime.MinValue;
}
idx += 8;
type = (FR_DATA_TYPE)BitConverter.ToInt32(value, idx);
idx += 4;
//data
cnt += 4;
if (index + cnt > value.Length)
return false;
int len = BitConverter.ToInt32(value, idx);
idx += 4;
cnt += len * 4;
if (index + cnt > value.Length)
return false;
if (len > 0)
{
m_data = new int[len];
for (int i = 0; i < len; i++)
{
m_data[i] = BitConverter.ToInt32(value, idx);
idx += 4;
}
}
return true;
}
public byte[] ToBytes()
{
List<byte> buf = new List<byte>();
buf.AddRange(BitConverter.GetBytes(bookmark));
buf.AddRange(BitConverter.GetBytes(timemark.Ticks));
buf.AddRange(BitConverter.GetBytes((int)type));
if (m_data == null)
{
buf.AddRange(BitConverter.GetBytes(0));
}
else
{
buf.AddRange(BitConverter.GetBytes(m_data.Length));
for (int i = 0; i < m_data.Length; i++)
{
buf.AddRange(BitConverter.GetBytes(m_data[i]));
}
}
return buf.ToArray();
}
public bool TryParse(byte[] value)
{
int cnt;
return TryParse(value, 0, out cnt);
}
}
/// <summary>
/// 它是 struct, 值类型,所以不用 Clone!!!!!
/// </summary>
public struct TrendDataCell
{
/// <summary>
/// 时间
/// </summary>
public DateTime Time;
/// <summary>
/// 平均值
/// </summary>
public int Avg;
/// <summary>
/// sigma
/// </summary>
public int Sigma;
/// <summary>
/// 类型
/// </summary>
public FR_DATA_TYPE Type;
/// <summary>
///
/// </summary>
/// <returns></returns>
public override string ToString()
{
return Time.ToShortTimeString() + " " + Avg.ToString();
}
#region IPack 成员
/// <summary>
/// 输出20个字节
/// </summary>
/// <returns></returns>
public byte[] ToBytes()
{
List<byte> buf = new List<byte>();
buf.AddRange(BitConverter.GetBytes(Time.Ticks));
buf.AddRange(BitConverter.GetBytes(Avg));
buf.AddRange(BitConverter.GetBytes(Sigma));
buf.AddRange(BitConverter.GetBytes((int)Type));
return buf.ToArray();
}
/// <summary>
/// 使用20个字节转换
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public bool TryParse(byte[] value, int startIndex )
{
int count = 8 + 4 * 3;
if (value.Length < count)
return false;
int idx = startIndex;
Time = new DateTime(BitConverter.ToInt64(value, idx));
idx += 8;
Avg = BitConverter.ToInt32(value, idx);
idx += 4;
Sigma = BitConverter.ToInt32(value, idx);
idx += 4;
Type = (FR_DATA_TYPE)BitConverter.ToInt32(value, idx);
idx += 4;
return true;
}
public TrendDataCell Clone()
{
return new TrendDataCell()
{
Time = Time,
Avg = Avg,
Sigma = Sigma,
Type = Type
};
}
#endregion
}
/// <summary>
/// 获取模式
/// </summary>
public enum PushMode
{
/// <summary>
/// 获取并且推送
/// </summary>
GetAndPush,
/// <summary>
/// 只获取
/// </summary>
Get
}
/// <summary>
/// 它是 struct, 值类型,所以不用 Clone!!!!!
/// </summary>
public struct FrameDataCell
{
/// <summary>
/// 平均值
/// </summary>
public int Avg;
/// <summary>
/// sigma
/// </summary>
public int Sigma;
/// <summary>
///
/// </summary>
/// <returns></returns>
public override string ToString()
{
return Avg.ToString();
}
#region IPack 成员
/// <summary>
/// 输出20个字节
/// </summary>
/// <returns></returns>
public byte[] ToBytes()
{
List<byte> buf = new List<byte>();
buf.AddRange(BitConverter.GetBytes(Avg));
buf.AddRange(BitConverter.GetBytes(Sigma));
return buf.ToArray();
}
/// <summary>
/// 使用8个字节转换
/// </summary>
/// <param name="value"></param>
/// <param name="startIndex"></param>
/// <returns></returns>
public bool TryParse(byte[] value, int startIndex)
{
int count = 4 * 2;
if (value.Length < count)
return false;
int idx = startIndex;
Avg = BitConverter.ToInt32(value, idx);
idx += 4;
Sigma = BitConverter.ToInt32(value, idx);
idx += 4;
return true;
}
/// <summary>
/// 复制
/// </summary>
/// <returns></returns>
public FrameDataCell Clone()
{
return new FrameDataCell()
{
Avg = Avg,
Sigma = Sigma,
};
}
#endregion
}
}