34 #include <QtCore/QTextStream>
41 : addressSizeId( Bits32Id )
45 const char ByteArrayIHexStreamEncoder::hexDigits[16] =
46 {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F' };
49 void ByteArrayIHexStreamEncoder::streamLine( QTextStream& textStream,
50 const unsigned char* line )
53 unsigned char checksum = 0;
55 textStream << startCode;
57 const uint length = byteCountLineSize + addressLineSize + recordTypeLineSize + line[0];
58 for( uint i = 0; i < length; ++i )
60 const unsigned char byte = line[i];
61 textStream << hexValueOfNibble( byte >> 4 )
62 << hexValueOfNibble( byte );
66 checksum = (checksum ^ 0xFF) + 1;
67 textStream << hexValueOfNibble( checksum >> 4 )
68 << hexValueOfNibble( checksum ) <<
'\n';
71 void ByteArrayIHexStreamEncoder::streamExtendedSegmentAddress( QTextStream& textStream,
73 quint16 upperSegmentBaseAddress )
75 static const int nullAddress = 0;
76 static const int upperSegmentBaseAddressSize = 2;
78 line[byteCountLineOffset] = upperSegmentBaseAddressSize;
79 writeBigEndian( &line[addressLineOffset], nullAddress, addressLineSize );
80 line[recordTypeLineOffset] = ExtendedSegmentAddressRecord;
81 line[dataLineOffset] = upperSegmentBaseAddress >> 8;
82 line[dataLineOffset+1] = upperSegmentBaseAddress;
84 streamLine( textStream, line );
87 void ByteArrayIHexStreamEncoder::streamExtendedLinearAddress( QTextStream& textStream,
89 quint16 upperLinearBaseAddress )
91 static const int nullAddress = 0;
92 static const int upperLinearBaseAddressSize = 2;
94 line[byteCountLineOffset] = upperLinearBaseAddressSize;
95 writeBigEndian( &line[addressLineOffset], nullAddress, addressLineSize );
96 line[recordTypeLineOffset] = ExtendedLinearAddressRecord;
97 line[dataLineOffset] = upperLinearBaseAddress >> 8;
98 line[dataLineOffset+1] = upperLinearBaseAddress;
100 streamLine( textStream, line );
103 void ByteArrayIHexStreamEncoder::streamEndOfFile( QTextStream& textStream,
105 quint16 startAddress )
107 static const int endOfFileByteCount = 0;
109 line[byteCountLineOffset] = endOfFileByteCount;
110 writeBigEndian( &line[addressLineOffset], startAddress, addressLineSize );
111 line[recordTypeLineOffset] = EndOfFileRecord;
113 streamLine( textStream, line );
127 Q_UNUSED( byteArrayView );
132 QTextStream textStream( device );
135 static const int maxDataPerLineCount = 255;
136 static const int maxLineLength =
137 maxDataPerLineCount + byteCountLineSize + addressLineSize + recordTypeLineSize;
144 const int lastLinePosition = layout.lastLinePosition( startCoord.line() );
145 const int dataPerLineCount = qMin( byteArrayView->
noOfBytesPerLine(), maxDataPerLineCount );
146 unsigned char line[maxLineLength];
147 unsigned char* lineData = &line[dataLineOffset];
149 const int firstDataEnd = lastLinePosition - startCoord.pos() + 1;
150 int nextUpperAddressChangeDataEnd = 0x10000 - (range.
start() & 0xFFFF);
152 int nextDataEnd = qMin( dataPerLineCount,
153 qMin(firstDataEnd,nextUpperAddressChangeDataEnd) );
158 const quint16 upperLinearBaseAddress = (range.
start() >> 16);
159 streamExtendedLinearAddress( textStream, line, upperLinearBaseAddress );
163 const quint16 upperSegmentBaseAddress = (range.
start() >> 4) & 0xF000;
164 streamExtendedSegmentAddress( textStream, line, upperSegmentBaseAddress );
167 while( i <= range.
end() )
174 if( d == nextDataEnd )
176 line[byteCountLineOffset] = d;
177 writeBigEndian( &line[addressLineOffset], lineOffset, addressLineSize );
178 line[recordTypeLineOffset] = DataRecord;
180 streamLine( textStream, line );
184 if( d == nextUpperAddressChangeDataEnd )
188 const quint16 upperLinearBaseAddress = (i >> 16);
189 streamExtendedLinearAddress( textStream, line, upperLinearBaseAddress );
193 const quint16 upperSegmentBaseAddress = (i >> 4) & 0xF000;
194 streamExtendedSegmentAddress( textStream, line, upperSegmentBaseAddress );
197 nextUpperAddressChangeDataEnd = 0x10000 - (i & 0xFFFF);
198 nextDataEnd = qMin( dataPerLineCount,
199 qMin(range.
end()-i+1, nextUpperAddressChangeDataEnd) );
205 streamEndOfFile( textStream, line );
virtual ~ByteArrayIHexStreamEncoder()
could it be useful to hide the data access behind an iterator? * class KDataBufferIterator { public: ...
int noOfBytesPerLine() const
a class which represents a coord in a 2-dim.
Okteta::Address firstLineOffset() const
IHexStreamEncoderSettings mSettings
AddressSizeId addressSizeId
the logical layout of a byte array table for a view
ByteArrayIHexStreamEncoder()
virtual Size size() const =0
IHexStreamEncoderSettings()
virtual Byte byte(Address offset) const =0
locates working range The idea behind is to tell buffer which range will be requested in the followin...
virtual bool encodeDataToStream(QIODevice *device, const ByteArrayView *byteArrayView, const Okteta::AbstractByteArrayModel *byteArrayModel, const Okteta::AddressRange &range)
Okteta::Address startOffset() const