style(libiec): 行宽压缩 — 一条语句一行, 仅多参逻辑分组分行
## 规则 - 函数声明/简单调用/打印: 一行写完 - 仅 task_event_recv 等逻辑分组保留多行 - 空括弧压缩: if(x) return; 不用再换行 ## 行数变化 iec104.cpp: 1402→1200 (-202) iec104_cfg.cpp: 157→135 (-22) iec104_point.cpp: 309→260 (-49)
This commit is contained in:
parent
62b5467c5a
commit
45e8697454
File diff suppressed because it is too large
Load Diff
|
|
@ -64,16 +64,10 @@ LOCAL int parse_signals(XMLElement *p_root)
|
||||||
|
|
||||||
for (rule_idx = 0; rule_idx < RULE_COUNT; rule_idx++)
|
for (rule_idx = 0; rule_idx < RULE_COUNT; rule_idx++)
|
||||||
{
|
{
|
||||||
XMLElement *p_parent = p_root->FirstChildElement(
|
XMLElement *p_parent = p_root->FirstChildElement(g_rules[rule_idx].xml_tag);
|
||||||
g_rules[rule_idx].xml_tag);
|
if (NULL == p_parent) continue;
|
||||||
|
|
||||||
if (NULL == p_parent)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
XMLElement *p_sig = p_parent->FirstChildElement(xml_el_signal);
|
XMLElement *p_sig = p_parent->FirstChildElement(xml_el_signal);
|
||||||
|
|
||||||
while (NULL != p_sig)
|
while (NULL != p_sig)
|
||||||
{
|
{
|
||||||
stru_iec_sig entry = {};
|
stru_iec_sig entry = {};
|
||||||
|
|
@ -87,22 +81,14 @@ LOCAL int parse_signals(XMLElement *p_root)
|
||||||
|
|
||||||
entry.desc = (NULL != p_attr_desc) ? p_attr_desc : "";
|
entry.desc = (NULL != p_attr_desc) ? p_attr_desc : "";
|
||||||
entry.link = (NULL != p_attr_link) ? p_attr_link : "";
|
entry.link = (NULL != p_attr_link) ? p_attr_link : "";
|
||||||
entry.inf = (NULL != p_attr_inf)
|
entry.inf = (NULL != p_attr_inf) ? (uint16_t)atoi(p_attr_inf) : 0;
|
||||||
? (uint16_t)atoi(p_attr_inf) : 0;
|
entry.type = (NULL != p_attr_type) ? dc_get_type_id_by_name(p_attr_type) : 0;
|
||||||
entry.type = (NULL != p_attr_type)
|
entry.invert = (NULL != p_attr_invert) ? (uint8_t)atoi(p_attr_invert) : 0;
|
||||||
? dc_get_type_id_by_name(p_attr_type) : 0;
|
entry.factor = (NULL != p_attr_factor) ? (float)atof(p_attr_factor) : 0.0f;
|
||||||
entry.invert = (NULL != p_attr_invert)
|
entry.offset = (NULL != p_attr_offset) ? (float)atof(p_attr_offset) : 0.0f;
|
||||||
? (uint8_t)atoi(p_attr_invert) : 0;
|
|
||||||
entry.factor = (NULL != p_attr_factor)
|
|
||||||
? (float)atof(p_attr_factor) : 0.0f;
|
|
||||||
entry.offset = (NULL != p_attr_offset)
|
|
||||||
? (float)atof(p_attr_offset) : 0.0f;
|
|
||||||
|
|
||||||
/* 如果 XML 未指定 type, 使用规则默认值 */
|
/* 如果 XML 未指定 type, 使用规则默认值 */
|
||||||
if (0 == entry.type)
|
if (0 == entry.type) entry.type = g_rules[rule_idx].default_type;
|
||||||
{
|
|
||||||
entry.type = g_rules[rule_idx].default_type;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_rules[rule_idx].p_vec->push_back(entry);
|
g_rules[rule_idx].p_vec->push_back(entry);
|
||||||
p_sig = p_sig->NextSiblingElement(xml_el_signal);
|
p_sig = p_sig->NextSiblingElement(xml_el_signal);
|
||||||
|
|
@ -124,11 +110,7 @@ int iec_cfg_parse(const char *xml_path)
|
||||||
XMLDocument doc;
|
XMLDocument doc;
|
||||||
XMLElement *p_root;
|
XMLElement *p_root;
|
||||||
|
|
||||||
if (NULL == xml_path)
|
if (NULL == xml_path) { LOG_E("iec_cfg_parse: NULL path"); return -1; }
|
||||||
{
|
|
||||||
LOG_E("iec_cfg_parse: NULL path");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (XML_SUCCESS != doc.LoadFile(xml_path))
|
if (XML_SUCCESS != doc.LoadFile(xml_path))
|
||||||
{
|
{
|
||||||
|
|
@ -137,20 +119,12 @@ int iec_cfg_parse(const char *xml_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
p_root = doc.RootElement();
|
p_root = doc.RootElement();
|
||||||
if (NULL == p_root)
|
if (NULL == p_root) { LOG_E("iec_cfg_parse: no root element"); return -1; }
|
||||||
{
|
|
||||||
LOG_E("iec_cfg_parse: no root element");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (0 != parse_signals(p_root))
|
if (0 != parse_signals(p_root)) return -1;
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG_I("iec_cfg_parse: %s loaded — ST=%d MX=%d CO=%d DD=%d AO=%d Param=%d",
|
LOG_I("iec_cfg_parse: %s loaded — ST=%d MX=%d CO=%d DD=%d AO=%d Param=%d",
|
||||||
xml_path,
|
xml_path, (int)g_cfg.vec_st.size(), (int)g_cfg.vec_mx.size(),
|
||||||
(int)g_cfg.vec_st.size(), (int)g_cfg.vec_mx.size(),
|
|
||||||
(int)g_cfg.vec_co.size(), (int)g_cfg.vec_dd.size(),
|
(int)g_cfg.vec_co.size(), (int)g_cfg.vec_dd.size(),
|
||||||
(int)g_cfg.vec_ao.size(), (int)g_cfg.vec_param.size());
|
(int)g_cfg.vec_ao.size(), (int)g_cfg.vec_param.size());
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -18,13 +18,11 @@
|
||||||
extern int cb_soe_write(uint16_t idx, uint8_t status, uint32_t sec, uint16_t ms);
|
extern int cb_soe_write(uint16_t idx, uint8_t status, uint32_t sec, uint16_t ms);
|
||||||
extern int cb_yc_disturb_write(uint16_t idx, float val);
|
extern int cb_yc_disturb_write(uint16_t idx, float val);
|
||||||
extern int cb_dd_disturb_write(uint16_t idx, float val, uint32_t sec, uint16_t ms);
|
extern int cb_dd_disturb_write(uint16_t idx, float val, uint32_t sec, uint16_t ms);
|
||||||
extern int cb_fault_write(iec_soe_info_t *p_soe, uint8_t yx_n,
|
extern int cb_fault_write(iec_soe_info_t *p_soe, uint8_t yx_n, iec_yc_info_t *p_yc, uint8_t yc_n);
|
||||||
iec_yc_info_t *p_yc, uint8_t yc_n);
|
|
||||||
|
|
||||||
/* =========================== 信号变更回调 =========================== */
|
/* =========================== 信号变更回调 =========================== */
|
||||||
|
|
||||||
LOCAL void on_st_change(const char *p_saddr, uint8_t data_type,
|
LOCAL void on_st_change(const char *p_saddr, uint8_t data_type, const void *p_val, const void *p_prev)
|
||||||
const void *p_val, const void *p_prev)
|
|
||||||
{
|
{
|
||||||
std::vector<stru_iec_sig> &vec = iec_cfg_ptr_get()->vec_st;
|
std::vector<stru_iec_sig> &vec = iec_cfg_ptr_get()->vec_st;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
@ -32,24 +30,15 @@ LOCAL void on_st_change(const char *p_saddr, uint8_t data_type,
|
||||||
uint8_t last;
|
uint8_t last;
|
||||||
|
|
||||||
(void)data_type;
|
(void)data_type;
|
||||||
|
if (NULL == p_saddr || NULL == p_val || NULL == p_prev) return;
|
||||||
if (NULL == p_saddr || NULL == p_val || NULL == p_prev)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string link(p_saddr);
|
std::string link(p_saddr);
|
||||||
|
|
||||||
for (i = 0; i < vec.size(); i++)
|
for (i = 0; i < vec.size(); i++)
|
||||||
{
|
{
|
||||||
if (vec[i].link != link)
|
if (vec[i].link != link) continue;
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
val = *(const uint8_t *)p_val;
|
val = *(const uint8_t *)p_val;
|
||||||
last = *(const uint8_t *)p_prev;
|
last = *(const uint8_t *)p_prev;
|
||||||
|
|
||||||
if (val != last)
|
if (val != last)
|
||||||
{
|
{
|
||||||
cb_soe_write(i, val, (uint32_t)time(NULL), 0);
|
cb_soe_write(i, val, (uint32_t)time(NULL), 0);
|
||||||
|
|
@ -58,8 +47,7 @@ LOCAL void on_st_change(const char *p_saddr, uint8_t data_type,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LOCAL void on_mx_change(const char *p_saddr, uint8_t data_type,
|
LOCAL void on_mx_change(const char *p_saddr, uint8_t data_type, const void *p_val, const void *p_prev)
|
||||||
const void *p_val, const void *p_prev)
|
|
||||||
{
|
{
|
||||||
std::vector<stru_iec_sig> &vec = iec_cfg_ptr_get()->vec_mx;
|
std::vector<stru_iec_sig> &vec = iec_cfg_ptr_get()->vec_mx;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
@ -67,33 +55,20 @@ LOCAL void on_mx_change(const char *p_saddr, uint8_t data_type,
|
||||||
float last;
|
float last;
|
||||||
|
|
||||||
(void)data_type;
|
(void)data_type;
|
||||||
|
if (NULL == p_saddr || NULL == p_val || NULL == p_prev) return;
|
||||||
if (NULL == p_saddr || NULL == p_val || NULL == p_prev)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string link(p_saddr);
|
std::string link(p_saddr);
|
||||||
|
|
||||||
for (i = 0; i < vec.size(); i++)
|
for (i = 0; i < vec.size(); i++)
|
||||||
{
|
{
|
||||||
if (vec[i].link != link)
|
if (vec[i].link != link) continue;
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
val = *(const float *)p_val;
|
val = *(const float *)p_val;
|
||||||
last = *(const float *)p_prev;
|
last = *(const float *)p_prev;
|
||||||
|
if (fabsf(val - last) > 0.1f) cb_yc_disturb_write(i, val);
|
||||||
if (fabsf(val - last) > 0.1f)
|
|
||||||
{
|
|
||||||
cb_yc_disturb_write(i, val);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LOCAL void on_dd_change(const char *p_saddr, uint8_t data_type,
|
LOCAL void on_dd_change(const char *p_saddr, uint8_t data_type, const void *p_val, const void *p_prev)
|
||||||
const void *p_val, const void *p_prev)
|
|
||||||
{
|
{
|
||||||
std::vector<stru_iec_sig> &vec = iec_cfg_ptr_get()->vec_dd;
|
std::vector<stru_iec_sig> &vec = iec_cfg_ptr_get()->vec_dd;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
@ -101,24 +76,15 @@ LOCAL void on_dd_change(const char *p_saddr, uint8_t data_type,
|
||||||
float last;
|
float last;
|
||||||
|
|
||||||
(void)data_type;
|
(void)data_type;
|
||||||
|
if (NULL == p_saddr || NULL == p_val || NULL == p_prev) return;
|
||||||
if (NULL == p_saddr || NULL == p_val || NULL == p_prev)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string link(p_saddr);
|
std::string link(p_saddr);
|
||||||
|
|
||||||
for (i = 0; i < vec.size(); i++)
|
for (i = 0; i < vec.size(); i++)
|
||||||
{
|
{
|
||||||
if (vec[i].link != link)
|
if (vec[i].link != link) continue;
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
val = *(const float *)p_val;
|
val = *(const float *)p_val;
|
||||||
last = *(const float *)p_prev;
|
last = *(const float *)p_prev;
|
||||||
|
|
||||||
if (fabsf(val - last) > 0.1f)
|
if (fabsf(val - last) > 0.1f)
|
||||||
{
|
{
|
||||||
cb_dd_disturb_write(i, val, (uint32_t)time(NULL), 0);
|
cb_dd_disturb_write(i, val, (uint32_t)time(NULL), 0);
|
||||||
|
|
@ -127,26 +93,16 @@ LOCAL void on_dd_change(const char *p_saddr, uint8_t data_type,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LOCAL void on_yk_change(const char *p_saddr, dc_ctrl_step_t step,
|
LOCAL void on_yk_change(const char *p_saddr, dc_ctrl_step_t step, uint8_t data_type, uint8_t zone, const void *p_val)
|
||||||
uint8_t data_type, uint8_t zone, const void *p_val)
|
|
||||||
{
|
{
|
||||||
/* YK 由 CS10x SetYkInfor 回调直接写入 datacenter, 此处预留 */
|
/* YK 由 CS10x SetYkInfor 回调直接写入 datacenter, 此处预留 */
|
||||||
(void)p_saddr;
|
(void)p_saddr; (void)step; (void)data_type; (void)zone; (void)p_val;
|
||||||
(void)step;
|
|
||||||
(void)data_type;
|
|
||||||
(void)zone;
|
|
||||||
(void)p_val;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LOCAL void on_ao_change(const char *p_saddr, dc_ctrl_step_t step,
|
LOCAL void on_ao_change(const char *p_saddr, dc_ctrl_step_t step, uint8_t data_type, uint8_t zone, const void *p_val)
|
||||||
uint8_t data_type, uint8_t zone, const void *p_val)
|
|
||||||
{
|
{
|
||||||
/* AO 由 CS10x 参数回调写入 datacenter, 此处预留 */
|
/* AO 由 CS10x 参数回调写入 datacenter, 此处预留 */
|
||||||
(void)p_saddr;
|
(void)p_saddr; (void)step; (void)data_type; (void)zone; (void)p_val;
|
||||||
(void)step;
|
|
||||||
(void)data_type;
|
|
||||||
(void)zone;
|
|
||||||
(void)p_val;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* =========================== 数据中心事件队列消费 =========================== */
|
/* =========================== 数据中心事件队列消费 =========================== */
|
||||||
|
|
@ -157,10 +113,7 @@ LOCAL void on_dc_soe(void *p_data)
|
||||||
std::vector<stru_iec_sig> &vec = iec_cfg_ptr_get()->vec_st;
|
std::vector<stru_iec_sig> &vec = iec_cfg_ptr_get()->vec_st;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
if (NULL == p_data)
|
if (NULL == p_data) return;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
p_event = (dc_soe_event_t *)p_data;
|
p_event = (dc_soe_event_t *)p_data;
|
||||||
std::string link(p_event->saddr);
|
std::string link(p_event->saddr);
|
||||||
|
|
@ -169,8 +122,7 @@ LOCAL void on_dc_soe(void *p_data)
|
||||||
{
|
{
|
||||||
if (vec[i].link == link)
|
if (vec[i].link == link)
|
||||||
{
|
{
|
||||||
cb_soe_write(i, p_event->status,
|
cb_soe_write(i, p_event->status, p_event->tm_sec, p_event->tm_ms);
|
||||||
p_event->tm_sec, p_event->tm_ms);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -183,10 +135,7 @@ LOCAL void on_dc_fault(void *p_data)
|
||||||
iec_soe_info_t soe;
|
iec_soe_info_t soe;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
if (NULL == p_data)
|
if (NULL == p_data) return;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
p_event = (dc_fault_event_t *)p_data;
|
p_event = (dc_fault_event_t *)p_data;
|
||||||
std::string link(p_event->saddr);
|
std::string link(p_event->saddr);
|
||||||
|
|
@ -195,11 +144,7 @@ LOCAL void on_dc_fault(void *p_data)
|
||||||
memset(&soe, 0, sizeof(soe));
|
memset(&soe, 0, sizeof(soe));
|
||||||
for (i = 0; i < vec_st.size(); i++)
|
for (i = 0; i < vec_st.size(); i++)
|
||||||
{
|
{
|
||||||
if (vec_st[i].link == link)
|
if (vec_st[i].link == link) { soe.info_addr = i; break; }
|
||||||
{
|
|
||||||
soe.info_addr = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
soe.status = 1;
|
soe.status = 1;
|
||||||
|
|
@ -215,10 +160,7 @@ LOCAL void on_dc_disturb_dd(void *p_data)
|
||||||
std::vector<stru_iec_sig> &vec = iec_cfg_ptr_get()->vec_dd;
|
std::vector<stru_iec_sig> &vec = iec_cfg_ptr_get()->vec_dd;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
if (NULL == p_data)
|
if (NULL == p_data) return;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
p_event = (dc_disturb_event_t *)p_data;
|
p_event = (dc_disturb_event_t *)p_data;
|
||||||
std::string link(p_event->saddr);
|
std::string link(p_event->saddr);
|
||||||
|
|
@ -227,8 +169,7 @@ LOCAL void on_dc_disturb_dd(void *p_data)
|
||||||
{
|
{
|
||||||
if (vec[i].link == link)
|
if (vec[i].link == link)
|
||||||
{
|
{
|
||||||
cb_dd_disturb_write(i, p_event->f_val,
|
cb_dd_disturb_write(i, p_event->f_val, p_event->tm_sec, p_event->tm_ms);
|
||||||
p_event->tm_sec, p_event->tm_ms);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -302,8 +243,7 @@ int iec104_point_init(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_I("iec104_point_init: ST=%d MX=%d CO=%d DD=%d AO=%d Param=%d",
|
LOG_I("iec104_point_init: ST=%d MX=%d CO=%d DD=%d AO=%d Param=%d",
|
||||||
(int)p_cfg->vec_st.size(), (int)p_cfg->vec_mx.size(),
|
(int)p_cfg->vec_st.size(), (int)p_cfg->vec_mx.size(), (int)p_cfg->vec_co.size(),
|
||||||
(int)p_cfg->vec_co.size(), (int)p_cfg->vec_dd.size(),
|
(int)p_cfg->vec_dd.size(), (int)p_cfg->vec_ao.size(), (int)p_cfg->vec_param.size());
|
||||||
(int)p_cfg->vec_ao.size(), (int)p_cfg->vec_param.size());
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue