Skip to content

Commit c3f6d8c

Browse files
authored
Merge branch 'dev' into suica
2 parents 9023b84 + 9f5e93b commit c3f6d8c

File tree

8 files changed

+66
-29
lines changed

8 files changed

+66
-29
lines changed

applications/debug/unit_tests/tests/furi/furi_stdio_test.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ static size_t mock_in_cb(char* buffer, size_t size, FuriWait wait, void* context
3030
}
3131

3232
void test_stdin(void) {
33-
FuriThreadStdinReadCallback in_cb = furi_thread_get_stdin_callback();
33+
FuriThreadStdinReadCallback in_cb;
34+
void* in_ctx;
35+
furi_thread_get_stdin_callback(&in_cb, &in_ctx);
3436
furi_thread_set_stdin_callback(mock_in_cb, CONTEXT_MAGIC);
3537
char buf[256];
3638

@@ -63,13 +65,14 @@ void test_stdin(void) {
6365
fgets(buf, sizeof(buf), stdin);
6466
mu_assert_string_eq(" World!\n", buf);
6567

66-
furi_thread_set_stdin_callback(in_cb, CONTEXT_MAGIC);
68+
furi_thread_set_stdin_callback(in_cb, in_ctx);
6769
}
6870

6971
// stdout
7072

7173
static FuriString* mock_out;
72-
FuriThreadStdoutWriteCallback original_out_cb;
74+
static FuriThreadStdoutWriteCallback original_out_cb;
75+
static void* original_out_ctx;
7376

7477
static void mock_out_cb(const char* data, size_t size, void* context) {
7578
furi_check(context == CONTEXT_MAGIC);
@@ -83,15 +86,15 @@ static void assert_and_clear_mock_out(const char* expected) {
8386
// return the original stdout callback for the duration of the check
8487
// if the check fails, we don't want the error to end up in our buffer,
8588
// we want to be able to see it!
86-
furi_thread_set_stdout_callback(original_out_cb, CONTEXT_MAGIC);
89+
furi_thread_set_stdout_callback(original_out_cb, original_out_ctx);
8790
mu_assert_string_eq(expected, furi_string_get_cstr(mock_out));
8891
furi_thread_set_stdout_callback(mock_out_cb, CONTEXT_MAGIC);
8992

9093
furi_string_reset(mock_out);
9194
}
9295

9396
void test_stdout(void) {
94-
original_out_cb = furi_thread_get_stdout_callback();
97+
furi_thread_get_stdout_callback(&original_out_cb, &original_out_ctx);
9598
furi_thread_set_stdout_callback(mock_out_cb, CONTEXT_MAGIC);
9699
mock_out = furi_string_alloc();
97100

@@ -104,5 +107,5 @@ void test_stdout(void) {
104107
assert_and_clear_mock_out("Hello!");
105108

106109
furi_string_free(mock_out);
107-
furi_thread_set_stdout_callback(original_out_cb, CONTEXT_MAGIC);
110+
furi_thread_set_stdout_callback(original_out_cb, original_out_ctx);
108111
}

furi/core/thread.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -758,16 +758,22 @@ static int32_t __furi_thread_stdout_flush(FuriThread* thread) {
758758
return 0;
759759
}
760760

761-
FuriThreadStdoutWriteCallback furi_thread_get_stdout_callback(void) {
761+
void furi_thread_get_stdout_callback(FuriThreadStdoutWriteCallback* callback, void** context) {
762762
FuriThread* thread = furi_thread_get_current();
763763
furi_check(thread);
764-
return thread->output.write_callback;
764+
furi_check(callback);
765+
furi_check(context);
766+
*callback = thread->output.write_callback;
767+
*context = thread->output.context;
765768
}
766769

767-
FuriThreadStdinReadCallback furi_thread_get_stdin_callback(void) {
770+
void furi_thread_get_stdin_callback(FuriThreadStdinReadCallback* callback, void** context) {
768771
FuriThread* thread = furi_thread_get_current();
769772
furi_check(thread);
770-
return thread->input.read_callback;
773+
furi_check(callback);
774+
furi_check(context);
775+
*callback = thread->input.read_callback;
776+
*context = thread->input.context;
771777
}
772778

773779
void furi_thread_set_stdout_callback(FuriThreadStdoutWriteCallback callback, void* context) {

furi/core/thread.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,16 +479,18 @@ uint32_t furi_thread_get_stack_space(FuriThreadId thread_id);
479479
/**
480480
* @brief Get the standard output callback for the current thead.
481481
*
482-
* @return pointer to the standard out callback function
482+
* @param[out] callback where to store the stdout callback
483+
* @param[out] context where to store the context
483484
*/
484-
FuriThreadStdoutWriteCallback furi_thread_get_stdout_callback(void);
485+
void furi_thread_get_stdout_callback(FuriThreadStdoutWriteCallback* callback, void** context);
485486

486487
/**
487488
* @brief Get the standard input callback for the current thead.
488489
*
489-
* @return pointer to the standard in callback function
490+
* @param[out] callback where to store the stdin callback
491+
* @param[out] context where to store the context
490492
*/
491-
FuriThreadStdinReadCallback furi_thread_get_stdin_callback(void);
493+
void furi_thread_get_stdin_callback(FuriThreadStdinReadCallback* callback, void** context);
492494

493495
/** Set standard output callback for the current thread.
494496
*

lib/lfrfid/protocols/protocol_securakey.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,22 @@ uint8_t* protocol_securakey_get_data(ProtocolSecurakey* protocol) {
6161
static bool protocol_securakey_can_be_decoded(ProtocolSecurakey* protocol) {
6262
// check 19 bits preamble + format flag
6363
if(bit_lib_get_bits_32(protocol->RKKT_encoded_data, 0, 19) == 0b0111111111000000000) {
64-
protocol->bit_format = 0;
65-
return true;
64+
if(bit_lib_test_parity(protocol->RKKT_encoded_data, 2, 54, BitLibParityAlways0, 9)) {
65+
protocol->bit_format = 0;
66+
return true;
67+
}
6668
} else if(bit_lib_get_bits_32(protocol->RKKT_encoded_data, 0, 19) == 0b0111111111001011010) {
67-
protocol->bit_format = 26;
68-
return true;
69+
if(bit_lib_test_parity(protocol->RKKT_encoded_data, 2, 90, BitLibParityAlways0, 9)) {
70+
protocol->bit_format = 26;
71+
return true;
72+
}
6973
} else if(bit_lib_get_bits_32(protocol->RKKT_encoded_data, 0, 19) == 0b0111111111001100000) {
70-
protocol->bit_format = 32;
71-
return true;
72-
} else {
73-
return false;
74+
if(bit_lib_test_parity(protocol->RKKT_encoded_data, 2, 90, BitLibParityAlways0, 9)) {
75+
protocol->bit_format = 32;
76+
return true;
77+
}
7478
}
79+
return false;
7580
}
7681

7782
static void protocol_securakey_decode(ProtocolSecurakey* protocol) {

lib/toolbox/pipe.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct PipeSide {
2323
PipeSideDataArrivedCallback on_data_arrived;
2424
PipeSideSpaceFreedCallback on_space_freed;
2525
PipeSideBrokenCallback on_pipe_broken;
26+
FuriWait stdout_timeout;
2627
};
2728

2829
PipeSideBundle pipe_alloc(size_t capacity, size_t trigger_level) {
@@ -52,12 +53,14 @@ PipeSideBundle pipe_alloc_ex(PipeSideReceiveSettings alice, PipeSideReceiveSetti
5253
.shared = shared,
5354
.sending = alice_to_bob,
5455
.receiving = bob_to_alice,
56+
.stdout_timeout = FuriWaitForever,
5557
};
5658
*bobs_side = (PipeSide){
5759
.role = PipeRoleBob,
5860
.shared = shared,
5961
.sending = bob_to_alice,
6062
.receiving = alice_to_bob,
63+
.stdout_timeout = FuriWaitForever,
6164
};
6265

6366
return (PipeSideBundle){.alices_side = alices_side, .bobs_side = bobs_side};
@@ -100,7 +103,8 @@ static void _pipe_stdout_cb(const char* data, size_t size, void* context) {
100103
furi_assert(context);
101104
PipeSide* pipe = context;
102105
while(size) {
103-
size_t sent = pipe_send(pipe, data, size, FuriWaitForever);
106+
size_t sent = pipe_send(pipe, data, size, pipe->stdout_timeout);
107+
if(!sent) break;
104108
data += sent;
105109
size -= sent;
106110
}
@@ -118,6 +122,11 @@ void pipe_install_as_stdio(PipeSide* pipe) {
118122
furi_thread_set_stdin_callback(_pipe_stdin_cb, pipe);
119123
}
120124

125+
void pipe_set_stdout_timeout(PipeSide* pipe, FuriWait timeout) {
126+
furi_check(pipe);
127+
pipe->stdout_timeout = timeout;
128+
}
129+
121130
size_t pipe_receive(PipeSide* pipe, void* data, size_t length, FuriWait timeout) {
122131
furi_check(pipe);
123132
return furi_stream_buffer_receive(pipe->receiving, data, length, timeout);

lib/toolbox/pipe.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@ void pipe_free(PipeSide* pipe);
147147
*/
148148
void pipe_install_as_stdio(PipeSide* pipe);
149149

150+
/**
151+
* @brief Sets the timeout for `stdout` write operations
152+
*
153+
* @note This value is set to `FuriWaitForever` when the pipe is created
154+
*
155+
* @param [in] pipe Pipe side to set the timeout of
156+
* @param [in] timeout Timeout value in ticks
157+
*/
158+
void pipe_set_stdout_timeout(PipeSide* pipe, FuriWait timeout);
159+
150160
/**
151161
* @brief Receives data from the pipe.
152162
*

targets/f18/api_symbols.csv

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
entry,status,name,type,params
2-
Version,+,81.1,,
2+
Version,+,82.0,,
33
Header,+,applications/services/bt/bt_service/bt.h,,
44
Header,+,applications/services/bt/bt_service/bt_keys_storage.h,,
55
Header,+,applications/services/cli/cli.h,,
@@ -1666,8 +1666,8 @@ Function,+,furi_thread_get_return_code,int32_t,FuriThread*
16661666
Function,+,furi_thread_get_signal_callback,FuriThreadSignalCallback,const FuriThread*
16671667
Function,+,furi_thread_get_stack_space,uint32_t,FuriThreadId
16681668
Function,+,furi_thread_get_state,FuriThreadState,FuriThread*
1669-
Function,+,furi_thread_get_stdin_callback,FuriThreadStdinReadCallback,
1670-
Function,+,furi_thread_get_stdout_callback,FuriThreadStdoutWriteCallback,
1669+
Function,+,furi_thread_get_stdin_callback,void,"FuriThreadStdinReadCallback*, void**"
1670+
Function,+,furi_thread_get_stdout_callback,void,"FuriThreadStdoutWriteCallback*, void**"
16711671
Function,+,furi_thread_is_suspended,_Bool,FuriThreadId
16721672
Function,+,furi_thread_join,_Bool,FuriThread*
16731673
Function,+,furi_thread_list_alloc,FuriThreadList*,
@@ -2333,6 +2333,7 @@ Function,+,pipe_set_broken_callback,void,"PipeSide*, PipeSideBrokenCallback, Fur
23332333
Function,+,pipe_set_callback_context,void,"PipeSide*, void*"
23342334
Function,+,pipe_set_data_arrived_callback,void,"PipeSide*, PipeSideDataArrivedCallback, FuriEventLoopEvent"
23352335
Function,+,pipe_set_space_freed_callback,void,"PipeSide*, PipeSideSpaceFreedCallback, FuriEventLoopEvent"
2336+
Function,+,pipe_set_stdout_timeout,void,"PipeSide*, FuriWait"
23362337
Function,+,pipe_spaces_available,size_t,PipeSide*
23372338
Function,+,pipe_state,PipeState,PipeSide*
23382339
Function,+,plugin_manager_alloc,PluginManager*,"const char*, uint32_t, const ElfApiInterface*"

targets/f7/api_symbols.csv

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
entry,status,name,type,params
2-
Version,+,81.1,,
2+
Version,+,82.0,,
33
Header,+,applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h,,
44
Header,+,applications/services/bt/bt_service/bt.h,,
55
Header,+,applications/services/bt/bt_service/bt_keys_storage.h,,
@@ -1887,8 +1887,8 @@ Function,+,furi_thread_get_return_code,int32_t,FuriThread*
18871887
Function,+,furi_thread_get_signal_callback,FuriThreadSignalCallback,const FuriThread*
18881888
Function,+,furi_thread_get_stack_space,uint32_t,FuriThreadId
18891889
Function,+,furi_thread_get_state,FuriThreadState,FuriThread*
1890-
Function,+,furi_thread_get_stdin_callback,FuriThreadStdinReadCallback,
1891-
Function,+,furi_thread_get_stdout_callback,FuriThreadStdoutWriteCallback,
1890+
Function,+,furi_thread_get_stdin_callback,void,"FuriThreadStdinReadCallback*, void**"
1891+
Function,+,furi_thread_get_stdout_callback,void,"FuriThreadStdoutWriteCallback*, void**"
18921892
Function,+,furi_thread_is_suspended,_Bool,FuriThreadId
18931893
Function,+,furi_thread_join,_Bool,FuriThread*
18941894
Function,+,furi_thread_list_alloc,FuriThreadList*,
@@ -2971,6 +2971,7 @@ Function,+,pipe_set_broken_callback,void,"PipeSide*, PipeSideBrokenCallback, Fur
29712971
Function,+,pipe_set_callback_context,void,"PipeSide*, void*"
29722972
Function,+,pipe_set_data_arrived_callback,void,"PipeSide*, PipeSideDataArrivedCallback, FuriEventLoopEvent"
29732973
Function,+,pipe_set_space_freed_callback,void,"PipeSide*, PipeSideSpaceFreedCallback, FuriEventLoopEvent"
2974+
Function,+,pipe_set_stdout_timeout,void,"PipeSide*, FuriWait"
29742975
Function,+,pipe_spaces_available,size_t,PipeSide*
29752976
Function,+,pipe_state,PipeState,PipeSide*
29762977
Function,+,plugin_manager_alloc,PluginManager*,"const char*, uint32_t, const ElfApiInterface*"

0 commit comments

Comments
 (0)