208 lines
9.9 KiB
C++
208 lines
9.9 KiB
C++
|
|
|
|||
|
|
#include <TestProject/RNG/BaseData.h>
|
|||
|
|
#include <TestProject/RNG/Generator.h>
|
|||
|
|
#include <TestProject/RNG/RandT.h>
|
|||
|
|
#include <TestProject/RNG/read_csv.hpp>
|
|||
|
|
BaseData::BaseData data1;
|
|||
|
|
// ReadCSV::DoubleData ddata("D102-1#酸槽数据.csv"); ///< 2列:入口流量,出口流量
|
|||
|
|
ReadCSV::DoubleData
|
|||
|
|
ddata("数据毛刺-仿真.csv"); ///< 4列:实际速度,实际电流,设定速度,spderr
|
|||
|
|
ReadCSV::DoubleData gdata("毛刺数据.csv"); ///< 6列:RW_o_Drv_ActSpd
|
|||
|
|
///< RW_o_Drv_Current
|
|||
|
|
///< RW_o_Drv_TQ_Ref
|
|||
|
|
///< RW_o_Drv_SpdRegInt
|
|||
|
|
///< RW_o_Drv_SpdErr RW_o_Drv_AVF
|
|||
|
|
ReadCSV::DoubleData spbdata(
|
|||
|
|
"转矩减小-速度偏差大-仿真2.csv"); ///< 4列:实际速度,实际电流,实际转矩,设定速度
|
|||
|
|
ReadCSV::DoubleData
|
|||
|
|
liquid_data("液位.csv"); ///< 4列:实际速度,实际电流,实际转矩,设定速度
|
|||
|
|
// ReadCSV::IntData idata("D302-压辊数据.csv"); ///< 2列:阀动作,接近开关信号
|
|||
|
|
ReadCSV::IntData
|
|||
|
|
idata("C308仿-压辊数据.csv"); ///< 3列:阀动作- 开,接近开关信号-开,阀动作-关
|
|||
|
|
ReadCSV::DoubleData
|
|||
|
|
ddata_cn("D102-3#BR电流数据.csv"); ///< 4列:2/3/4电流,速度设定值
|
|||
|
|
ReadCSV::DoubleData
|
|||
|
|
ddata_cb("D102-3#BR异常电流数据.csv"); ///< 4列:2/3/4电流,速度设定值
|
|||
|
|
|
|||
|
|
ReadCSV::IntData car_data("D302-2#小车减速位.csv"); ///< 2列:位置,接近开关
|
|||
|
|
ReadCSV::DoubleData std1_wr("D302-1#机架正弯.csv"); ///< 2列:给定,反馈
|
|||
|
|
ReadCSV::DoubleData std5_wr("D302-工作辊正弯DS.csv"); ///< 2列:给定,反馈
|
|||
|
|
ReadCSV::DoubleData loop3("D302-3#活套1-5电流.csv"); ///< 5列:1-5电机电流
|
|||
|
|
ReadCSV::DoubleData c308fur2col("C308速度毛刺仿真.csv"); ///< 2列 正常 毛刺
|
|||
|
|
ReadCSV::IntData
|
|||
|
|
std4_cr("D102-4#机架上中间辊窜辊.csv"); ///< 5列:编码器-4个窜动
|
|||
|
|
ReadCSV::IntData loop8_bool("D102-loop8.csv"); ///< 2列:DS,OS
|
|||
|
|
|
|||
|
|
Generator::Generator() {
|
|||
|
|
stime = chrono::system_clock::now();
|
|||
|
|
logger_ = std::make_unique<LOG>("Generator");
|
|||
|
|
}
|
|||
|
|
Generator::~Generator() {
|
|||
|
|
// if (!map_tables_.empty()) {
|
|||
|
|
// auto iter = map_tables_.begin();
|
|||
|
|
// while (iter != map_tables_.end()) {
|
|||
|
|
// delete iter->second;
|
|||
|
|
// iter->second = nullptr;
|
|||
|
|
// map_tables_.erase(iter++);
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
for (auto &it : m_mapfix) {
|
|||
|
|
if (it.second != nullptr) {
|
|||
|
|
delete it.second;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
bool Generator::wtite_in_shm(int event_no) {
|
|||
|
|
try {
|
|||
|
|
// if (map_tables_.find(event_no) == map_tables_.end()) {
|
|||
|
|
// map_tables_[event_no] =
|
|||
|
|
// new CMemTable<PLC_DATA>(StringHelper::ToString<int>(event_no),
|
|||
|
|
// 100);
|
|||
|
|
// }
|
|||
|
|
// logger_->Debug() << "wtite_in_shm Test--1" << endl;
|
|||
|
|
if (m_mapfix.find(event_no) == m_mapfix.end()) {
|
|||
|
|
m_mapfix.insert(
|
|||
|
|
make_pair(event_no, new CMemFix<PLC_DATA>(std::to_string(event_no),
|
|||
|
|
TEL_CACHE_SIZE)));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
binary_tele.ReBuild(event_no);
|
|||
|
|
int size = binary_tele.size();
|
|||
|
|
// binary_tele.Print();
|
|||
|
|
size_t data_index =
|
|||
|
|
((chrono::system_clock::now() - stime).count() / (size_t)pow(10, 6)) /
|
|||
|
|
20; ///<时间-下标
|
|||
|
|
logger_->Debug() << "wtite_in_shm Test--2"
|
|||
|
|
<< "---data_index:" << data_index << endl;
|
|||
|
|
for (int i = 0; i < size; i++) {
|
|||
|
|
if (binary_tele[i].type[0] == 'b') {
|
|||
|
|
/*bool量*/
|
|||
|
|
if (binary_tele[i].length != '1') {
|
|||
|
|
binary_tele[i] = RandT::randomBool();
|
|||
|
|
if (strcmp(binary_tele[i].item, "3G-DSA-B01-01B") == 0) {
|
|||
|
|
/*2#张力辊压辊打开*/
|
|||
|
|
binary_tele[i] = (float)idata(data_index, 0);
|
|||
|
|
} else if (strcmp(binary_tele[i].item, "3G-PX-B01-01") == 0) {
|
|||
|
|
/*2#张力辊压辊打开位*/
|
|||
|
|
binary_tele[i] = (float)idata(data_index, 1);
|
|||
|
|
} else if (strcmp(binary_tele[i].item, "3G-DSA-B01-01A") == 0) {
|
|||
|
|
/*2#张力辊压辊关闭*/
|
|||
|
|
binary_tele[i] = (float)idata(data_index, 2);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
else if (strcmp(binary_tele[i].item, "ENT_DR_2R22_limi") == 0) {
|
|||
|
|
/*No.2入口钢卷小车-后退极限接近开关*/
|
|||
|
|
binary_tele[i] = (float)car_data(data_index, 1);
|
|||
|
|
} else if (strcmp(binary_tele[i].item, "ENT_DR_2R11_act") == 0) {
|
|||
|
|
/*4#机架窜辊动作1*/
|
|||
|
|
binary_tele[i] = (float)std4_cr(data_index, 1);
|
|||
|
|
} else if (strcmp(binary_tele[i].item, "ENT_DR_2R12_act") == 0) {
|
|||
|
|
/*4#机架窜辊动作2*/
|
|||
|
|
binary_tele[i] = (float)std4_cr(data_index, 2);
|
|||
|
|
} else if (strcmp(binary_tele[i].item, "ENT_DR_2R11_limi") == 0) {
|
|||
|
|
/*4#机架窜辊动作3*/
|
|||
|
|
binary_tele[i] = (float)std4_cr(data_index, 3);
|
|||
|
|
} else if (strcmp(binary_tele[i].item, "ENT_DR_2R12_limi") == 0) {
|
|||
|
|
/*4#机架窜辊动作4*/
|
|||
|
|
binary_tele[i] = (float)std4_cr(data_index, 4);
|
|||
|
|
} else if (strcmp(binary_tele[i].item, "ENT_DR_2_run") == 0) {
|
|||
|
|
/*入口活套-No.8摆动门传动侧关闭极限接近开关*/
|
|||
|
|
binary_tele[i] = (float)loop8_bool(data_index, 0);
|
|||
|
|
} else if (strcmp(binary_tele[i].item, "ENT_DR_2_Ft") == 0) {
|
|||
|
|
/*入口活套-No.8摆动门操作侧关闭极限接近开关*/
|
|||
|
|
binary_tele[i] = (float)loop8_bool(data_index, 1);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
} else {
|
|||
|
|
logger_->Error() << "event_no:" << event_no << ",数据项:"
|
|||
|
|
<< binary_tele[i].chinese
|
|||
|
|
<< ",item:" << binary_tele[i].item
|
|||
|
|
<< "类型长度不匹配,"
|
|||
|
|
<< "type:" << binary_tele[i].type
|
|||
|
|
<< ",lenth:" << binary_tele[i].length << std::endl;
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
/*模拟量*/
|
|||
|
|
strcpy((char *)binary_tele[i].value, binary_tele[i].defaultValue);
|
|||
|
|
float dataN = binary_tele[i];
|
|||
|
|
binary_tele[i] = float(dataN + RandT::RandT(-0.01, 0.01));
|
|||
|
|
|
|||
|
|
if (strcmp(binary_tele[i].item, "BR1_1_V_act") == 0) {
|
|||
|
|
/*1#张力辊1#辊 实际速度*/
|
|||
|
|
binary_tele[i] =
|
|||
|
|
(float)binary_tele[i] + (float)c308fur2col(data_index, 1);
|
|||
|
|
} else if (strcmp(binary_tele[i].item, "BR1_2_V_act") == 0) {
|
|||
|
|
/*2#张力辊1#辊 设定速度*/
|
|||
|
|
binary_tele[i] =
|
|||
|
|
(float)binary_tele[i] + (float)c308fur2col(data_index, 0);
|
|||
|
|
} else if (strcmp(binary_tele[i].item, "BR2_1_V_act") == 0) {
|
|||
|
|
/*2#张力辊1#辊 实际电流*/
|
|||
|
|
binary_tele[i] =
|
|||
|
|
(float)binary_tele[i] + (float)c308fur2col(data_index, 0);
|
|||
|
|
} else if (strcmp(binary_tele[i].item, "BR2_2_V_act") == 0) {
|
|||
|
|
/*2#张力辊2#辊 实际速度*/
|
|||
|
|
binary_tele[i] =
|
|||
|
|
(float)binary_tele[i] + (float)c308fur2col(data_index, 1);
|
|||
|
|
} else if (strcmp(binary_tele[i].item, "BR2_2_I_act") == 0) {
|
|||
|
|
/*2#张力辊2#辊 实际电流*/
|
|||
|
|
binary_tele[i] = (float)spbdata(data_index, 1);
|
|||
|
|
} else if (strcmp(binary_tele[i].item, "BR2_2_TQ_act") == 0) {
|
|||
|
|
/*2#张力辊2#辊 实际转矩*/
|
|||
|
|
binary_tele[i] = (float)spbdata(data_index, 2);
|
|||
|
|
} else if (strcmp(binary_tele[i].item, "IW_3G_LV_J02_03") == 0) {
|
|||
|
|
/*入口液压站液位*/
|
|||
|
|
binary_tele[i] = (float)liquid_data(data_index, 0);
|
|||
|
|
} else if (strcmp(binary_tele[i].item, "TCM-4-82-BDRef-1-118") == 0) {
|
|||
|
|
/*1#机架工作辊正弯辊压力给定*/
|
|||
|
|
binary_tele[i] = (float)std1_wr(data_index, 0);
|
|||
|
|
} else if (strcmp(binary_tele[i].item, "TCM-4-82-BD-1-101") == 0) {
|
|||
|
|
/*1#机架工作辊正弯辊压力反馈*/
|
|||
|
|
binary_tele[i] = (float)std1_wr(data_index, 1);
|
|||
|
|
} else if (strcmp(binary_tele[i].item, "TCM-72-150-BDRef-5-134") == 0) {
|
|||
|
|
/*5#机架工作辊DS正弯辊压力给定*/
|
|||
|
|
binary_tele[i] = (float)std5_wr(data_index, 0);
|
|||
|
|
} else if (strcmp(binary_tele[i].item, "TCM-72-150-BD-5-117") == 0) {
|
|||
|
|
/*5#机架工作辊DS正弯辊压力反馈*/
|
|||
|
|
binary_tele[i] = (float)std5_wr(data_index, 1);
|
|||
|
|
} else if (strcmp(binary_tele[i].item, "ENT_BR_4R1_torfbk") == 0) {
|
|||
|
|
/*3#活套1#电机电流*/
|
|||
|
|
binary_tele[i] = (float)loop3(data_index, 0);
|
|||
|
|
} else if (strcmp(binary_tele[i].item, "ENT_BR_4R2_torfbk") == 0) {
|
|||
|
|
/*3#活套2#电机电流*/
|
|||
|
|
binary_tele[i] = (float)loop3(data_index, 1);
|
|||
|
|
} else if (strcmp(binary_tele[i].item, "ENT_BR_4R3_torfbk") == 0) {
|
|||
|
|
/*3#活套3#电机电流*/
|
|||
|
|
binary_tele[i] = (float)loop3(data_index, 2);
|
|||
|
|
} else if (strcmp(binary_tele[i].item, "ENT_BR_4R3_curfbk") == 0) {
|
|||
|
|
/*3#活套4#电机电流*/
|
|||
|
|
binary_tele[i] = (float)loop3(data_index, 3);
|
|||
|
|
} else if (strcmp(binary_tele[i].item, "ENT_BR_4R1_curfbk") == 0) {
|
|||
|
|
/*3#活套5#电机电流*/
|
|||
|
|
binary_tele[i] = (float)loop3(data_index, 4);
|
|||
|
|
} else if (strcmp(binary_tele[i].item, "ENT_BR_4R2_curfbk") == 0) {
|
|||
|
|
/*4#机架上中间辊窜辊编码器*/
|
|||
|
|
binary_tele[i] = (float)std4_cr(data_index, 0);
|
|||
|
|
} else if (strcmp(binary_tele[i].item, "ACD-3-42-FQ-2") == 0) {
|
|||
|
|
/*3#酸槽出口流量 ---Test*/
|
|||
|
|
binary_tele[i] = (float)RandT::randomBool();
|
|||
|
|
} else {
|
|||
|
|
// logger_->Debug() << "test:" << binary_tele[i].item
|
|||
|
|
// << ",value:" << binary_tele[i] << endl;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// logger_->Debug() << "vale:" << binary_tele[i].value << "," << dataN
|
|||
|
|
// << endl;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
// binary_tele.Print();
|
|||
|
|
char *buff = binary_tele.GetTeleData();
|
|||
|
|
// this->logger_->Debug() << buff << endl;
|
|||
|
|
// map_tables_[event_no]->push((PLC_DATA*)buff);
|
|||
|
|
m_mapfix[event_no]->push((PLC_DATA *)buff);
|
|||
|
|
// ((BinaryTele*)buff)->Print();
|
|||
|
|
return true;
|
|||
|
|
} catch (const std::exception &e) {
|
|||
|
|
logger_->Error() << "wtite_in_shm Error!" << e.what() << std::endl;
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
}
|