📄 caculate.cpp
字号:
#include "class.h"
#include "extern.h"
void CCaculate::init()
{
#ifdef CAL_GEAR
init_ma_to_b_gear();
#endif
}
void CCaculate::init_ma_to_b_gear()
{
FILE *fp;
char buf[MAXFILEBUF];
if ((fp = fopen("matogear.cfg", "rt")) == NULL) {
return;
}
for (int i = 0; i < MA_TO_B_NUM; i++) {
fgets(buf, MAXFILEBUF, fp);
sscanf(buf, "%*s%*s%u", &ma_yc_no[i]);
}
fclose(fp);
ma_timer = 0;
memset(¤t_gear[0], 0, sizeof(current_gear));
ma_to_gear_first = TRUE;
}
void CCaculate::ma_to_b_gear() // 4-20mA current to 17 trasform gear
{
INT16U range[18] = {358, 460, 562, 664, 766, 868, 970, 1072, 1174, 1276,
1378, 1480, 1582, 1684, 1786, 1888, 1990, 2092};
INT16U bvalue;
int gear;
int i, j, temp;
soe_record_t temp_soe;
yxbw_record_t temp_yx_bw;
sclock sclk;
if (ma_timer < 2) {
ma_timer++;
return;
}
else ma_timer = 0;
for (i = 0; i < MA_TO_B_NUM; i++) {
bvalue = dbdata.Yc[ma_yc_no[i]];
if ((bvalue < 0x800) || (bvalue > 0xf00)) continue;
bvalue = 0xfff - bvalue;
for (j = 0; j < 17; j++)
if (bvalue > range[j] && bvalue < range[j + 1]) {
gear = j + 1;
break;
}
if (ma_to_gear_first) {
for (j = 0; j < _TotalYx; j++) {
if (YxDefine[j].portno == 40 && YxDefine[j].type == i
&& YxDefine[j].info == gear) {
yx_update_db(j, 1);
current_gear[i] = gear;
}
}
ma_to_gear_first = FALSE;
return;
}
if (gear == current_gear[i]) continue;
for (j = 0; j < _TotalYx; j++) {
if (YxDefine[j].portno == 40 && YxDefine[j].type == i
&& YxDefine[j].info == current_gear[i]) {
yx_update_db(j, 0);
temp_soe.status_switch_no = j & 0xfff;
temp_soe.status_switch_no &= 0x7fff; // 0x80:0->1 0x00:1->0
GetClock(&sclk);
temp_soe.day = sclk.day;
temp_soe.hour = sclk.hour;
temp_soe.minute = sclk.minute;
temp_soe.second = sclk.second;
temp_soe.msecond = sclk.msecond;
insert_soe(&temp_soe); // add to soe buffer
temp = (temp_soe.status_switch_no & 0xfff) / 32;
temp_yx_bw.func_code = temp;
temp_yx_bw.yx_code[0] = dbdata.Yx[temp * 2];
temp_yx_bw.yx_code[1] = dbdata.Yx[temp * 2 + 1];
insert_yx_bw(&temp_yx_bw); // add to yx bw buffer
}
if (YxDefine[j].portno == 40 && YxDefine[j].type == i
&& YxDefine[j].info == gear) {
yx_update_db(j, 1);
temp_soe.status_switch_no = j & 0xfff;
temp_soe.status_switch_no |= 0x8000; // 0x80:0->1 0x00:1->0
GetClock(&sclk);
temp_soe.day = sclk.day;
temp_soe.hour = sclk.hour;
temp_soe.minute = sclk.minute;
temp_soe.second = sclk.second;
temp_soe.msecond = sclk.msecond;
insert_soe(&temp_soe); // add to soe buffer
temp = (temp_soe.status_switch_no & 0xfff) / 32;
temp_yx_bw.func_code = temp;
temp_yx_bw.yx_code[0] = dbdata.Yx[temp * 2];
temp_yx_bw.yx_code[1] = dbdata.Yx[temp * 2 + 1];
insert_yx_bw(&temp_yx_bw); // add to yx bw buffer
}
}
current_gear[i] = gear;
}
}
void CCaculate::reset_protect_yx()
{
int i, temp;
soe_record_t temp_soe;
yxbw_record_t temp_yx_bw;
sclock sclk;
for (i = 0; i < _TotalYx; i++) {
if (YxDefine[i].reset != 0) {
if (PR_start_flag[i]) { // wait reset
if (PR_timer[i] > PROTECT_RESET_GAP) { // reach the reset time
yx_update_db(i, 0);
PR_start_flag[i] = FALSE;
temp_soe.status_switch_no = i & 0xfff;
temp_soe.status_switch_no &= 0x7fff; // 0x80:0->1 0x00:1->0
GetClock(&sclk);
temp_soe.day = sclk.day;
temp_soe.hour = sclk.hour;
temp_soe.minute = sclk.minute;
temp_soe.second = sclk.second;
temp_soe.msecond = sclk.msecond;
insert_soe(&temp_soe); // add to soe buffer
temp = (temp_soe.status_switch_no & 0xfff) / 32;
temp_yx_bw.func_code = temp;
temp_yx_bw.yx_code[0] = dbdata.Yx[temp * 2];
temp_yx_bw.yx_code[1] = dbdata.Yx[temp * 2 + 1];
insert_yx_bw(&temp_yx_bw); // add to yx bw buffer
}
else PR_timer[i]++;
}
else { // detect reset
if (get_yx_dot(i)) { // act
PR_start_flag[i] = TRUE;
PR_timer[i] = 0;
}
}
}
}
}
void CCaculate::deal()
{
#ifdef CAL_GEAR
ma_to_b_gear();
#endif
reset_protect_yx();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -