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