mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
Merge remote-tracking branch 'ul/dev' into mntm-dev
This commit is contained in:
@@ -220,8 +220,10 @@ static void subghz_protocol_encoder_came_atomo_get_upload(
|
||||
instance->encoder.upload[index++] =
|
||||
level_duration_make(false, (uint32_t)subghz_protocol_came_atomo_const.te_long * 60);
|
||||
|
||||
// Btn counter 0x0 - 0x7F
|
||||
pack[0] = 0;
|
||||
for(uint8_t i = 0; i < 8; i++) {
|
||||
pack[0] = (instance->generic.data_2 >> 56);
|
||||
//pack[0] = (instance->generic.data_2 >> 56);
|
||||
pack[1] = (instance->generic.cnt >> 8);
|
||||
pack[2] = (instance->generic.cnt & 0xFF);
|
||||
pack[3] = ((instance->generic.data_2 >> 32) & 0xFF);
|
||||
@@ -230,11 +232,42 @@ static void subghz_protocol_encoder_came_atomo_get_upload(
|
||||
pack[6] = ((instance->generic.data_2 >> 8) & 0xFF);
|
||||
pack[7] = (btn << 4);
|
||||
|
||||
if(pack[0] == 0x7F) {
|
||||
/* if(pack[0] == 0x7F) {
|
||||
pack[0] = 0;
|
||||
} else {
|
||||
pack[0] += (i + 1);
|
||||
}
|
||||
*/
|
||||
switch(i) {
|
||||
case 0:
|
||||
pack[0] = 10; // 0A
|
||||
break;
|
||||
case 1:
|
||||
pack[0] = 30;
|
||||
break;
|
||||
case 2:
|
||||
pack[0] = 125; // 7D
|
||||
break;
|
||||
case 3:
|
||||
pack[0] = 126; // 7E
|
||||
break;
|
||||
case 4:
|
||||
pack[0] = 127; // 7F
|
||||
break;
|
||||
case 5:
|
||||
pack[0] = 0; // 00
|
||||
break;
|
||||
case 6:
|
||||
pack[0] = 1; // 01
|
||||
break;
|
||||
case 7:
|
||||
pack[0] = 3;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// 10 50 125 126 127 0 1 2
|
||||
|
||||
atomo_encrypt(pack);
|
||||
uint32_t hi = pack[0] << 24 | pack[1] << 16 | pack[2] << 8 | pack[3];
|
||||
@@ -523,7 +556,8 @@ static void subghz_protocol_came_atomo_remote_controller(SubGhzBlockGeneric* ins
|
||||
* 0x931dfb16c0b1 ^ 0xXXXXXXXXXXXXXXXX = 0xEF3ED0F7D9EF
|
||||
* 0xEF3 ED0F7D9E F => 0xEF3 - CNT, 0xED0F7D9E - SN, 0xF - key
|
||||
*
|
||||
* ***Eng1n33r ver. (actual)***
|
||||
* ***Actual***
|
||||
* Button hold-cycle counter (8-bit, from 0 to 0x7F) should DO full cycle or half cycle keeping values like zero
|
||||
* 0x1FF08D9924984115 - received data
|
||||
* 0x00F7266DB67BEEA0 - inverted data
|
||||
* 0x0501FD0000A08300 - decrypted data,
|
||||
@@ -722,7 +756,7 @@ void subghz_protocol_decoder_came_atomo_get_string(void* context, FuriString* ou
|
||||
"%s %db\r\n"
|
||||
"Key:%08lX%08lX\r\n"
|
||||
"Sn:0x%08lX Btn:%01X\r\n"
|
||||
"Pcl_Cnt:0x%04lX\r\n"
|
||||
"Cnt:0x%04lX\r\n"
|
||||
"Btn_Cnt:0x%02X",
|
||||
|
||||
instance->generic.protocol_name,
|
||||
|
||||
@@ -170,13 +170,14 @@ static void subghz_protocol_encoder_gangqi_get_upload(SubGhzProtocolEncoderGangQ
|
||||
// Generate new key using custom or default button
|
||||
instance->generic.btn = subghz_protocol_gangqi_get_btn_code();
|
||||
|
||||
uint64_t new_key = (instance->generic.data >> 14) << 14 | (instance->generic.btn << 10) |
|
||||
(0b01 << 8);
|
||||
uint16_t serial = (uint16_t)((instance->generic.data >> 18) & 0xFFFF);
|
||||
uint8_t const_and_button = (uint8_t)(0xD0 | instance->generic.btn);
|
||||
uint8_t serial_high = (uint8_t)(serial >> 8);
|
||||
uint8_t serial_low = (uint8_t)(serial & 0xFF);
|
||||
uint8_t bytesum = (uint8_t)(0xC8 - serial_high - serial_low - const_and_button);
|
||||
|
||||
uint8_t crc = -0xD7 - ((new_key >> 32) & 0xFF) - ((new_key >> 24) & 0xFF) -
|
||||
((new_key >> 16) & 0xFF) - ((new_key >> 8) & 0xFF);
|
||||
|
||||
instance->generic.data = (new_key | crc);
|
||||
instance->generic.data = (instance->generic.data >> 14) << 14 | (instance->generic.btn << 10) |
|
||||
(bytesum << 2);
|
||||
|
||||
size_t index = 0;
|
||||
|
||||
@@ -232,41 +233,12 @@ static void subghz_protocol_gangqi_remote_controller(SubGhzBlockGeneric* instanc
|
||||
subghz_custom_btn_set_max(3);
|
||||
|
||||
// GangQi Decoder
|
||||
// 09.2024 - @xMasterX (MMX)
|
||||
// 09.2024 - @xMasterX (MMX) (last update - bytesum calculation at 02.2025)
|
||||
// Thanks @Skorpionm for support!
|
||||
// Thanks @Drone1950 and @mishamyte (who spent 2 weeks on this) for making this work properly
|
||||
|
||||
//// 4D=F8=171=229 byte sum should be always the same
|
||||
// Button
|
||||
// Serial || BBBB || CRC (byte sum) with overflow and starting point 0xD7
|
||||
//034AAB75BC = 00110100101010101011 01 1101 01 101111 00 // A (0xD)
|
||||
//034AAB79B8 = 00110100101010101011 01 1110 01 101110 00 // B (0xE)
|
||||
//034AAB6DC4 = 00110100101010101011 01 1011 01 110001 00 // C (0xB)
|
||||
//034AAB5DD4 = 00110100101010101011 01 0111 01 110101 00 // D (0x7)
|
||||
//034AAB55DC = 00110100101010101011 01 0101 01 110111 00 // Settings (0x5)
|
||||
//034AAB51E0 = 00110100101010101011 01 0100 01 111000 00 // A (0x4)
|
||||
//034AAB49E8 = 00110100101010101011 01 0010 01 111010 00 // C (0x2)
|
||||
//034AAB59D8 = 00110100101010101011 01 0110 01 110110 00 // D (0x6)
|
||||
//034AAB45EC = 00110100101010101011 01 0001 01 111011 00 // Settings exit (0x1)
|
||||
//
|
||||
// Serial 3 bytes should meet requirements see validation example at subghz_protocol_decoder_gangqi_get_string
|
||||
//
|
||||
// Code for finding start byte for crc sum
|
||||
//
|
||||
//uint64_t test = 0x034AAB79B8; //B8
|
||||
//for(size_t byte = 0; byte < 0xFF; ++byte) {
|
||||
// uint8_t crc_res = -byte - ((test >> 32) & 0xFF) - ((test >> 24) & 0xFF) -
|
||||
// ((test >> 16) & 0xFF) - ((test >> 8) & 0xFF);
|
||||
// if(crc_res == 0xB8) {
|
||||
// uint64_t test2 = 0x034AAB6DC4; //C4
|
||||
// uint8_t crc_res2 = -byte - ((test2 >> 32) & 0xFF) - ((test2 >> 24) & 0xFF) -
|
||||
// ((test2 >> 16) & 0xFF) - ((test2 >> 8) & 0xFF);
|
||||
// if(crc_res2 == 0xC4) {
|
||||
// printf("Start byte for CRC = %02lX / CRC = %02X \n", byte, crc_res);
|
||||
//
|
||||
// printf("Testing second parcel CRC = %02X", crc_res2);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// Example of correct bytesum calculation
|
||||
// 0xC8 - serial_high - serial_low - constant_and_button
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus
|
||||
@@ -485,23 +457,29 @@ void subghz_protocol_decoder_gangqi_get_string(void* context, FuriString* output
|
||||
// Parse serial
|
||||
subghz_protocol_gangqi_remote_controller(&instance->generic);
|
||||
|
||||
// Get CRC
|
||||
uint8_t crc = -0xD7 - ((instance->generic.data >> 32) & 0xFF) -
|
||||
((instance->generic.data >> 24) & 0xFF) -
|
||||
((instance->generic.data >> 16) & 0xFF) - ((instance->generic.data >> 8) & 0xFF);
|
||||
// Get byte sum
|
||||
uint16_t serial = (uint16_t)((instance->generic.data >> 18) & 0xFFFF);
|
||||
uint8_t const_and_button = (uint8_t)(0xD0 | instance->generic.btn);
|
||||
uint8_t serial_high = (uint8_t)(serial >> 8);
|
||||
uint8_t serial_low = (uint8_t)(serial & 0xFF);
|
||||
// Type 1 is what original remotes use, type 2 is "backdoor" sum that receiver accepts too
|
||||
uint8_t sum_type1 = (uint8_t)(0xC8 - serial_high - serial_low - const_and_button);
|
||||
uint8_t sum_type2 = (uint8_t)(0x02 + serial_high + serial_low + const_and_button);
|
||||
|
||||
furi_string_cat_printf(
|
||||
output,
|
||||
"%s %db\r\n"
|
||||
"Key: 0x%X%08lX\r\n"
|
||||
"Serial: 0x%05lX CRC: 0x%02X\r\n"
|
||||
"Serial: 0x%05lX\r\n"
|
||||
"Sum: 0x%02X Sum2: 0x%02X\r\n"
|
||||
"Btn: 0x%01X - %s\r\n",
|
||||
instance->generic.protocol_name,
|
||||
instance->generic.data_count_bit,
|
||||
(uint8_t)(instance->generic.data >> 32),
|
||||
(uint32_t)(instance->generic.data & 0xFFFFFFFF),
|
||||
instance->generic.serial,
|
||||
crc,
|
||||
sum_type1,
|
||||
sum_type2,
|
||||
instance->generic.btn,
|
||||
subghz_protocol_gangqi_get_button_name(instance->generic.btn));
|
||||
}
|
||||
|
||||
@@ -171,10 +171,10 @@ static void subghz_protocol_encoder_hollarm_get_upload(SubGhzProtocolEncoderHoll
|
||||
|
||||
uint64_t new_key = (instance->generic.data >> 12) << 12 | (instance->generic.btn << 8);
|
||||
|
||||
uint8_t crc = ((new_key >> 32) & 0xFF) + ((new_key >> 24) & 0xFF) + ((new_key >> 16) & 0xFF) +
|
||||
((new_key >> 8) & 0xFF);
|
||||
uint8_t bytesum = ((new_key >> 32) & 0xFF) + ((new_key >> 24) & 0xFF) +
|
||||
((new_key >> 16) & 0xFF) + ((new_key >> 8) & 0xFF);
|
||||
|
||||
instance->generic.data = (new_key | crc);
|
||||
instance->generic.data = (new_key | bytesum);
|
||||
|
||||
size_t index = 0;
|
||||
|
||||
@@ -235,7 +235,7 @@ static void subghz_protocol_hollarm_remote_controller(SubGhzBlockGeneric* instan
|
||||
// F0B9342401 = 01 8bit Sum
|
||||
// F0B9342805 = 05 8bit Sum
|
||||
|
||||
// Serial (moved 2bit to right) | Btn | 8b CRC (previous 4 bytes sum)
|
||||
// Serial (moved 2bit to right) | Btn | 8b previous 4 bytes sum
|
||||
// 00001111000010111001001101000010 0010 11111111 btn = (0x2)
|
||||
// 00001111000010111001001101000010 0001 11111110 btn = (0x1)
|
||||
// 00001111000010111001001101000010 0100 00000001 btn = (0x4)
|
||||
@@ -378,6 +378,21 @@ void subghz_protocol_decoder_hollarm_feed(void* context, bool level, volatile ui
|
||||
// Saving with 2bit to the right offset for proper parsing
|
||||
instance->generic.data = (instance->decoder.decode_data >> 2);
|
||||
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
|
||||
|
||||
uint8_t bytesum = ((instance->generic.data >> 32) & 0xFF) +
|
||||
((instance->generic.data >> 24) & 0xFF) +
|
||||
((instance->generic.data >> 16) & 0xFF) +
|
||||
((instance->generic.data >> 8) & 0xFF);
|
||||
|
||||
if(bytesum != (instance->generic.data & 0xFF)) {
|
||||
// Check if the key is valid by verifying the sum
|
||||
instance->generic.data = 0;
|
||||
instance->generic.data_count_bit = 0;
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
instance->decoder.parser_step = HollarmDecoderStepReset;
|
||||
break;
|
||||
}
|
||||
if(instance->base.callback)
|
||||
instance->base.callback(&instance->base, instance->base.context);
|
||||
}
|
||||
@@ -449,23 +464,23 @@ void subghz_protocol_decoder_hollarm_get_string(void* context, FuriString* outpu
|
||||
|
||||
// Parse serial
|
||||
subghz_protocol_hollarm_remote_controller(&instance->generic);
|
||||
// Get CRC
|
||||
uint8_t crc = ((instance->generic.data >> 32) & 0xFF) +
|
||||
((instance->generic.data >> 24) & 0xFF) +
|
||||
((instance->generic.data >> 16) & 0xFF) + ((instance->generic.data >> 8) & 0xFF);
|
||||
// Get byte sum
|
||||
uint8_t bytesum =
|
||||
((instance->generic.data >> 32) & 0xFF) + ((instance->generic.data >> 24) & 0xFF) +
|
||||
((instance->generic.data >> 16) & 0xFF) + ((instance->generic.data >> 8) & 0xFF);
|
||||
|
||||
furi_string_cat_printf(
|
||||
output,
|
||||
"%s %db\r\n"
|
||||
"Key: 0x%02lX%08lX\r\n"
|
||||
"Serial: 0x%06lX CRC: %02X\r\n"
|
||||
"Serial: 0x%06lX Sum: %02X\r\n"
|
||||
"Btn: 0x%01X - %s\r\n",
|
||||
instance->generic.protocol_name,
|
||||
instance->generic.data_count_bit,
|
||||
(uint32_t)(instance->generic.data >> 32),
|
||||
(uint32_t)instance->generic.data,
|
||||
instance->generic.serial,
|
||||
crc,
|
||||
bytesum,
|
||||
instance->generic.btn,
|
||||
subghz_protocol_hollarm_get_button_name(instance->generic.btn));
|
||||
}
|
||||
|
||||
@@ -216,6 +216,9 @@ void subghz_protocol_decoder_marantec24_feed(void* context, bool level, volatile
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderMarantec24* instance = context;
|
||||
|
||||
// Marantec24 Decoder
|
||||
// 2024 - @xMasterX (MMX)
|
||||
|
||||
// Key samples
|
||||
// 101011000000010111001000 = AC05C8
|
||||
// 101011000000010111000100 = AC05C4
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "protocol_items.h" // IWYU pragma: keep
|
||||
|
||||
const SubGhzProtocol* subghz_protocol_registry_items[] = {
|
||||
const SubGhzProtocol* const subghz_protocol_registry_items[] = {
|
||||
&subghz_protocol_gate_tx,
|
||||
&subghz_protocol_keeloq,
|
||||
&subghz_protocol_star_line,
|
||||
@@ -80,6 +80,7 @@ const SubGhzProtocol* subghz_protocol_registry_items[] = {
|
||||
&subghz_protocol_marantec24,
|
||||
&subghz_protocol_hollarm,
|
||||
&subghz_protocol_hay21,
|
||||
&subghz_protocol_revers_rb2,
|
||||
};
|
||||
|
||||
const SubGhzProtocolRegistry subghz_protocol_registry = {
|
||||
|
||||
@@ -81,3 +81,4 @@
|
||||
#include "marantec24.h"
|
||||
#include "hollarm.h"
|
||||
#include "hay21.h"
|
||||
#include "revers_rb2.h"
|
||||
|
||||
408
lib/subghz/protocols/revers_rb2.c
Normal file
408
lib/subghz/protocols/revers_rb2.c
Normal file
@@ -0,0 +1,408 @@
|
||||
#include "revers_rb2.h"
|
||||
#include <lib/toolbox/manchester_decoder.h>
|
||||
#include <lib/toolbox/manchester_encoder.h>
|
||||
#include "../blocks/const.h"
|
||||
#include "../blocks/decoder.h"
|
||||
#include "../blocks/encoder.h"
|
||||
#include "../blocks/generic.h"
|
||||
#include "../blocks/math.h"
|
||||
|
||||
#define TAG "SubGhzProtocolRevers_RB2"
|
||||
|
||||
static const SubGhzBlockConst subghz_protocol_revers_rb2_const = {
|
||||
.te_short = 250,
|
||||
.te_long = 500,
|
||||
.te_delta = 160,
|
||||
.min_count_bit_for_found = 64,
|
||||
};
|
||||
|
||||
struct SubGhzProtocolDecoderRevers_RB2 {
|
||||
SubGhzProtocolDecoderBase base;
|
||||
|
||||
SubGhzBlockDecoder decoder;
|
||||
SubGhzBlockGeneric generic;
|
||||
ManchesterState manchester_saved_state;
|
||||
uint16_t header_count;
|
||||
};
|
||||
|
||||
struct SubGhzProtocolEncoderRevers_RB2 {
|
||||
SubGhzProtocolEncoderBase base;
|
||||
|
||||
SubGhzProtocolBlockEncoder encoder;
|
||||
SubGhzBlockGeneric generic;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
Revers_RB2DecoderStepReset = 0,
|
||||
Revers_RB2DecoderStepHeader,
|
||||
Revers_RB2DecoderStepDecoderData,
|
||||
} Revers_RB2DecoderStep;
|
||||
|
||||
const SubGhzProtocolDecoder subghz_protocol_revers_rb2_decoder = {
|
||||
.alloc = subghz_protocol_decoder_revers_rb2_alloc,
|
||||
.free = subghz_protocol_decoder_revers_rb2_free,
|
||||
|
||||
.feed = subghz_protocol_decoder_revers_rb2_feed,
|
||||
.reset = subghz_protocol_decoder_revers_rb2_reset,
|
||||
|
||||
.get_hash_data = subghz_protocol_decoder_revers_rb2_get_hash_data,
|
||||
.serialize = subghz_protocol_decoder_revers_rb2_serialize,
|
||||
.deserialize = subghz_protocol_decoder_revers_rb2_deserialize,
|
||||
.get_string = subghz_protocol_decoder_revers_rb2_get_string,
|
||||
};
|
||||
|
||||
const SubGhzProtocolEncoder subghz_protocol_revers_rb2_encoder = {
|
||||
.alloc = subghz_protocol_encoder_revers_rb2_alloc,
|
||||
.free = subghz_protocol_encoder_revers_rb2_free,
|
||||
|
||||
.deserialize = subghz_protocol_encoder_revers_rb2_deserialize,
|
||||
.stop = subghz_protocol_encoder_revers_rb2_stop,
|
||||
.yield = subghz_protocol_encoder_revers_rb2_yield,
|
||||
};
|
||||
|
||||
const SubGhzProtocol subghz_protocol_revers_rb2 = {
|
||||
.name = SUBGHZ_PROTOCOL_REVERSRB2_NAME,
|
||||
.type = SubGhzProtocolTypeStatic,
|
||||
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable |
|
||||
SubGhzProtocolFlag_Load | SubGhzProtocolFlag_Save | SubGhzProtocolFlag_Send,
|
||||
|
||||
.decoder = &subghz_protocol_revers_rb2_decoder,
|
||||
.encoder = &subghz_protocol_revers_rb2_encoder,
|
||||
};
|
||||
|
||||
void* subghz_protocol_encoder_revers_rb2_alloc(SubGhzEnvironment* environment) {
|
||||
UNUSED(environment);
|
||||
SubGhzProtocolEncoderRevers_RB2* instance = malloc(sizeof(SubGhzProtocolEncoderRevers_RB2));
|
||||
|
||||
instance->base.protocol = &subghz_protocol_revers_rb2;
|
||||
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;
|
||||
}
|
||||
|
||||
void subghz_protocol_encoder_revers_rb2_free(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolEncoderRevers_RB2* instance = context;
|
||||
free(instance->encoder.upload);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
static LevelDuration
|
||||
subghz_protocol_encoder_revers_rb2_add_duration_to_upload(ManchesterEncoderResult result) {
|
||||
LevelDuration data = {.duration = 0, .level = 0};
|
||||
switch(result) {
|
||||
case ManchesterEncoderResultShortLow:
|
||||
data.duration = subghz_protocol_revers_rb2_const.te_short;
|
||||
data.level = false;
|
||||
break;
|
||||
case ManchesterEncoderResultLongLow:
|
||||
data.duration = subghz_protocol_revers_rb2_const.te_long;
|
||||
data.level = false;
|
||||
break;
|
||||
case ManchesterEncoderResultLongHigh:
|
||||
data.duration = subghz_protocol_revers_rb2_const.te_long;
|
||||
data.level = true;
|
||||
break;
|
||||
case ManchesterEncoderResultShortHigh:
|
||||
data.duration = subghz_protocol_revers_rb2_const.te_short;
|
||||
data.level = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
furi_crash("SubGhz: ManchesterEncoderResult is incorrect.");
|
||||
break;
|
||||
}
|
||||
return level_duration_make(data.level, data.duration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generating an upload from data.
|
||||
* @param instance Pointer to a SubGhzProtocolEncoderRevers_RB2 instance
|
||||
*/
|
||||
static void
|
||||
subghz_protocol_encoder_revers_rb2_get_upload(SubGhzProtocolEncoderRevers_RB2* instance) {
|
||||
furi_assert(instance);
|
||||
size_t index = 0;
|
||||
|
||||
ManchesterEncoderState enc_state;
|
||||
manchester_encoder_reset(&enc_state);
|
||||
ManchesterEncoderResult result;
|
||||
|
||||
for(uint8_t i = instance->generic.data_count_bit; i > 0; i--) {
|
||||
if(!manchester_encoder_advance(
|
||||
&enc_state, bit_read(instance->generic.data, i - 1), &result)) {
|
||||
instance->encoder.upload[index++] =
|
||||
subghz_protocol_encoder_revers_rb2_add_duration_to_upload(result);
|
||||
manchester_encoder_advance(
|
||||
&enc_state, bit_read(instance->generic.data, i - 1), &result);
|
||||
}
|
||||
instance->encoder.upload[index++] =
|
||||
subghz_protocol_encoder_revers_rb2_add_duration_to_upload(result);
|
||||
}
|
||||
instance->encoder.upload[index] = subghz_protocol_encoder_revers_rb2_add_duration_to_upload(
|
||||
manchester_encoder_finish(&enc_state));
|
||||
if(level_duration_get_level(instance->encoder.upload[index])) {
|
||||
index++;
|
||||
}
|
||||
instance->encoder.upload[index++] = level_duration_make(false, (uint32_t)320);
|
||||
instance->encoder.size_upload = index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Analysis of received data
|
||||
* @param instance Pointer to a SubGhzBlockGeneric* instance
|
||||
*/
|
||||
static void subghz_protocol_revers_rb2_remote_controller(SubGhzBlockGeneric* instance) {
|
||||
// Revers RB2 / RB2M Decoder
|
||||
// 02.2025 - @xMasterX (MMX)
|
||||
instance->serial = (((instance->data << 16) >> 16) >> 10);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus
|
||||
subghz_protocol_encoder_revers_rb2_deserialize(void* context, FlipperFormat* flipper_format) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolEncoderRevers_RB2* instance = context;
|
||||
SubGhzProtocolStatus ret = SubGhzProtocolStatusError;
|
||||
do {
|
||||
ret = subghz_block_generic_deserialize_check_count_bit(
|
||||
&instance->generic,
|
||||
flipper_format,
|
||||
subghz_protocol_revers_rb2_const.min_count_bit_for_found);
|
||||
if(ret != SubGhzProtocolStatusOk) {
|
||||
break;
|
||||
}
|
||||
//optional parameter parameter
|
||||
flipper_format_read_uint32(
|
||||
flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1);
|
||||
|
||||
subghz_protocol_revers_rb2_remote_controller(&instance->generic);
|
||||
subghz_protocol_encoder_revers_rb2_get_upload(instance);
|
||||
instance->encoder.is_running = true;
|
||||
} while(false);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void subghz_protocol_encoder_revers_rb2_stop(void* context) {
|
||||
SubGhzProtocolEncoderRevers_RB2* instance = context;
|
||||
instance->encoder.is_running = false;
|
||||
}
|
||||
|
||||
LevelDuration subghz_protocol_encoder_revers_rb2_yield(void* context) {
|
||||
SubGhzProtocolEncoderRevers_RB2* 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_revers_rb2_alloc(SubGhzEnvironment* environment) {
|
||||
UNUSED(environment);
|
||||
SubGhzProtocolDecoderRevers_RB2* instance = malloc(sizeof(SubGhzProtocolDecoderRevers_RB2));
|
||||
instance->base.protocol = &subghz_protocol_revers_rb2;
|
||||
instance->generic.protocol_name = instance->base.protocol->name;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_protocol_decoder_revers_rb2_free(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderRevers_RB2* instance = context;
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void subghz_protocol_decoder_revers_rb2_reset(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderRevers_RB2* instance = context;
|
||||
manchester_advance(
|
||||
instance->manchester_saved_state,
|
||||
ManchesterEventReset,
|
||||
&instance->manchester_saved_state,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void subghz_protocol_decoder_revers_rb2_addbit(void* context, bool data) {
|
||||
SubGhzProtocolDecoderRevers_RB2* instance = context;
|
||||
instance->decoder.decode_data = (instance->decoder.decode_data << 1) | data;
|
||||
instance->decoder.decode_count_bit++;
|
||||
|
||||
if(instance->decoder.decode_count_bit >= 65) {
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if(instance->decoder.decode_count_bit <
|
||||
subghz_protocol_revers_rb2_const.min_count_bit_for_found) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Revers RB2 / RB2M Decoder
|
||||
// 02.2025 - @xMasterX (MMX)
|
||||
|
||||
uint16_t preamble = (instance->decoder.decode_data >> 48) & 0xFF;
|
||||
uint16_t stop_code = (instance->decoder.decode_data & 0x3FF);
|
||||
|
||||
if(preamble == 0xFF && stop_code == 0x200) {
|
||||
//Found header and stop code
|
||||
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;
|
||||
manchester_advance(
|
||||
instance->manchester_saved_state,
|
||||
ManchesterEventReset,
|
||||
&instance->manchester_saved_state,
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_protocol_decoder_revers_rb2_feed(void* context, bool level, volatile uint32_t duration) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderRevers_RB2* instance = context;
|
||||
ManchesterEvent event = ManchesterEventReset;
|
||||
|
||||
switch(instance->decoder.parser_step) {
|
||||
case Revers_RB2DecoderStepReset:
|
||||
if((!level) &&
|
||||
(DURATION_DIFF(duration, 600) < subghz_protocol_revers_rb2_const.te_delta)) {
|
||||
instance->decoder.parser_step = Revers_RB2DecoderStepHeader;
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
manchester_advance(
|
||||
instance->manchester_saved_state,
|
||||
ManchesterEventReset,
|
||||
&instance->manchester_saved_state,
|
||||
NULL);
|
||||
}
|
||||
break;
|
||||
case Revers_RB2DecoderStepHeader:
|
||||
if(!level) {
|
||||
if(DURATION_DIFF(duration, subghz_protocol_revers_rb2_const.te_short) <
|
||||
subghz_protocol_revers_rb2_const.te_delta) {
|
||||
if(instance->decoder.te_last == 1) {
|
||||
instance->header_count++;
|
||||
}
|
||||
instance->decoder.te_last = level;
|
||||
} else {
|
||||
instance->header_count = 0;
|
||||
instance->decoder.te_last = 0;
|
||||
instance->decoder.parser_step = Revers_RB2DecoderStepReset;
|
||||
}
|
||||
} else {
|
||||
if(DURATION_DIFF(duration, subghz_protocol_revers_rb2_const.te_short) <
|
||||
subghz_protocol_revers_rb2_const.te_delta) {
|
||||
if(instance->decoder.te_last == 0) {
|
||||
instance->header_count++;
|
||||
}
|
||||
instance->decoder.te_last = level;
|
||||
} else {
|
||||
instance->header_count = 0;
|
||||
instance->decoder.te_last = 0;
|
||||
instance->decoder.parser_step = Revers_RB2DecoderStepReset;
|
||||
}
|
||||
}
|
||||
|
||||
if(instance->header_count == 4) {
|
||||
instance->header_count = 0;
|
||||
instance->decoder.decode_data = 0xF;
|
||||
instance->decoder.decode_count_bit = 4;
|
||||
instance->decoder.parser_step = Revers_RB2DecoderStepDecoderData;
|
||||
}
|
||||
break;
|
||||
case Revers_RB2DecoderStepDecoderData:
|
||||
if(!level) {
|
||||
if(DURATION_DIFF(duration, subghz_protocol_revers_rb2_const.te_short) <
|
||||
subghz_protocol_revers_rb2_const.te_delta) {
|
||||
event = ManchesterEventShortLow;
|
||||
} else if(
|
||||
DURATION_DIFF(duration, subghz_protocol_revers_rb2_const.te_long) <
|
||||
subghz_protocol_revers_rb2_const.te_delta) {
|
||||
event = ManchesterEventLongLow;
|
||||
} else {
|
||||
instance->decoder.parser_step = Revers_RB2DecoderStepReset;
|
||||
}
|
||||
} else {
|
||||
if(DURATION_DIFF(duration, subghz_protocol_revers_rb2_const.te_short) <
|
||||
subghz_protocol_revers_rb2_const.te_delta) {
|
||||
event = ManchesterEventShortHigh;
|
||||
} else if(
|
||||
DURATION_DIFF(duration, subghz_protocol_revers_rb2_const.te_long) <
|
||||
subghz_protocol_revers_rb2_const.te_delta) {
|
||||
event = ManchesterEventLongHigh;
|
||||
} else {
|
||||
instance->decoder.parser_step = Revers_RB2DecoderStepReset;
|
||||
}
|
||||
}
|
||||
if(event != ManchesterEventReset) {
|
||||
bool data;
|
||||
bool data_ok = manchester_advance(
|
||||
instance->manchester_saved_state, event, &instance->manchester_saved_state, &data);
|
||||
|
||||
if(data_ok) {
|
||||
subghz_protocol_decoder_revers_rb2_addbit(instance, data);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t subghz_protocol_decoder_revers_rb2_get_hash_data(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderRevers_RB2* instance = context;
|
||||
return subghz_protocol_blocks_get_hash_data(
|
||||
&instance->decoder, (instance->decoder.decode_count_bit / 8) + 1);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus subghz_protocol_decoder_revers_rb2_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderRevers_RB2* instance = context;
|
||||
return subghz_block_generic_serialize(&instance->generic, flipper_format, preset);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus
|
||||
subghz_protocol_decoder_revers_rb2_deserialize(void* context, FlipperFormat* flipper_format) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderRevers_RB2* instance = context;
|
||||
return subghz_block_generic_deserialize_check_count_bit(
|
||||
&instance->generic,
|
||||
flipper_format,
|
||||
subghz_protocol_revers_rb2_const.min_count_bit_for_found);
|
||||
}
|
||||
|
||||
void subghz_protocol_decoder_revers_rb2_get_string(void* context, FuriString* output) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderRevers_RB2* instance = context;
|
||||
subghz_protocol_revers_rb2_remote_controller(&instance->generic);
|
||||
|
||||
furi_string_cat_printf(
|
||||
output,
|
||||
"%s %db\r\n"
|
||||
"Key:%lX%08lX\r\n"
|
||||
"Sn:0x%08lX \r\n",
|
||||
instance->generic.protocol_name,
|
||||
instance->generic.data_count_bit,
|
||||
(uint32_t)(instance->generic.data >> 32),
|
||||
(uint32_t)(instance->generic.data & 0xFFFFFFFF),
|
||||
instance->generic.serial);
|
||||
}
|
||||
109
lib/subghz/protocols/revers_rb2.h
Normal file
109
lib/subghz/protocols/revers_rb2.h
Normal file
@@ -0,0 +1,109 @@
|
||||
#pragma once
|
||||
|
||||
#include "base.h"
|
||||
|
||||
#define SUBGHZ_PROTOCOL_REVERSRB2_NAME "Revers_RB2"
|
||||
|
||||
typedef struct SubGhzProtocolDecoderRevers_RB2 SubGhzProtocolDecoderRevers_RB2;
|
||||
typedef struct SubGhzProtocolEncoderRevers_RB2 SubGhzProtocolEncoderRevers_RB2;
|
||||
|
||||
extern const SubGhzProtocolDecoder subghz_protocol_revers_rb2_decoder;
|
||||
extern const SubGhzProtocolEncoder subghz_protocol_revers_rb2_encoder;
|
||||
extern const SubGhzProtocol subghz_protocol_revers_rb2;
|
||||
|
||||
/**
|
||||
* Allocate SubGhzProtocolEncoderRevers_RB2.
|
||||
* @param environment Pointer to a SubGhzEnvironment instance
|
||||
* @return SubGhzProtocolEncoderRevers_RB2* pointer to a SubGhzProtocolEncoderRevers_RB2 instance
|
||||
*/
|
||||
void* subghz_protocol_encoder_revers_rb2_alloc(SubGhzEnvironment* environment);
|
||||
|
||||
/**
|
||||
* Free SubGhzProtocolEncoderRevers_RB2.
|
||||
* @param context Pointer to a SubGhzProtocolEncoderRevers_RB2 instance
|
||||
*/
|
||||
void subghz_protocol_encoder_revers_rb2_free(void* context);
|
||||
|
||||
/**
|
||||
* Deserialize and generating an upload to send.
|
||||
* @param context Pointer to a SubGhzProtocolEncoderRevers_RB2 instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @return status
|
||||
*/
|
||||
SubGhzProtocolStatus
|
||||
subghz_protocol_encoder_revers_rb2_deserialize(void* context, FlipperFormat* flipper_format);
|
||||
|
||||
/**
|
||||
* Forced transmission stop.
|
||||
* @param context Pointer to a SubGhzProtocolEncoderRevers_RB2 instance
|
||||
*/
|
||||
void subghz_protocol_encoder_revers_rb2_stop(void* context);
|
||||
|
||||
/**
|
||||
* Getting the level and duration of the upload to be loaded into DMA.
|
||||
* @param context Pointer to a SubGhzProtocolEncoderRevers_RB2 instance
|
||||
* @return LevelDuration
|
||||
*/
|
||||
LevelDuration subghz_protocol_encoder_revers_rb2_yield(void* context);
|
||||
|
||||
/**
|
||||
* Allocate SubGhzProtocolDecoderRevers_RB2.
|
||||
* @param environment Pointer to a SubGhzEnvironment instance
|
||||
* @return SubGhzProtocolDecoderRevers_RB2* pointer to a SubGhzProtocolDecoderRevers_RB2 instance
|
||||
*/
|
||||
void* subghz_protocol_decoder_revers_rb2_alloc(SubGhzEnvironment* environment);
|
||||
|
||||
/**
|
||||
* Free SubGhzProtocolDecoderRevers_RB2.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderRevers_RB2 instance
|
||||
*/
|
||||
void subghz_protocol_decoder_revers_rb2_free(void* context);
|
||||
|
||||
/**
|
||||
* Reset decoder SubGhzProtocolDecoderRevers_RB2.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderRevers_RB2 instance
|
||||
*/
|
||||
void subghz_protocol_decoder_revers_rb2_reset(void* context);
|
||||
|
||||
/**
|
||||
* Parse a raw sequence of levels and durations received from the air.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderRevers_RB2 instance
|
||||
* @param level Signal level true-high false-low
|
||||
* @param duration Duration of this level in, us
|
||||
*/
|
||||
void subghz_protocol_decoder_revers_rb2_feed(void* context, bool level, uint32_t duration);
|
||||
|
||||
/**
|
||||
* Getting the hash sum of the last randomly received parcel.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderRevers_RB2 instance
|
||||
* @return hash Hash sum
|
||||
*/
|
||||
uint8_t subghz_protocol_decoder_revers_rb2_get_hash_data(void* context);
|
||||
|
||||
/**
|
||||
* Serialize data SubGhzProtocolDecoderRevers_RB2.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderRevers_RB2 instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @param preset The modulation on which the signal was received, SubGhzRadioPreset
|
||||
* @return status
|
||||
*/
|
||||
SubGhzProtocolStatus subghz_protocol_decoder_revers_rb2_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset);
|
||||
|
||||
/**
|
||||
* Deserialize data SubGhzProtocolDecoderRevers_RB2.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderRevers_RB2 instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @return status
|
||||
*/
|
||||
SubGhzProtocolStatus
|
||||
subghz_protocol_decoder_revers_rb2_deserialize(void* context, FlipperFormat* flipper_format);
|
||||
|
||||
/**
|
||||
* Getting a textual representation of the received data.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderRevers_RB2 instance
|
||||
* @param output Resulting text
|
||||
*/
|
||||
void subghz_protocol_decoder_revers_rb2_get_string(void* context, FuriString* output);
|
||||
@@ -12,7 +12,7 @@ typedef struct SubGhzProtocolRegistry SubGhzProtocolRegistry;
|
||||
typedef struct SubGhzProtocol SubGhzProtocol;
|
||||
|
||||
struct SubGhzProtocolRegistry {
|
||||
const SubGhzProtocol** items;
|
||||
const SubGhzProtocol* const* items;
|
||||
const size_t size;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user