void JtagAnalyzer::Setup() { mTCK = GetAnalyzerChannelData(mSettings->mTCKChannel); mTMS = GetAnalyzerChannelData(mSettings->mTMSChannel); mTDI = GetAnalyzerChannelData(mSettings->mTDIChannel); mTDO = GetAnalyzerChannelData(mSettings->mTDOChannel); if (mSettings->mTRSTChannel != UNDEFINED_CHANNEL) { mTRST = GetAnalyzerChannelData(mSettings->mTRSTChannel); } else { mTRST = NULL; } switch (mSettings->mInnerProto) { case InnerPlain: mInnerAnalyzer = new JtagPlainAnalyzer(mSettings.get()); break; case InnerAVR: mInnerAnalyzer = new JtagAvrAnalyzer(mSettings.get()); break; case InnerARM: mInnerAnalyzer = new JtagArmAnalyzer(mSettings.get()); break; } }
void I2sAnalyzer::WorkerThread() { //UpArrow, DownArrow if( mSettings->mDataValidEdge == AnalyzerEnums::NegEdge ) mArrowMarker = AnalyzerResults::DownArrow; else mArrowMarker = AnalyzerResults::UpArrow; mClock = GetAnalyzerChannelData( mSettings->mClockChannel ); mFrame = GetAnalyzerChannelData( mSettings->mFrameChannel ); mData = GetAnalyzerChannelData( mSettings->mDataChannel ); SetupForGettingFirstBit(); SetupForGettingFirstFrame(); for( ; ; ) { GetFrame(); AnalyzeFrame(); mResults->CommitResults(); ReportProgress( mClock->GetSampleNumber() ); CheckIfThreadShouldExit(); } }
void HD44780Analyzer::WorkerThread() { U32 dbline; //get sample rate mSampleRateHz = GetSampleRate(); //setup channels mE = GetAnalyzerChannelData( mSettings->mEChannel ); mRS = GetAnalyzerChannelData( mSettings->mRSChannel ); if( mSettings->mRWChannel != UNDEFINED_CHANNEL ) mRW = GetAnalyzerChannelData( mSettings->mRWChannel ); else mRW = NULL; for (dbline=0;dbline<8;dbline++) if( mSettings->mDBChannel[dbline] != UNDEFINED_CHANNEL ) mDB[dbline] = GetAnalyzerChannelData( mSettings->mDBChannel[dbline] ); else mDB[dbline] = NULL; //if we start high we need to move to low if( mE->GetBitState() == BIT_HIGH) mE->AdvanceToNextEdge(); //we always start in 8-bit mode unless the force 4-bit mode option is selected //function set command can change modes bitmode8=!mSettings->mStartIn4BitMode; //reset between E high pulse measurements mLastEStart=0; //reset busy mode mWaitBusy=0; //get frames for( ; ; ) { GetTransfer(); CheckIfThreadShouldExit(); } }
void PWMAnalyzer::WorkerThread() { mSampleRateHz = GetSampleRate(); mPWM = GetAnalyzerChannelData(mSettings->mInputChannel); // Find the next full pulse for a clean start. mPWM->AdvanceToNextEdge(); if (mPWM->GetBitState() == BIT_LOW) { mPWM->AdvanceToNextEdge(); } int type = mSettings->mAnalysisType; double prevval(0); for (;;) { U64 start = mPWM->GetSampleNumber(); // Rising mPWM->AdvanceToNextEdge(); U64 mid = mPWM->GetSampleNumber(); // Falling mPWM->AdvanceToNextEdge(); U64 end = mPWM->GetSampleNumber(); // Rising double val = Value(start, mid, end); if (std::abs(val - prevval) >= mSettings->mMinChange) { mResults->AddMarker(end - ((end - start) / 2), val > prevval ? AnalyzerResults::UpArrow : AnalyzerResults::DownArrow, mSettings->mInputChannel); Frame frame; frame.mData1 = mid; frame.mStartingSampleInclusive = start; frame.mEndingSampleInclusive = end; mResults->AddFrame(frame); mResults->CommitResults(); ReportProgress(frame.mEndingSampleInclusive); prevval = val; } } }
void SimpleParallelAnalyzer::WorkerThread() { mResults->AddChannelBubblesWillAppearOn( mSettings->mClockChannel ); mSampleRateHz = GetSampleRate(); AnalyzerResults::MarkerType clock_arrow; if( mSettings->mClockEdge == AnalyzerEnums::NegEdge ) clock_arrow = AnalyzerResults::DownArrow; else clock_arrow = AnalyzerResults::UpArrow; mClock = GetAnalyzerChannelData( mSettings->mClockChannel ); mData.clear(); mDataMasks.clear(); U32 count = mSettings->mDataChannels.size(); for( U32 i=0; i<count; i++ ) { if( mSettings->mDataChannels[i] != UNDEFINED_CHANNEL ) { mData.push_back( GetAnalyzerChannelData( mSettings->mDataChannels[i] ) ); mDataMasks.push_back( 1 << i ); mDataChannels.push_back( mSettings->mDataChannels[i] ); } } U32 num_data_lines = mData.size(); if( mSettings->mClockEdge == AnalyzerEnums::NegEdge ) { if( mClock->GetBitState() == BIT_LOW ) mClock->AdvanceToNextEdge(); }else { if( mClock->GetBitState() == BIT_HIGH ) mClock->AdvanceToNextEdge(); } mClock->AdvanceToNextEdge(); //this is the data-valid edge for( ; ; ) { U64 sample = mClock->GetSampleNumber(); mResults->AddMarker( sample, clock_arrow, mSettings->mClockChannel ); U16 result = 0; for( U32 i=0; i<num_data_lines; i++ ) { mData[i]->AdvanceToAbsPosition( sample ); if( mData[i]->GetBitState() == BIT_HIGH ) { result |= mDataMasks[i]; } mResults->AddMarker( sample, AnalyzerResults::Dot, mDataChannels[i] ); } mClock->AdvanceToNextEdge(); mClock->AdvanceToNextEdge(); //this is the data-valid edge //we have a byte to save. Frame frame; frame.mData1 = result; frame.mFlags = 0; frame.mStartingSampleInclusive = sample; frame.mEndingSampleInclusive = mClock->GetSampleNumber() - 1; mResults->AddFrame( frame ); mResults->CommitResults(); ReportProgress( frame.mEndingSampleInclusive ); } }
// ============================================================================== // Main data parsing method // ============================================================================== void RFFEAnalyzer::WorkerThread() { U8 byte_count; mSampleRateHz = GetSampleRate(); mSdata = GetAnalyzerChannelData(mSettings->mSdataChannel); mSclk = GetAnalyzerChannelData(mSettings->mSclkChannel); mResults->CancelPacketAndStartNewPacket(); while (1) { try { // Look for an SSC // This method only returns false if there is no more data to be scanned // in which case, we call the Cancel and wait for new data method in the // API if (!FindStartSeqCondition()) { mResults->CancelPacketAndStartNewPacket(); break; } // Find and parse the Slave Address and the RFFE Command // Return ByteCount field - depending on the command it may or may not be // relevent byte_count = FindCommandFrame(); // We know what kind of packet we are handling now, and various parameters // including the number of data bytes. Go ahead and handle the different // cases switch (mRffeCmdType) { case RFFEAnalyzerResults::RffeTypeExtWrite: FindByteFrame(RFFEAnalyzerResults::RffeAddressField); for (U32 i = 0; i <= byte_count; i += 1) { FindByteFrame(RFFEAnalyzerResults::RffeDataField); } break; case RFFEAnalyzerResults::RffeTypeReserved: break; case RFFEAnalyzerResults::RffeTypeMasterRead: FindByteFrame(RFFEAnalyzerResults::RffeAddressField); FindBusPark(); for (U32 i = 0; i <= byte_count; i += 1) { FindByteFrame(RFFEAnalyzerResults::RffeDataField); } break; case RFFEAnalyzerResults::RffeTypeMasterWrite: FindByteFrame(RFFEAnalyzerResults::RffeAddressField); for (U32 i = 0; i <= byte_count; i += 1) { FindByteFrame(RFFEAnalyzerResults::RffeDataField); } break; case RFFEAnalyzerResults::RffeTypeMasterHandoff: FindBusPark(); for (U32 i = 0; i <= byte_count; i += 1) { FindByteFrame(RFFEAnalyzerResults::RffeDataField); } break; case RFFEAnalyzerResults::RffeTypeInterrupt: FindBusPark(); if (FindISI()) { FindInterruptSlots(); } break; case RFFEAnalyzerResults::RffeTypeExtRead: FindByteFrame(RFFEAnalyzerResults::RffeAddressField); FindBusPark(); for (U32 i = 0; i <= byte_count; i += 1) { FindByteFrame(RFFEAnalyzerResults::RffeDataField); } break; case RFFEAnalyzerResults::RffeTypeExtLongWrite: FindByteFrame(RFFEAnalyzerResults::RffeAddressHiField); FindByteFrame(RFFEAnalyzerResults::RffeAddressLoField); for (U32 i = 0; i <= byte_count; i += 1) { FindByteFrame(RFFEAnalyzerResults::RffeDataField); } break; case RFFEAnalyzerResults::RffeTypeExtLongRead: FindByteFrame(RFFEAnalyzerResults::RffeAddressHiField); FindByteFrame(RFFEAnalyzerResults::RffeAddressLoField); FindBusPark(); for (U32 i = 0; i <= byte_count; i += 1) { FindByteFrame(RFFEAnalyzerResults::RffeDataField); } break; case RFFEAnalyzerResults::RffeTypeNormalWrite: FindByteFrame(RFFEAnalyzerResults::RffeDataField); break; case RFFEAnalyzerResults::RffeTypeNormalRead: FindBusPark(); FindByteFrame(RFFEAnalyzerResults::RffeDataField); break; case RFFEAnalyzerResults::RffeTypeWrite0: break; } // Finish up with a Bus Park (except for interrupts) if (mRffeCmdType != RFFEAnalyzerResults::RffeTypeInterrupt) { FindBusPark(); } } catch (int exception) { if (exception == UNEXPECTED_SSC_EXCEPTION) { // Do nothing, this can happen } } // Commit the Result and call the API Required finished? method. mResults->CommitPacketAndStartNewPacket(); CheckIfThreadShouldExit(); } }
void IRAnalyzer::WorkerThread() { U64 tick, ntick, mtick, sample; mResults.reset( new IRAnalyzerResults( this, mSettings.get() ) ); SetAnalyzerResults( mResults.get() ); mResults->AddChannelBubblesWillAppearOn( mSettings->mInputChannel ); mSampleRateHz = GetSampleRate(); mSerial = GetAnalyzerChannelData( mSettings->mInputChannel ); U32 samples_per_bit = mSampleRateHz / mSettings->mFrequency; // 562.5 U32 samples_to_first_center_of_first_data_bit = U32( 1.5 * double( mSampleRateHz ) / double( mSettings->mFrequency ) ); // 843.75 for ( ; ; ) { if( mSerial->GetBitState() == BIT_HIGH ) { mSerial->AdvanceToNextEdge(); } tick = mSerial->GetSampleNumber(); mSerial->AdvanceToNextEdge(); ntick = mSerial->GetSampleNumber(); mtick = U32((ntick - tick)*1000000/mSampleRateHz); if (mtick > 8700 && mtick < 9300) { // Found 9ms leading burst Frame frame; frame.mData1 = 0x1; frame.mFlags = 0; frame.mStartingSampleInclusive = tick; frame.mEndingSampleInclusive = ntick; mResults->AddFrame( frame ); mResults->CommitResults(); ReportProgress( frame.mEndingSampleInclusive ); // Look for a 4.5ms space mSerial->AdvanceToNextEdge(); tick = mSerial->GetSampleNumber(); mtick = U32((tick - ntick)*1000000/mSampleRateHz); if (mtick > 4250 && mtick < 4750) { // Found 4.5ms space Frame frame; frame.mData1 = 0x2; frame.mFlags = 0; frame.mStartingSampleInclusive = ntick; frame.mEndingSampleInclusive = tick; mResults->AddFrame( frame ); mResults->CommitResults(); ReportProgress( frame.mEndingSampleInclusive ); mSerial->AdvanceToNextEdge(); tick = mSerial->GetSampleNumber(); // Decode address of receiving device tick = this->DecodeAddr(tick, 8, IRAnalyzerResults::IADDR); // Decode logical inverse of address tick = this->DecodeAddr(tick, 8, IRAnalyzerResults::ADDR); // Decode command tick = this->DecodeAddr(tick, 8, IRAnalyzerResults::CMD); // Decode logical inverse of command tick = this->DecodeAddr(tick, 8, IRAnalyzerResults::ICMD); // Space mSerial->AdvanceToNextEdge(); ntick = mSerial->GetSampleNumber(); mtick = U32((ntick - tick)*1000000/mSampleRateHz); if (mtick > 40500 && mtick < 42500) { Frame frame; frame.mData1 = 0x2; frame.mFlags = 0; frame.mStartingSampleInclusive = tick; frame.mEndingSampleInclusive = ntick; mResults->AddFrame( frame ); mResults->CommitResults(); ReportProgress( frame.mEndingSampleInclusive ); } // Repeat tick = ntick; sample = ntick; mSerial->AdvanceToNextEdge(); ntick = mSerial->GetSampleNumber(); mtick = U32((ntick - sample)*1000000/mSampleRateHz); if (mtick > 8700 && mtick < 9300) { sample = ntick; mSerial->AdvanceToNextEdge(); ntick = mSerial->GetSampleNumber(); mtick = U32((ntick - sample)*1000000/mSampleRateHz); if (mtick > 2100 && mtick < 2400) { sample = ntick; mSerial->AdvanceToNextEdge(); ntick = mSerial->GetSampleNumber(); mtick = U32((ntick - sample)*1000000/mSampleRateHz); if (mtick > 550 && mtick < 620) { Frame frame; frame.mData1 = 0x4; frame.mFlags = 0; frame.mStartingSampleInclusive = tick; frame.mEndingSampleInclusive = ntick; mResults->AddFrame( frame ); mResults->CommitResults(); ReportProgress( frame.mEndingSampleInclusive ); } } } } } } mResults->CommitResults(); }
void AcuriteAnalyzer::WorkerThread() { AcuRiteDecoder decoder; U32 lastPulse = 0; Frame frame; // for saving/printing data frame.mFlags = 0; frame.mStartingSampleInclusive = 0; mResults.reset( new AcuriteAnalyzerResults( this, mSettings.get() ) ); SetAnalyzerResults( mResults.get() ); mResults->AddChannelBubblesWillAppearOn( mSettings->mInputChannel ); mSampleRateHz = GetSampleRate(); log("mSampleRateHz is %lu", mSampleRateHz); mSampleRateMs = mSampleRateHz / 1000000; log("mSampleRateMs is %lu", mSampleRateMs); mSerial = GetAnalyzerChannelData( mSettings->mInputChannel ); log("Looking for start low..."); // Have to start on a low pulse... if( mSerial->GetBitState() == BIT_HIGH ) mSerial->AdvanceToNextEdge(); while (1) { // Find the leading edge log("looking for next leading edge"); mSerial->AdvanceToNextEdge(); // Determine the time of this pulse U64 samplepos = mSerial->GetSampleNumber() / mSampleRateMs; if ( (!frame.mStartingSampleInclusive) || decoder.state == DecodeOOK::UNKNOWN ) { frame.mStartingSampleInclusive = mSerial->GetSampleNumber(); mResults->AddMarker( mSerial->GetSampleNumber(), AnalyzerResults::Dot, mSettings->mInputChannel ); } // Pass the pulse to the decoder log("calling decoder.nextPulse(%lu)", (unsigned long)samplepos - lastPulse); if (decoder.nextPulse((unsigned long)samplepos - lastPulse)) { byte size; log("nextPulse is now done"); const byte *data = decoder.getData(size); char output[1024]; interpretData(data, size, output); decoder.resetDecoder(); // Display the data mResults->AddMarker( mSerial->GetSampleNumber(), AnalyzerResults::Dot, mSettings->mInputChannel ); frame.mEndingSampleInclusive = mSerial->GetSampleNumber(); frame.mData1 = (U64)output; // fixme - this is fugly. mResults->AddFrame( frame ); mResults->CommitResults(); ReportProgress( frame.mEndingSampleInclusive ); // reset frame for next one frame.mStartingSampleInclusive = 0; // make sure we're at a low level when we're done decoding if ( mSerial->GetBitState() == BIT_HIGH) mSerial->AdvanceToNextEdge(); } log("Decoder state is now %d", decoder.state); lastPulse = samplepos; } }
void SerialAnalyzer::WorkerThread() { mSampleRateHz = GetSampleRate(); ComputeSampleOffsets(); U32 num_bits = mSettings->mBitsPerTransfer; if( mSettings->mSerialMode != SerialAnalyzerEnums::Normal ) num_bits++; if( mSettings->mInverted == false ) { mBitHigh = BIT_HIGH; mBitLow = BIT_LOW; }else { mBitHigh = BIT_LOW; mBitLow = BIT_HIGH; } U64 bit_mask = 0; U64 mask = 0x1ULL; for( U32 i=0; i<num_bits; i++ ) { bit_mask |= mask; mask <<= 1; } mSerial = GetAnalyzerChannelData( mSettings->mInputChannel ); mSerial->TrackMinimumPulseWidth(); if( mSerial->GetBitState() == mBitLow ) mSerial->AdvanceToNextEdge(); for( ; ; ) { //we're starting high. (we'll assume that we're not in the middle of a byte. mSerial->AdvanceToNextEdge(); //we're now at the beginning of the start bit. We can start collecting the data. U64 frame_starting_sample = mSerial->GetSampleNumber(); U64 data = 0; bool parity_error = false; bool framing_error = false; bool mp_is_address = false; DataBuilder data_builder; data_builder.Reset( &data, mSettings->mShiftOrder, num_bits ); U64 marker_location = frame_starting_sample; for( U32 i=0; i<num_bits; i++ ) { mSerial->Advance( mSampleOffsets[i] ); data_builder.AddBit( mSerial->GetBitState() ); marker_location += mSampleOffsets[i]; mResults->AddMarker( marker_location, AnalyzerResults::Dot, mSettings->mInputChannel ); } if( mSettings->mInverted == true ) data = (~data) & bit_mask; if( mSettings->mSerialMode != SerialAnalyzerEnums::Normal ) { //extract the MSB U64 msb = data >> (num_bits - 1); msb &= 0x1; if( mSettings->mSerialMode == SerialAnalyzerEnums::MpModeMsbOneMeansAddress ) { if( msb == 0x0 ) mp_is_address = false; else mp_is_address = true; } if( mSettings->mSerialMode == SerialAnalyzerEnums::MpModeMsbZeroMeansAddress ) { if( msb == 0x0 ) mp_is_address = true; else mp_is_address = false; } //now remove the msb. data &= ( bit_mask >> 1 ); } parity_error = false; if( mSettings->mParity != AnalyzerEnums::None ) { mSerial->Advance( mParityBitOffset ); bool is_even = AnalyzerHelpers::IsEven( AnalyzerHelpers::GetOnesCount( data ) ); if( mSettings->mParity == AnalyzerEnums::Even ) { if( is_even == true ) { if( mSerial->GetBitState() != mBitLow ) //we expect a low bit, to keep the parity even. parity_error = true; }else { if( mSerial->GetBitState() != mBitHigh ) //we expect a high bit, to force parity even. parity_error = true; } }else //if( mSettings->mParity == AnalyzerEnums::Odd ) { if( is_even == false ) { if( mSerial->GetBitState() != mBitLow ) //we expect a low bit, to keep the parity odd. parity_error = true; }else { if( mSerial->GetBitState() != mBitHigh ) //we expect a high bit, to force parity odd. parity_error = true; } } marker_location += mParityBitOffset; mResults->AddMarker( marker_location, AnalyzerResults::Square, mSettings->mInputChannel ); } //now we must dermine if there is a framing error. framing_error = false; mSerial->Advance( mStartOfStopBitOffset ); if( mSerial->GetBitState() != mBitHigh ) { framing_error = true; }else { U32 num_edges = mSerial->Advance( mEndOfStopBitOffset ); if( num_edges != 0 ) framing_error = true; } if( framing_error == true ) { marker_location += mStartOfStopBitOffset; mResults->AddMarker( marker_location, AnalyzerResults::ErrorX, mSettings->mInputChannel ); if( mEndOfStopBitOffset != 0 ) { marker_location += mEndOfStopBitOffset; mResults->AddMarker( marker_location, AnalyzerResults::ErrorX, mSettings->mInputChannel ); } } //ok now record the value! //note that we're not using the mData2 or mType fields for anything, so we won't bother to set them. Frame frame; frame.mStartingSampleInclusive = frame_starting_sample; frame.mEndingSampleInclusive = mSerial->GetSampleNumber(); frame.mData1 = data; frame.mFlags = 0; if( parity_error == true ) frame.mFlags |= PARITY_ERROR_FLAG | DISPLAY_AS_ERROR_FLAG; if( framing_error == true ) frame.mFlags |= FRAMING_ERROR_FLAG | DISPLAY_AS_ERROR_FLAG; if( mp_is_address == true ) frame.mFlags |= MP_MODE_ADDRESS_FLAG; if( mp_is_address == true ) mResults->CommitPacketAndStartNewPacket(); mResults->AddFrame( frame ); mResults->CommitResults(); ReportProgress( frame.mEndingSampleInclusive ); CheckIfThreadShouldExit(); if( framing_error == true ) //if we're still low, let's fix that for the next round. { if( mSerial->GetBitState() == mBitLow ) mSerial->AdvanceToNextEdge(); } }
void ManchesterAnalyzer::WorkerThread() { mManchester = GetAnalyzerChannelData( mSettings->mInputChannel ); mSampleRateHz = this->GetSampleRate(); double half_peroid = 1.0 / double( mSettings->mBitRate * 2 ); half_peroid *= 1000000.0; mT = U32( ( mSampleRateHz * half_peroid ) / 1000000.0 ); switch( mSettings->mTolerance ) { case TOL25: mTError = mT / 2; break; case TOL5: mTError = mT / 10; break; case TOL05: mTError = mT / 100; break; } if( mTError < 3 ) mTError = 3; //mTError = mT / 2; mSynchronized = false; //mResults->AddMarker( mManchester->GetSampleNumber(), AnalyzerResults::One, mSettings->mInputChannel ); mManchester->AdvanceToNextEdge(); mBitsForNextByte.clear(); mUnsyncedLocations.clear(); mIgnoreBitCount = mSettings->mBitsToIgnore; for( ; ; ) { switch( mSettings->mMode ) { case MANCHESTER: { SynchronizeManchester(); ProcessManchesterData(); } break; case DIFFERENTIAL_MANCHESTER: { SynchronizeDifferential(); ProcessDifferential(); } break; case BI_PHASE_MARK: { SynchronizeBiPhase(); ProcessBiPhaseData(); } break; case BI_PHASE_SPACE: { SynchronizeBiPhase(); ProcessBiPhaseData(); } break; } //mManchester->AdvanceToNextEdge(); //mResults->CommitResults(); ReportProgress( mManchester->GetSampleNumber() ); CheckIfThreadShouldExit(); } }
void N64Analyzer::WorkerThread() { mResults.reset( new N64AnalyzerResults( this, mSettings.get() ) ); SetAnalyzerResults( mResults.get() ); mResults->AddChannelBubblesWillAppearOn( mSettings->mInputChannel ); mSampleRateHz = GetSampleRate(); mData = GetAnalyzerChannelData( mSettings->mInputChannel ); U64 one_us_low = (U64)((0.75 * (double)mSampleRateHz) / 1000000.0); U64 one_us_exact = (U64)((1.0 * (double)mSampleRateHz) / 1000000.0); U64 one_us_high = (U64)((1.25 * (double)mSampleRateHz) / 1000000.0); U64 two_us_low = (U64)((1.75 * (double)mSampleRateHz) / 1000000.0); U64 two_us_high = (U64)((2.25 * (double)mSampleRateHz) / 1000000.0); U64 three_us_low = (U64)((2.75 * (double)mSampleRateHz) / 1000000.0); U64 three_us_exact = (U64)((3.0 * (double)mSampleRateHz) / 1000000.0); U64 three_us_high = (U64)((3.25 * (double)mSampleRateHz) / 1000000.0); // Move forward until the line is high if( mData->GetBitState() == BIT_LOW ) mData->AdvanceToNextEdge(); // Move until it is low mData->AdvanceToNextEdge(); std::vector<Frame> frames; // We're now on a falling edge for (;;) { U64 low_start, low_end, high_end; low_start = mData->GetSampleNumber(); // Measure how long it takes to go high mData->AdvanceToNextEdge(); low_end = mData->GetSampleNumber(); U64 low_duration = low_end - low_start; // Measure how long it is high for mData->AdvanceToNextEdge(); high_end = mData->GetSampleNumber(); U64 high_duration = high_end - low_end; Frame frame; bool frame_valid = false; if (low_duration >= one_us_low && low_duration <= one_us_high) { if (high_duration >= three_us_low) { // Decide where to call the end of this bit U64 bit_end = high_end; if (high_duration > three_us_high) { bit_end = low_end + three_us_exact; } U64 halfway = low_start + (bit_end - low_start) / 2.0; mResults->AddMarker( halfway, AnalyzerResults::Dot, mSettings->mInputChannel ); frame.mData1 = 1; frame.mFlags = 0; frame.mStartingSampleInclusive = low_start; frame.mEndingSampleInclusive = bit_end; frame_valid = true; } else { // Might be a consolestop bit? // Put a '3' on just the low part frame.mData1 = 3; frame.mFlags = 0; frame.mStartingSampleInclusive = low_start; frame.mEndingSampleInclusive = low_end; frame_valid = true; } } else if (low_duration >= two_us_low && low_duration <= two_us_high) { // Controller stop bit // Mark only the low portion frame.mData1 = 2; frame.mFlags = 0; frame.mStartingSampleInclusive = low_start; frame.mEndingSampleInclusive = low_end; frame_valid = true; } else if (low_duration >= three_us_low && low_duration <= three_us_high) { if (high_duration >= one_us_low) { // Decide where to call the end of this bit U64 bit_end = high_end; if (high_duration > one_us_high) { bit_end = low_end + one_us_exact; } U64 halfway = low_start + (bit_end - low_start) / 2.0; mResults->AddMarker( halfway, AnalyzerResults::Dot, mSettings->mInputChannel ); frame.mData1 = 0; frame.mFlags = 0; frame.mStartingSampleInclusive = low_start; frame.mEndingSampleInclusive = bit_end; frame_valid = true; } else { // High portion was too short? should we ignore this? } } if (frame_valid) { if (frame.mData1 == 0 || frame.mData1 == 1) { frames.push_back(frame); } if (frames.size() == 8) { // Collect them as a byte frame.mData1 = (frames[0].mData1 << 7) | (frames[1].mData1 << 6) | (frames[2].mData1 << 5) | (frames[3].mData1 << 4) | (frames[4].mData1 << 3) | (frames[5].mData1 << 2) | (frames[6].mData1 << 1) | (frames[7].mData1 << 0); frame.mFlags = 0; frame.mStartingSampleInclusive = frames[0].mStartingSampleInclusive; frame.mEndingSampleInclusive = frames[7].mEndingSampleInclusive; mResults->AddFrame( frame ); mResults->CommitResults(); frames.clear(); } // Check how long it is until if (frames.size() > 0) { if ((high_end - frames[frames.size() - 1].mEndingSampleInclusive) > one_us_exact) { for (int i = 0; i < frames.size(); i++) { mResults->AddFrame( frames[i] ); mResults->CommitResults(); } frames.clear(); } } } ReportProgress( high_end ); // We are now on a falling edge which will start the next loop correctly } return; double samples_per_bit = mSampleRateHz / bitrate; U32 samples_to_first_center_of_first_data_bit = U32( 1.5 * double( mSampleRateHz ) / double( bitrate ) ); mData = GetAnalyzerChannelData( mSettings->mInputChannel ); if( mData->GetBitState() == BIT_LOW ) mData->AdvanceToNextEdge(); int state = CONTROLLER_STOP_BIT; bool idle = true; U32 data = 0; for (;;) { U64 start, middle, end, first, second; int bit = NO_BIT; mData->AdvanceToNextEdge(); start = mData->GetSampleNumber(); middle = 0; // idle + console stop doesn't give us the first half of the signal // so we step back to align everything if (idle && state == CONSOLE_STOP_BIT) { end = mData->GetSampleOfNextEdge(); first = round((double)(end - start) / samples_per_bit); if (first == 1 || first == 3) { middle = start; idle = false; if (first == 1) { start -= samples_per_bit * 3; } else if (first == 3) { start -= samples_per_bit * 1; } } } if (!middle) { mData->AdvanceToNextEdge(); middle = mData->GetSampleNumber(); } first = round((double)(middle - start) / samples_per_bit); end = std::min(mData->GetSampleOfNextEdge(), (U64)(middle + (4 - first) * samples_per_bit)); second = round((double)(end - middle) / samples_per_bit); if (bit == NO_BIT) { if (first == 1 && second == 3) { bit = ONE_BIT; data = data << 1 | 1; } else if (first == 3 && second == 1) { bit = ZERO_BIT; data = data << 1; } else if (first == 1 && second == 2) { idle = true; state = bit = CONSOLE_STOP_BIT; // consume an edge because we're on the wrong side of the cycle mData->AdvanceToNextEdge(); } else if (first == 2 && (second == 1 || second == 2)) { if (second == 2) end -= samples_per_bit; idle = true; state = bit = CONTROLLER_STOP_BIT; } } if (bit == NO_BIT) continue; // add a marker U64 halfway = start + (end - start) / 2.0; mResults->AddMarker( halfway, AnalyzerResults::Dot, mSettings->mInputChannel ); Frame frame; frame.mData1 = bit; frame.mFlags = 0; frame.mStartingSampleInclusive = start; frame.mEndingSampleInclusive = end; mResults->AddFrame( frame ); mResults->CommitResults(); ReportProgress( frame.mEndingSampleInclusive ); } return; }
void LINAnalyzer::WorkerThread() { bool showIBS=false; // show inter-byte space? U8 nDataBytes=0; bool byteFramingError; Frame byteFrame; // byte fame from start bit to stop bit Frame ibsFrame; // inter-byte space startsing after SYNC ibsFrame.mData1 = 0; ibsFrame.mData2 = 0; ibsFrame.mFlags = 0; ibsFrame.mType = 0; mSerial = GetAnalyzerChannelData( mSettings->mInputChannel ); if( mSerial->GetBitState() == BIT_LOW ) mSerial->AdvanceToNextEdge(); mResults->CancelPacketAndStartNewPacket(); for( ; ; ) { ibsFrame.mStartingSampleInclusive = mSerial->GetSampleNumber(); if( ( mFrameState == LINAnalyzerResults::NoFrame ) || ( mFrameState == LINAnalyzerResults::headerBreak ) ) { byteFrame.mData1 = GetBreakField( byteFrame.mStartingSampleInclusive, byteFrame.mEndingSampleInclusive, byteFramingError ); } else { byteFrame.mData1 = ByteFrame( byteFrame.mStartingSampleInclusive, byteFrame.mEndingSampleInclusive, byteFramingError ); } ibsFrame.mEndingSampleInclusive = byteFrame.mStartingSampleInclusive; byteFrame.mData2 = 0; byteFrame.mFlags = byteFramingError ? LINAnalyzerResults::byteFramingError : 0; byteFrame.mType = mFrameState; if ( showIBS ) { mResults->AddFrame( ibsFrame ); } switch( mFrameState ) { case LINAnalyzerResults::NoFrame: mFrameState = LINAnalyzerResults::headerBreak; case LINAnalyzerResults::headerBreak: // expecting break showIBS=true; if ( byteFrame.mData1 == 0x00 ) { mFrameState = LINAnalyzerResults::headerSync; byteFrame.mType = LINAnalyzerResults::headerBreak; } else { byteFrame.mFlags |= LINAnalyzerResults::headerBreakExpected; mFrameState = LINAnalyzerResults::NoFrame; } break; case LINAnalyzerResults::headerSync: // expecting sync. if ( byteFrame.mData1 == 0x55 ) { mFrameState = LINAnalyzerResults::headerPID; } else { byteFrame.mFlags |= LINAnalyzerResults::headerSyncExpected; mFrameState = LINAnalyzerResults::NoFrame; } break; case LINAnalyzerResults::headerPID: // expecting PID. mFrameState = LINAnalyzerResults::responseDataZero; if ( mSettings->mLINVersion >= 2 ) { mChecksum.clear(); mChecksum.add(byteFrame.mData1); } break; // LIN Response case LINAnalyzerResults::responseDataZero: // expecting first resppnse data byte. if ( mSettings->mLINVersion < 2 ) { mChecksum.clear(); } mChecksum.add(byteFrame.mData1); nDataBytes = 1; mFrameState = LINAnalyzerResults::responseData; break; case LINAnalyzerResults::responseData: // expecting response data. if ( nDataBytes >= 8 || mChecksum.result() == byteFrame.mData1 ) { // FIXME - peek ahead for BREAK such that checksum match + BREAK detected at next char == end of packet. mFrameState = LINAnalyzerResults::responseChecksum; byteFrame.mType = LINAnalyzerResults::responseChecksum; } else { ++nDataBytes; mChecksum.add( byteFrame.mData1 ); break; } case LINAnalyzerResults::responseChecksum: // expecting checksum. nDataBytes = 0; if ( mChecksum.result() != byteFrame.mData1 ) { byteFrame.mFlags |= LINAnalyzerResults::checksumMismatch; } mFrameState = LINAnalyzerResults::NoFrame; showIBS=false; break; } byteFrame.mData2 = nDataBytes; mResults->AddFrame( byteFrame ); mResults->CommitPacketAndStartNewPacket(); mResults->CommitResults(); ReportProgress( byteFrame.mEndingSampleInclusive ); } }
void AtmelSWIAnalyzer::Setup() { // get the channel data pointer mSDA = GetAnalyzerChannelData(mSettings.mSDAChannel); }
void PS2KeyboardAnalyzer::WorkerThread() { mData = GetAnalyzerChannelData( mSettings->mDataChannel ); mClock = GetAnalyzerChannelData( mSettings->mClockChannel ); //begin from here for( ; ; ) { //init all variables, these will be updated by the GetNextData function U64 DataPayload =0; U64 frame_starting_sample; U64 frame_ending_sample; bool DeviceTx = false; bool ParityError = false; bool ACKed = false; //get a data transmission GetNextData(frame_starting_sample, frame_ending_sample, DeviceTx, DataPayload, ParityError, ACKed); Frame frame; frame.mStartingSampleInclusive = frame_starting_sample; U8 flags =0x00; //begin to analyze the frame based on direction of transmission if(DeviceTx) { if(mSettings->mDeviceType==0) { //transmission is from Device->Host, device is keyboard flags = flags | TX_DEVICE_TO_HOST; bool EndOfFrame = false; while(!EndOfFrame) { if(DataPayload==0xE0) { //extended key code flags = flags | EXTENDED_KEY; GetNextData(frame_starting_sample, frame_ending_sample, DeviceTx, DataPayload, ParityError, ACKed); EndOfFrame=false; } else if (DataPayload==0xEE) { flags = flags | DATA_FRAME; frame.mData2 = ECHO_FRAME; EndOfFrame = true; } else if (DataPayload==0xAA) { flags = flags | DATA_FRAME; frame.mData2 = BAT_FRAME; EndOfFrame = true; } else if (DataPayload==0xFA) { flags = flags | DATA_FRAME; frame.mData2 = ACK_FRAME; EndOfFrame = true; } else if(DataPayload==0xF0) { //break code flags = flags | BREAK_CODE; GetNextData(frame_starting_sample, frame_ending_sample, DeviceTx, DataPayload, ParityError, ACKed); EndOfFrame=false; } else if(DataPayload==0xE1) { //Pause/break key bool IsErrorInTx = false; bool finished = false; U64 compare_data[7] = {0x14,0x77,0xE1,0xF0,0x14,0xF0,0x77}; int cnt=0; while(!IsErrorInTx && !finished) { GetNextData(frame_starting_sample, frame_ending_sample, DeviceTx, DataPayload, ParityError, ACKed); if(compare_data[cnt]!=DataPayload) IsErrorInTx = true; else cnt++; if(cnt>6) finished=true; } if(finished) flags = flags | PAUSE_BREAK; else flags = flags | ERROR_FRAME; EndOfFrame=true; } else if(DataPayload==0x12 && (flags&EXTENDED_KEY)) { //Print Screen Make bool IsErrorInTx = false; bool finished = false; U64 compare_data[2] = {0xE0,0x7C}; int cnt=0; while(!IsErrorInTx && !finished) { GetNextData(frame_starting_sample, frame_ending_sample, DeviceTx, DataPayload, ParityError, ACKed); if(compare_data[cnt]!=DataPayload) IsErrorInTx = true; else cnt++; if(cnt>1) finished=true; } if(finished) { flags = flags | PRINT_SCREEN | MAKE_CODE; } else flags = flags | ERROR_FRAME; EndOfFrame=true; } else if(DataPayload==0x7C && flags&BREAK_CODE && flags&EXTENDED_KEY) { //Print Screen Break bool IsErrorInTx = false; bool finished = false; U64 compare_data[3] = {0xE0,0xF0,0x12}; int cnt=0; while(!IsErrorInTx && !finished) { GetNextData(frame_starting_sample, frame_ending_sample, DeviceTx, DataPayload, ParityError, ACKed); if(compare_data[cnt]!=DataPayload) IsErrorInTx = true; else cnt++; if(cnt>2) finished=true; } if(finished) { flags = flags | PRINT_SCREEN | BREAK_CODE; } else flags = flags | ERROR_FRAME; EndOfFrame=true; } else { //value EndOfFrame=true; } } frame.mData1 = DataPayload; } else { //device is a mouse, transmission from device to house flags = flags | TX_DEVICE_TO_HOST; if(DataPayload==0xFA) { flags = flags | DATA_FRAME; frame.mData2 = ACK_FRAME; } else if (DataPayload==0xAA) { flags = flags | DATA_FRAME; frame.mData2 = BAT_FRAME; } else if(DataPayload&0x08) { flags = flags | MOVEMENT_FRAME; U64 movement_packet[4] = {0x00, 0x00, 0x00, 0x00}; movement_packet[0] = DataPayload; GetNextData(frame_starting_sample, frame_ending_sample, DeviceTx, movement_packet[1], ParityError, ACKed); GetNextData(frame_starting_sample, frame_ending_sample, DeviceTx, movement_packet[2], ParityError, ACKed); if(mSettings->mDeviceType==2) GetNextData(frame_starting_sample, frame_ending_sample, DeviceTx, movement_packet[3], ParityError, ACKed); DataPayload = movement_packet[3]<<24 | movement_packet[2]<<16 | movement_packet[1]<<8 | movement_packet[0]; } else { } frame.mData1 = DataPayload; } } else { //transmission is Host->Device flags = flags | TX_HOST_TO_DEVICE; frame.mData1 = DataPayload; } frame.mFlags = flags; frame.mEndingSampleInclusive = frame_ending_sample; mResults->AddFrame(frame); mResults->CommitResults(); ReportProgress( frame.mEndingSampleInclusive ); CheckIfThreadShouldExit(); } }