mxpopstar
2022-05-03 e75ef5f04f61aa5fbd89fd5c413dcee1819b7a91
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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
package com.dev.bybb;
 
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
 
public class BYBB_Data {
    private final int BYTE_ETH_DATA_LEN = 66*4 + 2;
    private final int BYTE_ETH_STAT_LEN = 56;
    
    int DC_AnDian_Vol_1;
    int DC_AnDian_Curr_1;
    int DC_AnDian_Vol_2;
    int DC_AnDian_Curr_2;
    
    int Batt_GroupVol_1;
    int Batt_GroupCurr_1;
    int Batt_GroupVol_2;
    int Batt_GroupCurr_2;
    
    int QiFa_Vol_1;
    int QiFa_Curr_1;
    int QiFa_Vol_2;
    int QiFa_Curr_2;
    
    int DianJi_Speed;
    int DianJi_Power;
    
    int NiBian_Power1_VolAB;
    int NiBian_Power1_VolBC;
    int NiBian_Power1_VolCA;
    int NiBian_Power1_Power;
    
    int NiBian_Power2_VolAB;
    int NiBian_Power2_VolBC;
    int NiBian_Power2_VolCA;
    int NiBian_Power2_Power;
    
    int NiBian_Power3_VolAB;
    int NiBian_Power3_VolBC;
    int NiBian_Power3_VolCA;
    int NiBian_Power3_Power;
    
    int NiBian_Power4_VolAB;
    int NiBian_Power4_VolBC;
    int NiBian_Power4_VolCA;
    int NiBian_Power4_Power;
    
    int AC_AnDian_VolAB;
    int AC_AnDian_VolBC;
    int AC_AnDian_VolCA;
    int AC_AnDian_Power;
    
    int DC_230V_Fault;
    int DC_25V_Fault;
    int MonitSys_Fault;
    
    int QD103_Curr;
    int QD105_Curr;
    
    int QD203_Curr;
    int QD205_Curr;
    int QD206_Curr;
    
    int QD302_Curr;
    int QD304_Curr;
    int QD305_Curr;
    int QD306_Curr;
    int QD307_Curr;
    int QD308_Curr;
    
    int QD402_Curr;
    int QD404_Curr;
    int QD405_Curr;
    int QD407_Curr;
    int QD408_Curr;
    
    int QA101_A_Curr;
    int QA105_A_Curr;
    
    int QA201_A_Curr;
    int QA205_A_Curr;
    int QA206_A_Curr;
    
    int QA301_A_Curr;
    int QA302_A_Curr;
    int QA305_A_Curr;
    int QA306_A_Curr;
    
    int QA401_A_Curr;
    int QA402_A_Curr;
    int QA403_A_Curr;
    int QA405_A_Curr;
    
    int crc;
    
