@@ -193,8 +193,8 @@ static const uint8_t char_prop_crazy = ESP_GATT_CHAR_PROP_BIT_WRITE | ESP_GATT
193193
194194// start ctf data vars
195195static char writeData [100 ];
196- static char flag_state [19 ] = {'F' , 'F' , 'F' ,'F' ,'F' ,'F' ,'F' ,'F' ,'F' ,'F' ,'F' ,'F' ,'F' ,'F' ,'F' ,'F' ,'F' ,'F' ,'F' };
197- static uint8_t score_read_value [11 ] = { 'S' , 'c' , 'o' , 'r' , 'e' , ':' , ' ' , '0' , '/' , '1' , '7' } ;
196+ static char flag_state [17 ] = {'F' ,'F' ,'F' ,'F' ,'F' ,'F' ,'F' ,'F' ,'F' ,'F' ,'F' ,'F' ,'F' ,'F' ,'F' ,'F' ,'F' };
197+ static uint8_t score_read_value [31 ] = "Score: 0/17 [FFFFFFFFFFFFFFFFF]" ;
198198static const char write_any_flag [] = "Write anything here" ;
199199static const char write_ascii_flag [] = "Write the ascii value \"GLaDOS\" here" ;
200200static const char write_hex_flag [] = "Write the hex value 0x07 here" ;
@@ -215,7 +215,6 @@ static const uint8_t flag_read_value[16] = {'W','r','i','t','e', ' ', 'F', 'l','
215215int read_alot_counter = 0 ;
216216int read_counter = 0 ;
217217int score = 0 ;
218- static char string_score [10 ] = "0" ;
219218int BLINK_GPIO = 2 ;
220219int indicate_handle_state = 0 ;
221220int send_response = 0 ;
@@ -462,14 +461,10 @@ static void set_score()
462461 score += 1 ;
463462 }
464463 }
465-
466- itoa (score , string_score , 10 );
467- for (int i = 0 ; i < strlen (string_score ) ; ++ i )
468- {
469- if (strlen (string_score ) == 1 ){
470- score_read_value [7 ] = ' ' ;}
471- score_read_value [6 + i ] = string_score [i ];
472- }
464+
465+ snprintf ((char * restrict)& score_read_value [6 ], 3 , "%2d" , score );
466+ score_read_value [8 ] = '/' ; //overwrite the null terminator from the snprintf
467+ strncpy ((char * restrict)& score_read_value [13 ], flag_state , 17 );
473468 esp_ble_gatts_set_attr_value (blectf_handle_table [IDX_CHAR_SCORE ]+ 1 , sizeof score_read_value , score_read_value );
474469}
475470
0 commit comments