File transfer with cmd code via BLE.

Hi All,

        I am using NRF52840 with USB MSC code. I have managed to create a file inside flash chip. I am also able to transfer this file via BLE to the app. Now while doing file transfer I am diving the file into 200bytes of chunks and then transmitting data. I am successfully able to transmit the file as well. I have to add a cmd code "0x44" in each 200 byte transfer. How can I do that? 

File transfer start

0x44  + 200 bytes

0x44 +200 bytes

0x44 + 200 bytes

...

end of transfer.

Can anyone help me modfiy the code below:-


void read_from_file(void)
{
    FRESULT ff_result;
    FIL file;
    uint32_t bytes_read;


    fatfs_ls();
    
    if(file_found_on_sdcard)
    {
          NRF_LOG_INFO("Reading from file %s",my_filename);
          ff_result = f_open(&file, my_filename, FA_READ);
          if (ff_result != FR_OK)
          {
              NRF_LOG_INFO("Unable to open or create file:%s",my_filename);
              return;
          }

          ff_result = f_read(&file, file_buffer, FILE_SIZE_MAX, (UINT *) &bytes_read);
          if (ff_result != FR_OK)
          {
              NRF_LOG_INFO("Read failed\r\n.");
          }
          else
          {
              NRF_LOG_INFO("%d bytes read.", bytes_read);
              file_actual_read_size = bytes_read;
          }

          (void) f_close(&file);
    }
    else
    {
          NRF_LOG_INFO("No file named %s found",my_filename);
          file_send_to_peripheral = false;
    }
    return;
}


void send_file_to_app(void)
{
        read_from_file();
        
      
            if(file_actual_read_size > 0)
            {
                uint16_t remaining_bytes = file_actual_read_size;
                uint16_t chunk_length = MAX_HRM_LEN;
                ret_code_t err_code;
                while(remaining_bytes > 0)
                {
                    //err_code = ble_nus_data_send(&m_nus, &file_buffer[file_actual_read_size - remaining_bytes], &chunk_length, m_conn_handle);
                    err_code = rcbr_service_send_data(&file_buffer[file_actual_read_size - remaining_bytes], chunk_length);
                    if(err_code != NRF_ERROR_RESOURCES)
                    {
                        APP_ERROR_CHECK(err_code);
                        remaining_bytes -= chunk_length;
                        if(remaining_bytes < chunk_length)
                        {
                            chunk_length = remaining_bytes;
                        }
                        NRF_LOG_INFO("Remaining bytes to send: %d", remaining_bytes);
                    }
                }

            }
            file_send_to_peripheral = false;

}

Thanks & Regards,

Snehal

Related