Git Product home page Git Product logo

checksum's Introduction

License: MIT

Bolder Flight Systems Logo     Arduino Logo

Checksum

This library contains clases and methods for computing common checksums. This library is compatible with Arduino and with CMake build systems.

Installation

Arduino

Use the Arduino Library Manager to install this library or clone to your Arduino/libraries folder. This library is added as:

#include "checksum.h"

An example Arduino executable is located at examples/arduino/checksum_example/checksum_example.ino. Teensy 3.x, 4.x, and LC devices are used for testing under Arduino and this library should be compatible with other Arduino devices.

CMake

CMake is used to build this library, which is exported as a library target called checksum. The header is added as:

#include "checksum.h"

The library can be also be compiled stand-alone using the CMake idiom of creating a build directory and then, from within that directory issuing:

cmake ..
make

This will build the library, an example executable called checksum_example, and an executable for testing using the Google Test framework, called checksum_test. The example executable source file is located at examples/cmake/checksum_example.cc.

Namespace

This library is within the namespace bfs.

Fletcher16

This class implements a Fletcher16 checksum.

Methods

Fletcher16() Creates a Fletcher16 object and initializes the checksum states.

bfs::Fletcher16 chk;

uint16_t Compute(uint8_t const * const data, const size_t len) Initializes the checksum states and computes the checksum in a single pass, given a pointer to an array of the data and the length of the array. The result is returned as a 16 bit unsigned integer.

uint8_t test[] = {'a','b','c','d','e'};
uint16_t result = chk.Compute(test, sizeof(test));
std::cout << result << std::endl;  // 51440

uint16_t Update(uint8_t const * const data, const size_t len) Computes the checksum given a pointer to an array of the data and the length of the array. The result is returned as a 16 bit unsigned integer. Note that this method does not reset the checksum states, enabling it to be used iteratively.

uint8_t test[] = {'a','b','c','d','e'};
for (size_t i = 0; i < sizeof(test); i++) {
   result = chk.Update(&test[i], 1);
}
std::cout << result << std::endl;  // 51440

void Reset() This method resets the checksum states. It should be used in conjunction with the Update method to reset states in between different checksum computations.

uint8_t test[] = {'a','b','c','d','e'};
for (size_t i = 0; i < sizeof(test); i++) {
   result = chk.Update(&test[i], 1);
}
std::cout << result << std::endl;  // 51440
chk.Reset();
uint8_t test2[] = {'a','b','c','d','e','f','g','h'};
for (size_t i = 0; i < sizeof(test2); i++) {
   result = chk.Update(&test2[i], 1);
}
std::cout << result << std::endl;  // 1575

checksum's People

Contributors

flybrianfly 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.