-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a simple way to read IOP files to assist with testing. Feel free to use this in applications that consume this library to easily read an IOP file, but it may not be ideal for an embedded platform with very limted RAM, as it will store the entire IOP file content in RAM. If you need to read an object pool in segments due to RAM restrictions, you should instead use CAN data chunk callbacks in concert with your own custom driver for getting pool data. If there is demand for it, I may add an interface for that in the future.
- Loading branch information
Showing
3 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//================================================================================================ | ||
/// @file iop_file_interface.hpp | ||
/// | ||
/// @brief A class that manages reading IOP files | ||
/// @author Adrian Del Grosso | ||
/// | ||
/// @copyright 2022 Adrian Del Grosso | ||
//================================================================================================ | ||
|
||
#ifndef IOP_FILE_INTERFACE_HPP | ||
#define IOP_FILE_INTERFACE_HPP | ||
|
||
#include <vector> | ||
#include <cstdint> | ||
#include <string> | ||
|
||
namespace isobus | ||
{ | ||
//================================================================================================ | ||
/// @class IOPFileInterface | ||
/// | ||
/// @brief A class that manages reading IOP files | ||
/// @details IOP files are the standard format for ISOBUS object pools. This class will read | ||
/// an IOP file, and return a vector that represents the object pool stored in the file. | ||
//================================================================================================ | ||
class IOPFileInterface | ||
{ | ||
public: | ||
/// @brief Reads an IOP file given a file name/path | ||
/// @param[in] filename A string filepath for the IOP file to read | ||
/// @returns A vector with an object pool in it, or an empty vector if reading failed | ||
static std::vector<std::uint8_t> read_iop_file(const std::string &filename); | ||
}; | ||
} | ||
|
||
#endif // IOP_FILE_INTERFACE_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//================================================================================================ | ||
/// @file iop_file_interface.cpp | ||
/// | ||
/// @brief Implementation of class that manages reading IOP files | ||
/// @author Adrian Del Grosso | ||
/// | ||
/// @copyright 2022 Adrian Del Grosso | ||
//================================================================================================ | ||
#include "iop_file_interface.hpp" | ||
|
||
#include <fstream> | ||
#include <iterator> | ||
|
||
namespace isobus | ||
{ | ||
std::vector<std::uint8_t> IOPFileInterface::read_iop_file(const std::string &filename) | ||
{ | ||
std::vector<std::uint8_t> retVal; | ||
std::streampos fileSize; | ||
|
||
std::ifstream file(filename, std::ios::binary); | ||
|
||
if (file.is_open()) | ||
{ | ||
// Ignore newlines | ||
file.unsetf(std::ios::skipws); | ||
|
||
file.seekg(0, std::ios::end); | ||
fileSize = file.tellg(); | ||
file.seekg(0, std::ios::beg); | ||
|
||
retVal.reserve(fileSize); | ||
|
||
// Read in the data | ||
retVal.insert(retVal.begin(), std::istream_iterator<std::uint8_t>(file), std::istream_iterator<std::uint8_t>()); | ||
} | ||
return retVal; | ||
} | ||
} |