From f4e4dda81eeaf459ece660e4e56da2e82b1c9f2b Mon Sep 17 00:00:00 2001 From: Diego Escalona Date: Tue, 30 Jan 2024 18:06:30 +0100 Subject: [PATCH] gpm: check if answer was received before waiting for it in the GPM fw update Signed-off-by: Diego Escalona --- XBeeLibrary.Core/Models/GpmManager.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/XBeeLibrary.Core/Models/GpmManager.cs b/XBeeLibrary.Core/Models/GpmManager.cs index 5695db6..4439084 100644 --- a/XBeeLibrary.Core/Models/GpmManager.cs +++ b/XBeeLibrary.Core/Models/GpmManager.cs @@ -1,5 +1,5 @@ /* - * Copyright 2023, Digi International Inc. + * Copyright 2023,2024, Digi International Inc. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -498,9 +498,15 @@ private string SendGPMAPIPacket(XBeePacket packet, int timeout) // Send the packet. device.SendPacketAsync(packet); // Wait for response or timeout. - lock (gpmLock) + // Check first if the answer to the packet was not already received. Interfaces + // such as Bluetooth can take some time to execute the write operation and, by + // the time that process finishes, the answer could have been already received. + if (!gpmPacketReceived) { - Monitor.Wait(gpmLock, Math.Max(timeout, AbstractXBeeDevice.DEFAULT_RECEIVE_TIMETOUT)); + lock (gpmLock) + { + Monitor.Wait(gpmLock, Math.Max(timeout, AbstractXBeeDevice.DEFAULT_RECEIVE_TIMETOUT)); + } } if (!gpmPacketSent)