Comments (13)
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.
Thanks for your question
Will take a look into it tomorrow (getting late here)
from crc.
Thanks so much, an especially late in the evening for you, on Eastern time here. Have a good night!
from crc.
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.
Output
...\Arduino\libraries\CRC\examples\CRC8_test2\CRC8_test2.ino
1D
1D
7
from crc.
Hope this helps.
Rob
from crc.
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.
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.
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.
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.
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.
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.
You're welcome and thanks!
If there are more question, feel free to open an issue !
from crc.
Related Issues (18)
- fix classes 32 and 64 like issue #4 HOT 1
- Diverging CRC16 results HOT 4
- const Parameters? HOT 6
- how to get crc12? HOT 6
- different crc32 result from crccalc.com/ HOT 5
- Yield condition is not updated in loop HOT 6
- make it possible to enable / disable yield() HOT 15
- Add "ifndef ... define..." to prevent already defined errors HOT 26
- input content (uint8_t *array) as HEX HOT 8
- Add constructors with all parameters at once HOT 2
- Binary CRC8 HOT 17
- Hexa number as input HOT 5
- Use little endian by default HOT 17
- CRC16.h or crc16.h? HOT 2
- Discuss 1.0.0 HOT 7
- warning: 'deprecated' attribute directive ignored [-Wattributes] HOT 6
- The CRC16-Modbus calculation with the bytes swapped for Dwin displays HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from crc.