ihex

package module
v0.0.0-...-bf28f22 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 5, 2018 License: MIT Imports: 5 Imported by: 3

README

PLEASE NOTE: I no longer actively maintain this project. Pull requests are welcome, but development has halted and issues are unlikely to gain a response.

ihex-go

An Intel HEX format parsing library.

Link to documentation

License

This source code is distributed under the MIT license.

Documentation

Index

Examples

Constants

View Source
const (
	Data                   RecordType = 0x00
	EndOfFile                         = 0x01
	ExtendedSegmentAddress            = 0x02
	StartSegmentAddress               = 0x03
	ExtendedLinearAddress             = 0x04
	StartLinearAddress                = 0x05
)

Variables

This section is empty.

Functions

func Checksum

func Checksum(buf []byte) (sum byte)

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Parses IHEX files.

Example
d := NewDecoder(os.Stdin)

for d.Scan() {
	// do something with d.Record()
}

// check if there was an error during parsing
err := d.Err()
if err != nil {
	// handle the error
}

func NewDecoder

func NewDecoder(r io.Reader) (d *Decoder)

Create a new Decoder using input from the given io.Reader.

func (*Decoder) Err

func (d *Decoder) Err() (err error)

Returns the first error that occurred during parsing, or nil if there was no error.

func (*Decoder) Record

func (d *Decoder) Record() (rec Record)

Returns the most recently parsed record. An empty record is returned if Scan has not yet been called, or if Scan has never returned true.

func (*Decoder) Scan

func (d *Decoder) Scan() (ok bool)

Read and decode one record from the source, returning true if the record was decoded successfully. False may be returned if the end of the file is reached or an error has occurred. This method is designed to be called repeatedly to read the entire file, and then have the Err method called to determine if an error occurred. The scanned record can be retrieved with the Record method.

func (*Decoder) ScanData

func (d *Decoder) ScanData() (ok bool)

ScanData returns the next Data record. Any extended segment or linear addresses are processed but not returned -- the function calls itself recursively until the next data record or EOF is encountered

type ExtAddress

type ExtAddress uint32

ExtAddress represents an extended address of width up to 32-bits

type ExtAddressSlice

type ExtAddressSlice []ExtAddress

ExtAddressSlice is defined in order to allow implemention of the Sort interface for client convenience. Invoke as follows:

 import "sort"
	addressesToSort := []ExtAddress{....}
	sort.Sort(ExtAddressSlice(addressesToSort))

func (ExtAddressSlice) Len

func (a ExtAddressSlice) Len() int

func (ExtAddressSlice) Less

func (a ExtAddressSlice) Less(i, j int) bool

func (ExtAddressSlice) Swap

func (a ExtAddressSlice) Swap(i, j int)

type Record

type Record struct {
	// The type of record
	Type RecordType

	// The address associated with the record's data (for Data records).
	Address uint16

	// The Extended address associated with the record's data
	ExtendedAddress ExtAddress

	// The payload of the record.
	Data []byte
}

Represents a single IHEX record.

func DecodeRecord

func DecodeRecord(bytes []byte) (rec Record, err error)

Interpreting bytes as the binary form of an IHEX record, decode and return a Record. err may be non-nil if there was a checksum mismatch.

func DecodeRecordHex

func DecodeRecordHex(hexStr string) (rec Record, err error)

Interpreting hexStr as the hexadecimal form of an IHEX record with or without the leading start token (colon), deocde and return a Record. err may be non-nil if there was a checksum mismatch or if the decoding from hexadecimal failed.

func (Record) Encode

func (rec Record) Encode() (bytes []byte)

Encode the record to the binary form of an IHEX record.

func (Record) EncodeHex

func (rec Record) EncodeHex() (hexStr string)

Encode the record to the hexadecimal form of an IHEX record, with the leading start token (colon).

func (*Record) String

func (rec *Record) String() string

type RecordType

type RecordType uint8

RecordType is a value from 0 to 5 as described in the intel hex spec (http://www.piclist.com/techref/fileext/hex/intel.htm)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL