meal_pager_retekess_td174.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #include "meal_pager_retekess_td174.h"
  2. static char* genRawDataTd174(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 300 -900"); // Always starts with 01
  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, " 300 -6000");
  24. free(line); // Free memory allocated for the line
  25. return res;
  26. }
  27. static void meal_pager_retekess_td174_generate_pager(
  28. void* context,
  29. char* stationId,
  30. uint32_t pager,
  31. FlipperFormat* ff) {
  32. Meal_Pager* app = context;
  33. char pagerId[11];
  34. char* fullId = (char*)malloc(25 * sizeof(char));
  35. uint32_t action = 0; // 0 = ring, 1 = mute
  36. char actionId[2];
  37. //FURI_LOG_D(TAG, "Generating TD174 Data for Pager %lu", pager);
  38. app->current_pager = pager;
  39. meal_pager_transmit_model_set_pager(app->meal_pager_transmit, app->current_pager);
  40. uint32ToBinaray(pager, pagerId, 8);
  41. uint32ToBinaray(action, actionId, 2);
  42. reverse(pagerId);
  43. reverse(actionId);
  44. //FURI_LOG_D(TAG, "Station Bin: %s", stationId);
  45. //FURI_LOG_D(TAG, "Pager Bin: %s", pagerId);
  46. //FURI_LOG_D(TAG, "Action Bin: %s", actionId);
  47. customConcat(fullId, stationId);
  48. customConcat(fullId, actionId);
  49. customConcat(fullId, pagerId);
  50. char* manchester = encManchester(fullId, 0);
  51. char* rawSignal = genRawDataTd174(300, 900, manchester);
  52. for(uint32_t i = 1; app->repeats >= i; i++) {
  53. flipper_format_write_string_cstr(ff, "RAW_Data", rawSignal);
  54. }
  55. free(manchester);
  56. free(rawSignal);
  57. }
  58. static void
  59. meal_pager_retekess_td174_generate_station(void* context, uint32_t station, FlipperFormat* ff) {
  60. Meal_Pager* app = context;
  61. FURI_LOG_D(
  62. TAG,
  63. "Generating TD174 Data for Station %lu. Pagers From %lu to %lu",
  64. station,
  65. app->first_pager,
  66. app->last_pager);
  67. app->current_station = station;
  68. app->current_pager = app->first_pager;
  69. char stationId[14];
  70. uint32ToBinaray(station, stationId, 13);
  71. reverse(stationId);
  72. meal_pager_transmit_model_set_station(app->meal_pager_transmit, app->current_station);
  73. for(uint32_t i = app->current_pager; i <= app->last_pager; i++) {
  74. meal_pager_retekess_td174_generate_pager(app, stationId, i, ff);
  75. if(app->stop_transmit) {
  76. break;
  77. }
  78. }
  79. }
  80. bool meal_pager_retekess_td174_generate_all(void* context) {
  81. Meal_Pager* app = context;
  82. app->current_pager = 1;
  83. app->current_station = app->first_station;
  84. Storage* storage = furi_record_open(RECORD_STORAGE);
  85. FlipperFormat* ff = flipper_format_file_alloc(storage);
  86. bool success = meal_pager_save_subghz_buffer_file_start(
  87. app, ff, storage, MEAL_PAGER_SUBGHZ_FILE_ALT_FREQUENCY);
  88. if(!success) {
  89. FURI_LOG_D(TAG, "failed to save to buffer");
  90. meal_pager_save_subghz_buffer_stop(app, ff);
  91. furi_record_close(RECORD_STORAGE);
  92. return success;
  93. }
  94. for(uint32_t i = app->current_station; i <= app->last_station; i++) {
  95. meal_pager_retekess_td174_generate_station(app, i, ff);
  96. //furi_thread_flags_wait(0, FuriFlagWaitAny, 100);
  97. if(app->stop_transmit) {
  98. break;
  99. }
  100. }
  101. meal_pager_save_subghz_buffer_stop(app, ff);
  102. furi_record_close(RECORD_STORAGE);
  103. return success;
  104. }