@@ -28,6 +28,7 @@ extern volatile bool update_rtc;
28
28
29
29
extern volatile bool log_file_active ;
30
30
31
+ static bool cat_in_progress = false;
31
32
static lfs_file_t file_command_interface ;
32
33
static uint8_t lfs_file_buf [4096 ]; // Must be cache size
33
34
static struct lfs_file_config lfs_file_config ;
@@ -77,23 +78,39 @@ void command_interface_process_byte(char incoming)
77
78
{
78
79
NRF_LOG_INFO ("ACK handler >%s<" , command_input_buffer );
79
80
NRF_LOG_FLUSH ();
80
- 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
+ }
81
90
}
82
91
else if ( strncmp (& command_input_buffer [strlen (command_input_buffer )- 4 ], "nack" , 4 ) == 0 )
83
92
{
84
93
NRF_LOG_INFO ("NACK handler >%s<" , command_input_buffer );
85
94
NRF_LOG_FLUSH ();
86
95
if (sync_in_progress )
87
96
{
88
- // For a cat command we want to seek to the byte the client last received
89
- if (strncmp (command_input_buffer , "cat" , 3 ) == 0 )
97
+ if (cat_in_progress )
90
98
{
91
- // Set the file position to what we've received on the client side
92
- 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
+ }
93
105
}
94
106
// Continue to send data to the client
95
107
command_interface_continue_transfer (command_input_buffer );
96
108
}
109
+ else
110
+ {
111
+ NRF_LOG_WARNING ("NACK received while !sync_in_progress" );
112
+ NRF_LOG_FLUSH ();
113
+ }
97
114
}
98
115
else if (strncmp (command_input_buffer , "log" , 3 ) == 0 )
99
116
{
@@ -184,12 +201,17 @@ void command_interface_process_byte(char incoming)
184
201
185
202
NRF_LOG_INFO ("filename %s" , filename );
186
203
NRF_LOG_FLUSH ();
204
+ if (cat_in_progress )
205
+ {
206
+ lfs_file_close (m_lfs , & file_command_interface );
207
+ }
187
208
if (lfs_file_opencfg (m_lfs , & file_command_interface , filename , LFS_O_RDONLY , & lfs_file_config ) >= 0 )
188
209
{
210
+ lfs_file_seek (m_lfs , & file_command_interface , 0 , LFS_SEEK_SET ); //TODO: Testing rewind on open, necessary?
189
211
sprintf ((char * )command_response_buffer , "cat,%s" , filename );
190
212
m_ble_tx_logbuffer (command_response_buffer , (size_t )strlen ((const char * )command_response_buffer ));
191
213
bytes_sent = 0 ;
192
- sync_in_progress = true;
214
+ cat_in_progress = true;
193
215
}
194
216
}
195
217
else if (strncmp (command_input_buffer , "rm " , 3 ) == 0 && strlen (command_input_buffer ) > 3 )
@@ -241,7 +263,7 @@ void command_interface_process_byte(char incoming)
241
263
}
242
264
else if (strncmp (command_input_buffer , "version" , 7 ) == 0 )
243
265
{
244
- sprintf ((char * )command_response_buffer , "version,0.9.1 ,beta" );
266
+ sprintf ((char * )command_response_buffer , "version,0.10.0 ,beta" );
245
267
m_ble_tx_logbuffer (command_response_buffer , strlen ((const char * )command_response_buffer ));
246
268
}
247
269
else if (strncmp (command_input_buffer , "getcfg" , 6 ) == 0 )
@@ -346,21 +368,40 @@ void command_interface_process_byte(char incoming)
346
368
347
369
m_ble_tx_logbuffer (command_response_buffer , strlen ((const char * )command_response_buffer ));
348
370
}
371
+ else if (strncmp (command_input_buffer , "syncstart" , 9 ) == 0 )
372
+ {
373
+ // Sync process is starting
374
+ NRF_LOG_INFO ("syncstart command received" );
375
+ NRF_LOG_FLUSH ();
376
+ if (!sync_in_progress )
377
+ {
378
+ sync_in_progress = true;
379
+ NRF_LOG_INFO ("sync_in_progress is now true" );
380
+ NRF_LOG_FLUSH ();
381
+ } else {
382
+ NRF_LOG_INFO ("sync_in_progress was already true" );
383
+ NRF_LOG_FLUSH ();
384
+ }
385
+ }
349
386
else if (strncmp (command_input_buffer , "syncstop" , 8 ) == 0 )
350
387
{
351
388
// Sync process was aborted by the user
352
389
NRF_LOG_INFO ("syncstop command received" );
353
390
NRF_LOG_FLUSH ();
354
391
if (sync_in_progress )
355
392
{
356
- int close_result = lfs_file_close (m_lfs , & file_command_interface );
357
- NRF_LOG_INFO ("lfs close result: %d" , close_result );
358
- NRF_LOG_FLUSH ();
359
393
sync_in_progress = false;
360
394
} else {
361
395
NRF_LOG_INFO ("sync_in_progress was false" );
362
396
NRF_LOG_FLUSH ();
363
397
}
398
+ if (cat_in_progress )
399
+ {
400
+ int close_result = lfs_file_close (m_lfs , & file_command_interface );
401
+ NRF_LOG_INFO ("lfs close result: %d" , close_result );
402
+ NRF_LOG_FLUSH ();
403
+ cat_in_progress = false;
404
+ }
364
405
}
365
406
else if (strncmp (command_input_buffer , "snooze," , 7 ) == 0 )
366
407
{
@@ -374,7 +415,7 @@ void command_interface_process_byte(char incoming)
374
415
// Return robogotchi unique ID
375
416
NRF_LOG_INFO ("robogotchi ID command received" );
376
417
NRF_LOG_FLUSH ();
377
- sprintf ((char * )command_response_buffer , "roboid,%02x%02x " , NRF_FICR -> DEVICEID [0 ], NRF_FICR -> DEVICEID [1 ]);
418
+ sprintf ((char * )command_response_buffer , "roboid,%02lx%02lx " , NRF_FICR -> DEVICEID [0 ], NRF_FICR -> DEVICEID [1 ]);
378
419
m_ble_tx_logbuffer (command_response_buffer , strlen ((const char * )command_response_buffer ));
379
420
}
380
421
@@ -424,22 +465,30 @@ void command_interface_continue_transfer(char* command)
424
465
}
425
466
else if (strncmp (command_input_buffer , "cat" , 3 ) == 0 )
426
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
+ }
427
474
NRF_LOG_INFO ("command_interface_continue_transfer(TRANSFER_MODE_CAT)" );
428
475
NRF_LOG_FLUSH ();
429
476
430
477
if (bytes_sent >= file_command_interface .ctz .size )
431
478
{
432
479
m_ble_tx_logbuffer ((unsigned char * )"cat,complete" , strlen ("cat,complete" ));
433
480
434
- NRF_LOG_INFO ("finished cat" );
481
+ NRF_LOG_INFO ("sending cat,complete " );
435
482
NRF_LOG_FLUSH ();
436
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
+ /*
437
487
int close_result = lfs_file_close(m_lfs, &file_command_interface);
438
-
439
488
NRF_LOG_INFO("cat close result: %d", close_result);
440
489
NRF_LOG_FLUSH();
441
-
442
- sync_in_progress = false;
490
+ cat_in_progress = false;
491
+ */
443
492
}
444
493
else if (bytes_sent < file_command_interface .ctz .size )
445
494
{
0 commit comments