Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef ASEBA_HEX_FILE_H
00022 #define ASEBA_HEX_FILE_H
00023
00024 #include "../common/types.h"
00025 #include "../utils/FormatableString.h"
00026 #include <map>
00027 #include <vector>
00028 #include <string>
00029
00030 namespace Aseba
00031 {
00032 class HexFile
00033 {
00034 public:
00035 struct Error
00036 {
00037 virtual ~Error () { }
00038 virtual std::string toString() const = 0;
00039 };
00040
00041 struct EarlyEOF : Error
00042 {
00043 int line;
00044
00045 EarlyEOF(int line) : line(line) { }
00046 virtual std::string toString() const;
00047 };
00048
00049 struct InvalidRecord : Error
00050 {
00051 int line;
00052
00053 InvalidRecord(int line) : line(line) { }
00054 virtual std::string toString() const;
00055 };
00056
00057 struct WrongCheckSum : Error
00058 {
00059 int line;
00060 uint8 recordCheckSum;
00061 uint8 computedCheckSum;
00062
00063 WrongCheckSum (int line, uint8 recordCheckSum, uint8 computedCheckSum) :
00064 line(line),
00065 recordCheckSum(recordCheckSum),
00066 computedCheckSum(computedCheckSum)
00067 { }
00068 virtual std::string toString() const;
00069 };
00070
00071 struct UnknownRecordType : Error
00072 {
00073 int line;
00074 uint8 recordType;
00075
00076 UnknownRecordType(int line, uint8 recordType) : line(line), recordType(recordType) { }
00077 virtual std::string toString() const;
00078 };
00079
00080 struct FileOpeningError : Error
00081 {
00082 std::string fileName;
00083
00084 FileOpeningError(const std::string &fileName) : fileName(fileName) { }
00085 virtual std::string toString() const;
00086 };
00087
00088 public:
00089 typedef std::map<uint32, std::vector<uint8> > ChunkMap;
00090 ChunkMap data;
00091
00092 public:
00093 void read(const std::string &fileName);
00094 void write(const std::string &fileName) const;
00095 void strip(unsigned pageSize);
00096
00097 protected:
00098 unsigned getUint4(std::istream &stream);
00099 unsigned getUint8(std::istream &stream);
00100 unsigned getUint16(std::istream &stream);
00101 void writeExtendedLinearAddressRecord(std::ofstream &stream, unsigned addr16) const;
00102 void writeData(std::ofstream &stream, unsigned addr16, unsigned count8, uint8 *data) const;
00103 };
00104 }
00105
00106 #endif
00107