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.
 
 
 

112 lines
3.3 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 outputFileName;
size_t pos = projFileName.find_last_of(".");
if (pos == string::npos) {
projectName = projFileName;
} else {
projectName = projFileName.substr(0, pos);
}
pinCsvFileName = projectName + ".csv";
outputFileName = projectName + ".fdc";
ZLOGI(TAG, "input file:%s", pinCsvFileName.c_str());
shared_ptr<ZCSV> zcsv = make_shared<ZCSV>();
bool suc = zcsv->parseCSV(pinCsvFileName.c_str());
if (!suc) {
ZLOGE(TAG, "parse csv failed");
return -1;
}
map<string, int> colNum;
auto keys = zcsv->getRowKeys();
ofstream file;
file.open(outputFileName, ios::out | ios::trunc);
int maxRow = zcsv->maxRowNum();
for (uint32_t i = 1; i <= maxRow; i++) {
// 检查必要数值
string PORT = zcsv->getData("PORT", i);
string PAP_IO_LOC = zcsv->getData("PAP_IO_LOC", i);
string PAP_IO_DIRECTION = zcsv->getData("PAP_IO_DIRECTION", i);
if (PORT.empty() || PORT == "NA") {
ZLOGE(TAG, "line %d name is empty, skip", i + 1);
continue;
}
if (PAP_IO_LOC.empty() || PAP_IO_LOC == "NA") {
ZLOGE(TAG, "line %d PAP_IO_LOC is empty, skip", i + 1);
continue;
}
if (PAP_IO_DIRECTION.empty()) {
ZLOGE(TAG, "error!!!,line %d PAP_IO_DIRECTION is empty", i + 1);
return -1;
}
// 插入数值
vector<string> keys = zcsv->getRowKeys();
for (auto& key : keys) {
if (key == "PORT") continue;
if (zcsv->getData(key, i).empty()) continue;
if (zcsv->getData(key, i) == "NA") continue;
file << "define_attribute {p:" << PORT << "} {" << key << "} {" << zcsv->getData(key, i) << "}" << endl;
}
// // 尝试插入默认值
if (PAP_IO_DIRECTION == "INPUT") {
TRY_INSERT_DEFALUT_VALUE("PAP_IO_VCCIO", "3.3");
TRY_INSERT_DEFALUT_VALUE("PAP_IO_STANDARD", "LVCMOS33");
} else if (PAP_IO_DIRECTION == "OUTPUT") {
TRY_INSERT_DEFALUT_VALUE("PAP_IO_VCCIO", "3.3");
TRY_INSERT_DEFALUT_VALUE("PAP_IO_STANDARD", "LVCMOS33");
TRY_INSERT_DEFALUT_VALUE("PAP_IO_DRIVE", "4");
TRY_INSERT_DEFALUT_VALUE("PAP_IO_SLEW", "SLOW");
} else {
ZLOGE(TAG, "error!!!,line %d PAP_IO_DIRECTION (%s) is error", i + 1, PAP_IO_DIRECTION.c_str());
return -1;
}
}
file.close();
ZLOGI(TAG, "generator %s success", outputFileName.c_str());
return 0;
}
int main(int argc, char const* argv[]) {
domain(argc, argv);
Sleep(3000);
}