npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

intel_hex_386

v1.0.3

Published

Read and Write intel hex 386 files

Downloads

4

Readme

Intel Hex 386 - Overview

IN DEVELOPMENT - NEEDS TESTING - DO NOT USE IN PRODUCTION CODE

Intel Hex 386 is a typescript library for parsing intel hex files commonly used for flashing microcontrollers.

Table of Contents

Brief

In Detail

Limitations

This utility currently only works with extended linear address intel hex files. It is also designed only to deal with intel hex files that already exist, it currently does not have the capacity to generate an intel hex file from nothing.

However, it is possible to generate a intel hex file from binary if the block data structure is known.

Dependancies

npm

  • ncc_common

Installation

npm install intel_hex_386

Basics

Import ES Module

Vanilla Javascript ES

import { IntelHex386 } from "intel_hex_386";

TypeScript

import { IntelHex386, ByteOrder } from "intel_hex_386";

Instantiate

Some intel hex files can include a crc, or additional information such as the byte order for the file. This data is not processed by this package. Only the intel hex document is read from the string. The parser is agnostic to anything else in the file and should only extract a continuous intel hex 386 document.

If any record has an incorrect checksum the package will throw an error.

const intelHexFile:string = fs.readFileSync(filepath,'utf8');
const intelHex386 = new IntelHex386(intelHexFile);

Serialize

Serialization generates a utf8 encoded string of the intel hex records. During serialization the checksum for each record is calculated.

const intelHexSerialized:string = intelHex386.serialize();

The Cursor

Reading & Writing to the intel hex.

Recommended

Destructure the cursor

const { cursor } = intelHex386;

Set Byte Order

If the byte order is not set before the first read or write an error will be thrown.

Typescript

cursor.setByteOrder(ByteOrder.LittleEndian);

Javascript

cursor.setByteOrder("LittleEndian");

Using the cursor for dynamic sequential reads

let read = cursor.read(0x12345678);

Setting the cursor to a variable allows for sequential reads to be made, from the initial starting address.

This can be useful when a yet unknown number of sequential operations need to take place

const getUint32:number = () => read.integer(false,4);
const packedValues = getUint32();
const idObjects = [];

for (let p = 0; p < packedValues; p++){
  const id = getUInt32();
  const sequentialIds = getUInt32();

  for (let s = 0; s < sequentialIds;s++){
    idObjects.push({ id: id + s });
  }
}

Using the cursor to read specific types

This packages is intended to handle reading and writing specific primative datatypes to and from the intel hex 386 file.

  • bytes
  • integers
  • fixed points
  • floats
  • strings

Please see: Cursor for a detailed explaination of the type options.

const unsigned32BitInteger:number = (
  cursor
    .read(0x12345678)
    .integer(false,4)
) // returns a single 32 bit integer

const unsigned32BitInteger:number[] = (
  cursor
    .read(0x12345678)
    .integer(false,4,10)
) // returns an array of 10, 32 bit integers 

From

Static Method

Create a new intel hex 386 from an array of objects containing the starting address and buffer for that starting address.

import { IntelHex386, BlockDataStructure } from "intel_hex_386";

const block1:BlockDataStructure = {
  address: 0x80020000,
  binary: Buffer.from([ 1, 2, 3, 4])
}
const block2:BlockDataStructure = {
  address: 0x802C0700,
  binary: Buffer.from([ 5, 6, 7, 8])
}

const blockDataStructure:BlockDataStructure[] = [
  block1,
  block2
];

const generatedIntelHex = IntelHex386.createFrom(blockDataStructure);