@@ -21,41 +21,41 @@ extern uint16_t m_ble_fus_max_data_len;
21
21
extern void user_cfg_set (bool restart_telemetry_timer );
22
22
extern struct gotchi_configuration gotchi_cfg_user ;
23
23
24
- static lfs_file_t file ;
24
+ extern bool sync_in_progress ;
25
+ extern struct lfs_config cfg ;
26
+ extern volatile bool update_rtc ;
27
+
28
+ extern volatile bool log_file_active ;
29
+
30
+ static lfs_file_t file_command_interface ;
25
31
static uint8_t lfs_file_buf [256 ]; // Must be cache size
26
32
static struct lfs_file_config lfs_file_config ;
27
33
static lfs_dir_t directory ;
28
34
static int32_t bytes_sent = -1 ; //file.ctz.size;
29
35
30
- void (* m_ble_tx_logbuffer )(unsigned char * data , unsigned int len );
36
+ static void (* m_ble_tx_logbuffer )(unsigned char * data , unsigned int len );
31
37
static lfs_t * m_lfs ;
32
38
33
39
static int command_input_index = 0 ;
34
40
static char command_input_buffer [ 128 ] = { 0 };
35
- static unsigned char command_response_buffer [512 ];
41
+ static unsigned char command_response_buffer [256 ];
36
42
37
- extern bool sync_in_progress ;
43
+ static void ( * m_update_time )( int syear , int smonth , int sday , int shour , int sminute , int ssecond ) ;
38
44
39
- void command_interface_init (void (* ble_send_logbuffer )(unsigned char * , unsigned int ), lfs_t * lfs )
45
+ void command_interface_init (void (* ble_send_logbuffer )(unsigned char * , unsigned int ), lfs_t * lfs , void ( * update_time )( int , int , int , int , int , int ) )
40
46
{
41
47
ASSERT (lfs != NULL );
42
48
ASSERT (ble_send_logbuffer != NULL );
43
49
m_lfs = lfs ;
44
50
m_ble_tx_logbuffer = ble_send_logbuffer ;
51
+ m_update_time = update_time ;
45
52
46
53
// Prepare the static file buffer
47
54
memset (& lfs_file_config , 0 , sizeof (struct lfs_file_config ));
48
55
lfs_file_config .buffer = lfs_file_buf ;
49
56
lfs_file_config .attr_count = 0 ;
50
57
}
51
58
52
- extern time_t currentTime ;
53
- extern struct tm * tmTime ;
54
- extern struct lfs_config cfg ;
55
- extern volatile bool update_rtc ;
56
-
57
- extern volatile bool log_file_active ;
58
-
59
59
void command_interface_process_byte (char incoming )
60
60
{
61
61
command_input_buffer [ command_input_index ++ ] = incoming ;
@@ -88,7 +88,7 @@ void command_interface_process_byte(char incoming)
88
88
if (strncmp (command_input_buffer , "cat" , 3 ) == 0 )
89
89
{
90
90
// Set the file position to what we've received on the client side
91
- lfs_file_seek (m_lfs , & file , atoi (command_input_buffer + 4 ), LFS_SEEK_SET );
91
+ lfs_file_seek (m_lfs , & file_command_interface , atoi (command_input_buffer + 4 ), LFS_SEEK_SET );
92
92
}
93
93
// Continue to send data to the client
94
94
command_interface_continue_transfer (command_input_buffer );
@@ -126,13 +126,7 @@ void command_interface_process_byte(char incoming)
126
126
NRF_LOG_FLUSH ();
127
127
128
128
// Update time in memory
129
- tmTime -> tm_year = syear - 1900 ;
130
- tmTime -> tm_mon = smonth - 1 ;
131
- tmTime -> tm_mday = sday ;
132
- tmTime -> tm_hour = shour ;
133
- tmTime -> tm_min = sminute ;
134
- tmTime -> tm_sec = ssecond ;
135
- currentTime = mktime (tmTime );
129
+ m_update_time (syear , smonth , sday , shour , sminute , ssecond );
136
130
137
131
// Update time on RTC
138
132
update_rtc = true;
@@ -189,7 +183,7 @@ void command_interface_process_byte(char incoming)
189
183
190
184
NRF_LOG_INFO ("filename %s" , filename );
191
185
NRF_LOG_FLUSH ();
192
- if (lfs_file_opencfg (m_lfs , & file , filename , LFS_O_RDONLY , & lfs_file_config ) >= 0 )
186
+ if (lfs_file_opencfg (m_lfs , & file_command_interface , filename , LFS_O_RDONLY , & lfs_file_config ) >= 0 )
193
187
{
194
188
sprintf ((char * )command_response_buffer , "cat,%s" , filename );
195
189
m_ble_tx_logbuffer (command_response_buffer , (size_t )strlen ((const char * )command_response_buffer ));
@@ -358,7 +352,7 @@ void command_interface_process_byte(char incoming)
358
352
NRF_LOG_FLUSH ();
359
353
if (sync_in_progress )
360
354
{
361
- int close_result = lfs_file_close (m_lfs , & file );
355
+ int close_result = lfs_file_close (m_lfs , & file_command_interface );
362
356
NRF_LOG_INFO ("lfs close result: %d" , close_result );
363
357
NRF_LOG_FLUSH ();
364
358
sync_in_progress = false;
@@ -417,23 +411,23 @@ void command_interface_continue_transfer(char* command)
417
411
NRF_LOG_INFO ("command_interface_continue_transfer(TRANSFER_MODE_CAT)" );
418
412
NRF_LOG_FLUSH ();
419
413
420
- if (bytes_sent >= file .ctz .size )
414
+ if (bytes_sent >= file_command_interface .ctz .size )
421
415
{
422
416
m_ble_tx_logbuffer ((unsigned char * )"cat,complete" , strlen ("cat,complete" ));
423
417
424
418
NRF_LOG_INFO ("finished cat" );
425
419
NRF_LOG_FLUSH ();
426
420
427
- int close_result = lfs_file_close (m_lfs , & file );
421
+ int close_result = lfs_file_close (m_lfs , & file_command_interface );
428
422
429
423
NRF_LOG_INFO ("cat close result: %d" , close_result );
430
424
NRF_LOG_FLUSH ();
431
425
432
426
sync_in_progress = false;
433
427
}
434
- else if (bytes_sent < file .ctz .size )
428
+ else if (bytes_sent < file_command_interface .ctz .size )
435
429
{
436
- int32_t read_response = lfs_file_read (m_lfs , & file , & command_response_buffer , m_ble_fus_max_data_len );
430
+ int32_t read_response = lfs_file_read (m_lfs , & file_command_interface , & command_response_buffer , m_ble_fus_max_data_len );
437
431
if (read_response > 0 )
438
432
{
439
433
m_ble_tx_logbuffer (command_response_buffer , read_response );
0 commit comments