Hi,
I have CSV file stored on an SD card (which I create via the nordic board). I want to send this via a GATT connection.
I have gotten a service with a notifiable characteristic value that increments once per second using a notification timeout handler.
I am also able to read a single line of my sd cards CSV.
I now want to combine the two functionalities but need some help.
Firstly I am always reading the first line of the CSV by calling the function read_line. This is custom and reads the first line of the csv files and prints it out to the terminal.
How do I read several lines aka more data because I'll need to read the entire file and send it via my gatt connection.
Are my following assumptions of how to read and send the sd card CSV file correct?
- I need to know how to set the last pointer of where the data is read upto.
- Then send that data via notifications.
- Once that data is sent read the next lines of the CSV file and send that.
- Then repeat until the file is completely read. Which I presume I can do by identifying the size of the file and reading that many bytes.
If so I need to know
- How large of a gatt characteristic i can have presently a byte.
- How to set a read pointer (the point the sd card read periously got to)
- How to read the entire CSV file
- How to link my data to the notification
Thanks
Note Using SDK 16, NRF52840-dk PCA 10056 S140 in segger. Below is my code. I want to adapt my read line so it can read and broadcast the entire CSV file upto 2mbytes.
static void notification_timeout_handler(void * p_context) { UNUSED_PARAMETER(p_context); ret_code_t err_code; // Increment the value of m_custom_value before nortifing it. m_custom_value++; err_code = ble_cus_custom_value_update(&m_cus, m_custom_value);//Need to link this to the CSV file data APP_ERROR_CHECK(err_code); }
void SD_CARD_Read_Line() { UINT bytesRead;//From sd card driver library static FATFS fs; static DIR dir; static FILINFO fno; static FIL file; uint32_t bytes_written; FRESULT ff_result; DSTATUS disk_state = STA_NOINIT; NRF_LOG_INFO("Reading SD CARD data"); char data[100]={0}; /* Line buffer */ unsigned int ByteRead = 0; ff_result = f_open(&file, FILE_NAME, FA_READ); if (ff_result != FR_OK) { NRF_LOG_INFO("Unable to open or create file: " FILE_NAME ".\r\n"); return; } uint16_t size = f_size(&file) ; NRF_LOG_INFO("size of the file in bytes = %d\r\n",size); ff_result = f_read(&file,data,52, &ByteRead); if (ff_result != FR_OK) { NRF_LOG_INFO("Unable to read or create file: " FILE_NAME ".\r\n"); return; } else if(ff_result == FR_OK) { NRF_LOG_INFO("%d bytes read\r\n",ByteRead); NRF_LOG_INFO("Data is : %s\r\n", (uint32_t) data); } else { NRF_LOG_INFO("Error operation\r\n"); } (void) f_close(&file); }