Luu 1 год назад
Родитель
Сommit
32716b8042
4 измененных файлов с 38 добавлено и 19 удалено
  1. 7 0
      metroflip.c
  2. 4 2
      metroflip_i.h
  3. 16 9
      scenes/metroflip_scene_navigo.c
  4. 11 8
      scenes/metroflip_scene_ravkav.c

+ 7 - 0
metroflip.c

@@ -193,3 +193,10 @@ extern int32_t metroflip(void* p) {
     metroflip_free(app);
     return 0;
 }
+
+void dec_to_bits(char dec_representation, char *bit_representation) {
+    int decimal = dec_representation - '0'; 
+    for (int i = 7; i >= 0; --i) {  
+        bit_representation[i] = (decimal & (1 << i)) ? '1' : '0';  
+    }
+}

+ 4 - 2
metroflip_i.h

@@ -37,7 +37,7 @@ extern const Icon I_RFIDDolphinReceive_97x61;
 #include <dolphin/dolphin.h>
 #include <locale/locale.h>
 #include <stdio.h>
-#include <string.h>
+#include <strings.h>
 #include <flipper_application/flipper_application.h>
 #include <loader/firmware_api/firmware_api.h>
 
@@ -122,7 +122,7 @@ void metroflip_app_blink_stop(Metroflip* metroflip);
     if(!(locked)) submenu_add_item(submenu, label, index, callback, callback_context)
 #endif
 
-// Calypso
+///////////////////////////////// Calypso /////////////////////////////////
 
 #define Metroflip_POLLER_MAX_BUFFER_SIZE 1024
 
@@ -139,3 +139,5 @@ void byte_to_binary(uint8_t byte, char* bits);
 int binary_to_decimal(const char binary[]);
 
 int bit_slice_to_dec(const char* bit_representation, int start, int end);
+
+void dec_to_bits(char dec_representation, char *bit_representation);

+ 16 - 9
scenes/metroflip_scene_navigo.c

@@ -100,12 +100,15 @@ static NfcCommand metroflip_scene_navigo_poller_callback(NfcGenericEvent event,
                 }
                 char bit_representation[response_length * 8 + 1];
                 bit_representation[0] = '\0';
-                for(size_t i = 0; i < response_length; i++) {
+                for (size_t i = 0; i < response_length; i++) {
                     char bits[9];
                     uint8_t byte = bit_buffer_get_byte(rx_buffer, i);
-                    byte_to_binary(byte, bits);
-                    strcat(bit_representation, bits);
+                    byte_to_binary(byte, bits);  
+                    for (int j = 0; j < 8; j++) {  
+                        bit_representation[i * 8 + j] = bits[j];
+                    }
                 }
+                bit_representation[response_length * 8] = '\0';
                 int start = 55, end = 70;
                 float decimal_value = bit_slice_to_dec(bit_representation, start, end);
                 float balance = decimal_value / 100;
@@ -178,11 +181,13 @@ static NfcCommand metroflip_scene_navigo_poller_callback(NfcGenericEvent event,
                 }
                 char environment_bit_representation[response_length * 8 + 1];
                 environment_bit_representation[0] = '\0';
-                for(size_t i = 0; i < response_length; i++) {
+                for (size_t i = 0; i < response_length; i++) {
                     char bits[9];
                     uint8_t byte = bit_buffer_get_byte(rx_buffer, i);
-                    byte_to_binary(byte, bits);
-                    strcat(environment_bit_representation, bits);
+                    byte_to_binary(byte, bits);  
+                    for (int j = 0; j < 8; j++) {  
+                        environment_bit_representation[i * 8 + j] = bits[j];
+                    }
                 }
                 start = 45;
                 end = 58;
@@ -256,11 +261,13 @@ static NfcCommand metroflip_scene_navigo_poller_callback(NfcGenericEvent event,
                     }
                     char event_bit_representation[response_length * 8 + 1];
                     event_bit_representation[0] = '\0';
-                    for(size_t i = 0; i < response_length; i++) {
+                    for (size_t i = 0; i < response_length; i++) {
                         char bits[9];
                         uint8_t byte = bit_buffer_get_byte(rx_buffer, i);
-                        byte_to_binary(byte, bits);
-                        strcat(event_bit_representation, bits);
+                        byte_to_binary(byte, bits);  
+                        for (int j = 0; j < 8; j++) {  
+                            event_bit_representation[i * 8 + j] = bits[j];
+                        }
                     }
                     furi_string_cat_printf(parsed_data, "\nEvent 0%d:\n", i);
                     int start = 53, end = 60;

+ 11 - 8
scenes/metroflip_scene_ravkav.c

@@ -172,11 +172,13 @@ static NfcCommand metroflip_scene_ravkav_poller_callback(NfcGenericEvent event,
                 }
                 char bit_representation[response_length * 8 + 1];
                 bit_representation[0] = '\0';
-                for(size_t i = 0; i < response_length; i++) {
+                for (size_t i = 0; i < response_length; i++) {
                     char bits[9];
                     uint8_t byte = bit_buffer_get_byte(rx_buffer, i);
-                    byte_to_binary(byte, bits);
-                    strcat(bit_representation, bits);
+                    byte_to_binary(byte, bits);  
+                    for (int j = 0; j < 8; j++) {  
+                        bit_representation[i * 8 + j] = bits[j];
+                    }
                 }
                 int start = 54, end = 83;
                 char bit_slice[end - start + 1];
@@ -248,14 +250,15 @@ static NfcCommand metroflip_scene_ravkav_poller_callback(NfcGenericEvent event,
                             app->view_dispatcher, MetroflipCustomEventPollerFileNotFound);
                         break;
                     }
-                    char bit_representation
-                        [response_length * 8 + 1]; // Total bits in the response (each byte = 8 bits)
+                    char bit_representation[response_length * 8 + 1];
                     bit_representation[0] = '\0';
-                    for(size_t i = 0; i < response_length; i++) {
+                    for (size_t i = 0; i < response_length; i++) {
                         char bits[9];
                         uint8_t byte = bit_buffer_get_byte(rx_buffer, i);
-                        byte_to_binary(byte, bits);
-                        strcat(bit_representation, bits);
+                        byte_to_binary(byte, bits);  
+                        for (int j = 0; j < 8; j++) {  
+                            bit_representation[i * 8 + j] = bits[j];
+                        }
                     }
                     int start = 23, end = 52;
                     char bit_slice[end - start + 2];