Giter Site home page Giter Site logo

CRC8 SAE J1850 From CAN Data about crc HOT 13 CLOSED

gsmith1979 avatar gsmith1979 commented on May 26, 2024
CRC8 SAE J1850 From CAN Data

from crc.

Comments (13)

gsmith1979 avatar gsmith1979 commented on May 26, 2024 1

Very nice, thanks so much! My programming I would say is very limited, but that probably overestimates my abilities haha. Thank you again for your time, I will make a contribution through paypal. Pretty amazing to have someone so responsive helping with something like this, greatly appreciated!

from crc.

RobTillaart avatar RobTillaart commented on May 26, 2024

Thanks for your question
Will take a look into it tomorrow (getting late here)

from crc.

gsmith1979 avatar gsmith1979 commented on May 26, 2024

Thanks so much, an especially late in the evening for you, on Eastern time here. Have a good night!

from crc.

RobTillaart avatar RobTillaart commented on May 26, 2024

The screenshot in code

//    FILE: CRC8_test2.ino
//  AUTHOR: Rob Tillaart
// PURPOSE: demo
//    DATE: 2021-01-20
//    (c) : MIT

#include "CRC8.h"

byte arr[7] = { 0x13, 0x54, 0x13, 0x88, 0x00, 0x0e, 0x99 };

CRC8 crc(0x1D, 0xFF, 0xFF, false, false);

void setup()
{
  Serial.begin(115200);
  Serial.println(__FILE__);

  crc.add((uint8_t*)arr, 7);
  Serial.println(crc.calc(), HEX);

  crc.restart();
  for (int i = 0; i < 7; i++)
  {
    crc.add(arr[i]);
  }
  uint8_t result = crc.calc();
  Serial.println(result, HEX);
  Serial.println(crc.count());
}

void loop()
{
}

// -- END OF FILE --

from crc.

RobTillaart avatar RobTillaart commented on May 26, 2024

Output

...\Arduino\libraries\CRC\examples\CRC8_test2\CRC8_test2.ino
1D
1D
7

from crc.

RobTillaart avatar RobTillaart commented on May 26, 2024

Hope this helps.
Rob

from crc.

gsmith1979 avatar gsmith1979 commented on May 26, 2024

My general confusion (sorry I'm a mechanical engineer and not a good programmer at all) is in how to get my 8 bytes that I read in from can as buf[0], buf[1] etc. Into an array that the function will read like you have shown), in the case where you have entered ox13 etc, could a delared variable like buf[0] be used?

I believe when I read it in, I interact with it in decimal form.

Again apologies for my lack of general programming and data types understanding.

from crc.

gsmith1979 avatar gsmith1979 commented on May 26, 2024

Thank you very much for your help, I was able to get your code pasted into my mess and it seems to be working :) Please let me know what I owe you for your time!
Greg

from crc.

RobTillaart avatar RobTillaart commented on May 26, 2024

My code shows 2 ways to calculate CRC.
One with array as parameter and one with one element at a time
As your data is already in an array called buf, the first one looks easiest.

crc.add((uint8_t*) buf, 7);
If (crc.calc() != buf[7])
{
  // Handle error
}
.

from crc.

RobTillaart avatar RobTillaart commented on May 26, 2024

Please let me know what I owe you for your time!

Did not spent serious time on your issue, so you owe me nothing.

Most of my time goes to developing and maintaining the libraries, so you might consider sponsoring that process (onetime / monthly) or if you prefer donate to charity (e.g doctors without borders) .
Or just help a stranger with a question someday in your life.

from crc.

RobTillaart avatar RobTillaart commented on May 26, 2024

Maybe better example, a bit integrated

unsigned char len = 0;
if (CAN_MSGAVAIL == CAN.checkReceive()) 
 {         // check if data coming
        CAN.readMsgBuf(&len, buf);    // read data,  len: data length, buf: data buf

        crc.add((uint8_t*) buf, 7);  //  check the CRC of the incoming message
        If (crc.calc() != buf[7])
        {
          // Handle error
        }

        unsigned long canId = CAN.getCanId();

If you need to send a message

buf[0] = xxx;
buf[1] = yyy;
// etc
buf[6] = zzz;

crc.restart();      //  restart CRC calculation
crc.add((uint8_t*) buf, 7);
buf[7] = crc.calc();   // calculate the CRC and assign it to the CRC element of the buffer

CAN.sendMsgBuf(7, buf);   //  assume something like this exists

from crc.

RobTillaart avatar RobTillaart commented on May 26, 2024

As the library has several "standard" CRC sets defined in CrcParameters.h,
This is how the code could initialize the crc object, so you would always know which standard was used.
(instead of just 5 parameters with no obvious meaning)

CRC8 crc(CRC8_SAEJ1850_POLYNOME,
         CRC8_SAEJ1850_INITIAL,
         CRC8_SAEJ1850_XOR_OUT,
         CRC8_SAEJ1850_REV_IN,
         CRC8_SAEJ1850_REV_OUT,
         );

And yes, maintainability comes with more typing :)

from crc.

RobTillaart avatar RobTillaart commented on May 26, 2024

You're welcome and thanks!
If there are more question, feel free to open an issue !

from crc.

Related Issues (18)

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.