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:
Skorpionm 2024-06-01 15:15:24 +04:00 committed by GitHub
parent 3b83604fb7
commit 83e4bcc35a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 2 deletions

View file

@ -80,6 +80,14 @@ SubGhzProtocolStatus subghz_txrx_gen_data_protocol_and_te(
FURI_LOG_E(TAG, "Unable to update 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; return ret;
} }

View file

@ -13,6 +13,7 @@
*/ */
#define TAG "SubGhzProtocolPrinceton" #define TAG "SubGhzProtocolPrinceton"
#define PRINCETON_GUARD_TIME_DEFALUT 30 //GUARD_TIME = PRINCETON_GUARD_TIME_DEFALUT * TE
static const SubGhzBlockConst subghz_protocol_princeton_const = { static const SubGhzBlockConst subghz_protocol_princeton_const = {
.te_short = 390, .te_short = 390,
@ -29,6 +30,7 @@ struct SubGhzProtocolDecoderPrinceton {
uint32_t te; uint32_t te;
uint32_t last_data; uint32_t last_data;
uint32_t guard_time;
}; };
struct SubGhzProtocolEncoderPrinceton { struct SubGhzProtocolEncoderPrinceton {
@ -38,6 +40,7 @@ struct SubGhzProtocolEncoderPrinceton {
SubGhzBlockGeneric generic; SubGhzBlockGeneric generic;
uint32_t te; uint32_t te;
uint32_t guard_time;
}; };
typedef enum { typedef enum {
@ -135,8 +138,9 @@ static bool
//Send Stop bit //Send Stop bit
instance->encoder.upload[index++] = level_duration_make(true, (uint32_t)instance->te); instance->encoder.upload[index++] = level_duration_make(true, (uint32_t)instance->te);
//Send PT_GUARD //Send PT_GUARD_TIME
instance->encoder.upload[index++] = level_duration_make(false, (uint32_t)instance->te * 30); instance->encoder.upload[index++] =
level_duration_make(false, (uint32_t)instance->te * instance->guard_time);
return true; return true;
} }
@ -165,6 +169,11 @@ SubGhzProtocolStatus
break; break;
} }
//optional parameter parameter //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_read_uint32(
flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1); 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_data = 0;
instance->decoder.decode_count_bit = 0; instance->decoder.decode_count_bit = 0;
instance->te = 0; instance->te = 0;
instance->guard_time = PRINCETON_GUARD_TIME_DEFALUT;
} }
break; break;
case PrincetonDecoderStepSaveDuration: 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 = instance->decoder.decode_data;
instance->generic.data_count_bit = instance->decoder.decode_count_bit; instance->generic.data_count_bit = instance->decoder.decode_count_bit;
instance->guard_time = round((float)duration / instance->te);
if(instance->base.callback) if(instance->base.callback)
instance->base.callback(&instance->base, instance->base.context); 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"); FURI_LOG_E(TAG, "Unable to add TE");
ret = SubGhzProtocolStatusErrorParserTe; 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; return ret;
} }
@ -349,6 +366,10 @@ SubGhzProtocolStatus
ret = SubGhzProtocolStatusErrorParserTe; ret = SubGhzProtocolStatusErrorParserTe;
break; 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); } while(false);
return ret; return ret;