meal_pager_retekess_td157.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #include "meal_pager_retekess_td157.h"
  2. static char* genRawDataTD157(int zero, int one, const char* bits) {
  3. int bitsLen = strlen(bits);
  4. int lineLen = 256; // Adjust the line length as needed
  5. char* line = (char*)malloc(lineLen * sizeof(char));
  6. // Initialize the line with the first part
  7. char* res = (char*)malloc(lineLen * sizeof(char));
  8. res[0] = '\0'; // Null-terminate the result string
  9. customConcat(res, "-6000");
  10. // Append bits and create the line
  11. for (int i = 0; i < bitsLen; i++) {
  12. char c = bits[i];
  13. int t = (c == '0') ? zero : one;
  14. if (i % 2 == 0) {
  15. snprintf(line, lineLen, " %d", t);
  16. } else {
  17. snprintf(line, lineLen, " -%d", t);
  18. }
  19. // Concatenate the line to the result string
  20. customConcat(res, line);
  21. }
  22. // Append the closing part to the line
  23. customConcat(res, " 200 -6000");
  24. free(line); // Free memory allocated for the line
  25. return res;
  26. }
  27. static void meal_pager_retekess_td157_generate_pager(void* context, char* stationId, uint32_t pager, FlipperFormat* ff) {
  28. Meal_Pager* app = context;
  29. char pagerId[11];
  30. char* fullId = (char*)malloc(25 * sizeof(char));
  31. uint32_t action = 2;
  32. char actionId[4];
  33. app->current_pager = pager;
  34. meal_pager_transmit_model_set_pager(app->meal_pager_transmit, app->current_pager);
  35. FURI_LOG_D(TAG, "Generating TD157 Data for Pager %lu", pager);
  36. uint32ToBinaray(pager, pagerId, 10);
  37. customConcat(fullId, stationId);
  38. customConcat(fullId, pagerId);
  39. uint32ToBinaray(action, actionId, 4);
  40. customConcat(fullId, actionId);
  41. char* manchester = encManchester(fullId, 0);
  42. char* rawSignal = genRawDataTD157(200, 600, manchester);
  43. flipper_format_write_string_cstr(ff, "RAW_Data", rawSignal);
  44. free(manchester);
  45. free(rawSignal);
  46. }
  47. static void meal_pager_retekess_td157_generate_station(void* context, uint32_t station, FlipperFormat* ff) {
  48. Meal_Pager* app = context;
  49. FURI_LOG_D(TAG, "Generating TD157 Data for Station %lu. Pagers From %lu to %lu", station, app->first_pager, app->last_pager);
  50. app->current_station = station;
  51. app->current_pager = app->first_pager;
  52. char stationId[14];
  53. uint32ToBinaray(station, stationId, 10);
  54. //reverse(stationId);
  55. meal_pager_transmit_model_set_station(app->meal_pager_transmit, app->current_station);
  56. for (u_int32_t i = app->current_pager;i <= app->last_pager; i++) {
  57. meal_pager_retekess_td157_generate_pager(app, stationId, i, ff);
  58. if (app->stop_transmit) {
  59. break;
  60. }
  61. }
  62. }
  63. bool meal_pager_retekess_td157_generate_all(void* context) {
  64. Meal_Pager* app = context;
  65. app->current_pager = 1;
  66. app->current_station = app->first_station;
  67. Storage* storage = furi_record_open(RECORD_STORAGE);
  68. FlipperFormat* ff = flipper_format_file_alloc(storage);
  69. bool success = meal_pager_save_subghz_buffer_file_start(app, ff, storage);
  70. if (!success) {
  71. FURI_LOG_D(TAG, "failed to save to buffer");
  72. meal_pager_save_subghz_buffer_stop(app, ff);
  73. furi_record_close(RECORD_STORAGE);
  74. return success;
  75. }
  76. for (u_int32_t i = app->current_station;i <= app->last_station; i++) {
  77. meal_pager_retekess_td157_generate_station(app, i, ff);
  78. if (app->stop_transmit) {
  79. break;
  80. }
  81. }
  82. meal_pager_save_subghz_buffer_stop(app, ff);
  83. furi_record_close(RECORD_STORAGE);
  84. return success;
  85. }