[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
13
applications/external/weather_station/application.fam
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
App(
|
||||
appid="weather_station",
|
||||
name="Weather Station",
|
||||
apptype=FlipperAppType.EXTERNAL,
|
||||
targets=["f7"],
|
||||
entry_point="weather_station_app",
|
||||
requires=["gui"],
|
||||
stack_size=4 * 1024,
|
||||
order=50,
|
||||
fap_icon="weather_station_10px.png",
|
||||
fap_category="Sub-GHz",
|
||||
fap_icon_assets="images",
|
||||
)
|
||||
14
applications/external/weather_station/helpers/weather_station_event.h
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
typedef enum {
|
||||
//WSCustomEvent
|
||||
WSCustomEventStartId = 100,
|
||||
|
||||
WSCustomEventSceneSettingLock,
|
||||
|
||||
WSCustomEventViewReceiverOK,
|
||||
WSCustomEventViewReceiverConfig,
|
||||
WSCustomEventViewReceiverBack,
|
||||
WSCustomEventViewReceiverOffDisplay,
|
||||
WSCustomEventViewReceiverUnlock,
|
||||
} WSCustomEvent;
|
||||
49
applications/external/weather_station/helpers/weather_station_types.h
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
|
||||
#define WS_VERSION_APP "0.8"
|
||||
#define WS_DEVELOPED "SkorP"
|
||||
#define WS_GITHUB "https://github.com/flipperdevices/flipperzero-firmware"
|
||||
|
||||
#define WS_KEY_FILE_VERSION 1
|
||||
#define WS_KEY_FILE_TYPE "Flipper Weather Station Key File"
|
||||
|
||||
/** WSRxKeyState state */
|
||||
typedef enum {
|
||||
WSRxKeyStateIDLE,
|
||||
WSRxKeyStateBack,
|
||||
WSRxKeyStateStart,
|
||||
WSRxKeyStateAddKey,
|
||||
} WSRxKeyState;
|
||||
|
||||
/** WSHopperState state */
|
||||
typedef enum {
|
||||
WSHopperStateOFF,
|
||||
WSHopperStateRunnig,
|
||||
WSHopperStatePause,
|
||||
WSHopperStateRSSITimeOut,
|
||||
} WSHopperState;
|
||||
|
||||
/** WSLock */
|
||||
typedef enum {
|
||||
WSLockOff,
|
||||
WSLockOn,
|
||||
} WSLock;
|
||||
|
||||
typedef enum {
|
||||
WeatherStationViewVariableItemList,
|
||||
WeatherStationViewSubmenu,
|
||||
WeatherStationViewReceiver,
|
||||
WeatherStationViewReceiverInfo,
|
||||
WeatherStationViewWidget,
|
||||
} WeatherStationView;
|
||||
|
||||
/** WeatherStationTxRx state */
|
||||
typedef enum {
|
||||
WSTxRxStateIDLE,
|
||||
WSTxRxStateRx,
|
||||
WSTxRxStateTx,
|
||||
WSTxRxStateSleep,
|
||||
} WSTxRxState;
|
||||
BIN
applications/external/weather_station/images/Humid_10x15.png
vendored
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
applications/external/weather_station/images/Humid_8x13.png
vendored
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
applications/external/weather_station/images/Lock_7x8.png
vendored
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
applications/external/weather_station/images/Pin_back_arrow_10x8.png
vendored
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
applications/external/weather_station/images/Quest_7x8.png
vendored
Normal file
|
After Width: | Height: | Size: 3.6 KiB |
BIN
applications/external/weather_station/images/Scanning_123x52.png
vendored
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
applications/external/weather_station/images/Therm_7x16.png
vendored
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
applications/external/weather_station/images/Timer_11x11.png
vendored
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
applications/external/weather_station/images/Unlock_7x8.png
vendored
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
applications/external/weather_station/images/WarningDolphin_45x42.png
vendored
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
applications/external/weather_station/images/station_icon.png
vendored
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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 °C * 10
|
||||
* - t: BCD, Temperature; in °C * 1
|
||||
* - z: BCD, Temperature; in °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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
|
||||
211
applications/external/weather_station/scenes/weather_station_receiver.c
vendored
Normal file
@@ -0,0 +1,211 @@
|
||||
#include "../weather_station_app_i.h"
|
||||
#include "../views/weather_station_receiver.h"
|
||||
|
||||
static const NotificationSequence subghs_sequence_rx = {
|
||||
&message_green_255,
|
||||
|
||||
&message_vibro_on,
|
||||
&message_note_c6,
|
||||
&message_delay_50,
|
||||
&message_sound_off,
|
||||
&message_vibro_off,
|
||||
|
||||
&message_delay_50,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static const NotificationSequence subghs_sequence_rx_locked = {
|
||||
&message_green_255,
|
||||
|
||||
&message_display_backlight_on,
|
||||
|
||||
&message_vibro_on,
|
||||
&message_note_c6,
|
||||
&message_delay_50,
|
||||
&message_sound_off,
|
||||
&message_vibro_off,
|
||||
|
||||
&message_delay_500,
|
||||
|
||||
&message_display_backlight_off,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static void weather_station_scene_receiver_update_statusbar(void* context) {
|
||||
WeatherStationApp* app = context;
|
||||
FuriString* history_stat_str;
|
||||
history_stat_str = furi_string_alloc();
|
||||
if(!ws_history_get_text_space_left(app->txrx->history, history_stat_str)) {
|
||||
FuriString* frequency_str;
|
||||
FuriString* modulation_str;
|
||||
|
||||
frequency_str = furi_string_alloc();
|
||||
modulation_str = furi_string_alloc();
|
||||
|
||||
ws_get_frequency_modulation(app, frequency_str, modulation_str);
|
||||
|
||||
ws_view_receiver_add_data_statusbar(
|
||||
app->ws_receiver,
|
||||
furi_string_get_cstr(frequency_str),
|
||||
furi_string_get_cstr(modulation_str),
|
||||
furi_string_get_cstr(history_stat_str));
|
||||
|
||||
furi_string_free(frequency_str);
|
||||
furi_string_free(modulation_str);
|
||||
} else {
|
||||
ws_view_receiver_add_data_statusbar(
|
||||
app->ws_receiver, furi_string_get_cstr(history_stat_str), "", "");
|
||||
}
|
||||
furi_string_free(history_stat_str);
|
||||
}
|
||||
|
||||
void weather_station_scene_receiver_callback(WSCustomEvent event, void* context) {
|
||||
furi_assert(context);
|
||||
WeatherStationApp* app = context;
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, event);
|
||||
}
|
||||
|
||||
static void weather_station_scene_receiver_add_to_history_callback(
|
||||
SubGhzReceiver* receiver,
|
||||
SubGhzProtocolDecoderBase* decoder_base,
|
||||
void* context) {
|
||||
furi_assert(context);
|
||||
WeatherStationApp* app = context;
|
||||
FuriString* str_buff;
|
||||
str_buff = furi_string_alloc();
|
||||
|
||||
if(ws_history_add_to_history(app->txrx->history, decoder_base, app->txrx->preset) ==
|
||||
WSHistoryStateAddKeyNewDada) {
|
||||
furi_string_reset(str_buff);
|
||||
|
||||
ws_history_get_text_item_menu(
|
||||
app->txrx->history, str_buff, ws_history_get_item(app->txrx->history) - 1);
|
||||
ws_view_receiver_add_item_to_menu(
|
||||
app->ws_receiver,
|
||||
furi_string_get_cstr(str_buff),
|
||||
ws_history_get_type_protocol(
|
||||
app->txrx->history, ws_history_get_item(app->txrx->history) - 1));
|
||||
|
||||
weather_station_scene_receiver_update_statusbar(app);
|
||||
notification_message(app->notifications, &sequence_blink_green_10);
|
||||
if(app->lock != WSLockOn) {
|
||||
notification_message(app->notifications, &subghs_sequence_rx);
|
||||
} else {
|
||||
notification_message(app->notifications, &subghs_sequence_rx_locked);
|
||||
}
|
||||
}
|
||||
subghz_receiver_reset(receiver);
|
||||
furi_string_free(str_buff);
|
||||
app->txrx->rx_key_state = WSRxKeyStateAddKey;
|
||||
}
|
||||
|
||||
void weather_station_scene_receiver_on_enter(void* context) {
|
||||
WeatherStationApp* app = context;
|
||||
|
||||
FuriString* str_buff;
|
||||
str_buff = furi_string_alloc();
|
||||
|
||||
if(app->txrx->rx_key_state == WSRxKeyStateIDLE) {
|
||||
ws_preset_init(app, "AM650", subghz_setting_get_default_frequency(app->setting), NULL, 0);
|
||||
ws_history_reset(app->txrx->history);
|
||||
app->txrx->rx_key_state = WSRxKeyStateStart;
|
||||
}
|
||||
|
||||
ws_view_receiver_set_lock(app->ws_receiver, app->lock);
|
||||
|
||||
//Load history to receiver
|
||||
ws_view_receiver_exit(app->ws_receiver);
|
||||
for(uint8_t i = 0; i < ws_history_get_item(app->txrx->history); i++) {
|
||||
furi_string_reset(str_buff);
|
||||
ws_history_get_text_item_menu(app->txrx->history, str_buff, i);
|
||||
ws_view_receiver_add_item_to_menu(
|
||||
app->ws_receiver,
|
||||
furi_string_get_cstr(str_buff),
|
||||
ws_history_get_type_protocol(app->txrx->history, i));
|
||||
app->txrx->rx_key_state = WSRxKeyStateAddKey;
|
||||
}
|
||||
furi_string_free(str_buff);
|
||||
weather_station_scene_receiver_update_statusbar(app);
|
||||
|
||||
ws_view_receiver_set_callback(app->ws_receiver, weather_station_scene_receiver_callback, app);
|
||||
subghz_receiver_set_rx_callback(
|
||||
app->txrx->receiver, weather_station_scene_receiver_add_to_history_callback, app);
|
||||
|
||||
if(app->txrx->txrx_state == WSTxRxStateRx) {
|
||||
ws_rx_end(app);
|
||||
};
|
||||
if((app->txrx->txrx_state == WSTxRxStateIDLE) || (app->txrx->txrx_state == WSTxRxStateSleep)) {
|
||||
ws_begin(
|
||||
app,
|
||||
subghz_setting_get_preset_data_by_name(
|
||||
app->setting, furi_string_get_cstr(app->txrx->preset->name)));
|
||||
|
||||
ws_rx(app, app->txrx->preset->frequency);
|
||||
}
|
||||
|
||||
ws_view_receiver_set_idx_menu(app->ws_receiver, app->txrx->idx_menu_chosen);
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, WeatherStationViewReceiver);
|
||||
}
|
||||
|
||||
bool weather_station_scene_receiver_on_event(void* context, SceneManagerEvent event) {
|
||||
WeatherStationApp* app = context;
|
||||
bool consumed = false;
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
switch(event.event) {
|
||||
case WSCustomEventViewReceiverBack:
|
||||
// Stop CC1101 Rx
|
||||
if(app->txrx->txrx_state == WSTxRxStateRx) {
|
||||
ws_rx_end(app);
|
||||
ws_sleep(app);
|
||||
};
|
||||
app->txrx->hopper_state = WSHopperStateOFF;
|
||||
app->txrx->idx_menu_chosen = 0;
|
||||
subghz_receiver_set_rx_callback(app->txrx->receiver, NULL, app);
|
||||
|
||||
app->txrx->rx_key_state = WSRxKeyStateIDLE;
|
||||
ws_preset_init(
|
||||
app, "AM650", subghz_setting_get_default_frequency(app->setting), NULL, 0);
|
||||
scene_manager_search_and_switch_to_previous_scene(
|
||||
app->scene_manager, WeatherStationSceneStart);
|
||||
consumed = true;
|
||||
break;
|
||||
case WSCustomEventViewReceiverOK:
|
||||
app->txrx->idx_menu_chosen = ws_view_receiver_get_idx_menu(app->ws_receiver);
|
||||
scene_manager_next_scene(app->scene_manager, WeatherStationSceneReceiverInfo);
|
||||
consumed = true;
|
||||
break;
|
||||
case WSCustomEventViewReceiverConfig:
|
||||
app->txrx->idx_menu_chosen = ws_view_receiver_get_idx_menu(app->ws_receiver);
|
||||
scene_manager_next_scene(app->scene_manager, WeatherStationSceneReceiverConfig);
|
||||
consumed = true;
|
||||
break;
|
||||
case WSCustomEventViewReceiverOffDisplay:
|
||||
notification_message(app->notifications, &sequence_display_backlight_off);
|
||||
consumed = true;
|
||||
break;
|
||||
case WSCustomEventViewReceiverUnlock:
|
||||
app->lock = WSLockOff;
|
||||
consumed = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if(event.type == SceneManagerEventTypeTick) {
|
||||
if(app->txrx->hopper_state != WSHopperStateOFF) {
|
||||
ws_hopper_update(app);
|
||||
weather_station_scene_receiver_update_statusbar(app);
|
||||
}
|
||||
// Get current RSSI
|
||||
float rssi = furi_hal_subghz_get_rssi();
|
||||
ws_view_receiver_set_rssi(app->ws_receiver, rssi);
|
||||
|
||||
if(app->txrx->txrx_state == WSTxRxStateRx) {
|
||||
notification_message(app->notifications, &sequence_blink_cyan_10);
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void weather_station_scene_receiver_on_exit(void* context) {
|
||||
UNUSED(context);
|
||||
}
|
||||
30
applications/external/weather_station/scenes/weather_station_scene.c
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "../weather_station_app_i.h"
|
||||
|
||||
// Generate scene on_enter handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
|
||||
void (*const weather_station_scene_on_enter_handlers[])(void*) = {
|
||||
#include "weather_station_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_event handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
|
||||
bool (*const weather_station_scene_on_event_handlers[])(void* context, SceneManagerEvent event) = {
|
||||
#include "weather_station_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_exit handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
|
||||
void (*const weather_station_scene_on_exit_handlers[])(void* context) = {
|
||||
#include "weather_station_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Initialize scene handlers configuration structure
|
||||
const SceneManagerHandlers weather_station_scene_handlers = {
|
||||
.on_enter_handlers = weather_station_scene_on_enter_handlers,
|
||||
.on_event_handlers = weather_station_scene_on_event_handlers,
|
||||
.on_exit_handlers = weather_station_scene_on_exit_handlers,
|
||||
.scene_num = WeatherStationSceneNum,
|
||||
};
|
||||
29
applications/external/weather_station/scenes/weather_station_scene.h
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/scene_manager.h>
|
||||
|
||||
// Generate scene id and total number
|
||||
#define ADD_SCENE(prefix, name, id) WeatherStationScene##id,
|
||||
typedef enum {
|
||||
#include "weather_station_scene_config.h"
|
||||
WeatherStationSceneNum,
|
||||
} WeatherStationScene;
|
||||
#undef ADD_SCENE
|
||||
|
||||
extern const SceneManagerHandlers weather_station_scene_handlers;
|
||||
|
||||
// Generate scene on_enter handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
|
||||
#include "weather_station_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_event handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) \
|
||||
bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event);
|
||||
#include "weather_station_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_exit handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context);
|
||||
#include "weather_station_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
78
applications/external/weather_station/scenes/weather_station_scene_about.c
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
#include "../weather_station_app_i.h"
|
||||
#include "../helpers/weather_station_types.h"
|
||||
|
||||
void weather_station_scene_about_widget_callback(
|
||||
GuiButtonType result,
|
||||
InputType type,
|
||||
void* context) {
|
||||
WeatherStationApp* app = context;
|
||||
if(type == InputTypeShort) {
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, result);
|
||||
}
|
||||
}
|
||||
|
||||
void weather_station_scene_about_on_enter(void* context) {
|
||||
WeatherStationApp* app = context;
|
||||
|
||||
FuriString* temp_str;
|
||||
temp_str = furi_string_alloc();
|
||||
furi_string_printf(temp_str, "\e#%s\n", "Information");
|
||||
|
||||
furi_string_cat_printf(temp_str, "Version: %s\n", WS_VERSION_APP);
|
||||
furi_string_cat_printf(temp_str, "Developed by: %s\n", WS_DEVELOPED);
|
||||
furi_string_cat_printf(temp_str, "Github: %s\n\n", WS_GITHUB);
|
||||
|
||||
furi_string_cat_printf(temp_str, "\e#%s\n", "Description");
|
||||
furi_string_cat_printf(
|
||||
temp_str, "Reading messages from\nweather stations that work\nwith SubGhz sensors\n\n");
|
||||
|
||||
furi_string_cat_printf(temp_str, "Supported protocols:\n");
|
||||
size_t i = 0;
|
||||
const char* protocol_name =
|
||||
subghz_environment_get_protocol_name_registry(app->txrx->environment, i++);
|
||||
do {
|
||||
furi_string_cat_printf(temp_str, "%s\n", protocol_name);
|
||||
protocol_name = subghz_environment_get_protocol_name_registry(app->txrx->environment, i++);
|
||||
} while(protocol_name != NULL);
|
||||
|
||||
widget_add_text_box_element(
|
||||
app->widget,
|
||||
0,
|
||||
0,
|
||||
128,
|
||||
14,
|
||||
AlignCenter,
|
||||
AlignBottom,
|
||||
"\e#\e! \e!\n",
|
||||
false);
|
||||
widget_add_text_box_element(
|
||||
app->widget,
|
||||
0,
|
||||
2,
|
||||
128,
|
||||
14,
|
||||
AlignCenter,
|
||||
AlignBottom,
|
||||
"\e#\e! Weather station \e!\n",
|
||||
false);
|
||||
widget_add_text_scroll_element(app->widget, 0, 16, 128, 50, furi_string_get_cstr(temp_str));
|
||||
furi_string_free(temp_str);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, WeatherStationViewWidget);
|
||||
}
|
||||
|
||||
bool weather_station_scene_about_on_event(void* context, SceneManagerEvent event) {
|
||||
WeatherStationApp* app = context;
|
||||
bool consumed = false;
|
||||
UNUSED(app);
|
||||
UNUSED(event);
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void weather_station_scene_about_on_exit(void* context) {
|
||||
WeatherStationApp* app = context;
|
||||
|
||||
// Clear views
|
||||
widget_reset(app->widget);
|
||||
}
|
||||
5
applications/external/weather_station/scenes/weather_station_scene_config.h
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
ADD_SCENE(weather_station, start, Start)
|
||||
ADD_SCENE(weather_station, about, About)
|
||||
ADD_SCENE(weather_station, receiver, Receiver)
|
||||
ADD_SCENE(weather_station, receiver_config, ReceiverConfig)
|
||||
ADD_SCENE(weather_station, receiver_info, ReceiverInfo)
|
||||
223
applications/external/weather_station/scenes/weather_station_scene_receiver_config.c
vendored
Normal file
@@ -0,0 +1,223 @@
|
||||
#include "../weather_station_app_i.h"
|
||||
|
||||
enum WSSettingIndex {
|
||||
WSSettingIndexFrequency,
|
||||
WSSettingIndexHopping,
|
||||
WSSettingIndexModulation,
|
||||
WSSettingIndexLock,
|
||||
};
|
||||
|
||||
#define HOPPING_COUNT 2
|
||||
const char* const hopping_text[HOPPING_COUNT] = {
|
||||
"OFF",
|
||||
"ON",
|
||||
};
|
||||
const uint32_t hopping_value[HOPPING_COUNT] = {
|
||||
WSHopperStateOFF,
|
||||
WSHopperStateRunnig,
|
||||
};
|
||||
|
||||
uint8_t weather_station_scene_receiver_config_next_frequency(const uint32_t value, void* context) {
|
||||
furi_assert(context);
|
||||
WeatherStationApp* app = context;
|
||||
uint8_t index = 0;
|
||||
for(uint8_t i = 0; i < subghz_setting_get_frequency_count(app->setting); i++) {
|
||||
if(value == subghz_setting_get_frequency(app->setting, i)) {
|
||||
index = i;
|
||||
break;
|
||||
} else {
|
||||
index = subghz_setting_get_frequency_default_index(app->setting);
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
uint8_t weather_station_scene_receiver_config_next_preset(const char* preset_name, void* context) {
|
||||
furi_assert(context);
|
||||
WeatherStationApp* app = context;
|
||||
uint8_t index = 0;
|
||||
for(uint8_t i = 0; i < subghz_setting_get_preset_count(app->setting); i++) {
|
||||
if(!strcmp(subghz_setting_get_preset_name(app->setting, i), preset_name)) {
|
||||
index = i;
|
||||
break;
|
||||
} else {
|
||||
// index = subghz_setting_get_frequency_default_index(app ->setting);
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
uint8_t weather_station_scene_receiver_config_hopper_value_index(
|
||||
const uint32_t value,
|
||||
const uint32_t values[],
|
||||
uint8_t values_count,
|
||||
void* context) {
|
||||
furi_assert(context);
|
||||
UNUSED(values_count);
|
||||
WeatherStationApp* app = context;
|
||||
|
||||
if(value == values[0]) {
|
||||
return 0;
|
||||
} else {
|
||||
variable_item_set_current_value_text(
|
||||
(VariableItem*)scene_manager_get_scene_state(
|
||||
app->scene_manager, WeatherStationSceneReceiverConfig),
|
||||
" -----");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void weather_station_scene_receiver_config_set_frequency(VariableItem* item) {
|
||||
WeatherStationApp* app = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
|
||||
if(app->txrx->hopper_state == WSHopperStateOFF) {
|
||||
char text_buf[10] = {0};
|
||||
snprintf(
|
||||
text_buf,
|
||||
sizeof(text_buf),
|
||||
"%lu.%02lu",
|
||||
subghz_setting_get_frequency(app->setting, index) / 1000000,
|
||||
(subghz_setting_get_frequency(app->setting, index) % 1000000) / 10000);
|
||||
variable_item_set_current_value_text(item, text_buf);
|
||||
app->txrx->preset->frequency = subghz_setting_get_frequency(app->setting, index);
|
||||
} else {
|
||||
variable_item_set_current_value_index(
|
||||
item, subghz_setting_get_frequency_default_index(app->setting));
|
||||
}
|
||||
}
|
||||
|
||||
static void weather_station_scene_receiver_config_set_preset(VariableItem* item) {
|
||||
WeatherStationApp* app = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
variable_item_set_current_value_text(
|
||||
item, subghz_setting_get_preset_name(app->setting, index));
|
||||
ws_preset_init(
|
||||
app,
|
||||
subghz_setting_get_preset_name(app->setting, index),
|
||||
app->txrx->preset->frequency,
|
||||
subghz_setting_get_preset_data(app->setting, index),
|
||||
subghz_setting_get_preset_data_size(app->setting, index));
|
||||
}
|
||||
|
||||
static void weather_station_scene_receiver_config_set_hopping_running(VariableItem* item) {
|
||||
WeatherStationApp* app = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
|
||||
variable_item_set_current_value_text(item, hopping_text[index]);
|
||||
if(hopping_value[index] == WSHopperStateOFF) {
|
||||
char text_buf[10] = {0};
|
||||
snprintf(
|
||||
text_buf,
|
||||
sizeof(text_buf),
|
||||
"%lu.%02lu",
|
||||
subghz_setting_get_default_frequency(app->setting) / 1000000,
|
||||
(subghz_setting_get_default_frequency(app->setting) % 1000000) / 10000);
|
||||
variable_item_set_current_value_text(
|
||||
(VariableItem*)scene_manager_get_scene_state(
|
||||
app->scene_manager, WeatherStationSceneReceiverConfig),
|
||||
text_buf);
|
||||
app->txrx->preset->frequency = subghz_setting_get_default_frequency(app->setting);
|
||||
variable_item_set_current_value_index(
|
||||
(VariableItem*)scene_manager_get_scene_state(
|
||||
app->scene_manager, WeatherStationSceneReceiverConfig),
|
||||
subghz_setting_get_frequency_default_index(app->setting));
|
||||
} else {
|
||||
variable_item_set_current_value_text(
|
||||
(VariableItem*)scene_manager_get_scene_state(
|
||||
app->scene_manager, WeatherStationSceneReceiverConfig),
|
||||
" -----");
|
||||
variable_item_set_current_value_index(
|
||||
(VariableItem*)scene_manager_get_scene_state(
|
||||
app->scene_manager, WeatherStationSceneReceiverConfig),
|
||||
subghz_setting_get_frequency_default_index(app->setting));
|
||||
}
|
||||
|
||||
app->txrx->hopper_state = hopping_value[index];
|
||||
}
|
||||
|
||||
static void
|
||||
weather_station_scene_receiver_config_var_list_enter_callback(void* context, uint32_t index) {
|
||||
furi_assert(context);
|
||||
WeatherStationApp* app = context;
|
||||
if(index == WSSettingIndexLock) {
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, WSCustomEventSceneSettingLock);
|
||||
}
|
||||
}
|
||||
|
||||
void weather_station_scene_receiver_config_on_enter(void* context) {
|
||||
WeatherStationApp* app = context;
|
||||
VariableItem* item;
|
||||
uint8_t value_index;
|
||||
|
||||
item = variable_item_list_add(
|
||||
app->variable_item_list,
|
||||
"Frequency:",
|
||||
subghz_setting_get_frequency_count(app->setting),
|
||||
weather_station_scene_receiver_config_set_frequency,
|
||||
app);
|
||||
value_index =
|
||||
weather_station_scene_receiver_config_next_frequency(app->txrx->preset->frequency, app);
|
||||
scene_manager_set_scene_state(
|
||||
app->scene_manager, WeatherStationSceneReceiverConfig, (uint32_t)item);
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
char text_buf[10] = {0};
|
||||
snprintf(
|
||||
text_buf,
|
||||
sizeof(text_buf),
|
||||
"%lu.%02lu",
|
||||
subghz_setting_get_frequency(app->setting, value_index) / 1000000,
|
||||
(subghz_setting_get_frequency(app->setting, value_index) % 1000000) / 10000);
|
||||
variable_item_set_current_value_text(item, text_buf);
|
||||
|
||||
item = variable_item_list_add(
|
||||
app->variable_item_list,
|
||||
"Hopping:",
|
||||
HOPPING_COUNT,
|
||||
weather_station_scene_receiver_config_set_hopping_running,
|
||||
app);
|
||||
value_index = weather_station_scene_receiver_config_hopper_value_index(
|
||||
app->txrx->hopper_state, hopping_value, HOPPING_COUNT, app);
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, hopping_text[value_index]);
|
||||
|
||||
item = variable_item_list_add(
|
||||
app->variable_item_list,
|
||||
"Modulation:",
|
||||
subghz_setting_get_preset_count(app->setting),
|
||||
weather_station_scene_receiver_config_set_preset,
|
||||
app);
|
||||
value_index = weather_station_scene_receiver_config_next_preset(
|
||||
furi_string_get_cstr(app->txrx->preset->name), app);
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(
|
||||
item, subghz_setting_get_preset_name(app->setting, value_index));
|
||||
|
||||
variable_item_list_add(app->variable_item_list, "Lock Keyboard", 1, NULL, NULL);
|
||||
variable_item_list_set_enter_callback(
|
||||
app->variable_item_list,
|
||||
weather_station_scene_receiver_config_var_list_enter_callback,
|
||||
app);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, WeatherStationViewVariableItemList);
|
||||
}
|
||||
|
||||
bool weather_station_scene_receiver_config_on_event(void* context, SceneManagerEvent event) {
|
||||
WeatherStationApp* app = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == WSCustomEventSceneSettingLock) {
|
||||
app->lock = WSLockOn;
|
||||
scene_manager_previous_scene(app->scene_manager);
|
||||
consumed = true;
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void weather_station_scene_receiver_config_on_exit(void* context) {
|
||||
WeatherStationApp* app = context;
|
||||
variable_item_list_set_selected_item(app->variable_item_list, 0);
|
||||
variable_item_list_reset(app->variable_item_list);
|
||||
}
|
||||
50
applications/external/weather_station/scenes/weather_station_scene_receiver_info.c
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
#include "../weather_station_app_i.h"
|
||||
#include "../views/weather_station_receiver.h"
|
||||
|
||||
void weather_station_scene_receiver_info_callback(WSCustomEvent event, void* context) {
|
||||
furi_assert(context);
|
||||
WeatherStationApp* app = context;
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, event);
|
||||
}
|
||||
|
||||
static void weather_station_scene_receiver_info_add_to_history_callback(
|
||||
SubGhzReceiver* receiver,
|
||||
SubGhzProtocolDecoderBase* decoder_base,
|
||||
void* context) {
|
||||
furi_assert(context);
|
||||
WeatherStationApp* app = context;
|
||||
|
||||
if(ws_history_add_to_history(app->txrx->history, decoder_base, app->txrx->preset) ==
|
||||
WSHistoryStateAddKeyUpdateData) {
|
||||
ws_view_receiver_info_update(
|
||||
app->ws_receiver_info,
|
||||
ws_history_get_raw_data(app->txrx->history, app->txrx->idx_menu_chosen));
|
||||
subghz_receiver_reset(receiver);
|
||||
|
||||
notification_message(app->notifications, &sequence_blink_green_10);
|
||||
app->txrx->rx_key_state = WSRxKeyStateAddKey;
|
||||
}
|
||||
}
|
||||
|
||||
void weather_station_scene_receiver_info_on_enter(void* context) {
|
||||
WeatherStationApp* app = context;
|
||||
|
||||
subghz_receiver_set_rx_callback(
|
||||
app->txrx->receiver, weather_station_scene_receiver_info_add_to_history_callback, app);
|
||||
ws_view_receiver_info_update(
|
||||
app->ws_receiver_info,
|
||||
ws_history_get_raw_data(app->txrx->history, app->txrx->idx_menu_chosen));
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, WeatherStationViewReceiverInfo);
|
||||
}
|
||||
|
||||
bool weather_station_scene_receiver_info_on_event(void* context, SceneManagerEvent event) {
|
||||
WeatherStationApp* app = context;
|
||||
bool consumed = false;
|
||||
UNUSED(app);
|
||||
UNUSED(event);
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void weather_station_scene_receiver_info_on_exit(void* context) {
|
||||
UNUSED(context);
|
||||
}
|
||||
58
applications/external/weather_station/scenes/weather_station_scene_start.c
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
#include "../weather_station_app_i.h"
|
||||
|
||||
typedef enum {
|
||||
SubmenuIndexWeatherStationReceiver,
|
||||
SubmenuIndexWeatherStationAbout,
|
||||
} SubmenuIndex;
|
||||
|
||||
void weather_station_scene_start_submenu_callback(void* context, uint32_t index) {
|
||||
WeatherStationApp* app = context;
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, index);
|
||||
}
|
||||
|
||||
void weather_station_scene_start_on_enter(void* context) {
|
||||
UNUSED(context);
|
||||
WeatherStationApp* app = context;
|
||||
Submenu* submenu = app->submenu;
|
||||
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Read Weather Station",
|
||||
SubmenuIndexWeatherStationReceiver,
|
||||
weather_station_scene_start_submenu_callback,
|
||||
app);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"About",
|
||||
SubmenuIndexWeatherStationAbout,
|
||||
weather_station_scene_start_submenu_callback,
|
||||
app);
|
||||
|
||||
submenu_set_selected_item(
|
||||
submenu, scene_manager_get_scene_state(app->scene_manager, WeatherStationSceneStart));
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, WeatherStationViewSubmenu);
|
||||
}
|
||||
|
||||
bool weather_station_scene_start_on_event(void* context, SceneManagerEvent event) {
|
||||
WeatherStationApp* app = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubmenuIndexWeatherStationAbout) {
|
||||
scene_manager_next_scene(app->scene_manager, WeatherStationSceneAbout);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuIndexWeatherStationReceiver) {
|
||||
scene_manager_next_scene(app->scene_manager, WeatherStationSceneReceiver);
|
||||
consumed = true;
|
||||
}
|
||||
scene_manager_set_scene_state(app->scene_manager, WeatherStationSceneStart, event.event);
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void weather_station_scene_start_on_exit(void* context) {
|
||||
WeatherStationApp* app = context;
|
||||
submenu_reset(app->submenu);
|
||||
}
|
||||
464
applications/external/weather_station/views/weather_station_receiver.c
vendored
Normal file
@@ -0,0 +1,464 @@
|
||||
#include "weather_station_receiver.h"
|
||||
#include "../weather_station_app_i.h"
|
||||
#include <weather_station_icons.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <input/input.h>
|
||||
#include <gui/elements.h>
|
||||
#include <m-array.h>
|
||||
|
||||
#define FRAME_HEIGHT 12
|
||||
#define MAX_LEN_PX 112
|
||||
#define MENU_ITEMS 4u
|
||||
#define UNLOCK_CNT 3
|
||||
|
||||
#define SUBGHZ_RAW_TRESHOLD_MIN -90.0f
|
||||
typedef struct {
|
||||
FuriString* item_str;
|
||||
uint8_t type;
|
||||
} WSReceiverMenuItem;
|
||||
|
||||
ARRAY_DEF(WSReceiverMenuItemArray, WSReceiverMenuItem, M_POD_OPLIST)
|
||||
|
||||
#define M_OPL_WSReceiverMenuItemArray_t() ARRAY_OPLIST(WSReceiverMenuItemArray, M_POD_OPLIST)
|
||||
|
||||
struct WSReceiverHistory {
|
||||
WSReceiverMenuItemArray_t data;
|
||||
};
|
||||
|
||||
typedef struct WSReceiverHistory WSReceiverHistory;
|
||||
|
||||
static const Icon* ReceiverItemIcons[] = {
|
||||
[SubGhzProtocolTypeUnknown] = &I_Quest_7x8,
|
||||
[SubGhzProtocolTypeStatic] = &I_Unlock_7x8,
|
||||
[SubGhzProtocolTypeDynamic] = &I_Lock_7x8,
|
||||
[SubGhzProtocolWeatherStation] = &I_station_icon,
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
WSReceiverBarShowDefault,
|
||||
WSReceiverBarShowLock,
|
||||
WSReceiverBarShowToUnlockPress,
|
||||
WSReceiverBarShowUnlock,
|
||||
} WSReceiverBarShow;
|
||||
|
||||
struct WSReceiver {
|
||||
WSLock lock;
|
||||
uint8_t lock_count;
|
||||
FuriTimer* timer;
|
||||
View* view;
|
||||
WSReceiverCallback callback;
|
||||
void* context;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
FuriString* frequency_str;
|
||||
FuriString* preset_str;
|
||||
FuriString* history_stat_str;
|
||||
WSReceiverHistory* history;
|
||||
uint16_t idx;
|
||||
uint16_t list_offset;
|
||||
uint16_t history_item;
|
||||
WSReceiverBarShow bar_show;
|
||||
uint8_t u_rssi;
|
||||
} WSReceiverModel;
|
||||
|
||||
void ws_view_receiver_set_rssi(WSReceiver* instance, float rssi) {
|
||||
furi_assert(instance);
|
||||
with_view_model(
|
||||
instance->view,
|
||||
WSReceiverModel * model,
|
||||
{
|
||||
if(rssi < SUBGHZ_RAW_TRESHOLD_MIN) {
|
||||
model->u_rssi = 0;
|
||||
} else {
|
||||
model->u_rssi = (uint8_t)(rssi - SUBGHZ_RAW_TRESHOLD_MIN);
|
||||
}
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
void ws_view_receiver_set_lock(WSReceiver* ws_receiver, WSLock lock) {
|
||||
furi_assert(ws_receiver);
|
||||
ws_receiver->lock_count = 0;
|
||||
if(lock == WSLockOn) {
|
||||
ws_receiver->lock = lock;
|
||||
with_view_model(
|
||||
ws_receiver->view,
|
||||
WSReceiverModel * model,
|
||||
{ model->bar_show = WSReceiverBarShowLock; },
|
||||
true);
|
||||
furi_timer_start(ws_receiver->timer, pdMS_TO_TICKS(1000));
|
||||
} else {
|
||||
with_view_model(
|
||||
ws_receiver->view,
|
||||
WSReceiverModel * model,
|
||||
{ model->bar_show = WSReceiverBarShowDefault; },
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
||||
void ws_view_receiver_set_callback(
|
||||
WSReceiver* ws_receiver,
|
||||
WSReceiverCallback callback,
|
||||
void* context) {
|
||||
furi_assert(ws_receiver);
|
||||
furi_assert(callback);
|
||||
ws_receiver->callback = callback;
|
||||
ws_receiver->context = context;
|
||||
}
|
||||
|
||||
static void ws_view_receiver_update_offset(WSReceiver* ws_receiver) {
|
||||
furi_assert(ws_receiver);
|
||||
|
||||
with_view_model(
|
||||
ws_receiver->view,
|
||||
WSReceiverModel * model,
|
||||
{
|
||||
size_t history_item = model->history_item;
|
||||
uint16_t bounds = history_item > 3 ? 2 : history_item;
|
||||
|
||||
if(history_item > 3 && model->idx >= (int16_t)(history_item - 1)) {
|
||||
model->list_offset = model->idx - 3;
|
||||
} else if(model->list_offset < model->idx - bounds) {
|
||||
model->list_offset =
|
||||
CLAMP(model->list_offset + 1, (int16_t)(history_item - bounds), 0);
|
||||
} else if(model->list_offset > model->idx - bounds) {
|
||||
model->list_offset = CLAMP(model->idx - 1, (int16_t)(history_item - bounds), 0);
|
||||
}
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
void ws_view_receiver_add_item_to_menu(WSReceiver* ws_receiver, const char* name, uint8_t type) {
|
||||
furi_assert(ws_receiver);
|
||||
with_view_model(
|
||||
ws_receiver->view,
|
||||
WSReceiverModel * model,
|
||||
{
|
||||
WSReceiverMenuItem* item_menu = WSReceiverMenuItemArray_push_raw(model->history->data);
|
||||
item_menu->item_str = furi_string_alloc_set(name);
|
||||
item_menu->type = type;
|
||||
if((model->idx == model->history_item - 1)) {
|
||||
model->history_item++;
|
||||
model->idx++;
|
||||
} else {
|
||||
model->history_item++;
|
||||
}
|
||||
},
|
||||
true);
|
||||
ws_view_receiver_update_offset(ws_receiver);
|
||||
}
|
||||
|
||||
void ws_view_receiver_add_data_statusbar(
|
||||
WSReceiver* ws_receiver,
|
||||
const char* frequency_str,
|
||||
const char* preset_str,
|
||||
const char* history_stat_str) {
|
||||
furi_assert(ws_receiver);
|
||||
with_view_model(
|
||||
ws_receiver->view,
|
||||
WSReceiverModel * model,
|
||||
{
|
||||
furi_string_set_str(model->frequency_str, frequency_str);
|
||||
furi_string_set_str(model->preset_str, preset_str);
|
||||
furi_string_set_str(model->history_stat_str, history_stat_str);
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
static void ws_view_receiver_draw_frame(Canvas* canvas, uint16_t idx, bool scrollbar) {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_draw_box(canvas, 0, 0 + idx * FRAME_HEIGHT, scrollbar ? 122 : 127, FRAME_HEIGHT);
|
||||
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
canvas_draw_dot(canvas, 0, 0 + idx * FRAME_HEIGHT);
|
||||
canvas_draw_dot(canvas, 1, 0 + idx * FRAME_HEIGHT);
|
||||
canvas_draw_dot(canvas, 0, (0 + idx * FRAME_HEIGHT) + 1);
|
||||
|
||||
canvas_draw_dot(canvas, 0, (0 + idx * FRAME_HEIGHT) + 11);
|
||||
canvas_draw_dot(canvas, scrollbar ? 121 : 126, 0 + idx * FRAME_HEIGHT);
|
||||
canvas_draw_dot(canvas, scrollbar ? 121 : 126, (0 + idx * FRAME_HEIGHT) + 11);
|
||||
}
|
||||
|
||||
static void ws_view_rssi_draw(Canvas* canvas, WSReceiverModel* model) {
|
||||
for(uint8_t i = 1; i < model->u_rssi; i++) {
|
||||
if(i % 5) {
|
||||
canvas_draw_dot(canvas, 46 + i, 50);
|
||||
canvas_draw_dot(canvas, 47 + i, 51);
|
||||
canvas_draw_dot(canvas, 46 + i, 52);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ws_view_receiver_draw(Canvas* canvas, WSReceiverModel* model) {
|
||||
canvas_clear(canvas);
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
|
||||
elements_button_left(canvas, "Config");
|
||||
|
||||
bool scrollbar = model->history_item > 4;
|
||||
FuriString* str_buff;
|
||||
str_buff = furi_string_alloc();
|
||||
|
||||
WSReceiverMenuItem* item_menu;
|
||||
|
||||
for(size_t i = 0; i < MIN(model->history_item, MENU_ITEMS); ++i) {
|
||||
size_t idx = CLAMP((uint16_t)(i + model->list_offset), model->history_item, 0);
|
||||
item_menu = WSReceiverMenuItemArray_get(model->history->data, idx);
|
||||
furi_string_set(str_buff, item_menu->item_str);
|
||||
elements_string_fit_width(canvas, str_buff, scrollbar ? MAX_LEN_PX - 6 : MAX_LEN_PX);
|
||||
if(model->idx == idx) {
|
||||
ws_view_receiver_draw_frame(canvas, i, scrollbar);
|
||||
} else {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
}
|
||||
canvas_draw_icon(canvas, 4, 2 + i * FRAME_HEIGHT, ReceiverItemIcons[item_menu->type]);
|
||||
canvas_draw_str(canvas, 14, 9 + i * FRAME_HEIGHT, furi_string_get_cstr(str_buff));
|
||||
furi_string_reset(str_buff);
|
||||
}
|
||||
if(scrollbar) {
|
||||
elements_scrollbar_pos(canvas, 128, 0, 49, model->idx, model->history_item);
|
||||
}
|
||||
furi_string_free(str_buff);
|
||||
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
|
||||
if(model->history_item == 0) {
|
||||
canvas_draw_icon(canvas, 0, 0, &I_Scanning_123x52);
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str(canvas, 63, 46, "Scanning...");
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
}
|
||||
|
||||
// Draw RSSI
|
||||
ws_view_rssi_draw(canvas, model);
|
||||
|
||||
switch(model->bar_show) {
|
||||
case WSReceiverBarShowLock:
|
||||
canvas_draw_icon(canvas, 64, 55, &I_Lock_7x8);
|
||||
canvas_draw_str(canvas, 74, 62, "Locked");
|
||||
break;
|
||||
case WSReceiverBarShowToUnlockPress:
|
||||
canvas_draw_str(canvas, 44, 62, furi_string_get_cstr(model->frequency_str));
|
||||
canvas_draw_str(canvas, 79, 62, furi_string_get_cstr(model->preset_str));
|
||||
canvas_draw_str(canvas, 96, 62, furi_string_get_cstr(model->history_stat_str));
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
elements_bold_rounded_frame(canvas, 14, 8, 99, 48);
|
||||
elements_multiline_text(canvas, 65, 26, "To unlock\npress:");
|
||||
canvas_draw_icon(canvas, 65, 42, &I_Pin_back_arrow_10x8);
|
||||
canvas_draw_icon(canvas, 80, 42, &I_Pin_back_arrow_10x8);
|
||||
canvas_draw_icon(canvas, 95, 42, &I_Pin_back_arrow_10x8);
|
||||
canvas_draw_icon(canvas, 16, 13, &I_WarningDolphin_45x42);
|
||||
canvas_draw_dot(canvas, 17, 61);
|
||||
break;
|
||||
case WSReceiverBarShowUnlock:
|
||||
canvas_draw_icon(canvas, 64, 55, &I_Unlock_7x8);
|
||||
canvas_draw_str(canvas, 74, 62, "Unlocked");
|
||||
break;
|
||||
default:
|
||||
canvas_draw_str(canvas, 44, 62, furi_string_get_cstr(model->frequency_str));
|
||||
canvas_draw_str(canvas, 79, 62, furi_string_get_cstr(model->preset_str));
|
||||
canvas_draw_str(canvas, 96, 62, furi_string_get_cstr(model->history_stat_str));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void ws_view_receiver_timer_callback(void* context) {
|
||||
furi_assert(context);
|
||||
WSReceiver* ws_receiver = context;
|
||||
with_view_model(
|
||||
ws_receiver->view,
|
||||
WSReceiverModel * model,
|
||||
{ model->bar_show = WSReceiverBarShowDefault; },
|
||||
true);
|
||||
if(ws_receiver->lock_count < UNLOCK_CNT) {
|
||||
ws_receiver->callback(WSCustomEventViewReceiverOffDisplay, ws_receiver->context);
|
||||
} else {
|
||||
ws_receiver->lock = WSLockOff;
|
||||
ws_receiver->callback(WSCustomEventViewReceiverUnlock, ws_receiver->context);
|
||||
}
|
||||
ws_receiver->lock_count = 0;
|
||||
}
|
||||
|
||||
bool ws_view_receiver_input(InputEvent* event, void* context) {
|
||||
furi_assert(context);
|
||||
WSReceiver* ws_receiver = context;
|
||||
|
||||
if(ws_receiver->lock == WSLockOn) {
|
||||
with_view_model(
|
||||
ws_receiver->view,
|
||||
WSReceiverModel * model,
|
||||
{ model->bar_show = WSReceiverBarShowToUnlockPress; },
|
||||
true);
|
||||
if(ws_receiver->lock_count == 0) {
|
||||
furi_timer_start(ws_receiver->timer, pdMS_TO_TICKS(1000));
|
||||
}
|
||||
if(event->key == InputKeyBack && event->type == InputTypeShort) {
|
||||
ws_receiver->lock_count++;
|
||||
}
|
||||
if(ws_receiver->lock_count >= UNLOCK_CNT) {
|
||||
ws_receiver->callback(WSCustomEventViewReceiverUnlock, ws_receiver->context);
|
||||
with_view_model(
|
||||
ws_receiver->view,
|
||||
WSReceiverModel * model,
|
||||
{ model->bar_show = WSReceiverBarShowUnlock; },
|
||||
true);
|
||||
ws_receiver->lock = WSLockOff;
|
||||
furi_timer_start(ws_receiver->timer, pdMS_TO_TICKS(650));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if(event->key == InputKeyBack && event->type == InputTypeShort) {
|
||||
ws_receiver->callback(WSCustomEventViewReceiverBack, ws_receiver->context);
|
||||
} else if(
|
||||
event->key == InputKeyUp &&
|
||||
(event->type == InputTypeShort || event->type == InputTypeRepeat)) {
|
||||
with_view_model(
|
||||
ws_receiver->view,
|
||||
WSReceiverModel * model,
|
||||
{
|
||||
if(model->idx != 0) model->idx--;
|
||||
},
|
||||
true);
|
||||
} else if(
|
||||
event->key == InputKeyDown &&
|
||||
(event->type == InputTypeShort || event->type == InputTypeRepeat)) {
|
||||
with_view_model(
|
||||
ws_receiver->view,
|
||||
WSReceiverModel * model,
|
||||
{
|
||||
if(model->history_item && model->idx != model->history_item - 1) model->idx++;
|
||||
},
|
||||
true);
|
||||
} else if(event->key == InputKeyLeft && event->type == InputTypeShort) {
|
||||
ws_receiver->callback(WSCustomEventViewReceiverConfig, ws_receiver->context);
|
||||
} else if(event->key == InputKeyOk && event->type == InputTypeShort) {
|
||||
with_view_model(
|
||||
ws_receiver->view,
|
||||
WSReceiverModel * model,
|
||||
{
|
||||
if(model->history_item != 0) {
|
||||
ws_receiver->callback(WSCustomEventViewReceiverOK, ws_receiver->context);
|
||||
}
|
||||
},
|
||||
false);
|
||||
}
|
||||
|
||||
ws_view_receiver_update_offset(ws_receiver);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ws_view_receiver_enter(void* context) {
|
||||
furi_assert(context);
|
||||
}
|
||||
|
||||
void ws_view_receiver_exit(void* context) {
|
||||
furi_assert(context);
|
||||
WSReceiver* ws_receiver = context;
|
||||
with_view_model(
|
||||
ws_receiver->view,
|
||||
WSReceiverModel * model,
|
||||
{
|
||||
furi_string_reset(model->frequency_str);
|
||||
furi_string_reset(model->preset_str);
|
||||
furi_string_reset(model->history_stat_str);
|
||||
for
|
||||
M_EACH(item_menu, model->history->data, WSReceiverMenuItemArray_t) {
|
||||
furi_string_free(item_menu->item_str);
|
||||
item_menu->type = 0;
|
||||
}
|
||||
WSReceiverMenuItemArray_reset(model->history->data);
|
||||
model->idx = 0;
|
||||
model->list_offset = 0;
|
||||
model->history_item = 0;
|
||||
},
|
||||
false);
|
||||
furi_timer_stop(ws_receiver->timer);
|
||||
}
|
||||
|
||||
WSReceiver* ws_view_receiver_alloc() {
|
||||
WSReceiver* ws_receiver = malloc(sizeof(WSReceiver));
|
||||
|
||||
// View allocation and configuration
|
||||
ws_receiver->view = view_alloc();
|
||||
|
||||
ws_receiver->lock = WSLockOff;
|
||||
ws_receiver->lock_count = 0;
|
||||
view_allocate_model(ws_receiver->view, ViewModelTypeLocking, sizeof(WSReceiverModel));
|
||||
view_set_context(ws_receiver->view, ws_receiver);
|
||||
view_set_draw_callback(ws_receiver->view, (ViewDrawCallback)ws_view_receiver_draw);
|
||||
view_set_input_callback(ws_receiver->view, ws_view_receiver_input);
|
||||
view_set_enter_callback(ws_receiver->view, ws_view_receiver_enter);
|
||||
view_set_exit_callback(ws_receiver->view, ws_view_receiver_exit);
|
||||
|
||||
with_view_model(
|
||||
ws_receiver->view,
|
||||
WSReceiverModel * model,
|
||||
{
|
||||
model->frequency_str = furi_string_alloc();
|
||||
model->preset_str = furi_string_alloc();
|
||||
model->history_stat_str = furi_string_alloc();
|
||||
model->bar_show = WSReceiverBarShowDefault;
|
||||
model->history = malloc(sizeof(WSReceiverHistory));
|
||||
WSReceiverMenuItemArray_init(model->history->data);
|
||||
},
|
||||
true);
|
||||
ws_receiver->timer =
|
||||
furi_timer_alloc(ws_view_receiver_timer_callback, FuriTimerTypeOnce, ws_receiver);
|
||||
return ws_receiver;
|
||||
}
|
||||
|
||||
void ws_view_receiver_free(WSReceiver* ws_receiver) {
|
||||
furi_assert(ws_receiver);
|
||||
|
||||
with_view_model(
|
||||
ws_receiver->view,
|
||||
WSReceiverModel * model,
|
||||
{
|
||||
furi_string_free(model->frequency_str);
|
||||
furi_string_free(model->preset_str);
|
||||
furi_string_free(model->history_stat_str);
|
||||
for
|
||||
M_EACH(item_menu, model->history->data, WSReceiverMenuItemArray_t) {
|
||||
furi_string_free(item_menu->item_str);
|
||||
item_menu->type = 0;
|
||||
}
|
||||
WSReceiverMenuItemArray_clear(model->history->data);
|
||||
free(model->history);
|
||||
},
|
||||
false);
|
||||
furi_timer_free(ws_receiver->timer);
|
||||
view_free(ws_receiver->view);
|
||||
free(ws_receiver);
|
||||
}
|
||||
|
||||
View* ws_view_receiver_get_view(WSReceiver* ws_receiver) {
|
||||
furi_assert(ws_receiver);
|
||||
return ws_receiver->view;
|
||||
}
|
||||
|
||||
uint16_t ws_view_receiver_get_idx_menu(WSReceiver* ws_receiver) {
|
||||
furi_assert(ws_receiver);
|
||||
uint32_t idx = 0;
|
||||
with_view_model(
|
||||
ws_receiver->view, WSReceiverModel * model, { idx = model->idx; }, false);
|
||||
return idx;
|
||||
}
|
||||
|
||||
void ws_view_receiver_set_idx_menu(WSReceiver* ws_receiver, uint16_t idx) {
|
||||
furi_assert(ws_receiver);
|
||||
with_view_model(
|
||||
ws_receiver->view,
|
||||
WSReceiverModel * model,
|
||||
{
|
||||
model->idx = idx;
|
||||
if(model->idx > 2) model->list_offset = idx - 2;
|
||||
},
|
||||
true);
|
||||
ws_view_receiver_update_offset(ws_receiver);
|
||||
}
|
||||
38
applications/external/weather_station/views/weather_station_receiver.h
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
#include "../helpers/weather_station_types.h"
|
||||
#include "../helpers/weather_station_event.h"
|
||||
|
||||
typedef struct WSReceiver WSReceiver;
|
||||
|
||||
typedef void (*WSReceiverCallback)(WSCustomEvent event, void* context);
|
||||
|
||||
void ws_view_receiver_set_rssi(WSReceiver* instance, float rssi);
|
||||
|
||||
void ws_view_receiver_set_lock(WSReceiver* ws_receiver, WSLock keyboard);
|
||||
|
||||
void ws_view_receiver_set_callback(
|
||||
WSReceiver* ws_receiver,
|
||||
WSReceiverCallback callback,
|
||||
void* context);
|
||||
|
||||
WSReceiver* ws_view_receiver_alloc();
|
||||
|
||||
void ws_view_receiver_free(WSReceiver* ws_receiver);
|
||||
|
||||
View* ws_view_receiver_get_view(WSReceiver* ws_receiver);
|
||||
|
||||
void ws_view_receiver_add_data_statusbar(
|
||||
WSReceiver* ws_receiver,
|
||||
const char* frequency_str,
|
||||
const char* preset_str,
|
||||
const char* history_stat_str);
|
||||
|
||||
void ws_view_receiver_add_item_to_menu(WSReceiver* ws_receiver, const char* name, uint8_t type);
|
||||
|
||||
uint16_t ws_view_receiver_get_idx_menu(WSReceiver* ws_receiver);
|
||||
|
||||
void ws_view_receiver_set_idx_menu(WSReceiver* ws_receiver, uint16_t idx);
|
||||
|
||||
void ws_view_receiver_exit(void* context);
|
||||
245
applications/external/weather_station/views/weather_station_receiver_info.c
vendored
Normal file
@@ -0,0 +1,245 @@
|
||||
#include "weather_station_receiver.h"
|
||||
#include "../weather_station_app_i.h"
|
||||
#include "weather_station_icons.h"
|
||||
#include "../protocols/ws_generic.h"
|
||||
#include <input/input.h>
|
||||
#include <gui/elements.h>
|
||||
#include <float_tools.h>
|
||||
|
||||
struct WSReceiverInfo {
|
||||
View* view;
|
||||
FuriTimer* timer;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint32_t curr_ts;
|
||||
FuriString* protocol_name;
|
||||
WSBlockGeneric* generic;
|
||||
} WSReceiverInfoModel;
|
||||
|
||||
void ws_view_receiver_info_update(WSReceiverInfo* ws_receiver_info, FlipperFormat* fff) {
|
||||
furi_assert(ws_receiver_info);
|
||||
furi_assert(fff);
|
||||
|
||||
with_view_model(
|
||||
ws_receiver_info->view,
|
||||
WSReceiverInfoModel * model,
|
||||
{
|
||||
flipper_format_rewind(fff);
|
||||
flipper_format_read_string(fff, "Protocol", model->protocol_name);
|
||||
|
||||
ws_block_generic_deserialize(model->generic, fff);
|
||||
|
||||
FuriHalRtcDateTime curr_dt;
|
||||
furi_hal_rtc_get_datetime(&curr_dt);
|
||||
model->curr_ts = furi_hal_rtc_datetime_to_timestamp(&curr_dt);
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
void ws_view_receiver_info_draw(Canvas* canvas, WSReceiverInfoModel* model) {
|
||||
char buffer[64];
|
||||
canvas_clear(canvas);
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
|
||||
snprintf(
|
||||
buffer,
|
||||
sizeof(buffer),
|
||||
"%s %db",
|
||||
furi_string_get_cstr(model->protocol_name),
|
||||
model->generic->data_count_bit);
|
||||
canvas_draw_str(canvas, 0, 8, buffer);
|
||||
|
||||
if(model->generic->channel != WS_NO_CHANNEL) {
|
||||
snprintf(buffer, sizeof(buffer), "Ch: %01d", model->generic->channel);
|
||||
canvas_draw_str(canvas, 106, 8, buffer);
|
||||
}
|
||||
|
||||
if(model->generic->id != WS_NO_ID) {
|
||||
snprintf(buffer, sizeof(buffer), "Sn: 0x%02lX", model->generic->id);
|
||||
canvas_draw_str(canvas, 0, 20, buffer);
|
||||
}
|
||||
|
||||
if(model->generic->btn != WS_NO_BTN) {
|
||||
snprintf(buffer, sizeof(buffer), "Btn: %01d", model->generic->btn);
|
||||
canvas_draw_str(canvas, 57, 20, buffer);
|
||||
}
|
||||
|
||||
if(model->generic->battery_low != WS_NO_BATT) {
|
||||
snprintf(
|
||||
buffer, sizeof(buffer), "Batt: %s", (!model->generic->battery_low ? "ok" : "low"));
|
||||
canvas_draw_str_aligned(canvas, 126, 17, AlignRight, AlignCenter, buffer);
|
||||
}
|
||||
|
||||
snprintf(buffer, sizeof(buffer), "Data: 0x%llX", model->generic->data);
|
||||
canvas_draw_str(canvas, 0, 32, buffer);
|
||||
|
||||
elements_bold_rounded_frame(canvas, 0, 38, 127, 25);
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
|
||||
if(!float_is_equal(model->generic->temp, WS_NO_TEMPERATURE)) {
|
||||
canvas_draw_icon(canvas, 6, 43, &I_Therm_7x16);
|
||||
|
||||
uint8_t temp_x1 = 0;
|
||||
uint8_t temp_x2 = 0;
|
||||
if(furi_hal_rtc_get_locale_units() == FuriHalRtcLocaleUnitsMetric) {
|
||||
snprintf(buffer, sizeof(buffer), "%3.1f C", (double)model->generic->temp);
|
||||
if(model->generic->temp < -9.0f) {
|
||||
temp_x1 = 49;
|
||||
temp_x2 = 40;
|
||||
} else {
|
||||
temp_x1 = 47;
|
||||
temp_x2 = 38;
|
||||
}
|
||||
} else {
|
||||
snprintf(
|
||||
buffer,
|
||||
sizeof(buffer),
|
||||
"%3.1f F",
|
||||
(double)locale_celsius_to_fahrenheit(model->generic->temp));
|
||||
if((model->generic->temp < -27.77f) || (model->generic->temp > 37.77f)) {
|
||||
temp_x1 = 50;
|
||||
temp_x2 = 42;
|
||||
} else {
|
||||
temp_x1 = 48;
|
||||
temp_x2 = 40;
|
||||
}
|
||||
}
|
||||
|
||||
canvas_draw_str_aligned(canvas, temp_x1, 47, AlignRight, AlignTop, buffer);
|
||||
canvas_draw_circle(canvas, temp_x2, 46, 1);
|
||||
}
|
||||
|
||||
if(model->generic->humidity != WS_NO_HUMIDITY) {
|
||||
canvas_draw_icon(canvas, 53, 44, &I_Humid_8x13);
|
||||
snprintf(buffer, sizeof(buffer), "%d%%", model->generic->humidity);
|
||||
canvas_draw_str(canvas, 64, 55, buffer);
|
||||
}
|
||||
|
||||
if((int)model->generic->timestamp > 0 && model->curr_ts) {
|
||||
int ts_diff = (int)model->curr_ts - (int)model->generic->timestamp;
|
||||
|
||||
canvas_draw_icon(canvas, 91, 46, &I_Timer_11x11);
|
||||
|
||||
if(ts_diff > 60) {
|
||||
int tmp_sec = ts_diff;
|
||||
int cnt_min = 1;
|
||||
for(int i = 1; tmp_sec > 60; i++) {
|
||||
tmp_sec = tmp_sec - 60;
|
||||
cnt_min = i;
|
||||
}
|
||||
|
||||
if(model->curr_ts % 2 == 0) {
|
||||
canvas_draw_str_aligned(canvas, 105, 51, AlignLeft, AlignCenter, "Old");
|
||||
} else {
|
||||
if(cnt_min >= 59) {
|
||||
canvas_draw_str_aligned(canvas, 105, 51, AlignLeft, AlignCenter, "Old");
|
||||
} else {
|
||||
snprintf(buffer, sizeof(buffer), "%dm", cnt_min);
|
||||
canvas_draw_str_aligned(canvas, 114, 51, AlignCenter, AlignCenter, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
snprintf(buffer, sizeof(buffer), "%d", ts_diff);
|
||||
canvas_draw_str_aligned(canvas, 112, 51, AlignCenter, AlignCenter, buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ws_view_receiver_info_input(InputEvent* event, void* context) {
|
||||
furi_assert(context);
|
||||
//WSReceiverInfo* ws_receiver_info = context;
|
||||
|
||||
if(event->key == InputKeyBack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void ws_view_receiver_info_enter(void* context) {
|
||||
furi_assert(context);
|
||||
WSReceiverInfo* ws_receiver_info = context;
|
||||
|
||||
furi_timer_start(ws_receiver_info->timer, 1000);
|
||||
}
|
||||
|
||||
static void ws_view_receiver_info_exit(void* context) {
|
||||
furi_assert(context);
|
||||
WSReceiverInfo* ws_receiver_info = context;
|
||||
|
||||
furi_timer_stop(ws_receiver_info->timer);
|
||||
|
||||
with_view_model(
|
||||
ws_receiver_info->view,
|
||||
WSReceiverInfoModel * model,
|
||||
{ furi_string_reset(model->protocol_name); },
|
||||
false);
|
||||
}
|
||||
|
||||
static void ws_view_receiver_info_timer(void* context) {
|
||||
WSReceiverInfo* ws_receiver_info = context;
|
||||
// Force redraw
|
||||
with_view_model(
|
||||
ws_receiver_info->view,
|
||||
WSReceiverInfoModel * model,
|
||||
{
|
||||
FuriHalRtcDateTime curr_dt;
|
||||
furi_hal_rtc_get_datetime(&curr_dt);
|
||||
model->curr_ts = furi_hal_rtc_datetime_to_timestamp(&curr_dt);
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
WSReceiverInfo* ws_view_receiver_info_alloc() {
|
||||
WSReceiverInfo* ws_receiver_info = malloc(sizeof(WSReceiverInfo));
|
||||
|
||||
// View allocation and configuration
|
||||
ws_receiver_info->view = view_alloc();
|
||||
|
||||
view_allocate_model(ws_receiver_info->view, ViewModelTypeLocking, sizeof(WSReceiverInfoModel));
|
||||
view_set_context(ws_receiver_info->view, ws_receiver_info);
|
||||
view_set_draw_callback(ws_receiver_info->view, (ViewDrawCallback)ws_view_receiver_info_draw);
|
||||
view_set_input_callback(ws_receiver_info->view, ws_view_receiver_info_input);
|
||||
view_set_enter_callback(ws_receiver_info->view, ws_view_receiver_info_enter);
|
||||
view_set_exit_callback(ws_receiver_info->view, ws_view_receiver_info_exit);
|
||||
|
||||
with_view_model(
|
||||
ws_receiver_info->view,
|
||||
WSReceiverInfoModel * model,
|
||||
{
|
||||
model->generic = malloc(sizeof(WSBlockGeneric));
|
||||
model->protocol_name = furi_string_alloc();
|
||||
},
|
||||
true);
|
||||
|
||||
ws_receiver_info->timer =
|
||||
furi_timer_alloc(ws_view_receiver_info_timer, FuriTimerTypePeriodic, ws_receiver_info);
|
||||
|
||||
return ws_receiver_info;
|
||||
}
|
||||
|
||||
void ws_view_receiver_info_free(WSReceiverInfo* ws_receiver_info) {
|
||||
furi_assert(ws_receiver_info);
|
||||
|
||||
furi_timer_free(ws_receiver_info->timer);
|
||||
|
||||
with_view_model(
|
||||
ws_receiver_info->view,
|
||||
WSReceiverInfoModel * model,
|
||||
{
|
||||
furi_string_free(model->protocol_name);
|
||||
free(model->generic);
|
||||
},
|
||||
false);
|
||||
|
||||
view_free(ws_receiver_info->view);
|
||||
free(ws_receiver_info);
|
||||
}
|
||||
|
||||
View* ws_view_receiver_info_get_view(WSReceiverInfo* ws_receiver_info) {
|
||||
furi_assert(ws_receiver_info);
|
||||
return ws_receiver_info->view;
|
||||
}
|
||||
16
applications/external/weather_station/views/weather_station_receiver_info.h
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
#include "../helpers/weather_station_types.h"
|
||||
#include "../helpers/weather_station_event.h"
|
||||
#include <lib/flipper_format/flipper_format.h>
|
||||
|
||||
typedef struct WSReceiverInfo WSReceiverInfo;
|
||||
|
||||
void ws_view_receiver_info_update(WSReceiverInfo* ws_receiver_info, FlipperFormat* fff);
|
||||
|
||||
WSReceiverInfo* ws_view_receiver_info_alloc();
|
||||
|
||||
void ws_view_receiver_info_free(WSReceiverInfo* ws_receiver_info);
|
||||
|
||||
View* ws_view_receiver_info_get_view(WSReceiverInfo* ws_receiver_info);
|
||||
BIN
applications/external/weather_station/weather_station_10px.png
vendored
Normal file
|
After Width: | Height: | Size: 175 B |
178
applications/external/weather_station/weather_station_app.c
vendored
Normal file
@@ -0,0 +1,178 @@
|
||||
#include "weather_station_app_i.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include "protocols/protocol_items.h"
|
||||
|
||||
static bool weather_station_app_custom_event_callback(void* context, uint32_t event) {
|
||||
furi_assert(context);
|
||||
WeatherStationApp* app = context;
|
||||
return scene_manager_handle_custom_event(app->scene_manager, event);
|
||||
}
|
||||
|
||||
static bool weather_station_app_back_event_callback(void* context) {
|
||||
furi_assert(context);
|
||||
WeatherStationApp* app = context;
|
||||
return scene_manager_handle_back_event(app->scene_manager);
|
||||
}
|
||||
|
||||
static void weather_station_app_tick_event_callback(void* context) {
|
||||
furi_assert(context);
|
||||
WeatherStationApp* app = context;
|
||||
scene_manager_handle_tick_event(app->scene_manager);
|
||||
}
|
||||
|
||||
WeatherStationApp* weather_station_app_alloc() {
|
||||
WeatherStationApp* app = malloc(sizeof(WeatherStationApp));
|
||||
|
||||
// GUI
|
||||
app->gui = furi_record_open(RECORD_GUI);
|
||||
|
||||
// View Dispatcher
|
||||
app->view_dispatcher = view_dispatcher_alloc();
|
||||
app->scene_manager = scene_manager_alloc(&weather_station_scene_handlers, app);
|
||||
view_dispatcher_enable_queue(app->view_dispatcher);
|
||||
|
||||
view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
|
||||
view_dispatcher_set_custom_event_callback(
|
||||
app->view_dispatcher, weather_station_app_custom_event_callback);
|
||||
view_dispatcher_set_navigation_event_callback(
|
||||
app->view_dispatcher, weather_station_app_back_event_callback);
|
||||
view_dispatcher_set_tick_event_callback(
|
||||
app->view_dispatcher, weather_station_app_tick_event_callback, 100);
|
||||
|
||||
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
|
||||
|
||||
// Open Notification record
|
||||
app->notifications = furi_record_open(RECORD_NOTIFICATION);
|
||||
|
||||
// Variable Item List
|
||||
app->variable_item_list = variable_item_list_alloc();
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher,
|
||||
WeatherStationViewVariableItemList,
|
||||
variable_item_list_get_view(app->variable_item_list));
|
||||
|
||||
// SubMenu
|
||||
app->submenu = submenu_alloc();
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher, WeatherStationViewSubmenu, submenu_get_view(app->submenu));
|
||||
|
||||
// Widget
|
||||
app->widget = widget_alloc();
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher, WeatherStationViewWidget, widget_get_view(app->widget));
|
||||
|
||||
// Receiver
|
||||
app->ws_receiver = ws_view_receiver_alloc();
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher,
|
||||
WeatherStationViewReceiver,
|
||||
ws_view_receiver_get_view(app->ws_receiver));
|
||||
|
||||
// Receiver Info
|
||||
app->ws_receiver_info = ws_view_receiver_info_alloc();
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher,
|
||||
WeatherStationViewReceiverInfo,
|
||||
ws_view_receiver_info_get_view(app->ws_receiver_info));
|
||||
|
||||
//init setting
|
||||
app->setting = subghz_setting_alloc();
|
||||
|
||||
//ToDo FIX file name setting
|
||||
subghz_setting_load(app->setting, EXT_PATH("subghz/assets/setting_user"));
|
||||
|
||||
//init Worker & Protocol & History
|
||||
app->lock = WSLockOff;
|
||||
app->txrx = malloc(sizeof(WeatherStationTxRx));
|
||||
app->txrx->preset = malloc(sizeof(SubGhzRadioPreset));
|
||||
app->txrx->preset->name = furi_string_alloc();
|
||||
ws_preset_init(app, "AM650", subghz_setting_get_default_frequency(app->setting), NULL, 0);
|
||||
|
||||
app->txrx->hopper_state = WSHopperStateOFF;
|
||||
app->txrx->history = ws_history_alloc();
|
||||
app->txrx->worker = subghz_worker_alloc();
|
||||
app->txrx->environment = subghz_environment_alloc();
|
||||
subghz_environment_set_protocol_registry(
|
||||
app->txrx->environment, (void*)&weather_station_protocol_registry);
|
||||
app->txrx->receiver = subghz_receiver_alloc_init(app->txrx->environment);
|
||||
|
||||
subghz_receiver_set_filter(app->txrx->receiver, SubGhzProtocolFlag_Decodable);
|
||||
subghz_worker_set_overrun_callback(
|
||||
app->txrx->worker, (SubGhzWorkerOverrunCallback)subghz_receiver_reset);
|
||||
subghz_worker_set_pair_callback(
|
||||
app->txrx->worker, (SubGhzWorkerPairCallback)subghz_receiver_decode);
|
||||
subghz_worker_set_context(app->txrx->worker, app->txrx->receiver);
|
||||
|
||||
furi_hal_power_suppress_charge_enter();
|
||||
|
||||
scene_manager_next_scene(app->scene_manager, WeatherStationSceneStart);
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
void weather_station_app_free(WeatherStationApp* app) {
|
||||
furi_assert(app);
|
||||
|
||||
//CC1101 off
|
||||
ws_sleep(app);
|
||||
|
||||
// Submenu
|
||||
view_dispatcher_remove_view(app->view_dispatcher, WeatherStationViewSubmenu);
|
||||
submenu_free(app->submenu);
|
||||
|
||||
// Variable Item List
|
||||
view_dispatcher_remove_view(app->view_dispatcher, WeatherStationViewVariableItemList);
|
||||
variable_item_list_free(app->variable_item_list);
|
||||
|
||||
// Widget
|
||||
view_dispatcher_remove_view(app->view_dispatcher, WeatherStationViewWidget);
|
||||
widget_free(app->widget);
|
||||
|
||||
// Receiver
|
||||
view_dispatcher_remove_view(app->view_dispatcher, WeatherStationViewReceiver);
|
||||
ws_view_receiver_free(app->ws_receiver);
|
||||
|
||||
// Receiver Info
|
||||
view_dispatcher_remove_view(app->view_dispatcher, WeatherStationViewReceiverInfo);
|
||||
ws_view_receiver_info_free(app->ws_receiver_info);
|
||||
|
||||
//setting
|
||||
subghz_setting_free(app->setting);
|
||||
|
||||
//Worker & Protocol & History
|
||||
subghz_receiver_free(app->txrx->receiver);
|
||||
subghz_environment_free(app->txrx->environment);
|
||||
ws_history_free(app->txrx->history);
|
||||
subghz_worker_free(app->txrx->worker);
|
||||
furi_string_free(app->txrx->preset->name);
|
||||
free(app->txrx->preset);
|
||||
free(app->txrx);
|
||||
|
||||
// View dispatcher
|
||||
view_dispatcher_free(app->view_dispatcher);
|
||||
scene_manager_free(app->scene_manager);
|
||||
|
||||
// Notifications
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
app->notifications = NULL;
|
||||
|
||||
// Close records
|
||||
furi_record_close(RECORD_GUI);
|
||||
|
||||
furi_hal_power_suppress_charge_exit();
|
||||
|
||||
free(app);
|
||||
}
|
||||
|
||||
int32_t weather_station_app(void* p) {
|
||||
UNUSED(p);
|
||||
WeatherStationApp* weather_station_app = weather_station_app_alloc();
|
||||
|
||||
view_dispatcher_run(weather_station_app->view_dispatcher);
|
||||
|
||||
weather_station_app_free(weather_station_app);
|
||||
|
||||
return 0;
|
||||
}
|
||||
156
applications/external/weather_station/weather_station_app_i.c
vendored
Normal file
@@ -0,0 +1,156 @@
|
||||
#include "weather_station_app_i.h"
|
||||
|
||||
#define TAG "WeatherStation"
|
||||
#include <flipper_format/flipper_format_i.h>
|
||||
|
||||
void ws_preset_init(
|
||||
void* context,
|
||||
const char* preset_name,
|
||||
uint32_t frequency,
|
||||
uint8_t* preset_data,
|
||||
size_t preset_data_size) {
|
||||
furi_assert(context);
|
||||
WeatherStationApp* app = context;
|
||||
furi_string_set(app->txrx->preset->name, preset_name);
|
||||
app->txrx->preset->frequency = frequency;
|
||||
app->txrx->preset->data = preset_data;
|
||||
app->txrx->preset->data_size = preset_data_size;
|
||||
}
|
||||
|
||||
bool ws_set_preset(WeatherStationApp* app, const char* preset) {
|
||||
if(!strcmp(preset, "FuriHalSubGhzPresetOok270Async")) {
|
||||
furi_string_set(app->txrx->preset->name, "AM270");
|
||||
} else if(!strcmp(preset, "FuriHalSubGhzPresetOok650Async")) {
|
||||
furi_string_set(app->txrx->preset->name, "AM650");
|
||||
} else if(!strcmp(preset, "FuriHalSubGhzPreset2FSKDev238Async")) {
|
||||
furi_string_set(app->txrx->preset->name, "FM238");
|
||||
} else if(!strcmp(preset, "FuriHalSubGhzPreset2FSKDev476Async")) {
|
||||
furi_string_set(app->txrx->preset->name, "FM476");
|
||||
} else if(!strcmp(preset, "FuriHalSubGhzPresetCustom")) {
|
||||
furi_string_set(app->txrx->preset->name, "CUSTOM");
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "Unknown preset");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ws_get_frequency_modulation(
|
||||
WeatherStationApp* app,
|
||||
FuriString* frequency,
|
||||
FuriString* modulation) {
|
||||
furi_assert(app);
|
||||
if(frequency != NULL) {
|
||||
furi_string_printf(
|
||||
frequency,
|
||||
"%03ld.%02ld",
|
||||
app->txrx->preset->frequency / 1000000 % 1000,
|
||||
app->txrx->preset->frequency / 10000 % 100);
|
||||
}
|
||||
if(modulation != NULL) {
|
||||
furi_string_printf(modulation, "%.2s", furi_string_get_cstr(app->txrx->preset->name));
|
||||
}
|
||||
}
|
||||
|
||||
void ws_begin(WeatherStationApp* app, uint8_t* preset_data) {
|
||||
furi_assert(app);
|
||||
UNUSED(preset_data);
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_idle();
|
||||
furi_hal_subghz_load_custom_preset(preset_data);
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
app->txrx->txrx_state = WSTxRxStateIDLE;
|
||||
}
|
||||
|
||||
uint32_t ws_rx(WeatherStationApp* app, uint32_t frequency) {
|
||||
furi_assert(app);
|
||||
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
|
||||
furi_crash("WeatherStation: Incorrect RX frequency.");
|
||||
}
|
||||
furi_assert(
|
||||
app->txrx->txrx_state != WSTxRxStateRx && app->txrx->txrx_state != WSTxRxStateSleep);
|
||||
|
||||
furi_hal_subghz_idle();
|
||||
uint32_t value = furi_hal_subghz_set_frequency_and_path(frequency);
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_subghz_flush_rx();
|
||||
furi_hal_subghz_rx();
|
||||
|
||||
furi_hal_subghz_start_async_rx(subghz_worker_rx_callback, app->txrx->worker);
|
||||
subghz_worker_start(app->txrx->worker);
|
||||
app->txrx->txrx_state = WSTxRxStateRx;
|
||||
return value;
|
||||
}
|
||||
|
||||
void ws_idle(WeatherStationApp* app) {
|
||||
furi_assert(app);
|
||||
furi_assert(app->txrx->txrx_state != WSTxRxStateSleep);
|
||||
furi_hal_subghz_idle();
|
||||
app->txrx->txrx_state = WSTxRxStateIDLE;
|
||||
}
|
||||
|
||||
void ws_rx_end(WeatherStationApp* app) {
|
||||
furi_assert(app);
|
||||
furi_assert(app->txrx->txrx_state == WSTxRxStateRx);
|
||||
if(subghz_worker_is_running(app->txrx->worker)) {
|
||||
subghz_worker_stop(app->txrx->worker);
|
||||
furi_hal_subghz_stop_async_rx();
|
||||
}
|
||||
furi_hal_subghz_idle();
|
||||
app->txrx->txrx_state = WSTxRxStateIDLE;
|
||||
}
|
||||
|
||||
void ws_sleep(WeatherStationApp* app) {
|
||||
furi_assert(app);
|
||||
furi_hal_subghz_sleep();
|
||||
app->txrx->txrx_state = WSTxRxStateSleep;
|
||||
}
|
||||
|
||||
void ws_hopper_update(WeatherStationApp* app) {
|
||||
furi_assert(app);
|
||||
|
||||
switch(app->txrx->hopper_state) {
|
||||
case WSHopperStateOFF:
|
||||
case WSHopperStatePause:
|
||||
return;
|
||||
case WSHopperStateRSSITimeOut:
|
||||
if(app->txrx->hopper_timeout != 0) {
|
||||
app->txrx->hopper_timeout--;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
float rssi = -127.0f;
|
||||
if(app->txrx->hopper_state != WSHopperStateRSSITimeOut) {
|
||||
// See RSSI Calculation timings in CC1101 17.3 RSSI
|
||||
rssi = furi_hal_subghz_get_rssi();
|
||||
|
||||
// Stay if RSSI is high enough
|
||||
if(rssi > -90.0f) {
|
||||
app->txrx->hopper_timeout = 10;
|
||||
app->txrx->hopper_state = WSHopperStateRSSITimeOut;
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
app->txrx->hopper_state = WSHopperStateRunnig;
|
||||
}
|
||||
// Select next frequency
|
||||
if(app->txrx->hopper_idx_frequency <
|
||||
subghz_setting_get_hopper_frequency_count(app->setting) - 1) {
|
||||
app->txrx->hopper_idx_frequency++;
|
||||
} else {
|
||||
app->txrx->hopper_idx_frequency = 0;
|
||||
}
|
||||
|
||||
if(app->txrx->txrx_state == WSTxRxStateRx) {
|
||||
ws_rx_end(app);
|
||||
};
|
||||
if(app->txrx->txrx_state == WSTxRxStateIDLE) {
|
||||
subghz_receiver_reset(app->txrx->receiver);
|
||||
app->txrx->preset->frequency =
|
||||
subghz_setting_get_hopper_frequency(app->setting, app->txrx->hopper_idx_frequency);
|
||||
ws_rx(app, app->txrx->preset->frequency);
|
||||
}
|
||||
}
|
||||
73
applications/external/weather_station/weather_station_app_i.h
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
#pragma once
|
||||
|
||||
#include "helpers/weather_station_types.h"
|
||||
|
||||
#include "scenes/weather_station_scene.h"
|
||||
#include <gui/gui.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
#include <gui/scene_manager.h>
|
||||
#include <gui/modules/submenu.h>
|
||||
#include <gui/modules/variable_item_list.h>
|
||||
#include <gui/modules/widget.h>
|
||||
#include <notification/notification_messages.h>
|
||||
#include "views/weather_station_receiver.h"
|
||||
#include "views/weather_station_receiver_info.h"
|
||||
#include "weather_station_history.h"
|
||||
|
||||
#include <lib/subghz/subghz_setting.h>
|
||||
#include <lib/subghz/subghz_worker.h>
|
||||
#include <lib/subghz/receiver.h>
|
||||
#include <lib/subghz/transmitter.h>
|
||||
#include <lib/subghz/registry.h>
|
||||
|
||||
typedef struct WeatherStationApp WeatherStationApp;
|
||||
|
||||
struct WeatherStationTxRx {
|
||||
SubGhzWorker* worker;
|
||||
|
||||
SubGhzEnvironment* environment;
|
||||
SubGhzReceiver* receiver;
|
||||
SubGhzRadioPreset* preset;
|
||||
WSHistory* history;
|
||||
uint16_t idx_menu_chosen;
|
||||
WSTxRxState txrx_state;
|
||||
WSHopperState hopper_state;
|
||||
uint8_t hopper_timeout;
|
||||
uint8_t hopper_idx_frequency;
|
||||
WSRxKeyState rx_key_state;
|
||||
};
|
||||
|
||||
typedef struct WeatherStationTxRx WeatherStationTxRx;
|
||||
|
||||
struct WeatherStationApp {
|
||||
Gui* gui;
|
||||
ViewDispatcher* view_dispatcher;
|
||||
WeatherStationTxRx* txrx;
|
||||
SceneManager* scene_manager;
|
||||
NotificationApp* notifications;
|
||||
VariableItemList* variable_item_list;
|
||||
Submenu* submenu;
|
||||
Widget* widget;
|
||||
WSReceiver* ws_receiver;
|
||||
WSReceiverInfo* ws_receiver_info;
|
||||
WSLock lock;
|
||||
SubGhzSetting* setting;
|
||||
};
|
||||
|
||||
void ws_preset_init(
|
||||
void* context,
|
||||
const char* preset_name,
|
||||
uint32_t frequency,
|
||||
uint8_t* preset_data,
|
||||
size_t preset_data_size);
|
||||
bool ws_set_preset(WeatherStationApp* app, const char* preset);
|
||||
void ws_get_frequency_modulation(
|
||||
WeatherStationApp* app,
|
||||
FuriString* frequency,
|
||||
FuriString* modulation);
|
||||
void ws_begin(WeatherStationApp* app, uint8_t* preset_data);
|
||||
uint32_t ws_rx(WeatherStationApp* app, uint32_t frequency);
|
||||
void ws_idle(WeatherStationApp* app);
|
||||
void ws_rx_end(WeatherStationApp* app);
|
||||
void ws_sleep(WeatherStationApp* app);
|
||||
void ws_hopper_update(WeatherStationApp* app);
|
||||
245
applications/external/weather_station/weather_station_history.c
vendored
Normal file
@@ -0,0 +1,245 @@
|
||||
#include "weather_station_history.h"
|
||||
#include <flipper_format/flipper_format_i.h>
|
||||
#include <lib/toolbox/stream/stream.h>
|
||||
#include <lib/subghz/receiver.h>
|
||||
#include "protocols/ws_generic.h"
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
#define WS_HISTORY_MAX 50
|
||||
#define TAG "WSHistory"
|
||||
|
||||
typedef struct {
|
||||
FuriString* item_str;
|
||||
FlipperFormat* flipper_string;
|
||||
uint8_t type;
|
||||
uint32_t id;
|
||||
SubGhzRadioPreset* preset;
|
||||
} WSHistoryItem;
|
||||
|
||||
ARRAY_DEF(WSHistoryItemArray, WSHistoryItem, M_POD_OPLIST)
|
||||
|
||||
#define M_OPL_WSHistoryItemArray_t() ARRAY_OPLIST(WSHistoryItemArray, M_POD_OPLIST)
|
||||
|
||||
typedef struct {
|
||||
WSHistoryItemArray_t data;
|
||||
} WSHistoryStruct;
|
||||
|
||||
struct WSHistory {
|
||||
uint32_t last_update_timestamp;
|
||||
uint16_t last_index_write;
|
||||
uint8_t code_last_hash_data;
|
||||
FuriString* tmp_string;
|
||||
WSHistoryStruct* history;
|
||||
};
|
||||
|
||||
WSHistory* ws_history_alloc(void) {
|
||||
WSHistory* instance = malloc(sizeof(WSHistory));
|
||||
instance->tmp_string = furi_string_alloc();
|
||||
instance->history = malloc(sizeof(WSHistoryStruct));
|
||||
WSHistoryItemArray_init(instance->history->data);
|
||||
return instance;
|
||||
}
|
||||
|
||||
void ws_history_free(WSHistory* instance) {
|
||||
furi_assert(instance);
|
||||
furi_string_free(instance->tmp_string);
|
||||
for
|
||||
M_EACH(item, instance->history->data, WSHistoryItemArray_t) {
|
||||
furi_string_free(item->item_str);
|
||||
furi_string_free(item->preset->name);
|
||||
free(item->preset);
|
||||
flipper_format_free(item->flipper_string);
|
||||
item->type = 0;
|
||||
}
|
||||
WSHistoryItemArray_clear(instance->history->data);
|
||||
free(instance->history);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
uint32_t ws_history_get_frequency(WSHistory* instance, uint16_t idx) {
|
||||
furi_assert(instance);
|
||||
WSHistoryItem* item = WSHistoryItemArray_get(instance->history->data, idx);
|
||||
return item->preset->frequency;
|
||||
}
|
||||
|
||||
SubGhzRadioPreset* ws_history_get_radio_preset(WSHistory* instance, uint16_t idx) {
|
||||
furi_assert(instance);
|
||||
WSHistoryItem* item = WSHistoryItemArray_get(instance->history->data, idx);
|
||||
return item->preset;
|
||||
}
|
||||
|
||||
const char* ws_history_get_preset(WSHistory* instance, uint16_t idx) {
|
||||
furi_assert(instance);
|
||||
WSHistoryItem* item = WSHistoryItemArray_get(instance->history->data, idx);
|
||||
return furi_string_get_cstr(item->preset->name);
|
||||
}
|
||||
|
||||
void ws_history_reset(WSHistory* instance) {
|
||||
furi_assert(instance);
|
||||
furi_string_reset(instance->tmp_string);
|
||||
for
|
||||
M_EACH(item, instance->history->data, WSHistoryItemArray_t) {
|
||||
furi_string_free(item->item_str);
|
||||
furi_string_free(item->preset->name);
|
||||
free(item->preset);
|
||||
flipper_format_free(item->flipper_string);
|
||||
item->type = 0;
|
||||
}
|
||||
WSHistoryItemArray_reset(instance->history->data);
|
||||
instance->last_index_write = 0;
|
||||
instance->code_last_hash_data = 0;
|
||||
}
|
||||
|
||||
uint16_t ws_history_get_item(WSHistory* instance) {
|
||||
furi_assert(instance);
|
||||
return instance->last_index_write;
|
||||
}
|
||||
|
||||
uint8_t ws_history_get_type_protocol(WSHistory* instance, uint16_t idx) {
|
||||
furi_assert(instance);
|
||||
WSHistoryItem* item = WSHistoryItemArray_get(instance->history->data, idx);
|
||||
return item->type;
|
||||
}
|
||||
|
||||
const char* ws_history_get_protocol_name(WSHistory* instance, uint16_t idx) {
|
||||
furi_assert(instance);
|
||||
WSHistoryItem* item = WSHistoryItemArray_get(instance->history->data, idx);
|
||||
flipper_format_rewind(item->flipper_string);
|
||||
if(!flipper_format_read_string(item->flipper_string, "Protocol", instance->tmp_string)) {
|
||||
FURI_LOG_E(TAG, "Missing Protocol");
|
||||
furi_string_reset(instance->tmp_string);
|
||||
}
|
||||
return furi_string_get_cstr(instance->tmp_string);
|
||||
}
|
||||
|
||||
FlipperFormat* ws_history_get_raw_data(WSHistory* instance, uint16_t idx) {
|
||||
furi_assert(instance);
|
||||
WSHistoryItem* item = WSHistoryItemArray_get(instance->history->data, idx);
|
||||
if(item->flipper_string) {
|
||||
return item->flipper_string;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
bool ws_history_get_text_space_left(WSHistory* instance, FuriString* output) {
|
||||
furi_assert(instance);
|
||||
if(instance->last_index_write == WS_HISTORY_MAX) {
|
||||
if(output != NULL) furi_string_printf(output, "Memory is FULL");
|
||||
return true;
|
||||
}
|
||||
if(output != NULL)
|
||||
furi_string_printf(output, "%02u/%02u", instance->last_index_write, WS_HISTORY_MAX);
|
||||
return false;
|
||||
}
|
||||
|
||||
void ws_history_get_text_item_menu(WSHistory* instance, FuriString* output, uint16_t idx) {
|
||||
WSHistoryItem* item = WSHistoryItemArray_get(instance->history->data, idx);
|
||||
furi_string_set(output, item->item_str);
|
||||
}
|
||||
|
||||
WSHistoryStateAddKey
|
||||
ws_history_add_to_history(WSHistory* instance, void* context, SubGhzRadioPreset* preset) {
|
||||
furi_assert(instance);
|
||||
furi_assert(context);
|
||||
|
||||
if(instance->last_index_write >= WS_HISTORY_MAX) return WSHistoryStateAddKeyOverflow;
|
||||
|
||||
SubGhzProtocolDecoderBase* decoder_base = context;
|
||||
if((instance->code_last_hash_data ==
|
||||
subghz_protocol_decoder_base_get_hash_data(decoder_base)) &&
|
||||
((furi_get_tick() - instance->last_update_timestamp) < 500)) {
|
||||
instance->last_update_timestamp = furi_get_tick();
|
||||
return WSHistoryStateAddKeyTimeOut;
|
||||
}
|
||||
|
||||
instance->code_last_hash_data = subghz_protocol_decoder_base_get_hash_data(decoder_base);
|
||||
instance->last_update_timestamp = furi_get_tick();
|
||||
|
||||
FlipperFormat* fff = flipper_format_string_alloc();
|
||||
uint32_t id = 0;
|
||||
subghz_protocol_decoder_base_serialize(decoder_base, fff, preset);
|
||||
|
||||
do {
|
||||
if(!flipper_format_rewind(fff)) {
|
||||
FURI_LOG_E(TAG, "Rewind error");
|
||||
break;
|
||||
}
|
||||
if(!flipper_format_read_uint32(fff, "Id", (uint32_t*)&id, 1)) {
|
||||
FURI_LOG_E(TAG, "Missing Id");
|
||||
break;
|
||||
}
|
||||
} while(false);
|
||||
flipper_format_free(fff);
|
||||
|
||||
//Update record if found
|
||||
bool sensor_found = false;
|
||||
for(size_t i = 0; i < WSHistoryItemArray_size(instance->history->data); i++) {
|
||||
WSHistoryItem* item = WSHistoryItemArray_get(instance->history->data, i);
|
||||
if(item->id == id) {
|
||||
sensor_found = true;
|
||||
Stream* flipper_string_stream = flipper_format_get_raw_stream(item->flipper_string);
|
||||
stream_clean(flipper_string_stream);
|
||||
subghz_protocol_decoder_base_serialize(decoder_base, item->flipper_string, preset);
|
||||
return WSHistoryStateAddKeyUpdateData;
|
||||
}
|
||||
}
|
||||
|
||||
// or add new record
|
||||
if(!sensor_found) { //-V547
|
||||
WSHistoryItem* item = WSHistoryItemArray_push_raw(instance->history->data);
|
||||
item->preset = malloc(sizeof(SubGhzRadioPreset));
|
||||
item->type = decoder_base->protocol->type;
|
||||
item->preset->frequency = preset->frequency;
|
||||
item->preset->name = furi_string_alloc();
|
||||
furi_string_set(item->preset->name, preset->name);
|
||||
item->preset->data = preset->data;
|
||||
item->preset->data_size = preset->data_size;
|
||||
item->id = id;
|
||||
|
||||
item->item_str = furi_string_alloc();
|
||||
item->flipper_string = flipper_format_string_alloc();
|
||||
subghz_protocol_decoder_base_serialize(decoder_base, item->flipper_string, preset);
|
||||
|
||||
do {
|
||||
if(!flipper_format_rewind(item->flipper_string)) {
|
||||
FURI_LOG_E(TAG, "Rewind error");
|
||||
break;
|
||||
}
|
||||
if(!flipper_format_read_string(
|
||||
item->flipper_string, "Protocol", instance->tmp_string)) {
|
||||
FURI_LOG_E(TAG, "Missing Protocol");
|
||||
break;
|
||||
}
|
||||
|
||||
if(!flipper_format_rewind(item->flipper_string)) {
|
||||
FURI_LOG_E(TAG, "Rewind error");
|
||||
break;
|
||||
}
|
||||
uint8_t key_data[sizeof(uint64_t)] = {0};
|
||||
if(!flipper_format_read_hex(item->flipper_string, "Data", key_data, sizeof(uint64_t))) {
|
||||
FURI_LOG_E(TAG, "Missing Data");
|
||||
break;
|
||||
}
|
||||
uint64_t data = 0;
|
||||
for(uint8_t i = 0; i < sizeof(uint64_t); i++) {
|
||||
data = (data << 8) | key_data[i];
|
||||
}
|
||||
uint32_t temp_data = 0;
|
||||
if(!flipper_format_read_uint32(item->flipper_string, "Ch", (uint32_t*)&temp_data, 1)) {
|
||||
FURI_LOG_E(TAG, "Missing Channel");
|
||||
break;
|
||||
}
|
||||
if(temp_data != WS_NO_CHANNEL) {
|
||||
furi_string_cat_printf(instance->tmp_string, " Ch:%X", (uint8_t)temp_data);
|
||||
}
|
||||
|
||||
furi_string_printf(
|
||||
item->item_str, "%s %llX", furi_string_get_cstr(instance->tmp_string), data);
|
||||
|
||||
} while(false);
|
||||
instance->last_index_write++;
|
||||
return WSHistoryStateAddKeyNewDada;
|
||||
}
|
||||
return WSHistoryStateAddKeyUnknown;
|
||||
}
|
||||
112
applications/external/weather_station/weather_station_history.h
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <math.h>
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <lib/flipper_format/flipper_format.h>
|
||||
#include <lib/subghz/types.h>
|
||||
|
||||
typedef struct WSHistory WSHistory;
|
||||
|
||||
/** History state add key */
|
||||
typedef enum {
|
||||
WSHistoryStateAddKeyUnknown,
|
||||
WSHistoryStateAddKeyTimeOut,
|
||||
WSHistoryStateAddKeyNewDada,
|
||||
WSHistoryStateAddKeyUpdateData,
|
||||
WSHistoryStateAddKeyOverflow,
|
||||
} WSHistoryStateAddKey;
|
||||
|
||||
/** Allocate WSHistory
|
||||
*
|
||||
* @return WSHistory*
|
||||
*/
|
||||
WSHistory* ws_history_alloc(void);
|
||||
|
||||
/** Free WSHistory
|
||||
*
|
||||
* @param instance - WSHistory instance
|
||||
*/
|
||||
void ws_history_free(WSHistory* instance);
|
||||
|
||||
/** Clear history
|
||||
*
|
||||
* @param instance - WSHistory instance
|
||||
*/
|
||||
void ws_history_reset(WSHistory* instance);
|
||||
|
||||
/** Get frequency to history[idx]
|
||||
*
|
||||
* @param instance - WSHistory instance
|
||||
* @param idx - record index
|
||||
* @return frequency - frequency Hz
|
||||
*/
|
||||
uint32_t ws_history_get_frequency(WSHistory* instance, uint16_t idx);
|
||||
|
||||
SubGhzRadioPreset* ws_history_get_radio_preset(WSHistory* instance, uint16_t idx);
|
||||
|
||||
/** Get preset to history[idx]
|
||||
*
|
||||
* @param instance - WSHistory instance
|
||||
* @param idx - record index
|
||||
* @return preset - preset name
|
||||
*/
|
||||
const char* ws_history_get_preset(WSHistory* instance, uint16_t idx);
|
||||
|
||||
/** Get history index write
|
||||
*
|
||||
* @param instance - WSHistory instance
|
||||
* @return idx - current record index
|
||||
*/
|
||||
uint16_t ws_history_get_item(WSHistory* instance);
|
||||
|
||||
/** Get type protocol to history[idx]
|
||||
*
|
||||
* @param instance - WSHistory instance
|
||||
* @param idx - record index
|
||||
* @return type - type protocol
|
||||
*/
|
||||
uint8_t ws_history_get_type_protocol(WSHistory* instance, uint16_t idx);
|
||||
|
||||
/** Get name protocol to history[idx]
|
||||
*
|
||||
* @param instance - WSHistory instance
|
||||
* @param idx - record index
|
||||
* @return name - const char* name protocol
|
||||
*/
|
||||
const char* ws_history_get_protocol_name(WSHistory* instance, uint16_t idx);
|
||||
|
||||
/** Get string item menu to history[idx]
|
||||
*
|
||||
* @param instance - WSHistory instance
|
||||
* @param output - FuriString* output
|
||||
* @param idx - record index
|
||||
*/
|
||||
void ws_history_get_text_item_menu(WSHistory* instance, FuriString* output, uint16_t idx);
|
||||
|
||||
/** Get string the remaining number of records to history
|
||||
*
|
||||
* @param instance - WSHistory instance
|
||||
* @param output - FuriString* output
|
||||
* @return bool - is FUUL
|
||||
*/
|
||||
bool ws_history_get_text_space_left(WSHistory* instance, FuriString* output);
|
||||
|
||||
/** Add protocol to history
|
||||
*
|
||||
* @param instance - WSHistory instance
|
||||
* @param context - SubGhzProtocolCommon context
|
||||
* @param preset - SubGhzRadioPreset preset
|
||||
* @return WSHistoryStateAddKey;
|
||||
*/
|
||||
WSHistoryStateAddKey
|
||||
ws_history_add_to_history(WSHistory* instance, void* context, SubGhzRadioPreset* preset);
|
||||
|
||||
/** Get SubGhzProtocolCommonLoad to load into the protocol decoder bin data
|
||||
*
|
||||
* @param instance - WSHistory instance
|
||||
* @param idx - record index
|
||||
* @return SubGhzProtocolCommonLoad*
|
||||
*/
|
||||
FlipperFormat* ws_history_get_raw_data(WSHistory* instance, uint16_t idx);
|
||||