    private void genRandomData() {
        DC_AnDian_Vol_1 = (int) (900 + Math.random()*100);
        DC_AnDian_Curr_1 = (int) (200 + Math.random()*10);
        DC_AnDian_Vol_2 = (int) (910 + Math.random()*100);
        DC_AnDian_Curr_2 = (int) (100 + Math.random()*10);
        
        Batt_GroupVol_1 = (int) (900 + Math.random()*100);
        Batt_GroupCurr_1 = (int) (-100/* + Math.random()*10*/);
        Batt_GroupVol_2 = (int) (910 + Math.random()*100);
        Batt_GroupCurr_2 = (int) (-200/* + Math.random()*10*/);
        
        QiFa_Vol_1 = (int) (900 + Math.random()*100);
        QiFa_Curr_1 = (int) (300 + Math.random()*50);
        QiFa_Vol_2 = (int) (910 + Math.random()*100);
        QiFa_Curr_2 = (int) (300 + Math.random()*50);
        
        DianJi_Speed = (int) (100 + Math.random()*50);
        DianJi_Power = (int) (10 + Math.random()*10);
        
        NiBian_Power1_VolAB = (int) (380 + Math.random()*10);
        NiBian_Power1_VolBC = (int) (380 + Math.random()*10);
        NiBian_Power1_VolCA = (int) (380 + Math.random()*10);
        NiBian_Power1_Power = (int) (650 + Math.random()*100);
        
        NiBian_Power2_VolAB = (int) (380 + Math.random()*10);
        NiBian_Power2_VolBC = (int) (380 + Math.random()*10);
        NiBian_Power2_VolCA = (int) (380 + Math.random()*10);
        NiBian_Power2_Power = (int) (600 + Math.random()*100);
        
        NiBian_Power3_VolAB = (int) (380 + Math.random()*10);
        NiBian_Power3_VolBC = (int) (380 + Math.random()*10);
        NiBian_Power3_VolCA = (int) (380 + Math.random()*10);
        NiBian_Power3_Power = (int) (500 + Math.random()*100);
        
        NiBian_Power4_VolAB = (int) (380 + Math.random()*10);
        NiBian_Power4_VolBC = (int) (380 + Math.random()*10);
        NiBian_Power4_VolCA = (int) (380 + Math.random()*10);
        NiBian_Power4_Power = (int) (400 + Math.random()*100);
        
        AC_AnDian_VolAB = (int) (380 + Math.random()*10);
        AC_AnDian_VolBC = (int) (380 + Math.random()*10);
        AC_AnDian_VolCA = (int) (380 + Math.random()*10);
        AC_AnDian_Power = (int) (2000 + Math.random()*100);
        
        
        DC_230V_Fault = (int) (Math.random() + 0.5);
        DC_25V_Fault = (int) (Math.random() + 0.5);
        MonitSys_Fault = (int) (Math.random() + 0.5);
        
        QD103_Curr = (int) (100 + Math.random()*50);
        QD105_Curr = (int) (100 + Math.random()*50);
        
        QD203_Curr = (int) (100 + Math.random()*50);
        QD205_Curr = (int) (100 + Math.random()*50);
        QD206_Curr = (int) (100 + Math.random()*50);
        
        QD302_Curr = (int) (100 + Math.random()*50);
        QD304_Curr = (int) (100 + Math.random()*50);
        QD305_Curr = (int) (100 + Math.random()*50);
        QD306_Curr = (int) (100 + Math.random()*50);
        QD307_Curr = (int) (100 + Math.random()*50);
        QD308_Curr = (int) (100 + Math.random()*50);
        
        QD402_Curr = (int) (100 + Math.random()*50);
        QD404_Curr = (int) (100 + Math.random()*50);
        QD405_Curr = (int) (100 + Math.random()*50);
        QD407_Curr = (int) (100 + Math.random()*50);
        QD408_Curr = (int) (100 + Math.random()*50);
        
        QA101_A_Curr = (int) (100 + Math.random()*50);
        QA105_A_Curr = (int) (100 + Math.random()*50);
        
        QA201_A_Curr = (int) (100 + Math.random()*50);
        QA205_A_Curr = (int) (100 + Math.random()*50);
        QA206_A_Curr = (int) (100 + Math.random()*50);
        
        QA301_A_Curr = (int) (100 + Math.random()*50);
        QA302_A_Curr = (int) (100 + Math.random()*50);
        QA305_A_Curr = (int) (100 + Math.random()*50);
        QA306_A_Curr = (int) (100 + Math.random()*50);
        
        QA401_A_Curr = (int) (100 + Math.random()*50);
        QA402_A_Curr = (int) (100 + Math.random()*50);
        QA403_A_Curr = (int) (100 + Math.random()*50);
        QA405_A_Curr = (int) (100 + Math.random()*50);
    }
    
