diff --git a/CMakeLists.txt b/CMakeLists.txt index 0328c72..94f8fd0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,7 @@ set(OPENFPGALOADER_SOURCE src/anlogicCable.cpp src/dirtyJtag.cpp src/spiFlash.cpp + src/rawParser.cpp src/usbBlaster.cpp src/epcq.cpp src/svf_jtag.cpp @@ -77,6 +78,7 @@ set(OPENFPGALOADER_HEADERS src/cxxopts.hpp src/dirtyJtag.hpp src/progressBar.hpp + src/rawParser.hpp src/usbBlaster.hpp src/bitparser.hpp src/ftdiJtagBitbang.hpp diff --git a/src/rawParser.cpp b/src/rawParser.cpp new file mode 100644 index 0000000..ca8df44 --- /dev/null +++ b/src/rawParser.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2020 Gwenhael Goavec-Merou + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "configBitstreamParser.hpp" +#include "display.hpp" +#include "rawParser.hpp" + +using namespace std; + +RawParser::RawParser(const string &filename, bool reverseOrder): + ConfigBitstreamParser(filename, ConfigBitstreamParser::BIN_MODE, + false), _reverseOrder(reverseOrder) +{} + +int RawParser::parse() +{ + cout << "parsing " << _file_size << endl; + char *c = new char[_file_size]; + _fd.read(c, sizeof(char) * _file_size); + if (!_fd) { + printError("Error: fail to read " + _filename); + return EXIT_FAILURE; + } + cout << _bit_data << endl; + _bit_data.resize(_file_size); + for (int i = 0; i < _file_size; i++) + _bit_data[i] = (_reverseOrder) ? reverseByte(c[i]): c[i]; + _bit_length = _bit_data.size() * 8; + cout << "file length " << _bit_length << endl; + delete(c); + return EXIT_SUCCESS; +} diff --git a/src/rawParser.hpp b/src/rawParser.hpp new file mode 100644 index 0000000..9b618f5 --- /dev/null +++ b/src/rawParser.hpp @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2020 Gwenhael Goavec-Merou + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef SRC_RAWPARSER_HPP_ +#define SRC_RAWPARSER_HPP_ + +#include + +#include "configBitstreamParser.hpp" + +/*! + * \file rawParser + * \class RawParser + * \brief class used to read a raw data file + * \author Gwenhael Goavec-Merou + */ +class RawParser: public ConfigBitstreamParser { + public: + /*! + * \brief constructor + * \param[in] filename: raw file to read + * \param[in] reverseOrder: reverse each byte (LSB -> MSB, MSB -> LSB) + */ + RawParser(const std::string &filename, bool reverseOrder); + /*! + * \brief read full content of the file, fill the buffer + * \return EXIT_SUCCESS is file is fully read, EXIT_FAILURE otherwhise + */ + int parse() override; + + private: + bool _reverseOrder; /*!< tail if byte must be reversed */ +}; + +#endif // SRC_RAWPARSER_HPP_ +