mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
New Weather Station protocols Acurite986 KedsumTh
by @lagomorph and @Skorpionm
This commit is contained in:
274
lib/subghz/protocols/acurite_986.c
Normal file
274
lib/subghz/protocols/acurite_986.c
Normal file
@@ -0,0 +1,274 @@
|
||||
#include "acurite_986.h"
|
||||
|
||||
#define TAG "WSProtocolAcurite_986"
|
||||
|
||||
/*
|
||||
* Help
|
||||
* https://github.com/merbanan/rtl_433/blob/5bef4e43133ac4c0e2d18d36f87c52b4f9458453/src/devices/acurite.c#L1644
|
||||
*
|
||||
* 0110 0100 | 1010 1011 | 0110 0010 | 0000 0000 | 0111 0110
|
||||
* tttt tttt | IIII IIII | iiii iiii | nbuu uuuu | cccc cccc
|
||||
* - t: temperature in °F
|
||||
* - I: identification (high byte)
|
||||
* - i: identification (low byte)
|
||||
* - n: sensor number
|
||||
* - b: battery low flag to indicate low battery voltage
|
||||
* - u: unknown
|
||||
* - c: CRC (CRC-8 poly 0x07, little-endian)
|
||||
*
|
||||
* bits are sent and shown above LSB first
|
||||
* identification changes on battery switch
|
||||
*/
|
||||
|
||||
static const SubGhzBlockConst ws_protocol_acurite_986_const = {
|
||||
.te_short = 800,
|
||||
.te_long = 1750,
|
||||
.te_delta = 50,
|
||||
.min_count_bit_for_found = 40,
|
||||
};
|
||||
|
||||
struct WSProtocolDecoderAcurite_986 {
|
||||
SubGhzProtocolDecoderBase base;
|
||||
|
||||
SubGhzBlockDecoder decoder;
|
||||
WSBlockGeneric generic;
|
||||
};
|
||||
|
||||
struct WSProtocolEncoderAcurite_986 {
|
||||
SubGhzProtocolEncoderBase base;
|
||||
|
||||
SubGhzProtocolBlockEncoder encoder;
|
||||
WSBlockGeneric generic;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
Acurite_986DecoderStepReset = 0,
|
||||
Acurite_986DecoderStepSync1,
|
||||
Acurite_986DecoderStepSync2,
|
||||
Acurite_986DecoderStepSync3,
|
||||
Acurite_986DecoderStepSaveDuration,
|
||||
Acurite_986DecoderStepCheckDuration,
|
||||
} Acurite_986DecoderStep;
|
||||
|
||||
const SubGhzProtocolDecoder ws_protocol_acurite_986_decoder = {
|
||||
.alloc = ws_protocol_decoder_acurite_986_alloc,
|
||||
.free = ws_protocol_decoder_acurite_986_free,
|
||||
|
||||
.feed = ws_protocol_decoder_acurite_986_feed,
|
||||
.reset = ws_protocol_decoder_acurite_986_reset,
|
||||
|
||||
.get_hash_data = ws_protocol_decoder_acurite_986_get_hash_data,
|
||||
.serialize = ws_protocol_decoder_acurite_986_serialize,
|
||||
.deserialize = ws_protocol_decoder_acurite_986_deserialize,
|
||||
.get_string = ws_protocol_decoder_acurite_986_get_string,
|
||||
};
|
||||
|
||||
const SubGhzProtocolEncoder ws_protocol_acurite_986_encoder = {
|
||||
.alloc = NULL,
|
||||
.free = NULL,
|
||||
|
||||
.deserialize = NULL,
|
||||
.stop = NULL,
|
||||
.yield = NULL,
|
||||
};
|
||||
|
||||
const SubGhzProtocol ws_protocol_acurite_986 = {
|
||||
.name = WS_PROTOCOL_ACURITE_986_NAME,
|
||||
.type = SubGhzProtocolTypeStatic,
|
||||
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_315 | SubGhzProtocolFlag_868 |
|
||||
SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_Load |
|
||||
SubGhzProtocolFlag_Save,
|
||||
|
||||
.decoder = &ws_protocol_acurite_986_decoder,
|
||||
.encoder = &ws_protocol_acurite_986_encoder,
|
||||
|
||||
.filter = SubGhzProtocolFilter_Weather,
|
||||
};
|
||||
|
||||
void* ws_protocol_decoder_acurite_986_alloc(SubGhzEnvironment* environment) {
|
||||
UNUSED(environment);
|
||||
WSProtocolDecoderAcurite_986* instance = malloc(sizeof(WSProtocolDecoderAcurite_986));
|
||||
instance->base.protocol = &ws_protocol_acurite_986;
|
||||
instance->generic.protocol_name = instance->base.protocol->name;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_acurite_986_free(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAcurite_986* instance = context;
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_acurite_986_reset(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAcurite_986* instance = context;
|
||||
instance->decoder.parser_step = Acurite_986DecoderStepReset;
|
||||
}
|
||||
|
||||
static bool ws_protocol_acurite_986_check(WSProtocolDecoderAcurite_986* instance) {
|
||||
if(!instance->decoder.decode_data) return false;
|
||||
uint8_t msg[] = {
|
||||
instance->decoder.decode_data >> 32,
|
||||
instance->decoder.decode_data >> 24,
|
||||
instance->decoder.decode_data >> 16,
|
||||
instance->decoder.decode_data >> 8 };
|
||||
|
||||
uint8_t crc = subghz_protocol_blocks_crc8(msg, 4, 0x07, 0x00);
|
||||
return (crc == (instance->decoder.decode_data & 0xFF));
|
||||
}
|
||||
|
||||
/**
|
||||
* Analysis of received data
|
||||
* @param instance Pointer to a WSBlockGeneric* instance
|
||||
*/
|
||||
static void ws_protocol_acurite_986_remote_controller(WSBlockGeneric* instance) {
|
||||
int temp;
|
||||
|
||||
instance->id = subghz_protocol_blocks_reverse_key(instance->data >> 24, 8);
|
||||
instance->id = (instance->id << 8) | subghz_protocol_blocks_reverse_key(instance->data >> 16, 8);
|
||||
instance->battery_low = (instance->data >> 14) & 1;
|
||||
instance->channel = ((instance->data >> 15) & 1) + 1;
|
||||
|
||||
temp = subghz_protocol_blocks_reverse_key(instance->data >> 32, 8);
|
||||
if(temp & 0x80) {
|
||||
temp = -(temp & 0x7F);
|
||||
}
|
||||
instance->temp = locale_fahrenheit_to_celsius((float)temp);
|
||||
instance->btn = WS_NO_BTN;
|
||||
instance->humidity = WS_NO_HUMIDITY;
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_acurite_986_feed(void* context, bool level, uint32_t duration) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAcurite_986* instance = context;
|
||||
|
||||
switch(instance->decoder.parser_step) {
|
||||
case Acurite_986DecoderStepReset:
|
||||
if((!level) && (DURATION_DIFF(duration, ws_protocol_acurite_986_const.te_long) <
|
||||
ws_protocol_acurite_986_const.te_delta * 15)) {
|
||||
//Found 1st sync bit
|
||||
instance->decoder.parser_step = Acurite_986DecoderStepSync1;
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case Acurite_986DecoderStepSync1:
|
||||
if(DURATION_DIFF(duration, ws_protocol_acurite_986_const.te_long) <
|
||||
ws_protocol_acurite_986_const.te_delta * 15) {
|
||||
if(!level) {
|
||||
instance->decoder.parser_step = Acurite_986DecoderStepSync2;
|
||||
}
|
||||
} else {
|
||||
instance->decoder.parser_step = Acurite_986DecoderStepReset;
|
||||
}
|
||||
break;
|
||||
|
||||
case Acurite_986DecoderStepSync2:
|
||||
if(DURATION_DIFF(duration, ws_protocol_acurite_986_const.te_long) <
|
||||
ws_protocol_acurite_986_const.te_delta * 15) {
|
||||
if(!level) {
|
||||
instance->decoder.parser_step = Acurite_986DecoderStepSync3;
|
||||
}
|
||||
} else {
|
||||
instance->decoder.parser_step = Acurite_986DecoderStepReset;
|
||||
}
|
||||
break;
|
||||
|
||||
case Acurite_986DecoderStepSync3:
|
||||
if(DURATION_DIFF(duration, ws_protocol_acurite_986_const.te_long) <
|
||||
ws_protocol_acurite_986_const.te_delta * 15) {
|
||||
if(!level) {
|
||||
instance->decoder.parser_step = Acurite_986DecoderStepSaveDuration;
|
||||
}
|
||||
} else {
|
||||
instance->decoder.parser_step = Acurite_986DecoderStepReset;
|
||||
}
|
||||
break;
|
||||
|
||||
case Acurite_986DecoderStepSaveDuration:
|
||||
if(level) {
|
||||
instance->decoder.te_last = duration;
|
||||
instance->decoder.parser_step = Acurite_986DecoderStepCheckDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = Acurite_986DecoderStepReset;
|
||||
}
|
||||
break;
|
||||
|
||||
case Acurite_986DecoderStepCheckDuration:
|
||||
if(!level) {
|
||||
if(DURATION_DIFF(duration, ws_protocol_acurite_986_const.te_short) <
|
||||
ws_protocol_acurite_986_const.te_delta * 10) {
|
||||
if(duration < ws_protocol_acurite_986_const.te_short) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
||||
instance->decoder.parser_step = Acurite_986DecoderStepSaveDuration;
|
||||
} else {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
||||
instance->decoder.parser_step = Acurite_986DecoderStepSaveDuration;
|
||||
}
|
||||
} else {
|
||||
//Found syncPostfix
|
||||
instance->decoder.parser_step = Acurite_986DecoderStepReset;
|
||||
if((instance->decoder.decode_count_bit == ws_protocol_acurite_986_const.min_count_bit_for_found) &&
|
||||
ws_protocol_acurite_986_check(instance)) {
|
||||
instance->generic.data = instance->decoder.decode_data;
|
||||
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
|
||||
ws_protocol_acurite_986_remote_controller(&instance->generic);
|
||||
if(instance->base.callback)
|
||||
instance->base.callback(&instance->base, instance->base.context);
|
||||
}
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
}
|
||||
} else {
|
||||
instance->decoder.parser_step = Acurite_986DecoderStepReset;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t ws_protocol_decoder_acurite_986_get_hash_data(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAcurite_986* instance = context;
|
||||
return subghz_protocol_blocks_get_hash_data_long(
|
||||
&instance->decoder, (instance->decoder.decode_count_bit / 8) + 1);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus ws_protocol_decoder_acurite_986_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAcurite_986* instance = context;
|
||||
return ws_block_generic_serialize(&instance->generic, flipper_format, preset);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus
|
||||
ws_protocol_decoder_acurite_986_deserialize(void* context, FlipperFormat* flipper_format) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAcurite_986* instance = context;
|
||||
return ws_block_generic_deserialize_check_count_bit(
|
||||
&instance->generic,
|
||||
flipper_format,
|
||||
ws_protocol_acurite_986_const.min_count_bit_for_found);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_acurite_986_get_string(void* context, FuriString* output) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAcurite_986* instance = context;
|
||||
furi_string_cat_printf(
|
||||
output,
|
||||
"%s\r\n%dbit\r\n"
|
||||
"Key:0x%lX%08lX\r\n"
|
||||
"Sn:0x%lX Ch:%d Bat:%d\r\n"
|
||||
"Temp:%3.1f C Hum:%d%%",
|
||||
instance->generic.protocol_name,
|
||||
instance->generic.data_count_bit,
|
||||
(uint32_t)(instance->generic.data >> 32),
|
||||
(uint32_t)(instance->generic.data),
|
||||
instance->generic.id,
|
||||
instance->generic.channel,
|
||||
instance->generic.battery_low,
|
||||
(double)instance->generic.temp,
|
||||
instance->generic.humidity);
|
||||
}
|
||||
80
lib/subghz/protocols/acurite_986.h
Normal file
80
lib/subghz/protocols/acurite_986.h
Normal file
@@ -0,0 +1,80 @@
|
||||
#pragma once
|
||||
|
||||
#include <lib/subghz/protocols/base.h>
|
||||
|
||||
#include <lib/subghz/blocks/const.h>
|
||||
#include <lib/subghz/blocks/decoder.h>
|
||||
#include <lib/subghz/blocks/encoder.h>
|
||||
#include "ws_generic.h"
|
||||
#include <lib/subghz/blocks/math.h>
|
||||
|
||||
#define WS_PROTOCOL_ACURITE_986_NAME "Acurite-986"
|
||||
|
||||
typedef struct WSProtocolDecoderAcurite_986 WSProtocolDecoderAcurite_986;
|
||||
typedef struct WSProtocolEncoderAcurite_986 WSProtocolEncoderAcurite_986;
|
||||
|
||||
extern const SubGhzProtocolDecoder ws_protocol_acurite_986_decoder;
|
||||
extern const SubGhzProtocolEncoder ws_protocol_acurite_986_encoder;
|
||||
extern const SubGhzProtocol ws_protocol_acurite_986;
|
||||
|
||||
/**
|
||||
* Allocate WSProtocolDecoderAcurite_986.
|
||||
* @param environment Pointer to a SubGhzEnvironment instance
|
||||
* @return WSProtocolDecoderAcurite_986* pointer to a WSProtocolDecoderAcurite_986 instance
|
||||
*/
|
||||
void* ws_protocol_decoder_acurite_986_alloc(SubGhzEnvironment* environment);
|
||||
|
||||
/**
|
||||
* Free WSProtocolDecoderAcurite_986.
|
||||
* @param context Pointer to a WSProtocolDecoderAcurite_986 instance
|
||||
*/
|
||||
void ws_protocol_decoder_acurite_986_free(void* context);
|
||||
|
||||
/**
|
||||
* Reset decoder WSProtocolDecoderAcurite_986.
|
||||
* @param context Pointer to a WSProtocolDecoderAcurite_986 instance
|
||||
*/
|
||||
void ws_protocol_decoder_acurite_986_reset(void* context);
|
||||
|
||||
/**
|
||||
* Parse a raw sequence of levels and durations received from the air.
|
||||
* @param context Pointer to a WSProtocolDecoderAcurite_986 instance
|
||||
* @param level Signal level true-high false-low
|
||||
* @param duration Duration of this level in, us
|
||||
*/
|
||||
void ws_protocol_decoder_acurite_986_feed(void* context, bool level, uint32_t duration);
|
||||
|
||||
/**
|
||||
* Getting the hash sum of the last randomly received parcel.
|
||||
* @param context Pointer to a WSProtocolDecoderAcurite_986 instance
|
||||
* @return hash Hash sum
|
||||
*/
|
||||
uint32_t ws_protocol_decoder_acurite_986_get_hash_data(void* context);
|
||||
|
||||
/**
|
||||
* Serialize data WSProtocolDecoderAcurite_986.
|
||||
* @param context Pointer to a WSProtocolDecoderAcurite_986 instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @param preset The modulation on which the signal was received, SubGhzRadioPreset
|
||||
* @return status
|
||||
*/
|
||||
SubGhzProtocolStatus ws_protocol_decoder_acurite_986_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset);
|
||||
|
||||
/**
|
||||
* Deserialize data WSProtocolDecoderAcurite_986.
|
||||
* @param context Pointer to a WSProtocolDecoderAcurite_986 instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @return status
|
||||
*/
|
||||
SubGhzProtocolStatus
|
||||
ws_protocol_decoder_acurite_986_deserialize(void* context, FlipperFormat* flipper_format);
|
||||
|
||||
/**
|
||||
* Getting a textual representation of the received data.
|
||||
* @param context Pointer to a WSProtocolDecoderAcurite_986 instance
|
||||
* @param output Resulting text
|
||||
*/
|
||||
void ws_protocol_decoder_acurite_986_get_string(void* context, FuriString* output);
|
||||
297
lib/subghz/protocols/kedsum_th.c
Normal file
297
lib/subghz/protocols/kedsum_th.c
Normal file
@@ -0,0 +1,297 @@
|
||||
#include "kedsum_th.h"
|
||||
|
||||
#define TAG "WSProtocolKedsumTH"
|
||||
|
||||
/*
|
||||
* Help
|
||||
* https://github.com/merbanan/rtl_433/blob/master/src/devices/kedsum.c
|
||||
*
|
||||
* Frame structure:
|
||||
*
|
||||
* Byte: 0 1 2 3 4
|
||||
* Nibble: 1 2 3 4 5 6 7 8 9 10
|
||||
* Type: 00 IIIIIIII BBCC++++ ttttTTTT hhhhHHHH FFFFXXXX
|
||||
*
|
||||
* - I: unique id. changes on powercycle
|
||||
* - B: Battery state 10 = Ok, 01 = weak, 00 = bad
|
||||
* - C: channel, 00 = ch1, 10=ch3
|
||||
* - + low temp nibble
|
||||
* - t: med temp nibble
|
||||
* - T: high temp nibble
|
||||
* - h: humidity low nibble
|
||||
* - H: humidity high nibble
|
||||
* - F: flags
|
||||
* - X: CRC-4 poly 0x3 init 0x0 xor last 4 bits
|
||||
*/
|
||||
|
||||
static const SubGhzBlockConst ws_protocol_kedsum_th_const = {
|
||||
.te_short = 500,
|
||||
.te_long = 2000,
|
||||
.te_delta = 150,
|
||||
.min_count_bit_for_found = 42,
|
||||
};
|
||||
|
||||
struct WSProtocolDecoderKedsumTH {
|
||||
SubGhzProtocolDecoderBase base;
|
||||
|
||||
SubGhzBlockDecoder decoder;
|
||||
WSBlockGeneric generic;
|
||||
|
||||
uint16_t header_count;
|
||||
};
|
||||
|
||||
struct WSProtocolEncoderKedsumTH {
|
||||
SubGhzProtocolEncoderBase base;
|
||||
|
||||
SubGhzProtocolBlockEncoder encoder;
|
||||
WSBlockGeneric generic;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
KedsumTHDecoderStepReset = 0,
|
||||
KedsumTHDecoderStepCheckPreambule,
|
||||
KedsumTHDecoderStepSaveDuration,
|
||||
KedsumTHDecoderStepCheckDuration,
|
||||
} KedsumTHDecoderStep;
|
||||
|
||||
const SubGhzProtocolDecoder ws_protocol_kedsum_th_decoder = {
|
||||
.alloc = ws_protocol_decoder_kedsum_th_alloc,
|
||||
.free = ws_protocol_decoder_kedsum_th_free,
|
||||
|
||||
.feed = ws_protocol_decoder_kedsum_th_feed,
|
||||
.reset = ws_protocol_decoder_kedsum_th_reset,
|
||||
|
||||
.get_hash_data = ws_protocol_decoder_kedsum_th_get_hash_data,
|
||||
.serialize = ws_protocol_decoder_kedsum_th_serialize,
|
||||
.deserialize = ws_protocol_decoder_kedsum_th_deserialize,
|
||||
.get_string = ws_protocol_decoder_kedsum_th_get_string,
|
||||
};
|
||||
|
||||
const SubGhzProtocolEncoder ws_protocol_kedsum_th_encoder = {
|
||||
.alloc = NULL,
|
||||
.free = NULL,
|
||||
|
||||
.deserialize = NULL,
|
||||
.stop = NULL,
|
||||
.yield = NULL,
|
||||
};
|
||||
|
||||
const SubGhzProtocol ws_protocol_kedsum_th = {
|
||||
.name = WS_PROTOCOL_KEDSUM_TH_NAME,
|
||||
.type = SubGhzProtocolTypeStatic,
|
||||
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_315 | SubGhzProtocolFlag_868 |
|
||||
SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_Load |
|
||||
SubGhzProtocolFlag_Save,
|
||||
|
||||
.decoder = &ws_protocol_kedsum_th_decoder,
|
||||
.encoder = &ws_protocol_kedsum_th_encoder,
|
||||
|
||||
.filter = SubGhzProtocolFilter_Weather,
|
||||
};
|
||||
|
||||
void* ws_protocol_decoder_kedsum_th_alloc(SubGhzEnvironment* environment) {
|
||||
UNUSED(environment);
|
||||
WSProtocolDecoderKedsumTH* instance = malloc(sizeof(WSProtocolDecoderKedsumTH));
|
||||
instance->base.protocol = &ws_protocol_kedsum_th;
|
||||
instance->generic.protocol_name = instance->base.protocol->name;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_kedsum_th_free(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderKedsumTH* instance = context;
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_kedsum_th_reset(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderKedsumTH* instance = context;
|
||||
instance->decoder.parser_step = KedsumTHDecoderStepReset;
|
||||
}
|
||||
|
||||
static bool ws_protocol_kedsum_th_check_crc(WSProtocolDecoderKedsumTH* instance) {
|
||||
uint8_t msg[] = {
|
||||
instance->decoder.decode_data >> 32,
|
||||
instance->decoder.decode_data >> 24,
|
||||
instance->decoder.decode_data >> 16,
|
||||
instance->decoder.decode_data >> 8,
|
||||
instance->decoder.decode_data};
|
||||
|
||||
uint8_t crc =
|
||||
subghz_protocol_blocks_crc4(msg, 4, 0x03, 0); // CRC-4 poly 0x3 init 0x0 xor last 4 bits
|
||||
crc ^= msg[4] >> 4; // last nibble is only XORed
|
||||
return (crc == (msg[4] & 0x0F));
|
||||
}
|
||||
|
||||
/**
|
||||
* Analysis of received data
|
||||
* @param instance Pointer to a WSBlockGeneric* instance
|
||||
*/
|
||||
static void ws_protocol_kedsum_th_remote_controller(WSBlockGeneric* instance) {
|
||||
instance->id = instance->data >> 32;
|
||||
if((instance->data >> 30) & 0x3) {
|
||||
instance->battery_low = 0;
|
||||
} else {
|
||||
instance->battery_low = 1;
|
||||
}
|
||||
instance->channel = ((instance->data >> 28) & 0x3) + 1;
|
||||
instance->btn = WS_NO_BTN;
|
||||
uint16_t temp_raw = ((instance->data >> 16) & 0x0f) << 8 |
|
||||
((instance->data >> 20) & 0x0f) << 4 | ((instance->data >> 24) & 0x0f);
|
||||
instance->temp = locale_fahrenheit_to_celsius(((float)temp_raw - 900.0f) / 10.0f);
|
||||
instance->humidity = ((instance->data >> 8) & 0x0f) << 4 | ((instance->data >> 12) & 0x0f);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_kedsum_th_feed(void* context, bool level, uint32_t duration) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderKedsumTH* instance = context;
|
||||
|
||||
switch(instance->decoder.parser_step) {
|
||||
case KedsumTHDecoderStepReset:
|
||||
if((level) && (DURATION_DIFF(duration, ws_protocol_kedsum_th_const.te_short) <
|
||||
ws_protocol_kedsum_th_const.te_delta)) {
|
||||
instance->decoder.parser_step = KedsumTHDecoderStepCheckPreambule;
|
||||
instance->decoder.te_last = duration;
|
||||
instance->header_count = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case KedsumTHDecoderStepCheckPreambule:
|
||||
if(level) {
|
||||
instance->decoder.te_last = duration;
|
||||
} else {
|
||||
if((DURATION_DIFF(instance->decoder.te_last, ws_protocol_kedsum_th_const.te_short) <
|
||||
ws_protocol_kedsum_th_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_kedsum_th_const.te_long * 4) <
|
||||
ws_protocol_kedsum_th_const.te_delta * 4)) {
|
||||
//Found preambule
|
||||
instance->header_count++;
|
||||
} else if(
|
||||
(DURATION_DIFF(instance->decoder.te_last, ws_protocol_kedsum_th_const.te_short) <
|
||||
ws_protocol_kedsum_th_const.te_delta) &&
|
||||
(duration < (ws_protocol_kedsum_th_const.te_long * 2 +
|
||||
ws_protocol_kedsum_th_const.te_delta * 2))) {
|
||||
//Found syncPrefix
|
||||
if(instance->header_count > 0) {
|
||||
instance->decoder.parser_step = KedsumTHDecoderStepSaveDuration;
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
if((DURATION_DIFF(
|
||||
instance->decoder.te_last, ws_protocol_kedsum_th_const.te_short) <
|
||||
ws_protocol_kedsum_th_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_kedsum_th_const.te_long) <
|
||||
ws_protocol_kedsum_th_const.te_delta * 2)) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
||||
instance->decoder.parser_step = KedsumTHDecoderStepSaveDuration;
|
||||
} else if(
|
||||
(DURATION_DIFF(
|
||||
instance->decoder.te_last, ws_protocol_kedsum_th_const.te_short) <
|
||||
ws_protocol_kedsum_th_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_kedsum_th_const.te_long * 2) <
|
||||
ws_protocol_kedsum_th_const.te_delta * 4)) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
||||
instance->decoder.parser_step = KedsumTHDecoderStepSaveDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = KedsumTHDecoderStepReset;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
instance->decoder.parser_step = KedsumTHDecoderStepReset;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case KedsumTHDecoderStepSaveDuration:
|
||||
if(level) {
|
||||
instance->decoder.te_last = duration;
|
||||
instance->decoder.parser_step = KedsumTHDecoderStepCheckDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = KedsumTHDecoderStepReset;
|
||||
}
|
||||
break;
|
||||
|
||||
case KedsumTHDecoderStepCheckDuration:
|
||||
if(!level) {
|
||||
if(DURATION_DIFF(duration, ws_protocol_kedsum_th_const.te_long * 4) <
|
||||
ws_protocol_kedsum_th_const.te_delta * 4) {
|
||||
//Found syncPostfix
|
||||
if((instance->decoder.decode_count_bit ==
|
||||
ws_protocol_kedsum_th_const.min_count_bit_for_found) &&
|
||||
ws_protocol_kedsum_th_check_crc(instance)) {
|
||||
instance->generic.data = instance->decoder.decode_data;
|
||||
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
|
||||
ws_protocol_kedsum_th_remote_controller(&instance->generic);
|
||||
if(instance->base.callback)
|
||||
instance->base.callback(&instance->base, instance->base.context);
|
||||
}
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
instance->decoder.parser_step = KedsumTHDecoderStepReset;
|
||||
break;
|
||||
} else if(
|
||||
(DURATION_DIFF(instance->decoder.te_last, ws_protocol_kedsum_th_const.te_short) <
|
||||
ws_protocol_kedsum_th_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_kedsum_th_const.te_long) <
|
||||
ws_protocol_kedsum_th_const.te_delta * 2)) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
||||
instance->decoder.parser_step = KedsumTHDecoderStepSaveDuration;
|
||||
} else if(
|
||||
(DURATION_DIFF(instance->decoder.te_last, ws_protocol_kedsum_th_const.te_short) <
|
||||
ws_protocol_kedsum_th_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_kedsum_th_const.te_long * 2) <
|
||||
ws_protocol_kedsum_th_const.te_delta * 4)) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
||||
instance->decoder.parser_step = KedsumTHDecoderStepSaveDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = KedsumTHDecoderStepReset;
|
||||
}
|
||||
} else {
|
||||
instance->decoder.parser_step = KedsumTHDecoderStepReset;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t ws_protocol_decoder_kedsum_th_get_hash_data(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderKedsumTH* instance = context;
|
||||
return subghz_protocol_blocks_get_hash_data_long(
|
||||
&instance->decoder, (instance->decoder.decode_count_bit / 8) + 1);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus ws_protocol_decoder_kedsum_th_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderKedsumTH* instance = context;
|
||||
return ws_block_generic_serialize(&instance->generic, flipper_format, preset);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus
|
||||
ws_protocol_decoder_kedsum_th_deserialize(void* context, FlipperFormat* flipper_format) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderKedsumTH* instance = context;
|
||||
return ws_block_generic_deserialize_check_count_bit(
|
||||
&instance->generic, flipper_format, ws_protocol_kedsum_th_const.min_count_bit_for_found);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_kedsum_th_get_string(void* context, FuriString* output) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderKedsumTH* instance = context;
|
||||
furi_string_cat_printf(
|
||||
output,
|
||||
"%s\r\n%dbit\r\n"
|
||||
"Key:0x%lX%08lX\r\n"
|
||||
"Sn:0x%lX Ch:%d Bat:%d\r\n"
|
||||
"Temp:%3.1f C Hum:%d%%",
|
||||
instance->generic.protocol_name,
|
||||
instance->generic.data_count_bit,
|
||||
(uint32_t)(instance->generic.data >> 32),
|
||||
(uint32_t)(instance->generic.data),
|
||||
instance->generic.id,
|
||||
instance->generic.channel,
|
||||
instance->generic.battery_low,
|
||||
(double)instance->generic.temp,
|
||||
instance->generic.humidity);
|
||||
}
|
||||
80
lib/subghz/protocols/kedsum_th.h
Normal file
80
lib/subghz/protocols/kedsum_th.h
Normal file
@@ -0,0 +1,80 @@
|
||||
#pragma once
|
||||
|
||||
#include <lib/subghz/protocols/base.h>
|
||||
|
||||
#include <lib/subghz/blocks/const.h>
|
||||
#include <lib/subghz/blocks/decoder.h>
|
||||
#include <lib/subghz/blocks/encoder.h>
|
||||
#include "ws_generic.h"
|
||||
#include <lib/subghz/blocks/math.h>
|
||||
|
||||
#define WS_PROTOCOL_KEDSUM_TH_NAME "Kedsum-TH"
|
||||
|
||||
typedef struct WSProtocolDecoderKedsumTH WSProtocolDecoderKedsumTH;
|
||||
typedef struct WSProtocolEncoderKedsumTH WSProtocolEncoderKedsumTH;
|
||||
|
||||
extern const SubGhzProtocolDecoder ws_protocol_kedsum_th_decoder;
|
||||
extern const SubGhzProtocolEncoder ws_protocol_kedsum_th_encoder;
|
||||
extern const SubGhzProtocol ws_protocol_kedsum_th;
|
||||
|
||||
/**
|
||||
* Allocate WSProtocolDecoderKedsumTH.
|
||||
* @param environment Pointer to a SubGhzEnvironment instance
|
||||
* @return WSProtocolDecoderKedsumTH* pointer to a WSProtocolDecoderKedsumTH instance
|
||||
*/
|
||||
void* ws_protocol_decoder_kedsum_th_alloc(SubGhzEnvironment* environment);
|
||||
|
||||
/**
|
||||
* Free WSProtocolDecoderKedsumTH.
|
||||
* @param context Pointer to a WSProtocolDecoderKedsumTH instance
|
||||
*/
|
||||
void ws_protocol_decoder_kedsum_th_free(void* context);
|
||||
|
||||
/**
|
||||
* Reset decoder WSProtocolDecoderKedsumTH.
|
||||
* @param context Pointer to a WSProtocolDecoderKedsumTH instance
|
||||
*/
|
||||
void ws_protocol_decoder_kedsum_th_reset(void* context);
|
||||
|
||||
/**
|
||||
* Parse a raw sequence of levels and durations received from the air.
|
||||
* @param context Pointer to a WSProtocolDecoderKedsumTH instance
|
||||
* @param level Signal level true-high false-low
|
||||
* @param duration Duration of this level in, us
|
||||
*/
|
||||
void ws_protocol_decoder_kedsum_th_feed(void* context, bool level, uint32_t duration);
|
||||
|
||||
/**
|
||||
* Getting the hash sum of the last randomly received parcel.
|
||||
* @param context Pointer to a WSProtocolDecoderKedsumTH instance
|
||||
* @return hash Hash sum
|
||||
*/
|
||||
uint32_t ws_protocol_decoder_kedsum_th_get_hash_data(void* context);
|
||||
|
||||
/**
|
||||
* Serialize data WSProtocolDecoderKedsumTH.
|
||||
* @param context Pointer to a WSProtocolDecoderKedsumTH instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @param preset The modulation on which the signal was received, SubGhzRadioPreset
|
||||
* @return status
|
||||
*/
|
||||
SubGhzProtocolStatus ws_protocol_decoder_kedsum_th_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset);
|
||||
|
||||
/**
|
||||
* Deserialize data WSProtocolDecoderKedsumTH.
|
||||
* @param context Pointer to a WSProtocolDecoderKedsumTH instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @return status
|
||||
*/
|
||||
SubGhzProtocolStatus
|
||||
ws_protocol_decoder_kedsum_th_deserialize(void* context, FlipperFormat* flipper_format);
|
||||
|
||||
/**
|
||||
* Getting a textual representation of the received data.
|
||||
* @param context Pointer to a WSProtocolDecoderKedsumTH instance
|
||||
* @param output Resulting text
|
||||
*/
|
||||
void ws_protocol_decoder_kedsum_th_get_string(void* context, FuriString* output);
|
||||
@@ -49,6 +49,7 @@ const SubGhzProtocol* subghz_protocol_registry_items[] = {
|
||||
&ws_protocol_gt_wt_03,
|
||||
&ws_protocol_acurite_606tx,
|
||||
&ws_protocol_acurite_609txc,
|
||||
&ws_protocol_acurite_986,
|
||||
&ws_protocol_lacrosse_tx,
|
||||
&ws_protocol_lacrosse_tx141thbv2,
|
||||
&ws_protocol_oregon2,
|
||||
@@ -60,6 +61,7 @@ const SubGhzProtocol* subghz_protocol_registry_items[] = {
|
||||
&ws_protocol_tx_8300,
|
||||
&ws_protocol_wendox_w6726,
|
||||
&ws_protocol_auriol_ahfl,
|
||||
&ws_protocol_kedsum_th,
|
||||
&subghz_protocol_pocsag,
|
||||
&tpms_protocol_schrader_gg4,
|
||||
&subghz_protocol_bin_raw,
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
#include "gt_wt_03.h"
|
||||
#include "acurite_606tx.h"
|
||||
#include "acurite_609txc.h"
|
||||
#include "acurite_986.h"
|
||||
#include "lacrosse_tx.h"
|
||||
#include "lacrosse_tx141thbv2.h"
|
||||
#include "oregon2.h"
|
||||
@@ -61,6 +62,7 @@
|
||||
#include "tx_8300.h"
|
||||
#include "wendox_w6726.h"
|
||||
#include "auriol_ahfl.h"
|
||||
#include "kedsum_th.h"
|
||||
#include "pocsag.h"
|
||||
#include "schrader_gg4.h"
|
||||
#include "bin_raw.h"
|
||||
|
||||
Reference in New Issue
Block a user