    public ArrayList<byte[]> makeEthData(short dev_id) {
        genRandomData();
        
        ByteBuffer bf = ByteBuffer.allocate(500);
        bf.order(ByteOrder.BIG_ENDIAN);
        
        bf.putShort( dev_id );
        bf.putShort( (short) 0x0D0E );
        bf.putShort( (short) (BYTE_ETH_DATA_LEN / 2) );
        
        bf.putFloat((float)DC_AnDian_Vol_1 );
        bf.putFloat((float)DC_AnDian_Curr_1 );
        bf.putFloat((float)DC_AnDian_Vol_2 );
        bf.putFloat((float)DC_AnDian_Curr_2 );
        
        bf.putFloat((float)Batt_GroupVol_1 );
        bf.putFloat((float)Batt_GroupCurr_1 );
        bf.putFloat((float)Batt_GroupVol_2 );
        bf.putFloat((float)Batt_GroupCurr_2 );
        
        bf.putFloat((float)QiFa_Vol_1 );
        bf.putFloat((float)QiFa_Curr_1 );
        bf.putFloat((float)QiFa_Vol_2 );
        bf.putFloat((float)QiFa_Curr_2 );
        
        bf.putFloat((float)DianJi_Speed );
        bf.putFloat((float)DianJi_Power );
        
        bf.putFloat((float)NiBian_Power1_VolAB );
        bf.putFloat((float)NiBian_Power1_VolBC );
        bf.putFloat((float)NiBian_Power1_VolCA );
        bf.putFloat((float)NiBian_Power1_Power );
        
        bf.putFloat((float)NiBian_Power2_VolAB );
        bf.putFloat((float)NiBian_Power2_VolBC );
        bf.putFloat((float)NiBian_Power2_VolCA );
        bf.putFloat((float)NiBian_Power2_Power );
        
        bf.putFloat((float)NiBian_Power3_VolAB );
        bf.putFloat((float)NiBian_Power3_VolBC );
        bf.putFloat((float)NiBian_Power3_VolCA );
        bf.putFloat((float)NiBian_Power3_Power );
        
        bf.putFloat((float)NiBian_Power4_VolAB );
        bf.putFloat((float)NiBian_Power4_VolBC );
        bf.putFloat((float)NiBian_Power4_VolCA );
        bf.putFloat((float)NiBian_Power4_Power );
        
        bf.putFloat((float)AC_AnDian_VolAB );
        bf.putFloat((float)AC_AnDian_VolBC );
        bf.putFloat((float)AC_AnDian_VolCA );
        bf.putFloat((float)AC_AnDian_Power );
        
        bf.putInt( DC_230V_Fault );
        bf.putInt( DC_25V_Fault );
        bf.putInt( MonitSys_Fault );
        
        bf.putFloat((float)QD103_Curr );
        bf.putFloat((float)QD105_Curr );
        
        bf.putFloat((float)QD203_Curr );
        bf.putFloat((float)QD205_Curr );
        bf.putFloat((float)QD206_Curr );
        
        bf.putInt( QD302_Curr );
        bf.putInt( QD304_Curr );
        bf.putInt( QD305_Curr );
        bf.putInt( QD306_Curr );
        bf.putInt( QD307_Curr );
        bf.putInt( QD308_Curr );
        
        bf.putInt( QD402_Curr );
        bf.putInt( QD404_Curr );
        bf.putInt( QD405_Curr );
        bf.putInt( QD407_Curr );
        bf.putInt( QD408_Curr );
        
        bf.putInt( QA101_A_Curr );
        bf.putInt( QA105_A_Curr );
        
        bf.putInt( QA201_A_Curr );
        bf.putInt( QA205_A_Curr );
        bf.putInt( QA206_A_Curr );
        
        bf.putInt( QA301_A_Curr );
        bf.putInt( QA302_A_Curr );
        bf.putInt( QA305_A_Curr );
        bf.putInt( QA306_A_Curr );
        
        bf.putInt( QA401_A_Curr );
        bf.putInt( QA402_A_Curr );
        bf.putInt( QA403_A_Curr );
        bf.putInt( QA405_A_Curr );
        /*
        bf.putInt( DC_AnDian_Vol_1 );
        bf.putInt( DC_AnDian_Curr_1 );
        bf.putInt( DC_AnDian_Vol_2 );
        bf.putInt( DC_AnDian_Curr_2 );
        
        bf.putInt( Batt_GroupVol_1 );
        bf.putInt( Batt_GroupCurr_1 );
        bf.putInt( Batt_GroupVol_2 );
        bf.putInt( Batt_GroupCurr_2 );
        
        bf.putInt( QiFa_Vol_1 );
        bf.putInt( QiFa_Curr_1 );
        bf.putInt( QiFa_Vol_2 );
        bf.putInt( QiFa_Curr_2 );
        
        bf.putInt( DianJi_Speed );
        bf.putInt( DianJi_Power );
        
        bf.putInt( NiBian_Power1_VolAB );
        bf.putInt( NiBian_Power1_VolBC );
        bf.putInt( NiBian_Power1_VolCA );
        bf.putInt( NiBian_Power1_Power );
        
        bf.putInt( NiBian_Power2_VolAB );
        bf.putInt( NiBian_Power2_VolBC );
        bf.putInt( NiBian_Power2_VolCA );
        bf.putInt( NiBian_Power2_Power );
        
        bf.putInt( NiBian_Power3_VolAB );
        bf.putInt( NiBian_Power3_VolBC );
        bf.putInt( NiBian_Power3_VolCA );
        bf.putInt( NiBian_Power3_Power );
        
        bf.putInt( NiBian_Power4_VolAB );
        bf.putInt( NiBian_Power4_VolBC );
        bf.putInt( NiBian_Power4_VolCA );
        bf.putInt( NiBian_Power4_Power );
        
        bf.putInt( AC_AnDian_VolAB );
        bf.putInt( AC_AnDian_VolBC );
        bf.putInt( AC_AnDian_VolCA );
        bf.putInt( AC_AnDian_Power );
        
        bf.putInt( DC_230V_Fault );
        bf.putInt( DC_25V_Fault );
        bf.putInt( MonitSys_Fault );
        
        bf.putInt( QD103_Curr );
        bf.putInt( QD105_Curr );
        
        bf.putInt( QD203_Curr );
        bf.putInt( QD205_Curr );
        bf.putInt( QD206_Curr );
        
        bf.putInt( QD302_Curr );
        bf.putInt( QD304_Curr );
        bf.putInt( QD305_Curr );
        bf.putInt( QD306_Curr );
        bf.putInt( QD307_Curr );
        bf.putInt( QD308_Curr );
        
        bf.putInt( QD402_Curr );
        bf.putInt( QD404_Curr );
        bf.putInt( QD405_Curr );
        bf.putInt( QD407_Curr );
        bf.putInt( QD408_Curr );
        
        bf.putInt( QA101_A_Curr );
        bf.putInt( QA105_A_Curr );
        
        bf.putInt( QA201_A_Curr );
        bf.putInt( QA205_A_Curr );
        bf.putInt( QA206_A_Curr );
        
        bf.putInt( QA301_A_Curr );
        bf.putInt( QA302_A_Curr );
        bf.putInt( QA305_A_Curr );
        bf.putInt( QA306_A_Curr );
        
        bf.putInt( QA401_A_Curr );
        bf.putInt( QA402_A_Curr );
        bf.putInt( QA403_A_Curr );
        bf.putInt( QA405_A_Curr );
        */
        //bf.putInt( crc );
        
        bf.flip();
        
        ArrayList<byte[]> ret_dat = new ArrayList<byte[]>();
        byte[] bb = new byte[bf.limit()];
        bf.get(bb);
        ret_dat.add(bb);
        
        return ret_dat;
    }
    
