|
| 1 | + |
| 2 | +#include "meal_pager_retekess_td174.h" |
| 3 | + |
| 4 | +static char* genRawDataTd174(int zero, int one, const char* bits) { |
| 5 | + int bitsLen = strlen(bits); |
| 6 | + int lineLen = 256; // Adjust the line length as needed |
| 7 | + char* line = (char*)malloc(lineLen * sizeof(char)); |
| 8 | + |
| 9 | + // Initialize the line with the first part |
| 10 | + char* res = (char*)malloc(lineLen * sizeof(char)); |
| 11 | + res[0] = '\0'; // Null-terminate the result string |
| 12 | + |
| 13 | + customConcat(res, "-6000 300 -900"); // Always starts with 01 |
| 14 | + |
| 15 | + // Append bits and create the line |
| 16 | + for(int i = 0; i < bitsLen; i++) { |
| 17 | + char c = bits[i]; |
| 18 | + int t = (c == '0') ? zero : one; |
| 19 | + |
| 20 | + if(i % 2 == 0) { |
| 21 | + snprintf(line, lineLen, " %d", t); |
| 22 | + } else { |
| 23 | + snprintf(line, lineLen, " -%d", t); |
| 24 | + } |
| 25 | + |
| 26 | + // Concatenate the line to the result string |
| 27 | + customConcat(res, line); |
| 28 | + } |
| 29 | + |
| 30 | + // Append the closing part to the line |
| 31 | + customConcat(res, " 300 -6000"); |
| 32 | + |
| 33 | + free(line); // Free memory allocated for the line |
| 34 | + |
| 35 | + return res; |
| 36 | +} |
| 37 | + |
| 38 | +static void meal_pager_retekess_td174_generate_pager( |
| 39 | + void* context, |
| 40 | + char* stationId, |
| 41 | + uint32_t pager, |
| 42 | + FlipperFormat* ff) { |
| 43 | + Meal_Pager* app = context; |
| 44 | + char pagerId[11]; |
| 45 | + char* fullId = (char*)malloc(25 * sizeof(char)); |
| 46 | + uint32_t action = 0; // 0 = ring, 1 = mute |
| 47 | + char actionId[2]; |
| 48 | + //FURI_LOG_D(TAG, "Generating TD174 Data for Pager %lu", pager); |
| 49 | + app->current_pager = pager; |
| 50 | + meal_pager_transmit_model_set_pager(app->meal_pager_transmit, app->current_pager); |
| 51 | + uint32ToBinaray(pager, pagerId, 8); |
| 52 | + uint32ToBinaray(action, actionId, 2); |
| 53 | + reverse(pagerId); |
| 54 | + reverse(actionId); |
| 55 | + //FURI_LOG_D(TAG, "Station Bin: %s", stationId); |
| 56 | + //FURI_LOG_D(TAG, "Pager Bin: %s", pagerId); |
| 57 | + //FURI_LOG_D(TAG, "Action Bin: %s", actionId); |
| 58 | + customConcat(fullId, stationId); |
| 59 | + customConcat(fullId, actionId); |
| 60 | + customConcat(fullId, pagerId); |
| 61 | + char* manchester = encManchester(fullId, 0); |
| 62 | + char* rawSignal = genRawDataTd174(300, 900, manchester); |
| 63 | + for(u_int32_t i = 1; app->repeats >= i; i++) { |
| 64 | + flipper_format_write_string_cstr(ff, "RAW_Data", rawSignal); |
| 65 | + } |
| 66 | + free(manchester); |
| 67 | + free(rawSignal); |
| 68 | +} |
| 69 | + |
| 70 | +static void |
| 71 | + meal_pager_retekess_td174_generate_station(void* context, uint32_t station, FlipperFormat* ff) { |
| 72 | + Meal_Pager* app = context; |
| 73 | + FURI_LOG_D( |
| 74 | + TAG, |
| 75 | + "Generating TD174 Data for Station %lu. Pagers From %lu to %lu", |
| 76 | + station, |
| 77 | + app->first_pager, |
| 78 | + app->last_pager); |
| 79 | + app->current_station = station; |
| 80 | + app->current_pager = app->first_pager; |
| 81 | + char stationId[14]; |
| 82 | + uint32ToBinaray(station, stationId, 13); |
| 83 | + reverse(stationId); |
| 84 | + meal_pager_transmit_model_set_station(app->meal_pager_transmit, app->current_station); |
| 85 | + for(u_int32_t i = app->current_pager; i <= app->last_pager; i++) { |
| 86 | + meal_pager_retekess_td174_generate_pager(app, stationId, i, ff); |
| 87 | + if(app->stop_transmit) { |
| 88 | + break; |
| 89 | + } |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +bool meal_pager_retekess_td174_generate_all(void* context) { |
| 94 | + Meal_Pager* app = context; |
| 95 | + |
| 96 | + app->current_pager = 1; |
| 97 | + app->current_station = app->first_station; |
| 98 | + |
| 99 | + Storage* storage = furi_record_open(RECORD_STORAGE); |
| 100 | + FlipperFormat* ff = flipper_format_file_alloc(storage); |
| 101 | + bool success = meal_pager_save_subghz_buffer_file_start(app, ff, storage, MEAL_PAGER_SUBGHZ_FILE_ALT_FREQUENCY); |
| 102 | + |
| 103 | + if(!success) { |
| 104 | + FURI_LOG_D(TAG, "failed to save to buffer"); |
| 105 | + meal_pager_save_subghz_buffer_stop(app, ff); |
| 106 | + furi_record_close(RECORD_STORAGE); |
| 107 | + return success; |
| 108 | + } |
| 109 | + |
| 110 | + for(u_int32_t i = app->current_station; i <= app->last_station; i++) { |
| 111 | + meal_pager_retekess_td174_generate_station(app, i, ff); |
| 112 | + //furi_thread_flags_wait(0, FuriFlagWaitAny, 100); |
| 113 | + if(app->stop_transmit) { |
| 114 | + break; |
| 115 | + } |
| 116 | + } |
| 117 | + |
| 118 | + meal_pager_save_subghz_buffer_stop(app, ff); |
| 119 | + furi_record_close(RECORD_STORAGE); |
| 120 | + return success; |
| 121 | +} |
0 commit comments