factor.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. /******************************************************************************
  2. 版权所有:
  3. 文件名称: factor.c
  4. 文件版本: 01.01
  5. 创建作者: sunxi
  6. 创建日期: 2013-05-20
  7. 功能说明: 通道参数处理。
  8. 其它说明:
  9. 修改记录:
  10. */
  11. /*------------------------------- 头文件 --------------------------------------
  12. */
  13. #include "head.h"
  14. /*------------------------------- 宏定义 --------------------------------------
  15. */
  16. #define FACTOR_P_BASE (-360.0/32/8)
  17. //CT PT标度,1V或1A对应的码值
  18. // = (二次有效值/一次有效值)*(AD码值范围/电压范围(V))*1.4142
  19. // = (7.07/一次有效值)*(65536/20)*1.4142
  20. // = (7.07*65536/20*1.4142)/ 一次有效值.
  21. #define SCALE_PT_BIG (32768.0) // 二次有效值为7.07V或3.53V,需对应改变ADC的输入范围
  22. #define SCALE_CT_BIG (32768.0) // 二次有效值为7.07V或3.53V,需对应改变ADC的输入范围
  23. // 使用初级电阻标识
  24. #define SCALE_PT_102K (1.650*32768/5.0*1.4142) // DTU FTU使用电阻配置100V
  25. #define SCALE_PT_120K (1.032*32768/2.5*1.4142) //153K
  26. #define SCALE_PT_150K (1.0348*32768/2.5*1.4142) // 开普测试,测量范围264 增加了电阻
  27. #define SCALE_PT_172K (0.916*32768/2.5*1.4142) // 加264V相电压二次用万用表测有效值为0.916v
  28. // #define SCALE_PT_204K (0.513*32768/2.5*1.4142) // 次级电阻200k 最终版本
  29. // DTUv5与DTUv4同样硬件,系数一样
  30. #define SCALE_PT_204K (0.1105*32768/2.5*1.4142) // 加264V相电压二次用万用表测有效值为0.063v 初级241KΩ次级100Ω
  31. // 使用次级电阻标识
  32. #define SCALE_CT_100A_51 (2.526*32768/5.0*1.4142) // 次级电阻51欧,,加5A相电流二次用万用表测有效值为0.127V
  33. #define SCALE_CT_10A_51 (0.254*32768/2.5*1.4142) // 次级电阻51欧,加10A相电流二次用万用表测有效值为0.254V
  34. #define SCALE_CT_10A_120 (1.27*32768/2.5*1.4142) // 次级电阻249欧,加10A相电流二次用万用表测有效值为0.643V // 零序穿心5倍 最大量程20A
  35. #define SCALE_CT_10A_249 (1.265*32768/5.0*1.4142) // 1ACT 量程20A
  36. #define SCALE_CT_10A_604 (3.235*32768/5.0*1.4142) // 次级电阻604欧,加10A相电流二次用万用表测有效值为3.235V
  37. #define SCALE_EVT (32768.0)
  38. #define SCALE_ECT (32768.0)
  39. #define SCALE_PT_DEFAULT SCALE_PT_204K
  40. #define SCALE_CT_DEFAULT SCALE_CT_100A_51
  41. /*------------------------------ 类型结构 -------------------------------------
  42. */
  43. /*------------------------------ 全局变量 -------------------------------------
  44. */
  45. // 比例系数计算方法请参考<电子互感器比例系数计算方法.xlsx>
  46. static const float g_e_k[EQU_SCALE_NUM] =
  47. {
  48. SCALE_PT_BIG/(220*1.2),
  49. SCALE_PT_DEFAULT/(220*1.2),
  50. SCALE_EVT/(108.7856586), // EQU_SCALE_EVT_3V25_100V,10/(3.25*1.414)*100;
  51. SCALE_EVT/(31.31), // EQU_SCALE_EVT 最大测到30V
  52. #if 1
  53. SCALE_CT_BIG/54.752,
  54. #else
  55. SCALE_CT_BIG/100,
  56. #endif
  57. SCALE_CT_DEFAULT/100 ,
  58. SCALE_ECT/(10.60660172), // EQU_SCALE_ECT_1V_1A, 1V=1A
  59. SCALE_ECT/(11.73797257), // EQU_SCALE_ECT_0V2_1A,0.2V=1A.
  60. SCALE_CT_10A_51/10 ,
  61. SCALE_PT_102K/(220*1.2),
  62. SCALE_PT_120K/(220*1.2),
  63. SCALE_PT_172K/(220*1.2),
  64. SCALE_PT_204K/(220*1.2),
  65. SCALE_CT_10A_604/10 ,
  66. SCALE_CT_10A_120/10 ,
  67. SCALE_CT_10A_249/10 ,
  68. };
  69. //一次/二次变比
  70. static const float g_e_ps[EQU_SCALE_NUM] =
  71. {
  72. 10000.0/220.0,
  73. 10000.0/100.0,
  74. 10000.0/100.0, // EQU_SCALE_EVT_3V25_100V,10/(3.25*1.414)*100;
  75. 5773.502692/(100.0/3), // EQU_SCALE_EVT_6V50_100V,
  76. 600.0/5.0,
  77. 600.0/5.0,
  78. 600.0/1.0, // EQU_SCALE_ECT_1V_1A, 1V=1A
  79. 20.0/1.0, // EQU_SCALE_ECT_0V2_1A,0.2V=1A.
  80. 600.0/1.0,
  81. 10000.0/100.0,
  82. 10000.0/100.0,
  83. 10000.0/100.0,
  84. 10000.0/100.0,
  85. 10000.0/100.0,
  86. 10000.0/100.0,
  87. 10000.0/100.0,
  88. };
  89. // 电子互感器和电磁互感器二次值换算的比值
  90. const float g_e_k_ECVT[EQU_SCALE_NUM] =
  91. {
  92. 1.0,
  93. 1.0,
  94. 0.0325, // EQU_SCALE_EVT_3V25_100V,10/(3.25*1.414)*100;
  95. 0.065, // EQU_SCALE_EVT_6V50_100V,
  96. 1.0,
  97. 1.0,
  98. 1.0, // EQU_SCALE_ECT_1V_1A, 1V=1A
  99. 0.2, // EQU_SCALE_ECT_0V2_1A,0.2V=1A.
  100. 1.0,
  101. 1.0,
  102. 1.0,
  103. 1.0,
  104. 1.0,
  105. 1.0,
  106. 1.0,
  107. 1.0,
  108. };
  109. struct ac_slot_factor g_ac_factor[EQU_SLOT_AC_NUM];
  110. u32 g_factor_version = ACFACTOR_FILE_VERSION;
  111. u16 g_base_v,g_base_i;
  112. /*------------------------------ 函数声明 -------------------------------------
  113. */
  114. int factor_read_all(void);
  115. int factor_printf_temp(void);
  116. /*------------------------------ 外部函数 -------------------------------------
  117. 外部函数供其它实体文件引用,必须仔细检查传入参数的合法性.
  118. */
  119. int factor_init(void)
  120. {
  121. int slot,ret;
  122. // 取默认值
  123. g_factor_version = ACFACTOR_FILE_VERSION;
  124. for(slot=0; slot<EQU_SLOT_AC_NUM; slot++)
  125. {
  126. factor_get_default(&g_ac_factor[slot]);
  127. }
  128. // 检查装置配置
  129. if(equ_config_null())
  130. {
  131. return -1;
  132. }
  133. // 从文件系统读取系数
  134. ret = factor_read_all();
  135. if(ret != 0)
  136. {
  137. rt_err_set(ERR_CODE_FACTOR,0);
  138. printf("交流系数文件错误: (ret=%d)\r\n", ret);
  139. return -2;
  140. }
  141. return 0;
  142. }
  143. int factor_exit(void)
  144. {
  145. return 0;
  146. }
  147. int factor_read(u32 slot,struct ac_slot_factor *asf)
  148. {
  149. // 检查参数
  150. slot -= g_ac_slot_begin;
  151. if(slot >= EQU_SLOT_AC_NUM || asf == NULL)
  152. {
  153. return -1;
  154. }
  155. memcpy ((u8*)asf, &g_ac_factor[slot], sizeof(struct ac_slot_factor));
  156. return 0;
  157. }
  158. /******************************************************************************
  159. 函数名称: factor_write
  160. 函数版本: 01.01
  161. 创建作者: xxxxxx
  162. 创建日期: 2015-10-23
  163. 函数说明: 创建交流系数文件
  164. 参数说明: 无
  165. 返回值: 成功返回0.
  166. 修改记录:
  167. */
  168. int factor_write(u32 slot,struct ac_slot_factor *asf)
  169. {
  170. // 检查参数
  171. slot -= g_ac_slot_begin;
  172. if(slot >= EQU_SLOT_AC_NUM || asf == NULL)
  173. {
  174. return -1;
  175. }
  176. memcpy (&g_ac_factor[slot],(u8*)asf, sizeof(struct ac_slot_factor));
  177. return 0;
  178. }
  179. /******************************************************************************
  180. 函数名称: factor_read
  181. 函数版本: 01.01
  182. 创建作者: xxxxxx
  183. 创建日期: 2015-10-23
  184. 函数说明: 读取交流系数文件
  185. 参数说明: 无
  186. 返回值: 成功返回0.
  187. 修改记录:
  188. */
  189. int factor_read_all(void)
  190. {
  191. int len;
  192. u16 crc;
  193. u8 *buf;
  194. off_t pos;
  195. struct file * pfile;
  196. //int file_size;
  197. struct acfactor_file_head_data *brh;
  198. // 创建并打开文件
  199. pfile = (struct file *)rt_file_open("/app/data/acfactor.bin",O_RDWR,0);
  200. if(IS_ERR(pfile))
  201. {
  202. return -2;
  203. }
  204. // 得到文件长度
  205. len = rt_file_getfile_size(pfile);
  206. if(len <= 0)
  207. {
  208. rt_file_close(pfile, 0);
  209. return -21;
  210. }
  211. // 分配内存
  212. buf = (u8 *)rt_malloc(len);
  213. if((buf) == NULL)
  214. {
  215. rt_file_close(pfile,0);
  216. return -3;
  217. }
  218. // 读出内容
  219. pos = 0;
  220. if(rt_file_read(pfile,buf,len,&pos) != len)
  221. {
  222. rt_file_close(pfile,0);
  223. rt_free(buf);
  224. return -4;
  225. }
  226. // 关闭文件
  227. rt_file_close(pfile,0);
  228. // 检查CRC
  229. crc = CrcStr(buf,len-2);
  230. if(crc != *(u16*)(buf+len-2))
  231. {
  232. rt_free(buf);
  233. return -5;
  234. }
  235. // 检查文件签名
  236. brh = (struct acfactor_file_head_data*)buf;
  237. if(brh->cfh.signature != SIG_ACFACTOR_FILE)
  238. {
  239. rt_free(buf);
  240. return -6;
  241. }
  242. #if 0
  243. // 检查文件版本
  244. if(brh->cfh.version != ACFACTOR_FILE_VERSION)
  245. {
  246. rt_free(buf);
  247. return -66;
  248. }
  249. #endif
  250. //noted by sunxi: 20220413 暂进屏蔽
  251. #if 0
  252. // 检查FLASH唯一ID号
  253. if (memcmp (brh->auth_id, g_auth_id, 8) != 0)
  254. {
  255. rt_free(buf);
  256. return -7;
  257. }
  258. #endif
  259. // 检查板卡数量
  260. if(brh->num != EQU_SLOT_AC_NUM)
  261. {
  262. rt_free(buf);
  263. return -77;
  264. }
  265. // 检查文件长度
  266. if(len < (int)(sizeof(*brh) + brh->num*sizeof(struct ac_slot_factor)+ 2))
  267. {
  268. rt_free(buf);
  269. return -8;
  270. }
  271. //取出文件中存储内容
  272. g_factor_version = brh->cfh.version;
  273. g_base_v = brh->base_v;
  274. g_base_i = brh->base_i;
  275. memcpy ((u8*)g_ac_factor, buf+brh->addr, EQU_SLOT_AC_NUM*sizeof(struct ac_slot_factor));
  276. rt_free(buf);
  277. return 0;
  278. }
  279. int factor_write_all(u16 base_v,u16 base_i)
  280. {
  281. unsigned int addr,file_length;
  282. u16 crc;
  283. char *p;
  284. off_t pos;
  285. int pfile;
  286. struct acfactor_file_head_data acfactor_file;
  287. // 写文件头
  288. memset(&acfactor_file,0,sizeof(acfactor_file));
  289. acfactor_file.cfh.signature = SIG_ACFACTOR_FILE;
  290. acfactor_file.cfh.version = ACFACTOR_FILE_VERSION;
  291. memcpy (&acfactor_file.auth_id, g_auth_id, 8);
  292. acfactor_file.base_v = base_v ? base_v : g_base_v;
  293. acfactor_file.base_i = base_i ? base_i : g_base_i;
  294. g_base_v = acfactor_file.base_v;
  295. g_base_i = acfactor_file.base_i;
  296. acfactor_file.addr = FILE_ADDR_ALGIN(sizeof(acfactor_file));
  297. acfactor_file.num = EQU_SLOT_AC_NUM;
  298. // 得到文件长度
  299. addr = acfactor_file.addr + acfactor_file.num * sizeof(struct ac_slot_factor);
  300. file_length = FILE_ADDR_ALGIN(addr);
  301. // 分配并初始化空间
  302. p = (u8 *)rt_malloc(file_length + 2);
  303. if(!p)
  304. {
  305. rt_err_set(ERR_CODE_FACTOR,0);
  306. return -2;
  307. }
  308. memset(p, 0, file_length + 2);
  309. // 写入文件头
  310. memcpy(p, (char *)&acfactor_file, sizeof(acfactor_file));
  311. // 写系数
  312. memcpy(p+acfactor_file.addr, g_ac_factor, EQU_SLOT_AC_NUM * sizeof(struct ac_slot_factor));
  313. // 计算CRC
  314. crc = CrcStr(p, file_length);
  315. memcpy(p+file_length, &crc, 2);
  316. //swap16(p+file_length);//added by sunxi: 大小端问题 ----- 维护工具好像没有处理crc的大小端
  317. // 创建数据文件
  318. pfile = rt_file_open("/app/data/acfactor.bin",O_CREAT|O_RDWR|O_TRUNC,0);
  319. if(IS_ERR(pfile))
  320. {
  321. rt_err_set(ERR_CODE_FACTOR,0);
  322. rt_free(p);
  323. return -3;
  324. }
  325. pos = 0;
  326. rt_file_write(pfile, p, file_length+2, &pos);
  327. rt_file_close(pfile,0);
  328. rt_free(p);
  329. system("sync");//noted by sunxi: 把写好的文件,写到系统中去,不然,断电重启,有机会掉失
  330. //清除交流告警灯
  331. rt_err_clr(ERR_CODE_FACTOR,0);
  332. return 0;
  333. }
  334. int factor_write_board(u32 slot,struct ac_slot_factor *asf)
  335. {
  336. int ret ;
  337. ret = factor_write(slot,asf);
  338. if(ret != 0)
  339. {
  340. rt_err_set(ERR_CODE_FACTOR,slot);
  341. rt_printf("factor_write_board:slot=%lu,ret=%d.\r\n",slot,ret);
  342. return -1;
  343. }
  344. g_base_v = 0;
  345. g_base_i = 0;
  346. ret = factor_write_all(0,0);
  347. return ret;
  348. }
  349. int factor_get_default(struct ac_slot_factor *asf)
  350. {
  351. int i;
  352. if(asf == NULL)
  353. {
  354. return -1;
  355. }
  356. for(i=0; i<EQU_SLOT_AC_CHN; i++)
  357. {
  358. asf->factor_e_c[i] = 1.0;
  359. asf->factor_p_c[i] = 0.0;
  360. #ifdef PROTECT_AC_ADJUST
  361. asf->factor_p_e_c[i] = 1.0;
  362. #endif
  363. asf->pq_factor[i][0] = 0.0;
  364. asf->pq_factor[i][1] = 0.0;
  365. }
  366. asf->temp = 35.0;
  367. return 0;
  368. }
  369. int factor_restore_default(void)
  370. {
  371. int slot,ret ;
  372. // 取默认值
  373. g_factor_version = ACFACTOR_FILE_VERSION;
  374. for(slot=0; slot<EQU_SLOT_AC_NUM; slot++)
  375. {
  376. factor_get_default(&g_ac_factor[slot]);
  377. }
  378. // 重新初始化开关
  379. sw_init();
  380. // 保存
  381. g_base_v = 0;
  382. g_base_i = 0;
  383. ret = factor_write_all(0,0);
  384. rt_printf("factor_restore_default(ret=%d).\r\n",ret);
  385. return ret;
  386. }
  387. int factor_e_c_get(u32 slot,u32 index,float *f)
  388. {
  389. // 检查参数
  390. if(index >=(u32)equ_get_ac_num(slot))
  391. {
  392. return -1;
  393. }
  394. if(f == NULL)
  395. {
  396. return -2;
  397. }
  398. slot -= g_ac_slot_begin;
  399. if(slot >= EQU_SLOT_AC_NUM)
  400. {
  401. return -3;
  402. }
  403. *f = g_ac_factor[slot].factor_e_c[index];
  404. return 0;
  405. }
  406. int factor_e_c_set(u32 slot,u32 index,float f)
  407. {
  408. // 检查参数
  409. if(index >=(u32)equ_get_ac_num(slot))
  410. {
  411. return -1;
  412. }
  413. slot -= g_ac_slot_begin;
  414. if(slot >= EQU_SLOT_AC_NUM)
  415. {
  416. return -2;
  417. }
  418. g_ac_factor[slot].factor_e_c[index] = f;
  419. return 0;
  420. }
  421. int factor_p_c_get(u32 slot,u32 index,float *f)
  422. {
  423. // 检查参数
  424. if(index >=(u32)equ_get_ac_num(slot))
  425. {
  426. return -1;
  427. }
  428. if(f == NULL)
  429. {
  430. return -2;
  431. }
  432. slot -= g_ac_slot_begin;
  433. if(slot >= EQU_SLOT_AC_NUM)
  434. {
  435. return -3;
  436. }
  437. *f = g_ac_factor[slot].factor_p_c[index];
  438. return 0;
  439. }
  440. int factor_p_c_set(u32 slot,u32 index,float f)
  441. {
  442. // 检查参数
  443. if(index >=(u32)equ_get_ac_num(slot))
  444. {
  445. return -1;
  446. }
  447. slot -= g_ac_slot_begin;
  448. if(slot >= EQU_SLOT_AC_NUM)
  449. {
  450. return -2;
  451. }
  452. g_ac_factor[slot].factor_p_c[index] = f;
  453. return 0;
  454. }
  455. #ifdef PROTECT_AC_ADJUST
  456. int factor_p_e_c_get(u32 slot,u32 index,float *f)
  457. {
  458. // 检查参数
  459. if(index >=(u32)equ_get_ac_num(slot))
  460. {
  461. return -1;
  462. }
  463. if(f == NULL)
  464. {
  465. return -2;
  466. }
  467. slot -= g_ac_slot_begin;
  468. if(slot >= EQU_SLOT_AC_NUM)
  469. {
  470. return -3;
  471. }
  472. *f = g_ac_factor[slot].factor_p_e_c[index];
  473. return 0;
  474. }
  475. int factor_p_e_c_set(u32 slot,u32 index,float f)
  476. {
  477. // 检查参数
  478. if(index >=(u32)equ_get_ac_num(slot))
  479. {
  480. return -1;
  481. }
  482. slot -= g_ac_slot_begin;
  483. if(slot >= EQU_SLOT_AC_NUM)
  484. {
  485. return -2;
  486. }
  487. g_ac_factor[slot].factor_p_e_c[index] = f;
  488. return 0;
  489. }
  490. #endif
  491. int factor_pq_get(u32 slot,u32 index,float *f)
  492. {
  493. // 检查参数
  494. if(index >=(u32)equ_get_ac_num(slot))
  495. {
  496. return -1;
  497. }
  498. if(f == NULL)
  499. {
  500. return -2;
  501. }
  502. slot -= g_ac_slot_begin;
  503. if(slot >= EQU_SLOT_AC_NUM)
  504. {
  505. return -3;
  506. }
  507. *f++ = g_ac_factor[slot].pq_factor[index][0];
  508. *f = g_ac_factor[slot].pq_factor[index][1];
  509. return 0;
  510. }
  511. int factor_pq_set(u32 slot,u32 index,float *f)
  512. {
  513. // 检查参数
  514. if(index >=(u32)equ_get_ac_num(slot))
  515. {
  516. return -1;
  517. }
  518. if(f == NULL)
  519. {
  520. return -2;
  521. }
  522. slot -= g_ac_slot_begin;
  523. if(slot >= EQU_SLOT_AC_NUM)
  524. {
  525. return -3;
  526. }
  527. g_ac_factor[slot].pq_factor[index][0] = *f++;
  528. g_ac_factor[slot].pq_factor[index][1] = *f;
  529. return 0;
  530. }
  531. float factor_e_k(u32 index)
  532. {
  533. if(index >= EQU_SCALE_NUM)
  534. {
  535. return -1;
  536. }
  537. return g_e_k[index];
  538. }
  539. float factor_e_ps(u32 index)
  540. {
  541. if(index >= EQU_SCALE_NUM)
  542. {
  543. return -1;
  544. }
  545. return g_e_ps[index];
  546. }
  547. float factor_p_k(u32 index)
  548. {
  549. if(index >= CFG_ADC_CHANNEL)
  550. {
  551. return 0;
  552. }
  553. #ifdef BSP_DTU2 // 只有DTU2.0是分时通道切换采样的,所有有理论的角度偏差。
  554. //#if 1 // 目前先使用此值,以保证已校准设备的兼容性
  555. return (index/8)*FACTOR_P_BASE ;
  556. #else
  557. #ifdef BSP_DTU3
  558. // 保持旧版本的兼容性
  559. {
  560. u32 us;
  561. if(g_factor_version != ACFACTOR_FILE_VERSION)
  562. {
  563. return (index/8)*FACTOR_P_BASE ;
  564. }
  565. //1倍过采样延时1us
  566. us = (index%16)/2*CFG_ADC_OS_NUM;
  567. return -g_freq*us/1000000.0*360 ;
  568. }
  569. #else
  570. return 0;
  571. #endif
  572. #endif
  573. }
  574. int factor_temp_get(int slot,float *temp)
  575. {
  576. // 检查参数
  577. slot -= g_ac_slot_begin;
  578. if(slot >= EQU_SLOT_AC_NUM)
  579. {
  580. return -1;
  581. }
  582. *temp = g_ac_factor[slot].temp;
  583. return 0;
  584. }
  585. int factor_temp_set(int slot,float temp)
  586. {
  587. // 检查参数
  588. slot -= g_ac_slot_begin;
  589. if(slot >= EQU_SLOT_AC_NUM)
  590. {
  591. return -1;
  592. }
  593. g_ac_factor[slot].temp = temp;
  594. return 0;
  595. }
  596. /*------------------------------ 内部函数 -------------------------------------
  597. 内部函数以下划线‘_’开头,不需要检查参数的合法性.
  598. */
  599. /*------------------------------ 测试函数 -------------------------------------
  600. 一个实体文件必须带一个本模块的测试函数来进行单元测试,如果的确不方便在本模块中
  601. 进行单元测试,必须在此注明实际的测试位置(例如在哪个实体文件中使用哪个测试函数).
  602. */
  603. int factor_printf(void)
  604. {
  605. int slot,j;
  606. float f;
  607. rt_printf("校正系数:\r\n");
  608. rt_printf("版本:0x%08lx.\r\n",g_factor_version);
  609. rt_printf("最后校准基准值:电压=%d,电流=%d.\r\n",g_base_v,g_base_i);
  610. for(slot=0; slot<EQU_SLOT_AC_NUM; slot++)
  611. {
  612. rt_printf("序号:%02d(temp=%f).\r\n",slot,g_ac_factor[slot].temp);
  613. for(j=0;j<EQU_SLOT_AC_CHN;j++)
  614. {
  615. rt_printf("%02d:\tec=% 9f,\tpc=% 9f,\tpq1=% 9f,\tpq2=% 9f.\r\n",j,
  616. g_ac_factor[slot].factor_e_c[j],
  617. g_ac_factor[slot].factor_p_c[j],
  618. g_ac_factor[slot].pq_factor[j][0],
  619. g_ac_factor[slot].pq_factor[j][1]);
  620. }
  621. }
  622. for(j=0;j<(int)(sizeof(g_e_k)/sizeof(g_e_k[0])); j++)
  623. {
  624. rt_printf("g_e_k[%d]:%f.\r\n",j,g_e_k[j]);
  625. }
  626. for(j=0;j<16;j++)
  627. {
  628. f = factor_p_k(j);
  629. rt_printf("factor_p_k(%02d):%f.\r\n",j,f);
  630. }
  631. return 0;
  632. }
  633. //========================== 本文件结束 =============================