    public ArrayList<byte[]> makeEthStatData(short dev_id) {
        ByteBuffer bf = ByteBuffer.allocate(500);
        bf.order(ByteOrder.BIG_ENDIAN);
        
        bf.putShort( dev_id );
        bf.putShort( (short) 0x0D0E );
        bf.putShort( (short) (BYTE_ETH_STAT_LEN / 2) );
        
        for(int n=6; n<BYTE_ETH_STAT_LEN; n++) {
            bf.put( (byte)(Math.random()*1000) );
        }
        bf.flip();
        
        ArrayList<byte[]> ret_dat = new ArrayList<byte[]>();
        byte[] bb = new byte[bf.limit()];
        bf.get(bb);
        ret_dat.add(bb);
        
        return ret_dat;
    }
    
    static private byte[] genCanFrame(byte[] can_id, int val1, int val2, int val3, int val4, int dat_cnt) {
        ByteBuffer bf = ByteBuffer.allocate(100);
        bf.order(ByteOrder.LITTLE_ENDIAN);
        
        byte[] dat = new byte[13];
        bf.clear();
        bf.put((byte) ((byte)0x80 + (byte)(dat_cnt*2)));
        bf.put(can_id);
        bf.putShort( (short) val1 );
        bf.putShort( (short) val2 );
        bf.putShort( (short) val3 );
        bf.putShort( (short) val4 );
        bf.flip();
        bf.get(dat);
        
        return dat;
    }
    
