navigo.c 28 KB

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