@@ -5582,6 +5582,8 @@ SARA_R5_error_t SARA_R5::getFileContents(String filename, char *contents)
5582
5582
5583
5583
SARA_R5_error_t SARA_R5::getFileBlock (const String& filename, char * buffer, size_t offset, size_t requested_length, size_t & bytes_read)
5584
5584
{
5585
+ SARA_R5_error_t err;
5586
+ char *command;
5585
5587
bytes_read = 0 ;
5586
5588
if (filename.length () < 1 || buffer == nullptr || requested_length < 1 )
5587
5589
{
@@ -5599,10 +5601,15 @@ SARA_R5_error_t SARA_R5::getFileBlock(const String& filename, char* buffer, size
5599
5601
return SARA_R5_ERROR_INVALID;
5600
5602
}
5601
5603
5602
- size_t cmd_len = filename.length () + 32 ;
5603
- char * cmd = sara_r5_calloc_char (cmd_len);
5604
- sprintf (cmd, " at+urdblock=\" %s\" ,%lu,%lu\r\n " , filename.c_str (), offset, requested_length);
5605
- sendCommand (cmd, false );
5604
+ command = sara_r5_calloc_char (strlen (SARA_R5_FILE_SYSTEM_READ_BLOCK) + filename.length () + 28 );
5605
+ if (command == nullptr )
5606
+ {
5607
+ return SARA_R5_ERROR_OUT_OF_MEMORY;
5608
+ }
5609
+
5610
+ sprintf (command, " %s=\" %s\" ,%lu,%lu" , SARA_R5_FILE_SYSTEM_READ_BLOCK, filename.c_str (), offset, requested_length);
5611
+
5612
+ sendCommand (command, true );
5606
5613
5607
5614
int ich;
5608
5615
char ch;
@@ -5617,24 +5624,24 @@ SARA_R5_error_t SARA_R5::getFileBlock(const String& filename, char* buffer, size
5617
5624
continue ;
5618
5625
}
5619
5626
ch = (char )(ich & 0xFF );
5620
- cmd [bytes_read++] = ch;
5627
+ command [bytes_read++] = ch;
5621
5628
if (ch == ' "' )
5622
5629
{
5623
5630
quote_count++;
5624
5631
}
5625
- else if (ch == ' ,' && comma_idx == 0 )
5632
+ else if (ch == ' ,' && quote_count == 2 )
5626
5633
{
5627
5634
comma_idx = bytes_read;
5628
5635
}
5629
5636
}
5630
5637
5631
- cmd [bytes_read] = 0 ;
5632
- cmd [bytes_read - 2 ] = 0 ;
5638
+ command [bytes_read] = 0 ;
5639
+ command [bytes_read - 2 ] = 0 ;
5633
5640
5634
5641
// Example response:
5635
5642
// +URDBLOCK: "wombat.bin",64000,"<data starts here>... "<cr><lf>
5636
- size_t data_length = strtoul (&cmd [comma_idx], nullptr , 10 );
5637
- free (cmd );
5643
+ size_t data_length = strtoul (&command [comma_idx], nullptr , 10 );
5644
+ free (command );
5638
5645
5639
5646
bytes_read = 0 ;
5640
5647
size_t bytes_remaining = data_length;
0 commit comments