Code Monkey home page Code Monkey logo

jcd.srecord's Introduction

Jcd.SRecord

This library will load, parse and validate a motorola sRecord file according to the Ubuntu srec manpage and the Wikipedia SREC (file format) article.

Some inspiration was taken from reading the code by Vanya A. Sergeev and Jerry G. Scherer However, you'll note mine is significantly different.

Examples

    // read all of the data, tracking the parse result for each line.
    var document = SRecordDocument.CreateFromFile("FakeFirmware.s37");

    // compute some statistics.
    var parsingStats = document.CalculateParseStatistics();
    var dataStats = document.CalculateDataStatistics();

    // Report on what's in the file.
    Console.WriteLine($"Record type counts:");
    Console.WriteLine($"S0 {dataStats.S0Count}; S1 {dataStats.S1Count}; S2 {dataStats.S2Count}; S3 {dataStats.S3Count}; S4 {dataStats.S4Count}; S5 {dataStats.S5Count}; S6 {dataStats.S6Count}; S7 {dataStats.S7Count}; S8 {dataStats.S8Count}; S9: {dataStats.S9Count}");
    Console.WriteLine();
    Console.WriteLine($"Parsing stats:");
    Console.WriteLine($"Total number of blank lines: {parsingStats.BlankElementCount}");
    Console.WriteLine($"Total number of lines with parsing errors: {parsingStats.ErrorElementCount}");
    Console.WriteLine($"Total number of stand alone comment lines: {parsingStats.StandAloneCommentCount}");
    Console.WriteLine($"Total number of lines with comments: {parsingStats.ElementsWithCommentsCount}");
    Console.WriteLine($"Total number of lines with s-record entries: {parsingStats.ElementsWithSRecordDataCount}");
    Console.WriteLine($"Total number of lines with comments and s-record entries: {parsingStats.SRecordDataWithCommentCount}");
    Console.WriteLine($"Total line count: {parsingStats.TotalElementsCount}");
    /* The above gives the following output:
    Record type counts:
    S0 1; S1 3; S2 0; S3 0; S4 0; S5 1; S6 0; S7 0; S8 0; S9: 1

    Parsing stats:
    Total number of blank lines: 0
    Total number of lines with parsing errors: 0
    Total number of stand alone comment lines: 3
    Total number of lines with comments: 3
    Total number of lines with s-record entries: 6
    Total number of lines with comments and s-record entries: 0
    Total line count: 9
    */

    // now access the data and upload the firmware to a device.
    foreach (var record in document.SRecords)
    {
        // get a byte array if it's S1, S2, S3 and send firmware to the device.
        if (record.Type.Key == "S1" || record.Type.Key == "S2" || record.Type.Key == "S3")
            UploadToFirmware(record.Address, record.Type.AddressLengthInBytes, record.Data.ToArray());
        // set the execution address if S7, S8, or S9
        else if (record.Type.Key == "S7" || record.Type.Key == "S8" || record.Type.Key == "S9")
            SetExecutionAddress(record.Address,record.Type.AddressLengthInBytes);
    }

GitHub Build status CodeFactor Grade

MyGet Nuget

API Docs

jcd.srecord's People

Contributors

jason-c-daniels avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

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.