Просмотр исходного кода

Add basic support for unknown cards

DocSystem 1 год назад
Родитель
Сommit
5ac1a8ce16

+ 11 - 1
api/calypso/calypso_i.h

@@ -6,8 +6,18 @@
 #define CALYPSO_I_H
 #define CALYPSO_I_H
 
 
 typedef enum {
 typedef enum {
-    CALYPSO_CARD_NAVIGO,
+    CALYPSO_CARD_MOBIB,
     CALYPSO_CARD_OPUS,
     CALYPSO_CARD_OPUS,
+    CALYPSO_CARD_VIVA,
+    CALYPSO_CARD_PASSPASS,
+    CALYPSO_CARD_TAM,
+    CALYPSO_CARD_OURA,
+    CALYPSO_CARD_NAVIGO,
+    CALYPSO_CARD_KORRIGO,
+    CALYPSO_CARD_TISSEO,
+    CALYPSO_CARD_ENVIBUS,
+    CALYPSO_CARD_GIRONDE,
+    CALYPSO_CARD_RAVKAV,
     CALYPSO_CARD_UNKNOWN
     CALYPSO_CARD_UNKNOWN
 } CALYPSO_CARD_TYPE;
 } CALYPSO_CARD_TYPE;
 
 

+ 67 - 21
api/calypso/calypso_util.c

@@ -276,10 +276,10 @@ int get_calypso_node_size(const char* key, CalypsoApp* structure) {
 
 
 CALYPSO_CARD_TYPE guess_card_type(int country_num, int network_num) {
 CALYPSO_CARD_TYPE guess_card_type(int country_num, int network_num) {
     switch(country_num) {
     switch(country_num) {
-    case 250:
+    case 56:
         switch(network_num) {
         switch(network_num) {
-        case 901:
-            return CALYPSO_CARD_NAVIGO;
+        case 1:
+            return CALYPSO_CARD_MOBIB;
         default:
         default:
             return CALYPSO_CARD_UNKNOWN;
             return CALYPSO_CARD_UNKNOWN;
         }
         }
@@ -290,6 +290,36 @@ CALYPSO_CARD_TYPE guess_card_type(int country_num, int network_num) {
         default:
         default:
             return CALYPSO_CARD_UNKNOWN;
             return CALYPSO_CARD_UNKNOWN;
         }
         }
+    case 131:
+        return CALYPSO_CARD_VIVA;
+    case 250:
+        switch(network_num) {
+        case 0:
+            return CALYPSO_CARD_PASSPASS;
+        case 64:
+            return CALYPSO_CARD_TAM; // Montpellier
+        case 502:
+            return CALYPSO_CARD_OURA;
+        case 901:
+            return CALYPSO_CARD_NAVIGO;
+        case 908:
+            return CALYPSO_CARD_KORRIGO;
+        case 916:
+            return CALYPSO_CARD_TISSEO;
+        case 920:
+            return CALYPSO_CARD_ENVIBUS;
+        case 921:
+            return CALYPSO_CARD_GIRONDE;
+        default:
+            return CALYPSO_CARD_UNKNOWN;
+        }
+    case 376:
+        switch(network_num) {
+        case 2:
+            return CALYPSO_CARD_RAVKAV;
+        default:
+            return CALYPSO_CARD_UNKNOWN;
+        }
     default:
     default:
         return CALYPSO_CARD_UNKNOWN;
         return CALYPSO_CARD_UNKNOWN;
     }
     }
@@ -297,10 +327,16 @@ CALYPSO_CARD_TYPE guess_card_type(int country_num, int network_num) {
 
 
 const char* get_country_string(int country_num) {
 const char* get_country_string(int country_num) {
     switch(country_num) {
     switch(country_num) {
-    case 250:
-        return "France";
+    case 56:
+        return "Belgium";
     case 124:
     case 124:
         return "Canada";
         return "Canada";
+    case 131:
+        return "Portugal";
+    case 250:
+        return "France";
+    case 376:
+        return "Israel";
     default: {
     default: {
         char* country = malloc(4 * sizeof(char));
         char* country = malloc(4 * sizeof(char));
         snprintf(country, 4, "%d", country_num);
         snprintf(country, 4, "%d", country_num);
@@ -309,22 +345,32 @@ const char* get_country_string(int country_num) {
     }
     }
 }
 }
 
 
-const char* get_network_string(int country_num, int network_num) {
-    switch(country_num) {
-    case 250:
-        switch(network_num) {
-        case 901:
-            return "IDFM";
-        default:
-            return "Unknown";
-        }
-    case 124:
-        switch(network_num) {
-        case 1:
-            return "Opus";
-        default:
-            return "Unknown";
-        }
+const char* get_network_string(CALYPSO_CARD_TYPE card_type) {
+    switch(card_type) {
+    case CALYPSO_CARD_MOBIB:
+        return "Mobib";
+    case CALYPSO_CARD_OPUS:
+        return "Opus";
+    case CALYPSO_CARD_VIVA:
+        return "Viva";
+    case CALYPSO_CARD_PASSPASS:
+        return "PassPass";
+    case CALYPSO_CARD_TAM:
+        return "TAM";
+    case CALYPSO_CARD_OURA:
+        return "Oura";
+    case CALYPSO_CARD_NAVIGO:
+        return "IDFM";
+    case CALYPSO_CARD_KORRIGO:
+        return "KorriGo";
+    case CALYPSO_CARD_TISSEO:
+        return "Tisseo";
+    case CALYPSO_CARD_ENVIBUS:
+        return "Envibus";
+    case CALYPSO_CARD_GIRONDE:
+        return "Gironde";
+    case CALYPSO_CARD_RAVKAV:
+        return "Rav-Kav";
     default:
     default:
         return "Unknown";
         return "Unknown";
     }
     }

+ 1 - 1
api/calypso/calypso_util.h

@@ -97,6 +97,6 @@ CALYPSO_CARD_TYPE guess_card_type(int country_num, int network_num);
 
 
 const char* get_country_string(int country_num);
 const char* get_country_string(int country_num);
 
 
-const char* get_network_string(int country_num, int network_num);
+const char* get_network_string(CALYPSO_CARD_TYPE card_type);
 
 
 #endif // CALYPSO_UTIL_H
 #endif // CALYPSO_UTIL_H

+ 1 - 1
api/calypso/transit/navigo.c

@@ -506,7 +506,7 @@ void show_navigo_environment_info(NavigoCardEnv* environment, FuriString* parsed
     furi_string_cat_printf(
     furi_string_cat_printf(
         parsed_data,
         parsed_data,
         "Network: %s\n",
         "Network: %s\n",
-        get_network_string(environment->country_num, environment->network_num));
+        get_network_string(guess_card_type(environment->country_num, environment->network_num)));
     furi_string_cat_printf(parsed_data, "End of validity:\n");
     furi_string_cat_printf(parsed_data, "End of validity:\n");
     locale_format_datetime_cat(parsed_data, &environment->end_dt, false);
     locale_format_datetime_cat(parsed_data, &environment->end_dt, false);
     furi_string_cat_printf(parsed_data, "\n");
     furi_string_cat_printf(parsed_data, "\n");

+ 1 - 1
api/calypso/transit/opus.c

@@ -118,7 +118,7 @@ void show_opus_environment_info(OpusCardEnv* environment, FuriString* parsed_dat
     furi_string_cat_printf(
     furi_string_cat_printf(
         parsed_data,
         parsed_data,
         "Network: %s\n",
         "Network: %s\n",
-        get_network_string(environment->country_num, environment->network_num));
+        get_network_string(guess_card_type(environment->country_num, environment->network_num)));
     furi_string_cat_printf(parsed_data, "End of validity:\n");
     furi_string_cat_printf(parsed_data, "End of validity:\n");
     locale_format_datetime_cat(parsed_data, &environment->end_dt, false);
     locale_format_datetime_cat(parsed_data, &environment->end_dt, false);
     furi_string_cat_printf(parsed_data, "\n");
     furi_string_cat_printf(parsed_data, "\n");

+ 39 - 3
scenes/metroflip_scene_calypso.c

@@ -99,6 +99,14 @@ int check_response(
 void update_page_info(void* context, FuriString* parsed_data) {
 void update_page_info(void* context, FuriString* parsed_data) {
     Metroflip* app = context;
     Metroflip* app = context;
     CalypsoContext* ctx = app->calypso_context;
     CalypsoContext* ctx = app->calypso_context;
+    if(ctx->card->card_type != CALYPSO_CARD_NAVIGO && ctx->card->card_type != CALYPSO_CARD_OPUS) {
+        furi_string_cat_printf(
+            parsed_data,
+            "\e#%s %u:\n",
+            get_network_string(ctx->card->card_type),
+            ctx->card->card_number);
+        return;
+    }
     if(ctx->page_id == 0 || ctx->page_id == 1 || ctx->page_id == 2 || ctx->page_id == 3) {
     if(ctx->page_id == 0 || ctx->page_id == 1 || ctx->page_id == 2 || ctx->page_id == 3) {
         switch(ctx->card->card_type) {
         switch(ctx->card->card_type) {
         case CALYPSO_CARD_NAVIGO: {
         case CALYPSO_CARD_NAVIGO: {
@@ -165,6 +173,11 @@ void update_widget_elements(void* context) {
     Metroflip* app = context;
     Metroflip* app = context;
     CalypsoContext* ctx = app->calypso_context;
     CalypsoContext* ctx = app->calypso_context;
     Widget* widget = app->widget;
     Widget* widget = app->widget;
+    if(ctx->card->card_type != CALYPSO_CARD_NAVIGO && ctx->card->card_type != CALYPSO_CARD_OPUS) {
+        widget_add_button_element(
+            widget, GuiButtonTypeRight, "Exit", metroflip_next_button_widget_callback, context);
+        return;
+    }
     if(ctx->page_id < 7) {
     if(ctx->page_id < 7) {
         widget_add_button_element(
         widget_add_button_element(
             widget, GuiButtonTypeRight, "Next", metroflip_next_button_widget_callback, context);
             widget, GuiButtonTypeRight, "Next", metroflip_next_button_widget_callback, context);
@@ -234,6 +247,13 @@ void metroflip_next_button_widget_callback(GuiButtonType result, InputType type,
 
 
         FURI_LOG_I(TAG, "Page ID: %d -> %d", ctx->page_id, ctx->page_id + 1);
         FURI_LOG_I(TAG, "Page ID: %d -> %d", ctx->page_id, ctx->page_id + 1);
 
 
+        if(ctx->card->card_type != CALYPSO_CARD_NAVIGO &&
+           ctx->card->card_type != CALYPSO_CARD_OPUS) {
+            ctx->page_id = 0;
+            scene_manager_search_and_switch_to_previous_scene(
+                app->scene_manager, MetroflipSceneStart);
+            return;
+        }
         if(ctx->page_id < 7) {
         if(ctx->page_id < 7) {
             if(ctx->page_id == 0 && ctx->card->contracts_count < 2) {
             if(ctx->page_id == 0 && ctx->card->contracts_count < 2) {
                 ctx->page_id += 1;
                 ctx->page_id += 1;
@@ -406,9 +426,7 @@ static NfcCommand metroflip_scene_navigo_poller_callback(NfcGenericEvent event,
                     bit_slice_to_dec(environment_bit_representation, start, end) * 100 +
                     bit_slice_to_dec(environment_bit_representation, start, end) * 100 +
                     bit_slice_to_dec(environment_bit_representation, start + 4, end + 4) * 10 +
                     bit_slice_to_dec(environment_bit_representation, start + 4, end + 4) * 10 +
                     bit_slice_to_dec(environment_bit_representation, start + 8, end + 8);
                     bit_slice_to_dec(environment_bit_representation, start + 8, end + 8);
-                if(guess_card_type(country_num, network_num) != CALYPSO_CARD_UNKNOWN) {
-                    card->card_type = guess_card_type(country_num, network_num);
-                }
+                card->card_type = guess_card_type(country_num, network_num);
                 switch(card->card_type) {
                 switch(card->card_type) {
                 case CALYPSO_CARD_NAVIGO: {
                 case CALYPSO_CARD_NAVIGO: {
                     card->navigo = malloc(sizeof(NavigoCardData));
                     card->navigo = malloc(sizeof(NavigoCardData));
@@ -1328,6 +1346,24 @@ static NfcCommand metroflip_scene_navigo_poller_callback(NfcGenericEvent event,
 
 
                     break;
                     break;
                 }
                 }
+                case CALYPSO_CARD_UNKNOWN: {
+                    start = 3;
+                    end = 6;
+                    country_num =
+                        bit_slice_to_dec(environment_bit_representation, start, end) * 100 +
+                        bit_slice_to_dec(environment_bit_representation, start + 4, end + 4) * 10 +
+                        bit_slice_to_dec(environment_bit_representation, start + 8, end + 8);
+                    start = 15;
+                    end = 18;
+                    network_num =
+                        bit_slice_to_dec(environment_bit_representation, start, end) * 100 +
+                        bit_slice_to_dec(environment_bit_representation, start + 4, end + 4) * 10 +
+                        bit_slice_to_dec(environment_bit_representation, start + 8, end + 8);
+                    card->card_type = guess_card_type(country_num, network_num);
+                    if(card->card_type == CALYPSO_CARD_RAVKAV) {
+                    }
+                    break;
+                }
                 default:
                 default:
                     break;
                     break;
                 }
                 }