meal_pager_retekess_td165.c 3.6 KB

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