- Do we really care?
- GPS Hardware Port settings
- Avoid end-user actions
- A possible programmatic solution
For whatever reason you may want to know if the GPS Antenna your Windows Mobile device is connected to is internal or external... but... are we sure we should care? If you’re using GPSID APIs, then you shouldn’t care if the GPS Antenna is external or internal: in both cases it must be set in the OS’ GPS control panel applet by the user (this is not the only option, see below). Programmatically speaking, once you’ll call GpsOpenDevice to create a connection to the GPSID, then it’s up to the Intermediate Driver to internally take care if the antenna is internal or external.
In contrast, if you’re NOT using GPSID APIs (as I did in my previous test application I talked about in my blog), then probably your only option is as many 3rd party software do, i.e. scanning all the COM ports. In any case, also by using this approach you won’t be able to discriminate if the COM port you’re opening is related to an internal or external GPS antenna (for example if it’s a COM Port associated to the “Serial Port” service exposed by a Bluetooth GPS Antenna).
So the question may become: why do you need to care if the antenna is internal or external? Well... for example you may think that if external then the user is required to explicitly set the "GPS Hardware Port" within the GPS control panel applet (Start\Settings-System\GPS), contrarily to the case where the antenna is internal, because the manufacturer very likely configured its properties when building the platform... I'm talking about the following:
GPS Settings: Specify the hardware port to which your GPS device is connected. For more information, see the GPS device manufacturer's documentation.
And since, as I've already written, every developer must know the motto "KNOW THY USER, FOR HE IS NOT THEE" [cit. from David S. Platt, President of Rolling Thunder Computing] , you may want to provide users with as few as possible steps.
Ok, consider that at the moment there's no Configuration Service Provider for GPSID, however all the properties are retrieved through the Registry! So, for example, the Hardware Port is set under the keys documented at GPS Intermediate Driver GPS Hardware Registry Settings. So, if you know how the user will set the "Serial Port Service" of the external GPS Antenna (Bluetooth, SD or any other hardware), then it's a matter of using the Registry functions, or Microsoft.Win32.Registry NETCF class or even the Registry Configuration Service Provider for example. If you can't know a priori how the user will set his external device, then even knowing if it's indeed an external device doesn't help... probably the only option is at this point to instruct the user on how to set the external antenna's COM service and the associated Hardware Port within the GPSID control panel applet... This is basically what I saw in the manual of another great piece of software: Run.GPS! (thanks Giorgio for this hint!) -- see chapter 3 "GPS Support". I looked at SportsDo's user guide as well, and didn't find such info, probably purely because its GPS Data Interpreter engine is not based on Windows Mobile's GPSID (manual here).
In any case, to verify if the target device has an integrated GPS Antenna or not, accordingly to the documentation above you can check the GPS Intermediate Driver GPS Hardware Registry Settings, and analyze the keys under [HKEY_LOCAL_MACHINE\System\CurrentControlSet\GPS Intermediate Driver\Drivers]: I've found something interesting in this case...
- example of some devices WITH integrated antenna (note key "CurrentDriver"):
- other example of devices WITH integrated antenna (note key "CurrentDriver"):
- devices WITHOUT integrated antenna:
I've tried with a few devices (thanks Nicola, Carlo, Fernando and JP!! ) and in all of them the result is the same, i.e. when OEMs place a integrated antenna then they also "configure" its specific hardware through the [HKEY_LOCAL_MACHINE\System\CurrentControlSet\GPS Intermediate Driver\Drivers] key.
I noted a different set of keys on one device only, on which by the way the integrate GPS Antenna was working as expected... the CurrentDriver was NOT there! (see below) Looking at WM6 documentation, if it's not set the GPS Intermediate Driver uses plug and play GPS hardware. So? Does "plug&play GPS Hardware" have sense on a device with integrated GPS Antenna?? Without the CurrentDriver registry entry, multiple registry entries would have to change to switch between different GPS devices... without that set, does the device.exe load the first "driver" listed under [HKEY_LOCAL_MACHINE\System\CurrentControlSet\GPS Intermediate Driver\Drivers]? Very likely yes (I should confirm looking at source-code).
Even if we had such a confirmation, at this point the only thing that may discriminate if the GPS Antenna is internal or external SEEMS TO BE (I sure haven't tried on enough devices, so feel free to let me know!) *IF* [HKEY_LOCAL_MACHINE\System\CurrentControlSet\GPS Intermediate Driver\Drivers\Control Panel Configured Device] key *exists*. I was initially thinking at checking the value of [HKEY_LOCAL_MACHINE\System\CurrentControlSet\GPS Intermediate Driver\Drivers]CurrentDriver, however as you noticed I found at least one device without it and yet with integrated antenna... To wrap up the discussion, a possible programmatic approach may be: