From 8dfd5a598ae3ecf43f4e6dd4d57cf9f2498f1277 Mon Sep 17 00:00:00 2001 From: Derek Jamison Date: Mon, 7 Aug 2023 10:22:27 -0500 Subject: [PATCH] Send princeton signals --- subghz/apps/princeton-send/README.md | 8 ++ subghz/apps/princeton-send/application.fam | 10 ++ subghz/apps/princeton-send/princeton_send.c | 104 ++++++++++++++++++ subghz/apps/princeton-send/princeton_send.png | Bin 0 -> 1829 bytes 4 files changed, 122 insertions(+) create mode 100644 subghz/apps/princeton-send/README.md create mode 100644 subghz/apps/princeton-send/application.fam create mode 100644 subghz/apps/princeton-send/princeton_send.c create mode 100644 subghz/apps/princeton-send/princeton_send.png diff --git a/subghz/apps/princeton-send/README.md b/subghz/apps/princeton-send/README.md new file mode 100644 index 0000000..9b49452 --- /dev/null +++ b/subghz/apps/princeton-send/README.md @@ -0,0 +1,8 @@ +# Princeton Sender + +This is a demo application that sends a Princeton 24-bit code using the internal radio, then +it sends a 24-bit code using an external radio. It also enables the 5v pin for the external +radio, in case the radio has a 5-volt to 3.3-volt regulator attached. + +There is no UI for this project, it just sends the two signals and then exits. Hopefully you +can borrow this code for other projects, such as sending a beacon on a time interval. diff --git a/subghz/apps/princeton-send/application.fam b/subghz/apps/princeton-send/application.fam new file mode 100644 index 0000000..ae6b147 --- /dev/null +++ b/subghz/apps/princeton-send/application.fam @@ -0,0 +1,10 @@ +App( + appid="princeton_send", + name="Princeton Sender", + apptype=FlipperAppType.EXTERNAL, + entry_point="princeton_send_app", + requires=["gui", "subghz"], + stack_size=2 * 1024, + fap_icon="princeton_send.png", + fap_category="Sub-GHz", +) diff --git a/subghz/apps/princeton-send/princeton_send.c b/subghz/apps/princeton-send/princeton_send.c new file mode 100644 index 0000000..e30bec5 --- /dev/null +++ b/subghz/apps/princeton-send/princeton_send.c @@ -0,0 +1,104 @@ +#include +#include +#include +#include +#include +#include +#include + +static void subghz_radio_device_power_on() { + uint8_t attempts = 5; + while(--attempts > 0) { + if(furi_hal_power_enable_otg()) break; + furi_delay_ms(50); + } +} + +static void subghz_radio_device_power_off() { + if(furi_hal_power_is_otg_enabled()) furi_hal_power_disable_otg(); +} + +static void + set_princeton(FlipperFormat* flipper_format, uint32_t key, uint32_t te, uint32_t repeat) { + FuriString* princeton_settings = furi_string_alloc_printf( + "Protocol: Princeton\n" + "Bit: 24\n" + "Key: 00 00 00 00 00 %02X %02X %02X\n" + "TE: %lu\n" + "Repeat: %lu\n", + (uint8_t)((key >> 16) & 0xFFU), + (uint8_t)((key >> 8) & 0xFFU), + (uint8_t)(key & 0xFFU), + te, + repeat); + Stream* stream = flipper_format_get_raw_stream(flipper_format); + stream_clean(stream); + stream_write_cstring(stream, furi_string_get_cstr(princeton_settings)); + stream_seek(stream, 0, StreamOffsetFromStart); + furi_string_free(princeton_settings); +} + +static void send_princeton(uint32_t key, bool use_external_radio) { + uint32_t frequency = 433920000; + uint32_t te = 350; + uint32_t repeat = 5; + bool enable_5v = use_external_radio; + const SubGhzDevice* device; + + subghz_devices_init(); + if(use_external_radio) { + if(enable_5v) { + subghz_radio_device_power_on(); + } + device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_EXT_NAME); + } else { + device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_INT_NAME); + } + + SubGhzEnvironment* environment = subghz_environment_alloc(); + subghz_environment_set_protocol_registry(environment, (void*)&subghz_protocol_registry); + SubGhzTransmitter* transmitter = subghz_transmitter_alloc_init(environment, "Princeton"); + FlipperFormat* flipper_format = flipper_format_string_alloc(); + set_princeton(flipper_format, key, te, repeat); + subghz_transmitter_deserialize(transmitter, flipper_format); + subghz_devices_begin(device); + subghz_devices_reset(device); + subghz_devices_load_preset(device, FuriHalSubGhzPresetOok650Async, NULL); + frequency = subghz_devices_set_frequency(device, frequency); + + // Send + furi_hal_power_suppress_charge_enter(); + if(subghz_devices_start_async_tx(device, subghz_transmitter_yield, transmitter)) { + while(!(subghz_devices_is_async_complete_tx(device))) { + furi_delay_ms(100); + } + + subghz_devices_stop_async_tx(device); + } + + // Cleanup + subghz_devices_sleep(device); + subghz_devices_end(device); + subghz_devices_deinit(); + if(enable_5v) { + subghz_radio_device_power_off(); + } + furi_hal_power_suppress_charge_exit(); + flipper_format_free(flipper_format); + subghz_transmitter_free(transmitter); + subghz_environment_free(environment); +} + +int princeton_send_app(char* p) { + UNUSED(p); + + FURI_LOG_I("princeton_send", "Sending key with internal radio..."); + send_princeton(0x938475, false); + FURI_LOG_I("princeton_send", "Sent key."); + + FURI_LOG_I("princeton_send", "Sending key with external radio..."); + send_princeton(0x194857, true); + FURI_LOG_I("princeton_send", "Sent key?"); + + return 0; +} \ No newline at end of file diff --git a/subghz/apps/princeton-send/princeton_send.png b/subghz/apps/princeton-send/princeton_send.png new file mode 100644 index 0000000000000000000000000000000000000000..b85dc878ba456059cba6cfe3e9de9a40330b8667 GIT binary patch literal 1829 zcma)64NMbf7(Qe&fiU;Olo_&I4vjEu?|S^nrL{m?p^n4KKl{U@_m!Tsz1!WDmY)zK zb&8t;*~|dRCNk8aVVToqOhxAAjHs~8Wy##4#w~MMjFZ6pSzOq6ZTYEVKTWRpeee6c z&-c9V_ukuLDaeh9S{8*MNQ^npSP0+BI%-ik{QvZ(z7;{j8aRW&Vm261i^$tJ2SAX- zvEA)s$;J(_XZ2S57u(6`=-1zVkk^wJvOPPs`;IX6YsYl5%{~^V}D+0D7f1lUDAHIE2aNr+xexFw?C=u+&P*w zko!aGk3D+^IyTvRdn|4Gv){)&cE0lW7Y6TLJ-B{(%+vA5PABy5U+P=wYffHx@jA`4 zcD1bVwQg;Y>-OG0)_2y~bY!)2V%wSe93!>I$pHOeE7N2-tD6pN5=m0guCL% z$}qjmW9{pqL_y=n@3B#ke?iemMb3^jxn(#Hx@4r99cfI@QwG-PuYFyF8Eq?74 z6JB!k&dc_fn%|t*vE=HOOK$t%rK-w(UU$kuBSB;VGiQ2J|8}V0i*pi`N z7kup5TXZW!-5A!Ps($c!%7}6=5tjU7)6~=yT$Y@^)C6CVLSB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