rawParser: simple class to read raw binary content with an optional reverse order
This commit is contained in:
parent
381c67de00
commit
800ad1ce2c
|
|
@ -45,6 +45,7 @@ set(OPENFPGALOADER_SOURCE
|
||||||
src/anlogicCable.cpp
|
src/anlogicCable.cpp
|
||||||
src/dirtyJtag.cpp
|
src/dirtyJtag.cpp
|
||||||
src/spiFlash.cpp
|
src/spiFlash.cpp
|
||||||
|
src/rawParser.cpp
|
||||||
src/usbBlaster.cpp
|
src/usbBlaster.cpp
|
||||||
src/epcq.cpp
|
src/epcq.cpp
|
||||||
src/svf_jtag.cpp
|
src/svf_jtag.cpp
|
||||||
|
|
@ -77,6 +78,7 @@ set(OPENFPGALOADER_HEADERS
|
||||||
src/cxxopts.hpp
|
src/cxxopts.hpp
|
||||||
src/dirtyJtag.hpp
|
src/dirtyJtag.hpp
|
||||||
src/progressBar.hpp
|
src/progressBar.hpp
|
||||||
|
src/rawParser.hpp
|
||||||
src/usbBlaster.hpp
|
src/usbBlaster.hpp
|
||||||
src/bitparser.hpp
|
src/bitparser.hpp
|
||||||
src/ftdiJtagBitbang.hpp
|
src/ftdiJtagBitbang.hpp
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>
|
||||||
|
*
|
||||||
|
* 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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>
|
||||||
|
*
|
||||||
|
* 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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SRC_RAWPARSER_HPP_
|
||||||
|
#define SRC_RAWPARSER_HPP_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#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_
|
||||||
|
|
||||||
Loading…
Reference in New Issue