factor.c 16 KB

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