9
9
#include "nrf_ble_gatt.h"
10
10
#include "user_cfg.h"
11
11
12
+ extern uint16_t melody_snooze_seconds ;
12
13
extern uint16_t lfs_file_count ;
13
14
extern void display_file_count (void );
14
15
extern uint8_t lfs_free_space_check (void );
@@ -21,41 +22,41 @@ extern uint16_t m_ble_fus_max_data_len;
21
22
extern void user_cfg_set (bool restart_telemetry_timer );
22
23
extern struct gotchi_configuration gotchi_cfg_user ;
23
24
24
- static lfs_file_t file ;
25
+ extern bool sync_in_progress ;
26
+ extern struct lfs_config cfg ;
27
+ extern volatile bool update_rtc ;
28
+
29
+ extern volatile bool log_file_active ;
30
+
31
+ static lfs_file_t file_command_interface ;
25
32
static uint8_t lfs_file_buf [256 ]; // Must be cache size
26
33
static struct lfs_file_config lfs_file_config ;
27
34
static lfs_dir_t directory ;
28
35
static int32_t bytes_sent = -1 ; //file.ctz.size;
29
36
30
- void (* m_ble_tx_logbuffer )(unsigned char * data , unsigned int len );
37
+ static void (* m_ble_tx_logbuffer )(unsigned char * data , unsigned int len );
31
38
static lfs_t * m_lfs ;
32
39
33
40
static int command_input_index = 0 ;
34
41
static char command_input_buffer [ 128 ] = { 0 };
35
- static unsigned char command_response_buffer [512 ];
42
+ static unsigned char command_response_buffer [256 ];
36
43
37
- extern bool sync_in_progress ;
44
+ static void ( * m_update_time )( int syear , int smonth , int sday , int shour , int sminute , int ssecond ) ;
38
45
39
- void command_interface_init (void (* ble_send_logbuffer )(unsigned char * , unsigned int ), lfs_t * lfs )
46
+ 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
47
{
41
48
ASSERT (lfs != NULL );
42
49
ASSERT (ble_send_logbuffer != NULL );
43
50
m_lfs = lfs ;
44
51
m_ble_tx_logbuffer = ble_send_logbuffer ;
52
+ m_update_time = update_time ;
45
53
46
54
// Prepare the static file buffer
47
55
memset (& lfs_file_config , 0 , sizeof (struct lfs_file_config ));
48
56
lfs_file_config .buffer = lfs_file_buf ;
49
57
lfs_file_config .attr_count = 0 ;
50
58
}
51
59
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
60
void command_interface_process_byte (char incoming )
60
61
{
61
62
command_input_buffer [ command_input_index ++ ] = incoming ;
@@ -88,7 +89,7 @@ void command_interface_process_byte(char incoming)
88
89
if (strncmp (command_input_buffer , "cat" , 3 ) == 0 )
89
90
{
90
91
// 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 );
92
+ lfs_file_seek (m_lfs , & file_command_interface , atoi (command_input_buffer + 4 ), LFS_SEEK_SET );
92
93
}
93
94
// Continue to send data to the client
94
95
command_interface_continue_transfer (command_input_buffer );
@@ -126,13 +127,7 @@ void command_interface_process_byte(char incoming)
126
127
NRF_LOG_FLUSH ();
127
128
128
129
// 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 );
130
+ m_update_time (syear , smonth , sday , shour , sminute , ssecond );
136
131
137
132
// Update time on RTC
138
133
update_rtc = true;
@@ -189,7 +184,7 @@ void command_interface_process_byte(char incoming)
189
184
190
185
NRF_LOG_INFO ("filename %s" , filename );
191
186
NRF_LOG_FLUSH ();
192
- if (lfs_file_opencfg (m_lfs , & file , filename , LFS_O_RDONLY , & lfs_file_config ) >= 0 )
187
+ if (lfs_file_opencfg (m_lfs , & file_command_interface , filename , LFS_O_RDONLY , & lfs_file_config ) >= 0 )
193
188
{
194
189
sprintf ((char * )command_response_buffer , "cat,%s" , filename );
195
190
m_ble_tx_logbuffer (command_response_buffer , (size_t )strlen ((const char * )command_response_buffer ));
@@ -246,7 +241,7 @@ void command_interface_process_byte(char incoming)
246
241
}
247
242
else if (strncmp (command_input_buffer , "version" , 7 ) == 0 )
248
243
{
249
- sprintf ((char * )command_response_buffer , "version,0.8.2 ,beta" );
244
+ sprintf ((char * )command_response_buffer , "version,0.9.0 ,beta" );
250
245
m_ble_tx_logbuffer (command_response_buffer , strlen ((const char * )command_response_buffer ));
251
246
}
252
247
else if (strncmp (command_input_buffer , "getcfg" , 6 ) == 0 )
@@ -358,7 +353,7 @@ void command_interface_process_byte(char incoming)
358
353
NRF_LOG_FLUSH ();
359
354
if (sync_in_progress )
360
355
{
361
- int close_result = lfs_file_close (m_lfs , & file );
356
+ int close_result = lfs_file_close (m_lfs , & file_command_interface );
362
357
NRF_LOG_INFO ("lfs close result: %d" , close_result );
363
358
NRF_LOG_FLUSH ();
364
359
sync_in_progress = false;
@@ -367,6 +362,21 @@ void command_interface_process_byte(char incoming)
367
362
NRF_LOG_FLUSH ();
368
363
}
369
364
}
365
+ else if (strncmp (command_input_buffer , "snooze," , 7 ) == 0 )
366
+ {
367
+ // Set melody snooze duration
368
+ NRF_LOG_INFO ("snooze command received: %s seconds" , command_input_buffer + 7 );
369
+ NRF_LOG_FLUSH ();
370
+ melody_snooze_seconds = atoi (command_input_buffer + 7 );
371
+ }
372
+ else if (strncmp (command_input_buffer , "roboid" , 6 ) == 0 )
373
+ {
374
+ // Return robogotchi unique ID
375
+ NRF_LOG_INFO ("robogotchi ID command received" );
376
+ NRF_LOG_FLUSH ();
377
+ sprintf ((char * )command_response_buffer , "roboid,%02x%02x" , NRF_FICR -> DEVICEID [0 ], NRF_FICR -> DEVICEID [1 ]);
378
+ m_ble_tx_logbuffer (command_response_buffer , strlen ((const char * )command_response_buffer ));
379
+ }
370
380
371
381
memset (command_input_buffer , 0 , sizeof (command_input_buffer ));
372
382
command_input_index = 0 ;
@@ -417,23 +427,23 @@ void command_interface_continue_transfer(char* command)
417
427
NRF_LOG_INFO ("command_interface_continue_transfer(TRANSFER_MODE_CAT)" );
418
428
NRF_LOG_FLUSH ();
419
429
420
- if (bytes_sent >= file .ctz .size )
430
+ if (bytes_sent >= file_command_interface .ctz .size )
421
431
{
422
432
m_ble_tx_logbuffer ((unsigned char * )"cat,complete" , strlen ("cat,complete" ));
423
433
424
434
NRF_LOG_INFO ("finished cat" );
425
435
NRF_LOG_FLUSH ();
426
436
427
- int close_result = lfs_file_close (m_lfs , & file );
437
+ int close_result = lfs_file_close (m_lfs , & file_command_interface );
428
438
429
439
NRF_LOG_INFO ("cat close result: %d" , close_result );
430
440
NRF_LOG_FLUSH ();
431
441
432
442
sync_in_progress = false;
433
443
}
434
- else if (bytes_sent < file .ctz .size )
444
+ else if (bytes_sent < file_command_interface .ctz .size )
435
445
{
436
- int32_t read_response = lfs_file_read (m_lfs , & file , & command_response_buffer , m_ble_fus_max_data_len );
446
+ int32_t read_response = lfs_file_read (m_lfs , & file_command_interface , & command_response_buffer , m_ble_fus_max_data_len );
437
447
if (read_response > 0 )
438
448
{
439
449
m_ble_tx_logbuffer (command_response_buffer , read_response );
0 commit comments