Skip to content

Commit 52d6791

Browse files
[diag] Handle errors of TransmitPacket()
`TransmitPacket()` should return an error from platform Radio implementation, as for example Radio can be in incorrect state. If error occurs, output it onto console. Add wrong state case to tests and fix `diag repeat stop` called too lata. Signed-off-by: Maciej Baczmanski <maciej.baczmanski@nordicsemi.no>
1 parent 3470934 commit 52d6791

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

src/core/diags/factory_diags.cpp

+13-5
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ Error Diags::ProcessSend(uint8_t aArgsLength, char *aArgs[])
450450
VerifyOrExit(txLength >= OT_RADIO_FRAME_MIN_SIZE, error = kErrorInvalidArgs);
451451
mTxLen = txLength;
452452

453-
TransmitPacket();
453+
SuccessOrExit(error = TransmitPacket());
454454

455455
exit:
456456
return error;
@@ -528,8 +528,9 @@ Error Diags::ProcessStop(uint8_t aArgsLength, char *aArgs[])
528528
return kErrorNone;
529529
}
530530

531-
void Diags::TransmitPacket(void)
531+
Error Diags::TransmitPacket(void)
532532
{
533+
Error error = kErrorNone;
533534
mTxPacket->mChannel = mChannel;
534535

535536
if (mIsTxPacketSet)
@@ -550,7 +551,14 @@ void Diags::TransmitPacket(void)
550551
}
551552

552553
mDiagSendOn = true;
553-
IgnoreError(Get<Radio>().Transmit(*static_cast<Mac::TxFrame *>(mTxPacket)));
554+
error = Get<Radio>().Transmit(*static_cast<Mac::TxFrame *>(mTxPacket));
555+
556+
if(error != kErrorNone)
557+
{
558+
Output("Packet transmission failed, error: %s\r\n", ErrorToString(error));
559+
}
560+
561+
return error;
554562
}
555563

556564
Error Diags::ParseReceiveConfigFormat(const char *aFormat, ReceiveConfig &aConfig)
@@ -747,7 +755,7 @@ void Diags::AlarmFired(void)
747755
{
748756
uint32_t now = otPlatAlarmMilliGetNow();
749757

750-
TransmitPacket();
758+
IgnoreError(TransmitPacket());
751759
otPlatAlarmMilliStartAt(&GetInstance(), now, mTxPeriod);
752760
}
753761
else
@@ -856,7 +864,7 @@ void Diags::TransmitDone(Error aError)
856864
VerifyOrExit(mTxPackets > 1);
857865
mTxPackets--;
858866

859-
TransmitPacket();
867+
IgnoreError(TransmitPacket());
860868

861869
exit:
862870
return;

src/core/diags/factory_diags.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,10 @@ class Diags : public InstanceLocator, private NonCopyable
232232
Error GetPowerSettings(uint8_t aChannel, PowerSettings &aPowerSettings);
233233
Error ParseReceiveConfigFormat(const char *aFormat, ReceiveConfig &aConfig);
234234
Error RadioReceive(void);
235+
Error TransmitPacket(void);
235236
void OutputReceivedFrame(const otRadioFrame *aFrame);
236237
bool ShouldHandleReceivedFrame(const otRadioFrame &aFrame) const;
237238

238-
void TransmitPacket(void);
239239
void Output(const char *aFormat, ...);
240240
void ResetTxPacket(void);
241241
void OutputStats(void);

tests/scripts/expect/cli-diags.exp

+19-3
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,22 @@ send_user "input odd length test\n"
127127
send "diag frame 123\n"
128128
expect "Error"
129129

130+
send "diag radio sleep\n"
131+
expect_line "Done"
132+
133+
send "diag radio disable\n"
134+
expect_line "Done"
135+
136+
send "diag send 10 10\n"
137+
expect "Packet transmission failed, error: InvalidState"
138+
expect "Error 13: InvalidState"
139+
140+
send "diag radio enable\n"
141+
expect_line "Done"
142+
143+
send "diag radio receive\n"
144+
expect_line "Done"
145+
130146
send_user "shortest frame test\n"
131147
send "diag frame 112233\n"
132148
expect "Done"
@@ -138,6 +154,9 @@ send "diag frame 112233445566778899001122334455667788990011223344556677889900112
138154
expect "Done"
139155
send "diag repeat 1\n"
140156
expect "Done"
157+
sleep 3
158+
send "diag repeat stop\n"
159+
expect "Done"
141160

142161
send_user "send frame with security processed\n"
143162
send "diag frame -s 112233\n"
@@ -157,9 +176,6 @@ expect "Done"
157176
send "diag send 1\n"
158177
expect "Done"
159178

160-
send "diag repeat stop\n"
161-
expect "Done"
162-
163179
send "diag channel 11\n"
164180
expect_line "Done"
165181

0 commit comments

Comments
 (0)