2022-03-03 12:48:56 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
#include <lib/flipper_format/flipper_format.h>
|
|
|
|
#include <lib/toolbox/level_duration.h>
|
|
|
|
|
|
|
|
#include "environment.h"
|
|
|
|
#include <furi.h>
|
|
|
|
#include <furi_hal.h>
|
|
|
|
|
2022-07-26 15:21:51 +03:00
|
|
|
#define SUBGHZ_APP_FOLDER ANY_PATH("subghz")
|
|
|
|
#define SUBGHZ_RAW_FOLDER EXT_PATH("subghz")
|
2023-09-01 08:57:49 +03:00
|
|
|
#define SUBGHZ_APP_FILENAME_PREFIX "SubGHz"
|
|
|
|
#define SUBGHZ_APP_FILENAME_EXTENSION ".sub"
|
2022-03-03 12:48:56 +03:00
|
|
|
|
|
|
|
#define SUBGHZ_KEY_FILE_VERSION 1
|
|
|
|
#define SUBGHZ_KEY_FILE_TYPE "Flipper SubGhz Key File"
|
|
|
|
|
|
|
|
#define SUBGHZ_RAW_FILE_VERSION 1
|
|
|
|
#define SUBGHZ_RAW_FILE_TYPE "Flipper SubGhz RAW File"
|
|
|
|
|
2023-06-18 16:44:45 +03:00
|
|
|
#define SUBGHZ_KEYSTORE_DIR_NAME EXT_PATH("subghz/assets/keeloq_mfcodes")
|
|
|
|
#define SUBGHZ_KEYSTORE_DIR_USER_NAME EXT_PATH("subghz/assets/keeloq_mfcodes_user")
|
|
|
|
#define SUBGHZ_CAME_ATOMO_DIR_NAME EXT_PATH("subghz/assets/came_atomo")
|
|
|
|
#define SUBGHZ_NICE_FLOR_S_DIR_NAME EXT_PATH("subghz/assets/nice_flor_s")
|
|
|
|
#define SUBGHZ_ALUTECH_AT_4N_DIR_NAME EXT_PATH("subghz/assets/alutech_at_4n")
|
|
|
|
|
2023-06-06 22:13:41 +03:00
|
|
|
typedef struct SubGhzProtocolRegistry SubGhzProtocolRegistry;
|
|
|
|
typedef struct SubGhzEnvironment SubGhzEnvironment;
|
|
|
|
|
2022-10-19 20:27:26 +03:00
|
|
|
// Radio Preset
|
|
|
|
typedef struct {
|
|
|
|
FuriString* name;
|
|
|
|
uint32_t frequency;
|
|
|
|
uint8_t* data;
|
|
|
|
size_t data_size;
|
|
|
|
} SubGhzRadioPreset;
|
2022-03-03 12:48:56 +03:00
|
|
|
|
2023-03-03 18:09:13 +03:00
|
|
|
typedef enum {
|
|
|
|
SubGhzProtocolStatusOk = 0,
|
|
|
|
// Errors
|
|
|
|
SubGhzProtocolStatusError = (-1), ///< General unclassified error
|
|
|
|
// Serialize/De-serialize
|
|
|
|
SubGhzProtocolStatusErrorParserHeader = (-2), ///< Missing or invalid file header
|
|
|
|
SubGhzProtocolStatusErrorParserFrequency = (-3), ///< Missing `Frequency`
|
|
|
|
SubGhzProtocolStatusErrorParserPreset = (-4), ///< Missing `Preset`
|
|
|
|
SubGhzProtocolStatusErrorParserCustomPreset = (-5), ///< Missing `Custom_preset_module`
|
|
|
|
SubGhzProtocolStatusErrorParserProtocolName = (-6), ///< Missing `Protocol` name
|
|
|
|
SubGhzProtocolStatusErrorParserBitCount = (-7), ///< Missing `Bit`
|
|
|
|
SubGhzProtocolStatusErrorParserKey = (-8), ///< Missing `Key`
|
|
|
|
SubGhzProtocolStatusErrorParserTe = (-9), ///< Missing `Te`
|
|
|
|
SubGhzProtocolStatusErrorParserOthers = (-10), ///< Missing some other mandatory keys
|
|
|
|
// Invalid data
|
|
|
|
SubGhzProtocolStatusErrorValueBitCount = (-11), ///< Invalid bit count value
|
|
|
|
// Encoder issue
|
|
|
|
SubGhzProtocolStatusErrorEncoderGetUpload = (-12), ///< Payload encoder failure
|
|
|
|
// Special Values
|
2023-08-16 09:46:08 +03:00
|
|
|
SubGhzProtocolStatusErrorProtocolNotFound = (-13), ///< Protocol not found
|
2023-03-03 18:09:13 +03:00
|
|
|
SubGhzProtocolStatusReserved = 0x7FFFFFFF, ///< Prevents enum down-size compiler optimization.
|
|
|
|
} SubGhzProtocolStatus;
|
|
|
|
|
2022-03-03 12:48:56 +03:00
|
|
|
// Allocator and Deallocator
|
|
|
|
typedef void* (*SubGhzAlloc)(SubGhzEnvironment* environment);
|
|
|
|
typedef void (*SubGhzFree)(void* context);
|
|
|
|
|
|
|
|
// Serialize and Deserialize
|
2023-03-03 18:09:13 +03:00
|
|
|
typedef SubGhzProtocolStatus (
|
2022-10-19 20:27:26 +03:00
|
|
|
*SubGhzSerialize)(void* context, FlipperFormat* flipper_format, SubGhzRadioPreset* preset);
|
2023-03-03 18:09:13 +03:00
|
|
|
typedef SubGhzProtocolStatus (*SubGhzDeserialize)(void* context, FlipperFormat* flipper_format);
|
2022-03-03 12:48:56 +03:00
|
|
|
|
|
|
|
// Decoder specific
|
|
|
|
typedef void (*SubGhzDecoderFeed)(void* decoder, bool level, uint32_t duration);
|
|
|
|
typedef void (*SubGhzDecoderReset)(void* decoder);
|
|
|
|
typedef uint8_t (*SubGhzGetHashData)(void* decoder);
|
2022-10-05 18:15:23 +03:00
|
|
|
typedef void (*SubGhzGetString)(void* decoder, FuriString* output);
|
2022-03-03 12:48:56 +03:00
|
|
|
|
|
|
|
// Encoder specific
|
|
|
|
typedef void (*SubGhzEncoderStop)(void* encoder);
|
|
|
|
typedef LevelDuration (*SubGhzEncoderYield)(void* context);
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
SubGhzAlloc alloc;
|
|
|
|
SubGhzFree free;
|
|
|
|
|
|
|
|
SubGhzDecoderFeed feed;
|
|
|
|
SubGhzDecoderReset reset;
|
|
|
|
|
|
|
|
SubGhzGetHashData get_hash_data;
|
|
|
|
SubGhzGetString get_string;
|
|
|
|
SubGhzSerialize serialize;
|
|
|
|
SubGhzDeserialize deserialize;
|
|
|
|
} SubGhzProtocolDecoder;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
SubGhzAlloc alloc;
|
|
|
|
SubGhzFree free;
|
|
|
|
|
|
|
|
SubGhzDeserialize deserialize;
|
|
|
|
SubGhzEncoderStop stop;
|
|
|
|
SubGhzEncoderYield yield;
|
|
|
|
} SubGhzProtocolEncoder;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
SubGhzProtocolTypeUnknown = 0,
|
|
|
|
SubGhzProtocolTypeStatic,
|
|
|
|
SubGhzProtocolTypeDynamic,
|
|
|
|
SubGhzProtocolTypeRAW,
|
2022-10-19 20:27:26 +03:00
|
|
|
SubGhzProtocolWeatherStation,
|
|
|
|
SubGhzProtocolCustom,
|
2023-02-09 17:49:28 +03:00
|
|
|
SubGhzProtocolTypeBinRAW,
|
2022-03-03 12:48:56 +03:00
|
|
|
} SubGhzProtocolType;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
SubGhzProtocolFlag_RAW = (1 << 0),
|
|
|
|
SubGhzProtocolFlag_Decodable = (1 << 1),
|
|
|
|
SubGhzProtocolFlag_315 = (1 << 2),
|
|
|
|
SubGhzProtocolFlag_433 = (1 << 3),
|
|
|
|
SubGhzProtocolFlag_868 = (1 << 4),
|
|
|
|
SubGhzProtocolFlag_AM = (1 << 5),
|
|
|
|
SubGhzProtocolFlag_FM = (1 << 6),
|
|
|
|
SubGhzProtocolFlag_Save = (1 << 7),
|
|
|
|
SubGhzProtocolFlag_Load = (1 << 8),
|
|
|
|
SubGhzProtocolFlag_Send = (1 << 9),
|
2023-02-09 07:48:06 +03:00
|
|
|
SubGhzProtocolFlag_BinRAW = (1 << 10),
|
2023-06-14 01:24:05 +03:00
|
|
|
SubGhzProtocolFlag_StarLine = (1 << 11),
|
|
|
|
SubGhzProtocolFlag_AutoAlarms = (1 << 12),
|
2023-09-11 17:03:17 +03:00
|
|
|
SubGhzProtocolFlag_Magellan = (1 << 13),
|
|
|
|
SubGhzProtocolFlag_Princeton = (1 << 14),
|
2023-10-03 17:56:39 +03:00
|
|
|
SubGhzProtocolFlag_NiceFlorS = (1 << 15),
|
2022-03-03 12:48:56 +03:00
|
|
|
} SubGhzProtocolFlag;
|
|
|
|
|
2023-06-06 22:13:41 +03:00
|
|
|
struct SubGhzProtocol {
|
2022-03-03 12:48:56 +03:00
|
|
|
const char* name;
|
|
|
|
SubGhzProtocolType type;
|
|
|
|
SubGhzProtocolFlag flag;
|
|
|
|
|
|
|
|
const SubGhzProtocolEncoder* encoder;
|
|
|
|
const SubGhzProtocolDecoder* decoder;
|
2023-06-06 22:13:41 +03:00
|
|
|
};
|