|
| 1 | + |
| 2 | +#include <iostream> |
| 3 | +#include <fstream> |
| 4 | +#include <filesystem> |
| 5 | +#include "parser/dbcscanner.h" |
| 6 | +#include "codegen/c-main-generator.h" |
| 7 | +#include "codegen/c-util-generator.h" |
| 8 | +#include "codegen/fs-creator.h" |
| 9 | + |
| 10 | +#define GEN_UTIL_CODE |
| 11 | + |
| 12 | +DbcScanner* scanner; |
| 13 | +CiMainGenerator* cigen; |
| 14 | +CiUtilGenerator* ciugen; |
| 15 | +FsCreator* fscreator; |
| 16 | + |
| 17 | +std::string source_files_out_path; |
| 18 | +std::string dbc_file_path; |
| 19 | +std::string dbc_driver_name; |
| 20 | + |
| 21 | +int main(int argc, char* argv[]) |
| 22 | +{ |
| 23 | + scanner = new DbcScanner; |
| 24 | + cigen = new CiMainGenerator; |
| 25 | + ciugen = new CiUtilGenerator; |
| 26 | + fscreator = new FsCreator; |
| 27 | + |
| 28 | + bool numberLines = false; // Default is no line numbers. |
| 29 | + |
| 30 | + if (argc == 4) |
| 31 | + numberLines = true; |
| 32 | + |
| 33 | + if (numberLines) |
| 34 | + { |
| 35 | + std::ifstream reader; |
| 36 | + // copy dbc file name to string variable |
| 37 | + dbc_file_path = argv[1]; |
| 38 | + source_files_out_path = argv[2]; |
| 39 | + dbc_driver_name = argv[3]; |
| 40 | + |
| 41 | + std::cout << "dbc file : " << argv[1] << std::endl; |
| 42 | + std::cout << "gen path : " << argv[2] << std::endl; |
| 43 | + std::cout << "drv name : " << argv[3] << std::endl; |
| 44 | + |
| 45 | + if (std::filesystem::exists(dbc_file_path) == false) |
| 46 | + { |
| 47 | + std::cout << "DBC file is not exists!" << std::endl; |
| 48 | + return -1; |
| 49 | + } |
| 50 | + |
| 51 | + reader.open(dbc_file_path); |
| 52 | + |
| 53 | + std::istream& s = reader; |
| 54 | + |
| 55 | + scanner->TrimDbcText(s); |
| 56 | + |
| 57 | + std::string info("this is test"); |
| 58 | + |
| 59 | + auto ret = fscreator->PrepareDirectory(dbc_driver_name.c_str(), source_files_out_path.c_str(), true, info); |
| 60 | + |
| 61 | + if (ret) |
| 62 | + { |
| 63 | + cigen->Generate(scanner->dblist, fscreator->FS); |
| 64 | + } |
| 65 | + else |
| 66 | + { |
| 67 | + std::cout << "One or both are invalid\n"; |
| 68 | + } |
| 69 | + |
| 70 | +#if defined (GEN_UTIL_CODE) |
| 71 | + |
| 72 | + |
| 73 | + // test utility generation |
| 74 | + |
| 75 | + ret = fscreator->PrepareDirectory(dbc_driver_name.c_str() , (source_files_out_path).c_str(), true, info); |
| 76 | + |
| 77 | + MsgsClassification groups; |
| 78 | + |
| 79 | + for (size_t i = 0; i < scanner->dblist.msgs.size(); i++) |
| 80 | + { |
| 81 | + groups.Rx.push_back(scanner->dblist.msgs[i]->MsgID); |
| 82 | + } |
| 83 | + |
| 84 | + if (ret) |
| 85 | + { |
| 86 | + ciugen->Generate(scanner->dblist, fscreator->FS, groups, dbc_driver_name); |
| 87 | + } |
| 88 | + |
| 89 | +#endif |
| 90 | + |
| 91 | + } |
| 92 | + else |
| 93 | + { |
| 94 | + std::cout << "Argument list is bad." << std::endl; |
| 95 | + } |
| 96 | + |
| 97 | + std::cout << "Finished... Press any key." << std::endl; |
| 98 | +} |
0 commit comments