I want to use fstorage to write data to a file. The File with three records: 0x1111="Tablet1", 0x2222="data: abcdef", 0x3333="26". How to implement it? Can anyone guide me?
I want to use fstorage to write data to a file. The File with three records: 0x1111="Tablet1", 0x2222="data: abcdef", 0x3333="26". How to implement it? Can anyone guide me?
Hi
There is fstorage example code available here for SDK 10. There is also available simple fds code here for SDK 11. Discussion on the difference between pstorage, fstorage and fds is briefly discussed here
Update 26.10.2016 Below is fstorage example for SDK 11.0.0. The example writes two words to flash and then reads the flash contents. Result is printed on UART (UART settings: 115200 BAUD, 8N1, hardware flow control disabled)
ble_app_template_with_fstorage_operations.zip
Update 2 26.10.2016 I attach another SDK 11.0.0 example with the following UART output
ble_app_template_with_fstorage_operations_ascii.zip
I print it by hexadecimal code, because it cannot print non-ASCII data. If I set the second data to 0x2222="data: abcdef". I got the message as follows. Writing Record ID = 1 set write_flag Writing Record ID = 2 set write_flag Writing Record ID = 3 set write_flag Start searching... Found Record ID = 1 Tablet1 Found Record ID = 2 Data = ?? Found Record ID = 3 Data = 0x0000001a
If I set the second data to 0x2222="data abcdef". I got the message as follows. Writing Record ID = 1 set write_flag Writing Record ID = 2 set write_flag Writing Record ID = 3 set write_flag Start searching... Found Record ID = 1 Tablet1 Found Record ID = 2 Data = data abcdef Found Record ID = 3 Data = 0x0000001a
The two strings are only different at a character of ':' .ble_pstorge_1.c
Write hexadecimal code semms successfully. But write ASCII string include specail characters will cause fail. Can you test it with special characters like "~!@#$%^&*()_+-="?
I think the problem might be with your conversion from byte to words. The string "data: abcdef" is 12 characters long, plus the implicit string terminator character '\0', that's a total of 13 bytes. When you set length_words field of the chunk like this:
record_chunk.length_words = (sizeof(device_data)+1)/4;
My guess is that sizeof(device_data) will be 13 + 1 (which you add manually) / 4 equals to 3.5, which gets rounded down to 3, which is wrong since the string is 12 characters long but you need the 13th character (string terminator) to print correctly.
It works with "data abcdef" because that's one character shorter, thus 12 + 1 / 4 = 3,25 which gets rounded down to 3, which is right in this case because that's exactly the length of the string including the terminator character (implicit).
If you want approximate you should add 3. I would try like this:
length_words = (sizeof(data) + 3) / 4
System seems halt when I call the function of fds_record_write from BLE ancs profile. Can I not access fstorage from BLE ancs profile? Is it correct? Do you know how to do it?