From e71cb6ebacbddb4d761c1147438af27470f30cdb Mon Sep 17 00:00:00 2001 From: Marcus10110 Date: Fri, 5 Jun 2020 15:35:54 -0700 Subject: [PATCH] clang-format update of 1-Wire Analyzer --- src/OneWireAnalyzer.cpp | 1391 ++++++++++++------------ src/OneWireAnalyzer.h | 139 ++- src/OneWireAnalyzerResults.cpp | 720 ++++++------ src/OneWireAnalyzerResults.h | 27 +- src/OneWireAnalyzerSettings.cpp | 81 +- src/OneWireAnalyzerSettings.h | 28 +- src/OneWireSimulationDataGenerator.cpp | 487 ++++----- src/OneWireSimulationDataGenerator.h | 63 +- 8 files changed, 1479 insertions(+), 1457 deletions(-) diff --git a/src/OneWireAnalyzer.cpp b/src/OneWireAnalyzer.cpp index 6a4b5a8..0b300ac 100644 --- a/src/OneWireAnalyzer.cpp +++ b/src/OneWireAnalyzer.cpp @@ -1,762 +1,751 @@ -#pragma warning(push, 0) +#pragma warning( push, 0 ) #include #include -#pragma warning(pop) +#pragma warning( pop ) #include "OneWireAnalyzer.h" -#include "OneWireAnalyzerSettings.h" +#include "OneWireAnalyzerSettings.h" #include -OneWireAnalyzer::OneWireAnalyzer() -: mSettings( new OneWireAnalyzerSettings() ), - Analyzer2(), - mSimulationInitilized( false ) -{ - SetAnalyzerSettings( mSettings.get() ); +OneWireAnalyzer::OneWireAnalyzer() : mSettings( new OneWireAnalyzerSettings() ), Analyzer2(), mSimulationInitilized( false ) +{ + SetAnalyzerSettings( mSettings.get() ); } OneWireAnalyzer::~OneWireAnalyzer() { - KillThread(); + KillThread(); } void OneWireAnalyzer::SetupResults() { - mResults.reset( new OneWireAnalyzerResults( this, mSettings.get() ) ); - SetAnalyzerResults( mResults.get() ); - mResults->AddChannelBubblesWillAppearOn( mSettings->mOneWireChannel ); + mResults.reset( new OneWireAnalyzerResults( this, mSettings.get() ) ); + SetAnalyzerResults( mResults.get() ); + mResults->AddChannelBubblesWillAppearOn( mSettings->mOneWireChannel ); } void OneWireAnalyzer::WorkerThread() { - //mResults->AddChannelBubblesWillAppearOn( mSettings->mOneWireChannel ); - - mOneWire = GetAnalyzerChannelData( mSettings->mOneWireChannel ); - - U64 starting_sample = mOneWire->GetSampleNumber(); - //one_wire.MoveToSample( starting_sample ); - - U64 current_sample = starting_sample; - - mSampleRateHz = this->GetSampleRate(); - - mCurrentState = UnknownState; - bool force_overdrive = mSettings->mOverdrive; - mOverdrive = force_overdrive; - - mRisingEdgeSample = current_sample; - mFallingEdgeSample = 0; - mByteStartSample = 0; - mBlockPulseAdvance = false; - - for( ; ; ) - { - if( mBlockPulseAdvance == false ) - { - mPreviousRisingEdgeSample = mRisingEdgeSample; - - //one_wire.MoveRightUntilBitChanges( true, true ); - //most of the time, we will be entering on a falling edge. - - current_sample = mOneWire->GetSampleNumber(); - if( (mOneWire->GetBitState() == BIT_LOW) &&(current_sample > mFallingEdgeSample) ) - { - //it is possible that we have advanced into a reset pulse. - //mFallingEdgeSample will contain the falling edge that we came in on. we should be inside by either 3us or 30 us. - - U64 next_rising_edge_sample = mOneWire->GetSampleOfNextEdge(); - U64 low_pulse_length = next_rising_edge_sample - mFallingEdgeSample; - - //test for a reset condition. - U64 minimum_pulse_width = UsToSamples( SPEC_RESET_PULSE - MARGIN_INSIDE_RESET_PULSE ); - U64 spec_pulse_width = UsToSamples( SPEC_RESET_PULSE ); - U64 maximum_pulse_width = mLowPulseLength + 1; - if( force_overdrive || mOverdrive ) - { - minimum_pulse_width = UsToSamples( SPEC_OVD_RESET_PULSE - MARGIN_INSIDE_OVD_RESET_PULSE ); - spec_pulse_width = UsToSamples( SPEC_OVD_RESET_PULSE ); - maximum_pulse_width = UsToSamples( SPEC_MAX_OVD_RESET_PULSE + MARGIN_OUTSIDE_OVD_RESET_PULSE ); - } - if( ( mLowPulseLength > minimum_pulse_width ) && ( mLowPulseLength < maximum_pulse_width ) ) - { - //Reset Pulse Detected. - //Print Reset Bubble. - bool flag_warning = false; - if( force_overdrive || mOverdrive ) - { - if( low_pulse_length > UsToSamples( SPEC_RESET_PULSE - MARGIN_INSIDE_RESET_PULSE ) ) - { - if( low_pulse_length < UsToSamples( SPEC_RESET_PULSE ) ) - flag_warning = true; - } - } - else - { - if( low_pulse_length < spec_pulse_width ) - flag_warning = true; - } - mResults->CommitPacketAndStartNewPacket(); - if( flag_warning == true ) - //TODO: RecordBubble( one_wire_bubbles, mFallingEdgeSample, mRisingEdgeSample, RestartPulse, mLowPulseLength ); - RecordFrame(mFallingEdgeSample, next_rising_edge_sample, RestartPulse, 0, true ); - else - //TODO: RecordBubble( one_wire_bubbles, mFallingEdgeSample, mRisingEdgeSample, RestartPulse ); - RecordFrame(mFallingEdgeSample, next_rising_edge_sample, RestartPulse ); - - if (low_pulse_length > UsToSamples( SPEC_RESET_PULSE - MARGIN_INSIDE_RESET_PULSE )) - mOverdrive = false; - - mRomBitsRecieved = 0; - mRomDetected = 0; - mDataDetected = 0; - mDataBitsRecieved = 0; - - mCurrentState = ResetDetectedState; - mOneWire->AdvanceToNextEdge(); //advance to the rising edge out of the reset pulse, so we don't detect it twice. - - continue; - } - } - - mOneWire->AdvanceToNextEdge(); - - //if( one_wire.GetBitState() != BIT_LOW ) - // one_wire.MoveRightUntilBitChanges( true, true ); - - //this happens every time a zero is recorded. - if( mOneWire->GetBitState() != BIT_LOW ) - mOneWire->AdvanceToNextEdge(); - - mFallingEdgeSample = mOneWire->GetSampleNumber();//one_wire.GetSampleNumber(); - - mHighPulseLength = mFallingEdgeSample - mRisingEdgeSample; - - //one_wire.MoveRightUntilBitChanges( true, true ); - mRisingEdgeSample = mOneWire->GetSampleOfNextEdge(); - //mOneWire->AdvanceToNextEdge(); - - //mRisingEdgeSample = mOneWire->GetSampleNumber();//one_wire.GetSampleNumber(); - mLowPulseLength = mRisingEdgeSample - mFallingEdgeSample; - - mLowPulseTime = SamplesToUs( mLowPulseLength ); //micro seconds - mHighPulseTime = SamplesToUs( mHighPulseLength ); - - U64 min_low_pulse_samples = UsToSamples( 1 ); - min_low_pulse_samples /= 2; //customer had data where the min pulse was about 0.8us. - if( ( force_overdrive || mOverdrive ) && (mSampleRateHz <= 1000000 ) ) - min_low_pulse_samples = 0; - - while( mLowPulseLength < min_low_pulse_samples ) - { - mOneWire->AdvanceToNextEdge(); - mOneWire->AdvanceToNextEdge(); //next neg edge. - mFallingEdgeSample = mOneWire->GetSampleNumber();//one_wire.GetSampleNumber(); - mRisingEdgeSample = mOneWire->GetSampleOfNextEdge(); - mLowPulseLength = mRisingEdgeSample - mFallingEdgeSample; - mLowPulseTime = SamplesToUs( mLowPulseLength ); //micro seconds - } - - - //At this point, we should be sitting on a negative edge, and have the pulse length of the low pulse in front, and the high pulse behind. - } - mBlockPulseAdvance = false; - - //Test for a reset Pulse: - { - U64 minimum_pulse_width = UsToSamples( SPEC_RESET_PULSE - MARGIN_INSIDE_RESET_PULSE ); - U64 spec_pulse_width = UsToSamples( SPEC_RESET_PULSE ); - U64 maximum_pulse_width = mLowPulseLength + 1; - if( force_overdrive || mOverdrive ) - { - minimum_pulse_width = UsToSamples( SPEC_OVD_RESET_PULSE - MARGIN_INSIDE_OVD_RESET_PULSE ); - spec_pulse_width = UsToSamples( SPEC_OVD_RESET_PULSE ); - maximum_pulse_width = UsToSamples( SPEC_MAX_OVD_RESET_PULSE + MARGIN_OUTSIDE_OVD_RESET_PULSE ); - } - if( ( mLowPulseLength > minimum_pulse_width ) /*&& ( mLowPulseLength < maximum_pulse_width )*/ ) - { - //Reset Pulse Detected. - //Print Reset Bubble. - bool flag_warning = false; - if( force_overdrive || mOverdrive ) - { - if( mLowPulseLength > UsToSamples( SPEC_RESET_PULSE - MARGIN_INSIDE_RESET_PULSE ) ) - { - if( mLowPulseLength < UsToSamples( SPEC_RESET_PULSE ) ) - flag_warning = true; - } - } - else - { - if( mLowPulseLength < spec_pulse_width ) - flag_warning = true; - } - mResults->CommitPacketAndStartNewPacket(); - if( flag_warning == true ) - //TODO: RecordBubble( one_wire_bubbles, mFallingEdgeSample, mRisingEdgeSample, RestartPulse, mLowPulseLength ); - RecordFrame(mFallingEdgeSample, mRisingEdgeSample, RestartPulse, 0, true ); - else - //TODO: RecordBubble( one_wire_bubbles, mFallingEdgeSample, mRisingEdgeSample, RestartPulse ); - RecordFrame(mFallingEdgeSample, mRisingEdgeSample, RestartPulse ); - - if (mLowPulseLength > UsToSamples( SPEC_RESET_PULSE - MARGIN_INSIDE_RESET_PULSE )) - mOverdrive = false; - - mRomBitsRecieved = 0; - mRomDetected = 0; - mDataDetected = 0; - mDataBitsRecieved = 0; - - mCurrentState = ResetDetectedState; - continue; - } - } - - switch ( mCurrentState ) - { - case UnknownState: - { - //Do nothing. - } - break; - case ResetDetectedState: - { - //Test to see if er have a reset pulse. - U64 minimum_pulse_width = UsToSamples( SPEC_MIN_PRESENCE_PULSE - MARGIN_INSIDE_PRESENCE_PULSE ); - - if( force_overdrive || mOverdrive ) - { - minimum_pulse_width = UsToSamples( SPEC_MIN_OVD_PRESENCE_PULSE - MARGIN_INSIDE_OVD_PRESENCE_PULSE ); - } - if ( mLowPulseLength > minimum_pulse_width ) - { - //Presence Pulse Detected. - //TODO: RecordBubble( one_wire_bubbles, mFallingEdgeSample, mRisingEdgeSample, PresencePulse ); - RecordFrame( mFallingEdgeSample, mRisingEdgeSample, PresencePulse ); - - mCurrentState = PresenceDetectedState; - } - } - break; - case PresenceDetectedState: - { - //anticipating Rom Command. - if( mDataBitsRecieved == 0 ) - mByteStartSample = mFallingEdgeSample; - /* - U64 minimum_pulse_width_zero = UsToSamples( SPEC_MIN_ZERO_PULSE - MARGIN_INSIDE_ZERO_PULSE ); //60us spec - U64 maximum_pulse_width_one = UsToSamples( SPEC_MAX_ONE_PULSE + MARGIN_OUTSIDE_ONE_PULSE ); //15us spec - if( mOverdrive == true ) - { - minimum_pulse_width_zero = UsToSamples( SPEC_OVD_MIN_ZERO_PULSE - MARGIN_INSIDE_OVD_ZERO_PULSE ); //6us spec - maximum_pulse_width_one = UsToSamples( SPEC_MAX_OVD_ONE_PULSE + MARGIN_OUTSIDE_OVD_ONE_PULSE ); //2us spec - } - if ( mLowPulseLength > minimum_pulse_width_zero ) - { - //store a zero into the data. - } - else if( mLowPulseLength <= maximum_pulse_width_one ) - { - //store a one into the data. - if( ( mOverdrive == true ) || ( mLowPulseLength > 1 ) ) - mDataDetected |= U64(0x1) << mDataBitsRecieved; - } - else - { - mCurrentState = UnknownState; - //Something Broke. - } - */ - U64 sample_location_offset = UsToSamples( SPEC_SAMPLE_POINT ); - if( force_overdrive || mOverdrive ) - sample_location_offset = UsToSamples( SPEC_OVD_SAMPLE_POINT ); - mOneWire->Advance( U32( sample_location_offset ) ); - - if( mOneWire->GetBitState() == BIT_HIGH ) - { - //short pulse, this is a 1 - mDataDetected |= U64(0x1) << mDataBitsRecieved; - } - else - { - //long pulse, this is a 0 - } - //if( ( mOverdrive == true ) || ( mLowPulseLength > 1 ) ) - mDataBitsRecieved += 1; - - if( mDataBitsRecieved == 8 ) - { - //all 8 bits of rom command collected. - //add bubble for all 8 bits. - //ReadRom, SkipRom, SearchRom, MatchRom, OverdriveSkipRom, OverdriveMatchRom, AlarmSearchRom - OneWireFrameType frame_type; - - if( ( mDataDetected == 0x33 ) || ( mDataDetected == 0x0F ) ) - { - mCurrentRomCommand = ReadRom; - frame_type = ReadRomFrame; - } - else if( mDataDetected == 0xCC ) - { - mCurrentRomCommand = SkipRom; - frame_type = SkipRomFrame; - } - else if( mDataDetected == 0x55 ) - { - mCurrentRomCommand = MatchRom; - frame_type = MatchRomFrame; - } - else if( mDataDetected == 0xF0 ) - { - mCurrentRomCommand = SearchRom; - frame_type = SearchRomFrame; - } - else if( mDataDetected == 0x3C ) - { - mCurrentRomCommand = OverdriveSkipRom; - frame_type = OverdriveSkipRomFrame; - } - else if( mDataDetected == 0x69 ) - { - mCurrentRomCommand = OverdriveMatchRom; - frame_type = OverdriveMatchRomFrame; - } - else if( mDataDetected == 0xEC ) - { - mCurrentRomCommand = AlarmSearch; - frame_type = AlarmSearchFrame; - } - else - { - frame_type = InvalidRomCommandFrame; - mCurrentState = RomFinishedState; - } - - if(mCurrentState != RomFinishedState) - mCurrentState = RomCommandDetectedState; - - - //TODO: RecordBubble( one_wire_bubbles, mByteStartSample, mRisingEdgeSample, RomCommand, mCurrentRomCommand, mDataDetected ); - RecordFrame( mByteStartSample, mRisingEdgeSample, frame_type, mDataDetected ); - - - mDataBitsRecieved = 0; - mDataDetected = 0; - - continue; - } - - } - break; - case RomCommandDetectedState: - { - //ReadRom, SkipRom, SearchRom, MatchRom, OverdriveSkipRom, OverdriveMatchRom, AlarmSearchRom - switch( mCurrentRomCommand ) - { - case ReadRom: - { - //expecting 64 bits of rom address, nothing more. - //mRomDetected - if( mRomBitsRecieved == 8 ) - { - //Bubble the ROM Family Code. - //TODO: RecordBubble( one_wire_bubbles, mByteStartSample, mPreviousRisingEdgeSample, FamilyCode, mRomDetected ); - //RecordFrame( mByteStartSample, mPreviousRisingEdgeSample, FamilyCode, mRomDetected ); - mByteStartSample = mFallingEdgeSample; - } - if( mRomBitsRecieved == 56 ) - { - //Bubble the ROM Data bits. - //TODO: RecordBubble( one_wire_bubbles, mByteStartSample, mPreviousRisingEdgeSample, Rom, ((mRomDetected >> 8) & 0xFFFFFFFFFFFFull) ); - //RecordFrame( mByteStartSample, mPreviousRisingEdgeSample, Rom, ((mRomDetected >> 8) & 0xFFFFFFFFFFFFull) ); - mByteStartSample = mFallingEdgeSample; - } - if( mRomBitsRecieved == 0 ) - { - //Tag start of Family Code. - mByteStartSample = mFallingEdgeSample; - } - - U64 sample_location_offset = UsToSamples( SPEC_SAMPLE_POINT ); - if( force_overdrive || mOverdrive ) - sample_location_offset = UsToSamples( SPEC_OVD_SAMPLE_POINT ); - mOneWire->Advance( U32( sample_location_offset ) ); - - if( mOneWire->GetBitState() == BIT_HIGH ) - { - //short pulse, this is a 1 - mRomDetected |= U64(0x1) << mRomBitsRecieved; - } - else - { - //long pulse, this is a 0 - } - - mRomBitsRecieved += 1; - - if( mRomBitsRecieved == 8 ) - RecordFrame( mByteStartSample, mRisingEdgeSample, FamilyCode, mRomDetected ); - - - if( mRomBitsRecieved == 56 ) - RecordFrame( mByteStartSample, mRisingEdgeSample, Rom, ((mRomDetected >> 8) & 0xFFFFFFFFFFFFull) ); - - if( mRomBitsRecieved == 64 ) - { - //Bubble the ROM CRC. - //TODO: RecordBubble( one_wire_bubbles, mByteStartSample, mRisingEdgeSample, CRC, (mRomDetected >> 56) ); - RecordFrame( mByteStartSample, mRisingEdgeSample, CRC, (mRomDetected >> 56) ); - //Move to the next state - mCurrentState = RomFinishedState; - - } - } - break; - case SkipRom: - { - mCurrentState = RomFinishedState; - //we cannot through away our current transision! - mBlockPulseAdvance = true; - } - break; - case SearchRom: - { - //expecting 192 bits of crap :( perhaps we should filter out only the ROM select bits? - //mRomDetected - if( mRomBitsRecieved == 24 ) - { - //Bubble the ROM Family Code. - //TODO: RecordBubble( one_wire_bubbles, mByteStartSample, mPreviousRisingEdgeSample, FamilyCode, mRomDetected ); - //RecordFrame( mByteStartSample, mPreviousRisingEdgeSample, FamilyCode, mRomDetected ); - mByteStartSample = mFallingEdgeSample; - } - if( mRomBitsRecieved == 168 ) - { - //Bubble the ROM Data bits. - //TODO: RecordBubble( one_wire_bubbles, mByteStartSample, mPreviousRisingEdgeSample, Rom, ((mRomDetected >> 8) & 0xFFFFFFFFFFFFull) ); - //RecordFrame( mByteStartSample, mPreviousRisingEdgeSample, Rom, ((mRomDetected >> 8) & 0xFFFFFFFFFFFFull) ); - mByteStartSample = mFallingEdgeSample; - } - if( mRomBitsRecieved == 0 ) - { - //Tag start of Family Code. - mByteStartSample = mFallingEdgeSample; - } - if( ((mRomBitsRecieved + 1) % 3) == 0 ) - { - /* - U64 minimum_pulse_width_zero = UsToSamples( SPEC_MIN_ZERO_PULSE - MARGIN_INSIDE_ZERO_PULSE ); //60us spec - U64 maximum_pulse_width_one = UsToSamples( SPEC_MAX_ONE_PULSE + MARGIN_OUTSIDE_ONE_PULSE ); //15us spec - if( mOverdrive == true ) - { - minimum_pulse_width_zero = UsToSamples( SPEC_OVD_MIN_ZERO_PULSE - MARGIN_INSIDE_OVD_ZERO_PULSE ); //6us spec - maximum_pulse_width_one = UsToSamples( SPEC_MAX_OVD_ONE_PULSE + MARGIN_OUTSIDE_OVD_ONE_PULSE ); //2us spec - } - if ( mLowPulseLength > minimum_pulse_width_zero ) - { - //store a zero into the data. - } - else if( mLowPulseLength <= maximum_pulse_width_one ) - { - //store a one into the data. - mRomDetected |= U64(0x1) << ((mRomBitsRecieved - 2) / 3); - } - else - { - mCurrentState = UnknownState; - //Something Broke. - } - */ - U64 sample_location_offset = UsToSamples( SPEC_SAMPLE_POINT ); - if( force_overdrive || mOverdrive ) - sample_location_offset = UsToSamples( SPEC_OVD_SAMPLE_POINT ); - mOneWire->Advance( U32( sample_location_offset ) ); - - if( mOneWire->GetBitState() == BIT_HIGH ) - { - //short pulse, this is a 1 - mRomDetected |= U64(0x1) << ((mRomBitsRecieved - 2) / 3); - } - else - { - //long pulse, this is a 0 - } - } - mRomBitsRecieved += 1; - - - if( mRomBitsRecieved == 24 ) - RecordFrame( mByteStartSample, mRisingEdgeSample, FamilyCode, mRomDetected ); - - if( mRomBitsRecieved == 168 ) - RecordFrame( mByteStartSample, mRisingEdgeSample, Rom, ((mRomDetected >> 8) & 0xFFFFFFFFFFFFull) ); - - if( mRomBitsRecieved == 192 ) - { - //Bubble the ROM CRC. - //TODO: RecordBubble( one_wire_bubbles, mByteStartSample, mRisingEdgeSample, CRC, (mRomDetected >> 56) ); - RecordFrame( mByteStartSample, mRisingEdgeSample, CRC, (mRomDetected >> 56) ); - //Move to the next state - mCurrentState = RomFinishedState; - } - } - break; - case AlarmSearch: - { - //expecting 192 bits of crap :( perhaps we should filter out only the ROM select bits? - //mRomDetected - if( mRomBitsRecieved == 24 ) - { - //Bubble the ROM Family Code. - //TODO: RecordBubble( one_wire_bubbles, mByteStartSample, mPreviousRisingEdgeSample, FamilyCode, mRomDetected ); - //RecordFrame( mByteStartSample, mPreviousRisingEdgeSample, FamilyCode, mRomDetected ); - mByteStartSample = mFallingEdgeSample; - } - if( mRomBitsRecieved == 168 ) - { - //Bubble the ROM Data bits. - //TODO: RecordBubble( one_wire_bubbles, mByteStartSample, mPreviousRisingEdgeSample, Rom, ((mRomDetected >> 8) & 0xFFFFFFFFFFFFull) ); - //RecordFrame( mByteStartSample, mPreviousRisingEdgeSample, Rom, ((mRomDetected >> 8) & 0xFFFFFFFFFFFFull) ); - mByteStartSample = mFallingEdgeSample; - } - if( mRomBitsRecieved == 0 ) - { - //Tag start of Family Code. - mByteStartSample = mFallingEdgeSample; - } - if( ( ( mRomBitsRecieved + 1 ) % 3 ) == 0 ) - { - U64 sample_location_offset = UsToSamples( SPEC_SAMPLE_POINT ); - if( force_overdrive || mOverdrive ) - sample_location_offset = UsToSamples( SPEC_OVD_SAMPLE_POINT ); - mOneWire->Advance( U32( sample_location_offset ) ); - - if( mOneWire->GetBitState() == BIT_HIGH ) - { - //short pulse, this is a 1 - mRomDetected |= U64( 0x1 ) << ( ( mRomBitsRecieved - 2 ) / 3 ); - } - else - { - //long pulse, this is a 0 - } - } - mRomBitsRecieved += 1; - - - if( mRomBitsRecieved == 24 ) - RecordFrame( mByteStartSample, mRisingEdgeSample, FamilyCode, mRomDetected ); - - if( mRomBitsRecieved == 168 ) - RecordFrame( mByteStartSample, mRisingEdgeSample, Rom, ( ( mRomDetected >> 8 ) & 0xFFFFFFFFFFFFull ) ); - - if( mRomBitsRecieved == 192 ) - { - //Bubble the ROM CRC. - //TODO: RecordBubble( one_wire_bubbles, mByteStartSample, mRisingEdgeSample, CRC, (mRomDetected >> 56) ); - RecordFrame( mByteStartSample, mRisingEdgeSample, CRC, ( mRomDetected >> 56 ) ); - //Move to the next state - mCurrentState = RomFinishedState; - } - } - break; - case MatchRom: - { - //expecting 64 bits of rom address, nothing more. - //mRomDetected - if( mRomBitsRecieved == 8 ) - { - //Bubble the ROM Family Code. - //TODO: RecordBubble( one_wire_bubbles, mByteStartSample, mPreviousRisingEdgeSample, FamilyCode, mRomDetected ); - //RecordFrame( mByteStartSample, mPreviousRisingEdgeSample, FamilyCode, mRomDetected ); - mByteStartSample = mFallingEdgeSample; - } - if( mRomBitsRecieved == 56 ) - { - //Bubble the ROM Data bits. - //TODO: RecordBubble( one_wire_bubbles, mByteStartSample, mPreviousRisingEdgeSample, Rom, ((mRomDetected >> 8) & 0xFFFFFFFFFFFFull) ); - //RecordFrame( mByteStartSample, mPreviousRisingEdgeSample, Rom, ((mRomDetected >> 8) & 0xFFFFFFFFFFFFull) ); - mByteStartSample = mFallingEdgeSample; - } - if( mRomBitsRecieved == 0 ) - { - //Tag start of Family Code. - mByteStartSample = mFallingEdgeSample; - } - - U64 sample_location_offset = UsToSamples( SPEC_SAMPLE_POINT ); - if( force_overdrive || mOverdrive ) - sample_location_offset = UsToSamples( SPEC_OVD_SAMPLE_POINT ); - mOneWire->Advance( U32( sample_location_offset ) ); - - if( mOneWire->GetBitState() == BIT_HIGH ) - { - //short pulse, this is a 1 - mRomDetected |= U64(0x1) << mRomBitsRecieved; - } - else - { - //long pulse, this is a 0 - } - mRomBitsRecieved += 1; - - if( mRomBitsRecieved == 8 ) - RecordFrame( mByteStartSample, mRisingEdgeSample, FamilyCode, mRomDetected ); - - if( mRomBitsRecieved == 56 ) - RecordFrame( mByteStartSample, mRisingEdgeSample, Rom, ((mRomDetected >> 8) & 0xFFFFFFFFFFFFull) ); - - if( mRomBitsRecieved == 64 ) - { - //Bubble the ROM CRC. - //TODO: RecordBubble( one_wire_bubbles, mByteStartSample, mRisingEdgeSample, CRC, (mRomDetected >> 56) ); - RecordFrame( mByteStartSample, mRisingEdgeSample, CRC, (mRomDetected >> 56) ); - //Move to the next state - mCurrentState = RomFinishedState; - - } - } - break; - case OverdriveSkipRom: - { - mCurrentState = RomFinishedState; - mOverdrive = true; - //we cannot through away our current transision! - mBlockPulseAdvance = true; - } - break; - case OverdriveMatchRom: - { - mOverdrive = true; - //expecting 64 bits of rom address. - mCurrentRomCommand = MatchRom; - //we cannot through away our current transision! - mBlockPulseAdvance = true; - - } - break; - } - - } - break; - case RomFinishedState: - { - if( mDataBitsRecieved == 0 ) - { - mDataDetected = 0; - //Tag start of Family Code. - mByteStartSample = mFallingEdgeSample; - } - - U64 sample_location_offset = UsToSamples( SPEC_SAMPLE_POINT ); - if( force_overdrive || mOverdrive ) - sample_location_offset = UsToSamples( SPEC_OVD_SAMPLE_POINT ); - mOneWire->Advance( U32( sample_location_offset ) ); - - if( mOneWire->GetBitState() == BIT_HIGH ) - { - //short pulse, this is a 1 - mDataDetected |= U64(0x1) << mDataBitsRecieved; - } - else - { - //long pulse, this is a 0 - } - mDataBitsRecieved += 1; - - if( mDataBitsRecieved == 8 ) - { - //Bubble the ROM Family Code. - //TODO: RecordBubble( one_wire_bubbles, mByteStartSample, mRisingEdgeSample, Byte, mDataDetected ); - RecordFrame( mByteStartSample, mRisingEdgeSample, Byte, mDataDetected ); - mDataBitsRecieved = 0; - } - - } - break; - } - - - ReportProgress( mOneWire->GetSampleNumber() ); - CheckIfThreadShouldExit(); - - - } + // mResults->AddChannelBubblesWillAppearOn( mSettings->mOneWireChannel ); + + mOneWire = GetAnalyzerChannelData( mSettings->mOneWireChannel ); + + U64 starting_sample = mOneWire->GetSampleNumber(); + // one_wire.MoveToSample( starting_sample ); + + U64 current_sample = starting_sample; + + mSampleRateHz = this->GetSampleRate(); + + mCurrentState = UnknownState; + bool force_overdrive = mSettings->mOverdrive; + mOverdrive = force_overdrive; + + mRisingEdgeSample = current_sample; + mFallingEdgeSample = 0; + mByteStartSample = 0; + mBlockPulseAdvance = false; + + for( ;; ) + { + if( mBlockPulseAdvance == false ) + { + mPreviousRisingEdgeSample = mRisingEdgeSample; + + // one_wire.MoveRightUntilBitChanges( true, true ); + // most of the time, we will be entering on a falling edge. + + current_sample = mOneWire->GetSampleNumber(); + if( ( mOneWire->GetBitState() == BIT_LOW ) && ( current_sample > mFallingEdgeSample ) ) + { + // it is possible that we have advanced into a reset pulse. + // mFallingEdgeSample will contain the falling edge that we came in on. we should be inside by either 3us or 30 us. + + U64 next_rising_edge_sample = mOneWire->GetSampleOfNextEdge(); + U64 low_pulse_length = next_rising_edge_sample - mFallingEdgeSample; + + // test for a reset condition. + U64 minimum_pulse_width = UsToSamples( SPEC_RESET_PULSE - MARGIN_INSIDE_RESET_PULSE ); + U64 spec_pulse_width = UsToSamples( SPEC_RESET_PULSE ); + U64 maximum_pulse_width = mLowPulseLength + 1; + if( force_overdrive || mOverdrive ) + { + minimum_pulse_width = UsToSamples( SPEC_OVD_RESET_PULSE - MARGIN_INSIDE_OVD_RESET_PULSE ); + spec_pulse_width = UsToSamples( SPEC_OVD_RESET_PULSE ); + maximum_pulse_width = UsToSamples( SPEC_MAX_OVD_RESET_PULSE + MARGIN_OUTSIDE_OVD_RESET_PULSE ); + } + if( ( mLowPulseLength > minimum_pulse_width ) && ( mLowPulseLength < maximum_pulse_width ) ) + { + // Reset Pulse Detected. + // Print Reset Bubble. + bool flag_warning = false; + if( force_overdrive || mOverdrive ) + { + if( low_pulse_length > UsToSamples( SPEC_RESET_PULSE - MARGIN_INSIDE_RESET_PULSE ) ) + { + if( low_pulse_length < UsToSamples( SPEC_RESET_PULSE ) ) + flag_warning = true; + } + } + else + { + if( low_pulse_length < spec_pulse_width ) + flag_warning = true; + } + mResults->CommitPacketAndStartNewPacket(); + if( flag_warning == true ) + // TODO: RecordBubble( one_wire_bubbles, mFallingEdgeSample, mRisingEdgeSample, RestartPulse, mLowPulseLength ); + RecordFrame( mFallingEdgeSample, next_rising_edge_sample, RestartPulse, 0, true ); + else + // TODO: RecordBubble( one_wire_bubbles, mFallingEdgeSample, mRisingEdgeSample, RestartPulse ); + RecordFrame( mFallingEdgeSample, next_rising_edge_sample, RestartPulse ); + + if( low_pulse_length > UsToSamples( SPEC_RESET_PULSE - MARGIN_INSIDE_RESET_PULSE ) ) + mOverdrive = false; + + mRomBitsRecieved = 0; + mRomDetected = 0; + mDataDetected = 0; + mDataBitsRecieved = 0; + + mCurrentState = ResetDetectedState; + mOneWire->AdvanceToNextEdge(); // advance to the rising edge out of the reset pulse, so we don't detect it twice. + + continue; + } + } + + mOneWire->AdvanceToNextEdge(); + + // if( one_wire.GetBitState() != BIT_LOW ) + // one_wire.MoveRightUntilBitChanges( true, true ); + + // this happens every time a zero is recorded. + if( mOneWire->GetBitState() != BIT_LOW ) + mOneWire->AdvanceToNextEdge(); + + mFallingEdgeSample = mOneWire->GetSampleNumber(); // one_wire.GetSampleNumber(); + + mHighPulseLength = mFallingEdgeSample - mRisingEdgeSample; + + // one_wire.MoveRightUntilBitChanges( true, true ); + mRisingEdgeSample = mOneWire->GetSampleOfNextEdge(); + // mOneWire->AdvanceToNextEdge(); + + // mRisingEdgeSample = mOneWire->GetSampleNumber();//one_wire.GetSampleNumber(); + mLowPulseLength = mRisingEdgeSample - mFallingEdgeSample; + + mLowPulseTime = SamplesToUs( mLowPulseLength ); // micro seconds + mHighPulseTime = SamplesToUs( mHighPulseLength ); + + U64 min_low_pulse_samples = UsToSamples( 1 ); + min_low_pulse_samples /= 2; // customer had data where the min pulse was about 0.8us. + if( ( force_overdrive || mOverdrive ) && ( mSampleRateHz <= 1000000 ) ) + min_low_pulse_samples = 0; + + while( mLowPulseLength < min_low_pulse_samples ) + { + mOneWire->AdvanceToNextEdge(); + mOneWire->AdvanceToNextEdge(); // next neg edge. + mFallingEdgeSample = mOneWire->GetSampleNumber(); // one_wire.GetSampleNumber(); + mRisingEdgeSample = mOneWire->GetSampleOfNextEdge(); + mLowPulseLength = mRisingEdgeSample - mFallingEdgeSample; + mLowPulseTime = SamplesToUs( mLowPulseLength ); // micro seconds + } + + + // At this point, we should be sitting on a negative edge, and have the pulse length of the low pulse in front, and the high + // pulse behind. + } + mBlockPulseAdvance = false; + + // Test for a reset Pulse: + { + U64 minimum_pulse_width = UsToSamples( SPEC_RESET_PULSE - MARGIN_INSIDE_RESET_PULSE ); + U64 spec_pulse_width = UsToSamples( SPEC_RESET_PULSE ); + U64 maximum_pulse_width = mLowPulseLength + 1; + if( force_overdrive || mOverdrive ) + { + minimum_pulse_width = UsToSamples( SPEC_OVD_RESET_PULSE - MARGIN_INSIDE_OVD_RESET_PULSE ); + spec_pulse_width = UsToSamples( SPEC_OVD_RESET_PULSE ); + maximum_pulse_width = UsToSamples( SPEC_MAX_OVD_RESET_PULSE + MARGIN_OUTSIDE_OVD_RESET_PULSE ); + } + if( ( mLowPulseLength > minimum_pulse_width ) /*&& ( mLowPulseLength < maximum_pulse_width )*/ ) + { + // Reset Pulse Detected. + // Print Reset Bubble. + bool flag_warning = false; + if( force_overdrive || mOverdrive ) + { + if( mLowPulseLength > UsToSamples( SPEC_RESET_PULSE - MARGIN_INSIDE_RESET_PULSE ) ) + { + if( mLowPulseLength < UsToSamples( SPEC_RESET_PULSE ) ) + flag_warning = true; + } + } + else + { + if( mLowPulseLength < spec_pulse_width ) + flag_warning = true; + } + mResults->CommitPacketAndStartNewPacket(); + if( flag_warning == true ) + // TODO: RecordBubble( one_wire_bubbles, mFallingEdgeSample, mRisingEdgeSample, RestartPulse, mLowPulseLength ); + RecordFrame( mFallingEdgeSample, mRisingEdgeSample, RestartPulse, 0, true ); + else + // TODO: RecordBubble( one_wire_bubbles, mFallingEdgeSample, mRisingEdgeSample, RestartPulse ); + RecordFrame( mFallingEdgeSample, mRisingEdgeSample, RestartPulse ); + + if( mLowPulseLength > UsToSamples( SPEC_RESET_PULSE - MARGIN_INSIDE_RESET_PULSE ) ) + mOverdrive = false; + + mRomBitsRecieved = 0; + mRomDetected = 0; + mDataDetected = 0; + mDataBitsRecieved = 0; + + mCurrentState = ResetDetectedState; + continue; + } + } + + switch( mCurrentState ) + { + case UnknownState: + { + // Do nothing. + } + break; + case ResetDetectedState: + { + // Test to see if er have a reset pulse. + U64 minimum_pulse_width = UsToSamples( SPEC_MIN_PRESENCE_PULSE - MARGIN_INSIDE_PRESENCE_PULSE ); + + if( force_overdrive || mOverdrive ) + { + minimum_pulse_width = UsToSamples( SPEC_MIN_OVD_PRESENCE_PULSE - MARGIN_INSIDE_OVD_PRESENCE_PULSE ); + } + if( mLowPulseLength > minimum_pulse_width ) + { + // Presence Pulse Detected. + // TODO: RecordBubble( one_wire_bubbles, mFallingEdgeSample, mRisingEdgeSample, PresencePulse ); + RecordFrame( mFallingEdgeSample, mRisingEdgeSample, PresencePulse ); + + mCurrentState = PresenceDetectedState; + } + } + break; + case PresenceDetectedState: + { + // anticipating Rom Command. + if( mDataBitsRecieved == 0 ) + mByteStartSample = mFallingEdgeSample; + /* + U64 minimum_pulse_width_zero = UsToSamples( SPEC_MIN_ZERO_PULSE - MARGIN_INSIDE_ZERO_PULSE ); //60us spec + U64 maximum_pulse_width_one = UsToSamples( SPEC_MAX_ONE_PULSE + MARGIN_OUTSIDE_ONE_PULSE ); //15us spec + if( mOverdrive == true ) + { + minimum_pulse_width_zero = UsToSamples( SPEC_OVD_MIN_ZERO_PULSE - MARGIN_INSIDE_OVD_ZERO_PULSE ); //6us spec + maximum_pulse_width_one = UsToSamples( SPEC_MAX_OVD_ONE_PULSE + MARGIN_OUTSIDE_OVD_ONE_PULSE ); //2us spec + } + if ( mLowPulseLength > minimum_pulse_width_zero ) + { + //store a zero into the data. + } + else if( mLowPulseLength <= maximum_pulse_width_one ) + { + //store a one into the data. + if( ( mOverdrive == true ) || ( mLowPulseLength > 1 ) ) + mDataDetected |= U64(0x1) << mDataBitsRecieved; + } + else + { + mCurrentState = UnknownState; + //Something Broke. + } + */ + U64 sample_location_offset = UsToSamples( SPEC_SAMPLE_POINT ); + if( force_overdrive || mOverdrive ) + sample_location_offset = UsToSamples( SPEC_OVD_SAMPLE_POINT ); + mOneWire->Advance( U32( sample_location_offset ) ); + + if( mOneWire->GetBitState() == BIT_HIGH ) + { + // short pulse, this is a 1 + mDataDetected |= U64( 0x1 ) << mDataBitsRecieved; + } + else + { + // long pulse, this is a 0 + } + // if( ( mOverdrive == true ) || ( mLowPulseLength > 1 ) ) + mDataBitsRecieved += 1; + + if( mDataBitsRecieved == 8 ) + { + // all 8 bits of rom command collected. + // add bubble for all 8 bits. + // ReadRom, SkipRom, SearchRom, MatchRom, OverdriveSkipRom, OverdriveMatchRom, AlarmSearchRom + OneWireFrameType frame_type; + + if( ( mDataDetected == 0x33 ) || ( mDataDetected == 0x0F ) ) + { + mCurrentRomCommand = ReadRom; + frame_type = ReadRomFrame; + } + else if( mDataDetected == 0xCC ) + { + mCurrentRomCommand = SkipRom; + frame_type = SkipRomFrame; + } + else if( mDataDetected == 0x55 ) + { + mCurrentRomCommand = MatchRom; + frame_type = MatchRomFrame; + } + else if( mDataDetected == 0xF0 ) + { + mCurrentRomCommand = SearchRom; + frame_type = SearchRomFrame; + } + else if( mDataDetected == 0x3C ) + { + mCurrentRomCommand = OverdriveSkipRom; + frame_type = OverdriveSkipRomFrame; + } + else if( mDataDetected == 0x69 ) + { + mCurrentRomCommand = OverdriveMatchRom; + frame_type = OverdriveMatchRomFrame; + } + else if( mDataDetected == 0xEC ) + { + mCurrentRomCommand = AlarmSearch; + frame_type = AlarmSearchFrame; + } + else + { + frame_type = InvalidRomCommandFrame; + mCurrentState = RomFinishedState; + } + + if( mCurrentState != RomFinishedState ) + mCurrentState = RomCommandDetectedState; + + + // TODO: RecordBubble( one_wire_bubbles, mByteStartSample, mRisingEdgeSample, RomCommand, mCurrentRomCommand, mDataDetected + // ); + RecordFrame( mByteStartSample, mRisingEdgeSample, frame_type, mDataDetected ); + + + mDataBitsRecieved = 0; + mDataDetected = 0; + + continue; + } + } + break; + case RomCommandDetectedState: + { + // ReadRom, SkipRom, SearchRom, MatchRom, OverdriveSkipRom, OverdriveMatchRom, AlarmSearchRom + switch( mCurrentRomCommand ) + { + case ReadRom: + { + // expecting 64 bits of rom address, nothing more. + // mRomDetected + if( mRomBitsRecieved == 8 ) + { + // Bubble the ROM Family Code. + // TODO: RecordBubble( one_wire_bubbles, mByteStartSample, mPreviousRisingEdgeSample, FamilyCode, mRomDetected ); + // RecordFrame( mByteStartSample, mPreviousRisingEdgeSample, FamilyCode, mRomDetected ); + mByteStartSample = mFallingEdgeSample; + } + if( mRomBitsRecieved == 56 ) + { + // Bubble the ROM Data bits. + // TODO: RecordBubble( one_wire_bubbles, mByteStartSample, mPreviousRisingEdgeSample, Rom, ((mRomDetected >> 8) & + // 0xFFFFFFFFFFFFull) ); RecordFrame( mByteStartSample, mPreviousRisingEdgeSample, Rom, ((mRomDetected >> 8) & + // 0xFFFFFFFFFFFFull) ); + mByteStartSample = mFallingEdgeSample; + } + if( mRomBitsRecieved == 0 ) + { + // Tag start of Family Code. + mByteStartSample = mFallingEdgeSample; + } + + U64 sample_location_offset = UsToSamples( SPEC_SAMPLE_POINT ); + if( force_overdrive || mOverdrive ) + sample_location_offset = UsToSamples( SPEC_OVD_SAMPLE_POINT ); + mOneWire->Advance( U32( sample_location_offset ) ); + + if( mOneWire->GetBitState() == BIT_HIGH ) + { + // short pulse, this is a 1 + mRomDetected |= U64( 0x1 ) << mRomBitsRecieved; + } + else + { + // long pulse, this is a 0 + } + + mRomBitsRecieved += 1; + + if( mRomBitsRecieved == 8 ) + RecordFrame( mByteStartSample, mRisingEdgeSample, FamilyCode, mRomDetected ); + + + if( mRomBitsRecieved == 56 ) + RecordFrame( mByteStartSample, mRisingEdgeSample, Rom, ( ( mRomDetected >> 8 ) & 0xFFFFFFFFFFFFull ) ); + + if( mRomBitsRecieved == 64 ) + { + // Bubble the ROM CRC. + // TODO: RecordBubble( one_wire_bubbles, mByteStartSample, mRisingEdgeSample, CRC, (mRomDetected >> 56) ); + RecordFrame( mByteStartSample, mRisingEdgeSample, CRC, ( mRomDetected >> 56 ) ); + // Move to the next state + mCurrentState = RomFinishedState; + } + } + break; + case SkipRom: + { + mCurrentState = RomFinishedState; + // we cannot through away our current transision! + mBlockPulseAdvance = true; + } + break; + case SearchRom: + { + // expecting 192 bits of crap :( perhaps we should filter out only the ROM select bits? + // mRomDetected + if( mRomBitsRecieved == 24 ) + { + // Bubble the ROM Family Code. + // TODO: RecordBubble( one_wire_bubbles, mByteStartSample, mPreviousRisingEdgeSample, FamilyCode, mRomDetected ); + // RecordFrame( mByteStartSample, mPreviousRisingEdgeSample, FamilyCode, mRomDetected ); + mByteStartSample = mFallingEdgeSample; + } + if( mRomBitsRecieved == 168 ) + { + // Bubble the ROM Data bits. + // TODO: RecordBubble( one_wire_bubbles, mByteStartSample, mPreviousRisingEdgeSample, Rom, ((mRomDetected >> 8) & + // 0xFFFFFFFFFFFFull) ); RecordFrame( mByteStartSample, mPreviousRisingEdgeSample, Rom, ((mRomDetected >> 8) & + // 0xFFFFFFFFFFFFull) ); + mByteStartSample = mFallingEdgeSample; + } + if( mRomBitsRecieved == 0 ) + { + // Tag start of Family Code. + mByteStartSample = mFallingEdgeSample; + } + if( ( ( mRomBitsRecieved + 1 ) % 3 ) == 0 ) + { + /* + U64 minimum_pulse_width_zero = UsToSamples( SPEC_MIN_ZERO_PULSE - MARGIN_INSIDE_ZERO_PULSE ); //60us spec + U64 maximum_pulse_width_one = UsToSamples( SPEC_MAX_ONE_PULSE + MARGIN_OUTSIDE_ONE_PULSE ); //15us spec + if( mOverdrive == true ) + { + minimum_pulse_width_zero = UsToSamples( SPEC_OVD_MIN_ZERO_PULSE - MARGIN_INSIDE_OVD_ZERO_PULSE ); //6us spec + maximum_pulse_width_one = UsToSamples( SPEC_MAX_OVD_ONE_PULSE + MARGIN_OUTSIDE_OVD_ONE_PULSE ); //2us spec + } + if ( mLowPulseLength > minimum_pulse_width_zero ) + { + //store a zero into the data. + } + else if( mLowPulseLength <= maximum_pulse_width_one ) + { + //store a one into the data. + mRomDetected |= U64(0x1) << ((mRomBitsRecieved - 2) / 3); + } + else + { + mCurrentState = UnknownState; + //Something Broke. + } + */ + U64 sample_location_offset = UsToSamples( SPEC_SAMPLE_POINT ); + if( force_overdrive || mOverdrive ) + sample_location_offset = UsToSamples( SPEC_OVD_SAMPLE_POINT ); + mOneWire->Advance( U32( sample_location_offset ) ); + + if( mOneWire->GetBitState() == BIT_HIGH ) + { + // short pulse, this is a 1 + mRomDetected |= U64( 0x1 ) << ( ( mRomBitsRecieved - 2 ) / 3 ); + } + else + { + // long pulse, this is a 0 + } + } + mRomBitsRecieved += 1; + + + if( mRomBitsRecieved == 24 ) + RecordFrame( mByteStartSample, mRisingEdgeSample, FamilyCode, mRomDetected ); + + if( mRomBitsRecieved == 168 ) + RecordFrame( mByteStartSample, mRisingEdgeSample, Rom, ( ( mRomDetected >> 8 ) & 0xFFFFFFFFFFFFull ) ); + + if( mRomBitsRecieved == 192 ) + { + // Bubble the ROM CRC. + // TODO: RecordBubble( one_wire_bubbles, mByteStartSample, mRisingEdgeSample, CRC, (mRomDetected >> 56) ); + RecordFrame( mByteStartSample, mRisingEdgeSample, CRC, ( mRomDetected >> 56 ) ); + // Move to the next state + mCurrentState = RomFinishedState; + } + } + break; + case AlarmSearch: + { + // expecting 192 bits of crap :( perhaps we should filter out only the ROM select bits? + // mRomDetected + if( mRomBitsRecieved == 24 ) + { + // Bubble the ROM Family Code. + // TODO: RecordBubble( one_wire_bubbles, mByteStartSample, mPreviousRisingEdgeSample, FamilyCode, mRomDetected ); + // RecordFrame( mByteStartSample, mPreviousRisingEdgeSample, FamilyCode, mRomDetected ); + mByteStartSample = mFallingEdgeSample; + } + if( mRomBitsRecieved == 168 ) + { + // Bubble the ROM Data bits. + // TODO: RecordBubble( one_wire_bubbles, mByteStartSample, mPreviousRisingEdgeSample, Rom, ((mRomDetected >> 8) & + // 0xFFFFFFFFFFFFull) ); RecordFrame( mByteStartSample, mPreviousRisingEdgeSample, Rom, ((mRomDetected >> 8) & + // 0xFFFFFFFFFFFFull) ); + mByteStartSample = mFallingEdgeSample; + } + if( mRomBitsRecieved == 0 ) + { + // Tag start of Family Code. + mByteStartSample = mFallingEdgeSample; + } + if( ( ( mRomBitsRecieved + 1 ) % 3 ) == 0 ) + { + U64 sample_location_offset = UsToSamples( SPEC_SAMPLE_POINT ); + if( force_overdrive || mOverdrive ) + sample_location_offset = UsToSamples( SPEC_OVD_SAMPLE_POINT ); + mOneWire->Advance( U32( sample_location_offset ) ); + + if( mOneWire->GetBitState() == BIT_HIGH ) + { + // short pulse, this is a 1 + mRomDetected |= U64( 0x1 ) << ( ( mRomBitsRecieved - 2 ) / 3 ); + } + else + { + // long pulse, this is a 0 + } + } + mRomBitsRecieved += 1; + + + if( mRomBitsRecieved == 24 ) + RecordFrame( mByteStartSample, mRisingEdgeSample, FamilyCode, mRomDetected ); + + if( mRomBitsRecieved == 168 ) + RecordFrame( mByteStartSample, mRisingEdgeSample, Rom, ( ( mRomDetected >> 8 ) & 0xFFFFFFFFFFFFull ) ); + + if( mRomBitsRecieved == 192 ) + { + // Bubble the ROM CRC. + // TODO: RecordBubble( one_wire_bubbles, mByteStartSample, mRisingEdgeSample, CRC, (mRomDetected >> 56) ); + RecordFrame( mByteStartSample, mRisingEdgeSample, CRC, ( mRomDetected >> 56 ) ); + // Move to the next state + mCurrentState = RomFinishedState; + } + } + break; + case MatchRom: + { + // expecting 64 bits of rom address, nothing more. + // mRomDetected + if( mRomBitsRecieved == 8 ) + { + // Bubble the ROM Family Code. + // TODO: RecordBubble( one_wire_bubbles, mByteStartSample, mPreviousRisingEdgeSample, FamilyCode, mRomDetected ); + // RecordFrame( mByteStartSample, mPreviousRisingEdgeSample, FamilyCode, mRomDetected ); + mByteStartSample = mFallingEdgeSample; + } + if( mRomBitsRecieved == 56 ) + { + // Bubble the ROM Data bits. + // TODO: RecordBubble( one_wire_bubbles, mByteStartSample, mPreviousRisingEdgeSample, Rom, ((mRomDetected >> 8) & + // 0xFFFFFFFFFFFFull) ); RecordFrame( mByteStartSample, mPreviousRisingEdgeSample, Rom, ((mRomDetected >> 8) & + // 0xFFFFFFFFFFFFull) ); + mByteStartSample = mFallingEdgeSample; + } + if( mRomBitsRecieved == 0 ) + { + // Tag start of Family Code. + mByteStartSample = mFallingEdgeSample; + } + + U64 sample_location_offset = UsToSamples( SPEC_SAMPLE_POINT ); + if( force_overdrive || mOverdrive ) + sample_location_offset = UsToSamples( SPEC_OVD_SAMPLE_POINT ); + mOneWire->Advance( U32( sample_location_offset ) ); + + if( mOneWire->GetBitState() == BIT_HIGH ) + { + // short pulse, this is a 1 + mRomDetected |= U64( 0x1 ) << mRomBitsRecieved; + } + else + { + // long pulse, this is a 0 + } + mRomBitsRecieved += 1; + + if( mRomBitsRecieved == 8 ) + RecordFrame( mByteStartSample, mRisingEdgeSample, FamilyCode, mRomDetected ); + + if( mRomBitsRecieved == 56 ) + RecordFrame( mByteStartSample, mRisingEdgeSample, Rom, ( ( mRomDetected >> 8 ) & 0xFFFFFFFFFFFFull ) ); + + if( mRomBitsRecieved == 64 ) + { + // Bubble the ROM CRC. + // TODO: RecordBubble( one_wire_bubbles, mByteStartSample, mRisingEdgeSample, CRC, (mRomDetected >> 56) ); + RecordFrame( mByteStartSample, mRisingEdgeSample, CRC, ( mRomDetected >> 56 ) ); + // Move to the next state + mCurrentState = RomFinishedState; + } + } + break; + case OverdriveSkipRom: + { + mCurrentState = RomFinishedState; + mOverdrive = true; + // we cannot through away our current transision! + mBlockPulseAdvance = true; + } + break; + case OverdriveMatchRom: + { + mOverdrive = true; + // expecting 64 bits of rom address. + mCurrentRomCommand = MatchRom; + // we cannot through away our current transision! + mBlockPulseAdvance = true; + } + break; + } + } + break; + case RomFinishedState: + { + if( mDataBitsRecieved == 0 ) + { + mDataDetected = 0; + // Tag start of Family Code. + mByteStartSample = mFallingEdgeSample; + } + + U64 sample_location_offset = UsToSamples( SPEC_SAMPLE_POINT ); + if( force_overdrive || mOverdrive ) + sample_location_offset = UsToSamples( SPEC_OVD_SAMPLE_POINT ); + mOneWire->Advance( U32( sample_location_offset ) ); + + if( mOneWire->GetBitState() == BIT_HIGH ) + { + // short pulse, this is a 1 + mDataDetected |= U64( 0x1 ) << mDataBitsRecieved; + } + else + { + // long pulse, this is a 0 + } + mDataBitsRecieved += 1; + + if( mDataBitsRecieved == 8 ) + { + // Bubble the ROM Family Code. + // TODO: RecordBubble( one_wire_bubbles, mByteStartSample, mRisingEdgeSample, Byte, mDataDetected ); + RecordFrame( mByteStartSample, mRisingEdgeSample, Byte, mDataDetected ); + mDataBitsRecieved = 0; + } + } + break; + } + + + ReportProgress( mOneWire->GetSampleNumber() ); + CheckIfThreadShouldExit(); + } } void OneWireAnalyzer::RecordFrame( U64 starting_sample, U64 ending_sample, OneWireFrameType type, U64 data, bool warning ) { - Frame frame; - U8 flags = 0; - if( warning == true ) - flags |= DISPLAY_AS_WARNING_FLAG; - frame.mFlags = flags; - frame.mStartingSampleInclusive = starting_sample; - frame.mEndingSampleInclusive = ending_sample; - frame.mType = (U8)type; - frame.mData1 = data; - - mResults->AddFrame( frame ); - - mResults->CommitResults(); + Frame frame; + U8 flags = 0; + if( warning == true ) + flags |= DISPLAY_AS_WARNING_FLAG; + frame.mFlags = flags; + frame.mStartingSampleInclusive = starting_sample; + frame.mEndingSampleInclusive = ending_sample; + frame.mType = ( U8 )type; + frame.mData1 = data; + + mResults->AddFrame( frame ); + + mResults->CommitResults(); } - -U32 OneWireAnalyzer::GenerateSimulationData( U64 minimum_sample_index, U32 device_sample_rate, SimulationChannelDescriptor** simulation_channels ) +U32 OneWireAnalyzer::GenerateSimulationData( U64 minimum_sample_index, U32 device_sample_rate, + SimulationChannelDescriptor** simulation_channels ) { + if( mSimulationInitilized == false ) + { + mSimulationDataGenerator.Initialize( GetSimulationSampleRate(), mSettings.get() ); + mSimulationInitilized = true; + } - if( mSimulationInitilized == false ) - { - mSimulationDataGenerator.Initialize( GetSimulationSampleRate(), mSettings.get() ); - mSimulationInitilized = true; - } - - return mSimulationDataGenerator.GenerateSimulationData( minimum_sample_index, device_sample_rate, simulation_channels ); - - + return mSimulationDataGenerator.GenerateSimulationData( minimum_sample_index, device_sample_rate, simulation_channels ); } bool OneWireAnalyzer::NeedsRerun() { - return false; + return false; } U64 OneWireAnalyzer::UsToSamples( U64 us ) { - - return ( mSampleRateHz * us ) / 1000000; - - + return ( mSampleRateHz * us ) / 1000000; } U64 OneWireAnalyzer::SamplesToUs( U64 samples ) { - return( samples * 1000000 ) / mSampleRateHz; + return ( samples * 1000000 ) / mSampleRateHz; } U32 OneWireAnalyzer::GetMinimumSampleRateHz() { - return 2000000; + return 2000000; } -const char gAnalyzerName[] = "1-Wire"; //your analyzer must have a unique name +const char gAnalyzerName[] = "1-Wire"; // your analyzer must have a unique name const char* OneWireAnalyzer::GetAnalyzerName() const { - return gAnalyzerName; + return gAnalyzerName; } const char* GetAnalyzerName() { - return gAnalyzerName; + return gAnalyzerName; } Analyzer* CreateAnalyzer() { - return new OneWireAnalyzer(); + return new OneWireAnalyzer(); } void DestroyAnalyzer( Analyzer* analyzer ) { - delete analyzer; + delete analyzer; } diff --git a/src/OneWireAnalyzer.h b/src/OneWireAnalyzer.h index 23a88cc..b67c457 100644 --- a/src/OneWireAnalyzer.h +++ b/src/OneWireAnalyzer.h @@ -2,12 +2,12 @@ #define ONE_WIRE_ANALYZER_H #ifdef WIN32 - #define EXPORT __declspec(dllexport) +#define EXPORT __declspec( dllexport ) #else - #define EXPORT - #define __cdecl - #define __stdcall - #define __fastcall +#define EXPORT +#define __cdecl +#define __stdcall +#define __fastcall #endif #include "Analyzer.h" @@ -16,11 +16,44 @@ class OneWireAnalyzerSettings; -enum OneWireFrameType { RestartPulse, PresencePulse, ReadRomFrame, SkipRomFrame, SearchRomFrame, MatchRomFrame, OverdriveSkipRomFrame, OverdriveMatchRomFrame, CRC, FamilyCode, Rom, Byte, Bit, InvalidRomCommandFrame, AlarmSearchFrame }; -enum OneWireState { UnknownState, ResetDetectedState, PresenceDetectedState, RomCommandDetectedState, RomFinishedState }; -enum OneWireRomCommand { ReadRom, SkipRom, SearchRom, MatchRom, OverdriveSkipRom, OverdriveMatchRom, AlarmSearch }; +enum OneWireFrameType +{ + RestartPulse, + PresencePulse, + ReadRomFrame, + SkipRomFrame, + SearchRomFrame, + MatchRomFrame, + OverdriveSkipRomFrame, + OverdriveMatchRomFrame, + CRC, + FamilyCode, + Rom, + Byte, + Bit, + InvalidRomCommandFrame, + AlarmSearchFrame +}; +enum OneWireState +{ + UnknownState, + ResetDetectedState, + PresenceDetectedState, + RomCommandDetectedState, + RomFinishedState +}; +enum OneWireRomCommand +{ + ReadRom, + SkipRom, + SearchRom, + MatchRom, + OverdriveSkipRom, + OverdriveMatchRom, + AlarmSearch +}; -//http://www.maxim-ic.com/products/ibutton/ibuttons/standard.pdf +// http://www.maxim-ic.com/products/ibutton/ibuttons/standard.pdf const U64 SPEC_RESET_PULSE = 480; const U64 SPEC_OVD_RESET_PULSE = 48; @@ -41,67 +74,67 @@ const U64 MARGIN_OUTSIDE_PRESENCE_PULSE = 10; const U64 MARGIN_OUTSIDE_OVD_PRESENCE_PULSE = 1; - const U64 SPEC_SAMPLE_POINT = 19; const U64 SPEC_OVD_SAMPLE_POINT = 3; class OneWireAnalyzer : public Analyzer2 { -public: - OneWireAnalyzer(); - virtual ~OneWireAnalyzer(); - virtual void SetupResults(); - virtual void WorkerThread(); - virtual U32 GenerateSimulationData( U64 newest_sample_requested, U32 sample_rate, SimulationChannelDescriptor** simulation_channels ); - virtual U32 GetMinimumSampleRateHz(); - - virtual const char* GetAnalyzerName() const; - - virtual bool NeedsRerun(); - + public: + OneWireAnalyzer(); + virtual ~OneWireAnalyzer(); + virtual void SetupResults(); + virtual void WorkerThread(); + virtual U32 GenerateSimulationData( U64 newest_sample_requested, U32 sample_rate, SimulationChannelDescriptor** simulation_channels ); + virtual U32 GetMinimumSampleRateHz(); + + virtual const char* GetAnalyzerName() const; + + virtual bool NeedsRerun(); + #pragma warning( push ) -#pragma warning( disable : 4251 ) //warning C4251: 'ManchesterAnalyzer::<...>' : class <...> needs to have dll-interface to be used by clients of class -protected: - AnalyzerChannelData* mOneWire; +#pragma warning( disable : 4251 ) // warning C4251: 'ManchesterAnalyzer::<...>' : class <...> needs to have dll-interface to be used by + // clients of class + protected: + AnalyzerChannelData* mOneWire; - std::auto_ptr< OneWireAnalyzerSettings > mSettings; - std::auto_ptr< OneWireAnalyzerResults > mResults; + std::auto_ptr mSettings; + std::auto_ptr mResults; - OneWireSimulationDataGenerator mSimulationDataGenerator; + OneWireSimulationDataGenerator mSimulationDataGenerator; - void RecordFrame( U64 starting_sample, U64 ending_sample, OneWireFrameType type, U64 data = 0, bool warning = false ); - U64 UsToSamples( U64 us ); - U64 SamplesToUs( U64 samples ); + void RecordFrame( U64 starting_sample, U64 ending_sample, OneWireFrameType type, U64 data = 0, bool warning = false ); + U64 UsToSamples( U64 us ); + U64 SamplesToUs( U64 samples ); - U32 mSampleRateHz; + U32 mSampleRateHz; - //decoding variables and functions. - bool mOverdrive; //1-Wire in Overdrive mode. approx speed increase. - OneWireState mCurrentState; //Current state comunication is in: Reset/Romcommand/Rom data (for Match, Skip and Read)/Transfers - OneWireRomCommand mCurrentRomCommand; //stores which rom command was issued. - U32 mRomBitsRecieved; //count of ROM bits recieved after a rom command. - U64 mRomDetected; //actual rom of device detected. - U64 mDataDetected; //data from device. either a rom command or general data. - U32 mDataBitsRecieved; //count of data bits recieved. + // decoding variables and functions. + bool mOverdrive; // 1-Wire in Overdrive mode. approx speed increase. + OneWireState mCurrentState; // Current state comunication is in: Reset/Romcommand/Rom data (for Match, Skip and Read)/Transfers + OneWireRomCommand mCurrentRomCommand; // stores which rom command was issued. + U32 mRomBitsRecieved; // count of ROM bits recieved after a rom command. + U64 mRomDetected; // actual rom of device detected. + U64 mDataDetected; // data from device. either a rom command or general data. + U32 mDataBitsRecieved; // count of data bits recieved. - U64 mByteStartSample; + U64 mByteStartSample; - U64 mRisingEdgeSample; - U64 mFallingEdgeSample; - U64 mPreviousRisingEdgeSample; - U64 mLowPulseLength; //units - samples - U64 mHighPulseLength; //units - samples - U64 mLowPulseTime; //units - microseconds us 10^-6 - U64 mHighPulseTime; //units - microseconds us 10^-6 - bool mBlockPulseAdvance; //in the while loop, continue without advancing the transision! + U64 mRisingEdgeSample; + U64 mFallingEdgeSample; + U64 mPreviousRisingEdgeSample; + U64 mLowPulseLength; // units - samples + U64 mHighPulseLength; // units - samples + U64 mLowPulseTime; // units - microseconds us 10^-6 + U64 mHighPulseTime; // units - microseconds us 10^-6 + bool mBlockPulseAdvance; // in the while loop, continue without advancing the transision! - bool mSimulationInitilized; + bool mSimulationInitilized; #pragma warning( pop ) }; -extern "C" ANALYZER_EXPORT const char* __cdecl GetAnalyzerName( ); -extern "C" ANALYZER_EXPORT Analyzer* __cdecl CreateAnalyzer( ); +extern "C" ANALYZER_EXPORT const char* __cdecl GetAnalyzerName(); +extern "C" ANALYZER_EXPORT Analyzer* __cdecl CreateAnalyzer(); extern "C" ANALYZER_EXPORT void __cdecl DestroyAnalyzer( Analyzer* analyzer ); -#endif //ONE_WIRE_ANALYZER_H +#endif // ONE_WIRE_ANALYZER_H diff --git a/src/OneWireAnalyzerResults.cpp b/src/OneWireAnalyzerResults.cpp index 89f4215..8dd93c3 100644 --- a/src/OneWireAnalyzerResults.cpp +++ b/src/OneWireAnalyzerResults.cpp @@ -6,400 +6,412 @@ #include OneWireAnalyzerResults::OneWireAnalyzerResults( OneWireAnalyzer* analyzer, OneWireAnalyzerSettings* settings ) -: AnalyzerResults(), - mSettings( settings ), - mAnalyzer( analyzer ) + : AnalyzerResults(), mSettings( settings ), mAnalyzer( analyzer ) { - } OneWireAnalyzerResults::~OneWireAnalyzerResults() { - } -void OneWireAnalyzerResults::GenerateBubbleText( U64 frame_index, Channel& /*channel*/, DisplayBase display_base ) //unrefereced vars commented out to remove warnings. +void OneWireAnalyzerResults::GenerateBubbleText( U64 frame_index, Channel& /*channel*/, + DisplayBase display_base ) // unrefereced vars commented out to remove warnings. { - Frame frame = GetFrame( frame_index ); - ClearResultStrings(); + Frame frame = GetFrame( frame_index ); + ClearResultStrings(); - bool warning_flag = false; - if( ( frame.mFlags & DISPLAY_AS_WARNING_FLAG ) != 0 ) - warning_flag = true; + bool warning_flag = false; + if( ( frame.mFlags & DISPLAY_AS_WARNING_FLAG ) != 0 ) + warning_flag = true; - //RestartPulse, PresencePulse, ReadRomFrame, SkipRomFrame, SearchRomFrame, AlarmSearchFrame, MatchRomFrame, OverdriveSkipRomFrame, OverdriveMatchRomFrame, CRC, FamilyCode, Rom, Byte, Bit - char number_str[128]; - AnalyzerHelpers::GetNumberString( frame.mData1, display_base, 8, number_str, 128 ); - - switch( (OneWireFrameType)frame.mType ) - { - case RestartPulse: - { - if( warning_flag == false ) - { - AddResultString( "R" ); - AddResultString( "RESET" ); - AddResultString( "RESET condition" ); - } - else - { - AddResultString( "R!" ); - AddResultString( "RESET - WARNING" ); - AddResultString( "RESET - warning, too short." ); - AddResultString( "RESET - warning, pulse shorter than 480us" ); - } - } - break; - case PresencePulse: - { - AddResultString( "P" ); - AddResultString( "PRESENCE" ); - AddResultString( "PRESENCE condition" ); - } - break; - case ReadRomFrame: - { - AddResultString( "READ" ); - AddResultString( "READ ROM COMMAND" ); - AddResultString( "READ ROM command: [", number_str, "]" ); - } - break; - case SkipRomFrame: - { - AddResultString( "SKIP" ); - AddResultString( "SKIP ROM COMMAND" ); - AddResultString( "SKIP ROM command: [", number_str, "]" ); - } - break; - case SearchRomFrame: - { - AddResultString( "SEARCH" ); - AddResultString( "SEARCH ROM COMMAND" ); - AddResultString( "SEARCH ROM command: [", number_str, "]" ); - } - break; - case AlarmSearchFrame: - { - AddResultString( "ALARM" ); - AddResultString( "ALARM SEARCH ROM COMMAND" ); - AddResultString( "ALARM SEARCH ROM command: [", number_str, "]" ); - } - break; - case MatchRomFrame: - { - AddResultString( "MATCH" ); - AddResultString( "MATCH ROM COMMAND" ); - AddResultString( "MATCH ROM command: [", number_str, "]" ); - } - break; - case OverdriveSkipRomFrame: - { - AddResultString( "OD SKIP" ); - AddResultString( "OVERDRIVE SKIP ROM" ); - AddResultString( "OVERDRIVE SKIP ROM command: [", number_str, "]" ); - } - break; - case OverdriveMatchRomFrame: - { - AddResultString( "OD MATCH" ); - AddResultString( "OVERDRIVE MATCH COMMAND" ); - AddResultString( "OVERDRIVE MATCH ROM command: [", number_str, "]" ); - } - break; - case CRC: - { - AddResultString( "CRC" ); - AddResultString( "CRC: [", number_str, "]" ); - AddResultString( "CRC section from ROM: [", number_str, "]" ); - } - break; - case FamilyCode: - { - AddResultString( "FAMILY" ); - AddResultString( "FAMILY: [", number_str, "]" ); - AddResultString( "FAMILY CODE section from ROM: [", number_str, "]" ); - } - break; - case Rom: - { - AnalyzerHelpers::GetNumberString( frame.mData1, display_base, 48, number_str, 128 ); - AddResultString( "ROM" ); - AddResultString( "ROM: [", number_str, "]" ); - AddResultString( "ROM CODE section from ROM: [", number_str, "]" ); - } - break; - case Byte: - { - AddResultString( "D" ); - AddResultString( "DATA" ); - AddResultString( "DATA: [", number_str, "]" ); - } - break; - case Bit: - { - AddResultString( "Z" ); - AddResultString( "BIT" ); - AddResultString( "BIT - ERROR." ); - } - break; - case InvalidRomCommandFrame: - { - AddResultString( "COMMAND!" ); - AddResultString( "INVALID ROM COMMAND" ); - AddResultString( "Invalid ROM command: [", number_str, "]" ); - } - break; - } + // RestartPulse, PresencePulse, ReadRomFrame, SkipRomFrame, SearchRomFrame, AlarmSearchFrame, MatchRomFrame, OverdriveSkipRomFrame, + // OverdriveMatchRomFrame, CRC, FamilyCode, Rom, Byte, Bit + char number_str[ 128 ]; + AnalyzerHelpers::GetNumberString( frame.mData1, display_base, 8, number_str, 128 ); + + switch( ( OneWireFrameType )frame.mType ) + { + case RestartPulse: + { + if( warning_flag == false ) + { + AddResultString( "R" ); + AddResultString( "RESET" ); + AddResultString( "RESET condition" ); + } + else + { + AddResultString( "R!" ); + AddResultString( "RESET - WARNING" ); + AddResultString( "RESET - warning, too short." ); + AddResultString( "RESET - warning, pulse shorter than 480us" ); + } + } + break; + case PresencePulse: + { + AddResultString( "P" ); + AddResultString( "PRESENCE" ); + AddResultString( "PRESENCE condition" ); + } + break; + case ReadRomFrame: + { + AddResultString( "READ" ); + AddResultString( "READ ROM COMMAND" ); + AddResultString( "READ ROM command: [", number_str, "]" ); + } + break; + case SkipRomFrame: + { + AddResultString( "SKIP" ); + AddResultString( "SKIP ROM COMMAND" ); + AddResultString( "SKIP ROM command: [", number_str, "]" ); + } + break; + case SearchRomFrame: + { + AddResultString( "SEARCH" ); + AddResultString( "SEARCH ROM COMMAND" ); + AddResultString( "SEARCH ROM command: [", number_str, "]" ); + } + break; + case AlarmSearchFrame: + { + AddResultString( "ALARM" ); + AddResultString( "ALARM SEARCH ROM COMMAND" ); + AddResultString( "ALARM SEARCH ROM command: [", number_str, "]" ); + } + break; + case MatchRomFrame: + { + AddResultString( "MATCH" ); + AddResultString( "MATCH ROM COMMAND" ); + AddResultString( "MATCH ROM command: [", number_str, "]" ); + } + break; + case OverdriveSkipRomFrame: + { + AddResultString( "OD SKIP" ); + AddResultString( "OVERDRIVE SKIP ROM" ); + AddResultString( "OVERDRIVE SKIP ROM command: [", number_str, "]" ); + } + break; + case OverdriveMatchRomFrame: + { + AddResultString( "OD MATCH" ); + AddResultString( "OVERDRIVE MATCH COMMAND" ); + AddResultString( "OVERDRIVE MATCH ROM command: [", number_str, "]" ); + } + break; + case CRC: + { + AddResultString( "CRC" ); + AddResultString( "CRC: [", number_str, "]" ); + AddResultString( "CRC section from ROM: [", number_str, "]" ); + } + break; + case FamilyCode: + { + AddResultString( "FAMILY" ); + AddResultString( "FAMILY: [", number_str, "]" ); + AddResultString( "FAMILY CODE section from ROM: [", number_str, "]" ); + } + break; + case Rom: + { + AnalyzerHelpers::GetNumberString( frame.mData1, display_base, 48, number_str, 128 ); + AddResultString( "ROM" ); + AddResultString( "ROM: [", number_str, "]" ); + AddResultString( "ROM CODE section from ROM: [", number_str, "]" ); + } + break; + case Byte: + { + AddResultString( "D" ); + AddResultString( "DATA" ); + AddResultString( "DATA: [", number_str, "]" ); + } + break; + case Bit: + { + AddResultString( "Z" ); + AddResultString( "BIT" ); + AddResultString( "BIT - ERROR." ); + } + break; + case InvalidRomCommandFrame: + { + AddResultString( "COMMAND!" ); + AddResultString( "INVALID ROM COMMAND" ); + AddResultString( "Invalid ROM command: [", number_str, "]" ); + } + break; + } } void OneWireAnalyzerResults::GenerateExportFile( const char* file, DisplayBase display_base, U32 /*export_type_user_id*/ ) { - //export_type_user_id is only important if we have more than one export type. + // export_type_user_id is only important if we have more than one export type. + + std::stringstream ss; + void* f = AnalyzerHelpers::StartFile( file ); - std::stringstream ss; - void* f = AnalyzerHelpers::StartFile( file ); + U64 trigger_sample = mAnalyzer->GetTriggerSample(); + U32 sample_rate = mAnalyzer->GetSampleRate(); - U64 trigger_sample = mAnalyzer->GetTriggerSample(); - U32 sample_rate = mAnalyzer->GetSampleRate(); + ss << "PacketId, Time[s], Detail, [data]" << std::endl; - ss << "PacketId, Time[s], Detail, [data]" << std::endl; + U64 num_frames = GetNumFrames(); + for( U32 i = 0; i < num_frames; i++ ) + { + Frame frame = GetFrame( i ); - U64 num_frames = GetNumFrames(); - for( U32 i=0; i < num_frames; i++ ) - { - Frame frame = GetFrame( i ); + bool warning_flag = false; + if( ( frame.mFlags & DISPLAY_AS_WARNING_FLAG ) != 0 ) + warning_flag = true; - bool warning_flag = false; - if( ( frame.mFlags & DISPLAY_AS_WARNING_FLAG ) != 0 ) - warning_flag = true; - - char packet_id_str[128]; - U64 packet_id = GetPacketContainingFrameSequential( i ); - if( packet_id != INVALID_RESULT_INDEX ) - AnalyzerHelpers::GetNumberString( packet_id, Decimal, 0, packet_id_str, 128 ); - else - packet_id_str[0] = 0; + char packet_id_str[ 128 ]; + U64 packet_id = GetPacketContainingFrameSequential( i ); + if( packet_id != INVALID_RESULT_INDEX ) + AnalyzerHelpers::GetNumberString( packet_id, Decimal, 0, packet_id_str, 128 ); + else + packet_id_str[ 0 ] = 0; - ss << packet_id_str << ","; + ss << packet_id_str << ","; - char time_str[128]; - AnalyzerHelpers::GetTimeString( frame.mStartingSampleInclusive, trigger_sample, sample_rate, time_str, 128 ); + char time_str[ 128 ]; + AnalyzerHelpers::GetTimeString( frame.mStartingSampleInclusive, trigger_sample, sample_rate, time_str, 128 ); - ss << time_str << ","; - //RestartPulse, PresencePulse, ReadRomFrame, SkipRomFrame, SearchRomFrame, AlarmSearchFrame, MatchRomFrame, OverdriveSkipRomFrame, OverdriveMatchRomFrame, CRC, FamilyCode, Rom, Byte, Bit - char number_str[128]; - AnalyzerHelpers::GetNumberString( frame.mData1, display_base, 8, number_str, 128); - switch( (OneWireFrameType)frame.mType ) - { - case RestartPulse: - { - if( warning_flag == false ) //correct reset pulse. - ss << "Reset Pulse"; - else //out of spec reset pulse. - ss << "Reset Pulse ( out of spec )"; - } - break; - case PresencePulse: - { - ss << "Presence Pulse"; - } - break; - case ReadRomFrame: - { - ss << "Read Rom Command" << ", " << number_str; - } - break; - case SkipRomFrame: - { - ss << "Skip Rom Command" << ", " << number_str; - } - break; - case SearchRomFrame: - { - ss << "Search Rom Command" << ", " << number_str; - } - break; - case AlarmSearchFrame: - { - ss << "Alarm Search Rom Command" << ", " << number_str; - } - break; - case MatchRomFrame: - { - ss << "Match Rom Command" << ", " << number_str; - } - break; - case OverdriveSkipRomFrame: - { - ss << "Overdrive Skip Rom Command" << ", " << number_str; - } - break; - case OverdriveMatchRomFrame: - { - ss << "Overdrive Match Rom Command" << ", " << number_str; - } - break; - case CRC: - { - ss << "ROM CRC" << ", " << number_str; - } - break; - case FamilyCode: - { - ss << "ROM Family Code" << ", " << number_str; - } - break; - case Rom: - { - AnalyzerHelpers::GetNumberString( frame.mData1, display_base, 48, number_str, 128 ); - ss << "ROM Code" << ", " << number_str; + ss << time_str << ","; + // RestartPulse, PresencePulse, ReadRomFrame, SkipRomFrame, SearchRomFrame, AlarmSearchFrame, MatchRomFrame, OverdriveSkipRomFrame, + // OverdriveMatchRomFrame, CRC, FamilyCode, Rom, Byte, Bit + char number_str[ 128 ]; + AnalyzerHelpers::GetNumberString( frame.mData1, display_base, 8, number_str, 128 ); + switch( ( OneWireFrameType )frame.mType ) + { + case RestartPulse: + { + if( warning_flag == false ) // correct reset pulse. + ss << "Reset Pulse"; + else // out of spec reset pulse. + ss << "Reset Pulse ( out of spec )"; + } + break; + case PresencePulse: + { + ss << "Presence Pulse"; + } + break; + case ReadRomFrame: + { + ss << "Read Rom Command" + << ", " << number_str; + } + break; + case SkipRomFrame: + { + ss << "Skip Rom Command" + << ", " << number_str; + } + break; + case SearchRomFrame: + { + ss << "Search Rom Command" + << ", " << number_str; + } + break; + case AlarmSearchFrame: + { + ss << "Alarm Search Rom Command" + << ", " << number_str; + } + break; + case MatchRomFrame: + { + ss << "Match Rom Command" + << ", " << number_str; + } + break; + case OverdriveSkipRomFrame: + { + ss << "Overdrive Skip Rom Command" + << ", " << number_str; + } + break; + case OverdriveMatchRomFrame: + { + ss << "Overdrive Match Rom Command" + << ", " << number_str; + } + break; + case CRC: + { + ss << "ROM CRC" + << ", " << number_str; + } + break; + case FamilyCode: + { + ss << "ROM Family Code" + << ", " << number_str; + } + break; + case Rom: + { + AnalyzerHelpers::GetNumberString( frame.mData1, display_base, 48, number_str, 128 ); + ss << "ROM Code" + << ", " << number_str; + } + break; + case Byte: + { + ss << "Data" + << ", " << number_str; + } + break; + case Bit: + { + } + break; + case InvalidRomCommandFrame: + { + ss << "Invalid Rom Command" + << ", " << number_str; + } + break; + } - } - break; - case Byte: - { - ss << "Data" << ", " << number_str; - } - break; - case Bit: - { - } - break; - case InvalidRomCommandFrame: - { - ss << "Invalid Rom Command" << ", " << number_str; - } - break; - } + ss << std::endl; - ss << std::endl; + AnalyzerHelpers::AppendToFile( ( U8* )ss.str().c_str(), ss.str().length(), f ); + ss.str( std::string() ); - AnalyzerHelpers::AppendToFile( (U8*)ss.str().c_str(), ss.str().length(), f ); - ss.str( std::string() ); - - if( UpdateExportProgressAndCheckForCancel( i, num_frames ) == true ) - { - AnalyzerHelpers::EndFile( f ); - return; - } - } + if( UpdateExportProgressAndCheckForCancel( i, num_frames ) == true ) + { + AnalyzerHelpers::EndFile( f ); + return; + } + } - UpdateExportProgressAndCheckForCancel( num_frames, num_frames ); - AnalyzerHelpers::EndFile( f ); + UpdateExportProgressAndCheckForCancel( num_frames, num_frames ); + AnalyzerHelpers::EndFile( f ); } void OneWireAnalyzerResults::GenerateFrameTabularText( U64 frame_index, DisplayBase display_base ) { - Frame frame = GetFrame( frame_index ); + Frame frame = GetFrame( frame_index ); ClearTabularText(); - bool warning_flag = false; - if( ( frame.mFlags & DISPLAY_AS_WARNING_FLAG ) != 0 ) - warning_flag = true; + bool warning_flag = false; + if( ( frame.mFlags & DISPLAY_AS_WARNING_FLAG ) != 0 ) + warning_flag = true; - //RestartPulse, PresencePulse, ReadRomFrame, SkipRomFrame, SearchRomFrame, AlarmSearchFrame, MatchRomFrame, OverdriveSkipRomFrame, OverdriveMatchRomFrame, CRC, FamilyCode, Rom, Byte, Bit - char number_str[128]; - AnalyzerHelpers::GetNumberString( frame.mData1, display_base, 8, number_str, 128 ); - - switch( (OneWireFrameType)frame.mType ) - { - case RestartPulse: - { - if( warning_flag == false ) - { - AddTabularText( "RESET condition" ); - } - else - { - AddTabularText( "RESET - warning, pulse shorter than 480us" ); - } - } - break; - case PresencePulse: - { - AddTabularText( "PRESENCE condition" ); - } - break; - case ReadRomFrame: - { - AddTabularText( "READ ROM command: [", number_str, "]" ); - } - break; - case SkipRomFrame: - { - AddTabularText( "SKIP ROM command: [", number_str, "]" ); - } - break; - case SearchRomFrame: - { - AddTabularText( "SEARCH ROM command: [", number_str, "]" ); - } - break; - case AlarmSearchFrame: - { - AddTabularText( "ALARM SEARCH ROM command: [", number_str, "]" ); - } - break; - case MatchRomFrame: - { - AddTabularText( "MATCH ROM command: [", number_str, "]" ); - } - break; - case OverdriveSkipRomFrame: - { - AddTabularText( "OVERDRIVE SKIP ROM command: [", number_str, "]" ); - } - break; - case OverdriveMatchRomFrame: - { - AddTabularText( "OVERDRIVE MATCH ROM command: [", number_str, "]" ); - } - break; - case CRC: - { - AddTabularText( "CRC section from ROM: [", number_str, "]" ); - } - break; - case FamilyCode: - { - AddTabularText( "FAMILY CODE section from ROM: [", number_str, "]" ); - } - break; - case Rom: - { - AnalyzerHelpers::GetNumberString( frame.mData1, display_base, 48, number_str, 128 ); - AddTabularText( "ROM CODE section from ROM: [", number_str, "]" ); - } - break; - case Byte: - { - AddTabularText( "DATA: [", number_str, "]" ); - } - break; - case Bit: - { - AddTabularText( "BIT - ERROR." ); - } - break; - case InvalidRomCommandFrame: - { - AddTabularText( "Invalid ROM command: [", number_str, "]" ); - } - break; - } + // RestartPulse, PresencePulse, ReadRomFrame, SkipRomFrame, SearchRomFrame, AlarmSearchFrame, MatchRomFrame, OverdriveSkipRomFrame, + // OverdriveMatchRomFrame, CRC, FamilyCode, Rom, Byte, Bit + char number_str[ 128 ]; + AnalyzerHelpers::GetNumberString( frame.mData1, display_base, 8, number_str, 128 ); + switch( ( OneWireFrameType )frame.mType ) + { + case RestartPulse: + { + if( warning_flag == false ) + { + AddTabularText( "RESET condition" ); + } + else + { + AddTabularText( "RESET - warning, pulse shorter than 480us" ); + } + } + break; + case PresencePulse: + { + AddTabularText( "PRESENCE condition" ); + } + break; + case ReadRomFrame: + { + AddTabularText( "READ ROM command: [", number_str, "]" ); + } + break; + case SkipRomFrame: + { + AddTabularText( "SKIP ROM command: [", number_str, "]" ); + } + break; + case SearchRomFrame: + { + AddTabularText( "SEARCH ROM command: [", number_str, "]" ); + } + break; + case AlarmSearchFrame: + { + AddTabularText( "ALARM SEARCH ROM command: [", number_str, "]" ); + } + break; + case MatchRomFrame: + { + AddTabularText( "MATCH ROM command: [", number_str, "]" ); + } + break; + case OverdriveSkipRomFrame: + { + AddTabularText( "OVERDRIVE SKIP ROM command: [", number_str, "]" ); + } + break; + case OverdriveMatchRomFrame: + { + AddTabularText( "OVERDRIVE MATCH ROM command: [", number_str, "]" ); + } + break; + case CRC: + { + AddTabularText( "CRC section from ROM: [", number_str, "]" ); + } + break; + case FamilyCode: + { + AddTabularText( "FAMILY CODE section from ROM: [", number_str, "]" ); + } + break; + case Rom: + { + AnalyzerHelpers::GetNumberString( frame.mData1, display_base, 48, number_str, 128 ); + AddTabularText( "ROM CODE section from ROM: [", number_str, "]" ); + } + break; + case Byte: + { + AddTabularText( "DATA: [", number_str, "]" ); + } + break; + case Bit: + { + AddTabularText( "BIT - ERROR." ); + } + break; + case InvalidRomCommandFrame: + { + AddTabularText( "Invalid ROM command: [", number_str, "]" ); + } + break; + } } -void OneWireAnalyzerResults::GeneratePacketTabularText( U64 /*packet_id*/, DisplayBase /*display_base*/ ) //unrefereced vars commented out to remove warnings. +void OneWireAnalyzerResults::GeneratePacketTabularText( U64 /*packet_id*/, + DisplayBase /*display_base*/ ) // unrefereced vars commented out to remove warnings. { - ClearResultStrings(); - AddResultString( "not supported" ); + ClearResultStrings(); + AddResultString( "not supported" ); } -void OneWireAnalyzerResults::GenerateTransactionTabularText( U64 /*transaction_id*/, DisplayBase /*display_base*/ ) //unrefereced vars commented out to remove warnings. +void OneWireAnalyzerResults::GenerateTransactionTabularText( + U64 /*transaction_id*/, DisplayBase /*display_base*/ ) // unrefereced vars commented out to remove warnings. { - ClearResultStrings(); - AddResultString( "not supported" ); + ClearResultStrings(); + AddResultString( "not supported" ); } diff --git a/src/OneWireAnalyzerResults.h b/src/OneWireAnalyzerResults.h index 888a0dc..9387549 100644 --- a/src/OneWireAnalyzerResults.h +++ b/src/OneWireAnalyzerResults.h @@ -11,22 +11,21 @@ class OneWireAnalyzerSettings; class OneWireAnalyzerResults : public AnalyzerResults { -public: - OneWireAnalyzerResults( OneWireAnalyzer* analyzer, OneWireAnalyzerSettings* settings ); - virtual ~OneWireAnalyzerResults(); + public: + OneWireAnalyzerResults( OneWireAnalyzer* analyzer, OneWireAnalyzerSettings* settings ); + virtual ~OneWireAnalyzerResults(); - virtual void GenerateBubbleText( U64 frame_index, Channel& channel, DisplayBase display_base ); - virtual void GenerateExportFile( const char* file, DisplayBase display_base, U32 export_type_user_id ); + virtual void GenerateBubbleText( U64 frame_index, Channel& channel, DisplayBase display_base ); + virtual void GenerateExportFile( const char* file, DisplayBase display_base, U32 export_type_user_id ); - virtual void GenerateFrameTabularText(U64 frame_index, DisplayBase display_base ); - virtual void GeneratePacketTabularText( U64 packet_id, DisplayBase display_base ); - virtual void GenerateTransactionTabularText( U64 transaction_id, DisplayBase display_base ); + virtual void GenerateFrameTabularText( U64 frame_index, DisplayBase display_base ); + virtual void GeneratePacketTabularText( U64 packet_id, DisplayBase display_base ); + virtual void GenerateTransactionTabularText( U64 transaction_id, DisplayBase display_base ); -protected: //functions - -protected: //vars - OneWireAnalyzerSettings* mSettings; - OneWireAnalyzer* mAnalyzer; + protected: // functions + protected: // vars + OneWireAnalyzerSettings* mSettings; + OneWireAnalyzer* mAnalyzer; }; -#endif //ONE_WIRE_ANALYZER_RESULTS +#endif // ONE_WIRE_ANALYZER_RESULTS diff --git a/src/OneWireAnalyzerSettings.cpp b/src/OneWireAnalyzerSettings.cpp index d1f1c4c..2d8f825 100644 --- a/src/OneWireAnalyzerSettings.cpp +++ b/src/OneWireAnalyzerSettings.cpp @@ -4,29 +4,27 @@ #include #include -OneWireAnalyzerSettings::OneWireAnalyzerSettings() -: mOneWireChannel ( UNDEFINED_CHANNEL ), -mOverdrive( false ) +OneWireAnalyzerSettings::OneWireAnalyzerSettings() : mOneWireChannel( UNDEFINED_CHANNEL ), mOverdrive( false ) { - mOneWireChannelInterface.reset( new AnalyzerSettingInterfaceChannel() ); - mOneWireChannelInterface->SetTitleAndTooltip( "1-Wire", "Maxim 1-Wire Interface" ); - mOneWireChannelInterface->SetChannel( mOneWireChannel ); + mOneWireChannelInterface.reset( new AnalyzerSettingInterfaceChannel() ); + mOneWireChannelInterface->SetTitleAndTooltip( "1-Wire", "Maxim 1-Wire Interface" ); + mOneWireChannelInterface->SetChannel( mOneWireChannel ); - mOverDriveInterface.reset( new AnalyzerSettingInterfaceBool() ); - mOverDriveInterface->SetTitleAndTooltip( "", "The analyzer will only operate at high speed overdrive mode." ); - mOverDriveInterface->SetCheckBoxText( "Overdrive only mode" ); - mOverDriveInterface->SetValue( false ); + mOverDriveInterface.reset( new AnalyzerSettingInterfaceBool() ); + mOverDriveInterface->SetTitleAndTooltip( "", "The analyzer will only operate at high speed overdrive mode." ); + mOverDriveInterface->SetCheckBoxText( "Overdrive only mode" ); + mOverDriveInterface->SetValue( false ); - AddInterface( mOneWireChannelInterface.get() ); - AddInterface( mOverDriveInterface.get() ); + AddInterface( mOneWireChannelInterface.get() ); + AddInterface( mOverDriveInterface.get() ); - //AddExportOption( 0, "Export as text/csv file", "text (*.txt);;csv (*.csv)" ); - AddExportOption( 0, "Export as text/csv file" ); - AddExportExtension( 0, "text", "txt" ); - AddExportExtension( 0, "csv", "csv" ); + // AddExportOption( 0, "Export as text/csv file", "text (*.txt);;csv (*.csv)" ); + AddExportOption( 0, "Export as text/csv file" ); + AddExportExtension( 0, "text", "txt" ); + AddExportExtension( 0, "csv", "csv" ); - ClearChannels(); - AddChannel( mOneWireChannel, "1-WIRE", false ); + ClearChannels(); + AddChannel( mOneWireChannel, "1-WIRE", false ); } OneWireAnalyzerSettings::~OneWireAnalyzerSettings() @@ -35,48 +33,47 @@ OneWireAnalyzerSettings::~OneWireAnalyzerSettings() void OneWireAnalyzerSettings::UpdateInterfacesFromSettings() { - mOneWireChannelInterface->SetChannel( mOneWireChannel ); - mOverDriveInterface->SetValue( mOverdrive ); + mOneWireChannelInterface->SetChannel( mOneWireChannel ); + mOverDriveInterface->SetValue( mOverdrive ); } bool OneWireAnalyzerSettings::SetSettingsFromInterfaces() { - mOneWireChannel = mOneWireChannelInterface->GetChannel(); - mOverdrive = mOverDriveInterface->GetValue(); + mOneWireChannel = mOneWireChannelInterface->GetChannel(); + mOverdrive = mOverDriveInterface->GetValue(); - ClearChannels(); - AddChannel( mOneWireChannel, "1-WIRE", true ); + ClearChannels(); + AddChannel( mOneWireChannel, "1-WIRE", true ); - return true; + return true; } void OneWireAnalyzerSettings::LoadSettings( const char* settings ) { - SimpleArchive text_archive; - text_archive.SetString( settings ); + SimpleArchive text_archive; + text_archive.SetString( settings ); - const char* name_string; //the first thing in the archive is the name of the protocol analyzer that the data belongs to. - text_archive >> &name_string; - if( strcmp( name_string, "SaleaeOneWireAnalyzer" ) != 0 ) - AnalyzerHelpers::Assert( "SaleaeOneWireAnalyzer: Provided with a settings string that doesn't belong to us;" ); + const char* name_string; // the first thing in the archive is the name of the protocol analyzer that the data belongs to. + text_archive >> &name_string; + if( strcmp( name_string, "SaleaeOneWireAnalyzer" ) != 0 ) + AnalyzerHelpers::Assert( "SaleaeOneWireAnalyzer: Provided with a settings string that doesn't belong to us;" ); - text_archive >> mOneWireChannel; - text_archive >> mOverdrive; + text_archive >> mOneWireChannel; + text_archive >> mOverdrive; - ClearChannels(); - AddChannel( mOneWireChannel, "1-WIRE", true ); + ClearChannels(); + AddChannel( mOneWireChannel, "1-WIRE", true ); - UpdateInterfacesFromSettings(); + UpdateInterfacesFromSettings(); } const char* OneWireAnalyzerSettings::SaveSettings() { - SimpleArchive text_archive; + SimpleArchive text_archive; - text_archive << "SaleaeOneWireAnalyzer"; - text_archive << mOneWireChannel; - text_archive << mOverdrive; + text_archive << "SaleaeOneWireAnalyzer"; + text_archive << mOneWireChannel; + text_archive << mOverdrive; - return SetReturnString( text_archive.GetString() ); + return SetReturnString( text_archive.GetString() ); } - diff --git a/src/OneWireAnalyzerSettings.h b/src/OneWireAnalyzerSettings.h index 317b504..359e025 100644 --- a/src/OneWireAnalyzerSettings.h +++ b/src/OneWireAnalyzerSettings.h @@ -6,22 +6,22 @@ class OneWireAnalyzerSettings : public AnalyzerSettings { -public: - OneWireAnalyzerSettings(); - virtual ~OneWireAnalyzerSettings(); + public: + OneWireAnalyzerSettings(); + virtual ~OneWireAnalyzerSettings(); - virtual bool SetSettingsFromInterfaces(); //Get the settings out of the interfaces, validate them, and save them to your local settings vars. - virtual void LoadSettings( const char* settings ); //Load your settings from a string. - virtual const char* SaveSettings(); //Save your settings to a string. + virtual bool + SetSettingsFromInterfaces(); // Get the settings out of the interfaces, validate them, and save them to your local settings vars. + virtual void LoadSettings( const char* settings ); // Load your settings from a string. + virtual const char* SaveSettings(); // Save your settings to a string. - void UpdateInterfacesFromSettings(); + void UpdateInterfacesFromSettings(); - Channel mOneWireChannel; - bool mOverdrive; - -protected: - std::auto_ptr< AnalyzerSettingInterfaceChannel > mOneWireChannelInterface; - std::auto_ptr< AnalyzerSettingInterfaceBool > mOverDriveInterface; + Channel mOneWireChannel; + bool mOverdrive; + protected: + std::auto_ptr mOneWireChannelInterface; + std::auto_ptr mOverDriveInterface; }; -#endif //ONEWIRE_ANALYZER_SETTINGS +#endif // ONEWIRE_ANALYZER_SETTINGS diff --git a/src/OneWireSimulationDataGenerator.cpp b/src/OneWireSimulationDataGenerator.cpp index e9cc6dc..d368a32 100644 --- a/src/OneWireSimulationDataGenerator.cpp +++ b/src/OneWireSimulationDataGenerator.cpp @@ -3,304 +3,297 @@ OneWireSimulationDataGenerator::OneWireSimulationDataGenerator() { - } OneWireSimulationDataGenerator::~OneWireSimulationDataGenerator() { - } void OneWireSimulationDataGenerator::Initialize( U32 simulation_sample_rate, OneWireAnalyzerSettings* settings ) { - mSimulationSampleRateHz = simulation_sample_rate; - mSettings = settings; - - mOneWireSimulationData.SetChannel( mSettings->mOneWireChannel ); - mOneWireSimulationData.SetSampleRate( simulation_sample_rate ); - - mOneWireSimulationData.SetInitialBitState( BIT_HIGH ); - //mOneWireSimulationData.Advance( 1000 ); - mSimOverdrive = mSettings->mOverdrive; + mSimulationSampleRateHz = simulation_sample_rate; + mSettings = settings; + mOneWireSimulationData.SetChannel( mSettings->mOneWireChannel ); + mOneWireSimulationData.SetSampleRate( simulation_sample_rate ); + mOneWireSimulationData.SetInitialBitState( BIT_HIGH ); + // mOneWireSimulationData.Advance( 1000 ); + mSimOverdrive = mSettings->mOverdrive; } -U32 OneWireSimulationDataGenerator::GenerateSimulationData( U64 largest_sample_requested, U32 sample_rate, SimulationChannelDescriptor** simulation_channels ) +U32 OneWireSimulationDataGenerator::GenerateSimulationData( U64 largest_sample_requested, U32 sample_rate, + SimulationChannelDescriptor** simulation_channels ) { - U64 adjusted_largest_sample_requested = AnalyzerHelpers::AdjustSimulationTargetSample( largest_sample_requested, sample_rate, mSimulationSampleRateHz ); - - while( mOneWireSimulationData.GetCurrentSampleNumber() < adjusted_largest_sample_requested ) - { - U32 delay; - if(mSimOverdrive == true) - delay = 30; - else - delay = 250; - - mOneWireSimulationData.Advance( U32(UsToSamples(delay * 3 )) ); - //mSimulationSampleIndex += UsToSamples(delay * 3, true); - - SimResetPacket(); - SimReadRom(0x8877665544332211ull); - - //mSimulationSampleIndex += UsToSamples(delay, true); - mOneWireSimulationData.Advance( U32( UsToSamples(delay ) ) ); - SimWriteByte(0x37); - //mSimulationSampleIndex += UsToSamples(delay, true); - mOneWireSimulationData.Advance( U32( UsToSamples(delay ) ) ); - SimWriteByte(0xF0); - - std::vector device_ROMs; - device_ROMs.push_back(0x8877665544332211ull); - device_ROMs.push_back(0x1122334455667788ull); - - SimResetPacket(); - U64 found_device; - found_device = SimSearchRom( device_ROMs ); - - //mSimulationSampleIndex += UsToSamples(delay, true); - mOneWireSimulationData.Advance( U32( UsToSamples(delay ) ) ); - SimWriteByte(0x0F); - //mSimulationSampleIndex += UsToSamples(delay, true); - mOneWireSimulationData.Advance( U32( UsToSamples(delay ) ) ); - SimWriteByte(0xF0); - //mSimulationSampleIndex += UsToSamples(delay, true); - mOneWireSimulationData.Advance( U32( UsToSamples(delay ) ) ); - SimWriteByte(0x55); - //mSimulationSampleIndex += UsToSamples(delay, true); - mOneWireSimulationData.Advance( U32( UsToSamples(delay ) ) ); - SimWriteByte(0x18); - - SimResetPacket(); - SimMatchRom(0xF0E1D2C3B4A59687ull); - - - //mSimulationSampleIndex += UsToSamples(delay, true); - mOneWireSimulationData.Advance( U32( UsToSamples(delay ) ) ); - SimWriteByte(0x55); - //mSimulationSampleIndex += UsToSamples(delay, true); - mOneWireSimulationData.Advance( U32( UsToSamples(delay ) ) ); - SimWriteByte(0x18); - - - SimResetPacket(); - //mSimulationSampleIndex += UsToSamples(delay, true); - mOneWireSimulationData.Advance( U32( UsToSamples( delay ) ) ); - SimWriteByte( 0xEC ); - - - if( !mSimOverdrive ) - { - SimResetPacket(); - SimOverdriveSkipRom(); - } - - } - - *simulation_channels = &mOneWireSimulationData; - - - - return 1; // we are retuning the size of the SimulationChannelDescriptor array. In our case, the "array" is length 1. + U64 adjusted_largest_sample_requested = + AnalyzerHelpers::AdjustSimulationTargetSample( largest_sample_requested, sample_rate, mSimulationSampleRateHz ); + + while( mOneWireSimulationData.GetCurrentSampleNumber() < adjusted_largest_sample_requested ) + { + U32 delay; + if( mSimOverdrive == true ) + delay = 30; + else + delay = 250; + + mOneWireSimulationData.Advance( U32( UsToSamples( delay * 3 ) ) ); + // mSimulationSampleIndex += UsToSamples(delay * 3, true); + + SimResetPacket(); + SimReadRom( 0x8877665544332211ull ); + + // mSimulationSampleIndex += UsToSamples(delay, true); + mOneWireSimulationData.Advance( U32( UsToSamples( delay ) ) ); + SimWriteByte( 0x37 ); + // mSimulationSampleIndex += UsToSamples(delay, true); + mOneWireSimulationData.Advance( U32( UsToSamples( delay ) ) ); + SimWriteByte( 0xF0 ); + + std::vector device_ROMs; + device_ROMs.push_back( 0x8877665544332211ull ); + device_ROMs.push_back( 0x1122334455667788ull ); + + SimResetPacket(); + U64 found_device; + found_device = SimSearchRom( device_ROMs ); + + // mSimulationSampleIndex += UsToSamples(delay, true); + mOneWireSimulationData.Advance( U32( UsToSamples( delay ) ) ); + SimWriteByte( 0x0F ); + // mSimulationSampleIndex += UsToSamples(delay, true); + mOneWireSimulationData.Advance( U32( UsToSamples( delay ) ) ); + SimWriteByte( 0xF0 ); + // mSimulationSampleIndex += UsToSamples(delay, true); + mOneWireSimulationData.Advance( U32( UsToSamples( delay ) ) ); + SimWriteByte( 0x55 ); + // mSimulationSampleIndex += UsToSamples(delay, true); + mOneWireSimulationData.Advance( U32( UsToSamples( delay ) ) ); + SimWriteByte( 0x18 ); + + SimResetPacket(); + SimMatchRom( 0xF0E1D2C3B4A59687ull ); + + + // mSimulationSampleIndex += UsToSamples(delay, true); + mOneWireSimulationData.Advance( U32( UsToSamples( delay ) ) ); + SimWriteByte( 0x55 ); + // mSimulationSampleIndex += UsToSamples(delay, true); + mOneWireSimulationData.Advance( U32( UsToSamples( delay ) ) ); + SimWriteByte( 0x18 ); + + + SimResetPacket(); + // mSimulationSampleIndex += UsToSamples(delay, true); + mOneWireSimulationData.Advance( U32( UsToSamples( delay ) ) ); + SimWriteByte( 0xEC ); + + + if( !mSimOverdrive ) + { + SimResetPacket(); + SimOverdriveSkipRom(); + } + } + + *simulation_channels = &mOneWireSimulationData; + + + return 1; // we are retuning the size of the SimulationChannelDescriptor array. In our case, the "array" is length 1. } -void OneWireSimulationDataGenerator::SimReadRom ( U64 rom ) -{ //ROM: CRC:SERIAL:FAMILY, 1:6:1 - //Code: 0x33 - SimWriteByte(0x33); - SimWriteByte(U32((rom & 0x00000000000000FFull))); //family code - SimWriteByte(U32((rom & 0x000000000000FF00ull)>>8)); //Serial 1 - SimWriteByte(U32((rom & 0x0000000000FF0000ull)>>16)); //Serial 2 - SimWriteByte(U32((rom & 0x00000000FF000000ull)>>24)); //Serial 3 - SimWriteByte(U32((rom & 0x000000FF00000000ull)>>32)); //Serial 4 - SimWriteByte(U32((rom & 0x0000FF0000000000ull)>>40)); //Serial 5 - SimWriteByte(U32((rom & 0x00FF000000000000ull)>>48)); //Serial 6 - SimWriteByte(U32((rom & 0xFF00000000000000ull)>>56)); //CRC - +void OneWireSimulationDataGenerator::SimReadRom( U64 rom ) +{ // ROM: CRC:SERIAL:FAMILY, 1:6:1 + // Code: 0x33 + SimWriteByte( 0x33 ); + SimWriteByte( U32( ( rom & 0x00000000000000FFull ) ) ); // family code + SimWriteByte( U32( ( rom & 0x000000000000FF00ull ) >> 8 ) ); // Serial 1 + SimWriteByte( U32( ( rom & 0x0000000000FF0000ull ) >> 16 ) ); // Serial 2 + SimWriteByte( U32( ( rom & 0x00000000FF000000ull ) >> 24 ) ); // Serial 3 + SimWriteByte( U32( ( rom & 0x000000FF00000000ull ) >> 32 ) ); // Serial 4 + SimWriteByte( U32( ( rom & 0x0000FF0000000000ull ) >> 40 ) ); // Serial 5 + SimWriteByte( U32( ( rom & 0x00FF000000000000ull ) >> 48 ) ); // Serial 6 + SimWriteByte( U32( ( rom & 0xFF00000000000000ull ) >> 56 ) ); // CRC } -void OneWireSimulationDataGenerator::SimSkipRom () +void OneWireSimulationDataGenerator::SimSkipRom() { - //Code: 0xCC - SimWriteByte(0xCC); - + // Code: 0xCC + SimWriteByte( 0xCC ); } void OneWireSimulationDataGenerator::SimMatchRom( U64 rom, bool overdrive ) { - //Code: 0x55 - if( overdrive == false ) - SimWriteByte(0x55); - SimWriteByte(U32((rom & 0x00000000000000FFull))); //family code - SimWriteByte(U32((rom & 0x000000000000FF00ull)>>8)); //Serial 1 - SimWriteByte(U32((rom & 0x0000000000FF0000ull)>>16)); //Serial 2 - SimWriteByte(U32((rom & 0x00000000FF000000ull)>>24)); //Serial 3 - SimWriteByte(U32((rom & 0x000000FF00000000ull)>>32)); //Serial 4 - SimWriteByte(U32((rom & 0x0000FF0000000000ull)>>40)); //Serial 5 - SimWriteByte(U32((rom & 0x00FF000000000000ull)>>48)); //Serial 6 - SimWriteByte(U32((rom & 0xFF00000000000000ull)>>56)); //CRC + // Code: 0x55 + if( overdrive == false ) + SimWriteByte( 0x55 ); + SimWriteByte( U32( ( rom & 0x00000000000000FFull ) ) ); // family code + SimWriteByte( U32( ( rom & 0x000000000000FF00ull ) >> 8 ) ); // Serial 1 + SimWriteByte( U32( ( rom & 0x0000000000FF0000ull ) >> 16 ) ); // Serial 2 + SimWriteByte( U32( ( rom & 0x00000000FF000000ull ) >> 24 ) ); // Serial 3 + SimWriteByte( U32( ( rom & 0x000000FF00000000ull ) >> 32 ) ); // Serial 4 + SimWriteByte( U32( ( rom & 0x0000FF0000000000ull ) >> 40 ) ); // Serial 5 + SimWriteByte( U32( ( rom & 0x00FF000000000000ull ) >> 48 ) ); // Serial 6 + SimWriteByte( U32( ( rom & 0xFF00000000000000ull ) >> 56 ) ); // CRC } U64 OneWireSimulationDataGenerator::SimSearchRom( std::vector& roms ) { - U64 selected_device = 0; - //Code: 0xF0 - SimWriteByte(0xF0); - //for each bit posision in each of the roms, we will check to see if they all match, or if they conflict. - for( U32 i = 0; i<64; i++ ) - { - std::vector::iterator it = roms.begin(); - - U32 rom_bit = (*it >> i) & 0x1; - U32 comp_bit = rom_bit ^ 0x1; - for(; it != roms.end(); ++it) - { - U32 current_bit = (*it >> i) & 0x1; - if (current_bit != rom_bit) - { - rom_bit = 0; - comp_bit = 0; - //Eliminate all remaining roms with a '1' at posision i. - for( std::vector::iterator delete_it = roms.begin(); delete_it != roms.end(); ++delete_it ) - { - if( ((*delete_it >> i) & 0x1) == 0x1 ) - { - delete_it = roms.erase(delete_it); - it = roms.begin(); - } - - } - - } - } - SimWriteBit(rom_bit); - SimWriteBit(comp_bit); - if(rom_bit == 1) - { - selected_device |= U64(0x1) << i; - SimWriteBit(1); - } - else - { - SimWriteBit(0); - } - - } - return selected_device; + U64 selected_device = 0; + // Code: 0xF0 + SimWriteByte( 0xF0 ); + // for each bit posision in each of the roms, we will check to see if they all match, or if they conflict. + for( U32 i = 0; i < 64; i++ ) + { + std::vector::iterator it = roms.begin(); + + U32 rom_bit = ( *it >> i ) & 0x1; + U32 comp_bit = rom_bit ^ 0x1; + for( ; it != roms.end(); ++it ) + { + U32 current_bit = ( *it >> i ) & 0x1; + if( current_bit != rom_bit ) + { + rom_bit = 0; + comp_bit = 0; + // Eliminate all remaining roms with a '1' at posision i. + for( std::vector::iterator delete_it = roms.begin(); delete_it != roms.end(); ++delete_it ) + { + if( ( ( *delete_it >> i ) & 0x1 ) == 0x1 ) + { + delete_it = roms.erase( delete_it ); + it = roms.begin(); + } + } + } + } + SimWriteBit( rom_bit ); + SimWriteBit( comp_bit ); + if( rom_bit == 1 ) + { + selected_device |= U64( 0x1 ) << i; + SimWriteBit( 1 ); + } + else + { + SimWriteBit( 0 ); + } + } + return selected_device; } void OneWireSimulationDataGenerator::SimOverdriveSkipRom() { - //Code: 0x3C - SimWriteByte(0x3C); - mSimOverdrive = true; -} + // Code: 0x3C + SimWriteByte( 0x3C ); + mSimOverdrive = true; +} void OneWireSimulationDataGenerator::SimOverdriveMatchRom( U64 rom ) { - //Code: 0x69 - SimWriteByte(0x69); - mSimOverdrive = true; - SimMatchRom( rom, true ); + // Code: 0x69 + SimWriteByte( 0x69 ); + mSimOverdrive = true; + SimMatchRom( rom, true ); } void OneWireSimulationDataGenerator::SimResetPacket() { - U32 reset_window_length = 960; - U32 reset_pulse_length = 480; - if ( ((mOneWireSimulationData.GetCurrentSampleNumber() >> 5) % 20) > 15 ) - reset_pulse_length = 440; - U32 device_responce_delay = 30; - U32 device_responce_length = 120; - - if( mSimOverdrive == true ) - { - reset_window_length = 96; - reset_pulse_length = 48; - device_responce_delay = 4; - device_responce_length = 12; - } - - //mOneWireTransitions->push_back(mSimulationSampleIndex); - mOneWireSimulationData.Transition(); - //mSimulationSampleIndex += UsToSamples(reset_pulse_length ); //Reset Pulse Length - mOneWireSimulationData.Advance( U32( UsToSamples( reset_pulse_length ) ) ); - //mOneWireTransitions->push_back(mSimulationSampleIndex); - mOneWireSimulationData.Transition(); - //mSimulationSampleIndex += UsToSamples(device_responce_delay ); //Typical delay before responce - mOneWireSimulationData.Advance( U32( UsToSamples( device_responce_delay ) ) ); - //mOneWireTransitions->push_back(mSimulationSampleIndex); - mOneWireSimulationData.Transition(); - //mSimulationSampleIndex += UsToSamples(device_responce_length ); //Typical responce length - mOneWireSimulationData.Advance( U32( UsToSamples( device_responce_length ) ) ); - //mOneWireTransitions->push_back(mSimulationSampleIndex); - mOneWireSimulationData.Transition(); - //mSimulationSampleIndex += UsToSamples( reset_window_length - reset_pulse_length - device_responce_delay - device_responce_length, true ); //Required Time for Reset and Presence opperation. - mOneWireSimulationData.Advance( U32( UsToSamples( reset_window_length - reset_pulse_length - device_responce_delay - device_responce_length ) ) ); + U32 reset_window_length = 960; + U32 reset_pulse_length = 480; + if( ( ( mOneWireSimulationData.GetCurrentSampleNumber() >> 5 ) % 20 ) > 15 ) + reset_pulse_length = 440; + U32 device_responce_delay = 30; + U32 device_responce_length = 120; + + if( mSimOverdrive == true ) + { + reset_window_length = 96; + reset_pulse_length = 48; + device_responce_delay = 4; + device_responce_length = 12; + } + + // mOneWireTransitions->push_back(mSimulationSampleIndex); + mOneWireSimulationData.Transition(); + // mSimulationSampleIndex += UsToSamples(reset_pulse_length ); //Reset Pulse Length + mOneWireSimulationData.Advance( U32( UsToSamples( reset_pulse_length ) ) ); + // mOneWireTransitions->push_back(mSimulationSampleIndex); + mOneWireSimulationData.Transition(); + // mSimulationSampleIndex += UsToSamples(device_responce_delay ); //Typical delay before responce + mOneWireSimulationData.Advance( U32( UsToSamples( device_responce_delay ) ) ); + // mOneWireTransitions->push_back(mSimulationSampleIndex); + mOneWireSimulationData.Transition(); + // mSimulationSampleIndex += UsToSamples(device_responce_length ); //Typical responce length + mOneWireSimulationData.Advance( U32( UsToSamples( device_responce_length ) ) ); + // mOneWireTransitions->push_back(mSimulationSampleIndex); + mOneWireSimulationData.Transition(); + // mSimulationSampleIndex += UsToSamples( reset_window_length - reset_pulse_length - device_responce_delay - device_responce_length, + // true ); //Required Time for Reset and Presence opperation. + mOneWireSimulationData.Advance( + U32( UsToSamples( reset_window_length - reset_pulse_length - device_responce_delay - device_responce_length ) ) ); } void OneWireSimulationDataGenerator::SimWriteBit( U32 bit ) { - U32 slot_length = 70; - U32 logic_low_length = 60; - U32 logic_high_length = 6; - - if( mSimOverdrive == true ) - { - slot_length = 8; - logic_low_length = 6; - logic_high_length = 2; - } - //mOneWireTransitions->push_back(mSimulationSampleIndex); - mOneWireSimulationData.Transition(); - if ( bit == BIT_LOW ) //0 (long) - { - //mSimulationSampleIndex += UsToSamples(logic_low_length ); - mOneWireSimulationData.Advance( U32( UsToSamples( logic_low_length ) ) ); - //mOneWireTransitions->push_back(mSimulationSampleIndex); - mOneWireSimulationData.Transition(); - //mSimulationSampleIndex += UsToSamples(slot_length - logic_low_length ); - mOneWireSimulationData.Advance( U32( UsToSamples( slot_length - logic_low_length ) ) ); - } - else if( bit == BIT_HIGH ) //1 (short) - { - //mSimulationSampleIndex += UsToSamples(logic_high_length ); - mOneWireSimulationData.Advance( U32( UsToSamples( logic_high_length ) ) ); - //mOneWireTransitions->push_back(mSimulationSampleIndex); - mOneWireSimulationData.Transition(); - //mSimulationSampleIndex += UsToSamples(slot_length - logic_high_length ); - mOneWireSimulationData.Advance( U32( UsToSamples( slot_length - logic_high_length ) ) ); - } + U32 slot_length = 70; + U32 logic_low_length = 60; + U32 logic_high_length = 6; + + if( mSimOverdrive == true ) + { + slot_length = 8; + logic_low_length = 6; + logic_high_length = 2; + } + // mOneWireTransitions->push_back(mSimulationSampleIndex); + mOneWireSimulationData.Transition(); + if( bit == BIT_LOW ) // 0 (long) + { + // mSimulationSampleIndex += UsToSamples(logic_low_length ); + mOneWireSimulationData.Advance( U32( UsToSamples( logic_low_length ) ) ); + // mOneWireTransitions->push_back(mSimulationSampleIndex); + mOneWireSimulationData.Transition(); + // mSimulationSampleIndex += UsToSamples(slot_length - logic_low_length ); + mOneWireSimulationData.Advance( U32( UsToSamples( slot_length - logic_low_length ) ) ); + } + else if( bit == BIT_HIGH ) // 1 (short) + { + // mSimulationSampleIndex += UsToSamples(logic_high_length ); + mOneWireSimulationData.Advance( U32( UsToSamples( logic_high_length ) ) ); + // mOneWireTransitions->push_back(mSimulationSampleIndex); + mOneWireSimulationData.Transition(); + // mSimulationSampleIndex += UsToSamples(slot_length - logic_high_length ); + mOneWireSimulationData.Advance( U32( UsToSamples( slot_length - logic_high_length ) ) ); + } } void OneWireSimulationDataGenerator::SimWriteByte( U32 byte ) { - //LSB first - U32 mask = 1; - for( U32 i = 0; i < 8; i++ ) - { - U32 mask_result = byte & mask; - if( mask_result != 0 ) - SimWriteBit( BIT_HIGH ); - else - SimWriteBit( BIT_LOW ); - mask = mask << 1; - } - if( mSimOverdrive == true ) - //mSimulationSampleIndex += UsToSamples( 12 ); - mOneWireSimulationData.Advance( U32( UsToSamples( 12 ) ) ); - else - //mSimulationSampleIndex += UsToSamples(120 ); - mOneWireSimulationData.Advance( U32( UsToSamples( 120 ) ) ); + // LSB first + U32 mask = 1; + for( U32 i = 0; i < 8; i++ ) + { + U32 mask_result = byte & mask; + if( mask_result != 0 ) + SimWriteBit( BIT_HIGH ); + else + SimWriteBit( BIT_LOW ); + mask = mask << 1; + } + if( mSimOverdrive == true ) + // mSimulationSampleIndex += UsToSamples( 12 ); + mOneWireSimulationData.Advance( U32( UsToSamples( 12 ) ) ); + else + // mSimulationSampleIndex += UsToSamples(120 ); + mOneWireSimulationData.Advance( U32( UsToSamples( 120 ) ) ); } U64 OneWireSimulationDataGenerator::UsToSamples( U64 us ) { - return ( mSimulationSampleRateHz * us ) / 1000000; + return ( mSimulationSampleRateHz * us ) / 1000000; } U64 OneWireSimulationDataGenerator::SamplesToUs( U64 samples ) { - return( samples * 1000000 ) / mSimulationSampleRateHz; + return ( samples * 1000000 ) / mSimulationSampleRateHz; } diff --git a/src/OneWireSimulationDataGenerator.h b/src/OneWireSimulationDataGenerator.h index 4e5d354..5d0ac0a 100644 --- a/src/OneWireSimulationDataGenerator.h +++ b/src/OneWireSimulationDataGenerator.h @@ -7,36 +7,35 @@ class OneWireAnalyzerSettings; class OneWireSimulationDataGenerator { -public: - OneWireSimulationDataGenerator(); - ~OneWireSimulationDataGenerator(); - - void Initialize( U32 simulation_sample_rate, OneWireAnalyzerSettings* settings ); - U32 GenerateSimulationData( U64 newest_sample_requested, U32 sample_rate, SimulationChannelDescriptor** simulation_channels ); - -protected: - OneWireAnalyzerSettings* mSettings; - U32 mSimulationSampleRateHz; - -protected: //Serial specific - - U64 UsToSamples( U64 us ); - U64 SamplesToUs( U64 samples ); - - //Simulation variables and functions. - void SimResetPacket(); - void SimWriteBit( U32 bit ); - void SimWriteByte( U32 byte ); - void SimReadRom ( U64 rom ); - void SimSkipRom (); - void SimMatchRom( U64 rom, bool overdrive = false ); - U64 SimSearchRom( std::vector& roms ); - void SimOverdriveSkipRom(); - void SimOverdriveMatchRom( U64 rom ); - - bool mSimOverdrive; - U64 mSimulationSampleIndex; - - SimulationChannelDescriptor mOneWireSimulationData; //if we had more than one channel to simulate, they would need to be in an array + public: + OneWireSimulationDataGenerator(); + ~OneWireSimulationDataGenerator(); + + void Initialize( U32 simulation_sample_rate, OneWireAnalyzerSettings* settings ); + U32 GenerateSimulationData( U64 newest_sample_requested, U32 sample_rate, SimulationChannelDescriptor** simulation_channels ); + + protected: + OneWireAnalyzerSettings* mSettings; + U32 mSimulationSampleRateHz; + + protected: // Serial specific + U64 UsToSamples( U64 us ); + U64 SamplesToUs( U64 samples ); + + // Simulation variables and functions. + void SimResetPacket(); + void SimWriteBit( U32 bit ); + void SimWriteByte( U32 byte ); + void SimReadRom( U64 rom ); + void SimSkipRom(); + void SimMatchRom( U64 rom, bool overdrive = false ); + U64 SimSearchRom( std::vector& roms ); + void SimOverdriveSkipRom(); + void SimOverdriveMatchRom( U64 rom ); + + bool mSimOverdrive; + U64 mSimulationSampleIndex; + + SimulationChannelDescriptor mOneWireSimulationData; // if we had more than one channel to simulate, they would need to be in an array }; -#endif //ONE_WIRE +#endif // ONE_WIRE