| Remote Access Control |

# 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 59 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 67 of file hexfile.h.

    00067 : m_address( 0 ) {}

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

Ctor initializing the address.

Definition at line 69 of file hexfile.h.

    00069 : m_address( address ) {}

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

Definition at line 70 of file hexfile.h.

    00070 {}

## Member Function Documentation

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

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

Definition at line 69 of file hexfile.cpp.

References Add().

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

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 58 of file hexfile.cpp.

References m_data.

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

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

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

Get number of bytes currently in this record.

Definition at line 79 of file hexfile.h.

References m_data.

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

    00079 { 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 78 of file hexfile.cpp.

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

Referenced by operator<<().

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

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 77 of file hexfile.h.

References m_address.

    00077 { m_address = address; }

## Field Documentation

unsigned long HEXRecord::m_address`[private]`

Start address.

Definition at line 62 of file hexfile.h.

Referenced by Print(), and SetAddress().

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

Data bytes.

Definition at line 63 of file hexfile.h.

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

@DOC_TITLE@