main.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // crclibtest.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
  2. //
  3. #include <iostream>
  4. #include <map>
  5. #include "crc_interface.h"
  6. using namespace std;
  7. std::map<std::string, std::string> charPtrToMap(char*** ptr, int n) {
  8. std::map<std::string, std::string> result;
  9. for (int i = 0; i < n; i++) {
  10. char* key = ptr[i][0];
  11. char* value = ptr[i][1];
  12. result[key] = value;
  13. }
  14. return result;
  15. }
  16. void freeCharPtr(char*** ptr, int n) {
  17. for (int i = 0; i < n; i++) {
  18. delete[] ptr[i][0];
  19. delete[] ptr[i][1];
  20. delete[] ptr[i];
  21. }
  22. delete[] ptr;
  23. }
  24. int main()
  25. {
  26. //输入SCD路径
  27. string scdPath;
  28. cout << "Please select the action you want to take:" << endl;
  29. cout << "1. Calculate the CRC of all IEDs and the CRC of SCDs" << endl;
  30. cout << "2. Calculate the CRC of the specified IED" << endl;
  31. cout << "3. Export the CCD of the specified IED" << endl;
  32. cout << "Please enter the action number(1-3):" << endl;
  33. int iActType = -1;
  34. cin >> iActType;
  35. if (iActType == 1)
  36. {
  37. string scdPath;
  38. cout << "Please input the path of SCD file:" << endl;
  39. cin >> scdPath;
  40. cout << "Please wait.." << endl;
  41. int iCalcSize;
  42. char*** pszCrcMap;
  43. const char* pszSCDCRC = calcALLIEDCRC(&pszCrcMap, scdPath.c_str(), iCalcSize);
  44. cout << "SCD CRC:" << pszSCDCRC << endl;
  45. std::map<std::string, std::string> crcMap = charPtrToMap(pszCrcMap, iCalcSize);
  46. for (auto it = crcMap.begin(); it != crcMap.end(); it++) {
  47. cout << it->first << ":" << it->second << endl;
  48. }
  49. cout << "The CRC of SCD is:" << pszSCDCRC << endl;
  50. freeCharPtr(pszCrcMap, iCalcSize);
  51. delete[] pszSCDCRC;
  52. }
  53. else if (iActType == 2)
  54. {
  55. string scdPath;
  56. cout << "Please input the path of SCD file:" << endl;
  57. cin >> scdPath;
  58. string iedName;
  59. cout << "Please input the name of IED:" << endl;
  60. cin >> iedName;
  61. const char* crc = calcIEDCRC(scdPath.c_str(), iedName.c_str());
  62. cout << "The CRC of IED is:" << crc << endl;
  63. delete[] crc;
  64. }
  65. else if (iActType == 3)
  66. {
  67. string scdPath;
  68. cout << "Please input the path of SCD file:" << endl;
  69. cin >> scdPath;
  70. string iedName;
  71. cout << "Please input the name of IED:" << endl;
  72. cin >> iedName;
  73. string exportPath;
  74. cout << "Please input the path of export directory:" << endl;
  75. cin >> exportPath;
  76. exportCCD(scdPath.c_str(), iedName.c_str(), exportPath.c_str());
  77. }
  78. else
  79. {
  80. cout << "Please input the correct number!" << endl;
  81. }
  82. system("pause");
  83. return 0;
  84. }