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.

111 lines
3.3 KiB

  1. #include <windows.h>
  2. #include <iostream>
  3. #include <set>
  4. #include "logger.hpp"
  5. #include "zcsv.hpp"
  6. using namespace iflytop;
  7. using namespace std;
  8. #define TAG "Main"
  9. #define TRY_INSERT_DEFALUT_VALUE(key, value) \
  10. if (zcsv->getData(key, i).empty() || zcsv->getData(key, i) == "NA") { \
  11. file << "define_attribute {p:" << PORT << "} {" << key << "} {" << value << "}" << endl; \
  12. }
  13. char projFileName_cstr[128] = {0};
  14. int domain(int argc, char const* argv[]) {
  15. // 搜索当前文件夹,找到*.pds文件
  16. WIN32_FIND_DATAA FindFileData;
  17. HANDLE hFind = FindFirstFileA("*.pds", &FindFileData);
  18. if (hFind == INVALID_HANDLE_VALUE) {
  19. ZLOGE(TAG, "find file failed");
  20. return -1;
  21. }
  22. strcpy(projFileName_cstr, FindFileData.cFileName);
  23. FindClose(hFind);
  24. string projFileName = projFileName_cstr;
  25. string projectName;
  26. string pinCsvFileName;
  27. string outputFileName;
  28. size_t pos = projFileName.find_last_of(".");
  29. if (pos == string::npos) {
  30. projectName = projFileName;
  31. } else {
  32. projectName = projFileName.substr(0, pos);
  33. }
  34. pinCsvFileName = projectName + ".csv";
  35. outputFileName = projectName + ".fdc";
  36. ZLOGI(TAG, "input file:%s", pinCsvFileName.c_str());
  37. shared_ptr<ZCSV> zcsv = make_shared<ZCSV>();
  38. bool suc = zcsv->parseCSV(pinCsvFileName.c_str());
  39. if (!suc) {
  40. ZLOGE(TAG, "parse csv failed");
  41. return -1;
  42. }
  43. map<string, int> colNum;
  44. auto keys = zcsv->getRowKeys();
  45. ofstream file;
  46. file.open(outputFileName, ios::out | ios::trunc);
  47. int maxRow = zcsv->maxRowNum();
  48. for (uint32_t i = 1; i <= maxRow; i++) {
  49. // 检查必要数值
  50. string PORT = zcsv->getData("PORT", i);
  51. string PAP_IO_LOC = zcsv->getData("PAP_IO_LOC", i);
  52. string PAP_IO_DIRECTION = zcsv->getData("PAP_IO_DIRECTION", i);
  53. if (PORT.empty() || PORT == "NA") {
  54. ZLOGE(TAG, "line %d name is empty, skip", i + 1);
  55. continue;
  56. }
  57. if (PAP_IO_LOC.empty() || PAP_IO_LOC == "NA") {
  58. ZLOGE(TAG, "line %d PAP_IO_LOC is empty, skip", i + 1);
  59. continue;
  60. }
  61. if (PAP_IO_DIRECTION.empty()) {
  62. ZLOGE(TAG, "error!!!,line %d PAP_IO_DIRECTION is empty", i + 1);
  63. return -1;
  64. }
  65. // 插入数值
  66. vector<string> keys = zcsv->getRowKeys();
  67. for (auto& key : keys) {
  68. if (key == "PORT") continue;
  69. if (zcsv->getData(key, i).empty()) continue;
  70. if (zcsv->getData(key, i) == "NA") continue;
  71. file << "define_attribute {p:" << PORT << "} {" << key << "} {" << zcsv->getData(key, i) << "}" << endl;
  72. }
  73. // // 尝试插入默认值
  74. if (PAP_IO_DIRECTION == "INPUT") {
  75. TRY_INSERT_DEFALUT_VALUE("PAP_IO_VCCIO", "3.3");
  76. TRY_INSERT_DEFALUT_VALUE("PAP_IO_STANDARD", "LVCMOS33");
  77. } else if (PAP_IO_DIRECTION == "OUTPUT") {
  78. TRY_INSERT_DEFALUT_VALUE("PAP_IO_VCCIO", "3.3");
  79. TRY_INSERT_DEFALUT_VALUE("PAP_IO_STANDARD", "LVCMOS33");
  80. TRY_INSERT_DEFALUT_VALUE("PAP_IO_DRIVE", "4");
  81. TRY_INSERT_DEFALUT_VALUE("PAP_IO_SLEW", "SLOW");
  82. } else {
  83. ZLOGE(TAG, "error!!!,line %d PAP_IO_DIRECTION (%s) is error", i + 1, PAP_IO_DIRECTION.c_str());
  84. return -1;
  85. }
  86. }
  87. file.close();
  88. ZLOGI(TAG, "generator %s success", outputFileName.c_str());
  89. return 0;
  90. }
  91. int main(int argc, char const* argv[]) {
  92. domain(argc, argv);
  93. Sleep(3000);
  94. }