Skip to content

Commit 68719f2

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 143ebbf commit 68719f2

File tree

3 files changed

+38
-10
lines changed

3 files changed

+38
-10
lines changed

src/core/diags/factory_diags.cpp

+16-6
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,9 @@ Error Diags::ProcessSend(uint8_t aArgsLength, char *aArgs[])
457457
VerifyOrExit(txLength >= OT_RADIO_FRAME_MIN_SIZE, error = kErrorInvalidArgs);
458458
mTxLen = txLength;
459459

460-
Output("sending %#x packet(s), length %#x\r\n", static_cast<int>(mTxPackets), static_cast<int>(mTxLen));
461-
TransmitPacket();
460+
SuccessOrExit(error = TransmitPacket());
462461

462+
Output("sending %#x packet(s), length %#x\r\n", static_cast<int>(mTxPackets), static_cast<int>(mTxLen));
463463
exit:
464464
return error;
465465
}
@@ -537,7 +537,7 @@ Error Diags::ProcessStop(uint8_t aArgsLength, char *aArgs[])
537537
return kErrorNone;
538538
}
539539

540-
void Diags::TransmitPacket(void)
540+
Error Diags::TransmitPacket(void)
541541
{
542542
mTxPacket->mChannel = mChannel;
543543

@@ -559,7 +559,7 @@ void Diags::TransmitPacket(void)
559559
}
560560

561561
mDiagSendOn = true;
562-
IgnoreError(Get<Radio>().Transmit(*static_cast<Mac::TxFrame *>(mTxPacket)));
562+
return Get<Radio>().Transmit(*static_cast<Mac::TxFrame *>(mTxPacket));
563563
}
564564

565565
Error Diags::ParseReceiveConfigFormat(const char *aFormat, ReceiveConfig &aConfig)
@@ -758,7 +758,11 @@ void Diags::AlarmFired(void)
758758
{
759759
uint32_t now = otPlatAlarmMilliGetNow();
760760

761-
TransmitPacket();
761+
Error error = TransmitPacket();
762+
if (error != kErrorNone)
763+
{
764+
Output("Packet transmission failed\r\nstatus %#x\r\n", error);
765+
}
762766
otPlatAlarmMilliStartAt(&GetInstance(), now, mTxPeriod);
763767
}
764768
else
@@ -841,6 +845,8 @@ void Diags::ReceiveDone(otRadioFrame *aFrame, Error aError)
841845

842846
void Diags::TransmitDone(Error aError)
843847
{
848+
Error error;
849+
844850
VerifyOrExit(mDiagSendOn);
845851
mDiagSendOn = false;
846852

@@ -859,7 +865,11 @@ void Diags::TransmitDone(Error aError)
859865
}
860866

861867
VerifyOrExit(!mRepeatActive);
862-
TransmitPacket();
868+
error = TransmitPacket();
869+
if (error != kErrorNone)
870+
{
871+
Output("Packet transmission failed\r\nstatus %#x\r\n", error);
872+
}
863873

864874
exit:
865875
return;

src/core/diags/factory_diags.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,10 @@ class Diags : public InstanceLocator, private NonCopyable
228228
Error GetPowerSettings(uint8_t aChannel, PowerSettings &aPowerSettings);
229229
Error ParseReceiveConfigFormat(const char *aFormat, ReceiveConfig &aConfig);
230230
Error RadioReceive(void);
231+
Error TransmitPacket(void);
231232
void OutputReceivedFrame(const otRadioFrame *aFrame);
232233
bool ShouldHandleReceivedFrame(const otRadioFrame &aFrame) const;
233234

234-
void TransmitPacket(void);
235235
void Output(const char *aFormat, ...);
236236
void AppendErrorResult(Error aError);
237237
void ResetTxPacket(void);

tests/scripts/expect/cli-diags.exp

+21-3
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,24 @@ send_user "input odd length test\n"
130130
send "diag frame 123\n"
131131
expect "Error"
132132

133+
send "diag radio sleep\n"
134+
expect_line "Done"
135+
136+
send "diag radio disable\n"
137+
expect_line "Done"
138+
139+
send "diag send 10 10\n"
140+
expect "failed"
141+
expect "status 0xd"
142+
expect "Error 13: InvalidState"
143+
144+
send "diag radio enable\n"
145+
expect_line "Done"
146+
147+
send "diag radio receive\n"
148+
expect "set radio from sleep to receive on channel 20"
149+
expect_line "Done"
150+
133151
send_user "shortest frame test\n"
134152
send "diag frame 112233\n"
135153
expect "Done"
@@ -143,6 +161,9 @@ expect "Done"
143161
send "diag repeat 1\n"
144162
expect "length 0x7f"
145163
expect "Done"
164+
sleep 3
165+
send "diag repeat stop\n"
166+
expect "Done"
146167

147168
send_user "send frame with security processed\n"
148169
send "diag frame -s 112233\n"
@@ -165,9 +186,6 @@ send "diag send 1\n"
165186
expect "length 0x3"
166187
expect "Done"
167188

168-
send "diag repeat stop\n"
169-
expect "Done"
170-
171189
send "diag channel 11\n"
172190
expect "set channel to 11"
173191
expect_line "Done"

0 commit comments

Comments
 (0)