@@ -587,6 +587,50 @@ void Diags::TransmitPacket(void)
587
587
IgnoreError (Get<Radio>().Transmit (*static_cast <Mac::TxFrame *>(mTxPacket )));
588
588
}
589
589
590
+ Error Diags::ParseReceiveConfigFormat (const char *aFormat, ReceiveConfig &aConfig)
591
+ {
592
+ Error error = kErrorNone ;
593
+
594
+ VerifyOrExit (aFormat != nullptr , error = kErrorInvalidArgs );
595
+
596
+ for (const char *arg = aFormat; *arg != ' \0 ' ; arg++)
597
+ {
598
+ switch (*arg)
599
+ {
600
+ case ' r' :
601
+ aConfig.mShowRssi = true ;
602
+ break ;
603
+
604
+ case ' l' :
605
+ aConfig.mShowLqi = true ;
606
+ break ;
607
+
608
+ case ' p' :
609
+ aConfig.mShowPsdu = true ;
610
+ break ;
611
+
612
+ default :
613
+ ExitNow (error = OT_ERROR_INVALID_ARGS);
614
+ }
615
+ }
616
+
617
+ exit :
618
+ return error;
619
+ }
620
+
621
+ Error Diags::RadioReceive (void )
622
+ {
623
+ Error error;
624
+
625
+ SuccessOrExit (error = Get<Radio>().Receive (mChannel ));
626
+ SuccessOrExit (error = Get<Radio>().SetTransmitPower (mTxPower ));
627
+ otPlatDiagChannelSet (mChannel );
628
+ otPlatDiagTxPowerSet (mTxPower );
629
+
630
+ exit :
631
+ return error;
632
+ }
633
+
590
634
Error Diags::ProcessRadio (uint8_t aArgsLength, char *aArgs[])
591
635
{
592
636
Error error = kErrorInvalidArgs ;
@@ -601,12 +645,44 @@ Error Diags::ProcessRadio(uint8_t aArgsLength, char *aArgs[])
601
645
}
602
646
else if (StringMatch (aArgs[0 ], " receive" ))
603
647
{
604
- SuccessOrExit (error = Get<Radio>().Receive (mChannel ));
605
- SuccessOrExit (error = Get<Radio>().SetTransmitPower (mTxPower ));
606
- otPlatDiagChannelSet (mChannel );
607
- otPlatDiagTxPowerSet (mTxPower );
648
+ ReceiveConfig receiveConfig;
649
+
650
+ aArgs++;
651
+ aArgsLength--;
652
+
653
+ if (aArgsLength == 0 )
654
+ {
655
+ SuccessOrExit (error = RadioReceive ());
656
+ Output (" set radio from sleep to receive on channel %d\r\n status 0x%02x\r\n " , mChannel , error);
657
+ ExitNow ();
658
+ }
608
659
609
- Output (" set radio from sleep to receive on channel %d\r\n status 0x%02x\r\n " , mChannel , error);
660
+ if (StringMatch (aArgs[0 ], " async" ))
661
+ {
662
+ aArgs++;
663
+ aArgsLength--;
664
+ receiveConfig.mIsAsyncCommand = true ;
665
+ }
666
+
667
+ VerifyOrExit (aArgsLength > 0 );
668
+ SuccessOrExit (error = Utils::CmdLineParser::ParseAsUint16 (aArgs[0 ], receiveConfig.mNumFrames ));
669
+ aArgs++;
670
+ aArgsLength--;
671
+
672
+ if (aArgsLength > 0 )
673
+ {
674
+ SuccessOrExit (error = ParseReceiveConfigFormat (aArgs[0 ], receiveConfig));
675
+ }
676
+
677
+ SuccessOrExit (error = RadioReceive ());
678
+
679
+ receiveConfig.mIsEnabled = true ;
680
+ mReceiveConfig = receiveConfig;
681
+
682
+ if (!mReceiveConfig .mIsAsyncCommand )
683
+ {
684
+ error = kErrorPending ;
685
+ }
610
686
}
611
687
else if (StringMatch (aArgs[0 ], " state" ))
612
688
{
@@ -668,10 +744,54 @@ void Diags::AlarmFired(void)
668
744
}
669
745
}
670
746
747
+ void Diags::OutputReceivedFrame (const otRadioFrame *aFrame)
748
+ {
749
+ VerifyOrExit (mReceiveConfig .mIsEnabled && (aFrame != nullptr ));
750
+
751
+ Output (" %u" , mReceiveConfig .mReceiveCount ++);
752
+
753
+ if (mReceiveConfig .mShowRssi )
754
+ {
755
+ Output (" , rssi:%d" , aFrame->mInfo .mRxInfo .mRssi );
756
+ }
757
+
758
+ if (mReceiveConfig .mShowLqi )
759
+ {
760
+ Output (" , lqi:%u" , aFrame->mInfo .mRxInfo .mLqi );
761
+ }
762
+
763
+ if (mReceiveConfig .mShowPsdu )
764
+ {
765
+ static constexpr uint16_t kBufSize = 255 ;
766
+ char buf[kBufSize ];
767
+ StringWriter writer (buf, sizeof (buf));
768
+
769
+ writer.AppendHexBytes (aFrame->mPsdu , aFrame->mLength );
770
+ Output (" , len:%u, psdu:%s" , aFrame->mLength , buf);
771
+ }
772
+
773
+ Output (" \r\n " );
774
+
775
+ if (mReceiveConfig .mReceiveCount >= mReceiveConfig .mNumFrames )
776
+ {
777
+ mReceiveConfig .mIsEnabled = false ;
778
+
779
+ if (!mReceiveConfig .mIsAsyncCommand )
780
+ {
781
+ Output (" OT_ERROR_NONE" );
782
+ }
783
+ }
784
+
785
+ exit :
786
+ return ;
787
+ }
788
+
671
789
void Diags::ReceiveDone (otRadioFrame *aFrame, Error aError)
672
790
{
673
791
if (aError == kErrorNone )
674
792
{
793
+ OutputReceivedFrame (aFrame);
794
+
675
795
// for sensitivity test, only record the rssi and lqi for the first and last packet
676
796
if (mStats .mReceivedPackets == 0 )
677
797
{
@@ -910,7 +1030,7 @@ Error Diags::ProcessGpio(uint8_t aArgsLength, char *aArgs[])
910
1030
911
1031
void Diags::AppendErrorResult (Error aError)
912
1032
{
913
- if (aError != kErrorNone )
1033
+ if (( aError != kErrorNone ) && (aError != kErrorPending ) )
914
1034
{
915
1035
Output (" failed\r\n status %#x\r\n " , aError);
916
1036
}
0 commit comments