navigo.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  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. int navigo_station_type = event->transport_type;
  374. if(event->transport_type == COMMUTER_TRAIN && event->route_number_available &&
  375. event->route_number >= 16 && event->service_provider == NAVIGO_PROVIDER_RATP &&
  376. event->station_sub_id == 0) {
  377. navigo_station_type = METRO;
  378. }
  379. char* station = get_navigo_station(
  380. event->station_group_id, event->station_id, event->station_sub_id, navigo_station_type);
  381. char* sector = NULL;
  382. if(navigo_station_type == COMMUTER_TRAIN) {
  383. sector = get_navigo_train_sector(event->station_group_id);
  384. } else {
  385. sector = get_navigo_station(event->station_group_id, 0, 0, navigo_station_type);
  386. }
  387. if(event->transport_type == URBAN_BUS || event->transport_type == INTERURBAN_BUS ||
  388. event->transport_type == METRO || event->transport_type == TRAM) {
  389. if(event->route_number_available) {
  390. if(event->transport_type == METRO && event->route_number == 103) {
  391. furi_string_cat_printf(
  392. parsed_data,
  393. "%s 3 bis\n%s\n",
  394. get_intercode_string_transport_type(event->transport_type),
  395. get_intercode_string_transition_type(event->transition));
  396. } else if(event->transport_type == TRAM) {
  397. furi_string_cat_printf(
  398. parsed_data,
  399. "%s %s\n%s\n",
  400. get_intercode_string_transport_type(event->transport_type),
  401. get_navigo_tram_line(event->route_number),
  402. get_intercode_string_transition_type(event->transition));
  403. } else {
  404. furi_string_cat_printf(
  405. parsed_data,
  406. "%s %d\n%s\n",
  407. get_intercode_string_transport_type(event->transport_type),
  408. event->route_number,
  409. get_intercode_string_transition_type(event->transition));
  410. }
  411. } else {
  412. furi_string_cat_printf(
  413. parsed_data,
  414. "%s\n%s\n",
  415. get_intercode_string_transport_type(event->transport_type),
  416. get_intercode_string_transition_type(event->transition));
  417. }
  418. furi_string_cat_printf(
  419. parsed_data,
  420. "Transporter: %s\n",
  421. get_navigo_service_provider(event->service_provider));
  422. furi_string_cat_printf(parsed_data, "Station: %s\nSector: %s\n", station, sector);
  423. if(event->location_gate_available) {
  424. furi_string_cat_printf(parsed_data, "Gate: %d\n", event->location_gate);
  425. }
  426. if(event->device_available) {
  427. if(event->transport_type == URBAN_BUS || event->transport_type == INTERURBAN_BUS) {
  428. const char* side = event->side == 0 ? "right" : "left";
  429. furi_string_cat_printf(parsed_data, "Door: %d\nSide: %s\n", event->door, side);
  430. } else {
  431. furi_string_cat_printf(parsed_data, "Device: %d\n", event->device);
  432. }
  433. }
  434. if(event->mission_available) {
  435. furi_string_cat_printf(parsed_data, "Mission: %d\n", event->mission);
  436. }
  437. if(event->vehicle_id_available) {
  438. furi_string_cat_printf(parsed_data, "Vehicle: %d\n", event->vehicle_id);
  439. }
  440. if(event->used_contract_available) {
  441. furi_string_cat_printf(
  442. parsed_data,
  443. "Contract: %d - %s\n",
  444. event->used_contract,
  445. get_navigo_tariff(contracts[event->used_contract - 1].tariff));
  446. }
  447. locale_format_datetime_cat(parsed_data, &event->date, true);
  448. furi_string_cat_printf(parsed_data, "\n");
  449. } else if(event->transport_type == COMMUTER_TRAIN) {
  450. if(event->route_number_available) {
  451. furi_string_cat_printf(
  452. parsed_data,
  453. "RER %c\n%s\n",
  454. (65 + event->route_number - 16),
  455. get_intercode_string_transition_type(event->transition));
  456. } else {
  457. furi_string_cat_printf(
  458. parsed_data,
  459. "%s\n%s\n",
  460. get_intercode_string_transport_type(event->transport_type),
  461. get_intercode_string_transition_type(event->transition));
  462. }
  463. furi_string_cat_printf(
  464. parsed_data,
  465. "Transporter: %s\n",
  466. get_navigo_service_provider(event->service_provider));
  467. furi_string_cat_printf(parsed_data, "Station: %s\nSector: %s\n", station, sector);
  468. if(event->location_gate_available) {
  469. furi_string_cat_printf(parsed_data, "Gate: %d\n", event->location_gate);
  470. }
  471. if(event->device_available) {
  472. if(event->service_provider == NAVIGO_PROVIDER_SNCF) {
  473. furi_string_cat_printf(parsed_data, "Device: %d\n", event->device & 0xFF);
  474. } else {
  475. furi_string_cat_printf(parsed_data, "Device: %d\n", event->device);
  476. }
  477. }
  478. if(event->mission_available) {
  479. furi_string_cat_printf(parsed_data, "Mission: %d\n", event->mission);
  480. }
  481. if(event->vehicle_id_available) {
  482. furi_string_cat_printf(parsed_data, "Vehicle: %d\n", event->vehicle_id);
  483. }
  484. if(event->used_contract_available) {
  485. furi_string_cat_printf(
  486. parsed_data,
  487. "Contract: %d - %s\n",
  488. event->used_contract,
  489. get_navigo_tariff(contracts[event->used_contract - 1].tariff));
  490. }
  491. locale_format_datetime_cat(parsed_data, &event->date, true);
  492. furi_string_cat_printf(parsed_data, "\n");
  493. } else {
  494. furi_string_cat_printf(
  495. parsed_data,
  496. "%s - %s\n",
  497. get_intercode_string_transport_type(event->transport_type),
  498. get_intercode_string_transition_type(event->transition));
  499. furi_string_cat_printf(
  500. parsed_data,
  501. "Transporter: %s\n",
  502. get_navigo_service_provider(event->service_provider));
  503. furi_string_cat_printf(parsed_data, "Station: %s\nSector: %s\n", station, sector);
  504. if(event->location_gate_available) {
  505. furi_string_cat_printf(parsed_data, "Gate: %d\n", event->location_gate);
  506. }
  507. if(event->device_available) {
  508. furi_string_cat_printf(parsed_data, "Device: %d\n", event->device);
  509. }
  510. if(event->mission_available) {
  511. furi_string_cat_printf(parsed_data, "Mission: %d\n", event->mission);
  512. }
  513. if(event->vehicle_id_available) {
  514. furi_string_cat_printf(parsed_data, "Vehicle: %d\n", event->vehicle_id);
  515. }
  516. if(event->used_contract_available) {
  517. furi_string_cat_printf(
  518. parsed_data,
  519. "Contract: %d - %s\n",
  520. event->used_contract,
  521. get_navigo_tariff(contracts[event->used_contract - 1].tariff));
  522. }
  523. locale_format_datetime_cat(parsed_data, &event->date, true);
  524. furi_string_cat_printf(parsed_data, "\n");
  525. }
  526. free(station);
  527. free(sector);
  528. }
  529. void show_navigo_special_event_info(NavigoCardSpecialEvent* event, FuriString* parsed_data) {
  530. int navigo_station_type = event->transport_type;
  531. if(event->transport_type == COMMUTER_TRAIN && event->route_number_available &&
  532. event->route_number >= 16 && event->service_provider == NAVIGO_PROVIDER_RATP &&
  533. event->station_sub_id == 0) {
  534. navigo_station_type = METRO;
  535. }
  536. char* station = get_navigo_station(
  537. event->station_group_id, event->station_id, event->station_sub_id, navigo_station_type);
  538. char* sector = NULL;
  539. if(navigo_station_type == COMMUTER_TRAIN) {
  540. sector = get_navigo_train_sector(event->station_group_id);
  541. } else {
  542. sector = get_navigo_station(event->station_group_id, 0, 0, navigo_station_type);
  543. }
  544. if(event->transport_type == URBAN_BUS || event->transport_type == INTERURBAN_BUS ||
  545. event->transport_type == METRO || event->transport_type == TRAM) {
  546. if(event->route_number_available) {
  547. if(event->transport_type == METRO && event->route_number == 103) {
  548. furi_string_cat_printf(
  549. parsed_data,
  550. "%s 3 bis\n%s\n",
  551. get_intercode_string_transport_type(event->transport_type),
  552. get_intercode_string_transition_type(event->transition));
  553. } else if(event->transport_type == TRAM) {
  554. furi_string_cat_printf(
  555. parsed_data,
  556. "%s %s\n%s\n",
  557. get_intercode_string_transport_type(event->transport_type),
  558. get_navigo_tram_line(event->route_number),
  559. get_intercode_string_transition_type(event->transition));
  560. } else {
  561. furi_string_cat_printf(
  562. parsed_data,
  563. "%s %d\n%s\n",
  564. get_intercode_string_transport_type(event->transport_type),
  565. event->route_number,
  566. get_intercode_string_transition_type(event->transition));
  567. }
  568. } else {
  569. furi_string_cat_printf(
  570. parsed_data,
  571. "%s\n%s\n",
  572. get_intercode_string_transport_type(event->transport_type),
  573. get_intercode_string_transition_type(event->transition));
  574. }
  575. furi_string_cat_printf(
  576. parsed_data, "Result: %s\n", get_intercode_string_event_result(event->result));
  577. furi_string_cat_printf(
  578. parsed_data,
  579. "Transporter: %s\n",
  580. get_navigo_service_provider(event->service_provider));
  581. furi_string_cat_printf(parsed_data, "Station: %s\nSector: %s\n", station, sector);
  582. if(event->device_available) {
  583. furi_string_cat_printf(parsed_data, "Device: %d\n", event->device);
  584. }
  585. locale_format_datetime_cat(parsed_data, &event->date, true);
  586. furi_string_cat_printf(parsed_data, "\n");
  587. } else if(event->transport_type == COMMUTER_TRAIN) {
  588. if(event->route_number_available) {
  589. furi_string_cat_printf(
  590. parsed_data,
  591. "RER %c\n%s\n",
  592. (65 + event->route_number - 16),
  593. get_intercode_string_transition_type(event->transition));
  594. } else {
  595. furi_string_cat_printf(
  596. parsed_data,
  597. "%s\n%s\n",
  598. get_intercode_string_transport_type(event->transport_type),
  599. get_intercode_string_transition_type(event->transition));
  600. }
  601. furi_string_cat_printf(
  602. parsed_data, "Result: %s\n", get_intercode_string_event_result(event->result));
  603. furi_string_cat_printf(
  604. parsed_data,
  605. "Transporter: %s\n",
  606. get_navigo_service_provider(event->service_provider));
  607. furi_string_cat_printf(parsed_data, "Station: %s\nSector: %s\n", station, sector);
  608. if(event->device_available) {
  609. if(event->service_provider == NAVIGO_PROVIDER_SNCF) {
  610. furi_string_cat_printf(parsed_data, "Device: %d\n", event->device & 0xFF);
  611. } else {
  612. furi_string_cat_printf(parsed_data, "Device: %d\n", event->device);
  613. }
  614. }
  615. locale_format_datetime_cat(parsed_data, &event->date, true);
  616. furi_string_cat_printf(parsed_data, "\n");
  617. } else {
  618. furi_string_cat_printf(
  619. parsed_data,
  620. "%s - %s\n",
  621. get_intercode_string_transport_type(event->transport_type),
  622. get_intercode_string_transition_type(event->transition));
  623. furi_string_cat_printf(
  624. parsed_data, "Result: %s\n", get_intercode_string_event_result(event->result));
  625. furi_string_cat_printf(
  626. parsed_data,
  627. "Transporter: %s\n",
  628. get_navigo_service_provider(event->service_provider));
  629. furi_string_cat_printf(parsed_data, "Station: %s\nSector: %s\n", station, sector);
  630. if(event->device_available) {
  631. furi_string_cat_printf(parsed_data, "Device: %d\n", event->device);
  632. }
  633. locale_format_datetime_cat(parsed_data, &event->date, true);
  634. furi_string_cat_printf(parsed_data, "\n");
  635. }
  636. free(station);
  637. free(sector);
  638. }
  639. void show_navigo_contract_info(NavigoCardContract* contract, FuriString* parsed_data) {
  640. // Core type and ticket info
  641. furi_string_cat_printf(parsed_data, "Type: %s\n", get_navigo_tariff(contract->tariff));
  642. if(contract->counter_present) {
  643. furi_string_cat_printf(parsed_data, "Remaining Tickets: %d\n", contract->counter.count);
  644. furi_string_cat_printf(parsed_data, "Last load: %d\n", contract->counter.last_load);
  645. }
  646. // Validity period
  647. furi_string_cat_printf(parsed_data, "Valid from: ");
  648. locale_format_datetime_cat(parsed_data, &contract->start_date, false);
  649. furi_string_cat_printf(parsed_data, "\n");
  650. if(contract->end_date_available) {
  651. furi_string_cat_printf(parsed_data, "to: ");
  652. locale_format_datetime_cat(parsed_data, &contract->end_date, false);
  653. furi_string_cat_printf(parsed_data, "\n");
  654. }
  655. // Serial number (if available)
  656. if(contract->serial_number_available) {
  657. furi_string_cat_printf(parsed_data, "TCN Number: %d\n", contract->serial_number);
  658. }
  659. if(contract->price_amount_available) {
  660. furi_string_cat_printf(parsed_data, "Amount: %.2f EUR\n", contract->price_amount);
  661. }
  662. if(contract->pay_method_available) {
  663. furi_string_cat_printf(
  664. parsed_data,
  665. "Payment Method: %s\n",
  666. get_intercode_string_pay_method(contract->pay_method));
  667. }
  668. if(contract->zones_available) {
  669. furi_string_cat_printf(parsed_data, "%s\n", get_zones(contract->zones));
  670. }
  671. furi_string_cat_printf(parsed_data, "Sold on: ");
  672. locale_format_datetime_cat(parsed_data, &contract->sale_date, false);
  673. furi_string_cat_printf(parsed_data, "\n");
  674. furi_string_cat_printf(
  675. parsed_data, "Sales Agent: %s\n", get_navigo_service_provider(contract->sale_agent));
  676. furi_string_cat_printf(parsed_data, "Sales Terminal: %d\n", contract->sale_device);
  677. furi_string_cat_printf(
  678. parsed_data, "Status: %s\n", get_intercode_string_contract_status(contract->status));
  679. furi_string_cat_printf(parsed_data, "Authenticity Code: %d\n", contract->authenticator);
  680. }
  681. void show_navigo_environment_info(
  682. NavigoCardEnv* environment,
  683. NavigoCardHolder* holder,
  684. FuriString* parsed_data) {
  685. furi_string_cat_printf(
  686. parsed_data, "Card status: %s\n", get_intercode_string_holder_type(holder->card_status));
  687. if(is_intercode_string_holder_linked(holder->card_status)) {
  688. furi_string_cat_printf(parsed_data, "Linked to an organization\n");
  689. }
  690. furi_string_cat_printf(
  691. parsed_data,
  692. "App Version: %s - v%d\n",
  693. get_intercode_string_version(environment->app_version),
  694. get_intercode_string_subversion(environment->app_version));
  695. furi_string_cat_printf(
  696. parsed_data, "Country: %s\n", get_country_string(environment->country_num));
  697. furi_string_cat_printf(
  698. parsed_data,
  699. "Network: %s\n",
  700. get_network_string(guess_card_type(environment->country_num, environment->network_num)));
  701. furi_string_cat_printf(parsed_data, "End of validity:\n");
  702. locale_format_datetime_cat(parsed_data, &environment->end_dt, false);
  703. furi_string_cat_printf(parsed_data, "\n");
  704. }