@@ -78,23 +78,39 @@ void command_interface_process_byte(char incoming)
78
78
{
79
79
NRF_LOG_INFO ("ACK handler >%s<" , command_input_buffer );
80
80
NRF_LOG_FLUSH ();
81
- command_interface_continue_transfer ( command_input_buffer );
81
+ if (sync_in_progress )
82
+ {
83
+ command_interface_continue_transfer ( command_input_buffer );
84
+ }
85
+ else
86
+ {
87
+ NRF_LOG_WARNING ("ACK received while !sync_in_progress" );
88
+ NRF_LOG_FLUSH ();
89
+ }
82
90
}
83
91
else if ( strncmp (& command_input_buffer [strlen (command_input_buffer )- 4 ], "nack" , 4 ) == 0 )
84
92
{
85
93
NRF_LOG_INFO ("NACK handler >%s<" , command_input_buffer );
86
94
NRF_LOG_FLUSH ();
87
95
if (sync_in_progress )
88
96
{
89
- // For a cat command we want to seek to the byte the client last received
90
- if (strncmp (command_input_buffer , "cat" , 3 ) == 0 )
97
+ if (cat_in_progress )
91
98
{
92
- // Set the file position to what we've received on the client side
93
- lfs_file_seek (m_lfs , & file_command_interface , atoi (command_input_buffer + 4 ), LFS_SEEK_SET );
99
+ // For a cat command we want to seek to the byte the client last received
100
+ if (strncmp (command_input_buffer , "cat" , 3 ) == 0 )
101
+ {
102
+ // Set the file position to what we've received on the client side
103
+ lfs_file_seek (m_lfs , & file_command_interface , atoi (command_input_buffer + 4 ), LFS_SEEK_SET );
104
+ }
94
105
}
95
106
// Continue to send data to the client
96
107
command_interface_continue_transfer (command_input_buffer );
97
108
}
109
+ else
110
+ {
111
+ NRF_LOG_WARNING ("NACK received while !sync_in_progress" );
112
+ NRF_LOG_FLUSH ();
113
+ }
98
114
}
99
115
else if (strncmp (command_input_buffer , "log" , 3 ) == 0 )
100
116
{
@@ -191,6 +207,7 @@ void command_interface_process_byte(char incoming)
191
207
}
192
208
if (lfs_file_opencfg (m_lfs , & file_command_interface , filename , LFS_O_RDONLY , & lfs_file_config ) >= 0 )
193
209
{
210
+ lfs_file_seek (m_lfs , & file_command_interface , 0 , LFS_SEEK_SET ); //TODO: Testing rewind on open, necessary?
194
211
sprintf ((char * )command_response_buffer , "cat,%s" , filename );
195
212
m_ble_tx_logbuffer (command_response_buffer , (size_t )strlen ((const char * )command_response_buffer ));
196
213
bytes_sent = 0 ;
@@ -448,22 +465,30 @@ void command_interface_continue_transfer(char* command)
448
465
}
449
466
else if (strncmp (command_input_buffer , "cat" , 3 ) == 0 )
450
467
{
468
+ if (!cat_in_progress )
469
+ {
470
+ NRF_LOG_WARNING ("CAT ACK/NACK received while !cat_in_progress" );
471
+ NRF_LOG_FLUSH ();
472
+ return ;
473
+ }
451
474
NRF_LOG_INFO ("command_interface_continue_transfer(TRANSFER_MODE_CAT)" );
452
475
NRF_LOG_FLUSH ();
453
476
454
477
if (bytes_sent >= file_command_interface .ctz .size )
455
478
{
456
479
m_ble_tx_logbuffer ((unsigned char * )"cat,complete" , strlen ("cat,complete" ));
457
480
458
- NRF_LOG_INFO ("finished cat" );
481
+ NRF_LOG_INFO ("sending cat,complete " );
459
482
NRF_LOG_FLUSH ();
460
483
484
+ //NOTE: Leaving file open in case the client needs to ACK/NACK
485
+ //NOTE: File will be closed upon request of the next file or syncstop
486
+ /*
461
487
int close_result = lfs_file_close(m_lfs, &file_command_interface);
462
-
463
488
NRF_LOG_INFO("cat close result: %d", close_result);
464
489
NRF_LOG_FLUSH();
465
-
466
490
cat_in_progress = false;
491
+ */
467
492
}
468
493
else if (bytes_sent < file_command_interface .ctz .size )
469
494
{
0 commit comments