navigo.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. #include "navigo.h"
  2. #include "navigo_lists.h"
  3. #include "../../../metroflip_i.h"
  4. const char* get_navigo_service_provider(int provider) {
  5. switch(provider) {
  6. case NAVIGO_PROVIDER_SNCF:
  7. return "SNCF";
  8. case NAVIGO_PROVIDER_RATP:
  9. return "RATP";
  10. case 4:
  11. case 10:
  12. return "IDF Mobilites";
  13. case NAVIGO_PROVIDER_ORA:
  14. return "ORA";
  15. case NAVIGO_PROVIDER_VEOLIA_CSO:
  16. return "CSO (VEOLIA)";
  17. case NAVIGO_PROVIDER_VEOLIA_RBUS:
  18. return "R'Bus (VEOLIA)";
  19. case NAVIGO_PROVIDER_PHEBUS:
  20. return "Phebus";
  21. case NAVIGO_PROVIDER_RATP_VEOLIA_NANTERRE:
  22. return "RATP (Veolia Transport Nanterre)";
  23. default: {
  24. char* provider_str = malloc(6 * sizeof(char));
  25. snprintf(provider_str, 6, "%d", provider);
  26. return provider_str;
  27. }
  28. }
  29. }
  30. const char* get_navigo_tariff(int tariff) {
  31. switch(tariff) {
  32. case 0x0000:
  33. return "Navigo Mois";
  34. case 0x0001:
  35. return "Navigo Semaine";
  36. case 0x0002:
  37. return "Navigo Annuel";
  38. case 0x0003:
  39. return "Navigo Jour";
  40. case 0x0004:
  41. return "Imagine R Junior";
  42. case 0x0005:
  43. return "Imagine R Etudiant";
  44. case 0x000D:
  45. return "Navigo Jeunes Week-end";
  46. case 0x0015:
  47. return "Paris-Visite"; // Theoric
  48. case 0x1000:
  49. return "Navigo Liberte+";
  50. case 0x4000:
  51. return "Navigo Mois 75%%";
  52. case 0x4001:
  53. return "Navigo Semaine 75%%";
  54. case 0x4015:
  55. return "Paris-Visite (Enfant)"; // Theoric
  56. case 0x5000:
  57. return "Tickets T+";
  58. case 0x5004:
  59. return "Tickets OrlyBus"; // Theoric
  60. case 0x5005:
  61. return "Tickets RoissyBus"; // Theoric
  62. case 0x5006:
  63. return "Bus-Tram"; // Theoric
  64. case 0x5008:
  65. return "Metro-Train-RER"; // Theoric
  66. case 0x500b:
  67. return "Paris <> Aeroports"; // Theoric
  68. case 0x5010:
  69. return "Tickets T+ (Reduit)"; // Theoric
  70. case 0x5016:
  71. return "Bus-Tram (Reduit)"; // Theoric
  72. case 0x5018:
  73. return "Metro-Train-RER (Reduit)"; // Theoric
  74. case 0x501b:
  75. return "Paris <> Aeroports (Reduit)"; // Theoric
  76. case 0x8003:
  77. return "Navigo Solidarite Gratuit";
  78. default: {
  79. char* tariff_str = malloc(6 * sizeof(char));
  80. snprintf(tariff_str, 6, "%d", tariff);
  81. return tariff_str;
  82. }
  83. }
  84. }
  85. const char* get_zones(int* zones) {
  86. if(zones[0] && zones[4]) {
  87. return "All Zones (1-5)";
  88. } else if(zones[0] && zones[3]) {
  89. return "Zones 1-4";
  90. } else if(zones[0] && zones[2]) {
  91. return "Zones 1-3";
  92. } else if(zones[0] && zones[1]) {
  93. return "Zones 1-2";
  94. } else if(zones[0]) {
  95. return "Zone 1";
  96. } else if(zones[1] && zones[4]) {
  97. return "Zones 2-5";
  98. } else if(zones[1] && zones[3]) {
  99. return "Zones 2-4";
  100. } else if(zones[1] && zones[2]) {
  101. return "Zones 2-3";
  102. } else if(zones[1]) {
  103. return "Zone 2";
  104. } else if(zones[2] && zones[4]) {
  105. return "Zones 3-5";
  106. } else if(zones[2] && zones[3]) {
  107. return "Zones 3-4";
  108. } else if(zones[2]) {
  109. return "Zone 3";
  110. } else if(zones[3] && zones[4]) {
  111. return "Zones 4-5";
  112. } else if(zones[3]) {
  113. return "Zone 4";
  114. } else if(zones[4]) {
  115. return "Zone 5";
  116. } else {
  117. return "Unknown";
  118. }
  119. }
  120. char* get_token(char* psrc, const char* delimit, void* psave) {
  121. static char sret[512];
  122. register char* ptr = psave;
  123. memset(sret, 0, sizeof(sret));
  124. if(psrc != NULL) strcpy(ptr, psrc);
  125. if(ptr == NULL) return NULL;
  126. int i = 0, nlength = strlen(ptr);
  127. for(i = 0; i < nlength; i++) {
  128. if(ptr[i] == delimit[0]) break;
  129. if(ptr[i] == delimit[1]) {
  130. ptr = NULL;
  131. break;
  132. }
  133. sret[i] = ptr[i];
  134. }
  135. if(ptr != NULL) strcpy(ptr, &ptr[i + 1]);
  136. return sret;
  137. }
  138. char* get_navigo_station(
  139. int station_group_id,
  140. int station_id,
  141. int station_sub_id,
  142. int transport_type) {
  143. switch(transport_type) {
  144. case COMMUTER_TRAIN: {
  145. if(station_group_id < 77 && station_id < 19) {
  146. char* file_path = malloc(256 * sizeof(char));
  147. if(!file_path) {
  148. return "Unknown";
  149. }
  150. snprintf(
  151. file_path,
  152. 256,
  153. APP_ASSETS_PATH("navigo/stations/train/stations_%d.txt"),
  154. station_group_id);
  155. const char* sncf_stations_path = file_path;
  156. Storage* storage = furi_record_open(RECORD_STORAGE);
  157. Stream* stream = file_stream_alloc(storage);
  158. FuriString* line = furi_string_alloc();
  159. char* found_station_name = NULL;
  160. if(file_stream_open(stream, sncf_stations_path, FSAM_READ, FSOM_OPEN_EXISTING)) {
  161. while(stream_read_line(stream, line)) {
  162. // file is in csv format: station_id,station_sub_id,station_name
  163. // search for the station
  164. furi_string_replace_all(line, "\r", "");
  165. furi_string_replace_all(line, "\n", "");
  166. const char* string_line = furi_string_get_cstr(line);
  167. char* string_line_copy = strdup(string_line);
  168. if(!string_line_copy) {
  169. return "Unknown";
  170. }
  171. int line_station_id = atoi(get_token(string_line_copy, ",", string_line_copy));
  172. int line_station_sub_id =
  173. atoi(get_token(string_line_copy, ",", string_line_copy));
  174. if(line_station_id == station_id && line_station_sub_id == station_sub_id) {
  175. found_station_name =
  176. strdup(get_token(string_line_copy, ",", string_line_copy));
  177. free(string_line_copy);
  178. break;
  179. }
  180. free(string_line_copy);
  181. }
  182. } else {
  183. FURI_LOG_E("Metroflip:Scene:Calypso", "Failed to open train stations file");
  184. }
  185. furi_string_free(line);
  186. file_stream_close(stream);
  187. stream_free(stream);
  188. free(file_path);
  189. if(found_station_name) {
  190. return found_station_name;
  191. }
  192. }
  193. // cast station_group_id-station_id-station_sub_id to a string
  194. char* station = malloc(12 * sizeof(char));
  195. if(!station) {
  196. return "Unknown";
  197. }
  198. snprintf(station, 10, "%d-%d-%d", station_group_id, station_id, station_sub_id);
  199. return station;
  200. }
  201. case TRAM: {
  202. char* file_path = malloc(256 * sizeof(char));
  203. if(!file_path) {
  204. return "Unknown";
  205. }
  206. snprintf(
  207. file_path,
  208. 256,
  209. APP_ASSETS_PATH("navigo/stations/tram/stations_%d.txt"),
  210. station_group_id);
  211. const char* sncf_stations_path = file_path;
  212. Storage* storage = furi_record_open(RECORD_STORAGE);
  213. Stream* stream = file_stream_alloc(storage);
  214. FuriString* line = furi_string_alloc();
  215. char* found_station_name = NULL;
  216. if(file_stream_open(stream, sncf_stations_path, FSAM_READ, FSOM_OPEN_EXISTING)) {
  217. while(stream_read_line(stream, line)) {
  218. // file is in csv format: station_id,station_sub_id,station_name
  219. // search for the station
  220. furi_string_replace_all(line, "\r", "");
  221. furi_string_replace_all(line, "\n", "");
  222. const char* string_line = furi_string_get_cstr(line);
  223. char* string_line_copy = strdup(string_line);
  224. if(!string_line_copy) {
  225. return "Unknown";
  226. }
  227. int line_station_id = atoi(get_token(string_line_copy, ",", string_line_copy));
  228. int line_station_sub_id = atoi(get_token(string_line_copy, ",", string_line_copy));
  229. if(line_station_id == station_id && line_station_sub_id == station_sub_id) {
  230. found_station_name =
  231. strdup(get_token(string_line_copy, ",", string_line_copy));
  232. free(string_line_copy);
  233. break;
  234. }
  235. free(string_line_copy);
  236. }
  237. } else {
  238. FURI_LOG_E("Metroflip:Scene:Calypso", "Failed to open tram stations file");
  239. }
  240. furi_string_free(line);
  241. file_stream_close(stream);
  242. stream_free(stream);
  243. free(file_path);
  244. if(found_station_name) {
  245. return found_station_name;
  246. }
  247. // cast station_group_id-station_id-station_sub_id to a string
  248. char* station = malloc(12 * sizeof(char));
  249. if(!station) {
  250. return "Unknown";
  251. }
  252. if(station_sub_id != 0) {
  253. snprintf(station, 10, "%d-%d-%d", station_group_id, station_id, station_sub_id);
  254. } else if(station_id != 0) {
  255. snprintf(station, 10, "%d-%d", station_group_id, station_id);
  256. } else {
  257. snprintf(station, 10, "%d", station_group_id);
  258. }
  259. return station;
  260. }
  261. case METRO: {
  262. if(station_group_id < 32 && station_id < 16) {
  263. char* file_path = malloc(256 * sizeof(char));
  264. if(!file_path) {
  265. return "Unknown";
  266. }
  267. snprintf(
  268. file_path,
  269. 256,
  270. APP_ASSETS_PATH("navigo/stations/metro/stations_%d.txt"),
  271. station_group_id);
  272. const char* ratp_stations_path = file_path;
  273. Storage* storage = furi_record_open(RECORD_STORAGE);
  274. Stream* stream = file_stream_alloc(storage);
  275. FuriString* line = furi_string_alloc();
  276. char* found_station_name = NULL;
  277. if(file_stream_open(stream, ratp_stations_path, FSAM_READ, FSOM_OPEN_EXISTING)) {
  278. while(stream_read_line(stream, line)) {
  279. // file is in csv format: station_id,station_name
  280. // search for the station
  281. furi_string_replace_all(line, "\r", "");
  282. furi_string_replace_all(line, "\n", "");
  283. const char* string_line = furi_string_get_cstr(line);
  284. char* string_line_copy = strdup(string_line);
  285. if(!string_line_copy) {
  286. return "Unknown";
  287. }
  288. int line_station_id = atoi(get_token(string_line_copy, ",", string_line_copy));
  289. if(line_station_id == station_id) {
  290. found_station_name =
  291. strdup(get_token(string_line_copy, ",", string_line_copy));
  292. free(string_line_copy);
  293. break;
  294. }
  295. free(string_line_copy);
  296. }
  297. } else {
  298. FURI_LOG_E("Metroflip:Scene:Calypso", "Failed to open metro stations file");
  299. }
  300. furi_string_free(line);
  301. file_stream_close(stream);
  302. stream_free(stream);
  303. free(file_path);
  304. if(found_station_name) {
  305. return found_station_name;
  306. }
  307. }
  308. // cast station_group_id-station_id to a string
  309. char* station = malloc(12 * sizeof(char));
  310. if(!station) {
  311. return "Unknown";
  312. }
  313. if(station_sub_id != 0) {
  314. snprintf(station, 10, "%d-%d-%d", station_group_id, station_id, station_sub_id);
  315. } else if(station_id != 0) {
  316. snprintf(station, 10, "%d-%d", station_group_id, station_id);
  317. } else {
  318. snprintf(station, 10, "%d", station_group_id);
  319. }
  320. return station;
  321. }
  322. default: {
  323. // cast station_group_id-station_id to a string
  324. char* station = malloc(12 * sizeof(char));
  325. if(!station) {
  326. return "Unknown";
  327. }
  328. if(station_sub_id != 0) {
  329. snprintf(station, 10, "%d-%d-%d", station_group_id, station_id, station_sub_id);
  330. } else if(station_id != 0) {
  331. snprintf(station, 10, "%d-%d", station_group_id, station_id);
  332. } else {
  333. snprintf(station, 10, "%d", station_group_id);
  334. }
  335. return station;
  336. }
  337. }
  338. }
  339. char* get_navigo_train_sector(int station_group_id) {
  340. // group id is in format XY where X is the sector
  341. const char* station_name = NAVIGO_SNCF_SECTORS_LIST[station_group_id / 10];
  342. return strdup(station_name);
  343. }
  344. const char* get_navigo_tram_line(int route_number) {
  345. switch(route_number) {
  346. case 1:
  347. case 13:
  348. return "T3a";
  349. case 9:
  350. return "T9";
  351. case 16:
  352. return "T6";
  353. case 18:
  354. return "T8";
  355. default: {
  356. char* line = malloc(5 * sizeof(char));
  357. if(!line) {
  358. return "Unknown";
  359. }
  360. snprintf(line, 5, "?%d?", route_number);
  361. return line;
  362. }
  363. }
  364. }
  365. void show_navigo_event_info(
  366. NavigoCardEvent* event,
  367. NavigoCardContract* contracts,
  368. FuriString* parsed_data) {
  369. if(event->used_contract == 0) {
  370. furi_string_cat_printf(parsed_data, "No event data\n");
  371. return;
  372. }
  373. char* station = get_navigo_station(
  374. event->station_group_id, event->station_id, event->station_sub_id, event->transport_type);
  375. char* sector = NULL;
  376. if(event->transport_type == COMMUTER_TRAIN) {
  377. sector = get_navigo_train_sector(event->station_group_id);
  378. } else {
  379. sector = get_navigo_station(event->station_group_id, 0, 0, event->transport_type);
  380. }
  381. if(event->transport_type == URBAN_BUS || event->transport_type == INTERURBAN_BUS ||
  382. event->transport_type == METRO || event->transport_type == TRAM) {
  383. if(event->route_number_available) {
  384. if(event->transport_type == METRO && event->route_number == 103) {
  385. furi_string_cat_printf(
  386. parsed_data,
  387. "%s 3 bis\n%s\n",
  388. get_intercode_string_transport_type(event->transport_type),
  389. get_intercode_string_transition_type(event->transition));
  390. } else if(event->transport_type == TRAM) {
  391. furi_string_cat_printf(
  392. parsed_data,
  393. "%s %s\n%s\n",
  394. get_intercode_string_transport_type(event->transport_type),
  395. get_navigo_tram_line(event->route_number),
  396. get_intercode_string_transition_type(event->transition));
  397. } else {
  398. furi_string_cat_printf(
  399. parsed_data,
  400. "%s %d\n%s\n",
  401. get_intercode_string_transport_type(event->transport_type),
  402. event->route_number,
  403. get_intercode_string_transition_type(event->transition));
  404. }
  405. } else {
  406. furi_string_cat_printf(
  407. parsed_data,
  408. "%s\n%s\n",
  409. get_intercode_string_transport_type(event->transport_type),
  410. get_intercode_string_transition_type(event->transition));
  411. }
  412. furi_string_cat_printf(
  413. parsed_data,
  414. "Transporter: %s\n",
  415. get_navigo_service_provider(event->service_provider));
  416. furi_string_cat_printf(parsed_data, "Station: %s\nSector: %s\n", station, sector);
  417. if(event->location_gate_available) {
  418. furi_string_cat_printf(parsed_data, "Gate: %d\n", event->location_gate);
  419. }
  420. if(event->device_available) {
  421. if(event->transport_type == URBAN_BUS || event->transport_type == INTERURBAN_BUS) {
  422. const char* side = event->side == 0 ? "right" : "left";
  423. furi_string_cat_printf(parsed_data, "Door: %d\nSide: %s\n", event->door, side);
  424. } else {
  425. furi_string_cat_printf(parsed_data, "Device: %d\n", event->device);
  426. }
  427. }
  428. if(event->mission_available) {
  429. furi_string_cat_printf(parsed_data, "Mission: %d\n", event->mission);
  430. }
  431. if(event->vehicle_id_available) {
  432. furi_string_cat_printf(parsed_data, "Vehicle: %d\n", event->vehicle_id);
  433. }
  434. if(event->used_contract_available) {
  435. furi_string_cat_printf(
  436. parsed_data,
  437. "Contract: %d - %s\n",
  438. event->used_contract,
  439. get_navigo_tariff(contracts[event->used_contract - 1].tariff));
  440. }
  441. locale_format_datetime_cat(parsed_data, &event->date, true);
  442. furi_string_cat_printf(parsed_data, "\n");
  443. } else if(event->transport_type == COMMUTER_TRAIN) {
  444. if(event->route_number_available) {
  445. furi_string_cat_printf(
  446. parsed_data,
  447. "RER %c\n%s\n",
  448. (65 + event->route_number - 17),
  449. get_intercode_string_transition_type(event->transition));
  450. } else {
  451. furi_string_cat_printf(
  452. parsed_data,
  453. "%s\n%s\n",
  454. get_intercode_string_transport_type(event->transport_type),
  455. get_intercode_string_transition_type(event->transition));
  456. }
  457. furi_string_cat_printf(
  458. parsed_data,
  459. "Transporter: %s\n",
  460. get_navigo_service_provider(event->service_provider));
  461. furi_string_cat_printf(parsed_data, "Station: %s\nSector: %s\n", station, sector);
  462. if(event->location_gate_available) {
  463. furi_string_cat_printf(parsed_data, "Gate: %d\n", event->location_gate);
  464. }
  465. if(event->device_available) {
  466. if(event->service_provider == NAVIGO_PROVIDER_SNCF) {
  467. furi_string_cat_printf(parsed_data, "Device: %d\n", event->device & 0xFF);
  468. } else {
  469. furi_string_cat_printf(parsed_data, "Device: %d\n", event->device);
  470. }
  471. }
  472. if(event->mission_available) {
  473. furi_string_cat_printf(parsed_data, "Mission: %d\n", event->mission);
  474. }
  475. if(event->vehicle_id_available) {
  476. furi_string_cat_printf(parsed_data, "Vehicle: %d\n", event->vehicle_id);
  477. }
  478. if(event->used_contract_available) {
  479. furi_string_cat_printf(
  480. parsed_data,
  481. "Contract: %d - %s\n",
  482. event->used_contract,
  483. get_navigo_tariff(contracts[event->used_contract - 1].tariff));
  484. }
  485. locale_format_datetime_cat(parsed_data, &event->date, true);
  486. furi_string_cat_printf(parsed_data, "\n");
  487. } else {
  488. furi_string_cat_printf(
  489. parsed_data,
  490. "%s - %s\n",
  491. get_intercode_string_transport_type(event->transport_type),
  492. get_intercode_string_transition_type(event->transition));
  493. furi_string_cat_printf(
  494. parsed_data,
  495. "Transporter: %s\n",
  496. get_navigo_service_provider(event->service_provider));
  497. furi_string_cat_printf(parsed_data, "Station: %s\nSector: %s\n", station, sector);
  498. if(event->location_gate_available) {
  499. furi_string_cat_printf(parsed_data, "Gate: %d\n", event->location_gate);
  500. }
  501. if(event->device_available) {
  502. furi_string_cat_printf(parsed_data, "Device: %d\n", event->device);
  503. }
  504. if(event->mission_available) {
  505. furi_string_cat_printf(parsed_data, "Mission: %d\n", event->mission);
  506. }
  507. if(event->vehicle_id_available) {
  508. furi_string_cat_printf(parsed_data, "Vehicle: %d\n", event->vehicle_id);
  509. }
  510. if(event->used_contract_available) {
  511. furi_string_cat_printf(
  512. parsed_data,
  513. "Contract: %d - %s\n",
  514. event->used_contract,
  515. get_navigo_tariff(contracts[event->used_contract - 1].tariff));
  516. }
  517. locale_format_datetime_cat(parsed_data, &event->date, true);
  518. furi_string_cat_printf(parsed_data, "\n");
  519. }
  520. free(station);
  521. free(sector);
  522. }
  523. void show_navigo_special_event_info(NavigoCardSpecialEvent* event, FuriString* parsed_data) {
  524. char* station = get_navigo_station(
  525. event->station_group_id, event->station_id, event->station_sub_id, event->transport_type);
  526. char* sector = NULL;
  527. if(event->transport_type == COMMUTER_TRAIN) {
  528. sector = get_navigo_train_sector(event->station_group_id);
  529. } else {
  530. sector = get_navigo_station(event->station_group_id, 0, 0, event->transport_type);
  531. }
  532. if(event->transport_type == URBAN_BUS || event->transport_type == INTERURBAN_BUS ||
  533. event->transport_type == METRO || event->transport_type == TRAM) {
  534. if(event->route_number_available) {
  535. if(event->transport_type == METRO && event->route_number == 103) {
  536. furi_string_cat_printf(
  537. parsed_data,
  538. "%s 3 bis\n%s\n",
  539. get_intercode_string_transport_type(event->transport_type),
  540. get_intercode_string_transition_type(event->transition));
  541. } else if(event->transport_type == TRAM) {
  542. furi_string_cat_printf(
  543. parsed_data,
  544. "%s %s\n%s\n",
  545. get_intercode_string_transport_type(event->transport_type),
  546. get_navigo_tram_line(event->route_number),
  547. get_intercode_string_transition_type(event->transition));
  548. } else {
  549. furi_string_cat_printf(
  550. parsed_data,
  551. "%s %d\n%s\n",
  552. get_intercode_string_transport_type(event->transport_type),
  553. event->route_number,
  554. get_intercode_string_transition_type(event->transition));
  555. }
  556. } else {
  557. furi_string_cat_printf(
  558. parsed_data,
  559. "%s\n%s\n",
  560. get_intercode_string_transport_type(event->transport_type),
  561. get_intercode_string_transition_type(event->transition));
  562. }
  563. furi_string_cat_printf(
  564. parsed_data, "Result: %s\n", get_intercode_string_event_result(event->result));
  565. furi_string_cat_printf(
  566. parsed_data,
  567. "Transporter: %s\n",
  568. get_navigo_service_provider(event->service_provider));
  569. furi_string_cat_printf(parsed_data, "Station: %s\nSector: %s\n", station, sector);
  570. if(event->device_available) {
  571. furi_string_cat_printf(parsed_data, "Device: %d\n", event->device);
  572. }
  573. locale_format_datetime_cat(parsed_data, &event->date, true);
  574. furi_string_cat_printf(parsed_data, "\n");
  575. } else if(event->transport_type == COMMUTER_TRAIN) {
  576. if(event->route_number_available) {
  577. furi_string_cat_printf(
  578. parsed_data,
  579. "RER %c\n%s\n",
  580. (65 + event->route_number - 17),
  581. get_intercode_string_transition_type(event->transition));
  582. } else {
  583. furi_string_cat_printf(
  584. parsed_data,
  585. "%s\n%s\n",
  586. get_intercode_string_transport_type(event->transport_type),
  587. get_intercode_string_transition_type(event->transition));
  588. }
  589. furi_string_cat_printf(
  590. parsed_data, "Result: %s\n", get_intercode_string_event_result(event->result));
  591. furi_string_cat_printf(
  592. parsed_data,
  593. "Transporter: %s\n",
  594. get_navigo_service_provider(event->service_provider));
  595. furi_string_cat_printf(parsed_data, "Station: %s\nSector: %s\n", station, sector);
  596. if(event->device_available) {
  597. if(event->service_provider == NAVIGO_PROVIDER_SNCF) {
  598. furi_string_cat_printf(parsed_data, "Device: %d\n", event->device & 0xFF);
  599. } else {
  600. furi_string_cat_printf(parsed_data, "Device: %d\n", event->device);
  601. }
  602. }
  603. locale_format_datetime_cat(parsed_data, &event->date, true);
  604. furi_string_cat_printf(parsed_data, "\n");
  605. } else {
  606. furi_string_cat_printf(
  607. parsed_data,
  608. "%s - %s\n",
  609. get_intercode_string_transport_type(event->transport_type),
  610. get_intercode_string_transition_type(event->transition));
  611. furi_string_cat_printf(
  612. parsed_data, "Result: %s\n", get_intercode_string_event_result(event->result));
  613. furi_string_cat_printf(
  614. parsed_data,
  615. "Transporter: %s\n",
  616. get_navigo_service_provider(event->service_provider));
  617. furi_string_cat_printf(parsed_data, "Station: %s\nSector: %s\n", station, sector);
  618. if(event->device_available) {
  619. furi_string_cat_printf(parsed_data, "Device: %d\n", event->device);
  620. }
  621. locale_format_datetime_cat(parsed_data, &event->date, true);
  622. furi_string_cat_printf(parsed_data, "\n");
  623. }
  624. free(station);
  625. free(sector);
  626. }
  627. void show_navigo_contract_info(NavigoCardContract* contract, FuriString* parsed_data) {
  628. // Core type and ticket info
  629. furi_string_cat_printf(parsed_data, "Type: %s\n", get_navigo_tariff(contract->tariff));
  630. if(contract->counter_present) {
  631. furi_string_cat_printf(parsed_data, "Remaining Tickets: %d\n", contract->counter.count);
  632. furi_string_cat_printf(parsed_data, "Last load: %d\n", contract->counter.last_load);
  633. }
  634. // Validity period
  635. furi_string_cat_printf(parsed_data, "Valid from: ");
  636. locale_format_datetime_cat(parsed_data, &contract->start_date, false);
  637. furi_string_cat_printf(parsed_data, "\n");
  638. if(contract->end_date_available) {
  639. furi_string_cat_printf(parsed_data, "to: ");
  640. locale_format_datetime_cat(parsed_data, &contract->end_date, false);
  641. furi_string_cat_printf(parsed_data, "\n");
  642. }
  643. // Serial number (if available)
  644. if(contract->serial_number_available) {
  645. furi_string_cat_printf(parsed_data, "TCN Number: %d\n", contract->serial_number);
  646. }
  647. if(contract->price_amount_available) {
  648. furi_string_cat_printf(parsed_data, "Amount: %.2f EUR\n", contract->price_amount);
  649. }
  650. if(contract->pay_method_available) {
  651. furi_string_cat_printf(
  652. parsed_data,
  653. "Payment Method: %s\n",
  654. get_intercode_string_pay_method(contract->pay_method));
  655. }
  656. if(contract->zones_available) {
  657. furi_string_cat_printf(parsed_data, "%s\n", get_zones(contract->zones));
  658. }
  659. furi_string_cat_printf(parsed_data, "Sold on: ");
  660. locale_format_datetime_cat(parsed_data, &contract->sale_date, false);
  661. furi_string_cat_printf(parsed_data, "\n");
  662. furi_string_cat_printf(
  663. parsed_data, "Sales Agent: %s\n", get_navigo_service_provider(contract->sale_agent));
  664. furi_string_cat_printf(parsed_data, "Sales Terminal: %d\n", contract->sale_device);
  665. furi_string_cat_printf(
  666. parsed_data, "Status: %s\n", get_intercode_string_contract_status(contract->status));
  667. furi_string_cat_printf(parsed_data, "Authenticity Code: %d\n", contract->authenticator);
  668. }
  669. void show_navigo_environment_info(
  670. NavigoCardEnv* environment,
  671. NavigoCardHolder* holder,
  672. FuriString* parsed_data) {
  673. furi_string_cat_printf(
  674. parsed_data, "Card status: %s\n", get_intercode_string_holder_type(holder->card_status));
  675. if(is_intercode_string_holder_linked(holder->card_status)) {
  676. furi_string_cat_printf(parsed_data, "Linked to an organization\n");
  677. }
  678. furi_string_cat_printf(
  679. parsed_data,
  680. "App Version: %s - v%d\n",
  681. get_intercode_string_version(environment->app_version),
  682. get_intercode_string_subversion(environment->app_version));
  683. furi_string_cat_printf(
  684. parsed_data, "Country: %s\n", get_country_string(environment->country_num));
  685. furi_string_cat_printf(
  686. parsed_data,
  687. "Network: %s\n",
  688. get_network_string(guess_card_type(environment->country_num, environment->network_num)));
  689. furi_string_cat_printf(parsed_data, "End of validity:\n");
  690. locale_format_datetime_cat(parsed_data, &environment->end_dt, false);
  691. furi_string_cat_printf(parsed_data, "\n");
  692. }