mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-26 22:40:25 +00:00
[FL-2129] SubGhz: Fix Duty cycle at 433/868 (#892)
* [FL-2129] SubGhz: Fix Duty cycle at 433/868 * SubGhz: fix syntax * SubGhz: increased silence time in the 868 range * SubGhz: added build flag LAB_TESTS * SubGhz: better LAB_TESTS flag handling * NFC: LAB_TESTS flag handling Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
This commit is contained in:
parent
58ce937321
commit
1232defcf1
7 changed files with 96 additions and 25 deletions
|
@ -316,3 +316,9 @@ SRV_STORAGE ?= 0
|
|||
ifeq ($(SRV_STORAGE), 1)
|
||||
CFLAGS += -DSRV_STORAGE
|
||||
endif
|
||||
|
||||
|
||||
LAB_TESTS ?= 0
|
||||
ifeq ($(LAB_TESTS), 1)
|
||||
CFLAGS += -DLAB_TESTS
|
||||
endif
|
|
@ -5,7 +5,9 @@ enum SubmenuIndex {
|
|||
SubmenuIndexRunScript,
|
||||
SubmenuIndexSaved,
|
||||
SubmenuIndexAddManualy,
|
||||
#ifdef LAB_TESTS
|
||||
SubmenuIndexDebug,
|
||||
#endif
|
||||
};
|
||||
|
||||
void nfc_scene_start_submenu_callback(void* context, uint32_t index) {
|
||||
|
@ -30,7 +32,9 @@ void nfc_scene_start_on_enter(void* context) {
|
|||
submenu, "Saved cards", SubmenuIndexSaved, nfc_scene_start_submenu_callback, nfc);
|
||||
submenu_add_item(
|
||||
submenu, "Add manually", SubmenuIndexAddManualy, nfc_scene_start_submenu_callback, nfc);
|
||||
#ifdef LAB_TESTS
|
||||
submenu_add_item(submenu, "Debug", SubmenuIndexDebug, nfc_scene_start_submenu_callback, nfc);
|
||||
#endif
|
||||
submenu_set_selected_item(
|
||||
submenu, scene_manager_get_scene_state(nfc->scene_manager, NfcSceneStart));
|
||||
|
||||
|
@ -61,10 +65,12 @@ bool nfc_scene_start_on_event(void* context, SceneManagerEvent event) {
|
|||
nfc->scene_manager, NfcSceneStart, SubmenuIndexAddManualy);
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneSetType);
|
||||
consumed = true;
|
||||
#ifdef LAB_TESTS
|
||||
} else if(event.event == SubmenuIndexDebug) {
|
||||
scene_manager_set_scene_state(nfc->scene_manager, NfcSceneStart, SubmenuIndexDebug);
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateApduSequence);
|
||||
consumed = true;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
enum SubmenuIndex {
|
||||
SubmenuIndexRead = 10,
|
||||
SubmenuIndexSaved,
|
||||
#ifdef LAB_TESTS
|
||||
SubmenuIndexTest,
|
||||
#endif
|
||||
SubmenuIndexAddManualy,
|
||||
SubmenuIndexFrequencyAnalyzer,
|
||||
SubmenuIndexReadRAW,
|
||||
|
@ -41,9 +43,10 @@ void subghz_scene_start_on_enter(void* context) {
|
|||
SubmenuIndexFrequencyAnalyzer,
|
||||
subghz_scene_start_submenu_callback,
|
||||
subghz);
|
||||
#ifdef LAB_TESTS
|
||||
submenu_add_item(
|
||||
subghz->submenu, "Test", SubmenuIndexTest, subghz_scene_start_submenu_callback, subghz);
|
||||
|
||||
#endif
|
||||
submenu_set_selected_item(
|
||||
subghz->submenu, scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneStart));
|
||||
|
||||
|
@ -80,11 +83,13 @@ bool subghz_scene_start_on_event(void* context, SceneManagerEvent event) {
|
|||
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexFrequencyAnalyzer);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneFrequencyAnalyzer);
|
||||
return true;
|
||||
#ifdef LAB_TESTS
|
||||
} else if(event.event == SubmenuIndexTest) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexTest);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneTest);
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include <toolbox/level_duration.h>
|
||||
#include <lib/subghz/protocols/subghz_protocol_princeton.h>
|
||||
|
||||
#define SUBGHZ_TEST_PACKET_COUNT 1000
|
||||
#define SUBGHZ_TEST_PACKET_COUNT 500
|
||||
|
||||
struct SubghzTestPacket {
|
||||
View* view;
|
||||
|
@ -137,6 +137,7 @@ static bool subghz_test_packet_input(InputEvent* event, void* context) {
|
|||
if(model->status == SubghzTestPacketModelStatusRx) {
|
||||
furi_hal_subghz_stop_async_rx();
|
||||
} else if(model->status == SubghzTestPacketModelStatusTx) {
|
||||
subghz_encoder_princeton_stop(instance->encoder, millis());
|
||||
furi_hal_subghz_stop_async_tx();
|
||||
}
|
||||
|
||||
|
@ -164,7 +165,10 @@ static bool subghz_test_packet_input(InputEvent* event, void* context) {
|
|||
furi_hal_subghz_start_async_rx(subghz_test_packet_rx_callback, instance);
|
||||
} else {
|
||||
subghz_encoder_princeton_set(
|
||||
instance->encoder, 0x00AABBCC, SUBGHZ_TEST_PACKET_COUNT);
|
||||
instance->encoder,
|
||||
0x00AABBCC,
|
||||
SUBGHZ_TEST_PACKET_COUNT,
|
||||
subghz_frequencies[model->frequency]);
|
||||
if(!furi_hal_subghz_start_async_tx(
|
||||
subghz_encoder_princeton_yield, instance->encoder)) {
|
||||
model->status = SubghzTestPacketModelStatusOnlyRx;
|
||||
|
@ -213,6 +217,7 @@ void subghz_test_packet_exit(void* context) {
|
|||
if(model->status == SubghzTestPacketModelStatusRx) {
|
||||
furi_hal_subghz_stop_async_rx();
|
||||
} else if(model->status == SubghzTestPacketModelStatusTx) {
|
||||
subghz_encoder_princeton_stop(instance->encoder, millis());
|
||||
furi_hal_subghz_stop_async_tx();
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -104,7 +104,10 @@ bool subghz_test_static_input(InputEvent* event, void* context) {
|
|||
FURI_LOG_I(TAG, "TX Start");
|
||||
|
||||
subghz_encoder_princeton_set(
|
||||
instance->encoder, subghz_test_static_keys[model->button], 10000);
|
||||
instance->encoder,
|
||||
subghz_test_static_keys[model->button],
|
||||
10000,
|
||||
subghz_frequencies[model->frequency]);
|
||||
|
||||
furi_hal_subghz_start_async_tx(
|
||||
subghz_encoder_princeton_yield, instance->encoder);
|
||||
|
@ -113,6 +116,7 @@ bool subghz_test_static_input(InputEvent* event, void* context) {
|
|||
} else if(event->type == InputTypeRelease) {
|
||||
if(instance->satus_tx == SubghzTestStaticStatusTX) {
|
||||
FURI_LOG_I(TAG, "TX Stop");
|
||||
subghz_encoder_princeton_stop(instance->encoder, millis());
|
||||
subghz_encoder_princeton_print_log(instance->encoder);
|
||||
furi_hal_subghz_stop_async_tx();
|
||||
notification_message(notification, &sequence_reset_red);
|
||||
|
|
|
@ -5,11 +5,13 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#define SUBGHZ_PT_SHORT 400
|
||||
#define SUBGHZ_PT_SHORT 300
|
||||
#define SUBGHZ_PT_LONG (SUBGHZ_PT_SHORT * 3)
|
||||
#define SUBGHZ_PT_GUARD (SUBGHZ_PT_SHORT * 30)
|
||||
#define SUBGHZ_PT_COUNT_KEY 5
|
||||
#define SUBGHZ_PT_TIMEOUT 320
|
||||
#define SUBGHZ_PT_COUNT_KEY_433 9
|
||||
#define SUBGHZ_PT_TIMEOUT_433 900
|
||||
#define SUBGHZ_PT_COUNT_KEY_868 9
|
||||
#define SUBGHZ_PT_TIMEOUT_868 14000
|
||||
|
||||
#define TAG "SubghzPrinceton"
|
||||
|
||||
|
@ -19,8 +21,11 @@ struct SubGhzEncoderPrinceton {
|
|||
size_t repeat;
|
||||
size_t front;
|
||||
size_t count_key;
|
||||
size_t count_key_package;
|
||||
uint32_t time_high;
|
||||
uint32_t time_low;
|
||||
uint32_t timeout;
|
||||
uint32_t time_stop;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
|
@ -48,15 +53,37 @@ void subghz_encoder_princeton_set_te(SubGhzEncoderPrinceton* instance, void* dec
|
|||
}
|
||||
}
|
||||
|
||||
void subghz_encoder_princeton_set(SubGhzEncoderPrinceton* instance, uint32_t key, size_t repeat) {
|
||||
void subghz_encoder_princeton_stop(SubGhzEncoderPrinceton* instance, uint32_t time_stop) {
|
||||
instance->time_stop = time_stop;
|
||||
}
|
||||
|
||||
void subghz_encoder_princeton_set(
|
||||
SubGhzEncoderPrinceton* instance,
|
||||
uint32_t key,
|
||||
size_t repeat,
|
||||
uint32_t frequency) {
|
||||
furi_assert(instance);
|
||||
instance->te = SUBGHZ_PT_SHORT;
|
||||
instance->key = key;
|
||||
instance->repeat = repeat + 1;
|
||||
instance->front = 48;
|
||||
instance->count_key = SUBGHZ_PT_COUNT_KEY + 7;
|
||||
instance->time_high = 0;
|
||||
instance->time_low = 0;
|
||||
if(frequency < 700000000) {
|
||||
instance->count_key_package = SUBGHZ_PT_COUNT_KEY_433;
|
||||
instance->timeout = SUBGHZ_PT_TIMEOUT_433;
|
||||
} else {
|
||||
instance->count_key_package = SUBGHZ_PT_COUNT_KEY_868;
|
||||
instance->timeout = SUBGHZ_PT_TIMEOUT_868;
|
||||
}
|
||||
|
||||
instance->count_key = instance->count_key_package + 3;
|
||||
|
||||
if((millis() - instance->time_stop) < instance->timeout) {
|
||||
instance->time_stop = (instance->timeout - (millis() - instance->time_stop)) * 1000;
|
||||
} else {
|
||||
instance->time_stop = 0;
|
||||
}
|
||||
}
|
||||
|
||||
size_t subghz_encoder_princeton_get_repeat_left(SubGhzEncoderPrinceton* instance) {
|
||||
|
@ -70,7 +97,8 @@ void subghz_encoder_princeton_print_log(void* context) {
|
|||
((float)instance->time_high / (instance->time_high + instance->time_low)) * 100;
|
||||
FURI_LOG_I(
|
||||
TAG "Encoder",
|
||||
"Radio ON=%dus, OFF=%dus, DutyCycle=%d,%d%%",
|
||||
"Radio tx_time=%dus ON=%dus, OFF=%dus, DutyCycle=%d,%d%%",
|
||||
instance->time_high + instance->time_low,
|
||||
instance->time_high,
|
||||
instance->time_low,
|
||||
(uint32_t)duty_cycle,
|
||||
|
@ -105,6 +133,16 @@ LevelDuration subghz_encoder_princeton_yield(void* context) {
|
|||
else
|
||||
instance->time_low += instance->te * 3;
|
||||
}
|
||||
} else {
|
||||
if(instance->time_stop) {
|
||||
ret = level_duration_make(level, level ? instance->te : instance->time_stop);
|
||||
if(level)
|
||||
instance->time_high += instance->te;
|
||||
else {
|
||||
instance->time_low += instance->time_stop;
|
||||
instance->time_stop = 0;
|
||||
instance->front = 47;
|
||||
}
|
||||
} else {
|
||||
if(--instance->count_key != 0) {
|
||||
ret = level_duration_make(level, level ? instance->te : instance->te * 30);
|
||||
|
@ -113,13 +151,14 @@ LevelDuration subghz_encoder_princeton_yield(void* context) {
|
|||
else
|
||||
instance->time_low += instance->te * 30;
|
||||
} else {
|
||||
instance->count_key = SUBGHZ_PT_COUNT_KEY + 6;
|
||||
instance->count_key = instance->count_key_package + 2;
|
||||
instance->front = 48;
|
||||
ret = level_duration_make(level, level ? instance->te : SUBGHZ_PT_TIMEOUT * 1000);
|
||||
ret = level_duration_make(level, level ? instance->te : instance->timeout * 1000);
|
||||
if(level)
|
||||
instance->time_high += instance->te;
|
||||
else
|
||||
instance->time_low += SUBGHZ_PT_TIMEOUT * 1000;
|
||||
instance->time_low += instance->timeout * 1000;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,7 +167,6 @@ LevelDuration subghz_encoder_princeton_yield(void* context) {
|
|||
instance->repeat--;
|
||||
instance->front = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -138,8 +176,8 @@ SubGhzDecoderPrinceton* subghz_decoder_princeton_alloc(void) {
|
|||
instance->te = SUBGHZ_PT_SHORT;
|
||||
instance->common.name = "Princeton";
|
||||
instance->common.code_min_count_bit_for_found = 24;
|
||||
instance->common.te_short = SUBGHZ_PT_SHORT; //150;
|
||||
instance->common.te_long = SUBGHZ_PT_LONG; //450;
|
||||
instance->common.te_short = 400; //150;
|
||||
instance->common.te_long = 1200; //450;
|
||||
instance->common.te_delta = 250; //50;
|
||||
instance->common.type_protocol = SubGhzProtocolCommonTypeStatic;
|
||||
instance->common.to_string = (SubGhzProtocolCommonToStr)subghz_decoder_princeton_to_str;
|
||||
|
|
|
@ -20,12 +20,19 @@ SubGhzEncoderPrinceton* subghz_encoder_princeton_alloc();
|
|||
*/
|
||||
void subghz_encoder_princeton_free(SubGhzEncoderPrinceton* instance);
|
||||
|
||||
void subghz_encoder_princeton_stop(SubGhzEncoderPrinceton* instance, uint32_t time_stop);
|
||||
|
||||
/** Set new encoder params
|
||||
* @param instance - SubGhzEncoderPrinceton instance
|
||||
* @param key - 24bit key
|
||||
* @param repeat - how many times to repeat
|
||||
* @param frequency - frequency
|
||||
*/
|
||||
void subghz_encoder_princeton_set(SubGhzEncoderPrinceton* instance, uint32_t key, size_t repeat);
|
||||
void subghz_encoder_princeton_set(
|
||||
SubGhzEncoderPrinceton* instance,
|
||||
uint32_t key,
|
||||
size_t repeat,
|
||||
uint32_t frequency);
|
||||
|
||||
/** Get repeat count left
|
||||
* @param instance - SubGhzEncoderPrinceton instance
|
||||
|
|
Loading…
Reference in a new issue