How do I access the product version in a singleton file.
Where would I declare the
__system_product_version
How do I access the product version in a singleton file.
Where would I declare the
__system_product_version
That's normally not how you use it. It should be set using PRODUCT_VERSION()
which is a macro, defined here which sets the variable you referenced. The examples show it in the top of the main application source file, but it can be in a different location. One common choice is to put it in its own .h file that's only included from your main source file, which makes it easier to overwrite using a script.
As an alternative to using your own script, there's a Github action that can be used for CI/CD deployment of products that automatically updates the PRODUCT_VERSION.
If you want to read the version from other parts of your source, you should make a getter. Because the variable is not declared in a Device OS header file for reading, you'd need a declaration:
extern uint16_t __system_product_version;
And then your getter would just return the value.
The value is used not only when the device connects to the cloud, but it's also stored in the binary. The latter is important because that's what the firmware upload to product checks to see if the firmware is the right version. Because of this, you cannot set the product version at runtime.
Thanks Rick. So if i have my app split up into singletons. and lets say I wish to access the variable __system_product_id
in my publishHandler.cpp file.
Where should I declare the extern uint16_t __system_product_id;
and what should the getter look like?
You could make a singleton class just for accessing the system version. The implementation .cpp file would contain the extern declaration, which would prevent it from leaking out into the global namespace within your app.
If you have some sort of utility class, you could put it in there. It could be static or a singleton.
Thanks Rick,
I'm still struggling a bit here, but in my publishHandler.h file, I declared the variable outside the class, and created a getter like so:
extern uint16_t __system_product_id;
class publishHandler {
public:
uint16_t getFirmware();
The getter is defined like this
uint16_t publishHandler::getFirmware(){
return __system_product_id;
}
I am then using the getter in a snprintf
with the %d
formatter. This is providing the incorrect value for my firmware though.
My version is PRODUCT_VERSION(96);
and my snprinf is returning 25. Is this a casting issue from uint16_t to int?
Sorry, I copied the wrong line, it should be __system_product_version not __system_product_id.
Thanks Rick, I don't know how I missed that. Bank Holiday brain I guess.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.