Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: H.x frame decoding #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 64 additions & 9 deletions source/SENTAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,7 @@ void SENTAnalyzer::syncPulseDetected()
{
U8 expected_crc = CalculateCRC();
bool crc_correct = (framelist.at(crc_nibble_number).mData1 == expected_crc);
for(std::vector<Frame>::iterator it = framelist.begin(); it != framelist.end(); it++) {
if(!crc_correct && (it->mType == CRCNibble)) {
addErrorFrame(expected_crc, it->mStartingSampleInclusive, it->mEndingSampleInclusive, CrcError);
} else {
mResults->AddFrame( *it );
mResults->CommitResults();
ReportProgress( it->mEndingSampleInclusive );
}
}
commit_results(crc_correct, expected_crc);
mResults->CommitPacketAndStartNewPacket();
}
else if( framelist.size() > 0 )
Expand All @@ -130,6 +122,69 @@ void SENTAnalyzer::syncPulseDetected()
framelist.clear();
}


void SENTAnalyzer::commit_results(bool crc_correct, U8 expected_crc)
{
#if 1
/* Sync pulse */
mResults->AddFrame(framelist[0]);
mResults->CommitResults();
ReportProgress(framelist[0].mEndingSampleInclusive );

/* SCN */
mResults->AddFrame(framelist[1]);
mResults->CommitResults();
ReportProgress(framelist[1].mEndingSampleInclusive );

/* FC1 */
U16 fc1_data = ((framelist[2].mData1 & 0xF) << 8u) | ((framelist[3].mData1 & 0xF) << 4u) | (framelist[4].mData1 & 0xF);
Frame fc1_frame;
fc1_frame.mData1 = fc1_data;
fc1_frame.mFlags = 0;
fc1_frame.mType = FCNibble;
fc1_frame.mStartingSampleInclusive = framelist[2].mStartingSampleInclusive;
fc1_frame.mEndingSampleInclusive = framelist[4].mEndingSampleInclusive;

mResults->AddFrame(fc1_frame);
mResults->CommitResults();
ReportProgress(fc1_frame.mEndingSampleInclusive );

/* Secure counter */
U16 secure_counter_data = ((framelist[5].mData1 & 0xF) << 4u) | (framelist[6].mData1 & 0xF);
Frame secure_counter_frame;
secure_counter_frame.mData1 = secure_counter_data;
secure_counter_frame.mFlags = 0;
secure_counter_frame.mType = FCNibble;
secure_counter_frame.mStartingSampleInclusive = framelist[5].mStartingSampleInclusive;
secure_counter_frame.mEndingSampleInclusive = framelist[6].mEndingSampleInclusive;

mResults->AddFrame(secure_counter_frame);
mResults->CommitResults();
ReportProgress(secure_counter_frame.mEndingSampleInclusive );

for(std::vector<Frame>::iterator it = framelist.begin() + 7; it != framelist.end(); it++)
{
if(!crc_correct && (it->mType == CRCNibble)) {
addErrorFrame(expected_crc, it->mStartingSampleInclusive, it->mEndingSampleInclusive, CrcError);
} else {
mResults->AddFrame(*it);
mResults->CommitResults();
ReportProgress(it->mEndingSampleInclusive );
}
}
#else
for(std::vector<Frame>::iterator it = framelist.begin(); it != framelist.end(); it++) {
if(!crc_correct && (it->mType == CRCNibble)) {
addErrorFrame(expected_crc, it->mStartingSampleInclusive, it->mEndingSampleInclusive, CrcError);
} else {
mResults->AddFrame(*it);
mResults->CommitResults();
ReportProgress(it->mEndingSampleInclusive );
}
}
#endif

}
/** Function for correcting the tick time
*
* This function should be called whenever a sync pulse is detected (given the specified clock tolerances)
Expand Down
1 change: 1 addition & 0 deletions source/SENTAnalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ANALYZER_EXPORT SENTAnalyzer : public Analyzer2
U32 corrected_samples_per_tick;

void syncPulseDetected();
void commit_results(bool crc_correct, U8 expected_crc);
void correctTickTime(U32 number_of_samples);
U8 CalculateCRC();
bool isPulseSyncPulse(U16 number_of_ticks);
Expand Down