From dda9b40f737f11579336a4f29695944dd4931057 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sat, 6 Jan 2024 22:37:40 +0300 Subject: [PATCH] upd mealpager --- non_catalog_apps/meal_pager/README.md | 4 +- non_catalog_apps/meal_pager/application.fam | 2 +- non_catalog_apps/meal_pager/docs/changelog.md | 6 + .../meal_pager/helpers/meal_pager_storage.c | 6 +- .../meal_pager/helpers/meal_pager_storage.h | 3 +- .../retekess/meal_pager_retekess_t119.c | 2 +- .../retekess/meal_pager_retekess_t119.h | 1 + .../retekess/meal_pager_retekess_td157.c | 2 +- .../retekess/meal_pager_retekess_td157.h | 1 + .../retekess/meal_pager_retekess_td165.c | 117 +++++++++++++++++ .../retekess/meal_pager_retekess_td165.h | 8 ++ .../retekess/meal_pager_retekess_td174.c | 121 ++++++++++++++++++ .../retekess/meal_pager_retekess_td174.h | 7 + .../scenes/meal_pager_scene_settings.c | 3 +- .../scenes/meal_pager_scene_transmit.c | 8 ++ 15 files changed, 279 insertions(+), 12 deletions(-) create mode 100644 non_catalog_apps/meal_pager/helpers/retekess/meal_pager_retekess_td165.c create mode 100644 non_catalog_apps/meal_pager/helpers/retekess/meal_pager_retekess_td165.h create mode 100644 non_catalog_apps/meal_pager/helpers/retekess/meal_pager_retekess_td174.c create mode 100644 non_catalog_apps/meal_pager/helpers/retekess/meal_pager_retekess_td174.h diff --git a/non_catalog_apps/meal_pager/README.md b/non_catalog_apps/meal_pager/README.md index f326b7e4ca3..956557ec0ea 100644 --- a/non_catalog_apps/meal_pager/README.md +++ b/non_catalog_apps/meal_pager/README.md @@ -7,8 +7,8 @@ This app triggers restaurant pagers in a brute force manner, useful to test if d ## Supported Pagers - Retekess T119 - Retekess TD157 -- Retekess TD165 (coming soon) -- Retekess TD174 (coming soon) +- Retekess TD165 +- Retekess TD174 ### Features - Select range of stations (needs improving for full range) diff --git a/non_catalog_apps/meal_pager/application.fam b/non_catalog_apps/meal_pager/application.fam index c3fc1787c4c..7dd49b37320 100644 --- a/non_catalog_apps/meal_pager/application.fam +++ b/non_catalog_apps/meal_pager/application.fam @@ -7,7 +7,7 @@ App( fap_icon="icons/meal_pager_10px.png", fap_icon_assets="icons", fap_category="Sub-GHz", - fap_version="0.8", + fap_version="1.0", fap_author="leedave", fap_weburl="https://github.com/leedave/flipper-zero-meal-pager", fap_description="This app triggers restaurant pagers in a brute force manner, useful to test if devices are still functional.", diff --git a/non_catalog_apps/meal_pager/docs/changelog.md b/non_catalog_apps/meal_pager/docs/changelog.md index 35f4c2d690f..2c9adca3463 100644 --- a/non_catalog_apps/meal_pager/docs/changelog.md +++ b/non_catalog_apps/meal_pager/docs/changelog.md @@ -1,3 +1,9 @@ +## v1.0 +- Added support for TD174 + +## v0.9 +- Added support for TD165 + ## v0.8 - Added Repeats feature - Repeats configuration in settings diff --git a/non_catalog_apps/meal_pager/helpers/meal_pager_storage.c b/non_catalog_apps/meal_pager/helpers/meal_pager_storage.c index eb8135abe38..fbb4b5b56bf 100644 --- a/non_catalog_apps/meal_pager/helpers/meal_pager_storage.c +++ b/non_catalog_apps/meal_pager/helpers/meal_pager_storage.c @@ -15,7 +15,7 @@ static void meal_pager_close_config_file(FlipperFormat* file) { flipper_format_free(file); } -bool meal_pager_save_subghz_buffer_file_start(void* context, FlipperFormat* ff, Storage* storage) { +bool meal_pager_save_subghz_buffer_file_start(void* context, FlipperFormat* ff, Storage* storage, char* frequency) { // SubGhz TXRX can only be loaded with files, makes sense as to save RAM Meal_Pager* app = context; UNUSED(app); @@ -56,12 +56,10 @@ bool meal_pager_save_subghz_buffer_file_start(void* context, FlipperFormat* ff, success = flipper_format_write_header_cstr( ff, MEAL_PAGER_SUBGHZ_FILE_TYPE, MEAL_PAGER_SUBGHZ_FILE_VERSION) && - flipper_format_write_string_cstr(ff, "Frequency", MEAL_PAGER_SUBGHZ_FILE_FREQUENCY) && + flipper_format_write_string_cstr(ff, "Frequency", frequency) && flipper_format_write_string_cstr(ff, "Preset", MEAL_PAGER_SUBGHZ_FILE_PRESET) && flipper_format_write_string_cstr(ff, "Protocol", MEAL_PAGER_SUBGHZ_FILE_Protocol); - //UNUSED(success); return success; - //return ff; } void meal_pager_save_subghz_buffer_stop(void* context, FlipperFormat* ff) { diff --git a/non_catalog_apps/meal_pager/helpers/meal_pager_storage.h b/non_catalog_apps/meal_pager/helpers/meal_pager_storage.h index 16fcde886e3..816b99b0230 100644 --- a/non_catalog_apps/meal_pager/helpers/meal_pager_storage.h +++ b/non_catalog_apps/meal_pager/helpers/meal_pager_storage.h @@ -25,10 +25,11 @@ #define MEAL_PAGER_SUBGHZ_FILE_TYPE "Flipper SubGhz RAW File" #define MEAL_PAGER_SUBGHZ_FILE_VERSION 1 #define MEAL_PAGER_SUBGHZ_FILE_FREQUENCY "433920000" +#define MEAL_PAGER_SUBGHZ_FILE_ALT_FREQUENCY "433889000" #define MEAL_PAGER_SUBGHZ_FILE_PRESET "FuriHalSubGhzPresetOok650Async" #define MEAL_PAGER_SUBGHZ_FILE_Protocol "RAW" -bool meal_pager_save_subghz_buffer_file_start(void* context, FlipperFormat* ff, Storage* storage); +bool meal_pager_save_subghz_buffer_file_start(void* context, FlipperFormat* ff, Storage* storage, char* frequency); void meal_pager_save_subghz_buffer_stop(void* context, FlipperFormat* ff); diff --git a/non_catalog_apps/meal_pager/helpers/retekess/meal_pager_retekess_t119.c b/non_catalog_apps/meal_pager/helpers/retekess/meal_pager_retekess_t119.c index 00a167e7507..79b9c70553d 100644 --- a/non_catalog_apps/meal_pager/helpers/retekess/meal_pager_retekess_t119.c +++ b/non_catalog_apps/meal_pager/helpers/retekess/meal_pager_retekess_t119.c @@ -107,7 +107,7 @@ bool meal_pager_retekess_t119_generate_all(void* context) { Storage* storage = furi_record_open(RECORD_STORAGE); FlipperFormat* ff = flipper_format_file_alloc(storage); - bool success = meal_pager_save_subghz_buffer_file_start(app, ff, storage); + bool success = meal_pager_save_subghz_buffer_file_start(app, ff, storage, MEAL_PAGER_SUBGHZ_FILE_FREQUENCY); if(!success) { FURI_LOG_D(TAG, "failed to save to buffer"); diff --git a/non_catalog_apps/meal_pager/helpers/retekess/meal_pager_retekess_t119.h b/non_catalog_apps/meal_pager/helpers/retekess/meal_pager_retekess_t119.h index 3968581e146..03eaaa4296c 100644 --- a/non_catalog_apps/meal_pager/helpers/retekess/meal_pager_retekess_t119.h +++ b/non_catalog_apps/meal_pager/helpers/retekess/meal_pager_retekess_t119.h @@ -3,5 +3,6 @@ #include "../../meal_pager_i.h" #include "../meal_pager_calc.h" +#include "../meal_pager_storage.h" bool meal_pager_retekess_t119_generate_all(void* context); \ No newline at end of file diff --git a/non_catalog_apps/meal_pager/helpers/retekess/meal_pager_retekess_td157.c b/non_catalog_apps/meal_pager/helpers/retekess/meal_pager_retekess_td157.c index 0c1f44e9a82..d9c08cfc638 100644 --- a/non_catalog_apps/meal_pager/helpers/retekess/meal_pager_retekess_td157.c +++ b/non_catalog_apps/meal_pager/helpers/retekess/meal_pager_retekess_td157.c @@ -93,7 +93,7 @@ bool meal_pager_retekess_td157_generate_all(void* context) { Storage* storage = furi_record_open(RECORD_STORAGE); FlipperFormat* ff = flipper_format_file_alloc(storage); - bool success = meal_pager_save_subghz_buffer_file_start(app, ff, storage); + bool success = meal_pager_save_subghz_buffer_file_start(app, ff, storage, MEAL_PAGER_SUBGHZ_FILE_FREQUENCY); if(!success) { FURI_LOG_D(TAG, "failed to save to buffer"); diff --git a/non_catalog_apps/meal_pager/helpers/retekess/meal_pager_retekess_td157.h b/non_catalog_apps/meal_pager/helpers/retekess/meal_pager_retekess_td157.h index 4513bf9aa6d..c5d2012208d 100644 --- a/non_catalog_apps/meal_pager/helpers/retekess/meal_pager_retekess_td157.h +++ b/non_catalog_apps/meal_pager/helpers/retekess/meal_pager_retekess_td157.h @@ -3,5 +3,6 @@ #include "../../meal_pager_i.h" #include "../meal_pager_calc.h" +#include "../meal_pager_storage.h" bool meal_pager_retekess_td157_generate_all(void* context); \ No newline at end of file diff --git a/non_catalog_apps/meal_pager/helpers/retekess/meal_pager_retekess_td165.c b/non_catalog_apps/meal_pager/helpers/retekess/meal_pager_retekess_td165.c new file mode 100644 index 00000000000..f052f0e026c --- /dev/null +++ b/non_catalog_apps/meal_pager/helpers/retekess/meal_pager_retekess_td165.c @@ -0,0 +1,117 @@ + +#include "meal_pager_retekess_td165.h" + +static char* genRawDataTD165(int zero, int one, const char* bits) { + int bitsLen = strlen(bits); + int lineLen = 256; // Adjust the line length as needed + char* line = (char*)malloc(lineLen * sizeof(char)); + + // Initialize the line with the first part + char* res = (char*)malloc(lineLen * sizeof(char)); + res[0] = '\0'; // Null-terminate the result string + + customConcat(res, "-6000"); + + // Append bits and create the line + for(int i = 0; i < bitsLen; i++) { + char c = bits[i]; + int t = (c == '0') ? zero : one; + + if(i % 2 == 0) { + snprintf(line, lineLen, " %d", t); + } else { + snprintf(line, lineLen, " -%d", t); + } + + // Concatenate the line to the result string + customConcat(res, line); + } + + // Append the closing part to the line + customConcat(res, " 200 -6000"); + + free(line); // Free memory allocated for the line + + return res; +} + +static void meal_pager_retekess_td165_generate_pager( + void* context, + char* stationId, + uint32_t pager, + FlipperFormat* ff) { + Meal_Pager* app = context; + char pagerId[11]; + char* fullId = (char*)malloc(25 * sizeof(char)); + uint32_t action = 0; + char actionId[2]; + app->current_pager = pager; + meal_pager_transmit_model_set_pager(app->meal_pager_transmit, app->current_pager); + FURI_LOG_D(TAG, "Generating TD165 Data for Pager %lu", pager); + uint32ToBinaray(pager, pagerId, 10); + reverse(pagerId); + customConcat(fullId, stationId); + customConcat(fullId, pagerId); + uint32ToBinaray(action, actionId, 1); + reverse(actionId); + customConcat(fullId, actionId); + char* manchester = encManchester(fullId, 0); + char* rawSignal = genRawDataTD165(200, 600, manchester); + for(u_int32_t i = 1; app->repeats >= i; i++) { + flipper_format_write_string_cstr(ff, "RAW_Data", rawSignal); + } + free(manchester); + free(rawSignal); +} + +static void + meal_pager_retekess_td165_generate_station(void* context, uint32_t station, FlipperFormat* ff) { + Meal_Pager* app = context; + FURI_LOG_D( + TAG, + "Generating TD165 Data for Station %lu. Pagers From %lu to %lu", + station, + app->first_pager, + app->last_pager); + app->current_station = station; + app->current_pager = app->first_pager; + char stationId[14]; + uint32ToBinaray(station, stationId, 13); + reverse(stationId); + meal_pager_transmit_model_set_station(app->meal_pager_transmit, app->current_station); + for(u_int32_t i = app->current_pager; i <= app->last_pager; i++) { + meal_pager_retekess_td165_generate_pager(app, stationId, i, ff); + if(app->stop_transmit) { + break; + } + } +} + +bool meal_pager_retekess_td165_generate_all(void* context) { + Meal_Pager* app = context; + + app->current_pager = 1; + app->current_station = app->first_station; + + Storage* storage = furi_record_open(RECORD_STORAGE); + FlipperFormat* ff = flipper_format_file_alloc(storage); + bool success = meal_pager_save_subghz_buffer_file_start(app, ff, storage, MEAL_PAGER_SUBGHZ_FILE_FREQUENCY); + + if(!success) { + FURI_LOG_D(TAG, "failed to save to buffer"); + meal_pager_save_subghz_buffer_stop(app, ff); + furi_record_close(RECORD_STORAGE); + return success; + } + + for(u_int32_t i = app->current_station; i <= app->last_station; i++) { + meal_pager_retekess_td165_generate_station(app, i, ff); + if(app->stop_transmit) { + break; + } + } + + meal_pager_save_subghz_buffer_stop(app, ff); + furi_record_close(RECORD_STORAGE); + return success; +} diff --git a/non_catalog_apps/meal_pager/helpers/retekess/meal_pager_retekess_td165.h b/non_catalog_apps/meal_pager/helpers/retekess/meal_pager_retekess_td165.h new file mode 100644 index 00000000000..64b8adcd862 --- /dev/null +++ b/non_catalog_apps/meal_pager/helpers/retekess/meal_pager_retekess_td165.h @@ -0,0 +1,8 @@ + +#pragma once + +#include "../../meal_pager_i.h" +#include "../meal_pager_calc.h" +#include "../meal_pager_storage.h" + +bool meal_pager_retekess_td165_generate_all(void* context); \ No newline at end of file diff --git a/non_catalog_apps/meal_pager/helpers/retekess/meal_pager_retekess_td174.c b/non_catalog_apps/meal_pager/helpers/retekess/meal_pager_retekess_td174.c new file mode 100644 index 00000000000..afc354b19c5 --- /dev/null +++ b/non_catalog_apps/meal_pager/helpers/retekess/meal_pager_retekess_td174.c @@ -0,0 +1,121 @@ + +#include "meal_pager_retekess_td174.h" + +static char* genRawDataTd174(int zero, int one, const char* bits) { + int bitsLen = strlen(bits); + int lineLen = 256; // Adjust the line length as needed + char* line = (char*)malloc(lineLen * sizeof(char)); + + // Initialize the line with the first part + char* res = (char*)malloc(lineLen * sizeof(char)); + res[0] = '\0'; // Null-terminate the result string + + customConcat(res, "-6000 300 -900"); // Always starts with 01 + + // Append bits and create the line + for(int i = 0; i < bitsLen; i++) { + char c = bits[i]; + int t = (c == '0') ? zero : one; + + if(i % 2 == 0) { + snprintf(line, lineLen, " %d", t); + } else { + snprintf(line, lineLen, " -%d", t); + } + + // Concatenate the line to the result string + customConcat(res, line); + } + + // Append the closing part to the line + customConcat(res, " 300 -6000"); + + free(line); // Free memory allocated for the line + + return res; +} + +static void meal_pager_retekess_td174_generate_pager( + void* context, + char* stationId, + uint32_t pager, + FlipperFormat* ff) { + Meal_Pager* app = context; + char pagerId[11]; + char* fullId = (char*)malloc(25 * sizeof(char)); + uint32_t action = 0; // 0 = ring, 1 = mute + char actionId[2]; + //FURI_LOG_D(TAG, "Generating TD174 Data for Pager %lu", pager); + app->current_pager = pager; + meal_pager_transmit_model_set_pager(app->meal_pager_transmit, app->current_pager); + uint32ToBinaray(pager, pagerId, 8); + uint32ToBinaray(action, actionId, 2); + reverse(pagerId); + reverse(actionId); + //FURI_LOG_D(TAG, "Station Bin: %s", stationId); + //FURI_LOG_D(TAG, "Pager Bin: %s", pagerId); + //FURI_LOG_D(TAG, "Action Bin: %s", actionId); + customConcat(fullId, stationId); + customConcat(fullId, actionId); + customConcat(fullId, pagerId); + char* manchester = encManchester(fullId, 0); + char* rawSignal = genRawDataTd174(300, 900, manchester); + for(u_int32_t i = 1; app->repeats >= i; i++) { + flipper_format_write_string_cstr(ff, "RAW_Data", rawSignal); + } + free(manchester); + free(rawSignal); +} + +static void + meal_pager_retekess_td174_generate_station(void* context, uint32_t station, FlipperFormat* ff) { + Meal_Pager* app = context; + FURI_LOG_D( + TAG, + "Generating TD174 Data for Station %lu. Pagers From %lu to %lu", + station, + app->first_pager, + app->last_pager); + app->current_station = station; + app->current_pager = app->first_pager; + char stationId[14]; + uint32ToBinaray(station, stationId, 13); + reverse(stationId); + meal_pager_transmit_model_set_station(app->meal_pager_transmit, app->current_station); + for(u_int32_t i = app->current_pager; i <= app->last_pager; i++) { + meal_pager_retekess_td174_generate_pager(app, stationId, i, ff); + if(app->stop_transmit) { + break; + } + } +} + +bool meal_pager_retekess_td174_generate_all(void* context) { + Meal_Pager* app = context; + + app->current_pager = 1; + app->current_station = app->first_station; + + Storage* storage = furi_record_open(RECORD_STORAGE); + FlipperFormat* ff = flipper_format_file_alloc(storage); + bool success = meal_pager_save_subghz_buffer_file_start(app, ff, storage, MEAL_PAGER_SUBGHZ_FILE_ALT_FREQUENCY); + + if(!success) { + FURI_LOG_D(TAG, "failed to save to buffer"); + meal_pager_save_subghz_buffer_stop(app, ff); + furi_record_close(RECORD_STORAGE); + return success; + } + + for(u_int32_t i = app->current_station; i <= app->last_station; i++) { + meal_pager_retekess_td174_generate_station(app, i, ff); + //furi_thread_flags_wait(0, FuriFlagWaitAny, 100); + if(app->stop_transmit) { + break; + } + } + + meal_pager_save_subghz_buffer_stop(app, ff); + furi_record_close(RECORD_STORAGE); + return success; +} diff --git a/non_catalog_apps/meal_pager/helpers/retekess/meal_pager_retekess_td174.h b/non_catalog_apps/meal_pager/helpers/retekess/meal_pager_retekess_td174.h new file mode 100644 index 00000000000..5e4be92d85e --- /dev/null +++ b/non_catalog_apps/meal_pager/helpers/retekess/meal_pager_retekess_td174.h @@ -0,0 +1,7 @@ + +#pragma once + +#include "../../meal_pager_i.h" +#include "../meal_pager_calc.h" + +bool meal_pager_retekess_td174_generate_all(void* context); \ No newline at end of file diff --git a/non_catalog_apps/meal_pager/scenes/meal_pager_scene_settings.c b/non_catalog_apps/meal_pager/scenes/meal_pager_scene_settings.c index 4e2c604f7c7..082870160a8 100644 --- a/non_catalog_apps/meal_pager/scenes/meal_pager_scene_settings.c +++ b/non_catalog_apps/meal_pager/scenes/meal_pager_scene_settings.c @@ -153,8 +153,7 @@ void meal_pager_scene_settings_on_enter(void* context) { item = variable_item_list_add( app->variable_item_list, "Pager Type:", - //4, - 2, + 4, meal_pager_scene_settings_set_pager_type, app); value_index = value_index_uint32(app->pager_type, pager_type_value, 4); diff --git a/non_catalog_apps/meal_pager/scenes/meal_pager_scene_transmit.c b/non_catalog_apps/meal_pager/scenes/meal_pager_scene_transmit.c index 339d4b2a44a..142c35ff2d5 100644 --- a/non_catalog_apps/meal_pager/scenes/meal_pager_scene_transmit.c +++ b/non_catalog_apps/meal_pager/scenes/meal_pager_scene_transmit.c @@ -2,6 +2,8 @@ #include "../helpers/meal_pager_custom_event.h" #include "../helpers/retekess/meal_pager_retekess_t119.h" #include "../helpers/retekess/meal_pager_retekess_td157.h" +#include "../helpers/retekess/meal_pager_retekess_td165.h" +#include "../helpers/retekess/meal_pager_retekess_td174.h" #include "../views/meal_pager_transmit.h" #include "../helpers/meal_pager_led.h" #include "../helpers/subghz/subghz.h" @@ -34,6 +36,12 @@ void meal_pager_scene_transmit_on_enter(void* context) { case Meal_PagerPagerTypeTD157: generated = meal_pager_retekess_td157_generate_all(app); break; + case Meal_PagerPagerTypeTD165: + generated = meal_pager_retekess_td165_generate_all(app); + break; + case Meal_PagerPagerTypeTD174: + generated = meal_pager_retekess_td174_generate_all(app); + break; default: generated = false; break;