    ArrayList<byte[]> makeCanData() {
        ArrayList<byte[]> al_bytes = new ArrayList<byte[]>();
        genRandomData();
        
        byte[] can_id = new byte[4];
        can_id[0] = (byte) 0x1E;
        can_id[1] = (byte) 0x86;
        can_id[2] = (byte) 0x68;
        can_id[3] = (byte) 0x00;
        
        al_bytes.add(genCanFrame(can_id, DC_AnDian_Vol_1, DC_AnDian_Curr_1, DC_AnDian_Vol_2, DC_AnDian_Curr_2, 4));
        
        can_id[3] += 1;
        al_bytes.add(genCanFrame(can_id, Batt_GroupVol_1, Batt_GroupCurr_1, Batt_GroupVol_2, Batt_GroupCurr_2, 4));
    
        can_id[3] += 1;
        al_bytes.add(genCanFrame(can_id, QiFa_Vol_1, QiFa_Curr_1, QiFa_Vol_2, QiFa_Curr_2, 4));
        
        can_id[3] += 1;
        al_bytes.add(genCanFrame(can_id, DianJi_Speed, DianJi_Power, 0, 0, 4));
    
        can_id[3] += 1;
        al_bytes.add(genCanFrame(can_id, NiBian_Power1_VolAB, NiBian_Power1_VolBC, 
                                         NiBian_Power1_VolCA, NiBian_Power1_Power, 4));
    
        can_id[3] += 1;
        al_bytes.add(genCanFrame(can_id, NiBian_Power2_VolAB, NiBian_Power2_VolBC, 
                                         NiBian_Power2_VolCA, NiBian_Power2_Power, 4));
    
        can_id[3] += 1;
        al_bytes.add(genCanFrame(can_id, NiBian_Power3_VolAB, NiBian_Power3_VolBC, 
                                         NiBian_Power3_VolCA, NiBian_Power3_Power, 4));
    
        can_id[3] += 1;
        al_bytes.add(genCanFrame(can_id, NiBian_Power4_VolAB, NiBian_Power4_VolBC, 
                                         NiBian_Power4_VolCA, NiBian_Power4_Power, 4));
    
        can_id[3] += 1;
        al_bytes.add(genCanFrame(can_id, AC_AnDian_VolAB, AC_AnDian_VolBC, 
                                         AC_AnDian_VolCA, AC_AnDian_Power, 4));
        can_id[3] += 1;
        al_bytes.add(genCanFrame(can_id, DC_230V_Fault, DC_25V_Fault, 
                                         MonitSys_Fault, 0, 3));
    
        return al_bytes;
    }
    
    ArrayList<byte[]> makeCanStatData(){
        ArrayList<byte[]> al_bytes = new ArrayList<byte[]>();
        
        byte[] can_id = new byte[4];
        can_id[0] = (byte) 0x1E;
        can_id[1] = (byte) 0x86;
        can_id[2] = (byte) 0x68;
        can_id[3] = (byte) 0x00;
        
        al_bytes.add(genCanFrame(can_id, (short)(Math.random()*100000), (short)(Math.random()*100000), 
                                         (short)(Math.random()*100000), (short)(Math.random()*100000), 4));
        
        can_id[3] += 1;
        al_bytes.add(genCanFrame(can_id, (short)(Math.random()*100000), (short)(Math.random()*100000), 
                                          (short)(Math.random()*100000), (short)(Math.random()*100000), 4));
    
        can_id[3] += 1;
        al_bytes.add(genCanFrame(can_id, (short)(Math.random()*100000), (short)(Math.random()*100000), 
                                          (short)(Math.random()*100000), (short)(Math.random()*100000), 4));
        
        return al_bytes;
    }
    
    static public ArrayList<byte[]> iniCanFrameData(byte[] can_id, int frame_cnt) {
        ArrayList<byte[]> al_bytes = new ArrayList<byte[]>();
        
        for(int n=0; n<frame_cnt; n++) {
            al_bytes.add(genCanFrame(can_id, (short)(0), (short)(0), (short)(0), (short)(0), 4));
            can_id[3] += 1;
        }
        
        return al_bytes;
    }
}