Hi,
希望有人可以澄清使用这两个功能的差异以及应使用它们的时间/地点。
uint32_t yyy = 0x12345678;
ble_gatts_set_value(xxx_val_h, sizeof(yyy), &yyy);
或者
ble_storage_put_u32(conn_idx, xxx_val_h, yyy, true); // with param conn_idx is this per connection?
谢谢,
亚历克斯。
Device:
Hi Alex,
ble_gatts_set/get() are APIs intended for accessing the local BLE database. E.g. reading and setting a value in the database during a connection. The ble_storage_put_uXX() API creates a persistent copy of the value in the flash device - in the NVMS partition for access across connection/reconnection, etc. The latter API is intended for application data handling, while the first, is for directly manipulation of the database.
A quick example is in the Battery service in the SDK:
/Jon
Hi Jon,
thanks for the explanation.
将explain why the notification / indication (xxx_ccc_h) are stored to flash.
我认为连接中心的MAC地址与数据一起存储?
Hi Alex,
My apologies for the confusion above. The connection/reconnection was misleading. This particular API should be used to store local values for later access during the connection, in this instance (The BAS example).
If you take a look at this example, the cleanup gets called on disconnect to remove all the storage. This is done since, the values can only be associated with the conn_idx, and the conn_idx can only be assured through one connection.
So in this case, we use ble storage for storing a local copy of the CCC (not having to get it from the DB each time), and we also use it for doing a 'sanity' check on the previous levels of the BAS. Example, we poll the battery value, and go to notify - we check the previous value stored in ble_storage.c to see if the notification is necessary. If the notification is necessary, since the level has changed - the ble_storage is updated with the new value for subsequent reads.
This is the general idea behind it.
Hi Jon,
啊,现在我更困惑!
我可以看到您使用以下方式获取DB的值:BLE_GATTS_GET_VALUE
and testing with the value passed as a param and only updating the DB if changed using: ble_gatts_set_value
but I don't see why it's necessary to use: ble_storage_put_u32
especially if the value isn't persistant for the same central across different connections.
please could you turn the lights on for me!?
Hi Alex,
你没有困惑:)。我相信我正在使用一个糟糕的例子来说明这个概念,但我认为你有一般的想法。
The storage is primarily just being used a local copy instead of accessing the database. In most cases, you should be able to just use ble_gatts_get_value and ble_gatts_set_value to access the most current database values. If you wish to store a local copy, which we do in most of our examples, use the storage. If you wish to get the latest database value, use the ble_gatts API.
There are both forms of this used in our examples, and I agree it tends to get a little confusing. For the ble_gatts_set/get, this is illustrated in a straightforward manner in bas_notify_level. We have already set the level with bas_set_level, so we can just use ble_gatts_get_value and then follow it with notify_level. Using the ble_storage_put_32 just now stores a local copy of this in the flash.
So basically - if you want to read and modify the database, the ble_gatts_set/get is required for proper BLE functionality, and then you could use ble_storage for application reasons.
谢谢jon。
这是有道理的。