2022-10-18 16:51:44 +00:00
|
|
|
#include "magellan.h"
|
2022-08-22 18:01:42 +00:00
|
|
|
|
|
|
|
#include "../blocks/const.h"
|
|
|
|
#include "../blocks/decoder.h"
|
|
|
|
#include "../blocks/encoder.h"
|
|
|
|
#include "../blocks/generic.h"
|
|
|
|
#include "../blocks/math.h"
|
|
|
|
|
2022-10-18 16:51:44 +00:00
|
|
|
#define TAG "SubGhzProtocolMagellan"
|
2022-08-22 18:01:42 +00:00
|
|
|
|
2022-10-18 16:51:44 +00:00
|
|
|
static const SubGhzBlockConst subghz_protocol_magellan_const = {
|
2022-08-22 18:01:42 +00:00
|
|
|
.te_short = 200,
|
|
|
|
.te_long = 400,
|
|
|
|
.te_delta = 100,
|
|
|
|
.min_count_bit_for_found = 32,
|
|
|
|
};
|
|
|
|
|
2022-10-18 16:51:44 +00:00
|
|
|
struct SubGhzProtocolDecoderMagellan {
|
2022-08-22 18:01:42 +00:00
|
|
|
SubGhzProtocolDecoderBase base;
|
|
|
|
|
|
|
|
SubGhzBlockDecoder decoder;
|
|
|
|
SubGhzBlockGeneric generic;
|
|
|
|
uint16_t header_count;
|
|
|
|
};
|
|
|
|
|
2022-10-18 16:51:44 +00:00
|
|
|
struct SubGhzProtocolEncoderMagellan {
|
2022-08-22 18:01:42 +00:00
|
|
|
SubGhzProtocolEncoderBase base;
|
|
|
|
|
|
|
|
SubGhzProtocolBlockEncoder encoder;
|
|
|
|
SubGhzBlockGeneric generic;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef enum {
|
2022-10-18 16:51:44 +00:00
|
|
|
MagellanDecoderStepReset = 0,
|
|
|
|
MagellanDecoderStepCheckPreambula,
|
|
|
|
MagellanDecoderStepFoundPreambula,
|
|
|
|
MagellanDecoderStepSaveDuration,
|
|
|
|
MagellanDecoderStepCheckDuration,
|
|
|
|
} MagellanDecoderStep;
|
|
|
|
|
|
|
|
const SubGhzProtocolDecoder subghz_protocol_magellan_decoder = {
|
|
|
|
.alloc = subghz_protocol_decoder_magellan_alloc,
|
|
|
|
.free = subghz_protocol_decoder_magellan_free,
|
|
|
|
|
|
|
|
.feed = subghz_protocol_decoder_magellan_feed,
|
|
|
|
.reset = subghz_protocol_decoder_magellan_reset,
|
|
|
|
|
|
|
|
.get_hash_data = subghz_protocol_decoder_magellan_get_hash_data,
|
|
|
|
.serialize = subghz_protocol_decoder_magellan_serialize,
|
|
|
|
.deserialize = subghz_protocol_decoder_magellan_deserialize,
|
|
|
|
.get_string = subghz_protocol_decoder_magellan_get_string,
|
2022-08-22 18:01:42 +00:00
|
|
|
};
|
|
|
|
|
2022-10-18 16:51:44 +00:00
|
|
|
const SubGhzProtocolEncoder subghz_protocol_magellan_encoder = {
|
|
|
|
.alloc = subghz_protocol_encoder_magellan_alloc,
|
|
|
|
.free = subghz_protocol_encoder_magellan_free,
|
2022-08-22 18:01:42 +00:00
|
|
|
|
2022-10-18 16:51:44 +00:00
|
|
|
.deserialize = subghz_protocol_encoder_magellan_deserialize,
|
|
|
|
.stop = subghz_protocol_encoder_magellan_stop,
|
|
|
|
.yield = subghz_protocol_encoder_magellan_yield,
|
2022-08-22 18:01:42 +00:00
|
|
|
};
|
|
|
|
|
2022-10-18 16:51:44 +00:00
|
|
|
const SubGhzProtocol subghz_protocol_magellan = {
|
|
|
|
.name = SUBGHZ_PROTOCOL_MAGELLAN_NAME,
|
2022-08-22 18:01:42 +00:00
|
|
|
.type = SubGhzProtocolTypeStatic,
|
|
|
|
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable |
|
|
|
|
SubGhzProtocolFlag_Load | SubGhzProtocolFlag_Save | SubGhzProtocolFlag_Send,
|
|
|
|
|
2022-10-18 16:51:44 +00:00
|
|
|
.decoder = &subghz_protocol_magellan_decoder,
|
|
|
|
.encoder = &subghz_protocol_magellan_encoder,
|
2022-08-22 18:01:42 +00:00
|
|
|
};
|
|
|
|
|
2022-10-18 16:51:44 +00:00
|
|
|
void* subghz_protocol_encoder_magellan_alloc(SubGhzEnvironment* environment) {
|
2022-08-22 18:01:42 +00:00
|
|
|
UNUSED(environment);
|
2022-10-18 16:51:44 +00:00
|
|
|
SubGhzProtocolEncoderMagellan* instance = malloc(sizeof(SubGhzProtocolEncoderMagellan));
|
2022-08-22 18:01:42 +00:00
|
|
|
|
2022-10-18 16:51:44 +00:00
|
|
|
instance->base.protocol = &subghz_protocol_magellan;
|
2022-08-22 18:01:42 +00:00
|
|
|
instance->generic.protocol_name = instance->base.protocol->name;
|
|
|
|
|
|
|
|
instance->encoder.repeat = 10;
|
|
|
|
instance->encoder.size_upload = 256;
|
|
|
|
instance->encoder.upload = malloc(instance->encoder.size_upload * sizeof(LevelDuration));
|
|
|
|
instance->encoder.is_running = false;
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2022-10-18 16:51:44 +00:00
|
|
|
void subghz_protocol_encoder_magellan_free(void* context) {
|
2022-08-22 18:01:42 +00:00
|
|
|
furi_assert(context);
|
2022-10-18 16:51:44 +00:00
|
|
|
SubGhzProtocolEncoderMagellan* instance = context;
|
2022-08-22 18:01:42 +00:00
|
|
|
free(instance->encoder.upload);
|
|
|
|
free(instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generating an upload from data.
|
2022-10-18 16:51:44 +00:00
|
|
|
* @param instance Pointer to a SubGhzProtocolEncoderMagellan instance
|
2022-08-22 18:01:42 +00:00
|
|
|
* @return true On success
|
|
|
|
*/
|
2022-10-18 16:51:44 +00:00
|
|
|
static bool subghz_protocol_encoder_magellan_get_upload(SubGhzProtocolEncoderMagellan* instance) {
|
2022-08-22 18:01:42 +00:00
|
|
|
furi_assert(instance);
|
|
|
|
|
|
|
|
size_t index = 0;
|
|
|
|
|
|
|
|
//Send header
|
|
|
|
instance->encoder.upload[index++] =
|
2022-10-18 16:51:44 +00:00
|
|
|
level_duration_make(true, (uint32_t)subghz_protocol_magellan_const.te_short * 4);
|
2022-08-22 18:01:42 +00:00
|
|
|
instance->encoder.upload[index++] =
|
2022-10-18 16:51:44 +00:00
|
|
|
level_duration_make(false, (uint32_t)subghz_protocol_magellan_const.te_short);
|
2022-08-22 18:01:42 +00:00
|
|
|
for(uint8_t i = 0; i < 12; i++) {
|
|
|
|
instance->encoder.upload[index++] =
|
2022-10-18 16:51:44 +00:00
|
|
|
level_duration_make(true, (uint32_t)subghz_protocol_magellan_const.te_short);
|
2022-08-22 18:01:42 +00:00
|
|
|
instance->encoder.upload[index++] =
|
2022-10-18 16:51:44 +00:00
|
|
|
level_duration_make(false, (uint32_t)subghz_protocol_magellan_const.te_short);
|
2022-08-22 18:01:42 +00:00
|
|
|
}
|
|
|
|
instance->encoder.upload[index++] =
|
2022-10-18 16:51:44 +00:00
|
|
|
level_duration_make(true, (uint32_t)subghz_protocol_magellan_const.te_short);
|
2022-08-22 18:01:42 +00:00
|
|
|
instance->encoder.upload[index++] =
|
2022-10-18 16:51:44 +00:00
|
|
|
level_duration_make(false, (uint32_t)subghz_protocol_magellan_const.te_long);
|
2022-08-22 18:01:42 +00:00
|
|
|
|
|
|
|
//Send start bit
|
|
|
|
instance->encoder.upload[index++] =
|
2022-10-18 16:51:44 +00:00
|
|
|
level_duration_make(true, (uint32_t)subghz_protocol_magellan_const.te_long * 3);
|
2022-08-22 18:01:42 +00:00
|
|
|
instance->encoder.upload[index++] =
|
2022-10-18 16:51:44 +00:00
|
|
|
level_duration_make(false, (uint32_t)subghz_protocol_magellan_const.te_long);
|
2022-08-22 18:01:42 +00:00
|
|
|
|
|
|
|
//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++] =
|
2022-10-18 16:51:44 +00:00
|
|
|
level_duration_make(true, (uint32_t)subghz_protocol_magellan_const.te_short);
|
2022-08-22 18:01:42 +00:00
|
|
|
instance->encoder.upload[index++] =
|
2022-10-18 16:51:44 +00:00
|
|
|
level_duration_make(false, (uint32_t)subghz_protocol_magellan_const.te_long);
|
2022-08-22 18:01:42 +00:00
|
|
|
} else {
|
|
|
|
//send bit 0
|
|
|
|
instance->encoder.upload[index++] =
|
2022-10-18 16:51:44 +00:00
|
|
|
level_duration_make(true, (uint32_t)subghz_protocol_magellan_const.te_long);
|
2022-08-22 18:01:42 +00:00
|
|
|
instance->encoder.upload[index++] =
|
2022-10-18 16:51:44 +00:00
|
|
|
level_duration_make(false, (uint32_t)subghz_protocol_magellan_const.te_short);
|
2022-08-22 18:01:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Send stop bit
|
|
|
|
instance->encoder.upload[index++] =
|
2022-10-18 16:51:44 +00:00
|
|
|
level_duration_make(true, (uint32_t)subghz_protocol_magellan_const.te_short);
|
2022-08-22 18:01:42 +00:00
|
|
|
instance->encoder.upload[index++] =
|
2022-10-18 16:51:44 +00:00
|
|
|
level_duration_make(false, (uint32_t)subghz_protocol_magellan_const.te_long * 100);
|
2022-08-22 18:01:42 +00:00
|
|
|
|
|
|
|
instance->encoder.size_upload = index;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-10-18 16:51:44 +00:00
|
|
|
bool subghz_protocol_encoder_magellan_deserialize(void* context, FlipperFormat* flipper_format) {
|
2022-08-22 18:01:42 +00:00
|
|
|
furi_assert(context);
|
2022-10-18 16:51:44 +00:00
|
|
|
SubGhzProtocolEncoderMagellan* instance = context;
|
2022-08-22 18:01:42 +00:00
|
|
|
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 !=
|
2022-10-18 16:51:44 +00:00
|
|
|
subghz_protocol_magellan_const.min_count_bit_for_found) {
|
2022-08-22 18:01:42 +00:00
|
|
|
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);
|
|
|
|
|
2022-10-18 16:51:44 +00:00
|
|
|
if(!subghz_protocol_encoder_magellan_get_upload(instance)) break;
|
2022-08-22 18:01:42 +00:00
|
|
|
instance->encoder.is_running = true;
|
|
|
|
|
|
|
|
res = true;
|
|
|
|
} while(false);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2022-10-18 16:51:44 +00:00
|
|
|
void subghz_protocol_encoder_magellan_stop(void* context) {
|
|
|
|
SubGhzProtocolEncoderMagellan* instance = context;
|
2022-08-22 18:01:42 +00:00
|
|
|
instance->encoder.is_running = false;
|
|
|
|
}
|
|
|
|
|
2022-10-18 16:51:44 +00:00
|
|
|
LevelDuration subghz_protocol_encoder_magellan_yield(void* context) {
|
|
|
|
SubGhzProtocolEncoderMagellan* instance = context;
|
2022-08-22 18:01:42 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-10-18 16:51:44 +00:00
|
|
|
void* subghz_protocol_decoder_magellan_alloc(SubGhzEnvironment* environment) {
|
2022-08-22 18:01:42 +00:00
|
|
|
UNUSED(environment);
|
2022-10-18 16:51:44 +00:00
|
|
|
SubGhzProtocolDecoderMagellan* instance = malloc(sizeof(SubGhzProtocolDecoderMagellan));
|
|
|
|
instance->base.protocol = &subghz_protocol_magellan;
|
2022-08-22 18:01:42 +00:00
|
|
|
instance->generic.protocol_name = instance->base.protocol->name;
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2022-10-18 16:51:44 +00:00
|
|
|
void subghz_protocol_decoder_magellan_free(void* context) {
|
2022-08-22 18:01:42 +00:00
|
|
|
furi_assert(context);
|
2022-10-18 16:51:44 +00:00
|
|
|
SubGhzProtocolDecoderMagellan* instance = context;
|
2022-08-22 18:01:42 +00:00
|
|
|
free(instance);
|
|
|
|
}
|
|
|
|
|
2022-10-18 16:51:44 +00:00
|
|
|
void subghz_protocol_decoder_magellan_reset(void* context) {
|
2022-08-22 18:01:42 +00:00
|
|
|
furi_assert(context);
|
2022-10-18 16:51:44 +00:00
|
|
|
SubGhzProtocolDecoderMagellan* instance = context;
|
|
|
|
instance->decoder.parser_step = MagellanDecoderStepReset;
|
2022-08-22 18:01:42 +00:00
|
|
|
}
|
|
|
|
|
2022-10-18 16:51:44 +00:00
|
|
|
uint8_t subghz_protocol_magellan_crc8(uint8_t* data, size_t len) {
|
2022-08-22 18:01:42 +00:00
|
|
|
uint8_t crc = 0x00;
|
|
|
|
size_t i, j;
|
|
|
|
for(i = 0; i < len; i++) {
|
|
|
|
crc ^= data[i];
|
|
|
|
for(j = 0; j < 8; j++) {
|
|
|
|
if((crc & 0x80) != 0)
|
|
|
|
crc = (uint8_t)((crc << 1) ^ 0x31);
|
|
|
|
else
|
|
|
|
crc <<= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return crc;
|
|
|
|
}
|
|
|
|
|
2022-10-18 16:51:44 +00:00
|
|
|
static bool subghz_protocol_magellan_check_crc(SubGhzProtocolDecoderMagellan* instance) {
|
2022-08-22 18:01:42 +00:00
|
|
|
uint8_t data[3] = {
|
|
|
|
instance->decoder.decode_data >> 24,
|
|
|
|
instance->decoder.decode_data >> 16,
|
|
|
|
instance->decoder.decode_data >> 8};
|
|
|
|
return (instance->decoder.decode_data & 0xFF) ==
|
2022-10-18 16:51:44 +00:00
|
|
|
subghz_protocol_magellan_crc8(data, sizeof(data));
|
2022-08-22 18:01:42 +00:00
|
|
|
}
|
|
|
|
|
2022-10-18 16:51:44 +00:00
|
|
|
void subghz_protocol_decoder_magellan_feed(void* context, bool level, uint32_t duration) {
|
2022-08-22 18:01:42 +00:00
|
|
|
furi_assert(context);
|
2022-10-18 16:51:44 +00:00
|
|
|
SubGhzProtocolDecoderMagellan* instance = context;
|
2022-08-22 18:01:42 +00:00
|
|
|
|
|
|
|
switch(instance->decoder.parser_step) {
|
2022-10-18 16:51:44 +00:00
|
|
|
case MagellanDecoderStepReset:
|
|
|
|
if((level) && (DURATION_DIFF(duration, subghz_protocol_magellan_const.te_short) <
|
|
|
|
subghz_protocol_magellan_const.te_delta)) {
|
|
|
|
instance->decoder.parser_step = MagellanDecoderStepCheckPreambula;
|
2022-08-22 18:01:42 +00:00
|
|
|
instance->decoder.te_last = duration;
|
|
|
|
instance->header_count = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-18 16:51:44 +00:00
|
|
|
case MagellanDecoderStepCheckPreambula:
|
2022-08-22 18:01:42 +00:00
|
|
|
if(level) {
|
|
|
|
instance->decoder.te_last = duration;
|
|
|
|
} else {
|
2022-10-18 16:51:44 +00:00
|
|
|
if((DURATION_DIFF(instance->decoder.te_last, subghz_protocol_magellan_const.te_short) <
|
|
|
|
subghz_protocol_magellan_const.te_delta) &&
|
|
|
|
(DURATION_DIFF(duration, subghz_protocol_magellan_const.te_short) <
|
|
|
|
subghz_protocol_magellan_const.te_delta)) {
|
2022-08-22 18:01:42 +00:00
|
|
|
// Found header
|
|
|
|
instance->header_count++;
|
|
|
|
} else if(
|
2022-10-18 16:51:44 +00:00
|
|
|
(DURATION_DIFF(instance->decoder.te_last, subghz_protocol_magellan_const.te_short) <
|
|
|
|
subghz_protocol_magellan_const.te_delta) &&
|
|
|
|
(DURATION_DIFF(duration, subghz_protocol_magellan_const.te_long) <
|
|
|
|
subghz_protocol_magellan_const.te_delta * 2) &&
|
2022-08-22 18:01:42 +00:00
|
|
|
(instance->header_count > 10)) {
|
2022-10-18 16:51:44 +00:00
|
|
|
instance->decoder.parser_step = MagellanDecoderStepFoundPreambula;
|
2022-08-22 18:01:42 +00:00
|
|
|
} else {
|
2022-10-18 16:51:44 +00:00
|
|
|
instance->decoder.parser_step = MagellanDecoderStepReset;
|
2022-08-22 18:01:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-18 16:51:44 +00:00
|
|
|
case MagellanDecoderStepFoundPreambula:
|
2022-08-22 18:01:42 +00:00
|
|
|
if(level) {
|
|
|
|
instance->decoder.te_last = duration;
|
|
|
|
} else {
|
|
|
|
if((DURATION_DIFF(
|
2022-10-18 16:51:44 +00:00
|
|
|
instance->decoder.te_last, subghz_protocol_magellan_const.te_short * 6) <
|
|
|
|
subghz_protocol_magellan_const.te_delta * 3) &&
|
|
|
|
(DURATION_DIFF(duration, subghz_protocol_magellan_const.te_long) <
|
|
|
|
subghz_protocol_magellan_const.te_delta * 2)) {
|
|
|
|
instance->decoder.parser_step = MagellanDecoderStepSaveDuration;
|
2022-08-22 18:01:42 +00:00
|
|
|
instance->decoder.decode_data = 0;
|
|
|
|
instance->decoder.decode_count_bit = 0;
|
|
|
|
} else {
|
2022-10-18 16:51:44 +00:00
|
|
|
instance->decoder.parser_step = MagellanDecoderStepReset;
|
2022-08-22 18:01:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-18 16:51:44 +00:00
|
|
|
case MagellanDecoderStepSaveDuration:
|
2022-08-22 18:01:42 +00:00
|
|
|
if(level) {
|
|
|
|
instance->decoder.te_last = duration;
|
2022-10-18 16:51:44 +00:00
|
|
|
instance->decoder.parser_step = MagellanDecoderStepCheckDuration;
|
2022-08-22 18:01:42 +00:00
|
|
|
} else {
|
2022-10-18 16:51:44 +00:00
|
|
|
instance->decoder.parser_step = MagellanDecoderStepReset;
|
2022-08-22 18:01:42 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-10-18 16:51:44 +00:00
|
|
|
case MagellanDecoderStepCheckDuration:
|
2022-08-22 18:01:42 +00:00
|
|
|
if(!level) {
|
2022-10-18 16:51:44 +00:00
|
|
|
if((DURATION_DIFF(instance->decoder.te_last, subghz_protocol_magellan_const.te_short) <
|
|
|
|
subghz_protocol_magellan_const.te_delta) &&
|
|
|
|
(DURATION_DIFF(duration, subghz_protocol_magellan_const.te_long) <
|
|
|
|
subghz_protocol_magellan_const.te_delta)) {
|
2022-08-22 18:01:42 +00:00
|
|
|
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
2022-10-18 16:51:44 +00:00
|
|
|
instance->decoder.parser_step = MagellanDecoderStepSaveDuration;
|
2022-08-22 18:01:42 +00:00
|
|
|
} else if(
|
2022-10-18 16:51:44 +00:00
|
|
|
(DURATION_DIFF(instance->decoder.te_last, subghz_protocol_magellan_const.te_long) <
|
|
|
|
subghz_protocol_magellan_const.te_delta) &&
|
|
|
|
(DURATION_DIFF(duration, subghz_protocol_magellan_const.te_short) <
|
|
|
|
subghz_protocol_magellan_const.te_delta)) {
|
2022-08-22 18:01:42 +00:00
|
|
|
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
2022-10-18 16:51:44 +00:00
|
|
|
instance->decoder.parser_step = MagellanDecoderStepSaveDuration;
|
|
|
|
} else if(duration >= (subghz_protocol_magellan_const.te_long * 3)) {
|
2022-08-22 18:01:42 +00:00
|
|
|
//Found stop bit
|
|
|
|
if((instance->decoder.decode_count_bit ==
|
2022-10-18 16:51:44 +00:00
|
|
|
subghz_protocol_magellan_const.min_count_bit_for_found) &&
|
|
|
|
subghz_protocol_magellan_check_crc(instance)) {
|
2022-08-22 18:01:42 +00:00
|
|
|
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->decoder.decode_data = 0;
|
|
|
|
instance->decoder.decode_count_bit = 0;
|
2022-10-18 16:51:44 +00:00
|
|
|
instance->decoder.parser_step = MagellanDecoderStepReset;
|
2022-08-22 18:01:42 +00:00
|
|
|
} else {
|
2022-10-18 16:51:44 +00:00
|
|
|
instance->decoder.parser_step = MagellanDecoderStepReset;
|
2022-08-22 18:01:42 +00:00
|
|
|
}
|
|
|
|
} else {
|
2022-10-18 16:51:44 +00:00
|
|
|
instance->decoder.parser_step = MagellanDecoderStepReset;
|
2022-08-22 18:01:42 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Analysis of received data
|
|
|
|
* @param instance Pointer to a SubGhzBlockGeneric* instance
|
|
|
|
*/
|
2022-10-18 16:51:44 +00:00
|
|
|
static void subghz_protocol_magellan_check_remote_controller(SubGhzBlockGeneric* instance) {
|
2022-08-22 18:01:42 +00:00
|
|
|
/*
|
|
|
|
* package 32b data 24b CRC8
|
|
|
|
* 0x037AE4828 => 001101111010111001001000 00101000
|
|
|
|
*
|
|
|
|
* 0x037AE48 (flipped in reverse bit sequence) => 0x1275EC
|
|
|
|
*
|
|
|
|
* 0x1275EC => 0x12-event codes, 0x75EC-serial (dec 117236)
|
|
|
|
*
|
|
|
|
* event codes
|
2022-08-31 14:27:34 +00:00
|
|
|
* bit_0: 1-Open/Motion, 0-close/ok
|
2022-08-22 18:01:42 +00:00
|
|
|
* bit_1: 1-Tamper On (alarm), 0-Tamper Off (ok)
|
|
|
|
* bit_2: ?
|
|
|
|
* bit_3: 1-power on
|
2022-08-31 14:27:34 +00:00
|
|
|
* bit_4: model type - wireless reed
|
2022-08-22 18:01:42 +00:00
|
|
|
* bit_5: model type - motion sensor
|
|
|
|
* bit_6: ?
|
|
|
|
* bit_7: ?
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
uint64_t data_rev = subghz_protocol_blocks_reverse_key(instance->data >> 8, 24);
|
|
|
|
instance->serial = data_rev & 0xFFFF;
|
|
|
|
instance->btn = (data_rev >> 16) & 0xFF;
|
|
|
|
}
|
|
|
|
|
2022-10-18 16:51:44 +00:00
|
|
|
static void subghz_protocol_magellan_get_event_serialize(uint8_t event, FuriString* output) {
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_cat_printf(
|
2022-08-22 18:01:42 +00:00
|
|
|
output,
|
|
|
|
"%s%s%s%s%s%s%s%s",
|
2022-08-31 14:27:34 +00:00
|
|
|
((event >> 4) & 0x1 ? (event & 0x1 ? " Open" : " Close") :
|
|
|
|
(event & 0x1 ? " Motion" : " Ok")),
|
2022-09-25 14:34:52 +00:00
|
|
|
((event >> 1) & 0x1 ? ", Tamper On\n(Alarm)" : ""),
|
2022-08-22 18:01:42 +00:00
|
|
|
((event >> 2) & 0x1 ? ", ?" : ""),
|
|
|
|
((event >> 3) & 0x1 ? ", Power On" : ""),
|
2022-08-31 14:27:34 +00:00
|
|
|
((event >> 4) & 0x1 ? ", MT:Wireless_Reed" : ""),
|
2022-08-22 18:01:42 +00:00
|
|
|
((event >> 5) & 0x1 ? ", MT:Motion_Sensor" : ""),
|
|
|
|
((event >> 6) & 0x1 ? ", ?" : ""),
|
|
|
|
((event >> 7) & 0x1 ? ", ?" : ""));
|
|
|
|
}
|
|
|
|
|
2022-10-18 16:51:44 +00:00
|
|
|
uint8_t subghz_protocol_decoder_magellan_get_hash_data(void* context) {
|
2022-08-22 18:01:42 +00:00
|
|
|
furi_assert(context);
|
2022-10-18 16:51:44 +00:00
|
|
|
SubGhzProtocolDecoderMagellan* instance = context;
|
2022-08-22 18:01:42 +00:00
|
|
|
return subghz_protocol_blocks_get_hash_data(
|
|
|
|
&instance->decoder, (instance->decoder.decode_count_bit / 8) + 1);
|
|
|
|
}
|
|
|
|
|
2022-10-18 16:51:44 +00:00
|
|
|
bool subghz_protocol_decoder_magellan_serialize(
|
2022-08-22 18:01:42 +00:00
|
|
|
void* context,
|
|
|
|
FlipperFormat* flipper_format,
|
2022-10-19 15:52:21 +00:00
|
|
|
SubGhzRadioPreset* preset) {
|
2022-08-22 18:01:42 +00:00
|
|
|
furi_assert(context);
|
2022-10-18 16:51:44 +00:00
|
|
|
SubGhzProtocolDecoderMagellan* instance = context;
|
2022-08-22 18:01:42 +00:00
|
|
|
return subghz_block_generic_serialize(&instance->generic, flipper_format, preset);
|
|
|
|
}
|
|
|
|
|
2022-10-18 16:51:44 +00:00
|
|
|
bool subghz_protocol_decoder_magellan_deserialize(void* context, FlipperFormat* flipper_format) {
|
2022-08-22 18:01:42 +00:00
|
|
|
furi_assert(context);
|
2022-10-18 16:51:44 +00:00
|
|
|
SubGhzProtocolDecoderMagellan* instance = context;
|
2022-08-22 18:01:42 +00:00
|
|
|
bool ret = false;
|
|
|
|
do {
|
|
|
|
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(instance->generic.data_count_bit !=
|
2022-10-18 16:51:44 +00:00
|
|
|
subghz_protocol_magellan_const.min_count_bit_for_found) {
|
2022-08-22 18:01:42 +00:00
|
|
|
FURI_LOG_E(TAG, "Wrong number of bits in key");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ret = true;
|
|
|
|
} while(false);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-10-18 16:51:44 +00:00
|
|
|
void subghz_protocol_decoder_magellan_get_string(void* context, FuriString* output) {
|
2022-08-22 18:01:42 +00:00
|
|
|
furi_assert(context);
|
2022-10-18 16:51:44 +00:00
|
|
|
SubGhzProtocolDecoderMagellan* instance = context;
|
|
|
|
subghz_protocol_magellan_check_remote_controller(&instance->generic);
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_cat_printf(
|
2022-08-22 18:01:42 +00:00
|
|
|
output,
|
|
|
|
"%s %dbit\r\n"
|
|
|
|
"Key:0x%08lX\r\n"
|
2022-10-07 13:35:15 +00:00
|
|
|
"Sn:%03ld%03ld, Event:0x%02X\r\n"
|
2022-08-22 18:01:42 +00:00
|
|
|
"Stat:",
|
|
|
|
instance->generic.protocol_name,
|
|
|
|
instance->generic.data_count_bit,
|
|
|
|
(uint32_t)(instance->generic.data & 0xFFFFFFFF),
|
|
|
|
(instance->generic.serial >> 8) & 0xFF,
|
|
|
|
instance->generic.serial & 0xFF,
|
|
|
|
instance->generic.btn);
|
|
|
|
|
2022-10-18 16:51:44 +00:00
|
|
|
subghz_protocol_magellan_get_event_serialize(instance->generic.btn, output);
|
2022-08-22 18:01:42 +00:00
|
|
|
}
|