meal_pager_retekess_t119.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #include "meal_pager_retekess_t119.h"
  2. static char* genRawDataT119(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_t119_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 T119 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, 10);
  41. uint32ToBinaray(action, actionId, 1);
  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, pagerId);
  49. //FURI_LOG_D(TAG, "Result %s", fullId);
  50. //FURI_LOG_D(TAG, "Station & Pager: %s", stationPagerId);
  51. //FURI_LOG_D(TAG, "Station & Pager: %s", stationPagerId);
  52. customConcat(fullId, actionId);
  53. //FURI_LOG_D(TAG, "CustomConcat: %s", fullId);
  54. //FURI_LOG_D(TAG, "Station & Pager & Action: %s", fullId);
  55. char* manchester = encManchester(fullId, 0);
  56. //FURI_LOG_D(TAG, "Manchester: %s", manchester);
  57. char* rawSignal = genRawDataT119(200, 600, manchester);
  58. //FURI_LOG_D(TAG, "RAW_Data: %s", rawSignal);
  59. for(uint32_t i = 1; app->repeats >= i; i++) {
  60. flipper_format_write_string_cstr(ff, "RAW_Data", rawSignal);
  61. }
  62. //flipper_format_write_string_cstr(ff, "RAW_Data", rawSignal);
  63. free(manchester);
  64. free(rawSignal);
  65. }
  66. static void
  67. meal_pager_retekess_t119_generate_station(void* context, uint32_t station, FlipperFormat* ff) {
  68. Meal_Pager* app = context;
  69. FURI_LOG_D(
  70. TAG,
  71. "Generating T119 Data for Station %lu. Pagers From %lu to %lu",
  72. station,
  73. app->first_pager,
  74. app->last_pager);
  75. app->current_station = station;
  76. app->current_pager = app->first_pager;
  77. char stationId[14];
  78. uint32ToBinaray(station, stationId, 13);
  79. reverse(stationId);
  80. meal_pager_transmit_model_set_station(app->meal_pager_transmit, app->current_station);
  81. for(uint32_t i = app->current_pager; i <= app->last_pager; i++) {
  82. meal_pager_retekess_t119_generate_pager(app, stationId, i, ff);
  83. //furi_thread_flags_wait(0, FuriFlagWaitAny, 1);
  84. if(app->stop_transmit) {
  85. break;
  86. }
  87. }
  88. }
  89. bool meal_pager_retekess_t119_generate_all(void* context) {
  90. Meal_Pager* app = context;
  91. app->current_pager = 1;
  92. app->current_station = app->first_station;
  93. Storage* storage = furi_record_open(RECORD_STORAGE);
  94. FlipperFormat* ff = flipper_format_file_alloc(storage);
  95. bool success = meal_pager_save_subghz_buffer_file_start(
  96. app, ff, storage, MEAL_PAGER_SUBGHZ_FILE_FREQUENCY);
  97. if(!success) {
  98. FURI_LOG_D(TAG, "failed to save to buffer");
  99. meal_pager_save_subghz_buffer_stop(app, ff);
  100. furi_record_close(RECORD_STORAGE);
  101. return success;
  102. }
  103. for(uint32_t i = app->current_station; i <= app->last_station; i++) {
  104. meal_pager_retekess_t119_generate_station(app, i, ff);
  105. //furi_thread_flags_wait(0, FuriFlagWaitAny, 100);
  106. if(app->stop_transmit) {
  107. break;
  108. }
  109. }
  110. meal_pager_save_subghz_buffer_stop(app, ff);
  111. furi_record_close(RECORD_STORAGE);
  112. return success;
  113. }