parent
7fd80337dd
commit
d6dc13937e
|
|
@ -22,3 +22,7 @@ tmp/
|
||||||
|
|
||||||
# vscode 缓存
|
# vscode 缓存
|
||||||
.vscode/
|
.vscode/
|
||||||
|
release/x86/exe/FTU_cfg_parse
|
||||||
|
release/x86/exe/RTU
|
||||||
|
src/system/uart_trans/
|
||||||
|
src/system/FTU_cfg_parse/
|
||||||
|
|
|
||||||
|
|
@ -235,6 +235,59 @@ uint32_t com_channel_interface_get(uint32_t comm_id);
|
||||||
extern void com_recv_data(uint32_t itfs, const uint8_t *p_rx, uint16_t rx_len);
|
extern void com_recv_data(uint32_t itfs, const uint8_t *p_rx, uint16_t rx_len);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ftu配置解析相关结构体和函数声明
|
||||||
|
// 基础信息
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
std::string saddr;
|
||||||
|
std::string desc;
|
||||||
|
uint16_t inf;
|
||||||
|
}stru_self_ptl_cfg_base;
|
||||||
|
|
||||||
|
// 参数信息
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
stru_self_ptl_cfg_base base;
|
||||||
|
uint8_t type;
|
||||||
|
std::string default_value;
|
||||||
|
std::string unit;
|
||||||
|
std::string min;
|
||||||
|
std::string max;
|
||||||
|
std::string step;
|
||||||
|
}stru_self_ptl_cfg_param;
|
||||||
|
|
||||||
|
// 所有配置信息
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
bool init;
|
||||||
|
std::vector<stru_self_ptl_cfg_base> st_vec;
|
||||||
|
std::vector<stru_self_ptl_cfg_base> mx_vec;
|
||||||
|
std::vector<stru_self_ptl_cfg_base> co_vec;
|
||||||
|
std::vector<stru_self_ptl_cfg_base> dd_vec;
|
||||||
|
|
||||||
|
uint8_t param_md5[16];
|
||||||
|
std::vector<stru_self_ptl_cfg_param> param_vec;
|
||||||
|
}stru_self_ptl_cfg;
|
||||||
|
|
||||||
|
// 解析配置文件接口
|
||||||
|
int self_ptl_cfg_parse(const std::string &path);
|
||||||
|
|
||||||
|
// 获取配置结构体指针接口
|
||||||
|
stru_self_ptl_cfg* self_ptl_cfg_get();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 信号控制枚举
|
// 信号控制枚举
|
||||||
enum SIGNAL_CTRL_TYPE
|
enum SIGNAL_CTRL_TYPE
|
||||||
{
|
{
|
||||||
|
|
@ -264,9 +317,9 @@ typedef struct
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
double min; // 最小值
|
float min; // 最小值
|
||||||
double max; // 最大值
|
float max; // 最大值
|
||||||
double step; // 步长
|
float step; // 步长
|
||||||
std::string unit; // 单位
|
std::string unit; // 单位
|
||||||
void *p_default; // 默认值
|
void *p_default; // 默认值
|
||||||
}stru_signal_param;
|
}stru_signal_param;
|
||||||
|
|
@ -290,6 +343,8 @@ int dc_signal_param_link_with_callback(const std::string &saddr, uint8_t data_ty
|
||||||
// 数据中心参数设置接口
|
// 数据中心参数设置接口
|
||||||
int dc_signal_param_set_val(const std::string &saddr, SIGNAL_CTRL_STEP step, uint8_t data_type, void *p_data);
|
int dc_signal_param_set_val(const std::string &saddr, SIGNAL_CTRL_STEP step, uint8_t data_type, void *p_data);
|
||||||
|
|
||||||
|
int dc_signal_param_set_val_without_check(const std::string &saddr, uint8_t data_type, void *p_data);
|
||||||
|
|
||||||
// 数据中心遥控信号注册接口
|
// 数据中心遥控信号注册接口
|
||||||
int dc_signal_yk(const std::string &saddr, const std::string &desc, uint8_t data_type, uint8_t ctrl_type, void *p_data, signal_change_cb cb);
|
int dc_signal_yk(const std::string &saddr, const std::string &desc, uint8_t data_type, uint8_t ctrl_type, void *p_data, signal_change_cb cb);
|
||||||
|
|
||||||
|
|
@ -317,10 +372,14 @@ std::string dc_get_signal_val(void *p_data, uint8_t data_type);
|
||||||
// 数据中心设置信号值字符串接口
|
// 数据中心设置信号值字符串接口
|
||||||
int dc_set_out_signal_val(const std::string &saddr, void *set_data);
|
int dc_set_out_signal_val(const std::string &saddr, void *set_data);
|
||||||
|
|
||||||
|
// 数据中心根据数据类型创建数据指针接口
|
||||||
|
void *dc_create_data_ptr_by_type(uint8_t data_type);
|
||||||
|
|
||||||
// 数据中心根据数据类型ID获取数据类型字符串接口
|
// 数据中心根据数据类型ID获取数据类型字符串接口
|
||||||
std::string dc_get_data_type_str_by_id(uint8_t data_type);
|
std::string dc_get_data_type_str_by_id(uint8_t data_type);
|
||||||
|
|
||||||
// 数据中心根据数据类型字符串获取数据类型ID接口
|
// 数据中心根据数据类型字符串获取数据类型ID接口
|
||||||
uint8_t dc_get_data_type_id_by_str(const std::string &data_type_str);
|
uint8_t dc_get_data_type_id_by_str(const std::string &data_type_str);
|
||||||
|
|
||||||
|
uint8_t dc_get_data_type_len(uint8_t data_type);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "myBase.h"
|
|
||||||
#include "mySystem.h"
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
std::string saddr;
|
|
||||||
std::string desc;
|
|
||||||
uint16_t inf;
|
|
||||||
}stru_self_ptl_cfg_base;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
stru_self_ptl_cfg_base base;
|
|
||||||
uint8_t type;
|
|
||||||
std::string default_value;
|
|
||||||
std::string unit;
|
|
||||||
std::string min;
|
|
||||||
std::string max;
|
|
||||||
std::string step;
|
|
||||||
}stru_self_ptl_cfg_param;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
std::vector<stru_self_ptl_cfg_base> st_vec;
|
|
||||||
std::vector<stru_self_ptl_cfg_base> mx_vec;
|
|
||||||
std::vector<stru_self_ptl_cfg_base> co_vec;
|
|
||||||
std::vector<stru_self_ptl_cfg_base> dd_vec;
|
|
||||||
|
|
||||||
std::vector<stru_self_ptl_cfg_param> param_vec;
|
|
||||||
}stru_self_ptl_cfg;
|
|
||||||
|
|
||||||
|
|
||||||
int self_ptl_cfg_parse(const std::string &path);
|
|
||||||
stru_self_ptl_cfg* self_ptl_cfg_get();
|
|
||||||
|
|
||||||
|
|
@ -3,9 +3,22 @@
|
||||||
#include "myTask.h"
|
#include "myTask.h"
|
||||||
|
|
||||||
#include "app_sys.h"
|
#include "app_sys.h"
|
||||||
|
#include "mySystem.h"
|
||||||
|
|
||||||
|
|
||||||
|
LOCAL std::string path = "/mnt/RTU/test/file/SYSCONFIG/";
|
||||||
|
LOCAL std::string self_ptl_cfg = "self_ptl.xml";
|
||||||
|
|
||||||
|
int app_cfg_parse()
|
||||||
|
{
|
||||||
|
if(0 != self_ptl_cfg_parse(path + self_ptl_cfg))
|
||||||
|
{
|
||||||
|
MY_LOG_E("self_ptl_cfg_parse failed, path:%s", (path + self_ptl_cfg).c_str());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
|
@ -17,6 +30,12 @@ int main(void)
|
||||||
|
|
||||||
MY_LOG_I("main start !");
|
MY_LOG_I("main start !");
|
||||||
|
|
||||||
|
if(0 != app_cfg_parse())
|
||||||
|
{
|
||||||
|
MY_LOG_E("app_cfg_parse failed !");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if(0 != app_sys_init())
|
if(0 != app_sys_init())
|
||||||
{
|
{
|
||||||
MY_LOG_E("app_sys_init failed !");
|
MY_LOG_E("app_sys_init failed !");
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#include "self_ptl_cfg.h"
|
#include "myBase.h"
|
||||||
|
#include "mySystem.h"
|
||||||
#include "tinyxml2.h"
|
#include "tinyxml2.h"
|
||||||
|
|
||||||
LOCAL const char *ele_Root = "Root";
|
LOCAL const char *ele_Root = "Root";
|
||||||
|
|
@ -12,6 +13,8 @@ LOCAL const char *ele_Param = "Param";
|
||||||
LOCAL const char *ele_Item = "Item";
|
LOCAL const char *ele_Item = "Item";
|
||||||
|
|
||||||
LOCAL const char *attr_count = "count";
|
LOCAL const char *attr_count = "count";
|
||||||
|
LOCAL const char *attr_md5 = "md5";
|
||||||
|
|
||||||
LOCAL const char *attr_saddr = "saddr";
|
LOCAL const char *attr_saddr = "saddr";
|
||||||
LOCAL const char *attr_desc = "desc";
|
LOCAL const char *attr_desc = "desc";
|
||||||
LOCAL const char *attr_inf = "inf";
|
LOCAL const char *attr_inf = "inf";
|
||||||
|
|
@ -25,7 +28,7 @@ LOCAL const char *attr_step = "step";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LOCAL stru_self_ptl_cfg g_self_ptl_cfg;
|
LOCAL stru_self_ptl_cfg g_self_ptl_cfg = {.init = false};
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
|
@ -44,6 +47,11 @@ std::vector<stru_local_parse_base> g_local_parse_vec =
|
||||||
|
|
||||||
stru_self_ptl_cfg* self_ptl_cfg_get()
|
stru_self_ptl_cfg* self_ptl_cfg_get()
|
||||||
{
|
{
|
||||||
|
if(!g_self_ptl_cfg.init)
|
||||||
|
{
|
||||||
|
MY_LOG_E("self_ptl_cfg not parsed yet, returning pointer with uninit data");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
return &g_self_ptl_cfg;
|
return &g_self_ptl_cfg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -83,7 +91,11 @@ LOCAL int parse_base(tinyxml2::XMLElement *root)
|
||||||
const char *saddr = item_ele->Attribute(attr_saddr);
|
const char *saddr = item_ele->Attribute(attr_saddr);
|
||||||
const char *desc = item_ele->Attribute(attr_desc);
|
const char *desc = item_ele->Attribute(attr_desc);
|
||||||
int inf = 0;
|
int inf = 0;
|
||||||
item_ele->QueryIntAttribute(attr_inf, &inf);
|
if(tinyxml2::XMLError::XML_SUCCESS != item_ele->QueryIntAttribute(attr_inf, &inf))
|
||||||
|
{
|
||||||
|
MY_LOG_E("failed to parse attribute %s in element %s, inf get failed", attr_inf, local_parse.type.c_str());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (saddr != nullptr)
|
if (saddr != nullptr)
|
||||||
{
|
{
|
||||||
|
|
@ -111,10 +123,101 @@ LOCAL int parse_base(tinyxml2::XMLElement *root)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int parse_param(tinyxml2::XMLElement *root)
|
||||||
|
{
|
||||||
|
tinyxml2::XMLElement *parent_ele = root->FirstChildElement(ele_Param);
|
||||||
|
if (parent_ele == nullptr)
|
||||||
|
{
|
||||||
|
MY_LOG_E("not found element %s", ele_Param);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *count_str = parent_ele->Attribute(attr_count);
|
||||||
|
int count = 0;
|
||||||
|
if (count_str != nullptr)
|
||||||
|
{
|
||||||
|
count = atoi(count_str);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MY_LOG_E("not found attribute %s in element %s", attr_count, ele_Param);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *md5_str = parent_ele->Attribute(attr_md5);
|
||||||
|
if(nullptr == md5_str)
|
||||||
|
{
|
||||||
|
MY_LOG_E("not found attribute %s in element %s", attr_md5, ele_Param);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(strlen(md5_str) != 32)
|
||||||
|
{
|
||||||
|
MY_LOG_E("invalid md5 string %s in element %s", md5_str, ele_Param);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
for(int i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
std::string byte_str = md5_str + i*2;
|
||||||
|
byte_str[2] = '\0';
|
||||||
|
g_self_ptl_cfg.param_md5[i] = (uint8_t)strtoul(byte_str.c_str(), nullptr, 16);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tinyxml2::XMLElement *item_ele = parent_ele->FirstChildElement(ele_Item);
|
||||||
|
while (item_ele != nullptr)
|
||||||
|
{
|
||||||
|
stru_self_ptl_cfg_param cfg_param;
|
||||||
|
const char *saddr = item_ele->Attribute(attr_saddr);
|
||||||
|
const char *desc = item_ele->Attribute(attr_desc);
|
||||||
|
int inf = 0;
|
||||||
|
if(tinyxml2::XMLError::XML_SUCCESS != item_ele->QueryIntAttribute(attr_inf, &inf))
|
||||||
|
{
|
||||||
|
MY_LOG_E("failed to parse attribute %s in element %s, inf get failed", attr_inf, ele_Param);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const char *type = item_ele->Attribute(attr_type);
|
||||||
|
const char *default_value = item_ele->Attribute(attr_default);
|
||||||
|
const char *unit = item_ele->Attribute(attr_unit);
|
||||||
|
const char *min = item_ele->Attribute(attr_min);
|
||||||
|
const char *max = item_ele->Attribute(attr_max);
|
||||||
|
const char *step = item_ele->Attribute(attr_step);
|
||||||
|
|
||||||
|
cfg_param.base.saddr = saddr != nullptr ? saddr : "";
|
||||||
|
cfg_param.base.desc = desc != nullptr ? desc : "";
|
||||||
|
cfg_param.base.inf = inf;
|
||||||
|
cfg_param.type = dc_get_data_type_id_by_str(type != nullptr ? type : "");
|
||||||
|
cfg_param.default_value = default_value != nullptr ? default_value : "";
|
||||||
|
cfg_param.unit = unit != nullptr ? unit : "";
|
||||||
|
cfg_param.min = min != nullptr ? min : "";
|
||||||
|
cfg_param.max = max != nullptr ? max : "";
|
||||||
|
cfg_param.step = step != nullptr ? step : "";
|
||||||
|
|
||||||
|
g_self_ptl_cfg.param_vec.push_back(cfg_param);
|
||||||
|
|
||||||
|
item_ele = item_ele->NextSiblingElement(ele_Item);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(g_self_ptl_cfg.param_vec.size() != count)
|
||||||
|
{
|
||||||
|
MY_LOG_E("count mismatch for element %s, expected %d, actual %d",
|
||||||
|
ele_Param, count, (int)g_self_ptl_cfg.param_vec.size());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int self_ptl_cfg_parse(const std::string &path)
|
int self_ptl_cfg_parse(const std::string &path)
|
||||||
{
|
{
|
||||||
// 解析XML文件
|
if(g_self_ptl_cfg.init)
|
||||||
|
{
|
||||||
|
MY_LOG_I("self_ptl_cfg already parsed, skip");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解析XML文件
|
||||||
tinyxml2::XMLDocument doc;
|
tinyxml2::XMLDocument doc;
|
||||||
if (doc.LoadFile(path.c_str()) != tinyxml2::XML_SUCCESS)
|
if (doc.LoadFile(path.c_str()) != tinyxml2::XML_SUCCESS)
|
||||||
{
|
{
|
||||||
|
|
@ -129,12 +232,21 @@ int self_ptl_cfg_parse(const std::string &path)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 解析st、mx、co、dd
|
||||||
if(parse_base(root) != 0)
|
if(parse_base(root) != 0)
|
||||||
{
|
{
|
||||||
MY_LOG_E("Failed to parse base elements");
|
MY_LOG_E("Failed to parse base elements");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 解析param
|
||||||
|
if(parse_param(root) != 0)
|
||||||
|
{
|
||||||
|
MY_LOG_E("Failed to parse param elements");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_self_ptl_cfg.init = true;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -926,6 +926,26 @@ int dc_signal_param_set_val(const std::string &saddr, SIGNAL_CTRL_STEP step, uin
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int dc_signal_param_set_val_without_check(const std::string &saddr, uint8_t data_type, void *p_data)
|
||||||
|
{
|
||||||
|
XXH128_hash_t hash = XXH3_128bits(saddr.c_str(), saddr.length());
|
||||||
|
stru_signal *p_signal = dc_find_signal(hash, g_datacenter.siganl_param);
|
||||||
|
if(p_signal != nullptr)
|
||||||
|
{
|
||||||
|
if(p_signal->data_type != data_type)
|
||||||
|
{
|
||||||
|
LOG_E("saddr %s data type %s(%d) not match ctrl data type %s(%d)",
|
||||||
|
saddr.c_str(), dc_get_data_type_str_by_id(p_signal->data_type), p_signal->data_type, dc_get_data_type_str_by_id(data_type), data_type);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
dc_set_signal_val(p_signal->p_data, data_type, p_data);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_E("saddr %s not found in param table", saddr.c_str());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int dc_signal_yk(const std::string &saddr, const std::string &desc, uint8_t data_type, uint8_t ctrl_type, void *p_data, signal_change_cb cb)
|
int dc_signal_yk(const std::string &saddr, const std::string &desc, uint8_t data_type, uint8_t ctrl_type, void *p_data, signal_change_cb cb)
|
||||||
{
|
{
|
||||||
|
|
@ -1077,6 +1097,27 @@ LOCAL std::map<uint8_t, std::string> g_data_type_str = {
|
||||||
{DATA_TYPE_C1, "char1"}
|
{DATA_TYPE_C1, "char1"}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
LOCAL std::map<uint8_t, uint8_t> g_data_type_len = {
|
||||||
|
{DATA_TYPE_B, 1},
|
||||||
|
{DATA_TYPE_S8, 1},
|
||||||
|
{DATA_TYPE_U8, 1},
|
||||||
|
{DATA_TYPE_S16, 2},
|
||||||
|
{DATA_TYPE_U16, 2},
|
||||||
|
{DATA_TYPE_S32, 4},
|
||||||
|
{DATA_TYPE_U32, 4},
|
||||||
|
{DATA_TYPE_L64, 8},
|
||||||
|
{DATA_TYPE_UL64, 8},
|
||||||
|
{DATA_TYPE_F32, 4},
|
||||||
|
{DATA_TYPE_D64, 8},
|
||||||
|
{DATA_TYPE_IP, 4},
|
||||||
|
{DATA_TYPE_MAC, 8},
|
||||||
|
{DATA_TYPE_C8, 8},
|
||||||
|
{DATA_TYPE_C32, 32},
|
||||||
|
{DATA_TYPE_C64, 64},
|
||||||
|
{DATA_TYPE_C128, 128},
|
||||||
|
{DATA_TYPE_C1, 1}
|
||||||
|
};
|
||||||
|
|
||||||
std::string dc_get_data_type_str_by_id(uint8_t data_type)
|
std::string dc_get_data_type_str_by_id(uint8_t data_type)
|
||||||
{
|
{
|
||||||
auto it = g_data_type_str.find(data_type);
|
auto it = g_data_type_str.find(data_type);
|
||||||
|
|
@ -1102,6 +1143,19 @@ uint8_t dc_get_data_type_id_by_str(const std::string &data_type_str)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t dc_get_data_type_len(uint8_t data_type)
|
||||||
|
{
|
||||||
|
auto it = g_data_type_len.find(data_type);
|
||||||
|
if(it != g_data_type_len.end())
|
||||||
|
{
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::string dc_get_signal_val(void *p_data, uint8_t data_type)
|
std::string dc_get_signal_val(void *p_data, uint8_t data_type)
|
||||||
{
|
{
|
||||||
std::string str = "";
|
std::string str = "";
|
||||||
|
|
@ -1245,6 +1299,100 @@ int dc_set_out_signal_val(const std::string &saddr, void *set_data)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *dc_create_data_ptr_by_type(uint8_t data_type)
|
||||||
|
{
|
||||||
|
uint8_t *p_u8 = nullptr;
|
||||||
|
int8_t *p_s8 = nullptr;
|
||||||
|
int16_t *p_s16 = nullptr;
|
||||||
|
uint16_t *p_u16 = nullptr;
|
||||||
|
int32_t *p_s32 = nullptr;
|
||||||
|
uint32_t *p_u32 = nullptr;
|
||||||
|
int64_t *p_l64 = nullptr;
|
||||||
|
uint64_t *p_ul64 = nullptr;
|
||||||
|
float *p_f = nullptr;
|
||||||
|
double *p_d = nullptr;
|
||||||
|
char *p_char = nullptr;
|
||||||
|
|
||||||
|
switch(data_type)
|
||||||
|
{
|
||||||
|
case DATA_TYPE_B:
|
||||||
|
p_u8 = new uint8_t;
|
||||||
|
(*p_u8) = 0;
|
||||||
|
return p_u8;
|
||||||
|
case DATA_TYPE_S8:
|
||||||
|
p_s8 = new int8_t;
|
||||||
|
(*p_s8) = 0;
|
||||||
|
return p_s8;
|
||||||
|
case DATA_TYPE_U8:
|
||||||
|
p_u8 = new uint8_t;
|
||||||
|
(*p_u8) = 0;
|
||||||
|
return p_u8;
|
||||||
|
case DATA_TYPE_S16:
|
||||||
|
p_s16 = new int16_t;
|
||||||
|
(*p_s16) = 0;
|
||||||
|
return p_s16;
|
||||||
|
case DATA_TYPE_U16:
|
||||||
|
p_u16 = new uint16_t;
|
||||||
|
(*p_u16) = 0;
|
||||||
|
return p_u16;
|
||||||
|
case DATA_TYPE_S32:
|
||||||
|
p_s32 = new int32_t;
|
||||||
|
(*p_s32) = 0;
|
||||||
|
return p_s32;
|
||||||
|
case DATA_TYPE_U32:
|
||||||
|
p_u32 = new uint32_t;
|
||||||
|
(*p_u32) = 0;
|
||||||
|
return p_u32;
|
||||||
|
case DATA_TYPE_L64:
|
||||||
|
p_l64 = new int64_t;
|
||||||
|
(*p_l64) = 0;
|
||||||
|
return p_l64;
|
||||||
|
case DATA_TYPE_UL64:
|
||||||
|
p_ul64 = new uint64_t;
|
||||||
|
(*p_ul64) = 0;
|
||||||
|
return p_ul64;
|
||||||
|
case DATA_TYPE_F32:
|
||||||
|
p_f = new float;
|
||||||
|
(*p_f) = 0.0;
|
||||||
|
return p_f;
|
||||||
|
case DATA_TYPE_D64:
|
||||||
|
p_d = new double;
|
||||||
|
(*p_d) = 0.0;
|
||||||
|
return p_d;
|
||||||
|
case DATA_TYPE_IP:
|
||||||
|
p_char = new char[4];
|
||||||
|
memset(p_char, 0, 4);
|
||||||
|
return p_char;
|
||||||
|
case DATA_TYPE_MAC:
|
||||||
|
p_char = new char[8];
|
||||||
|
memset(p_char, 0, 8);
|
||||||
|
return p_char;
|
||||||
|
case DATA_TYPE_C8:
|
||||||
|
p_char = new char[8];
|
||||||
|
memset(p_char, 0, 8);
|
||||||
|
return p_char;
|
||||||
|
case DATA_TYPE_C32:
|
||||||
|
p_char = new char[32];
|
||||||
|
memset(p_char, 0, 32);
|
||||||
|
return p_char;
|
||||||
|
case DATA_TYPE_C64:
|
||||||
|
p_char = new char[64];
|
||||||
|
memset(p_char, 0, 64);
|
||||||
|
return p_char;
|
||||||
|
case DATA_TYPE_C128:
|
||||||
|
p_char = new char[128];
|
||||||
|
memset(p_char, 0, 128);
|
||||||
|
return p_char;
|
||||||
|
case DATA_TYPE_C1:
|
||||||
|
p_char = new char[1];
|
||||||
|
memset(p_char, 0, 1);
|
||||||
|
return p_char;
|
||||||
|
default:
|
||||||
|
LOG_E("unknown data_type: %d", data_type);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LOCAL void dc_show_signals(stru_signal_map &dc_signal_map)
|
LOCAL void dc_show_signals(stru_signal_map &dc_signal_map)
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,7 @@
|
||||||
|
|
||||||
#include "myBase.h"
|
#include "myBase.h"
|
||||||
#include "myIcp67.h"
|
#include "myIcp67.h"
|
||||||
|
#include "self_ptl.h"
|
||||||
uint8_t self_ptl_get_type_len(uint8_t type);
|
|
||||||
|
|
||||||
void param_pop_out(stru_icp67 *p_icp67, uint16_t addr, uint8_t type, uint8_t len, uint8_t *p_data);
|
void param_pop_out(stru_icp67 *p_icp67, uint16_t addr, uint8_t type, uint8_t len, uint8_t *p_data);
|
||||||
void iec_point_tbl_pop_out(stru_icp67 *p_icp67, uint16_t info_addr, uint16_t num, uint8_t *p_data);
|
void iec_point_tbl_pop_out(stru_icp67 *p_icp67, uint16_t info_addr, uint16_t num, uint8_t *p_data);
|
||||||
|
|
|
||||||
|
|
@ -1,122 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "myBase.h"
|
|
||||||
|
|
||||||
#include "mySystem.h"
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
std::string name;
|
|
||||||
std::string desc;
|
|
||||||
std::string type_str;
|
|
||||||
uint8_t type;
|
|
||||||
uint16_t inf;
|
|
||||||
void *p_data;
|
|
||||||
}stru_param_cfg_data;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
uint8_t md5[16];
|
|
||||||
std::map<uint8_t, std::vector<stru_param_cfg_data>> map_type_param;
|
|
||||||
std::vector<stru_param_cfg_data> vec_param;
|
|
||||||
}stru_param_cfg;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
std::vector<std::string> field_vec;
|
|
||||||
}stru_csv_row;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
std::vector<stru_csv_row> row_vec;
|
|
||||||
int capacity;
|
|
||||||
}stru_csv_data;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
std::string saddr;
|
|
||||||
std::string desc;
|
|
||||||
uint16_t inf;
|
|
||||||
bool invert;
|
|
||||||
uint16_t debounce_time;
|
|
||||||
uint8_t data;
|
|
||||||
}stru_iec_st_info;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
std::string saddr;
|
|
||||||
std::string desc;
|
|
||||||
uint16_t inf;
|
|
||||||
float factor;
|
|
||||||
uint8_t record_flag;
|
|
||||||
uint16_t dead_zone;
|
|
||||||
float max_limit;
|
|
||||||
float data;
|
|
||||||
float old_data;
|
|
||||||
}stru_iec_mx_info;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
std::string saddr;
|
|
||||||
std::string desc;
|
|
||||||
uint16_t inf;
|
|
||||||
uint16_t ctrl_attr;
|
|
||||||
uint8_t data;
|
|
||||||
}stru_iec_co_info;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
std::string saddr;
|
|
||||||
std::string desc;
|
|
||||||
uint16_t inf;
|
|
||||||
float factor;
|
|
||||||
float data;
|
|
||||||
}stru_iec_dd_info;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
std::string saddr;
|
|
||||||
std::string desc;
|
|
||||||
uint16_t inf;
|
|
||||||
uint8_t encoding;
|
|
||||||
uint8_t type;
|
|
||||||
uint16_t param_addr;
|
|
||||||
uint8_t up_dtype;
|
|
||||||
float factor;
|
|
||||||
void *p_data;
|
|
||||||
}stru_iec_param_info;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
stru_csv_data *p_fixed_param_cfg_csv;
|
|
||||||
stru_csv_data *p_param_csv;
|
|
||||||
stru_csv_data *p_iec_st_csv;
|
|
||||||
stru_csv_data *p_iec_mx_csv;
|
|
||||||
stru_csv_data *p_iec_co_csv;
|
|
||||||
stru_csv_data *p_iec_dd_csv;
|
|
||||||
stru_csv_data *p_iec_param_fixed_csv;
|
|
||||||
stru_csv_data *p_iec_param_run_csv;
|
|
||||||
stru_csv_data *p_iec_param_act_csv;
|
|
||||||
|
|
||||||
stru_param_cfg *p_param_cfg;
|
|
||||||
std::map<std::string, std::string> param_signal_name_map;
|
|
||||||
|
|
||||||
std::vector<stru_iec_st_info> st_info_vec;
|
|
||||||
std::vector<stru_iec_mx_info> mx_info_vec;
|
|
||||||
std::vector<stru_iec_co_info> co_info_vec;
|
|
||||||
std::vector<stru_iec_dd_info> dd_info_vec;
|
|
||||||
std::vector<stru_iec_param_info> param_info_vec;
|
|
||||||
}stru_app_cfg;
|
|
||||||
|
|
||||||
int parse_cfg_files();
|
|
||||||
stru_app_cfg *get_app_cfg_ptr(void);
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "myBase.h"
|
#include "myBase.h"
|
||||||
|
#include "mySystem.h"
|
||||||
|
|
||||||
#define IEC_START 0x68
|
#define IEC_START 0x68
|
||||||
#define IEC_TAIL 0x16
|
#define IEC_TAIL 0x16
|
||||||
|
|
@ -42,3 +42,31 @@ typedef struct
|
||||||
}stru_iec104_asdu;
|
}stru_iec104_asdu;
|
||||||
#pragma pack()
|
#pragma pack()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
stru_self_ptl_cfg_base *p_base;
|
||||||
|
void *p_data;
|
||||||
|
void *p_last_data;
|
||||||
|
}stru_self_ptl_cfg_base_data;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
stru_self_ptl_cfg_param *p_param;
|
||||||
|
void *p_data;
|
||||||
|
void *p_default_data;
|
||||||
|
}stru_self_ptl_cfg_param_data;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
std::vector<stru_self_ptl_cfg_base_data> st_vec;
|
||||||
|
std::vector<stru_self_ptl_cfg_base_data> mx_vec;
|
||||||
|
std::vector<stru_self_ptl_cfg_base_data> co_vec;
|
||||||
|
std::vector<stru_self_ptl_cfg_base_data> dd_vec;
|
||||||
|
|
||||||
|
std::vector<stru_self_ptl_cfg_param_data> param_vec;
|
||||||
|
}stru_self_ptl_cfg_data;
|
||||||
|
|
||||||
|
stru_self_ptl_cfg_data *self_ptl_cfg_data_ptr_get();
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#include "myMd5.h"
|
#include "myMd5.h"
|
||||||
#include "myCmd.h"
|
#include "myCmd.h"
|
||||||
#include "parse_cfg.h"
|
// #include "parse_cfg.h"
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
@ -138,185 +138,6 @@ std::map<uint8_t, local_test> g_map_local_test =
|
||||||
{11, test_file},
|
{11, test_file},
|
||||||
};
|
};
|
||||||
|
|
||||||
LOCAL std::map<uint8_t, uint8_t> g_type_len_map =
|
|
||||||
{
|
|
||||||
{1, 1},
|
|
||||||
{43, 1},
|
|
||||||
{32, 1},
|
|
||||||
{33, 2},
|
|
||||||
{45, 2},
|
|
||||||
{2, 4},
|
|
||||||
{35, 4},
|
|
||||||
{36, 8},
|
|
||||||
{37, 8},
|
|
||||||
{38, 4},
|
|
||||||
{39, 8},
|
|
||||||
{100, 16},
|
|
||||||
{101, 6},
|
|
||||||
{102, 8},
|
|
||||||
{103, 32},
|
|
||||||
{104, 64},
|
|
||||||
{105, 128},
|
|
||||||
{106, 1},
|
|
||||||
};
|
|
||||||
|
|
||||||
uint8_t self_ptl_get_type_len(uint8_t type)
|
|
||||||
{
|
|
||||||
if(g_type_len_map.find(type) == g_type_len_map.end())
|
|
||||||
{
|
|
||||||
LOG_E("self_ptl_get_type_len: invalid type:%d", type);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return g_type_len_map[type];
|
|
||||||
}
|
|
||||||
|
|
||||||
LOCAL void param_data_show(void *p_data, std::string &dst, uint8_t type)
|
|
||||||
{
|
|
||||||
if(NULL == p_data)
|
|
||||||
{
|
|
||||||
LOG_E("param_data_show: invalid parameter, p_data:%p", p_data);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
char temp[64] = {0};
|
|
||||||
char *src = NULL;
|
|
||||||
|
|
||||||
switch(type)
|
|
||||||
{
|
|
||||||
case DATA_TYPE_B:
|
|
||||||
dst = *(uint8_t *)p_data ? "true" : "false";
|
|
||||||
break;
|
|
||||||
case DATA_TYPE_S8:
|
|
||||||
dst = std::to_string(*(int8_t *)p_data);
|
|
||||||
break;
|
|
||||||
case DATA_TYPE_U8:
|
|
||||||
dst = std::to_string(*(uint8_t *)p_data);
|
|
||||||
break;
|
|
||||||
case DATA_TYPE_S16:
|
|
||||||
dst = std::to_string(*(int16_t *)p_data);
|
|
||||||
break;
|
|
||||||
case DATA_TYPE_U16:
|
|
||||||
dst = std::to_string(*(uint16_t *)p_data);
|
|
||||||
break;
|
|
||||||
case DATA_TYPE_S32:
|
|
||||||
dst = std::to_string(*(int32_t *)p_data);
|
|
||||||
break;
|
|
||||||
case DATA_TYPE_U32:
|
|
||||||
dst = std::to_string(*(uint32_t *)p_data);
|
|
||||||
break;
|
|
||||||
case DATA_TYPE_L64:
|
|
||||||
dst = std::to_string(*(int64_t *)p_data);
|
|
||||||
break;
|
|
||||||
case DATA_TYPE_UL64:
|
|
||||||
dst = std::to_string(*(uint64_t *)p_data);
|
|
||||||
break;
|
|
||||||
case DATA_TYPE_F32:
|
|
||||||
dst = std::to_string(*(float *)p_data);
|
|
||||||
break;
|
|
||||||
case DATA_TYPE_D64:
|
|
||||||
dst = std::to_string(*(double *)p_data);
|
|
||||||
break;
|
|
||||||
case DATA_TYPE_IP:
|
|
||||||
src = (char *)p_data;
|
|
||||||
sprintf(temp, "%d.%d.%d.%d", (uint8_t)src[0], (uint8_t)src[1], (uint8_t)src[2], (uint8_t)src[3]);
|
|
||||||
dst = std::string(temp);
|
|
||||||
break;
|
|
||||||
case DATA_TYPE_MAC:
|
|
||||||
src = (char *)p_data;
|
|
||||||
sprintf(temp, "%02x:%02x:%02x:%02x:%02x:%02x", (uint8_t)src[0], (uint8_t)src[1], (uint8_t)src[2], (uint8_t)src[3], (uint8_t)src[4], (uint8_t)src[5]);
|
|
||||||
dst = std::string(temp);
|
|
||||||
break;
|
|
||||||
case DATA_TYPE_C1:
|
|
||||||
src = (char *)p_data;
|
|
||||||
sprintf(temp, "%c", src[0]);
|
|
||||||
dst = std::string(temp);
|
|
||||||
break;
|
|
||||||
case DATA_TYPE_C8:
|
|
||||||
case DATA_TYPE_C32:
|
|
||||||
case DATA_TYPE_C64:
|
|
||||||
// case DATA_TYPE_C128:
|
|
||||||
dst = std::string((char *)p_data);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
dst = "unknow type";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LOCAL void param_data_set(stru_param_cfg_data ¶m_data, uint16_t inf,uint8_t type, uint8_t *data)
|
|
||||||
{
|
|
||||||
if(inf != param_data.inf || type != param_data.type)
|
|
||||||
{
|
|
||||||
LOG_E("data addr or type not match, data_addr:%x, data_type:%d, param_data.inf:%x, param_data.type:%d");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
char temp[64] = {0};
|
|
||||||
|
|
||||||
switch(param_data.type)
|
|
||||||
{
|
|
||||||
case DATA_TYPE_B:
|
|
||||||
*(uint8_t *)param_data.p_data = data[0] & 0x01;
|
|
||||||
break;
|
|
||||||
case DATA_TYPE_S8:
|
|
||||||
*(int8_t *)param_data.p_data = *(int8_t *)data;
|
|
||||||
break;
|
|
||||||
case DATA_TYPE_U8:
|
|
||||||
*(uint8_t *)param_data.p_data = *(uint8_t *)data;
|
|
||||||
break;
|
|
||||||
case DATA_TYPE_S16:
|
|
||||||
*(int16_t *)param_data.p_data = *(int16_t *)data;
|
|
||||||
break;
|
|
||||||
case DATA_TYPE_U16:
|
|
||||||
*(uint16_t *)param_data.p_data = *(uint16_t *)data;
|
|
||||||
break;
|
|
||||||
case DATA_TYPE_S32:
|
|
||||||
*(int32_t *)param_data.p_data = *(int32_t *)data;
|
|
||||||
break;
|
|
||||||
case DATA_TYPE_U32:
|
|
||||||
*(uint32_t *)param_data.p_data = *(uint32_t *)data;
|
|
||||||
break;
|
|
||||||
case DATA_TYPE_L64:
|
|
||||||
*(int64_t *)param_data.p_data = *(int64_t *)data;
|
|
||||||
break;
|
|
||||||
case DATA_TYPE_UL64:
|
|
||||||
*(uint64_t *)param_data.p_data = *(uint64_t *)data;
|
|
||||||
break;
|
|
||||||
case DATA_TYPE_F32:
|
|
||||||
*(float *)param_data.p_data = *(float *)data;
|
|
||||||
break;
|
|
||||||
case DATA_TYPE_D64:
|
|
||||||
*(double *)param_data.p_data = *(double *)data;
|
|
||||||
break;
|
|
||||||
case DATA_TYPE_IP:
|
|
||||||
// sprintf((char *)param_data.p_data, "%d.%d.%d.%d", data[0], data[1], data[2], data[3]);
|
|
||||||
strncpy((char *)param_data.p_data, (char *)data, 4);
|
|
||||||
break;
|
|
||||||
case DATA_TYPE_MAC:
|
|
||||||
// sprintf((char *)param_data.p_data, "%02x:%02x:%02x:%02x:%02x:%02x", data[0], data[1], data[2], data[3], data[4], data[5]);
|
|
||||||
strncpy((char *)param_data.p_data, (char *)data, 8);
|
|
||||||
break;
|
|
||||||
case DATA_TYPE_C1:
|
|
||||||
*(char *)param_data.p_data = (char)data[0];
|
|
||||||
break;
|
|
||||||
case DATA_TYPE_C8:
|
|
||||||
strncpy((char *)param_data.p_data, (char *)data, 8);
|
|
||||||
break;
|
|
||||||
case DATA_TYPE_C32:
|
|
||||||
strncpy((char *)param_data.p_data, (char *)data, 32);
|
|
||||||
break;
|
|
||||||
case DATA_TYPE_C64:
|
|
||||||
strncpy((char *)param_data.p_data, (char *)data, 64);
|
|
||||||
break;
|
|
||||||
// case DATA_TYPE_C128:
|
|
||||||
// strncpy((char *)param_data.val.c128, (char *)data, 128);
|
|
||||||
// break;
|
|
||||||
default:
|
|
||||||
LOG_E("unknow type:%d", param_data.type);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void param_pop_out(stru_icp67 *p_icp67, uint16_t addr, uint8_t type, uint8_t len, uint8_t *p_data)
|
void param_pop_out(stru_icp67 *p_icp67, uint16_t addr, uint8_t type, uint8_t len, uint8_t *p_data)
|
||||||
{
|
{
|
||||||
|
|
@ -326,12 +147,18 @@ void param_pop_out(stru_icp67 *p_icp67, uint16_t addr, uint8_t type, uint8_t len
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
stru_app_cfg *p_cfg = get_app_cfg_ptr();
|
stru_self_ptl_cfg_data *p_app_cfg_data = self_ptl_cfg_data_ptr_get();
|
||||||
|
|
||||||
uint16_t pos = g_local_param_get.offset + g_local_param_get.rx_cnt;
|
uint16_t pos = g_local_param_get.offset + g_local_param_get.rx_cnt;
|
||||||
stru_param_cfg_data *p_param_data = &p_cfg->p_param_cfg->vec_param[pos];
|
stru_self_ptl_cfg_param_data *p_param_data = &p_app_cfg_data->param_vec[pos];
|
||||||
|
|
||||||
param_data_set(*p_param_data, addr, type, p_data);
|
if(p_param_data->p_param->base.inf == addr && p_param_data->p_param->type == type)
|
||||||
|
{
|
||||||
|
// dc_signal_param_set_val(p_param_data->p_param->base.saddr, SIGNAL_CTRL_STEP::SELECT, type, p_data);
|
||||||
|
// dc_signal_param_set_val(p_param_data->p_param->base.saddr, SIGNAL_CTRL_STEP::DIRECT, type, p_data);
|
||||||
|
|
||||||
|
dc_signal_param_set_val_without_check(p_param_data->p_param->base.saddr, type, p_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
g_local_param_get.rx_cnt++;
|
g_local_param_get.rx_cnt++;
|
||||||
|
|
@ -394,8 +221,7 @@ void self_check_pop_out(stru_icp67 *p_icp67, stru_data_info *p_data, uint16_t ad
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string data;
|
std::string data = dc_get_signal_val(p_data->data, p_data->data_type);
|
||||||
param_data_show(p_data->data, data, p_data->data_type);
|
|
||||||
|
|
||||||
LOG_I("self_check_pop_out: addr %d, type %d, len %d, data %s", addr, p_data->data_type, p_data->data_len, data.c_str());
|
LOG_I("self_check_pop_out: addr %d, type %d, len %d, data %s", addr, p_data->data_type, p_data->data_len, data.c_str());
|
||||||
}
|
}
|
||||||
|
|
@ -659,18 +485,19 @@ void mx_trans(stru_icp67 *p_icp67, uint16_t info_addr, float p_data)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
stru_app_cfg *p_cfg = get_app_cfg_ptr();
|
stru_self_ptl_cfg_data *p_app_cfg_data = self_ptl_cfg_data_ptr_get();
|
||||||
|
|
||||||
if(info_addr < p_cfg->mx_info_vec.size())
|
if(info_addr < p_app_cfg_data->mx_vec.size())
|
||||||
{
|
{
|
||||||
p_cfg->mx_info_vec[info_addr].data = p_data;
|
*(float *)(p_app_cfg_data->mx_vec[info_addr].p_data) = p_data;
|
||||||
|
|
||||||
if(fabs(p_cfg->mx_info_vec[info_addr].old_data - p_data) > 0.1)
|
float last = *(float *)(p_app_cfg_data->mx_vec[info_addr].p_last_data);
|
||||||
|
if(fabs(last - p_data) > 0.1)
|
||||||
{
|
{
|
||||||
// UserWriteDisturbYc(info_addr, p_data);
|
// UserWriteDisturbYc(info_addr, p_data);
|
||||||
// LOG_I("mx_trans: addr %d, data %f, old_data %f", info_addr, p_data, p_cfg->mx_info_vec[info_addr].old_data);
|
// LOG_I("mx_trans: addr %d, data %f, old_data %f", info_addr, p_data, p_cfg->mx_info_vec[info_addr].old_data);
|
||||||
}
|
}
|
||||||
p_cfg->mx_info_vec[info_addr].old_data = p_data;
|
*(float *)(p_app_cfg_data->mx_vec[info_addr].p_last_data) = p_data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -682,21 +509,19 @@ void st_trans(stru_icp67 *p_icp67, uint16_t info_addr, uint8_t p_data)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
stru_app_cfg *p_cfg = get_app_cfg_ptr();
|
stru_self_ptl_cfg_data *p_app_cfg_data = self_ptl_cfg_data_ptr_get();
|
||||||
|
|
||||||
|
if(info_addr < p_app_cfg_data->st_vec.size())
|
||||||
if(info_addr < p_cfg->st_info_vec.size())
|
|
||||||
{
|
{
|
||||||
// if(p_data == 1 || p_data == 2)
|
|
||||||
// {
|
|
||||||
// p_data -= 1;
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// p_data = 0;
|
|
||||||
// }
|
|
||||||
|
|
||||||
p_cfg->st_info_vec[info_addr].data = p_data;
|
|
||||||
|
*(uint8_t *)(p_app_cfg_data->st_vec[info_addr].p_data) = p_data;
|
||||||
|
|
||||||
|
if(*(uint8_t *)(p_app_cfg_data->st_vec[info_addr].p_last_data) != p_data)
|
||||||
|
{
|
||||||
|
// UserWriteDisturbYx(info_addr, p_data);
|
||||||
|
*(uint8_t *)(p_app_cfg_data->st_vec[info_addr].p_last_data) = p_data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -810,18 +635,18 @@ LOCAL void iec_point_tbl_decode_mx(std::vector<stru_tlv> &tlv_vec)
|
||||||
|
|
||||||
LOG_I("iec_point_tbl_decode_mx: inf %d, factor %f, record_flag %d, dead_zone %d, max_value %d", inf, factor, record_flag, dead_zone, max_value);
|
LOG_I("iec_point_tbl_decode_mx: inf %d, factor %f, record_flag %d, dead_zone %d, max_value %d", inf, factor, record_flag, dead_zone, max_value);
|
||||||
|
|
||||||
stru_app_cfg *p_cfg = get_app_cfg_ptr();
|
stru_self_ptl_cfg_data *p_app_cfg_data = self_ptl_cfg_data_ptr_get();
|
||||||
|
|
||||||
for(uint16_t i = 0; i < p_cfg->mx_info_vec.size(); i++)
|
// for(uint16_t i = 0; i < p_app_cfg_data->mx_vec.size(); i++)
|
||||||
{
|
// {
|
||||||
if(inf == p_cfg->mx_info_vec[i].inf)
|
// if(inf == p_app_cfg_data->mx_vec[i].p_base->inf)
|
||||||
{
|
// {
|
||||||
p_cfg->mx_info_vec[i].factor = factor;
|
// p_app_cfg_data->mx_vec[i].factor = factor;
|
||||||
p_cfg->mx_info_vec[i].record_flag = record_flag;
|
// p_app_cfg_data->mx_vec[i].record_flag = record_flag;
|
||||||
p_cfg->mx_info_vec[i].dead_zone = dead_zone;
|
// p_app_cfg_data->mx_vec[i].dead_zone = dead_zone;
|
||||||
p_cfg->mx_info_vec[i].max_limit = max_value;
|
// p_app_cfg_data->mx_vec[i].max_limit = max_value;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
LOCAL void iec_point_tbl_decode_st(std::vector<stru_tlv> &tlv_vec)
|
LOCAL void iec_point_tbl_decode_st(std::vector<stru_tlv> &tlv_vec)
|
||||||
|
|
@ -838,16 +663,16 @@ LOCAL void iec_point_tbl_decode_st(std::vector<stru_tlv> &tlv_vec)
|
||||||
|
|
||||||
LOG_I("iec_point_tbl_decode_st: inf %d, invert %d, debounce_time %d", inf, invert, debounce_time);
|
LOG_I("iec_point_tbl_decode_st: inf %d, invert %d, debounce_time %d", inf, invert, debounce_time);
|
||||||
|
|
||||||
stru_app_cfg *p_cfg = get_app_cfg_ptr();
|
stru_self_ptl_cfg_data *p_app_cfg_data = self_ptl_cfg_data_ptr_get();
|
||||||
|
|
||||||
for(uint16_t i = 0; i < p_cfg->st_info_vec.size(); i++)
|
// for(uint16_t i = 0; i < p_app_cfg_data->st_vec.size(); i++)
|
||||||
{
|
// {
|
||||||
if(inf == p_cfg->st_info_vec[i].inf)
|
// if(inf == p_app_cfg_data->st_vec[i].p_base->inf)
|
||||||
{
|
// {
|
||||||
p_cfg->st_info_vec[i].invert = invert;
|
// p_app_cfg_data->st_vec[i].invert = invert;
|
||||||
p_cfg->st_info_vec[i].debounce_time = debounce_time;
|
// p_app_cfg_data->st_vec[i].debounce_time = debounce_time;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -864,15 +689,15 @@ LOCAL void iec_point_tbl_decode_co(std::vector<stru_tlv> &tlv_vec)
|
||||||
|
|
||||||
LOG_I("iec_point_tbl_decode_co: inf %d, attr %d", inf, attr);
|
LOG_I("iec_point_tbl_decode_co: inf %d, attr %d", inf, attr);
|
||||||
|
|
||||||
stru_app_cfg *p_cfg = get_app_cfg_ptr();
|
stru_self_ptl_cfg_data *p_app_cfg_data = self_ptl_cfg_data_ptr_get();
|
||||||
|
|
||||||
for(uint16_t i = 0; i < p_cfg->co_info_vec.size(); i++)
|
// for(uint16_t i = 0; i < p_app_cfg_data->co_vec.size(); i++)
|
||||||
{
|
// {
|
||||||
if(inf == p_cfg->co_info_vec[i].inf)
|
// if(inf == p_app_cfg_data->co_vec[i].p_base->inf)
|
||||||
{
|
// {
|
||||||
p_cfg->co_info_vec[i].ctrl_attr = attr;
|
// p_app_cfg_data->co_vec[i].ctrl_attr = attr;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
LOCAL void iec_point_tbl_decode_ao(std::vector<stru_tlv> &tlv_vec)
|
LOCAL void iec_point_tbl_decode_ao(std::vector<stru_tlv> &tlv_vec)
|
||||||
|
|
@ -892,19 +717,19 @@ LOCAL void iec_point_tbl_decode_ao(std::vector<stru_tlv> &tlv_vec)
|
||||||
|
|
||||||
LOG_I("iec_point_tbl_decode_ao: inf %d, encoding %d, type %d, param_addr %d, up_dtype %d, factor %f", inf, encoding, type, param_addr, up_dtype, factor);
|
LOG_I("iec_point_tbl_decode_ao: inf %d, encoding %d, type %d, param_addr %d, up_dtype %d, factor %f", inf, encoding, type, param_addr, up_dtype, factor);
|
||||||
|
|
||||||
stru_app_cfg *p_cfg = get_app_cfg_ptr();
|
stru_self_ptl_cfg_data *p_app_cfg_data = self_ptl_cfg_data_ptr_get();
|
||||||
|
|
||||||
for(uint16_t i = 0; i < p_cfg->param_info_vec.size(); i++)
|
// for(uint16_t i = 0; i < p_app_cfg_data->param_vec.size(); i++)
|
||||||
{
|
// {
|
||||||
if(inf == p_cfg->param_info_vec[i].inf)
|
// if(inf == p_app_cfg_data->param_vec[i].p_param->base.inf)
|
||||||
{
|
// {
|
||||||
p_cfg->param_info_vec[i].encoding = encoding;
|
// p_app_cfg_data->param_vec[i].encoding = encoding;
|
||||||
p_cfg->param_info_vec[i].type = type;
|
// p_app_cfg_data->param_vec[i].type = type;
|
||||||
p_cfg->param_info_vec[i].param_addr = param_addr;
|
// p_app_cfg_data->param_vec[i].param_addr = param_addr;
|
||||||
p_cfg->param_info_vec[i].up_dtype = up_dtype;
|
// p_app_cfg_data->param_vec[i].up_dtype = up_dtype;
|
||||||
p_cfg->param_info_vec[i].factor = factor;
|
// p_app_cfg_data->param_vec[i].factor = factor;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
LOCAL void iec_point_tbl_decode_dd(std::vector<stru_tlv> &tlv_vec)
|
LOCAL void iec_point_tbl_decode_dd(std::vector<stru_tlv> &tlv_vec)
|
||||||
|
|
@ -920,15 +745,15 @@ LOCAL void iec_point_tbl_decode_dd(std::vector<stru_tlv> &tlv_vec)
|
||||||
|
|
||||||
LOG_I("iec_point_tbl_decode_dd: inf %d, factor %f", inf, factor);
|
LOG_I("iec_point_tbl_decode_dd: inf %d, factor %f", inf, factor);
|
||||||
|
|
||||||
stru_app_cfg *p_cfg = get_app_cfg_ptr();
|
stru_self_ptl_cfg_data *p_app_cfg_data = self_ptl_cfg_data_ptr_get();
|
||||||
|
|
||||||
for(uint16_t i = 0; i < p_cfg->dd_info_vec.size(); i++)
|
// for(uint16_t i = 0; i < p_app_cfg_data->dd_vec.size(); i++)
|
||||||
{
|
// {
|
||||||
if(inf == p_cfg->dd_info_vec[i].inf)
|
// if(inf == p_app_cfg_data->dd_vec[i].p_base->inf)
|
||||||
{
|
// {
|
||||||
p_cfg->dd_info_vec[i].factor = factor;
|
// p_app_cfg_data->dd_vec[i].factor = factor;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
LOCAL void iec_point_tbl_decode_mx_oper(std::vector<stru_tlv> &tlv_vec)
|
LOCAL void iec_point_tbl_decode_mx_oper(std::vector<stru_tlv> &tlv_vec)
|
||||||
|
|
@ -1069,18 +894,21 @@ LOCAL int file_size_get(const char *file_name, uint32_t *p_size)
|
||||||
|
|
||||||
LOCAL void test_param_get(stru_icp67 *p_icp67, stru_genneral_method *p_method)
|
LOCAL void test_param_get(stru_icp67 *p_icp67, stru_genneral_method *p_method)
|
||||||
{
|
{
|
||||||
stru_app_cfg *p_cfg = get_app_cfg_ptr();
|
stru_self_ptl_cfg_data *p_app_cfg_data = self_ptl_cfg_data_ptr_get();
|
||||||
|
|
||||||
uint16_t cnt = 0;
|
uint16_t cnt = 0;
|
||||||
|
|
||||||
if(g_local_param_get.offset >= p_cfg->p_param_cfg->vec_param.size())
|
if(g_local_param_get.offset >= p_app_cfg_data->param_vec.size())
|
||||||
{
|
{
|
||||||
for(uint16_t i = 0; i < p_cfg->p_param_cfg->vec_param.size(); i++)
|
for(uint16_t i = 0; i < p_app_cfg_data->param_vec.size(); i++)
|
||||||
{
|
{
|
||||||
stru_param_cfg_data *p_data = &p_cfg->p_param_cfg->vec_param[i];
|
stru_self_ptl_cfg_param_data *p_data = &p_app_cfg_data->param_vec[i];
|
||||||
|
|
||||||
std::string val = "";
|
std::string val = dc_get_signal_val(p_data->p_data, p_data->p_param->type);
|
||||||
param_data_show(p_data->p_data, val, p_data->type);
|
|
||||||
printf("inf %04x, type %04d, len %04d, val %s\n", p_data->inf, p_data->type, g_type_len_map[p_data->type], val.c_str());
|
stru_self_ptl_cfg_base *p_base = &p_data->p_param->base;
|
||||||
|
|
||||||
|
printf("saddr %s, desc %s, inf %04x, type %04d, len %04d, val %s\n", p_base->saddr.c_str(), p_base->desc.c_str(), p_base->inf, p_data->p_param->type, dc_get_data_type_len(p_data->p_param->type), val.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
g_flag[1] = 0;
|
g_flag[1] = 0;
|
||||||
|
|
@ -1088,18 +916,18 @@ LOCAL void test_param_get(stru_icp67 *p_icp67, stru_genneral_method *p_method)
|
||||||
}
|
}
|
||||||
uint16_t i = 0;
|
uint16_t i = 0;
|
||||||
|
|
||||||
if(p_cfg->p_param_cfg->vec_param[g_local_param_get.offset].type == DATA_TYPE_C32)
|
if(p_app_cfg_data->param_vec[g_local_param_get.offset].p_param->type == DATA_TYPE_C32)
|
||||||
{
|
{
|
||||||
g_local_param_get.per_cnt = 10;
|
g_local_param_get.per_cnt = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
stru_ti_1_2_data data[g_local_param_get.per_cnt] = {0};
|
stru_ti_1_2_data data[g_local_param_get.per_cnt] = {0};
|
||||||
for(i = g_local_param_get.offset; cnt < g_local_param_get.per_cnt && i < p_cfg->p_param_cfg->vec_param.size(); i++,cnt++)
|
for(i = g_local_param_get.offset; cnt < g_local_param_get.per_cnt && i < p_app_cfg_data->param_vec.size(); i++,cnt++)
|
||||||
{
|
{
|
||||||
|
|
||||||
data[cnt].data_addr = p_cfg->p_param_cfg->vec_param[i].inf;
|
data[cnt].data_addr = p_app_cfg_data->param_vec[i].p_param->base.inf;
|
||||||
data[cnt].data_type = p_cfg->p_param_cfg->vec_param[i].type;
|
data[cnt].data_type = p_app_cfg_data->param_vec[i].p_param->type;
|
||||||
data[cnt].data_len = g_type_len_map[data[cnt].data_type];
|
data[cnt].data_len = dc_get_data_type_len(p_app_cfg_data->param_vec[i].p_param->type);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_flag[1] = 0;
|
g_flag[1] = 0;
|
||||||
|
|
@ -1107,7 +935,7 @@ LOCAL void test_param_get(stru_icp67 *p_icp67, stru_genneral_method *p_method)
|
||||||
g_local_param_get.rx_cnt = 0;
|
g_local_param_get.rx_cnt = 0;
|
||||||
g_local_param_get.tx_cnt = cnt;
|
g_local_param_get.tx_cnt = cnt;
|
||||||
|
|
||||||
LOG_I("param_get: i %d, cnt %d, tx_cnt %d, offset %d, size %d", i, cnt, g_local_param_get.tx_cnt, g_local_param_get.offset, p_cfg->p_param_cfg->vec_param.size());
|
LOG_I("param_get: i %d, cnt %d, tx_cnt %d, offset %d, size %d", i, cnt, g_local_param_get.tx_cnt, g_local_param_get.offset, p_app_cfg_data->param_vec.size());
|
||||||
p_method->param_get_cb(p_icp67, data, cnt);
|
p_method->param_get_cb(p_icp67, data, cnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1219,57 +1047,57 @@ void self_ptl_method_task()
|
||||||
|
|
||||||
LOCAL void cmd_show_iec_tbl(uint16_t info_addr)
|
LOCAL void cmd_show_iec_tbl(uint16_t info_addr)
|
||||||
{
|
{
|
||||||
stru_app_cfg *p_cfg = get_app_cfg_ptr();
|
// stru_app_cfg *p_cfg = get_app_cfg_ptr();
|
||||||
if(info_addr == MX_INFO_ADDR)
|
// if(info_addr == MX_INFO_ADDR)
|
||||||
{
|
// {
|
||||||
for(uint16_t i = 0; i < p_cfg->mx_info_vec.size(); i++)
|
// for(uint16_t i = 0; i < p_cfg->mx_info_vec.size(); i++)
|
||||||
{
|
// {
|
||||||
stru_iec_mx_info *p = &p_cfg->mx_info_vec[i];
|
// stru_iec_mx_info *p = &p_cfg->mx_info_vec[i];
|
||||||
|
|
||||||
printf("no %04d, inf %04x, factor %f, record_flag %d, dead_zone %d, max_value %f, data %f, desc %s\n ",
|
// printf("no %04d, inf %04x, factor %f, record_flag %d, dead_zone %d, max_value %f, data %f, desc %s\n ",
|
||||||
i, p->inf, p->factor, p->record_flag, p->dead_zone, p->max_limit, p->data, p->desc.c_str());
|
// i, p->inf, p->factor, p->record_flag, p->dead_zone, p->max_limit, p->data, p->desc.c_str());
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else if(info_addr == ST_INFO_ADDR)
|
// else if(info_addr == ST_INFO_ADDR)
|
||||||
{
|
// {
|
||||||
for(uint16_t i = 0; i < p_cfg->st_info_vec.size(); i++)
|
// for(uint16_t i = 0; i < p_cfg->st_info_vec.size(); i++)
|
||||||
{
|
// {
|
||||||
stru_iec_st_info *p = &p_cfg->st_info_vec[i];
|
// stru_iec_st_info *p = &p_cfg->st_info_vec[i];
|
||||||
|
|
||||||
printf("no %04d, inf %04x, invert %d, debounce_time %d, data %d, desc %s\n ",
|
// printf("no %04d, inf %04x, invert %d, debounce_time %d, data %d, desc %s\n ",
|
||||||
i, p->inf, p->invert, p->debounce_time, p->data, p->desc.c_str());
|
// i, p->inf, p->invert, p->debounce_time, p->data, p->desc.c_str());
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else if(info_addr == CO_INFO_ADDR)
|
// else if(info_addr == CO_INFO_ADDR)
|
||||||
{
|
// {
|
||||||
for(uint16_t i = 0; i < p_cfg->co_info_vec.size(); i++)
|
// for(uint16_t i = 0; i < p_cfg->co_info_vec.size(); i++)
|
||||||
{
|
// {
|
||||||
stru_iec_co_info *p = &p_cfg->co_info_vec[i];
|
// stru_iec_co_info *p = &p_cfg->co_info_vec[i];
|
||||||
|
|
||||||
printf("no %04d, inf %04x, ctrl_attr %d, data %d, desc %s\n ", i, p->inf, p->ctrl_attr, p->data, p->desc.c_str());
|
// printf("no %04d, inf %04x, ctrl_attr %d, data %d, desc %s\n ", i, p->inf, p->ctrl_attr, p->data, p->desc.c_str());
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else if(info_addr == AO_INFO_ADDR)
|
// else if(info_addr == AO_INFO_ADDR)
|
||||||
{
|
// {
|
||||||
for(uint16_t i = 0; i < p_cfg->param_info_vec.size(); i++)
|
// for(uint16_t i = 0; i < p_cfg->param_info_vec.size(); i++)
|
||||||
{
|
// {
|
||||||
stru_iec_param_info *p = &p_cfg->param_info_vec[i];
|
// stru_iec_param_info *p = &p_cfg->param_info_vec[i];
|
||||||
|
|
||||||
char val[256] = {0};
|
// char val[256] = {0};
|
||||||
// param_data_show(p->p_val->buf, val, p->type);
|
// // param_data_show(p->p_val->buf, val, p->type);
|
||||||
printf("no %04d, inf %04x, encoding %d, type %d, param_addr %d, up_dtype %d, factor %f, data %s, desc %s\n ",
|
// printf("no %04d, inf %04x, encoding %d, type %d, param_addr %d, up_dtype %d, factor %f, data %s, desc %s\n ",
|
||||||
i, p->inf, p->encoding, p->type, p->param_addr, p->up_dtype, p->factor, val, p->desc.c_str());
|
// i, p->inf, p->encoding, p->type, p->param_addr, p->up_dtype, p->factor, val, p->desc.c_str());
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else if(info_addr == DD_INFO_ADDR)
|
// else if(info_addr == DD_INFO_ADDR)
|
||||||
{
|
// {
|
||||||
for(uint16_t i = 0; i < p_cfg->dd_info_vec.size(); i++)
|
// for(uint16_t i = 0; i < p_cfg->dd_info_vec.size(); i++)
|
||||||
{
|
// {
|
||||||
stru_iec_dd_info *p = &p_cfg->dd_info_vec[i];
|
// stru_iec_dd_info *p = &p_cfg->dd_info_vec[i];
|
||||||
|
|
||||||
printf("no %04d, inf %04x, factor %f, data %f, desc %s\n ", i, p->inf, p->factor, p->data, p->desc.c_str());
|
// printf("no %04d, inf %04x, factor %f, data %f, desc %s\n ", i, p->inf, p->factor, p->data, p->desc.c_str());
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
LOCAL void cmd_self_ptl(int argc, char *argv[])
|
LOCAL void cmd_self_ptl(int argc, char *argv[])
|
||||||
|
|
@ -1295,14 +1123,14 @@ LOCAL void cmd_self_ptl(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
else if(argc == 3)
|
else if(argc == 3)
|
||||||
{
|
{
|
||||||
stru_app_cfg *p_cfg = get_app_cfg_ptr();
|
stru_self_ptl_cfg_data *p_cfg = self_ptl_cfg_data_ptr_get();
|
||||||
for(uint16_t i = 0; i < p_cfg->p_param_cfg->vec_param.size(); i++)
|
for(uint16_t i = 0; i < p_cfg->param_vec.size(); i++)
|
||||||
{
|
{
|
||||||
stru_param_cfg_data *p_data = &p_cfg->p_param_cfg->vec_param[i];
|
stru_self_ptl_cfg_param_data *p_data = &p_cfg->param_vec[i];
|
||||||
|
stru_self_ptl_cfg_base *p_base = &p_data->p_param->base;
|
||||||
std::string val = "";
|
std::string val = dc_get_signal_val(p_data->p_data, p_data->p_param->type);
|
||||||
param_data_show(p_data->p_data, val, p_data->type);
|
printf("no %06d, saddr %s, desc %s, inf %04x, type %04d, len %04d, val %s, default %s\n",
|
||||||
printf("no %06d, inf %04x, type %04d, len %04d, val %s\n", i, p_data->inf, p_data->type, g_type_len_map[p_data->type], val.c_str());
|
i, p_base->saddr.c_str(), p_base->desc.c_str(), p_base->inf, p_data->p_param->type, dc_get_data_type_len(p_data->p_param->type), val.c_str(), p_data->p_param->default_value.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,890 +0,0 @@
|
||||||
#include "parse_cfg.h"
|
|
||||||
#include "myMd5.h"
|
|
||||||
#include "myFunc.h"
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
|
|
||||||
LOCAL int parse_fixed_param_csv(const char *file_name, stru_app_cfg &app_cfg);
|
|
||||||
LOCAL int parse_param_csv(const char *file_name, stru_app_cfg &app_cfg);
|
|
||||||
LOCAL int parse_param_txt(const char *file_name, stru_app_cfg &app_cfg);
|
|
||||||
LOCAL int parse_iec_st_csv(const char *file_name, stru_app_cfg &app_cfg);
|
|
||||||
LOCAL int parse_iec_mx_csv(const char *file_name, stru_app_cfg &app_cfg);
|
|
||||||
LOCAL int parse_iec_co_csv(const char *file_name, stru_app_cfg &app_cfg);
|
|
||||||
LOCAL int parse_iec_dd_csv(const char *file_name, stru_app_cfg &app_cfg);
|
|
||||||
LOCAL int parse_iec_param_fixed_csv(const char *file_name, stru_app_cfg &app_cfg);
|
|
||||||
LOCAL int parse_iec_param_run_csv(const char *file_name, stru_app_cfg &app_cfg);
|
|
||||||
LOCAL int parse_iec_param_act_csv(const char *file_name, stru_app_cfg &app_cfg);
|
|
||||||
|
|
||||||
LOCAL void show_param_cfg(stru_param_cfg ¶m_cfg);
|
|
||||||
LOCAL stru_param_cfg *parse_param_cfg(std::string cfg_file, std::map<std::string, std::string> &signal_name_map);
|
|
||||||
|
|
||||||
|
|
||||||
LOCAL void csv_data_show(stru_csv_data *p_data);
|
|
||||||
LOCAL stru_csv_data *csv_parse(const std::string csv_file);
|
|
||||||
|
|
||||||
|
|
||||||
LOCAL stru_app_cfg g_app_cfg = {0};
|
|
||||||
|
|
||||||
stru_app_cfg *get_app_cfg_ptr(void)
|
|
||||||
{
|
|
||||||
return &g_app_cfg;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOCAL std::string g_cfg_path = "/mnt/RTU/test/file/SYSCONFIG/";
|
|
||||||
|
|
||||||
LOCAL struct
|
|
||||||
{
|
|
||||||
const char *file_name;
|
|
||||||
int (*func_parse)(const char *file_name, stru_app_cfg &app_cfg);
|
|
||||||
}g_cfg_list[] =
|
|
||||||
{
|
|
||||||
{"fixed_param_cfg.csv", parse_fixed_param_csv},
|
|
||||||
{"ParamMapping.csv", parse_param_csv},
|
|
||||||
{"st.csv", parse_iec_st_csv},
|
|
||||||
{"mx.csv", parse_iec_mx_csv},
|
|
||||||
{"co.csv", parse_iec_co_csv},
|
|
||||||
{"dd.csv", parse_iec_dd_csv},
|
|
||||||
{"fixed_param.csv", parse_iec_param_fixed_csv},
|
|
||||||
|
|
||||||
{"act_param.csv", parse_iec_param_act_csv},
|
|
||||||
{"run_param.csv", parse_iec_param_run_csv},
|
|
||||||
{"PARAMCONFIG.txt", parse_param_txt},
|
|
||||||
};
|
|
||||||
LOCAL int g_cfg_list_size = sizeof(g_cfg_list) / sizeof(g_cfg_list[0]);
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
uint8_t type_len;
|
|
||||||
uint8_t type_id;
|
|
||||||
}stru_type_info;
|
|
||||||
|
|
||||||
LOCAL std::map<std::string, stru_type_info> g_type_map =
|
|
||||||
{
|
|
||||||
{"s8", {1, DATA_TYPE_S8}},
|
|
||||||
{"u8", {1, DATA_TYPE_U8}},
|
|
||||||
{"s16", {2, DATA_TYPE_S16}},
|
|
||||||
{"u16", {2, DATA_TYPE_U16}},
|
|
||||||
{"s32", {4, DATA_TYPE_S32}},
|
|
||||||
{"u32", {4, DATA_TYPE_U32}},
|
|
||||||
{"f32", {4, DATA_TYPE_F32}},
|
|
||||||
{"ip", {4, DATA_TYPE_IP}},
|
|
||||||
{"mac", {8, DATA_TYPE_MAC}},
|
|
||||||
{"c8", {8, DATA_TYPE_C8}},
|
|
||||||
{"c32", {32, DATA_TYPE_C32}},
|
|
||||||
{"c64", {64, DATA_TYPE_C64}},
|
|
||||||
{"c1", {1, DATA_TYPE_C1}},
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LOCAL void param_set_signal_name_map(stru_csv_data &csv_data, std::map<std::string, std::string> &signal_name_map)
|
|
||||||
{
|
|
||||||
for(size_t i = 1; i < csv_data.row_vec.size(); i++)
|
|
||||||
{
|
|
||||||
stru_csv_row &row = csv_data.row_vec[i];
|
|
||||||
if(row.field_vec.size() < 2)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
std::string signal = row.field_vec[1];
|
|
||||||
std::string name = row.field_vec[3];
|
|
||||||
signal_name_map[signal] = name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LOCAL void hex_str_to_int(std::string &hex_str, uint16_t &data)
|
|
||||||
{
|
|
||||||
char *endptr;
|
|
||||||
data = strtoul(hex_str.c_str(), &endptr, 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
LOCAL int parse_param_csv(const char *file_name, stru_app_cfg &app_cfg)
|
|
||||||
{
|
|
||||||
std::string path = g_cfg_path + file_name;
|
|
||||||
|
|
||||||
if(NULL == (app_cfg.p_param_csv = csv_parse(path)))
|
|
||||||
{
|
|
||||||
MY_LOG_E("parse %s failed", path.c_str());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
param_set_signal_name_map(*app_cfg.p_param_csv, app_cfg.param_signal_name_map);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
LOCAL int parse_param_txt(const char *file_name, stru_app_cfg &app_cfg)
|
|
||||||
{
|
|
||||||
std::string path = g_cfg_path + file_name;
|
|
||||||
|
|
||||||
if(NULL == (app_cfg.p_param_cfg = parse_param_cfg(path, app_cfg.param_signal_name_map)))
|
|
||||||
{
|
|
||||||
MY_LOG_E("parse %s failed", path.c_str());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// show_param_cfg(*app_cfg.p_param_cfg);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
LOCAL int parse_fixed_param_csv(const char *file_name, stru_app_cfg &app_cfg)
|
|
||||||
{
|
|
||||||
std::string path = g_cfg_path + file_name;
|
|
||||||
|
|
||||||
if(NULL == (app_cfg.p_fixed_param_cfg_csv = csv_parse(path)))
|
|
||||||
{
|
|
||||||
MY_LOG_E("parse %s failed", path.c_str());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// csv_data_show(app_cfg.p_fixed_param_cfg_csv);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
LOCAL int parse_iec_st_csv(const char *file_name, stru_app_cfg &app_cfg)
|
|
||||||
{
|
|
||||||
std::string path = g_cfg_path + file_name;
|
|
||||||
|
|
||||||
if(NULL == (app_cfg.p_iec_st_csv = csv_parse(path)))
|
|
||||||
{
|
|
||||||
MY_LOG_E("parse %s failed", path.c_str());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// csv_data_show(app_cfg.p_iec_st_csv);
|
|
||||||
for(size_t i = 1; i < app_cfg.p_iec_st_csv->row_vec.size(); i++)
|
|
||||||
{
|
|
||||||
stru_csv_row &row = app_cfg.p_iec_st_csv->row_vec[i];
|
|
||||||
if(row.field_vec.size() < 2)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
stru_iec_st_info st_info;
|
|
||||||
st_info.desc = row.field_vec[0];
|
|
||||||
hex_str_to_int(row.field_vec[1], st_info.inf);
|
|
||||||
|
|
||||||
app_cfg.st_info_vec.push_back(st_info);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOCAL int parse_iec_mx_csv(const char *file_name, stru_app_cfg &app_cfg)
|
|
||||||
{
|
|
||||||
std::string path = g_cfg_path + file_name;
|
|
||||||
|
|
||||||
if(NULL == (app_cfg.p_iec_mx_csv = csv_parse(path)))
|
|
||||||
{
|
|
||||||
MY_LOG_E("parse %s failed", path.c_str());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// csv_data_show(app_cfg.p_iec_mx_csv);
|
|
||||||
|
|
||||||
for(size_t i = 1; i < app_cfg.p_iec_mx_csv->row_vec.size(); i++)
|
|
||||||
{
|
|
||||||
stru_csv_row &row = app_cfg.p_iec_mx_csv->row_vec[i];
|
|
||||||
if(row.field_vec.size() < 2)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
stru_iec_mx_info mx_info;
|
|
||||||
mx_info.desc = row.field_vec[0];
|
|
||||||
hex_str_to_int(row.field_vec[1], mx_info.inf);
|
|
||||||
|
|
||||||
app_cfg.mx_info_vec.push_back(mx_info);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOCAL int parse_iec_co_csv(const char *file_name, stru_app_cfg &app_cfg)
|
|
||||||
{
|
|
||||||
std::string path = g_cfg_path + file_name;
|
|
||||||
|
|
||||||
if(NULL == (app_cfg.p_iec_co_csv = csv_parse(path)))
|
|
||||||
{
|
|
||||||
MY_LOG_E("parse %s failed", path.c_str());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// csv_data_show(app_cfg.p_iec_co_csv);
|
|
||||||
|
|
||||||
for(size_t i = 1; i < app_cfg.p_iec_co_csv->row_vec.size(); i++)
|
|
||||||
{
|
|
||||||
stru_csv_row &row = app_cfg.p_iec_co_csv->row_vec[i];
|
|
||||||
if(row.field_vec.size() < 2)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
stru_iec_co_info co_info;
|
|
||||||
co_info.desc = row.field_vec[0];
|
|
||||||
hex_str_to_int(row.field_vec[1], co_info.inf);
|
|
||||||
|
|
||||||
app_cfg.co_info_vec.push_back(co_info);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOCAL int parse_iec_dd_csv(const char *file_name, stru_app_cfg &app_cfg)
|
|
||||||
{
|
|
||||||
std::string path = g_cfg_path + file_name;
|
|
||||||
|
|
||||||
if(NULL == (app_cfg.p_iec_dd_csv = csv_parse(path)))
|
|
||||||
{
|
|
||||||
MY_LOG_E("parse %s failed", path.c_str());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// csv_data_show(app_cfg.p_iec_dd_csv);
|
|
||||||
|
|
||||||
for(size_t i = 1; i < app_cfg.p_iec_dd_csv->row_vec.size(); i++)
|
|
||||||
{
|
|
||||||
stru_csv_row &row = app_cfg.p_iec_dd_csv->row_vec[i];
|
|
||||||
if(row.field_vec.size() < 2)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
stru_iec_dd_info dd_info;
|
|
||||||
dd_info.desc = row.field_vec[0];
|
|
||||||
hex_str_to_int(row.field_vec[1], dd_info.inf);
|
|
||||||
|
|
||||||
app_cfg.dd_info_vec.push_back(dd_info);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOCAL int parse_iec_param_fixed_csv(const char *file_name, stru_app_cfg &app_cfg)
|
|
||||||
{
|
|
||||||
std::string path = g_cfg_path + file_name;
|
|
||||||
|
|
||||||
if(NULL == (app_cfg.p_iec_param_fixed_csv = csv_parse(path)))
|
|
||||||
{
|
|
||||||
MY_LOG_E("parse %s failed", path.c_str());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// csv_data_show(app_cfg.p_iec_param_fixed_csv);
|
|
||||||
|
|
||||||
for(size_t i = 1; i < app_cfg.p_iec_param_fixed_csv->row_vec.size(); i++)
|
|
||||||
{
|
|
||||||
stru_csv_row &row = app_cfg.p_iec_param_fixed_csv->row_vec[i];
|
|
||||||
if(row.field_vec.size() < 2)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
stru_iec_param_info param_info;
|
|
||||||
param_info.desc = row.field_vec[0];
|
|
||||||
hex_str_to_int(row.field_vec[1], param_info.inf);
|
|
||||||
|
|
||||||
app_cfg.param_info_vec.push_back(param_info);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOCAL int parse_iec_param_run_csv(const char *file_name, stru_app_cfg &app_cfg)
|
|
||||||
{
|
|
||||||
std::string path = g_cfg_path + file_name;
|
|
||||||
|
|
||||||
if(NULL == (app_cfg.p_iec_param_run_csv = csv_parse(path)))
|
|
||||||
{
|
|
||||||
MY_LOG_E("parse %s failed", path.c_str());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// csv_data_show(app_cfg.p_iec_param_run_csv);
|
|
||||||
|
|
||||||
for(size_t i = 1; i < app_cfg.p_iec_param_run_csv->row_vec.size(); i++)
|
|
||||||
{
|
|
||||||
stru_csv_row &row = app_cfg.p_iec_param_run_csv->row_vec[i];
|
|
||||||
if(row.field_vec.size() < 2)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
stru_iec_param_info param_info;
|
|
||||||
param_info.desc = row.field_vec[0];
|
|
||||||
hex_str_to_int(row.field_vec[1], param_info.inf);
|
|
||||||
|
|
||||||
app_cfg.param_info_vec.push_back(param_info);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOCAL int parse_iec_param_act_csv(const char *file_name, stru_app_cfg &app_cfg)
|
|
||||||
{
|
|
||||||
std::string path = g_cfg_path + file_name;
|
|
||||||
|
|
||||||
if(NULL == (app_cfg.p_iec_param_act_csv = csv_parse(path)))
|
|
||||||
{
|
|
||||||
MY_LOG_E("parse %s failed", path.c_str());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// csv_data_show(app_cfg.p_iec_param_act_csv);
|
|
||||||
|
|
||||||
for(size_t i = 1; i < app_cfg.p_iec_param_act_csv->row_vec.size(); i++)
|
|
||||||
{
|
|
||||||
stru_csv_row &row = app_cfg.p_iec_param_act_csv->row_vec[i];
|
|
||||||
if(row.field_vec.size() < 2)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
stru_iec_param_info param_info;
|
|
||||||
param_info.desc = row.field_vec[0];
|
|
||||||
hex_str_to_int(row.field_vec[1], param_info.inf);
|
|
||||||
|
|
||||||
app_cfg.param_info_vec.push_back(param_info);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int parse_cfg_files(void)
|
|
||||||
{
|
|
||||||
for(int i = 0; i < g_cfg_list_size; i++)
|
|
||||||
{
|
|
||||||
if(NULL == g_cfg_list[i].file_name || NULL == g_cfg_list[i].func_parse)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(0 != g_cfg_list[i].func_parse(g_cfg_list[i].file_name, g_app_cfg))
|
|
||||||
{
|
|
||||||
MY_LOG_E("parse %s failed", g_cfg_list[i].file_name);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LOCAL void parse_param_cfg_info(std::string temp, stru_param_cfg ¶m_cfg, std::map<std::string, std::string> &signal_name_map)
|
|
||||||
{
|
|
||||||
if(temp.empty())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string name = "";
|
|
||||||
std::string signal = "";
|
|
||||||
std::string type = "";
|
|
||||||
|
|
||||||
size_t pos = temp.find(":");
|
|
||||||
if(pos != std::string::npos)
|
|
||||||
{
|
|
||||||
signal = temp.substr(0, pos);
|
|
||||||
type = temp.substr(pos+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(g_type_map.find(type) == g_type_map.end())
|
|
||||||
{
|
|
||||||
MY_LOG_E("type %s is not supported, signal %s", type.c_str(), signal.c_str());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
stru_type_info type_info = g_type_map[type];
|
|
||||||
|
|
||||||
|
|
||||||
std::vector<stru_param_cfg_data> *param_vec = ¶m_cfg.map_type_param[type_info.type_len];
|
|
||||||
|
|
||||||
if(signal_name_map.find(signal) != signal_name_map.end())
|
|
||||||
{
|
|
||||||
name = signal_name_map[signal];
|
|
||||||
}
|
|
||||||
param_vec->push_back({name, signal, type, type_info.type_id});
|
|
||||||
|
|
||||||
if(type_info.type_id == DATA_TYPE_B || type_info.type_id == DATA_TYPE_U8)
|
|
||||||
{
|
|
||||||
uint8_t *p_u8 = (uint8_t*)malloc(sizeof(uint8_t));
|
|
||||||
if(NULL == p_u8)
|
|
||||||
{
|
|
||||||
MY_LOG_E("DATA_TYPE_B malloc failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
param_vec->back().p_data = (void *)p_u8;
|
|
||||||
}
|
|
||||||
else if(type_info.type_id == DATA_TYPE_C1)
|
|
||||||
{
|
|
||||||
char *p_c1 = (char*)malloc(sizeof(char));
|
|
||||||
if(NULL == p_c1)
|
|
||||||
{
|
|
||||||
MY_LOG_E("DATA_TYPE_C1 malloc failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
param_vec->back().p_data = (void *)p_c1;
|
|
||||||
}
|
|
||||||
else if(type_info.type_id == DATA_TYPE_S8)
|
|
||||||
{
|
|
||||||
int8_t *p_s8 = (int8_t*)malloc(sizeof(int8_t));
|
|
||||||
if(NULL == p_s8)
|
|
||||||
{
|
|
||||||
MY_LOG_E("DATA_TYPE_S8 malloc failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
param_vec->back().p_data = (void *)p_s8;
|
|
||||||
}
|
|
||||||
else if(type_info.type_id == DATA_TYPE_S16)
|
|
||||||
{
|
|
||||||
int16_t *p_s16 = (int16_t*)malloc(sizeof(int16_t));
|
|
||||||
if(NULL == p_s16)
|
|
||||||
{
|
|
||||||
MY_LOG_E("DATA_TYPE_S16 malloc failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
param_vec->back().p_data = (void *)p_s16;
|
|
||||||
}
|
|
||||||
else if(type_info.type_id == DATA_TYPE_U16)
|
|
||||||
{
|
|
||||||
uint16_t *p_u16 = (uint16_t*)malloc(sizeof(uint16_t));
|
|
||||||
if(NULL == p_u16)
|
|
||||||
{
|
|
||||||
MY_LOG_E("DATA_TYPE_U16 malloc failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
param_vec->back().p_data = (void *)p_u16;
|
|
||||||
}
|
|
||||||
else if(type_info.type_id == DATA_TYPE_S32)
|
|
||||||
{
|
|
||||||
int32_t *p_s32 = (int32_t*)malloc(sizeof(int32_t));
|
|
||||||
if(NULL == p_s32)
|
|
||||||
{
|
|
||||||
MY_LOG_E("DATA_TYPE_S32 malloc failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
param_vec->back().p_data = (void *)p_s32;
|
|
||||||
}
|
|
||||||
else if(type_info.type_id == DATA_TYPE_U32)
|
|
||||||
{
|
|
||||||
uint32_t *p_u32 = (uint32_t*)malloc(sizeof(uint32_t));
|
|
||||||
if(NULL == p_u32)
|
|
||||||
{
|
|
||||||
MY_LOG_E("DATA_TYPE_U32 malloc failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
param_vec->back().p_data = (void *)p_u32;
|
|
||||||
}
|
|
||||||
else if(type_info.type_id == DATA_TYPE_L64)
|
|
||||||
{
|
|
||||||
int64_t *p_l64 = (int64_t*)malloc(sizeof(int64_t));
|
|
||||||
if(NULL == p_l64)
|
|
||||||
{
|
|
||||||
MY_LOG_E("DATA_TYPE_L64 malloc failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
param_vec->back().p_data = (void *)p_l64;
|
|
||||||
}
|
|
||||||
else if(type_info.type_id == DATA_TYPE_UL64)
|
|
||||||
{
|
|
||||||
uint64_t *p_ul64 = (uint64_t*)malloc(sizeof(uint64_t));
|
|
||||||
if(NULL == p_ul64)
|
|
||||||
{
|
|
||||||
MY_LOG_E("DATA_TYPE_UL64 malloc failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
param_vec->back().p_data = (void *)p_ul64;
|
|
||||||
}
|
|
||||||
else if(type_info.type_id == DATA_TYPE_F32)
|
|
||||||
{
|
|
||||||
float *p_f32 = (float*)malloc(sizeof(float));
|
|
||||||
if(NULL == p_f32)
|
|
||||||
{
|
|
||||||
MY_LOG_E("DATA_TYPE_F32 malloc failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
param_vec->back().p_data = (void *)p_f32;
|
|
||||||
}
|
|
||||||
else if(type_info.type_id == DATA_TYPE_D64)
|
|
||||||
{
|
|
||||||
double *p_f64 = (double*)malloc(sizeof(double));
|
|
||||||
if(NULL == p_f64)
|
|
||||||
{
|
|
||||||
MY_LOG_E("DATA_TYPE_D64 malloc failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
param_vec->back().p_data = (void *)p_f64;
|
|
||||||
}
|
|
||||||
else if(type_info.type_id == DATA_TYPE_IP)
|
|
||||||
{
|
|
||||||
char *p_ip = (char*)malloc(sizeof(char)*4);
|
|
||||||
if(NULL == p_ip)
|
|
||||||
{
|
|
||||||
MY_LOG_E("DATA_TYPE_IP malloc failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
param_vec->back().p_data = (void *)p_ip;
|
|
||||||
}
|
|
||||||
else if(type_info.type_id == DATA_TYPE_MAC)
|
|
||||||
{
|
|
||||||
char *p_mac = (char*)malloc(sizeof(char)*8);
|
|
||||||
if(NULL == p_mac)
|
|
||||||
{
|
|
||||||
MY_LOG_E("DATA_TYPE_MAC malloc failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
param_vec->back().p_data = (void *)p_mac;
|
|
||||||
}
|
|
||||||
else if(type_info.type_id == DATA_TYPE_C8)
|
|
||||||
{
|
|
||||||
char *p_c8 = (char*)malloc(sizeof(char)*8);
|
|
||||||
if(NULL == p_c8)
|
|
||||||
{
|
|
||||||
MY_LOG_E("DATA_TYPE_C8 malloc failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
param_vec->back().p_data = (void *)p_c8;
|
|
||||||
}
|
|
||||||
else if(type_info.type_id == DATA_TYPE_C32)
|
|
||||||
{
|
|
||||||
char *p_c32 = (char*)malloc(sizeof(char)*32);
|
|
||||||
if(NULL == p_c32)
|
|
||||||
{
|
|
||||||
MY_LOG_E("DATA_TYPE_C32 malloc failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
param_vec->back().p_data = (void *)p_c32;
|
|
||||||
}
|
|
||||||
else if(type_info.type_id == DATA_TYPE_C64)
|
|
||||||
{
|
|
||||||
char *p_c64 = (char*)malloc(sizeof(char)*64);
|
|
||||||
if(NULL == p_c64)
|
|
||||||
{
|
|
||||||
MY_LOG_E("DATA_TYPE_C64 malloc failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
param_vec->back().p_data = (void *)p_c64;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LOCAL stru_param_cfg *parse_param_cfg_buf(uint8_t *p_buf, uint32_t buf_size, std::map<std::string, std::string> &signal_name_map)
|
|
||||||
{
|
|
||||||
if(NULL == p_buf || 0 == buf_size)
|
|
||||||
{
|
|
||||||
MY_LOG_E("p_buf is NULL or buf_size is 0");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
stru_param_cfg *param_cfg = new stru_param_cfg;
|
|
||||||
if(NULL == param_cfg)
|
|
||||||
{
|
|
||||||
MY_LOG_E("malloc failed");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
MD5_CTX md5_ctx;
|
|
||||||
StartMD5(&md5_ctx);
|
|
||||||
EncodeMD5(&md5_ctx, p_buf, buf_size);
|
|
||||||
GetMD5(&md5_ctx, param_cfg->md5);
|
|
||||||
|
|
||||||
|
|
||||||
uint8_t temp[64] = {0};
|
|
||||||
uint8_t temp_len = 0;
|
|
||||||
uint32_t pos = 0;
|
|
||||||
for(uint32_t i = 0; i < buf_size; i++)
|
|
||||||
{
|
|
||||||
if(p_buf[i] != ',' && p_buf[i] != '\n' && p_buf[i] != '\r')
|
|
||||||
{
|
|
||||||
temp[temp_len++] = p_buf[i];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
temp[temp_len] = '\0';
|
|
||||||
parse_param_cfg_info((char*)temp, *param_cfg, signal_name_map);
|
|
||||||
temp_len = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(i == buf_size-1)
|
|
||||||
{
|
|
||||||
temp[temp_len] = '\0';
|
|
||||||
parse_param_cfg_info((char*)temp, *param_cfg, signal_name_map);
|
|
||||||
temp_len = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(std::map<uint8_t, std::vector<stru_param_cfg_data>>::iterator it = param_cfg->map_type_param.begin(); it != param_cfg->map_type_param.end(); it++)
|
|
||||||
{
|
|
||||||
std::vector<stru_param_cfg_data> *param_vec = &it->second;
|
|
||||||
uint16_t inf = 0;
|
|
||||||
for(std::vector<stru_param_cfg_data>::iterator it2 = param_vec->begin(); it2 != param_vec->end(); it2++)
|
|
||||||
{
|
|
||||||
it2->inf = inf;
|
|
||||||
param_cfg->vec_param.push_back(*it2);
|
|
||||||
inf ++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return param_cfg;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
LOCAL stru_param_cfg *do_parse_param_cfg(std::string cfg_file, std::map<std::string, std::string> &signal_name_map)
|
|
||||||
{
|
|
||||||
uint32_t file_size = func_get_file_size(cfg_file.c_str());
|
|
||||||
if(0 == file_size)
|
|
||||||
{
|
|
||||||
MY_LOG_E("cfg_file %s is empty", cfg_file.c_str());
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t *p_buf = (uint8_t*)malloc(file_size+1);
|
|
||||||
if(NULL == p_buf)
|
|
||||||
{
|
|
||||||
MY_LOG_E("malloc failed");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t read_size = 0;
|
|
||||||
if(0 != func_read_file_to_buf(cfg_file.c_str(), (char*)p_buf, file_size, &read_size))
|
|
||||||
{
|
|
||||||
MY_LOG_E("read cfg_file %s failed", cfg_file.c_str());
|
|
||||||
free(p_buf);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(file_size != read_size)
|
|
||||||
{
|
|
||||||
MY_LOG_E("read cfg_file %s failed, read_size %d, file_size %d", cfg_file.c_str(), read_size, file_size);
|
|
||||||
free(p_buf);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
p_buf[file_size] = '\0';
|
|
||||||
|
|
||||||
return parse_param_cfg_buf(p_buf, file_size, signal_name_map);
|
|
||||||
}
|
|
||||||
|
|
||||||
LOCAL void show_param_cfg(stru_param_cfg ¶m_cfg)
|
|
||||||
{
|
|
||||||
MY_LOG_I("md5:");
|
|
||||||
for(int i = 0; i < 16; i++)
|
|
||||||
{
|
|
||||||
printf("%02x ", param_cfg.md5[i]);
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
|
|
||||||
// for(std::vector<stru_param_cfg_data>::iterator it = param_cfg.vec_param.begin(); it != param_cfg.vec_param.end(); it++)
|
|
||||||
// {
|
|
||||||
// MY_LOG_I("name %s, desc %s, type %s, type_id %d, inf %d", it->name.c_str(), it->desc.c_str(), it->type_str.c_str(), it->type, it->inf);
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
LOCAL stru_param_cfg *parse_param_cfg(std::string cfg_file, std::map<std::string, std::string> &signal_name_map)
|
|
||||||
{
|
|
||||||
if(0 != func_file_exist(cfg_file.c_str()))
|
|
||||||
{
|
|
||||||
MY_LOG_E("cfg_file %s does not exist", cfg_file.c_str());
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
stru_param_cfg *param_cfg = do_parse_param_cfg(cfg_file, signal_name_map);
|
|
||||||
if(NULL == param_cfg)
|
|
||||||
{
|
|
||||||
MY_LOG_E("parse cfg_file %s failed", cfg_file.c_str());
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
show_param_cfg(*param_cfg);
|
|
||||||
|
|
||||||
return param_cfg;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LOCAL std::string trim(const std::string& str) {
|
|
||||||
size_t start = str.find_first_not_of(" \t\r\n");
|
|
||||||
if (start == std::string::npos)
|
|
||||||
return "";
|
|
||||||
size_t end = str.find_last_not_of(" \t\r\n");
|
|
||||||
std::string result = str.substr(start, end - start + 1);
|
|
||||||
|
|
||||||
// 去除首尾的引号
|
|
||||||
if (result.size() >= 2 && result.front() == '"' && result.back() == '"')
|
|
||||||
{
|
|
||||||
result = result.substr(1, result.size() - 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOCAL void parse_line(const std::string line, char delimiter, stru_csv_row &row)
|
|
||||||
{
|
|
||||||
std::string field;
|
|
||||||
int in_qutoes = 0;
|
|
||||||
|
|
||||||
for(size_t i = 0; i < line.length(); i++)
|
|
||||||
{
|
|
||||||
char c = line[i];
|
|
||||||
|
|
||||||
if(in_qutoes)
|
|
||||||
{
|
|
||||||
if(c == '"')
|
|
||||||
{
|
|
||||||
if(i + 1 < line.length() && line[i+1] == '"')
|
|
||||||
{
|
|
||||||
field += c;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
in_qutoes = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
field += c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(c == delimiter)
|
|
||||||
{
|
|
||||||
row.field_vec.push_back(trim(field));
|
|
||||||
field.clear();
|
|
||||||
}
|
|
||||||
else if(c == '"')
|
|
||||||
{
|
|
||||||
in_qutoes = 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
field += c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
row.field_vec.push_back(trim(field));
|
|
||||||
}
|
|
||||||
|
|
||||||
LOCAL stru_csv_data *csv_parse(const std::string csv_file)
|
|
||||||
{
|
|
||||||
std::ifstream fp(csv_file);
|
|
||||||
if(!fp.is_open())
|
|
||||||
{
|
|
||||||
MY_LOG_E("csv_parse: file %s open failed", csv_file.c_str());
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
stru_csv_data *csv_data = new stru_csv_data;
|
|
||||||
csv_data->capacity = 0;
|
|
||||||
|
|
||||||
std::string line;
|
|
||||||
std::string buffer;
|
|
||||||
int line_num = 0;
|
|
||||||
|
|
||||||
while (std::getline(fp, line))
|
|
||||||
{
|
|
||||||
line_num++;
|
|
||||||
|
|
||||||
if(!line.empty() && line.back() == '\r')
|
|
||||||
{
|
|
||||||
line.pop_back();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!buffer.empty())
|
|
||||||
{
|
|
||||||
buffer += "\n" + line;
|
|
||||||
line = buffer;
|
|
||||||
buffer.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool in_qutoes = false;
|
|
||||||
for(char c : line)
|
|
||||||
{
|
|
||||||
if(c == '"')
|
|
||||||
{
|
|
||||||
in_qutoes = !in_qutoes;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(in_qutoes)
|
|
||||||
{
|
|
||||||
buffer = line;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
stru_csv_row row;
|
|
||||||
parse_line(line, ',', row);
|
|
||||||
|
|
||||||
if(!csv_data->row_vec.empty() && row.field_vec.size() == 1 && csv_data->row_vec.back().field_vec.size()>1)
|
|
||||||
{
|
|
||||||
if(!csv_data->row_vec.empty())
|
|
||||||
{
|
|
||||||
csv_data->row_vec.back().field_vec.back() += " " + row.field_vec[0];
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
csv_data->row_vec.push_back(row);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!buffer.empty())
|
|
||||||
{
|
|
||||||
stru_csv_row row;
|
|
||||||
parse_line(buffer, ',', row);
|
|
||||||
csv_data->row_vec.push_back(row);
|
|
||||||
}
|
|
||||||
|
|
||||||
fp.close();
|
|
||||||
|
|
||||||
return csv_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOCAL void csv_data_show(stru_csv_data *p_data)
|
|
||||||
{
|
|
||||||
std::vector<stru_csv_row> &data = p_data->row_vec;
|
|
||||||
if (data.empty())
|
|
||||||
{
|
|
||||||
std::cout << "No data" << std::endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 打印列标题
|
|
||||||
std::cout << "Total rows: " << data.size() << std::endl;
|
|
||||||
std::cout << "Total columns: " << data[0].field_vec.size() << std::endl << std::endl;
|
|
||||||
|
|
||||||
std::cout << "=== Column Headers ===" << std::endl;
|
|
||||||
for (size_t j = 0; j < data[0].field_vec.size(); j++) {
|
|
||||||
std::cout << "[" << j << "] " << data[0].field_vec[j] << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 打印前几行作为预览
|
|
||||||
int previewRows = data.size();
|
|
||||||
for (int i = 1; i < previewRows; i++) {
|
|
||||||
std::cout << "Row " << i << " (" << data[i].field_vec.size() << " fields): ";
|
|
||||||
for (size_t j = 0; j < data[i].field_vec.size(); j++)
|
|
||||||
{
|
|
||||||
std::string field = data[i].field_vec[j];
|
|
||||||
|
|
||||||
std::cout << "[" << field << "] ";
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
#include "myLog.h"
|
#include "myLog.h"
|
||||||
#include "myIcp67.h"
|
#include "myIcp67.h"
|
||||||
#include "method.h"
|
#include "method.h"
|
||||||
#include "parse_cfg.h"
|
|
||||||
#include "self_ptl.h"
|
#include "self_ptl.h"
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
|
@ -77,6 +76,9 @@ stru_self_ptl g_self_ptl =
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
stru_self_ptl_cfg_data g_self_ptl_cfg_data = {};
|
||||||
|
|
||||||
|
|
||||||
stru_genneral_method *self_ptl_method_ptr_get()
|
stru_genneral_method *self_ptl_method_ptr_get()
|
||||||
{
|
{
|
||||||
return &g_self_ptl.method;
|
return &g_self_ptl.method;
|
||||||
|
|
@ -87,6 +89,11 @@ stru_icp67 *self_ptl_icp67_ptr_get()
|
||||||
return &g_self_ptl.icp67;
|
return &g_self_ptl.icp67;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stru_self_ptl_cfg_data *self_ptl_cfg_data_ptr_get()
|
||||||
|
{
|
||||||
|
return &g_self_ptl_cfg_data;
|
||||||
|
}
|
||||||
|
|
||||||
LOCAL void put_rx_data(stru_self_rx *p_slef_rx, uint8_t *p_rx, uint16_t len)
|
LOCAL void put_rx_data(stru_self_rx *p_slef_rx, uint8_t *p_rx, uint16_t len)
|
||||||
{
|
{
|
||||||
if(NULL == p_slef_rx || NULL == p_rx || 0 == len)
|
if(NULL == p_slef_rx || NULL == p_rx || 0 == len)
|
||||||
|
|
@ -458,6 +465,76 @@ void self_ptl_set_interface(uint32_t interface)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
LOCAL int self_ptl_cfg_init()
|
||||||
|
{
|
||||||
|
stru_self_ptl_cfg *p_cfg = self_ptl_cfg_get();
|
||||||
|
if(nullptr == p_cfg)
|
||||||
|
{
|
||||||
|
LOG_E("self_ptl_cfg_init self_ptl_cfg_get failed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
stru_self_ptl_cfg_data *p_cfg_data = &g_self_ptl_cfg_data;
|
||||||
|
|
||||||
|
for(uint32_t i = 0; i < p_cfg->st_vec.size(); i++)
|
||||||
|
{
|
||||||
|
uint8_t *p_u8 = new uint8_t;
|
||||||
|
uint8_t *p_u8_last = new uint8_t;
|
||||||
|
(*p_u8) = 0;
|
||||||
|
(*p_u8_last) = 0;
|
||||||
|
p_cfg_data->st_vec.push_back({&p_cfg->st_vec[i], p_u8, p_u8_last});
|
||||||
|
}
|
||||||
|
|
||||||
|
for(uint32_t i = 0; i < p_cfg->mx_vec.size(); i++)
|
||||||
|
{
|
||||||
|
float *p_f = new float;
|
||||||
|
float *p_f_last = new float;
|
||||||
|
(*p_f) = 0.0;
|
||||||
|
(*p_f_last) = 0.0;
|
||||||
|
p_cfg_data->mx_vec.push_back({&p_cfg->mx_vec[i], p_f, p_f_last});
|
||||||
|
}
|
||||||
|
|
||||||
|
for(uint32_t i = 0; i < p_cfg->co_vec.size(); i++)
|
||||||
|
{
|
||||||
|
uint8_t *p_u8 = new uint8_t;
|
||||||
|
uint8_t *p_u8_last = new uint8_t;
|
||||||
|
(*p_u8) = 0;
|
||||||
|
(*p_u8_last) = 0;
|
||||||
|
p_cfg_data->co_vec.push_back({&p_cfg->co_vec[i], p_u8, p_u8_last});
|
||||||
|
}
|
||||||
|
|
||||||
|
for(uint32_t i = 0; i < p_cfg->dd_vec.size(); i++)
|
||||||
|
{
|
||||||
|
float *p_f = new float;
|
||||||
|
float *p_f_last = new float;
|
||||||
|
(*p_f) = 0.0;
|
||||||
|
(*p_f_last) = 0.0;
|
||||||
|
p_cfg_data->dd_vec.push_back({&p_cfg->dd_vec[i], p_f, p_f_last});
|
||||||
|
}
|
||||||
|
|
||||||
|
for(uint32_t i = 0; i < p_cfg->param_vec.size(); i++)
|
||||||
|
{
|
||||||
|
stru_self_ptl_cfg_param *p_param = &p_cfg->param_vec[i];
|
||||||
|
void *p_data = dc_create_data_ptr_by_type(p_param->type);
|
||||||
|
if(nullptr == p_data)
|
||||||
|
{
|
||||||
|
LOG_E("self_ptl_cfg_init dc_create_data_ptr_by_type failed, type:%d", p_param->type);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *p_default_data = dc_create_data_ptr_by_type(p_param->type);
|
||||||
|
if(nullptr == p_default_data)
|
||||||
|
{
|
||||||
|
LOG_E("self_ptl_cfg_init dc_create_data_ptr_by_type failed, type:%d", p_param->type);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
p_cfg_data->param_vec.push_back({p_param, p_data, p_default_data});
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void self_ptl_init()
|
void self_ptl_init()
|
||||||
{
|
{
|
||||||
// g_self_ptl.interface = com_channel_interface_get(ENUM_COMM_TCP_C_0);
|
// g_self_ptl.interface = com_channel_interface_get(ENUM_COMM_TCP_C_0);
|
||||||
|
|
@ -466,14 +543,14 @@ void self_ptl_init()
|
||||||
stru_icp67 *p_icp67 = &g_self_ptl.icp67;
|
stru_icp67 *p_icp67 = &g_self_ptl.icp67;
|
||||||
icp67_init(p_icp67, self_ptl_data_tx, (void *)&g_self_ptl.interface);
|
icp67_init(p_icp67, self_ptl_data_tx, (void *)&g_self_ptl.interface);
|
||||||
|
|
||||||
stru_app_cfg *p_app_cfg = get_app_cfg_ptr();
|
stru_self_ptl_cfg *p_self_cfg = self_ptl_cfg_get();
|
||||||
if(NULL == p_app_cfg)
|
if(nullptr == p_self_cfg)
|
||||||
{
|
{
|
||||||
LOG_E("self_ptl_init p_app_cfg NULL");
|
LOG_E("self_ptl_init self_ptl_cfg_get failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
icp67_set_param_cfg_md5(p_icp67, p_app_cfg->p_param_cfg->md5);
|
icp67_set_param_cfg_md5(p_icp67, p_self_cfg->param_md5);
|
||||||
|
|
||||||
stru_genneral_method *p_method = &g_self_ptl.method;
|
stru_genneral_method *p_method = &g_self_ptl.method;
|
||||||
|
|
||||||
|
|
@ -583,7 +660,7 @@ void self_ptl_signal_change_callback(std::string saddr, SIGNAL_CTRL_STEP step, u
|
||||||
LOG_I("signal_type %s, no %s", signal_type.c_str(), no.c_str());
|
LOG_I("signal_type %s, no %s", signal_type.c_str(), no.c_str());
|
||||||
|
|
||||||
stru_icp67 *p_icp67 = &g_self_ptl.icp67;
|
stru_icp67 *p_icp67 = &g_self_ptl.icp67;
|
||||||
stru_app_cfg *p_app_cfg = get_app_cfg_ptr();
|
stru_self_ptl_cfg_data *p_self_cfg_data = &g_self_ptl_cfg_data;
|
||||||
|
|
||||||
if(signal_type == "co")
|
if(signal_type == "co")
|
||||||
{
|
{
|
||||||
|
|
@ -595,17 +672,17 @@ void self_ptl_signal_change_callback(std::string saddr, SIGNAL_CTRL_STEP step, u
|
||||||
{
|
{
|
||||||
if(g_self_ptl.method.param_set_cb)
|
if(g_self_ptl.method.param_set_cb)
|
||||||
{
|
{
|
||||||
for(uint32_t i = 0; i < p_app_cfg->p_param_cfg->vec_param.size(); i++)
|
for(uint32_t i = 0; i < p_self_cfg_data->param_vec.size(); i++)
|
||||||
{
|
{
|
||||||
stru_param_cfg_data *p = &p_app_cfg->p_param_cfg->vec_param.at(i);
|
stru_self_ptl_cfg_param_data *p = &p_self_cfg_data->param_vec.at(i);
|
||||||
if(p->desc == no)
|
if(p->p_param && p->p_param->base.saddr == saddr)
|
||||||
{
|
{
|
||||||
uint8_t temp[256] = {0};
|
uint8_t temp[256] = {0};
|
||||||
stru_ti_1_2_data_info *p_data_info = (stru_ti_1_2_data_info *)temp;
|
stru_ti_1_2_data_info *p_data_info = (stru_ti_1_2_data_info *)temp;
|
||||||
p_data_info->data_addr = p->inf;
|
p_data_info->data_addr = p->p_param->base.inf;
|
||||||
p_data_info->data_type = p->type;
|
p_data_info->data_type = p->p_param->type;
|
||||||
p_data_info->data_len = self_ptl_get_type_len(p->type);
|
p_data_info->data_len = dc_get_data_type_len(p->p_param->type);
|
||||||
std::string val = dc_get_signal_val(p->p_data, p->type);
|
std::string val = dc_get_signal_val(p->p_data, p->p_param->type);
|
||||||
strcpy((char *)p_data_info->data, val.c_str());
|
strcpy((char *)p_data_info->data, val.c_str());
|
||||||
g_self_ptl.method.param_set_cb(p_icp67, temp, 1);
|
g_self_ptl.method.param_set_cb(p_icp67, temp, 1);
|
||||||
break;
|
break;
|
||||||
|
|
@ -616,14 +693,26 @@ void self_ptl_signal_change_callback(std::string saddr, SIGNAL_CTRL_STEP step, u
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOCAL float safeStringToFloat(const std::string& str)
|
||||||
|
{
|
||||||
|
float f = 0.0f;
|
||||||
|
try {
|
||||||
|
// 能转就转
|
||||||
|
f = std::stof(str);
|
||||||
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
|
// 转不了就返回0.0
|
||||||
|
// LOG_E("safeStringToFloat failed to convert '%s' to float: %s", str.c_str(), e.what());
|
||||||
|
return 0.0f;
|
||||||
|
}
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
int self_ptl_do_signal_out(stru_app *p_app)
|
int self_ptl_do_signal_out(stru_app *p_app)
|
||||||
{
|
{
|
||||||
stru_app_cfg *p_app_cfg = get_app_cfg_ptr();
|
stru_self_ptl_cfg_data *p_app_cfg_data = &g_self_ptl_cfg_data;
|
||||||
if(NULL == p_app_cfg)
|
|
||||||
{
|
stru_self_ptl_cfg_base_data *p = nullptr;
|
||||||
LOG_E("self_ptl_do_signal_out p_app_cfg NULL");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
ret |= dc_signal_out("self_ptl.run_cnt", "self_ptl.run_cnt", DATA_TYPE_U32, &p_app->run_cnt);
|
ret |= dc_signal_out("self_ptl.run_cnt", "self_ptl.run_cnt", DATA_TYPE_U32, &p_app->run_cnt);
|
||||||
|
|
@ -633,14 +722,14 @@ int self_ptl_do_signal_out(stru_app *p_app)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LOG_I("***********st_info_size %d", p_app_cfg->st_info_vec.size());
|
// LOG_I("***********st_info_size %d", p_app_cfg->st_info_vec.size());
|
||||||
|
|
||||||
for(uint32_t i = 0; i < p_app_cfg->st_info_vec.size(); i++)
|
for(uint32_t i = 0; i < p_app_cfg_data->st_vec.size(); i++)
|
||||||
{
|
{
|
||||||
stru_iec_st_info *p = &p_app_cfg->st_info_vec.at(i);
|
p = &p_app_cfg_data->st_vec.at(i);
|
||||||
|
if(p && p->p_base)
|
||||||
p->saddr = "self_ptl.st." + std::to_string(i);
|
{
|
||||||
ret |= dc_signal_out(p->saddr, p->desc, DATA_TYPE_U8, &p->data);
|
ret |= dc_signal_out(p->p_base->saddr, p->p_base->desc, DATA_TYPE_U8, p->p_data);
|
||||||
// LOG_I("no %d, saddr %s, desc %s", i, p->saddr.c_str(), p->desc.c_str());
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ret != 0)
|
if(ret != 0)
|
||||||
|
|
@ -648,11 +737,13 @@ int self_ptl_do_signal_out(stru_app *p_app)
|
||||||
goto ERR;
|
goto ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(uint32_t i = 0; i < p_app_cfg->mx_info_vec.size(); i++)
|
for(uint32_t i = 0; i < p_app_cfg_data->mx_vec.size(); i++)
|
||||||
{
|
{
|
||||||
stru_iec_mx_info *p = &p_app_cfg->mx_info_vec.at(i);
|
p = &p_app_cfg_data->mx_vec.at(i);
|
||||||
p->saddr = "self_ptl.mx." + std::to_string(i);
|
if(p && p->p_base)
|
||||||
ret |= dc_signal_out(p->saddr, p->desc, DATA_TYPE_F32, &p->data);
|
{
|
||||||
|
ret |= dc_signal_out(p->p_base->saddr, p->p_base->desc, DATA_TYPE_F32, p->p_data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ret != 0)
|
if(ret != 0)
|
||||||
|
|
@ -660,12 +751,13 @@ int self_ptl_do_signal_out(stru_app *p_app)
|
||||||
goto ERR;
|
goto ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(uint32_t i = 0; i < p_app_cfg->co_info_vec.size(); i++)
|
for(uint32_t i = 0; i < p_app_cfg_data->co_vec.size(); i++)
|
||||||
{
|
{
|
||||||
stru_iec_co_info *p = &p_app_cfg->co_info_vec.at(i);
|
p = &p_app_cfg_data->co_vec.at(i);
|
||||||
p->saddr = "self_ptl.co." + std::to_string(i);
|
if(p && p->p_base)
|
||||||
// ret |= dc_signal_out(p->saddr, p->desc, DATA_TYPE_U8, &p->data);
|
{
|
||||||
ret |= dc_signal_yk(p->saddr, p->desc, DATA_TYPE_U8, SIGNAL_CTRL_TYPE::SBO_NORMAL, &p->data, self_ptl_signal_change_callback);
|
ret |= dc_signal_yk(p->p_base->saddr, p->p_base->desc, DATA_TYPE_U8, SIGNAL_CTRL_TYPE::SBO_NORMAL, p->p_data, self_ptl_signal_change_callback);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ret != 0)
|
if(ret != 0)
|
||||||
|
|
@ -673,11 +765,13 @@ int self_ptl_do_signal_out(stru_app *p_app)
|
||||||
goto ERR;
|
goto ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(uint32_t i = 0; i < p_app_cfg->dd_info_vec.size(); i++)
|
for(uint32_t i = 0; i < p_app_cfg_data->dd_vec.size(); i++)
|
||||||
{
|
{
|
||||||
stru_iec_dd_info *p = &p_app_cfg->dd_info_vec.at(i);
|
p = &p_app_cfg_data->dd_vec.at(i);
|
||||||
p->saddr = "self_ptl.dd." + std::to_string(i);
|
if(p && p->p_base)
|
||||||
ret |= dc_signal_out(p->saddr, p->desc, DATA_TYPE_F32, &p->data);
|
{
|
||||||
|
ret |= dc_signal_out(p->p_base->saddr, p->p_base->desc, DATA_TYPE_F32, p->p_data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ret != 0)
|
if(ret != 0)
|
||||||
|
|
@ -685,18 +779,20 @@ int self_ptl_do_signal_out(stru_app *p_app)
|
||||||
goto ERR;
|
goto ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(uint32_t i = 0; i < p_app_cfg->p_param_cfg->vec_param.size(); i++)
|
for(uint32_t i = 0; i < p_app_cfg_data->param_vec.size(); i++)
|
||||||
{
|
{
|
||||||
stru_param_cfg_data *p = &p_app_cfg->p_param_cfg->vec_param.at(i);
|
stru_self_ptl_cfg_param_data *p_param = &p_app_cfg_data->param_vec.at(i);
|
||||||
std::string saddr = "self_ptl.param." + p->desc;
|
if(p_param && p_param->p_param)
|
||||||
stru_signal_param param;
|
{
|
||||||
param.min = 0;
|
stru_signal_param param;
|
||||||
param.max = 100;
|
param.min = safeStringToFloat(p_param->p_param->min);
|
||||||
param.step = 1;
|
param.max = safeStringToFloat(p_param->p_param->max);
|
||||||
param.p_default = NULL;
|
param.step = safeStringToFloat(p_param->p_param->step);
|
||||||
param.unit = "";
|
param.p_default = p_param->p_default_data;
|
||||||
// ret |= dc_signal_out(saddr, p->name, p->type, p->p_data);
|
param.unit = p_param->p_param->unit;
|
||||||
ret |= dc_signal_param(saddr, p->name, p->type, param, SIGNAL_CTRL_TYPE::SBO_NORMAL, p->p_data, self_ptl_signal_change_callback);
|
// ret(saddr, p(saddr, p->name, p->type, p->p_data);
|
||||||
|
ret |= dc_signal_param(p_param->p_param->base.saddr, p_param->p_param->base.desc, p_param->p_param->type, param, SIGNAL_CTRL_TYPE::SBO_NORMAL, p_param->p_data, self_ptl_signal_change_callback);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ret != 0)
|
if(ret != 0)
|
||||||
|
|
@ -715,11 +811,13 @@ int app_self_ptl_init1(void *arg)
|
||||||
{
|
{
|
||||||
stru_app *p_app = (stru_app *)arg;
|
stru_app *p_app = (stru_app *)arg;
|
||||||
|
|
||||||
if(0 != parse_cfg_files())
|
// if(0 != parse_cfg_files())
|
||||||
{
|
// {
|
||||||
MY_LOG_E("self ptl parse_cfg_files failed");
|
// MY_LOG_E("self ptl parse_cfg_files failed");
|
||||||
return -1;
|
// return -1;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
self_ptl_cfg_init();
|
||||||
|
|
||||||
self_ptl_init();
|
self_ptl_init();
|
||||||
|
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue