HexFile.h
Go to the documentation of this file.
00001 /*
00002         Aseba - an event-based framework for distributed robot control
00003         Copyright (C) 2007--2012:
00004                 Stephane Magnenat <stephane at magnenat dot net>
00005                 (http://stephane.magnenat.net)
00006                 and other contributors, see authors.txt for details
00007         
00008         This program is free software: you can redistribute it and/or modify
00009         it under the terms of the GNU Lesser General Public License as published
00010         by the Free Software Foundation, version 3 of the License.
00011         
00012         This program is distributed in the hope that it will be useful,
00013         but WITHOUT ANY WARRANTY; without even the implied warranty of
00014         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015         GNU Lesser General Public License for more details.
00016         
00017         You should have received a copy of the GNU Lesser General Public License
00018         along with this program. If not, see <http://www.gnu.org/licenses/>.
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 


aseba
Author(s): Stéphane Magnenat
autogenerated on Sun Oct 5 2014 23:46:38