mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-10 06:54:19 +00:00
SubGhz: Princeton protocol add custom guard time (#3671)
* SubGhz: Princeton protocol add custom guard time * SubGhz: fix type var * SubGhz: fix syntax * SubGhz: add define PRINCETON_GUARD_TIME_DEFALUT * Update princeton.c Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
parent
3b83604fb7
commit
83e4bcc35a
2 changed files with 31 additions and 2 deletions
|
@ -80,6 +80,14 @@ SubGhzProtocolStatus subghz_txrx_gen_data_protocol_and_te(
|
|||
FURI_LOG_E(TAG, "Unable to update Te");
|
||||
}
|
||||
}
|
||||
if(ret == SubGhzProtocolStatusOk) {
|
||||
uint32_t guard_time = 30;
|
||||
if(!flipper_format_update_uint32(
|
||||
instance->fff_data, "Guard_time", (uint32_t*)&guard_time, 1)) {
|
||||
ret = SubGhzProtocolStatusErrorParserOthers;
|
||||
FURI_LOG_E(TAG, "Unable to update Guard_time");
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
*/
|
||||
|
||||
#define TAG "SubGhzProtocolPrinceton"
|
||||
#define PRINCETON_GUARD_TIME_DEFALUT 30 //GUARD_TIME = PRINCETON_GUARD_TIME_DEFALUT * TE
|
||||
|
||||
static const SubGhzBlockConst subghz_protocol_princeton_const = {
|
||||
.te_short = 390,
|
||||
|
@ -29,6 +30,7 @@ struct SubGhzProtocolDecoderPrinceton {
|
|||
|
||||
uint32_t te;
|
||||
uint32_t last_data;
|
||||
uint32_t guard_time;
|
||||
};
|
||||
|
||||
struct SubGhzProtocolEncoderPrinceton {
|
||||
|
@ -38,6 +40,7 @@ struct SubGhzProtocolEncoderPrinceton {
|
|||
SubGhzBlockGeneric generic;
|
||||
|
||||
uint32_t te;
|
||||
uint32_t guard_time;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
|
@ -135,8 +138,9 @@ static bool
|
|||
|
||||
//Send Stop bit
|
||||
instance->encoder.upload[index++] = level_duration_make(true, (uint32_t)instance->te);
|
||||
//Send PT_GUARD
|
||||
instance->encoder.upload[index++] = level_duration_make(false, (uint32_t)instance->te * 30);
|
||||
//Send PT_GUARD_TIME
|
||||
instance->encoder.upload[index++] =
|
||||
level_duration_make(false, (uint32_t)instance->te * instance->guard_time);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -165,6 +169,11 @@ SubGhzProtocolStatus
|
|||
break;
|
||||
}
|
||||
//optional parameter parameter
|
||||
if(!flipper_format_read_uint32(
|
||||
flipper_format, "Guard_time", (uint32_t*)&instance->guard_time, 1)) {
|
||||
instance->guard_time = PRINCETON_GUARD_TIME_DEFALUT;
|
||||
}
|
||||
|
||||
flipper_format_read_uint32(
|
||||
flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1);
|
||||
|
||||
|
@ -235,6 +244,7 @@ void subghz_protocol_decoder_princeton_feed(void* context, bool level, uint32_t
|
|||
instance->decoder.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
instance->te = 0;
|
||||
instance->guard_time = PRINCETON_GUARD_TIME_DEFALUT;
|
||||
}
|
||||
break;
|
||||
case PrincetonDecoderStepSaveDuration:
|
||||
|
@ -257,6 +267,7 @@ void subghz_protocol_decoder_princeton_feed(void* context, bool level, uint32_t
|
|||
|
||||
instance->generic.data = instance->decoder.decode_data;
|
||||
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
|
||||
instance->guard_time = round((float)duration / instance->te);
|
||||
|
||||
if(instance->base.callback)
|
||||
instance->base.callback(&instance->base, instance->base.context);
|
||||
|
@ -323,6 +334,12 @@ SubGhzProtocolStatus subghz_protocol_decoder_princeton_serialize(
|
|||
FURI_LOG_E(TAG, "Unable to add TE");
|
||||
ret = SubGhzProtocolStatusErrorParserTe;
|
||||
}
|
||||
if((ret == SubGhzProtocolStatusOk) &&
|
||||
!flipper_format_write_uint32(flipper_format, "Guard_time", &instance->guard_time, 1)) {
|
||||
FURI_LOG_E(TAG, "Unable to add Guard_time");
|
||||
ret = SubGhzProtocolStatusErrorParserOthers;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -349,6 +366,10 @@ SubGhzProtocolStatus
|
|||
ret = SubGhzProtocolStatusErrorParserTe;
|
||||
break;
|
||||
}
|
||||
if(!flipper_format_read_uint32(
|
||||
flipper_format, "Guard_time", (uint32_t*)&instance->guard_time, 1)) {
|
||||
instance->guard_time = PRINCETON_GUARD_TIME_DEFALUT;
|
||||
}
|
||||
} while(false);
|
||||
|
||||
return ret;
|
||||
|
|
Loading…
Reference in a new issue