1 | /*
|
---|
2 | * TOPPERS Software
|
---|
3 | * Toyohashi Open Platform for Embedded Real-Time Systems
|
---|
4 | *
|
---|
5 | * Copyright (C) 2005-2008 by TAKAGI Nobuhisa
|
---|
6 | *
|
---|
7 | * ãLì ÒÍCȺÌ(1)`(4)Ìðð½·êÉÀèC{\tgEF
|
---|
8 | * Ai{\tgEFAðüϵ½àÌðÜÞDȺ¯¶jðgpE¡»Eü
|
---|
9 | * ÏEÄzziȺCpÆÄÔj·é±Æð³Åø·éD
|
---|
10 | * (1) {\tgEFAð\[XR[hÌ`Åp·éêÉÍCãLÌì
|
---|
11 | * \¦C±Ìpð¨æÑºLÌ³ÛØKèªC»ÌÜÜÌ`Å\[
|
---|
12 | * XR[hÉÜÜêĢ鱯D
|
---|
13 | * (2) {\tgEFAðCCu`®ÈÇC¼Ì\tgEFAJÉg
|
---|
14 | * pÅ«é`ÅÄzz·éêÉÍCÄzzɺ¤hL
|
---|
15 | gip
|
---|
16 | * Ò}j
|
---|
17 | AÈÇjÉCãLÌì \¦C±Ìpð¨æÑºL
|
---|
18 | * Ì³ÛØKèðfÚ·é±ÆD
|
---|
19 | * (3) {\tgEFAðC@íÉgÝÞÈÇC¼Ì\tgEFAJÉg
|
---|
20 | * pūȢ`ÅÄzz·éêÉÍCÌ¢¸ê©Ìðð½·±
|
---|
21 | * ÆD
|
---|
22 | * (a) Äzzɺ¤hL
|
---|
23 | gipÒ}j
|
---|
24 | AÈÇjÉCãLÌ
|
---|
25 | * ì \¦C±Ìpð¨æÑºLÌ³ÛØKèðfÚ·é±ÆD
|
---|
26 | * (b) ÄzzÌ`ÔðCÊÉèßéû@ÉæÁÄCTOPPERSvWFNgÉ
|
---|
27 | * ñ·é±ÆD
|
---|
28 | * (4) {\tgEFAÌpÉæè¼ÚIܽÍÔÚIɶ¶é¢©Èé¹
|
---|
29 | * Q©çàCãLì Ò¨æÑTOPPERSvWFNgðÆÓ·é±ÆD
|
---|
30 | * ܽC{\tgEFAÌ[UܽÍGh[U©çÌ¢©Èé
|
---|
31 | * RÉîÿ©çàCãLì Ò¨æÑTOPPERSvWFNgð
|
---|
32 | * ÆÓ·é±ÆD
|
---|
33 | *
|
---|
34 | * {\tgEFAÍC³ÛØÅñ³êÄ¢éàÌÅ éDãLì Ò¨
|
---|
35 | * æÑTOPPERSvWFNgÍC{\tgEFAÉÖµÄCÁèÌgpÚI
|
---|
36 | * ÉηéK«àÜßÄC¢©ÈéÛØàsíÈ¢DܽC{\tgEF
|
---|
37 | * AÌpÉæè¼ÚIܽÍÔÚIɶ¶½¢©Èé¹QÉÖµÄàC»
|
---|
38 | * ÌÓCðíÈ¢D
|
---|
39 | *
|
---|
40 | */
|
---|
41 |
|
---|
42 | /*!
|
---|
43 | * \file toppers/s_record.hpp
|
---|
44 | * \brief g[SR[h𵤽ßÌé¾è`
|
---|
45 | *
|
---|
46 | * ±Ìt@CÅè`³êéNX
|
---|
47 | * \code
|
---|
48 | * class s_record;
|
---|
49 | * struct s_record::record;
|
---|
50 | * class s_record::format_error;
|
---|
51 | * class s_record::checksum_error;
|
---|
52 | * \endcode
|
---|
53 | */
|
---|
54 | #ifndef TOPPERS_S_RECORD_HPP_
|
---|
55 | #define TOPPERS_S_RECORD_HPP_
|
---|
56 |
|
---|
57 | #include "toppers/config.hpp"
|
---|
58 | #include <iosfwd>
|
---|
59 | #include <string>
|
---|
60 | #include <vector>
|
---|
61 | #include <utility>
|
---|
62 | #include <stdexcept>
|
---|
63 | #include <boost/cstdint.hpp>
|
---|
64 |
|
---|
65 | namespace toppers
|
---|
66 | {
|
---|
67 |
|
---|
68 | /*!
|
---|
69 | * \class s_record s_record.hpp "toppers/s_recored.hpp"
|
---|
70 | * \brief g[SR[h𵤽ßÌNX
|
---|
71 | *
|
---|
72 | * \sa s_record::record, s_record::format_error, s_record::checksum_error
|
---|
73 | */
|
---|
74 | class s_record
|
---|
75 | {
|
---|
76 | public:
|
---|
77 | typedef std::pair< unsigned long, std::vector< unsigned char > > value_type;
|
---|
78 | typedef std::vector< value_type >::size_type size_type;
|
---|
79 |
|
---|
80 | /*!
|
---|
81 | * \struct record s_record.hpp "toppers/s_record.hpp"
|
---|
82 | * \brief SR[hÌPsR[hîñði[·é½ßÌ\¢Ì
|
---|
83 | */
|
---|
84 | struct record
|
---|
85 | {
|
---|
86 | int type;
|
---|
87 | int length;
|
---|
88 | unsigned long address;
|
---|
89 | std::vector< unsigned char > data;
|
---|
90 | int checksum;
|
---|
91 | };
|
---|
92 |
|
---|
93 | /*!
|
---|
94 | * \class data_error s_record.hpp "toppers/s_record.hpp"
|
---|
95 | * \brief SR[hÌf[^G[áONX
|
---|
96 | */
|
---|
97 | class data_error : public std::runtime_error
|
---|
98 | {
|
---|
99 | public:
|
---|
100 | data_error() : std::runtime_error( "S-record data error" ) {}
|
---|
101 | };
|
---|
102 | /*!
|
---|
103 | * \class format_error s_record.hpp "toppers/s_record.hpp"
|
---|
104 | * \brief SR[hÌ®G[áONX
|
---|
105 | */
|
---|
106 | class format_error : public std::runtime_error
|
---|
107 | {
|
---|
108 | public:
|
---|
109 | format_error() : std::runtime_error( "S-record format error" ) {}
|
---|
110 | };
|
---|
111 | /*!
|
---|
112 | * \class checksum_error s_record.hpp "toppers/s_record.hpp"
|
---|
113 | * \brief SR[hÌ`FbNTG[áONX
|
---|
114 | */
|
---|
115 | class checksum_error : public std::runtime_error
|
---|
116 | {
|
---|
117 | public:
|
---|
118 | checksum_error() : std::runtime_error( "S-record checksum error" ) {}
|
---|
119 | };
|
---|
120 |
|
---|
121 | /*!
|
---|
122 | * \brief ftHgRXgN^
|
---|
123 | */
|
---|
124 | s_record() : cache_( data_.end() ) {}
|
---|
125 | /*!
|
---|
126 | * \brief RXgN^
|
---|
127 | * \param istr üÍXg[
|
---|
128 | *
|
---|
129 | * s_record NX̶¬Æ¯Éf[^Ì[hðs¢Ü·B
|
---|
130 | */
|
---|
131 | explicit s_record( std::istream& istr ) { load( istr ); }
|
---|
132 | /*!
|
---|
133 | * \brief fXgN^
|
---|
134 | */
|
---|
135 | virtual ~s_record() {}
|
---|
136 |
|
---|
137 | void load( std::istream& istr );
|
---|
138 | int operator[]( size_type address ) const;
|
---|
139 | boost::uintmax_t get_value( std::size_t base, std::size_t size, bool little_endian ) const;
|
---|
140 | unsigned long lower_bound() const;
|
---|
141 | unsigned long upper_bound() const;
|
---|
142 | protected:
|
---|
143 | static record const read_record( std::string const& rec_buf );
|
---|
144 | static int xdigit_to_int( int ch );
|
---|
145 | private:
|
---|
146 | std::vector< value_type > data_;
|
---|
147 | mutable std::vector< value_type >::const_iterator cache_;
|
---|
148 | };
|
---|
149 |
|
---|
150 | }
|
---|
151 |
|
---|
152 | #endif // ! TOPPERS_S_RECORD_HPP_
|
---|