[FL-3078] Per protocol signal repeat count (#2293)

* Better Infrared protocol file structure
* Rename InfraredProtocolSpec to InfraredProtocolVariant
* Slightly better names
* Add repeat count field to protocol variant description
* Repeat the signal the appropriate number of times when brute-forcing
* Repeat the signal the appropriate number of times when sending via worker
* Better signal count logic in infrared_transmit
* Better variable names
* Convert some raw signals to messages in tv.ir

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
Georgii Surkov
2023-01-13 16:50:19 +03:00
committed by GitHub
parent ad9d746a27
commit 75e9de12b0
47 changed files with 1220 additions and 1180 deletions

View File

@@ -1,10 +1,5 @@
#include "common/infrared_common_i.h"
#include "infrared.h"
#include "infrared_protocol_defs_i.h"
#include <stdbool.h>
#include <stdint.h>
#include <furi.h>
#include "../infrared_i.h"
#include "infrared_protocol_nec_i.h"
#include <core/check.h>
InfraredMessage* infrared_decoder_nec_check_ready(void* ctx) {
return infrared_common_decoder_check_ready(ctx);
@@ -86,7 +81,7 @@ InfraredStatus infrared_decoder_nec_decode_repeat(InfraredCommonDecoder* decoder
}
void* infrared_decoder_nec_alloc(void) {
return infrared_common_decoder_alloc(&protocol_nec);
return infrared_common_decoder_alloc(&infrared_protocol_nec);
}
InfraredMessage* infrared_decoder_nec_decode(void* decoder, bool level, uint32_t duration) {

View File

@@ -1,10 +1,7 @@
#include "infrared_protocol_nec_i.h"
#include <core/core_defines.h>
#include <core/check.h>
#include "infrared.h"
#include "common/infrared_common_i.h"
#include <stdint.h>
#include "../infrared_i.h"
#include "infrared_protocol_defs_i.h"
#include <furi.h>
static const uint32_t repeat_timings[] = {
INFRARED_NEC_REPEAT_PERIOD - INFRARED_NEC_REPEAT_MARK - INFRARED_NEC_REPEAT_SPACE -
@@ -81,7 +78,7 @@ InfraredStatus infrared_encoder_nec_encode_repeat(
}
void* infrared_encoder_nec_alloc(void) {
return infrared_common_encoder_alloc(&protocol_nec);
return infrared_common_encoder_alloc(&infrared_protocol_nec);
}
void infrared_encoder_nec_free(void* encoder_ptr) {

View File

@@ -1,47 +0,0 @@
#include "../infrared_i.h"
#include "infrared_protocol_defs_i.h"
static const InfraredProtocolSpecification infrared_nec_protocol_specification = {
.name = "NEC",
.address_length = 8,
.command_length = 8,
.frequency = INFRARED_COMMON_CARRIER_FREQUENCY,
.duty_cycle = INFRARED_COMMON_DUTY_CYCLE,
};
static const InfraredProtocolSpecification infrared_necext_protocol_specification = {
.name = "NECext",
.address_length = 16,
.command_length = 16,
.frequency = INFRARED_COMMON_CARRIER_FREQUENCY,
.duty_cycle = INFRARED_COMMON_DUTY_CYCLE,
};
static const InfraredProtocolSpecification infrared_nec42_protocol_specification = {
.name = "NEC42",
.address_length = 13,
.command_length = 8,
.frequency = INFRARED_COMMON_CARRIER_FREQUENCY,
.duty_cycle = INFRARED_COMMON_DUTY_CYCLE,
};
static const InfraredProtocolSpecification infrared_nec42ext_protocol_specification = {
.name = "NEC42ext",
.address_length = 26,
.command_length = 16,
.frequency = INFRARED_COMMON_CARRIER_FREQUENCY,
.duty_cycle = INFRARED_COMMON_DUTY_CYCLE,
};
const InfraredProtocolSpecification* infrared_nec_get_spec(InfraredProtocol protocol) {
if(protocol == InfraredProtocolNEC)
return &infrared_nec_protocol_specification;
else if(protocol == InfraredProtocolNECext)
return &infrared_necext_protocol_specification;
else if(protocol == InfraredProtocolNEC42)
return &infrared_nec42_protocol_specification;
else if(protocol == InfraredProtocolNEC42ext)
return &infrared_nec42ext_protocol_specification;
else
return NULL;
}

View File

@@ -0,0 +1,74 @@
#include "infrared_protocol_nec_i.h"
const InfraredCommonProtocolSpec infrared_protocol_nec = {
.timings =
{
.preamble_mark = INFRARED_NEC_PREAMBLE_MARK,
.preamble_space = INFRARED_NEC_PREAMBLE_SPACE,
.bit1_mark = INFRARED_NEC_BIT1_MARK,
.bit1_space = INFRARED_NEC_BIT1_SPACE,
.bit0_mark = INFRARED_NEC_BIT0_MARK,
.bit0_space = INFRARED_NEC_BIT0_SPACE,
.preamble_tolerance = INFRARED_NEC_PREAMBLE_TOLERANCE,
.bit_tolerance = INFRARED_NEC_BIT_TOLERANCE,
.silence_time = INFRARED_NEC_SILENCE,
.min_split_time = INFRARED_NEC_MIN_SPLIT_TIME,
},
.databit_len[0] = 42,
.databit_len[1] = 32,
.no_stop_bit = false,
.decode = infrared_common_decode_pdwm,
.encode = infrared_common_encode_pdwm,
.interpret = infrared_decoder_nec_interpret,
.decode_repeat = infrared_decoder_nec_decode_repeat,
.encode_repeat = infrared_encoder_nec_encode_repeat,
};
static const InfraredProtocolVariant infrared_protocol_variant_nec = {
.name = "NEC",
.address_length = 8,
.command_length = 8,
.frequency = INFRARED_COMMON_CARRIER_FREQUENCY,
.duty_cycle = INFRARED_COMMON_DUTY_CYCLE,
.repeat_count = INFRARED_NEC_REPEAT_COUNT_MIN,
};
static const InfraredProtocolVariant infrared_protocol_variant_necext = {
.name = "NECext",
.address_length = 16,
.command_length = 16,
.frequency = INFRARED_COMMON_CARRIER_FREQUENCY,
.duty_cycle = INFRARED_COMMON_DUTY_CYCLE,
.repeat_count = INFRARED_NEC_REPEAT_COUNT_MIN,
};
static const InfraredProtocolVariant infrared_protocol_variant_nec42 = {
.name = "NEC42",
.address_length = 13,
.command_length = 8,
.frequency = INFRARED_COMMON_CARRIER_FREQUENCY,
.duty_cycle = INFRARED_COMMON_DUTY_CYCLE,
.repeat_count = INFRARED_NEC_REPEAT_COUNT_MIN,
};
static const InfraredProtocolVariant infrared_protocol_variant_nec42ext = {
.name = "NEC42ext",
.address_length = 26,
.command_length = 16,
.frequency = INFRARED_COMMON_CARRIER_FREQUENCY,
.duty_cycle = INFRARED_COMMON_DUTY_CYCLE,
.repeat_count = INFRARED_NEC_REPEAT_COUNT_MIN,
};
const InfraredProtocolVariant* infrared_protocol_nec_get_variant(InfraredProtocol protocol) {
if(protocol == InfraredProtocolNEC)
return &infrared_protocol_variant_nec;
else if(protocol == InfraredProtocolNECext)
return &infrared_protocol_variant_necext;
else if(protocol == InfraredProtocolNEC42)
return &infrared_protocol_variant_nec42;
else if(protocol == InfraredProtocolNEC42ext)
return &infrared_protocol_variant_nec42ext;
else
return NULL;
}

View File

@@ -0,0 +1,30 @@
#pragma once
#include "../infrared_i.h"
/***************************************************************************************************
* NEC protocol description
* https://radioparty.ru/manuals/encyclopedia/213-ircontrol?start=1
****************************************************************************************************
* Preamble Preamble Pulse Distance/Width Pause Preamble Preamble Stop
* mark space Modulation up to period repeat repeat bit
* mark space
*
* 9000 4500 32 bit + stop bit ...110000 9000 2250
* __________ _ _ _ _ _ _ _ _ _ _ _ _ _ ___________ _
* ____ __________ _ _ _ __ __ __ _ _ __ __ _ _ ________________ ____________ ___
*
***************************************************************************************************/
void* infrared_decoder_nec_alloc(void);
void infrared_decoder_nec_reset(void* decoder);
void infrared_decoder_nec_free(void* decoder);
InfraredMessage* infrared_decoder_nec_check_ready(void* decoder);
InfraredMessage* infrared_decoder_nec_decode(void* decoder, bool level, uint32_t duration);
void* infrared_encoder_nec_alloc(void);
InfraredStatus infrared_encoder_nec_encode(void* encoder_ptr, uint32_t* duration, bool* level);
void infrared_encoder_nec_reset(void* encoder_ptr, const InfraredMessage* message);
void infrared_encoder_nec_free(void* encoder_ptr);
const InfraredProtocolVariant* infrared_protocol_nec_get_variant(InfraredProtocol protocol);

View File

@@ -0,0 +1,29 @@
#pragma once
#include "../common/infrared_common_i.h"
#define INFRARED_NEC_PREAMBLE_MARK 9000
#define INFRARED_NEC_PREAMBLE_SPACE 4500
#define INFRARED_NEC_BIT1_MARK 560
#define INFRARED_NEC_BIT1_SPACE 1690
#define INFRARED_NEC_BIT0_MARK 560
#define INFRARED_NEC_BIT0_SPACE 560
#define INFRARED_NEC_REPEAT_PERIOD 110000
#define INFRARED_NEC_SILENCE INFRARED_NEC_REPEAT_PERIOD
#define INFRARED_NEC_MIN_SPLIT_TIME INFRARED_NEC_REPEAT_PAUSE_MIN
#define INFRARED_NEC_REPEAT_PAUSE_MIN 4000
#define INFRARED_NEC_REPEAT_PAUSE_MAX 150000
#define INFRARED_NEC_REPEAT_COUNT_MIN 1
#define INFRARED_NEC_REPEAT_MARK 9000
#define INFRARED_NEC_REPEAT_SPACE 2250
#define INFRARED_NEC_PREAMBLE_TOLERANCE 200 // us
#define INFRARED_NEC_BIT_TOLERANCE 120 // us
extern const InfraredCommonProtocolSpec infrared_protocol_nec;
bool infrared_decoder_nec_interpret(InfraredCommonDecoder* decoder);
InfraredStatus infrared_decoder_nec_decode_repeat(InfraredCommonDecoder* decoder);
InfraredStatus infrared_encoder_nec_encode_repeat(
InfraredCommonEncoder* encoder,
uint32_t* duration,
bool* level);