forked from bobyuxinyang/dlt645_2007
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdlt645_api_07.c
12818 lines (11510 loc) · 523 KB
/
dlt645_api_07.c
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
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dlt645_api_07.h"
#ifdef D07_DEBUG_ON
INT32 g_need_pack_07 = D07_OFF;
char g_out_data_07[OUT_BUF_LEN] = {0};
#endif
// 数据域长度
#define D07_DATA_LEN_METER_PROG 50
#define D07_DATA_LEN_RECD_METER_CLEAR 106
#define D07_DATA_LEN_RECD_DEAMD_CLEAR 202
/*************************************************
Function: d07_str_to_num
Description: 将长度为len的string转为数字转出
Calls:
Called By:
Input:
Output:
Return:
Others:
*************************************************/
INT32 d07_str_to_num(char* str, INT32 len)
{
char buf[10] = {0};
INT32 i;
if(len > 10)
{
return -1;
}
for(i = 0; i < len; i++)
{
buf[i] = str[i];
}
return atoi(buf);
}
/*****************************************************************************
函 数 名 : d07_hex_str_to_long
功能描述 : 将长度为len的内容,当作十六进制字符串,将为长整数
输入参数 : char*str
INT32 len
输出参数 : 无
返 回 值 :
调用函数 :
被调函数 :
修改历史 :
1.日 期 : 2012年11月23日
作 者 : liming
修改内容 : 新生成函数
*****************************************************************************/
long d07_hex_str_to_long(char*str, INT32 len)
{
long lRet = 0;
INT32 i = 0;
char buf[9]= {0};
if(len > 8 || len <= 0)
{
return 0xFFFFFFFF;
}
for(i = 0; i < len; i++)
{
buf[i] = str[i];
}
lRet = strtol(buf,NULL, 16);
return lRet;
}
void str2bcd(char *str,UINT8 *BCD,INT32 *BCD_length)
{
INT32 i = 0,j = 0,sLen;
INT32 tmp=strlen(str);
if(str==0)
{
return;
}
sLen = tmp;
tmp-=tmp%2;
for(i=0;i<tmp;i++)
{
if(str==0 ||
!((str[i]>='0' && str[i]<='9' )|| (str[i]>='a' && str[i]<='f') || (str[i]>='A' && str[i]<='F')))
return;
}
// for(i=0,j=0;i<tmp/2;i++,j+=2)
for(i=0,j=sLen-1;i<tmp/2;i++,j-=2)
{
// (str[j] > '9') ? (str[j]>'F' ? BCD[i]=str[j]-'a'+10 : BCD[i]=str[j]-'A'+10):( BCD[i]=str[j]-'0');
if(str[j] > '9')
{
if(str[j]>'F')
{
BCD[i]=str[j]-'a'+10;
}
else
{
BCD[i]=str[j]-'A'+10;
}
}
else
{
BCD[i]=str[j]-'0';
}
if(str[j-1]>'9')
{
if(str[j+1]>'F')
{
BCD[i]=(BCD[i]<<4)+str[j+1]-'a'+10;
}
else
{
BCD[i]=(BCD[i]<<4)+str[j+1]-'A'+10;
}
}
else
{
BCD[i]=(BCD[i]<<4)+str[j+1]-'0';
}
// ? (str[j+1]>'F' ? BCD[i]=(BCD[i]<<4)+str[j+1]-'a'+10 : BCD[i]=(BCD[i]<<4)+str[j+1]-'A'+10)
// : BCD[i]=(BCD[i]<<4)+str[j+1]-'0';
}
if(BCD_length)
*BCD_length=tmp/2;
return;
}
/*************************************************
Function: get_d07_ruler_id
Description: 通过规约类型获得对应规约ID
Author: liming
Calls:
Called By:
Input: E_D07_RULER_TYPE type,
S_D07_RULER_PARA para,
Output: UINT32 rulerID 规约ID
Return: 正确返回 0 其它为错误类型
Others: 重要函数,规约解析核心函数
*************************************************/
INT32 get_d07_ruler_id(E_D07_RULER_TYPE type,
S_D07_RULER_PARA para,
UINT32 *poutRulerID)
{
return E_D07_OK;
}
/*************************************************
Function: pack_d07_frame_by_data
Description: 内部函数,仅完成结构体的填充
Author: liming
Calls:
Called By:
Input: S_D07_PACK_FRAME *inPara 用于封帧数据
Output: char *outBuffer 封装后的帧buffer
INT32 *outLength 该帧总长
Return: 正确返回0
Others:
*************************************************/
INT32 pack_d07_frame_by_data(S_D07_PACK_FRAME *inPara, char *outBuffer, INT32 *outLength)
{
INT32 i;
INT32 len = 0; /* 计算包的总字节长 */
UINT8 ucCheckSum = 0;
UINT8 ucDi0,ucDi1,ucDi2,ucDi3;
UINT8 aucAddrTmp[6];
if(NULL == outBuffer || NULL == inPara || NULL == outLength)
{
return E_D07_ERRO_NULL;
}
// 准备数据
ucDi0 = inPara->ruler_id & 0xFF;
ucDi1 = (inPara->ruler_id >> 8) & 0xFF;
ucDi2 = (inPara->ruler_id >> 16) & 0xFF;
ucDi3 = (inPara->ruler_id >> 24) & 0xFF;
d07_str2bcd(inPara->address, aucAddrTmp, 6);
/* 开始封帧 */
// 1 帧起始符
outBuffer[len++] = 0x68;
// 2 地址域
for(i = 0; i < 6; i++)
{
outBuffer[len++] = aucAddrTmp[i];
}
// 3 帧起始符
outBuffer[len++] = 0x68;
// 4 控制码
outBuffer[len++] = inPara->ctrl_code;
// 5 数据域字节数
outBuffer[len++] = inPara->data_len;
//printf("len = %d\n", inPara->data_len);
// 6 规约ID - 以下数据域 逐字节加0x33
outBuffer[len++] = ucDi0 + 0x33;
outBuffer[len++] = ucDi1 + 0x33;
outBuffer[len++] = ucDi2 + 0x33;
outBuffer[len++] = ucDi3 + 0x33;
// 7 其它数据
for(i = 0; i < inPara->data_len - 4; i++)
{
outBuffer[len++] = inPara->data[i] + 0x33;
}
// 8 计数检验和
for(i = 0; i < len; i++)
{
ucCheckSum += outBuffer[i];
}
// 9 检验和
outBuffer[len++] = ucCheckSum;
// 10 结束符
outBuffer[len++] = 0x16;
/* 输出参数 */
*outLength = len;
return E_D07_OK;
}
/*************************************************
Function: trans_d07ctrl_char2struct
Description: 解析将代表它的字节值转化控制码结构输出
Author: liming
Calls:
Called By:
Input: S_D07_CTRL_CODE *inStruct
Output: UINT8 *outChar
Return:
Others: 反转换 trans_d07ctrl_struct2char
*************************************************/
eD07Err trans_d07ctrl_char2struct(UINT8 inChar, S_D07_CTRL_CODE *outStruct)
{
UINT8 ucCtrlCode = inChar;
INT32 func_code = 0;
if(NULL == outStruct)
{
return E_D07_ERRO_NULL;
}
if((ucCtrlCode & 0x80) == 0)
{
outStruct->direct = E_D07_CTRL_DIR_M2S;
}
else
{
outStruct->direct = E_D07_CTRL_DIR_S2M;
}
if((ucCtrlCode & 0x40) == 0)
{
outStruct->reply = E_D07_CTRL_SR_OK;
}
else
{
outStruct->reply = E_D07_CTRL_SR_NO;
}
if((ucCtrlCode & 0x20) == 0)
{
outStruct->follow = E_D07_CTRL_FLW_NONE;
}
else
{
outStruct->follow = E_D07_CTRL_FLW_HAVE;
}
func_code = ucCtrlCode & 0x1F;
switch(func_code)
{
case D07_CTRL_RESV:
outStruct->funcode = E_D07_CTRL_RESV;
break;
case D07_CTRL_SYNC_TIME:
outStruct->funcode = E_D07_CTRL_SYNC_TIME;
break;
case D07_CTRL_READ_DATA:
outStruct->funcode = E_D07_CTRL_READ_DATA;
break;
case D07_CTRL_READ_AFTERDATA:
outStruct->funcode = E_D07_CTRL_READ_AFTERDATA;
break;
case D07_CTRL_READ_ADDR:
outStruct->funcode = E_D07_CTRL_READ_ADDR;
break;
case D07_CTRL_WRITE_DATA:
outStruct->funcode = E_D07_CTRL_WRITE_DATA;
break;
case D07_CTRL_WRITE_ADDR:
outStruct->funcode = E_D07_CTRL_WRITE_ADDR;
break;
case D07_CTRL_FREEZ_COMM:
outStruct->funcode = E_D07_CTRL_FREEZ_COMM;
break;
case D07_CTRL_MODIFY_BAUD:
outStruct->funcode = E_D07_CTRL_MODIFY_BAUD;
break;
case D07_CTRL_MODIFY_PASSWORD:
outStruct->funcode = E_D07_CTRL_MODIFY_PASSWORD;
break;
case D07_CTRL_CLEAR_MAXDEMAND:
outStruct->funcode = E_D07_CTRL_CLEAR_MAXDEMAND;
break;
case D07_CTRL_CLEAR_METER:
outStruct->funcode = E_D07_CTRL_CLEAR_METER;
break;
case D07_CTRL_CLEAR_EVENT:
outStruct->funcode = E_D07_CTRL_CLEAR_EVENT;
break;
case D07_CTRL_COMM:
outStruct->funcode = E_D07_CTRL_COMM;
break;
default:
return E_D07_ERRO_PARA_OUT_RANGE;
}
return E_D07_OK;
}
/*************************************************
Function: trans_d07ctrl_struct2char
Description: 解析控制码结构 将代码它的字节值输出
Author: liming
Calls:
Called By:
Input: S_D07_CTRL_CODE *inStruct
Output: UINT8 *outChar
Return:
Others: 反转换 trans_d07ctrl_char2struct
*************************************************/
eD07Err trans_d07ctrl_struct2char(UINT8 *outChar, S_D07_CTRL_CODE *inStruct)
{
UINT8 ucCtrlCode = 0;
UINT8 ucD7,ucD6,ucD5,ucD40;
if(NULL == outChar || NULL == inStruct)
{
return E_D07_ERRO_NULL;
}
ucD7 = inStruct->direct;
ucD6 = inStruct->reply;
ucD5 = inStruct->follow;
ucD40 = inStruct->funcode;
ucCtrlCode |= ucD7 << 7;
ucCtrlCode |= ucD6 << 6;
ucCtrlCode |= ucD5 << 5;
ucCtrlCode |= ucD40 & 0x1F;
*outChar = ucCtrlCode;
return E_D07_OK;
}
/*************************************************
Function: unpack_d07_frame
Description: 解析DLT645 2007帧功能函数
Author: liming
Calls:
Called By:
Input: inpBuffer 传入包有帧buffer指针
inBufferLength 该buffer长度
Output: outpFrame 该帧的各类详细信息
Return: 正确返回0
Others: 重要的功能函数
*************************************************/
INT32 unpack_d07_frame(void *inpBuffer, INT32 inBufferLength, S_D07_UNPACK *outpFrame)
{
INT32 nNumber0xFE = 0; /* 前导字符的个数 */
INT32 i = 0;
INT32 pos = 0;
INT32 nCheckSumPosStart, nCheckSumPos, nEndPos;
INT32 ret = 0;
UINT8 ucCtrlCode = 0;
UINT8 ucDataLen = 0;
UINT8 ucCheckSum = 0;
UINT32 ulRulerID = 0;
UINT8 *buffer = (UINT8 *)inpBuffer;
char addr_bcd[6] = {0}; //地址信息(BCD形式)
char addr_str[D07_ADDR_LEN+1] = {0}; //地址信息(string形式)
UINT8 aucDataTmp[D07_DATA_MAX];
S_D07_RULER_INFO stRulerInfor = {0};
F_D07_RULER_TRANS pTransFunc; /* 解析函数指针 */
if(NULL == inpBuffer || NULL == outpFrame)
{
return E_D07_ERRO_NULL;
}
if(inBufferLength < D07_FRAME_LEN_MIN)
{
return E_D07_ERRO_FRAME_UNCOMP;
}
for(i = 0; i < 4; i++)
{
if(0xFE == buffer[i])
{
pos++;
nNumber0xFE++;
}
}
nCheckSumPosStart = pos;
// 检查前导字符 0x68
if(0x68 != buffer[pos] || 0x68 != buffer[pos+7])
{
return E_D07_ERRO_FRAME_0x68;
}
//地址
pos++;
for(i = 0; i < 6; i++)
{
addr_bcd[i] = buffer[pos++];
}
pos++;
//地址
d07_bcd2str(addr_bcd, addr_str, 6);
//控制码
ucCtrlCode = buffer[pos++];
//printf("\nCtrlCode = 0x%02X\n", ucCtrlCode);
//转换控制码
ret = trans_d07ctrl_char2struct(ucCtrlCode, &(outpFrame->ctrl_s));
if(E_D07_OK != ret)
{
return ret;
}
//数据域长度
ucDataLen = buffer[pos++];
nCheckSumPos = pos + ucDataLen;
nEndPos = nCheckSumPos+1;
for(i = 0; i < ucDataLen; i++)
{
aucDataTmp[i] = (buffer[pos++] - 0x33);
}
//查检checksum
for(i = nCheckSumPosStart; i < nCheckSumPos; i++)
{
ucCheckSum += buffer[i];
}
if(ucCheckSum != buffer[nCheckSumPos])
{
return E_D07_ERRO_FRAME_CHECK_SUM;
}
//结束符
if(0x16 != buffer[nEndPos])
{
return E_D07_ERRO_FRAME_END_0x16;
}
//地址
for(i = 0; i < D07_ADDR_LEN; i++)
{
outpFrame->address[i] = addr_str[i];
//printf("%d - %c \n",i, addr_str[i]);
}
// 正常的报文
if(E_D07_CTRL_SR_OK == outpFrame->ctrl_s.reply)
{
// 原数据
for(i = 4; i < ucDataLen; i++)
{
outpFrame->data_pack[i-4] = aucDataTmp[i];
}
// 规约ID
ulRulerID = ((aucDataTmp[0] & 0xFF) |
((aucDataTmp[1] << 8) & 0xFF00) |
((aucDataTmp[2] << 16) & 0xFF0000) |
((aucDataTmp[3] << 24) & 0xFF000000));
// 通过ID获取详细信息
ret = get_d07_ruler_info(ulRulerID, &stRulerInfor);
if(E_D07_OK != ret)
{
return ret;
}
if(NULL == stRulerInfor.func)
{
outpFrame->flag = E_D07_UNPD_FLG_FUNC_NULL;
}
else
{
if(ucDataLen > 4)
{
pTransFunc = stRulerInfor.func;
ret = pTransFunc(E_D07_TRANS_F2U,
(void*)&(outpFrame->data_unpack),
(void*)&(outpFrame->data_pack));
if(E_D07_OK == ret)
{
outpFrame->flag = E_D07_UNPD_FLG_OK;
}
else
{
outpFrame->flag = E_D07_UNPD_FLG_FUNC_ERROR;
}
}
}
outpFrame->data_len = ucDataLen - 4;
}
else
{
for(i = 0; i < ucDataLen; i++)
{
outpFrame->data_pack[i] = aucDataTmp[i];
}
// 异常报文
outpFrame->data_len = ucDataLen;
outpFrame->flag = E_D07_UNPD_FLG_ERROR_OK;
ret = trans_d07_data_err(E_D07_TRANS_F2U,
(void*)&(outpFrame->data_unpack),
(void*)&(outpFrame->data_pack));
if(E_D07_OK == ret)
{
outpFrame->flag = E_D07_UNPD_FLG_ERROR_OK;
}
else
{
outpFrame->flag = E_D07_UNPD_FLG_FUNC_ERROR;
}
}
/* 封装输出最后信息 */
outpFrame->lead_num = nNumber0xFE;
outpFrame->ctrl_c = ucCtrlCode;
outpFrame->ruler_id = ulRulerID;
outpFrame->frame_len = ucDataLen + 12;
outpFrame->type = stRulerInfor.type;
outpFrame->format = stRulerInfor.format;
return E_D07_OK;
}
/*************************************************
Function: get_d07_ruler_info
Description: 通过规约ID获得对应规约的详细信息:
(1)规约的类型及额外数据
(2)对应数据格式类型
(3)数据域长度
(4)数据域各数据单位
(5)规约的可读写属性
(6)该规约的数据项名称
(7)实现对该条规约解析和封装函数指针
Author: liming
Calls:
Called By:
Input: UINT32 rulerID 规约ID
Output: S_D07_RULER_INFO *outRulerInfo
Return: 正确返回 0 其它为错误类型
Others: 重要函数,规约解析核心函数
*************************************************/
INT32 get_d07_ruler_info(UINT32 rulerID, S_D07_RULER_INFO *outRulerInfo)
{
UINT8 ucDi3 = 0;
UINT8 ucDi2 = 0;
UINT8 ucDi1 = 0;
UINT8 ucDi0 = 0;
E_D07_RULER_TYPE type = E_D07_RULER_TYPE_UNKNOWN; // 规约类型
E_D07_RULER_RDWR rdwr = E_D07_RDWR_READ_ONLY; // 规约数据的读写属性
E_D07_RULER_FORMAT format = E_D07_FMT_UNKOWN; // 规约数据的格式
F_D07_RULER_TRANS func = NULL; // 数据域转换函数指针
S_D07_RULER_PARA para = {0}; // 规约类型的额外数据
INT32 len = 0; // 数据域字节长度
char name[NAME_LEN] = {0}; // 该条规约数据项名称
char name_1[NAME_LEN] = {0};
char strPayOff[32] = {0};
if(NULL == outRulerInfo)
{
return E_D07_ERRO_NULL;
}
ucDi0 = rulerID & 0xFF;
ucDi1 = (rulerID >> 8) & 0xFF;
ucDi2 = (rulerID >> 16) & 0xFF;
ucDi3 = (rulerID >> 24) & 0xFF;
//printf("D3 = 0x%02X \nD2 = 0x%02X \nD1 = 0x%02X \nD0 = 0x%02X\n", ucDi3, ucDi2,ucDi1,ucDi0);
switch(ucDi3)
{
case 0: //{00}[*][*][*]
{
if(ucDi0 > 0xC) // [00][*][*]{!(0x00~0x0C)}
{
return E_D07_ERRO_UNKOWN_ID;
}
// 封装结算日字符串
if(ucDi0 == 0)
{
sprintf(strPayOff, "%s", "(当前)");
}
else
{
sprintf(strPayOff,"(上%d结算日)", ucDi0);
}
/* 对于表 A.1 相同的数据属性 */
para.payoff = (E_D07_PARA_PAYOFF)(ucDi0 + 1); /* 结算日 */
para.rate = E_D07_RATE_NULL;
para.harm = E_D07_HARM_NULL;
para.last = E_D07_LAST_NULL;
rdwr = E_D07_RDWR_READ_ONLY;
format = E_D07_FMT_XXXXXX_XX;
len = 4;
func = trans_d07_data_XXXXXX_XX;
switch(ucDi2)
{
case 0x0://[00]{00}[*][*]
{
if(0 == ucDi1)//[00][00]{00}[*]
{
type = E_D07_RULER_TYPE_COMB_HAVE_POWER_TOTAL;
sprintf(name_1, "组合有功总电能");
}
else if(ucDi1 >= 0x01 && ucDi1 <= 0x3F) //[00][00]{(1~3F)}[*]
{
type = E_D07_RULER_TYPE_COMB_HAVE_POWER_RATE;
para.rate = (E_D07_PARA_RATE)ucDi1;
sprintf(name_1, "组合有功费率%d电能", ucDi1);
}
else if(0xFF == ucDi1) //[00][00]{FF}[*]
{
type = E_D07_RULER_TYPE_COMB_HAVE_POWER_BLOCK;
sprintf(name_1, "组合有功电能数据块");
}
else //[00][00]{(!(0-3F,FF))}[*]
{
return E_D07_ERRO_UNKOWN_ID;
}
}
break;
case 0x1://[00]{01}[*][*]
{
if(0 == ucDi1)//[00][01]{00}[*]
{
type = E_D07_RULER_TYPE_FORTH_HAVE_POWER_TOTAL;
sprintf(name_1, "正向有功总电能");
}
else if(ucDi1 >= 0x01 && ucDi1 <= 0x3F) //[00][01]{(1~3F)}[*]
{
type = E_D07_RULER_TYPE_FORTH_HAVE_POWER_RATE;
para.rate = (E_D07_PARA_RATE)ucDi1;
sprintf(name_1, "正向有功费率%d电能", ucDi1);
}
else if(0xFF == ucDi1) //[00][01]{FF}[*]
{
type = E_D07_RULER_TYPE_FORTH_HAVE_POWER_BLOCK;
sprintf(name_1, "正向有功电能数据块");
}
else //[00][01]{(!(0-3F,FF))}[*]
{
return E_D07_ERRO_UNKOWN_ID;
}
}
break;
case 0x2://[00]{02}[*][*]
{
if(0 == ucDi1)//[00][02]{00}[*]
{
type = E_D07_RULER_TYPE_BACK_HAVE_POWER_TOTAL;
sprintf(name_1, "反向有功总电能");
}
else if(ucDi1 >= 0x01 && ucDi1 <= 0x3F) //[00][02]{(1~3F)}[*]
{
type = E_D07_RULER_TYPE_BACK_HAVE_POWER_RATE;
para.rate = (E_D07_PARA_RATE)ucDi1;
sprintf(name_1, "反向有功费率%d电能", ucDi1);
}
else if(0xFF == ucDi1) //[00][02]{FF}[*]
{
type = E_D07_RULER_TYPE_BACK_HAVE_POWER_BLOCK;
sprintf(name_1, "反向有功电能数据块");
}
else //[00][02]{(!(0-3F,FF))}[*]
{
return E_D07_ERRO_UNKOWN_ID;
}
}
break;
case 0x3://[00]{03}[*][*]
{
if(0 == ucDi1)//[00][03]{00}[*]
{
type = E_D07_RULER_TYPE_COMB_NONE_1_POWER_TOTAL;
sprintf(name_1, "组合无功1总电能");
}
else if(ucDi1 >= 0x01 && ucDi1 <= 0x3F) //[03][00]{(1~3F)}[*]
{
type = E_D07_RULER_TYPE_COMB_NONE_1_POWER_RATE;
para.rate = (E_D07_PARA_RATE)ucDi1;
sprintf(name_1, "组合无功1费率%d电能", ucDi1);
}
else if(0xFF == ucDi1) //[00][03]{FF}[*]
{
type = E_D07_RULER_TYPE_COMB_NONE_1_POWER_BLOCK;
sprintf(name_1, "组合无功1电能数据块");
}
else //[00][03]{(!(0-3F,FF))}[*]
{
return E_D07_ERRO_UNKOWN_ID;
}
}
break;
case 0x4://[00]{04}[*][*]
{
if(0 == ucDi1)//[00][04]{00}[*]
{
type = E_D07_RULER_TYPE_COMB_NONE_2_POWER_TOTAL;
sprintf(name_1, "组合无功2总电能");
}
else if(ucDi1 >= 0x01 && ucDi1 <= 0x3F) //[04][00]{(1~3F)}[*]
{
type = E_D07_RULER_TYPE_COMB_NONE_2_POWER_RATE;
para.rate = (E_D07_PARA_RATE)ucDi1;
sprintf(name_1, "组合无功2费率%d电能", ucDi1);
}
else if(0xFF == ucDi1) //[00][04]{FF}[*]
{
type = E_D07_RULER_TYPE_COMB_NONE_2_POWER_BLOCK;
sprintf(name_1, "组合无功2电能数据块");
}
else //[00][04]{(!(0-3F,FF))}[*]
{
return E_D07_ERRO_UNKOWN_ID;
}
}
break;
case 0x5://[00]{05}[*][*]
{
if(0 == ucDi1)//[00][05]{00}[*]
{
type = E_D07_RULER_TYPE_QUAD_1_NONE_POWER_TOTAL;
sprintf(name_1, "第一象限无功总电能");
}
else if(ucDi1 >= 0x01 && ucDi1 <= 0x3F) //[00][05]{(1~3F)}[*]
{
type = E_D07_RULER_TYPE_QUAD_1_NONE_POWER_RATE;
para.rate = (E_D07_PARA_RATE)ucDi1;
sprintf(name_1, "第一象限无功费率%d电能", ucDi1);
}
else if(0xFF == ucDi1) //[00][05]{FF}[*]
{
type = E_D07_RULER_TYPE_QUAD_1_NONE_POWER_BLOCK;
sprintf(name_1, "第一象限无功电能数据块");
}
else //[00][05]{(!(0-3F,FF))}[*]
{
return E_D07_ERRO_UNKOWN_ID;
}
}
break;
case 0x6://[00]{06}[*][*]
{
if(0 == ucDi1)//[00][06]{00}[*]
{
type = E_D07_RULER_TYPE_QUAD_2_NONE_POWER_TOTAL;
sprintf(name_1, "第二象限无功总电能");
}
else if(ucDi1 >= 0x01 && ucDi1 <= 0x3F) //[00][06]{(1~3F)}[*]
{
type = E_D07_RULER_TYPE_QUAD_2_NONE_POWER_RATE;
para.rate = (E_D07_PARA_RATE)ucDi1;
sprintf(name_1, "第二象限无功费率%d电能", ucDi1);
}
else if(0xFF == ucDi1) //[00][06]{FF}[*]
{
type = E_D07_RULER_TYPE_QUAD_2_NONE_POWER_BLOCK;
sprintf(name_1, "第二象限无功电能数据块");
}
else //[00][06]{(!(0-3F,FF))}[*]
{
return E_D07_ERRO_UNKOWN_ID;
}
}
break;
case 0x7://[00]{07}[*][*]
{
if(0 == ucDi1)//[00][07]{00}[*]
{
type = E_D07_RULER_TYPE_QUAD_3_NONE_POWER_TOTAL;
sprintf(name_1, "第三象限无功总电能");
}
else if(ucDi1 >= 0x01 && ucDi1 <= 0x3F) //[00][07]{(1~3F)}[*]
{
type = E_D07_RULER_TYPE_QUAD_3_NONE_POWER_RATE;
para.rate = (E_D07_PARA_RATE)ucDi1;
sprintf(name_1, "第三象限无功费率%d电能", ucDi1);
}
else if(0xFF == ucDi1) //[00][07]{FF}[*]
{
type = E_D07_RULER_TYPE_QUAD_3_NONE_POWER_BLOCK;
sprintf(name_1, "第三象限无功电能数据块");
}
else //[00][07]{(!(0-3F,FF))}[*]
{
return E_D07_ERRO_UNKOWN_ID;
}
}
break;
case 0x8://[00]{08}[*][*]
{
if(0 == ucDi1)//[00][08]{00}[*]
{
type = E_D07_RULER_TYPE_QUAD_4_NONE_POWER_TOTAL;
sprintf(name_1, "第四象限无功总电能");
}
else if(ucDi1 >= 0x01 && ucDi1 <= 0x3F) //[00][08]{(1~3F)}[*]
{
type = E_D07_RULER_TYPE_QUAD_4_NONE_POWER_RATE;
para.rate = (E_D07_PARA_RATE)ucDi1;
sprintf(name_1, "第四象限无功费率%d电能", ucDi1);
}
else if(0xFF == ucDi1) //[00][08]{FF}[*]
{
type = E_D07_RULER_TYPE_QUAD_4_NONE_POWER_BLOCK;
sprintf(name_1, "第四象限无功电能数据块");
}
else //[00][08]{(!(0-3F,FF))}[*]
{
return E_D07_ERRO_UNKOWN_ID;
}
}
break;
case 0x9://[00]{09}[*][*]
{
if(0 == ucDi1)//[00][09]{00}[*]
{
type = E_D07_RULER_TYPE_FORTH_APPARENT_POWER_TOTAL;
sprintf(name_1, "正向视在总电能");
}
else if(ucDi1 >= 0x01 && ucDi1 <= 0x3F) //[00][09]{(1~3F)}[*]
{
type = E_D07_RULER_TYPE_FORTH_APPARENT_POWER_RATE;
para.rate = (E_D07_PARA_RATE)ucDi1;
sprintf(name_1, "正向视在费率%d电能", ucDi1);
}
else if(0xFF == ucDi1) //[00][09]{FF}[*]
{
type = E_D07_RULER_TYPE_FORTH_APPARENT_POWER_BLOCK;
sprintf(name_1, "正向视在电能数据块");
}
else //[00][09]{(!(0-3F,FF))}[*]
{
return E_D07_ERRO_UNKOWN_ID;
}
}
break;
case 0xA://[00]{0A}[*][*]
{
if(0 == ucDi1)//[00][0A]{00}[*]
{
type = E_D07_RULER_TYPE_BACK_APPARENT_POWER_TOTAL;
sprintf(name_1, "反向视在总电能");
}
else if(ucDi1 >= 0x01 && ucDi1 <= 0x3F) //[00][0A]{(1~3F)}[*]
{
type = E_D07_RULER_TYPE_BACK_APPARENT_POWER_RATE;