Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: cfe08ff0ebad
Choose a base ref
...
head repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 86f127f5de8c
Choose a head ref
  • 4 commits
  • 1 file changed
  • 2 contributors

Commits on Dec 19, 2020

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    b1ba421 View commit details
  2. fix formatting

    pd0wm committed Dec 19, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    c15bc13 View commit details
  3. add parentheses

    pd0wm committed Dec 19, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    da5dd5a View commit details
  4. Merge pull request #388 from pd0wm/master

    Verify CAN CRC (#333)
    azonenberg authored Dec 19, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    86f127f View commit details
Showing with 20 additions and 2 deletions.
  1. +20 −2 scopeprotocols/CANDecoder.cpp
22 changes: 20 additions & 2 deletions scopeprotocols/CANDecoder.cpp
Original file line number Diff line number Diff line change
@@ -126,6 +126,11 @@ void CANDecoder::Refresh()
int frame_bytes_left = 0;
int32_t frame_id = 0;
char tmp[128];

// CRC (http://esd.cs.ucr.edu/webres/can20.pdf page 13)
const uint16_t crc_poly = 0x4599;
uint16_t crc = 0;

for(size_t i = 0; i < len; i++)
{
bool v = diff->m_samples[i];
@@ -218,6 +223,16 @@ void CANDecoder::Refresh()
current_field |= 1;
nbit ++;

if (state != STATE_CRC){
uint16_t crc_bit_14 = (crc >> 14) & 0x1;
uint16_t crc_nxt = sampled_value ^ crc_bit_14;
crc = crc << 1;

if (crc_nxt){
crc = crc ^ crc_poly;
}
}

switch(state)
{
//Wait for at least 7 bit times low
@@ -245,6 +260,7 @@ void CANDecoder::Refresh()

tblockstart = off;
nbit = 0;
crc = 0;
current_field = 0;
state = STATE_ID;
break;
@@ -416,10 +432,12 @@ void CANDecoder::Refresh()
//CRC is 15 bits long
if(nbit == 15)
{
//TODO: actually check the CRC
bool crc_ok = (current_field == (crc & 0x7fff));
auto type = crc_ok ? CANSymbol::TYPE_CRC_OK : CANSymbol::TYPE_CRC_BAD;

cap->m_offsets.push_back(tblockstart);
cap->m_durations.push_back(end - tblockstart);
cap->m_samples.push_back(CANSymbol(CANSymbol::TYPE_CRC_OK, current_field));
cap->m_samples.push_back(CANSymbol(type, current_field));

state = STATE_CRC_DELIM;
}