[FL-3097] fbt, faploader: minimal app module implementation (#2420)
* fbt, faploader: minimal app module implementation * faploader, libs: moved API hashtable core to flipper_application * example: compound api * lib: flipper_application: naming fixes, doxygen comments * fbt: changed `requires` manifest field behavior for app extensions * examples: refactored plugin apps; faploader: changed new API naming; fbt: changed PLUGIN app type meaning * loader: dropped support for debug apps & plugin menus * moved applications/plugins -> applications/external * Restored x bit on chiplist_convert.py * git: fixed free-dap submodule path * pvs: updated submodule paths * examples: example_advanced_plugins.c: removed potential memory leak on errors * examples: example_plugins: refined requires * fbt: not deploying app modules for debug/sample apps; extra validation for .PLUGIN-type apps * apps: removed cdefines for external apps * fbt: moved ext app path definition * fbt: reworked fap_dist handling; f18: synced api_symbols.csv * fbt: removed resources_paths for extapps * scripts: reworked storage * scripts: reworked runfap.py & selfupdate.py to use new api * wip: fal runner * fbt: moved file packaging into separate module * scripts: storage: fixes * scripts: storage: minor fixes for new api * fbt: changed internal artifact storage details for external apps * scripts: storage: additional fixes and better error reporting; examples: using APP_DATA_PATH() * fbt, scripts: reworked launch_app to deploy plugins; moved old runfap.py to distfap.py * fbt: extra check for plugins descriptors * fbt: additional checks in emitter * fbt: better info message on SDK rebuild * scripts: removed requirements.txt * loader: removed remnants of plugins & debug menus * post-review fixes
This commit is contained in:
298
applications/external/weather_station/protocols/acurite_592txr.c
vendored
Normal file
298
applications/external/weather_station/protocols/acurite_592txr.c
vendored
Normal file
@@ -0,0 +1,298 @@
|
||||
#include "acurite_592txr.h"
|
||||
|
||||
#define TAG "WSProtocolAcurite_592TXR"
|
||||
|
||||
/*
|
||||
* Help
|
||||
* https://github.com/merbanan/rtl_433/blob/master/src/devices/acurite.c
|
||||
*
|
||||
* Acurite 592TXR Temperature Humidity sensor decoder
|
||||
* Message Type 0x04, 7 bytes
|
||||
* | Byte 0 | Byte 1 | Byte 2 | Byte 3 | Byte 4 | Byte 5 | Byte 6 |
|
||||
* | --------- | --------- | --------- | --------- | --------- | --------- | --------- |
|
||||
* | CCII IIII | IIII IIII | pB00 0100 | pHHH HHHH | p??T TTTT | pTTT TTTT | KKKK KKKK |
|
||||
* - C: Channel 00: C, 10: B, 11: A, (01 is invalid)
|
||||
* - I: Device ID (14 bits)
|
||||
* - B: Battery, 1 is battery OK, 0 is battery low
|
||||
* - M: Message type (6 bits), 0x04
|
||||
* - T: Temperature Celsius (11 - 14 bits?), + 1000 * 10
|
||||
* - H: Relative Humidity (%) (7 bits)
|
||||
* - K: Checksum (8 bits)
|
||||
* - p: Parity bit
|
||||
* Notes:
|
||||
* - Temperature
|
||||
* - Encoded as Celsius + 1000 * 10
|
||||
* - only 11 bits needed for specified range -40 C to 70 C (-40 F - 158 F)
|
||||
* - However 14 bits available for temperature, giving possible range of -100 C to 1538.4 C
|
||||
* - @todo - check if high 3 bits ever used for anything else
|
||||
*
|
||||
*/
|
||||
|
||||
static const SubGhzBlockConst ws_protocol_acurite_592txr_const = {
|
||||
.te_short = 200,
|
||||
.te_long = 400,
|
||||
.te_delta = 90,
|
||||
.min_count_bit_for_found = 56,
|
||||
};
|
||||
|
||||
struct WSProtocolDecoderAcurite_592TXR {
|
||||
SubGhzProtocolDecoderBase base;
|
||||
|
||||
SubGhzBlockDecoder decoder;
|
||||
WSBlockGeneric generic;
|
||||
|
||||
uint16_t header_count;
|
||||
};
|
||||
|
||||
struct WSProtocolEncoderAcurite_592TXR {
|
||||
SubGhzProtocolEncoderBase base;
|
||||
|
||||
SubGhzProtocolBlockEncoder encoder;
|
||||
WSBlockGeneric generic;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
Acurite_592TXRDecoderStepReset = 0,
|
||||
Acurite_592TXRDecoderStepCheckPreambule,
|
||||
Acurite_592TXRDecoderStepSaveDuration,
|
||||
Acurite_592TXRDecoderStepCheckDuration,
|
||||
} Acurite_592TXRDecoderStep;
|
||||
|
||||
const SubGhzProtocolDecoder ws_protocol_acurite_592txr_decoder = {
|
||||
.alloc = ws_protocol_decoder_acurite_592txr_alloc,
|
||||
.free = ws_protocol_decoder_acurite_592txr_free,
|
||||
|
||||
.feed = ws_protocol_decoder_acurite_592txr_feed,
|
||||
.reset = ws_protocol_decoder_acurite_592txr_reset,
|
||||
|
||||
.get_hash_data = ws_protocol_decoder_acurite_592txr_get_hash_data,
|
||||
.serialize = ws_protocol_decoder_acurite_592txr_serialize,
|
||||
.deserialize = ws_protocol_decoder_acurite_592txr_deserialize,
|
||||
.get_string = ws_protocol_decoder_acurite_592txr_get_string,
|
||||
};
|
||||
|
||||
const SubGhzProtocolEncoder ws_protocol_acurite_592txr_encoder = {
|
||||
.alloc = NULL,
|
||||
.free = NULL,
|
||||
|
||||
.deserialize = NULL,
|
||||
.stop = NULL,
|
||||
.yield = NULL,
|
||||
};
|
||||
|
||||
const SubGhzProtocol ws_protocol_acurite_592txr = {
|
||||
.name = WS_PROTOCOL_ACURITE_592TXR_NAME,
|
||||
.type = SubGhzProtocolWeatherStation,
|
||||
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_315 | SubGhzProtocolFlag_868 |
|
||||
SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable,
|
||||
|
||||
.decoder = &ws_protocol_acurite_592txr_decoder,
|
||||
.encoder = &ws_protocol_acurite_592txr_encoder,
|
||||
};
|
||||
|
||||
void* ws_protocol_decoder_acurite_592txr_alloc(SubGhzEnvironment* environment) {
|
||||
UNUSED(environment);
|
||||
WSProtocolDecoderAcurite_592TXR* instance = malloc(sizeof(WSProtocolDecoderAcurite_592TXR));
|
||||
instance->base.protocol = &ws_protocol_acurite_592txr;
|
||||
instance->generic.protocol_name = instance->base.protocol->name;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_acurite_592txr_free(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAcurite_592TXR* instance = context;
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_acurite_592txr_reset(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAcurite_592TXR* instance = context;
|
||||
instance->decoder.parser_step = Acurite_592TXRDecoderStepReset;
|
||||
}
|
||||
|
||||
static bool ws_protocol_acurite_592txr_check_crc(WSProtocolDecoderAcurite_592TXR* instance) {
|
||||
uint8_t msg[] = {
|
||||
instance->decoder.decode_data >> 48,
|
||||
instance->decoder.decode_data >> 40,
|
||||
instance->decoder.decode_data >> 32,
|
||||
instance->decoder.decode_data >> 24,
|
||||
instance->decoder.decode_data >> 16,
|
||||
instance->decoder.decode_data >> 8};
|
||||
|
||||
if((subghz_protocol_blocks_add_bytes(msg, 6) ==
|
||||
(uint8_t)(instance->decoder.decode_data & 0xFF)) &&
|
||||
(!subghz_protocol_blocks_parity_bytes(&msg[2], 4))) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Analysis of received data
|
||||
* @param instance Pointer to a WSBlockGeneric* instance
|
||||
*/
|
||||
static void ws_protocol_acurite_592txr_remote_controller(WSBlockGeneric* instance) {
|
||||
uint8_t channel[] = {3, 0, 2, 1};
|
||||
uint8_t channel_raw = ((instance->data >> 54) & 0x03);
|
||||
instance->channel = channel[channel_raw];
|
||||
instance->id = (instance->data >> 40) & 0x3FFF;
|
||||
instance->battery_low = !((instance->data >> 38) & 1);
|
||||
instance->humidity = (instance->data >> 24) & 0x7F;
|
||||
|
||||
uint16_t temp_raw = ((instance->data >> 9) & 0xF80) | ((instance->data >> 8) & 0x7F);
|
||||
instance->temp = ((float)(temp_raw)-1000) / 10.0f;
|
||||
|
||||
instance->btn = WS_NO_BTN;
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_acurite_592txr_feed(void* context, bool level, uint32_t duration) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAcurite_592TXR* instance = context;
|
||||
|
||||
switch(instance->decoder.parser_step) {
|
||||
case Acurite_592TXRDecoderStepReset:
|
||||
if((level) && (DURATION_DIFF(duration, ws_protocol_acurite_592txr_const.te_short * 3) <
|
||||
ws_protocol_acurite_592txr_const.te_delta * 2)) {
|
||||
instance->decoder.parser_step = Acurite_592TXRDecoderStepCheckPreambule;
|
||||
instance->decoder.te_last = duration;
|
||||
instance->header_count = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case Acurite_592TXRDecoderStepCheckPreambule:
|
||||
if(level) {
|
||||
instance->decoder.te_last = duration;
|
||||
} else {
|
||||
if((DURATION_DIFF(
|
||||
instance->decoder.te_last, ws_protocol_acurite_592txr_const.te_short * 3) <
|
||||
ws_protocol_acurite_592txr_const.te_delta * 2) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_acurite_592txr_const.te_short * 3) <
|
||||
ws_protocol_acurite_592txr_const.te_delta * 2)) {
|
||||
//Found preambule
|
||||
instance->header_count++;
|
||||
} else if((instance->header_count > 2) && (instance->header_count < 5)) {
|
||||
if((DURATION_DIFF(
|
||||
instance->decoder.te_last, ws_protocol_acurite_592txr_const.te_short) <
|
||||
ws_protocol_acurite_592txr_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_acurite_592txr_const.te_long) <
|
||||
ws_protocol_acurite_592txr_const.te_delta)) {
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
||||
instance->decoder.parser_step = Acurite_592TXRDecoderStepSaveDuration;
|
||||
} else if(
|
||||
(DURATION_DIFF(
|
||||
instance->decoder.te_last, ws_protocol_acurite_592txr_const.te_long) <
|
||||
ws_protocol_acurite_592txr_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_acurite_592txr_const.te_short) <
|
||||
ws_protocol_acurite_592txr_const.te_delta)) {
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
||||
instance->decoder.parser_step = Acurite_592TXRDecoderStepSaveDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = Acurite_592TXRDecoderStepReset;
|
||||
}
|
||||
} else {
|
||||
instance->decoder.parser_step = Acurite_592TXRDecoderStepReset;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Acurite_592TXRDecoderStepSaveDuration:
|
||||
if(level) {
|
||||
instance->decoder.te_last = duration;
|
||||
instance->decoder.parser_step = Acurite_592TXRDecoderStepCheckDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = Acurite_592TXRDecoderStepReset;
|
||||
}
|
||||
break;
|
||||
|
||||
case Acurite_592TXRDecoderStepCheckDuration:
|
||||
if(!level) {
|
||||
if(duration >= ((uint32_t)ws_protocol_acurite_592txr_const.te_short * 5)) {
|
||||
if((instance->decoder.decode_count_bit ==
|
||||
ws_protocol_acurite_592txr_const.min_count_bit_for_found) &&
|
||||
ws_protocol_acurite_592txr_check_crc(instance)) {
|
||||
instance->generic.data = instance->decoder.decode_data;
|
||||
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
|
||||
ws_protocol_acurite_592txr_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 = Acurite_592TXRDecoderStepReset;
|
||||
break;
|
||||
} else if(
|
||||
(DURATION_DIFF(
|
||||
instance->decoder.te_last, ws_protocol_acurite_592txr_const.te_short) <
|
||||
ws_protocol_acurite_592txr_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_acurite_592txr_const.te_long) <
|
||||
ws_protocol_acurite_592txr_const.te_delta)) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
||||
instance->decoder.parser_step = Acurite_592TXRDecoderStepSaveDuration;
|
||||
} else if(
|
||||
(DURATION_DIFF(
|
||||
instance->decoder.te_last, ws_protocol_acurite_592txr_const.te_long) <
|
||||
ws_protocol_acurite_592txr_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_acurite_592txr_const.te_short) <
|
||||
ws_protocol_acurite_592txr_const.te_delta)) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
||||
instance->decoder.parser_step = Acurite_592TXRDecoderStepSaveDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = Acurite_592TXRDecoderStepReset;
|
||||
}
|
||||
} else {
|
||||
instance->decoder.parser_step = Acurite_592TXRDecoderStepReset;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t ws_protocol_decoder_acurite_592txr_get_hash_data(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAcurite_592TXR* instance = context;
|
||||
return subghz_protocol_blocks_get_hash_data(
|
||||
&instance->decoder, (instance->decoder.decode_count_bit / 8) + 1);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus ws_protocol_decoder_acurite_592txr_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAcurite_592TXR* instance = context;
|
||||
return ws_block_generic_serialize(&instance->generic, flipper_format, preset);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus
|
||||
ws_protocol_decoder_acurite_592txr_deserialize(void* context, FlipperFormat* flipper_format) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAcurite_592TXR* instance = context;
|
||||
return ws_block_generic_deserialize_check_count_bit(
|
||||
&instance->generic,
|
||||
flipper_format,
|
||||
ws_protocol_acurite_592txr_const.min_count_bit_for_found);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_acurite_592txr_get_string(void* context, FuriString* output) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAcurite_592TXR* instance = context;
|
||||
furi_string_printf(
|
||||
output,
|
||||
"%s %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
applications/external/weather_station/protocols/acurite_592txr.h
vendored
Normal file
80
applications/external/weather_station/protocols/acurite_592txr.h
vendored
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_592TXR_NAME "Acurite 592TXR"
|
||||
|
||||
typedef struct WSProtocolDecoderAcurite_592TXR WSProtocolDecoderAcurite_592TXR;
|
||||
typedef struct WSProtocolEncoderAcurite_592TXR WSProtocolEncoderAcurite_592TXR;
|
||||
|
||||
extern const SubGhzProtocolDecoder ws_protocol_acurite_592txr_decoder;
|
||||
extern const SubGhzProtocolEncoder ws_protocol_acurite_592txr_encoder;
|
||||
extern const SubGhzProtocol ws_protocol_acurite_592txr;
|
||||
|
||||
/**
|
||||
* Allocate WSProtocolDecoderAcurite_592TXR.
|
||||
* @param environment Pointer to a SubGhzEnvironment instance
|
||||
* @return WSProtocolDecoderAcurite_592TXR* pointer to a WSProtocolDecoderAcurite_592TXR instance
|
||||
*/
|
||||
void* ws_protocol_decoder_acurite_592txr_alloc(SubGhzEnvironment* environment);
|
||||
|
||||
/**
|
||||
* Free WSProtocolDecoderAcurite_592TXR.
|
||||
* @param context Pointer to a WSProtocolDecoderAcurite_592TXR instance
|
||||
*/
|
||||
void ws_protocol_decoder_acurite_592txr_free(void* context);
|
||||
|
||||
/**
|
||||
* Reset decoder WSProtocolDecoderAcurite_592TXR.
|
||||
* @param context Pointer to a WSProtocolDecoderAcurite_592TXR instance
|
||||
*/
|
||||
void ws_protocol_decoder_acurite_592txr_reset(void* context);
|
||||
|
||||
/**
|
||||
* Parse a raw sequence of levels and durations received from the air.
|
||||
* @param context Pointer to a WSProtocolDecoderAcurite_592TXR instance
|
||||
* @param level Signal level true-high false-low
|
||||
* @param duration Duration of this level in, us
|
||||
*/
|
||||
void ws_protocol_decoder_acurite_592txr_feed(void* context, bool level, uint32_t duration);
|
||||
|
||||
/**
|
||||
* Getting the hash sum of the last randomly received parcel.
|
||||
* @param context Pointer to a WSProtocolDecoderAcurite_592TXR instance
|
||||
* @return hash Hash sum
|
||||
*/
|
||||
uint8_t ws_protocol_decoder_acurite_592txr_get_hash_data(void* context);
|
||||
|
||||
/**
|
||||
* Serialize data WSProtocolDecoderAcurite_592TXR.
|
||||
* @param context Pointer to a WSProtocolDecoderAcurite_592TXR 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_592txr_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset);
|
||||
|
||||
/**
|
||||
* Deserialize data WSProtocolDecoderAcurite_592TXR.
|
||||
* @param context Pointer to a WSProtocolDecoderAcurite_592TXR instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @return status
|
||||
*/
|
||||
SubGhzProtocolStatus
|
||||
ws_protocol_decoder_acurite_592txr_deserialize(void* context, FlipperFormat* flipper_format);
|
||||
|
||||
/**
|
||||
* Getting a textual representation of the received data.
|
||||
* @param context Pointer to a WSProtocolDecoderAcurite_592TXR instance
|
||||
* @param output Resulting text
|
||||
*/
|
||||
void ws_protocol_decoder_acurite_592txr_get_string(void* context, FuriString* output);
|
239
applications/external/weather_station/protocols/acurite_606tx.c
vendored
Normal file
239
applications/external/weather_station/protocols/acurite_606tx.c
vendored
Normal file
@@ -0,0 +1,239 @@
|
||||
#include "acurite_606tx.h"
|
||||
|
||||
#define TAG "WSProtocolAcurite_606TX"
|
||||
|
||||
/*
|
||||
* Help
|
||||
* https://github.com/merbanan/rtl_433/blob/5bef4e43133ac4c0e2d18d36f87c52b4f9458453/src/devices/acurite.c#L1644
|
||||
*
|
||||
* 0000 1111 | 0011 0000 | 0101 1100 | 1110 0111
|
||||
* iiii iiii | buuu tttt | tttt tttt | cccc cccc
|
||||
* - i: identification; changes on battery switch
|
||||
* - c: lfsr_digest8;
|
||||
* - u: unknown;
|
||||
* - b: battery low; flag to indicate low battery voltage
|
||||
* - t: Temperature; in °C
|
||||
*
|
||||
*/
|
||||
|
||||
static const SubGhzBlockConst ws_protocol_acurite_606tx_const = {
|
||||
.te_short = 500,
|
||||
.te_long = 2000,
|
||||
.te_delta = 150,
|
||||
.min_count_bit_for_found = 32,
|
||||
};
|
||||
|
||||
struct WSProtocolDecoderAcurite_606TX {
|
||||
SubGhzProtocolDecoderBase base;
|
||||
|
||||
SubGhzBlockDecoder decoder;
|
||||
WSBlockGeneric generic;
|
||||
};
|
||||
|
||||
struct WSProtocolEncoderAcurite_606TX {
|
||||
SubGhzProtocolEncoderBase base;
|
||||
|
||||
SubGhzProtocolBlockEncoder encoder;
|
||||
WSBlockGeneric generic;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
Acurite_606TXDecoderStepReset = 0,
|
||||
Acurite_606TXDecoderStepSaveDuration,
|
||||
Acurite_606TXDecoderStepCheckDuration,
|
||||
} Acurite_606TXDecoderStep;
|
||||
|
||||
const SubGhzProtocolDecoder ws_protocol_acurite_606tx_decoder = {
|
||||
.alloc = ws_protocol_decoder_acurite_606tx_alloc,
|
||||
.free = ws_protocol_decoder_acurite_606tx_free,
|
||||
|
||||
.feed = ws_protocol_decoder_acurite_606tx_feed,
|
||||
.reset = ws_protocol_decoder_acurite_606tx_reset,
|
||||
|
||||
.get_hash_data = ws_protocol_decoder_acurite_606tx_get_hash_data,
|
||||
.serialize = ws_protocol_decoder_acurite_606tx_serialize,
|
||||
.deserialize = ws_protocol_decoder_acurite_606tx_deserialize,
|
||||
.get_string = ws_protocol_decoder_acurite_606tx_get_string,
|
||||
};
|
||||
|
||||
const SubGhzProtocolEncoder ws_protocol_acurite_606tx_encoder = {
|
||||
.alloc = NULL,
|
||||
.free = NULL,
|
||||
|
||||
.deserialize = NULL,
|
||||
.stop = NULL,
|
||||
.yield = NULL,
|
||||
};
|
||||
|
||||
const SubGhzProtocol ws_protocol_acurite_606tx = {
|
||||
.name = WS_PROTOCOL_ACURITE_606TX_NAME,
|
||||
.type = SubGhzProtocolWeatherStation,
|
||||
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_315 | SubGhzProtocolFlag_868 |
|
||||
SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable,
|
||||
|
||||
.decoder = &ws_protocol_acurite_606tx_decoder,
|
||||
.encoder = &ws_protocol_acurite_606tx_encoder,
|
||||
};
|
||||
|
||||
void* ws_protocol_decoder_acurite_606tx_alloc(SubGhzEnvironment* environment) {
|
||||
UNUSED(environment);
|
||||
WSProtocolDecoderAcurite_606TX* instance = malloc(sizeof(WSProtocolDecoderAcurite_606TX));
|
||||
instance->base.protocol = &ws_protocol_acurite_606tx;
|
||||
instance->generic.protocol_name = instance->base.protocol->name;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_acurite_606tx_free(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAcurite_606TX* instance = context;
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_acurite_606tx_reset(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAcurite_606TX* instance = context;
|
||||
instance->decoder.parser_step = Acurite_606TXDecoderStepReset;
|
||||
}
|
||||
|
||||
static bool ws_protocol_acurite_606tx_check(WSProtocolDecoderAcurite_606TX* instance) {
|
||||
if(!instance->decoder.decode_data) return false;
|
||||
uint8_t msg[] = {
|
||||
instance->decoder.decode_data >> 24,
|
||||
instance->decoder.decode_data >> 16,
|
||||
instance->decoder.decode_data >> 8};
|
||||
|
||||
uint8_t crc = subghz_protocol_blocks_lfsr_digest8(msg, 3, 0x98, 0xF1);
|
||||
return (crc == (instance->decoder.decode_data & 0xFF));
|
||||
}
|
||||
|
||||
/**
|
||||
* Analysis of received data
|
||||
* @param instance Pointer to a WSBlockGeneric* instance
|
||||
*/
|
||||
static void ws_protocol_acurite_606tx_remote_controller(WSBlockGeneric* instance) {
|
||||
instance->id = (instance->data >> 24) & 0xFF;
|
||||
instance->battery_low = (instance->data >> 23) & 1;
|
||||
|
||||
instance->channel = WS_NO_CHANNEL;
|
||||
|
||||
if(!((instance->data >> 19) & 1)) {
|
||||
instance->temp = (float)((instance->data >> 8) & 0x07FF) / 10.0f;
|
||||
} else {
|
||||
instance->temp = (float)((~(instance->data >> 8) & 0x07FF) + 1) / -10.0f;
|
||||
}
|
||||
instance->btn = WS_NO_BTN;
|
||||
instance->humidity = WS_NO_HUMIDITY;
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_acurite_606tx_feed(void* context, bool level, uint32_t duration) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAcurite_606TX* instance = context;
|
||||
|
||||
switch(instance->decoder.parser_step) {
|
||||
case Acurite_606TXDecoderStepReset:
|
||||
if((!level) && (DURATION_DIFF(duration, ws_protocol_acurite_606tx_const.te_short * 17) <
|
||||
ws_protocol_acurite_606tx_const.te_delta * 8)) {
|
||||
//Found syncPrefix
|
||||
instance->decoder.parser_step = Acurite_606TXDecoderStepSaveDuration;
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case Acurite_606TXDecoderStepSaveDuration:
|
||||
if(level) {
|
||||
instance->decoder.te_last = duration;
|
||||
instance->decoder.parser_step = Acurite_606TXDecoderStepCheckDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = Acurite_606TXDecoderStepReset;
|
||||
}
|
||||
break;
|
||||
|
||||
case Acurite_606TXDecoderStepCheckDuration:
|
||||
if(!level) {
|
||||
if(DURATION_DIFF(instance->decoder.te_last, ws_protocol_acurite_606tx_const.te_short) <
|
||||
ws_protocol_acurite_606tx_const.te_delta) {
|
||||
if((DURATION_DIFF(duration, ws_protocol_acurite_606tx_const.te_short) <
|
||||
ws_protocol_acurite_606tx_const.te_delta) ||
|
||||
(duration > ws_protocol_acurite_606tx_const.te_long * 3)) {
|
||||
//Found syncPostfix
|
||||
instance->decoder.parser_step = Acurite_606TXDecoderStepReset;
|
||||
if((instance->decoder.decode_count_bit ==
|
||||
ws_protocol_acurite_606tx_const.min_count_bit_for_found) &&
|
||||
ws_protocol_acurite_606tx_check(instance)) {
|
||||
instance->generic.data = instance->decoder.decode_data;
|
||||
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
|
||||
ws_protocol_acurite_606tx_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 if(
|
||||
DURATION_DIFF(duration, ws_protocol_acurite_606tx_const.te_long) <
|
||||
ws_protocol_acurite_606tx_const.te_delta * 2) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
||||
instance->decoder.parser_step = Acurite_606TXDecoderStepSaveDuration;
|
||||
} else if(
|
||||
DURATION_DIFF(duration, ws_protocol_acurite_606tx_const.te_long * 2) <
|
||||
ws_protocol_acurite_606tx_const.te_delta * 4) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
||||
instance->decoder.parser_step = Acurite_606TXDecoderStepSaveDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = Acurite_606TXDecoderStepReset;
|
||||
}
|
||||
} else {
|
||||
instance->decoder.parser_step = Acurite_606TXDecoderStepReset;
|
||||
}
|
||||
} else {
|
||||
instance->decoder.parser_step = Acurite_606TXDecoderStepReset;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t ws_protocol_decoder_acurite_606tx_get_hash_data(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAcurite_606TX* instance = context;
|
||||
return subghz_protocol_blocks_get_hash_data(
|
||||
&instance->decoder, (instance->decoder.decode_count_bit / 8) + 1);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus ws_protocol_decoder_acurite_606tx_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAcurite_606TX* instance = context;
|
||||
return ws_block_generic_serialize(&instance->generic, flipper_format, preset);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus
|
||||
ws_protocol_decoder_acurite_606tx_deserialize(void* context, FlipperFormat* flipper_format) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAcurite_606TX* instance = context;
|
||||
return ws_block_generic_deserialize_check_count_bit(
|
||||
&instance->generic,
|
||||
flipper_format,
|
||||
ws_protocol_acurite_606tx_const.min_count_bit_for_found);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_acurite_606tx_get_string(void* context, FuriString* output) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAcurite_606TX* instance = context;
|
||||
furi_string_printf(
|
||||
output,
|
||||
"%s %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
applications/external/weather_station/protocols/acurite_606tx.h
vendored
Normal file
80
applications/external/weather_station/protocols/acurite_606tx.h
vendored
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_606TX_NAME "Acurite-606TX"
|
||||
|
||||
typedef struct WSProtocolDecoderAcurite_606TX WSProtocolDecoderAcurite_606TX;
|
||||
typedef struct WSProtocolEncoderAcurite_606TX WSProtocolEncoderAcurite_606TX;
|
||||
|
||||
extern const SubGhzProtocolDecoder ws_protocol_acurite_606tx_decoder;
|
||||
extern const SubGhzProtocolEncoder ws_protocol_acurite_606tx_encoder;
|
||||
extern const SubGhzProtocol ws_protocol_acurite_606tx;
|
||||
|
||||
/**
|
||||
* Allocate WSProtocolDecoderAcurite_606TX.
|
||||
* @param environment Pointer to a SubGhzEnvironment instance
|
||||
* @return WSProtocolDecoderAcurite_606TX* pointer to a WSProtocolDecoderAcurite_606TX instance
|
||||
*/
|
||||
void* ws_protocol_decoder_acurite_606tx_alloc(SubGhzEnvironment* environment);
|
||||
|
||||
/**
|
||||
* Free WSProtocolDecoderAcurite_606TX.
|
||||
* @param context Pointer to a WSProtocolDecoderAcurite_606TX instance
|
||||
*/
|
||||
void ws_protocol_decoder_acurite_606tx_free(void* context);
|
||||
|
||||
/**
|
||||
* Reset decoder WSProtocolDecoderAcurite_606TX.
|
||||
* @param context Pointer to a WSProtocolDecoderAcurite_606TX instance
|
||||
*/
|
||||
void ws_protocol_decoder_acurite_606tx_reset(void* context);
|
||||
|
||||
/**
|
||||
* Parse a raw sequence of levels and durations received from the air.
|
||||
* @param context Pointer to a WSProtocolDecoderAcurite_606TX instance
|
||||
* @param level Signal level true-high false-low
|
||||
* @param duration Duration of this level in, us
|
||||
*/
|
||||
void ws_protocol_decoder_acurite_606tx_feed(void* context, bool level, uint32_t duration);
|
||||
|
||||
/**
|
||||
* Getting the hash sum of the last randomly received parcel.
|
||||
* @param context Pointer to a WSProtocolDecoderAcurite_606TX instance
|
||||
* @return hash Hash sum
|
||||
*/
|
||||
uint8_t ws_protocol_decoder_acurite_606tx_get_hash_data(void* context);
|
||||
|
||||
/**
|
||||
* Serialize data WSProtocolDecoderAcurite_606TX.
|
||||
* @param context Pointer to a WSProtocolDecoderAcurite_606TX 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_606tx_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset);
|
||||
|
||||
/**
|
||||
* Deserialize data WSProtocolDecoderAcurite_606TX.
|
||||
* @param context Pointer to a WSProtocolDecoderAcurite_606TX instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @return status
|
||||
*/
|
||||
SubGhzProtocolStatus
|
||||
ws_protocol_decoder_acurite_606tx_deserialize(void* context, FlipperFormat* flipper_format);
|
||||
|
||||
/**
|
||||
* Getting a textual representation of the received data.
|
||||
* @param context Pointer to a WSProtocolDecoderAcurite_606TX instance
|
||||
* @param output Resulting text
|
||||
*/
|
||||
void ws_protocol_decoder_acurite_606tx_get_string(void* context, FuriString* output);
|
239
applications/external/weather_station/protocols/acurite_609txc.c
vendored
Normal file
239
applications/external/weather_station/protocols/acurite_609txc.c
vendored
Normal file
@@ -0,0 +1,239 @@
|
||||
#include "acurite_609txc.h"
|
||||
|
||||
#define TAG "WSProtocolAcurite_609TXC"
|
||||
|
||||
/*
|
||||
* Help
|
||||
* https://github.com/merbanan/rtl_433/blob/5bef4e43133ac4c0e2d18d36f87c52b4f9458453/src/devices/acurite.c#L216
|
||||
*
|
||||
* 0000 1111 | 0011 0000 | 0101 1100 | 0000 0000 | 1110 0111
|
||||
* iiii iiii | buuu tttt | tttt tttt | hhhh hhhh | cccc cccc
|
||||
* - i: identification; changes on battery switch
|
||||
* - c: checksum (sum of previous by bytes)
|
||||
* - u: unknown
|
||||
* - b: battery low; flag to indicate low battery voltage
|
||||
* - t: temperature; in °C * 10, 12 bit with complement
|
||||
* - h: humidity
|
||||
*
|
||||
*/
|
||||
|
||||
static const SubGhzBlockConst ws_protocol_acurite_609txc_const = {
|
||||
.te_short = 500,
|
||||
.te_long = 1000,
|
||||
.te_delta = 150,
|
||||
.min_count_bit_for_found = 40,
|
||||
};
|
||||
|
||||
struct WSProtocolDecoderAcurite_609TXC {
|
||||
SubGhzProtocolDecoderBase base;
|
||||
|
||||
SubGhzBlockDecoder decoder;
|
||||
WSBlockGeneric generic;
|
||||
};
|
||||
|
||||
struct WSProtocolEncoderAcurite_609TXC {
|
||||
SubGhzProtocolEncoderBase base;
|
||||
|
||||
SubGhzProtocolBlockEncoder encoder;
|
||||
WSBlockGeneric generic;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
Acurite_609TXCDecoderStepReset = 0,
|
||||
Acurite_609TXCDecoderStepSaveDuration,
|
||||
Acurite_609TXCDecoderStepCheckDuration,
|
||||
} Acurite_609TXCDecoderStep;
|
||||
|
||||
const SubGhzProtocolDecoder ws_protocol_acurite_609txc_decoder = {
|
||||
.alloc = ws_protocol_decoder_acurite_609txc_alloc,
|
||||
.free = ws_protocol_decoder_acurite_609txc_free,
|
||||
|
||||
.feed = ws_protocol_decoder_acurite_609txc_feed,
|
||||
.reset = ws_protocol_decoder_acurite_609txc_reset,
|
||||
|
||||
.get_hash_data = ws_protocol_decoder_acurite_609txc_get_hash_data,
|
||||
.serialize = ws_protocol_decoder_acurite_609txc_serialize,
|
||||
.deserialize = ws_protocol_decoder_acurite_609txc_deserialize,
|
||||
.get_string = ws_protocol_decoder_acurite_609txc_get_string,
|
||||
};
|
||||
|
||||
const SubGhzProtocolEncoder ws_protocol_acurite_609txc_encoder = {
|
||||
.alloc = NULL,
|
||||
.free = NULL,
|
||||
|
||||
.deserialize = NULL,
|
||||
.stop = NULL,
|
||||
.yield = NULL,
|
||||
};
|
||||
|
||||
const SubGhzProtocol ws_protocol_acurite_609txc = {
|
||||
.name = WS_PROTOCOL_ACURITE_609TXC_NAME,
|
||||
.type = SubGhzProtocolWeatherStation,
|
||||
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_315 | SubGhzProtocolFlag_868 |
|
||||
SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable,
|
||||
|
||||
.decoder = &ws_protocol_acurite_609txc_decoder,
|
||||
.encoder = &ws_protocol_acurite_609txc_encoder,
|
||||
};
|
||||
|
||||
void* ws_protocol_decoder_acurite_609txc_alloc(SubGhzEnvironment* environment) {
|
||||
UNUSED(environment);
|
||||
WSProtocolDecoderAcurite_609TXC* instance = malloc(sizeof(WSProtocolDecoderAcurite_609TXC));
|
||||
instance->base.protocol = &ws_protocol_acurite_609txc;
|
||||
instance->generic.protocol_name = instance->base.protocol->name;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_acurite_609txc_free(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAcurite_609TXC* instance = context;
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_acurite_609txc_reset(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAcurite_609TXC* instance = context;
|
||||
instance->decoder.parser_step = Acurite_609TXCDecoderStepReset;
|
||||
}
|
||||
|
||||
static bool ws_protocol_acurite_609txc_check(WSProtocolDecoderAcurite_609TXC* instance) {
|
||||
if(!instance->decoder.decode_data) return false;
|
||||
uint8_t crc = (uint8_t)(instance->decoder.decode_data >> 32) +
|
||||
(uint8_t)(instance->decoder.decode_data >> 24) +
|
||||
(uint8_t)(instance->decoder.decode_data >> 16) +
|
||||
(uint8_t)(instance->decoder.decode_data >> 8);
|
||||
return (crc == (instance->decoder.decode_data & 0xFF));
|
||||
}
|
||||
|
||||
/**
|
||||
* Analysis of received data
|
||||
* @param instance Pointer to a WSBlockGeneric* instance
|
||||
*/
|
||||
static void ws_protocol_acurite_609txc_remote_controller(WSBlockGeneric* instance) {
|
||||
instance->id = (instance->data >> 32) & 0xFF;
|
||||
instance->battery_low = (instance->data >> 31) & 1;
|
||||
|
||||
instance->channel = WS_NO_CHANNEL;
|
||||
|
||||
// Temperature in Celsius is encoded as a 12 bit integer value
|
||||
// multiplied by 10 using the 4th - 6th nybbles (bytes 1 & 2)
|
||||
// negative values are recovered by sign extend from int16_t.
|
||||
int16_t temp_raw =
|
||||
(int16_t)(((instance->data >> 12) & 0xf000) | ((instance->data >> 16) << 4));
|
||||
instance->temp = (temp_raw >> 4) * 0.1f;
|
||||
instance->humidity = (instance->data >> 8) & 0xff;
|
||||
instance->btn = WS_NO_BTN;
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_acurite_609txc_feed(void* context, bool level, uint32_t duration) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAcurite_609TXC* instance = context;
|
||||
|
||||
switch(instance->decoder.parser_step) {
|
||||
case Acurite_609TXCDecoderStepReset:
|
||||
if((!level) && (DURATION_DIFF(duration, ws_protocol_acurite_609txc_const.te_short * 17) <
|
||||
ws_protocol_acurite_609txc_const.te_delta * 8)) {
|
||||
//Found syncPrefix
|
||||
instance->decoder.parser_step = Acurite_609TXCDecoderStepSaveDuration;
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case Acurite_609TXCDecoderStepSaveDuration:
|
||||
if(level) {
|
||||
instance->decoder.te_last = duration;
|
||||
instance->decoder.parser_step = Acurite_609TXCDecoderStepCheckDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = Acurite_609TXCDecoderStepReset;
|
||||
}
|
||||
break;
|
||||
|
||||
case Acurite_609TXCDecoderStepCheckDuration:
|
||||
if(!level) {
|
||||
if(DURATION_DIFF(instance->decoder.te_last, ws_protocol_acurite_609txc_const.te_short) <
|
||||
ws_protocol_acurite_609txc_const.te_delta) {
|
||||
if((DURATION_DIFF(duration, ws_protocol_acurite_609txc_const.te_short) <
|
||||
ws_protocol_acurite_609txc_const.te_delta) ||
|
||||
(duration > ws_protocol_acurite_609txc_const.te_long * 3)) {
|
||||
//Found syncPostfix
|
||||
instance->decoder.parser_step = Acurite_609TXCDecoderStepReset;
|
||||
if((instance->decoder.decode_count_bit ==
|
||||
ws_protocol_acurite_609txc_const.min_count_bit_for_found) &&
|
||||
ws_protocol_acurite_609txc_check(instance)) {
|
||||
instance->generic.data = instance->decoder.decode_data;
|
||||
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
|
||||
ws_protocol_acurite_609txc_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 if(
|
||||
DURATION_DIFF(duration, ws_protocol_acurite_609txc_const.te_long) <
|
||||
ws_protocol_acurite_609txc_const.te_delta * 2) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
||||
instance->decoder.parser_step = Acurite_609TXCDecoderStepSaveDuration;
|
||||
} else if(
|
||||
DURATION_DIFF(duration, ws_protocol_acurite_609txc_const.te_long * 2) <
|
||||
ws_protocol_acurite_609txc_const.te_delta * 4) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
||||
instance->decoder.parser_step = Acurite_609TXCDecoderStepSaveDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = Acurite_609TXCDecoderStepReset;
|
||||
}
|
||||
} else {
|
||||
instance->decoder.parser_step = Acurite_609TXCDecoderStepReset;
|
||||
}
|
||||
} else {
|
||||
instance->decoder.parser_step = Acurite_609TXCDecoderStepReset;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t ws_protocol_decoder_acurite_609txc_get_hash_data(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAcurite_609TXC* instance = context;
|
||||
return subghz_protocol_blocks_get_hash_data(
|
||||
&instance->decoder, (instance->decoder.decode_count_bit / 8) + 1);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus ws_protocol_decoder_acurite_609txc_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAcurite_609TXC* instance = context;
|
||||
return ws_block_generic_serialize(&instance->generic, flipper_format, preset);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus
|
||||
ws_protocol_decoder_acurite_609txc_deserialize(void* context, FlipperFormat* flipper_format) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAcurite_609TXC* instance = context;
|
||||
return ws_block_generic_deserialize_check_count_bit(
|
||||
&instance->generic,
|
||||
flipper_format,
|
||||
ws_protocol_acurite_609txc_const.min_count_bit_for_found);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_acurite_609txc_get_string(void* context, FuriString* output) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAcurite_609TXC* instance = context;
|
||||
furi_string_printf(
|
||||
output,
|
||||
"%s %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 >> 40),
|
||||
(uint32_t)(instance->generic.data),
|
||||
instance->generic.id,
|
||||
instance->generic.channel,
|
||||
instance->generic.battery_low,
|
||||
(double)instance->generic.temp,
|
||||
instance->generic.humidity);
|
||||
}
|
80
applications/external/weather_station/protocols/acurite_609txc.h
vendored
Normal file
80
applications/external/weather_station/protocols/acurite_609txc.h
vendored
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_609TXC_NAME "Acurite-609TXC"
|
||||
|
||||
typedef struct WSProtocolDecoderAcurite_609TXC WSProtocolDecoderAcurite_609TXC;
|
||||
typedef struct WSProtocolEncoderAcurite_609TXC WSProtocolEncoderAcurite_609TXC;
|
||||
|
||||
extern const SubGhzProtocolDecoder ws_protocol_acurite_609txc_decoder;
|
||||
extern const SubGhzProtocolEncoder ws_protocol_acurite_609txc_encoder;
|
||||
extern const SubGhzProtocol ws_protocol_acurite_609txc;
|
||||
|
||||
/**
|
||||
* Allocate WSProtocolDecoderAcurite_609TXC.
|
||||
* @param environment Pointer to a SubGhzEnvironment instance
|
||||
* @return WSProtocolDecoderAcurite_609TXC* pointer to a WSProtocolDecoderAcurite_609TXC instance
|
||||
*/
|
||||
void* ws_protocol_decoder_acurite_609txc_alloc(SubGhzEnvironment* environment);
|
||||
|
||||
/**
|
||||
* Free WSProtocolDecoderAcurite_609TXC.
|
||||
* @param context Pointer to a WSProtocolDecoderAcurite_609TXC instance
|
||||
*/
|
||||
void ws_protocol_decoder_acurite_609txc_free(void* context);
|
||||
|
||||
/**
|
||||
* Reset decoder WSProtocolDecoderAcurite_609TXC.
|
||||
* @param context Pointer to a WSProtocolDecoderAcurite_609TXC instance
|
||||
*/
|
||||
void ws_protocol_decoder_acurite_609txc_reset(void* context);
|
||||
|
||||
/**
|
||||
* Parse a raw sequence of levels and durations received from the air.
|
||||
* @param context Pointer to a WSProtocolDecoderAcurite_609TXC instance
|
||||
* @param level Signal level true-high false-low
|
||||
* @param duration Duration of this level in, us
|
||||
*/
|
||||
void ws_protocol_decoder_acurite_609txc_feed(void* context, bool level, uint32_t duration);
|
||||
|
||||
/**
|
||||
* Getting the hash sum of the last randomly received parcel.
|
||||
* @param context Pointer to a WSProtocolDecoderAcurite_609TXC instance
|
||||
* @return hash Hash sum
|
||||
*/
|
||||
uint8_t ws_protocol_decoder_acurite_609txc_get_hash_data(void* context);
|
||||
|
||||
/**
|
||||
* Serialize data WSProtocolDecoderAcurite_609TXC.
|
||||
* @param context Pointer to a WSProtocolDecoderAcurite_609TXC 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_609txc_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset);
|
||||
|
||||
/**
|
||||
* Deserialize data WSProtocolDecoderAcurite_609TXC.
|
||||
* @param context Pointer to a WSProtocolDecoderAcurite_609TXC instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @return status
|
||||
*/
|
||||
SubGhzProtocolStatus
|
||||
ws_protocol_decoder_acurite_609txc_deserialize(void* context, FlipperFormat* flipper_format);
|
||||
|
||||
/**
|
||||
* Getting a textual representation of the received data.
|
||||
* @param context Pointer to a WSProtocolDecoderAcurite_609TXC instance
|
||||
* @param output Resulting text
|
||||
*/
|
||||
void ws_protocol_decoder_acurite_609txc_get_string(void* context, FuriString* output);
|
268
applications/external/weather_station/protocols/ambient_weather.c
vendored
Normal file
268
applications/external/weather_station/protocols/ambient_weather.c
vendored
Normal file
@@ -0,0 +1,268 @@
|
||||
#include "ambient_weather.h"
|
||||
#include <lib/toolbox/manchester_decoder.h>
|
||||
|
||||
#define TAG "WSProtocolAmbient_Weather"
|
||||
|
||||
/*
|
||||
* Help
|
||||
* https://github.com/merbanan/rtl_433/blob/master/src/devices/ambient_weather.c
|
||||
*
|
||||
* Decode Ambient Weather F007TH, F012TH, TF 30.3208.02, SwitchDoc F016TH.
|
||||
* Devices supported:
|
||||
* - Ambient Weather F007TH Thermo-Hygrometer.
|
||||
* - Ambient Weather F012TH Indoor/Display Thermo-Hygrometer.
|
||||
* - TFA senders 30.3208.02 from the TFA "Klima-Monitor" 30.3054,
|
||||
* - SwitchDoc Labs F016TH.
|
||||
* This decoder handles the 433mhz/868mhz thermo-hygrometers.
|
||||
* The 915mhz (WH*) family of devices use different modulation/encoding.
|
||||
* Byte 0 Byte 1 Byte 2 Byte 3 Byte 4 Byte 5
|
||||
* xxxxMMMM IIIIIIII BCCCTTTT TTTTTTTT HHHHHHHH MMMMMMMM
|
||||
* - x: Unknown 0x04 on F007TH/F012TH
|
||||
* - M: Model Number?, 0x05 on F007TH/F012TH/SwitchDocLabs F016TH
|
||||
* - I: ID byte (8 bits), volatie, changes at power up,
|
||||
* - B: Battery Low
|
||||
* - C: Channel (3 bits 1-8) - F007TH set by Dip switch, F012TH soft setting
|
||||
* - T: Temperature 12 bits - Fahrenheit * 10 + 400
|
||||
* - H: Humidity (8 bits)
|
||||
* - M: Message integrity check LFSR Digest-8, gen 0x98, key 0x3e, init 0x64
|
||||
*
|
||||
* three repeats without gap
|
||||
* full preamble is 0x00145 (the last bits might not be fixed, e.g. 0x00146)
|
||||
* and on decoding also 0xffd45
|
||||
*/
|
||||
|
||||
#define AMBIENT_WEATHER_PACKET_HEADER_1 0xFFD440000000000 //0xffd45 .. 0xffd46
|
||||
#define AMBIENT_WEATHER_PACKET_HEADER_2 0x001440000000000 //0x00145 .. 0x00146
|
||||
#define AMBIENT_WEATHER_PACKET_HEADER_MASK 0xFFFFC0000000000
|
||||
|
||||
static const SubGhzBlockConst ws_protocol_ambient_weather_const = {
|
||||
.te_short = 500,
|
||||
.te_long = 1000,
|
||||
.te_delta = 120,
|
||||
.min_count_bit_for_found = 48,
|
||||
};
|
||||
|
||||
struct WSProtocolDecoderAmbient_Weather {
|
||||
SubGhzProtocolDecoderBase base;
|
||||
|
||||
SubGhzBlockDecoder decoder;
|
||||
WSBlockGeneric generic;
|
||||
ManchesterState manchester_saved_state;
|
||||
uint16_t header_count;
|
||||
};
|
||||
|
||||
struct WSProtocolEncoderAmbient_Weather {
|
||||
SubGhzProtocolEncoderBase base;
|
||||
|
||||
SubGhzProtocolBlockEncoder encoder;
|
||||
WSBlockGeneric generic;
|
||||
};
|
||||
|
||||
const SubGhzProtocolDecoder ws_protocol_ambient_weather_decoder = {
|
||||
.alloc = ws_protocol_decoder_ambient_weather_alloc,
|
||||
.free = ws_protocol_decoder_ambient_weather_free,
|
||||
|
||||
.feed = ws_protocol_decoder_ambient_weather_feed,
|
||||
.reset = ws_protocol_decoder_ambient_weather_reset,
|
||||
|
||||
.get_hash_data = ws_protocol_decoder_ambient_weather_get_hash_data,
|
||||
.serialize = ws_protocol_decoder_ambient_weather_serialize,
|
||||
.deserialize = ws_protocol_decoder_ambient_weather_deserialize,
|
||||
.get_string = ws_protocol_decoder_ambient_weather_get_string,
|
||||
};
|
||||
|
||||
const SubGhzProtocolEncoder ws_protocol_ambient_weather_encoder = {
|
||||
.alloc = NULL,
|
||||
.free = NULL,
|
||||
|
||||
.deserialize = NULL,
|
||||
.stop = NULL,
|
||||
.yield = NULL,
|
||||
};
|
||||
|
||||
const SubGhzProtocol ws_protocol_ambient_weather = {
|
||||
.name = WS_PROTOCOL_AMBIENT_WEATHER_NAME,
|
||||
.type = SubGhzProtocolWeatherStation,
|
||||
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_315 | SubGhzProtocolFlag_868 |
|
||||
SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable,
|
||||
|
||||
.decoder = &ws_protocol_ambient_weather_decoder,
|
||||
.encoder = &ws_protocol_ambient_weather_encoder,
|
||||
};
|
||||
|
||||
void* ws_protocol_decoder_ambient_weather_alloc(SubGhzEnvironment* environment) {
|
||||
UNUSED(environment);
|
||||
WSProtocolDecoderAmbient_Weather* instance = malloc(sizeof(WSProtocolDecoderAmbient_Weather));
|
||||
instance->base.protocol = &ws_protocol_ambient_weather;
|
||||
instance->generic.protocol_name = instance->base.protocol->name;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_ambient_weather_free(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAmbient_Weather* instance = context;
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_ambient_weather_reset(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAmbient_Weather* instance = context;
|
||||
manchester_advance(
|
||||
instance->manchester_saved_state,
|
||||
ManchesterEventReset,
|
||||
&instance->manchester_saved_state,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static bool ws_protocol_ambient_weather_check_crc(WSProtocolDecoderAmbient_Weather* instance) {
|
||||
uint8_t msg[] = {
|
||||
instance->decoder.decode_data >> 40,
|
||||
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_lfsr_digest8(msg, 5, 0x98, 0x3e) ^ 0x64;
|
||||
return (crc == (uint8_t)(instance->decoder.decode_data & 0xFF));
|
||||
}
|
||||
|
||||
/**
|
||||
* Analysis of received data
|
||||
* @param instance Pointer to a WSBlockGeneric* instance
|
||||
*/
|
||||
static void ws_protocol_ambient_weather_remote_controller(WSBlockGeneric* instance) {
|
||||
instance->id = (instance->data >> 32) & 0xFF;
|
||||
instance->battery_low = (instance->data >> 31) & 1;
|
||||
instance->channel = ((instance->data >> 28) & 0x07) + 1;
|
||||
instance->temp =
|
||||
locale_fahrenheit_to_celsius(((float)((instance->data >> 16) & 0x0FFF) - 400.0f) / 10.0f);
|
||||
instance->humidity = (instance->data >> 8) & 0xFF;
|
||||
instance->btn = WS_NO_BTN;
|
||||
|
||||
// ToDo maybe it won't be needed
|
||||
/*
|
||||
Sanity checks to reduce false positives and other bad data
|
||||
Packets with Bad data often pass the MIC check.
|
||||
- humidity > 100 (such as 255) and
|
||||
- temperatures > 140 F (such as 369.5 F and 348.8 F
|
||||
Specs in the F007TH and F012TH manuals state the range is:
|
||||
- Temperature: -40 to 140 F
|
||||
- Humidity: 10 to 99%
|
||||
@todo - sanity check b[0] "model number"
|
||||
- 0x45 - F007TH and F012TH
|
||||
- 0x?5 - SwitchDocLabs F016TH temperature sensor (based on comment b[0] & 0x0f == 5)
|
||||
- ? - TFA 30.3208.02
|
||||
if (instance->humidity < 0 || instance->humidity > 100) {
|
||||
ERROR;
|
||||
}
|
||||
|
||||
if (instance->temp < -40.0 || instance->temp > 140.0) {
|
||||
ERROR;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_ambient_weather_feed(void* context, bool level, uint32_t duration) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAmbient_Weather* instance = context;
|
||||
|
||||
ManchesterEvent event = ManchesterEventReset;
|
||||
if(!level) {
|
||||
if(DURATION_DIFF(duration, ws_protocol_ambient_weather_const.te_short) <
|
||||
ws_protocol_ambient_weather_const.te_delta) {
|
||||
event = ManchesterEventShortLow;
|
||||
} else if(
|
||||
DURATION_DIFF(duration, ws_protocol_ambient_weather_const.te_long) <
|
||||
ws_protocol_ambient_weather_const.te_delta * 2) {
|
||||
event = ManchesterEventLongLow;
|
||||
}
|
||||
} else {
|
||||
if(DURATION_DIFF(duration, ws_protocol_ambient_weather_const.te_short) <
|
||||
ws_protocol_ambient_weather_const.te_delta) {
|
||||
event = ManchesterEventShortHigh;
|
||||
} else if(
|
||||
DURATION_DIFF(duration, ws_protocol_ambient_weather_const.te_long) <
|
||||
ws_protocol_ambient_weather_const.te_delta * 2) {
|
||||
event = ManchesterEventLongHigh;
|
||||
}
|
||||
}
|
||||
if(event != ManchesterEventReset) {
|
||||
bool data;
|
||||
bool data_ok = manchester_advance(
|
||||
instance->manchester_saved_state, event, &instance->manchester_saved_state, &data);
|
||||
|
||||
if(data_ok) {
|
||||
instance->decoder.decode_data = (instance->decoder.decode_data << 1) | !data;
|
||||
}
|
||||
|
||||
if(((instance->decoder.decode_data & AMBIENT_WEATHER_PACKET_HEADER_MASK) ==
|
||||
AMBIENT_WEATHER_PACKET_HEADER_1) ||
|
||||
((instance->decoder.decode_data & AMBIENT_WEATHER_PACKET_HEADER_MASK) ==
|
||||
AMBIENT_WEATHER_PACKET_HEADER_2)) {
|
||||
if(ws_protocol_ambient_weather_check_crc(instance)) {
|
||||
instance->generic.data = instance->decoder.decode_data;
|
||||
instance->generic.data_count_bit =
|
||||
ws_protocol_ambient_weather_const.min_count_bit_for_found;
|
||||
ws_protocol_ambient_weather_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.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
manchester_advance(
|
||||
instance->manchester_saved_state,
|
||||
ManchesterEventReset,
|
||||
&instance->manchester_saved_state,
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t ws_protocol_decoder_ambient_weather_get_hash_data(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAmbient_Weather* instance = context;
|
||||
return subghz_protocol_blocks_get_hash_data(
|
||||
&instance->decoder, (instance->decoder.decode_count_bit / 8) + 1);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus ws_protocol_decoder_ambient_weather_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAmbient_Weather* instance = context;
|
||||
return ws_block_generic_serialize(&instance->generic, flipper_format, preset);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus
|
||||
ws_protocol_decoder_ambient_weather_deserialize(void* context, FlipperFormat* flipper_format) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAmbient_Weather* instance = context;
|
||||
return ws_block_generic_deserialize_check_count_bit(
|
||||
&instance->generic,
|
||||
flipper_format,
|
||||
ws_protocol_ambient_weather_const.min_count_bit_for_found);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_ambient_weather_get_string(void* context, FuriString* output) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAmbient_Weather* instance = context;
|
||||
furi_string_printf(
|
||||
output,
|
||||
"%s %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
applications/external/weather_station/protocols/ambient_weather.h
vendored
Normal file
80
applications/external/weather_station/protocols/ambient_weather.h
vendored
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_AMBIENT_WEATHER_NAME "Ambient_Weather"
|
||||
|
||||
typedef struct WSProtocolDecoderAmbient_Weather WSProtocolDecoderAmbient_Weather;
|
||||
typedef struct WSProtocolEncoderAmbient_Weather WSProtocolEncoderAmbient_Weather;
|
||||
|
||||
extern const SubGhzProtocolDecoder ws_protocol_ambient_weather_decoder;
|
||||
extern const SubGhzProtocolEncoder ws_protocol_ambient_weather_encoder;
|
||||
extern const SubGhzProtocol ws_protocol_ambient_weather;
|
||||
|
||||
/**
|
||||
* Allocate WSProtocolDecoderAmbient_Weather.
|
||||
* @param environment Pointer to a SubGhzEnvironment instance
|
||||
* @return WSProtocolDecoderAmbient_Weather* pointer to a WSProtocolDecoderAmbient_Weather instance
|
||||
*/
|
||||
void* ws_protocol_decoder_ambient_weather_alloc(SubGhzEnvironment* environment);
|
||||
|
||||
/**
|
||||
* Free WSProtocolDecoderAmbient_Weather.
|
||||
* @param context Pointer to a WSProtocolDecoderAmbient_Weather instance
|
||||
*/
|
||||
void ws_protocol_decoder_ambient_weather_free(void* context);
|
||||
|
||||
/**
|
||||
* Reset decoder WSProtocolDecoderAmbient_Weather.
|
||||
* @param context Pointer to a WSProtocolDecoderAmbient_Weather instance
|
||||
*/
|
||||
void ws_protocol_decoder_ambient_weather_reset(void* context);
|
||||
|
||||
/**
|
||||
* Parse a raw sequence of levels and durations received from the air.
|
||||
* @param context Pointer to a WSProtocolDecoderAmbient_Weather instance
|
||||
* @param level Signal level true-high false-low
|
||||
* @param duration Duration of this level in, us
|
||||
*/
|
||||
void ws_protocol_decoder_ambient_weather_feed(void* context, bool level, uint32_t duration);
|
||||
|
||||
/**
|
||||
* Getting the hash sum of the last randomly received parcel.
|
||||
* @param context Pointer to a WSProtocolDecoderAmbient_Weather instance
|
||||
* @return hash Hash sum
|
||||
*/
|
||||
uint8_t ws_protocol_decoder_ambient_weather_get_hash_data(void* context);
|
||||
|
||||
/**
|
||||
* Serialize data WSProtocolDecoderAmbient_Weather.
|
||||
* @param context Pointer to a WSProtocolDecoderAmbient_Weather 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_ambient_weather_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset);
|
||||
|
||||
/**
|
||||
* Deserialize data WSProtocolDecoderAmbient_Weather.
|
||||
* @param context Pointer to a WSProtocolDecoderAmbient_Weather instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @return status
|
||||
*/
|
||||
SubGhzProtocolStatus
|
||||
ws_protocol_decoder_ambient_weather_deserialize(void* context, FlipperFormat* flipper_format);
|
||||
|
||||
/**
|
||||
* Getting a textual representation of the received data.
|
||||
* @param context Pointer to a WSProtocolDecoderAmbient_Weather instance
|
||||
* @param output Resulting text
|
||||
*/
|
||||
void ws_protocol_decoder_ambient_weather_get_string(void* context, FuriString* output);
|
248
applications/external/weather_station/protocols/auriol_hg0601a.c
vendored
Normal file
248
applications/external/weather_station/protocols/auriol_hg0601a.c
vendored
Normal file
@@ -0,0 +1,248 @@
|
||||
#include "auriol_hg0601a.h"
|
||||
|
||||
#define TAG "WSProtocolAuriol_TH"
|
||||
|
||||
/*
|
||||
*
|
||||
Auriol HG06061A-DCF-TX sensor.
|
||||
|
||||
Data layout:
|
||||
DDDDDDDD-B0-NN-TT-TTTTTTTTTT-CCCC-HHHHHHHH
|
||||
Exmpl.: 11110100-10-01-00-0001001100-1111-01011101
|
||||
|
||||
- D: id, 8 bit
|
||||
- B: where B is the battery status: 1=OK, 0=LOW, 1 bit
|
||||
- 0: just zero :)
|
||||
- N: NN is the channel: 00=CH1, 01=CH2, 11=CH3, 2bit
|
||||
- T: temperature, 12 bit: 2's complement, scaled by 10
|
||||
- C: 4 bit: seems to be 0xf constantly, a separator between temp and humidity
|
||||
- H: humidity sensor, humidity is 8 bits
|
||||
|
||||
* The sensor sends 37 bits 10 times,
|
||||
* the packets are ppm modulated (distance coding) with a pulse of ~500 us
|
||||
* followed by a short gap of ~1000 us for a 0 bit or a long ~2000 us gap for a
|
||||
* 1 bit, the sync gap is ~4000 us.
|
||||
*
|
||||
*/
|
||||
|
||||
#define AURIOL_TH_CONST_DATA 0b1110
|
||||
|
||||
static const SubGhzBlockConst ws_protocol_auriol_th_const = {
|
||||
.te_short = 500,
|
||||
.te_long = 2000,
|
||||
.te_delta = 150,
|
||||
.min_count_bit_for_found = 37,
|
||||
};
|
||||
|
||||
struct WSProtocolDecoderAuriol_TH {
|
||||
SubGhzProtocolDecoderBase base;
|
||||
|
||||
SubGhzBlockDecoder decoder;
|
||||
WSBlockGeneric generic;
|
||||
};
|
||||
|
||||
struct WSProtocolEncoderAuriol_TH {
|
||||
SubGhzProtocolEncoderBase base;
|
||||
|
||||
SubGhzProtocolBlockEncoder encoder;
|
||||
WSBlockGeneric generic;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
auriol_THDecoderStepReset = 0,
|
||||
auriol_THDecoderStepSaveDuration,
|
||||
auriol_THDecoderStepCheckDuration,
|
||||
} auriol_THDecoderStep;
|
||||
|
||||
const SubGhzProtocolDecoder ws_protocol_auriol_th_decoder = {
|
||||
.alloc = ws_protocol_decoder_auriol_th_alloc,
|
||||
.free = ws_protocol_decoder_auriol_th_free,
|
||||
|
||||
.feed = ws_protocol_decoder_auriol_th_feed,
|
||||
.reset = ws_protocol_decoder_auriol_th_reset,
|
||||
|
||||
.get_hash_data = ws_protocol_decoder_auriol_th_get_hash_data,
|
||||
.serialize = ws_protocol_decoder_auriol_th_serialize,
|
||||
.deserialize = ws_protocol_decoder_auriol_th_deserialize,
|
||||
.get_string = ws_protocol_decoder_auriol_th_get_string,
|
||||
};
|
||||
|
||||
const SubGhzProtocolEncoder ws_protocol_auriol_th_encoder = {
|
||||
.alloc = NULL,
|
||||
.free = NULL,
|
||||
|
||||
.deserialize = NULL,
|
||||
.stop = NULL,
|
||||
.yield = NULL,
|
||||
};
|
||||
|
||||
const SubGhzProtocol ws_protocol_auriol_th = {
|
||||
.name = WS_PROTOCOL_AURIOL_TH_NAME,
|
||||
.type = SubGhzProtocolWeatherStation,
|
||||
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_315 | SubGhzProtocolFlag_868 |
|
||||
SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable,
|
||||
|
||||
.decoder = &ws_protocol_auriol_th_decoder,
|
||||
.encoder = &ws_protocol_auriol_th_encoder,
|
||||
};
|
||||
|
||||
void* ws_protocol_decoder_auriol_th_alloc(SubGhzEnvironment* environment) {
|
||||
UNUSED(environment);
|
||||
WSProtocolDecoderAuriol_TH* instance = malloc(sizeof(WSProtocolDecoderAuriol_TH));
|
||||
instance->base.protocol = &ws_protocol_auriol_th;
|
||||
instance->generic.protocol_name = instance->base.protocol->name;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_auriol_th_free(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAuriol_TH* instance = context;
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_auriol_th_reset(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAuriol_TH* instance = context;
|
||||
instance->decoder.parser_step = auriol_THDecoderStepReset;
|
||||
}
|
||||
|
||||
static bool ws_protocol_auriol_th_check(WSProtocolDecoderAuriol_TH* instance) {
|
||||
uint8_t type = (instance->decoder.decode_data >> 8) & 0x0F;
|
||||
|
||||
if((type == AURIOL_TH_CONST_DATA) && ((instance->decoder.decode_data >> 4) != 0xffffffff)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Analysis of received data
|
||||
* @param instance Pointer to a WSBlockGeneric* instance
|
||||
*/
|
||||
static void ws_protocol_auriol_th_remote_controller(WSBlockGeneric* instance) {
|
||||
instance->id = (instance->data >> 31) & 0xFF;
|
||||
instance->battery_low = ((instance->data >> 30) & 1);
|
||||
instance->channel = ((instance->data >> 25) & 0x03) + 1;
|
||||
instance->btn = WS_NO_BTN;
|
||||
if(!((instance->data >> 23) & 1)) {
|
||||
instance->temp = (float)((instance->data >> 13) & 0x07FF) / 10.0f;
|
||||
} else {
|
||||
instance->temp = (float)((~(instance->data >> 13) & 0x07FF) + 1) / -10.0f;
|
||||
}
|
||||
|
||||
instance->humidity = (instance->data >> 1) & 0x7F;
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_auriol_th_feed(void* context, bool level, uint32_t duration) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAuriol_TH* instance = context;
|
||||
|
||||
switch(instance->decoder.parser_step) {
|
||||
case auriol_THDecoderStepReset:
|
||||
if((!level) && (DURATION_DIFF(duration, ws_protocol_auriol_th_const.te_short * 8) <
|
||||
ws_protocol_auriol_th_const.te_delta)) {
|
||||
//Found sync
|
||||
instance->decoder.parser_step = auriol_THDecoderStepSaveDuration;
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case auriol_THDecoderStepSaveDuration:
|
||||
if(level) {
|
||||
instance->decoder.te_last = duration;
|
||||
instance->decoder.parser_step = auriol_THDecoderStepCheckDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = auriol_THDecoderStepReset;
|
||||
}
|
||||
break;
|
||||
|
||||
case auriol_THDecoderStepCheckDuration:
|
||||
if(!level) {
|
||||
if(DURATION_DIFF(duration, ws_protocol_auriol_th_const.te_short * 8) <
|
||||
ws_protocol_auriol_th_const.te_delta) {
|
||||
//Found sync
|
||||
instance->decoder.parser_step = auriol_THDecoderStepReset;
|
||||
if((instance->decoder.decode_count_bit ==
|
||||
ws_protocol_auriol_th_const.min_count_bit_for_found) &&
|
||||
ws_protocol_auriol_th_check(instance)) {
|
||||
instance->generic.data = instance->decoder.decode_data;
|
||||
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
|
||||
ws_protocol_auriol_th_remote_controller(&instance->generic);
|
||||
if(instance->base.callback)
|
||||
instance->base.callback(&instance->base, instance->base.context);
|
||||
instance->decoder.parser_step = auriol_THDecoderStepCheckDuration;
|
||||
}
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
|
||||
break;
|
||||
} else if(
|
||||
(DURATION_DIFF(instance->decoder.te_last, ws_protocol_auriol_th_const.te_short) <
|
||||
ws_protocol_auriol_th_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_auriol_th_const.te_short * 2) <
|
||||
ws_protocol_auriol_th_const.te_delta)) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
||||
instance->decoder.parser_step = auriol_THDecoderStepSaveDuration;
|
||||
} else if(
|
||||
(DURATION_DIFF(instance->decoder.te_last, ws_protocol_auriol_th_const.te_short) <
|
||||
ws_protocol_auriol_th_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_auriol_th_const.te_short * 4) <
|
||||
ws_protocol_auriol_th_const.te_delta * 2)) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
||||
instance->decoder.parser_step = auriol_THDecoderStepSaveDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = auriol_THDecoderStepReset;
|
||||
}
|
||||
} else {
|
||||
instance->decoder.parser_step = auriol_THDecoderStepReset;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t ws_protocol_decoder_auriol_th_get_hash_data(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAuriol_TH* instance = context;
|
||||
return subghz_protocol_blocks_get_hash_data(
|
||||
&instance->decoder, (instance->decoder.decode_count_bit / 8) + 1);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus ws_protocol_decoder_auriol_th_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAuriol_TH* instance = context;
|
||||
return ws_block_generic_serialize(&instance->generic, flipper_format, preset);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus
|
||||
ws_protocol_decoder_auriol_th_deserialize(void* context, FlipperFormat* flipper_format) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAuriol_TH* instance = context;
|
||||
return ws_block_generic_deserialize_check_count_bit(
|
||||
&instance->generic, flipper_format, ws_protocol_auriol_th_const.min_count_bit_for_found);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_auriol_th_get_string(void* context, FuriString* output) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderAuriol_TH* instance = context;
|
||||
furi_string_printf(
|
||||
output,
|
||||
"%s %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
applications/external/weather_station/protocols/auriol_hg0601a.h
vendored
Normal file
80
applications/external/weather_station/protocols/auriol_hg0601a.h
vendored
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_AURIOL_TH_NAME "Auriol HG06061" //HG06061A-DCF-TX
|
||||
|
||||
typedef struct WSProtocolDecoderAuriol_TH WSProtocolDecoderAuriol_TH;
|
||||
typedef struct WSProtocolEncoderAuriol_TH WSProtocolEncoderAuriol_TH;
|
||||
|
||||
extern const SubGhzProtocolDecoder ws_protocol_auriol_th_decoder;
|
||||
extern const SubGhzProtocolEncoder ws_protocol_auriol_th_encoder;
|
||||
extern const SubGhzProtocol ws_protocol_auriol_th;
|
||||
|
||||
/**
|
||||
* Allocate WSProtocolDecoderAuriol_TH.
|
||||
* @param environment Pointer to a SubGhzEnvironment instance
|
||||
* @return WSProtocolDecoderAuriol_TH* pointer to a WSProtocolDecoderAuriol_TH instance
|
||||
*/
|
||||
void* ws_protocol_decoder_auriol_th_alloc(SubGhzEnvironment* environment);
|
||||
|
||||
/**
|
||||
* Free WSProtocolDecoderAuriol_TH.
|
||||
* @param context Pointer to a WSProtocolDecoderAuriol_TH instance
|
||||
*/
|
||||
void ws_protocol_decoder_auriol_th_free(void* context);
|
||||
|
||||
/**
|
||||
* Reset decoder WSProtocolDecoderAuriol_TH.
|
||||
* @param context Pointer to a WSProtocolDecoderAuriol_TH instance
|
||||
*/
|
||||
void ws_protocol_decoder_auriol_th_reset(void* context);
|
||||
|
||||
/**
|
||||
* Parse a raw sequence of levels and durations received from the air.
|
||||
* @param context Pointer to a WSProtocolDecoderAuriol_TH instance
|
||||
* @param level Signal level true-high false-low
|
||||
* @param duration Duration of this level in, us
|
||||
*/
|
||||
void ws_protocol_decoder_auriol_th_feed(void* context, bool level, uint32_t duration);
|
||||
|
||||
/**
|
||||
* Getting the hash sum of the last randomly received parcel.
|
||||
* @param context Pointer to a WSProtocolDecoderAuriol_TH instance
|
||||
* @return hash Hash sum
|
||||
*/
|
||||
uint8_t ws_protocol_decoder_auriol_th_get_hash_data(void* context);
|
||||
|
||||
/**
|
||||
* Serialize data WSProtocolDecoderAuriol_TH.
|
||||
* @param context Pointer to a WSProtocolDecoderAuriol_TH 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_auriol_th_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset);
|
||||
|
||||
/**
|
||||
* Deserialize data WSProtocolDecoderAuriol_TH.
|
||||
* @param context Pointer to a WSProtocolDecoderAuriol_TH instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @return status
|
||||
*/
|
||||
SubGhzProtocolStatus
|
||||
ws_protocol_decoder_auriol_th_deserialize(void* context, FlipperFormat* flipper_format);
|
||||
|
||||
/**
|
||||
* Getting a textual representation of the received data.
|
||||
* @param context Pointer to a WSProtocolDecoderAuriol_TH instance
|
||||
* @param output Resulting text
|
||||
*/
|
||||
void ws_protocol_decoder_auriol_th_get_string(void* context, FuriString* output);
|
255
applications/external/weather_station/protocols/gt_wt_02.c
vendored
Normal file
255
applications/external/weather_station/protocols/gt_wt_02.c
vendored
Normal file
@@ -0,0 +1,255 @@
|
||||
#include "gt_wt_02.h"
|
||||
|
||||
#define TAG "WSProtocolGT_WT02"
|
||||
|
||||
/*
|
||||
* Help
|
||||
* https://github.com/merbanan/rtl_433/blob/master/src/devices/gt_wt_02.c
|
||||
*
|
||||
* GT-WT-02 sensor on 433.92MHz.
|
||||
* Example and frame description provided by https://github.com/ludwich66
|
||||
* [01] {37} 34 00 ed 47 60 : 00110100 00000000 11101101 01000111 01100000
|
||||
* code, BatOK,not-man-send, Channel1, +23,7<>C, 35%
|
||||
* [01] {37} 34 8f 87 15 90 : 00110100 10001111 10000111 00010101 10010000
|
||||
* code, BatOK,not-man-send, Channel1,-12,1<>C, 10%
|
||||
* Humidity:
|
||||
* - the working range is 20-90 %
|
||||
* - if "LL" in display view it sends 10 %
|
||||
* - if "HH" in display view it sends 110%
|
||||
* SENSOR: GT-WT-02 (ALDI Globaltronics..)
|
||||
* TYP IIIIIIII BMCCTTTT TTTTTTTT HHHHHHHX XXXXX
|
||||
* TYPE Description:
|
||||
* - I = Random Device Code, changes with battery reset
|
||||
* - B = Battery 0=OK 1=LOW
|
||||
* - M = Manual Send Button Pressed 0=not pressed 1=pressed
|
||||
* - C = Channel 00=CH1, 01=CH2, 10=CH3
|
||||
* - T = Temperature, 12 Bit 2's complement, scaled by 10
|
||||
* - H = Humidity = 7 Bit bin2dez 00-99, Display LL=10%, Display HH=110% (Range 20-90%)
|
||||
* - X = Checksum, sum modulo 64
|
||||
* A Lidl AURIO (from 12/2018) with PCB marking YJ-T12 V02 has two extra bits in front.
|
||||
*
|
||||
*/
|
||||
|
||||
static const SubGhzBlockConst ws_protocol_gt_wt_02_const = {
|
||||
.te_short = 500,
|
||||
.te_long = 2000,
|
||||
.te_delta = 150,
|
||||
.min_count_bit_for_found = 37,
|
||||
};
|
||||
|
||||
struct WSProtocolDecoderGT_WT02 {
|
||||
SubGhzProtocolDecoderBase base;
|
||||
|
||||
SubGhzBlockDecoder decoder;
|
||||
WSBlockGeneric generic;
|
||||
};
|
||||
|
||||
struct WSProtocolEncoderGT_WT02 {
|
||||
SubGhzProtocolEncoderBase base;
|
||||
|
||||
SubGhzProtocolBlockEncoder encoder;
|
||||
WSBlockGeneric generic;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
GT_WT02DecoderStepReset = 0,
|
||||
GT_WT02DecoderStepSaveDuration,
|
||||
GT_WT02DecoderStepCheckDuration,
|
||||
} GT_WT02DecoderStep;
|
||||
|
||||
const SubGhzProtocolDecoder ws_protocol_gt_wt_02_decoder = {
|
||||
.alloc = ws_protocol_decoder_gt_wt_02_alloc,
|
||||
.free = ws_protocol_decoder_gt_wt_02_free,
|
||||
|
||||
.feed = ws_protocol_decoder_gt_wt_02_feed,
|
||||
.reset = ws_protocol_decoder_gt_wt_02_reset,
|
||||
|
||||
.get_hash_data = ws_protocol_decoder_gt_wt_02_get_hash_data,
|
||||
.serialize = ws_protocol_decoder_gt_wt_02_serialize,
|
||||
.deserialize = ws_protocol_decoder_gt_wt_02_deserialize,
|
||||
.get_string = ws_protocol_decoder_gt_wt_02_get_string,
|
||||
};
|
||||
|
||||
const SubGhzProtocolEncoder ws_protocol_gt_wt_02_encoder = {
|
||||
.alloc = NULL,
|
||||
.free = NULL,
|
||||
|
||||
.deserialize = NULL,
|
||||
.stop = NULL,
|
||||
.yield = NULL,
|
||||
};
|
||||
|
||||
const SubGhzProtocol ws_protocol_gt_wt_02 = {
|
||||
.name = WS_PROTOCOL_GT_WT_02_NAME,
|
||||
.type = SubGhzProtocolWeatherStation,
|
||||
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_315 | SubGhzProtocolFlag_868 |
|
||||
SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable,
|
||||
|
||||
.decoder = &ws_protocol_gt_wt_02_decoder,
|
||||
.encoder = &ws_protocol_gt_wt_02_encoder,
|
||||
};
|
||||
|
||||
void* ws_protocol_decoder_gt_wt_02_alloc(SubGhzEnvironment* environment) {
|
||||
UNUSED(environment);
|
||||
WSProtocolDecoderGT_WT02* instance = malloc(sizeof(WSProtocolDecoderGT_WT02));
|
||||
instance->base.protocol = &ws_protocol_gt_wt_02;
|
||||
instance->generic.protocol_name = instance->base.protocol->name;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_gt_wt_02_free(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderGT_WT02* instance = context;
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_gt_wt_02_reset(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderGT_WT02* instance = context;
|
||||
instance->decoder.parser_step = GT_WT02DecoderStepReset;
|
||||
}
|
||||
|
||||
static bool ws_protocol_gt_wt_02_check(WSProtocolDecoderGT_WT02* instance) {
|
||||
if(!instance->decoder.decode_data) return false;
|
||||
uint8_t sum = (instance->decoder.decode_data >> 5) & 0xe;
|
||||
uint64_t temp_data = instance->decoder.decode_data >> 9;
|
||||
for(uint8_t i = 0; i < 7; i++) {
|
||||
sum += (temp_data >> (i * 4)) & 0xF;
|
||||
}
|
||||
return ((uint8_t)(instance->decoder.decode_data & 0x3F) == (sum & 0x3F));
|
||||
}
|
||||
|
||||
/**
|
||||
* Analysis of received data
|
||||
* @param instance Pointer to a WSBlockGeneric* instance
|
||||
*/
|
||||
static void ws_protocol_gt_wt_02_remote_controller(WSBlockGeneric* instance) {
|
||||
instance->id = (instance->data >> 29) & 0xFF;
|
||||
instance->battery_low = (instance->data >> 28) & 1;
|
||||
instance->btn = (instance->data >> 27) & 1;
|
||||
instance->channel = ((instance->data >> 25) & 0x3) + 1;
|
||||
|
||||
if(!((instance->data >> 24) & 1)) {
|
||||
instance->temp = (float)((instance->data >> 13) & 0x07FF) / 10.0f;
|
||||
} else {
|
||||
instance->temp = (float)((~(instance->data >> 13) & 0x07FF) + 1) / -10.0f;
|
||||
}
|
||||
|
||||
instance->humidity = (instance->data >> 6) & 0x7F;
|
||||
if(instance->humidity <= 10) // actually the sensors sends 10 below working range of 20%
|
||||
instance->humidity = 0;
|
||||
else if(instance->humidity > 90) // actually the sensors sends 110 above working range of 90%
|
||||
instance->humidity = 100;
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_gt_wt_02_feed(void* context, bool level, uint32_t duration) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderGT_WT02* instance = context;
|
||||
|
||||
switch(instance->decoder.parser_step) {
|
||||
case GT_WT02DecoderStepReset:
|
||||
if((!level) && (DURATION_DIFF(duration, ws_protocol_gt_wt_02_const.te_short * 18) <
|
||||
ws_protocol_gt_wt_02_const.te_delta * 8)) {
|
||||
//Found syncPrefix
|
||||
instance->decoder.parser_step = GT_WT02DecoderStepSaveDuration;
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case GT_WT02DecoderStepSaveDuration:
|
||||
if(level) {
|
||||
instance->decoder.te_last = duration;
|
||||
instance->decoder.parser_step = GT_WT02DecoderStepCheckDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = GT_WT02DecoderStepReset;
|
||||
}
|
||||
break;
|
||||
|
||||
case GT_WT02DecoderStepCheckDuration:
|
||||
if(!level) {
|
||||
if(DURATION_DIFF(instance->decoder.te_last, ws_protocol_gt_wt_02_const.te_short) <
|
||||
ws_protocol_gt_wt_02_const.te_delta) {
|
||||
if(DURATION_DIFF(duration, ws_protocol_gt_wt_02_const.te_short * 18) <
|
||||
ws_protocol_gt_wt_02_const.te_delta * 8) {
|
||||
//Found syncPostfix
|
||||
instance->decoder.parser_step = GT_WT02DecoderStepReset;
|
||||
if((instance->decoder.decode_count_bit ==
|
||||
ws_protocol_gt_wt_02_const.min_count_bit_for_found) &&
|
||||
ws_protocol_gt_wt_02_check(instance)) {
|
||||
instance->generic.data = instance->decoder.decode_data;
|
||||
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
|
||||
ws_protocol_gt_wt_02_remote_controller(&instance->generic);
|
||||
if(instance->base.callback)
|
||||
instance->base.callback(&instance->base, instance->base.context);
|
||||
} else if(instance->decoder.decode_count_bit == 1) {
|
||||
instance->decoder.parser_step = GT_WT02DecoderStepSaveDuration;
|
||||
}
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
} else if(
|
||||
DURATION_DIFF(duration, ws_protocol_gt_wt_02_const.te_long) <
|
||||
ws_protocol_gt_wt_02_const.te_delta * 2) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
||||
instance->decoder.parser_step = GT_WT02DecoderStepSaveDuration;
|
||||
} else if(
|
||||
DURATION_DIFF(duration, ws_protocol_gt_wt_02_const.te_long * 2) <
|
||||
ws_protocol_gt_wt_02_const.te_delta * 4) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
||||
instance->decoder.parser_step = GT_WT02DecoderStepSaveDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = GT_WT02DecoderStepReset;
|
||||
}
|
||||
} else {
|
||||
instance->decoder.parser_step = GT_WT02DecoderStepReset;
|
||||
}
|
||||
} else {
|
||||
instance->decoder.parser_step = GT_WT02DecoderStepReset;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t ws_protocol_decoder_gt_wt_02_get_hash_data(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderGT_WT02* instance = context;
|
||||
return subghz_protocol_blocks_get_hash_data(
|
||||
&instance->decoder, (instance->decoder.decode_count_bit / 8) + 1);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus ws_protocol_decoder_gt_wt_02_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderGT_WT02* instance = context;
|
||||
return ws_block_generic_serialize(&instance->generic, flipper_format, preset);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus
|
||||
ws_protocol_decoder_gt_wt_02_deserialize(void* context, FlipperFormat* flipper_format) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderGT_WT02* instance = context;
|
||||
return ws_block_generic_deserialize_check_count_bit(
|
||||
&instance->generic, flipper_format, ws_protocol_gt_wt_02_const.min_count_bit_for_found);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_gt_wt_02_get_string(void* context, FuriString* output) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderGT_WT02* instance = context;
|
||||
furi_string_printf(
|
||||
output,
|
||||
"%s %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
applications/external/weather_station/protocols/gt_wt_02.h
vendored
Normal file
80
applications/external/weather_station/protocols/gt_wt_02.h
vendored
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_GT_WT_02_NAME "GT-WT02"
|
||||
|
||||
typedef struct WSProtocolDecoderGT_WT02 WSProtocolDecoderGT_WT02;
|
||||
typedef struct WSProtocolEncoderGT_WT02 WSProtocolEncoderGT_WT02;
|
||||
|
||||
extern const SubGhzProtocolDecoder ws_protocol_gt_wt_02_decoder;
|
||||
extern const SubGhzProtocolEncoder ws_protocol_gt_wt_02_encoder;
|
||||
extern const SubGhzProtocol ws_protocol_gt_wt_02;
|
||||
|
||||
/**
|
||||
* Allocate WSProtocolDecoderGT_WT02.
|
||||
* @param environment Pointer to a SubGhzEnvironment instance
|
||||
* @return WSProtocolDecoderGT_WT02* pointer to a WSProtocolDecoderGT_WT02 instance
|
||||
*/
|
||||
void* ws_protocol_decoder_gt_wt_02_alloc(SubGhzEnvironment* environment);
|
||||
|
||||
/**
|
||||
* Free WSProtocolDecoderGT_WT02.
|
||||
* @param context Pointer to a WSProtocolDecoderGT_WT02 instance
|
||||
*/
|
||||
void ws_protocol_decoder_gt_wt_02_free(void* context);
|
||||
|
||||
/**
|
||||
* Reset decoder WSProtocolDecoderGT_WT02.
|
||||
* @param context Pointer to a WSProtocolDecoderGT_WT02 instance
|
||||
*/
|
||||
void ws_protocol_decoder_gt_wt_02_reset(void* context);
|
||||
|
||||
/**
|
||||
* Parse a raw sequence of levels and durations received from the air.
|
||||
* @param context Pointer to a WSProtocolDecoderGT_WT02 instance
|
||||
* @param level Signal level true-high false-low
|
||||
* @param duration Duration of this level in, us
|
||||
*/
|
||||
void ws_protocol_decoder_gt_wt_02_feed(void* context, bool level, uint32_t duration);
|
||||
|
||||
/**
|
||||
* Getting the hash sum of the last randomly received parcel.
|
||||
* @param context Pointer to a WSProtocolDecoderGT_WT02 instance
|
||||
* @return hash Hash sum
|
||||
*/
|
||||
uint8_t ws_protocol_decoder_gt_wt_02_get_hash_data(void* context);
|
||||
|
||||
/**
|
||||
* Serialize data WSProtocolDecoderGT_WT02.
|
||||
* @param context Pointer to a WSProtocolDecoderGT_WT02 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_gt_wt_02_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset);
|
||||
|
||||
/**
|
||||
* Deserialize data WSProtocolDecoderGT_WT02.
|
||||
* @param context Pointer to a WSProtocolDecoderGT_WT02 instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @return status
|
||||
*/
|
||||
SubGhzProtocolStatus
|
||||
ws_protocol_decoder_gt_wt_02_deserialize(void* context, FlipperFormat* flipper_format);
|
||||
|
||||
/**
|
||||
* Getting a textual representation of the received data.
|
||||
* @param context Pointer to a WSProtocolDecoderGT_WT02 instance
|
||||
* @param output Resulting text
|
||||
*/
|
||||
void ws_protocol_decoder_gt_wt_02_get_string(void* context, FuriString* output);
|
330
applications/external/weather_station/protocols/gt_wt_03.c
vendored
Normal file
330
applications/external/weather_station/protocols/gt_wt_03.c
vendored
Normal file
@@ -0,0 +1,330 @@
|
||||
#include "gt_wt_03.h"
|
||||
|
||||
#define TAG "WSProtocolGT_WT03"
|
||||
|
||||
/*
|
||||
* Help
|
||||
* https://github.com/merbanan/rtl_433/blob/master/src/devices/gt_wt_03.c
|
||||
*
|
||||
*
|
||||
* Globaltronics GT-WT-03 sensor on 433.92MHz.
|
||||
* The 01-set sensor has 60 ms packet gap with 10 repeats.
|
||||
* The 02-set sensor has no packet gap with 23 repeats.
|
||||
* Example:
|
||||
* {41} 17 cf be fa 6a 80 [ S1 C1 26,1 C 78.9 F 48% Bat-Good Manual-Yes ]
|
||||
* {41} 17 cf be fa 6a 80 [ S1 C1 26,1 C 78.9 F 48% Bat-Good Manual-Yes Batt-Changed ]
|
||||
* {41} 17 cf fe fa ea 80 [ S1 C1 26,1 C 78.9 F 48% Bat-Good Manual-No Batt-Changed ]
|
||||
* {41} 01 cf 6f 11 b2 80 [ S2 C2 23,8 C 74.8 F 48% Bat-LOW Manual-No ]
|
||||
* {41} 01 c8 d0 2b 76 80 [ S2 C3 -4,4 C 24.1 F 55% Bat-Good Manual-No Batt-Changed ]
|
||||
* Format string:
|
||||
* ID:8h HUM:8d B:b M:b C:2d TEMP:12d CHK:8h 1x
|
||||
* Data layout:
|
||||
* TYP IIIIIIII HHHHHHHH BMCCTTTT TTTTTTTT XXXXXXXX
|
||||
* - I: Random Device Code: changes with battery reset
|
||||
* - H: Humidity: 8 Bit 00-99, Display LL=10%, Display HH=110% (Range 20-95%)
|
||||
* - B: Battery: 0=OK 1=LOW
|
||||
* - M: Manual Send Button Pressed: 0=not pressed, 1=pressed
|
||||
* - C: Channel: 00=CH1, 01=CH2, 10=CH3
|
||||
* - T: Temperature: 12 Bit 2's complement, scaled by 10, range-50.0 C (-50.1 shown as Lo) to +70.0 C (+70.1 C is shown as Hi)
|
||||
* - X: Checksum, xor shifting key per byte
|
||||
* Humidity:
|
||||
* - the working range is 20-95 %
|
||||
* - if "LL" in display view it sends 10 %
|
||||
* - if "HH" in display view it sends 110%
|
||||
* Checksum:
|
||||
* Per byte xor the key for each 1-bit, shift per bit. Key list per bit, starting at MSB:
|
||||
* - 0x00 [07]
|
||||
* - 0x80 [06]
|
||||
* - 0x40 [05]
|
||||
* - 0x20 [04]
|
||||
* - 0x10 [03]
|
||||
* - 0x88 [02]
|
||||
* - 0xc4 [01]
|
||||
* - 0x62 [00]
|
||||
* Note: this can also be seen as lower byte of a Galois/Fibonacci LFSR-16, gen 0x00, init 0x3100 (or 0x62 if reversed) resetting at every byte.
|
||||
* Battery voltages:
|
||||
* - U=<2,65V +- ~5% Battery indicator
|
||||
* - U=>2.10C +- 5% plausible readings
|
||||
* - U=2,00V +- ~5% Temperature offset -5°C Humidity offset unknown
|
||||
* - U=<1,95V +- ~5% does not initialize anymore
|
||||
* - U=1,90V +- 5% temperature offset -15°C
|
||||
* - U=1,80V +- 5% Display is showing refresh pattern
|
||||
* - U=1.75V +- ~5% TX causes cut out
|
||||
*
|
||||
*/
|
||||
|
||||
static const SubGhzBlockConst ws_protocol_gt_wt_03_const = {
|
||||
.te_short = 285,
|
||||
.te_long = 570,
|
||||
.te_delta = 120,
|
||||
.min_count_bit_for_found = 41,
|
||||
};
|
||||
|
||||
struct WSProtocolDecoderGT_WT03 {
|
||||
SubGhzProtocolDecoderBase base;
|
||||
|
||||
SubGhzBlockDecoder decoder;
|
||||
WSBlockGeneric generic;
|
||||
|
||||
uint16_t header_count;
|
||||
};
|
||||
|
||||
struct WSProtocolEncoderGT_WT03 {
|
||||
SubGhzProtocolEncoderBase base;
|
||||
|
||||
SubGhzProtocolBlockEncoder encoder;
|
||||
WSBlockGeneric generic;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
GT_WT03DecoderStepReset = 0,
|
||||
GT_WT03DecoderStepCheckPreambule,
|
||||
GT_WT03DecoderStepSaveDuration,
|
||||
GT_WT03DecoderStepCheckDuration,
|
||||
} GT_WT03DecoderStep;
|
||||
|
||||
const SubGhzProtocolDecoder ws_protocol_gt_wt_03_decoder = {
|
||||
.alloc = ws_protocol_decoder_gt_wt_03_alloc,
|
||||
.free = ws_protocol_decoder_gt_wt_03_free,
|
||||
|
||||
.feed = ws_protocol_decoder_gt_wt_03_feed,
|
||||
.reset = ws_protocol_decoder_gt_wt_03_reset,
|
||||
|
||||
.get_hash_data = ws_protocol_decoder_gt_wt_03_get_hash_data,
|
||||
.serialize = ws_protocol_decoder_gt_wt_03_serialize,
|
||||
.deserialize = ws_protocol_decoder_gt_wt_03_deserialize,
|
||||
.get_string = ws_protocol_decoder_gt_wt_03_get_string,
|
||||
};
|
||||
|
||||
const SubGhzProtocolEncoder ws_protocol_gt_wt_03_encoder = {
|
||||
.alloc = NULL,
|
||||
.free = NULL,
|
||||
|
||||
.deserialize = NULL,
|
||||
.stop = NULL,
|
||||
.yield = NULL,
|
||||
};
|
||||
|
||||
const SubGhzProtocol ws_protocol_gt_wt_03 = {
|
||||
.name = WS_PROTOCOL_GT_WT_03_NAME,
|
||||
.type = SubGhzProtocolWeatherStation,
|
||||
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_315 | SubGhzProtocolFlag_868 |
|
||||
SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable,
|
||||
|
||||
.decoder = &ws_protocol_gt_wt_03_decoder,
|
||||
.encoder = &ws_protocol_gt_wt_03_encoder,
|
||||
};
|
||||
|
||||
void* ws_protocol_decoder_gt_wt_03_alloc(SubGhzEnvironment* environment) {
|
||||
UNUSED(environment);
|
||||
WSProtocolDecoderGT_WT03* instance = malloc(sizeof(WSProtocolDecoderGT_WT03));
|
||||
instance->base.protocol = &ws_protocol_gt_wt_03;
|
||||
instance->generic.protocol_name = instance->base.protocol->name;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_gt_wt_03_free(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderGT_WT03* instance = context;
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_gt_wt_03_reset(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderGT_WT03* instance = context;
|
||||
instance->decoder.parser_step = GT_WT03DecoderStepReset;
|
||||
}
|
||||
|
||||
static bool ws_protocol_gt_wt_03_check_crc(WSProtocolDecoderGT_WT03* instance) {
|
||||
uint8_t msg[] = {
|
||||
instance->decoder.decode_data >> 33,
|
||||
instance->decoder.decode_data >> 25,
|
||||
instance->decoder.decode_data >> 17,
|
||||
instance->decoder.decode_data >> 9};
|
||||
|
||||
uint8_t sum = 0;
|
||||
for(unsigned k = 0; k < sizeof(msg); ++k) {
|
||||
uint8_t data = msg[k];
|
||||
uint16_t key = 0x3100;
|
||||
for(int i = 7; i >= 0; --i) {
|
||||
// XOR key into sum if data bit is set
|
||||
if((data >> i) & 1) sum ^= key & 0xff;
|
||||
// roll the key right
|
||||
key = (key >> 1);
|
||||
}
|
||||
}
|
||||
return ((sum ^ (uint8_t)((instance->decoder.decode_data >> 1) & 0xFF)) == 0x2D);
|
||||
}
|
||||
|
||||
/**
|
||||
* Analysis of received data
|
||||
* @param instance Pointer to a WSBlockGeneric* instance
|
||||
*/
|
||||
static void ws_protocol_gt_wt_03_remote_controller(WSBlockGeneric* instance) {
|
||||
instance->id = instance->data >> 33;
|
||||
instance->humidity = (instance->data >> 25) & 0xFF;
|
||||
|
||||
if(instance->humidity <= 10) { // actually the sensors sends 10 below working range of 20%
|
||||
instance->humidity = 0;
|
||||
} else if(instance->humidity > 95) { // actually the sensors sends 110 above working range of 90%
|
||||
instance->humidity = 100;
|
||||
}
|
||||
|
||||
instance->battery_low = (instance->data >> 24) & 1;
|
||||
instance->btn = (instance->data >> 23) & 1;
|
||||
instance->channel = ((instance->data >> 21) & 0x03) + 1;
|
||||
|
||||
if(!((instance->data >> 20) & 1)) {
|
||||
instance->temp = (float)((instance->data >> 9) & 0x07FF) / 10.0f;
|
||||
} else {
|
||||
instance->temp = (float)((~(instance->data >> 9) & 0x07FF) + 1) / -10.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_gt_wt_03_feed(void* context, bool level, uint32_t duration) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderGT_WT03* instance = context;
|
||||
|
||||
switch(instance->decoder.parser_step) {
|
||||
case GT_WT03DecoderStepReset:
|
||||
if((level) && (DURATION_DIFF(duration, ws_protocol_gt_wt_03_const.te_short * 3) <
|
||||
ws_protocol_gt_wt_03_const.te_delta * 2)) {
|
||||
instance->decoder.parser_step = GT_WT03DecoderStepCheckPreambule;
|
||||
instance->decoder.te_last = duration;
|
||||
instance->header_count = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case GT_WT03DecoderStepCheckPreambule:
|
||||
if(level) {
|
||||
instance->decoder.te_last = duration;
|
||||
} else {
|
||||
if((DURATION_DIFF(instance->decoder.te_last, ws_protocol_gt_wt_03_const.te_short * 3) <
|
||||
ws_protocol_gt_wt_03_const.te_delta * 2) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_gt_wt_03_const.te_short * 3) <
|
||||
ws_protocol_gt_wt_03_const.te_delta * 2)) {
|
||||
//Found preambule
|
||||
instance->header_count++;
|
||||
} else if(instance->header_count == 4) {
|
||||
if((DURATION_DIFF(instance->decoder.te_last, ws_protocol_gt_wt_03_const.te_short) <
|
||||
ws_protocol_gt_wt_03_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_gt_wt_03_const.te_long) <
|
||||
ws_protocol_gt_wt_03_const.te_delta)) {
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
||||
instance->decoder.parser_step = GT_WT03DecoderStepSaveDuration;
|
||||
} else if(
|
||||
(DURATION_DIFF(instance->decoder.te_last, ws_protocol_gt_wt_03_const.te_long) <
|
||||
ws_protocol_gt_wt_03_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_gt_wt_03_const.te_short) <
|
||||
ws_protocol_gt_wt_03_const.te_delta)) {
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
||||
instance->decoder.parser_step = GT_WT03DecoderStepSaveDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = GT_WT03DecoderStepReset;
|
||||
}
|
||||
} else {
|
||||
instance->decoder.parser_step = GT_WT03DecoderStepReset;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case GT_WT03DecoderStepSaveDuration:
|
||||
if(level) {
|
||||
instance->decoder.te_last = duration;
|
||||
instance->decoder.parser_step = GT_WT03DecoderStepCheckDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = GT_WT03DecoderStepReset;
|
||||
}
|
||||
break;
|
||||
|
||||
case GT_WT03DecoderStepCheckDuration:
|
||||
if(!level) {
|
||||
if(((DURATION_DIFF(instance->decoder.te_last, ws_protocol_gt_wt_03_const.te_short * 3) <
|
||||
ws_protocol_gt_wt_03_const.te_delta * 2) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_gt_wt_03_const.te_short * 3) <
|
||||
ws_protocol_gt_wt_03_const.te_delta * 2))) {
|
||||
if((instance->decoder.decode_count_bit ==
|
||||
ws_protocol_gt_wt_03_const.min_count_bit_for_found) &&
|
||||
ws_protocol_gt_wt_03_check_crc(instance)) {
|
||||
instance->generic.data = instance->decoder.decode_data;
|
||||
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
|
||||
ws_protocol_gt_wt_03_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->header_count = 1;
|
||||
instance->decoder.parser_step = GT_WT03DecoderStepCheckPreambule;
|
||||
break;
|
||||
} else if(
|
||||
(DURATION_DIFF(instance->decoder.te_last, ws_protocol_gt_wt_03_const.te_short) <
|
||||
ws_protocol_gt_wt_03_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_gt_wt_03_const.te_long) <
|
||||
ws_protocol_gt_wt_03_const.te_delta)) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
||||
instance->decoder.parser_step = GT_WT03DecoderStepSaveDuration;
|
||||
} else if(
|
||||
(DURATION_DIFF(instance->decoder.te_last, ws_protocol_gt_wt_03_const.te_long) <
|
||||
ws_protocol_gt_wt_03_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_gt_wt_03_const.te_short) <
|
||||
ws_protocol_gt_wt_03_const.te_delta)) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
||||
instance->decoder.parser_step = GT_WT03DecoderStepSaveDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = GT_WT03DecoderStepReset;
|
||||
}
|
||||
} else {
|
||||
instance->decoder.parser_step = GT_WT03DecoderStepReset;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t ws_protocol_decoder_gt_wt_03_get_hash_data(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderGT_WT03* instance = context;
|
||||
return subghz_protocol_blocks_get_hash_data(
|
||||
&instance->decoder, (instance->decoder.decode_count_bit / 8) + 1);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus ws_protocol_decoder_gt_wt_03_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderGT_WT03* instance = context;
|
||||
return ws_block_generic_serialize(&instance->generic, flipper_format, preset);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus
|
||||
ws_protocol_decoder_gt_wt_03_deserialize(void* context, FlipperFormat* flipper_format) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderGT_WT03* instance = context;
|
||||
return ws_block_generic_deserialize_check_count_bit(
|
||||
&instance->generic, flipper_format, ws_protocol_gt_wt_03_const.min_count_bit_for_found);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_gt_wt_03_get_string(void* context, FuriString* output) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderGT_WT03* instance = context;
|
||||
furi_string_printf(
|
||||
output,
|
||||
"%s %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
applications/external/weather_station/protocols/gt_wt_03.h
vendored
Normal file
80
applications/external/weather_station/protocols/gt_wt_03.h
vendored
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_GT_WT_03_NAME "GT-WT03"
|
||||
|
||||
typedef struct WSProtocolDecoderGT_WT03 WSProtocolDecoderGT_WT03;
|
||||
typedef struct WSProtocolEncoderGT_WT03 WSProtocolEncoderGT_WT03;
|
||||
|
||||
extern const SubGhzProtocolDecoder ws_protocol_gt_wt_03_decoder;
|
||||
extern const SubGhzProtocolEncoder ws_protocol_gt_wt_03_encoder;
|
||||
extern const SubGhzProtocol ws_protocol_gt_wt_03;
|
||||
|
||||
/**
|
||||
* Allocate WSProtocolDecoderGT_WT03.
|
||||
* @param environment Pointer to a SubGhzEnvironment instance
|
||||
* @return WSProtocolDecoderGT_WT03* pointer to a WSProtocolDecoderGT_WT03 instance
|
||||
*/
|
||||
void* ws_protocol_decoder_gt_wt_03_alloc(SubGhzEnvironment* environment);
|
||||
|
||||
/**
|
||||
* Free WSProtocolDecoderGT_WT03.
|
||||
* @param context Pointer to a WSProtocolDecoderGT_WT03 instance
|
||||
*/
|
||||
void ws_protocol_decoder_gt_wt_03_free(void* context);
|
||||
|
||||
/**
|
||||
* Reset decoder WSProtocolDecoderGT_WT03.
|
||||
* @param context Pointer to a WSProtocolDecoderGT_WT03 instance
|
||||
*/
|
||||
void ws_protocol_decoder_gt_wt_03_reset(void* context);
|
||||
|
||||
/**
|
||||
* Parse a raw sequence of levels and durations received from the air.
|
||||
* @param context Pointer to a WSProtocolDecoderGT_WT03 instance
|
||||
* @param level Signal level true-high false-low
|
||||
* @param duration Duration of this level in, us
|
||||
*/
|
||||
void ws_protocol_decoder_gt_wt_03_feed(void* context, bool level, uint32_t duration);
|
||||
|
||||
/**
|
||||
* Getting the hash sum of the last randomly received parcel.
|
||||
* @param context Pointer to a WSProtocolDecoderGT_WT03 instance
|
||||
* @return hash Hash sum
|
||||
*/
|
||||
uint8_t ws_protocol_decoder_gt_wt_03_get_hash_data(void* context);
|
||||
|
||||
/**
|
||||
* Serialize data WSProtocolDecoderGT_WT03.
|
||||
* @param context Pointer to a WSProtocolDecoderGT_WT03 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_gt_wt_03_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset);
|
||||
|
||||
/**
|
||||
* Deserialize data WSProtocolDecoderGT_WT03.
|
||||
* @param context Pointer to a WSProtocolDecoderGT_WT03 instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @return status
|
||||
*/
|
||||
SubGhzProtocolStatus
|
||||
ws_protocol_decoder_gt_wt_03_deserialize(void* context, FlipperFormat* flipper_format);
|
||||
|
||||
/**
|
||||
* Getting a textual representation of the received data.
|
||||
* @param context Pointer to a WSProtocolDecoderGT_WT03 instance
|
||||
* @param output Resulting text
|
||||
*/
|
||||
void ws_protocol_decoder_gt_wt_03_get_string(void* context, FuriString* output);
|
286
applications/external/weather_station/protocols/infactory.c
vendored
Normal file
286
applications/external/weather_station/protocols/infactory.c
vendored
Normal file
@@ -0,0 +1,286 @@
|
||||
#include "infactory.h"
|
||||
|
||||
#define TAG "WSProtocolInfactory"
|
||||
|
||||
/*
|
||||
* Help
|
||||
* https://github.com/merbanan/rtl_433/blob/master/src/devices/infactory.c
|
||||
*
|
||||
* Analysis using Genuino (see http://gitlab.com/hp-uno, e.g. uno_log_433):
|
||||
* Observed On-Off-Key (OOK) data pattern:
|
||||
* preamble syncPrefix data...(40 bit) syncPostfix
|
||||
* HHLL HHLL HHLL HHLL HLLLLLLLLLLLLLLLL (HLLLL HLLLLLLLL HLLLL HLLLLLLLL ....) HLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
|
||||
* Breakdown:
|
||||
* - four preamble pairs '1'/'0' each with a length of ca. 1000us
|
||||
* - syncPre, syncPost, data0, data1 have a '1' start pulse of ca. 500us
|
||||
* - syncPre pulse before dataPtr has a '0' pulse length of ca. 8000us
|
||||
* - data0 (0-bits) have then a '0' pulse length of ca. 2000us
|
||||
* - data1 (1-bits) have then a '0' pulse length of ca. 4000us
|
||||
* - syncPost after dataPtr has a '0' pulse length of ca. 16000us
|
||||
* This analysis is the reason for the new r_device definitions below.
|
||||
* NB: pulse_slicer_ppm does not use .gap_limit if .tolerance is set.
|
||||
*
|
||||
* Outdoor sensor, transmits temperature and humidity data
|
||||
* - inFactory NC-3982-913/NX-5817-902, Pearl (for FWS-686 station)
|
||||
* - nor-tec 73383 (weather station + sensor), Schou Company AS, Denmark
|
||||
* - DAY 73365 (weather station + sensor), Schou Company AS, Denmark
|
||||
* Known brand names: inFactory, nor-tec, GreenBlue, DAY. Manufacturer in China.
|
||||
* Transmissions includes an id. Every 60 seconds the sensor transmits 6 packets:
|
||||
* 0000 1111 | 0011 0000 | 0101 1100 | 1110 0111 | 0110 0001
|
||||
* iiii iiii | cccc ub?? | tttt tttt | tttt hhhh | hhhh ??nn
|
||||
* - i: identification; changes on battery switch
|
||||
* - c: CRC-4; CCITT checksum, see below for computation specifics
|
||||
* - u: unknown; (sometimes set at power-on, but not always)
|
||||
* - b: battery low; flag to indicate low battery voltage
|
||||
* - h: Humidity; BCD-encoded, each nibble is one digit, 'A0' means 100%rH
|
||||
* - t: Temperature; in °F as binary number with one decimal place + 90 °F offset
|
||||
* - n: Channel; Channel number 1 - 3
|
||||
*
|
||||
*/
|
||||
|
||||
static const SubGhzBlockConst ws_protocol_infactory_const = {
|
||||
.te_short = 500,
|
||||
.te_long = 2000,
|
||||
.te_delta = 150,
|
||||
.min_count_bit_for_found = 40,
|
||||
};
|
||||
|
||||
struct WSProtocolDecoderInfactory {
|
||||
SubGhzProtocolDecoderBase base;
|
||||
|
||||
SubGhzBlockDecoder decoder;
|
||||
WSBlockGeneric generic;
|
||||
|
||||
uint16_t header_count;
|
||||
};
|
||||
|
||||
struct WSProtocolEncoderInfactory {
|
||||
SubGhzProtocolEncoderBase base;
|
||||
|
||||
SubGhzProtocolBlockEncoder encoder;
|
||||
WSBlockGeneric generic;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
InfactoryDecoderStepReset = 0,
|
||||
InfactoryDecoderStepCheckPreambule,
|
||||
InfactoryDecoderStepSaveDuration,
|
||||
InfactoryDecoderStepCheckDuration,
|
||||
} InfactoryDecoderStep;
|
||||
|
||||
const SubGhzProtocolDecoder ws_protocol_infactory_decoder = {
|
||||
.alloc = ws_protocol_decoder_infactory_alloc,
|
||||
.free = ws_protocol_decoder_infactory_free,
|
||||
|
||||
.feed = ws_protocol_decoder_infactory_feed,
|
||||
.reset = ws_protocol_decoder_infactory_reset,
|
||||
|
||||
.get_hash_data = ws_protocol_decoder_infactory_get_hash_data,
|
||||
.serialize = ws_protocol_decoder_infactory_serialize,
|
||||
.deserialize = ws_protocol_decoder_infactory_deserialize,
|
||||
.get_string = ws_protocol_decoder_infactory_get_string,
|
||||
};
|
||||
|
||||
const SubGhzProtocolEncoder ws_protocol_infactory_encoder = {
|
||||
.alloc = NULL,
|
||||
.free = NULL,
|
||||
|
||||
.deserialize = NULL,
|
||||
.stop = NULL,
|
||||
.yield = NULL,
|
||||
};
|
||||
|
||||
const SubGhzProtocol ws_protocol_infactory = {
|
||||
.name = WS_PROTOCOL_INFACTORY_NAME,
|
||||
.type = SubGhzProtocolWeatherStation,
|
||||
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_315 | SubGhzProtocolFlag_868 |
|
||||
SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable,
|
||||
|
||||
.decoder = &ws_protocol_infactory_decoder,
|
||||
.encoder = &ws_protocol_infactory_encoder,
|
||||
};
|
||||
|
||||
void* ws_protocol_decoder_infactory_alloc(SubGhzEnvironment* environment) {
|
||||
UNUSED(environment);
|
||||
WSProtocolDecoderInfactory* instance = malloc(sizeof(WSProtocolDecoderInfactory));
|
||||
instance->base.protocol = &ws_protocol_infactory;
|
||||
instance->generic.protocol_name = instance->base.protocol->name;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_infactory_free(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderInfactory* instance = context;
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_infactory_reset(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderInfactory* instance = context;
|
||||
instance->decoder.parser_step = InfactoryDecoderStepReset;
|
||||
}
|
||||
|
||||
static bool ws_protocol_infactory_check_crc(WSProtocolDecoderInfactory* instance) {
|
||||
uint8_t msg[] = {
|
||||
instance->decoder.decode_data >> 32,
|
||||
(((instance->decoder.decode_data >> 24) & 0x0F) | (instance->decoder.decode_data & 0x0F)
|
||||
<< 4),
|
||||
instance->decoder.decode_data >> 16,
|
||||
instance->decoder.decode_data >> 8,
|
||||
instance->decoder.decode_data};
|
||||
|
||||
uint8_t crc =
|
||||
subghz_protocol_blocks_crc4(msg, 4, 0x13, 0); // Koopmann 0x9, CCITT-4; FP-4; ITU-T G.704
|
||||
crc ^= msg[4] >> 4; // last nibble is only XORed
|
||||
return (crc == ((instance->decoder.decode_data >> 28) & 0x0F));
|
||||
}
|
||||
|
||||
/**
|
||||
* Analysis of received data
|
||||
* @param instance Pointer to a WSBlockGeneric* instance
|
||||
*/
|
||||
static void ws_protocol_infactory_remote_controller(WSBlockGeneric* instance) {
|
||||
instance->id = instance->data >> 32;
|
||||
instance->battery_low = (instance->data >> 26) & 1;
|
||||
instance->btn = WS_NO_BTN;
|
||||
instance->temp =
|
||||
locale_fahrenheit_to_celsius(((float)((instance->data >> 12) & 0x0FFF) - 900.0f) / 10.0f);
|
||||
instance->humidity =
|
||||
(((instance->data >> 8) & 0x0F) * 10) + ((instance->data >> 4) & 0x0F); // BCD, 'A0'=100%rH
|
||||
instance->channel = instance->data & 0x03;
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_infactory_feed(void* context, bool level, uint32_t duration) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderInfactory* instance = context;
|
||||
|
||||
switch(instance->decoder.parser_step) {
|
||||
case InfactoryDecoderStepReset:
|
||||
if((level) && (DURATION_DIFF(duration, ws_protocol_infactory_const.te_short * 2) <
|
||||
ws_protocol_infactory_const.te_delta * 2)) {
|
||||
instance->decoder.parser_step = InfactoryDecoderStepCheckPreambule;
|
||||
instance->decoder.te_last = duration;
|
||||
instance->header_count = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case InfactoryDecoderStepCheckPreambule:
|
||||
if(level) {
|
||||
instance->decoder.te_last = duration;
|
||||
} else {
|
||||
if((DURATION_DIFF(instance->decoder.te_last, ws_protocol_infactory_const.te_short * 2) <
|
||||
ws_protocol_infactory_const.te_delta * 2) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_infactory_const.te_short * 2) <
|
||||
ws_protocol_infactory_const.te_delta * 2)) {
|
||||
//Found preambule
|
||||
instance->header_count++;
|
||||
} else if(
|
||||
(DURATION_DIFF(instance->decoder.te_last, ws_protocol_infactory_const.te_short) <
|
||||
ws_protocol_infactory_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_infactory_const.te_short * 16) <
|
||||
ws_protocol_infactory_const.te_delta * 8)) {
|
||||
//Found syncPrefix
|
||||
if(instance->header_count > 3) {
|
||||
instance->decoder.parser_step = InfactoryDecoderStepSaveDuration;
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
}
|
||||
} else {
|
||||
instance->decoder.parser_step = InfactoryDecoderStepReset;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case InfactoryDecoderStepSaveDuration:
|
||||
if(level) {
|
||||
instance->decoder.te_last = duration;
|
||||
instance->decoder.parser_step = InfactoryDecoderStepCheckDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = InfactoryDecoderStepReset;
|
||||
}
|
||||
break;
|
||||
|
||||
case InfactoryDecoderStepCheckDuration:
|
||||
if(!level) {
|
||||
if(duration >= ((uint32_t)ws_protocol_infactory_const.te_short * 30)) {
|
||||
//Found syncPostfix
|
||||
if((instance->decoder.decode_count_bit ==
|
||||
ws_protocol_infactory_const.min_count_bit_for_found) &&
|
||||
ws_protocol_infactory_check_crc(instance)) {
|
||||
instance->generic.data = instance->decoder.decode_data;
|
||||
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
|
||||
ws_protocol_infactory_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 = InfactoryDecoderStepReset;
|
||||
break;
|
||||
} else if(
|
||||
(DURATION_DIFF(instance->decoder.te_last, ws_protocol_infactory_const.te_short) <
|
||||
ws_protocol_infactory_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_infactory_const.te_long) <
|
||||
ws_protocol_infactory_const.te_delta * 2)) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
||||
instance->decoder.parser_step = InfactoryDecoderStepSaveDuration;
|
||||
} else if(
|
||||
(DURATION_DIFF(instance->decoder.te_last, ws_protocol_infactory_const.te_short) <
|
||||
ws_protocol_infactory_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_infactory_const.te_long * 2) <
|
||||
ws_protocol_infactory_const.te_delta * 4)) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
||||
instance->decoder.parser_step = InfactoryDecoderStepSaveDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = InfactoryDecoderStepReset;
|
||||
}
|
||||
} else {
|
||||
instance->decoder.parser_step = InfactoryDecoderStepReset;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t ws_protocol_decoder_infactory_get_hash_data(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderInfactory* instance = context;
|
||||
return subghz_protocol_blocks_get_hash_data(
|
||||
&instance->decoder, (instance->decoder.decode_count_bit / 8) + 1);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus ws_protocol_decoder_infactory_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderInfactory* instance = context;
|
||||
return ws_block_generic_serialize(&instance->generic, flipper_format, preset);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus
|
||||
ws_protocol_decoder_infactory_deserialize(void* context, FlipperFormat* flipper_format) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderInfactory* instance = context;
|
||||
return ws_block_generic_deserialize_check_count_bit(
|
||||
&instance->generic, flipper_format, ws_protocol_infactory_const.min_count_bit_for_found);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_infactory_get_string(void* context, FuriString* output) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderInfactory* instance = context;
|
||||
furi_string_printf(
|
||||
output,
|
||||
"%s %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
applications/external/weather_station/protocols/infactory.h
vendored
Normal file
80
applications/external/weather_station/protocols/infactory.h
vendored
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_INFACTORY_NAME "inFactory-TH"
|
||||
|
||||
typedef struct WSProtocolDecoderInfactory WSProtocolDecoderInfactory;
|
||||
typedef struct WSProtocolEncoderInfactory WSProtocolEncoderInfactory;
|
||||
|
||||
extern const SubGhzProtocolDecoder ws_protocol_infactory_decoder;
|
||||
extern const SubGhzProtocolEncoder ws_protocol_infactory_encoder;
|
||||
extern const SubGhzProtocol ws_protocol_infactory;
|
||||
|
||||
/**
|
||||
* Allocate WSProtocolDecoderInfactory.
|
||||
* @param environment Pointer to a SubGhzEnvironment instance
|
||||
* @return WSProtocolDecoderInfactory* pointer to a WSProtocolDecoderInfactory instance
|
||||
*/
|
||||
void* ws_protocol_decoder_infactory_alloc(SubGhzEnvironment* environment);
|
||||
|
||||
/**
|
||||
* Free WSProtocolDecoderInfactory.
|
||||
* @param context Pointer to a WSProtocolDecoderInfactory instance
|
||||
*/
|
||||
void ws_protocol_decoder_infactory_free(void* context);
|
||||
|
||||
/**
|
||||
* Reset decoder WSProtocolDecoderInfactory.
|
||||
* @param context Pointer to a WSProtocolDecoderInfactory instance
|
||||
*/
|
||||
void ws_protocol_decoder_infactory_reset(void* context);
|
||||
|
||||
/**
|
||||
* Parse a raw sequence of levels and durations received from the air.
|
||||
* @param context Pointer to a WSProtocolDecoderInfactory instance
|
||||
* @param level Signal level true-high false-low
|
||||
* @param duration Duration of this level in, us
|
||||
*/
|
||||
void ws_protocol_decoder_infactory_feed(void* context, bool level, uint32_t duration);
|
||||
|
||||
/**
|
||||
* Getting the hash sum of the last randomly received parcel.
|
||||
* @param context Pointer to a WSProtocolDecoderInfactory instance
|
||||
* @return hash Hash sum
|
||||
*/
|
||||
uint8_t ws_protocol_decoder_infactory_get_hash_data(void* context);
|
||||
|
||||
/**
|
||||
* Serialize data WSProtocolDecoderInfactory.
|
||||
* @param context Pointer to a WSProtocolDecoderInfactory 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_infactory_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset);
|
||||
|
||||
/**
|
||||
* Deserialize data WSProtocolDecoderInfactory.
|
||||
* @param context Pointer to a WSProtocolDecoderInfactory instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @return status
|
||||
*/
|
||||
SubGhzProtocolStatus
|
||||
ws_protocol_decoder_infactory_deserialize(void* context, FlipperFormat* flipper_format);
|
||||
|
||||
/**
|
||||
* Getting a textual representation of the received data.
|
||||
* @param context Pointer to a WSProtocolDecoderInfactory instance
|
||||
* @param output Resulting text
|
||||
*/
|
||||
void ws_protocol_decoder_infactory_get_string(void* context, FuriString* output);
|
319
applications/external/weather_station/protocols/lacrosse_tx.c
vendored
Normal file
319
applications/external/weather_station/protocols/lacrosse_tx.c
vendored
Normal file
@@ -0,0 +1,319 @@
|
||||
#include "lacrosse_tx.h"
|
||||
|
||||
#define TAG "WSProtocolLaCrosse_TX"
|
||||
|
||||
/*
|
||||
* Help
|
||||
* https://github.com/merbanan/rtl_433/blob/master/src/devices/lacrosse.c
|
||||
*
|
||||
*
|
||||
* LaCrosse TX 433 Mhz Temperature and Humidity Sensors.
|
||||
* - Tested: TX-7U and TX-6U (Temperature only)
|
||||
* - Not Tested but should work: TX-3, TX-4
|
||||
* - also TFA Dostmann 30.3120.90 sensor (for e.g. 35.1018.06 (WS-9015) station)
|
||||
* - also TFA Dostmann 30.3121 sensor
|
||||
* Protocol Documentation: http://www.f6fbb.org/domo/sensors/tx3_th.php
|
||||
* Message is 44 bits, 11 x 4 bit nybbles:
|
||||
* [00] [cnt = 10] [type] [addr] [addr + parity] [v1] [v2] [v3] [iv1] [iv2] [check]
|
||||
* Notes:
|
||||
* - Zero Pulses are longer (1,400 uS High, 1,000 uS Low) = 2,400 uS
|
||||
* - One Pulses are shorter ( 550 uS High, 1,000 uS Low) = 1,600 uS
|
||||
* - Sensor id changes when the battery is changed
|
||||
* - Primary Value are BCD with one decimal place: vvv = 12.3
|
||||
* - Secondary value is integer only intval = 12, seems to be a repeat of primary
|
||||
* This may actually be an additional data check because the 4 bit checksum
|
||||
* and parity bit is pretty week at detecting errors.
|
||||
* - Temperature is in Celsius with 50.0 added (to handle negative values)
|
||||
* - Humidity values appear to be integer precision, decimal always 0.
|
||||
* - There is a 4 bit checksum and a parity bit covering the three digit value
|
||||
* - Parity check for TX-3 and TX-4 might be different.
|
||||
* - Msg sent with one repeat after 30 mS
|
||||
* - Temperature and humidity are sent as separate messages
|
||||
* - Frequency for each sensor may be could be off by as much as 50-75 khz
|
||||
* - LaCrosse Sensors in other frequency ranges (915 Mhz) use FSK not OOK
|
||||
* so they can't be decoded by rtl_433 currently.
|
||||
* - Temperature and Humidity are sent in different messages bursts.
|
||||
*/
|
||||
|
||||
#define LACROSSE_TX_GAP 1000
|
||||
#define LACROSSE_TX_BIT_SIZE 44
|
||||
#define LACROSSE_TX_SUNC_PATTERN 0x0A000000000
|
||||
#define LACROSSE_TX_SUNC_MASK 0x0F000000000
|
||||
#define LACROSSE_TX_MSG_TYPE_TEMP 0x00
|
||||
#define LACROSSE_TX_MSG_TYPE_HUM 0x0E
|
||||
|
||||
static const SubGhzBlockConst ws_protocol_lacrosse_tx_const = {
|
||||
.te_short = 550,
|
||||
.te_long = 1300,
|
||||
.te_delta = 120,
|
||||
.min_count_bit_for_found = 40,
|
||||
};
|
||||
|
||||
struct WSProtocolDecoderLaCrosse_TX {
|
||||
SubGhzProtocolDecoderBase base;
|
||||
|
||||
SubGhzBlockDecoder decoder;
|
||||
WSBlockGeneric generic;
|
||||
|
||||
uint16_t header_count;
|
||||
};
|
||||
|
||||
struct WSProtocolEncoderLaCrosse_TX {
|
||||
SubGhzProtocolEncoderBase base;
|
||||
|
||||
SubGhzProtocolBlockEncoder encoder;
|
||||
WSBlockGeneric generic;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
LaCrosse_TXDecoderStepReset = 0,
|
||||
LaCrosse_TXDecoderStepCheckPreambule,
|
||||
LaCrosse_TXDecoderStepSaveDuration,
|
||||
LaCrosse_TXDecoderStepCheckDuration,
|
||||
} LaCrosse_TXDecoderStep;
|
||||
|
||||
const SubGhzProtocolDecoder ws_protocol_lacrosse_tx_decoder = {
|
||||
.alloc = ws_protocol_decoder_lacrosse_tx_alloc,
|
||||
.free = ws_protocol_decoder_lacrosse_tx_free,
|
||||
|
||||
.feed = ws_protocol_decoder_lacrosse_tx_feed,
|
||||
.reset = ws_protocol_decoder_lacrosse_tx_reset,
|
||||
|
||||
.get_hash_data = ws_protocol_decoder_lacrosse_tx_get_hash_data,
|
||||
.serialize = ws_protocol_decoder_lacrosse_tx_serialize,
|
||||
.deserialize = ws_protocol_decoder_lacrosse_tx_deserialize,
|
||||
.get_string = ws_protocol_decoder_lacrosse_tx_get_string,
|
||||
};
|
||||
|
||||
const SubGhzProtocolEncoder ws_protocol_lacrosse_tx_encoder = {
|
||||
.alloc = NULL,
|
||||
.free = NULL,
|
||||
|
||||
.deserialize = NULL,
|
||||
.stop = NULL,
|
||||
.yield = NULL,
|
||||
};
|
||||
|
||||
const SubGhzProtocol ws_protocol_lacrosse_tx = {
|
||||
.name = WS_PROTOCOL_LACROSSE_TX_NAME,
|
||||
.type = SubGhzProtocolWeatherStation,
|
||||
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_315 | SubGhzProtocolFlag_868 |
|
||||
SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable,
|
||||
|
||||
.decoder = &ws_protocol_lacrosse_tx_decoder,
|
||||
.encoder = &ws_protocol_lacrosse_tx_encoder,
|
||||
};
|
||||
|
||||
void* ws_protocol_decoder_lacrosse_tx_alloc(SubGhzEnvironment* environment) {
|
||||
UNUSED(environment);
|
||||
WSProtocolDecoderLaCrosse_TX* instance = malloc(sizeof(WSProtocolDecoderLaCrosse_TX));
|
||||
instance->base.protocol = &ws_protocol_lacrosse_tx;
|
||||
instance->generic.protocol_name = instance->base.protocol->name;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_lacrosse_tx_free(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderLaCrosse_TX* instance = context;
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_lacrosse_tx_reset(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderLaCrosse_TX* instance = context;
|
||||
instance->header_count = 0;
|
||||
instance->decoder.parser_step = LaCrosse_TXDecoderStepReset;
|
||||
}
|
||||
|
||||
static bool ws_protocol_lacrosse_tx_check_crc(WSProtocolDecoderLaCrosse_TX* instance) {
|
||||
if(!instance->decoder.decode_data) return false;
|
||||
uint8_t msg[] = {
|
||||
(instance->decoder.decode_data >> 36) & 0x0F,
|
||||
(instance->decoder.decode_data >> 32) & 0x0F,
|
||||
(instance->decoder.decode_data >> 28) & 0x0F,
|
||||
(instance->decoder.decode_data >> 24) & 0x0F,
|
||||
(instance->decoder.decode_data >> 20) & 0x0F,
|
||||
(instance->decoder.decode_data >> 16) & 0x0F,
|
||||
(instance->decoder.decode_data >> 12) & 0x0F,
|
||||
(instance->decoder.decode_data >> 8) & 0x0F,
|
||||
(instance->decoder.decode_data >> 4) & 0x0F};
|
||||
|
||||
uint8_t crc = subghz_protocol_blocks_add_bytes(msg, 9);
|
||||
return ((crc & 0x0F) == ((instance->decoder.decode_data) & 0x0F));
|
||||
}
|
||||
|
||||
/**
|
||||
* Analysis of received data
|
||||
* @param instance Pointer to a WSBlockGeneric* instance
|
||||
*/
|
||||
static void ws_protocol_lacrosse_tx_remote_controller(WSBlockGeneric* instance) {
|
||||
uint8_t msg_type = (instance->data >> 32) & 0x0F;
|
||||
instance->id = (((instance->data >> 28) & 0x0F) << 3) | (((instance->data >> 24) & 0x0F) >> 1);
|
||||
|
||||
float msg_value = (float)((instance->data >> 20) & 0x0F) * 10.0f +
|
||||
(float)((instance->data >> 16) & 0x0F) +
|
||||
(float)((instance->data >> 12) & 0x0F) * 0.1f;
|
||||
|
||||
if(msg_type == LACROSSE_TX_MSG_TYPE_TEMP) { //-V1051
|
||||
instance->temp = msg_value - 50.0f;
|
||||
instance->humidity = WS_NO_HUMIDITY;
|
||||
} else if(msg_type == LACROSSE_TX_MSG_TYPE_HUM) {
|
||||
//ToDo for verification, records are needed with sensors maintaining temperature and temperature for this standard
|
||||
instance->humidity = (uint8_t)msg_value;
|
||||
} else {
|
||||
furi_crash("WS: WSProtocolLaCrosse_TX incorrect msg_type.");
|
||||
}
|
||||
|
||||
instance->btn = WS_NO_BTN;
|
||||
instance->battery_low = WS_NO_BATT;
|
||||
instance->channel = WS_NO_CHANNEL;
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_lacrosse_tx_feed(void* context, bool level, uint32_t duration) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderLaCrosse_TX* instance = context;
|
||||
|
||||
switch(instance->decoder.parser_step) {
|
||||
case LaCrosse_TXDecoderStepReset:
|
||||
if((!level) && (DURATION_DIFF(duration, LACROSSE_TX_GAP) <
|
||||
ws_protocol_lacrosse_tx_const.te_delta * 2)) {
|
||||
instance->decoder.parser_step = LaCrosse_TXDecoderStepCheckPreambule;
|
||||
instance->header_count = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case LaCrosse_TXDecoderStepCheckPreambule:
|
||||
|
||||
if(level) {
|
||||
if((DURATION_DIFF(duration, ws_protocol_lacrosse_tx_const.te_short) <
|
||||
ws_protocol_lacrosse_tx_const.te_delta) &&
|
||||
(instance->header_count > 1)) {
|
||||
instance->decoder.parser_step = LaCrosse_TXDecoderStepCheckDuration;
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
instance->decoder.te_last = duration;
|
||||
} else if(duration > (ws_protocol_lacrosse_tx_const.te_long * 2)) {
|
||||
instance->decoder.parser_step = LaCrosse_TXDecoderStepReset;
|
||||
}
|
||||
} else {
|
||||
if(DURATION_DIFF(duration, LACROSSE_TX_GAP) <
|
||||
ws_protocol_lacrosse_tx_const.te_delta * 2) {
|
||||
instance->decoder.te_last = duration;
|
||||
instance->header_count++;
|
||||
} else {
|
||||
instance->decoder.parser_step = LaCrosse_TXDecoderStepReset;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case LaCrosse_TXDecoderStepSaveDuration:
|
||||
if(level) {
|
||||
instance->decoder.te_last = duration;
|
||||
instance->decoder.parser_step = LaCrosse_TXDecoderStepCheckDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = LaCrosse_TXDecoderStepReset;
|
||||
}
|
||||
break;
|
||||
|
||||
case LaCrosse_TXDecoderStepCheckDuration:
|
||||
|
||||
if(!level) {
|
||||
if(duration > LACROSSE_TX_GAP * 3) {
|
||||
if(DURATION_DIFF(
|
||||
instance->decoder.te_last, ws_protocol_lacrosse_tx_const.te_short) <
|
||||
ws_protocol_lacrosse_tx_const.te_delta) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
||||
instance->decoder.parser_step = LaCrosse_TXDecoderStepSaveDuration;
|
||||
} else if(
|
||||
DURATION_DIFF(
|
||||
instance->decoder.te_last, ws_protocol_lacrosse_tx_const.te_long) <
|
||||
ws_protocol_lacrosse_tx_const.te_delta) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
||||
instance->decoder.parser_step = LaCrosse_TXDecoderStepSaveDuration;
|
||||
}
|
||||
if((instance->decoder.decode_data & LACROSSE_TX_SUNC_MASK) ==
|
||||
LACROSSE_TX_SUNC_PATTERN) {
|
||||
if(ws_protocol_lacrosse_tx_check_crc(instance)) {
|
||||
instance->generic.data = instance->decoder.decode_data;
|
||||
instance->generic.data_count_bit = LACROSSE_TX_BIT_SIZE;
|
||||
ws_protocol_lacrosse_tx_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->header_count = 0;
|
||||
instance->decoder.parser_step = LaCrosse_TXDecoderStepReset;
|
||||
break;
|
||||
} else if(
|
||||
(DURATION_DIFF(instance->decoder.te_last, ws_protocol_lacrosse_tx_const.te_short) <
|
||||
ws_protocol_lacrosse_tx_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, LACROSSE_TX_GAP) <
|
||||
ws_protocol_lacrosse_tx_const.te_delta * 2)) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
||||
instance->decoder.parser_step = LaCrosse_TXDecoderStepSaveDuration;
|
||||
} else if(
|
||||
(DURATION_DIFF(instance->decoder.te_last, ws_protocol_lacrosse_tx_const.te_long) <
|
||||
ws_protocol_lacrosse_tx_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, LACROSSE_TX_GAP) <
|
||||
ws_protocol_lacrosse_tx_const.te_delta * 2)) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
||||
instance->decoder.parser_step = LaCrosse_TXDecoderStepSaveDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = LaCrosse_TXDecoderStepReset;
|
||||
}
|
||||
|
||||
} else {
|
||||
instance->decoder.parser_step = LaCrosse_TXDecoderStepReset;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t ws_protocol_decoder_lacrosse_tx_get_hash_data(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderLaCrosse_TX* instance = context;
|
||||
return subghz_protocol_blocks_get_hash_data(
|
||||
&instance->decoder, (instance->decoder.decode_count_bit / 8) + 1);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus ws_protocol_decoder_lacrosse_tx_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderLaCrosse_TX* instance = context;
|
||||
return ws_block_generic_serialize(&instance->generic, flipper_format, preset);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus
|
||||
ws_protocol_decoder_lacrosse_tx_deserialize(void* context, FlipperFormat* flipper_format) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderLaCrosse_TX* instance = context;
|
||||
return ws_block_generic_deserialize_check_count_bit(
|
||||
&instance->generic, flipper_format, ws_protocol_lacrosse_tx_const.min_count_bit_for_found);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_lacrosse_tx_get_string(void* context, FuriString* output) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderLaCrosse_TX* instance = context;
|
||||
furi_string_printf(
|
||||
output,
|
||||
"%s %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
applications/external/weather_station/protocols/lacrosse_tx.h
vendored
Normal file
80
applications/external/weather_station/protocols/lacrosse_tx.h
vendored
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_LACROSSE_TX_NAME "LaCrosse_TX"
|
||||
|
||||
typedef struct WSProtocolDecoderLaCrosse_TX WSProtocolDecoderLaCrosse_TX;
|
||||
typedef struct WSProtocolEncoderLaCrosse_TX WSProtocolEncoderLaCrosse_TX;
|
||||
|
||||
extern const SubGhzProtocolDecoder ws_protocol_lacrosse_tx_decoder;
|
||||
extern const SubGhzProtocolEncoder ws_protocol_lacrosse_tx_encoder;
|
||||
extern const SubGhzProtocol ws_protocol_lacrosse_tx;
|
||||
|
||||
/**
|
||||
* Allocate WSProtocolDecoderLaCrosse_TX.
|
||||
* @param environment Pointer to a SubGhzEnvironment instance
|
||||
* @return WSProtocolDecoderLaCrosse_TX* pointer to a WSProtocolDecoderLaCrosse_TX instance
|
||||
*/
|
||||
void* ws_protocol_decoder_lacrosse_tx_alloc(SubGhzEnvironment* environment);
|
||||
|
||||
/**
|
||||
* Free WSProtocolDecoderLaCrosse_TX.
|
||||
* @param context Pointer to a WSProtocolDecoderLaCrosse_TX instance
|
||||
*/
|
||||
void ws_protocol_decoder_lacrosse_tx_free(void* context);
|
||||
|
||||
/**
|
||||
* Reset decoder WSProtocolDecoderLaCrosse_TX.
|
||||
* @param context Pointer to a WSProtocolDecoderLaCrosse_TX instance
|
||||
*/
|
||||
void ws_protocol_decoder_lacrosse_tx_reset(void* context);
|
||||
|
||||
/**
|
||||
* Parse a raw sequence of levels and durations received from the air.
|
||||
* @param context Pointer to a WSProtocolDecoderLaCrosse_TX instance
|
||||
* @param level Signal level true-high false-low
|
||||
* @param duration Duration of this level in, us
|
||||
*/
|
||||
void ws_protocol_decoder_lacrosse_tx_feed(void* context, bool level, uint32_t duration);
|
||||
|
||||
/**
|
||||
* Getting the hash sum of the last randomly received parcel.
|
||||
* @param context Pointer to a WSProtocolDecoderLaCrosse_TX instance
|
||||
* @return hash Hash sum
|
||||
*/
|
||||
uint8_t ws_protocol_decoder_lacrosse_tx_get_hash_data(void* context);
|
||||
|
||||
/**
|
||||
* Serialize data WSProtocolDecoderLaCrosse_TX.
|
||||
* @param context Pointer to a WSProtocolDecoderLaCrosse_TX 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_lacrosse_tx_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset);
|
||||
|
||||
/**
|
||||
* Deserialize data WSProtocolDecoderLaCrosse_TX.
|
||||
* @param context Pointer to a WSProtocolDecoderLaCrosse_TX instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @return status
|
||||
*/
|
||||
SubGhzProtocolStatus
|
||||
ws_protocol_decoder_lacrosse_tx_deserialize(void* context, FlipperFormat* flipper_format);
|
||||
|
||||
/**
|
||||
* Getting a textual representation of the received data.
|
||||
* @param context Pointer to a WSProtocolDecoderLaCrosse_TX instance
|
||||
* @param output Resulting text
|
||||
*/
|
||||
void ws_protocol_decoder_lacrosse_tx_get_string(void* context, FuriString* output);
|
288
applications/external/weather_station/protocols/lacrosse_tx141thbv2.c
vendored
Normal file
288
applications/external/weather_station/protocols/lacrosse_tx141thbv2.c
vendored
Normal file
@@ -0,0 +1,288 @@
|
||||
#include "lacrosse_tx141thbv2.h"
|
||||
|
||||
#define TAG "WSProtocolLaCrosse_TX141THBv2"
|
||||
|
||||
/*
|
||||
* Help
|
||||
* https://github.com/merbanan/rtl_433/blob/master/src/devices/lacrosse_tx141x.c
|
||||
*
|
||||
* iiii iiii | bkcc tttt | tttt tttt | hhhh hhhh | cccc cccc | u
|
||||
* - i: identification; changes on battery switch
|
||||
* - c: lfsr_digest8_reflect;
|
||||
* - u: unknown;
|
||||
* - b: battery low; flag to indicate low battery voltage
|
||||
* - h: Humidity;
|
||||
* - t: Temperature; in °F as binary number with one decimal place + 50 °F offset
|
||||
* - n: Channel; Channel number 1 - 3
|
||||
*/
|
||||
|
||||
static const SubGhzBlockConst ws_protocol_lacrosse_tx141thbv2_const = {
|
||||
.te_short = 250,
|
||||
.te_long = 500,
|
||||
.te_delta = 120,
|
||||
.min_count_bit_for_found = 41,
|
||||
};
|
||||
|
||||
struct WSProtocolDecoderLaCrosse_TX141THBv2 {
|
||||
SubGhzProtocolDecoderBase base;
|
||||
|
||||
SubGhzBlockDecoder decoder;
|
||||
WSBlockGeneric generic;
|
||||
|
||||
uint16_t header_count;
|
||||
};
|
||||
|
||||
struct WSProtocolEncoderLaCrosse_TX141THBv2 {
|
||||
SubGhzProtocolEncoderBase base;
|
||||
|
||||
SubGhzProtocolBlockEncoder encoder;
|
||||
WSBlockGeneric generic;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
LaCrosse_TX141THBv2DecoderStepReset = 0,
|
||||
LaCrosse_TX141THBv2DecoderStepCheckPreambule,
|
||||
LaCrosse_TX141THBv2DecoderStepSaveDuration,
|
||||
LaCrosse_TX141THBv2DecoderStepCheckDuration,
|
||||
} LaCrosse_TX141THBv2DecoderStep;
|
||||
|
||||
const SubGhzProtocolDecoder ws_protocol_lacrosse_tx141thbv2_decoder = {
|
||||
.alloc = ws_protocol_decoder_lacrosse_tx141thbv2_alloc,
|
||||
.free = ws_protocol_decoder_lacrosse_tx141thbv2_free,
|
||||
|
||||
.feed = ws_protocol_decoder_lacrosse_tx141thbv2_feed,
|
||||
.reset = ws_protocol_decoder_lacrosse_tx141thbv2_reset,
|
||||
|
||||
.get_hash_data = ws_protocol_decoder_lacrosse_tx141thbv2_get_hash_data,
|
||||
.serialize = ws_protocol_decoder_lacrosse_tx141thbv2_serialize,
|
||||
.deserialize = ws_protocol_decoder_lacrosse_tx141thbv2_deserialize,
|
||||
.get_string = ws_protocol_decoder_lacrosse_tx141thbv2_get_string,
|
||||
};
|
||||
|
||||
const SubGhzProtocolEncoder ws_protocol_lacrosse_tx141thbv2_encoder = {
|
||||
.alloc = NULL,
|
||||
.free = NULL,
|
||||
|
||||
.deserialize = NULL,
|
||||
.stop = NULL,
|
||||
.yield = NULL,
|
||||
};
|
||||
|
||||
const SubGhzProtocol ws_protocol_lacrosse_tx141thbv2 = {
|
||||
.name = WS_PROTOCOL_LACROSSE_TX141THBV2_NAME,
|
||||
.type = SubGhzProtocolWeatherStation,
|
||||
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_315 | SubGhzProtocolFlag_868 |
|
||||
SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable,
|
||||
|
||||
.decoder = &ws_protocol_lacrosse_tx141thbv2_decoder,
|
||||
.encoder = &ws_protocol_lacrosse_tx141thbv2_encoder,
|
||||
};
|
||||
|
||||
void* ws_protocol_decoder_lacrosse_tx141thbv2_alloc(SubGhzEnvironment* environment) {
|
||||
UNUSED(environment);
|
||||
WSProtocolDecoderLaCrosse_TX141THBv2* instance =
|
||||
malloc(sizeof(WSProtocolDecoderLaCrosse_TX141THBv2));
|
||||
instance->base.protocol = &ws_protocol_lacrosse_tx141thbv2;
|
||||
instance->generic.protocol_name = instance->base.protocol->name;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_lacrosse_tx141thbv2_free(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderLaCrosse_TX141THBv2* instance = context;
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_lacrosse_tx141thbv2_reset(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderLaCrosse_TX141THBv2* instance = context;
|
||||
instance->decoder.parser_step = LaCrosse_TX141THBv2DecoderStepReset;
|
||||
}
|
||||
|
||||
static bool
|
||||
ws_protocol_lacrosse_tx141thbv2_check_crc(WSProtocolDecoderLaCrosse_TX141THBv2* instance) {
|
||||
if(!instance->decoder.decode_data) return false;
|
||||
uint8_t msg[] = {
|
||||
instance->decoder.decode_data >> 33,
|
||||
instance->decoder.decode_data >> 25,
|
||||
instance->decoder.decode_data >> 17,
|
||||
instance->decoder.decode_data >> 9};
|
||||
|
||||
uint8_t crc = subghz_protocol_blocks_lfsr_digest8_reflect(msg, 4, 0x31, 0xF4);
|
||||
return (crc == ((instance->decoder.decode_data >> 1) & 0xFF));
|
||||
}
|
||||
|
||||
/**
|
||||
* Analysis of received data
|
||||
* @param instance Pointer to a WSBlockGeneric* instance
|
||||
*/
|
||||
static void ws_protocol_lacrosse_tx141thbv2_remote_controller(WSBlockGeneric* instance) {
|
||||
instance->id = instance->data >> 33;
|
||||
instance->battery_low = (instance->data >> 32) & 1;
|
||||
instance->btn = (instance->data >> 31) & 1;
|
||||
instance->channel = ((instance->data >> 29) & 0x03) + 1;
|
||||
instance->temp = ((float)((instance->data >> 17) & 0x0FFF) - 500.0f) / 10.0f;
|
||||
instance->humidity = (instance->data >> 9) & 0xFF;
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_lacrosse_tx141thbv2_feed(void* context, bool level, uint32_t duration) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderLaCrosse_TX141THBv2* instance = context;
|
||||
|
||||
switch(instance->decoder.parser_step) {
|
||||
case LaCrosse_TX141THBv2DecoderStepReset:
|
||||
if((level) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_lacrosse_tx141thbv2_const.te_short * 3) <
|
||||
ws_protocol_lacrosse_tx141thbv2_const.te_delta * 2)) {
|
||||
instance->decoder.parser_step = LaCrosse_TX141THBv2DecoderStepCheckPreambule;
|
||||
instance->decoder.te_last = duration;
|
||||
instance->header_count = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case LaCrosse_TX141THBv2DecoderStepCheckPreambule:
|
||||
if(level) {
|
||||
instance->decoder.te_last = duration;
|
||||
} else {
|
||||
if((DURATION_DIFF(
|
||||
instance->decoder.te_last,
|
||||
ws_protocol_lacrosse_tx141thbv2_const.te_short * 3) <
|
||||
ws_protocol_lacrosse_tx141thbv2_const.te_delta * 2) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_lacrosse_tx141thbv2_const.te_short * 3) <
|
||||
ws_protocol_lacrosse_tx141thbv2_const.te_delta * 2)) {
|
||||
//Found preambule
|
||||
instance->header_count++;
|
||||
} else if(instance->header_count == 4) {
|
||||
if((DURATION_DIFF(
|
||||
instance->decoder.te_last,
|
||||
ws_protocol_lacrosse_tx141thbv2_const.te_short) <
|
||||
ws_protocol_lacrosse_tx141thbv2_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_lacrosse_tx141thbv2_const.te_long) <
|
||||
ws_protocol_lacrosse_tx141thbv2_const.te_delta)) {
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
||||
instance->decoder.parser_step = LaCrosse_TX141THBv2DecoderStepSaveDuration;
|
||||
} else if(
|
||||
(DURATION_DIFF(
|
||||
instance->decoder.te_last,
|
||||
ws_protocol_lacrosse_tx141thbv2_const.te_long) <
|
||||
ws_protocol_lacrosse_tx141thbv2_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_lacrosse_tx141thbv2_const.te_short) <
|
||||
ws_protocol_lacrosse_tx141thbv2_const.te_delta)) {
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
||||
instance->decoder.parser_step = LaCrosse_TX141THBv2DecoderStepSaveDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = LaCrosse_TX141THBv2DecoderStepReset;
|
||||
}
|
||||
} else {
|
||||
instance->decoder.parser_step = LaCrosse_TX141THBv2DecoderStepReset;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case LaCrosse_TX141THBv2DecoderStepSaveDuration:
|
||||
if(level) {
|
||||
instance->decoder.te_last = duration;
|
||||
instance->decoder.parser_step = LaCrosse_TX141THBv2DecoderStepCheckDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = LaCrosse_TX141THBv2DecoderStepReset;
|
||||
}
|
||||
break;
|
||||
|
||||
case LaCrosse_TX141THBv2DecoderStepCheckDuration:
|
||||
if(!level) {
|
||||
if(((DURATION_DIFF(
|
||||
instance->decoder.te_last,
|
||||
ws_protocol_lacrosse_tx141thbv2_const.te_short * 3) <
|
||||
ws_protocol_lacrosse_tx141thbv2_const.te_delta * 2) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_lacrosse_tx141thbv2_const.te_short * 3) <
|
||||
ws_protocol_lacrosse_tx141thbv2_const.te_delta * 2))) {
|
||||
if((instance->decoder.decode_count_bit ==
|
||||
ws_protocol_lacrosse_tx141thbv2_const.min_count_bit_for_found) &&
|
||||
ws_protocol_lacrosse_tx141thbv2_check_crc(instance)) {
|
||||
instance->generic.data = instance->decoder.decode_data;
|
||||
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
|
||||
ws_protocol_lacrosse_tx141thbv2_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->header_count = 1;
|
||||
instance->decoder.parser_step = LaCrosse_TX141THBv2DecoderStepCheckPreambule;
|
||||
break;
|
||||
} else if(
|
||||
(DURATION_DIFF(
|
||||
instance->decoder.te_last, ws_protocol_lacrosse_tx141thbv2_const.te_short) <
|
||||
ws_protocol_lacrosse_tx141thbv2_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_lacrosse_tx141thbv2_const.te_long) <
|
||||
ws_protocol_lacrosse_tx141thbv2_const.te_delta)) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
||||
instance->decoder.parser_step = LaCrosse_TX141THBv2DecoderStepSaveDuration;
|
||||
} else if(
|
||||
(DURATION_DIFF(
|
||||
instance->decoder.te_last, ws_protocol_lacrosse_tx141thbv2_const.te_long) <
|
||||
ws_protocol_lacrosse_tx141thbv2_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_lacrosse_tx141thbv2_const.te_short) <
|
||||
ws_protocol_lacrosse_tx141thbv2_const.te_delta)) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
||||
instance->decoder.parser_step = LaCrosse_TX141THBv2DecoderStepSaveDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = LaCrosse_TX141THBv2DecoderStepReset;
|
||||
}
|
||||
} else {
|
||||
instance->decoder.parser_step = LaCrosse_TX141THBv2DecoderStepReset;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t ws_protocol_decoder_lacrosse_tx141thbv2_get_hash_data(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderLaCrosse_TX141THBv2* instance = context;
|
||||
return subghz_protocol_blocks_get_hash_data(
|
||||
&instance->decoder, (instance->decoder.decode_count_bit / 8) + 1);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus ws_protocol_decoder_lacrosse_tx141thbv2_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderLaCrosse_TX141THBv2* instance = context;
|
||||
return ws_block_generic_serialize(&instance->generic, flipper_format, preset);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus ws_protocol_decoder_lacrosse_tx141thbv2_deserialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderLaCrosse_TX141THBv2* instance = context;
|
||||
return ws_block_generic_deserialize_check_count_bit(
|
||||
&instance->generic,
|
||||
flipper_format,
|
||||
ws_protocol_lacrosse_tx141thbv2_const.min_count_bit_for_found);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_lacrosse_tx141thbv2_get_string(void* context, FuriString* output) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderLaCrosse_TX141THBv2* instance = context;
|
||||
furi_string_printf(
|
||||
output,
|
||||
"%s %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);
|
||||
}
|
81
applications/external/weather_station/protocols/lacrosse_tx141thbv2.h
vendored
Normal file
81
applications/external/weather_station/protocols/lacrosse_tx141thbv2.h
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
#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_LACROSSE_TX141THBV2_NAME "TX141THBv2"
|
||||
|
||||
typedef struct WSProtocolDecoderLaCrosse_TX141THBv2 WSProtocolDecoderLaCrosse_TX141THBv2;
|
||||
typedef struct WSProtocolEncoderLaCrosse_TX141THBv2 WSProtocolEncoderLaCrosse_TX141THBv2;
|
||||
|
||||
extern const SubGhzProtocolDecoder ws_protocol_lacrosse_tx141thbv2_decoder;
|
||||
extern const SubGhzProtocolEncoder ws_protocol_lacrosse_tx141thbv2_encoder;
|
||||
extern const SubGhzProtocol ws_protocol_lacrosse_tx141thbv2;
|
||||
|
||||
/**
|
||||
* Allocate WSProtocolDecoderLaCrosse_TX141THBv2.
|
||||
* @param environment Pointer to a SubGhzEnvironment instance
|
||||
* @return WSProtocolDecoderLaCrosse_TX141THBv2* pointer to a WSProtocolDecoderLaCrosse_TX141THBv2 instance
|
||||
*/
|
||||
void* ws_protocol_decoder_lacrosse_tx141thbv2_alloc(SubGhzEnvironment* environment);
|
||||
|
||||
/**
|
||||
* Free WSProtocolDecoderLaCrosse_TX141THBv2.
|
||||
* @param context Pointer to a WSProtocolDecoderLaCrosse_TX141THBv2 instance
|
||||
*/
|
||||
void ws_protocol_decoder_lacrosse_tx141thbv2_free(void* context);
|
||||
|
||||
/**
|
||||
* Reset decoder WSProtocolDecoderLaCrosse_TX141THBv2.
|
||||
* @param context Pointer to a WSProtocolDecoderLaCrosse_TX141THBv2 instance
|
||||
*/
|
||||
void ws_protocol_decoder_lacrosse_tx141thbv2_reset(void* context);
|
||||
|
||||
/**
|
||||
* Parse a raw sequence of levels and durations received from the air.
|
||||
* @param context Pointer to a WSProtocolDecoderLaCrosse_TX141THBv2 instance
|
||||
* @param level Signal level true-high false-low
|
||||
* @param duration Duration of this level in, us
|
||||
*/
|
||||
void ws_protocol_decoder_lacrosse_tx141thbv2_feed(void* context, bool level, uint32_t duration);
|
||||
|
||||
/**
|
||||
* Getting the hash sum of the last randomly received parcel.
|
||||
* @param context Pointer to a WSProtocolDecoderLaCrosse_TX141THBv2 instance
|
||||
* @return hash Hash sum
|
||||
*/
|
||||
uint8_t ws_protocol_decoder_lacrosse_tx141thbv2_get_hash_data(void* context);
|
||||
|
||||
/**
|
||||
* Serialize data WSProtocolDecoderLaCrosse_TX141THBv2.
|
||||
* @param context Pointer to a WSProtocolDecoderLaCrosse_TX141THBv2 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_lacrosse_tx141thbv2_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset);
|
||||
|
||||
/**
|
||||
* Deserialize data WSProtocolDecoderLaCrosse_TX141THBv2.
|
||||
* @param context Pointer to a WSProtocolDecoderLaCrosse_TX141THBv2 instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @return status
|
||||
*/
|
||||
SubGhzProtocolStatus ws_protocol_decoder_lacrosse_tx141thbv2_deserialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format);
|
||||
|
||||
/**
|
||||
* Getting a textual representation of the received data.
|
||||
* @param context Pointer to a WSProtocolDecoderLaCrosse_TX141THBv2 instance
|
||||
* @param output Resulting text
|
||||
*/
|
||||
void ws_protocol_decoder_lacrosse_tx141thbv2_get_string(void* context, FuriString* output);
|
254
applications/external/weather_station/protocols/nexus_th.c
vendored
Normal file
254
applications/external/weather_station/protocols/nexus_th.c
vendored
Normal file
@@ -0,0 +1,254 @@
|
||||
#include "nexus_th.h"
|
||||
|
||||
#define TAG "WSProtocolNexus_TH"
|
||||
|
||||
/*
|
||||
* Help
|
||||
* https://github.com/merbanan/rtl_433/blob/master/src/devices/nexus.c
|
||||
*
|
||||
* Nexus sensor protocol with ID, temperature and optional humidity
|
||||
* also FreeTec (Pearl) NC-7345 sensors for FreeTec Weatherstation NC-7344,
|
||||
* also infactory/FreeTec (Pearl) NX-3980 sensors for infactory/FreeTec NX-3974 station,
|
||||
* also Solight TE82S sensors for Solight TE76/TE82/TE83/TE84 stations,
|
||||
* also TFA 30.3209.02 temperature/humidity sensor.
|
||||
* The sensor sends 36 bits 12 times,
|
||||
* the packets are ppm modulated (distance coding) with a pulse of ~500 us
|
||||
* followed by a short gap of ~1000 us for a 0 bit or a long ~2000 us gap for a
|
||||
* 1 bit, the sync gap is ~4000 us.
|
||||
* The data is grouped in 9 nibbles:
|
||||
* [id0] [id1] [flags] [temp0] [temp1] [temp2] [const] [humi0] [humi1]
|
||||
* - The 8-bit id changes when the battery is changed in the sensor.
|
||||
* - flags are 4 bits B 0 C C, where B is the battery status: 1=OK, 0=LOW
|
||||
* - and CC is the channel: 0=CH1, 1=CH2, 2=CH3
|
||||
* - temp is 12 bit signed scaled by 10
|
||||
* - const is always 1111 (0x0F)
|
||||
* - humidity is 8 bits
|
||||
* The sensors can be bought at Clas Ohlsen (Nexus) and Pearl (infactory/FreeTec).
|
||||
*
|
||||
*/
|
||||
|
||||
#define NEXUS_TH_CONST_DATA 0b1111
|
||||
|
||||
static const SubGhzBlockConst ws_protocol_nexus_th_const = {
|
||||
.te_short = 500,
|
||||
.te_long = 2000,
|
||||
.te_delta = 150,
|
||||
.min_count_bit_for_found = 36,
|
||||
};
|
||||
|
||||
struct WSProtocolDecoderNexus_TH {
|
||||
SubGhzProtocolDecoderBase base;
|
||||
|
||||
SubGhzBlockDecoder decoder;
|
||||
WSBlockGeneric generic;
|
||||
};
|
||||
|
||||
struct WSProtocolEncoderNexus_TH {
|
||||
SubGhzProtocolEncoderBase base;
|
||||
|
||||
SubGhzProtocolBlockEncoder encoder;
|
||||
WSBlockGeneric generic;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
Nexus_THDecoderStepReset = 0,
|
||||
Nexus_THDecoderStepSaveDuration,
|
||||
Nexus_THDecoderStepCheckDuration,
|
||||
} Nexus_THDecoderStep;
|
||||
|
||||
const SubGhzProtocolDecoder ws_protocol_nexus_th_decoder = {
|
||||
.alloc = ws_protocol_decoder_nexus_th_alloc,
|
||||
.free = ws_protocol_decoder_nexus_th_free,
|
||||
|
||||
.feed = ws_protocol_decoder_nexus_th_feed,
|
||||
.reset = ws_protocol_decoder_nexus_th_reset,
|
||||
|
||||
.get_hash_data = ws_protocol_decoder_nexus_th_get_hash_data,
|
||||
.serialize = ws_protocol_decoder_nexus_th_serialize,
|
||||
.deserialize = ws_protocol_decoder_nexus_th_deserialize,
|
||||
.get_string = ws_protocol_decoder_nexus_th_get_string,
|
||||
};
|
||||
|
||||
const SubGhzProtocolEncoder ws_protocol_nexus_th_encoder = {
|
||||
.alloc = NULL,
|
||||
.free = NULL,
|
||||
|
||||
.deserialize = NULL,
|
||||
.stop = NULL,
|
||||
.yield = NULL,
|
||||
};
|
||||
|
||||
const SubGhzProtocol ws_protocol_nexus_th = {
|
||||
.name = WS_PROTOCOL_NEXUS_TH_NAME,
|
||||
.type = SubGhzProtocolWeatherStation,
|
||||
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_315 | SubGhzProtocolFlag_868 |
|
||||
SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable,
|
||||
|
||||
.decoder = &ws_protocol_nexus_th_decoder,
|
||||
.encoder = &ws_protocol_nexus_th_encoder,
|
||||
};
|
||||
|
||||
void* ws_protocol_decoder_nexus_th_alloc(SubGhzEnvironment* environment) {
|
||||
UNUSED(environment);
|
||||
WSProtocolDecoderNexus_TH* instance = malloc(sizeof(WSProtocolDecoderNexus_TH));
|
||||
instance->base.protocol = &ws_protocol_nexus_th;
|
||||
instance->generic.protocol_name = instance->base.protocol->name;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_nexus_th_free(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderNexus_TH* instance = context;
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_nexus_th_reset(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderNexus_TH* instance = context;
|
||||
instance->decoder.parser_step = Nexus_THDecoderStepReset;
|
||||
}
|
||||
|
||||
static bool ws_protocol_nexus_th_check(WSProtocolDecoderNexus_TH* instance) {
|
||||
uint8_t type = (instance->decoder.decode_data >> 8) & 0x0F;
|
||||
|
||||
if((type == NEXUS_TH_CONST_DATA) && ((instance->decoder.decode_data >> 4) != 0xffffffff)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Analysis of received data
|
||||
* @param instance Pointer to a WSBlockGeneric* instance
|
||||
*/
|
||||
static void ws_protocol_nexus_th_remote_controller(WSBlockGeneric* instance) {
|
||||
instance->id = (instance->data >> 28) & 0xFF;
|
||||
instance->battery_low = !((instance->data >> 27) & 1);
|
||||
instance->channel = ((instance->data >> 24) & 0x03) + 1;
|
||||
instance->btn = WS_NO_BTN;
|
||||
if(!((instance->data >> 23) & 1)) {
|
||||
instance->temp = (float)((instance->data >> 12) & 0x07FF) / 10.0f;
|
||||
} else {
|
||||
instance->temp = (float)((~(instance->data >> 12) & 0x07FF) + 1) / -10.0f;
|
||||
}
|
||||
|
||||
instance->humidity = instance->data & 0xFF;
|
||||
if(instance->humidity > 95)
|
||||
instance->humidity = 95;
|
||||
else if(instance->humidity < 20)
|
||||
instance->humidity = 20;
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_nexus_th_feed(void* context, bool level, uint32_t duration) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderNexus_TH* instance = context;
|
||||
|
||||
switch(instance->decoder.parser_step) {
|
||||
case Nexus_THDecoderStepReset:
|
||||
if((!level) && (DURATION_DIFF(duration, ws_protocol_nexus_th_const.te_short * 8) <
|
||||
ws_protocol_nexus_th_const.te_delta * 4)) {
|
||||
//Found sync
|
||||
instance->decoder.parser_step = Nexus_THDecoderStepSaveDuration;
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case Nexus_THDecoderStepSaveDuration:
|
||||
if(level) {
|
||||
instance->decoder.te_last = duration;
|
||||
instance->decoder.parser_step = Nexus_THDecoderStepCheckDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = Nexus_THDecoderStepReset;
|
||||
}
|
||||
break;
|
||||
|
||||
case Nexus_THDecoderStepCheckDuration:
|
||||
if(!level) {
|
||||
if(DURATION_DIFF(duration, ws_protocol_nexus_th_const.te_short * 8) <
|
||||
ws_protocol_nexus_th_const.te_delta * 4) {
|
||||
//Found sync
|
||||
instance->decoder.parser_step = Nexus_THDecoderStepReset;
|
||||
if((instance->decoder.decode_count_bit ==
|
||||
ws_protocol_nexus_th_const.min_count_bit_for_found) &&
|
||||
ws_protocol_nexus_th_check(instance)) {
|
||||
instance->generic.data = instance->decoder.decode_data;
|
||||
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
|
||||
ws_protocol_nexus_th_remote_controller(&instance->generic);
|
||||
if(instance->base.callback)
|
||||
instance->base.callback(&instance->base, instance->base.context);
|
||||
instance->decoder.parser_step = Nexus_THDecoderStepCheckDuration;
|
||||
}
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
|
||||
break;
|
||||
} else if(
|
||||
(DURATION_DIFF(instance->decoder.te_last, ws_protocol_nexus_th_const.te_short) <
|
||||
ws_protocol_nexus_th_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_nexus_th_const.te_short * 2) <
|
||||
ws_protocol_nexus_th_const.te_delta * 2)) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
||||
instance->decoder.parser_step = Nexus_THDecoderStepSaveDuration;
|
||||
} else if(
|
||||
(DURATION_DIFF(instance->decoder.te_last, ws_protocol_nexus_th_const.te_short) <
|
||||
ws_protocol_nexus_th_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_nexus_th_const.te_short * 4) <
|
||||
ws_protocol_nexus_th_const.te_delta * 4)) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
||||
instance->decoder.parser_step = Nexus_THDecoderStepSaveDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = Nexus_THDecoderStepReset;
|
||||
}
|
||||
} else {
|
||||
instance->decoder.parser_step = Nexus_THDecoderStepReset;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t ws_protocol_decoder_nexus_th_get_hash_data(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderNexus_TH* instance = context;
|
||||
return subghz_protocol_blocks_get_hash_data(
|
||||
&instance->decoder, (instance->decoder.decode_count_bit / 8) + 1);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus ws_protocol_decoder_nexus_th_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderNexus_TH* instance = context;
|
||||
return ws_block_generic_serialize(&instance->generic, flipper_format, preset);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus
|
||||
ws_protocol_decoder_nexus_th_deserialize(void* context, FlipperFormat* flipper_format) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderNexus_TH* instance = context;
|
||||
return ws_block_generic_deserialize_check_count_bit(
|
||||
&instance->generic, flipper_format, ws_protocol_nexus_th_const.min_count_bit_for_found);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_nexus_th_get_string(void* context, FuriString* output) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderNexus_TH* instance = context;
|
||||
furi_string_printf(
|
||||
output,
|
||||
"%s %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
applications/external/weather_station/protocols/nexus_th.h
vendored
Normal file
80
applications/external/weather_station/protocols/nexus_th.h
vendored
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_NEXUS_TH_NAME "Nexus-TH"
|
||||
|
||||
typedef struct WSProtocolDecoderNexus_TH WSProtocolDecoderNexus_TH;
|
||||
typedef struct WSProtocolEncoderNexus_TH WSProtocolEncoderNexus_TH;
|
||||
|
||||
extern const SubGhzProtocolDecoder ws_protocol_nexus_th_decoder;
|
||||
extern const SubGhzProtocolEncoder ws_protocol_nexus_th_encoder;
|
||||
extern const SubGhzProtocol ws_protocol_nexus_th;
|
||||
|
||||
/**
|
||||
* Allocate WSProtocolDecoderNexus_TH.
|
||||
* @param environment Pointer to a SubGhzEnvironment instance
|
||||
* @return WSProtocolDecoderNexus_TH* pointer to a WSProtocolDecoderNexus_TH instance
|
||||
*/
|
||||
void* ws_protocol_decoder_nexus_th_alloc(SubGhzEnvironment* environment);
|
||||
|
||||
/**
|
||||
* Free WSProtocolDecoderNexus_TH.
|
||||
* @param context Pointer to a WSProtocolDecoderNexus_TH instance
|
||||
*/
|
||||
void ws_protocol_decoder_nexus_th_free(void* context);
|
||||
|
||||
/**
|
||||
* Reset decoder WSProtocolDecoderNexus_TH.
|
||||
* @param context Pointer to a WSProtocolDecoderNexus_TH instance
|
||||
*/
|
||||
void ws_protocol_decoder_nexus_th_reset(void* context);
|
||||
|
||||
/**
|
||||
* Parse a raw sequence of levels and durations received from the air.
|
||||
* @param context Pointer to a WSProtocolDecoderNexus_TH instance
|
||||
* @param level Signal level true-high false-low
|
||||
* @param duration Duration of this level in, us
|
||||
*/
|
||||
void ws_protocol_decoder_nexus_th_feed(void* context, bool level, uint32_t duration);
|
||||
|
||||
/**
|
||||
* Getting the hash sum of the last randomly received parcel.
|
||||
* @param context Pointer to a WSProtocolDecoderNexus_TH instance
|
||||
* @return hash Hash sum
|
||||
*/
|
||||
uint8_t ws_protocol_decoder_nexus_th_get_hash_data(void* context);
|
||||
|
||||
/**
|
||||
* Serialize data WSProtocolDecoderNexus_TH.
|
||||
* @param context Pointer to a WSProtocolDecoderNexus_TH 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_nexus_th_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset);
|
||||
|
||||
/**
|
||||
* Deserialize data WSProtocolDecoderNexus_TH.
|
||||
* @param context Pointer to a WSProtocolDecoderNexus_TH instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @return status
|
||||
*/
|
||||
SubGhzProtocolStatus
|
||||
ws_protocol_decoder_nexus_th_deserialize(void* context, FlipperFormat* flipper_format);
|
||||
|
||||
/**
|
||||
* Getting a textual representation of the received data.
|
||||
* @param context Pointer to a WSProtocolDecoderNexus_TH instance
|
||||
* @param output Resulting text
|
||||
*/
|
||||
void ws_protocol_decoder_nexus_th_get_string(void* context, FuriString* output);
|
429
applications/external/weather_station/protocols/oregon2.c
vendored
Normal file
429
applications/external/weather_station/protocols/oregon2.c
vendored
Normal file
@@ -0,0 +1,429 @@
|
||||
#include "oregon2.h"
|
||||
|
||||
#include <lib/subghz/blocks/const.h>
|
||||
#include <lib/subghz/blocks/decoder.h>
|
||||
#include <lib/subghz/blocks/encoder.h>
|
||||
#include <lib/subghz/blocks/math.h>
|
||||
#include "ws_generic.h"
|
||||
|
||||
#include <lib/toolbox/manchester_decoder.h>
|
||||
#include <lib/flipper_format/flipper_format_i.h>
|
||||
|
||||
#define TAG "WSProtocolOregon2"
|
||||
|
||||
static const SubGhzBlockConst ws_oregon2_const = {
|
||||
.te_long = 1000,
|
||||
.te_short = 500,
|
||||
.te_delta = 200,
|
||||
.min_count_bit_for_found = 32,
|
||||
};
|
||||
|
||||
#define OREGON2_PREAMBLE_BITS 19
|
||||
#define OREGON2_PREAMBLE_MASK 0b1111111111111111111
|
||||
#define OREGON2_SENSOR_ID(d) (((d) >> 16) & 0xFFFF)
|
||||
#define OREGON2_CHECKSUM_BITS 8
|
||||
|
||||
// 15 ones + 0101 (inverted A)
|
||||
#define OREGON2_PREAMBLE 0b1111111111111110101
|
||||
|
||||
// bit indicating the low battery
|
||||
#define OREGON2_FLAG_BAT_LOW 0x4
|
||||
|
||||
/// Documentation for Oregon Scientific protocols can be found here:
|
||||
/// http://wmrx00.sourceforge.net/Arduino/OregonScientific-RF-Protocols.pdf
|
||||
// Sensors ID
|
||||
#define ID_THGR122N 0x1d20
|
||||
#define ID_THGR968 0x1d30
|
||||
#define ID_BTHR918 0x5d50
|
||||
#define ID_BHTR968 0x5d60
|
||||
#define ID_RGR968 0x2d10
|
||||
#define ID_THR228N 0xec40
|
||||
#define ID_THN132N 0xec40 // same as THR228N but different packet size
|
||||
#define ID_RTGN318 0x0cc3 // warning: id is from 0x0cc3 and 0xfcc3
|
||||
#define ID_RTGN129 0x0cc3 // same as RTGN318 but different packet size
|
||||
#define ID_THGR810 0xf824 // This might be ID_THGR81, but what's true is lost in (git) history
|
||||
#define ID_THGR810a 0xf8b4 // unconfirmed version
|
||||
#define ID_THN802 0xc844
|
||||
#define ID_PCR800 0x2914
|
||||
#define ID_PCR800a 0x2d14 // Different PCR800 ID - AU version I think
|
||||
#define ID_WGR800 0x1984
|
||||
#define ID_WGR800a 0x1994 // unconfirmed version
|
||||
#define ID_WGR968 0x3d00
|
||||
#define ID_UV800 0xd874
|
||||
#define ID_THN129 0xcc43 // THN129 Temp only
|
||||
#define ID_RTHN129 0x0cd3 // RTHN129 Temp, clock sensors
|
||||
#define ID_RTHN129_1 0x9cd3
|
||||
#define ID_RTHN129_2 0xacd3
|
||||
#define ID_RTHN129_3 0xbcd3
|
||||
#define ID_RTHN129_4 0xccd3
|
||||
#define ID_RTHN129_5 0xdcd3
|
||||
#define ID_BTHGN129 0x5d53 // Baro, Temp, Hygro sensor
|
||||
#define ID_UVR128 0xec70
|
||||
#define ID_THGR328N 0xcc23 // Temp & Hygro sensor similar to THR228N with 5 channel instead of 3
|
||||
#define ID_RTGR328N_1 0xdcc3 // RTGR328N_[1-5] RFclock(date &time)&Temp&Hygro sensor
|
||||
#define ID_RTGR328N_2 0xccc3
|
||||
#define ID_RTGR328N_3 0xbcc3
|
||||
#define ID_RTGR328N_4 0xacc3
|
||||
#define ID_RTGR328N_5 0x9cc3
|
||||
#define ID_RTGR328N_6 0x8ce3 // RTGR328N_6&7 RFclock(date &time)&Temp&Hygro sensor like THGR328N
|
||||
#define ID_RTGR328N_7 0x8ae3
|
||||
|
||||
struct WSProtocolDecoderOregon2 {
|
||||
SubGhzProtocolDecoderBase base;
|
||||
|
||||
SubGhzBlockDecoder decoder;
|
||||
WSBlockGeneric generic;
|
||||
ManchesterState manchester_state;
|
||||
bool prev_bit;
|
||||
bool have_bit;
|
||||
|
||||
uint8_t var_bits;
|
||||
uint32_t var_data;
|
||||
};
|
||||
|
||||
typedef struct WSProtocolDecoderOregon2 WSProtocolDecoderOregon2;
|
||||
|
||||
typedef enum {
|
||||
Oregon2DecoderStepReset = 0,
|
||||
Oregon2DecoderStepFoundPreamble,
|
||||
Oregon2DecoderStepVarData,
|
||||
} Oregon2DecoderStep;
|
||||
|
||||
void* ws_protocol_decoder_oregon2_alloc(SubGhzEnvironment* environment) {
|
||||
UNUSED(environment);
|
||||
WSProtocolDecoderOregon2* instance = malloc(sizeof(WSProtocolDecoderOregon2));
|
||||
instance->base.protocol = &ws_protocol_oregon2;
|
||||
instance->generic.protocol_name = instance->base.protocol->name;
|
||||
instance->generic.humidity = WS_NO_HUMIDITY;
|
||||
instance->generic.temp = WS_NO_TEMPERATURE;
|
||||
instance->generic.btn = WS_NO_BTN;
|
||||
instance->generic.channel = WS_NO_CHANNEL;
|
||||
instance->generic.battery_low = WS_NO_BATT;
|
||||
instance->generic.id = WS_NO_ID;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_oregon2_free(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderOregon2* instance = context;
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_oregon2_reset(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderOregon2* instance = context;
|
||||
instance->decoder.parser_step = Oregon2DecoderStepReset;
|
||||
instance->decoder.decode_data = 0UL;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
manchester_advance(
|
||||
instance->manchester_state, ManchesterEventReset, &instance->manchester_state, NULL);
|
||||
instance->have_bit = false;
|
||||
instance->var_data = 0;
|
||||
instance->var_bits = 0;
|
||||
}
|
||||
|
||||
static ManchesterEvent level_and_duration_to_event(bool level, uint32_t duration) {
|
||||
bool is_long = false;
|
||||
|
||||
if(DURATION_DIFF(duration, ws_oregon2_const.te_long) < ws_oregon2_const.te_delta) {
|
||||
is_long = true;
|
||||
} else if(DURATION_DIFF(duration, ws_oregon2_const.te_short) < ws_oregon2_const.te_delta) {
|
||||
is_long = false;
|
||||
} else {
|
||||
return ManchesterEventReset;
|
||||
}
|
||||
|
||||
if(level)
|
||||
return is_long ? ManchesterEventLongHigh : ManchesterEventShortHigh;
|
||||
else
|
||||
return is_long ? ManchesterEventLongLow : ManchesterEventShortLow;
|
||||
}
|
||||
|
||||
// From sensor id code return amount of bits in variable section
|
||||
// https://temofeev.ru/info/articles/o-dekodirovanii-protokola-pogodnykh-datchikov-oregon-scientific
|
||||
static uint8_t oregon2_sensor_id_var_bits(uint16_t sensor_id) {
|
||||
switch(sensor_id) {
|
||||
case ID_THR228N:
|
||||
case ID_RTHN129_1:
|
||||
case ID_RTHN129_2:
|
||||
case ID_RTHN129_3:
|
||||
case ID_RTHN129_4:
|
||||
case ID_RTHN129_5:
|
||||
return 16;
|
||||
case ID_THGR122N:
|
||||
return 24;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void ws_oregon2_decode_const_data(WSBlockGeneric* ws_block) {
|
||||
ws_block->id = OREGON2_SENSOR_ID(ws_block->data);
|
||||
|
||||
uint8_t ch_bits = (ws_block->data >> 12) & 0xF;
|
||||
ws_block->channel = 1;
|
||||
while(ch_bits > 1) {
|
||||
ws_block->channel++;
|
||||
ch_bits >>= 1;
|
||||
}
|
||||
|
||||
ws_block->battery_low = (ws_block->data & OREGON2_FLAG_BAT_LOW) ? 1 : 0;
|
||||
}
|
||||
|
||||
uint16_t bcd_decode_short(uint32_t data) {
|
||||
return (data & 0xF) * 10 + ((data >> 4) & 0xF);
|
||||
}
|
||||
|
||||
static float ws_oregon2_decode_temp(uint32_t data) {
|
||||
int32_t temp_val;
|
||||
temp_val = bcd_decode_short(data >> 4);
|
||||
temp_val *= 10;
|
||||
temp_val += (data >> 12) & 0xF;
|
||||
if(data & 0xF) temp_val = -temp_val;
|
||||
return (float)temp_val / 10.0;
|
||||
}
|
||||
|
||||
static void ws_oregon2_decode_var_data(WSBlockGeneric* ws_b, uint16_t sensor_id, uint32_t data) {
|
||||
switch(sensor_id) {
|
||||
case ID_THR228N:
|
||||
case ID_RTHN129_1:
|
||||
case ID_RTHN129_2:
|
||||
case ID_RTHN129_3:
|
||||
case ID_RTHN129_4:
|
||||
case ID_RTHN129_5:
|
||||
ws_b->temp = ws_oregon2_decode_temp(data);
|
||||
ws_b->humidity = WS_NO_HUMIDITY;
|
||||
return;
|
||||
case ID_THGR122N:
|
||||
ws_b->humidity = bcd_decode_short(data);
|
||||
ws_b->temp = ws_oregon2_decode_temp(data >> 8);
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_oregon2_feed(void* context, bool level, uint32_t duration) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderOregon2* instance = context;
|
||||
// oregon v2.1 signal is inverted
|
||||
ManchesterEvent event = level_and_duration_to_event(!level, duration);
|
||||
bool data;
|
||||
|
||||
// low-level bit sequence decoding
|
||||
if(event == ManchesterEventReset) {
|
||||
instance->decoder.parser_step = Oregon2DecoderStepReset;
|
||||
instance->have_bit = false;
|
||||
instance->decoder.decode_data = 0UL;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
}
|
||||
if(manchester_advance(instance->manchester_state, event, &instance->manchester_state, &data)) {
|
||||
if(instance->have_bit) {
|
||||
if(!instance->prev_bit && data) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
||||
} else if(instance->prev_bit && !data) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
||||
} else {
|
||||
ws_protocol_decoder_oregon2_reset(context);
|
||||
}
|
||||
instance->have_bit = false;
|
||||
} else {
|
||||
instance->prev_bit = data;
|
||||
instance->have_bit = true;
|
||||
}
|
||||
}
|
||||
|
||||
switch(instance->decoder.parser_step) {
|
||||
case Oregon2DecoderStepReset:
|
||||
// waiting for fixed oregon2 preamble
|
||||
if(instance->decoder.decode_count_bit >= OREGON2_PREAMBLE_BITS &&
|
||||
((instance->decoder.decode_data & OREGON2_PREAMBLE_MASK) == OREGON2_PREAMBLE)) {
|
||||
instance->decoder.parser_step = Oregon2DecoderStepFoundPreamble;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
instance->decoder.decode_data = 0UL;
|
||||
}
|
||||
break;
|
||||
case Oregon2DecoderStepFoundPreamble:
|
||||
// waiting for fixed oregon2 data
|
||||
if(instance->decoder.decode_count_bit == 32) {
|
||||
instance->generic.data = instance->decoder.decode_data;
|
||||
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
|
||||
instance->decoder.decode_data = 0UL;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
|
||||
// reverse nibbles in decoded data
|
||||
instance->generic.data = (instance->generic.data & 0x55555555) << 1 |
|
||||
(instance->generic.data & 0xAAAAAAAA) >> 1;
|
||||
instance->generic.data = (instance->generic.data & 0x33333333) << 2 |
|
||||
(instance->generic.data & 0xCCCCCCCC) >> 2;
|
||||
|
||||
ws_oregon2_decode_const_data(&instance->generic);
|
||||
instance->var_bits =
|
||||
oregon2_sensor_id_var_bits(OREGON2_SENSOR_ID(instance->generic.data));
|
||||
|
||||
if(!instance->var_bits) {
|
||||
// sensor is not supported, stop decoding, but showing the decoded fixed part
|
||||
instance->decoder.parser_step = Oregon2DecoderStepReset;
|
||||
if(instance->base.callback)
|
||||
instance->base.callback(&instance->base, instance->base.context);
|
||||
} else {
|
||||
instance->decoder.parser_step = Oregon2DecoderStepVarData;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Oregon2DecoderStepVarData:
|
||||
// waiting for variable (sensor-specific data)
|
||||
if(instance->decoder.decode_count_bit == instance->var_bits + OREGON2_CHECKSUM_BITS) {
|
||||
instance->var_data = instance->decoder.decode_data & 0xFFFFFFFF;
|
||||
|
||||
// reverse nibbles in var data
|
||||
instance->var_data = (instance->var_data & 0x55555555) << 1 |
|
||||
(instance->var_data & 0xAAAAAAAA) >> 1;
|
||||
instance->var_data = (instance->var_data & 0x33333333) << 2 |
|
||||
(instance->var_data & 0xCCCCCCCC) >> 2;
|
||||
|
||||
ws_oregon2_decode_var_data(
|
||||
&instance->generic,
|
||||
OREGON2_SENSOR_ID(instance->generic.data),
|
||||
instance->var_data >> OREGON2_CHECKSUM_BITS);
|
||||
|
||||
instance->decoder.parser_step = Oregon2DecoderStepReset;
|
||||
if(instance->base.callback)
|
||||
instance->base.callback(&instance->base, instance->base.context);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t ws_protocol_decoder_oregon2_get_hash_data(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderOregon2* instance = context;
|
||||
return subghz_protocol_blocks_get_hash_data(
|
||||
&instance->decoder, (instance->decoder.decode_count_bit / 8) + 1);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus ws_protocol_decoder_oregon2_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderOregon2* instance = context;
|
||||
SubGhzProtocolStatus ret = SubGhzProtocolStatusError;
|
||||
ret = ws_block_generic_serialize(&instance->generic, flipper_format, preset);
|
||||
if(ret != SubGhzProtocolStatusOk) return ret;
|
||||
uint32_t temp = instance->var_bits;
|
||||
if(!flipper_format_write_uint32(flipper_format, "VarBits", &temp, 1)) {
|
||||
FURI_LOG_E(TAG, "Error adding VarBits");
|
||||
return SubGhzProtocolStatusErrorParserOthers;
|
||||
}
|
||||
if(!flipper_format_write_hex(
|
||||
flipper_format,
|
||||
"VarData",
|
||||
(const uint8_t*)&instance->var_data,
|
||||
sizeof(instance->var_data))) {
|
||||
FURI_LOG_E(TAG, "Error adding VarData");
|
||||
return SubGhzProtocolStatusErrorParserOthers;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus
|
||||
ws_protocol_decoder_oregon2_deserialize(void* context, FlipperFormat* flipper_format) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderOregon2* instance = context;
|
||||
uint32_t temp_data;
|
||||
SubGhzProtocolStatus ret = SubGhzProtocolStatusError;
|
||||
do {
|
||||
ret = ws_block_generic_deserialize(&instance->generic, flipper_format);
|
||||
if(ret != SubGhzProtocolStatusOk) {
|
||||
break;
|
||||
}
|
||||
if(!flipper_format_read_uint32(flipper_format, "VarBits", &temp_data, 1)) {
|
||||
FURI_LOG_E(TAG, "Missing VarLen");
|
||||
ret = SubGhzProtocolStatusErrorParserOthers;
|
||||
break;
|
||||
}
|
||||
instance->var_bits = (uint8_t)temp_data;
|
||||
if(!flipper_format_read_hex(
|
||||
flipper_format,
|
||||
"VarData",
|
||||
(uint8_t*)&instance->var_data,
|
||||
sizeof(instance->var_data))) { //-V1051
|
||||
FURI_LOG_E(TAG, "Missing VarData");
|
||||
ret = SubGhzProtocolStatusErrorParserOthers;
|
||||
break;
|
||||
}
|
||||
if(instance->generic.data_count_bit != ws_oregon2_const.min_count_bit_for_found) {
|
||||
FURI_LOG_E(TAG, "Wrong number of bits in key: %d", instance->generic.data_count_bit);
|
||||
ret = SubGhzProtocolStatusErrorValueBitCount;
|
||||
break;
|
||||
}
|
||||
} while(false);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void oregon2_append_check_sum(uint32_t fix_data, uint32_t var_data, FuriString* output) {
|
||||
uint8_t sum = fix_data & 0xF;
|
||||
uint8_t ref_sum = var_data & 0xFF;
|
||||
var_data >>= 8;
|
||||
|
||||
for(uint8_t i = 1; i < 8; i++) {
|
||||
fix_data >>= 4;
|
||||
var_data >>= 4;
|
||||
sum += (fix_data & 0xF) + (var_data & 0xF);
|
||||
}
|
||||
|
||||
// swap calculated sum nibbles
|
||||
sum = (((sum >> 4) & 0xF) | (sum << 4)) & 0xFF;
|
||||
if(sum == ref_sum)
|
||||
furi_string_cat_printf(output, "Sum ok: 0x%hhX", ref_sum);
|
||||
else
|
||||
furi_string_cat_printf(output, "Sum err: 0x%hhX vs 0x%hhX", ref_sum, sum);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_oregon2_get_string(void* context, FuriString* output) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderOregon2* instance = context;
|
||||
furi_string_cat_printf(
|
||||
output,
|
||||
"%s\r\n"
|
||||
"ID: 0x%04lX, ch: %d, bat: %d, rc: 0x%02lX\r\n",
|
||||
instance->generic.protocol_name,
|
||||
instance->generic.id,
|
||||
instance->generic.channel,
|
||||
instance->generic.battery_low,
|
||||
(uint32_t)(instance->generic.data >> 4) & 0xFF);
|
||||
|
||||
if(instance->var_bits > 0) {
|
||||
furi_string_cat_printf(
|
||||
output,
|
||||
"Temp:%d.%d C Hum:%d%%",
|
||||
(int16_t)instance->generic.temp,
|
||||
abs(
|
||||
((int16_t)(instance->generic.temp * 10) -
|
||||
(((int16_t)instance->generic.temp) * 10))),
|
||||
instance->generic.humidity);
|
||||
oregon2_append_check_sum((uint32_t)instance->generic.data, instance->var_data, output);
|
||||
}
|
||||
}
|
||||
|
||||
const SubGhzProtocolDecoder ws_protocol_oregon2_decoder = {
|
||||
.alloc = ws_protocol_decoder_oregon2_alloc,
|
||||
.free = ws_protocol_decoder_oregon2_free,
|
||||
|
||||
.feed = ws_protocol_decoder_oregon2_feed,
|
||||
.reset = ws_protocol_decoder_oregon2_reset,
|
||||
|
||||
.get_hash_data = ws_protocol_decoder_oregon2_get_hash_data,
|
||||
.serialize = ws_protocol_decoder_oregon2_serialize,
|
||||
.deserialize = ws_protocol_decoder_oregon2_deserialize,
|
||||
.get_string = ws_protocol_decoder_oregon2_get_string,
|
||||
};
|
||||
|
||||
const SubGhzProtocol ws_protocol_oregon2 = {
|
||||
.name = WS_PROTOCOL_OREGON2_NAME,
|
||||
.type = SubGhzProtocolWeatherStation,
|
||||
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable,
|
||||
|
||||
.decoder = &ws_protocol_oregon2_decoder,
|
||||
};
|
6
applications/external/weather_station/protocols/oregon2.h
vendored
Normal file
6
applications/external/weather_station/protocols/oregon2.h
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <lib/subghz/protocols/base.h>
|
||||
|
||||
#define WS_PROTOCOL_OREGON2_NAME "Oregon2"
|
||||
extern const SubGhzProtocol ws_protocol_oregon2;
|
321
applications/external/weather_station/protocols/oregon_v1.c
vendored
Normal file
321
applications/external/weather_station/protocols/oregon_v1.c
vendored
Normal file
@@ -0,0 +1,321 @@
|
||||
#include "oregon_v1.h"
|
||||
#include <lib/toolbox/manchester_decoder.h>
|
||||
|
||||
#define TAG "WSProtocolOregon_V1"
|
||||
|
||||
/*
|
||||
* Help
|
||||
* https://github.dev/merbanan/rtl_433/blob/bb1be7f186ac0fdb7dc5d77693847d96fb95281e/src/devices/oregon_scientific_v1.c
|
||||
*
|
||||
* OSv1 protocol.
|
||||
*
|
||||
* MC with nominal bit width of 2930 us.
|
||||
* Pulses are somewhat longer than nominal half-bit width, 1748 us / 3216 us,
|
||||
* Gaps are somewhat shorter than nominal half-bit width, 1176 us / 2640 us.
|
||||
* After 12 preamble bits there is 4200 us gap, 5780 us pulse, 5200 us gap.
|
||||
* And next 32 bit data
|
||||
*
|
||||
* Care must be taken with the gap after the sync pulse since it
|
||||
* is outside of the normal clocking. Because of this a data stream
|
||||
* beginning with a 0 will have data in this gap.
|
||||
*
|
||||
*
|
||||
* Data is in reverse order of bits
|
||||
* RevBit(data32bit)=> tib23atad
|
||||
*
|
||||
* tib23atad => xxxxxxxx | busuTTTT | ttttzzzz | ccuuiiii
|
||||
*
|
||||
* - i: ID
|
||||
* - x: CRC;
|
||||
* - u: unknown;
|
||||
* - b: battery low; flag to indicate low battery voltage
|
||||
* - s: temperature sign
|
||||
* - T: BCD, Temperature; in <20>C * 10
|
||||
* - t: BCD, Temperature; in <20>C * 1
|
||||
* - z: BCD, Temperature; in <20>C * 0.1
|
||||
* - c: Channel 00=CH1, 01=CH2, 10=CH3
|
||||
*
|
||||
*/
|
||||
|
||||
#define OREGON_V1_HEADER_OK 0xFF
|
||||
|
||||
static const SubGhzBlockConst ws_protocol_oregon_v1_const = {
|
||||
.te_short = 1465,
|
||||
.te_long = 2930,
|
||||
.te_delta = 350,
|
||||
.min_count_bit_for_found = 32,
|
||||
};
|
||||
|
||||
struct WSProtocolDecoderOregon_V1 {
|
||||
SubGhzProtocolDecoderBase base;
|
||||
|
||||
SubGhzBlockDecoder decoder;
|
||||
WSBlockGeneric generic;
|
||||
ManchesterState manchester_state;
|
||||
uint16_t header_count;
|
||||
uint8_t first_bit;
|
||||
};
|
||||
|
||||
struct WSProtocolEncoderOregon_V1 {
|
||||
SubGhzProtocolEncoderBase base;
|
||||
|
||||
SubGhzProtocolBlockEncoder encoder;
|
||||
WSBlockGeneric generic;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
Oregon_V1DecoderStepReset = 0,
|
||||
Oregon_V1DecoderStepFoundPreamble,
|
||||
Oregon_V1DecoderStepParse,
|
||||
} Oregon_V1DecoderStep;
|
||||
|
||||
const SubGhzProtocolDecoder ws_protocol_oregon_v1_decoder = {
|
||||
.alloc = ws_protocol_decoder_oregon_v1_alloc,
|
||||
.free = ws_protocol_decoder_oregon_v1_free,
|
||||
|
||||
.feed = ws_protocol_decoder_oregon_v1_feed,
|
||||
.reset = ws_protocol_decoder_oregon_v1_reset,
|
||||
|
||||
.get_hash_data = ws_protocol_decoder_oregon_v1_get_hash_data,
|
||||
.serialize = ws_protocol_decoder_oregon_v1_serialize,
|
||||
.deserialize = ws_protocol_decoder_oregon_v1_deserialize,
|
||||
.get_string = ws_protocol_decoder_oregon_v1_get_string,
|
||||
};
|
||||
|
||||
const SubGhzProtocolEncoder ws_protocol_oregon_v1_encoder = {
|
||||
.alloc = NULL,
|
||||
.free = NULL,
|
||||
|
||||
.deserialize = NULL,
|
||||
.stop = NULL,
|
||||
.yield = NULL,
|
||||
};
|
||||
|
||||
const SubGhzProtocol ws_protocol_oregon_v1 = {
|
||||
.name = WS_PROTOCOL_OREGON_V1_NAME,
|
||||
.type = SubGhzProtocolWeatherStation,
|
||||
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_315 | SubGhzProtocolFlag_868 |
|
||||
SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable,
|
||||
|
||||
.decoder = &ws_protocol_oregon_v1_decoder,
|
||||
.encoder = &ws_protocol_oregon_v1_encoder,
|
||||
};
|
||||
|
||||
void* ws_protocol_decoder_oregon_v1_alloc(SubGhzEnvironment* environment) {
|
||||
UNUSED(environment);
|
||||
WSProtocolDecoderOregon_V1* instance = malloc(sizeof(WSProtocolDecoderOregon_V1));
|
||||
instance->base.protocol = &ws_protocol_oregon_v1;
|
||||
instance->generic.protocol_name = instance->base.protocol->name;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_oregon_v1_free(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderOregon_V1* instance = context;
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_oregon_v1_reset(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderOregon_V1* instance = context;
|
||||
instance->decoder.parser_step = Oregon_V1DecoderStepReset;
|
||||
}
|
||||
|
||||
static bool ws_protocol_oregon_v1_check(WSProtocolDecoderOregon_V1* instance) {
|
||||
if(!instance->decoder.decode_data) return false;
|
||||
uint64_t data = subghz_protocol_blocks_reverse_key(instance->decoder.decode_data, 32);
|
||||
uint16_t crc = (data & 0xff) + ((data >> 8) & 0xff) + ((data >> 16) & 0xff);
|
||||
crc = (crc & 0xff) + ((crc >> 8) & 0xff);
|
||||
return (crc == ((data >> 24) & 0xFF));
|
||||
}
|
||||
|
||||
/**
|
||||
* Analysis of received data
|
||||
* @param instance Pointer to a WSBlockGeneric* instance
|
||||
*/
|
||||
static void ws_protocol_oregon_v1_remote_controller(WSBlockGeneric* instance) {
|
||||
uint64_t data = subghz_protocol_blocks_reverse_key(instance->data, 32);
|
||||
|
||||
instance->id = data & 0xFF;
|
||||
instance->channel = ((data >> 6) & 0x03) + 1;
|
||||
|
||||
float temp_raw =
|
||||
((data >> 8) & 0x0F) * 0.1f + ((data >> 12) & 0x0F) + ((data >> 16) & 0x0F) * 10.0f;
|
||||
if(!((data >> 21) & 1)) {
|
||||
instance->temp = temp_raw;
|
||||
} else {
|
||||
instance->temp = -temp_raw;
|
||||
}
|
||||
|
||||
instance->battery_low = !((instance->data >> 23) & 1ULL);
|
||||
|
||||
instance->btn = WS_NO_BTN;
|
||||
instance->humidity = WS_NO_HUMIDITY;
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_oregon_v1_feed(void* context, bool level, uint32_t duration) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderOregon_V1* instance = context;
|
||||
ManchesterEvent event = ManchesterEventReset;
|
||||
switch(instance->decoder.parser_step) {
|
||||
case Oregon_V1DecoderStepReset:
|
||||
if((level) && (DURATION_DIFF(duration, ws_protocol_oregon_v1_const.te_short) <
|
||||
ws_protocol_oregon_v1_const.te_delta)) {
|
||||
instance->decoder.parser_step = Oregon_V1DecoderStepFoundPreamble;
|
||||
instance->decoder.te_last = duration;
|
||||
instance->header_count = 0;
|
||||
}
|
||||
break;
|
||||
case Oregon_V1DecoderStepFoundPreamble:
|
||||
if(level) {
|
||||
//keep high levels, if they suit our durations
|
||||
if((DURATION_DIFF(duration, ws_protocol_oregon_v1_const.te_short) <
|
||||
ws_protocol_oregon_v1_const.te_delta) ||
|
||||
(DURATION_DIFF(duration, ws_protocol_oregon_v1_const.te_short * 4) <
|
||||
ws_protocol_oregon_v1_const.te_delta)) {
|
||||
instance->decoder.te_last = duration;
|
||||
} else {
|
||||
instance->decoder.parser_step = Oregon_V1DecoderStepReset;
|
||||
}
|
||||
} else if(
|
||||
//checking low levels
|
||||
(DURATION_DIFF(duration, ws_protocol_oregon_v1_const.te_short) <
|
||||
ws_protocol_oregon_v1_const.te_delta) &&
|
||||
(DURATION_DIFF(instance->decoder.te_last, ws_protocol_oregon_v1_const.te_short) <
|
||||
ws_protocol_oregon_v1_const.te_delta)) {
|
||||
// Found header
|
||||
instance->header_count++;
|
||||
} else if(
|
||||
(DURATION_DIFF(duration, ws_protocol_oregon_v1_const.te_short * 3) <
|
||||
ws_protocol_oregon_v1_const.te_delta) &&
|
||||
(DURATION_DIFF(instance->decoder.te_last, ws_protocol_oregon_v1_const.te_short) <
|
||||
ws_protocol_oregon_v1_const.te_delta)) {
|
||||
// check header
|
||||
if(instance->header_count > 7) {
|
||||
instance->header_count = OREGON_V1_HEADER_OK;
|
||||
}
|
||||
} else if(
|
||||
(instance->header_count == OREGON_V1_HEADER_OK) &&
|
||||
(DURATION_DIFF(instance->decoder.te_last, ws_protocol_oregon_v1_const.te_short * 4) <
|
||||
ws_protocol_oregon_v1_const.te_delta)) {
|
||||
//found all the necessary patterns
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 1;
|
||||
manchester_advance(
|
||||
instance->manchester_state,
|
||||
ManchesterEventReset,
|
||||
&instance->manchester_state,
|
||||
NULL);
|
||||
instance->decoder.parser_step = Oregon_V1DecoderStepParse;
|
||||
if(duration < ws_protocol_oregon_v1_const.te_short * 4) {
|
||||
instance->first_bit = 1;
|
||||
} else {
|
||||
instance->first_bit = 0;
|
||||
}
|
||||
} else {
|
||||
instance->decoder.parser_step = Oregon_V1DecoderStepReset;
|
||||
}
|
||||
break;
|
||||
case Oregon_V1DecoderStepParse:
|
||||
if(level) {
|
||||
if(DURATION_DIFF(duration, ws_protocol_oregon_v1_const.te_short) <
|
||||
ws_protocol_oregon_v1_const.te_delta) {
|
||||
event = ManchesterEventShortHigh;
|
||||
} else if(
|
||||
DURATION_DIFF(duration, ws_protocol_oregon_v1_const.te_long) <
|
||||
ws_protocol_oregon_v1_const.te_delta) {
|
||||
event = ManchesterEventLongHigh;
|
||||
} else {
|
||||
instance->decoder.parser_step = Oregon_V1DecoderStepReset;
|
||||
}
|
||||
} else {
|
||||
if(DURATION_DIFF(duration, ws_protocol_oregon_v1_const.te_short) <
|
||||
ws_protocol_oregon_v1_const.te_delta) {
|
||||
event = ManchesterEventShortLow;
|
||||
} else if(
|
||||
DURATION_DIFF(duration, ws_protocol_oregon_v1_const.te_long) <
|
||||
ws_protocol_oregon_v1_const.te_delta) {
|
||||
event = ManchesterEventLongLow;
|
||||
} else if(duration >= ((uint32_t)ws_protocol_oregon_v1_const.te_long * 2)) {
|
||||
if(instance->decoder.decode_count_bit ==
|
||||
ws_protocol_oregon_v1_const.min_count_bit_for_found) {
|
||||
if(instance->first_bit) {
|
||||
instance->decoder.decode_data = ~instance->decoder.decode_data | (1 << 31);
|
||||
}
|
||||
if(ws_protocol_oregon_v1_check(instance)) {
|
||||
instance->generic.data = instance->decoder.decode_data;
|
||||
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
|
||||
ws_protocol_oregon_v1_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;
|
||||
manchester_advance(
|
||||
instance->manchester_state,
|
||||
ManchesterEventReset,
|
||||
&instance->manchester_state,
|
||||
NULL);
|
||||
} else {
|
||||
instance->decoder.parser_step = Oregon_V1DecoderStepReset;
|
||||
}
|
||||
}
|
||||
if(event != ManchesterEventReset) {
|
||||
bool data;
|
||||
bool data_ok = manchester_advance(
|
||||
instance->manchester_state, event, &instance->manchester_state, &data);
|
||||
|
||||
if(data_ok) {
|
||||
instance->decoder.decode_data = (instance->decoder.decode_data << 1) | !data;
|
||||
instance->decoder.decode_count_bit++;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t ws_protocol_decoder_oregon_v1_get_hash_data(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderOregon_V1* instance = context;
|
||||
return subghz_protocol_blocks_get_hash_data(
|
||||
&instance->decoder, (instance->decoder.decode_count_bit / 8) + 1);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus ws_protocol_decoder_oregon_v1_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderOregon_V1* instance = context;
|
||||
return ws_block_generic_serialize(&instance->generic, flipper_format, preset);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus
|
||||
ws_protocol_decoder_oregon_v1_deserialize(void* context, FlipperFormat* flipper_format) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderOregon_V1* instance = context;
|
||||
return ws_block_generic_deserialize_check_count_bit(
|
||||
&instance->generic, flipper_format, ws_protocol_oregon_v1_const.min_count_bit_for_found);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_oregon_v1_get_string(void* context, FuriString* output) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderOregon_V1* instance = context;
|
||||
furi_string_printf(
|
||||
output,
|
||||
"%s %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
applications/external/weather_station/protocols/oregon_v1.h
vendored
Normal file
80
applications/external/weather_station/protocols/oregon_v1.h
vendored
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_OREGON_V1_NAME "Oregon-v1"
|
||||
|
||||
typedef struct WSProtocolDecoderOregon_V1 WSProtocolDecoderOregon_V1;
|
||||
typedef struct WSProtocolEncoderOregon_V1 WSProtocolEncoderOregon_V1;
|
||||
|
||||
extern const SubGhzProtocolDecoder ws_protocol_oregon_v1_decoder;
|
||||
extern const SubGhzProtocolEncoder ws_protocol_oregon_v1_encoder;
|
||||
extern const SubGhzProtocol ws_protocol_oregon_v1;
|
||||
|
||||
/**
|
||||
* Allocate WSProtocolDecoderOregon_V1.
|
||||
* @param environment Pointer to a SubGhzEnvironment instance
|
||||
* @return WSProtocolDecoderOregon_V1* pointer to a WSProtocolDecoderOregon_V1 instance
|
||||
*/
|
||||
void* ws_protocol_decoder_oregon_v1_alloc(SubGhzEnvironment* environment);
|
||||
|
||||
/**
|
||||
* Free WSProtocolDecoderOregon_V1.
|
||||
* @param context Pointer to a WSProtocolDecoderOregon_V1 instance
|
||||
*/
|
||||
void ws_protocol_decoder_oregon_v1_free(void* context);
|
||||
|
||||
/**
|
||||
* Reset decoder WSProtocolDecoderOregon_V1.
|
||||
* @param context Pointer to a WSProtocolDecoderOregon_V1 instance
|
||||
*/
|
||||
void ws_protocol_decoder_oregon_v1_reset(void* context);
|
||||
|
||||
/**
|
||||
* Parse a raw sequence of levels and durations received from the air.
|
||||
* @param context Pointer to a WSProtocolDecoderOregon_V1 instance
|
||||
* @param level Signal level true-high false-low
|
||||
* @param duration Duration of this level in, us
|
||||
*/
|
||||
void ws_protocol_decoder_oregon_v1_feed(void* context, bool level, uint32_t duration);
|
||||
|
||||
/**
|
||||
* Getting the hash sum of the last randomly received parcel.
|
||||
* @param context Pointer to a WSProtocolDecoderOregon_V1 instance
|
||||
* @return hash Hash sum
|
||||
*/
|
||||
uint8_t ws_protocol_decoder_oregon_v1_get_hash_data(void* context);
|
||||
|
||||
/**
|
||||
* Serialize data WSProtocolDecoderOregon_V1.
|
||||
* @param context Pointer to a WSProtocolDecoderOregon_V1 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_oregon_v1_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset);
|
||||
|
||||
/**
|
||||
* Deserialize data WSProtocolDecoderOregon_V1.
|
||||
* @param context Pointer to a WSProtocolDecoderOregon_V1 instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @return status
|
||||
*/
|
||||
SubGhzProtocolStatus
|
||||
ws_protocol_decoder_oregon_v1_deserialize(void* context, FlipperFormat* flipper_format);
|
||||
|
||||
/**
|
||||
* Getting a textual representation of the received data.
|
||||
* @param context Pointer to a WSProtocolDecoderOregon_V1 instance
|
||||
* @param output Resulting text
|
||||
*/
|
||||
void ws_protocol_decoder_oregon_v1_get_string(void* context, FuriString* output);
|
23
applications/external/weather_station/protocols/protocol_items.c
vendored
Normal file
23
applications/external/weather_station/protocols/protocol_items.c
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
#include "protocol_items.h"
|
||||
|
||||
const SubGhzProtocol* weather_station_protocol_registry_items[] = {
|
||||
&ws_protocol_infactory,
|
||||
&ws_protocol_thermopro_tx4,
|
||||
&ws_protocol_nexus_th,
|
||||
&ws_protocol_gt_wt_02,
|
||||
&ws_protocol_gt_wt_03,
|
||||
&ws_protocol_acurite_606tx,
|
||||
&ws_protocol_acurite_609txc,
|
||||
&ws_protocol_lacrosse_tx,
|
||||
&ws_protocol_lacrosse_tx141thbv2,
|
||||
&ws_protocol_oregon2,
|
||||
&ws_protocol_acurite_592txr,
|
||||
&ws_protocol_ambient_weather,
|
||||
&ws_protocol_auriol_th,
|
||||
&ws_protocol_oregon_v1,
|
||||
&ws_protocol_tx_8300,
|
||||
};
|
||||
|
||||
const SubGhzProtocolRegistry weather_station_protocol_registry = {
|
||||
.items = weather_station_protocol_registry_items,
|
||||
.size = COUNT_OF(weather_station_protocol_registry_items)};
|
20
applications/external/weather_station/protocols/protocol_items.h
vendored
Normal file
20
applications/external/weather_station/protocols/protocol_items.h
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include "../weather_station_app_i.h"
|
||||
|
||||
#include "infactory.h"
|
||||
#include "thermopro_tx4.h"
|
||||
#include "nexus_th.h"
|
||||
#include "gt_wt_02.h"
|
||||
#include "gt_wt_03.h"
|
||||
#include "acurite_606tx.h"
|
||||
#include "acurite_609txc.h"
|
||||
#include "lacrosse_tx.h"
|
||||
#include "lacrosse_tx141thbv2.h"
|
||||
#include "oregon2.h"
|
||||
#include "acurite_592txr.h"
|
||||
#include "ambient_weather.h"
|
||||
#include "auriol_hg0601a.h"
|
||||
#include "oregon_v1.h"
|
||||
#include "tx_8300.h"
|
||||
|
||||
extern const SubGhzProtocolRegistry weather_station_protocol_registry;
|
251
applications/external/weather_station/protocols/thermopro_tx4.c
vendored
Normal file
251
applications/external/weather_station/protocols/thermopro_tx4.c
vendored
Normal file
@@ -0,0 +1,251 @@
|
||||
#include "thermopro_tx4.h"
|
||||
|
||||
#define TAG "WSProtocolThermoPRO_TX4"
|
||||
|
||||
/*
|
||||
* Help
|
||||
* https://github.com/merbanan/rtl_433/blob/master/src/devices/thermopro_tx2.c
|
||||
*
|
||||
* The sensor sends 37 bits 6 times, before the first packet there is a sync pulse.
|
||||
* The packets are ppm modulated (distance coding) with a pulse of ~500 us
|
||||
* followed by a short gap of ~2000 us for a 0 bit or a long ~4000 us gap for a
|
||||
* 1 bit, the sync gap is ~9000 us.
|
||||
* The data is grouped in 9 nibbles
|
||||
* [type] [id0] [id1] [flags] [temp0] [temp1] [temp2] [humi0] [humi1]
|
||||
* - type: 4 bit fixed 1001 (9) or 0110 (5)
|
||||
* - id: 8 bit a random id that is generated when the sensor starts, could include battery status
|
||||
* the same batteries often generate the same id
|
||||
* - flags(3): is 1 when the battery is low, otherwise 0 (ok)
|
||||
* - flags(2): is 1 when the sensor sends a reading when pressing the button on the sensor
|
||||
* - flags(1,0): the channel number that can be set by the sensor (1, 2, 3, X)
|
||||
* - temp: 12 bit signed scaled by 10
|
||||
* - humi: 8 bit always 11001100 (0xCC) if no humidity sensor is available
|
||||
*
|
||||
*/
|
||||
|
||||
#define THERMO_PRO_TX4_TYPE_1 0b1001
|
||||
#define THERMO_PRO_TX4_TYPE_2 0b0110
|
||||
|
||||
static const SubGhzBlockConst ws_protocol_thermopro_tx4_const = {
|
||||
.te_short = 500,
|
||||
.te_long = 2000,
|
||||
.te_delta = 150,
|
||||
.min_count_bit_for_found = 37,
|
||||
};
|
||||
|
||||
struct WSProtocolDecoderThermoPRO_TX4 {
|
||||
SubGhzProtocolDecoderBase base;
|
||||
|
||||
SubGhzBlockDecoder decoder;
|
||||
WSBlockGeneric generic;
|
||||
};
|
||||
|
||||
struct WSProtocolEncoderThermoPRO_TX4 {
|
||||
SubGhzProtocolEncoderBase base;
|
||||
|
||||
SubGhzProtocolBlockEncoder encoder;
|
||||
WSBlockGeneric generic;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
ThermoPRO_TX4DecoderStepReset = 0,
|
||||
ThermoPRO_TX4DecoderStepSaveDuration,
|
||||
ThermoPRO_TX4DecoderStepCheckDuration,
|
||||
} ThermoPRO_TX4DecoderStep;
|
||||
|
||||
const SubGhzProtocolDecoder ws_protocol_thermopro_tx4_decoder = {
|
||||
.alloc = ws_protocol_decoder_thermopro_tx4_alloc,
|
||||
.free = ws_protocol_decoder_thermopro_tx4_free,
|
||||
|
||||
.feed = ws_protocol_decoder_thermopro_tx4_feed,
|
||||
.reset = ws_protocol_decoder_thermopro_tx4_reset,
|
||||
|
||||
.get_hash_data = ws_protocol_decoder_thermopro_tx4_get_hash_data,
|
||||
.serialize = ws_protocol_decoder_thermopro_tx4_serialize,
|
||||
.deserialize = ws_protocol_decoder_thermopro_tx4_deserialize,
|
||||
.get_string = ws_protocol_decoder_thermopro_tx4_get_string,
|
||||
};
|
||||
|
||||
const SubGhzProtocolEncoder ws_protocol_thermopro_tx4_encoder = {
|
||||
.alloc = NULL,
|
||||
.free = NULL,
|
||||
|
||||
.deserialize = NULL,
|
||||
.stop = NULL,
|
||||
.yield = NULL,
|
||||
};
|
||||
|
||||
const SubGhzProtocol ws_protocol_thermopro_tx4 = {
|
||||
.name = WS_PROTOCOL_THERMOPRO_TX4_NAME,
|
||||
.type = SubGhzProtocolWeatherStation,
|
||||
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_315 | SubGhzProtocolFlag_868 |
|
||||
SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable,
|
||||
|
||||
.decoder = &ws_protocol_thermopro_tx4_decoder,
|
||||
.encoder = &ws_protocol_thermopro_tx4_encoder,
|
||||
};
|
||||
|
||||
void* ws_protocol_decoder_thermopro_tx4_alloc(SubGhzEnvironment* environment) {
|
||||
UNUSED(environment);
|
||||
WSProtocolDecoderThermoPRO_TX4* instance = malloc(sizeof(WSProtocolDecoderThermoPRO_TX4));
|
||||
instance->base.protocol = &ws_protocol_thermopro_tx4;
|
||||
instance->generic.protocol_name = instance->base.protocol->name;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_thermopro_tx4_free(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderThermoPRO_TX4* instance = context;
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_thermopro_tx4_reset(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderThermoPRO_TX4* instance = context;
|
||||
instance->decoder.parser_step = ThermoPRO_TX4DecoderStepReset;
|
||||
}
|
||||
|
||||
static bool ws_protocol_thermopro_tx4_check(WSProtocolDecoderThermoPRO_TX4* instance) {
|
||||
uint8_t type = instance->decoder.decode_data >> 33;
|
||||
|
||||
if((type == THERMO_PRO_TX4_TYPE_1) || (type == THERMO_PRO_TX4_TYPE_2)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Analysis of received data
|
||||
* @param instance Pointer to a WSBlockGeneric* instance
|
||||
*/
|
||||
static void ws_protocol_thermopro_tx4_remote_controller(WSBlockGeneric* instance) {
|
||||
instance->id = (instance->data >> 25) & 0xFF;
|
||||
instance->battery_low = (instance->data >> 24) & 1;
|
||||
instance->btn = (instance->data >> 23) & 1;
|
||||
instance->channel = ((instance->data >> 21) & 0x03) + 1;
|
||||
|
||||
if(!((instance->data >> 20) & 1)) {
|
||||
instance->temp = (float)((instance->data >> 9) & 0x07FF) / 10.0f;
|
||||
} else {
|
||||
instance->temp = (float)((~(instance->data >> 9) & 0x07FF) + 1) / -10.0f;
|
||||
}
|
||||
|
||||
instance->humidity = (instance->data >> 1) & 0xFF;
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_thermopro_tx4_feed(void* context, bool level, uint32_t duration) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderThermoPRO_TX4* instance = context;
|
||||
|
||||
switch(instance->decoder.parser_step) {
|
||||
case ThermoPRO_TX4DecoderStepReset:
|
||||
if((!level) && (DURATION_DIFF(duration, ws_protocol_thermopro_tx4_const.te_short * 18) <
|
||||
ws_protocol_thermopro_tx4_const.te_delta * 10)) {
|
||||
//Found sync
|
||||
instance->decoder.parser_step = ThermoPRO_TX4DecoderStepSaveDuration;
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case ThermoPRO_TX4DecoderStepSaveDuration:
|
||||
if(level) {
|
||||
instance->decoder.te_last = duration;
|
||||
instance->decoder.parser_step = ThermoPRO_TX4DecoderStepCheckDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = ThermoPRO_TX4DecoderStepReset;
|
||||
}
|
||||
break;
|
||||
|
||||
case ThermoPRO_TX4DecoderStepCheckDuration:
|
||||
if(!level) {
|
||||
if(DURATION_DIFF(duration, ws_protocol_thermopro_tx4_const.te_short * 18) <
|
||||
ws_protocol_thermopro_tx4_const.te_delta * 10) {
|
||||
//Found sync
|
||||
instance->decoder.parser_step = ThermoPRO_TX4DecoderStepReset;
|
||||
if((instance->decoder.decode_count_bit ==
|
||||
ws_protocol_thermopro_tx4_const.min_count_bit_for_found) &&
|
||||
ws_protocol_thermopro_tx4_check(instance)) {
|
||||
instance->generic.data = instance->decoder.decode_data;
|
||||
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
|
||||
ws_protocol_thermopro_tx4_remote_controller(&instance->generic);
|
||||
if(instance->base.callback)
|
||||
instance->base.callback(&instance->base, instance->base.context);
|
||||
instance->decoder.parser_step = ThermoPRO_TX4DecoderStepCheckDuration;
|
||||
}
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
|
||||
break;
|
||||
} else if(
|
||||
(DURATION_DIFF(
|
||||
instance->decoder.te_last, ws_protocol_thermopro_tx4_const.te_short) <
|
||||
ws_protocol_thermopro_tx4_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_thermopro_tx4_const.te_long) <
|
||||
ws_protocol_thermopro_tx4_const.te_delta * 2)) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
||||
instance->decoder.parser_step = ThermoPRO_TX4DecoderStepSaveDuration;
|
||||
} else if(
|
||||
(DURATION_DIFF(
|
||||
instance->decoder.te_last, ws_protocol_thermopro_tx4_const.te_short) <
|
||||
ws_protocol_thermopro_tx4_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_thermopro_tx4_const.te_long * 2) <
|
||||
ws_protocol_thermopro_tx4_const.te_delta * 4)) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
||||
instance->decoder.parser_step = ThermoPRO_TX4DecoderStepSaveDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = ThermoPRO_TX4DecoderStepReset;
|
||||
}
|
||||
} else {
|
||||
instance->decoder.parser_step = ThermoPRO_TX4DecoderStepReset;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t ws_protocol_decoder_thermopro_tx4_get_hash_data(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderThermoPRO_TX4* instance = context;
|
||||
return subghz_protocol_blocks_get_hash_data(
|
||||
&instance->decoder, (instance->decoder.decode_count_bit / 8) + 1);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus ws_protocol_decoder_thermopro_tx4_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderThermoPRO_TX4* instance = context;
|
||||
return ws_block_generic_serialize(&instance->generic, flipper_format, preset);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus
|
||||
ws_protocol_decoder_thermopro_tx4_deserialize(void* context, FlipperFormat* flipper_format) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderThermoPRO_TX4* instance = context;
|
||||
return ws_block_generic_deserialize_check_count_bit(
|
||||
&instance->generic,
|
||||
flipper_format,
|
||||
ws_protocol_thermopro_tx4_const.min_count_bit_for_found);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_thermopro_tx4_get_string(void* context, FuriString* output) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderThermoPRO_TX4* instance = context;
|
||||
furi_string_printf(
|
||||
output,
|
||||
"%s %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
applications/external/weather_station/protocols/thermopro_tx4.h
vendored
Normal file
80
applications/external/weather_station/protocols/thermopro_tx4.h
vendored
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_THERMOPRO_TX4_NAME "ThermoPRO-TX4"
|
||||
|
||||
typedef struct WSProtocolDecoderThermoPRO_TX4 WSProtocolDecoderThermoPRO_TX4;
|
||||
typedef struct WSProtocolEncoderThermoPRO_TX4 WSProtocolEncoderThermoPRO_TX4;
|
||||
|
||||
extern const SubGhzProtocolDecoder ws_protocol_thermopro_tx4_decoder;
|
||||
extern const SubGhzProtocolEncoder ws_protocol_thermopro_tx4_encoder;
|
||||
extern const SubGhzProtocol ws_protocol_thermopro_tx4;
|
||||
|
||||
/**
|
||||
* Allocate WSProtocolDecoderThermoPRO_TX4.
|
||||
* @param environment Pointer to a SubGhzEnvironment instance
|
||||
* @return WSProtocolDecoderThermoPRO_TX4* pointer to a WSProtocolDecoderThermoPRO_TX4 instance
|
||||
*/
|
||||
void* ws_protocol_decoder_thermopro_tx4_alloc(SubGhzEnvironment* environment);
|
||||
|
||||
/**
|
||||
* Free WSProtocolDecoderThermoPRO_TX4.
|
||||
* @param context Pointer to a WSProtocolDecoderThermoPRO_TX4 instance
|
||||
*/
|
||||
void ws_protocol_decoder_thermopro_tx4_free(void* context);
|
||||
|
||||
/**
|
||||
* Reset decoder WSProtocolDecoderThermoPRO_TX4.
|
||||
* @param context Pointer to a WSProtocolDecoderThermoPRO_TX4 instance
|
||||
*/
|
||||
void ws_protocol_decoder_thermopro_tx4_reset(void* context);
|
||||
|
||||
/**
|
||||
* Parse a raw sequence of levels and durations received from the air.
|
||||
* @param context Pointer to a WSProtocolDecoderThermoPRO_TX4 instance
|
||||
* @param level Signal level true-high false-low
|
||||
* @param duration Duration of this level in, us
|
||||
*/
|
||||
void ws_protocol_decoder_thermopro_tx4_feed(void* context, bool level, uint32_t duration);
|
||||
|
||||
/**
|
||||
* Getting the hash sum of the last randomly received parcel.
|
||||
* @param context Pointer to a WSProtocolDecoderThermoPRO_TX4 instance
|
||||
* @return hash Hash sum
|
||||
*/
|
||||
uint8_t ws_protocol_decoder_thermopro_tx4_get_hash_data(void* context);
|
||||
|
||||
/**
|
||||
* Serialize data WSProtocolDecoderThermoPRO_TX4.
|
||||
* @param context Pointer to a WSProtocolDecoderThermoPRO_TX4 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_thermopro_tx4_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset);
|
||||
|
||||
/**
|
||||
* Deserialize data WSProtocolDecoderThermoPRO_TX4.
|
||||
* @param context Pointer to a WSProtocolDecoderThermoPRO_TX4 instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @return status
|
||||
*/
|
||||
SubGhzProtocolStatus
|
||||
ws_protocol_decoder_thermopro_tx4_deserialize(void* context, FlipperFormat* flipper_format);
|
||||
|
||||
/**
|
||||
* Getting a textual representation of the received data.
|
||||
* @param context Pointer to a WSProtocolDecoderThermoPRO_TX4 instance
|
||||
* @param output Resulting text
|
||||
*/
|
||||
void ws_protocol_decoder_thermopro_tx4_get_string(void* context, FuriString* output);
|
284
applications/external/weather_station/protocols/tx_8300.c
vendored
Normal file
284
applications/external/weather_station/protocols/tx_8300.c
vendored
Normal file
@@ -0,0 +1,284 @@
|
||||
#include "tx_8300.h"
|
||||
|
||||
#define TAG "WSProtocolTX_8300"
|
||||
|
||||
/*
|
||||
* Help
|
||||
* https://github.com/merbanan/rtl_433/blob/master/src/devices/ambientweather_tx8300.c
|
||||
*
|
||||
* Ambient Weather TX-8300 (also sold as TFA 30.3211.02).
|
||||
* 1970us pulse with variable gap (third pulse 3920 us).
|
||||
* Above 79% humidity, gap after third pulse is 5848 us.
|
||||
* - Bit 1 : 1970us pulse with 3888 us gap
|
||||
* - Bit 0 : 1970us pulse with 1936 us gap
|
||||
* 74 bit (2 bit preamble and 72 bit data => 9 bytes => 18 nibbles)
|
||||
* The preamble seems to be a repeat counter (00, and 01 seen),
|
||||
* the first 4 bytes are data,
|
||||
* the second 4 bytes the same data inverted,
|
||||
* the last byte is a checksum.
|
||||
* Preamble format (2 bits):
|
||||
* [1 bit (0)] [1 bit rolling count]
|
||||
* Payload format (32 bits):
|
||||
* HHHHhhhh ??CCNIII IIIITTTT ttttuuuu
|
||||
* - H = First BCD digit humidity (the MSB might be distorted by the demod)
|
||||
* - h = Second BCD digit humidity, invalid humidity seems to be 0x0e
|
||||
* - ? = Likely battery flag, 2 bits
|
||||
* - C = Channel, 2 bits
|
||||
* - N = Negative temperature sign bit
|
||||
* - I = ID, 7-bit
|
||||
* - T = First BCD digit temperature
|
||||
* - t = Second BCD digit temperature
|
||||
* - u = Third BCD digit temperature
|
||||
* The Checksum seems to covers the 4 data bytes and is something like Fletcher-8.
|
||||
**/
|
||||
|
||||
#define TX_8300_PACKAGE_SIZE 32
|
||||
|
||||
static const SubGhzBlockConst ws_protocol_tx_8300_const = {
|
||||
.te_short = 1940,
|
||||
.te_long = 3880,
|
||||
.te_delta = 250,
|
||||
.min_count_bit_for_found = 72,
|
||||
};
|
||||
|
||||
struct WSProtocolDecoderTX_8300 {
|
||||
SubGhzProtocolDecoderBase base;
|
||||
|
||||
SubGhzBlockDecoder decoder;
|
||||
WSBlockGeneric generic;
|
||||
uint32_t package_1;
|
||||
uint32_t package_2;
|
||||
};
|
||||
|
||||
struct WSProtocolEncoderTX_8300 {
|
||||
SubGhzProtocolEncoderBase base;
|
||||
|
||||
SubGhzProtocolBlockEncoder encoder;
|
||||
WSBlockGeneric generic;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
TX_8300DecoderStepReset = 0,
|
||||
TX_8300DecoderStepCheckPreambule,
|
||||
TX_8300DecoderStepSaveDuration,
|
||||
TX_8300DecoderStepCheckDuration,
|
||||
} TX_8300DecoderStep;
|
||||
|
||||
const SubGhzProtocolDecoder ws_protocol_tx_8300_decoder = {
|
||||
.alloc = ws_protocol_decoder_tx_8300_alloc,
|
||||
.free = ws_protocol_decoder_tx_8300_free,
|
||||
|
||||
.feed = ws_protocol_decoder_tx_8300_feed,
|
||||
.reset = ws_protocol_decoder_tx_8300_reset,
|
||||
|
||||
.get_hash_data = ws_protocol_decoder_tx_8300_get_hash_data,
|
||||
.serialize = ws_protocol_decoder_tx_8300_serialize,
|
||||
.deserialize = ws_protocol_decoder_tx_8300_deserialize,
|
||||
.get_string = ws_protocol_decoder_tx_8300_get_string,
|
||||
};
|
||||
|
||||
const SubGhzProtocolEncoder ws_protocol_tx_8300_encoder = {
|
||||
.alloc = NULL,
|
||||
.free = NULL,
|
||||
|
||||
.deserialize = NULL,
|
||||
.stop = NULL,
|
||||
.yield = NULL,
|
||||
};
|
||||
|
||||
const SubGhzProtocol ws_protocol_tx_8300 = {
|
||||
.name = WS_PROTOCOL_TX_8300_NAME,
|
||||
.type = SubGhzProtocolWeatherStation,
|
||||
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_315 | SubGhzProtocolFlag_868 |
|
||||
SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable,
|
||||
|
||||
.decoder = &ws_protocol_tx_8300_decoder,
|
||||
.encoder = &ws_protocol_tx_8300_encoder,
|
||||
};
|
||||
|
||||
void* ws_protocol_decoder_tx_8300_alloc(SubGhzEnvironment* environment) {
|
||||
UNUSED(environment);
|
||||
WSProtocolDecoderTX_8300* instance = malloc(sizeof(WSProtocolDecoderTX_8300));
|
||||
instance->base.protocol = &ws_protocol_tx_8300;
|
||||
instance->generic.protocol_name = instance->base.protocol->name;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_tx_8300_free(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderTX_8300* instance = context;
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_tx_8300_reset(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderTX_8300* instance = context;
|
||||
instance->decoder.parser_step = TX_8300DecoderStepReset;
|
||||
}
|
||||
|
||||
static bool ws_protocol_tx_8300_check_crc(WSProtocolDecoderTX_8300* instance) {
|
||||
if(!instance->package_2) return false;
|
||||
if(instance->package_1 != ~instance->package_2) return false;
|
||||
|
||||
uint16_t x = 0;
|
||||
uint16_t y = 0;
|
||||
for(int i = 0; i < 32; i += 4) {
|
||||
x += (instance->package_1 >> i) & 0x0F;
|
||||
y += (instance->package_1 >> i) & 0x05;
|
||||
}
|
||||
uint8_t crc = (~x & 0xF) << 4 | (~y & 0xF);
|
||||
return (crc == ((instance->decoder.decode_data) & 0xFF));
|
||||
}
|
||||
|
||||
/**
|
||||
* Analysis of received data
|
||||
* @param instance Pointer to a WSBlockGeneric* instance
|
||||
*/
|
||||
static void ws_protocol_tx_8300_remote_controller(WSBlockGeneric* instance) {
|
||||
instance->humidity = (((instance->data >> 28) & 0x0F) * 10) + ((instance->data >> 24) & 0x0F);
|
||||
instance->btn = WS_NO_BTN;
|
||||
if(!((instance->data >> 22) & 0x03))
|
||||
instance->battery_low = 0;
|
||||
else
|
||||
instance->battery_low = 1;
|
||||
instance->channel = (instance->data >> 20) & 0x03;
|
||||
instance->id = (instance->data >> 12) & 0x7F;
|
||||
|
||||
float temp_raw = ((instance->data >> 8) & 0x0F) * 10.0f + ((instance->data >> 4) & 0x0F) +
|
||||
(instance->data & 0x0F) * 0.1f;
|
||||
if(!((instance->data >> 19) & 1)) {
|
||||
instance->temp = temp_raw;
|
||||
} else {
|
||||
instance->temp = -temp_raw;
|
||||
}
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_tx_8300_feed(void* context, bool level, uint32_t duration) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderTX_8300* instance = context;
|
||||
|
||||
switch(instance->decoder.parser_step) {
|
||||
case TX_8300DecoderStepReset:
|
||||
if((level) && (DURATION_DIFF(duration, ws_protocol_tx_8300_const.te_short * 2) <
|
||||
ws_protocol_tx_8300_const.te_delta)) {
|
||||
instance->decoder.parser_step = TX_8300DecoderStepCheckPreambule;
|
||||
}
|
||||
break;
|
||||
|
||||
case TX_8300DecoderStepCheckPreambule:
|
||||
if((!level) && ((DURATION_DIFF(duration, ws_protocol_tx_8300_const.te_short * 2) <
|
||||
ws_protocol_tx_8300_const.te_delta) ||
|
||||
(DURATION_DIFF(duration, ws_protocol_tx_8300_const.te_short * 3) <
|
||||
ws_protocol_tx_8300_const.te_delta))) {
|
||||
instance->decoder.parser_step = TX_8300DecoderStepSaveDuration;
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 1;
|
||||
instance->package_1 = 0;
|
||||
instance->package_2 = 0;
|
||||
} else {
|
||||
instance->decoder.parser_step = TX_8300DecoderStepReset;
|
||||
}
|
||||
break;
|
||||
|
||||
case TX_8300DecoderStepSaveDuration:
|
||||
if(level) {
|
||||
instance->decoder.te_last = duration;
|
||||
instance->decoder.parser_step = TX_8300DecoderStepCheckDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = TX_8300DecoderStepReset;
|
||||
}
|
||||
break;
|
||||
|
||||
case TX_8300DecoderStepCheckDuration:
|
||||
if(!level) {
|
||||
if(duration >= ((uint32_t)ws_protocol_tx_8300_const.te_short * 5)) {
|
||||
//Found syncPostfix
|
||||
if((instance->decoder.decode_count_bit ==
|
||||
ws_protocol_tx_8300_const.min_count_bit_for_found) &&
|
||||
ws_protocol_tx_8300_check_crc(instance)) {
|
||||
instance->generic.data = instance->package_1;
|
||||
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
|
||||
ws_protocol_tx_8300_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 = 1;
|
||||
instance->decoder.parser_step = TX_8300DecoderStepReset;
|
||||
break;
|
||||
} else if(
|
||||
(DURATION_DIFF(instance->decoder.te_last, ws_protocol_tx_8300_const.te_short) <
|
||||
ws_protocol_tx_8300_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_tx_8300_const.te_long) <
|
||||
ws_protocol_tx_8300_const.te_delta * 2)) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
||||
instance->decoder.parser_step = TX_8300DecoderStepSaveDuration;
|
||||
} else if(
|
||||
(DURATION_DIFF(instance->decoder.te_last, ws_protocol_tx_8300_const.te_short) <
|
||||
ws_protocol_tx_8300_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, ws_protocol_tx_8300_const.te_short) <
|
||||
ws_protocol_tx_8300_const.te_delta)) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
||||
instance->decoder.parser_step = TX_8300DecoderStepSaveDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = TX_8300DecoderStepReset;
|
||||
}
|
||||
|
||||
if(instance->decoder.decode_count_bit == TX_8300_PACKAGE_SIZE) {
|
||||
instance->package_1 = instance->decoder.decode_data;
|
||||
instance->decoder.decode_data = 0;
|
||||
} else if(instance->decoder.decode_count_bit == TX_8300_PACKAGE_SIZE * 2) {
|
||||
instance->package_2 = instance->decoder.decode_data;
|
||||
instance->decoder.decode_data = 0;
|
||||
}
|
||||
|
||||
} else {
|
||||
instance->decoder.parser_step = TX_8300DecoderStepReset;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t ws_protocol_decoder_tx_8300_get_hash_data(void* context) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderTX_8300* instance = context;
|
||||
return subghz_protocol_blocks_get_hash_data(
|
||||
&instance->decoder, (instance->decoder.decode_count_bit / 8) + 1);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus ws_protocol_decoder_tx_8300_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderTX_8300* instance = context;
|
||||
return ws_block_generic_serialize(&instance->generic, flipper_format, preset);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus
|
||||
ws_protocol_decoder_tx_8300_deserialize(void* context, FlipperFormat* flipper_format) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderTX_8300* instance = context;
|
||||
return ws_block_generic_deserialize_check_count_bit(
|
||||
&instance->generic, flipper_format, ws_protocol_tx_8300_const.min_count_bit_for_found);
|
||||
}
|
||||
|
||||
void ws_protocol_decoder_tx_8300_get_string(void* context, FuriString* output) {
|
||||
furi_assert(context);
|
||||
WSProtocolDecoderTX_8300* instance = context;
|
||||
furi_string_printf(
|
||||
output,
|
||||
"%s %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
applications/external/weather_station/protocols/tx_8300.h
vendored
Normal file
80
applications/external/weather_station/protocols/tx_8300.h
vendored
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_TX_8300_NAME "TX8300"
|
||||
|
||||
typedef struct WSProtocolDecoderTX_8300 WSProtocolDecoderTX_8300;
|
||||
typedef struct WSProtocolEncoderTX_8300 WSProtocolEncoderTX_8300;
|
||||
|
||||
extern const SubGhzProtocolDecoder ws_protocol_tx_8300_decoder;
|
||||
extern const SubGhzProtocolEncoder ws_protocol_tx_8300_encoder;
|
||||
extern const SubGhzProtocol ws_protocol_tx_8300;
|
||||
|
||||
/**
|
||||
* Allocate WSProtocolDecoderTX_8300.
|
||||
* @param environment Pointer to a SubGhzEnvironment instance
|
||||
* @return WSProtocolDecoderTX_8300* pointer to a WSProtocolDecoderTX_8300 instance
|
||||
*/
|
||||
void* ws_protocol_decoder_tx_8300_alloc(SubGhzEnvironment* environment);
|
||||
|
||||
/**
|
||||
* Free WSProtocolDecoderTX_8300.
|
||||
* @param context Pointer to a WSProtocolDecoderTX_8300 instance
|
||||
*/
|
||||
void ws_protocol_decoder_tx_8300_free(void* context);
|
||||
|
||||
/**
|
||||
* Reset decoder WSProtocolDecoderTX_8300.
|
||||
* @param context Pointer to a WSProtocolDecoderTX_8300 instance
|
||||
*/
|
||||
void ws_protocol_decoder_tx_8300_reset(void* context);
|
||||
|
||||
/**
|
||||
* Parse a raw sequence of levels and durations received from the air.
|
||||
* @param context Pointer to a WSProtocolDecoderTX_8300 instance
|
||||
* @param level Signal level true-high false-low
|
||||
* @param duration Duration of this level in, us
|
||||
*/
|
||||
void ws_protocol_decoder_tx_8300_feed(void* context, bool level, uint32_t duration);
|
||||
|
||||
/**
|
||||
* Getting the hash sum of the last randomly received parcel.
|
||||
* @param context Pointer to a WSProtocolDecoderTX_8300 instance
|
||||
* @return hash Hash sum
|
||||
*/
|
||||
uint8_t ws_protocol_decoder_tx_8300_get_hash_data(void* context);
|
||||
|
||||
/**
|
||||
* Serialize data WSProtocolDecoderTX_8300.
|
||||
* @param context Pointer to a WSProtocolDecoderTX_8300 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_tx_8300_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset);
|
||||
|
||||
/**
|
||||
* Deserialize data WSProtocolDecoderTX_8300.
|
||||
* @param context Pointer to a WSProtocolDecoderTX_8300 instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @return status
|
||||
*/
|
||||
SubGhzProtocolStatus
|
||||
ws_protocol_decoder_tx_8300_deserialize(void* context, FlipperFormat* flipper_format);
|
||||
|
||||
/**
|
||||
* Getting a textual representation of the received data.
|
||||
* @param context Pointer to a WSProtocolDecoderTX_8300 instance
|
||||
* @param output Resulting text
|
||||
*/
|
||||
void ws_protocol_decoder_tx_8300_get_string(void* context, FuriString* output);
|
256
applications/external/weather_station/protocols/ws_generic.c
vendored
Normal file
256
applications/external/weather_station/protocols/ws_generic.c
vendored
Normal file
@@ -0,0 +1,256 @@
|
||||
#include "ws_generic.h"
|
||||
#include <lib/toolbox/stream/stream.h>
|
||||
#include <lib/flipper_format/flipper_format_i.h>
|
||||
#include "../helpers/weather_station_types.h"
|
||||
|
||||
#define TAG "WSBlockGeneric"
|
||||
|
||||
void ws_block_generic_get_preset_name(const char* preset_name, FuriString* preset_str) {
|
||||
const char* preset_name_temp;
|
||||
if(!strcmp(preset_name, "AM270")) {
|
||||
preset_name_temp = "FuriHalSubGhzPresetOok270Async";
|
||||
} else if(!strcmp(preset_name, "AM650")) {
|
||||
preset_name_temp = "FuriHalSubGhzPresetOok650Async";
|
||||
} else if(!strcmp(preset_name, "FM238")) {
|
||||
preset_name_temp = "FuriHalSubGhzPreset2FSKDev238Async";
|
||||
} else if(!strcmp(preset_name, "FM476")) {
|
||||
preset_name_temp = "FuriHalSubGhzPreset2FSKDev476Async";
|
||||
} else {
|
||||
preset_name_temp = "FuriHalSubGhzPresetCustom";
|
||||
}
|
||||
furi_string_set(preset_str, preset_name_temp);
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus ws_block_generic_serialize(
|
||||
WSBlockGeneric* instance,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset) {
|
||||
furi_assert(instance);
|
||||
SubGhzProtocolStatus res = SubGhzProtocolStatusError;
|
||||
FuriString* temp_str;
|
||||
temp_str = furi_string_alloc();
|
||||
do {
|
||||
stream_clean(flipper_format_get_raw_stream(flipper_format));
|
||||
if(!flipper_format_write_header_cstr(
|
||||
flipper_format, WS_KEY_FILE_TYPE, WS_KEY_FILE_VERSION)) {
|
||||
FURI_LOG_E(TAG, "Unable to add header");
|
||||
res = SubGhzProtocolStatusErrorParserHeader;
|
||||
break;
|
||||
}
|
||||
|
||||
if(!flipper_format_write_uint32(flipper_format, "Frequency", &preset->frequency, 1)) {
|
||||
FURI_LOG_E(TAG, "Unable to add Frequency");
|
||||
res = SubGhzProtocolStatusErrorParserFrequency;
|
||||
break;
|
||||
}
|
||||
|
||||
ws_block_generic_get_preset_name(furi_string_get_cstr(preset->name), temp_str);
|
||||
if(!flipper_format_write_string_cstr(
|
||||
flipper_format, "Preset", furi_string_get_cstr(temp_str))) {
|
||||
FURI_LOG_E(TAG, "Unable to add Preset");
|
||||
res = SubGhzProtocolStatusErrorParserPreset;
|
||||
break;
|
||||
}
|
||||
if(!strcmp(furi_string_get_cstr(temp_str), "FuriHalSubGhzPresetCustom")) {
|
||||
if(!flipper_format_write_string_cstr(
|
||||
flipper_format, "Custom_preset_module", "CC1101")) {
|
||||
FURI_LOG_E(TAG, "Unable to add Custom_preset_module");
|
||||
res = SubGhzProtocolStatusErrorParserCustomPreset;
|
||||
break;
|
||||
}
|
||||
if(!flipper_format_write_hex(
|
||||
flipper_format, "Custom_preset_data", preset->data, preset->data_size)) {
|
||||
FURI_LOG_E(TAG, "Unable to add Custom_preset_data");
|
||||
res = SubGhzProtocolStatusErrorParserCustomPreset;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!flipper_format_write_string_cstr(flipper_format, "Protocol", instance->protocol_name)) {
|
||||
FURI_LOG_E(TAG, "Unable to add Protocol");
|
||||
res = SubGhzProtocolStatusErrorParserProtocolName;
|
||||
break;
|
||||
}
|
||||
|
||||
uint32_t temp_data = instance->id;
|
||||
if(!flipper_format_write_uint32(flipper_format, "Id", &temp_data, 1)) {
|
||||
FURI_LOG_E(TAG, "Unable to add Id");
|
||||
res = SubGhzProtocolStatusErrorParserOthers;
|
||||
break;
|
||||
}
|
||||
|
||||
temp_data = instance->data_count_bit;
|
||||
if(!flipper_format_write_uint32(flipper_format, "Bit", &temp_data, 1)) {
|
||||
FURI_LOG_E(TAG, "Unable to add Bit");
|
||||
res = SubGhzProtocolStatusErrorParserBitCount;
|
||||
break;
|
||||
}
|
||||
|
||||
uint8_t key_data[sizeof(uint64_t)] = {0};
|
||||
for(size_t i = 0; i < sizeof(uint64_t); i++) {
|
||||
key_data[sizeof(uint64_t) - i - 1] = (instance->data >> (i * 8)) & 0xFF;
|
||||
}
|
||||
|
||||
if(!flipper_format_write_hex(flipper_format, "Data", key_data, sizeof(uint64_t))) {
|
||||
FURI_LOG_E(TAG, "Unable to add Data");
|
||||
res = SubGhzProtocolStatusErrorParserOthers;
|
||||
break;
|
||||
}
|
||||
|
||||
temp_data = instance->battery_low;
|
||||
if(!flipper_format_write_uint32(flipper_format, "Batt", &temp_data, 1)) {
|
||||
FURI_LOG_E(TAG, "Unable to add Battery_low");
|
||||
res = SubGhzProtocolStatusErrorParserOthers;
|
||||
break;
|
||||
}
|
||||
|
||||
temp_data = instance->humidity;
|
||||
if(!flipper_format_write_uint32(flipper_format, "Hum", &temp_data, 1)) {
|
||||
FURI_LOG_E(TAG, "Unable to add Humidity");
|
||||
res = SubGhzProtocolStatusErrorParserOthers;
|
||||
break;
|
||||
}
|
||||
|
||||
//DATE AGE set
|
||||
FuriHalRtcDateTime curr_dt;
|
||||
furi_hal_rtc_get_datetime(&curr_dt);
|
||||
uint32_t curr_ts = furi_hal_rtc_datetime_to_timestamp(&curr_dt);
|
||||
|
||||
temp_data = curr_ts;
|
||||
if(!flipper_format_write_uint32(flipper_format, "Ts", &temp_data, 1)) {
|
||||
FURI_LOG_E(TAG, "Unable to add timestamp");
|
||||
res = SubGhzProtocolStatusErrorParserOthers;
|
||||
break;
|
||||
}
|
||||
|
||||
temp_data = instance->channel;
|
||||
if(!flipper_format_write_uint32(flipper_format, "Ch", &temp_data, 1)) {
|
||||
FURI_LOG_E(TAG, "Unable to add Channel");
|
||||
res = SubGhzProtocolStatusErrorParserOthers;
|
||||
break;
|
||||
}
|
||||
|
||||
temp_data = instance->btn;
|
||||
if(!flipper_format_write_uint32(flipper_format, "Btn", &temp_data, 1)) {
|
||||
FURI_LOG_E(TAG, "Unable to add Btn");
|
||||
res = SubGhzProtocolStatusErrorParserOthers;
|
||||
break;
|
||||
}
|
||||
|
||||
float temp = instance->temp;
|
||||
if(!flipper_format_write_float(flipper_format, "Temp", &temp, 1)) {
|
||||
FURI_LOG_E(TAG, "Unable to add Temperature");
|
||||
res = SubGhzProtocolStatusErrorParserOthers;
|
||||
break;
|
||||
}
|
||||
|
||||
res = SubGhzProtocolStatusOk;
|
||||
} while(false);
|
||||
furi_string_free(temp_str);
|
||||
return res;
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus
|
||||
ws_block_generic_deserialize(WSBlockGeneric* instance, FlipperFormat* flipper_format) {
|
||||
furi_assert(instance);
|
||||
SubGhzProtocolStatus res = SubGhzProtocolStatusError;
|
||||
uint32_t temp_data = 0;
|
||||
|
||||
do {
|
||||
if(!flipper_format_rewind(flipper_format)) {
|
||||
FURI_LOG_E(TAG, "Rewind error");
|
||||
res = SubGhzProtocolStatusErrorParserOthers;
|
||||
break;
|
||||
}
|
||||
|
||||
if(!flipper_format_read_uint32(flipper_format, "Id", (uint32_t*)&temp_data, 1)) {
|
||||
FURI_LOG_E(TAG, "Missing Id");
|
||||
res = SubGhzProtocolStatusErrorParserOthers;
|
||||
break;
|
||||
}
|
||||
instance->id = (uint32_t)temp_data;
|
||||
|
||||
if(!flipper_format_read_uint32(flipper_format, "Bit", (uint32_t*)&temp_data, 1)) {
|
||||
FURI_LOG_E(TAG, "Missing Bit");
|
||||
res = SubGhzProtocolStatusErrorParserBitCount;
|
||||
break;
|
||||
}
|
||||
instance->data_count_bit = (uint8_t)temp_data;
|
||||
|
||||
uint8_t key_data[sizeof(uint64_t)] = {0};
|
||||
if(!flipper_format_read_hex(flipper_format, "Data", key_data, sizeof(uint64_t))) {
|
||||
FURI_LOG_E(TAG, "Missing Data");
|
||||
res = SubGhzProtocolStatusErrorParserOthers;
|
||||
break;
|
||||
}
|
||||
|
||||
for(uint8_t i = 0; i < sizeof(uint64_t); i++) {
|
||||
instance->data = instance->data << 8 | key_data[i];
|
||||
}
|
||||
|
||||
if(!flipper_format_read_uint32(flipper_format, "Batt", (uint32_t*)&temp_data, 1)) {
|
||||
FURI_LOG_E(TAG, "Missing Battery_low");
|
||||
res = SubGhzProtocolStatusErrorParserOthers;
|
||||
break;
|
||||
}
|
||||
instance->battery_low = (uint8_t)temp_data;
|
||||
|
||||
if(!flipper_format_read_uint32(flipper_format, "Hum", (uint32_t*)&temp_data, 1)) {
|
||||
FURI_LOG_E(TAG, "Missing Humidity");
|
||||
res = SubGhzProtocolStatusErrorParserOthers;
|
||||
break;
|
||||
}
|
||||
instance->humidity = (uint8_t)temp_data;
|
||||
|
||||
if(!flipper_format_read_uint32(flipper_format, "Ts", (uint32_t*)&temp_data, 1)) {
|
||||
FURI_LOG_E(TAG, "Missing timestamp");
|
||||
res = SubGhzProtocolStatusErrorParserOthers;
|
||||
break;
|
||||
}
|
||||
instance->timestamp = (uint32_t)temp_data;
|
||||
|
||||
if(!flipper_format_read_uint32(flipper_format, "Ch", (uint32_t*)&temp_data, 1)) {
|
||||
FURI_LOG_E(TAG, "Missing Channel");
|
||||
res = SubGhzProtocolStatusErrorParserOthers;
|
||||
break;
|
||||
}
|
||||
instance->channel = (uint8_t)temp_data;
|
||||
|
||||
if(!flipper_format_read_uint32(flipper_format, "Btn", (uint32_t*)&temp_data, 1)) {
|
||||
FURI_LOG_E(TAG, "Missing Btn");
|
||||
res = SubGhzProtocolStatusErrorParserOthers;
|
||||
break;
|
||||
}
|
||||
instance->btn = (uint8_t)temp_data;
|
||||
|
||||
float temp;
|
||||
if(!flipper_format_read_float(flipper_format, "Temp", (float*)&temp, 1)) {
|
||||
FURI_LOG_E(TAG, "Missing Temperature");
|
||||
res = SubGhzProtocolStatusErrorParserOthers;
|
||||
break;
|
||||
}
|
||||
instance->temp = temp;
|
||||
|
||||
res = SubGhzProtocolStatusOk;
|
||||
} while(0);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus ws_block_generic_deserialize_check_count_bit(
|
||||
WSBlockGeneric* instance,
|
||||
FlipperFormat* flipper_format,
|
||||
uint16_t count_bit) {
|
||||
SubGhzProtocolStatus ret = SubGhzProtocolStatusError;
|
||||
do {
|
||||
ret = ws_block_generic_deserialize(instance, flipper_format);
|
||||
if(ret != SubGhzProtocolStatusOk) {
|
||||
break;
|
||||
}
|
||||
if(instance->data_count_bit != count_bit) {
|
||||
FURI_LOG_E(TAG, "Wrong number of bits in key");
|
||||
ret = SubGhzProtocolStatusErrorValueBitCount;
|
||||
break;
|
||||
}
|
||||
} while(false);
|
||||
return ret;
|
||||
}
|
81
applications/external/weather_station/protocols/ws_generic.h
vendored
Normal file
81
applications/external/weather_station/protocols/ws_generic.h
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include <lib/flipper_format/flipper_format.h>
|
||||
#include "furi.h"
|
||||
#include <furi_hal.h>
|
||||
#include <lib/subghz/types.h>
|
||||
#include <locale/locale.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define WS_NO_ID 0xFFFFFFFF
|
||||
#define WS_NO_BATT 0xFF
|
||||
#define WS_NO_HUMIDITY 0xFF
|
||||
#define WS_NO_CHANNEL 0xFF
|
||||
#define WS_NO_BTN 0xFF
|
||||
#define WS_NO_TEMPERATURE -273.0f
|
||||
|
||||
typedef struct WSBlockGeneric WSBlockGeneric;
|
||||
|
||||
struct WSBlockGeneric {
|
||||
const char* protocol_name;
|
||||
uint64_t data;
|
||||
uint32_t id;
|
||||
uint8_t data_count_bit;
|
||||
uint8_t battery_low;
|
||||
uint8_t humidity;
|
||||
uint32_t timestamp;
|
||||
uint8_t channel;
|
||||
uint8_t btn;
|
||||
float temp;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get name preset.
|
||||
* @param preset_name name preset
|
||||
* @param preset_str Output name preset
|
||||
*/
|
||||
void ws_block_generic_get_preset_name(const char* preset_name, FuriString* preset_str);
|
||||
|
||||
/**
|
||||
* Serialize data WSBlockGeneric.
|
||||
* @param instance Pointer to a WSBlockGeneric instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @param preset The modulation on which the signal was received, SubGhzRadioPreset
|
||||
* @return status
|
||||
*/
|
||||
SubGhzProtocolStatus ws_block_generic_serialize(
|
||||
WSBlockGeneric* instance,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset);
|
||||
|
||||
/**
|
||||
* Deserialize data WSBlockGeneric.
|
||||
* @param instance Pointer to a WSBlockGeneric instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @return status
|
||||
*/
|
||||
SubGhzProtocolStatus
|
||||
ws_block_generic_deserialize(WSBlockGeneric* instance, FlipperFormat* flipper_format);
|
||||
|
||||
/**
|
||||
* Deserialize data WSBlockGeneric.
|
||||
* @param instance Pointer to a WSBlockGeneric instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @param count_bit Count bit protocol
|
||||
* @return status
|
||||
*/
|
||||
SubGhzProtocolStatus ws_block_generic_deserialize_check_count_bit(
|
||||
WSBlockGeneric* instance,
|
||||
FlipperFormat* flipper_format,
|
||||
uint16_t count_bit);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
Reference in New Issue
Block a user