Coder Social home page Coder Social logo

libihex's Introduction

libihex

Plain C library for manipulating IntelHex files.

Features

  • robust intelhex parsing
  • binary data segmentation
  • dynamic memory allocation
  • automatic records aligning
  • automatic segments sorting and joining
  • data overlapping detection
  • CRLF and LF compatible
  • small footprint, very fast and resources friendly
  • padding byte for unspecified addresses
  • trivial api
  • unit tests
  • error raports

Build

Build and install:

cmake .
make
make check
sudo make install

API

struct ihex_object *ihex_new(void);
void ihex_delete(struct ihex_object *self);
const char *ihex_get_error_string(struct ihex_object *self);
int ihex_parse_file(struct ihex_object *self, FILE *fp);
int ihex_dump_file(struct ihex_object *self, FILE *fp);
int ihex_set_data(struct ihex_object *self, uint32_t adr, uint8_t *data, uint32_t size);
int ihex_get_data(struct ihex_object *self, uint32_t adr, uint8_t *data, uint32_t size);

See ihex.h header file for details.

Examples

Loading IntelHex file

#include <stdio.h>

/* include library header */
#include <ihex.h>

/* example intelhex data file content */
static char input_hex[] =
":020000040800F2\n"
":0400020001020304F0\n"
":00000001FF\n";

int main(int argc, char **argv)
{
        struct ihex_object *ihex;
        FILE *fp;
        unsigned char data[8];
        int i;

        /* create new intelhex parser instance */
	ihex = ihex_new();

        /* open file with intelhex data */
	fp = fmemopen(input_hex, sizeof(input_hex), "r");

        /* parsing intelhex stream */
        ihex_parse_file(ihex, fp);

        /* close file */
	fclose(fp);

        /* get binary data */
        ihex_get_data(ihex, 0x08000000, data, sizeof(data));

        /* print data output: FF FF 01 02 03 04 FF FF*/
        for (i = 0; i < sizeof(data); i++)
                printf("%02X ", data[i]);

        /* free resources */
        ihex_delete(ihex);

        return 0;
}

libihex's People

Contributors

marcinbor85 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

thegeek82000

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.