mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-07-16 00:18:11 -07:00
Merge branch 'fz-dev' into dev
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "lfrfid_protocols.h"
|
||||
#include "protocol_em4100.h"
|
||||
#include "protocol_h10301.h"
|
||||
#include "protocol_idteck.h"
|
||||
#include "protocol_indala26.h"
|
||||
#include "protocol_io_prox_xsf.h"
|
||||
#include "protocol_awid.h"
|
||||
@@ -19,6 +20,7 @@
|
||||
const ProtocolBase* lfrfid_protocols[] = {
|
||||
[LFRFIDProtocolEM4100] = &protocol_em4100,
|
||||
[LFRFIDProtocolH10301] = &protocol_h10301,
|
||||
[LFRFIDProtocolIdteck] = &protocol_idteck,
|
||||
[LFRFIDProtocolIndala26] = &protocol_indala26,
|
||||
[LFRFIDProtocolIOProxXSF] = &protocol_io_prox_xsf,
|
||||
[LFRFIDProtocolAwid] = &protocol_awid,
|
||||
|
||||
@@ -10,6 +10,7 @@ typedef enum {
|
||||
typedef enum {
|
||||
LFRFIDProtocolEM4100,
|
||||
LFRFIDProtocolH10301,
|
||||
LFRFIDProtocolIdteck,
|
||||
LFRFIDProtocolIndala26,
|
||||
LFRFIDProtocolIOProxXSF,
|
||||
LFRFIDProtocolAwid,
|
||||
|
||||
@@ -0,0 +1,269 @@
|
||||
#include <furi.h>
|
||||
#include <toolbox/protocols/protocol.h>
|
||||
#include <lfrfid/tools/bit_lib.h>
|
||||
#include "lfrfid_protocols.h"
|
||||
|
||||
// Example: 4944544B 351FBE4B
|
||||
// 01001001 01000100 01010100 01001011 00110101 00011111 10111110 01001011
|
||||
// 4 9 4 4 5 4 4 B 3 5 1 F B E 4 B
|
||||
// 0100 1001 0100 0100 0101 0100 0100 1011 0011 0101 0001 1111 1011 1110 0100 1011
|
||||
|
||||
#define IDTECK_PREAMBLE_BIT_SIZE (32)
|
||||
#define IDTECK_PREAMBLE_DATA_SIZE (8)
|
||||
|
||||
#define IDTECK_ENCODED_BIT_SIZE (64)
|
||||
#define IDTECK_ENCODED_DATA_SIZE (((IDTECK_ENCODED_BIT_SIZE) / 8) + IDTECK_PREAMBLE_DATA_SIZE)
|
||||
#define IDTECK_ENCODED_DATA_LAST ((IDTECK_ENCODED_BIT_SIZE) / 8)
|
||||
|
||||
#define IDTECK_DECODED_BIT_SIZE (64)
|
||||
#define IDTECK_DECODED_DATA_SIZE (8)
|
||||
|
||||
#define IDTECK_US_PER_BIT (255)
|
||||
#define IDTECK_ENCODER_PULSES_PER_BIT (16)
|
||||
|
||||
typedef struct {
|
||||
uint8_t data_index;
|
||||
uint8_t bit_clock_index;
|
||||
bool last_bit;
|
||||
bool current_polarity;
|
||||
bool pulse_phase;
|
||||
} ProtocolIdteckEncoder;
|
||||
|
||||
typedef struct {
|
||||
uint8_t encoded_data[IDTECK_ENCODED_DATA_SIZE];
|
||||
uint8_t negative_encoded_data[IDTECK_ENCODED_DATA_SIZE];
|
||||
uint8_t corrupted_encoded_data[IDTECK_ENCODED_DATA_SIZE];
|
||||
uint8_t corrupted_negative_encoded_data[IDTECK_ENCODED_DATA_SIZE];
|
||||
|
||||
uint8_t data[IDTECK_DECODED_DATA_SIZE];
|
||||
ProtocolIdteckEncoder encoder;
|
||||
} ProtocolIdteck;
|
||||
|
||||
ProtocolIdteck* protocol_idteck_alloc(void) {
|
||||
ProtocolIdteck* protocol = malloc(sizeof(ProtocolIdteck));
|
||||
return protocol;
|
||||
};
|
||||
|
||||
void protocol_idteck_free(ProtocolIdteck* protocol) {
|
||||
free(protocol);
|
||||
};
|
||||
|
||||
uint8_t* protocol_idteck_get_data(ProtocolIdteck* protocol) {
|
||||
return protocol->data;
|
||||
};
|
||||
|
||||
void protocol_idteck_decoder_start(ProtocolIdteck* protocol) {
|
||||
memset(protocol->encoded_data, 0, IDTECK_ENCODED_DATA_SIZE);
|
||||
memset(protocol->negative_encoded_data, 0, IDTECK_ENCODED_DATA_SIZE);
|
||||
memset(protocol->corrupted_encoded_data, 0, IDTECK_ENCODED_DATA_SIZE);
|
||||
memset(protocol->corrupted_negative_encoded_data, 0, IDTECK_ENCODED_DATA_SIZE);
|
||||
};
|
||||
|
||||
static bool protocol_idteck_check_preamble(uint8_t* data, size_t bit_index) {
|
||||
// Preamble 01001001 01000100 01010100 01001011
|
||||
if(*(uint32_t*)&data[bit_index / 8] != 0b01001011010101000100010001001001) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool protocol_idteck_can_be_decoded(uint8_t* data) {
|
||||
if(!protocol_idteck_check_preamble(data, 0)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool protocol_idteck_decoder_feed_internal(bool polarity, uint32_t time, uint8_t* data) {
|
||||
time += (IDTECK_US_PER_BIT / 2);
|
||||
|
||||
size_t bit_count = (time / IDTECK_US_PER_BIT);
|
||||
bool result = false;
|
||||
|
||||
if(bit_count < IDTECK_ENCODED_BIT_SIZE) {
|
||||
for(size_t i = 0; i < bit_count; i++) {
|
||||
bit_lib_push_bit(data, IDTECK_ENCODED_DATA_SIZE, polarity);
|
||||
if(protocol_idteck_can_be_decoded(data)) {
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void protocol_idteck_decoder_save(uint8_t* data_to, const uint8_t* data_from) {
|
||||
bit_lib_copy_bits(data_to, 0, 64, data_from, 0);
|
||||
}
|
||||
|
||||
bool protocol_idteck_decoder_feed(ProtocolIdteck* protocol, bool level, uint32_t duration) {
|
||||
bool result = false;
|
||||
|
||||
if(duration > (IDTECK_US_PER_BIT / 2)) {
|
||||
if(protocol_idteck_decoder_feed_internal(level, duration, protocol->encoded_data)) {
|
||||
protocol_idteck_decoder_save(protocol->data, protocol->encoded_data);
|
||||
FURI_LOG_D("Idteck", "Positive");
|
||||
result = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
if(protocol_idteck_decoder_feed_internal(
|
||||
!level, duration, protocol->negative_encoded_data)) {
|
||||
protocol_idteck_decoder_save(protocol->data, protocol->negative_encoded_data);
|
||||
FURI_LOG_D("Idteck", "Negative");
|
||||
result = true;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if(duration > (IDTECK_US_PER_BIT / 4)) {
|
||||
// Try to decode wrong phase synced data
|
||||
if(level) {
|
||||
duration += 120;
|
||||
} else {
|
||||
if(duration > 120) {
|
||||
duration -= 120;
|
||||
}
|
||||
}
|
||||
|
||||
if(protocol_idteck_decoder_feed_internal(
|
||||
level, duration, protocol->corrupted_encoded_data)) {
|
||||
protocol_idteck_decoder_save(protocol->data, protocol->corrupted_encoded_data);
|
||||
FURI_LOG_D("Idteck", "Positive Corrupted");
|
||||
|
||||
result = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
if(protocol_idteck_decoder_feed_internal(
|
||||
!level, duration, protocol->corrupted_negative_encoded_data)) {
|
||||
protocol_idteck_decoder_save(
|
||||
protocol->data, protocol->corrupted_negative_encoded_data);
|
||||
FURI_LOG_D("Idteck", "Negative Corrupted");
|
||||
|
||||
result = true;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
bool protocol_idteck_encoder_start(ProtocolIdteck* protocol) {
|
||||
memset(protocol->encoded_data, 0, IDTECK_ENCODED_DATA_SIZE);
|
||||
*(uint32_t*)&protocol->encoded_data[0] = 0b01001011010101000100010001001001;
|
||||
bit_lib_copy_bits(protocol->encoded_data, 32, 32, protocol->data, 32);
|
||||
|
||||
protocol->encoder.last_bit =
|
||||
bit_lib_get_bit(protocol->encoded_data, IDTECK_ENCODED_BIT_SIZE - 1);
|
||||
protocol->encoder.data_index = 0;
|
||||
protocol->encoder.current_polarity = true;
|
||||
protocol->encoder.pulse_phase = true;
|
||||
protocol->encoder.bit_clock_index = 0;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
LevelDuration protocol_idteck_encoder_yield(ProtocolIdteck* protocol) {
|
||||
LevelDuration level_duration;
|
||||
ProtocolIdteckEncoder* encoder = &protocol->encoder;
|
||||
|
||||
if(encoder->pulse_phase) {
|
||||
level_duration = level_duration_make(encoder->current_polarity, 1);
|
||||
encoder->pulse_phase = false;
|
||||
} else {
|
||||
level_duration = level_duration_make(!encoder->current_polarity, 1);
|
||||
encoder->pulse_phase = true;
|
||||
|
||||
encoder->bit_clock_index++;
|
||||
if(encoder->bit_clock_index >= IDTECK_ENCODER_PULSES_PER_BIT) {
|
||||
encoder->bit_clock_index = 0;
|
||||
|
||||
bool current_bit = bit_lib_get_bit(protocol->encoded_data, encoder->data_index);
|
||||
|
||||
if(current_bit != encoder->last_bit) {
|
||||
encoder->current_polarity = !encoder->current_polarity;
|
||||
}
|
||||
|
||||
encoder->last_bit = current_bit;
|
||||
|
||||
bit_lib_increment_index(encoder->data_index, IDTECK_ENCODED_BIT_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
return level_duration;
|
||||
};
|
||||
|
||||
// factory code
|
||||
static uint32_t get_fc(const uint8_t* data) {
|
||||
uint32_t fc = 0;
|
||||
fc = bit_lib_get_bits_32(data, 0, 32);
|
||||
return fc;
|
||||
}
|
||||
|
||||
// card number
|
||||
static uint32_t get_card(const uint8_t* data) {
|
||||
uint32_t cn = 0;
|
||||
cn = bit_lib_get_bits_32(data, 32, 32);
|
||||
return cn;
|
||||
}
|
||||
|
||||
void protocol_idteck_render_data_internal(ProtocolIdteck* protocol, FuriString* result, bool brief) {
|
||||
const uint32_t fc = get_fc(protocol->data);
|
||||
const uint32_t card = get_card(protocol->data);
|
||||
|
||||
if(brief) {
|
||||
furi_string_printf(result, "FC: %08lX\r\nCard: %08lX", fc, card);
|
||||
} else {
|
||||
furi_string_printf(
|
||||
result,
|
||||
"FC: %08lX\r\n"
|
||||
"Card: %08lX\r\n",
|
||||
fc,
|
||||
card);
|
||||
}
|
||||
}
|
||||
void protocol_idteck_render_data(ProtocolIdteck* protocol, FuriString* result) {
|
||||
protocol_idteck_render_data_internal(protocol, result, false);
|
||||
}
|
||||
void protocol_idteck_render_brief_data(ProtocolIdteck* protocol, FuriString* result) {
|
||||
protocol_idteck_render_data_internal(protocol, result, true);
|
||||
}
|
||||
|
||||
bool protocol_idteck_write_data(ProtocolIdteck* protocol, void* data) {
|
||||
LFRFIDWriteRequest* request = (LFRFIDWriteRequest*)data;
|
||||
bool result = false;
|
||||
|
||||
protocol_idteck_encoder_start(protocol);
|
||||
|
||||
if(request->write_type == LFRFIDWriteTypeT5577) {
|
||||
request->t5577.block[0] = LFRFID_T5577_BITRATE_RF_32 | LFRFID_T5577_MODULATION_PSK1 |
|
||||
(2 << LFRFID_T5577_MAXBLOCK_SHIFT);
|
||||
request->t5577.block[1] = bit_lib_get_bits_32(protocol->encoded_data, 0, 32);
|
||||
request->t5577.block[2] = bit_lib_get_bits_32(protocol->encoded_data, 32, 32);
|
||||
request->t5577.blocks_to_write = 3;
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const ProtocolBase protocol_idteck = {
|
||||
.name = "Idteck",
|
||||
.manufacturer = "IDTECK",
|
||||
.data_size = IDTECK_DECODED_DATA_SIZE,
|
||||
.features = LFRFIDFeaturePSK,
|
||||
.validate_count = 6,
|
||||
.alloc = (ProtocolAlloc)protocol_idteck_alloc,
|
||||
.free = (ProtocolFree)protocol_idteck_free,
|
||||
.get_data = (ProtocolGetData)protocol_idteck_get_data,
|
||||
.decoder =
|
||||
{
|
||||
.start = (ProtocolDecoderStart)protocol_idteck_decoder_start,
|
||||
.feed = (ProtocolDecoderFeed)protocol_idteck_decoder_feed,
|
||||
},
|
||||
.encoder =
|
||||
{
|
||||
.start = (ProtocolEncoderStart)protocol_idteck_encoder_start,
|
||||
.yield = (ProtocolEncoderYield)protocol_idteck_encoder_yield,
|
||||
},
|
||||
.render_data = (ProtocolRenderData)protocol_idteck_render_data,
|
||||
.render_brief_data = (ProtocolRenderData)protocol_idteck_render_brief_data,
|
||||
.write_data = (ProtocolWriteData)protocol_idteck_write_data,
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
#include <toolbox/protocols/protocol.h>
|
||||
|
||||
extern const ProtocolBase protocol_idteck;
|
||||
@@ -12,7 +12,7 @@ const SubGhzProtocol* subghz_protocol_registry_items[] = {
|
||||
&subghz_protocol_chamb_code, &subghz_protocol_power_smart, &subghz_protocol_marantec,
|
||||
&subghz_protocol_bett, &subghz_protocol_doitrand, &subghz_protocol_phoenix_v2,
|
||||
&subghz_protocol_honeywell_wdb, &subghz_protocol_magellan, &subghz_protocol_intertechno_v3,
|
||||
&subghz_protocol_clemsa, &subghz_protocol_ansonic,
|
||||
&subghz_protocol_clemsa, &subghz_protocol_ansonic, &subghz_protocol_smc5326,
|
||||
};
|
||||
|
||||
const SubGhzProtocolRegistry subghz_protocol_registry = {
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "intertechno_v3.h"
|
||||
#include "clemsa.h"
|
||||
#include "ansonic.h"
|
||||
#include "smc5326.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -0,0 +1,387 @@
|
||||
#include "smc5326.h"
|
||||
|
||||
#include "../blocks/const.h"
|
||||
#include "../blocks/decoder.h"
|
||||
#include "../blocks/encoder.h"
|
||||
#include "../blocks/generic.h"
|
||||
#include "../blocks/math.h"
|
||||
|
||||
/*
|
||||
* Help
|
||||
* https://datasheetspdf.com/pdf-file/532079/Aslic/AX5326-4/1
|
||||
*
|
||||
*/
|
||||
|
||||
#define TAG "SubGhzProtocolSMC5326"
|
||||
|
||||
#define DIP_P 0b11 //(+)
|
||||
#define DIP_O 0b10 //(0)
|
||||
#define DIP_N 0b00 //(-)
|
||||
|
||||
#define DIP_PATTERN "%c%c%c%c%c%c%c%c"
|
||||
#define SHOW_DIP_P(dip, check_dip) \
|
||||
((((dip >> 0xE) & 0x3) == check_dip) ? '*' : '_'), \
|
||||
((((dip >> 0xC) & 0x3) == check_dip) ? '*' : '_'), \
|
||||
((((dip >> 0xA) & 0x3) == check_dip) ? '*' : '_'), \
|
||||
((((dip >> 0x8) & 0x3) == check_dip) ? '*' : '_'), \
|
||||
((((dip >> 0x6) & 0x3) == check_dip) ? '*' : '_'), \
|
||||
((((dip >> 0x4) & 0x3) == check_dip) ? '*' : '_'), \
|
||||
((((dip >> 0x2) & 0x3) == check_dip) ? '*' : '_'), \
|
||||
((((dip >> 0x0) & 0x3) == check_dip) ? '*' : '_')
|
||||
|
||||
static const SubGhzBlockConst subghz_protocol_smc5326_const = {
|
||||
.te_short = 300,
|
||||
.te_long = 900,
|
||||
.te_delta = 200,
|
||||
.min_count_bit_for_found = 25,
|
||||
};
|
||||
|
||||
struct SubGhzProtocolDecoderSMC5326 {
|
||||
SubGhzProtocolDecoderBase base;
|
||||
|
||||
SubGhzBlockDecoder decoder;
|
||||
SubGhzBlockGeneric generic;
|
||||
|
||||
uint32_t te;
|
||||
uint32_t last_data;
|
||||
};
|
||||
|
||||
struct SubGhzProtocolEncoderSMC5326 {
|
||||
SubGhzProtocolEncoderBase base;
|
||||
|
||||
SubGhzProtocolBlockEncoder encoder;
|
||||
SubGhzBlockGeneric generic;
|
||||
|
||||
uint32_t te;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
SMC5326DecoderStepReset = 0,
|
||||
SMC5326DecoderStepSaveDuration,
|
||||
SMC5326DecoderStepCheckDuration,
|
||||
} SMC5326DecoderStep;
|
||||
|
||||
const SubGhzProtocolDecoder subghz_protocol_smc5326_decoder = {
|
||||
.alloc = subghz_protocol_decoder_smc5326_alloc,
|
||||
.free = subghz_protocol_decoder_smc5326_free,
|
||||
|
||||
.feed = subghz_protocol_decoder_smc5326_feed,
|
||||
.reset = subghz_protocol_decoder_smc5326_reset,
|
||||
|
||||
.get_hash_data = subghz_protocol_decoder_smc5326_get_hash_data,
|
||||
.serialize = subghz_protocol_decoder_smc5326_serialize,
|
||||
.deserialize = subghz_protocol_decoder_smc5326_deserialize,
|
||||
.get_string = subghz_protocol_decoder_smc5326_get_string,
|
||||
};
|
||||
|
||||
const SubGhzProtocolEncoder subghz_protocol_smc5326_encoder = {
|
||||
.alloc = subghz_protocol_encoder_smc5326_alloc,
|
||||
.free = subghz_protocol_encoder_smc5326_free,
|
||||
|
||||
.deserialize = subghz_protocol_encoder_smc5326_deserialize,
|
||||
.stop = subghz_protocol_encoder_smc5326_stop,
|
||||
.yield = subghz_protocol_encoder_smc5326_yield,
|
||||
};
|
||||
|
||||
const SubGhzProtocol subghz_protocol_smc5326 = {
|
||||
.name = SUBGHZ_PROTOCOL_SMC5326_NAME,
|
||||
.type = SubGhzProtocolTypeStatic,
|
||||
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_868 | SubGhzProtocolFlag_315 |
|
||||
SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_Load |
|
||||
SubGhzProtocolFlag_Save | SubGhzProtocolFlag_Send,
|
||||
|
||||
.decoder = &subghz_protocol_smc5326_decoder,
|
||||
.encoder = &subghz_protocol_smc5326_encoder,
|
||||
};
|
||||
|
||||
void* subghz_protocol_encoder_smc5326_alloc(SubGhzEnvironment* environment) {
|
||||
UNUSED(environment);
|
||||
SubGhzProtocolEncoderSMC5326* instance = malloc(sizeof(SubGhzProtocolEncoderSMC5326));
|
||||
|
||||
instance->base.protocol = &subghz_protocol_smc5326;
|
||||
instance->generic.protocol_name = instance->base.protocol->name;
|
||||
|
||||
instance->encoder.repeat = 10;
|
||||
instance->encoder.size_upload = 128;
|
||||
instance->encoder.upload = malloc(instance->encoder.size_upload * sizeof(LevelDuration));
|
||||
instance->encoder.is_running = false;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_protocol_encoder_smc5326_free(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolEncoderSMC5326* instance = context;
|
||||
free(instance->encoder.upload);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generating an upload from data.
|
||||
* @param instance Pointer to a SubGhzProtocolEncoderSMC5326 instance
|
||||
* @return true On success
|
||||
*/
|
||||
static bool subghz_protocol_encoder_smc5326_get_upload(SubGhzProtocolEncoderSMC5326* instance) {
|
||||
furi_assert(instance);
|
||||
|
||||
size_t index = 0;
|
||||
size_t size_upload = (instance->generic.data_count_bit * 2) + 2;
|
||||
if(size_upload > instance->encoder.size_upload) {
|
||||
FURI_LOG_E(TAG, "Size upload exceeds allocated encoder buffer.");
|
||||
return false;
|
||||
} else {
|
||||
instance->encoder.size_upload = size_upload;
|
||||
}
|
||||
|
||||
//Send key data
|
||||
for(uint8_t i = instance->generic.data_count_bit; i > 0; i--) {
|
||||
if(bit_read(instance->generic.data, i - 1)) {
|
||||
//send bit 1
|
||||
instance->encoder.upload[index++] =
|
||||
level_duration_make(true, (uint32_t)instance->te * 3);
|
||||
instance->encoder.upload[index++] = level_duration_make(false, (uint32_t)instance->te);
|
||||
} else {
|
||||
//send bit 0
|
||||
instance->encoder.upload[index++] = level_duration_make(true, (uint32_t)instance->te);
|
||||
instance->encoder.upload[index++] =
|
||||
level_duration_make(false, (uint32_t)instance->te * 3);
|
||||
}
|
||||
}
|
||||
|
||||
//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 * 25);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool subghz_protocol_encoder_smc5326_deserialize(void* context, FlipperFormat* flipper_format) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolEncoderSMC5326* instance = context;
|
||||
bool res = false;
|
||||
do {
|
||||
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
|
||||
FURI_LOG_E(TAG, "Deserialize error");
|
||||
break;
|
||||
}
|
||||
if(!flipper_format_rewind(flipper_format)) {
|
||||
FURI_LOG_E(TAG, "Rewind error");
|
||||
break;
|
||||
}
|
||||
if(!flipper_format_read_uint32(flipper_format, "TE", (uint32_t*)&instance->te, 1)) {
|
||||
FURI_LOG_E(TAG, "Missing TE");
|
||||
break;
|
||||
}
|
||||
if(instance->generic.data_count_bit !=
|
||||
subghz_protocol_smc5326_const.min_count_bit_for_found) {
|
||||
FURI_LOG_E(TAG, "Wrong number of bits in key");
|
||||
break;
|
||||
}
|
||||
//optional parameter parameter
|
||||
flipper_format_read_uint32(
|
||||
flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1);
|
||||
|
||||
if(!subghz_protocol_encoder_smc5326_get_upload(instance)) break;
|
||||
instance->encoder.is_running = true;
|
||||
|
||||
res = true;
|
||||
} while(false);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void subghz_protocol_encoder_smc5326_stop(void* context) {
|
||||
SubGhzProtocolEncoderSMC5326* instance = context;
|
||||
instance->encoder.is_running = false;
|
||||
}
|
||||
|
||||
LevelDuration subghz_protocol_encoder_smc5326_yield(void* context) {
|
||||
SubGhzProtocolEncoderSMC5326* instance = context;
|
||||
|
||||
if(instance->encoder.repeat == 0 || !instance->encoder.is_running) {
|
||||
instance->encoder.is_running = false;
|
||||
return level_duration_reset();
|
||||
}
|
||||
|
||||
LevelDuration ret = instance->encoder.upload[instance->encoder.front];
|
||||
|
||||
if(++instance->encoder.front == instance->encoder.size_upload) {
|
||||
instance->encoder.repeat--;
|
||||
instance->encoder.front = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void* subghz_protocol_decoder_smc5326_alloc(SubGhzEnvironment* environment) {
|
||||
UNUSED(environment);
|
||||
SubGhzProtocolDecoderSMC5326* instance = malloc(sizeof(SubGhzProtocolDecoderSMC5326));
|
||||
instance->base.protocol = &subghz_protocol_smc5326;
|
||||
instance->generic.protocol_name = instance->base.protocol->name;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_protocol_decoder_smc5326_free(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderSMC5326* instance = context;
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void subghz_protocol_decoder_smc5326_reset(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderSMC5326* instance = context;
|
||||
instance->decoder.parser_step = SMC5326DecoderStepReset;
|
||||
instance->last_data = 0;
|
||||
}
|
||||
|
||||
void subghz_protocol_decoder_smc5326_feed(void* context, bool level, uint32_t duration) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderSMC5326* instance = context;
|
||||
|
||||
switch(instance->decoder.parser_step) {
|
||||
case SMC5326DecoderStepReset:
|
||||
if((!level) && (DURATION_DIFF(duration, subghz_protocol_smc5326_const.te_short * 24) <
|
||||
subghz_protocol_smc5326_const.te_delta * 12)) {
|
||||
//Found Preambula
|
||||
instance->decoder.parser_step = SMC5326DecoderStepSaveDuration;
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
instance->te = 0;
|
||||
}
|
||||
break;
|
||||
case SMC5326DecoderStepSaveDuration:
|
||||
//save duration
|
||||
if(level) {
|
||||
instance->decoder.te_last = duration;
|
||||
instance->te += duration;
|
||||
instance->decoder.parser_step = SMC5326DecoderStepCheckDuration;
|
||||
}
|
||||
break;
|
||||
case SMC5326DecoderStepCheckDuration:
|
||||
if(!level) {
|
||||
if(duration >= ((uint32_t)subghz_protocol_smc5326_const.te_long * 2)) {
|
||||
instance->decoder.parser_step = SMC5326DecoderStepSaveDuration;
|
||||
if(instance->decoder.decode_count_bit ==
|
||||
subghz_protocol_smc5326_const.min_count_bit_for_found) {
|
||||
if((instance->last_data == instance->decoder.decode_data) &&
|
||||
instance->last_data) {
|
||||
instance->te /= (instance->decoder.decode_count_bit * 4 + 1);
|
||||
|
||||
instance->generic.data = instance->decoder.decode_data;
|
||||
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
|
||||
|
||||
if(instance->base.callback)
|
||||
instance->base.callback(&instance->base, instance->base.context);
|
||||
}
|
||||
instance->last_data = instance->decoder.decode_data;
|
||||
}
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
instance->te = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
instance->te += duration;
|
||||
|
||||
if((DURATION_DIFF(instance->decoder.te_last, subghz_protocol_smc5326_const.te_short) <
|
||||
subghz_protocol_smc5326_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, subghz_protocol_smc5326_const.te_long) <
|
||||
subghz_protocol_smc5326_const.te_delta * 3)) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
||||
instance->decoder.parser_step = SMC5326DecoderStepSaveDuration;
|
||||
} else if(
|
||||
(DURATION_DIFF(instance->decoder.te_last, subghz_protocol_smc5326_const.te_long) <
|
||||
subghz_protocol_smc5326_const.te_delta * 3) &&
|
||||
(DURATION_DIFF(duration, subghz_protocol_smc5326_const.te_short) <
|
||||
subghz_protocol_smc5326_const.te_delta)) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
||||
instance->decoder.parser_step = SMC5326DecoderStepSaveDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = SMC5326DecoderStepReset;
|
||||
}
|
||||
} else {
|
||||
instance->decoder.parser_step = SMC5326DecoderStepReset;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t subghz_protocol_decoder_smc5326_get_hash_data(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderSMC5326* instance = context;
|
||||
return subghz_protocol_blocks_get_hash_data(
|
||||
&instance->decoder, (instance->decoder.decode_count_bit / 8) + 1);
|
||||
}
|
||||
|
||||
bool subghz_protocol_decoder_smc5326_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderSMC5326* instance = context;
|
||||
bool res = subghz_block_generic_serialize(&instance->generic, flipper_format, preset);
|
||||
if(res && !flipper_format_write_uint32(flipper_format, "TE", &instance->te, 1)) {
|
||||
FURI_LOG_E(TAG, "Unable to add TE");
|
||||
res = false;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
bool subghz_protocol_decoder_smc5326_deserialize(void* context, FlipperFormat* flipper_format) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderSMC5326* instance = context;
|
||||
bool res = false;
|
||||
do {
|
||||
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
|
||||
FURI_LOG_E(TAG, "Deserialize error");
|
||||
break;
|
||||
}
|
||||
if(instance->generic.data_count_bit !=
|
||||
subghz_protocol_smc5326_const.min_count_bit_for_found) {
|
||||
FURI_LOG_E(TAG, "Wrong number of bits in key");
|
||||
break;
|
||||
}
|
||||
if(!flipper_format_rewind(flipper_format)) {
|
||||
FURI_LOG_E(TAG, "Rewind error");
|
||||
break;
|
||||
}
|
||||
if(!flipper_format_read_uint32(flipper_format, "TE", (uint32_t*)&instance->te, 1)) {
|
||||
FURI_LOG_E(TAG, "Missing TE");
|
||||
break;
|
||||
}
|
||||
res = true;
|
||||
} while(false);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static void subghz_protocol_smc5326_get_event_serialize(uint8_t event, FuriString* output) {
|
||||
furi_string_cat_printf(
|
||||
output,
|
||||
"%s%s%s%s\r\n",
|
||||
(((event >> 6) & 0x3) == 0x3 ? "B1 " : ""),
|
||||
(((event >> 4) & 0x3) == 0x3 ? "B2 " : ""),
|
||||
(((event >> 2) & 0x3) == 0x3 ? "B3 " : ""),
|
||||
(((event >> 0) & 0x3) == 0x3 ? "B4 " : ""));
|
||||
}
|
||||
|
||||
void subghz_protocol_decoder_smc5326_get_string(void* context, FuriString* output) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderSMC5326* instance = context;
|
||||
uint32_t data = (uint32_t)((instance->generic.data >> 9) & 0xFFFF);
|
||||
|
||||
furi_string_cat_printf(
|
||||
output,
|
||||
"%s %dbit\r\n"
|
||||
"Key:%07lX Te:%ldus\r\n"
|
||||
" +: " DIP_PATTERN "\r\n"
|
||||
" o: " DIP_PATTERN " ",
|
||||
instance->generic.protocol_name,
|
||||
instance->generic.data_count_bit,
|
||||
(uint32_t)(instance->generic.data & 0x1FFFFFF),
|
||||
instance->te,
|
||||
SHOW_DIP_P(data, DIP_P),
|
||||
SHOW_DIP_P(data, DIP_O));
|
||||
subghz_protocol_smc5326_get_event_serialize(instance->generic.data >> 1, output);
|
||||
furi_string_cat_printf(output, " -: " DIP_PATTERN "\r\n", SHOW_DIP_P(data, DIP_N));
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
#pragma once
|
||||
|
||||
#include "base.h"
|
||||
|
||||
#define SUBGHZ_PROTOCOL_SMC5326_NAME "SMC5326"
|
||||
|
||||
typedef struct SubGhzProtocolDecoderSMC5326 SubGhzProtocolDecoderSMC5326;
|
||||
typedef struct SubGhzProtocolEncoderSMC5326 SubGhzProtocolEncoderSMC5326;
|
||||
|
||||
extern const SubGhzProtocolDecoder subghz_protocol_smc5326_decoder;
|
||||
extern const SubGhzProtocolEncoder subghz_protocol_smc5326_encoder;
|
||||
extern const SubGhzProtocol subghz_protocol_smc5326;
|
||||
|
||||
/**
|
||||
* Allocate SubGhzProtocolEncoderSMC5326.
|
||||
* @param environment Pointer to a SubGhzEnvironment instance
|
||||
* @return SubGhzProtocolEncoderSMC5326* pointer to a SubGhzProtocolEncoderSMC5326 instance
|
||||
*/
|
||||
void* subghz_protocol_encoder_smc5326_alloc(SubGhzEnvironment* environment);
|
||||
|
||||
/**
|
||||
* Free SubGhzProtocolEncoderSMC5326.
|
||||
* @param context Pointer to a SubGhzProtocolEncoderSMC5326 instance
|
||||
*/
|
||||
void subghz_protocol_encoder_smc5326_free(void* context);
|
||||
|
||||
/**
|
||||
* Deserialize and generating an upload to send.
|
||||
* @param context Pointer to a SubGhzProtocolEncoderSMC5326 instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @return true On success
|
||||
*/
|
||||
bool subghz_protocol_encoder_smc5326_deserialize(void* context, FlipperFormat* flipper_format);
|
||||
|
||||
/**
|
||||
* Forced transmission stop.
|
||||
* @param context Pointer to a SubGhzProtocolEncoderSMC5326 instance
|
||||
*/
|
||||
void subghz_protocol_encoder_smc5326_stop(void* context);
|
||||
|
||||
/**
|
||||
* Getting the level and duration of the upload to be loaded into DMA.
|
||||
* @param context Pointer to a SubGhzProtocolEncoderSMC5326 instance
|
||||
* @return LevelDuration
|
||||
*/
|
||||
LevelDuration subghz_protocol_encoder_smc5326_yield(void* context);
|
||||
|
||||
/**
|
||||
* Allocate SubGhzProtocolDecoderSMC5326.
|
||||
* @param environment Pointer to a SubGhzEnvironment instance
|
||||
* @return SubGhzProtocolDecoderSMC5326* pointer to a SubGhzProtocolDecoderSMC5326 instance
|
||||
*/
|
||||
void* subghz_protocol_decoder_smc5326_alloc(SubGhzEnvironment* environment);
|
||||
|
||||
/**
|
||||
* Free SubGhzProtocolDecoderSMC5326.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderSMC5326 instance
|
||||
*/
|
||||
void subghz_protocol_decoder_smc5326_free(void* context);
|
||||
|
||||
/**
|
||||
* Reset decoder SubGhzProtocolDecoderSMC5326.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderSMC5326 instance
|
||||
*/
|
||||
void subghz_protocol_decoder_smc5326_reset(void* context);
|
||||
|
||||
/**
|
||||
* Parse a raw sequence of levels and durations received from the air.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderSMC5326 instance
|
||||
* @param level Signal level true-high false-low
|
||||
* @param duration Duration of this level in, us
|
||||
*/
|
||||
void subghz_protocol_decoder_smc5326_feed(void* context, bool level, uint32_t duration);
|
||||
|
||||
/**
|
||||
* Getting the hash sum of the last randomly received parcel.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderSMC5326 instance
|
||||
* @return hash Hash sum
|
||||
*/
|
||||
uint8_t subghz_protocol_decoder_smc5326_get_hash_data(void* context);
|
||||
|
||||
/**
|
||||
* Serialize data SubGhzProtocolDecoderSMC5326.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderSMC5326 instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @param preset The modulation on which the signal was received, SubGhzRadioPreset
|
||||
* @return true On success
|
||||
*/
|
||||
bool subghz_protocol_decoder_smc5326_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset);
|
||||
|
||||
/**
|
||||
* Deserialize data SubGhzProtocolDecoderSMC5326.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderSMC5326 instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @return true On success
|
||||
*/
|
||||
bool subghz_protocol_decoder_smc5326_deserialize(void* context, FlipperFormat* flipper_format);
|
||||
|
||||
/**
|
||||
* Getting a textual representation of the received data.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderSMC5326 instance
|
||||
* @param output Resulting text
|
||||
*/
|
||||
void subghz_protocol_decoder_smc5326_get_string(void* context, FuriString* output);
|
||||
Reference in New Issue
Block a user