| AVR Z-LINKŪ |

# HEXRecord Class Reference

`#include <hexfile.h>`

## Detailed Description

This class contains one HEX file record, i.e. one text line of the file.

Definition at line 58 of file hexfile.h.

## Public Member Functions
void | Add (std::vector< byte > data)
void | Add (byte data)
size_t | GetByteCount () const
| HEXRecord (unsigned long address)
| HEXRecord ()
void | Print (std::ostream &os) const
void | SetAddress (unsigned long address)
| ~HEXRecord ()
## Private Attributes
unsigned long | m_address
std::vector< byte > | m_data

## Constructor & Destructor Documentation

HEXRecord::HEXRecord | ( |  | ) | `[inline]`

Default ctor. Must use SetAddress later.

Definition at line 66 of file hexfile.h.

    00066 : m_address( 0 ) {}

HEXRecord::HEXRecord | ( | unsigned long | address | ) | `[inline, explicit]`

Ctor initializing the address.

Definition at line 68 of file hexfile.h.

    00068 : m_address( address ) {}

HEXRecord::~HEXRecord | ( |  | ) | `[inline]`

Definition at line 69 of file hexfile.h.

    00069 {}

## Member Function Documentation

void HEXRecord::Add | ( | std::vector< byte > | data | ) |

Add set of data bytes to the end of the record.

Definition at line 68 of file hexfile.cpp.

References Add().

    00069 {
    00070         for( size_t idx = 0; idx < data.size(); ++idx ) {
    00071                 Add( data.at( idx ) );
    00072         }
    00073 }

Here is the call graph for this function:

void HEXRecord::Add | ( | byte | data | ) |

Add one data byte to the end of the record.

Definition at line 57 of file hexfile.cpp.

References m_data.

Referenced by Add(), and operator<<().

    00058 {
    00059         if( data > 255 ) {
    00060                 throw std::runtime_error( "Data larger than 255" );
    00061         }
    00062
    00063         m_data.push_back( data );
    00064 }

size_t HEXRecord::GetByteCount | ( |  | ) | const`[inline]`

Get number of bytes currently in this record.

Definition at line 78 of file hexfile.h.

References m_data.

Referenced by HEXFile::Add(), and Print().

    00078 { return m_data.size(); }

void HEXRecord::Print | ( | std::ostream & | os | ) | const

Print this record as a valid HEX file record to an output stream.

Definition at line 77 of file hexfile.cpp.

References GetByteCount(), HEXDATARECORDTYPE, m_address, and m_data.

Referenced by operator<<().

    00078 {
    00079         if( GetByteCount() > 255 ) {
    00080                 throw std::runtime_error( "HEX record have more than 255 data bytes" );
    00081         }
    00082
    00083         if( m_address > 65535 ) {
    00084                 throw std::runtime_error( "HEX record base address exceeds 16 bits" );
    00085         }
    00086
    00087         if( m_address + GetByteCount() > 65536 ) {
    00088                 throw std::runtime_error( "HEX record data crosses segment boundary" );
    00089         }
    00090
    00091         byte checksum = 0;
    00092         checksum += GetByteCount(); // First byte in record.
    00093         checksum += m_address & 0xff; // Second byte in record.
    00094         checksum += (m_address >> 8) & 0xff; // Third byte in record.
    00095         checksum += HEXDATARECORDTYPE; // Fourth byte in record.
    00096
    00097         os << ":" << std::setfill('0') << std::hex
    00098                 << std::setw(2) << GetByteCount()
    00099                 << std::setw(2) << ((m_address >> 8) & 0xff)
    00100                 << std::setw(2) << (m_address & 0xff)
    00101                 << std::setw(2) << HEXDATARECORDTYPE;
    00102
    00103         for( size_t idx = 0; idx < GetByteCount(); ++idx ) {
    00104                 byte data = m_data.at( idx );
    00105                 os << std::setw(2) << data;
    00106                 checksum += data;
    00107         }
    00108
    00109         os << std::setw(2) << ((-checksum) & 0xff) // 2's complement of total sum.
    00110                 << std::endl;
    00111 }

Here is the call graph for this function:

void HEXRecord::SetAddress | ( | unsigned long | address | ) | `[inline]`

Set the start address for this record.

Definition at line 76 of file hexfile.h.

References m_address.

    00076 { m_address = address; }

## Field Documentation

unsigned long HEXRecord::m_address`[private]`

Start address.

Definition at line 61 of file hexfile.h.

Referenced by Print(), and SetAddress().

std::vector< byte > HEXRecord::m_data`[private]`

Data bytes.

Definition at line 62 of file hexfile.h.

Referenced by Add(), GetByteCount(), and Print().

@DOC_TITLE@