navigo.c 28 KB

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