meal_pager_retekess_t119.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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(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 = 0; // 0 = ring, 1 = mute
  32. char actionId[2];
  33. //FURI_LOG_D(TAG, "Generating T119 Data for Pager %lu", pager);
  34. app->current_pager = pager;
  35. meal_pager_transmit_model_set_pager(app->meal_pager_transmit, app->current_pager);
  36. uint32ToBinaray(pager, pagerId, 10);
  37. uint32ToBinaray(action, actionId, 1);
  38. reverse(pagerId);
  39. reverse(actionId);
  40. //FURI_LOG_D(TAG, "Station Bin: %s", stationId);
  41. //FURI_LOG_D(TAG, "Pager Bin: %s", pagerId);
  42. //FURI_LOG_D(TAG, "Action Bin: %s", actionId);
  43. customConcat(fullId, stationId);
  44. customConcat(fullId, pagerId);
  45. //FURI_LOG_D(TAG, "Result %s", fullId);
  46. //FURI_LOG_D(TAG, "Station & Pager: %s", stationPagerId);
  47. //FURI_LOG_D(TAG, "Station & Pager: %s", stationPagerId);
  48. customConcat(fullId, actionId);
  49. //FURI_LOG_D(TAG, "CustomConcat: %s", fullId);
  50. //FURI_LOG_D(TAG, "Station & Pager & Action: %s", fullId);
  51. char* manchester = encManchester(fullId, 0);
  52. //FURI_LOG_D(TAG, "Manchester: %s", manchester);
  53. char* rawSignal = genRawDataT119(200, 600, manchester);
  54. //FURI_LOG_D(TAG, "RAW_Data: %s", rawSignal);
  55. flipper_format_write_string_cstr(ff, "RAW_Data", rawSignal);
  56. free(manchester);
  57. free(rawSignal);
  58. }
  59. static void meal_pager_retekess_t119_generate_station(void* context, uint32_t station, FlipperFormat* ff) {
  60. Meal_Pager* app = context;
  61. FURI_LOG_D(TAG, "Generating T119 Data for Station %lu. Pagers From %lu to %lu", station, app->first_pager, app->last_pager);
  62. app->current_station = station;
  63. app->current_pager = app->first_pager;
  64. char stationId[14];
  65. uint32ToBinaray(station, stationId, 13);
  66. reverse(stationId);
  67. meal_pager_transmit_model_set_station(app->meal_pager_transmit, app->current_station);
  68. for (u_int32_t i = app->current_pager;i <= app->last_pager; i++) {
  69. meal_pager_retekess_t119_generate_pager(app, stationId, i, ff);
  70. //furi_thread_flags_wait(0, FuriFlagWaitAny, 1);
  71. if (app->stop_transmit) {
  72. break;
  73. }
  74. }
  75. }
  76. bool meal_pager_retekess_t119_generate_all(void* context) {
  77. Meal_Pager* app = context;
  78. app->current_pager = 1;
  79. app->current_station = app->first_station;
  80. Storage* storage = furi_record_open(RECORD_STORAGE);
  81. FlipperFormat* ff = flipper_format_file_alloc(storage);
  82. bool success = meal_pager_save_subghz_buffer_file_start(app, ff, storage);
  83. if (!success) {
  84. FURI_LOG_D(TAG, "failed to save to buffer");
  85. meal_pager_save_subghz_buffer_stop(app, ff);
  86. furi_record_close(RECORD_STORAGE);
  87. return success;
  88. }
  89. for (u_int32_t i = app->current_station;i <= app->last_station; i++) {
  90. meal_pager_retekess_t119_generate_station(app, i, ff);
  91. //furi_thread_flags_wait(0, FuriFlagWaitAny, 100);
  92. if (app->stop_transmit) {
  93. break;
  94. }
  95. }
  96. meal_pager_save_subghz_buffer_stop(app, ff);
  97. furi_record_close(RECORD_STORAGE);
  98. return success;
  99. }