@@ -11,21 +11,22 @@ NfcComparatorReaderWorker* nfc_comparator_reader_worker_alloc() {
11
11
4096 ,
12
12
nfc_comparator_reader_worker_task ,
13
13
nfc_comparator_reader_worker );
14
+ nfc_comparator_reader_worker -> state = NfcComparatorReaderWorkerState_Stopped ;
14
15
return nfc_comparator_reader_worker ;
15
16
}
16
17
17
18
void nfc_comparator_reader_worker_free (void * context ) {
18
19
NfcComparatorReaderWorker * nfc_comparator_reader_worker = context ;
19
20
furi_assert (nfc_comparator_reader_worker );
20
21
nfc_free (nfc_comparator_reader_worker -> nfc );
21
- nfc_device_free (nfc_comparator_reader_worker -> loaded_nfc_card );
22
22
nfc_scanner_free (nfc_comparator_reader_worker -> nfc_scanner );
23
23
furi_thread_free (nfc_comparator_reader_worker -> thread );
24
24
free (nfc_comparator_reader_worker );
25
25
}
26
26
27
27
void nfc_comparator_reader_worker_scanner_callback (NfcScannerEvent event , void * context ) {
28
28
NfcComparatorReaderWorker * nfc_comparator_reader_worker = context ;
29
+ furi_assert (nfc_comparator_reader_worker );
29
30
switch (event .type ) {
30
31
case NfcScannerEventTypeDetected :
31
32
nfc_comparator_reader_worker -> protocol = event .data .protocols ;
@@ -38,6 +39,7 @@ void nfc_comparator_reader_worker_scanner_callback(NfcScannerEvent event, void*
38
39
39
40
NfcCommand nfc_comparator_reader_worker_poller_callback (NfcGenericEvent event , void * context ) {
40
41
NfcComparatorReaderWorker * nfc_comparator_reader_worker = context ;
42
+ furi_assert (nfc_comparator_reader_worker );
41
43
UNUSED (event );
42
44
NfcCommand command = NfcCommandStop ;
43
45
nfc_comparator_reader_worker -> state = NfcComparatorReaderWorkerState_Comparing ;
@@ -70,78 +72,90 @@ int32_t nfc_comparator_reader_worker_task(void* context) {
70
72
while (nfc_comparator_reader_worker -> state == NfcComparatorReaderWorkerState_Polling ) {
71
73
furi_delay_ms (100 );
72
74
}
75
+
73
76
nfc_poller_stop (nfc_poller );
74
77
75
- NfcDeviceData * nfc_device_data = (NfcDeviceData * )nfc_poller_get_data (nfc_poller );
76
78
NfcDevice * data = nfc_device_alloc ();
77
- nfc_device_set_data (data , nfc_comparator_reader_worker -> protocol [0 ], nfc_device_data );
78
-
79
- if (nfc_device_get_protocol_name (nfc_device_get_protocol (data )) ==
80
- nfc_device_get_protocol_name (
81
- nfc_device_get_protocol (nfc_comparator_reader_worker -> loaded_nfc_card ))) {
82
- nfc_comparator_reader_worker -> compare_checks -> protocol = true;
83
- } else {
84
- nfc_comparator_reader_worker -> compare_checks -> protocol = false;
85
- }
79
+ nfc_device_set_data (
80
+ data ,
81
+ nfc_comparator_reader_worker -> protocol [0 ],
82
+ (NfcDeviceData * )nfc_poller_get_data (nfc_poller ));
83
+
84
+ nfc_comparator_reader_worker -> compare_checks .protocol =
85
+ nfc_device_get_protocol_name (nfc_device_get_protocol (data )) ==
86
+ nfc_device_get_protocol_name (
87
+ nfc_device_get_protocol (nfc_comparator_reader_worker -> loaded_nfc_card )) ?
88
+ true :
89
+ false;
86
90
87
91
nfc_poller_free (nfc_poller );
88
92
89
93
size_t poller_uid_len = 0 ;
90
- const uint8_t * uid = nfc_device_get_uid (data , & poller_uid_len );
94
+ const uint8_t * poller_uid = nfc_device_get_uid (data , & poller_uid_len );
91
95
FuriString * poller_uid_str = furi_string_alloc ();
92
96
for (size_t i = 0 ; i < poller_uid_len ; i ++ ) {
93
- char uid_str [3 ];
94
- snprintf (uid_str , sizeof (uid_str ), "%02X" , uid [i ]);
95
- furi_string_cat (poller_uid_str , uid_str );
97
+ furi_string_utf8_push (poller_uid_str , poller_uid [i ]);
96
98
}
97
99
100
+ nfc_device_free (data );
101
+
98
102
size_t loaded_uid_len = 0 ;
99
103
const uint8_t * loaded_uid =
100
104
nfc_device_get_uid (nfc_comparator_reader_worker -> loaded_nfc_card , & loaded_uid_len );
101
105
FuriString * loaded_uid_str = furi_string_alloc ();
102
106
for (size_t i = 0 ; i < loaded_uid_len ; i ++ ) {
103
- char uid_str [3 ];
104
- snprintf (uid_str , sizeof (uid_str ), "%02X" , loaded_uid [i ]);
105
- furi_string_cat (loaded_uid_str , uid_str );
107
+ furi_string_utf8_push (loaded_uid_str , loaded_uid [i ]);
106
108
}
107
109
108
- if (furi_string_cmpi (poller_uid_str , loaded_uid_str ) == 0 ) {
109
- nfc_comparator_reader_worker -> compare_checks -> uid = true;
110
- } else {
111
- nfc_comparator_reader_worker -> compare_checks -> uid = false;
112
- }
110
+ nfc_comparator_reader_worker -> compare_checks .uid =
111
+ furi_string_cmpi (loaded_uid_str , poller_uid_str ) == 0 ? true : false;
113
112
114
113
furi_string_free (poller_uid_str );
115
114
furi_string_free (loaded_uid_str );
116
115
116
+ nfc_comparator_reader_worker -> state = NfcComparatorReaderWorkerState_Stopped ;
117
+
117
118
return 0 ;
118
119
}
119
120
120
121
void nfc_comparator_reader_worker_set_compare_nfc_device (void * context , NfcDevice * nfc_device ) {
121
122
NfcComparatorReaderWorker * nfc_comparator_reader_worker = context ;
123
+ furi_assert (nfc_comparator_reader_worker );
122
124
nfc_comparator_reader_worker -> loaded_nfc_card = nfc_device ;
123
125
}
124
126
125
- bool nfc_comparator_reader_worker_is_done (void * context ) {
127
+ bool nfc_comparator_reader_worker_is_running (void * context ) {
126
128
NfcComparatorReaderWorker * nfc_comparator_reader_worker = context ;
127
- return nfc_comparator_reader_worker -> state = = NfcComparatorReaderWorkerState_Stopped ;
129
+ return nfc_comparator_reader_worker -> state ! = NfcComparatorReaderWorkerState_Stopped ;
128
130
}
129
131
130
- NfcComparatorReaderWorkerCompareChecks *
131
- nfc_comparator_reader_worker_get_compare_checks (void * context ) {
132
+ NfcComparatorReaderWorkerState nfc_comparator_reader_worker_get_state (void * context ) {
132
133
NfcComparatorReaderWorker * nfc_comparator_reader_worker = context ;
133
- return nfc_comparator_reader_worker -> compare_checks ;
134
+ furi_assert (nfc_comparator_reader_worker );
135
+ return nfc_comparator_reader_worker -> state ;
136
+ }
137
+
138
+ void nfc_comparator_reader_worker_stop (void * context ) {
139
+ NfcComparatorReaderWorker * nfc_comparator_reader_worker = context ;
140
+ furi_assert (nfc_comparator_reader_worker );
141
+ if (nfc_comparator_reader_worker -> state != NfcComparatorReaderWorkerState_Stopped ) {
142
+ nfc_comparator_reader_worker -> state = NfcComparatorReaderWorkerState_Stopped ;
143
+ }
144
+ furi_thread_join (nfc_comparator_reader_worker -> thread );
134
145
}
135
146
136
147
void nfc_comparator_reader_worker_start (void * context ) {
137
148
NfcComparatorReaderWorker * nfc_comparator_reader_worker = context ;
138
149
furi_assert (nfc_comparator_reader_worker );
139
- furi_thread_start (nfc_comparator_reader_worker -> thread );
150
+ if (nfc_comparator_reader_worker -> state == NfcComparatorReaderWorkerState_Stopped ) {
151
+ nfc_comparator_reader_worker -> state = NfcComparatorReaderWorkerState_Scanning ;
152
+ furi_thread_start (nfc_comparator_reader_worker -> thread );
153
+ }
140
154
}
141
155
142
- void nfc_comparator_reader_worker_stop (void * context ) {
156
+ NfcComparatorReaderWorkerCompareChecks
157
+ nfc_comparator_reader_worker_get_compare_checks (void * context ) {
143
158
NfcComparatorReaderWorker * nfc_comparator_reader_worker = context ;
144
159
furi_assert (nfc_comparator_reader_worker );
145
- nfc_comparator_reader_worker -> state = NfcComparatorReaderWorkerState_Stopped ;
146
- furi_thread_join (nfc_comparator_reader_worker -> thread );
160
+ return nfc_comparator_reader_worker -> compare_checks ;
147
161
}
0 commit comments