-
Notifications
You must be signed in to change notification settings - Fork 102
gnss: remove device from global list when no poweroff #147
Conversation
The following code should be valid to recover from a situation in which the GNSS is disconnected/connected or power up. while((uret = uDeviceOpen(&gDeviceCfg, &device_handle)) != U_ERROR_COMMON_SUCCESS) { uPortTaskBlock(5000); } Current implementation fails with U_ERROR_COMMON_INVALID_PARAMETER with no recovery option, this loop is infinite connecting GNSS will have no affect. The reason is that the removeDevice() is called with powerOff=false, this result in not removing the device from the global device list. When the device is opened again it is already found within the list at by pGetGnssInstanceTransportHandle which is called by uGnssAdd(), uGnssAdd() returns U_ERROR_COMMON_INVALID_PARAMETER. The software should release any resources attached to a device regardless of poweron/poweroff, the resources are logical and may be created when required. This patch removes the device from the list in case of poweroff was not requested. Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
Trying to recall if there was a reason why I did it that way and also pushing to test system in case it objects... |
Hmm, no, a look at the code suggests that the cellular equivalent does a proper remove, looks like this was just a mistake for the GNSS case. Will merge if test system says "yo". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, the equivalent device code for cellular code does a proper removal, this appears to be an oversight for the GNSS case. The test system shows now issue with this change, hence looks good both to me and the machine.
Merging...
Hello @RobMeades, Thinking about this a bit more... leaving the device instance open when poweoff failure will result in a leak as the opendevice will fail and not allow user to release the resources or reattempt as the next open will fail. I suggest to remove the poweron/poweroff from the device open so the user will be able to control the close sequence, or to release the device in any case if open failed regardless of power state. Alon |
Hmmm, yes, so maybe it should be:
|
@RobMeades library should notify the user that we could not power off the device in addition to the original error. as maybe some other action should be done. this is why playing with power should probably be separated from device behaviors. |
Apologies for the delay in replying: needed to complete a mutexed operation before I could free-up processing time :-). There are two cases:
In case (b) the error reported to the caller is the In case (a) we've managed to successfully power-on the GNSS device and then found there is no room in the list so we call removeDevice() with So I don't think I'm going to worry about (b) and I think the uDeviceClose() is OK with the code as it stands...? |
Hello @RobMeades , Per your description, I am afraid that the change we merged 7df8ac9 broke as you do expect device to be available to the user in case of open failure this is required to properly close the device with different power attributes. This is very confusing and should be clearly documented. And there is a bug there in any case as we should return a valid device handle only if it is indeed valid per the power off issue and not in other cases. I suggest a more consistent design so that open and poweron will be separated, the open is local operation and does not communicate with the device while poweron does. The open should fail only if local operating system cannot allocate the resources. I guess I would have also separated between poweroff and close for the same reason. Regards, |
Not sure I follow: if uDeviceOpen() fails then in all cases except (b) (which is very unlikely to occur) the device is both not powered-up and not occupying any resources, there is no device and therefore no device handle. The user sees the negative error code and tries a different tack...? |
As far as I can follow, if the device open is success and some interaction with it fails and if poweron/off is enabled then the open will fail, the handle will be null and there will be no way to recover. |
OK, I've taken the time to use @philwareublox as a sounding box and, spelling it out in laborious detail, we believe you are describing this scenario:
If we were to change the code as I indicated a few comments above, to remove the device anyway in this scenario, while that would resolve the problem, as you have pointed out it also hides information; the user no longer knows whether their misbehaving device is powered on or not. Well, they might guess that we cannot possibly know 'cos the goldarned thing is misbehaving, but anyway, let's say we take the return values of the code at face value. The correct recovery, then, is to call uDeviceClose() again, this time with the I don't want to change the APIs for device open/close, it would be a breaking change to a fundamental API, something we very much try not to do, so instead I will update the description for uDeviceClose() as follows:
I will also update all of the places in the examples and the test code where we call uDeviceClose() with |
Great, thank you for sorting this out! |
The following code should be valid to recover from a situation in which the GNSS is disconnected/connected or power up.
Current implementation fails with U_ERROR_COMMON_INVALID_PARAMETER with no recovery option, this loop is infinite connecting GNSS will have no affect.
The reason is that the removeDevice() is called with powerOff=false, this result in not removing the device from the global device list.
When the device is opened again it is already found within the list at by pGetGnssInstanceTransportHandle which is called by uGnssAdd(), uGnssAdd() returns U_ERROR_COMMON_INVALID_PARAMETER.
The software should release any resources attached to a device regardless of poweron/poweroff, the resources are logical and may be created when required.
This patch removes the device from the list in case of poweroff was not requested.