You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

89 lines
2.5 KiB

#include <windows.h>
#include <iostream>
#include <set>
#include "logger.hpp"
#include "zcsv.hpp"
using namespace iflytop;
using namespace std;
#define TAG "Main"
#define TRY_INSERT_DEFALUT_VALUE(key, value) \
if (zcsv->getData(key, i).empty() || zcsv->getData(key, i) == "NA") { \
file << "define_attribute {p:" << PORT << "} {" << key << "} {" << value << "}" << endl; \
}
char projFileName_cstr[128] = {0};
int domain(int argc, char const* argv[]) {
// // 搜索当前文件夹,找到*.pds文件
WIN32_FIND_DATAA FindFileData;
HANDLE hFind = FindFirstFileA("*.pds", &FindFileData);
if (hFind == INVALID_HANDLE_VALUE) {
ZLOGE(TAG, "find file failed");
return -1;
}
strcpy(projFileName_cstr, FindFileData.cFileName);
FindClose(hFind);
string projFileName = projFileName_cstr;
string projectName;
string pinCsvFileName;
string fdcFileName;
size_t pos = projFileName.find_last_of(".");
if (pos == string::npos) {
projectName = projFileName;
} else {
projectName = projFileName.substr(0, pos);
}
pinCsvFileName = projectName + ".csv";
fdcFileName = projectName + ".fdc";
ZLOGI(TAG, "fdc file:%s", fdcFileName.c_str());
// 打开fdc文件,并逐行解析下面字符串,
// 如下解析出如果是define_attribute,则 rowName:ex_clk, colName:PAP_IO_DIRECTION, data:INPUT
// define_attribute {p:ex_clk} {PAP_IO_DIRECTION} {INPUT}
shared_ptr<ZCSV> zcsv = make_shared<ZCSV>();
fstream file(fdcFileName, ios::in);
if (!file.is_open()) {
ZLOGE(TAG, "open fdc file failed");
return -1;
}
string line;
while (getline(file, line)) {
if (line.find("define_attribute") != string::npos) {
string rowName;
string colName;
string data;
size_t pos1 = line.find("{p:");
size_t pos2 = line.find("}", pos1);
rowName = line.substr(pos1 + 3, pos2 - pos1 - 3);
pos1 = line.find("{", pos2);
pos2 = line.find("}", pos1);
colName = line.substr(pos1 + 1, pos2 - pos1 - 1);
pos1 = line.find("{", pos2);
pos2 = line.find("}", pos1);
data = line.substr(pos1 + 1, pos2 - pos1 - 1);
ZLOGI(TAG, "rowName:%s, colName:%s, data:%s", rowName.c_str(), colName.c_str(), data.c_str());
zcsv->setData(rowName, colName, data);
}
}
zcsv->setdata(0, 0, "PORT");
zcsv->dumpCSV(pinCsvFileName);
ZLOGI(TAG, "fdc2csv success...");
return 0;
}
int main(int argc, char const* argv[]) {
domain(argc, argv);
Sleep(3000);
}