Subversion Repositories HomeAutomation

Rev

Rev 1987 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. /*
  2.  *
  3.  *  Copyright (C) 2010  Mattias Runge
  4.  *
  5.  *  This program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2 of the License, or
  8.  *  (at your option) any later version.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License along
  16.  *  with this program; if not, write to the Free Software Foundation, Inc.,
  17.  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18.  *
  19.  */
  20.  
  21. #ifndef CONTROL_CODE_H
  22. #define CONTROL_CODE_H
  23.  
  24. #include <string>
  25.  
  26. #include <boost/shared_ptr.hpp>
  27.  
  28. #include "common/Byteset.h"
  29.  
  30. namespace atom {
  31. namespace control {
  32.  
  33. class Code
  34. {
  35. public:
  36.   typedef boost::shared_ptr<Code> Pointer;
  37.  
  38.   Code();
  39.   virtual ~Code();
  40.  
  41.   bool LoadIntelHexFile(std::string filename);
  42.   bool ParseIntelHex(std::string data);
  43.  
  44.   unsigned int GetAddressLower();
  45.   unsigned int GetAddressUpper();
  46.   unsigned char GetByte(unsigned int address);
  47.   unsigned int GetChecksum();
  48.   unsigned int GetLength();
  49.   bool IsValid();
  50.   void Reset(bool fill);
  51.   void AddByte(unsigned char byte);
  52.  
  53. private:
  54.   common::Byteset data_;
  55.   bool            is_valid_;
  56.   unsigned int    address_lower_;
  57.   unsigned int    address_upper_;
  58.   unsigned int    checksum_;
  59.  
  60.   void CalculateChecksum();
  61. };
  62.  
  63. }; // namespace control
  64. }; // namespace atom
  65.  
  66. #endif // CONTROL_CODE_H
  67.