types.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #include <stddef.h>
  5. #include <lib/flipper_format/flipper_format.h>
  6. #include <lib/toolbox/level_duration.h>
  7. #include "environment.h"
  8. #include <furi.h>
  9. #include <furi_hal.h>
  10. #define SUBGHZ_APP_FOLDER ANY_PATH("subghz")
  11. #define SUBGHZ_RAW_FOLDER EXT_PATH("subghz")
  12. #define SUBGHZ_APP_EXTENSION ".sub"
  13. #define SUBGHZ_KEY_FILE_VERSION 1
  14. #define SUBGHZ_KEY_FILE_TYPE "Flipper SubGhz Key File"
  15. #define SUBGHZ_RAW_FILE_VERSION 1
  16. #define SUBGHZ_RAW_FILE_TYPE "Flipper SubGhz RAW File"
  17. // Radio Preset
  18. typedef struct {
  19. FuriString* name;
  20. uint32_t frequency;
  21. uint8_t* data;
  22. size_t data_size;
  23. } SubGhzRadioPreset;
  24. typedef enum {
  25. SubGhzProtocolStatusOk = 0,
  26. // Errors
  27. SubGhzProtocolStatusError = (-1), ///< General unclassified error
  28. // Serialize/De-serialize
  29. SubGhzProtocolStatusErrorParserHeader = (-2), ///< Missing or invalid file header
  30. SubGhzProtocolStatusErrorParserFrequency = (-3), ///< Missing `Frequency`
  31. SubGhzProtocolStatusErrorParserPreset = (-4), ///< Missing `Preset`
  32. SubGhzProtocolStatusErrorParserCustomPreset = (-5), ///< Missing `Custom_preset_module`
  33. SubGhzProtocolStatusErrorParserProtocolName = (-6), ///< Missing `Protocol` name
  34. SubGhzProtocolStatusErrorParserBitCount = (-7), ///< Missing `Bit`
  35. SubGhzProtocolStatusErrorParserKey = (-8), ///< Missing `Key`
  36. SubGhzProtocolStatusErrorParserTe = (-9), ///< Missing `Te`
  37. SubGhzProtocolStatusErrorParserOthers = (-10), ///< Missing some other mandatory keys
  38. // Invalid data
  39. SubGhzProtocolStatusErrorValueBitCount = (-11), ///< Invalid bit count value
  40. // Encoder issue
  41. SubGhzProtocolStatusErrorEncoderGetUpload = (-12), ///< Payload encoder failure
  42. // Special Values
  43. SubGhzProtocolStatusReserved = 0x7FFFFFFF, ///< Prevents enum down-size compiler optimization.
  44. } SubGhzProtocolStatus;
  45. // Allocator and Deallocator
  46. typedef void* (*SubGhzAlloc)(SubGhzEnvironment* environment);
  47. typedef void (*SubGhzFree)(void* context);
  48. // Serialize and Deserialize
  49. typedef SubGhzProtocolStatus (
  50. *SubGhzSerialize)(void* context, FlipperFormat* flipper_format, SubGhzRadioPreset* preset);
  51. typedef SubGhzProtocolStatus (*SubGhzDeserialize)(void* context, FlipperFormat* flipper_format);
  52. // Decoder specific
  53. typedef void (*SubGhzDecoderFeed)(void* decoder, bool level, uint32_t duration);
  54. typedef void (*SubGhzDecoderReset)(void* decoder);
  55. typedef uint8_t (*SubGhzGetHashData)(void* decoder);
  56. typedef void (*SubGhzGetString)(void* decoder, FuriString* output);
  57. // Encoder specific
  58. typedef void (*SubGhzEncoderStop)(void* encoder);
  59. typedef LevelDuration (*SubGhzEncoderYield)(void* context);
  60. typedef struct {
  61. SubGhzAlloc alloc;
  62. SubGhzFree free;
  63. SubGhzDecoderFeed feed;
  64. SubGhzDecoderReset reset;
  65. SubGhzGetHashData get_hash_data;
  66. SubGhzGetString get_string;
  67. SubGhzSerialize serialize;
  68. SubGhzDeserialize deserialize;
  69. } SubGhzProtocolDecoder;
  70. typedef struct {
  71. SubGhzAlloc alloc;
  72. SubGhzFree free;
  73. SubGhzDeserialize deserialize;
  74. SubGhzEncoderStop stop;
  75. SubGhzEncoderYield yield;
  76. } SubGhzProtocolEncoder;
  77. typedef enum {
  78. SubGhzProtocolTypeUnknown = 0,
  79. SubGhzProtocolTypeStatic,
  80. SubGhzProtocolTypeDynamic,
  81. SubGhzProtocolTypeRAW,
  82. SubGhzProtocolWeatherStation,
  83. SubGhzProtocolCustom,
  84. } SubGhzProtocolType;
  85. typedef enum {
  86. SubGhzProtocolFlag_RAW = (1 << 0),
  87. SubGhzProtocolFlag_Decodable = (1 << 1),
  88. SubGhzProtocolFlag_315 = (1 << 2),
  89. SubGhzProtocolFlag_433 = (1 << 3),
  90. SubGhzProtocolFlag_868 = (1 << 4),
  91. SubGhzProtocolFlag_AM = (1 << 5),
  92. SubGhzProtocolFlag_FM = (1 << 6),
  93. SubGhzProtocolFlag_Save = (1 << 7),
  94. SubGhzProtocolFlag_Load = (1 << 8),
  95. SubGhzProtocolFlag_Send = (1 << 9),
  96. SubGhzProtocolFlag_BinRAW = (1 << 10),
  97. } SubGhzProtocolFlag;
  98. typedef struct {
  99. const char* name;
  100. SubGhzProtocolType type;
  101. SubGhzProtocolFlag flag;
  102. const SubGhzProtocolEncoder* encoder;
  103. const SubGhzProtocolDecoder* decoder;
  104. } SubGhzProtocol;